Gossamer Forum
Home : Products : Links 2.0 : Customization :

Comments 4 MOD and Detailed Pages

Quote Reply
Comments 4 MOD and Detailed Pages
I'm using the Comments 4 Lite mod. I wanted to have comments show up on detailed pages, but read in this thread (http://gossamer-threads.com/...uest=10367102#235551) that you can't do that. Instead you have to have details show up on comments pages. I guess you can do that because links.def is required in comments4l.cgi. My problem is that none of my tags are working. I added them, as the thread suggested, in site_html_templates under sub site_html_comments4l. Added:

title => $db_title,
review => $db_review,
description => $db_description,
author => $db_author,
isbn => $db_isbn,
publisher => $db_publisher,
pubyear => $db_pubyear,
image => $db_image,
price => $db_price,

But they're still not showing up. I keep getting "Unkown Tag: Title", etc. So I tried changing all the tags in the comments4l.html template to lowercase (i.e., <%title%> instead of <%Title%>. That made a page come up, but all I got were the field numbers of each, instead of the info. I'm kind of stuck at this point. Don't know what else to try. Does anyone have a suggestion?

Thanks,

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
I've been considering adding this to my new site [under development]; if I get it working, with the comments on the detail page (or the details on the comments page...), I'll let you know what I did...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Ok, got the basic Comments 4lite mod up and running, now comes the customization... Cool

Try adding this in comments4l.cgi

require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/comments.def";
require "$db_lib_path/links.def";


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Forget that last suggestion...

What I did was, in comments4l.cgi, change this:

sub main {
#-------------------------------------------------------------------
local (%in) = &parse_form;

$in{'post_comment'} ? &post_comment : &display;

#if ($in = 'post_comment'){
#&post_comment;
#}
#elsif ($in = 'display') {
#&display;
#}
# else {
# &site_error;
# }


} # keep


Now change your link to the comment page like so:

<a href="<%db_cgi_url%>/comments4l.cgi?LID=<%ID%>">Comments</a><%totals%>

Note that "function=display&" has been removed.

Then I copied my detail.html template into the comments4l.html template, leaving only this from the original:

<!-- comments test 1 -->
<b><h2>Comments</h2></b>
<%pheader%>
<%comments%>
<!-- comments test 1 -->

Then put in everything from your sub build_detailed_page that is missing in the sub site_html_comments4l routine.

Now all your tags should work --- mine do!
Next, in comments4l.cgi, add this:

<td><input type="SUBMIT" name="post_comment" value="Add Comment"></form></td>

You can remove this from the form: <input type="HIDDEN" NAME="function" VALUE="post_comment">.

There is the problem now that the comment success and comment error pages include all of the detail page info. These need to be set to use new templates. Also, with the way I have it set right now, there is no error page, as the 'else' has been taken out of the loop. Well, you do get one if you try to post comments too soon. (Error You have already submitted a review/comment for this site)

I'll look at it more later, it's past 3AM... Crazy


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
That's great. I'm glad you got the build part working. I'm still having trouble with tags showing up. comments4l.cgi doesn't seem to be reading links.def, no matter what I do to site_html_templates. I've tried:

title => $title,
review => $review,
description => $description,
author => $author,
rating => $rating,


(I get Tag Unknown) and:

title => $db_title,
review => $db_review,
description => $db_description,
author => $db_author,
rating => $db_rating,

(I get Tag Unknown; I get the field number instead of the info, IF I change the tags on the template to lowercase) so...and:

Title => $title,
Review => $review,
Description => $description,
Author => $author,
Rating => $rating,

(I get blank space, no field number or info) and:

Title => $db_title,
Review => $db_review,
Description => $db_description,
Author => $db_author,
Rating => $db_rating,

(Again, I get the field number but no info).

If I put in

require "admin/links.def";

then comments4l.cgi can't read comments.def, and gives me Tag Unknown for all its own tags.

It's like comments4l.cgi will only read one database at a time. Putting them in site_html_templates only keeps me from getting an Unknown Tag error. But comments4l.cgi still doesn't know where to go to get the info--it's not using links.def (unless you tell it to, but then it doesn't use comments.def) But doesn't comments4l.cgi require links.cfg I'm reading require "admin/links.cfg"; right in the script. So if links.cfg is being read, wouldn't that make the links.def fields work?

I don't know what else to try or do, but start screaming Help, help, help, help!!

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
I did not have to define the tags that are normally available, just the ones I have customized:

