[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
---|
| 13 | |
---|
| 14 | class context |
---|
| 15 | { |
---|
| 16 | public $stack = array(); |
---|
[2566] | 17 | |
---|
[0] | 18 | public function __set($name,$var) |
---|
| 19 | { |
---|
| 20 | if ($var === null) { |
---|
| 21 | $this->pop($name); |
---|
| 22 | } else { |
---|
| 23 | $this->stack[$name][] =& $var; |
---|
| 24 | if ($var instanceof record) { |
---|
| 25 | $this->stack['cur_loop'][] =& $var; |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | } |
---|
[2566] | 29 | |
---|
[0] | 30 | public function __get($name) |
---|
| 31 | { |
---|
| 32 | if (!isset($this->stack[$name])) { |
---|
| 33 | return null; |
---|
| 34 | } |
---|
[2566] | 35 | |
---|
[0] | 36 | $n = count($this->stack[$name]); |
---|
| 37 | if ($n > 0) { |
---|
| 38 | return $this->stack[$name][($n-1)]; |
---|
| 39 | } |
---|
[2566] | 40 | |
---|
[0] | 41 | return null; |
---|
| 42 | } |
---|
[2566] | 43 | |
---|
[0] | 44 | public function exists($name) |
---|
| 45 | { |
---|
| 46 | return isset($this->stack[$name][0]); |
---|
| 47 | } |
---|
[2566] | 48 | |
---|
[0] | 49 | public function pop($name) |
---|
| 50 | { |
---|
| 51 | if (isset($this->stack[$name])) { |
---|
| 52 | $v = array_pop($this->stack[$name]); |
---|
| 53 | if ($v instanceof record) { |
---|
| 54 | array_pop($this->stack['cur_loop']); |
---|
| 55 | } |
---|
| 56 | unset($v); |
---|
| 57 | } |
---|
| 58 | } |
---|
[2566] | 59 | |
---|
[0] | 60 | # Loop position tests |
---|
[2774] | 61 | public function loopPosition($start,$length=null,$even=null,$modulo=null) |
---|
[0] | 62 | { |
---|
| 63 | if (!$this->cur_loop) { |
---|
| 64 | return false; |
---|
| 65 | } |
---|
[2566] | 66 | |
---|
[0] | 67 | $index = $this->cur_loop->index(); |
---|
| 68 | $size = $this->cur_loop->count(); |
---|
[2566] | 69 | |
---|
[0] | 70 | $test = false; |
---|
| 71 | if ($start >= 0) |
---|
| 72 | { |
---|
| 73 | $test = $index >= $start; |
---|
| 74 | if ($length !== null) { |
---|
| 75 | if ($length >= 0) { |
---|
| 76 | $test = $test && $index < $start + $length; |
---|
| 77 | } else { |
---|
| 78 | $test = $test && $index < $size + $length; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
| 84 | $test = $index >= $size + $start; |
---|
| 85 | if ($length !== null) { |
---|
| 86 | if ($length >= 0) { |
---|
| 87 | $test = $test && $index < $size + $start + $length; |
---|
| 88 | } else { |
---|
| 89 | $test = $test && $index < $size + $length; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
[2566] | 93 | |
---|
[0] | 94 | if ($even !== null) { |
---|
| 95 | $test = $test && $index%2 == $even; |
---|
| 96 | } |
---|
[2566] | 97 | |
---|
[2774] | 98 | if ($modulo !== null) { |
---|
| 99 | $test = $test && ($index % $modulo == 0); |
---|
| 100 | } |
---|
| 101 | |
---|
[0] | 102 | return $test; |
---|
| 103 | } |
---|
[2566] | 104 | |
---|
[2802] | 105 | # Static methods |
---|
| 106 | public static function global_filter($str, |
---|
| 107 | $encode_xml, $remove_html, $cut_string, $lower_case, $upper_case ,$encode_url ,$tag='') |
---|
| 108 | { |
---|
| 109 | $args = func_get_args(); |
---|
| 110 | array_pop($args); |
---|
| 111 | $args[0] =& $str; |
---|
[2566] | 112 | |
---|
[2802] | 113 | # --BEHAVIOR-- publicBeforeContentFilter |
---|
| 114 | $res = $GLOBALS['core']->callBehavior('publicBeforeContentFilter',$GLOBALS['core'],$tag,$args); |
---|
[2566] | 115 | |
---|
[2802] | 116 | if ($remove_html) { |
---|
| 117 | $str = self::remove_html($str); |
---|
| 118 | $str = preg_replace('/\s+/',' ',$str); |
---|
| 119 | } |
---|
[2566] | 120 | |
---|
[2802] | 121 | if ($encode_xml) { |
---|
| 122 | $str = self::encode_xml($str); |
---|
| 123 | } |
---|
[2566] | 124 | |
---|
[2802] | 125 | if ($cut_string) { |
---|
| 126 | $str = self::cut_string($str,(integer) $cut_string); |
---|
| 127 | } |
---|
[2566] | 128 | |
---|
[2802] | 129 | if ($lower_case) { |
---|
| 130 | $str = self::lower_case($str); |
---|
| 131 | } elseif ($upper_case) { |
---|
| 132 | if ($upper_case == 2) { |
---|
| 133 | $str = self::capitalize($str); |
---|
| 134 | } else { |
---|
| 135 | $str = self::upper_case($str); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | if ($encode_url) { |
---|
| 139 | $str = self::encode_url($str); |
---|
| 140 | } |
---|
[2566] | 141 | |
---|
[2802] | 142 | # --BEHAVIOR-- publicAfterContentFilter |
---|
| 143 | $res = $GLOBALS['core']->callBehavior('publicAfterContentFilter',$GLOBALS['core'],$tag,$args); |
---|
[2566] | 144 | |
---|
[2802] | 145 | return $str; |
---|
| 146 | } |
---|
[2566] | 147 | |
---|
[2802] | 148 | public static function encode_url($str) |
---|
| 149 | { |
---|
| 150 | return urlencode($str); |
---|
| 151 | } |
---|
[2566] | 152 | |
---|
[0] | 153 | public static function cut_string($str,$l) |
---|
| 154 | { |
---|
| 155 | return text::cutString($str,$l); |
---|
| 156 | } |
---|
[2566] | 157 | |
---|
[0] | 158 | public static function encode_xml($str) |
---|
| 159 | { |
---|
| 160 | return html::escapeHTML($str); |
---|
| 161 | } |
---|
[2566] | 162 | |
---|
[0] | 163 | public static function remove_html($str) |
---|
| 164 | { |
---|
| 165 | return html::decodeEntities(html::clean($str)); |
---|
| 166 | } |
---|
[2566] | 167 | |
---|
[0] | 168 | public static function lower_case($str) |
---|
| 169 | { |
---|
| 170 | return mb_strtolower($str); |
---|
| 171 | } |
---|
[2566] | 172 | |
---|
[0] | 173 | public static function upper_case($str) |
---|
| 174 | { |
---|
| 175 | return mb_strtoupper($str); |
---|
| 176 | } |
---|
[930] | 177 | |
---|
| 178 | public static function capitalize($str) |
---|
| 179 | { |
---|
| 180 | if ($str != '') { |
---|
| 181 | $str[0] = mb_strtoupper($str[0]); |
---|
| 182 | } |
---|
| 183 | return $str; |
---|
| 184 | } |
---|
[2566] | 185 | |
---|
[0] | 186 | public static function categoryPostParam(&$p) |
---|
| 187 | { |
---|
| 188 | $not = substr($p['cat_url'],0,1) == '!'; |
---|
| 189 | if ($not) { |
---|
| 190 | $p['cat_url'] = substr($p['cat_url'],1); |
---|
| 191 | } |
---|
[2566] | 192 | |
---|
[0] | 193 | $p['cat_url'] = preg_split('/\s*,\s*/',$p['cat_url'],-1,PREG_SPLIT_NO_EMPTY); |
---|
[2566] | 194 | |
---|
[0] | 195 | foreach ($p['cat_url'] as &$v) |
---|
| 196 | { |
---|
| 197 | if ($not) { |
---|
| 198 | $v .= ' ?not'; |
---|
| 199 | } |
---|
| 200 | if ($GLOBALS['_ctx']->exists('categories') && preg_match('/#self/',$v)) { |
---|
| 201 | $v = preg_replace('/#self/',$GLOBALS['_ctx']->categories->cat_url,$v); |
---|
| 202 | } elseif ($GLOBALS['_ctx']->exists('posts') && preg_match('/#self/',$v)) { |
---|
| 203 | $v = preg_replace('/#self/',$GLOBALS['_ctx']->posts->cat_url,$v); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | } |
---|
[2566] | 207 | |
---|
[0] | 208 | # Static methods for pagination |
---|
| 209 | public static function PaginationNbPages() |
---|
| 210 | { |
---|
| 211 | global $_ctx; |
---|
[2566] | 212 | |
---|
[0] | 213 | if ($_ctx->pagination === null) { |
---|
| 214 | return false; |
---|
| 215 | } |
---|
[2566] | 216 | |
---|
[0] | 217 | $nb_posts = $_ctx->pagination->f(0); |
---|
[2863] | 218 | if (($GLOBALS['core']->url->type == 'default') || ($GLOBALS['core']->url->type == 'default-page')) { |
---|
| 219 | $nb_pages = ceil(($nb_posts - $_ctx->nb_entry_first_page) / $_ctx->nb_entry_per_page + 1); |
---|
| 220 | } else { |
---|
| 221 | $nb_pages = ceil($nb_posts / $_ctx->nb_entry_per_page); |
---|
| 222 | } |
---|
[2566] | 223 | |
---|
[0] | 224 | return $nb_pages; |
---|
| 225 | } |
---|
[2566] | 226 | |
---|
[0] | 227 | public static function PaginationPosition($offset=0) |
---|
| 228 | { |
---|
| 229 | if (isset($GLOBALS['_page_number'])) { |
---|
| 230 | $p = $GLOBALS['_page_number']; |
---|
| 231 | } else { |
---|
| 232 | $p = 1; |
---|
| 233 | } |
---|
[2566] | 234 | |
---|
[0] | 235 | $p = $p+$offset; |
---|
[2566] | 236 | |
---|
[0] | 237 | $n = self::PaginationNbPages(); |
---|
| 238 | if (!$n) { |
---|
| 239 | return $p; |
---|
| 240 | } |
---|
[2566] | 241 | |
---|
[0] | 242 | if ($p > $n || $p <= 0) { |
---|
| 243 | return 1; |
---|
| 244 | } else { |
---|
| 245 | return $p; |
---|
| 246 | } |
---|
| 247 | } |
---|
[2566] | 248 | |
---|
[0] | 249 | public static function PaginationStart() |
---|
| 250 | { |
---|
| 251 | if (isset($GLOBALS['_page_number'])) { |
---|
| 252 | return self::PaginationPosition() == 1; |
---|
| 253 | } |
---|
[2566] | 254 | |
---|
[0] | 255 | return true; |
---|
| 256 | } |
---|
[2566] | 257 | |
---|
[0] | 258 | public static function PaginationEnd() |
---|
| 259 | { |
---|
| 260 | if (isset($GLOBALS['_page_number'])) { |
---|
| 261 | return self::PaginationPosition() == self::PaginationNbPages(); |
---|
| 262 | } |
---|
[2566] | 263 | |
---|
[0] | 264 | return false; |
---|
| 265 | } |
---|
[2566] | 266 | |
---|
[0] | 267 | public static function PaginationURL($offset=0) |
---|
| 268 | { |
---|
| 269 | $args = $_SERVER['URL_REQUEST_PART']; |
---|
[2566] | 270 | |
---|
[0] | 271 | $n = self::PaginationPosition($offset); |
---|
[2566] | 272 | |
---|
[0] | 273 | $args = preg_replace('#(^|/)page/([0-9]+)$#','',$args); |
---|
[2566] | 274 | |
---|
[0] | 275 | $url = $GLOBALS['core']->blog->url.$args; |
---|
[2566] | 276 | |
---|
[0] | 277 | if ($n > 1) { |
---|
| 278 | $url = preg_replace('#/$#','',$url); |
---|
| 279 | $url .= '/page/'.$n; |
---|
| 280 | } |
---|
[2566] | 281 | |
---|
[0] | 282 | # If search param |
---|
| 283 | if (!empty($_GET['q'])) { |
---|
| 284 | $s = strpos($url,'?') !== false ? '&' : '?'; |
---|
| 285 | $url .= $s.'q='.rawurlencode($_GET['q']); |
---|
| 286 | } |
---|
| 287 | return $url; |
---|
| 288 | } |
---|
[2566] | 289 | |
---|
[0] | 290 | # Robots policy |
---|
| 291 | public static function robotsPolicy($base,$over) |
---|
| 292 | { |
---|
| 293 | $pol = array('INDEX' => 'INDEX','FOLLOW' => 'FOLLOW', 'ARCHIVE' => 'ARCHIVE'); |
---|
| 294 | $base = array_flip(preg_split('/\s*,\s*/',$base)); |
---|
| 295 | $over = array_flip(preg_split('/\s*,\s*/',$over)); |
---|
[2566] | 296 | |
---|
[0] | 297 | foreach ($pol as $k => &$v) |
---|
| 298 | { |
---|
| 299 | if (isset($base[$k]) || isset($base['NO'.$k])) { |
---|
| 300 | $v = isset($base['NO'.$k]) ? 'NO'.$k : $k; |
---|
| 301 | } |
---|
| 302 | if (isset($over[$k]) || isset($over['NO'.$k])) { |
---|
| 303 | $v = isset($over['NO'.$k]) ? 'NO'.$k : $k; |
---|
| 304 | } |
---|
| 305 | } |
---|
[2566] | 306 | |
---|
[0] | 307 | if ($pol['ARCHIVE'] == 'ARCHIVE') { |
---|
| 308 | unset($pol['ARCHIVE']); |
---|
| 309 | } |
---|
[2566] | 310 | |
---|
[0] | 311 | return implode(', ',$pol); |
---|
| 312 | } |
---|
[2566] | 313 | |
---|
[0] | 314 | # Smilies static methods |
---|
| 315 | public static function getSmilies($blog) |
---|
| 316 | { |
---|
| 317 | $path = array(); |
---|
| 318 | if (isset($GLOBALS['__theme'])) { |
---|
| 319 | $path[] = $GLOBALS['__theme']; |
---|
[2676] | 320 | if (isset($GLOBALS['__parent_theme'])) { |
---|
| 321 | $path[] = $GLOBALS['__parent_theme']; |
---|
| 322 | } |
---|
[0] | 323 | } |
---|
| 324 | $path[] = 'default'; |
---|
| 325 | $definition = $blog->themes_path.'/%s/smilies/smilies.txt'; |
---|
| 326 | $base_url = $blog->settings->system->themes_url.'/%s/smilies/'; |
---|
[2566] | 327 | |
---|
[0] | 328 | $res = array(); |
---|
[2566] | 329 | |
---|
[0] | 330 | foreach ($path as $t) |
---|
| 331 | { |
---|
| 332 | if (file_exists(sprintf($definition,$t))) { |
---|
| 333 | $base_url = sprintf($base_url,$t); |
---|
| 334 | return self::smiliesDefinition(sprintf($definition,$t),$base_url); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | return false; |
---|
| 338 | } |
---|
[2566] | 339 | |
---|
[0] | 340 | public static function smiliesDefinition($f,$url) |
---|
| 341 | { |
---|
| 342 | $def = file($f); |
---|
[2566] | 343 | |
---|
[0] | 344 | $res = array(); |
---|
| 345 | foreach($def as $v) |
---|
| 346 | { |
---|
| 347 | $v = trim($v); |
---|
| 348 | if (preg_match('|^([^\t]*)[\t]+(.*)$|',$v,$matches)) |
---|
| 349 | { |
---|
| 350 | $r = '/(\A|[\s]+|>)('.preg_quote($matches[1],'/').')([\s]+|[<]|\Z)/ms'; |
---|
| 351 | $s = '$1<img src="'.$url.$matches[2].'" '. |
---|
| 352 | 'alt="$2" class="smiley" />$3'; |
---|
| 353 | $res[$r] = $s; |
---|
| 354 | } |
---|
| 355 | } |
---|
[2566] | 356 | |
---|
[0] | 357 | return $res; |
---|
| 358 | } |
---|
[2566] | 359 | |
---|
[0] | 360 | public static function addSmilies($str) |
---|
| 361 | { |
---|
| 362 | if (!isset($GLOBALS['__smilies']) || !is_array($GLOBALS['__smilies'])) { |
---|
| 363 | return $str; |
---|
| 364 | } |
---|
[975] | 365 | |
---|
| 366 | # Process part adapted from SmartyPants engine (J. Gruber et al.) : |
---|
| 367 | |
---|
| 368 | $tokens = self::tokenizeHTML($str); |
---|
| 369 | $result = ''; |
---|
| 370 | $in_pre = 0; # Keep track of when we're inside <pre> or <code> tags. |
---|
| 371 | |
---|
| 372 | foreach ($tokens as $cur_token) { |
---|
| 373 | if ($cur_token[0] == "tag") { |
---|
| 374 | # Don't mess with quotes inside tags. |
---|
| 375 | $result .= $cur_token[1]; |
---|
| 376 | if (preg_match('@<(/?)(?:pre|code|kbd|script|math)[\s>]@', $cur_token[1], $matches)) { |
---|
| 377 | $in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1; |
---|
| 378 | } |
---|
| 379 | } else { |
---|
| 380 | $t = $cur_token[1]; |
---|
| 381 | if (!$in_pre) { |
---|
| 382 | $t = preg_replace(array_keys($GLOBALS['__smilies']),array_values($GLOBALS['__smilies']),$t); |
---|
| 383 | } |
---|
| 384 | $result .= $t; |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | return $result; |
---|
[0] | 389 | } |
---|
[937] | 390 | |
---|
[975] | 391 | private static function tokenizeHTML($str) |
---|
| 392 | { |
---|
| 393 | # Function from SmartyPants engine (J. Gruber et al.) |
---|
| 394 | # |
---|
| 395 | # Parameter: String containing HTML markup. |
---|
| 396 | # Returns: An array of the tokens comprising the input |
---|
| 397 | # string. Each token is either a tag (possibly with nested, |
---|
| 398 | # tags contained therein, such as <a href="<MTFoo>">, or a |
---|
| 399 | # run of text between tags. Each element of the array is a |
---|
| 400 | # two-element array; the first is either 'tag' or 'text'; |
---|
| 401 | # the second is the actual value. |
---|
| 402 | # |
---|
| 403 | # |
---|
[2566] | 404 | # Regular expression derived from the _tokenize() subroutine in |
---|
[975] | 405 | # Brad Choate's MTRegex plugin. |
---|
| 406 | # <http://www.bradchoate.com/past/mtregex.php> |
---|
| 407 | # |
---|
| 408 | $index = 0; |
---|
| 409 | $tokens = array(); |
---|
| 410 | |
---|
| 411 | $match = '(?s:<!(?:--.*?--\s*)+>)|'. # comment |
---|
| 412 | '(?s:<\?.*?\?>)|'. # processing instruction |
---|
| 413 | # regular tags |
---|
[2566] | 414 | '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; |
---|
[975] | 415 | |
---|
| 416 | $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE); |
---|
| 417 | |
---|
| 418 | foreach ($parts as $part) { |
---|
[2566] | 419 | if (++$index % 2 && $part != '') |
---|
[975] | 420 | $tokens[] = array('text', $part); |
---|
| 421 | else |
---|
| 422 | $tokens[] = array('tag', $part); |
---|
| 423 | } |
---|
| 424 | return $tokens; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | |
---|
[0] | 428 | # First post image helpers |
---|
[937] | 429 | public static function EntryFirstImageHelper($size,$with_category,$class="",$no_tag=false,$content_only=false,$cat_only=false) |
---|
[0] | 430 | { |
---|
[678] | 431 | global $core, $_ctx; |
---|
[2566] | 432 | |
---|
[1537] | 433 | try { |
---|
| 434 | $media = new dcMedia($core); |
---|
| 435 | $sizes = implode('|',array_keys($media->thumb_sizes)).'|o'; |
---|
| 436 | if (!preg_match('/^'.$sizes.'$/',$size)) { |
---|
| 437 | $size = 's'; |
---|
| 438 | } |
---|
| 439 | $p_url = $core->blog->settings->system->public_url; |
---|
| 440 | $p_site = preg_replace('#^(.+?//.+?)/(.*)$#','$1',$core->blog->url); |
---|
| 441 | $p_root = $core->blog->public_path; |
---|
[2566] | 442 | |
---|
[1537] | 443 | $pattern = '(?:'.preg_quote($p_site,'/').')?'.preg_quote($p_url,'/'); |
---|
| 444 | $pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|jpeg|gif|png))"[^>]+/msui',$pattern); |
---|
[2566] | 445 | |
---|
[1537] | 446 | $src = ''; |
---|
| 447 | $alt = ''; |
---|
[2566] | 448 | |
---|
[1537] | 449 | # We first look in post content |
---|
| 450 | if (!$cat_only && $_ctx->posts) |
---|
[0] | 451 | { |
---|
[1537] | 452 | $subject = ($content_only ? '' : $_ctx->posts->post_excerpt_xhtml).$_ctx->posts->post_content_xhtml; |
---|
| 453 | if (preg_match_all($pattern,$subject,$m) > 0) |
---|
| 454 | { |
---|
| 455 | foreach ($m[1] as $i => $img) { |
---|
| 456 | if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) { |
---|
[2566] | 457 | $dirname = str_replace('\\', '/', dirname($img)); |
---|
[1537] | 458 | $src = $p_url.($dirname != '/' ? $dirname : '').'/'.$src; |
---|
| 459 | if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) { |
---|
| 460 | $alt = $malt[1]; |
---|
| 461 | } |
---|
| 462 | break; |
---|
[0] | 463 | } |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | } |
---|
[2566] | 467 | |
---|
[1537] | 468 | # No src, look in category description if available |
---|
| 469 | if (!$src && $with_category && $_ctx->posts->cat_desc) |
---|
| 470 | { |
---|
| 471 | if (preg_match_all($pattern,$_ctx->posts->cat_desc,$m) > 0) |
---|
| 472 | { |
---|
| 473 | foreach ($m[1] as $i => $img) { |
---|
| 474 | if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) { |
---|
[2566] | 475 | $dirname = str_replace('\\', '/', dirname($img)); |
---|
[1537] | 476 | $src = $p_url.($dirname != '/' ? $dirname : '').'/'.$src; |
---|
| 477 | if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) { |
---|
| 478 | $alt = $malt[1]; |
---|
| 479 | } |
---|
| 480 | break; |
---|
[0] | 481 | } |
---|
| 482 | } |
---|
[1537] | 483 | }; |
---|
| 484 | } |
---|
[2566] | 485 | |
---|
[1537] | 486 | if ($src) { |
---|
| 487 | if ($no_tag) { |
---|
| 488 | return $src; |
---|
| 489 | } else { |
---|
| 490 | return '<img alt="'.$alt.'" src="'.$src.'" class="'.$class.'" />'; |
---|
[0] | 491 | } |
---|
[899] | 492 | } |
---|
[2566] | 493 | |
---|
[1537] | 494 | } catch (Exception $e) { |
---|
| 495 | $core->error->add($e->getMessage()); |
---|
[0] | 496 | } |
---|
| 497 | } |
---|
[2566] | 498 | |
---|
[0] | 499 | private static function ContentFirstImageLookup($root,$img,$size) |
---|
| 500 | { |
---|
[678] | 501 | global $core; |
---|
[2566] | 502 | |
---|
[0] | 503 | # Get base name and extension |
---|
| 504 | $info = path::info($img); |
---|
| 505 | $base = $info['base']; |
---|
[2566] | 506 | |
---|
[1537] | 507 | try { |
---|
| 508 | $media = new dcMedia($core); |
---|
| 509 | $sizes = implode('|',array_keys($media->thumb_sizes)); |
---|
| 510 | if (preg_match('/^\.(.+)_('.$sizes.')$/',$base,$m)) { |
---|
| 511 | $base = $m[1]; |
---|
[0] | 512 | } |
---|
[2566] | 513 | |
---|
[1537] | 514 | $res = false; |
---|
| 515 | if ($size != 'o' && file_exists($root.'/'.$info['dirname'].'/.'.$base.'_'.$size.'.jpg')) |
---|
| 516 | { |
---|
| 517 | $res = '.'.$base.'_'.$size.'.jpg'; |
---|
| 518 | } |
---|
[2639] | 519 | elseif ($size != 'o' && file_exists($root.'/'.$info['dirname'].'/.'.$base.'_'.$size.'.png')) |
---|
| 520 | { |
---|
| 521 | $res = '.'.$base.'_'.$size.'.png'; |
---|
| 522 | } |
---|
[1537] | 523 | else |
---|
| 524 | { |
---|
| 525 | $f = $root.'/'.$info['dirname'].'/'.$base; |
---|
| 526 | if (file_exists($f.'.'.$info['extension'])) { |
---|
| 527 | $res = $base.'.'.$info['extension']; |
---|
| 528 | } elseif (file_exists($f.'.jpg')) { |
---|
| 529 | $res = $base.'.jpg'; |
---|
| 530 | } elseif (file_exists($f.'.jpeg')) { |
---|
| 531 | $res = $base.'.jpeg'; |
---|
| 532 | } elseif (file_exists($f.'.png')) { |
---|
| 533 | $res = $base.'.png'; |
---|
| 534 | } elseif (file_exists($f.'.gif')) { |
---|
| 535 | $res = $base.'.gif'; |
---|
| 536 | } elseif (file_exists($f.'.JPG')) { |
---|
| 537 | $res = $base.'.JPG'; |
---|
| 538 | } elseif (file_exists($f.'.JPEG')) { |
---|
| 539 | $res = $base.'.JPEG'; |
---|
| 540 | } elseif (file_exists($f.'.PNG')) { |
---|
| 541 | $res = $base.'.PNG'; |
---|
| 542 | } elseif (file_exists($f.'.GIF')) { |
---|
| 543 | $res = $base.'.GIF'; |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } catch (Exception $e) { |
---|
| 547 | $core->error->add($e->getMessage()); |
---|
[0] | 548 | } |
---|
[2566] | 549 | |
---|
[0] | 550 | if ($res) { |
---|
| 551 | return $res; |
---|
| 552 | } |
---|
| 553 | return false; |
---|
| 554 | } |
---|
| 555 | } |
---|