Gbook.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // if(!preg_match('/[^\x00-\x80]/',$param['gbook_content'])){
  64. // return ['code'=>1005,'msg'=>lang('index/require_cn')];
  65. // }
  66. $param['gbook_reply'] = '';
  67. if(empty(cookie('user_id'))){
  68. $param['gbook_name'] = lang('controller/visitor');
  69. $param['user_id']=0;
  70. }
  71. else{
  72. $param['gbook_name'] = cookie('user_name');
  73. $param['user_id'] = intval(cookie('user_id'));
  74. $user_data = model('User')->field('user_nick_name')->where(['user_id' => $param['user_id']])->find();
  75. if (!empty($user_data['user_nick_name'])) {
  76. $param['gbook_name'] = $user_data['user_nick_name'];
  77. }
  78. }
  79. $param['gbook_name'] = htmlentities(trim($param['gbook_name']));
  80. if($GLOBALS['config']['gbook']['audit'] ==1){
  81. $param['gbook_status'] = 0;
  82. }
  83. $param['gbook_ip'] = mac_get_ip_long();
  84. $res = model('Gbook')->saveData($param);
  85. if($res['code']>1){
  86. return $res;
  87. }
  88. else{
  89. cookie($cookie, 't', $GLOBALS['config']['gbook']['timespan']);
  90. if($GLOBALS['config']['gbook']['audit'] ==1){
  91. $res['msg'] = lang('index/thanks_msg_audit');
  92. }
  93. else{
  94. $res['msg'] = lang('index/thanks_msg');
  95. }
  96. return $res;
  97. }
  98. }
  99. }