diff --git a/tools/transfer.php b/tools/transfer.php index 924b0fb175..af0b614b4e 100644 --- a/tools/transfer.php +++ b/tools/transfer.php @@ -74,6 +74,9 @@ } } + $source = str_replace(array('mb_strtoupper', 'mb_strlen'), + array('Typecho_Common::strToUpper', 'Typecho_Common::strLen'), $source); + $tokens = token_get_all($source); $source = ''; diff --git a/var/CommonMark/DocParser.php b/var/CommonMark/DocParser.php index 337b8f13f8..3bc4d7b6ad 100644 --- a/var/CommonMark/DocParser.php +++ b/var/CommonMark/DocParser.php @@ -63,7 +63,7 @@ protected static function detabLine($string) foreach ($parts as $part) { // Calculate number of spaces; insert them followed by the non-tab contents - $amount = 4 - mb_strlen($line, 'UTF-8') % 4; + $amount = 4 - Typecho_Common::strLen($line, 'UTF-8') % 4; $line .= str_repeat(' ', $amount) . $part; } diff --git a/var/CommonMark/Reference/Reference.php b/var/CommonMark/Reference/Reference.php index ee8ddeac5f..40ab7484ca 100644 --- a/var/CommonMark/Reference/Reference.php +++ b/var/CommonMark/Reference/Reference.php @@ -87,6 +87,6 @@ public static function normalizeReference($string) // leading/trailing whitespace $string = preg_replace('/\s+/', '', trim($string)); - return mb_strtoupper($string, 'UTF-8'); + return Typecho_Common::strToUpper($string, 'UTF-8'); } } diff --git a/var/Markdown.php b/var/Markdown.php index 9b5e339961..c1d6d1d042 100644 --- a/var/Markdown.php +++ b/var/Markdown.php @@ -35,7 +35,7 @@ public function renderInline(CommonMark_Element_InlineElementInterface $inline) * @license GNU General Public License 2.0 */ class Markdown -{ +{ /** * convert * diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php index 2b9cbc6a39..f7cb13fcb1 100644 --- a/var/Typecho/Common.php +++ b/var/Typecho/Common.php @@ -48,6 +48,17 @@ class Typecho_Common */ public static $exceptionHandle; + /** + * 将字符串变成大写的回调函数 + * + * @param array $matches + * @access public + * @return string + */ + public static function __strToUpper($matches) + { + return strtoupper($matches[0]); + } /** * 将url中的非法xss去掉时的数组回调过滤函数 @@ -226,6 +237,7 @@ public static function exceptionHandle(Exception $exception) @ob_end_clean(); if (defined('__TYPECHO_DEBUG__')) { + echo '

' . $exception->getMessage() . '

'; echo nl2br($exception->__toString()); } else { if (404 == $exception->getCode() && !empty(self::$exceptionHandle)) { @@ -740,6 +752,23 @@ public static function strLen($str) } } + /** + * 获取大写字符串 + * + * @param string $str + * @access public + * @return string + */ + public static function strToUpper($str) + { + if (__TYPECHO_MB_SUPPORTED__) { + return mb_strtoupper($str, self::$charset); + } else { + return 'UTF-8' == strtoupper(self::$charset) + ? preg_replace_callback("/[a-z]+/u", array('Typecho_Common', '__strToUpper'), $str) : strtoupper($str); + } + } + /** * 检查是否为合法的编码数据 * diff --git a/var/Typecho/Db/Query.php b/var/Typecho/Db/Query.php index 3a7f300693..fabd11e1fb 100644 --- a/var/Typecho/Db/Query.php +++ b/var/Typecho/Db/Query.php @@ -111,26 +111,9 @@ private function filterColumn($str) $split = ''; $quotes = 0; - // fix issue #288 - $inStr = false; - for ($i = 0; $i < $length; $i ++) { $cha = $str[$i]; - if (false !== strpos("'\"", $cha)) { - $inStr = !$inStr; - - if (!$inStr) { - $result .= $cha; - continue; - } - } - - if ($inStr) { - $result .= $cha; - continue; - } - if (ctype_alnum($cha) || false !== strpos('_*', $cha)) { if (!$lastIsAlnum) { if ($quotes > 0 && !ctype_digit($word) && '.' != $split @@ -374,11 +357,12 @@ public function rows(array $rows) * * @param string $key 栏目名称 * @param mixed $value 指定的值 + * @param bool $escape 是否转义 * @return Typecho_Db_Query */ - public function expression($key, $value) + public function expression($key, $value, $escape = true) { - $this->_sqlPreBuild['rows'][$this->filterColumn($key)] = $this->filterColumn($value); + $this->_sqlPreBuild['rows'][$this->filterColumn($key)] = $escape ? $this->filterColumn($value) : $value; return $this; }