Build this for me please, some genius coder

Links and other hanky panky that doesn't have to do with anything in particular.
User avatar
jb
Roosevelt
Posts: 4227
Joined: Sat Sep 25, 2004 10:12 am
Instruments: Guitar, Cello, Keys, Uke, Vox, Perc
Recording Method: Logic X
Submitting as: The John Benjamin Band
Pronouns: he/him
Location: WASHINGTON, DC
Contact:

Build this for me please, some genius coder

Post by jb »

I want a hack/mod for PHPBB that will let me/admin/moderators choose posts and select them for a special "Best Posts" forum. It would only include the single post, but the permalink would point back to the original post.

Then I need an RSS feed generator for forums/threads.

Who has the BALLS to accept this challenge????
blippity blop ya don’t stop heyyyyyyyyy
User avatar
drë
Niemöller
Posts: 1197
Joined: Sun Sep 26, 2004 12:24 am
Instruments: guitar
Recording Method: protools
Submitting as: Andre was here at Midnight
Location: Seattle, Wa
Contact:

Post by drë »

am in.

But first I will need your admin user name and password
Your bank account number, social security number, date of birth, and mother’s maiden name.

Deal?

Here’s a start: a Boolean on the thread table to mark the tread “best”;
Then display a toggle checkbox for special users, to turn it on/off.
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

I have a nice hack to make the first half of this work. When I sober up later I will try and explain how it works (after confirming that it actually works) so you can patch it into your own system, if you so desire.

I was a bit surprised to discover that PHPBB doesn't seem to have any built-in RSS support, even in the new-fangled 3.0 versions. It can't be that difficult to do, so maybe I'll look into that later, if I discover that I have the BALLS to do so.
WeaselSlayer
Niemöller
Posts: 1592
Joined: Tue Dec 14, 2004 5:13 pm
Instruments: Guitar, keyboard
Recording Method: Garageband, laptop mic
Submitting as: Luke Henley
Location: Tucson, AZ
Contact:

Post by WeaselSlayer »

Something tells me no one will be directed toward my cutting wit and pleasurable devilry.
User avatar
Märk
Churchill
Posts: 2051
Joined: Sat Sep 25, 2004 8:35 pm
Instruments: Guitar, bass
Recording Method: Cubase, Steinberg CI2
Submitting as: ROTR, svenmullet, I forget what else
Pronouns: it
Location: Canada

Post by Märk »

Change your name to WeaselSläyer already. Sheesh.
* this is not a disclaimer
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

Those will both be in version 2.ö
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

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'] : '';
		}
	}
}
User avatar
ken
Roosevelt
Posts: 3926
Joined: Sat Sep 25, 2004 6:10 pm
Instruments: Guitar, bass, drums, keys
Recording Method: Audient Sono, MOTU 828x, Cubase
Submitting as: Ken's Super Duper Band 'n Stuff
Pronouns: he/him
Location: oakland, ca
Contact:

Post by ken »

Ben,

That is what PM is for!
Ken's Super Duper Band 'n Stuff - Berkeley Social Scene - Tiny Robots - Seamus Collective - Semolina Pilchards - Cutie Pies - Explino! - Bravo Bros. - 2 from 14 - and more!

i would just like to remind everyone that Ken eats kittens - blue lang
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

But, but everyone deserves my wisdom!
frankie big face
Churchill
Posts: 2186
Joined: Sat Sep 25, 2004 12:26 pm
Instruments: Vocals, Bass, Guitar, Saxophone, Flute, Keyboard, Violin, Other Stuff
Recording Method: Logic, UAD Apollo Twin, Mac
Submitting as: frankie big face
Pronouns: he/him
Location: Lancaster, PA

Post by frankie big face »

ken wrote:Ben,

That is what PM is for!
No it's not! That was awesome! I don't understand any of it, but it looks like it took you a really long time. Good job.
User avatar
drë
Niemöller
Posts: 1197
Joined: Sun Sep 26, 2004 12:24 am
Instruments: guitar
Recording Method: protools
Submitting as: Andre was here at Midnight
Location: Seattle, Wa
Contact:

Post by drë »

frankie big face wrote:
ken wrote:Ben,

That is what PM is for!
No it's not! That was awesome! I don't understand any of it, but it looks like it took you a really long time. Good job.
Yeah, apparently Ben is not a drunk bookworm after all.
Cheers to Ben, you’re the shit.
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

drë wrote:Yeah, apparently Ben is not a drunk bookworm after all.
In all fairness, this didn't take all that much time, and I do enjoy reading and drinking. To excess, in both cases. Also, the above code would not have been possible without gin and tonic.

RSS is actually gonna take a little while because there is apparently a lot to be written from scratch, but it's not like I have anything better to do (besides read books and drink).
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

RSS support!

First, download this zip file and put its contents (rss.php) in the /includes folder of your bb code. Then make one small change to includes/functions_post.php:

Code: Select all

	/* bzl: start of what to add */
	/* Here, the post has updated successfully.  I think.  So it should be a good place to update RSS */
	if ($topic_type == POST_ANNOUNCE) {
	  include ($phpbb_root_path . 'includes/rss.' . $phpEx);
	  output_rss();
	}
