示例#1
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;
 }