I 've been fiddling around with the code, trying to make the detail pages do different things, and it hit me [like a brick] that there is an easy way to be able to use ANYTHING for the category name, and still get Links to build right, and actually to make the URLs simpler.
For a sample, look here: http://theonetruechurch.com/links3
These are the cat names used by the linked-title, as entered in the admin; no new fields required:
Gossamer Threads Links: Test Three! : 3 & down : Sub & level four?
And this is the URL for that page:
http://theonetruechurch.com/.../sub_and_level_four/
The spaces are replaced with underscores (_), all letters are converted to lowercase, the '&' is replaced with the word 'and', and other characters (!?) are removed!
I just did this, and it works so far. I still need to check how it affects things like search, etc. But I will post the code changes so others can experiment, too.
It's easy! The changes are in red, some stuff added, some removed (#commented out).
In nph-build.cgi:
sub build_dir {
# --------------------------------------------------------
# Verifies that all neccessary directories have been created
# before we create the category file. Takes as input, the category
# to verify, and returns the full directory path.
my $input = shift;
my ($dir, $path) = '';
my @dirs = split /\//, $input;
foreach $dir (@dirs) {
$path .= "/$dir";
$path =~ tr/ /_/;
$path =~ tr/[A-Z]/[a-z]/;
$path =~ tr/\?\*\.!//d;
$path =~ s/\&/and/g;
&build_check_dir ($build_root_path, $path);
if (! (-e "$build_root_path$path")) {
print "\tMaking Directory ($build_dir_per): '$build_root_path$path' ...";
if (mkdir ("$build_root_path$path", "$build_dir_per")) {;
print "Made. CHMOD ($build_dir_per) ...";
if (chmod ($build_dir_per, "$build_root_path$path")) {;
print "Done.";
}
else { print "CHMOD ($build_dir_per) failed! Reason: $!."; }
}
else { print "mkdir failed! Reason: $!."; }
print "\n";
}
}
return "$build_root_path$path";
}
sub build_check_dir {
# --------------------------------------------------------
# Checks the directory before we create it to make sure there
# are no funncy characters in it.
my ($root, $dir) = @_;
# my $chrs = quotemeta ("/_-");
if (! -e $root) {
&cgierr ("Root directory: $root does not exist!");
}
# if ($dir !~ m,^[\w\d$chrs]+$,) {
# &cgierr ("Invalid characters in category name: $dir. Must contain only letters, numbers, _, / and -.");
# }
return $input;
}
In db_utils.pl:
sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
# $toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode =~ s/\%2F/\//g;
$toencode =~ tr/ /_/;
$toencode =~ tr/[A-Z]/[a-z]/;
$toencode =~ tr/\?\*\.!//d;
$toencode =~ s/\&/and/g;
return $toencode;
}
In category.def:
# Database Definition: CATEGORIES
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
# Name => [1, 'alpha', 40, 75, 1, '', '^[\w\d/_-]+$'],
Name => [1, 'alpha', 40, 75, 1, '', ''],
Description => [2, 'alpha', '40x3', 500, 0, '', ''],
Related => [3, 'alpha', 0, 255, 0, '', ''],
'Meta Description' => [4, 'alpha', 40, 75, 0, '', ''],
'Meta Keywords' => [5, 'alpha', 40, 75, 0, '', ''],
Header => [6, 'alpha', 40, 75, 0, '', ''],
Footer => [7, 'alpha', 40, 75, 0, '', '']
);
I might get the hang of this stuff yet!
=====
OK, first update already...
This mod makes the New, Cool , and Rate pages build with lowercase letters, so a few more changes are in order. All templates need to be changed so that they have lowercase letters. Here is the original code:
<a class="menulink" href="<%build_root_url%>/New">What's New</a> |
<a class="menulink" href="<%build_root_url%>/Cool">What's Cool</a> |
<a class="menulink" href="<%build_root_url%>/Ratings">Top Rated</a> |
and the updated code:
<a class="menulink" href="<%build_root_url%>/new">What's New</a> |
<a class="menulink" href="<%build_root_url%>/cool">What's Cool</a> |
<a class="menulink" href="<%build_root_url%>/ratings">Top Rated</a> |
Then, in links.cfg, change the uppercase N, C, and R to lowercase (the red is just for comparison):
# PATH and URL of What's New page. No Trailing slash.
# $build_new_path = "$build_root_path/New";
$build_new_path = "$build_root_path/new";
$build_new_url = "$build_root_url/new";
# PATH and URL of What's Cool page. No Trailing slash.
$build_cool_path = "$build_root_path/cool";
$build_cool_url = "$build_root_url/cool";
# PATH and URL of What's Rating page. No Trailing slash.
$build_ratings_path = "$build_root_path/ratings";
$build_ratings_url = "$build_root_url/ratings";
The search works fine, the dropdown on the add form looks fine...
I am very happy with this discovery!!!
Note that if this mod is applied to an existing site, all your old links (bookmarks, search engine links, etc) will become invalid.
Leonard
aka PerlFlunkie
For a sample, look here: http://theonetruechurch.com/links3
These are the cat names used by the linked-title, as entered in the admin; no new fields required:
Gossamer Threads Links: Test Three! : 3 & down : Sub & level four?
And this is the URL for that page:
http://theonetruechurch.com/.../sub_and_level_four/
The spaces are replaced with underscores (_), all letters are converted to lowercase, the '&' is replaced with the word 'and', and other characters (!?) are removed!
I just did this, and it works so far. I still need to check how it affects things like search, etc. But I will post the code changes so others can experiment, too.
It's easy! The changes are in red, some stuff added, some removed (#commented out).
In nph-build.cgi:
sub build_dir {
# --------------------------------------------------------
# Verifies that all neccessary directories have been created
# before we create the category file. Takes as input, the category
# to verify, and returns the full directory path.
my $input = shift;
my ($dir, $path) = '';
my @dirs = split /\//, $input;
foreach $dir (@dirs) {
$path .= "/$dir";
$path =~ tr/ /_/;
$path =~ tr/[A-Z]/[a-z]/;
$path =~ tr/\?\*\.!//d;
$path =~ s/\&/and/g;
&build_check_dir ($build_root_path, $path);
if (! (-e "$build_root_path$path")) {
print "\tMaking Directory ($build_dir_per): '$build_root_path$path' ...";
if (mkdir ("$build_root_path$path", "$build_dir_per")) {;
print "Made. CHMOD ($build_dir_per) ...";
if (chmod ($build_dir_per, "$build_root_path$path")) {;
print "Done.";
}
else { print "CHMOD ($build_dir_per) failed! Reason: $!."; }
}
else { print "mkdir failed! Reason: $!."; }
print "\n";
}
}
return "$build_root_path$path";
}
sub build_check_dir {
# --------------------------------------------------------
# Checks the directory before we create it to make sure there
# are no funncy characters in it.
my ($root, $dir) = @_;
# my $chrs = quotemeta ("/_-");
if (! -e $root) {
&cgierr ("Root directory: $root does not exist!");
}
# if ($dir !~ m,^[\w\d$chrs]+$,) {
# &cgierr ("Invalid characters in category name: $dir. Must contain only letters, numbers, _, / and -.");
# }
return $input;
}
In db_utils.pl:
sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
# $toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode =~ s/\%2F/\//g;
$toencode =~ tr/ /_/;
$toencode =~ tr/[A-Z]/[a-z]/;
$toencode =~ tr/\?\*\.!//d;
$toencode =~ s/\&/and/g;
return $toencode;
}
In category.def:
# Database Definition: CATEGORIES
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
# Name => [1, 'alpha', 40, 75, 1, '', '^[\w\d/_-]+$'],
Name => [1, 'alpha', 40, 75, 1, '', ''],
Description => [2, 'alpha', '40x3', 500, 0, '', ''],
Related => [3, 'alpha', 0, 255, 0, '', ''],
'Meta Description' => [4, 'alpha', 40, 75, 0, '', ''],
'Meta Keywords' => [5, 'alpha', 40, 75, 0, '', ''],
Header => [6, 'alpha', 40, 75, 0, '', ''],
Footer => [7, 'alpha', 40, 75, 0, '', '']
);
I might get the hang of this stuff yet!
=====
OK, first update already...
This mod makes the New, Cool , and Rate pages build with lowercase letters, so a few more changes are in order. All templates need to be changed so that they have lowercase letters. Here is the original code:
<a class="menulink" href="<%build_root_url%>/New">What's New</a> |
<a class="menulink" href="<%build_root_url%>/Cool">What's Cool</a> |
<a class="menulink" href="<%build_root_url%>/Ratings">Top Rated</a> |
and the updated code:
<a class="menulink" href="<%build_root_url%>/new">What's New</a> |
<a class="menulink" href="<%build_root_url%>/cool">What's Cool</a> |
<a class="menulink" href="<%build_root_url%>/ratings">Top Rated</a> |
Then, in links.cfg, change the uppercase N, C, and R to lowercase (the red is just for comparison):
# PATH and URL of What's New page. No Trailing slash.
# $build_new_path = "$build_root_path/New";
$build_new_path = "$build_root_path/new";
$build_new_url = "$build_root_url/new";
# PATH and URL of What's Cool page. No Trailing slash.
$build_cool_path = "$build_root_path/cool";
$build_cool_url = "$build_root_url/cool";
# PATH and URL of What's Rating page. No Trailing slash.
$build_ratings_path = "$build_root_path/ratings";
$build_ratings_url = "$build_root_url/ratings";
The search works fine, the dropdown on the add form looks fine...
I am very happy with this discovery!!!
Note that if this mod is applied to an existing site, all your old links (bookmarks, search engine links, etc) will become invalid.
Leonard
aka PerlFlunkie