Gossamer Forum
Quote Reply
Hot Threads List...
Is there a way to display a list of the latest hot threads?

Sean
Quote Reply
Re: [SeanP] Hot Threads List... In reply to
you really need to read the help section of your program.
Gossamer Forum Help
Table of Contents
Gossamer Forum Developers Guide : Enhancing Gossamer Forum
There are many different ways you can enhance Gossamer Forum. Plugins are the most advanced way and is a great way to share your addition with others. However, if you just need to add some code, or alter Gossamer Forum so it works for you, there are a couple different things you can do.
Running Custom Code:
Before you get into Plugins, you may not even need them! The template system provides a robust way of adding your own code to Gossamer Forum which will be safe from future upgrades!. It is strongly recommended that you not edit the source, but rather make your changes in separate modules or in template globals. You can do this in one of two ways:

1. Go to Build->Template Globals and you can add a perl subroutine. For instance, to display a list of the top 5 posts with most replies you could do: sub {
my $tags = shift;
my $post_db = $DB->table ('Post');
$post_db->select_options ('ORDER BY post_replies DESC', 'LIMIT 5');
my $sth = $post_db->select;
my @output;
while (my $post = $sth->fetchrow_hashref) {
push @output, $post;
}
return { post_loop => \@output };
}
The first argument is a hash ref of tags that are already available on this page. Your function can either return a hash ref making new tags available, or return HTML that will be displayed to the user. In our case we have created a new tag <%post_loop%> that will be a loop variable of 5 new posts. So you would do:
<%my_global_tag%>
<%loop post_loop%>
Post: <%post_subject%> has <%post_replies%> replies!
<%endloop%>

Assuming my_global_tag is what you save the above tag as.
2. Create your own module with functions, and reference it:
<%Yourmodule::somefunc%>
and it will run somefunc that should be found in Yourmodule.pm. When calling a function <%Module::function%>, it does not get passed any arguments. You can pass in your own arguments <%Yourmodule::somefunc ('This is my first argument', 'This is my second')%>. To get the hash of template tags available, simply call my $tags = GT::Template->tags; inside your code.
Adding Custom Fields:
Adding fields is easy in Gossamer Forum. To add a new field to the User table, simply click on Tools->User. It will show you a list of all the current columns. Do not remove system columns, but you can safely add new fields. Simply click on Add Column at the bottom. This will present you with the following options:
Column Name This is the name of the column, and must be a valid SQL name (so no spaces, etc.) Column Type This is a select list of what type of data you will store. If you need more then 255 characters, you should use a TEXT field. Column Size This is the length of the field and is only required for CHAR types. Column Values
(Only for ENUM fields)
If you are using an ENUM (enumerated) type, then you need to enter the values here. One value per line. For instance if you wanted to add a column Status that could have values 'Cool', 'New', 'Popular', 'Reviewed' only, then you would enter those values her, one per line. Not Null Set to Yes if the user must enter a value, if set to no, the column can be left blank. Default Enter the default value here, this will be what is shown when the user clicks on add. Form Display If your column is named foo_bar then you can enter a pretty name that is used when displaying the column (such as 'My New Column'). Form Type A select list of what type of form you want to use to display this field: checkboxes, radio buttons, textareas, etc. Form Size The SIZE attribute of the form, this determines how large the form appears in the admin. Form Names
(Stored in Database)
If the form type is a select or checkbox, this list controls what names are stored in the database. Form Values
(Displayed on Form)
If the form type is a select or checkbox, this list controls what values are displayed to the user. Form Regex You can enter a regular expression that all input must pass before being submitted. Search Weight This controls whether the field is searchable by the user. The higher the number, the more important the result is.
When you hit submit, the column will automatically appear in your Admin, and be available on your templates as <%ColumnName%>. Table of Contents



Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Post deleted by SeanP In reply to

Last edited by:

SeanP: Apr 15, 2005, 12:38 PM
Quote Reply
Re: [SandraR] Hot Threads List... In reply to
That will work fine for the forum itself, but how do you get a list of the hot threads for the index page (HTML) of a site?

I use includes (SSI) running searches to do some magic with other programs, but do not see where I can do this with links.
Quote Reply
Re: [webslicer] Hot Threads List... In reply to
To start, create a new template set called, oh, ssi.

I'd created an include for the overall forum homepage that showed the newest threads. So in the ssi template set, I stripped out all the unneeded HTML in category_view.html and then called it like this:

Code:
<!--#include virtual="/cgi-bin/forum/gforum.cgi?t=ssi"-->

Last edited by:

agaffin: Jun 21, 2005, 11:55 AM
Quote Reply
Re: [agaffin] Hot Threads List... In reply to
Sounds promising. But how did you reduce the length of the titles, number of posts, etc?

Can you consider sharing the resultant template with us?
It would take many hours to re-create it!
Quote Reply
Re: [webslicer] Hot Threads List... In reply to
Here goes. First, you'll need to scrub some of the styles, tables, etc. in the attached templates, sorry (but hopefully they'll get you started)! Once you do that, create a new template directory and load the attached templates into them.

Create this global (which I got from somewhere here a long time ago):
Code:
sub { my $tags = shift;
my $post_db = $DB->table ('Post');
$post_db->select_options ('WHERE post_root_id=0', 'ORDER BY post_time DESC', 'LIMIT 10');
my $sth = $post_db->select;
my @output;
while (my $post = $sth->fetchrow_hashref) { push @output, $post;
} return { post_loop => \@output };
}

I called it hot_threads; if you change the name, change it in the attached category_list.html. What it does in category_list.html is bring up a list of the linked subject lines of your ten most recent threads (change LIMIT to your tastes). You could also use it to add "descriptions" of the threads, i.e., the first X characters of the first post by creating a separate global called html_strip (a sample is attached) and then wrap the post_message variable in category_list.html with it like this:

Code:
<%html_strip($post_message)%>

It's longer than it should be for an SSI, but I'm also using it to strip out certain characters for generating an RSS feed (the attached version calls up to the first 200 characters). To limit the size of the subject lines, I created a global like this:

Code:
sub {
my $post_subject = shift;
return substr($post_subject,0,60);
}

where "60" is the number of characters you want - and wrap post_subject with it like this:

Code:
<%antisaklad($post_subject)%>

(in honor of a user who was forever writing subject lines as long as your average romance novel).

To actually call all this stuff via SSIs:

Create an SSI pointing at /cgi-bin/forum/gforum.cgi?t=ssi (where "ssi" is the name of your SSI-template directory) to bring up the ten most recent threads (the attached template also has a similar block to call up the ten most posted-to threads; feel free to delete).

If you want to call up the most recently commented-on threads in a particular forum, create an SSI for /cgi-bin/forum/gforum.cgi?forum=24;t=ssi - swapping in the ID number of the actual forum you pointed to.

We're a newspaper, so I also created similar SSIs to link articles to individual comments on them; if you want those, let me know.

Last edited by:

agaffin: Jun 22, 2005, 10:40 AM
Quote Reply
Re: [agaffin] Hot Threads List... In reply to
Thanks!

But I have not been able to get that working for HOT THREADS.

Shouldn't it sort by views to make it a "hot" list?

I am also looking to have the hot threads list output in date ranges: last 24hrs, last 3 days, and by month (between 2 dates)

I guess we would need to select by date range, then by resulting top 10 views. The date range part is wgere I am hung up.
Doing the last x seconds will cover the last day or week Hot list, but a different section of code (I think) is needed to select between 2 dates for last week Hot or Last Month's Hot Threads..

<%GForum::Stats::posts_last(1w)%> will show posts in the last week... Any ideas?

Last edited by:

webslicer: Sep 9, 2005, 5:48 AM
Quote Reply
Re: [webslicer] Hot Threads List... In reply to
FYI, this is a great feature. Thanks... I got it working in no time, and that's saying something!
Quote Reply
Re: [agaffin] Hot Threads List... In reply to
How would I change the following code to, if the subject is over 30 characters, to display the first 30 characters of the subject plus an ellipsis (...) at the end?

Thanks!

Code:

sub {
my $post_subject = shift;
return substr($post_subject,0,60);
}
Quote Reply
Re: [Jobu] Hot Threads List... In reply to
Hi,

This should work

sub {
my $post_subject = shift;
return $post_subject unless(length($post_subject)>30);

return substr($post_subject,0,30);
}

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Hot Threads List... In reply to
In Reply To:
Hi,

This should work

sub {
my $post_subject = shift;
return $post_subject unless(length($post_subject)>30);

return substr($post_subject,0,30);
}

Cheers,


Yeah, I got it working, thanks. Stupid syntax error on my part.