2010-07-28 20:12:00 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
2011-03-02 01:20:16 +03:00
|
|
|
* @author Frank Karlitschek
|
|
|
|
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
|
|
|
|
*
|
2010-07-28 20:12:00 +04:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
2011-03-02 01:20:16 +03:00
|
|
|
* License as published by the Free Software Foundation; either
|
2010-07-28 20:12:00 +04:00
|
|
|
* version 3 of the License, or any later version.
|
2011-03-02 01:20:16 +03:00
|
|
|
*
|
2010-07-28 20:12:00 +04:00
|
|
|
* 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.
|
2011-03-02 01:20:16 +03:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
2010-07-28 20:12:00 +04:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OC_PLUGIN{
|
|
|
|
static private $blacklist=array();
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-07-28 20:12:00 +04:00
|
|
|
/**
|
|
|
|
* load the plugin with the given id
|
|
|
|
* @param string id
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
static public function load($id){
|
|
|
|
global $SERVERROOT;
|
2010-08-05 04:44:54 +04:00
|
|
|
$data=self::getPluginData($id);
|
|
|
|
if($data){
|
|
|
|
if(isset($data['info']['require'])){
|
|
|
|
$minVersion=explode('.',$data['info']['require']);
|
2010-07-29 00:45:24 +04:00
|
|
|
$version=OC_UTIL::getVersion();
|
|
|
|
$roundTo=count($minVersion);
|
|
|
|
while(count($version)>$roundTo){
|
|
|
|
if($version[count($version)-1]>=50){
|
|
|
|
$version[count($version)-2]++;
|
|
|
|
}
|
|
|
|
unset($version[count($version)-1]);
|
|
|
|
}
|
|
|
|
for($i=0;$i<count($minVersion);$i++){
|
|
|
|
if($version[$i]<$minVersion[$i]){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
//check for uninstalled db's
|
2010-09-25 18:47:06 +04:00
|
|
|
if(isset($data['install']) and isset($data['install']['database'])){
|
|
|
|
foreach($data['install']['database'] as $db){
|
2011-04-16 21:06:45 +04:00
|
|
|
$installed=OC_APPCONFIG::getValue('plugin_installer','database_installed_'.$id.'_'.$db,'false');
|
|
|
|
if($installed!='true'){
|
2010-09-25 18:47:06 +04:00
|
|
|
self::installDB($id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2011-01-04 02:11:16 +03:00
|
|
|
if(isset($data['runtime'])){
|
|
|
|
foreach($data['runtime'] as $include){
|
|
|
|
include($SERVERROOT.'/plugins/'.$id.'/'.$include);
|
|
|
|
}
|
2010-07-28 20:12:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-09-29 02:03:02 +04:00
|
|
|
/**
|
|
|
|
* Get a list of all installed plugins
|
|
|
|
*/
|
|
|
|
public static function listPlugins() {
|
|
|
|
global $SERVERROOT;
|
|
|
|
$plugins = array();
|
|
|
|
$fd = opendir($SERVERROOT . '/plugins');
|
|
|
|
while ( false !== ($filename = readdir($fd)) ) {
|
|
|
|
if ( $filename<>'.' AND $filename<>'..' AND ('.' != substr($filename, 0, 1))) {
|
|
|
|
if(file_exists($SERVERROOT . '/plugins/'.$filename.'/plugin.xml')){
|
|
|
|
$plugins[]=$filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($fd);
|
|
|
|
return $plugins;
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-07-28 20:12:00 +04:00
|
|
|
/**
|
|
|
|
* Load all plugins that aren't blacklisted
|
|
|
|
*/
|
|
|
|
public static function loadPlugins() {
|
2011-04-16 13:11:16 +04:00
|
|
|
$CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false );
|
2010-09-25 18:47:06 +04:00
|
|
|
if($CONFIG_INSTALLED){
|
|
|
|
global $SERVERROOT;
|
2010-09-29 02:05:10 +04:00
|
|
|
$plugins = self::listPlugins();
|
2010-09-25 18:47:06 +04:00
|
|
|
$blacklist=self::loadBlacklist();
|
2010-09-29 02:05:10 +04:00
|
|
|
foreach($plugins as $plugin){
|
|
|
|
if (array_search($plugin,$blacklist)===false) {
|
|
|
|
self::load($plugin);
|
2010-09-25 18:47:06 +04:00
|
|
|
}
|
2010-07-28 20:12:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-07-28 20:12:00 +04:00
|
|
|
/**
|
|
|
|
* load the blacklist from blacklist.txt
|
|
|
|
* @return array
|
|
|
|
*/
|
2010-09-29 02:03:02 +04:00
|
|
|
public static function loadBlacklist(){
|
2010-07-28 20:12:00 +04:00
|
|
|
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;
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-07-28 20:12:00 +04:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-07-28 20:12:00 +04:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-07-28 20:12:00 +04:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-08-05 04:44:54 +04:00
|
|
|
/**
|
2010-09-25 18:47:06 +04:00
|
|
|
* Load data from the plugin.xml of a plugin, either identified by the plugin or the path of the plugin.xml file
|
2010-08-05 04:44:54 +04:00
|
|
|
* @param string id
|
2010-09-25 18:47:06 +04:00
|
|
|
* @return array
|
2010-08-05 04:44:54 +04:00
|
|
|
*/
|
|
|
|
public static function getPluginData($id){
|
|
|
|
global $SERVERROOT;
|
|
|
|
if(is_file($id)){
|
|
|
|
$file=$id;
|
|
|
|
}else{
|
2010-10-16 03:42:58 +04:00
|
|
|
if(!is_dir($SERVERROOT.'/plugins/'.$id) or !is_file($SERVERROOT.'/plugins/'.$id.'/plugin.xml')){
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
$file=$SERVERROOT.'/plugins/'.$id.'/plugin.xml';
|
|
|
|
}
|
2010-08-05 04:44:54 +04:00
|
|
|
}
|
|
|
|
$data=array();
|
|
|
|
$plugin=new DOMDocument();
|
|
|
|
$plugin->load($file);
|
|
|
|
$data['version']=$plugin->documentElement->getAttribute('version');
|
|
|
|
$info=$plugin->getElementsByTagName('info');
|
|
|
|
if($info->length>0){
|
|
|
|
$info=$info->item(0);
|
|
|
|
$data['info']=array();
|
|
|
|
foreach($info->childNodes as $child){
|
|
|
|
if($child->nodeType==XML_ELEMENT_NODE){
|
|
|
|
$data['info'][$child->tagName]=$child->textContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$runtime=$plugin->getElementsByTagName('runtime');
|
|
|
|
if($runtime->length>0){
|
|
|
|
$runtime=$runtime->item(0);
|
|
|
|
$data['runtime']=array();
|
|
|
|
foreach($runtime->childNodes as $child){
|
|
|
|
if($child->nodeType==XML_ELEMENT_NODE and $child->tagName=='include'){
|
|
|
|
$data['runtime'][]=$child->textContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$install=$plugin->getElementsByTagName('install');
|
|
|
|
if($install->length>0){
|
|
|
|
$install=$install->item(0);
|
|
|
|
$data['install']=array();
|
|
|
|
foreach($install->childNodes as $child){
|
|
|
|
if($child->nodeType==XML_ELEMENT_NODE){
|
|
|
|
$data['install']['include']=array();
|
|
|
|
$data['install']['dialog']=array();
|
|
|
|
$data['install']['database']=array();
|
|
|
|
switch($child->tagName){
|
|
|
|
case 'include':
|
|
|
|
$data['install']['include'][]=$child->textContent;
|
|
|
|
break;
|
|
|
|
case 'dialog':
|
|
|
|
$data['install']['dialog'][]=$child->textContent;
|
|
|
|
break;
|
|
|
|
case 'database':
|
|
|
|
$data['install']['database'][]=$child->textContent;
|
2010-09-25 18:47:06 +04:00
|
|
|
$data['install']['database_installed'][$child->textContent]=($child->hasAttribute('installed') and $child->getAttribute('installed')=='true')?true:false;
|
2010-08-05 04:44:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$uninstall=$plugin->getElementsByTagName('uninstall');
|
|
|
|
if($uninstall->length>0){
|
|
|
|
$uninstall=$uninstall->item(0);
|
|
|
|
$data['uninstall']=array();
|
|
|
|
foreach($uninstall->childNodes as $child){
|
|
|
|
if($child->nodeType==XML_ELEMENT_NODE){
|
|
|
|
$data['uninstall']['include']=array();
|
|
|
|
$data['uninstall']['dialog']=array();
|
|
|
|
switch($child->tagName){
|
|
|
|
case 'include':
|
|
|
|
$data['uninstall']['include'][]=$child->textContent;
|
|
|
|
break;
|
|
|
|
case 'dialog':
|
|
|
|
$data['uninstall']['dialog'][]=$child->textContent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
|
|
|
|
2010-09-25 18:47:06 +04:00
|
|
|
/**
|
|
|
|
* Save data to the plugin.xml of a plugin, either identified by the plugin or the path of the plugin.xml file
|
|
|
|
* @param string id
|
|
|
|
* @param array data the plugin data in the same structure as returned by getPluginData
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function savePluginData($id,$data){
|
|
|
|
global $SERVERROOT;
|
|
|
|
if(is_file($id)){
|
|
|
|
$file=$id;
|
|
|
|
}
|
|
|
|
if(!is_dir($SERVERROOT.'/plugins/'.$id) or !is_file($SERVERROOT.'/plugins/'.$id.'/plugin.xml')){
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
$file=$SERVERROOT.'/plugins/'.$id.'/plugin.xml';
|
|
|
|
}
|
|
|
|
$plugin=new DOMDocument();
|
|
|
|
$pluginNode=$plugin->createElement('plugin');
|
|
|
|
$pluginNode->setAttribute('version',$data['version']);
|
|
|
|
$plugin->appendChild($pluginNode);
|
|
|
|
$info=$plugin->createElement('info');
|
|
|
|
foreach($data['info'] as $name=>$value){
|
|
|
|
$node=$plugin->createElement($name);
|
|
|
|
$node->appendChild($plugin->createTextNode($value));
|
|
|
|
$info->appendChild($node);
|
|
|
|
}
|
|
|
|
$pluginNode->appendChild($info);
|
|
|
|
if(isset($data['runtime'])){
|
|
|
|
$runtime=$plugin->createElement('runtime');
|
|
|
|
foreach($data['runtime'] as $include){
|
|
|
|
$node=$plugin->createElement('include');
|
|
|
|
$node->appendChild($plugin->createTextNode($include));
|
|
|
|
$runtime->appendChild($node);
|
|
|
|
}
|
|
|
|
$pluginNode->appendChild($runtime);
|
|
|
|
}
|
|
|
|
if(isset($data['install'])){
|
|
|
|
$install=$plugin->createElement('install');
|
|
|
|
foreach($data['install']['include'] as $include){
|
|
|
|
$node=$plugin->createElement('include');
|
|
|
|
$node->appendChild($plugin->createTextNode($include));
|
|
|
|
$install->appendChild($node);
|
|
|
|
}
|
|
|
|
foreach($data['install']['dialog'] as $dialog){
|
|
|
|
$node=$plugin->createElement('dialog');
|
|
|
|
$node->appendChild($plugin->createTextNode($dialog));
|
|
|
|
$install->appendChild($node);
|
|
|
|
}
|
|
|
|
foreach($data['install']['database'] as $database){
|
|
|
|
$node=$plugin->createElement('database');
|
|
|
|
$node->appendChild($plugin->createTextNode($database));
|
|
|
|
if($data['install']['database_installed'][$database]){
|
|
|
|
$node->setAttribute('installed','true');
|
|
|
|
}
|
|
|
|
$install->appendChild($node);
|
|
|
|
}
|
|
|
|
$pluginNode->appendChild($install);
|
|
|
|
}
|
|
|
|
if(isset($data['uninstall'])){
|
|
|
|
$uninstall=$plugin->createElement('uninstall');
|
|
|
|
foreach($data['uninstall']['include'] as $include){
|
|
|
|
$node=$plugin->createElement('include');
|
|
|
|
$node->appendChild($plugin->createTextNode($include));
|
|
|
|
$uninstall->appendChild($node);
|
|
|
|
}
|
|
|
|
foreach($data['uninstall']['dialog'] as $dialog){
|
|
|
|
$node=$plugin->createElement('dialog');
|
|
|
|
$node->appendChild($plugin->createTextNode($dialog));
|
|
|
|
$uninstall->appendChild($node);
|
|
|
|
}
|
|
|
|
$pluginNode->appendChild($uninstall);
|
|
|
|
}
|
|
|
|
$plugin->save($file);
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-09-25 18:47:06 +04:00
|
|
|
/**
|
|
|
|
* install the databases of a plugin
|
|
|
|
* @param string id
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function installDB($id){
|
|
|
|
global $SERVERROOT;
|
|
|
|
$data=OC_PLUGIN::getPluginData($id);
|
|
|
|
foreach($data['install']['database'] as $db){
|
2011-04-16 21:06:45 +04:00
|
|
|
$installed=OC_APPCONFIG::getValue('plugin_installer','database_installed_'.$id.'_'.$db,'false');
|
|
|
|
if ($installed!='true'){
|
2010-09-25 18:47:06 +04:00
|
|
|
$file=$SERVERROOT.'/plugins/'.$id.'/'.$db;
|
|
|
|
OC_DB::createDbFromStructure($file);
|
2011-04-16 21:06:45 +04:00
|
|
|
OC_APPCONFIG::setValue('plugin_installer','database_installed_'.$id.'_'.$db,'true');
|
2010-09-25 18:47:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-02 01:20:16 +03:00
|
|
|
|
2010-10-16 03:42:58 +04:00
|
|
|
public static function installPlugin($path){
|
|
|
|
global $SERVERROOT;
|
|
|
|
if(is_file($path)){
|
|
|
|
$zip = new ZipArchive;
|
|
|
|
if($zip->open($path)===TRUE){
|
|
|
|
$folder=sys_get_temp_dir().'/OC_PLUGIN_INSTALL/';
|
|
|
|
mkdir($folder);
|
|
|
|
$zip->extractTo($folder);
|
|
|
|
if(is_file($folder.'/plugin.xml')){
|
|
|
|
$pluginData=self::getPluginData($folder.'/plugin.xml');
|
|
|
|
if(array_search($pluginData['info']['id'],self::listPlugins())===false){
|
|
|
|
if(isset($pluginData['install'])){
|
|
|
|
foreach($pluginData['install']['database'] as $db){
|
|
|
|
OC_DB::createDbFromStructure($folder.'/'.$db);
|
2011-04-16 21:06:45 +04:00
|
|
|
OC_APPCONFIG::setValue('plugin_installer','database_installed_'.$id.'_'.$db,'true');
|
2010-10-16 03:42:58 +04:00
|
|
|
}
|
|
|
|
foreach($pluginData['install']['include'] as $include){
|
|
|
|
include($folder.'/'.$include);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recursive_copy($folder,$SERVERROOT.'/plugins/'.$pluginData['info']['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delTree($folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-28 20:12:00 +04:00
|
|
|
}
|
|
|
|
?>
|