|
From: Paul S. O. <ps...@us...> - 2001-11-09 13:15:38
|
Update of /cvsroot/phpbb/phpBB2
In directory usw-pr-cvs1:/tmp/cvs-serv12253
Modified Files:
profile.php privmsg.php posting.php
Log Message:
Altered templates so preview/errors are sent as 'boxes' rather than pparsed and output directly, greater control for designer
Index: profile.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/profile.php,v
retrieving revision 1.126
retrieving revision 1.127
diff -C2 -r1.126 -r1.127
*** profile.php 2001/11/08 06:12:53 1.126
--- profile.php 2001/11/09 13:15:35 1.127
***************
*** 1463,1467 ****
"ERROR_MESSAGE" => $error_msg)
);
! $template->pparse("reg_header");
}
--- 1463,1467 ----
"ERROR_MESSAGE" => $error_msg)
);
! $template->assign_var_from_handle("ERROR_BOX", "reg_header");
}
Index: privmsg.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/privmsg.php,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -r1.39 -r1.40
*** privmsg.php 2001/11/08 06:06:54 1.39
--- privmsg.php 2001/11/09 13:15:35 1.40
***************
*** 1294,1298 ****
"L_POSTED" => $lang['Posted'])
);
! $template->pparse("preview");
}
--- 1294,1298 ----
"L_POSTED" => $lang['Posted'])
);
! $template->assign_var_from_handle("POST_PREVIEW_BOX", "preview");
}
***************
*** 1308,1312 ****
"ERROR_MESSAGE" => $error_msg)
);
! $template->pparse("reg_header");
}
//
--- 1308,1312 ----
"ERROR_MESSAGE" => $error_msg)
);
! $template->assign_var_from_handle("ERROR_BOX", "reg_header");
}
//
Index: posting.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/posting.php,v
retrieving revision 1.89
retrieving revision 1.90
diff -C2 -r1.89 -r1.90
*** posting.php 2001/11/08 06:06:54 1.89
--- posting.php 2001/11/09 13:15:35 1.90
***************
*** 30,33 ****
--- 30,438 ----
// Page specific functions
//
+ function clean_words($entry, &$stopword_list, &$synonym_list)
+ {
+ $init_match = array("^", "$", "&", "(", ")", "<", ">", "`", "'", "|", ",", "@", "_", "?", "%");
+ $init_replace = array(" ", " ", " ", " ", " ", " ", " ", " ", "", " ", " ", " ", " ", " ", " ");
+
+ $later_match = array("-", "~", "+", ".", "[", "]", "{", "}", ":", "\\", "/", "=", "#", "\"", ";", "*", "!");
+ $later_replace = array(" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ");
+
+ $entry = " " . stripslashes(strip_tags(strtolower($entry))) . " ";
+
+ $entry = preg_replace("/[\n\r]/is", " ", $entry);
+ $entry = preg_replace("/\b[a-z0-9]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/]+)?/si", " ", $entry);
+
+ $entry = str_replace($init_match, $init_replace, $entry);
+
+ $entry = preg_replace("/\[code:[0-9]+:[0-9a-z]{10,}\].*?\[\/code:[0-9]+:[0-9a-z]{10,}\]/is", " ", $entry);
+ $entry = preg_replace("/\[img\].*?\[\/img\]/is", " ", $entry);
+ $entry = preg_replace("/\[\/?[a-z\*=\+\-]+[0-9a-z]?(\:[a-z0-9]+)?:[a-z0-9]{10,}(\:[a-z0-9]+)?=?.*?\]/si", " ", $entry);
+ $entry = preg_replace("/\[\/?[a-z\*]+[=\+\-]?[0-9a-z]+?:[a-z0-9]{10,}[=.*?]?\]/si", " ", $entry);
+ $entry = preg_replace("/\[\/?url(=.*?)?\]/si", " ", $entry);
+ $entry = preg_replace("/\b[0-9]+\b/si", " ", $entry);
+ $entry = preg_replace("/\b&[a-z]+;\b/is", " ", $entry);
+ $entry = preg_replace("/\b[a-z0-9]{1,2}?\b/si", " ", $entry);
+ $entry = preg_replace("/\b[a-z0-9]{50,}?\b/si", " ", $entry);
+
+ $entry = str_replace($later_match, $later_replace, $entry);
+
+ if( !empty($stopword_list) )
+ {
+ for ($j = 0; $j < count($stopword_list); $j++)
+ {
+ $filter_word = trim(strtolower($stopword_list[$j]));
+ $entry = preg_replace("/\b" . preg_quote($filter_word, "/") . "\b/is", " ", $entry);
+ }
+ }
+
+ if( !empty($synonym_list) )
+ {
+ for ($j = 0; $j < count($synonym_list); $j++)
+ {
+ list($replace_synonym, $match_synonym) = split(" ", trim(strtolower($synonym_list[$j])));
+ $entry = preg_replace("/\b" . preg_quote(trim($match_synonym), "/") . "\b/is", " " . trim($replace_synonym) . " ", $entry);
+ }
+ }
+
+ return $entry;
+ }
+
+ function split_words(&$entry)
+ {
+ preg_match_all("/\b(\w[\w']*\w+|\w+?)\b/", $entry, $split_entries);
+
+ return $split_entries[1];
+ }
+
+ function remove_old( $post_id )
+ {
+ global $db;
+
+ if( count($word_id_list) )
+ {
+ $word_id_sql = "";
+ for($i = 0; $i < count($word_id_list); $i++ )
+ {
+ if( $word_id_sql != "" )
+ {
+ $word_id_sql .= ", ";
+ }
+ $word_id_sql .= $word_id_list[$i]['word_id'];
+ }
+ $word_id_sql = " AND sl.word_id IN ($word_id_sql)";
+ }
+ else
+ {
+ $word_id_sql = "";
+ }
+
+ }
+
+ function remove_common($percent, $word_id_list = array())
+ {
+ global $db;
+
+ if( count($word_id_list) )
+ {
+ $word_id_sql = "";
+ for($i = 0; $i < count($word_id_list); $i++ )
+ {
+ if( $word_id_sql != "" )
+ {
+ $word_id_sql .= ", ";
+ }
+ $word_id_sql .= $word_id_list[$i]['word_id'];
+ }
+ $word_id_sql = " AND sl.word_id IN ($word_id_sql)";
+
+ $sql = "SELECT sl.word_id, SUM(sm.word_count) AS post_occur_count
+ FROM phpbb_search_wordlist sl, phpbb_search_wordmatch sm
+ WHERE sl.word_id = sm.word_id
+ $word_id_sql
+ GROUP BY sl.word_id
+ ORDER BY post_occur_count DESC";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Couldn't obtain search word sums", "", __LINE__, __FILE__, $sql);
+ }
+
+ if( $post_count = $db->sql_numrows($result) )
+ {
+ $rowset = $db->sql_fetchrowset($result);
+
+ $sql = "SELECT COUNT(post_id) AS total_posts
+ FROM phpbb_posts";
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't obtain post count", "", __LINE__, __FILE__, $sql);
+ }
+
+ $row = $db->sql_fetchrow($result);
+
+ $words_removed = 0;
+
+ for($i = 0; $i < $post_count; $i++)
+ {
+ if( ( $rowset[$i]['post_occur_count'] / $row['total_posts'] ) >= $percent )
+ {
+ $sql = "DELETE FROM phpbb_search_wordlist
+ WHERE word_id = " . $rowset[$i]['word_id'];
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't delete word list entry", "", __LINE__, __FILE__, $sql);
+ }
+
+ $sql = "DELETE FROM phpbb_search_wordmatch
+ WHERE word_id = " . $rowset[$i]['word_id'];
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't delete word match entry", "", __LINE__, __FILE__, $sql);
+ }
+
+ $words_removed++;
+ }
+ }
+ }
+ }
+
+ return $words_removed;
+ }
+
+ function remove_old_words($post_id)
+ {
+ global $db, $phpbb_root_path, $board_config, $lang;
+
+ $stopword_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_stopwords.txt");
+ $synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt");
+
+ $sql = "SELECT post_text
+ FROM " . POSTS_TEXT_TABLE . "
+ WHERE post_id = $post_id";
+ if( $result = $db->sql_query($sql) )
+ {
+ $row = $db->sql_fetchrow($result);
+ // print_r($row);
+
+ $search_text = clean_words($row['post_text'], $stopword_array, $synonym_array);
+ $search_matches = split_words($search_text);
+
+ if( count($search_matches) )
+ {
+ $word = array();
+ $word_count = array();
+ $phrase_string = $text;
+
+ $sql_in = "";
+ for ($j = 0; $j < count($search_matches); $j++)
+ {
+ $this_word = strtolower(trim($search_matches[$j]));
+
+ if( empty($word_count[$this_word]) )
+ {
+ $word_count[$this_word] = 1;
+ }
+
+ $new_word = true;
+ for($k = 0; $k < count($word); $k++)
+ {
+ if( $this_word == $word[$k] )
+ {
+ $new_word = false;
+ $word_count[$this_word]++;
+ }
+ }
+
+ if( $new_word )
+ {
+ $word[] = $this_word;
+ }
+ }
+
+ for($j = 0; $j < count($word); $j++)
+ {
+ if( $word[$j] )
+ {
+ if( $sql_in != "" )
+ {
+ $sql_in .= ", ";
+ }
+ $sql_in .= "'" . $word[$j] . "'";
+ }
+ }
+
+ $sql = "SELECT word_id, word_text
+ FROM phpbb_search_wordlist
+ WHERE word_text IN ($sql_in)";
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't select words", "", __LINE__, __FILE__, $sql);
+ }
+
+ if( $word_check_count = $db->sql_numrows($result) )
+ {
+ $check_words = $db->sql_fetchrowset($result);
+
+ // print_r($check_words);
+
+ $word_id_sql = "";
+ for($i = 0; $i < count($check_words); $i++ )
+ {
+ if( $word_id_sql != "" )
+ {
+ $word_id_sql .= ", ";
+ }
+ $word_id_sql .= $check_words[$i]['word_id'];
+ }
+ $word_id_sql = "word_id IN ($word_id_sql)";
+
+ $sql = "SELECT word_id, COUNT(post_id) AS post_occur_count
+ FROM phpbb_search_wordmatch
+ WHERE $word_id_sql
+ GROUP BY word_id
+ ORDER BY post_occur_count DESC";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Couldn't obtain search word sums", "", __LINE__, __FILE__, $sql);
+ }
+
+ if( $post_count = $db->sql_numrows($result) )
+ {
+ $rowset = $db->sql_fetchrowset($result);
+
+ // print_r($rowset);
+
+ for($i = 0; $i < $post_count; $i++)
+ {
+ // echo $rowset[$i]['post_occur_count'] . "<BR>";
+ if( $rowset[$i]['post_occur_count'] == 1 )
+ {
+ $sql = "DELETE FROM phpbb_search_wordlist
+ WHERE word_id = " . $rowset[$i]['word_id'];
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't delete word list entry", "", __LINE__, __FILE__, $sql);
+ }
+ }
+ }
+ }
+
+ $sql = "DELETE FROM phpbb_search_wordmatch
+ WHERE post_id = $post_id";
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't delete word match entry for this post", "", __LINE__, __FILE__, $sql);
+ }
+ }
+ }
+ }
+ else
+ {
+ message_die(GENERAL_ERROR, "Couldn't obtain post text", "", __LINE__, __FILE__, $sql);
+ }
+
+ return;
+ }
+
+ function add_search_words($post_id, $text)
+ {
+ global $db, $phpbb_root_path, $board_config, $lang;
+
+ $stopword_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_stopwords.txt");
+ $synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt");
+
+ $search_text = clean_words($text, $stopword_array, $synonym_array);
+ $search_matches = split_words($search_text);
+
+ if( count($search_matches) )
+ {
+ $word = array();
+ $word_count = array();
+ $phrase_string = $text;
+
+ $sql_in = "";
+ for ($j = 0; $j < count($search_matches); $j++)
+ {
+ $this_word = strtolower(trim($search_matches[$j]));
+
+ if( empty($word_count[$this_word]) )
+ {
+ $word_count[$this_word] = 1;
+ }
+
+ $new_word = true;
+ for($k = 0; $k < count($word); $k++)
+ {
+ if( $this_word == $word[$k] )
+ {
+ $new_word = false;
+ $word_count[$this_word]++;
+ }
+ }
+
+ if( $new_word )
+ {
+ $word[] = $this_word;
+ }
+ }
+
+ for($j = 0; $j < count($word); $j++)
+ {
+ if( $word[$j] )
+ {
+ if( $sql_in != "" )
+ {
+ $sql_in .= ", ";
+ }
+ $sql_in .= "'" . $word[$j] . "'";
+ }
+ }
+
+ $sql = "SELECT word_id, word_text
+ FROM phpbb_search_wordlist
+ WHERE word_text IN ($sql_in)";
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't select words", "", __LINE__, __FILE__, $sql);
+ }
+
+ if( $word_check_count = $db->sql_numrows($result) )
+ {
+ $check_words = $db->sql_fetchrowset($result);
+ }
+
+ for ($j = 0; $j < count($word); $j++)
+ {
+ if( $word[$j] )
+ {
+ $new_match = true;
+
+ if( $word_check_count )
+ {
+ for($k = 0; $k < $word_check_count; $k++)
+ {
+ if( $word[$j] == $check_words[$k]['word_text'] )
+ {
+ $new_match = false;
+ $word_id = $check_words[$k]['word_id'];
+ }
+ }
+ }
+
+ if( $new_match )
+ {
+ $sql = "INSERT INTO phpbb_search_wordlist (word_text)
+ VALUES ('". addslashes($word[$j]) . "')";
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't insert new word", "", __LINE__, __FILE__, $sql);
+ }
+
+ $word_id = $db->sql_nextid();
+ }
+
+ $sql = "INSERT INTO phpbb_search_wordmatch (post_id, word_id, word_count, title_match)
+ VALUES ($post_id, $word_id, " . $word_count[$word[$j]] . ", 0)";
+ $result = $db->sql_query($sql);
+ if( !$result )
+ {
+ message_die(GENERAL_ERROR, "Couldn't insert new word match", "", __LINE__, __FILE__, $sql);
+ }
+ }
+ }
+ }
+
+ remove_common(0.25, $check_words);
+
+ return;
+ }
+
function topic_review($topic_id, $is_inline_review)
{
***************
*** 908,912 ****
$result = ($mode == "reply") ? $db->sql_query($sql, BEGIN_TRANSACTION) : $db->sql_query($sql);
! if($result)
{
$new_post_id = $db->sql_nextid();
--- 1313,1317 ----
$result = ($mode == "reply") ? $db->sql_query($sql, BEGIN_TRANSACTION) : $db->sql_query($sql);
! if( $result )
{
$new_post_id = $db->sql_nextid();
***************
*** 915,919 ****
VALUES ($new_post_id, '$post_subject', '$post_message')";
! if($db->sql_query($sql))
{
$sql = "UPDATE " . TOPICS_TABLE . "
--- 1320,1324 ----
VALUES ($new_post_id, '$post_subject', '$post_message')";
! if( $db->sql_query($sql) )
{
$sql = "UPDATE " . TOPICS_TABLE . "
***************
*** 925,933 ****
$sql .= " WHERE topic_id = $new_topic_id";
! if($db->sql_query($sql))
{
$sql = "UPDATE " . FORUMS_TABLE . "
SET forum_last_post_id = $new_post_id, forum_posts = forum_posts + 1";
! if($mode == "newtopic")
{
$sql .= ", forum_topics = forum_topics + 1";
--- 1330,1338 ----
$sql .= " WHERE topic_id = $new_topic_id";
! if( $db->sql_query($sql) )
{
$sql = "UPDATE " . FORUMS_TABLE . "
SET forum_last_post_id = $new_post_id, forum_posts = forum_posts + 1";
! if( $mode == "newtopic" )
{
$sql .= ", forum_topics = forum_topics + 1";
***************
*** 936,940 ****
$sql .= " WHERE forum_id = $forum_id";
! if($db->sql_query($sql))
{
$sql = "UPDATE " . USERS_TABLE . "
--- 1341,1345 ----
$sql .= " WHERE forum_id = $forum_id";
! if( $db->sql_query($sql) )
{
$sql = "UPDATE " . USERS_TABLE . "
***************
*** 942,947 ****
WHERE user_id = " . $userdata['user_id'];
! if($db->sql_query($sql, END_TRANSACTION))
{
//
// Email users who are watching this topic
--- 1347,1354 ----
WHERE user_id = " . $userdata['user_id'];
! if( $db->sql_query($sql, END_TRANSACTION))
{
+ add_search_words($new_post_id, stripslashes($post_message));
+
//
// Email users who are watching this topic
***************
*** 1248,1255 ****
if( $delete || $mode == "delete" )
{
$sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = $post_id";
-
if($db->sql_query($sql, BEGIN_TRANSACTION))
{
--- 1655,1662 ----
if( $delete || $mode == "delete" )
{
+ remove_old_words($post_id);
$sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = $post_id";
if($db->sql_query($sql, BEGIN_TRANSACTION))
{
***************
*** 1258,1262 ****
if($db->sql_query($sql))
{
-
if( $is_last_post_topic && $is_first_post_topic )
{
--- 1665,1668 ----
***************
*** 1379,1383 ****
$message = $lang['Deleted'];
! if( !$is_first_post_topic && !$is_last_post_topic )
{
$template->assign_vars(array(
--- 1785,1789 ----
$message = $lang['Deleted'];
! if( !$is_first_post_topic || !$is_last_post_topic )
{
$template->assign_vars(array(
***************
*** 1473,1480 ****
}
$sql = "UPDATE " . POSTS_TABLE . "
SET bbcode_uid = '$bbcode_uid', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig" . $edited_sql . "
WHERE post_id = $post_id";
-
if($db->sql_query($sql, BEGIN_TRANSACTION))
{
--- 1879,1887 ----
}
+ remove_old_words($post_id);
+
$sql = "UPDATE " . POSTS_TABLE . "
SET bbcode_uid = '$bbcode_uid', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig" . $edited_sql . "
WHERE post_id = $post_id";
if($db->sql_query($sql, BEGIN_TRANSACTION))
{
***************
*** 1487,1490 ****
--- 1894,1899 ----
if( $db->sql_query($sql) )
{
+ add_search_words($post_id, stripslashes($post_message));
+
//
// Update topics table here
***************
*** 1605,1615 ****
}
}
- else
- {
-
- }
}
else
{
if( $db->sql_query($sql, END_TRANSACTION) )
{
--- 2014,2023 ----
}
}
}
else
{
+ remove_old_words($post_id);
+ add_search_words($post_id, stripslashes($post_message));
+
if( $db->sql_query($sql, END_TRANSACTION) )
{
***************
*** 1951,1955 ****
}
! $post_message = preg_replace("/(|\:1)\:$post_bbcode_uid(|\:[a-z])/si", "", $post_message);
$post_message = str_replace("<br />", "\n", $post_message);
$post_message = preg_replace($html_entities_match, $html_entities_replace, $post_message);
--- 2359,2363 ----
}
! $post_message = preg_replace("/\:$post_bbcode_uid(|\:[a-z])/si", "", $post_message);
$post_message = str_replace("<br />", "\n", $post_message);
$post_message = preg_replace($html_entities_match, $html_entities_replace, $post_message);
***************
*** 2140,2145 ****
"L_POSTED" => $lang['Posted'])
);
! $template->pparse("preview");
!
}
//
--- 2548,2552 ----
"L_POSTED" => $lang['Posted'])
);
! $template->assign_var_from_handle("POST_PREVIEW_BOX", "preview");
}
//
***************
*** 2158,2162 ****
"ERROR_MESSAGE" => $error_msg)
);
! $template->pparse("reg_header");
}
//
--- 2565,2569 ----
"ERROR_MESSAGE" => $error_msg)
);
! $template->assign_var_from_handle("ERROR_BOX", "reg_header");
}
//
|