Expanded forum description from a "base note"
Posted by jxh
|
Expanded forum description from a "base note" February 22, 2007 12:06AM |
Registered: 20 years ago Posts: 14 |
I'm trying to get some text above the Phorum menu in list.php (at least), taking text from a note in the forum itself. Call it an expanded Description.
So far, with bodies_in_list 1 in settings.tpl, I have in header.tpl:
<div class="PhorumFloatingText">{IF DESCRIPTION}{DESCRIPTION}{ELSE}<?php print(preg_replace('/<br \/>\n<br \/>\n<br \/>\n<br \/>\nEdited.*$/', "", $PHORUM['DATA']['ROWS'][1]['body'])) ?>{/IF} </div>
but of course ROWS->1 isn't always around. (I imagined that each forum had a message #1.) I thought of digging through all the messages looking for one whose name is "Base note" ideally hidden so only admins can see and edit it, but only the ROWS being displayed on the page are loaded, excluding hidden ones. If you go to a second page, or you hide the "base" note, it vanishes from ROWS.
I could load something that only admin.php can see or edit -- it makes sense since Description is edited only there -- but I don't see an easy way to add a field to the forum itself. Really, though, I want to delegate this to the forum owner, perhaps by the moderation mechanism or something.
Any ideas?
So far, with bodies_in_list 1 in settings.tpl, I have in header.tpl:
<div class="PhorumFloatingText">{IF DESCRIPTION}{DESCRIPTION}{ELSE}<?php print(preg_replace('/<br \/>\n<br \/>\n<br \/>\n<br \/>\nEdited.*$/', "", $PHORUM['DATA']['ROWS'][1]['body'])) ?>{/IF} </div>
but of course ROWS->1 isn't always around. (I imagined that each forum had a message #1.) I thought of digging through all the messages looking for one whose name is "Base note" ideally hidden so only admins can see and edit it, but only the ROWS being displayed on the page are loaded, excluding hidden ones. If you go to a second page, or you hide the "base" note, it vanishes from ROWS.
I could load something that only admin.php can see or edit -- it makes sense since Description is edited only there -- but I don't see an easy way to add a field to the forum itself. Really, though, I want to delegate this to the forum owner, perhaps by the moderation mechanism or something.
Any ideas?
|
Re: Expanded forum description from a "base note" February 22, 2007 03:52AM |
Admin Registered: 22 years ago Posts: 8,532 |
I think that the solution that you're after is a bit too hard and complicated this way. Using a forum message for this is likely to get you in troubles (like you already found out with multiple pages and the need for a preg_replace for getting rid of edit messages). You could pull this off by adding a hidden message with a special subject to each forum, but that means that for each list page view, you'll have to search through the messages to find the extended description message for the forum. Not really good for your server performance.
What I would do, is use the phorum_settings table for storing the information, in combination with a module. The module could be structured like this:
* A hook which modifies the forum description before it's displayed, by adding the extended description to the already available description. So no template changes are needed for displaying the extended description.
* For moderators, there could be an "edit" link added to the extended description, which they can click to open an ...
* ...addon script, which allows them to edit the message.
* The extended descriptions can be stored using the phorum_settings, where the stored data is an array in which the keys are forum ids and the values are the extended messages. Storing the data would be done in the same way as in many module settings.php script, except that it would now be done from a front end addon script.
So this way, the functionality could be built as a drop in module, without having to apply hackery to the system.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
What I would do, is use the phorum_settings table for storing the information, in combination with a module. The module could be structured like this:
* A hook which modifies the forum description before it's displayed, by adding the extended description to the already available description. So no template changes are needed for displaying the extended description.
* For moderators, there could be an "edit" link added to the extended description, which they can click to open an ...
* ...addon script, which allows them to edit the message.
* The extended descriptions can be stored using the phorum_settings, where the stored data is an array in which the keys are forum ids and the values are the extended messages. Storing the data would be done in the same way as in many module settings.php script, except that it would now be done from a front end addon script.
So this way, the functionality could be built as a drop in module, without having to apply hackery to the system.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Expanded forum description from a "base note" February 22, 2007 10:00AM |
Registered: 20 years ago Posts: 14 |
|
Re: Expanded forum description from a "base note" February 22, 2007 01:17PM |
Registered: 20 years ago Posts: 14 |
Quote
mmakaay
You could pull this off by adding a hidden message with a special subject to each forum, but that means that for each list page view, you'll have to search through the messages to find the extended description message for the forum. Not really good for your server performance.
Concur, but I just need something to show quickly. For the short term, can you explain how I would go about that search? I've got this at the top of my list.tpl:
<?php
// base note:
echo $PHORUM['DATA']['FORUM_ID'];
$msg = phorum_db_get_message(9, "message_id", false);
echo nl2br($msg["body"]);
?>
but that "9" obviously needs to be something else. Is there an example of a search call I could use? Or you mention forum_settings, but I haven't discovered that yet. Can you point me somewhere for that? Thanks again!
|
Re: Expanded forum description from a "base note" February 22, 2007 01:57PM |
Admin Registered: 22 years ago Posts: 8,532 |
Take a look at some module settings.php files for getting an idea on how to make use of the phorum settings functionality. You can store data by key. The value can either be a scalar value or an array. Arrays will automatically be stored serialized in the database, so if you retrieve a key for which you stored an array, you'll get an array back.
The search that you do here will return the data for message id 9. That is not a search for subject or anything. You'll get the data for message 9 above every list page this way. Maybe you could use phorum_db_get_message("special subject", "subject", false) for finding the right message. The phorum_db_get_message should return data for the active forum, so if you search by subject this way, you should get the special message for that forum (all untested, but I guess it should work).
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
The search that you do here will return the data for message id 9. That is not a search for subject or anything. You'll get the data for message 9 above every list page this way. Maybe you could use phorum_db_get_message("special subject", "subject", false) for finding the right message. The phorum_db_get_message should return data for the active forum, so if you search by subject this way, you should get the special message for that forum (all untested, but I guess it should work).
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Expanded forum description from a "base note" February 22, 2007 02:27PM |
Registered: 20 years ago Posts: 14 |
Quote
mmakaay
Maybe you could use phorum_db_get_message("special subject", "subject", false) for finding the right message. The phorum_db_get_message should return data for the active forum, so if you search by subject this way, you should get the special message for that forum (all untested, but I guess it should work).
It does! I see how phorum_db_get_message() works now. Showing my work here for posterity:
<?php
// base note:
$msg = phorum_db_get_message("Base note", "subject", false);
echo nl2br($msg["body"]);
if ($PHORUM['DATA']['MODERATOR']) {
echo '<a href="';
echo phorum_get_url(PHORUM_POSTING_URL, 'moderation', $msg['message_id'] );
echo '">[edit]</a>';
}
?>
OK, the final fillip: bbcode. I had scraped an example from another topic in here that mentioned calling nl2br(phorum_bb_code($msg['body'])), but that throws:
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/phorum-5.1.19/mods/bbcode/bbcode.php on line 73
???
|
Re: Expanded forum description from a "base note" February 22, 2007 02:41PM |
Admin Registered: 22 years ago Posts: 8,532 |
nl2br has nothing to do with bbcode. Forget about nl2br and use the normal formatting function for doing this. From the top of my head:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
$msgs = array($msg["message_id"] => $msg);
include_once("./include/format_functions.php");
$msgs = phorum_format_messages($msgs);
$msg = $msgs[$msg["message_id"]];
echo $msg["body"];
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Expanded forum description from a "base note" February 23, 2007 07:11AM |
Registered: 25 years ago Posts: 1,076 |
How many forums do you have, wouldn't it be easier to just hardcode the "message" to list page?
Or use a text file that you read with a simple php function directly to the correct location?
That isn't exactly an elegant solution but the functionality you are trying to achieve doesn't really need an elegant solution.
---
-=[ Panu ]=-
Or use a text file that you read with a simple php function directly to the correct location?
That isn't exactly an elegant solution but the functionality you are trying to achieve doesn't really need an elegant solution.
---
-=[ Panu ]=-
Your IP address, domain or ISP has been blocked. Please contact the forum administrators.
Sorry, only registered users may post in this forum.