diff --git a/acp/portal_info.php b/acp/portal_info.php index b8cc7eeb..527c102e 100644 --- a/acp/portal_info.php +++ b/acp/portal_info.php @@ -9,11 +9,6 @@ namespace board3\portal\acp; -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * @package module_install */ diff --git a/acp/portal_module.php b/acp/portal_module.php index c54286a4..92d4af41 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -9,14 +9,6 @@ namespace board3\portal\acp; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class portal_module { public $u_action; @@ -31,7 +23,7 @@ class portal_module public function __construct() { - global $db, $user, $cache, $request, $template; + global $db, $user, $cache, $request, $template, $table_prefix; global $config, $phpbb_root_path, $phpbb_admin_path, $phpbb_container, $phpEx; $user->add_lang_ext('board3/portal', array('portal', 'portal_acp')); @@ -52,6 +44,8 @@ class portal_module $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')); + define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.modules.table')); + define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.config.table')); if (!function_exists('column_string_const')) { @@ -396,19 +390,19 @@ class portal_module { $this->move_module_up($module_id); } - elseif ($action == 'move_down') + else if ($action == 'move_down') { $this->move_module_down($module_id); } - elseif($action == 'move_right') + else if($action == 'move_right') { $this->move_module_right($module_id); } - elseif($action == 'move_left') + else if($action == 'move_left') { $this->move_module_left($module_id); } - elseif ($action == 'delete') + else if ($action == 'delete') { $this->module_delete($id, $mode, $action, $module_id); } @@ -429,7 +423,7 @@ class portal_module { $submit = $this->can_move_module(array('left', 'right'), $module_classname); } - elseif (in_array($column_string, array('center', 'top', 'bottom'))) + else if (in_array($column_string, array('center', 'top', 'bottom'))) { $submit = $this->can_move_module(array('center', 'top', 'bottom'), $module_classname); } @@ -519,7 +513,7 @@ class portal_module continue; } } - elseif (in_array($column_string, array('center', 'top', 'bottom'))) + else if (in_array($column_string, array('center', 'top', 'bottom'))) { // does the module already exist in the center columns? if (!$this->can_move_module(array('center', 'top', 'bottom'), $module_class)) @@ -956,7 +950,7 @@ class portal_module { $move_action = 1; // we move 1 column to the left } - elseif($this->c_class->columns & column_string_const(column_num_string($module_data['module_column'] - 2)) && $module_data['module_column'] != 2) + else if($this->c_class->columns & column_string_const(column_num_string($module_data['module_column'] - 2)) && $module_data['module_column'] != 2) { $move_action = 2; // we move 2 columns to the left } @@ -980,7 +974,7 @@ class portal_module { trigger_error($this->user->lang['UNABLE_TO_MOVE'] . adm_back_link($this->u_action)); } - elseif ($column_string == 'center' && !$this->can_move_module(array('top', 'center', 'bottom'), $module_data['module_classname'])) + else if ($column_string == 'center' && !$this->can_move_module(array('top', 'center', 'bottom'), $module_data['module_classname'])) { // we are moving from the right to the center column so we should move to the left column instead $move_action = 2; @@ -1051,7 +1045,7 @@ class portal_module { $move_action = 1; // we move 1 column to the right } - elseif($this->c_class->columns & column_string_const(column_num_string($module_data['module_column'] + 2)) && $module_data['module_column'] != 2) + else if($this->c_class->columns & column_string_const(column_num_string($module_data['module_column'] + 2)) && $module_data['module_column'] != 2) { $move_action = 2; // we move 2 columns to the right } @@ -1075,7 +1069,7 @@ class portal_module { trigger_error($this->user->lang['UNABLE_TO_MOVE'] . adm_back_link($this->u_action)); } - elseif ($column_string == 'center' && !$this->can_move_module(array('top', 'center', 'bottom'), $module_data['module_classname'])) + else if ($column_string == 'center' && !$this->can_move_module(array('top', 'center', 'bottom'), $module_data['module_classname'])) { // we are moving from the left to the center column so we should move to the right column instead $move_action = 2; @@ -1264,7 +1258,7 @@ class portal_module $submit = false; } } - elseif (in_array($target_column, array('center', 'top', 'bottom'))) + else if (in_array($target_column, array('center', 'top', 'bottom'))) { // does the module already exist in the center columns? if (isset($this->module_column[$module_class]) && diff --git a/config/services.yml b/config/services.yml index 94ba2650..a779c9b3 100644 --- a/config/services.yml +++ b/config/services.yml @@ -11,6 +11,8 @@ parameters: - board3.de - updatecheck - board3_portal.xml + board3.config.table: %core.table_prefix%portal_config + board3.modules.table: %core.table_prefix%portal_modules services: board3.portal.main: @@ -24,6 +26,8 @@ services: - %core.root_path% - .%core.php_ext% - @board3.module_collection + - %board3.config.table% + - %board3.modules.table% board3.version.check: class: board3\portal\includes\mod_version_check diff --git a/controller/main.php b/controller/main.php index d6072a96..abd02895 100644 --- a/controller/main.php +++ b/controller/main.php @@ -84,8 +84,10 @@ class main * @param string $php_ext PHP file extension * @param \phpbb\di\service_collection $modules Board3 Modules service * collection + * @param string $config_table Board3 config table + * @param string $modules_table Board3 modules table */ - public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext, $modules) + public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext, $modules, $config_table, $modules_table) { global $portal_root_path; @@ -101,6 +103,8 @@ class main $this->includes_path = $phpbb_root_path . 'ext/board3/portal/includes/'; $this->root_path = $phpbb_root_path . 'ext/board3/portal/'; $portal_root_path = $this->root_path; + define('PORTAL_MODULES_TABLE', $modules_table); + define('PORTAL_CONFIG_TABLE', $config_table); if (!function_exists('obtain_portal_config')) { diff --git a/develop/create_schema_files.php b/develop/create_schema_files.php deleted file mode 100644 index 1107bec5..00000000 --- a/develop/create_schema_files.php +++ /dev/null @@ -1,242 +0,0 @@ -get('ext.manager') - ->get_finder() - ->core_path('ext/board3/portal/') - ->directory('migrations') - ->get_classes(); - -// Get phpBB classes and merge with above -$classes = array_merge($classes, $phpbb_container->get('ext.manager') - ->get_finder() - ->core_path('phpbb/') - ->directory('db/migration/data') - ->get_classes()); -$db_tools = new \phpbb\db\tools($db, true); - -$schema_generator = new \phpbb\db\migration\schema_generator($classes, $config, $db, $db_tools, $phpbb_root_path, $phpEx, 'phpbb_'); -$schema_data = $schema_generator->get_schema(); -$dbms_type_map = phpbb\db\tools::get_dbms_type_map(); - -$fp = fopen($schema_path . 'schema.json', 'wb'); -fwrite($fp, json_encode($schema_data, JSON_PRETTY_PRINT)); -fclose($fp); - -foreach ($supported_dbms as $dbms) -{ - $fp = fopen($schema_path . $dbms . '_schema.sql', 'wb'); - - // Write Header - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'firebird': - case 'sqlite': - fwrite($fp, "# DO NOT EDIT THIS FILE, IT IS GENERATED\n"); - fwrite($fp, "#\n"); - fwrite($fp, "# To change the contents of this file, edit\n"); - fwrite($fp, "# phpBB/develop/create_schema_files.php and\n"); - fwrite($fp, "# run it.\n"); - break; - - case 'mssql': - case 'oracle': - case 'postgres': - fwrite($fp, "/*\n"); - fwrite($fp, " * DO NOT EDIT THIS FILE, IT IS GENERATED\n"); - fwrite($fp, " *\n"); - fwrite($fp, " * To change the contents of this file, edit\n"); - fwrite($fp, " * phpBB/develop/create_schema_files.php and\n"); - fwrite($fp, " * run it.\n"); - fwrite($fp, " */\n\n"); - break; - } - - $line = ''; - switch ($dbms) - { - case 'oracle': - $line .= custom_data('oracle') . "\n"; - break; - - case 'postgres': - $line .= "BEGIN;\n\n"; - $line .= custom_data('postgres') . "\n"; - $line .= "COMMIT;\n\n"; - break; - } - - fwrite($fp, $line); - fclose($fp); -} - -/** -* Data put into the header for various dbms -*/ -function custom_data($dbms) -{ - switch ($dbms) - { - case 'oracle': - return << LOWER($2)' LANGUAGE SQL STRICT; -CREATE FUNCTION _varchar_ci_greater_equals(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) >= LOWER($2)' LANGUAGE SQL STRICT; - -/* - Operators -*/ -CREATE OPERATOR <( - PROCEDURE = _varchar_ci_less_than, - LEFTARG = varchar_ci, - RIGHTARG = varchar_ci, - COMMUTATOR = >, - NEGATOR = >=, - RESTRICT = scalarltsel, - JOIN = scalarltjoinsel); - -CREATE OPERATOR <=( - PROCEDURE = _varchar_ci_less_equal, - LEFTARG = varchar_ci, - RIGHTARG = varchar_ci, - COMMUTATOR = >=, - NEGATOR = >, - RESTRICT = scalarltsel, - JOIN = scalarltjoinsel); - -CREATE OPERATOR >( - PROCEDURE = _varchar_ci_greater_than, - LEFTARG = varchar_ci, - RIGHTARG = varchar_ci, - COMMUTATOR = <, - NEGATOR = <=, - RESTRICT = scalargtsel, - JOIN = scalargtjoinsel); - -CREATE OPERATOR >=( - PROCEDURE = _varchar_ci_greater_equals, - LEFTARG = varchar_ci, - RIGHTARG = varchar_ci, - COMMUTATOR = <=, - NEGATOR = <, - RESTRICT = scalargtsel, - JOIN = scalargtjoinsel); - -CREATE OPERATOR <>( - PROCEDURE = _varchar_ci_not_equal, - LEFTARG = varchar_ci, - RIGHTARG = varchar_ci, - COMMUTATOR = <>, - NEGATOR = =, - RESTRICT = neqsel, - JOIN = neqjoinsel); - -CREATE OPERATOR =( - PROCEDURE = _varchar_ci_equal, - LEFTARG = varchar_ci, - RIGHTARG = varchar_ci, - COMMUTATOR = =, - NEGATOR = <>, - RESTRICT = eqsel, - JOIN = eqjoinsel, - HASHES, - MERGES, - SORT1= <); - -EOF; - break; - } - - return ''; -} - -echo 'done'; diff --git a/develop/generate_migrations_data.php b/develop/generate_migrations_data.php deleted file mode 100644 index 175fdbae..00000000 --- a/develop/generate_migrations_data.php +++ /dev/null @@ -1,385 +0,0 @@ -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; -$table_prefix = 'phpbb_'; -require_once $phpbb_root_path . 'includes/constants.php'; -require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx; - -$phpbb_class_loader_mock = new \phpbb\class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php"); -$phpbb_class_loader_mock->register(); -$phpbb_class_loader_ext = new \phpbb\class_loader('\\', $phpbb_root_path . 'ext/', "php"); -$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(); - -function set_config($name, $val) -{ - global $config_entry; - - if (isset($config_entry[$name])) - { - trigger_error('Duplicate entry: ' . $name); - } - - handle_string($val); - - $config_entry[$name] = $val; -} - -function handle_string(&$str) -{ - if (is_string($str) && strpos($str, '$') === 0) - { - // @codingStandardsIgnoreStart - $str = str_replace(',', ' . \',\' . ', $str); - // @codingStandardsIgnoreEnd - } - else if (is_string($str)) - { - $str = "'$str'"; - } - - if (empty($str)) - { - $str = "''"; - } -} - -function set_portal_config($name, $val) -{ - global $portal_config_entry; - - if (isset($portal_config_entry[$name])) - { - trigger_error('Duplicate entry: ' . $name); - } - - handle_string($val); - - // we do not want serialized entries as they are hard to read - if (strpos($val, 'a:') === 1) - { - // cut preceding and appended quote - $val = substr($val, 1, -1); - // start unserializing and building - $val = unserialize($val); - $after_val = 'serialize(array(
'; - foreach ($val as $key => $entry) - { - if (is_array($entry)) - { - $after_val .= ' array(
'; - foreach ($entry as $one => $two) - { - handle_string($one); - handle_string($two); - $after_val .= ' ' . $one . ' => ' . $two . ',
'; - } - $after_val .= ' ),
'; - } - else - { - handle_string($key); - handle_string($entry); - $after_val .= ' ' . $key . ' => ' . $entry . ',
'; - } - } - $after_val .= ' ))'; - $val = $after_val; - } - - $portal_config_entry[$name] = $val; -} - -$db = new db($db_data); -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 '
'; - -echo '

