blob: fd5039d01b0a558bf98b7e36c69955ff83f4d486 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2018 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
require_once dirname(__FILE__) . '/Project.class.php';
require_once dirname(__FILE__) . '/database.inc';
/**
* The Trademarks class provides information about the various
* trademarks, both registered (&reg;) and unregistered (&trade;),
* owned by the Eclipse Foundation.
*
* The constructor is private to prevent the creation of multiple
* instances. Obtain the single instance by calling
* <code>Trademarks::getInstance()</code>.
*
* This class gathers data from a couple of different sources. The
* Eclipse Foundation asserts a common law (unregistered) trademark
* of all project names, so the bulk of the unregistered trademarks come
* from project names. These values are modified and supplemented via
* information provided in the <code>trademarks.ini</code> file.
* The format for the entries are documented in the file.
*
* The <code>getRegistered()</code> and <code>getUnregistered()</code>
* functions answer arrays containing the registered and unregistered
* trademarks, respectively. The array takes the following form:
*
* <pre>{
* "birt": [
* {
* "name": "Eclipse Business Intelligence and Reporting Tools",
* "link": "https:\/\/projects.eclipse.org\/projects\/birt"
* },
* {
* "name": "Business Intelligence and Reporting Tools",
* "link": "https:\/\/projects.eclipse.org\/projects\/birt"
* },
* {
* "name": "Eclipse BIRT",
* "link": "https:\/\/projects.eclipse.org\/projects\/birt"
* },
* {
* "name": "BIRT",
* "link": "https:\/\/projects.eclipse.org\/projects\/birt"
* }
* ],
* ...
* "eclipse.platform": [
* {
* "name": "Eclipse Platform",
* "link": "https:\/\/projects.eclipse.org\/projects\/eclipse.platform"
* }
* ],
* ...</pre>
*
* Values are organized by id (the project id when a project id is available,
* or another value that uniquely identifies a collection of trademarks), pointing
* to an array containing one or more entires that themselves are arrays that
* contain the actual data. In the example above, the Eclipse BIRT project provides
* a list of four different names, but the Eclipse Platform project only provides
* one.
*
* @see Project::getTrademark()
* @see getRegistered()
* @see getUnregistered()
*/
class Trademarks {
private $config;
private $registered = array();
private $unregistered = array();
private static $INSTANCE;
/**
* This function answers the singleton instance of this class.
*
* @return Trademarks
*/
public static function getInstance() {
self::init();
return self::$INSTANCE;
}
/**
* This function lazy-initializes the instance.
* It should never be directly called by user code.
*/
static function init() {
if (isset(self::$INSTANCE)) return;
self::$INSTANCE = new self();
}
private function __construct() {
$this->loadConfig();
$this->loadRegisteredTrademarks();
$this->loadProjectTrademarks();
foreach($this->config['unregistered'] as $value) {
$this->addTrademark($this->unregistered, $value);
}
foreach($this->config['remove'] as $id) {
unset($this->unregistered[$id]);
}
uksort($this->unregistered, function ($a, $b) {
return strnatcasecmp($a[0]['name'], $b[0]['name']);
});
}
public function getRegistered() {
return $this->registered;
}
public function getUnregistered() {
return $this->unregistered;
}
private function loadConfig() {
$this->config = parse_ini_file(dirname(__FILE__) . '/trademarks.ini', true);
}
private function loadRegisteredTrademarks() {
foreach($this->config['registered'] as $registered) {
$this->addTrademark($this->registered, $registered);
}
}
private function addTrademark(&$target, $value) {
$trademarks = array();
$parts = explode('|', $value);
if (count($parts) >= 2) {
$target[$parts[0]][] = array('name' => $parts[1], 'link' => @$parts[2]);
}
}
private function loadProjectTrademarks() {
foreach(Project::getAll() as $project) {
$project->trademarksDo(TRADEMARK_UNREGISTERED, function($term) use (&$project) {
$this->unregistered[$project->getId()][] = array(
'name' => $term,
'link' => $project->isArchived() ? null : $project->getUrl()
);
});
}
}
}
?>