From 51f97c7e847d555ea6c887416263d19fe1ea4ef9 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 9 Jan 2015 15:46:35 +0100 Subject: [PATCH] section control over their notice lists + HTML id stuff --- lib/attachmentnoticesection.php | 2 +- lib/invitebuttonsection.php | 5 +++++ lib/noticelist.php | 9 ++++++++- lib/noticelistitem.php | 10 +++++++++- lib/noticesection.php | 20 +++++++++++++++---- lib/profilesection.php | 2 +- lib/section.php | 13 +++--------- plugins/Favorite/lib/popularnoticesection.php | 4 ++-- 8 files changed, 45 insertions(+), 20 deletions(-) diff --git a/lib/attachmentnoticesection.php b/lib/attachmentnoticesection.php index b59568749c..7a22bd0e9d 100644 --- a/lib/attachmentnoticesection.php +++ b/lib/attachmentnoticesection.php @@ -70,6 +70,6 @@ class AttachmentNoticeSection extends NoticeSection function divId() { - return 'popular_notices'; + return 'attachment_section'; } } diff --git a/lib/invitebuttonsection.php b/lib/invitebuttonsection.php index 3d385f02a5..57e204cf86 100644 --- a/lib/invitebuttonsection.php +++ b/lib/invitebuttonsection.php @@ -64,6 +64,11 @@ class InviteButtonSection extends Section return false; } + function divId() + { + return 'invite_button'; + } + function showContent() { $this->out->element( diff --git a/lib/noticelist.php b/lib/noticelist.php index 6a430d210b..c9d43c097a 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -55,6 +55,7 @@ class NoticeList extends Widget protected $addressees = true; protected $attachments = true; + protected $id_prefix = null; protected $maxchars = 0; protected $options = true; protected $show_n = NOTICES_PER_PAGE; @@ -81,7 +82,12 @@ class NoticeList extends Widget $this->$key = (bool)$prefs[$key]; } } - + // string preferences + foreach(array('id_prefix') as $key) { + if (array_key_exists($key, $prefs)) { + $this->$key = $prefs[$key]; + } + } } /** @@ -134,6 +140,7 @@ class NoticeList extends Widget { $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); diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index be55c522c8..4a50f548cb 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -60,6 +60,7 @@ class NoticeListItem extends Widget protected $addressees = true; protected $attachments = true; + protected $id_prefix = null; protected $options = true; protected $maxchars = 0; // if <= 0 it means use full posts @@ -99,6 +100,12 @@ class NoticeListItem extends Widget $this->$key = (bool)$prefs[$key]; } } + // string preferences + foreach(array('id_prefix') as $key) { + if (array_key_exists($key, $prefs)) { + $this->$key = $prefs[$key]; + } + } } /** @@ -211,8 +218,9 @@ class NoticeListItem extends Widget if (!empty($this->notice->source)) { $class .= ' notice-source-'.$this->notice->source; } + $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : ''); $this->out->elementStart('li', array('class' => $class, - 'id' => 'notice-' . $id)); + 'id' => "${id_prefix}notice-${id}")); Event::handle('EndOpenNoticeListItemElement', array($this)); } } diff --git a/lib/noticesection.php b/lib/noticesection.php index 2c52d66a59..ba30c982e4 100644 --- a/lib/noticesection.php +++ b/lib/noticesection.php @@ -46,14 +46,26 @@ define('NOTICES_PER_SECTION', 6); * @link http://status.net/ */ -class NoticeSection extends Section +abstract class NoticeSection extends Section { + protected $addressees = false; + protected $attachments = false; + protected $maxchars = 140; + protected $options = false; + protected $show_n = NOTICES_PER_SECTION; + function showContent() { - // args: notice object, html outputter, preference array for list and items - $list = new SectionNoticeList($this->getNotices(), $this->out); + $prefs = array(); + foreach (array('addressees', 'attachments', 'maxchars', 'options', 'show_n') as $key) { + $prefs[$key] = $this->$key; + } + $prefs['id_prefix'] = $this->divId(); + + // args: notice object, html outputter, preference array for notice lists and their items + $list = new NoticeList($this->getNotices(), $this->out, $prefs); $total = $list->show(); // returns total amount of notices available - return ($total > NOTICES_PER_SECTION); // do we have more to show? + return ($total > $this->show_n); // do we have more to show? } function getNotices() diff --git a/lib/profilesection.php b/lib/profilesection.php index ea50f5283f..53002912bc 100644 --- a/lib/profilesection.php +++ b/lib/profilesection.php @@ -46,7 +46,7 @@ define('PROFILES_PER_SECTION', 6); * @link http://status.net/ */ -class ProfileSection extends Section +abstract class ProfileSection extends Section { function showContent() { diff --git a/lib/section.php b/lib/section.php index 2d8d6f3673..9154bd3e66 100644 --- a/lib/section.php +++ b/lib/section.php @@ -27,11 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/lib/widget.php'; +if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); } /** * Base class for sections @@ -45,7 +41,7 @@ require_once INSTALLDIR.'/lib/widget.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class Section extends Widget +abstract class Section extends Widget { /** * Show the form @@ -94,10 +90,7 @@ class Section extends Widget $this->out->elementEnd('p'); } - function divId() - { - return 'generic_section'; - } + abstract public function divId(); function title() { diff --git a/plugins/Favorite/lib/popularnoticesection.php b/plugins/Favorite/lib/popularnoticesection.php index 2000d302d4..648d7a877a 100644 --- a/plugins/Favorite/lib/popularnoticesection.php +++ b/plugins/Favorite/lib/popularnoticesection.php @@ -47,7 +47,7 @@ class PopularNoticeSection extends NoticeSection { protected $viewer; - function __construct($out, $viewer) + function __construct($out, Profile $viewer=null) { parent::__construct($out); $this->viewer = $viewer; @@ -67,7 +67,7 @@ class PopularNoticeSection extends NoticeSection function divId() { - return 'popular_notices'; + return 'popular_section'; } function moreUrl() -- 2.39.5