Gbook.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\index\controller;
  3. class Gbook extends Base
  4. {
  5. var $_config;
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. //关闭中
  10. if($GLOBALS['config']['gbook']['status'] == 0){
  11. echo 'gbook is close';
  12. exit;
  13. }
  14. }
  15. public function index()
  16. {
  17. if (Request()->isPost()) {
  18. return $this->saveData();
  19. }
  20. $param = mac_param_url();
  21. $this->assign('param',$param);
  22. $this->assign('gbook',$GLOBALS['config']['gbook']);
  23. return $this->label_fetch('gbook/index');
  24. }
  25. public function ajax()
  26. {
  27. $param = mac_param_url();
  28. $this->assign('param',$param);
  29. $this->assign('gbook',$GLOBALS['config']['gbook']);
  30. return $this->label_fetch('gbook/ajax',0,'json');
  31. }
  32. public function report()
  33. {
  34. $param = mac_param_url();
  35. $this->assign('param',$param);
  36. $this->assign('gbook',$GLOBALS['config']['gbook']);
  37. return $this->label_fetch('gbook/report');
  38. }
  39. public function saveData() {
  40. $param = input();
  41. if($GLOBALS['config']['gbook']['verify'] == 1){
  42. if(!captcha_check($param['verify'])){
  43. return ['code'=>1002,'msg'=>lang('verify_err')];
  44. }
  45. }
  46. if($GLOBALS['config']['gbook']['login'] ==1){
  47. if(empty(cookie('user_id'))){
  48. return ['code' => 1003, 'msg' => lang('index/require_login')];
  49. }
  50. $res = model('User')->checkLogin();
  51. if($res['code']>1) {
  52. return ['code' => 1003, 'msg' => lang('index/require_login')];
  53. }
  54. }
  55. if(empty($param['gbook_content'])){
  56. return ['code'=>1004,'msg'=>lang('index/require_content')];
  57. }
  58. $cookie = 'gbook_timespan';
  59. if(!empty(cookie($cookie))){
  60. return ['code'=>1005,'msg'=>lang('frequently')];
  61. }
  62. $param['gbook_content']= htmlentities(mac_filter_words($param['gbook_content']));
  63. $pattern = '/[^\x00-\x80]/';
  64. if(!preg_match($pattern,$param['gbook_content'])){
  65. return ['code'=>1005,'msg'=>lang('index/require_cn')];
  66. }
  67. $param['gbook_reply'] = '';
  68. if(empty(cookie('user_id'))){
  69. $param['gbook_name'] = lang('controller/visitor');
  70. $param['user_id']=0;
  71. }
  72. else{
  73. $param['gbook_name'] = cookie('user_name');
  74. $param['user_id'] = intval(cookie('user_id'));
  75. }
  76. $param['gbook_name'] = htmlentities($param['gbook_name']);
  77. if($GLOBALS['config']['gbook']['audit'] ==1){
  78. $param['gbook_status'] = 0;
  79. }
  80. $param['gbook_ip'] = mac_get_ip_long();
  81. $res = model('Gbook')->saveData($param);
  82. if($res['code']>1){
  83. return $res;
  84. }
  85. else{
  86. cookie($cookie, 't', $GLOBALS['config']['gbook']['timespan']);
  87. if($GLOBALS['config']['gbook']['audit'] ==1){
  88. $res['msg'] = lang('index/thanks_msg_audit');
  89. }
  90. else{
  91. $res['msg'] = lang('index/thanks_msg');
  92. }
  93. return $res;
  94. }
  95. }
  96. }