public function getEnvironments() { $environments = array(); $filesToCheck = array("site","db","project","mail"); if ($handle = opendir($this->_generic->getPathConfig("configSecure"))) { while (false !== ($entry = readdir($handle))) { foreach($filesToCheck as $file) { if (SLS_String::startsWith($entry,$file."_") && SLS_String::endsWith($entry,".xml")) { $environment = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($entry,$file."_"),".xml"); if (!in_array($environment,$environments)) $environments[] = $environment; } } } } return $environments; }
/** * Bind dependencies between mysql table and static|component|controller|action into controller_bind.json. * This file is used to know if we need to flush cached files when we insert/update/delete datas into tables. * * @access private * @param string $query the sql select query you have to analyze * @since 1.0.9 */ private function logDependencies($query) { // If cache enabled, don't log dependencies if ($this->_generic->isCache()) return true; // Objects $log = false; $query = strtolower($query); $tables = array(); // Force explain on the query to grep tables $explains = $this->select("EXPLAIN ".$query); for($i=0 ; $i<$count=count($explains) ; $i++) $tables[] = $explains[$i]->table; // Check all tables > real table name or f****n alias ? for($i=0 ; $i<$count=count($tables) ; $i++) { if (!in_array($tables[$i],$this->_tables)) { if (SLS_String::endsWith($query," ".$tables[$i])) $tables[$i] = str_replace('`','',SLS_String::substrAfterLastDelimiter(trim(SLS_String::substrBeforeLastDelimiter($query," ".$tables[$i]))," ")); else $tables[$i] = str_replace('`','',SLS_String::substrAfterLastDelimiter(trim(SLS_String::substrBeforeFirstDelimiter($query," ".$tables[$i]." "))," ")); if (!in_array($tables[$i],$this->_tables)) unset($tables[$i]); } } if (!empty($tables)) { $traces = debug_backtrace(); for($i=0 ; $i<$count=count($traces) ; $i++) { $file = $traces[$i]["file"]; if (SLS_String::contains($file,$this->_generic->getPathConfig("staticsControllers"))) { $log = true; $name = strtolower(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($file,$this->_generic->getPathConfig("staticsControllers")),".controller.php")); foreach($tables as $table) $this->_cache->addBind($table,"statics",$name); break; } if (SLS_String::contains($file,$this->_generic->getPathConfig("componentsControllers"))) { $log = true; $name = strtolower(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($file,$this->_generic->getPathConfig("componentsControllers")),".controller.php")); foreach($tables as $table) $this->_cache->addBind($table,"components",$name); break; } if (SLS_String::contains($file,$this->_generic->getPathConfig("actionsControllers"))) { $log = true; if (SLS_String::contains($file,"/__") && SLS_String::contains($file,".protected.php")) { $name = strtolower(SLS_String::substrAfterFirstDelimiter($this->_generic->getControllerId(),"_")); foreach($tables as $table) $this->_cache->addBind($table,"controllers",$name); break; } else { $name = strtolower(SLS_String::substrAfterFirstDelimiter($this->_generic->getActionId(),"_")); foreach($tables as $table) $this->_cache->addBind($table,"actions",$name); break; } } } if ($log) $this->_cache->saveBind(); } }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $siteXML = $this->_generic->getSiteXML(); $langs = $this->_lang->getSiteLangs(); $errors = array(); if ($this->_http->getParam("reload") == "true") { $alias = SLS_String::trimSlashesFromString($this->_http->getParam("alias")); $domain = SLS_String::trimSlashesFromString($this->_http->getParam("domain")); $lang = SLS_String::trimSlashesFromString($this->_http->getParam("lang")); $cdn = $this->_http->getParam("cdn"); if ($cdn != 'true') $cdn = 'false'; if (SLS_String::endsWith(trim($domain),"/")) $domain = SLS_String::substrBeforeLastDelimiter(trim($domain),"/"); $result = $siteXML->getTag("//configs/domainName/domain[@alias='".$alias."']"); if (empty($alias)) array_push($errors,"You must choose an alias for your domain name."); else if (!empty($result)) array_push($errors,"This alias is already used by another domain, please choose another."); if (empty($domain)) array_push($errors,"You must fill your domain name."); else if (!SLS_String::isValidUrl("http://".$domain)) array_push($errors,"This domain is not a valid url."); if (empty($errors)) { $str_xml = '<domain alias="'.$alias.'" js="true" isSecure="false" cdn="'.$cdn.'" lang="'.$lang.'">'. '<![CDATA['.$domain.']]>'. '</domain>'; $siteXML->appendXMLNode("//configs/domainName",$str_xml); $siteXML->saveXML($this->_generic->getPathConfig("configSecure")."site.xml"); $this->_generic->forward("SLS_Bo","GlobalSettings"); } else { $xml->startTag("domain"); $xml->addFullTag("alias",$alias,true); $xml->addFullTag("domain",$domain,true); $xml->addFullTag("cdn",$cdn,true); $xml->addFullTag("lang",$lang,true); $xml->endTag("domain"); } } $langsBinded = $siteXML->getTags("//configs/domainName/domain/@lang"); foreach($langs as $lang) if (in_array($lang,$langsBinded)) unset($langs[array_shift(array_keys($langs,$lang))]); $xml->startTag("langs"); foreach($langs as $lang) $xml->addFullTag("lang",$lang,true); $xml->endTag("langs"); $xml->startTag("errors"); foreach($errors as $error) $xml->addFullTag("error",$error,true); $xml->endTag("errors"); $this->saveXML($xml); }
/** * Get the URL of the customer back-office menu * * @access public * @return string the url of the {{USER_BO}}/BoMenu * @since 1.1 */ public function urlBoMenu() { $params = array_merge_recursive($_POST,$_GET); if (SLS_String::endsWith($params['smode'], SLS_Generic::getInstance()->getSiteConfig('defaultExtension'))) $params['smode'] = SLS_String::substrBeforeLastDelimiter($params['smode'], '.'.SLS_Generic::getInstance()->getSiteConfig('defaultExtension')); $explode = explode("/", $params['smode']); $params['smode'] = array_shift($explode); $queryString = ""; $params = array_chunk($explode, 2); for($i=0 ; $i<$count=count($params) ; $i++) if (count($params[$i]) == 2) $queryString .= (($i == 0) ? '' : '&').$params[$i][0].'='.(($params[$i][1] != "|sls_empty|") ? $params[$i][1] : ""); $queryString = str_replace(array("=","&"),"/",$queryString); $controllerBo = $this->_generic->getBo(); if (!empty($controllerBo)) { $controllers = $this->_generic->translateActionId($this->_generic->getActionId($controllerBo,"BoMenu")); return $this->_generic->getSiteConfig("protocol")."://".$this->_generic->getSiteConfig("domainName")."/".$controllers["controller"]."/".$controllers["scontroller"]."/".$queryString.".".$this->_generic->getSiteConfig("defaultExtension"); } else return ""; }
/** * Set the title of the current page * * @access protected * @param string $title the title of the current page * @param bool $incremental true to add a new one, false to overwrite * @see SLS_GenericController::setMetaRobots * @see SLS_GenericController::setMetaAuthor * @see SLS_GenericController::setMetaCopyright * @see SLS_GenericController::setMetaKeywords * @see SLS_GenericController::setMetaDescription * @since 1.0 */ protected function setMetaTitle($title="", $incremental=false) { if (empty($title)) { // Try to recover title from metas.xml $currentTitle = array_shift($this->_generic->getCoreXML('metas')->getTags("//sls_configs/action[@id='".$this->_generic->getActionId()."']/title[@lang='".$this->_generic->getObjectLang()->getLang()."']")); if (!empty($currentTitle)) $this->_pageTitle = $currentTitle." | ".$this->_generic->getSiteConfig("projectName"); // Else, recover title from Controller & Action names else { if ($this->_generic->getSiteConfig('isInstall') == 1) { $currentTitle = array_shift($this->_generic->getControllersXML()->getTags("//controllers/controller[@name='".$this->_generic->getGenericControllerName()."']/scontrollers/scontroller[@name='".$this->_generic->getGenericScontrollerName()."']/scontrollerLangs/scontrollerLang[@lang='".$this->_generic->getObjectLang()->getLang()."']/@title")); if (!empty($currentTitle)) $this->_pageTitle = $currentTitle." | ".$this->_generic->getSiteConfig("projectName"); } else { $controllers = $this->_generic->getTranslatedController($this->_generic->getGenericControllerName(), $this->_generic->getGenericScontrollerName()); $this->_pageTitle = $controllers['controller']." - ".$controllers['scontroller']." | ".$this->_generic->getSiteConfig("projectName"); } } } else { if ($incremental === false) { $this->_pageTitle = $title; if (!SLS_String::endsWith($this->_pageTitle," | ".$this->_generic->getSiteConfig("projectName"))) $this->_pageTitle .= " | ".$this->_generic->getSiteConfig("projectName"); } else { if (SLS_String::endsWith($this->_pageTitle," | ".$this->_generic->getSiteConfig("projectName"))) $this->_pageTitle = SLS_String::substrBeforeLastDelimiter($this->_pageTitle," | ".$this->_generic->getSiteConfig("projectName"))." ".$title." | ".$this->_generic->getSiteConfig("projectName"); else { $this->_pageTitle .= " ".$title; if (!SLS_String::endsWith($this->_pageTitle," | ".$this->_generic->getSiteConfig("projectName"))) $this->_pageTitle .= " | ".$this->_generic->getSiteConfig("projectName"); } } } }
/** * Get columns of a given table * * @param string $db the db alias of the table * @param string $table the wanted table you want to extract columns infos * @param string $boPath xPath of the table in bo.xml * @param string $classFather the father model (if children) * @param bool $needPk if you want primary_key * @param bool $needBoSettings if you want bo listing privileges (list|edit|filter) * @return array $columns columns of the table */ public function getTableColumns($db,$table,$boPath="",$classFather="",$needPk=false,$needBoSettings=false) { $infosTable = $this->_db->showColumns($table); $isMultilanguage = false; $uniquesMultilang = array(); $columns = array(); foreach((is_array($infosTable)) ? $infosTable : array($infosTable) as $infoTable) { if ($infoTable->Key == "PRI" && $infoTable->Field == "pk_lang") { $isMultilanguage = true; break; } } // Show create table if ($isMultilanguage) { $create = array_shift($this->_db->select("SHOW CREATE TABLE `".$table."`")); $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 columns if (is_array($infosTable)) { foreach($infosTable as $infoTable) { $pk = "false"; // Switch primary keys if ($infoTable->Key == "PRI") { if (!$needPk) continue; else $pk = "true"; } // Column $column = array("db" => $db, "table" => $table, "name" => $infoTable->Field, "pk" => $pk, "label" => $infoTable->Field, "multilanguage" => ($this->_object->isMultilanguage()) ? "true" : "false", "native_type" => "string", "html_type" => "input_text", "specific_type" => "", "specific_type_extended" => "", "file_uid" => uniqid(), "image_ratio" => "*", "image_thumb" => "", "image_min_width" => "*", "image_min_height" => "*", "html" => "false", "choices" => array(), "values" => (empty($classFather)) ? $this->_langsValues : array(), "errors" => array(), "required" => "true", "unique" => "false", "default" => "", "ac_db" => "", "ac_entity" => "", "ac_fk" => "", "ac_column" => "", "ac_label" => "", "ac_pattern" => "", "ac_multiple" => "", "min_length" => "", "max_length" => "", "filters" => ""); if ($needBoSettings) { $column["list"] = "true"; $column["edit"] = "false"; $column["filter"] = "true"; if (!empty($boPath)) { $columnBoAttributes = array_shift($this->_xmlBo->getTagsAttributes($boPath."/columns/column[@name='".$column["name"]."']",array("displayList","allowEdit","displayFilter"))); if (!empty($columnBoAttributes)) { $columnBoAttributesOptions = array("true","false"); $column["list"] = (in_array($columnBoAttributes["attributes"][0]["value"],$columnBoAttributesOptions)) ? $columnBoAttributes["attributes"][0]["value"] : "true"; $column["edit"] = (in_array($columnBoAttributes["attributes"][1]["value"],$columnBoAttributesOptions)) ? $columnBoAttributes["attributes"][1]["value"] : "false"; $column["filter"] = (in_array($columnBoAttributes["attributes"][2]["value"],$columnBoAttributesOptions)) ? $columnBoAttributes["attributes"][2]["value"] : "true"; } } } // Comment $comment = empty($infoTable->Comment) ? $infoTable->Field : $infoTable->Comment; 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]) ? $infoTable->Field : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key]; } if (!empty($comment)) $column["label"] = $comment; // Native type, possible choices $nativeType = $infoTable->Type; $columnValues = array(); switch($nativeType) { case (false !== $typeMatch = $this->containsRecursive($nativeType,array("int"))): $columnType = "int"; $column["html_type"] = "input_number"; break; case (false !== $typeMatch = $this->containsRecursive($nativeType,array("float","double","decimal","real"))): $columnType = "float"; $column["html_type"] = "input_number"; break; case (false !== $typeMatch = $this->containsRecursive($nativeType,array("year","datetime","timestamp","time","date"))): $columnType = ($typeMatch == "timestamp") ? "datetime" : $typeMatch; $column["html_type"] = "input_".$typeMatch; if ($infoTable->Null == "NO") { switch ($typeMatch) { case "year": $column["default"] = date("Y"); break; case "time": $column["default"] = date("H:i:s"); break; case "date": $column["default"] = date("Y-m-d"); break; default: $column["default"] = date("Y-m-d H:i:s"); break; } } break; case (false !== $typeMatch = $this->containsRecursive($nativeType,array("enum","set"))): $columnType = "string"; $column["html_type"] = ($typeMatch == "enum") ? "input_radio" : "input_checkbox"; $columnValues = explode("','",SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($nativeType, "')"), "('")); break; case (false !== $typeMatch = $this->containsRecursive($nativeType,array("text"))): $columnType = "string"; $column["html_type"] = "input_textarea"; break; default: $columnType = "string"; $column["html_type"] = "input_text"; break; } $column["native_type"] = $columnType; $column["choices"] = $columnValues; // MaxLength if (SLS_String::contains($infoTable->Type,"(") && SLS_String::endsWith(trim($infoTable->Type),")")) { $maxLength = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($infoTable->Type,"("),")"); $column["max_length"] = (is_numeric($maxLength) && $maxLength > 0) ? $maxLength : ""; } // Nullable ? unique ? default value ? $column["required"] = ($infoTable->Null == "NO") ? "true" : "false"; $column["unique"] = ($infoTable->Key == "UNI" || in_array($column["name"],$uniquesMultilang)) ? "true" : "false"; if (empty($column["default"])) $column["default"] = (empty($infoTable->Default)) ? "" : $infoTable->Default; // Allow HTML & i18n if (!empty($boPath)) { $columnBoAttributes = array_shift($this->_xmlBo->getTagsAttributes($boPath."/columns/column[@name='".$column["name"]."']",array("allowHtml","multilanguage"))); if (!empty($columnBoAttributes)) { $allowHtml = $columnBoAttributes["attributes"][0]["value"]; $isMultilang = $columnBoAttributes["attributes"][1]["value"]; $column["html"] = ($allowHtml == "true") ? "true" : "false"; $column["multilanguage"] = ($isMultilang == "true") ? "true" : "false"; } } // Specific type & extended $typeExists = array_shift($this->_xmlType->getTagsAttributes("//sls_configs/entry[@table='".$this->_db_alias."_".$table."' and @column='".$column["name"]."']",array("type","rules","thumbs"))); if (!empty($typeExists)) { $specificType = $typeExists["attributes"][0]["value"]; $specificRules = $typeExists["attributes"][1]["value"]; $specificThumbs = unserialize(str_replace("||#||",'"',$typeExists["attributes"][2]["value"])); $specificTypeExtended = ""; switch($specificType) { case "address": /* Nothing */ break; case "color": /* Nothing */ break; case "email": /* Nothing */ break; case "url": /* Nothing */ break; case "position": $record = array_shift($this->_db->select("SELECT MAX(`".$column["name"]."`) AS max_position FROM `".$table."` ")); $column["default"] = (!empty($record->max_position) && is_numeric($record->max_position) && $record->max_position > 0) ? ($record->max_position+1) : 1; break; case "uniqid": // Generate uid $column["default"] = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),(!empty($column["max_length"])) ? $column["max_length"] : 40); break; case (SLS_String::startsWith($specificType,"num_")): // Get numeric settings $specificTypeExtended = SLS_String::substrAfterFirstDelimiter($specificType,"num_"); $specificType = "numeric"; break; case (SLS_String::startsWith($specificType,"ip_")): // Get IP settings $specificTypeExtended = SLS_String::substrAfterFirstDelimiter($specificType,"ip_"); $specificType = "ip"; $column["default"] = $_SERVER['REMOTE_ADDR']; break; case (SLS_String::startsWith($specificType,"file_")): // Get file settings $specificTypeExtended = SLS_String::substrAfterFirstDelimiter($specificType,"file_"); $specificType = "file"; $column["html_type"] = "input_file"; if ($specificTypeExtended == "img") { if (!empty($specificThumbs)) { usort($specificThumbs,array($this,'sortThumbsMin')); $thumb = array_shift($specificThumbs); if (!empty($thumb["suffix"])) $column["image_thumb"] = $thumb["suffix"]; } $column["image_ratio"] = SLS_String::substrBeforeFirstDelimiter($specificRules,"|"); $column["image_min_width"] = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($specificRules,"|"),"|"); $column["image_min_height"] = SLS_String::substrAfterLastDelimiter($specificRules,"|"); } break; case ($specificType == "complexity" && (!empty($specificRules))): // Get complexity settings & minLength if (SLS_String::contains($specificRules,"min")) { $column["min_length"] = SLS_String::substrAfterFirstDelimiter($specificRules,"min"); $specificRules = SLS_String::substrBeforeFirstDelimiter($specificRules,"min"); if (SLS_String::endsWith($specificRules,"|")) $specificRules = SLS_String::substrBeforeLastDelimiter($specificRules,"|"); } $specificTypeExtended = $specificRules; break; default: $specificType = ""; break; } $column["specific_type"] = $specificType; $column["specific_type_extended"] = $specificTypeExtended; } if (!empty($column["default"]) && SLS_String::startsWith($column["html_type"],"input_file")) $column["default"] = (file_exists($this->_generic->getPathConfig("files").$column["default"])) ? SLS_String::getUrlFile($column["default"]) : ""; // Filters $filters = $this->_xmlFilter->getTags("//sls_configs/entry[@table='".$this->_db_alias."_".$table."' and @column='".$column["name"]."']/@filter"); for($i=0 ; $i<$count=count($filters) ; $i++) { if ($filters[$i] == "hash") $column["html_type"] = "input_password"; else $column["filters"] .= (((!empty($column["filters"])) ? "|" : "").$filters[$i]); } // pk_lang if ($needPk && $isMultilanguage && $infoTable->Field == "pk_lang") { $column["html_type"] = "input_radio"; $column["choices"] = $this->_lang->getSiteLangs(); } // Fk $columnFk = array(); $fkExists = array_shift($this->_xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$this->_db_alias."_".$table."' and @columnFk='".$column["name"]."']",array("tablePk","labelPk"))); if (!empty($fkExists)) { $tableAlias = $this->_db_alias; $tableFk = $table; $tablePk = $fkExists["attributes"][0]["value"]; $labelPk = $fkExists["attributes"][1]["value"]; $this->_generic->useModel(SLS_String::substrAfterFirstDelimiter($tablePk,"_"),$tableAlias,"user"); $classFk = ucfirst($tableAlias)."_".SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")); $objectFk = new $classFk(); $pk = $objectFk->getPrimaryKey(); $str = $labelPk; $labelPkReal = $labelPk; $params = $objectFk->getParams(true,true); foreach($params as $key => $value) { if (is_array($value)) { foreach($value as $key2 => $value2) { if (SLS_String::contains($str,$key2)) { $this->_generic->useModel($key,$tableAlias,"user"); $classFk2 = ucfirst($tableAlias)."_".SLS_String::tableToClass($key); $object2 = new $classFk2(); $str = str_replace($key2,$object2->getColumnComment($key2),$str); } } } else { if (SLS_String::contains($str,$key)) $str = str_replace($key,$objectFk->getColumnComment($key),$str); } } $labelPk = $str; $column["html_type"] = "input_ac"; $column["ac_db"] = strtolower($tableAlias); $column["ac_entity"] = strtolower($tableFk); $column["ac_fk"] = $tablePk; $column["ac_column"] = $column["name"]; if (SLS_String::startsWith($labelPk,"sls:lang:")) { $globalKey = strtoupper(SLS_String::substrAfterFirstDelimiter($labelPk,"sls:lang:")); $labelPk = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) ? $labelPk : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey]; } $column["ac_label"] = $labelPk; $column["ac_pattern"] = $labelPkReal; $column["ac_multiple"] = "false"; if ($column["required"] == "false") $column["default"] = "0"; } else $tablePk = null; if (empty($classFather) || (!empty($classFather) && $classFather != ucfirst($tablePk))) $columns[$column["name"]] = $column; } } return $columns; }
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 getXML() { # Objects $className = ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table); $this->_generic->useModel(SLS_String::tableToClass($this->_table),ucfirst(strtolower($this->_db_alias)),"user"); $this->_object = new $className(); $this->_table = $this->_object->getTable(); $this->_gap = 0; $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($className)."']"; $boExists = $this->_xmlBo->getTag($boPath."/@type"); if (empty($boExists)) $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($className)."']"; # /Objects # User params $this->_join = array(); $this->_where = array(); $this->_group = array(); $this->_order = array(); $this->_limit = array(); $this->_reload = ($this->_http->getParam("reload-filters") == "true") ? true : false; $joins = $this->_xmlBo->getTagsAttributes($boPath."/joins/join",array("table","column")); $wheres = $this->_xmlBo->getTagsAttributes($boPath."/wheres/where",array("table","column","value","mode")); $groups = $this->_xmlBo->getTagsAttributes($boPath."/groups/group",array("table","column")); $orders = $this->_xmlBo->getTagsAttributes($boPath."/orders/order",array("table","column","order")); $limits = array_shift($this->_xmlBo->getTagsAttributes($boPath."/limits/limit",array("start","length"))); if (!empty($joins)) for($i=0 ; $i<$count=count($joins) ; $i++) $this->_join[] = array("table" => SLS_String::substrAfterFirstDelimiter($joins[$i]["attributes"][0]["value"],"_"), "column" => $joins[$i]["attributes"][1]["value"], "mode" => "left"); if (!empty($wheres) && !$this->_reload) for($i=0 ; $i<$count=count($wheres) ; $i++) $this->_where[] = array("column" => SLS_String::substrAfterFirstDelimiter($wheres[$i]["attributes"][0]["value"],"_").".".$wheres[$i]["attributes"][1]["value"], "value" => $wheres[$i]["attributes"][2]["value"], "mode" => $wheres[$i]["attributes"][3]["value"]); if (!empty($groups)) for($i=0 ; $i<$count=count($groups) ; $i++) $this->_group[] = SLS_String::substrAfterFirstDelimiter($groups[$i]["attributes"][0]["value"],"_").".".$groups[$i]["attributes"][1]["value"]; if (!empty($orders)) for($i=0 ; $i<$count=count($orders) ; $i++) $this->_order[] = array("column" => SLS_String::substrAfterFirstDelimiter($orders[$i]["attributes"][0]["value"],"_").".".$orders[$i]["attributes"][1]["value"], "order" => $orders[$i]["attributes"][2]["value"]); if (!empty($limits)) { $this->_limit["start"] = $limits["attributes"][0]["value"]; $this->_limit["length"] = $limits["attributes"][1]["value"]; } # /User params # Comments $this->_comments = array(); $this->_types = array(); $commentsTable = array(); $tables = array($this->_table); foreach($this->_join as $joinTable) $tables[] = $joinTable["table"]; foreach($tables as $commentTable) { if (!array_key_exists($commentTable,$commentsTable)) { $comment = $this->_object->getTableComment($commentTable,$this->_db_alias); if (empty($comment)) $comment = $commentTable; 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]) ? $commentTable : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key]; } $commentsTable[$commentTable] = $comment; } } # /Comments # Columns $this->_columns = array(); $this->_columns = array_merge($this->_columns, $this->getTableColumns($this->_db_alias,$this->_table,$boPath,"",true,true)); foreach($this->_join as $joinTable) $this->_columns = array_merge($this->_columns, $this->getTableColumns($this->_db_alias,$joinTable["table"],$boPath,"",false,true)); $this->_xml->startTag("columns"); foreach($this->_columns as $columnName => $infosColumn) { $this->_xml->startTag("column"); foreach($infosColumn as $key => $value) { if ((is_array($value) && !in_array($key,array("choices","values","errors"))) || in_array($key,array("values","errors"))) continue; if ($key == "choices") { $this->_xml->startTag("choices"); foreach($value as $currentValue) $this->_xml->addFullTag("choice",$currentValue,true); $this->_xml->endTag("choices"); } else if ($key == "label") { $this->_xml->addFullTag($key,$value,true); $this->_xml->startTag("labels_html"); $labels = explode(" ",trim($value)); foreach($labels as $label) $this->_xml->addFullTag("label_html",$label,true); $this->_xml->endTag("labels_html"); } else $this->_xml->addFullTag($key,$value,true); } $this->_xml->endTag("column"); } $this->_xml->endTag("columns"); # /Columns # Reload params // Where $filters = $this->_http->getParam("filters"); if (is_array($filters)) { foreach($filters as $filterTable => $filterColumns) { foreach($filterColumns as $filterColumn => $infos) { $values = (is_array($infos["values"]) && $this->_columns[$filterColumn]["html_type"] != 'input_checkbox') ? $infos["values"] : array($infos["values"]); $modes = (is_array($infos["mode"])) ? $infos["mode"] : array($infos["mode"]); for($i=0 ; $i<$count=count($values) ; $i++) { $value = $values[$i]; $mode = (isset($modes[$i])) ? $modes[$i] : ((isset($modes[0])) ? ($modes[0]) : ""); $mode = (empty($mode)) ? "equal" : $mode; if (is_array($value) && $this->_columns[$filterColumn]["html_type"] == 'input_checkbox') $mode = "in"; if (in_array($mode,array("null","notnull")) || (!in_array($mode,array("null","notnull")) && !empty($value))) { $whereFound = false; foreach($this->_where as $where) { if (SLS_String::contains($where["column"],$filterColumn) && $where["value"] == $value && $where["mode"] == $mode) { $whereFound = true; break; } } if (!$whereFound) $this->_where[] = array("column" => $filterTable.".".$filterColumn, "value" => $value, "mode" => $mode); } } } } } // Order $orderP = $this->_http->getParam("Order"); if (!empty($orderP)) { $orderWays = array("ASC","DESC"); $orderColumn = SLS_String::substrBeforeLastDelimiter($orderP,"_"); $orderWay = SLS_String::substrAfterLastDelimiter($orderP,"_"); if (array_key_exists($orderColumn,$this->_columns)) { if (!in_array(strtoupper($orderWay),$orderWays)) $orderWay = array_shift($orderWays); $this->_order = array(array("column" => $orderColumn, "order" => $orderWay)); } } // Limit $length = $this->_http->getParam("Length"); if (!empty($length) && $length > 0) $this->_limit["length"] = $length; # /Reload params # Default params $positionExists = $this->_xmlType->getTag("//sls_configs/entry[@table='".$this->_table."' and @type='position']/@column"); $lengthExists = $this->_xmlRight->getTag("//sls_configs/entry[@login='******']/settings/setting[@key='list_nb_by_page']"); $fkRecursiveExists = $this->_xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($this->_db_alias."_".$this->_table)."' and @tablePk='".strtolower($this->_db_alias)."_".SLS_String::tableToClass($this->_table)."']/@columnFk"); // i18n > restrict on current language if ($this->_object->isMultilanguage()) { $whereLang = false; foreach($this->_where as $where) { if (SLS_String::contains($where["column"],"pk_lang")) { $whereLang = true; break; } } if (!$whereLang) array_unshift($this->_where, array("column" => $this->_table.".pk_lang", "value" => $this->_lang->getLang(), "mode" => "equal")); if (!empty($this->_join)) { foreach($this->_join as $join) { $join = (is_array($join) && array_key_exists("table",$join)) ? $join["table"] : $join; $this->_generic->useModel(SLS_String::tableToClass($join),$this->_db_alias,"user"); $joinClass = ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($join); $joinObject = new $joinClass(); $joinColumns = $joinObject->getColumns(); if (is_array($joinColumns) && in_array("pk_lang",$joinColumns)) array_push($this->_where, array("column" => $join.".pk_lang", "value" => $this->_lang->getLang(), "mode" => "equal")); } } } // fk on the same model if (!empty($fkRecursiveExists)) $this->_where[] = array("column" => $this->_table.".".$fkRecursiveExists, "value" => "", "mode" => "null"); // group by PK if (empty($this->_group)) $this->_group = array($this->_object->getPrimaryKey()); // order by position asc or PK desc if (empty($this->_order)) $this->_order = (empty($positionExists)) ? array(array("column" => $this->_object->getPrimaryKey(), "order" => "DESC")) : array(array("column" => $positionExists, "order" => "ASC")); // limit at 0, 20 if (empty($this->_limit)) { if (!empty($lengthExists) && $lengthExists > 0) $this->_limit = array("start" => "0", "length" => $lengthExists); else $this->_limit = array("start" => "0", "length" => "20"); } # /Default params # Page infos $this->_xml->startTag("page"); $this->_xml->startTag("model"); $this->_xml->addFullTag("db",$this->_db_alias,true); $this->_xml->addFullTag("table",$this->_table,true); $this->_xml->addFullTag("label",$comment = trim((empty($commentsTable[$this->_table])) ? $this->_table : $commentsTable[$this->_table]),true); $this->_xml->startTag("labels_html"); $comments = explode(" ",$comment); foreach($comments as $comment) $this->_xml->addFullTag("label_html",$comment,true); $this->_xml->endTag("labels_html"); $this->_xml->addFullTag("pk",$this->_object->getPrimaryKey(),true); $this->_xml->endTag("model"); $this->_xml->startTag("joins"); foreach($this->_join as $joinTable) { $this->_xml->startTag("join"); $this->_xml->addFullTag("db",$this->_db_alias,true); $this->_xml->addFullTag("table",$joinTable["table"],true); $this->_xml->addFullTag("column",$joinTable["column"],true); $this->_xml->addFullTag("label",$comment = trim((empty($commentsTable[$joinTable["table"]])) ? $joinTable["table"] : $commentsTable[$joinTable["table"]]),true); $this->_xml->startTag("labels_html"); $comments = explode(" ",$comment); foreach($comments as $comment) $this->_xml->addFullTag("label_html",$comment,true); $this->_xml->endTag("labels_html"); $this->_xml->endTag("join"); } $this->_xml->endTag("joins"); $pkLangWhereFound = false; $this->_xml->startTag("wheres"); foreach($this->_where as $clause) { $table = (SLS_String::contains($clause["column"],".")) ? SLS_String::substrBeforeFirstDelimiter($clause["column"],".") : $this->_table; $column = (SLS_String::contains($clause["column"],".")) ? SLS_String::substrAfterFirstDelimiter($clause["column"],".") : $clause["column"]; if ($column != "pk_lang" || ($column == "pk_lang" && !$pkLangWhereFound)) { if ($column == "pk_lang" && !$pkLangWhereFound) $pkLangWhereFound = true; $this->_xml->startTag("where"); $this->_xml->addFullTag("table",$table,true); $this->_xml->addFullTag("column",$column,true); $this->_xml->startTag("values"); if (is_array($clause["value"])) { foreach($clause["value"] as $clauseValue) $this->_xml->addFullTag("value",$clauseValue,true); } else $this->_xml->addFullTag("value",$clause["value"],true); $this->_xml->endTag("values"); $this->_xml->addFullTag("mode",$clause["mode"],true); $this->_xml->endTag("where"); } } $this->_xml->endTag("wheres"); $this->_xml->startTag("groups"); foreach($this->_group as $groupColumn) $this->_xml->addFullTag("group",(SLS_String::contains($groupColumn,".")) ? SLS_String::substrAfterFirstDelimiter($groupColumn,".") : $groupColumn,true); $this->_xml->endTag("groups"); $this->_xml->startTag("order"); $this->_xml->addFullTag("column",(SLS_String::contains($this->_order[0]["column"],".")) ? SLS_String::substrAfterFirstDelimiter($this->_order[0]["column"],".") : $this->_order[0]["column"],true); $this->_xml->addFullTag("way",$this->_order[0]["order"],true); $this->_xml->endTag("order"); $page = ($this->_http->getParam("page") > 1) ? $this->_http->getParam("page") : 1; $this->_xml->startTag("limit"); $this->_xml->addFullTag("start",$this->_limit["start"] = ($page < 2) ? 0 : (($page-1) * $this->_limit["length"]),true); $this->_xml->addFullTag("length",$this->_limit["length"],true); $this->_xml->endTag("limit"); $countWhere = $this->_where; if (!empty($fkRecursiveExists)) { for($i=0 ; $i<$count=count($countWhere) ; $i++) { if ($countWhere[$i]["column"] == $this->_table.".".$fkRecursiveExists) { unset($countWhere[$i]); break; } } } $this->_xml->addFullTag("total",$this->_object->countModels($this->_table,$this->_join,$countWhere,$this->_group),true); $this->_xml->endTag("page"); # /Page infos # Recordsets $recordsets = $this->_object->searchModels($this->_table,$this->_join,$this->_where,$this->_group,$this->_order,$this->_limit); $this->_xml = $this->formatRecordsets($this->_xml,$recordsets,$fkRecursiveExists); # Recordsets # Urls $this->_xml->startTag("urls"); $this->_xml->addFullTag("list",($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"List".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)))) ? $this->_generic->getFullPath($this->_boController,"List".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)) : "",true,array("authorized" => (SLS_BoRights::isAuthorized("read",ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table))) ? "true" : "false")); $this->_xml->addFullTag("add",($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"Add".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)))) ? $this->_generic->getFullPath($this->_boController,"Add".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)) : "",true,array("authorized" => (SLS_BoRights::isAuthorized("add",ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table))) ? "true" : "false")); $this->_xml->addFullTag("populate",$this->_generic->getFullPath($this->_boController,"BoPopulate",array("Db" => ucfirst(strtolower($this->_db_alias)), "Table" => $this->_table)),true,array("authorized" => (SLS_BoRights::getAdminType() == "developer") ? "true" : "false")); $this->_xml->addFullTag("edit",($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"Modify".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)))) ? $this->_generic->getFullPath($this->_boController,"Modify".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table),array("id" => ""),false) : "",true,array("authorized" => (SLS_BoRights::isAuthorized("edit",ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table))) ? "true" : "false")); $this->_xml->addFullTag("clone",($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"Clone".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)))) ? $this->_generic->getFullPath($this->_boController,"Clone".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table),array("id" => ""),false) : "",true,array("authorized" => (SLS_BoRights::isAuthorized("clone",ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table))) ? "true" : "false")); $this->_xml->addFullTag("delete",($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"Delete".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)))) ? $this->_generic->getFullPath($this->_boController,"Delete".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table),array("id" => ""),false) : "",true,array("authorized" => (SLS_BoRights::isAuthorized("delete",ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table))) ? "true" : "false")); $this->_xml->endTag("urls"); # /Urls # Remember admin settings $nodeExists = $this->_xmlRight->getTag("//sls_configs/entry[@login='******']/@login"); if (!empty($nodeExists)) { $this->_xmlRight->setTag("//sls_configs/entry[@login='******']/settings/setting[@key='list_nb_by_page']",$this->_limit["length"]); $this->_xmlRight->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml"); $this->_xmlRight->refresh(); } # /Remember admin settings # Session remember $rememberList = $this->_session->getParam("SLS_BO_LIST"); if (empty($rememberList)) $rememberList = array(); $url = SLS_String::substrAfterFirstDelimiter($_SERVER["REQUEST_URI"],(($_SERVER['SCRIPT_NAME'] != "/index.php") ? SLS_String::substrBeforeFirstDelimiter($_SERVER['SCRIPT_NAME'],"/index.php")."/" : "/")); if (SLS_String::endsWith($url,$this->_generic->getSiteConfig("defaultExtension"))) $url = SLS_String::substrBeforeLastDelimiter($url,".".$this->_generic->getSiteConfig("defaultExtension")); $query = http_build_query($_POST,"","/"); $query = str_replace(array("%5B","%5D","=/","="),array("[","]","=|sls_empty|/","/"),preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $query)); if (SLS_String::endsWith(trim($query),"/")) $query = SLS_String::substrBeforeLastDelimiter(trim($query),"/"); if (!empty($query)) $url .= "/".$query.((count(explode("/",$query))%2 != 0) ? "/|sls_empty|" : ""); if (SLS_String::endsWith($url,"/")) $url = SLS_String::substrBeforeLastDelimiter($url,"/"); $url .= ".".$this->_generic->getSiteConfig("defaultExtension"); $rememberList[$this->_db_alias."_".$this->_table] = $url; $this->_session->setParam("SLS_BO_LIST",$rememberList); # /Session remember return $this->_xml; }
/** * Format paginate * Since sls 1.0.7: javascript removed, all links are real * * @access public static * @param int $start offset start * @param int $length results by page * @param int $total total results * @param string $param name of the parameter (default: 'page') * @param string $urlSuffix end of url (default: '.sls') * @param string $aClass <a> className (default: 'pager_link'); * @param string $spanClass <span> selected className (default: 'pager_selected'); * @param string $dot <span>...</span> dot className (default: 'pager_dot'); * @param int $maxNb max number to display (default: 10) * @param int $adj nb adjacent numbers (default: 3) * @return string html string * @since 1.0.1 */ public static function paginate($start,$length,$total,$param="page",$urlSuffix=".sls",$aClass="pager_link",$spanClass="pager_selected",$dotClass="pager_dot",$maxNb=10,$adj=3) { if ($length == 0 || $total == 0) return ''; $current = ($start == 0) ? 1 : ($start/$length)+1; $total = ceil($total / $length); $pager = ''; $url = (self::startsWith($_SERVER["SERVER_PROTOCOL"],"https") ? "https://" : "http://").$_SERVER["HTTP_HOST"]; if ($_SERVER["REQUEST_URI"] == "/") $url .= ("/".($_SESSION["current_controller_translated"]."/".$_SESSION["current_action_translated"])); else $url .= (self::substrBeforeFirstDelimiter(self::substrBeforeFirstDelimiter($_SERVER["REQUEST_URI"],"."),"/".$param."/")); if (self::endsWith($url,"/")) $url = self::substrBeforeLastDelimiter($url,"/"); $query = http_build_query($_POST,"","/"); $query = str_replace(array("%5B","%5D","=/","="),array("[","]","=|sls_empty|/","/"),preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $query)); if (SLS_String::endsWith(trim($query),"/")) $query = SLS_String::substrBeforeLastDelimiter(trim($query),"/"); if (!empty($query)) $url .= "/".$query.((count(explode("/",$query))%2 != 0) ? "/|sls_empty|" : ""); if ($total > 1) { if ($current > 1) $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($current-1).$urlSuffix.'" ><</a>'; if ($total < ($maxNb/2 + ($adj * 2))) { $pager .= ($current == 1) ? ('<span class="'.$spanClass.'">1</span>') : ('<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.(1).$urlSuffix.'">1</a>'); for ($i = 2; $i<=$total; $i++) { if ($i == $current) $pager .= '<span class="'.$spanClass.'">'.$i.'</span>'; else $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($i).$urlSuffix.'" >'.$i.'</a>'; } } else { if ($current < 2 + ($adj * 2)) { $pager .= ($current == 1) ? ('<span class="'.$spanClass.'">1</span>') : ('<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.(1).$urlSuffix.'">1</a>'); for ($i = 2; $i < 4 + ($adj * 2); $i++) { if ($i == $current) $pager .= '<span class="'.$spanClass.'">'.$i.'</span>'; else $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($i).$urlSuffix.'">'.$i.'</a>'; } $pager .= '<span class="'.$dotClass.'">...</span>'; $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($total-1).$urlSuffix.'">'.($total-1).'</a>'; $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($total).$urlSuffix.'">'.$total.'</a>'; } else if ( (($adj * 2) + 1 < $current) && ($current < $total - ($adj * 2)) ) { $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.(1).$urlSuffix.'">'.(1).'</a>'; $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.(2).$urlSuffix.'">'.(2).'</a>'; $pager .= '<span class="'.$dotClass.'">...</span>'; for ($i = $current - $adj; $i <= $current + $adj; $i++) { if ($i == $current) $pager .= '<span class="'.$spanClass.'">'.$i.'</span>'; else $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($i).$urlSuffix.'">'.$i.'</a>'; } $pager .= '<span class="'.$dotClass.'">...</span>'; $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($total-1).$urlSuffix.'">'.($total-1).'</a>'; $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($total).$urlSuffix.'">'.$total.'</a>'; } else { $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.(1).$urlSuffix.'">'.(1).'</a>'; $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.(2).$urlSuffix.'">'.(2).'</a>'; $pager .= '<span class="'.$dotClass.'">...</span>'; for ($i = $total - (2 + ($adj * 2)); $i <= $total; $i++) { if ($i == $current) $pager .= '<span class="'.$spanClass.'">'.$i.'</span>'; else $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($i).$urlSuffix.'">'.$i.'</a>'; } } } if ($current < $total) $pager .= '<a class="'.$aClass.'" href="'.$url.'/'.$param.'/'.($current+1).$urlSuffix.'" >></a>'; } return $pager; }
/** * Return all parameters (GET, POST or FILES) * * @access public * @param string $type the type you want ('ALL','POST','GET','FILES') * @return array $params array of all paramters * @since 1.0 * @example * var_dump($this->_http->getParams()); * // will produce : * array( * "mode" => "Home", * "smode" => "Welcome", * "..." => "..." * ) */ public function getParams($type='all') { $type = strtoupper($type); if ($type != 'ALL' && $type != 'POST' && $type != 'GET' && $type != 'FILES') SLS_Tracing::addTrace(new Exception("To use the method SLS_HttpRequest::getParams(), you need to specify a correct type of value ('all', 'post', 'get' or 'files')")); else { if ($type == 'ALL') return $this->_params; elseif ($type == 'POST') return $_POST; elseif ($type == 'GET') { $params = $_GET; // Strip extension if exists if (SLS_String::endsWith($params['smode'], SLS_Generic::getInstance()->getSiteConfig('defaultExtension'))) $params['smode'] = SLS_String::substrBeforeLastDelimiter($params['smode'], '.'.SLS_Generic::getInstance()->getSiteConfig('defaultExtension')); // Get smode $explode = explode("/", $params['smode']); $params['smode'] = array_shift($explode); // Transform url in classic queryString '?param1=value1¶m2=value2...' $queryString = ""; $params = array_chunk($explode, 2); for($i=0 ; $i<$count=count($params) ; $i++) if (count($params[$i]) == 2) $queryString .= (($i == 0) ? '' : '&').$params[$i][0].'='.(($params[$i][1] != "|sls_empty|") ? $params[$i][1] : ""); // Get all params/values parse_str($queryString,$params); if (!empty($params)) { foreach($params as $key => $value) $params[$key] = $value; } return $params; } elseif ($type == 'FILES') return $_FILES; else return $this->_params; } }
/** * Recursive files listing * * @param array $files array of files * @param string $root path * @param string $extension extension to fetch */ protected function recursiveList($files,$root,$extension=".js") { if (SLS_String::endsWith($root,"/")) $root = SLS_String::substrBeforeLastDelimiter($root,"/"); $handle = opendir($root); while (false !== ($file = readdir($handle))) { if (is_dir($root."/".$file) && substr($file, 0, 1) != ".") $this->recursiveList($files,$root."/".$file,$extension); if (!is_dir($root."/".$file) && substr($file, 0, 1) != ".") if (SLS_String::endsWith($file,$extension)) array_push($files,$root."/".$file); } return $files; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $plugId = $this->_http->getParam('Plugin'); $reload = $this->_http->getParam('reload', 'post'); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'Plugins'); if(SLS_PluginsManager::isExists($plugId) === false) $this->redirect($controllers['controller']."/".$controllers['scontroller']); $plugin = new SLS_PluginsManager($plugId); $xmlPlug = $plugin->getXML(); if (!$plugin->isCustomizable()) $this->redirect($controllers['controller']."/".$controllers['scontroller']); $xml->startTag("plugin_infos"); $xml->addFullTag('name', $plugin->_name); $xml->addFullTag('code', $plugin->_code); $xml->addFullTag('id', $plugin->_id); $xml->addFullTag('version', $plugin->_version); $xml->endTag("plugin_infos"); if ($reload == 'true') { $errors = array(); $form_memory = array(); $form_memory = $this->recoverFormValues("//plugin", $xmlPlug, $form_memory); $xml->startTag("memory"); foreach ($form_memory as $key=>$field) { $xml->startTag("values"); $xml->addFullTag("name", $key, true); $xml->addFullTag("value", $field['value'], true); $xml->endTag("values"); $xpath = $field['xpath']; $index = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($xpath, "["), "]"); $xpathNoIndex = SLS_String::substrBeforeLastDelimiter($xpath, "["); if (SLS_String::endsWith($key, "_alias")) { if (count($xmlPlug->getTags($xpathNoIndex."[position() != ".$index." and @alias='".$field['value']."']")) != 0) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." alias ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_UNIQUE']; else $xmlPlug->setTagAttributes($xpath, array("alias"=>$field['value'])); } else { $is_null = (array_shift($xmlPlug->getTags($xpath."/@null")) == "1") ? true : false; switch (array_shift($xmlPlug->getTags($xpath."/@type"))) { case "string" : if (!SLS_String::validateString($field['value']) && !$is_null) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_TYPE']; else $xmlPlug->setTag($xpath, $field['value']); break; case "password" : if (isset($field['value'])) $xmlPlug->setTag($xpath, SLS_Security::encrypt($field['value'], $this->_generic->getSiteConfig("privateKey"))); break; case "int" : if (!is_int($field['value']) && !$is_null) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_TYPE']; else $xmlPlug->setTag($xpath, $field['value']); break; case "float" : if (!is_float($field['value']) && !$is_null) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_TYPE']; else $xmlPlug->setTag($xpath, $field['value']); break; case "select" : $values = explode("|||", array_shift($xmlPlug->getTags($xpath."/@values"))); if (!in_array($field['value'], $values)) $errors[] = array_shift($xmlPlug->getTags($xpath."/@label"))." ".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_E_CONTENT']; else $xmlPlug->setTag($xpath, $field['value']); break; default: break; } } } $xml->endTag("memory"); if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } else { $xml->addFullTag("success", "ok", true); $plugin->saveXML($xmlPlug); } } $xml->addFullTag("fields", $plugin->getFields()->getXML('noHeader'), false); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->makeMenu($this->getXML()); $slsXml = $this->_generic->getCoreXML('sls'); $errors = array(); $syncServer = array_shift($slsXml->getTags("slsnetwork")); $action = $this->_http->getParam('Action'); $serverID = $this->_http->getParam("Server"); $pluginID = $this->_http->getParam("Plugin"); $this->registerLink("CREATE", "SLS_Bo", "CreatePlugin"); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'SearchPlugin'); $serversJSON = @file_get_contents($syncServer); if ($serversJSON === false ||empty($serversJSON)) $errors[] = "You are not connected to internet or synchronisation server is temporaly unavailable"; else { $servers = json_decode($serversJSON); $pluginsServers = $servers->servers->plugins; $plugins = array(); $xml->startTag("servers"); foreach ($pluginsServers as $pluginsServer) { $serverContent = @file_get_contents($pluginsServer->url); $xml->startTag("server", array("name"=>$pluginsServer->name,"id"=>$pluginsServer->id)); $xml->addFullTag("url", $pluginsServer->url, true, array("status"=>($serverContent === false || empty($serverContent)) ? "0" : "1")); if ($serverContent !== false && !empty($serverContent)) { $serverContent = json_decode($serverContent); $xml->startTag("plugins"); $plugs = $serverContent->plugins; foreach ($plugs as $plug) { // If we want to download this Plugin if ($action == "Download" && $pluginsServer->id == $serverID && $plug->id == $pluginID) { $way = $this->_http->getParam('Way'); $pluginXML = $this->_generic->getPluginXml("plugins"); if (count($pluginXML->getTags("//plugins/plugin[@id = '".$plug->id."']")) == 0 && count($pluginXML->getTags("//plugins/plugin[@code = '".$plug->code."' and @beta='1']")) == 0) { if (SLS_Remote::remoteFileExists($plug->file) != 0) $errors[] = $plug->name." is unavailable"; else { $filename = $this->_generic->getPathConfig("coreTmpDownload")."Plugins/".SLS_String::substrAfterLastDelimiter($plug->file, "/"); if (!is_dir($this->_generic->getPathConfig("coreTmpDownload")."Plugins")) mkdir($this->_generic->getPathConfig("coreTmpDownload")."Plugins"); $result = @copy($plug->file, $filename); if ($result === false) $errors[] = "The download of ".$plug->name." has failed"; else { $tar = new SLS_Tar(); if ($tar->openTAR($filename) === false) $errors[] = "Plugin archive is corrupted"; else { $hasConf = false; $isFile = true; $pathName = ""; foreach ($tar->directories as $directory) { if (SLS_String::startsWith($directory['name'], "Sources/")) { $dirName = SLS_String::substrAfterFirstDelimiter($directory['name'], "Sources/"); if (!empty($dirName)) { if (!is_dir($this->_generic->getPathConfig("plugins").$dirName)) mkdir($this->_generic->getPathConfig("plugins").$dirName); if (empty($pathName)) $pathName = (strpos($dirName, "/") !== false) ? SLS_String::substrBeforeLastDelimiter($dirName, "/") : $dirName; $isFile = false; } } } foreach ($tar->files as $file) { $copy = true; if (SLS_String::startsWith($file['name'], "Configs/") && SLS_String::endsWith($file['name'], ".xml")) { $hasConf = true; $copy = @file_put_contents($this->_generic->getPathConfig("configPlugins").$plug->id."_".$plug->code.".xml", $file['file']); } if (SLS_String::startsWith($file['name'], 'Sources/')) { if ($isFile === true && $pathName == "") $pathName = SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/"); $realPathFile = $this->_generic->getPathConfig("plugins").SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/"); $copy = @file_put_contents($realPathFile, $file['file']); } if ($copy === false) { $errors[] = "The copy of ".$file['name']." has failed"; } } if (empty($errors)) { $newPlugin = new SLS_XMLToolbox(false); $newPlugin->startTag("plugin", array("code"=>$plug->code,"id"=>$plug->id,"version"=>$plug->version,"compability"=>$plug->compability,"customizable"=>($hasConf) ? "1" : "0","file"=>($isFile)?"1":"0","path"=>$pathName)); $newPlugin->addFullTag("name", $plug->name, true); $newPlugin->addFullTag("description", $plug->desc, true); $newPlugin->addFullTag("author", $plug->author, true); $newPlugin->addFullTag("dependencies", "", false); $newPlugin->endTag("plugin"); $pluginXML->appendXMLNode("//plugins", $newPlugin->getXML('noHeader')); file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginXML->getXML()); } if (is_file($filename)) unlink($filename); } } } } if ($way == "Maj") { $this->goDirectTo("SLS_Bo", "Plugins"); } }// /If we want to download this Plugin // We list all Plugins available on this server $exist = SLS_PluginsManager::isExists($plug->id); if ($exist) { $plugin = new SLS_PluginsManager($plug->id); } $xml->startTag("plugin", array("version"=>$plug->version,"code"=>$plug->code,"id"=>$plug->id,"compability"=>((float)$plug->compability<=(float)array_shift($slsXml->getTags("version"))) ? "1" : "0","has"=>($exist)?"1":"0")); $xml->addFullTag("name", $plug->name, true); $xml->addFullTag("doc", $pluginsServer->domain.$plug->doc, true); $xml->addFullTag("dl", $controllers['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$controllers['controller']."/".$controllers['scontroller']."/Action/Download/Server/".$pluginsServer->id."/Plugin/".$plug->id.".sls"); $xml->addFullTag("desc", $plug->desc, true); $xml->addFullTag("author", $plug->author, true); $xml->endTag("plugin"); } $xml->endTag("plugins"); } $xml->endTag("server"); } $xml->endTag("servers"); } if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $this->saveXML($xml); }
/** * Log execution time * * @access public * @param float $time execution time * @param string $message message to log * @param string $detail detail * @param string $type type of process * @since 1.0.5 */ public function logTime($time,$message,$detail="",$type="unknown") { #echo "[".$type."] || ".date("Y-m-d H:i:s")." || ".$time." || ".$message." || "."Detail: ".$detail."<br />"; // Developer monitoring if ($this->getSide() == "user" && $this->getBo() != $this->getGenericControllerName()) { $types = array("statics" => array("time" => "0", "logs" => array()), "components" => array("time" => "0", "logs" => array()), "routing" => array("time" => "0", "msg" => ""), "init" => array("time" => "0", "msg" => ""), "action" => array("time" => "0", "msg" => ""), "sql" => array("time" => "0", "logs" => array()), "parsing_html" => array("time" => "0", "msg" => ""), "parsing_xsl" => array("time" => "0", "msg" => ""), "flush_cache" => array("time" => "0", "logs" => array())); $logSession = $this->_session->getParam("sls_dev_logs"); $devLogs = (empty($logSession)) ? $types : $logSession; switch($type) { case "Controller Static": $devLogs["statics"]["time"] += $time; $devLogs["statics"]["logs"][] = array("time" => $time, "msg" => trim(SLS_String::substrAfterFirstDelimiter($detail,"Controller:"))); break; case "Controller Component": $devLogs["components"]["time"] += $time; $devLogs["components"]["logs"][] = array("time" => $time, "msg" => trim(SLS_String::substrAfterFirstDelimiter($detail,"Controller:"))); break; case "Controller Front": $mapping = trim(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($message,"Resolve Mapping ("),")")); $mappingController = SLS_String::substrBeforeFirstDelimiter($mapping,"/"); $mappingAction = SLS_String::substrAfterFirstDelimiter($mapping,"/"); $devLogs["routing"]["time"] += $time; $devLogs["routing"]["msg"] = SLS_String::printArray(array("mode" => $mappingController, "smode" => $mappingAction)); break; case "Controller Init": $devLogs["init"]["time"] += $time; break; case "Controller Action": $devLogs["action"]["time"] += $time; break; case "MySQL Query": $message = trim((!SLS_String::startsWith($detail,"Query:")) ? $message : SLS_String::substrAfterFirstDelimiter($detail,"Query:")); if ($message == "MySQL Connecting") $message = "Connection"." |n|".$detail; $message = str_replace(array("|n|"),array("\n"),$message); $devLogs["sql"]["time"] += $time; $devLogs["sql"]["logs"][] = array("time" => $time, "msg" => $message); break; case "HTML Parsing": $devLogs["parsing_html"]["time"] += $time; break; case "XML/XSL Parsing": $devLogs["parsing_xsl"]["time"] += $time; break; case "Flush Cache": $devLogs["flush_cache"]["time"] += $time; $devLogs["flush_cache"]["logs"][] = array("time" => $time, "msg" => $detail); break; } $this->_session->setParam("sls_dev_logs",$devLogs); } if (!$this->isMonitoring()) return; // Objects $nbOccurencesFiles = 0; $nbMaxLines = 5000; $directory = "monitoring/".date("Y-m"); $fileName = date("Y-m-d"); $filePath = ""; // Check if monitoring directory exists if (!file_exists($this->getPathConfig("logs")."monitoring")) mkdir($this->getPathConfig("logs")."monitoring",0777); // If month directory doesn't exists, create it if (!file_exists($this->getPathConfig("logs").$directory)) mkdir($this->getPathConfig("logs").$directory,0777); // Count the number of hits of log file $handle = opendir($this->getPathConfig("logs").$directory); while (false !== ($file = readdir($handle))) if (SLS_String::startsWith($file,$fileName)) $nbOccurencesFiles++; closedir($handle); // If the current file log doesn't exists, create it if ($nbOccurencesFiles == 0) { touch($this->getPathConfig("logs").$directory."/".$fileName."_0.log"); $filePath = $this->getPathConfig("logs").$directory."/".$fileName."_0.log"; } // Else, locate it else $filePath = $this->getPathConfig("logs").$directory."/".$fileName."_".($nbOccurencesFiles-1).".log"; // Then, if and only if the file log has been located, increased or created : write into the logs if (is_file($filePath) && $this->getSide() == "user") { $oldContentLog = file_get_contents($filePath); $newContentLog = "".$type." || ".date("Y-m-d H:i:s")." || ".$time." || ".$message." || ".$detail; if (SLS_String::endsWith($newContentLog,"\n")) $newContentLog = SLS_String::substrBeforeLastDelimiter($newContentLog,"\n"); $newContentLog = str_replace("\n","|n|",$newContentLog); file_put_contents($filePath,$newContentLog."\n".$oldContentLog,LOCK_EX); if ($type == "Render") { $oldContentLog = file_get_contents($filePath); $newContentLog = "#|end|#"; file_put_contents($filePath,$newContentLog."\n".$oldContentLog,LOCK_EX); // If the max number of lines has been reach, increase the file log version if (SLS_String::countLines(file_get_contents($filePath)) >= $nbMaxLines) { touch($this->getPathConfig("logs").$directory."/".$fileName."_".$nbOccurencesFiles.".log"); $filePath = $this->getPathConfig("logs").$directory."/".$fileName."_".$nbOccurencesFiles.".log"; } } } }