From 0093b035c12bf21c88f57e4f0931b0abce214f43 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jan 2009 23:48:05 -0500 Subject: 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. --- actions/public.php | 197 ++++++++++++++++++++++++++++++++++++------------- lib/action.php | 34 +++++++++ lib/feedlist.php | 156 +++++++++++++++++++++++++++++++++++++++ lib/personal.php | 108 ++------------------------- lib/publicgroupnav.php | 83 +++++++++++++++++++++ lib/stream.php | 26 ------- lib/util.php | 35 --------- 7 files changed, 422 insertions(+), 217 deletions(-) create mode 100644 lib/feedlist.php create mode 100644 lib/publicgroupnav.php diff --git a/actions/public.php b/actions/public.php index 039e885e6..e00f8efba 100644 --- a/actions/public.php +++ b/actions/public.php @@ -1,9 +1,12 @@ . + * + * @category Public + * @package Laconica + * @author Evan Prodromou + * @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 + * @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 + */ - function handle($args) - { - parent::handle($args); + var $page = null; - $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + /** + * Read and validate arguments + * + * @param array $args URL parameters + * + * @return boolean success value + */ - header('X-XRDS-Location: '. common_local_url('publicxrds')); + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; + } - common_show_header(_('Public timeline'), - array($this, 'show_header'), null, - array($this, 'show_top')); + /** + * handle request + * + * Show the public stream, using recipe method showPage() + * + * @param array $args arguments, mostly unused + * + * @return void + */ - # XXX: Public sidebar here? + function handle($args) + { + parent::handle($args); - $this->show_notices($page); + header('X-XRDS-Location: '. common_local_url('publicxrds')); - common_show_footer(); + $this->showPage(); } - function show_top() + /** + * Title of the page + * + * @return page title, including page number if over 1 + */ + + function title() { - if (common_logged_in()) { - common_notice_form('public'); + if ($this->page > 1) { + return sprintf(_('Public timeline, page %d'), $this->page); } else { - $instr = $this->get_instructions(); - $output = common_markup_to_html($instr); - common_element_start('div', 'instructions'); - common_raw($output); - common_element_end('div'); + return _('Public timeline'); } - - $this->public_views_menu(); - - $this->show_feeds_list(array(0=>array('href'=>common_local_url('publicrss'), - 'type' => 'rss', - 'version' => 'RSS 1.0', - 'item' => 'publicrss'), - 1=>array('href'=>common_local_url('publicatom'), - 'type' => 'atom', - 'version' => 'Atom 1.0', - '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%%))'); - } + /** + * Output elements for RSS and Atom feeds + * + * @return void + */ - function show_header() + function showFeeds() { - common_element('link', array('rel' => 'alternate', + $this->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', + } + + /** + * Extra head elements + * + * We include a 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'))); } - function show_notices($page) + /** + * 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 + */ - $cnt = 0; - $notice = Notice::publicStream(($page-1)*NOTICES_PER_PAGE, + function showContent() + { + $notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if (!$notice) { @@ -97,9 +165,32 @@ class PublicAction extends StreamAction return; } - $cnt = $this->show_notice_list($notice); + $nl = new NoticeList($notice); + + $cnt = $nl->show(); - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'public'); + $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', + 'version' => 'RSS 1.0', + 'item' => 'publicrss'), + 1 => array('href' => common_local_url('publicatom'), + 'type' => 'atom', + 'version' => 'Atom 1.0', + 'item' => 'publicatom'))); } } diff --git a/lib/action.php b/lib/action.php index 59cc173e7..95178c65e 100644 --- a/lib/action.php +++ b/lib/action.php @@ -553,4 +553,38 @@ class Action extends HTMLOutputter // lawsuit common_element('a', $attrs, $text); 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'); + } + } } diff --git a/lib/feedlist.php b/lib/feedlist.php new file mode 100644 index 000000000..0ff88cb25 --- /dev/null +++ b/lib/feedlist.php @@ -0,0 +1,156 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @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 + * @author Sarven Capadisli + * @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'); + } +} diff --git a/lib/personal.php b/lib/personal.php index 02b01fece..4e56c9566 100644 --- a/lib/personal.php +++ b/lib/personal.php @@ -21,12 +21,12 @@ if (!defined('LACONICA')) { exit(1); } class PersonalAction extends Action { - + function is_readonly() { return true; } - + function handle($args) { parent::handle($args); @@ -69,11 +69,11 @@ class PersonalAction extends Action _('Favorites'), sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), $action == 'showfavorites'); - + $cur = common_current_user(); - + if ($cur && $cur->id == $user->id) { - + common_menu_item(common_local_url('inbox', array('nickname' => $nickname)), _('Inbox'), @@ -85,108 +85,10 @@ class PersonalAction extends Action _('Your sent messages'), $action == 'outbox'); } - - 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) { $source_name = _($source); diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php new file mode 100644 index 000000000..d21d0a458 --- /dev/null +++ b/lib/publicgroupnav.php @@ -0,0 +1,83 @@ +. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @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 + * @author Sarven Capadisli + * @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'); + } +} diff --git a/lib/stream.php b/lib/stream.php index 73758adee..0cb9e0bf4 100644 --- a/lib/stream.php +++ b/lib/stream.php @@ -24,32 +24,6 @@ require_once(INSTALLDIR.'/lib/noticelist.php'); 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) { $nl = new NoticeList($notice); diff --git a/lib/util.php b/lib/util.php index 009a0457c..a1e325204 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1459,41 +1459,6 @@ function common_valid_tag($tag) 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 * and written by Evan Prodromou. */ -- cgit v1.2.3-54-g00ecf