diff --git a/acp/portal_module.php b/acp/portal_module.php index 28e60880..45ef2370 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -418,8 +418,6 @@ class portal_module if ($add_column) { $submit = (isset($_POST['submit'])) ? true : false; - $directory = $this->root_path . 'portal/modules/'; - if ($submit) { $module_classname = request_var('module_classname', ''); @@ -460,18 +458,7 @@ class portal_module } else { - $class = 'portal_' . $module_classname . '_module'; - - if (!class_exists($class)) - { - include($directory . 'portal_' . $module_classname . '.' . $this->php_ex); - } - if (!class_exists($class)) - { - trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); - } - - $this->c_class = new $class(); + continue; } $sql = 'SELECT module_order @@ -486,8 +473,8 @@ class portal_module 'module_classname' => $module_classname, 'module_column' => $add_column, 'module_order' => $module_order, - 'module_name' => $this->c_class->name, - 'module_image_src' => $this->c_class->image_src, + 'module_name' => $this->c_class->get_name(), + 'module_image_src' => $this->c_class->get_image(), 'module_group_ids' => '', 'module_image_height' => 16, 'module_image_width' => 16, @@ -529,72 +516,7 @@ class portal_module $this->template->assign_var('S_EDIT', true); $fileinfo = array(); - - // @todo: remove old school way of getting modules - $dh = @opendir($directory); - if (!$dh) - { - return $fileinfo; - } - - while (($file = readdir($dh)) !== false) - { - // Is module? - if (preg_match('/^portal_.+\.' . $this->php_ex . '$/', $file)) - { - $class = str_replace(".{$this->php_ex}", '', $file) . '_module'; - $module_class = str_replace(array('portal_', ".{$this->php_ex}"), '', $file); - $column_string = column_num_string($add_column); - - // do we want to add the module to the side columns or to the center columns? - if ($module_class != 'custom') - { - if (in_array($column_string, array('left', 'right'))) - { - // does the module already exist in the side columns? - if (isset($module_column[$module_class]) && - (in_array('left', $module_column[$module_class]) || in_array('right', $module_column[$module_class]))) - { - continue; - } - } - elseif (in_array($column_string, array('center', 'top', 'bottom'))) - { - // does the module already exist in the center columns? - if (isset($module_column[$module_class]) && - (in_array('center', $module_column[$module_class]) || - in_array('top', $module_column[$module_class]) || - in_array('bottom', $module_column[$module_class]))) - { - continue; - } - } - } - - if (!class_exists($class)) - { - include($directory . $file); - } - - // Get module title tag - if (class_exists($class)) - { - $this->c_class = new $class(); - if ($this->c_class->columns & column_string_const($add_module)) - { - if ($this->c_class->get_language()) - { - $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->get_language()); - } - $fileinfo[] = array( - 'module' => substr($class, 7, -7), - 'name' => $this->user->lang[$this->c_class->get_name()], - ); - } - } - } - } - closedir($dh); + $column_string = column_num_string($add_column); // Find new modules foreach ($this->modules as $module_class => $module) @@ -659,27 +581,13 @@ class portal_module } else { - $directory = $this->root_path . 'portal/modules/'; - $portal_modules = obtain_portal_modules(); foreach($portal_modules as $row) { if (!isset($this->modules[$row['module_classname']])) { - $class = 'portal_' . $row['module_classname'] . '_module'; - if (!class_exists($class)) - { - include($directory . 'portal_' . $row['module_classname'] . '.' . $this->php_ex); - } - if (class_exists($class)) - { - $this->c_class = new $class(); - } - else - { - continue; - } + continue; } else { @@ -1207,25 +1115,19 @@ class portal_module $module_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $directory = $this->root_path . 'portal/modules/'; - if ($module_data !== false) { $module_classname = request_var('module_classname', ''); - $class = 'portal_' . $module_classname . '_module'; - if (!class_exists($class)) - { - include($directory . 'portal_' . $module_classname . '.' . $this->php_ex); - } - if (!class_exists($class)) + + if (!isset($this->modules[$module_classname])) { trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); } - + if (confirm_box(true)) { - $this->c_class = new $class(); - $this->c_class->uninstall($module_data['module_id']); + $this->c_class = $this->modules[$module_classname]; + $this->c_class->uninstall($module_data['module_id'], $this->db); $sql = 'DELETE FROM ' . PORTAL_MODULES_TABLE . ' WHERE module_id = ' . (int) $module_id; @@ -1243,10 +1145,10 @@ class portal_module } else { - $this->c_class = new $class(); - if ($this->c_class->language) + $this->c_class = $this->modules[$module_classname]; + if ($this->c_class->get_language()) { - $this->user->add_lang('mods/portal/' . $this->c_class->language); + $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->get_language()); } $confirm_text = (isset($this->user->lang[$module_data['module_name']])) ? sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], $this->user->lang[$module_data['module_name']]) : sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], utf8_normalize_nfc($module_data['module_name'])); confirm_box(false, $confirm_text, build_hidden_fields(array( diff --git a/adm/style/portal/acp_portal_custom.html b/adm/style/portal/acp_portal_custom.html index 4cc35484..3d7bf66d 100644 --- a/adm/style/portal/acp_portal_custom.html +++ b/adm/style/portal/acp_portal_custom.html @@ -53,20 +53,20 @@ var help_line = { } - function change_palette() - { - dE('colour_palette'); - e = document.getElementById('colour_palette'); +function change_palette() +{ + dE('colour_palette'); + e = document.getElementById('colour_palette'); - if (e.style.display == 'block') - { - document.getElementById('bbpalette').value = '{LA_FONT_COLOR_HIDE}'; - } - else - { - document.getElementById('bbpalette').value = '{LA_FONT_COLOR}'; - } + if (e.style.display == 'block') + { + document.getElementById('bbpalette').value = '{LA_FONT_COLOR_HIDE}'; } + else + { + document.getElementById('bbpalette').value = '{LA_FONT_COLOR}'; + } +} // ]]> diff --git a/adm/style/portal/acp_portal_welcome.html b/adm/style/portal/acp_portal_welcome.html index 0914a16e..166c89f9 100644 --- a/adm/style/portal/acp_portal_welcome.html +++ b/adm/style/portal/acp_portal_welcome.html @@ -1,6 +1,6 @@ - + @@ -134,38 +149,12 @@ var help_line = {
diff --git a/config/modules.yml b/config/modules.yml new file mode 100644 index 00000000..561227e9 --- /dev/null +++ b/config/modules.yml @@ -0,0 +1,292 @@ +services: + board3.module.announcements: + class: \board3\portal\modules\announcements + arguments: + - @auth + - @cache + - @config + - @template + - @dbal.conn + - %core.php_ext% + - %core.root_path% + - @user + tags: + - { name: board3.module } + + board3.module.attachments: + class: \board3\portal\modules\attachments + arguments: + - @auth + - @config + - @template + - @dbal.conn + - %core.php_ext% + - %core.root_path% + - @user + tags: + - { name: board3.module } + + board3.module.birthday_list: + class: \board3\portal\modules\birthday_list + arguments: + - @config + - @template + - @dbal.conn + - @user + tags: + - { name: board3.module } + + board3.module.calendar: + class: \board3\portal\modules\calendar + arguments: + - @config + - @template + - @dbal.conn + - %core.root_path% + - %core.php_ext% + - @user + - @path_helper + tags: + - { name: board3.module } + + board3.module.clock: + class: \board3\portal\modules\clock + tags: + - { name: board3.module } + + board3.module.custom: + class: \board3\portal\modules\custom + arguments: + - @config + - @template + - @dbal.conn + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.donation: + class: \board3\portal\modules\donation + arguments: + - @config + - @template + - @user + tags: + - { name: board3.module } + + board3.module.forumlist: + class: \board3\portal\modules\forumlist + arguments: + - @auth + - @config + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.friends: + class: \board3\portal\modules\friends + arguments: + - @auth + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.latest_bots: + class: \board3\portal\modules\latest_bots + arguments: + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.latest_members: + class: \board3\portal\modules\latest_members + arguments: + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.leaders: + class: \board3\portal\modules\leaders + arguments: + - @auth + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.link_us: + class: \board3\portal\modules\link_us + arguments: + - @config + - @template + - @user + tags: + - { name: board3.module } + + board3.module.links: + class: \board3\portal\modules\links + arguments: + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.main_menu: + class: \board3\portal\modules\main_menu + arguments: + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.news: + class: \board3\portal\modules\news + arguments: + - @auth + - @cache + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.poll: + class: \board3\portal\modules\poll + arguments: + - @auth + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.random_member: + class: \board3\portal\modules\random_member + arguments: + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.recent: + class: \board3\portal\modules\recent + arguments: + - @auth + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + tags: + - { name: board3.module } + + board3.module.search: + class: \board3\portal\modules\search + arguments: + - @template + - %core.php_ext% + - %core.root_path% + tags: + - { name: board3.module } + + board3.module.statistics: + class: \board3\portal\modules\statistics + arguments: + - @cache + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.stylechanger: + class: \board3\portal\modules\stylechanger + arguments: + - @config + - @template + - @dbal.conn + - %core.php_ext% + - %core.root_path% + - @user + tags: + - { name: board3.module } + + board3.module.topposters: + class: \board3\portal\modules\topposters + arguments: + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + tags: + - { name: board3.module } + + board3.module.user_menu: + class: \board3\portal\modules\user_menu + arguments: + - @auth + - @config + - @dbal.conn + - @template + - @user + - %core.root_path% + - %core.php_ext% + tags: + - { name: board3.module } + + board3.module.welcome: + class: \board3\portal\modules\welcome + arguments: + - @config + - @template + - @user + - %core.root_path% + - %core.php_ext% + tags: + - { name: board3.module } + + board3.module.whois_online: + class: \board3\portal\modules\whois_online + arguments: + - @auth + - @dbal.conn + - @template + - @user + - %core.root_path% + - %core.php_ext% + tags: + - { name: board3.module } diff --git a/config/services.yml b/config/services.yml index 1bbaaf91..e1635105 100644 --- a/config/services.yml +++ b/config/services.yml @@ -1,3 +1,6 @@ +imports: + - { resource: modules.yml } + parameters: board3.version_data: author: Marc @@ -10,7 +13,6 @@ parameters: - board3_portal.xml services: - board3.portal.main: class: \board3\portal\controller\main arguments: @@ -39,177 +41,3 @@ services: - @service_container tags: - { name: service_collection, tag: board3.module } - - board3.module.announcements: - class: \board3\portal\modules\announcements - arguments: - - @auth - - @cache - - @config - - @template - - @dbal.conn - - %core.php_ext% - - %core.root_path% - - @user - tags: - - { name: board3.module } - - board3.module.attachments: - class: \board3\portal\modules\attachments - arguments: - - @auth - - @config - - @template - - @dbal.conn - - %core.php_ext% - - %core.root_path% - - @user - tags: - - { name: board3.module } - - board3.module.birthday_list: - class: \board3\portal\modules\birthday_list - arguments: - - @config - - @template - - @dbal.conn - - @user - tags: - - { name: board3.module } - - board3.module.calendar: - class: \board3\portal\modules\calendar - arguments: - - @config - - @template - - @dbal.conn - - %core.root_path% - - %core.php_ext% - - @user - - @path_helper - tags: - - { name: board3.module } - - board3.module.custom: - class: \board3\portal\modules\custom - arguments: - - @config - - @template - - @dbal.conn - - %core.root_path% - - %core.php_ext% - - @user - tags: - - { name: board3.module } - - board3.module.forumlist: - class: \board3\portal\modules\forumlist - arguments: - - @auth - - @config - - @template - - %core.root_path% - - %core.php_ext% - - @user - tags: - - { name: board3.module } - - board3.module.friends: - class: \board3\portal\modules\friends - arguments: - - @auth - - @config - - @dbal.conn - - @template - - @user - tags: - - { name: board3.module } - - board3.module.latest_bots: - class: \board3\portal\modules\latest_bots - arguments: - - @config - - @dbal.conn - - @template - - @user - tags: - - { name: board3.module } - - board3.module.latest_members: - class: \board3\portal\modules\latest_members - arguments: - - @config - - @dbal.conn - - @template - - @user - tags: - - { name: board3.module } - - board3.module.leaders: - class: \board3\portal\modules\leaders - arguments: - - @auth - - @config - - @dbal.conn - - @template - - %core.root_path% - - %core.php_ext% - - @user - tags: - - { name: board3.module } - - board3.module.link_us: - class: \board3\portal\modules\link_us - arguments: - - @config - - @template - - @user - tags: - - { name: board3.module } - - board3.module.links: - class: \board3\portal\modules\links - arguments: - - @config - - @dbal.conn - - @template - - %core.root_path% - - %core.php_ext% - - @user - tags: - - { name: board3.module } - - board3.module.search: - class: \board3\portal\modules\search - arguments: - - @template - - %core.php_ext% - - %core.root_path% - tags: - - { name: board3.module } - - board3.module.stylechanger: - class: \board3\portal\modules\stylechanger - arguments: - - @config - - @template - - @dbal.conn - - %core.php_ext% - - %core.root_path% - - @user - tags: - - { name: board3.module } - - board3.module.clock: - class: \board3\portal\modules\clock - tags: - - { name: board3.module } - - board3.module.donation: - class: \board3\portal\modules\donation - arguments: - - @config - - @template - - @user - tags: - - { name: board3.module } diff --git a/migrations/v210_beta1.php b/migrations/v210_beta1.php index c612ab2c..be52e38a 100644 --- a/migrations/v210_beta1.php +++ b/migrations/v210_beta1.php @@ -303,7 +303,7 @@ class v210_beta1 extends \phpbb\db\migration\migration // Populate module table $board3_sql_query = array( array( - 'module_classname' => 'main_menu', + 'module_classname' => '\board3\portal\modules\main_menu', 'module_column' => 1, 'module_order' => 1, 'module_name' => 'M_MENU', @@ -369,7 +369,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'topposters', + 'module_classname' => '\board3\portal\modules\topposters', 'module_column' => 1, 'module_order' => 7, 'module_name' => 'TOPPOSTERS', @@ -402,7 +402,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'welcome', + 'module_classname' => '\board3\portal\modules\welcome', 'module_column' => 2, 'module_order' => 1, 'module_name' => 'PORTAL_WELCOME', @@ -413,7 +413,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'recent', + 'module_classname' => '\board3\portal\modules\recent', 'module_column' => 2, 'module_order' => 2, 'module_name' => 'PORTAL_RECENT', @@ -435,7 +435,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'news', + 'module_classname' => '\board3\portal\modules\news', 'module_column' => 2, 'module_order' => 4, 'module_name' => 'LATEST_NEWS', @@ -446,7 +446,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'poll', + 'module_classname' => '\board3\portal\modules\poll', 'module_column' => 2, 'module_order' => 5, 'module_name' => 'PORTAL_POLL', @@ -457,7 +457,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'whois_online', + 'module_classname' => '\board3\portal\modules\whois_online', 'module_column' => 2, 'module_order' => 6, 'module_name' => 'PORTAL_WHOIS_ONLINE', @@ -468,7 +468,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'user_menu', + 'module_classname' => '\board3\portal\modules\user_menu', 'module_column' => 3, 'module_order' => 1, 'module_name' => 'USER_MENU', @@ -479,7 +479,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'statistics', + 'module_classname' => '\board3\portal\modules\statistics', 'module_column' => 3, 'module_order' => 2, 'module_name' => 'STATISTICS', diff --git a/portal/modules/portal_main_menu.php b/modules/main_menu.php similarity index 71% rename from portal/modules/portal_main_menu.php rename to modules/main_menu.php index 6b514fc7..59cd954d 100644 --- a/portal/modules/portal_main_menu.php +++ b/modules/main_menu.php @@ -1,24 +1,18 @@ config = $config; + $this->db = $db; + $this->template = $template; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $phpEx; + $this->user = $user; + } + + /** + * @inheritdoc + */ public function get_template_side($module_id) { - global $config, $template, $phpEx, $phpbb_root_path, $user, $db; - $links = array(); $portal_config = obtain_portal_config(); @@ -76,8 +109,8 @@ class portal_main_menu_module extends \board3\portal\modules\module_base { if($links[$i]['type'] == self::LINK_CAT) { - $template->assign_block_vars('portalmenu', array( - 'CAT_TITLE' => (isset($user->lang[$links[$i]['title']])) ? $user->lang[$links[$i]['title']] : $links[$i]['title'], + $this->template->assign_block_vars('portalmenu', array( + 'CAT_TITLE' => (isset($this->user->lang[$links[$i]['title']])) ? $this->user->lang[$links[$i]['title']] : $links[$i]['title'], 'MODULE_ID' => $module_id, )); } @@ -86,7 +119,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base if($links[$i]['type'] == self::LINK_INT) { $links[$i]['url'] = str_replace('&', '&', $links[$i]['url']); // we need to do this in order to prevent XHTML validation errors - $cur_url = append_sid($phpbb_root_path . $links[$i]['url']); // the user should know what kind of file it is + $cur_url = append_sid($this->phpbb_root_path . $links[$i]['url']); // the user should know what kind of file it is } else { @@ -98,10 +131,10 @@ class portal_main_menu_module extends \board3\portal\modules\module_base if(!empty($permission_check) || $links[$i]['permission'] == '') { - $template->assign_block_vars('portalmenu.links', array( - 'LINK_TITLE' => (isset($user->lang[$links[$i]['title']])) ? $user->lang[$links[$i]['title']] : $links[$i]['title'], + $this->template->assign_block_vars('portalmenu.links', array( + 'LINK_TITLE' => (isset($this->user->lang[$links[$i]['title']])) ? $this->user->lang[$links[$i]['title']] : $links[$i]['title'], 'LINK_URL' => $cur_url, - 'NEW_WINDOW' => ($links[$i]['type'] != self::LINK_INT && $config['board3_menu_url_new_window_' . $module_id]) ? true : false, + 'NEW_WINDOW' => ($links[$i]['type'] != self::LINK_INT && $this->config['board3_menu_url_new_window_' . $module_id]) ? true : false, )); } } @@ -110,9 +143,11 @@ class portal_main_menu_module extends \board3\portal\modules\module_base return 'main_menu_side.html'; } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { - // do not remove this as it is needed in order to run manage_links return array( 'title' => 'ACP_PORTAL_MENU', 'vars' => array( @@ -124,18 +159,16 @@ class portal_main_menu_module extends \board3\portal\modules\module_base } /** - * API functions + * @inheritdoc */ public function install($module_id) { - global $phpbb_root_path, $phpEx, $db; - // get the correct group IDs from the database $in_ary = array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA'); - $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' WHERE ' . $db->sql_in_set('group_name', $in_ary); - $result = $db->sql_query($sql); - while($row = $db->sql_fetchrow($result)) + $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' WHERE ' . $this->db->sql_in_set('group_name', $in_ary); + $result = $this->db->sql_query($sql); + while($row = $this->db->sql_fetchrow($result)) { $groups_ary[$row['group_name']] = $row['group_id']; } @@ -172,16 +205,16 @@ class portal_main_menu_module extends \board3\portal\modules\module_base $links_urls = array( '', - 'index.' . $phpEx, - 'search.' . $phpEx, - 'ucp.' . $phpEx . '?mode=register', - 'memberlist.' . $phpEx, - 'memberlist.' . $phpEx . '?mode=leaders', + 'index.' . $this->php_ext, + 'search.' . $this->php_ext, + 'ucp.' . $this->php_ext . '?mode=register', + 'memberlist.' . $this->php_ext, + 'memberlist.' . $this->php_ext . '?mode=leaders', '', - 'faq.' . $phpEx, - 'faq.' . $phpEx . '?mode=bbcode', - 'ucp.' . $phpEx . '?mode=terms', - 'ucp.' . $phpEx . '?mode=privacy', + 'faq.' . $this->php_ext, + 'faq.' . $this->php_ext . '?mode=bbcode', + 'ucp.' . $this->php_ext . '?mode=terms', + 'ucp.' . $this->php_ext . '?mode=privacy', ); $links_permissions = array( @@ -216,6 +249,9 @@ class portal_main_menu_module extends \board3\portal\modules\module_base return true; } + /** + * @inheritdoc + */ public function uninstall($module_id, $db) { $del_config = array( @@ -235,11 +271,17 @@ class portal_main_menu_module extends \board3\portal\modules\module_base return $db->sql_query($sql); } - // Manage the menu links + /** + * Manage the menu links + * + * @param mixed $value Value of input + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ public function manage_links($value, $key, $module_id) { - global $config, $phpbb_admin_path, $user, $phpEx, $db, $template; - $action = request_var('action', ''); $action = (isset($_POST['add'])) ? 'add' : $action; $action = (isset($_POST['save'])) ? 'save' : $action; @@ -250,7 +292,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base $links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]); - $u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&mode=config&module_id=' . $module_id); + $u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\modules\portal&mode=config&module_id=' . $module_id); switch ($action) { @@ -258,7 +300,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base case 'save': if (!check_form_key('acp_portal')) { - trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING); } $link_title = utf8_normalize_nfc(request_var('link_title', ' ', true)); @@ -273,12 +315,12 @@ class portal_main_menu_module extends \board3\portal\modules\module_base $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' ORDER BY group_id ASC'; - $result = $db->sql_query($sql); - while($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while($row = $this->db->sql_fetchrow($result)) { $groups_ary[] = $row['group_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $link_permissions = array_intersect($link_permission, $groups_ary); $link_permissions = implode(',', $link_permissions); @@ -286,18 +328,18 @@ class portal_main_menu_module extends \board3\portal\modules\module_base // Check for errors if (!$link_title) { - trigger_error($user->lang['NO_LINK_TITLE'] . adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_LINK_TITLE'] . adm_back_link($u_action), E_USER_WARNING); } if (!$link_is_cat && !$link_url) { - trigger_error($user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING); } // overwrite already existing links and make sure we don't try to save a link outside of the normal array size of $links if (isset($link_id) && $link_id < sizeof($links)) { - $message = $user->lang['LINK_UPDATED']; + $message = $this->user->lang['LINK_UPDATED']; $links[$link_id] = array( 'title' => $link_title, @@ -310,11 +352,11 @@ class portal_main_menu_module extends \board3\portal\modules\module_base } else { - $message = $user->lang['LINK_ADDED']; + $message = $this->user->lang['LINK_ADDED']; if($link_type != self::LINK_CAT && sizeof($links) < 1) { - trigger_error($user->lang['ACP_PORTAL_MENU_CREATE_CAT'] . adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang['ACP_PORTAL_MENU_CREATE_CAT'] . adm_back_link($u_action), E_USER_WARNING); } $links[] = array( 'title' => $link_title, @@ -337,7 +379,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base if (!isset($link_id) && $link_id >= sizeof($links)) { - trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING); } if (confirm_box(true)) @@ -354,7 +396,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base } else { - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + confirm_box(false, $this->user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( 'link_id' => $link_id, 'action' => 'delete', ))); @@ -368,7 +410,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base if (!isset($link_id) && $link_id >= sizeof($links)) { - trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING); } // make sure we don't try to move a link where it can't be moved @@ -411,7 +453,7 @@ class portal_main_menu_module extends \board3\portal\modules\module_base // Edit or add menu item case 'edit': case 'add': - $template->assign_vars(array( + $this->template->assign_vars(array( 'LINK_TITLE' => (isset($links[$link_id]['title']) && $action != 'add') ? $links[$link_id]['title'] : '', 'LINK_URL' => (isset($links[$link_id]['url']) && $links[$link_id]['type'] != self::LINK_CAT && $action != 'add') ? str_replace('&', '&', $links[$link_id]['url']) : '', @@ -429,16 +471,16 @@ class portal_main_menu_module extends \board3\portal\modules\module_base $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' ORDER BY group_id ASC'; - $result = $db->sql_query($sql); - while($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while($row = $this->db->sql_fetchrow($result)) { - $template->assign_block_vars('permission_setting_menu', array( + $this->template->assign_block_vars('permission_setting_menu', array( 'SELECTED' => (in_array($row['group_id'], $groups_ary)) ? true : false, - 'GROUP_NAME' => (isset($user->lang['G_' . $row['group_name']])) ? $user->lang['G_' . $row['group_name']] : $row['group_name'], + 'GROUP_NAME' => (isset($this->user->lang['G_' . $row['group_name']])) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_ID' => $row['group_id'], )); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return; @@ -447,8 +489,8 @@ class portal_main_menu_module extends \board3\portal\modules\module_base for ($i = 0; $i < sizeof($links); $i++) { - $template->assign_block_vars('links', array( - 'LINK_TITLE' => ($action != 'add') ? ((isset($user->lang[$links[$i]['title']])) ? $user->lang[$links[$i]['title']] : $links[$i]['title']) : '', + $this->template->assign_block_vars('links', array( + 'LINK_TITLE' => ($action != 'add') ? ((isset($this->user->lang[$links[$i]['title']])) ? $this->user->lang[$links[$i]['title']] : $links[$i]['title']) : '', 'LINK_URL' => ($action != 'add') ? str_replace('&', '&', $links[$i]['url']) : '', 'U_EDIT' => $u_action . '&action=edit&id=' . $i, @@ -461,12 +503,26 @@ class portal_main_menu_module extends \board3\portal\modules\module_base } } + /** + * Update links + * + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ public function update_links($key, $module_id) { $this->manage_links('', $key, $module_id); } - // Unserialize links array + /** + * Unserialize links array + * + * @param string $serial_str Serialized string + * + * @return string Unserialized string + */ private function utf_unserialize($serial_str) { $out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str ); diff --git a/portal/modules/portal_news.php b/modules/news.php similarity index 54% rename from portal/modules/portal_news.php rename to modules/news.php index d8cd194b..7ea1ccb0 100644 --- a/portal/modules/portal_news.php +++ b/modules/news.php @@ -1,24 +1,18 @@ auth = $auth; + $this->cache = $cache; + $this->config = $config; + $this->db = $db; + $this->template = $template; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $phpEx; + $this->user = $user; + } + + /** + * @inheritdoc + */ public function get_template_center($module_id) { - global $config, $template, $db, $user, $auth, $cache, $phpEx, $phpbb_root_path; - $news = request_var('news', -1); - $news = ($news > $config['board3_number_of_news_' . $module_id] -1) ? -1 : $news; - $user->add_lang('viewforum'); + $news = ($news > $this->config['board3_number_of_news_' . $module_id] -1) ? -1 : $news; + $this->user->add_lang('viewforum'); $start = request_var('np', 0); $start = ($start < 0) ? 0 : $start; // Fetch news from portal/includes/functions.php with check if "read full" is requested. - $portal_news_length = ($news < 0) ? $config['board3_news_length_' . $module_id] : 0; - $fetch_news = phpbb_fetch_posts($module_id, $config['board3_news_forum_' . $module_id], $config['board3_news_permissions_' . $module_id], $config['board3_number_of_news_' . $module_id], $portal_news_length, 0, ($config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $start, $config['board3_news_exclude_' . $module_id]); + $portal_news_length = ($news < 0) ? $this->config['board3_news_length_' . $module_id] : 0; + $fetch_news = phpbb_fetch_posts($module_id, $this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $start, $this->config['board3_news_exclude_' . $module_id]); // Any news present? If not terminate it here. if (sizeof($fetch_news) == 0) { - $template->assign_block_vars('news_row', array( + $this->template->assign_block_vars('news_row', array( 'S_NO_TOPICS' => true, 'S_NOT_LAST' => false, )); @@ -73,10 +116,10 @@ class portal_news_module extends \board3\portal\modules\module_base else { // Count number of posts for news archive, considering if permission check is dis- or enabled. - if ($config['board3_news_archive_' . $module_id]) + if ($this->config['board3_news_archive_' . $module_id]) { - $permissions = $config['board3_news_permissions_' . $module_id]; - $forum_from = $config['board3_news_forum_' . $module_id]; + $permissions = $this->config['board3_news_permissions_' . $module_id]; + $forum_from = $this->config['board3_news_forum_' . $module_id]; $forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); @@ -84,14 +127,14 @@ class portal_news_module extends \board3\portal\modules\module_base if($permissions == true) { - $disallow_access = array_unique(array_keys($auth->acl_getf('!f_read', true))); + $disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true))); } else { $disallow_access = array(); } - if($config['board3_news_exclude_' . $module_id] == true) + if($this->config['board3_news_exclude_' . $module_id] == true) { $disallow_access = array_merge($disallow_access, $forum_from); $forum_from = array(); @@ -122,7 +165,7 @@ class portal_news_module extends \board3\portal\modules\module_base $str_where = (strlen($str_where) > 0) ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : ''; - $topic_type = ($config['board3_show_all_news_' . $module_id]) ? '(topic_type <> ' . POST_ANNOUNCE . ') AND (topic_type <> ' . POST_GLOBAL . ')' : 'topic_type = ' . POST_NORMAL; + $topic_type = ($this->config['board3_show_all_news_' . $module_id]) ? '(topic_type <> ' . POST_ANNOUNCE . ') AND (topic_type <> ' . POST_GLOBAL . ')' : 'topic_type = ' . POST_NORMAL; $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . ' @@ -130,9 +173,9 @@ class portal_news_module extends \board3\portal\modules\module_base AND topic_visibility = ' . ITEM_APPROVED . ' AND topic_moved_id = 0 ' . $str_where; - $result = $db->sql_query($sql); - $total_news = (int) $db->sql_fetchfield('num_topics'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_news = (int) $this->db->sql_fetchfield('num_topics'); + $this->db->sql_freeresult($result); } $topic_tracking_info = get_portal_tracking_info($fetch_news); @@ -147,7 +190,7 @@ class portal_news_module extends \board3\portal\modules\module_base { $open_bracket = '[ '; $close_bracket = ' ]'; - $read_full = $user->lang['READ_FULL']; + $read_full = $this->user->lang['READ_FULL']; } else { @@ -161,13 +204,13 @@ class portal_news_module extends \board3\portal\modules\module_base $unread_topic = (isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; $read_full_url = (isset($_GET['np'])) ? 'np='. $start . '&news=' . $i . '#n' . $i : 'news=' . $i . '#n' . $i; - $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); - if ($config['board3_news_archive_' . $module_id]) + $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) . '&t=' . $topic_id); + if ($this->config['board3_news_archive_' . $module_id]) { - $pagination = generate_portal_pagination(append_sid("{$phpbb_root_path}portal.$phpEx"), $total_news, $config['board3_number_of_news_' . $module_id], $start, ($config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news'); + $pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news'); } - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies']; + $replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies']; $folder_img = $folder_alt = $topic_type = $folder = $folder_new = ''; switch ($fetch_news[$i]['topic_type']) { @@ -182,7 +225,7 @@ class portal_news_module extends \board3\portal\modules\module_base default: $folder = 'topic_read'; $folder_new = 'topic_unread'; - if ($config['hot_threshold'] && $replies >= $config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) + if ($this->config['hot_threshold'] && $replies >= $this->config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) { $folder .= '_hot'; $folder_new .= '_hot'; @@ -205,38 +248,38 @@ class portal_news_module extends \board3\portal\modules\module_base $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($fetch_news[$i]['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Grab icons - $icons = $cache->obtain_icons(); + $icons = $this->cache->obtain_icons(); - phpbb_generate_template_pagination($template, $view_topic_url, 'pagination', 'np', $fetch_news[$i]['topic_replies'], $config['board3_number_of_news_' . $module_id], $start); + phpbb_generate_template_pagination($this->template, $view_topic_url, 'pagination', 'np', $fetch_news[$i]['topic_replies'], $this->config['board3_number_of_news_' . $module_id], $start); - $template->assign_block_vars('news_row', array( - 'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $config['allow_attachments']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', + $this->template->assign_block_vars('news_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'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'USERNAME_FULL_LAST' => $fetch_news[$i]['username_full_last'], - 'U_USER_PROFILE' => (($fetch_news[$i]['user_type'] == USER_NORMAL || $fetch_news[$i]['user_type'] == USER_FOUNDER) && $fetch_news[$i]['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $fetch_news[$i]['user_id']) : '', + 'U_USER_PROFILE' => (($fetch_news[$i]['user_type'] == USER_NORMAL || $fetch_news[$i]['user_type'] == USER_FOUNDER) && $fetch_news[$i]['user_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $fetch_news[$i]['user_id']) : '', 'TIME' => $fetch_news[$i]['topic_time'], - 'LAST_POST_TIME' => $user->format_date($fetch_news[$i]['topic_last_post_time']), + 'LAST_POST_TIME' => $this->user->format_date($fetch_news[$i]['topic_last_post_time']), 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, - 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), + 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_IMG_STYLE' => $folder_img, - 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), - 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], + 'TOPIC_FOLDER_IMG_SRC' => $this->user->img($folder_img, $folder_alt, false, '', 'src'), + 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => (!empty($icons[$fetch_news[$i]['icon_id']])) ? $icons[$fetch_news[$i]['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$fetch_news[$i]['icon_id']])) ? $icons[$fetch_news[$i]['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$fetch_news[$i]['icon_id']])) ? $icons[$fetch_news[$i]['icon_id']]['height'] : '', - 'FOLDER_IMG' => $user->img('topic_read', 'NO_NEW_POSTS'), - 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $fetch_news[$i]['forum_id']), - 'U_LAST_COMMENTS' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), - 'U_VIEW_COMMENTS' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), - 'U_VIEW_UNREAD' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&view=unread#unread'), - 'U_POST_COMMENT' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), - 'U_READ_FULL' => append_sid("{$phpbb_root_path}portal.$phpEx", $read_full_url), + 'FOLDER_IMG' => $this->user->img('topic_read', 'NO_NEW_POSTS'), + 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), + 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), + 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), + 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&view=unread#unread'), + 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), + 'U_READ_FULL' => append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", $read_full_url), 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, @@ -250,18 +293,18 @@ class portal_news_module extends \board3\portal\modules\module_base { foreach ($fetch_news[$i]['attachments'] as $attachment) { - $template->assign_block_vars('news_row.attachment', array( + $this->template->assign_block_vars('news_row.attachment', array( 'DISPLAY_ATTACHMENT' => $attachment) ); } } - if ($config['board3_number_of_news_' . $module_id] <> 0 && $config['board3_news_archive_' . $module_id]) + if ($this->config['board3_number_of_news_' . $module_id] <> 0 && $this->config['board3_news_archive_' . $module_id]) { - $template->assign_vars(array( + $this->template->assign_vars(array( 'NP_PAGINATION' => $pagination, - 'TOTAL_NEWS' => ($total_news == 1) ? sprintf($user->lang['VIEW_FORUM_TOPICS'][1], $total_news) : sprintf($user->lang['VIEW_FORUM_TOPICS'][2], $total_news), - 'NP_PAGE_NUMBER' => phpbb_on_page($template, $user, $view_topic_url, $total_news, $config['board3_number_of_news_' . $module_id], $start)) + 'TOTAL_NEWS' => ($total_news == 1) ? sprintf($this->user->lang['VIEW_FORUM_TOPICS'][1], $total_news) : sprintf($this->user->lang['VIEW_FORUM_TOPICS'][2], $total_news), + 'NP_PAGE_NUMBER' => phpbb_on_page($this->template, $this->user, $view_topic_url, $total_news, $this->config['board3_number_of_news_' . $module_id], $start)) ); } } @@ -275,17 +318,17 @@ class portal_news_module extends \board3\portal\modules\module_base $unread_topic = (isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; $open_bracket = '[ '; $close_bracket = ' ]'; - $read_full = $user->lang['BACK']; + $read_full = $this->user->lang['BACK']; - $read_full_url = (isset($_GET['np'])) ? append_sid("{$phpbb_root_path}portal.$phpEx", "np=$start#n$i") : append_sid("{$phpbb_root_path}portal.$phpEx#n$i"); - $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); - if ($config['board3_news_archive_' . $module_id]) + $read_full_url = (isset($_GET['np'])) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "np=$start#n$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#n$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) . '&t=' . $topic_id); + if ($this->config['board3_news_archive_' . $module_id]) { - $pagination = generate_portal_pagination(append_sid("{$phpbb_root_path}portal.$phpEx"), $total_news, $config['board3_number_of_news_' . $module_id], $start, ($config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news'); + $pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news'); } - $template->assign_block_vars('news_row', array( - 'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $config['allow_attachments']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', + $this->template->assign_block_vars('news_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'], 'POSTER' => $fetch_news[$i]['username'], @@ -295,36 +338,37 @@ class portal_news_module extends \board3\portal\modules\module_base 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, - 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $fetch_news[$i]['forum_id']), - 'U_LAST_COMMENTS' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), - 'U_VIEW_COMMENTS' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), - 'U_POST_COMMENT' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), + 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), + 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), + 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), + 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'U_READ_FULL' => $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, - 'PAGINATION' => topic_generate_pagination($fetch_news[$i]['topic_replies'], $view_topic_url), 'S_HAS_ATTACHMENTS' => (!empty($fetch_news[$i]['attachments'])) ? true : false, )); + phpbb_generate_template_pagination($this->template, $view_topic_url, 'news_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) { - $template->assign_block_vars('news_row.attachment', array( + $this->template->assign_block_vars('news_row.attachment', array( 'DISPLAY_ATTACHMENT' => $attachment) ); } } - if ($config['board3_number_of_news_' . $module_id] <> 0 && $config['board3_news_archive_' . $module_id]) + if ($this->config['board3_number_of_news_' . $module_id] <> 0 && $this->config['board3_news_archive_' . $module_id]) { - $template->assign_vars(array( + $this->template->assign_vars(array( 'NP_PAGINATION' => $pagination, - 'TOTAL_NEWS' => ($total_news == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $total_news), - 'NP_PAGE_NUMBER' => on_page($total_news, $config['board3_number_of_news_' . $module_id], $start)) + 'TOTAL_NEWS' => ($total_news == 1) ? $this->user->lang['VIEW_FORUM_TOPIC'] : $this->user->lang('VIEW_FORUM_TOPICS', $total_news), + 'NP_PAGE_NUMBER' => phpbb_on_page($this->template, $this->user, '', $total_news, $this->config['board3_number_of_news_' . $module_id], $start)) ); } } @@ -336,17 +380,17 @@ class portal_news_module extends \board3\portal\modules\module_base $topic_icons = true; } - $template->assign_vars(array( - 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), - 'READ_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), - 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'), - 'S_NEWEST_OR_FIRST' => ($config['board3_news_show_last_' . $module_id]) ? $user->lang['JUMP_NEWEST'] : $user->lang['JUMP_FIRST'], - 'POSTED_BY_TEXT' => ($config['board3_news_show_last_' . $module_id]) ? $user->lang['LAST_POST'] : $user->lang['POSTED'], - 'S_DISPLAY_NEWS_RVS' => ($config['board3_show_news_replies_views_' . $module_id]) ? true : false, + $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_NEWEST_OR_FIRST' => ($this->config['board3_news_show_last_' . $module_id]) ? $this->user->lang['JUMP_NEWEST'] : $this->user->lang['JUMP_FIRST'], + 'POSTED_BY_TEXT' => ($this->config['board3_news_show_last_' . $module_id]) ? $this->user->lang['LAST_POST'] : $this->user->lang['POSTED'], + 'S_DISPLAY_NEWS_RVS' => ($this->config['board3_show_news_replies_views_' . $module_id]) ? true : false, 'S_TOPIC_ICONS' => $topic_icons, )); - if($config['board3_news_style_' . $module_id]) + if($this->config['board3_news_style_' . $module_id]) { return 'news_compact_center.html'; } @@ -356,6 +400,9 @@ class portal_news_module extends \board3\portal\modules\module_base } } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { return array( @@ -377,7 +424,7 @@ class portal_news_module extends \board3\portal\modules\module_base } /** - * API functions + * @inheritdoc */ public function install($module_id) { @@ -394,6 +441,9 @@ class portal_news_module extends \board3\portal\modules\module_base return true; } + /** + * @inheritdoc + */ public function uninstall($module_id, $db) { $del_config = array( @@ -413,17 +463,23 @@ class portal_news_module extends \board3\portal\modules\module_base return $db->sql_query($sql); } - // Create forum select box + /** + * Create forum select box + * + * @param mixed $value Value of input + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ public function select_forums($value, $key, $module_id) { - global $user, $config; - $forum_list = make_forum_select(false, false, true, true, true, false, true); $selected = array(); - if(isset($config[$key]) && strlen($config[$key]) > 0) + if(isset($this->config[$key]) && strlen($this->config[$key]) > 0) { - $selected = explode(',', $config[$key]); + $selected = explode(',', $this->config[$key]); } // Build forum options $s_forum_options = ''; @@ -128,11 +183,16 @@ class portal_poll_module extends \board3\portal\modules\module_base return $s_forum_options; } - // Store selected forums + /** + * Store selected forums + * + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ public function store_selected_forums($key, $module_id) { - global $db, $cache; - // Get selected forums $values = request_var($key, array(0 => '')); @@ -147,17 +207,17 @@ class portal_poll_module extends \board3\portal\modules\module_base * * @param int $module_id Module ID * @param string $type Module type (center or side) + * + * @return string HTML filename */ protected function parse_template($module_id, $type = '') { - global $config, $template, $db, $user, $auth, $phpbb_root_path, $phpEx; - - $user->add_lang('viewtopic'); + $this->user->add_lang('viewtopic'); // check if we need to include the bbcode class if(!class_exists('bbcode')) { - include($phpbb_root_path . 'includes/bbcode.' . $phpEx); + include($this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext); } $view = request_var('view', ''); @@ -166,35 +226,35 @@ class portal_poll_module extends \board3\portal\modules\module_base $poll_view_ar = (strpos($poll_view, ',') !== FALSE) ? explode(',', $poll_view) : (($poll_view != '') ? array($poll_view) : array()); - if ($update && $config['board3_poll_allow_vote_' . $module_id]) + if ($update && $this->config['board3_poll_allow_vote_' . $module_id]) { $up_topic_id = request_var('t', 0); $up_forum_id = request_var('f', 0); $voted_id = request_var('vote_id', array('' => 0)); $cur_voted_id = array(); - if ($user->data['is_registered']) + if ($this->user->data['is_registered']) { $sql = 'SELECT poll_option_id FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $up_topic_id . ' - AND vote_user_id = ' . $user->data['user_id']; - $result = $db->sql_query($sql); + AND vote_user_id = ' . $this->user->data['user_id']; + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $cur_voted_id[] = $row['poll_option_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } else { // Cookie based guest tracking ... I don't like this but hum ho // it's oft requested. This relies on "nice" users who don't feel // the need to delete cookies to mess with results. - if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $up_topic_id])) + if (isset($_COOKIE[$this->config['cookie_name'] . '_poll_' . $up_topic_id])) { - $cur_voted_id = explode(',', request_var($config['cookie_name'] . '_poll_' . $up_topic_id, 0, false, true)); + $cur_voted_id = explode(',', request_var($this->config['cookie_name'] . '_poll_' . $up_topic_id, 0, false, true)); $cur_voted_id = array_map('intval', $cur_voted_id); } } @@ -202,19 +262,19 @@ class portal_poll_module extends \board3\portal\modules\module_base $sql = 'SELECT t.poll_length, t.poll_start, t.poll_vote_change, t.topic_status, f.forum_status, t.poll_max_options FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.forum_id = f.forum_id AND t.topic_id = " . (int) $up_topic_id . " AND t.forum_id = " . (int) $up_forum_id; - $result = $db->sql_query_limit($sql, 1); - $topic_data = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, 1); + $topic_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); - $s_can_up_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $up_forum_id)) || - ($auth->acl_get('f_votechg', $up_forum_id) && $topic_data['poll_vote_change'])) && + $s_can_up_vote = (((!sizeof($cur_voted_id) && $this->auth->acl_get('f_vote', $up_forum_id)) || + ($this->auth->acl_get('f_votechg', $up_forum_id) && $topic_data['poll_vote_change'])) && (($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) && $topic_data['topic_status'] != ITEM_LOCKED && $topic_data['forum_status'] != ITEM_LOCKED) ? true : false; if($s_can_up_vote) { - $redirect_url = append_sid("{$phpbb_root_path}app.$phpEx/portal"); + $redirect_url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"); if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id)) { @@ -232,7 +292,7 @@ class portal_poll_module extends \board3\portal\modules\module_base $message = 'VOTE_CONVERTED'; } - $message = $user->lang[$message] . '

