Beispiel #1
0
 public function loadSections($form_mode = false, $filler = true)
 {
     PHPWS_Core::initModClass('pagesmith', 'PS_Text.php');
     PHPWS_Core::initModClass('pagesmith', 'PS_Block.php');
     if (empty($this->_tpl)) {
         $this->loadTemplate();
     }
     if (empty($this->_tpl->structure)) {
         PHPWS_Error::log(PS_PG_TPL_ERROR, 'pagesmith', 'PS_Page::loadSections', $this->_tpl->file);
         throw new \Exception('Page template missing:' . $this->_tpl->file);
     }
     foreach ($this->_tpl->structure as $section_xml) {
         switch ($section_xml['TYPE']) {
             case 'image':
             case 'document':
             case 'media':
             case 'block':
                 $section = new PS_Block();
                 $section->pid = $this->id;
                 break;
             default:
                 $section = new PS_Text();
                 $section->pid = $this->id;
         }
         $section->plugSection($section_xml, $this->id);
         if ($form_mode && $filler) {
             $section->loadFiller();
         }
         $this->_sections[$section->secname] = $section;
     }
     if ($this->id) {
         // load sections from database
         // load sections should handle template
         $text_db = new PHPWS_DB('ps_text');
         $block_db = new PHPWS_DB('ps_block');
         $text_db->addWhere('pid', $this->id);
         $block_db->addWhere('pid', $this->id);
         $text_db->setIndexBy('secname');
         $block_db->setIndexBy('secname');
         $text_sections = $text_db->select();
         $block_sections = $block_db->select();
         if (!empty($text_sections)) {
             foreach ($text_sections as $secname => $section) {
                 if (isset($this->_sections[$secname])) {
                     PHPWS_Core::plugObject($this->_sections[$secname], $section);
                     // we don't want smarttags parsed
                     $this->_content[$secname] = $this->_sections[$secname]->getContent(!$form_mode);
                 } elseif (!empty($section['content'])) {
                     $this->_orphans[$secname] = $section;
                 } else {
                     $db = \Database::newDB();
                     $db->setConditional($db->addTable('ps_text')->getFieldConditional('id', $section['id']));
                     $db->delete();
                 }
             }
         }
         if (!empty($block_sections)) {
             foreach ($block_sections as $secname => $section) {
                 if (isset($this->_sections[$secname])) {
                     if ($this->_sections[$secname]->width) {
                         $default_w = $this->_sections[$secname]->width;
                     }
                     if ($this->_sections[$secname]->height) {
                         $default_h = $this->_sections[$secname]->height;
                     }
                     PHPWS_Core::plugObject($this->_sections[$secname], $section);
                     if ($this->_sections[$secname]->width && !empty($default_w)) {
                         $this->_sections[$secname]->width = $default_w;
                     }
                     if ($this->_sections[$secname]->height && !empty($default_h)) {
                         $this->_sections[$secname]->height = $default_h;
                     }
                     if ($form_mode && $this->_sections[$secname]->type_id) {
                         //reload the image form if the image is set
                         $this->_sections[$secname]->loadFiller();
                     }
                     $this->_content[$secname] = $this->_sections[$secname]->getContent();
                 } elseif ($section['type_id'] > 0) {
                     $this->_orphans[$secname] = $section;
                 } else {
                     $db = \Database::newDB();
                     $db->setConditional($db->addTable('ps_block')->getFieldConditional('id', $section['id']));
                     $db->delete();
                 }
             }
         }
     }
 }