Specific Number of Snip Characters

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

Specific Number of Snip Characters

Postby Buck Satan » Tue Apr 08, 2003 6:14 pm

Hi,

I'm currently using the Snip function (such as <Snip 50: Field: Text>), but it is designed not to break up words and (I believe) figures in HTML characters. For conformity, I would like to snip my news to an exact number of characters so they all have the exact same length. Is there any way to do this?

For example, snipping 20 characters would normally display this:

This is a news snippet...

Whereas I want to only show exactly 20 characters, even if it breaks up a word right in the middle, like this:

This is a news snipp...

Anybody know how this can be done?
Buck Satan
 
Posts: 28
Joined: Wed Nov 06, 2002 12:28 am

Postby Joyrex » Tue Apr 08, 2003 10:45 pm

See my post in the Read More thread in this forum for the specific PerlCode to strip the HTML out to get a uniform number of characters.
We are the music makers...we are the dreamers of the dreams...
User avatar
Joyrex
 
Posts: 259
Joined: Fri Jun 14, 2002 9:37 pm

Postby Buck Satan » Wed Apr 09, 2003 2:52 am

Hmm, but even with your code, it still won't snip in the middle of a word. Any idea if the code could be slightly adjusted to stop dead at, say, 75 characters no matter what?
Buck Satan
 
Posts: 28
Joined: Wed Nov 06, 2002 12:28 am

Postby T-1000 » Wed Apr 30, 2003 4:37 pm

I'd also like to know how to do this, i've tried Joyrex's code but it still outputs whole words before it snips.
T-1000
 
Posts: 66
Joined: Sun Mar 23, 2003 12:13 pm

Postby T-1000 » Wed May 14, 2003 7:15 am

can anyone help, please? :)
T-1000
 
Posts: 66
Joined: Sun Mar 23, 2003 12:13 pm

Postby T-1000 » Wed May 21, 2003 7:04 am

I know i'm probably in the minority here but i'd really like to know how to do this or if anyone could give me a few code pointers i'd be very gratefull!
T-1000
 
Posts: 66
Joined: Sun Mar 23, 2003 12:13 pm

Postby InSAnE NiNjA » Wed May 21, 2003 8:51 am

