From 52045ff2631cdfa14efd3379b64843cafd00df8f Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 19 Jun 2006 21:30:32 +0000 Subject: some bugfixes git-svn-id: file:///svn/phpbb/trunk@6104 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7b36c36548..9115ac2b6a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -429,13 +429,18 @@ function style_select($default = '', $all = false) /** * Pick a timezone */ -function tz_select($default = '') +function tz_select($default = '', $truncate = false) { global $sys_timezone, $user; $tz_select = ''; foreach ($user->lang['tz_zones'] as $offset => $zone) { + if ($truncate) + { + $zone = (strlen($zone) > 70) ? substr($zone, 0, 70) . '...' : $zone; + } + if (is_numeric($offset)) { $selected = ($offset == $default) ? ' selected="selected"' : ''; -- cgit v1.2.1 From 725b21f2d206efb4b34eb95ec3329bc81f66b805 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 22 Jun 2006 15:14:03 +0000 Subject: time to squash some bugs git-svn-id: file:///svn/phpbb/trunk@6114 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9115ac2b6a..1c631469cb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2658,7 +2658,7 @@ function page_header($page_title = '', $display_online_list = true) { header('Content-type: text/html; charset=' . $user->lang['ENCODING']); } - header('Cache-Control: private, no-cache="set-cookie", pre-check=0, post-check=0'); + header('Cache-Control: private, no-cache="set-cookie"'); header('Expires: 0'); header('Pragma: no-cache'); -- cgit v1.2.1 From 9c31a05b1c1fba2b1704996f0ed33cb451f13aa7 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 23 Jun 2006 14:04:41 +0000 Subject: make sure set_config is called with the correct is_dynamic value git-svn-id: file:///svn/phpbb/trunk@6117 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 1c631469cb..92410f2c1c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -145,7 +145,7 @@ function unique_id($extra = 'c') if ($dss_seeded !== true) { - set_config('rand_seed', $config['rand_seed']); + set_config('rand_seed', $config['rand_seed'], true); $dss_seeded = true; } -- cgit v1.2.1 From 3439d0f96e4deeecc2e681e08bf66b7c70f01930 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sat, 24 Jun 2006 13:27:04 +0000 Subject: ok, first attempt at solving some compatibility issues. - dropping in replacement for realpath git-svn-id: file:///svn/phpbb/trunk@6122 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 75 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 92410f2c1c..0a2778defe 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -376,6 +376,71 @@ if (!function_exists('stripos')) } } +if (!function_exists('realpath')) +{ + /** + * Replacement for realpath if it is disabled + * This function is from the php manual by nospam at savvior dot com + */ + function phpbb_realpath($path) + { + $translated_path = getenv('PATH_TRANSLATED'); + + $translated_path = str_replace('\\', '/', $translated_path); + $translated_path = str_replace(basename(getenv('PATH_INFO')), '', $translated_path); + + $translated_path .= '/'; + + if ($path == '.' || $path == './') + { + return $translated_path; + } + + // now check for back directory + $translated_path .= $path; + + $dirs = explode('/', $translated_path); + + foreach ($dirs as $key => $value) + { + if ($value == '..') + { + $dirs[$key] = ''; + $dirs[$key - 2] = ''; + } + } + + $translated_path = ''; + + foreach($dirs as $key => $value) + { + if (strlen($value) > 0) + { + $translated_path .= $value . '/'; + } + } + + $translated_path = substr($translated_path, 0, strlen($translated_path) - 1); + + if (is_dir($translated_path) || is_file($translated_path)) + { + return $translated_path; + } + + return false; + } +} +else +{ + /** + * A wrapper for realpath + */ + function phpbb_realpath($path) + { + return realpath($path); + } +} + // functions used for building option fields /** @@ -1189,8 +1254,8 @@ function redirect($url) else { // Get the realpath of dirname - $root_dirs = explode('/', str_replace('\\', '/', realpath('./'))); - $page_dirs = explode('/', str_replace('\\', '/', realpath($pathinfo['dirname']))); + $root_dirs = explode('/', str_replace('\\', '/', phpbb_realpath('./'))); + $page_dirs = explode('/', str_replace('\\', '/', phpbb_realpath($pathinfo['dirname']))); $intersection = array_intersect_assoc($root_dirs, $page_dirs); $root_dirs = array_diff_assoc($root_dirs, $intersection); @@ -2144,7 +2209,7 @@ function get_backtrace() $output = '
'; $backtrace = debug_backtrace(); - $path = realpath($phpbb_root_path); + $path = phpbb_realpath($phpbb_root_path); foreach ($backtrace as $number => $trace) { @@ -2226,8 +2291,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline) if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false) { // remove complete path to installation, with the risk of changing backslashes meant to be there - $errfile = str_replace(array(realpath($phpbb_root_path), '\\'), array('', '/'), $errfile); - $msg_text = str_replace(array(realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text); + $errfile = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $errfile); + $msg_text = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text); echo '[phpBB Debug] PHP Notice: in file ' . $errfile . ' on line ' . $errline . ': ' . $msg_text . '
' . "\n"; } -- cgit v1.2.1 From 737dea1370d4082fa66b9c459d60f879d1d7ac1b Mon Sep 17 00:00:00 2001 From: Graham Eames Date: Sat, 24 Jun 2006 15:52:17 +0000 Subject: Show message to those browsing whilst board is disabled git-svn-id: file:///svn/phpbb/trunk@6124 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0a2778defe..0ed9e924ea 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2686,6 +2686,7 @@ function page_header($page_title = '', $display_online_list = true) 'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '', 'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS) ? true : false, + 'S_BOARD_DISABLED' => ($config['board_disable'] && !defined('IN_LOGIN') && $auth->acl_gets('a_', 'm_')) ? true : false, 'S_REGISTERED_USER' => $user->data['is_registered'], 'S_USER_PM_POPUP' => $user->optionget('popuppm'), 'S_USER_LANG' => $user->data['user_lang'], -- cgit v1.2.1 From 6df6eb0e601d459544b0cbcee063cf19c01bb37d Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sat, 1 Jul 2006 19:11:52 +0000 Subject: - add additional auth check to the permission roles modules - added new function to return globally used expressions (get_preg_expression($mode)). This should be very helpful in getting wide spread similar checks (regular expressions) to one place reducing the risk of forgetting to change every location if you fix one. ;) We will add additional ones later, at the moment only the email check is retrieved... - added "active module" var to the module class returning the current active module - changed call to image magick - add administrator to global moderators group by default - extend auth_option column a little bit - other bugfixes git-svn-id: file:///svn/phpbb/trunk@6135 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0ed9e924ea..4f62fa3100 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1515,7 +1515,11 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa if ($admin && !$auth->acl_get('a_')) { // Not authd - add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); + // anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions + if ($user->data['is_registered']) + { + add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); + } trigger_error('NO_AUTH_ADMIN'); } @@ -1548,7 +1552,12 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa } else { - add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); + // Only log the failed attempt if a real user tried to. + // anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions + if ($user->data['is_registered']) + { + add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); + } } } @@ -1566,12 +1575,6 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa trigger_error($message . '

