Gossamer Forum
Home : Products : Links 2.0 : Customization :

Spanning Whats New Page (Again)

Quote Reply
Spanning Whats New Page (Again)
Hi all, I have read ever post there is concerning spanning the whats new page. I have also tried to install the 'Dynamic New Mod' for http://www.simball.de/links_mods/ but it did not write to the mew.txt file.

I know its been sometime since this topic has been discussed and there are now a lot of new faces and programmers around.

There has been several attempts from some of the best Links 2.0 modifiers around but no one has of yet come up with the direct coding.

Basically, what I have is over 300 new links on one page (not using the date breakdown). I would like to span this 300 links into pages of 50 etc. Sounds easy enough but have tried and failed big style.

Is there anyone out there who has done this and willinging to share the codes. I know Glennu managed it but it was for a paid customisation. I have snet him several emails but I think he has left the Links 2.0 world.

Any help is appreciated on this topic
Quote Reply
Re: [stu2000] Spanning Whats New Page (Again) In reply to
anyone help ???
Quote Reply
Re: [stu2000] Spanning Whats New Page (Again) In reply to
I have a what's new than spans. I think it has an small error if less than 10 new links ( I should be so lucky ). I will send it in a few hours.

I have a different new.html that prints so who knows if it will work for you.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Spanning Whats New Page (Again) In reply to
Gene, this would be much appreciated. I had over 30 links a day to the site, so having less than 10 shouldn't be a problem at all.
Quote Reply
Re: [esm] Spanning Whats New Page (Again) In reply to
Hi Gene

Can you help me too ... thanx



Jantje
Quote Reply
Re: [jantje] Spanning Whats New Page (Again) In reply to
glennu did this for me.

note that if the number of links are less than 10, it prints "Found $numlinks and displaying links 1 to $numlinks:" over and over again for the number of links, i.e., $numlinks times

I also did a little cleanup - hopefully, I didn't screw it!!!

and while I am not a Perl programmer, it seemed like there were some extra }s and one in the wrong place. Maybe some of the programmers could help.