# Comments 4 mod >
sub site_html_comments4l {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
&html_print_headers;

# Put linked-cat in link
$cat_url = &urlencode($rec{Category});
$cat_clean = &build_clean($rec{Category});

($rec{'isMapped'} eq 'Yes') ? ($rec{'isMapped'} = 1) : (delete $rec{'isMapped'});
print &load_template ('comments4l.html', {
pheader => $pheader,
comments => $comments, rate_image => &get_rating_image($rec{'Rating'}),
street_address => ($rec{'Street Address'}),
city => ($rec{'City'}),
street_address_url => &encode_map_url ($rec{'Street Address'}),
city_url => &encode_map_url ($rec{'City'}),
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
cat_clean => $cat_clean,
cat_url => $cat_url,

%rec,
%in,
%globals
} );
}

In the comment4l.cgi, this line is taking the input and getting the record:

require "$db_lib_path/links.def";
my %rec = &get_record ($in{'LID'});

So yes, you should be getting the info. Did you make the changes as I outlined? After I got it working, I went back and put the code the way it came, and it did not work (unknown tags), but what I posted should work. Note also that the mod instrctions are a bit off, the links.cfg changes should be like so:

# Comments 4 mod >
$db_comments_name = "$db_script_path/data/comments.db"; # PATH to comments database.
$db_comments_id_file_name = "$db_script_path/data/comments4id.txt"; # PATH to comments counter file.
$db_images = "$build_root_url/images"; # URL to where your two images are
# < Comments 4 mod


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Oh, wow. It works.


A moment of silence, there. Smile

Yep, that was it. I wasn't defining the tags correctly. I had author => $author. When I used author => ($rec{'Author'}) everything worked fine. Geez. If I knew even an ounce of perl, I wouldn't have made such a dumb mistake...and wasted almost two days over it.


Kathy

Last edited by:

KM: Jan 20, 2005, 12:24 PM
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
Okay. I just tried to add a comment and I saw that nightmare phrase again--"Unknown Tag." Yikes. Doesn't it use sub site_html_comments4l when printing new comments? Did you have this problem?

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
Yes, I had the same problem. Here is the fix:

In comments4l.cgi, move

require "$db_lib_path/links.def";
my %rec = &get_record ($in{'LID'});


from sub display to sub main, putting it just under this:

local (%in) = &parse_form;

Viola!

To get the linked title working (called with <%title_linked%>), put this in the sub site_html_comments4:

title_linked => &build_linked_title ("$rec{'Category'}/$rec{'Title'}"),

Then put this at the bottom of comments4l.cgi:

sub build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.

my $input = shift;
my (@dirs, $dir, $output, $path, $last);

@dirs = split (/\//, $input);
$last = &build_clean(pop @dirs);

$output = qq| <A HREF="$build_root_url/">$build_site_title</A> >|;
foreach $dir (@dirs) {
$path .= "/$dir";
$dir = &build_clean ($dir);
$output .= qq| <A HREF="$build_root_url$path/">$dir</A> >|;
}
$output .= " $last";

return $output;
}



Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Jan 20, 2005, 2:39 PM
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Okay. I tried that. I got Tag Unknown, ReviewTitle--ReviewTitle is the only field I'd added to comments.db. So, thinking it just wasn't recognizing an odd field, I tried taking it out (of db, template, etc.) I'm not getting an error, but I'm not getting comments, either. Any ideas?

Oh, and I didn't put in the linked_title sub because I'm not using linked titles (this is for a bookstore with book titles).

Kathy

Here's a bit more detail.

When I leave those two lines in sub display I get:
Unknown Tag: Author (a field defined in links.def) when try to add new comment

If I put them in both sub display and sub main, I get errors in place of comments on the page telling me the links.def fields are blank:

Date (Can not be left blank)
Category (Can not be left blank)
PubYear (Too long. Max length: 4)
Contact Email (Can not be left blank)
Votes (Can not be left blank)

If I put them in sub main, I get:
Unkown Tag: ReviewTitle (a field defined in comments.def) in place of comments on the page.

When I took ReviewTitle field out, I got another error, this time Unknown Tag: Contact Name, so it isn't recognizing any fields defined in comments.def.

My head hurts. I need chocolate.

Kathy

Last edited by:

KM: Jan 20, 2005, 4:17 PM
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
I see you're doing the same dance I am! Pirate

Yes, I have discovered problems after moving those two lines. So, take them out of sub main, put them back in sub display. I have also added them to sub site_error:

