/**
  * 修改截取后的头像
  */
 public function ModifyAvator()
 {
     $ShearPhoto["config"] = array("proportional" => 0);
     import('Vendor.ShearPhoto.ShearPhoto');
     $Shear = new \ShearPhoto(ACPopedom::mixPass(ACPopedom::getID()));
     $tmp_name = $Shear->run(json_decode(trim(stripslashes($_POST["JSdate"])), true), $ShearPhoto["config"]);
     //传入参数运行
     if (!$tmp_name) {
         $this->ajaxReturn(array('erro' => '头像保存失败'));
     }
     $filename = $Shear->filename . $Shear->imagesuffix;
     //又拍云上传
     import('Vendor.Upyun.UpYunApi');
     $upYunApi = new \UpYunApi(UPYUN_BUCKET, UPYUN_USERNAME, UPYUN_PASSWORD);
     $upYunApi->debug = false;
     $upYunApi->setApiDomain(UPYUN_HOST);
     $fh = fopen($tmp_name, 'rb');
     $rsp = $upYunApi->writeFile('/Attachment/face/' . $filename, $fh, true);
     if (file_exists(ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . $Shear->filename)) {
         unlink(ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . $filename);
     }
     fclose($fh);
     if ($rsp) {
         $result = M('Users')->where('userid = ' . ACPopedom::getID())->save(array('avator' => UPYUN_BASIC_URL . '/Attachment/face/' . $filename));
         if ($result !== false) {
             $userinfo = ACPopedom::getUserInfo();
             cookie("__info__", authcode(serialize(array('nickname' => $userinfo['nickname'], 'userid' => $userinfo['userid'], 'avator' => UPYUN_BASIC_URL . '/Attachment/face/' . $filename)), "ENCODE", SESSION_AUTH, C('COOKIE_EXPIRE')));
             $this->ajaxReturn(array('success' => '截图成功!如不能立即显示,请多刷新两次', 'url' => U('Web/UserCenter/index')));
         } else {
             $this->ajaxReturn(array('erro' => '头像更新失败'));
         }
     } else {
         $this->ajaxReturn(array('erro' => '头像更新失败'));
     }
 }
Esempio n. 2
0
 /**
  * 点赞一条feed
  */
 public function praise()
 {
     $feedid = intval(I('post.feedid', ''));
     \Predis\Autoloader::register();
     $redis = new \Predis\Client();
     if ($redis->zscore('feed:' . $feedid . ':praise', ACPopedom::getID())) {
         $res = $redis->zrem('feed:' . $feedid . ':praise', ACPopedom::getID());
         $rs = $redis->hincrby('feed:' . $feedid, 'praise', -1);
         $this->ajaxReturn($res && $rs ? array('status' => true) : array('status' => false, 'message' => '由于服务器君罢工,取消点赞失败失败啦..'));
     } else {
         $rs = $redis->zadd('feed:' . $feedid . ':praise', time(), ACPopedom::getID());
         $result = $redis->hincrby('feed:' . $feedid, 'praise', 1);
         $this->ajaxReturn($result && $rs ? array('status' => true, 'message' => '点赞成功了,么么哒') : array('status' => false, 'message' => '由于服务器君罢工,点赞失败失败啦..'));
     }
 }
 public function index()
 {
     \Predis\Autoloader::register();
     $redis = new \Predis\Client();
     $feedList = M('Feed')->alias('f')->field('f.feedid,f.posttime,f.show,f.content,f.picpath,f.appid,u.avator,u.nickname')->join(array('__USERS__ AS u ON f.userid =  u.userid '))->where('f.userid = ' . ACPopedom::getID())->select();
     foreach ($feedList as $key => $value) {
         $feedList[$key]['posttime'] = beforeTime($value['posttime']);
         if ($value['picpath']) {
             $feedList[$key]['picpath'] = explode('#$', $value['picpath']);
             $feedList[$key]['pic-col'] = count($feedList[$key]['picpath']) > 4 ? 3 : 12 / count($feedList[$key]['picpath']);
         }
         //取出点赞数
         $praise = $redis->hget('feed:' . $value['feedid'], 'praise');
         $feedList[$key]['praise'] = $praise ? $praise : 0;
     }
     //var_dump($feedList);
     $this->assign('feedlist', $feedList);
     $this->assign('userinfo', ACPopedom::getUserInfo());
     $this->display();
 }