[ticket/416] Allow adding announcements module more than once

B3P-416
This commit is contained in:
Marc Alexander
2014-12-01 21:51:55 +01:00
parent 15fbf01a29
commit 1544d85369
3 changed files with 77 additions and 76 deletions

View File

@@ -162,8 +162,8 @@ function generate_portal_pagination($base_url, $num_items, $per_page, $start_ite
switch ($type)
{
case "announcements":
$pagination_type = 'ap';
$anker = '#a';
$pagination_type = 'ap_' . $module_id;
$anker = '#a_' . $module_id;
break;
case "news":
case "news_all":
@@ -173,8 +173,8 @@ function generate_portal_pagination($base_url, $num_items, $per_page, $start_ite
default:
// this shouldn't happen but default to announcements
$pagination_type = 'ap';
$anker = '#a';
$pagination_type = 'ap_' . $module_id;
$anker = '#a_' . $module_id;
}
// Make sure $per_page is a valid value

View File

@@ -44,16 +44,16 @@ class announcements extends module_base
/** @var \phpbb\auth\auth */
protected $auth;
/** @var \phpbb\cache\driver */
/** @var \phpbb\cache\service */
protected $cache;
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template */
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\pagination */
@@ -81,10 +81,10 @@ class announcements extends module_base
* Construct an announcements object
*
* @param \phpbb\auth\auth $auth phpBB auth service
* @param \phpbb\cache\driver $cache phpBB cache driver
* @param \phpbb\cache\service $cache phpBB cache driver
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver $db Database driver
* @param \phpbb\template\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db Database driver
* @param \phpbb\pagination $pagination phpBB pagination
* @param \board3\portal\includes\modules_helper $modules_helper Portal modules helper
* @param \phpbb\request\request $request phpBB request
@@ -114,10 +114,11 @@ class announcements extends module_base
*/
public function get_template_center($module_id)
{
$announcement = $this->request->variable('announcement', -1);
$announcement = $this->request->variable('announcement_' . $module_id, -1);
$announcement = ($announcement > $this->config['board3_announcements_length_' . $module_id] -1) ? -1 : $announcement;
$start = $this->request->variable('ap', 0);
$start = $this->request->variable('ap_' . $module_id, 0);
$start = ($start < 0) ? 0 : $start;
$total_announcements = 1;
// Fetch announcements from portal functions.php with check if "read full" is requested.
$portal_announcement_length = ($announcement < 0) ? $this->config['board3_announcements_length_' . $module_id] : 0;
@@ -133,10 +134,28 @@ class announcements extends module_base
(bool) $this->config['board3_announcements_forum_exclude_' . $module_id]
);
$topic_icons = false;
if(!empty($fetch_news['topic_icons']))
{
$topic_icons = true;
}
// Standard announcements row
$announcements_row = array(
'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE'),
'S_DISPLAY_ANNOUNCEMENTS_RVS' => ($this->config['board3_show_announcements_replies_views_' . $module_id]) ? true : false,
'S_TOPIC_ICONS' => $topic_icons,
'MODULE_ID' => $module_id,
);
// Any announcements present? If not terminate it here.
if (sizeof($fetch_news) == 0)
{
$this->template->assign_block_vars('announcements_center_row', array(
$this->template->assign_block_vars('announcements', $announcements_row);
$this->template->assign_block_vars('announcements.center_row', array(
'S_NO_TOPICS' => true,
'S_NOT_LAST' => false
));
@@ -210,6 +229,20 @@ class announcements extends module_base
$topic_tracking_info = (get_portal_tracking_info($fetch_news));
if ($this->config['board3_number_of_announcements_' . $module_id] != 0 && $this->config['board3_announcements_archive_' . $module_id])
{
$pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id);
$announcements_row = array_merge($announcements_row, array(
'AP_PAGINATION' => (isset($pagination)) ? $pagination : '',
'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $this->user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($this->user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements),
'AP_PAGE_NUMBER' => $this->pagination->on_page($total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start),
));
}
// Assign announcements row
$this->template->assign_block_vars('announcements', $announcements_row);
if($announcement < 0)
// Show the announcements overview
{
@@ -234,14 +267,9 @@ class announcements extends module_base
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
$real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id;
$read_full_url = ($this->request->is_set('ap')) ? 'ap='. $start . '&amp;announcement=' . $i . '#a' . $i : 'announcement=' . $i . '#a' . $i;
$read_full_url = ($this->request->is_set('ap_' . $module_id)) ? "ap_{$module_id}=$start&amp;announcement_{$module_id}=$i#a_{$module_id}_$i" : "announcement_{$module_id}=$i#a_{$module_id}_$i";
$view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
if ($this->config['board3_announcements_archive_' . $module_id])
{
$pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements');
}
$replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies'];
switch ($fetch_news[$i]['topic_type'])
@@ -282,7 +310,7 @@ class announcements extends module_base
// Grab icons
$icons = $this->cache->obtain_icons();
$this->template->assign_block_vars('announcements_center_row', array(
$this->template->assign_block_vars('announcements.center_row', array(
'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $this->config['allow_attachments']) ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '',
'FORUM_NAME' => ($forum_id) ? $fetch_news[$i]['forum_name'] : '',
'TITLE' => $fetch_news[$i]['topic_title'],
@@ -319,25 +347,17 @@ class announcements extends module_base
'S_HAS_ATTACHMENTS' => (!empty($fetch_news[$i]['attachments'])) ? true : false,
));
$this->pagination->generate_template_pagination($view_topic_url, 'announcements_center_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1, true, true);
$this->pagination->generate_template_pagination($view_topic_url, 'announcements.center_row.pagination', 'ap_' . $module_id, $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1, true, true);
if(!empty($fetch_news[$i]['attachments']))
{
foreach ($fetch_news[$i]['attachments'] as $attachment)
{
$this->template->assign_block_vars('announcements_center_row.attachment', array(
$this->template->assign_block_vars('announcements.center_row.attachment', array(
'DISPLAY_ATTACHMENT' => $attachment)
);
}
}
if ($this->config['board3_number_of_announcements_' . $module_id] != 0 && $this->config['board3_announcements_archive_' . $module_id])
{
$this->template->assign_vars(array(
'AP_PAGINATION' => (isset($pagination)) ? $pagination : '',
'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $this->user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($this->user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements),
'AP_PAGE_NUMBER' => $this->pagination->on_page($total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start))
);
}
}
}
else
@@ -363,14 +383,14 @@ class announcements extends module_base
$read_full = $this->user->lang['BACK'];
$real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id;
$read_full_url = ($this->request->is_set('ap')) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "ap=$start#a$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#a$i");
$read_full_url = ($this->request->is_set('ap_' . $module_id)) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "ap_{$module_id}=$start#a_{$module_id}_$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#a_{$module_id}_$i");
$view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
if ($this->config['board3_announcements_archive_' . $module_id])
{
$pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements');
$pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), 1, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements');
}
$this->template->assign_block_vars('announcements_center_row', array(
$this->template->assign_block_vars('announcements.center_row', array(
'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $this->config['allow_attachments']) ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '',
'FORUM_NAME' => ($forum_id) ? $fetch_news[$i]['forum_name'] : '',
'TITLE' => $fetch_news[$i]['topic_title'],
@@ -394,42 +414,19 @@ class announcements extends module_base
'S_HAS_ATTACHMENTS' => (!empty($fetch_news[$i]['attachments'])) ? true : false,
));
$this->pagination->generate_template_pagination($view_topic_url, 'announcements_center_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1, true, true);
$this->pagination->generate_template_pagination($view_topic_url, 'announcements.center_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1, true, true);
if(!empty($fetch_news[$i]['attachments']))
{
foreach ($fetch_news[$i]['attachments'] as $attachment)
{
$this->template->assign_block_vars('announcements_center_row.attachment', array(
$this->template->assign_block_vars('announcements.center_row.attachment', array(
'DISPLAY_ATTACHMENT' => $attachment)
);
}
}
if ($this->config['board3_number_of_announcements_' . $module_id] <> 0 && $this->config['board3_announcements_archive_' . $module_id])
{
$this->template->assign_vars(array(
'AP_PAGINATION' => (!empty($pagination)) ? $pagination : '',
'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $this->user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($this->user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements),
'AP_PAGE_NUMBER' => $this->pagination->on_page($total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start))
);
}
}
}
$topic_icons = false;
if(!empty($fetch_news['topic_icons']))
{
$topic_icons = true;
}
$this->template->assign_vars(array(
'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE'),
'S_DISPLAY_ANNOUNCEMENTS_RVS' => ($this->config['board3_show_announcements_replies_views_' . $module_id]) ? true : false,
'S_TOPIC_ICONS' => $topic_icons,
));
if ($this->config['board3_announcements_style_' . $module_id])
{

View File

@@ -1,47 +1,51 @@
{$C_BLOCK_H_L}{$TITLE}{$C_BLOCK_H_R}
<!-- IF $S_POSTBODY_TOP --><div class="postbody portal-module-postbody"><!-- ENDIF -->
<!-- BEGIN announcements_center_row -->
<!-- IF announcements_center_row.S_NO_TOPICS -->
<!-- BEGIN announcements -->
<!-- IF announcements.MODULE_ID eq $MODULE_ID -->
<!-- BEGIN center_row -->
<!-- IF announcements.center_row.S_NO_TOPICS -->
<div class="post bg2">
<div class="inner">
<span><strong>{L_NO_ANNOUNCEMENTS}</strong></span>
<!-- ELSE -->
<div class="post <!-- IF announcements_center_row.S_ROW_COUNT is odd -->bg1<!-- ELSE -->bg2<!-- ENDIF --> portal-no-margin">
<div class="post <!-- IF announcements.center_row.S_ROW_COUNT is odd -->bg1<!-- ELSE -->bg2<!-- ENDIF --> portal-no-margin">
<div class="inner">
<h4 class="first"><a <!-- IF announcements_center_row.S_FIRST_ROW -->id="a" <!-- ENDIF -->name="a{announcements_center_row.A_ID}"></a><!-- IF announcements_center_row.S_UNREAD_INFO --><a href="{announcements_center_row.U_VIEW_UNREAD}">{NEWEST_POST_IMG}</a><!-- ELSE --><a href="{announcements_center_row.U_LAST_COMMENTS}">{READ_POST_IMG}</a><!-- ENDIF --> {announcements_center_row.ATTACH_ICON_IMG} <!-- IF announcements_center_row.S_POLL --> <strong>{L_VIEW_TOPIC_POLL}{L_COLON} </strong><!-- ENDIF --><!-- IF announcements_center_row.TOPIC_ICON_IMG --><img src="{T_ICONS_PATH}{announcements_center_row.TOPIC_ICON_IMG}" width="{announcements_center_row.TOPIC_ICON_IMG_WIDTH}" height="{announcements_center_row.TOPIC_ICON_IMG_HEIGHT}" alt="" /> <!-- ENDIF --><a href="{announcements_center_row.U_VIEW_COMMENTS}"><strong>{announcements_center_row.TITLE}</strong></a></h4>
<!-- IF announcements_center_row.PAGINATION --><strong class="pagination"><span>{announcements_center_row.PAGINATION}</span></strong><!-- ENDIF -->
<h4 class="first"><a <!-- IF announcements.center_row.S_FIRST_ROW -->id="a_{$MODULE_ID}" <!-- ENDIF -->name="a_{$MODULE_ID}_{announcements.center_row.A_ID}"></a><!-- IF announcements.center_row.S_UNREAD_INFO --><a href="{announcements.center_row.U_VIEW_UNREAD}">{NEWEST_POST_IMG}</a><!-- ELSE --><a href="{announcements.center_row.U_LAST_COMMENTS}">{READ_POST_IMG}</a><!-- ENDIF --> {announcements.center_row.ATTACH_ICON_IMG} <!-- IF announcements.center_row.S_POLL --> <strong>{L_VIEW_TOPIC_POLL}{L_COLON} </strong><!-- ENDIF --><!-- IF announcements.center_row.TOPIC_ICON_IMG --><img src="{T_ICONS_PATH}{announcements.center_row.TOPIC_ICON_IMG}" width="{announcements.center_row.TOPIC_ICON_IMG_WIDTH}" height="{announcements.center_row.TOPIC_ICON_IMG_HEIGHT}" alt="" /> <!-- ENDIF --><a href="{announcements.center_row.U_VIEW_COMMENTS}"><strong>{announcements.center_row.TITLE}</strong></a></h4>
<!-- IF announcements.center_row.PAGINATION --><strong class="pagination"><span>{announcements.center_row.PAGINATION}</span></strong><!-- ENDIF -->
<ul class="linklist">
<li>{L_POSTED} {L_POST_BY_AUTHOR}{L_COLON} {announcements_center_row.POSTER_FULL} &raquo; {announcements_center_row.TIME}</li>
<li class="rightside"><!-- IF announcements_center_row.FORUM_NAME -->{L_FORUM}{L_COLON} <strong><a href="{announcements_center_row.U_VIEWFORUM}">{announcements_center_row.FORUM_NAME}</a></strong><!-- ELSE -->{L_GLOBAL_ANNOUNCEMENT}<!-- ENDIF --></li>
<li>{L_POSTED} {L_POST_BY_AUTHOR}{L_COLON} {announcements.center_row.POSTER_FULL} &raquo; {announcements.center_row.TIME}</li>
<li class="rightside"><!-- IF announcements.center_row.FORUM_NAME -->{L_FORUM}{L_COLON} <strong><a href="{announcements.center_row.U_VIEWFORUM}">{announcements.center_row.FORUM_NAME}</a></strong><!-- ELSE -->{L_GLOBAL_ANNOUNCEMENT}<!-- ENDIF --></li>
</ul>
<!-- IF not $S_POSTBODY_TOP --><div class="postbody portal-module-postbody"><!-- ENDIF -->
<div class="content">
<br />{announcements_center_row.TEXT}
<br />{announcements.center_row.TEXT}
</div>
<!-- IF announcements_center_row.S_HAS_ATTACHMENTS -->
<!-- IF announcements.center_row.S_HAS_ATTACHMENTS -->
<dl class="attachbox">
<dt>{L_ATTACHMENTS}</dt>
<!-- BEGIN attachment -->
<dd>{announcements_center_row.attachment.DISPLAY_ATTACHMENT}</dd>
<dd>{announcements.center_row.attachment.DISPLAY_ATTACHMENT}</dd>
<!-- END attachment -->
</dl>
<!-- ENDIF -->
<br class="portal-clear" />
<span class="portal-title-span">{L_TOPIC_VIEWS}{L_COLON} {announcements_center_row.TOPIC_VIEWS} &nbsp;&bull;&nbsp; <a href="{announcements_center_row.U_VIEW_COMMENTS}" title="{L_VIEW_COMMENTS}">{L_COMMENTS}{L_COLON} {announcements_center_row.REPLIES}</a> &nbsp;&bull;&nbsp; <a href="{announcements_center_row.U_POST_COMMENT}">{L_POST_REPLY}</a></span>
<span class="portal-read-all-link">{announcements_center_row.OPEN}<a href="{announcements_center_row.U_READ_FULL}">{announcements_center_row.L_READ_FULL}</a>{announcements_center_row.CLOSE}</span>
<span class="portal-title-span">{L_TOPIC_VIEWS}{L_COLON} {announcements.center_row.TOPIC_VIEWS} &nbsp;&bull;&nbsp; <a href="{announcements.center_row.U_VIEW_COMMENTS}" title="{L_VIEW_COMMENTS}">{L_COMMENTS}{L_COLON} {announcements.center_row.REPLIES}</a> &nbsp;&bull;&nbsp; <a href="{announcements.center_row.U_POST_COMMENT}">{L_POST_REPLY}</a></span>
<span class="portal-read-all-link">{announcements.center_row.OPEN}<a href="{announcements.center_row.U_READ_FULL}">{announcements.center_row.L_READ_FULL}</a>{announcements.center_row.CLOSE}</span>
<div class="back2top"><a href="#wrap" class="top" title="{L_BACK_TO_TOP}">{L_BACK_TO_TOP}</a></div>
<!-- IF announcements_center_row.S_NOT_LAST --><br class="portal-clear" /><!-- ENDIF -->
<!-- IF announcements_center_row.S_LAST_ROW and (AP_PAGINATION or TOTAL_ANNOUNCEMENTS) -->
<!-- IF announcements.center_row.S_NOT_LAST --><br class="portal-clear" /><!-- ENDIF -->
<!-- IF announcements.center_row.S_LAST_ROW and (announcements.AP_PAGINATION or announcements.TOTAL_ANNOUNCEMENTS) -->
<hr class="dashed" />
<div class="pagination">
{TOTAL_ANNOUNCEMENTS}
<!-- IF AP_PAGE_NUMBER --><!-- IF AP_PAGINATION --> &bull; {AP_PAGE_NUMBER} &bull; {AP_PAGINATION}<!-- ELSE --> &bull; {AP_PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
{announcements.TOTAL_ANNOUNCEMENTS}
<!-- IF announcements.AP_PAGE_NUMBER --><!-- IF announcements.AP_PAGINATION --> &bull; {announcements.AP_PAGE_NUMBER} &bull; {announcements.AP_PAGINATION}<!-- ELSE --> &bull; {announcements.AP_PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
</div>
<!-- ENDIF -->
<!-- IF not $S_POSTBODY_TOP --></div><!-- ENDIF -->
<!-- ENDIF -->
</div>
</div>
<!-- END announcements_center_row -->
<!-- END center_row -->
<!-- ENDIF -->
<!-- END announcements -->
<!-- IF $S_POSTBODY_TOP --></div><!-- ENDIF -->
{$C_BLOCK_F_L}{$C_BLOCK_F_R}