Esempio n. 1
0
 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;
         }
     }
 }
Esempio n. 2
0
File: tools.php Progetto: ph7pal/mei
 public static function formatTime($date)
 {
     $thisyear = intval(zmf::time(NULL, 'Y'));
     $dateyear = intval(zmf::time($date, 'Y'));
     if ($thisyear - $dateyear > 0) {
         return zmf::time($date, 'Y-m-d H:i');
     }
     $thismo = intval(zmf::time(NULL, 'm'));
     $datemo = intval(zmf::time($date, 'm'));
     if ($thisyear == $dateyear && $thismo != $datemo) {
         return zmf::time($date, 'm-d H:i');
     }
     $timer = $date;
     $diff = zmf::now() - $timer;
     $thisto = intval(zmf::time(NULL, 'd'));
     $dateto = intval(zmf::time($date, 'd'));
     $day = $thisto - $dateto;
     $free = $diff % 86400;
     if ($day > 0) {
         if ($day > 7) {
             return zmf::time($date, 'n-j H:i');
         } elseif ($day == 1) {
             return "昨天 " . zmf::time($date, 'H:i');
         } elseif ($day == 2) {
             return "前天 " . zmf::time($date, 'H:i');
         } else {
             return $day . "天前";
         }
     } else {
         if ($free > 0) {
             $hour = floor($free / 3600);
             $free = $free % 3600;
             if ($hour > 0) {
                 return $hour . "小时前";
             } else {
                 if ($free > 0) {
                     $min = floor($free / 60);
                     $free = $free % 60;
                     if ($min > 0) {
                         return $min . "分钟前";
                     } else {
                         if ($free > 0) {
                             return $free . "秒前";
                         } else {
                             return '刚刚';
                         }
                     }
                 } else {
                     return '刚刚';
                 }
             }
         } else {
             return '刚刚';
         }
     }
 }
Esempio n. 3
0
 public static function add($params = array())
 {
     $data = array('uid' => $params['uid'], 'authorid' => $params['authorid'], '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 ($params['uid'] == $params['authorid']) {
         return false;
     }
     $model = new Notification();
     //2016修改为不计条数
     $model->attributes = $data;
     return $model->save();
 }
