Beispiel #1
0
 /**
  * Print all categories on root level
  * @return void
  */
 public function block_page($selected = NULL)
 {
     // Create instance of model and fetch data
     $page = new Page_Model();
     $data = $page->get_menu();
     // create view
     $template = new View('block_pages');
     $template->data = $data;
     $template->selected = $selected;
     $template->render(TRUE);
 }
Beispiel #2
0
 public function render()
 {
     if (!$this->links) {
         throw new Kohana_User_Exception("Navbar not implemented correctly", "Links have not been set. Please call <code>&#36;navbar->set_links({&#36;links})</code>");
     } else {
         if ($this->view) {
             return $this->render_to_view($this->view);
         } else {
             $html = "";
             $i = 0;
             foreach ($this->links as $link) {
                 $class = "";
                 if ($link->get_parent_id() == Page_Model::get_by_url()->id) {
                     $class .= "selected";
                 }
                 if ($i == 0) {
                     $class .= " first";
                 }
                 if ($i == count($this->links) - 1) {
                     $class .= " last";
                 }
                 $x = $this->template;
                 $x = str_replace('{CLASS}', $class, $x);
                 $x = str_replace('{TITLE}', $link->get_definition()->title, $x);
                 $x = str_replace('{URL}', $link->get_url(), $x);
                 $html .= $x;
                 $i++;
             }
             #			$html .= "</ul>";
             return $html;
         }
     }
 }
Beispiel #3
0
 public function __construct()
 {
     socialFeed::get_favicon_from('http://www.delicious.com/sydlawrence');
     $this->session = Session::instance();
     $this->db = new Database();
     parent::__construct();
     $_POST = $this->input->xss_clean($_POST);
     if ($this->input->post('attempt_login')) {
         $return = login::attempt_login();
         if (isset($return->id) && $return->id > 0) {
             $this->user = $return;
         } else {
             $this->__set_options(array('error' => $return));
         }
         if (isset($_GET['redirect'])) {
             url::redirect(urldecode($_GET['redirect']));
         }
     }
     $this->user = login::check_login();
     if ($this->input->get('logout')) {
         Auth::instance()->logout(TRUE);
         url::redirect();
     }
     $this->page = Page_Model::get_by_url();
     $this->feed = Feed_Model::get_by_url();
     $this->feedpost = Feedpost_Model::get_by_url();
     $this->__setup();
     $this->header = new View('includes/header');
     $this->footer = new View('includes/footer');
     $this->__binds();
 }
Beispiel #4
0
 public static function get_by_url()
 {
     $uri = uri::instance();
     $title = urldecode($uri->segment(1));
     $feed = ORM::factory('feed')->where('title', $title)->find();
     if ($feed->id > 0 && $title != "") {
         return $feed;
     }
     $title = str_replace('-', ' ', $title);
     $feed = ORM::factory('feed')->where('title', $title)->find();
     if ($feed->id > 0 && $title != "") {
         return $feed;
     }
     if ($p = Page_Model::get_by_url()) {
         $feed = ORM::factory('feed')->where('title', $p->title)->find();
         if ($feed->id > 0) {
             return $feed;
         }
     }
     return null;
 }
Beispiel #5
0
 function pages()
 {
     $this->template->content = new View('admin/pages');
     // setup and initialize form field names
     $form = array('action' => '', 'page_id' => '', 'page_title' => '', 'page_tab' => '', 'page_description' => '');
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->action == 'a') {
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('page_title', 'required', 'length[3,150]');
             $post->add_rules('page_description', 'required');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             $page_id = $post->page_id;
             $page = new Page_Model($page_id);
             if ($post->action == 'd') {
                 // Delete Action
                 $page->delete($page_id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } else {
                 if ($post->action == 'v') {
                     // Show/Hide Action
                     if ($page->loaded == true) {
                         if ($page->page_active == 1) {
                             $page->page_active = 0;
                         } else {
                             $page->page_active = 1;
                         }
                         $page->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                     }
                 } else {
                     if ($post->action == 'a') {
                         // Save Action
                         $page->page_title = $post->page_title;
                         $page->page_tab = $post->page_tab;
                         $page->page_description = $post->page_description;
                         $page->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                     }
                 }
             }
         } else {
             // No! We have validation errors, we need to show the form again, with the errors
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('page'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('page')->count_all()));
     $pages = ORM::factory('page')->orderby('page_title', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $this->template->content->form = $form;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->pages = $pages;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->editor_enabled = TRUE;
     $this->template->js = new View('admin/pages_js');
 }
Beispiel #6
0
 /**
  * Add Edit Pages
  */
 public function pages()
 {
     $this->template->content = new View('admin/pages');
     // setup and initialize form field names
     $form = array('action' => '', 'page_id' => '', 'page_title' => '', 'page_tab' => '', 'page_description' => '');
     // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         $page = (isset($_POST['page_id']) and Page_Model::is_valid_page($_POST['page_id'])) ? ORM::factory('page', $_POST['page_id']) : new Page_Model();
         $post = array_merge($_POST, $_FILES);
         $post = array_merge($post, array("id" => $page->id));
         Event::run('ushahidi_action.page_submit', $post);
         // Check for the specified action
         if ($_POST['action'] == 'a') {
             // Manually extract the data to be validated from $_POST
             $data = arr::extract($_POST, 'page_id', 'page_title', 'page_description', 'page_tab');
             if ($page->validate($data)) {
                 $page->save();
                 Event::run('ushahidi_action.page_edit', $page);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                 array_fill_keys($form, '');
             } else {
                 // Repopulate the form fields
                 $form = arr::overwrite($form, $data->as_array());
                 // Populate the error fields, if any
                 $errors = arr::overwrite($errors, $data->errors('page'));
                 $form_error = TRUE;
             }
         } elseif ($_POST['action'] == 'd') {
             // Delete action
             if ($page->loaded) {
                 $page->delete();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             }
         } elseif ($_POST['action'] == 'v') {
             // Show/Hide Action
             if ($page->loaded) {
                 $page->page_active = $page->page_active == 1 ? 0 : 1;
                 $page->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             }
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('page')->count_all()));
     $pages = ORM::factory('page')->orderby('page_title', 'asc')->find_all($this->items_per_page, $pagination->sql_offset);
     $this->template->content->form = $form;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->pages = $pages;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->editor_enabled = TRUE;
     $this->template->js = new View('admin/pages_js');
 }