]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/router.php
More routes.
[quix0rs-gnu-social.git] / lib / router.php
index d47ad7118332328cfd0208f152013ea950ce6fed..f70b67f383feadd9baa17bf73085bdb74cf48f6c 100644 (file)
@@ -47,7 +47,7 @@ require_once 'Net/URL/Mapper.php';
 
 class Router
 {
-    static $m = null;
+    var $m = null;
     static $inst = null;
 
     static function get()
@@ -98,12 +98,14 @@ class Router
         $main = array('login', 'logout', 'register', 'subscribe',
                       'unsubscribe', 'confirmaddress', 'recoverpassword',
                       'invite', 'favor', 'disfavor', 'sup',
-                      'tagother', 'block');
+                      'block');
 
         foreach ($main as $a) {
             $m->connect('main/'.$a, array('action' => $a));
         }
 
+        $m->connect('main/tagother/:id', array('action' => 'tagother'));
+
         // these take a code
 
         foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
@@ -115,6 +117,11 @@ class Router
         $m->connect('main/openid', array('action' => 'openidlogin'));
         $m->connect('main/remote', array('action' => 'remotesubscribe'));
 
+        foreach (array('requesttoken', 'accesstoken', 'userauthorization',
+                    'postnotice', 'updateprofile', 'finishremotesubscribe') as $action) {
+            $m->connect('index.php?action=' . $action, array('action' => $action));
+        }
+
         // settings
 
         foreach (array('profile', 'avatar', 'password', 'openid', 'im',
@@ -126,6 +133,7 @@ class Router
 
         foreach (array('group', 'people', 'notice') as $s) {
             $m->connect('search/'.$s, array('action' => $s.'search'));
+            $m->connect('search/'.$s.'?q=:q', array('action' => $s.'search'), array('q' => '.+'));
         }
 
         $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
@@ -133,6 +141,9 @@ class Router
         // notice
 
         $m->connect('notice/new', array('action' => 'newnotice'));
+        $m->connect('notice/new?replyto=:replyto',
+                    array('action' => 'newnotice'),
+                    array('replyto' => '[A-Za-z0-9_-]+'));
         $m->connect('notice/:notice',
                     array('action' => 'shownotice'),
                     array('notice' => '[0-9]+'));
@@ -211,7 +222,7 @@ class Router
         $m->connect('api/statuses/:method/:argument',
                     array('action' => 'api',
                           'apiaction' => 'statuses'),
-                    array('method' => '(user_timeline|show|destroy|friends|followers)'));
+                    array('method' => '(user_timeline|friends_timeline|show|destroy|friends|followers)'));
 
         // users
 
@@ -226,20 +237,31 @@ class Router
 
         // direct messages
 
-        $m->connect('api/direct_messages/:method',
-                    array('action' => 'api',
-                          'apiaction' => 'direct_messages'),
-                    array('method' => '(sent|new)(\.(xml|json|atom|rss))?'));
+        foreach (array('xml', 'json') as $e) {
+            $m->connect('api/direct_messages/new.'.$e,
+                        array('action' => 'api',
+                              'apiaction' => 'direct_messages',
+                              'method' => 'create.'.$e));
+        }
+
+        foreach (array('xml', 'json', 'rss', 'atom') as $e) {
+            $m->connect('api/direct_messages.'.$e,
+                        array('action' => 'api',
+                              'apiaction' => 'direct_messages',
+                              'method' => 'direct_messages.'.$e));
+        }
+
+        foreach (array('xml', 'json', 'rss', 'atom') as $e) {
+            $m->connect('api/direct_message/sent.'.$e,
+                        array('action' => 'api',
+                        'apiaction' => 'direct_messages',
+                        'method' => 'sent.'.$e));
+        }
 
         $m->connect('api/direct_messages/destroy/:argument',
                     array('action' => 'api',
                           'apiaction' => 'direct_messages'));
 
-        $m->connect('api/:method',
-                    array('action' => 'api',
-                          'apiaction' => 'direct_messages'),
-                    array('method' => 'direct_messages(\.(xml|json|atom|rss))?'));
-
         // friendships
 
         $m->connect('api/friendships/:method/:argument',
@@ -252,6 +274,33 @@ class Router
                           'apiaction' => 'friendships'),
                     array('method' => 'exists(\.(xml|json|rss|atom))'));
 
+
+        // Social graph
+
+        $m->connect('api/friends/ids/:argument',
+                    array('action' => 'api',
+                          'apiaction' => 'statuses',
+                          'method' => 'friendsIDs'));
+                                                   
+        foreach (array('xml', 'json') as $e) {
+            $m->connect('api/friends/ids.'.$e,
+                        array('action' => 'api',
+                              'apiaction' => 'statuses',
+                              'method' => 'friendsIDs.'.$e));
+        }
+                                                    
+        $m->connect('api/followers/ids/:argument',
+                    array('action' => 'api',
+                          'apiaction' => 'statuses',
+                          'method' => 'followersIDs'));
+
+        foreach (array('xml', 'json') as $e) {
+            $m->connect('api/followers/ids.'.$e,
+                        array('action' => 'api',
+                              'apiaction' => 'statuses',
+                              'method' => 'followersIDs.'.$e));
+        }
+
         // account
 
         $m->connect('api/account/:method',
@@ -269,10 +318,12 @@ class Router
                           'apiaction' => 'favorites',
                           'method' => 'favorites'));
 
-        $m->connect('api/:method',
-                    array('action' => 'api',
-                          'apiaction' => 'favorites'),
-                    array('method' => 'favorites(\.(xml|json|rss|atom))?'));
+        foreach (array('xml', 'json', 'rss', 'atom') as $e) {
+            $m->connect('api/favorites.'.$e,
+                array('action' => 'api',
+                      'apiaction' => 'favorites',
+                      'method' => 'favorites.'.$e));
+        }
 
         // notifications
 
@@ -345,10 +396,19 @@ class Router
 
     function map($path)
     {
-        return $this->m->match($path);
+        try {
+            $match = $this->m->match($path);
+        } catch (Net_URL_Mapper_InvalidException $e) {
+            common_log(LOG_ERR, "Problem getting route for $path - " .
+                $e->getMessage());
+            $cac = new ClientErrorAction("Page not found.", 404);
+            $cac->showPage();
+        }
+
+        return $match;
     }
 
-    function build($action, $args=null, $fragment=null)
+    function build($action, $args=null, $params=null, $fragment=null)
     {
         $action_arg = array('action' => $action);
 
@@ -358,6 +418,6 @@ class Router
             $args = $action_arg;
         }
 
-        return $this->m->generate($args, null, $fragment);
+        return $this->m->generate($args, $params, $fragment);
     }
-}
\ No newline at end of file
+}