Esempio n. 4
0
 /**
  * 计算回答的得分
  * @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);
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public function actionLogin()
 {
     $this->onlyOnPc();
     $this->layout = 'common';
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作');
     }
     $canLogin = true;
     $ip = Yii::app()->request->getUserHostAddress();
     $cacheKey = 'loginErrors-' . $ip;
     $errorTimes = zmf::getFCache($cacheKey);
     if ($errorTimes >= 5) {
         $canLogin = false;
     }
     if ($canLogin) {
         $model = new FrontLogin();
         if (isset($_POST['FrontLogin'])) {
             $model->attributes = $_POST['FrontLogin'];
             if ($model->validate() && $model->login()) {
                 $arr = array('latestLoginTime' => zmf::now());
                 $uid = Yii::app()->user->id;
                 //                    User::model()->updateByPk($uid, $arr);
                 zmf::delCookie('checkWithCaptcha');
                 zmf::delFCache($cacheKey);
                 if ($this->referer) {
                     $this->redirect($this->referer);
                 } else {
                     $this->redirect(zmf::config('baseurl'));
                 }
             } else {
                 zmf::updateFCacheCounter($cacheKey, 1, 3600);
                 zmf::setCookie('checkWithCaptcha', 1, 86400);
             }
         }
     }
     $this->pageTitle = '登录';
     $this->render('login', array('model' => $model));
 }
Esempio n. 7
0
 public function actionLogin($from = '')
 {
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作');
     }
     $model = new LoginForm();
     //登录
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'users-addUser-form') {
         echo CActiveForm::validate($modelUser);
         Yii::app()->end();
     }
     //登录
     if (isset($_POST['LoginForm'])) {
         $from = 'login';
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate()) {
             if ($model->login()) {
                 $arr = array('last_login_ip' => ip2long(Yii::app()->request->userHostAddress), 'last_login_time' => zmf::now());
                 Users::model()->updateByPk(Yii::app()->user->id, $arr);
                 Users::model()->updateCounters(array('login_count' => 1), ':id=id', array(':id' => Yii::app()->user->id));
                 if ($this->referer == '') {
                     $this->referer = array('users/index');
                 }
                 zmf::delCookie('checkWithCaptcha');
                 $this->redirect($this->referer);
             }
         } else {
             zmf::setCookie('checkWithCaptcha', 1, 86400);
         }
     }
     $this->pageTitle = '登录 - ' . zmf::config('sitename');
     $this->render('login', array('model' => $model));
 }
Esempio n. 8
0
?>
                <?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'startTime', 'language' => 'zh-cn', 'value' => date('Y/m/d', $model->startTime), 'options' => array('showAnim' => 'fadeIn'), 'htmlOptions' => array('readonly' => 'readonly', 'class' => 'form-control', 'value' => date('Y/m/d', $model->startTime ? $model->startTime : zmf::now()))));
?>
                <?php 
echo $form->error($model, 'startTime');
?>
            </div>
        </div>
        <div class="col-sm-6 col-xs-6">
            <div class="form-group">
                <?php 
echo $form->labelEx($model, 'endTime');
?>
                <?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'endTime', 'language' => 'zh-cn', 'value' => date('Y/m/d', $model->endTime), 'options' => array('showAnim' => 'fadeIn'), 'htmlOptions' => array('readonly' => 'readonly', 'class' => 'form-control', 'value' => date('Y/m/d', $model->endTime ? $model->endTime : zmf::now()))));
?>
                <?php 
echo $form->error($model, 'endTime');
?>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-6 col-xs-6">
            <div class="form-group">
                <?php 
echo $form->labelEx($model, 'areaid');
?>
                <?php 
$areaTitle = '';
Esempio n. 9
0
 private function add($type = '')
 {
     $uid = zmf::filterInput(Yii::app()->request->getParam('uid'), 't', 1);
     if (!$uid) {
         $uid = zmf::uid();
     }
     if (zmf::config('fbLoginOnly')) {
         if (!$uid) {
             $this->jsonOutPut(0, Yii::t('default', 'fbLoginOnly'));
         }
     }
     $url = zmf::filterInput(Yii::app()->request->getParam('url'), 't', 1);
     $email = zmf::filterInput(Yii::app()->request->getParam('email'), 't', 1);
     $content = zmf::filterInput(Yii::app()->request->getParam('content'), 't', 1);
     $ip = zmf::filterInput(Yii::app()->request->getParam('ip'), 't', 1);
     $appversion = zmf::filterInput(Yii::app()->request->getParam('appversion'), 't', 1);
     $os = zmf::filterInput(Yii::app()->request->getParam('os'), 't', 1);
     $platform = zmf::filterInput(Yii::app()->request->getParam('platform'), 't', 1);
     $time = zmf::filterInput(Yii::app()->request->getParam('time'), 't', 1);
     if (!$ip) {
         $ip = ip2long(Yii::app()->request->userHostAddress);
     }
     if (!$platform) {
         $platform = Yii::app()->request->getUserAgent();
     }
     if ($type == '' || !in_array($type, array('pc', 'mobile', 'ios', 'android'))) {
         $type = 'pc';
     }
     if (!$time) {
         $time = zmf::now();
     }
     $cacheKey = 'feedback_' . $ip;
     if ($content == '') {
         $this->jsonOutPut(0, Yii::t('default', 'fbNoEmpty'));
     }
     if (zmf::config('fbTimesLimit')) {
         $times = intval(zmf::getFCache($cacheKey));
         $_time = $times + 1;
         //fbLimitTimes
         zmf::setFCache($cacheKey, $_time, 60);
         if ($_time >= zmf::config('fbLimitTimes')) {
             $this->jsonOutPut(0, Yii::t('default', 'fbTimesLimit'));
         }
     }
     $data = array('uid' => $uid, 'url' => $url, 'email' => $email, 'content' => $content, 'ip' => $ip, 'cTime' => $time, 'status' => Posts::STATUS_STAYCHECK, 'classify' => $type, 'appversion' => $appversion, 'os' => $os, 'platform' => $platform);
     $model = new Feedback();
     $model->attributes = $data;
     if ($model->validate()) {
         if ($model->save()) {
             if (zmf::config("defaultNoticeUid")) {
                 $_data = array('uid' => zmf::config("defaultNoticeUid"), 'content' => ($email != '' ? $email . '反馈:' : '新反馈:') . $content, 'type' => 'feedback', 'from_id' => rand(1, 100000), 'from_idtype' => 'feedback');
                 Notification::add($_data);
             }
             $this->jsonOutPut(1, Yii::t('default', 'fbThanking'));
         } else {
             $this->jsonOutPut(0, Yii::t('default', 'fbThanking'));
         }
     } else {
         $this->jsonOutPut(0, Yii::t('default', 'notvalidate'));
     }
 }
Esempio n. 10
0
 public static function favorite($code, $type, $from = 'web', $uid = '')
 {
     if (!$code || !$type) {
         return array('status' => 0, 'msg' => '数据不全,请核实');
     }
     if (!in_array($type, array('post'))) {
         return array('status' => 0, 'msg' => '暂不允许的分类');
     }
     if (is_numeric($code)) {
         $id = $code;
     } else {
         $codeArr = Posts::decode($code);
         if ($codeArr['type'] != $type || !is_numeric($codeArr['id']) || $codeArr['id'] < 1) {
             $this->jsonOutPut(0, '您所查看的内容不存在');
         }
         $id = $codeArr['id'];
     }
     if (!$uid) {
         $uid = zmf::uid();
     }
     if ($uid) {
         if (zmf::actionLimit('favorite-' . $type, $id)) {
             return array('status' => 0, 'msg' => '操作太频繁,请稍后再试');
         }
     } else {
         //没有登录的访客点收藏时判断是否已收藏过
         if (zmf::actionLimit('favorite-' . $type, $id, 1, 86400, true)) {
             return array('status' => 1, 'msg' => '已点赞', 'state' => 1);
         }
         $uid = 0;
     }
     $postInfo = Posts::model()->findByPk($id);
     if (!$postInfo || $postInfo['status'] != Posts::STATUS_PASSED) {
         return array('status' => 0, 'msg' => '文章不存在');
     }
     $attr = array('uid' => $uid, 'logid' => $id, 'classify' => $type);
     $info = false;
     if ($uid) {
         $info = Favorites::model()->findByAttributes($attr);
     }
     if ($info) {
         if (Favorites::model()->deleteByPk($info['id'])) {
             if ($type == 'post') {
                 Posts::updateCount($id, 'Posts', -1, 'favorite');
             }
             return array('status' => 1, 'msg' => '取消点赞', 'state' => 3);
         } else {
             return array('status' => 0, 'msg' => '取消点赞失败', 'state' => 4);
         }
     } else {
         $attr['cTime'] = zmf::now();
         $model = new Favorites();
         $model->attributes = $attr;
         if ($model->save()) {
             if ($type == 'post') {
                 Posts::updateCount($id, 'Posts', 1, 'favorite');
             }
             //点赞后给对方发提醒
             $_noticedata = array('uid' => $postInfo['uid'], 'authorid' => $uid, 'content' => "您的文章【{$postInfo['title']}】有了新的赞", 'new' => 1, 'type' => 'favorite', 'cTime' => zmf::now(), 'from_id' => $model->id, 'from_num' => 1);
             Notification::add($_noticedata);
             return array('status' => 1, 'msg' => '点赞成功', 'state' => 1);
         } else {
             return array('status' => 0, 'msg' => '点赞失败', 'state' => 2);
         }
     }
 }
Esempio n. 11
0
 public function rules()
 {
     return array(array('uid', 'default', 'setOnEmpty' => true, 'value' => zmf::uid()), array('open', 'default', 'setOnEmpty' => true, 'value' => 1), array('cTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('open', 'numerical', 'integerOnly' => true), array('uid, logid, cTime', 'length', 'max' => 11), array('classify', 'length', 'max' => 32), array('uid, logid, classify', 'safe', 'on' => 'search'));
 }
Esempio n. 12
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('uid', 'default', 'setOnEmpty' => true, 'value' => zmf::uid()), array('cTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('status', 'default', 'setOnEmpty' => true, 'value' => Posts::STATUS_STAYCHECK), array('uid, title,avatar', 'required'), array('members, status,avatar,creditStatus,areaid', 'numerical', 'integerOnly' => true), array('uid,createAt, cTime,avatar,areaid', 'length', 'max' => 10), array('qq,weixin', 'length', 'max' => 25), array('title,address, slogan, phone,content,tagids,contact,openTime,email,weibo,website', 'length', 'max' => 255));
 }
Esempio n. 13
0
 public function rules()
 {
     return array(array('title,content', 'required'), array('cTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('status', 'default', 'setOnEmpty' => true, 'value' => Posts::STATUS_PASSED), array('uid', 'default', 'setOnEmpty' => true, 'value' => zmf::uid()), array('status, top', 'numerical', 'integerOnly' => true), array('uid, attachid, hits, comments, favors, cTime', 'length', 'max' => 10), array('title, source, sourceurl', 'length', 'max' => 255), array('classify', 'length', 'max' => 16), array('uid, title, classify, content', 'safe', 'on' => 'search'));
 }
Esempio n. 14
0
File: zmf.php Progetto: ph7pal/mei
 /**
  * 格式化时间戳
  * @param type $time
  * @param type $format
  * @return type
  */
 public static function time($time = '', $format = 'Y-m-d H:i:s')
 {
     if (!$time) {
         $time = zmf::now();
     }
     $timeset = date_default_timezone_get();
     if (!in_array($timeset, array('Etc/GMT-8', 'PRC', 'Asia/Shanghai', 'Asia/Shanghai', 'Asia/Chongqing'))) {
         date_default_timezone_set('Etc/GMT-8');
     }
     return date($format, $time);
 }
Esempio n. 15
0
 public function actionUpload()
 {
     $uptype = zmf::filterInput($_GET['type'], 't', 1);
     $logid = zmf::filterInput($_GET['id']);
     //所属对象
     $reImgsize = zmf::filterInput($_GET['imgsize']);
     //返回图片的尺寸
     $fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
     //上传控件的ID
     //将ads替换为flash
     if (!isset($uptype) or !in_array($uptype, array('siteinfo', 'post'))) {
         $this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
     }
     if (Yii::app()->request->getParam('PHPSESSID')) {
         Yii::app()->session->close();
         $res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
         Yii::app()->session->open();
     }
     if (Yii::app()->user->isGuest) {
         $this->jsonOutPut(0, Yii::t('default', 'loginfirst'));
     }
     if (!$fileholder) {
         $fileholder = 'filedata';
     }
     if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
         $this->jsonOutPut(0, '无效上传,请重试');
     }
     $model = new Attachments();
     $img = CUploadedFile::getInstanceByName($fileholder);
     $ext = $img->getExtensionName();
     $size = $img->getSize();
     if ($size > zmf::config('imgMaxSize')) {
         $this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
     }
     $upExt = zmf::config("imgAllowTypes");
     if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
         $this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
     }
     $sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]);
     if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) {
         $this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px.");
     }
     $ctime = zmf::now();
     $dirs = zmf::uploadDirs($ctime, 'app', $uptype, null, true);
     $fileName = uniqid() . '.' . $ext;
     $origin = $dirs['origin'];
     unset($dirs['origin']);
     $uploadedFiles = array();
     $uploadedFiles[] = array('from' => $origin . $fileName, 'to' => zmf::ftpPath($ctime, $uptype, 'origin') . $fileName);
     if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
         $data = array();
         $status = Posts::STATUS_PASSED;
         $data['uid'] = Yii::app()->user->id;
         $data['logid'] = $logid;
         $data['filePath'] = $fileName;
         $data['fileDesc'] = $fileName;
         $data['classify'] = $uptype;
         $data['covered'] = '0';
         $data['cTime'] = time();
         $data['status'] = $status;
         $data['width'] = $sizeinfo[0];
         $data['height'] = $sizeinfo[1];
         $data['size'] = $size;
         $model->attributes = $data;
         if ($model->validate()) {
             if ($model->save()) {
                 $image = Yii::app()->image->load($origin . $fileName);
                 $_quality = zmf::config('imgQuality');
                 $quality = isset($quality) ? $quality : 100;
                 foreach ($dirs as $dk => $_dir) {
                     if ($dk < 600) {
                         $image->smart_resize($dk, $dk * 0.75)->quality($quality);
                     } else {
                         $image->resize($dk, $dk)->quality($quality);
                     }
                     $image->save($_dir . $fileName);
                     $_todir = zmf::ftpPath($ctime, $uptype, $dk);
                     $uploadedFiles[] = array('id' => $model->id, 'from' => $_dir . $fileName, 'to' => $_todir . $fileName);
                 }
                 $imgsize = $reImgsize > 0 ? $reImgsize : 170;
                 $returnimg = zmf::uploadDirs($ctime, 'site', $uptype, $imgsize) . $fileName;
                 $outPutData = array('status' => 1, 'attachid' => $model->id, 'imgsrc' => $returnimg);
                 $json = CJSON::encode($outPutData);
                 echo $json;
             } else {
                 $this->jsonOutPut(0, '写入数据库错误');
             }
         } else {
             $this->jsonOutPut(0, '数据验证错误');
         }
     }
 }
