Inheritance: extends CActiveRecord
Esempio n. 1
0
 /**
  * @param Notice $notice
  * @return string
  **/
 public function send(Notice $notice)
 {
     $curl = curl_init();
     $xml = $notice->toXml($this->configuration);
     curl_setopt($curl, CURLOPT_URL, $this->configuration->get('apiEndPoint'));
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_TIMEOUT, $this->configuration->get('timeout'));
     curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
     // HTTP proxy support
     $proxyHost = $this->configuration->get('proxyHost');
     $proxyUser = $this->configuration->get('proxyUser');
     if (null !== $proxyHost) {
         curl_setopt($curl, CURLOPT_PROXY, $proxyHost . ':' . $this->configuration->get('proxyPort'));
         if (null !== $proxyUser) {
             curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyUser . ':' . $this->configuration->get('proxyPass'));
         }
     }
     $return = curl_exec($curl);
     curl_close($curl);
     return $return;
 }
 /**
  * If poster is in one of the forced groups, make sure their notice
  * gets saved into that group even if not explicitly mentioned.
  *
  * @param Notice $notice
  * @return boolean event hook return
  */
 function onStartNoticeDistribute($notice)
 {
     $profile = $notice->getProfile();
     $isRemote = !User::getKV('id', $profile->id);
     if ($isRemote) {
         /*
          * Notices from remote users on other sites
          * will normally not end up here unless they're
          * specifically directed here, e.g.: via explicit
          * post to a remote (to them) group. But remote
          * notices can also be `pulled in' as a result of
          * local users subscribing to the remote user;
          * from the remote user's perspective, this results
          * in group-forcing appearing effectively random.
          * So let's be consistent, and just never force
          * incoming remote notices into a ForceGroup:
          */
         return true;
     }
     foreach ($this->post as $nickname) {
         $group = User_group::getForNickname($nickname);
         if ($group && $profile->isMember($group)) {
             $notice->addToGroupInbox($group);
         }
     }
     return true;
 }
 /**
  * Handle distribution of a notice after we've saved it:
  * @li add to local recipient inboxes
  * @li send email notifications to local @-reply targets
  * @li run final EndNoticeSave plugin events
  * @li put any remaining post-processing into the queues
  *
  * If this function indicates failure, a warning will be logged
  * and the item is placed back in the queue to be re-run.
  *
  * @fixme addToInboxes is known to fail sometimes with large recipient sets
  *
  * @param Notice $notice
  * @return boolean true on success, false on failure
  */
 function handle($notice)
 {
     try {
         $notice->addToInboxes();
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         $notice->sendReplyNotifications();
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         Event::handle('EndNoticeDistribute', array($notice));
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         Event::handle('EndNoticeSave', array($notice));
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         // Enqueue for other handlers
         common_enqueue_notice($notice);
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     return true;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     // XXX It would be nice to do this without a join
     // (necessary to do it efficiently on accounts with long history)
     $notice = new Notice();
     $query = "select id from notice join notice_tag on id=notice_id where tag='" . $notice->escape($this->tag) . "' and profile_id=" . intval($this->profile->id);
     $since = Notice::whereSinceId($since_id, 'id', 'notice.created');
     if ($since) {
         $query .= " and ({$since})";
     }
     $max = Notice::whereMaxId($max_id, 'id', 'notice.created');
     if ($max) {
         $query .= " and ({$max})";
     }
     $query .= ' order by notice.created DESC, id DESC';
     if (!is_null($offset)) {
         $query .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset);
     }
     $notice->query($query);
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     return $ids;
 }
 static function getStreamByIds($ids)
 {
     $cache = Cache::instance();
     if (!empty($cache)) {
         $notices = array();
         foreach ($ids as $id) {
             $n = Notice::staticGet('id', $id);
             if (!empty($n)) {
                 $notices[] = $n;
             }
         }
         return new ArrayWrapper($notices);
     } else {
         $notice = new Notice();
         if (empty($ids)) {
             //if no IDs requested, just return the notice object
             return $notice;
         }
         $notice->whereAdd('id in (' . implode(', ', $ids) . ')');
         $notice->find();
         $temp = array();
         while ($notice->fetch()) {
             $temp[$notice->id] = clone $notice;
         }
         $wrapped = array();
         foreach ($ids as $id) {
             if (array_key_exists($id, $temp)) {
                 $wrapped[] = $temp[$id];
             }
         }
         return new ArrayWrapper($wrapped);
     }
 }
 function getNoticeIds($offset, $limit, $since_id = null, $max_id = null)
 {
     $notice = new Notice();
     // SELECT
     $notice->selectAdd();
     $notice->selectAdd('id');
     // WHERE
     $notice->conversation = $this->id;
     if (!empty($since_id)) {
         $notice->whereAdd(sprintf('notice.id > %d', $since_id));
     }
     if (!empty($max_id)) {
         $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
     }
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     if (!empty($this->selectVerbs)) {
         $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
     }
     // ORDER BY
     // currently imitates the previously used "_reverseChron" sorting
     $notice->orderBy('notice.created DESC');
     $notice->find();
     return $notice->fetchAll('id');
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $qry = null;
     $qry = 'SELECT notice.* FROM notice ';
     $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
     $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
     if ($since_id != 0) {
         $qry .= 'AND notice.id > ' . $since_id . ' ';
     }
     if ($max_id != 0) {
         $qry .= 'AND notice.id <= ' . $max_id . ' ';
     }
     // NOTE: we sort by event time, not by notice time!
     $qry .= 'ORDER BY happening.created DESC ';
     if (!is_null($offset)) {
         $qry .= "LIMIT {$limit} OFFSET {$offset}";
     }
     $notice->query($qry);
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     $notice->free();
     unset($notice);
     return $ids;
 }
