From 18a93ea8291585af4822f7fee4c401d4432a215f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 11 Nov 2013 23:02:41 +0100 Subject: [PATCH 01/41] [feature/module_services] Add clock module --- config/services.yml | 5 ++++ modules/clock.php | 62 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 modules/clock.php diff --git a/config/services.yml b/config/services.yml index 70fb892d..feaf3821 100644 --- a/config/services.yml +++ b/config/services.yml @@ -51,3 +51,8 @@ services: - @user tags: - { name: board3.module } + + board3.module.clock: + class: \board3\portal\modules\clock + tags: + - { name: board3.module } diff --git a/modules/clock.php b/modules/clock.php new file mode 100644 index 00000000..dd83e513 --- /dev/null +++ b/modules/clock.php @@ -0,0 +1,62 @@ +lang}/mods/portal/" + */ + public $language = 'portal_clock_module'; + + /** + * @inheritdoc + */ + public function get_template_side($module_id) + { + return 'clock_side.html'; + } + + /** + * @inheritdoc + */ + public function get_template_acp($module_id) + { + return array( + 'title' => 'ACP_PORTAL_CLOCK_SETTINGS', + 'vars' => array(), + ); + } +} From 7f85489f690d2288ee19ee4ad4b3ee8107014c9a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 11 Nov 2013 23:03:06 +0100 Subject: [PATCH 02/41] [feature/module_services] Remove IN_PHPBB check from modules files --- modules/module_base.php | 8 -------- modules/module_interface.php | 8 -------- modules/stylechanger.php | 8 -------- 3 files changed, 24 deletions(-) diff --git a/modules/module_base.php b/modules/module_base.php index b266f1c5..728f601d 100644 --- a/modules/module_base.php +++ b/modules/module_base.php @@ -9,14 +9,6 @@ namespace board3\portal\modules; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * @package module_base */ diff --git a/modules/module_interface.php b/modules/module_interface.php index b6e49d6b..165c18e4 100644 --- a/modules/module_interface.php +++ b/modules/module_interface.php @@ -9,14 +9,6 @@ namespace board3\portal\modules; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * @package module_interface */ diff --git a/modules/stylechanger.php b/modules/stylechanger.php index 432fa333..b1eaddd1 100644 --- a/modules/stylechanger.php +++ b/modules/stylechanger.php @@ -9,14 +9,6 @@ namespace board3\portal\modules; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * @package Stylechanger */ From 145bfeb6e54b3d526aaeb6f27ef1a9ee25b6b956 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 13:39:23 +0100 Subject: [PATCH 03/41] [feature/module_services] Let generate_migrations_data handle new modules --- develop/generate_migrations_data.php | 104 +++++++++++++++++++++++---- develop/phpbb_functions.php | 47 ++++++++++++ migrations/v210_beta1.php | 4 +- 3 files changed, 138 insertions(+), 17 deletions(-) create mode 100644 develop/phpbb_functions.php diff --git a/develop/generate_migrations_data.php b/develop/generate_migrations_data.php index 97c40da8..6e0b0e16 100644 --- a/develop/generate_migrations_data.php +++ b/develop/generate_migrations_data.php @@ -13,6 +13,7 @@ define('IN_PHPBB', true); define('B3_MODULE_ENABLED', 1); define('GROUPS_TABLE', '$this->table_prefix . \'groups'); $phpbb_root_path = '../../../../'; +$root_path = '../'; // one directory down include($phpbb_root_path . 'includes/startup.php'); $php_ex = substr(strrchr(__FILE__, '.'), 1); $phpEx = $php_ex; @@ -27,8 +28,14 @@ $phpbb_class_loader_ext->register(); $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php"); $phpbb_class_loader->register(); +require($phpbb_root_path . 'includes/functions_content.' . $phpEx); +require($phpbb_root_path . 'includes/functions_container.' . $phpEx); +include($phpbb_root_path . 'includes/functions_compatibility.' . $phpEx); +require($root_path . 'develop/phpbb_functions.' . $phpEx); +// Set up container +$phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); + $config_entry = $portal_config_entry = $db_data = array(); -$root_path = '../'; // one directory down function set_config($name, $val) { @@ -46,7 +53,11 @@ function set_config($name, $val) function handle_string(&$str) { - if (is_string($str)) + if (is_string($str) && strpos($str, '$') === 0) + { + $str = str_replace(',', ' . \',\' . ', $str); + } + else if (is_string($str)) { $str = "'$str'"; } @@ -109,14 +120,14 @@ board3_get_install_data($db, $root_path, $php_ex, $db_data); echo 'set_config entries for migrations:
';
 foreach ($config_entry as $name => $val)
 {
-	echo 'array(\'config.add\', array(\'' . $name . '\', ' . $val . ')),
'; + echo ' array(\'config.add\', array(\'' . $name . '\', ' . $val . ')),
'; } echo '
'; echo '

set_portal_config entries for migrations:
';
 foreach ($portal_config_entry as $name => $val)
 {
-	echo '		set_portal_config(\'' . $name . '\', ' . $val . ');
'; + echo ' $this->set_portal_config(\'' . $name . '\', ' . $val . ');
'; } echo '
'; @@ -135,6 +146,8 @@ echo $db_data . '
'; */ function board3_get_install_data($db, $root_path, $php_ex, &$db_data) { + global $phpbb_container; + $directory = $root_path . 'portal/modules/'; $db_data = ' $board3_sql_query = array(
'; @@ -173,24 +186,34 @@ function board3_get_install_data($db, $root_path, $php_ex, &$db_data) foreach ($modules_ary as $module_name => $module_data) { - $class_name = $module_name . '_module'; - if (!class_exists($class_name)) + $new_module_name = '\\board3\\portal\\modules\\' . str_replace('portal_', '', $module_name); + if (class_exists($new_module_name)) { - include($directory . $module_name . '.' . $php_ex); + $c_class = $phpbb_container->get('board3.module.' . str_replace('portal_', '', $module_name)); + $module_name = $new_module_name; } - if (!class_exists($class_name)) + else { - trigger_error('Class not found', E_USER_ERROR); - } + $class_name = $module_name . '_module'; + if (!class_exists($class_name)) + { + include($directory . $module_name . '.' . $php_ex); + } + if (!class_exists($class_name)) + { + trigger_error('Class not found: ' . $class_name, E_USER_ERROR); + } - $c_class = new $class_name(); + $c_class = new $class_name(); + $module_name = substr($module_name, 7); + } $sql_ary = array( - 'module_classname' => substr($module_name, 7), + 'module_classname' => $module_name, 'module_column' => $module_data[0], 'module_order' => $module_data[1], - 'module_name' => $c_class->get_name, - 'module_image_src' => $c_class->get_image, + 'module_name' => $c_class->get_name(), + 'module_image_src' => $c_class->get_image(), 'module_group_ids' => '', 'module_image_width' => 16, 'module_image_height' => 16, @@ -297,7 +320,7 @@ class db } } $this->int_pointer++; - return $ret; + return $this->preg_replace_value($ret); } } } @@ -306,4 +329,55 @@ class db return false; } } + + protected function preg_replace_value($value) + { + return preg_replace("/\{foobar\.group_id\.\s*([A-Z_]+?)\s*+\}/", "\$groups_ary['$1']", $value); + } +} + +/** +* Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name. +* +* If $dbms is a valid 3.1 db driver class name, returns it unchanged. +* Otherwise prepends phpbb\db\driver\ to the dbms to convert a 3.0 dbms +* to 3.1 db driver class name. +* +* @param string $dbms dbms parameter +* @return db driver class +*/ +function phpbb_convert_30_dbms_to_31($dbms) +{ + // Note: this check is done first because mysqli extension + // supplies a mysqli class, and class_exists($dbms) would return + // true for mysqli class. + // However, per the docblock any valid 3.1 driver name should be + // recognized by this function, and have priority over 3.0 dbms. + if (class_exists('phpbb\db\driver\\' . $dbms)) + { + return 'phpbb\db\driver\\' . $dbms; + } + + if (class_exists($dbms)) + { + // Additionally we could check that $dbms extends phpbb\db\driver\driver. + // http://php.net/manual/en/class.reflectionclass.php + // Beware of possible performance issues: + // http://stackoverflow.com/questions/294582/php-5-reflection-api-performance + // We could check for interface implementation in all paths or + // only when we do not prepend phpbb\db\driver\. + + /* + $reflection = new \ReflectionClass($dbms); + + if ($reflection->isSubclassOf('phpbb\db\driver\driver')) + { + return $dbms; + } + */ + + return $dbms; + } + + throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } diff --git a/develop/phpbb_functions.php b/develop/phpbb_functions.php new file mode 100644 index 00000000..15742147 --- /dev/null +++ b/develop/phpbb_functions.php @@ -0,0 +1,47 @@ + 1, ), array( - 'module_classname' => 'stylechanger', + 'module_classname' => '\board3\portal\modules\stylechanger', 'module_column' => 1, 'module_order' => 2, 'module_name' => 'BOARD_STYLE', @@ -336,7 +336,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'clock', + 'module_classname' => '\board3\portal\modules\clock', 'module_column' => 1, 'module_order' => 4, 'module_name' => 'CLOCK', From 8de0a01890218c15a2ae8842b0cf230e328b0b11 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 13:41:05 +0100 Subject: [PATCH 04/41] [feature/module_services] Turn clock and stylechanger into new modules only --- modules/clock.php | 32 +++++++ modules/stylechanger.php | 32 +++++++ portal/modules/portal_clock.php | 75 ----------------- portal/modules/portal_stylechanger.php | 110 ------------------------- 4 files changed, 64 insertions(+), 185 deletions(-) delete mode 100644 portal/modules/portal_clock.php delete mode 100644 portal/modules/portal_stylechanger.php diff --git a/modules/clock.php b/modules/clock.php index dd83e513..c10d80ff 100644 --- a/modules/clock.php +++ b/modules/clock.php @@ -41,6 +41,38 @@ class clock extends module_base */ public $language = 'portal_clock_module'; + /** + * @inheritdoc + */ + public function get_allowed_columns() + { + return $this->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 */ diff --git a/modules/stylechanger.php b/modules/stylechanger.php index b1eaddd1..d6080666 100644 --- a/modules/stylechanger.php +++ b/modules/stylechanger.php @@ -51,6 +51,38 @@ class stylechanger extends module_base $this->user = $user; } + /** + * @inheritdoc + */ + public function get_allowed_columns() + { + return $this->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 */ diff --git a/portal/modules/portal_clock.php b/portal/modules/portal_clock.php deleted file mode 100644 index 89d05db0..00000000 --- a/portal/modules/portal_clock.php +++ /dev/null @@ -1,75 +0,0 @@ -lang}/mods/portal/" - */ - public $language = 'portal_clock_module'; - - public function get_template_side($module_id) - { - return 'clock_side.html'; - } - - public function get_template_acp($module_id) - { - return array( - 'title' => 'ACP_PORTAL_CLOCK_SETTINGS', - 'vars' => array(), - ); - } - - /** - * API functions - */ - public function install($module_id) - { - return true; - } - - public function uninstall($module_id) - { - return true; - } -} diff --git a/portal/modules/portal_stylechanger.php b/portal/modules/portal_stylechanger.php deleted file mode 100644 index 063fe1db..00000000 --- a/portal/modules/portal_stylechanger.php +++ /dev/null @@ -1,110 +0,0 @@ -lang}/mods/portal/" - */ - public $language = 'portal_stylechanger_module'; - - public function get_template_side($module_id) - { - global $config, $template, $db, $phpEx, $phpbb_root_path, $user; - - $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 = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $style = request_var('style', 0); - if (!empty($style)) - { - $url = str_replace('style=' . $style, 'style=' . $row['style_id'], append_sid("{$phpbb_root_path}app.$phpEx/portal")); - } - else - { - $url = append_sid("{$phpbb_root_path}app.$phpEx/portal", 'style=' . $row['style_id']); - } - ++$style_count; - $style_select .= ''; - } - $db->sql_freeresult($result); - if(strlen($style_select)) - { - $template->assign_var('STYLE_SELECT', $style_select); - } - - - // Assign specific vars - $template->assign_vars(array( - 'S_STYLE_OPTIONS' => ($config['override_user_style'] || $style_count < 2) ? '' : style_select($user->data['user_style']), - )); - - return 'stylechanger_side.html'; - } - - public function get_template_acp($module_id) - { - return array( - 'title' => 'BOARD_STYLE', - 'vars' => array(), - ); - } - - /** - * API functions - */ - public function install($module_id) - { - return true; - } - - public function uninstall($module_id) - { - return true; - } -} From 31b4fe1f967b11b3511ddfaa90f6be231bcf36fa Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 14:06:48 +0100 Subject: [PATCH 05/41] [feature/module_services] Ignore line in generate_migrations_data in sniffer --- develop/generate_migrations_data.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/develop/generate_migrations_data.php b/develop/generate_migrations_data.php index 6e0b0e16..b8cfae19 100644 --- a/develop/generate_migrations_data.php +++ b/develop/generate_migrations_data.php @@ -55,7 +55,9 @@ function handle_string(&$str) { if (is_string($str) && strpos($str, '$') === 0) { + // @codingStandardsIgnoreStart $str = str_replace(',', ' . \',\' . ', $str); + // @codingStandardsIgnoreEnd } else if (is_string($str)) { From 35fb3103f79a3160c5657b0b1ada9c0e27238b97 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 14:44:08 +0100 Subject: [PATCH 06/41] [feature/module_services] Move donation module to new module format --- config/services.yml | 9 +++ .../donation.php | 65 +++++++++++++------ 2 files changed, 54 insertions(+), 20 deletions(-) rename portal/modules/portal_donation.php => modules/donation.php (60%) diff --git a/config/services.yml b/config/services.yml index feaf3821..d9bd8c85 100644 --- a/config/services.yml +++ b/config/services.yml @@ -56,3 +56,12 @@ services: 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/portal/modules/portal_donation.php b/modules/donation.php similarity index 60% rename from portal/modules/portal_donation.php rename to modules/donation.php index d698c7a6..c3aa8a4b 100644 --- a/portal/modules/portal_donation.php +++ b/modules/donation.php @@ -1,24 +1,18 @@ config = $config; + $this->template = $template; + $this->user = $user; + } + + /** + * @inheritdoc + */ public function get_template_center($module_id) { - global $config, $template, $user; - - $template->assign_vars(array( - 'PAY_ACC_CENTER' => $config['board3_pay_acc_' . $module_id], - 'PAY_CUSTOM_CENTER' => (!empty($config['board3_pay_custom_' . $module_id])) ? $user->data['username_clean'] : false, + $this->template->assign_vars(array( + 'PAY_ACC_CENTER' => $this->config['board3_pay_acc_' . $module_id], + 'PAY_CUSTOM_CENTER' => (!empty($this->config['board3_pay_custom_' . $module_id])) ? $this->user->data['username_clean'] : false, )); return 'donation_center.html'; } + /** + * @inheritdoc + */ public function get_template_side($module_id) { - global $config, $template, $user; - - $template->assign_vars(array( - 'PAY_ACC_SIDE' => $config['board3_pay_acc_' . $module_id], - 'PAY_CUSTOM_SIDE' => (!empty($config['board3_pay_custom_' . $module_id])) ? $user->data['username_clean'] : false, + $this->template->assign_vars(array( + 'PAY_ACC_SIDE' => $this->config['board3_pay_acc_' . $module_id], + 'PAY_CUSTOM_SIDE' => (!empty($this->config['board3_pay_custom_' . $module_id])) ? $this->user->data['username_clean'] : false, )); return 'donation_side.html'; } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { return array( @@ -84,7 +106,7 @@ class portal_donation_module extends \board3\portal\modules\module_base } /** - * API functions + * @inheritdoc */ public function install($module_id) { @@ -93,6 +115,9 @@ class portal_donation_module extends \board3\portal\modules\module_base return true; } + /** + * @inheritdoc + */ public function uninstall($module_id) { global $db; From d0e8cbea3243ec0ca38d7f1812f1b1abedeea651 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 14:45:19 +0100 Subject: [PATCH 07/41] [feature/module_services] Fix docblocks and missing variables in modules --- modules/clock.php | 32 --------------------- modules/stylechanger.php | 60 +++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 64 deletions(-) diff --git a/modules/clock.php b/modules/clock.php index c10d80ff..dd83e513 100644 --- a/modules/clock.php +++ b/modules/clock.php @@ -41,38 +41,6 @@ class clock extends module_base */ public $language = 'portal_clock_module'; - /** - * @inheritdoc - */ - public function get_allowed_columns() - { - return $this->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 */ diff --git a/modules/stylechanger.php b/modules/stylechanger.php index d6080666..202ebcd3 100644 --- a/modules/stylechanger.php +++ b/modules/stylechanger.php @@ -41,6 +41,34 @@ class stylechanger extends module_base */ public $language = 'portal_stylechanger_module'; + /** @var \phpbb\config\config */ + protected $config; + + /** @var \phpbb\template */ + protected $template; + + /** @var \phpbb\db\driver */ + protected $db; + + /** @var php file extension */ + protected $php_ext; + + /** @var phpbb root path */ + protected $phpbb_root_path; + + /** @var \phpbb\user */ + protected $user; + + /** + * Construct a stylechanger object + * + * @param \phpbb\config\config $config phpBB config + * @param \phpbb\template $template phpBB template + * @param \phpbb\db\driver $db Database driver + * @param string $phpEx php file extension + * @param string $phpbb_root_path phpBB root path + * @param \phpbb\user $user phpBB user object + */ public function __construct($config, $template, $db, $phpEx, $phpbb_root_path, $user) { $this->config = $config; @@ -51,38 +79,6 @@ class stylechanger extends module_base $this->user = $user; } - /** - * @inheritdoc - */ - public function get_allowed_columns() - { - return $this->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 */ From c37da45612655532cc426a0a0e2cb2645fb90582 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 14:46:18 +0100 Subject: [PATCH 08/41] [feature/module_services] Pass phpBB dbal driver to module uninstall method --- modules/donation.php | 4 +--- modules/module_base.php | 2 +- modules/module_interface.php | 3 ++- portal/modules/portal_announcements.php | 4 +--- portal/modules/portal_attachments.php | 4 +--- portal/modules/portal_birthday_list.php | 4 +--- portal/modules/portal_calendar.php | 4 +--- portal/modules/portal_custom.php | 4 +--- portal/modules/portal_default.php | 4 +--- portal/modules/portal_forumlist.php | 2 +- portal/modules/portal_friends.php | 4 +--- portal/modules/portal_latest_bots.php | 4 +--- portal/modules/portal_latest_members.php | 4 +--- portal/modules/portal_leaders.php | 4 +--- portal/modules/portal_link_us.php | 2 +- portal/modules/portal_links.php | 4 +--- portal/modules/portal_main_menu.php | 4 +--- portal/modules/portal_news.php | 4 +--- portal/modules/portal_poll.php | 4 +--- portal/modules/portal_random_member.php | 2 +- portal/modules/portal_recent.php | 4 +--- portal/modules/portal_search.php | 2 +- portal/modules/portal_statistics.php | 2 +- portal/modules/portal_topposters.php | 4 +--- portal/modules/portal_user_menu.php | 4 +--- portal/modules/portal_welcome.php | 4 +--- portal/modules/portal_whois_online.php | 2 +- 27 files changed, 28 insertions(+), 65 deletions(-) diff --git a/modules/donation.php b/modules/donation.php index c3aa8a4b..ae34ddeb 100644 --- a/modules/donation.php +++ b/modules/donation.php @@ -118,10 +118,8 @@ class donation extends module_base /** * @inheritdoc */ - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_pay_acc_' . $module_id, 'board3_pay_custom_' . $module_id, diff --git a/modules/module_base.php b/modules/module_base.php index 728f601d..c80f9756 100644 --- a/modules/module_base.php +++ b/modules/module_base.php @@ -81,7 +81,7 @@ class module_base implements module_interface /** * @inheritdoc */ - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } diff --git a/modules/module_interface.php b/modules/module_interface.php index 165c18e4..d2911e21 100644 --- a/modules/module_interface.php +++ b/modules/module_interface.php @@ -93,8 +93,9 @@ interface module_interface * Executes any additional commands for uninstalling the module * * @param int $module_id Module's ID + * @param \phpbb\db\driver $db phpBB dbal driver * * @return bool True if uninstall was successful, false if not */ - public function uninstall($module_id); + public function uninstall($module_id, $db); } diff --git a/portal/modules/portal_announcements.php b/portal/modules/portal_announcements.php index 7d7b678e..679a7fd4 100644 --- a/portal/modules/portal_announcements.php +++ b/portal/modules/portal_announcements.php @@ -413,10 +413,8 @@ class portal_announcements_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_announcements_style_' . $module_id, 'board3_number_of_announcements_' . $module_id, diff --git a/portal/modules/portal_attachments.php b/portal/modules/portal_attachments.php index 1e2c0624..de2fee59 100644 --- a/portal/modules/portal_attachments.php +++ b/portal/modules/portal_attachments.php @@ -87,10 +87,8 @@ class portal_attachments_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_attachments_number_' . $module_id, 'board3_attach_max_length_' . $module_id, diff --git a/portal/modules/portal_birthday_list.php b/portal/modules/portal_birthday_list.php index 79ca6482..987766a9 100644 --- a/portal/modules/portal_birthday_list.php +++ b/portal/modules/portal_birthday_list.php @@ -146,10 +146,8 @@ class portal_birthday_list_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_birthdays_ahead_' . $module_id, ); diff --git a/portal/modules/portal_calendar.php b/portal/modules/portal_calendar.php index 61c60100..5b416630 100644 --- a/portal/modules/portal_calendar.php +++ b/portal/modules/portal_calendar.php @@ -297,10 +297,8 @@ class portal_calendar_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_calendar_events_' . $module_id, ); diff --git a/portal/modules/portal_custom.php b/portal/modules/portal_custom.php index f9374308..b397be9d 100644 --- a/portal/modules/portal_custom.php +++ b/portal/modules/portal_custom.php @@ -90,10 +90,8 @@ class portal_custom_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_custom_' . $module_id . '_code', ); diff --git a/portal/modules/portal_default.php b/portal/modules/portal_default.php index 5bf6dc39..a9f36a1f 100644 --- a/portal/modules/portal_default.php +++ b/portal/modules/portal_default.php @@ -102,10 +102,8 @@ class portal_modulename_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_configname_' . $module_id, 'board3_configname2_' . $module_id, diff --git a/portal/modules/portal_forumlist.php b/portal/modules/portal_forumlist.php index 12a04219..028fc725 100644 --- a/portal/modules/portal_forumlist.php +++ b/portal/modules/portal_forumlist.php @@ -87,7 +87,7 @@ class portal_forumlist_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } diff --git a/portal/modules/portal_friends.php b/portal/modules/portal_friends.php index a04b5eb3..95972e19 100644 --- a/portal/modules/portal_friends.php +++ b/portal/modules/portal_friends.php @@ -122,10 +122,8 @@ class portal_friends_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_max_online_friends_' . $module_id, ); diff --git a/portal/modules/portal_latest_bots.php b/portal/modules/portal_latest_bots.php index f4e6cb15..00879c16 100755 --- a/portal/modules/portal_latest_bots.php +++ b/portal/modules/portal_latest_bots.php @@ -103,10 +103,8 @@ class portal_latest_bots_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_last_visited_bots_number_' . $module_id, ); diff --git a/portal/modules/portal_latest_members.php b/portal/modules/portal_latest_members.php index a788a933..1475be99 100644 --- a/portal/modules/portal_latest_members.php +++ b/portal/modules/portal_latest_members.php @@ -90,10 +90,8 @@ class portal_latest_members_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_max_last_member_' . $module_id, ); diff --git a/portal/modules/portal_leaders.php b/portal/modules/portal_leaders.php index bb267d26..55b4f454 100644 --- a/portal/modules/portal_leaders.php +++ b/portal/modules/portal_leaders.php @@ -226,10 +226,8 @@ class portal_leaders_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_leaders_ext_' . $module_id, ); diff --git a/portal/modules/portal_link_us.php b/portal/modules/portal_link_us.php index 818f6b3c..13594b4e 100644 --- a/portal/modules/portal_link_us.php +++ b/portal/modules/portal_link_us.php @@ -79,7 +79,7 @@ class portal_link_us_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } diff --git a/portal/modules/portal_links.php b/portal/modules/portal_links.php index 9cae9a1f..61cd1457 100644 --- a/portal/modules/portal_links.php +++ b/portal/modules/portal_links.php @@ -160,10 +160,8 @@ class portal_links_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_links_array_' . $module_id, ); diff --git a/portal/modules/portal_main_menu.php b/portal/modules/portal_main_menu.php index 1ce257fd..6b514fc7 100644 --- a/portal/modules/portal_main_menu.php +++ b/portal/modules/portal_main_menu.php @@ -216,10 +216,8 @@ class portal_main_menu_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_menu_array_' . $module_id, ); diff --git a/portal/modules/portal_news.php b/portal/modules/portal_news.php index 6d5045d5..d8cd194b 100644 --- a/portal/modules/portal_news.php +++ b/portal/modules/portal_news.php @@ -394,10 +394,8 @@ class portal_news_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_news_length_' . $module_id, 'board3_news_forum_' . $module_id, diff --git a/portal/modules/portal_poll.php b/portal/modules/portal_poll.php index 828d8dc4..4466cf1a 100644 --- a/portal/modules/portal_poll.php +++ b/portal/modules/portal_poll.php @@ -91,10 +91,8 @@ class portal_poll_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_poll_allow_vote_' . $module_id, 'board3_poll_topic_id_' . $module_id, diff --git a/portal/modules/portal_random_member.php b/portal/modules/portal_random_member.php index 70d14aa6..9e7e92c2 100644 --- a/portal/modules/portal_random_member.php +++ b/portal/modules/portal_random_member.php @@ -135,7 +135,7 @@ class portal_random_member_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } diff --git a/portal/modules/portal_recent.php b/portal/modules/portal_recent.php index ccf6a28f..f7a31b2a 100644 --- a/portal/modules/portal_recent.php +++ b/portal/modules/portal_recent.php @@ -196,10 +196,8 @@ class portal_recent_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_max_topics_' . $module_id, 'board3_recent_title_limit_' . $module_id, diff --git a/portal/modules/portal_search.php b/portal/modules/portal_search.php index 0e0a3880..f87bc876 100644 --- a/portal/modules/portal_search.php +++ b/portal/modules/portal_search.php @@ -78,7 +78,7 @@ class portal_search_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } diff --git a/portal/modules/portal_statistics.php b/portal/modules/portal_statistics.php index 4da2187c..04b1ee82 100644 --- a/portal/modules/portal_statistics.php +++ b/portal/modules/portal_statistics.php @@ -153,7 +153,7 @@ class portal_statistics_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } diff --git a/portal/modules/portal_topposters.php b/portal/modules/portal_topposters.php index bb9f2776..34d7833d 100644 --- a/portal/modules/portal_topposters.php +++ b/portal/modules/portal_topposters.php @@ -98,10 +98,8 @@ class portal_topposters_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_topposters_' . $module_id, ); diff --git a/portal/modules/portal_user_menu.php b/portal/modules/portal_user_menu.php index b778a416..2a6c0f1d 100644 --- a/portal/modules/portal_user_menu.php +++ b/portal/modules/portal_user_menu.php @@ -167,10 +167,8 @@ class portal_user_menu_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_user_menu_register_' . $module_id, ); diff --git a/portal/modules/portal_welcome.php b/portal/modules/portal_welcome.php index 3300bd7c..60f748a5 100644 --- a/portal/modules/portal_welcome.php +++ b/portal/modules/portal_welcome.php @@ -93,10 +93,8 @@ class portal_welcome_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_welcome_message_' . $module_id, ); diff --git a/portal/modules/portal_whois_online.php b/portal/modules/portal_whois_online.php index 7b48481c..a215f627 100644 --- a/portal/modules/portal_whois_online.php +++ b/portal/modules/portal_whois_online.php @@ -130,7 +130,7 @@ class portal_whois_online_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + public function uninstall($module_id, $db) { return true; } From fd12ba4b8e047219ec5c75dadf8831c27d062b82 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 12 Nov 2013 14:59:01 +0100 Subject: [PATCH 09/41] [feature/module_services] Fix minor issues in portal_poll --- portal/modules/portal_poll.php | 10 ++++------ .../prosilver/template/portal/modules/poll_side.html | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/portal/modules/portal_poll.php b/portal/modules/portal_poll.php index 4466cf1a..2ee75102 100644 --- a/portal/modules/portal_poll.php +++ b/portal/modules/portal_poll.php @@ -214,10 +214,10 @@ class portal_poll_module extends \board3\portal\modules\module_base if($s_can_up_vote) { + $redirect_url = append_sid("{$phpbb_root_path}app.$phpEx/portal"); + if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id)) { - $redirect_url = append_sid("{$phpbb_root_path}portal.$phpEx"); - meta_refresh(5, $redirect_url); if (!sizeof($voted_id)) { @@ -295,8 +295,6 @@ class portal_poll_module extends \board3\portal\modules\module_base //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now $db->sql_query($sql); - $redirect_url = append_sid("{$phpbb_root_path}portal.$phpEx"); - meta_refresh(5, $redirect_url); trigger_error($user->lang['VOTE_SUBMITTED'] . '

' . sprintf($user->lang['RETURN_PORTAL'], '', '')); } @@ -437,8 +435,8 @@ 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}portal.$phpEx", "polls=$poll_view_str"); - $portalvote_url= append_sid("{$phpbb_root_path}portal.$phpEx", "f=$forum_id&t=$topic_id"); + $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"); $poll_end = $data['poll_length'] + $data['poll_start']; diff --git a/styles/prosilver/template/portal/modules/poll_side.html b/styles/prosilver/template/portal/modules/poll_side.html index 5bcb6ee8..cdc37f37 100644 --- a/styles/prosilver/template/portal/modules/poll_side.html +++ b/styles/prosilver/template/portal/modules/poll_side.html @@ -46,7 +46,7 @@ {poll_side.S_HIDDEN_FIELDS} - +
@@ -55,4 +55,4 @@
-{$LR_BLOCK_F_L}{$LR_BLOCK_F_R} \ No newline at end of file +{$LR_BLOCK_F_L}{$LR_BLOCK_F_R} From f852f166f762642a283092ae3850f68ef67756b0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 14 Nov 2013 14:02:02 +0100 Subject: [PATCH 10/41] [feature/module_services] Make announcements module a service --- config/services.yml | 14 + migrations/v210_beta1.php | 2 +- modules/announcements.php | 529 ++++++++++++++++++++++++ portal/includes/functions.php | 14 +- portal/modules/portal_announcements.php | 468 --------------------- 5 files changed, 549 insertions(+), 478 deletions(-) create mode 100644 modules/announcements.php delete mode 100644 portal/modules/portal_announcements.php diff --git a/config/services.yml b/config/services.yml index d9bd8c85..cd68b043 100644 --- a/config/services.yml +++ b/config/services.yml @@ -40,6 +40,20 @@ services: 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.stylechanger: class: \board3\portal\modules\stylechanger arguments: diff --git a/migrations/v210_beta1.php b/migrations/v210_beta1.php index d22558e2..c9a9b109 100644 --- a/migrations/v210_beta1.php +++ b/migrations/v210_beta1.php @@ -424,7 +424,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'announcements', + 'module_classname' => '\board3\portal\modules\announcements', 'module_column' => 2, 'module_order' => 3, 'module_name' => 'GLOBAL_ANNOUNCEMENTS', diff --git a/modules/announcements.php b/modules/announcements.php new file mode 100644 index 00000000..e8382de9 --- /dev/null +++ b/modules/announcements.php @@ -0,0 +1,529 @@ +lang}/mods/portal/" + */ + public $language = 'portal_announcements_module'; + + /** @var \phpbb\auth\auth */ + protected $auth; + + /** @var \phpbb\cache\driver */ + protected $cache; + + /** @var \phpbb\config\config */ + protected $config; + + /** @var \phpbb\template */ + protected $template; + + /** @var \phpbb\db\driver */ + protected $db; + + /** @var php file extension */ + protected $php_ext; + + /** @var phpbb root path */ + protected $phpbb_root_path; + + /** @var \phpbb\user */ + protected $user; + + /** + * Construct a stylechanger object + * + * @param \phpbb\auth\auth $auth phpBB auth service + * @param \phpbb\cache\driver $cache phpBB cache driver + * @param \phpbb\config\config $config phpBB config + * @param \phpbb\template $template phpBB template + * @param \phpbb\db\driver $db Database driver + * @param string $phpEx php file extension + * @param string $phpbb_root_path phpBB root path + * @param \phpbb\user $user phpBB user object + */ + public function __construct($auth, $cache, $config, $template, $db, $phpEx, $phpbb_root_path, $user) + { + $this->auth = $auth; + $this->cache = $cache; + $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_center($module_id) + { + $announcement = request_var('announcement', -1); + $announcement = ($announcement > $this->config['board3_announcements_length_' . $module_id] -1) ? -1 : $announcement; + $start = request_var('ap', 0); + $start = ($start < 0) ? 0 : $start; + + // Fetch announcements from portal/includes/functions.php with check if "read full" is requested. + $portal_announcement_length = ($announcement < 0) ? $this->config['board3_announcements_length_' . $module_id] : 0; + $fetch_news = phpbb_fetch_posts($module_id, $this->config['board3_global_announcements_forum_' . $module_id], $this->config['board3_announcements_permissions_' . $module_id], $this->config['board3_number_of_announcements_' . $module_id], $portal_announcement_length, $this->config['board3_announcements_day_' . $module_id], 'announcements', $start, $this->config['board3_announcements_forum_exclude_' . $module_id]); + + // Any announcements present? If not terminate it here. + if (sizeof($fetch_news) == 0) + { + $this->template->assign_block_vars('announcements_center_row', array( + 'S_NO_TOPICS' => true, + 'S_NOT_LAST' => false + )); + + $this->template->assign_var('S_CAN_READ', false); + } + else + { + // Count number of posts for announcements archive, considering if permission check is dis- or enabled. + if ($this->config['board3_announcements_archive_' . $module_id]) + { + $permissions = $this->config['board3_announcements_permissions_' . $module_id]; + $forum_from = $this->config['board3_global_announcements_forum_' . $module_id]; + $forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); + + $time = ($this->config['board3_announcements_day_' . $module_id] == 0) ? 0 : $this->config['board3_announcements_day_' . $module_id]; + $post_time = ($time == 0) ? '' : 'AND topic_time > ' . (time() - $time * 86400); + + $str_where = ''; + + if($permissions == true) + { + $disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true))); + } + else + { + $disallow_access = array(); + } + + if($this->config['board3_announcements_forum_exclude_' . $module_id] == true) + { + $disallow_access = array_merge($disallow_access, $forum_from); + $forum_from = array(); + } + + $global_f = 0; + + if(sizeof($forum_from)) + { + $disallow_access = array_diff($forum_from, $disallow_access); + if(!sizeof($disallow_access)) + { + return array(); + } + + foreach($disallow_access as $acc_id) + { + $str_where .= 'forum_id = ' . (int) $acc_id . ' OR '; + if($global_f < 1 && $acc_id > 0) + { + $global_f = $acc_id; + } + } + } + else + { + foreach($disallow_access as $acc_id) + { + $str_where .= 'forum_id <> ' . (int) $acc_id . ' AND '; + } + } + + $str_where = (strlen($str_where) > 0) ? 'AND (forum_id = 0 OR (' . trim(substr($str_where, 0, -4)) . '))' : ''; + + $sql = 'SELECT COUNT(topic_id) AS num_topics + FROM ' . TOPICS_TABLE . ' + WHERE ((topic_type = ' . POST_GLOBAL . ') + OR topic_type = ' . POST_ANNOUNCE . ') + AND topic_visibility = 1 + AND topic_moved_id = 0 + ' . $post_time . ' + ' . $str_where; + $result = $this->db->sql_query($sql); + $total_announcements = (int) $this->db->sql_fetchfield('num_topics'); + $this->db->sql_freeresult($result); + } + + $topic_tracking_info = (get_portal_tracking_info($fetch_news)); + + if($announcement < 0) + // Show the announcements overview + { + $count = $fetch_news['topic_count']; + for ($i = 0; $i < $count; $i++) + { + if(isset($fetch_news[$i]['striped']) && $fetch_news[$i]['striped'] == true) + { + $open_bracket = '[ '; + $close_bracket = ' ]'; + $read_full = $this->user->lang['READ_FULL']; + } + else + { + $open_bracket = ''; + $close_bracket = ''; + $read_full = ''; + } + // unread? + $forum_id = $fetch_news[$i]['forum_id']; + $topic_id = $fetch_news[$i]['topic_id']; + //$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id, $global_announce_list = false); + $unread_topic = (isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; + $real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id; + $read_full_url = (isset($_GET['ap'])) ? 'ap='. $start . '&announcement=' . $i . '#a' . $i : 'announcement=' . $i . '#a' . $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_announcements_archive_' . $module_id]) + { + $pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements'); + } + + $replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies']; + $folder_img = $folder_alt = $topic_type = $folder = $folder_new = ''; + switch ($fetch_news[$i]['topic_type']) + { + case POST_GLOBAL: + $folder = 'global_read'; + $folder_new = 'global_unread'; + break; + case POST_ANNOUNCE: + $folder = 'announce_read'; + $folder_new = 'announce_unread'; + break; + default: + $folder = 'topic_read'; + $folder_new = 'topic_unread'; + if ($this->config['hot_threshold'] && $replies >= $this->config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) + { + $folder .= '_hot'; + $folder_new .= '_hot'; + } + break; + } + + if ($fetch_news[$i]['topic_status'] == ITEM_LOCKED) + { + $folder .= '_locked'; + $folder_new .= '_locked'; + } + if ($fetch_news[$i]['topic_type'] == POST_GLOBAL) + { + $global_announce_list[$fetch_news[$i]['topic_id']] = true; + } + if ($fetch_news[$i]['topic_posted']) + { + $folder .= '_mine'; + $folder_new .= '_mine'; + } + $folder_img = ($unread_topic) ? $folder_new : $folder; + $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($fetch_news[$i]['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); + + // Grab icons + $icons = $this->cache->obtain_icons(); + + $this->template->assign_block_vars('announcements_center_row', array( + 'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $this->config['allow_attachments']) ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', + 'FORUM_NAME' => ($forum_id) ? $fetch_news[$i]['forum_name'] : '', + 'TITLE' => $fetch_news[$i]['topic_title'], + '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("{$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' => $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'], + 'A_ID' => $i, + 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), + 'TOPIC_FOLDER_IMG_SRC' => $this->user->img($folder_img, $folder_alt, false, '', 'src'), + 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], + 'FOLDER_IMG' => $this->user->img('topic_read', 'NO_NEW_POSTS'), + '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'] : '', + '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}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), + 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id . '&view=unread#unread'), + 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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, + 'S_NOT_LAST' => ($i < sizeof($fetch_news) - 1) ? true : false, + 'S_POLL' => $fetch_news[$i]['poll'], + 'S_UNREAD_INFO' => $unread_topic, + 'S_HAS_ATTACHMENTS' => (!empty($fetch_news[$i]['attachments'])) ? true : false, + )); + + phpbb_generate_template_pagination($this->template, $view_topic_url, 'announcements_center_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1, true, true); + + + if(!empty($fetch_news[$i]['attachments'])) + { + foreach ($fetch_news[$i]['attachments'] as $attachment) + { + $this->template->assign_block_vars('announcements_center_row.attachment', array( + 'DISPLAY_ATTACHMENT' => $attachment) + ); + } + } + if ($this->config['board3_number_of_announcements_' . $module_id] != 0 && $this->config['board3_announcements_archive_' . $module_id]) + { + $this->template->assign_vars(array( + 'AP_PAGINATION' => $pagination, + 'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $this->user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($this->user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements), + 'AP_PAGE_NUMBER' => phpbb_on_page($this->template, $this->user, '', $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start)) + ); + } + } + } + else + // Show "read full" page + { + $i = $announcement; + + /** + * redirect to portal page if the specified announcement does not exist + * force #top anchor in order to get rid of the #a anchor + */ + if (!isset($fetch_news[$i])) + { + redirect(append_sid($this->phpbb_root_path . 'app.' . $this->php_ext, '/portal#top')); + } + + $forum_id = $fetch_news[$i]['forum_id']; + $topic_id = $fetch_news[$i]['topic_id']; + $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id, $global_announce_list = false); + $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 = $this->user->lang['BACK']; + $real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id; + + $read_full_url = (isset($_GET['ap'])) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "ap=$start#a$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#a$i"); + $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_announcements_archive_' . $module_id]) + { + $pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements'); + } + + $this->template->assign_block_vars('announcements_center_row', array( + 'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $this->config['allow_attachments']) ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', + 'FORUM_NAME' => ($forum_id) ? $fetch_news[$i]['forum_name'] : '', + 'TITLE' => $fetch_news[$i]['topic_title'], + 'POSTER' => $fetch_news[$i]['username'], + 'POSTER_FULL' => $fetch_news[$i]['username_full'], + 'TIME' => $fetch_news[$i]['topic_time'], + 'TEXT' => $fetch_news[$i]['post_text'], + 'REPLIES' => $fetch_news[$i]['topic_replies'], + 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], + 'A_ID' => $i, + '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}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), + 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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, + 'S_HAS_ATTACHMENTS' => (!empty($fetch_news[$i]['attachments'])) ? true : false, + )); + + phpbb_generate_template_pagination($this->template, $view_topic_url, 'announcements_center_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1, true, true); + + if(!empty($fetch_news[$i]['attachments'])) + { + foreach ($fetch_news[$i]['attachments'] as $attachment) + { + $this->template->assign_block_vars('announcements_center_row.attachment', array( + 'DISPLAY_ATTACHMENT' => $attachment) + ); + } + } + + if ($this->config['board3_number_of_announcements_' . $module_id] <> 0 && $this->config['board3_announcements_archive_' . $module_id]) + { + $this->template->assign_vars(array( + 'AP_PAGINATION' => $pagination, + 'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $this->user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($this->user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements), + 'AP_PAGE_NUMBER' => phpbb_on_page($this->template, $this->user, '', $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start)) + ); + } + } + } + + $topic_icons = false; + if(!empty($fetch_news['topic_icons'])) + { + $topic_icons = true; + } + + $this->template->assign_vars(array( + 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), + 'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), + 'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE'), + 'S_DISPLAY_ANNOUNCEMENTS_RVS' => ($this->config['board3_show_announcements_replies_views_' . $module_id]) ? true : false, + 'S_TOPIC_ICONS' => $topic_icons, + )); + + if ($this->config['board3_announcements_style_' . $module_id]) + { + return 'announcements_center_compact.html'; + } + else + { + return 'announcements_center.html'; + } + } + + /** + * @inheritdoc + */ + public function get_template_acp($module_id) + { + return array( + 'title' => 'ACP_PORTAL_ANNOUNCE_SETTINGS', + 'vars' => array( + 'legend1' => 'ACP_PORTAL_ANNOUNCE_SETTINGS', + 'board3_announcements_style_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_STYLE' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_number_of_announcements_' . $module_id => array('lang' => 'PORTAL_NUMBER_OF_ANNOUNCEMENTS' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + 'board3_announcements_day_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_DAY' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + 'board3_announcements_length_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + 'board3_global_announcements_forum_' . $module_id => array('lang' => 'PORTAL_GLOBAL_ANNOUNCEMENTS_FORUM' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), + 'board3_announcements_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_FORUM_EXCLUDE', 'validate' => 'string', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_announcements_archive_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_ARCHIVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_announcements_permissions_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_PERMISSIONS' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_show_announcements_replies_views_' . $module_id => array('lang' => 'PORTAL_SHOW_REPLIES_VIEWS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + ), + ); + } + + /** + * @inheritdoc + */ + public function install($module_id) + { + set_config('board3_announcements_style_' . $module_id, 0); + set_config('board3_number_of_announcements_' . $module_id, 1); + set_config('board3_announcements_day_' . $module_id, 0); + set_config('board3_announcements_length_' . $module_id, 200); + set_config('board3_global_announcements_forum_' . $module_id, ''); + set_config('board3_announcements_forum_exclude_' . $module_id, 0); + set_config('board3_announcements_archive_' . $module_id, 1); + set_config('board3_announcements_permissions_' . $module_id, 1); + set_config('board3_show_announcements_replies_views_' . $module_id, 1); + + return true; + } + + /** + * @inheritdoc + */ + public function uninstall($module_id, $db) + { + $del_config = array( + 'board3_announcements_style_' . $module_id, + 'board3_number_of_announcements_' . $module_id, + 'board3_announcements_day_' . $module_id, + 'board3_announcements_length_' . $module_id, + 'board3_global_announcements_forum_' . $module_id, + 'board3_announcements_forum_exclude_' . $module_id, + 'board3_announcements_archive_' . $module_id, + 'board3_announcements_permissions_' . $module_id, + 'board3_show_announcements_replies_views_' . $module_id, + ); + $sql = 'DELETE FROM ' . CONFIG_TABLE . ' + WHERE ' . $db->sql_in_set('config_name', $del_config); + return $db->sql_query($sql); + } + + /** + * Create forum select box + * + * @param mixed $value Value of input + * @param string $key Key name + * @param int $module_id Module ID + * + * @return string Forum select box HTML + */ + public function select_forums($value, $key, $module_id) + { + $forum_list = make_forum_select(false, false, true, true, true, false, true); + + $selected = array(); + if(isset($this->config[$key]) && strlen($this->config[$key]) > 0) + { + $selected = explode(',', $this->config[$key]); + } + // Build forum options + $s_forum_options = ''; + + return $s_forum_options; + + } + + /** + * Store selected forums + * + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ + public function store_selected_forums($key, $module_id) + { + // Get selected forums + $values = request_var($key, array(0 => '')); + $news = implode(',', $values); + set_config($key, $news); + } +} diff --git a/portal/includes/functions.php b/portal/includes/functions.php index bd13aa78..4627c43c 100644 --- a/portal/includes/functions.php +++ b/portal/includes/functions.php @@ -183,15 +183,11 @@ function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_pos if ($type == 'announcements' && $global_f < 1) { - $sql = 'SELECT - forum_id - FROM - ' . FORUMS_TABLE . ' - WHERE - forum_type = ' . FORUM_POST . ' - ' . str_replace('t.', '', $str_where) . ' - ORDER BY - forum_id'; + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST . ' + ' . str_replace('t.', '', $str_where) . ' + ORDER BY forum_id'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/portal/modules/portal_announcements.php b/portal/modules/portal_announcements.php deleted file mode 100644 index 679a7fd4..00000000 --- a/portal/modules/portal_announcements.php +++ /dev/null @@ -1,468 +0,0 @@ -lang}/mods/portal/" - */ - public $language = 'portal_announcements_module'; - - public function get_template_center($module_id) - { - global $config, $template, $db, $user, $auth, $cache, $phpEx, $phpbb_root_path; - - $announcement = request_var('announcement', -1); - $announcement = ($announcement > $config['board3_announcements_length_' . $module_id] -1) ? -1 : $announcement; - $start = request_var('ap', 0); - $start = ($start < 0) ? 0 : $start; - - // Fetch announcements from portal/includes/functions.php with check if "read full" is requested. - $portal_announcement_length = ($announcement < 0) ? $config['board3_announcements_length_' . $module_id] : 0; - $fetch_news = phpbb_fetch_posts($module_id, $config['board3_global_announcements_forum_' . $module_id], $config['board3_announcements_permissions_' . $module_id], $config['board3_number_of_announcements_' . $module_id], $portal_announcement_length, $config['board3_announcements_day_' . $module_id], 'announcements', $start, $config['board3_announcements_forum_exclude_' . $module_id]); - - // Any announcements present? If not terminate it here. - if (sizeof($fetch_news) == 0) - { - $template->assign_block_vars('announcements_center_row', array( - 'S_NO_TOPICS' => true, - 'S_NOT_LAST' => false - )); - - $template->assign_var('S_CAN_READ', false); - } - else - { - // Count number of posts for announcements archive, considering if permission check is dis- or enabled. - if ($config['board3_announcements_archive_' . $module_id]) - { - $permissions = $config['board3_announcements_permissions_' . $module_id]; - $forum_from = $config['board3_global_announcements_forum_' . $module_id]; - $forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); - - $time = ($config['board3_announcements_day_' . $module_id] == 0) ? 0 : $config['board3_announcements_day_' . $module_id]; - $post_time = ($time == 0) ? '' : 'AND topic_time > ' . (time() - $time * 86400); - - $str_where = ''; - - if($permissions == true) - { - $disallow_access = array_unique(array_keys($auth->acl_getf('!f_read', true))); - } - else - { - $disallow_access = array(); - } - - if($config['board3_announcements_forum_exclude_' . $module_id] == true) - { - $disallow_access = array_merge($disallow_access, $forum_from); - $forum_from = array(); - } - - $global_f = 0; - - if(sizeof($forum_from)) - { - $disallow_access = array_diff($forum_from, $disallow_access); - if(!sizeof($disallow_access)) - { - return array(); - } - - foreach($disallow_access as $acc_id) - { - $acc_id = (int) $acc_id; - $str_where .= "forum_id = $acc_id OR "; - if($global_f < 1 && $acc_id > 0) - { - $global_f = $acc_id; - } - } - } - else - { - foreach($disallow_access as $acc_id) - { - $acc_id = (int) $acc_id; - $str_where .= "forum_id <> $acc_id AND "; - } - } - - $str_where = (strlen($str_where) > 0) ? 'AND (forum_id = 0 OR (' . trim(substr($str_where, 0, -4)) . '))' : ''; - - $sql = 'SELECT COUNT(topic_id) AS num_topics - FROM ' . TOPICS_TABLE . ' - WHERE ((topic_type = ' . POST_GLOBAL . ') - OR topic_type = ' . POST_ANNOUNCE . ') - AND topic_visibility = 1 - AND topic_moved_id = 0 - ' . $post_time . ' - ' . $str_where; - $result = $db->sql_query($sql); - $total_announcements = (int) $db->sql_fetchfield('num_topics'); - $db->sql_freeresult($result); - } - - $topic_tracking_info = (get_portal_tracking_info($fetch_news)); - - if($announcement < 0) - // Show the announcements overview - { - $count = $fetch_news['topic_count']; - for ($i = 0; $i < $count; $i++) - { - if(isset($fetch_news[$i]['striped']) && $fetch_news[$i]['striped'] == true) - { - $open_bracket = '[ '; - $close_bracket = ' ]'; - $read_full = $user->lang['READ_FULL']; - } - else - { - $open_bracket = ''; - $close_bracket = ''; - $read_full = ''; - } - // unread? - $forum_id = $fetch_news[$i]['forum_id']; - $topic_id = $fetch_news[$i]['topic_id']; - //$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id, $global_announce_list = false); - $unread_topic = (isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; - $real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id; - $read_full_url = (isset($_GET['ap'])) ? 'ap='. $start . '&announcement=' . $i . '#a' . $i : 'announcement=' . $i . '#a' . $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_announcements_archive_' . $module_id]) - { - $pagination = generate_portal_pagination(append_sid("{$phpbb_root_path}portal.$phpEx"), $total_announcements, $config['board3_number_of_announcements_' . $module_id], $start, 'announcements'); - } - - $replies = ($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']) - { - case POST_GLOBAL: - $folder = 'global_read'; - $folder_new = 'global_unread'; - break; - case POST_ANNOUNCE: - $folder = 'announce_read'; - $folder_new = 'announce_unread'; - break; - default: - $folder = 'topic_read'; - $folder_new = 'topic_unread'; - if ($config['hot_threshold'] && $replies >= $config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) - { - $folder .= '_hot'; - $folder_new .= '_hot'; - } - break; - } - - if ($fetch_news[$i]['topic_status'] == ITEM_LOCKED) - { - $folder .= '_locked'; - $folder_new .= '_locked'; - } - if ($fetch_news[$i]['topic_type'] == POST_GLOBAL) - { - $global_announce_list[$fetch_news[$i]['topic_id']] = true; - } - if ($fetch_news[$i]['topic_posted']) - { - $folder .= '_mine'; - $folder_new .= '_mine'; - } - $folder_img = ($unread_topic) ? $folder_new : $folder; - $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($fetch_news[$i]['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); - - // Grab icons - $icons = $cache->obtain_icons(); - - $template->assign_block_vars('announcements_center_row', array( - 'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $config['allow_attachments']) ? $user->img('icon_topic_attach', $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']) : '', - 'TIME' => $fetch_news[$i]['topic_time'], - 'LAST_POST_TIME' => $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'], - 'A_ID' => $i, - 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), - 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), - 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], - 'FOLDER_IMG' => $user->img('topic_read', 'NO_NEW_POSTS'), - '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'] : '', - '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", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), - 'U_VIEW_UNREAD' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id . '&view=unread#unread'), - 'U_POST_COMMENT' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), - 'U_READ_FULL' => append_sid("{$phpbb_root_path}portal.$phpEx", $read_full_url), - 'L_READ_FULL' => $read_full, - 'OPEN' => $open_bracket, - 'CLOSE' => $close_bracket, - 'S_NOT_LAST' => ($i < sizeof($fetch_news) - 1) ? true : false, - 'S_POLL' => $fetch_news[$i]['poll'], - 'S_UNREAD_INFO' => $unread_topic, - 'PAGINATION' => topic_generate_pagination($fetch_news[$i]['topic_replies'], $view_topic_url), - 'S_HAS_ATTACHMENTS' => (!empty($fetch_news[$i]['attachments'])) ? true : false, - )); - - if(!empty($fetch_news[$i]['attachments'])) - { - foreach ($fetch_news[$i]['attachments'] as $attachment) - { - $template->assign_block_vars('announcements_center_row.attachment', array( - 'DISPLAY_ATTACHMENT' => $attachment) - ); - } - } - if ($config['board3_number_of_announcements_' . $module_id] != 0 && $config['board3_announcements_archive_' . $module_id]) - { - $template->assign_vars(array( - 'AP_PAGINATION' => $pagination, - 'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements), - 'AP_PAGE_NUMBER' => on_page($total_announcements, $config['board3_number_of_announcements_' . $module_id], $start)) - ); - } - } - } - else - // Show "read full" page - { - $i = $announcement; - - /** - * redirect to portal page if the specified announcement does not exist - * force #top anchor in order to get rid of the #a anchor - */ - if (!isset($fetch_news[$i])) - { - redirect(append_sid($phpbb_root_path . 'portal.' . $phpEx, '#top')); - } - - $forum_id = $fetch_news[$i]['forum_id']; - $topic_id = $fetch_news[$i]['topic_id']; - $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id, $global_announce_list = false); - $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']; - $real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id; - - $read_full_url = (isset($_GET['ap'])) ? append_sid("{$phpbb_root_path}portal.$phpEx", "ap=$start#a$i") : append_sid("{$phpbb_root_path}portal.$phpEx#a$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_announcements_archive_' . $module_id]) - { - $pagination = generate_portal_pagination(append_sid("{$phpbb_root_path}portal.$phpEx"), $total_announcements, $config['board3_number_of_announcements_' . $module_id], $start, 'announcements'); - } - - $template->assign_block_vars('announcements_center_row', array( - 'ATTACH_ICON_IMG' => ($fetch_news[$i]['attachment'] && $config['allow_attachments']) ? $user->img('icon_topic_attach', $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'], - 'TIME' => $fetch_news[$i]['topic_time'], - 'TEXT' => $fetch_news[$i]['post_text'], - 'REPLIES' => $fetch_news[$i]['topic_replies'], - 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], - 'A_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", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), - 'U_POST_COMMENT' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $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, - )); - - if(!empty($fetch_news[$i]['attachments'])) - { - foreach ($fetch_news[$i]['attachments'] as $attachment) - { - $template->assign_block_vars('announcements_center_row.attachment', array( - 'DISPLAY_ATTACHMENT' => $attachment) - ); - } - } - - if ($config['board3_number_of_announcements_' . $module_id] <> 0 && $config['board3_announcements_archive_' . $module_id]) - { - $template->assign_vars(array( - 'AP_PAGINATION' => $pagination, - 'TOTAL_ANNOUNCEMENTS' => ($total_announcements == 1) ? $user->lang['VIEW_LATEST_ANNOUNCEMENT'] : sprintf($user->lang['VIEW_LATEST_ANNOUNCEMENTS'], $total_announcements), - 'AP_PAGE_NUMBER' => on_page($total_announcements, $config['board3_number_of_announcements_' . $module_id], $start)) - ); - } - } - } - - $topic_icons = false; - if(!empty($fetch_news['topic_icons'])) - { - $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_DISPLAY_ANNOUNCEMENTS_RVS' => ($config['board3_show_announcements_replies_views_' . $module_id]) ? true : false, - 'S_TOPIC_ICONS' => $topic_icons, - )); - - if ($config['board3_announcements_style_' . $module_id]) - { - return 'announcements_center_compact.html'; - } - else - { - return 'announcements_center.html'; - } - } - - public function get_template_acp($module_id) - { - return array( - 'title' => 'ACP_PORTAL_ANNOUNCE_SETTINGS', - 'vars' => array( - 'legend1' => 'ACP_PORTAL_ANNOUNCE_SETTINGS', - 'board3_announcements_style_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_STYLE' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_number_of_announcements_' . $module_id => array('lang' => 'PORTAL_NUMBER_OF_ANNOUNCEMENTS' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'board3_announcements_day_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_DAY' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'board3_announcements_length_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'board3_global_announcements_forum_' . $module_id => array('lang' => 'PORTAL_GLOBAL_ANNOUNCEMENTS_FORUM' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), - 'board3_announcements_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_FORUM_EXCLUDE', 'validate' => 'string', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_announcements_archive_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_ARCHIVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_announcements_permissions_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_PERMISSIONS' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_show_announcements_replies_views_' . $module_id => array('lang' => 'PORTAL_SHOW_REPLIES_VIEWS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - ), - ); - } - - /** - * API functions - */ - public function install($module_id) - { - set_config('board3_announcements_style_' . $module_id, 0); - set_config('board3_number_of_announcements_' . $module_id, 1); - set_config('board3_announcements_day_' . $module_id, 0); - set_config('board3_announcements_length_' . $module_id, 200); - set_config('board3_global_announcements_forum_' . $module_id, ''); - set_config('board3_announcements_forum_exclude_' . $module_id, 0); - set_config('board3_announcements_archive_' . $module_id, 1); - set_config('board3_announcements_permissions_' . $module_id, 1); - set_config('board3_show_announcements_replies_views_' . $module_id, 1); - - return true; - } - - public function uninstall($module_id, $db) - { - $del_config = array( - 'board3_announcements_style_' . $module_id, - 'board3_number_of_announcements_' . $module_id, - 'board3_announcements_day_' . $module_id, - 'board3_announcements_length_' . $module_id, - 'board3_global_announcements_forum_' . $module_id, - 'board3_announcements_forum_exclude_' . $module_id, - 'board3_announcements_archive_' . $module_id, - 'board3_announcements_permissions_' . $module_id, - 'board3_show_announcements_replies_views_' . $module_id, - ); - $sql = 'DELETE FROM ' . CONFIG_TABLE . ' - WHERE ' . $db->sql_in_set('config_name', $del_config); - return $db->sql_query($sql); - } - - // Create forum select box - 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) - { - $selected = explode(',', $config[$key]); - } - // Build forum options - $s_forum_options = ''; - - return $s_forum_options; - - } - - // Store selected forums - public function store_selected_forums($key, $module_id) - { - global $db, $cache; - - // Get selected forums - $values = request_var($key, array(0 => '')); - $news = implode(',', $values); - set_config($key, $news); - } -} From 942d8f98e2e0ca581bf94ea52c548e81589c1322 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 14 Nov 2013 17:15:36 +0100 Subject: [PATCH 11/41] [feature/module_services] Move attachments module to services --- config/services.yml | 13 ++ .../attachments.php | 178 ++++++++++++------ 2 files changed, 138 insertions(+), 53 deletions(-) rename portal/modules/portal_attachments.php => modules/attachments.php (59%) diff --git a/config/services.yml b/config/services.yml index cd68b043..6d522e50 100644 --- a/config/services.yml +++ b/config/services.yml @@ -54,6 +54,19 @@ services: 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.stylechanger: class: \board3\portal\modules\stylechanger arguments: diff --git a/portal/modules/portal_attachments.php b/modules/attachments.php similarity index 59% rename from portal/modules/portal_attachments.php rename to modules/attachments.php index de2fee59..718dfdc3 100644 --- a/portal/modules/portal_attachments.php +++ b/modules/attachments.php @@ -1,24 +1,18 @@ auth = $auth; + $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_center($module_id) { return $this->parse_template($module_id, 'center'); } + /** + * @inheritdoc + */ public function get_template_side($module_id) { return $this->parse_template($module_id, 'side'); } + /** + * @inheritdoc + */ public function get_template_acp($module_id) { return array( @@ -74,7 +120,7 @@ class portal_attachments_module extends \board3\portal\modules\module_base } /** - * API functions + * @inheritdoc */ public function install($module_id) { @@ -87,6 +133,9 @@ class portal_attachments_module extends \board3\portal\modules\module_base return true; } + /** + * @inheritdoc + */ public function uninstall($module_id, $db) { $del_config = array( @@ -102,26 +151,32 @@ class portal_attachments_module extends \board3\portal\modules\module_base return $db->sql_query($sql); } - // Create select box for attachment filetype + /** + * Create select box for attachment filetype + * + * @param mixed $value Value of input + * @param string $key Key name + * @param int $module_id Module ID + * + * @return string Forum select box HTML + */ public function select_filetype($value, $key, $module_id) { - global $db, $user, $config; - // Get extensions $sql = 'SELECT * FROM ' . EXTENSIONS_TABLE . ' ORDER BY extension ASC'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $extensions[] = $row; } $selected = array(); - if(isset($config['board3_attachments_filetype_' . $module_id]) && strlen($config['board3_attachments_filetype_' . $module_id]) > 0) + if(isset($this->config['board3_attachments_filetype_' . $module_id]) && strlen($this->config['board3_attachments_filetype_' . $module_id]) > 0) { - $selected = explode(',', $config['board3_attachments_filetype_' . $module_id]); + $selected = explode(',', $this->config['board3_attachments_filetype_' . $module_id]); } // Build options @@ -135,11 +190,16 @@ class portal_attachments_module extends \board3\portal\modules\module_base return $ext_options; } - // Store selected filetypes + /** + * Store selected filetypes + * + * @param string $key Key name + * @param int $module_id Module ID + * + * @return null + */ public function store_filetypes($key, $module_id) { - global $db, $cache; - // Get selected extensions $values = request_var($key, array(0 => '')); @@ -149,17 +209,23 @@ class portal_attachments_module extends \board3\portal\modules\module_base } - // 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 string Forum select box HTML + */ public function select_forums($value, $key) { - 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 = '