/** * Compute the tag * * @return string the PHP / HTML content computed * @access private */ protected function _compute() { if (!isset($this->_computeParams['object']) || !$this->_computeParams['object'] instanceof CMS_page) { CMS_grandFather::raiseError('atm-js-add tag must be outside of <block> tags'); return ''; } if (!isset($this->_attributes['file'])) { CMS_grandFather::raiseError('atm-js-add tag must have file parameter'); return ''; } $files = CMS_module::moduleUsage($this->_computeParams['object']->getID(), "atm-js-tags-add"); $files = is_array($files) ? $files : array(); //append module js files $files = array_merge($files, array($this->_attributes['file'])); //save files CMS_module::moduleUsage($this->_computeParams['object']->getID(), "atm-js-tags-add", $files, true); }
/** * Compute the tag * * @return string the PHP / HTML content computed * @access private */ protected function _compute() { $headCode = ''; if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $headCode .= 'ob_start();'; $xml = new CMS_xml2Array($this->_computeChilds()); $headCode .= $xml->toXML($xml->getParsedArray(), false, true) . '<?php '; $headCode .= '$content = ob_get_contents(); ob_end_clean(); $replace=array();'; $footcode = 'if (trim($content)) {echo $content;}' . "\n"; } else { $headCode .= $this->_computeChilds() . ' if (trim($content)) {echo $content;}'; } if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $code = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($this->_returnComputedDatas($headCode)))); CMS_module::moduleUsage($this->_computeParams['object']->getID(), MOD_STANDARD_CODENAME, array('headCallback' => array($code))); } else { $this->_tagHeaderCode = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($headCode))); } return ''; }
} //load module $module = CMS_modulesCatalog::getByCodename($codename); if (!$module) { CMS_grandFather::raiseError('Unknown module or module for codename : ' . $codename); $view->show(); } //CHECKS user has module clearance if (!$cms_user->hasModuleClearance($codename, CLEARANCE_MODULE_EDIT)) { CMS_grandFather::raiseError('User has no rights on module : ' . $codename); $view->setActionMessage($cms_language->getmessage(MESSAGE_ERROR_MODULE_RIGHTS, array($module->getLabel($cms_language)))); $view->show(); } //get queried module categories $attrs = array("module" => $codename, "language" => $cms_language, "level" => $rootId, "root" => $rootId ? false : 0, "attrs" => false, "cms_user" => $cms_user); $categories = CMS_module::getModuleCategories($attrs); $nodes = array(); foreach ($categories as $category) { $parentRight = sensitiveIO::isPositiveInteger($category->getAttribute('parentID')) ? $cms_user->hasModuleCategoryClearance($category->getAttribute('parentID'), CLEARANCE_MODULE_MANAGE) : $cms_user->hasModuleClearance($codename, CLEARANCE_MODULE_EDIT); $categoryRight = $cms_user->hasModuleCategoryClearance($category->getID(), CLEARANCE_MODULE_MANAGE); $hasSiblings = $category->hasSiblings(); $qtip = $category->getIconPath(false, PATH_RELATIVETO_WEBROOT, true) ? '<img style="max-width:280px;" src="' . $category->getIconPath(true) . '" /><br />' : ''; $qtip .= $category->getDescription() ? $category->getDescription() . '<br />' : ''; if ($category->isProtected()) { $qtip .= '<strong>' . $cms_language->getMessage(MESSAGE_CATEGORY_PROTECTED) . ' : </strong>' . $cms_language->getMessage(MESSAGE_CATEGORY_PROTECTED_DESC) . '<br />'; } $qtip .= 'ID : ' . $category->getID(); $nodes[] = array('id' => 'cat' . $category->getID(), 'catId' => $category->getID(), 'text' => ($category->isProtected() ? '<span style="color:grey;"' . ($qtip ? ' ext:qtip="' . io::htmlspecialchars($qtip) . '"' : '') . '>' : '') . $category->getLabel() . ($category->isProtected() ? '</span>' : ''), 'leaf' => !$hasSiblings, 'qtip' => $qtip ? $qtip : false, 'draggable' => $parentRight && !$category->isProtected(), 'allowDrop' => $categoryRight, 'allowChildren' => true, 'disabled' => !$categoryRight, 'deletable' => $categoryRight && !$hasSiblings && !$category->isProtected() && !$module->isCategoryUsed($category), 'manageable' => $categoryRight, 'expanded' => sizeof($category->getLineageStack()) < $maxDepth, 'protected' => $category->isProtected() && !$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)); } $view->setContent($nodes); $view->show();
/** * Convert all definitions used by this object from human format to Automne format. * This method is usually used at end of module import process, when all objects are imported * * @param CMS_module $module The current object module * @return boolean : true on success, false on failure * @access public */ function convertDefinitions($module) { $this->setDefinition($module->convertDefinitionString($this->getDefinition(), false, true)); return $this->writeToPersistence(); }
/** * Convert all definitions used by this object from human format to Automne format. * This method is usually used at end of module import process, when all objects are imported * * @param CMS_module $module The current object module * @return boolean : true on success, false on failure * @access public */ function convertDefinitions($module) { $GLOBALS['moduleCodename'] = $module->getCodename(); $params = $this->getValue("params"); if ($params) { $fieldObject = $this->getTypeObject(); $params = $fieldObject->treatParams($params, ''); $this->setValue("params", $params); } return $this->writeToPersistence(); }
/** * Import module from given array datas * * @param array $data The module datas to import * @param array $params The import parameters. * array( * create => false|true : create missing objects (default : true) * update => false|true : update existing objects (default : true) * files => false|true : use files from PATH_TMP_FS (default : true) * ) * @param CMS_language $cms_language The CMS_langage to use * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids * @param string $infos : Reference : The import infos returned * @return boolean : true on success, false on failure * @access public */ static function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { $return = true; foreach ($data as $moduleDatas) { if (!isset($moduleDatas['codename'])) { $infos .= 'Missing codename ...' . "\n"; return false; } //check if module exists $codenames = CMS_modulesCatalog::getAllCodenames(); //instanciate module $importType = ''; if (isset($codenames[$moduleDatas['codename']])) { if (!isset($params['update']) || $params['update'] == true) { $module = CMS_modulesCatalog::getByCodename($moduleDatas['codename']); $infos .= 'Get Module ' . $module->getLabel($cms_language) . ' for update...' . "\n"; $importType = ' (Update)'; } else { $infos .= 'Module already exists and parameter does not allow to update it ...' . "\n"; return false; } } else { if (!isset($params['create']) || $params['create'] == true) { $infos .= 'Create new module for imported datas...' . "\n"; $importType = ' (Creation)'; if (isset($moduleDatas['polymod']) && $moduleDatas['polymod']) { $module = new CMS_polymod(); } else { $module = new CMS_module(); } } else { $infos .= 'Module does not exists and parameter does not allow to create it ...' . "\n"; return false; } } if ($module->fromArray($moduleDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Module "' . $module->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of module ' . $moduleDatas['codename'] . $importType . "\n"; } } return $return; }
/** * Treat given content tag by this module for the specified treatment mode, visualization mode and object. * * @param string $tag The CMS_XMLTag. * @param string $tagContent previous tag content. * @param integer $treatmentMode The current treatment mode (see constants on top of CMS_modulesTags class for accepted values). * @param integer $visualizationMode The current visualization mode (see constants on top of cms_page class for accepted values). * @param object $treatedObject The reference object to treat. * @param array $treatmentParameters : optionnal parameters used for the treatment. Usually an array of objects. * @return string the tag content treated. * @access public */ function treatWantedTag(&$tag, $tagContent, $treatmentMode, $visualizationMode, &$treatedObject, $treatmentParameters) { switch ($treatmentMode) { case MODULE_TREATMENT_CLIENTSPACE_TAGS: if (!$treatedObject instanceof CMS_pageTemplate) { $this->raiseError('$treatedObject must be a CMS_pageTemplate object'); return false; } if (!$treatmentParameters["page"] instanceof CMS_page) { $this->raiseError('$treatmentParameters["page"] must be a CMS_page object'); return false; } if (!$treatmentParameters["language"] instanceof CMS_language) { $this->raiseError('$treatmentParameters["language"] must be a CMS_language object'); return false; } switch ($tag->getName()) { case "atm-clientspace": $args = array("template" => $treatedObject->getID()); if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_HTML_EDITION || $visualizationMode == PAGE_VISUALMODE_FORM) { $args["editedMode"] = true; } $cs = $tag->getRepresentationInstance($args); if (is_object($cs)) { $html = $cs->getData($treatmentParameters["language"], $treatmentParameters["page"], $visualizationMode, false); } else { //call generic module clientspace content $cs = new CMS_moduleClientspace($tag->getAttributes()); $html = $cs->getClientspaceData($this->_codename, $treatmentParameters["language"], $treatmentParameters["page"], $visualizationMode); } if ($visualizationMode != PAGE_VISUALMODE_PRINT) { //save in global var the page ID who need this module so we can add the header code later. CMS_module::moduleUsage($treatmentParameters["page"]->getID(), $this->_codename, array('block' => true)); } break; case 'block': $attributes = $tag->getAttributes(); if (!isset($attributes['id'])) { $this->raiseError('Missing attribute id in block tag'); return false; } //create the block data $block = $tag->getRepresentationInstance(); //instanciate fake row $row = new CMS_row(0, $attributes['id']); //instanciate fake clientspace $cs = new CMS_moduleClientspace($tag->getAttributes()); //if block exists, use it if ($block) { $return = $block->getData($treatmentParameters["language"], $treatmentParameters["page"], $cs, $row, $visualizationMode); if ($return) { //save in global var the page ID who need this module so we can add the header code later. CMS_module::moduleUsage($treatmentParameters["page"]->getID(), $this->_codename, array('block' => true)); } return $return; } else { //else call module clientspace content $cs = new CMS_moduleClientspace($tag->getAttributes()); $return = $cs->getClientspaceData($this->_codename, new CMS_date(), $treatmentParameters["page"], $visualizationMode); if ($visualizationMode != PAGE_VISUALMODE_PRINT && $return) { //save in global var the page ID who need this module so we can add the header code later. CMS_module::moduleUsage($treatmentParameters["page"]->getID(), $this->_codename, array('block' => true)); } return $return; } break; } return $html; break; case MODULE_TREATMENT_BLOCK_TAGS: if (!$treatedObject instanceof CMS_row) { $this->raiseError('$treatedObject must be a CMS_row object'); return false; } if (!$treatmentParameters["page"] instanceof CMS_page) { $this->raiseError('$treatmentParameters["page"] must be a CMS_page object'); return false; } if (!$treatmentParameters["language"] instanceof CMS_language) { $this->raiseError('$treatmentParameters["language"] must be a CMS_language object'); return false; } if (!$treatmentParameters["clientSpace"] instanceof CMS_moduleClientspace) { $this->raiseError('$treatmentParameters["clientSpace"] must be a CMS_moduleClientspace object'); return false; } $attributes = $tag->getAttributes(); //create the block data $block = $tag->getRepresentationInstance(); //if block exists, use it if ($block) { $return = $block->getData($treatmentParameters["language"], $treatmentParameters["page"], $treatmentParameters["clientSpace"], $treatedObject, $visualizationMode); if ($return) { //save in global var the page ID who need this module so we can add the header code later. CMS_module::moduleUsage($treatmentParameters["page"]->getID(), $this->_codename, array('block' => true)); } return $return; } else { //else call module clientspace content $cs = new CMS_moduleClientspace($tag->getAttributes()); $return = $cs->getClientspaceData($this->_codename, new CMS_date(), $treatmentParameters["page"], $visualizationMode); if ($visualizationMode != PAGE_VISUALMODE_PRINT && $return) { //save in global var the page ID who need this module so we can add the header code later. CMS_module::moduleUsage($treatmentParameters["page"]->getID(), $this->_codename, array('block' => true)); } return $return; } break; case MODULE_TREATMENT_PAGEHEADER_TAGS: switch ($tag->getName()) { case "atm-js-tags": case "atm-css-tags": $usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename); $return = ''; //overwrite previous modules return to append files of this module //only if current page use a block of this module if (isset($usage['block'])) { //save in global var the page ID who use this tag CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array($tag->getName() => true)); //save new modules files switch ($tag->getName()) { case "atm-js-tags": if (!isset($usage['js-files'])) { //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags"); $files = is_array($files) ? $files : array(); //append module js files $files = array_merge($files, $this->getJSFiles($treatedObject->getID())); //save files CMS_module::moduleUsage($treatedObject->getID(), $tag->getName(), $files, true); //save JS handled CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('js-files' => true)); } break; case "atm-css-tags": $media = $tag->getAttribute('media') ? $tag->getAttribute('media') : 'all'; if (!isset($usage['css-media'][$media])) { $return = ''; //overwrite previous modules return to append files of this module //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags"); $files = is_array($files) ? $files : array(); //append module css files $moduleCSSFiles = $this->getCSSFiles($treatedObject->getID()); foreach ($moduleCSSFiles as $filesMedia => $mediaFiles) { if (!isset($files[$filesMedia])) { $files[$filesMedia] = array(); } $files[$filesMedia] = array_merge($files[$filesMedia], $moduleCSSFiles[$filesMedia]); } //save files CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags", $files, true); //save media handled CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('css-media' => array($media => true))); } break; } //Create return for all saved modules files switch ($tag->getName()) { case "atm-js-tags": //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags"); //add files from atm-js-add tag $filesAdd = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags-add"); $filesAdd = is_array($filesAdd) ? $filesAdd : array(); $files = array_merge($files, $filesAdd); $return .= '<?php echo CMS_view::getJavascript(array(\'' . implode('\',\'', array_unique($files)) . '\')); ?>' . "\n"; break; case "atm-css-tags": $media = $tag->getAttribute('media') ? $tag->getAttribute('media') : 'all'; //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags"); //add files from atm-css-add tag $filesAdd = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags-add"); $filesAdd = is_array($filesAdd) ? $filesAdd : array(); if (isset($files[$media])) { if (isset($filesAdd[$media])) { $files[$media] = array_merge($files[$media], $filesAdd[$media]); } $return .= '<?php echo CMS_view::getCSS(array(\'' . implode('\',\'', array_unique($files[$media])) . '\'), \'' . $media . '\'); ?>' . "\n"; } break; } return $return; } break; case 'atm-meta-tags': //if this page use a row of this module then add the css file if exists to the page $usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename); if (isset($usage['block'])) { //append module css files $moduleCSSFiles = $this->getCSSFiles($treatedObject->getID()); foreach ($moduleCSSFiles as $media => $mediaFiles) { if (!isset($usage['css-media'][$media])) { $tagContent .= "\n" . ' <!-- load the style of ' . $this->_codename . ' module for media ' . $media . ' -->' . "\n"; foreach ($moduleCSSFiles[$media] as $cssfile) { $tagContent .= ' <link rel="stylesheet" type="text/css" href="' . $cssfile . '" media="' . $media . '" />' . "\n"; } //save media handled CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('css-media' => array($media => true))); } } if (!isset($usage['atm-js-tags'])) { $jsFiles = $this->getJSFiles($treatedObject->getID()); if ($jsFiles) { $tagContent .= "\n" . ' <!-- load js file of ' . $this->_codename . ' module -->' . "\n"; foreach ($jsFiles as $jsfile) { $tagContent .= ' <script type="text/javascript" src="' . $jsfile . '"></script>' . "\n"; } } //save JS handled CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('js-files' => true)); } } return $tagContent; break; } break; } return $tagContent; }
/** * Convert all definitions used by this object from human format to Automne format. * This method is usually used at end of module import process, when all objects are imported * * @param CMS_module $module The current object module * @return boolean : true on success, false on failure * @access public */ function convertDefinitions($module) { $this->setValue("definition", $module->convertDefinitionString($this->_objectValues['definition'], false, true)); return $this->writeToPersistence(); }
/** * Returns each category ID and label in a module given user can see * * @access public * @param CMS_profile $cms_user, the profile concerned by these restrictions * @param string $cms_module, the module codename * @param CMS_language $cms_language, the language of the labels * @param mixed $clearanceLevel * - false : CLEARANCE_MODULE_VIEW * - true : CLEARANCE_MODULE_EDIT * - constant value : clearanceLevel value * @param boolean $strict return only categories from this clearance (default : false, else, return complete categories tree until given clearance) * @return array(string) the statements or false if profile hasn't any access to any categories * @static */ function getSiblingCategoriesAsArray(&$category, $count, &$cms_user, $cms_module, $cms_language, $clearanceLevel = false, $strict = false) { $count++; $attrs = array("module" => $cms_module, "language" => $cms_language, "level" => $category->getID(), "root" => false, "cms_user" => &$cms_user, "clearanceLevel" => $clearanceLevel, "strict" => $strict); $siblings = CMS_module::getModuleCategories($attrs); if (is_array($siblings) && $siblings) { $ctgs = array(); foreach ($siblings as $obj) { $ctgs[$obj->getID()] = str_repeat('- ', $count) . '' . io::htmlspecialchars($obj->getLabel()); if (false !== ($a_sibling = CMS_moduleCategories_catalog::getSiblingCategoriesAsArray($obj, $count, $cms_user, $cms_module, $cms_language, $clearanceLevel, $strict))) { while (list($id, $lbl) = each($a_sibling)) { if ($id) { $ctgs[$id] = $lbl; } } } } if (is_array($ctgs) && $ctgs) { return $ctgs; } } return false; }
/** * Gets the data in HTML mode. * * @param CMS_language &$language The language of the administration frontend * @param CMS_page &$page The page which contains the client space * @param CMS_clientSpace &$clientSpace The client space which contains the row * @param CMS_row &$row The row which contains the block * @param integer $visualizationMode The visualization mode used * @return string the HTML data * @access public */ function getData(&$language, &$page, &$clientSpace, &$row, $visualizationMode) { parent::getData($language, $page, $clientSpace, $row, $visualizationMode); //get the data switch ($visualizationMode) { case PAGE_VISUALMODE_HTML_PUBLIC: case PAGE_VISUALMODE_PRINT: $data = $this->getRawData($page->getID(), $clientSpace->getTagID(), $row->getTagID(), RESOURCE_LOCATION_USERSPACE, true); break; case PAGE_VISUALMODE_HTML_EDITED: $data = $this->getRawData($page->getID(), $clientSpace->getTagID(), $row->getTagID(), RESOURCE_LOCATION_USERSPACE, false); break; case PAGE_VISUALMODE_HTML_EDITION: case PAGE_VISUALMODE_FORM: case PAGE_VISUALMODE_CLIENTSPACES_FORM: $data = $this->getRawData($page->getID(), $clientSpace->getTagID(), $row->getTagID(), RESOURCE_LOCATION_EDITION, false); break; } //build the HTML $html_attributes = ""; foreach ($this->_attributes as $name => $value) { if ($name != "module" && $name != "type") { $html_attributes .= ' ' . $name . '="' . $value . '"'; } } $src = ''; $this->_hasContent = $data && $data["file"] ? true : false; switch ($visualizationMode) { case PAGE_VISUALMODE_HTML_PUBLIC: case PAGE_VISUALMODE_PRINT: if ($this->_hasContent) { $language = CMS_languagesCatalog::getByCode($page->getLanguage(true)); $src = PATH_MODULES_FILES_STANDARD_WR . '/public/' . $data["file"]; } break; case PAGE_VISUALMODE_HTML_EDITED: if ($this->_hasContent) { $language = CMS_languagesCatalog::getByCode($page->getLanguage(false)); $src = PATH_MODULES_FILES_STANDARD_WR . '/edited/' . $data["file"]; } break; case PAGE_VISUALMODE_HTML_EDITION: if ($this->_hasContent) { $language = CMS_languagesCatalog::getByCode($page->getLanguage(false)); $src = PATH_MODULES_FILES_STANDARD_WR . '/edition/' . $data["file"]; } break; case PAGE_VISUALMODE_FORM: $this->_editable = true; if ($this->_hasContent) { $language = CMS_languagesCatalog::getByCode($page->getLanguage(false)); $src = PATH_MODULES_FILES_STANDARD_WR . '/edition/' . $data["file"]; } else { $html = '<img src="' . PATH_MODULES_FILES_STANDARD_WR . '/flash.gif" alt="X" title="X" />'; $form_data = str_replace("{{data}}", $html, $this->_definition); return $this->_getHTMLForm($language, $page, $clientSpace, $row, $this->_tagID, $form_data); } break; case PAGE_VISUALMODE_CLIENTSPACES_FORM: $this->_hasContent = false; $this->_editable = false; $html = '<img src="' . PATH_MODULES_FILES_STANDARD_WR . '/flash.gif" alt="X" title="X" />'; return $this->_getHTMLForm($language, $page, $clientSpace, $row, $this->_tagID, $form_data); break; } if (!$src) { return ''; } $id = $data["name"] ? 'flash-' . sensitiveIO::sanitizeHTMLString($data["name"]) : 'flash-' . md5(mt_rand() . microtime()); $html = '<div>' . "\n" . ' <script type="text/javascript">' . "\n" . ' swfobject.embedSWF(\'' . $src . '\', \'' . $id . '\', \'' . $data['width'] . '\', \'' . $data['height'] . '\', \'' . $data['version'] . '\', "' . PATH_MAIN_WR . '/swfobject/expressInstall.swf", {' . sensitiveIO::sanitizeJSString($data['flashvars'], false, false) . '}, {' . sensitiveIO::sanitizeJSString($data['params'], false, false) . '}, {' . sensitiveIO::sanitizeJSString($data['attributes'], false, false) . '});' . "\n" . ' </script>' . "\n" . ' <div id="' . $id . '" class="atm-blockflash" style="width:' . $data["width"] . 'px;height:' . $data["height"] . 'px;">' . "\n" . ' <noscript>' . $language->getMessage(self::MESSAGE_PAGE_JAVASCRIPT_MANDATORY) . '</noscript>' . "\n" . ' <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>' . "\n" . ' </div>' . '</div>' . "\n"; $blockinfos = array('blockflash' => array()); $blockinfos['blockflash'] = true; CMS_module::moduleUsage($page->getID(), MOD_STANDARD_CODENAME, $blockinfos); if ($visualizationMode != PAGE_VISUALMODE_FORM) { return str_replace("{{data}}", $html, $this->_definition); } else { $form_data = str_replace("{{data}}", $html, $this->_definition); return $this->_getHTMLForm($language, $page, $clientSpace, $row, $this->_tagID, $form_data); } }
/** * Return the module code for the specified treatment mode, visualization mode and object. * * @param mixed $modulesCode the previous modules codes (usually string) * @param integer $treatmentMode The current treatment mode (see constants on top of this file for accepted values). * @param integer $visualizationMode The current visualization mode (see constants on top of cms_page class for accepted values). * @param object $treatedObject The reference object to treat. * @param array $treatmentParameters : optionnal parameters used for the treatment. Usually an array of objects. * * @return string : the module code to add * @access public */ function getModuleCode($modulesCode, $treatmentMode, $visualizationMode, &$treatedObject, $treatmentParameters) { switch ($treatmentMode) { case MODULE_TREATMENT_PAGECONTENT_HEADER_CODE: $modulesCode[MOD_STANDARD_CODENAME] = ''; $modulesCode[MOD_STANDARD_CODENAME] .= '<?php' . "\n" . '//Generated on ' . date('r') . ' by ' . CMS_grandFather::SYSTEM_LABEL . ' ' . AUTOMNE_VERSION . "\n"; //HTTPS constant if ($treatedObject->isHTTPS()) { $modulesCode[MOD_STANDARD_CODENAME] .= 'defined(\'PAGE_SSL_MODE\') || define(\'PAGE_SSL_MODE\', true);' . "\n"; } else { $modulesCode[MOD_STANDARD_CODENAME] .= '//Page can be HTTPS' . "\n" . 'if (!((isset($_SERVER["REQUEST_URI"]) && strpos($_SERVER["REQUEST_URI"], \'' . PATH_ADMIN_WR . '\') !== false) || (isset($_REQUEST[\'atm-context\']) && $_REQUEST[\'atm-context\'] == \'adminframe\'))) {' . "\n" . ' if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] && strtolower($_SERVER["HTTPS"]) != \'off\') {' . "\n" . ' defined(\'PAGE_SSL_MODE\') || define(\'PAGE_SSL_MODE\', true);' . "\n" . ' }' . "\n" . '}' . "\n"; } //Current page constant $modulesCode[MOD_STANDARD_CODENAME] .= 'defined(\'CURRENT_PAGE\') || define(\'CURRENT_PAGE\', ' . $treatedObject->getID() . ');' . "\n"; if ($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC || $visualizationMode == PAGE_VISUALMODE_PRINT) { //path to cms_rc_frontend $path = PATH_PAGES_HTML_WR == PATH_MAIN_WR . "/html" ? '/../../cms_rc_frontend.php' : '/../cms_rc_frontend.php'; //cms_rc_frontend include $modulesCode[MOD_STANDARD_CODENAME] .= 'if (!defined(\'PATH_REALROOT_FS\')){' . "\n" . ' require_once(dirname(__FILE__).\'' . $path . '\');' . "\n" . '} else {' . "\n" . ' require_once(PATH_REALROOT_FS."/cms_rc_frontend.php");' . "\n" . '}' . "\n"; //redirection code if any $redirectlink = $treatedObject->getRedirectLink(true); if ($redirectlink->hasValidHREF()) { $href = $redirectlink->getHTML(false, MOD_STANDARD_CODENAME, RESOURCE_DATA_LOCATION_PUBLIC, false, true); $modulesCode[MOD_STANDARD_CODENAME] .= 'CMS_view::redirect(\'' . $href . '\', true, 302);' . "\n"; } //old url pattern redireciton $modulesCode[MOD_STANDARD_CODENAME] .= 'if (!isset($cms_page_included) && !$_POST && !$_GET) {' . "\n" . ' CMS_view::redirect(\'' . $treatedObject->getURL($visualizationMode == PAGE_VISUALMODE_PRINT ? true : false) . '\', true, 301);' . "\n" . '}' . "\n"; //non-https redirection for https page if ($treatedObject->isHTTPS()) { $modulesCode[MOD_STANDARD_CODENAME] .= '//Page must be HTTPS' . "\n" . 'if (!(strpos($_SERVER["REQUEST_URI"], PATH_ADMIN_WR) !== false || (isset($_REQUEST[\'atm-context\']) && $_REQUEST[\'atm-context\'] == \'adminframe\')) && (!defined("APPLICATION_ENFORCE_SSL") || APPLICATION_ENFORCE_SSL == true)) {' . "\n" . ' if (!(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] && strtolower($_SERVER["HTTPS"]) != \'off\')) {' . "\n" . ' CMS_view::redirect(\'' . $treatedObject->getURL($visualizationMode == PAGE_VISUALMODE_PRINT ? true : false) . '\', true, 301);' . "\n" . ' }' . "\n" . '}' . "\n"; } //rights 403 redirection if (APPLICATION_ENFORCES_ACCESS_CONTROL) { //include user access checking on top of output file $modulesCode[MOD_STANDARD_CODENAME] .= 'if (!is_object($cms_user) || !$cms_user->hasPageClearance(' . $treatedObject->getID() . ', CLEARANCE_PAGE_VIEW)) {' . "\n" . ' CMS_view::redirect(PATH_FRONTEND_SPECIAL_LOGIN_WR.\'?referer=\'.base64_encode($_SERVER[\'REQUEST_URI\']));' . "\n" . '}' . "\n"; } } else { //page previz & edition $modulesCode[MOD_STANDARD_CODENAME] .= 'if (!in_array(\'' . PATH_REALROOT_FS . '/cms_rc_frontend.php\', get_included_files())){ require_once(\'' . PATH_REALROOT_FS . '/cms_rc_frontend.php\');} else { global $cms_user,$cms_language;}'; } $modulesCode[MOD_STANDARD_CODENAME] .= ' ?>'; //Get header code (atm-header tags) if ($usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename)) { //add header codes if (isset($usage['headCallback'])) { foreach ($usage['headCallback'] as $headCallback) { if (isset($headCallback['code'])) { $modulesCode[MOD_STANDARD_CODENAME] .= $headCallback['code']; } } } } return $modulesCode; break; case MODULE_TREATMENT_EDITOR_CODE: if ($treatmentParameters["editor"] == "fckeditor") { $languages = implode(',', array_keys(CMS_languagesCatalog::getAllLanguages(MOD_STANDARD_CODENAME))); //This is an exception of the method, because here we return an array, see admin/fckeditor/fckconfig.php for the detail return array("Default" => array("'automneLinks'"), "modulesDeclaration" => array("FCKConfig.Plugins.Add( 'automneLinks', '" . $languages . "' );")); } else { return $modulesCode; } break; case MODULE_TREATMENT_EDITOR_PLUGINS: if ($treatmentParameters["editor"] == "fckeditor") { $language = $treatmentParameters["user"]->getLanguage(); $modulesCode['automneLinks'] = $language->getMessage(self::MESSAGE_MOD_STANDARD_PLUGIN); } break; case MODULE_TREATMENT_EDITOR_JSCODE: $modulesCode[MOD_STANDARD_CODENAME] = "\n\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\tfunction openWindow(url, name, w, h, r, s, m, left, top) {\n\t\t\t\t\tpopupWin = window.open(url, name, 'width=' + w + ',height=' + h + ',resizable=' + r + ',scrollbars='+ s + ',menubar=' + m + ',left=' + left + ',top=' + top);\n\t\t\t\t}\n\t\t\t\t</script>"; return $modulesCode; break; case MODULE_TREATMENT_ROWS_EDITION_LABELS: $modulesCode[$this->_codename] = ''; //if user has rights on module if ($treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) { if (!isset($treatmentParameters['request'])) { //add form to choose object to display $modulesCode[$this->_codename] = ' <h1>' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_TAGS_CHOOSE) . '<select onchange="Ext.get(\'help' . $this->_codename . '\').getUpdater().update({url: \'' . PATH_ADMIN_WR . '/help-detail.php\',params: {module: \'' . $this->_codename . '\',object: this.value, mode:' . MODULE_TREATMENT_ROWS_EDITION_LABELS . '}});"> <option value="">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_CHOOSE) . '</option> <option value="block">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS) . '</option> <option value="working">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS) . '</option> <option value="working-standard">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_STANDARD_TAGS) . '</option> <option value="vars">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS) . '</option> </select></h1> <div id="help' . $this->_codename . '"></div> '; } //then display chosen object infos if (isset($treatmentParameters['request'][$this->_codename]) && isset($treatmentParameters['request'][$this->_codename . 'object'])) { switch ($treatmentParameters['request'][$this->_codename . 'object']) { case 'block': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS_EXPLANATION); break; case 'working': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS_EXPLANATION); break; case 'working-standard': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_STANDARD_TAGS_EXPLANATION); break; case 'vars': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS_EXPLANATION, array($treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask())); break; } } } return $modulesCode; break; case MODULE_TREATMENT_TEMPLATES_EDITION_LABELS: $modulesCode[$this->_codename] = ''; //if user has rights on module if ($treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) { if (!isset($treatmentParameters['request'])) { //add form to choose object to display $modulesCode[$this->_codename] = ' <h1>' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_TAGS_CHOOSE) . '<select onchange="Ext.get(\'help' . $this->_codename . '\').getUpdater().update({url: \'' . PATH_ADMIN_WR . '/help-detail.php\',params: {module: \'' . $this->_codename . '\',object: this.value, mode:' . MODULE_TREATMENT_TEMPLATES_EDITION_LABELS . '}});"> <option value="">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_CHOOSE) . '</option> <option value="block">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS) . '</option> <option value="working">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS) . '</option> <option value="working-standard">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_STANDARD_TAGS) . '</option> <option value="vars">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS) . '</option> </select></h1> <div id="help' . $this->_codename . '"></div> '; } //then display chosen object infos if (isset($treatmentParameters['request'][$this->_codename]) && isset($treatmentParameters['request'][$this->_codename . 'object'])) { switch ($treatmentParameters['request'][$this->_codename . 'object']) { case 'block': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_TEMPLATE_EXPLANATION); break; case 'working': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS_EXPLANATION); break; case 'working-standard': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_STANDARD_TAGS_EXPLANATION); break; case 'vars': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS_EXPLANATION, array($treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask())); break; } } } return $modulesCode; /*$modulesCode[MOD_STANDARD_CODENAME] = $treatmentParameters["language"]->getMessage(self::MESSAGE_MOD_STANDARD_TEMPLATE_EXPLANATION); return $modulesCode;*/ break; case MODULE_TREATMENT_ALERTS: $modulesCode[MOD_STANDARD_CODENAME] = array(ALERT_LEVEL_PROFILE => array('label' => CMS_profile::MESSAGE_ALERT_LEVEL_PROFILE, 'description' => CMS_profile::MESSAGE_ALERT_LEVEL_PROFILE_DESCRIPTION)); //only if user has validation clearances if ($treatmentParameters['user']->hasValidationClearance(MOD_STANDARD_CODENAME)) { $modulesCode[MOD_STANDARD_CODENAME][ALERT_LEVEL_VALIDATION] = array('label' => CMS_profile::MESSAGE_ALERT_LEVEL_VALIDATION, 'description' => CMS_profile::MESSAGE_ALERT_LEVEL_VALIDATION_DESCRIPTION); } //only if user has edition clearances if ($treatmentParameters['user']->hasEditablePages()) { $modulesCode[MOD_STANDARD_CODENAME][ALERT_LEVEL_PAGE_ALERTS] = array('label' => CMS_profile::MESSAGE_ALERT_LEVEL_PAGE_ALERTS, 'description' => CMS_profile::MESSAGE_ALERT_LEVEL_PAGE_ALERTS_DESCRIPTION); } return $modulesCode; break; } return $modulesCode; }
/** * Changes The item data (in the DB) from one location to another. * * @param CMS_resource $resource The resource concerned by the data location change * @param string $locationFrom The starting location among "edited", "edition", "public", "archived", "deleted" * @param string $locationTo The ending location among "edited", "edition", "public", "archived", "deleted" * @param boolean $copyOnly If true, data is not deleted from the original location * @return void * @access private */ protected function _changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly = false) { if (is_array($this->_resourceInfo) && $this->_resourceInfo) { if (!parent::_changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly)) { return false; } foreach ($this->_resourceInfo as $tableName => $tableInfo) { //move the data CMS_modulesCatalog::moveResourceData($this, $tableName, $tableInfo['key'], $resource->getID(), $locationFrom, $locationTo, $copyOnly); } } }
/** * Convert all definitions used by this object from human format to Automne format. * This method is usually used at end of module import process, when all objects are imported * * @param CMS_module $module The current object module * @return boolean : true on success, false on failure * @access public */ function convertDefinitions($module) { $this->setValue("composedLabel", $module->convertDefinitionString($this->getValue("composedLabel"), false, true)); $this->setValue("previewURL", $module->convertDefinitionString($this->getValue("previewURL"), false, true)); $this->setValue("indexURL", $module->convertDefinitionString($this->getValue("indexURL"), false, true)); $this->setValue("resultsDefinition", $module->convertDefinitionString($this->getValue("resultsDefinition"), false, true)); return $this->writeToPersistence(); }
/** * Recursive function to build the categories tree. * * @param CMS_moduleCategory $category * @param integer $count, to determine category in-tree depth * @return string HTML formated */ function build_category_tree_options($category, $count) { global $codename, $cms_language, $parentCategory, $cms_module, $cms_user, $catId; //if category is not itself (to avoid infinite loop in lineage) $a = array(); if ($category->getID() != $catId) { $category->setAttribute('language', $cms_language); $label = htmlspecialchars($category->getLabel()); if ($count >= 1) { $label = str_repeat(' ::', $count) . ' ' . $label; } $a[] = array($category->getID(), $label); $count++; $attrs = array("module" => $codename, "language" => $cms_language, "level" => $category->getID(), "root" => -1, "cms_user" => $cms_user, "clearanceLevel" => CLEARANCE_MODULE_MANAGE, "strict" => true); $siblings = CMS_module::getModuleCategories($attrs); if (sizeof($siblings)) { foreach ($siblings as $aSibling) { $aSibling->setAttribute('language', $cms_language); $a = array_merge($a, build_category_tree_options($aSibling, $count)); } } } return $a; }
foreach ($modules as $aModule) { if ($aModule->getCodename() == $_POST["codename"]) { $cms_message .= "\n" . $cms_language->getMessage(MESSAGE_FORM_ERROR_CODENAME_USED); } } } $languages = CMS_languagesCatalog::getAllLanguages(); foreach ($languages as $aLanguage) { if (!$_POST['label' . $aLanguage->getCode()]) { $cms_message .= "\n" . $cms_language->getMessage(MESSAGE_FORM_ERROR_MALFORMED_FIELD, array($aLanguage->getLabel())); } } if (!$cms_message) { //create the new module $moduleCodename = $_POST["codename"]; $module = new CMS_module(); $module->setCodename($moduleCodename); $module->setLabel(1); $module->setPolymod(true); $module->setAdminFrontend('index.php'); if ($module->writeToPersistence()) { //create module label //this is a direct sql query cause no writing interface exists now for messages table $count = 0; foreach ($languages as $aLanguage) { $sql = "\n\t\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t\tmessages\n\t\t\t\t\t\t\tset\n\t\t\t\t\t\t\t\tid_mes = '1',\n\t\t\t\t\t\t\t\tmodule_mes = '" . SensitiveIO::sanitizeSQLString($moduleCodename) . "',\n\t\t\t\t\t\t\t\tlanguage_mes = '" . SensitiveIO::sanitizeSQLString($aLanguage->getCode()) . "',\n\t\t\t\t\t\t\t\tmessage_mes = '" . SensitiveIO::sanitizeSQLString($_POST['label' . $aLanguage->getCode()]) . "'\n\t\t\t\t\t\t"; $q = new CMS_query($sql); } //create all needed .htaccess files if (isset($_POST['hasprotect']) && $_POST['protect'] == 1) { CMS_file::copyTo(PATH_HTACCESS_FS . '/htaccess_file', PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/edited/.htaccess');
/** * Recursive function to build items tree. * * @param mixed $items : current category or page * @param integer $count, to determine item in-tree depth * @param integer $parent_clearance, immediate parent item clearance * @return string HTML formated */ function build_items_tree(&$item, $count, $parent_clearance) { global $moduleCodename, $cms_language, $cms_user, $profileId, $hash; //current user environment global $items_ids; //reference to all displayed items global $modules_clearances, $stack_clearances; //all clearances types available global $maxDepth, $clearance_colors; //displaying options global $disableFields; //disable status $s = ''; $count++; // Current category clearance $i_default_clearance = $stack_clearances->getElementValueFromKey($item->getID()); // Thig hidden but sets current category clearance identical // to its parent's one, used to hide some checkboxes $i_current_clearance = $i_default_clearance !== false ? (int) $i_default_clearance : $parent_clearance; if ($i_default_clearance !== false) { $bgColor = ' style="background-color:' . $clearance_colors[$i_default_clearance] . ';"'; } elseif (!$i_default_clearance && $item->isRoot()) { $bgColor = ' style="background-color:' . $clearance_colors[CLEARANCE_MODULE_NONE] . ';"'; } else { $bgColor = ''; } $items_ids[] = $item->getID(); if (is_a($item, 'CMS_moduleCategory')) { $hasSiblings = $item->hasSiblings(); } else { $hasSiblings = CMS_tree::hasSiblings($item); } //Link to sub categories if ($hasSiblings) { if ($count < $maxDepth) { $thumbnail = ''; } else { $thumbnail = '<a href="#" onclick="Automne.categories.open(' . $item->getID() . ', \'' . $hash . '\', this);return false;" title="ID : ' . $item->getID() . '">+</a>'; } } else { $thumbnail = ''; } //disabled checkboxes if needed if ($disableFields) { $disabled = ' disabled="disabled"'; } else { //check if user has edition rights on item if (is_a($item, 'CMS_moduleCategory')) { $disabled = $cms_user->hasModuleCategoryClearance($item->getID(), CLEARANCE_MODULE_MANAGE) ? '' : ' disabled="disabled"'; } else { $disabled = $cms_user->hasPageClearance($item->getId(), CLEARANCE_PAGE_EDIT) ? '' : ' disabled="disabled"'; } } $label = is_a($item, 'CMS_moduleCategory') ? $item->getLabel() : $item->getTitle(); $label = $disabled ? '<span style="color:grey;">' . $label . '</span>' : $label; // Get title and form actions $s .= ' <li' . $bgColor . ' id="li-' . $hash . '-' . $item->getID() . '"> <table border="0" cellpadding="0" cellspacing="0"' . $bgColor . ' onMouseOver="Automne.categories.onRow(this);" onMouseOut="Automne.categories.outRow(this);"> <tr> <td width="100%"> ' . $thumbnail . '<span title="ID : ' . $item->getID() . '">' . $label . '</span></td> <td width="120"> <table width="120" border="0" cellpadding="0" cellspacing="0" id="checkboxes-' . $hash . '-' . $item->getID() . '"> <tr>'; @reset($modules_clearances); while (list($msg, $value) = @each($modules_clearances)) { $sel = ''; //check if user has edition rights on item if ($disableFields) { $disabled = ' disabled="disabled"'; } else { if (is_a($item, 'CMS_moduleCategory')) { $disabled = $cms_user->hasModuleCategoryClearance($item->getID(), CLEARANCE_MODULE_MANAGE) ? '' : ' disabled="disabled"'; } else { $disabled = $cms_user->hasPageClearance($item->getId(), CLEARANCE_PAGE_EDIT) ? '' : ' disabled="disabled"'; } } if ($item->isRoot() || !$item->isRoot() && $parent_clearance !== $value) { // If none clearance defined yet, access is denied to any root category if (!$i_default_clearance && $value === CLEARANCE_MODULE_NONE && $item->isRoot() || $i_default_clearance !== false && (int) $i_default_clearance === $value) { $sel = ' checked="checked"'; } $s .= '<td width="30" align="center"><input type="checkbox"' . $disabled . ' onclick="Automne.categories.unselectOthers(\'' . $item->getID() . '\',\'' . $value . '\', \'' . $count . '\', \'' . $hash . '\');" id="check-' . $hash . '-' . $item->getID() . '_' . $value . '" name="cat' . $item->getID() . '" value="' . $value . '"' . $sel . $disabled . ' /></td>'; } else { $s .= '<td width="30" align="center"><input type="checkbox"' . $disabled . ' onclick="Automne.categories.unselectOthers(\'' . $item->getID() . '\',\'' . $value . '\', \'' . $count . '\', \'' . $hash . '\');" id="check-' . $hash . '-' . $item->getID() . '_' . $value . '" name="cat' . $item->getID() . '" value="' . $value . '" style="display:none;"' . $disabled . ' /></td>'; } } $s .= ' </tr> </table> </td> </tr> </table>'; // Print siblings tree recursivly if ($hasSiblings) { if ($count < $maxDepth) { //get siblings if (is_a($item, 'CMS_moduleCategory')) { $attrs = array("module" => $moduleCodename, "language" => $cms_language, "level" => $item->getID(), "root" => false, "attrs" => false, "cms_user" => &$cms_user); $siblings = CMS_module::getModuleCategories($attrs); } else { $siblings = CMS_tree::getSiblings($item); } // Prepare form actions here if (is_array($siblings) && $siblings) { $s .= '<ul id="ul-' . $hash . '-' . $item->getID() . '">'; foreach ($siblings as $aSibling) { if (is_a($item, 'CMS_moduleCategory')) { $aSibling->setAttribute('language', $cms_language); } $s .= build_items_tree($aSibling, $count, $i_current_clearance); } $s .= '</ul>'; } } } $s .= '</li>'; return $s; }
/** * Get the parsing content * only with self::PARSE_MODE * * @param constant $type : the content type to return in : * - self::OUTPUT_RESULT output evalued PHP result * - self::OUTPUT_PHP output valid PHP to execute * @param array $parameters parameters to help parsing * 'public' : current public status * 'pageID' : current parsed page * 'itemID' : current item ID to work with * 'objectID' : current object type ID to work with * 'item' : current item to work with * 'module' : current module codename * 'block_attributes' : current block attributes values * 'language' : current language code * @return string the PHP / HTML content parsed * @access public */ function getContent($type = self::OUTPUT_RESULT, &$parameters) { if (!trim($this->_definition)) { return; } //set parameters $this->_parameters = array_merge($this->_parameters, $parameters); // //Create all pre-execution variables with parameters values // $headers = $return = ''; if (is_object($this->_parser)) { //init exported vars $languageObject = $blockAttributes = $pageID = $pluginSelection = $polyobjectsDefinitions = ''; //load all poly objects for module if (!$this->_parameters['module']) { $this->raiseError("Missing valid module codename in parameters."); } else { //set module as cached element $this->_elements['module'][] = $this->_parameters['module']; //prefetch module objects $polyObjects = CMS_poly_object_catalog::getObjectsForModule($this->_parameters['module']); if (is_array($polyObjects) && $polyObjects) { foreach ($polyObjects as $polyObject) { $polyobjectsDefinitions .= 'if (!isset($object[' . $polyObject->getID() . '])) $object[' . $polyObject->getID() . '] = new CMS_poly_object(' . $polyObject->getID() . ', 0, array(), $parameters[\'public\']);' . "\n"; } } $polyobjectsDefinitions .= '$parameters[\'module\'] = \'' . $this->_parameters['module'] . '\';' . "\n"; } $blockAttributes = $objectID = $pageID = $pluginSelection = $languageObject = $public = ''; //set plugin selection if any if (isset($this->_parameters['selection'])) { $pluginSelection = '$parameters[\'selection\'] = ' . var_export($this->_parameters['selection'], true) . ';' . "\n"; } //set pageID if any if (isset($this->_parameters['pageID']) && sensitiveIO::isPositiveInteger($this->_parameters['pageID'])) { $pageID = '$parameters[\'pageID\'] = \'' . $this->_parameters['pageID'] . '\';' . "\n"; } //set itemID if any if (isset($this->_parameters['itemID']) && sensitiveIO::isPositiveInteger($this->_parameters['itemID'])) { $pageID = '$parameters[\'itemID\'] = \'' . $this->_parameters['itemID'] . '\';' . "\n"; } //export block attributes if (isset($this->_parameters['block_attributes'])) { $blockAttributes = '$blockAttributes = ' . CMS_polymod_definition_parsing::preReplaceVars(var_export($this->_parameters['block_attributes'], true), true) . ';' . "\n"; } //instanciate language if exists if (isset($this->_parameters['language'])) { $languageObject = 'if (!isset($cms_language) || (isset($cms_language) && $cms_language->getCode() != \'' . $this->_parameters['language'] . '\')) $cms_language = new CMS_language(\'' . $this->_parameters['language'] . '\');' . "\n"; } //instanciate objectID if exists if (isset($this->_parameters['objectID']) && sensitiveIO::isPositiveInteger($this->_parameters['objectID'])) { $objectID = '$parameters[\'objectID\'] = ' . $this->_parameters['objectID'] . ';' . "\n"; } //set public status if (isset($this->_parameters['public'])) { //if value exists here, use it $public = '$parameters[\'public\'] = ' . ($this->_parameters['public'] ? 'true' : 'false') . ';' . "\n"; } else { //else if it exists during execution, use it or force public status $public = '$parameters[\'public\'] = (isset($parameters[\'public\'])) ? $parameters[\'public\'] : true;' . "\n"; } $headers = $footers = ''; //do not add cache reference if no cache is queried if (!isset($this->_parameters['cache']) || $this->_parameters['cache'] != false) { $footers .= '$content .= \'<!--{elements:\'.base64_encode(serialize(' . var_export($this->_elements, true) . ')).\'}-->\';' . "\n"; } $headers = '$content = "";' . "\n" . '$replace = "";' . "\n" . '$atmIfResults = array();' . "\n" . 'if (!isset($objectDefinitions) || !is_array($objectDefinitions)) $objectDefinitions = array();' . "\n" . $blockAttributes . $objectID . $pageID . $pluginSelection . $languageObject . $public . 'if (isset($parameters[\'item\'])) {' . "\n" . ' $parameters[\'objectID\'] = $parameters[\'item\']->getObjectID();' . "\n" . '} elseif (isset($parameters[\'itemID\']) && sensitiveIO::isPositiveInteger($parameters[\'itemID\']) && !isset($parameters[\'objectID\'])) {' . "\n" . ' $parameters[\'objectID\'] = CMS_poly_object_catalog::getObjectDefinitionByID($parameters[\'itemID\']);' . "\n" . '}' . "\n" . 'if (!isset($object) || !is_array($object)) $object = array();' . "\n" . $polyobjectsDefinitions; } switch ($type) { case self::OUTPUT_PHP: //if header callback exists, add it to module useage for this page if (is_array($this->_headCallBack) && $this->_headCallBack) { if (sensitiveIO::isPositiveInteger($this->_parameters['pageID']) && $this->_parameters['module'] && $this->_parameters['language']) { //add language to callBack infos $this->_headCallBack['language'] = $this->_parameters['language']; $this->_headCallBack['headcode'] = $headers; $this->_headCallBack['footcode'] = $footers; CMS_module::moduleUsage($this->_parameters['pageID'], $this->_parameters['module'], array('headCallback' => array($this->_headCallBack))); } else { $this->raiseError('Missing valid pageID or module codename or language code in parameters to use header callback.'); return false; } } $return = '<?php' . "\n" . '/*Generated on ' . date('r') . ' by ' . CMS_grandFather::SYSTEM_LABEL . ' ' . AUTOMNE_VERSION . " */\n" . 'if(!APPLICATION_ENFORCES_ACCESS_CONTROL || (isset($cms_user) && is_a($cms_user, \'CMS_profile_user\') && $cms_user->hasModuleClearance(\'' . $this->_parameters['module'] . '\', CLEARANCE_MODULE_VIEW))){' . "\n"; $return .= $headers . "\n" . $this->_definition . "\n" . '$content = CMS_polymod_definition_parsing::replaceVars($content, $replace);' . "\n" . $footers . "\n" . 'echo $content;' . "\n" . 'unset($content);' . "\n" . 'unset($replace);'; $return .= '}' . "\n" . '?>'; return CMS_XMLTag::indentPHP($return); break; case self::OUTPUT_RESULT: global $cms_user, $cms_language; //then eval content if (is_object($this->_parser)) { if (isset($this->_parameters['item']) && is_object($this->_parameters['item'])) { //make object available $object[$this->_parameters['item']->getObjectID()] =& $this->_parameters['item']; } $this->_definition = $headers . "\n" . $this->_definition . "\n" . '$content = CMS_polymod_definition_parsing::replaceVars($content, $replace);' . "\n" . $footers . "\n" . 'return $content;' . "\n"; $return = eval(sensitiveIO::sanitizeExecCommand($this->_definition)); } else { if (!is_object($this->_parameters['item'])) { $this->raiseError('Missing valid item in parameters.'); return false; } //make object available $object[$this->_parameters['item']->getObjectID()] = $this->_parameters['item']; //CMS_grandFather::log($this->_definition); $return = eval(sensitiveIO::sanitizeExecCommand('return "' . $this->_definition . '";')); } if (isset($ckeck) && $ckeck === false) { $this->raiseError('Can\'t eval content type to return : ' . $this->_definition); return false; } return $return; break; default: $this->raiseError('Unknown content type to return : ' . $type); return false; break; } }
/** * Return the module code for the specified treatment mode, visualization mode and object. * * @param mixed $modulesCode the previous modules codes (usually string) * @param integer $treatmentMode The current treatment mode (see constants on top of this file for accepted values). * @param integer $visualizationMode The current visualization mode (see constants on top of cms_page class for accepted values). * @param object $treatedObject The reference object to treat. * @param array $treatmentParameters : optionnal parameters used for the treatment. Usually an array of objects. * * @return string : the module code to add * @access public */ function getModuleCode($modulesCode, $treatmentMode, $visualizationMode, &$treatedObject, $treatmentParameters) { switch ($treatmentMode) { case MODULE_TREATMENT_PAGECONTENT_HEADER_CODE: //if this page use a row of this module then add the header code to the page if ($usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename)) { if (isset($usage['headCallback'])) { $modulesCode[$this->_codename] = ''; foreach ($usage['headCallback'] as $headCallback) { //add header codes if (isset($headCallback['tagsCallback'])) { foreach ($headCallback['tagsCallback'] as $key => $headcode) { if (isset($headcode['code'])) { $modulesCode[$this->_codename] .= '<?php' . "\n" . $headCallback['headcode'] . "\n" . $headcode['code'] . "\n" . '?>'; } } } //add forms header if needed if (isset($headCallback['form']) && $headCallback['form']) { $modulesCode[$this->_codename] .= '<?php CMS_poly_definition_functions::formActions(' . var_export($headCallback['form'], true) . ', \'' . $treatedObject->getID() . '\', \'' . $headCallback['language'] . '\', ' . ($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC || $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC_INDEXABLE ? 'true' : 'false') . ', $polymodFormsError, $polymodFormsItems); ?>'; } //add forms callback if needed if (isset($headCallback['formsCallback']) && is_array($headCallback['formsCallback']) && isset($headCallback['headcode'])) { foreach ($headCallback['formsCallback'] as $formName => $formCallback) { foreach ($formCallback as $formFieldID => $callback) { if (io::isPositiveInteger($formFieldID)) { $modulesCode[$this->_codename] .= '<?php' . "\n" . '//callback function to check field ' . $formFieldID . ' for atm-form ' . $formName . "\n" . 'function form_' . $formName . '_' . $formFieldID . '($formName, $fieldID, &$item_' . $formName . '_' . $formFieldID . ') {' . "\n" . ' global $cms_user;' . "\n" . ' global $public_search;' . "\n" . ' global $cms_language;' . "\n" . ' $object[$item_' . $formName . '_' . $formFieldID . '->getObjectID()] = $item_' . $formName . '_' . $formFieldID . ';' . "\n" . ' ' . $headCallback['headcode'] . "\n" . ' ' . $callback . "\n" . ' return false;' . "\n" . '}' . "\n" . '?>'; } elseif ($formFieldID == 'form') { $modulesCode[$this->_codename] .= '<?php' . "\n" . '//callback function for atm-form ' . $formName . "\n" . 'function form_' . $formName . '($formName, &$item_' . $formName . ') {' . "\n" . ' global $cms_user;' . "\n" . ' global $public_search;' . "\n" . ' global $cms_language;' . "\n" . ' $object[$item_' . $formName . '->getObjectID()] = $item_' . $formName . ';' . "\n" . ' ' . $headCallback['headcode'] . "\n" . ' ' . $callback . "\n" . ' return true;' . "\n" . '}' . "\n" . '?>'; } } } } } } } return $modulesCode; break; case MODULE_TREATMENT_ROWS_EDITION_LABELS: $modulesCode[$this->_codename] = ''; //if user has rights on module if ($treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) { if (!isset($treatmentParameters['request'])) { //add form to choose object to display $modulesCode[$this->_codename] = ' <h1>' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_ROW_TAGS_CHOOSE, false, MOD_POLYMOD_CODENAME) . '<select onchange="Ext.get(\'help' . $this->_codename . '\').getUpdater().update({url: \'' . PATH_ADMIN_WR . '/help-detail.php\',params: {module: \'' . $this->_codename . '\',object: this.value, mode:' . MODULE_TREATMENT_ROWS_EDITION_LABELS . '}});"> <option value="">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_CHOOSE) . '</option> <optgroup label="' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_ROW_TAGS_EXPLANATION, false, MOD_POLYMOD_CODENAME) . '"> <option value="block">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS, false, MOD_POLYMOD_CODENAME) . '</option> <option value="search">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_SEARCH_TAGS, false, MOD_POLYMOD_CODENAME) . '</option> <option value="working">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS) . '</option> <option value="working-polymod">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_POLYMOD_TAGS, false, MOD_POLYMOD_CODENAME) . '</option> <option value="vars">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS) . '</option> <option value="forms">' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_FORMS, false, MOD_POLYMOD_CODENAME) . '</option> </optgroup> <optgroup label="' . $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_ROW_OBJECTS_VARS_EXPLANATION, false, MOD_POLYMOD_CODENAME) . '">'; $modulesCode[$this->_codename] .= CMS_poly_module_structure::viewObjectInfosList($this->_codename, $treatmentParameters["language"], @$treatmentParameters['request'][$this->_codename . 'object']); $modulesCode[$this->_codename] .= ' </optgroup>'; $modulesCode[$this->_codename] .= ' </select></h1> <div id="help' . $this->_codename . '"></div> '; } //then display chosen object infos if (isset($treatmentParameters['request'][$this->_codename]) && isset($treatmentParameters['request'][$this->_codename . 'object'])) { switch ($treatmentParameters['request'][$this->_codename . 'object']) { case 'block': $moduleLanguages = CMS_languagesCatalog::getAllLanguages($this->_codename); foreach ($moduleLanguages as $moduleLanguage) { $moduleLanguagesCodes[] = $moduleLanguage->getCode(); } $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_TAGS_EXPLANATION, array($this->_codename, implode(', ', $moduleLanguagesCodes)), MOD_POLYMOD_CODENAME); break; case 'search': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_SEARCH_TAGS_EXPLANATION, false, MOD_POLYMOD_CODENAME); break; case 'working': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_TAGS_EXPLANATION); break; case 'working-polymod': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_WORKING_POLYMOD_TAGS_EXPLANATION, array(implode(', ', CMS_modulesCatalog::getAllCodenames())), MOD_POLYMOD_CODENAME); break; case 'vars': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_GENERAL_VARS_EXPLANATION, array($treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask(), $treatmentParameters["language"]->getDateFormatMask())); break; case 'forms': $modulesCode[$this->_codename] .= $treatmentParameters["language"]->getMessage(self::MESSAGE_PAGE_BLOCK_FORMS_EXPLANATION, false, MOD_POLYMOD_CODENAME); break; default: //object info $modulesCode[$this->_codename] .= CMS_poly_module_structure::viewObjectRowInfos($this->_codename, $treatmentParameters["language"], $treatmentParameters['request'][$this->_codename . 'object']); break; } } } return $modulesCode; break; case MODULE_TREATMENT_EDITOR_CODE: if ($treatmentParameters["editor"] == "fckeditor" && $treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) { if (!isset($modulesCode["Default"]['polymod'])) { $pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject(); if (is_array($pluginDefinitions) && $pluginDefinitions) { $languages = implode(',', array_keys(CMS_languagesCatalog::getAllLanguages())); //This is an exception of the method, because here we return an array, see admin/fckeditor/fckconfig.php for the detail $modulesCode["Default"]['polymod'] = "'polymod'"; $modulesCode["modulesDeclaration"]['polymod'] = "FCKConfig.Plugins.Add( 'polymod', '" . $languages . "' );"; } } $plugins = array(); //get all objects for module $moduleObjects = CMS_poly_object_catalog::getObjectsForModule($this->_codename); foreach ($moduleObjects as $object) { $fields = CMS_poly_object_catalog::getFieldsDefinition($object->getID()); foreach ($fields as $field) { $fieldObject = $field->getTypeObject(true); if (method_exists($fieldObject, 'getUsedPlugins')) { $plugins = array_merge($plugins, $fieldObject->getUsedPlugins()); } } } $plugins = array_unique($plugins); // create specific polymod toolbar $modulesCode["ToolbarSets"][] = "FCKConfig.ToolbarSets[\"" . $this->_codename . "\"] = [\n\t\t\t\t\t\t\t\t['Source','Undo','Redo'],\n\t\t\t\t\t\t\t\t['Cut','Copy','Paste','PasteText','PasteWord'],\n\t\t\t\t\t\t\t\t['OrderedList','UnorderedList','-','Outdent','Indent'],\n\t\t\t\t\t\t\t\t['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],\n\t\t\t\t\t\t\t\t['Link','Unlink','Anchor'" . ($plugins ? ',' . implode(",", $plugins) : '') . "],\n\t\t\t\t\t\t\t\t['Table','Rule','SpecialChar']\n\t\t\t\t\t\t\t];"; } return $modulesCode; break; case MODULE_TREATMENT_EDITOR_PLUGINS: if ($treatmentParameters["editor"] == "fckeditor" && $treatmentParameters["user"]->hasModuleClearance($this->_codename, CLEARANCE_MODULE_EDIT)) { if (!isset($modulesCode['polymod'])) { $modulesCode['polymod'] = ''; $pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject(); if (is_array($pluginDefinitions) && $pluginDefinitions) { foreach ($pluginDefinitions as $pluginDefinition) { $modulesCode['polymod'] .= $modulesCode['polymod'] ? ', ' : ''; $modulesCode['polymod'] .= $pluginDefinition->getLabel($treatmentParameters["user"]->getLanguage()); } } } } break; case MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT: //if object is a polyobject and module is the current object's module if ($treatedObject instanceof CMS_poly_object && $this->_codename == CMS_poly_object_catalog::getModuleCodenameForObject($treatedObject->getID())) { //send notification of the validation result to polyobject $treatedObject->afterValidation($treatmentParameters['result']); } break; case MODULE_TREATMENT_ALERTS: //only if user has validation clearances if ($treatmentParameters['user']->hasValidationClearance($this->_codename)) { $modulesCode[$this->_codename] = array(ALERT_LEVEL_VALIDATION => array('label' => self::MESSAGE_ALERT_LEVEL_VALIDATION, 'description' => self::MESSAGE_ALERT_LEVEL_VALIDATION_DESCRIPTION)); } return $modulesCode; break; } return $modulesCode; }
/** * Changes The item data (in the DB) from one location to another. * * @param CMS_resource $resource The resource concerned by the data location change * @param string $locationFrom The starting location among "edited", "edition", "public", "archived", "deleted" * @param string $locationTo The ending location among "edited", "edition", "public", "archived", "deleted" * @param boolean $copyOnly If true, data is not deleted from the original location * @return void * @access private */ protected function _changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly = false) { //check queried data location change if (!parent::_changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly)) { return false; } //get all secondary resources concerned by this validation $secondaryResourceIds = $resource->getAllSecondaryResourcesForPrimaryResource(); if (is_array($secondaryResourceIds) && $secondaryResourceIds) { foreach ($secondaryResourceIds as $secondaryResourceId) { if ($locationTo != RESOURCE_DATA_LOCATION_DELETED && $locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { //move the data CMS_modulePolymodValidation::moveResourceData($this->getCodename(), $secondaryResourceId, $locationFrom, $locationTo, $copyOnly); } } } //then move resource data for concerned resource CMS_modulePolymodValidation::moveResourceData($this->getCodename(), $resource->getID(), $locationFrom, $locationTo, $copyOnly); }
/** * Compute the tag * * @return string the PHP / HTML content computed * @access private */ protected function _compute() { //return code $return = $this->_computeChilds(); $strict = isset($this->_attributes['strict']) && ($this->_attributes['strict'] == 'true' || $this->_attributes['strict'] == true || $this->_attributes['strict'] == 1) ? true : false; //Ajax code $ajaxCode = ' if(io::request(\'out\') == \'xml\') { $xmlCondition = CMS_polymod_definition_parsing::replaceVars("' . $this->replaceVars($this->_attributes['what'], false, false, array($this, 'encloseWithPrepareVar')) . '", $replace); if ($xmlCondition) { $func = create_function("","return (".$xmlCondition.");"); if ($func && $func()) { $cms_view = CMS_view::getInstance(); $content = $replace = \'\';'; if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $ajaxCode .= 'ob_start();'; $xml = new CMS_xml2Array($return); $ajaxCode .= $xml->toXML($xml->getParsedArray(), false, true) . '<?php '; $ajaxCode .= '$content = ob_get_contents(); ob_end_clean(); $replace=array();'; } else { $ajaxCode .= $return; } $ajaxCode .= '$content = CMS_polymod_definition_parsing::replaceVars($content, $replace); $cms_view->setDisplayMode(' . ($strict ? 'CMS_view::SHOW_XML' : 'CMS_view::SHOW_RAW') . '); $cms_view->setContent($content); //output empty XML response unset($content); unset($replace); $cms_view->setContentTag(\'data\'); $cms_view->show(); } } unset($xmlCondition); }'; if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $code = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($this->_returnComputedDatas($ajaxCode)))); CMS_module::moduleUsage($this->_computeParams['object']->getID(), MOD_STANDARD_CODENAME, array('headCallback' => array($code))); } else { $this->_tagHeaderCode = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($ajaxCode))); } return $return; }