/* end of what to add */

	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)
	{
In my version of the file that starts at line 255, and the function "add_search_words" isn't called anywhere else so that is a good thing to search for.



Now, every time you post a new topic and mark it as "Announcement" (right next to "Sticky") it will get added to rss.xml (in the main bb folder). This also works if you take a normal post and edit it to be an announcement, or if you edit an announcement's original post. Replies to announcements are ignored. The actual text of the post is not included in the rss file (just a link to the board) but that's easy enough to add in if you really want to. I wouldn't, but it's not my board.

You'll get a couple of warning messages along with the "Thanks for the post!" screen but that just means it's working! I just learned PHP this week and I have a flu that will probably require hospitalization soon so I have no real interest in fixing that stuff. Consider it either an exercise for the reader, or just part of the charm of a really ugly hack. I also had to do a few things I'm not proud of to make it work with PHP 4, because my web site hasn't upgraded.

You'll probably want to tweak around in the rss.php file (linked above). Right now, for example, the copyright message is "copyright message here" and you may want to change that (I wasn't sure how y'all'd want it). Other stuff is all guesswork but it looks okay to me and works with my rss client, which is the reader built into Opera 9.
User avatar
jb
Roosevelt
Posts: 4227
Joined: Sat Sep 25, 2004 10:12 am
Instruments: Guitar, Cello, Keys, Uke, Vox, Perc
Recording Method: Logic X
Submitting as: The John Benjamin Band
Pronouns: he/him
Location: WASHINGTON, DC
Contact:

Post by jb »

OK, now to get some other *ahem* volunteer to implement this... SHADOWY PUPPETMASTER WHERE ARE YOU WHEN WE NEED YOU
blippity blop ya don’t stop heyyyyyyyyy
shadowy puppetmaster
A New Player
Posts: 17
Joined: Sat May 20, 2006 8:14 pm
Contact:

Post by shadowy puppetmaster »

EXTREMELY BUSY.
anti-m
Niemöller
Posts: 1160
Joined: Mon Sep 19, 2005 2:00 pm
Submitting as: Anti-m, Jeplexe
Location: PDX
Contact:

Post by anti-m »

bz£ wrote:Also, the above code would not have been possible without gin and tonic.
This code brought to you by the letters "G" and "T."
User avatar
jb
Roosevelt
Posts: 4227
Joined: Sat Sep 25, 2004 10:12 am
Instruments: Guitar, Cello, Keys, Uke, Vox, Perc
Recording Method: Logic X
Submitting as: The John Benjamin Band
Pronouns: he/him
Location: WASHINGTON, DC
Contact:

Post by jb »

I hesitate to ask this, but in order to achieve my original goal can we make the rss script work for all posts in a particular thread?

What I have in mind is to specify that all posts to the "Best Of" thread go into the RSS feed, and then to restrict posting to the "Best Of" to moderators only.

Does the "Best Of" hack make it so only mods/admin can select "Best Of" entries?

Thanks for your work, Ben, and any additional hacking you feel up to donating. :)

JB
blippity blop ya don’t stop heyyyyyyyyy
User avatar
bz£
Orwell
Posts: 946
Joined: Sat Sep 25, 2004 10:50 am
Location: boston ma

Post by bz£ »

jb wrote:I hesitate to ask this, but in order to achieve my original goal can we make the rss script work for all posts in a particular thread?
Sure; that's how I had it originally but the thing that rewrites the rss.xml file wasn't triggering right. I should be able to fix that pretty easily.
What I have in mind is to specify that all posts to the "Best Of" thread go into the RSS feed, and then to restrict posting to the "Best Of" to moderators only.

Does the "Best Of" hack make it so only mods/admin can select "Best Of" entries?
It only lets admins select for Best Of. I wouldn't let anyone reply to the Best-of thread, either. Not sure exactly what the difference between "admin" and "moderator" is.

Probably won't get around to making this work right away; they let me out of the hospital (and, sadly, I didn't see any masked administrators) but I'm still not really able to think straight for more than a minute at a time. It shouldn't be all that hard, though, and I'm happy to be able to help.
User avatar
mkilly
Niemöller
Posts: 1229
Joined: Mon Sep 27, 2004 10:22 am
Instruments: guitar
Location: Austin, Texas
Contact:

Post by mkilly »

bz£ wrote:Not sure exactly what the difference between "admin" and "moderator" is.
I think admins are system-wide, and moderators can be users elevated to editors of specific boards. Glenn, for instance, moderates a bunch of the forums, but only (I think) JB, Spud, maybe fluffy are admins.
"It is really true what philosophy tells us, that life must be understood backwards. But with this, one forgets the second proposition, that it must be lived forwards." Søren Kierkegaard
User avatar
Reist
Roosevelt
Posts: 3066
Joined: Mon Jan 30, 2006 2:26 pm
Instruments: Drums, Guitar
Recording Method: Yamaha AW1600, Reaper
Submitting as: Therman
Location: Calgary
Contact:

Post by Reist »

I think that's how the system works. I run the forum at Radnoise, so I'm the admin. I can take a user and give them permission to moderate.
User avatar
fluffy
Eisenhower
Posts: 11267
Joined: Sat Sep 25, 2004 10:56 am
Instruments: sometimes
Recording Method: Logic Pro X
Submitting as: Sockpuppet
Pronouns: she/they
Location: Seattle-ish
Contact:

Post by fluffy »

I'm not an admin (or a moderator, for that matter). It shows who the admins are on the main forum index.

Moderators only have control over posts in specific sections, while admins also have control over users and the whole forum.
User avatar
Lunkhead
Rosselli
Posts: 8567
Joined: Sat Sep 25, 2004 12:14 pm
Instruments: many
Recording Method: cubase/mac/tascam4x4
Submitting as: Berkeley Social Scene
Pronouns: he/him
Location: Central Oregon
Contact:

Post by Lunkhead »

bz£ wrote:they let me out of the hospital
Hospital? That sucks. Get well soon!
Post Reply