X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fnoticelistitem.php;h=f25613b9a96988972946b96b024cda003c735697;hb=cafab14f2bdbd05c9047d53cc094ec483ee23e81;hp=dc1a1a02b1c0d372d918d086fadeb07eb7acfbd0;hpb=d32fef60394dbacca2f1dec24fd55043e328d0d1;p=quix0rs-gnu-social.git diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index dc1a1a02b1..f25613b9a9 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -58,6 +58,13 @@ class NoticeListItem extends Widget /** The profile of the author of the notice, extracted once for convenience. */ var $profile = null; + protected $addressees = true; + protected $attachments = true; + protected $id_prefix = null; + protected $options = true; + protected $maxchars = 0; // if <= 0 it means use full posts + protected $item_tag = 'li'; + /** * constructor * @@ -65,7 +72,7 @@ class NoticeListItem extends Widget * * @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)) { @@ -79,7 +86,27 @@ class NoticeListItem extends Widget } 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]; + } + } + // string preferences + foreach(array('id_prefix', 'item_tag') as $key) { + if (array_key_exists($key, $prefs)) { + $this->$key = $prefs[$key]; + } + } } /** @@ -123,7 +150,7 @@ class NoticeListItem extends Widget $this->elementStart('section', array('class'=>'notice-headers')); $this->showNoticeTitle(); $this->showAuthor(); - $this->showAddressees(); + if ($this->addressees) { $this->showAddressees(); } $this->elementEnd('section'); } @@ -131,8 +158,8 @@ class NoticeListItem extends Widget { $this->elementStart('footer'); $this->showNoticeInfo(); - $this->showNoticeAttachments(); - $this->showNoticeOptions(); + if ($this->options) { $this->showNoticeOptions(); } + if ($this->attachments) { $this->showNoticeAttachments(); } $this->elementEnd('footer'); } @@ -153,7 +180,6 @@ class NoticeListItem extends Widget $this->showNoticeSource(); $this->showNoticeLocation(); $this->showPermalink(); - $this->showRepeat(); Event::handle('EndShowNoticeInfo', array($this)); } } @@ -166,7 +192,6 @@ class NoticeListItem extends Widget $this->out->elementStart('div', 'notice-options'); if (Event::handle('StartShowNoticeOptionItems', array($this))) { $this->showReplyLink(); - $this->showRepeatForm(); $this->showDeleteLink(); Event::handle('EndShowNoticeOptionItems', array($this)); } @@ -192,8 +217,9 @@ class NoticeListItem extends Widget if (!empty($this->notice->source)) { $class .= ' notice-source-'.$this->notice->source; } - $this->out->elementStart('li', array('class' => $class, - 'id' => 'notice-' . $id)); + $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : ''); + $this->out->elementStart($this->item_tag, array('class' => $class, + 'id' => "${id_prefix}notice-${id}")); Event::handle('EndOpenNoticeListItemElement', array($this)); } } @@ -289,7 +315,9 @@ class NoticeListItem extends Widget // 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, @@ -498,32 +526,6 @@ class NoticeListItem extends Widget } } - /** - * show a link to the author of repeat - * - * @return void - */ - function showRepeat() - { - if (!empty($this->repeat)) { - - $repeater = Profile::getKV('id', $this->repeat->profile_id); - - $attrs = array('href' => $repeater->profileurl, - 'class' => 'h-card p-author', - 'title' => $repeater->getFancyName()); - - $this->out->elementStart('span', 'repeat h-entry'); - - // TRANS: Addition in notice list item if notice was repeated. Followed by a span with a nickname. - $this->out->raw(_('Repeated by').' '); - - $this->out->element('a', $attrs, $repeater->getNickname()); - - $this->out->elementEnd('span'); - } - } - /** * show a link to reply to the current notice * @@ -567,7 +569,7 @@ class NoticeListItem extends Widget $deleteurl = common_local_url('deletenotice', array('notice' => $todel->id)); $this->out->element('a', array('href' => $deleteurl, - 'class' => 'notice_delete', + 'class' => 'notice_delete popup', // TRANS: Link title in notice list item to delete a notice. 'title' => _('Delete this notice from the timeline.')), // TRANS: Link text in notice list item to delete a notice. @@ -575,34 +577,6 @@ class NoticeListItem extends Widget } } - /** - * show the form to repeat a notice - * - * @return void - */ - function showRepeatForm() - { - if ($this->notice->scope == Notice::PUBLIC_SCOPE || - $this->notice->scope == Notice::SITE_SCOPE) { - $user = common_current_user(); - if (!empty($user) && - $user->id != $this->notice->profile_id) { - $this->out->text(' '); - $profile = $user->getProfile(); - if ($profile->hasRepeated($this->notice)) { - $this->out->element('span', array('class' => 'repeated', - // TRANS: Title for repeat form status in notice list when a notice has been repeated. - 'title' => _('Notice repeated.')), - // TRANS: Repeat form status in notice list when a notice has been repeated. - _('Repeated')); - } else { - $rf = new RepeatForm($this->out, $this->notice); - $rf->show(); - } - } - } - } - /** * finish the notice *