111
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

103 lines
3.4 KiB

  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2018年3月5日
  7. * 留言控制器
  8. */
  9. namespace app\home\controller;
  10. use app\home\model\ParserModel;
  11. use core\basic\Controller;
  12. class MessageController extends Controller
  13. {
  14. protected $model;
  15. public function __construct()
  16. {
  17. $this->model = new ParserModel();
  18. }
  19. // 留言新增
  20. public function add()
  21. {
  22. if ($_POST) {
  23. if (time() - session('lastsub') < 10) {
  24. alert_back('您提交太频繁了,请稍后再试!');
  25. }
  26. // 验证码验证
  27. $checkcode = strtolower(post('checkcode', 'var'));
  28. if ($this->config('message_check_code')) {
  29. if (! $checkcode) {
  30. alert_back('验证码不能为空!');
  31. }
  32. if ($checkcode != session('checkcode')) {
  33. alert_back('验证码错误!');
  34. }
  35. }
  36. // 读取字段
  37. if (! $form = $this->model->getFormField(1)) {
  38. alert_back('留言表单不存在任何字段,请核对后重试!');
  39. }
  40. // 接收数据
  41. $mail_body = '';
  42. foreach ($form as $value) {
  43. $field_data = post($value->name);
  44. if (is_array($field_data)) { // 如果是多选等情况时转换
  45. $field_data = implode(',', $field_data);
  46. }
  47. $field_data = preg_replace_r('pboot:if', '', $field_data);
  48. if ($value->required && ! $field_data) {
  49. alert_back($value->description . '不能为空!');
  50. } else {
  51. $data[$value->name] = $field_data;
  52. $mail_body .= $value->description . ':' . $field_data . '<br>';
  53. }
  54. }
  55. // 设置额外数据
  56. if ($data) {
  57. $data['acode'] = get_lg();
  58. $data['user_ip'] = ip2long(get_user_ip());
  59. $data['user_os'] = get_user_os();
  60. $data['user_bs'] = get_user_bs();
  61. $data['recontent'] = '';
  62. $data['status'] = 0;
  63. $data['create_user'] = 'guest';
  64. $data['update_user'] = 'guest';
  65. }
  66. if ($this->model->addMessage($data)) {
  67. session('lastsub', time()); // 记录最后提交时间
  68. $this->log('留言提交成功!');
  69. if ($this->config('message_send_mail') && $this->config('message_send_to')) {
  70. $mail_subject = "【PbootCMS】您有新的" . $value->form_name . "信息,请注意查收!";
  71. $mail_body .= '<br>来自网站 ' . get_http_url() . ' (' . date('Y-m-d H:i:s') . ')';
  72. sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
  73. }
  74. alert_location('提交成功!', '-1', 1);
  75. } else {
  76. $this->log('留言提交失败!');
  77. alert_back('提交失败!');
  78. }
  79. } else {
  80. error('提交失败,请使用POST方式提交!');
  81. }
  82. }
  83. // 空拦截
  84. public function _empty()
  85. {
  86. error('您访问的地址有误,请核对后重试!');
  87. }
  88. }