public function action() { $user = $this->hasAuthorative(); $plugId = $this->_http->getParam('Plugin'); $field = $this->_http->getParam('Field'); $action = $this->_http->getParam('Action'); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'EditPlugin'); if (empty($plugId) || SLS_PluginsManager::isExists($plugId) === false) $this->dispatch('SLS_Bo', 'Plugins'); $plugin = new SLS_PluginsManager($plugId); $xmlPlug = $plugin->getXML(); if (empty($field) || empty($action)) $this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls"); $xpath = "//".str_replace("|||", "/", str_replace("|$|", "]", str_replace("$|$", "[", $field))); $clonable = array_shift($xmlPlug->getTags($xpath."/@clonable")); if ($clonable != 1) $this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls"); $nodeName = SLS_String::substrBeforeLastDelimiter($xpath, "["); if ($action == "del" && count($xmlPlug->getTags($nodeName)) > 1) { $xmlPlug->deleteTags($xpath, 1); } if ($action == "add") { $node = new SLS_XMLToolbox($xmlPlug->getNode($xpath)); $parent = SLS_String::substrBeforeLastDelimiter($xpath, "/"); $xmlPlug->appendXMLNode($xpath, $node->getXml('noHeader'), 1, "after"); $newIndex = SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterLastDelimiter($xpath, "["), "]"); $newIndex++; $newNode = SLS_String::substrBeforeLastDelimiter($xpath, "[")."[".$newIndex."]"; if ($xmlPlug->countChilds($newNode) == 0) $xmlPlug->setTag($newNode, "", false); else $xmlPlug = $this->removeRecursiveValues($newNode, $xmlPlug); $xmlPlug->setTagAttributes($newNode, array("alias"=>uniqid())); } $plugin->saveXML($xmlPlug); $this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls"); }
/** * Constructor * * @access protected * @param object $plugin the plugin object * @since 1.0 */ protected function __construct($plugin) { $this->_className = get_class($plugin); $this->_code = strtolower($this->_className); $pluginsXML = SLS_PluginsManager::returnPluginsXML(); if (count($pluginsXML->getTags("//plugins/plugin[@code='".$this->_code."']/@id")) == 0) SLS_Tracing::addTrace(new Exception("Cannot find plugin Configuration for ".$this->_className)); else { $this->_id = array_shift($pluginsXML->getTags("//plugins/plugin[@code='".$this->_code."']/@id")); $this->_pluginManager = new SLS_PluginsManager($this->_id); $this->_xml = $this->_pluginManager->getXML(); $this->_version = $this->_pluginManager->_version; } }
/** * Init static xml variable * * @access public static * @return SLS_XmlToolbox $pluginXML the xml configuration of plugins * @since 1.0 */ public static function returnPluginsXML() { if (!is_object(SLS_PluginsManager::$_pluginsXML)) SLS_PluginsManager::$_pluginsXML = SLS_Generic::getInstance()->getPluginXml("plugins"); return SLS_PluginsManager::$_pluginsXML; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $reload = $this->_http->getParam("reload"); $action = $this->_http->getParam("Action"); $errors = array(); $slsXml = $this->_generic->getCoreXML('sls'); $syncServer = array_shift($slsXml->getTags("slsnetwork")); $slsVersion = array_shift($slsXml->getTags("version")); $edit = $this->_generic->getTranslatedController('SLS_Bo', 'EditPlugin'); $editAppli = $this->_generic->getTranslatedController('SLS_Bo', 'CreatePlugin'); $pluginsXML = $this->_generic->getPluginXml("plugins"); // List own Plugins if ($action == "") { $deleteController = $this->_generic->getTranslatedController("SLS_Bo", "DeletePlugin"); if (($count = count($pluginsXML->getTags("//plugins/plugin[@beta='1']"))) > 0) { $xml->startTag("own_plugin"); for($i=1;$i<=$count;$i++) { $id = array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/@id")); $xml->startTag("plugin", array("code"=>array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/@code")),"id"=>$id)); $xml->addFullTag("description", array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/description")), true); $xml->addFullTag("custom", array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/@customizable")), true); $xml->addFullTag("edit", $edit['protocol']."://".$this->_generic->getSiteConfig('domainName')."/".$edit['controller']."/".$edit['scontroller']."/Plugin/".$id.".sls", true); $xml->addFullTag("name", array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/name")), true); $xml->addFullTag("delete", $deleteController['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$deleteController['controller']."/".$deleteController['scontroller']."/Plugin/".$id.".sls", true); $xml->addFullTag("editAppli", $editAppli['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$editAppli['controller']."/".$editAppli['scontroller']."/Plugin/".$id."/Action/Edit.sls", true); $xml->endTag("plugin"); } $xml->endTag("own_plugin"); } $this->registerLink("CREATE", "SLS_Bo", "CreatePlugin", array("Action"=>"Create")); $xml->addFullTag("step", "list", true); } // Create a new Plugin elseif ($action == "Create") { if ($reload == "true") { $name = SLS_String::trimSlashesFromString($this->_http->getParam("name")); $code = SLS_String::stringToUrl(strtolower(SLS_String::getSafeFilename(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", true); $output = SLS_String::trimSlashesFromString($this->_http->getParam("output")); $custom = SLS_String::trimSlashesFromString($this->_http->getParam("custom")); $path = SLS_String::trimSlashesFromString($this->_http->getParam("path")); $pathName = SLS_String::stringToUrl(SLS_String::getSafeFilename(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", false); $description = SLS_String::trimSlashesFromString($this->_http->getParam("full_description")); // Get Plugins Versions $serversJSON = @file_get_contents($syncServer); $pluginsAvailable = array(); $filesReserved = array(); $dirsReserved = array(); if ($serversJSON !== false && !empty($serversJSON)) { $servers = json_decode($serversJSON); $pluginsServers = $servers->servers->plugins; $plugins = array(); foreach ($pluginsServers as $pluginsServer) { $serverContent = @file_get_contents($pluginsServer->url); if ($serverContent !== false && !empty($serverContent)) { $serverContent = json_decode($serverContent); $plugs = $serverContent->plugins; foreach ($plugs as $plug) { $pluginsAvailable[] = $plug->code; if ($plug->type == 'file') $filesReserved[] = $plug->path; else $dirsReserved[] = $plug->path; } } } } $xml->startTag("form"); $xml->addFullTag("name", $name, true); $xml->addFullTag("code", $code, true); $xml->addFullTag("custom", $custom, true); $xml->addFullTag("path", $path, true); $xml->addFullTag("path_name", $pathName, true); $xml->addFullTag("fill_description", $description, true); if (empty($name)) $errors[] = "You must fill the common name"; if (empty($code)) $errors[] = "You must fill the code name"; if (empty($output) || ($output != 'yes' && $output != 'no')) $errors[] = "Choose if your plugin is an output type"; if (empty($custom) || ($custom != 'yes' && $custom != 'no')) $errors[] = "Choose if your plugin will be customizable"; if (empty($path) || ($path != 'file' && $path != 'dir')) $errors[] = "Choose if your plugin require only a file or multiple files in a directory"; if (empty($pathName)) $errors[] = "You must choose a filename or a directory name"; if (empty($description)) $errors[] = "You must fill the full description in English"; if (empty($errors)) { if (in_array($code, $pluginsAvailable)) $errors[] = "This code name is already in use for another plugin"; if ($path == 'file' && in_array($pathName.".class.php", $filesReserved)) $errors[] = "This file name is already in use for another plugin"; if ($path == 'dir' && in_array($pathName, $dirsReserved)) $errors[] = "This directory name is already in use for another plugin"; if (empty($errors)) { $newId = md5(uniqid($this->_generic->getSiteConfig("privateKey"))); $pathFile = $this->_generic->getPathConfig("plugins"); if ($path =="dir") $pathFile .= $pathName."/"; if ($output == 'no') { $str = '<?php'."\n". '/**'."\n". ' * Plugin '.$name."\n". ' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n". ' *'."\n". ' * @package Plugins'."\n". ' * @since 1.0'."\n". ' */'."\n". 'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin'."\n". '{'."\n". t(1).'public function __construct()'."\n". t(1).'{'."\n". t(2).'parent::__construct($this);'."\n". t(2).'$this->checkDependencies();'."\n". t(1).'}'."\n\n". t(1).'public function checkDependencies()'."\n". t(1).'{'."\n". t(1).'}'."\n". '}'."\n". '?>'; } else { $str = '<?php'."\n". '/**'."\n". ' * Plugin '.$name."\n". ' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n". ' *'."\n". ' * @package Plugins'."\n". ' * @since 1.0'."\n". ' */'."\n". 'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin, SLS_IPluginOutput'."\n". '{'."\n". t(1).'public function __construct()'."\n". t(1).'{'."\n". t(2).'parent::__construct($this);'."\n". t(2).'$this->checkDependencies();'."\n". t(1).'}'."\n\n". t(1).'public function checkDependencies()'."\n". t(1).'{'."\n". t(1).'}'."\n". '}'."\n". '?>'; } if (@file_put_contents($pathFile.$pathName.".class.php", $str) === false) $errors[] = "Plugin Creation failed"; if (empty($errors)) { if ($custom == "yes") { $str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><plugin><exemple_part writable=\"1\" label=\"Exemple Part\" clonable=\"1\" alias=\"main\"><exemple_row writable=\"1\" label=\"Exemple Row\" type=\"string\" clonable=\"0\" /></exemple_part></plugin>"; if (@file_put_contents($this->_generic->getPathConfig("configPlugins").$newId."_".$code.".xml", $str) === false) $errors[] = "Plugin Creation failed"; } } if (empty($errors)) { $newPlugin = new SLS_XMLToolbox(false); $newPlugin->startTag("plugin", array( "beta"=>"1", "code"=>$code, "id"=>$newId, "version"=>"0.1", "compability"=>$slsVersion, "customizable"=>($custom=="yes")?"1":"0", "output"=>($output=="yes")?"1":"0", "file"=>($path=="file")?"1":"0", "path"=>($path=="file")?$pathName.".class.php" : $pathName )); $newPlugin->addFullTag("name", $name, true); $newPlugin->addFullTag("description", $description, true); $newPlugin->addFullTag("author", "Me", true); $newPlugin->addFullTag("dependencies", "", false); $newPlugin->endTag("plugin"); $pluginsXML->appendXMLNode("//plugins", $newPlugin->getXML('noHeader')); file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginsXML->getXML()); $this->goDirectTo("SLS_Bo", "CreatePlugin"); } } } $xml->endTag("form"); } $xml->addFullTag("step", "create", true); } elseif ($action == "Edit") { $pluginID = $this->_http->getParam("Plugin"); if (SLS_PluginsManager::isExists($pluginID) === false) $this->goDirectTo("SLS_Bo", "CreatePlugin"); $originalPlugin = new SLS_PluginsManager($pluginID); if ($reload == "true") { $name = SLS_String::trimSlashesFromString($this->_http->getParam("name")); $code = SLS_String::stringToUrl(strtolower(SLS_String::getSafeFilename(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", true); $output = SLS_String::trimSlashesFromString($this->_http->getParam("output")); $custom = SLS_String::trimSlashesFromString($this->_http->getParam("custom")); $path = SLS_String::trimSlashesFromString($this->_http->getParam("path")); $pathName = SLS_String::stringToUrl(SLS_String::getSafeFilename(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", false); $description = SLS_String::trimSlashesFromString($this->_http->getParam("full_description")); // Get Plugins Versions $serversJSON = @file_get_contents($syncServer); $pluginsAvailable = array(); $filesReserved = array(); $dirsReserved = array(); if ($serversJSON !== false && !empty($serversJSON)) { $servers = json_decode($serversJSON); $pluginsServers = $servers->servers->plugins; $plugins = array(); foreach ($pluginsServers as $pluginsServer) { $serverContent = @file_get_contents($pluginsServer->url); if ($serverContent !== false && !empty($serverContent)) { $serverContent = json_decode($serverContent); $plugs = $serverContent->plugins; foreach ($plugs as $plug) { $pluginsAvailable[] = $plug->code; if ($plug->type == 'file') $filesReserved[] = $plug->path; else $dirsReserved[] = $plug->path; } } } } $xml->startTag("form"); $xml->addFullTag("name", $name, true); $xml->addFullTag("code", $code, true); $xml->addFullTag("custom", $custom, true); $xml->addFullTag("path", $path, true); $xml->addFullTag("path_name", $pathName, true); $xml->addFullTag("fill_description", $description, true); if (empty($name)) $errors[] = "You must fill the common name"; if (empty($code)) $errors[] = "You must fill the code name"; if (empty($output) || ($output != 'yes' && $output != 'no')) $errors[] = "Choose if your plugin is an output type"; if (empty($custom) || ($custom != 'yes' && $custom != 'no')) $errors[] = "Choose if your plugin will be customizable"; if (empty($path) || ($path != 'file' && $path != 'dir')) $errors[] = "Choose if your plugin require only a file or multiple files in a directory"; if (empty($pathName)) $errors[] = "You must choose a filename or a directory name"; if (empty($description)) $errors[] = "You must fill the full description in English"; if (empty($errors)) { if ($code != $originalPlugin->_code && in_array($code, $pluginsAvailable)) $errors[] = "This code name is already in use for another plugin"; if ($pathName.".class.php" != $originalPlugin->_path && $path == 'file' && in_array($pathName.".class.php", $filesReserved)) $errors[] = "This file name is already in use for another plugin"; if ($pathName != $originalPlugin->_path && $path == 'dir' && in_array($pathName, $dirsReserved)) $errors[] = "This directory name is already in use for another plugin"; if (empty($errors)) { if ($originalPlugin->_file == 1 && $path == 'dir') { if (!is_dir($this->_generic->getPathConfig("plugins").$originalPlugin->_path)) mkdir($this->_generic->getPathConfig("plugins").$pathName); if (is_file($this->_generic->getPathConfig("plugins").$originalPlugin->_path)) @unlink($this->_generic->getPathConfig("plugins").$originalPlugin->_path); } if ($originalPlugin->_file == 0 && $path == 'file') { if (is_dir($this->_generic->getPathConfig("plugins").$originalPlugin->_path)) $this->_generic->rm_recursive($this->_generic->getPathConfig("plugins").$originalPlugin->_path); if ($output == 'no') { $str = '<?php'."\n". '/**'."\n". ' * Plugin '.$name."\n". ' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n". ' *'."\n". ' * @package Plugins'."\n". ' * @since 1.0'."\n". ' */'."\n". 'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin'."\n". '{'."\n". t(1).'public function __construct()'."\n". t(1).'{'."\n". t(2).'parent::__construct($this);'."\n". t(2).'$this->checkDependencies();'."\n". t(1).'}'."\n\n". t(1).'public function checkDependencies()'."\n". t(1).'{'."\n". t(1).'}'."\n". '}'."\n". '?>'; } else { $str = '<?php'."\n". '/**'."\n". ' * Plugin '.$name."\n". ' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n". ' *'."\n". ' * @package Plugins'."\n". ' * @since 1.0'."\n". ' */'."\n". 'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin, SLS_IPluginOutput'."\n". '{'."\n". t(1).'public function __construct()'."\n". t(1).'{'."\n". t(2).'parent::__construct($this);'."\n". t(2).'$this->checkDependencies();'."\n". t(1).'}'."\n\n". t(1).'public function checkDependencies()'."\n". t(1).'{'."\n". t(1).'}'."\n". '}'."\n". '?>'; } if (@file_put_contents($this->_generic->getPathConfig("plugins").$pathName.".class.php", $str) === false) $errors[] = "Plugin Creation failed"; } if ($originalPlugin->_file == 1 && $path == 'file' && $pathName.".class.php" != $originalPlugin->_path) { if (is_file($this->_generic->getPathConfig("plugins").$originalPlugin->_path)) rename($this->_generic->getPathConfig("plugins").$originalPlugin->_path, $this->_generic->getPathConfig("plugins").$pathName.".class.php"); } if ($originalPlugin->_file == 0 && $path == 'dir' && $pathName != $originalPlugin->_path) { if (is_dir($this->_generic->getPathConfig("plugins").$originalPlugin->_path)) rename($this->_generic->getPathConfig("plugins").$originalPlugin->_path, $this->_generic->getPathConfig("plugins").$pathName); } if (empty($errors)) { if ($custom == "yes" && $originalPlugin->_customizable == false) { $str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><plugin><exemple_part writable=\"1\" label=\"Exemple Part\" clonable=\"1\" alias=\"main\"><exemple_row writable=\"1\" label=\"Exemple Row\" type=\"string\" clonable=\"0\" /></exemple_part></plugin>"; if (@file_put_contents($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$code.".xml", $str) === false) $errors[] = "Plugin Creation failed"; } if ($custom == "no" && $originalPlugin->_customizable == true) { if (is_file($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml")) unlink($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml"); } } if (empty($errors)) { if ($code != $originalPlugin->_code) { $pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("code"=>$code)); if (is_file($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml")) rename($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml", $this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$code.".xml"); } if (($output == "yes" && $originalPlugin->_output == 0) || ($output == "no" && $originalPlugin->_output == 1)) $pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("output"=>($output=="yes")?"1":"0")); if (($custom == "yes" && $originalPlugin->_customizable == false) || ($custom == "no" && $originalPlugin->_customizable == true)) $pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("customizable"=>($custom=="yes")?"1":"0")); if (($originalPlugin->_file == 1 && $path == 'dir') || ($originalPlugin->_file == 0 && $path == 'file')) $pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("file"=>($path=="file")?"1":"0")); if (($path == 'file' && $originalPlugin->_path != $pathName.".class.php") || ($path == 'dir' && $originalPlugin->_path != $pathName)) $pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("path"=>($path=="file")?$pathName.".class.php" : $pathName)); if ($originalPlugin->_name != $name) $pluginsXML->setTag("//plugins/plugin[@beta='1' and @id='".$pluginID."']/name", $name, true); if ($originalPlugin->_description != $description) $pluginsXML->setTag("//plugins/plugin[@beta='1' and @id='".$pluginID."']/description", $description, true); file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginsXML->getXML()); $this->goDirectTo("SLS_Bo", "CreatePlugin"); } } } $xml->endTag("form"); } $originalPlugin = new SLS_PluginsManager($pluginID); $xml->startTag("plugin"); $xml->addFullTag("name", $originalPlugin->_name, true); $xml->addFullTag("code", $originalPlugin->_code, true); $xml->addFullTag("output", ($originalPlugin->_output == 1)?"yes":"no", true); $xml->addFullTag("custom", ($originalPlugin->_customizable)?"yes":"no", true); $xml->addFullTag("path", ($originalPlugin->_file==1)?'file':'dir', true); $xml->addFullTag("path_name", ($originalPlugin->_file==1)?SLS_String::substrBeforeLastDelimiter($originalPlugin->_path, ".class.php"):$originalPlugin->_path, true); $xml->addFullTag("fill_description", $originalPlugin->_description, true); $xml->endTag("plugin"); $xml->addFullTag("step", "edit", true); } if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $plugId = $this->_http->getParam('Plugin'); $reload = $this->_http->getParam('reload', 'post'); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'Plugins'); if(SLS_PluginsManager::isExists($plugId) === false) $this->redirect($controllers['controller']."/".$controllers['scontroller']); $plugin = new SLS_PluginsManager($plugId); $xmlPlug = $plugin->getXML(); if (!$plugin->isCustomizable()) $this->redirect($controllers['controller']."/".$controllers['scontroller']); $xml->startTag("plugin_infos"); $xml->addFullTag('name', $plugin->_name); $xml->addFullTag('code', $plugin->_code); $xml->addFullTag('id', $plugin->_id); $xml->addFullTag('version', $plugin->_version); $xml->endTag("plugin_infos"); if ($reload == 'true') { $errors = array(); $form_memory = array(); $form_memory = $this->recoverFormValues("//plugin", $xmlPlug, $form_memory); $xml->startTag("memory"); foreach ($form_memory as $key=>$field) { $xml->startTag("values"); $xml->addFullTag("name", $key, true); $xml->addFullTag("value", $field['value'], true); $xml->endTag("values"); $xpath = $field['xpath']; $index = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($xpath, "["), "]"); $xpathNoIndex = SLS_String::substrBeforeLastDelimiter($xpath, "["); if (SLS_String::endsWith($key, "_alias")) { if (count($xmlPlug->getTags($xpathNoIndex."[position() != ".$index." and @alias='".$field['value']."']")) != 0) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." alias ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_UNIQUE']; else $xmlPlug->setTagAttributes($xpath, array("alias"=>$field['value'])); } else { $is_null = (array_shift($xmlPlug->getTags($xpath."/@null")) == "1") ? true : false; switch (array_shift($xmlPlug->getTags($xpath."/@type"))) { case "string" : if (!SLS_String::validateString($field['value']) && !$is_null) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_TYPE']; else $xmlPlug->setTag($xpath, $field['value']); break; case "password" : if (isset($field['value'])) $xmlPlug->setTag($xpath, SLS_Security::encrypt($field['value'], $this->_generic->getSiteConfig("privateKey"))); break; case "int" : if (!is_int($field['value']) && !$is_null) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_TYPE']; else $xmlPlug->setTag($xpath, $field['value']); break; case "float" : if (!is_float($field['value']) && !$is_null) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_TYPE']; else $xmlPlug->setTag($xpath, $field['value']); break; case "select" : $values = explode("|||", array_shift($xmlPlug->getTags($xpath."/@values"))); if (!in_array($field['value'], $values)) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_CONTENT']; else $xmlPlug->setTag($xpath, $field['value']); break; default: break; } } } $xml->endTag("memory"); if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } else { $xml->addFullTag("success", "ok", true); $plugin->saveXML($xmlPlug); } } $xml->addFullTag("fields", $plugin->getFields()->getXML('noHeader'), false); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->makeMenu($this->getXML()); $slsXml = $this->_generic->getCoreXML('sls'); $errors = array(); $syncServer = array_shift($slsXml->getTags("slsnetwork")); $action = $this->_http->getParam('Action'); $serverID = $this->_http->getParam("Server"); $pluginID = $this->_http->getParam("Plugin"); $this->registerLink("CREATE", "SLS_Bo", "CreatePlugin"); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'SearchPlugin'); $serversJSON = @file_get_contents($syncServer); if ($serversJSON === false ||empty($serversJSON)) $errors[] = "You are not connected to internet or synchronisation server is temporaly unavailable"; else { $servers = json_decode($serversJSON); $pluginsServers = $servers->servers->plugins; $plugins = array(); $xml->startTag("servers"); foreach ($pluginsServers as $pluginsServer) { $serverContent = @file_get_contents($pluginsServer->url); $xml->startTag("server", array("name"=>$pluginsServer->name,"id"=>$pluginsServer->id)); $xml->addFullTag("url", $pluginsServer->url, true, array("status"=>($serverContent === false || empty($serverContent)) ? "0" : "1")); if ($serverContent !== false && !empty($serverContent)) { $serverContent = json_decode($serverContent); $xml->startTag("plugins"); $plugs = $serverContent->plugins; foreach ($plugs as $plug) { // If we want to download this Plugin if ($action == "Download" && $pluginsServer->id == $serverID && $plug->id == $pluginID) { $way = $this->_http->getParam('Way'); $pluginXML = $this->_generic->getPluginXml("plugins"); if (count($pluginXML->getTags("//plugins/plugin[@id = '".$plug->id."']")) == 0 && count($pluginXML->getTags("//plugins/plugin[@code = '".$plug->code."' and @beta='1']")) == 0) { if (SLS_Remote::remoteFileExists($plug->file) != 0) $errors[] = $plug->name." is unavailable"; else { $filename = $this->_generic->getPathConfig("coreTmpDownload")."Plugins/".SLS_String::substrAfterLastDelimiter($plug->file, "/"); if (!is_dir($this->_generic->getPathConfig("coreTmpDownload")."Plugins")) mkdir($this->_generic->getPathConfig("coreTmpDownload")."Plugins"); $result = @copy($plug->file, $filename); if ($result === false) $errors[] = "The download of ".$plug->name." has failed"; else { $tar = new SLS_Tar(); if ($tar->openTAR($filename) === false) $errors[] = "Plugin archive is corrupted"; else { $hasConf = false; $isFile = true; $pathName = ""; foreach ($tar->directories as $directory) { if (SLS_String::startsWith($directory['name'], "Sources/")) { $dirName = SLS_String::substrAfterFirstDelimiter($directory['name'], "Sources/"); if (!empty($dirName)) { if (!is_dir($this->_generic->getPathConfig("plugins").$dirName)) mkdir($this->_generic->getPathConfig("plugins").$dirName); if (empty($pathName)) $pathName = (strpos($dirName, "/") !== false) ? SLS_String::substrBeforeLastDelimiter($dirName, "/") : $dirName; $isFile = false; } } } foreach ($tar->files as $file) { $copy = true; if (SLS_String::startsWith($file['name'], "Configs/") && SLS_String::endsWith($file['name'], ".xml")) { $hasConf = true; $copy = @file_put_contents($this->_generic->getPathConfig("configPlugins").$plug->id."_".$plug->code.".xml", $file['file']); } if (SLS_String::startsWith($file['name'], 'Sources/')) { if ($isFile === true && $pathName == "") $pathName = SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/"); $realPathFile = $this->_generic->getPathConfig("plugins").SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/"); $copy = @file_put_contents($realPathFile, $file['file']); } if ($copy === false) { $errors[] = "The copy of ".$file['name']." has failed"; } } if (empty($errors)) { $newPlugin = new SLS_XMLToolbox(false); $newPlugin->startTag("plugin", array("code"=>$plug->code,"id"=>$plug->id,"version"=>$plug->version,"compability"=>$plug->compability,"customizable"=>($hasConf) ? "1" : "0","file"=>($isFile)?"1":"0","path"=>$pathName)); $newPlugin->addFullTag("name", $plug->name, true); $newPlugin->addFullTag("description", $plug->desc, true); $newPlugin->addFullTag("author", $plug->author, true); $newPlugin->addFullTag("dependencies", "", false); $newPlugin->endTag("plugin"); $pluginXML->appendXMLNode("//plugins", $newPlugin->getXML('noHeader')); file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginXML->getXML()); } if (is_file($filename)) unlink($filename); } } } } if ($way == "Maj") { $this->goDirectTo("SLS_Bo", "Plugins"); } }// /If we want to download this Plugin // We list all Plugins available on this server $exist = SLS_PluginsManager::isExists($plug->id); if ($exist) { $plugin = new SLS_PluginsManager($plug->id); } $xml->startTag("plugin", array("version"=>$plug->version,"code"=>$plug->code,"id"=>$plug->id,"compability"=>((float)$plug->compability<=(float)array_shift($slsXml->getTags("version"))) ? "1" : "0","has"=>($exist)?"1":"0")); $xml->addFullTag("name", $plug->name, true); $xml->addFullTag("doc", $pluginsServer->domain.$plug->doc, true); $xml->addFullTag("dl", $controllers['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$controllers['controller']."/".$controllers['scontroller']."/Action/Download/Server/".$pluginsServer->id."/Plugin/".$plug->id.".sls"); $xml->addFullTag("desc", $plug->desc, true); $xml->addFullTag("author", $plug->author, true); $xml->endTag("plugin"); } $xml->endTag("plugins"); } $xml->endTag("server"); } $xml->endTag("servers"); } if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $this->saveXML($xml); }