[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 3 /* 4 + ----------------------------------------------------------------------------+ 5 | e107 website system 6 | 7 | ©Steve Dunstan 2001-2002 8 | http://e107.org 9 | jalist@e107.org 10 | 11 | Released under the terms and conditions of the 12 | GNU General Public License (http://gnu.org). 13 | 14 | $Source: /cvsroot/e107/e107_0.7/e107_handlers/shortcode_handler.php,v $ 15 | $Revision: 1.41 $ 16 | $Date: 2006/12/05 10:51:32 $ 17 | $Author: mrpete $ 18 +----------------------------------------------------------------------------+ 19 */ 20 21 if (!defined('e107_INIT')) { exit; } 22 23 if (!isset($tp) || !is_object($tp -> e_sc)) { 24 $tp->e_sc = new e_shortcode; 25 } 26 27 class e_shortcode { 28 var $scList; 29 var $parseSCFiles; 30 var $addedCodes; 31 var $registered_codes; 32 33 function e_shortcode() 34 { 35 global $pref, $register_sc; 36 37 if(varset($pref['shortcode_list'],'') != '') 38 { 39 foreach($pref['shortcode_list'] as $path=>$namearray) 40 { 41 foreach($namearray as $code=>$uclass) 42 { 43 $code = strtoupper($code); 44 $this->registered_codes[$code]['type'] = 'plugin'; 45 $this->registered_codes[$code]['path'] = $path; 46 // $this->registered_codes[$code]['perms'] = $uclass; 47 } 48 } 49 } 50 51 if(isset($register_sc) && is_array($register_sc)) 52 { 53 foreach($register_sc as $code) 54 { 55 $this->registered_codes[$code]['type'] = 'theme'; 56 } 57 } 58 } 59 60 function parseCodes($text, $useSCFiles = TRUE, $extraCodes = '') { 61 $this->parseSCFiles = $useSCFiles; 62 $ret = ''; 63 if (is_array($extraCodes)) { 64 foreach($extraCodes as $sc => $code) { 65 $this->scList[$sc] = $code; 66 } 67 } 68 $tmp = explode("\n", $text); 69 foreach($tmp as $line) { 70 if (preg_match("/{.+?}/", $line, $match)) { 71 $ret .= preg_replace_callback("#\{(\S[^\x02]*?\S)\}#", array($this, 'doCode'), $line); 72 } else { 73 $ret .= $line; 74 } 75 } 76 return $ret; 77 } 78 79 function doCode($matches) 80 { 81 global $pref, $e107cache, $menu_pref, $sc_style, $parm, $sql; 82 83 if(strpos($matches[1], E_NL) !== false) 84 { 85 return $matches[0]; 86 } 87 88 if (strpos($matches[1], '=')) 89 { 90 list($code, $parm) = explode("=", $matches[1], 2); 91 } 92 else 93 { 94 $code = $matches[1]; 95 $parm = ''; 96 } 97 $parm = trim($parm); 98 99 if (E107_DBG_BBSC) 100 { 101 global $db_debug; 102 $sql->db_Mark_Time("SC $code"); 103 $db_debug->logCode(2, $code, $parm, ""); 104 } 105 106 if (is_array($this->scList) && array_key_exists($code, $this->scList)) 107 { 108 $shortcode = $this->scList[$code]; 109 } 110 else 111 { 112 if ($this->parseSCFiles == TRUE) 113 { 114 if (is_array($this -> registered_codes) && array_key_exists($code, $this->registered_codes)) 115 { 116 if($this->registered_codes[$code]['type'] == 'plugin') 117 { 118 $scFile = e_PLUGIN.strtolower($this->registered_codes[$code]['path']).'/'.strtolower($code).'.sc'; 119 } 120 else 121 { 122 $scFile = THEME.strtolower($code).'.sc'; 123 } 124 } 125 else 126 { 127 $scFile = e_FILE."shortcode/".strtolower($code).".sc"; 128 } 129 if (file_exists($scFile)) { 130 $shortcode = file_get_contents($scFile); 131 $this->scList[$code] = $shortcode; 132 } 133 } 134 } 135 136 if(E107_DBG_SC){ 137 echo " sc= ".str_replace(e_FILE."shortcode/","",$scFile)."<br />"; 138 } 139 140 if(E107_DBG_BBSC) 141 { 142 trigger_error("starting shortcode {".$code."}", E_USER_ERROR); 143 } 144 $ret = (isset($shortcode) ? eval($shortcode) : ""); 145 146 if($ret != '' || is_numeric($ret)) 147 { 148 if(isset($sc_style) && is_array($sc_style) && array_key_exists($code,$sc_style)) 149 { 150 if(isset($sc_style[$code]['pre'])) 151 { 152 $ret = $sc_style[$code]['pre'].$ret; 153 } 154 if(isset($sc_style[$code]['post'])) 155 { 156 $ret = $ret.$sc_style[$code]['post']; 157 } 158 } 159 } 160 if (E107_DBG_SC) { 161 $sql->db_Mark_Time("(SC $code Done)"); 162 } 163 return $ret; 164 } 165 166 function parse_scbatch($fname, $type = 'file') { 167 $ret = array(); 168 if($type == 'file') 169 { 170 $sc_batch = file($fname); 171 } 172 else 173 { 174 $sc_batch = $fname; 175 } 176 $cur_sc = ''; 177 foreach($sc_batch as $line) { 178 if (trim($line) == 'SC_END') { 179 $cur_sc = ''; 180 } 181 if ($cur_sc && !$override) { 182 $ret[$cur_sc] .= $line; 183 } 184 if (preg_match("#^SC_BEGIN (\w*).*#", $line, $matches)) { 185 $cur_sc = $matches[1]; 186 $ret[$cur_sc]=''; 187 if (is_array($this -> registered_codes) && array_key_exists($cur_sc, $this -> registered_codes)) { 188 if ($this -> registered_codes[$cur_sc]['type'] == 'plugin') { 189 $scFile = e_PLUGIN.strtolower($this -> registered_codes[$cur_sc]['path']).'/'.strtolower($cur_sc).'.sc'; 190 } else { 191 $scFile = THEME.strtolower($cur_sc).'.sc'; 192 } 193 if (is_readable($scFile)) { 194 $ret[$cur_sc] = file_get_contents($scFile); 195 } 196 $override = TRUE; 197 } else { 198 $override = FALSE; 199 } 200 } 201 } 202 return $ret; 203 } 204 } 205 206 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |