phpBB

Code Changes

File: includes/functions_content.php

  Unmodified   Added   Modified   Removed
Line 21Line 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 249Line 250
{
// first replace all whitespaces with single spaces
$text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", ' '));

{
// first replace all whitespaces with single spaces
$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 261Line 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 340Line 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 403Line 431
{
static $bbcode;


{
static $bbcode;


	if (!$text)

	if ($text === '')

	{
return '';
}

	{
return '';
}

Line 449Line 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 501Line 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 565Line 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 583Line 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 667Line 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 716Line 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 824Line 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 841Line 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 943Line 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 989Line 1031
						'S_FLASH_FILE'	=> true,
'WIDTH' => $width,
'HEIGHT' => $height,

						'S_FLASH_FILE'	=> true,
'WIDTH' => $width,
'HEIGHT' => $height,

 
						'U_VIEW_LINK'	=> $download_link . '&amp;view=1',

					);

// Viewed/Heared File ... update the download count

					);

// Viewed/Heared File ... update the download count

Line 1082Line 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 1119Line 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 1137Line 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 1146Line 1191
* @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &amp;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 &amp;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&amp;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 1163Line 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 . '&amp;u=' . (int) $user_id : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . (int) $user_id);
}

				$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']);


	}
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']);



}

/**

}

/**