12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\common\model;
- use think\Model;
- //公告表
- class Announcement extends Model
- {
- protected $updateTime = false;
- /**
- * 获取内容
- * @param $host bool/string 可指定域名,默认当前域名
- * @return mixed|string
- */
- public function getContent($host = true)
- {
- if (empty($this->content)) {
- return "";
- }
- $content = $this->content;
- $imgs = matchImg($this->content);
- foreach ($imgs as $image) {
- if (startWith($image, 'http')) {
- continue;
- }
- $full_image = url($image, '', false, $host);//加上域名
- $content = str_replace($image, $full_image, $content);
- }
- return $content;
- }
- /**
- * 获取缩略图
- * @param $host bool/string 可指定域名,默认当前域名
- * @return bool|mixed|string
- */
- public function getThumb($host = true)
- {
- if ($this->thumb) {
- return geturl($this->thumb, '', $host);
- } else {
- //尝试从内容中提取图片
- if (empty($this->content)) {
- return "";
- }
- $imgs = matchImg($this->content);
- return count($imgs) == 0 ? "" : url($imgs[0], '', false, $host);
- }
- }
- }
|