Skip to content

Commit

Permalink
Merge pull request MightyGorgon#81 from vendethiel/issue48
Browse files Browse the repository at this point in the history
Quick Title: allow html/smilies/bbcode
  • Loading branch information
MightyGorgon committed Nov 23, 2014
2 parents a70d9d3 + 354baba commit 195ded3
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 45 deletions.
16 changes: 12 additions & 4 deletions adm/admin_quick_title.php
Expand Up @@ -110,24 +110,30 @@
$name = request_post_var('title_info', '', true);
$date = request_post_var('date_format', '');


include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
$bbcode->allow_html = true;
$bbcode->allow_bbcode = true;
$bbcode->allow_smilies = true;
$html = $bbcode->parse($name);

if(empty($name))
{
message_die(GENERAL_MESSAGE, $lang['Must_select_title']);
}

if (!empty($title_id))
{

$sql = "UPDATE " . TITLE_INFOS_TABLE . "
SET title_info = '" . $db->sql_escape($name) . "', date_format = '" . $db->sql_escape($date) . "', admin_auth = $admin, mod_auth = $mod, poster_auth = $poster
SET title_info = '" . $db->sql_escape($name) . "', title_html = '" . $db->sql_escape($html) . "', date_format = '" . $db->sql_escape($date) . "', admin_auth = $admin, mod_auth = $mod, poster_auth = $poster
WHERE id = '" . $title_id . "'";

$message = $lang['Title_updated'];
}
else
{
$sql = "INSERT INTO " . TITLE_INFOS_TABLE . " (title_info, admin_auth, mod_auth, poster_auth, date_format)
VALUES ('" . $db->sql_escape($name) . "', $admin, $mod, $poster, '" . $db->sql_escape($date) . "')";
$sql = "INSERT INTO " . TITLE_INFOS_TABLE . " (title_info, title_html, admin_auth, mod_auth, poster_auth, date_format)
VALUES ('" . $db->sql_escape($name) . "', '" . $db->sql_escape($html) . "', $admin, $mod, $poster, '" . $db->sql_escape($date) . "')";

$message = $lang['Title_added'];
}
Expand Down Expand Up @@ -192,6 +198,7 @@
$template->assign_block_vars('title', array(
'ROW_CLASS' => $row_class,
'TITLE' => $title_rows[$i]['title_info'],
'HTML' => $title_rows[$i]['title_html'],
'PERMISSIONS' => $perm,
'DATE_FORMAT' => $title_rows[$i]['date_format'],
'U_TITLE_EDIT' => append_sid('admin_quick_title.' . PHP_EXT . '?mode=edit&id=' . $title_id),
Expand Down Expand Up @@ -247,6 +254,7 @@
$template->assign_block_vars('title', array(
'ROW_CLASS' => $row_class,
'TITLE' => $title_rows[$i]['title_info'],
'HTML' => $title_rows[$i]['title_html'],
'PERMISSIONS' => $perm,
'DATE_FORMAT' => $title_rows[$i]['date_format'],

Expand Down
2 changes: 1 addition & 1 deletion includes/class_mcp.php
Expand Up @@ -657,7 +657,7 @@ function topic_quick_title_edit($topics_ids, $qt_row)
{
global $db, $cache, $config, $user, $lang;

$addon = str_replace('%mod%', addslashes($user->data['username']), $qt_row['title_info'] . ' ');
$addon = str_replace('%mod%', addslashes($user->data['username']), $qt_row['title_html'] . ' ');
$dateqt = ($qt_row['date_format'] == '') ? create_date($config['default_dateformat'], time(), $config['board_timezone']) : create_date($qt_row['date_format'], time(), $config['board_timezone']);
$addon = str_replace('%date%', $dateqt, $addon);

Expand Down
2 changes: 1 addition & 1 deletion includes/class_topics.php
Expand Up @@ -405,7 +405,7 @@ function get_topic_prefixes()
$topic_prefixes = array();
while ($row = $db->sql_fetchrow($result))
{
$topic_prefixes[$row['id']] = $row['title_info'];
$topic_prefixes[$row['id']] = $row['title_html'];
}
$db->sql_freeresult($result);
return $topic_prefixes;
Expand Down
21 changes: 9 additions & 12 deletions includes/functions_categories_hierarchy.php
Expand Up @@ -1091,19 +1091,9 @@ function build_index($cur = 'Root', $cat_break = false, &$forum_moderators, $rea
$last_post = $lang['No_Posts'];
if ((isset($data['tree.forum_last_post_id']) && $data['tree.forum_last_post_id']) && (isset($data['tree.topic_last_post_auth']) && $data['tree.topic_last_post_auth']))
{
// resize
$topic_title = $data['tree.topic_title'];
$topic_title = (empty($data['title_compl_infos'])) ? $topic_title : $data['title_compl_infos'] . ' ' . $topic_title;
$topic_title_plain = $topic_title;
$topic_title_short = $topic_title;
if (strlen($topic_title) > (intval($config['last_topic_title_length']) - 3))
{
$topic_title_short = substr($topic_title, 0, intval($config['last_topic_title_length'])) . '...';
}
$topic_title = htmlspecialchars_clean($data['tree.topic_title']);
$topic_title_plain = htmlspecialchars_clean($data['tree.topic_title']);

// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title_short);
$topic_title_plain = htmlspecialchars_clean($topic_title_plain);
// SMILEYS IN TITLE - BEGIN
if ($config['smilies_topic_title'] && !$lofi)
{
Expand All @@ -1112,6 +1102,13 @@ function build_index($cur = 'Root', $cat_break = false, &$forum_moderators, $rea
}
// SMILEYS IN TITLE - END

$topic_title = (empty($data['title_compl_infos'])) ? $topic_title : $data['title_compl_infos'] . ' ' . $topic_title;
if (strlen($topic_title) > (intval($config['last_topic_title_length']) - 3))
{
// remove tags from the short version, in case a smiley or a quick title prefix is in there
$topic_title = substr(strip_tags($topic_title), 0, intval($config['last_topic_title_length'])) . '...';
}

$topic_title = '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . ((!empty($data['forum_id'])) ? (POST_FORUM_URL . '=' . $data['forum_id'] . '&amp;') : '') . POST_POST_URL . '=' . $data['tree.forum_last_post_id']) . '#p' . $data['tree.forum_last_post_id'] . '" title="' . $topic_title_plain . '">' . $topic_title . '</a><br />';

$last_post_time = create_date_ip($config['default_dateformat'], $data['tree.post_time'], $config['board_timezone']);
Expand Down
2 changes: 1 addition & 1 deletion install/clean_tables_ip.php
Expand Up @@ -279,7 +279,7 @@ function footer()
$table_prefix . 'sudoku_users' => array('user_id', 'game_pack', 'game_num', 'game_level', 'line_1', 'line_2', 'line_3', 'line_4', 'line_5', 'line_6', 'line_7', 'line_8', 'line_9', 'points', 'done'),
$table_prefix . 'themes' => array('themes_id', 'template_name', 'style_name', 'head_stylesheet', 'body_background', 'body_bgcolor', 'tr_class1', 'tr_class2', 'tr_class3', 'td_class1', 'td_class2', 'td_class3'),
$table_prefix . 'tickets_cat' => array('ticket_cat_id', 'ticket_cat_title', 'ticket_cat_des', 'ticket_cat_emails'),
$table_prefix . 'title_infos' => array('id', 'title_info', 'date_format', 'admin_auth', 'mod_auth', 'poster_auth'),
$table_prefix . 'title_infos' => array('id', 'title_info', 'title_html', 'date_format', 'admin_auth', 'mod_auth', 'poster_auth'),
$table_prefix . 'topic_view' => array('topic_id', 'user_id', 'view_time', 'view_count'),
$table_prefix . 'topics' => array('topic_id', 'forum_id', 'topic_title', 'topic_title_clean', 'topic_ftitle_clean', 'topic_tags', 'topic_desc', 'topic_similar_topics', 'topic_poster', 'topic_time', 'topic_views', 'topic_replies', 'topic_status', 'topic_type', 'poll_title', 'poll_start', 'poll_length', 'poll_max_options', 'poll_last_vote', 'poll_vote_change', 'topic_first_post_id', 'topic_first_post_time', 'topic_first_poster_id', 'topic_first_poster_name', 'topic_first_poster_color', 'topic_last_post_id', 'topic_last_post_time', 'topic_last_poster_name', 'topic_last_poster_color', 'topic_last_poster_id', 'topic_moved_id', 'topic_attachment', 'title_compl_infos', 'news_id', 'topic_calendar_time', 'topic_calendar_duration', 'topic_reg', 'topic_rating', 'topic_show_portal'),
$table_prefix . 'topics_tags_list' => array('tag_text', 'tag_id', 'tag_count'),
Expand Down
1 change: 1 addition & 0 deletions install/schemas/mysql_schema.sql
Expand Up @@ -1731,6 +1731,7 @@ CREATE TABLE `phpbb_themes` (
CREATE TABLE `phpbb_title_infos` (
`id` INT(11) NOT NULL auto_increment,
`title_info` VARCHAR(255) NOT NULL DEFAULT '',
`title_html` VARCHAR(255) NOT NULL DEFAULT '',
`date_format` VARCHAR(25) DEFAULT NULL,
`admin_auth` TINYINT(1) DEFAULT '0',
`mod_auth` TINYINT(1) DEFAULT '0',
Expand Down
2 changes: 1 addition & 1 deletion install/schemas/sql_update_ip.php
Expand Up @@ -4587,13 +4587,13 @@
$sql[] = "DELETE FROM `" . $table_prefix . "config` WHERE `config_name` = 'yahoo_search_additional_urls'";
$sql[] = "DELETE FROM `" . $table_prefix . "config` WHERE `config_name` = 'yahoo_search_compress'";
$sql[] = "DELETE FROM `" . $table_prefix . "config` WHERE `config_name` = 'yahoo_search_compression_level'";
$sql[] = "ALTER TABLE `" . $table_prefix . "title_infos` ADD COLUMN `title_html` VARCHAR(255) NOT NULL DEFAULT ''",

/* Updating from IP 2.0.13.99 */
case '2.0.13.99':

/* Updating from IP 2.0.14.100 */
case '2.0.14.100':

}

$sql[] = "INSERT INTO " . $table_prefix . "config VALUES ('ip_version', '" . $ip_version . "')";
Expand Down
6 changes: 4 additions & 2 deletions modcp.php
Expand Up @@ -992,7 +992,9 @@
$select_title = '<select name="qtnum"><option value="-1">---</option>';
while ($row = $db->sql_fetchrow($result))
{
$addon = str_replace('%mod%', addslashes($user->data['username']), $row['title_info']);
// If there's text left when stripping tags, keep it, else display the bbcode version
$nameqt = strip_tags($row['title_html']) ? strip_tags($row['title_html']) : $row['title_info'];
$addon = str_replace('%mod%', addslashes($user->data['username']), $nameqt);
$dateqt = ($row['date_format'] == '') ? create_date($config['default_dateformat'], time(), $config['board_timezone']) : create_date($row['date_format'], time(), $config['board_timezone']);
$addon = str_replace('%date%', $dateqt, $addon);
$select_title .= '<option value="' . $row['id'] . '">' . htmlspecialchars($addon) . '</option>';
Expand Down Expand Up @@ -1122,7 +1124,6 @@

$topic_title = censor_text($topic_rowset[$i]['topic_title']);
$topic_title_prefix = (empty($topic_rowset[$i]['title_compl_infos'])) ? '' : $topic_rowset[$i]['title_compl_infos'] . ' ';
$topic_title = $topic_title_prefix . $topic_title;
// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
// SMILEYS IN TITLE - BEGIN
Expand All @@ -1132,6 +1133,7 @@
$topic_title = $bbcode->parse_only_smilies($topic_title);
}
// SMILEYS IN TITLE - END
$topic_title = $topic_title_prefix . $topic_title;

//$news_label = ($topic_rowset[$i]['news_id'] > 0) ? $lang['News_Cmx'] . '' : '';
$news_label = '';
Expand Down
4 changes: 2 additions & 2 deletions recent.php
Expand Up @@ -269,8 +269,7 @@
$word_censor = censor_text($line[$i]['topic_title']);
$topic_title = (strlen($line[$i]['topic_title']) < $topic_length) ? $word_censor : substr(stripslashes($word_censor), 0, $topic_length) . '...';
$topic_title_prefix = (empty($line[$i]['title_compl_infos'])) ? '' : $line[$i]['title_compl_infos'] . ' ';
$topic_title = $topic_title_prefix . $topic_title;


//$news_label = ($line[$i]['news_id'] > 0) ? $lang['News_Cmx'] . '' : '';
$news_label = '';

Expand Down Expand Up @@ -321,6 +320,7 @@

// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title = $topic_title_prefix . $topic_title;
$template->assign_block_vars('recent', array(
'ROW_CLASS' => (!($i % 2)) ? $theme['td_class1'] : $theme['td_class2'],

Expand Down
12 changes: 3 additions & 9 deletions search.php
Expand Up @@ -1444,7 +1444,7 @@

$topic_title = censor_text($topic_title);
$topic_raw_title = censor_text($topic_raw_title);
$post_subject = !empty($searchset[$i]['post_subject']) ? censor_text($searchset[$i]['post_subject']) : $topic_title_prefix . $topic_title;
$post_subject = !empty($searchset[$i]['post_subject']) ? censor_text($searchset[$i]['post_subject']) : $topic_title_prefix . htmlspecialchars_clean($topic_title);
$message = censor_text($message);

$poster = ($searchset[$i]['user_id'] != ANONYMOUS) ? colorize_username($searchset[$i]['user_id'], $searchset[$i]['username'], $searchset[$i]['user_color'], $searchset[$i]['user_active']) : (($searchset[$i]['post_username'] != '') ? $searchset[$i]['post_username'] : $lang['Guest']);
Expand Down Expand Up @@ -1519,13 +1519,10 @@
$message = $lang['Reserved_Post'];
*/
}
else
{
$topic_title = $topic_title_prefix . $topic_title;
}
// SELF AUTH - END
// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title = $topic_title_prefix . $topic_title;
$template->assign_block_vars('searchresults', array(
'TOPIC_TITLE' => $topic_title,
'FORUM_NAME' => get_object_lang(POST_FORUM_URL . $searchset[$i]['forum_id'], 'name'),
Expand Down Expand Up @@ -1729,10 +1726,6 @@
$topic_title = $lang['Reserved_Topic'];
*/
}
else
{
$topic_title = $topic_title_prefix . $topic_title;
}
// SELF AUTH - END

// UPI2DB - BEGIN
Expand All @@ -1750,6 +1743,7 @@

// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title = $topic_title_prefix . $topic_title;
$template->assign_block_vars('searchresults', array(
'ROW_CLASS' => (!($i % 2)) ? $theme['td_class1'] : $theme['td_class2'],
'FORUM_NAME' => get_object_lang(POST_FORUM_URL . $searchset[$i]['forum_id'], 'name'),
Expand Down
4 changes: 2 additions & 2 deletions tags.php
Expand Up @@ -166,7 +166,7 @@
$news_label = '';

$word_censor = censor_text($topic['topic_title']);
$topic_title = ((empty($topic['title_compl_infos'])) ? '' : $topic['title_compl_infos'] . ' ') . ((strlen($topic['topic_title']) < $topic_length) ? $word_censor : substr(stripslashes($word_censor), 0, $topic_length) . '...');
$topic_title = ((strlen($topic['topic_title']) < $topic_length) ? $word_censor : substr(stripslashes($word_censor), 0, $topic_length) . '...');

$topic_link = $class_topics->build_topic_icon_link($forum_id, $topic['topic_id'], $topic['topic_type'], $topic['topic_reg'], $topic['topic_replies'], $topic['news_id'], $topic['poll_start'], $topic['topic_status'], $topic['topic_moved_id'], $topic['post_time'], $user_replied, $replies);

Expand All @@ -184,7 +184,7 @@
$topic_tags_links = $class_topics_tags->build_tags_list_single_topic($topic['topic_tags']);

// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title = ((empty($topic['title_compl_infos'])) ? '' : $topic['title_compl_infos'] . ' ') . htmlspecialchars_clean($topic_title);
$template->assign_block_vars('row', array(
'CLASS' => $class,
'ROW_NUMBER' => $i + 1,
Expand Down
2 changes: 1 addition & 1 deletion templates/common/acp/title_list_body.tpl
Expand Up @@ -13,7 +13,7 @@
</tr>
<!-- BEGIN title -->
<tr>
<td class="{title.ROW_CLASS} row-center">{title.TITLE}</td>
<td class="{title.ROW_CLASS} row-center">{title.HTML}</td>
<td class="{title.ROW_CLASS} row-center">{title.PERMISSIONS}</td>
<td class="{title.ROW_CLASS} row-center">{title.DATE_FORMAT}</td>
<td class="{title.ROW_CLASS} row-center"><a href="{title.U_TITLE_EDIT}">{L_EDIT}</a></td>
Expand Down
2 changes: 1 addition & 1 deletion templates/default/xs_topic.tpl
Expand Up @@ -131,7 +131,7 @@ if($can_reply)
{IMG_THL}{IMG_THC}<span class="forumlink"><?php echo $lang['Post_a_reply']; ?></span>{IMG_THR}<table class="forumlinenb">
<tr>
<td class="row1 tw200px tdnw"><span class="gen"><b><?php echo $lang['Subject']; ?>:</b></span></td>
<td class="row2 tw100pct"><input type="text" name="subject" size="45" maxlength="120" style="width: 98%;" tabindex="2" class="post" value="{L_REPLY_PREFIX}{TOPIC_TITLE}" /></td>
<td class="row2 tw100pct"><input type="text" name="subject" size="45" maxlength="120" style="width: 98%;" tabindex="2" class="post" value="{L_REPLY_PREFIX}{TOPIC_TITLE_PLAIN}" /></td>
</tr>
<tr>
<td class="row1 tw200px tdnw"><span class="gen"><b><?php echo $lang['Message_body']; ?>:<br /><img src="{T_TEMPLATE_PATH}/images/spacer.gif" width="200" height="1" alt="" /></b></span></td>
Expand Down
4 changes: 2 additions & 2 deletions viewforum.php
Expand Up @@ -1018,17 +1018,17 @@
update_clean_topic_title($topic_id, $topic_title_clean);
}
$topic_title_prefix = (empty($topic_rowset[$i]['title_compl_infos'])) ? '' : $topic_rowset[$i]['title_compl_infos'] . ' ';
$topic_title = $topic_title_prefix . $topic_title;
// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title_plain = htmlspecialchars($topic_title);
$topic_title_plain = htmlspecialchars($topic_title_prefix . $topic_title);
// SMILEYS IN TITLE - BEGIN
if (($config['smilies_topic_title'] == true) && !$lofi)
{
$bbcode->allow_smilies = (($config['allow_smilies'] && $topic_rowset[$i]['enable_smilies']) ? true : false);
$topic_title = $bbcode->parse_only_smilies($topic_title);
}
// SMILEYS IN TITLE - END
$topic_title = $topic_title_prefix . $topic_title;

//$news_label = ($topic_rowset[$i]['news_id'] > 0) ? $lang['News_Cmx'] . '' : '';
$news_label = '';
Expand Down
2 changes: 1 addition & 1 deletion viewforumlist.php
Expand Up @@ -261,9 +261,9 @@
update_clean_topic_title($topic_id, $topic_title_clean);
}
$topic_title_prefix = (empty($topic_rowset[$i]['title_compl_infos'])) ? '' : $topic_rowset[$i]['title_compl_infos'] . ' ';
$topic_title = $topic_title_prefix . $topic_title;
// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title = $topic_title_prefix . $topic_title;
$topic_title_plain = htmlspecialchars($topic_title);

if (($config['url_rw'] == '1') || (($config['url_rw_guests'] == '1') && ($user->data['user_id'] == ANONYMOUS)))
Expand Down
13 changes: 8 additions & 5 deletions viewtopic.php
Expand Up @@ -844,9 +844,8 @@
define('SHOW_ONLINE', true);
}

$topic_title = $topic_title_prefix . $topic_title;
$meta_content['page_title'] = $meta_content['forum_name'] . ' :: ' . $topic_title;
$meta_content['page_title_clean'] = $topic_title;
$meta_content['page_title'] = $meta_content['forum_name'] . ' :: ' . $topic_title_prefix . $topic_title;
$meta_content['page_title_clean'] = $topic_title_prefix . $topic_title;
$template->assign_var('S_VIEW_TOPIC', true);
if ($config['show_icons'] == true)
{
Expand Down Expand Up @@ -973,7 +972,9 @@
$select_title = '<form action="modcp.' . PHP_EXT . '?sid=' . $user->data['session_id'] . '" method="post"><br /><br /><select name="qtnum"><option value="-1">---</option>';
while ($row = $db->sql_fetchrow($result))
{
$addon = str_replace('%mod%', addslashes($user->data['username']), $row['title_info']);
// If there's text left when stripping tags, keep it, else display the bbcode version
$nameqt = strip_tags($row['title_html']) ? strip_tags($row['title_html']) : $row['title_info'];
$addon = str_replace('%mod%', addslashes($user->data['username']), $nameqt);
$dateqt = ($row['date_format'] == '') ? create_date($config['default_dateformat'], time(), $config['board_timezone']) : create_date($row['date_format'], time(), $config['board_timezone']);
$addon = str_replace('%date%', $dateqt, $addon);
$select_title .= '<option value="' . $row['id'] . '">' . htmlspecialchars($addon) . '</option>';
Expand Down Expand Up @@ -1118,14 +1119,16 @@
// URL Rewrite - END

// Convert and clean special chars!
$topic_title = htmlspecialchars_clean($topic_title);
$topic_title_plain = htmlspecialchars_clean($topic_title);
$topic_title = $topic_title_prefix . $topic_title_plain;
$template->assign_vars(array(
'FORUM_ID' => $forum_id,
'FORUM_ID_FULL' => POST_FORUM_URL . $forum_id,
'FORUM_NAME' => $forum_name,
'FORUM_RULES' => $rules_bbcode,
'TOPIC_ID' => $topic_id,
'TOPIC_ID_FULL' => POST_TOPIC_URL . $topic_id,
'TOPIC_TITLE_PLAIN' => $topic_title_plain,
'TOPIC_TITLE' => $topic_title,
'TOPIC_TITLE_SHORT' => ((strlen($topic_title) > 80) ? substr($topic_title, 0, 75) . '...' : $topic_title),

Expand Down

0 comments on commit 195ded3

Please sign in to comment.