/**
  * Handle the request
  *
  * Return some Twitter-ish data about API limits
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
     }
     $reset = new DateTime();
     $reset->modify('+1 hour');
     $this->initDocument($this->format);
     if ($this->format == 'xml') {
         $this->elementStart('hash');
         $this->element('remaining-hits', array('type' => 'integer'), 150);
         $this->element('hourly-limit', array('type' => 'integer'), 150);
         $this->element('reset-time', array('type' => 'datetime'), common_date_iso8601($reset->format('r')));
         $this->element('reset_time_in_seconds', array('type' => 'integer'), strtotime('+1 hour'));
         $this->elementEnd('hash');
     } elseif ($this->format == 'json') {
         $out = array('reset_time_in_seconds' => strtotime('+1 hour'), 'remaining_hits' => 150, 'hourly_limit' => 150, 'reset_time' => common_date_rfc2822($reset->format('r')));
         print json_encode($out);
     }
     $this->endDocument($this->format);
 }
示例#2
0
 function rssDirectMessageArray($message)
 {
     $entry = array();
     $from = $message->getFrom();
     $entry['title'] = sprintf('Message from %1$s to %2$s', $from->nickname, $message->getTo()->nickname);
     $entry['content'] = common_xml_safe_str($message->rendered);
     $entry['link'] = common_local_url('showmessage', array('message' => $message->id));
     $entry['published'] = common_date_iso8601($message->created);
     $taguribase = TagURI::base();
     $entry['id'] = "tag:{$taguribase}:{$entry['link']}";
     $entry['updated'] = $entry['published'];
     $entry['author-name'] = $from->getBestName();
     $entry['author-uri'] = $from->homepage;
     $avatar = $from->getAvatar(AVATAR_STREAM_SIZE);
     $entry['avatar'] = !empty($avatar) ? $avatar->url : Avatar::defaultImage(AVATAR_STREAM_SIZE);
     $entry['avatar-type'] = !empty($avatar) ? $avatar->mediatype : 'image/png';
     // RSS item specific
     $entry['description'] = $entry['content'];
     $entry['pubDate'] = common_date_rfc2822($message->created);
     $entry['guid'] = $entry['link'];
     return $entry;
 }
 /**
  * Build a search result object
  *
  * This populates the the result in preparation for JSON encoding.
  *
  * @return void
  */
 function buildResult()
 {
     $this->text = $this->notice->content;
     $replier_profile = null;
     if ($this->notice->reply_to) {
         $reply = Notice::staticGet(intval($this->notice->reply_to));
         if ($reply) {
             $replier_profile = $reply->getProfile();
         }
     }
     $this->to_user_id = $replier_profile ? intval($replier_profile->id) : null;
     $this->to_user = $replier_profile ? $replier_profile->nickname : null;
     $this->from_user = $this->profile->nickname;
     $this->id = $this->notice->id;
     $this->from_user_id = $this->profile->id;
     $user = User::staticGet('id', $this->profile->id);
     $this->iso_language_code = $user->language;
     $this->source = $this->getSourceLink($this->notice->source);
     $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
     $this->profile_image_url = $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE);
     $this->created_at = common_date_rfc2822($this->notice->created);
 }
 /**
  * Build a search result object
  *
  * This populates the the result in preparation for JSON encoding.
  *
  * @return void
  */
 function buildResult()
 {
     $this->text = $this->notice->content;
     $replier_profile = null;
     if ($this->notice->reply_to) {
         $reply = Notice::getKV(intval($this->notice->reply_to));
         if ($reply) {
             $replier_profile = $reply->getProfile();
         }
     }
     $this->to_user_id = $replier_profile ? intval($replier_profile->id) : null;
     $this->to_user = $replier_profile ? $replier_profile->nickname : null;
     $this->from_user = $this->profile->nickname;
     $this->id = $this->notice->id;
     $this->from_user_id = $this->profile->id;
     $this->iso_language_code = Profile_prefs::getConfigData($this->profile, 'site', 'language');
     $this->source = $this->getSourceLink($this->notice->source);
     $this->profile_image_url = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
     $this->created_at = common_date_rfc2822($this->notice->created);
 }
示例#5
0
 function twitterRssEntryArray($notice)
 {
     $entry = array();
     if (Event::handle('StartRssEntryArray', array($notice, &$entry))) {
         $profile = $notice->getProfile();
         // We trim() to avoid extraneous whitespace in the output
         $entry['content'] = common_xml_safe_str(trim($notice->rendered));
         $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
         $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
         $entry['published'] = common_date_iso8601($notice->created);
         $taguribase = TagURI::base();
         $entry['id'] = "tag:{$taguribase}:{$entry['link']}";
         $entry['updated'] = $entry['published'];
         $entry['author'] = $profile->getBestName();
         // Enclosures
         $attachments = $notice->attachments();
         $enclosures = array();
         foreach ($attachments as $attachment) {
             try {
                 $enclosure_o = $attachment->getEnclosure();
                 $enclosure = array();
                 $enclosure['url'] = $enclosure_o->url;
                 $enclosure['mimetype'] = $enclosure_o->mimetype;
                 $enclosure['size'] = $enclosure_o->size;
                 $enclosures[] = $enclosure;
             } catch (ServerException $e) {
                 // There was not enough metadata available
             }
         }
         if (!empty($enclosures)) {
             $entry['enclosures'] = $enclosures;
         }
         // Tags/Categories
         $tag = new Notice_tag();
         $tag->notice_id = $notice->id;
         if ($tag->find()) {
             $entry['tags'] = array();
             while ($tag->fetch()) {
                 $entry['tags'][] = $tag->tag;
             }
         }
         $tag->free();
         // RSS Item specific
         $entry['description'] = $entry['content'];
         $entry['pubDate'] = common_date_rfc2822($notice->created);
         $entry['guid'] = $entry['link'];
         if (isset($notice->lat) && isset($notice->lon)) {
             // This is the format that GeoJSON expects stuff to be in.
             // showGeoRSS() below uses it for XML output, so we reuse it
             $entry['geo'] = array('type' => 'Point', 'coordinates' => array((double) $notice->lat, (double) $notice->lon));
         } else {
             $entry['geo'] = null;
         }
         Event::handle('EndRssEntryArray', array($notice, &$entry));
     }
     return $entry;
 }
示例#6
0
 function twitter_rss_dmsg_array($message)
 {
     $entry = array();
     $entry['title'] = sprintf('Message from %s to %s', $message->getFrom()->nickname, $message->getTo()->nickname);
     $entry['content'] = common_xml_safe_str(trim($message->content));
     $entry['link'] = common_local_url('showmessage', array('message' => $message->id));
     $entry['published'] = common_date_iso8601($message->created);
     $taguribase = common_config('integration', 'taguri');
     $entry['id'] = "tag:{$taguribase},:{$entry['link']}";
     $entry['updated'] = $entry['published'];
     $entry['author'] = $message->getFrom()->getBestName();
     # RSS Item specific
     $entry['description'] = $entry['content'];
     $entry['pubDate'] = common_date_rfc2822($message->created);
     $entry['guid'] = $entry['link'];
     return $entry;
 }