Example #1
0
 public static function getRootfolderByModule($module)
 {
     $found = false;
     $searchModule = $module;
     if (strtolower($searchModule) == 'tag') {
         $searchModule = 'admin';
     }
     $formFile = sfConfig::get('sf_root_dir') . "/config/form.xml";
     if (is_readable($formFile)) {
         $objects = XMLParser::getXMLdataValues($formFile);
         foreach ($objects as $obj) {
             if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'open') {
                 if (strtoupper($obj['attributes']['MODULE']) == strtoupper($searchModule)) {
                     $found = true;
                     break;
                 }
             }
         }
     }
     if (!$found) {
         //echo "getRootfolderByModule($module): not_found!";
         return null;
     }
     try {
         $c = new Criteria();
         $c->add(RootfolderPeer::LABEL, $module);
         $c->addOr(RootfolderPeer::LABEL, ucfirst($module));
         $rootFolder = RootfolderPeer::doSelectOne($c);
         if (!$rootFolder) {
             $rootFolder = new Rootfolder();
             $rootFolder->setLabel(ucfirst($module));
             $rootFolder->save();
         }
         return $rootFolder;
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #2
0
 public function executeIndex()
 {
     $this->setLayout("backend");
     $subscriber = $this->getUser()->getSubscriber();
     if (!$subscriber || $subscriber->getBackend() != 1) {
         $this->forward("user", "login");
     }
     $this->refresh = $this->getRequestParameter("refresh");
     $this->model = $this->getRequestParameter("model");
     $this->id = $this->getRequestParameter("id");
     $this->parent = $this->getRequestParameter("parent");
     $this->err = $this->getRequestParameter("err");
     $this->mainMenu = $this->getPresentationFor('admin', 'backendMainMenu');
     $this->contextMenus = $this->getPresentationFor('admin', 'contextMenus');
     $this->currentModule = $this->getUser()->getAttribute('currentModule');
     $filters = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/backend/config/backendFilters.xml");
     $i = 0;
     $y = 0;
     $moduleFilters = array();
     foreach ($filters as $filter) {
         if ($filter['tag'] == 'MODULE' && $filter['type'] == 'open') {
             $i++;
             $y = 0;
             $f = array();
             $name = null;
             $name = $filter['attributes']['NAME'];
         }
         if ($filter['tag'] == 'FILTER' && $filter['type'] == 'complete') {
             $y++;
             $f[$y]['name'] = $filter['attributes']['NAME'];
             $f[$y]['pop'] = $filter['attributes']['POP'];
             $f[$y]['value'] = str_replace("\"", "'", $filter['value']);
         }
         if ($filter['tag'] == 'MODULE' && $filter['type'] == 'close') {
             $moduleFilters[$i]['moduleName'] = $name;
             $moduleFilters[$i]['filters'] = $f;
         }
     }
     $this->moduleFilters = $moduleFilters;
 }
Example #3
0
function run_generate_cache($task, $args)
{
    ini_set("memory_limit", "2048M");
    ini_set("display_errors", 1);
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', 'frontend');
    define('SF_ENVIRONMENT', 'dev');
    define('SF_DEBUG', false);
    sfConfig::set("sf_use_relations_cache", 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();
    run_url_relations($task, $args);
    run_tags_relations($task, $args);
    echo_cms_title("GENERATING CACHE...");
    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";
    }
    //echo_cms_sep();
    echo_cms("sf_cache_objects = " . sfConfig::get('sf_cache_objects'));
    echo_cms("sf_cache_relations = " . sfConfig::get('sf_cache_relations'));
    echo_cms("sf_cache_trees = " . sfConfig::get('sf_cache_trees'));
    //echo_cms_sep();
    if (count($args) > 0) {
        $relationsFlag = substr($args[0], 0, 3) == "rel";
        $listsFlag = substr($args[0], 0, 4) == "list";
        $cacheModel = $args[0];
        if (is_numeric($cacheModel)) {
            $obj = Document::getDocumentInstance($cacheModel);
            if ($obj) {
                $phpName = get_class($obj);
            } else {
                echo_cms_error("Object with ID=" . $cacheModel . " not found!");
                exit;
            }
        }
    }
    // parse schema file to make Schema.class.php
    $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/schema.xml");
    $schemaFile = sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
    $content = $content = "<?php\n class Schema\n{\n\n";
    echo_cms("Building " . $schemaFile . "... ");
    foreach ($objects as $obj) {
        if ($obj['tag'] == 'TABLE' && $obj['type'] == 'open') {
            $table = $obj['attributes']['PHPNAME'];
            if ($phpName && $phpName == $table) {
                $tableName = $obj['attributes']['NAME'];
            }
            $trees = explode(",", $obj['attributes']['TREE']);
            $content .= "\tpublic static function get" . $table . "Trees()\n\t{\n";
            $content .= "\t\treturn array(";
            foreach ($trees as $tree) {
                $content .= "'" . strtolower($tree) . "', ";
            }
            $content = substr($content, 0, -2);
            $content .= ");\n\t}\n\n";
            $content .= "\tpublic static function get" . $table . "Properties()\n\t{\n";
            $content .= "\t\treturn array(";
        }
        if ($obj['tag'] == 'COLUMN' && $obj['type'] == 'complete') {
            $property = $obj['attributes']['NAME'];
            $getProperty = UtilsHelper::convertFieldName($property);
            $content .= "'" . $getProperty . "', ";
        }
        if ($obj['tag'] == 'TABLE' && $obj['type'] == 'close') {
            $content = substr($content, 0, -2);
            $content .= ");\n\t}\n\n";
        }
    }
    $content .= "\n}";
    //echo_cms_sep();
    if (FileHelper::writeFile($schemaFile, $content)) {
        echo_cms($schemaFile . " writen successfully!");
    } else {
        echo_cms_error("Error writing " . $schemaFile . "!");
    }
    echo "\n";
    //echo_cms_sep();
    if (substr($args[0], 0, 5) == "schema") {
        echo_cms(" Done!");
        exit;
    }
    if (!$relationsFlag && !$listsFlag) {
        try {
            if (is_numeric($cacheModel)) {
                $obj = array();
                $obj['tag'] = 'OBJECT';
                $obj['type'] = 'complete';
                $obj['id'] = $cacheModel;
                $objects = array($obj);
                $exit = true;
            } elseif ($cacheModel) {
                $obj = array();
                $obj['tag'] = 'OBJECT';
                $obj['type'] = 'complete';
                $obj['value'] = $cacheModel;
                $objects = array($obj);
                $exit = true;
            } else {
                $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml");
            }
            foreach ($objects as $obj) {
                if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
                    if ($id = $obj['id']) {
                        $obj = Document::getDocumentInstance($id);
                        $model = get_class($obj);
                        $c = new Criteria();
                        $c->add($tableName . '.ID', $id);
                    } else {
                        $model = $obj['value'];
                        $c = new Criteria();
                    }
                    $classPeer = ucfirst($model) . "Peer";
                    //$c = new Criteria();
                    //$results = call_user_func(array($classPeer, 'doSelect'), $c);
                    $peerMethod = "doSelect";
                    $results = call_user_func(array($classPeer, $peerMethod), $c);
                    echo_cms("  Caching " . $model . " documents");
                    $ind = 0;
                    foreach ($results as $result) {
                        if ($ind % 20 == 0) {
                            echo $ind . "  .\r";
                        } else {
                            if ($ind % 10 == 0) {
                                echo $ind . "  o\r";
                            }
                        }
                        $ind++;
                        Document::cacheObj($result, $model, false);
                    }
                    echo_cms(" ====> " . $ind . " " . $model . " Document(s) cached.");
                    //echo_cms_sep();
                }
            }
            if ($exit) {
                exit;
            }
        } catch (Expection $e) {
            echo_cms_error(" Error: {$e}");
        }
    }
    if (!$listsFlag) {
        echo "\n";
        //echo_cms_sep();
        echo_cms("Writing relations cache");
        Relation::checkRelationCache('lock');
        try {
            $c = new Criteria();
            $c->addAscendingOrderByColumn('id1');
            $c->addAscendingOrderByColumn('document_model2');
            $c->addAscendingOrderByColumn('sort_order');
            $relations = RelationPeer::doSelect($c);
            $relationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/childrenRelations.php";
            echo_cms("Processing children :");
            $i = 0;
            $content = "<?php \n";
            $oldIDModel = '';
            $currIDModel = '';
            $idStr = '';
            foreach ($relations as $relation) {
                $currIDModel = $relation->getId1() . ':' . $relation->getDocumentModel2();
                if ($i == 0) {
                    $oldIDModel = $currIDModel;
                }
                $i++;
                echo $i . "\t\t\r";
                if ($currIDModel == $oldIDModel) {
                    $idStr .= "," . $relation->getId2();
                } else {
                    $idStr = substr($idStr, 1);
                    $content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n";
                    $idStr = "," . $relation->getId2();
                }
                $oldIDModel = $currIDModel;
                $oldId1 = $relation->getId1();
                $oldModel2 = $relation->getDocumentModel2();
            }
            if ($idStr) {
                $idStr = substr($idStr, 1);
                $content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n";
            }
            echo "\n";
            $content .= "\n?>";
            //echo_cms_sep();
            if (FileHelper::writeFile($relationsFile, $content)) {
                echo_cms($relationsFile . " written successfully");
            } else {
                echo_cms_error("Error writing " . $relationsFile . " !");
            }
            //echo_cms_sep();
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
        Relation::checkRelationCache('unlock');
    }
    if (!$relationsFlag) {
        echo "\n";
        //echo_cms_sep();
        echo_cms_title("Writing Lists cache");
        $listsRootFolder = Rootfolder::getRootfolderByModule("lists");
        if ($listsRootFolder) {
            $lists = Document::getChildrenOf($listsRootFolder->getId(), "Lists");
        }
        foreach ($lists as $list) {
            $listId = $list->getListId();
            echo "\t\tprocessing \"" . $listId . "\" list ...";
            $listPath = sfConfig::get('sf_root_dir') . "/cache/listscache/" . $listId . ".php";
            @unlink($listPath);
            $content = "<?php \n";
            $content .= "\$listItemsForSelect = array(\n";
            $items = Lists::getListitemsForSelect($listId, array(), false);
            foreach ($items as $key => $item) {
                $content .= "\"" . str_replace("\"", "\\\"", $key) . "\" => \"" . str_replace("\"", "\\\"", $item) . "\",\n";
            }
            $content .= ");\n?>";
            if (FileHelper::writeFile($listPath, $content)) {
                echo_cms(" Done!");
            } else {
                echo_cms_error(" Error!");
            }
        }
        //echo_cms_sep();
    }
    sfConfig::set("sf_use_relations_cache", true);
}
Example #4
0
 public function executeGetRichtextFields()
 {
     $this->setLayout(false);
     $template = $this->getRequestParameter('template');
     $templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.xml';
     if (!is_file($templateFile)) {
         $templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.xml';
     }
     $tags = XMLParser::getXMLdataValues($templateFile);
     // CREATING PREDEFINED RICHTEXT FIELDS
     $richtextCnt = 0;
     $richtextBoxes = array();
     foreach ($tags as $tag) {
         if ($tag['tag'] == 'DESTINATION' && $tag['type'] == 'complete' && $tag['attributes']['TYPE'] == 'richtext') {
             $richtextCnt++;
             $richtextBoxes[$richtextCnt] = $tag['attributes']['ID'];
         }
     }
     $obj = Document::getDocumentInstance($this->getRequestParameter('id'));
     if ($obj) {
         $this->richtext = self::get_richtext($obj->getContent());
     }
     $this->obj = $obj;
     $this->boxes = $richtextBoxes;
 }
Example #5
0
 public static function cacheObj($document, $documentModel = null, $refreshTree = true, $parentId = null)
 {
     if (sfConfig::get('sf_cache_objects')) {
         // parse cachedObjects and cache objects
         $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml");
         // check if documentModel is Cached
         $foundModel = false;
         if (is_null($documentModel)) {
             $documentModel = get_class($document);
         }
         foreach ($objects as $obj) {
             if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
                 if ($documentModel == $obj['value']) {
                     $foundModel = true;
                 }
             }
         }
         // Caching Object if it's model is in "cachedObjects.xml" file
         if ($foundModel) {
             $docId = $document->getId();
             $path = self::getCachePath($docId, true);
             include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php";
             $m = "get" . $documentModel . "Properties";
             $properties = Schema::$m();
             $content = "<?php\nclass CachedObj" . $docId . "\n{\n";
             $content .= "\tpublic function __getDocumentModel(){\n\t\treturn \"" . $documentModel . "\";\n\t}\n";
             foreach ($properties as $getProperty) {
                 $getter = "get" . ucfirst($getProperty);
                 $v = $document->{$getter}();
                 if (is_null($v)) {
                     $content .= "\tpublic function " . $getter . "(){\n\t\treturn NULL;\n\t}\n";
                 } else {
                     if ($documentModel == "Page" && $getProperty == "Content") {
                         $content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n";
                     } else {
                         // delete <script> tags !!!
                         $v = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v);
                         $v = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v);
                         $content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n";
                     }
                 }
                 /*					else
                 					{
                 					$content .= "\tpublic function ".$getter."(){\n\t\treturn ".$v.";\n\t}\n";
                 					}*/
             }
             if (!$parentId) {
                 $parentId = intval(self::getParentOf($docId, null, false, false));
             }
             $content .= "\tpublic function getParent(){\n\t\treturn {$parentId};\n\t}\n";
             $content .= "}";
             $cachefile = $path . "doc" . $docId . ".php";
             if (file_exists($cachefile)) {
                 unlink($cachefile);
             }
             FileHelper::writeFile($cachefile, $content);
             chmod($cachefile, 0777);
         }
     }
     // Refreshing Tree - not related to CacheObject !!!
     if (sfConfig::get('sf_cache_trees') && $refreshTree) {
         /*
         $modules = FileHelper::getSubElements(sfConfig::get('sf_root_dir')."/apps/backend/modules", "folder");
         foreach ($modules as $module => $path)
         */
         include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php";
         $documentModel = get_class($document);
         $getTree = "get" . $documentModel . "Trees";
         $trees = Schema::$getTree();
         foreach ($trees as $module) {
             $module = strtolower($module);
             // Caching Left, Right and MCE tree
             BackendService::updateTree($module, $document, "UPDATE");
             //BackendService::updateTree($module, $document, "UPDATE", "right");
             BackendService::updateTree($module, $document, "UPDATE", "mce");
         }
     }
 }
