Modify public stream to use new UI framework

I modified public.php to use the new UI framework. Since the Action
class isn't functional yet, I don't know if it works.

I took some of the functionality, like the public tabs nav and the
feeds list, and made them widgets.

I also moved the navigation from common_navigation() to a method of
Action.
This commit is contained in:
Evan Prodromou 2009-01-13 23:48:05 -05:00
parent 93e249de2a
commit 0093b035c1
7 changed files with 424 additions and 219 deletions

View File

@ -1,9 +1,12 @@
<?php <?php
/* /**
* Laconica - a distributed open-source microblogging tool * Laconica, the distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
* *
* This program is free software: you can redistribute it and/or modify * Action for displaying the public stream
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
@ -15,49 +18,173 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Public
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @copyright 2008-2009 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/ */
if (!defined('LACONICA')) { exit(1); } if (!defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/lib/stream.php'); /**
* Action for displaying the public stream
*
* @category Public
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
* @see PublicrssAction
* @see PublicxrdsAction
*/
class PublicAction extends StreamAction class PublicAction extends Action
{ {
/**
* page of the stream we're on; default = 1
*/
var $page = null;
/**
* Read and validate arguments
*
* @param array $args URL parameters
*
* @return boolean success value
*/
function prepare($args)
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
return true;
}
/**
* handle request
*
* Show the public stream, using recipe method showPage()
*
* @param array $args arguments, mostly unused
*
* @return void
*/
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
$page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
header('X-XRDS-Location: '. common_local_url('publicxrds')); header('X-XRDS-Location: '. common_local_url('publicxrds'));
common_show_header(_('Public timeline'), $this->showPage();
array($this, 'show_header'), null,
array($this, 'show_top'));
# XXX: Public sidebar here?
$this->show_notices($page);
common_show_footer();
} }
function show_top() /**
* Title of the page
*
* @return page title, including page number if over 1
*/
function title()
{ {
if (common_logged_in()) { if ($this->page > 1) {
common_notice_form('public'); return sprintf(_('Public timeline, page %d'), $this->page);
} else { } else {
$instr = $this->get_instructions(); return _('Public timeline');
$output = common_markup_to_html($instr); }
common_element_start('div', 'instructions');
common_raw($output);
common_element_end('div');
} }
$this->public_views_menu(); /**
* Output <head> elements for RSS and Atom feeds
*
* @return void
*/
$this->show_feeds_list(array(0=>array('href'=>common_local_url('publicrss'), function showFeeds()
{
$this->element('link', array('rel' => 'alternate',
'href' => common_local_url('publicrss'),
'type' => 'application/rss+xml',
'title' => _('Public Stream Feed')));
}
/**
* Extra head elements
*
* We include a <meta> element linking to the publicxrds page, for OpenID
* client-side authentication.
*
* @return void
*/
function extraHead()
{
// for client side of OpenID authentication
$this->element('meta', array('http-equiv' => 'X-XRDS-Location',
'content' => common_local_url('publicxrds')));
}
/**
* Show tabset for this page
*
* Uses the PublicGroupNav widget
*
* @return void
* @see PublicGroupNav
*/
function showLocalNav()
{
$nav = new PublicGroupNav($this);
$nav->show();
}
/**
* Fill the content area
*
* Shows a list of the notices in the public stream, with some pagination
* controls.
*
* @return void
*/
function showContent()
{
$notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1);
if (!$notice) {
$this->server_error(_('Could not retrieve public stream.'));
return;
}
$nl = new NoticeList($notice);
$cnt = $nl->show();
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'public');
}
/**
* Makes a list of exported feeds for this page
*
* @return void
*
* @todo I18N
*/
function showExportData()
{
$fl = new FeedList($this);
$fl->show(array(0 => array('href' => common_local_url('publicrss'),
'type' => 'rss', 'type' => 'rss',
'version' => 'RSS 1.0', 'version' => 'RSS 1.0',
'item' => 'publicrss'), 'item' => 'publicrss'),
@ -66,40 +193,4 @@ class PublicAction extends StreamAction
'version' => 'Atom 1.0', 'version' => 'Atom 1.0',
'item' => 'publicatom'))); 'item' => 'publicatom')));
} }
function get_instructions()
{
return _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
'[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ([Read more](%%doc.help%%))');
}
function show_header()
{
common_element('link', array('rel' => 'alternate',
'href' => common_local_url('publicrss'),
'type' => 'application/rss+xml',
'title' => _('Public Stream Feed')));
# for client side of OpenID authentication
common_element('meta', array('http-equiv' => 'X-XRDS-Location',
'content' => common_local_url('publicxrds')));
}
function show_notices($page)
{
$cnt = 0;
$notice = Notice::publicStream(($page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1);
if (!$notice) {
$this->server_error(_('Could not retrieve public stream.'));
return;
}
$cnt = $this->show_notice_list($notice);
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'public');
}
} }

