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"); }
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); }