ArticleModel.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Admin\Model;
  3. use Think\Model;
  4. /**
  5. * 文章模型
  6. * @author Devil
  7. * @blog http://gong.gg/
  8. * @version 0.0.1
  9. * @datetime 2016-12-01T21:51:08+0800
  10. */
  11. class ArticleModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('title', 'CheckTitle', '{%article_title_format}', 1, 'callback', 3),
  17. array('article_class_id', 'IsExistArticleClassId', '{%article_article_class_id_error}', 1, 'callback', 3),
  18. array('title_color', 'CheckTitleColor', '{%common_color_format}', 2, 'callback', 3),
  19. array('jump_url', 'CheckJumpUrl', '{%article_jump_url_format}', 2, 'callback', 3),
  20. array('is_enable', array(0,1), '{%common_enable_tips}', 1, 'in', 3),
  21. array('content', 'CheckContent', '{%article_content_format_mobile}', 1, 'callback', 3),
  22. );
  23. /**
  24. * [CheckTitle 标题校验]
  25. * @author Devil
  26. * @blog http://gong.gg/
  27. * @version 0.0.1
  28. * @datetime 2016-12-13T19:29:30+0800
  29. */
  30. public function CheckTitle()
  31. {
  32. $len = Utf8Strlen(I('title'));
  33. return ($len >= 3 && $len <= 60);
  34. }
  35. /**
  36. * [IsExistArticleClassId 文章分类是否存在]
  37. * @author Devil
  38. * @blog http://gong.gg/
  39. * @version 0.0.1
  40. * @datetime 2016-12-10T14:09:40+0800
  41. * @return [boolean] [存在true, 不存在false]
  42. */
  43. public function IsExistArticleClassId()
  44. {
  45. $temp = $this->db(0)->table('__ARTICLE_CLASS__')->field(array('id'))->find(I('article_class_id'));
  46. return !empty($temp);
  47. }
  48. /**
  49. * [CheckTitleColor 颜色值校验]
  50. * @author Devil
  51. * @blog http://gong.gg/
  52. * @version 0.0.1
  53. * @datetime 2016-12-13T15:12:32+0800
  54. */
  55. public function CheckTitleColor()
  56. {
  57. return (preg_match('/'.L('common_regex_color').'/', I('title_color')) == 1) ? true : false;
  58. }
  59. /**
  60. * [CheckJumpUrl 跳转url地址校验]
  61. * @author Devil
  62. * @blog http://gong.gg/
  63. * @version 0.0.1
  64. * @datetime 2016-12-13T15:12:32+0800
  65. */
  66. public function CheckJumpUrl()
  67. {
  68. return (preg_match('/'.L('common_regex_url').'/', I('jump_url')) == 1) ? true : false;
  69. }
  70. /**
  71. * [CheckContent 内容校验]
  72. * @author Devil
  73. * @blog http://gong.gg/
  74. * @version 0.0.1
  75. * @datetime 2016-12-13T19:29:30+0800
  76. */
  77. public function CheckContent()
  78. {
  79. $len = Utf8Strlen(I('content'));
  80. return ($len >= 50 && $len <= 105000);
  81. }
  82. }
  83. ?>