View File

@ -553,4 +553,38 @@ class Action extends HTMLOutputter // lawsuit
common_element('a', $attrs, $text); common_element('a', $attrs, $text);
common_element_end('li'); common_element_end('li');
} }
// Does a little before-after block for next/prev page
function pagination($have_before, $have_after, $page, $action, $args=null)
{
if ($have_before || $have_after) {
$this->elementStart('div', array('id' => 'pagination'));
$this->elementStart('ul', array('id' => 'nav_pagination'));
}
if ($have_before) {
$pargs = array('page' => $page-1);
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
$this->elementStart('li', 'before');
$this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'),
_('« After'));
$this->elementEnd('li');
}
if ($have_after) {
$pargs = array('page' => $page+1);
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
$this->elementStart('li', 'after');
$this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'),
_('Before »'));
$this->elementEnd('li');
}
if ($have_before || $have_after) {
$this->elementEnd('ul');
$this->elementEnd('div');
}
}
} }

156
lib/feedlist.php Normal file
View File

@ -0,0 +1,156 @@
<?php
/**
* Laconica, the distributed open-source microblogging tool
*
* Widget for showing a list of feeds
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @copyright 2008 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/
if (!defined('LACONICA')) {
exit(1);
}
/**
* Widget for showing a list of feeds
*
* Typically used for Action::showExportList()
*
* @category Widget
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
* @see Action::showExportList()
*/
class FeedList
{
var $out = null;
function __construct($out=null)
{
$this->out = $out;
}
function show($feeds)
{
$this->out->elementStart('div', array('class' => 'feeds'));
$this->out->element('p', null, 'Feeds:');
$this->out->elementStart('ul', array('class' => 'xoxo'));
foreach ($feeds as $key => $value) {
$this->feedItem($feeds[$key]);
}
$this->out->elementEnd('ul');
$this->out->elementEnd('div');
}
function feedItem($feed)
{
$nickname = $this->trimmed('nickname');
switch($feed['item']) {
case 'notices': default:
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "$nickname's ".$feed['version']." notice feed";
$feed['textContent'] = "RSS";
break;
case 'allrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = $feed['version']." feed for $nickname and friends";
$feed['textContent'] = "RSS";
break;
case 'repliesrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = $feed['version']." feed for replies to $nickname";
$feed['textContent'] = "RSS";
break;
case 'publicrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Public timeline ".$feed['version']." feed";
$feed['textContent'] = "RSS";
break;
case 'publicatom':
$feed_classname = "atom";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Public timeline ".$feed['version']." feed";
$feed['textContent'] = "Atom";
break;
case 'tagrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = $feed['version']." feed for this tag";
$feed['textContent'] = "RSS";
break;
case 'favoritedrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Favorited ".$feed['version']." feed";
$feed['textContent'] = "RSS";
break;
case 'foaf':
$feed_classname = "foaf";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "$nickname's FOAF file";
$feed['textContent'] = "FOAF";
break;
case 'favoritesrss':
$feed_classname = "favorites";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Feed for favorites of $nickname";
$feed['textContent'] = "RSS";
break;
case 'usertimeline':
$feed_classname = "atom";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "$nickname's ".$feed['version']." notice feed";
$feed['textContent'] = "Atom";
break;
}
$this->out->elementStart('li');
$this->out->element('a', array('href' => $feed['href'],
'class' => $feed_classname,
'type' => $feed_mimetype,
'title' => $feed_title),
$feed['textContent']);
$this->out->elementEnd('li');
}
}

View File

