section control over their notice lists + HTML id stuff

This commit is contained in:
Mikael Nordfeldth 2015-01-09 15:46:35 +01:00
parent 7ed1ef081b
commit 51f97c7e84
8 changed files with 45 additions and 20 deletions

View File

@ -70,6 +70,6 @@ class AttachmentNoticeSection extends NoticeSection
function divId() function divId()
{ {
return 'popular_notices'; return 'attachment_section';
} }
} }

View File

@ -64,6 +64,11 @@ class InviteButtonSection extends Section
return false; return false;
} }
function divId()
{
return 'invite_button';
}
function showContent() function showContent()
{ {
$this->out->element( $this->out->element(

View File

@ -55,6 +55,7 @@ class NoticeList extends Widget
protected $addressees = true; protected $addressees = true;
protected $attachments = true; protected $attachments = true;
protected $id_prefix = null;
protected $maxchars = 0; protected $maxchars = 0;
protected $options = true; protected $options = true;
protected $show_n = NOTICES_PER_PAGE; protected $show_n = NOTICES_PER_PAGE;
@ -81,7 +82,12 @@ class NoticeList extends Widget
$this->$key = (bool)$prefs[$key]; $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, $prefs = array('addressees' => $this->addressees,
'attachments' => $this->attachments, 'attachments' => $this->attachments,
'id_prefix' => $this->id_prefix,
'maxchars' => $this->maxchars, 'maxchars' => $this->maxchars,
'options' => $this->options); 'options' => $this->options);
return new NoticeListItem($notice, $this->out, $prefs); return new NoticeListItem($notice, $this->out, $prefs);

View File

@ -60,6 +60,7 @@ class NoticeListItem extends Widget
protected $addressees = true; protected $addressees = true;
protected $attachments = true; protected $attachments = true;
protected $id_prefix = null;
protected $options = true; protected $options = true;
protected $maxchars = 0; // if <= 0 it means use full posts protected $maxchars = 0; // if <= 0 it means use full posts
@ -99,6 +100,12 @@ class NoticeListItem extends Widget
$this->$key = (bool)$prefs[$key]; $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)) { if (!empty($this->notice->source)) {
$class .= ' notice-source-'.$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, $this->out->elementStart('li', array('class' => $class,
'id' => 'notice-' . $id)); 'id' => "${id_prefix}notice-${id}"));
Event::handle('EndOpenNoticeListItemElement', array($this)); Event::handle('EndOpenNoticeListItemElement', array($this));
} }
} }

View File

@ -46,14 +46,26 @@ define('NOTICES_PER_SECTION', 6);
* @link http://status.net/ * @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() function showContent()
{ {
// args: notice object, html outputter, preference array for list and items $prefs = array();
$list = new SectionNoticeList($this->getNotices(), $this->out); 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 $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() function getNotices()

View File

@ -46,7 +46,7 @@ define('PROFILES_PER_SECTION', 6);
* @link http://status.net/ * @link http://status.net/
*/ */
class ProfileSection extends Section abstract class ProfileSection extends Section
{ {
function showContent() function showContent()
{ {

View File

@ -27,11 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
exit(1);
}
require_once INSTALLDIR.'/lib/widget.php';
/** /**
* Base class for sections * 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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class Section extends Widget abstract class Section extends Widget
{ {
/** /**
* Show the form * Show the form
@ -94,10 +90,7 @@ class Section extends Widget
$this->out->elementEnd('p'); $this->out->elementEnd('p');
} }
function divId() abstract public function divId();
{
return 'generic_section';
}
function title() function title()
{ {

View File

@ -47,7 +47,7 @@ class PopularNoticeSection extends NoticeSection
{ {
protected $viewer; protected $viewer;
function __construct($out, $viewer) function __construct($out, Profile $viewer=null)
{ {
parent::__construct($out); parent::__construct($out);
$this->viewer = $viewer; $this->viewer = $viewer;
@ -67,7 +67,7 @@ class PopularNoticeSection extends NoticeSection
function divId() function divId()
{ {
return 'popular_notices'; return 'popular_section';
} }
function moreUrl() function moreUrl()