$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
         $codeTopaste = str_replace('<img ', '<img contenteditable="false" unselectable="on" ', $codeTopaste);
         //encode all ampersand without reencode already encoded ampersand
         $codeTopaste = sensitiveIO::reencodeAmpersand($codeTopaste);
         if ($codeTopaste) {
             //add identification span tag arround code to paste
             $codeTopaste = '<span id="polymod-' . $pluginId . '-' . $itemId . '" class="polymod" title="' . io::htmlspecialchars($selectedPlugin->getLabel($cms_language) . ' : ' . trim($item->getLabel($cms_language))) . '">' . $codeTopaste . '</span>';
         }
         $content = $codeTopaste;
     } elseif (sensitiveIO::isPositiveInteger($itemId) && $selectedPlugin->needSelection()) {
         $codeTopaste = '<span id="polymod-' . $pluginId . '-' . $itemId . '" class="polymod">' . $selectedContent . '</span>';
         $content = $codeTopaste;
     } else {
         $selectedContent = $selectedContent ? $selectedContent : ' ';
         $content = $selectedContent;
     }
     break;
 case 'setRowParameters':
     $tpl = sensitiveIO::request('template', 'sensitiveIO::isPositiveInteger');
Exemple #2
0
 /**
  * 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();
 }