/** * 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_BLOCK_TAGS: return parent::treatWantedTag($tag, $tagContent, $treatmentMode, $visualizationMode, $treatedObject, $treatmentParameters); break; case MODULE_TREATMENT_CLIENTSPACE_TAGS: return parent::treatWantedTag($tag, $tagContent, $treatmentMode, $visualizationMode, $treatedObject, $treatmentParameters); break; case MODULE_TREATMENT_PAGECONTENT_TAGS: if (!$treatedObject instanceof CMS_page) { $this->raiseError('$treatedObject must be a CMS_page object'); return false; } switch ($tag->getName()) { case "span": $ids = explode('-', $tag->getAttribute('id')); $selectedPluginID = (int) $ids[1]; $selectedItem = (int) $ids[2]; //then create the code to paste for the current selected object if any if (sensitiveIO::isPositiveInteger($selectedItem) && sensitiveIO::isPositiveInteger($selectedPluginID)) { //get plugin $selectedPlugin = new CMS_poly_plugin_definitions($selectedPluginID); //get plugin definition $definition = $selectedPlugin->getValue('compiledDefinition'); //set parsing parameters $parameters = array(); $parameters['itemID'] = $selectedItem; $parameters['pageID'] = $treatedObject->getID(); $parameters['public'] = $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC || $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC_INDEXABLE ? true : false; //get originaly selected text if (!$selectedPlugin->needSelection()) { $parameters['selection'] = ''; } else { $hasSelection = preg_match('#<!--(.*)-->#s', $tag->getInnerContent(), $matches); $parameters['selection'] = io::decodeEntities($hasSelection ? $matches[1] : $tag->getInnerContent()); //$parameters['selection'] = io::decodeEntities($tag->getInnerContent()); } $tagContent = '<?php $parameters = ' . var_export($parameters, true) . ';' . "\n" . io::substr($definition, 5); //save in global var the page ID who need this module so we can add the header code later. CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('block' => true)); //Cache management if ($parameters['public']) { //create definition hash $cacheHash = md5(serialize(array('definition' => $tagContent, 'parameters' => $parameters))); $tagContent = CMS_cache::wrapCode($cacheHash, $tagContent); } } return $tagContent; break; } break; case MODULE_TREATMENT_PAGEHEADER_TAGS: $content = parent::treatWantedTag($tag, $tagContent, $treatmentMode, $visualizationMode, $treatedObject, $treatmentParameters); if ($treatedObject instanceof CMS_page && $tag->getName() === "atm-meta-tags") { $oembed = CMS_polymod_oembed_definition_catalog::getByCodename($treatedObject->getCodename()); if ($oembed && CMS_poly_object_catalog::getModuleCodenameForObjectType($oembed->getObjectdefinition()) === $this->_codename) { $content .= '<?php ' . "\n" . 'echo CMS_polymod_oembed_definition::getDiscoveryEndpoint(); ?>'; } } return $content; break; case MODULE_TREATMENT_WYSIWYG_INNER_TAGS: switch ($tag->getName()) { case "span": global $cms_language; $ids = explode('-', $tag->getAttribute('id')); $selectedPluginID = (int) $ids[1]; $selectedItem = (int) $ids[2]; //then create the code to paste for the current selected object if any if (sensitiveIO::isPositiveInteger($selectedItem) && sensitiveIO::isPositiveInteger($selectedPluginID)) { //get plugin $selectedPlugin = new CMS_poly_plugin_definitions($selectedPluginID); //get selected item $item = CMS_poly_object_catalog::getObjectByID($selectedItem, false, $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC || $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC_INDEXABLE ? true : false); if ($item && !$item->hasError()) { //get originaly selected text if any $selectedText = ''; if ($selectedPlugin->needSelection()) { $hasSelection = preg_match('#<!--(.*)-->#s', $tag->getInnerContent(), $matches); $selectedText = $hasSelection ? $matches[1] : $tag->getInnerContent(); $tagContent = '<span id="polymod-' . $selectedPluginID . '-' . $selectedItem . '" class="polymod" title="' . io::htmlspecialchars($selectedPlugin->getLabel($cms_language) . ' : ' . trim($item->getLabel($cms_language))) . '">' . $selectedText . '</span>'; } else { $tagContent = '<span id="polymod-' . $selectedPluginID . '-' . $selectedItem . '" class="polymod" title="' . io::htmlspecialchars($selectedPlugin->getLabel($cms_language) . ' : ' . trim($item->getLabel($cms_language))) . '">' . CMS_poly_definition_functions::pluginCode($selectedPluginID, $selectedItem, '', $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC || $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC_INDEXABLE ? true : false, true) . '</span>'; } } else { $tagContent = ''; } } //strip cache comment $tagContent = preg_replace('#<!--{cache:(.*)}-->#Us', '', $tagContent); //encode all ampersand without reencode already encoded ampersand $tagContent = sensitiveIO::reencodeAmpersand($tagContent); return $tagContent; break; } return $tagContent; break; case MODULE_TREATMENT_WYSIWYG_OUTER_TAGS: switch ($tag->getName()) { case "span": $ids = explode('-', $tag->getAttribute('id')); $selectedPluginID = (int) $ids[1]; $selectedItem = (int) $ids[2]; //then create the code to paste for the current selected object if any if (sensitiveIO::isPositiveInteger($selectedItem) && sensitiveIO::isPositiveInteger($selectedPluginID)) { //get plugin $selectedPlugin = new CMS_poly_plugin_definitions($selectedPluginID); //get originaly selected text if any $selectedText = $commentSelectedText = ''; if ($selectedPlugin->needSelection()) { $hasSelection = preg_match('#<!--(.*)-->#s', $tag->getInnerContent(), $matches); $selectedText = $hasSelection ? $matches[1] : $tag->getInnerContent(); $commentSelectedText = '<!--' . ($hasSelection ? $matches[1] : $tag->getInnerContent()) . '-->'; } $tagContent = '<span id="polymod-' . $selectedPluginID . '-' . $selectedItem . '" class="polymod">' . "\n" . '<?php echo CMS_poly_definition_functions::pluginCode(\'' . $selectedPluginID . '\', \'' . $selectedItem . '\', ' . var_export($selectedText, true) . ', true); ?>' . "\n" . $commentSelectedText . '</span>'; } return $tagContent; break; } return $tagContent; break; } return $tag->getContent(); }
$mod->processValidation($validation, VALIDATION_OPTION_ACCEPT); //Log action $log = new CMS_log(); $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_DIRECT_VALIDATION, $cms_user, $codename, $item->getStatus(), 'Item \'' . $item->getLabel() . '\' (' . $item->getObjectDefinition()->getLabel($cms_language) . ')', $item); } } } } break; case 'pluginSelection': $view->setDisplayMode(CMS_view::SHOW_RAW); $selectedContent = sensitiveIO::request('content'); $pluginId = sensitiveIO::request('plugin'); $selectedPlugin = new CMS_poly_plugin_definitions($pluginId); //then create the code to paste for the current selected object if any if (sensitiveIO::isPositiveInteger($itemId) && !$selectedPlugin->needSelection()) { //$item = CMS_poly_object_catalog::getObjectByID($selectedItem); $definition = $selectedPlugin->getValue('definition'); $parameters = array(); $parameters['itemID'] = $itemId; $parameters['module'] = $codename; $cms_page = CMS_session::getPage(); if (is_object($cms_page) && !$cms_page->hasError()) { $parameters['pageID'] = $cms_page->getID(); } $parameters['selection'] = io::decodeEntities($selectedContent); $parameters['public'] = false; $parameters['plugin-view'] = true; $definitionParsing = new CMS_polymod_definition_parsing($definition, true, CMS_polymod_definition_parsing::PARSE_MODE); $codeTopaste = $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters); //add some attributes to images to prevent resizing into editor
/** * Return a wysiwyg plugin output for given parameters * * @param integer $pluginID : the plugin id to use * @param integer $itemID : the item id to use * @param string $selection : the selected wysiwyg text if any * @param boolean $public : the data status * @param boolean $pluginView : is this plugin is intended to be shown in wysiwyg view ? (default false) * @return string : the plugin output * @access public * @static */ static function pluginCode($pluginID, $itemID, $selection, $public = false, $pluginView = false) { global $cms_user; //then create the code to paste for the current selected object if any if (sensitiveIO::isPositiveInteger($itemID) && sensitiveIO::isPositiveInteger($pluginID)) { //get plugin $plugin = new CMS_poly_plugin_definitions($pluginID); //set execution parameters $parameters = array(); $parameters['itemID'] = $itemID; $parameters['public'] = $public; if ($pluginView) { $parameters['plugin-view'] = true; } //get originaly selected text if (!$plugin->needSelection()) { $parameters['selection'] = ''; } else { $parameters['selection'] = io::decodeEntities($selection); } //this line is used to optimise text fields (see CMS_object_text) which use a lot of plugin codes. //in this case, items are searched before then put in this global var so it is not necessary to do one search for each of them if (isset($GLOBALS['polymod']['preparedItems'][$plugin->getValue('objectID')][$itemID])) { $parameters['item'] = $GLOBALS['polymod']['preparedItems'][$plugin->getValue('objectID')][$itemID]; } //eval item content ob_start(); eval(sensitiveIO::sanitizeExecCommand(sensitiveIO::stripPHPTags($plugin->getValue('compiledDefinition')))); $data = ob_get_contents(); ob_end_clean(); return $data; } }