Announcement.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. //公告表
  5. class Announcement extends Model
  6. {
  7. protected $updateTime = false;
  8. /**
  9. * 获取内容
  10. * @param $host bool/string 可指定域名,默认当前域名
  11. * @return mixed|string
  12. */
  13. public function getContent($host = true)
  14. {
  15. if (empty($this->content)) {
  16. return "";
  17. }
  18. $content = $this->content;
  19. $imgs = matchImg($this->content);
  20. foreach ($imgs as $image) {
  21. if (startWith($image, 'http')) {
  22. continue;
  23. }
  24. $full_image = url($image, '', false, $host);//加上域名
  25. $content = str_replace($image, $full_image, $content);
  26. }
  27. return $content;
  28. }
  29. /**
  30. * 获取缩略图
  31. * @param $host bool/string 可指定域名,默认当前域名
  32. * @return bool|mixed|string
  33. */
  34. public function getThumb($host = true)
  35. {
  36. if ($this->thumb) {
  37. return geturl($this->thumb, '', $host);
  38. } else {
  39. //尝试从内容中提取图片
  40. if (empty($this->content)) {
  41. return "";
  42. }
  43. $imgs = matchImg($this->content);
  44. return count($imgs) == 0 ? "" : url($imgs[0], '', false, $host);
  45. }
  46. }
  47. }