diff --git a/include/class.plugin.php b/include/class.plugin.php index db496e33a026b6652836435a6705fa59963dd80d..4df5688435dc2eb1ae63c1c9cbdac1a1f3c8ffeb 100644 --- a/include/class.plugin.php +++ b/include/class.plugin.php @@ -164,15 +164,23 @@ class PluginManager { // read all plugins $info = static::getInfoForPath( INCLUDE_DIR . $ht['install_path'], $ht['isphar']); + list($path, $class) = explode(':', $info['plugin']); if (!$class) $class = $path; elseif ($ht['isphar']) - require_once('phar://' . INCLUDE_DIR . $ht['install_path'] + @include_once('phar://' . INCLUDE_DIR . $ht['install_path'] . '/' . $path); else - require_once(INCLUDE_DIR . $ht['install_path'] + @include_once(INCLUDE_DIR . $ht['install_path'] . '/' . $path); + + if (!class_exists($class)) { + $class = 'DefunctPlugin'; + $ht['isactive'] = false; + $info = array('name' => $ht['name'] . ' '. __('(defunct — missing)')); + } + if ($ht['isactive']) { static::$plugin_list[$ht['install_path']] = new $class($ht['id']); @@ -271,7 +279,9 @@ class PluginManager { if (!isset(static::$plugin_info[$install_path])) { // plugin.php is require to return an array of informaiton about // the plugin. - $info = array_merge($defaults, (include $path . '/plugin.php')); + if (!file_exists($path . '/plugin.php')) + return false; + $info = array_merge($defaults, (@include $path . '/plugin.php')); $info['install_path'] = $install_path; // XXX: Ensure 'id' key isset @@ -284,11 +294,14 @@ class PluginManager { static $instances = array(); if (!isset($instances[$path]) && ($ps = static::allInstalled()) - && ($ht = $ps[$path]) - && ($info = static::getInfoForPath($path))) { + && ($ht = $ps[$path])) { + + $info = static::getInfoForPath($path); + // $ht may be the plugin instance if ($ht instanceof Plugin) return $ht; + // Usually this happens when the plugin is being enabled list($path, $class) = explode(':', $info['plugin']); if (!$class) @@ -685,4 +698,11 @@ abstract class Plugin { } } +class DefunctPlugin extends Plugin { + function bootstrap() {} + + function enable() { + return false; + } +} ?> diff --git a/scp/plugins.php b/scp/plugins.php index ccc856e3a3f744b3060affde8a7dba95fd54650b..06b7cbcd2664471bc4de14ff12a45ba3343713fc 100644 --- a/scp/plugins.php +++ b/scp/plugins.php @@ -23,7 +23,10 @@ if($_POST) { case 'enable': foreach ($_POST['ids'] as $id) { if ($p = Plugin::lookup($id)) { - $p->enable(); + if (!$p->enable()) + $errors['err'] = sprintf( + __('Unable to enable %s.'), + $p->getName()); } } break;