Ejemplo n.º 1
0
 /**
  * 获取长文本广播
  */
 public function long_text()
 {
     if (request::method() != 'get') {
         $this->send_response(400, NULL, '400:无法接受GET以外请求方式');
     }
     $statuses_id = $this->input->get('statuses_id', '');
     $pagesize = $this->input->get('pagesize', 0);
     $page = $this->input->get('page', 1);
     $pagepad = $page > 1 ? ($page - 1) * $pagesize : 0;
     if ($statuses_id) {
         $feed = $this->feedModel->findFeed($statuses_id);
         $str_count = str::strLen($feed['long_text']);
         if ($pagesize && $str_count > $pagesize) {
             $tmp_text = str::cnSubstr($feed['long_text'], $pagepad, $pagesize);
         } else {
             $tmp_text = $feed['long_text'];
         }
     }
     $data = array('id' => $statuses_id, 'pagesize' => $pagesize, 'page' => $page, 'total' => $str_count, 'text' => $tmp_text, 'at' => $feed['at']);
     $this->send_response(200, $data);
 }
Ejemplo n.º 2
0
 /**
  *
  * 评论mo短信
  * @param string $feedid
  * @param array $at
  */
 private function mo_sms_comment($commentid, $feedid, $receiver_uid, $receiver_name, $moid = '', $auto)
 {
     $type = $this->format_type($typeid);
     $sender_uid = $this->uid;
     $sender_name = sns::getrealname($this->uid);
     //检查接收者是否在自己联系人中,并且接收者级别<3
     if (Friend_Model::instance()->check_iscontact($sender_uid, $receiver_uid)) {
         $receiver_status = sns::getstatus($receiver_uid);
         if ($receiver_status >= 3 && $auto == true) {
             return false;
         }
     } else {
         return false;
     }
     //接收者的用户基本要<2x
     if (!$this->is_mo_sms_sent('comment', $feedid, $sender_uid, $receiver_uid, $moid)) {
         $receiver_info = sns::getuser($receiver_uid);
         $url_code = Url_Model::instance()->create('status', $sender_uid, $sender_name, $receiver_uid, $receiver_name, $receiver_info['mobile'], $receiver_info['zone_code'], $feedid);
         $short_url = MO_SMS_JUMP . $url_code;
         $comment_row = $this->comment_new->findOne(array('id' => $commentid));
         if ($comment_row) {
             $content = str::cnSubstr($this->feed_at_format($comment_row['content'], $comment_row['at']), 0, 15) . '..';
             $data = array();
             $data['sender']['id'] = $sender_uid;
             $data['sender']['name'] = $sender_name;
             $data['receiver'][] = $receiver_uid;
             $data['timestamp'] = time();
             $data['content']['text'] = $sender_name . '分享了:' . $content . ',点开互动: ' . $short_url;
             $mq_msg = array("kind" => "mobile_sms", "data" => $data);
             $this->mq_send(json_encode($mq_msg), $this->uid, 'momo_im');
             $this->mo_sms_log('comment', $commentid, $feedid, $this->uid, $receiver_uid, $moid);
             if ($moid) {
                 $this->update_my_mo($moid);
             }
             return true;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * 
  * @param $uid
  * @param $site
  * @param $content
  * @param $image
  * @return unknown_type
  */
 private function _sync_weibo($sync, $uid, $site, $title, $description, $image, $location)
 {
     $res = array();
     if (is_array($sync) && count($sync) > 0 && $title && $description && $image) {
         if ($sync['weibo']) {
             require_once Kohana::find_file('vendor', 'weibo/saetv2.ex.class');
             $oauth = Kohana::config('uap.oauth');
             $token = Bind_Model::instance()->oauth2_check($uid, 'weibo');
             $updated_time = $token['updated'] ? $token['updated'] : $token['created'];
             if ($updated_time + $token['expires_in'] > time()) {
                 $c = new SaeTClientV2($oauth['weibo.com']['WB_AKEY'], $oauth['weibo.com']['WB_SKEY'], $token['access_token']);
                 if ($c) {
                     $img = $this->model->_warp_image($image);
                     $img_url = $img[0]['url'] ? $img[0]['url'] : '';
                     $content = '#' . $title . '#' . $description;
                     $content = str::strLen($content) > 120 ? str::cnSubstr($content, 0, 120) . '..' : $content;
                     //$img_url = 'http://momoimg.com/photo/3846870_LrurOnCRM365Gc_cI0ferPZaqFP2hLDtdsB2R1WtHFsrGiLDQ647LfN09AM_780.jpg';
                     $latitude = $location['latitude'] ? $location['latitude'] : NULL;
                     $longitude = $location['longitude'] ? $location['longitude'] : NULL;
                     if ($img_url) {
                         $result = $c->upload($content, $img_url, $latitude, $longitude);
                     } else {
                         $result = $c->update($content, $latitude, $longitude);
                     }
                     if ($result['id']) {
                         $res = array('weibo' => 1);
                     } else {
                         $res = array('weibo' => 0, 'error' => $result['error'], 'type' => 'error');
                     }
                 }
             } else {
                 $res = array('weibo' => 0, 'error' => 'access_token expired!', 'type' => 'expire');
             }
         }
     }
     return $res;
 }
Ejemplo n.º 4
0
 /**
  * 创建活动
  */
 public function create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400505:活动信息非法');
     }
     $post = new Validation($data);
     $post->add_rules('title', 'required', 'length[1, 30]');
     $post->add_rules('content', 'required', 'length[0, 10000]');
     $post->add_rules('start_time', 'required');
     //$post->add_rules('end_time', 'required');
     //$post->add_rules('assemble_location', 'required');
     $post->add_rules('event_location', 'required');
     $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation'));
     $post->add_callbacks(TRUE, array($this, '_check_time_validation'));
     if ($post->validate()) {
         $form = $post->as_array();
         $event = array();
         $event['organizer'] = $this->user_id;
         $event['type'] = $form['type'];
         $event['title'] = $form['title'];
         $event['summary'] = empty($form['summary']) ? '' : $form['summary'];
         $event['deadline'] = empty($form['deadline']) ? 0 : $form['deadline'];
         $event['apply_desc'] = empty($form['apply_desc']) ? '' : $form['apply_desc'];
         $event['content'] = $form['content'];
         $event['start_time'] = $form['start_time'];
         if ($form['end_time']) {
             $event['end_time'] = $form['end_time'];
         }
         $event['city'] = $form['city'] ? $form['city'] : 3501;
         $event['private'] = (int) $form['private'];
         $event['fee'] = $form['fee'] ? $form['fee'] : '';
         if ($form['apply_doc']) {
             if (!$this->_check_apply_doc($form['apply_doc'])) {
                 $this->send_response(400, NULL, '400413:apply_doc信息非法');
             }
             $event['apply_doc'] = serialize($form['apply_doc']);
         }
         $event['status'] = 1;
         $event['create_time'] = time();
         $event['event_location'] = serialize($form['event_location']);
         if ($form['assemble_location']) {
             $event['assemble_location'] = serialize($form['assemble_location']);
         }
         $event_id = $this->model->add($event);
         if ($event_id) {
             if ($form['image']) {
                 $this->_create_event_image($event_id, $form['image']);
             }
             if ($form['apply_doc']) {
                 $this->_create_event_apply_doc($event_id, $form['apply_doc']);
             }
             //创建群组
             $group_id = $this->_create_group($event);
             if ($group_id) {
                 $this->_add_group_user($group_id, $this->user_id, Kohana::config('group.grade.master'));
                 $this->model->update($event_id, array('gid' => $group_id));
             }
             $user = sns::getuser($this->user_id);
             $eventUser = array('eid' => $event_id, 'pid' => 0, 'uid' => $this->user_id, 'name' => $user['realname'], 'mobile' => $user['mobile'], 'apply_type' => Kohana::config('event.apply_type.joined'), 'apply_time' => time(), 'grade' => Kohana::config('event.grade.creator'));
             $this->model->applyEvent($eventUser);
             $opt = array('event' => array('id' => $event_id, 'name' => $event['title'], 'cover' => ''), 'no_sign' => 1);
             $event_url = MO_EVENT . 'event/show/' . $event_id;
             $short_title = str::strLen($event['title']) > 10 ? str::cnSubstr($event['title'], 0, 10) . '..' : $event['title'];
             $event_short_url = url::getShortUrl($event_url);
             $content = '【' . $event_short_url . ' 】由' . $user['realname'] . '发起的活动,快来参加吧';
             $this->send_event_mq(Kohana::config('uap.xiaomo'), $this->user_id, $content, $opt);
             $this->send_response(200, array('id' => floatval($event_id), 'gid' => (int) $group_id));
         }
         $this->send_response(400, NULL, '400413:活动发布失败');
     }
     $errors = $post->errors();
     foreach ($errors as $key => $value) {
         switch ($key) {
             case 'type':
                 $this->send_response(400, NULL, '400405:活动类型为空');
                 break;
             case 'start_time':
                 $this->send_response(400, NULL, '400406:活动开始时间为空');
                 break;
             case 'end_time':
                 $this->send_response(400, NULL, '400407:活动结束时间为空');
                 break;
             case 'assemble_location':
                 $this->send_response(400, NULL, '400408:集合地点为空');
                 break;
             case 'event_location':
                 $this->send_response(400, NULL, '400409:活动地点为空');
                 break;
             case 'end_before_start':
                 $this->send_response(400, NULL, '400410:活动结束时间必须大于开始时间');
                 break;
             case 'content':
                 $this->send_response(400, NULL, '400411:活动内容为空');
                 break;
             default:
                 $this->send_response(400, NULL, '400412:活动信息非法');
                 break;
         }
     }
     $this->send_response(400, NULL, '400412:活动信息非法');
 }