コード例 #1
0
ファイル: PageController.php プロジェクト: julpi/FreshCMS
 private function _add()
 {
     $data = $_POST['page'];
     Flash::set('post_data', (object) $data);
     if (empty($data['title'])) {
         // Rebuilding original page
         $part = $_POST['part'];
         if (!empty($part)) {
             $tmp = false;
             foreach ($part as $key => $val) {
                 $tmp[$key] = (object) $val;
             }
             $part = $tmp;
         }
         $page = $_POST['page'];
         if (!empty($page) && !array_key_exists('is_protected', $page)) {
             $page = array_merge($page, array('is_protected' => 0));
         }
         $tags = $_POST['page_tag'];
         //Flash::setNow('page', (object) $page);
         //Flash::setNow('page_parts', (object) $part);
         //Flash::setNow('page_tag', $tags);
         Flash::setNow('error', __('You have to specify a title!'));
         //redirect(get_url('page/add'));
         // display things ...
         $this->setLayout('backend');
         $this->display('page/edit', array('action' => 'add', 'page' => (object) $page, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => (object) $part, 'layouts' => Record::findAllFrom('Layout')));
     }
     /**
      * Make sure the title doesn't contain HTML
      *
      * @todo Replace this by HTML Purifier?
      */
     if (Setting::get('allow_html_title') == 'off') {
         use_helper('Kses');
         $data['title'] = kses(trim($data['title']), array());
     }
     $page = new Page($data);
     // save page data
     if ($page->save()) {
         // get data from user
         $data_parts = $_POST['part'];
         Flash::set('post_parts_data', (object) $data_parts);
         foreach ($data_parts as $data) {
             $data['page_id'] = $page->id;
             $data['name'] = trim($data['name']);
             $page_part = new PagePart($data);
             $page_part->save();
         }
         // save tags
         $page->setTags($_POST['page_tag']['tags']);
         Flash::set('success', __('Page has been saved!'));
     } else {
         Flash::set('error', __('Page has not been saved!'));
         redirect(get_url('page/add'));
     }
     // save and quit or save and continue editing ?
     if (isset($_POST['commit'])) {
         redirect(get_url('page'));
     } else {
         redirect(get_url('page/edit/' . $page->id));
     }
 }
コード例 #2
0
 private function _edit($id)
 {
     $data = $_POST['page'];
     $page = Page::findById($id);
     // need to do this because the use of a checkbox
     $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0;
     $page->setFromData($data);
     Observer::notify('page_edit_before_save');
     if ($page->save()) {
         // get data for parts of this page
         $data_parts = $_POST['part'];
         $old_parts = PagePart::findByPageId($id);
         // check if all old page part are passed in POST
         // if not ... we need to delete it!
         foreach ($old_parts as $old_part) {
             $not_in = true;
             foreach ($data_parts as $part_id => $data) {
                 $data['name'] = trim($data['name']);
                 if ($old_part->name == $data['name']) {
                     $not_in = false;
                     $part = new PagePart($data);
                     $part->page_id = $id;
                     $part->save();
                     unset($data_parts[$part_id]);
                     break;
                 }
             }
             if ($not_in) {
                 $old_part->delete();
             }
         }
         // add the new ones
         foreach ($data_parts as $part_id => $data) {
             $data['name'] = trim($data['name']);
             $part = new PagePart($data);
             $part->page_id = $id;
             $part->save();
         }
         // save tags
         $page->saveTags($_POST['page_tag']['tags']);
         Flash::set('success', __('Page has been saved!'));
         /* Successfully edited so notify. */
         Observer::notify('page_edit_after_save', $page);
     } else {
         Flash::set('error', __('Page has not been saved!'));
         redirect(get_url('page/edit/' . $id));
     }
     // save and quit or save and continue editing ?
     if (isset($_POST['commit'])) {
         redirect(get_url('page'));
     } else {
         redirect(get_url('page/edit/' . $id));
     }
 }
コード例 #3
0
ファイル: Page.php プロジェクト: julpi/FreshCMS
 public function setParts(array $new_parts)
 {
     // If an array is passed convert to stdObject
     // if (is_array($data_parts)) {
     //     $objParts = new stdClass;
     //     foreach ($data_parts as $part)
     //         $objParts->{$part->name} = $part;
     //     $data_parts = $objParts;
     // } elseif (!is_a($data_parts, 'stdClass')){
     //     return false;
     // }
     // check if all old page part are present
     // if not ... we need to delete it!
     foreach ($this->parts as $old_part) {
         $not_in = true;
         foreach ($new_parts as $part_id => $data) {
             $data['name'] = trim($data['name']);
             if ($old_part->name == $data['name']) {
                 $not_in = false;
                 // this will not really create a new page part because
                 // the id of the part is passed in $data
                 $part = new PagePart($data);
                 $part->page_id = $this->id;
                 $part->save();
                 Observer::notify('part_edit_after_save', $part);
                 $this->parts->{$part->name} = $part;
                 unset($new_parts[$part_id]);
                 break;
             }
         }
         if ($not_in) {
             $old_part->delete();
         }
     }
     // add the new ones
     foreach ($new_parts as $part_id => $data) {
         $data['name'] = trim($data['name']);
         $part = new PagePart($data);
         $part->page_id = $this->id;
         $part->save();
         Observer::notify('part_add_after_save', $part);
         $this->parts->{$data}['name'] = $part;
     }
 }