Esempio n. 16
0
 public function actionUpload()
 {
     $uptype = zmf::filterInput($_GET['type'], 't', 1);
     $logid = zmf::filterInput($_GET['id']);
     //所属对象
     $reImgsize = zmf::filterInput($_GET['imgsize']);
     //返回图片的尺寸
     $fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
     //上传控件的ID
     if (!isset($uptype) or !in_array($uptype, array('posts', 'siteinfo'))) {
         $this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
     }
     if (Yii::app()->request->getParam('PHPSESSID')) {
         Yii::app()->session->close();
         $res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
         Yii::app()->session->open();
     }
     if (Yii::app()->user->isGuest) {
         $this->jsonOutPut(0, '请先登录');
     }
     if (!$fileholder) {
         $fileholder = 'filedata';
     }
     if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
         $this->jsonOutPut(0, '无效上传,请重试');
     }
     $img = CUploadedFile::getInstanceByName($fileholder);
     $ext = $img->getExtensionName();
     $size = $img->getSize();
     if ($size > zmf::config('imgMaxSize')) {
         $this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
     }
     $upExt = zmf::config("imgAllowTypes");
     if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
         $this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
     }
     $sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]);
     if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) {
         $this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px.");
     }
     $ctime = zmf::now();
     $dir = zmf::uploadDirs($ctime, 'app', $uptype);
     zmf::createUploadDir($dir);
     $fileName = zmf::uuid() . '.' . $ext;
     $origin = $dir;
     if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
         $data = array();
         $status = Posts::STATUS_NOTPASSED;
         $data['uid'] = zmf::uid();
         $data['logid'] = $logid;
         $data['filePath'] = $fileName;
         $data['fileDesc'] = '';
         $data['classify'] = $uptype;
         $data['covered'] = '0';
         $data['cTime'] = $ctime;
         $data['status'] = $status;
         $data['width'] = $sizeinfo[0];
         $data['height'] = $sizeinfo[1];
         $data['size'] = $size;
         $model = new Attachments();
         $model->attributes = $data;
         if ($model->save()) {
             $attachid = $model->id;
             $returnImgDir = zmf::getUpExtraUrl($ctime);
             $saveName = $uptype . '/' . $returnImgDir . '/' . $fileName;
             $accessKey = zmf::config('qiniuAk');
             $secretKey = zmf::config('qiniuSk');
             $bucket = zmf::config('qiniuBucket');
             if ($accessKey && $secretKey && $bucket) {
                 $auth = new Auth($accessKey, $secretKey);
                 $token = $auth->uploadToken($bucket);
                 $uploadMgr = new UploadManager();
                 list($ret, $err) = $uploadMgr->putFile($token, $saveName, $origin . $fileName);
                 if ($err !== null) {
                     zmf::fp(var_export($err));
                     $this->jsonOutPut(0, '上传至云服务错误');
                 }
             }
             $returnimg = zmf::uploadDirs($ctime, 'site', $uptype) . $fileName;
             $returnimg = zmf::getThumbnailUrl($returnimg, '650', $uptype);
             $_attr = array('id' => $attachid, 'imgurl' => $returnimg);
             $html = '';
             if ($uptype == 'posts') {
                 //$html=  $this->renderPartial('/posts/_addImg',array('data'=>$_attr),true);
             }
             $outPutData = array('status' => 1, 'attachid' => $attachid, 'imgsrc' => $returnimg, 'html' => $html);
             $json = CJSON::encode($outPutData);
             echo $json;
         } else {
             $this->jsonOutPut(0, '写入数据库错误');
         }
     }
 }