@ -89,104 +89,6 @@ class PersonalAction extends Action
common_element_end('ul'); common_element_end('ul');
} }
function show_feeds_list($feeds)
{
common_element_start('div', array('class' => 'feeds'));
common_element('p', null, 'Feeds:');
common_element_start('ul', array('class' => 'xoxo'));
foreach ($feeds as $key => $value) {
$this->common_feed_item($feeds[$key]);
}
common_element_end('ul');
common_element_end('div');
}
function common_feed_item($feed)
{
$nickname = $this->trimmed('nickname');
switch($feed['item']) {
case 'notices': default:
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "$nickname's ".$feed['version']." notice feed";
$feed['textContent'] = "RSS";
break;
case 'allrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = $feed['version']." feed for $nickname and friends";
$feed['textContent'] = "RSS";
break;
case 'repliesrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = $feed['version']." feed for replies to $nickname";
$feed['textContent'] = "RSS";
break;
case 'publicrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Public timeline ".$feed['version']." feed";
$feed['textContent'] = "RSS";
break;
case 'publicatom':
$feed_classname = "atom";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Public timeline ".$feed['version']." feed";
$feed['textContent'] = "Atom";
break;
case 'tagrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = $feed['version']." feed for this tag";
$feed['textContent'] = "RSS";
break;
case 'favoritedrss':
$feed_classname = $feed['type'];
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Favorited ".$feed['version']." feed";
$feed['textContent'] = "RSS";
break;
case 'foaf':
$feed_classname = "foaf";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "$nickname's FOAF file";
$feed['textContent'] = "FOAF";
break;
case 'favoritesrss':
$feed_classname = "favorites";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "Feed for favorites of $nickname";
$feed['textContent'] = "RSS";
break;
case 'usertimeline':
$feed_classname = "atom";
$feed_mimetype = "application/".$feed['type']."+xml";
$feed_title = "$nickname's ".$feed['version']." notice feed";
$feed['textContent'] = "Atom";
break;
}
common_element_start('li');
common_element('a', array('href' => $feed['href'],
'class' => $feed_classname,
'type' => $feed_mimetype,
'title' => $feed_title),
$feed['textContent']);
common_element_end('li');
}
function source_link($source) function source_link($source)
{ {
$source_name = _($source); $source_name = _($source);

83
lib/publicgroupnav.php Normal file
View File

@ -0,0 +1,83 @@
<?php
/**
* Laconica, the distributed open-source microblogging tool
*
* Base class for all actions (~views)
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Action
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @copyright 2008 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/
if (!defined('LACONICA')) {
exit(1);
}
/**
* Base class for all actions
*
* This is the base class for all actions in the package. An action is
* more or less a "view" in an MVC framework.
*
* Actions are responsible for extracting and validating parameters; using
* model classes to read and write to the database; and doing ouput.
*
* @category Output
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
* @see HTMLOutputter
*/
class PublicGroupNav
{
var $action = null;
function __construct($action=null)
{
$this->action = $action;
}
function show()
{
$this->action->elementStart('ul', array('id' => 'nav_views'));
common_menu_item(common_local_url('public'), _('Public'),
_('Public timeline'), $this->action == 'public');
common_menu_item(common_local_url('tag'), _('Recent tags'),
_('Recent tags'), $this->action == 'tag');
if (count(common_config('nickname', 'featured')) > 0) {
common_menu_item(common_local_url('featured'), _('Featured'),
_('Featured users'), $this->action == 'featured');
}
common_menu_item(common_local_url('favorited'), _('Popular'),
_("Popular notices"), $this->action == 'favorited');
common_element_end('ul');
}
}

View File

@ -24,32 +24,6 @@ require_once(INSTALLDIR.'/lib/noticelist.php');
class StreamAction extends PersonalAction class StreamAction extends PersonalAction
{ {
function public_views_menu()
{
$action = $this->trimmed('action');
common_element_start('ul', array('id' => 'nav_views'));
common_menu_item(common_local_url('public'), _('Public'),
_('Public timeline'), $action == 'public');
common_menu_item(common_local_url('tag'), _('Recent tags'),
_('Recent tags'), $action == 'tag');
if (count(common_config('nickname', 'featured')) > 0) {
common_menu_item(common_local_url('featured'), _('Featured'),
_('Featured users'), $action == 'featured');
}
common_menu_item(common_local_url('favorited'), _('Popular'),
_("Popular notices"), $action == 'favorited');
common_element_end('ul');
}
function show_notice_list($notice) function show_notice_list($notice)
{ {
$nl = new NoticeList($notice); $nl = new NoticeList($notice);

View File

@ -1459,41 +1459,6 @@ function common_valid_tag($tag)
return false; return false;
} }
// Does a little before-after block for next/prev page
function common_pagination($have_before, $have_after, $page, $action, $args=null)
{
if ($have_before || $have_after) {
common_element_start('div', array('id' => 'pagination'));
common_element_start('ul', array('id' => 'nav_pagination'));
}
if ($have_before) {
$pargs = array('page' => $page-1);
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
common_element_start('li', 'before');
common_element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'),
_('« After'));
common_element_end('li');
}
if ($have_after) {
$pargs = array('page' => $page+1);
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
common_element_start('li', 'after');
common_element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'),
_('Before »'));
common_element_end('li');
}
if ($have_before || $have_after) {
common_element_end('ul');
common_element_end('div');
}
}
/* Following functions are copied from MediaWiki GlobalFunctions.php /* Following functions are copied from MediaWiki GlobalFunctions.php
* and written by Evan Prodromou. */ * and written by Evan Prodromou. */