} $toptitle = cot_breadcrumbs(cot_forums_buildpath($s), $cfg['homebreadcrumb']); $toptitle .= $usr['isadmin'] ? $R['forums_code_admin_mark'] : ''; $sys['sublocation'] = $structure['forums'][$s]['title']; $out['subtitle'] = $L['forums_newtopic']; $out['head'] .= $R['code_noindex']; /* === Hook === */ foreach (cot_getextplugins('forums.newtopic.main') as $pl) { include $pl; } /* ===== */ require_once cot_incfile('forms'); require_once $cfg['system_dir'] . '/header.php'; $mskin = cot_tplfile(array('forums', 'newtopic', $structure['forums'][$s]['tpl'])); $t = new XTemplate($mskin); $t->assign(array('FORUMS_NEWTOPIC_PAGETITLE' => $toptitle, 'FORUMS_NEWTOPIC_SUBTITLE' => htmlspecialchars(cot_parse_autourls($structure['forums'][$s]['desc'])), 'FORUMS_NEWTOPIC_SEND' => cot_url('forums', "m=newtopic&a=newtopic&s=" . $s), 'FORUMS_NEWTOPIC_TITLE' => cot_inputbox('text', 'rtopictitle', $rtopic['ft_title'], array('size' => 56, 'maxlength' => 255)), 'FORUMS_NEWTOPIC_DESC' => cot_inputbox('text', 'rtopicdesc', $rtopic['ft_desc'], array('size' => 56, 'maxlength' => 255)), 'FORUMS_NEWTOPIC_TEXT' => cot_textarea('rmsgtext', $rmsg['fp_text'], 20, 56, '', 'input_textarea_' . $minimaxieditor), 'FORUMS_NEWTOPIC_EDITTIMEOUT' => cot_build_timegap(0, $cfg['forums']['edittimeout'] * 3600))); // Extra fields foreach ($cot_extrafields[$db_forum_posts] as $exfld) { $uname = strtoupper($exfld['field_name']); $exfld_val = cot_build_extrafields('rmsg' . $exfld['field_name'], $exfld, $rmsg['fp_' . $exfld['field_name']]); $exfld_title = isset($L['forums_posts_' . $exfld['field_name'] . '_title']) ? $L['forums_posts_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $t->assign(array('FORUMS_NEWTOPIC_' . $uname => $exfld_val, 'FORUMS_NEWTOPIC_' . $uname . '_TITLE' => $exfld_title, 'FORUMS_NEWTOPIC_EXTRAFLD' => $exfld_val, 'FORUMS_NEWTOPIC_EXTRAFLD_TITLE' => $exfld_title)); $t->parse('MAIN.EXTRAFLD'); } // Extra fields foreach ($cot_extrafields[$db_forum_topics] as $exfld) { $uname = strtoupper($exfld['field_name']); $exfld_val = cot_build_extrafields('rtopic' . $exfld['field_name'], $exfld, $rtopic['ft_' . $exfld['field_name']]); $exfld_title = isset($L['forums_topics_' . $exfld['field_name'] . '_title']) ? $L['forums_topics_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $t->assign(array('FORUMS_NEWTOPIC_TOPIC_' . $uname => $exfld_val, 'FORUMS_NEWTOPIC_TOPIC_' . $uname . '_TITLE' => $exfld_title, 'FORUMS_NEWTOPIC_TOPIC_EXTRAFLD' => $exfld_val, 'FORUMS_NEWTOPIC_TOPIC_EXTRAFLD_TITLE' => $exfld_title)); $t->parse('MAIN.TOPIC_EXTRAFLD');
/** * Returns all section tags for coTemplate * * @param string $cat Forums structure cat code * @param string $tag_prefix Prefix for tags * @param array $stat Category statistics * * @return array */ function cot_generate_sectiontags($cat, $tag_prefix = '', $stat = NULL) { global $cfg, $structure, $cot_extrafields, $usr, $sys, $L, $db_structure; $stat['fs_lt_date'] = !empty($stat['fs_lt_date']) ? $stat['fs_lt_date'] : 0; $stat['fs_lt_posterid'] = !empty($stat['fs_lt_posterid']) ? $stat['fs_lt_posterid'] : 0; $usr['lastvisit'] = !empty($usr['lastvisit']) ? $usr['lastvisit'] : 0; $new_elems = $usr['id'] > 0 && $stat['fs_lt_date'] > $usr['lastvisit'] && $stat['fs_lt_posterid'] != $usr['id']; $sections = array($tag_prefix . 'CAT' => $cat, $tag_prefix . 'LOCKED' => $structure['forums'][$cat]['locked'], $tag_prefix . 'TITLE' => $structure['forums'][$cat]['title'], $tag_prefix . 'DESC' => cot_parse_autourls($structure['forums'][$cat]['desc']) . ($structure['forums'][$cat]['locked'] ? ' ' . $L['Locked'] : ''), $tag_prefix . 'ICON' => empty($structure['forums'][$cat]['icon']) ? '' : cot_rc('img_structure_cat', array('icon' => $structure['forums'][$cat]['icon'], 'title' => htmlspecialchars($structure['forums'][$cat]['title']), 'desc' => htmlspecialchars($structure['forums'][$cat]['desc']))), $tag_prefix . 'URL' => cot_url('forums', 'm=topics&s=' . $cat), $tag_prefix . 'SECTIONSURL' => cot_url('forums', 'c=' . $cat), $tag_prefix . 'NEWPOSTS' => $new_elems, $tag_prefix . 'CAT_DEFSTATE' => htmlspecialchars($cfg['forums']['cat_' . $cat]['defstate'])); if (is_array($stat)) { if ($stat['fs_lt_date'] > 0) { $sections += array($tag_prefix . 'LASTPOSTDATE' => cot_date('datetime_short', $stat['fs_lt_date']), $tag_prefix . 'LASTPOSTER' => cot_build_user($stat['fs_lt_posterid'], htmlspecialchars($stat['fs_lt_postername'])), $tag_prefix . 'LASTPOST' => cot_rc_link($new_elems ? cot_url('forums', 'm=posts&q=' . $stat['fs_lt_id'] . '&n=unread', '#unread') : cot_url('forums', 'm=posts&q=' . $stat['fs_lt_id'] . '&n=last', '#bottom'), cot_cutstring($stat['fs_lt_title'], 32)), $tag_prefix . 'LASTPOST_URL' => $new_elems ? cot_url('forums', 'm=posts&q=' . $stat['fs_lt_id'] . '&n=unread', '#unread') : cot_url('forums', 'm=posts&q=' . $stat['fs_lt_id'] . '&n=last', '#bottom'), $tag_prefix . 'TIMEAGO' => cot_build_timegap($stat['fs_lt_date'], $sys['now'])); } $sections += array($tag_prefix . 'TOPICCOUNT' => $stat['topiccount'], $tag_prefix . 'LASTPOSTDATE_STAMP' => $stat['fs_lt_date'], $tag_prefix . 'POSTCOUNT' => $stat['postcount'], $tag_prefix . 'VIEWCOUNT' => $stat['viewcount'], $tag_prefix . 'VIEWCOUNT_SHORT' => $stat['viewcount'] > 9999 ? floor($stat['viewcount'] / 1000) . 'k' : $stat['viewcount']); } if (!is_array($stat) || !$stat['fs_lt_date']) { $sections[$tag_prefix . 'LASTPOSTDATE'] = ''; $sections[$tag_prefix . 'LASTPOSTER'] = ''; $sections[$tag_prefix . 'LASTPOST'] = ''; $sections[$tag_prefix . 'TIMEAGO'] = ''; $sections[$tag_prefix . 'TOPICCOUNT'] = 0; $sections[$tag_prefix . 'POSTCOUNT'] = 0; $sections[$tag_prefix . 'VIEWCOUNT'] = 0; $sections[$tag_prefix . 'VIEWCOUNT_SHORT'] = 0; } foreach ($cot_extrafields[$db_structure] as $exfld) { $uname = strtoupper($exfld['field_name']); $sections[$tag_prefix . $uname . '_TITLE'] = isset($L['structure_' . $exfld['field_name'] . '_title']) ? $L['structure_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $sections[$tag_prefix . $uname] = cot_build_extrafields_data('structure', $exfld, $structure['forums'][$cat][$exfld['field_name']]); $sections[$tag_prefix . $uname . '_VALUE'] = $structure['forums'][$cat][$exfld['field_name']]; } return $sections; }
$db->update($db_forum_topics, array("ft_mode" => 1), "ft_id={$q}"); break; case 'clear': cot_log("Resetted topic #" . $q, 'for'); $db->update($db_forum_topics, array("ft_state" => 0, "ft_sticky" => 0, "ft_mode" => 0), "ft_id={$q}"); break; } cot_redirect(cot_url('forums', "m=topics&s=" . $s, '', true)); } /* === Hook === */ foreach (cot_getextplugins('forums.topics.first') as $pl) { include $pl; } /* ===== */ require_once cot_incfile('forms'); $structure['forums'][$s]['desc'] = cot_parse_autourls($structure['forums'][$s]['desc']); $title_params = array('FORUM' => $L['Forums'], 'SECTION' => $structure['forums'][$s]['title']); $out['subtitle'] = cot_title($cfg['forums']['title_topics'], $title_params); $out['desc'] = htmlspecialchars(strip_tags($structure['forums'][$s]['desc'])); $sys['sublocation'] = $structure['forums'][$s]['title']; if (!empty($cfg['forums']['cat_' . $s]['keywords'])) { $out['keywords'] = $cfg['forums']['cat_' . $s]['keywords']; } if (!empty($cfg['forums']['cat_' . $s]['metadesc'])) { $out['desc'] = $cfg['forums']['cat_' . $s]['metadesc']; } if (!empty($cfg['forums']['cat_' . $s]['metatitle'])) { $out['subtitle'] = $cfg['forums']['cat_' . $s]['metatitle']; } /* === Hook === */ foreach (cot_getextplugins('forums.topics.main') as $pl) {
/** * Parses bbcodes in text. * * @global $cot_bbcodes * @param string $text Text body * @return string */ function cot_parse_bbcode($text) { global $cfg, $cot_bbcodes, $cot_bbcode_containers, $sys, $cot_smilies, $L, $usr; $code = array(); $unique_seed = $sys['unique']; $ii = 10000; $text = htmlspecialchars($text); cot::$cfg['plugin']['bbcode']['parse_autourls'] && ($text = cot_parse_autourls($text)); $parse_smilies = $cfg['plugin']['bbcode']['smilies']; if ($parse_smilies && is_array($cot_smilies)) { foreach ($cot_smilies as $k => $v) { $ii++; $key = '**' . $ii . $unique_seed . '**'; $code[$key] = '<img class="aux smiley" src="./images/smilies/' . $v['file'] . '" alt="' . htmlspecialchars($v['code']) . '" />'; $text = preg_replace('#(^|\\s)' . preg_quote($v['code']) . '(\\s|$)#', '$1' . $key . '$2', $text); if (htmlspecialchars($v['code']) != $v['code']) { // Fix for cc inserts $text = preg_replace('#(^|\\s)' . preg_quote(htmlspecialchars($v['code'])) . '(\\s|$)#', '$1' . $key . '$2', $text); } } } // BB auto-close $bbc = array(); if (preg_match_all('#\\[(/)?(' . $cot_bbcode_containers . ')(=[^\\]]*)?\\]#i', $text, $mt, PREG_SET_ORDER)) { $cdata = ''; // Count all unclosed bbcode entries for ($i = 0, $cnt = count($mt); $i < $cnt; $i++) { $bb = mb_strtolower($mt[$i][2]); if ($mt[$i][1] == '/') { if (empty($cdata)) { // Protect from "[/foo] [/bar][foo][bar]" trick if ($bbc[$bb] > 0) { $bbc[$bb]--; } // else echo 'ERROR: invalid closing bbcode detected'; } elseif ($bb == $cdata) { $bbc[$bb]--; $cdata = ''; } } elseif (empty($cdata)) { // Count opening tag in $bbc[$bb]++; if ($bb == 'code' || $bb == 'highlight') { // Ignore bbcodes in constant data $cdata = $bb; } } } // Close all unclosed tags. Produces non XHTML-compliant output // (doesn't take tag order and semantics into account) but fixes the layout if (count($bbc) > 0) { foreach ($bbc as $bb => $c) { $text .= str_repeat("[/{$bb}]", $c); } } } // Done, ready to parse bbcodes $cnt = count($cot_bbcodes); for ($i = 0; $i < $cnt; $i++) { $bbcode = $cot_bbcodes[$i]; switch ($bbcode['mode']) { case 'str': $text = str_ireplace($bbcode['pattern'], $bbcode['replacement'], $text); break; case 'pcre': $text = preg_replace('`' . $bbcode['pattern'] . '`mis', $bbcode['replacement'], $text); break; case 'callback': $phpcode = 'global $cfg, $sys, $usr, $L, $theme, $cot_groups;' . $bbcode['replacement']; $text = preg_replace_callback('`' . $bbcode['pattern'] . '`mis', create_function('$input', $phpcode), $text); break; } } $text = nl2br($text); $text = str_replace("\r", '', $text); // Strip extraneous breaks $text = preg_replace('#<(/?)(p|hr|ul|ol|li|blockquote|table|tr|td|th|div|h1|h2|h3|h4|h5)(.*?)>(\\s*)<br />#', '<$1$2$3>', $text); $text = preg_replace_callback('#<pre[^>]*>(.+?)</pre>#sm', 'cot_bbcode_parse_pre', $text); foreach ($code as $x => $y) { $text = str_replace($x, $y, $text); } return $text; }