Esempio n. 17
0
 public function actionSetStatus()
 {
     $this->checkLogin();
     $keyid = zmf::val('a', 2);
     $classify = zmf::val('b', 1);
     $_status = zmf::val('c', 1);
     if (!$keyid) {
         $this->jsonOutPut(0, '请选择对象');
     }
     if (!in_array($classify, array('posts', 'comments'))) {
         $this->jsonOutPut(0, '不允许的类型');
     }
     if (!in_array($_status, array('del', 'passed'))) {
         $this->jsonOutPut(0, '不允许的类型');
     }
     if ($_status == 'top') {
         if ($classify == 'posts') {
             $attr = array('top' => 1, 'updateTime' => zmf::now());
         } else {
             $attr = array('top' => 1);
         }
     } else {
         if ($_status == 'canceltop') {
             $attr = array('top' => 0);
         } else {
             if ($_status == 'del') {
                 $attr = array('status' => Posts::STATUS_DELED);
             } else {
                 if ($_status == 'passed') {
                     $attr = array('status' => Posts::STATUS_PASSED);
                 }
             }
         }
     }
     $ucClassify = ucfirst($classify);
     if (!class_exists($ucClassify)) {
         $this->jsonOutPut(0, '不存在的类型');
     }
     $model = new $ucClassify();
     if ($model->updateByPk($keyid, $attr)) {
         if ($classify == 'comments') {
             Posts::updateCommentsNum($keyid);
         }
         $this->jsonOutPut(1, '操作成功');
     } else {
         $this->jsonOutPut(0, '操作失败');
     }
 }
Esempio n. 18
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('password, truename, email', 'required'), array('groupid', 'default', 'setOnEmpty' => true, 'value' => zmf::config('userDefaultGroup')), array('register_time, last_login_time', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('status', 'default', 'setOnEmpty' => true, 'value' => Posts::STATUS_PASSED), array('register_ip, last_login_ip', 'default', 'setOnEmpty' => true, 'value' => ip2long(Yii::app()->request->userHostAddress)), array('groupid, status, email_status', 'numerical', 'integerOnly' => true), array('username, password, truename, email,avatar,desc,url', 'length', 'max' => 255), array('register_ip, last_login_ip', 'length', 'max' => 15), array('register_time, last_login_time, login_count,hits,posts', 'length', 'max' => 10), array('id, username, truename, email', 'safe', 'on' => 'search'));
 }
Esempio n. 19
0
File: Users.php Progetto: ph7pal/mei
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('cTime,last_login_time', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('username, email, password, classify,phone', 'required'), array('classify, last_login_ip, status, emailstatus', 'numerical', 'integerOnly' => true), array('username', 'length', 'max' => 50), array('email', 'length', 'max' => 255), array('email', 'email'), array('phone', 'length', 'max' => 16), array('password', 'length', 'max' => 32), array('groupid', 'length', 'max' => 5), array('last_login_time, login_count, cTime, areaid', 'length', 'max' => 10), array('hash', 'length', 'max' => 8), array('id, username, email, phone, password, classify, groupid, last_login_ip, last_login_time, login_count, status, cTime, emailstatus, hash, areaid', 'safe', 'on' => 'search'));
 }
Esempio n. 20
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('uid, logid', 'required'), array('cTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('uid, logid, order, cTime', 'length', 'max' => 10), array('uid, logid', 'safe', 'on' => 'search'));
 }
