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
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";
}
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."