#', '#"#');
$html_entities_replace = array('&', '<', '>', '"');
$unhtml_specialchars_match = array('#>#', '#<#', '#"#', '#&#');
$unhtml_specialchars_replace = array('>', '<', '"', '&');
//
// Post an addon to the existing post
//
function submit_merged_post($post_id, $forum_id, $subject, $message, &$return_message, &$return_meta)
{
global $board_config, $db, $lang, $phpEx, $phpbb_root_path;
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_merge.' . $phpEx);
include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
$current_time = time();
// Check message
if ( empty($message) )
{
message_die(GENERAL_MESSAGE, $lang['Empty_message']);
}
$sql = "SELECT p.post_created, p.post_time, p.enable_html, p.enable_bbcode, p.enable_smilies, pt.*
FROM " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE ." pt
WHERE p.post_id = $post_id
AND pt.post_id = p.post_id";
$result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not obtain last post information', '', __LINE__, __FILE__, $sql);
$last_post_data = $db->sql_fetchrow($result);
// Flood control
if ( ($current_time - intval($last_post_data['post_time'])) < intval($board_config['merge_flood_interval']) )
{
message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
}
$last_post_created = $last_post_data['post_created'];
$last_post_time = $last_post_data['post_time'];
$last_html = $last_post_data['enable_html'];
$last_bbcode = $last_post_data['enable_bbcode'];
$last_smilies = $last_post_data['enable_smilies'];
$last_bbcode_uid = $last_post_data['bbcode_uid'];
$last_subject = $last_post_data['post_subject'];
$last_message = $last_post_data['post_text'];
$db->sql_freeresult($result);
if ($last_bbcode_uid != '')
{
$last_message = preg_replace('/\:(([a-z0-9]:)?)' . $last_bbcode_uid . '/s', '', $last_message);
}
$last_message = unprepare_message($last_message);
// Adding slashes, we need this step for comparison
$last_subject = addslashes($last_subject);
$last_message = addslashes($last_message);
// Preparing separator
$merged_after = ($current_time - $last_post_time);
$merged_sec = $merged_after % 60;
$merged_min = ($merged_after/60) % 60;
$merged_hours = ($merged_after/3600) % 24 ;
$merged_days = ($merged_after/86400) % 31;
$s_st = ($merged_sec) ? seconds_st($merged_sec) : '';
$m_st = ($merged_min) ? minutes_st($merged_min) : '';
$h_st = ($merged_hours) ? hours_st($merged_hours) : '';
$d_st = ($merged_days) ? days_st($merged_days) : '';
$separator = sprintf($lang['Merge_separator'],$d_st,$h_st,$m_st,$s_st);
$separator .= ( !empty($subject) && ($subject != $last_subject) ) ? sprintf($lang['Merge_post_subject'], $subject) : '';
$separator = str_replace("'", "''", $separator);
$message = ($message != $last_message) ? $last_message . $separator . trim($message) : trim($message);
$message = prepare_message($message, $last_html, $last_bbcode, $last_smilies, $last_bbcode_uid);
// This replacement was borrowed from posting.php
$last_subject = str_replace("\'", "''", $last_subject);
$last_message = str_replace("\'", "''", $last_message);
$sql = "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '$message' WHERE post_id = $post_id";
$result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not update post text information', '', __LINE__, __FILE__, $sql);
$sql = "UPDATE " . POSTS_TABLE . " SET post_time = $current_time WHERE post_id = $post_id";
$result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not update last post time', '', __LINE__, __FILE__, $sql);
$sql = "UPDATE " . FORUMS_TABLE . " SET forum_last_post_id = $post_id WHERE forum_id = $forum_id";
$result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not update forum last post id', '', __LINE__, __FILE__, $sql);
// Search routines
remove_search_post($post_id);
add_search_words('single', $post_id, stripslashes($message), stripslashes($subject));
// Meta & return message
$return_meta = '';
$return_message = $lang['Stored'] . '
' . sprintf($lang['Click_view_message'], '', '') . '
' . sprintf($lang['Click_return_forum'], '', '');
}
//
// This function will prepare a posted message for
// entry into the database.
//
function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0)
{
global $board_config, $html_entities_match, $html_entities_replace;
//
// Clean up the message
//
$message = trim($message);
if ($html_on)
{
// If HTML is on, we try to make it safe
// This approach is quite agressive and anything that does not look like a valid tag
// is going to get converted to HTML entities
$message = stripslashes($message);
$html_match = '#<[^\w<]*(\w+)((?:"[^"]*"|\'[^\']*\'|[^<>\'"])+)?>#';
$matches = array();
$message_split = preg_split($html_match, $message);
preg_match_all($html_match, $message, $matches);
$message = '';
foreach ($message_split as $part)
{
$tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2]));
$message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag);
}
$message = addslashes($message);
$message = str_replace('"', '\"', $message);
}
else
{
$message = preg_replace($html_entities_match, $html_entities_replace, $message);
}
if($bbcode_on && $bbcode_uid != '')
{
$message = bbencode_first_pass($message, $bbcode_uid);
}
/* ---8<--------[Detector Bots]----------------------------------------- */
global $unhtml_specialchars_match, $unhtml_specialchars_replace,$client_ip,$user_ip,$db,$userdata,$phpbb_root_path,$phpEx,$lang;
$first_post_max_link = 1; // позволено линков Гостю и Юзеру в самом первом посте, все слепленные считаются одним постом
$newbie_max_link = 100; // позволено линков новичку, написавшему более 1 поста
$oldbie_minposts = 100; // старичком считаем юзера, написавшего хотя бы 16 постов
$oldbie_max_link = 100; // позволено линков старичку
$use_yellowcard = false; // штрафовать юзера. Если MOD YellowCard установлен, поставить TRUE
$APM_mod_installed = false; // Если MOD Advanced Posts Merging 2.x установлен, поставить TRUE
$send_email_to_admin = true; // отправлять уведомление админу
$admin_email = $board_config['board_email']; // электропочта администратора форума ИЛИ
// $admin_email = "info@cwtcrew.org"; // ящик для спама.
$link_count = 0; // инициализация счетчика
preg_match_all('#(\[url(.*?)\[\/url\])|(([\n ]href=(.*?)>)|((^|[\n ])([\w]+?://|www|ftp)[^ \"\n\r\t<>]*))|((^|[\n ]|mailto:)([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+))#si', $message, $links);
if (isset($links[1])) {$link_count += count($links[1]);}
if ($userdata['user_level'] == ADMIN && $userdata['session_logged_in']) {$link_count=0;} // Admin can post anything
if ($userdata['user_id'] == ANONYMOUS)
{
if ($link_count > $first_post_max_link)
{
if ($send_email_to_admin)
{
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$emailer = new emailer($board_config['smtp_delivery']);
$emailer->from($board_config['board_email']);
$emailer->replyto($board_config['board_email']);
$emailer->use_template('detector_bot', $board_config['default_lang']);
$emailer->email_address($admin_email);
$emailer->set_subject($lang['D_Bots_email_subj']);
$emailer->assign_vars(array(
'SITENAME' => $board_config['sitename'],
'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('
', "\n", "-- \n" . $board_config['board_email_sig']) : '',
'IP' => $client_ip,
'POSTS' => '',
'LINKS' => $link_count,
'RESULT' => $lang['D_Bots_post_not_sent'],
'USERNAME' => substr(preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", $userdata['username'])), 0, 25),
'MESSAGE' => substr(preg_replace('/\<(.*?)>/i','',preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", bbencode_second_pass($message, $bbcode_uid)))), 0, 1000),
'SUB' => substr(preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", $GLOBALS['subject'])), 0, 100)));
$emailer->send();
$emailer->reset();
}
message_die(GENERAL_MESSAGE, $lang['D_Bots_msg_guest']);
}
}
elseif ($userdata['user_posts'] < ($APM_mod_installed ? 2 : 1) && $link_count > $first_post_max_link) // 1st post.
{
// grrr... spammer... kill user & message! without warning...
$sql = "DELETE FROM " . SESSIONS_TABLE . " WHERE session_ip ='$user_ip'";
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Error clearing session', '', __LINE__, __FILE__, $sql); }
$sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE user_id = ".$userdata['user_id'];
if ($row = $db->sql_fetchrow($db->sql_query($sql)))
{
$sql = "DELETE FROM " . GROUPS_TABLE . " WHERE group_id = ".$row['group_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Error deleting group', '', __LINE__, __FILE__, $sql); }
}
$sql = "DELETE FROM " . USER_GROUP_TABLE . " WHERE user_id = ".$userdata['user_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Error deleting user to group', '', __LINE__, __FILE__, $sql); }
$sql = "DELETE FROM " . USERS_TABLE . " WHERE user_id = ".$userdata['user_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Error deleting user', '', __LINE__, __FILE__, $sql); }
// clean forums correctly (Advanced Posts Merging Support)
if (isset($GLOBALS['topic_id']) && $GLOBALS['topic_id']!='' && !is_null($GLOBALS['topic_id']))
{
// $sql = "DELETE p.* FROM ".POSTS_TABLE." p LEFT JOIN ".USERS_TABLE." u ON p.poster_id = u.user_id WHERE (u.user_id Is Null)";
// if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Cannot delete posts', '', __LINE__, __FILE__, $sql); }
$sql = "SELECT p.* FROM ".POSTS_TABLE." p LEFT JOIN ".USERS_TABLE." u ON p.poster_id = u.user_id WHERE (u.user_id Is Null)";
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Cannot select posts', '', __LINE__, __FILE__, $sql); }
while ($row = $db->sql_fetchrow($result)) {
$sql = "DELETE FROM ".POSTS_TABLE." WHERE post_id = ".$row['post_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Cannot delete posts', '', __LINE__, __FILE__, $sql); }
}
// $sql = "DELETE pt.* FROM ".POSTS_TEXT_TABLE." pt LEFT JOIN ".POSTS_TABLE." p ON p.post_id = pt.post_id WHERE (p.post_id Is Null)";
// if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Cannot delete post texts', '', __LINE__, __FILE__, $sql); }
$sql = "SELECT pt.* FROM ".POSTS_TEXT_TABLE." pt LEFT JOIN ".POSTS_TABLE." p ON p.post_id = pt.post_id WHERE (p.post_id Is Null)";
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Cannot select post', '', __LINE__, __FILE__, $sql); }
while ($row = $db->sql_fetchrow($result)) {
$sql = "DELETE FROM ".POSTS_TEXT_TABLE." WHERE post_id = ".$row['post_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Cannot delete post text', '', __LINE__, __FILE__, $sql); }
}
// synchronize topics & forums
$sql = "SELECT MIN(post_id) AS first_post, MAX(post_id) AS last_post FROM ".POSTS_TABLE." WHERE topic_id = ".$GLOBALS['topic_id'];
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql); }
if ($row = $db->sql_fetchrow($result))
{
$first_post = ( $row['first_post'] ) ? $row['first_post'] : 0;
$last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
}
else
{
$first_post = $last_post = 0;
}
if ($first_post!=0 && $last_post!=0)
{
$sql = "UPDATE ".TOPICS_TABLE." SET topic_first_post_id = $first_post, topic_last_post_id = $last_post WHERE topic_id = ".$GLOBALS['topic_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql); }
}
else
{
// topic's empty, so kill empty topics
// $sql = "DELETE t.* FROM ".TOPICS_TABLE." t LEFT JOIN ".POSTS_TABLE." p ON p.topic_id = t.topic_id WHERE (p.topic_id Is Null)";
// if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Cannot delete post texts', '', __LINE__, __FILE__, $sql); }
$sql = "SELECT t.* FROM ".TOPICS_TABLE." t LEFT JOIN ".POSTS_TABLE." p ON p.topic_id = t.topic_id WHERE (p.topic_id Is Null)";
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Cannot select post', '', __LINE__, __FILE__, $sql); }
while ($row = $db->sql_fetchrow($result)) {
$sql = "DELETE FROM ".TOPICS_TABLE." WHERE topic_id = ".$row['topic_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Cannot delete topic', '', __LINE__, __FILE__, $sql); }
}
}
$sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total FROM ".POSTS_TABLE." WHERE forum_id = ".$GLOBALS['forum_id'];
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql); }
if ($row = $db->sql_fetchrow($result))
{
$last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
$total_posts = ($row['total']) ? $row['total'] : 0;
}
else
{
$last_post = $total_posts = 0;
}
$sql = "SELECT COUNT(topic_id) AS total FROM ".TOPICS_TABLE." WHERE forum_id = ".$GLOBALS['forum_id'];
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql); }
$total_topics = ( $row = $db->sql_fetchrow($result) ) ? ( ( $row['total'] ) ? $row['total'] : 0 ) : 0;
$sql = "UPDATE ".FORUMS_TABLE." SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics WHERE forum_id = ".$GLOBALS['forum_id'];
if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql); }
}
if ($send_email_to_admin)
{
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$emailer = new emailer($board_config['smtp_delivery']);
$emailer->from($board_config['board_email']);
$emailer->replyto($board_config['board_email']);
$emailer->use_template('detector_bot', $board_config['default_lang']);
$emailer->email_address($admin_email);
$emailer->set_subject($lang['D_Bots_email_subj']);
$emailer->assign_vars(array(
'SITENAME' => $board_config['sitename'],
'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('
', "\n", "-- \n" . $board_config['board_email_sig']) : '',
'IP' => $client_ip,
'POSTS' => $userdata['user_posts'],
'LINKS' => $link_count,
'RESULT' => $lang['D_Bots_post_deleted'].' '.$lang['D_Bots_user_deleted'],
'USERNAME' => substr(preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", $userdata['username'])), 0, 25),
'MESSAGE' => substr(preg_replace('/\<(.*?)>/i','',preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", bbencode_second_pass($message, $bbcode_uid)))), 0, 1000),
'SUB' => substr(preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", $GLOBALS['subject'])), 0, 100)));
$emailer->send();
$emailer->reset();
}
message_die(GENERAL_MESSAGE, sprintf($lang['D_Bots_msg_user_deleted'], $userdata['username']));
}
elseif (($userdata['user_posts'] < $oldbie_minposts && $link_count > $newbie_max_link) || ($link_count > $oldbie_max_link))
{
if ($use_yellowcard)
{
$sql = "SELECT user_warnings FROM " . USERS_TABLE . " WHERE user_id = ".$userdata['user_id'];
if ($row = $db->sql_fetchrow($db->sql_query($sql)))
{
$sql = "UPDATE " . USERS_TABLE . " SET user_warnings = ".(intval($row['user_warnings'])+1)." WHERE user_id = ".$userdata['user_id'];
if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'SQL Quering error', '', __LINE__, __FILE__, $sql); }
}
else
{
message_die(GENERAL_ERROR, 'SQL Quering error', '', __LINE__, __FILE__, $sql);
}
}
if ($send_email_to_admin)
{
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$emailer = new emailer($board_config['smtp_delivery']);
$emailer->from($board_config['board_email']);
$emailer->replyto($board_config['board_email']);
$emailer->use_template('detector_bot', $board_config['default_lang']);
$emailer->email_address($admin_email);
$emailer->set_subject($lang['D_Bots_email_subj']);
$emailer->assign_vars(array(
'SITENAME' => $board_config['sitename'],
'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('
', "\n", "-- \n" . $board_config['board_email_sig']) : '',
'IP' => $client_ip,
'POSTS' => $userdata['user_posts'],
'LINKS' => $link_count,
'RESULT' => $lang['D_Bots_post_not_sent'].($use_yellowcard ? ' '.sprintf($lang['D_Bots_user_mulcted'], $row['user_warnings']+1, $board_config['max_user_bancard']):''),
'USERNAME' => substr(preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", $userdata['username'])), 0, 25),
'MESSAGE' => substr(preg_replace('/\<(.*?)>/i','',preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", bbencode_second_pass($message, $bbcode_uid)))), 0, 1000),
'SUB' => substr(preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, str_replace("\'", "'", $GLOBALS['subject'])), 0, 100)));
$emailer->send();
$emailer->reset();
}
message_die(GENERAL_MESSAGE, sprintf($lang['D_Bots_msg_user_mulcted'], $userdata['username']));
}
/* ---8<--------[Detector Bots]----------------------------------------- */
return $message;
}
function unprepare_message($message)
{
global $unhtml_specialchars_match, $unhtml_specialchars_replace;
return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $message);
}
//
// Prepare a message for posting
//
function prepare_post(&$mode, &$post_data, &$bbcode_on, &$html_on, &$smilies_on, &$error_msg, &$username, &$bbcode_uid, &$subject, &$message, &$poll_title, &$poll_options, &$poll_length)
{
global $board_config, $userdata, $lang, $phpEx, $phpbb_root_path;
// Check username
if (!empty($username))
{
$username = phpbb_clean_username($username);
if (!$userdata['session_logged_in'] || ($userdata['session_logged_in'] && $username != $userdata['username']))
{
include($phpbb_root_path . 'includes/functions_validate.'.$phpEx);
$result = validate_username($username);
if ($result['error'])
{
$error_msg .= (!empty($error_msg)) ? '
' . $result['error_msg'] : $result['error_msg'];
}
}
else
{
$username = '';
}
}
// Check subject
if (!empty($subject))
{
$subject = htmlspecialchars(trim($subject));
}
else if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
{
$error_msg .= (!empty($error_msg)) ? '
' . $lang['Empty_subject'] : $lang['Empty_subject'];
}
// Check message
if (!empty($message))
{
$bbcode_uid = ($bbcode_on) ? make_bbcode_uid() : '';
$message = prepare_message(trim($message), $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
}
else if ($mode != 'delete' && $mode != 'poll_delete')
{
$error_msg .= (!empty($error_msg)) ? '
' . $lang['Empty_message'] : $lang['Empty_message'];
}
//
// Handle poll stuff
//
if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
{
$poll_length = (isset($poll_length)) ? max(0, intval($poll_length)) : 0;
if (!empty($poll_title))
{
$poll_title = htmlspecialchars(trim($poll_title));
}
if(!empty($poll_options))
{
$temp_option_text = array();
while(list($option_id, $option_text) = @each($poll_options))
{
$option_text = trim($option_text);
if (!empty($option_text))
{
$temp_option_text[intval($option_id)] = htmlspecialchars($option_text);
}
}
$option_text = $temp_option_text;
if (count($poll_options) < 2)
{
$error_msg .= (!empty($error_msg)) ? '
' . $lang['To_few_poll_options'] : $lang['To_few_poll_options'];
}
else if (count($poll_options) > $board_config['max_poll_options'])
{
$error_msg .= (!empty($error_msg)) ? '
' . $lang['To_many_poll_options'] : $lang['To_many_poll_options'];
}
else if ($poll_title == '')
{
$error_msg .= (!empty($error_msg)) ? '
' . $lang['Empty_poll_title'] : $lang['Empty_poll_title'];
}
}
}
return;
}
//
// Post a new topic/reply/poll or edit existing post/poll
//
function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, &$bbcode_on, &$html_on, &$smilies_on, &$attach_sig, &$bbcode_uid, $post_username, $post_subject, $post_message, $poll_title, &$poll_options, &$poll_length)
{
global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
global $userdata, $user_ip;
include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
$current_time = time();
//
// MOD: No Flood Control For Mods And Admins by Berend Dekens
// Retreive authentication info to determine if this user has moderator status
//
$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
$is_mod = $is_auth['auth_mod'];
if (($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost') && !$is_mod)
{
//
// Flood control
//
$where_sql = ($userdata['user_id'] == ANONYMOUS) ? "poster_ip = '$user_ip'" : 'poster_id = ' . $userdata['user_id'];
$sql = "SELECT MAX(post_time) AS last_post_time
FROM " . POSTS_TABLE . "
WHERE $where_sql";
if ($result = $db->sql_query($sql))
{
if ($row = $db->sql_fetchrow($result))
{
if (intval($row['last_post_time']) > 0 && ($current_time - intval($row['last_post_time'])) < intval($board_config['flood_interval']))
{
message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
}
}
}
}
if ($mode == 'editpost')
{
remove_search_post($post_id);
}
if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
{
$topic_vote = (!empty($poll_title) && count($poll_options) >= 2) ? 1 : 0;
$sql = ($mode != "editpost") ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '$post_subject', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . " WHERE topic_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
if ($mode == 'newtopic')
{
$topic_id = $db->sql_nextid();
}
}
$edited_sql = ($mode == 'editpost' && !$post_data['last_post'] && $post_data['poster_post']) ? ", post_edit_time = $current_time, post_edit_count = post_edit_count + 1 " : "";
$sql = ($mode != "editpost") ? "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, post_created, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $attach_sig)" : "UPDATE " . POSTS_TABLE . " SET post_username = '$post_username', 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))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
if ($mode != 'editpost')
{
$post_id = $db->sql_nextid();
}
$sql = ($mode != 'editpost') ? "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($post_id, '$post_subject', '$bbcode_uid', '$post_message')" : "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '$post_message', bbcode_uid = '$bbcode_uid', post_subject = '$post_subject' WHERE post_id = $post_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
////democracy/////
if ($mode == 'editpost' && $post_data['poster_id'] != $userdata['user_id'])
{
db_query('UPDATE {POSTS_TABLE} SET post_locked = %d WHERE post_id = %d', $post_data['post_locked'], $post_id);
}
/////////////
add_search_words('single', $post_id, stripslashes($post_message), stripslashes($post_subject));
//
// Add poll
//
if (($mode == 'newtopic' || ($mode == 'editpost' && $post_data['edit_poll'])) && !empty($poll_title) && count($poll_options) >= 2)
{
$sql = (!$post_data['has_poll']) ? "INSERT INTO " . VOTE_DESC_TABLE . " (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ($poll_length * 86400) . ")" : "UPDATE " . VOTE_DESC_TABLE . " SET vote_text = '$poll_title', vote_length = " . ($poll_length * 86400) . " WHERE topic_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$delete_option_sql = '';
$old_poll_result = array();
if ($mode == 'editpost' && $post_data['has_poll'])
{
$sql = "SELECT vote_option_id, vote_result
FROM " . VOTE_RESULTS_TABLE . "
WHERE vote_id = $poll_id
ORDER BY vote_option_id ASC";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not obtain vote data results for this topic', '', __LINE__, __FILE__, $sql);
}
while ($row = $db->sql_fetchrow($result))
{
$old_poll_result[$row['vote_option_id']] = $row['vote_result'];
if (!isset($poll_options[$row['vote_option_id']]))
{
$delete_option_sql .= ($delete_option_sql != '') ? ', ' . $row['vote_option_id'] : $row['vote_option_id'];
}
}
}
else
{
$poll_id = $db->sql_nextid();
}
@reset($poll_options);
$poll_option_id = 1;
while (list($option_id, $option_text) = each($poll_options))
{
if (!empty($option_text))
{
$option_text = str_replace("\'", "''", htmlspecialchars($option_text));
$poll_result = ($mode == "editpost" && isset($old_poll_result[$option_id])) ? $old_poll_result[$option_id] : 0;
$sql = ($mode != "editpost" || !isset($old_poll_result[$option_id])) ? "INSERT INTO " . VOTE_RESULTS_TABLE . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($poll_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . VOTE_RESULTS_TABLE . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $poll_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$poll_option_id++;
}
}
if ($delete_option_sql != '')
{
$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
WHERE vote_option_id IN ($delete_option_sql)
AND vote_id = $poll_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql);
}
}
}
$meta = '';
$message = $lang['Stored'] . '
' . sprintf($lang['Click_view_message'], '', '') . '
' . sprintf($lang['Click_return_forum'], '', '');
return false;
}
//
// Update post stats and details
//
function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_id, &$user_id)
{
global $db;
$sign = ($mode == 'delete') ? '- 1' : '+ 1';
$forum_update_sql = "forum_posts = forum_posts $sign";
$topic_update_sql = '';
if ($mode == 'delete')
{
/////////democracy///////////////
db_query('UPDATE {REPUTATION_TABLE} SET post_id = {NO_ID} WHERE post_id = %d', $post_id);
db_query('DELETE FROM {POST_REPORTS_TABLE} WHERE post_id = %d', $post_id);
////////////////////////
if ($post_data['last_post'])
{
if ($post_data['first_post'])
{
$forum_update_sql .= ', forum_topics = forum_topics - 1';
}
else
{
$topic_update_sql .= 'topic_replies = topic_replies - 1';
$sql = "SELECT MAX(post_id) AS last_post_id
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
$topic_update_sql .= ', topic_last_post_id = ' . $row['last_post_id'];
}
}
if ($post_data['last_topic'])
{
$sql = "SELECT MAX(post_id) AS last_post_id
FROM " . POSTS_TABLE . "
WHERE forum_id = $forum_id";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
$forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0';
}
}
}
else if ($post_data['first_post'])
{
$sql = "SELECT MIN(post_id) AS first_post_id
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
$topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['first_post_id'];
}
}
else
{
$topic_update_sql .= 'topic_replies = topic_replies - 1';
}
}
else if ($mode != 'poll_delete')
{
$forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : "");
$topic_update_sql = "topic_last_post_id = $post_id" . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id");
}
else
{
$topic_update_sql .= 'topic_vote = 0';
}
if ($mode != 'poll_delete')
{
$sql = "UPDATE " . FORUMS_TABLE . " SET
$forum_update_sql
WHERE forum_id = $forum_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
if ($topic_update_sql != '')
{
$sql = "UPDATE " . TOPICS_TABLE . " SET
$topic_update_sql
WHERE topic_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
if ($mode != 'poll_delete')
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_posts = user_posts $sign
WHERE user_id = $user_id";
if (!$db->sql_query($sql, END_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
$sql = "SELECT ug.user_id, g.group_id as g_id, u.user_posts, g.group_count, g.group_count_max FROM " . USERS_TABLE . " u, " . GROUPS_TABLE . " g
LEFT JOIN ". USER_GROUP_TABLE." ug ON g.group_id=ug.group_id AND ug.user_id=$user_id
WHERE u.user_id=$user_id
AND g.group_single_user=0
AND g.group_count_enable=1
AND g.group_moderator<>$user_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error geting users post stat', '', __LINE__, __FILE__, $sql);
}
while ($group_data = $db->sql_fetchrow($result))
{
$user_already_added = (empty($group_data['user_id'])) ? FALSE : TRUE;
$user_add = ($group_data['group_count'] == $group_data['user_posts'] && $user_id!=ANONYMOUS) ? TRUE : FALSE;
$user_remove = ($group_data['group_count'] > $group_data['user_posts'] || $group_data['group_count_max'] < $group_data['user_posts']) ? TRUE : FALSE;
if ($user_add && !$user_already_added)
{
//user join a autogroup
$sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
VALUES (".$group_data['g_id'].", $user_id, '0')";
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error insert users, group count', '', __LINE__, __FILE__, $sql);
}
} else
if ( $user_already_added && $user_remove)
{
//remove user from auto group
$sql = "DELETE FROM " . USER_GROUP_TABLE . "
WHERE group_id=".$group_data['g_id']."
AND user_id=$user_id";
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not remove users, group count', '', __LINE__, __FILE__, $sql);
}
}
}
return;
}
//
// Delete a post/poll
//
function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id)
{
global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
global $userdata, $user_ip;
if ($mode != 'poll_delete')
{
include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
$sql = "DELETE FROM " . POSTS_TABLE . "
WHERE post_id = $post_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = $post_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
if ($post_data['last_post'])
{
if ($post_data['first_post'])
{
$forum_update_sql .= ', forum_topics = forum_topics - 1';
$sql = "DELETE FROM " . TOPICS_TABLE . "
WHERE topic_id = $topic_id
OR topic_moved_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . THANKS_TABLE . "
WHERE topic_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting Thanks post Information', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
}
}
remove_search_post($post_id);
}
if ($mode == 'poll_delete' || ($mode == 'delete' && $post_data['first_post'] && $post_data['last_post']) && $post_data['has_poll'] && $post_data['edit_poll'])
{
$sql = "DELETE FROM " . VOTE_DESC_TABLE . "
WHERE topic_id = $topic_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
WHERE vote_id = $poll_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . VOTE_USERS_TABLE . "
WHERE vote_id = $poll_id";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
}
}
if ($mode == 'delete' && $post_data['first_post'] && $post_data['last_post'])
{
$meta = '';
$message = $lang['Deleted'];
}
else
{
$meta = '';
$message = (($mode == 'poll_delete') ? $lang['Poll_delete'] : $lang['Deleted']) . '
' . sprintf($lang['Click_return_topic'], '', '');
}
$message .= '
' . sprintf($lang['Click_return_forum'], '', '');
return;
}
//
// Handle user notification on new post
//
function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user)
{
global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
global $userdata, $user_ip;
$current_time = time();
if ($mode != 'delete')
{
if ($mode == 'reply' || $mode == 'thank')
{
$sql = "SELECT ban_userid
FROM " . BANLIST_TABLE;
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not obtain banlist', '', __LINE__, __FILE__, $sql);
}
$user_id_sql = '';
while ($row = $db->sql_fetchrow($result))
{
if (isset($row['ban_userid']) && !empty($row['ban_userid']))
{
$user_id_sql .= ', ' . $row['ban_userid'];
}
}
$sql = "SELECT u.user_id, u.user_email, u.user_lang
FROM " . TOPICS_WATCH_TABLE . " tw, " . USERS_TABLE . " u
WHERE tw.topic_id = $topic_id
AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . ")
AND tw.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . "
AND u.user_id = tw.user_id";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql);
}
$update_watched_sql = '';
$bcc_list_ary = array();
if ($row = $db->sql_fetchrow($result))
{
// Sixty second limit
@set_time_limit(60);
do
{
if ($row['user_email'] != '')
{
$bcc_list_ary[$row['user_lang']][] = $row['user_email'];
}
$update_watched_sql .= ($update_watched_sql != '') ? ', ' . $row['user_id'] : $row['user_id'];
}
while ($row = $db->sql_fetchrow($result));
//
// Let's do some checking to make sure that mass mail functions
// are working in win32 versions of php.
//
if (preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
{
$ini_val = (@phpversion() >= '4.0.0') ? 'ini_get' : 'get_cfg_var';
// We are running on windows, force delivery to use our smtp functions
// since php's are broken by default
$board_config['smtp_delivery'] = 1;
$board_config['smtp_host'] = @$ini_val('SMTP');
}
if (sizeof($bcc_list_ary))
{
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$emailer = new emailer($board_config['smtp_delivery']);
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$script_name = ($script_name != '') ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx;
$server_name = trim($board_config['server_name']);
$server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
$server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) . '/' : '/';
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
$emailer->from($board_config['board_email']);
$emailer->replyto($board_config['board_email']);
$topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($topic_title)) : unprepare_message($topic_title);
$vars = array(
'reply' => array('template' => 'topic_notify', 'subject' => $lang['Topic_reply_notification']),
'thank' => array('template' => 'thanks_notify', 'subject' => $lang['Post_thanks_notification'])
);
@reset($bcc_list_ary);
while (list($user_lang, $bcc_list) = each($bcc_list_ary))
{
$emailer->use_template($vars[$mode]['template'], $user_lang);
for ($i = 0; $i < count($bcc_list); $i++)
{
$emailer->bcc($bcc_list[$i]);
}
// The Topic_reply_notification lang string below will be used
// if for some reason the mail template subject cannot be read
// ... note it will not necessarily be in the posters own language!
$emailer->set_subject($vars[$mode]['subject']);
// This is a nasty kludge to remove the username var ... till (if?)
// translators update their templates
$emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);
$emailer->assign_vars(array(
'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('
', "\n", "-- \n" . $board_config['board_email_sig']) : '',
'SITENAME' => $board_config['sitename'],
'TOPIC_TITLE' => $topic_title,
'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
'U_STOP_WATCHING_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_TOPIC_URL . "=$topic_id&unwatch=topic")
);
$emailer->send();
$emailer->reset();
}
}
}
$db->sql_freeresult($result);
if ($update_watched_sql != '')
{
$sql = "UPDATE " . TOPICS_WATCH_TABLE . "
SET notify_status = " . TOPIC_WATCH_NOTIFIED . "
WHERE topic_id = $topic_id
AND user_id IN ($update_watched_sql)";
$db->sql_query($sql);
}
}
$sql = "SELECT topic_id
FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if (!$notify_user && !empty($row['topic_id']))
{
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not delete topic watch information', '', __LINE__, __FILE__, $sql);
}
}
else if ($notify_user && empty($row['topic_id']))
{
$sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not insert topic watch information', '', __LINE__, __FILE__, $sql);
}
}
}
}
//
// Fill smiley templates (or just the variables) with smileys
// Either in a window or inline
//
function generate_smilies($mode, $page_id)
{
global $db, $board_config, $template, $lang, $images, $theme, $phpEx, $phpbb_root_path;
global $user_ip, $session_length, $starttime;
global $userdata;
global $smile_group;
$inline_columns = $board_config['smilies_inline_columns'];
$inline_rows = $board_config['smilies_inline_rows'];
$window_columns = $board_config['smilies_window_columns'];
$where = '';
// get the smiling groups list
$sql = 'SELECT * FROM ' . SMILIES_GROUPS_TABLE .'
ORDER BY sort_key';
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, "Could not obtain emoticon information", "", __LINE__, __FILE__, $sql);
}
$smile_groups = $db->sql_fetchrowset($result);
if ($mode == 'window')
{
$userdata = session_pagestart($user_ip, $page_id);
init_userprefs($userdata);
$gen_simple_header = TRUE;
$page_title = $lang['Emoticons'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(
'smiliesbody' => 'posting_smilies.tpl')
);
}
elseif ($mode == 'window_announcement_text')
{
$userdata = session_pagestart($user_ip, $page_id);
init_userprefs($userdata);
$gen_simple_header = TRUE;
$page_title = $lang['Site_Announcement'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(
'smiliesbody' => 'posting_smilies_announcement_centre_text.tpl')
);
}
$sql = "SELECT emoticon, code, smile_url
FROM " . SMILIES_TABLE . $where . "
ORDER BY sort_key";
if ($result = $db->sql_query($sql))
{
$num_smilies = 0;
$rowset = array();
while ($row = $db->sql_fetchrow($result))
{
if (empty($rowset[$row['smile_url']]))
{
$rowset[$row['smile_url']]['code'] = str_replace("'", "\\'", str_replace('\\', '\\\\', $row['code']));
$rowset[$row['smile_url']]['emoticon'] = $row['emoticon'];
$num_smilies++;
}
}
if ($num_smilies)
{
$smilies_count = ($mode == 'inline') ? min($inline_columns * $inline_rows - 1
, $num_smilies) : $num_smilies;
$smilies_split_row = ($mode == 'inline') ? $inline_columns - 1 : $window_columns - 1;
$s_colspan = 0;
$row = 0;
$col = 0;
while (list($smile_url, $data) = @each($rowset))
{
if (!$col)
{
$template->assign_block_vars('smilies_row', array());
}
$template->assign_block_vars('smilies_row.smilies_col', array(
'SMILEY_CODE' => $data['code'],
'SMILEY_IMG' => $board_config['smilies_path'] . '/' . $smile_url,
'SMILEY_DESC' => $data['emoticon'])
);
$s_colspan = max($s_colspan, $col + 1);
if ($col == $smilies_split_row)
{
if ($mode == 'inline' && $row == $inline_rows - 1)
{
break;
}
$col = 0;
$row++;
}
else
{
$col++;
}
}
if ($mode == 'inline')
{
$template->assign_block_vars('switch_smilies_extra', array());
$template->assign_vars(array(
'L_MORE_SMILIES' => $lang['More_emoticons'],
'U_MORE_SMILIES' => append_sid("posting.$phpEx?mode=smilies"))
);
}
}
$template->assign_vars(array(
'L_NO_SMILES' => $num_smilies ? '' : '' . $lang['smiles_none'] . '',
'L_CURRENT_GROUP' => $current_group['name'],
'L_EMOTICONS' => $lang['Emoticons'],
'L_CLOSE_WINDOW' => $lang['Close_window'],
'S_SMILIES_COLSPAN' => $s_colspan,
'WIN_W' => $current_group['width'],
'WIN_H' => $current_group['height'])
);
}
if ($mode == 'window' || $mode == 'window_announcement_text')
{
$template->pparse('smiliesbody');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
}
/**
* Called from within prepare_message to clean included HTML tags if HTML is
* turned on for that post
* @param array $tag Matching text from the message to parse
*/
function clean_html($tag)
{
global $board_config;
if (empty($tag[0]))
{
return '';
}
$allowed_html_tags = preg_split('/, */', strtolower($board_config['allow_html_tags']));
$disallowed_attributes = '/^(?:style|on)/i';
// Check if this is an end tag
preg_match('/<[^\w\/]*\/[\W]*(\w+)/', $tag[0], $matches);
if (sizeof($matches))
{
if (in_array(strtolower($matches[1]), $allowed_html_tags))
{
return '' . $matches[1] . '>';
}
else
{
return htmlspecialchars('' . $matches[1] . '>');
}
}
// Check if this is an allowed tag
if (in_array(strtolower($tag[1]), $allowed_html_tags))
{
$attributes = '';
if (!empty($tag[2]))
{
preg_match_all('/[\W]*?(\w+)[\W]*?=[\W]*?(["\'])((?:(?!\2).)*)\2/', $tag[2], $test);
for ($i = 0; $i < sizeof($test[0]); $i++)
{
if (preg_match($disallowed_attributes, $test[1][$i]))
{
continue;
}
$attributes .= ' ' . $test[1][$i] . '=' . $test[2][$i] . str_replace(array('[', ']'), array('[', ']'), htmlspecialchars($test[3][$i])) . $test[2][$i];
}
}
if (in_array(strtolower($tag[1]), $allowed_html_tags))
{
return '<' . $tag[1] . $attributes . '>';
}
else
{
return htmlspecialchars('<' . $tag[1] . $attributes . '>');
}
}
// Finally, this is not an allowed tag so strip all the attibutes and escape it
else
{
return htmlspecialchars('<' . $tag[1] . '>');
}
}
?>