]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Beginning to refactor document relationship links to reduce common code.
authorMeitar Moscovitz <meitarm@gmail.com>
Tue, 10 Feb 2009 08:42:01 +0000 (19:42 +1100)
committerMeitar Moscovitz <meitarm@gmail.com>
Tue, 10 Feb 2009 09:25:44 +0000 (20:25 +1100)
My attempts here are to mimic the `pagination()` method shared by
actions. I'm tentatively adding the `$count` property to actions so that
we can query the number of notices ''being displayed'' per page prior to
calling the actual `pagination()` method itself, since document
relationship `<link>` elements need to be output inside of `showHead()`,
before `showContent()`, which is where `pagination()` is, gets called.

13 files changed:
actions/all.php
actions/favorited.php
actions/groupmembers.php
actions/groups.php
actions/inbox.php
actions/outbox.php
actions/public.php
actions/replies.php
actions/showfavorites.php
actions/showgroup.php
actions/showstream.php
actions/tag.php
lib/action.php

index 76b1bbcdf8c5e1ac6a012f566cb223101b993913..4a625207a45f5623b8ca5c573883afa44225b58b 100644 (file)
@@ -85,19 +85,8 @@ class AllAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('all',
-                                                                    array('nickname' => $this->user->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('all',
-                                                                array('nickname' => $this->user->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'all', array('nickname' => $this->user->nickname));
     }
 
     function showLocalNav()
index 367fb6dd698c321831cf2d73eda2347b18e0b346..74920ca7e4073a7a4f68b0911ce971b55fa2d5b5 100644 (file)
@@ -203,16 +203,7 @@ class FavoritedAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('favorited',
-                                                                    array('page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('favorited',
-                                                                array('page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'favorited');
     }
 }
index 2b2bdba93d80cc8894f0748fc19ed11c9319e1e5..b80f3d90d10176f84f8c1446504fb3c763c461cb 100644 (file)
@@ -145,18 +145,7 @@ class GroupmembersAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('groupmembers',
-                                                                    array('nickname' => $this->group->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Group Members')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('groupmembers',
-                                                                array('nickname' => $this->group->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Group Members')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'groupmembers', array('nickname' => $this->group->nickname));
     }
 }
index b0bf7cfc2af57417f09e59940df24bbd31380fef..e158698de28216cbde3aa910cd32f6e0f8c46e56 100644 (file)
@@ -137,16 +137,7 @@ class GroupsAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('groups',
-                                                                    array('page' => $this->page - 1)),
-                                         'title' => _('Next Groups')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('groups',
-                                                                array('page' => $this->page + 1)),
-                                     'title' => _('Previous Groups')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'groups', array('nickname' => $this->group->nickname));
     }
 }
index d12f3f20ae6ec8393a8e150f8fecc737c8fe2374..7b5cf2d203d8f6abf1380ac74cc6e234f1d1d125 100644 (file)
@@ -70,19 +70,8 @@ class InboxAction extends MailboxAction
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('inbox',
-                                                                    array('nickname' => $this->user->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Messages')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('inbox',
-                                                                array('nickname' => $this->user->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Messages')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'inbox', array('nickname' => $this->user->nickname));
     }
 
     /**
index 043b74edc49d55487dd2859ca0ada1abcad9bc04..deef1cc870f5ef9a7ef6c2643be3f59a1f116958 100644 (file)
@@ -69,19 +69,8 @@ class OutboxAction extends MailboxAction
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('outbox',
-                                                                    array('nickname' => $this->user->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Messages')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('outbox',
-                                                                array('nickname' => $this->user->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Messages')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'outbox', array('nickname' => $this->user->nickname));
     }
 
     /**
index 25889eee5a0e2644fce6dfea67627c6dbc692b0c..eb2a4b1b004439ce7ba2a2d0cecc06e913ada860 100644 (file)
@@ -56,6 +56,18 @@ class PublicAction extends Action
 
     var $page = null;
 
+    /**
+     * Number of notices being shown on this page.
+     */
+    //    Does this need to be here? Should it be?
+    //    If it does, this property needs to be
+    //    added to other actions as well, like $page.
+    //    I'm trying to find a way to capture the
+    //    output of the $cnt variable from this
+    //    action's showContent() method but need
+    //    to do so earlier, I think...?
+    var $count = null;
+
     function isReadOnly()
     {
         return true;
@@ -134,17 +146,8 @@ class PublicAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('public',
-                                                                    array('page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('public',
-                                                                array('page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'public');
     }
 
     /**
index 5ae99e16523c14a0feac8fdb7235c224a1f80988..7c24b554e0a0768ae81671b338103253570aac9c 100644 (file)
@@ -148,19 +148,8 @@ class RepliesAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('replies',
-                                                                    array('nickname' => $this->user->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('replies',
-                                                                array('nickname' => $this->user->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'replies', array('nickname' => $this->user->nickname));
     }
 
     /**
index f0297172a69f27e9e7f9b09f7a0509548776b2ec..585b3b75ab8809a6c6ff68c5693d30bee1cb0952 100644 (file)
@@ -160,21 +160,11 @@ class ShowfavoritesAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('showfavorites',
-                                                                    array('nickname' => $this->user->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Favorite Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('showfavorites',
-                                                                array('nickname' => $this->user->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Favorite Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'showfavorites', array('nickname' => $this->user->nickname));
     }
 
+
     /**
      * show the personal group nav
      *
index 7599a8de6ebb62ec10026aea1fb9e9129a0e3b89..a2b40f994811a2fc59f03cd2cbfd4128063e7c8c 100644 (file)
@@ -333,19 +333,8 @@ class ShowgroupAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('showgroup',
-                                                                    array('nickname' => $this->group->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('showgroup',
-                                                                array('nickname' => $this->group->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'showgroup', array('nickname' => $this->group->nickname));
     }
 
     /**
index 0c8fea18218a70f00feb28c75453fa2067b69ca9..1779c70f2c5e2069c4d35180d89c82604ce833b7 100644 (file)
@@ -202,19 +202,8 @@ class ShowstreamAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('showstream',
-                                                                    array('nickname' => $this->user->nickname,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('showstream',
-                                                                array('nickname' => $this->user->nickname,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'showstream', array('nickname' => $this->user->nickname));
     }
 
     function extraHead()
index f71f6d342f99fca6088e9e1c685443668c285b35..2a564a25d49442d72f1306a21c5119f916016139 100644 (file)
@@ -76,19 +76,8 @@ class TagAction extends Action
      */
     function showRelationshipLinks()
     {
-        // Machine-readable pagination
-        if ($this->page > 1) {
-            $this->element('link', array('rel' => 'next',
-                                         'href' => common_local_url('tag',
-                                                                    array('tag' => $this->tag,
-                                                                          'page' => $this->page - 1)),
-                                         'title' => _('Next Notices')));
-        }
-        $this->element('link', array('rel' => 'prev',
-                                     'href' => common_local_url('tag',
-                                                                array('tag' => $this->tag,
-                                                                      'page' => $this->page + 1)),
-                                     'title' => _('Previous Notices')));
+        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
+                                     $this->page, 'tag', array('tag' => $this->tag));
     }
 
     function showPageNotice()
index 8d0fea7afd2dcd6ff457258406751c18c4f9a04d..80a8969fa2bd3cdf89b71fdaacad8540cc85313e 100644 (file)
@@ -938,4 +938,38 @@ class Action extends HTMLOutputter // lawsuit
             $this->elementEnd('div');
         }
     }
+
+    /**
+     * Generate document metadata for sequential navigation
+     *
+     * @param boolean $have_before is there something before?
+     * @param boolean $have_after  is there something after?
+     * @param integer $page        current page
+     * @param string  $action      current action
+     * @param array   $args        rest of query arguments
+     *
+     * @return nothing
+     */
+    function sequenceRelationships($have_next, $have_previous, $page, $action, $args=null)
+    {
+        // Outputs machine-readable pagination in <link> elements.
+        // Pattern taken from $this->pagination() method.
+
+        // "next" is equivalent to "after"
+        if ($have_next) {
+            $pargs   = array('page' => $page-1);
+            $newargs = $args ? array_merge($args, $pargs) : $pargs;
+            $this->element('link', array('rel' => 'next',
+                                         'href' => common_local_url($action, $newargs),
+                                         'title' => _('Next')));
+        }
+        // "previous" is equivalent to "before"
+        if ($have_previous=true) { // FIXME
+            $pargs   = array('page' => $page+1);
+            $newargs = $args ? array_merge($args, $pargs) : $pargs;
+            $this->element('link', array('rel' => 'prev',
+                                         'href' => common_local_url($action, $newargs),
+                                         'title' => _('Previous')));
+        }
+    }
 }