Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Shortened Versions Global

Quote Reply
Shortened Versions Global
Hi,

Is there some code to add to this Shortened Versions Columns global (found in the resource section) that will remove any occurrences of the following:

" ' < >


sub {
my $tags = shift;
my $desc = $tags->{Description} or return "Non on this template";
length $desc <100 and return $desc;
my $short = substr ($desc, 0, 100);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}


This way you could add the outputted text into a meta tag without html tags breaking the meta tag.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
Add something like:

Code:
$short =~ s/["'<>]+//g;
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Paul Thanks!

Do I add this in or replace this line:

$short =~ s/\s\S+?$//;

BTW: what is that line doing?

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
I was just looking at that line, I don't really know why it is there.

What it is doing is removing a space followed by one or more non-spaces at the end of the string.

I think you can safely remove it and insert my code.
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Sorry Paul Im sure it nearly there but I still get:

"tick's"

in the description.

--------------------------------
Privacy Software

Last edited by:

BLOOD: Feb 10, 2003, 8:14 AM
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
Try changing it to;

sub {
my $tags = shift;
my $desc = $tags->{Description} or return "Non on this template";
length $desc <100 and return $desc;
my $short = substr ($desc, 0, 100);
$short =~ s/[\"\'<>]+//g;
$short .= " ...";
return $short;
}


Does that make a difference?

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!

Last edited by:

Andy: Feb 10, 2003, 8:35 AM
Quote Reply
Re: [Andy] Shortened Versions Global In reply to
No, this is what I changed it too but I still get "tick's" unfortunately Unsure

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
Whoops...my boo boo Tongue Try the edited code above now...

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: [BLOOD] Shortened Versions Global In reply to
You don't need to escape single/double quotes - it should work as far as I can tell.

The only other thing is try adding an "s" next to the "g". You shouldn't need it but it's worth a try.
Quote Reply
Re: [Andy] Shortened Versions Global In reply to
Strange it doesnít work. This is what I have:

sub {
my $tags = shift;
my $desc = $tags->{Description} or return "Non on this template";
length $desc <1000 and return $desc;
my $short = substr ($desc, 0, 1000);
$short =~ s/["'<>]+//gs;
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}

The code "$short =~ s/\s\S+?$//;" prevent a word being cut off mid way. Tried removing this but still no joy in removing quotes.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
Are you sure the string is over 1000 characters?...if not the regex won't be executed.

Last edited by:

Paul: Feb 10, 2003, 8:45 AM
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
BINGO!

That done it.

Thanks to all!!

--------------------------------
Privacy Software
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Just so I can understand whats going on with the logic, what exactly are these numbers saying:

length $desc <1000 and return $desc;
my $short = substr ($desc, 0, 1000);

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
>>
length $desc <1000 and return $desc;
<<

If the description length is already less than 1000 then just display the whole thing (no need to chop it up).

>>
my $short = substr ($desc, 0, 1000);
<<

If the description is longer than 1000 this code reduces it to 1000. 0 is the start point and 1000 is the length of chars you want to keep.
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Thanks again Paul. Cool

--------------------------------
Privacy Software
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Had another idea for this global. How difficult to force all output into lowercase letters so the description "Pink Poodles" will be outputted as "pink poodles"


.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
Ok, after some experimentation I came with using this:


sub {
my $tags = shift;
my $desc = lc($desc);
my $desc = $tags->{Description} or return "Non on this template";
length $desc <1000 and return $desc;
my $short = substr ($desc, 0, 1000);
$short =~ s/["'<>]+//gs;
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}

This works Ok but I am not a programmer!! So please tell me if this is correct or could cause problems down the road.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
You shouldn't declare $desc with my() twice.

Just change:

my $desc = $tags->{Description} or return "Non on this template";

to...

my $desc = lc($tags->{Description}) or return "Non on this template";
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Thanks, I also experimented with this conversion

$short =~ tr/A-Z/a-z/;

Which I assume works the same as the above.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Shortened Versions Global In reply to
Yeah. You may as well use lc though.
Quote Reply
Re: [Paul] Shortened Versions Global In reply to
Is it me, or is there a typo in this line;

my $desc = lc($tags->{Description}) or return "Non on this template";

Shouldn't the part in red say "None" ?

I'm just one of the picky types ;)

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!