Jonas was asking me for the code to this, for Batavia's use... I'm going to go to sleep very soon, but before that, here's the important bit in include/functions.php:
Code: Select all
$malsays_forum = 177; // this per-site magic number is the forum ID of the forum that the Malarbor updates will go on
global $bbcode;
// this query gets the content plus the bbcode stuff that I don't understand from the oldest post of the newest threads on the $malsays_forum forum
$sql = "SELECT post_text, bbcode_uid, bbcode_bitfield FROM phpbb_posts AS p JOIN phpbb_topics AS t ON p.topic_id = t.topic_id WHERE t.forum_id = $malsays_forum ORDER BY t.topic_id DESC, p.post_id ASC LIMIT 1;";
$result = $db->sql_query ($sql);
$malsays; // don't blame me, I'm a C programmer, I need to declare my variables no matter what :(
if ($row = $db->sql_fetchrow ($result)) {
$message = $row['post_text'];
$message = censor_text ($message); // I'm not quite sure what censor_text exactly does. I *hope* it censors words in the censorlist out of text.
// all the bbcode-related lines are just snarfed from different parts of the phpbb codebase, don't ask me how they work
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode->bbcode_second_pass ($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
$malsays['message'] = smiley_text (bbcode_nl2br ($message));
}
else {
$malsays['message'] = "Nothing, actually."; // put in a really stupid replacement if there's no post in the database to read the message out of
}
// the following comment and the last two lines of code are from phpBB.
// The following assigns all _common_ variables that may be used at any point in a template.
$template->assign_vars(array(
'MALSAYS_TITLE' => "Malarbor says",
'MALSAYS_MESSAGE' => $malsays['message'],
'MALSAYS_PICTURE' => "images/malarbor.png",
'SITENAME' => $config['sitename'],
'SITE_DESCRIPTION' => $config['site_desc'],
'PAGE_TITLE' => $page_title,
You can find out the place in functions.php where this code is supposed to go by searching for the last two lines - they're there in the original phpBB. Basically, what's going on in here is that the first part (from the first line to $template->assign vars...) reads the content of the appropriate message (the oldest message in the newest thread on the announcements forum) in to $malsays, and the second part feeds the content (plus a few other things for which I'm currently using default values - that's going to change, I guess) into phpBB's template system.
For this code to work, the bbcode class needs to be available in functions.php. This is easy to do: Just add
to the beginning of the file. The problem with that is that PHP will die on you if you try to load the class several times, so you'll also have to change "include" to "include_once" *everywhere else where bbcode.php is loaded*. Here's the list of files that include_once bbcode (I'm pretty sure that on most of these, the include_once was there to begin with and I only changed a few - I just don't remember which ones I changed anymore

)
Code: Select all
]$ grep -R include_once.\*bbcode.\*\$phpEx *
includes/functions_posting.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/ucp/ucp_pm_viewmessage.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/ucp/ucp_pm_viewmessage.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/mcp/mcp_queue.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/mcp/mcp_warn.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/mcp/mcp_reports.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/mcp/mcp_topic.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
includes/mcp/mcp_post.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
memberlist.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
search.php: include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
viewtopic.php:include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
You should begin by backing the board up and then trying to apply these changes to it. Don't forget to change those includes to include_onces *before* you add that one include_once to functions.php - otherwise PHP will yell at you for redeclaring the bbcode class.
The most important thing that you'll gain from all this is the variable MALSAYS_MESSAGE that you can use anywhere in the template code. To make use of it... well... this is very, very board-specific. You should just check template/overall_header.html in the style that you're using and see where you can put it.