getShortSp 设置内容长度 getShortSp=25 后面的数字25 是字符的长度
function getShortSp($str, $num)
{
if (utf8_strlen($str) > $num) {
$tag = '...';
}
$str = getShort($str, $num) . $tag;
return $str;
}
function utf8_strlen($string = null)
{
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
return count($match[0]);
}
Thumb取图片 简写函数,等同于getThumbImageById()
/**通过ID获取到图片的缩略图
* @param $cover_id 图片的ID
* @param int $width 需要取得的宽
* @param string $height 需要取得的高
* @param int $type 图片的类型,qiniu 七牛,local 本地, sae SAE
* @param bool $replace 是否强制替换
* @return string
* @auth 陈一枭
*/
function getThumbImageById($cover_id, $width = 100, $height = 'auto', $type = 0, $replace = false)
{
$picture = S('picture_' . $cover_id);
if (empty($picture)) {
$picture = M('Picture')->where(array('status' => 1))->getById($cover_id);
S('picture_' . $cover_id, $picture);
}
if ($picture['type'] == 'local') {
$attach = getThumbImage($picture['path'], $width, $height, $type, $replace);
return get_pic_src($attach['src']);
} else {
$new_img = $picture['path'];
$name = get_addon_class($picture['type']);
if (class_exists($name)) {
$class = new $name();
if (method_exists($class, 'thumb')) {
$new_img = $class->thumb($picture['path'], $width, $height, $type, $replace);
}
}
return get_pic_src($new_img);
}
}