use new plugin system for loading plugins

remotes/origin/stable
Robin Appelman 15 years ago
parent 687cb29c7d
commit 98e49c7552
  1. 30
      inc/lib_base.php
  2. 134
      inc/lib_plugin.php
  3. 2
      inc/lib_user.php
  4. 1
      plugins/blacklist.txt
  5. 11
      plugins/ldap/plugin.xml
  6. 11
      plugins/music/plugin.xml
  7. 12
      plugins/test/plugin.xml

@ -84,7 +84,9 @@ oc_require_once('lib_ocs.php');
@oc_require_once('MDB2/Schema.php'); @oc_require_once('MDB2/Schema.php');
oc_require_once('lib_connect.php'); oc_require_once('lib_connect.php');
oc_require_once('lib_remotestorage.php'); oc_require_once('lib_remotestorage.php');
oc_require_once('lib_plugin.php');
OC_PLUGIN::loadPlugins();
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ 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)"); @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('<td><img src="'.$WEBROOT.'/img/icons/other.png" width="16" height="16"></td>'); }else{ echo('<td><img src="'.$WEBROOT.'/img/icons/other.png" width="16" height="16"></td>');
} }
} }
/**
* 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');
}
}
}
} }

@ -0,0 +1,134 @@
<?php
/**
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
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);
}
}
}
?>

@ -23,8 +23,6 @@
global $CONFIG_BACKEND; global $CONFIG_BACKEND;
OC_UTIL::loadPlugins();
if ( !$CONFIG_INSTALLED ) { if ( !$CONFIG_INSTALLED ) {

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<plugin>
<meta>
<id>ldap</id>
<name>LDAP support for ownCloud</name>
<version>0.1</version>
<licence>AGPL</licence>
<author>fabian</author>
</meta>
<include>lib_ldap.php</include>
</plugin>

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<plugin>
<meta>
<id>music</id>
<name>Music player for ownCloud</name>
<version>0.1</version>
<licence>AGPL</licence>
<author>2010 Frank Karlitschek karlitschek@kde.org</author>
</meta>
<include>lib_music.php</include>
</plugin>

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<plugin>
<meta>
<id>test</id>
<name>Test plugin</name>
<version>0.1</version>
<licence>AGPL</licence>
<author>2010 Frank Karlitschek karlitschek@kde.org</author>
</meta>
<include>lib_test.php</include>
</plugin>
Loading…
Cancel
Save