/** * 添加相关资料到控制器中,方便Action中直接读取 */ protected function initAddDataToController() { //设置当前或之前访问的地区资料 $cookie = new XF_Cookie('local'); $province_id = $cookie->read(); $mod = new Application_Model_City(); $row = $mod->get($province_id); if ($row != false && $row->parent == '0') { $obj = (object) array('id' => $province_id, 'name' => $row->name, 'pinyin' => $row->pinyin); XF_Controller_Front::getInstance()->addHandleData('nowCity', $obj); XF_View::getInstance()->assign('nowCity', $obj); } //添加静态资源URL XF_Controller_Front::getInstance()->addHandleData('static_url', 'http://static.' . XF_Config::getInstance()->getDomain()); }
/** * 检测二级域名 */ protected function initCheckDomain() { $cookie = new XF_Cookie('local'); $tmp = explode('.', $_SERVER['HTTP_HOST']); //是否为地区二级域名 if (isset($this->_cityDomains->{$tmp[0]})) { $this->_nowCityDomain = (object) $this->_cityDomains->{$tmp[0]}; $this->_nowCityDomain->pinyin = $tmp[0]; //记录当前浏览的地区id $cookie->write($this->_nowCityDomain->id, 604800, '/', '.' . $this->_config->getDomain()); } else { //记录当前浏览的地区id $cookie->write(1, 604800, '/', '.' . $this->_config->getDomain()); XF_Functions::go('http://beijing.' . $this->_config->getDomain()); } }
private function switchCity() { $isSpider = false; $spiders = array('sogou spider', 'Sosospider', '360Spider', 'googlebot', 'mediapartners-google', 'baiduspider', 'msnbot', 'yodaobot', 'yahoo! slurp;', 'yahoo! slurp china;', 'iaskspider', 'sogou web spider', 'sogou push spider'); foreach ($spiders as $s) { if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), strtolower($s)) !== false) { $isSpider = true; break; } } //如果来源是本站则不自动跳转 if ((!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], XF_Config::getInstance()->getDomain()) == false) && $isSpider == false) { $domain_url = XF_Config::getInstance()->getDomain(); //是否存在cookie $cookie = new XF_Cookie('local'); if ($cookie->isEmpty() == false) { $mod = new Application_Model_City(); $row = $mod->get($cookie->read()); if ($row != false) { die('<script>window.location.href="http://' . $row->pinyin . '.' . $domain_url . '";</script>'); } } /////IP $ip = XF_Controller_Request_Http::getInstance()->getClientIp(); $mod = new Application_Model_IP(); $row = $mod->getByIP($ip); $province_id = 1; //如果用户ip不存在则添加到库中 if ($row == false) { $province_id = $mod->add($ip); } else { $province_id = $row->province_id; } XF_Config::getInstance()->load('cityDomain'); $cityDomains = (array) XF_Config::getInstance()->cityDomain; foreach ($cityDomains as $domain => $val) { if ($val['id'] == $province_id) { die('<script>window.location.href="http://' . $domain . '.' . $domain_url . '";</script>'); } } //默认为北京 die('<script>window.location.href="http://beijing.' . $domain_url . '";</script>'); } }
public function voteReportAction() { if ($this->_request->isXmlHttpRequest() && $this->_request->isPost()) { $typeId = $this->getParam("typeId"); $voteType = $this->getParam("voteType"); $gpjSession = new XF_Session("gpj_vote"); if (!$gpjSession->isEmpty()) { if (in_array($typeId, $gpjSession->read())) { die('{"code": "101"}'); } } $cookie = new XF_Cookie("gpj_vote"); $cookieAry = array(); if (!$cookie->isEmpty()) { $cookieAry = explode(",", $cookie->read()); if (in_array($typeId, $cookieAry)) { die('{"code": "101"}'); } } $vote = new Report_Model_Vote(); $reportVote = $vote->getVoteByTypeId($typeId); if ($reportVote) { if ($voteType == "right") { $voteAry["right_vote"] = $reportVote->right_vote + 1; } elseif ($voteType == "noright") { $voteAry["noright_vote"] = $reportVote->noright_vote + 1; } $res = $vote->upVoteById($reportVote->id, $voteAry); } else { if ($voteType == "right") { $voteAry["right_vote"] = 1; $voteAry["noright_vote"] = 0; } elseif ($voteType == "noright") { $voteAry["right_vote"] = 0; $voteAry["noright_vote"] = 1; } $voteAry["car_id"] = $typeId; $res = $vote->addVote($voteAry); } if ($res) { $cookieAry[] = $typeId; $cookie->write(implode(",", $cookieAry), 86400); if (!$gpjSession->isEmpty()) { $gpjAry = $gpjSession->read(); $gpjAry[] = $typeId; } $gpjSession->write($gpjAry); die('{"code":"200"}'); } } }