diff --git a/config/services.yml b/config/services.yml index 6a940fda..70fb892d 100644 --- a/config/services.yml +++ b/config/services.yml @@ -21,6 +21,7 @@ services: - @path_helper - %core.root_path% - .%core.php_ext% + - @board3.module_collection board3.version.check: class: \board3\portal\includes\mod_version_check @@ -31,3 +32,22 @@ services: - %core.php_ext% - @template - @user + + board3.module_collection: + class: phpbb\di\service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: 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 } diff --git a/controller/main.php b/controller/main.php index f5685b38..9c64e6cf 100644 --- a/controller/main.php +++ b/controller/main.php @@ -65,6 +65,12 @@ class main */ protected $path_helper; + /** + * Board3 Modules service collection + * @var phpbb\di\service_collection + */ + protected $modules; + /** * Constructor * NOTE: The parameters of this method must match in order and type with @@ -76,8 +82,10 @@ class main * @param \phpbb\path_helper $path_helper phpBB path helper * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP file extension + * @param \phpbb\di\service_collection $modules Board3 Modules service + * collection */ - public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext) + public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext, $modules) { global $portal_root_path; @@ -88,6 +96,8 @@ class main $this->path_helper = $path_helper; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->register_modules($modules); + $this->includes_path = $phpbb_root_path . 'ext/board3/portal/portal/'; $this->root_path = $phpbb_root_path . 'ext/board3/portal/'; $portal_root_path = $this->root_path; @@ -100,6 +110,25 @@ class main } } + /** + * Register list of Board3 Portal modules + * + * @param \phpbb\di\service_collection $modules Board3 Modules service + * collection + * @return void + */ + protected function register_modules($modules) + { + foreach ($modules as $current_module) + { + $class_name = '\\' . get_class($current_module); + if (!isset($this->modules[$class_name])) + { + $this->modules[$class_name] = $current_module; + } + } + } + /** * Extension front handler method. This is called automatically when your extension is accessed * through index.php?ext=example/foobar @@ -145,17 +174,28 @@ class main continue; } - $class_name = 'portal_' . $row['module_classname'] . '_module'; - if (!class_exists($class_name)) + // Do not try to load non-existant modules + if (!isset($this->modules[$row['module_classname']])) { - include("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}"); - } - if (!class_exists($class_name)) - { - trigger_error(sprintf($this->user->lang['CLASS_NOT_FOUND'], $class_name, 'portal_' . $row['module_classname']), E_USER_ERROR); - } + if (file_exists("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}")) + { + include("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}"); + } - $module = new $class_name(); + $class_name = 'portal_' . $row['module_classname'] . '_module'; + if (class_exists($class_name)) + { + $module = new $class_name(); + } + else + { + continue; + } + } + else + { + $module = $this->modules[$row['module_classname']]; + } /** * Check for permissions before loading anything @@ -167,9 +207,9 @@ class main continue; } - if ($module->language) + if ($language_file = $module->get_language()) { - $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $module->language); + $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $language_file); } if ($row['module_column'] == column_string_num('left') && $this->config['board3_left_column']) { diff --git a/modules/module_base.php b/modules/module_base.php new file mode 100644 index 00000000..b266f1c5 --- /dev/null +++ b/modules/module_base.php @@ -0,0 +1,96 @@ +columns; + } + + /** + * @inheritdoc + */ + public function get_name() + { + return $this->name; + } + + /** + * @inheritdoc + */ + public function get_image() + { + return $this->image_src; + } + + /** + * @inheritdoc + */ + public function get_language() + { + return $this->language; + } + + /** + * @inheritdoc + */ + public function get_template_side($module_id) + { + return; + } + + /** + * @inheritdoc + */ + public function get_template_center($module_id) + { + return; + } + + /** + * @inheritdoc + */ + public function get_template_acp($module_id) + { + return false; + } + + /** + * @inheritdoc + */ + public function install($module_id) + { + return true; + } + + /** + * @inheritdoc + */ + public function uninstall($module_id) + { + return true; + } +} diff --git a/modules/module_interface.php b/modules/module_interface.php new file mode 100644 index 00000000..b6e49d6b --- /dev/null +++ b/modules/module_interface.php @@ -0,0 +1,108 @@ +lang}/portal/" or + * this should return false. + * + * @return string|bool Language file or false + */ + public function get_language(); + + /** + * Get template file for side columns + * + * @param int $module_id Module's ID + * + * @return string Module template file + */ + public function get_template_side($module_id); + + /** + * Get template file for center columns + * + * @param int $module_id Module's ID + * + * @return string Module template file + */ + public function get_template_center($module_id); + + /** + * Get acp settings + * + * @param int $module_id Module's ID + * + * @return array ACP settings for module + */ + public function get_template_acp($module_id); + + /** + * Install module + * Executes any additional commands for installing the module + * + * @param int $module_id Module's ID + * + * @return bool True if install was successful, false if not + */ + public function install($module_id); + + /** + * Uninstall module + * Executes any additional commands for uninstalling the module + * + * @param int $module_id Module's ID + * + * @return bool True if uninstall was successful, false if not + */ + public function uninstall($module_id); +} diff --git a/modules/stylechanger.php b/modules/stylechanger.php new file mode 100644 index 00000000..432fa333 --- /dev/null +++ b/modules/stylechanger.php @@ -0,0 +1,113 @@ +lang}/mods/portal/" + */ + public $language = 'portal_stylechanger_module'; + + public function __construct($config, $template, $db, $phpEx, $phpbb_root_path, $user) + { + $this->config = $config; + $this->template = $template; + $this->db = $db; + $this->php_ext = $phpEx; + $this->phpbb_root_path = $phpbb_root_path; + $this->user = $user; + } + + /** + * @inheritdoc + */ + public function get_template_side($module_id) + { + $style_count = 0; + $style_select = ''; + $sql = 'SELECT style_id, style_name + FROM ' . STYLES_TABLE . ' + WHERE style_active = 1 + ORDER BY LOWER(style_name) ASC'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $style = request_var('style', 0); + if (!empty($style)) + { + $url = str_replace('style=' . $style, 'style=' . $row['style_id'], append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal")); + } + else + { + $url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", 'style=' . $row['style_id']); + } + ++$style_count; + $style_select .= ''; + } + $this->db->sql_freeresult($result); + if(strlen($style_select)) + { + $this->template->assign_var('STYLE_SELECT', $style_select); + } + + + // Assign specific vars + $this->template->assign_vars(array( + 'S_STYLE_OPTIONS' => ($this->config['override_user_style'] || $style_count < 2) ? '' : style_select($this->user->data['user_style']), + )); + + return 'stylechanger_side.html'; + } + + /** + * @inheritdoc + */ + public function get_template_acp($module_id) + { + return array( + 'title' => 'BOARD_STYLE', + 'vars' => array(), + ); + } +} diff --git a/portal/modules/portal_announcements.php b/portal/modules/portal_announcements.php index d79cad51..7d7b678e 100644 --- a/portal/modules/portal_announcements.php +++ b/portal/modules/portal_announcements.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Modulname */ -class portal_announcements_module +class portal_announcements_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_attachments.php b/portal/modules/portal_attachments.php index f10f468b..1e2c0624 100644 --- a/portal/modules/portal_attachments.php +++ b/portal/modules/portal_attachments.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Modulname */ -class portal_attachments_module +class portal_attachments_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_birthday_list.php b/portal/modules/portal_birthday_list.php index 39845ef3..79ca6482 100644 --- a/portal/modules/portal_birthday_list.php +++ b/portal/modules/portal_birthday_list.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Birthday List */ -class portal_birthday_list_module +class portal_birthday_list_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_calendar.php b/portal/modules/portal_calendar.php index f885e3a3..61c60100 100644 --- a/portal/modules/portal_calendar.php +++ b/portal/modules/portal_calendar.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Calendar */ -class portal_calendar_module +class portal_calendar_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_clock.php b/portal/modules/portal_clock.php index dd9faa87..89d05db0 100644 --- a/portal/modules/portal_clock.php +++ b/portal/modules/portal_clock.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Clock */ -class portal_clock_module +class portal_clock_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_custom.php b/portal/modules/portal_custom.php index 13007490..f9374308 100644 --- a/portal/modules/portal_custom.php +++ b/portal/modules/portal_custom.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Custom */ -class portal_custom_module +class portal_custom_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_default.php b/portal/modules/portal_default.php index eb4fa244..5bf6dc39 100644 --- a/portal/modules/portal_default.php +++ b/portal/modules/portal_default.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Modulname */ -class portal_modulename_module +class portal_modulename_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_donation.php b/portal/modules/portal_donation.php index 04ed6939..d698c7a6 100644 --- a/portal/modules/portal_donation.php +++ b/portal/modules/portal_donation.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Donation */ -class portal_donation_module +class portal_donation_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_forumlist.php b/portal/modules/portal_forumlist.php index f26322e0..12a04219 100644 --- a/portal/modules/portal_forumlist.php +++ b/portal/modules/portal_forumlist.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Forumlist */ -class portal_forumlist_module +class portal_forumlist_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_friends.php b/portal/modules/portal_friends.php index 748bd0ed..a04b5eb3 100644 --- a/portal/modules/portal_friends.php +++ b/portal/modules/portal_friends.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Friends */ -class portal_friends_module +class portal_friends_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_latest_bots.php b/portal/modules/portal_latest_bots.php index 4a9e85df..f4e6cb15 100755 --- a/portal/modules/portal_latest_bots.php +++ b/portal/modules/portal_latest_bots.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Latest Bots */ -class portal_latest_bots_module +class portal_latest_bots_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_latest_members.php b/portal/modules/portal_latest_members.php index 501a8970..a788a933 100644 --- a/portal/modules/portal_latest_members.php +++ b/portal/modules/portal_latest_members.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Modulname */ -class portal_latest_members_module +class portal_latest_members_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_leaders.php b/portal/modules/portal_leaders.php index 0e618393..bb267d26 100644 --- a/portal/modules/portal_leaders.php +++ b/portal/modules/portal_leaders.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Leaders */ -class portal_leaders_module +class portal_leaders_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_link_us.php b/portal/modules/portal_link_us.php index 2f16e488..818f6b3c 100644 --- a/portal/modules/portal_link_us.php +++ b/portal/modules/portal_link_us.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Clock */ -class portal_link_us_module +class portal_link_us_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_links.php b/portal/modules/portal_links.php index fc82e7c3..9cae9a1f 100644 --- a/portal/modules/portal_links.php +++ b/portal/modules/portal_links.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Links */ -class portal_links_module +class portal_links_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_main_menu.php b/portal/modules/portal_main_menu.php index ce065583..1ce257fd 100644 --- a/portal/modules/portal_main_menu.php +++ b/portal/modules/portal_main_menu.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Main Menu */ -class portal_main_menu_module +class portal_main_menu_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_news.php b/portal/modules/portal_news.php index b5dce512..6d5045d5 100644 --- a/portal/modules/portal_news.php +++ b/portal/modules/portal_news.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package News */ -class portal_news_module +class portal_news_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_poll.php b/portal/modules/portal_poll.php index 2fe95581..828d8dc4 100644 --- a/portal/modules/portal_poll.php +++ b/portal/modules/portal_poll.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Poll */ -class portal_poll_module +class portal_poll_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_random_member.php b/portal/modules/portal_random_member.php index 540b893a..70d14aa6 100644 --- a/portal/modules/portal_random_member.php +++ b/portal/modules/portal_random_member.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Random Member */ -class portal_random_member_module +class portal_random_member_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_recent.php b/portal/modules/portal_recent.php index 0c3061e4..ccf6a28f 100644 --- a/portal/modules/portal_recent.php +++ b/portal/modules/portal_recent.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Recent */ -class portal_recent_module +class portal_recent_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_search.php b/portal/modules/portal_search.php index 65267e86..0e0a3880 100644 --- a/portal/modules/portal_search.php +++ b/portal/modules/portal_search.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Search */ -class portal_search_module +class portal_search_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_statistics.php b/portal/modules/portal_statistics.php index 59c030c6..4da2187c 100644 --- a/portal/modules/portal_statistics.php +++ b/portal/modules/portal_statistics.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Statistics */ -class portal_statistics_module +class portal_statistics_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_stylechanger.php b/portal/modules/portal_stylechanger.php index 8f5fee1f..063fe1db 100644 --- a/portal/modules/portal_stylechanger.php +++ b/portal/modules/portal_stylechanger.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Stylechanger */ -class portal_stylechanger_module +class portal_stylechanger_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_topposters.php b/portal/modules/portal_topposters.php index 086749c2..bb9f2776 100644 --- a/portal/modules/portal_topposters.php +++ b/portal/modules/portal_topposters.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Topposters */ -class portal_topposters_module +class portal_topposters_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_user_menu.php b/portal/modules/portal_user_menu.php index 407b1bf6..b778a416 100644 --- a/portal/modules/portal_user_menu.php +++ b/portal/modules/portal_user_menu.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Modulname */ -class portal_user_menu_module +class portal_user_menu_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_welcome.php b/portal/modules/portal_welcome.php index 7e55916d..3300bd7c 100644 --- a/portal/modules/portal_welcome.php +++ b/portal/modules/portal_welcome.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Welcome */ -class portal_welcome_module +class portal_welcome_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10) diff --git a/portal/modules/portal_whois_online.php b/portal/modules/portal_whois_online.php index ce8de3c5..7b48481c 100644 --- a/portal/modules/portal_whois_online.php +++ b/portal/modules/portal_whois_online.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) /** * @package Who is online */ -class portal_whois_online_module +class portal_whois_online_module extends \board3\portal\modules\module_base { /** * Allowed columns: Just sum up your options (Exp: left + right = 10)