Esempio n. 8
0
 /**
  * @param Notice $notice
  * @return string
  **/
 public function send(Notice $notice)
 {
     $xml = $notice->toXml($this->configuration);
     $opts = array('http' => array('method' => 'POST', 'header' => $this->headers, 'content' => $xml));
     $context = stream_context_create($opts);
     $result = file_get_contents($this->configuration->apiEndPoint, false, $context);
     return $result;
 }
 /**
  * Fetch the next self::DELETION_WINDOW messages for this user.
  * @return Notice
  */
 protected function getNextBatch(User $user)
 {
     $notice = new Notice();
     $notice->profile_id = $user->id;
     $notice->limit(self::DELETION_WINDOW);
     $notice->find();
     return $notice;
 }
Esempio n. 10
0
 static function locFromStored(Notice $stored)
 {
     $loc = new Notice_location();
     $loc->notice_id = $stored->getID();
     if (!$loc->find(true)) {
         throw new NoResultException($loc);
     }
     return $loc->asLocation();
 }
 public function onEndShowThreadedNoticeTail(NoticeListItem $nli, Notice $notice, array $notices)
 {
     if ($this->prerender_replyforms) {
         $nli->out->elementStart('li', array('class' => 'notice-reply', 'style' => 'display: none;'));
         $replyForm = new NoticeForm($nli->out, array('inreplyto' => $notice->getID()));
         $replyForm->show();
         $nli->out->elementEnd('li');
     }
     return true;
 }
Esempio n. 12
0
 /**
  * If poster is in one of the forced groups, make sure their notice
  * gets saved into that group even if not explicitly mentioned.
  *
  * @param Notice $notice
  * @return boolean event hook return
  */
 function onStartNoticeDistribute($notice)
 {
     $profile = $notice->getProfile();
     foreach ($this->post as $nickname) {
         $group = User_group::getForNickname($nickname);
         if ($group && $profile->isMember($group)) {
             $notice->addToGroupInbox($group);
         }
     }
     return true;
 }
Esempio n. 13
0
 function approve($id)
 {
     if ($_POST) {
         $notice = new Notice($id);
         $_POST['approve_id'] = $this->session->userdata('id');
         $notice->approve_date = date("Y-m-d H:i:s");
         $notice->from_array($_POST);
         $notice->save();
         echo approve_comment($notice);
     }
 }
Esempio n. 14
0
 function getUpdates($seconds)
 {
     $notice = new Notice();
     # XXX: cache this. Depends on how big this protocol becomes;
     # Re-doing this query every 15 seconds isn't the end of the world.
     $notice->query('SELECT profile_id, max(id) AS max_id ' . 'FROM notice ' . (common_config('db', 'type') == 'pgsql' ? 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' : 'WHERE created > (now() - ' . $seconds . ') ') . 'GROUP BY profile_id');
     $updates = array();
     while ($notice->fetch()) {
         $updates[] = array($notice->profile_id, $notice->max_id);
     }
     return $updates;
 }
Esempio n. 15
0
 public static function saveNew(Notice $notice, Profile $profile, $reason = null)
 {
     $att = new Attention();
     $att->notice_id = $notice->getID();
     $att->profile_id = $profile->getID();
     $att->reason = $reason;
     $att->created = common_sql_now();
     $result = $att->insert();
     if ($result === false) {
         throw new Exception('Could not saveNew in Attention');
     }
     return $att;
 }
Esempio n. 16
0
 static function noticeCount($id)
 {
     $keypart = sprintf('conversation:notice_count:%d', $id);
     $cnt = self::cacheGet($keypart);
     if ($cnt !== false) {
         return $cnt;
     }
     $notice = new Notice();
     $notice->conversation = $id;
     $cnt = $notice->count();
     self::cacheSet($keypart, $cnt);
     return $cnt;
 }
Esempio n. 17
0
 static function noticeCount($id)
 {
     $keypart = sprintf('conversation:notice_count:%d', $id);
     $cnt = self::cacheGet($keypart);
     if ($cnt !== false) {
         return $cnt;
     }
     $notice = new Notice();
     $notice->conversation = $id;
     $notice->whereAddIn('verb', array(ActivityVerb::POST, ActivityUtils::resolveUri(ActivityVerb::POST, true)), $notice->columnType('verb'));
     $cnt = $notice->count();
     self::cacheSet($keypart, $cnt);
     return $cnt;
 }
Esempio n. 18
0
 public function run()
 {
     $this->controller->_seoTitle = '系统公告 - ' . $this->controller->_setting['site_name'];
     $model = new Notice();
     $criteria = new CDbCriteria();
     //查询条件
     $criteria->addColumnCondition(array('status' => 'Y'));
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     $lists = $model->findAll($criteria);
     $this->controller->render('index', array('lists' => $lists, 'pages' => $pages));
 }
 function activityObjectFromNotice(Notice $notice)
 {
     $object = new ActivityObject();
     $object->id = $notice->uri;
     $object->type = Video::OBJECT_TYPE;
     $object->title = $notice->content;
     $object->summary = $notice->content;
     $object->link = $notice->getUrl();
     $vid = Video::getByNotice($notice);
     if ($vid) {
         $object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array());
     }
     return $object;
 }
Esempio n. 20
0
 public function publishNotice()
 {
     $title = Input::get("title");
     $content = Input::get("content");
     if (!$title || !$content) {
         return Response::json(array("errCode" => 1, "errMsg" => "[参数错误]请填写要发布公告的标题和内容"));
     }
     $notice = new Notice();
     $notice->title = $title;
     $notice->content = $content;
     if (!$notice->save()) {
         return Response::json(array("errCode" => 1, "errMsg" => "[数据库错误]发布失败"));
     }
     return Response::json(array("errCode" => 0));
 }
 /**
  * @param Airbrake\Notice $notice
  * @return string
  **/
 public function send(Notice $notice)
 {
     $curl = curl_init();
     $xml = $notice->toXml($this->configuration);
     curl_setopt($curl, CURLOPT_URL, $this->configuration->apiEndPoint);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_TIMEOUT, $this->configuration->timeout);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $return = curl_exec($curl);
     curl_close($curl);
     return $return;
 }
 function handle($args)
 {
     parent::handle($args);
     $notice = new Notice();
     $notice->source = 'activity';
     $notice->find();
     while ($notice->fetch()) {
         $data = Notice::staticGet('id', $notice->id);
         $orign = clone $data;
         $data->content_type = NOTICE::CONTENT_TYPE_ACTIVITY;
         if (!$data->update($orign)) {
             echo 'profile update error' . $data->id;
             echo '<br>';
         }
     }
 }
Esempio n. 23
0
 /**
  * Action login
  */
 public function action_login()
 {
     $post = $this->request->post();
     $username = Arr::get($post, 'username');
     $password = Arr::get($post, 'password');
     $remember = Arr::get($post, 'remember') ?: 0;
     // If there is post login
     if ($this->request->post('login')) {
         // ログインチェック
         if (Auth::instance()->login($username, $password, $remember)) {
             // ロールチェック
             if (Auth::instance()->logged_in('direct') or Auth::instance()->logged_in('admin') or Auth::instance()->logged_in('edit')) {
                 // Add success notice
                 Notice::add(Notice::SUCCESS, Kohana::message('auth', 'login_success'), array(':user' => $username));
                 // Redirect to home
                 $this->redirect(URL::site($this->settings->backend_name, 'http'));
             } else {
                 // Add error notice
                 Notice::add(Notice::ERROR, Kohana::message('auth', 'login_refusal'), NULL, Kohana::message('auth', 'login_refusal_messages'));
             }
         } else {
             // Add error notice
             Notice::add(Notice::ERROR, Kohana::message('auth', 'login_failed'), NULL, Kohana::message('auth', 'login_failed_messages'));
         }
     }
     /**
      * View
      */
     // Get content
     $content_file = Tpl::get_file('login', $this->settings->back_tpl_dir . '/auth');
     $this->content = Tpl::factory($content_file)->set('post', $post);
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $notice->whereAdd('is_local =' . Notice::REMOTE);
     // -1 == blacklisted, -2 == gateway (i.e. Twitter)
     $notice->whereAdd('is_local !=' . Notice::LOCAL_NONPUBLIC);
     $notice->whereAdd('is_local !=' . Notice::GATEWAY);
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     if (!empty($this->selectVerbs)) {
         $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
     }
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
 /**
  *  提交消息信息
  */
 public function actionPostNoticeReturn()
 {
     if (!isset($_REQUEST['userId']) || !isset($_REQUEST['token']) || !isset($_REQUEST['noticeId']) || !isset($_REQUEST['status'])) {
         $this->_return('MSG_ERR_LESS_PARAM');
     }
     $user_id = trim(Yii::app()->request->getParam('userId'));
     $token = trim(Yii::app()->request->getParam('token'));
     $noticeId = trim(Yii::app()->request->getParam('noticeId'));
     $status = trim(Yii::app()->request->getParam('status'));
     if (!ctype_digit($user_id) || $user_id < 1) {
         $this->_return('MSG_ERR_NO_USER');
     }
     if (!ctype_digit($noticeId) || $noticeId < 1 || !Notice::model()->isExistNoticeId($noticeId, $user_id)) {
         $this->_return('MSG_ERR_FAIL_NOTICE');
     }
     if (!ctype_digit($status) || !in_array($status, array(1, 2, 3, 4))) {
         $this->_return('MSG_ERR_FAIL_NOTICE_STATUS');
     }
     // 验证token
     if (Token::model()->verifyToken($user_id, $token)) {
         $data = Notice::model()->postNoticeReturn($noticeId, $status);
         $this->_return('MSG_SUCCESS', $data);
     } else {
         $this->_return('MSG_ERR_TOKEN');
     }
 }
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  *
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->user = $this->auth_user;
     $this->notice = Notice::staticGet($this->arg('id'));
     return true;
 }
Esempio n. 27
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->user = common_current_user();
     if (empty($this->user)) {
         $this->clientError(_('Only logged-in users can repeat notices.'));
         return false;
     }
     $id = $this->trimmed('notice');
     if (empty($id)) {
         $this->clientError(_('No notice specified.'));
         return false;
     }
     $this->notice = Notice::staticGet('id', $id);
     if (empty($this->notice)) {
         $this->clientError(_('No notice specified.'));
         return false;
     }
     if ($this->user->id == $this->notice->profile_id) {
         $this->clientError(_("You can't repeat your own notice."));
         return false;
     }
     $token = $this->trimmed('token-' . $id);
     if (empty($token) || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return false;
     }
     $profile = $this->user->getProfile();
     if ($profile->hasRepeated($id)) {
         $this->clientError(_('You already repeated that notice.'));
         return false;
     }
     return true;
 }
 function onEndShowScripts($action)
 {
     $action->inlineScript('var Notice_maxContent = ' . Notice::maxContent());
     if (common_logged_in()) {
         $action->script($this->path('shorten.js'));
     }
 }
Esempio n. 29
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     Action::prepare($argarray);
     $this->id = $this->trimmed('id');
     $this->answer = QnA_Answer::staticGet('id', $this->id);
     if (empty($this->answer)) {
         // TRANS: Client exception thrown when requesting a non-existing answer.
         throw new ClientException(_m('No such answer.'), 404);
     }
     $this->question = $this->answer->getQuestion();
     if (empty($this->question)) {
         // TRANS: Client exception thrown when requesting an answer that has no connected question.
         throw new ClientException(_m('No question for this answer.'), 404);
     }
     $this->notice = Notice::staticGet('uri', $this->answer->uri);
     if (empty($this->notice)) {
         // TRANS: Did we used to have it, and it got deleted?
         throw new ClientException(_m('No such answer.'), 404);
     }
     $this->user = User::staticGet('id', $this->answer->profile_id);
     if (empty($this->user)) {
         // TRANS: Client exception thrown when requesting answer data for a non-existing user.
         throw new ClientException(_m('No such user.'), 404);
     }
     $this->profile = $this->user->getProfile();
     if (empty($this->profile)) {
         // TRANS: Client exception thrown when requesting answer data for a user without a profile.
         throw new ServerException(_m('User without a profile.'));
     }
     $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
     return true;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $search_engine = $notice->getSearchEngine('notice');
     $search_engine->set_sort_mode('chron');
     $search_engine->limit($offset, $limit);
     $ids = array();
     // wtf?
     $search_engine->query($this->q);
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     return $ids;
 }