enqueue(array( 'smile_replacements', )); $page_cfg['include_bbcode_js'] = true; // // BBCode templates // function get_bbcode_tpl () { $bbcode_tpl = array(); // Quote $bbcode_tpl['quote_open'] = <<
HTML; $bbcode_tpl['quote_username_open'] = <<
HTML; $bbcode_tpl['quote_close'] = <<
HTML; // Code $bbcode_tpl['code_open'] = <<
HTML; $bbcode_tpl['code_close'] = <<
HTML; // Spoiler $bbcode_tpl['spoiler_open'] = <<
HTML; $bbcode_tpl['spoiler_title_open'] = <<

\\1

HTML; $bbcode_tpl['spoiler_close'] = <<
HTML; // Image $bbcode_tpl['img'] = << HTML; $bbcode_tpl['img_aligned'] = << HTML; // HR $bbcode_tpl['hr'] = <<- HTML; array_deep($bbcode_tpl, 'bbcode_tpl_compact'); return $bbcode_tpl; } function bbcode_tpl_compact ($text) { $text = str_compact($text); $text = str_replace('> <', '><', $text); return $text; } // prepare a posted message for entry into the database function prepare_message ($message) { $message = bbcode::clean_up($message); $message = htmlCHR($message, false, ENT_NOQUOTES); return $message; } // Fill smiley templates (or just the variables) with smileys // Either in a window or inline function generate_smilies($mode) { global $bb_cfg, $template, $lang, $user, $datastore; $inline_columns = 4; $inline_rows = 7; $window_columns = 8; if ($mode == 'window') { $user->session_start(); } $data = $datastore->get('smile_replacements'); if ($sql = $data['smile']) { $num_smilies = 0; $rowset = array(); foreach ($sql as $row) { if (empty($rowset[$row['smile_url']])) { $rowset[$row['smile_url']]['code'] = addslashes($row['code']); $rowset[$row['smile_url']]['emoticon'] = $row['emoticon']; $num_smilies++; } } if ($num_smilies) { $smilies_count = ($mode == 'inline') ? min(19, $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' => $bb_cfg['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' && $num_smilies > $inline_rows * $inline_columns) { $template->assign_block_vars('switch_smilies_extra', array()); $template->assign_vars(array( 'U_MORE_SMILIES' => POSTING_URL ."?mode=smilies", )); } $template->assign_vars(array( 'PAGE_TITLE' => $lang['EMOTICONS'], 'S_SMILIES_COLSPAN' => $s_colspan, )); } } if ($mode == 'window') { print_page('posting_smilies.tpl', 'simple'); } } // some functions from vB // ############################################################################# /** * Strips away [quote] tags and their contents from the specified string * * @param string $text Text to be stripped of quote tags * * @return string */ function strip_quotes ($text) { $lowertext = strtolower($text); // find all [quote tags $start_pos = array(); $curpos = 0; do { $pos = strpos($lowertext, '[quote', $curpos); if ($pos !== false) { $start_pos["$pos"] = 'start'; $curpos = $pos + 6; } } while ($pos !== false); if (sizeof($start_pos) == 0) { return $text; } // find all [/quote] tags $end_pos = array(); $curpos = 0; do { $pos = strpos($lowertext, '[/quote', $curpos); if ($pos !== false) { $end_pos["$pos"] = 'end'; $curpos = $pos + 8; } } while ($pos !== false); if (sizeof($end_pos) == 0) { return $text; } // merge them together and sort based on position in string $pos_list = $start_pos + $end_pos; ksort($pos_list); do { // build a stack that represents when a quote tag is opened // and add non-quote text to the new string $stack = array(); $newtext = '[...] '; $substr_pos = 0; foreach ($pos_list AS $pos => $type) { $stacksize = sizeof($stack); if ($type == 'start') { // empty stack, so add from the last close tag or the beginning of the string if ($stacksize == 0) { $newtext .= substr($text, $substr_pos, $pos - $substr_pos); } array_push($stack, $pos); } else { // pop off the latest opened tag if ($stacksize) { array_pop($stack); $substr_pos = $pos + 8; } } } // add any trailing text $newtext .= substr($text, $substr_pos); // check to see if there's a stack remaining, remove those points // as key points, and repeat. Allows emulation of a non-greedy-type // recursion. if ($stack) { foreach ($stack AS $pos) { unset($pos_list["$pos"]); } } } while ($stack); return $newtext; } // ############################################################################# /** * Strips away bbcode from a given string, leaving plain text * * @param string $message Text to be stripped of bbcode tags * @param boolean $stripquotes If true, strip away quote tags AND their contents * @param boolean $fast_and_dirty If true, use the fast-and-dirty method rather than the shiny and nice method * * @return string */ function strip_bbcode ($message, $stripquotes = true, $fast_and_dirty = false, $showlinks = true) { $find = array(); $replace = array(); if ($stripquotes) { // [quote=username] and [quote] $message = strip_quotes($message); } // a really quick and rather nasty way of removing bbcode if ($fast_and_dirty) { // any old thing in square brackets $find[] = '#\[.*/?\]#siU'; $replace = ''; $message = preg_replace($find, $replace, $message); } // the preferable way to remove bbcode else { // simple links $find[] = '#\[(email|url)=("??)(.+)\\2\]\\3\[/\\1\]#siU'; $replace[] = '\3'; // named links $find[] = '#\[(email|url)=("??)(.+)\\2\](.+)\[/\\1\]#siU'; $replace[] = ($showlinks ? '\4 (\3)' : '\4'); // smilies $find[] = '#(?<=^|\W)(:\w+?:)(?=$|\W)#'; $replace[] = ''; // replace $message = preg_replace($find, $replace, $message); // strip out all other instances of [x]...[/x] while (preg_match('#\[([a-z]+)\s*?(?:[^\]]*?)\](.*?)(\[/\1\])#is', $message, $m)) { $message = str_replace($m[0], $m[2], $message); } $replace = array('[*]', '[hr]', '[br]', '[align=center]', '[align=left]', '[align=right]'); $message = str_replace($replace, ' ', $message); } return $message; } function extract_search_words ($text) { global $bb_cfg; $max_words_count = $bb_cfg['max_search_words_per_post']; $min_word_len = max(2, $bb_cfg['search_min_word_len'] - 1); $max_word_len = $bb_cfg['search_max_word_len']; $text = ' ' . str_compact(strip_tags(mb_strtolower($text))) . ' '; $text = str_replace(array('[', ']'), array('[', ']'), $text); // HTML entities like   $text = preg_replace('/(\w*?)&#?[0-9a-z]+;(\w*?)/iu', '', $text); // Remove URL's ((www|ftp)\.[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]*?) $text = preg_replace('#\b[a-z0-9]+://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+(/[0-9a-z\?\.%_\-\+=&/]+)?#u', ' ', $text); $text = str_replace('[url=', ' ', $text); $text = str_replace('?', ' ', $text); $text = str_replace('!', ' ', $text); $text = strip_bbcode($text); // Filter out characters like ^, $, &, change "it's" to "its" $text = preg_replace('#[.,:;]#u', ' ', $text); // short & long words // $text = preg_replace('#(?<=^|\s)(\S{1,'.$min_word_len.'}|\S{'.$max_word_len.',}|\W*)(?=$|\s)#u', ' ', $text); $text = remove_stopwords($text); # $text = replace_synonyms($text); // Trim 1+ spaces to one space and split this string into unique words $text = array_unique(explode(' ', str_compact($text))); // short & long words 2 $text_out = array(); foreach ($text as $word) { if (mb_strlen($word) > $min_word_len && mb_strlen($word) <= $max_word_len) $text_out[] = $word; } $text = $text_out; if (sizeof($text) > $max_words_count) { # shuffle($text); $text = array_splice($text, 0, $max_words_count); } return $text; } function replace_synonyms ($text) { static $syn_match = null, $syn_replace = null; if (is_null($syn_match)) { preg_match_all("#(\w+) (\w+)(\r?\n|$)#", @file_get_contents(LANG_DIR .'search_synonyms.txt'), $m); $syn_match = $m[2]; $syn_replace = $m[1]; array_deep($syn_match, 'pad_with_space'); array_deep($syn_replace, 'pad_with_space'); } return ($syn_match && $syn_replace) ? str_replace($syn_match, $syn_replace, $text) : $text; } function add_search_words ($post_id, $post_message, $topic_title = '', $only_return_words = false) { global $bb_cfg; $text = $topic_title .' '. $post_message; $words = ($text) ? extract_search_words($text) : array(); if ($only_return_words || $bb_cfg['search_engine_type'] == 'sphinx') { return join("\n", $words); } else { DB()->query("DELETE FROM ". BB_POSTS_SEARCH ." WHERE post_id = $post_id"); if ($words_sql = DB()->escape(join("\n", $words))) { DB()->query("REPLACE INTO ". BB_POSTS_SEARCH ." (post_id, search_words) VALUES ($post_id, '$words_sql')"); } } } class bbcode { var $tpl = array(); // шаблоны для замены тегов var $smilies = null; // смайлы var $found_spam = null; // найденные спам "слова" var $del_words = array(); // см. get_words_rate() var $tidy_cfg = array( 'drop-empty-paras' => false, 'fix-uri' => false, 'force-output' => true, 'hide-comments' => true, 'join-classes' => false, 'join-styles' => false, 'merge-divs' => false, 'newline' => 'LF', 'output-xhtml' => true, 'preserve-entities' => true, 'quiet' => true, 'quote-ampersand' => false, 'show-body-only' => true, 'show-errors' => false, 'show-warnings' => false, 'wrap' => 0, ); var $block_tags = array( 'align', 'br', 'clear', 'hr', 'list', 'pre', 'quote', 'spoiler', ); var $preg = array(); var $str = array(); var $preg_search = array(); var $preg_repl = array(); var $str_search = array(); var $str_repl = array(); /** * Constructor */ function bbcode () { $this->tpl = get_bbcode_tpl(); $this->init_replacements(); } /** * init_replacements */ function init_replacements () { $tpl = $this->tpl; $img_exp = '(https?:)?//[^\s\?&;=\#\"<>]+?\.(jpg|jpeg|gif|png|webp|bmp)([a-z0-9/?&%;][^\[\]]*)?'; $email_exp = '[a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+'; $this->preg = array( '#\[quote="(.+?)"\]#isu' => $tpl['quote_username_open'], '#\[spoiler="(.+?)"\]#isu' => $tpl['spoiler_title_open'], '#\[list=(a|A|i|I|1)\]#isu' => '