diff --git a/acp/portal_module.php b/acp/portal_module.php index f2a07d34..28e60880 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -22,9 +22,12 @@ class portal_module public $u_action; public $new_config = array(); protected $c_class; - protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx; + protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; protected $root_path, $mod_version_check; + /** @var \phpbb\di\service_collection Portal modules */ + protected $modules; + public function __construct() { global $db, $user, $cache, $template; @@ -46,7 +49,9 @@ class portal_module $this->phpbb_admin_path = $phpbb_admin_path; $this->portal_root_path = $this->root_path . 'portal/'; $this->php_ex = $phpEx; - $this->mod_version_check = $phpbb_container->get('board3.version.check'); + $this->phpbb_container = $phpbb_container; + $this->mod_version_check = $this->phpbb_container->get('board3.version.check'); + $this->register_modules($this->phpbb_container->get('board3.module_collection')); if (!function_exists('column_string_const')) { @@ -104,22 +109,32 @@ class portal_module if ($module_data !== false) { - $class = 'portal_' . $module_data['module_classname'] . '_module'; - if (!class_exists($class)) + if (!isset($this->modules[$module_data['module_classname']])) { - include($this->root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex); + $class = 'portal_' . $module_data['module_classname'] . '_module'; + if (!class_exists($class)) + { + include($this->root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex); + } + if (class_exists($class)) + { + $this->c_class = new $class(); + } + else + { + continue; + } } - if (!class_exists($class)) + else { - trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); + $this->c_class = $this->modules[$module_data['module_classname']]; } - $this->c_class = new $class(); - if ($this->c_class->language) + if ($this->c_class->get_language()) { - $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->language); + $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->get_language()); } - $module_name = $this->user->lang[$this->c_class->name]; + $module_name = $this->user->lang[$this->c_class->get_name()]; $display_vars = $this->c_class->get_template_acp($module_id); $this->template->assign_vars(array( 'MODULE_NAME' => (isset($this->c_class->hide_name) && $this->c_class->hide_name == true)? '' : $module_data['module_name'], @@ -277,7 +292,7 @@ class portal_module { add_log('admin', 'LOG_PORTAL_CONFIG', $this->user->lang['ACP_PORTAL_' . strtoupper($mode) . '_INFO']); } - trigger_error($this->user->lang['CONFIG_UPDATED'] . ((!empty($img_error) ? '

' . $this->user->lang['MODULE_IMAGE_ERROR'] . '
' . $img_error : '')) . adm_back_link(($module_id) ? append_sid("{$this->phpbb_root_path}adm/index.{$this->php_ex}", 'i=portal&mode=modules') : $this->u_action)); + trigger_error($this->user->lang['CONFIG_UPDATED'] . ((!empty($img_error) ? '

' . $this->user->lang['MODULE_IMAGE_ERROR'] . '
' . $img_error : '')) . adm_back_link(($module_id) ? append_sid("{$this->phpbb_root_path}adm/index.{$this->php_ex}", 'i=\board3\portal\acp\portal_module&mode=modules') : $this->u_action)); } // show custom HTML files on the settings page of the modules instead of the standard board3 portal one, if chosen by module @@ -408,7 +423,6 @@ class portal_module if ($submit) { $module_classname = request_var('module_classname', ''); - $class = 'portal_' . $module_classname . '_module'; $column_string = column_num_string($add_column); @@ -440,13 +454,24 @@ class portal_module trigger_error($this->user->lang['MODULE_ADD_ONCE'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (!class_exists($class)) + if (isset($this->modules[$module_classname])) { - include($directory . 'portal_' . $module_classname . '.' . $this->php_ex); + $this->c_class = $this->modules[$module_classname]; } - if (!class_exists($class)) + else { - trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); + $class = 'portal_' . $module_classname . '_module'; + + if (!class_exists($class)) + { + include($directory . 'portal_' . $module_classname . '.' . $this->php_ex); + } + if (!class_exists($class)) + { + trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); + } + + $this->c_class = new $class(); } $sql = 'SELECT module_order @@ -457,8 +482,6 @@ class portal_module $module_order = 1 + (int) $this->db->sql_fetchfield('module_order'); $this->db->sql_freeresult($result); - $this->c_class = new $class(); - $sql_ary = array( 'module_classname' => $module_classname, 'module_column' => $add_column, @@ -507,6 +530,7 @@ class portal_module $this->template->assign_var('S_EDIT', true); $fileinfo = array(); + // @todo: remove old school way of getting modules $dh = @opendir($directory); if (!$dh) { @@ -558,13 +582,13 @@ class portal_module $this->c_class = new $class(); if ($this->c_class->columns & column_string_const($add_module)) { - if ($this->c_class->language) + if ($this->c_class->get_language()) { - $this->user->add_lang('mods/portal/' . $this->c_class->language); + $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->get_language()); } $fileinfo[] = array( 'module' => substr($class, 7, -7), - 'name' => $this->user->lang[$this->c_class->name], + 'name' => $this->user->lang[$this->c_class->get_name()], ); } } @@ -572,6 +596,46 @@ class portal_module } closedir($dh); + // Find new modules + foreach ($this->modules as $module_class => $module) + { + if ($module_class !== '\board3\portal\modules\custom') + { + if (in_array($column_string, array('left', 'right'))) + { + // does the module already exist in the side columns? + if (isset($module_column[$module_class]) && + (in_array('left', $module_column[$module_class]) || in_array('right', $module_column[$module_class]))) + { + continue; + } + } + elseif (in_array($column_string, array('center', 'top', 'bottom'))) + { + // does the module already exist in the center columns? + if (isset($module_column[$module_class]) && + (in_array('center', $module_column[$module_class]) || + in_array('top', $module_column[$module_class]) || + in_array('bottom', $module_column[$module_class]))) + { + continue; + } + } + } + + if ($module->get_allowed_columns() & column_string_const($add_module)) + { + if ($module->get_language()) + { + $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $module->get_language()); + } + $fileinfo[] = array( + 'module' => $module_class, + 'name' => $this->user->lang[$module->get_name()], + ); + } + } + // we sort the $fileinfo array by the name of the modules foreach($fileinfo as $key => $cur_file) { @@ -601,25 +665,35 @@ class portal_module foreach($portal_modules as $row) { - $class = 'portal_' . $row['module_classname'] . '_module'; - if (!class_exists($class)) + if (!isset($this->modules[$row['module_classname']])) { - include($directory . 'portal_' . $row['module_classname'] . '.' . $this->php_ex); + $class = 'portal_' . $row['module_classname'] . '_module'; + if (!class_exists($class)) + { + include($directory . 'portal_' . $row['module_classname'] . '.' . $this->php_ex); + } + if (class_exists($class)) + { + $this->c_class = new $class(); + } + else + { + continue; + } } - if (!class_exists($class)) + else { - trigger_error('CLASS_NOT_FOUND', E_USER_ERROR); + $this->c_class = $this->modules[$row['module_classname']]; } - $this->c_class = new $class(); - if ($this->c_class->language) + if ($this->c_class->get_language()) { - $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->language); + $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->get_language()); } $template_column = column_num_string($row['module_column']); // find out of we can move modules to the left or right - if(($this->c_class->columns & column_string_const(column_num_string($row['module_column'] + 1))) || ($this->c_class->columns & column_string_const(column_num_string($row['module_column'] + 2)) && $row['module_column'] != 2)) + if(($this->c_class->get_allowed_columns() & column_string_const(column_num_string($row['module_column'] + 1))) || ($this->c_class->get_allowed_columns() & column_string_const(column_num_string($row['module_column'] + 2)) && $row['module_column'] != 2)) { /** * check if we can actually move @@ -652,7 +726,7 @@ class portal_module $move_right = false; } - if(($this->c_class->columns & column_string_const(column_num_string($row['module_column'] - 1))) || ($this->c_class->columns & column_string_const(column_num_string($row['module_column'] - 2)) && $row['module_column'] != 2)) + if(($this->c_class->get_allowed_columns() & column_string_const(column_num_string($row['module_column'] - 1))) || ($this->c_class->get_allowed_columns() & column_string_const(column_num_string($row['module_column'] - 2)) && $row['module_column'] != 2)) { /** * check if we can actually move @@ -1199,4 +1273,23 @@ class portal_module { return preg_replace(array('/i=[0-9]+/', '/mode=[a-zA-Z0-9_]+/'), array('i=\\' . __CLASS__, 'mode=' . $mode), $this->u_action) . '&module_id=' . $module_id; } + + /** + * Register list of Board3 Portal modules + * + * @param \phpbb\di\service_collection $modules Board3 Modules service + * collection + * @return null + */ + 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; + } + } + } } diff --git a/adm/style/portal/acp_portal.js b/adm/style/portal/acp_portal.js index 60cf5b5d..306f7452 100644 --- a/adm/style/portal/acp_portal.js +++ b/adm/style/portal/acp_portal.js @@ -331,11 +331,13 @@ function storeCaret(textEl) /** * Color pallette */ -function colorPalette(dir, width, height) -{ - var r = 0, g = 0, b = 0; - var numberList = new Array(6); - var color = ''; +function colorPalette(dir, width, height) { + var r = 0, + g = 0, + b = 0, + numberList = new Array(6), + color = '', + html = ''; numberList[0] = '00'; numberList[1] = '40'; @@ -343,44 +345,47 @@ function colorPalette(dir, width, height) numberList[3] = 'BF'; numberList[4] = 'FF'; - document.writeln(''); + html += '
'; - for (r = 0; r < 5; r++) - { - if (dir == 'h') - { - document.writeln(''); + for (r = 0; r < 5; r++) { + if (dir == 'h') { + html += ''; } - for (g = 0; g < 5; g++) - { - if (dir == 'v') - { - document.writeln(''); + for (g = 0; g < 5; g++) { + if (dir == 'v') { + html += ''; } - for (b = 0; b < 5; b++) - { + for (b = 0; b < 5; b++) { color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); - document.write(''); + html += ''; } - if (dir == 'v') - { - document.writeln(''); + if (dir == 'v') { + html += ''; } } - if (dir == 'h') - { - document.writeln(''); + if (dir == 'h') { + html += ''; } } - document.writeln('
'); - document.write('#' + color + ''); - document.writeln(''; + html += ''; + html += '
'); + html += ''; + return html; } +(function($) { + $(document).ready(function() { + $('#color_palette_placeholder').each(function() { + $(this).html(colorPalette('h', 5, 10)); + }); + }); +})(jQuery); + + /** * Caret Position object diff --git a/adm/style/portal/acp_portal_custom.html b/adm/style/portal/acp_portal_custom.html index 1fd3191e..4cc35484 100644 --- a/adm/style/portal/acp_portal_custom.html +++ b/adm/style/portal/acp_portal_custom.html @@ -1,6 +1,6 @@ - + @@ -131,41 +146,16 @@ var help_line = {
{L_PORTAL_CUSTOM}
style="display: none;"> +
diff --git a/config/services.yml b/config/services.yml index 70fb892d..c0f9cf52 100644 --- a/config/services.yml +++ b/config/services.yml @@ -40,6 +40,145 @@ 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.attachments: + class: \board3\portal\modules\attachments + arguments: + - @auth + - @config + - @template + - @dbal.conn + - %core.php_ext% + - %core.root_path% + - @user + tags: + - { name: board3.module } + + board3.module.birthday_list: + class: \board3\portal\modules\birthday_list + arguments: + - @config + - @template + - @dbal.conn + - @user + tags: + - { name: board3.module } + + board3.module.calendar: + class: \board3\portal\modules\calendar + arguments: + - @config + - @template + - @dbal.conn + - %core.root_path% + - %core.php_ext% + - @user + - @path_helper + tags: + - { name: board3.module } + + board3.module.custom: + class: \board3\portal\modules\custom + arguments: + - @config + - @template + - @dbal.conn + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.forumlist: + class: \board3\portal\modules\forumlist + arguments: + - @auth + - @config + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.friends: + class: \board3\portal\modules\friends + arguments: + - @auth + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.latest_bots: + class: \board3\portal\modules\latest_bots + arguments: + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.latest_members: + class: \board3\portal\modules\latest_members + arguments: + - @config + - @dbal.conn + - @template + - @user + tags: + - { name: board3.module } + + board3.module.leaders: + class: \board3\portal\modules\leaders + arguments: + - @auth + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + + board3.module.link_us: + class: \board3\portal\modules\link_us + arguments: + - @config + - @template + - @user + tags: + - { name: board3.module } + + board3.module.links: + class: \board3\portal\modules\links + arguments: + - @config + - @dbal.conn + - @template + - %core.root_path% + - %core.php_ext% + - @user + tags: + - { name: board3.module } + board3.module.stylechanger: class: \board3\portal\modules\stylechanger arguments: @@ -51,3 +190,17 @@ services: - @user tags: - { name: board3.module } + + board3.module.clock: + class: \board3\portal\modules\clock + tags: + - { name: board3.module } + + board3.module.donation: + class: \board3\portal\modules\donation + arguments: + - @config + - @template + - @user + tags: + - { name: board3.module } diff --git a/controller/main.php b/controller/main.php index 9c64e6cf..ad95e553 100644 --- a/controller/main.php +++ b/controller/main.php @@ -115,7 +115,7 @@ class main * * @param \phpbb\di\service_collection $modules Board3 Modules service * collection - * @return void + * @return null */ protected function register_modules($modules) { diff --git a/develop/generate_migrations_data.php b/develop/generate_migrations_data.php index 97c40da8..b8cfae19 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,13 @@ function set_config($name, $val) function handle_string(&$str) { - if (is_string($str)) + if (is_string($str) && strpos($str, '$') === 0) + { + // @codingStandardsIgnoreStart + $str = str_replace(',', ' . \',\' . ', $str); + // @codingStandardsIgnoreEnd + } + else if (is_string($str)) { $str = "'$str'"; } @@ -109,14 +122,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 +148,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 +188,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 +322,7 @@ class db } } $this->int_pointer++; - return $ret; + return $this->preg_replace_value($ret); } } } @@ -306,4 +331,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', @@ -325,7 +325,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'birthday_list', + 'module_classname' => '\board3\portal\modules\birthday_list', 'module_column' => 1, 'module_order' => 3, 'module_name' => 'BIRTHDAYS', @@ -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', @@ -358,7 +358,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'attachments', + 'module_classname' => '\board3\portal\modules\attachments', 'module_column' => 1, 'module_order' => 6, 'module_name' => 'PORTAL_ATTACHMENTS', @@ -380,7 +380,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'latest_members', + 'module_classname' => '\board3\portal\modules\latest_members', 'module_column' => 1, 'module_order' => 8, 'module_name' => 'LATEST_MEMBERS', @@ -391,7 +391,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'link_us', + 'module_classname' => '\board3\portal\modules\link_us', 'module_column' => 1, 'module_order' => 9, 'module_name' => 'LINK_US', @@ -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', @@ -490,7 +490,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'calendar', + 'module_classname' => '\board3\portal\modules\calendar', 'module_column' => 3, 'module_order' => 3, 'module_name' => 'PORTAL_CALENDAR', @@ -501,7 +501,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'leaders', + 'module_classname' => '\board3\portal\modules\leaders', 'module_column' => 3, 'module_order' => 4, 'module_name' => 'THE_TEAM', @@ -512,7 +512,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'latest_bots', + 'module_classname' => '\board3\portal\modules\latest_bots', 'module_column' => 3, 'module_order' => 5, 'module_name' => 'LATEST_BOTS', @@ -523,7 +523,7 @@ class v210_beta1 extends \phpbb\db\migration\migration 'module_status' => 1, ), array( - 'module_classname' => 'links', + 'module_classname' => '\board3\portal\modules\links', 'module_column' => 3, 'module_order' => 6, 'module_name' => 'PORTAL_LINKS', diff --git a/modules/announcements.php b/modules/announcements.php new file mode 100644 index 00000000..395eeee7 --- /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 an announcements 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/modules/portal_attachments.php b/modules/attachments.php similarity index 59% rename from portal/modules/portal_attachments.php rename to modules/attachments.php index 1e2c0624..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,10 +133,11 @@ class portal_attachments_module extends \board3\portal\modules\module_base return true; } - public function uninstall($module_id) + /** + * @inheritdoc + */ + public function uninstall($module_id, $db) { - global $db; - $del_config = array( 'board3_attachments_number_' . $module_id, 'board3_attach_max_length_' . $module_id, @@ -104,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 @@ -137,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 => '')); @@ -151,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 = ''; - foreach ($forum_list as $f_id => $f_row) - { - $s_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); - } -} diff --git a/portal/modules/portal_forumlist.php b/portal/modules/portal_forumlist.php deleted file mode 100644 index 12a04219..00000000 --- a/portal/modules/portal_forumlist.php +++ /dev/null @@ -1,94 +0,0 @@ -lang}/mods/portal/" - */ - public $language = 'portal_forumlist_module'; - - /** - * custom acp template - * file must be in "adm/style/portal/" - */ - public $custom_acp_tpl = ''; - - public function get_template_center($module_id) - { - global $config, $template, $user, $auth, $phpbb_root_path, $phpEx; - - display_forums('', $config['load_moderators'], false); - - $template->assign_vars(array( - 'FORUM_IMG' => $user->img('forum_read', 'NO_NEW_POSTS'), - 'FORUM_NEW_IMG' => $user->img('forum_unread', 'NEW_POSTS'), - 'FORUM_LOCKED_IMG' => $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'), - 'FORUM_NEW_LOCKED_IMG' => $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'), - 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums') : '', - 'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '', - )); - - return 'forumlist.html'; - } - - public function get_template_acp($module_id) - { - return array( - 'title' => 'PORTAL_FORUMLIST', - 'vars' => array(), - ); - } - - /** - * API functions - */ - public function install($module_id) - { - return true; - } - - public function uninstall($module_id) - { - return true; - } -} 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..1c4cb909 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, @@ -216,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)) { @@ -297,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'], '', '')); } @@ -439,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']; @@ -472,7 +468,7 @@ class portal_poll_module extends \board3\portal\modules\module_base 'POLL_LENGTH' => $data['poll_length'], 'TOPIC_ID' => $topic_id, 'TOTAL_VOTES' => $poll_total_votes, - 'L_MAX_VOTES' => ($data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $data['poll_max_options']), + 'L_MAX_VOTES' => $user->lang('MAX_OPTIONS_SELECT', $data['poll_max_options']), 'L_POLL_LENGTH' => ($data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '', 'S_CAN_VOTE' => $s_can_vote, 'S_DISPLAY_RESULTS' => $s_display_results, 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_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; - } -} 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; } diff --git a/styles/prosilver/template/portal/modules/attachments_center.html b/styles/prosilver/template/portal/modules/attachments_center.html index 93364230..bc1a7462 100644 --- a/styles/prosilver/template/portal/modules/attachments_center.html +++ b/styles/prosilver/template/portal/modules/attachments_center.html @@ -4,14 +4,14 @@ {L_FILENAME}
-  {attach_center.FILENAME}
+  {attach_center.FILENAME}
{L_FILESIZE}:{attach_center.FILESIZE}
{L_DOWNLOADS}:{attach_center.DOWNLOAD_COUNT}

- + {L_NO_ATTACHMENTS}
-{$C_BLOCK_F_L}{$C_BLOCK_F_R} \ No newline at end of file +{$C_BLOCK_F_L}{$C_BLOCK_F_R} diff --git a/styles/prosilver/template/portal/modules/attachments_side.html b/styles/prosilver/template/portal/modules/attachments_side.html index af279bf4..39efdc8c 100644 --- a/styles/prosilver/template/portal/modules/attachments_side.html +++ b/styles/prosilver/template/portal/modules/attachments_side.html @@ -2,12 +2,12 @@ {L_FILENAME}
-  {attach_side.FILENAME}
+  {attach_side.FILENAME}
{L_FILESIZE}:{attach_side.FILESIZE}
{L_DOWNLOADS}:{attach_side.DOWNLOAD_COUNT}

- + {L_NO_ATTACHMENTS}
-{$LR_BLOCK_F_L}{$LR_BLOCK_F_R} \ No newline at end of file +{$LR_BLOCK_F_L}{$LR_BLOCK_F_R} diff --git a/styles/prosilver/template/portal/modules/news_compact_center.html b/styles/prosilver/template/portal/modules/news_compact_center.html index 1c07c544..752e259c 100644 --- a/styles/prosilver/template/portal/modules/news_compact_center.html +++ b/styles/prosilver/template/portal/modules/news_compact_center.html @@ -26,7 +26,6 @@ {NEWEST_POST_IMG} {news_row.ATTACH_ICON_IMG} - {L_VIEW_TOPIC_POLL}
{news_row.TITLE}{L_VIEW_UNREAD_POST} @@ -73,4 +72,4 @@ {$C_BLOCK_F_L}{$C_BLOCK_F_R} - \ No newline at end of file + 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} diff --git a/styles/subsilver2/template/portal/modules/news_compact_center.html b/styles/subsilver2/template/portal/modules/news_compact_center.html index 058ae56e..f3aa40c3 100644 --- a/styles/subsilver2/template/portal/modules/news_compact_center.html +++ b/styles/subsilver2/template/portal/modules/news_compact_center.html @@ -30,7 +30,7 @@ [ {GOTO_PAGE_IMG}{L_GOTO_PAGE}: {news_row.PAGINATION} ] - {news_row.ATTACH_ICON_IMG} {L_VIEW_TOPIC_POLL}: {news_row.TITLE} + {news_row.ATTACH_ICON_IMG} {L_VIEW_TOPIC_POLL}{news_row.TITLE}

{L_POSTED} {L_POST_BY_AUTHOR} {news_row.POSTER_FULL} » {news_row.TIME}
{L_FORUM}: {news_row.FORUM_NAME} @@ -61,4 +61,4 @@ {$C_BLOCK_F_L}{$C_BLOCK_F_R} - \ No newline at end of file + diff --git a/tests/functional/portal_no_error_test.php b/tests/functional/portal_no_error_test.php new file mode 100644 index 00000000..c163e09b --- /dev/null +++ b/tests/functional/portal_no_error_test.php @@ -0,0 +1,41 @@ +login(); + $this->admin_login(); + $this->enable_board3_portal_ext(); + } + + public function test_vanilla_board() + { + $crawler = self::request('GET', 'app.php?portal'); + } + + public function test_with_poll() + { + // Create topic with poll + $data = $this->create_topic(2, 'Portal-poll', 'This is a poll for the portal', array( + 'poll_title' => 'Is this a poll?', + 'poll_option_text' => "Yes\nNo\nMaybe", + )); + + if (isset($data)) + { + $crawler = self::request('GET', 'app.php?portal'); + } + } +} diff --git a/tests/functional/portal_redirect_test.php b/tests/functional/portal_redirect_test.php index a667c130..8aa82b64 100644 --- a/tests/functional/portal_redirect_test.php +++ b/tests/functional/portal_redirect_test.php @@ -20,28 +20,6 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra $this->enable_board3_portal_ext(); } - protected function enable_board3_portal_ext() - { - $enable_portal = false; - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); - $disabled_extensions = $crawler->filter('tr.ext_disabled')->extract(array('_text')); - foreach ($disabled_extensions as $extension) - { - if (strpos($extension, 'Board3 Portal') !== false) - { - $enable_portal = true; - } - } - - if ($enable_portal) - { - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=board3%2fportal&sid=' . $this->sid); - $form = $crawler->selectButton('Enable')->form(); - $crawler = self::submit($form); - $this->assertContains('The extension was enabled successfully', $crawler->text()); - } - } - public function test_redirect() { if (function_exists('apache_get_modules')) @@ -51,7 +29,7 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra } else { - $mod_rewrite = (getenv('HTTP_MOD_REWRITE')=='On') ? true : false; + $mod_rewrite = (getenv('HTTP_MOD_REWRITE')=='On') ? true : false; } if ($mod_rewrite) diff --git a/tests/functions/check_file_src_test.php b/tests/functions/check_file_src_test.php new file mode 100644 index 00000000..b122ca78 --- /dev/null +++ b/tests/functions/check_file_src_test.php @@ -0,0 +1,41 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/styles.xml'); + } + + public function test_check_file_src() + { + $this->assertFalse(check_file_src('portal_attach.png', '', 15, false)); + $this->assertEquals(': styles/prosilver/theme/images/portal/portal_foobar.png
', check_file_src('portal_foobar.png', '', 15, false)); + } + + public function test_check_file_src_error() + { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->setExpectedTriggerError(E_USER_WARNING); + $this->assertEquals(': styles/prosilver/theme/images/portal/portal_foobar.png
', check_file_src('portal_foobar.png', '', 15)); + } +} diff --git a/tests/functions/fixtures/styles.xml b/tests/functions/fixtures/styles.xml new file mode 100644 index 00000000..6cb30627 --- /dev/null +++ b/tests/functions/fixtures/styles.xml @@ -0,0 +1,21 @@ + + + + style_path + style_name + style_active + style_parent_tree + + subsilver2 + subsilver2 + 0 + + + + prosilver + prosilver + 1 + + +
+
diff --git a/tests/testframework/functional_test_case.php b/tests/testframework/functional_test_case.php index 36058aee..09d3037d 100644 --- a/tests/testframework/functional_test_case.php +++ b/tests/testframework/functional_test_case.php @@ -11,4 +11,34 @@ namespace board3\portal\tests\testframework; abstract class functional_test_case extends \phpbb_functional_test_case { + protected $portal_enabled = false; + + public function enable_board3_portal_ext() + { + $enable_portal = false; + + if ($this->portal_enabled === true) + { + return; + } + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + $disabled_extensions = $crawler->filter('tr.ext_disabled')->extract(array('_text')); + foreach ($disabled_extensions as $extension) + { + if (strpos($extension, 'Board3 Portal') !== false) + { + $enable_portal = true; + } + } + + if ($enable_portal) + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=board3%2fportal&sid=' . $this->sid); + $form = $crawler->selectButton('Enable')->form(); + $crawler = self::submit($form); + $this->assertContains('The extension was enabled successfully', $crawler->text()); + $this->portal_enabled = true; + } + } } diff --git a/tests/testframework/test_case_helpers.php b/tests/testframework/test_case_helpers.php index 27c379c5..74ab9a82 100644 --- a/tests/testframework/test_case_helpers.php +++ b/tests/testframework/test_case_helpers.php @@ -9,7 +9,7 @@ namespace board3\portal\tests\testframework; -abstract class test_case_helpers extends \phpbb_test_case_helpers +class test_case_helpers extends \phpbb_test_case_helpers { /** * Copied from phpbb_test_case_helpers::get_test_config() to fix some paths