]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/twitapistatuses.php
if-else instead of ?:
[quix0rs-gnu-social.git] / actions / twitapistatuses.php
index a384cc75bed317b93fde481092003383ad5e9bbf..0c97ada0b115b8327725b864fff495b3a36b8d75 100644 (file)
@@ -27,26 +27,41 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
  */
 class TwitapistatusesAction extends TwitterapiAction {
        
+       function is_readonly() {
+               
+               static $write_methods = array(  'update',
+                                                                               'destroy');
+               
+               $cmdtext = explode('.', $this->arg('method'));          
+               
+               if (in_array($cmdtext[0], $write_methods)) {                    
+                       return false;
+               }
+                               
+               return true;
+       }
+       
        function public_timeline($args, $apidata) {
                parent::handle($args);
-
+               
                $sitename = common_config('site', 'name');
                $siteserver = common_config('site', 'server'); 
                $title = sprintf(_("%s public timeline"), $sitename);
                $id = "tag:$siteserver:Statuses";
                $link = common_root_url();
-               $subtitle = sprintf(_("%s updates from everyone!"), $sitemap);
+               $subtitle = sprintf(_("%s updates from everyone!"), $sitename);
 
                // Number of public statuses to return by default -- Twitter sends 20
                $MAX_PUBSTATUSES = 20;
 
-               $notice = DB_DataObject::factory('notice');
+               $notice = new Notice();
 
                // FIXME: To really live up to the spec we need to build a list
                // of notices by users who have custom avatars, so fix this SQL -- Zach
 
-               # FIXME: bad performance
-               $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)');
+               # XXX: sub-optimal performance
+               
+               $notice->is_local = 1;
                $notice->orderBy('created DESC, notice.id DESC');
                $notice->limit($MAX_PUBSTATUSES);
                $cnt = $notice->find();
@@ -80,8 +95,7 @@ class TwitapistatusesAction extends TwitterapiAction {
        
        function show_xml_timeline($notice) {
 
-               header('Content-Type: application/xml; charset=utf-8');         
-               common_start_xml();
+               $this->init_document('xml');
                common_element_start('statuses', array('type' => 'array'));
 
                if (is_array($notice)) {
@@ -97,14 +111,12 @@ class TwitapistatusesAction extends TwitterapiAction {
                }
                
                common_element_end('statuses');
-               common_end_xml();
+               $this->end_document('xml');
        }       
        
        function show_rss_timeline($notice, $title, $id, $link, $subtitle) {
                
-               header("Content-Type: application/rss+xml; charset=utf-8");
-               
-               $this->init_twitter_rss();
+               $this->init_document('rss');
                
                common_element_start('channel');
                common_element('title', NULL, $title);
@@ -127,14 +139,12 @@ class TwitapistatusesAction extends TwitterapiAction {
                }
 
                common_element_end('channel');                  
-               $this->end_twitter_rss();
+               $this->end_twitter_rss();               
        }
 
        function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL) {
                
-               header('Content-Type: application/atom+xml; charset=utf-8');
-
-               $this->init_twitter_atom();
+               $this->init_document('atom');
 
                common_element('title', NULL, $title);
                common_element('id', NULL, $id);
@@ -153,12 +163,13 @@ class TwitapistatusesAction extends TwitterapiAction {
                        }
                }
                
-               $this->end_twitter_atom();
+               $this->end_document('atom');
+               
        }
 
        function show_json_timeline($notice) {
                
-               header('Content-Type: application/json; charset=utf-8');
+               $this->init_document('json');
                
                $statuses = array();
                
@@ -175,6 +186,8 @@ class TwitapistatusesAction extends TwitterapiAction {
                }                       
                
                $this->show_twitter_json_statuses($statuses);                   
+               
+               $this->end_document('json');
        }
                
        /*
@@ -224,21 +237,7 @@ class TwitapistatusesAction extends TwitterapiAction {
                $link = common_local_url('all', array('nickname' => $user->nickname));
                $subtitle = sprintf(_("Updates from %s and friends on %s!"), $user->nickname, $sitename);
 
-               $notice = new Notice();
-
-               # XXX: chokety and bad
-
-               $notice->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$profile->id.' and subscribed = notice.profile_id)', 'OR');
-               $notice->whereAdd('profile_id = ' . $profile->id, 'OR');
-
-               # XXX: since
-               # XXX: since_id
-               
-               $notice->orderBy('created DESC, notice.id DESC');
-
-               $notice->limit((($page-1)*20), $count);
-
-               $cnt = $notice->find();
+               $notice = $user->noticesWithFriends(($page-1)*20, $count);
                
                switch($apidata['content-type']) {
                 case 'xml': 
@@ -315,7 +314,7 @@ class TwitapistatusesAction extends TwitterapiAction {
 
                if (!$profile) {
                        common_server_error(_('User has no profile.'));
-                       return;
+                       exit();
                }
                                
                $count = $this->arg('count');
@@ -370,48 +369,15 @@ class TwitapistatusesAction extends TwitterapiAction {
                
                exit();
        }
-
-       function show($args, $apidata) {
-               parent::handle($args);
-               
-               $id = $apidata['api_arg'];              
-               $notice = Notice::staticGet($id);
-
-               if ($notice) {
-
-                       if ($apidata['content-type'] == 'xml') { 
-                               $this->show_single_xml_status($notice);
-                       } elseif ($apidata['content-type'] == 'json') {
-                               $this->show_single_json_status($notice);
-                       }
-               } else {
-                       header('HTTP/1.1 404 Not Found');
-               }
-               
-               exit();
-       }
-               
-       function show_single_xml_status($notice) {
-               header('Content-Type: application/xml; charset=utf-8');         
-               common_start_xml();
-               $twitter_status = $this->twitter_status_array($notice);                                         
-               $this->show_twitter_xml_status($twitter_status);
-               common_end_xml();
-               exit();
-       }
-       
-       function show_single_json_status($notice) {
-               header('Content-Type: application/json; charset=utf-8');
-               $status = $this->twitter_status_array($notice);
-               $this->show_twitter_json_statuses($status);
-               exit();
-       }
                
        function update($args, $apidata) {
                parent::handle($args);
                
                $user = $apidata['user'];
                                
+               $this->is_readonly();
+               
+                               
                $notice = DB_DataObject::factory('notice');             
                
                $notice->profile_id = $user->id; # user id *is* profile id
@@ -438,7 +404,8 @@ class TwitapistatusesAction extends TwitterapiAction {
                }
 
                $notice->rendered = common_render_content($notice->content, $notice);
-
+               $notice->is_local = 1;
+               
                $id = $notice->insert();
 
                if (!$id) {
@@ -485,6 +452,7 @@ class TwitapistatusesAction extends TwitterapiAction {
                ID. Ex: http://server/api/statuses/replies.xml?since_id=12345
        */
        function replies($args, $apidata) {
+
                parent::handle($args);
 
                $since = $this->arg('since');
@@ -639,24 +607,26 @@ class TwitapistatusesAction extends TwitterapiAction {
                $user = $this->get_subs_user($apidata);
                
                # XXX: id
-               # XXX: page
                # XXX: lite
                
+               $page = $this->trimmed('page');
+               
+               if (!$page || !is_numeric($page)) {
+                       $page = 1;
+               }
+               
                $profile = $user->getProfile();
                
                if (!$profile) {
                        common_server_error(_('User has no profile.'));
                        return;
                }
-                                                               
-               if (!$page) {
-                       $page = 1;
-               }
                                
                $sub = new Subscription();
                $sub->$user_attr = $profile->id;
                $sub->orderBy('created DESC');
-
+               $sub->limit(($page-1)*100, 100);
+               
                $others = array();
 
                if ($sub->find()) {