26 private $requiredFiles = array(
27 'start.php',
'manifest.xml' 34 private $textFiles = array(
35 'README.txt',
'CHANGES.txt',
36 'INSTALL.txt',
'COPYRIGHT.txt',
'LICENSE.txt',
38 'README',
'README.md',
'README.markdown' 46 private $providesSupportedTypes = array(
47 'plugin',
'php_extension' 55 private $depsSupportedTypes = array(
56 'elgg_version',
'elgg_release',
'php_version',
'php_extension',
'php_ini',
'plugin',
'priority',
62 private $errorMsg =
'';
109 $path_array = explode(
'/', trim(
$path,
'/'));
110 $id = array_pop($path_array);
114 if (preg_match(
'/[^a-z0-9\.\-_]/i',
$plugin)) {
115 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidID', array(
$plugin)));
118 $path =
"{$plugin_path}$plugin/";
122 if (!is_dir(
$path)) {
123 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidPath', array(
$path)));
129 if ($validate && !$this->
isValid()) {
130 if ($this->errorMsg) {
131 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidPlugin:Details',
132 array(
$plugin, $this->errorMsg)));
134 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidPlugin', array(
$plugin)));
157 if (!isset($this->valid)) {
158 $this->valid = $this->validate();
166 private function validate() {
168 $have_req_files =
true;
169 foreach ($this->requiredFiles as $file) {
170 if (!is_readable($this->
path . $file)) {
171 $have_req_files =
false;
173 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:MissingFile', array($file));
179 if (!$have_req_files) {
180 return $this->valid =
false;
184 if (!$this->loadManifest()) {
188 if (!$this->isNamedCorrectly()) {
194 if (!$this->hasSaneDependencies()) {
207 private function isNamedCorrectly() {
211 if (!empty($required_id) && ($required_id !== $this->
id)) {
213 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:InvalidId', array($required_id));
231 private function hasSaneDependencies() {
242 foreach ($provides as $provide) {
244 if (!in_array($provide[
'type'], $this->providesSupportedTypes)) {
246 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:InvalidProvides', array($provide[
'type']));
251 $name = $provide[
'name'];
252 foreach (array(
'conflicts',
'requires') as $dep_type) {
253 foreach (${$dep_type} as $dep) {
254 if (!in_array($dep[
'type'], $this->depsSupportedTypes)) {
256 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:InvalidDependency', array($dep[
'type']));
261 if (isset($dep[
'name']) && $dep[
'name'] ==
$name) {
262 $version_compare = version_compare($provide[
'version'], $dep[
'version'], $dep[
'comparison']);
264 if ($version_compare) {
266 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:CircularDep',
267 array($dep[
'type'], $dep[
'name'], $this->
id));
290 if (!$this->manifest) {
291 if (!$this->loadManifest()) {
305 private function loadManifest() {
306 $file = $this->
path .
'manifest.xml';
309 $this->manifest = new \ElggPluginManifest($file, $this->
id);
311 $this->errorMsg = $e->getMessage();
319 $this->errorMsg =
_elgg_services()->translator->translate(
'unknown_error');
333 return $this->textFiles;
361 $this_id = $this->
getID();
365 foreach ($enabled_plugins as
$plugin) {
366 $temp_conflicts = array();
367 $temp_manifest = $plugin->getManifest();
369 $temp_conflicts = $plugin->getManifest()->getConflicts();
371 foreach ($temp_conflicts as $conflict) {
372 if ($conflict[
'type'] ==
'plugin' && $conflict[
'name'] == $this_id) {
373 $result = $this->checkDepPlugin($conflict, $enabled_plugins,
false);
376 $conflict[
'name'] = $plugin->getManifest()->getName();
378 if (!$full_report && !
$result[
'status']) {
379 $this->errorMsg =
"Conflicts with plugin \"{$plugin->getManifest()->getName()}\".";
383 'type' =>
'conflicted',
393 $check_types = array(
'requires',
'conflicts');
398 $check_types[] =
'suggests';
401 foreach ($check_types as $dep_type) {
402 $inverse = ($dep_type ==
'conflicts') ?
true :
false;
404 foreach (${$dep_type} as $dep) {
405 switch ($dep[
'type']) {
416 $result = $this->checkDepPlugin($dep, $enabled_plugins, $inverse);
420 $result = $this->checkDepPriority($dep, $enabled_plugins, $inverse);
424 $result = $this->checkDepPhpVersion($dep, $inverse);
427 case 'php_extension':
428 $result = $this->checkDepPhpExtension($dep, $inverse);
432 $result = $this->checkDepPhpIni($dep, $inverse);
442 if (!$full_report && !
$result[
'status']) {
443 $this->errorMsg =
"Missing dependencies.";
462 foreach ($provides as $provide) {
464 'type' =>
'provides',
485 private function checkDepPlugin(array $dep, array
$plugins, $inverse =
false) {
489 $r[
'status'] = !
$r[
'status'];
503 private function checkDepPriority(array $dep, array $plugins, $inverse =
false) {
506 if (!$plugin_package) {
509 'value' =>
'uninstalled' 517 if (!$test_plugin || !$test_plugin->isActive()) {
520 'value' =>
'uninstalled' 524 $plugin_priority = $plugin_package->getPriority();
525 $test_plugin_priority = $test_plugin->getPriority();
527 switch ($dep[
'priority']) {
529 $status = $plugin_priority < $test_plugin_priority;
533 $status = $plugin_priority > $test_plugin_priority;
541 if ($plugin_priority < $test_plugin_priority) {
565 private function checkDepElgg(array $dep, $elgg_version, $inverse =
false) {
566 $status = version_compare($elgg_version, $dep[
'version'], $dep[
'comparison']);
574 'value' => $elgg_version
585 private function checkDepPhpVersion(array $dep, $inverse =
false) {
586 $php_version = phpversion();
587 $status = version_compare($php_version, $dep[
'version'], $dep[
'comparison']);
595 'value' => $php_version
611 private function checkDepPhpExtension(array $dep, $inverse =
false) {
612 $name = $dep[
'name'];
614 $comparison = $dep[
'comparison'];
617 $status = extension_loaded(
$name);
620 $ext_version = phpversion(
$name);
626 $status = version_compare($ext_version,
$version, $comparison);
630 $ext_version =
'???';
635 if ($status ==
false) {
637 $status = $provides[
'status'];
638 $ext_version = $provides[
'value'];
647 'value' => $ext_version
658 private function checkDepPhpIni($dep, $inverse =
false) {
659 $name = $dep[
'name'];
661 $comparison = $dep[
'comparison'];
666 $setting = ini_get(
$name);
668 if ($setting ===
'') {
672 $status = version_compare($setting,
$value, $comparison);
699 return $this->errorMsg;
if($guid==elgg_get_logged_in_user_guid()) $name
_elgg_check_plugins_provides($type, $name, $version=null, $comparison= 'ge')
Checks if a plugin is currently providing $type and $name, and optionally checking a version...
getManifest()
Returns a parsed manifest file.
checkDependencies($full_report=false)
Returns if the Elgg system meets the plugin's dependency requirements.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
$CONFIG path
The full path where Elgg is installed.
getTextFilenames()
Returns an array of present and readable text files.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
__construct($plugin, $validate=true)
Load a plugin package from mod/$id or by full path.
elgg_get_version($human_readable=false)
Get the current Elgg version information.
getError()
Returns the last error message.
getID()
Returns the Plugin ID.
isValid()
Checks if this is a valid Elgg plugin.
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.