aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/classes/ElggPluginManifest.php170
-rw-r--r--engine/classes/ElggPluginManifestParser18.php7
-rw-r--r--engine/classes/ElggPluginPackage.php9
-rw-r--r--engine/lib/plugins.php14
-rw-r--r--engine/tests/api/plugins.php16
-rw-r--r--engine/tests/test_files/plugin_18/manifest.xml6
6 files changed, 145 insertions, 77 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>