Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/functions_content.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_content.php 9184 2008-12-11 14:46:38Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    251251        $text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", '     '));
    252252
     253        // we need to turn the entities back into their original form, to not cut the message in between them
     254        $entities = array('<', '>', '[', ']', '.', ':', ':');
     255        $characters = array('<', '>', '[', ']', '.', ':', ':');
     256        $text = str_replace($entities, $characters, $text);
     257
    253258        $word_indizes = array();
    254259        if (sizeof($words))
     
    262267                                if (preg_match('#(?:[^\w]|^)(' . $word . ')(?:[^\w]|$)#i', $text, $match))
    263268                                {
     269                                        if (empty($match[1]))
     270                                        {
     271                                                continue;
     272                                        }
     273
    264274                                        $pos = utf8_strpos($text, $match[1]);
    265275                                        if ($pos !== false)
     
    341351                                }
    342352                        }
    343                         return $final_text;
     353                        return str_replace($characters, $entities, $final_text);
    344354                }
    345355        }
     
    347357        if (!sizeof($words) || !sizeof($word_indizes))
    348358        {
    349                 return (utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text;
     359                return str_replace($characters, $entities, ((utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text));
    350360        }
    351361}
     
    676686        static $censors;
    677687
     688        // Nothing to do?
     689        if ($text === '')
     690        {
     691                return '';
     692        }
     693
    678694        // We moved the word censor checks in here because we call this function quite often - and then only need to do the check once
    679695        if (!isset($censors) || !is_array($censors))
     
    724740        else
    725741        {
    726                 return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $phpbb_root_path . $config['smilies_path'] . '/\2 />', $text);
     742                $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;
     743                return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $root_path . $config['smilies_path'] . '/\2 />', $text);
    727744        }
    728745}
     
    832849                // Some basics...
    833850                $attachment['extension'] = strtolower(trim($attachment['extension']));
    834                 $filename = $phpbb_root_path . $config['upload_path'] . '/' . basename($attachment['physical_filename']);
    835                 $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . basename($attachment['physical_filename']);
     851                $filename = $phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($attachment['physical_filename']);
     852                $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . utf8_basename($attachment['physical_filename']);
    836853
    837854                $upload_icon = '';
     
    849866                }
    850867
    851                 $filesize = $attachment['filesize'];
    852                 $size_lang = ($filesize >= 1048576) ? $user->lang['MIB'] : (($filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
    853                 $filesize = get_formatted_filesize($filesize, false);
     868                $filesize = get_formatted_filesize($attachment['filesize'], false);
    854869
    855870                $comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
     
    857872                $block_array += array(
    858873                        'UPLOAD_ICON'           => $upload_icon,
    859                         'FILESIZE'                      => $filesize,
    860                         'SIZE_LANG'                     => $size_lang,
    861                         'DOWNLOAD_NAME'         => basename($attachment['real_filename']),
     874                        'FILESIZE'                      => $filesize['value'],
     875                        'SIZE_LANG'                     => $filesize['unit'],
     876                        'DOWNLOAD_NAME'         => utf8_basename($attachment['real_filename']),
    862877                        'COMMENT'                       => $comment,
    863878                );
     
    951966                                                'THUMB_IMAGE'           => $thumbnail_link,
    952967                                        );
     968
     969                                        $update_count[] = $attachment['attach_id'];
    953970                                break;
    954971
     
    9971014                                                'WIDTH'                 => $width,
    9981015                                                'HEIGHT'                => $height,
     1016                                                'U_VIEW_LINK'   => $download_link . '&amp;view=1',
    9991017                                        );
    10001018
     
    10891107* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
    10901108* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
    1091 * @param bool $allow_reply Allow Re: in front of string
     1109* @param bool $allow_reply Allow Re: in front of string
     1110*       NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_legnth) and is deprecated.
    10921111* @param string $append String to be appended
    10931112*/
    1094 function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = true, $append = '')
     1113function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
    10951114{
    10961115        $chars = array();
     
    11271146                        $string = implode('', $chars);
    11281147                }
    1129                 while (utf8_strlen($string) > $max_store_length || !sizeof($chars));
     1148                while (!empty($chars) && utf8_strlen($string) > $max_store_length);
    11301149        }
    11311150
     
    11601179{
    11611180        static $_profile_cache;
    1162         static $_base_profile_url;
    1163 
    1164         $cache_key = $user_id;
    1165 
    1166         // 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.
    1167         if ($user_id && $user_id != ANONYMOUS && isset($_profile_cache[$cache_key][$mode]))
    1168         {
    1169                 // If the mode is 'no_profile', we simply construct the TPL code due to calls to this mode being very very rare
    1170                 if ($mode == 'no_profile')
    1171                 {
    1172                         $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
    1173                         return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl);
    1174                 }
    1175 
    1176                 return $_profile_cache[$cache_key][$mode];
    1177         }
    1178 
    1179         global $phpbb_root_path, $phpEx, $user, $auth;
    1180 
    1181         $username_colour = ($username_colour) ? '#' . $username_colour : '';
    1182 
    1183         if ($guest_username === false)
    1184         {
    1185                 $username = ($username) ? $username : $user->lang['GUEST'];
    1186         }
    1187         else
    1188         {
    1189                 $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
    1190         }
    1191 
    1192         // Build cache for all modes
    1193         $_profile_cache[$cache_key]['colour'] = $username_colour;
    1194         $_profile_cache[$cache_key]['username'] = $username;
    1195         $_profile_cache[$cache_key]['no_profile'] = true;
    1196 
    1197         // Profile url - only show if not anonymous and permission to view profile if registered user
    1198         // For anonymous the link leads to a login page.
    1199         if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile')))
    1200         {
    1201                 if (empty($_base_profile_url))
    1202                 {
    1203                         $_base_profile_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u={USER_ID}');
    1204                 }
    1205 
    1206                 $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&amp;u=' . (int) $user_id : str_replace('={USER_ID}', '=' . (int) $user_id, $_base_profile_url);
    1207                 $tpl = (!$username_colour) ? '<a href="{PROFILE_URL}">{USERNAME}</a>' : '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
    1208                 $_profile_cache[$cache_key]['full'] = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl);
    1209         }
    1210         else
    1211         {
    1212                 $tpl = (!$username_colour) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
    1213                 $_profile_cache[$cache_key]['full'] = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), $tpl);
    1214                 $profile_url = '';
    1215         }
    1216 
    1217         // Use the profile url from above
    1218         $_profile_cache[$cache_key]['profile'] = $profile_url;
    1219 
    1220         // If - by any chance - no_profile is called before any other mode, we need to do the calculation here
    1221         if ($mode == 'no_profile')
    1222         {
    1223                 $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
    1224                 return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl);
    1225         }
    1226 
    1227         return $_profile_cache[$cache_key][$mode];
     1181
     1182        // We cache some common variables we need within this function
     1183        if (empty($_profile_cache))
     1184        {
     1185                global $phpbb_root_path, $phpEx;
     1186
     1187                $_profile_cache['base_url'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u={USER_ID}');
     1188                $_profile_cache['tpl_noprofile'] = '{USERNAME}';
     1189                $_profile_cache['tpl_noprofile_colour'] = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
     1190                $_profile_cache['tpl_profile'] = '<a href="{PROFILE_URL}">{USERNAME}</a>';
     1191                $_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
     1192        }
     1193
     1194        global $user, $auth;
     1195
     1196        // This switch makes sure we only run code required for the mode
     1197        switch ($mode)
     1198        {
     1199                case 'full':
     1200                case 'no_profile':
     1201                case 'colour':
     1202
     1203                        // Build correct username colour
     1204                        $username_colour = ($username_colour) ? '#' . $username_colour : '';
     1205
     1206                        // Return colour
     1207                        if ($mode == 'colour')
     1208                        {
     1209                                return $username_colour;
     1210                        }
     1211
     1212                // no break;
     1213
     1214                case 'username':
     1215
     1216                        // Build correct username
     1217                        if ($guest_username === false)
     1218                        {
     1219                                $username = ($username) ? $username : $user->lang['GUEST'];
     1220                        }
     1221                        else
     1222                        {
     1223                                $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
     1224                        }
     1225
     1226                        // Return username
     1227                        if ($mode == 'username')
     1228                        {
     1229                                return $username;
     1230                        }
     1231
     1232                // no break;
     1233
     1234                case 'profile':
     1235
     1236                        // Build correct profile url - only show if not anonymous and permission to view profile if registered user
     1237                        // For anonymous the link leads to a login page.
     1238                        if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile')))
     1239                        {
     1240                                $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&amp;u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']);
     1241                        }
     1242                        else
     1243                        {
     1244                                $profile_url = '';
     1245                        }
     1246
     1247                        // Return profile
     1248                        if ($mode == 'profile')
     1249                        {
     1250                                return $profile_url;
     1251                        }
     1252
     1253                // no break;
     1254        }
     1255
     1256        if (($mode == 'full' && !$profile_url) || $mode == 'no_profile')
     1257        {
     1258                return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']);
     1259        }
     1260
     1261        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']);
    12281262}
    12291263
Note: See TracChangeset for help on using the changeset viewer.