Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

category dir names

Quote Reply
category dir names
hehe.. i noticed my category Tips & Tricks has the DIR named.. Tips___Tricks

how inefficient would it be if i were to go through the entire links script and change every single time it puts the URL of a category up and change it so that it something other than the category name to build the dir...

i'd rather have /tips/ instead of /Tips___Tricks/ and keep the name of the category appearing "Tips & Tricks" [sorta like what yahoo does]..

i don't think i should make the changes now.. until the next released version comes out..

jerry

[This message has been edited by widgetz (edited October 23, 1999).]
Quote Reply
Re: category dir names In reply to
no.. i just find it annoying if someone wanted to type in the dir name.. they would type in something weird.. yahoo.. for their Arts & Humanities directory.. they have the dir name as arts

links sql creates Tips___Tricks for Tips & Tricks (that is 3 underscores).. which I find sorta "weird looking".. so i made the mod to use the directory i want.. tips

it's not much.. but i find it better looking. .Megalinks 1.0 had this..

jerry
Quote Reply
Re: category dir names In reply to
nevermind.. i just made the mod.. not too hard.. i still have to do it everywhere i can find it.. but still Wink

http://www.pdamania.com/index.html

i just did the big things.. everytime i find something that uses it.. i'll make the changes.. it's really easy.. just a tiny sub that gets the directory..

jerry
Quote Reply
Re: category dir names In reply to
I'm not sure what the benefit of this is... sounds like a personal thing Smile Once you get the hang of Unix, the MS DOS/Windows world no longer makes any sense <G>

In a way, I find it easier to type the '_' because I know my categories, and I just replace the funny characters with '_' Since I do a lot of stuff at the command line (I just can't get away from that) I think I'd find it confusing to wonder what the program abbreviated it to ...

One _good_ mod might be to add a field to the category description "Dir_Name" where you could name the directory. That way you could enforce a directory naming convention across your site.

What I'm hoping is a better way to 'nest' the categories... A drop-down box that allows the current addition to be made a sub-category of the selected directory. Prevents typos.

Quote Reply
Re: category dir names In reply to
Hi, jerry,
I am interested in your mod. Would you please tell me how to do it?
Thank you.
Quote Reply
Re: category dir names In reply to
if you are interested in doing this.. just go into the admin.. add a new field to the category table.

Name: Directory
Type: CHAR
Size: 40
MAX : 255
Def : No

and leave the rest alone..

replace your sub build_clean_name in DB_Utils.pm with:

Code:
sub build_clean_name {
# --------------------------------------------------------
# Converts a category name into something usable by a directory/URL.
#
my $name = shift;
my $db = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Category.def";
my $rec = $db->get_record (&get_category_id($name), 'HASH');

if ($rec->{'Directory'}) { return $rec->{'Directory'}; }
elsif ($LINKS{foreign_char}) {
my @cat = split /\//, $name;
my ($id, $tmp, $output);
for (0 .. $#cat) {
$tmp = join "/", @cat;
$id = &get_category_id ($tmp);
if (!$id) { $tmp =~ s/[^\w\d\_\-\/]/_/g; $id = $tmp; }
$output = "$id/$output";
pop @cat;
}
$output =~ s,/$,,;
return $output;
}
$name =~ s/[^\w\d\_\-\/]/_/g;
return $name;
}

in build_linked_title..

replace

Code:
$clean_input = &build_clean_name ($input);

with:

Code:
($input =~ m,^(.*)/[^/]+$,) ?
($clean_input = &build_clean_name($1)) :
($clean_input = &build_clean_name($input));

this is to avoid problems with detailed pages..

now that's all..

jerry

[This message has been edited by widgetz (edited October 24, 1999).]

[This message has been edited by widgetz (edited October 24, 1999).]
Quote Reply
Re: category dir names In reply to
..

[This message has been edited by widgetz (edited October 24, 1999).]
Quote Reply
Re: category dir names In reply to
Hi, jerry,
Thank you. It's nice.
Links SQL 1.1b1 is different in sub site_html_print_cat.

sub site_html_print_cat {
my ($subcat, $dynamic) = @_;
my @names = keys %{$subcat};

my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames);
my $breakpoint = int (($#names+1) / $LINKS{build_category_columns}) + ( (($#names+1) % $LINKS{build_category_columns}) ? 1 : 0);

# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;
$i = 0;
foreach $cat (sort @names) {
$cat_r = $subcat->{$cat};

# Get the URL and the Category name.
$category_url = $LINKS{build_root_url} . "/" . &build_clean_name ($cat_r->{Name}) . "/";
($cat_r->{Name} =~ m,.*/([^/]+)$,) ? ($category_name = $1) : ($category_name = $cat_r->{Name});
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

# 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).
($i and ($i % $breakpoint)) or ($output .= qq|</td><td class="catlist" valign="top">\n|);
$i++;
$output .= &load_template ('subcategory.html', $cat_r);
}
# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
defined $dynamic and &clean_output($dynamic, \$output);
return $output;
}

So the following code doesn't work:
$category_url = $LINKS{build_root_url} . "/" . &get_category_dir($id) . "/";

Do you know how to modify it?
Quote Reply
Re: category dir names In reply to
Code:
$category_url = $LINKS{build_root_url} . "/" . &build_clean_name ($cat_r->{Name}) . "/";

to

Code:
$category_url = $LINKS{build_root_url} . "/" . &get_category_dir($cat_r->{ID}) . "/";
Quote Reply
Re: category dir names In reply to
i noticed what i forgot to tell you..

if you want to change the dirname.. put something in Directory.. otherwise it uses default..

but the directory name is just like the category name.. you have to type in the categories that are before it..

Just say you have a category like:

Cat/Bat/That/Matt/Subcat

and you want it to appear like

http://www.url.to/cat/bat/that/matt/subcat/

then you type in

cat/bat/that/matt/subcat

ok.. but you can also make it shorter.. and put it in your root.. like this

http://www.url.to/subcat/

just put:

subcat

in the directory name.. all the links will still work right.. that's what i like about it Wink

jerry
Quote Reply
Re: category dir names In reply to
Hi, jerry,

I have a subcategory: Cat/Bat(which is under category Cat), I want it to appear as: http://www.url.to/cat/bat.
If I typed in: cat/bat,
it appeared as: http://www.url.to/cat/cat/bat.
If I typed in: bat,
it appeared as:
http://www.url.to/bat.

Do you know how to modify this?
Quote Reply
Re: category dir names In reply to
are you sure??

that doesn't make any sense..

it builds exactly what you type in.. never changes anything..

make sure this is what is happening.. is it happening to every link?

jerry
Quote Reply
Re: category dir names In reply to
alex.. do you recommend any changes?

i didn't know what to do with the build_clean_name thing.. it will do a query even if there is no directory.. i didn't want to use your suggestion of $LINKS{'use_separate_dir'}..

cause if they wanted to use a seperate dir.. then they would fill it in.. right? Smile

jerry
Quote Reply
Re: category dir names In reply to
Hi,

Good idea! Can I make a suggestion? Simply modify build_clean_name to do as you want. You might want to add in:

if ($LINKS{'use_separate_dir'}) {
# .. Your code here
}
else {
# rest of code
}

and make it an option. &build_clean_name will be used whenever we have a category name, and need to convert that to a directory/URL.

This will save you from having to modify any other files, and it will work in future versions.

Cheers,

Alex
Quote Reply
Re: category dir names In reply to
the reason why i didn't do that.. is cause i thought build_clean_name might have been used for other things instead of directories..

but coming from you.. i guess not Wink

i'll change it..

jerry

[This message has been edited by widgetz (edited October 24, 1999).]
Quote Reply
Re: category dir names In reply to
..

[This message has been edited by widgetz (edited October 24, 1999).]
Quote Reply
Re: category dir names In reply to
I'm not sure I understand what you mean? For instance, one change I've added to build_clean_name is:

Code:
if ($LINKS{foreign_char}) {
my @cat = split /\//, $name;
my ($output, $id, $tmp, $level);
$level = $#cat;
for (0 .. $level) {
$tmp = join "/", @cat;
$id = &get_category_id ($tmp);
if (!$id) { $tmp =~ s/[^\w\d\_\-\/]/_/g; $id = $tmp; }
$output = "$id/$output";
pop @cat;
}
$output =~ s,/$,,;
return $output;
}

What this will do, is if you set $LINKS{foreign_char} = 1, then Links SQL will now generate directories/URL's based on your category ID rather then you category name. This is useful for foreign languages where all characters would be considered "strange" by Links SQL and converted to underscores.

A similiar option could be $LINKS{build_directory_field}. You set this to the field you want to use for the directory name or leave blank to use the category name as normal. Now your build_clean_name looks like:

Code:
sub build_clean_name {
# --------------------------------------------------------
# Converts a category name into something usable by a directory/URL.
#
my $name = shift;
if ($LINKS{foreign_char}) {
my @cat = split /\//, $name;
my ($output, $id, $tmp, $level);
$level = $#cat;
for (0 .. $level) {
$tmp = join "/", @cat;
$id = &get_category_id ($tmp);
if (!$id) { $tmp =~ s/[^\w\d\_\-\/]/_/g; $id = $tmp; }
$output = "$id/$output";
pop @cat;
}
$output =~ s,/$,,;
return $output;
}
elsif ($LINKS{build_directory_field}) {
my $id = &get_category_id ($name);
if (! $CATDB) {
$CATDB = new Links: BSQL $LINKS{admin_root_path} . "/defs/Category.def";
}
my $rec = $CATDB->get_record ($id, 'HASH');
return $rec->{$LINKS{build_directory_field}};
}
else {
$name =~ s/\s/_/g;
$name =~ s/[^\w\d\_\-\/]/_/g;
return $name;
}
}

(untested, but it looks ok). Actually I think I might add this in to the next version. =) You shouldn't have to change anything other than that. If there are problems with Detailed pages, or other areas, I'll look into fixing those up.

Cheers,

Alex





[This message has been edited by Alex (edited October 24, 1999).]
Quote Reply
Re: category dir names In reply to
this thing is your way of doing it would require all the categories to have a directory name..

also.. the problem with detailed pages is..

if you sent it into build_clean_name as

Software/Scripts/Links SQL

then it wouldn't be able to find it in the category database.. so you have to cut the last one off (which i did..) understand?

the thing i don't like about my code is that you have to do a query for each category that comes in even if it doesn't have a value in Directory.. but i don't think there is any other way to do it..

and then if there is a value.. it uses that as the directory otherwise it goes through the regular routine..

jerry
Quote Reply
Re: category dir names In reply to
Just change mine to:

if ($rec->{$LINKS{build_directory_field}}) { return $rec->{$LINKS{build_directory_field}}; }
else { $name =~ s/\s/_/g; $name =~ s/[^\w\d\_\-\/]/_/g; return $name; }

to only use it if a field has been entered, otherwise revert to the other way.

If you change build_linked_title to:

Code:
sub build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.

my $input = shift;
my (@dirs, $dir, $output, $path, $last);

@dirs = split (/\//, $input);
$last = pop @dirs;

$output = qq| <A HREF="$LINKS{build_root_url}/">Top</A> :|;
for (0 .. $#dirs) {
$path .= "/" . &build_clean_name( join "/", @dirs[0 .. $_] );
$output .= qq| <A HREF="$LINKS{build_root_url}$path/">$dirs[$_]</A> :|;
}
$output .= " $last";
return $output;
}

It will now work with Detailed pages. I've tested this a little on my demo and it's working well.

Cheers,

Alex
Quote Reply
Re: category dir names In reply to
Code:
if ($rec->{$LINKS{build_directory_field}}) { return $rec->{$LINKS{build_directory_field}};
}
else { $name =~ s/\s/_/g; $name =~ s/[^\w\d\_\-\/]/_/g; return $name; }

would require them to have a value for every category in the $LINKS{build_directory_field} field..

what i was getting at was that it is optional.. and if the value exists it uses it.. otherwise it uses the name of the category as default..

jerry
Quote Reply
Re: category dir names In reply to
No, what that part meant was if the category record we looked up had a value in our new directory field, use it. Otherwise do the replacing of special chars as normal.

Cheers,

Alex
Quote Reply
Re: category dir names In reply to
oops! Smile

i didn't see the $rec->{..} so i pretty much got the wrong idea again Wink

ok.. anyways.. i am working on something else right now.. (it's almost done.. just trying to build on another idea i have)

jerry
Quote Reply
Re: category dir names In reply to
if you came to this mod from pugdog's links sql faq.. please note that Links SQL 1.1 has this feature INCLUDED..

just define:

Code:
$LINKS{build_directory_field}

in Links.pm and then add the field to the Category table..

PUGDOG.. i told you take the link off once already.. but you seem to have added it once again! Smile

jerry
Quote Reply
Re: category dir names In reply to
That's why the thread is being pointed to,
since it answers HOW, even if it's down a
few posts.

TO make you happy I excerpted the 1.1 code
in the short description.

------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/