Esempio n. 21
0
 /**
  * 统计用户的内容数
  */
 public static function getCounts($uid, $info = '')
 {
     if (!$uid) {
         return array();
     }
     if ($info) {
         if (zmf::now() - $info['last_update'] <= 3600) {
             $data = array('posts' => $info['posts'], 'answers' => $info['answers'], 'tips' => $info['tips']);
             return $data;
         }
     }
     $data = array('posts' => Posts::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'answers' => Answer::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'tips' => PoiPost::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'favors' => Favorites::model()->count('uid=:uid AND classify="user"', array(':uid' => $uid)), 'fans' => Favorites::model()->count('logid=:uid AND classify="user"', array(':uid' => $uid)));
     //将统计数据更新到用户统计表
     $data['last_update'] = zmf::now();
     Users::model()->updateByPk($uid, $data);
     return $data;
 }
Esempio n. 22
0
File: Tags.php Progetto: ph7pal/momo
 public static function addRelation($tagid, $logid, $classify)
 {
     if (!$tagid || !$logid || !$classify) {
         return false;
     }
     $_info = TagRelation::model()->find('tagid=:tagid AND logid=:logid AND classify=:classify', array(':tagid' => $tagid, ':logid' => $logid, ':classify' => $classify));
     if (!$_info) {
         $_tagre = array('tagid' => $tagid, 'logid' => $logid, 'classify' => $classify, 'cTime' => zmf::now());
         $modelC = new TagRelation();
         $modelC->attributes = $_tagre;
         return $modelC->save();
     }
     return true;
 }
Esempio n. 23
0
 public static function getNearBy($arr, $origin)
 {
     $lat = $arr['lat'];
     $lng = $arr['long'];
     $notInclude = $arr['notId'];
     $limit = 5;
     if ($origin == '' || !in_array($origin, array('posts', 'position'))) {
         return false;
     }
     $_cal3 = "(ROUND(12756.274 * ASIN(SQRT(POW(SIN(((lat * PI() / 180.0) - ({$lat} * PI() / 180.0))/2),2) +COS(lat * PI() / 180.0)*COS({$lat} * PI() / 180.0)*POW(SIN(((`long` * PI() / 180.0)-({$lng} * PI() / 180.0))/2),2)))))";
     $longSql = "SELECT DISTINCT(id), '{$origin}',{$_cal3} AS distance FROM {{{$origin}}} WHERE status=1 AND id!={$notInclude} AND {$_cal3}<=10 ORDER BY distance LIMIT 0,{$limit}";
     $tops = Yii::app()->db->createCommand($longSql)->queryAll();
     if (!empty($tops)) {
         $ids = join(',', array_keys(CHtml::listData($tops, 'id', '')));
         $_into = zmf::now() . '#' . $ids;
         if ($origin != 'position') {
             Posts::model()->updateByPk($notInclude, array('nearby' => $_into));
             $_sql = "SELECT id,title FROM {{posts}} WHERE id IN({$ids}) AND status=" . Posts::STATUS_PASSED . " ORDER BY FIELD(id,{$ids})";
         } else {
             Position::model()->updateByPk($notInclude, array('nearby' => $_into));
             $_sql = "SELECT id,title_cn,title_en,title_local,score,scorer,classify FROM {{position}} WHERE id IN({$ids}) AND status=" . Posts::STATUS_PASSED . " ORDER BY FIELD(id,{$ids})";
         }
         if ($ids != '') {
             $tops = Yii::app()->db->createCommand($_sql)->queryAll();
         }
     }
     return $tops;
 }
