public function setGroup($uid, $title, $gid = NULL)
 {
     F(self::CACHE_PREFIX . "list_" . $uid, null);
     F(self::CACHE_PREFIX . "usergroup_{$uid}_{$gid}", null);
     $uid = intval($uid);
     $title = h(mStr($title, 8, 'utf-8', false));
     if (!$title) {
         return 0;
     }
     //查看分组是否已存在
     $map = array('uid' => $uid, 'title' => $title);
     $_gid = $this->getField('follow_group_id', $map);
     if (!$_gid) {
         if ($gid == NULL) {
             $data = array('uid' => $uid, 'title' => $title, 'ctime' => time());
             $gid = $this->add($data);
             return $gid;
         } else {
             $gid = intval($gid);
             if (!$gid) {
                 return 0;
             }
             $data = array('follow_group_id' => $gid, 'uid' => $uid, 'title' => $title);
             $res = $this->save($data);
             return 1;
         }
     } elseif ($_gid == $gid) {
         return 1;
     } else {
         return 0;
     }
 }
 /**
  * 获取给定话题名的话题ID
  *
  * @param string $name 话题名
  * @return int 话题ID
  */
 public function getTopicId($name)
 {
     $topic_length = 20;
     $map['name'] = trim(t(mStr(preg_replace("/#/", '', $name), $topic_length, 'utf-8', false)));
     if (empty($map['name'])) {
         return 0;
     }
     $info = $this->where($map)->find();
     if ($info['topic_id']) {
         return $info['topic_id'];
     } else {
         $map['count'] = 0;
         $map['ctime'] = time();
         return $this->add($map);
     }
 }
Пример #3
0
 public function addDigg($feed_id, $mid)
 {
     $data['feed_id'] = $feed_id;
     $data['uid'] = $mid;
     $data['uid'] = !$data['uid'] ? $GLOBALS['ts']['mid'] : $data['uid'];
     if (!$data['uid']) {
         $this->error = '未登录不能赞';
         return false;
     }
     $isExit = $this->where($data)->getField('id');
     if ($isExit) {
         $this->error = '你已经赞过';
         return false;
     }
     $data['cTime'] = time();
     $res = $this->add($data);
     //dump($res);dump($this->getLastSql());
     if ($res) {
         $feed = model('Source')->getSourceInfo('feed', $feed_id);
         $result = model('Feed')->where('feed_id=' . $feed_id)->setInc('digg_count');
         model('Feed')->cleanCache($feed_id);
         // dump($result);dump(model('Feed')->getLastSql());
         // 增加通知::  {user} 赞了你的微博:{content}。<a href="{sourceurl}" target='_blank'>去看看>></a>
         $author = model('User')->getUserInfo($mid);
         $config['user'] = '******' . $author['space_url'] . '" >' . $author['uname'] . '</a>';
         $config['content'] = t($feed['source_body']);
         $config['content'] = str_replace('◆', '', $config['content']);
         $config['content'] = mStr($config['content'], 34);
         $config['sourceurl'] = $feed['source_url'];
         model('Notify')->sendNotify($feed['uid'], 'digg', $config);
         //增加积分
         model('Credit')->setUserCredit($mid, 'digg_weibo');
         model('Credit')->setUserCredit($feed['uid'], 'digged_weibo');
     }
     return $res;
 }
Пример #4
0
 /**
  * 保存相册编辑信息
  * @return void
  */
 public function do_update_album()
 {
     // 相册信息
     $albumId = intval($_POST['albumId']);
     $album_name = t($_POST['album_name']);
     $album_cover = intval($_POST['album_cover']);
     $album_privacy = intval($_POST['album_privacy']);
     $album_privacy_data = t($_POST['album_privacy_data']);
     $albumDao = D('Album', 'photo');
     $photoDao = D('Photo', 'photo');
     // 获取相册信息
     $albumInfo = $albumDao->where("id='{$albumId}' AND userId='{$this->mid}' ")->find();
     if (!$albumInfo) {
         $this->error('你没有权限编辑该相册!');
     }
     //解析图片数据
     foreach ($_POST['name'] as $k => $v) {
         $new_photos[$k]['name'] = t($v);
         $new_photoids[] = t($k);
     }
     foreach ($_POST['move_to'] as $k => $v) {
         $new_photos[$k]['albumId'] = t($v);
     }
     // 对比原始数据,筛选出需要更新的图片
     $photo_ids['id'] = array('IN', $new_photoids);
     $old_photos = $photoDao->where($photo_ids)->findAll();
     foreach ($old_photos as $k => $v) {
         // 如果相册ID和名称都没变化,不需要保存
         $photoid = $v['id'];
         if ($v['albumId'] == $new_photos[$photoid]['albumId'] && $v['name'] == $new_photos[$photoid]['name']) {
             unset($new_photos[$photoid]);
         }
     }
     // 保存图片信息
     foreach ($new_photos as $k => $v) {
         unset($map);
         $map['userId'] = $this->mid;
         $map['albumId'] = $v['albumId'];
         $map['name'] = $v['name'];
         $map['privacy'] = $album_privacy;
         // 相册信息更新
         $photoDao->limit(1)->where("id='{$k}'")->save($map);
         // 重置相册图片数
         $albumDao->updateAlbumPhotoCount($map['albumId']);
     }
     // 重置相册图片数
     $albumDao->updateAlbumPhotoCount($albumId);
     // 如果相册封面发生变化
     if ($albumInfo['coverImageId'] != $album_cover) {
         $album['coverImageId'] = $album_cover;
         if ($coverInfo = $photoDao->field('id, savepath')->find($album_cover)) {
             $album['coverImagePath'] = $coverInfo['savepath'];
         }
     }
     // 如果相册隐私发生变化
     if ($albumInfo['privacy'] != $album_privacy) {
         $album['privacy'] = $album_privacy;
         // 更新该相册下所有图片的隐私
         unset($map);
         $map['privacy'] = $album_privacy;
         $photoDao->where("albumId='{$albumId}'")->save($map);
     }
     // 如果相册隐私数据发生变化
     if ($albumInfo['privacy_data'] != $album_privacy_data) {
         $album['privacy_data'] = h(t($album_privacy_data));
     }
     $album['name'] = h(t(mStr($album_name, 14, 'utf-8', false)));
     $result = $albumDao->where("id='{$albumId}'")->save($album);
     // 跳转到相册页面
     $this->assign('jumpUrl', U('/Index/album', array(id => $albumId, uid => $this->mid)));
     $this->success('相册编辑成功!');
 }
 function followtopic()
 {
     $name = $_POST['name'];
     $topicId = D('Topic')->getTopicId($name);
     if ($topicId) {
         $id = D('Follow')->dofollow($this->mid, $topicId, 1);
     }
     echo json_encode(array('code' => $id, 'topicId' => $topicId, 'name' => h(t(mStr(preg_replace("/#/", '', $name), 150, 'utf-8', false)))));
 }