Posted by Template Lib 09 on Sat 12 Jan 14:28
report abuse | download | new post
- /**
- * CodeIgniter
- *
- * An open source application development framework for PHP 4.3.2 or newer
- *
- * @package CodeIgniter
- * @author Rick Ellis
- * @copyright Copyright (c) 2006, EllisLab, Inc.
- * @license http://www.codeignitor.com/user_guide/license.html
- * @link http://www.codeigniter.com
- * @since Version 1.0
- * @filesource
- */
- // ------------------------------------------------------------------------
- /**
- * CodeIgniter Template Class
- *
- * Permits admin pages to be constructed easier.
- *
- * @package CodeIgniter
- * @subpackage Libraries
- * @category Libraries
- * @author Philip Sturgeon
- * @link
- */
- class Template {
- var $page_body = '';
- var $directory = '';
- var $module = '';
- var $title = '';
- var $extra_head_content = '';
- // Default wrapper files
- var $layout_file = 'layout.php';
- var $sub_layout_file = '';
- var $folder_mode = 'modules';
- var $wrap_mode = true;
- var $html_mode = false;
- // Seconds that cache will be alive for
- var $cache_lifetime = 0;//7200;
- var $error_messages = 0;
- var $CI;
- /**
- * Constructor - Calls the CI instance and sets a debug message
- *
- * The constructor can be passed an array of config values
- */
- function Template()
- {
- $this->CI =& get_instance();
- log_message('debug', "Template Class Initialized");
- if($this->folder_mode == 'modules'):
- // If the current module setting is empty, and there is a module loaded...
- if($this->module == '' && $this->CI->uri->router->fetch_module() != 'modules//'):
- endif;
- elseif($this->folder_mode == 'subdir'):
- if($this->directory == '' && $this->CI->uri->router->fetch_directory() != '/'):
- endif;
- endif;
- }
- // --------------------------------------------------------------------
- /**
- * Set the mode of the creation
- *
- * @access public
- * @param string
- * @return void
- */
- {
- $this->CI =& get_instance();
- $this->CI->load->library('defaults');
- $default_data = $this->CI->defaults->fetch();
- if($page_body != '') $this->page_body = $page_body;
- if($module != '') $this->module = $module;
- // Merge all the data together
- // Set the basic defaults
- $this->data['page_title'] = $this->title;
- $this->data['navigation'] = $this->_build_navigation();
- $this->data['crumbs'] = $this->_build_crumbs();
- $this->data['extra_head_content'] = ($this->extra_head_content) ? $this->extra_head_content : '';
- // If the page should include an error too, then parse the error box
- $this->data['error_box'] = (!empty($this->data['error_string'])) ? $this->CI->load->view('error_box', $this->data, true, $module) : '';
- // If the page should include an info message too, then parse the info box
- $this->data['info_box'] = (!empty($this->data['info_string'])) ? $this->CI->load->view('info_box', $this->data, true, $module) : '';
- // Disable sodding IE7's constant cacheing!!
- $this->CI->output->set_header("HTTP/1.0 200 OK");
- $this->CI->output->set_header("HTTP/1.1 200 OK");
- $this->CI->output->set_header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- $this->CI->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
- $this->CI->output->set_header("Cache-Control: post-check=0, pre-check=0, max-age=0");
- $this->CI->output->set_header("Pragma: no-cache");
- // Let CI do the cacheing instead... if they want it!
- $this->CI->output->cache($this->cache_lifetime);
- // Time to make the body, load view or parse HTML?
- if($this->html_mode):
- $this->data['page_content'] = $this->page_body;
- else:
- // If directory is set, use it
- $this->data['page_content'] = $this->CI->load->view($view_file, $this->data, true, $this->module);
- endif;
- // Want header and footer file included, or just the main file?
- if($this->wrap_mode):
- // Using a sub-wrapper. Like an extra few divs round a page or a special set of blocks
- $this->data['sub_page_content'] = $this->data['page_content'];
- // If directory is set, use it
- $sub_layout = (!empty($this->directory)) ? $this->directory.'/'.$this->sub_layout_file : $this->sub_layout_file;
- $this->data['page_content'] = $this->CI->load->view($sub_layout, $this->data, true, $this->sub_layout_module);
- endif;
- // If directory is set, use it
- $layout_file = (!empty($this->directory)) ? $this->directory.'/'.$this->layout_file : $this->layout_file;
- $output = $this->CI->load->view($layout_file, $this->data, true);
- else:
- $output = $this->data['page_content'];
- endif;
- // Want it returned or output to browser?
- if($return):
- return $output;
- else:
- // Send it to output
- $this->CI->output->set_output($output);
- endif;
- }
- /**
- * Allows for custom view segments to be loaded
- *
- * @access public
- * @param string
- * @param string
- * @return void
- */
- function sub_layout($filename, $sectionname = NULL)
- {
- $this->sub_layout_file = $filename;
- $this->sub_layout_module = $sectionname;
- }
- /**
- * Set the title of the page
- *
- * @access public
- * @param string
- * @return void
- */
- function title($title = '')
- {
- if($title != '') $this->title = $title;
- }
- /**
- * Put extra javascipt, css, meta tags, etc
- *
- * @access public
- * @param string
- * @return void
- */
- function extra_head($str = '')
- {
- }
- function directory($directory = '')
- {
- if($directory != '') $this->directory = $directory;
- }
- function module($module = '')
- {
- if($module != '') $this->module = $module;
- }
- /**
- * Should we include headers and footers?
- *
- * @access public
- * @param string
- * @return void
- */
- function html_mode($html = true)
- {
- $this->html_mode = $html;
- }
- /**
- * Should we include headers and footers?
- *
- * @access public
- * @param string
- * @return void
- */
- function wrap_mode($wrap = true)
- {
- $this->wrap_mode = $wrap;
- }
- /**
- * Create navigations for a specific page
- *
- * @access public
- * @param string
- * @param string
- * @return void
- */
- {
- $this->navigation = $this->navigation + $links;
- }
- /**
- * Helps build custom breadcrumb trails
- *
- * @access public
- * @param string
- * @param string
- * @return void
- */
- function crumb($name, $segment = NULL)
- {
- }
- /**
- * Add an error message to the page
- *
- * @access public
- * @param string
- * @return void
- */
- function error($error_string = '', $error_output = 'error_string')
- {
- $this->data[$error_output] .= $error_string."<br/>\n";
- else:
- $this->data[$error_output] = $error_string."<br/>\n";
- endif;
- $this->error_messages++;
- }
- /**
- * Check if there is an error message
- *
- * @access public
- * @return void
- */
- function have_errors()
- {
- if($this->error_messages > 0) return true;
- else return false;
- }
- /**
- * Add an info message to the page
- *
- * @access public
- * @param string
- * @return void
- */
- function info($info_string = '', $info_output = 'info_string')
- {
- $this->data[$info_output] .= $info_string."<br/>\n";
- else:
- $this->data[$info_output] = $info_string."<br/>\n";
- endif;
- }
- function _guess_title()
- {
- $this->CI =& get_instance();
- $this->CI->load->helper('inflector');
- // Obviously no title, lets get making one
- if($this->folder_mode == 'modules'):
- elseif($this->folder_mode == 'subdir'):
- endif;
- $controller = $this->CI->uri->router->class;
- $method = $this->CI->uri->router->method;
- // Is there a module?
- else $title_parts[] = $controller;
- // If the method isnt index, use that
- if($method != 'index') $title_parts[] = $method;
- return $this->title;
- }
- // Build the array into a string with anchors and ->'s
- function _build_navigation()
- {
- foreach($this->navigation as $text => $link):
- // Support javascript links
- $nav_parts[] = '<a href="'.$link.'" title="'.$text.'">'.$text.'</a>';
- else:
- $nav_parts[] = anchor($link, $text);
- endif;
- endforeach;
- return $nav_parts;
- }
- // Build the array into a string with anchors and ->'s
- function _build_crumbs()
- {
- $this->CI =& get_instance();
- $this->CI->load->helper('inflector');
- // First, we need the module name
- if($this->folder_mode == 'modules'):
- elseif($this->folder_mode == 'subdir'):
- endif;
- // Force it to the front
- // No crumbs? Lets add some
- $controller = $this->CI->uri->router->class;
- endif;
- foreach($this->crumbs as $crumb):
- $crumb_parts[] = anchor($crumb[1], $crumb[0]);
- else:
- $crumb_parts[] = $crumb[0];
- endif;
- endforeach;
- return $crumb_string;
- }
- }
- // END Template class
- ?>
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.