public function beforeSave() { $ip = Yii::app()->request->userHostAddress; $key = 'ipInfo-' . $ip; $ipData = zmf::getCookie($key); if (!$ipData) { $url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip=' . $ip; // 执行HTTP请求 $header = array('apikey:e5882e7ac4b03c5d6f332b6de4469e81'); $ch = curl_init(); // 添加apikey到header curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $res = curl_exec($ch); $res = CJSON::decode($res, true); $retData = array(); if ($res['errNum'] == 0) { $retData = $res['retData']; } $ipData = json_encode($retData); zmf::setCookie($key, $ipData, 2592000); } $this->ip = ip2long($ip); $this->ipInfo = $ipData; return true; }
function _referer() { $currentUrl = Yii::app()->request->url; $arr = array('/site/', '/error/', '/attachments/'); $set = true; if (Common::checkImg($currentUrl)) { $set = false; } if ($set) { foreach ($arr as $val) { if (!$set) { break; } if (strpos($currentUrl, $val) !== false) { $set = false; break; } } } if ($set && Yii::app()->request->isAjaxRequest) { $set = false; } $referer = zmf::getCookie('refererUrl'); if ($set) { zmf::setCookie('refererUrl', $currentUrl, 86400); } if ($referer != '') { $this->referer = $referer; } }
public function actionView() { $id = zmf::val('id', 2); if (!$id) { throw new CHttpException(404, 'The requested page does not exist.'); } $info = $this->loadModel($id); $pageSize = 30; $comments = Comments::getCommentsByPage($id, 'posts', 1, $pageSize); $tags = Tags::getByIds($info['tagids']); $relatePosts = Posts::getRelations($id, 5); if (!zmf::actionLimit('visit-Posts', $id, 5, 60)) { Posts::updateCount($id, 'Posts', 1, 'hits'); } $size = '600'; if ($this->isMobile) { $size = '640'; } $info['content'] = zmf::text(array(), $info['content'], true, $size); $data = array('info' => $info, 'comments' => $comments, 'tags' => $tags, 'relatePosts' => $relatePosts, 'loadMore' => count($comments) == $pageSize ? 1 : 0); $this->favorited = Favorites::checkFavored($id, 'post'); $this->pageTitle = $info['title']; $this->selectNav = 'posts'; $this->render('view', $data); }
public function actionIndex() { $type = zmf::val('type', 1); if (!$type || $type == 'staycheck') { $status = Posts::STATUS_STAYCHECK; } else { $status = Posts::STATUS_PASSED; } $sql = "SELECT c.id,c.uid,c.content,c.cTime,p.title,c.logid,c.status FROM {{comments}} c,{{posts}} p WHERE c.status={$status} AND c.logid=p.id ORDER BY c.cTime DESC"; Posts::getAll(array('sql' => $sql), $pager, $items); if (!empty($items)) { $uids = array_filter(array_keys(CHtml::listData($items, 'uid', ''))); $uidsStr = join(',', $uids); if ($uidsStr != '') { $usernames = Yii::app()->db->createCommand("SELECT id,truename FROM {{users}} WHERE id IN({$uidsStr})")->queryAll(); if (!empty($usernames)) { foreach ($items as $k => $val) { foreach ($usernames as $val2) { if ($val['uid'] > 0 && $val['uid'] == $val2['id']) { $items[$k]['loginUsername'] = $val2['truename']; } } } } } } $this->render('index', array('pages' => $pager, 'posts' => $items)); }
public function init() { parent::init(); $passwdErrorTimes = zmf::getCookie('checkWithCaptcha'); $time = zmf::config('adminErrorTimes'); if ($time > 0) { if ($passwdErrorTimes >= $time) { header('Content-Type: text/html; charset=utf-8'); echo '您暂时已被禁止访问'; Yii::app()->end(); } } $uid = zmf::uid(); if ($uid) { // $randKey_cookie = zmf::getCookie('adminRandKey' . $uid); // $randKey_cache = zmf::getFCache('adminRandKey' . $uid); // if (!$randKey_cookie || ($randKey_cache != $randKey_cookie)) { // Yii::app()->user->logout(); // $this->message(0, '登录已过期,请重新登录', Yii::app()->createUrl('admin/site/login')); // } $this->userInfo = Users::getOne($uid); $this->uid = $uid; } else { $currentUrl = Yii::app()->request->url; if (strpos($currentUrl, '/site/') === false) { $this->message(0, '请先登录', Yii::app()->createUrl('/site/login')); } } }
/** * 获取汇率 * 雅虎YQL https://developer.yahoo.com/yql/console/ * 请求语句 select * from yahoo.finance.xchange where pair="CNYUSD,CNYHKD" * 示例 https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22CNYUSD%2CCNYHKD%22%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback= */ public function actionExrates() { $units = tools::getUnits(); unset($units['CNY']); $arr = array(); foreach ($units as $k => $v) { $arr[] = 'CNY' . $k; } $str = join(',', $arr); $url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22{$str}%22%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback="; $output = zmf::curlget($url); if (!$output) { exit('Failed'); } $rateArr = CJSON::decode($output); $rateArr = $rateArr['query']['results']['rate']; foreach ($rateArr as $val) { $_key = str_replace('CNY', '', $val['id']); $rates[$_key] = array('rate' => $val['Rate'], 'title' => tools::getUnits($_key)); } $detailDir = Yii::app()->basePath . '/runtime/rates/'; zmf::createUploadDir($detailDir); $dir = $detailDir . 'detail.log'; file_put_contents($dir, CJSON::encode($rates)); exit('well done'); }
public static function add($params = array()) { $uid = zmf::uid(); $data = array('uid' => $params['uid'], 'authorid' => $uid, 'content' => $params['content'], 'new' => 1, 'type' => $params['type'], 'cTime' => zmf::now(), 'from_id' => $params['from_id'], 'from_idtype' => $params['from_idtype'], 'from_num' => 1); if ($uid == $params['uid']) { return false; } $model = new Notification(); $info = $model->find("uid=:uid AND authorid=:authorid AND from_id=:from AND type=:type", array(':uid' => $params['uid'], ':authorid' => $uid, ':from' => $params['from_id'], ':type' => $params['type'])); if ($info) { //存在则更新最新操作时间 if ($model->updateByPk($info['id'], array('cTime' => time(), 'new' => 1, 'from_num' => $info['from_num'] + 1))) { return true; } else { return false; } } else { //不存在则新增 $model->attributes = $data; if ($model->save()) { return true; } else { return false; } } }
public function loadCssJs($type = 'web') { $_staticUrl = zmf::config('cssJsStaticUrl'); $staticUrl = $_staticUrl ? $_staticUrl : zmf::config('baseurl'); $cs = Yii::app()->clientScript; if ($type == 'wedding') { $cs->registerCssFile($staticUrl . 'common/css/bootstrap.min.css'); $cs->registerCssFile($staticUrl . 'common/css/font-awesome.min.css'); $cs->registerCssFile($staticUrl . 'common/css/wedding.css'); $cs->registerCoreScript('jquery'); $cs->registerScriptFile($staticUrl . "common/js/bootstrap.min.js", CClientScript::POS_END); $cs->registerScriptFile($staticUrl . "common/js/wedding.js", CClientScript::POS_END); } elseif ($type == 'user') { $cs->registerCssFile($staticUrl . 'common/css/bootstrap.min.css'); $cs->registerCssFile($staticUrl . 'common/css/font-awesome.min.css'); $cs->registerCssFile($staticUrl . 'common/css/user.css'); $cs->registerCoreScript('jquery'); $cs->registerScriptFile($staticUrl . "common/js/bootstrap.min.js", CClientScript::POS_END); $cs->registerScriptFile($staticUrl . "common/js/wedding.js", CClientScript::POS_END); } elseif ($type == 'group') { $cs->registerCssFile($staticUrl . 'common/css/bootstrap.min.css'); $cs->registerCssFile($staticUrl . 'common/css/font-awesome.min.css'); $cs->registerCssFile($staticUrl . 'common/css/group.css'); $cs->registerCoreScript('jquery'); $cs->registerScriptFile($staticUrl . "common/js/bootstrap.min.js", CClientScript::POS_END); $cs->registerScriptFile($staticUrl . "common/js/wedding.js", CClientScript::POS_END); } }
public function init() { parent::init(); if (zmf::config('closeSite')) { header("Content-type: text/html; charset=utf-8"); exit(zmf::config('closeSiteReason')); } $this->layout = '//layouts/wedding'; $this->currentModule = 'wedding'; // Yii::app()->theme = 'web'; // if (isset($_GET['lang']) && in_array($_GET['lang'], array('zh_cn', 'zh_tw', 'en'))) { // Yii::app()->language = $_GET['lang']; // zmf::delCookie('lang'); // zmf::setCookie('lang', $_GET['lang']); // } // $lang = zmf::getCookie('lang'); // if ($lang != '') { // Yii::app()->language = $lang; // } else { // $countryCode = zmf::getCountryByIp(); // $countryCode = strtoupper($countryCode); // if ($countryCode == 'CN') { // Yii::app()->language = 'zh_cn'; // } elseif (in_array($countryCode, array('HK', 'MO', 'TW'))) { // Yii::app()->language = 'zh_tw'; // } elseif ($countryCode == 'IANA') { // Yii::app()->language = 'zh_cn'; // } else { // Yii::app()->language = 'en'; // } // zmf::setCookie('lang', Yii::app()->language); // } }
public function init() { if (!zmf::uid()) { $this->redirect(zmf::config('baseurl')); } Users::checkPower('admin'); Yii::app()->language = 'zh_cn'; }
public function rules() { $rules = array(array('email, password', 'required'), array('rememberMe', 'boolean'), array('password', 'authenticate')); $cookieInfo = zmf::getCookie('checkWithCaptcha'); if ($cookieInfo == '1') { $rules[] = array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements()); } return $rules; }
public function init() { if (zmf::config('mobile')) { if (tools::checkmobile($this->platform)) { Yii::app()->theme = 'mobile'; $this->isMobile = 'yes'; } } }
public static function getAvatar($aid, $size = 170) { $info = Attachments::getOne($aid); $url = ''; if ($info) { $url = zmf::uploadDirs($info['cTime'], 'site', $info['classify'], $size) . $info['filePath']; } return $url; }
public function actionNotice() { $sql = "SELECT * FROM {{notification}} WHERE uid='{$this->uid}' ORDER BY cTime DESC"; Posts::getAll(array('sql' => $sql), $pages, $comLists); Notification::model()->updateAll(array('new' => 0), 'uid=:uid', array(':uid' => $this->uid)); $data = array('posts' => $comLists, 'pages' => $pages); $this->pageTitle = $this->userInfo['truename'] . '的提醒 - ' . zmf::config('sitename'); $this->render('notice', $data); }
public function init() { //zh_tw\en_us Yii::app()->language = 'zh_cn'; if (zmf::config('mobile')) { if (tools::checkmobile($this->platform)) { $this->isMobile = 'yes'; } } }
public static function getTops() { $keys = zmf::config('hotsearchs'); if ($keys) { $arr = explode('#', $keys); return $arr; } else { return false; } }
public static function checkWeixin() { $wxId = zmf::config('weixin_app_id'); $wxSecret = zmf::config('weixin_app_key'); $callback = zmf::config('weixin_app_callback'); if (!$wxId || !$wxSecret || !$callback) { return false; } return TRUE; }
public function loadCssJs($type = 'web', $action = '') { if (YII_DEBUG) { $staticUrl = Yii::app()->baseUrl . '/'; } else { $_staticUrl = zmf::config('cssJsStaticUrl'); $staticUrl = $_staticUrl ? $_staticUrl : zmf::config('baseurl'); } $cs = Yii::app()->clientScript; $c = Yii::app()->getController()->id; $a = Yii::app()->getController()->getAction()->id; $cssDir = Yii::app()->basePath . '/../common/css'; $jsDir = Yii::app()->basePath . '/../common/js'; $cssArr = array(); $jsArr = array(); if ($type == 'web') { $cssArr = array('bootstrap', 'font-awesome', 'zmf'); $jsArr = array('bootstrap', 'zmf'); $cs->registerCoreScript('jquery'); } elseif ($type == 'mobile') { $cssArr = array('frozen', 'font-awesome'); $jsArr = array('zepto', 'frozen'); $cssArr[] = 'mobile'; $jsArr[] = 'mobile'; } elseif ($type == 'admin') { $cssArr = array('frozen'); $jsArr = array('zepto', 'frozen'); $cssArr[] = 'mobile'; $jsArr[] = 'mobile'; } $cssDirArr = zmf::readDir($cssDir, false); $jsDirArr = zmf::readDir($jsDir, false); foreach ($cssArr as $cssFileName) { foreach ($cssDirArr as $cssfile) { if (strpos($cssfile, $type . '-' . $cssFileName) !== false) { $cs->registerCssFile($staticUrl . 'common/css/' . $cssfile); } } } foreach ($jsArr as $jsFileName) { foreach ($jsDirArr as $jsfile) { if (strpos($jsfile, $type . '-' . $jsFileName) !== false) { if (strpos($jsfile, 'head') !== false) { $pos = CClientScript::POS_HEAD; } else { $pos = CClientScript::POS_END; } $cs->registerScriptFile($staticUrl . 'common/js/' . $jsfile, $pos); } } } }
/** * 计算回答的得分 * @param type $info * @return double */ public static function calScore($info) { //距离回答发表的时间 $Qage = (zmf::now() - $info['cTime']) / 3600; $Qage = round($Qage, 1); //距离最后一个回答的时间 $Qupdated = (zmf::now() - $info['lastupdate']) / 3600; $Qupdated = round($Qupdated, 1); //todo,是否考虑回答的评论数 $dividend = log10($info['hits']) * 4 + $info['comments'] * ($info['favor'] - $info['nouse']) / 5; $divisor = pow($Qage + 1 - ($Qage - $Qupdated) / 2, 1.5); return round($dividend / $divisor * 100000, 9); }
public function getNum() { $uid = zmf::uid(); if (!$uid) { return '0'; } $num = Notification::model()->count('new=1 AND uid=:uid', array(':uid' => $uid)); if ($num > 0) { return $num; } else { return '0'; } }
public function actionView($code) { $code = zmf::filterInput($code, 't', 1); $info = SiteInfo::model()->find('code=:code', array(':code' => $code)); if (!$info) { throw new CHttpException(404, '您所查看的页面不存在'); } $allInfos = SiteInfo::model()->findAll(array('select' => 'code,title', 'condition' => 'status=' . Posts::STATUS_PASSED)); //更新访问统计 Posts::updateCount($info['id'], 'SiteInfo'); $data = array('info' => $info, 'allInfos' => $allInfos, 'code' => $code); $this->pageTitle = $info['title'] . ' - ' . zmf::config('sitename'); $this->render('/site/siteinfo', $data); }
public function actionMap() { $this->layout = 'common'; $sql = "SELECT id,title,lat,`long`,comments,favorite,cTime FROM {{posts}} WHERE lat!='' AND `long`!='' AND `status`=1 ORDER BY cTime ASC"; Posts::getAll(array('sql' => $sql, 'pageSize' => 100), $pages, $posts); foreach ($posts as $k => $val) { $posts[$k]['href'] = Yii::app()->createUrl('posts/view', array('id' => $val['id'])); $posts[$k]['cTime'] = zmf::formatTime($val['cTime']); } $posts = !empty($posts) ? $posts : array(); $data = array('postJson' => CJSON::encode($posts), 'loadMap' => empty($posts) ? false : true); $this->pageTitle = '足迹 - ' . zmf::config('sitename'); $this->selectNav = 'map'; $this->render('/index/map', $data); }
public function actionManage() { $id = zmf::filterInput($_POST['id']); if (!Yii::app()->request->isAjaxRequest) { Admin::jsonOutPut(0, '不允许的操作'); } if (!isset($id) or !is_numeric($id)) { Admin::jsonOutPut(0, '缺少参数'); } $status = Feedback::STATUS_CHECKED; if (Feedback::model()->updateByPk($id, array('status' => $status))) { Admin::jsonOutPut(1, '操作成功!'); } else { Admin::jsonOutPut(0, '操作失败'); } }
public function actionUpdate($type) { if (!in_array($type, array('info', 'passwd'))) { $this->message(0, '您的操作有误'); } if (isset($_POST) and !empty($_POST)) { $model = new Users(); if ($type == 'info') { $intoData['truename'] = zmf::filterInput($_POST['truename'], 't', 1); if (!$intoData['truename']) { $this->message(0, '用户名不能为空'); } //如果用户修改了用户名,则判断是否被使用 if ($intoData['truename'] != $this->userInfo['truename']) { $info = Users::getInfoByName($intoData['truename']); if ($info) { $this->message(0, '该用户名已被使用'); } } $intoData['url'] = zmf::filterInput($_POST['url'], 't', 1); $intoData['desc'] = zmf::filterInput($_POST['desc'], 't', 1); } elseif ($type == 'passwd') { $old = zmf::filterInput($_POST['old_password'], 't', 1); $info = Users::model()->findByPk($this->uid); if (!$old) { $this->message(0, '请输入原始密码'); } elseif (md5($old) != $info['password']) { $this->message(0, '原始密码不正确'); } if (!$_POST['password']) { $this->message(0, '请输入密码'); } elseif (strlen($_POST['password']) < 5) { $this->message(0, '新密码过短,请重新输入'); } $intoData['password'] = md5($_POST['password']); } if ($model->updateByPk($this->uid, $intoData)) { $this->message(1, '修改成功', Yii::app()->createUrl('users/index')); } else { $this->message(1, '修改成功', Yii::app()->createUrl('users/index')); } } $data = array('info' => $this->userInfo, 'type' => $type); $this->render('update', $data); }
public static function checkFavored($logid, $type) { if (Yii::app()->user->isGuest) { return false; } if (!is_numeric($logid)) { return false; } if (!isset($type) or !in_array($type, array('posts', 'attachments', 'poi', 'user', 'question', 'goods'))) { return false; } $attr = array('uid' => zmf::uid(), 'logid' => $logid, 'classify' => $type); if (Favorites::model()->findByAttributes($attr)) { return true; } else { return false; } }
/** * 返回用户关注的地址 * @param type $userInfo 用户信息 * @param type $return 返回方式 a:数组;s:字符串 * @return type */ public static function getLikes($userInfo, $return = 'a') { $cache = zmf::getCookie('myLikeAreas'); if (!$userInfo && !$cache) { return array(); } if ($userInfo) { $extra = CJSON::decode($userInfo['extra'], true); $likes = $extra['likeAreas']; } else { $likes = $cache; } if ($return == 'a') { return explode(',', $likes); } else { return join(',', explode(',', $likes)); } }
public function actionAdd() { $this->checkPower('setConfig'); $type = zmf::filterInput($_POST['type'], 't', 1); if ($type == '' or !in_array($type, array('baseinfo', 'upload', 'base', 'email'))) { $type = 'baseinfo'; } unset($_POST['type']); unset($_POST['YII_CSRF_TOKEN']); $configs = $_POST; if (!empty($configs)) { foreach ($configs as $k => $v) { if (is_array($v)) { $v = join(',', $v); } //组织出hash,根据变量、变量的值及分类的md5 $_hash = md5($k . $v . $type); //如果能找到hash则说明该设置未变化 $_configInfo = Config::model()->find('`hash`=:hash', array(':hash' => $_hash)); if (!$_configInfo) { //没找到说明已更改或者不存在该设置 //根据name和classify判断是否有该设置,没有则新增,有则更新 $_detailInfo = Config::model()->find('`name`=:name AND classify=:type', array(':name' => $k, ':type' => $type)); if (!$_detailInfo) { //新增 $data = array('name' => zmf::filterInput($k, 't'), 'value' => zmf::filterInput($v, 't'), 'classify' => zmf::filterInput($type, 't'), 'hash' => $_hash); $model = new Config(); $model->attributes = $data; $model->save(); } else { //更新 Config::model()->updateByPk($_detailInfo['id'], array('value' => zmf::filterInput($v, 't'), 'hash' => $_hash)); } } else { //未做变化,不操作 } } } //更新本地配置缓存 $_c = Config::model()->findAll(); $configs = CHtml::listData($_c, 'name', 'value'); zmf::writeSet($configs); $this->redirect(array('config/index', 'type' => $type)); }
/** * 返回坐标的封面图 * @param type $poiInfo * @param type $size * @return string */ public static function faceImg($poiInfo, $size = '170', $type = 'posts') { $url = ''; if ($poiInfo['faceimg']) { $info = Attachments::getOne($poiInfo['faceimg']); if ($info) { if ($info['remote'] != '') { $url = $info['remote']; } else { $url = zmf::uploadDirs($info['cTime'], 'site', $info['classify']) . $info['filePath']; } } } if (!$url) { return ''; } $reurl = zmf::getThumbnailUrl($url, $size, $type); return $reurl; }
public function loadCssJs($type = 'web') { $_staticUrl = zmf::config('cssJsStaticUrl'); $staticUrl = $_staticUrl ? $_staticUrl : zmf::config('baseurl'); $cs = Yii::app()->clientScript; if ($type == 'web') { $cs->registerCssFile($staticUrl . 'common/css/bootstrap.min.css'); $cs->registerCssFile($staticUrl . 'common/css/font-awesome.min.css'); $cs->registerCssFile($staticUrl . 'common/css/font-awesome-ie7.min.css'); $cs->registerCssFile($staticUrl . 'common/css/newsoul.css'); $cs->registerCoreScript('jquery'); $cs->registerScriptFile($staticUrl . "common/js/zmf.js", CClientScript::POS_END); } elseif ($type == 'mobile') { $cs->registerCssFile($staticUrl . 'common/css/frozen.css'); $cs->registerCssFile($staticUrl . 'common/css/mobile.css'); $cs->registerScriptFile($staticUrl . "common/js/zepto.min.js", CClientScript::POS_HEAD); $cs->registerScriptFile($staticUrl . "common/js/frozen.js", CClientScript::POS_END); } }
function actionLogin() { $this->layout = 'common'; if (!Yii::app()->user->isGuest) { $this->message(0, '您已登录,请勿重复操作', Yii::app()->createUrl('admin/index/index')); } $model = new LoginForm(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate() && $model->login()) { $arr = array('latestLoginTime' => zmf::now()); $uid = Yii::app()->user->id; if (!$this->checkPower('user', $uid, true)) { Yii::app()->user->logout(); $model->addError('username', '您不是管理员'); } else { //User::model()->updateByPk($uid, $arr); zmf::delCookie('checkWithCaptcha'); //只允许单点登录 $randKey = zmf::randMykeys(8); zmf::setCookie('adminRandKey' . $uid, $randKey, 86400); zmf::setFCache('adminRandKey' . $uid, $randKey, 86400); //记录操作 //UserLog::add($uid, '登录后台'.Yii::app()->request->userHostAddress); $uuid = zmf::uuid(); zmf::setCookie('userCheckedLogin' . $uid, $uuid, 86400); $this->redirect(array('index/index')); } } else { $times = zmf::getCookie('checkWithCaptcha'); zmf::setCookie('checkWithCaptcha', intval($times) + 1, 86400); } } $data = array('model' => $model); $this->render('login', $data); }