[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/ -> class_templates.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  class templates
  13  {
  14      /**
  15       * The total number of templates.
  16       *
  17       * @var int
  18       */
  19      public $total = 0;
  20  
  21      /**
  22       * The template cache.
  23       *
  24       * @var array
  25       */
  26      public $cache = array();
  27  
  28      /**
  29       * Array of templates loaded that were not loaded via the cache
  30       *
  31       * @var array
  32       */
  33      public $uncached_templates = array();
  34  
  35      /**
  36       * Cache the templates.
  37       *
  38       * @param string A list of templates to cache.
  39       */
  40  	function cache($templates)
  41      {
  42          global $db, $theme;
  43          $sql = $sqladd = "";
  44          $names = explode(",", $templates);
  45          foreach($names as $key => $title)
  46          {
  47              $sql .= " ,'".trim($title)."'";
  48          }
  49  
  50          $query = $db->simple_select("templates", "title,template", "title IN (''$sql) AND sid IN ('-2','-1','".$theme['templateset']."')", array('order_by' => 'sid', 'order_dir' => 'asc'));
  51          while($template = $db->fetch_array($query))
  52          {
  53              $this->cache[$template['title']] = $template['template'];
  54          }
  55      }
  56  
  57      /**
  58       * Gets templates.
  59       *
  60       * @param string The title of the template to get.
  61       * @param boolean True if template contents must be escaped, false if not.
  62       * @param boolean True to output HTML comments, false to not output.
  63       * @return string The template HTML.
  64       */
  65  	function get($title, $eslashes=1, $htmlcomments=1)
  66      {
  67          global $db, $theme, $mybb;
  68  
  69          //
  70          // DEVELOPMENT MODE
  71          //
  72          if(isset($mybb->dev_mode) && $mybb->dev_mode == 1)
  73          {
  74              $template = $this->dev_get($title);
  75              if($template !== false)
  76              {
  77                  $this->cache[$title] = $template;
  78              }
  79          }
  80          
  81          if(!isset($this->cache[$title]))
  82          {
  83              $query = $db->simple_select("templates", "template", "title='".$db->escape_string($title)."' AND sid IN ('-2','-1','".$theme['templateset']."')", array('order_by' => 'sid', 'order_dir' => 'DESC', 'limit' => 1));
  84  
  85              $gettemplate = $db->fetch_array($query);
  86              if($mybb->debug_mode)
  87              {
  88                  $this->uncached_templates[$title] = $title;
  89              }
  90              
  91              if(!$gettemplate)
  92              {
  93                  $gettemplate['template'] = "";
  94              }
  95  
  96              $this->cache[$title] = $gettemplate['template'];
  97          }
  98          $template = $this->cache[$title];
  99  
 100          if($htmlcomments)
 101          {
 102              if($mybb->settings['tplhtmlcomments'] == 1)
 103              {
 104                  $template = "<!-- start: ".htmlspecialchars_uni($title)." -->\n{$template}\n<!-- end: ".htmlspecialchars_uni($title)." -->";
 105              }
 106              else
 107              {
 108                  $template = "\n{$template}\n";
 109              }
 110          }
 111          
 112          if($eslashes)
 113          {
 114              $template = str_replace("\\'", "'", addslashes($template));
 115          }
 116          return $template;
 117      }
 118  
 119      /**
 120       * Fetch a template directly from the install/resources/mybb_theme.xml directory if it exists (DEVELOPMENT MODE)
 121       */
 122  	function dev_get($title)
 123      {
 124          static $template_xml;
 125  
 126          if(!$template_xml)
 127          {
 128              if(@file_exists(MYBB_ROOT."install/resources/mybb_theme.xml"))
 129              {
 130                  $template_xml = simplexml_load_file(MYBB_ROOT."install/resources/mybb_theme.xml");
 131              }
 132              else
 133              {
 134                  return false;
 135              }
 136          }
 137          $res = $template_xml->xpath("//template[@name='{$title}']");
 138          return $res[0];
 139      }
 140  }
 141  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1