This commit is contained in:
fen 2014-01-10 23:55:59 +08:00
commit 787c143949
3 changed files with 45 additions and 15 deletions

View File

@ -731,15 +731,26 @@ EOF;
*/
public static function subStr($str, $start, $length, $trim = "...")
{
if (function_exists('mb_get_info')) {
$iLength = mb_strlen($str, self::$charset);
$str = mb_substr($str, $start, $length, self::$charset);
return ($length < $iLength - $start) ? $str . $trim : $str;
} else {
preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $str, $info);
$str = join("", array_slice($info[0], $start, $length));
return ($length < (sizeof($info[0]) - $start)) ? $str . $trim : $str;
if (!strlen($str)) {
return '';
}
$iLength = self::strLen($str) - $start;
$tLength = $length < $iLength ? ($length - self::strLen($trim)) : $length;
if (function_exists('mb_get_info')) {
$str = mb_substr($str, $start, $tLength, self::$charset);
} else {
if ('UTF-8' == strtoupper(self::$charset)) {
if (preg_match_all("/./u", $str, $matches)) {
$str = implode('', array_slice($matches[0], $start, $tLength));
}
} else {
$str = substr($str, $start, $tLength);
}
}
return $length < $iLength ? ($str . $trim) : $str;
}
/**
@ -754,8 +765,8 @@ EOF;
if (function_exists('mb_get_info')) {
return mb_strlen($str, self::$charset);
} else {
preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $str, $info);
return sizeof($info[0]);
return 'UTF-8' == strtoupper(self::$charset)
? strlen(utf8_decode($str)) : strlen($info[0]);
}
}
@ -792,12 +803,16 @@ EOF;
}
$str = $return;
} else if ('UTF-8' == strtoupper(self::$charset)) {
if (preg_match_all("/[\w" . preg_quote('_-') . "]+/u", $str, $matches)) {
$str = implode('-', $matches[0]);
}
} else {
$str = str_replace(array("'", ":", "\\", "/", '"'), "", $str);
$str = str_replace(array("+", ",", ' ', '', ' ', ".", "?", "=", "&", "!", "<", ">", "(", ")", "[", "]", "{", "}"), "-", $str);
$str = trim($str, '-');
}
$str = trim($str, '-_');
$str = !strlen($str) ? $default : $str;
return substr($str, 0, $maxLength);
}

View File

@ -162,6 +162,8 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
->where('coid = ?', $coid)->limit(1), array($this, 'push'));
if ($comment && $this->commentIsWriteable()) {
$this->pluginHandle()->delete($comment, $this);
/** 删除评论 */
$this->db->query($this->db->delete('table.comments')->where('coid = ?', $coid));
@ -170,6 +172,8 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
$this->db->query($this->db->update('table.contents')
->expression('commentsNum', 'commentsNum - 1')->where('cid = ?', $comment['cid']));
}
$this->pluginHandle()->finishDelete($comment, $this);
$deleteRows ++;
}

View File

@ -54,6 +54,19 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
return self::makeUploadDir($path);
}
/**
* 获取安全的文件名
*
* @param string $name
* @static
* @access private
* @return string
*/
private static function getSafeName($name)
{
preg_split("/(\/|\\\|:)/"
}
/**
* 上传文件处理函数,如果需要实现自己的文件哈希或者特殊的文件系统,请在options表里把uploadHandle改成自己的函数
*
@ -72,8 +85,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
return $result;
}
$fileName = preg_split("(\/|\\|:)", $file['name']);
$file['name'] = array_pop($fileName);
$file['name'] = basename($file['name']);
//获取扩展名
$ext = '';
@ -152,8 +164,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
return $result;
}
$fileName = preg_split("(\/|\\|:)", $file['name']);
$file['name'] = array_pop($fileName);
$file['name'] = basename($file['name']);
//获取扩展名
$ext = '';