Looking for hack... [message #3253] |
Fri, 14 June 2002 23:41 |
heidiott
Messages: 34 Registered: May 2002
Karma: 0
|
Member |
|
|
I would love to find a hack that would allow me to put some code on the main page of my site... http://crafterscommunity.com to pull the last 5 posts from the boards... I don't know if anyone has done something like this but any help on how to do it would be appreciated.
Thank you,
Heidi
|
|
|
Re: Looking for hack... [message #3257 is a reply to message #3253] |
Sat, 15 June 2002 01:42 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
It is not an especially difficult thing to do. Do you want to show the last X subjects from the forum and a link to those threads, nothing more, correct?
FUDforum Core Developer
|
|
|
|
Re: Looking for hack... [message #3259 is a reply to message #3258] |
Sat, 15 June 2002 04:06 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
the simplest way to accomplish this would by creating the following php code:
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "path/to/GLOBALS.php";
$cid = mysql_connect($MYSQL_SERVER, $MYSQL_LOGIN, $MYSQL_PASSWORD);
$r = mysql_db_query($MYSQL_DB, "SELECT
fud_msg.id,
fud_msg.subject
FROM
fud_thread
INNER JOIN fud_msg
ON fud_thread.root_msg_id=fud_msg.id
WHERE
fud_msg.approved='Y'
ORDER by
fud_thread.id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
echo "<a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& quot;>".$obj->subject."</a><br>\n";
}
mysql_free_result($r);
}
FUDforum Core Developer
|
|
|
|
Re: Looking for hack... [message #3262 is a reply to message #3260] |
Sat, 15 June 2002 07:09 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Yeah, you need to modify the your code to something like this:
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "path/to/GLOBALS.php";
$cid = mysql_connect($MYSQL_SERVER, $MYSQL_LOGIN, $MYSQL_PASSWORD);
$r = mysql_db_query($MYSQL_DB, "SELECT resource_id FROM fud_group_cache WHERE user_id=0 AND p_VIEW='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($MYSQL_DB, "SELECT
fud_msg.id,
fud_msg.subject
FROM
fud_thread
INNER JOIN fud_msg
ON fud_thread.root_msg_id=fud_msg.id
WHERE
fud_thread.forum_id IN (".$lm.") AND
fud_msg.approved='Y'
ORDER by
fud_thread.id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
echo "<a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& quot;>".$obj->subject."</a><br>\n";
}
mysql_free_result($r);
}
FUDforum Core Developer
|
|
|
|
Re: Looking for hack... [message #3279 is a reply to message #3278] |
Sat, 15 June 2002 18:16 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
mysql_db_query($MYSQL_DB, "SELECT resource_id FROM fud_group_cache WHERE user_id=0 AND p_VIEW='Y'", $cid);
after this line do:
echo mysql_error();
see what it says.
FUDforum Core Developer
|
|
|
|
Re: Looking for hack... [message #3283 is a reply to message #3281] |
Sat, 15 June 2002 19:26 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
D'oh my mistake...
rename p_VIEW to p_READ it'll work.
FUDforum Core Developer
|
|
|
|
|
|
|
Re: Looking for hack... [message #3288 is a reply to message #3287] |
Sat, 15 June 2002 23:51 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
This is not something that is up to FUD to contain. As you see by this function the code is very simple, if you want it write it yourself.
FUDforum Core Developer
|
|
|
Re: Looking for hack... [message #4350 is a reply to message #3253] |
Wed, 24 July 2002 19:00 |
heidiott
Messages: 34 Registered: May 2002
Karma: 0
|
Member |
|
|
I upgraded to the new forum version this morning and now I'm getting the following error with this code...
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/www.crafterscommunity.net/web/test.php on line 11
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/www.crafterscommunity.net/web/test.php on line 27
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/www.crafterscommunity.net/web/test.php on line 32
Here is the code I have in test.php...
<?php
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "/path_removed_/GLOBALS.php";
$cid = mysql_connect($MYSQL_SERVER, $MYSQL_LOGIN, $MYSQL_PASSWORD);
$r = mysql_db_query($MYSQL_DB, "SELECT resource_id FROM fud_group_cache WHERE user_id='0' AND p_READ='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($MYSQL_DB, "SELECT
fud_msg.id,
fud_msg.subject
FROM
fud_thread
INNER JOIN fud_msg
ON fud_thread.root_msg_id=fud_msg.id
WHERE
fud_thread.forum_id IN (".$lm.") AND
fud_msg.approved='Y'
ORDER by
fud_thread.id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
echo "<img src=http://www.crafterscommunity.net/forum/styles/default/goto.gif vspace=3 align=middle> <a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& quot;>".$obj->subject."</a><br>\n";
}
mysql_free_result($r);
}
?>
|
|
|
Re: Looking for hack... [message #4359 is a reply to message #4350] |
Wed, 24 July 2002 20:36 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Do your table names has fud_ prefix or is it something else?
Use mysql_error() function to see the text message, which will explain in detail why your queries have failed.
FUDforum Core Developer
|
|
|
Re: Looking for hack... [message #4385 is a reply to message #3253] |
Thu, 25 July 2002 02:22 |
heidiott
Messages: 34 Registered: May 2002
Karma: 0
|
Member |
|
|
Ah ha... I got it Thanks to your help.
Here is the new code for others who would like to use it with version 2.2.3...
<?php
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "/path_to/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT resource_id FROM fud_group_cache WHERE user_id='0' AND p_READ='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT
fud_msg.id,
fud_msg.subject
FROM
fud_thread
INNER JOIN fud_msg
ON fud_thread.root_msg_id=fud_msg.id
WHERE
fud_thread.forum_id IN (".$lm.") AND
fud_msg.approved='Y'
ORDER by
fud_thread.id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
echo "<img src=http://www.yoursite.com/forum/styles/default/goto.gif vspace=3 align=middle> <a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& quot;>".$obj->subject."</a><br>\n";
}
mysql_free_result($r);
}
?>
|
|
|
|
Re: Looking for hack... [message #4392 is a reply to message #4389] |
Thu, 25 July 2002 13:33 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
yeah the links seem wrong
they should be
index.php?t=msg&goto=message_id
FUDforum Core Developer
|
|
|
|
|
|
|
Re: Looking for hack... [message #5538 is a reply to message #5533] |
Sat, 07 September 2002 20:07 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
did you modify the MySQL table prefixes with your table prefix,. rather then 'fud_' that is used in the example?
FUDforum Core Developer
|
|
|
Re: Looking for hack... [message #5544 is a reply to message #5538] |
Sun, 08 September 2002 02:35 |
|
it's very good
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "/path_to/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT resource_id FROM ".$DBHOST_TBL_PREFIX."group_cache WHERE user_id=0 AND p_READ='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT
".$DBHOST_TBL_PREFIX."msg.id,
".$DBHOST_TBL_PREFIX."msg.subject
FROM
".$DBHOST_TBL_PREFIX."thread
INNER JOIN ".$DBHOST_TBL_PREFIX."msg
ON ".$DBHOST_TBL_PREFIX."thread.root_msg_id=".$DBHOST_TBL_PREFI X."msg.id
WHERE
".$DBHOST_TBL_PREFIX."thread.forum_id IN (".$lm.") AND
".$DBHOST_TBL_PREFIX."msg.approved='Y'
ORDER by
".$DBHOST_TBL_PREFIX."thread.id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
echo "<img src=http://fi7pyu.free.fr/bbs/theme/default/images/goto.gif vspace=3 align=middle> <a href=\"".$WWW_ROOT."index.php?t=msg&goto=".$obj-> ;id."\"& quot; target=\"_blank\">".$obj->subject."</a>< br>\n";
}
mysql_free_result($r);
}
http://fi7pyu.free.fr/bbs/lastpost.php
[Updated on: Sun, 08 September 2002 02:43] Report message to a moderator
|
|
|
Re: Looking for hack... [message #5630 is a reply to message #5544] |
Tue, 10 September 2002 21:55 |
kewlguy
Messages: 9 Registered: August 2002 Location: Gainesville
Karma: 0
|
Junior Member |
|
|
Ok, finally got it to work, it took this code:
<?php
// n_posts is the number of messages you wish to fetch
function fetch_forum_posts($n_posts)
{
include_once "/path/to/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT resource_id FROM ".$DBHOST_TBL_PREFIX."group_cache WHERE user_id=0 AND p_READ='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT ".$DBHOST_TBL_PREFIX."msg.id, ".$DBHOST_TBL_PREFIX."msg.subject
FROM ".$DBHOST_TBL_PREFIX."thread INNER JOIN ".$DBHOST_TBL_PREFIX."msg
ON ".$DBHOST_TBL_PREFIX."thread.root_msg_id=".$DBHOST_TBL_PREFI X."msg.id
WHERE ".$DBHOST_TBL_PREFIX."thread.forum_id IN (".$lm.") AND
".$DBHOST_TBL_PREFIX."msg.approved='Y' ORDER by ".$DBHOST_TBL_PREFIX."thread.id DESC LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
// Here you do your actual code, below is a working example
print "» <a class =\"menubar\" href=\"";
print $WWW_ROOT . "index.php?t=msg&goto=" . $obj->id . "\" target=\"_blank\">" . $obj->subject;
print "</a><br>\n";
}
mysql_free_result($r);
}
?>
Thanks everyone!
[Updated on: Tue, 10 September 2002 21:56] Report message to a moderator
|
|
|
|
Re: Looking for hack... [message #5640 is a reply to message #5638] |
Wed, 11 September 2002 14:54 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
I believe the ORDER BY is wrong, it should order by thread.last_post_id not thread.id
FUDforum Core Developer
|
|
|
Re: Looking for hack... [message #8594 is a reply to message #5630] |
Mon, 10 February 2003 16:34 |
|
Sergey
Messages: 41 Registered: January 2003
Karma: 0
|
Member |
|
|
kewlguy wrote on Tue, 10 September 2002 17:55 | Ok, finally got it to work, it took this code:
<?php
// n_posts is the number of messages you wish to fetch
function fetch_forum_posts($n_posts)
{
include_once "/path/to/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT resource_id FROM ".$DBHOST_TBL_PREFIX."group_cache WHERE user_id=0 AND p_READ='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT ".$DBHOST_TBL_PREFIX."msg.id, ".$DBHOST_TBL_PREFIX."msg.subject
FROM ".$DBHOST_TBL_PREFIX."thread INNER JOIN ".$DBHOST_TBL_PREFIX."msg
ON ".$DBHOST_TBL_PREFIX."thread.root_msg_id=".$DBHOST_TBL_PREFI X."msg.id
WHERE ".$DBHOST_TBL_PREFIX."thread.forum_id IN (".$lm.") AND
".$DBHOST_TBL_PREFIX."msg.approved='Y' ORDER by ".$DBHOST_TBL_PREFIX."thread.id DESC LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
// Here you do your actual code, below is a working example
print "» <a class =\"menubar\" href=\"";
print $WWW_ROOT . "index.php?t=msg&goto=" . $obj->id . "\" target=\"_blank\">" . $obj->subject;
print "</a><br>\n";
}
mysql_free_result($r);
}
?>
Thanks everyone!
|
I am trying to do recent posts on my forum also, but can not to get it work correctly . Just getting a blank page...
Can I ask where I need to put this code :
1. As a separate .php page in forum/default directory?
2. As a some kind of template where all templates are?
3. As a .php somewhere and then call it as <? php include ?> in page where I want to see resent posts?
4. As a function somewhere in existing file?
Thanx everybody who can help me on this one!
-------------------
"If you really want something in this life you have to work for it.
Now quiet, they're about to announce the lottery numbers."
Author: Homer Simpson.
|
|
|
Re: Looking for hack... [message #8595 is a reply to message #8594] |
Mon, 10 February 2003 16:39 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Except #1 all of the solutions can be safely used.
For simplicity you could put your code inside the .php file and then include that file from the forum code.
FUDforum Core Developer
|
|
|
|
Re: Looking for hack... [message #8612 is a reply to message #8608] |
Tue, 11 February 2003 01:57 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Suppose you've decided to include your php script inside post page. So the process would be quite simple, take you php script and place it anywhere. The open post.php.t (PHP source of the template) and add <?php include "full_path_to_your_file.php"; ?>. Now go to template editor and rebuilt your theme.
Voila.
FUDforum Core Developer
|
|
|
|
Re: Looking for hack... [message #9502 is a reply to message #3253] |
Wed, 02 April 2003 23:02 |
jonrocks
Messages: 1 Registered: April 2003
Karma: 0
|
Junior Member |
|
|
Here is, at least what i think, an easier to use php script to do the samething. Just go though both php files and edit them. the ez_sql file you just need to edit these lines
// User Settings -- CHANGE HERE
define("EZSQL_DB_USER", "username"); // <-- mysql db user (change username)
define("EZSQL_DB_PASSWORD", "password"); // <-- mysql db password (change password)
define("EZSQL_DB_NAME", "dbname"); // <-- mysql db pname (change dbname)
define("EZSQL_DB_HOST", "localhost"); // <-- mysql server host (change localhost to your host, most likely is localhost though)
// ==================================================================
It should be quite straight forward. The other php script latest.php should not need to be changed, but it would be worthit to go though it just incase.
You can check out a working example here http://www.jonmm.com/latest.php
-
Attachment: latest.php
(Size: 1.43KB, Downloaded 1152 times)
-
Attachment: ez_sql.php
(Size: 14.12KB, Downloaded 1247 times)
[Updated on: Wed, 02 April 2003 23:03] Report message to a moderator
|
|
|
|
Re: Newest Posts with date and name ? Re: Looking for hack... [message #12061 is a reply to message #11584] |
Sun, 27 July 2003 13:37 |
|
Wild_Cat
Messages: 144 Registered: November 2002 Location: Odessa, Ukraine
Karma: 0
|
Senior Member |
|
|
Well, I needed the dates too, so, although I'm by far not a PHP pro, I optimised the code given by protoss to a template-like result: you don't have to watch your server_name/db_name/username/password/MySQL table prefixes any more - it takes it all from your GLOBALS.php
(it also pointed out to msg.php in the root dir which doesn't exist in version 2.5.0 which I use and for which this code is done consequently)
and I managed to add the date to the code, it turned out to be indeed easy enough. Well, it took me more than a couple of minutes, since I'm not an SQL pro either but I needed it myself, so... here you are:
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "forum/fud/include/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
$tbl = $DBHOST_TBL_PREFIX;
$r = mysql_db_query($DBHOST_DBNAME, "SELECT resource_id FROM ".$tbl."group_cache
WHERE user_id=0 AND p_READ='Y'", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT
".$tbl."msg.id,
".$tbl."msg.subject,
".$tbl."thread.last_post_date,
".$tbl."thread.last_post_id
FROM
".$tbl."thread
INNER JOIN ".$tbl."msg
ON ".$tbl."thread.root_msg_id=".$tbl."msg.id
WHERE
".$tbl."thread.forum_id IN (".$lm.") AND
".$tbl."msg.approved='Y'
ORDER by
".$tbl."thread.last_post_id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
$tm = date("d/m/Y H:i", $obj->last_post_date);
echo $tm." - <a href=\"".$WWW_ROOT."index.php?t=msg&goto=".$obj->id."\">".$obj->subject."</a>
<a href=\"".$WWW_ROOT."index.php?t=tree&goto=".$obj->last_post_id."\">»»»</a><br>\n";
}
mysql_free_result($r);
}
So then you only have to call on that function, indicating as parameter the number of posts you want to fetch. For changing the date-time format in the date() function - see the PHP help file.
Here is the working example (theme names in Russian but it's not essential) http://avalon.net.ua/forum.php calling fetch_forum_posts(5);
I have updated the script for myself with another feature and do so for you. Now you have two links:
1) [/u]thread root message subject[/u] - linking to the beginning of the theme in flat view;
2) [/u]>>>>>>[/u] - linking to the last message of the thread in tree view
(you may vary them at will/need)
Lady of Avalon
[Updated on: Fri, 02 January 2004 03:54] Report message to a moderator
|
|
|
Re: Newest Posts with date and name ? Re: Looking for hack... [message #14378 is a reply to message #12061] |
Thu, 13 November 2003 13:39 |
pinion
Messages: 2 Registered: November 2003
Karma: 0
|
Junior Member |
|
|
I'm strongly considering switching to this board software, but being able to install this hack is a must. "jonrocks" attachments seem to have been deleted, and every message in this thread has been posted quite a while ago so I'm worried it may no longer work with the latest version of the board.
Is there still an easy-to-install working version available? Please help.
[Updated on: Thu, 13 November 2003 13:45] Report message to a moderator
|
|
|
|
|