Code:
sub build_new_page {
# --------------------------------------------------------
# Creates a "What's New" page. Set $build_span_pages to 1 in links.cfg
# and it will create a seperate page for each date.
# Creates spanned "What's NEW" pages. local ($total, $id2, $link_results, $title_linked, $title, $next, $prev);
my (%link_output, $category_clean, $url, $page_num, $prev_page, $next_page, $numlinks);



if ($build_new_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}



$total = 0;
$numlinks = 0;
CATEGORY: foreach $id2 (sort keys %new_links) {
LINK: for ($i = 0; $i < ($#{$new_links{$id2}}+1) / ($#db_cols + 1); $i++) {$total++;}
}
$numlinks = $total;
$title_linked = &build_linked_title ("New");
open (NEW, ">$build_new_path/$build_index") or cgierr ("unable to open new page: $build_new_path/$build_index. Reason: $!");
print "\tNew Links: $total\n";
close NEW;
$url = $build_new_url;
$next = $prev = $link_results = "";
$linktotal = $numlinks;
if (($numlinks > $build_links_per_page) && $build_span_pages) {
$total_pages=(int($numlinks/$build_links_per_page));
if ($total_pages < $numlinks/$build_links_per_page) {$total_pages++}
$next .= qq~ <b>Found $linktotal and displaying links 1 to $build_links_per_page:</b>~;
$next .= "<b>1</b>";
# new added
for $j(2..($total_pages)){
$next .= qq~ <a class=mLink href="more$j$build_extension">$j</a>~;
}
# end of for #added
$page_num = 2;
$next .= qq~ <a class=mLink href="more$page_num$build_extension">[>>]</a>~;
$p = 1;
$t = 0;
$i = 0;
$r = 0;
foreach $id2 (sort {$b <=> $a} keys %new_links) {
$category_clean = &build_clean ($category);
if ($i < $build_links_per_page) {
LINK: for ($q = 0; $q < ($#{$new_links{$id2}}+1) / ($#db_cols + 1); $q++) {
if ($i < $build_links_per_page) {
%tmp = &array_to_hash ($q, @{$new_links{$id2}});
$link_output{$id2} .= &site_html_link (%tmp) . "\n";
$i++;
}
else {
$r--;
$t = $q;
last;
}
}
$link_results .= $link_output{$id2};
$r++;
}
}
$p++;
$numlinks = $numlinks - $i;
}



# seems like the } just above or the one 3 lines up is unnecessary

# Otherwise we either only have less then x number of links, or we are not
# splitting pages, so let's just build them all.
else {
foreach $id2 (sort {$b <=> $a} keys %new_links) {
$category_clean = &build_clean ($category);
$next .= qq~ <b>Found $numlinks and displaying links 1 to $numlinks: </b>~;
LINK: for ($q = 0; $q < ($#{$new_links{$id2}}+1) / ($#db_cols + 1); $q++) {
%tmp = &array_to_hash ($q, @{$new_links{$id2}});
$link_output{$id2} .= &site_html_link (%tmp) . "\n";
}
$link_results .= $link_output{$id2};
}
}



#once again it seems like one of the above 2 }s are unnecessary

# Create the main page.
open (NEW, ">$build_new_path/$build_index") or &cgierr ("unable to open new page: $build_new_path/$build_index. Reason: $!");
print NEW &site_html_new(@new_links);
close NEW;
# Then we go through the list of links and build on the remaining pages.
while ($next && $build_span_pages) {
if ($numlinks > $build_links_per_page) {
$nlink=$endlink=$prev=$next=$next_page=$prev_page="";
$next_page = $page_num+1;
$prev_page = $page_num-1;
$endlink = ($prev_page*$build_links_per_page)+1;
$nlink = ($endlink + $build_links_per_page) - 1;
$prev .= qq~ <b>Found $linktotal and displaying links $endlink to $nlink: </b>~;
if ($page_num == 2){
$prev .= qq~ <a class=mLink href="$url">[<<]</a> ~;
$prev .= qq~ <a class=mLink href="$url"> 1</a> ~;
}
else {$prev .= qq~ <a class=mLink href="more$prev_page$build_extension">[<<]</a> ~;
$prev .= qq~ <a class=mLink href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a class="mLink" href="more$k$build_extension">$k</a>~;}
}
$next .= qq~ $page_num</b> ~;
for $m($next_page..$total_pages){$next .= qq~ <a class=mLink href="more$m$build_extension">$m</a>~;}
$next .= qq~ <a class=mLink href="more$next_page$build_extension">[>>]</a>~;
}
# end of if
else {
if ($page_num == $total_pages) {
$endlink = $prev = $next = $next_page = $prev_page= "";
$prev_page=$total_pages-1;
$endlink = ($prev_page*$build_links_per_page)+1;
$prev .= qq~ <b>Found $linktotal and displaying links $endlink to $linktotal: </b>~;
if ($page_num == 2){
$prev .= qq~ <a class=mLink href="$url">[<<]</a> ~;
$prev .= qq~ <a class=mLink href="$url"> 1</a> ~;
}
else {$prev .= qq~ <a class=mLink href="more$prev_page$build_extension">[<<]</a> ~;
$prev .= qq~ <a class=mLink href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a class=mLink href="more$k$build_extension">$k</a>~;}
} # end of else
$prev .= qq~ <b>$page_num</font></b> ~;
}
# end of if
}
# end of else



$link_results = "";
$i = 0;
$s = 1;
foreach $id2 (sort {$b <=> $a} keys %new_links) {
if (($s > $r) && ($i < $build_links_per_page)) {
$category_clean = &build_clean ($category);
$link_output{$id2} = "";
LINK: for ($q = $t; $q < ($#{$new_links{$id2}}+1) / ($#db_cols + 1); $q++) {
if ($i < $build_links_per_page) {
%tmp = &array_to_hash ($q, @{$new_links{$id2}});
$link_output{$id2} .= &site_html_link (%tmp) . "\n";
$i++;
$t = 0;
}
else {
$r--;
$t = $q;
last;
}
}



# seems like this last } goes before the else

$link_results .= $link_output{$id2};
$r++;
}
$s++;
}
# end of while



$title_linked = &build_linked_title ("$cat/Page_$page_num/");
$title = &build_unlinked_title ("$cat/Page_$page_num/");
$use_html ?
print qq|\tSubpage : <A class=mLink HREF="|, $url, qq|more$page_num$build_extension" TARGET="_blank">$build_new_path/more$page_num$build_extension</A>\n| :
print qq|\tSubpage : $build_new_path/more$page_num$build_extension\n|;



open (NEW, ">$build_new_path/more$page_num$build_extension") or &cgierr ("unable to open new page: $build_new_path/index$page_num$build_extension. Reason: $!");
print NEW &site_html_new(@new_links);
close NEW;
$p++;
$numlinks = $numlinks - $i;
if ($page_num == $total_pages) { last; }
else { $page_num++; }}
print "\n";
}


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Spanning Whats New Page (Again) In reply to
Hi Gene



Thanx, I didn't tried it yet. But I soon will. I let you know!



Jantje