OK, here's a start...
. Many routines are edited to show only what needs changing, mssing code indicated with
.
Code:
db_utils.pl sub build_select_field {
*** # This section creates the XHTML.
$output = qq|<select name="$name"|;
$mult ?
($output .= qq| multiple="multiple" size="$altcatsize">\n|) :
($output .= qq|>\n|);
$output .= qq|<option value="---">---</option>\n|; foreach $field (@fields) { $values{$field} ?
($output .= qq|<option value="$field" selected="selected">$field</option>\n|) :
($output .= qq|<option value="$field">$field</option>\n|);
}
$output .= "</select>\n";
return $output;
}
---------------
This next one is a new routine, you need to add it.
sub build_select_field_clean {
# --------------------------------------------------------
# Builds an XHTML-valid select field for the add/modify forms.
# Only used for the Category and Altcategories fields. my ($column, $value, $name, $mult) = @_;
my ($size, %values);
$name || ($name = $column);
$size || ($size = 1);
$altcatsize || ($altcatsize = 5); # Subcat/Yahoo select mod >
$db_select_fields{'Mult-Subcats'} = join (",", &category_list);
# < Subcat/Yahoo select mod
if (! exists $db_select_fields{$column}) {
$db_select_fields{$db_cols[$db_category]} = $db_select_fields{'Mult-Related'} = join (",", &category_list);
} # alt cat mod >
if (! exists $db_select_fields{$column} && $column eq "AltCategories" && exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = $db_select_fields{'Category'}
}
elsif (! exists $db_select_fields{$column} && $column eq "AltCategories" && ! exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list);
}
# < alt cat mod if ($mult) {
@fields = split (/\,/, $db_select_fields{"Mult-$column"});
%values = map { $_ => 1 } split (/\Q$db_delim\E/, $value);
}
else {
@fields = split (/\,/, $db_select_fields{$column});
$values{$value}++;
}
($#fields >= 0) or return "error building select field: no select fields specified in config for field '$column'!"; # This section creates the XHTML.
$output = qq|<select name="$name"|;
$mult ?
($output .= qq| multiple="multiple" size="$altcatsize">\n|) :
($output .= qq|>\n|);
$output .= qq|<option value="---">---</option>\n|; foreach $field (@fields) {
# These two subs clean up the entries --
my $field_clean = &build_clean($field);
my $field_url = &urlencode($field);
$values{$field} ?
($output .= qq|<option value="$field_url" selected="selected">$field_clean</option>\n|) :
($output .= qq|<option value="$field_url">$field_clean</option>\n|);
}
$output .= "</select>\n";
return $output;
} ----------------
sub build_select_field_from_db {
*** # Make a select list out of those names.
$output = qq|<select name="$name"><option>---</option>|;
foreach $field (sort keys %selectfields) {
($field eq $value) ?
($output .= "<option value=\"$field\" selected=\"selected\">$field</option>\n") :
($output .= "<option value=\"$field\">$field</option>\n");
}
$output .= "</select>\n"; return $output;
}
--------------
sub build_checkbox_field {
*** foreach $box (@boxes) {
(grep $_ eq $box, @values) ?
($output .= qq!<input type="checkbox" name="$name" value="$box" checked="checked" /> $box\n!) :
($output .= qq!<input type="checkbox" name="$name" value="$box" /> $box\n!);
}
return $output;
}
------------------
sub build_radio_field {
*** foreach $button (@buttons) {
($value eq $button) ?
($output .= qq|<input type="radio" name="$name" value="$button" checked /> $button \n|) :
($output .= qq|<input type="radio" name="$name" value="$button" /> $button \n|);
}
return $output;
}
---------------
These next two are modified for my mod that allows special characters in the category name,
which is posted elsewhere. They may not need to be changed for your site.
The part in red will change the category divider in the drop-down lists from a
/ to a
».
sub build_clean {
# --------------------------------------------------------
# Formats a category name for displaying as XHTML compliant.
# In order to enable use of the pound sign (#) in the cat name,
# a two-step jig is required... my ($input) = shift;
$input =~ s/_/ /g; # Change '_' to spaces.
$input =~ s|#|\^|g; # Change '#' to '^' (step 1)
$input =~ s/&/&/g; # Change '&' to '&'
$input =~ s|\^|#|g; # Change '^' to '#' (step 2)
$input =~ s|/| » |g; # Change '/' to ' » ' (' » '). # Catgeory divider
$input =~ s/\\/\/g; # Change '\' to '\'
$input =~ s/\?/?/g; # Change '?' to '?'
$input =~ s/!/!/g; # Change '!' to '!' return $input;
}
The red part changes all letters in the URL to lowercase.
This mod will require other changes, too, also previously posted.
sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
my($toencode) = shift;
$toencode =~ s/&/and/g; #change '&' to 'and'
$toencode =~ tr/ /_/; #replace space with underscore
$toencode =~ tr/[A-Z]/[a-z]/; #change all letters to lowercase
$toencode =~ s/[!?#]//g; #remove these characters (!?#)
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode =~ s/\%2F/\//g;
return $toencode;
}
-----------
site_html_templates.pl sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;
my $category = shift;
($category = qq~$category <input type="hidden" name="Category" value="$category">~) :
($category = &build_select_field_clean ("Category", "$in{'Category'}"));
my $altcategories = &build_select_field_clean ("AltCategories","$in{'AltCategories'}","AltCategories","multiple Size=3");
print &load_template ('add.html', {
Category => $category,
AltCategories => $altcategories, %in,
%globals
});
}
----------------
sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.
my ($errormsg) = shift;
my $category = &build_select_field_clean ("Category", "$in{'Category'}");
delete $in{'Category'}; my $altcategories = &build_select_field_clean ("AltCategories","$in{'AltCategories'}","AltCategories","multiple Size=3");
delete $in{'AltCategories'}; &html_print_headers;
print &load_template ('add_error.html', {
error => $errormsg,
Category => $category,
AltCategories => $altcategories, %in,
%globals
});
}
--------------
In the modify template, change to this:
Category <%Cat%>
sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.
my (%record) = @_;
&html_print_headers;
my $cat = &build_select_field_clean ("Category", "$record{'Category'}"); my $altcategories = &build_select_field_clean ("AltCategories","$in{'AltCategories'}","AltCategories","MULTIPLE Size=3");
print &load_template ('modify.html', {
Cat => $cat,
Category => $category,
AltCategories => $altcategories, %in,
%record,
%globals
});
}
------------
This routine is highly modified, but the general idea is still the same...
sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i, $columns, $subcatsub);
my ($half) = int (($#subcat+2) / 2);
# Print Header.
$output = qq|<div class="float_container"><div class="float_left">\n|; # > category sort mod
sub byfield { $category{$a}[$cat_sort_field] <=> $category{$b}[$cat_sort_field] };
foreach $subcat (sort byfield @subcat) {
# foreach $subcat (sort @subcat) { # < original
# < category sort mod ($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~</div>\n~;
$output .= qq~<div class="float_right">\n~;
$i = 0;
} # Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<div class="link_top">\n|;
$output .= qq|<a class="cat2" href="$url">$category_name</a>
<span class="smalltype">($numlinks)</span>\n|;
$output .= qq|</div>|; # > Yahoo-style mod
if ($#{$subcategories{$subcat}} >= 0) {
$v = 0;
$output .= qq~<div class="link_bottom">~; # > category sort mod and added '$subcatsub'
foreach $subcatsub (sort byfield @{$subcategories{$subcat}}) {
#foreach $subcatsub (sort @{$subcategories{$subcat}}) {
# < category sort mod $suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) {$subcategory_name = &build_clean($1);
}
else {$subcategory_name = &build_clean($subcatsub);
} $output .= qq~<a class="cat2" href="$suburl">$subcategory_name</a>~ if ($v <= 5);
$output .= qq~, \n~ if ($v ne $#{$subcategories{$subcat}} && $v <= 5);
$output .= qq~<a class="cat2" href="$url"> more»</a>\n~ if ($v eq "5");
$v++;
}
$output .= qq~</div>~;
}
$i++;
}
## < Yahoo-style mod $output .= "</div></div>\n"; $output .= qq|</dl>|; return $output;
}
There changes in nph-build.cgi, but they are pretty minor. Much alteration is required in the templates, of course. Let me know how this works, and what else needs correcting.