/** * Overrides the standard w3sTemplateEngine constructor to render only the * a template without contents. * * @param The id of the template to render * */ public function __construct($idTemplate, $otherTemplate) { $this->idTemplate = $idTemplate; $template = DbFinder::from('W3sTemplate')->with('W3sProject')->findPK($idTemplate); if ($template != null) { $this->otherTemplate = $otherTemplate; // Finds the current template for slot mapper, if exists $currentTemplate = sprintf('[%s][%s]', $idTemplate, $otherTemplate); $slots = DbFinder::from('W3sSlotMapper')->where('Templates', $currentTemplate)->count(); // Current template doesn't exist if ($slots == 0) { // Checks for corrispondence, tring to invert destination with source $currentTemplate = sprintf('[%s][%s]', $otherTemplate, $idTemplate); $slots = DbFinder::from('W3sSlotMapper')->where('Templates', $currentTemplate)->count(); if ($slots > 0) { $this->currentTemplate = $currentTemplate; } } else { $this->currentTemplate = sprintf('[%s][%s]', $idTemplate, $otherTemplate); } $this->templateName = $template->getTemplateName(); $this->projectName = $template->getW3sProject()->getProjectName(); $this->pageContents = w3sCommonFunctions::readFileContents(self::getTemplateFile($this->projectName, $this->templateName)); } else { $this->templateName = null; $this->projectName = null; $this->pageContents = w3sCommonFunctions::toI18n('The requested template has not been found in the database and cannot be rendered.'); } }
/** * Inserts the menu links related to the inserted content, * into the w3sMenuElements table * * @return bool * */ protected function setDefaultRelatedElements() { $bRollBack = false; $con = Propel::getConnection(); $con = w3sPropelWorkaround::beginTransaction($con); for ($i = 1; $i < 4; $i++) { $newMenu = new W3sMenuElement(); $contentValues = array("ContentId" => $this->content->getId(), "PageId" => 0, "Link" => w3sCommonFunctions::toI18n('This is a link'), "ExternalLink" => '', "Image" => '', "RolloverImage" => '', "Position" => $i); $newMenu->fromArray($contentValues); $result = $newMenu->save(); if ($newMenu->isModified() && $result == 0) { $bRollBack = true; break; } } if (!$bRollBack) { // Everything was fine so W3StudioCMS commits to database $con->commit(); $result = true; } else { // Something was wrong so W3StudioCMS aborts the operation and restores to previous status w3sPropelWorkaround::rollBack($con); $result = false; } }
public function executeRemove($request) { if ($request->hasParameter('themeName')) { $theme = new w3sThemeImport(); $theme->remove($request->getParameter('themeName')); return $this->renderPartial('refresh'); } else { $this->getResponse()->setStatusCode(404); $message = w3sCommonFunctions::toI18n('themeName parameter is required.'); return $this->renderText(w3sCommonFunctions::displayMessage($message, 'error', true)); } }
/** * Saves the metatags for the current page * */ public function executeLoadMetas($request) { if ($request->hasParameter('lang') && $request->hasParameter('page')) { if ($this->getRequestParameter('lang') != 0 && $this->getRequestParameter('page') != 0) { $metatag = W3sSearchEnginePeer::getFromPageAndLanguage($this->getRequestParameter('lang'), $this->getRequestParameter('page')); $metatagManager = new w3sMetatagsManager($metatag); return $this->renderPartial('metatagsInterface', array('metatagManager' => $metatagManager)); } else { $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('A required parameter has not a valid value.')); } } else { $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('A required parameter misses')); } }
public function executeEdit(sfWebRequest $request) { if ($request->hasParameter('idGroup') && ($request->hasParameter('groupName') || $request->hasParameter('idTemplate'))) { $group = DbFinder::from('W3sGroup')->findPK($this->getRequestParameter('idGroup')); if ($group != null) { $groupManager = new w3sGroupManager($group); $result = $groupManager->edit($request->getParameter('groupName'), $request->getParameter('idTemplate')); } else { $result = 2; } $groupEditor = null; if ($result != 1) { $this->getResponse()->setStatusCode(404); $groupEditor = new w3sGroupEditorForEdit($request->getParameter('idGroup'), $request->getParameter('groupName')); } return $this->renderPartial('edit', array('result' => $result, "groupEditor" => $groupEditor)); } else { $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('A required parameter misses.')); } }
/** * Renders the editor * * @return string * */ public function render() { $options = DbFinder::from('W3sTemplate')->find(); return sprintf($this->editorSkeleton, label_for('group_name', w3sCommonFunctions::toI18n('Group name:')), input_tag('w3s_group_name', ''), label_for('template_name', w3sCommonFunctions::toI18n('Template name:')), select_tag('w3s_templates_select', objects_for_select($options, 'getId', 'getTemplateName')), link_to_function(w3sCommonFunctions::toI18n('Add Group'), 'W3sGroup.add()', 'id="w3s_change_button" class="link_button"')); }
/** * Executes openEditor action * */ public function executeOpenEditor($request) { // The parameters passed to the forwarded action are already setted in the javascript if ($request->hasParameter('idContent') && $this->getRequestParameter('idContent') > 0) { $content = W3sContentPeer::retrieveByPk($this->getRequestParameter('idContent')); if ($content != null) { $this->editor = w3sEditorFactory::create($content); return $this->renderPartial('showEditor'); } } $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('The content you are trying to edit does not exists anymore.')); }
/** * Renames the page */ public function executeRename($request) { if ($request->hasParameter('idPage') && $request->hasParameter('newName')) { $page = W3sPagePeer::retrieveByPk($this->getRequestParameter('idPage')); if ($page != null) { $page->setPageName($this->getRequestParameter('newName')); $page->save(); $fileManager = new w3sFileManager($this->getRequestParameter('curLang'), $this->getRequestParameter('curPage')); return $this->renderPartial('listPages', array('fileManager' => $fileManager)); } else { $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('The requested page does not exists anymore.')); } } else { $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('One or more required parameter are missing.')); } }
/** * Deletes a content * */ public function executeDelete($request) { if ($request->hasParameter('idContent')) { $currentContent = DbFinder::from('W3sContent')->findPK($request->getParameter('idContent')); $this->content = w3sContentManagerFactory::create($currentContent->getContentTypeId(), $currentContent); $result = $this->content->delete(); if ($result != 1) { $this->getResponse()->setStatusCode(404); return $this->renderText($this->content->displayError($result, true)); } } else { $this->getResponse()->setStatusCode(404); return $this->renderText(w3sCommonFunctions::toI18n('A required parameter misses.')); } }
/** * setMessageErrors. Fills the standard error messages */ protected function setMessageErrors() { $this->errors[2] = w3sCommonFunctions::toI18n('An error occoured while adding the new content.'); $this->errors[4] = w3sCommonFunctions::toI18n('An error occoured while editing the selected content.'); $this->errors[8] = w3sCommonFunctions::toI18n('An error occoured while deleting the selected content.'); $this->errors[16] = w3sCommonFunctions::toI18n('The content is the same of the one stored: nothing to do.'); }
/** * Checks if a slot map exists between the template related to current group and the * template related to the group user wants to change * * @param The id of the destionation template * * @return string * */ public function checkMapping($destTemplate) { // Retrieves the template related to the current group $group = DbFinder::from('W3sGroup')->with('W3sTemplate')->findPK($this->idGroup); $sourceTemplate = $group->getW3sTemplate()->getId(); // Checks if user chooses a group which have a different template from the one // that belongs current group if ($sourceTemplate != $destTemplate) { // Checks for slot mapping $this->currentTemplate = sprintf('[%s][%s]', $sourceTemplate, $destTemplate); $sourceSlotsCount = DbFinder::from('W3sSlotMapper')->where('Templates', $this->currentTemplate)->count(); // When no slots mapping has been found, tries to invert source and destination template if ($sourceSlotsCount == 0) { $this->currentTemplate = sprintf('[%s][%s]', $destTemplate, $sourceTemplate); $sourceSlotsCount = DbFinder::from('W3sSlotMapper')->where('Templates', $this->currentTemplate)->count(); } // A mapping exists if ($sourceSlotsCount > 0) { // Checks if all the slots has been mapped. Obviously there's no need to // map all the slots $templateSlotsCount = DbFinder::from('W3sSlot')->where('TemplateId', $this->currentTemplate)->count(); // Not all the slots has been mapped. A warning is displayed if ($sourceSlotsCount != $templateSlotsCount) { $result = w3sCommonFunctions::toI18n('Warning: not all the source template\'s slots are not mapped on the destination template.'); } else { $result = w3sCommonFunctions::toI18n('All the slots of both templates has been matched.'); } } else { $result = w3sCommonFunctions::toI18n('There\'s not exist any map between templates\'s slots.'); } // User can always change the maps he made $result .= sprintf(' <a href="#" onclick="W3sControlPanel.doSlotMapping(%s, %s, \'%s\'); return false;" class="w3s_slot_link">%s</a>', $sourceTemplate, $destTemplate, sfConfig::get("app_w3s_web_skin_images_dir"), w3sCommonFunctions::toI18n('Map Slots')); } else { // When user choose a group which have the same template, no slot map is required $result = w3sCommonFunctions::toI18n('The templates are the same. There is not needed any map.'); } return $result; }
public static function displayMessage($message, $type = 'error', $closeLink = true) { $class = $type . '_message'; $result = '<div id="w3s_message"><p class="' . $class . '">%s</p></div>'; if ($closeLink) { $result .= '<div id="w3s_message_close_section"><a href="#" onclick="W3sWindow.closeModal();">%s</a></div>'; $result = sprintf($result, $message, w3sCommonFunctions::toI18n('Close')); } else { $result = sprintf($result, $message); } return $result; }