public static function view($removefieldset = false) { if (!self::$_started) { return; } self::$timeEnd = self::getmicrotime(); $time = sprintf('%.5f', self::$timeEnd - self::$timeStart); $files = sprintf('%.5f', self::$filesTime); $rapportSQL = sprintf('%.2f', 100 * self::$totalTime / $time); $rapportPHP = 100 - $rapportSQL; $memoryPeak = round(memory_get_peak_usage() / 1048576, 3); $content = 'File ' . $_SERVER['SCRIPT_NAME'] . "\n" . 'Loaded in ' . $time . ' seconds' . "\n" . 'Loaded PHP files : ' . self::$filesLoaded . "\n" . 'SQL requests : ' . sprintf('%.5f', self::$totalTime) . ' seconds (' . self::$sqlNbRequests . ' requests)' . "\n" . '% SQL/PHP : ' . $rapportSQL . ' / ' . $rapportPHP . ' %' . "\n" . 'Memory Peak : ' . $memoryPeak . 'Mo' . "\n"; if (function_exists('xdebug_get_profiler_filename') && xdebug_get_profiler_filename()) { $content .= 'XDebug Profile : ' . xdebug_get_profiler_filename() . "\n"; } if (function_exists('xdebug_get_profiler_filename') && xdebug_get_tracefile_name()) { $content .= 'XDebug Trace : ' . xdebug_get_tracefile_name() . "\n"; } $content .= 'User : '******' (' . CMS_session::getUserId() . ')' : 'none') . "\n"; $content .= 'Session Id ' . Zend_Session::getId() . "\n"; //$content .= 'Current page '.CMS_session::getPageID()."\n"; if (VIEW_SQL && $_SERVER["SCRIPT_NAME"] != PATH_ADMIN_WR . '/stat.php') { $stat = array('stat_time_start' => self::$timeStart, 'stat_time_end' => self::$timeEnd, 'stat_total_time' => self::$totalTime, 'stat_sql_nb_requests' => self::$sqlNbRequests, 'stat_sql_table' => self::$sqlTable, 'stat_content_name' => basename($_SERVER["SCRIPT_NAME"]), 'stat_files_table' => self::$filesTable, 'stat_memory_table' => self::$memoryTable, 'stat_memory_peak' => $memoryPeak, 'stat_files_loaded' => self::$filesLoaded); $statName = 'stat_' . md5(rand()); //save stats to cache (for 10 min) $cache = new CMS_cache($statName, 'atm-stats', 600, false); if ($cache) { $cache->save($stat); } } $content = !$removefieldset ? '<fieldset style="width:200px;" class="atm-debug"><legend>Debug Statistics</legend><pre>' . $content . '</pre>' : 'Debug Statistics :' . "\n" . $content; if (isset($statName)) { $content .= '<a href="' . PATH_ADMIN_WR . '/stat.php?stat=' . $statName . '" target="_blank">View statistics detail</a>'; } //end xhprof profiling if (defined('APPLICATION_ENABLE_PROFILING') && APPLICATION_ENABLE_PROFILING && function_exists('xhprof_disable')) { $xhprof_data = xhprof_disable(); include_once APPLICATION_XHPROF_ROOT_FS . "/xhprof_lib/utils/xhprof_lib.php"; include_once APPLICATION_XHPROF_ROOT_FS . "/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $profileName = md5($_SERVER['REQUEST_URI']); $run_id = $xhprof_runs->save_run($xhprof_data, md5($_SERVER['REQUEST_URI'])); $content .= '<br /><a href="' . APPLICATION_XHPROF_URI . 'xhprof_html/index.php?run=' . $run_id . '&source=' . $profileName . '" target="_blank">View profiling detail</a>'; } $content .= !$removefieldset ? '</fieldset>' : ''; return $content; }
/** * Raises an error. Shows it to the screen * Deprecated, use raiseError instead * @param string $errorMessage the error message. * @param boolean $encodeOutput, does the screen output should be encoded (default : false) * @return void * @access public */ public function _raiseError($errorMessage, $encodeOutput = false, $error = true) { static $errorNumber; $systemDebug = !defined('SYSTEM_DEBUG') ? true : SYSTEM_DEBUG; if (isset($this) && isset($this->_debug) && $this->_debug === NULL) { $this->_debug = $systemDebug; } if ($errorMessage) { //second condition are for static calls (made by static methods) if (!defined('APPLICATION_EXEC_TYPE') || APPLICATION_EXEC_TYPE == 'http' && (!isset($this) && $systemDebug || isset($this) && isset($this->_debug) && $this->_debug)) { $backTrace = $backTraceLink = ''; if (version_compare(phpversion(), "5.2.5", "<")) { $bt = @array_reverse(debug_backtrace()); } else { $bt = @array_reverse(debug_backtrace(false)); } $backtrace = array('summary' => sensitiveIO::printBackTrace($bt), 'backtrace' => @print_r($bt, true)); $backtraceName = 'bt_' . md5(rand()); $backTraceLink = PATH_ADMIN_WR . '/backtrace.php?bt=' . $backtraceName; //save backtrace to cache (for 10 min) $cache = new CMS_cache($backtraceName, 'atm-backtrace', 600, false); if ($cache) { $cache->save($backtrace); } unset($backtrace, $cache, $bt); //append error to current view $view = CMS_view::getInstance(); $outputMessage = $encodeOutput ? io::htmlspecialchars($errorMessage) : $errorMessage; $view->addError(array('error' => $outputMessage, 'backtrace' => $backTraceLink)); } //second condition are for static calls (made by static methods) if (!isset($this) || !isset($this->_log) || $this->_log) { if (@file_put_contents(PATH_MAIN_FS . '/' . self::ERROR_LOG, date("Y-m-d H:i:s", time()) . '|' . APPLICATION_EXEC_TYPE . '|' . $errorMessage . "\n", FILE_APPEND) !== false) { CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . '/' . self::ERROR_LOG); } else { die('<pre><b>' . CMS_view::SYSTEM_LABEL . ' ' . AUTOMNE_VERSION . ' error : /automne dir is not writable' . "</b></pre>\n"); } } } //must be at the end because it interferes with the static calls conditions above if ($error && isset($this)) { $this->_errRaised = true; } }
/** * Delete object and values. * If object is a primary resource, this deletion is submitted to validation and an email is sent to validators. * * @param boolean $hardDelete : completely destroy object and associated resource if any. After this, this object will no longer exists at all. Default : false. * /!\ if object is a primary resource, no validation will be queried to validators, object will be directly destroyed from all locations. /!\ * @return boolean true on success, false on failure * @access public */ function delete($hardDelete = false) { global $cms_user; //get Object definition $objectDef = $this->getObjectDefinition(); //get module codename $polyModuleCodename = $objectDef->getValue('module'); //if object is not a primary resource if ($this->_objectResourceStatus != 1 || $hardDelete) { $forceSecondaryRessourcePublication = false; if ($this->_objectResourceStatus == 2 && !$hardDelete) { //if this object is a secondary resource, primary items which uses this object must be updated //get all primary resource associated $primaryItems = CMS_poly_object_catalog::getPrimaryItemsWhichUsesSecondaryItem($this->_ID, true, false); if ($primaryItems) { foreach ($primaryItems as $primaryItem) { $primaryItem->writeToPersistence(); } } else { $forceSecondaryRessourcePublication = true; } } //if object is not a secondary resource, delete public datas, else preserve it : it will be deleted on primary resource validation if ($this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication || $hardDelete) { //delete datas from public locations CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_DEVNULL); if (!$hardDelete) { //mark item as deleted CMS_modulePolymodValidation::markDeletedItem($this->getID()); } else { //destroy poly_object reference $sql = "delete from mod_object_polyobjects where id_moo = '" . $this->getID() . "'"; new CMS_query($sql); } } if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) { $modulesCodes = new CMS_modulesCodes(); //add a call to all modules for before validation specific treatment $modulesCodes->getModulesCodes(MODULE_TREATMENT_BEFORE_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete')); } if (!$hardDelete) { //move resource datas from edited to deleted location CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DELETED); } else { //delete datas from edited locations CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DEVNULL); } if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) { //add a call to all modules for after validation specific treatment $modulesCodes->getModulesCodes(MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete')); } if ($this->_objectResourceStatus == 1 && $hardDelete) { //delete associated resource parent::destroy(); } //Log action $log = new CMS_log(); $language = $cms_user->getLanguage(); $log->logMiscAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $polyModuleCodename); if ($hardDelete) { unset($this); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename)); CMS_cache::clearTypeCache('polymod'); return true; } else { //change the article proposed location and send emails to all the validators if ($this->setProposedLocation(RESOURCE_LOCATION_DELETED, $cms_user)) { parent::writeToPersistence(); if (APPLICATION_ENFORCES_WORKFLOW) { if (!NO_APPLICATION_MAIL) { //get editors $editors = $this->getEditors(); $editorsIds = array(); foreach ($editors as $editor) { $editorsIds[] = $editor->getUserId(); } $validators = CMS_profile_usersCatalog::getValidators($polyModuleCodename); foreach ($validators as $validator) { //add script to send email for validator if needed CMS_scriptsManager::addScript($polyModuleCodename, array('task' => 'emailNotification', 'object' => $this->getID(), 'validator' => $validator->getUserId(), 'type' => 'delete', 'editors' => $editorsIds)); } //then launch scripts execution CMS_scriptsManager::startScript(); } } else { $validation = new CMS_resourceValidation($polyModuleCodename, RESOURCE_EDITION_LOCATION, $this); $mod = CMS_modulesCatalog::getByCodename($polyModuleCodename); $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT); } //Log action $log = new CMS_log(); $language = $cms_user->getLanguage(); $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, $polyModuleCodename, $this->getStatus(), 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $this); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename)); CMS_cache::clearTypeCache('polymod'); return true; } else { return false; } } }
if (!$field->hasError()) { if (!$field->setValue("indexable", $_POST["indexable"])) { $cms_message .= "\n" . $cms_language->getMessage(MESSAGE_FORM_ERROR_MALFORMED_FIELD, array($cms_language->getMessage(MESSAGE_PAGE_FIELD_FRONTEND))); } else { //save the data $field->writeToPersistence(); $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); } } break; case 'deleteObject': if ($object->destroy()) { unset($object); unset($objectID); //unset fields catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'fields')); $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); } else { $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_DELETE_OBJECT_ERROR); } break; case "delete": $field = new CMS_poly_object_field($_POST["field"]); if (!$field->hasError() && $field->destroy()) { //then reload object if (sensitiveIO::IsPositiveInteger($objectID)) { $object = new CMS_poly_object_definition($objectID); } $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); } else { $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_DELETE_FIELD_ERROR);
/** * Moves position of a category in list, with given offset * * @access public * @param CMS_moduleCategory $siblingCategory * @param integer $moveOffset values 1 or -1 expected * @return boolean true on succes, false on failure */ static function moveCategoryOrder(&$siblingCategory, $moveOffset) { // Checks : pages must be CMS_moduleCategory and offset in (1, -1) if (!$siblingCategory instanceof CMS_moduleCategory) { CMS_grandFather::raiseError("Category to move not valid."); return false; } if (!SensitiveIO::isInSet($moveOffset, array(1, -1))) { CMS_grandFather::raiseError("Offset must be 1 or -1"); return false; } // Find the siblings to switch order $parent = $siblingCategory->getParent(); // Use this function to compact of siblings order if (!$parent instanceof CMS_moduleCategory || !CMS_moduleCategories_catalog::compactSiblingsOrder($parent->getID())) { CMS_grandFather::raiseError("Reordering siblings failed for category " . $parent->getID()); return false; } $siblings = $parent->getSiblings(); $sibling_to_move_left = false; $sibling_to_move_right = false; $lastSibling = false; foreach ($siblings as $aSibling) { if ($moveOffset == 1 && $lastSibling && $lastSibling->getID() == $siblingCategory->getID()) { $sibling_to_move_left = $aSibling; $sibling_to_move_right = $siblingCategory; break; } if ($moveOffset == -1 && $lastSibling && $aSibling->getID() == $siblingCategory->getID()) { $sibling_to_move_left = $siblingCategory; $sibling_to_move_right = $lastSibling; break; } $lastSibling = $aSibling; } if ($sibling_to_move_left && $sibling_to_move_right) { //move the siblings order $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\torder_mca=order_mca - 1\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $sibling_to_move_left->getID() . "'\n\t\t\t"; $q = new CMS_query($sql); $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\torder_mca=order_mca + 1\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $sibling_to_move_right->getID() . "'\n\t\t\t"; $q = new CMS_query($sql); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $sibling_to_move_right->getAttribute('moduleCodename'))); CMS_cache::clearTypeCache('polymod'); return true; } else { CMS_grandFather::raiseError("Move impossible (first or last sibling to move, or parent and sibling not related"); return false; } }
/** * Process the module validations : here, calls the parent function but before : * - Pass all the editors to remindedEditors * - computes all the pages that got to be regenerated. * * @param CMS_resourceValidation $resourceValidation The resource validation to process * @param integer $result The result of the validation process. See VALIDATION_OPTION constants * @param boolean $lastValidation Is this the last validation done in a load of multiple validations (or the only one) ? * if true, launch the regeneration script. * @return boolean true on success, false on failure to process * @access public */ function processValidation($resourceValidation, $result, $lastValidation = true) { if (!$resourceValidation instanceof CMS_resourceValidation) { $this->raiseError("ResourceValidation is not a valid CMS_resourceValidation object"); return false; } $editions = $resourceValidation->getEditions(); $page = $resourceValidation->getResource(); $publication_before = $page->getPublication(); $location_before = $page->getLocation(); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => MOD_STANDARD_CODENAME)); CMS_cache::clearTypeCache('polymod'); //Get the linked pages (it will be too late after parent processing if pages move outside USERSPACE //first add the page to regen $regen_pages = array(); if ($result == VALIDATION_OPTION_ACCEPT) { //2.1. If editions contains SIBLINGSORDER, all pages monitoring this one for father changes should regen if ($editions & RESOURCE_EDITION_SIBLINGSORDER || $editions & RESOURCE_EDITION_MOVE) { $temp_regen = CMS_linxesCatalog::getWatchers($page); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } } //2.2. If editions contains BASEDATA, all pages linked with this one should regen, and all monitoring its father if ($editions & RESOURCE_EDITION_BASEDATA || $editions & RESOURCE_EDITION_LOCATION) { $temp_regen = CMS_linxesCatalog::getLinkers($page); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } $father = CMS_tree::getFather($page); if ($father) { $temp_regen = CMS_linxesCatalog::getWatchers($father); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } } } //2.3. If editions contains CONTENT, only the page should be regen if ($editions & RESOURCE_EDITION_CONTENT) { //do nothing, the page is already in the array } $regen_pages = array_unique($regen_pages); } //call the parent function, but empty the reminded editors stack before if ($result == VALIDATION_OPTION_ACCEPT) { $stack = $page->getRemindedEditorsStack(); $stack->emptyStack(); $page->setRemindedEditorsStack($stack); $page->writeToPersistence(); } if (!parent::processValidation($resourceValidation, $result)) { return false; } if ($result == VALIDATION_OPTION_REFUSE && ($editions & RESOURCE_EDITION_SIBLINGSORDER || $editions & RESOURCE_EDITION_MOVE)) { //validation was refused, move the page to it's original position if ($editions & RESOURCE_EDITION_SIBLINGSORDER) { //revert page order to the old one CMS_tree::revertSiblingsOrder($page); } elseif ($editions & RESOURCE_EDITION_MOVE) { //revert page move to the old position CMS_tree::revertPageMove($page); } } //if validation was not accepted, nothing more to do if ($result != VALIDATION_OPTION_ACCEPT) { return true; } //re-instanciate the page object that have changed $page = CMS_tree::getPageByID($resourceValidation->getResourceID()); //page was moved out of userspace if ($editions & RESOURCE_EDITION_LOCATION) { if ($page->getLocation() != RESOURCE_LOCATION_USERSPACE && $location_before == RESOURCE_LOCATION_USERSPACE) { $page->deleteFiles(); CMS_linxesCatalog::deleteLinxes($page, true); if ($publication_before != RESOURCE_PUBLICATION_NEVERVALIDATED) { CMS_tree::detachPageFromTree($page, true); } CMS_tree::detachPageFromTree($page, false); //can't regenerate the page now if ($key = array_search($page->getID(), $regen_pages)) { unset($regen_pages[$key]); } } } elseif ($editions & RESOURCE_EDITION_BASEDATA && $publication_before != RESOURCE_PUBLICATION_NEVERVALIDATED && $page->getPublication() != RESOURCE_PUBLICATION_PUBLIC && CMS_tree::isInPublicTree($page)) { //detach page if publication dates changed and page no longer published $page->deleteFiles(); CMS_linxesCatalog::deleteLinxes($page, true); CMS_tree::detachPageFromTree($page, true); //can't regenerate the page now if ($key = array_search($page->getID(), $regen_pages)) { unset($regen_pages[$key]); } } else { //LINX_TREE RECORDS GENERATION //1. If the page has never been validated if ($publication_before == RESOURCE_PUBLICATION_NEVERVALIDATED) { //test the father's editions. If SIBLINGSORDER, only attach the page, else validate all of siblings orders $father = CMS_tree::getFather($page, true); $father_status = $father->getStatus(); if ($father_status->getEditions() & RESOURCE_EDITION_SIBLINGSORDER || $editions & RESOURCE_EDITION_MOVE) { CMS_tree::attachPageToTree($page, $father, true); } else { CMS_tree::publishSiblingsOrder($father); } } //2. If the page has been validated, attach it to the public tree $grand_root = CMS_tree::getRoot(); if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC && $page->getID() != $grand_root->getID()) { $father = CMS_tree::getFather($page); if ($editions & RESOURCE_EDITION_MOVE) { //publish page move CMS_tree::publishPageMove($page); //regenerate all pages which link moved page $temp_regen = CMS_linxesCatalog::getLinkers($page); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } //and regenerate all page who watch new father page $temp_regen = CMS_linxesCatalog::getWatchers($father); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } } else { CMS_tree::attachPageToTree($page, $father, true); } } //PAGE REGENERATION //3. the page itself (fromscratch needed). $launchRegnerator = $lastValidation && !$regen_pages ? true : false; CMS_tree::submitToRegenerator($page->getID(), true, $launchRegnerator); } $regen_pages = array_unique($regen_pages); //2. the linked pages CMS_tree::submitToRegenerator($regen_pages, false, !$lastValidation); return true; }
if (is_array($files)) { $content .= "Start update of Automne messages ...<br />"; foreach ($files as $file) { if (file_exists($file) && CMS_patch::executeSqlScript($file, true)) { CMS_patch::executeSqlScript($file); } else { $content .= 'Error during database update ! Script ' . $file . ' must be executed manualy<br/>'; } } $content .= "Automne messages updated.<br /><br />"; } //clear caches $content .= "Clean Automne cache.<br /><br />"; CMS_cache::clearTypeCache('polymod'); CMS_cache::clearTypeCache('atm-polymod-structure'); CMS_cache::clearTypeCache('text/javascript'); CMS_cache::clearTypeCache('text/css'); CMS_cache::clearTypeCache('atm-backtrace'); //compile polymod definitions CMS_polymod::compileDefinitions(); $content .= "Objects definitions recompilations is done.<br />"; //regenerate pages $content .= "<br />Launch pages regeneration."; CMS_tree::regenerateAllPages(true); $content .= '</pre>'; if (!$included) { $view->setContent($content); $view->show(); } else { echo $content; }
// $Id: backtrace.php,v 1.3 2010/03/08 16:41:17 sebastien Exp $ /** * PHP page : Backtrace debug page * * @package Automne * @subpackage admin * @author Sébastien Pauchet <*****@*****.**> */ require_once dirname(__FILE__) . '/../../cms_rc_admin.php'; $dialog = new CMS_dialog(); $dialog->setTitle('Automne :: Debug :: BackTrace', 'pic_meta.gif'); $backTraceName = $_GET['bt']; if (!$backTraceName) { $content = 'Cannot backtrace, datas missing ...'; } else { //get backtrace from cache object $cache = new CMS_cache($backTraceName, 'atm-backtrace', 600, false); //load cache content if (!$cache->exist() || !($datas = $cache->load())) { $content = 'Cannot backtrace, datas missing ...'; } else { $content = ' <h3>Backtrace:</h3> ' . $datas['summary'] . '<br /> <h3>Backtrace Detail:</h3> <pre>' . io::htmlspecialchars($datas['backtrace']) . '</pre> '; } } $dialog->setContent($content); $dialog->show();
/** * Destroy this object in DB * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_ID) { //first delete old polyobject references $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_polyobjects\n\t\t\t\twhere\n\t\t\t\t\tobject_type_id_moo = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_polyobjects for object : " . $this->_ID); return false; } //second delete object label and description if (sensitiveIO::IsPositiveInteger($this->getValue("labelID"))) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->destroy(); } if (sensitiveIO::IsPositiveInteger($this->getValue("descriptionID"))) { $description = new CMS_object_i18nm($this->getValue("labelID")); $description->destroy(); } //third, delete object definition datas $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mod = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_definition for object : " . $this->_ID); return false; } //unset objects catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'object')); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_objectValues["module"])); CMS_cache::clearTypeCache('polymod'); } unset($this); return true; }
/** * Retrieve current media datas from provider * * @return boolean * @access protected */ protected function _retrieveDatas() { if ($this->_datas) { return true; } //load provider if (!$this->_getProvider()) { return false; } //set cache lifetime $lifetime = 86400; //(default : 24 hours) //create cache id from files, compression status and last time files access $cacheId = md5(serialize(array('url' => $this->_url, 'maxwidth' => io::isPositiveInteger($this->_maxwidth) ? $this->_maxwidth : '', 'maxheight' => io::isPositiveInteger($this->_maxheight) ? $this->_maxheight : ''))); //create cache object $cache = new CMS_cache($cacheId, 'oembed', $lifetime, false); $datas = ''; if (!$cache->exist() || !($datas = $cache->load())) { try { $client = new Zend_Http_Client(); $client->setUri($this->getProvider()); //HTTP config $httpConfig = array('maxredirects' => 5, 'timeout' => 10, 'useragent' => 'Mozilla/5.0 (compatible; Automne/' . AUTOMNE_VERSION . '; +http://www.automne-cms.org)'); if (defined('APPLICATION_PROXY_HOST') && APPLICATION_PROXY_HOST) { $httpConfig['adapter'] = 'Zend_Http_Client_Adapter_Proxy'; $httpConfig['proxy_host'] = APPLICATION_PROXY_HOST; if (defined('APPLICATION_PROXY_PORT') && APPLICATION_PROXY_PORT) { $httpConfig['proxy_port'] = APPLICATION_PROXY_PORT; } } $client->setConfig($httpConfig); $client->setParameterGet(array('url' => $this->_url, 'format' => 'json')); if (io::isPositiveInteger($this->_maxwidth)) { $client->setParameterGet('maxwidth', $this->_maxwidth); } if (io::isPositiveInteger($this->_maxheight)) { $client->setParameterGet('maxheight', $this->_maxheight); } $client->request(); $response = $client->getLastResponse(); } catch (Zend_Http_Client_Exception $e) { $this->raiseError('Error for url: ' . $this->_url . ' - ' . $e->getMessage()); } if (isset($response) && $response->isSuccessful()) { $jsonString = $response->getBody(); $datas = json_decode($jsonString, true); } else { if (isset($response)) { $this->raiseError('Error for oembed url: ' . $this->_url . ' (Provider: ' . $this->getProvider() . ') - ' . $response->getStatus() . ' - ' . $response->getMessage()); } else { $this->raiseError('Error for oembed url: ' . $this->_url . ' (Provider: ' . $this->getProvider() . ') - no response object'); } //create error datas $datas = array('error' => isset($response) ? $response->getStatus() : '500', 'cache_age' => 7200, 'type' => 'error'); } if ($cache) { if (isset($datas['cache_age']) && io::isPositiveInteger($datas['cache_age']) && $datas['cache_age'] != 86400) { //create cache object with new lifetime $cache = new CMS_cache($cacheId, 'oembed', $datas['cache_age'], false); } $cache->save($datas, array('type' => 'oembed', 'provider' => $this->getProvider())); } } if (!$datas) { return false; } $this->_datas = $datas; return true; }
} else { if (@file_put_contents(PATH_MAIN_FS . "/SUBVERSION", time()) !== false) { CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . "/SUBVERSION"); $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } } //remove JS and CSS cache if (!CMS_cache::clearTypeCache('text/javascript') || !CMS_cache::clearTypeCache('text/css')) { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'polymod-cache-reset': //remove polymod cache if (CMS_cache::clearTypeCache('polymod') && CMS_cache::clearTypeCache('atm-polymod-structure')) { $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'cache-reset': //remove polymod cache if (CMS_file::deltree(PATH_CACHE_FS, false)) { $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'update-db': ob_start();
/** * Writes the user Data into persistence (MySQL for now). * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { $this->writeProfileToPersistence(); $this->_contactData->writeToPersistence(); //if deleted, must set the login to nothing, so this login could be reused in the future if ($this->_deleted) { $this->_login = ''; } $sql_fields = "\n\t\t\tactive_pru='" . $this->_active . "',\n\t\t\tdeleted_pru='" . $this->_deleted . "',\n\t\t\tlogin_pru='" . SensitiveIO::sanitizeSQLString($this->_login) . "',\n\t\t\tpassword_pru='" . SensitiveIO::sanitizeSQLString($this->_password) . "',\n\t\t\tfirstName_pru='" . SensitiveIO::sanitizeSQLString($this->_firstName) . "',\n\t\t\tlastName_pru='" . SensitiveIO::sanitizeSQLString($this->_lastName) . "',\n\t\t\tcontactData_pru='" . SensitiveIO::sanitizeSQLString($this->_contactData->getId()) . "',\n\t\t\tlanguage_pru='" . SensitiveIO::sanitizeSQLString($this->_language->getCode()) . "',\n\t\t\tprofile_pru='" . SensitiveIO::sanitizeSQLString(parent::getId()) . "',\n\t\t\talerts_pru='" . SensitiveIO::sanitizeSQLString($this->_alerts->getTextDefinition()) . "',\n\t\t\tfavorites_pru='" . SensitiveIO::sanitizeSQLString(implode(',', $this->_favorites)) . "'\n\t\t"; if ($this->_userId) { $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tprofilesUsers\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_pru='" . $this->_userId . "'\n\t\t\t"; } else { $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofilesUsers\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if ($q->hasError()) { return false; } elseif (!$this->_userId) { $this->_userId = $q->getLastInsertedID(); } // Update validation catalog if ($this->_validationChange || $this->_deleted) { $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tprofilesUsers_validators\n\t\t\t\twhere\n\t\t\t\t\tuserId_puv='" . $this->_userId . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($this->_active) { //loop through validationClearances $validationClearances = parent::getValidationClearances(); $elements = $validationClearances->getElements(); $sql = ''; foreach ($elements as $value) { $sql .= $sql ? ', ' : ''; $sql .= "('" . $this->_userId . "' ,'" . $value[0] . "') "; } if ($sql) { $sql = "\n\t\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t\tprofilesUsers_validators (userId_puv, module_puv)\n\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t" . $sql; $q = new CMS_query($sql); } } $this->_validationChange = false; } //if deleted, must remove user from group list if ($this->_deleted) { $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tprofileUsersByGroup\n\t\t\t\twhere\n\t\t\t\t\tuserId_gu='" . $this->_userId . "'\n\t\t\t"; $q = new CMS_query($sql); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('resource' => 'users')); CMS_cache::clearTypeCache('polymod'); return true; }
/** * Destroy this object in DB * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_ID) { //first delete definition $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_plugin_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mowd = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_polyobjects for object : " . $this->_ID); return false; } //second delete object label and description if (sensitiveIO::IsPositiveInteger($this->getValue("labelID"))) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->destroy(); } if (sensitiveIO::IsPositiveInteger($this->getValue("descriptionID"))) { $description = new CMS_object_i18nm($this->getValue("labelID")); $description->destroy(); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => CMS_poly_object_catalog::getModuleCodenameForObjectType($this->getValue('objectID')))); CMS_cache::clearTypeCache('polymod'); //unset polymod structure in cache CMS_cache::clearTypeCache('atm-polymod-structure'); } unset($this); return true; }
* @package Automne * @subpackage frontend * @author Sébastien Pauchet <*****@*****.**> */ if (!isset($_REQUEST['atm-previz'])) { define('SYSTEM_DEBUG', false); } //Include all needed classes require_once dirname(__FILE__) . '/../cms_rc_frontend.php'; //Get RSS object $error = 0; $ttl = '1440'; $data = $label = $rssTitle = $description = $link = $categoriesTags = $copyrightTag = $emailTag = ''; $namespaces = 'xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom"'; $hash = md5(serialize($_REQUEST)); $cache = new CMS_cache($hash, 'polymod', 'auto', true); if ($cache->exist()) { //Get content from cache $content = $cache->load(); } else { $cache->start(); if (!isset($_REQUEST['id']) || !sensitiveIO::isPositiveInteger($_REQUEST['id'])) { $error = 1; } else { if (!CMS_poly_rss_definitions::exists($_REQUEST['id'])) { $error = 2; } else { $RSSDefinition = new CMS_poly_rss_definitions($_REQUEST['id']); if ($RSSDefinition->hasError()) { $error = 2; }
/** * Clear type cache using metas * * @param string $type : the cache type to clear * @param array $metas : the cache metas to clear * @param contant $mode : the zend cache constant to clean matching cache * Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG (default) * Zend_Cache::CLEANING_MODE_MATCHING_TAG * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG * @return boolean * @access public * @static */ function clearTypeCacheByMetas($type, $metas, $mode = Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG) { $type = io::sanitizeAsciiString($type); //Convert metas into tags $tags = CMS_cache::_createTags($metas); //CMS_grandFather::log('Clear cache '.$type.' for metas '.print_r($tags, true).' ('.io::getCallInfos().')'); $return = true; //check cache dir $cachedir = new CMS_file(PATH_CACHE_FS . '/' . $type, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); if ($cachedir->exists()) { //Frontend cache options $frontendOptions = array('lifetime' => null, 'caching' => true, 'automatic_cleaning_factor' => 10); //Backend cache options $backendOptions = array('cache_dir' => PATH_CACHE_FS . '/' . $type, 'cache_file_umask' => octdec(FILES_CHMOD), 'hashed_directory_umask' => octdec(DIRS_CHMOD), 'hashed_directory_level' => 1); // getting a Zend_Cache_Core object try { $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); } catch (Zend_Cache_Exception $e) { CMS_grandFather::raiseError($e->getMessage()); } if ($cache) { try { $return = $cache->clean($mode, $tags); } catch (Zend_Cache_Exception $e) { CMS_grandFather::raiseError($e->getMessage()); $return = false; } } else { $return = false; } } return $return; }
/** * Deletes a category from persistence * Must be called from static method * @see CMS_moduleCategories_catalog * * @access public * @return boolean */ function destroy() { if ($this->_categoryID > 0) { $err = 0; $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tmodulesCategories\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $this->_categoryID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $err++; $this->raiseError("Error deleting category."); } $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tmodulesCategories_i18nm\n\t\t\t\twhere\n\t\t\t\t\tcategory_mcl='" . $this->_categoryID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $err++; $this->raiseError("Error deleting category labels."); } $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tmodulesCategories_clearances\n\t\t\t\twhere\n\t\t\t\t\tcategory_mcc='" . $this->_categoryID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $err++; $this->raiseError("Error deleting category clearances."); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_moduleCodename)); CMS_cache::clearTypeCache('polymod'); unset($this); return $err <= 0; } return false; }
/** * Create datas from definition. * Parse definition and create PHP / HTML string * * @param serialized datas $rawDatas : The user specified parameters for the row * @param CMS_page $page The reference of the current page using block * @param boolean $public The needed precision for USERSPACE location (default : false) * @param constant $type The needed return type of datas (default : CMS_polymod_definition_parsing::OUTPUT_RESULT) * @return string The PHP / HTML datas * @access private */ protected function _createDatasFromDefinition($rawDatas, &$page, $visualizationMode, $type = CMS_polymod_definition_parsing::OUTPUT_RESULT) { $public = $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC; $parameters = $rawDatas ? array_merge($rawDatas, $this->_attributes) : $this->_attributes; // If no language parameter : set page language $parameters['language'] = isset($parameters['language']) && $parameters['language'] ? $parameters['language'] : $page->getLanguage(); $parameters = array('block_attributes' => $parameters, 'module' => $this->_attributes['module'], 'language' => $parameters['language'], 'pageID' => $page->getID(), 'public' => $public); $polymodParsing = new CMS_polymod_definition_parsing($this->_definition, true, CMS_polymod_definition_parsing::PARSE_MODE, $this->_attributes['module'], $visualizationMode); $content = $polymodParsing->getContent($type, $parameters); if (!$public) { return $content; } //Cache management $cacheHash = md5(serialize(array('definition' => $content, 'parameters' => $parameters))); $lifetime = isset($this->_attributes['cache']) ? $this->_attributes['cache'] : 'auto'; $content = CMS_cache::wrapCode($cacheHash, $content, $lifetime); return $content; }
/** * Writes the group data into persistence (MySQL for now). * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { parent::writeToPersistence(); $sql_fields = "\n\t\t\tlabel_prg='" . SensitiveIO::sanitizeSQLString($this->_label) . "',\n\t\t\tdescription_prg='" . SensitiveIO::sanitizeSQLString($this->_description) . "',\n\t\t\tprofile_prg='" . SensitiveIO::sanitizeSQLString(parent::getId()) . "'\n\t\t"; if ($this->_groupId) { $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tprofilesUsersGroups\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_prg='" . $this->_groupId . "'\n\t\t\t"; } else { $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofilesUsersGroups\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if ($q->hasError()) { return false; } elseif (!$this->_groupId) { $this->_groupId = $q->getLastInsertedID(); } /* Delete all records and re-insert the good ones */ $sql = "\n\t\t\tdelete from\n\t\t\t\tprofileUsersByGroup\n\t\t\twhere\n\t\t\t\tgroupId_gu='" . $this->_groupId . "'\n\t\t"; $q = new CMS_query($sql); if (is_array($this->_users) && $this->_users) { $sql = ''; foreach ($this->_users as $user) { $sql .= $sql ? ', ' : ''; $sql .= "('" . $this->_groupId . "' ,'" . $user . "') "; } $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofileUsersByGroup (groupId_gu, userId_gu)\n\t\t\t\tvalues \n\t\t\t\t\t" . $sql; $q = new CMS_query($sql); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('resource' => 'users')); CMS_cache::clearTypeCache('polymod'); return true; }
/** * Get object Definition (CMS_poly_object_definition) * * @return CMS_poly_object_definition * @access public */ function getObjectDefinition() { //create cache object $cache = new CMS_cache('object' . $this->_objectID, 'atm-polymod-structure', 2592000, false); $datas = ''; if (!$cache->exist() || !($datas = $cache->load())) { //datas does not exists : load it $datas = CMS_poly_object_catalog::getObjectDefinition($this->_objectID); if ($cache) { $cache->save($datas, array('type' => 'object')); } } return $datas; }
/** * Completely destroy a list of objects and associated resources if any. After this, objects will no longer exists at all. * /!\ if objects are primary resources, no validation will be queried to validators, objects will be directly destroyed from all locations. /!\ * * @param integer $objectID the object type ID to destroy * @param array $itemIDs array of object ids to completely destroy * @access public * @static */ static function hardDeleteObjects($objectID, $itemIDs) { if (!sensitiveIO::isPositiveInteger($objectID)) { CMS_grandFather::raiseError("objectID is not a positive integer : " . $objectID); return false; } if (!is_array($itemIDs)) { CMS_grandFather::raiseError("itemIDs is not an array : " . print_r($itemIDs, true)); return false; } //get object definition $objectDef = CMS_poly_object_catalog::getObjectDefinition($objectID); //if object is a primary resource, destroy all resources associated to objects if ($objectDef->isPrimaryResource()) { //get resources Ids $sql = "select \n\t\t\t\t\t\tvalue \n\t\t\t\t\tfrom \n\t\t\t\t\t\tmod_subobject_integer_edited \n\t\t\t\t\twhere \n\t\t\t\t\t\tobjectID in (" . implode(',', $itemIDs) . ")\n\t\t\t\t\t\tand objectFieldID = 0"; $q = new CMS_query($sql); $resourceIDs = array(); if ($q->getNumRows()) { while ($r = $q->getArray()) { $resourceIDs[] = $r['value']; } } //get resources statuses Ids $sql = "select \n\t\t\t\t\t\tstatus_res \n\t\t\t\t\tfrom \n\t\t\t\t\t\tresources \n\t\t\t\t\twhere \n\t\t\t\t\t\tid_res in (" . implode(',', $resourceIDs) . ")"; $q = new CMS_query($sql); $resourceStatusesIDs = array(); if ($q->getNumRows()) { while ($r = $q->getArray()) { $resourceStatusesIDs[] = $r['status_res']; } } //then delete both of them $sql = "delete\n\t\t\t\t\tfrom \n\t\t\t\t\t\tresources \n\t\t\t\t\twhere \n\t\t\t\t\t\tid_res in (" . implode(',', $resourceIDs) . ")"; $q = new CMS_query($sql); $sql = "delete\n\t\t\t\t\tfrom \n\t\t\t\t\t\tresourceStatuses \n\t\t\t\t\twhere \n\t\t\t\t\t\tid_rs in (" . implode(',', $resourceStatusesIDs) . ")"; $q = new CMS_query($sql); } //delete objects datas from poly_object table $sql = "delete\n\t\t\t\tfrom \n\t\t\t\t\tmod_object_polyobjects \n\t\t\t\twhere \n\t\t\t\t\tid_moo in (" . implode(',', $itemIDs) . ")"; $q = new CMS_query($sql); //delete from data tables $dataTables = array('mod_subobject_date_deleted', 'mod_subobject_date_edited', 'mod_subobject_date_public', 'mod_subobject_integer_deleted', 'mod_subobject_integer_edited', 'mod_subobject_integer_public', 'mod_subobject_string_deleted', 'mod_subobject_string_edited', 'mod_subobject_string_public', 'mod_subobject_text_deleted', 'mod_subobject_text_edited', 'mod_subobject_text_public'); foreach ($dataTables as $datasTable) { $sql = "delete\n\t\t\t\t\tfrom \n\t\t\t\t\t\t" . $datasTable . "\n\t\t\t\t\twhere \n\t\t\t\t\t\tobjectID in (" . implode(',', $itemIDs) . ")"; $q = new CMS_query($sql); } //delete associated objects module files if any foreach ($itemIDs as $itemID) { $files = glob(PATH_MODULES_FILES_FS . '/' . $objectDef->getValue('module') . '/*/r' . $itemID . '_*'); if (is_array($files) && $files) { foreach ($files as $file) { if (is_file($file)) { @unlink($file); } } } } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $objectDef->getValue('module'))); CMS_cache::clearTypeCache('polymod'); return true; }
/** * Destroy this object, in DB and filesystem if needed * Destroy title label also * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_fieldID) { //delete all files of objects for this field $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID); $filesDir = new CMS_file(PATH_MODULES_FILES_FS . '/' . $module, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); if ($filesDir->exists()) { //search all files of this field $filesList = $filesDir->getFileList(PATH_MODULES_FILES_FS . '/' . $module . '/*_f' . $this->_fieldID . '_*'); //then delete them foreach ($filesList as $aFile) { if (!CMS_file::deleteFile($aFile['name'])) { $this->raiseError("Can't delete file " . $aFile['name'] . " for field : " . $this->_fieldID); return false; } } } //delete all datas of objects for this field $tables = array('mod_subobject_date_deleted', 'mod_subobject_date_edited', 'mod_subobject_date_public', 'mod_subobject_integer_deleted', 'mod_subobject_integer_edited', 'mod_subobject_integer_public', 'mod_subobject_string_deleted', 'mod_subobject_string_edited', 'mod_subobject_string_public', 'mod_subobject_text_deleted', 'mod_subobject_text_edited', 'mod_subobject_text_public'); foreach ($tables as $aTable) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $aTable . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectFieldID = '" . $this->_fieldID . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table " . $aTable . " for field : " . $this->_fieldID); return false; } } //delete title label object if (sensitiveIO::IsPositiveInteger($this->_objectFieldValues["labelID"])) { $label = new CMS_object_i18nm($this->_objectFieldValues["labelID"]); $label->destroy(); } //delete field DB record $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_field \n\t\t\t\twhere\n\t\t\t\t\tid_mof='" . $this->_fieldID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_field for field : " . $this->_fieldID); return false; } //unset fields catalog in cache CMS_cache::clearTypeCache('atm-polymod-structure'); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID))); CMS_cache::clearTypeCache('polymod'); } //unset fields catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'fields')); //finally destroy object instance unset($this); return true; }
/** * Destroy the module * * @return void * @access public */ function destroy() { global $cms_user; // Check module exists and is polymod if (!$this->isDestroyable()) { return false; } // CHECK USED ROWS $rowsIds = CMS_rowsCatalog::getByModules(array($this->_codename), false, false); //delete all module rows foreach ($rowsIds as $rowId) { $row = CMS_rowsCatalog::getByID($rowId); if (is_object($row)) { $row->destroy(); } } // TREAT CATEGORIES $attrs = array("module" => $this->_codename, "language" => CMS_languagesCatalog::getDefaultLanguage(), "level" => -1, "root" => -1, "cms_user" => $cms_user, "clearanceLevel" => CLEARANCE_MODULE_EDIT, "strict" => false); $cats = CMS_moduleCategories_catalog::getAll($attrs); if ($cats) { foreach ($cats as $cat) { // Destroy category $cat->destroy(); } } // TREAT MODULE & VALIDATIONS RIGHTS $sql = "\n\t\t\tselect \n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tprofiles\n\t\t\twhere\n\t\t\t\tmoduleClearancesStack_pr like '" . io::sanitizeSQLString($this->_codename) . ",%'\n\t\t\t\t or moduleClearancesStack_pr like '%;" . io::sanitizeSQLString($this->_codename) . ",%'\n\t\t "; $q = new CMS_query($sql); if ($q->getNumRows()) { while ($r = $q->getArray()) { $stack = new CMS_stack(); $stack->setTextDefinition($r['moduleClearancesStack_pr']); $stack->delAllWithOneKey($this->_codename); $qInsert = new CMS_query("update profiles set moduleClearancesStack_pr='" . io::sanitizeSQLString($stack->getTextDefinition()) . "' where id_pr='" . $r['id_pr'] . "'"); } } $sql = "\n\t\t\tselect \n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tprofiles\n\t\t\twhere\n\t\t\t\tvalidationClearancesStack_pr like '" . io::sanitizeSQLString($this->_codename) . ";%'\n\t\t\t\t or validationClearancesStack_pr like '%;" . io::sanitizeSQLString($this->_codename) . ";%'\n\t\t\t\t or validationClearancesStack_pr = '" . io::sanitizeSQLString($this->_codename) . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { while ($r = $q->getArray()) { $stack = new CMS_stack(); $stack->setTextDefinition($r['validationClearancesStack_pr']); $stack->delAllWithOneKey($this->_codename); $qInsert = new CMS_query("update profiles set validationClearancesStack_pr='" . io::sanitizeSQLString($stack->getTextDefinition()) . "' where id_pr='" . $r['id_pr'] . "'"); } } //remove module files if (CMS_file::deltreeSimulation(PATH_MODULES_FILES_FS . '/' . $this->_codename, true)) { CMS_file::deltree(PATH_MODULES_FILES_FS . '/' . $this->_codename, true); } //remove JS and CSS if (is_dir(PATH_JS_FS . '/modules/' . $this->_codename) && CMS_file::deltreeSimulation(PATH_JS_FS . '/modules/' . $this->_codename, true)) { CMS_file::deltree(PATH_JS_FS . '/modules/' . $this->_codename, true); } if (is_dir(PATH_CSS_FS . '/modules/' . $this->_codename) && CMS_file::deltreeSimulation(PATH_CSS_FS . '/modules/' . $this->_codename, true)) { CMS_file::deltree(PATH_CSS_FS . '/modules/' . $this->_codename, true); } $cssFiles = $this->getCSSFiles('', true); foreach ($cssFiles as $mediaCssFiles) { foreach ($mediaCssFiles as $cssFile) { CMS_file::deleteFile(PATH_REALROOT_FS . '/' . $cssFile); } } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_codename)); CMS_cache::clearTypeCache('polymod'); // Destroy module return parent::destroy(); }
/** * Process the module validations. Note that the EMails sent to either the transferred validator or the editors were sent before. * * @param CMS_resourceValidation $resourceValidation The resource validation to process * @param integer $result The result of the validation process. See VALIDATION_OPTION constants * @return boolean true on success, false on failure to process * @access public */ function processValidation($resourceValidation, $result, $lastValidation = true) { if (!CMS_poly_object_catalog::hasPrimaryResource($this->getCodename())) { $this->raiseError("Module have not any primary resource !"); return false; } if (!$resourceValidation instanceof CMS_resourceValidation) { $this->raiseError("ResourceValidation is not a valid CMS_resourceValidation object"); return false; } if (!SensitiveIO::isInSet($result, CMS_resourceValidation::getAllValidationOptions())) { $this->raiseError("ProcessValidation : result is not a valid validation option"); return false; } //Tell the resource of the changes $resource = $resourceValidation->getResource(); $editions = $resourceValidation->getEditions(); //add a call to all modules for validation specific treatment $modulesCodes = new CMS_modulesCodes(); //add a call to modules after validation $modulesCodes->getModulesCodes(MODULE_TREATMENT_BEFORE_VALIDATION_TREATMENT, '', $resource, array('result' => $result, 'lastvalidation' => $lastValidation, 'module' => $this->_codename)); switch ($result) { case VALIDATION_OPTION_REFUSE: //validation was refused, adjust the array of validations refused $all_editions = CMS_resourceStatus::getAllEditions(); foreach ($all_editions as $aEdition) { if ($aEdition & $editions) { if (RESOURCE_EDITION_LOCATION & $aEdition && $resource->getProposedLocation() == RESOURCE_LOCATION_DELETED) { $resource->removeProposedLocation(); } else { $resource->addValidationRefused($aEdition); } } } break; case VALIDATION_OPTION_ACCEPT: //if one of the edition was the location, only treat this one. Move the data. if ($editions & RESOURCE_EDITION_LOCATION) { if ($resource->getLocation() == RESOURCE_LOCATION_USERSPACE) { //pulling resource out of USERSPACE switch ($resource->getProposedLocation()) { case RESOURCE_LOCATION_DELETED: $locationTo = RESOURCE_DATA_LOCATION_DELETED; break; } //first, move edited $this->_changeDataLocation($resource, RESOURCE_DATA_LOCATION_EDITED, $locationTo); //then delete public $this->_changeDataLocation($resource, RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_DEVNULL); //mark item as deleted CMS_modulePolymodValidation::markDeletedItem($resource->getID()); } else { if ($resource->getProposedLocation() == RESOURCE_LOCATION_USERSPACE) { //Pushing resource to USERSPACE switch ($resource->getLocation()) { case RESOURCE_LOCATION_DELETED: $locationFrom = RESOURCE_DATA_LOCATION_DELETED; break; } //if resource was published, copy data to public table if ($resource->getPublication() != RESOURCE_PUBLICATION_NEVERVALIDATED) { $this->_changeDataLocation($resource, $locationFrom, RESOURCE_DATA_LOCATION_PUBLIC, true); } //move data from its location to edited $this->_changeDataLocation($resource, $locationFrom, RESOURCE_DATA_LOCATION_EDITED); } else { //the move entirely takes place outside of USERSPACE (archived to deleted hopefully) switch ($resource->getLocation()) { case RESOURCE_LOCATION_DELETED: $locationFrom = RESOURCE_DATA_LOCATION_DELETED; break; } switch ($resource->getProposedLocation()) { case RESOURCE_LOCATION_DELETED: $locationTo = RESOURCE_DATA_LOCATION_DELETED; break; } $this->_changeDataLocation($resource, $locationFrom, $locationTo); if ($locationTo == RESOURCE_DATA_LOCATION_DELETED) { //mark item as deleted CMS_modulePolymodValidation::markDeletedItem($resource->getID()); } } } $resource->validateProposedLocation(); } else { $all_editions = CMS_resourceStatus::getAllEditions(); $this->_changeDataLocation($resource, RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_PUBLIC, true); foreach ($all_editions as $aEdition) { if ($aEdition & $editions) { $resource->validateEdition($aEdition); } } } break; } //if resource is a polyobject, we need to save only it resource (parent) status if (!$resource instanceof CMS_poly_object) { $resource->writeToPersistence(); } else { $resource->writeToPersistence(false); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_codename)); CMS_cache::clearTypeCache('polymod'); } $modulesCodes->getModulesCodes(MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT, '', $resource, array('result' => $result, 'lastvalidation' => $lastValidation, 'module' => $this->_codename)); return true; }
/** * Send a group of files to client (ie : JS or CSS files) * Provide coherent user caching infos (1 month) for files and allow gzip when possible * * @param array $files : array of files path to send to client (FS relative) * @param string $contentType : the content type to send to client (default : text/html) * @return void * @access public * @static */ static function sendFiles($files, $contentType = 'text/html') { //check for the closest last modification date $lastdate = ''; //check for included files in less files $includes = array(); if ($contentType == 'text/css') { foreach ($files as $key => $file) { if (pathinfo($file, PATHINFO_EXTENSION) == 'less') { $lessCache = new CMS_cache(md5($file), 'lessphp', 2592000, false); if ($lessCache->exist()) { $includes = array_merge($includes, $lessCache->load()); } } } } if ($includes) { foreach ($includes as $key => $file) { if (file_exists($file) && is_file($file)) { $lastdate = filemtime($file) > $lastdate ? filemtime($file) : $lastdate; } } } foreach ($files as $key => $file) { if (file_exists($file) && is_file($file)) { $lastdate = filemtime($file) > $lastdate ? filemtime($file) : $lastdate; } else { CMS_grandFather::raiseError('Can\'t find file : ' . $file . ', skip it.'); unset($files[$key]); } } if (file_exists($_SERVER['SCRIPT_FILENAME'])) { $lastdate = filemtime($_SERVER['SCRIPT_FILENAME']) > $lastdate ? filemtime($_SERVER['SCRIPT_FILENAME']) : $lastdate; } //check If-Modified-Since header if exists then return a 304 if needed if (isset($_SERVER['IF-MODIFIED-SINCE'])) { $ifModifiedSince = strtotime($_SERVER['IF-MODIFIED-SINCE']); } elseif (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $ifModifiedSince = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']); } if (isset($ifModifiedSince) && $lastdate <= $ifModifiedSince) { header('HTTP/1.1 304 Not Modified'); header('Content-Type: ' . $contentType); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastdate) . ' GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT'); //30 days header("Cache-Control: must-revalidate"); header("Pragma: public"); exit; } $compress = 'ob_gzhandler' != ini_get('output_handler') && extension_loaded('zlib') && !ini_get('zlib.output_compression') && strpos(strtolower(@$_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') !== false; //create cache id from files, compression status and last time files access $id = md5(implode(',', $files) . '-' . $compress . '-' . $lastdate); //create cache object $cache = new CMS_cache($id, $contentType, 2592000, false); $datas = ''; if (!$cache->exist() || !($datas = $cache->load())) { // datas cache missing so create it foreach ($files as $file) { $fileData = file_get_contents($file); //strip BOM from file if exists if (substr($fileData, 0, 3) === '') { $fileData = substr($fileData, 3); } //append file origin comment if ($contentType == 'text/javascript') { $fileData = '//<<' . "\n" . '//JS file: ' . str_replace(PATH_REALROOT_FS, '', $file) . '' . "\n" . '//!>>' . "\n" . $fileData; } //append file origin comment if ($contentType == 'text/css') { //compile less files if needed if (pathinfo($file, PATHINFO_EXTENSION) == 'less') { $less = new lessc($file); $fileData = $less->parse(); $lessIncludes = $less->allParsedFiles(); if (sizeof($lessIncludes) > 1) { $lessCache = new CMS_cache(md5($file), 'lessphp', 2592000, false); $lessCache->save(array_keys($lessIncludes), array('type' => 'lessphp')); } } $fileData = '/*<<*/' . "\n" . '/* CSS file: ' . str_replace(PATH_REALROOT_FS, '', $file) . ' */' . "\n" . '/*!>>*/' . "\n" . $fileData; } $datas .= $fileData . "\n"; } //minimize JS files if needed if (!SYSTEM_DEBUG && $contentType == 'text/javascript') { $datas = JSMin::minify($datas); } //minimize CSS files if needed if (!SYSTEM_DEBUG && $contentType == 'text/css') { $datas = cssmin::minify($datas); } //compres data if needed if ($compress) { $datas = gzencode($datas, 3); } if ($cache) { $cache->save($datas, array('type' => $contentType)); } } //send headers header('Content-Type: ' . $contentType); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastdate) . ' GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT'); //30 days header("Cache-Control: must-revalidate"); header("Pragma: public"); //send gzip header if needed if ($compress) { header('Vary: Accept-Encoding'); // Handle proxies header("Content-Encoding: gzip"); } //send content echo $datas; exit; }