Gossamer Forum
Home : Products : Links 2.0 : Customization :

Post all links no matter what category on one page

Quote Reply
Post all links no matter what category on one page
I would like to post all links no matter what category on one page. How can I go about doing this?

Thanks!
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
I've been trying to do this myself. It should be easy to modify the links tree mod if you know CGI. Unfortunately, I don't, so I've wasted all day trying to make it work.

I'm hoping somebody else can help us out here. The links tree mod is nice and compact, and would work perfectly. It sorts the links alphabetically, and works great. The only modification I need is that I want all of the links to be in one (long) list, without being sorted by categories.

For a CGI pro, this seems like an easy hack, so how about some help please!
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
Paul (moderator) had a mod at http://www.gossamer-threads.com/...D%20-%20NewX;#168184 to produce a Top X list list which I modified slightly. Here is what he had

Code:
#!/usr/bin/perleval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1");
require "admin/links.cfg";
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
};
if ($@) {
print "Content-type: text/plain\n\n";
print $@;
exit;
}

&main;

sub main {

my @data = `tail -$max_new $db_links_name`;
my $i = 0;
print "Content-type: text/html\n\n";
print "<table>";
foreach (@data) {
$i++;
chomp;
split /\|/;
print qq|<tr><td>$i.</td><td><a href="$_[$db_url]">$_[$db_title]</a></td></tr>|;
}
print "</table>";
}

Then in links.cfg add a new variable:

$max_new = X;

X being the number of new links you want to show.

Then include the file into your page using SSI ...eg

<!--#exec cgi="/cgi-bin/links/topx.cgi"-->



I renamed it list.cgi

Code:
#!/usr/bin/perleval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1");
require "/home/acct351/cgi-bin/links/admin/links.cfg";
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";};
if ($@) {
print "Content-type: text/plain\n\n";
print $@;
exit;
}
&main;sub main {
my @data = `tail -999 $db_links_name`;
my $i = 0;
my $cat="";
my $rest="";
print "Content-type: text/html\n\n";
foreach (@data) {
$i++;
chomp;
split /\|/;
# $_[$db_desc] =~ s,\`\`,<br>,g; this also works
$_[$db_desc] =~ s,``,<br>,g;
$_[$db_category] =~ s,_,&nbsp;,g;
($cat, $rest)= split(/\//,$_[$db_category]);
print qq|
<TR class="test" onmouseover="this.className='test2'" onmouseout="this.className='test'">
<TD width=15 ALIGN=RIGHT VALIGN=top><FONT class=f3>$i.</FONT></TD>
<TD width=100 VALIGN=top>
<A class=mLink HREF="http://">Email</A></TD"]mailto:$_[$db_contact_email]">Email</A></TD>
<TD width=100 VALIGN=top><FONT class=f3>$_[$db_area]</FONT>&nbsp;</TD>
<TD width=400 VALIGN=top><FONT class=f3>$_[$db_desc]</FONT>&nbsp;</TD></TR>|;
}
}


Ignore all the reference to class, mouseovers/outs. I just added some stuff to allow sorting by clicking on the columns headings and to highlight the active row.

OK, don't laugh. I'm sure it is not very good but it works. and I don't use it often.

Paul gets all the credit for this. I just added a little html stuff.

I'm not sure about the "tail" thing. But I guess it starts at the last record and works backward. I have don't have that many records so the - 999 works OK. Somehow it starts at the first record and then goes to the last record.

here is what the table looks like

Code:
<TABLE id=table2 class=tblborder1 BORDER=1 BGCOLOR="#CDD3F8"
CELLSPACING=0 CELLPADDING=6 WIDTH="96%">
<tbody>
<TR>
<TH width=15 ALIGN=RIGHT VALIGN=top>Line#</TH>
<TH width=100 VALIGN=top>Link</TH>
<TH width=100 VALIGN=top>State</TH>
<TH width=100 VALIGN=top>Category</TH>
<TH width=100 VALIGN=top>Email</TH>
<TH width=100 VALIGN=top>Area</TH>
<TH width=400 VALIGN=top>Desc</TH>
</TR>
<!--#exec cgi="/cgi-bin/links/list.cgi"-->
</TABLE>
Once again my table is for sorting. you can use just a plain table

Not sure if this is what you want but here is what I did. And it is very slow to bring up


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."

Last edited by:

esm: Jan 21, 2003, 9:30 PM
Quote Reply
Re: [esm] Post all links no matter what category on one page In reply to
Just tried the above mod and it works well, but I must say though, I have a directory of over 1100 links and it took over 90 seconds on a 56 K modem to display page, even with the code completely stripped down.

I would only do the above mod if your directory is below a 1000 records.

Stu2000

- Top 100 forums / GT Links 2.0 websites -
Quote Reply
Re: [stu2000] Post all links no matter what category on one page In reply to
well, I did say that it was slow. Remember, you are downloading the entire links.db file and not a generated or created HTML page.

Rather than look at the number of links, you should look at the size of the links.db file as that will be a much better indicator of the time required to download the file.

You could include some javascript to show a progress bar to the surfer so they know that something is happening during the download.

If you really need a listing of your links ( either all or just some of the fields ), you may not be too concerned about the download time.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Post all links no matter what category on one page In reply to
Smile Good advice

Stu2000

- Top 100 forums / GT Links 2.0 websites -
Quote Reply
Re: [esm] Post all links no matter what category on one page In reply to
Or you can save the results into an html file. Compact it. Upload and link to that. :) I will give this script a shot right now.
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
If I run the cgi file I get a 500 error. Looking into my log it shows..Premature end of script headers: for the cgi file. What am I missing here?
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
well, I thought of that too but figured the links.db was as compact as a file could be and certainly smaller than any html page that would be produced from it (unless I showed only a couple of the fields - I do show 7 of the 66 fields but the description field is one of them ). So I didn't check it.

