$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'); $rowId = sensitiveIO::request('rowType', 'sensitiveIO::isPositiveInteger'); $rowTag = sensitiveIO::request('rowTag'); $cs = sensitiveIO::request('cs');
/** * 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(); }
$content .= ' <dialog-title type="admin_h2">' . $cms_language->getMessage(MESSAGE_PAGE_PLUGIN_DEFINITIONS, false, MOD_POLYMOD_CODENAME) . ' :</dialog-title> <br />'; if (sizeof($pluginDefinitions)) { $content .= '<table border="0" cellpadding="2" cellspacing="2"> <tr> <th class="admin">' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_TITLE) . '</th> <th class="admin">' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_DESCRIPTION) . '</th> <th class="admin">' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_ACTIONS) . '</th> </tr>'; $copunt = 0; foreach ($pluginDefinitions as $pluginDefinition) { $count++; $td_class = $count % 2 == 0 ? "admin_lightgreybg" : "admin_darkgreybg"; $content .= '<tr alt="ID : ' . $pluginDefinition->getID() . '" title="ID : ' . $pluginDefinition->getID() . '"> <td class="' . $td_class . '">' . $pluginDefinition->getLabel($cms_language) . '</td> <td class="' . $td_class . '">' . $pluginDefinition->getDescription($cms_language) . '</td> <td class="' . $td_class . '"> <table border="0" cellpadding="2" cellspacing="0"> <tr>'; $canBeDeleted = true; if ($canBeDeleted) { $content .= ' <form action="' . $_SERVER["SCRIPT_NAME"] . '" method="post" onSubmit="return confirm(\'' . addslashes($cms_language->getMessage(MESSAGE_PAGE_ACTION_DELETEPLUGINCONFIRM, array($pluginDefinition->getLabel($cms_language)), MOD_POLYMOD_CODENAME)) . ' ?\')"> <input type="hidden" name="cms_action" value="deletePlugin" /> <input type="hidden" name="pluginDefinition" value="' . $pluginDefinition->getID() . '" /> <input type="hidden" name="moduleCodename" value="' . $moduleCodename . '" /> <input type="hidden" name="object" value="' . $object->getID() . '" /> <td class="admin"><input type="submit" class="admin_input_' . $td_class . '" value="' . $cms_language->getMessage(MESSAGE_PAGE_ACTION_DELETE) . '" /></td> </form>'; }
/** * Import object from given array datas * * @param array $data The object datas to import * @param array $params The import parameters. * array( * module => false|true : the module to create object (required) * 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 */ function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { if (!isset($params['module'])) { $infos .= 'Error : missing module codename for object importation ...' . "\n"; return false; } $module = CMS_modulesCatalog::getByCodename($params['module']); if ($module->hasError()) { $infos .= 'Error : invalid module for object importation : ' . $params['module'] . "\n"; return false; } if (!$this->getID() && CMS_poly_object_catalog::objectUuidExists($data['uuid'])) { //check imported uuid. If objects does not have an Id, the uuid must be unique or must be regenerated $uuid = io::uuid(); //store old uuid relation $idsRelation['objects-uuid'][$data['uuid']] = $uuid; $data['uuid'] = $uuid; } //set object uuid if not exists if (!$this->_objectValues["uuid"]) { $this->_objectValues["uuid"] = $data['uuid']; } if (isset($data['labels'])) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->setValues($data['labels']); $label->writeToPersistence(); $this->setValue("labelID", $label->getID()); } if (isset($data['descriptions'])) { $description = new CMS_object_i18nm($this->getValue("descriptionID")); $description->setValues($data['descriptions']); $description->writeToPersistence(); $this->setValue("descriptionID", $description->getID()); } if (isset($data['params']['resourceUsage'])) { $this->setValue("resourceUsage", $data['params']['resourceUsage']); } if (isset($data['params']['admineditable'])) { $this->setValue("admineditable", $data['params']['admineditable']); } if (isset($data['params']['indexable'])) { $this->setValue("indexable", $data['params']['indexable']); } if (isset($data['params']['multilanguage'])) { $this->setValue("multilanguage", $data['params']['multilanguage']); } if (isset($data['params']['composedLabel'])) { $this->setValue("composedLabel", $module->convertDefinitionString($data['params']['composedLabel'], false)); } if (isset($data['params']['previewURL'])) { $this->setValue("previewURL", $module->convertDefinitionString($data['params']['previewURL'], false)); } if (isset($data['params']['indexURL'])) { $this->setValue("indexURL", $module->convertDefinitionString($data['params']['indexURL'], false)); } if (isset($data['params']['resultsDefinition'])) { $this->setValue("resultsDefinition", $module->convertDefinitionString($data['params']['resultsDefinition'], false)); } //write object if (!$this->writeToPersistence()) { $infos .= 'Error : can not write object ...' . "\n"; return false; } //if current object id has changed from imported id, set relation if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) { $idsRelation['objects'][$data['id']] = $this->getID(); } //set this object into definition to convert array so it can be converted again at end of import process $idsRelation['definitionToConvert'][] = $this; $return = true; //object fields if (isset($data['fields'])) { foreach ($data['fields'] as $fieldDatas) { $importType = ''; if (isset($fieldDatas['type'])) { if (isset($fieldDatas['uuid']) && ($id = CMS_poly_object_catalog::fieldExists($params['module'], $fieldDatas['uuid']))) { //field already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $field = new CMS_poly_object_field($id); $importType = ' (Update)'; } } else { //create new field if we can if (!isset($params['create']) || $params['create'] == true) { $field = new CMS_poly_object_field(); $importType = ' (Creation)'; } } if (isset($field)) { if ($field->fromArray($fieldDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Field "' . $field->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of field ...' . $importType . "\n"; } } } else { $return = false; $infos .= 'Error during import of field : missing type' . "\n"; } } } //object rss feeds if (isset($data['rss'])) { foreach ($data['rss'] as $rssDatas) { $importType = ''; if (isset($rssDatas['uuid']) && ($id = CMS_poly_object_catalog::rssExists($params['module'], $rssDatas['uuid']))) { //rss already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $rss = new CMS_poly_rss_definitions($id); $importType = ' (Update)'; } } else { //create new rss if we can if (!isset($params['create']) || $params['create'] == true) { $rss = new CMS_poly_rss_definitions(); $importType = ' (Creation)'; } } if (isset($rss)) { if ($rss->fromArray($rssDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'RSS feed "' . $rss->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of rss feed ...' . $importType . "\n"; } } } } //plugins wysiwyg if (isset($data['plugins'])) { foreach ($data['plugins'] as $pluginDatas) { $importType = ''; if (isset($pluginDatas['uuid']) && ($id = CMS_poly_object_catalog::pluginExists($params['module'], $pluginDatas['uuid']))) { //plugin already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $plugin = new CMS_poly_plugin_definitions($id); $importType = ' (Update)'; } } else { //create new plugin if we can if (!isset($params['create']) || $params['create'] == true) { $plugin = new CMS_poly_plugin_definitions(); $importType = ' (Creation)'; } } if (isset($plugin)) { if ($plugin->fromArray($pluginDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Plugin Wysiwyg "' . $plugin->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of plugin wysiwyg ...' . $importType . "\n"; } } } } return $return; }