aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions.php143
-rw-r--r--phpBB/includes/functions_posting.php5
-rw-r--r--phpBB/includes/mcp/mcp_post.php2
-rw-r--r--phpBB/includes/mcp/mcp_queue.php1
-rwxr-xr-xphpBB/includes/mcp/mcp_reports.php1
-rw-r--r--phpBB/includes/mcp/mcp_topic.php2
-rwxr-xr-xphpBB/includes/mcp/mcp_warn.php4
-rwxr-xr-xphpBB/includes/search/fulltext_native.php21
-rw-r--r--phpBB/includes/session.php22
-rw-r--r--phpBB/includes/ucp/ucp_pm_viewmessage.php12
10 files changed, 184 insertions, 29 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 4227a8a9a3..02f1553c43 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -2015,6 +2015,117 @@ function bump_topic_allowed($forum_id, $topic_bumped, $last_post_time, $topic_po
}
/**
+* Generates a text with approx. the specified length which contains the specified words and their context
+*
+* @param string $text The full text from which context shall be extracted
+* @param string $words An array of words which should be contained in the result, * is allowed as a wildcard
+* @param int $length The desired length of the resulting text, however the result might be shorter or longer than this value
+*
+* @return string Context of the specified words seperated by "..."
+*/
+function get_context($text, $words, $length = 400)
+{
+ // first replace all whitespaces with single spaces
+ $text = preg_replace('/\s+/', ' ', $text);
+
+ $word_indizes = array();
+ if (sizeof($words))
+ {
+ $match = '';
+ // find the starting indizes of all words
+ foreach ($words as $word)
+ {
+ if (preg_match('#(?: |^)(' . str_replace('\*', '\w*?', preg_quote($word, '#')) . ')(?: |$)#i', $text, $match))
+ {
+ $pos = strpos($text, $match[1]);
+ if ($pos !== false)
+ {
+ $word_indizes[] = $pos;
+ }
+ }
+ }
+ unset($match);
+
+ if (sizeof($word_indizes))
+ {
+ $word_indizes = array_unique($word_indizes);
+ sort($word_indizes);
+
+ $wordnum = sizeof($word_indizes);
+ // number of characters on the right and left side of each word
+ $sequence_length = (int) ($length / (2 * $wordnum)) - 2;
+ $final_text = '';
+ $word = $j = 0;
+ $final_text_index = -1;
+
+ // cycle through every character in the original text
+ for ($i = $word_indizes[$word], $n = strlen($text); $i < $n; $i++)
+ {
+ // if the current position is the start of one of the words then append $sequence_length characters to the final text
+ if (isset($word_indizes[$word]) && ($i == $word_indizes[$word]))
+ {
+ if ($final_text_index < $i - $sequence_length - 1)
+ {
+ $final_text .= '... ' . preg_replace('#^([^ ]*)#', '', substr($text, $i - $sequence_length, $sequence_length));
+ }
+ else
+ {
+ // if the final text is already nearer to the current word than $sequence_length we only append the text
+ // from its current index on and distribute the unused length to all other sequenes
+ $sequence_length += (int) (($final_text_index - $i + $sequence_length + 1) / (2 * $wordnum));
+ $final_text .= substr($text, $final_text_index + 1, $i - $final_text_index - 1);
+ }
+ $final_text_index = $i - 1;
+
+ // add the following characters to the final text (see below)
+ $word++;
+ $j = 1;
+ }
+
+ if ($j > 0)
+ {
+ // add the character to the final text and increment the sequence counter
+ $final_text .= $text[$i];
+ $final_text_index++;
+ $j++;
+
+ // if this is a whitespace then check whether we are done with this sequence
+ if ($text[$i] == ' ')
+ {
+ // only check whether we have to exit the context generation completely if we haven't already reached the end anyway
+ if ($i + 4 < $n)
+ {
+ if (($j > $sequence_length && $word >= $wordnum) || strlen($final_text) > $length)
+ {
+ $final_text .= ' ...';
+ break;
+ }
+ }
+ else
+ {
+ // make sure the text really reaches the end
+ $j -= 4;
+ }
+
+ // stop context generation and wait for the next word
+ if ($j > $sequence_length)
+ {
+ $j = 0;
+ }
+ }
+ }
+ }
+ return $final_text;
+ }
+ }
+
+ if (!sizeof($words) || !sizeof($word_indizes))
+ {
+ return (strlen($text) >= $length + 3) ? substr($text, 0, $length) . '...' : $text;
+ }
+}
+
+/**
* Decode text whereby text is coming from the db and expected to be pre-parsed content
* We are placing this outside of the message parser because we are often in need of it...
*/
@@ -2053,6 +2164,33 @@ function decode_message(&$message, $bbcode_uid = '')
}
/**
+* Strips all bbcode from a text and returns the plain content
+*/
+function strip_bbcode(&$text, $uid = '')
+{
+ if (!$uid)
+ {
+ $uid = '[0-9a-z]{5,}';
+ }
+
+ $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?$uid)\]#", ' ', $text);
+
+ $match = array(
+ '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
+ '#<!\-\- m \-\-><a href="(.*?)" target="_blank">.*?</a><!\-\- m \-\->#',
+ '#<!\-\- w \-\-><a href="http:\/\/(.*?)" target="_blank">.*?</a><!\-\- w \-\->#',
+ '#<!\-\- l \-\-><a href="(.*?)">.*?</a><!\-\- l \-\->#',
+ '#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
+ '#<!\-\- .*? \-\->#s',
+ '#<.*?>#s'
+ );
+
+ $replace = array('\1', '\1', '\1', '\1', '\1', '', '');
+
+ $text = preg_replace($match, $replace, $text);
+}
+
+/**
* For display of custom parsed text on user-facing pages
* Expects $text to be the value directly from the database (stored value)
*/
@@ -2065,6 +2203,8 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
return '';
}
+ $text = str_replace("\n", '<br />', censor_text($text));
+
// Parse bbcode if bbcode uid stored and bbcode enabled
if ($uid && ($flags & 1))
{
@@ -2074,7 +2214,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
}
- if (empty($__bbcode))
+ if (empty($bbcode))
{
$bbcode = new bbcode($bitfield);
}
@@ -2087,7 +2227,6 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
}
$text = smiley_text($text, !($flags & 2));
- $text = str_replace("\n", '<br />', censor_text($text));
return $text;
}
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 2ac732746e..a8c7078057 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -873,6 +873,8 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
$post_subject = $row['post_subject'];
$message = $row['post_text'];
+ $message = censor_text($message);
+ $message = str_replace("\n", '<br />', $message);
$decoded_message = false;
if ($show_quote_button && $auth->acl_get('f_reply', $forum_id))
@@ -892,14 +894,13 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
$message = smiley_text($message, !$row['enable_smilies']);
$post_subject = censor_text($post_subject);
- $message = censor_text($message);
$template->assign_block_vars($mode . '_row', array(
'POSTER_NAME' => $poster,
'POST_SUBJECT' => $post_subject,
'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
'POST_DATE' => $user->format_date($row['post_time']),
- 'MESSAGE' => str_replace("\n", '<br />', $message),
+ 'MESSAGE' => $message,
'DECODED_MESSAGE' => $decoded_message,
'U_POST_ID' => $row['post_id'],
diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php
index 08bcc713f8..9cb3ec278b 100644
--- a/phpBB/includes/mcp/mcp_post.php
+++ b/phpBB/includes/mcp/mcp_post.php
@@ -95,6 +95,7 @@ function mcp_post_details($id, $mode, $action)
// Process message, leave it uncensored
$message = $post_info['post_text'];
+ $message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
@@ -102,7 +103,6 @@ function mcp_post_details($id, $mode, $action)
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = smiley_text($message);
- $message = str_replace("\n", '<br />', $message);
$template->assign_vars(array(
'U_MCP_ACTION' => "$url&amp;i=main&amp;quickmod=1", // Use this for mode paramaters
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php
index 95e89fa9dc..3deeff6d1f 100644
--- a/phpBB/includes/mcp/mcp_queue.php
+++ b/phpBB/includes/mcp/mcp_queue.php
@@ -109,6 +109,7 @@ class mcp_queue
// Process message, leave it uncensored
$message = $post_info['post_text'];
+ $message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php
index a52bc02359..67af086292 100755
--- a/phpBB/includes/mcp/mcp_reports.php
+++ b/phpBB/includes/mcp/mcp_reports.php
@@ -117,6 +117,7 @@ class mcp_reports
// Process message, leave it uncensored
$message = $post_info['post_text'];
+ $message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php
index 7f1bc2a0c4..466459415d 100644
--- a/phpBB/includes/mcp/mcp_topic.php
+++ b/phpBB/includes/mcp/mcp_topic.php
@@ -110,6 +110,7 @@ function mcp_topic_view($id, $mode, $action)
$message = $row['post_text'];
$post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
+ $message = str_replace("\n", '<br />', $message);
if ($row['bbcode_bitfield'])
{
@@ -117,7 +118,6 @@ function mcp_topic_view($id, $mode, $action)
}
$message = smiley_text($message);
- $message = str_replace("\n", '<br />', $message);
if (!$row['post_approved'])
{
diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php
index bc428570ab..9a6ae1ab8f 100755
--- a/phpBB/includes/mcp/mcp_warn.php
+++ b/phpBB/includes/mcp/mcp_warn.php
@@ -247,6 +247,7 @@ function mcp_warn_post_view($id, $mode, $action)
// We want to make the message available here as a reminder
// Parse the message and subject
$message = $userrow['post_text'];
+ $message = str_replace("\n", '<br />', censor_text($message));
// Second parse bbcode here
if ($userrow['bbcode_bitfield'])
@@ -260,9 +261,6 @@ function mcp_warn_post_view($id, $mode, $action)
// Always process smilies after parsing bbcodes
$message = smiley_text($message);
- // Replace naughty words such as farty pants
- $message = str_replace("\n", '<br />', censor_text($message));
-
// Generate the appropriate user information for the user we are looking at
$rank_title = $rank_img = '';
// get_user_rank($userrow['user_rank'], $userrow['user_posts'], $rank_title, $rank_img);
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php
index e4ff1f8fc2..90da8abcd1 100755
--- a/phpBB/includes/search/fulltext_native.php
+++ b/phpBB/includes/search/fulltext_native.php
@@ -119,6 +119,15 @@ class fulltext_native extends search_backend
// remove some useless bracket combinations which might be created by the previous regexps
$keywords = str_replace(array('()', ')|('), array('', '|'), $keywords);
+ $keywords = preg_replace_callback(
+ '#\((?:(?:[^)]*?) )*?[^)]*?\)#',
+ create_function(
+ '$matches',
+ 'return str_replace(" ", "|", $matches[0]);'
+ ),
+ $keywords
+ );
+
// $keywords input format: each word seperated by a space, words in a bracket are not seperated
// the user wants to search for any word, convert the search query
@@ -187,7 +196,7 @@ class fulltext_native extends search_backend
// a group of which at least one may not be in the resulting posts
if ($word[0] == '(')
{
- $word = explode('|', substr($word, 1, -1));
+ $word = array_unique(explode('|', substr($word, 1, -1)));
$mode = 'must_exclude_one';
}
// one word which should not be in the resulting posts
@@ -209,7 +218,7 @@ class fulltext_native extends search_backend
// a group of words of which at least one word should be in every resulting post
if ($word[0] == '(')
{
- $word = explode('|', substr($word, 1, -1));
+ $word = array_unique(explode('|', substr($word, 1, -1)));
}
$ignore_no_id = false;
$mode = 'must_contain';
@@ -880,7 +889,7 @@ class fulltext_native extends search_backend
// Do not index code
$match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is';
// BBcode
- $match[] = '#\[\/?[a-z\*\+\-]+(?:=.*?)?(\:?[0-9a-z]{5,})\]#';
+ $match[] = '#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?[0-9a-z]{5,})\]#';
$min = $config['fulltext_native_min_chars'];
$max = $config['fulltext_native_max_chars'];
@@ -890,7 +899,7 @@ class fulltext_native extends search_backend
/**
* Clean up the string, remove HTML tags, remove BBCodes
*/
- $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), '', $user->lang['ENCODING']), ' ');
+ $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), -1, $user->lang['ENCODING']), ' ');
while (isset($word[0]))
{
@@ -1146,14 +1155,14 @@ class fulltext_native extends search_backend
$destroy_cache_words = array();
- // Remove common (> 60% of posts ) words
+ // Remove common (> 20% of posts ) words
if ($config['num_posts'] >= 100)
{
// First, get the IDs of common words
$sql = 'SELECT word_id
FROM ' . SEARCH_WORDMATCH_TABLE . '
GROUP BY word_id
- HAVING COUNT(word_id) > ' . floor($config['num_posts'] * 0.6);
+ HAVING COUNT(word_id) > ' . floor($config['num_posts'] * 0.2);
$result = $db->sql_query($sql);
$sql_in = array();
diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php
index 0e934edb8a..5441f7e556 100644
--- a/phpBB/includes/session.php
+++ b/phpBB/includes/session.php
@@ -1340,13 +1340,15 @@ class user extends session
static $imgs;
global $phpbb_root_path;
- if (empty($imgs[$img . $suffix]) || $width !== false)
+ $img_data = $imgs[$img . $suffix];
+
+ if (empty($img_data) || $width !== false)
{
if (!isset($this->theme[$img]) || !$this->theme[$img])
{
// Do not fill the image to let designers decide what to do if the image is empty
- $imgs[$img . $suffix] = '';
- return $imgs[$img . $suffix];
+ $img_data = '';
+ return $img_data;
}
// Do not include dimensions?
@@ -1372,9 +1374,9 @@ class user extends session
$imgsrc = str_replace('{SUFFIX}', $suffix, $imgsrc);
}
- $imgs[$img . $suffix]['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . str_replace('{LANG}', $this->img_lang, $imgsrc);
- $imgs[$img . $suffix]['width'] = $width;
- $imgs[$img . $suffix]['height'] = $height;
+ $img_data['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . str_replace('{LANG}', $this->img_lang, $imgsrc);
+ $img_data['width'] = $width;
+ $img_data['height'] = $height;
}
$alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt;
@@ -1382,19 +1384,19 @@ class user extends session
switch ($type)
{
case 'src':
- return $imgs[$img . $suffix]['src'];
+ return $img_data['src'];
break;
case 'width':
- return $imgs[$img . $suffix]['width'];
+ return $img_data['width'];
break;
case 'height':
- return $imgs[$img . $suffix]['height'];
+ return $img_data['height'];
break;
default:
- return '<img src="' . $imgs[$img . $suffix]['src'] . '"' . (($imgs[$img . $suffix]['width']) ? ' width="' . $imgs[$img . $suffix]['width'] . '"' : '') . (($imgs[$img . $suffix]['height']) ? ' height="' . $imgs[$img . $suffix]['height'] . '"' : '') . ' alt="' . $alt . '" title="' . $alt . '" />';
+ return '<img src="' . $img_data['src'] . '"' . (($img_data['width']) ? ' width="' . $img_data['width'] . '"' : '') . (($img_data['height']) ? ' height="' . $img_data['height'] . '"' : '') . ' alt="' . $alt . '" title="' . $alt . '" />';
break;
}
}
diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php
index f0fa234944..3ffc19df55 100644
--- a/phpBB/includes/ucp/ucp_pm_viewmessage.php
+++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php
@@ -54,6 +54,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
// Parse the message and subject
$message = $message_row['message_text'];
+ $message = str_replace("\n", '<br />', censor_text($message));
// Second parse bbcode here
if ($message_row['bbcode_bitfield'])
@@ -66,7 +67,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
// Replace naughty words such as farty pants
$message_row['message_subject'] = censor_text($message_row['message_subject']);
- $message = str_replace("\n", '<br />', censor_text($message));
// Editing information
if ($message_row['message_edit_count'] && $config['display_last_edited'])
@@ -146,6 +146,9 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
// End signature parsing, only if needed
if ($signature)
{
+ $signature = censor_text($signature);
+ $signature = str_replace("\n", '<br />', censor_text($signature));
+
if ($user_info['user_sig_bbcode_bitfield'])
{
if ($bbcode === false)
@@ -158,7 +161,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
}
$signature = smiley_text($signature);
- $signature = str_replace("\n", '<br />', censor_text($signature));
}
$url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
@@ -318,6 +320,9 @@ function message_history($msg_id, $user_id, $message_row, $folder)
$subject = $row['message_subject'];
$message = $row['message_text'];
+ $message = censor_text($message);
+ $message = str_replace("\n", '<br />', $message)
+
if ($row['bbcode_bitfield'])
{
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
@@ -326,7 +331,6 @@ function message_history($msg_id, $user_id, $message_row, $folder)
$message = smiley_text($message, !$row['enable_smilies']);
$subject = censor_text($subject);
- $message = censor_text($message);
if ($id == $msg_id)
{
@@ -339,7 +343,7 @@ function message_history($msg_id, $user_id, $message_row, $folder)
'AUTHOR_NAME' => $author,
'SUBJECT' => $subject,
'SENT_DATE' => $user->format_date($row['message_time']),
- 'MESSAGE' => str_replace("\n", '<br />', $message),
+ 'MESSAGE' => $message,
'FOLDER' => implode(', ', $row['folder']),
'S_CURRENT_MSG' => ($row['msg_id'] == $msg_id),