CommentModel.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. class CommentModel extends Model
  5. {
  6. /**
  7. * 关联 user表
  8. * @return $this
  9. */
  10. public function user()
  11. {
  12. return $this->belongsTo('UserModel', 'user_id')->setEagerlyType(1);
  13. }
  14. /**
  15. * content 自动转化
  16. * @param $value
  17. * @return string
  18. */
  19. public function getContentAttr($value)
  20. {
  21. return cmf_replace_content_file_url(htmlspecialchars_decode($value));
  22. }
  23. /**
  24. * content 自动转化
  25. * @param $value
  26. * @return string
  27. */
  28. public function setContentAttr($value)
  29. {
  30. $config = \HTMLPurifier_Config::createDefault();
  31. if (!file_exists(RUNTIME_PATH . 'HTMLPurifier_DefinitionCache_Serializer')) {
  32. mkdir(RUNTIME_PATH . 'HTMLPurifier_DefinitionCache_Serializer');
  33. }
  34. $config->set('Cache.SerializerPath', RUNTIME_PATH . 'HTMLPurifier_DefinitionCache_Serializer');
  35. $purifier = new \HTMLPurifier($config);
  36. $cleanHtml = $purifier->purify(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
  37. return htmlspecialchars($cleanHtml);
  38. }
  39. }