<?php
/**
*
* @package BBcode Page Extension for the phpBB Forum Software package.
* @copyright (c) 2017 - 2025 Kirk https://kirk-phpbb.com
* @copyright (c) 2008 - 2012 Stoker http://www.phpbb3bbcodes.com
* @copyright (c) 2007 nedka (Nguyen Dang Khoa)
* @license GNU General Public License, version 2 (GPL-2.0-only)
*
*/
namespace kirk\bbcodepage\controller;
/**
* @ignore
*/
class bbcodepage_main
{
protected $auth;
protected $config;
protected $language;
protected $helper;
protected $request;
protected $template;
protected $db;
protected $phpbb_root_path;
protected $php_ext;
public function __construct(
\phpbb\auth\auth $auth,
\phpbb\config\config $config,
\phpbb\language\language $language,
\phpbb\request\request_interface $request,
\phpbb\template\template $template,
\phpbb\controller\helper $helper,
\phpbb\db\driver\driver_interface $db,
$pagination,
$phpbb_root_path,
$php_ext
)
{
$this->auth = $auth;
$this->config = $config;
$this->language = $language;
$this->request = $request;
$this->template = $template;
$this->helper = $helper;
$this->db = $db;
$this->pagination = $pagination;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
// Variables for BBCode Page
$this->bbcodes_per_page = !empty($this->config['bbcodes_per_page']) ?
$this->config['bbcodes_per_page'] : $this->config['posts_per_page'];
$this->pagination_url = $helper->route('kirk_bbcodepage');
}
/**
* Controller for route app.php/bbcodepage and /bbcodepage
*
* @return Symfony\Component\HttpFoundation\Response A Symfony Response object
*/
public function base()
{
$this->language->add_lang('bbcodepage', 'kirk/bbcodepage');
// Can this user or Group view the BBCode page?
$bbcp_redirect_index_page = !$this->auth->acl_gets('u_view_bbcodepage')
|| !$this->config['allow_bbcode']
|| !$this->config['bbcodepage_activated']
|| $this->config['bbcodepage_adminmode']
&& !$this->auth->acl_get('a_');
if ($bbcp_redirect_index_page)
{
redirect(append_sid($this->phpbb_root_path . 'index.' . $this->php_ext));
}
// How many bbcodes do we have?
// Change "WHERE display_on_posting" to "WHERE bbcode_helpline" if you want to display the BBCodes only with help line.
// Delete "WHERE display_on_posting != '' " or "WHERE bbcode_helpline != '' " if you want to display all BBCodes.
$sql = 'SELECT COUNT(bbcode_helpline) AS total_bbcodes
FROM ' . BBCODES_TABLE . "
WHERE display_on_posting != ''
ORDER BY bbcode_tag ASC";
$result = $this->db->sql_query($sql);
$total_bbcodes = (int) $this->db->sql_fetchfield('total_bbcodes');
$this->db->sql_freeresult($result);
$start = $this->request->variable('start', 0);
// Grab BBCode tags details for display
// Change "WHERE display_on_posting" to "WHERE bbcode_helpline" if you want to display the BBCodes only with help line.
// Delete "WHERE display_on_posting != '' " or "WHERE bbcode_helpline != '' " if you want to display all BBCodes.
$sql = 'SELECT bbcode_tag, bbcode_helpline, display_on_posting, bbcode_match, bbcode_tpl
FROM ' . BBCODES_TABLE . "
WHERE display_on_posting != ''
ORDER BY bbcode_tag ASC";
$result = $this->db->sql_query_limit($sql, $this->bbcodes_per_page, $start);
while ($bbcodes_rowset = $this->db->sql_fetchrow($result))
{
// If the helpline is defined within the language file, we will use the localised version, else just use the database entry.
$bbcodes_rowset['bbcode_helpline'] = $this->language->lang($bbcodes_rowset['bbcode_helpline']);
$this->template->assign_block_vars('bbcodes', [
'BBCP_BBCODE_NAME' => $bbcodes_rowset['bbcode_tag'],
'BBCP_BBCODE_HELPLINE' => $bbcodes_rowset['bbcode_helpline'],
'BBCP_BBCODE_DISPLAY' => $bbcodes_rowset['display_on_posting'],
'BBCP_BBCODE_USAGE' => $bbcodes_rowset['bbcode_match'],
'BBCP_BBCODE_TPL' => $bbcodes_rowset['bbcode_tpl']
]);
}
$this->db->sql_freeresult($result);
$bbcodes = $this->language->lang('BBCP_BBCODES_COUNT', $total_bbcodes);
$this->pagination->generate_template_pagination = $this->helper->route('kirk_bbcodepage');
$this->template->assign_vars([
'PAGINATION' => $this->pagination->generate_template_pagination($this->pagination_url, 'pagination', 'start', $total_bbcodes, $this->bbcodes_per_page, $start),
'PAGE_NUMBER' => $this->pagination->on_page($total_bbcodes, $this->bbcodes_per_page, $start),
'TOTAL_BBCODES' => $bbcodes
]);
// Adding links to the breadcrumbs
$this->template->assign_block_vars('navlinks', [
'FORUM_NAME' => $this->language->lang('BBCP'),
'U_VIEW_FORUM' => append_sid('bbcodepage')
]);
return $this->helper->render('bbcodepage.html', $this->language->lang('BBCP'));
}
public function redirect()
{
redirect($this->helper->route('kirk_bbcodepage'));
}
}