Gossamer Forum
Home : Products : Links 2.0 : Customization :

Strip whitespace in category fields?

Quote Reply
Strip whitespace in category fields?
How do you strip whitespace in category fields? I tried this in site_html_templates.pl in sub site_html_print_cat and sub site_html_category with no luck:

Code:
##strip whitespace

$stubhub =~ s/^\s*|\s*$//g;
$stubhub being one of my category fields. Tongue
Quote Reply
Re: [dawgtoons] Strip whitespace in category fields? In reply to
Hi,

^\s+ should do the job

$stubhub =~ s/^\s+//g;

I didn't look at the code in site_html_template.pl - but that should work fine :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Strip whitespace in category fields? In reply to
Still no luck - here's what I have tried:

Code:
sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#

my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="100%" border="0" cellspacing="2" cellpadding="2"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];
($id) = @{$category{$subcat}}[8];
($id) = @{$category{$subcat}}[9];

#strip whitespace

$stubhub =~ s/^\s+//g;

# 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|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

and this:

Code:
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.

return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
linkcolor => $linkcolor,
ebay => $ebay,
weather => $weather,
fansedgeurl => $fansedgeurl,
fansedgeimg => $fansedgeimg,
stubhub => $stubhub,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
$stubhub =~ s/^\s+//g;

}
Quote Reply
Re: [dawgtoons] Strip whitespace in category fields? In reply to
Hi,

You're doing the replace *after* its been passed to the template Tongue

Try thisa:

Code:
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.

$stubhub =~ s/^\s+//g;

return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
linkcolor => $linkcolor,
ebay => $ebay,
weather => $weather,
fansedgeurl => $fansedgeurl,
fansedgeimg => $fansedgeimg,
stubhub => $stubhub,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Strip whitespace in category fields? In reply to
Still no luck - maybe I am not going about this in the right way. I have a category field that I'm entering HTML in by C&Ping. When I don't strip all the white space out manually, I get accent marks (ex: ` ) that show up. They don't show up in the admin panel after I successfully add it - just when I build the templates.

If I can get the script to strip out the white space for me, it will save a lot of work in the long run.
Quote Reply
Re: [dawgtoons] Strip whitespace in category fields? In reply to
Hi,

I think ` is actually for newlines (\n).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Strip whitespace in category fields? In reply to
I think this would do:

$stubhub =~ s/ //g;


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Strip whitespace in category fields? In reply to
PerlFlunkie wrote:
I think this would do:

$stubhub =~ s/ //g;


That stripped out the images... I also tried this but got the original results (still had the accent marks):

$stubhub =~ s/[\n\r\|]/ /g;
$stubhub =~ s/\t//g;
$stubhub =~ s/\n//g;
$stubhub =~ s/\n/ /g;

Here's an example of where I'm putting this. Look in the block "Army Black Knights Tickets":

http://www.collegeteamlinks.com/Independents/Army/

Last edited by:

dawgtoons: Feb 12, 2008, 10:31 AM
Quote Reply
Re: [dawgtoons] Strip whitespace in category fields? In reply to
Okay, how about...

$stubhub =~ s/`//g;

Part of the problem may be how/where you copy the code from. Word likes to put hidden stuff in there like line breaks, which would not happen using WordPad or any text editor.

Also, you use a <p> tag to separate the images, but no </p>. Aim for correct code... Wink



<a href="http://www.kqzyfj.com/...ts-football-tickets/" target="_blank" onmouseover="window.status='http://www.stubhub.com';return true;" onmouseout="window.status=' ';return true;">``<img src="http://www.ftjcfx.com/...s-football-136px.gif" alt="Great Army Black Knights Tickets at StubHub.com! " border="0"/><br>Football Tickets</a>``


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Strip whitespace in category fields? In reply to
Yes! That did it. SmileSmile I'm using EditPad Lite to C&P, so I figured that would strip it out. Thanks for your help - that saves a lot of work for me. Smile

When I code by hand, I usually don't put the </p> in there... I used Dreamweaver as a shortcut sometimes though and it puts it in there. Tongue

Last edited by:

dawgtoons: Feb 12, 2008, 12:35 PM