📄 mtutil.php
字号:
<?php# Copyright 2001-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: MTUtil.php 11056 2005-04-07 02:07:21Z bchoate $function start_end_ts($ts) { if ($ts) { if (strlen($ts) == 4) { $ts_start = $ts . '0101'; $ts_end = $ts . '1231'; } elseif (strlen($ts) == 6) { $ts_start = $ts . '01'; $ts_end = $ts . sprintf("%02d", days_in(substr($ts, 6,2), substr($ts, 0, 4))); } else { $ts_start = $ts; $ts_end = $ts; } } return array($ts_start . '000000', $ts_end . '235959');}function start_end_month($ts) { $y = substr($ts, 0, 4); $mo = substr($ts, 4, 2); $start = sprintf("%04d%02d01000000", $y, $mo); $end = sprintf("%04d%02d%02d235959", $y, $mo, days_in($mo, $y)); return array($start, $end);}function days_in($m, $y) { return date('t', mktime(0, 0, 0, $m, 1, $y)); #static $Days_In = array( -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); #if ($m != 2) # return $Days_In[intval($m)]; #return $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? # 29 : 28;}function start_end_day($ts) { $day = substr($ts, 0, 8); return array($day . "000000", $day . "235959");}function start_end_year($ts) { $year = substr($ts, 0, 4); return array($year . "0101000000", $year . "1231235959");}function start_end_week($ts) { $y = substr($ts, 0, 4); $mo = substr($ts, 4, 2); $d = substr($ts, 6, 2); $h = substr($ts, 8, 2); $s = substr($ts, 10, 2); $wday = wday_from_ts($y, $mo, $d); list($sd, $sm, $sy) = array($d - $wday, $mo, $y); if ($sd < 1) { $sm--; if ($sm < 1) { $sm = 12; $sy--; } $sd += days_in($sm, $sy); } $start = sprintf("%04d%02d%02d%s", $sy, $sm, $sd, "000000"); list($ed, $em, $ey) = array($d + 6 - $wday, $mo, $y); if ($ed > days_in($em, $ey)) { $ed -= days_in($em, $ey); $em++; if ($em > 12) { $em = 1; $ey++; } } $end = sprintf("%04d%02d%02d%s", $ey, $em, $ed, "235959"); return array($start, $end);}global $In_Year;$In_Year = array( array( 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 ), array( 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 ),);function week2ymd($y, $week) { $tstamp = strtotime('+' . $week-1 . ' week',mktime(0,0,0,1,1,$y)); $tsa = localtime($tstamp); return array($tsa[5]+1900, $tsa[4]+1, $tsa[3]);}function wday_from_ts($y, $m, $d) { global $In_Year; $leap = $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? 1 : 0; $y--; ## Copied from Date::Calc. $days = $y * 365; $days += $y >>= 2; $days -= intval($y /= 25); $days += $y >> 2; $days += $In_Year[$leap][$m-1] + $d; return $days % 7;}function yday_from_ts($y, $m, $d) { global $In_Year; $leap = $y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? 1 : 0; return $In_Year[$leap][$m-1] + $d;}function substr_wref($str, $start, $length) { if (preg_match_all('/(&[^;]*;|.)/', $str, $character_entities)) { return implode('', array_slice($character_entities[0], $start, $length)); } else { return ''; }}function format_ts($format, $ts, $blog, $lang = null) { global $Languages; if (!isset($lang) || empty($lang)) { $lang = ($blog && $blog['blog_language'] ? $blog['blog_language'] : 'en'); } if (!isset($format) || empty($format)) { if (count($Languages[$lang]) >= 4) $format = $Languages[$lang][3]; $format or $format = "%B %e, %Y %I:%M %p"; } global $_format_ts_cache; if (!isset($_format_ts_cache)) { $_format_ts_cache = array(); } if (isset($_format_ts_cache[$ts.$lang])) { $f = $_format_ts_cache[$ts.$lang]; } else { $L = $Languages[$lang]; $tsa = array(substr($ts, 0, 4), substr($ts, 4, 2), substr($ts, 6, 2), substr($ts, 8, 2), substr($ts, 10, 2), substr($ts, 12, 2)); list($f['Y'], $f['m'], $f['d'], $f['H'], $f['M'], $f['S']) = $tsa; $f['w'] = wday_from_ts($tsa[0],$tsa[1],$tsa[2]); $f['j'] = yday_from_ts($tsa[0],$tsa[1],$tsa[2]); $f['y'] = substr($f['Y'], 2); $f['b'] = substr_wref($L[1][$f['m']-1], 0, 3); $f['B'] = $L[1][$f['m']-1]; $f['a'] = substr_wref($L[0][$f['w']], 0, 3); $f['A'] = $L[0][$f['w']]; $f['e'] = $f['d']; $f['e'] = preg_replace('!^0!', ' ', $f['e']); $f['I'] = $f['H']; if ($f['I'] > 12) { $f['I'] -= 12; $f['p'] = $L[2][1]; } elseif ($f['I'] == 0) { $f['I'] = 12; $f['p'] = $L[2][0]; } elseif ($f['I'] == 12) { $f['p'] = $L[2][1]; } else { $f['p'] = $L[2][0]; } $f['I'] = sprintf("%02d", $f['I']); $f['k'] = $f['H']; $f['k'] = preg_replace('!^0!', ' ', $f['k']); $f['l'] = $f['I']; $f['l'] = preg_replace('!^0!', ' ', $f['l']); $f['j'] = sprintf("%03d", $f['j']); $f['Z'] = ''; $_format_ts_cache[$ts . $lang] = $f; } $date_format = null; if (count($Languages[$lang]) >= 5) $date_format = $Languages[$lang][4]; $date_format or $date_format = "%B %d, %Y"; $time_format = null; if (count($Languages[$lang]) >= 6) $time_format = $Languages[$lang][5]; $time_format or $time_format = "%I:%M %p"; $format = preg_replace('!%x!', $date_format, $format); $format = preg_replace('!%X!', $time_format, $format); ## This is a dreadful hack. I can't think of a good format specifier ## for "%B %Y" (which is used for monthly archives, for example) so ## I'll just hardcode this, for Japanese dates. if ($lang == 'jp') { if (count($Languages[$lang]) >= 7) $format = preg_replace('!%B %Y!', $Languages[$lang][6], $format); } if (isset($format)) { $format = preg_replace('!%(\w)!e', '\$f[\'\1\']', $format); } return $format;}function dirify($s) { global $mt; $charset = $mt->config['PublishCharset']; if ($charset == 'utf-8') { return utf8_dirify($s); } else { return iso_dirify($s); }}function utf8_dirify($s) { $s = xliterate_utf8($s); ## convert high-ASCII chars to 7bit. $s = strtolower($s); ## lower-case. $s = strip_tags($s); ## remove HTML tags. $s = preg_replace('!&[^;\s]+;!', '', $s); ## remove HTML entities. $s = preg_replace('![^\w\s]!', '', $s); ## remove non-word/space chars. $s = str_replace(' ','_',$s); ## change space chars to underscores. return($s);}global $Utf8_ASCII;$Utf8_ASCII = array( "\xc3\x80" => 'A', # A` "\xc3\xa0" => 'a', # a` "\xc3\x81" => 'A', # A' "\xc3\xa1" => 'a', # a' "\xc3\x82" => 'A', # A^ "\xc3\xa2" => 'a', # a^ "\xc3\x84" => 'Ae', # A: "\xc3\xa4" => 'ae', # a: "\xc3\x83" => 'A', # A~ "\xc3\xa3" => 'a', # a~ "\xc3\x88" => 'E', # E` "\xc3\xa8" => 'e', # e` "\xc3\x89" => 'E', # E' "\xc3\xa9" => 'e', # e' "\xc3\x8a" => 'E', # E^ "\xc3\xaa" => 'e', # e^ "\xc3\x8b" => 'Ee', # E: "\xc3\xab" => 'ee', # e: "\xc3\x8c" => 'I', # I` "\xc3\xac" => 'i', # i` "\xc3\x8d" => 'I', # I' "\xc3\xad" => 'i', # i' "\xc3\x8e" => 'I', # I^ "\xc3\xae" => 'i', # i^ "\xc3\x8f" => 'Ie', # I: "\xc3\xaf" => 'ie', # i: "\xc3\x92" => 'O', # O` "\xc3\xb2" => 'o', # o` "\xc3\x93" => 'O', # O' "\xc3\xb3" => 'o', # o' "\xc3\x94" => 'O', # O^ "\xc3\xb4" => 'o', # o^ "\xc3\x96" => 'Oe', # O: "\xc3\xb6" => 'oe', # o: "\xc3\x95" => 'O', # O~ "\xc3\xb5" => 'o', # o~ "\xc3\x98" => 'Oe', # O/ "\xc3\xb8" => 'oe', # o/ "\xc3\x99" => 'U', # U` "\xc3\xb9" => 'u', # u` "\xc3\x9a" => 'U', # U' "\xc3\xba" => 'u', # u' "\xc3\x9b" => 'U', # U^ "\xc3\xbb" => 'u', # u^ "\xc3\x9c" => 'Ue', # U: "\xc3\xbc" => 'ue', # u: "\xc3\x87" => 'C', # ,C "\xc3\xa7" => 'c', # ,c "\xc3\x91" => 'N', # N~ "\xc3\xb1" => 'n', # n~ "\xc3\x9f" => 'ss', # double-s);function xliterate_utf8($s) { global $Utf8_ASCII; return strtr($s, $Utf8_ASCII);}function iso_dirify($s) { $s = convert_high_ascii($s); ## convert high-ASCII chars to 7bit. $s = strtolower($s); ## lower-case. $s = strip_tags($s); ## remove HTML tags. $s = preg_replace('!&[^;\s]+;!', '', $s); ## remove HTML entities. $s = preg_replace('![^\w\s]!', '', $s); ## remove non-word/space chars. $s = str_replace(' ','_',$s); ## change space chars to underscores. return($s);}global $Latin1_ASCII;$Latin1_ASCII = array( "\xc0" => 'A', # A` "\xe0" => 'a', # a` "\xc1" => 'A', # A' "\xe1" => 'a', # a' "\xc2" => 'A', # A^ "\xe2" => 'a', # a^ "\xc4" => 'Ae', # A: "\xe4" => 'ae', # a: "\xc3" => 'A', # A~ "\xe3" => 'a', # a~ "\xc8" => 'E', # E` "\xe8" => 'e', # e` "\xc9" => 'E', # E' "\xe9" => 'e', # e' "\xca" => 'E', # E^ "\xea" => 'e', # e^ "\xcb" => 'Ee', # E: "\xeb" => 'ee', # e: "\xcc" => 'I', # I` "\xec" => 'i', # i` "\xcd" => 'I', # I' "\xed" => 'i', # i' "\xce" => 'I', # I^ "\xee" => 'i', # i^ "\xcf" => 'Ie', # I: "\xef" => 'ie', # i: "\xd2" => 'O', # O` "\xf2" => 'o', # o` "\xd3" => 'O', # O' "\xf3" => 'o', # o' "\xd4" => 'O', # O^ "\xf4" => 'o', # o^ "\xd6" => 'Oe', # O: "\xf6" => 'oe', # o: "\xd5" => 'O', # O~ "\xf5" => 'o', # o~ "\xd8" => 'Oe', # O/ "\xf8" => 'oe', # o/ "\xd9" => 'U', # U` "\xf9" => 'u', # u` "\xda" => 'U', # U' "\xfa" => 'u', # u' "\xdb" => 'U', # U^ "\xfb" => 'u', # u^ "\xdc" => 'Ue', # U: "\xfc" => 'ue', # u: "\xc7" => 'C', # ,C "\xe7" => 'c', # ,c "\xd1" => 'N', # N~ "\xf1" => 'n', # n~ "\xdf" => 'ss',);function convert_high_ascii($s) { global $Latin1_ASCII; return strtr($s, $Latin1_ASCII);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -