| 1 | <?php |
|---|
| 2 | # Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd. |
|---|
| 3 | # This program is distributed under the terms of the |
|---|
| 4 | # GNU General Public License, version 2. |
|---|
| 5 | # |
|---|
| 6 | # $Id$ |
|---|
| 7 | |
|---|
| 8 | function start_end_ts($ts) { |
|---|
| 9 | if ($ts) { |
|---|
| 10 | if (strlen($ts) == 4) { |
|---|
| 11 | $ts_start = $ts . '0101'; |
|---|
| 12 | $ts_end = $ts . '1231'; |
|---|
| 13 | } elseif (strlen($ts) == 6) { |
|---|
| 14 | $ts_start = $ts . '01'; |
|---|
| 15 | $ts_end = $ts . sprintf("%02d", days_in(substr($ts, 4, 2), substr($ts, 0, 4))); |
|---|
| 16 | } else { |
|---|
| 17 | $ts_start = $ts; |
|---|
| 18 | $ts_end = $ts; |
|---|
| 19 | } |
|---|
| 20 | } |
|---|
| 21 | return array($ts_start . '000000', $ts_end . '235959'); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | function start_end_month($ts) { |
|---|
| 25 | $y = substr($ts, 0, 4); |
|---|
| 26 | $mo = substr($ts, 4, 2); |
|---|
| 27 | $start = sprintf("%04d%02d01000000", $y, $mo); |
|---|
| 28 | $end = sprintf("%04d%02d%02d235959", $y, $mo, days_in($mo, $y)); |
|---|
| 29 | return array($start, $end); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | function days_in($m, $y) { |
|---|
| 33 | return date('t', mktime(0, 0, 0, $m, 1, $y)); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | function start_end_day($ts) { |
|---|
| 37 | $day = substr($ts, 0, 8); |
|---|
| 38 | return array($day . "000000", $day . "235959"); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | function start_end_year($ts) { |
|---|
| 42 | $year = substr($ts, 0, 4); |
|---|
| 43 | return array($year . "0101000000", $year . "1231235959"); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | function start_end_week($ts) { |
|---|
| 47 | $y = substr($ts, 0, 4); |
|---|
| 48 | $mo = substr($ts, 4, 2); |
|---|
| 49 | $d = substr($ts, 6, 2); |
|---|
| 50 | $h = substr($ts, 8, 2); |
|---|
| 51 | $s = substr($ts, 10, 2); |
|---|
| 52 | $wday = wday_from_ts($y, $mo, $d); |
|---|
| 53 | list($sd, $sm, $sy) = array($d - $wday, $mo, $y); |
|---|
| 54 | if ($sd < 1) { |
|---|
| 55 | $sm--; |
|---|
| 56 | if ($sm < 1) { |
|---|
| 57 | $sm = 12; $sy--; |
|---|
| 58 | } |
|---|
| 59 | $sd += days_in($sm, $sy); |
|---|
| 60 | } |
|---|
| 61 | $start = sprintf("%04d%02d%02d%s", $sy, $sm, $sd, "000000"); |
|---|
| 62 | list($ed, $em, $ey) = array($d + 6 - $wday, $mo, $y); |
|---|
| 63 | if ($ed > days_in($em, $ey)) { |
|---|
| 64 | $ed -= days_in($em, $ey); |
|---|
| 65 | $em++; |
|---|
| 66 | if ($em > 12) { |
|---|
| 67 | $em = 1; $ey++; |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | $end = sprintf("%04d%02d%02d%s", $ey, $em, $ed, "235959"); |
|---|
| 71 | return array($start, $end); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | global $In_Year; |
|---|
| 75 | $In_Year = array( |
|---|
| 76 | array( 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 ), |
|---|
| 77 | array( 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 ), |
|---|
| 78 | ); |
|---|
| 79 | function week2ymd($y, $week) { |
|---|
| 80 | $jan_one_dow_m1 = (ymd2rd($y, 1, 1) + 6) % 7; |
|---|
| 81 | |
|---|
| 82 | if ($jan_one_dow_m1 < 4) $week--; |
|---|
| 83 | $day_of_year = $week * 7 - $jan_one_dow_m1; |
|---|
| 84 | $leap_year = is_leap_year($y); |
|---|
| 85 | if ($day_of_year < 1) { |
|---|
| 86 | $y--; |
|---|
| 87 | $day_of_year = ($leap_year ? 366 : 365) + $day_of_year; |
|---|
| 88 | } |
|---|
| 89 | if ($leap_year) { |
|---|
| 90 | $ref = array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335); |
|---|
| 91 | } else { |
|---|
| 92 | $ref = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334); |
|---|
| 93 | } |
|---|
| 94 | $m = 0; |
|---|
| 95 | for ($i = count($ref); $i > 0; $i--) { |
|---|
| 96 | if ($day_of_year > $ref[$i-1]) { |
|---|
| 97 | $m = $i; |
|---|
| 98 | break; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | return array($y, $m, $day_of_year - $ref[$m-1]); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | function is_leap_year($y) { |
|---|
| 105 | return (!($y % 4) && ($y % 100)) || !($y % 400) ? true : false; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | function ymd2rd($y,$m,$d) { |
|---|
| 109 | # make month in range 3..14 (treat Jan & Feb as months 13..14 of |
|---|
| 110 | # prev year) |
|---|
| 111 | if ( $m <= 2 ) { |
|---|
| 112 | $adj = (int)(( 14 - $m ) / 12); |
|---|
| 113 | $y -= $adj; |
|---|
| 114 | $m += 12 * $adj; |
|---|
| 115 | } |
|---|
| 116 | elseif ( $m > 14 ) |
|---|
| 117 | { |
|---|
| 118 | $adj = (int)(( $m - 3 ) / 12); |
|---|
| 119 | $y += $adj; |
|---|
| 120 | $m -= 12 * $adj; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | # make year positive (oh, for a use integer 'sane_div'!) |
|---|
| 124 | if ( $y < 0 ) |
|---|
| 125 | { |
|---|
| 126 | $adj = (int)(( 399 - $y ) / 400); |
|---|
| 127 | $d -= 146097 * $adj; |
|---|
| 128 | $y += 400 * $adj; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | # add: day of month, days of previous 0-11 month period that began |
|---|
| 132 | # w/March, days of previous 0-399 year period that began w/March |
|---|
| 133 | # of a 400-multiple year), days of any 400-year periods before |
|---|
| 134 | # that, and 306 days to adjust from Mar 1, year 0-relative to Jan |
|---|
| 135 | # 1, year 1-relative (whew) |
|---|
| 136 | $d += (int)(( $m * 367 - 1094 ) / 12) + (int)((($y % 100) * 1461) / 4) + |
|---|
| 137 | ( (int)($y / 100) * 36524 + (int)($y / 400) ) - 306; |
|---|
| 138 | return $d; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | function wday_from_ts($y, $m, $d) { |
|---|
| 142 | global $In_Year; |
|---|
| 143 | $leap = $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? 1 : 0; |
|---|
| 144 | $y--; |
|---|
| 145 | |
|---|
| 146 | ## Copied from Date::Calc. |
|---|
| 147 | $days = $y * 365; |
|---|
| 148 | $days += $y >>= 2; |
|---|
| 149 | $days -= intval($y /= 25); |
|---|
| 150 | $days += $y >> 2; |
|---|
| 151 | $days += $In_Year[$leap][$m-1] + $d; |
|---|
| 152 | return $days % 7; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | function yday_from_ts($y, $m, $d) { |
|---|
| 156 | global $In_Year; |
|---|
| 157 | $leap = $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? 1 : 0; |
|---|
| 158 | return $In_Year[$leap][$m-1] + $d; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | function substr_wref($str, $start, $length) { |
|---|
| 162 | if (preg_match_all('/(&[^;]*;|.)/', $str, $character_entities)) { |
|---|
| 163 | return implode('', array_slice($character_entities[0], $start, $length)); |
|---|
| 164 | } else { |
|---|
| 165 | return ''; |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | function format_ts($format, $ts, $blog, $lang = null) { |
|---|
| 170 | global $Languages; |
|---|
| 171 | if (!isset($lang) || empty($lang)) { |
|---|
| 172 | global $mt; |
|---|
| 173 | $lang = ($blog && $blog['blog_language'] ? $blog['blog_language'] : |
|---|
| 174 | $mt->config('DefaultLanguage')); |
|---|
| 175 | } |
|---|
| 176 | if ($lang == 'jp') { |
|---|
| 177 | $lang = 'ja'; |
|---|
| 178 | } |
|---|
| 179 | $lang = strtolower(substr($lang, 0, 2)); |
|---|
| 180 | if (!isset($format) || empty($format)) { |
|---|
| 181 | if (count($Languages[$lang]) >= 4) |
|---|
| 182 | $format = $Languages[$lang][3]; |
|---|
| 183 | $format or $format = "%B %e, %Y %l:%M %p"; |
|---|
| 184 | } |
|---|
| 185 | global $_format_ts_cache; |
|---|
| 186 | if (!isset($_format_ts_cache)) { |
|---|
| 187 | $_format_ts_cache = array(); |
|---|
| 188 | } |
|---|
| 189 | if (isset($_format_ts_cache[$ts.$lang])) { |
|---|
| 190 | $f = $_format_ts_cache[$ts.$lang]; |
|---|
| 191 | } else { |
|---|
| 192 | $L = $Languages[$lang]; |
|---|
| 193 | $tsa = array(substr($ts, 0, 4), substr($ts, 4, 2), substr($ts, 6, 2), |
|---|
| 194 | substr($ts, 8, 2), substr($ts, 10, 2), substr($ts, 12, 2)); |
|---|
| 195 | list($f['Y'], $f['m'], $f['d'], $f['H'], $f['M'], $f['S']) = $tsa; |
|---|
| 196 | $f['w'] = wday_from_ts($tsa[0],$tsa[1],$tsa[2]); |
|---|
| 197 | $f['j'] = yday_from_ts($tsa[0],$tsa[1],$tsa[2]); |
|---|
| 198 | $f['y'] = substr($f['Y'], 2); |
|---|
| 199 | $f['b'] = substr_wref($L[1][$f['m']-1], 0, 3); |
|---|
| 200 | $f['B'] = $L[1][$f['m']-1]; |
|---|
| 201 | if ($lang == 'ja') { |
|---|
| 202 | $f['a'] = substr($L[0][$f['w']], 0, 8); |
|---|
| 203 | } else { |
|---|
| 204 | $f['a'] = substr_wref($L[0][$f['w']], 0, 3); |
|---|
| 205 | } |
|---|
| 206 | $f['A'] = $L[0][$f['w']]; |
|---|
| 207 | $f['e'] = $f['d']; |
|---|
| 208 | $f['e'] = preg_replace('!^0!', ' ', $f['e']); |
|---|
| 209 | $f['I'] = $f['H']; |
|---|
| 210 | if ($f['I'] > 12) { |
|---|
| 211 | $f['I'] -= 12; |
|---|
| 212 | $f['p'] = $L[2][1]; |
|---|
| 213 | } elseif ($f['I'] == 0) { |
|---|
| 214 | $f['I'] = 12; |
|---|
| 215 | $f['p'] = $L[2][0]; |
|---|
| 216 | } elseif ($f['I'] == 12) { |
|---|
| 217 | $f['p'] = $L[2][1]; |
|---|
| 218 | } else { |
|---|
| 219 | $f['p'] = $L[2][0]; |
|---|
| 220 | } |
|---|
| 221 | $f['I'] = sprintf("%02d", $f['I']); |
|---|
| 222 | $f['k'] = $f['H']; |
|---|
| 223 | $f['k'] = preg_replace('!^0!', ' ', $f['k']); |
|---|
| 224 | $f['l'] = $f['I']; |
|---|
| 225 | $f['l'] = preg_replace('!^0!', ' ', $f['l']); |
|---|
| 226 | $f['j'] = sprintf("%03d", $f['j']); |
|---|
| 227 | $f['Z'] = ''; |
|---|
| 228 | $_format_ts_cache[$ts . $lang] = $f; |
|---|
| 229 | } |
|---|
| 230 | $date_format = null; |
|---|
| 231 | if (count($Languages[$lang]) >= 5) |
|---|
| 232 | $date_format = $Languages[$lang][4]; |
|---|
| 233 | $date_format or $date_format = "%B %e, %Y"; |
|---|
| 234 | $time_format = null; |
|---|
| 235 | if (count($Languages[$lang]) >= 6) |
|---|
| 236 | $time_format = $Languages[$lang][5]; |
|---|
| 237 | $time_format or $time_format = "%l:%M %p"; |
|---|
| 238 | $format = preg_replace('!%x!', $date_format, $format); |
|---|
| 239 | $format = preg_replace('!%X!', $time_format, $format); |
|---|
| 240 | ## This is a dreadful hack. I can't think of a good format specifier |
|---|
| 241 | ## for "%B %Y" (which is used for monthly archives, for example) so |
|---|
| 242 | ## I'll just hardcode this, for Japanese dates. |
|---|
| 243 | if ($lang == 'ja') { |
|---|
| 244 | if (count($Languages[$lang]) >= 8) { |
|---|
| 245 | $format = preg_replace('!%B %Y!', $Languages[$lang][6], $format); |
|---|
| 246 | $format = preg_replace('!%B %E,? %Y!i', $Languages[$lang][4], $format); |
|---|
| 247 | $format = preg_replace('!%B %E!', $Languages[$lang][7], $format); |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | elseif ( $lang == 'it' ) { |
|---|
| 251 | ## Hack for the Italian dates |
|---|
| 252 | ## In Italian, the date always come before the month. |
|---|
| 253 | $format = preg_replace('!%b %e!', '%e %b', $format); |
|---|
| 254 | } |
|---|
| 255 | if (isset($format)) { |
|---|
| 256 | $format = preg_replace('!%(\w)!e', '\$f[\'\1\']', $format); |
|---|
| 257 | } |
|---|
| 258 | return $format; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | function dirify($s, $sep = '_') { |
|---|
| 262 | global $mt; |
|---|
| 263 | $charset = $mt->config('PublishCharset'); |
|---|
| 264 | $charset or $charset = 'utf-8'; |
|---|
| 265 | if (preg_match('/utf-?8/i', $charset)) { |
|---|
| 266 | return utf8_dirify($s, $sep); |
|---|
| 267 | } else { |
|---|
| 268 | return iso_dirify($s, $sep); |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | function utf8_dirify($s, $sep = '_') { |
|---|
| 273 | if ($sep == '1') $sep = '_'; |
|---|
| 274 | $s = xliterate_utf8($s); ## convert high-ASCII chars to 7bit. |
|---|
| 275 | $s = strtolower($s); ## lower-case. |
|---|
| 276 | $s = strip_tags($s); ## remove HTML tags. |
|---|
| 277 | $s = preg_replace('!&[^;\s]+;!', '', $s); ## remove HTML entities. |
|---|
| 278 | $s = preg_replace('![^\w\s]!', '', $s); ## remove non-word/space chars. |
|---|
| 279 | $s = preg_replace('/\s+/',$sep,$s); ## change space chars to underscores. |
|---|
| 280 | return($s); |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | global $Utf8_ASCII; |
|---|
| 284 | $Utf8_ASCII = array( |
|---|
| 285 | "\xc3\x80" => 'A', # A` |
|---|
| 286 | "\xc3\xa0" => 'a', # a` |
|---|
| 287 | "\xc3\x81" => 'A', # A' |
|---|
| 288 | "\xc3\xa1" => 'a', # a' |
|---|
| 289 | "\xc3\x82" => 'A', # A^ |
|---|
| 290 | "\xc3\xa2" => 'a', # a^ |
|---|
| 291 | "\xc4\x82" => 'A', # latin capital letter a with breve |
|---|
| 292 | "\xc4\x83" => 'a', # latin small letter a with breve |
|---|
| 293 | "\xc3\x86" => 'AE', # latin capital letter AE |
|---|
| 294 | "\xc3\xa6" => 'ae', # latin small letter ae |
|---|
| 295 | "\xc3\x85" => 'A', # latin capital letter a with ring above |
|---|
| 296 | "\xc3\xa5" => 'a', # latin small letter a with ring above |
|---|
| 297 | "\xc4\x80" => 'A', # latin capital letter a with macron |
|---|
| 298 | "\xc4\x81" => 'a', # latin small letter a with macron |
|---|
| 299 | "\xc4\x84" => 'A', # latin capital letter a with ogonek |
|---|
| 300 | "\xc4\x85" => 'a', # latin small letter a with ogonek |
|---|
| 301 | "\xc3\x84" => 'A', # A: |
|---|
| 302 | "\xc3\xa4" => 'a', # a: |
|---|
| 303 | "\xc3\x83" => 'A', # A~ |
|---|
| 304 | "\xc3\xa3" => 'a', # a~ |
|---|
| 305 | "\xc3\x88" => 'E', # E` |
|---|
| 306 | "\xc3\xa8" => 'e', # e` |
|---|
| 307 | "\xc3\x89" => 'E', # E' |
|---|
| 308 | "\xc3\xa9" => 'e', # e' |
|---|
| 309 | "\xc3\x8a" => 'E', # E^ |
|---|
| 310 | "\xc3\xaa" => 'e', # e^ |
|---|
| 311 | "\xc3\x8b" => 'E', # E: |
|---|
| 312 | "\xc3\xab" => 'e', # e: |
|---|
| 313 | "\xc4\x92" => 'E', # latin capital letter e with macron |
|---|
| 314 | "\xc4\x93" => 'e', # latin small letter e with macron |
|---|
| 315 | "\xc4\x98" => 'E', # latin capital letter e with ogonek |
|---|
| 316 | "\xc4\x99" => 'e', # latin small letter e with ogonek |
|---|
| 317 | "\xc4\x9a" => 'E', # latin capital letter e with caron |
|---|
| 318 | "\xc4\x9b" => 'e', # latin small letter e with caron |
|---|
| 319 | "\xc4\x94" => 'E', # latin capital letter e with breve |
|---|
| 320 | "\xc4\x95" => 'e', # latin small letter e with breve |
|---|
| 321 | "\xc4\x96" => 'E', # latin capital letter e with dot above |
|---|
| 322 | "\xc4\x97" => 'e', # latin small letter e with dot above |
|---|
| 323 | "\xc3\x8c" => 'I', # I` |
|---|
| 324 | "\xc3\xac" => 'i', # i` |
|---|
| 325 | "\xc3\x8d" => 'I', # I' |
|---|
| 326 | "\xc3\xad" => 'i', # i' |
|---|
| 327 | "\xc3\x8e" => 'I', # I^ |
|---|
| 328 | "\xc3\xae" => 'i', # i^ |
|---|
| 329 | "\xc3\x8f" => 'I', # I: |
|---|
| 330 | "\xc3\xaf" => 'i', # i: |
|---|
| 331 | "\xc4\xaa" => 'I', # latin capital letter i with macron |
|---|
| 332 | "\xc4\xab" => 'i', # latin small letter i with macron |
|---|
| 333 | "\xc4\xa8" => 'I', # latin capital letter i with tilde |
|---|
| 334 | "\xc4\xa9" => 'i', # latin small letter i with tilde |
|---|
| 335 | "\xc4\xac" => 'I', # latin capital letter i with breve |
|---|
| 336 | "\xc4\xad" => 'i', # latin small letter i with breve |
|---|
| 337 | "\xc4\xae" => 'I', # latin capital letter i with ogonek |
|---|
| 338 | "\xc4\xaf" => 'i', # latin small letter i with ogonek |
|---|
| 339 | "\xc4\xb0" => 'I', # latin capital letter with dot above |
|---|
| 340 | "\xc4\xb1" => 'i', # latin small letter dotless i |
|---|
| 341 | "\xc4\xb2" => 'IJ', # latin capital ligature ij |
|---|
| 342 | "\xc4\xb3" => 'ij', # latin small ligature ij |
|---|
| 343 | "\xc4\xb4" => 'J', # latin capital letter j with circumflex |
|---|
| 344 | "\xc4\xb5" => 'j', # latin small letter j with circumflex |
|---|
| 345 | "\xc4\xb6" => 'K', # latin capital letter k with cedilla |
|---|
| 346 | "\xc4\xb7" => 'k', # latin small letter k with cedilla |
|---|
| 347 | "\xc4\xb8" => 'k', # latin small letter kra |
|---|
| 348 | "\xc5\x81" => 'L', # latin capital letter l with stroke |
|---|
| 349 | "\xc5\x82" => 'l', # latin small letter l with stroke |
|---|
| 350 | "\xc4\xbd" => 'L', # latin capital letter l with caron |
|---|
| 351 | "\xc4\xbe" => 'l', # latin small letter l with caron |
|---|
| 352 | "\xc4\xb9" => 'L', # latin capital letter l with acute |
|---|
| 353 | "\xc4\xba" => 'l', # latin small letter l with acute |
|---|
| 354 | "\xc4\xbb" => 'L', # latin capital letter l with cedilla |
|---|
| 355 | "\xc4\xbc" => 'l', # latin small letter l with cedilla |
|---|
| 356 | "\xc4\xbf" => 'l', # latin capital letter l with middle dot |
|---|
| 357 | "\xc5\x80" => 'l', # latin small letter l with middle dot |
|---|
| 358 | "\xc3\x92" => 'O', # O` |
|---|
| 359 | "\xc3\xb2" => 'o', # o` |
|---|
| 360 | "\xc3\x93" => 'O', # O' |
|---|
| 361 | "\xc3\xb3" => 'o', # o' |
|---|
| 362 | "\xc3\x94" => 'O', # O^ |
|---|
| 363 | "\xc3\xb4" => 'o', # o^ |
|---|
| 364 | "\xc3\x96" => 'O', # O: |
|---|
| 365 | "\xc3\xb6" => 'o', # o: |
|---|
| 366 | "\xc3\x95" => 'O', # O~ |
|---|
| 367 | "\xc3\xb5" => 'o', # o~ |
|---|
| 368 | "\xc3\x98" => 'O', # O/ |
|---|
| 369 | "\xc3\xb8" => 'o', # o/ |
|---|
| 370 | "\xc5\x8c" => 'O', # latin capital letter o with macron |
|---|
| 371 | "\xc5\x8d" => 'o', # latin small letter o with macron |
|---|
| 372 | "\xc5\x90" => 'O', # latin capital letter o with double acute |
|---|
| 373 | "\xc5\x91" => 'o', # latin small letter o with double acute |
|---|
| 374 | "\xc5\x8e" => 'O', # latin capital letter o with breve |
|---|
| 375 | "\xc5\x8f" => 'o', # latin small letter o with breve |
|---|
| 376 | "\xc5\x92" => 'OE', # latin capital ligature oe |
|---|
| 377 | "\xc5\x93" => 'oe', # latin small ligature oe |
|---|
| 378 | "\xc5\x94" => 'R', # latin capital letter r with acute |
|---|
| 379 | "\xc5\x95" => 'r', # latin small letter r with acute |
|---|
| 380 | "\xc5\x98" => 'R', # latin capital letter r with caron |
|---|
| 381 | "\xc5\x99" => 'r', # latin small letter r with caron |
|---|
| 382 | "\xc5\x96" => 'R', # latin capital letter r with cedilla |
|---|
| 383 | "\xc5\x97" => 'r', # latin small letter r with cedilla |
|---|
| 384 | "\xc3\x99" => 'U', # U` |
|---|
| 385 | "\xc3\xb9" => 'u', # u` |
|---|
| 386 | "\xc3\x9a" => 'U', # U' |
|---|
| 387 | "\xc3\xba" => 'u', # u' |
|---|
| 388 | "\xc3\x9b" => 'U', # U^ |
|---|
| 389 | "\xc3\xbb" => 'u', # u^ |
|---|
| 390 | "\xc3\x9c" => 'U', # U: |
|---|
| 391 | "\xc3\xbc" => 'u', # u: |
|---|
| 392 | "\xc5\xaa" => 'U', # latin capital letter u with macron |
|---|
| 393 | "\xc5\xab" => 'u', # latin small letter u with macron |
|---|
| 394 | "\xc5\xae" => 'U', # latin capital letter u with ring above |
|---|
| 395 | "\xc5\xaf" => 'u', # latin small letter u with ring above |
|---|
| 396 | "\xc5\xb0" => 'U', # latin capital letter u with double acute |
|---|
| 397 | "\xc5\xb1" => 'u', # latin small letter u with double acute |
|---|
| 398 | "\xc5\xac" => 'U', # latin capital letter u with breve |
|---|
| 399 | "\xc5\xad" => 'u', # latin small letter u with breve |
|---|
| 400 | "\xc5\xa8" => 'U', # latin capital letter u with tilde |
|---|
| 401 | "\xc5\xa9" => 'u', # latin small letter u with tilde |
|---|
| 402 | "\xc5\xb2" => 'U', # latin capital letter u with ogonek |
|---|
| 403 | "\xc5\xb3" => 'u', # latin small letter u with ogonek |
|---|
| 404 | "\xc3\x87" => 'C', # ,C |
|---|
| 405 | "\xc3\xa7" => 'c', # ,c |
|---|
| 406 | "\xc4\x86" => 'C', # latin capital letter c with acute |
|---|
| 407 | "\xc4\x87" => 'c', # latin small letter c with acute |
|---|
| 408 | "\xc4\x8c" => 'C', # latin capital letter c with caron |
|---|
| 409 | "\xc4\x8d" => 'c', # latin small letter c with caron |
|---|
| 410 | "\xc4\x88" => 'C', # latin capital letter c with circumflex |
|---|
| 411 | "\xc4\x89" => 'c', # latin small letter c with circumflex |
|---|
| 412 | "\xc4\x8a" => 'C', # latin capital letter c with dot above |
|---|
| 413 | "\xc4\x8b" => 'c', # latin small letter c with dot above |
|---|
| 414 | "\xc4\x8e" => 'D', # latin capital letter d with caron |
|---|
| 415 | "\xc4\x8f" => 'd', # latin small letter d with caron |
|---|
| 416 | "\xc4\x90" => 'D', # latin capital letter d with stroke |
|---|
| 417 | "\xc4\x91" => 'd', # latin small letter d with stroke |
|---|
| 418 | "\xc3\x91" => 'N', # N~ |
|---|
| 419 | "\xc3\xb1" => 'n', # n~ |
|---|
| 420 | "\xc5\x83" => 'N', # latin capital letter n with acute |
|---|
| 421 | "\xc5\x84" => 'n', # latin small letter n with acute |
|---|
| 422 | "\xc5\x87" => 'N', # latin capital letter n with caron |
|---|
| 423 | "\xc5\x88" => 'n', # latin small letter n with caron |
|---|
| 424 | "\xc5\x85" => 'N', # latin capital letter n with cedilla |
|---|
| 425 | "\xc5\x86" => 'n', # latin small letter n with cedilla |
|---|
| 426 | "\xc5\x89" => 'n', # latin small letter n preceded by apostrophe |
|---|
| 427 | "\xc5\x8a" => 'N', # latin capital letter eng |
|---|
| 428 | "\xc5\x8b" => 'n', # latin small letter eng |
|---|
| 429 | "\xc3\x9f" => 'ss', # double-s |
|---|
| 430 | "\xc5\x9a" => 'S', # latin capital letter s with acute |
|---|
| 431 | "\xc5\x9b" => 's', # latin small letter s with acute |
|---|
| 432 | "\xc5\xa0" => 'S', # latin capital letter s with caron |
|---|
| 433 | "\xc5\xa1" => 's', # latin small letter s with caron |
|---|
| 434 | "\xc5\x9e" => 'S', # latin capital letter s with cedilla |
|---|
| 435 | "\xc5\x9f" => 's', # latin small letter s with cedilla |
|---|
| 436 | "\xc5\x9c" => 'S', # latin capital letter s with circumflex |
|---|
| 437 | "\xc5\x9d" => 's', # latin small letter s with circumflex |
|---|
| 438 | "\xc8\x98" => 'S', # latin capital letter s with comma below |
|---|
| 439 | "\xc8\x99" => 's', # latin small letter s with comma below |
|---|
| 440 | "\xc5\xa4" => 'T', # latin capital letter t with caron |
|---|
| 441 | "\xc5\xa5" => 't', # latin small letter t with caron |
|---|
| 442 | "\xc5\xa2" => 'T', # latin capital letter t with cedilla |
|---|
| 443 | "\xc5\xa3" => 't', # latin small letter t with cedilla |
|---|
| 444 | "\xc5\xa6" => 'T', # latin capital letter t with stroke |
|---|
| 445 | "\xc5\xa7" => 't', # latin small letter t with stroke |
|---|
| 446 | "\xc8\x9a" => 'T', # latin capital letter t with comma below |
|---|
| 447 | "\xc8\x9b" => 't', # latin small letter t with comma below |
|---|
| 448 | "\xc6\x92" => 'f', # latin small letter f with hook |
|---|
| 449 | "\xc4\x9c" => 'G', # latin capital letter g with circumflex |
|---|
| 450 | "\xc4\x9d" => 'g', # latin small letter g with circumflex |
|---|
| 451 | "\xc4\x9e" => 'G', # latin capital letter g with breve |
|---|
| 452 | "\xc4\x9f" => 'g', # latin small letter g with breve |
|---|
| 453 | "\xc4\xa0" => 'G', # latin capital letter g with dot above |
|---|
| 454 | "\xc4\xa1" => 'g', # latin small letter g with dot above |
|---|
| 455 | "\xc4\xa2" => 'G', # latin capital letter g with cedilla |
|---|
| 456 | "\xc4\xa3" => 'g', # latin small letter g with cedilla |
|---|
| 457 | "\xc4\xa4" => 'H', # latin capital letter h with circumflex |
|---|
| 458 | "\xc4\xa5" => 'h', # latin small letter h with circumflex |
|---|
| 459 | "\xc4\xa6" => 'H', # latin capital letter h with stroke |
|---|
| 460 | "\xc4\xa7" => 'h', # latin small letter h with stroke |
|---|
| 461 | "\xc5\xb4" => 'W', # latin capital letter w with circumflex |
|---|
| 462 | "\xc5\xb5" => 'w', # latin small letter w with circumflex |
|---|
| 463 | "\xc3\x9d" => 'Y', # latin capital letter y with acute |
|---|
| 464 | "\xc3\xbd" => 'y', # latin small letter y with acute |
|---|
| 465 | "\xc5\xb8" => 'Y', # latin capital letter y with diaeresis |
|---|
| 466 | "\xc3\xbf" => 'y', # latin small letter y with diaeresis |
|---|
| 467 | "\xc5\xb6" => 'Y', # latin capital letter y with circumflex |
|---|
| 468 | "\xc5\xb7" => 'y', # latin small letter y with circumflex |
|---|
| 469 | "\xc5\xbd" => 'Z', # latin capital letter z with caron |
|---|
| 470 | "\xc5\xbe" => 'z', # latin small letter z with caron |
|---|
| 471 | "\xc5\xbb" => 'Z', # latin capital letter z with dot above |
|---|
| 472 | "\xc5\xbc" => 'z', # latin small letter z with dot above |
|---|
| 473 | "\xc5\xb9" => 'Z', # latin capital letter z with acute |
|---|
| 474 | "\xc5\xba" => 'z', # latin small letter z with acute |
|---|
| 475 | ); |
|---|
| 476 | function xliterate_utf8($s) { |
|---|
| 477 | global $Utf8_ASCII; |
|---|
| 478 | return strtr($s, $Utf8_ASCII); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | function iso_dirify($s, $sep = '_') { |
|---|
| 482 | if ($sep == '1') $sep = '_'; |
|---|
| 483 | $s = convert_high_ascii($s); ## convert high-ASCII chars to 7bit. |
|---|
| 484 | $s = strtolower($s); ## lower-case. |
|---|
| 485 | $s = strip_tags($s); ## remove HTML tags. |
|---|
| 486 | $s = preg_replace('!&[^;\s]+;!', '', $s); ## remove HTML entities. |
|---|
| 487 | $s = preg_replace('![^\w\s]!', '', $s); ## remove non-word/space chars. |
|---|
| 488 | $s = preg_replace('/\s+/',$sep,$s); ## change space chars to underscores. |
|---|
| 489 | return($s); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | global $Latin1_ASCII; |
|---|
| 493 | $Latin1_ASCII = array( |
|---|
| 494 | "\xc0" => 'A', # A` |
|---|
| 495 | "\xe0" => 'a', # a` |
|---|
| 496 | "\xc1" => 'A', # A' |
|---|
| 497 | "\xe1" => 'a', # a' |
|---|
| 498 | "\xc2" => 'A', # A^ |
|---|
| 499 | "\xe2" => 'a', # a^ |
|---|
| 500 | "\xc4" => 'A', # A: |
|---|
| 501 | "\xe4" => 'a', # a: |
|---|
| 502 | "\xc5" => 'A', # Aring |
|---|
| 503 | "\xe5" => 'a', # aring |
|---|
| 504 | "\xc6" => 'AE', # AE |
|---|
| 505 | "\xe6" => 'ae', # ae |
|---|
| 506 | "\xc3" => 'A', # A~ |
|---|
| 507 | "\xe3" => 'a', # a~ |
|---|
| 508 | "\xc8" => 'E', # E` |
|---|
| 509 | "\xe8" => 'e', # e` |
|---|
| 510 | "\xc9" => 'E', # E' |
|---|
| 511 | "\xe9" => 'e', # e' |
|---|
| 512 | "\xca" => 'E', # E^ |
|---|
| 513 | "\xea" => 'e', # e^ |
|---|
| 514 | "\xcb" => 'E', # E: |
|---|
| 515 | "\xeb" => 'e', # e: |
|---|
| 516 | "\xcc" => 'I', # I` |
|---|
| 517 | "\xec" => 'i', # i` |
|---|
| 518 | "\xcd" => 'I', # I' |
|---|
| 519 | "\xed" => 'i', # i' |
|---|
| 520 | "\xce" => 'I', # I^ |
|---|
| 521 | "\xee" => 'i', # i^ |
|---|
| 522 | "\xcf" => 'I', # I: |
|---|
| 523 | "\xef" => 'i', # i: |
|---|
| 524 | "\xd2" => 'O', # O` |
|---|
| 525 | "\xf2" => 'o', # o` |
|---|
| 526 | "\xd3" => 'O', # O' |
|---|
| 527 | "\xf3" => 'o', # o' |
|---|
| 528 | "\xd4" => 'O', # O^ |
|---|
| 529 | "\xf4" => 'o', # o^ |
|---|
| 530 | "\xd6" => 'O', # O: |
|---|
| 531 | "\xf6" => 'o', # o: |
|---|
| 532 | "\xd5" => 'O', # O~ |
|---|
| 533 | "\xf5" => 'o', # o~ |
|---|
| 534 | "\xd8" => 'O', # O/ |
|---|
| 535 | "\xf8" => 'o', # o/ |
|---|
| 536 | "\xd9" => 'U', # U` |
|---|
| 537 | "\xf9" => 'u', # u` |
|---|
| 538 | "\xda" => 'U', # U' |
|---|
| 539 | "\xfa" => 'u', # u' |
|---|
| 540 | "\xdb" => 'U', # U^ |
|---|
| 541 | "\xfb" => 'u', # u^ |
|---|
| 542 | "\xdc" => 'U', # U: |
|---|
| 543 | "\xfc" => 'u', # u: |
|---|
| 544 | "\xc7" => 'C', # ,C |
|---|
| 545 | "\xe7" => 'c', # ,c |
|---|
| 546 | "\xd1" => 'N', # N~ |
|---|
| 547 | "\xf1" => 'n', # n~ |
|---|
| 548 | "\xdd" => 'Y', # Yacute |
|---|
| 549 | "\xfd" => 'y', # yacute |
|---|
| 550 | "\xdf" => 'ss', # szlig |
|---|
| 551 | "\xff" => 'y' # yuml |
|---|
| 552 | ); |
|---|
| 553 | function convert_high_ascii($s) { |
|---|
| 554 | global $mt; |
|---|
| 555 | $lang = $mt->config('DefaultLanguage'); |
|---|
| 556 | if ($lang == 'ja') { |
|---|
| 557 | $s = mb_convert_encoding($s, 'UTF-8'); |
|---|
| 558 | return $s; |
|---|
| 559 | } |
|---|
| 560 | global $Latin1_ASCII; |
|---|
| 561 | return strtr($s, $Latin1_ASCII); |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | global $Languages; |
|---|
| 565 | $Languages = array( |
|---|
| 566 | 'en' => array( |
|---|
| 567 | array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'), |
|---|
| 568 | array('January','February','March','April','May','June', |
|---|
| 569 | 'July','August','September','October','November','December'), |
|---|
| 570 | array('AM','PM'), |
|---|
| 571 | ), |
|---|
| 572 | |
|---|
| 573 | 'fr' => array( |
|---|
| 574 | array('dimanche','lundi','mardi','mercredi','jeudi','vendredi','samedi' ), |
|---|
| 575 | array('janvier', "février", 'mars', 'avril', 'mai', 'juin', |
|---|
| 576 | 'juillet', "août", 'septembre', 'octobre', 'novembre', |
|---|
| 577 | "décembre"), |
|---|
| 578 | array('AM','PM'), |
|---|
| 579 | ), |
|---|
| 580 | |
|---|
| 581 | 'es' => array( |
|---|
| 582 | array('Domingo', 'Lunes', 'Martes', "Miércoles", 'Jueves', |
|---|
| 583 | 'Viernes', "Sábado"), |
|---|
| 584 | array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto', |
|---|
| 585 | 'Septiembre','Octubre','Noviembre','Diciembre'), |
|---|
| 586 | array('AM','PM'), |
|---|
| 587 | ), |
|---|
| 588 | |
|---|
| 589 | 'pt' => array( |
|---|
| 590 | array('domingo', 'segunda-feira', "terça-feira", 'quarta-feira', |
|---|
| 591 | 'quinta-feira', 'sexta-feira', "sábado"), |
|---|
| 592 | array('janeiro', 'fevereiro', "março", 'abril', 'maio', 'junho', |
|---|
| 593 | 'julho', 'agosto', 'setembro', 'outubro', 'novembro', |
|---|
| 594 | 'dezembro' ), |
|---|
| 595 | array('AM','PM'), |
|---|
| 596 | ), |
|---|
| 597 | |
|---|
| 598 | 'nl' => array( |
|---|
| 599 | array('zondag','maandag','dinsdag','woensdag','donderdag','vrijdag', |
|---|
| 600 | 'zaterdag'), |
|---|
| 601 | array('januari','februari','maart','april','mei','juni','juli','augustus', |
|---|
| 602 | 'september','oktober','november','december'), |
|---|
| 603 | array('am','pm'), |
|---|
| 604 | "%d %B %Y %H:%M", |
|---|
| 605 | "%d %B %Y" |
|---|
| 606 | ), |
|---|
| 607 | |
|---|
| 608 | 'dk' => array( |
|---|
| 609 | array("søndag", 'mandag', 'tirsdag', 'onsdag', 'torsdag', |
|---|
| 610 | 'fredag', "lørdag"), |
|---|
| 611 | array('januar','februar','marts','april','maj','juni','juli','august', |
|---|
| 612 | 'september','oktober','november','december'), |
|---|
| 613 | array('am','pm'), |
|---|
| 614 | "%d.%m.%Y %H:%M", |
|---|
| 615 | "%d.%m.%Y", |
|---|
| 616 | "%H:%M", |
|---|
| 617 | ), |
|---|
| 618 | |
|---|
| 619 | 'se' => array( |
|---|
| 620 | array("söndag", "måndag", 'tisdag', 'onsdag', 'torsdag', |
|---|
| 621 | 'fredag', "lördag"), |
|---|
| 622 | array('januari','februari','mars','april','maj','juni','juli','augusti', |
|---|
| 623 | 'september','oktober','november','december'), |
|---|
| 624 | array('FM','EM'), |
|---|
| 625 | ), |
|---|
| 626 | |
|---|
| 627 | 'no' => array( |
|---|
| 628 | array("Søndag", "Mandag", 'Tirsdag', 'Onsdag', 'Torsdag', |
|---|
| 629 | 'Fredag', "Lørdag"), |
|---|
| 630 | array('Januar','Februar','Mars','April','Mai','Juni','Juli','August', |
|---|
| 631 | 'September','Oktober','November','Desember'), |
|---|
| 632 | array('FM','EM'), |
|---|
| 633 | ), |
|---|
| 634 | |
|---|
| 635 | 'de' => array( |
|---|
| 636 | array('Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag', |
|---|
| 637 | 'Samstag'), |
|---|
| 638 | array('Januar', 'Februar', "März", 'April', 'Mai', 'Juni', |
|---|
| 639 | 'Juli', 'August', 'September', 'Oktober', 'November', |
|---|
| 640 | 'Dezember'), |
|---|
| 641 | array('FM','EM'), |
|---|
| 642 | "%d.%m.%y %H:%M", |
|---|
| 643 | "%d.%m.%y", |
|---|
| 644 | "%H:%M", |
|---|
| 645 | ), |
|---|
| 646 | |
|---|
| 647 | 'it' => array( |
|---|
| 648 | array('Domenica', "Lunedì", "Martedì", "Mercoledì", |
|---|
| 649 | "Giovedì", "Venerdì", 'Sabato'), |
|---|
| 650 | array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio', |
|---|
| 651 | 'Agosto','Settembre','Ottobre','Novembre','Dicembre'), |
|---|
| 652 | array('AM','PM'), |
|---|
| 653 | "%d.%m.%y %H:%M", |
|---|
| 654 | "%d.%m.%y", |
|---|
| 655 | "%H:%M", |
|---|
| 656 | ), |
|---|
| 657 | |
|---|
| 658 | 'pl' => array( |
|---|
| 659 | array('niedziela', "poniedziałek", 'wtorek', "środa", |
|---|
| 660 | 'czwartek', "piątek", 'sobota'), |
|---|
| 661 | array('stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', |
|---|
| 662 | 'lipca', 'sierpnia', "września", "października", |
|---|
| 663 | 'listopada', 'grudnia'), |
|---|
| 664 | array('AM','PM'), |
|---|
| 665 | "%e %B %Y %k:%M", |
|---|
| 666 | "%e %B %Y", |
|---|
| 667 | "%k:%M", |
|---|
| 668 | ), |
|---|
| 669 | |
|---|
| 670 | 'fi' => array( |
|---|
| 671 | array('sunnuntai','maanantai','tiistai','keskiviikko','torstai','perjantai', |
|---|
| 672 | 'lauantai'), |
|---|
| 673 | array('tammikuu', 'helmikuu', 'maaliskuu', 'huhtikuu', 'toukokuu', |
|---|
| 674 | "kesäkuu", "heinäkuu", 'elokuu', 'syyskuu', 'lokakuu', |
|---|
| 675 | 'marraskuu', 'joulukuu'), |
|---|
| 676 | array('AM','PM'), |
|---|
| 677 | "%d.%m.%y %H:%M", |
|---|
| 678 | ), |
|---|
| 679 | |
|---|
| 680 | 'is' => array( |
|---|
| 681 | array('Sunnudagur', "Mánudagur", "Þriðjudagur", |
|---|
| 682 | "Miðvikudagur", 'Fimmtudagur', "Föstudagur", |
|---|
| 683 | 'Laugardagur'), |
|---|
| 684 | array("janúar", "febrúar", 'mars', "apríl", "maí", |
|---|
| 685 | "júní", "júlí", "ágúst", 'september', |
|---|
| 686 | "október", "nóvember", 'desember'), |
|---|
| 687 | array('FH','EH'), |
|---|
| 688 | "%d.%m.%y %H:%M", |
|---|
| 689 | ), |
|---|
| 690 | |
|---|
| 691 | 'si' => array( |
|---|
| 692 | array('nedelja', 'ponedeljek', 'torek', 'sreda', "ãetrtek", |
|---|
| 693 | 'petek', 'sobota'), |
|---|
| 694 | array('januar','februar','marec','april','maj','junij','julij','avgust', |
|---|
| 695 | 'september','oktober','november','december'), |
|---|
| 696 | array('AM','PM'), |
|---|
| 697 | "%d.%m.%y %H:%M", |
|---|
| 698 | ), |
|---|
| 699 | |
|---|
| 700 | 'cz' => array( |
|---|
| 701 | array('Neděle', 'Pondělí', 'Úterý', |
|---|
| 702 | 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'), |
|---|
| 703 | array('Leden', 'Únor', 'Březen', 'Duben', 'Květen', |
|---|
| 704 | 'Červen', 'Červenec', 'Srpen', 'Září', |
|---|
| 705 | 'Øíjen', 'Listopad', 'Prosinec'), |
|---|
| 706 | array('AM','PM'), |
|---|
| 707 | "%e. %B %Y %k:%M", |
|---|
| 708 | "%e. %B %Y", |
|---|
| 709 | "%k:%M", |
|---|
| 710 | ), |
|---|
| 711 | |
|---|
| 712 | 'sk' => array( |
|---|
| 713 | array('nedeľa', 'pondelok', 'utorok', 'streda', |
|---|
| 714 | 'štvrtok', 'piatok', 'sobota'), |
|---|
| 715 | array('január', 'február', 'marec', 'apríl', |
|---|
| 716 | 'máj', 'jún', 'júl', 'august', 'september', |
|---|
| 717 | 'október', 'november', 'december'), |
|---|
| 718 | array('AM','PM'), |
|---|
| 719 | "%e. %B %Y %k:%M", |
|---|
| 720 | "%e. %B %Y", |
|---|
| 721 | "%k:%M", |
|---|
| 722 | ), |
|---|
| 723 | |
|---|
| 724 | 'jp' => array( |
|---|
| 725 | array('日曜日', '月曜日', |
|---|
| 726 | '火曜日', '水曜日', |
|---|
| 727 | '木曜日', '金曜日', |
|---|
| 728 | '土曜日'), |
|---|
| 729 | array('1','2','3','4','5','6','7','8','9','10','11','12'), |
|---|
| 730 | array('AM','PM'), |
|---|
| 731 | "%Y年%b月%e日 %H:%M", |
|---|
| 732 | "%Y年%b月%e日", |
|---|
| 733 | "%H:%M", |
|---|
| 734 | "%Y年%b月", |
|---|
| 735 | "%b月%e日", |
|---|
| 736 | ), |
|---|
| 737 | |
|---|
| 738 | 'ja' => array( |
|---|
| 739 | array('日曜日', '月曜日', |
|---|
| 740 | '火曜日', '水曜日', |
|---|
| 741 | '木曜日', '金曜日', |
|---|
| 742 | '土曜日'), |
|---|
| 743 | array('1','2','3','4','5','6','7','8','9','10','11','12'), |
|---|
| 744 | array('AM','PM'), |
|---|
| 745 | "%Y年%b月%e日 %H:%M", |
|---|
| 746 | "%Y年%b月%e日", |
|---|
| 747 | "%H:%M", |
|---|
| 748 | "%Y年%b月", |
|---|
| 749 | "%b月%e日", |
|---|
| 750 | ), |
|---|
| 751 | |
|---|
| 752 | 'et' => array( |
|---|
| 753 | array('ipühapäev','esmaspäev','teisipäev', |
|---|
| 754 | 'kolmapäev','neljapäev','reede','laupäev'), |
|---|
| 755 | array('jaanuar', 'veebruar', 'märts', 'aprill', 'mai', |
|---|
| 756 | 'juuni', 'juuli', 'august', 'september', 'oktoober', |
|---|
| 757 | 'november', 'detsember'), |
|---|
| 758 | array('AM','PM'), |
|---|
| 759 | "%m.%d.%y %H:%M", |
|---|
| 760 | "%e. %B %Y", |
|---|
| 761 | "%H:%M", |
|---|
| 762 | ), |
|---|
| 763 | ); |
|---|
| 764 | |
|---|
| 765 | global $_encode_xml_Map; |
|---|
| 766 | $_encode_xml_Map = array('&' => '&', '"' => '"', |
|---|
| 767 | '<' => '<', '>' => '>', |
|---|
| 768 | '\'' => '''); |
|---|
| 769 | |
|---|
| 770 | function encode_xml($str, $nocdata = 0) { |
|---|
| 771 | global $mt, $_encode_xml_Map; |
|---|
| 772 | $cfg_nocdata = $mt->config('NoCDATA'); |
|---|
| 773 | $nocdata or (isset($cfg_nocdata) and $nocdata = $cfg_nocdata); |
|---|
| 774 | if ((!$nocdata) && (preg_match('/ |
|---|
| 775 | <[^>]+> ## HTML markup |
|---|
| 776 | | ## or |
|---|
| 777 | &(?:(?!(\#([0-9]+)|\#x([0-9a-fA-F]+))).*?); |
|---|
| 778 | ## something that looks like an HTML entity. |
|---|
| 779 | /x', $str))) { |
|---|
| 780 | ## If ]]> exists in the string, encode the > to >. |
|---|
| 781 | $str = preg_replace('/]]>/', ']]>', $str); |
|---|
| 782 | $str = '<![CDATA[' . $str . ']]>'; |
|---|
| 783 | } else { |
|---|
| 784 | $str = strtr($str, $_encode_xml_Map); |
|---|
| 785 | $str = preg_replace('/&((\#([0-9]+)|\#x([0-9a-fA-F]+)).*?);/', "&$1;", $str); |
|---|
| 786 | } |
|---|
| 787 | return $str; |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | function decode_xml($str) { |
|---|
| 791 | if (preg_match('/<!\[CDATA\[(.*?)]]>/', $str)) { |
|---|
| 792 | $str = preg_replace('/<!\[CDATA\[(.*?)]]>/', '\1', $str); |
|---|
| 793 | ## Decode encoded ]]> |
|---|
| 794 | $str = preg_replace('/]]&(gt|#62);/', ']]>', $str); |
|---|
| 795 | } else { |
|---|
| 796 | global $_encode_xml_Map; |
|---|
| 797 | $str = strtr($str, array_flip($_encode_xml_Map)); |
|---|
| 798 | } |
|---|
| 799 | return $str; |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | function encode_js($str) { |
|---|
| 803 | if (!isset($str)) return ''; |
|---|
| 804 | $str = preg_replace('!\\\\!', '\\\\', $str); |
|---|
| 805 | $str = preg_replace('!>!', '\\>', $str); |
|---|
| 806 | $str = preg_replace('!<!', '\\<', $str); |
|---|
| 807 | $str = preg_replace('!(s)(cript)!i', '$1\\\\$2', $str); |
|---|
| 808 | $str = preg_replace('!</!', '<\\/', $str); # </ is supposed to be the end of Javascript (</script in most UA) |
|---|
| 809 | $str = preg_replace('!\'!', '\\\'', $str); |
|---|
| 810 | $str = preg_replace('!"!', '\\"', $str); |
|---|
| 811 | $str = preg_replace('!\n!', '\\n', $str); |
|---|
| 812 | $str = preg_replace('!\f!', '\\f', $str); |
|---|
| 813 | $str = preg_replace('!\r!', '\\r', $str); |
|---|
| 814 | $str = preg_replace('!\t!', '\\t', $str); |
|---|
| 815 | return $str; |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | function gmtime($ts = null) { |
|---|
| 819 | if (!isset($ts)) { |
|---|
| 820 | $ts = time(); |
|---|
| 821 | } |
|---|
| 822 | $offset = date('Z', $ts); |
|---|
| 823 | $ts -= $offset; |
|---|
| 824 | $tsa = localtime($ts); |
|---|
| 825 | $tsa[8] = 0; |
|---|
| 826 | return $tsa; |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | function is_hash($array) { |
|---|
| 830 | if ( is_array($array) ) { |
|---|
| 831 | if ( array_keys($array) === range(0, count($array) - 1) ) { |
|---|
| 832 | // 0,1,2,3... must be an array |
|---|
| 833 | return false; |
|---|
| 834 | } |
|---|
| 835 | return true; |
|---|
| 836 | } |
|---|
| 837 | return false; |
|---|
| 838 | } |
|---|
| 839 | |
|---|
| 840 | function offset_time_list($ts, $blog = null, $dir = null) { |
|---|
| 841 | return gmtime(offset_time($ts, $blog, $dir)); |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | function strip_hyphen($s) { |
|---|
| 845 | return preg_replace('/-+/', '-', $s); |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | function first_n_words($text, $n) { |
|---|
| 849 | $text = strip_tags($text); |
|---|
| 850 | $words = preg_split('/\s+/', $text); |
|---|
| 851 | $max = count($words) > $n ? $n : count($words); |
|---|
| 852 | return join(' ', array_slice($words, 0, $max)); |
|---|
| 853 | } |
|---|
| 854 | |
|---|
| 855 | function html_text_transform($str = '') { |
|---|
| 856 | $paras = preg_split('/\r?\n\r?\n/', $str); |
|---|
| 857 | if ($str == '') { |
|---|
| 858 | return ''; |
|---|
| 859 | } |
|---|
| 860 | foreach ($paras as $k => $p) { |
|---|
| 861 | if (!preg_match('/^<\/?(?:h1|h2|h3|h4|h5|h6|table|ol|dl|ul|menu|dir|p|pre|center|form|select|fieldset|blockquote|address|div|hr)/', $p)) { |
|---|
| 862 | $p = preg_replace('/\r?\n/', "<br />\n", $p); |
|---|
| 863 | $p = "<p>$p</p>"; |
|---|
| 864 | $paras[$k] = $p; |
|---|
| 865 | } |
|---|
| 866 | } |
|---|
| 867 | return implode("\n\n", $paras); |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | function encode_html($str, $quote_style = ENT_COMPAT) { |
|---|
| 871 | if (!isset($str)) return ''; |
|---|
| 872 | $trans_table = get_html_translation_table(HTML_SPECIALCHARS, $quote_style); |
|---|
| 873 | if( $trans_table["'"] != ''' ) { # some versions of PHP match single quotes to ' |
|---|
| 874 | $trans_table["'"] = '''; |
|---|
| 875 | } |
|---|
| 876 | return (strtr($str, $trans_table)); |
|---|
| 877 | } |
|---|
| 878 | |
|---|
| 879 | function decode_html($str, $quote_style = ENT_COMPAT) { |
|---|
| 880 | if (!isset($str)) return ''; |
|---|
| 881 | $trans_table = get_html_translation_table(HTML_SPECIALCHARS, $quote_style); |
|---|
| 882 | if( $trans_table["'"] != ''' ) { # some versions of PHP match single quotes to ' |
|---|
| 883 | $trans_table["'"] = '''; |
|---|
| 884 | } |
|---|
| 885 | return (strtr($str, array_flip($trans_table))); |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | function get_category_context(&$ctx, $class = 'category') { |
|---|
| 889 | # Get our hands on the category for the current context |
|---|
| 890 | # Either in MTCategories, a Category Archive Template |
|---|
| 891 | # Or the category for the current entry |
|---|
| 892 | $cat = $ctx->stash('category') or |
|---|
| 893 | $ctx->stash('archive_category'); |
|---|
| 894 | if (!isset($cat)) { |
|---|
| 895 | # No category found so far, test the entry |
|---|
| 896 | if ($ctx->stash('entry')) { |
|---|
| 897 | $entry = $ctx->stash('entry'); |
|---|
| 898 | if (empty($entry['placement_category_id'])) |
|---|
| 899 | return null; |
|---|
| 900 | if ($class == 'folder') |
|---|
| 901 | $cat = $ctx->mt->db->fetch_folder($entry['placement_category_id']); |
|---|
| 902 | else |
|---|
| 903 | $cat = $ctx->mt->db->fetch_category($entry['placement_category_id']); |
|---|
| 904 | |
|---|
| 905 | # Return empty string if entry has no category |
|---|
| 906 | # as the tag has been used in the correct context |
|---|
| 907 | # but there is no category to work with |
|---|
| 908 | if (!isset($cat)) { |
|---|
| 909 | return null; |
|---|
| 910 | } |
|---|
| 911 | } else { |
|---|
| 912 | $tag = $ctx->this_tag(); |
|---|
| 913 | return $ctx->error("$tag must be used in a category context"); |
|---|
| 914 | } |
|---|
| 915 | } |
|---|
| 916 | return $cat; |
|---|
| 917 | } |
|---|
| 918 | |
|---|
| 919 | function munge_comment($text, $blog) { |
|---|
| 920 | if (!$blog['blog_allow_comment_html']) { |
|---|
| 921 | $text = strip_tags($text); |
|---|
| 922 | } |
|---|
| 923 | if ($blog['blog_autolink_urls']) { |
|---|
| 924 | $text = preg_replace('!(^|\s|>)(https?://[^\s<]+)!s', '$1<a href="$2">$2</a>', $text); |
|---|
| 925 | } |
|---|
| 926 | return $text; |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | function length_text($text) { |
|---|
| 930 | if (!extension_loaded('mbstring')) { |
|---|
| 931 | $len = strlen($text); |
|---|
| 932 | } else { |
|---|
| 933 | $len = mb_strlen($text); |
|---|
| 934 | } |
|---|
| 935 | return $len; |
|---|
| 936 | } |
|---|
| 937 | |
|---|
| 938 | function substr_text($text, $startpos, $length) { |
|---|
| 939 | if (!extension_loaded('mbstring')) { |
|---|
| 940 | $text = substr($text, $startpos, $length); |
|---|
| 941 | } else { |
|---|
| 942 | $text = mb_substr($text, $startpos, $length); |
|---|
| 943 | } |
|---|
| 944 | return $text; |
|---|
| 945 | } |
|---|
| 946 | |
|---|
| 947 | function first_n_text($text, $n) { |
|---|
| 948 | if (!isset($lang) || empty($lang)) { |
|---|
| 949 | global $mt; |
|---|
| 950 | $lang = ($blog && $blog['blog_language'] ? $blog['blog_language'] : |
|---|
| 951 | $mt->config('DefaultLanguage')); |
|---|
| 952 | } |
|---|
| 953 | if ($lang == 'jp') { |
|---|
| 954 | $lang = 'ja'; |
|---|
| 955 | } |
|---|
| 956 | |
|---|
| 957 | if ($lang == 'ja') { |
|---|
| 958 | $text = strip_tags($text); |
|---|
| 959 | $text = preg_replace('/\r?\n/', " ", $text); |
|---|
| 960 | return substr_text($text, 0, $n); |
|---|
| 961 | }else{ |
|---|
| 962 | return first_n_words($text, $n); |
|---|
| 963 | } |
|---|
| 964 | } |
|---|
| 965 | |
|---|
| 966 | function tag_split_delim($delim, $str) { |
|---|
| 967 | $delim = quotemeta($delim); |
|---|
| 968 | $tags = array(); |
|---|
| 969 | $str = trim($str); |
|---|
| 970 | while (strlen($str) && (preg_match("/^(((['\"])(.*?)\3[^$delim]*?|.*?)($delim\s*|$))/s", $str, $match))) { |
|---|
| 971 | $str = substr($str, strlen($match[1])); |
|---|
| 972 | $tag = (isset($match[4]) && $match[4] != '') ? $match[4] : $match[2]; |
|---|
| 973 | $tag = trim($tag); |
|---|
| 974 | $tag = preg_replace('/\s+/', ' ', $tag); |
|---|
| 975 | $n8d_tag = tag_normalize($tag); |
|---|
| 976 | if ($n8d_tag != '') |
|---|
| 977 | if ($tag != '') $tags[] = $tag; |
|---|
| 978 | } |
|---|
| 979 | return $tags; |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | function tag_split($str) { |
|---|
| 983 | return tag_split_delim(',', $str); |
|---|
| 984 | } |
|---|
| 985 | |
|---|
| 986 | function catarray_path_length_sort($a, $b) { |
|---|
| 987 | $al = strlen($a['category_label_path']); |
|---|
| 988 | $bl = strlen($b['category_label_path']); |
|---|
| 989 | return $al == $bl ? 0 : $al < $bl ? 1 : -1; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | # sorts by length of category label, from longest to shortest |
|---|
| 993 | function catarray_length_sort($a, $b) { |
|---|
| 994 | $al = strlen($a['category_label']); |
|---|
| 995 | $bl = strlen($b['category_label']); |
|---|
| 996 | return $al == $bl ? 0 : $al < $bl ? 1 : -1; |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | function create_expr_exception($m) { |
|---|
| 1000 | if ($m[2]) |
|---|
| 1001 | return '(0)'; |
|---|
| 1002 | else |
|---|
| 1003 | return $m[1]; |
|---|
| 1004 | } |
|---|
| 1005 | |
|---|
| 1006 | function create_cat_expr_function($expr, &$cats, $param) { |
|---|
| 1007 | global $mt; |
|---|
| 1008 | $cats_used = array(); |
|---|
| 1009 | $orig_expr = $expr; |
|---|
| 1010 | |
|---|
| 1011 | $include_children = $param['children'] ? 1 : 0; |
|---|
| 1012 | $cats_used = array(); |
|---|
| 1013 | |
|---|
| 1014 | if (preg_match('/\//', $expr)) { |
|---|
| 1015 | foreach ($cats as $id => $cat) { |
|---|
| 1016 | $catp = category_label_path($cat); |
|---|
| 1017 | $cats[$id]['category_label_path'] = $catp; |
|---|
| 1018 | } |
|---|
| 1019 | $cols = array('category_label_path', 'category_label'); |
|---|
| 1020 | } else { |
|---|
| 1021 | $cols = array('category_label'); |
|---|
| 1022 | } |
|---|
| 1023 | foreach ($cols as $col) { |
|---|
| 1024 | if ($col == 'category_label_path') { |
|---|
| 1025 | usort($cats, 'catarray_path_length_sort'); |
|---|
| 1026 | } else { |
|---|
| 1027 | usort($cats, 'catarray_length_sort'); |
|---|
| 1028 | } |
|---|
| 1029 | $cats_replaced = array(); |
|---|
| 1030 | foreach ($cats as $cat) { |
|---|
| 1031 | $catl = $cat[$col]; |
|---|
| 1032 | $catid = $cat['category_id']; |
|---|
| 1033 | $catre = preg_quote($catl, "/"); |
|---|
| 1034 | if (!preg_match("/(?:(?<![#\d])\[$catre\]|$catre)|(?:#$catid\b)/", $expr)) |
|---|
| 1035 | continue; |
|---|
| 1036 | if ($include_children) { |
|---|
| 1037 | $kids = array($cat); |
|---|
| 1038 | $child_cats = array(); |
|---|
| 1039 | while ($c = array_shift($kids)) { |
|---|
| 1040 | $child_cats[$c['category_id']] = $c; |
|---|
| 1041 | $children = $mt->db->fetch_categories(array('category_id' => $c['category_id'], 'children' => 1, 'show_empty' => 1, 'class' => $c['category_class'])); |
|---|
| 1042 | if ($children) { |
|---|
| 1043 | foreach ($children as $child) { |
|---|
| 1044 | $kids[] = $child; |
|---|
| 1045 | } |
|---|
| 1046 | } |
|---|
| 1047 | } |
|---|
| 1048 | $repl = ''; |
|---|
| 1049 | foreach ($child_cats as $ccid => $cc) { |
|---|
| 1050 | $repl .= '||#' . $ccid; |
|---|
| 1051 | } |
|---|
| 1052 | if (strlen($repl)) $repl = substr($repl, 2); |
|---|
| 1053 | $repl = '(' . $repl . ')'; |
|---|
| 1054 | } else { |
|---|
| 1055 | $repl = "(#$catid)"; |
|---|
| 1056 | } |
|---|
| 1057 | if (isset($cats_replaced[$catl])) { |
|---|
| 1058 | $last_catid = $cats_replaced[$catl]; |
|---|
| 1059 | $expr = preg_replace("/(#$last_catid\b)/", '($1 || #' . $catid . ')', $expr); |
|---|
| 1060 | } else { |
|---|
| 1061 | $expr = preg_replace("/(?:(?<!#)(?:\[$catre\]|$catre))|#$catid\b/", $repl, |
|---|
| 1062 | $expr); |
|---|
| 1063 | $cats_replaced[$catl] = $catid; |
|---|
| 1064 | } |
|---|
| 1065 | if ($include_children) { |
|---|
| 1066 | foreach ($child_cats as $ccid => $cc) |
|---|
| 1067 | $cats_used[$ccid] = $cc; |
|---|
| 1068 | } else { |
|---|
| 1069 | $cats_used[$catid] = $cat; |
|---|
| 1070 | } |
|---|
| 1071 | } |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | $expr = preg_replace('/\bAND\b/i', '&&', $expr); |
|---|
| 1075 | $expr = preg_replace('/\bOR\b/i', '||', $expr); |
|---|
| 1076 | $expr = preg_replace('/\bNOT\b/i', '!', $expr); |
|---|
| 1077 | $expr = preg_replace_callback('/( |#\d+|&&|\|\||!|\(|\))|([^#0-9&|!()]+)/', 'create_expr_exception', $expr); |
|---|
| 1078 | |
|---|
| 1079 | # strip out all the 'ok' stuff. if anything is left, we have |
|---|
| 1080 | # some invalid data in our expression: |
|---|
| 1081 | $test_expr = preg_replace('/!|&&|\|\||\(0\)|\(|\)|\s|#\d+/', '', $expr); |
|---|
| 1082 | if ($test_expr != '') { |
|---|
| 1083 | echo "Invalid category filter: $orig_expr"; |
|---|
| 1084 | return; |
|---|
| 1085 | } |
|---|
| 1086 | if (!preg_match('/!/', $expr)) |
|---|
| 1087 | $cats = array_values($cats_used); |
|---|
| 1088 | |
|---|
| 1089 | $expr = preg_replace('/#(\d+)/', "array_key_exists('\\1', \$pm)", $expr); |
|---|
| 1090 | $expr = '$pm = array_key_exists($e["entry_id"], $c["p"]) ? $c["p"][$e["entry_id"]] : array(); return (' . $expr . ');'; |
|---|
| 1091 | $fn = create_function('&$e,&$c', $expr); |
|---|
| 1092 | if ($fn === FALSE) { |
|---|
| 1093 | echo "Invalid category filter: $orig_expr"; |
|---|
| 1094 | return; |
|---|
| 1095 | } |
|---|
| 1096 | return $fn; |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | function category_label_path($cat) { |
|---|
| 1100 | global $mt; |
|---|
| 1101 | $mtdb =& $mt->db; |
|---|
| 1102 | if (isset($cat['__label_path'])) |
|---|
| 1103 | return $cat['__label_path']; |
|---|
| 1104 | $result = preg_match('/\//', $cat['category_label']) ? '[' . $cat['category_label'] . ']' : $cat['category_label']; |
|---|
| 1105 | while ($cat) { |
|---|
| 1106 | $cat = $cat['category_parent'] ? $mtdb->fetch_category($cat['category_parent']) : null; |
|---|
| 1107 | if ($cat) |
|---|
| 1108 | $result = (preg_match('/\//', $cat['category_label']) ? '[' . $cat['category_label'] . ']' : $cat['category_label']) . '/' . $result; |
|---|
| 1109 | } |
|---|
| 1110 | # caching this information may be problematic IF |
|---|
| 1111 | # parent category labels are changed. |
|---|
| 1112 | $cat['__label_path'] = $result; |
|---|
| 1113 | return $result; |
|---|
| 1114 | } |
|---|
| 1115 | |
|---|
| 1116 | function cat_path_to_category($path, $blogs = null, $class = 'category') { |
|---|
| 1117 | global $mt; |
|---|
| 1118 | if (!$blogs) |
|---|
| 1119 | $blogs = array('include_blogs' => $mt->blog_id); |
|---|
| 1120 | if (!is_array($blogs)) |
|---|
| 1121 | $blogs = array($blogs); |
|---|
| 1122 | $mtdb =& $mt->db; |
|---|
| 1123 | if (preg_match_all('/(\[[^]]+?\]|[^]\/]+)/', $path, $matches)) { |
|---|
| 1124 | # split on slashes, fields quoted by [] |
|---|
| 1125 | $cat_path = $matches[1]; |
|---|
| 1126 | for ($i = 0; $i < count($cat_path); $i++) { |
|---|
| 1127 | $cat_path[$i] = preg_replace('/^\[(.*)\]$/', '\1', $cat_path[$i]); # remove any [] |
|---|
| 1128 | } |
|---|
| 1129 | $last_cat_ids = array(0); |
|---|
| 1130 | foreach ($cat_path as $label) { |
|---|
| 1131 | $cats = $mtdb->fetch_categories(array_merge($blogs, array('label' => $label, 'parent' => $last_cat_ids, 'show_empty' => 1, 'class' => $class))); |
|---|
| 1132 | if (!$cats) |
|---|
| 1133 | break; |
|---|
| 1134 | $last_cat_ids = array(); |
|---|
| 1135 | foreach ($cats as $cat) |
|---|
| 1136 | $last_cat_ids[] = $cat['category_id']; |
|---|
| 1137 | } |
|---|
| 1138 | } |
|---|
| 1139 | if ($cats) |
|---|
| 1140 | return $cats; |
|---|
| 1141 | if (!$cats && $path) { |
|---|
| 1142 | $cats = $mtdb->fetch_categories(array_merge($blogs, array('label' => $path, 'show_empty' => 1, 'class' => $class))); |
|---|
| 1143 | if ($cats) |
|---|
| 1144 | return $cats; |
|---|
| 1145 | } |
|---|
| 1146 | return null; |
|---|
| 1147 | } |
|---|
| 1148 | |
|---|
| 1149 | # sorts by length of tag name, from longest to shortest |
|---|
| 1150 | function tagarray_name_sort($a, $b) { |
|---|
| 1151 | return strcmp($a['tag_name'], $b['tag_name']); |
|---|
| 1152 | } |
|---|
| 1153 | |
|---|
| 1154 | function tagarray_length_sort($a, $b) { |
|---|
| 1155 | $al = strlen($a['tag_name']); |
|---|
| 1156 | $bl = strlen($b['tag_name']); |
|---|
| 1157 | return $al == $bl ? 0 : $al < $bl ? 1 : -1; |
|---|
| 1158 | } |
|---|
| 1159 | |
|---|
| 1160 | function create_tag_expr_function($expr, &$tags, $datasource = 'entry') { |
|---|
| 1161 | $tags_used = array(); |
|---|
| 1162 | $orig_expr = $expr; |
|---|
| 1163 | |
|---|
| 1164 | # Sort in descending order by length |
|---|
| 1165 | usort($tags, 'tagarray_length_sort'); |
|---|
| 1166 | |
|---|
| 1167 | # Modify the tag argument, replacing the tag name with '#TagID' |
|---|
| 1168 | # Create a ID-based hash of the tags that are used in the arg |
|---|
| 1169 | foreach ($tags as $tag) { |
|---|
| 1170 | $tagn = $tag['tag_name']; |
|---|
| 1171 | $tagid = $tag['tag_id']; |
|---|
| 1172 | $oldexpr = $expr; |
|---|
| 1173 | $expr = preg_replace("!(?:\Q[$tagn]\E|\Q$tagn\E)!", "#$tagid", |
|---|
| 1174 | $expr); |
|---|
| 1175 | if ($oldexpr != $expr) |
|---|
| 1176 | $tags_used[$tagid] = $tag; |
|---|
| 1177 | } |
|---|
| 1178 | |
|---|
| 1179 | # Replace logical constructs with their PHP equivalents |
|---|
| 1180 | $expr = preg_replace('/\bAND\b/i', '&&', $expr); |
|---|
| 1181 | $expr = preg_replace('/\bOR\b/i', '||', $expr); |
|---|
| 1182 | $expr = preg_replace('/\bNOT\b/i', '!', $expr); |
|---|
| 1183 | |
|---|
| 1184 | # The following is no more readable in PHP than it is in Perl |
|---|
| 1185 | $expr = preg_replace_callback('/( |\#\d+|&&|\|\||!|\(|\))|([^#&|!()]+)/', 'create_expr_exception', $expr); |
|---|
| 1186 | |
|---|
| 1187 | # Syntax check on 'tag' argument |
|---|
| 1188 | # Strip out all the valid stuff. if anything is left, we have |
|---|
| 1189 | # some invalid data in our expression |
|---|
| 1190 | $test_expr = preg_replace('/!|&&|\|\||\(0\)|\(|\)|\s|#\d+/', '', $expr); |
|---|
| 1191 | if ($test_expr != '') { |
|---|
| 1192 | echo "Invalid tag filter: $orig_expr"; |
|---|
| 1193 | return; |
|---|
| 1194 | } |
|---|
| 1195 | |
|---|
| 1196 | # Populate array (passed in by reference) of used tags |
|---|
| 1197 | $tags = array_values($tags_used); |
|---|
| 1198 | |
|---|
| 1199 | # Replace '#TagID' with a hash lookup function. |
|---|
| 1200 | # Function confirms/denies use of tag on entry (by IDs) |
|---|
| 1201 | $column_name = $datasource . '_id'; |
|---|
| 1202 | $expr = preg_replace('/#(\d+)/', "array_key_exists('\\1', \$tm)", $expr); |
|---|
| 1203 | |
|---|
| 1204 | # Create a PHP-blessed function of that code and return it |
|---|
| 1205 | # if all is well. This function will be used later to |
|---|
| 1206 | # test for existence of specified tags in entries. |
|---|
| 1207 | $expr = '$tm = array_key_exists($e["'.$datasource.'_id"], $c["t"]) ? $c["t"][$e["'.$datasource.'_id"]] : array(); return ' . $expr . |
|---|
| 1208 | ';'; |
|---|
| 1209 | $fn = create_function('&$e,&$c', $expr); |
|---|
| 1210 | if ($fn === FALSE) { |
|---|
| 1211 | echo "Invalid tag filter: $orig_expr"; |
|---|
| 1212 | return; |
|---|
| 1213 | } |
|---|
| 1214 | return $fn; |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | function tag_normalize($str) { |
|---|
| 1218 | # FIXME: character set issues here... |
|---|
| 1219 | $private = preg_match('/^@/', $str) ? 1 : 0; |
|---|
| 1220 | $str = preg_replace('/[@!`\\<>\*&#\/~\?\'"\.\,=\(\)\${}\[\];:\ \+\-\r\n]+/', '', $str); |
|---|
| 1221 | $str = strtolower($str); |
|---|
| 1222 | if ($private) $str = '@' . $str; |
|---|
| 1223 | return $str; |
|---|
| 1224 | } |
|---|
| 1225 | |
|---|
| 1226 | function static_path($host) { |
|---|
| 1227 | global $mt; |
|---|
| 1228 | $path = $mt->config('StaticWebPath'); |
|---|
| 1229 | if (!$path) { |
|---|
| 1230 | $path = $mt->config('CGIPath'); |
|---|
| 1231 | if (substr($path, 0, 1) == '/') { # relative |
|---|
| 1232 | if (!preg_match('!/$!', $host)) |
|---|
| 1233 | $host .= '/'; |
|---|
| 1234 | if (preg_match('!^(https?://[^/:]+)(:\d+)?/!', $host, $matches)) { |
|---|
| 1235 | $path = $matches[1] . $path; |
|---|
| 1236 | } |
|---|
| 1237 | } |
|---|
| 1238 | if (substr($path, strlen($path) - 1, 1) != '/') |
|---|
| 1239 | $path .= '/'; |
|---|
| 1240 | $path .= 'mt-static/'; |
|---|
| 1241 | } elseif (substr($path, 0, 1) == '/') { |
|---|
| 1242 | if (!preg_match('!/$!', $host)) |
|---|
| 1243 | $host .= '/'; |
|---|
| 1244 | if (preg_match('!^(https?://[^/:]+)(:\d+)?/!', $host, $matches)) { |
|---|
| 1245 | $path = $matches[1] . $path; |
|---|
| 1246 | } |
|---|
| 1247 | } |
|---|
| 1248 | if (substr($path, strlen($path) - 1, 1) != '/') |
|---|
| 1249 | $path .= '/'; |
|---|
| 1250 | |
|---|
| 1251 | return $path; |
|---|
| 1252 | } |
|---|
| 1253 | |
|---|
| 1254 | function static_file_path() { |
|---|
| 1255 | global $mt; |
|---|
| 1256 | $path = $mt->config('StaticFilePath'); |
|---|
| 1257 | if (!$path) { |
|---|
| 1258 | $path = dirname(dirname(dirname(__FILE__))); |
|---|
| 1259 | $path .= DIRECTORY_SEPARATOR . 'mt-static' . DIRECTORY_SEPARATOR; |
|---|
| 1260 | } |
|---|
| 1261 | if (substr($path, strlen($path) - 1, 1) != DIRECTORY_SEPARATOR) |
|---|
| 1262 | $path .= DIRECTORY_SEPARATOR; |
|---|
| 1263 | |
|---|
| 1264 | return $path; |
|---|
| 1265 | } |
|---|
| 1266 | |
|---|
| 1267 | function asset_path($path, $blog) { |
|---|
| 1268 | $site_path = $blog['blog_site_path']; |
|---|
| 1269 | $site_path = preg_replace('/\/$/', '', $site_path); |
|---|
| 1270 | $path = preg_replace('/^%r/', $site_path, $path); |
|---|
| 1271 | |
|---|
| 1272 | $static_file_path = static_file_path(); |
|---|
| 1273 | $static_file_path = preg_replace('/\/$/', '', $static_file_path); |
|---|
| 1274 | $path = preg_replace('/^%s/', $static_file_path, $path); |
|---|
| 1275 | |
|---|
| 1276 | $archive_path = $blog['blog_archive_path']; |
|---|
| 1277 | if ($archive_path) { |
|---|
| 1278 | $archive_path = preg_replace('/\/$/', '', $archive_path); |
|---|
| 1279 | $path = preg_replace('/^%a/', $archive_path, $path); |
|---|
| 1280 | } |
|---|
| 1281 | |
|---|
| 1282 | return $path; |
|---|
| 1283 | } |
|---|
| 1284 | |
|---|
| 1285 | function userpic_url($asset, $blog, $author) { |
|---|
| 1286 | global $mt; |
|---|
| 1287 | $format = $mt->translate('userpic-[_1]-%wx%h%x', array($author['author_id'])); |
|---|
| 1288 | $max_dim = $mt->config('UserpicThumbnailSize'); |
|---|
| 1289 | |
|---|
| 1290 | # generate thumbnail |
|---|
| 1291 | $src_file = asset_path($asset['asset_file_path'], $blog); |
|---|
| 1292 | |
|---|
| 1293 | $cache_path = $mt->config('AssetCacheDir'); |
|---|
| 1294 | $image_path = $cache_path . DIRECTORY_SEPARATOR . 'userpics'; |
|---|
| 1295 | $static_file_path = static_file_path().'support'; |
|---|
| 1296 | |
|---|
| 1297 | require_once('thumbnail_lib.php'); |
|---|
| 1298 | $thumb = new Thumbnail($src_file); |
|---|
| 1299 | $thumb_w = $max_dim; |
|---|
| 1300 | $thumb_h = $max_dim; |
|---|
| 1301 | $dest; |
|---|
| 1302 | $thumb_name = $static_file_path.DIRECTORY_SEPARATOR.$image_path.DIRECTORY_SEPARATOR.$format; |
|---|
| 1303 | if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $asset['asset_id'], $scale, $thumb_name, 'png')) { |
|---|
| 1304 | return ''; |
|---|
| 1305 | } |
|---|
| 1306 | $basename = basename($dest); |
|---|
| 1307 | |
|---|
| 1308 | $static_path = $mt->config('StaticWebPath'); |
|---|
| 1309 | $static_path = preg_replace('/\/$/', '', $static_path); |
|---|
| 1310 | $static_path .= '/support'; |
|---|
| 1311 | $url = sprintf("%s/%s/%s", $static_path, $image_path, $basename); |
|---|
| 1312 | return $url; |
|---|
| 1313 | } |
|---|
| 1314 | |
|---|
| 1315 | # for compatibility... |
|---|
| 1316 | function make_thumbnail_file($src, $dest, $width, $height, $scale = 0, $dest_type = 'auto', $id = 0) { |
|---|
| 1317 | require_once('thumbnail_lib.php'); |
|---|
| 1318 | $thumb = new Thumbnail($src); |
|---|
| 1319 | |
|---|
| 1320 | $thumb_w = $width; |
|---|
| 1321 | $thumb_h = $height; |
|---|
| 1322 | $thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $id, $scale, null, $dest_type); |
|---|
| 1323 | |
|---|
| 1324 | return array($thumb_w, $thumb_h); |
|---|
| 1325 | } |
|---|
| 1326 | |
|---|
| 1327 | function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h-%i%x') { |
|---|
| 1328 | # Get parameter |
|---|
| 1329 | $site_path = $blog['blog_site_path']; |
|---|
| 1330 | $site_path = preg_replace('/\/$/', '', $site_path); |
|---|
| 1331 | $filename = asset_path($asset['asset_file_path'], $blog); |
|---|
| 1332 | |
|---|
| 1333 | # Retrieve thumbnail |
|---|
| 1334 | global $mt; |
|---|
| 1335 | $path_parts = pathinfo($filename); |
|---|
| 1336 | $cache_path = $mt->config('AssetCacheDir'); |
|---|
| 1337 | |
|---|
| 1338 | $ts = preg_replace('![^0-9]!', '', $asset['asset_created_on']); |
|---|
| 1339 | $date_stamp = format_ts('%Y/%m', $ts, $blog); |
|---|
| 1340 | $base_path = $site_path; |
|---|
| 1341 | if (preg_match('/^%a/', $asset['asset_file_path']) && !empty($blog['blog_archive_path'])) { |
|---|
| 1342 | $base_path = $blog['blog_archive_path']; |
|---|
| 1343 | $base_path = preg_replace('/\/$/', '', $base_path); |
|---|
| 1344 | } |
|---|
| 1345 | |
|---|
| 1346 | $cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR; |
|---|
| 1347 | $thumb_name = $cache_dir . $format; |
|---|
| 1348 | |
|---|
| 1349 | # generate thumbnail |
|---|
| 1350 | require_once('thumbnail_lib.php'); |
|---|
| 1351 | $thumb = new Thumbnail($filename); |
|---|
| 1352 | $thumb_w = $width; |
|---|
| 1353 | $thumb_h = $height; |
|---|
| 1354 | $dest; |
|---|
| 1355 | if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $asset['asset_id'], $scale, $thumb_name)) { |
|---|
| 1356 | return ''; |
|---|
| 1357 | } |
|---|
| 1358 | |
|---|
| 1359 | # make url |
|---|
| 1360 | $basename = basename($dest); |
|---|
| 1361 | $base_url = $blog['blog_site_url']; |
|---|
| 1362 | if (preg_match('/^%a/', $asset['asset_file_path']) && !empty($blog['blog_archive_url'])) |
|---|
| 1363 | $base_url = $blog['blog_archive_url']; |
|---|
| 1364 | if (!preg_match('!/$!', $base_url)) |
|---|
| 1365 | $base_url .= '/'; |
|---|
| 1366 | |
|---|
| 1367 | $thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename; |
|---|
| 1368 | |
|---|
| 1369 | return array($thumb_url, $thumb_w, $thumb_h, $thumb_name); |
|---|
| 1370 | } |
|---|
| 1371 | |
|---|
| 1372 | function asset_cleanup($str) { |
|---|
| 1373 | $str = preg_replace_callback('/<(?:[Ff][Oo][Rr][Mm]|[Ss][Pp][Aa][Nn])([^>]*?)\smt:asset-id="\d+"([^>]+?>)(.*?)<\/(?:[Ff][Oo][Rr][Mm]|[Ss][Pp][Aa][Nn])>/s', 'asset_cleanup_cb', $str); |
|---|
| 1374 | return $str; |
|---|
| 1375 | } |
|---|
| 1376 | |
|---|
| 1377 | function asset_cleanup_cb($matches) { |
|---|
| 1378 | $attr = $matches[1] . $matches[2]; |
|---|
| 1379 | $inner = $matches[3]; |
|---|
| 1380 | $attr = preg_replace('/\s[Cc][Oo][Nn][Tt][Ee][Nn][Tt][Ee][Dd][Ii][Tt][Aa][Bb][Ll][Ee]=([\'"][^\'"]*?[\'"]|[Ff][Aa][Ll][Ss][Ee])/', '', $attr); |
|---|
| 1381 | return '<span' . $attr . $inner . '</span>'; |
|---|
| 1382 | } |
|---|
| 1383 | |
|---|
| 1384 | function create_role_expr_function($expr, &$roles, $datasource = 'author') { |
|---|
| 1385 | $roles_used = array(); |
|---|
| 1386 | $orig_expr = $expr; |
|---|
| 1387 | |
|---|
| 1388 | $expr = preg_replace('/,/i', ' OR ', $expr); |
|---|
| 1389 | |
|---|
| 1390 | foreach ($roles as $role) { |
|---|
| 1391 | $rolen = $role['role_name']; |
|---|
| 1392 | $roleid = $role['role_id']; |
|---|
| 1393 | $oldexpr = $expr; |
|---|
| 1394 | $expr = preg_replace("!(?:\Q[$rolen]\E|\Q$rolen\E)!", "#$roleid", $expr); |
|---|
| 1395 | if ($oldexpr != $expr) |
|---|
| 1396 | $roles_used[$roleid] = $role; |
|---|
| 1397 | } |
|---|
| 1398 | |
|---|
| 1399 | $expr = preg_replace('/\bOR\b/i', '||', $expr); |
|---|
| 1400 | $expr = preg_replace('/\bAND\b/i', '&&', $expr); |
|---|
| 1401 | $expr = preg_replace('/\bNOT\b/i', '!', $expr); |
|---|
| 1402 | $expr = preg_replace_callback('/( |#\d+|&&|\|\||!|\(|\))|([^#0-9&|!()]+)/', 'create_expr_exception', $expr); |
|---|
| 1403 | |
|---|
| 1404 | $test_expr = preg_replace('/!|&&|\|\||\(0\)|\(|\)|\s|#\d+/', '', $expr); |
|---|
| 1405 | if ($test_expr != '') { |
|---|
| 1406 | echo "Invalid role filter: $orig_expr"; |
|---|
| 1407 | return; |
|---|
| 1408 | } |
|---|
| 1409 | |
|---|
| 1410 | if (!preg_match('/!/', $expr)) |
|---|
| 1411 | $roles = array_values($roles_used); |
|---|
| 1412 | |
|---|
| 1413 | $column_name = $datasource . '_id'; |
|---|
| 1414 | $expr = preg_replace('/#(\d+)/', "array_key_exists('\\1', \$tm)", $expr); |
|---|
| 1415 | |
|---|
| 1416 | $expr = '$tm = array_key_exists($e["'.$datasource.'_id"], $c["r"]) ? $c["r"][$e["'.$datasource.'_id"]] : array(); return ' . $expr . ';'; |
|---|
| 1417 | $fn = create_function('&$e,&$c', $expr); |
|---|
| 1418 | if ($fn === FALSE) { |
|---|
| 1419 | echo "Invalid role filter: $orig_expr"; |
|---|
| 1420 | return; |
|---|
| 1421 | } |
|---|
| 1422 | return $fn; |
|---|
| 1423 | } |
|---|
| 1424 | |
|---|
| 1425 | function create_status_expr_function($expr, &$status, $datasource = 'author') { |
|---|
| 1426 | $orig_expr = $expr; |
|---|
| 1427 | |
|---|
| 1428 | foreach ($status as $s) { |
|---|
| 1429 | $statusn = $s['name']; |
|---|
| 1430 | $statusid = $s['id']; |
|---|
| 1431 | $oldexpr = $expr; |
|---|
| 1432 | $expr = preg_replace("!(?:\Q[$statusn]\E|\Q$statusn\E)!", "#$statusid", $expr); |
|---|
| 1433 | } |
|---|
| 1434 | |
|---|
| 1435 | $expr = preg_replace('/\bOR\b/i', '||', $expr); |
|---|
| 1436 | $expr = preg_replace_callback('/( |#\d+|&&|\|\||!|\(|\))|([^#0-9&|!()]+)/', 'create_expr_exception', $expr); |
|---|
| 1437 | |
|---|
| 1438 | $test_expr = preg_replace('/!|&&|\|\||\(0\)|\(|\)|\s|#\d+/', '', $expr); |
|---|
| 1439 | if ($test_expr != '') { |
|---|
| 1440 | echo "Invalid status filter: $orig_expr"; |
|---|
| 1441 | return; |
|---|
| 1442 | } |
|---|
| 1443 | |
|---|
| 1444 | $expr = preg_replace('/#(\d+)/', '$e["'.$datasource.'_status"] == \\1', $expr); |
|---|
| 1445 | $expr = 'return ' . $expr . ';'; |
|---|
| 1446 | |
|---|
| 1447 | $fn = create_function('&$e,&$c', $expr); |
|---|
| 1448 | if ($fn === FALSE) { |
|---|
| 1449 | echo "Invalid status filter: $orig_expr"; |
|---|
| 1450 | return; |
|---|
| 1451 | } |
|---|
| 1452 | return $fn; |
|---|
| 1453 | } |
|---|
| 1454 | |
|---|
| 1455 | function create_rating_expr_function($expr, $filter, $namespace, $datasource = 'entry') { |
|---|
| 1456 | $orig_expr = $expr; |
|---|
| 1457 | |
|---|
| 1458 | require_once 'rating_lib.php'; |
|---|
| 1459 | $expr = '$ctx = $c; if ($ctx == null) { global $mt; $ctx = $mt->context(); } $old = $ctx->mt->db->result; '; |
|---|
| 1460 | if ($filter == 'min_score') { |
|---|
| 1461 | $expr .= '$ret = score_for($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'") >= '.$orig_expr.';'; |
|---|
| 1462 | } elseif ($filter == 'max_score') { |
|---|
| 1463 | $expr .= '$ret = score_for($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'") <= '.$orig_expr.';'; |
|---|
| 1464 | } elseif ($filter == 'min_rate') { |
|---|
| 1465 | $expr .= '$ret = score_avg($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'") >= '.$orig_expr.';'; |
|---|
| 1466 | } elseif ($filter == 'max_rate') { |
|---|
| 1467 | $expr .= '$ret = score_avg($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'") <= '.$orig_expr.';'; |
|---|
| 1468 | } elseif ($filter == 'min_count') { |
|---|
| 1469 | $expr .= '$ret = score_count($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'") >= '.$orig_expr.';'; |
|---|
| 1470 | } elseif ($filter == 'max_count') { |
|---|
| 1471 | $expr .= '$ret = score_count($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'") <= '.$orig_expr.';'; |
|---|
| 1472 | } elseif ($filter == 'scored_by') { |
|---|
| 1473 | $expr .= '$ret = get_score($ctx, $e["'.$datasource.'_id"], "'.$datasource.'", "'.$namespace.'", '.$orig_expr.') > 0;'; |
|---|
| 1474 | } |
|---|
| 1475 | $expr .= ' $ctx->mt->db->result = $old; return $ret;'; |
|---|
| 1476 | |
|---|
| 1477 | $fn = create_function('&$e,&$c', $expr); |
|---|
| 1478 | if ($fn === FALSE) { |
|---|
| 1479 | echo "Invalid rating filter: $orig_expr"; |
|---|
| 1480 | return; |
|---|
| 1481 | } |
|---|
| 1482 | return $fn; |
|---|
| 1483 | } |
|---|
| 1484 | |
|---|
| 1485 | function _math_operation($op, $lvalue, $rvalue) { |
|---|
| 1486 | if (!preg_match('/^\-?[\d\.]+$/', $lvalue)) |
|---|
| 1487 | return; |
|---|
| 1488 | if ( isset($rvalue) && !preg_match('/^\-?[\d\.]+$/', $rvalue)) |
|---|
| 1489 | return; |
|---|
| 1490 | if ( !isset($rvalue) |
|---|
| 1491 | && $op != 'inc' && $op != 'dec' && $op != '++' && $op != '--' ) |
|---|
| 1492 | return; |
|---|
| 1493 | if ( ( '+' == $op ) || ( 'add' == $op ) ) { |
|---|
| 1494 | return $lvalue + $rvalue; |
|---|
| 1495 | } |
|---|
| 1496 | elseif ( ( '++' == $op ) || ( 'inc' == $op ) ) { |
|---|
| 1497 | return $lvalue + 1; |
|---|
| 1498 | } |
|---|
| 1499 | elseif ( ( '-' == $op ) || ( 'sub' == $op ) ) { |
|---|
| 1500 | return $lvalue - $rvalue; |
|---|
| 1501 | } |
|---|
| 1502 | elseif ( ( '--' == $op ) || ( 'dec' == $op ) ) { |
|---|
| 1503 | return $lvalue - 1; |
|---|
| 1504 | } |
|---|
| 1505 | elseif ( ( '*' == $op ) || ( 'mul' == $op ) ) { |
|---|
| 1506 | return $lvalue * $rvalue; |
|---|
| 1507 | } |
|---|
| 1508 | elseif ( ( '/' == $op ) || ( 'div' == $op ) ) { |
|---|
| 1509 | if ( $rvalue == 0 ) |
|---|
| 1510 | return; |
|---|
| 1511 | return $lvalue / $rvalue; |
|---|
| 1512 | } |
|---|
| 1513 | elseif ( ( '%' == $op ) || ( 'mod' == $op ) ) { |
|---|
| 1514 | // to be in line with perl equivalent |
|---|
| 1515 | $lvalue = floor($lvalue); |
|---|
| 1516 | $rvalue = floor($rvalue); |
|---|
| 1517 | if ( $rvalue == 0 ) |
|---|
| 1518 | return; |
|---|
| 1519 | return $lvalue % $rvalue; |
|---|
| 1520 | } |
|---|
| 1521 | return; |
|---|
| 1522 | } |
|---|
| 1523 | |
|---|
| 1524 | function apply_text_filter ($ctx, $text, $filters) { |
|---|
| 1525 | if ($text == '' || $filters == '') return $text; |
|---|
| 1526 | |
|---|
| 1527 | $f = preg_split('/\s*,\s*/', $filters); |
|---|
| 1528 | if (is_array($f) && count($f) > 0) { |
|---|
| 1529 | foreach ($f as $filter) { |
|---|
| 1530 | if ($filter == '__default__') { |
|---|
| 1531 | $filter = 'convert_breaks'; |
|---|
| 1532 | } |
|---|
| 1533 | if ($filter == 'convert_breaks') { |
|---|
| 1534 | $text = html_text_transform($text); |
|---|
| 1535 | } elseif ($ctx->load_modifier($filter)) { |
|---|
| 1536 | $mod = 'smarty_modifier_'.$filter; |
|---|
| 1537 | $text = $mod($text); |
|---|
| 1538 | } |
|---|
| 1539 | } |
|---|
| 1540 | } |
|---|
| 1541 | |
|---|
| 1542 | return $text; |
|---|
| 1543 | } |
|---|
| 1544 | |
|---|
| 1545 | function get_page_column ($layout) { |
|---|
| 1546 | $columns = 0; |
|---|
| 1547 | if (empty($layout)) return $columns; |
|---|
| 1548 | |
|---|
| 1549 | $columns_map = array( |
|---|
| 1550 | 'layout-wt' => 2, |
|---|
| 1551 | 'layout-tw' => 2, |
|---|
| 1552 | 'layout-wm' => 2, |
|---|
| 1553 | 'layout-mw' => 2, |
|---|
| 1554 | 'layout-wtt' => 3, |
|---|
| 1555 | 'layout-twt' => 3); |
|---|
| 1556 | |
|---|
| 1557 | if(array_key_exists($layout, $columns_map)) |
|---|
| 1558 | $columns = $columns_map[$layout]; |
|---|
| 1559 | |
|---|
| 1560 | return $columns; |
|---|
| 1561 | } |
|---|
| 1562 | |
|---|
| 1563 | function mkpath($path, $mode = 0777) { |
|---|
| 1564 | // PHP5 supports recursive param |
|---|
| 1565 | if (version_compare(PHP_VERSION, '5.0.0', ">=")) |
|---|
| 1566 | return mkdir($path, $mode, true); |
|---|
| 1567 | |
|---|
| 1568 | // for php4 |
|---|
| 1569 | is_dir(dirname($path)) || mkpath(dirname($path), $mode); |
|---|
| 1570 | return is_dir($path) || @mkdir($path, $mode); |
|---|
| 1571 | } |
|---|
| 1572 | |
|---|
| 1573 | ?> |
|---|