gnu-social/lib/noticelist.php

147 lines
4.2 KiB
PHP
Raw Normal View History

<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* widget for displaying a list of notices
*
* 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 UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
2009-08-26 07:16:46 +09:00
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
2009-01-16 08:43:58 +09:00
require_once INSTALLDIR.'/lib/favorform.php';
require_once INSTALLDIR.'/lib/disfavorform.php';
require_once INSTALLDIR.'/lib/attachmentlist.php';
2009-01-16 08:43:58 +09:00
/**
* widget for displaying a list of notices
*
* There are a number of actions that display a list of notices, in
* reverse chronological order. This widget abstracts out most of the
* code for UI for notice lists. It's overridden to hide some
* data for e.g. the profile page.
*
* @category UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
2009-08-26 07:16:46 +09:00
* @link http://status.net/
* @see Notice
* @see NoticeListItem
* @see ProfileNoticeList
*/
2009-01-16 05:19:32 +09:00
class NoticeList extends Widget
{
/** the current stream of notices being displayed. */
var $notice = null;
/**
* constructor
*
* @param Notice $notice stream of notices from DB_DataObject
*/
2009-01-16 05:19:32 +09:00
function __construct($notice, $out=null)
{
2009-01-20 01:35:04 +09:00
parent::__construct($out);
$this->notice = $notice;
}
/**
* show the list of notices
*
* "Uses up" the stream by looping through it. So, probably can't
* be called twice on the same list.
*
* @return int count of notices listed.
*/
function show()
{
2009-01-16 07:31:32 +09:00
$this->out->elementStart('div', array('id' =>'notices_primary'));
$this->out->elementStart('ol', array('class' => 'notices xoxo'));
2011-08-02 05:43:44 +09:00
$notices = $this->notice->fetchAll();
2011-08-03 00:22:37 +09:00
$total = count($notices);
2011-08-02 05:43:44 +09:00
$notices = array_slice($notices, 0, NOTICES_PER_PAGE);
self::prefill($notices);
2011-08-02 05:43:44 +09:00
foreach ($notices as $notice) {
try {
2011-08-02 05:43:44 +09:00
$item = $this->newListItem($notice);
$item->show();
} catch (Exception $e) {
// we log exceptions and continue
common_log(LOG_ERR, $e->getMessage());
continue;
}
}
$this->out->elementEnd('ol');
2009-01-16 07:31:32 +09:00
$this->out->elementEnd('div');
2011-08-03 00:22:37 +09:00
return $total;
}
/**
* returns a new list item for the current notice
*
* Recipe (factory?) method; overridden by sub-classes to give
* a different list item class.
*
* @param Notice $notice the current notice
*
* @return NoticeListItem a list item for displaying the notice
*/
function newListItem($notice)
{
2009-01-16 05:19:32 +09:00
return new NoticeListItem($notice, $this->out);
}
2011-08-02 05:43:44 +09:00
static function prefill(&$notices, $avatarSize=AVATAR_STREAM_SIZE)
2011-08-02 05:43:44 +09:00
{
2011-08-03 12:12:21 +09:00
// Prefill attachments
Notice::fillAttachments($notices);
2011-08-02 05:43:44 +09:00
// Prefill the profiles
$profiles = Notice::fillProfiles($notices);
// Prefill the avatars
Profile::fillAvatars($profiles, $avatarSize);
$p = Profile::current();
$ids = array();
foreach ($notices as $notice) {
$ids[] = $notice->id;
}
if (!empty($p)) {
Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id));
}
2011-08-02 05:43:44 +09:00
}
}