diff --git a/inc/lib_base.php b/inc/lib_base.php index aae9048f09..521694bf53 100644 --- a/inc/lib_base.php +++ b/inc/lib_base.php @@ -84,7 +84,9 @@ oc_require_once('lib_ocs.php'); @oc_require_once('MDB2/Schema.php'); oc_require_once('lib_connect.php'); oc_require_once('lib_remotestorage.php'); +oc_require_once('lib_plugin.php'); +OC_PLUGIN::loadPlugins(); if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ @mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)"); @@ -289,34 +291,6 @@ class OC_UTIL { }else{ echo(''); } } - - /** - * Load the plugins - */ - public static function loadPlugins() { - global $CONFIG_LOADPLUGINS; - global $SERVERROOT; - - $CONFIG_LOADPLUGINS = 'all'; - if ( 'all' !== $CONFIG_LOADPLUGINS ) { - $plugins = explode(' ', $CONFIG_LOADPLUGINS); - } else { - $plugins = array(); - $fd = opendir($SERVERROOT . '/plugins'); - while ( false !== ($filename = readdir($fd)) ) { - if ( $filename<>'.' AND $filename<>'..' AND ('.' != substr($filename, 0, 1)) ) { - $plugins[] = $filename; - } - } - closedir($fd); - } - if ( isset($plugins[0]) ) { - foreach ( $plugins as $plugin ) { - oc_require_once('/plugins/' . $plugin . '/lib_' . $plugin . '.php'); - } - } - } - } diff --git a/inc/lib_plugin.php b/inc/lib_plugin.php new file mode 100644 index 0000000000..178179a05e --- /dev/null +++ b/inc/lib_plugin.php @@ -0,0 +1,134 @@ +. +* +*/ + +class OC_PLUGIN{ + static private $blacklist=array(); + + /** + * load the plugin with the given id + * @param string id + * @return bool + */ + static public function load($id){ + global $SERVERROOT; + if(is_dir($SERVERROOT.'/plugins/'.$id) and is_file($SERVERROOT.'/plugins/'.$id.'/plugin.xml')){ + $plugin=new DOMDocument(); + $plugin->load($SERVERROOT.'/plugins/'.$id.'/plugin.xml'); + $pluginId=$plugin->getElementsByTagName('id')->item(0)->textContent; + if($pluginId==$id){//sanity check for plugins installed in the wrong folder + $childs=$plugin->documentElement->childNodes; + foreach($childs as $child){ + if($child->nodeType==XML_ELEMENT_NODE and $child->tagName=='include'){ + $file=$SERVERROOT.'/plugins/'.$id.'/'.$child->textContent; + include($file); + } + } + return true; + } + } + return false; + } + + /** + * Load all plugins that aren't blacklisted + */ + public static function loadPlugins() { + global $SERVERROOT; + $plugins = array(); + $blacklist=self::loadBlacklist(); + $fd = opendir($SERVERROOT . '/plugins'); + while ( false !== ($filename = readdir($fd)) ) { + if ( $filename<>'.' AND $filename<>'..' AND ('.' != substr($filename, 0, 1)) AND array_search($filename,$blacklist)===false) { + self::load($filename); + } + } + closedir($fd); + } + + /** + * load the blacklist from blacklist.txt + * @return array + */ + private static function loadBlacklist(){ + global $SERVERROOT; + if(count(self::$blacklist)>0){ + return self::$blacklist; + } + $blacklist=array(); + if(is_file($SERVERROOT.'/plugins/blacklist.txt')){ + $file=file_get_contents($SERVERROOT.'/plugins/blacklist.txt'); + $lines=explode("\n",$file); + foreach($lines as $line){ + $id=trim($line); + if($id!='' and is_dir($SERVERROOT.'/plugins/'.$id)){ + $blacklist[]=$id; + } + } + } + self::$blacklist=$blacklist; + return $blacklist; + } + + /** + * save a blacklist to blacklist.txt + * @param array blacklist + */ + private static function saveBlacklist($blacklist){ + global $SERVERROOT; + $file=''; + foreach($blacklist as $item){ + $file.="$item\n"; + } + self::$blacklist=$blacklist; + file_put_contents($SERVERROOT.'/plugins/blacklist.txt',$file); + } + + /** + * add a plugin to the blacklist + * @param string id + */ + public static function addToBlacklist($id){ + $blacklist=self::loadBlacklist(); + if(array_search($id,$blacklist)===false){ + $blacklist[]=$id; + self::$blacklist=$blacklist; + self::saveBlacklist($blacklist); + } + } + + /** + * remove a plugin to the blacklist + * @param string id + */ + public static function removeFromBlacklist($id){ + $blacklist=self::loadBlacklist(); + $index=array_search($id,$blacklist); + if($index!==false){ + unset($blacklist[$index]); + self::$blacklist=$blacklist; + self::saveBlacklist($blacklist); + } + } +} + +?> diff --git a/inc/lib_user.php b/inc/lib_user.php index 1d0cb86c6a..0d9b1c5dda 100644 --- a/inc/lib_user.php +++ b/inc/lib_user.php @@ -23,8 +23,6 @@ global $CONFIG_BACKEND; -OC_UTIL::loadPlugins(); - if ( !$CONFIG_INSTALLED ) { diff --git a/plugins/blacklist.txt b/plugins/blacklist.txt new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/plugins/blacklist.txt @@ -0,0 +1 @@ +test diff --git a/plugins/ldap/plugin.xml b/plugins/ldap/plugin.xml new file mode 100644 index 0000000000..c58ac4dd3d --- /dev/null +++ b/plugins/ldap/plugin.xml @@ -0,0 +1,11 @@ + + + + ldap + LDAP support for ownCloud + 0.1 + AGPL + fabian + + lib_ldap.php + \ No newline at end of file diff --git a/plugins/music/plugin.xml b/plugins/music/plugin.xml new file mode 100644 index 0000000000..5377e439ae --- /dev/null +++ b/plugins/music/plugin.xml @@ -0,0 +1,11 @@ + + + + music + Music player for ownCloud + 0.1 + AGPL + 2010 Frank Karlitschek karlitschek@kde.org + + lib_music.php + diff --git a/plugins/test/plugin.xml b/plugins/test/plugin.xml new file mode 100644 index 0000000000..5f510f2c38 --- /dev/null +++ b/plugins/test/plugin.xml @@ -0,0 +1,12 @@ + + + + test + Test plugin + 0.1 + AGPL + 2010 Frank Karlitschek karlitschek@kde.org + + lib_test.php + +