function run_build_backend($task, $args) { ini_set("memory_limit", "2048M"); // get configuration // define constants define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'backend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; // $databaseManager = new sfDatabaseManager(); // $databaseManager->initialize(); if (!class_exists("XMLParser")) { include sfConfig::get('sf_root_dir') . "/lib/tools/XMLParser.class.php"; } if (!class_exists("FileHelper")) { include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php"; } $modules = FileHelper::getSubElements(sfConfig::get('sf_root_dir') . "/apps/" . SF_APP . "/modules", "folder"); $content = "function initBindings()\n{\n"; $contentTemplate = ""; echo_cms_title("Building backend..."); foreach ($modules as $module => $path) { if ($module == "admin") { $module = "tag"; } if (substr($module, 0, 1) == ".") { continue; } $objects1 = array(); $objects2 = array(); $objectsDone = array(); if (!is_readable($path . "/config/leftTree.xml") && !is_readable($path . "/config/mainList.xml")) { continue; } else { $objects1 = XMLParser::getXMLdataValues($path . "/config/leftTree.xml"); $objects2 = XMLParser::getXMLdataValues($path . "/config/mainList.xml"); } $objects = array_merge($objects1, $objects2); $content .= "\n/*------------- MODULE " . $module . " ----------------*/\n\n"; $contentTemplate .= "\n<!-- -------------------- MODULE " . $module . " -------------------- -->\n\n"; $contentTemplate .= "<?php if(\$userRights['{$module}']): ?>\n"; echo_cms_sep(); echo_cms("Module " . $module); echo_cms_sep(); foreach ($objects as $obj) { $createCommands = ""; $contentTemplateLiTags = ""; $forbidenGenericCommands = array(); if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') { $objName = $obj['value']; if (in_array($objName, $objectsDone)) { continue; } $objectsDone[] = $objName; echo_cms(" Writing commands for : " . $objName); $params = $obj['attributes']['COMMANDS']; if ($params) { $commands = explode(",", $params); foreach ($commands as $command) { if (substr($command, 0, 1) == "-") { $forbidenGenericCommands[] = substr($command, 1); } else { $docType = substr($command, 6); $commandTitle = $docType; if (substr($docType, -4) == "I18n") { $commandTitle = substr($docType, 0, -4) . " (Language version)"; } $createCommands .= "\t\t\t'" . $command . "': function(t) {createDocument('" . $docType . "', t.id);},\n"; $contentTemplateLiTags .= "\t\t\t<?php if(\$userRights['{$module}']['{$objName}']['{$command}']): ?>\n"; $contentTemplateLiTags .= "\t\t\t\t<li id='" . $command . "'><img src='/images/icons/" . strtolower($docType) . ".png'/>Create " . ucfirst($commandTitle) . "</li>\n"; $contentTemplateLiTags .= "\t\t\t<?php endif; ?>\n"; } } } if ($objName != "Rootfolder") { if (!in_array("delete", $forbidenGenericCommands)) { $createCommands .= "\t\t\t'deleteDocument': function(t) {deleteDocument(t.id);},\n"; $contentTemplateLiTags .= "\t\t\t<?php if(\$userRights['{$module}']['{$objName}']['delete']): ?>\n"; $contentTemplateLiTags .= "\t\t\t\t<li id='deleteDocument'><img src='/images/icons/delete_document.png'/>Delete</li>\n"; $contentTemplateLiTags .= "\t\t\t<?php endif; ?>\n"; } if (!in_array("edit", $forbidenGenericCommands)) { $createCommands .= "\t\t\t'editDocument': function(t) {editDocument('" . $objName . "', t.id);},\n"; $contentTemplateLiTags .= "\t\t\t<?php if(\$userRights['{$module}']['{$objName}']['edit']): ?>\n"; $contentTemplateLiTags .= "\t\t\t\t<li id='editDocument'><img src='/images/icons/edit_document.png'/>Edit</li>\n"; $contentTemplateLiTags .= "\t\t\t<?php endif; ?>\n"; } if (!in_array("order", $forbidenGenericCommands)) { $createCommands .= "\t\t\t'orderDocumentUp': function(t) {orderDocument(t.id,true);},\n"; $createCommands .= "\t\t\t'orderDocumentDown': function(t) {orderDocument(t.id,false);},\n"; $contentTemplateLiTags .= "\t\t\t<?php if(\$userRights['{$module}']['{$objName}']['order']): ?>\n"; $contentTemplateLiTags .= "\t\t\t\t<li id='orderDocumentUp'><img src='/images/icons/arrow_up.png'/>Move Up</li>\n"; $contentTemplateLiTags .= "\t\t\t\t<li id='orderDocumentDown'><img src='/images/icons/arrow_down.png'/>Move Down</li>\n"; $contentTemplateLiTags .= "\t\t\t<?php endif; ?>\n"; } } $createCommands = substr($createCommands, 0, -2) . "\n"; $contentTemplate .= "\t<?php if(\$userRights['{$module}']['{$objName}']): ?>\n"; $contentTemplate .= "\t<div class='contextMenu' id='" . $module . "_" . strtolower($objName) . "'>\n\t<ul>\n"; $content .= "\t\$('span." . $module . "_" . strtolower($objName) . "').contextMenu('" . $module . "_" . strtolower($objName) . "', {\n" . "\t\tbindings: {\n"; $contentTemplate .= $contentTemplateLiTags; $content .= $createCommands; $content .= "\t\t}\n\t});\n\n"; $contentTemplate .= "\t\t</ul>\n" . "\t</div>\n"; $contentTemplate .= "\t<?php endif; ?>\n\n"; } } $contentTemplate .= "<?php endif; ?>\n"; } $content .= "}"; $contextMenusTemplate = sfConfig::get('sf_root_dir') . "/apps/" . SF_APP . "/modules/admin/templates/contextMenusSuccess.php"; $contextMenusJs = sfConfig::get('sf_web_dir') . "/js/" . SF_APP . "/contextMenus.js"; echo_cms_sep(); if (FileHelper::writeFile($contextMenusTemplate, $contentTemplate)) { echo_cms("contextMenusSuccess.php written successfully"); } else { echo_cms_error("Error writing contextMenusSuccess.php !"); } if (FileHelper::writeFile($contextMenusJs, $content)) { echo_cms("contextMenus.js written successfully"); } else { echo_cms_error("Error writing contextMenus.js !"); } echo_cms_sep(); }
public function executeSavePageContent() { $this->page = Document::getDocumentInstance($this->getRequestParameter('id')); $content = '<?xml version="1.0" encoding="UTF-8"?>'; $content .= '<blocks>'; $data = $this->page->getContent(); if (!empty($data)) { $blockContentsTags = XMLParser::getXMLdataValues($data, false, false); } foreach ($blockContentsTags as $block) { if ($block["tag"] == "BLOCK") { $content .= '<block id="' . $block['attributes']["ID"] . '" target="' . $block['attributes']["TARGET"] . '" action="' . $block['attributes']["ACTION"] . '"'; if (isset($block['attributes']["PARAMETERS"])) { $content .= ' parameters="' . $block['attributes']["PARAMETERS"] . '"'; } $content .= '>'; if ($this->getRequestParameter($block['attributes']["ID"])) { $blockContent = $this->getRequestParameter($block['attributes']["ID"]); if (substr($block['attributes']["ID"], 0, 8) == "richtext") { $imgTags = explode('<img', $blockContent); $imageFound = false; $thumbDir = "richtext/" . $this->getRequestParameter('id') . "/" . substr($block['attributes']["ID"], 8); $usedImg = array(); for ($i = 0; $i < count($imgTags); $i++) { $imgParams = explode('/>', $imgTags[$i]); $id = 0; $thumb = "richtext"; foreach ($imgParams as $paramStr) { $width = null; $height = null; $id = false; if (strstr($paramStr, "width")) { $width = strstr($paramStr, "width"); $width = substr($width, 7); $pos = strpos($width, '"'); $width = substr($width, 0, $pos); } if (strstr($paramStr, "height")) { $height = strstr($paramStr, "height"); $height = substr($height, 8); $pos = strpos($height, '"'); $height = substr($height, 0, $pos); } if (strstr($paramStr, "id")) { $id = strstr($paramStr, "id"); $id = substr($id, 4); $pos = strpos($id, '"'); $id = substr($id, 0, $pos); } if ($id) { $prefix = time(); if (strstr($paramStr, "src")) { $src = strstr($paramStr, "src"); $src = substr($src, 5); $pos = strpos($src, '"'); $src = substr($src, 0, $pos); $parts = explode("/", $src); if ($parts[6]) { $prefix = $parts[6]; } } $img = Document::getDocumentInstance($id); if ($img && get_class($img) == "Media" && $img->isImage()) { if (empty($height) && empty($width)) { list($width, $height) = getimagesize($img->getServerAbsoluteUrl()); } $img->resizeImage($thumbDir, $height, $width, $prefix); $imageFound = true; $usedImg[] = SF_ROOT_DIR . "/www/media/upload/thumbs/" . $thumbDir . "/" . $id . "-" . $prefix . "." . $img->getExtention(); } } $id++; } $thumb = str_replace("/", "-", $thumbDir); $replaceStr = 'src="/media/display/thumb/' . $thumb . '/freeimg/' . $prefix . '/id/'; $find = array('src="/media/display/id/', 'src="/media/display/thumb/thumbs/id/'); $replace = array($replaceStr, $replaceStr); $blockParts[] = str_replace($find, $replace, $imgTags[$i]); } if ($imageFound) { $blockContent = implode("<img ", $blockParts); } $blockContent = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $blockContent); $blockContent = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $blockContent); $files = FileHelper::getSubElements(SF_ROOT_DIR . "/www/media/upload/thumbs/" . $thumbDir, "file"); foreach ($files as $file) { if (!in_array($file, $usedImg)) { // delete RICHTEXT media unlink($file); // delete ORIGINAL media $parts = explode(DIRECTORY_SEPARATOR, $file); $delFile = array_pop($parts); $delIdArr = explode("-", $delFile); $delId = $delIdArr[0]; $imageToDelete = Document::getDocumentInstance($delId); if ($imageToDelete) { $imageToDelete->delete(); } } } } $content .= '<![CDATA[' . $blockContent . ']]>'; } else { $blockContent = $block["value"]; $blockContent = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $blockContent); $blockContent = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $blockContent); $content .= '<![CDATA[' . $blockContent . ']]>'; } $content .= '</block>'; } } $content .= '</blocks>'; $this->page->setContent($content); $this->page->save(); return $this->redirect($this->getRequest()->getReferer()); }