But since you bring it up, here is what my file sizes are:

466,068 links.db
755,024 list.html
731,871 list.html compacted

I don't show all the fields in the list.html page. but that is offset by all the table tags.

If all I showed was the Title and URL ( without the A HREF tag stuff ), then maybe the list.html page would be smaller.

Well, you get the point on what I am saying.

I will say that since it has to build the page dynamically AND it uses some javascript to allow sorting by the column headings, it does take 3-4 minutes to "show" the page to the surfer.

Come tp think of it, the javascript is probably sorting the info which is why the links appear in order from the first record to the last record and not the opposite order ( Paul's script actually lists the links last record first ).

A static page ( of even 750kb ) would download much quicker. But I would loose the real time capability unless I created the page every time I re-built my links. I may do that and save some initial time at least.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Post all links no matter what category on one page In reply to
> A static page ( of even 750kb ) would download much quicker.
> But I would loose the real time capability unless I created the
> page every time I re-built my links.

Check out how quickly the links tree mod builds its tree page. It takes hardly any time at all. It already shows all the links, all we need to do is to have somebody hack it to show them all in alpha order without the categories.

If you do that, you can simply insert it into your nph-build.cgi script, and it will build the all links page every time you build, no extra work needed. Quick, easy and it would work well. Now would somebody PLEASE figure out the minor change needed to sort by title in alpha and skip the categories? I've tried, but I'm not up on arrays and sorts in CGI enough to work it out...
Quote Reply
Re: [Bob Harbison] Post all links no matter what category on one page In reply to
How quickly the file is built has little relation to how quickly it could be viewed in a browser - especially if via a modem connection. If the page contains tables, it's going to be slower to render and even with a cable or ADSL connection it's still going to take a while to download first.

As for someone else coming along and making these changes for you, well I'm not sure you understand why that may take some time.

You'd need someone with an understanding of Perl and the tree mod you're hoping to adapt. They can't modify a file they don't have access to, and obviously fewer people here have that addon than have the main Links 2 program.

They'd also need to visit here to read your posts and have the time (and inclination) to help you. Fairly obviously, that would be more likely on a weekend.
Quote Reply
Re: [Bob Harbison] Post all links no matter what category on one page In reply to
well, HTML pages are HTML pages. A 40k pape will load about as fast as any other 40K page. Change the 40k to 400k and one 400k page will load about as fast as any other 400K page. Assuming all you have is the one table with the required tr/td/td/tr tags. So, a 400kb static page built with the tree mod and an almost identical 400k static page built from Paul's mod with load in about the same time. html is html.

So the question is how to build the page. I do agree with you that it would be nice to have Links build that page as part of the build all process. But, "if all you have is a hammer, then the world looks like a nail to you Tongue." I don't know much about PERL so I can't change the tree mod. I'm sure that someone could. I do know enough to take Paul's code and modify it to produce the same thing.

So, I'll just have to take the extra 45 seconds and do it manually until someone modifies the tree mod to do the same thing. Unsure


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [Bob Harbison] Post all links no matter what category on one page In reply to
> I'm not sure you understand why that may take some time

Well yes, I do... I've done a lot of hacking with Links, and I'm familiar enough with Perl to know that what I'm asking isn't real easy (or else I could do it) but it's not overy difficult either (the sort and print routine is already there, all that needs done is to sort links rather than categories, I honestly think only a few lines need changed.)

The reason I'm pleading and begging is that I've been looking for a mod like this for literally a couple of years now. I have two uses, one is to use a link checking spyder on all of my links, which is quicker and easier if it's confined to one page, and to help me track my book "inventory".
Quote Reply
Re: [Bob Harbison] Post all links no matter what category on one page In reply to
Probably only a few lines do need to be changed, but as I said, the person who did so would need to know Perl and have a copy of the tree mod (or needlessly reproduce much of the code that's already there).

If the mod is freeware, you would likely get a better response if you pasted the modified code (only) here. That way people wouldn't have to find and download the file to be able to see how the mod currently works and make suggestions for changes.

I could probably work it out given time, but I'd need to download the mod and test the effects of any changes I made on a working version of the script before I could be sure it actually did what I expected it to do. My knowledge of Perl isn't yet at a level where I can instinctively know where to modify someone else's code just by looking at it (though I am quite practiced at spotting errors).

I do have the advantage of having Apache and Perl installed on my own machine for test purposes though. Unfortunately, it's on a separate O/S to the one I use to surf the 'net.

I understand your frustration. I've spent ages looking for a program with very specific features and it looks like I'm going to have to write it myself as no single product has everything I need.
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
In Reply To:
If I run the cgi file I get a 500 error. Looking into my log it shows..Premature end of script headers: for the cgi file. What am I missing here?
What about this post? :)

Last edited by:

solokron: Jan 23, 2003, 9:55 PM
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
In Reply To:
What about this post? :)
I lost track of which script you were talking about.

