FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Looking for hack...
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Looking for hack... [message #3253] Fri, 14 June 2002 23:41 Go to next message
heidiott is currently offline  heidiott   United States
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 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #3258 is a reply to message #3253] Sat, 15 June 2002 03:32 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
That's correct. I switched from phpbb to fudforum and my members love the fudforum boards! With phpbb I had a little script that would pull the last 5 posts to my main site page and I think it helped to get more people to participate in the discussions. If you could show me how I would really appreciate it.
Thank you,
Heidi
Re: Looking for hack... [message #3259 is a reply to message #3258] Sat, 15 June 2002 04:06 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #3260 is a reply to message #3253] Sat, 15 June 2002 04:42 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
I created a test page and there seemed to be an error. I'm just a beginner with php but I think I got the error fixed.
Here is the test page...
http://www.crafterscommunity.com/lastpost.php
The link did not work so I changed this line...
echo "<a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& amp; quot;>".$obj->subject."</a><br>\n";

to this...
echo "<a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& quot;>".$obj->subject."</a><br>\n";

Now it seems to be working great. I have just one more question. I have a hidden forum for my moderators. When this code displays the last posts it also picks up any posts on my moderators board. Is there anyway I can prevent posts from a hidden forum from being displayed?

Thank you so much for your help!
Heidi
Re: Looking for hack... [message #3262 is a reply to message #3260] Sat, 15 June 2002 07:09 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #3278 is a reply to message #3262] Sat, 15 June 2002 17:50 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
I'm getting an error with the last code...

--------------------------------
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/www.crafterscommunity.net/web/test.php on line 10

Warning: Supplied argument is not a valid MySQL result resource in /home/sites/www.crafterscommunity.net/web/test.php on line 26

Warning: Supplied argument is not a valid MySQL result resource in /home/sites/www.crafterscommunity.net/web/test.php on line 31
-------------------------------

These are the lines that the above is refering to...

line 10 ...
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';

line 26 ...
while( $obj = mysql_fetch_object($r) ) {

line 31 ...
mysql_free_result($r);


I hope you got some sleep last night.
The upgrade was well worth it for me. This is by far the best message board I have ever come across! Great job Very Happy

Heidi
Re: Looking for hack... [message #3279 is a reply to message #3278] Sat, 15 June 2002 18:16 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #3281 is a reply to message #3253] Sat, 15 June 2002 19:24 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
Unknown column 'p_VIEW' in 'where clause'
Re: Looking for hack... [message #3283 is a reply to message #3281] Sat, 15 June 2002 19:26 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #3284 is a reply to message #3253] Sat, 15 June 2002 19:28 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
Is is suposed to be p_VISIBLE?
Heidi
Re: Looking for hack... [message #3285 is a reply to message #3253] Sat, 15 June 2002 19:32 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
Well I tried it and it seems to work Smile
If I'm wrong let me know. Thanks again for all your help!
Heidi
Re: Looking for hack... [message #3286 is a reply to message #3253] Sat, 15 June 2002 19:33 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
oops didn't see your reply... going to try that
Heidi
Re: Looking for hack... [message #3287 is a reply to message #3286] Sat, 15 June 2002 23:29 Go to previous messageGo to next message
UserTom is currently offline  UserTom   United States
Messages: 43
Registered: April 2002
Karma: 0
Member
I asked about this feature a while ago. It would be really cool if FUD came with this hack built-in, available as an option...

wink,wink...

-Tom Murray
Re: Looking for hack... [message #3288 is a reply to message #3287] Sat, 15 June 2002 23:51 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
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>&nbsp;<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 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
Ah ha... I got it Very Happy 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>&nbsp;<a href=\"".$WWW_ROOT."msg.php?goto=".$obj->id."\& quot;>".$obj->subject."</a><br>\n";
}
mysql_free_result($r);
}
?>


Re: Looking for hack... [message #4389 is a reply to message #4385] Thu, 25 July 2002 10:22 Go to previous messageGo to next message
UserTom is currently offline  UserTom   United States
Messages: 43
Registered: April 2002
Karma: 0
Member
Heidi-

I just checked out your site. I noticed that the links to the individual posts lead back to the home page, instead of going to the actual post. The strange thing is that the correct address is displayed at the bottom of my browser (ie: msg.php?goto=20394).

-Tom M
Re: Looking for hack... [message #4392 is a reply to message #4389] Thu, 25 July 2002 13:33 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #4394 is a reply to message #3253] Thu, 25 July 2002 14:08 Go to previous messageGo to next message
heidiott is currently offline  heidiott   United States
Messages: 34
Registered: May 2002
Karma: 0
Member
Thank you... I was going to check that yesterday and forgot... Got it working now.
Heidi
icon5.gif  Re: Looking for hack... [message #5530 is a reply to message #4392] Sat, 07 September 2002 07:38 Go to previous messageGo to next message
kewlguy is currently offline  kewlguy   United States
Messages: 9
Registered: August 2002
Location: Gainesville
Karma: 0
Junior Member
I am getting this error when trying to run that code:
"Warning: Failed opening 'core.inc' for inclusion (include_path='.:/usr/local/lib/php') in /home/kewlguy/forum/include/GLOBALS.php on line 133

Warning: Supplied argument is not a valid MySQL result resource in /home/kewlguy/lastpost.php on line 19

Warning: Supplied argument is not a valid MySQL result resource in /home/kewlguy/lastpost.php on line 23"

All of the variables appear to be set properly in GLOBALS.php also, so I don't know what to do. Any suggestions? I can't find anywhere the line that says /usr/local/lib/php!
Re: Looking for hack... [message #5532 is a reply to message #5530] Sat, 07 September 2002 13:34 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Which forum version are you using?

FUDforum Core Developer
Re: Looking for hack... [message #5533 is a reply to message #5532] Sat, 07 September 2002 16:51 Go to previous messageGo to next message
kewlguy is currently offline  kewlguy   United States
Messages: 9
Registered: August 2002
Location: Gainesville
Karma: 0
Junior Member
I'm using version 2.3.0 =)
Re: Looking for hack... [message #5538 is a reply to message #5533] Sat, 07 September 2002 20:07 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous messageGo to next message
ezdb is currently offline  ezdb   China
Messages: 158
Registered: May 2002
Location: china
Karma: 0
Senior Member

it's very good Laughing
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>&nbsp;<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 Go to previous messageGo to next message
kewlguy is currently offline  kewlguy   United States
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 "» &nbsp;<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

icon9.gif  Re: Looking for hack... [message #5638 is a reply to message #5630] Wed, 11 September 2002 03:30 Go to previous messageGo to next message
kewlguy is currently offline  kewlguy   United States
Messages: 9
Registered: August 2002
Location: Gainesville
Karma: 0
Junior Member
Hmm... now this is weird. The posts don't appear to be updating. I tried posting a few sample messages, and it still is showing the posts that were there previously. Does anyone see any errors in my code?
Re: Looking for hack... [message #5640 is a reply to message #5638] Wed, 11 September 2002 14:54 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous messageGo to next message
Sergey is currently offline  Sergey   United States
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 "» &nbsp;<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 Confused . Just getting a blank page...

Can I ask where I need to put this code Rolling Eyes :

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 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #8608 is a reply to message #8595] Tue, 11 February 2003 00:18 Go to previous messageGo to next message
Sergey is currently offline  Sergey   United States
Messages: 41
Registered: January 2003
Karma: 0
Member
prottoss wrote on Mon, 10 February 2003 11:39

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.


Sorry for my stupidness Embarassed
May I just confirm? (I am not that good in php)

I create for example recent.php file with code above and put it inside directory WWW_SERVER_ROOT/theme/default/ or in specific directory under DATA_ROOT ?

And then in which file "forum code" I can include as <?php include("recent.php") ?> ?
In any file in DATA_ROOT/thm/default/tmpl/*.tmpl or DATA_ROOT/src/*.php.t or DATA_ROOT/src/*.inc.t ?

Thank you for your help! Razz


-------------------
"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 #8612 is a reply to message #8608] Tue, 11 February 2003 01:57 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #8633 is a reply to message #8612] Tue, 11 February 2003 23:04 Go to previous messageGo to next message
Sergey is currently offline  Sergey   United States
Messages: 41
Registered: January 2003
Karma: 0
Member
prottoss wrote on Mon, 10 February 2003 20:57

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.


Sorry, I hoped I am not going to bother you either... But ->

I am not good in php and I still can not get it to work Crying or Very Sad

I created file recent.php and put it in WWW_SERVER_ROOT/theme/default/ directory. ($n_post should be specified somewhere and I put in the beginning $n_post=10;)

Then I modified online_today.php.t template by putting <?php include "full_path_to_your_file/recent.php"; ?> at the and after ?> right?...

After I rebuilt my theme I went to the online_today page and get nothing...
I tried for testing purposes to put command 'echo "test";' inside recent.php file . I could see word "test" on the online_today page if I put 'echo' before function or after , but if I put somewhere inside function, I see nothing.

Sorry for being such a pain in the ...


-------------------
"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 #9502 is a reply to message #3253] Wed, 02 April 2003 23:02 Go to previous messageGo to next message
jonrocks is currently offline  jonrocks   United States
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 1145 times)
  • Attachment: ez_sql.php
    (Size: 14.12KB, Downloaded 1240 times)

[Updated on: Wed, 02 April 2003 23:03]

Report message to a moderator

Newest Posts with date and name ? Re: Looking for hack... [message #11584 is a reply to message #9502] Tue, 08 July 2003 11:13 Go to previous messageGo to next message
Zoog is currently offline  Zoog   Germany
Messages: 1
Registered: July 2003
Karma: 0
Junior Member
Well thanks! the above 2 files work great!

What I'm missing now is how the heck to get the name and date displayed with the newest posts?

I hope someone is so fit that it will take them just a few minutes to give me some help or the needed php code.

Thank you in advance!

Hi from Munich, Bavaria, Germany.

[Updated on: Tue, 15 July 2003 10:02]

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 Go to previous messageGo to next message
Wild_Cat is currently offline  Wild_Cat   Ukraine
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."\">&raquo;&raquo;&raquo;</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 Go to previous messageGo to next message
pinion is currently offline  pinion   Canada
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

Re: Newest Posts with date and name ? Re: Looking for hack... [message #15696 is a reply to message #14378] Fri, 02 January 2004 04:00 Go to previous messageGo to next message
Wild_Cat is currently offline  Wild_Cat   Ukraine
Messages: 144
Registered: November 2002
Location: Odessa, Ukraine
Karma: 0
Senior Member
The above code I posted works from 2.5.0 up to 2.5.3RC3 guaranteed
2.6.0 not being a release yet - I haven't installed or tested it.
But certainly, it will be easy enough to modify if it doesn't work then, so you might go for it, just wait for a stable latest release anyway or use what's already here with last stable releases.


Lady of Avalon
Re: Looking for hack... [message #18881 is a reply to message #3253] Wed, 16 June 2004 04:07 Go to previous messageGo to previous message
Zylle is currently offline  Zylle   United States
Messages: 2
Registered: June 2004
Karma: 0
Junior Member
I tried this code with the latest version and it doesn't work.
Pages (2): [1  2    »]  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: New threads on the front page of the site
Next Topic: General Hacking Recommendation please
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 09 18:01:05 GMT 2024

Total time taken to generate the page: 0.03044 seconds