' . sprintf($user->lang['RETURN_PORTAL'], '', ''); + $message = $this->user->lang[$message] . '

' . sprintf($this->user->lang['RETURN_PORTAL'], '', ''); trigger_error($message); } @@ -247,19 +307,19 @@ class portal_poll_module extends \board3\portal\modules\module_base SET poll_option_total = poll_option_total + 1 WHERE poll_option_id = ' . (int) $option . ' AND topic_id = ' . (int) $up_topic_id; - $db->sql_query($sql); + $this->db->sql_query($sql); - if ($user->data['is_registered']) + if ($this->user->data['is_registered']) { $sql_ary = array( 'topic_id' => (int) $up_topic_id, 'poll_option_id' => (int) $option, - 'vote_user_id' => (int) $user->data['user_id'], - 'vote_user_ip' => (string) $user->ip, + 'vote_user_id' => (int) $this->user->data['user_id'], + 'vote_user_ip' => (string) $this->user->ip, ); - $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); + $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); } } @@ -271,32 +331,32 @@ class portal_poll_module extends \board3\portal\modules\module_base SET poll_option_total = poll_option_total - 1 WHERE poll_option_id = ' . (int) $option . ' AND topic_id = ' . (int) $up_topic_id; - $db->sql_query($sql); + $this->db->sql_query($sql); - if ($user->data['is_registered']) + if ($this->user->data['is_registered']) { $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $up_topic_id . ' AND poll_option_id = ' . (int) $option . ' - AND vote_user_id = ' . (int) $user->data['user_id']; - $db->sql_query($sql); + AND vote_user_id = ' . (int) $this->user->data['user_id']; + $this->db->sql_query($sql); } } } - if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot']) + if ($this->user->data['user_id'] == ANONYMOUS && !$this->user->data['is_bot']) { - $user->set_cookie('poll_' . $up_topic_id, implode(',', $voted_id), time() + 31536000); + $this->user->set_cookie('poll_' . $up_topic_id, implode(',', $voted_id), time() + 31536000); } $sql = 'UPDATE ' . TOPICS_TABLE . ' SET poll_last_vote = ' . time() . " WHERE topic_id = $up_topic_id"; //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now - $db->sql_query($sql); + $this->db->sql_query($sql); meta_refresh(5, $redirect_url); - trigger_error($user->lang['VOTE_SUBMITTED'] . '

