Gossamer Forum
Home : Products : Links 2.0 : Customization :

Help with top level category name extraction

Quote Reply
Help with top level category name extraction
I need to extract the top level category name DURING the build so I can add the .gif extension to it and use that image on the page currently being built.

For example, for category Virginia/A/Alexandria, I need to extract Virginia from the category and add .gif to it creating Virginia.gif and subsequently load that image (a flag of Virginia) and put it somewhere on that page.

Does someone have a subroutine that will "pluck" the first part of a string from the First Position to any given character, in this case '/'????

If so, I could simply grab the substring I need and add '.gif' to it dynamically.

I'm not a perl programmer, just OLD Pascal, so I don't know what the heck I'm doing..<grin>

Thanks for your help!

Quote Reply
Re: Help with top level category name extraction In reply to
There are already some routines in place to do something similar.
I use
Code:
$my_title_linked = &my_build_linked_last ("$category");
in order to call the sub below to just get the last category.
Code:
sub my_build_linked_last {
# --------------------------------------------------------
# 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 = &build_clean(pop @dirs);

$output = qq|In <A HREF="$build_root_url/$category/" title="$category">$last</A>:<br>|;
return $output;
}

It generates something like In Computers
Where Computers is the last subcategory of the main categories. Something like:
Home/Products/Computers

You could possibly do something similar just get the first instead of the last.

This is in nph-build.cgi

The build_clean sub is in db_utils.pl

Hope this helps.
Quote Reply
Re: [jeffo] Help with top level category name extraction In reply to
this looks to be a workable mod for the print subcategory that everyone was looking for back in '99 (im currently still looking for one) so im bumping this to see if someone can make the instructions a bit more inteligable.

Here is what i want,

on a detailed page or subcategory page take from category_clean [home/category/subcategory] and return just [subcategory]. I figured out how make the subroutine but i cant for the life of me figure out how to get it to run. here is what i have...

in nph-build.cgi i added
Code:
sub my_build_linked_last {
# --------------------------------------------------------
# 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);
$output = &build_clean(pop @dirs);


return $output;
}

then under sub build_detailed_view in nph-build.cgi i replaced
Code:
$title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}");

with
Code:

$title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}");
$my_title_linked = &my_build_linked_last ("$category");

then in site_html_templates.pl under sub site_html_detailed i added
Code:
subcategory => $my_title_linked,

but when i call <%subcategory%> on my detaled pages it shows nothing. As in under home/entertainment/bands instead of printing Wedding Band named when i put Wedding <%subcategory%> named <%Title%> on the page it just prints Wedding named [Title]

im so close to getting this one that i can almost taste it but i just cant spend any more time banging my head against it right now so any help would be appriciated




Vote Stinky
Quote Reply
Re: [security_man] Help with top level category name extraction In reply to
Add this to the end of nph-build.cgi:


Code:

# next added for last_cat mod >
sub build_last_cat {
# --------------------------------------------------------
# Returns the last cat from a string of the current category. Includes a change in sub build_category_pages.

my $input = shift;
my (@dirs, $dir, $output, $path, $last);
@dirs = split (/\//, $input);
$last = &build_clean(pop @dirs);
$output = qq|$last|;

return $output;
}



Then in sub build_category_pages, add this:

Code:
$category_clean = &build_clean ($cat);
# next line added for last_cat mod >
$last_cat = &build_last_cat ($cat);



You should also be able to use it with a detailed page by adding this to sub build_detailed_view:

Code:

%rec = &array_to_hash (0, @values);
# next line added for last_cat mod >
$last_cat = &build_last_cat ("$rec{'Category')";



I use it with the detailed.cgi (info.cgi) mod, and it works fine. (These create dynamic detail pages, instead of static.)

==

In site_html_templates.pl, put this in the globals section:

Code:

last_cat => $build_last_cat,



==

Then use this tag to call it on the page:

Code:

<%last_cat%>



====

This could be used to do what the first poster wanted to do by changing this line in the above sub (adjust the URL to point to your image directory):

Code:


$last = &build_clean(shift @dirs);
$output = qq|<img src="$build_root_url/images/$last.gif">|;





Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Dec 6, 2005, 10:58 AM
Quote Reply
Re: [PerlFlunkie] Help with top level category name extraction In reply to
thanks leonard, i still cant seem to get it to work so i did a work around with php that is clunky but it does what i need so no worries... for some reason the call just isnt getting parsed. Anywhere i put <%last_cat%> it is just blank. Tried to call it in the sub site_html_detailed instead of the global section but still no luck... even tried a couple of other things that i knew wouldnt work but was worth a shot in the dark. It would be great to have this mod working but i cant figure it out :(

btw there was an error in the code above if anyone still trys to get this to work maybe itll save a bit of a headache:

instead of:
You should also be able to use it with a detailed page by adding this to sub build_detailed_view:

Code:

%rec = &array_to_hash (0, @values);
# next line added for last_cat mod >
$last_cat = &build_last_cat ("$rec{'Category')";

it should say:
You should also be able to use it with a detailed page by adding this to sub build_detailed_view:

Code:

%rec = &array_to_hash (0, @values);
# next line added for last_cat mod >
$last_cat = &build_last_cat ("$rec{'Category'}");
cheers, and thanks again for all your help :)




Vote Stinky
Quote Reply
Re: [security_man] Help with top level category name extraction In reply to
Oops...

Also, this looks wrong, should be a &, not a $:
last_cat => &build_last_cat,


Leonard
aka PerlFlunkie