aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggPluginPackage.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes/ElggPluginPackage.php')
-rw-r--r--engine/classes/ElggPluginPackage.php102
1 files changed, 72 insertions, 30 deletions
diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php
index e1b3427cc..37eb4bf4d 100644
--- a/engine/classes/ElggPluginPackage.php
+++ b/engine/classes/ElggPluginPackage.php
@@ -28,6 +28,17 @@ class ElggPluginPackage {
);
/**
+ * The optional files that can be read and served through the markdown page handler
+ * @var array
+ */
+ private $textFiles = array(
+ 'README.txt', 'CHANGES.txt',
+ 'INSTALL.txt', 'COPYRIGHT.txt', 'LICENSE.txt',
+
+ 'README', 'README.md', 'README.markdown'
+ );
+
+ /**
* Valid types for provides.
*
* @var array
@@ -48,7 +59,7 @@ class ElggPluginPackage {
/**
* An invalid plugin error.
*/
- private $invalidPluginError = '';
+ private $errorMsg = '';
/**
* Any dependencies messages
@@ -89,7 +100,6 @@ class ElggPluginPackage {
* @param string $plugin The ID (directory name) or full path of the plugin.
* @param bool $validate Automatically run isValid()?
*
- * @return true
* @throws PluginException
*/
public function __construct($plugin, $validate = true) {
@@ -106,7 +116,7 @@ class ElggPluginPackage {
} else {
// this is a plugin id
// strict plugin names
- if (preg_match('/[^a-z0-9\.\-_]/i', $id)) {
+ if (preg_match('/[^a-z0-9\.\-_]/i', $plugin)) {
throw new PluginException(elgg_echo('PluginException:InvalidID', array($plugin)));
}
@@ -122,9 +132,9 @@ class ElggPluginPackage {
$this->id = $id;
if ($validate && !$this->isValid()) {
- if ($this->invalidPluginError) {
+ if ($this->errorMsg) {
throw new PluginException(elgg_echo('PluginException:InvalidPlugin:Details',
- array($plugin, $this->invalidPluginError)));
+ array($plugin, $this->errorMsg)));
} else {
throw new PluginException(elgg_echo('PluginException:InvalidPlugin', array($plugin)));
}
@@ -155,14 +165,12 @@ class ElggPluginPackage {
return $this->valid;
}
- $valid = true;
-
// check required files.
$have_req_files = true;
foreach ($this->requiredFiles as $file) {
if (!is_readable($this->path . $file)) {
$have_req_files = false;
- $this->invalidPluginError =
+ $this->errorMsg =
elgg_echo('ElggPluginPackage:InvalidPlugin:MissingFile', array($file));
break;
}
@@ -170,23 +178,21 @@ class ElggPluginPackage {
// check required files
if (!$have_req_files) {
- $valid = false;
+ return $this->valid = false;
}
// check for valid manifest.
if (!$this->loadManifest()) {
- $valid = false;
+ return $this->valid = false;
}
// can't require or conflict with yourself or something you provide.
// make sure provides are all valid.
if (!$this->isSaneDeps()) {
- $valid = false;
+ return $this->valid = false;
}
- $this->valid = $valid;
-
- return $valid;
+ return $this->valid = true;
}
/**
@@ -206,6 +212,7 @@ class ElggPluginPackage {
return false;
}
+ // Note: $conflicts and $requires are not unused. They're called dynamically
$conflicts = $this->getManifest()->getConflicts();
$requires = $this->getManifest()->getRequires();
$provides = $this->getManifest()->getProvides();
@@ -213,7 +220,7 @@ class ElggPluginPackage {
foreach ($provides as $provide) {
// only valid provide types
if (!in_array($provide['type'], $this->providesSupportedTypes)) {
- $this->invalidPluginError =
+ $this->errorMsg =
elgg_echo('ElggPluginPackage:InvalidPlugin:InvalidProvides', array($provide['type']));
return false;
}
@@ -223,7 +230,7 @@ class ElggPluginPackage {
foreach (array('conflicts', 'requires') as $dep_type) {
foreach (${$dep_type} as $dep) {
if (!in_array($dep['type'], $this->depsSupportedTypes)) {
- $this->invalidPluginError =
+ $this->errorMsg =
elgg_echo('ElggPluginPackage:InvalidPlugin:InvalidDependency', array($dep['type']));
return false;
}
@@ -233,7 +240,7 @@ class ElggPluginPackage {
$version_compare = version_compare($provide['version'], $dep['version'], $dep['comparison']);
if ($version_compare) {
- $this->invalidPluginError =
+ $this->errorMsg =
elgg_echo('ElggPluginPackage:InvalidPlugin:CircularDep',
array($dep['type'], $dep['name'], $this->id));
@@ -279,6 +286,7 @@ class ElggPluginPackage {
try {
$this->manifest = new ElggPluginManifest($file, $this->id);
} catch (Exception $e) {
+ $this->errorMsg = $e->getMessage();
return false;
}
@@ -286,9 +294,22 @@ class ElggPluginPackage {
return true;
}
+ $this->errorMsg = elgg_echo('unknown_error');
return false;
}
+ /****************
+ * Readme Files *
+ ***************/
+
+ /**
+ * Returns an array of present and readable text files
+ *
+ * @return array
+ */
+ public function getTextFilenames() {
+ return $this->textFiles;
+ }
/***********************
* Dependencies system *
@@ -310,23 +331,30 @@ class ElggPluginPackage {
* @return bool|array
*/
public function checkDependencies($full_report = false) {
+ // Note: $conflicts and $requires are not unused. They're called dynamically
$requires = $this->getManifest()->getRequires();
$conflicts = $this->getManifest()->getConflicts();
+
$enabled_plugins = elgg_get_plugins('active');
$this_id = $this->getID();
$report = array();
// first, check if any active plugin conflicts with us.
foreach ($enabled_plugins as $plugin) {
- $temp_conflicts = $plugin->manifest->getConflicts();
+ $temp_conflicts = array();
+ $temp_manifest = $plugin->getManifest();
+ if ($temp_manifest instanceof ElggPluginManifest) {
+ $temp_conflicts = $plugin->getManifest()->getConflicts();
+ }
foreach ($temp_conflicts as $conflict) {
if ($conflict['type'] == 'plugin' && $conflict['name'] == $this_id) {
$result = $this->checkDepPlugin($conflict, $enabled_plugins, false);
// rewrite the conflict to show the originating plugin
- $conflict['name'] = $plugin->manifest->getName();
+ $conflict['name'] = $plugin->getManifest()->getName();
if (!$full_report && !$result['status']) {
+ $this->errorMsg = "Conflicts with plugin \"{$plugin->getManifest()->getName()}\".";
return $result['status'];
} else {
$report[] = array(
@@ -343,6 +371,7 @@ class ElggPluginPackage {
$check_types = array('requires', 'conflicts');
if ($full_report) {
+ // Note: $suggests is not unused. It's called dynamically
$suggests = $this->getManifest()->getSuggests();
$check_types[] = 'suggests';
}
@@ -379,6 +408,7 @@ class ElggPluginPackage {
// unless we're doing a full report, break as soon as we fail.
if (!$full_report && !$result['status']) {
+ $this->errorMsg = "Missing dependencies.";
return $result['status'];
} else {
// build report element and comment
@@ -438,25 +468,29 @@ class ElggPluginPackage {
* @return bool
*/
private function checkDepPriority(array $dep, array $plugins, $inverse = false) {
- // see if we exist as an ElggPlugin
- $this_plugin = elgg_get_plugin_from_id($this->getID());
- $this_priority = $this_plugin->getPriority();
-
- foreach ($plugins as $test_plugin) {
- if ($test_plugin->getID() == $dep['plugin']) {
- break;
- }
+ // grab the ElggPlugin using this package.
+ $plugin_package = elgg_get_plugin_from_id($this->getID());
+ $plugin_priority = $plugin_package->getPriority();
+ $test_plugin = elgg_get_plugin_from_id($dep['plugin']);
+
+ // If this isn't a plugin or the plugin isn't installed or active
+ // priority doesn't matter. Use requires to check if a plugin is active.
+ if (!$plugin_package || !$test_plugin || !$test_plugin->isActive()) {
+ return array(
+ 'status' => true,
+ 'value' => 'uninstalled'
+ );
}
$test_plugin_priority = $test_plugin->getPriority();
switch ($dep['priority']) {
case 'before':
- $status = $this_priority < $test_plugin_priority;
+ $status = $plugin_priority < $test_plugin_priority;
break;
case 'after':
- $status = $this_priority > $test_plugin_priority;
+ $status = $plugin_priority > $test_plugin_priority;
break;
default;
@@ -464,7 +498,7 @@ class ElggPluginPackage {
}
// get the current value
- if ($this_priority < $test_plugin_priority) {
+ if ($plugin_priority < $test_plugin_priority) {
$value = 'before';
} else {
$value = 'after';
@@ -595,4 +629,12 @@ class ElggPluginPackage {
return $this->id;
}
+ /**
+ * Returns the last error message.
+ *
+ * @return string
+ */
+ public function getError() {
+ return $this->errorMsg;
+ }
}