Announcement.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $thumb_url = geturl($this->thumb);
  38. if (startWith($thumb_url, 'http')) {
  39. return $thumb_url;
  40. } else {
  41. return url($thumb_url, '', false, $host);
  42. }
  43. } else {
  44. //尝试从内容中提取图片
  45. if (empty($this->content)) {
  46. return "";
  47. }
  48. $imgs = matchImg($this->content);
  49. return count($imgs) == 0 ? "" : $imgs[0];
  50. }
  51. }
  52. }