public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $param = $this->_http->getParam("name"); $model = SLS_String::substrAfterFirstDelimiter($param,"_"); $alias = SLS_String::substrBeforeFirstDelimiter($param,"_"); if ($this->_http->getParam("type") == "") $actionsTypes = array("list","add","modify","delete","clone"); else $actionsTypes = array($this->_http->getParam("type")); foreach($actionsTypes as $actionType) $this->deleteActionBo($model,$actionType,$alias); # Node into bo.xml $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($alias."_".$model)."']"; $boExists = $xmlBo->getTag($boPath."/@type"); if (empty($boExists)) $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($alias."_".$model)."']"; $boExists = $xmlBo->getTag($boPath); if (!empty($boExists)) { $xmlBo->deleteTags($boPath, count($xmlBo->getTags($boPath))); $xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML()); $xmlBo->refresh(); } # /Node into bo.xml $controllers = $this->_generic->getTranslatedController("SLS_Bo","Bo"); $this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"]); }
public function action() { // Params $name = SLS_String::trimSlashesFromString($this->_http->getParam("name")); // Objects $user = $this->hasAuthorative(); $xmlRights = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml")); $result = $xmlRights->getTags("//sls_configs/entry[@login='******']"); if (!empty($result)) { $xmlRights->setTagAttributes('//sls_configs/entry[@login="******"]', array("enabled" => ($xmlRights->getTag('//sls_configs/entry[@login="******"]/@enabled')=='false') ? 'true' : 'false')); $xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml"); } $this->_generic->forward("SLS_Bo","ManageRights"); }
public function action() { // Objects $xml = $this->getXML(); $user = $this->hasAuthorative(); $xml = $this->makeMenu($xml); $this->_generic->registerLink('Add', 'SLS_Bo', 'AddRight'); $xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteRight",array(),false)); $xml->addFullTag("edit",$this->_generic->getFullPath("SLS_Bo","EditRight",array(),false)); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"); $xmlRights = new SLS_XMLToolbox($pathsHandle); $result = $xmlRights->getTagsAttributes("//sls_configs/entry",array("login","password","name","firstname","enabled")); $xml->startTag("accounts"); for($i=0 ; $i<$count=count($result) ; $i++) { $xml->startTag("account"); for($j=0 ; $j<$count2=count($result[$i]["attributes"]) ; $j++) { if ($result[$i]["attributes"][$j]["key"] == "password") $xml->addFullTag($result[$i]["attributes"][$j]["key"],"******",true); else if (SLS_String::contains($result[$i]["attributes"][$j]["key"],"name")) $xml->addFullTag($result[$i]["attributes"][$j]["key"],ucwords(strtolower($result[$i]["attributes"][$j]["value"])),true); else $xml->addFullTag($result[$i]["attributes"][$j]["key"],$result[$i]["attributes"][$j]["value"],true); } $xml->addFullTag("color",$xmlRights->getTag("//sls_configs/entry[@login='******']/settings/setting[@key='color']"),true); $xml->endTag("account"); } $xml->endTag("accounts"); $xml->addFullTag("url_status",$this->_generic->getFullPath("SLS_Bo","ManageRightsStatus",array(),false)); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); // Get the table name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); if ($sql->tableExists($table)) { if ($this->_http->getParam("reload") == "true") { $replacements = array('&','>','<','=','"',"'"); $masks = array('&','>','<','=','','',''); $columnWanted = $this->_http->getParam("column"); $tableWanted = $this->_http->getParam("table"); $labelWanted = $this->_http->getParam($tableWanted.'_fkLabel'); $labelSpecified = SLS_String::trimSlashesFromString($this->_http->getParam("fkLabel_specified")); $multilang = $this->_http->getParam("multilanguage"); $onDelete = $this->_http->getParam("ondelete"); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); if (!empty($labelSpecified)) $labelSpecified = str_replace(array('='),array('='),htmlentities(strtolower($labelSpecified),ENT_QUOTES,"UTF-8")); $result = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$columnWanted."' and @tablePk='".$tableWanted."']"); // If an entry already exists in the XML, delete this record if (!empty($result)) { $xmlTmp = $xmlFk->deleteTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$columnWanted."' and @tablePk='".$tableWanted."']"); $xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlTmp); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); } // Save it into the XML $xmlNode = '<entry tableFk="'.$db."_".$table.'" columnFk="'.$columnWanted.'" multilanguage="'.$multilang.'" ondelete="'.$onDelete.'" labelPk="'.(empty($labelSpecified) ? $labelWanted : $labelSpecified).'" tablePk="'.$tableWanted.'" />'; $xmlFk->appendXMLNode("//sls_configs",$xmlNode); $xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlFk->getXML()); // Disable UserBo quick-edit feature on this column $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']"; $boExists = $xmlBo->getTag($boPath."/@allowEdit"); if (empty($boExists)) $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']"; $boExists = $xmlBo->getTag($boPath."/@allowEdit"); if (!empty($boExists)) { $xmlBo->setTagAttributes($boPath,array("allowEdit" => "false")); $xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML()); $xmlBo->refresh(); } // Update model $this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name")))); } // Get generic object $this->_generic->useModel(SLS_String::tableToClass($table),$db,"user"); $object = new $class(); // Get object's infos $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $columnsP = $object->getParams(); $pk = $object->getPrimaryKey(); $multilanguage = $object->isMultilanguage(); $xml->startTag("model"); $xml->addFullTag("table",$table,true); $xml->addFullTag("db",$db,true); $xml->addFullTag("class",$class,true); $xml->addFullTag("pk",$pk,true); $xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true); $xml->startTag("columns"); foreach($columnsP as $column => $value) { $res = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$column."']/@tablePk"); if ($object->getPrimaryKey() != $column && $column != "pk_lang" && empty($res)) $xml->addFullTag("column",$column,true); } $xml->endTag("columns"); $tables = $this->getAllModels(); sort($tables,SORT_REGULAR); $xml->startTag("tables"); for($i=0 ; $i<$count=count($tables) ; $i++) { if (SLS_String::startsWith($tables[$i],$db)) { $xml->startTag("table"); $xml->addFullTag("name",SLS_String::substrAfterFirstDelimiter($tables[$i],".")); $xml->addFullTag("db",SLS_String::substrBeforeFirstDelimiter($tables[$i],".")); $tableN = SLS_String::substrAfterFirstDelimiter($tables[$i],"."); $dbN = SLS_String::substrBeforeFirstDelimiter($tables[$i],"."); $classN = ucfirst($dbN)."_".SLS_String::tableToClass($tableN); $this->_generic->useModel($tableN,$dbN,"user"); $obj = new $classN(); $properties = $obj->getParams(); $xml->startTag("columns"); foreach($properties as $key => $value) if ($key != "pk_lang") $xml->addFullTag("column",$key,true); $xml->endTag("columns"); $xml->endTag("table"); } } $xml->endTag("tables"); $xml->endTag("model"); } else { $xml->addFullTag("error","Sorry this table doesn't exist anymore",true); } $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $environments = $this->getEnvironments(); $xml->startTag("environments"); for($i=0 ; $i<$count=count($environments) ; $i++) { $prodFiles = array ("site" => false, "db" => false, "mail" => false, "project" => false); foreach($prodFiles as $prodFile => $exists) { $ok = false; if (file_exists($this->_generic->getPathConfig("configSecure").$prodFile."_".$environments[$i].".xml")) { $handle = file_get_contents($this->_generic->getPathConfig("configSecure").$prodFile."_".$environments[$i].".xml"); $xmlConf = new SLS_XMLToolbox($handle); if ($prodFile == "site" && $xmlConf->getTag("//configs/domainName") != "") $ok = true; if ($prodFile == "db" && $xmlConf->getTag("//dbs/db/host") != "") $ok = true; if ($prodFile == "mail" && $xmlConf->getTag("//mails/host") != "") $ok = true; if ($prodFile == "project" && $handle != "") $ok = true; } $prodFiles[$prodFile] = $ok; } $xml->startTag("environment"); $xml->addFullTag("environment_title",$environments[$i],true); $xml->startTag("prod_files"); foreach($prodFiles as $prodFile => $exists) { $action = ""; switch($prodFile) { case "site": $action = "GlobalSettings"; break; case "db": $action = "DataBaseSettings"; break; case "mail": $action = "MailSettings"; break; case "project": $action = "ProjectSettings"; break; } $xml->startTag("prod_file"); $xml->addFullTag("title",$prodFile."_".$environments[$i].".xml",true); $xml->addFullTag("exists",($exists) ? "true" : "false",true); $xml->addFullTag("url_edit",$this->_generic->getFullPath("SLS_Bo",$action,array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"Env","value"=>$environments[$i]))),true); $xml->endTag("prod_file"); } $xml->endTag("prod_files"); $xml->addFullTag("url_batch",$this->_generic->getFullPath("SLS_Bo","GlobalSettings",array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"CompleteBatch","value"=>"true"),array("key"=>"Env","value"=>$environments[$i]))),true); $xml->endTag("environment"); } $xml->endTag("environments"); $xml->addFullTag("url_add_environment",$this->_generic->getFullPath("SLS_Bo","EnvironmentsAdd"),true); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $langs = $this->_generic->getObjectLang()->getSiteLangs(); $errors = array(); $siteXML = $this->_generic->getSiteXML(); $aliasesSelected = array(); $componentsSelected = array(); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginMobile = $plugin->getTag("//plugins/plugin[@code='mobile']"); $pluginMobile = (!empty($pluginMobile)) ? true : false; $controllersXML = $this->_generic->getControllersXML(); $metasXML = $this->_generic->getCoreXML('metas'); $controller = $this->_http->getParam('Controller'); $action = $this->_http->getParam('Action'); $actionExist = $controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']"); $actionId = array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@id")); $protocol = $this->_generic->getActionProtocol($actionId); if (count($actionExist) == 1) { $aliasesChecked = array_shift($controllersXML->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']",array("domains"))); if (!empty($aliasesChecked)) { $alias = explode(",",$aliasesChecked["attributes"][0]["value"]); foreach($alias as $cur_alias) array_push($aliasesSelected,$cur_alias); } $componentsChecked = array_shift($controllersXML->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']",array("components"))); if (!empty($componentsChecked)) { $component = explode(",",$componentsChecked["attributes"][0]["value"]); foreach($component as $cur_component) array_push($componentsSelected,$cur_component); } $reload = $this->_http->getParam("reload"); if ($reload == 'true') { $oldAction = SLS_String::trimSlashesFromString($this->_http->getParam("genericName")); $newAction = SLS_String::stringToUrl(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("actionName"))), "", false); $needDynamic = SLS_String::trimSlashesFromString($this->_http->getParam("dynamic")); $needOffline = SLS_String::trimSlashesFromString($this->_http->getParam("offline")); $needDefault = SLS_String::trimSlashesFromString($this->_http->getParam("default")); $searchEngine = SLS_String::trimSlashesFromString($this->_http->getParam("indexes")); $postProtocol = SLS_String::trimSlashesFromString($this->_http->getParam("protocol")); $tpl = SLS_String::trimSlashesFromString($this->_http->getParam('template')); $aliases = SLS_String::trimSlashesFromString($this->_http->getParam('domains')); $components = SLS_String::trimSlashesFromString($this->_http->getParam('components')); $cache_visibility = SLS_String::trimSlashesFromString($this->_http->getParam('cache_visibility')); $cache_scope = SLS_String::trimSlashesFromString($this->_http->getParam('cache_scope')); $cache_expiration = SLS_String::trimSlashesFromString($this->_http->getParam('cache_expiration')); $cache_responsive = SLS_String::trimSlashesFromString($this->_http->getParam('cache_responsive')); $toCache = (in_array($cache_visibility,array("public","private"))) ? true : false; if ($controller == "Home" && $action == "Index") { $needDefault = "true"; $newAction = $oldAction; } // If responsive wanted if ($cache_responsive == "true" && !$pluginMobile) { // Force Mobile plugin download file_get_contents($this->_generic->getFullPath("SLS_Bo", "SearchPlugin", array("Action" => "Download", "Server" => "4", "Plugin" => "20", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); } $postActionsLang = array(); $postTitlesLang = array(); $postDescriptionsLang = array(); $postKeywordsLang = array(); // Save Form informations $xml->startTag("form"); $xml->addFullTag("actionName", $newAction, true); foreach ($langs as $lang) { $postLang = trim(SLS_String::stringToUrl(SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-action")), "", false)); $postOldLang = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-oldAction")); if ($postLang != $oldAction) { $translationExist = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name != '".$oldAction."']/scontrollerLangs[scontrollerLang = '".$postLang."']"); if (empty($postLang)) array_push($errors, "You need to fill the ".$lang." url translations"); elseif(count($translationExist) != 0) array_push($errors, "You URL translation in ".$lang." is already in use on another action in the same controller"); else $postActionsLang[$lang] = $postLang; } // Get Titles $postTitlesLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-title")); $postDescriptionsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-description")); $postKeywordsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-keywords")); $xml->addFullTag($lang."-action", $postLang, true); $xml->addFullTag($lang."-title", $postTitlesLang[$lang], true); $xml->addFullTag($lang."-description", $postDescriptionsLang[$lang], true); $xml->addFullTag($lang."-keywords", $postKeywordsLang[$lang], true); } $xml->endTag("form"); if (empty($postProtocol) || ($postProtocol != 'http' && $postProtocol != 'https')) array_push($errors, "Protocol must be http or https"); else $protocol = $postProtocol; if (!empty($aliases) && is_array($aliases)) { $aliasesSelected = array(); foreach($aliases as $alias) array_push($aliasesSelected,$alias); } else { $aliasesSelected = array(); $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('domains' => '')); } if ($toCache && (!is_numeric($cache_expiration) || $cache_expiration < 0)) array_push($errors, "Your expiration cache must be a positive time or 0"); if ($toCache && (!in_array($cache_scope,array("full","partial")))) array_push($errors, "Your must describe your cache scope"); if ($toCache && is_numeric($cache_expiration) && $cache_expiration >= 0 && in_array($cache_scope,array("full","partial"))) $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('cache' => $cache_visibility.'|'.$cache_scope.'|'.(($cache_responsive == 'true') ? 'responsive' : 'no_responsive').'|'.$cache_expiration)); if (!$toCache) $controllersXML->deleteTagAttribute("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']","cache"); if (!empty($components) && is_array($components)) { $componentsSelected = array(); foreach($components as $component) array_push($componentsSelected,$component); } else { $componentsSelected = array(); $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('components' => '')); } if ((($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $action != 'Index') || ($controller == 'Default' && ($action != 'UrlError' && $action != 'BadRequestError' && $action != 'AuthorizationError' && $action != 'ForbiddenError' && $action != 'InternalServerError' && $action != 'TemporaryRedirectError' && $action != 'MaintenanceError')))) && ($oldAction != $newAction)) { $newNameExist = $controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$newAction."']"); if (count($newNameExist) != 0) array_push($errors, "The generic action name is already in use in this controller"); } else $newAction = $oldAction; if (empty($newAction)) array_push($errors, "Action name can't be empty."); if (!empty($aliases)) $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('domains' => implode(",",$aliasesSelected))); if (!empty($components)) $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('components' => implode(",",$componentsSelected))); $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('disable' => (empty($needOffline)) ? '0' : '1')); if ($tpl == -1) $controllersXML->deleteTagAttribute("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']", "tpl"); else $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']", array('tpl' => $tpl)); file_put_contents($this->_generic->getPathConfig('configSecure')."controllers.xml", $controllersXML->getXML()); $dynamic = (($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $action != 'Index') || ($controller == 'Default' && ($action != 'UrlError' && $action != 'BadRequestError' && $action != 'AuthorizationError' && $action != 'ForbiddenError' && $action != 'InternalServerError' && $action != 'TemporaryRedirectError' && $action != 'MaintenanceError')))) ? ($needDynamic == 'on') ? "1" : "0" : array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and side='user']/scontrollers/scontroller[@name='".$oldAction."']/@needParam")); // If no errors if (empty($errors)) { // If default, reset other in current controller if (!empty($needDefault)) { $actions = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller/@id"); foreach($actions as $curActionId) $controllersXML->setTagAttributes("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@id='".$curActionId."']", array('default' => '0')); } $controllersXML->setTagAttributes("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']", array("name"=>$newAction,"needParam"=>$dynamic,'protocol'=>$protocol,"default"=>(empty($needDefault) ? '0' : '1'))); foreach ($langs as $lang) { if (array_key_exists($lang, $postActionsLang)) $controllersXML->setTag("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']", $postActionsLang[$lang], true); else $controllersXML->setTag("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']", SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-oldAction")), true); } // If generic name is not the same, we modify all files if ($oldAction != $newAction) { // Controller $contentController = file_get_contents($this->_generic->getPathConfig('actionsControllers').$controller."/".$oldAction.".controller.php"); $contentController = str_replace(array(0=>" ".$controller.$oldAction." ", 1=>" ".$oldAction." "), array(0=>" ".$controller.$newAction." ", 1=>" ".$newAction." "), $contentController); file_put_contents($this->_generic->getPathConfig('actionsControllers').$controller."/".$newAction.".controller.php", $contentController); unlink($this->_generic->getPathConfig('actionsControllers').$controller."/".$oldAction.".controller.php"); //Langs foreach ($langs as $lang) { $contentLang = file_get_contents($this->_generic->getPathConfig('actionLangs').$controller."/".$oldAction.".".$lang.".lang.php"); $contentLang = str_replace(array(0=>" ".$controller.$oldAction." ", 1=>" ".$oldAction." "), array(0=>" ".$controller.$newAction." ", 1=>" ".$newAction." "), $contentLang); file_put_contents($this->_generic->getPathConfig('actionLangs').$controller."/".$newAction.".".$lang.".lang.php", $contentLang); unlink($this->_generic->getPathConfig('actionLangs').$controller."/".$oldAction.".".$lang.".lang.php"); } // Views // Body $contentBody = file_get_contents($this->_generic->getPathConfig('viewsBody').$controller."/".$oldAction.".xsl"); $contentBody = str_replace(array(0=>"name=\"".$oldAction."\">", 1=>$oldAction.".xsl"), array(0=>"name=\"".$newAction."\">", 1=>$newAction.".xsl"), $contentBody); file_put_contents($this->_generic->getPathConfig('viewsBody').$controller."/".$newAction.".xsl", $contentBody); unlink($this->_generic->getPathConfig('viewsBody').$controller."/".$oldAction.".xsl"); // Headers $contentHeader = file_get_contents($this->_generic->getPathConfig('viewsHeaders').$controller."/".$oldAction.".xsl"); $contentHeader = str_replace(array(0=>"name=\"Header".$oldAction."\">"), array(0=>"name=\"Header".$newAction."\">"), $contentHeader); file_put_contents($this->_generic->getPathConfig('viewsHeaders').$controller."/".$newAction.".xsl", $contentHeader); unlink($this->_generic->getPathConfig('viewsHeaders').$controller."/".$oldAction.".xsl"); } // We now update the XML foreach ($langs as $lang) { // Metas $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/title[@lang='".$lang."']", $postTitlesLang[$lang], true); $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/description[@lang='".$lang."']", $postDescriptionsLang[$lang], true); $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/keywords[@lang='".$lang."']", $postKeywordsLang[$lang], true); } if (!SLS_String::contains($searchEngine,", ")) $searchEngine = str_replace(",",", ",$searchEngine); if ($searchEngine != "index, follow" && $searchEngine != "noindex, follow" && $searchEngine != "noindex, nofollow" && $searchEngine != "index, nofollow") $searchEngine = "index, follow"; $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/robots", $searchEngine, true); file_put_contents($this->_generic->getPathConfig("configSecure")."controllers.xml", $controllersXML->getXML()); file_put_contents($this->_generic->getPathConfig("configSls")."metas.xml", $metasXML->getXML()); } if (count($errors) != 0) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $xml->startTag("cache"); $xml->addFullTag("cache_visibility", $cache_visibility,true); $xml->addFullTag("cache_scope", $cache_scope,true); $xml->addFullTag("cache_expiration", $cache_expiration,true); $xml->addFullTag("cache_responsive", $cache_responsive,true); $xml->endTag("cache"); } else { $actionCache = $this->_cache->getAction($actionId); $xml->startTag("cache"); $xml->addFullTag("cache_visibility", (is_array($actionCache)) ? $actionCache[0] : "",true); $xml->addFullTag("cache_scope", (is_array($actionCache)) ? $actionCache[1] : "",true); $xml->addFullTag("cache_expiration", (is_array($actionCache)) ? $actionCache[3] : "",true); $xml->addFullTag("cache_responsive", (is_array($actionCache)) ? (($actionCache[2]=="responsive") ? "true" : "") : "",true); $xml->endTag("cache"); } $tpl = $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@tpl"); if (empty($tpl)) $tpl = $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/@tpl"); $controllersXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSecure")."controllers.xml")); $xml->startTag("action"); $xml->addFullTag("name", $action, true); $xml->addFullTag("dynamic", (array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@needParam")) == '1') ? 'true' : 'false', true); $xml->addFullTag("offline", (array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@disable")) == '1') ? 'true' : 'false', true); $xml->addFullTag("default", (array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@default")) == '1') ? 'true' : 'false', true); $xml->addFullTag("indexes", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/robots")), true); $xml->addFullTag("canBeModified", (($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $action != 'Index') || ($controller == 'Default' && ($action != 'UrlError' && $action != 'BadRequestError' && $action != 'AuthorizationError' && $action != 'ForbiddenError' && $action != 'InternalServerError' && $action != 'TemporaryRedirectError' && $action != 'MaintenanceError')))) ? 'true' : 'false', true); $xml->startTag("translations"); foreach ($langs as $lang) { $xml->startTag("translation"); $xml->addFullTag("lang", $lang, true); $xml->addFullTag("name", array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']")) ,true); $xml->addFullTag("title", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/title[@lang='".$lang."']")),true); $xml->addFullTag("description", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/description[@lang='".$lang."']")),true); $xml->addFullTag("keywords", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/keywords[@lang='".$lang."']")),true); $xml->endTag("translation"); } $xml->endTag("translations"); $xml->endTag("action"); $xml->startTag('controller'); $xml->addFullTag("name", $controller, true); $xml->startTag('translations'); foreach ($langs as $lang) { $xml->startTag('translation'); $xml->addFullTag("lang", $lang, true); $xml->addFullTag("name", $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/controllerLangs/controllerLang[@lang='".$lang."']"), true); $xml->endTag('translation'); } $xml->endTag('translations'); $xml->endTag('controller'); // Build all tpls $tpls = $this->getAppTpls(); $xml->startTag("tpls"); foreach($tpls as $template) $xml->addFullTag("tpl",$template,true); $xml->endTag("tpls"); $xml->addFullTag('request', 'modifyAction', true); $aliases = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias")); $xml->startTag("aliases"); for($i=0 ; $i<$count=count($aliases) ; $i++) { $xml->startTag("alias"); $xml->addFullTag("name",$aliases[$i]["attributes"][0]["value"],true); $xml->addFullTag("selected",(in_array($aliases[$i]["attributes"][0]["value"],$aliasesSelected)) ? "true" : "false",true); $xml->endTag("alias"); } $xml->endTag("aliases"); $components = $this->_generic->recursiveReadDir($this->_generic->getPathConfig("componentsControllers"), array(), array(0=>"php")); $xml->startTag("components"); foreach ($components as $component) { $xml->startTag("component"); $xml->addFullTag("name", SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),true); $xml->addFullTag("selected",(in_array(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),$componentsSelected)) ? "true" : "false",true); $xml->endTag("component"); } $xml->endTag("components"); } else { $this->_generic->dispatch('SLS_Bo', 'Controllers'); } $xml->addFullTag('protocol', $protocol, true); $xml->addFullTag('template', $tpl, true); $this->saveXML($xml); }
/** * Get the source code of a model from his table * * @param string $tableName the table name * @param string $db the alias of the database on which the model is located * @return string $contentM the source code */ protected function getModelSource($tableName,$db) { $arrayConvertTypes = array( 'varchar' => 'string', 'tinyint' => 'int', 'text' => 'string', 'date' => 'string', 'smallint' => 'int', 'mediumint' => 'int', 'int' => 'int', 'bigint' => 'int', 'float' => 'float | int', 'double' => 'float | int', 'decimal' => 'float', 'datetime' => 'string', 'timestamp' => 'int', 'time' => 'string | int', 'year' => 'int', 'char' => 'string', 'tinyblob' => 'string', 'tinytext' => 'string', 'blob' => 'string', 'mediumblob'=> 'string', 'mediumtext'=> 'string', 'longblob' => 'string', 'longtext' => 'string', 'enum' => 'string', 'set' => 'string', 'bool' => 'int', 'binary' => 'string', 'varbinary' => 'string' ); $sql = SLS_Sql::getInstance(); $className = ucfirst($db)."_".SLS_String::tableToClass($tableName); $file = ucfirst($db).".".SLS_String::tableToClass($tableName); // Create empty source $contentM = ""; $primaryKey = ""; $multiLanguage = 'false'; $sql->changeDb($db); $columns = $sql->showColumns($tableName); $fileName = ucfirst($db).".".SLS_String::tableToClass($tableName).".model.php"; $primaryKey = ""; $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); $fkMethods = array(); $uniquesMultilang = array(); // Create Model $contentM = '<?php'."\n". '/**'."\n". ' * Object '.$className.''."\n". ' * @author SillySmart'."\n". ' * @copyright SillySmart'."\n". ' * @package Mvc.Models.Objects'."\n". ' * @see Sls.Models.Core.SLS_FrontModel'."\n". ' * @since 1.0'."\n". ' */'."\n". 'class '.$className.' extends SLS_FrontModel'."\n". '{'."\n". t(1).'/**'."\n". t(1).' * Class variables'."\n". t(1).' */'."\n"; $pkFound = false; for($i=0 ; $i<$count=count($columns) ; $i++) { if (!$pkFound && $columns[$i]->Key == "PRI") { $primaryKey = SLS_String::removePhpChars($columns[$i]->Field); $pkFound = true; } if ($columns[$i]->Field == "pk_lang" && $columns[$i]->Key == "PRI") $multiLanguage = 'true'; $contentM .= t(1).'protected $__'.SLS_String::removePhpChars($columns[$i]->Field).';'."\n"; } $contentM .= t(1).'protected $_table = "'.$tableName.'";'."\n". t(1).'protected $_db = "'.$db.'";'."\n". t(1).'protected $_primaryKey = "'.$primaryKey.'";'."\n"; // Show create table if ($multiLanguage == 'true') { $create = array_shift($sql->select("SHOW CREATE TABLE `".$tableName."`")); $instructions = array_map("trim",explode("\n",$create->{Create." ".Table})); foreach($instructions as $instruction) { if (SLS_String::startsWith($instruction,"UNIQUE KEY")) { $uniqueColumns = explode(",",SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($instruction,"("),")")); if (count($uniqueColumns) == 2 && in_array("`pk_lang`",$uniqueColumns)) { $uniqueColumn = array_shift($uniqueColumns); if ($uniqueColumn == "`pk_lang`") $uniqueColumn = array_shift($uniqueColumns); $uniquesMultilang[] = str_replace("`","",$uniqueColumn); } } } } // Get FKs to create access reference functions $fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$tableName."']",array("columnFk","tablePk")); $fkFunctions = ""; $fkCursor = ""; for($i=0 ; $i<$count=count($fks) ; $i++) { $tablePk = $fks[$i]["attributes"][1]["value"]; $functionName = SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_"))," ",false)),""); $functionName{0} = strtolower($functionName{0}); $functionNameModified = $functionName; while(in_array($functionNameModified,$fkMethods)) $functionNameModified = $functionName."_".($fkCursor = (empty($fkCursor)) ? 2 : $fkCursor+1); $fkMethods[] = $functionNameModified; $fkFunctions .= "'".$functionNameModified."'"; if ($i < ($count - 1)) $fkFunctions .= ", "; } $contentM .= t(1).'protected $_fks = array('.$fkFunctions.');'."\n"; $contentM .= t(1).'public $_typeErrors = array();'."\n\n". t(1).'/**'."\n". t(1).' * Constructor '.$className.''."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' * @param bool $mutlilanguage true if multilanguage content, else false'."\n". t(1).' */'."\n". t(1).'public function __construct($multilanguage='.$multiLanguage.')'."\n". t(1).'{'."\n". t(2).'parent::__construct($multilanguage);'."\n". t(2).'$this->buildDefaultValues();'."\n". t(1).'}'."\n\n"; $contentM .= t(1).'/**'."\n". t(1).' * Build default values for specific columns'."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' */'."\n". t(1).'public function buildDefaultValues()'."\n". t(1).'{'."\n"; for($i=0 ; $i<$count=count($columns) ; $i++) { $columnType = (strpos($columns[$i]->Type, "(")) ? SLS_String::substrBeforeFirstDelimiter(strtolower($columns[$i]->Type), "(") : $columns[$i]->Type; $functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",SLS_String::removePhpChars($columns[$i]->Field))," ",false)),""); if ($columns[$i]->Null == "NO") { // Dates if ($columnType == "date" || $columnType == "datetime" || $columnType == "timestamp" || $columnType == "year" || $columnType == "time") { switch ($columnType) { case "date": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d");'."\n"; break; case "time": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("H:i:s");'."\n"; break; case "datetime": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d H:i:s");'."\n"; break; case "timestamp": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d H:i:s");'."\n"; break; case "year": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y");'."\n"; break; } } // Uniqid $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".SLS_String::removePhpChars($columns[$i]->Field)."' and @type='uniqid']"); if (!empty($result)) { $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40);'."\n"; } // IP Address $result = array_shift($xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".SLS_String::removePhpChars($columns[$i]->Field)."' and (@type='ip_both' or @type='ip_v4' or @type='ip_v6')]/@type")); if (!empty($result)) { $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = $_SERVER["REMOTE_ADDR"];'."\n"; } } } $contentM .= t(1).'}'."\n\n"; for($i=0 ; $i<$count=count($columns) ; $i++) { $isPassword = false; if ($columns[$i]->Key != "PRI") { $column = SLS_String::removePhpChars($columns[$i]->Field); $columnType = (strpos($columns[$i]->Type, "(")) ? SLS_String::substrBeforeFirstDelimiter(strtolower($columns[$i]->Type), "(") : $columns[$i]->Type; $functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",$column)," ",false)),""); $contentM .= t(1).'/**'."\n". t(1).' * Set the value of '.$column.''."\n". t(1).' * Errors can be catched with the public variable $this->_typeErrors[\''.$column.'\']'."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' * @param '.$arrayConvertTypes[$columnType].' $value'."\n". t(1).' * @return bool true if updated, false if not'."\n". t(1).' */'."\n". t(1).'public function '.$functionName.'($value'; if ($columns[$i]->Default !== null) $contentM .= '="'.SLS_String::addSlashesToString($columns[$i]->Default,false).'"'; $contentM .= ')'."\n"; $contentM .= t(1).'{'."\n"; // Nullable case if ($columns[$i]->Null == "YES") { $contentM .= t(2).'if (empty($value))'."\n". t(2).'{'."\n". t(3).'$this->__set(\''.$column.'\', $value);'."\n". t(3).'$this->flushError(\''.$column.'\');'."\n". t(3).'return true;'."\n". t(2).'}'."\n\n"; } // Recover Fk $res = $xmlFk->getTagsByAttributes("//sls_configs/entry",array("tableFk","columnFk"),array($db."_".$tableName,$column)); if (!empty($res)) { $tableTm = substr($res,(strpos($res,'tablePk="')+9),(strpos($res,'"/>')-(strpos($res,'tablePk="')+9))); $tablePk = SLS_String::substrAfterFirstDelimiter($tableTm,"_"); $dbPk = SLS_String::substrBeforeFirstDelimiter($tableTm,"_"); $contentM .= t(2).'$this->_generic->useModel("'.SLS_String::tableToClass($tablePk).'","'.$dbPk.'","user");'."\n". t(2).'$object = new '.ucfirst($dbPk).'_'.SLS_String::tableToClass($tablePk).'();'."\n". t(2).'if ($object->getModel($value) === false)'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_KEY";'."\n". t(3).'return false;'."\n". t(2).'}'."\n". t(2).'$this->__set(\''.$column.'\', $value);'."\n". t(2).'$this->flushError(\''.$column.'\');'."\n". t(2).'return true;'."\n". t(1).'}'."\n\n"; } // If not a fk else { // Check filters $results = $xmlFilter->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@filter"); for($j=0 ; $j<$countJ=count($results) ; $j++) { switch($results[$j]) { case "hash": $isPassword = true; $contentM .= t(2).'if (empty($value))'."\n". t(3).'$value = $this->__'.$column.';'."\n"; break; default: $contentM .= t(2).'$value = SLS_String::filter($value,"'.$results[$j].'");'."\n"; break; } } if (count($results) > 0) $contentM .= "\n"; $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']"); // Force specific type numeric if ($this->containsRecursive($columnType,array("int","float","double","decimal","real"))) { $typeExists =($xmlType->getTag("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@type")); if (empty($typeExists)) { file_get_contents($this->_generic->getFullPath("SLS_Bo", "AddType", array("name" => strtolower($db."_".$tableName), "column" => $column, "reload" => "true", "type" => "num", "num" => (SLS_String::contains($columns[$i]->Type,"unsigned")) ? "gte" : "all", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); $xmlType->refresh(); } } if (!empty($result)) { $type = ""; $array = array('color','uniqid','email','ip_both','ip_v4','ip_v6','url','file_all','file_img','position','num_all','num_gt','num_gte','num_lt','num_lte','complexity'); for($j=0 ; $j<count($array) ; $j++) { $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."' and @type='".$array[$j]."']"); if (!empty($result)) { $type = $array[$j]; switch($type) { case "position": $contentM .= t(2).'if ($value == "" || $value == null || !is_int(intval($value)) || intval($value) < 0)'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n". t(2).'$qbd = new SLS_QueryBuilder();'."\n". t(2).'$old_'.$column.' = $this->__'.$column.';'."\n". t(2).'if (empty($old_'.$column.'))'."\n". t(2).'{'."\n". t(3).'$qbd->update()'."\n". t(4).'->from("'.$tableName.'")'."\n". t(4).'->set("`'.$column.'` = `'.$column.'` + 1")'."\n". t(4).'->where($qbd->expr()->gte("'.$column.'",$value))'."\n". t(4).'->groupBy("`'.$primaryKey.'`")'."\n". t(4).'->execute();'."\n". t(2).'}'."\n". t(2).'else'."\n". t(2).'{'."\n". t(3).'if ($old_'.$column.' != $value)'."\n". t(3).'{'."\n". t(4).'$qbd->update()'."\n". t(5).'->from("'.$tableName.'")'."\n". t(5).'->set("`'.$column.'` = `'.$column.'` ".(($old_'.$column.' < $value) ? "-" : "+")." 1")'."\n". t(5).'->where($qbd->expr()->{($old_'.$column.' < $value) ? "gt" : "gte"}("'.$column.'",($old_'.$column.' < $value) ? $old_'.$column.' : $value))'."\n". t(5).'->whereAnd($qbd->expr()->{($old_'.$column.' < $value) ? "lte" : "lt"}("'.$column.'",($old_'.$column.' < $value) ? $value : $old_'.$column.'))'."\n". t(5).'->groupBy("`'.$primaryKey.'`")'."\n". t(5).'->execute();'."\n". t(4).'$qbd->update()'."\n". t(5).'->from("'.$tableName.'")'."\n". t(5).'->set($qbd->expr()->eq("'.$column.'",$value))'."\n". t(5).'->where($qbd->expr()->eq("'.$primaryKey.'",$this->__'.$primaryKey.'))'."\n". t(5).'->groupBy("`'.$primaryKey.'`")'."\n". t(5).'->execute();'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; break; case "color": $contentM .= t(2).'if (!ctype_xdigit($value))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "uniqid": $contentM .= t(2).'if (empty($value))'."\n". t(3).'$value = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40);'."\n\n"; break; case "email": $contentM .= t(2).'if (!SLS_String::validateEmail($value))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "url": $contentM .= t(2).'if (!SLS_String::isValidUrl($value))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case (in_array($type,array("ip_both","ip_v4","ip_v6"))): $type = SLS_String::substrAfterLastDelimiter($type,"_"); $contentM .= t(2).'if (empty($value))'."\n". t(3).'$value = $_SERVER["REMOTE_ADDR"];'."\n\n"; $contentM .= t(2).'if (!SLS_String::isIp($value,"'.$type.'"))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case (in_array($type,array("num_all","num_gt","num_gte","num_lt","num_lte"))): $type = SLS_String::substrAfterLastDelimiter($type,"_"); switch($type) { case "gt": $operator = "<="; break; case "gte": $operator = "<"; break; case "lt": $operator = ">="; break; case "lte": $operator = ">"; break; } if ($type != 'all') { $contentM .= t(2).'if ($value '.$operator.' 0)'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } break; case "complexity": $rules = $xmlType->getTag("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@rules"); $rules = explode("|",$rules); $complexityMin = false; foreach($rules as $rule) { if (SLS_String::startsWith($rule,"min")) { $complexityMin = SLS_String::substrAfterFirstDelimiter($rule,"min"); unset($rules[array_shift(array_keys($rules,$rule))]); } else $rules[array_shift(array_keys($rules,$rule))] = '"'.$rule.'"'; } $rules = implode(",",$rules); $contentM .= t(2).'$complexity = array('.$rules.');'."\n". t(2).'if ((in_array("lc",$complexity) && preg_match(\'`[[:lower:]]`\', $value) === 0) || (in_array("uc",$complexity) && preg_match(\'`[[:upper:]]`\', $value) === 0) || (in_array("digit",$complexity) && preg_match(\'`[[:digit:]]`\', $value) === 0) || (in_array("wild",$complexity) && preg_match(\'`[^a-zA-Z0-9]`\', $value) === 0))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_COMPLEXITY";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; if (is_numeric($complexityMin)) $contentM .= t(2).'if (strlen(utf8_decode($value)) < '.$complexityMin.')'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "file_all": $contentM .= t(2).'if (!empty($this->__'.$column.') && $this->__'.$column.' != "'.$columns[$i]->Default.'" && $this->__'.$column.' != $value && SLS_String::startsWith((is_array($value)) ? ((array_key_exists("data",$value)) ? $value["data"]["tmp_name"] : $value["tmp_name"]) : $value, $this->getTable()."/"))'."\n". t(2).'{'."\n". t(3).'$this->deleteFiles(array("'.$column.'"));'."\n". t(3).'$this->__'.$column.' = "__Uploads/__Deprecated/".$this->__'.$column.';'."\n". t(3).'$this->save();'."\n". t(2).'}'."\n\n". t(2).'if (is_array($value))'."\n". t(2).'{'."\n". t(3).'if (array_key_exists("size",$value) && is_array($value["size"]))'."\n". t(4).'$size = $value["size"];'."\n". t(3).'if (array_key_exists("data",$value))'."\n". t(4).'$value = $value["data"];'."\n"; if ($columns[$i]->Null == "YES") $contentM .= t(3).'if ($value["error"] == 4)'."\n". t(3).'{'."\n". t(4).'$this->__set(\''.$column.'\',(empty($this->__'.$column.')) ? "" : $this->__'.$column.');'."\n". t(4).'$this->flushError(\''.$column.'\');'."\n". t(4).'return true;'."\n". t(3).'}'."\n"; $contentM .= t(3).'if ($value["error"] == 1 || $value["error"] == 2)'."\n". t(3).'{'."\n". t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_SIZE";'."\n". t(4).'return false;'."\n". t(3).'}'."\n". t(3).'else'."\n". t(3).'{'."\n". t(4).'try {'."\n". t(5).'if (!file_exists($this->_generic->getPathConfig("files").$this->_table))'."\n". t(6).'mkdir($this->_generic->getPathConfig("files").$this->_table,0755);'."\n\n". t(5).'$token = substr(md5(time().substr(sha1(microtime()),0,rand(5,12))),mt_rand(1,20),10);'."\n". t(5).'$fileName = SLS_String::sanitize(SLS_String::substrBeforeLastDelimiter($value["name"],"."),"_")."_".$token.".".SLS_String::substrAfterLastDelimiter($value["name"],".");'."\n". t(5).'rename($value["tmp_name"],$this->_generic->getPathConfig("files").$this->_table."/".$fileName);'."\n". t(5).'$value = $this->_table."/".$fileName;'."\n". t(4).'}'."\n". t(4).'catch (Exception $e) {'."\n". t(5).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_WRITE";'."\n". t(5).'return false;'."\n". t(4).'}'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; break; case "file_img": $contentM .= t(2).'if (!empty($this->__'.$column.') && $this->__'.$column.' != "'.$columns[$i]->Default.'" && $this->__'.$column.' != $value && SLS_String::startsWith((is_array($value)) ? ((array_key_exists("data",$value)) ? $value["data"]["tmp_name"] : $value["tmp_name"]) : $value, $this->getTable()."/"))'."\n". t(2).'{'."\n". t(3).'$this->deleteFiles(array("'.$column.'"));'."\n". t(3).'$this->__'.$column.' = "__Uploads/__Deprecated/".$this->__'.$column.';'."\n". t(3).'$this->save();'."\n". t(2).'}'."\n\n". t(2).'if (is_array($value))'."\n". t(2).'{'."\n". t(3).'if (array_key_exists("size",$value) && is_array($value["size"]))'."\n". t(4).'$size = $value["size"];'."\n". t(3).'if (array_key_exists("data",$value))'."\n". t(4).'$value = $value["data"];'."\n"; if ($columns[$i]->Null == "YES") $contentM .= t(3).'if ($value["error"] == 4)'."\n". t(3).'{'."\n". t(4).'$this->__set(\''.$column.'\',(empty($this->__'.$column.')) ? "" : $this->__'.$column.');'."\n". t(4).'$this->flushError(\''.$column.'\');'."\n". t(4).'return true;'."\n". t(3).'}'."\n"; $contentM .= t(3).'if ($value["error"] == 1 || $value["error"] == 2)'."\n". t(3).'{'."\n". t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_SIZE";'."\n". t(4).'return false;'."\n". t(3).'}'."\n". t(3).'else'."\n". t(3).'{'."\n". t(4).'try {'."\n". t(5).'if (!file_exists($this->_generic->getPathConfig("files").$this->_table))'."\n". t(6).'mkdir($this->_generic->getPathConfig("files").$this->_table,0755);'."\n\n". t(5).'$tmpName = $value["tmp_name"];'."\n". t(5).'if (!SLS_String::startsWith($tmpName,$this->_generic->getPathConfig("files")) || !SLS_String::contains($tmpName,"."))'."\n". t(5).'{'."\n". t(6).'if (!file_exists($this->_generic->getPathConfig("files")."__Uploads"))'."\n". t(7).'@mkdir($this->_generic->getPathConfig("files")."__Uploads");'."\n". t(6).'if (!file_exists($this->_generic->getPathConfig("files")."__Uploads/__Deprecated"))'."\n". t(7).'@mkdir($this->_generic->getPathConfig("files")."__Uploads/__Deprecated");'."\n". t(6).'$newName = $this->_generic->getPathConfig("files")."__Uploads/__Deprecated/".SLS_String::substrAfterLastDelimiter($tmpName,"/").((!SLS_String::contains($tmpName,".")) ? ".".SLS_String::substrAfterLastDelimiter($value["name"],".") : "");'."\n". t(6).'rename($tmpName,$newName);'."\n". t(6).'$tmpName = $newName;'."\n". t(5).'}'."\n". t(5).'$token = substr(md5(time().substr(sha1(microtime()),0,rand(5,12))),mt_rand(1,20),10);'."\n". t(5).'$fileName = SLS_String::sanitize(SLS_String::substrBeforeLastDelimiter($value["name"],"."),"_")."_".$token;'."\n". t(5).'$extension = pathinfo($tmpName, PATHINFO_EXTENSION);'."\n\n". t(5).'// Check img'."\n". t(5).'$img = new SLS_Image($tmpName);'."\n". t(5).'if ($img->getParam("existed"))'."\n". t(5).'{'."\n". t(6).'// Default crop'."\n". t(6).'if (empty($size))'."\n". t(7).'$size = array("x" => "0", "y" => "0", "w" => $img->getParam("width"), "h" => $img->getParam("height"));'."\n\n". t(6).'// Crop image'."\n". t(6).'$img->crop($size["x"],$size["y"],$size["w"],$size["h"]);'."\n". t(6).'// Check thumbs'."\n". t(6).'$xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"));'."\n". t(6).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$this->getDatabase()."_".$this->getTable()."\' and @column=\''.$column.'\' and @type=\'file_img\']","thumbs"));'."\n". t(6).'$thumbs = unserialize(str_replace("||#||",\'"\',$result["attribute"]));'."\n". t(6).'if (!empty($thumbs))'."\n". t(6).'{'."\n". t(7).'for($i=0 ; $i<$count=count($thumbs) ; $i++)'."\n". t(7).'{'."\n". t(8).'$img->transform($thumbs[$i]["width"],$thumbs[$i]["height"],$this->_generic->getPathConfig("files").$this->_table."/".$fileName.$thumbs[$i]["suffix"].".".$extension,$extension);'."\n". t(7).'}'."\n". t(6).'}'."\n\n". t(6).'// Move original'."\n". t(6).'rename($tmpName,$this->_generic->getPathConfig("files").$this->_table."/".$fileName.".".$extension);'."\n". t(5).'}'."\n". t(5).'else'."\n". t(5).'{'."\n". t(6).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(6).'return false;'."\n". t(5).'}'."\n". t(5).'$value = $this->_table."/".$fileName.".".$extension;'."\n". t(4).'}'."\n". t(4).'catch (Exception $e) {'."\n". t(5).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_WRITE";'."\n". t(5).'return false;'."\n". t(4).'}'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; break; } break; } } } // Not Nullable if ($columns[$i]->Null == "NO") { $contentM .= t(2).'if ($value === "")'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_EMPTY";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } if ($isPassword) { $result = array_shift($xmlFilter->getTagsAttribute("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']","hash")); $hash = (empty($result["attribute"])) ? "sha1" : $result["attribute"]; $contentM .= t(2).'if ($value != $this->__'.$column.')'."\n". t(3).'$value = SLS_String::filter($value,"hash","'.$hash.'");'."\n\n"; } // Not Nullable if ($columns[$i]->Null == "NO") { $contentM .= t(2).'if (is_null($value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_NULL";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } // Check change $contentM .= t(2).'if ($this->__'.$column.' == $value)'."\n". t(2).'{'."\n". t(3).'$this->flushError(\''.$column.'\');'."\n". t(3).'return true;'."\n". t(2).'}'."\n\n"; // Unique if ($columns[$i]->Key == "UNI" || in_array($column,$uniquesMultilang)) { $contentM .= t(2).'if (!$this->isUnique(\''.SLS_String::addSlashes($column, 'QUOTES').'\',$value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_UNIQUE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } // Float types if (SLS_String::startsWith($columnType,"float") || SLS_String::startsWith($columnType,"double") || SLS_String::startsWith($columnType,"decimal")) { $length = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, ')'), '('), ","); if (empty($length)) $length = "25"; $contentM .= t(2).'$decimal = (strpos($value, \',\')) ? str_replace(\',\', \'.\', $value) : (!strpos($value, \'.\')) ? $value.\'.0\' : $value;'."\n". t(2).'if (!is_numeric($decimal))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n". t(2).'if ((strlen($decimal)-1) > '.$length.')'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } // Enum types else if ($columnType == "enum" || $columnType == "set") { $values = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, "')"), "('"); if ($columnType == "enum") { $contentM .= t(2).'$values = explode("\',\'", "'.str_replace("''", "\'", $values).'");'."\n". t(2).'if (!in_array($value, $values))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_CONTENT";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } else { $contentM .= t(2).'$values = explode("\',\'", "'.str_replace("''", "\'", $values).'");'."\n". t(2).'$valueE = explode(",",$value);'."\n". t(2).'foreach($valueE as $set)'."\n". t(2).'{'."\n". t(3).'if (!in_array($set, $values))'."\n". t(3).'{'."\n". t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_CONTENT";'."\n". t(4).'return false;'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; } } else { if (strpos($columns[$i]->Type, "(")) { $length = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, ")"), "("); $contentM .= t(2).'if (strlen(utf8_decode($value)) > '.$length.')'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } if(SLS_String::endsWith($columnType, "int")) { $contentM .= t(2).'if (!is_numeric($value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } else if ($columnType == "date" || $columnType == "datetime" || $columnType == "timestamp") { switch ($columnType) { case "date": $contentM .= t(2).'if (!SLS_Date::isDate($value))'."\n"; break; case "datetime": $contentM .= t(2).'if (!SLS_Date::isDateTime($value))'."\n"; break; case "timestamp": $contentM .= t(2).'if (!SLS_Date::isDateTime($value))'."\n"; break; } $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } else if ($columnType == "time" || $columnType == "year") { switch ($columnType) { case "time": $contentM .= t(2).'if (strpos(\':\', $value) && substr_count($value, \':\') != 2)'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n". t(2).'$check = explode(\':\', $value);'."\n". t(2).'if (count($check) == 1 && !is_numeric($check[0]))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n". t(2).'else if ((count($check) > 1) && (!is_numeric($check[0]) || (!is_numeric($check[1]) || strlen($check[1]) > 2) || (!is_numeric($check[2]) || strlen($check[2]) > 2)))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "year": $contentM .= t(2).'if (!mktime(0, 0, 0, 0, 0, $value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; } } } $contentM .= t(2).'$this->__set(\''.$column.'\', $value);'."\n". t(2).'$this->flushError(\''.$column.'\');'."\n". t(2).'return true;'."\n". t(1).'}'."\n\n"; } } } // Get FKs to create access reference functions $fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$tableName."']",array("columnFk","tablePk")); $fkMethods = array(); $fkCursor = ""; for($i=0 ; $i<$count=count($fks) ; $i++) { $columnFk = $fks[$i]["attributes"][0]["value"]; $tablePk = $fks[$i]["attributes"][1]["value"]; $functionName = SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_"))," ",false)),""); $functionName{0} = strtolower($functionName{0}); $functionNameModified = $functionName; while(in_array($functionNameModified,$fkMethods)) $functionNameModified = $functionName."_".($fkCursor = (empty($fkCursor)) ? 2 : $fkCursor+1); $fkMethods[] = $functionNameModified; $contentM .= t(1).'/**'."\n". t(1).' * Get the instance of '.SLS_String::substrAfterFirstDelimiter($tablePk,"_").'\'s Model described by '.$columnFk.''."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' * @return '.SLS_String::tableToClass($tablePk).' $object the instance of '.SLS_String::substrAfterFirstDelimiter($tablePk,"_").'\'s Model'."\n". t(1).' */'."\n". t(1).'public function '.$functionNameModified.'()'."\n". t(1).'{'."\n". t(2).'$this->_generic->useModel("'.SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")).'","'.SLS_String::substrBeforeFirstDelimiter($tablePk,"_").'","user");'."\n". t(2).'$object = new '.ucfirst(SLS_String::substrBeforeFirstDelimiter($tablePk,"_")).'_'.SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")).'();'."\n". t(2).'$object->getModel($this->__'.$columnFk.');'."\n". t(2).'return $object;'."\n". t(1).'}'; $contentM .= ($i == ($count-1)) ? "\n" : "\n\n"; } $contentM .= '}'."\n". '?>'; return $contentM; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $langs = $this->_generic->getObjectLang()->getSiteLangs(); $listing = true; $errors = array(); $protocol = $this->_generic->getProtocol(); $siteXML = $this->_generic->getSiteXML(); $aliasesSelected = array(); $componentsSelected = array(); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginMobile = $plugin->getTag("//plugins/plugin[@code='mobile']"); $pluginMobile = (!empty($pluginMobile)) ? true : false; $controllersXML = $this->_generic->getControllersXML(); $controller = SLS_String::trimSlashesFromString($this->_http->getParam("Controller")); $controllers = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']"); if (count($controllers) == 1) { $controllerID = array_shift($controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/@id")); $protocol = $this->_generic->getControllerProtocol($controllerID); $listing = false; $xml->addFullTag('request', 'AddAction', true); if ($this->_http->getParam('reload') == 'true') { // Get the form informations $newAction = SLS_String::stringToUrl(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("actionName"))), "", false); $needDynamic = SLS_String::trimSlashesFromString($this->_http->getParam("dynamic")); $needOffline = SLS_String::trimSlashesFromString($this->_http->getParam("offline")); $needDefault = SLS_String::trimSlashesFromString($this->_http->getParam("default")); $searchEngine = SLS_String::trimSlashesFromString($this->_http->getParam("indexes")); $postProtocol = SLS_String::trimSlashesFromString($this->_http->getParam("protocol")); $tpl = SLS_String::trimSlashesFromString($this->_http->getParam('template')); $aliases = SLS_String::trimSlashesFromString($this->_http->getParam('domains')); $components = SLS_String::trimSlashesFromString($this->_http->getParam('components')); $cache_visibility = SLS_String::trimSlashesFromString($this->_http->getParam('cache_visibility')); $cache_scope = SLS_String::trimSlashesFromString($this->_http->getParam('cache_scope')); $cache_expiration = SLS_String::trimSlashesFromString($this->_http->getParam('cache_expiration')); $cache_responsive = SLS_String::trimSlashesFromString($this->_http->getParam('cache_responsive')); if (empty($postProtocol)) $postProtocol = "http"; $postActionsLang = array(); $postTitlesLang = array(); $postDescriptionsLang = array(); $postKeywordsLang = array(); $toCache = (in_array($cache_visibility,array("public","private"))) ? true : false; // If responsive wanted if ($cache_responsive == "true" && !$pluginMobile) { // Force Mobile plugin download file_get_contents($this->_generic->getFullPath("SLS_Bo", "SearchPlugin", array("Action" => "Download", "Server" => "4", "Plugin" => "20", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); } if (empty($newAction)) array_push($errors, "Action name can't be empty"); $actionExist = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name='".$newAction."']"); if (count($actionExist) == 0) { if (empty($postProtocol) || ($postProtocol != 'http' && $postProtocol != 'https')) array_push($errors, "Protocol must be http or https"); else $protocol = $postProtocol; if (!empty($aliases) && is_array($aliases)) foreach($aliases as $alias) array_push($aliasesSelected,$alias); if (!empty($components) && is_array($components)) foreach($components as $component) array_push($componentsSelected,$component); $siteLangs = $this->_generic->getObjectLang()->getSiteLangs(); foreach ($siteLangs as $lang) { // Check Url $postLang = trim(SLS_String::stringToUrl(SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-action")), "", false)); $translationExist = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller/scontrollerLangs[scontrollerLang = '".$postLang."']"); if (empty($postLang)) array_push($errors, "You need to fill the ".$lang." url translations"); elseif(count($translationExist) != 0) array_push($errors, "You URL translation in ".$lang." is already in use on another action in the same controller"); else $postActionsLang[$lang] = $postLang; // Get Titles $postTitlesLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-title")); // Get Description $postDescriptionsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-description")); // Get Keywords $postKeywordsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-keywords")); } if ($toCache && (!is_numeric($cache_expiration) || $cache_expiration < 0)) array_push($errors, "Your expiration cache must be a positive time or 0"); if ($toCache && (!in_array($cache_scope,array("full","partial")))) array_push($errors, "Your must describe your cache scope"); if (count($errors) == 0) { // If an error existing and the controller directory wasn't created if (!is_dir($this->_generic->getPathConfig("actionsControllers").$controller)) mkdir($this->_generic->getPathConfig("actionsControllers").$controller); if (!is_file($this->_generic->getPathConfig("actionsControllers").$controller."/__".$controller.".protected.php")) { $strControllerProtected = '<?php'."\n". '/**'."\n". '* Class generic for the controller '.$newControllerName.''."\n". '* Write here all your generic functions you need in your '.$newControllerName.' Actions'."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Mvc.Controllers.'.$newControllerName.''."\n". '* @see Mvc.Controllers.SiteProtected'."\n". '* @see Sls.Controllers.Core.SLS_GenericController'."\n". '* @since 1.0'."\n". '*/'."\n". 'class '.$newControllerName.'ControllerProtected extends SiteProtected'."\n". '{'."\n". t(1).'public function init()'."\n". t(1).'{'."\n". t(2).'parent::init();'."\n". t(1).'}'."\n". '}'."\n". '?>'; file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/__".$controller.".protected.php", $strControllerProtected); } // Create Controller File $strControllerAction = '<?php'."\n". '/**'."\n". '* Class '.$newAction.' into '.$controller.' Controller'."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Mvc.Controllers.'.$controller."\n". '* @see Mvc.Controllers.'.$controller.'.ControllerProtected'."\n". '* @see Mvc.Controllers.SiteProtected'."\n". '* @see Sls.Controllers.Core.SLS_GenericController'."\n". '* @since 1.0'."\n". '*'."\n". '*/'."\n". 'class '.$controller.$newAction.' extends '.$controller.'ControllerProtected'."\n". '{'."\n". t(1).'public function init()'."\n". t(1).'{'."\n". t(2).'parent::init();'."\n". t(1).'}'."\n\n". t(1).'public function action()'."\n". t(1).'{'."\n". t(2)."\n". t(1).'}'."\n". "}\n". '?>'; file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/".$newAction.".controller.php", $strControllerAction); // Create Lang Files if (!is_dir($this->_generic->getPathConfig("langs")."Actions/".$controller)) mkdir($this->_generic->getPathConfig("langs")."Actions/".$controller); $langsFiles = array(); foreach ($siteLangs as $lang) { $strLang = '<?php'."\n". '/**'."\n". '* '.strtoupper($lang).' File for the action '.$newAction.' into '.$controller.' Controller'."\n". '* You can create all your sentences variables here. To create it, follow the exemple :'."\n". '* '."\t".'Access it with JS and XSL variable : $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'KEY_OF_YOUR_VARIABLE\'] = "value of your sentence in '.strtoupper($lang).'";'."\n". '* '."\t".'Access it with XSL variable only : $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'XSL\'][\'KEY_OF_YOUR_VARIABLE\'] = "value of your sentence in '.strtoupper($lang).'";'."\n". '*'."\n". '* '."\t".'You can customise the value \'KEY_OF_YOUR_VARIABLE\' and "value of your sentence in '.strtoupper($lang).'" '."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Langs.Actions.'.$controller."\n". '* @since 1.0'."\n". '*'."\n". '*/'."\n". '?>'; file_put_contents($this->_generic->getPathConfig("langs")."Actions/".$controller."/".$newAction.".".strtolower($lang).".lang.php", $strLang); } // Create Views File if (!is_dir($this->_generic->getPathConfig("viewsBody").$controller)) mkdir($this->_generic->getPathConfig("viewsBody").$controller); if (!is_dir($this->_generic->getPathConfig("viewsHeaders").$controller)) mkdir($this->_generic->getPathConfig("viewsHeaders").$controller); $strBody = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n". t(1).'<xsl:template name="'.$newAction.'">'."\n". t(2).'<h1>Customize the body of this page in <i>'.$this->_generic->getPathConfig('viewsBody').$controller.'/'.$newAction.'.xsl</i></h1>'."\n". t(2).'<h2>And your headers in <i>'.$this->_generic->getPathConfig('viewsHeaders').$controller.'/'.$newAction.'.xsl</i></h2>'."\n". t(1).'</xsl:template>'."\n". '</xsl:stylesheet>'; $strHeader = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n". t(1).'<xsl:template name="Header'.$newAction.'">'."\n". t(1).'</xsl:template>'."\n". '</xsl:stylesheet>'; file_put_contents($this->_generic->getPathConfig("viewsBody").$controller.'/'.$newAction.'.xsl', $strBody); file_put_contents($this->_generic->getPathConfig("viewsHeaders").$controller.'/'.$newAction.'.xsl', $strHeader); // End of files creation // XML Modifications $metasXML = $this->_generic->getCoreXML('metas'); // Get the titles // If default, reset other in current controller if (!empty($needDefault)) { $actions = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller/@id"); foreach($actions as $curActionId) $controllersXML->setTagAttributes("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@id='".$curActionId."']", array('default' => '0')); } $actionId = $this->_generic->generateActionId(); $xmlAction = "<scontroller name=\"".$newAction."\" needParam=\""; $xmlAction .= ($this->_http->getParam("dynamic") == "on") ? "1" : "0"; $xmlAction .= "\" id=\"".$actionId."\" protocol=\"".$protocol."\""; if ($tpl != -1) $xmlAction .= " tpl=\"".$tpl."\""; if (!empty($aliases)) $xmlAction .= " domains=\"".implode(",",$aliases)."\""; if (!empty($components)) $xmlAction .= " components=\"".implode(",",$components)."\""; if (!empty($needOffline)) $xmlAction .= " disable=\"1\""; if (!empty($needDefault)) $xmlAction .= " default=\"1\""; if ($toCache) $xmlAction .= " cache=\"".$cache_visibility."|".$cache_scope."|".(($cache_responsive == "true") ? "responsive" : "no_responsive")."|".$cache_expiration."\""; $xmlAction .= "><scontrollerLangs>"; $strMetas = "<action id=\"".$actionId."\" />"; $metasXML->appendXMLNode("//sls_configs", $strMetas); foreach ($siteLangs as $lang) { $xmlAction .= "<scontrollerLang lang=\"".$lang."\"><![CDATA[".$postActionsLang[$lang]."]]></scontrollerLang>"; // Metas $metas = "<title lang=\"".$lang."\"><![CDATA[".$postTitlesLang[$lang]."]]></title>"; $metas .= "<description lang=\"".$lang."\"><![CDATA[".$postDescriptionsLang[$lang]."]]></description>"; $metas .= "<keywords lang=\"".$lang."\"><![CDATA[".$postKeywordsLang[$lang]."]]></keywords>"; $metasXML->appendXMLNode("//sls_configs/action[@id=\"".$actionId."\"]", $metas); } $xmlAction .= "</scontrollerLangs></scontroller>"; if (!SLS_String::contains($searchEngine,", ")) $searchEngine = str_replace(",",", ",$searchEngine); if ($searchEngine != "index, follow" && $searchEngine != "noindex, follow" && $searchEngine != "noindex, nofollow" && $searchEngine != "index, nofollow") $searchEngine = "index, follow"; $metasXML->appendXMLNode("//sls_configs/action[@id='".$actionId."']", "<robots><![CDATA[".$searchEngine."]]></robots>"); $controllersXML->appendXMLNode("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers", $xmlAction); file_put_contents($this->_generic->getPathConfig("configSecure")."controllers.xml", $controllersXML->getXML()); file_put_contents($this->_generic->getPathConfig("configSls")."metas.xml", $metasXML->getXML()); $controllers = $this->_generic->getTranslatedController("SLS_Bo", "Controllers"); $this->_generic->redirect($controllers['controller']."/".$controllers['scontroller'].".sls"); } } else array_push($errors, "This generic name is already in use for this controller"); if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); $xml->startTag('form'); $xml->addFullTag("controllerName", $postControllerName); foreach ($postActionsLang as $key=>$value) $xml->addFullTag($key."-action", $value, true); $xml->endTag('form'); $xml->addFullTag("default",(empty($needDefault)) ? "false" : "true",true); $xml->addFullTag("dynamic",(empty($needDynamic)) ? "false" : "true",true); $xml->addFullTag("offline",(empty($needOffline)) ? "false" : "true",true); $xml->startTag("cache"); $xml->addFullTag("cache_visibility", $cache_visibility,true); $xml->addFullTag("cache_scope", $cache_scope,true); $xml->addFullTag("cache_responsive", $cache_responsive,true); $xml->addFullTag("cache_expiration", $cache_expiration,true); $xml->endTag("cache"); } } else { $defaultExists = $controllersXML->getTag("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@default='1']/@name"); $xml->addFullTag("default",(empty($defaultExists)) ? "true" : "false",true); $xml->startTag("cache"); $xml->addFullTag("cache_visibility", "",true); $xml->addFullTag("cache_scope", "",true); $xml->addFullTag("cache_responsive","",true); $xml->addFullTag("cache_expiration", 0,true); $xml->endTag("cache"); } // Build all tpls $tpls = $this->getAppTpls(); $xml->startTag("tpls"); foreach($tpls as $template) $xml->addFullTag("tpl",$template,true); $xml->endTag("tpls"); $xml->startTag('controller'); $xml->addFullTag("name", $controller, true); $xml->startTag('translations'); foreach ($langs as $lang) { $xml->startTag('translation'); $xml->addFullTag("lang", $lang, true); $xml->addFullTag("name", $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/controllerLangs/controllerLang[@lang='".$lang."']"), true); $xml->endTag('translation'); } $xml->endTag('translations'); $xml->endTag('controller'); $xml->addFullTag('request', 'addAction', true); } else { $this->_generic->dispatch('SLS_Bo', 'Controllers'); } if (empty($tpl)) $tpl = $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/@tpl"); $xml->addFullTag('protocol', $protocol, true); $xml->addFullTag('template', $tpl, true); $aliases = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias")); $xml->startTag("aliases"); for($i=0 ; $i<$count=count($aliases) ; $i++) { $xml->startTag("alias"); $xml->addFullTag("name",$aliases[$i]["attributes"][0]["value"],true); $xml->addFullTag("selected",(in_array($aliases[$i]["attributes"][0]["value"],$aliasesSelected)) ? "true" : "false",true); $xml->endTag("alias"); } $xml->endTag("aliases"); $components = $this->_generic->recursiveReadDir($this->_generic->getPathConfig("componentsControllers"), array(), array(0=>"php")); $xml->startTag("components"); foreach ($components as $component) { $xml->startTag("component"); $xml->addFullTag("name", SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),true); $xml->addFullTag("selected",(in_array(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),$componentsSelected)) ? "true" : "false",true); $xml->endTag("component"); } $xml->endTag("components"); $this->saveXML($xml); }
public function action() { $xml = $this->getXML(); $xml = $this->makeMenu($xml); $user = $this->hasAuthorative(); // Objects $sql = SLS_Sql::getInstance(); $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml")); // Get the table & class name $tableName = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $className = ucfirst($db)."_".SLS_String::tableToClass($tableName); $file = ucfirst($db).".".SLS_String::tableToClass($tableName); $fileName = ucfirst($db).".".SLS_String::tableToClass($tableName).".model.php"; // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); // Remind old properties $this->_generic->useModel(SLS_String::tableToClass($tableName),ucfirst(strtolower($db)), "user"); $object = new $className(); $oldColumns = $object->getColumns(); // Update Model $contentM = $this->getModelSource($tableName,$db); file_put_contents($this->_generic->getPathConfig("models").$fileName,$contentM); // Check Bo $controllerBo = $this->_generic->getBo(); if (!empty($controllerBo)) { $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($className)."']"; $boExists = $xmlBo->getTag($boPath."/@type"); if (empty($boExists)) { $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($className)."']"; $boExists = $xmlBo->getTag($boPath); } if (!empty($boExists)) { $columns = $sql->showColumns($tableName); $newColumns = array(); for($i=0 ; $i<$count=count($columns) ; $i++) $newColumns[] = $columns[$i]->Field; $xmlNodes = ''; foreach($newColumns as $column) { $columnExists = $xmlBo->getTag($boPath."/columns/column[@table='".strtolower($className)."' and @name='".$column."']/@name"); if (empty($columnExists)) { // Avoid pk $isPk = ($column == $object->getPrimaryKey() || $column == 'pk_lang') ? true : false; // Avoid fk $fkExist = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($db."_".$tableName)."' and @columnFk='".$column."']/@tablePk"); $isFk = (!empty($fkExist)) ? true : false; // Avoid quick edit on type file $fileExist = $xmlType->getTag("//sls_configs/entry[@table='".strtolower($db."_".$tableName)."' and @column='".$column."' and (@type='file_all' or @type='file_img')]/@column"); $isFile = (!empty($fileExist)) ? true : false; $xmlNodes .= ' <column table="'.strtolower($db."_".$tableName).'" name="'.$column.'" multilanguage="'.(($object->isMultilanguage() && !$isPk) ? "true" : "false").'" displayFilter="true" displayList="'.(($isFk) ? "false" : "true").'" allowEdit="'.(($isPk || $isFk || $isFile) ? "false" : "true").'" allowHtml="false" />'."\n"; } } if (!empty($xmlNodes)) { $xmlBo->appendXMLNode($boPath."/columns",$xmlNodes); } $deprecatedColumns = array_diff($oldColumns,$newColumns); foreach($deprecatedColumns as $column) { $xmlBo->deleteTags($boPath."/columns/column[@table='".strtolower($className)."' and @name='".$column."']",1); } $xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML()); $xmlBo->refresh(); } } $action_id = $this->_http->getParam("Redirect"); if ($this->_generic->actionIdExists($action_id)) { $infos = $this->_generic->translateActionId($action_id); $this->_generic->redirect($infos['controller']."/".$infos['scontroller']); } else { $controllers = $this->_generic->getTranslatedController("SLS_Bo","EditModel"); $this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']."/name/".$db."_".$tableName); } }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $siteXML = $this->_generic->getSiteXML(); $errors = array(); $aliases = array(); $domains = array(); // Prod Deployment $env = $this->_http->getParam("Env"); if (empty($env)) $env = "prod"; $finalFile = ($this->_http->getParam("ProdDeployment") == "true") ? "site_".$env.".xml" : "site.xml"; $isInBatch = ($this->_http->getParam("CompleteBatch") == "true") ? true : false; $xml->addFullTag("is_batch",($isInBatch) ? "true" : "false",true); $xml->addFullTag("is_prod",($this->_http->getParam("ProdDeployment") == "true") ? "true" : "false",true); $xml->addFullTag("env",$env,true); // Get default values if ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) { $xmlSite = new SLS_XMLToolbox(file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")); $defaultDomain = $xmlSite->getTag("//configs/domainName/domain"); $defaultProject = $xmlSite->getTag("//configs/projectName"); $defaultVersion = $xmlSite->getTag("//configs/versionName"); $defaultExtension = $xmlSite->getTag("//configs/defaultExtension"); $defaultCharset = $xmlSite->getTag("//configs/defaultCharset"); $defaultDoctype = $xmlSite->getTag("//configs/defaultDoctype"); $timezone_area = SLS_String::substrBeforeFirstDelimiter($xmlSite->getTag("//configs/defaultTimezone"),"/"); $timezone_city = SLS_String::substrAfterFirstDelimiter($xmlSite->getTag("//configs/defaultTimezone"),"/"); $defaultLang = $xmlSite->getTag("//configs/defaultLang"); $defaultdomainSessionShare = $xmlSite->getTag("//configs/domainSession"); } else { $defaultDomain = $this->_generic->getSiteConfig("domainName"); $defaultProject = $this->_generic->getSiteConfig("projectName"); $defaultVersion = $this->_generic->getSiteConfig("versionName"); $defaultExtension = $this->_generic->getSiteConfig("defaultExtension"); $defaultCharset = $this->_generic->getSiteConfig("defaultCharset"); $defaultDoctype = $this->_generic->getSiteConfig("defaultDcotype"); $timezone_area = SLS_String::substrBeforeFirstDelimiter($this->_generic->getSiteConfig("defaultTimezone"),"/"); $timezone_city = SLS_String::substrAfterFirstDelimiter($this->_generic->getSiteConfig("defaultTimezone"),"/"); $defaultLang = $this->_generic->getSiteConfig("defaultLang"); $defaultdomainSessionShare = $this->_generic->getSiteConfig("domainSession"); } $reload = $this->_http->getParam("reload"); $charsetsXML = new SLS_XMLToolBox(file_get_contents($this->_generic->getPathConfig('configSls')."charset.xml")); $charsets = array_map('strtoupper', $charsetsXML->getTags('//sls_configs/charset/code')); $handle2 = file_get_contents($this->_generic->getPathConfig("configSls").'timezone.xml'); $xml->addFullTag("timezones", SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterFirstDelimiter($handle2, "<sls_configs>"), "</sls_configs>"), false); $langs = $this->_generic->getSiteXML()->getTags('//configs/langs/name'); if ($reload == "true") { $domains = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias")); for($i=0 ; $i<$count=count($domains) ; $i++) array_push($aliases,$domains[$i]["attributes"][0]["value"]); // Get New Parameters $exportConfig = $this->_http->getParam('export'); $domains = array(); foreach($aliases as $alias) { $domain = SLS_String::trimSlashesFromString($this->_http->getParam("domain_".$alias, "post")); if (SLS_String::endsWith(trim($domain),"/")) $domain = SLS_String::substrBeforeLastDelimiter(trim($domain),"/"); $domains[$alias]= $domain; } $postProject = SLS_String::trimSlashesFromString($this->_http->getParam("project", "post")); $postVersion = SLS_String::trimSlashesFromString($this->_http->getParam("version", "post")); $postExtension = SLS_String::trimSlashesFromString($this->_http->getParam("extension", "post")); $postCharset = SLS_String::trimSlashesFromString($this->_http->getParam("charset", "post")); $postDoctype = SLS_String::trimSlashesFromString($this->_http->getParam("doctype", "post")); $timezone_area = SLS_String::trimSlashesFromString($this->_http->getParam('settings_timezone_area')); $timezone_city = SLS_String::trimSlashesFromString($this->_http->getParam('settings_timezone_area_'.$timezone_area)); $postLang = SLS_String::trimSlashesFromString($this->_http->getParam("lang", "post")); $domainSessionShare = SLS_String::trimSlashesFromString($this->_http->getParam("domainSession", "post")); if ($this->_http->getParam("domainSessionActive") == "") $domainSessionShare = ""; foreach($domains as $alias => $domain) if (empty($domain)) array_push($errors, "The Domain name is required for the domain alias ".$alias); if (empty($postProject)) array_push($errors, "The project Name is required"); if (empty($postVersion)) array_push($errors, "The version Name is required"); if (empty($postExtension)) array_push($errors, "The extension is required"); if (!in_array($postCharset, $charsets)) array_push($errors, "The Charset selected is incorrect"); if (empty($postDoctype)) array_push($errors, "The doctype is required"); if (empty($timezone_area) || empty($timezone_city)) array_push($errors,"You must choose your default timezone"); if (!in_array($postLang, $langs)) array_push($errors, "The Default lang selected is incorrect"); if ($this->_http->getParam("domainSessionActive") != "" && empty($domainSessionShare)) array_push($errors,"You need to fill the domain pattern from which you want to share session"); if (empty($errors)) { foreach($domains as $alias => $domain) $siteXML->setTag("//configs/domainName/domain[@alias='".$alias."']", $domain, true); if ($defaultProject != $postProject) $siteXML->setTag("//configs/projectName", $postProject, true); if ($defaultVersion != $postVersion) $siteXML->setTag("//configs/versionName", $postVersion, true); if ($defaultExtension != $postExtension) $siteXML->setTag("//configs/defaultExtension", $postExtension, true); if ($defaultCharset != $postCharset) $siteXML->setTag("//configs/defaultCharset", $postCharset, true); if ($defaultDoctype != $postDoctype) $siteXML->setTag("//configs/defaultDoctype", $postDoctype, true); if ($defaultTimezone != $timezone_area."/".$timezone_city) $siteXML->setTag("//configs/defaultTimezone", $timezone_area."/".$timezone_city, true); if ($defaultLang != $postLang) $siteXML->setTag("//configs/defaultLang", $postLang, true); if ($defaultdomainSessionShare != $domainSessionShare) $siteXML->setTag("//configs/domainSession", $domainSessionShare, true); if ($exportConfig == "on") { $date = gmdate('D, d M Y H:i:s'); header("Content-Type: text/xml"); header('Content-Disposition: attachment; filename='.$finalFile); header('Last-Modified: '.$date. ' GMT'); header('Expires: ' .$date); // For This F**k'in Browser if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT'])) { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else header('Pragma: no-cache'); print($siteXML->getXML()); exit; } else { $siteXML->refresh(); @file_put_contents($this->_generic->getPathConfig("configSecure").$finalFile, $siteXML->getXML()); if ($isInBatch) $this->_generic->forward("SLS_Bo","DataBaseSettings",array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"CompleteBatch","value"=>"true"),array("key"=>"Env","value"=>$env))); else if ($this->_http->getParam("ProdDeployment") == "true") $this->_generic->forward("SLS_Bo","ProductionDeployment"); } } else { $xml->startTag('errors'); foreach ($errors as $error) $xml->addFullTag('error', $error); $xml->endTag('errors'); } } $this->_generic->eraseCache('Site'); $xml->startTag("charsets"); foreach ($charsets as $charset) $xml->addFullTag('charset', $charset, true); $xml->endTag("charsets"); $xml->startTag("langs"); foreach ($langs as $lang) $xml->addFullTag('lang', $lang, true); $xml->endTag("langs"); $xmlSite = (file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? new SLS_XMLToolbox(file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) : null; $xml->startTag("current_values"); if ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) $domains = $xmlSite->getTagsAttributes("//configs/domainName/domain",array("alias","default","lang")); else $domains = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias","default","lang")); $xml->startTag("domains"); for($i=0 ; $i<$count=count($domains) ; $i++) { $alias = $domains[$i]["attributes"][0]["value"]; $default = ($domains[$i]["attributes"][1]["value"] == 1) ? true : false; $domain_lang = $domains[$i]["attributes"][2]["value"]; $xml->startTag("domain"); $xml->addFullTag("alias",$alias,true); $xml->addFullTag("default",($default) ? "true" : "false",true); $xml->addFullTag("domain",$domains[$i]["value"],true); $xml->addFullTag("lang",$domain_lang,true); $xml->addFullTag("delete_url",$this->_generic->getFullPath("SLS_Bo","DeleteDomain",array(array("key"=>"alias","value"=>$alias))),true); $xml->endTag("domain"); } $xml->endTag("domains"); $xml->addFullTag("project", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/projectName") : $this->_generic->getSiteConfig("projectName"), true); $xml->addFullTag("version", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/versionName") : $this->_generic->getSiteConfig("versionName"), true); $xml->addFullTag("extension", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultExtension") :$this->_generic->getSiteConfig("defaultExtension"), true); $xml->addFullTag("charset", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultCharset") :$this->_generic->getSiteConfig("defaultCharset"), true); $xml->addFullTag("doctype", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultDoctype") :$this->_generic->getSiteConfig("defaultDoctype"), true); $xml->addFullTag("lang", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultLang") :$this->_generic->getSiteConfig("defaultLang"), true); $xml->addFullTag("domain_session", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/domainSession") : ((is_null($this->_generic->getSiteConfig("domainSession"))) ? "" : $this->_generic->getSiteConfig("domainSession")), true); $xml->startTag("timezone"); $xml->addFullTag("area",$timezone_area,true); $xml->addFullTag("city",$timezone_city,true); $xml->endTag("timezone"); $xml->endTag("current_values"); $xml->addFullTag("add_domain_url",$this->_generic->getFullPath("SLS_Bo","AddDomain"),true); $environments = $this->getEnvironments(); $xml->startTag("environments"); foreach($environments as $environment) $xml->addFullTag("environment",$environment,true); $xml->endTag("environments"); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginMobile = $plugin->getTag("//plugins/plugin[@code='mobile']"); $pluginMobile = (!empty($pluginMobile)) ? true : false; if ($this->_http->getParam('reload') == 'true') { $controller = SLS_String::trimSlashesFromString($this->_http->getParam('controllerName')); $cache_visibility = SLS_String::trimSlashesFromString($this->_http->getParam('cache_visibility')); $cache_expiration = SLS_String::trimSlashesFromString($this->_http->getParam('cache_expiration')); $cache_responsive = SLS_String::trimSlashesFromString($this->_http->getParam('cache_responsive')); // If responsive wanted if ($cache_responsive == "true" && !$pluginMobile) { // Force Mobile plugin download file_get_contents($this->_generic->getFullPath("SLS_Bo", "SearchPlugin", array("Action" => "Download", "Server" => "4", "Plugin" => "20", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); } if (empty($controller)) array_push($errors, "You must fill the component controller name"); if (in_array($cache_visibility,array("public","private")) && (!is_numeric($cache_expiration) || $cache_expiration < 0)) array_push($errors, "Your expiration cache must be a positive time or 0"); $controller = str_replace(" ", "", ucwords(trim(SLS_String::getAlphaString($controller)))); $components = $this->_generic->recursiveReadDir($this->_generic->getPathConfig("componentsControllers"), array(), array(0=>"php")); foreach ($components as $component) { if (SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php") == $controller) { array_push($errors, "The name '".$controller."' is already in use for a component controller"); break; } } if (empty($errors)) { $strNewComponent = '<?php'."\n". '/**'."\n". '* Controller Component '.$controller.'Controller'."\n". '*'."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Mvc.Controllers.Components.'.$controller.'Controller'."\n". '* @see Sls.Controllers.Core.SLS_FrontComponent'."\n". '* @since 1.0'."\n". '*/'."\n". 'class '.$controller.'Controller extends SLS_FrontComponent implements SLS_IComponent '."\n". '{'."\n". ''."\n". t(1).'public function __construct()'."\n". t(1).'{'."\n". t(2).'parent::__construct(true);'."\n". t(1).'}'."\n". ''."\n". t(1).'public function constructXML()'."\n". t(1).'{'."\n". t(2).'// Write here all your instructions to make your Component configuration with xml by $this->_xmlToolBox'."\n". t(1).'}'."\n". ''."\n". '}'."\n". '?>'; file_put_contents($this->_generic->getPathConfig("componentsControllers").$controller.".controller.php", $strNewComponent); // Cache if (in_array($cache_visibility,array("public","private"))) { $this->_cache->addObject(strtolower($controller),"components",$cache_visibility,($cache_responsive=="true") ? "responsive" : "no_responsive",$cache_expiration); $this->_cache->saveObject(); } $this->_generic->forward('SLS_Bo', 'Controllers'); } if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); $xml->startTag('form'); $xml->addFullTag("controllerName", $controller); $xml->addFullTag("cache_visibility", $cache_visibility,true); $xml->addFullTag("cache_expiration", $cache_expiration,true); $xml->addFullTag("cache_responsive", $cache_responsive,true); $xml->endTag('form'); } } else { $xml->startTag('form'); $xml->addFullTag("controllerName", $controller,true); $xml->addFullTag("cache_visibility", "",true); $xml->addFullTag("cache_expiration", "0",true); $xml->addFullTag("cache_responsive", "",true); $xml->endTag('form'); } $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginMobile = $plugin->getTag("//plugins/plugin[@code='mobile']"); $pluginMobile = (!empty($pluginMobile)) ? true : false; $controller = SLS_String::trimSlashesFromString($this->_http->getParam('Controller')); if (is_file($this->_generic->getPathConfig("staticsControllers").$controller.".controller.php")) { if ($this->_http->getParam('reload') == 'true') { $newController = SLS_String::trimSlashesFromString($this->_http->getParam('controllerName')); $oldController = SLS_String::trimSlashesFromString($this->_http->getParam('oldName')); $cache_visibility = SLS_String::trimSlashesFromString($this->_http->getParam('cache_visibility')); $cache_expiration = SLS_String::trimSlashesFromString($this->_http->getParam('cache_expiration')); $cache_responsive = SLS_String::trimSlashesFromString($this->_http->getParam('cache_responsive')); $toCache = (in_array($cache_visibility,array("public","private"))) ? true : false; // If responsive wanted if ($cache_responsive == "true" && !$pluginMobile) { // Force Mobile plugin download file_get_contents($this->_generic->getFullPath("SLS_Bo", "SearchPlugin", array("Action" => "Download", "Server" => "4", "Plugin" => "20", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); } if (empty($newController)) array_push($errors, "You must fill the static controller name"); if (in_array($cache_visibility,array("public","private")) && (!is_numeric($cache_expiration) || $cache_expiration < 0)) array_push($errors, "Your expiration cache must be a positive time or 0"); $newController = str_replace(" ", "", ucwords(trim(SLS_String::getAlphaString($newController)))); $statics = $this->_generic->recursiveReadDir($this->_generic->getPathConfig("staticsControllers"), array(), array(0=>"php")); foreach ($statics as $static) { if (SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterLastDelimiter($static, "/"), ".controller.php") == $newController && SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterLastDelimiter($static, "/"), ".controller.php") != $oldController) { array_push($errors, "The name '".$newController."' is already in use for a static controller"); break; } } if (empty($errors)) { if ($newController != $oldController) { $strController = file_get_contents($this->_generic->getPathConfig("staticsControllers").$oldController.".controller.php"); $strController = str_replace($oldController."Controller", $newController."Controller", $strController); file_put_contents($this->_generic->getPathConfig("staticsControllers").$newController.".controller.php", $strController); unlink($this->_generic->getPathConfig("staticsControllers").$oldController.".controller.php"); } // Cache if (in_array($cache_visibility,array("public","private"))) { $this->_cache->addObject(strtolower($newController),"statics",$cache_visibility,($cache_responsive=="true") ? "responsive" : "no_responsive",$cache_expiration); $this->_cache->saveObject(); } else { $this->_cache->deleteObject(strtolower($newController),"statics"); $this->_cache->saveObject(); } $this->_generic->forward("SLS_Bo", "Controllers"); } if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $xml->startTag('form'); $xml->addFullTag("controllerName", $postControllerName); $xml->addFullTag("cache_visibility", $cache_visibility,true); $xml->addFullTag("cache_expiration", $cache_expiration,true); $xml->addFullTag("cache_responsive", $cache_expiration,true); $xml->endTag('form'); } else { $xml->startTag('form'); $xml->addFullTag("controllerName", $controller); $xml->addFullTag("cache_visibility", $this->_cache->getObject(strtolower($controller),"statics","visibility"),true); $xml->addFullTag("cache_expiration", $this->_cache->getObject(strtolower($controller),"statics","expire"),true); $xml->addFullTag("cache_responsive", $this->_cache->getObject(strtolower($controller),"components","responsive"),true); $xml->endTag('form'); } $xml->startTag('controller'); $xml->addFullTag("name", $controller, true); $xml->endTag('controller'); } else { $this->_generic->forward('SLS_Bo', 'Controllers'); } $this->saveXML($xml); }
/** * Get foreign key recordsets of a given table * * @param string $tableSource * @param string $tableFk * @param string $pkFk * @param array $columnsToSelect * @param string $clause * @param string $lang * @param string $value * @param int $nb * @param int $id * @since 1.0.6 */ public function fkAC($tableSource,$tableFk,$pkFk,$columnsToSelect,$clause="",$lang="",$value="",$nb=10,$id=0) { $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."fks.xml")); $currentDb = $this->_db->getCurrentDb(); if (!empty($id)) { $sql = "SELECT * FROM "; for($i=0 ; $i<$count=count($tableFk) ; $i++) { if(!$this->_db->tableExists($tableFk[$i])) continue; if ($i> 0) { $currentFkTable = $tableFk[$i]; $sourceFkTable = ($i==0) ? $tableSource : $tableFk[0]; $columnFk = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($currentDb."_".$sourceFkTable)."' and @tablePk='".strtolower($currentDb)."_".SLS_String::tableToClass($currentFkTable)."']/@columnFk"); $this->_generic->useModel(SLS_String::tableToClass($currentFkTable), $currentDb); $currentFkClass = ucfirst(strtolower($currentDb))."_".SLS_String::tableToClass($currentFkTable); $currentFkObject = new $currentFkClass(); $sql .= "LEFT JOIN `".$tableFk[$i]."` "; } $sql .= "`".$tableFk[$i]."` "; if ($i > 0 && !empty($columnFk)) { $sql .= "ON `".$tableFk[0]."`.`".$columnFk."` = `".$tableFk[$i]."`.`".$currentFkObject->getPrimaryKey()."` "; } } $tableAlias = (!empty($tableFk)) ? "`".$tableFk[0]."`." : ""; $sql .= "WHERE ".$tableAlias."`".$pkFk."` = ".$id." "; if (!empty($lang)) $sql .= "AND ".$tableAlias."`pk_lang` = ".$this->_db->quote($lang)." "; $sql .= "GROUP BY ".$tableAlias."`".$pkFk."` ORDER BY ".$clause." ASC LIMIT 0,".$nb; $results = $this->_db->select($sql); } else { if (empty($clause) || empty($value)) { $sql = "SELECT COUNT(*) AS total, ".implode(',',$columnsToSelect)." FROM `".$tableSource."` "; for($i=0 ; $i<$count=count($tableFk) ; $i++) { if(!$this->_db->tableExists($tableFk[$i])) continue; $currentFkTable = $tableFk[$i]; $sourceFkTable = ($i==0) ? $tableSource : $tableFk[0]; $columnFk = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($currentDb."_".$sourceFkTable)."' and @tablePk='".strtolower($currentDb)."_".SLS_String::tableToClass($currentFkTable)."']/@columnFk"); $this->_generic->useModel(SLS_String::tableToClass($currentFkTable), $currentDb); $currentFkClass = ucfirst(strtolower($currentDb))."_".SLS_String::tableToClass($currentFkTable); $currentFkObject = new $currentFkClass(); $sql .= "LEFT JOIN `".$tableFk[$i]."` ON `".$sourceFkTable."`.`".$columnFk."` = `".$tableFk[$i]."`.`".$currentFkObject->getPrimaryKey()."` "; } $tableAlias = (!empty($tableFk)) ? "`".$tableFk[0]."`." : ""; if (!empty($lang)) $sql .= "WHERE ".$tableAlias."`pk_lang` = ".$this->_db->quote($lang)." "; $sql .= "GROUP BY ".$tableAlias."`".$pkFk."` LIMIT 0,".$nb; $results = $this->_db->select($sql); $nbResults = count($results); if ($nbResults < $nb && count($tableFk) > 0) { $pks = array(); for($i=0 ; $i<$count=count($results) ; $i++) $pks[] = $results[$i]->{$pkFk}; $table = array_shift($tableFk); $sql = "SELECT 0 AS total, ".implode(',',$columnsToSelect)." FROM `".$table."` "; for($i=0 ; $i<$count=count($tableFk) ; $i++) { if(!$this->_db->tableExists($tableFk[$i])) continue; $currentFkTable = $tableFk[$i]; $sourceFkTable = $table; $columnFk = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($currentDb."_".$sourceFkTable)."' and @tablePk='".strtolower($currentDb)."_".SLS_String::tableToClass($currentFkTable)."']/@columnFk"); $this->_generic->useModel(SLS_String::tableToClass($currentFkTable), $currentDb); $currentFkClass = ucfirst(strtolower($currentDb))."_".SLS_String::tableToClass($currentFkTable); $currentFkObject = new $currentFkClass(); $sql .= "LEFT JOIN `".$tableFk[$i]."` ON `".$sourceFkTable."`.`".$columnFk."` = `".$tableFk[$i]."`.`".$currentFkObject->getPrimaryKey()."` "; } $tableAlias = (!empty($table)) ? "`".$table."`." : ""; $sql .= "WHERE 1=1 "; if (!empty($lang)) $sql .= "AND ".$tableAlias."`pk_lang` = ".$this->_db->quote($lang)." "; if (!empty($pks)) $sql .= "AND ".$tableAlias."`".$pkFk."` NOT IN (".implode(',',$pks).") "; $sql .= "GROUP BY ".$tableAlias."`".$pkFk."` LIMIT 0,".($nb - $nbResults); $results = array_merge($results,$this->_db->select($sql)); } } else { $sql = "SELECT * FROM "; for($i=0 ; $i<$count=count($tableFk) ; $i++) { if(!$this->_db->tableExists($tableFk[$i])) continue; if ($i> 0) { $currentFkTable = $tableFk[$i]; $sourceFkTable = $tableFk[0]; $columnFk = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($currentDb."_".$sourceFkTable)."' and @tablePk='".strtolower($currentDb)."_".SLS_String::tableToClass($currentFkTable)."']/@columnFk"); $sql .= (!empty($columnFk)) ? "LEFT JOIN " : "NATURAL JOIN "; } $sql .= "`".$tableFk[$i]."` "; if ($i > 0 && !empty($columnFk)) { $this->_generic->useModel(SLS_String::tableToClass($currentFkTable), $currentDb); $currentFkClass = ucfirst(strtolower($currentDb))."_".SLS_String::tableToClass($currentFkTable); $currentFkObject = new $currentFkClass(); $sql .= "ON `".$tableFk[0]."`.`".$columnFk."` = `".$tableFk[$i]."`.`".$currentFkObject->getPrimaryKey()."` "; } } $tableAlias = (!empty($tableFk)) ? "`".$tableFk[0]."`." : ""; $sql .= "WHERE ".$clause." LIKE LOWER(".$this->_db->quote("%".$value."%").") "; if (!empty($lang)) $sql .= "AND ".$tableAlias."`pk_lang` = ".$this->_db->quote($lang)." "; $sql .= "GROUP BY ".$tableAlias."`".$pkFk."` ORDER BY ".$clause." ASC LIMIT 0,".$nb; $results = $this->_db->select($sql); } } return $results; }
public function action() { $user = $this->hasAuthorative(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); // Get the table name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); if ($sql->tableExists($table)) { if ($this->_http->getParam("reload") == "true") { $columnWanted = $this->_http->getParam("column"); $typeWanted = $this->_http->getParam("type"); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']"); // If an entry already exists in the XML, delete this record if (!empty($result)) { $xmlTmp = $xmlType->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']"); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlTmp); $xmlType->refresh(); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); } // If file type, check possible thumbs if ($typeWanted == "file") { $typeFile = $this->_http->getParam("file"); $file_thumb = $this->_http->getParam("file_thumb"); $multilang = $this->_http->getParam("multilanguage"); $thumbs = array(); $typeWanted = $typeWanted."_".$typeFile; if ($typeFile == "img" && !empty($file_thumb)) { for($i=0 ; $i<10 ; $i++) { $width = $this->_http->getParam("width".$i); $height = $this->_http->getParam("height".$i); $suffix = $this->_http->getParam("suffix".$i); if (!empty($suffix) && (!empty($width) || !empty($height))) array_push($thumbs,array('width' => $width, 'height' => $height, 'suffix' => $suffix)); } } $rules = "*|*|*"; if ($typeFile == "img") { $settings = $this->_http->getParam("imgSettings"); $ratio = str_replace(",",".",$settings["ratio"]); $minWidth = str_replace(",",".",$settings["min-width"]); $minHeight = str_replace(",",".",$settings["min-height"]); $ratio = (!is_numeric($ratio) || (is_numeric($ratio) && $ratio <= 0)) ? "*" : round($ratio,2); $minWidth = (!is_numeric($minWidth) || (is_numeric($minWidth) && $minWidth < 0)) ? "*" : round($minWidth,0); $minHeight = (!is_numeric($minHeight) || (is_numeric($minHeight) && $minHeight < 0)) ? "*" : round($minHeight,0); $rules = $ratio."|".$minWidth."|".$minHeight; } // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$rules.'" thumbs="'.str_replace('"','||#||',serialize($thumbs)).'" multilanguage="'.$multilang.'" type="'.$typeWanted.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "ip") { $type = $this->_http->getParam("ip"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "complexity") { $complexity = $this->_http->getParam("complexity"); $complexityMin = $this->_http->getParam("complexity_min"); $complexity = (empty($complexity)) ? array() : $complexity; if (!empty($complexityMin) && is_numeric($complexityMin) && $complexityMin >= 0) $complexity[] = "min".$complexityMin; $complexity = implode("|",$complexity); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$complexity.'" type="complexity" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "num") { $type = $this->_http->getParam("num"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } // Else, it's email, url, color, uniqid, position, address else { // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } // Disable UserBo quick-edit feature on this column if ($typeWanted == "file") { $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']"; $boExists = $xmlBo->getTag($boPath."/@allowEdit"); if (empty($boExists)) $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']"; $boExists = $xmlBo->getTag($boPath."/@allowEdit"); if (!empty($boExists)) { $xmlBo->setTagAttributes($boPath,array("allowEdit" => "false")); $xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML()); $xmlBo->refresh(); } } // Update model $this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name")))); } // Get generic object $this->_generic->useModel($table,$db,"user"); $object = new $class(); // Get object's infos $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $columnsP = $object->getParams(); $pk = $object->getPrimaryKey(); $multilanguage = $object->isMultilanguage(); $xml->startTag("model"); $xml->addFullTag("table",$table,true); $xml->addFullTag("db",$db,true); $xml->addFullTag("class",$class,true); $xml->addFullTag("pk",$pk,true); $xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true); $xml->startTag("columns"); foreach($columnsP as $column => $value) { $res = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$column."']/@tablePk"); if ($object->getPrimaryKey() != $column && $column != "pk_lang" && empty($res)) $xml->addFullTag("column",$column,true); } $xml->endTag("columns"); $xml->endTag("model"); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginImg = array_shift($plugin->getTags("//plugins/plugin[@code='image']")); $xml->addFullTag("plugin_img",empty($pluginImg) ? 'false' : 'true',true); $xml->addFullTag("plugin_url",$this->_generic->getFullPath("SLS_Bo","Plugins"),true); } else { $xml->addFullTag("error","Sorry this table doesn't exist anymore",true); } $this->saveXML($xml); }
public function constructXML() { $this->_boController = $this->_generic->getBo(); if ($this->_generic->getGenericControllerName() == $this->_boController) { @include_once($this->_generic->getPathConfig("actionLangs").$this->_boController."/__".$this->_boController.".".$this->_lang->getLang().".lang.php"); $db = SLS_Sql::getInstance(); $dbsAlias = $db->getDbs(); $comments = array(); foreach($dbsAlias as $dbAlias) { $db->changeDb($dbAlias); $tables = $db->showTables(); for($i=0 ; $i<$count=count($tables) ; $i++) { $table = $tables[$i]->Name; $key = ucfirst(strtolower($dbAlias))."_".SLS_String::tableToClass($table); if (!array_key_exists($key,$comments)) { $comment = $tables[$i]->Comment; if (SLS_String::startsWith($comment,"sls:lang:")) { $globalKey = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:")); $comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) ? $table : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey]; } $comments[$key] = (empty($comment)) ? $table : $comment; } } } $db->changeDb($db->connectToDefaultDb()); # Nav if (SLS_BoRights::isLogged()) { $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $entries = $xmlBo->getTagsAttributes("//sls_configs/entry",array("type","name")); $this->_xmlToolBox->startTag("nav"); if (!empty($entries)) { # BOs $this->_xmlToolBox->startTag("section"); $this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_SITE'],"true"); $this->_xmlToolBox->addFullTag("href","#","true"); $this->_xmlToolBox->startTag("categories"); for($i=0 ; $i<$count=count($entries) ; $i++) { $position = ($i+1); $type = $entries[$i]["attributes"][0]["value"]; $name = $entries[$i]["attributes"][1]["value"]; if ($type == "category") { $childs = $xmlBo->getTagsAttributes("//sls_configs/entry[".$position."]/entry",array("type","name")); $comment = $name; if (SLS_String::startsWith($comment,"sls:lang:")) { $globalKey = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:")); $comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) ? $name : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey]; } $this->_xmlToolBox->startTag("category",array("type"=>"category")); $this->_xmlToolBox->addFullTag("title",$comment,"true"); $this->_xmlToolBox->addFullTag("href","#","true"); if (!empty($childs)) { $this->_xmlToolBox->startTag("items"); for($j=0 ; $j<$count=count($childs) ; $j++) { $type = $childs[$j]["attributes"][0]["value"]; $name = $childs[$j]["attributes"][1]["value"]; $dbAlias = ucfirst(strtolower(SLS_String::substrBeforeFirstDelimiter($name,"_"))); $table = SLS_String::substrAfterFirstDelimiter($name,"_"); $right = SLS_BoRights::isAuthorized("read",$dbAlias."_".SLS_String::tableToClass($table)); if ($right == 1) { $comment = $comments[$dbAlias."_".SLS_String::tableToClass($table)]; if (SLS_String::startsWith($comment,"sls:lang:")) { $key = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:")); $comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) ? $table : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key]; } $actionIdsModel = array($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Add".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Modify".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Clone".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Delete".$dbAlias."_".SLS_String::tableToClass($table))); if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)))) { $this->_xmlToolBox->startTag("item"); $this->_xmlToolBox->addFullTag("db",$dbAlias,true); $this->_xmlToolBox->addFullTag("model",SLS_String::tableToClass($table),true); $this->_xmlToolBox->addFullTag("title",$comment,"true"); $this->_xmlToolBox->addFullTag("like",(SLS_BoRights::isLike("read",$dbAlias."_".SLS_String::tableToClass($table))) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("selected",(in_array($this->_generic->getActionId(),$actionIdsModel)) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)),"true"); $this->_xmlToolBox->endTag("item"); } } } $this->_xmlToolBox->endTag("items"); } $this->_xmlToolBox->endTag("category"); } else { $dbAlias = ucfirst(strtolower(SLS_String::substrBeforeFirstDelimiter($name,"_"))); $table = SLS_String::substrAfterFirstDelimiter($name,"_"); $right = SLS_BoRights::isAuthorized("read",$dbAlias."_".SLS_String::tableToClass($table)); if ($right == 1) { $comment = $comments[$dbAlias."_".SLS_String::tableToClass($table)]; if (SLS_String::startsWith($comment,"sls:lang:")) { $key = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:")); $comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) ? $table : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key]; } $actionIdsModel = array($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Add".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Modify".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Clone".$dbAlias."_".SLS_String::tableToClass($table)), $this->_generic->getActionId($this->_boController,"Delete".$dbAlias."_".SLS_String::tableToClass($table))); if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)))) { $this->_xmlToolBox->startTag("category",array("type"=>"table")); $this->_xmlToolBox->addFullTag("db",$dbAlias,true); $this->_xmlToolBox->addFullTag("model",SLS_String::tableToClass($table),true); $this->_xmlToolBox->addFullTag("title",$comment,"true"); $this->_xmlToolBox->addFullTag("like",(SLS_BoRights::isLike("read",$dbAlias."_".SLS_String::tableToClass($table))) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("selected",(in_array($this->_generic->getActionId(),$actionIdsModel)) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)),"true"); $this->_xmlToolBox->endTag("category"); } } } } $this->_xmlToolBox->endTag("categories"); $this->_xmlToolBox->endTag("section"); # /BOs } # i18n if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "Boi18n")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "Boi18n"))) { $file = $this->_http->getParam("File"); $this->_xmlToolBox->startTag("section"); $this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_I18N'],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n")) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href","#","true"); $this->_xmlToolBox->startTag("categories"); $controllers = $this->_generic->getControllersXML()->getTags("//controllers/controller[@side='user']/@name"); sort($controllers,SORT_STRING); for($i=0 ; $i<$count=count($controllers) ; $i++) { $actions = $this->_generic->getControllersXML()->getTags("//controllers/controller[@name='".$controllers[$i]."' and @side='user']/scontrollers/scontroller/@name"); sort($actions,SORT_STRING); $this->_xmlToolBox->startTag("category",array("type"=>"category")); $this->_xmlToolBox->addFullTag("title",$controllers[$i],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && SLS_String::startsWith($file, "Actions|".$controllers[$i]."|")) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href","#","true"); $this->_xmlToolBox->startTag("items"); if (file_exists($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/__".$controllers[$i].".".$this->_lang->getLang().".lang.php") && ($translations = file_get_contents($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/__".$controllers[$i].".".$this->_lang->getLang().".lang.php")) && SLS_String::contains(str_replace("","",$translations),'*/'."\n".'$GLOBALS') || (!SLS_String::contains($translations,"/**") && SLS_String::contains($translations,'$GLOBALS'))) { $this->_xmlToolBox->startTag("item"); $this->_xmlToolBox->addFullTag("title","__".$controllers[$i],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && $file == "Actions|".$controllers[$i]."|__".$controllers[$i]) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController, "Boi18n", array("File" => "Actions|".$controllers[$i]."|__".$controllers[$i])),"true"); $this->_xmlToolBox->endTag("item"); } for($j=0 ; $j<$countJ=count($actions) ; $j++) { if (file_exists($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/".$actions[$j].".".$this->_lang->getLang().".lang.php") && ($translations = file_get_contents($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/".$actions[$j].".".$this->_lang->getLang().".lang.php")) && SLS_String::contains(str_replace("","",$translations),'*/'."\n".'$GLOBALS') || (!SLS_String::contains($translations,"/**") && SLS_String::contains($translations,'$GLOBALS'))) { $this->_xmlToolBox->startTag("item"); $this->_xmlToolBox->addFullTag("title",$actions[$j],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && $file == "Actions|".$controllers[$i]."|".$actions[$j]) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController, "Boi18n", array("File" => "Actions|".$controllers[$i]."|".$actions[$j])),"true"); $this->_xmlToolBox->endTag("item"); } } $this->_xmlToolBox->endTag("items"); $this->_xmlToolBox->endTag("category"); } if (file_exists($this->_generic->getPathConfig("genericLangs")."site.".$this->_lang->getLang().".lang.php") && ($translations = file_get_contents($this->_generic->getPathConfig("genericLangs")."site.".$this->_lang->getLang().".lang.php")) && SLS_String::contains(str_replace("","",$translations),'*/'."\n".'$GLOBALS') || (!SLS_String::contains($translations,"/**") && SLS_String::contains($translations,'$GLOBALS'))) { $this->_xmlToolBox->startTag("category",array("type"=>"table")); $this->_xmlToolBox->addFullTag("title","__".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_I18N_SITE'],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && $file == "Generics|site") ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController, "Boi18n", array("File" => "Generics|site")),"true"); $this->_xmlToolBox->endTag("category"); } $this->_xmlToolBox->endTag("categories"); $this->_xmlToolBox->endTag("section"); } # /i18n # CkFinder if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "BoFileUpload")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "BoFileUpload"))) { $this->_xmlToolBox->startTag("section"); $this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_FILE_MANAGER'],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController,"BoFileUpload")) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"BoFileUpload"),"true"); $this->_xmlToolBox->endTag("section"); } # /CkFinder # ProjectSettings if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "BoProjectSettings")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "BoProjectSettings"))) { $this->_xmlToolBox->startTag("section"); $this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_PROJECT_SETTINGS'],"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController,"BoProjectSettings")) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"BoProjectSettings"),"true"); $this->_xmlToolBox->endTag("section"); } # /ProjectSettings # Users if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "BoUserList")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "BoUserList"))) { $actionsUser = array($this->_generic->getActionId($this->_boController, "BoUserList"), $this->_generic->getActionId($this->_boController, "BoUserAdd"), $this->_generic->getActionId($this->_boController, "BoUserModify"), $this->_generic->getActionId($this->_boController, "BoUserDelete"), $this->_generic->getActionId($this->_boController, "BoUserStatus")); $this->_xmlToolBox->startTag("section"); $this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_USERS'],"true"); $this->_xmlToolBox->addFullTag("selected",(in_array($this->_generic->getActionId(),$actionsUser)) ? "true" : "false","true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"BoUserList"),"true"); $this->_xmlToolBox->endTag("section"); } # /Users # Developer actions $boActions = $this->_generic->getControllersXML()->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller/@name"); for($i=0 ; $i<$count=count($boActions) ; $i++) { // If dev action & admin authorized if (!SLS_String::startsWith($boActions[$i],"Bo") && // Sls generated actions !SLS_String::startsWith($boActions[$i],"List") && // User action ListDb_Model !SLS_String::startsWith($boActions[$i],"Add") && // User action AddDb_Model !SLS_String::startsWith($boActions[$i],"Modify") && // User action ModifyDb_Model !SLS_String::startsWith($boActions[$i],"Delete") && // User action DeleteDb_Model !SLS_String::startsWith($boActions[$i],"Clone") && // User action CloneDb_Model !SLS_String::startsWith($boActions[$i],"Email") && // User action EmailDb_Model SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, $boActions[$i]))) { $this->_xmlToolBox->startTag("section"); $this->_xmlToolBox->addFullTag("title",$this->_generic->getControllersXML()->getTag("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='".$boActions[$i]."']/scontrollerLangs/scontrollerLang[@lang='".$this->_lang->getLang()."']"),"true"); $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, $boActions[$i])) ? "true" : "false", "true"); $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,$boActions[$i]),"true"); $this->_xmlToolBox->endTag("section"); } } # /Developer actions $this->_xmlToolBox->endTag("nav"); } # /Nav # Admin $xmlRight = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml")); $adminName = $this->_session->getParam("SLS_BO_USER_NAME"); $adminFirstname = $this->_session->getParam("SLS_BO_USER_FIRSTNAME"); if (!empty($adminName) && !empty($adminFirstname)) $imgPath = $this->_generic->getPathConfig("files")."__Uploads/images/bo/".SLS_String::stringToUrl($adminName."_".$adminFirstname,"_").".jpg"; else $imgPath = $this->_generic->getPathConfig("coreImg")."BO-2014/Pictos/default_dev_account_small.jpg"; $this->_xmlToolBox->startTag("admin"); $this->_xmlToolBox->addFullTag("img",(file_exists($imgPath) && !is_dir($imgPath)) ? $this->_generic->getSiteConfig("protocol")."://".$this->_generic->getSiteConfig("domainName")."/".$imgPath : $this->_generic->getSiteConfig("protocol")."://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files")."__Uploads/images/bo/default_account.jpg",true); $this->_xmlToolBox->addFullTag("login",$this->_session->getParam("SLS_BO_USER"),true); $this->_xmlToolBox->addFullTag("name",ucwords(strtolower((!empty($adminName)) ? $adminName : "Developer")),true); $this->_xmlToolBox->addFullTag("firstname",((!empty($adminFirstname)) ? ucwords(strtolower($adminFirstname)) : "SillySmart"),true); $this->_xmlToolBox->addFullTag("type",SLS_BoRights::getAdminType(),true); $nodeExists = $xmlRight->getTag("//sls_configs/entry[@login='******']/@login"); if (!empty($nodeExists)) { $settings = array_combine($xmlRight->getTags("//sls_configs/entry[@login='******']/settings/setting/@key"),$xmlRight->getTags("//sls_configs/entry[@login='******']/settings/setting")); $this->_xmlToolBox->startTag("settings"); foreach($settings as $key => $value) $this->_xmlToolBox->addFullTag("setting",$value,true,array("key"=>$key)); $this->_xmlToolBox->endTag("settings"); } $xmlBoColors = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo_colors.xml")); $boColors = $xmlBoColors->getTagsAttributes("//sls_configs/template",array("name","hexa")); $this->_xmlToolBox->startTag("colors"); for($i=0 ; $i<$count=count($boColors) ; $i++) $this->_xmlToolBox->addFullTag("color",$boColors[$i]["attributes"][0]["value"],true,array("hexa" => $boColors[$i]["attributes"][1]["value"])); $this->_xmlToolBox->endTag("colors"); $this->_xmlToolBox->endTag("admin"); # /Admin # URLs $this->_xmlToolBox->startTag("various"); $this->_xmlToolBox->addFullTag("dashboard",$this->_generic->getFullPath($this->_boController,"BoDashBoard"),true,array("selected" => ($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController,"BoDashBoard")) ? "true" : "false")); $this->_xmlToolBox->addFullTag("export",$this->_generic->getFullPath($this->_boController,"BoExport"),true); $this->_xmlToolBox->addFullTag("ac",$this->_generic->getFullPath($this->_boController,"BoFkAc"),true); $this->_xmlToolBox->addFullTag("like",$this->_generic->getFullPath($this->_boController,"BoLike"),true); $this->_xmlToolBox->addFullTag("setting",$this->_generic->getFullPath($this->_boController,"BoSetting"),true); $this->_xmlToolBox->addFullTag("unique",$this->_generic->getFullPath($this->_boController,"BoUnique"),true); $this->_xmlToolBox->addFullTag("upload",$this->_generic->getFullPath($this->_boController,"BoUpload"),true); $this->_xmlToolBox->addFullTag("upload_progress",$this->_generic->getFullPath($this->_boController,"BoUploadProgress"),true); $this->_xmlToolBox->addFullTag("delete_file",$this->_generic->getFullPath($this->_boController,"BoDeleteFile"),true); $this->_xmlToolBox->addFullTag("login",$this->_generic->getFullPath($this->_boController,"BoLogin"),true); $this->_xmlToolBox->addFullTag("logout",(SLS_BoRights::getAdminType() == "developer") ? $this->_generic->getFullPath("SLS_Bo","Logout",array("Redirect" => $this->_generic->getActionId($this->_boController,"BoLogin"), "Lang" => $this->_lang->getLang()),true,"en") : $this->_generic->getFullPath($this->_boController,"BoLogout"),true); $this->_xmlToolBox->addFullTag("forgotten_pwd",$this->_generic->getFullPath($this->_boController,"BoForgottenPwd"),true); $this->_xmlToolBox->addFullTag("renew_pwd",$this->_generic->getFullPath($this->_boController,"BoRenewPwd",array("Login"=>$this->_session->getParam("SLS_BO_USER"))),true); $this->_xmlToolBox->addFullTag("is_logged",$this->_generic->getFullPath($this->_boController,"BoIsLogged"),true); $this->_xmlToolBox->addFullTag("switch_lang",$this->_generic->getFullPath($this->_boController,"BoSwitchLang",array("Lang"=>""),false),true); $this->_xmlToolBox->addFullTag("user_add",$this->_generic->getFullPath($this->_boController,"BoUserAdd"),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserAdd"))) ? "true" : "false")); $this->_xmlToolBox->addFullTag("user_modify",$this->_generic->getFullPath($this->_boController,"BoUserModify",array("id" => ''),false),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserModify"))) ? "true" : "false")); $this->_xmlToolBox->addFullTag("user_delete",$this->_generic->getFullPath($this->_boController,"BoUserDelete",array("id" => ''),false),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserDelete"))) ? "true" : "false")); $this->_xmlToolBox->addFullTag("user_status",$this->_generic->getFullPath($this->_boController,"BoUserStatus",array("id" => ''),false),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserStatus"))) ? "true" : "false")); $this->_xmlToolBox->endTag("various"); # /URLs # Server $apcUpload = (in_array(ini_get("apc.rfc1867"),array(1,"1","On","on",true,"true"))) ? "true" : "false"; $apcUploadKey = ini_get("apc.rfc1867_name"); $uploadMaxFilesize = ini_get("upload_max_filesize"); $unite = strtolower(substr(trim($uploadMaxFilesize), -1)); switch ($unite) { case 'k': $uploadMaxFilesize = (int)$uploadMaxFilesize * 1024; break; case 'm': $uploadMaxFilesize = (int)$uploadMaxFilesize * 1024 * 1024; break; case 'g': $uploadMaxFilesize = (int)$uploadMaxFilesize * 1024 * 1024 * 1024; break; default: $uploadMaxFilesize = $uploadMaxFilesize; break; } $this->_xmlToolBox->startTag("server"); $this->_xmlToolBox->addFullTag("apc_upload",$apcUpload,true); $this->_xmlToolBox->addFullTag("apc_upload_key",$apcUploadKey,true); $this->_xmlToolBox->addFullTag("upload_max_size",$uploadMaxFilesize,true); $this->_xmlToolBox->endTag("server"); # /Server } }
public function action() { set_time_limit(0); $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $controllersXML = $this->_generic->getControllersXML(); $controller = $controllersXML->getTag("//controllers/controller[@isBo='true']/@name"); $tokenSecret = sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3)); $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml")); // Check if bo controller already exist if (empty($controller)) { $xml->startTag("errors"); $xml->addFullTag("error","Back-office controller could not be found. Please follow the following link to create it.",true); $xml->endTag("errors"); } // Else, let's choose the models else { // If reload if ($this->_http->getParam("reload") == "true") { $modelsWanted = $this->_http->getParam("models"); $langs = $this->_lang->getSiteLangs(); if (is_array($modelsWanted)) { // Foreach models choose, generate files foreach($modelsWanted as $model) { $db = Sls_String::substrBeforeFirstDelimiter($model,"."); $table = Sls_String::substrAfterFirstDelimiter($model,"."); # Node into bo.xml $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($db."_".$table)."']"; $boExists = $xmlBo->getTag($boPath."/@type"); if (empty($boExists)) $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($db."_".$table)."']"; $boExists = $xmlBo->getTag($boPath); if (empty($boExists)) { $this->_generic->useModel(SLS_String::tableToClass($table),ucfirst(strtolower($db)),"user"); $class = ucfirst(strtolower($db))."_".SLS_String::tableToClass($table); $object = new $class(); $xmlNode = ' <entry type="table" name="'.strtolower($db."_".$table).'" multilanguage="'.(($object->isMultilanguage()) ? "true" : "false").'">'."\n"; $xmlNode .= ' <columns>'."\n"; foreach($object->getColumns() as $column) { // Avoid pk $isPk = ($column == $object->getPrimaryKey() || $column == 'pk_lang') ? true : false; // Avoid fk $fkExist = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($db."_".$table)."' and @columnFk='".$column."']/@tablePk"); $isFk = (!empty($fkExist)) ? true : false; // Avoid quick edit on type file $fileExist = $xmlType->getTag("//sls_configs/entry[@table='".strtolower($db."_".$table)."' and @column='".$column."' and (@type='file_all' or @type='file_img')]/@column"); $isFile = (!empty($fileExist)) ? true : false; $xmlNode .= ' <column table="'.strtolower($db."_".$table).'" name="'.$column.'" multilanguage="'.(($object->isMultilanguage() && !$isPk) ? "true" : "false").'" displayFilter="true" displayList="'.(($isFk) ? "false" : "true").'" allowEdit="'.(($isPk || $isFk || $isFile) ? "false" : "true").'" allowHtml="false" />'."\n"; } $xmlNode .= ' </columns>'."\n"; $xmlNode .= ' </entry>'."\n"; $xmlBo->appendXMLNode("//sls_configs",$xmlNode); $xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML()); $xmlBo->refresh(); } # /Node into bo.xml # BoActions $boActions = array("List","Add","Modify","Clone","Delete"); foreach($boActions as $boAction) { // Generate Action $action = ucfirst(strtolower($boAction)).ucfirst(strtolower($db))."_".SLS_String::tableToClass($table); $params = array(0 => array("key" => "reload", "value" => "true"), 1 => array("key" => "Controller", "value" => $controller), 2 => array("key" => "actionName", "value" => $action), 3 => array("key" => "token", "value" => $tokenSecret), 4 => array("key" => "template", "value" => "bo"), 5 => array("key" => "dynamic", "value" => "on"), 6 => array("key" => "indexes", "value" => "noindex,nofollow") ); foreach($langs as $lang) { $tmpParam = array("key" => $lang."-action", "value" => $action."_".$lang); $tmpTitle = array("key" => $lang."-title", "value" => $action); array_push($params,$tmpParam); array_push($params,$tmpTitle); } file_get_contents($this->_generic->getFullPath("SLS_Bo", "AddAction", $params, true)); // Erase Action if (file_exists($this->_generic->getPathConfig("installDeployement")."Controllers/Actions/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.controller.php")) { $source = str_replace(array("{{USER_BO}}","{{DB}}","{{TABLE}}"),array($controller,ucfirst(strtolower($db)),SLS_String::tableToClass($table)),file_get_contents($this->_generic->getPathConfig("installDeployement")."Controllers/Actions/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.controller.php")); file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/".$action.".controller.php",$source); } // Erase View Head if (file_exists($this->_generic->getPathConfig("installDeployement")."Views/Headers/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl")) { $source = str_replace(array("{{USER_BO}}","{{DB}}","{{TABLE}}"),array($controller,ucfirst(strtolower($db)),SLS_String::tableToClass($table)),file_get_contents($this->_generic->getPathConfig("installDeployement")."Views/Headers/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl")); file_put_contents($this->_generic->getPathConfig("viewsHeaders").$controller."/".$action.".xsl",$source); } // Erase View Body if (file_exists($this->_generic->getPathConfig("installDeployement")."Views/Body/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl")) { $source = str_replace(array("{{USER_BO}}","{{DB}}","{{TABLE}}"),array($controller,ucfirst(strtolower($db)),SLS_String::tableToClass($table)),file_get_contents($this->_generic->getPathConfig("installDeployement")."Views/Body/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl")); file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/".$action.".xsl",$source); } } # /BoActions } $this->_generic->forward("SLS_Bo","ManageRights"); } } $sql = SLS_Sql::getInstance(); $models = $this->getAllModels(); $dbs = $sql->getDbs(); sort($dbs,SORT_REGULAR); $xml->startTag("dbs"); foreach($dbs as $db) { sort($models,SORT_REGULAR); $xml->startTag("db"); $xml->addFullTag("name",$db,true); $xml->startTag("models"); for($i=0 ; $i<$count=count($models) ; $i++) { if (SLS_String::startsWith($models[$i],$db)) { $xml->startTag("model"); $xml->addFullTag("name",SLS_String::substrAfterFirstDelimiter($models[$i],"."),true); $xml->addFullTag("existed",($this->boActionExist(SLS_String::substrAfterFirstDelimiter($models[$i],"."),SLS_String::substrBeforeFirstDelimiter($models[$i],"."))) ? "true" : "false",true); $xml->endTag("model"); } } $xml->endTag("models"); $xml->endTag("db"); } $xml->endTag("dbs"); } $xml->addFullTag("url_add_controller",$this->_generic->getFullPath("SLS_Bo","AddController",array(0=>array("key"=>"isBo","value"=>"true"))),true); $this->saveXML($xml); }