/** * Constructor. * initializes the page if the id is given. * * @param integer $id DB id * @return void * @access public */ function __construct($id = 0) { $this->_remindedEditors = new CMS_stack(); $this->_lastReminder = new CMS_date(); $this->_lastFileCreation = new CMS_date(); if ($id) { if (!SensitiveIO::isPositiveInteger($id)) { $this->raiseError("Id is not a positive integer"); return; } $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tid_pag='{$id}' and\n\t\t\t\t\tresource_pag = id_res and\n\t\t\t\t\tstatus_res = id_rs\n\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { $data = $q->getArray(); $this->_pageID = $id; $this->_remindedEditors->setTextDefinition($data["remindedEditorsStack_pag"]); $this->_lastReminder->setFromDBValue($data["lastReminder_pag"]); $this->_templateID = $data["template_pag"]; $this->_lastFileCreation->setFromDBValue($data["lastFileCreation_pag"]); $this->_pageURL = $data["url_pag"]; $this->_protected = $data["protected_pag"] ? true : false; $this->_https = $data["https_pag"] ? true : false; //initialize super-class parent::__construct($data); } else { //display this error only if we are in HTTP mode (not cli) because it is only relevant in this mode if (!defined('APPLICATION_EXEC_TYPE') || APPLICATION_EXEC_TYPE == 'http') { $this->raiseError("Unknown ID :" . $id . ' from ' . io::getCallInfos(3)); } else { $this->raiseError(); } } } else { //initialize super-class parent::__construct(); } }
/** * Gets alias by its internal ID * * @param integer $id The DB ID of the alias to get * @return CMS_resource_cms_aliases or false if not found * @access public * @static */ static function getByID($id, $reset = false) { if (!SensitiveIO::isPositiveInteger($id)) { CMS_grandFather::raiseError("Id must be positive integer : " . $id . ' - ' . io::getCallInfos()); return false; } static $aliases; if (isset($aliases[$id]) && !$reset) { return $aliases[$id]; } $aliases[$id] = new CMS_resource_cms_aliases($id); /*if ($aliases[$id]->hasError()) { $aliases[$id] = false; }*/ return $aliases[$id]; }
/** * Automne autoload handler * * @return true * @access public */ static function autoload($classname) { static $classes, $modules; if (!isset($classes)) { $classes = array('cms_stack' => PATH_PACKAGES_FS . '/common/stack.php', 'cms_contactdata' => PATH_PACKAGES_FS . '/common/contactdata.php', 'cms_contactdatas_catalog' => PATH_PACKAGES_FS . '/common/contactdatascatalog.php', 'cms_href' => PATH_PACKAGES_FS . '/common/href.php', 'cms_log_catalog' => PATH_PACKAGES_FS . '/common/logcatalog.php', 'cms_log' => PATH_PACKAGES_FS . '/common/log.php', 'cms_languagescatalog' => PATH_PACKAGES_FS . '/common/languagescatalog.php', 'cms_actions' => PATH_PACKAGES_FS . '/common/actions.php', 'cms_action' => PATH_PACKAGES_FS . '/common/action.php', 'cms_search' => PATH_PACKAGES_FS . '/common/search.php', 'cms_contactdatas_catalog' => PATH_PACKAGES_FS . '/common/contactdatascatalog.php', 'cms_email' => PATH_PACKAGES_FS . '/common/email.php', 'cms_emailscatalog' => PATH_PACKAGES_FS . '/common/emailscatalog.php', 'cms_query' => PATH_PACKAGES_FS . '/common/query.php', 'cms_date' => PATH_PACKAGES_FS . '/common/date.php', 'cms_language' => PATH_PACKAGES_FS . '/common/language.php', 'cms_oembed' => PATH_PACKAGES_FS . '/common/oembed.php', 'sensitiveio' => PATH_PACKAGES_FS . '/common/sensitiveio.php', 'io' => PATH_PACKAGES_FS . '/common/sensitiveio.php', 'cms_context' => PATH_PACKAGES_FS . '/dialogs/context.php', 'cms_wysiwyg_toolbar' => PATH_PACKAGES_FS . '/dialogs/toolbar.php', 'cms_dialog' => PATH_PACKAGES_FS . '/dialogs/dialog.php', 'cms_jsdialog' => PATH_PACKAGES_FS . '/dialogs/jsdialog.php', 'cms_view' => PATH_PACKAGES_FS . '/dialogs/view.php', 'cms_submenus' => PATH_PACKAGES_FS . '/dialogs/submenus.php', 'cms_submenu' => PATH_PACKAGES_FS . '/dialogs/submenu.php', 'cms_dialog_listboxes' => PATH_PACKAGES_FS . '/dialogs/dialoglistboxes.php', 'cms_dialog_href' => PATH_PACKAGES_FS . '/dialogs/dialoghref.php', 'cms_fileupload_dialog' => PATH_PACKAGES_FS . '/dialogs/fileupload.php', 'cms_loadingdialog' => PATH_PACKAGES_FS . '/dialogs/loadingDialog.php', 'cms_texteditor' => PATH_PACKAGES_FS . '/dialogs/texteditor.php', 'cms_stats' => PATH_PACKAGES_FS . '/dialogs/stats.php', 'cms_patch' => PATH_PACKAGES_FS . '/files/patch.php', 'cms_file' => PATH_PACKAGES_FS . '/files/filesManagement.php', 'cms_archive' => PATH_PACKAGES_FS . '/files/archive.php', 'cms_gzip_file' => PATH_PACKAGES_FS . '/files/archive-gzip.php', 'cms_tar_file' => PATH_PACKAGES_FS . '/files/archive-tar.php', 'cms_zip_file' => PATH_PACKAGES_FS . '/files/archive-zip.php', 'cms_fileupload' => PATH_PACKAGES_FS . '/files/fileupload.php', 'cms_cache' => PATH_PACKAGES_FS . '/files/cache.php', 'cms_image' => PATH_PACKAGES_FS . '/files/image.php', 'cms_module' => PATH_MODULES_FS . '/module.php', 'cms_modulescodes' => PATH_MODULES_FS . '/modulesCodes.php', 'cms_modulevalidation' => PATH_MODULES_FS . '/moduleValidation.php', 'cms_superresource' => PATH_MODULES_FS . '/super_resource.php', 'cms_modulecategory' => PATH_MODULES_FS . '/modulecategory.php', 'cms_modulescatalog' => PATH_MODULES_FS . '/modulescatalog.php', 'cms_modulecategories_catalog' => PATH_MODULES_FS . '/modulecategoriescatalog.php', 'cms_modulestags' => PATH_MODULES_FS . '/modulesTags.php', 'cms_moduleclientspace' => PATH_MODULES_FS . '/moduleclientspace.php', 'cms_superresource' => PATH_MODULES_FS . '/super_resource.php', 'cms_polymod' => PATH_MODULES_FS . '/polymod.php', 'cms_modulepolymodvalidation' => PATH_MODULES_FS . '/modulePolymodValidation.php', 'cms_module_export' => PATH_MODULES_FS . '/export.php', 'cms_module_import' => PATH_MODULES_FS . '/import.php', 'cms_rowscatalog' => PATH_MODULES_FS . '/standard/rowscatalog.php', 'cms_row' => PATH_MODULES_FS . '/standard/row.php', 'cms_block' => PATH_MODULES_FS . '/standard/block.php', 'cms_block_file' => PATH_MODULES_FS . '/standard/blockfile.php', 'cms_block_flash' => PATH_MODULES_FS . '/standard/blockflash.php', 'cms_block_image' => PATH_MODULES_FS . '/standard/blockimage.php', 'cms_blockscatalog' => PATH_MODULES_FS . '/standard/blockscatalog.php', 'cms_block_text' => PATH_MODULES_FS . '/standard/blocktext.php', 'cms_block_varchar' => PATH_MODULES_FS . '/standard/blockvarchar.php', 'cms_block_link' => PATH_MODULES_FS . '/standard/blocklink.php', 'cms_moduleclientspace_standard' => PATH_MODULES_FS . '/standard/clientspace.php', 'cms_moduleclientspace_standard_catalog' => PATH_MODULES_FS . '/standard/clientspacescatalog.php', 'cms_xmltag_admin' => PATH_MODULES_FS . '/standard/tags/admin.php', 'cms_xmltag_noadmin' => PATH_MODULES_FS . '/standard/tags/noadmin.php', 'cms_xmltag_edit' => PATH_MODULES_FS . '/standard/tags/edit.php', 'cms_xmltag_noedit' => PATH_MODULES_FS . '/standard/tags/noedit.php', 'cms_xmltag_title' => PATH_MODULES_FS . '/standard/tags/title.php', 'cms_xmltag_page' => PATH_MODULES_FS . '/standard/tags/page.php', 'cms_xmltag_website' => PATH_MODULES_FS . '/standard/tags/website.php', 'cms_xmltag_anchor' => PATH_MODULES_FS . '/standard/tags/anchor.php', 'cms_xmltag_header' => PATH_MODULES_FS . '/standard/tags/header.php', 'cms_xmltag_redirect' => PATH_MODULES_FS . '/standard/tags/redirect.php', 'cms_xmltag_xml' => PATH_MODULES_FS . '/standard/tags/xml.php', 'cms_xmltag_js_add' => PATH_MODULES_FS . '/standard/tags/js-add.php', 'cms_xmltag_css_add' => PATH_MODULES_FS . '/standard/tags/css-add.php', 'cms_linxescatalog' => PATH_PACKAGES_FS . '/pageContent/linxescatalog.php', 'cms_xml2array' => PATH_PACKAGES_FS . '/pageContent/xml2Array.php', 'cms_linx' => PATH_PACKAGES_FS . '/pageContent/linx.php', 'cms_linxcondition' => PATH_PACKAGES_FS . '/pageContent/linxcondition.php', 'cms_linxdisplay' => PATH_PACKAGES_FS . '/pageContent/linxdisplay.php', 'cms_linxnodespec' => PATH_PACKAGES_FS . '/pageContent/linxnodespec.php', 'cms_xmltag' => PATH_PACKAGES_FS . '/pageContent/xmltag.php', 'cms_xmlparser' => PATH_PACKAGES_FS . '/pageContent/xmlparser.php', 'cms_domdocument' => PATH_PACKAGES_FS . '/pageContent/xmldomdocument.php', 'cms_array2xml' => PATH_PACKAGES_FS . '/pageContent/array2Xml.php', 'cms_array2csv' => PATH_PACKAGES_FS . '/pageContent/array2csv.php', 'processmanager' => PATH_PACKAGES_FS . '/scripts/backgroundScript/processmanager.php', 'backgroundscript' => PATH_PACKAGES_FS . '/scripts/backgroundScript/backgroundscript.php', 'cms_scriptsmanager' => PATH_PACKAGES_FS . '/scripts/scriptsmanager.php', 'cms_tree' => PATH_PACKAGES_FS . '/tree/tree.php', 'cms_page' => PATH_PACKAGES_FS . '/tree/page.php', 'cms_pagetemplatescatalog' => PATH_PACKAGES_FS . '/tree/pagetemplatescatalog.php', 'cms_pagetemplate' => PATH_PACKAGES_FS . '/tree/pagetemplate.php', 'cms_websitescatalog' => PATH_PACKAGES_FS . '/tree/websitescatalog.php', 'cms_website' => PATH_PACKAGES_FS . '/tree/website.php', 'cms_profile_user' => PATH_PACKAGES_FS . '/user/profileuser.php', 'cms_profile' => PATH_PACKAGES_FS . '/user/profile.php', 'cms_modulecategoriesclearances' => PATH_PACKAGES_FS . '/user/profilemodulecategoriesclearances.php', 'cms_profile_userscatalog' => PATH_PACKAGES_FS . '/user/profileuserscatalog.php', 'cms_profile_usersgroupscatalog' => PATH_PACKAGES_FS . '/user/profileusersgroupscatalog.php', 'cms_profile_usersgroup' => PATH_PACKAGES_FS . '/user/profileusersgroup.php', 'cms_session' => PATH_PACKAGES_FS . '/user/session.php', 'cms_auth' => PATH_PACKAGES_FS . '/user/auth.php', 'cms_resource' => PATH_PACKAGES_FS . '/workflow/resource.php', 'cms_resourcestatus' => PATH_PACKAGES_FS . '/workflow/resourcestatus.php', 'cms_resourcevalidationinfo' => PATH_PACKAGES_FS . '/workflow/resourcevalidationinfo.php', 'cms_resourcevalidation' => PATH_PACKAGES_FS . '/workflow/resourcevalidation.php', 'cms_resourcevalidationscatalog' => PATH_PACKAGES_FS . '/workflow/resourcevalidationscatalog.php', 'fckeditor' => PATH_MAIN_FS . '/fckeditor/fckeditor.php', 'ckeditor' => PATH_MAIN_FS . '/ckeditor/ckeditor.php', 'jsmin' => PATH_MAIN_FS . '/jsmin/jsmin.php', 'cssmin' => PATH_MAIN_FS . '/cssmin/cssmin.php', 'phpexcel' => PATH_MAIN_FS . '/phpexcel/PHPExcel.php', 'phpexcel_iofactory' => PATH_MAIN_FS . '/phpexcel/PHPExcel/IOFactory.php', 'lessc' => PATH_MAIN_FS . '/lessphp/lessc.inc.php'); } $file = ''; if (isset($classes[strtolower($classname)])) { $file = $classes[strtolower($classname)]; } elseif (strpos($classname, 'CMS_module_') === 0) { //modules lazy loading if (file_exists(PATH_MODULES_FS . '/' . substr($classname, 11) . '.php')) { $file = PATH_MODULES_FS . '/' . substr($classname, 11) . '.php'; } else { //here, we need to stop return false; } } if (!$file) { //Zend Framework if (substr(strtolower($classname), 0, 5) == 'zend_') { chdir(PATH_MAIN_FS); require_once PATH_MAIN_FS . '/Zend/Loader/Autoloader.php'; if (!Zend_Loader_Autoloader::autoload($classname)) { return false; } /*only for stats*/ if (STATS_DEBUG) { CMS_stats::$filesLoaded++; } if (STATS_DEBUG && VIEW_SQL) { CMS_stats::$filesTable[] = array('class' => $classname, 'from' => io::getCallInfos(3)); CMS_stats::$memoryTable[] = array('class' => $classname, 'memory' => memory_get_usage(), 'peak' => memory_get_peak_usage()); } return true; } //try modules Autoload if (!isset($modules)) { $modules = CMS_modulesCatalog::getAll("id"); } $polymodDone = false; foreach ($modules as $codename => $module) { if ((!$polymodDone && $module->isPolymod() || !$module->isPolymod()) && method_exists($module, 'load')) { if (!$polymodDone && $module->isPolymod()) { $polymodDone = true; } $file = $module->load($classname); } elseif ($polymodDone && $module->isPolymod()) { unset($modules[$codename]); } if ($file) { break; } } //in case this website do not use any polymod module if (!$polymodDone && !$file) { require_once PATH_MODULES_FS . '/polymod.php'; $file = CMS_polymod::load($classname); } } if ($file) { require_once $file; /*only for stats*/ if (defined('STATS_DEBUG') && defined('VIEW_SQL')) { if (STATS_DEBUG) { CMS_stats::$filesLoaded++; } if (STATS_DEBUG && VIEW_SQL) { CMS_stats::$filesTable[] = array('file' => $file, 'class' => $classname, 'from' => io::getCallInfos(3)); CMS_stats::$memoryTable[] = array('file' => $file, 'class' => $classname, 'memory' => memory_get_usage(), 'peak' => memory_get_peak_usage()); } } } }
/** * Constructor. * Initializes the connection and launches the query. * * @param string $sql The sql statement * @param string $dsn The database dsn * @param string $user The database user * @param string $pass The database password * @return void * @access public */ public function __construct($sql = '', $dsn = APPLICATION_DB_DSN, $user = APPLICATION_DB_USER, $pass = APPLICATION_DB_PASSWORD) { $this->_sql = trim($sql); $this->_connect($dsn, $user, $pass); if ($this->_sql && $this->_db) { /*only for stats*/ if (STATS_DEBUG) { $time_start = CMS_stats::getmicrotime(); } if (preg_match("#^(insert|update)#i", $this->_sql)) { $this->_numRows = $this->_db->exec($this->_sql); if (preg_match("#^insert#i", $this->_sql)) { $this->_lastInsertedID = $this->_db->lastInsertId(); } $errorInfos = $this->_db->errorInfo(); if (isset($errorInfos[2])) { $clean_sql = str_replace("\n", "", $this->_sql); $clean_sql = preg_replace("#\t+#", " ", $clean_sql); $errorInfo = isset($errorInfos[2]) ? $errorInfos[2] : 'No error returned'; $this->raiseError('Database querying failed : ' . $errorInfo . "\nQuery : " . $clean_sql); } } else { $this->_result = $this->_db->query($this->_sql); if ($this->_result) { $this->_numRows = $this->_result->rowCount(); } else { $clean_sql = str_replace("\n", "", $this->_sql); $clean_sql = preg_replace("#\t+#", " ", $clean_sql); $errorInfos = $this->_db->errorInfo(); $errorInfo = isset($errorInfos[2]) ? $errorInfos[2] : 'No error returned'; $this->raiseError('Database querying failed : ' . $errorInfo . "\nQuery : " . $clean_sql . "\nFrom : " . io::getCallInfos(3)); } } /*only for stats*/ if (STATS_DEBUG) { $currenttime = CMS_stats::getmicrotime(); $time = $currenttime - $time_start; if (VIEW_SQL) { CMS_stats::$sqlTable[] = array('sql' => $this->_sql, 'time' => $time, 'current' => $currenttime - CMS_stats::$timeStart, 'from' => io::getCallInfos(3), 'memory' => memory_get_usage(), 'peak' => memory_get_peak_usage()); } CMS_stats::$sqlNbRequests++; CMS_stats::$totalTime += $time; } } }
/** * get an object field * * @param integer $fieldID : the field to get. If empty, return an array of all objects values * @return mixed : the object field or an array of the object fields * @access public */ function objectValues($fieldID = '') { if (!$fieldID) { return $this->_objectValues; } else { if (!isset($this->_objectValues[$fieldID])) { global $cms_language; $language = $cms_language ? $cms_language : CMS_languagesCatalog::getDefaultLanguage(); $this->raiseError('Object field with ID ' . $fieldID . ' does not exists as a field of object ' . $this->getFieldLabel($language) . ' (' . $this->_objectID . ') - ' . io::getCallInfos(3)); //return dummy object field (correct bug 536) return new CMS_poly_object($this->_objectID); } return $this->_objectValues[$fieldID]; } }
/** * Does an object exists with given parameters * this method is use by fromArray import method to know if an imported object already exist or not * * @param string $module The module codename to check * @param string $uuid The object uuid to check * @return mixed : integer id if exists, false otherwise * @access public */ static function objectExists($module, $uuid) { if (!$module) { CMS_grandFather::raiseError("module must be set"); return false; } if (!$uuid) { CMS_grandFather::raiseError("uuid must be set " . io::getCallInfos(3)); return false; } $q = new CMS_query("\n\t\t\tselect \n\t\t\t\tid_mod\n\t\t\tfrom \n\t\t\t\tmod_object_definition \n\t\t\twhere\n\t\t\t\tuuid_mod='" . io::sanitizeSQLString($uuid) . "'\n\t\t\t\tand module_mod='" . io::sanitizeSQLString($module) . "'\n\t\t"); if ($q->getNumRows()) { return $q->getValue('id_mod'); } return false; }
/** * Constructor. * Build the language by its code * * @return void * @access public */ function __construct($code = '') { static $languageObject; if ($code) { if (!isset($languageObject[$code])) { // Get Language label $sql = "\n\t\t\t\t\tselect \n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\tlanguages\n\t\t\t\t\twhere\n\t\t\t\t\t\tcode_lng='" . SensitiveIO::sanitizeSQLString($code) . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { $data = $q->getArray(); $this->_code = $code; $this->_label = $data["label_lng"]; $this->_dateFormat = $data["dateFormat_lng"]; $this->_availableForBackoffice = $data["availableForBackoffice_lng"]; $this->_modulesDenied = explode(';', $data["modulesDenied_lng"]); } else { $this->raiseError("Unknown code: " . $code . ' - ' . io::getCallInfos(3)); } $languageObject[$code] = $this; } else { $this->_code = $languageObject[$code]->_code; $this->_label = $languageObject[$code]->_label; $this->_dateFormat = $languageObject[$code]->_dateFormat; $this->_availableForBackoffice = $languageObject[$code]->_availableForBackoffice; $this->_modulesDenied = $languageObject[$code]->_modulesDenied; } } }
/** * Returns a queried CMS_page value * Static function. * * @param mixed $id The DB ID of the wanted CMS_page or or "self" or the page codename ($currentPageId is mandatory in this case) * @param string $type The value type to get * @param boolean $public : public value or edited value (default : public) * @param integer $currentPageId : the page reference (required if first parameter is not a page Id) * @return CMS_page value or false on failure to find it * @access public */ static function getPageValue($id, $type, $public = true, $currentPageId = null) { static $pagesInfos; //if no current page given, try to get it from constant if (!io::isPositiveInteger($currentPageId) && defined('CURRENT_PAGE') && io::isPositiveInteger(CURRENT_PAGE)) { $currentPageId = CURRENT_PAGE; } if (!SensitiveIO::isPositiveInteger($id)) { if ($id == 'self' && SensitiveIO::isPositiveInteger($currentPageId)) { $id = $currentPageId; } elseif ($id == 'father' && SensitiveIO::isPositiveInteger($currentPageId)) { $id = CMS_tree::getFather($currentPageId); } elseif (SensitiveIO::isPositiveInteger($currentPageId) && strtolower(io::sanitizeAsciiString($id)) == $id) { return CMS_tree::getPageCodenameValue($id, $currentPageId, $type); } elseif ($type != 'exists') { CMS_grandFather::raiseError("Page id must be positive integer : " . print_r(func_get_args(), true) . ' - ' . io::getCallInfos(3)); return false; } else { return false; } } if (!isset($pagesInfos[$id][$type][$public])) { $page = CMS_tree::getPageByID($id); if (!$page) { $return = false; } else { switch ($type) { case 'exists': $return = $page->getPublication() == RESOURCE_PUBLICATION_PUBLIC ? true : false; break; case 'url': $return = $page->getURL(); break; case 'printurl': $return = $page->getURL(true); break; case 'title': $return = $page->getTitle($public); break; case 'link': case 'linktitle': $return = $page->getLinkTitle($public); break; case 'id': $return = $page->getID(); break; case 'website': $return = $page->getWebsite()->getID(); break; case 'codename': case 'keywords': case 'description': case 'category': case 'author': case 'replyto': case 'copyright': case 'language': case 'robots': case 'pragma': case 'refresh': $method = 'get' . ucfirst($type); $return = $page->{$method}($public); break; case 'metas': $return = $page->getMetas($public); break; case 'level': $return = sizeof(CMS_tree::getLineage($page->getWebsite()->getRoot()->getID(), $page->getID(), false, $public)); break; default: CMS_grandFather::raiseError("Unknown type value to get : " . $type); $return = false; break; } $pagesInfos[$id][$type][$public] = $return; } } return $pagesInfos[$id][$type][$public]; }