diff --git a/includes/class-Licenses.php b/includes/class-Licenses.php index 0e0e2a8..2e6700b 100644 --- a/includes/class-Licenses.php +++ b/includes/class-Licenses.php @@ -1,101 +1,175 @@ . +/** + * Collector of some known licenses + */ class Licenses { - private $licenses; + /** + * All the registered licenses indexed by code + * + * @var array + */ + private $licenses = []; + + /** + * Instance of this singleton + * + * @var self + */ + private static $instance = null; + + /** + * Get the singleton instance + * + * @return self + */ + public static function instance() { + if( !self::$instance ) { + self::$instance = new self(); + } + return self::$instance; + } - function __construct() { + /** + * Constructor + */ + public function __construct() { $this->add('gnu-gpl', "GNU GPL", "GNU General Public License", 'https://www.gnu.org/licenses/gpl-3.0.html'); $this->add('gnu-gpl-v3', "GNU GPL v3", __("GNU General Public License, versione 3"), 'https://www.gnu.org/licenses/gpl-3.0.html'); $this->add('gnu-gpl-v2', "GNU GPL v2", __("GNU General Public License, versione 2"), 'https://www.gnu.org/licenses/gpl-2.0.html'); $this->add('gnu-agpl', "GNU AGPL", "GNU Affero General Public License", 'https://www.gnu.org/licenses/agpl-3.0.html'); $this->add('apache', "Apache 2.0", __("Licenza Apache, versione 2.0"), 'https://www.apache.org/licenses/LICENSE-2.0.html'); $this->add('mit', "MIT", __("Licenza MIT"), 'https://opensource.org/licenses/MIT'); $this->add('php', "PHP", __("Licenza PHP"), 'http://www.php.net/license/3_01.txt'); $this->add('odbl', "ODbl", "Open Data Commons Open Database License", 'http://opendatacommons.org/licenses/odbl/'); $this->add('cc-by', "CC By 4.0", __("Creative Commons - Attribuzione 4.0 Internazionale"), _('https://creativecommons.org/licenses/by/4.0/deed.it') ); $this->add('cc-by-sa-3.0', "CC By-Sa 3.0", __("Creative Commons - Attribuzione - Condividi allo stesso modo 3.0 Unported"), _('https://creativecommons.org/licenses/by-sa/3.0/deed.it') ); $this->add('cc-by-sa-4.0', "CC By-Sa 4.0", __("Creative Commons - Attribuzione - Condividi allo stesso modo 4.0 Internazionale"), _('https://creativecommons.org/licenses/by-sa/4.0/deed.it') ); $this->add('cc-by-nc-sa-4.0', "CC By-Nc-Sa 4.0", __("Creative Commons - Attribuzione - Non commerciale - Condividi allo stesso modo 4.0 Internazionale"), _('https://creativecommons.org/licenses/by-nc-sa/4.0/deed.it') ); $this->add('jquery', "jQuery", __("Licenza jQuery"), 'https://github.com/jquery/jquery/blob/master/LICENSE.txt'); $this->add('bsd-2', "BSD-2", "BSD-2", 'https://www.gnu.org/licenses/license-list.html#FreeBSD'); $this->add('aal', "AAL", "Attribution Assurance License", 'https://opensource.org/licenses/AAL'); $this->add('wtfpl', "WTFPL", __("Fai cosa c**** ti pare Public License"), _('https://it.wikipedia.org/wiki/WTFPL') ); } - private static $_instance; - /** - * Get the singleton instance + * Register another License * + * @param string $code License code + * @param string $short License short name (English) + * @param string $name License long name (internationalized) + * @param string $url License URL (internationalized) * @return self */ - public static function instance() { - if( empty( self::$_instance ) ) { - self::$_instance = new self(); - } - return self::$_instance; + public function add( $code, $short, $name, $url ) { + $this->licenses[ $code ] = new License( $code, $short, $name, $url ); + return $this; } - function add($code, $short, $name, $url) { - $this->licenses[$code] = new License($short, $name, $url); - return $this; + /** + * Get all the registered Licenses + * + * @return array + */ + public function all() { + return $this->licenses; } - function get($code) { - return $this->licenses[$code]; + /** + * Get a single License + * + * @param string $code License code + * @return License + */ + public function get( $code ) { + return $this->licenses[ $code ]; } } class License { + + public $code; public $short; public $name; public $url; - function __construct($short, $name, $url) { + function __construct( $code, $short, $name, $url ) { + $this->code = $code; $this->short = $short; $this->name = $name; $this->url = $url; } - function getShort() { + /** + * Get the License code + * + * @return string + */ + public function getCode() { + return $this->code; + } + + /** + * Get the License short name + * + * @return string + */ + public function getShort() { return $this->short; } - function getName() { + /** + * Get the License long name + * + * @return string + */ + public function getName() { return $this->name; } - function getURL() { + /** + * Get the License URL + * + * @return string + */ + public function getURL() { return $this->url; } - function getLink($classes = null, $other = null) { - if(null === $other) { + /** + * Get a link to this License + * + * @param string $classes Set custom classes + * @param string $other Set custom inline tags + * @return string + */ + public function getLink( $classes = null, $other = null ) { + if( null !== $other ) { $other = 'target="_blank"'; } return HTML::a( $this->getURL(), $this->getShort(), - $this->getName(), + esc_html( $this->getName() ), $classes, $other ); } }