Something smarter than the 'addressees' and 'attachments' booleans etc.
is desired.
var $notice = null;
+ protected $addressees = true;
+ protected $attachments = true;
+ protected $maxchars = 0;
+ protected $options = true;
+ protected $show_n = NOTICES_PER_PAGE;
+
/**
* constructor
*
* @param Notice $notice stream of notices from DB_DataObject
*/
- function __construct(Notice $notice, $out=null)
+ function __construct(Notice $notice, $out=null, array $prefs=array())
{
parent::__construct($out);
$this->notice = $notice;
+
+ // integer preferences
+ foreach(array('show_n', 'maxchars') as $key) {
+ if (array_key_exists($key, $prefs)) {
+ $this->$key = (int)$prefs[$key];
+ }
+ }
+ // boolean preferences
+ foreach(array('addressees', 'attachments', 'options') as $key) {
+ if (array_key_exists($key, $prefs)) {
+ $this->$key = (bool)$prefs[$key];
+ }
+ }
+
}
/**
* "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.
+ * @param integer $n The amount of notices to show.
+ *
+ * @return int Total amount of notices actually available.
*/
function show()
{
$notices = $this->notice->fetchAll();
$total = count($notices);
- $notices = array_slice($notices, 0, NOTICES_PER_PAGE);
+ $notices = array_slice($notices, 0, $this->show_n);
self::prefill($notices);
*/
function newListItem(Notice $notice)
{
- return new NoticeListItem($notice, $this->out);
+ $prefs = array('addressees' => $this->addressees,
+ 'attachments' => $this->attachments,
+ 'maxchars' => $this->maxchars,
+ 'options' => $this->options);
+ return new NoticeListItem($notice, $this->out, $prefs);
}
static function prefill(array &$notices)
/** The profile of the author of the notice, extracted once for convenience. */
var $profile = null;
+ protected $addressees = true;
+ protected $attachments = true;
+ protected $options = true;
+ protected $maxchars = 0; // if <= 0 it means use full posts
+
/**
* constructor
*
*
* @param Notice $notice The notice we'll display
*/
- function __construct(Notice $notice, Action $out=null)
+ function __construct(Notice $notice, Action $out=null, array $prefs=array())
{
parent::__construct($out);
if (!empty($notice->repeat_of)) {
} else {
$this->notice = $notice;
}
+
$this->profile = $this->notice->getProfile();
+
+ // integer preferences
+ foreach(array('maxchars') as $key) {
+ if (array_key_exists($key, $prefs)) {
+ $this->$key = (int)$prefs[$key];
+ }
+ }
+ // boolean preferences
+ foreach(array('addressees', 'attachments', 'options') as $key) {
+ if (array_key_exists($key, $prefs)) {
+ $this->$key = (bool)$prefs[$key];
+ }
+ }
}
/**
$this->elementStart('section', array('class'=>'notice-headers'));
$this->showNoticeTitle();
$this->showAuthor();
- $this->showAddressees();
+ if ($this->addressees) { $this->showAddressees(); }
$this->elementEnd('section');
}
{
$this->elementStart('footer');
$this->showNoticeInfo();
- $this->showNoticeAttachments();
- $this->showNoticeOptions();
+ if ($this->attachments) { $this->showNoticeAttachments(); }
+ if ($this->options) { $this->showNoticeOptions(); }
$this->elementEnd('footer');
}
// FIXME: URL, image, video, audio
$this->out->elementStart('article', array('class' => 'e-content'));
if (Event::handle('StartShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()))) {
- if ($this->notice->rendered) {
+ if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) {
+ $this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]');
+ } elseif ($this->notice->rendered) {
$this->out->raw($this->notice->rendered);
} else {
// XXX: may be some uncooked notices in the DB,
* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL') && !defined('GNUSOCIAL')) { exit(1); }
define('NOTICES_PER_SECTION', 6);
class NoticeSection extends Section
{
+ protected $addressees = false;
+ protected $attachments = false;
protected $maxchars = 140;
+ protected $options = false;
+ protected $show_n = NOTICES_PER_SECTION;
function showContent()
{
- $notices = $this->getNotices();
- $cnt = 0;
- $this->out->elementStart('ol', 'notices xoxo');
- while ($notices->fetch() && ++$cnt <= NOTICES_PER_SECTION) {
- $this->showNotice($notices);
- }
-
- $this->out->elementEnd('ol');
- return ($cnt > NOTICES_PER_SECTION);
+ // args: notice object, html outputter, preference array for list and items
+ $list = new NoticeList($this->getNotices(), $this->out,
+ array('addressees' => $this->addressees,
+ 'attachments' => $this->attachments,
+ 'maxchars'=> $this->maxchars,
+ 'options' => $this->options,
+ 'show_n' => $this->show_n));
+ $total = $list->show(); // returns total amount of notices available
+ return ($total > NOTICES_PER_SECTION); // do we have more to show?
}
function getNotices()
{
return null;
}
-
- function showNotice(Notice $notice)
- {
- $profile = $notice->getProfile();
- if (empty($profile)) {
- common_log(LOG_WARNING, sprintf("Notice %d has no profile",
- $notice->id));
- return;
- }
- $this->out->elementStart('li', 'h-entry notice');
- $this->out->elementStart('div', 'h-card');
- $this->out->elementStart('a', array('title' => $profile->getBestName(),
- 'href' => $profile->profileurl,
- 'class' => 'p-author u-url p-name'));
- $avatarUrl = $profile->avatarUrl(AVATAR_MINI_SIZE);
- $this->out->element('img', array('src' => $avatarUrl,
- 'width' => AVATAR_MINI_SIZE,
- 'height' => AVATAR_MINI_SIZE,
- 'class' => 'avatar u-photo',
- 'alt' => $profile->getBestName()));
- $this->out->text($profile->getBestName());
- $this->out->elementEnd('a');
-
- $this->out->elementStart('p', 'e-content');
- $this->out->text(mb_strlen($notice->content) > $this->maxchars
- ? mb_substr($notice->content, 0, $this->maxchars) . '[…]'
- : $notice->content);
- $this->out->elementEnd('p');
-
- $this->out->elementStart('div', 'entry_content');
- $nli = new NoticeListItem($notice, $this->out);
- $nli->showNoticeLink();
- $this->out->elementEnd('div');
-
- if (!empty($notice->value)) {
- $this->out->elementStart('p');
- $this->out->text($notice->value);
- $this->out->elementEnd('p');
- }
- $this->out->elementEnd('div');
- $this->out->elementEnd('li');
- }
}