Ejemplo n.º 1
0
 /**
  * Build a multi-array of parent > children.
  *
  * @return array An array representing the page tree.
  */
 public function get_page_tree()
 {
     $all_pages = Page::order_by('order', 'asc')->get(array('id', 'parent_id', 'title'));
     // First, re-index the array.
     foreach ($all_pages as $row) {
         $pages[$row->id] = array('id' => $row->id, 'li_id' => 'page_', 'link_type' => 'page', 'rel' => $row->id, 'parent_id' => $row->parent_id, 'title' => $row->title, 'url' => isset($page->slug) ? $page->slug : '', 'class' => $row->class);
     }
     unset($all_pages);
     $page_array = array();
     // Do we have pages?
     if (isset($pages) and !empty($pages)) {
         // Build a multidimensional array of parent > children.
         foreach ($pages as $row) {
             if (array_key_exists($row['parent_id'], $pages)) {
                 // Add this page to the children array of the parent page.
                 $pages[$row['parent_id']]['children'][] =& $pages[$row['id']];
             }
             // This is a root page.
             if ($row['parent_id'] == 0) {
                 $page_array[] =& $pages[$row['id']];
             }
         }
     }
     return $page_array;
 }
Ejemplo n.º 2
0
 public function render($slug = null, $check_restrictions = true)
 {
     if ($slug == null) {
         $slug = $this->page_slug;
     }
     if ($slug == '/' or empty($slug)) {
         $slug = 'home';
     }
     if ($slug == '404') {
         //page not found. Do we have a 404 page? really? :)
         $page = Model\Page::where('slug', '=', '404')->first();
         if (isset($page) and count($page) > 0) {
             $this->data['meta_title'] = $page->title;
             $this->data['meta_description'] = $page->meta_description;
             $this->data['meta_keywords'] = $page->meta_keywords;
             $this->data['page_content'] = $page->body;
             return $this->theme->render('pages::frontend.page', $this->data);
         } else {
             // How embarrassing we dont have a 404 page :)
             // Return default framework 404
             return Response::error('404');
         }
     }
     $page = Model\Page::where('slug', '=', $slug)->first();
     if (!isset($page) or empty($page)) {
         $page = Model\Page::where('slug', '=', '404')->first();
     }
     $page_access = explode(',', $page->restricted_to);
     if (Restriction::passes($page_access, new Auth())) {
         if (isset($page) and count($page) > 0) {
             $this->data['meta_title'] = $page->title;
             $this->data['meta_description'] = $page->meta_description;
             $this->data['meta_keywords'] = $page->meta_keywords;
             $this->data['page_content'] = $page->body;
             return $this->theme->render('pages::frontend.page', $this->data);
         } else {
             //page not found. Do we have a 404 page? really? :)
             $page = Model\Page::where('slug', '=', '404')->first();
             if (isset($page) and count($page) > 0) {
                 return Redirect::to('404');
             } else {
                 // How embarrassing we dont have a 404 page :)
                 // Return default framework 404
                 return Response::error('404');
             }
         }
     } else {
         // not allowed to view page
         //page not found. Do we have a 404 page? really? :)
         $page = Model\Page::where('slug', '=', '404')->first();
         if (isset($page) and count($page) > 0) {
             return Redirect::to('404');
         } else {
             // How embarrassing we dont have a 404 page :)
             // Return default framework 404
             return Response::error('404');
         }
     }
 }
Ejemplo n.º 3
0
 public function createAction()
 {
     $this->layout('layout/layout');
     $this->layout()->main_menu = $this->_main_menu;
     $form = new PageForm();
     $form->get('submit')->setValue('Create');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $page = new Page();
         $form->setInputFilter($page->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $page->exchangeArray($form->getData());
             $this->getPageTable()->createPage($page);
             // Redirect to list of albums
             return $this->redirect()->toRoute('home/pages');
         }
     }
     $view = new ViewModel(array('form' => $form));
     return $view;
 }