Example #6
0
 public static function getMceTree($moduleName)
 {
     $lmn = strtolower($moduleName);
     $moduleName = ucfirst($lmn);
     $htmlCacheFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.html";
     if (is_readable($htmlCacheFile)) {
         $content = file_get_contents($htmlCacheFile);
         return $content;
     }
     $phpFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.php";
     if (is_readable($phpFile)) {
         return self::makeHtmlCache($moduleName, "mce");
     }
     $rightTree = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/backend/modules/" . $lmn . "/config/mceTree.xml");
     $displayedObjects = array();
     foreach ($rightTree as $obj) {
         if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
             $displayedObjects[] = $obj['value'];
         }
     }
     $document = Rootfolder::getRootfolderByModule($moduleName);
     $docId = $document->getId();
     $contentArr = self::makePhpArray($docId, $lmn, $displayedObjects);
     // make Root element
     $rootItem = array();
     $rootItem[$docId]['id'] = $document->getId();
     $rootItem[$docId]['model'] = 'rootfolder';
     $rootItem[$docId]['class'] = $lmn . '_rootfolder';
     $rootItem[$docId]['level'] = 0;
     $rootItem[$docId]['label'] = addslashes($document->getLabel());
     $contentArr = array_merge($rootItem, $contentArr);
     return self::makePhpCache($contentArr, $moduleName, "mce");
 }