' . sprintf($l_redirect, '', '')); } - // The user wanted to re-authenticate, but something failed - log this - if ($admin) - { - add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); - } - // Something failed, determine what... if ($result['status'] == LOGIN_BREAK) { @@ -1950,7 +1953,7 @@ function make_clickable($text, $server_url = false) $magic_url_replace[] = "'\$1' . ((strlen('\$2') > 55) ? substr(str_replace('&', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&', '&', '\$2'), -10) : '\$2') . ''"; // matches an email@domain type address at the start of a line, or after a space or after what might be a BBCode. - $magic_url_match[] = '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.(?:[\w\-\.]+\.)?[\w]+)#ie'; + $magic_url_match[] = '/(^|[\n ]|\()(' . get_preg_expression('email') . ')/ie'; $magic_url_replace[] = "'\$1' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . ''"; } @@ -2254,6 +2257,23 @@ function get_backtrace() return $output; } +/** +* This function returns a regular expression pattern for commonly used expressions +* Use with / as delimiter +* mode can be: email| +*/ +function get_preg_expression($mode) +{ + switch ($mode) + { + case 'email': + return '[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+'; + break; + } + + return ''; +} + // Handler, header and footer /** -- cgit v1.2.1 From 98fc394eb350d55c1876ffe8ce02260113af1368 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 2 Jul 2006 21:42:54 +0000 Subject: - fixed language pack management a bit (supporting backslashes) - fixed ftp_fsock, also fixing a reported bug in there git-svn-id: file:///svn/phpbb/trunk@6139 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4f62fa3100..86f002d14e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2072,26 +2072,41 @@ function extension_allowed($forum_id, $extension, &$extensions) // Little helpers +/** +* Little helper for the build_hidden_fields function +*/ +function _build_hidden_fields($key, $value, $specialchar) +{ + $hidden_fields = ''; + + if (!is_array($value)) + { + $key = ($specialchar) ? htmlspecialchars($key) : $key; + $value = ($specialchar) ? htmlspecialchars($value) : $value; + + $hidden_fields .= '' . "\n"; + } + else + { + foreach ($value as $_key => $_value) + { + $hidden_fields .= _build_hidden_fields($key . '[' . $_key . ']', $_value, $specialchar); + } + } + + return $hidden_fields; +} + /** * Build simple hidden fields from array */ -function build_hidden_fields($field_ary) +function build_hidden_fields($field_ary, $specialchar = false) { $s_hidden_fields = ''; foreach ($field_ary as $name => $vars) { - if (is_array($vars)) - { - foreach ($vars as $key => $value) - { - $s_hidden_fields .= ''; - } - } - else - { - $s_hidden_fields .= ''; - } + $s_hidden_fields .= _build_hidden_fields($name, $vars, $specialchar); } return $s_hidden_fields; -- cgit v1.2.1 From 00508798251f0ebd897b94b360b7426846dab840 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 5 Jul 2006 15:48:43 +0000 Subject: re-check cookie_secure value within generate_board_url() for those users having it enabled but not running on a SSL connection (which of course results in server errors). This should (hopefully) further minimize support requests. ;) Thanks again to aninhill for giving me full access to his board to be able to spot this error. git-svn-id: file:///svn/phpbb/trunk@6147 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 86f002d14e..4185837917 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1165,8 +1165,6 @@ function generate_board_url($without_script_path = false) $server_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'); $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'); - $url = (($config['cookie_secure']) ? 'https://' : 'http://') . $server_name; - // Forcing server vars is the only way to specify/override the protocol if ($config['force_server_vars'] || !$server_name) { @@ -1176,6 +1174,12 @@ function generate_board_url($without_script_path = false) $url = $server_protocol . $server_name; } + else + { + // Do not rely on cookie_secure, users seem to think that it means a secured cookie instead of an encrypted connection + $cookie_secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0; + $url = (($cookie_secure) ? 'https://' : 'http://') . $server_name; + } if ($server_port && (($config['cookie_secure'] && $server_port <> 443) || (!$config['cookie_secure'] && $server_port <> 80))) { -- cgit v1.2.1 From 462dc69b8e8568f4656675b31b99a31ad98e1331 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 6 Jul 2006 16:46:53 +0000 Subject: some bugfixes git-svn-id: file:///svn/phpbb/trunk@6149 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4185837917..50cdd6a121 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1202,15 +1202,12 @@ function redirect($url) { global $db, $cache, $config, $user; - if (isset($db)) + if (empty($user->lang)) { - $db->sql_close(); + $user->add_lang('common'); } - if (isset($cache)) - { - $cache->unload(); - } + garbage_collection(); // Make sure no &'s are in, this will break the redirect $url = str_replace('&', '&', $url); @@ -2341,16 +2338,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline) case E_USER_ERROR: - if (isset($db)) - { - $db->sql_close(); - } + garbage_collection(); - if (isset($cache)) - { - $cache->unload(); - } - echo ''; echo ''; echo ''; @@ -2499,7 +2488,9 @@ function page_header($page_title = '', $display_online_list = true) if (!empty($_REQUEST['f'])) { $f = request_var('f', 0); - $reading_sql = " AND s.session_page LIKE '%f=$f%'"; + + // Do not change this (it is defined as _f_={forum_id}x within session.php) + $reading_sql = " AND s.session_page LIKE '%\_f\_={$f}x%'"; } // Get number of online guests @@ -2727,6 +2718,7 @@ function page_header($page_title = '', $display_online_list = true) 'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS) ? true : false, 'S_BOARD_DISABLED' => ($config['board_disable'] && !defined('IN_LOGIN') && $auth->acl_gets('a_', 'm_')) ? true : false, 'S_REGISTERED_USER' => $user->data['is_registered'], + 'S_IS_BOT' => $user->data['is_bot'], 'S_USER_PM_POPUP' => $user->optionget('popuppm'), 'S_USER_LANG' => $user->data['user_lang'], 'S_USER_BROWSER' => (isset($user->data['session_browser'])) ? $user->data['session_browser'] : $user->lang['UNKNOWN_BROWSER'], -- cgit v1.2.1 From 46af817cb058e2eecd89081af4a40075426a32ef Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 9 Jul 2006 16:23:57 +0000 Subject: - tackle some usability issues - fix bug #3147 - added the lock-images made by SHS` - fixed MSSQL errors (adding the correct ESCAPE sequence) git-svn-id: file:///svn/phpbb/trunk@6161 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 50cdd6a121..0da1bf243d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -412,7 +412,7 @@ if (!function_exists('realpath')) $translated_path = ''; - foreach($dirs as $key => $value) + foreach ($dirs as $key => $value) { if (strlen($value) > 0) { @@ -2491,6 +2491,12 @@ function page_header($page_title = '', $display_online_list = true) // Do not change this (it is defined as _f_={forum_id}x within session.php) $reading_sql = " AND s.session_page LIKE '%\_f\_={$f}x%'"; + + // Specify escape character for MSSQL + if (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') + { + $reading_sql .= " ESCAPE '\\'"; + } } // Get number of online guests -- cgit v1.2.1 From c4f2430645dbc8cba38c1ea3f08366034bba7127 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 13 Jul 2006 12:51:56 +0000 Subject: - renamed the following columns: comment -> attach_comment new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted module_name -> module_basename value -> lang_value - every column is now NOT NULL - every column is now having a DEFAULT value - hopefully mostly consistent across every db schema - untested schemas: sqlite, oracle, firebird git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0da1bf243d..13558acccf 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1526,7 +1526,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa if (isset($_POST['login'])) { - $username = request_var('username', '', true); + $username = request_var('username', ''); $password = request_var('password', ''); $autologin = (!empty($_POST['autologin'])) ? true : false; $viewonline = (!empty($_POST['viewonline'])) ? 0 : 1; -- cgit v1.2.1 From d10e5bfc1acc671b1028bfaa16b1dee24295a222 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 14 Jul 2006 12:59:55 +0000 Subject: add not applied sql_escape in memberlist git-svn-id: file:///svn/phpbb/trunk@6178 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 13558acccf..e357435fcc 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2834,7 +2834,6 @@ function page_footer() else if (time() - $config['database_gc'] > $config['database_last_gc']) { // Tidy the database - // This includes recalculation binary trees, ... $cron_type = 'tidy_database'; } else if (time() - $config['search_gc'] > $config['search_last_gc']) -- cgit v1.2.1 From fa205b922dcfa09bab26b6cf9d406d2afe1a0518 Mon Sep 17 00:00:00 2001 From: David M Date: Mon, 17 Jul 2006 03:23:31 +0000 Subject: hmm... This commit does not increase the number of BBCodes. However, this does other things that we need to do first. This splits the usage of allow_* from the BBCode bitfield in forum descriptions, forum rules and group descriptions. This also fixes a tiny, tiny severe issue that nobody found :D I hope it works :P git-svn-id: file:///svn/phpbb/trunk@6188 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e357435fcc..c5d5b2f2a3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1811,7 +1811,7 @@ function decode_message(&$message, $bbcode_uid = '') * For display of custom parsed text on user-facing pages * Expects $text to be the value directly from the database (stored value) */ -function generate_text_for_display($text, $uid, $bitfield) +function generate_text_for_display($text, $uid, $bitfield, $flags) { global $__bbcode; @@ -1820,13 +1820,6 @@ function generate_text_for_display($text, $uid, $bitfield) return ''; } - // Get flags... they are always allow_bbcode, allow_smilies and allow_urls - $flags = $bitfield; - if ($flags >> 3) - { - $flags = bindec(substr(decbin($flags), strlen(decbin($flags >> 3)))); - } - // Parse bbcode if bbcode uid stored and bbcode enabled if ($uid && ($flags & 1)) { @@ -1838,11 +1831,11 @@ function generate_text_for_display($text, $uid, $bitfield) if (empty($__bbcode)) { - $__bbcode = new bbcode($bitfield >> 3); + $__bbcode = new bbcode($bitfield); } else { - $__bbcode->bbcode($bitfield >> 3); + $__bbcode->bbcode($bitfield); } $__bbcode->bbcode_second_pass($text, $uid); @@ -1859,7 +1852,7 @@ function generate_text_for_display($text, $uid, $bitfield) * This function additionally returns the uid and bitfield that needs to be stored. * Expects $text to be the value directly from request_var() and in it's non-parsed form */ -function generate_text_for_storage(&$text, &$uid, &$bitfield, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) +function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) { global $phpbb_root_path, $phpEx; @@ -1889,7 +1882,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, $allow_bbcode = fa } $flags = (($allow_bbcode) ? 1 : 0) + (($allow_smilies) ? 2 : 0) + (($allow_urls) ? 4 : 0); - $bitfield = $flags + ($message_parser->bbcode_bitfield << 3); + $bitfield = $message_parser->bbcode_bitfield; return; } @@ -1898,17 +1891,10 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, $allow_bbcode = fa * For decoding custom parsed text for edits as well as extracting the flags * Expects $text to be the value directly from the database (pre-parsed content) */ -function generate_text_for_edit($text, $uid, $bitfield) +function generate_text_for_edit($text, $uid, $flags) { global $phpbb_root_path, $phpEx; - // Get forum flags... - $flags = $bitfield; - if ($flags >> 3) - { - $flags = bindec(substr(decbin($flags), strlen(decbin($flags >> 3)))); - } - decode_message($text, $uid); return array( -- cgit v1.2.1 From 9532514c2a566437a9524af1dfca298da58fd40a Mon Sep 17 00:00:00 2001 From: David M Date: Mon, 24 Jul 2006 10:08:36 +0000 Subject: OK... This commit should increase the total number of BBCodes from 31 to 2040. Some things to watch out for: Each database likes to deal with binary data in its own, special way. They are, quite frankly, too cool for school. MySQL, MSSQL and Oracle all allow me to send in a default value for their binary column using a hex number. However, MSSQL forces me to send the specific data as a hex number and thus we must CAST it. PostgreSQL allows me to set a binary column, but with a twist. It demands that the default be in _octal_ and its datatype allows somewhere around a gigabyte's worth of BBCodes ( PGSQL users, we shut you down to 2040 for your own good! ) Firebird has no decent mechanism for allowing me to shuttle in binary data so I must force my way in. By virtue of triggers and a UDF, we ram in our default values. SQLite is the most bizarre of them all. They have no mechanism for turning an ASCII code into a ASCII character. Because of this, we have a trigger and a UDF (just like Firebird!) but with a twist! The UDF is defined on the PHP side of things instead of SQL. SQLite also demands that it's data be encoded before being sent off. Other notes: - SQLite installs again :D - Firebird nearly installs again :P - Database backup is not screwed up :P P.S. I hope nothing broke :D git-svn-id: file:///svn/phpbb/trunk@6209 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 96 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c5d5b2f2a3..d5355ca600 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1857,7 +1857,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb global $phpbb_root_path, $phpEx; $uid = ''; - $bitfield = 0; + $bitfield = ''; if (!$text) { @@ -2863,4 +2863,98 @@ function garbage_collection() $db->sql_close(); } +class bitfield +{ + var $data; + + function bitfield($bitfield = '') + { + $this->data = $bitfield; + } + + function get($n) + { + /** + * Get the ($n / 8)th char + */ + $byte = $n >> 3; + + if (!isset($this->data[$byte])) + { + /** + * Of course, if it doesn't exist then the result if FALSE + */ + return FALSE; + } + + $c = $this->data[$byte]; + + /** + * Lookup the ($n % 8)th bit of the byte + */ + $bit = 7 - ($n & 7); + return (bool) (ord($c) & (1 << $bit)); + } + + function set($n) + { + $byte = $n >> 3; + $bit = 7 - ($n & 7); + + if (isset($this->data[$byte])) + { + $this->data[$byte] = $this->data[$byte] | chr(1 << $bit); + } + else + { + if ($byte - strlen($this->data) > 0) + { + $this->data .= str_repeat("\0", $byte - strlen($this->data)); + } + $this->data .= chr(1 << $bit); + } + } + + function clear($n) + { + $byte = $n >> 3; + + if (!isset($this->data[$byte])) + { + return; + } + + $bit = 7 - ($n & 7); + $this->data[$byte] = $this->data[$byte] &~ chr(1 << $bit); + } + + function get_blob() + { + return $this->data; + } + + function get_bin() + { + $bin = ''; + $len = strlen($this->data); + + for ($i = 0; $i < $len; ++$i) + { + $bin .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT); + } + + return $bin; + } + + function get_all_set() + { + return array_keys(array_filter(str_split($this->get_bin()))); + } + + function merge($bitfield) + { + $this->data = $this->data | $bitfield->get_blob(); + } +} + ?> \ No newline at end of file -- cgit v1.2.1 From ced8624b8e86bc6aac143163e538f87376319079 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 1 Aug 2006 15:29:47 +0000 Subject: - fixing some bugs - shortening some db columns to meet the requirements - correctly increase/decrease user post counts - fix the topic title length bug(s) git-svn-id: file:///svn/phpbb/trunk@6224 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d5355ca600..320cee5bf5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2276,6 +2276,41 @@ function get_preg_expression($mode) return ''; } +/** +* Truncates string while retaining special characters if going over the max length +* The default max length is 60 at the moment +*/ +function truncate_string($string, $max_length = 60) +{ + $chars = array(); + + // split the multibyte characters first + $string_ary = preg_split('#(&\#[0-9]+;)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE); + + // Now go through the array and split the other characters + foreach ($string_ary as $key => $value) + { + if (strpos($value, '&#') === 0) + { + $chars[] = $value; + continue; + } + + // decode html entities and put them back later + $_chars = str_split(html_entity_decode($value)); + $chars = array_merge($chars, array_map('htmlspecialchars', $_chars)); + } + + // Now check the length ;) + if (sizeof($chars) <= $max_length) + { + return $string; + } + + // Cut off the last elements from the array + return implode('', array_slice($chars, 0, $max_length)); +} + // Handler, header and footer /** @@ -2863,6 +2898,8 @@ function garbage_collection() $db->sql_close(); } +/** +*/ class bitfield { var $data; @@ -2872,26 +2909,22 @@ class bitfield $this->data = $bitfield; } + /** + */ function get($n) { - /** - * Get the ($n / 8)th char - */ + // Get the ($n / 8)th char $byte = $n >> 3; if (!isset($this->data[$byte])) { - /** - * Of course, if it doesn't exist then the result if FALSE - */ - return FALSE; + // Of course, if it doesn't exist then the result if FALSE + return false; } $c = $this->data[$byte]; - /** - * Lookup the ($n % 8)th bit of the byte - */ + // Lookup the ($n % 8)th bit of the byte $bit = 7 - ($n & 7); return (bool) (ord($c) & (1 << $bit)); } -- cgit v1.2.1 From 8b079894f3e528c9ffe652f8f3a041599d8cbdc0 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 6 Aug 2006 17:25:29 +0000 Subject: - finally making the age calculation work [Bug #3582] - replacing all occurances of L_NONE with a more specific string [Bug #3494] - a few corrections to html id attributes in the installer - using correct permission in mcp_report [Bug #2471] - allow deleting the avatar, when no upload method is enabled and hide the delete button if no avatar is set git-svn-id: file:///svn/phpbb/trunk@6241 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 320cee5bf5..51c298a01d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2590,7 +2590,7 @@ function page_header($page_title = '', $display_online_list = true) if (!$online_userlist) { - $online_userlist = $user->lang['NONE']; + $online_userlist = $user->lang['NO_ONLINE_USERS']; } if (empty($_REQUEST['f'])) -- cgit v1.2.1 From 53085a4c78b3004d1e4adf8e06b0617f7f8a288b Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 9 Aug 2006 21:03:46 +0000 Subject: - load tracking updates. Need to be tested on a clean installation too - at the moment only tiny quirks are noticed at area51. - reported bugs fixed git-svn-id: file:///svn/phpbb/trunk@6256 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 116 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 51c298a01d..48336727f0 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -539,7 +539,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}"); } - else + else if ($config['load_anon_lastread'] || $user->data['is_registered']) { $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; $tracking_topics = ($tracking_topics) ? unserialize($tracking_topics) : array(); @@ -633,7 +633,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } } } - else + else if ($config['load_anon_lastread'] || $user->data['is_registered']) { $tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; $tracking = ($tracking) ? unserialize($tracking) : array(); @@ -698,7 +698,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $db->sql_return_on_error(false); } } - else + else if ($config['load_anon_lastread'] || $user->data['is_registered']) { $tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; $tracking = ($tracking) ? unserialize($tracking) : array(); @@ -745,7 +745,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ if ($user->data['is_registered']) { - $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . intval(base_convert(max($time_keys) + $config['board_startdate'], 36, 10)) . " WHERE user_id = {$user->data['user_id']}"); + $user->data['user_lastmark'] = intval(base_convert(max($time_keys) + $config['board_startdate'], 36, 10)); + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . $user->data['user_lastmark'] . " WHERE user_id = {$user->data['user_id']}"); } else { @@ -929,7 +930,7 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis } } } - else + else if ($config['load_anon_lastread'] || $user->data['is_registered']) { global $tracking_topics; @@ -995,6 +996,111 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis return $last_read; } +/** +* Check for read forums and update topic tracking info accordingly +* +* @param int $forum_id the forum id to check +* @param int $forum_last_post_time the forums last post time +* @param int $f_mark_time the forums last mark time if user is registered and load_db_lastread enabled +* @param int $mark_time_forum false if the mark time needs to be obtained, else the last users forum mark time +* +*/ +function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false) +{ + global $db, $tracking_topics, $user, $config; + + // Determine the users last forum mark time if not given. + if ($mark_time_forum === false) + { + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + $mark_time_forum = (!empty($f_mark_time)) ? $f_mark_time : $user->data['user_lastmark']; + } + else if ($config['load_anon_lastread'] || $user->data['is_registered']) + { + if (!isset($tracking_topics) || !sizeof($tracking_topics)) + { + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; + $tracking_topics = ($tracking_topics) ? unserialize($tracking_topics) : array(); + } + + if (!$user->data['is_registered']) + { + $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0; + } + + $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark']; + } + } + + // Check the forum for any left unread topics. + // If there are none, we mark the forum as read. + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + if ($mark_time_forum >= $forum_last_post_time) + { + // We do not need to mark read, this happened before. Therefore setting this to true + $row = true; + } + else + { + $sql = 'SELECT t.forum_id FROM ' . TOPICS_TABLE . ' t + LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ') + WHERE t.forum_id = ' . $forum_id . ' + AND t.topic_last_post_time > ' . $mark_time_forum . ' + AND t.topic_moved_id = 0 + AND tt.topic_id IS NULL + GROUP BY t.forum_id'; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + } + else if ($config['load_anon_lastread'] || $user->data['is_registered']) + { + // Get information from cookie + $row = false; + + if (!isset($tracking_topics['tf'][$forum_id])) + { + // We do not need to mark read, this happened before. Therefore setting this to true + $row = true; + } + else + { + $sql = 'SELECT topic_id + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = ' . $forum_id . ' + AND topic_last_post_time > ' . $mark_time_forum . ' + AND topic_moved_id = 0'; + $result = $db->sql_query($sql); + + $check_forum = $tracking_topics['tf'][$forum_id]; + $unread = false; + while ($row = $db->sql_fetchrow($result)) + { + if (!in_array(base_convert($row['topic_id'], 10, 36), array_keys($check_forum))) + { + $unread = true; + break; + } + } + $db->sql_freeresult($result); + + $row = $unread; + } + } + else + { + $row = true; + } + + if (!$row) + { + markread('topics', $forum_id); + } +} + // Pagination functions /** -- cgit v1.2.1 From 86f3d738a0efbf5c50bdf112841aba2c8b859e85 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 11 Aug 2006 21:52:46 +0000 Subject: so.... what does this thing do? well, the super fast, ultra efficient, massively huge BBCode handling system was implemented differently on each DBMS. Although this provided the best performance, the solution was a bit hacky. So what does this new thing do? We use base64 encoding to make everything nice and shiny, it turns into nice, safe characters that we can just jam into varchars on essentially any database. This has two implications: we must decode every bitfield we get AND we have slightly fewer IDs to work with. It goes down from 2040 BBCodes to 1512. We lose like a quarter of them :P P.S. I hope nothing broke :P git-svn-id: file:///svn/phpbb/trunk@6263 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 48336727f0..a676a717ff 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3012,7 +3012,7 @@ class bitfield function bitfield($bitfield = '') { - $this->data = $bitfield; + $this->data = base64_decode($bitfield); } /** @@ -3072,6 +3072,11 @@ class bitfield return $this->data; } + function get_base64() + { + return base64_encode($this->data); + } + function get_bin() { $bin = ''; -- cgit v1.2.1 From 8405f0d324fd42bec2f775986e69e5d8cf548ebf Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sat, 12 Aug 2006 13:14:39 +0000 Subject: sql_in_set changes git-svn-id: file:///svn/phpbb/trunk@6271 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index a676a717ff..48fec2d795 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -576,13 +576,13 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ { $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']} - AND forum_id IN (" . implode(', ', $forum_id) . ")"; + AND " . $db->sql_in_set('forum_id', $forum_id); $db->sql_query($sql); $sql = 'SELECT forum_id FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']} - AND forum_id IN (" . implode(', ', $forum_id) . ')'; + AND " . $db->sql_in_set('forum_id', $forum_id); $result = $db->sql_query($sql); $sql_update = array(); @@ -597,7 +597,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . ' SET mark_time = ' . time() . " WHERE user_id = {$user->data['user_id']} - AND forum_id IN (" . implode(', ', $sql_update) . ')'; + AND " . $db->sql_in_set('forum_id', $sql_update); $db->sql_query($sql); } @@ -888,7 +888,7 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis $sql = 'SELECT topic_id, mark_time FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']} - AND topic_id IN (" . implode(', ', $topic_ids) . ")"; + AND " . $db->sql_in_set('topic_id', $topic_ids); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -1805,13 +1805,13 @@ function login_forum_box($forum_data) $sql_in = array(); do { - $sql_in[] = "'" . $db->sql_escape($row['session_id']) . "'"; + $sql_in[] = (string) $row['session_id']; } while ($row = $db->sql_fetchrow($result)); // Remove expired sessions $sql = 'DELETE FROM ' . FORUMS_ACCESS_TABLE . ' - WHERE session_id NOT IN (' . implode(', ', $sql_in) . ')'; + WHERE ' . $db->sql_in_set('session_id', $sql_in, true); $db->sql_query($sql); } $db->sql_freeresult($result); -- cgit v1.2.1