Esempio n. 24
0
 public function actionUpload()
 {
     $uptype = zmf::filterInput($_GET['type'], 't', 1);
     $logid = zmf::filterInput($_GET['id']);
     //所属对象
     $reImgsize = zmf::filterInput($_GET['imgsize']);
     //返回图片的尺寸
     $fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
     //上传控件的ID
     //将ads替换为flash
     if (!isset($uptype) or !in_array($uptype, array('columns', 'coverimg', 'flash', 'link', 'album', 'posts', 'poi', 'poipost', 'answer', 'question', 'siteinfo', 'goods', 'group', 'avatar'))) {
         $this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
     }
     if (Yii::app()->request->getParam('PHPSESSID')) {
         Yii::app()->session->close();
         $res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
         Yii::app()->session->open();
     }
     if (Yii::app()->user->isGuest) {
         $this->jsonOutPut(0, Yii::t('default', 'loginfirst'));
     }
     $checkInfo = UserPower::check('addImage', true);
     if (!$checkInfo['status']) {
         $this->jsonOutPut(0, $checkInfo['msg']);
     }
     if ($uptype == 'poi') {
         if (!$logid || !is_numeric($logid)) {
             $this->jsonOutPut(0, '无效上传,请重试');
         } else {
             $poiInfo = Position::model()->findByPk($logid);
             if (!$poiInfo || $poiInfo['status'] != Posts::STATUS_PASSED) {
                 $this->jsonOutPut(0, '无效上传,请重试');
             }
         }
     }
     if (!$fileholder) {
         $fileholder = 'filedata';
     }
     if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
         $this->jsonOutPut(0, '无效上传,请重试');
     }
     $model = new Attachments();
     $img = CUploadedFile::getInstanceByName($fileholder);
     $ext = $img->getExtensionName();
     $size = $img->getSize();
     if ($size > zmf::config('imgMaxSize')) {
         $this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
     }
     $upExt = zmf::config("imgAllowTypes");
     if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
         $this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
     }
     $sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]);
     if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) {
         $this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px.");
     }
     $ctime = zmf::now();
     $uid = zmf::uid();
     $dirs = zmf::uploadDirs($ctime, 'app', $uptype, null, true);
     $fileName = uniqid() . '.' . $ext;
     $origin = $dirs['origin'];
     unset($dirs['origin']);
     $uploadedFiles = array();
     $uploadedFiles[] = array('from' => $origin . $fileName, 'to' => zmf::ftpPath($ctime, $uptype, 'origin') . $fileName);
     if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
         $data = array();
         if ($uptype == 'posts') {
             $status = Posts::STATUS_DELED;
         } else {
             $status = Posts::STATUS_PASSED;
         }
         $data['uid'] = $uid;
         $data['logid'] = $logid;
         $data['filePath'] = $fileName;
         $data['fileDesc'] = $fileName;
         $data['classify'] = $uptype;
         $data['covered'] = '0';
         $data['cTime'] = time();
         $data['status'] = $status;
         $data['width'] = $sizeinfo[0];
         $data['height'] = $sizeinfo[1];
         $data['size'] = $size;
         if ($uptype == 'poi') {
             $data['areaid'] = $poiInfo['areaid'];
         }
         $model->attributes = $data;
         if ($model->validate()) {
             if ($model->save()) {
                 if ($uptype == 'poi') {
                     Posts::updateCount($logid, 'Position', 1, 'attach');
                 } elseif ($uptype == 'avatar') {
                     Users::model()->updateByPk($uid, array('avatar' => $model->id));
                 }
                 //                    $image = Yii::app()->image->load($origin . $fileName);
                 //                    $_quality = zmf::config('imgQuality');
                 //                    $quality = isset($quality) ? $quality : 100;
                 Yii::import('application.vendors.thinkphp.*');
                 require_once 'ImageGd.php';
                 if (in_array($uptype, array('group', 'avatar'))) {
                     $rate = 1;
                 } else {
                     $rate = 0.75;
                 }
                 foreach ($dirs as $dk => $_dir) {
                     $image = new ImageGd($origin . $fileName);
                     if ($dk < 600) {
                         $image->thumb($dk, $dk * $rate, 'center');
                     } else {
                         $image->thumb($dk, 10000);
                         //$image->water(Yii::app()->basePath . '/../common/images/water.png',2);
                     }
                     $image->save($_dir . $fileName);
                     $_todir = zmf::ftpPath($ctime, $uptype, $dk);
                     $uploadedFiles[] = array('id' => $model->id, 'from' => $_dir . $fileName, 'to' => $_todir . $fileName);
                 }
                 $imgsize = $reImgsize > 0 ? $reImgsize : 170;
                 $returnimg = zmf::uploadDirs($ctime, 'site', $uptype, $imgsize) . $fileName;
                 $outPutData = array('status' => 1, 'attachid' => $model->id, 'imgsrc' => $returnimg);
                 $json = CJSON::encode($outPutData);
                 if (zmf::config('ftpon')) {
                     $asyncdata = "method=ftpupload&json=" . zmf::jiaMi(CJSON::encode($uploadedFiles));
                     AsyncController::Async($asyncdata);
                 }
                 if ($uptype == 'avatar') {
                     zmf::delFCache("userInfo-{$uid}");
                 }
                 echo $json;
             } else {
                 $this->jsonOutPut(0, '写入数据库错误');
             }
         } else {
             $this->jsonOutPut(0, '数据验证错误');
         }
     } else {
         $this->jsonOutPut(0, '移动到指定文件夹出错');
     }
 }
Esempio n. 25
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('content', 'required'), array('cTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('ip', 'default', 'setOnEmpty' => true, 'value' => ip2long(Yii::app()->request->userHostAddress)), array('status', 'numerical', 'integerOnly' => true), array('uid,cTime', 'length', 'max' => 10), array('ip', 'length', 'max' => 25), array('contact, appinfo, sysinfo, content', 'length', 'max' => 255), array('type', 'length', 'max' => 8), array('id, uid, contact, appinfo, sysinfo, content, type, ip, cTime, status', 'safe', 'on' => 'search'));
 }
