Created
February 19, 2017 19:16
-
-
Save msaulohenrique/a7f50b3c330d65a300937a1ec482ff1c to your computer and use it in GitHub Desktop.
PORTAL_RECENT Sidebar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @package Board3 Portal v2.1 | |
* @copyright (c) 2013 Board3 Group ( www.board3.de ) | |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 | |
* | |
*/ | |
namespace board3\portal\modules; | |
/** | |
* @package Recent | |
*/ | |
class recent extends module_base | |
{ | |
/** | |
* Allowed columns: Just sum up your options (Exp: left + right = 10) | |
* top 1 | |
* left 2 | |
* center 4 | |
* right 8 | |
* bottom 16 | |
*/ | |
public $columns = 31; | |
/** | |
* Default modulename | |
*/ | |
public $name = 'PORTAL_RECENT'; | |
/** | |
* Default module-image: | |
* file must be in "{T_THEME_PATH}/images/portal/" | |
*/ | |
public $image_src = ''; | |
/** | |
* module-language file | |
* file must be in "language/{$user->lang}/mods/portal/" | |
*/ | |
public $language = 'portal_recent_module'; | |
/** | |
* custom acp template | |
* file must be in "adm/style/portal/" | |
*/ | |
public $custom_acp_tpl = ''; | |
/** @var \phpbb\auth\auth */ | |
protected $auth; | |
/** @var \phpbb\config\config */ | |
protected $config; | |
/** @var \phpbb\db\driver */ | |
protected $db; | |
/** @var \phpbb\request\request */ | |
protected $request; | |
/** @var \phpbb\template */ | |
protected $template; | |
/** @var string phpBB root path */ | |
protected $phpbb_root_path; | |
/** @var \phpbb\user */ | |
protected $user; | |
/** @var string PHP file extension */ | |
protected $php_ext; | |
/** | |
* Construct a recent object | |
* | |
* @param \phpbb\auth\auth $auth phpBB auth | |
* @param \phpbb\config\config $config phpBB config | |
* @param \phpbb\db\driver $db phpBB db driver | |
* @param \phpbb\request\request $request phpBB request | |
* @param \phpbb\template $template phpBB template | |
* @param string $phpbb_root_path phpBB root path | |
* @param \phpbb\user $user phpBB user object | |
* @param string $phpEx php file extension | |
*/ | |
public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $user, $phpEx) | |
{ | |
$this->auth = $auth; | |
$this->config = $config; | |
$this->db = $db; | |
$this->request = $request; | |
$this->template = $template; | |
$this->phpbb_root_path = $phpbb_root_path; | |
$this->user = $user; | |
$this->php_ext = $phpEx; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function get_template_center($module_id) | |
{ | |
// | |
// Exclude forums | |
// | |
$sql_where = ''; | |
if ($this->config['board3_recent_forum_' . $module_id] > 0) | |
{ | |
$exclude_forums = explode(',', $this->config['board3_recent_forum_' . $module_id]); | |
$sql_where = ' AND ' . $this->db->sql_in_set('forum_id', array_map('intval', $exclude_forums), ($this->config['board3_recent_exclude_forums_' . $module_id]) ? true : false); | |
} | |
// Get a list of forums the user cannot read | |
$forum_ary = array_unique(array_keys($this->auth->acl_getf('!f_read', true))); | |
// Determine first forum the user is able to read (must not be a category) | |
$sql = 'SELECT forum_id | |
FROM ' . FORUMS_TABLE . ' | |
WHERE forum_type = ' . FORUM_POST; | |
$forum_sql = ''; | |
if (sizeof($forum_ary)) | |
{ | |
$sql .= ' AND ' . $this->db->sql_in_set('forum_id', $forum_ary, true); | |
$forum_sql = ' AND ' . $this->db->sql_in_set('t.forum_id', $forum_ary, true); | |
} | |
$result = $this->db->sql_query_limit($sql, 1, 0, 600); | |
$g_forum_id = (int) $this->db->sql_fetchfield('forum_id'); | |
$this->db->sql_freeresult($result); | |
// | |
// Recent announcements | |
// | |
$sql = 'SELECT topic_title, forum_id, topic_id | |
FROM ' . TOPICS_TABLE . ' t | |
WHERE topic_status <> ' . FORUM_LINK . ' | |
AND topic_visibility = ' . ITEM_APPROVED . ' | |
AND (topic_type = ' . POST_ANNOUNCE . ' OR topic_type = ' . POST_GLOBAL . ') | |
AND topic_moved_id = 0 | |
' . $sql_where . $forum_sql . ' | |
ORDER BY topic_time DESC'; | |
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0 , 600); | |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) | |
{ | |
// auto auth | |
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) | |
{ | |
$this->template->assign_block_vars('latest_announcements', array( | |
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), | |
'FULL_TITLE' => censor_text($row['topic_title']), | |
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) | |
)); | |
} | |
} | |
$this->db->sql_freeresult($result); | |
// | |
// Recent hot topics | |
// | |
$sql = 'SELECT topic_title, forum_id, topic_id | |
FROM ' . TOPICS_TABLE . ' t | |
WHERE topic_visibility = ' . ITEM_APPROVED . ' | |
AND topic_posts_approved >' . $this->config['hot_threshold'] . ' | |
AND topic_moved_id = 0 | |
' . $sql_where . $forum_sql . ' | |
ORDER BY topic_time DESC'; | |
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 600); | |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) | |
{ | |
// auto auth | |
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) | |
{ | |
$this->template->assign_block_vars('latest_hot_topics', array( | |
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), | |
'FULL_TITLE' => censor_text($row['topic_title']), | |
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) | |
)); | |
} | |
} | |
$this->db->sql_freeresult($result); | |
// | |
// Recent topic (only show normal topic) | |
// | |
$sql = 'SELECT topic_title, forum_id, topic_id | |
FROM ' . TOPICS_TABLE . ' t | |
WHERE topic_status <> ' . ITEM_MOVED . ' | |
AND topic_visibility = ' . ITEM_APPROVED . ' | |
AND topic_type = ' . POST_NORMAL . ' | |
AND topic_moved_id = 0 | |
' . $sql_where . $forum_sql . ' | |
ORDER BY topic_time DESC'; | |
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 600); | |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) | |
{ | |
// auto auth | |
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) | |
{ | |
$this->template->assign_block_vars('latest_topics', array( | |
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), | |
'FULL_TITLE' => censor_text($row['topic_title']), | |
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']) | |
)); | |
} | |
} | |
$this->db->sql_freeresult($result); | |
return 'recent_center.html'; | |
} | |
public function get_template_side($module_id) | |
{ | |
// | |
// Exclude forums | |
// | |
$sql_where = ''; | |
if ($this->config['board3_recent_forum_' . $module_id] > 0) | |
{ | |
$exclude_forums = explode(',', $this->config['board3_recent_forum_' . $module_id]); | |
$sql_where = ' AND ' . $this->db->sql_in_set('forum_id', array_map('intval', $exclude_forums), ($this->config['board3_recent_exclude_forums_' . $module_id]) ? true : false); | |
} | |
// Get a list of forums the user cannot read | |
$forum_ary = array_unique(array_keys($this->auth->acl_getf('!f_read', true))); | |
// Determine first forum the user is able to read (must not be a category) | |
$sql = 'SELECT forum_id | |
FROM ' . FORUMS_TABLE . ' | |
WHERE forum_type = ' . FORUM_POST; | |
$forum_sql = ''; | |
if (sizeof($forum_ary)) | |
{ | |
$sql .= ' AND ' . $this->db->sql_in_set('forum_id', $forum_ary, true); | |
$forum_sql = ' AND ' . $this->db->sql_in_set('t.forum_id', $forum_ary, true); | |
} | |
$result = $this->db->sql_query_limit($sql, 1, 0, 600); | |
$g_forum_id = (int) $this->db->sql_fetchfield('forum_id'); | |
$this->db->sql_freeresult($result); | |
// | |
// Recent announcements | |
// | |
$sql = 'SELECT topic_title, forum_id, topic_id | |
FROM ' . TOPICS_TABLE . ' t | |
WHERE topic_status <> ' . FORUM_LINK . ' | |
AND topic_visibility = ' . ITEM_APPROVED . ' | |
AND (topic_type = ' . POST_ANNOUNCE . ' OR topic_type = ' . POST_GLOBAL . ') | |
AND topic_moved_id = 0 | |
' . $sql_where . $forum_sql . ' | |
ORDER BY topic_time DESC'; | |
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0 , 600); | |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) | |
{ | |
// auto auth | |
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) | |
{ | |
$this->template->assign_block_vars('latest_announcements', array( | |
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), | |
'FULL_TITLE' => censor_text($row['topic_title']), | |
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) | |
)); | |
} | |
} | |
$this->db->sql_freeresult($result); | |
// | |
// Recent hot topics | |
// | |
$sql = 'SELECT topic_title, forum_id, topic_id | |
FROM ' . TOPICS_TABLE . ' t | |
WHERE topic_visibility = ' . ITEM_APPROVED . ' | |
AND topic_posts_approved >' . $this->config['hot_threshold'] . ' | |
AND topic_moved_id = 0 | |
' . $sql_where . $forum_sql . ' | |
ORDER BY topic_time DESC'; | |
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 600); | |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) | |
{ | |
// auto auth | |
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) | |
{ | |
$this->template->assign_block_vars('latest_hot_topics', array( | |
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), | |
'FULL_TITLE' => censor_text($row['topic_title']), | |
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) | |
)); | |
} | |
} | |
$this->db->sql_freeresult($result); | |
// | |
// Recent topic (only show normal topic) | |
// | |
$sql = 'SELECT topic_title, forum_id, topic_id, topic_last_poster_name, topic_last_poster_colour, topic_last_poster_id, topic_last_post_time | |
FROM ' . TOPICS_TABLE . ' t | |
WHERE topic_status <> ' . ITEM_MOVED . ' | |
AND topic_visibility = ' . ITEM_APPROVED . ' | |
AND topic_type = ' . POST_NORMAL . ' | |
AND topic_moved_id = 0 | |
' . $sql_where . $forum_sql . ' | |
ORDER BY topic_time DESC'; | |
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 600); | |
while (($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) | |
{ | |
// auto auth | |
if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) | |
{ | |
$this->template->assign_block_vars('latest_topics', array( | |
'TITLE' => character_limit($row['topic_title'], $this->config['board3_recent_title_limit_' . $module_id]), | |
'FULL_TITLE' => censor_text($row['topic_title']), | |
'LAST_POSTER_NAME' => $row['topic_last_poster_name'], | |
'LAST_POSTER_COLOUR' => $row['topic_last_poster_colour'], | |
'LAST_POSTER_ID' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $row['topic_last_poster_id']), | |
'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), | |
'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']) | |
)); | |
} | |
} | |
$this->db->sql_freeresult($result); | |
return 'recent_side.html'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function get_template_acp($module_id) | |
{ | |
return array( | |
'title' => 'ACP_PORTAL_RECENT_SETTINGS', | |
'vars' => array( | |
'legend1' => 'ACP_PORTAL_RECENT_SETTINGS', | |
'board3_max_topics_' . $module_id => array('lang' => 'PORTAL_MAX_TOPIC', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), | |
'board3_recent_title_limit_' . $module_id => array('lang' => 'PORTAL_RECENT_TITLE_LIMIT', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), | |
'board3_recent_forum_' . $module_id => array('lang' => 'PORTAL_RECENT_FORUM', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')), | |
'board3_recent_exclude_forums_' . $module_id => array('lang' => 'PORTAL_EXCLUDE_FORUM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), | |
) | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function install($module_id) | |
{ | |
$this->config->set('board3_max_topics_' . $module_id, 10); | |
$this->config->set('board3_recent_title_limit_' . $module_id, 100); | |
$this->config->set('board3_recent_forum_' . $module_id, ''); | |
$this->config->set('board3_recent_exclude_forums_' . $module_id, 1); | |
return true; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function uninstall($module_id, $db) | |
{ | |
$del_config = array( | |
'board3_max_topics_' . $module_id, | |
'board3_recent_title_limit_' . $module_id, | |
'board3_recent_forum_' . $module_id, | |
'board3_recent_exclude_forums_' . $module_id, | |
); | |
$sql = 'DELETE FROM ' . CONFIG_TABLE . ' | |
WHERE ' . $db->sql_in_set('config_name', $del_config); | |
return $db->sql_query($sql); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- IF .latest_announcements or .latest_hot_topics or .latest_topics --> | |
{$C_BLOCK_H_L}{$TITLE}{$C_BLOCK_H_R} | |
<ul class="topiclist forums collapse in" cellspacing="1" width="100%"> | |
<!--li> | |
<!-- IF .latest_announcements --><ul class="row1"><sliong>{L_PORTAL_RECENT_ANN}</sliong></ul><!-- ENDIF --> | |
<!-- IF .latest_hot_topics --><ul class="row1"><sliong>{L_PORTAL_RECENT_HOT_TOPIC}</sliong></ul><!-- ENDIF --> | |
<!-- IF .latest_topics --><ul class="row1"><sliong>{L_PORTAL_RECENT_TOPIC}</sliong></ul><!-- ENDIF --> | |
</li--> | |
<li> | |
<!-- IF .latest_announcements --> | |
<ul class="row1" width="33%" valign="top"> | |
<!-- BEGIN latest_announcements --> | |
<li><a href="{latest_announcements.U_VIEW_TOPIC}" title="{latest_announcements.FULL_TITLE}">{latest_announcements.TITLE}</a></li> | |
<li>{L_POST_BY_AUTHOR}{L_COLON} {latest_topics.LAST_POSTER} » {latest_topics.TIME}</li> | |
<!-- END latest_announcements --> | |
</ul> | |
<!-- ENDIF --> | |
<!-- IF .latest_hot_topics --> | |
<ul class="row1" width="33%" valign="top"> | |
<!-- BEGIN latest_hot_topics --> | |
<li><a href="{latest_hot_topics.U_VIEW_TOPIC}" title="{latest_hot_topics.FULL_TITLE}">{latest_hot_topics.TITLE}</a></li> | |
<li>{L_POST_BY_AUTHOR}{L_COLON} {latest_topics.LAST_POSTER} » {latest_topics.TIME}</li> | |
<!-- END latest_hot_topics --> | |
</ul> | |
<!-- ENDIF --> | |
<!-- IF .latest_topics --> | |
<ul class="row1" width="33%" valign="top"> | |
<!-- BEGIN latest_topics --> | |
<li><a href="{latest_topics.U_VIEW_TOPIC}" title="{latest_topics.FULL_TITLE}">{latest_topics.TITLE}</a><br /></li> | |
<li>{L_POST_BY_AUTHOR}{L_COLON} <a href="{latest_topics.LAST_POSTER_ID}" style="color: #{latest_topics.LAST_POSTER_COLOUR};" class="username-coloured">{latest_topics.LAST_POSTER_NAME}</a> » {latest_topics.LAST_POST_TIME}</li> | |
<!-- END latest_topics --> | |
</ul> | |
<!-- ENDIF --> | |
</li> | |
</ul> | |
{$C_BLOCK_F_L}{$C_BLOCK_F_R} | |
<!-- ENDIF --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment