
pugdog
User
Karma: -0 / +1
Mar 26, 2006, 9:51 PM
Post #1 of 1
(20507 views)
Shortcut
Send pugdog a wink
|
|
[NEW WIDGET] List newest GForum posts in Glinks
|
Can't Post
|
|
(from a reply on the GT forums, I made) I looked at the suggestions here, and I need something like this too. The best idea, would be if GLinks could read the GForum tables, and yank the data out itself, and stuff it into a <%loop%>able variable, or reversing the logic, if GForum could export an XML/RSS type feed that Glinks could parse and read. Alternatively, creating a subroutine that would pull the data directly from Gforum, with as little overhead as possible, is another. Combining some ideas from about a dozen unrelated threads, you'd end up with something like: <%grab_gforum_newest (10)%> sub { ## this routine will connect to a GForum database, from inside a GLinks template/global ## it will grab the newest posts, 10 of them, and return the ID, Subject and Time of the post. ## You need to loop through the returned value, using standard GT::Template tags, style, etc. my $limit = shift; $limit = 10 if (ref $limit); ## the template parser has a nasty habit of passing in a hash_ref of all tags if no ## value is supplied to the routines. So, we need to check a scalar was passed in. ## a scalar returns "undef" when checked as a reference, so if a ref value exists, it's not a salar use lib '/var/home/bodyartist/tfpmodels.com/cgi-bin/gforum/admin'; my $DB_GFORUM = GT::SQL->new('/var/home/bodyartist/tfpmodels.com/cgi-bin/gforum/admin/defs'); ## force a table object from ANOTHER database ## the GForum must be on the same server/account/etc to work this way my $posts_table = $DB_GFORUM->table('Post'); ## now, create a table object to that new $DB object $posts_table->select_options("ORDER BY post_latest_reply", "LIMIT $limit"); ## set the select options to order the results to pick off the newest my $sth = $posts_table->select('post_id', 'post_subject', 'post_time' => { ## remember, => is just a snooty comma ## forum_id_fk => 123, ## limit to a forum, if you want post_root_id => 0 } ## don't find replies ); ## now, to generalize this routine, so it can be used in other areas, not just this particular one, ## we want to return a <%loop%>able variable, so we can pick out the datafields and format as we need to. ## to locate a post in GForum, all we need is it's ID, and then call it with .../gforum.cgi?post=$id ## real simple, and similar to using jump.cgi?ID=$id ## FYI: remember, you might need to $subject = GT::CGI::html_escape($subject); in some cases/situations. use GT::Date qw/date_get/ ; ## qw/:all/; ## need to do a date transform my @output; while (my $post = $sth->fetchrow_hashref) { $post->{post_time} = date_get($post->{post_time}); # if you have an active forum, you might want to put the time. I *know* there is a better way, # and it should be possible to show the date for posts not made today, and time for posts made # today, but that is up to you. This is just an example of where, and how you could do it. # my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $post->{post_time}; # $post->{post_time} = "$hour:$min:$sec"; push @output, $post; } return ({'GForum_loop' => \@output}); ## return the dereferenced array, the actual data as a tag called <%GForum_loop%> ## which you'd use as <%loop GForum_loop%>...<%endloop%> ## contains the hash_keys post_id, post_subject and post_time ## sample template output line: ## <li><a href="http://url/to/gforum.cgi?post=<%post_id%>"><%escape_html post_subject%></a> at <%post_time%></li> ## if you are using the search engine templates, you can do something like: ## <li><a href="/forum/Post_P<%post_id%>"><%escape_html post_subject%></a> at <%post_time%></li> ## the templates parse out the stuff BEFORE the _P(*\d) and all it looks at is the number after the _P } Note: I have this working, several minor bug fixes, and quirks fixed, date transform support added, some extra example template code, etc. This is working on my site, as noted.
|