Line 21 | Line 21 |
---|
* make_jumpbox() * bump_topic_allowed() * get_context()
|
* make_jumpbox() * bump_topic_allowed() * get_context()
|
| * phpbb_clean_search_string()
|
* decode_message() * strip_bbcode() * generate_text_for_display()
| * decode_message() * strip_bbcode() * generate_text_for_display()
|
Line 41 | Line 42 |
---|
/** * Generate sort selection fields */
|
/** * Generate sort selection fields */
|
function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param)
| function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param, $def_st = false, $def_sk = false, $def_sd = false)
|
{ global $user;
$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
|
{ global $user;
$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
|
// Check if the key is selectable. If not, we reset to the first key found. // This ensures the values are always valid. if (!isset($limit_days[$sort_days])) { @reset($limit_days); $sort_days = key($limit_days); }
| $sorts = array( 'st' => array( 'key' => 'sort_days', 'default' => $def_st, 'options' => $limit_days, 'output' => &$s_limit_days, ),
|
|
|
if (!isset($sort_by_text[$sort_key])) { @reset($sort_by_text); $sort_key = key($sort_by_text); }
| 'sk' => array( 'key' => 'sort_key', 'default' => $def_sk, 'options' => $sort_by_text, 'output' => &$s_sort_key, ),
|
|
|
if (!isset($sort_dir_text[$sort_dir]))
| 'sd' => array( 'key' => 'sort_dir', 'default' => $def_sd, 'options' => $sort_dir_text, 'output' => &$s_sort_dir, ), ); $u_sort_param = '';
foreach ($sorts as $name => $sort_ary)
|
{
|
{
|
@reset($sort_dir_text); $sort_dir = key($sort_dir_text); }
| $key = $sort_ary['key']; $selected = $$sort_ary['key'];
|
|
|
$s_limit_days = '<select name="st" id="st">'; foreach ($limit_days as $day => $text)
| // Check if the key is selectable. If not, we reset to the default or first key found. // This ensures the values are always valid. We also set $sort_dir/sort_key/etc. to the // correct value, else the protection is void. ;) if (!isset($sort_ary['options'][$selected]))
|
{
|
{
|
$selected = ($sort_days == $day) ? ' selected="selected"' : ''; $s_limit_days .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
| if ($sort_ary['default'] !== false) { $selected = $$key = $sort_ary['default'];
|
}
|
}
|
$s_limit_days .= '</select>';
$s_sort_key = '<select name="sk" id="sk">'; foreach ($sort_by_text as $key => $text)
| else
|
{
|
{
|
$selected = ($sort_key == $key) ? ' selected="selected"' : ''; $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
| @reset($sort_ary['options']); $selected = $$key = key($sort_ary['options']); }
|
}
|
}
|
$s_sort_key .= '</select>';
| |
|
|
$s_sort_dir = '<select name="sd" id="sd">'; foreach ($sort_dir_text as $key => $value)
| $sort_ary['output'] = '<select name="' . $name . '" id="' . $name . '">'; foreach ($sort_ary['options'] as $option => $text)
|
{
|
{
|
$selected = ($sort_dir == $key) ? ' selected="selected"' : ''; $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
| $sort_ary['output'] .= '<option value="' . $option . '"' . (($selected == $option) ? ' selected="selected"' : '') . '>' . $text . '</option>';
|
}
|
}
|
$s_sort_dir .= '</select>';
| $sort_ary['output'] .= '</select>';
|
|
|
$u_sort_param = "st=$sort_days&sk=$sort_key&sd=$sort_dir";
| $u_sort_param .= ($selected !== $sort_ary['default']) ? ((strlen($u_sort_param)) ? '&' : '') . "{$name}={$selected}" : ''; }
|
return; }
| return; }
|
Line 239 | Line 249 |
---|
function get_context($text, $words, $length = 400) { // first replace all whitespaces with single spaces
|
function get_context($text, $words, $length = 400) { // first replace all whitespaces with single spaces
|
$text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", ' '), $text);
| $text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", ' '));
// we need to turn the entities back into their original form, to not cut the message in between them $entities = array('<', '>', '[', ']', '.', ':', ':'); $characters = array('<', '>', '[', ']', '.', ':', ':'); $text = str_replace($entities, $characters, $text);
|
$word_indizes = array(); if (sizeof($words))
| $word_indizes = array(); if (sizeof($words))
|
Line 252 | Line 267 |
---|
{ if (preg_match('#(?:[^\w]|^)(' . $word . ')(?:[^\w]|$)#i', $text, $match)) {
|
{ if (preg_match('#(?:[^\w]|^)(' . $word . ')(?:[^\w]|$)#i', $text, $match)) {
|
| if (empty($match[1])) { continue; }
|
$pos = utf8_strpos($text, $match[1]); if ($pos !== false) {
| $pos = utf8_strpos($text, $match[1]); if ($pos !== false) {
|
Line 331 | Line 351 |
---|
} } }
|
} } }
|
return $final_text;
| return str_replace($characters, $entities, $final_text);
|
} }
if (!sizeof($words) || !sizeof($word_indizes)) {
|
} }
if (!sizeof($words) || !sizeof($word_indizes)) {
|
return (utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text;
| return str_replace($characters, $entities, ((utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text));
|
}
|
}
|
| }
/** * Cleans a search string by removing single wildcards from it and replacing multiple spaces with a single one. * * @param string $search_string The full search string which should be cleaned. * * @return string The cleaned search string without any wildcards and multiple spaces. */ function phpbb_clean_search_string($search_string) { // This regular expressions matches every single wildcard. // That means one after a whitespace or the beginning of the string or one before a whitespace or the end of the string. $search_string = preg_replace('#(?<=^|\s)\*+(?=\s|$)#', '', $search_string); $search_string = trim($search_string); $search_string = preg_replace(array('#\s+#u', '#\*+#u'), array(' ', '*'), $search_string); return $search_string;
|
}
/**
| }
/**
|
Line 394 | Line 431 |
---|
{ static $bbcode;
|
{ static $bbcode;
|
if (!$text)
| if ($text === '')
|
{ return ''; }
| { return ''; }
|
Line 440 | Line 477 |
---|
$uid = $bitfield = ''; $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
|
$uid = $bitfield = ''; $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
|
if (!$text)
| if ($text === '')
|
{ return; }
| { return; }
|
Line 492 | Line 529 |
---|
*/ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class) {
|
*/ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class) {
|
$orig_url = $url . $relative_url;
| $orig_url = $url; $orig_relative = $relative_url;
|
$append = ''; $url = htmlspecialchars_decode($url); $relative_url = htmlspecialchars_decode($relative_url);
| $append = ''; $url = htmlspecialchars_decode($url); $relative_url = htmlspecialchars_decode($relative_url);
|
Line 556 | Line 594 |
---|
{ $url = substr($url, 0, -1); }
|
{ $url = substr($url, 0, -1); }
|
| break;
// set last_char to empty here, so the variable can be used later to // check whether a character was removed default: $last_char = '';
|
break; }
| break; }
|
Line 574 | Line 618 |
---|
// don't touch it and let MAGIC_URL_FULL take care of it. if (!$relative_url) {
|
// don't touch it and let MAGIC_URL_FULL take care of it. if (!$relative_url) {
|
return $whitespace . $orig_url . '/'; // slash is taken away by relative url pattern
| return $whitespace . $orig_url . '/' . $orig_relative; // slash is taken away by relative url pattern
|
} break;
| } break;
|
Line 658 | Line 702 |
---|
function censor_text($text) { static $censors;
|
function censor_text($text) { static $censors;
|
| // Nothing to do? if ($text === '') { return ''; }
|
// We moved the word censor checks in here because we call this function quite often - and then only need to do the check once if (!isset($censors) || !is_array($censors))
| // We moved the word censor checks in here because we call this function quite often - and then only need to do the check once if (!isset($censors) || !is_array($censors))
|
Line 707 | Line 757 |
---|
} else {
|
} else {
|
return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $phpbb_root_path . $config['smilies_path'] . '/\2 />', $text);
| $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $root_path . $config['smilies_path'] . '/\2 />', $text);
|
} }
| } }
|
Line 815 | Line 866 |
---|
// Some basics... $attachment['extension'] = strtolower(trim($attachment['extension']));
|
// Some basics... $attachment['extension'] = strtolower(trim($attachment['extension']));
|
$filename = $phpbb_root_path . $config['upload_path'] . '/' . basename($attachment['physical_filename']); $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . basename($attachment['physical_filename']);
| $filename = $phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($attachment['physical_filename']); $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . utf8_basename($attachment['physical_filename']);
|
$upload_icon = '';
| $upload_icon = '';
|
Line 832 | Line 883 |
---|
} }
|
} }
|
$filesize = $attachment['filesize']; $size_lang = ($filesize >= 1048576) ? $user->lang['MIB'] : (($filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']); $filesize = get_formatted_filesize($filesize, false);
| $filesize = get_formatted_filesize($attachment['filesize'], false);
|
$comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
$block_array += array( 'UPLOAD_ICON' => $upload_icon,
|
$comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
$block_array += array( 'UPLOAD_ICON' => $upload_icon,
|
'FILESIZE' => $filesize, 'SIZE_LANG' => $size_lang, 'DOWNLOAD_NAME' => basename($attachment['real_filename']),
| 'FILESIZE' => $filesize['value'], 'SIZE_LANG' => $filesize['unit'], 'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']),
|
'COMMENT' => $comment, );
| 'COMMENT' => $comment, );
|
Line 934 | Line 983 |
---|
'S_THUMBNAIL' => true, 'THUMB_IMAGE' => $thumbnail_link, );
|
'S_THUMBNAIL' => true, 'THUMB_IMAGE' => $thumbnail_link, );
|
| $update_count[] = $attachment['attach_id'];
|
break;
// Windows Media Streams
| break;
// Windows Media Streams
|
Line 980 | Line 1031 |
---|
'S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height,
|
'S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height,
|
| 'U_VIEW_LINK' => $download_link . '&view=1',
|
);
// Viewed/Heared File ... update the download count
| );
// Viewed/Heared File ... update the download count
|
Line 1073 | Line 1125 |
---|
* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char) * @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars). * @param bool $allow_reply Allow Re: in front of string
|
* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char) * @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars). * @param bool $allow_reply Allow Re: in front of string
|
| * NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated.
|
* @param string $append String to be appended */
|
* @param string $append String to be appended */
|
function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = true, $append = '')
| function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
|
{ $chars = array();
| { $chars = array();
|
Line 1110 | Line 1163 |
---|
array_pop($chars); $string = implode('', $chars); }
|
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)
| }
if ($strip_reply)
|
Line 1128 | Line 1181 |
---|
/** * Get username details for placing into templates.
|
/** * Get username details for placing into templates.
|
| * This function caches all modes on first call, except for no_profile and anonymous user - determined by $user_id.
|
* * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour), full (for obtaining a html string representing a coloured link to the users profile) or no_profile (the same as full but forcing no profile link) * @param int $user_id The users id
| * * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour), full (for obtaining a html string representing a coloured link to the users profile) or no_profile (the same as full but forcing no profile link) * @param int $user_id The users id
|
Line 1137 | Line 1191 |
---|
* @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} * * @return string A string consisting of what is wanted based on $mode.
|
* @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} * * @return string A string consisting of what is wanted based on $mode.
|
| * @author BartVB, Acyd Burn
|
*/ function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) {
|
*/ function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) {
|
global $phpbb_root_path, $phpEx, $user, $auth;
| static $_profile_cache;
|
|
|
$profile_url = '';
| // We cache some common variables we need within this function if (empty($_profile_cache)) { global $phpbb_root_path, $phpEx;
$_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 $user, $auth;
// This switch makes sure we only run code required for the mode switch ($mode) { case 'full': case 'no_profile': case 'colour':
// Build correct username colour
|
$username_colour = ($username_colour) ? '#' . $username_colour : '';
|
$username_colour = ($username_colour) ? '#' . $username_colour : '';
|
| // Return colour if ($mode == 'colour') { return $username_colour; }
// no break;
case 'username':
// Build correct username
|
if ($guest_username === false) { $username = ($username) ? $username : $user->lang['GUEST'];
| if ($guest_username === false) { $username = ($username) ? $username : $user->lang['GUEST'];
|
Line 1154 | Line 1241 |
---|
$username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']); }
|
$username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']); }
|
// Only show the link if not anonymous if ($mode != 'no_profile' && $user_id && $user_id != ANONYMOUS)
| // Return username if ($mode == 'username')
|
{
|
{
|
// Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly). // For all others the link leads to a login page or the profile. if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')) { $profile_url = '';
| return $username;
|
}
|
}
|
else
| // 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 : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . (int) $user_id); }
| $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 = ''; }
|
} else { $profile_url = ''; }
|
switch ($mode)
| // Return profile if ($mode == 'profile')
|
{
|
{
|
case 'profile':
| |
return $profile_url;
|
return $profile_url;
|
break;
| }
|
|
|
case 'username': return $username; break;
| // no break; }
|
|
|
case 'colour': return $username_colour; break;
case 'no_profile': case 'full': default:
$tpl = ''; if (!$profile_url && !$username_colour)
| if (($mode == 'full' && !$profile_url) || $mode == 'no_profile')
|
{
|
{
|
$tpl = '{USERNAME}'; } else if (!$profile_url && $username_colour) { $tpl = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; } else if ($profile_url && !$username_colour) { $tpl = '<a href="{PROFILE_URL}">{USERNAME}</a>'; } else if ($profile_url && $username_colour) { $tpl = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
| return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']);
|
}
|
}
|
return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); break; }
| 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']);
|
}
/**
| }
/**
|