pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

styledna private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Layout Lib on Tue 7 Oct 16:04
report abuse | download | new post

  1. <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3.  * CodeIgniter
  4.  *
  5.  * An open source application development framework for PHP 4.3.2 or newer
  6.  *
  7.  * @package        CodeIgniter
  8.  * @author        Rick Ellis
  9.  * @copyright    Copyright (c) 2006, EllisLab, Inc.
  10.  * @license        http://www.codeignitor.com/user_guide/license.html
  11.  * @link        http://www.codeigniter.com
  12.  * @since        Version 1.0
  13.  * @filesource
  14.  */
  15.  
  16. // ------------------------------------------------------------------------
  17.  
  18. /**
  19.  * CodeIgniter Layout Class
  20.  *
  21.  * Permits admin pages to be constructed easier.
  22.  *
  23.  * @package             CodeIgniter
  24.  * @subpackage          Libraries
  25.  * @category            Libraries
  26.  * @author              Philip Sturgeon
  27.  * @link
  28.  */
  29. class Layout {
  30.  
  31.     var $page_body = '';
  32.     var $_directory = '';
  33.     var $_module = '';
  34.     var $_controller = '';
  35.     var $_method = '';
  36.  
  37.     var $_page_title = '';
  38.     var $_extra_head_content = '';
  39.     var $_breadcrumbs = array();
  40.     var $_navigation = array();
  41.  
  42.     // Default wrapper files
  43.     var $layout_file = 'layout.php';
  44.  
  45.     var $folder_mode = 'matchbox'; // 'subdir', 'matchbox'
  46.     var $wrap_mode = true;
  47.     var $html_mode = false;
  48.  
  49.     // Seconds that cache will be alive for
  50.     var $cache_lifetime = 0;//7200;
  51.  
  52.     var $CI;
  53.     var $data;
  54.  
  55.     /**
  56.      * Constructor - Calls the CI instance and sets a debug message
  57.      *
  58.      * The constructor can be passed an array of config values
  59.      */
  60.     function __construct()
  61.     {
  62.         $this->CI =& get_instance();
  63.         log_message('debug', "Template Class Initialized");
  64.  
  65.         if($this->folder_mode == 'subdir'):
  66.  
  67.             if($this->_module == '' && $this->CI->uri->router->fetch_directory() != '/'):
  68.                 $this->_module = str_replace('/', '', $this->CI->uri->router->fetch_directory());
  69.             endif;
  70.  
  71.         elseif($this->folder_mode == 'matchbox'):
  72.  
  73.             if($this->_module == '' && $this->CI->matchbox->fetch_module() != ''):
  74.                 $this->_module = str_replace(array('modules/', '/'), '', $this->CI->matchbox->fetch_module());
  75.             endif;
  76.            
  77.         endif;
  78.        
  79.         $this->_controller      = strtolower(get_class($this->CI));
  80.         $s                                      = $this->CI->uri->rsegment_array();
  81.         $n                                      = array_search($this->_controller, $s);
  82.         $this->_method          = $this->CI->uri->rsegment($n+1);
  83.     }
  84.  
  85.     // --------------------------------------------------------------------
  86.  
  87.     /**
  88.      * Set the mode of the creation
  89.      *
  90.      * @access    public
  91.      * @param    string
  92.  
  93.      * @return    void
  94.      */
  95.     function create($page_body = '', $data = NULL, $return = false, $module = '')
  96.     {
  97.         if($page_body != '') $this->page_body = $page_body;
  98.         if($module != '')    $this->_module = $module;
  99.  
  100.         // Merge all the data together
  101.         $this->CI->load->helper('array');
  102.         array_object_merge($this->data, $data);
  103.  
  104.         if(empty($this->_page_title)) $this->_guess_title();
  105.  
  106.         // Set the basic defaults
  107.         $this->data->page_title                         = $this->_page_title;
  108.         //$this->data->navigation           = $this->_create_navigation();
  109.         $this->data->breadcrumbs            = $this->_create_breadcrumbs();
  110.         $this->data->extra_head_content         = $this->_extra_head_content;
  111.  
  112.         // Disable sodding IE7's constant cacheing!!
  113.         $this->CI->output->set_header("HTTP/1.0 200 OK");
  114.         $this->CI->output->set_header("HTTP/1.1 200 OK");
  115.         $this->CI->output->set_header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  116.         $this->CI->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
  117.         $this->CI->output->set_header("Cache-Control: post-check=0, pre-check=0, max-age=0");
  118.         $this->CI->output->set_header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
  119.         $this->CI->output->set_header("Pragma: no-cache");
  120.  
  121.         // Let CI do the caching instead of bloody IE7
  122.         $this->CI->output->cache($this->cache_lifetime);
  123.  
  124.         // Time to make the body, load view or parse HTML?
  125.         if($this->html_mode):
  126.                 $output = $this->page_body;
  127.  
  128.         else:
  129.             // If directory or module is set, use it
  130.             $view_file = (!empty($this->_directory)) ? $this->_directory.'/'.$this->page_body : $this->page_body;
  131.             $output = $this->CI->load->view($view_file, $this->data, true, $this->_module);
  132.         endif;
  133.        
  134.         // Want this file wrapped with the layout file?
  135.         if($this->wrap_mode):
  136.                         // Send what we have so far to the layout view
  137.                         $this->data->page_output = $output;
  138.                        
  139.             // If directory is set, use it
  140.             $layout_file = (!empty($this->_directory)) ? $this->_directory.'/'.$this->layout_file : $this->layout_file;
  141.             $output = $this->CI->load->view($layout_file, $this->data, true);
  142.        
  143.         else:
  144.                  $this->data->page_output = $output;
  145.         endif;
  146.  
  147.         // Want it returned or output to browser?
  148.         if($return):
  149.             return $output;
  150.         else:
  151.             // Send it to output
  152.             $this->CI->output->set_output($output);
  153.         endif;
  154.  
  155.     }
  156.  
  157.     /**
  158.      * Set the title of the page
  159.      *
  160.      * @access    public
  161.      * @param    string
  162.      * @return    void
  163.      */
  164.  
  165.     function title($title = '')
  166.     {
  167.         if($title != '') $this->_page_title = $title;
  168.     }
  169.  
  170.     /**
  171.      * Put extra javascipt, css, meta tags, etc
  172.      *
  173.      * @access    public
  174.      * @param    string
  175.      * @return    void
  176.      */
  177.  
  178.     function extra_head($str = '')
  179.     {
  180.         $this->_extra_head_content .= $str."\n";
  181.     }
  182.  
  183.     function module($module = '')
  184.     {
  185.         $this->_module = $module;
  186.     }
  187.  
  188.     /**
  189.      * Should we include headers and footers?
  190.      *
  191.      * @access    public
  192.      * @param    string
  193.      * @return    void
  194.      */
  195.  
  196.     function html_mode($html = true)
  197.     {
  198.         $this->html_mode = $html;
  199.     }
  200.  
  201.     /**
  202.      * Should we include headers and footers?
  203.      *
  204.      * @access    public
  205.      * @param    string
  206.      * @return    void
  207.      */
  208.  
  209.     function wrap_mode($wrap = true)
  210.     {
  211.         $this->wrap_mode = $wrap;
  212.     }
  213.  
  214.  
  215.     /**
  216.      * Create navigations for a specific page
  217.      *
  218.      * @access    public
  219.      * @param    string
  220.      * @param    string
  221.      * @return    void
  222.      */
  223.  
  224.     function navigation($links = array())
  225.     {
  226.         $this->_navigation = $this->_navigation + $links;
  227.     }
  228.  
  229.  
  230.     /**
  231.      * Helps build custom breadcrumb trails
  232.      *
  233.      * @access    public
  234.      * @param    string
  235.      * @param    string
  236.      * @return    void
  237.      */
  238.  
  239.     function add_breadcrumb($name, $url_ref = '')
  240.     {
  241.         $this->_breadcrumbs[] = array('name'=>$name, 'url_ref'=>$segment);
  242.     }
  243.  
  244.  
  245.     function _guess_title()
  246.     {
  247.         $this->CI->load->helper('inflector');
  248.  
  249.         // Obviously no title, lets get making one
  250.         $title_parts = array();
  251.  
  252.         // Is there a module?
  253.         if(!empty($this->_module))      $title_parts[] = strtolower($this->_module);
  254.         else                            $title_parts[] = strtolower($this->_controller);
  255.  
  256.         // If the method is something other than index, use that
  257.         if($this->_method != 'index' && $title_parts[0] != $this->_method)    $title_parts[] = $this->_method;
  258.  
  259.         $this->_page_title = humanize(implode(' | ', $title_parts));
  260.  
  261.         return $this->_page_title;
  262.     }
  263.  
  264.  
  265.     // Build the array into a string with anchors and ->'s
  266.     function _create_navigation()
  267.     {/*
  268.         $nav_parts = array();
  269.  
  270.         foreach($this->_navigation as $text => $link):
  271.  
  272.             // Support javascript links
  273.             if(strpos($link, 'javascript:') === 0):
  274.                 $nav_parts[] = '<a href="'.$link.'" title="'.$text.'">'.$text.'</a>';
  275.  
  276.             else:
  277.                 $nav_parts[] = anchor($link, $text);
  278.             endif;
  279.  
  280.         endforeach;
  281.  
  282.         return $nav_parts;
  283.     */}
  284.  
  285.  
  286.     // Build the array into a string with anchors and ->'s
  287.     function _create_breadcrumbs()
  288.     {
  289.         $this->CI->load->helper('inflector');
  290.  
  291.         // No crumbs (other than possibly the section crumb we just added)?
  292.         if(count($this->_breadcrumbs) <= 1):
  293.  
  294.                 $url_parts = array();
  295.                 $segment_array = $this->CI->uri->segment_array();
  296.                 $last_segment = array_pop($segment_array);
  297.                 foreach($segment_array as $url_ref):
  298.                        
  299.                         // Skip if we already have this breadcrumb and its not admin
  300.                         if(in_array($url_ref, $url_parts) or $url_ref == 'admin') continue;
  301.  
  302.                         $url_parts[] = $url_ref;
  303.                         $this->_breadcrumbs[] = array('name'=>humanize($url_ref), 'url_ref'=>implode('/', $url_parts), 'current_page'=>false);
  304.                 endforeach;
  305.                
  306.                 $url_parts[] = $last_segment;
  307.                 $this->_breadcrumbs[] = array('name'=>humanize($last_segment), 'url_ref'=>implode('/', $url_parts), 'current_page'=>true);
  308.  
  309.         endif;
  310.  
  311.         return $this->_breadcrumbs;
  312.     }
  313.  
  314. }
  315. // END Layout class
  316. ?>

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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me