Beginning to refactor document relationship links to reduce common code.
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.
This commit is contained in:
parent
3585012380
commit
b240a17194
|
@ -85,19 +85,8 @@ class AllAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'all', array('nickname' => $this->user->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showLocalNav()
|
function showLocalNav()
|
||||||
|
|
|
@ -203,16 +203,7 @@ class FavoritedAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'favorited');
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,18 +145,7 @@ class GroupmembersAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'groupmembers', array('nickname' => $this->group->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,16 +137,7 @@ class GroupsAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'groups', array('nickname' => $this->group->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,19 +70,8 @@ class InboxAction extends MailboxAction
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'inbox', array('nickname' => $this->user->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -69,19 +69,8 @@ class OutboxAction extends MailboxAction
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'outbox', array('nickname' => $this->user->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,6 +56,18 @@ class PublicAction extends Action
|
||||||
|
|
||||||
var $page = null;
|
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()
|
function isReadOnly()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -134,17 +146,8 @@ class PublicAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'public');
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -148,19 +148,8 @@ class RepliesAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'replies', array('nickname' => $this->user->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -160,21 +160,11 @@ class ShowfavoritesAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'showfavorites', array('nickname' => $this->user->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show the personal group nav
|
* show the personal group nav
|
||||||
*
|
*
|
||||||
|
|
|
@ -333,19 +333,8 @@ class ShowgroupAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'showgroup', array('nickname' => $this->group->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -202,19 +202,8 @@ class ShowstreamAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'showstream', array('nickname' => $this->user->nickname));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extraHead()
|
function extraHead()
|
||||||
|
|
|
@ -76,19 +76,8 @@ class TagAction extends Action
|
||||||
*/
|
*/
|
||||||
function showRelationshipLinks()
|
function showRelationshipLinks()
|
||||||
{
|
{
|
||||||
// Machine-readable pagination
|
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
|
||||||
if ($this->page > 1) {
|
$this->page, 'tag', array('tag' => $this->tag));
|
||||||
$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')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPageNotice()
|
function showPageNotice()
|
||||||
|
|
|
@ -938,4 +938,38 @@ class Action extends HTMLOutputter // lawsuit
|
||||||
$this->elementEnd('div');
|
$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')));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user