28 private $requiredFiles = array(
29 'start.php',
'manifest.xml' 36 private $textFiles = array(
37 'README.txt',
'CHANGES.txt',
38 'INSTALL.txt',
'COPYRIGHT.txt',
'LICENSE.txt',
40 'README',
'README.md',
'README.markdown' 48 private $providesSupportedTypes = array(
49 'plugin',
'php_extension' 57 private $depsSupportedTypes = array(
58 'elgg_release',
'php_version',
'php_extension',
'php_ini',
'plugin',
'priority',
64 private $errorMsg =
'';
111 $path_array = explode(
'/', trim(
$path,
'/'));
112 $id = array_pop($path_array);
116 if (preg_match(
'/[^a-z0-9\.\-_]/i',
$plugin)) {
117 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidID', array(
$plugin)));
120 $path =
"{$plugin_path}$plugin/";
124 if (!is_dir(
$path)) {
125 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidPath', array(
$path)));
131 if ($validate && !$this->
isValid()) {
132 if ($this->errorMsg) {
133 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidPlugin:Details',
134 array(
$plugin, $this->errorMsg)));
136 throw new \PluginException(
_elgg_services()->translator->translate(
'PluginException:InvalidPlugin', array(
$plugin)));
159 if (!isset($this->valid)) {
160 $this->valid = $this->validate();
168 private function validate() {
170 $have_req_files =
true;
171 foreach ($this->requiredFiles as
$file) {
172 if (!is_readable($this->
path . $file)) {
173 $have_req_files =
false;
175 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:MissingFile', array($file));
181 if (!$have_req_files) {
182 return $this->valid =
false;
186 if (!$this->loadManifest()) {
190 if (!$this->isNamedCorrectly()) {
196 if (!$this->hasSaneDependencies()) {
200 if (!$this->hasReadableConfigFile()) {
213 private function hasReadableConfigFile() {
214 $file =
"{$this->path}/" . self::STATIC_CONFIG_FILENAME;
215 if (!is_file(
$file)) {
219 if (is_readable(
$file)) {
224 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:UnreadableConfig');
234 private function isNamedCorrectly() {
238 if (!empty($required_id) && ($required_id !== $this->
id)) {
240 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:InvalidId', array($required_id));
258 private function hasSaneDependencies() {
269 foreach ($provides as $provide) {
271 if (!in_array($provide[
'type'], $this->providesSupportedTypes)) {
273 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:InvalidProvides', array($provide[
'type']));
278 $name = $provide[
'name'];
279 foreach (array(
'conflicts',
'requires') as $dep_type) {
280 foreach (${$dep_type} as $dep) {
281 if (!in_array($dep[
'type'], $this->depsSupportedTypes)) {
283 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:InvalidDependency', array($dep[
'type']));
288 if (isset($dep[
'name']) && $dep[
'name'] ==
$name) {
289 $version_compare = version_compare($provide[
'version'], $dep[
'version'], $dep[
'comparison']);
291 if ($version_compare) {
293 _elgg_services()->translator->translate(
'ElggPluginPackage:InvalidPlugin:CircularDep',
294 array($dep[
'type'], $dep[
'name'], $this->
id));
317 if (!$this->manifest) {
318 if (!$this->loadManifest()) {
332 private function loadManifest() {
336 $this->manifest = new \ElggPluginManifest(
$file, $this->
id);
338 $this->errorMsg = $e->getMessage();
346 $this->errorMsg =
_elgg_services()->translator->translate(
'unknown_error');
360 return $this->textFiles;
388 $this_id = $this->
getID();
392 foreach ($enabled_plugins as
$plugin) {
393 $temp_conflicts = array();
394 $temp_manifest = $plugin->getManifest();
396 $temp_conflicts = $plugin->getManifest()->getConflicts();
398 foreach ($temp_conflicts as $conflict) {
399 if ($conflict[
'type'] ==
'plugin' && $conflict[
'name'] == $this_id) {
400 $result = $this->checkDepPlugin($conflict, $enabled_plugins,
false);
403 $conflict[
'name'] = $plugin->getManifest()->getName();
405 if (!$full_report && !
$result[
'status']) {
406 $css_id = preg_replace(
'/[^a-z0-9-]/i',
'-', $plugin->getManifest()->getID());
408 'text' => $plugin->getManifest()->getName(),
409 'href' =>
"#$css_id",
412 $key =
'ElggPluginPackage:InvalidPlugin:ConflictsWithPlugin';
413 $this->errorMsg =
_elgg_services()->translator->translate($key, [$link]);
417 'type' =>
'conflicted',
427 $check_types = array(
'requires',
'conflicts');
432 $check_types[] =
'suggests';
435 foreach ($check_types as $dep_type) {
436 $inverse = ($dep_type ==
'conflicts') ?
true :
false;
438 foreach (${$dep_type} as $dep) {
439 switch ($dep[
'type']) {
445 $result = $this->checkDepPlugin($dep, $enabled_plugins, $inverse);
449 $result = $this->checkDepPriority($dep, $enabled_plugins, $inverse);
453 $result = $this->checkDepPhpVersion($dep, $inverse);
456 case 'php_extension':
457 $result = $this->checkDepPhpExtension($dep, $inverse);
461 $result = $this->checkDepPhpIni($dep, $inverse);
471 if (!$full_report && !
$result[
'status']) {
472 $this->errorMsg =
"Missing dependencies.";
491 foreach ($provides as $provide) {
493 'type' =>
'provides',
514 private function checkDepPlugin(array $dep, array $plugins, $inverse =
false) {
518 $r[
'status'] = !
$r[
'status'];
532 private function checkDepPriority(array $dep, array $plugins, $inverse =
false) {
535 if (!$plugin_package) {
538 'value' =>
'uninstalled' 546 if (!$test_plugin || !$test_plugin->isActive()) {
549 'value' =>
'uninstalled' 553 $plugin_priority = $plugin_package->getPriority();
554 $test_plugin_priority = $test_plugin->getPriority();
556 switch ($dep[
'priority']) {
558 $status = $plugin_priority < $test_plugin_priority;
562 $status = $plugin_priority > $test_plugin_priority;
570 if ($plugin_priority < $test_plugin_priority) {
594 private function checkDepElgg(array $dep, $elgg_version, $inverse =
false) {
595 $status = version_compare($elgg_version, $dep[
'version'], $dep[
'comparison']);
603 'value' => $elgg_version
614 private function checkDepPhpVersion(array $dep, $inverse =
false) {
615 $php_version = phpversion();
616 $status = version_compare($php_version, $dep[
'version'], $dep[
'comparison']);
624 'value' => $php_version
640 private function checkDepPhpExtension(array $dep, $inverse =
false) {
641 $name = $dep[
'name'];
643 $comparison = $dep[
'comparison'];
646 $status = extension_loaded(
$name);
649 $ext_version = phpversion(
$name);
655 $status = version_compare($ext_version,
$version, $comparison);
659 $ext_version =
'???';
664 if ($status ==
false) {
666 $status = $provides[
'status'];
667 $ext_version = $provides[
'value'];
676 'value' => $ext_version
687 private function checkDepPhpIni($dep, $inverse =
false) {
688 $name = $dep[
'name'];
690 $comparison = $dep[
'comparison'];
695 $setting = ini_get(
$name);
697 if ($setting ===
'') {
701 $status = version_compare($setting,
$value, $comparison);
728 return $this->errorMsg;
if(!array_key_exists($filename, $text_files)) $file
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_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
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.
const STATIC_CONFIG_FILENAME
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.