Gossamer Forum
Home : Products : Links 2.0 : Customization :

Top 10 on home page by number of visits

(Page 4 of 5)
> > > >
Quote Reply
Re: Work with site_html.pl In reply to
In Reply To:
Will this same code work with site_html.pl.
Yes...it will...Simply use the following codes in the sub site_html_home routine where you want to print the Top Ten....

Code:

~;
&top_ten;
output .= qq~


Regards,


Eliot Lee
Quote Reply
Re: Work with site_html.pl In reply to
Thanks, but getting an error
*******
Error including libraries: Can't modify constant item in concatenation at /data1/hypermart.net/moneysearch/cgi-bin/admin/site_html.pl line 228, near "~;"
(Might be a runaway multi-line ~~ string starting on line 188)

Make sure they exist, permissions are set properly, and paths are set correctly.
*******

I put in my site_html.pl

##########################################################
## Top 10 sites ##
##########################################################

sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites
open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
$output .= "$count. <a href=\"$url{$field}\">$name{$field}</a>
\n";
}
$count++;
}
return $output;
}



And for the code for the output. I put on my home page, in the site_html.pl

~;
&top_ten;
output .= qq~


Any idea's on why it may not be working.

Thanks for all your help.

John Schultz
www.incomemax.com

Quote Reply
Re: Work with site_html.pl In reply to
The error message indicates that the PROBLEM is NOT in the sub top_ten routine, but in the sub site_html_home routine.

Please post the sub site_html_home routine.

Regards,

Eliot Lee
Quote Reply
Re: Work with site_html.pl In reply to
Here is my sub site_html_home

http://www.incomemax.com/links/site_html_home.txt

Thanks
Again

John

Quote Reply
Re: Work with site_html.pl In reply to
Okay...I gave you slightly bad codes...

Change the codes I gave you to the following:

Code:

~;
&top_ten;
$output = qq~


Regards,


Eliot Lee
Quote Reply
Re: Work with site_html.pl In reply to
Almost there, the errors are gone.

But now, it does not print out the top ten, and all the code above it is gone.

here is a sample

http://www.incomemax.com/links/index.txt

Thanks John

Quote Reply
Re: Top 10 on home page by number of visits In reply to
hello,

I tested the modifications of ELIOT but nothing is displayed. I do not have any error message...

Of what that can it come well?

Thank you,

Laurent


Quote Reply
Re: Work with site_html.pl In reply to
Try the following THEN...

Create a "global" variable for the top_ten sub, like the following:

$top_ten = &top_ten;

AFTER the following codes:

Code:

$date = &get_date;
$time = &get_time;


Then replace the codes I have given you so far with the following codes where you want the TOP TEN to appear in your sub site_html_home:

Code:

$top_ten


Regards,

Eliot Lee
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Stop SHOUTING my name!!

And I have already responded to your duplicate postings!

Regards,

Eliot Lee
Quote Reply
Re: Work with site_html.pl In reply to
Thanks Again for your help.

It finally works.



Thanks for all your help..

John Schultz

Quote Reply
Re: Work with site_html.pl In reply to
You're welcome....

In Reply To:
It finally works.
NOT....my problem...if you want to fix problems quickly, then I would suggest the following:

1) Buy a Perl book, so that you can learn the basic codes that will assist you in customizing your .cgi and .pl scripts.

2) Take some Perl tutorials online (http://www.cgi101.com).

3) Take a Perl programming course.

Wink

Regards,



Eliot Lee
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Can you please give me some more info on how to create a seperate .html file with the top ten so I can use include page to put it on a seperate page. I use include page all the time but I'm not sure how to create the new .html file in links. I created a template with just the top ten global on it and added some code to site_html_templates.pl to try to include the new template in the build process but it doesn't work and I'm stuck. I made my best effort to come up with something on my own but I have no idea how close I am. I'd appreciate any help you can give me.

Thanks much.

Quote Reply
Re: Top 10 on home page by number of visits In reply to
There is a FAQ for creating new .html template files in the Resource Center...Do you know where the Resource Center is located? Have you browsed or searched it? You SHOULD!

Anyway...here is the FAQ:

http://www.anthrotech.com/...inks/faqs/templates/

By using this FAQ, you will be able to use GLOBAL variables in the new template file you create and build via the nph-build.cgi file.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Okay tried this mod and everything is pretty happy except I get a full repeat of all the top 10's
ie: 1-10 in a table
and 1-10 in a table same links

my code:
sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites

open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");

LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
$descrip{$data[0]} = $data[5];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
# $output .= "$count. <a href=\"$url{$field}\">$name{$field}</a>
$descrip{$field}
\n";