Is it code pasted here, or the tree mod?

I noticed that
Code:
#!/usr/bin/perleval {
should be
Code:
#!/usr/bin/perl
eval {
in a post above though, if that helps.
Quote Reply
Re: [wysardry] Post all links no matter what category on one page In reply to
If it helps, I have the template-based tree mod here.


Leonard
aka PerlFlunkie
Quote Reply
Re: [wysardry] Post all links no matter what category on one page In reply to
yep, that occurred during the editing process here at the forum. It occured again below when I first copied the text into the "code" section below. Buggy software Sly. Obviously, it should start out as

Code:
#!/usr/bin/perl

eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1");


and since we cannot edit our posts after the first 30 minutes, it will remain frozen in error for all eternityUnsure.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [PerlFlunkie] Post all links no matter what category on one page In reply to
In Reply To:
If it helps, I have the template-based tree mod here.




Sweet! Thanks!
Quote Reply
Re: [wysardry] Post all links no matter what category on one page In reply to
Yes I cleaned up that as well and location etc. That is when I became frustrated and looked at the server logs to find the 500. Can you attach a template to this thread? That would be great! Thanks!

In Reply To:
In Reply To:
What about this post? :)
I lost track of which script you were talking about.

Is it code pasted here, or the tree mod?

I noticed that
Code:
#!/usr/bin/perleval {
should be
Code:
#!/usr/bin/perl
eval {
in a post above though, if that helps.
Quote Reply
Re: [solokron] Post all links no matter what category on one page In reply to
I have attached Paul's topx.cgi mod with the changes I made. You will need to change the 999 to a higher number if you have more than 999 links. you will also need to change the names of db_ variables to match you own. Finally, you will need to strip out the css stuff ( class= ) and the onmouseover/onmouseout.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."

Last edited by:

esm: Jan 24, 2003, 6:13 AM
Quote Reply
Re: [esm] Post all links no matter what category on one page In reply to
In Reply To:
I have attached Paul's topx.cgi mod with the changes I made. You will need to change the 999 to a higher number if you have more than 999 links. you will also need to change the names of db_ variables to match you own. Finally, you will need to strip out the css stuff ( class= ) and the onmouseover/onmouseout.


Thanks esm!
Quote Reply
Re: [wysardry] Post all links no matter what category on one page In reply to
For reference, you can find the whole tree mod here. It consists of an entire nph-build.cgi script, but if you look at it you can easily cut and paste the three segments into your existing nph-build.cgi. It works fine, and does what they say it will. (It would be nice if it sorted the links as well as cats, but oh well...)

Here's the section of code I'm talking about, the main portion of this mod:

I've narrowed it down to one area that needs changed. I'm hoping that if the code that sorts and prints the categories is modified to sort and print the links instead, it will do what I want done. By setting the linkstree variable to 0, you can get to skip the portion that now prints the links (listed by category, and not sorted)

It will end up only showing the title, but that's all I want done. Once we figure out how to get it to print all of the links, it shouldn't be to hard to get it to use the links template as well.

Code:


# *********************************************** tree modification - begin ****************

sub build_tree_page {

# --------------------------------------------------------

# This routine builds a tree from all links/categories

my ($cat, $url, $dir, @related, $relation, $page_num, $next_page, $numlinks);

my ($linkstree, $output, @categorylist, $depth_old, $depth_new);

local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped);

local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $next, $prev);

