123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- <?php
- class ElggPluginManifest {
-
- protected $parser;
-
- protected $namespace_root = 'http://www.elgg.org/plugin_manifest/';
-
- private $depsStructPlugin = array(
- 'type' => '',
- 'name' => '',
- 'version' => '',
- 'comparison' => 'ge'
- );
-
- private $depsStructPriority = array(
- 'type' => '',
- 'priority' => '',
- 'plugin' => ''
- );
-
- private $depsStructElgg = array(
- 'type' => '',
- 'version' => '',
- 'comparison' => 'ge'
- );
-
-
- private $depsStructPhpVersion = array(
- 'type' => '',
- 'version' => '',
- 'comparison' => 'ge'
- );
-
- private $depsStructPhpIni = array(
- 'type' => '',
- 'name' => '',
- 'value' => '',
- 'comparison' => '='
- );
-
- private $depsStructPhpExtension = array(
- 'type' => '',
- 'name' => '',
- 'version' => '',
- 'comparison' => '='
- );
-
- private $depsConflictsStruct = array(
- 'type' => '',
- 'name' => '',
- 'version' => '',
- 'comparison' => '='
- );
-
- private $depsProvidesStruct = array(
- 'type' => '',
- 'name' => '',
- 'version' => ''
- );
-
- private $screenshotStruct = array(
- 'description' => '',
- 'path' => ''
- );
-
-
- private $contributorStruct = array(
- 'name' => '',
- 'email' => '',
- 'website' => '',
- 'username' => '',
- 'description' => '',
- );
-
- protected $apiVersion;
-
- protected $pluginID;
-
- public function __construct($manifest, $plugin_id = null) {
- if ($plugin_id) {
- $this->pluginID = $plugin_id;
- }
-
- if ($manifest instanceof \ElggXMLElement) {
- $manifest_obj = $manifest;
- } else {
- $raw_xml = '';
- if (substr(trim($manifest), 0, 1) == '<') {
-
- $raw_xml = $manifest;
- } elseif (is_file($manifest)) {
-
- $raw_xml = file_get_contents($manifest);
- }
- if ($raw_xml) {
- $manifest_obj = new \ElggXMLElement($raw_xml);
- } else {
- $manifest_obj = null;
- }
- }
- if (!$manifest_obj) {
- throw new \PluginException(_elgg_services()->translator->translate('PluginException:InvalidManifest',
- array($this->getPluginID())));
- }
-
- if (isset($manifest_obj->attributes['xmlns'])) {
- $namespace = $manifest_obj->attributes['xmlns'];
- $version = str_replace($this->namespace_root, '', $namespace);
- } else {
- $version = 1.7;
- }
- $this->apiVersion = $version;
- $parser_class_name = '\ElggPluginManifestParser' . str_replace('.', '', $this->apiVersion);
-
- try {
- $class_exists = class_exists($parser_class_name);
- } catch (Exception $e) {
- $class_exists = false;
- }
- if ($class_exists) {
- $this->parser = new $parser_class_name($manifest_obj, $this);
- } else {
- throw new \PluginException(_elgg_services()->translator->translate('PluginException:NoAvailableParser',
- array($this->apiVersion, $this->getPluginID())));
- }
- if (!$this->parser->parse()) {
- throw new \PluginException(_elgg_services()->translator->translate('PluginException:ParserError',
- array($this->apiVersion, $this->getPluginID())));
- }
- }
-
- public function getApiVersion() {
- return $this->apiVersion;
- }
-
- public function getPluginID() {
- if ($this->pluginID) {
- return $this->pluginID;
- } else {
- return _elgg_services()->translator->translate('unknown');
- }
- }
-
- public function getManifest() {
- return $this->parser->getManifest();
- }
-
-
- public function getName() {
- $name = $this->parser->getAttribute('name');
- if (!$name && $this->pluginID) {
- $name = ucwords(str_replace('_', ' ', $this->pluginID));
- }
- return $name;
- }
-
- public function getID() {
- return trim((string) $this->parser->getAttribute('id'));
- }
-
- public function getDescription() {
- return $this->parser->getAttribute('description');
- }
-
- public function getBlurb() {
- $blurb = $this->parser->getAttribute('blurb');
- if (!$blurb) {
- $blurb = elgg_get_excerpt($this->getDescription());
- }
- return $blurb;
- }
-
- public function getLicense() {
-
- $en_us = $this->parser->getAttribute('license');
- if ($en_us) {
- return $en_us;
- } else {
- return $this->parser->getAttribute('licence');
- }
- }
-
- public function getRepositoryURL() {
- return $this->parser->getAttribute('repository');
- }
-
- public function getBugTrackerURL() {
- return $this->parser->getAttribute('bugtracker');
- }
-
- public function getDonationsPageURL() {
- return $this->parser->getAttribute('donations');
- }
-
- public function getVersion() {
- return $this->parser->getAttribute('version');
- }
-
- public function getAuthor() {
- return $this->parser->getAttribute('author');
- }
-
- public function getCopyright() {
- return $this->parser->getAttribute('copyright');
- }
-
- public function getWebsite() {
- return $this->parser->getAttribute('website');
- }
-
- public function getCategories() {
- $bundled_plugins = array(
- 'aalborg_theme',
- 'blog',
- 'bookmarks',
- 'categories',
- 'ckeditor',
- 'custom_index',
- 'dashboard',
- 'developers',
- 'diagnostics',
- 'embed',
- 'externalpages',
- 'file',
- 'garbagecollector',
- 'groups',
- 'htmlawed',
- 'invitefriends',
- 'legacy_urls',
- 'likes',
- 'logbrowser',
- 'login_as',
- 'logrotate',
- 'members',
- 'messageboard',
- 'messages',
- 'notifications',
- 'pages',
- 'profile',
- 'reportedcontent',
- 'search',
- 'site_notifications',
- 'tagcloud',
- 'thewire',
- 'twitter_api',
- 'uservalidationbyemail',
- 'web_services',
- 'zaudio',
- );
- $cats = $this->parser->getAttribute('category');
- if (!$cats) {
- $cats = array();
- }
- if (in_array('bundled', $cats) && !in_array($this->getPluginID(), $bundled_plugins)) {
- unset($cats[array_search('bundled', $cats)]);
- }
- return $cats;
- }
-
- public function getScreenshots() {
- $ss = $this->parser->getAttribute('screenshot');
- if (!$ss) {
- $ss = array();
- }
- $normalized = array();
- foreach ($ss as $s) {
- $normalized[] = $this->buildStruct($this->screenshotStruct, $s);
- }
- return $normalized;
- }
-
-
- public function getContributors() {
- $ss = $this->parser->getAttribute('contributor');
- if (!$ss) {
- $ss = array();
- }
- $normalized = array();
- foreach ($ss as $s) {
- $normalized[] = $this->buildStruct($this->contributorStruct, $s);
- }
- return $normalized;
- }
-
- public function getProvides() {
-
- if ($this->getApiVersion() < 1.8) {
- $provides = array();
- } else {
- $provides = $this->parser->getAttribute('provides');
- }
- if (!$provides) {
- $provides = array();
- }
-
- if ($this->pluginID) {
- $provides[] = array(
- 'type' => 'plugin',
- 'name' => $this->getPluginID(),
- 'version' => $this->getVersion()
- );
- }
- $normalized = array();
- foreach ($provides as $provide) {
- $normalized[] = $this->buildStruct($this->depsProvidesStruct, $provide);
- }
- return $normalized;
- }
-
- public function getRequires() {
-
- if ($this->apiVersion < 1.8) {
- $elgg_version = $this->parser->getAttribute('elgg_version');
- if ($elgg_version) {
- $reqs = array(
- array(
- 'type' => 'elgg_version',
- 'version' => $elgg_version,
- 'comparison' => 'ge'
- )
- );
- } else {
- $reqs = array();
- }
- } else {
- $reqs = $this->parser->getAttribute('requires');
- }
- if (!$reqs) {
- $reqs = array();
- }
- $normalized = array();
- foreach ($reqs as $req) {
- $normalized[] = $this->normalizeDep($req);
- }
- return $normalized;
- }
-
- public function getSuggests() {
- $suggests = $this->parser->getAttribute('suggests');
- if (!$suggests) {
- $suggests = array();
- }
- $normalized = array();
- foreach ($suggests as $suggest) {
- $normalized[] = $this->normalizeDep($suggest);
- }
- return $normalized;
- }
-
- private function normalizeDep($dep) {
- switch ($dep['type']) {
- case 'elgg_version':
- case 'elgg_release':
- $struct = $this->depsStructElgg;
- break;
- case 'plugin':
- $struct = $this->depsStructPlugin;
- break;
- case 'priority':
- $struct = $this->depsStructPriority;
- break;
- case 'php_version':
- $struct = $this->depsStructPhpVersion;
- break;
-
- case 'php_extension':
- $struct = $this->depsStructPhpExtension;
- break;
- case 'php_ini':
- $struct = $this->depsStructPhpIni;
-
- if (isset($dep['value'])) {
- switch (strtolower($dep['value'])) {
- case 'yes':
- case 'true':
- case 'on':
- case 1:
- $dep['value'] = 1;
- break;
- case 'no':
- case 'false':
- case 'off':
- case 0:
- case '':
- $dep['value'] = 0;
- break;
- }
- }
- break;
- default:
-
- return $dep;
- }
-
- $normalized_dep = $this->buildStruct($struct, $dep);
-
- if (isset($normalized_dep['comparison'])) {
- switch ($normalized_dep['comparison']) {
- case '<':
- $normalized_dep['comparison'] = 'lt';
- break;
- case '<=':
- $normalized_dep['comparison'] = 'le';
- break;
- case '>':
- $normalized_dep['comparison'] = 'gt';
- break;
- case '>=':
- $normalized_dep['comparison'] = 'ge';
- break;
- case '==':
- case 'eq':
- $normalized_dep['comparison'] = '=';
- break;
- case '<>':
- case 'ne':
- $normalized_dep['comparison'] = '!=';
- break;
- }
- }
- return $normalized_dep;
- }
-
- public function getConflicts() {
-
- if ($this->getApiVersion() < 1.8) {
- $conflicts = array();
- } else {
- $conflicts = $this->parser->getAttribute('conflicts');
- }
- if (!$conflicts) {
- $conflicts = array();
- }
- $normalized = array();
- foreach ($conflicts as $conflict) {
- $normalized[] = $this->buildStruct($this->depsConflictsStruct, $conflict);
- }
- return $normalized;
- }
-
- public function getActivateOnInstall() {
- $activate = $this->parser->getAttribute('activate_on_install');
- switch (strtolower($activate)) {
- case 'yes':
- case 'true':
- case 'on':
- case 1:
- return true;
- case 'no':
- case 'false':
- case 'off':
- case 0:
- case '':
- return false;
- }
- }
-
- protected function buildStruct(array $struct, array $array) {
- $return = array();
- foreach ($struct as $index => $default) {
- $return[$index] = elgg_extract($index, $array, $default);
- }
- return $return;
- }
-
- static public function getFriendlyCategory($category) {
- $cat_raw_string = "admin:plugins:category:$category";
- $cat_display_string = _elgg_services()->translator->translate($cat_raw_string);
- if ($cat_display_string == $cat_raw_string) {
- $category = str_replace(array('-', '_'), ' ', $category);
- $cat_display_string = ucwords($category);
- }
- return $cat_display_string;
- }
- }
|