Esempio n. 26
0
 /**
  * 问题的赞成反对及其他点赞
  */
 public function actionFavor()
 {
     //        Users::checkPower('favor');
     $type = zmf::filterInput($_POST['type'], 't', 1);
     $keyid = zmf::filterInput($_POST['keyid']);
     if (!$keyid) {
         $this->jsonOutPut(0, Yii::t('default', 'pagenotexists'));
     }
     if (!isset($type) or empty($type) or !in_array($type, array('naodong'))) {
         //Forbidden::updateTimes();
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     if (zmf::actionLimit('favor-' . $type, $keyid)) {
         $this->jsonOutPut(0, '操作太频繁,请稍后再试');
     }
     if ($type == 'naodong') {
         $classify = 'favorNaodong';
         $model = new Naodong();
         $field = 'favors';
     }
     if (!$model) {
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     $info = $model->findByPk($keyid);
     if (!$info) {
         $this->jsonOutPut(0, Yii::t('default', 'pagenotexists'));
     } elseif ($info['status'] != Posts::STATUS_PASSED) {
         $this->jsonOutPut(0, '您操作的内容正在审核或已删除');
     }
     //        elseif ($info['uid'] == zmf::uid()) {
     //            $this->jsonOutPut(0, '不能操作自己的哦~');
     //        }
     if (UserAction::checkAction($keyid, $classify)) {
         if (UserAction::delAction($keyid, $classify)) {
             if ($field) {
                 $model->updateCounters(array($field => -1), 'id=:id', array(':id' => $keyid));
             }
             $this->jsonOutPut(3, '取消赞成功');
         } else {
             $this->jsonOutPut(0, '取消赞失败');
         }
     } else {
         if (UserAction::recordAction($keyid, $classify, $info['uid'])) {
             if ($field) {
                 if ($model->updateCounters(array($field => 1), 'id=:id', array(':id' => $keyid))) {
                     if ($type == 'naodong') {
                         $_url = CHtml::link('查看详情', array('index/view', 'id' => $keyid));
                         $_content = '您的作品有了新的赞,' . $_url;
                         $toNotice = true;
                     }
                     if ($toNotice) {
                         $_noticedata = array('uid' => $info['uid'], 'authorid' => $this->uid, 'content' => $_content, 'new' => 1, 'type' => 'favor', 'cTime' => zmf::now(), 'from_id' => $keyid, 'from_num' => 1);
                         Notification::add($_noticedata);
                     }
                 }
             }
             $this->jsonOutPut(1, '添加赞成功');
         } else {
             $this->jsonOutPut(0, '添加赞失败');
         }
     }
 }
Esempio n. 27
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('uid', 'default', 'setOnEmpty' => true, 'value' => zmf::uid()), array('uid, title,code, content', 'required'), array('code', 'unique'), array('status', 'default', 'setOnEmpty' => true, 'value' => Posts::STATUS_PASSED), array('status', 'numerical', 'integerOnly' => true), array('cTime,updateTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('uid, colid, faceimg, hits, cTime, updateTime', 'length', 'max' => 10), array('code', 'length', 'max' => 16), array('title', 'length', 'max' => 255), array('id, uid, colid, faceimg, code, title, content, hits, cTime, updateTime, status', 'safe', 'on' => 'search'));
 }
Esempio n. 28
0
 public function checkUser()
 {
     if (!$this->usercode) {
         self::output('缺少参数:usercode', $this->errorCode);
     }
     $code = zmf::jieMi($this->usercode);
     $arr = explode('#', $code);
     //如果不能解密字符串,或者不是类似于'123#ios#1412555521'则报错
     if (!$code || !$arr || count($arr) != 3 || $arr[1] != $this->appPlatform) {
         self::output('验证用户信息失败,请重新登录', 400);
     }
     $this->uid = $arr[0];
     $this->userInfo = User::model()->findByPk($this->uid);
     if (!$this->userInfo) {
         self::output('验证用户信息错误:不存在的用户', 400);
     }
     if ($this->userInfo['code'] != $this->usercode) {
         self::output('您的账号已在其他设备登录,请重新登录', 400);
     }
     //如果已经过期
     if (zmf::now() - $arr[2] > 86400 * 30) {
         self::output('由于长时间未登录,请重新登录', 400);
     }
 }
Esempio n. 29
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('uid, token, openid', 'required'), array('web, app', 'numerical', 'integerOnly' => true), array('cTime,updateTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('uid, expires, cTime, updateTime', 'length', 'max' => 10), array('token,openid', 'length', 'max' => 255), array('data', 'safe'), array('uid, token, openid, web, app, expires, data, cTime, updateTime', 'safe', 'on' => 'search'));
 }
Esempio n. 30
0
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array(array('cTime', 'default', 'setOnEmpty' => true, 'value' => zmf::now()), array('groupid, uid', 'required'), array('isAdmin', 'numerical', 'integerOnly' => true), array('uid,cTime', 'length', 'max' => 10), array('groupid', 'length', 'max' => 19), array('groupid, uid, isAdmin', 'safe', 'on' => 'search'));
 }