Custom Subroutine Vanished Help?

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

Moderator: Spunkmeyer

Custom Subroutine Vanished Help?

Postby Pirate Elf » Thu Mar 15, 2007 11:15 pm

I had a custom subroutine done by Parahead that split long words but I just updated to the 1.25 core and it went bye bye. It has been so long since I messed with the backend of coranto I totally forgot I was using it. So if parahead still exists could you tell me a quick snip it of code that will split long words like:

Change

superlongwordthatbreakstablesandannoysme

to this

superlongword thatbreakstablesand annoysme

it actually broke my whole style keeps giving me MAD errors: Long Style:

Code: Select all
<PerlCode>
 $Text = splitLongWords($Text);
</PerlCode>


Is what I was using, and when I remove it I get a long nice error. Any help would be great

1.25 broke the whole style. :-(

Thank god for cache! Found using google reposted here for me:
Code: Select all
$max_word_length = 20;
$preferred_word_length = 15;
$punish_length = 3;

# Take care of words that is longer than "max_word_length" chars
# by putting in a space every "preferred_word_length" chars.
# Text inbetween tags, < and >, is left untuched.
# It can also handle words continuing over several tags without
# spacing between them: <B>test</B><I>test2</I>
# "punish_length" is used when using a bunch of tags in a row
# (eg. a lot of smilies after each other)
sub splitLongWords
{
 my $text = shift;
 my $return_text = '';
 my ($split_text, $spacer, $length);
 my $totlength = 0;

 while(length($text) > 0)
 {
  my ($pre, $rest) = split('<', $text, 2);
  my ($tag, $post) = split('>', $rest, 2);
 ($split_text, $spacer, $length) = splitter($pre);
 $totlength = $length if($spacer);
 $totlength += $length if(!$spacer);
 $totlength += $punish_length if(!$spacer && $length == 0);
 if($totlength > $max_word_length)
 {
  $return_text .= ' ';
  $totlength -= $max_word_length;
 }
 $return_text .= $split_text;
 $return_text .= '<'.$tag.'>' unless(length($tag) == 0);
 $text = $post;
 }
 return "$return_text";
}


# Splitts all long words found in the string.
# Does not take tags into account,
# this sub is only ment to be used by splitLongWords
sub splitter
{
 my $text = shift;
 my $spacer = 0;
 my $length = length($text);

 my $return_text = ($text =~ m/^ /)? ' ':'';
 my $last_space = ($text =~ m/ $/)? ' ':'';

 my (@words) = split(/\s/,$text);
 foreach my $word(@words)
 {
  $length = length($word);
  if(length($word) > $max_word_length)
  {
   my $tmp_word = '';
   while( length($word) > $max_word_length)
   {
    my $word_pre = substr($word, 0, $preferred_word_length);
    $word = substr($word, $preferred_word_length, length($word));
    $tmp_word .= "$word_pre ";
   }
   $spacer = 1;
   $length = length($word);
   $word = "$tmp_word$word";
  }
  $spacer = 1 if ($return_text);
  $return_text .= ' ' if($return_text);
  $return_text .= $word;
  $return_text .= $last_space;
 }
 return ($return_text, $spacer, $length);
}
Nichts ist für dich
Nichts war für dich
Nichts bleibt für dich
Für immer
Pirate Elf
 
Posts: 732
Joined: Wed Jan 31, 2007 9:45 pm

Postby Jackanape » Fri Mar 16, 2007 12:18 pm

Also, Pirate, for future consideration, the old forums are all archived here under the Support Archives link.
A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly.
Specialization is for insects.
-Robert A. Heinlein
User avatar
Jackanape
 
Posts: 632
Joined: Tue Jan 09, 2007 12:15 am
Location: Capitol of the Great State of New York

Postby Pirate Elf » Sat Mar 17, 2007 2:57 am

O RLY? Good stuff! Thank you
Nichts ist für dich
Nichts war für dich
Nichts bleibt für dich
Für immer
Pirate Elf
 
Posts: 732
Joined: Wed Jan 31, 2007 9:45 pm

Postby Lumberjack » Sat Mar 17, 2007 9:22 am

I am using a variant of this for the headlines, which first uses SnipText to take the first 10 characters, rounded to the nearest word. And then if the subject happens to be one really long word, I shorten it to 20 characters so it fits in the table:
Code: Select all
<PerlCode>
my $CustomSnip = SnipText($Subject,10);
$CustomSnip = sprintf('%.20s', $CustomSnip);
while ($CustomSnip =~ s/\.$//) {};
</PerlCode>

That last line takes off any trailing dots, I can't remember why I started doing that.. the thing I notice with this is, no matter how much you anticipate, one user always posts something you weren't expecting, and you will always end up adding another line.
By the way I tried substr instead of sprintf but it didn't work (and actually this is more appropriate for the purpose).

Oh, you must then use $CustomSnip instead of $Subject in your style.
Lumberjack
 
Posts: 555
Joined: Wed Jan 10, 2007 7:22 pm
Location: Oxford, UK

Postby Whatrevolution » Sat May 26, 2007 12:51 pm

Lumberjack wrote:That last line takes off any trailing dots, I can't remember why I started doing that..


Looks useful for when you have Coranto adding its own elipses to the end of a snip, and the line being snipped happens to get snipped at a user's own elipses. :D Nice.
Whatrevolution
 
Posts: 7
Joined: Fri May 25, 2007 9:49 am


Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest

cron