Code: Select all
<PerlCode>
*antiDotSnip = sub { my ($text, $len) = @_; $text = HTMLstrip($text); return ($text =~ /({$len}\S*)/ ? $1 : $text);} unless $aDSLoaded; $aDSLoaded++;
</PerlCode>
Code: Select all
<PerlCode>
$NAME = antiDotSnip($NAME, #);
</PerlCode>


Again, # is the number of characters you want to keep and NAME is the name of the field you want to snip. Note: If you want to snip multiple fields using this method ONLY reuse the very last code example.

this is my attempt at it.. a slightly modified version of lordph1l's code
its 5 in the morning and i might have gotten it backwards.. so try it
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby T-1000 » Wed May 21, 2003 11:58 am

Thanks for replying Ninja!
I've tried your code but i'm getting this error right after i select to re-build the news:

Untrapped Error: Quantifier follows nothing before HERE mark in regex m/({ << HERE 15}\S*)/ at crcfg.dat line 984, <FH> line 4.

I'm sorry but i haven't a clue what it's trying to tell me :P
D'ya have any ideas whats wrong?
T-1000
 
Posts: 66
Joined: Sun Mar 23, 2003 12:13 pm

Postby msbzdragn » Wed May 21, 2003 3:10 pm

Might not be the best way to do it, but here's how I'm making a snipped headline on a site of mine, with 25 characters followed by "...". If you want a different number of characters, change both occurrences of 25 to something else. If you don't want the ..., remove it. If you want to snip a different field, replace $Subject with $Fieldname, where Fieldname is the name of the field in question, and if you feel like it rename $SnippedSubject as well. I've removed the Maginot stuff from my style in this demonstration to avoid confusion.

Code: Select all
<PerlCode>
if (length ($Subject) > 25) {
$SnippedSubject = substr($Subject,0,25);
}
</PerlCode><If: Field: SnippedSubject><Field: SnippedSubject>...<If: Else><Field: Subject></If><br />
<PerlCode>
{
 $SnippedSubject = "";
}
</PerlCode>


This will snip to an exact number of characters, regardless of whether there's HTML tags in it. If you are snipping a field that has HTML tags in it - say the news text field - , you will NOT want to do this as it might snip the text after an open tag, but before the closing tag - or even in the middle of an open or close tag. That would cause problems in your output, hence use the approach below:

Code: Select all
<PerlCode>
$StrippedText = HTMLstrip($Text);
if (length ($StrippedText) > 500) {
$SnippedText = substr($StrippedText,0,500);
}
</PerlCode><If: Field: SnippedText><Field: SnippedText>... <A HREF="<MaginotURL: news>">(More)</A><If: Else><Field: Text></If><br />
<PerlCode>
{
 $SnippedText = "";
}
</PerlCode>


This will check the length of your news Text field without HTML tags, and if it is longer than 500 characters will put the first 500 characters of that field without HTML, followed by a more link to a Maginot profile called news. If there is less than 500 characters, it will put the entire news text field, including all HTML tags.
Michael R. Tomkins
Administrator, 'Unofficial Coranto / NewsPro Forums'

Mitsubishi Diamante Forum

Do NOT send me instant messages asking for Coranto help without me telling you explicitly to do so. You WILL be placed on ignore if you do so; I don't have time to provide personal tech support to every person who IM's me. Sorry!
User avatar
msbzdragn
 
Posts: 2397
Joined: Mon Mar 11, 2002 4:51 pm
Location: Oak Ridge, TN

Postby Olecram » Wed May 21, 2003 3:48 pm

Can I use this code without using maginot?

I use viewnews.cgi

How can i split news using viewnews.cgi

Suppouse i have a large content of a specific news, so i would like that news to be one news that in the end of it appears a name "continue" and when a clik in that link i go to the rest of that news.

can it be done?
User avatar
Olecram
 
Posts: 57
Joined: Thu May 01, 2003 10:39 pm
Location: Brazil

Postby T-1000 » Wed May 21, 2003 4:02 pm

That's really great, works perfect msbzdragn!
Thankyou x 1000000 for your help guys
T-1000
 
Posts: 66
Joined: Sun Mar 23, 2003 12:13 pm

Postby SrNupsen » Wed May 21, 2003 4:03 pm

To use it with viewnews.cgi, just replace where it says

Code: Select all
<A HREF="<MaginotURL: news>">


with

Code: Select all
<A HREF="http://www.yourserver.com/path/to/viewnews.cgi?id=<Field: newsid>">


There's an addon to split items over several pages. Take a look in the addon section.

MrNupsen
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby msbzdragn » Wed May 21, 2003 4:09 pm

T-1000 wrote:That's really great, works perfect msbzdragn!
Thankyou x 1000000 for your help guys


Glad to help... Thanks to Nupsen for stepping in with the viewnews answer...
Michael R. Tomkins
Administrator, 'Unofficial Coranto / NewsPro Forums'

Mitsubishi Diamante Forum

Do NOT send me instant messages asking for Coranto help without me telling you explicitly to do so. You WILL be placed on ignore if you do so; I don't have time to provide personal tech support to every person who IM's me. Sorry!
User avatar
msbzdragn
 
Posts: 2397
Joined: Mon Mar 11, 2002 4:51 pm
Location: Oak Ridge, TN

Postby Olecram » Wed May 21, 2003 6:53 pm

MrNupsen wrote:There's an addon to split items over several pages. Take a look in the addon section.


MrNupsen,

I looked at the addon section, but i just found the addon for Maginot.
Can you help me?

Thank you,
User avatar
Olecram
 
Posts: 57
Joined: Thu May 01, 2003 10:39 pm
Location: Brazil

Postby SrNupsen » Wed May 21, 2003 9:00 pm

Oops, I confused it with Multipage. I looked around a bit, and it seems that splitting one single article into several pages isn't possible with viewnews.cgi

So, I guess you have to install Maginot. But don't be afraid. If I managed to get the hang of it, so can you. Besides, you won't be using the most advanced features, only static split pages.

And, I might add, you'll find Maginot a lot better in the long run :)

Sorry for confusing you.

MrNupsen
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway


Return to Customization

Who is online

Users browsing this forum: No registered users and 2 guests

cron