' . sprintf($user->lang['RETURN_PORTAL'], '', '')); + trigger_error($this->user->lang['VOTE_SUBMITTED'] . '

' . sprintf($this->user->lang['RETURN_PORTAL'], '', '')); } } @@ -306,13 +366,13 @@ class portal_poll_module extends \board3\portal\modules\module_base // Get readable forums $forum_list = array(); - $forum_list = array_unique(array_keys($auth->acl_getf('f_read', true))); + $forum_list = array_unique(array_keys($this->auth->acl_getf('f_read', true))); - if($config['board3_poll_topic_id_' . $module_id] !== '') + if($this->config['board3_poll_topic_id_' . $module_id] !== '') { - $poll_forums_config = explode(',' ,$config['board3_poll_topic_id_' . $module_id]); + $poll_forums_config = explode(',' ,$this->config['board3_poll_topic_id_' . $module_id]); - if($config['board3_poll_exclude_id_' . $module_id]) + if($this->config['board3_poll_exclude_id_' . $module_id]) { $forum_list = array_unique(array_diff($forum_list, $poll_forums_config)); } @@ -327,10 +387,10 @@ class portal_poll_module extends \board3\portal\modules\module_base if(sizeof($forum_list)) { $poll_forums = true; - $where = 'AND ' . $db->sql_in_set('t.forum_id', $forum_list); + $where = 'AND ' . $this->db->sql_in_set('t.forum_id', $forum_list); } - if ($config['board3_poll_hide_' . $module_id]) + if ($this->config['board3_poll_hide_' . $module_id]) { $portal_poll_hide = "AND (t.poll_start + t.poll_length > ". time() ." OR t.poll_length = 0)"; } @@ -350,13 +410,13 @@ class portal_poll_module extends \board3\portal\modules\module_base AND p.post_id = t.topic_first_post_id {$portal_poll_hide} ORDER BY t.poll_start DESC"; - $limit = (isset($config['board3_poll_limit_' . $module_id])) ? $config['board3_poll_limit_' . $module_id] : 3; - $result = $db->sql_query_limit($sql, $limit); + $limit = (isset($this->config['board3_poll_limit_' . $module_id])) ? $this->config['board3_poll_limit_' . $module_id] : 3; + $result = $this->db->sql_query_limit($sql, $limit); $has_poll = false; if ($result) { - while($data = $db->sql_fetchrow($result)) + while($data = $this->db->sql_fetchrow($result)) { $has_poll = true; $poll_has_options = false; @@ -365,36 +425,36 @@ class portal_poll_module extends \board3\portal\modules\module_base $forum_id = (int) $data['forum_id']; $cur_voted_id = array(); - if($config['board3_poll_allow_vote_' . $module_id]) + if($this->config['board3_poll_allow_vote_' . $module_id]) { - if ($user->data['is_registered']) + if ($this->user->data['is_registered']) { $vote_sql = 'SELECT poll_option_id FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $topic_id . ' - AND vote_user_id = ' . $user->data['user_id']; - $vote_result = $db->sql_query($vote_sql); + AND vote_user_id = ' . $this->user->data['user_id']; + $vote_result = $this->db->sql_query($vote_sql); - while ($row = $db->sql_fetchrow($vote_result)) + while ($row = $this->db->sql_fetchrow($vote_result)) { $cur_voted_id[] = $row['poll_option_id']; } - $db->sql_freeresult($vote_result); + $this->db->sql_freeresult($vote_result); } else { // Cookie based guest tracking ... I don't like this but hum ho // it's oft requested. This relies on "nice" users who don't feel // the need to delete cookies to mess with results. - if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id])) + if (isset($_COOKIE[$this->config['cookie_name'] . '_poll_' . $topic_id])) { - $cur_voted_id = explode(',', request_var($config['cookie_name'] . '_poll_' . $topic_id, 0, false, true)); + $cur_voted_id = explode(',', request_var($this->config['cookie_name'] . '_poll_' . $topic_id, 0, false, true)); $cur_voted_id = array_map('intval', $cur_voted_id); } } - $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) || - ($auth->acl_get('f_votechg', $forum_id) && $data['poll_vote_change'])) && + $s_can_vote = (((!sizeof($cur_voted_id) && $this->auth->acl_get('f_vote', $forum_id)) || + ($this->auth->acl_get('f_votechg', $forum_id) && $data['poll_vote_change'])) && (($data['poll_length'] != 0 && $data['poll_start'] + $data['poll_length'] > time()) || $data['poll_length'] == 0) && $data['topic_status'] != ITEM_LOCKED && $data['forum_status'] != ITEM_LOCKED) ? true : false; @@ -411,20 +471,20 @@ class portal_poll_module extends \board3\portal\modules\module_base WHERE po.topic_id = {$topic_id} ORDER BY po.poll_option_id"; - $poll_result = $db->sql_query($poll_sql); + $poll_result = $this->db->sql_query($poll_sql); $poll_total_votes = 0; $poll_data = array(); if ($poll_result) { - while($polls_data = $db->sql_fetchrow($poll_result)) + while($polls_data = $this->db->sql_fetchrow($poll_result)) { $poll_has_options = true; $poll_data[] = $polls_data; $poll_total_votes += $polls_data['poll_option_total']; } } - $db->sql_freeresult($poll_result); + $this->db->sql_freeresult($poll_result); $make_poll_view = array(); @@ -435,9 +495,9 @@ class portal_poll_module extends \board3\portal\modules\module_base } $poll_view_str = urlencode(implode(',', $make_poll_view)); - $portalpoll_url= append_sid("{$phpbb_root_path}app.$phpEx/portal", "polls=$poll_view_str"); - $portalvote_url= append_sid("{$phpbb_root_path}app.$phpEx/portal", "f=$forum_id&t=$topic_id"); - $viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id"); + $portalpoll_url= append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "polls=$poll_view_str"); + $portalvote_url= append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "f=$forum_id&t=$topic_id"); + $viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f=$forum_id&t=$topic_id"); $poll_end = $data['poll_length'] + $data['poll_start']; // Parse BBCode title @@ -461,15 +521,15 @@ class portal_poll_module extends \board3\portal\modules\module_base $data['poll_title'] = smiley_text($data['poll_title']); unset($poll_bbcode); - $template->assign_block_vars(($type !== '') ? 'poll_' . $type : 'poll', array( + $this->template->assign_block_vars(($type !== '') ? 'poll_' . $type : 'poll', array( 'S_POLL_HAS_OPTIONS' => $poll_has_options, 'POLL_QUESTION' => $data['poll_title'], - 'U_POLL_TOPIC' => append_sid($phpbb_root_path . 'viewtopic.' . $phpEx . '?t=' . $topic_id . '&f=' . $forum_id), + 'U_POLL_TOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext . '?t=' . $topic_id . '&f=' . $forum_id), 'POLL_LENGTH' => $data['poll_length'], 'TOPIC_ID' => $topic_id, 'TOTAL_VOTES' => $poll_total_votes, - 'L_MAX_VOTES' => $user->lang('MAX_OPTIONS_SELECT', $data['poll_max_options']), - 'L_POLL_LENGTH' => ($data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '', + 'L_MAX_VOTES' => $this->user->lang('MAX_OPTIONS_SELECT', $data['poll_max_options']), + 'L_POLL_LENGTH' => ($data['poll_length']) ? sprintf($this->user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $this->user->format_date($poll_end)) : '', 'S_CAN_VOTE' => $s_can_vote, 'S_DISPLAY_RESULTS' => $s_display_results, 'S_IS_MULTI_CHOICE' => ($data['poll_max_options'] > 1) ? true : false, @@ -504,24 +564,24 @@ class portal_poll_module extends \board3\portal\modules\module_base $pd['poll_option_text'] = smiley_text($pd['poll_option_text']); unset($poll_bbcode); - $template->assign_block_vars((($type !== '') ? 'poll_' . $type : 'poll') . '.poll_option', array( + $this->template->assign_block_vars((($type !== '') ? 'poll_' . $type : 'poll') . '.poll_option', array( 'POLL_OPTION_ID' => $pd['poll_option_id'], 'POLL_OPTION_CAPTION' => $pd['poll_option_text'], 'POLL_OPTION_RESULT' => $pd['poll_option_total'], 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PCT' => round($option_pct * 100), - 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 35) . 'px'), + 'POLL_OPTION_IMG' => $this->user->img('poll_center', $option_pct_txt, round($option_pct * 35) . 'px'), 'POLL_OPTION_VOTED' => (in_array($pd['poll_option_id'], $cur_voted_id)) ? true : false )); } } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $template->assign_vars(array( + $this->template->assign_vars(array( 'S_HAS_POLL' => $has_poll, - 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'), - 'POLL_RIGHT_CAP_IMG' => $user->img('poll_right'), + 'POLL_LEFT_CAP_IMG' => $this->user->img('poll_left'), + 'POLL_RIGHT_CAP_IMG' => $this->user->img('poll_right'), )); } return (($type !== '') ? 'poll_' . $type : 'poll_center') . '.html'; diff --git a/portal/modules/portal_random_member.php b/modules/random_member.php similarity index 74% rename from portal/modules/portal_random_member.php rename to modules/random_member.php index 9e7e92c2..a47b693d 100644 --- a/portal/modules/portal_random_member.php +++ b/modules/random_member.php @@ -1,24 +1,18 @@ db = $db; + $this->template = $template; + $this->user = $user; + } + + /** + * @inheritdoc + */ public function get_template_side($module_id) { - global $config, $template, $db, $user; - - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'postgres': $sql = 'SELECT * @@ -85,8 +103,8 @@ class portal_random_member_module extends \board3\portal\modules\module_base break; } - $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); $avatar_img = get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']); @@ -97,7 +115,7 @@ class portal_random_member_module extends \board3\portal\modules\module_base $user_id = (int) $row['user_id']; $colour = $row['user_colour']; - $template->assign_block_vars('random_member', array( + $this->template->assign_block_vars('random_member', array( 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $colour), 'USERNAME' => get_username_string('username', $user_id, $username, $colour), 'USER_COLOR' => get_username_string('colour', $user_id, $username, $colour), @@ -109,16 +127,19 @@ class portal_random_member_module extends \board3\portal\modules\module_base 'USER_POSTS' => (int) $row['user_posts'], 'AVATAR_IMG' => $avatar_img, - 'JOINED' => $user->format_date($row['user_regdate'], 'd.M.Y'), + 'JOINED' => $this->user->format_date($row['user_regdate'], 'd.M.Y'), 'USER_OCC' => censor_text($row['user_occ']), 'USER_FROM' => censor_text($row['user_from']), 'U_WWW' => censor_text($row['user_website']), )); - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return 'random_member_side.html'; } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { return array( @@ -126,17 +147,4 @@ class portal_random_member_module extends \board3\portal\modules\module_base 'vars' => array(), ); } - - /** - * API functions - */ - public function install($module_id) - { - return true; - } - - public function uninstall($module_id, $db) - { - return true; - } } diff --git a/portal/modules/portal_recent.php b/modules/recent.php similarity index 53% rename from portal/modules/portal_recent.php rename to modules/recent.php index f7a31b2a..5956d15a 100644 --- a/portal/modules/portal_recent.php +++ b/modules/recent.php @@ -1,24 +1,18 @@ auth = $auth; + $this->config = $config; + $this->db = $db; + $this->template = $template; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $phpEx; + } + + /** + * @inheritdoc + */ public function get_template_center($module_id) { - global $config, $template, $db, $auth, $phpbb_root_path, $phpEx; - // // Exclude forums // $sql_where = ''; - if ($config['board3_recent_forum_' . $module_id] > 0) + if ($this->config['board3_recent_forum_' . $module_id] > 0) { - $exclude_forums = explode(',', $config['board3_recent_forum_' . $module_id]); + $exclude_forums = explode(',', $this->config['board3_recent_forum_' . $module_id]); - $sql_where = ' AND ' . $db->sql_in_set('forum_id', array_map('intval', $exclude_forums), ($config['board3_recent_exclude_forums_' . $module_id]) ? true : false); + $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($auth->acl_getf('!f_read', true))); + $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 @@ -79,13 +112,13 @@ class portal_recent_module extends \board3\portal\modules\module_base $forum_sql = ''; if (sizeof($forum_ary)) { - $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true); - $forum_sql = ' AND ' . $db->sql_in_set('t.forum_id', $forum_ary, true); + $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 = $db->sql_query_limit($sql, 1); - $g_forum_id = (int) $db->sql_fetchfield('forum_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, 1); + $g_forum_id = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); // // Recent announcements @@ -98,21 +131,21 @@ class portal_recent_module extends \board3\portal\modules\module_base AND topic_moved_id = 0 ' . $sql_where . '' . $forum_sql . ' ORDER BY topic_time DESC'; - $result = $db->sql_query_limit($sql, $config['board3_max_topics_' . $module_id]); + $result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id]); - while(($row = $db->sql_fetchrow($result)) && ($row['topic_title'])) + while(($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) { // auto auth - if (($auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) + if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) { - $template->assign_block_vars('latest_announcements', array( - 'TITLE' => character_limit($row['topic_title'], $config['board3_recent_title_limit_' . $module_id]), + $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("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) + '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']) )); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // // Recent hot topics @@ -120,25 +153,25 @@ class portal_recent_module extends \board3\portal\modules\module_base $sql = 'SELECT topic_title, forum_id, topic_id FROM ' . TOPICS_TABLE . ' t WHERE topic_visibility = ' . ITEM_APPROVED . ' - AND topic_posts_approved >' . $config['hot_threshold'] . ' + AND topic_posts_approved >' . $this->config['hot_threshold'] . ' AND topic_moved_id = 0 ' . $sql_where . '' . $forum_sql . ' ORDER BY topic_time DESC'; - $result = $db->sql_query_limit($sql, $config['board3_max_topics_' . $module_id]); + $result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id]); - while(($row = $db->sql_fetchrow($result)) && ($row['topic_title'])) + while(($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) { // auto auth - if (($auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) + if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) { - $template->assign_block_vars('latest_hot_topics', array( - 'TITLE' => character_limit($row['topic_title'], $config['board3_recent_title_limit_' . $module_id]), + $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("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id']) . '&t=' . $row['topic_id']) + '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']) )); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // // Recent topic (only show normal topic) @@ -151,25 +184,28 @@ class portal_recent_module extends \board3\portal\modules\module_base AND topic_moved_id = 0 ' . $sql_where . '' . $forum_sql . ' ORDER BY topic_time DESC'; - $result = $db->sql_query_limit($sql, $config['board3_max_topics_' . $module_id]); + $result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id]); - while(($row = $db->sql_fetchrow($result)) && ($row['topic_title'])) + while(($row = $this->db->sql_fetchrow($result)) && ($row['topic_title'])) { // auto auth - if (($auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) + if (($this->auth->acl_get('f_read', $row['forum_id'])) || ($row['forum_id'] == '0')) { - $template->assign_block_vars('latest_topics', array( - 'TITLE' => character_limit($row['topic_title'], $config['board3_recent_title_limit_' . $module_id]), + $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("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']) + 'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']) )); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return 'recent_center.html'; } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { return array( @@ -185,7 +221,7 @@ class portal_recent_module extends \board3\portal\modules\module_base } /** - * API functions + * @inheritdoc */ public function install($module_id) { @@ -196,6 +232,9 @@ class portal_recent_module extends \board3\portal\modules\module_base return true; } + /** + * @inheritdoc + */ public function uninstall($module_id, $db) { $del_config = array( @@ -209,17 +248,23 @@ class portal_recent_module extends \board3\portal\modules\module_base return $db->sql_query($sql); } - // Create forum select box + /** + * Create forum select box + * + * @param mixed $value Value of input + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ public function select_forums($value, $key, $module_id) { - global $user, $config; - $forum_list = make_forum_select(false, false, true, true, true, false, true); $selected = array(); - if(isset($config[$key]) && strlen($config[$key]) > 0) + if(isset($this->config[$key]) && strlen($this->config[$key]) > 0) { - $selected = explode(',', $config[$key]); + $selected = explode(',', $this->config[$key]); } // Build forum options $s_forum_options = '