123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- <?php
-
-
- namespace app\home\controller;
-
- use think\Db;
- use think\Verify;
-
- class Lists extends Base
- {
-
- public $nid = '';
-
- public $channel = '';
-
- public function _initialize()
- {
- parent::_initialize();
- }
-
-
-
- public function index($tid = '')
- {
- $param = input('param.');
-
-
- $page_tmp = input('param.page/s', 0);
- if (empty($tid) || !is_numeric($page_tmp)) {
- to_index("404");
- }
-
-
-
- if(stristr($this->request->url(), '&c=Lists&a=index&')) {
- to_index("404");
- }
-
- $map = [];
-
-
-
- if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
- $map = array('a.dirname' => $tid);
- } else {
- $map = array('a.id' => intval($tid));
- }
- $map['a.is_del'] = 0;
- $map['a.lang'] = $this->home_lang;
- $row = Db::name('arctype')->field('a.id, a.current_channel, b.nid')
- ->alias('a')
- ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
- ->where($map)
- ->find();
- if (empty($row)) {
- to_index("404");
- }
- $tid = $row['id'];
- $this->nid = $row['nid'];
- $this->channel = intval($row['current_channel']);
-
-
-
- if((int)$tid === 1232){
- $areaname = request()->get('areaname','');
- if((int)$areaname > 0){
- return action('home/View/index', 'tid=1232&aid='.$areaname);
- }
- }
-
-
- $result = $this->logic($tid);
- $eyou = array(
- 'field' => $result,
- );
- $this->eyou = array_merge($this->eyou, $eyou);
- $this->assign('eyou', $this->eyou);
-
-
- $viewfile = !empty($result['templist'])
- ? str_replace('.' . $this->view_suffix, '', $result['templist'])
- : 'lists_' . $this->nid;
-
-
- if (config('city_switch_on') && !empty($this->home_site)) {
- $viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$this->home_site;
- $viewfilepath2 = TEMPLATE_PATH.$this->theme_style_path.DS.'city'.DS.$this->home_site;
- if (!empty($this->eyou['global']['site_template'])) {
- if (file_exists($viewfilepath2)) {
- $viewfile = "city/{$this->home_site}/{$viewfile}";
- } else if (file_exists($viewfilepath)) {
- $viewfile = "{$this->home_site}/{$viewfile}";
- }
- }
- } else if (config('lang_switch_on') && !empty($this->home_lang)) {
- $viewfilepath = TEMPLATE_PATH . $this->theme_style_path . DS . $viewfile . "_{$this->home_lang}." . $this->view_suffix;
- if (file_exists($viewfilepath)) {
- $viewfile .= "_{$this->home_lang}";
- }
- }
-
- $users_id = (int)session('users_id');
- $emptyhtml = $this->check_arcrank($this->eyou['field'],$users_id);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!empty($emptyhtml)) {
-
-
-
- return $this->fetch("./public/html/empty_view.htm");
-
- } else {
- $view = ":{$viewfile}";
- if (51 == $this->channel) {
- $Ask = new \app\home\controller\Ask;
- return $Ask->index();
- }else{
- return $this->fetch($view);
- }
- }
-
-
- }
-
-
-
- private function check_arcrank($eyou_field,$users_id){
- $emptyhtml = "";
- $eyou_field['page_limit'] = empty($eyou_field['page_limit']) ? [] : explode(',', $eyou_field['page_limit']);
- if ($eyou_field['typearcrank'] > 0 && in_array(1,$eyou_field['page_limit']) ) {
- if (empty($users_id)) {
- $url = url('user/Users/login');
- if (stristr($url, '?')) {
- $url = $url."&referurl=".urlencode($eyou_field['arcurl']);
- } else {
- $url = $url."?referurl=".urlencode($eyou_field['arcurl']);
- }
- $this->redirect($url);
- }
- $msg = action('api/Ajax/get_arcrank', ['tid' => $eyou_field['id'], 'vars' => 1]);
- if (true !== $msg) {
- $this->error($msg);
- }
- }
-
- return $emptyhtml;
- }
-
-
-
- private function logic($tid = '')
- {
- $result = array();
-
- if (empty($tid)) {
- return $result;
- }
- switch ($this->channel) {
- case '6':
- {
- $arctype_info = model('Arctype')->getInfo($tid);
- if ($arctype_info) {
-
- $archivesModel = new \app\home\model\Archives;
- $result_new = $archivesModel->readContentFirst($tid);
-
- if ($result_new['arcrank'] == -1) {
- $this->success('待审核稿件,你没有权限阅读!');
- exit;
- }
-
- if ($result_new['is_part'] == 1) {
- $result_new['typelink'] = htmlspecialchars_decode($result_new['typelink']);
- if (!is_http_url($result_new['typelink'])) {
- $typeurl = '//'.$this->request->host();
- if (!preg_match('#^'.ROOT_DIR.'(.*)$#i', $result_new['typelink'])) {
- $typeurl .= ROOT_DIR;
- }
- $typeurl .= '/'.trim($result_new['typelink'], '/');
- $result_new['typelink'] = $typeurl;
- }
- $this->redirect($result_new['typelink']);
- exit;
- }
-
- $result_new = $this->fieldLogic->getChannelFieldList($result_new, $this->channel);
-
- $result = array_merge($arctype_info, $result_new);
-
- $result['templist'] = !empty($arctype_info['templist']) ? $arctype_info['templist'] : 'lists_'. $arctype_info['nid'];
- $result['dirpath'] = $arctype_info['dirpath'];
- $result['diy_dirpath'] = $arctype_info['diy_dirpath'];
- $result['typeid'] = $arctype_info['typeid'];
- $result['rulelist'] = $arctype_info['rulelist'];
- }
- break;
- }
-
- default:
- {
- $result = model('Arctype')->getInfo($tid);
-
- if ($result['is_part'] == 1) {
- $result['typelink'] = htmlspecialchars_decode($result['typelink']);
- if (!is_http_url($result['typelink'])) {
- $result['typelink'] = '//'.$this->request->host().ROOT_DIR.'/'.trim($result['typelink'], '/');
- }
- $this->redirect($result['typelink']);
- exit;
- }
-
- break;
- }
- }
-
- if (!empty($result)) {
-
- $result = $this->fieldLogic->getTableFieldList($result, config('global.arctype_channel_id'));
-
- }
-
-
- $result['has_children'] = model('Arctype')->hasChildren($tid);
-
-
-
-
-
- $route_param = request()->route();
-
-
-
-
-
-
- $result['pageurl'] = typeurl('home/'.$result['ctl_name'].'/lists', $result, true, true);
- $result['pageurl'] = get_list_only_pageurl($result['pageurl'], $result['typeid'], $result['rulelist']);
- $result['pageurl_m'] = pc_to_mobile_url($result['pageurl'], $result['typeid']);
-
- $result['mobile_domain'] = '';
- if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
- $result['mobile_domain'] = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
- }
-
-
- foreach ($result as $key => $val) {
- if (!preg_match('/^type/i', $key)) {
- $key_new = 'type' . $key;
- !array_key_exists($key_new, $result) && $result[$key_new] = $val;
- }
- }
-
-
- return $result;
- }
-
-
-
- public function gbook_submit()
- {
- $typeid = input('post.typeid/d');
- if (IS_POST && !empty($typeid)) {
- $form_type = input('post.form_type/d', 0);
- $channel_guestbook_gourl = tpSetting('channel_guestbook.channel_guestbook_gourl');
- if (!empty($channel_guestbook_gourl)) {
- $gourl = $channel_guestbook_gourl;
- } else {
- $gourl = input('post.gourl/s');
- $gourl = urldecode($gourl);
- $gourl = str_replace(['"',"'",';'], '', $gourl);
- }
- $post = input('post.');
- unset($post['gourl']);
-
- $token = '__token__';
- foreach ($post as $key => $val) {
- if (preg_match('/^__token__/i', $key)) {
- $token = $key;
- continue;
- }
-
-
-
-
-
-
- }
- $ip = clientIP();
-
-
- $channel_guestbook_interval = tpSetting('channel_guestbook.channel_guestbook_interval');
- $channel_guestbook_interval = is_numeric($channel_guestbook_interval) ? intval($channel_guestbook_interval) : 60;
- if (0 < $channel_guestbook_interval) {
- $map = array(
- 'typeid' => $typeid,
- 'form_type'=> $form_type,
- 'ip' => $ip,
- 'add_time' => array('gt', getTime() - $channel_guestbook_interval),
- );
- $count = Db::name('guestbook')->where($map)->count('aid');
- if ($count > 0) {
- $msg = sprintf(foreign_lang('gbook2', $this->home_lang), $channel_guestbook_interval);
- $this->error($msg);
- }
- }
-
-
- $attrArr = [];
-
- if (is_language()) {
- foreach ($post as $key => $val) {
- if (preg_match_all('/^attr_(\d+)$/i', $key, $matchs)) {
- $attr_value = intval($matchs[1][0]);
- $attrArr[$attr_value] = [
- 'attr_id' => $attr_value,
- ];
- }
- }
- if (1 == $form_type) {
- $attrArr = model('LanguageAttr')->getBindValue($attrArr, 'form_attribute');
- } else {
- $attrArr = model('LanguageAttr')->getBindValue($attrArr, 'guestbook_attribute');
- }
- }
-
- $ContentArr = [];
- foreach ($post as $key => $value) {
- if (stripos($key, "attr_") !== false) {
-
- $attr_id = substr($key, 5);
- $attr_id = intval($attr_id);
- if (!empty($attrArr)) {
- $attr_id = $attrArr[$attr_id]['attr_id'];
- }
- $ga_data = Db::name('guestbook_attribute')->where([
- 'attr_id' => $attr_id,
- ])->find();
- if ($ga_data['required'] == 1) {
- if (empty($value)) {
- $msg = sprintf(foreign_lang('gbook3', $this->home_lang), $ga_data['attr_name']);
- $this->error($msg);
- } else {
- if ($ga_data['validate_type'] == 6) {
- $pattern = "/^1\d{10}$/";
- if (!preg_match($pattern, $value)) {
- $msg = sprintf(foreign_lang('gbook4', $this->home_lang), $ga_data['attr_name']);
- $this->error($msg);
- }
- } elseif ($ga_data['validate_type'] == 7) {
- $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
- if (preg_match($pattern, $value) == false) {
- $msg = sprintf(foreign_lang('gbook4', $this->home_lang), $ga_data['attr_name']);
- $this->error($msg);
- }
- }
- }
- }
- if (is_array($value)){
- $value = implode(',', $value);
- }
-
- array_push($ContentArr, $value);
- }
- }
-
-
- $is_vertify = 1;
- $guestbook_captcha = config('captcha.guestbook');
- if (!function_exists('imagettftext') || empty($guestbook_captcha['is_on'])) {
- $is_vertify = 0;
- }
- if (1 == $is_vertify) {
- if (empty($post['vertify'])) {
- $msg = foreign_lang('gbook5', $this->home_lang);
- $this->error($msg);
- }
-
- $verify = new Verify();
- if (!$verify->check($post['vertify'], $token)) {
- $msg = foreign_lang('gbook6', $this->home_lang);
- $this->error($msg);
- }
- }
-
-
- if (1 == $form_type) {
- $channel = 0;
- } else {
- $channeltype_list = config('global.channeltype_list');
- $channel = !empty($channeltype_list['guestbook']) ? $channeltype_list['guestbook'] : 8;
- }
-
- $newData = array(
- 'typeid' => $typeid,
- 'form_type' => $form_type,
- 'channel' => $channel,
- 'ip' => $ip,
- 'source' => isMobile() ? 2 : 1,
- 'lang' => $this->home_lang,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- );
- $data = array_merge($post, $newData);
-
-
- if (!empty($post['real_validate'])) {
- if (!empty($post['real_validate_phone_input']) && !empty($post['real_validate_attr_id'])) {
-
- $phone = !empty($post[$post['real_validate_attr_id']]) ? $post[$post['real_validate_attr_id']] : 0;
- if (empty($phone)) {
- $msg = foreign_lang('gbook7', $this->home_lang);
- $this->error($msg);
- }
-
- $where = [
- 'source' => 7,
- 'mobile' => $phone,
- 'code' => $post['real_validate_phone_input']
- ];
- $smsLog = Db::name('sms_log')->where($where)->order('id desc')->find();
- if (empty($smsLog)) {
- $msg = foreign_lang('gbook8', $this->home_lang);
- $this->error($msg);
- }
-
- $time = getTime();
- $smsLog['add_time'] += \think\Config::get('global.mobile_default_time_out');
-
- if (1 === intval($smsLog['is_use']) || $smsLog['add_time'] <= $time) {
- $msg = foreign_lang('gbook9', $this->home_lang);
- $this->error($msg);
- }
-
- $where = [
- 'source' => 7,
- 'mobile' => $phone,
- 'is_use' => 0,
- 'lang' => $this->home_lang
- ];
- $update = [
- 'is_use' => 1,
- 'update_time' => $time
- ];
- Db::name('sms_log')->where($where)->update($update);
-
- unset($post['real_validate_input'], $post['real_validate_phone_input'], $post['real_validate_attr_id'], $post['real_validate_token']);
- } else {
- $msg = foreign_lang('gbook10', $this->home_lang);
- $this->error($msg);
- }
- }
-
-
- $rule = [
- 'typeid' => 'require|token:' . $token,
- ];
- $message = [
- 'typeid.require' => foreign_lang('gbook11', $this->home_lang),
- ];
- $validate = new \think\Validate($rule, $message);
- if (!$validate->batch()->check($data)) {
- $error = $validate->getError();
- $error_msg = array_values($error);
- $this->error($error_msg[0]);
- } else {
- $guestbookRow = [];
-
- $formdata = $data;
- foreach ($formdata as $key => $val) {
- if (in_array($key, ['typeid', 'lang']) || preg_match('/^attr_(\d+)$/i', $key)) {
- continue;
- }
- unset($formdata[$key]);
- }
- if (is_array($_FILES)) {
- $formdata = array_merge($formdata, $_FILES);
- }
- $md5data = md5(serialize($formdata));
- $data['md5data'] = $md5data;
- $users_id = session('users_id');
- $data['users_id'] = !empty($users_id) ? $users_id : 0;
- $guestbookRow = Db::name('guestbook')->field('aid')->where(['md5data' => $md5data])->find();
-
- $dataStr = '';
- if (empty($guestbookRow)) {
- $aid = Db::name('guestbook')->insertGetId($data);
- if ($aid > 0) {
- $res = $this->saveGuestbookAttr($aid, $typeid, $post);
- if ($res){
- $this->error($res);
- }
- }
- $_POST['aid'] = $aid;
-
- $data = [
- 'gbook_submit',
- $typeid,
- $aid,
- $form_type,
- ];
- $dataStr = implode('|', $data);
-
-
-
- SendNotifyMessage($ContentArr, 1, 1, 0);
-
- } else {
- $_POST['aid'] = $guestbookRow['aid'];
-
- Db::name('guestbook')->where('aid', $guestbookRow['aid'])->update([
- 'is_read' => 0,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- ]);
- }
-
- $msg = foreign_lang('gbook1', $this->home_lang);
- $channel_guestbook_time = tpSetting('channel_guestbook.channel_guestbook_time');
- $channel_guestbook_time = !empty($channel_guestbook_time) ? intval($channel_guestbook_time) : 5;
- $this->success($msg, $gourl, $dataStr, $channel_guestbook_time);
- }
- }
- $msg = foreign_lang('gbook11', $this->home_lang);
- $this->error($msg);
- }
-
-
-
- private function saveGuestbookAttr($aid, $typeid, $post)
- {
-
-
- $image_type_list = explode('|', tpCache('global.image_type'));
-
- foreach ($_FILES as $fileElementId => $file) {
- try {
- if (is_array($file['name'])) {
- $files = $this->request->file($fileElementId);
- foreach ($files as $key => $value) {
- $ext = pathinfo($value->getInfo('name'), PATHINFO_EXTENSION);
- if (in_array($ext, $image_type_list)) {
- $uplaod_data = func_common($fileElementId, 'allimg', '', $value);
- } else {
- $uplaod_data = func_common_doc($fileElementId, 'files', '', $value);
- }
- if (0 == $uplaod_data['errcode']) {
- if (empty($post[$fileElementId])) {
- $post[$fileElementId] = $uplaod_data['img_url'];
- } else {
- $post[$fileElementId] .= ',' . $uplaod_data['img_url'];
- }
- } else {
- return $uplaod_data['errmsg'];
- }
- }
- } else {
- if (!empty($file['name']) && !is_array($file['name'])) {
- $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
- if (in_array($ext, $image_type_list)) {
- $uplaod_data = func_common($fileElementId, 'allimg');
- } else {
- $uplaod_data = func_common_doc($fileElementId, 'files');
- }
- if (0 == $uplaod_data['errcode']) {
- $post[$fileElementId] = $uplaod_data['img_url'];
- } else {
- return $uplaod_data['errmsg'];
- }
- }
- }
- } catch (\Exception $e) {}
- }
-
- $attrArr = [];
-
-
- if (is_language()) {
- foreach ($post as $key => $val) {
- if (preg_match_all('/^attr_(\d+)$/i', $key, $matchs)) {
- $attr_value = intval($matchs[1][0]);
- $attrArr[$attr_value] = [
- 'attr_id' => $attr_value,
- ];
- }
- }
- if (!empty($post['form_type'])) {
- $attrArr = model('LanguageAttr')->getBindValue($attrArr, 'form_attribute');
- } else {
- $attrArr = model('LanguageAttr')->getBindValue($attrArr, 'guestbook_attribute');
- }
- }
-
-
- foreach ($post as $k => $v) {
- if (!strstr($k, 'attr_')) continue;
- $attr_id = str_replace('attr_', '', $k);
- if (is_array($v)) {
- $v = implode(PHP_EOL, $v);
- } else {
- $ga_data = Db::name('guestbook_attribute')->where([
- 'attr_id' => $attr_id,
- ])->find();
- if (!empty($ga_data) && 10 == $ga_data['attr_input_type']){
- $v = strtotime($v);
- }
- }
-
-
- if (!empty($attrArr)) {
- $attr_id = $attrArr[$attr_id]['attr_id'];
- }
-
-
-
-
- $v = trim($v);
- $adddata = array(
- 'aid' => $aid,
- 'form_type' => empty($post['form_type']) ? 0 : intval($post['form_type']),
- 'attr_id' => $attr_id,
- 'attr_value' => $v,
- 'lang' => $this->home_lang,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- );
- Db::name('guestbook_attr')->add($adddata);
- }
- }
- }
|