sub site_error {
# --------------------------------------------------------
#Displays the error page
my $error = shift;
require "$db_lib_path/links.def";
my %rec = &get_record ($in{'LID'});

$pheader= "Error";

I also put them in sub post_comment, just above:

$state = "added";

This presents all the page info correct except the link ID, which now appears as the comment ID. Kinda kills the jump.cgi (and rate, etc) action... Frown

I will probably make it go to a new template for the success and error pages, instead of re-displaying all the detail info (mine includes photos).

Chocolate sounds like an EXCELLENT idea! Smile


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Yes! How nice to finally get to a comments posted page. Wow, you've done a lot of hard work to get this far. I wish I was more help. I just keep asking questions and pointing out problems you already know about. Not very helpful. But what a great job you've done! GLad I got to watch.

If you do make templates, let me know. I'd love to have them. Right now, I've put a javascript back link on the page, which takes them back two pages to the category page. If I take them back only one page, I get another Unknown Tag error (I'm beginning to dread and hate those two words). That's okay for a page with a few books, I guess, but not one with a ton of site links.

Yes, the chocolate helped. And I don't even feel guilty. Smile

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
To have a different page used for error and success results, do this:

In sub site_error, and in sub post_comment (just below #YOU MUST LEAVE THE ABOVE LINK BACK TO MY SITE INTACT. DO NOT remove it. ), change this...

&site_html_comments4l;

to this...

&site_html_comments4_plain;

Then in site_html_templates.pl, add this sub after the other two:

sub site_html_comments4_plain {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
&html_print_headers;

print &load_template ('comments4_plain.html', {
pheader => $pheader,
comments => $comments,
title_linked => &build_linked_title ("$rec{'Category'}/$rec{'Title'}"),
%rec,
%in,
%globals
} );
}


Then make a new template, named comments4_plain.html, like so:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/...TD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
<%site_title%>: Comments Results
</title>
<link
rel="stylesheet"
type="text/css"
href="<%build_root_url%>/links.css" />
</head>
<%include header.txt%>
<!-- begin unique content -->
<div id="maincol">
<p>
<strong
class="title"><%title_linked%></strong>
</p>
<div class="whatis">
<%Title%>
</div>
<%pheader%>
<%comments%>

</div>
<!-- end unique content -->
<%include footer.txt%>


The red part is what you need to have, the rest can match your site.
There, that was simple! Wink

You can change the messages to whatever you want, in comments4l.cgi:

sub site_error {
# --------------------------------------------------------
#Displays the error page
my $error = shift;
$pheader= "Error";
$comments = qq|$error<br><br>
<br>
Add your text here! <br>
<center>Using comments 4 mod from <a href = "http://cgi-resource.co.uk">GB resources</a>
</center>
|;


and in sub post_comment:

$state = "added";

$pheader= "Comment added";
$comments = qq|Your comment has been added<br>Whatever!<br>
<br>
<center>Using comments 4 mod from <a href = "http://cgi-resource.co.uk">GB resources</a>
</center>
|;

&site_html_comments4_plain;


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
This is so sweet. It works like a dream. Very, very nice. Thank you. You really should write this up and stick it in the Resources section. It's great!

In comments4l.cgi, under the messages ($comments) to be sent on your new comments2_plain.html template, I added:

<center><b><a href="http://whatever.com/cgi-bin/comments4l.cgi?LID=$rec{'ID'}">Return to the Page</a></b><br></center>

With the javascript return, back button, etc., I kept running into more (yes, you guessed it) Unknown Tag errors. This seems to work and take you back to a clean page, with the comment loaded.

Hey, it might be a puny, small little thing, but at least I can say I contributed. Smile

Thank you again for all your hard work. Now, can you recommend a good perl book? (I'm serious. It's time.)

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
I'm having a small problem. My rate images aren't showing up on comments4l.html. I'm using the 5 star rating mod. Have this in my sub site_html_link:

$rating = qq|<img src="http://x.org/images/rate-5.gif">| if ($rec{'Rating'} =~ /(9|10)(\.\d\d)?/);
$rating = qq|<img src="http://x.org/images/rate-4.gif">| if ($rec{'Rating'} =~ /(7|8)(\.\d\d)?/);
$rating = qq|<img src="http://x.org/images/rate-3.gif">| if ($rec{'Rating'} =~ /(5|6)(\.\d\d)?/);
$rating = qq|<img src="http://x.org/images/rate-2.gif">| if ($rec{'Rating'} =~ /(3|4)(\.\d\d)?/);
$rating = qq|<img src="http://x.org/images/rate-1.gif">| if ($rec{'Rating'} =~ /(1|2)(\.\d\d)?/);
$rating = qq|<small>Not Rated Yet</small>| if ($rec{'Rating'} < 1);

have rate_img => $rating, defined in sub html_link and sub site_html_comments4l

and am using the tag <%rate_img%> on links.html and comments4l.html.

If I use this - rate_img => ($rec{'Rating'}), - in sub site_html_comments4l I do get a rating, but not the image. How do I define the rate_img in this sub so the I get an image?

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
I use a different image rate mod, and it works OK. Try this:

rate_img => ($rec{'rating'}),

--Note the lowercase 'r'.

Your back-link is good; I made up a modified linked-title sub to do that, but your is much simpler. Good job! Wink

---
edit - instead of Return to the Page, use Return to $rec{'Title'}
- instead of hard-coding your url into the link, use ...href="$db_cgi_url/comments4l.cgi...
---


As you can tell, my coding is trial-and-error, so I do refer to books frequently! These two are what I am using:

Perl (Your visual blueprint for building Perl scripts) by Whitehead and Kramer, pub by Visual

Perl and CGI for the WWW by Elizabeth Castro, pub by Peachpit Press


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Jan 21, 2005, 11:13 AM
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Another fix:

To get gramatically correct stats...


There is 1 comment for this advertiser.
1 person liked this site, 0 thought it was okay, and 0 didn't like it.

There are 3 comments for this advertiser.
2 people liked this site, 1 thought it was okay, and 0 didn't like it.


...replace this code:

$pheader = qq|<div class="title_trail">There are $links comments for $rec{'Title'}
<br />(<b>$rate1</b> people liked the site)
(<b>$rate2</b> thought it was okay)
(<b>$rate3</b> didn't like it)
</div>
|;


...with this:

if ($links == 1) {
$gram_1 = "is <b>$links<\/b> comment";
}
else {
$gram_1 = "are <b>$links<\/b> comments";
}
if ($rate1 == 1) {
$gram_2 = "<b>$rate1<\/b> person";
}
else {
$gram_2 = "<b>$rate1<\/b> people";
}
$pheader = qq|<div class="title_trail">There $gram_1 for this advertiser<br />
$gram_2 liked this site, <b>$rate2</b> thought it was okay, and <b>$rate3</b> didn't like it.
</div>
|;




Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments 4 MOD and Detailed Pages In reply to
Thanks for the suggestions. My rating images still wouldn't show up. What I finally tried was restating the code entirely in sub site_html_comments4l. So I put this in both sub site_html_comments4l and sub site_html_link:

$rating = qq|<img src="http://www.xx.org/.../rategifs/rate-5.gif">| if ($rec{'Rating'} =~ /(9|10)(\.\d\d)?/);
$rating = qq|<img src="http://www.xx.org/.../rategifs/rate-4.gif">| if ($rec{'Rating'} =~ /(7|8)(\.\d\d)?/);
$rating = qq|<img src="http://www.xx.org/.../rategifs/rate-3.gif">| if ($rec{'Rating'} =~ /(5|6)(\.\d\d)?/);
$rating = qq|<img src="http://www.xx.org/.../rategifs/rate-2.gif">| if ($rec{'Rating'} =~ /(3|4)(\.\d\d)?/);
$rating = qq|<img src="http://www.xx.org/.../rategifs/rate-1.gif">| if ($rec{'Rating'} =~ /(1|2)(\.\d\d)?/);
$rating = qq|<small>Not Yet Rated</small>| if ($rec{'Rating'} < 1);

and defined it like you suggested in sub site_html_comments4l:

rate_img => $rating

Works great now! I've got to tell you, I'm really pleased with how the pages look. Question: Do dynamic comments.html pages take more bandwidth to display than static detailed.html pages? Not sure about my terminology--hope you understand my question.

Kathy
Quote Reply
Re: [KM] Comments 4 MOD and Detailed Pages In reply to
I don't think dynamic pages use more 'bandwidth'...

Quote:

The amount of data that can be transmitted in a fixed amount of time. For digital devices, the bandwidth is usually expressed in bits per second(bps) or bytes per second.


What they effect is server load, or...

Quote:

... the amount of data (traffic) being carried by the network.


This is not a problem unless your site gets REALLY busy. My econo-package gives me 5 GB Transfer (5,120 MB Bandwidth) . For January, I am at 218830 Kb. Using the formula below, that's almost 214MB, FAR short of my limit. Of course, many sites get LOTS more traffic.

Quote:
KBytes sent:
Whenever a user visits a page, downloads a file, or views an image, data is transferred. KBytes sent is a measure of the amount of data that has transferred, measured in Kilobytes, or Kb. This is also equates to the amount of bandwidth being transferred.

If you need to know how many Megabytes has been transferred, divide this number by 1024. To convert to Gigabytes, simply divide again by 1024. You may also type the number Kbytes sent in the form below to have the total calculated for you.


Anyway, glad you got your graphics figured out!


Leonard
aka PerlFlunkie