$output .= qq|
<table width="90%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#FF0000">
<tr>
<td align="center" valign="middle" width="">$count.</td>
<td valign="middle" width="" height="25" bgcolor="#99CCFF" align="center"><a href=\"$url{$field}\">$name{$field}</a></td>
<td align="center" valign="middle" width="">$descrip{$field}</td>
</tr>
</table>
\n|;

}
$count++;
}
return $output;
}

also I have a small problem the descript instead of "spaces" gives me ''
ie:
dfsadfs``4654546a``asdfdsfs
this is gibberish cause it's a test link

thanks for your help

Quote Reply
Re: Top 10 on home page by number of visits In reply to
okay figured out the repeated table problem:

the comment line was screwing me over.
# $output .= "$count. <a href=\"$url{$field}\">$name{$field}</a>$descrip{$field}\n";

now how do you deal with the spaces ??? anybody have a suggestion?

Quote Reply
Re: [jcrow] Top 10 on home page by number of visits In reply to
Hi!

wondered what code should i put to have links listed like;

1. Site
Hits: 1234
2. Site2
Hits: 1265
3. Site3
Hits: 3435

thanx in advance

Gregor
Quote Reply
Re: [Chewbaca] Top 10 on home page by number of visits In reply to
Hi Elliot!

I'm getting error on your mod. Is there anyway you can send me a copy of the mod in original text file or .cgi/.pl file?. Because I copied exactly the way your mod appeared in this forum but when I installed it. it show errors. I've checked the path, permission they all right. I can't figure out how to get it work. I need your help.


huy

If you can send it to
hxt99@yahoo.com.au
Quote Reply
Re: [huy] Top 10 on home page by number of visits In reply to
What errors???

I ain't a mind reader...please post the exact errors you received and may be we can help you. Ambigous statements like "I got errors" only delays assistance and raises confusion.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Top 10 on home page by number of visits In reply to
HI. I tried inserting this code into my

site_html_tepmplates.pl

here's the error i got

Error including libraries: Missing right bracket at /t4cmini/public_html/cgi-bin/search/admin/site_html_templates.pl line 407, at end of line
syntax error at /t4cmini/public_html/cgi-bin/search/admin/site_html_templates.pl line 407, at EOF

Make sure they exist, permissions are set properly, and paths are set correctly.


I'll post my code.. could you tell me what i did wrong please? thanks!










# -------------
# Links
# -------------
# Links Manager
#
# File: site_html.pl
# Description: This library contains all the HTML that will be generated in
# the finished directory.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.01
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================

# ----------------------------------------------------------------------
# The HTML in this file and the style sheet (links.css) have been authored
# by Chris Croome of webarchitects.
#
# Email: chris@atomism.demon.co.uk
# Web: http://www.webarchitects.co.uk/
# ----------------------------------------------------------------------

# You can put variables here that you would like to use in any
# of your templates.

%globals = (
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
topsites => &top_ten,
css => $build_css_url,
banner => ''
);


sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}

sub site_html_home {
# --------------------------------------------------------# This routine will build a home page. It is not meant to have any # links on it, only subcategories.my (@data,%tophits,%name,%url);open (NAME,"<$db_file_name"); LINE: while(<NAME> ){ next LINE if (/^#/); next LINE if (/^\s*$/); @data=split (/\|/); $tophits{$data[0]} = $data[8]; $name{$data[0]} = $data[1]; $url{$data[0]} = $data[2];}close (NAME);my $count=1;foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {if ($count <= 10) {$topsites_output .= "$count. <a href=\"$url{$field}\">$name{$field}</a><br>\n";}$count++;} return &load_template ('home.html', { topsites_output => $topsites_output, category => $category, grand_total => $grand_total, %globals });}

sub site_html_new {
# --------------------------------------------------------
# This routine will build a what's new page.

return &load_template ('new.html', {
total => $total,
grand_total => $grand_total,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}

sub site_html_cool {
# --------------------------------------------------------
# This routine will build a what's new page.

return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}

sub site_html_detailed {
# --------------------------------------------------------
# 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.
#
my %rec = @_;
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}

sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.

return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}

sub site_html_ratings {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.

return &load_template ( 'rate_top.html', {
top_rated => $top_rated,
top_votes => $top_votes,
%globals
});
}

########################################################################################
# THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!#
########################################################################################

sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;

my $category = shift;
$category ?
($category = qq~$category <input type=hidden name="Category" value="$category">~) :
($category = &build_select_field ("Category", "$in{'Category'}"));

print &load_template ('add.html', {
Category => $category,
%globals
});
}

sub site_html_add_success {
# --------------------------------------------------------
# This routine determines how the add success page will look like.

&html_print_headers;

print &load_template ('add_success.html', {
%in,
%globals
});
}

sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.

my ($errormsg) = shift;
$in{'Category'} ?
($in{'Category'} = qq~<input type=hidden name="Category" value="$in{'Category'}">$in{'Category'}~) :
($in{'Category'} = &build_select_field ("Category"));

&html_print_headers;
print &load_template ('add_error.html', {
error => $errormsg,
%in,
%globals
});

}

sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.

my $category = &build_select_field ("Category", "$in{'Category'}");

&html_print_headers;
print &load_template ('modify.html', {
Category => $category,
%globals
});
}

sub site_html_modify_success {
# --------------------------------------------------------
# This routine determines how the modify success page will look like.

&html_print_headers;
print &load_template ('modify_success.html', {
%in,
%globals
});
}

sub site_html_modify_failure {
# --------------------------------------------------------
# This routine determines how the modify failure page will look like.

my $errormsg = shift;
$in{'Category'} = &build_select_field ("Category", $in{'Category'});

&html_print_headers;
print &load_template ('modify_error.html', {
error => $errormsg,
%in,
%globals
});
}

sub site_html_search_results {
# --------------------------------------------------------
# This routine displays the search results.
#
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_results.html', {
term => $term,
link_results => $link_results,
category_results => $category_results,
next => $next,
cat_hits => $cat_hits,
link_hits => $link_hits,
%in,
%globals
});
}

sub site_html_search_failure {
# --------------------------------------------------------
# This routine displays a failed search page with error in $error.
#
my $error = shift;
my $term = &urlencode ($in{'query'});
&html_print_headers;

print &load_template ('search_error.html', {
term => $term,
error => $error,
%in,
%globals
});
}

sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.

&html_print_headers;
print &load_template ('search.html', {
term => $term,
error => $error,
%in,
%globals
});
}

sub site_html_mailing {
# --------------------------------------------------------
# This routine displays your mailing list subscribe/unsubscribe form.
#
my $action = shift;
my $message;
($action eq 'subscribe') and ($message = qq~You've been successfully subscribed to the mailing list!~);
($action eq 'unsubscribe') and ($message = qq~You've been successfully removed from the mailing list!~);

&html_print_headers;
print &load_template ('email.html', {
message => $message,
%in,
%globals
});
}

sub site_html_mailing_error {
# --------------------------------------------------------
# This routine is displayed if there was a problem subscribing.
#
my $error = shift;

&html_print_headers();
print &load_template ('email_error.html', {
error => $error,
%in,
%globals
});
}

sub site_html_rate_form {
# --------------------------------------------------------
# This routine determines how the rate form page will look like.
#
my %rec = @_;

&html_print_headers;
print &load_template ('rate.html', {
%rec,
%globals
});
}

sub site_html_rate_success {
# --------------------------------------------------------
# This routine determines how the rate success page will look like.

&html_print_headers;
print &load_template ('rate_success.html', {
%in,
%globals
});
}

sub site_html_rate_failure {
# --------------------------------------------------------
# This routine determines how the rate failure page will look like.

my ($errormsg) = shift;

&html_print_headers;
print &load_template ('rate_error.html', {
error => $errormsg,
%in,
%globals
});

}

########################################################################################
# THE FOLLOWING DETERMINES YOUR CATEGORY LISTING, IT'S NOT TEMPLATE BASED (YET)! #
########################################################################################

sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#

my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];

# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;
Quote Reply
Re: [CEGlobe] Top 10 on home page by number of visits In reply to
In Reply To:


return &load_template ('home.html', {
topsites_output => $topsites_output,
category => $category,
grand_total => $grand_total,
%globals
});
}[/code]

Hi, just wondering what happened to "hits => $hits," and what is it for?

Thanks,

Will
Quote Reply
Re: [CEGlobe] Top 10 on home page by number of visits In reply to
 
I get the error:


Unkown Tag: topsites_output

any ideas?

Thanks,

Will
Quote Reply
Re: [Heckler] Top 10 on home page by number of visits In reply to
In Reply To:
$output .= "$count. <a href=\"$url{$field}\">$name{$field}</a>
\n";

I tried chaging to

$output .= "$count. <a href=\"$url{$field}\">$name{$field}</a>
\n". $tophits;

I am trying to show the number of hits... but it doesn't work. Anyone know why?

Thanks,

Will


Quote Reply
Re: [Heckler] Top 10 on home page by number of visits In reply to
Sorry for digging this archive back up, but I have just installed this mod and it works well. At the top of this thread it was asked if the title can be limited to lets say 15 characters. A solution is provided by the use of nested tables.

Its an option but can anyone elese provide another solution, I ask this because some of my titles can be up to 20 - 30 characters in length and its looking messy.

Thanx

Stu
Quote Reply
Re: [stu2000] Top 10 on home page by number of visits In reply to
Search this forum for substr or length, you can reduce the number of characters by using perl.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [stu2000] Top 10 on home page by number of visits In reply to
$variable = substr($variable, 0, 15);

Last edited by:

Paul: Mar 25, 2002, 1:50 AM
> > > >