Changeset 2566:9bf417837888 for inc/public/lib.tpl.context.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/public/lib.tpl.context.php
r1537 r2566 15 15 { 16 16 public $stack = array(); 17 17 18 18 public function __set($name,$var) 19 19 { … … 27 27 } 28 28 } 29 29 30 30 public function __get($name) 31 31 { … … 33 33 return null; 34 34 } 35 35 36 36 $n = count($this->stack[$name]); 37 37 if ($n > 0) { 38 38 return $this->stack[$name][($n-1)]; 39 39 } 40 40 41 41 return null; 42 42 } 43 43 44 44 public function exists($name) 45 45 { 46 46 return isset($this->stack[$name][0]); 47 47 } 48 48 49 49 public function pop($name) 50 50 { … … 57 57 } 58 58 } 59 59 60 60 # Loop position tests 61 61 public function loopPosition($start,$length=null,$even=null) … … 64 64 return false; 65 65 } 66 66 67 67 $index = $this->cur_loop->index(); 68 68 $size = $this->cur_loop->count(); 69 69 70 70 $test = false; 71 71 if ($start >= 0) … … 91 91 } 92 92 } 93 93 94 94 if ($even !== null) { 95 95 $test = $test && $index%2 == $even; 96 96 } 97 97 98 98 return $test; 99 99 } 100 101 100 101 102 102 # Static methods 103 103 public static function global_filter($str, … … 107 107 array_pop($args); 108 108 $args[0] =& $str; 109 109 110 110 # --BEHAVIOR-- publicBeforeContentFilter 111 111 $res = $GLOBALS['core']->callBehavior('publicBeforeContentFilter',$GLOBALS['core'],$tag,$args); 112 112 113 113 if ($remove_html) { 114 114 $str = self::remove_html($str); 115 115 $str = preg_replace('/\s+/',' ',$str); 116 116 } 117 117 118 118 if ($encode_xml) { 119 119 $str = self::encode_xml($str); 120 120 } 121 121 122 122 if ($cut_string) { 123 123 $str = self::cut_string($str,(integer) $cut_string); 124 124 } 125 125 126 126 if ($lower_case) { 127 127 $str = self::lower_case($str); … … 133 133 } 134 134 } 135 135 136 136 # --BEHAVIOR-- publicAfterContentFilter 137 137 $res = $GLOBALS['core']->callBehavior('publicAfterContentFilter',$GLOBALS['core'],$tag,$args); 138 138 139 139 return $str; 140 140 } 141 142 141 142 143 143 public static function cut_string($str,$l) 144 144 { 145 145 return text::cutString($str,$l); 146 146 } 147 147 148 148 public static function encode_xml($str) 149 149 { 150 150 return html::escapeHTML($str); 151 151 } 152 152 153 153 public static function remove_html($str) 154 154 { 155 155 return html::decodeEntities(html::clean($str)); 156 156 } 157 157 158 158 public static function lower_case($str) 159 159 { 160 160 return mb_strtolower($str); 161 161 } 162 162 163 163 public static function upper_case($str) 164 164 { … … 173 173 return $str; 174 174 } 175 175 176 176 public static function categoryPostParam(&$p) 177 177 { … … 180 180 $p['cat_url'] = substr($p['cat_url'],1); 181 181 } 182 182 183 183 $p['cat_url'] = preg_split('/\s*,\s*/',$p['cat_url'],-1,PREG_SPLIT_NO_EMPTY); 184 184 185 185 foreach ($p['cat_url'] as &$v) 186 186 { … … 195 195 } 196 196 } 197 197 198 198 # Static methods for pagination 199 199 public static function PaginationNbPages() 200 200 { 201 201 global $_ctx; 202 202 203 203 if ($_ctx->pagination === null) { 204 204 return false; 205 205 } 206 206 207 207 $nb_posts = $_ctx->pagination->f(0); 208 208 $nb_per_page = $_ctx->post_params['limit'][1]; 209 209 210 210 $nb_pages = ceil($nb_posts/$nb_per_page); 211 211 212 212 return $nb_pages; 213 213 } 214 214 215 215 public static function PaginationPosition($offset=0) 216 216 { … … 220 220 $p = 1; 221 221 } 222 222 223 223 $p = $p+$offset; 224 224 225 225 $n = self::PaginationNbPages(); 226 226 if (!$n) { 227 227 return $p; 228 228 } 229 229 230 230 if ($p > $n || $p <= 0) { 231 231 return 1; … … 234 234 } 235 235 } 236 236 237 237 public static function PaginationStart() 238 238 { … … 240 240 return self::PaginationPosition() == 1; 241 241 } 242 242 243 243 return true; 244 244 } 245 245 246 246 public static function PaginationEnd() 247 247 { … … 249 249 return self::PaginationPosition() == self::PaginationNbPages(); 250 250 } 251 251 252 252 return false; 253 253 } 254 254 255 255 public static function PaginationURL($offset=0) 256 256 { 257 257 $args = $_SERVER['URL_REQUEST_PART']; 258 258 259 259 $n = self::PaginationPosition($offset); 260 260 261 261 $args = preg_replace('#(^|/)page/([0-9]+)$#','',$args); 262 262 263 263 $url = $GLOBALS['core']->blog->url.$args; 264 264 265 265 if ($n > 1) { 266 266 $url = preg_replace('#/$#','',$url); 267 267 $url .= '/page/'.$n; 268 268 } 269 269 270 270 # If search param 271 271 if (!empty($_GET['q'])) { … … 275 275 return $url; 276 276 } 277 277 278 278 # Robots policy 279 279 public static function robotsPolicy($base,$over) … … 282 282 $base = array_flip(preg_split('/\s*,\s*/',$base)); 283 283 $over = array_flip(preg_split('/\s*,\s*/',$over)); 284 284 285 285 foreach ($pol as $k => &$v) 286 286 { … … 292 292 } 293 293 } 294 294 295 295 if ($pol['ARCHIVE'] == 'ARCHIVE') { 296 296 unset($pol['ARCHIVE']); 297 297 } 298 298 299 299 return implode(', ',$pol); 300 300 } 301 301 302 302 # Smilies static methods 303 303 public static function getSmilies($blog) … … 310 310 $definition = $blog->themes_path.'/%s/smilies/smilies.txt'; 311 311 $base_url = $blog->settings->system->themes_url.'/%s/smilies/'; 312 312 313 313 $res = array(); 314 314 315 315 foreach ($path as $t) 316 316 { … … 322 322 return false; 323 323 } 324 324 325 325 public static function smiliesDefinition($f,$url) 326 326 { 327 327 $def = file($f); 328 328 329 329 $res = array(); 330 330 foreach($def as $v) … … 339 339 } 340 340 } 341 341 342 342 return $res; 343 343 } 344 344 345 345 public static function addSmilies($str) 346 346 { … … 387 387 # 388 388 # 389 # Regular expression derived from the _tokenize() subroutine in 389 # Regular expression derived from the _tokenize() subroutine in 390 390 # Brad Choate's MTRegex plugin. 391 391 # <http://www.bradchoate.com/past/mtregex.php> … … 397 397 '(?s:<\?.*?\?>)|'. # processing instruction 398 398 # regular tags 399 '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; 399 '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; 400 400 401 401 $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE); 402 402 403 403 foreach ($parts as $part) { 404 if (++$index % 2 && $part != '') 404 if (++$index % 2 && $part != '') 405 405 $tokens[] = array('text', $part); 406 406 else … … 415 415 { 416 416 global $core, $_ctx; 417 417 418 418 try { 419 419 $media = new dcMedia($core); … … 425 425 $p_site = preg_replace('#^(.+?//.+?)/(.*)$#','$1',$core->blog->url); 426 426 $p_root = $core->blog->public_path; 427 427 428 428 $pattern = '(?:'.preg_quote($p_site,'/').')?'.preg_quote($p_url,'/'); 429 429 $pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|jpeg|gif|png))"[^>]+/msui',$pattern); 430 430 431 431 $src = ''; 432 432 $alt = ''; 433 433 434 434 # We first look in post content 435 435 if (!$cat_only && $_ctx->posts) … … 440 440 foreach ($m[1] as $i => $img) { 441 441 if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) { 442 $dirname = str_replace('\\', '/', dirname($img)); 442 $dirname = str_replace('\\', '/', dirname($img)); 443 443 $src = $p_url.($dirname != '/' ? $dirname : '').'/'.$src; 444 444 if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) { … … 450 450 } 451 451 } 452 452 453 453 # No src, look in category description if available 454 454 if (!$src && $with_category && $_ctx->posts->cat_desc) … … 458 458 foreach ($m[1] as $i => $img) { 459 459 if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) { 460 $dirname = str_replace('\\', '/', dirname($img)); 460 $dirname = str_replace('\\', '/', dirname($img)); 461 461 $src = $p_url.($dirname != '/' ? $dirname : '').'/'.$src; 462 462 if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) { … … 468 468 }; 469 469 } 470 470 471 471 if ($src) { 472 472 if ($no_tag) { … … 476 476 } 477 477 } 478 478 479 479 } catch (Exception $e) { 480 480 $core->error->add($e->getMessage()); 481 481 } 482 482 } 483 483 484 484 private static function ContentFirstImageLookup($root,$img,$size) 485 485 { 486 486 global $core; 487 487 488 488 # Get base name and extension 489 489 $info = path::info($img); 490 490 $base = $info['base']; 491 491 492 492 try { 493 493 $media = new dcMedia($core); … … 496 496 $base = $m[1]; 497 497 } 498 498 499 499 $res = false; 500 500 if ($size != 'o' && file_exists($root.'/'.$info['dirname'].'/.'.$base.'_'.$size.'.jpg')) … … 528 528 $core->error->add($e->getMessage()); 529 529 } 530 530 531 531 if ($res) { 532 532 return $res; … … 535 535 } 536 536 } 537 ?>
Note: See TracChangeset
for help on using the changeset viewer.