# by setting this to 0, you will get a listing of only the categories

# set linkstree to 0 if you want only a tree off all categories

# set linkstree to 1 if you want a tree off all categories and links

$linkstree = 0;

$depth_old = 0;

$url = "$build_root_path/tree$build_extension";

open (CAT, ">$url") or &cgierr ("unable to open category page: $url. Reason: $!");

$output = qq~

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

<html>

<head>

<title>$build_site_title: Tree</title>

<link rel=stylesheet href="$build_css_url" type="text/css" title="webarchitects links style sheet">

</head>

<body>

<p><strong class="title"><A HREF="$build_root_url/">Top</A> : Tree</strong></p>

<h1>$build_site_title: Tree</h1>

<p><small class="menu">|

<a class="menulink" href="$build_root_url">Home</a> |

<a class="menulink" href="$build_add_url">Add a Resource</a> |

<a class="menulink" href="$build_modify_url">Modify a Resource</a> |

<a class="menulink" href="$build_new_url">What's New</a> |

<a class="menulink" href="$build_cool_url">What's Cool</a> |

<a class="menulink" href="$build_ratings_url">Top Rated</a> |

<a class="menulink" href="$build_email_url">Email Updates</a> |

<a class="menulink" href="$build_jump_url?ID=random">Random Link</a> |

<a class="menulink" href="$build_search_url">Search</a> |

</small></p>

~;

print CAT $output;

#

# *** This is the piece of code I'm trying to change. If I can get this to sort

# links instead of categories, it will do what I need it to do. It will only show

# the title and link to that resource, but that's all I want to have it do anyway...

#

# Go through each category and build the appropriate page.

CATEGORY: foreach $cat (sort keys %category) {

next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)



# We set up all the variables people can use in &site_html.pl.

($description, $related, $meta_name, $meta_keywords, $header, $footer) = @{$category{$cat}}[2..7];

$title_linked = &build_linked_title ($cat);

$title = &build_unlinked_title ($cat);

$total = ($#{$links{$cat}} + 1) / ($#db_cols + 1);

$category_name = $cat;

$category_name_escaped = &urlencode ($cat);

$category_clean = &build_clean ($cat);

$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);

@categorylist = split (/\//, $cat);

$depth_new = $#categorylist;

$links = "";

if ($depth_new < $depth_old) {

for ($i = 0; $i <= ($depth_old - ($depth_new + 1)); $i++) {

$links .= "\n</ul>";

}

}

$links .= qq~\n<p><strong class="link"><a href="$build_root_url/$cat/">$title</a></strong>~;

if ($linkstree == 1) {

for ($i = 0; $i < $numlinks; $i++) {

%tmp = &array_to_hash ($i, @{$links{$cat}});

$links .= &site_html_link (%tmp);

}

$links .= "\n";

}

if ($#{$subcategories{$cat}} >= 0) {

$links .= "\n<ul>";

}

print CAT $links;

$depth_old = $depth_new;

}

$output = qq~

<form action="$build_search_url" method="GET">

<h2>Search</h2>

<div class="margin">

<table border="0" cellspacing="0" cellpadding="0">

<tr><td><strong class="search">Looking for something in particular?</strong></td></tr>

<tr><td><input type="text" size=15 name="query"> <input type=submit value="Search!"></td></tr>

<tr><td><small class="more"><a href="$build_search_url">More search options</a></small></td></tr>

</table>

</div>

</form>

<p><small class="update">Pages Updated On: $date - $time<br>

Links Engine Powered By: <a href="http://www.gossamer-threads.com/">Gossamer Threads Inc.</a></small></p>

</body>

</html>

~;

print CAT $output;

close CAT;

}

# *********************************************** tree modification - end ******************
Quote Reply
Re: [Bob Harbison] Post all links no matter what category on one page In reply to
I actually downloaded the script out of curiosity yesterday and played with it for a while.

The problem is, that the tree mod does not actually read or sort the entries itself - it uses the info provided by the build_stats routine.

Editing the build_stats routine would change the way New, Cool and Popular links were displayed, and probably those on category pages too.

There doesn't seem to be an existing routine that reads in and sorts all the links without splitting them into categories first.

In other words, you need a whole new subroutine to do that.

It might be possible to reuse some of the existing code from different build and sort routines to create a hybrid, but you would have to be careful not to overwrite existing variables.

Unfortunately, that requires a better understanding of the variables and program flow than I have at present.

Hopefully, one of the veteran users will be able to help.

Have you considered trying to import the links.db file into a desktop database program and using that to sort the data on the Title field?