diff options
Diffstat (limited to 'phpBB/includes/functions_content.php')
| -rw-r--r-- | phpBB/includes/functions_content.php | 122 |
1 files changed, 70 insertions, 52 deletions
diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index f5c0786fed..23cbff7e8f 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -950,6 +950,8 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, 'S_THUMBNAIL' => true, 'THUMB_IMAGE' => $thumbnail_link, ); + + $update_count[] = $attachment['attach_id']; break; // Windows Media Streams @@ -996,6 +998,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, 'S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height, + 'U_VIEW_LINK' => $download_link . '&view=1', ); // Viewed/Heared File ... update the download count @@ -1126,7 +1129,7 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al array_pop($chars); $string = implode('', $chars); } - while (utf8_strlen($string) > $max_store_length || !sizeof($chars)); + while (!empty($chars) && utf8_strlen($string) > $max_store_length); } if ($strip_reply) @@ -1159,72 +1162,87 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) { static $_profile_cache; - static $_base_profile_url; - - $cache_key = $user_id; - // If the get_username_string() function had been executed once with an (to us) unkown mode, all modes are pre-filled and we can just grab it. - if ($user_id && $user_id != ANONYMOUS && isset($_profile_cache[$cache_key][$mode])) + // We cache some common variables we need within this function + if (empty($_profile_cache)) { - // If the mode is 'no_profile', we simply construct the TPL code due to calls to this mode being very very rare - if ($mode == 'no_profile') - { - $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; - return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl); - } + global $phpbb_root_path, $phpEx; - return $_profile_cache[$cache_key][$mode]; + $_profile_cache['base_url'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}'); + $_profile_cache['tpl_noprofile'] = '{USERNAME}'; + $_profile_cache['tpl_noprofile_colour'] = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; + $_profile_cache['tpl_profile'] = '<a href="{PROFILE_URL}">{USERNAME}</a>'; + $_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>'; } - global $phpbb_root_path, $phpEx, $user, $auth; - - $username_colour = ($username_colour) ? '#' . $username_colour : ''; + global $user, $auth; - if ($guest_username === false) + // This switch makes sure we only run code required for the mode + switch ($mode) { - $username = ($username) ? $username : $user->lang['GUEST']; - } - else - { - $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']); - } + case 'full': + case 'no_profile': + case 'colour': - // Build cache for all modes - $_profile_cache[$cache_key]['colour'] = $username_colour; - $_profile_cache[$cache_key]['username'] = $username; - $_profile_cache[$cache_key]['no_profile'] = true; + // Build correct username colour + $username_colour = ($username_colour) ? '#' . $username_colour : ''; - // Profile url - only show if not anonymous and permission to view profile if registered user - // For anonymous the link leads to a login page. - if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile'))) - { - if (empty($_base_profile_url)) - { - $_base_profile_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}'); - } + // Return colour + if ($mode == 'colour') + { + return $username_colour; + } - $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace('={USER_ID}', '=' . (int) $user_id, $_base_profile_url); - $tpl = (!$username_colour) ? '<a href="{PROFILE_URL}">{USERNAME}</a>' : '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>'; - $_profile_cache[$cache_key]['full'] = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); - } - else - { - $tpl = (!$username_colour) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; - $_profile_cache[$cache_key]['full'] = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), $tpl); - $profile_url = ''; - } + // no break; - // Use the profile url from above - $_profile_cache[$cache_key]['profile'] = $profile_url; + case 'username': + + // Build correct username + if ($guest_username === false) + { + $username = ($username) ? $username : $user->lang['GUEST']; + } + else + { + $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']); + } + + // Return username + if ($mode == 'username') + { + return $username; + } + + // no break; + + case 'profile': + + // Build correct profile url - only show if not anonymous and permission to view profile if registered user + // For anonymous the link leads to a login page. + if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile'))) + { + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']); + } + else + { + $profile_url = ''; + } + + // Return profile + if ($mode == 'profile') + { + return $profile_url; + } + + // no break; + } - // If - by any chance - no_profile is called before any other mode, we need to do the calculation here - if ($mode == 'no_profile') + if (($mode == 'full' && !$profile_url) || $mode == 'no_profile') { - $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; - return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl); + return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); } - return $_profile_cache[$cache_key][$mode]; + return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); } /** |
