/** * Constructor * * @access public * @since 1.0 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_cache = $this->_generic->getObjectCache(); $this->_xmlToolBox = new SLS_XMLToolbox(); $this->_xmlToolBox->startTag("Components"); $this->_xmlToolBox->addFullTag("Sls", "", false); if ($this->_generic->getSide() == "user" || ($this->_generic->getActionId() == $this->_generic->getActionId("SLS_Bo","ProdSettings"))) $this->_xmlToolBox->addFullTag("Site", "", false); $this->_xmlToolBox->endTag("Components"); $this->_isCache = $this->_generic->isCache(); $this->_cacheXML = new SLS_XMLToolbox(false); if (!$this->_isCache) $this->_cacheXML->startTag("components"); // Load Core Statics $this->recursiveStaticLoading($this->_generic->getPathConfig("coreComponentsControllers"), 'Sls'); if ($this->_generic->getSide() == "user" || ($this->_generic->getActionId() == $this->_generic->getActionId("SLS_Bo","ProdSettings"))) $this->recursiveStaticLoading($this->_generic->getPathConfig("componentsControllers"), 'Site'); if (!$this->_isCache) { $this->_cacheXML->endTag("components"); $writeXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSecure")."cache.xml")); $writeXML->overwriteTags("//statics", $this->_cacheXML->getXML('noHeader')); $writeXML->saveXML($this->_generic->getPathConfig("configSecure")."cache.xml"); } return $this->getXML(); }
/** * Constructor * * @access public * @param bool $multilanguage true if we have multilanguage content, else false * @since 1.0 */ public function __construct($multilanguage=false) { $this->_isMultilanguage = ($multilanguage) ? true : false; $this->beSurInitDbInfos(); $this->_generic = SLS_Generic::getInstance(); $sql = get_class($this)."Sql"; $this->_sql = new ${sql}($this->_table, $this->_primaryKey, $this->_isMultilanguage); }
/** * Constructor * * @access public * @since 1.0 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_session = $this->_generic->getObjectSession(); $this->_cookieName = ($this->_generic->getSide() == 'sls') ? md5($this->_generic->getSiteConfig("projectName")."-SLS_Management") : md5($this->_generic->getSiteConfig("projectName")."-User-Lang"); $this->_cookie = new SLS_Cookie($this->_cookieName); $lang = ($this->_generic->getSide() == 'sls') ? 'en' : $this->_session->getParam("lang"); $this->refreshLangSide(); $applicationLangs = $this->getSiteLangs(); // We search into the session if one lang is already defined if (!empty($lang) && in_array($lang, $applicationLangs)) { $this->_lang = $lang; } else if($this->_generic->getSiteConfig('isInstall') == 0) { // Search into the cookie the lang $lang = $this->_cookie->__get("lang"); if (!empty($lang) && in_array($lang, $applicationLangs)) $this->_lang = $lang; // Search into the browser's lang else { $langsAccepted = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $hasLangAccepted = false; // We search if one lang into the browser match with one lang of the application foreach ($langsAccepted as $value) { if (in_array(strtolower(substr($value, 0, 2)), $applicationLangs) && is_file($this->_generic->getPathConfig("coreGenericLangs")."generic.".substr($value, 0, 2).".lang.php") && is_file($this->_generic->getPathConfig("genericLangs")."site.".substr($value, 0, 2).".lang.php")) { $hasLangAccepted = true; $lang = substr($value, 0, 2); break; } } // If any langs has been found, take the default language defined in the back office if (!$hasLangAccepted) $lang = $this->_generic->getSiteConfig("defaultLang"); } } // Load lang files include ($this->_generic->getPathConfig("coreGenericLangs")."generic.".substr($lang, 0, 2).".lang.php"); if ($this->_generic->getSide() == 'user' && !$this->_generic->getSiteConfig("isInstall")) include ($this->_generic->getPathConfig("genericLangs")."site.".substr($lang, 0, 2).".lang.php"); $this->_lang = $lang; // Set the lang into the cookie and into the session $this->setCookieLang(); $this->setSessionLang(); }
/** * Constructor, instanciate PDO class to prepare connection(s) * * @access public * @since 1.0 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_cache = $this->_generic->getObjectCache(); $needed = array("mysql", "PDO", "pdo_mysql"); $php = get_loaded_extensions(); foreach ($needed as $phpPre) if (!in_array($phpPre, $php)) SLS_Tracing::addTrace(new Exception("You need PHP Extension : ".$phpPre)); }
/** * Constructor * * @access private * @since 1.0 */ private function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_cache = $this->_generic->getObjectCache(); $this->_httpRequest = $this->_generic->getObjectHttpRequest(); $this->_lang = $this->_generic->getObjectLang(); $this->_controllerXML = $this->_generic->getControllersXML(); $this->parseUrl(); $this->_lastSide = $this->_generic->getObjectSession()->getParam('lastSide'); $this->_includePathControllers = (!empty($this->_lastSide) && $this->_lastSide == 'sls') ? "coreActionsControllers" : "actionsControllers"; $this->_defaultClassName = (!empty($this->_lastSide) && $this->_lastSide == 'sls') ? "SLS_Default" : "Default"; (!empty($this->_lastSide) && $this->_lastSide == 'sls') ? $this->_lang = new SLS_Lang() : ""; }
/** * Constructor * * @access public * @param bool $userSide true if it's user side, else false * @since 1.0 */ public function __construct($userSide=false) { $this->_generic = SLS_Generic::getInstance(); $this->_http = $this->_generic->getObjectHttpRequest(); $this->_session = $this->_generic->getObjectSession(); $this->_lang = $this->_generic->getObjectLang(); $this->_security = $this->_generic->getObjectSecurity(); $this->_xmlToolBox = new SLS_XMLToolbox(false); if ($userSide === true) { $this->_onSide = 'user'; $this->_xmlToolBox->startTag(SLS_String::substrBeforeLastDelimiter(get_class($this), "Controller")); } $this->constructXML(); }
/** * Constructor * * @access public * @since 1.0 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_http = $this->_generic->getObjectHttpRequest(); $this->_session = $this->_generic->getObjectSession(); $this->_lang = $this->_generic->getObjectLang(); $this->_cache = $this->_generic->getObjectCache(); $this->_security = $this->_generic->getObjectSecurity(); $this->_xml = $this->_generic->getBufferXML(); $initControllerXml = new SLS_XMLToolbox($this->_xml); $initControllerXml->appendXMLNode("//root", "<View></View>"); $this->_xml = $initControllerXml->getXML(); $this->_generic->setBufferXml($this->_xml, false); $this->_loadStaticsJs = ($this->_generic->getSiteConfig("defaultLoadStaticsJavascript") == 1) ? true : false; $this->_loadDynsJs = ($this->_generic->getSiteConfig("defaultLoadDynsJavascript") == 1) ? true : false; $this->_jsMultiLang = ($this->_generic->getSiteConfig("defaultMultilanguageJavascript") == 1) ? true : false; $this->_buildConfigsJsVars = ($this->_generic->getSiteConfig("defaultBuildConfigsJsVars") == 1) ? true : false; $this->recoverInitialMetas(); }
/** * Constructor, start the session * * @access public * @param bool $remote true if you want to access sillysmart in a isolated way like web-services, else false (default) * @since 1.0 */ public function __construct($remote=false) { $domainSession = SLS_Generic::getInstance()->getSiteConfig("domainSession"); // If we have a session sharing between domains if (!empty($domainSession)) { try { ini_set("session.cookie_domain",$domainSession); } catch (Exception $e) { SLS_Tracing::addTrace($e); } } // If not a remote access if (!$remote && PHP_SAPI !== 'cli') session_start(); }
/** * Constructor * * @access public * @since 1.0 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_session = $this->_generic->getObjectSession(); $this->_http = $this->_generic->getObjectHttpRequest(); $this->_lang = $this->_generic->getObjectLang(); $this->_async = (strtolower($this->_http->getParam("sls-request"))=="async") ? true : false; $this->_db = new SLS_Sql(); $this->_boController = $this->_generic->getBo(); $this->_boProtocol = $this->_generic->getControllersXML()->getTag("//controllers/controller[@name='".$this->_boController."']/@protocol"); $this->_defaultDb = $this->_generic->getDbXML()->getTag("//dbs/db[@isDefault='true']/@alias"); $this->_xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $this->_xmlRight = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml")); $this->_xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml")); $this->_xmlFilter = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml")); $this->_xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $this->_xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml")); $this->_langs = $this->_lang->getSiteLangs(); $this->_defaultLang = $this->_generic->getSiteConfig("defaultLang"); $this->isAuthorized(); }
/** * Switch the current application language and reload the current page * * @access public * @param string $lang the lang to switch * @param string $controller the generic controller to reroute after changing lang (if empty, previous controller) * @param string $scontroller the generic scontroller to reroute after changing lang (if empty, previous action) * @param string $domainAlias the alias domain * @since 1.0 * @example * $this->_generic->switchLang("fr"); * // will change your current language to 'french' */ public function switchLang($lang,$controller="",$scontroller="",$params="",$domainAlias="") { $mode = $this->getObjectSession()->getParam("previousMode"); $smode = $this->getObjectSession()->getParam("previousSmode"); $more = $this->getObjectSession()->getParam("previousMore"); if (!empty($params)) { $more = ""; foreach($params as $paramKey => $paramValue) $more .= "/".$paramKey."/".$paramValue; } $controller = (empty($controller)) ? $this->getObjectSession()->getParam("previousController") : $controller; $scontroller = (empty($scontroller)) ? $this->getObjectSession()->getParam("previousScontroller") : $scontroller; $generic = SLS_Generic::getInstance(); $domainAlias = $generic->getSiteXML()->getTag("//configs/domainName/domain[@lang = '".$lang."']/@alias"); $actualLang = $this->getObjectLang()->getLang(); // If unknown lang, redirect on current page without switching lang if (!in_array($lang,$this->getObjectLang()->getSiteLangs())) $this->redirect($mode."/".$smode.$more,$domainAlias); // If we don't have generic controllers but translated controllers, try to recover generics if ((empty($controller) && empty($scontroller)) && (!empty($mode) && !empty($smode))) { $controller = array_shift($this->_controllers->getTags("//controllers/controller[controllerLangs[controllerLang[@lang='".$actualLang."']='".$mode."']]/@name")); $scontroller = array_shift($this->_controllers->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[scontrollerLangs/scontrollerLang[@lang='".$actualLang."']='".$smode."']/@name")); } // If impossible to relocate previous controllers, redirect on home in the new lang if (empty($controller) || empty($scontroller)) { $this->getObjectLang()->setLang($lang); $this->forward("Home","Index",array(),$lang,(!empty($domainAlias)) ? $domainAlias : ""); } // If we are here, it's cool :) else { $this->getObjectLang()->setLang($lang); $urlArray = $this->getTranslatedController($controller,$scontroller,$lang); $this->redirect($this->getSiteConfig("protocol")."://".$this->getSiteConfig("domainName",(!empty($domainAlias)) ? $domainAlias : "")."/".$urlArray["controller"]."/".$urlArray["scontroller"].$more); } }
public static function boExists() { return (SLS_Generic::getInstance()->getBo() == "") ? false : true; }
/** * Constructor * * @access public * @since 1.0 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->_session = $this->_generic->getObjectSession(); }
/** * 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; } }
/** * Constructor, instanciate generic class & get bind * * @access public * @since 1.0.9 */ public function __construct() { $this->_generic = SLS_Generic::getInstance(); $this->fetchBind(); $this->fetchObject(); }
/** * Symmetric encryption * * @access public static * @param string $text the text to encrypt * @param string $key the private key (default Project Private key) * @return string $decrypted the text decrypted * @see SLS_Security::crypte * @since 1.0 * @example * $uncrypted = SLS_Security::getInstance()->decrypt("VyUA[..]UgCCA="); * var_dump($uncrypted); * // will produce : "sillysmart" */ public static function decrypt($text,$key="") { if ($key == "") $key = SLS_Generic::getInstance()->getSiteConfig('privateKey'); $text = SLS_Security::generateKey(base64_decode($text),$key); $decrypted = ""; for ($i=0;$i<strlen($text);$i++) { $md5 = substr($text,$i,1); $i++; $decrypted.= (substr($text,$i,1) ^ $md5); } return $decrypted; }
<?php include "Sls/Generics/SLS_Generic.class.php"; $genericLib = SLS_Generic::getInstance()->loadFramework(); $frontController = SLS_FrontController::getInstance($genericLib); $frontController->loadController(); new SLS_View($genericLib, $frontController->getXML());
/** * Get absolute URL to a file * * @access public static * @param string $file file name * @param string $domainAlias the alias domain * @return string $file absolute URL * @see SLS_String::getUrlFileImg * @since 1.0.7 */ public static function getUrlFile($file,$domain="") { $generic = SLS_Generic::getInstance(); return $generic->getSiteConfig("protocol")."://".$generic->getSiteConfig("domainName",(empty($domain) && $generic->hasCdn()) ? $generic->getCdn() : $domain)."/".$generic->getPathConfig("files").$file; }
/** * Compile the mail before sending it * * @access public * @since 1.0 */ public function compileMail() { if (empty($this->headers['From'])) $this->setSender(SLS_Generic::getInstance()->getMailConfig('defaultSender').'@'.SLS_Generic::getInstance()->getMailConfig('defaultDomain'), SLS_Generic::getInstance()->getMailConfig('defaultNameSender')); if (empty($this->headers['Reply-To'])) $this->setReply(SLS_Generic::getInstance()->getMailConfig('defaultReply').'@'.SLS_Generic::getInstance()->getMailConfig('defaultDomain'), SLS_Generic::getInstance()->getMailConfig('defaultNameReply')); if (empty($this->headers['Return-Path'])) $this->setReply(SLS_Generic::getInstance()->getMailConfig('defaultReturn').'@'.SLS_Generic::getInstance()->getMailConfig('defaultDomain'), SLS_Generic::getInstance()->getMailConfig('defaultNameReturn')); if((empty($this->headers['To']) && empty($this->headers['Cc']) && empty($this->headers['Bcc'])) || (empty($this->headers['From']) && empty($this->headers['Return-Path']))) return $this->error("Some required headers are missing."); if($this->versionplain == "" && $this->versionhtml != "") $this->versionplain = strip_tags(str_replace("<br />", "\n", $this->versionhtml)); if(!empty($this->attachments)) { $this->headers['Content-type'] = "multipart/mixed; boundary=\"Part-{$this->boundary['mixed']}\""; $this->message .= "--Part-{$this->boundary['mixed']}\r\n"; } else if(!empty($this->files)) $this->headers['Content-type'] = "multipart/related; boundary=\"Part-{$this->boundary['related']}\""; else if(!empty($this->versionhtml)) $this->headers['Content-type'] = "multipart/alternative; boundary=\"Part-{$this->boundary['alternative']}\""; else $this->headers['Content-type'] = "text/plain; charset=\"us-ascii\""; if(!empty($this->files) && !empty($this->attachments)) $this->message .= $this->wrapHeader("Content-type: multipart/related; boundary=\"Part-{$this->boundary['related']}\"\r\n\r\n"); if(!empty($this->files)) $this->message .= "--Part-{$this->boundary['related']}\r\n"; if(!empty($this->versionhtml) && (!empty($this->files) || !empty($this->attachments))) $this->message .= $this->wrapHeader("Content-type: multipart/alternative; boundary=\"Part-{$this->boundary['alternative']}\"\r\n\r\n"); if(!empty($this->versionhtml)) $this->message .= "--Part-{$this->boundary['alternative']}\r\n"; if(!empty($this->versionhtml) || !empty($this->files) || !empty($this->attachments)) { $this->message .= "Content-type: text/plain; charset=\"us-ascii\"\r\n"; $this->message .= "Content-transfer-encoding: 7bit\r\n\r\n"; $this->message .= $this->versionplain."\r\n\r\n"; } else $this->message = $this->versionplain; if(!empty($this->versionhtml)) { $this->message .= "--Part-{$this->boundary['alternative']}\r\n"; $this->message .= "Content-type: text/html; charset=\"{$this->charset}\"\r\n"; $this->message .= "Content-transfer-encoding: quoted-printable\r\n\r\n"; $this->message .= $this->versionhtml."\r\n\r\n"; $this->message .= "--Part-{$this->boundary['alternative']}--\r\n"; } if(!empty($this->files)) { $this->compileEmbedded(); $this->message .= "--Part-{$this->boundary['related']}--\r\n"; } if(!empty($this->attachments)) { $this->compileAttachments(); $this->message .= "--Part-{$this->boundary['mixed']}--\r\n"; } $headers = array(); foreach($this->headers as $k => $v) { if(is_array($v) && !empty($v)) $headers[$k] = $v; else if($v != "" && !empty($v)) { if (substr($v,0,strlen("$k:")) != "$k:" ) $headers[$k] = wordwrap("$k: $v",75,"\r\n "); else $headers[$k] = $v; } } $this->headers = $headers; $this->compiled = true; }
/** * Delete n objects of models * * @param string $table the current table to delete (default: empty => current model) * @param array $joins the table(s) to join with current table (default: empty => no join) * If you want to natural join: * <code>array("table_2","table_3","...","table_n")</code> will give 'DELETE FROM table_1 NATURAL JOIN table_2 NATURAL JOIN table_3 ... NATURAL JOIN table_n' * If you want to join with a specific column: * <code>array(0=>array("table"=>"table_2","column"=>"column_2"),1=>array("table"=>"table_3","column"=>"column_3"))</code> * If you want to inner/left/right join: * <code>array(0=>array("table"=>"table_2","column"=>"column_2","mode"=>"natural"),1=>array("table"=>"table_3","column"=>"column_3","mode"=>"left"))</code> * @param array $clause the clause wanted (default: empty => no clause) * <code> * array * ( * [0] => array * ( * ["column"] = "column_1", * ["value"] = "value_1", * ["mode"] = "like" or "notlike" or "beginwith" or "endwith" or "equal" or "notequal" or "lt" or "le" or "ge" or "gt" or "null" or "notnull" * ) * [1] => array * ( * ["column"] = "user_department", * ["value"] = "75", * ["mode"] = "like" or "notlike" or "beginwith" or "endwith" or "equal" or "notequal" or "lt" or "le" or "ge" or "gt" or "null" or "notnull" * ) * ) * </code> * @return int $count the number of lines deleted * @see SLS_FrontModel::searchModels * @since 1.0.6 */ public function deleteModels($table,$joins,$clause) { $allowToJoin = false; $modeJoin = "inner"; $modesJoin = array("inner","left","right"); $columns = array(); /** * TABLE NAME */ // If table name haven't been filled, try to recover table name from the current model if (empty($table)) { $table = (empty($this->_table)) ? substr(get_class($this),0,strlen(get_class($this))-3) : $this->_table; } // If table name is again empty, throw a Sls Exception if (empty($table)) { SLS_Tracing::addTrace(new Exception("Error: Table's name has been omitted"),true); return false; } // If model doesn't exists if ($this->_generic->useModel(SLS_String::tableToClass($table),$this->_db->getCurrentDb(),"user") || $this->_generic->useModel(SLS_String::tableToClass($table),$this->_db->getCurrentDb(),"sls")) { $className = ucfirst(strtolower($this->_db->getCurrentDb()))."_".SLS_String::tableToClass($table); $object = new $className(); foreach($object->getParams() as $key => $value) array_push($columns,$key); } else { SLS_Tracing::addTrace(new Exception("Error: Table `".$table."` doesn't exist in database `".($this->_db->getCurrentDb())."`"),true); return false; } /** * /TABLE NAME */ /** * JOINS */ // Get all the columns of the current table $columnsMain = $columns; $joinMain = $table; // If we want to join tables if (is_array($joins) && !empty($joins)) { // Foreach tables to join foreach ($joins as $currentJoin) { // If we want joins with the clause "using" if (is_array($currentJoin)) { // Override join mode ? if (array_key_exists("mode",$currentJoin)) $modeJoin = (in_array(strtolower($currentJoin["mode"]),$modesJoin)) ? strtolower($currentJoin["mode"]) : array_shift($modesJoin); $currentJoin = $currentJoin["table"]; } // If the table to join doesn't exists in MySQL, throw a Sls Exception if (!$this->_generic->useModel(SLS_String::tableToClass($currentJoin),$this->_db->getCurrentDb(),"user") && !$this->_generic->useModel(SLS_String::tableToClass($currentJoin),$this->_db->getCurrentDb(),"sls")) SLS_Tracing::addTrace(new Exception("Warning: Table `".$currentJoin."` to join with `".$joinMain."` doesn't exist in database `".(SLS_Generic::getInstance()->getDbConfig("base"))."`"),true); // Else check if we can join else { $className = ucfirst(strtolower($this->_db->getCurrentDb()))."_".SLS_String::tableToClass($currentJoin); $objectJoin = new $className(); $columnsJoin = array(); // Get all the columns of the table to join foreach($objectJoin->getParams() as $key => $value) array_push($columnsJoin,$key); // If we want joins with the clause "using", allow to join and merge the columns of the table to join with all the columns already listed if (is_array($currentJoin)) { $allowToJoin = true; $columnsMain = array_merge($columnsMain,$columnsJoin); } // Else if we want a "NATURAL JOIN", check if we have a common key else { // Foreach columns of the current table foreach($columnsMain as $tMain) { // Foreach columns of the table to join foreach($columnsJoin as $tJoin) { // If we have a common column, allow to join and merge the columns of the table to join with all the columns already listed if ($tJoin == $tMain) { $allowToJoin = true; $columnsMain = array_merge($columnsMain,$columnsJoin); } } } } // If we can't join, throw a Sls Exception if (!$allowToJoin) { SLS_Tracing::addTrace(new Exception("Warning: Table `".$currentJoin."` to join with `".$joinMain."` doesn't have a common key"),true); $joins = array(); break; } // Move the reference table $joinMain = $currentJoin; } } } // Build the start of the query $sql = "DELETE `".$table."` FROM `".$table."` "; // If we can join, build the join if ($allowToJoin && is_array($joins) && !empty($joins)) { foreach ($joins as $currentJoin) { if (is_array($currentJoin)) $sql .= strtoupper($modeJoin)." JOIN "."\n". " `".$currentJoin["table"]."` USING(".$currentJoin["column"].") "; else $sql .= "NATURAL JOIN "."\n". " `".$currentJoin."` "; } } /** * /JOINS */ /** * CLAUSE */ // If we want a clause where if (!empty($clause)) { $lastSucceeded = false; // Foreach items to restrict for($i=0 ; $i<count($clause) ; $i++) { // If column on which you want to apply a restrict clause is in the list of columns collected on the tables $columnName = (SLS_String::contains($clause[$i]["column"],".")) ? SLS_String::substrAfterLastDelimiter($clause[$i]["column"],".") : $clause[$i]["column"]; if (in_array($columnName,$columnsMain)) { $sql .= ($lastSucceeded) ? " AND " : " WHERE "; // Build the correct statement $clause[$i]["column"] = "`".$clause[$i]["column"]."`"; switch($clause[$i]["mode"]) { case "like": $sql .= ("LOWER(".$clause[$i]["column"].") LIKE ".$this->_db->quote("%".strtolower($clause[$i]["value"])."%")); break; case "notlike": $sql .= ("LOWER(".$clause[$i]["column"].") NOT LIKE ".$this->_db->quote("%".strtolower($clause[$i]["value"])."%")); break; case "beginwith": $sql .= ("LOWER(".$clause[$i]["column"].") LIKE ".$this->_db->quote(strtolower($clause[$i]["value"])."%")); break; case "endwith": $sql .= ("LOWER(".$clause[$i]["column"].") LIKE ".$this->_db->quote("%".strtolower($clause[$i]["value"]))); break; case "equal": $sql .= ("".$clause[$i]["column"]." = ".$this->_db->quote($clause[$i]["value"])); break; case "notequal": $sql .= ("".$clause[$i]["column"]." != ".$this->_db->quote($clause[$i]["value"])); break; case "lt": $sql .= ("".$clause[$i]["column"]." < ".$this->_db->quote($clause[$i]["value"])); break; case "le": $sql .= ("".$clause[$i]["column"]." <= ".$this->_db->quote($clause[$i]["value"])); break; case "ge": $sql .= ("".$clause[$i]["column"]." >= ".$this->_db->quote($clause[$i]["value"])); break; case "gt": $sql .= ("".$clause[$i]["column"]." > ".$this->_db->quote($clause[$i]["value"])); break; case "null": $sql .= ("".$clause[$i]["column"]." IS NULL "); break; case "notnull": $sql .= ("".$clause[$i]["column"]." IS NOT NULL "); break; case "in": $clause[$i]["value"] = (is_array($clause[$i]["value"])) ? array_map(array($this->_db, 'quote'),$clause[$i]["value"]) : $clause[$i]["value"]; $sql .= ("".$clause[$i]["column"]." IN (".((is_array($clause[$i]["value"]) ? implode(",",$clause[$i]["value"]) : $this->_db->quote($clause[$i]["value"]))).") "); break; case "notin": $clause[$i]["value"] = (is_array($clause[$i]["value"])) ? array_map(array($this->_db, 'quote'),$clause[$i]["value"]) : $clause[$i]["value"]; $sql .= (" ".$clause[$i]["column"]." NOT IN (".((is_array($clause[$i]["value"]) ? implode(",",$clause[$i]["value"]) : $this->_db->quote($clause[$i]["value"]))).") "); break; default: $sql .= ("LOWER(".$clause[$i]["column"].") LIKE ".$this->_db->quote("%".strtolower($clause[$i]["value"])."%")); break; } $lastSucceeded = true; } // Else, throw a Sls Exception else SLS_Tracing::addTrace(new Exception("Warning: Column ".$clause[$i]["column"]." in clause where doesn't exist in table `".$table."` (and collected tables to join)"),true); } } /** * /CLAUSE */ // Try to execute the built query try { return $this->_db->delete($sql); } catch (Exception $e) { SLS_Tracing::addTrace($e,true); return false; } }
/** * Load Mootools in the output case * * @access public static * @since 1.0 */ public static function loadMootools() { $generic = SLS_Generic::getInstance(); echo '<script src="'.$generic->getProtocol().'://'.$generic->getSiteConfig("domainName").'/'.$generic->getPathConfig("coreJsDyn").'mootools-core-and-more-1.5.0.js" type="text/javascript"></script>'."\n"; echo '<link href="'.$generic->getProtocol().'://'.$generic->getSiteConfig('domainName').'/'.$generic->getPathConfig('coreCss').'highlight.css" rel="stylesheet" type="text/css" />'."\n"; echo '<script src="'.$generic->getProtocol().'://'.$generic->getSiteConfig("domainName").'/'.$generic->getPathConfig("coreJsDyn").'highlight.js" type="text/javascript"></script>'."\n"; echo "<script type='text/javascript'>\n window.addEvent('load', function(){\n var toolTipsB = new Tips($$('.tooltip'), {\n className: 'custom_tip',\n showDelay: 200,\n hideDelay: 200,\n fixed: true,\n onShow: function(toolTip) {\n var element = new Element('div',{'html' : $$('.tip-text')[0].get('html')});\n var childrens = element.getChildren('pre')\n if (childrens.length > 0){\n for(i=0 ; i<childrens.length ; i++){\n SyntaxHighlighter.highlight(childrens[i]);\n }\n }\n toolTip.setStyle('display','block');\n }\n });\n });\n SyntaxHighlighter.all();\n </script>\n"; }
/** * Check if the current admin is authorized to access on this back-office action * * @access public static * @param string $type the type of action ('List'|'Add'|'Modify'|'Delete') * @return int $authorized -1 if not logged, 0 is not authorized, 1 if ok * @since 1.0 */ public static function isAuthorized($role="read",$entity="",$aid="") { $generic = SLS_Generic::getInstance(); $session = $generic->getObjectSession(); $sessionToken = substr(substr(sha1($generic->getSiteConfig("privateKey")),12,31).substr(sha1($generic->getSiteConfig("privateKey")),4,11),6); $xmlRights = new SLS_XMLToolbox(file_get_contents($generic->getPathConfig("configSls")."/rights.xml")); $authorized = 0; if (self::isLogged()) { if ($session->getParam("SLS_SESSION_VALID_".$sessionToken) == "true") return 1; if ($role == "dashboard" && SLS_String::contains($aid,"sls_graph")) { $result = array_shift($xmlRights->getTags("//sls_configs/entry[@login='******']/action[@id='".$aid."']/@id")); $authorized = (!empty($result)) ? 1 : 0; } else if ($generic->actionIdExists($aid)) { $result = array_shift($xmlRights->getTags("//sls_configs/entry[@login='******']/action[@id='".$aid."']/@id")); $authorized = (!empty($result)) ? 1 : 0; } else { $result = array_shift($xmlRights->getTags("//sls_configs/entry[@login='******']/action[@role='".$role."' and @entity='".$entity."']/@id")); $authorized = (!empty($result)) ? 1 : 0; } return $authorized; } else return -1; }
/** * Init static xml variable * * @access public static * @return SLS_XmlToolbox $pluginXML the xml configuration of plugins * @since 1.0 */ public static function returnPluginsXML() { if (!is_object(SLS_PluginsManager::$_pluginsXML)) SLS_PluginsManager::$_pluginsXML = SLS_Generic::getInstance()->getPluginXml("plugins"); return SLS_PluginsManager::$_pluginsXML; }
/** * Parsing: flow XML + XSL => xHTML * * @access private * @since 1.0 */ private function parseToXhtml() { $this->_generic->_time_checkpoint = microtime(true); // Xml $xmlDoc = new DOMDocument(); try { $xmlDoc->loadXML($this->_xml); } catch (Exception $e) { SLS_Tracing::addTrace(new Exception("Error during XML Parsing"), true, "<h2>".$e->getMessage()."</h2><div style=\"margin: 0 30px;padding: 10px;\"><pre name=\"code\" class=\"brush:xml\">".htmlentities($this->_xml, ENT_QUOTES)."</pre></div>"); } // Xsl $xslDoc = new DOMDocument(); try { $xslDoc->loadXML($this->constructGenericXsl()); } catch (Exception $e) { SLS_Tracing::addTrace(new Exception($e->getMessage())); } // Parsing $proc = new XSLTProcessor(); $proc->registerPHPFunctions(); try { $proc->importStyleSheet($xslDoc); } catch (Exception $e) { SLS_Tracing::addTrace(new Exception($e->getMessage())); } // If errors in dev if (!SLS_Generic::getInstance()->isProd() && SLS_Tracing::$_exceptionThrown) SLS_Tracing::displayTraces(); else { // Show xml in source in dev /*if ($this->_generic->getSiteConfig("isProd") == 0) echo "<!--[if lt IE 5]><!--<![CDATA[<pre style='display:none;'>\n".$this->_xml." \n</pre>]]>--><![endif]-->\n";*/ // Parse XML/XSL $html = $proc->transformToXML($xmlDoc); $this->_generic->logTime($this->_generic->monitor($this->_generic->_time_checkpoint),"Parsing XML/XSL","","XML/XSL Parsing"); $this->_generic->_time_checkpoint = microtime(true); // Parse HTML with SLS_Dtd $html = $this->parseHtml($html); // Sls cached enabled and Action cache enabled ? $cacheOptions = $this->_cache->getAction(); $actionCache = false; if ($this->_generic->isCache() && $this->_generic->getSide() == "user" && $this->_generic->getGenericControllerName() != "Default" && is_array($cacheOptions) && count($cacheOptions) == 4) { $actionCache = true; $actionCacheVisibility = $cacheOptions[0]; $actionCacheScope = $cacheOptions[1]; $actionCacheResponsive = $cacheOptions[2]; $actionCacheExpiration = $cacheOptions[3]; // Save Full HTML cached if ($actionCacheScope == "full") $this->_cache->saveCacheFull($html,$actionCacheVisibility,$actionCacheResponsive); } // Show flash button to copy Xml if developer on user side and not on Bo if (SLS_BoRights::isLogged() && SLS_BoRights::getAdminType() == "developer" && $this->_generic->getSide() == "user" && $this->_generic->getGenericControllerName() != $this->_generic->getBo()) $html = preg_replace('/\<\/head\>/i', "\n". t(1).'<!-- Sls developer Toolbar -->'."\n". t(1).'<script type="text/javascript" src="'.$this->_generic->getProtocol().'://'.$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("coreJsDyn").'ZeroClipboard/ZeroClipboard.js"></script>'."\n". t(1).'<script type="text/javascript">'."\n". t(2).'window.slsBuild.xml = "'.htmlentities(str_replace(array('"',"\n"),array('\"',''),$this->_xml),ENT_COMPAT,"UTF-8").'";'."\n". t(1).'</script>'."\n". t(1).'<!-- /Sls developer Toolbar -->'."\n\n". t(1).'</head>', $html); echo $html; $this->_generic->logTime($this->_generic->monitor($this->_generic->_time_checkpoint),"Parsing HTML","","HTML Parsing"); } }