Exemplo n.º 1
0
<?php

$slug = uri_segment(2);
if ($slug) {
    $article = fuel_model('articles', array('find' => 'one', 'where' => array('slug' => $slug)));
    if (empty($article)) {
        redirect_404();
    }
} else {
    $tags = fuel_model('tags');
}
if (!empty($article)) {
    ?>
	
	<h1><?php 
    echo fuel_edit($article);
    echo $article->title;
    ?>
</h1>
	<div class="author"><?php 
    echo $article->author->name;
    ?>
</div>
	<img src="<?php 
    echo $article->image_path;
    ?>
" alt="<?php 
    echo $article->title_entities;
    ?>
" class="img_right" />
	<article><?php 
Exemplo n.º 2
0
 /**
  * Renders a static view page that is using the "opt-in controller" method
  *
  * @access	public
  * @param	boolean	Determines whether to return the value or to echo it out (optional)
  * @param	boolean	Determines whether to render any inline editing (optional)
  * @return	string
  */
 public function variables_render($return = FALSE, $fuelify = FALSE)
 {
     // get the location and load page vars
     $page = $this->location;
     $vars = $this->variables();
     $this->load_resources($vars);
     // for convenience we'll add the $CI object'
     $vars['CI'] =& $this->CI;
     $this->CI->load->vars($vars);
     if (!empty($vars['view'])) {
         $view = $vars['view'];
     } else {
         $view = $page;
         // if view is the index.html file, then show a 404
         if ($view == 'index.html') {
             redirect_404();
         }
         // do not display any views that have an underscore at the beginning of the view name, or is part of the path (e.g. about/_hidden/contact_email1.php)
         $view_parts = explode('/', $view);
         foreach ($view_parts as $view_part) {
             if (!strncmp($view_part, '_', 1)) {
                 show_404();
             }
         }
     }
     $output = NULL;
     // test that the file exists in the associated language
     if (!empty($this->language) and !$this->fuel->language->is_default($this->language)) {
         $view_tmp = 'language/' . $this->language . '/' . $view;
         if (file_exists($this->views_path . $view_tmp . '.php')) {
             $view = $view_tmp;
         }
     }
     // set the extension... allows for sitemap.xml for example
     $ext = '.' . pathinfo($view, PATHINFO_EXTENSION);
     $check_file = $this->views_path . $view;
     // added .php so $check_file will essentially not work and will then go to any redirects or 404
     if (empty($ext) or $ext == '.' or $ext == '.php') {
         $ext = EXT;
         $check_file = $this->views_path . $view . $ext;
     }
     // find a view file
     if (!file_exists($check_file)) {
         if (!isset($vars['find_view']) or isset($vars['find_view']) and $vars['find_view'] !== FALSE) {
             $view = $this->find_view_file($view);
             $check_file = $this->views_path . $view . $ext;
         }
     }
     // if view file exists, set the appropriate layout
     if (file_exists($check_file)) {
         // set layout variable if it isn't set yet'
         if (!empty($vars['layout'])) {
             $layout = $vars['layout'];
             $this->layout = $this->fuel->layouts->get($layout);
         }
         if ($this->layout) {
             // call layout hook
             $this->layout->call_hook('pre_render', array('vars' => $vars));
             // run the variables through the pre_process method on the layout
             // !important ... will reference the layout specified to this point so a layout variable set within the body of the page will not work
             $vars = $this->layout->pre_process($vars);
         }
         // load the file so we can parse it
         if (!empty($vars['parse_view'])) {
             // load here to save on execution time...
             $this->CI->load->library('parser');
             $body = file_get_contents($check_file);
             // now parse any template like syntax
             $vars = $this->CI->load->get_vars();
             $body = $this->CI->parser->parse_string($body, $vars, TRUE);
         } else {
             $body = $this->CI->load->module_view($this->view_module, $view, $vars, TRUE);
         }
         // now set $vars to the cached so that we have a fresh set to send to the layout in case any were declared in the view
         $vars = $this->CI->load->get_vars();
         // set layout variable again if it's changed'
         if (isset($vars['layout']) and (empty($this->layout) or is_object($this->layout) and $this->layout->name != $vars['layout'])) {
             $layout = $vars['layout'];
             if (empty($layout)) {
                 $layout = '';
             }
             $this->layout = $this->fuel->layouts->get($layout);
         }
         if ($this->layout) {
             $this->_page_data['layout'] = $layout;
             if (is_object($this->layout)) {
                 $layout = $this->layout->name;
             }
         } else {
             $this->_page_data['layout'] = NULL;
             $layout = FALSE;
         }
         if (!empty($layout)) {
             $vars['body'] = $body;
             $layout_dir = trim($this->fuel->layouts->layouts_folder, '/');
             // remove any trailing slash... we'll add it below'
             if (strncmp($layout, $layout_dir, strlen($layout_dir)) !== 0) {
                 $layout = $layout_dir . '/' . $layout;
             }
             $output = $this->CI->load->module_view($this->layout->module(), $layout, $vars, TRUE);
         } else {
             $output = $body;
         }
     }
     if (empty($output) && empty($vars['allow_empty_content'])) {
         return FALSE;
     }
     // call layout hook
     if ($layout) {
         $this->layout->call_hook('post_render', array('vars' => $vars, 'output' => $output));
         // run the post_process layout method... good for appending to the output (e.g. google analytics code)
         $output = $this->layout->post_process($output);
     }
     if ($fuelify) {
         $output = $this->fuelify($output);
     }
     if ($return) {
         return $output;
     } else {
         $this->CI->output->set_output($output);
         return TRUE;
     }
 }
Exemplo n.º 3
0
 function post($slug = null)
 {
     if (empty($slug)) {
         redirect_404();
     }
     $this->load->library('session');
     $blog_config = $this->fuel->blog->config();
     // run before_posts_by_date hook
     $hook_params = array('slug' => $slug);
     $this->fuel->blog->run_hook('before_post', $hook_params);
     $post = $this->fuel->blog->get_post($slug);
     if (isset($post->id)) {
         $vars = $this->_common_vars();
         $vars['post'] = $post;
         $vars['user'] = $this->fuel->blog->logged_in_user();
         $vars['page_title'] = $post->title;
         $vars['next'] = $this->fuel->blog->get_next_post($post);
         $vars['prev'] = $this->fuel->blog->get_prev_post($post);
         $vars['slug'] = $slug;
         $vars['is_home'] = $this->fuel->blog->is_home();
         $antispam = md5(random_string('unique'));
         $field_values = array();
         // post comment
         if (!empty($_POST)) {
             $field_values = $_POST;
             // the id of "content" is a likely ID on the front end, so we use comment_content and need to remap
             $field_values['content'] = $field_values['new_comment'];
             unset($field_values['antispam']);
             if (!empty($_POST['new_comment'])) {
                 $vars['processed'] = $this->_process_comment($post);
             } else {
                 add_error(lang('blog_error_blank_comment'));
             }
         }
         $cache_id = fuel_cache_id();
         $cache = $this->fuel->blog->get_cache($cache_id);
         if (!empty($cache) and empty($_POST)) {
             $output =& $cache;
         } else {
             $this->load->library('form');
             if (is_true_val($this->fuel->blog->config('use_captchas'))) {
                 $captcha = $this->_render_captcha();
                 $vars['captcha'] = $captcha;
             }
             $vars['thanks'] = $this->session->flashdata('thanks') ? blog_block('comment_thanks', $vars, TRUE) : '';
             $vars['comment_form'] = '';
             $this->session->set_userdata('antispam', $antispam);
             if ($post->allow_comments) {
                 $this->load->module_model(BLOG_FOLDER, 'blog_comments_model');
                 $this->load->library('form_builder', $blog_config['comment_form']);
                 $fields['author_name'] = array('label' => 'Name', 'required' => TRUE);
                 $fields['author_email'] = array('label' => 'Email', 'required' => TRUE);
                 $fields['author_website'] = array('label' => 'Website');
                 $fields['new_comment'] = array('label' => 'Comment', 'type' => 'textarea', 'required' => TRUE);
                 $fields['post_id'] = array('type' => 'hidden', 'value' => $post->id);
                 $fields['antispam'] = array('type' => 'hidden', 'value' => $antispam);
                 if (!empty($vars['captcha'])) {
                     $fields['captcha'] = array('required' => TRUE, 'label' => 'Security Text', 'value' => '', 'after_html' => ' <span class="captcha">' . $vars['captcha']['image'] . '</span><br /><span class="captcha_text">' . lang('blog_captcha_text') . '</span>');
                 }
                 // now merge with config... can't do array_merge_recursive'
                 foreach ($blog_config['comment_form']['fields'] as $key => $field) {
                     if (isset($fields[$key])) {
                         $fields[$key] = array_merge($fields[$key], $field);
                     }
                 }
                 if (!isset($blog_config['comment_form']['label_layout'])) {
                     $this->form_builder->label_layout = 'left';
                 }
                 if (!isset($blog_config['comment_form']['submit_value'])) {
                     $this->form_builder->submit_value = 'Submit Comment';
                 }
                 if (!isset($blog_config['comment_form']['use_form_tag'])) {
                     $this->form_builder->use_form_tag = TRUE;
                 }
                 if (!isset($blog_config['comment_form']['display_errors'])) {
                     $this->form_builder->display_errors = TRUE;
                 }
                 $this->form_builder->form_attrs = 'method="post" action="' . site_url($this->uri->uri_string()) . '#comments_form"';
                 $this->form_builder->set_fields($fields);
                 $this->form_builder->set_field_values($field_values);
                 $this->form_builder->set_validator($this->blog_comments_model->get_validation());
                 $vars['comment_form'] = $this->form_builder->render();
                 $vars['fields'] = $fields;
             }
             $output = $this->_render('post', $vars, TRUE);
             // save cache only if we are not posting data
             if (!empty($_POST)) {
                 $this->fuel->blog->save_cache($cache_id, $output);
             }
         }
         if (!empty($output)) {
             $this->output->set_output($output);
             return;
         }
     } else {
         show_404();
     }
 }
Exemplo n.º 4
0
 public function _remap_variables($page)
 {
     // set up cache info
     $cache_group = $this->fuel->config('page_cache_group');
     $cache_id = $this->fuel->cache->create_id();
     if ($this->fuel->config('use_page_cache') !== 'cms' and $this->cache->get($cache_id, $cache_group, FALSE) and !is_fuelified()) {
         $output = $this->cache->get($cache_id, $cache_group);
     } else {
         // get the output
         $output = $page->variables_render(TRUE, FALSE);
         // save to cache but you must not be logged in for it to save
         if ($this->fuel->config('use_page_cache') !== FALSE and $this->fuel->config('use_page_cache') !== 'cms' and !is_fuelified()) {
             $this->fuel->cache->save($cache_id, $output, $cache_group, $this->fuel->config('page_cache_ttl'));
         }
     }
     // show 404 if output is explicitly set to FALSE
     if ($output === FALSE) {
         // do any redirects... will exit script if any
         redirect_404();
     }
     // fuelify output
     $output = $page->fuelify($output);
     // render output
     $this->output->set_output($output);
 }
 function _remap()
 {
     $this->current_page = $this->fuel->user_guide->current_page();
     $cache_id = $this->current_page;
     if ($this->fuel->user_guide->config('use_cache') and $this->fuel->cache->is_cached($cache_id)) {
         $output = $this->fuel->cache->get($cache_id);
     } else {
         $this->fuel->pagevars->vars_path = USER_GUIDE_PATH . 'views/_variables/';
         $vars = array();
         // get modules
         $modules = array('', 'fuel');
         $modules = array_merge($modules, $this->fuel->config('modules_allowed'));
         $vars = $this->fuel->user_guide->get_vars($this->current_page);
         foreach ($modules as $m) {
             if ((!$this->fuel->user_guide->config('authenticate') or $this->fuel->auth->has_permission('user_guide_' . $m)) and file_exists(MODULES_PATH . $m . '/views/_docs/index' . EXT)) {
                 $module_view = $this->load->module_view($m, '_docs/index', array(), TRUE);
                 $mod_page_title = $this->fuel->user_guide->page_title($module_view);
                 $vars['modules'][$m] = !empty($mod_page_title) ? $mod_page_title : humanize($m) . ' Module';
             }
         }
         // render page
         // pull from modules folder if URI says so
         $uri_path_index = count(explode('/', $this->fuel->user_guide->config('root_url'))) + 1;
         $module_page = uri_path(FALSE, $uri_path_index);
         $module_view_path = !empty($module_page) ? '_docs/' . $module_page : '_docs/index';
         $allow_auto_generation = $this->fuel->user_guide->config('allow_auto_generation');
         if (is_file(USER_GUIDE_PATH . 'views/' . $this->current_page . EXT)) {
             $vars['body'] = $this->load->module_view(USER_GUIDE_FOLDER, $this->current_page, $vars, TRUE);
             if ($this->fuel->user_guide->page_segment(2)) {
                 $vars['sections'] = $this->fuel->user_guide->breadcrumb($this->current_page);
             }
         } else {
             if (is_file(FUEL_PATH . 'views/_docs/' . $this->current_page . EXT)) {
                 $vars['body'] = $this->load->module_view(FUEL_FOLDER, '_docs/' . $this->current_page, $vars, TRUE);
                 if ($this->fuel->user_guide->page_segment(2)) {
                     $vars['sections'] = $this->fuel->user_guide->breadcrumb($this->current_page);
                 }
             } else {
                 if ($this->fuel->user_guide->page_segment(2)) {
                     if (in_array($this->fuel->user_guide->page_segment(1), $this->fuel->user_guide->valid_folders)) {
                         $module = FUEL_FOLDER;
                         $file = $this->fuel->user_guide->page_segment(2);
                         $uri_path_index = count(explode('/', $this->fuel->user_guide->config('root_url'))) - 2;
                         $module_view_path = '_docs/' . uri_path(FALSE, $uri_path_index);
                     } else {
                         $module = $this->fuel->user_guide->page_segment(2);
                         $file = $this->fuel->user_guide->page_segment(3);
                         if (!empty($file) and $file != 'index') {
                             $module_view_path = '_docs/' . $file;
                         }
                     }
                     $body = '';
                     if (file_exists(MODULES_PATH . $module . '/views/' . $module_view_path . EXT)) {
                         $body = $this->load->module_view($module, $module_view_path, $vars, TRUE);
                     } else {
                         if ($allow_auto_generation === TRUE or in_array($module, $allow_auto_generation)) {
                             if (!empty($file)) {
                                 $uri_folder = $this->fuel->user_guide->page_segment(4);
                                 $valid_folders = $this->fuel->user_guide->valid_folders;
                                 $file_name = ucfirst($file);
                                 $folder = ($uri_folder and in_array($uri_folder, $valid_folders)) ? $uri_folder : 'libraries';
                                 if (preg_match('#_helper$#', $file)) {
                                     $folder = 'helpers';
                                     $file_name = strtolower($file);
                                 } else {
                                     if (preg_match('#_model$#', $file)) {
                                         $folder = 'models';
                                         $file_name = strtolower($file);
                                     }
                                 }
                                 $file_name = preg_replace('#^my_(\\w+)#', 'MY_$1', $file_name);
                                 $file_path = MODULES_PATH . $module . '/' . $folder . '/' . $file_name . EXT;
                                 if (file_exists($file_path)) {
                                     $body = $this->fuel->user_guide->generate_docs($file_name, $folder, $module, array());
                                 } else {
                                     $file_path = APPPATH . '/' . $folder . '/' . $file_name . EXT;
                                     if (file_exists($file_path)) {
                                         $body = $this->fuel->user_guide->generate_docs($file_name, $folder, $module, array());
                                     }
                                 }
                                 if ($this->fuel->user_guide->page_segment(2)) {
                                     $vars['sections'] = $this->fuel->user_guide->breadcrumb($this->current_page);
                                 }
                             }
                         }
                     }
                     if (!$this->fuel->user_guide->config('authenticate') or $this->fuel->auth->has_permission('user_guide_' . $module) and isset($body)) {
                         $vars['body'] = $body;
                         if ($file) {
                             if (isset($vars['modules'][$module])) {
                                 if ($module != FUEL_FOLDER) {
                                     $vars['sections'] = array($vars['modules'][$module] => 'modules/' . $module);
                                 }
                             } else {
                                 redirect_404();
                             }
                         }
                     }
                 } else {
                     redirect_404();
                 }
             }
         }
         if (empty($vars['body'])) {
             redirect_404();
         }
         $vars['page_title'] = $this->fuel->user_guide->page_title($vars['body']);
         $output = $this->load->module_view(USER_GUIDE_FOLDER, '_layouts/user_guide', $vars, TRUE);
         if ($this->fuel->user_guide->config('use_cache')) {
             $this->fuel->cache->save($cache_id, $output);
         }
     }
     $this->output->set_output($output);
 }