Arrighty! Here's a little hack that seems to work okay. It puts another button next to the "Reply w/quote" thing. It does the same thing, except that it posts to a special "Best of" thread instead of the original, and it includes a link to the original thread.
So, you pick a message that you think is cool, and click the best-of button, and you can type in what's so great about it and such. You can also edit out irrelevant parts of the original message, or whatever.
Because it's a hack, there are a few hard-coded things, and it's not particularly robusto, but it is free. If anyone happens to care about tighter security or software design best practices, feel free to fix it up. Also, I don't know exactly what version of phpbb we're running here or what other changes have been made to the source, so my directions are a little vague. Y'all'll figure it out.
JB: If this is too messy to make sense of, I can do it for you if you email me the files that need changing.
There are three places you need to make changes:
1. templates/whatever/viewtopic_body.tpl
(once for each template; I believe we have two here)
About a third of the way down, add the little bit in green:
<td>{postrow.BESTOF_IMG} {postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.IP_IMG}</td>
"QUOTE_IMG" only appears once in the file, so you can search for that.
2. viewtopic.php
There are two sections to add here. First, the big stuff; add everything after my name. The first few lines are just there to show you what to look for: you can search for "Search_user_posts" to find the right spot because that word doesn't appear anywhere else. (In my version of the file the new code starts at line #997.)
Code: Select all
$temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&showresults=posts");
$search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '" title="' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '" border="0"></a>';
$search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '</a>';
/* bzl */
if ( $is_auth['auth_mod'] )
{
$lang['Best_Of'] = "Best Of"; /* this oughta be localized */
$temp_url = append_sid("posting.$phpEx?mode=bestof&" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
$bestof_img = '<a href="' . $temp_url . '"><img src="' . $images['folder_hot'] . '" alt="' . $lang['Best_Of'] . '" title="' . $lang['Best_Of'] . '" border="0"></a>';
$bestof = '<a href="' . $temp_url . '">' . $lang['Best_Of'] . '</a>';
}
else
{
$bestof_img = '';
$bestof = '';
}
At the very bottom of the file is a big assignment:
Code: Select all
$template->assign_block_vars('postrow', array(
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'POSTER_NAME' => $poster,
'POSTER_RANK' => $poster_rank,
'RANK_IMAGE' => $rank_image,
(et cetera)
Add in:
Code: Select all
'BESTOF_IMG' => $bestof_img,
'BESTOF' => $bestof,
3. posting.php
There are a bunch of small changes to make in this file.
a.) Add the bestof auth check. I'm not sure if this does what I think it does, or if it's really even necessary, but I can't make myself care enough.
Code: Select all
//
// What auth type do we need to check?
//
$is_auth = array();
switch( $mode )
{
case 'newtopic':
if ( $topic_type == POST_ANNOUNCE )
{
$is_auth_type = 'auth_announce';
}
else if ( $topic_type == POST_STICKY )
{
$is_auth_type = 'auth_sticky';
}
else
{
$is_auth_type = 'auth_post';
}
break;
case 'reply':
case 'quote':
$is_auth_type = 'auth_reply';
break;
/* ADD THE NEXT THREE LINES */
case 'bestof':
$is_auth_type = 'auth_mod';
break;
case 'editpost':
$is_auth_type = 'auth_edit';
break;
(etc.)
b.) Add the SQL stuff:
Code: Select all
//
// Here we do various lookups to find topic_id, forum_id, post_id etc.
// Doing it here prevents spoofing (eg. faking forum_id, topic_id or post_id
//
$error_msg = '';
$post_data = array();
switch ( $mode )
{
/* ADD THE BESTOF CASE HERE */
/* bzl */
case 'bestof':
if ( empty($post_id) )
{
message_die(GENERAL_MESSAGE, $lang['No_post_id']);
}
$select_sql = (!$submit) ? ', t.topic_title, p.enable_bbcode, p.enable_html, p.enable_smilies, p.enable_sig, p.post_username, pt.post_subject, pt.post_text, pt.bbcode_uid, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid' : '';
$from_sql = ( !$submit ) ? ", " . POSTS_TEXT_TABLE . " pt, " . USERS_TABLE . " u" : '';
$where_sql = ( !$submit ) ? "AND pt.post_id = p.post_id AND u.user_id = p.poster_id" : '';
$sql = "SELECT f.*, t.topic_id, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_vote, p.post_id, p.poster_id" . $select_sql . "
FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $from_sql . "
WHERE p.post_id = $post_id
AND t.topic_id = p.topic_id
AND f.forum_id = p.forum_id
$where_sql";
break;
/* END OF WHAT GETS ADDED */
case 'newtopic':
if ( empty($forum_id) )
{
message_die(GENERAL_MESSAGE, $lang['Forum_not_exist']);
}
$sql = "SELECT *
FROM " . FORUMS_TABLE . "
WHERE forum_id = $forum_id";
break;
case 'reply':
case 'vote':
(etc)
c.) Add the best-of topic number:
Code: Select all
else
{
if ( $mode == 'quote' )
{
$topic_id = $post_info['topic_id'];
}
if ( $mode == 'newtopic' )
{
$post_data['topic_type'] = POST_NORMAL;
}
/* ADD THIS IF */
if ( $mode == 'bestof' )
{
$topic_id = 4430;
}
$post_data['first_post'] = ( $mode == 'newtopic' ) ? true : 0;
$post_data['last_post'] = false;
$post_data['has_poll'] = false;
$post_data['edit_poll'] = false;
}
The number '4430' is the topic number to which the best posts get posted. That's
this thread, so you should probably create a different thread and put that number in instead.
d.) Add the code to handle the bestof post. This one is big and has three separate changes, so be careful.
Code: Select all
//
// User default entry point
//
if ( $mode == 'newtopic' )
{
$user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';
$username = ($userdata['session_logged_in']) ? $userdata['username'] : '';
$poll_title = '';
$poll_length = '';
$subject = '';
$message = '';
}
else if ( $mode == 'reply' )
{
$user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';
$username = ( $userdata['session_logged_in'] ) ? $userdata['username'] : '';
$subject = '';
$message = '';
}
/* (1) CHANGE THIS LINE: *********************
else if ( $mode == 'quote' || $mode == 'editpost' )
TO: */
else if ( $mode == 'quote' || $mode == 'editpost' || $mode = 'bestof' )
{
$subject = ( $post_data['first_post'] ) ? $post_info['topic_title'] : $post_info['post_subject'];
$message = $post_info['post_text'];
if ( $mode == 'editpost' )
{
$attach_sig = ( $post_info['enable_sig'] && $post_info['user_sig'] != '' ) ? TRUE : 0;
$user_sig = $post_info['user_sig'];
$html_on = ( $post_info['enable_html'] ) ? true : false;
$bbcode_on = ( $post_info['enable_bbcode'] ) ? true : false;
$smilies_on = ( $post_info['enable_smilies'] ) ? true : false;
}
else
{
$attach_sig = ( $userdata['user_attachsig'] ) ? TRUE : 0;
$user_sig = $userdata['user_sig'];
}
if ( $post_info['bbcode_uid'] != '' )
{
$message = preg_replace('/\:(([a-z0-9]:)?)' . $post_info['bbcode_uid'] . '/s', '', $message);
}
$message = str_replace('<lt>', '>', $message);
$message = str_replace('<br>', "\n", $message);
/* (2) CHANGE THIS LINE *********************
if ( $mode == 'quote' )
TO: */
if ( $mode == 'quote' || $mode == 'bestof' )
{
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replace_word);
$msg_date = create_date($board_config['default_dateformat'], $postrow['post_time'], $board_config['board_timezone']);
// Use trim to get rid of spaces placed there by MS-SQL 2000
$quote_username = ( trim($post_info['post_username']) != '' ) ? $post_info['post_username'] : $post_info['username'];
/* (3) REPLACE THIS LINE: *********************
$message = '[quote="' . $quote_username . '"]' . $message . '[/quote]';
WITH THESE: */
if ( $mode == 'bestof' )
{
$message = "[url=" . append_sid("http://www.songfight.net/forums/viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $post_info['topic_id']) . '](original thread)[/url][quote="' . $quote_username . '"]' . $message . '[/quote]';
}
else
{
$message = '[quote="' . $quote_username . '"]' . $message . '[/quote]';
}
/* END OF REPLACEMENT */
if ( !empty($orig_word) )
{
$subject = ( !empty($subject) ) ? preg_replace($orig_word, $replace_word, $subject) : '';
$message = ( !empty($message) ) ? preg_replace($orig_word, $replace_word, $message) : '';
}
if ( !preg_match('/^Re:/', $subject) && strlen($subject) > 0 )
{
$subject = 'Re: ' . $subject;
}
$mode = 'reply';
}
else
{
$username = ( $post_info['user_id'] == ANONYMOUS && !empty($post_info['post_username']) ) ? $post_info['post_username'] : '';
}
}
}