[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 class templates 12 { 13 /** 14 * The total number of templates. 15 * 16 * @var int 17 */ 18 public $total = 0; 19 20 /** 21 * The template cache. 22 * 23 * @var array 24 */ 25 public $cache = array(); 26 27 /** 28 * Array of templates loaded that were not loaded via the cache 29 * 30 * @var array 31 */ 32 public $uncached_templates = array(); 33 34 /** 35 * Cache the templates. 36 * 37 * @param string $templates A list of templates to cache. 38 */ 39 function cache($templates) 40 { 41 global $db, $theme; 42 $sql = $sqladd = ""; 43 $names = explode(",", $templates); 44 foreach($names as $key => $title) 45 { 46 $sql .= " ,'".trim($title)."'"; 47 } 48 49 $query = $db->simple_select("templates", "title,template", "title IN (''$sql) AND sid IN ('-2','-1','".(int)$theme['templateset']."')", array('order_by' => 'sid', 'order_dir' => 'asc')); 50 while($template = $db->fetch_array($query)) 51 { 52 $this->cache[$template['title']] = $template['template']; 53 } 54 } 55 56 /** 57 * Gets templates. 58 * 59 * @param string $title The title of the template to get. 60 * @param boolean|int $eslashes True if template contents must be escaped, false if not. 61 * @param boolean|int $htmlcomments True to output HTML comments, false to not output. 62 * @return string The template HTML. 63 */ 64 function get($title, $eslashes=1, $htmlcomments=1) 65 { 66 global $db, $theme, $mybb; 67 68 // 69 // DEVELOPMENT MODE 70 // 71 if($mybb->dev_mode == 1) 72 { 73 $template = $this->dev_get($title); 74 if($template !== false) 75 { 76 $this->cache[$title] = $template; 77 } 78 } 79 80 if(!isset($this->cache[$title])) 81 { 82 // Only load master and global templates if template is needed in Admin CP 83 if(empty($theme['templateset'])) 84 { 85 $query = $db->simple_select("templates", "template", "title='".$db->escape_string($title)."' AND sid IN ('-2','-1')", array('order_by' => 'sid', 'order_dir' => 'DESC', 'limit' => 1)); 86 } 87 else 88 { 89 $query = $db->simple_select("templates", "template", "title='".$db->escape_string($title)."' AND sid IN ('-2','-1','".(int)$theme['templateset']."')", array('order_by' => 'sid', 'order_dir' => 'DESC', 'limit' => 1)); 90 } 91 92 $gettemplate = $db->fetch_array($query); 93 if($mybb->debug_mode) 94 { 95 $this->uncached_templates[$title] = $title; 96 } 97 98 if(empty($gettemplate)) 99 { 100 $gettemplate = array('template' => ''); 101 } 102 103 $this->cache[$title] = $gettemplate['template']; 104 } 105 $template = $this->cache[$title]; 106 107 if($htmlcomments && $template !== false) 108 { 109 if($mybb->settings['tplhtmlcomments'] == 1) 110 { 111 $template = "<!-- start: ".htmlspecialchars_uni($title)." -->\n{$template}\n<!-- end: ".htmlspecialchars_uni($title)." -->"; 112 } 113 else 114 { 115 $template = "\n{$template}\n"; 116 } 117 } 118 119 if($eslashes) 120 { 121 $template = str_replace("\\'", "'", addslashes($template)); 122 } 123 return $template; 124 } 125 126 /** 127 * Prepare a template for rendering to a variable. 128 * 129 * @param string $template The name of the template to get. 130 * @param boolean $eslashes True if template contents must be escaped, false if not. 131 * @param boolean $htmlcomments True to output HTML comments, false to not output. 132 * @return string The eval()-ready PHP code for rendering the template 133 */ 134 function render($template, $eslashes=true, $htmlcomments=true) 135 { 136 return 'return "'.$this->get($template, $eslashes, $htmlcomments).'";'; 137 } 138 139 /** 140 * Fetch a template directly from the install/resources/mybb_theme.xml directory if it exists (DEVELOPMENT MODE) 141 * 142 * @param string $title 143 * @return string|bool 144 */ 145 function dev_get($title) 146 { 147 static $template_xml; 148 149 if(!$template_xml) 150 { 151 if(@file_exists(MYBB_ROOT."install/resources/mybb_theme.xml")) 152 { 153 $template_xml = simplexml_load_file(MYBB_ROOT."install/resources/mybb_theme.xml"); 154 } 155 else 156 { 157 return false; 158 } 159 } 160 $res = $template_xml->xpath("//template[@name='{$title}']"); 161 return $res[0]; 162 } 163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |