123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class JSONSearchResultsList
- {
- protected $notice;
- protected $rpp;
-
-
- var $results;
- var $since_id;
- var $max_id;
- var $refresh_url;
- var $results_per_page;
- var $completed_in;
- var $page;
- var $query;
-
- function __construct($notice, $query, $rpp, $page, $since_id = 0)
- {
- $this->notice = $notice;
- $this->query = urlencode($query);
- $this->results_per_page = $rpp;
- $this->rpp = $rpp;
- $this->page = $page;
- $this->since_id = $since_id;
- $this->results = array();
- }
-
- function show()
- {
- $cnt = 0;
- $this->max_id = 0;
- $time_start = microtime(true);
- while ($this->notice->fetch() && $cnt <= $this->rpp) {
- $cnt++;
-
- if (!$this->max_id) {
- $this->max_id = (int)$this->notice->id;
- }
- if ($this->since_id && $this->notice->id <= $this->since_id) {
- break;
- }
- if ($cnt > $this->rpp) {
- break;
- }
- $profile = $this->notice->getProfile();
-
- if (!empty($profile)) {
- $item = new ResultItem($this->notice);
- array_push($this->results, $item);
- }
- }
- $time_end = microtime(true);
- $this->completed_in = $time_end - $time_start;
-
- $this->refresh_url = '?since_id=' . $this->max_id .
- '&q=' . $this->query;
-
- if ($cnt > $this->rpp) {
- $this->next_page = '?page=' . ($this->page + 1) .
- '&max_id=' . $this->max_id;
- if ($this->rpp != 15) {
- $this->next_page .= '&rpp=' . $this->rpp;
- }
- $this->next_page .= '&q=' . $this->query;
- }
- if ($this->page > 1) {
- $this->previous_page = '?page=' . ($this->page - 1) .
- '&max_id=' . $this->max_id;
- if ($this->rpp != 15) {
- $this->previous_page .= '&rpp=' . $this->rpp;
- }
- $this->previous_page .= '&q=' . $this->query;
- }
- print json_encode($this);
- return $cnt;
- }
- }
- class ResultItem
- {
-
- protected $notice;
-
- protected $profile;
-
-
- var $text;
- var $to_user_id;
- var $to_user;
- var $from_user;
- var $id;
- var $from_user_id;
- var $iso_language_code;
- var $source = null;
- var $source_link = null;
- var $profile_image_url;
- var $created_at;
-
- function __construct($notice)
- {
- $this->notice = $notice;
- $this->profile = $notice->getProfile();
- $this->buildResult();
- }
-
- 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->setSourceData();
- $this->profile_image_url = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
- $this->created_at = common_date_rfc2822($this->notice->created);
- }
-
- function setSourceData()
- {
- $source = null;
- $source_link = null;
- switch ($source) {
- case 'web':
- case 'xmpp':
- case 'mail':
- case 'omb':
- case 'api':
-
- $source = _($this->notice->source);
- break;
- default:
- $ns = Notice_source::getKV($this->notice->source);
- if ($ns instanceof Notice_source) {
- $source = $ns->code;
- if (!empty($ns->url)) {
- $source_link = $ns->url;
- if (!empty($ns->name)) {
- $source = $ns->name;
- }
- }
- }
- break;
- }
- $this->source = $source;
- $this->source_link = $source_link;
- }
- }
|