Example #7
0
 public static function getMainList(&$documentId, $moduleName, $page = 1)
 {
     $moduleName = strtolower($moduleName);
     try {
         if ($moduleName == "settings") {
             $settingsArr = array();
             if (is_readable(sfConfig::get('sf_root_dir') . "/config/settings.xml")) {
                 $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/settings.xml");
             }
             foreach ($objects as $obj) {
                 if ($obj['tag'] == 'ELEMENT' && $obj['type'] == 'open') {
                     $objName = $obj['attributes']['LABEL'];
                     $objDescription = $obj['attributes']['DESCRIPTION'];
                 }
                 if ($obj['tag'] == 'ITEM' && $obj['type'] == 'complete') {
                     //$val = $obj['attributes']['VALUE'];
                     $settingName = $objName;
                     //$settingName = strtolower($objName);
                     $settingsArr[$settingName] = $objDescription;
                 }
             }
             $pager = new sfPropelPager("Relation", 20);
             $pager->setResults($settingsArr);
             $pager->setPage($page);
             $pager->init();
             foreach ($pager->getResults() as $name => $label) {
                 $res['children'][$name] = $label;
             }
             $res['paging'] = $pager->paging(true);
             return $res;
         }
         if ($moduleName == "labels") {
             $localesArr = array();
             if (is_readable(sfConfig::get('sf_root_dir') . "/config/locales.xml")) {
                 $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/locales.xml");
                 foreach ($objects as $obj) {
                     if ($obj['tag'] == 'LOCALE' && $obj['type'] == 'open') {
                         $objName = $obj['attributes']['LABEL'];
                         if ($obj['attributes']['DESCRIPTION']) {
                             $objDescription = $obj['attributes']['DESCRIPTION'];
                         } else {
                             $objDescription = '[' . $obj['attributes']['LABEL'] . ']';
                         }
                     }
                     if ($obj['tag'] == 'ITEM' && $obj['type'] == 'complete') {
                         //$val = $obj['attributes']['VALUE'];
                         $localeName = $objName;
                         //$localeName = strtolower($objName);
                         $localesArr[$localeName] = $objDescription;
                     }
                 }
             }
             $pager = new sfPropelPager("Relation", 20);
             $pager->setResults($localesArr);
             $pager->setPage($page);
             $pager->init();
             foreach ($pager->getResults() as $name => $label) {
                 $res['children'][$name] = $label;
             }
             $res['paging'] = $pager->paging(true);
             return $res;
         }
         $mainList = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/panel/modules/" . $moduleName . "/config/mainList.xml");
         $displayedObjects = array();
         $rootId = null;
         foreach ($mainList as $obj) {
             if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
                 $displayedObjects[] = $obj['value'];
             }
             // check overwrite RootID
             if ($obj['tag'] == 'OBJECTS' && $obj['type'] == 'open') {
                 if (array_key_exists("attributes", $obj) && array_key_exists("PARENT", $obj['attributes'])) {
                     $rootName = $obj['attributes']['PARENT'];
                     $rootDocument = Rootfolder::getRootfolderByModule($rootName);
                     if ($rootDocument) {
                         $rootId = $rootDocument->getId();
                     }
                 }
                 if (array_key_exists("attributes", $obj) && array_key_exists("TAG", $obj['attributes'])) {
                     $tag = $obj['attributes']['TAG'];
                     $rootDocument = Document::getDocumentByExclusiveTag($tag);
                     if ($rootDocument) {
                         $rootId = $rootDocument->getId();
                     }
                 }
             }
         }
         $children = array();
         $res = array('children' => array(), 'paging' => '');
         $c = new Criteria();
         if (!$documentId) {
             if ($rootId) {
                 $documentId = $rootId;
             } else {
                 $document = Rootfolder::getRootfolderByModule($moduleName);
                 if ($document) {
                     $documentId = $document->getId();
                 }
             }
         }
         //echo "rootId = $rootId; moduleName = $moduleName;";
         if ($documentId) {
             $pager = new sfPropelPager("Relation", 20);
             $c->add(RelationPeer::ID1, $documentId);
             $c->add(RelationPeer::DOCUMENT_MODEL2, $displayedObjects, Criteria::IN);
             $c->addAscendingOrderByColumn(RelationPeer::SORT_ORDER);
             $pager->setCriteria($c);
             $pager->setPage($page);
             $pager->init();
             foreach ($pager->getResults() as $relation) {
                 $id = $relation->getId2();
                 $res['children'][] = Document::getDocumentInstance($id);
             }
         }
         $res['paging'] = $pager->paging(true);
         return $res;
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #8
0
 private function getContent($backend = false)
 {
     $templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $this->pageDocument->getTemplate() . '.xml';
     if (!is_file($templateFile)) {
         $templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $this->pageDocument->getTemplate() . '.xml';
     }
     $tags = XMLParser::getXMLdataValues($templateFile, true, true);
     $targets = XMLParser::getTargetsForTemplateBlocks($tags);
     $content = '';
     $processContent = false;
     $freeCnt = 0;
     if ($backend) {
         $freeContentStr = 'free content...';
         $richTextStr = 'Click here to edit richtext content...';
     } else {
         $freeContentStr = '';
     }
     // CREATING PREDEFINED RICHTEXT FIELDS
     if ($this->pageDocument->getContent() === null) {
         $richtextCnt = 0;
         $richrextBoxes = '';
         foreach ($tags as $tag) {
             if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'open') {
                 $processContent = true;
                 continue;
             }
             if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'close') {
                 $processContent = false;
                 continue;
             }
             if ($processContent) {
                 if ($tag['type'] == 'complete') {
                     if (array_key_exists("attributes", $tag) && array_key_exists('ID', $tag['attributes']) && isset($targets[$tag['attributes']['ID']])) {
                         $templateType = $targets[$tag['attributes']['ID']]['type'];
                         if ($templateType == 'richtext') {
                             $richtextCnt++;
                             $richrextBoxes .= '<block id="richtext' . $richtextCnt . '" target="' . $tag['attributes']["ID"] . '" action="richtext"><![CDATA[<p></p>Click here to edit richtext content...<p></p>]]></block>';
                         }
                     }
                 }
             }
         }
         if ($richrextBoxes) {
             $richrextBoxes = '<?xml version="1.0" encoding="UTF-8"?><blocks>' . $richrextBoxes . '</blocks>';
         }
         $this->pageDocument->setContent($richrextBoxes);
         $this->pageDocument->save();
     }
     foreach ($tags as $tag) {
         if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'open') {
             $processContent = true;
             continue;
         }
         if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'close') {
             $processContent = false;
             continue;
         }
         if ($processContent) {
             if ($tag['type'] == 'open') {
                 $content .= str_repeat(chr(9), $tag['level'] - 3) . '<' . $tag['tag'];
                 if (array_key_exists('attributes', $tag)) {
                     foreach ($tag['attributes'] as $key => $val) {
                         $content .= ' ' . strtolower($key) . '="' . $val . '"';
                     }
                 }
                 $content .= '>' . chr(10);
             }
             if ($tag['type'] == 'complete') {
                 $content .= str_repeat(chr(9), $tag['level'] - 3) . '<' . $tag['tag'];
                 if (array_key_exists("attributes", $tag)) {
                     foreach ($tag['attributes'] as $key => $val) {
                         $content .= ' ' . strtolower($key) . '="' . $val . '"';
                     }
                 }
                 $content .= '>' . chr(10);
                 //content here
                 if (array_key_exists("attributes", $tag) && array_key_exists('ID', $tag['attributes']) && isset($targets[$tag['attributes']['ID']])) {
                     if ($targets[$tag['attributes']['ID']]['type'] != 'free' && $targets[$tag['attributes']['ID']]['type'] != 'richtext') {
                         $component = explode('/', $targets[$tag['attributes']['ID']]['type']);
                         // check if defined BLOCK exists ---> checking if "execute<BlockName>" method exist in <module> class
                         $controler = $this->getController();
                         if ($controler->actionExists($component[0], $component[1])) {
                             // render block params
                             if (isset($targets[$tag['attributes']['ID']]['parameters'])) {
                                 $arr = array();
                                 $parameters = explode(' ', $targets[$tag['attributes']['ID']]['parameters']);
                                 foreach ($parameters as $parameter) {
                                     $param = explode('=', $parameter);
                                     $arr[$param[0]] = $param[1];
                                 }
                                 $this->getRequest()->setParameter('params', $arr);
                             }
                             $content .= $this->getPresentationFor($component[0], $component[1]);
                         } else {
                             $content .= "<br>Block '" . $component[0] . "/" . $component[1] . "' doesn't exist!<br>";
                         }
                     } else {
                         $freeCnt++;
                         $blobData = $this->pageDocument->getContent();
                         if (!empty($blobData)) {
                             $blockContents = $blobData;
                             $blockContentsTags = XMLParser::getXMLdataValues($blockContents, false, false);
                             $foundBlock = false;
                             foreach ($blockContentsTags as $block) {
                                 if ($block["tag"] == "BLOCK" && $block['attributes']["TARGET"] == $tag['attributes']['ID']) {
                                     if ($block['attributes']["ACTION"] == "richtext") {
                                         if ($backend) {
                                             if ($block["value"] == '') {
                                                 $richTemplate = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'richtext.php';
                                                 if (file_exists($richTemplate)) {
                                                     $block["value"] = file_get_contents($richTemplate);
                                                 } else {
                                                     $block["value"] = '<p></p>' . $richTextStr . '<p></p>';
                                                 }
                                             }
                                             $content .= '<form method="post" action="/admin/website/savePageContent"><input type="hidden" name="id" value="' . $this->pageDocument->getId() . '"/><input type="hidden" name="parentBlock" value="' . $block['attributes']["TARGET"] . '"/><div id="' . $block['attributes']["ID"] . '" class="richtext">' . $block["value"] . '</div></form>';
                                             //$content .= '<form method="post" action="/admin/website/savePageContent"><input type="hidden" name="id" value="'.$this->pageDocument->getId().'"/><input type="hidden" name="parentBlock" value="'.$block['attributes']["TARGET"].'"/><div id="'.$block['attributes']["ID"].'" class="richtext">'.$block["value"].'</div></form>';
                                         } else {
                                             $content .= '<div id="' . $block['attributes']["ID"] . '" class="richtext">' . $block["value"] . '</div>';
                                             //$content .= '<div id="'.$block['attributes']["ID"].'" class="richtext">'.$block["value"].'</div>';
                                         }
                                     } else {
                                         $url = $block['attributes']["ACTION"];
                                         $action = explode('/', $url);
                                         // check if defined BLOCK exists ---> checking if "execute<BlockName>" method exist in <module> class
                                         $controler = $this->getController();
                                         if ($controler->actionExists($action[0], $action[1])) {
                                             // render block params
                                             if (isset($block['attributes']['PARAMETERS'])) {
                                                 $arr = array();
                                                 $parameters = explode(' ', $block['attributes']['PARAMETERS']);
                                                 foreach ($parameters as $parameter) {
                                                     $param = explode('=', $parameter);
                                                     //$arr[$block['attributes']['ID']][$param[0]] = $param[1];
                                                     if (array_key_exists(1, $param)) {
                                                         $arr[$param[0]] = $param[1];
                                                     }
                                                 }
                                                 $this->getRequest()->setParameter('params', $arr);
                                                 //$this->getRequest()->setParameter('paramid', $block['attributes']['ID']);
                                             }
                                             $this->getRequest()->setParameter('blockId', $block['attributes']["ID"]);
                                             $content .= '<div id="' . $block['attributes']["ID"] . '" class="free">' . $this->getPresentationFor($action[0], $action[1]) . '</div>';
                                         } else {
                                             $content .= '<div id="' . $block['attributes']["ID"] . '" class="free">Block ' . $action[0] . '/' . $action[1] . ' does not exist!</div>';
                                         }
                                     }
                                     $foundBlock = true;
                                 }
                             }
                             if (!$foundBlock) {
                                 $content .= '<div id="new/Block' . $freeCnt . '" class="free">' . $freeContentStr . '</div>';
                             }
                         } else {
                             $content .= '<div id="new/Block' . $freeCnt . '" class="free">' . $freeContentStr . '</div>';
                         }
                     }
                 }
                 $content .= str_repeat(chr(9), $tag['level'] - 3) . '</' . $tag['tag'] . '>' . chr(10);
             }
             if ($tag['type'] == 'close') {
                 $content .= str_repeat(chr(9), $tag['level'] - 3) . '</' . $tag['tag'] . '>' . chr(10);
             }
         }
     }
     return $content;
 }
Example #9
0
 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());
 }