123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
- class NoticeList extends Widget
- {
-
- var $notice = null;
- protected $addressees = true;
- protected $attachments = true;
- protected $id_prefix = null;
- protected $maxchars = 0;
- protected $options = true;
- protected $show_n = NOTICES_PER_PAGE;
-
- function __construct(Notice $notice, $out=null, array $prefs=array())
- {
- parent::__construct($out);
- $this->notice = $notice;
-
- foreach(array('show_n', 'maxchars') as $key) {
- if (array_key_exists($key, $prefs)) {
- $this->$key = (int)$prefs[$key];
- }
- }
-
- foreach(array('addressees', 'attachments', 'options') as $key) {
- if (array_key_exists($key, $prefs)) {
- $this->$key = (bool)$prefs[$key];
- }
- }
-
- foreach(array('id_prefix') as $key) {
- if (array_key_exists($key, $prefs)) {
- $this->$key = $prefs[$key];
- }
- }
- }
-
- public function show()
- {
- $this->out->elementStart('ol', array('class' => 'notices xoxo'));
- $notices = $this->notice->fetchAll();
- $total = count($notices);
- $notices = array_slice($notices, 0, $this->show_n);
-
- self::prefill($notices);
-
- foreach ($notices as $notice) {
- try {
- $item = $this->newListItem($notice);
- $item->show();
- } catch (Exception $e) {
-
- common_log(LOG_ERR, $e->getMessage());
- continue;
- }
- }
- $this->out->elementEnd('ol');
- return $total;
- }
-
- function newListItem(Notice $notice)
- {
- $prefs = array('addressees' => $this->addressees,
- 'attachments' => $this->attachments,
- 'id_prefix' => $this->id_prefix,
- 'maxchars' => $this->maxchars,
- 'options' => $this->options);
- return new NoticeListItem($notice, $this->out, $prefs);
- }
-
- static function prefill(array &$notices)
- {
- $scoped = Profile::current();
- $notice_ids = Notice::_idsOf($notices);
- if (Event::handle('StartNoticeListPrefill', array(&$notices, $notice_ids, $scoped))) {
-
- Notice::fillAttachments($notices);
-
- $profiles = Notice::fillProfiles($notices);
- Event::handle('EndNoticeListPrefill', array(&$notices, &$profiles, $notice_ids, $scoped));
- }
- }
- }
|