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 Template Lib 09 on Sat 12 Jan 14:28
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 Template 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 Template {
  30.  
  31.         var $page_body = '';
  32.         var $directory = '';
  33.         var $module = '';
  34.  
  35.         var $title = '';
  36.         var $extra_head_content = '';
  37.  
  38.         var $navigation = array();
  39.         var $crumbs = array();
  40.  
  41.         // Default wrapper files
  42.         var $layout_file = 'layout.php';
  43.         var $sub_layout_file = '';
  44.  
  45.         var $folder_mode = 'modules';
  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 $error_messages = 0;
  53.        
  54.        
  55.         var $CI;
  56.         var $data = array();
  57.  
  58.         /**
  59.          * Constructor - Calls the CI instance and sets a debug message
  60.          *
  61.          * The constructor can be passed an array of config values
  62.          */
  63.         function Template()
  64.         {
  65.                 $this->CI =& get_instance();
  66.                 log_message('debug', "Template Class Initialized");
  67.  
  68.                
  69.                 if($this->folder_mode == 'modules'):
  70.                        
  71.                         // If the current module setting is empty, and there is a module loaded...
  72.                         if($this->module == '' && $this->CI->uri->router->fetch_module() != 'modules//'):
  73.                                 $this->modulestr_replace(array('modules/', '/'), '', $this->CI->uri->router->fetch_module());
  74.                         endif;
  75.                
  76.                 elseif($this->folder_mode == 'subdir'):
  77.                
  78.                         if($this->directory == '' && $this->CI->uri->router->fetch_directory() != '/'):
  79.                                 $this->directory =      str_replace('/', '', $this->CI->uri->router->fetch_directory());
  80.                         endif;
  81.                 endif;
  82.         }
  83.  
  84.         // --------------------------------------------------------------------
  85.  
  86.         /**
  87.          * Set the mode of the creation
  88.          *
  89.          * @access      public
  90.          * @param       string
  91.  
  92.          * @return      void
  93.          */
  94.         function create($page_body = '', $data = array('empty'), $return = false, $module = '')
  95.         {
  96.                 $this->CI =& get_instance();
  97.  
  98.                 $this->CI->load->library('defaults');
  99.                 $default_data = $this->CI->defaults->fetch();
  100.  
  101.                 if($page_body != '') $this->page_body = $page_body;
  102.                 if($module != '')        $this->module = $module;
  103.                
  104.                 // Merge all the data together
  105.                 $this->data = array_merge($data, $this->data, $default_data);
  106.  
  107.                 if(empty($this->title)) $this->_guess_title();
  108.  
  109.                 // Set the basic defaults
  110.                 $this->data['page_title']                       = $this->title;
  111.                 $this->data['navigation']                       = $this->_build_navigation();
  112.                 $this->data['crumbs']                           = $this->_build_crumbs();
  113.                 $this->data['extra_head_content']       = ($this->extra_head_content) ? $this->extra_head_content : '';
  114.  
  115.                 // If the page should include an error too, then parse the error box
  116.                 $this->data['error_box'] = (!empty($this->data['error_string'])) ? $this->CI->load->view('error_box', $this->data, true, $module) : '';
  117.  
  118.                 // If the page should include an info message too, then parse the info box
  119.                 $this->data['info_box'] = (!empty($this->data['info_string'])) ? $this->CI->load->view('info_box', $this->data, true, $module) : '';
  120.  
  121.                 // Disable sodding IE7's constant cacheing!!
  122.                 $this->CI->output->set_header("HTTP/1.0 200 OK");
  123.                 $this->CI->output->set_header("HTTP/1.1 200 OK");
  124.                 $this->CI->output->set_header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  125.                 $this->CI->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
  126.                 $this->CI->output->set_header("Cache-Control: post-check=0, pre-check=0, max-age=0");
  127.                 $this->CI->output->set_header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
  128.                 $this->CI->output->set_header("Pragma: no-cache");
  129.  
  130.                 // Let CI do the cacheing instead... if they want it!
  131.                 $this->CI->output->cache($this->cache_lifetime);
  132.  
  133.                 // Time to make the body, load view or parse HTML?
  134.                 if($this->html_mode):
  135.                         $this->data['page_content'] = $this->page_body;
  136.                
  137.                 else:
  138.                         // If directory is set, use it
  139.                         $view_file = (!empty($this->directory)) ? $this->directory.'/'.$this->page_body : $this->page_body;
  140.                         $this->data['page_content'] = $this->CI->load->view($view_file, $this->data, true, $this->module);
  141.                 endif;
  142.  
  143.  
  144.  
  145.                 // Want header and footer file included, or just the main file?
  146.                 if($this->wrap_mode):
  147.  
  148.                         // Using a sub-wrapper. Like an extra few divs round a page or a special set of blocks
  149.                         if(!empty($this->sub_layout_file)):
  150.                                 $this->data['sub_page_content'] = $this->data['page_content'];
  151.                                
  152.                                 // If directory is set, use it
  153.                                 $sub_layout = (!empty($this->directory)) ? $this->directory.'/'.$this->sub_layout_file : $this->sub_layout_file;
  154.                                 $this->data['page_content'] = $this->CI->load->view($sub_layout, $this->data, true, $this->sub_layout_module);
  155.                         endif;
  156.  
  157.                         // If directory is set, use it
  158.                         $layout_file = (!empty($this->directory)) ? $this->directory.'/'.$this->layout_file : $this->layout_file;
  159.                         $output = $this->CI->load->view($layout_file, $this->data, true);
  160.                 else:
  161.  
  162.                         $output = $this->data['page_content'];
  163.                 endif;
  164.  
  165.                 // Want it returned or output to browser?
  166.                 if($return):
  167.                         return $output;
  168.                 else:
  169.                         // Send it to output
  170.                         $this->CI->output->set_output($output);
  171.                 endif;
  172.  
  173.         }
  174.  
  175.         /**
  176.          * Allows for custom view segments to be loaded
  177.          *
  178.          * @access      public
  179.          * @param       string
  180.          * @param       string
  181.          * @return      void
  182.          */
  183.  
  184.         function sub_layout($filename, $sectionname = NULL)
  185.         {
  186.                 $this->sub_layout_file = $filename;
  187.                 $this->sub_layout_module = $sectionname;
  188.         }
  189.  
  190.         /**
  191.          * Set the title of the page
  192.          *
  193.          * @access      public
  194.          * @param       string
  195.          * @return      void
  196.          */
  197.  
  198.         function title($title = '')
  199.         {
  200.                 if($title != '') $this->title = $title;
  201.         }
  202.  
  203.         /**
  204.          * Put extra javascipt, css, meta tags, etc
  205.          *
  206.          * @access      public
  207.          * @param       string
  208.          * @return      void
  209.          */
  210.  
  211.         function extra_head($str = '')
  212.         {
  213.                 if(!empty($str)) $this->extra_head_content .= $str."\n";
  214.         }
  215.  
  216.         function directory($directory = '')
  217.         {
  218.                 if($directory != '') $this->directory = $directory;
  219.         }
  220.  
  221.         function module($module = '')
  222.         {
  223.                 if($module != '') $this->module = $module;
  224.         }
  225.  
  226.         /**
  227.          * Should we include headers and footers?
  228.          *
  229.          * @access      public
  230.          * @param       string
  231.          * @return      void
  232.          */
  233.  
  234.         function html_mode($html = true)
  235.         {
  236.                 $this->html_mode = $html;
  237.         }
  238.  
  239.         /**
  240.          * Should we include headers and footers?
  241.          *
  242.          * @access      public
  243.          * @param       string
  244.          * @return      void
  245.          */
  246.  
  247.         function wrap_mode($wrap = true)
  248.         {
  249.                 $this->wrap_mode = $wrap;
  250.         }
  251.  
  252.  
  253.         /**
  254.          * Create navigations for a specific page
  255.          *
  256.          * @access      public
  257.          * @param       string
  258.          * @param       string
  259.          * @return      void
  260.          */
  261.  
  262.         function navigation($links = array())
  263.         {
  264.                 $this->navigation = $this->navigation + $links;
  265.         }
  266.  
  267.  
  268.         /**
  269.          * Helps build custom breadcrumb trails
  270.          *
  271.          * @access      public
  272.          * @param       string
  273.          * @param       string
  274.          * @return      void
  275.          */
  276.  
  277.         function crumb($name, $segment = NULL)
  278.         {
  279.                 $this->crumbs[] = array($name, $segment);
  280.         }
  281.  
  282.  
  283.         /**
  284.          * Add an error message to the page
  285.          *
  286.          * @access      public
  287.          * @param       string
  288.          * @return      void
  289.          */
  290.         function error($error_string = '', $error_output = 'error_string')
  291.         {
  292.                 if(empty($error_string)) return false;
  293.  
  294.                 if(isset($this->data[$error_output])):
  295.                         $this->data[$error_output] .= $error_string."<br/>\n";
  296.                 else:
  297.                         $this->data[$error_output] = $error_string."<br/>\n";
  298.                 endif;
  299.  
  300.                 $this->error_messages++;
  301.         }
  302.  
  303.         /**
  304.          * Check if there is an error message
  305.          *
  306.          * @access      public
  307.          * @return      void
  308.          */
  309.         function have_errors()
  310.         {
  311.                 if($this->error_messages > 0) return true;
  312.                 else return false;
  313.         }
  314.  
  315.         /**
  316.          * Add an info message to the page
  317.          *
  318.          * @access      public
  319.          * @param       string
  320.          * @return      void
  321.          */
  322.         function info($info_string = '', $info_output = 'info_string')
  323.         {
  324.                 if(empty($info_string)) return false;
  325.  
  326.                 if(isset($this->data[$info_output])):
  327.                         $this->data[$info_output] .= $info_string."<br/>\n";
  328.                 else:
  329.                         $this->data[$info_output] = $info_string."<br/>\n";
  330.                 endif;
  331.         }
  332.  
  333.         function _guess_title()
  334.         {
  335.                 $this->CI =& get_instance();
  336.  
  337.                 $this->CI->load->helper('inflector');
  338.  
  339.                 // Obviously no title, lets get making one
  340.                 $title_parts = array();
  341.  
  342.                 if($this->folder_mode == 'modules'):
  343.                         $section                =       str_replace(array('modules/', '/'), '', $this->CI->uri->router->fetch_module());
  344.                 elseif($this->folder_mode == 'subdir'):
  345.                         $section                =       str_replace('/', '', $this->CI->uri->router->fetch_directory());
  346.                 endif;
  347.                
  348.                 $controller     =       $this->CI->uri->router->class;
  349.                 $method                 =       $this->CI->uri->router->method;
  350.  
  351.                 // Is there a module?
  352.                 if(!empty($directory))  $title_parts[] = $section;
  353.                 else                                    $title_parts[] = $controller;
  354.  
  355.                 // If the method isnt index, use that
  356.                 if($method != 'index')  $title_parts[] = $method;
  357.  
  358.                 $this->title = humanize(implode(' > ', $title_parts));
  359.  
  360.                 return $this->title;
  361.         }
  362.  
  363.  
  364.         // Build the array into a string with anchors and ->'s
  365.         function _build_navigation()
  366.         {
  367.                 $nav_parts = array();
  368.  
  369.                 foreach($this->navigation as $text => $link):
  370.                        
  371.                         // Support javascript links
  372.                         if(strpos($link, 'javascript:') === 0):
  373.                                 $nav_parts[] = '<a href="'.$link.'" title="'.$text.'">'.$text.'</a>';
  374.                        
  375.                         else:
  376.                                 $nav_parts[] = anchor($link, $text);
  377.                         endif;
  378.                        
  379.                 endforeach;
  380.  
  381.                 return $nav_parts;
  382.         }
  383.  
  384.  
  385.         // Build the array into a string with anchors and ->'s
  386.         function _build_crumbs()
  387.         {
  388.                 $this->CI =& get_instance();
  389.                 $this->CI->load->helper('inflector');
  390.                
  391.                 // First, we need the module name
  392.                 if($this->folder_mode == 'modules'):
  393.                         $section = str_replace(array('modules/', '/'), '', $this->CI->uri->router->fetch_module());
  394.        
  395.                 elseif($this->folder_mode == 'subdir'):
  396.                         $section =      str_replace('/', '', $this->CI->uri->router->fetch_directory());
  397.                 endif;
  398.                
  399.                 // Force it to the front
  400.                 $section_segment = array(humanize($section), $section);
  401.                 array_unshift($this->crumbs, $section_segment);
  402.                
  403.                 // No crumbs? Lets add some
  404.                 if(count($this->crumbs) == 1):
  405.                
  406.                         $controller = $this->CI->uri->router->class;
  407.                         $this->crumbs[] = array(humanize($controller), $this->crumbs[0][1].'/'.$controller);
  408.  
  409.                 endif;
  410.        
  411.  
  412.                 $crumb_parts = array();
  413.                 foreach($this->crumbs as $crumb):
  414.  
  415.                         if(!empty($crumb[1])):
  416.                                 $crumb_parts[] = anchor($crumb[1], $crumb[0]);
  417.                         else:
  418.                                 $crumb_parts[] = $crumb[0];
  419.                         endif;
  420.  
  421.                 endforeach;
  422.  
  423.                 $crumb_string = implode(' > ', $crumb_parts);
  424.  
  425.                 return $crumb_string;
  426.         }
  427.  
  428. }
  429. // END Template class
  430. ?>

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 so that I can delete my post