public function pre_output($input, $data) { // if we want an array, format it correctly if (isset($data['return_type']) and $data['return_type'] === 'array') { $keyword_array = Keywords::get_array($input); $keywords = array(); $total = count($keyword_array); foreach ($keyword_array as $key => $value) { $keywords[] = array('count' => $key, 'total' => $total, 'is_first' => $key == 0, 'is_last' => $key == $total - 1, 'keyword' => $value); } return $keywords; } // otherwise return it as a string return Keywords::get_string($input); }
/** * Get data for a page. * * @param int $id The page id. */ public function details_get($id) { $this->load->model('page_m'); // Get the page along with its chunks. $page = $this->page_m->get($id); if ($page and !empty($page)) { // We only require certain columns. $fields = array('id', 'slug', 'title', 'uri', 'css', 'js', 'meta_title', 'meta_keywords', 'meta_description', 'rss_enabled', 'comments_enabled', 'is_home', 'status', 'chunks'); // Just so that we do not redeclare it for every loop. $page_keys = array_keys($page); foreach ($page_keys as $key) { // If the key is not something we are interested in including in our response. if (!in_array($key, $fields)) { // unset it. unset($page[$key]); } } $page->meta_keywords = Keywords::get_string($page->meta_keywords); } // Sent the response out. $this->response(array('page' => $page)); }
/** * Index * * Store an entry in the search index. * * <code> * $this->search_index_m->index( * 'blog', * 'blog:post', * 'blog:posts', * $id, * 'blog/'.date('Y/m/', $post->created_on).$post->slug, * $post->title, * $post->intro, * array( * 'cp_edit_uri' => 'admin/blog/edit/'.$id, * 'cp_delete_uri' => 'admin/blog/delete/'.$id, * 'keywords' => $post->keywords, * ) * ); * </code> * * @param string $module The module that owns this entry * @param string $singular The unique singular language key for this piece of data * @param string $plural The unique plural language key that describes many pieces of this data * @param int $entry_id The id for this entry * @param string $uri The relative uri to installation root * @param string $title Title or Name of this entry * @param string $description Description of this entry * @param array $options Options such as keywords (array or string - hash of keywords) and cp_edit_url/cp_delete_url * @return array */ public function index($module, $singular, $plural, $entry_id, $uri, $title, $description = null, array $options = array()) { // Drop it so we can create a new index $this->drop_index($module, $singular, $entry_id); // Hand over keywords without needing to look them up if (!empty($options['keywords'])) { if (is_array($options['keywords'])) { $this->db->set('keywords', implode(',', $options['keywords'])); } elseif (is_string($options['keywords'])) { $this->db->set(array('keywords' => Keywords::get_string($options['keywords']), 'keyword_hash' => $options['keywords'])); } } // Store a link to edit this entry if (!empty($options['cp_edit_uri'])) { $this->db->set('cp_edit_uri', $options['cp_edit_uri']); } // Store a link to delete this entry if (!empty($options['cp_delete_uri'])) { $this->db->set('cp_delete_uri', $options['cp_delete_uri']); } return $this->db->insert('search_index', array('title' => $title, 'description' => strip_tags($description), 'module' => $module, 'entry_key' => $singular, 'entry_plural' => $plural, 'entry_id' => $entry_id, 'uri' => $uri)); }
/** * Edit an existing page * * @param int $id The id of the page. */ public function edit($id = 0) { // We are lost without an id. Redirect to the pages index. $id or redirect('admin/pages'); // The user needs to be able to edit pages. role_or_die('pages', 'edit_live'); // Retrieve the page data along with its chunk data as an array. $page = $this->page_m->get($id); // If there's a keywords hash if ($page->meta_keywords != '') { // Get comma-separated meta_keywords based on keywords hash $this->load->model('keywords/keyword_m'); $old_keywords_hash = $page->meta_keywords; $page->meta_keywords = Keywords::get_string($page->meta_keywords); } // Turn the CSV list back to an array $page->restricted_to = explode(',', $page->restricted_to); // Got page? if (!$page or empty($page)) { // Maybe you would like to create one? $this->session->set_flashdata('error', lang('pages_page_not_found_error')); redirect('admin/pages/create'); } // did they even submit? if ($input = $this->input->post()) { // do they have permission to proceed? if ($input['status'] == 'live') { role_or_die('pages', 'put_live'); } // were there keywords before this update? if (isset($old_keywords_hash)) { $input['old_keywords_hash'] = $old_keywords_hash; } // validate and insert if ($this->page_m->edit($id, $input)) { $this->session->set_flashdata('success', sprintf(lang('pages_edit_success'), $input['title'])); Events::trigger('page_updated', $id); $this->pyrocache->delete_all('page_m'); $this->pyrocache->delete_all('navigation_m'); // Mission accomplished! $input['btnAction'] == 'save_exit' ? redirect('admin/pages') : redirect('admin/pages/edit/' . $id); } else { // validation failed, we must repopulate the chunks form $chunk_slugs = $this->input->post('chunk_slug') ? array_values($this->input->post('chunk_slug')) : array(); $chunk_classes = $this->input->post('chunk_class') ? array_values($this->input->post('chunk_class')) : array(); $chunk_bodies = $this->input->post('chunk_body') ? array_values($this->input->post('chunk_body')) : array(); $chunk_types = $this->input->post('chunk_type') ? array_values($this->input->post('chunk_type')) : array(); $page->chunks = array(); $chunk_bodies_count = count($input['chunk_body']); for ($i = 0; $i < $chunk_bodies_count; $i++) { $page->chunks[] = array('id' => $i, 'slug' => !empty($chunk_slugs[$i]) ? $chunk_slugs[$i] : '', 'class' => !empty($chunk_classes[$i]) ? $chunk_classes[$i] : '', 'type' => !empty($chunk_types[$i]) ? $chunk_types[$i] : '', 'body' => !empty($chunk_bodies[$i]) ? $chunk_bodies[$i] : ''); } } } // Loop through each validation rule foreach ($this->page_m->fields() as $field) { // Nothing to do for these two fields. if (in_array($field, array('navigation_group_id', 'chunk_body[]'))) { continue; } // Translate the data of restricted_to to something we can use in the form. if ($field === 'restricted_to[]') { $page->restricted_to = set_value($field, $page->restricted_to); $page->restricted_to[0] = $page->restricted_to[0] == '' ? '0' : $page->restricted_to[0]; continue; } // Set all the other fields $page->{$field} = set_value($field, $page->{$field}); } // If this page has a parent. if ($page->parent_id > 0) { // Get only the details for the parent, no chunks. $parent_page = $this->page_m->get($page->parent_id, false); } else { $parent_page = false; } $this->_form_data(); $this->template->title($this->module_details['name'], sprintf(lang('pages:edit_title'), $page->title))->append_metadata($this->load->view('fragments/wysiwyg', array(), true))->append_css('module::page-edit.css')->set('page', $page)->set('parent_page', $parent_page)->build('admin/form'); }
/** * Edit blog post * * @access public * @param int $id the ID of the blog post to edit * @return void */ public function edit($id = 0) { $id or redirect('admin/blog'); $post = $this->blog_m->get($id); $post->keywords = Keywords::get_string($post->keywords); // If we have a useful date, use it if ($this->input->post('created_on')) { $created_on = strtotime(sprintf('%s %s:%s', $this->input->post('created_on'), $this->input->post('created_on_hour'), $this->input->post('created_on_minute'))); } else { $created_on = $post->created_on; } $this->form_validation->set_rules(array_merge($this->validation_rules, array('title' => array('field' => 'title', 'label' => 'lang:blog_title_label', 'rules' => 'trim|htmlspecialchars|required|max_length[100]|callback__check_title[' . $id . ']'), 'slug' => array('field' => 'slug', 'label' => 'lang:blog_slug_label', 'rules' => 'trim|required|alpha_dot_dash|max_length[100]|callback__check_slug[' . $id . ']')))); if ($this->form_validation->run()) { // They are trying to put this live if ($post->status != 'live' and $this->input->post('status') == 'live') { role_or_die('blog', 'put_live'); } $author_id = empty($post->display_name) ? $this->current_user->id : $post->author_id; $result = $this->blog_m->update($id, array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'keywords' => Keywords::process($this->input->post('keywords')), 'intro' => $this->input->post('intro'), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on' => $created_on, 'comments_enabled' => $this->input->post('comments_enabled'), 'author_id' => $author_id, 'type' => $this->input->post('type'), 'parsed' => $this->input->post('type') == 'markdown' ? parse_markdown($this->input->post('body')) : '')); if ($result) { $this->session->set_flashdata(array('success' => sprintf(lang('blog_edit_success'), $this->input->post('title')))); // They are trying to put this live if ($post->status != 'live' and $this->input->post('status') == 'live') { // Fire an event, we're posting a new blog! Events::trigger('blog_article_published', $id); } } else { $this->session->set_flashdata('error', $this->lang->line('blog_edit_error')); } // Redirect back to the form or main page $this->input->post('btnAction') == 'save_exit' ? redirect('admin/blog') : redirect('admin/blog/edit/' . $id); } // Go through all the known fields and get the post values foreach ($this->validation_rules as $key => $field) { if (isset($_POST[$field['field']])) { $post->{$field}['field'] = set_value($field['field']); } } $post->created_on = $created_on; $this->template->title($this->module_details['name'], sprintf(lang('blog_edit_title'), $post->title))->append_metadata($this->load->view('fragments/wysiwyg', $this->data, TRUE))->append_js('jquery/jquery.tagsinput.js')->append_js('module::blog_form.js')->append_css('jquery/jquery.tagsinput.css')->set('post', $post)->build('admin/form'); }
/** * Edit blog post * * @param int $id The ID of the blog post to edit */ public function edit($id = 0) { $id or redirect('admin/blog'); $post = $this->blog_m->get($id); // They are trying to put this live if ($post->status != 'live' and $this->input->post('status') == 'live') { role_or_die('blog', 'put_live'); } // If we have keywords before the update, we'll want to remove them from keywords_applied $old_keywords_hash = trim($post->keywords) != '' ? $post->keywords : null; $post->keywords = Keywords::get_string($post->keywords); // If we have a useful date, use it if ($this->input->post('created_on')) { $created_on = strtotime(sprintf('%s %s:%s', $this->input->post('created_on'), $this->input->post('created_on_hour'), $this->input->post('created_on_minute'))); } else { $created_on = $post->created_on; } // Load up streams $this->load->driver('Streams'); $stream = $this->streams->streams->get_stream('blog', 'blogs'); $stream_fields = $this->streams_m->get_stream_fields($stream->id, $stream->stream_namespace); // Get the validation for our custom blog fields. $blog_validation = $this->streams->streams->validation_array($stream->stream_slug, $stream->stream_namespace, 'new'); $blog_validation = array_merge($this->validation_rules, array('title' => array('field' => 'title', 'label' => 'lang:global:title', 'rules' => 'trim|htmlspecialchars|required|max_length[100]|callback__check_title[' . $id . ']'), 'slug' => array('field' => 'slug', 'label' => 'lang:global:slug', 'rules' => 'trim|required|alpha_dot_dash|max_length[100]|callback__check_slug[' . $id . ']'))); // Merge and set our validation rules $this->form_validation->set_rules(array_merge($this->validation_rules, $blog_validation)); $hash = $this->input->post('preview_hash'); if ($this->input->post('status') == 'draft' and $this->input->post('preview_hash') == '') { $hash = $this->_preview_hash(); } elseif ($this->input->post('status') == 'live') { $hash = ''; } if ($this->form_validation->run()) { $author_id = empty($post->display_name) ? $this->current_user->id : $post->author_id; $extra = array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'keywords' => Keywords::process($this->input->post('keywords'), $old_keywords_hash), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on' => $created_on, 'updated_on' => $created_on, 'created' => date('Y-m-d H:i:s', $created_on), 'updated' => date('Y-m-d H:i:s', $created_on), 'comments_enabled' => $this->input->post('comments_enabled'), 'author_id' => $author_id, 'type' => $this->input->post('type'), 'parsed' => $this->input->post('type') == 'markdown' ? parse_markdown($this->input->post('body')) : '', 'preview_hash' => $hash); if ($this->streams->entries->update_entry($id, $_POST, 'blog', 'blogs', array('updated'), $extra)) { $this->session->set_flashdata(array('success' => sprintf(lang('blog:edit_success'), $this->input->post('title')))); // Blog article has been updated, may not be anything to do with publishing though Events::trigger('post_updated', $id); // They are trying to put this live if ($post->status != 'live' and $this->input->post('status') == 'live') { // Fire an event, we're posting a new blog! Events::trigger('post_published', $id); } } else { $this->session->set_flashdata('error', lang('blog:edit_error')); } // Redirect back to the form or main page $this->input->post('btnAction') == 'save_exit' ? redirect('admin/blog') : redirect('admin/blog/edit/' . $id); } // Go through all the known fields and get the post values foreach ($this->validation_rules as $key => $field) { if (isset($_POST[$field['field']])) { $post->{$field}['field'] = set_value($field['field']); } } $post->created_on = $created_on; // Set Values $values = $this->fields->set_values($stream_fields, $post, 'edit'); // Run stream field events $this->fields->run_field_events($stream_fields, array(), $values); $this->template->title($this->module_details['name'], sprintf(lang('blog:edit_title'), $post->title))->append_metadata($this->load->view('fragments/wysiwyg', array(), true))->append_js('jquery/jquery.tagsinput.js')->append_js('module::blog_form.js')->set('stream_fields', $this->streams->fields->get_stream_fields($stream->stream_slug, $stream->stream_namespace, $values, $post->id))->append_css('jquery/jquery.tagsinput.css')->set('post', $post)->build('admin/form'); }
/** * Edit news post * * @param int $id The ID of the news post to edit */ public function edit($id = 0) { $id or redirect('admin/news'); $post = $this->news_m->get($id); // They are trying to put this live if ($post->status != 'live' and $this->input->post('status') == 'live') { role_or_die('news', 'put_live'); } // If we have keywords before the update, we'll want to remove them from keywords_applied $old_keywords_hash = trim($post->keywords) != '' ? $post->keywords : null; $post->keywords = Keywords::get_string($post->keywords); // If we have a useful date, use it if ($this->input->post('created_on')) { $created_on = strtotime(sprintf('%s %s:%s', $this->input->post('created_on'), $this->input->post('created_on_hour'), $this->input->post('created_on_minute'))); } else { $created_on = $post->created_on; } // Load up streams $this->load->driver('Streams'); $stream = $this->streams->streams->get_stream('news', 'news'); $stream_fields = $this->streams_m->get_stream_fields($stream->id, $stream->stream_namespace); // Get the validation for our custom news fields. $news_validation = $this->streams->streams->validation_array($stream->stream_slug, $stream->stream_namespace, 'new'); $news_validation = array_merge($this->validation_rules, array('title' => array('field' => 'title', 'label' => 'lang:global:title', 'rules' => 'trim|htmlspecialchars|required|max_length[100]|callback__check_title[' . $id . ']'), 'slug' => array('field' => 'slug', 'label' => 'lang:global:slug', 'rules' => 'trim|required|alpha_dot_dash|max_length[100]|callback__check_slug[' . $id . ']'))); // Upload image validation if ($_FILES) { $allowed = array('.jpg', '.jpeg', '.gif', '.png'); $upload_key = array_keys($_FILES); if (!empty($_FILES[$upload_key[0]]['name']) && $_FILES[$upload_key[0]]['error'] == UPLOAD_ERR_OK) { $ext = strtolower(strrchr($_FILES[$upload_key[0]]['name'], '.')); if (!in_array($ext, $allowed)) { $this->form_validation->set_error('Invalid image file extension. Allowed extension are .jpg, .jpeg, .png, .gif'); } } } // Merge and set our validation rules $this->form_validation->set_rules(array_merge($this->validation_rules, $news_validation)); $hash = $this->input->post('preview_hash'); if ($this->input->post('status') == 'draft' and $this->input->post('preview_hash') == '') { $hash = $this->_preview_hash(); } elseif ($this->input->post('status') == 'live') { $hash = ''; } if ($this->form_validation->run()) { $author_id = empty($post->display_name) ? $this->current_user->id : $post->author_id; $extra = array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'keywords' => Keywords::process($this->input->post('keywords'), $old_keywords_hash), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on' => $created_on, 'updated_on' => $created_on, 'created' => date('Y-m-d H:i:s', $created_on), 'updated' => date('Y-m-d H:i:s', $created_on), 'comments_enabled' => $this->input->post('comments_enabled'), 'author_id' => $author_id, 'type' => $this->input->post('type'), 'parsed' => $this->input->post('type') == 'markdown' ? parse_markdown($this->input->post('body')) : '', 'preview_hash' => $hash); if ($this->streams->entries->update_entry($id, $_POST, 'news', 'news', array('updated'), $extra)) { // Upload image if ($_FILES) { $upload_key = array_keys($_FILES); if (!empty($_FILES[$upload_key[0]]['name']) && $_FILES[$upload_key[0]]['error'] == UPLOAD_ERR_OK) { $tmp_name = $_FILES[$upload_key[0]]['tmp_name']; $ext = strtolower(strrchr($_FILES[$upload_key[0]]['name'], '.')); $file_name = 'IMG_' . date('Ymd_His') . $ext; if (@move_uploaded_file($tmp_name, $this->_news_base_file_dir . '/' . $file_name)) { @unlink($this->_news_base_file_dir . '/' . $post->image); $this->db->update('news', array('image' => $file_name), array('id' => $id)); } } } $this->session->set_flashdata(array('success' => sprintf(lang('news:edit_success'), $this->input->post('title')))); // news article has been updated, may not be anything to do with publishing though Events::trigger('post_updated', $id); // They are trying to put this live if ($post->status != 'live' and $this->input->post('status') == 'live') { // Fire an event, we're posting a new news! Events::trigger('post_published', $id); } } else { $this->session->set_flashdata('error', lang('news:edit_error')); } // Redirect back to the form or main page $this->input->post('btnAction') == 'save_exit' ? redirect('admin/news') : redirect('admin/news/edit/' . $id); } // Go through all the known fields and get the post values foreach ($this->validation_rules as $key => $field) { if (isset($_POST[$field['field']])) { $post->{$field}['field'] = set_value($field['field']); } } if (file_exists(UPLOAD_PATH . 'news/' . $post->image) && is_file(UPLOAD_PATH . 'news/' . $post->image)) { $image = $this->_news_base_file_dir . '/' . $post->image; $this->load->model('files/image_m'); $post->image = $this->_news_base_file_url . '/' . $post->image; $post->thumb = $this->image_m->resize($image, 100, 100, 'crop'); } $post->created_on = $created_on; // Set Values $values = $this->fields->set_values($stream_fields, $post, 'edit'); // Run stream field events $this->fields->run_field_events($stream_fields, array(), $values); $this->template->title($this->module_details['name'], sprintf(lang('news:edit_title'), $post->title))->append_metadata($this->load->view('fragments/wysiwyg', array(), true))->append_js('jquery/jquery.tagsinput.js')->append_js('module::news_form.js')->set('stream_fields', $this->streams->fields->get_stream_fields($stream->stream_slug, $stream->stream_namespace, $values, $post->id))->append_css('jquery/jquery.tagsinput.css')->set('post', $post)->build('admin/form'); }
/** * Page method * * @param array $url_segments The URL segments. */ public function _page($url_segments) { // Get our chunks field type if this is an // upgraded site. if ($this->db->table_exists('page_chunks')) { $this->type->load_types_from_folder(APPPATH . 'modules/pages/field_types/', 'pages_module'); } // If we are on the development environment, // we should get rid of the cache. That ways we can just // make updates to the page type files and see the // results immediately. if (ENVIRONMENT == PYRO_DEVELOPMENT) { $this->pyrocache->delete_all('page_m'); } // GET THE PAGE ALREADY. In the event of this being the home page $url_segments will be null $page = $this->page_m->get_by_uri($url_segments, true); // Setting this so others may use it. $this->template->set('page', $page); // If page is missing or not live (and the user does not have permission) show 404 if (!$page or $page->status == 'draft' and !$this->permission_m->has_role(array('put_live', 'edit_live'))) { // Load the '404' page. If the actual 404 page is missing (oh the irony) bitch and quit to prevent an infinite loop. if (!($page = $this->pyrocache->model('page_m', 'get_by_uri', array('404')))) { show_error('The page you are trying to view does not exist and it also appears as if the 404 page has been deleted.'); } } // the home page won't have a base uri isset($page->base_uri) or $page->base_uri = $url_segments; // If this is a homepage, do not show the slug in the URL if ($page->is_home and $url_segments) { redirect('', 'location', 301); } // If the page is missing, set the 404 status header if ($page->slug == '404') { $this->output->set_status_header(404); } elseif ($page->restricted_to) { $page->restricted_to = (array) explode(',', $page->restricted_to); // Are they logged in and an admin or a member of the correct group? if (!$this->current_user or isset($this->current_user->group) and $this->current_user->group != 'admin' and !in_array($this->current_user->group_id, $page->restricted_to)) { // send them to login but bring them back when they're done redirect('users/login/' . (empty($url_segments) ? '' : implode('/', $url_segments))); } } // We want to use the valid uri from here on. Don't worry about segments passed by Streams or // similar. Also we don't worry about breadcrumbs for 404 if ($url_segments = explode('/', $page->base_uri) and count($url_segments) > 1) { // we dont care about the last one array_pop($url_segments); // This array of parents in the cache? if (!($parents = $this->pyrocache->get('page_m/' . md5(implode('/', $url_segments))))) { $parents = $breadcrumb_segments = array(); foreach ($url_segments as $segment) { $breadcrumb_segments[] = $segment; $parents[] = $this->pyrocache->model('page_m', 'get_by_uri', array($breadcrumb_segments, true, true)); } // Cache for next time $this->pyrocache->write($parents, 'page_m/' . md5(implode('/', $url_segments))); } foreach ($parents as $parent_page) { $this->template->set_breadcrumb($parent_page->title, $parent_page->uri); } } // If this page has an RSS feed, show it if ($page->rss_enabled) { $this->template->append_metadata('<link rel="alternate" type="application/rss+xml" title="' . $page->meta_title . '" href="' . site_url(uri_string() . '.rss') . '" />'); } // Set pages layout files in your theme folder if ($this->template->layout_exists($page->uri . '.html')) { $this->template->set_layout($page->uri . '.html'); } // If a Page Type has a Theme Layout that exists, use it if (!empty($page->layout->theme_layout) and $this->template->layout_exists($page->layout->theme_layout) and ($this->template->layout_is('default.html') or $page->layout->theme_layout !== 'default.html')) { $this->template->set_layout($page->layout->theme_layout); } // --------------------------------- // Metadata // --------------------------------- // First we need to figure out our metadata. If we have meta for our page, // that overrides the meta from the page layout. $meta_title = $page->meta_title ? $page->meta_title : $page->layout->meta_title; $meta_description = $page->meta_description ? $page->meta_description : $page->layout->meta_description; $meta_keywords = ''; if ($page->meta_keywords or $page->layout->meta_keywords) { $meta_keywords = $page->meta_keywords ? Keywords::get_string($page->meta_keywords) : Keywords::get_string($page->layout->meta_keywords); } $meta_robots = $page->meta_robots_no_index ? 'noindex' : 'index'; $meta_robots .= $page->meta_robots_no_follow ? ',nofollow' : ',follow'; // They will be parsed later, when they are set for the template library. // Not got a meta title? Use slogan for homepage or the normal page title for other pages if (!$meta_title) { $meta_title = $page->is_home ? $this->settings->site_slogan : $page->title; } // Set the title, keywords, description, and breadcrumbs. $this->template->title($this->parser->parse_string($meta_title, $page, true))->set_metadata('keywords', $this->parser->parse_string($meta_keywords, $page, true))->set_metadata('robots', $meta_robots)->set_metadata('description', $this->parser->parse_string($meta_description, $page, true))->set_breadcrumb($page->title); // Parse the CSS so we can use tags like {{ asset:inline_css }} // #foo {color: red} {{ /asset:inline_css }} // to output css via the {{ asset:render_inline_css }} tag. This is most useful for JS $css = $this->parser->parse_string($page->layout->css . $page->css, $this, true); // there may not be any css (for sure after parsing Lex tags) if ($css) { $this->template->append_metadata(' <style type="text/css"> ' . $css . ' </style>', 'late_header'); } $js = $this->parser->parse_string($page->layout->js . $page->js, $this, true); // Add our page and page layout JS if ($js) { $this->template->append_metadata(' <script type="text/javascript"> ' . $js . ' </script>'); } // If comments are enabled, go fetch them all if (Settings::get('enable_comments')) { // Load Comments so we can work out what to do with them $this->load->library('comments/comments', array('entry_id' => $page->id, 'entry_title' => $page->title, 'module' => 'pages', 'singular' => 'pages:page', 'plural' => 'pages:pages')); } // Get our stream. $stream = $this->streams_m->get_stream($page->layout->stream_id); // We are going to pre-build this data so we have the data // available to the template plugin (since we are pre-parsing our views). $template = $this->template->build_template_data(); // Parse our view file. The view file is nothing // more than an echo of $page->layout->body and the // comments after it (if the page has comments). $html = $this->template->load_view('pages/page', array('page' => $page), false); $view = $this->parser->parse_string($html, $page, true, false, array('stream' => $stream->stream_slug, 'namespace' => $stream->stream_namespace, 'id_name' => 'entry_id')); if ($page->slug == '404') { log_message('error', 'Page Missing: ' . $this->uri->uri_string()); // things behave a little differently when called by MX from MY_Exceptions' show_404() exit($this->template->build($view, array('page' => $page), false, false, true, $template)); } $this->template->build($view, array('page' => $page), false, false, true, $template); }
public function pre_output($input) { return Keywords::get_string($input); }
/** * Page method * * @param array $url_segments The URL segments. */ public function _page($url_segments) { $page = $url_segments !== NULL ? $this->pyrocache->model('page_m', 'get_by_uri', array($url_segments, TRUE)) : $this->pyrocache->model('page_m', 'get_home'); // If page is missing or not live (and not an admin) show 404 if (!$page or $page->status == 'draft' and (!isset($this->current_user->group) or $this->current_user->group != 'admin')) { // Load the '404' page. If the actual 404 page is missing (oh the irony) bitch and quit to prevent an infinite loop. if (!($page = $this->pyrocache->model('page_m', 'get_by_uri', array('404')))) { show_error('The page you are trying to view does not exist and it also appears as if the 404 page has been deleted.'); } } // the home page won't have a base uri isset($page->base_uri) or $page->base_uri = $url_segments; // If this is a homepage, do not show the slug in the URL if ($page->is_home and $url_segments) { redirect('', 'location', 301); } // If the page is missing, set the 404 status header if ($page->slug == '404') { $this->output->set_status_header(404); } elseif ($page->restricted_to) { $page->restricted_to = (array) explode(',', $page->restricted_to); // Are they logged in and an admin or a member of the correct group? if (!$this->current_user or isset($this->current_user->group) and $this->current_user->group != 'admin' and !in_array($this->current_user->group_id, $page->restricted_to)) { // send them to login but bring them back when they're done redirect('users/login/' . (empty($url_segments) ? '' : implode('/', $url_segments))); } } // We want to use the valid uri from here on. Don't worry about segments passed by Streams or // similar. Also we don't worry about breadcrumbs for 404 if ($url_segments = explode('/', $page->base_uri) and count($url_segments) > 1) { // we dont care about the last one array_pop($url_segments); // This array of parents in the cache? if (!($parents = $this->pyrocache->get('page_m/' . md5(implode('/', $url_segments))))) { $parents = $breadcrumb_segments = array(); foreach ($url_segments as $segment) { $breadcrumb_segments[] = $segment; $parents[] = $this->pyrocache->model('page_m', 'get_by_uri', array($breadcrumb_segments, TRUE)); } // Cache for next time $this->pyrocache->write($parents, 'page_m/' . md5(implode('/', $url_segments))); } foreach ($parents as $parent_page) { $this->template->set_breadcrumb($parent_page->title, $parent_page->uri); } } // Not got a meta title? Use slogan for homepage or the normal page title for other pages if ($page->meta_title == '') { $page->meta_title = $page->is_home ? $this->settings->site_slogan : $page->title; } // If this page has an RSS feed, show it if ($page->rss_enabled) { $this->template->append_metadata('<link rel="alternate" type="application/rss+xml" title="' . $page->meta_title . '" href="' . site_url(uri_string() . '.rss') . '" />'); } // Wrap the page with a page layout, otherwise use the default 'Home' layout if (!($page->layout = $this->page_layouts_m->get($page->layout_id))) { // Some pillock deleted the page layout, use the default and pray to god they didnt delete that too $page->layout = $this->page_layouts_m->get(1); } // Set pages layout files in your theme folder if ($this->template->layout_exists($page->uri . '.html')) { $this->template->set_layout($page->uri . '.html'); } // If a Page Layout has a Theme Layout that exists, use it if (!empty($page->layout->theme_layout) and $this->template->layout_exists($page->layout->theme_layout) and ($this->template->layout_is('default.html') or $page->layout->theme_layout !== 'default.html')) { $this->template->set_layout($page->layout->theme_layout); } // Grab all the chunks that make up the body $page->chunks = $this->page_m->get_chunks($page->id); $chunk_html = ''; foreach ($page->chunks as $chunk) { $chunk_html .= '<section id="' . $chunk->slug . '" class="page-chunk ' . $chunk->class . '">' . '<div class="page-chunk-pad">' . ($chunk->type == 'markdown' ? $chunk->parsed : $chunk->body) . '</div>' . '</section>' . PHP_EOL; } // Create page output. We do this before parsing the page contents so that // title, meta, & breadcrumbs can be overridden with tags in the page content $this->template->title($page->meta_title)->set_metadata('keywords', Keywords::get_string($page->meta_keywords))->set_metadata('description', $page->meta_description)->set_breadcrumb($page->title); // Parse it so the embedded tags are parsed. We pass along $page so that {{ page:id }} and friends work in page content. $page->body = $this->parser->parse_string(str_replace(array(''', '"'), array("'", '"'), $chunk_html), array('theme' => $this->theme, 'page' => $page), TRUE); if ($page->layout->css or $page->css) { $this->template->append_metadata(' <style type="text/css"> ' . $page->layout->css . ' ' . $page->css . ' </style>', 'late_header'); } if ($page->layout->js or $page->js) { $this->template->append_metadata(' <script type="text/javascript"> ' . $page->layout->js . ' ' . $page->js . ' </script>'); } if ($page->slug == '404') { log_message('error', 'Page Missing: ' . $this->uri->uri_string()); // things behave a little differently when called by MX from MY_Exceptions' show_404() exit($this->template->build('pages/page', array('page' => $page), FALSE, FALSE)); } $this->template->build('page', array('page' => $page), FALSE, FALSE); }