Posted by Layout Lib on Tue 7 Oct 16:04
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 Layout Class
- *
- * Permits admin pages to be constructed easier.
- *
- * @package CodeIgniter
- * @subpackage Libraries
- * @category Libraries
- * @author Philip Sturgeon
- * @link
- */
- class Layout {
- var $page_body = '';
- var $_directory = '';
- var $_module = '';
- var $_controller = '';
- var $_method = '';
- var $_page_title = '';
- var $_extra_head_content = '';
- // Default wrapper files
- var $layout_file = 'layout.php';
- var $folder_mode = 'matchbox'; // 'subdir', 'matchbox'
- var $wrap_mode = true;
- var $html_mode = false;
- // Seconds that cache will be alive for
- var $cache_lifetime = 0;//7200;
- var $CI;
- var $data;
- /**
- * Constructor - Calls the CI instance and sets a debug message
- *
- * The constructor can be passed an array of config values
- */
- function __construct()
- {
- $this->CI =& get_instance();
- log_message('debug', "Template Class Initialized");
- if($this->folder_mode == 'subdir'):
- if($this->_module == '' && $this->CI->uri->router->fetch_directory() != '/'):
- endif;
- elseif($this->folder_mode == 'matchbox'):
- if($this->_module == '' && $this->CI->matchbox->fetch_module() != ''):
- endif;
- endif;
- $s = $this->CI->uri->rsegment_array();
- $this->_method = $this->CI->uri->rsegment($n+1);
- }
- // --------------------------------------------------------------------
- /**
- * Set the mode of the creation
- *
- * @access public
- * @param string
- * @return void
- */
- function create($page_body = '', $data = NULL, $return = false, $module = '')
- {
- if($page_body != '') $this->page_body = $page_body;
- if($module != '') $this->_module = $module;
- // Merge all the data together
- $this->CI->load->helper('array');
- array_object_merge($this->data, $data);
- // Set the basic defaults
- $this->data->page_title = $this->_page_title;
- //$this->data->navigation = $this->_create_navigation();
- $this->data->breadcrumbs = $this->_create_breadcrumbs();
- $this->data->extra_head_content = $this->_extra_head_content;
- // 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 caching instead of bloody IE7
- $this->CI->output->cache($this->cache_lifetime);
- // Time to make the body, load view or parse HTML?
- if($this->html_mode):
- $output = $this->page_body;
- else:
- // If directory or module is set, use it
- $view_file = (!empty($this->_directory)) ? $this->_directory.'/'.$this->page_body : $this->page_body;
- $output = $this->CI->load->view($view_file, $this->data, true, $this->_module);
- endif;
- // Want this file wrapped with the layout file?
- if($this->wrap_mode):
- // Send what we have so far to the layout view
- $this->data->page_output = $output;
- // 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:
- $this->data->page_output = $output;
- endif;
- // Want it returned or output to browser?
- if($return):
- return $output;
- else:
- // Send it to output
- $this->CI->output->set_output($output);
- endif;
- }
- /**
- * Set the title of the page
- *
- * @access public
- * @param string
- * @return void
- */
- function title($title = '')
- {
- if($title != '') $this->_page_title = $title;
- }
- /**
- * Put extra javascipt, css, meta tags, etc
- *
- * @access public
- * @param string
- * @return void
- */
- function extra_head($str = '')
- {
- $this->_extra_head_content .= $str."\n";
- }
- function module($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 add_breadcrumb($name, $url_ref = '')
- {
- }
- function _guess_title()
- {
- $this->CI->load->helper('inflector');
- // Obviously no title, lets get making one
- // Is there a module?
- // If the method is something other than index, use that
- if($this->_method != 'index' && $title_parts[0] != $this->_method) $title_parts[] = $this->_method;
- return $this->_page_title;
- }
- // Build the array into a string with anchors and ->'s
- function _create_navigation()
- {/*
- $nav_parts = array();
- foreach($this->_navigation as $text => $link):
- // Support javascript links
- if(strpos($link, 'javascript:') === 0):
- $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 _create_breadcrumbs()
- {
- $this->CI->load->helper('inflector');
- // No crumbs (other than possibly the section crumb we just added)?
- $segment_array = $this->CI->uri->segment_array();
- foreach($segment_array as $url_ref):
- // Skip if we already have this breadcrumb and its not admin
- $url_parts[] = $url_ref;
- $this->_breadcrumbs[] = array('name'=>humanize($url_ref), 'url_ref'=>implode('/', $url_parts), 'current_page'=>false);
- endforeach;
- $url_parts[] = $last_segment;
- $this->_breadcrumbs[] = array('name'=>humanize($last_segment), 'url_ref'=>implode('/', $url_parts), 'current_page'=>true);
- endif;
- return $this->_breadcrumbs;
- }
- }
- // END Layout 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.