set_portal_config entries for migrations:
';
-foreach ($portal_config_entry as $name => $val)
-{
-	echo '		$this->set_portal_config(\'' . $name . '\', ' . $val . ');
'; -} -echo '
'; - -echo '

database entries:
';
-echo $db_data . '

'; - -/** -* This function will install the basic set of portal modules -* -* only set $purge_modules to false if you already know that the table is empty -* set $u_action to where the user should be redirected after this -* note that already existing data won't be deleted from the config and portal_config -* just to make sure we don't overwrite anything, the IDs won't be reset -* !! this function should usually only be executed once upon installing the portal !! -* DO NOT set $purge_modules to false unless you want to auto-add all modules again after deleting them (i.e. if your database was corrupted) -*/ -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(
'; - - /* - * this is a list of the basic modules that will be installed - * module_name => array(module_column, module_order) - */ - $modules_ary = array( - // left column - 'portal_main_menu' => array(1, 1), - 'portal_stylechanger' => array(1, 2), - 'portal_birthday_list' => array(1, 3), - 'portal_clock' => array(1, 4), - 'portal_search' => array(1, 5), - 'portal_attachments' => array(1, 6), - 'portal_topposters' => array(1, 7), - 'portal_latest_members' => array(1, 8), - 'portal_link_us' => array(1, 9), - - // center column - 'portal_welcome' => array(2, 1), - 'portal_recent' => array(2, 2), - 'portal_announcements' => array(2, 3), - 'portal_news' => array(2, 4), - 'portal_poll' => array(2, 5), - 'portal_whois_online' => array(2, 6), - - // right column - 'portal_user_menu' => array(3, 1), - 'portal_statistics' => array(3, 2), - 'portal_calendar' => array(3, 3), - 'portal_leaders' => array(3, 4), - 'portal_latest_bots' => array(3, 5), - 'portal_links' => array(3, 6), - ); - - foreach ($modules_ary as $module_name => $module_data) - { - $new_module_name = '\\board3\\portal\\modules\\' . str_replace('portal_', '', $module_name); - if (class_exists($new_module_name)) - { - $c_class = $phpbb_container->get('board3.module.' . str_replace('portal_', '', $module_name)); - $module_name = $new_module_name; - } - else - { - $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(); - $module_name = substr($module_name, 7); - } - - $sql_ary = array( - '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_group_ids' => '', - 'module_image_width' => 16, - 'module_image_height' => 16, - 'module_status' => B3_MODULE_ENABLED, - ); - $sql = 'INSERT INTO \' . $this->table_prefix . \'portal_modules ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql, true); - - $data1 = array(); - $data2 = array(); - $db_data .= ' array(
'; - foreach ($sql_ary as $key => $val) - { - $key = (is_string($key)) ? '\'' . $key . '\'' : $key; - $val = (is_string($val)) ? '\'' . $val . '\'' : $val; - $db_data .= ' ' . $key . ' => ' . $val . ',
'; - } - $db_data .= ' ),
'; - $c_class->install($db->sql_id()); - } - $db_data .= ' );'; -} - -class db -{ - // start at 0 - private $sql_id = 0; - - private $id = 0; - - private $int_pointer = 0; - - private $sql_ary = array(); - - private $sql_in_set = array(); - - private $data = array(); - - public function __construct(&$data) - { - $this->data = &$data; - } - public function sql_id() - { - return $this->sql_id; - } - - public function sql_query($sql, $increase = false) - { - if (strpos($sql, 'INSERT') !== false) - { - //$this->data[] = $sql; - } - if ($increase) - { - $this->sql_id++; - } - $this->id++; - $this->sql_ary[$this->id] = $sql; - return $this->id; - } - - public function sql_build_array($type, $ary) - { - $data1 = array(); - $data2 = array(); - foreach ($ary as $key => $val) - { - $data1[] = $key; - $data2[] = (is_string($val)) ? '\'' . $val . '\'' : $val; - } - return '(' . implode(', ', $data1) . ') VALUES (' . implode(', ', $data2) . ');'; - } - - public function sql_in_set($data1, $data2, $bool = -1) - { - $this->sql_in_set[$this->id + 1] = array($data1, $data2); - return '\' . $db->sql_in_set('. $data1 . ', array(' . implode(',', $data2) . (($bool !== -1) ? '), ' . $bool : '') . '))'; - } - - public function sql_fetchrow($id) - { - if (isset($this->sql_ary[$id])) - { - preg_match_all('/SELECT+[a-z0-9A-Z,_ ]+FROM/', $this->sql_ary[$id], $match); - if (!empty($match)) - { - // cut "SELECT " and " FROM" - $match = substr($match[0][0], 7, strlen($match[0][0]) - 5 - 7); - $match = str_replace(', ', ',', $match); - $match = explode(',', $match); - if (isset($this->sql_in_set[$id][1][$this->int_pointer])) - { - $ret = array(); - foreach ($match as $key) - { - if ($key == $this->sql_in_set[$id][0]) - { - $ret[$key] = $this->sql_in_set[$id][1][$this->int_pointer]; - } - else - { - $ret[$key] = "{foobar.{$key}.{$this->sql_in_set[$id][1][$this->int_pointer]}}"; - } - } - $this->int_pointer++; - return $this->preg_replace_value($ret); - } - } - } - else - { - 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 deleted file mode 100644 index a9eda74f..00000000 --- a/develop/phpbb_functions.php +++ /dev/null @@ -1,47 +0,0 @@ - {TABLE_DATA}) -* {TABLE_DATA}: -* COLUMNS = array({column_name} = array({column_type}, {default}, {auto_increment})) -* PRIMARY_KEY = {column_name(s)} -* KEYS = array({key_name} = array({key_type}, {column_name(s)})), -* -* Column Types: -* INT:x => SIGNED int(x) -* BINT => BIGINT -* UINT => mediumint(8) UNSIGNED -* UINT:x => int(x) UNSIGNED -* TINT:x => tinyint(x) -* USINT => smallint(4) UNSIGNED (for _order columns) -* BOOL => tinyint(1) UNSIGNED -* VCHAR => varchar(255) -* CHAR:x => char(x) -* XSTEXT_UNI => text for storing 100 characters (topic_title for example) -* STEXT_UNI => text for storing 255 characters (normal input field with a max of 255 single-byte chars) - same as VCHAR_UNI -* TEXT_UNI => text for storing 3000 characters (short text, descriptions, comments, etc.) -* MTEXT_UNI => mediumtext (post text, large text) -* VCHAR:x => varchar(x) -* TIMESTAMP => int(11) UNSIGNED -* DECIMAL => decimal number (5,2) -* DECIMAL: => decimal number (x,2) -* PDECIMAL => precision decimal number (6,3) -* PDECIMAL: => precision decimal number (x,3) -* VCHAR_UNI => varchar(255) BINARY -* VCHAR_CI => varchar_ci for postgresql, others VCHAR -*/ - -/** -* Step 1: Manipulate phpbb's tables -*/ -$schema_data['phpbb_log']['COLUMNS']['album_id'] = array('UINT', 0); -$schema_data['phpbb_log']['COLUMNS']['image_id'] = array('UINT', 0); -$schema_data['phpbb_sessions']['COLUMNS']['session_album_id'] = array('UINT', 0); -$schema_data['phpbb_sessions']['KEYS']['session_aid'] = array('INDEX', 'session_album_id'); - -/** -* Step 2: Add own tables -*/ -$schema_data['phpbb_gallery_albums'] = array( - 'COLUMNS' => array( - 'album_id' => array('UINT', NULL, 'auto_increment'), - 'parent_id' => array('UINT', 0), - 'left_id' => array('UINT', 1), - 'right_id' => array('UINT', 2), - 'album_parents' => array('MTEXT_UNI', ''), - 'album_type' => array('UINT:3', 1), - 'album_status' => array('UINT:1', 1), - 'album_contest' => array('UINT', 0), - 'album_name' => array('VCHAR:255', ''), - 'album_desc' => array('MTEXT_UNI', ''), - 'album_desc_options' => array('UINT:3', 7), - 'album_desc_uid' => array('VCHAR:8', ''), - 'album_desc_bitfield' => array('VCHAR:255', ''), - 'album_user_id' => array('UINT', 0), - 'album_images' => array('UINT', 0), - 'album_images_real' => array('UINT', 0), - 'album_last_image_id' => array('UINT', 0), - 'album_image' => array('VCHAR', ''), - 'album_last_image_time' => array('INT:11', 0), - 'album_last_image_name' => array('VCHAR', ''), - 'album_last_username' => array('VCHAR', ''), - 'album_last_user_colour' => array('VCHAR:6', ''), - 'album_last_user_id' => array('UINT', 0), - 'album_watermark' => array('UINT:1', 1), - 'album_sort_key' => array('VCHAR:8', ''), - 'album_sort_dir' => array('VCHAR:8', ''), - 'display_in_rrc' => array('UINT:1', 1), - 'display_on_index' => array('UINT:1', 1), - 'display_subalbum_list' => array('UINT:1', 1), - 'album_feed' => array('BOOL', 1), - 'album_auth_access' => array('TINT:1', 0), - ), - 'PRIMARY_KEY' => 'album_id', -); - -$schema_data['phpbb_gallery_albums_track'] = array( - 'COLUMNS' => array( - 'user_id' => array('UINT', 0), - 'album_id' => array('UINT', 0), - 'mark_time' => array('TIMESTAMP', 0), - ), - 'PRIMARY_KEY' => array('user_id', 'album_id'), -); - -$schema_data['phpbb_gallery_comments'] = array( - 'COLUMNS' => array( - 'comment_id' => array('UINT', NULL, 'auto_increment'), - 'comment_image_id' => array('UINT', NULL), - 'comment_user_id' => array('UINT', 0), - 'comment_username' => array('VCHAR', ''), - 'comment_user_colour' => array('VCHAR:6', ''), - 'comment_user_ip' => array('VCHAR:40', ''), - 'comment_signature' => array('BOOL', 0), - 'comment_time' => array('UINT:11', 0), - 'comment' => array('MTEXT_UNI', ''), - 'comment_uid' => array('VCHAR:8', ''), - 'comment_bitfield' => array('VCHAR:255', ''), - 'comment_edit_time' => array('UINT:11', 0), - 'comment_edit_count' => array('USINT', 0), - 'comment_edit_user_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'comment_id', - 'KEYS' => array( - 'id' => array('INDEX', 'comment_image_id'), - 'uid' => array('INDEX', 'comment_user_id'), - 'ip' => array('INDEX', 'comment_user_ip'), - 'time' => array('INDEX', 'comment_time'), - ), -); - -$schema_data['phpbb_gallery_contests'] = array( - 'COLUMNS' => array( - 'contest_id' => array('UINT', NULL, 'auto_increment'), - 'contest_album_id' => array('UINT', 0), - 'contest_start' => array('UINT:11', 0), - 'contest_rating' => array('UINT:11', 0), - 'contest_end' => array('UINT:11', 0), - 'contest_marked' => array('TINT:1', 0), - 'contest_first' => array('UINT', 0), - 'contest_second' => array('UINT', 0), - 'contest_third' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'contest_id', -); - -$schema_data['phpbb_gallery_favorites'] = array( - 'COLUMNS' => array( - 'favorite_id' => array('UINT', NULL, 'auto_increment'), - 'user_id' => array('UINT', 0), - 'image_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'favorite_id', - 'KEYS' => array( - 'uid' => array('INDEX', 'user_id'), - 'id' => array('INDEX', 'image_id'), - ), -); - -$schema_data['phpbb_gallery_images'] = array( - 'COLUMNS' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'image_filename' => array('VCHAR:255', ''), - 'image_name' => array('VCHAR:255', ''), - 'image_name_clean' => array('VCHAR:255', ''), - 'image_desc' => array('MTEXT_UNI', ''), - 'image_desc_uid' => array('VCHAR:8', ''), - 'image_desc_bitfield' => array('VCHAR:255', ''), - 'image_user_id' => array('UINT', 0), - 'image_username' => array('VCHAR:255', ''), - 'image_username_clean' => array('VCHAR:255', ''), - 'image_user_colour' => array('VCHAR:6', ''), - 'image_user_ip' => array('VCHAR:40', ''), - 'image_time' => array('UINT:11', 0), - 'image_album_id' => array('UINT', 0), - 'image_view_count' => array('UINT:11', 0), - 'image_status' => array('UINT:3', 0), - 'image_contest' => array('UINT:1', 0), - 'image_contest_end' => array('TIMESTAMP', 0), - 'image_contest_rank' => array('UINT:3', 0), - 'image_filemissing' => array('UINT:3', 0), - 'image_has_exif' => array('UINT:3', 2), - 'image_exif_data' => array('TEXT', ''), - 'image_rates' => array('UINT', 0), - 'image_rate_points' => array('UINT', 0), - 'image_rate_avg' => array('UINT', 0), - 'image_comments' => array('UINT', 0), - 'image_last_comment' => array('UINT', 0), - 'image_allow_comments' => array('TINT:1', 1), - 'image_favorited' => array('UINT', 0), - 'image_reported' => array('UINT', 0), - 'filesize_upload' => array('UINT:20', 0), - 'filesize_medium' => array('UINT:20', 0), - 'filesize_cache' => array('UINT:20', 0), - ), - 'PRIMARY_KEY' => 'image_id', - 'KEYS' => array( - 'aid' => array('INDEX', 'image_album_id'), - 'uid' => array('INDEX', 'image_user_id'), - 'time' => array('INDEX', 'image_time'), - ), -); - -$schema_data['phpbb_gallery_modscache'] = array( - 'COLUMNS' => array( - 'album_id' => array('UINT', 0), - 'user_id' => array('UINT', 0), - 'username' => array('VCHAR', ''), - 'group_id' => array('UINT', 0), - 'group_name' => array('VCHAR', ''), - 'display_on_index' => array('TINT:1', 1), - ), - 'KEYS' => array( - 'doi' => array('INDEX', 'display_on_index'), - 'aid' => array('INDEX', 'album_id'), - ), -); - -$schema_data['phpbb_gallery_permissions'] = array( - 'COLUMNS' => array( - 'perm_id' => array('UINT', NULL, 'auto_increment'), - 'perm_role_id' => array('UINT', 0), - 'perm_album_id' => array('UINT', 0), - 'perm_user_id' => array('UINT', 0), - 'perm_group_id' => array('UINT', 0), - 'perm_system' => array('INT:3', 0), - ), - 'PRIMARY_KEY' => 'perm_id', -); - -$schema_data['phpbb_gallery_rates'] = array( - 'COLUMNS' => array( - 'rate_image_id' => array('UINT', 0), - 'rate_user_id' => array('UINT', 0), - 'rate_user_ip' => array('VCHAR:40', ''), - 'rate_point' => array('UINT:3', 0), - ), - 'PRIMARY_KEY' => array('rate_image_id', 'rate_user_id'), -); - -$schema_data['phpbb_gallery_reports'] = array( - 'COLUMNS' => array( - 'report_id' => array('UINT', NULL, 'auto_increment'), - 'report_album_id' => array('UINT', 0), - 'report_image_id' => array('UINT', 0), - 'reporter_id' => array('UINT', 0), - 'report_manager' => array('UINT', 0), - 'report_note' => array('MTEXT_UNI', ''), - 'report_time' => array('UINT:11', 0), - 'report_status' => array('UINT:3', 0), - ), - 'PRIMARY_KEY' => 'report_id', -); - -$schema_data['phpbb_gallery_roles'] = array( - 'COLUMNS' => array( - 'role_id' => array('UINT', NULL, 'auto_increment'), - 'a_list' => array('UINT:3', 0), - 'i_view' => array('UINT:3', 0), - 'i_watermark' => array('UINT:3', 0), - 'i_upload' => array('UINT:3', 0), - 'i_edit' => array('UINT:3', 0), - 'i_delete' => array('UINT:3', 0), - 'i_rate' => array('UINT:3', 0), - 'i_approve' => array('UINT:3', 0), - 'i_lock' => array('UINT:3', 0), - 'i_report' => array('UINT:3', 0), - 'i_count' => array('UINT', 0), - 'i_unlimited' => array('UINT:3', 0), - 'c_read' => array('UINT:3', 0), - 'c_post' => array('UINT:3', 0), - 'c_edit' => array('UINT:3', 0), - 'c_delete' => array('UINT:3', 0), - 'm_comments' => array('UINT:3', 0), - 'm_delete' => array('UINT:3', 0), - 'm_edit' => array('UINT:3', 0), - 'm_move' => array('UINT:3', 0), - 'm_report' => array('UINT:3', 0), - 'm_status' => array('UINT:3', 0), - 'a_count' => array('UINT', 0), - 'a_unlimited' => array('UINT:3', 0), - 'a_restrict' => array('UINT:3', 0), - ), - 'PRIMARY_KEY' => 'role_id', -); - -$schema_data['phpbb_gallery_users'] = array( - 'COLUMNS' => array( - 'user_id' => array('UINT', 0), - 'watch_own' => array('UINT:3', 0), - 'watch_favo' => array('UINT:3', 0), - 'watch_com' => array('UINT:3', 0), - 'user_images' => array('UINT', 0), - 'personal_album_id' => array('UINT', 0), - 'user_lastmark' => array('TIMESTAMP', 0), - 'user_last_update' => array('TIMESTAMP', 0), - 'user_viewexif' => array('UINT:1', 0), - 'user_permissions' => array('MTEXT_UNI', ''), - 'user_permissions_changed' => array('TIMESTAMP', 0), - 'user_allow_comments' => array('TINT:1', 1), - 'subscribe_pegas' => array('TINT:1', 0), - ), - 'PRIMARY_KEY' => 'user_id', - 'KEYS' => array( - 'pega' => array('INDEX', array('personal_album_id')), - ), -); - -$schema_data['phpbb_gallery_watch'] = array( - 'COLUMNS' => array( - 'watch_id' => array('UINT', NULL, 'auto_increment'), - 'album_id' => array('UINT', 0), - 'image_id' => array('UINT', 0), - 'user_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'watch_id', - 'KEYS' => array( - 'uid' => array('INDEX', 'user_id'), - 'id' => array('INDEX', 'image_id'), - 'aid' => array('INDEX', 'album_id'), - ), -); diff --git a/includes/constants.php b/includes/constants.php index 4bdc73f1..e503e773 100644 --- a/includes/constants.php +++ b/includes/constants.php @@ -7,18 +7,9 @@ * */ -if (!defined('IN_PHPBB')) -{ - exit; -} - -global $table_prefix; - // Config constants define('B3_MODULE_DISABLED', 0); define('B3_MODULE_ENABLED', 1); // Tables and paths define('PORTAL_ROOT_PATH', 'portal/'); -define('PORTAL_MODULES_TABLE', $table_prefix . 'portal_modules'); -define('PORTAL_CONFIG_TABLE', $table_prefix . 'portal_config'); diff --git a/includes/functions.php b/includes/functions.php index fd073829..57ef2a72 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -7,11 +7,6 @@ * */ -if (!defined('IN_PHPBB') && !defined('UMIL_AUTO') && !defined('IN_INSTALL')) -{ - exit; -} - // Get portal config function obtain_portal_config() { @@ -102,7 +97,7 @@ function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_pos $posts = $update_count = array(); $post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400); - $forum_from = (strpos($forum_from, ',') !== FALSE) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); + $forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); $str_where = ''; $topic_icons = array(0); $have_icons = 0; @@ -410,21 +405,14 @@ function character_limit(&$title, $limit = 0) */ function get_sub_taged_string($message, $bbcode_uid, $length) { - global $portal_root_path, $phpEx; - - if(!class_exists('phpbb_trim_message')) + if (class_exists('\nickvergessen\trimmessage\trim_message')) { - include($portal_root_path . 'includes/trim_message/trim_message.' . $phpEx); + $trim = new \nickvergessen\trimmessage\trim_message($message, $bbcode_uid, $length); + $message = $trim->message(); + unset($trim); } - if(!class_exists('phpbb_trim_message_bbcodes')) - { - include($portal_root_path . 'includes/trim_message/bbcodes.' . $phpEx); - } - - $object = new phpbb_trim_message($message, $bbcode_uid, $length); - // Ready to get parsed: - return $object->message(); + return $message; } function ap_validate($str) @@ -440,7 +428,7 @@ function generate_portal_pagination($base_url, $num_items, $per_page, $start_ite { global $template, $user; - switch($type) + switch ($type) { case "announcements": $pagination_type = 'ap'; diff --git a/includes/functions_modules.php b/includes/functions_modules.php index 3f5e83ac..78196106 100644 --- a/includes/functions_modules.php +++ b/includes/functions_modules.php @@ -7,11 +7,6 @@ * */ -if (!defined('IN_PHPBB')) -{ - exit; -} - function column_num_string($column) { switch ($column) diff --git a/includes/functions_upload.php b/includes/functions_upload.php index 6d69d510..9b9b6771 100644 --- a/includes/functions_upload.php +++ b/includes/functions_upload.php @@ -7,10 +7,7 @@ * */ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace board3\portal\includes; /** * @ignore diff --git a/includes/mod_version_check.php b/includes/mod_version_check.php index da4cf1bf..a8d14fc7 100644 --- a/includes/mod_version_check.php +++ b/includes/mod_version_check.php @@ -9,15 +9,6 @@ namespace board3\portal\includes; -/** -* @ignore -*/ - -if (!defined('IN_PHPBB')) -{ - exit; -} - class mod_version_check { /** diff --git a/includes/trim_message/bbcodes.php b/includes/trim_message/bbcodes.php deleted file mode 100644 index 63100d17..00000000 --- a/includes/trim_message/bbcodes.php +++ /dev/null @@ -1,490 +0,0 @@ - -* @package trim_message -* @copyright 2011 -* @license http://opensource.org/licenses/gpl-license.php GNU Public License -* @version 1.1 -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** -* phpbb_trim_message_bbcodes class -*/ -class phpbb_trim_message_bbcodes -{ - /** - * Some BBCodes, such as img and flash should not be split up in their middle. - * So I added a sensitive BBCode array which protects BBCodes from being split. - * You can also need to add your custom bbcodes in here. - */ - private $sensitive_bbcodes = array('url', 'flash', 'flash=', 'attachment', 'attachment=', 'img', 'email', 'email='); - private $is_sensitive = false; - - /** - * Variables - */ - private $message = ''; - private $bbcode_uid = ''; - private $bbcode_list = array(); - private $array_size = 0; - private $max_content_length = 0; - private $cur_content_length = 0; - private $cur_position = 0; - public $trim_position = 0; - public $is_trimmed = false; - - /** - * Constructor - * - * @param string $message parsed message you want to trim - * @param string $bbcode_uid bbcode_uid of the post - */ - public function __construct($message, $bbcode_uid, $content_length) - { - $this->message = $message; - $this->bbcode_uid = $bbcode_uid; - $this->max_content_length = $content_length; - $this->array_size = 0; - } - - public function get_bbcodes() - { - $bbcode_end_length = utf8_strlen(':' . $this->bbcode_uid . ']'); - $quote_end_length = utf8_strlen('":' . $this->bbcode_uid . ']'); - - $possible_bbcodes = explode('[', $this->message); - $content_length = $this->get_content_length($possible_bbcodes[0]); - if ($content_length >= $this->max_content_length) - { - $allowed_content_position = $this->get_content_position($possible_bbcodes[0], $this->max_content_length); - $this->trim_position = $this->cur_position + $allowed_content_position; - // As we did not touch any bbcodes yet, we can just skip all that. - if (!$this->max_content_length || ($content_length > $this->max_content_length)) - { - $this->is_trimmed = true; - } - return; - } - $this->cur_position += utf8_strlen($possible_bbcodes[0]) + 1; - $this->cur_content_length += $content_length; - - // Skip the first one. - array_shift($possible_bbcodes); - $num_possible_bbcodes = sizeof($possible_bbcodes); - $num_tested_bbcodes = 0; - $start_of_last_part = 0; - - $allow_close_quote = false; - - foreach ($possible_bbcodes as $part) - { - $num_tested_bbcodes++; - $exploded_parts = explode(':' . $this->bbcode_uid . ']', $part); - $num_parts = sizeof($exploded_parts); - - /** - * One element means we do not match an end before the next opening: - * String: [quote="[bbcode:uid]foobar[/bbcode:uid]":uid] - * Keys: ^^^^^^^ = 0 - */ - if ($num_parts == 1) - { - // 1 means, we are in [quote="":uid] and found another bbcode here. - if (utf8_strpos($exploded_parts[0], 'quote="') === 0) - { - $open_end_quote = utf8_strpos($this->message, '":' . $this->bbcode_uid . ']', $this->cur_position); - if ($open_end_quote !== false) - { - $close_quote = utf8_strpos($this->message, '[/quote:' . $this->bbcode_uid . ']', $open_end_quote); - if ($close_quote !== false) - { - $open_end_quote += $quote_end_length; - $this->open_bbcode('quote', $this->cur_position); - $this->bbcode_action('quote', 'open_end', $open_end_quote); - $this->cur_position += utf8_strlen($exploded_parts[0]); - - // We allow the 3-keys special-case, when we have found a beginning before... - $allow_close_quote = true; - } - } - } - // Or the user just used a normal [ in his post. - else - { - $this->cur_content_length++; - $content_length = $this->get_content_length($exploded_parts[0]); - $max_content_allowed = ($this->max_content_length - $this->cur_content_length); - if (($content_length >= $max_content_allowed) && !$this->trim_position) - { - $allowed_content_position = $this->get_content_position($exploded_parts[0], $max_content_allowed); - $this->trim_position = $this->cur_position + $allowed_content_position; - } - $this->cur_content_length += $content_length; - $this->cur_position += utf8_strlen($exploded_parts[0]); - } - } - /** - * Two element is the normal case: - * String: [bbcode:uid]foobar - * Keys: ^^^^^^ = 0 ^^^^^^ = 1 - * String: [/bbcode:uid]foobar - * Keys: ^^^^^^^ = 0 ^^^^^^ = 1 - */ - elseif ($num_parts == 2) - { - /** - * We found an opening bracket in the quoted username which is not a bbcode - * String: [quote="odd[name":uid]quote-text - * Keys: ^^^^^ = 0 ^^^^^^^^^^ = 1 - */ - if ($allow_close_quote && (utf8_substr($exploded_parts[0], -6) == '"')) - { - $this->cur_position += utf8_strlen($exploded_parts[0]) + $bbcode_end_length; - - $content_length = $this->get_content_length($exploded_parts[1]); - $max_content_allowed = ($this->max_content_length - $this->cur_content_length); - if (($content_length >= $max_content_allowed) && !$this->trim_position) - { - $allowed_content_position = $this->get_content_position($exploded_parts[1], $max_content_allowed); - $this->trim_position = $this->cur_position + $allowed_content_position; - } - $this->cur_content_length += $content_length; - $this->cur_position += utf8_strlen($exploded_parts[1]); - $allow_close_quote = false; - } - // We matched something ;) - else if ($exploded_parts[0][0] != '/') - { - // Open BBCode-tag - $bbcode_tag = $this->filter_bbcode_tag($exploded_parts[0]); - $bbcode_tag_extended = $this->filter_bbcode_tag($exploded_parts[0], false, false); - if (in_array($bbcode_tag_extended, $this->sensitive_bbcodes)) - { - $this->is_sensitive = true; - } - - $this->open_bbcode($bbcode_tag, $this->cur_position); - $this->cur_position += utf8_strlen($exploded_parts[0]) + $bbcode_end_length; - $this->bbcode_action($bbcode_tag, 'open_end', $this->cur_position); - - if (!$allow_close_quote && !$this->is_sensitive) - { - // If we allow a closing quote, we are in the username. - // We do not count that as content-length. - $content_length = $this->get_content_length($exploded_parts[1]); - $max_content_allowed = ($this->max_content_length - $this->cur_content_length); - if (($content_length >= $max_content_allowed) && !$this->trim_position) - { - $allowed_content_position = $this->get_content_position($exploded_parts[1], $max_content_allowed); - $this->trim_position = $this->cur_position + $allowed_content_position; - } - $this->cur_content_length += $content_length; - } - $this->cur_position += utf8_strlen($exploded_parts[1]); - } - else - { - // Close BBCode-tag - $bbcode_tag = $this->filter_bbcode_tag($exploded_parts[0]); - $bbcode_tag_extended = $this->filter_bbcode_tag($exploded_parts[0], false); - if ($bbcode_tag_extended == $bbcode_tag) - { - $bbcode_tag_extended = ''; - } - $this->is_sensitive = false; - - $this->bbcode_action($bbcode_tag, 'close_start', $this->cur_position); - $this->cur_position += utf8_strlen($exploded_parts[0]) + $bbcode_end_length; - $this->bbcode_action($bbcode_tag, 'close_end', $this->cur_position, $bbcode_tag_extended); - - if (!$allow_close_quote) - { - // If we allow a closing quote, we are in the username. - // We do not count that as content-length. - $content_length = $this->get_content_length($exploded_parts[1]); - $max_content_allowed = ($this->max_content_length - $this->cur_content_length); - if (($content_length >= $max_content_allowed) && !$this->trim_position) - { - $allowed_content_position = $this->get_content_position($exploded_parts[1], $max_content_allowed); - $this->trim_position = $this->cur_position + $allowed_content_position; - } - $this->cur_content_length += $content_length; - } - $this->cur_position += utf8_strlen($exploded_parts[1]); - } - } - /** - * Three elements means we are closing the opening-quote and the BBCode from inside: - * String: [quote="[bbcode:uid]foo[/bbcode:uid]bar":uid]quotehere - * Keys: ^^^^^^^ = 0 ^^^^ = 1 ^^^^^^^^^ = 2 - */ - elseif ($num_parts == 3) - { - if (($exploded_parts[0][0] == '/') && (utf8_substr($exploded_parts[1], -6) == '"') && $allow_close_quote) - { - $bbcode_tag = $this->filter_bbcode_tag($exploded_parts[0]); - - $this->bbcode_action($bbcode_tag, 'close_start', $this->cur_position); - $this->cur_position += utf8_strlen($exploded_parts[0]) + $bbcode_end_length; - $this->bbcode_action($bbcode_tag, 'close_end', $this->cur_position); - $this->cur_position += utf8_strlen($exploded_parts[1]) + $bbcode_end_length; - - $content_length = $this->get_content_length($exploded_parts[2]); - $max_content_allowed = ($this->max_content_length - $this->cur_content_length); - if (($content_length >= $max_content_allowed) && !$this->trim_position) - { - $allowed_content_position = $this->get_content_position($exploded_parts[2], $max_content_allowed); - $this->trim_position = $this->cur_position + $allowed_content_position; - } - $this->cur_position += utf8_strlen($exploded_parts[2]); - $this->cur_content_length += $content_length; - - $allow_close_quote = false; - } - } - - // Increase by one for the [ we explode on. - $this->cur_position++; - } - - if ($this->cur_content_length > $this->max_content_length) - { - $this->is_trimmed = true; - } - } - - /** - * Add a bbcode to the bbcode-list - * - * @param string $tag BBCode-tag, Exp: code - * @param int $open_start start-position of the bbcode-open-tag - * (Exp: >[bbcode_list[] = array( - 'bbcode_tag' => $tag, - 'open_start' => $open_start, - 'open_end' => 0, - 'close_start' => 0, - 'close_end' => 0, - ); - $this->array_size++; - } - - /** - * Add position to a listed bbcode - * - * @param string $tag BBCode-tag, Exp: code - * @param string $part part can be one of the following: - * i) open_end => [code>]<[/code] - * ii) close_open => [code]>[ [code][/code>]< - * @param int $position start-position of the bbcode-open-tag - * @param int $tag_extended with the list-bbcode we get some - * information about the bbcode at the end - * of it. So we need to readd that. - */ - private function bbcode_action($tag, $part, $position, $tag_extended = false) - { - for ($i = 1; $i <= $this->array_size; $i++) - { - if ($this->bbcode_list[$this->array_size - $i]['bbcode_tag'] == $tag) - { - if (!$this->bbcode_list[$this->array_size - $i][$part]) - { - $this->bbcode_list[$this->array_size - $i][$part] = $position; - if ($tag_extended) - { - $this->bbcode_list[$this->array_size - $i]['bbcode_tag'] = $tag_extended; - } - return; - } - } - } - } - - /** - * Removes all BBcodes after a given position - */ - public function remove_bbcodes_after() - { - for ($i = 1; $i <= $this->array_size; $i++) - { - if ($this->bbcode_list[$this->array_size - $i]['open_start'] >= $this->trim_position) - { - unset($this->bbcode_list[$this->array_size - $i]); - } - } - - $this->array_size = sizeof($this->bbcode_list); - } - - /** - * Returns an array with BBCodes that need to be closed, after the position. - */ - public function get_open_bbcodes_after($position) - { - $bbcodes = array(); - for ($i = 1; $i <= $this->array_size; $i++) - { - if (($this->bbcode_list[$this->array_size - $i]['open_start'] < $position) && - ($this->bbcode_list[$this->array_size - $i]['close_start'] >= $position)) - { - $bbcodes[] = $this->bbcode_list[$this->array_size - $i]['bbcode_tag']; - } - } - return $bbcodes; - } - - /** - * Get the length of the content (subtract code for smilie and url parsing) - * - * @param string $content Message to get the content length from - * Exp: text - * Content: ^^^^ - * - * @return int length of content without special markup - */ - static public function get_content_length($content) - { - $content_length = utf8_strlen($content); - $last_smiley = false; - $last_html_opening = $last_html_closing = 0; - while (($last_html_opening = utf8_strpos($content, '<', $last_html_closing)) !== false) - { - $last_html_closing = utf8_strpos($content, '>', $last_html_opening); - /** - * Abort while loop if there are no more ">" or we'll end up in an - * endless loop. The abort needs to be done here or the following - * code will produce incorrect data. - */ - if (!$last_html_closing) - { - break; - } - - if (($smiley_code = utf8_substr($content, $last_html_opening + 7, ($last_html_closing - $last_html_opening - 11))) != '--') - { - if ($last_smiley == $smiley_code) - { - $content_length += utf8_strlen($smiley_code); - $last_smiley = false; - } - else - { - $last_smiley = $smiley_code; - } - } - $content_length -= ($last_html_closing - $last_html_opening) + 1; - } - return $content_length; - } - - /** - * Get the position in the text, where we need to cut the message. - * - * Exp: sampletext AL = 8 - * Content: ^^^^^^^^^^^^^^^^ Text-Position = 16 - * - * @param string $content Message to get the position in - * @param int $allowed_length Content length we are allowed to add. - * - * @return int position in the markup-text where we cut the text - */ - static public function get_content_position($content, $allowed_length) - { - if (utf8_strpos(utf8_substr($content, 0, $allowed_length), '<') === false) - { - /** - * If we did not find any HTML in our section, we can cut it. - * Exp: sampletext AL = 3 - * Content: ^^^ Text-Position = 3 - */ - return $allowed_length; - } - - $content_length = $allowed_length; - $start_position = 0; - $last_smiley = false; - while (($last_html_opening = utf8_strpos(utf8_substr($content, 0, $content_length), '<', $start_position)) !== false) - { - // foreach markup we find in the string, we enlarge our text-size. - $last_html_closing = utf8_strpos($content, '>', $last_html_opening); - /** - * Abort while loop if there are no more ">" or the following code - * will produce incorrect data and additionally produce a PHP Notice. - */ - if (!$last_html_closing) - { - break; - } - - $content_length += ($last_html_closing - $last_html_opening) + 1; - - $smiley_code = utf8_substr($content, $last_html_opening + 7, ($last_html_closing - $last_html_opening - 11)); - if (($smiley_code != '--') && (utf8_strpos($smiley_code, 'c="{SMILIES_PATH}/') === false)) - { - if ($last_smiley == $smiley_code) - { - $content_length -= utf8_strlen($smiley_code); - $last_smiley = false; - } - else - { - $last_smiley = $smiley_code; - } - } - - $start_position = $last_html_opening + 1; - } - - return $content_length; - } - - /** - * Filter BBCode-Tags: - * - * Exp: [/*:m] <= automatically added end of [*] - * Exp: [/list:x] <= end of [list] tag with list-style-element - * Exp: [bbcode=param1;param2] <= start of bbcode-tag with parameters - * - * @return string plain bbcode-tag - */ - static public function filter_bbcode_tag($bbcode_tag, $strip_information = true, $strip_equal = true) - { - if ($bbcode_tag[0] == '/') - { - $bbcode_tag = utf8_substr($bbcode_tag, 1); - } - - if ($strip_information && ($bbcode_tag == '*:m')) - { - return '*'; - } - - if ($strip_information && (utf8_substr($bbcode_tag, 0, 5) == 'list:')) - { - return 'list'; - } - - if (($strip_information || !$strip_equal) && (($equals = utf8_strpos($bbcode_tag, '=')) !== false)) - { - $bbcode_tag = utf8_substr($bbcode_tag, 0, (!$strip_equal) ? $equals + 1 : $equals); - } - - return $bbcode_tag; - } -} diff --git a/includes/trim_message/trim_message.php b/includes/trim_message/trim_message.php deleted file mode 100644 index d9c3d436..00000000 --- a/includes/trim_message/trim_message.php +++ /dev/null @@ -1,190 +0,0 @@ - -* @package trim_message -* @copyright 2011 -* @license http://opensource.org/licenses/gpl-license.php GNU Public License -* @version 1.0 -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** -* phpbb_trim_message class -*/ -class phpbb_trim_message -{ - /** - * Variables - */ - private $message = ''; - private $trimmed_message = ''; - private $bbcode_uid = ''; - private $append_str = ''; - private $length = 0; - private $length_tolerance = 0; - private $is_trimmed = null; - private $bbcodes = null; - - /** - * Constructor - * - * @param string $message parsed message you want to trim - * @param string $bbcode_uid bbcode_uid of the post - * @param int $length length the code should be trimmed to - * @param string $append_str text that is appended after trimmed message - * @param int $tolerance tolerance for the message: we don't trim it - * if it is shorter than length + tolerance. - */ - public function __construct($message, $bbcode_uid, $length, $append_str = ' [...]', $tolerance = 25) - { - $this->message = $message; - $this->bbcode_uid = $bbcode_uid; - $this->append_str = $append_str; - $this->length = (int) $length; - $this->length_tolerance = (int) $tolerance; - } - - /** - * Did we trim the message, or was it short enough? - */ - public function is_trimmed() - { - return (bool) $this->is_trimmed; - } - - /** - * Returns the message, trimmed or in full length - */ - public function message($force_full_length = false) - { - if (is_null($this->is_trimmed) && !$force_full_length) - { - $this->is_trimmed = $this->trim(); - } - - return ($this->is_trimmed && !$force_full_length) ? $this->trimmed_message : $this->message; - } - - /** - * Filter some easy cases where we can return the result easily - * - * @return bool Returns whether the message was trimmed or not. - */ - private function trim() - { - if (utf8_strlen($this->message) <= ($this->length + $this->length_tolerance)) - { - return false; - } - - if (!$this->bbcode_uid) - { - $this->trimmed_message = utf8_substr($this->message, 0, $this->length) . $this->append_str; - return true; - } - - $this->trim_action(); - return $this->bbcodes->is_trimmed; - } - - /** - * Do some magic... uhhh - */ - private function trim_action() - { - /** - * Prepare the difficult action - */ - $this->trimmed_message = $this->message; - $this->bbcodes = new phpbb_trim_message_bbcodes($this->trimmed_message, $this->bbcode_uid, $this->length); - - /** - * Step 1: Get a list of all BBCodes - */ - $this->bbcodes->get_bbcodes(); - - /** - * Step 2: Remove all bbcodes from the list, that are opened after - * the trim-position - */ - $this->bbcodes->remove_bbcodes_after(); - - /** - * Step 3: Trim message - */ - $this->trimmed_message = utf8_substr($this->message, 0, $this->bbcodes->trim_position); - - /** - * Step 4: i) Remove links/emails/smilies that are cut, somewhere - * in the middle - * ii) Renew trim-position if we did something - * iii) Append the message that is provided - */ - $this->remove_broken_links(); - $text_length = utf8_strlen($this->trimmed_message); - if ($this->bbcodes->is_trimmed) - { - $this->trimmed_message .= $this->append_str; - } - - /** - * Step 5: Close open BBCodes - */ - $open_bbcodes = $this->bbcodes->get_open_bbcodes_after($text_length); - $this->close_bbcodes($open_bbcodes); - } - - /** - * Removes broken smilies, emails and links without the URL-tag. - */ - private function remove_broken_links() - { - $open_brakets = substr_count($this->trimmed_message, '<'); - $closing_brakets = substr_count($this->trimmed_message, '>'); - if ($open_brakets != $closing_brakets) - { - /** - * There was an open braket for an unparsed link - * Example: <{cut}!-- l --> - */ - $this->trimmed_message = utf8_substr($this->trimmed_message, 0, utf8_strrpos($this->trimmed_message, '<')); - } - - $open_link = substr_count($this->trimmed_message, '{cut} - */ - $this->trimmed_message = utf8_substr($this->trimmed_message, 0, utf8_strrpos($this->trimmed_message, '