diff options
-rw-r--r-- | engine/classes/ElggPluginManifest.php | 170 | ||||
-rw-r--r-- | engine/classes/ElggPluginManifestParser18.php | 7 | ||||
-rw-r--r-- | engine/classes/ElggPluginPackage.php | 9 | ||||
-rw-r--r-- | engine/lib/plugins.php | 14 | ||||
-rw-r--r-- | engine/tests/api/plugins.php | 16 | ||||
-rw-r--r-- | engine/tests/test_files/plugin_18/manifest.xml | 6 | ||||
-rw-r--r-- | languages/en.php | 4 | ||||
-rw-r--r-- | views/default/admin/components/plugin.php | 8 | ||||
-rw-r--r-- | views/default/admin/components/plugin_dependencies.php | 5 | ||||
-rw-r--r-- | views/default/css/admin.php | 14 |
10 files changed, 168 insertions, 85 deletions
diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 7a261a755..7c9c0670e 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -25,7 +25,7 @@ class ElggPluginManifest { /** * The expected structure of a requires element */ - private $depsRequiresStructPlugin = array( + private $depsStructPlugin = array( 'type' => '', 'name' => '', 'version' => '', @@ -35,7 +35,7 @@ class ElggPluginManifest { /** * The expected structure of a requires element */ - private $depsRequiresStructPriority = array( + private $depsStructPriority = array( 'type' => '', 'priority' => '', 'plugin' => '' @@ -44,7 +44,7 @@ class ElggPluginManifest { /* * The expected structure of elgg and elgg_release requires element */ - private $depsRequiresStructElgg = array( + private $depsStructElgg = array( 'type' => '', 'version' => '', 'comparison' => 'ge' @@ -53,7 +53,7 @@ class ElggPluginManifest { /** * The expected structure of a requires php_ini dependency element */ - private $depsRequiresStructPhpIni = array( + private $depsStructPhpIni = array( 'type' => '', 'name' => '', 'value' => '', @@ -63,7 +63,7 @@ class ElggPluginManifest { /** * The expected structure of a requires php_extension dependency element */ - private $depsRequiresStructPhpExtension = array( + private $depsStructPhpExtension = array( 'type' => '', 'name' => '', 'version' => '', @@ -427,88 +427,118 @@ class ElggPluginManifest { $normalized = array(); foreach ($reqs as $req) { + $normalized[] = $this->normalizeDep($req); + } - switch ($req['type']) { - case 'elgg_version': - case 'elgg_release': - $struct = $this->depsRequiresStructElgg; - break; + return $normalized; + } - case 'plugin': - $struct = $this->depsRequiresStructPlugin; - break; + /** + * Returns the suggests elements. + * + * @return array + */ + public function getSuggests() { + $suggests = $this->parser->getAttribute('suggests'); - case 'priority': - $struct = $this->depsRequiresStructPriority; - break; + if (!$suggests) { + $suggests = array(); + } - case 'php_extension': - $struct = $this->depsRequiresStructPhpExtension; - break; + $normalized = array(); + foreach ($suggests as $suggest) { + $normalized[] = $this->normalizeDep($suggest); + } + + return $normalized; + } - case 'php_ini': - $struct = $this->depsRequiresStructPhpIni; - - // also normalize boolean values - if (isset($req['value'])) { - switch (strtolower($normalized_req['value'])) { - case 'yes': - case 'true': - case 'on': - case 1: - $normalized_req['value'] = 1; - break; - - case 'no': - case 'false': - case 'off': - case 0: - case '': - $normalized_req['value'] = 0; - break; - } + /** + * Normalizes a dependency array using the defined structs. + * Can be used with either requires or suggests. + * + * @param array $dep An dependency array. + * @return array The normalized deps array. + */ + 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_extension': + $struct = $this->depsStructPhpExtension; + break; + + case 'php_ini': + $struct = $this->depsStructPhpIni; + + // also normalize boolean values + if (isset($dep['value'])) { + switch (strtolower($normalized_dep['value'])) { + case 'yes': + case 'true': + case 'on': + case 1: + $normalized_dep['value'] = 1; + break; + + case 'no': + case 'false': + case 'off': + case 0: + case '': + $normalized_dep['value'] = 0; + break; } + } - break; - } + break; + } - $normalized_req = $this->buildStruct($struct, $req); + $normalized_dep = $this->buildStruct($struct, $dep); - // normalize comparison operators - if (isset($normalized_req['comparison'])) { - switch ($normalized_req['comparison']) { - case '<': - $normalized_req['comparison'] = 'lt'; - break; + // normalize comparison operators + if (isset($normalized_dep['comparison'])) { + switch ($normalized_dep['comparison']) { + case '<': + $normalized_dep['comparison'] = 'lt'; + break; - case '<=': - $normalized_req['comparison'] = 'le'; - break; + case '<=': + $normalized_dep['comparison'] = 'le'; + break; - case '>': - $normalized_req['comparison'] = 'gt'; - break; + case '>': + $normalized_dep['comparison'] = 'gt'; + break; - case '>=': - $normalized_req['comparison'] = 'ge'; - break; + case '>=': + $normalized_dep['comparison'] = 'ge'; + break; - case '==': - case 'eq': - $normalized_req['comparison'] = '='; - break; + case '==': + case 'eq': + $normalized_dep['comparison'] = '='; + break; - case '<>': - case 'ne': - $normalized_req['comparison'] = '!='; - break; - } + case '<>': + case 'ne': + $normalized_dep['comparison'] = '!='; + break; } - - $normalized[] = $normalized_req; } - return $normalized; + return $normalized_dep; } /** diff --git a/engine/classes/ElggPluginManifestParser18.php b/engine/classes/ElggPluginManifestParser18.php index 1f5b51bb5..c74b23e32 100644 --- a/engine/classes/ElggPluginManifestParser18.php +++ b/engine/classes/ElggPluginManifestParser18.php @@ -14,9 +14,9 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { */ protected $validAttributes = array( 'name', 'author', 'version', 'blurb', 'description', - 'website', 'copyright', 'license', 'requires', 'screenshot', - 'category', 'conflicts', 'provides', 'on_activate', 'on_deactivate', - 'admin_interface', 'activate_on_install' + 'website', 'copyright', 'license', 'requires', 'suggests', + 'screenshot', 'category', 'conflicts', 'provides', 'on_activate', + 'on_deactivate', 'admin_interface', 'activate_on_install' ); /** @@ -63,6 +63,7 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { case 'provides': case 'conflicts': case 'requires': + case 'suggests': if (!isset($element->children)) { return false; } diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 48a5fc4a8..2ae686b25 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -340,7 +340,14 @@ class ElggPluginPackage { } } - foreach (array('requires', 'conflicts') as $dep_type) { + $check_types = array('requires', 'conflicts'); + + if ($full_report) { + $suggests = $this->getManifest()->getSuggests(); + $check_types[] = 'suggests'; + } + + foreach ($check_types as $dep_type) { $inverse = ($dep_type == 'conflicts') ? true : false; foreach (${$dep_type} as $dep) { diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 31420a826..8d6daef6e 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -722,10 +722,18 @@ function elgg_get_plugin_dependency_strings($dep) { break; } - if ($dep['status']) { - $strings['comment'] = elgg_echo('ok'); + if ($dep['type'] == 'suggests') { + if ($dep['status']) { + $strings['comment'] = elgg_echo('ok'); + } else { + $strings['comment'] = elgg_echo('ElggPlugin:Dependencies:Suggests:Unsatisfied'); + } } else { - $strings['comment'] = elgg_echo('error'); + if ($dep['status']) { + $strings['comment'] = elgg_echo('ok'); + } else { + $strings['comment'] = elgg_echo('error'); + } } return $strings; diff --git a/engine/tests/api/plugins.php b/engine/tests/api/plugins.php index ac1278410..853af45e9 100644 --- a/engine/tests/api/plugins.php +++ b/engine/tests/api/plugins.php @@ -101,6 +101,10 @@ class ElggCorePluginsAPITest extends ElggCoreUnitTest { array('type' => 'php_extension', 'name' => 'big_math', 'version' => 1.0) ), + 'suggests' => array( + array('type' => 'plugin', 'name' => 'facebook_connect', 'version' => 1.0), + ), + 'on_activate' => array('setup_function'), 'on_deactivate' => array('teardown_function'), 'admin_interface' => 'simple', @@ -196,6 +200,18 @@ class ElggCorePluginsAPITest extends ElggCoreUnitTest { $this->assertEqual($this->package17->getManifest()->getRequires(), $requires); } + public function testElggPluginManifestGetSuggests() { + $suggests = array( + array('type' => 'plugin', 'name' => 'facebook_connect', 'version' => '1.0', 'comparison' => 'ge'), + ); + + $this->assertEqual($this->package18->getManifest()->getSuggests(), $suggests); + + $suggests = array(); + + $this->assertEqual($this->package17->getManifest()->getSuggests(), $suggests); + } + public function testElggPluginManifestGetDescription() { $this->assertEqual($this->package18->getManifest()->getDescription(), 'A longer, more interesting description.'); $this->assertEqual($this->package17->getManifest()->getDescription(), 'A 1.7-style manifest.'); diff --git a/engine/tests/test_files/plugin_18/manifest.xml b/engine/tests/test_files/plugin_18/manifest.xml index 2a4d72c65..76837977d 100644 --- a/engine/tests/test_files/plugin_18/manifest.xml +++ b/engine/tests/test_files/plugin_18/manifest.xml @@ -99,4 +99,10 @@ <version>1.0</version> </provides> + <suggests> + <type>plugin</type> + <name>facebook_connect</name> + <version>1.0</version> + </suggests> + </plugin_manifest> diff --git a/languages/en.php b/languages/en.php index 2dd61751e..5195264bd 100644 --- a/languages/en.php +++ b/languages/en.php @@ -7,7 +7,6 @@ */ $english = array( - /** * Sites */ @@ -85,6 +84,7 @@ $english = array( 'PluginException:ParserErrorMissingRequiredAttribute' => "Missing required '%s' attribute in manifest for plugin %s.", 'ElggPlugin:Dependencies:Requires' => 'Requires', + 'ElggPlugin:Dependencies:Suggests' => 'Suggests', 'ElggPlugin:Dependencies:Conflicts' => 'Conflicts', 'ElggPlugin:Dependencies:Conflicted' => 'Conflicted', 'ElggPlugin:Dependencies:Provides' => 'Provides', @@ -96,7 +96,7 @@ $english = array( 'ElggPlugin:Dependencies:Plugin' => 'Plugin: %s', 'ElggPlugin:Dependencies:Priority:After' => 'After %s', 'ElggPlugin:Dependencies:Priority:Before' => 'Before %s', - + 'ElggPlugin:Dependencies:Suggests:Unsatisfied' => 'Missing', 'InvalidParameterException:NonElggUser' => "Passing a non-ElggUser to an ElggUser constructor!", diff --git a/views/default/admin/components/plugin.php b/views/default/admin/components/plugin.php index 229dd8c57..e75c2c63e 100644 --- a/views/default/admin/components/plugin.php +++ b/views/default/admin/components/plugin.php @@ -167,15 +167,12 @@ if (elgg_view_exists($settings_view)) { } ?> <h3 class="elgg-head"><?php echo $plugin->manifest->getName() . " $version $settings_link"; ?></h3> - <div class="plugin_description"><?php echo $description; ?></div> - <p class="plugin_author"><?php echo $author . ' - ' . $website; ?></p> - <?php if ($plugin->manifest->getApiVersion() < 1.8) { $reqs = $plugin->manifest->getRequires(); if (!$reqs) { $message = elgg_echo('admin:plugins:warning:elgg_version_unknown'); - echo "<p class=\"plugin-cannot-activate\">$message</p>"; + echo "<p class=\"elgg-unsatisfied-dependency\">$message</p>"; } } @@ -185,6 +182,9 @@ if (elgg_view_exists($settings_view)) { } ?> + <div class="plugin_description"><?php echo $description; ?></div> + <p class="plugin_author"><?php echo $author . ' - ' . $website; ?></p> + <div class="pts"><a class="manifest_details small link"><?php echo elgg_echo("admin:plugins:label:moreinfo"); ?></a></div> <div class="manifest_file hidden"> diff --git a/views/default/admin/components/plugin_dependencies.php b/views/default/admin/components/plugin_dependencies.php index cd38e98b0..bb0fa4eec 100644 --- a/views/default/admin/components/plugin_dependencies.php +++ b/views/default/admin/components/plugin_dependencies.php @@ -27,11 +27,12 @@ echo '<tr/>'; $row = 'odd'; foreach ($deps as $dep) { $fields = elgg_get_plugin_dependency_strings($dep); + $type = $dep['type']; if ($dep['status']) { - $class = 'elgg-satisfied-dependency'; + $class = "elgg-satisfied-dependency elgg-dependency-$type"; } else { - $class = 'elgg-unsatisfied-dependency'; + $class = "elgg-unsatisfied-dependency elgg-dependency-$type"; } echo "<tr class=\"$row\">"; diff --git a/views/default/css/admin.php b/views/default/css/admin.php index e1aee66fe..729c770bb 100644 --- a/views/default/css/admin.php +++ b/views/default/css/admin.php @@ -1001,6 +1001,7 @@ ul.admin_plugins { .plugin_details h3 { margin-top:-13px; color:black; + padding-bottom: 10px; } .plugin_settings { font-weight: normal; @@ -1008,9 +1009,22 @@ ul.admin_plugins { .elgg-unsatisfied-dependency { font-weight: bold; } +.elgg-dependency-suggests { + font-weight: normal; +} +p.elgg-unsatisfied-dependency { + padding: 5px 0; + font-weight: bold; +} +p.elgg-dependency-suggests { + font-weight: normal; +} .elgg-plugin-screenshot { display: inline; } +.elgg-plugin-screenshot img { + border: 1px solid #999999; +} .elgg-plugin-screenshot-lightbox { display: block; position: absolute; |