Runaway Lines (with out snipping) (Solved)

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

Moderator: Spunkmeyer

Runaway Lines (with out snipping) (Solved)

Postby Pirate Elf » Fri Jun 04, 2004 1:18 am

Guys I have been working on a shoutbox for my friends and I am using coranto. Everything is perfect except there is a slight problem with runaway lines.

If the string is something like this

blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah

It freaks the page out, and doesn't resize properly. What I need it to do is something like this:

Code: Select all
blahblahblahblahblahblah<br>blahblahblahblahblahblahblah<br>blahblahblahblahblahblahblah


So any ideas? maybe a perl line I could throw in to the field?


Also if i have a field like Custom_Website, how can I make coranto check to see if it is a url or whether it's just a crap line or invalid value
Last edited by Pirate Elf on Mon Jun 07, 2004 1:22 pm, edited 1 time in total.
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 InSAnE NiNjA » Fri Jun 04, 2004 5:18 am

i dont know perl.. but the answer WOULD be perl code..

first would be some kind of wordwrap or string-replace command.. the other would be code that recognizes urls.. such as how coranto auto-links urls
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby Parahead » Fri Jun 04, 2004 6:39 am

The shoutbox at my site is developed by me and I run across just this problem, so I came up with the two routines belove. The $max_word_length and $preferred_word_length is kind of obvious what they do, but the $punish_length variable? Well, that is used if people adds a lot of tags after each other, since the tags doesn´t count. Each tag that is used "stand alone" got this punish_lenght appended to the total word length. (To sum that up, if you use alof of smilies after each other, you will only be allowed to have a certain amount before a space is inserted).

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);
}


Then it is bascially just placing the subs in cruser.pl and make a call to splitLongWords in your style like this:
Code: Select all
<PerlCode>
$SplittedText = splitLongWords($Text);
</PerlCode>

<Field: SplittedText>


Hope you can work out something with this?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Pirate Elf » Fri Jun 04, 2004 8:29 am

strange....

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

<Field: CustomField_Shouttext>



and added the little thing to the sub string, but for some reason it cleared every single bit of text... I will continue to play with it, but for some reason it didn't like me....

Also any ideas about the website? Like how I could make a small bit that would say

If text = http:// url
then post http://ur
else
nothing

so that way unless they put http://url it will just be blank....l



Edit:
I tried this
Code: Select all
<If: Field: CustomField_Website eq "http://">
<a href="<Field: CustomField_Website>" class="inlinelink" target="blank"><b><Field: User></b></a>
<If: Else>


But it won't accept anything other than http:// I just want it to only accept things that start with http://[/code]
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 Parahead » Fri Jun 04, 2004 11:01 am

Pirate Elf wrote:and added the little thing to the sub string, but for some reason it cleared every single bit of text... I will continue to play with it, but for some reason it didn't like me....
Don´t quite get what "added the little thing to the sub string" means... But note that I have just cut and pasted those two subs from my shoutbox script, I havn´t tested it in the way I suggested above, but they *do* work in my script... ;-) I am in a bit of a hurry so I don´t have time to test this right now, but if you havn´t solved it in a while I can check it out a bit more...

Pirate Elf wrote:I tried this
Code: Select all
<If: Field: CustomField_Website eq "http://">
<a href="<Field: CustomField_Website>" class="inlinelink" target="blank"><b><Field: User></b></a>
<If: Else>


But it won't accept anything other than http:// I just want it to only accept things that start with http://[/code]

That is because "eq" means equals, not "starts with"... ;-)
But maybe this match is what you want:
Code: Select all
<PerlCode>
if($CustomField_Website =~ m/^http:\/\//)
{
</PerlCode>
<a href="<Field: CustomField_Website>" class="inlinelink" target="blank"><b><Field: User></b></a>
<If: Else>
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Pirate Elf » Fri Jun 04, 2004 2:31 pm

You are the man! LOL! The perl string works beautifully for the website feature.

Parahead wrote:Don´t quite get what "added the little thing to the sub string" means... But note that I have just cut and pasted those two subs from my shoutbox script, I havn´t tested it in the way I suggested above, but they *do* work in my script... ;-) I am in a bit of a hurry so I don´t have time to test this right now, but if you havn´t solved it in a while I can check it out a bit more...


I was rather tired and still am (haven't slept yet), but what I meant is I added it to cruser.pl, then called the style with the perl code laid out like I said earlier. For some reason it cleared everything that was in it. I delete the perl script, and the text comes back.

Maybe I missed something I am going to get some sleep if you get any ideas just drop me a line. Meanwhille I am out for the day..
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 Parahead » Sat Jun 05, 2004 4:39 pm

Pirate Elf wrote:I was rather tired and still am (haven't slept yet), but what I meant is I added it to cruser.pl, then called the style with the perl code laid out like I said earlier. For some reason it cleared everything that was in it. I delete the perl script, and the text comes back.

Maybe I missed something I am going to get some sleep if you get any ideas just drop me a line. Meanwhille I am out for the day..
I tried this at my site and it worked like a charm. To be sure I copied the exact code from this forum... You just place the hole first code-section with the two subs and the three variables and put those in the cruser.pl file and then make the call like in the PerlCode example, that should work... ?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Pirate Elf » Sat Jun 05, 2004 9:42 pm

I copied it exaclty all I changed was Field: Splittedtext to CustomField_ShoutText

It just shows blanks of texts? perhaps I have to name it splittedtext? in which case how can I do that without getting customfield_splitted text

I copied exactly but still not working :-( is there an easy way like every 15characters add a break?

My style using your code:
Code: Select all
<PerlCode>
  my $GuestPostdetails=<Field: CustomField_PosterIP>;
  my ($GP_IP, $GP_name, $GP_email ) = split(/\;\;/, $GuestPostdetails);
</PerlCode>
<table cellpadding="2" cellspacing="0" border=0" width="100%" class="table1">
<tr>
<td class="shoutbox">
<PerlCode>
if($CustomField_Website =~ m/^http:\/\//)
{
</PerlCode>
<a href="<Field: CustomField_Website>" class="inlinelink" target="blank"><b><Field: User></b></a>
<If: Else>
<b><Field: User></b>
</If>: <PerlCode>
$CustomField_ShoutText = splitLongWords($Text);
</PerlCode> <Field: CustomField_ShoutText><!-- Guest Poster IP:    <Field: GP_IP> -->
</td></tr></table>

Gives blanks....
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 Parahead » Sun Jun 06, 2004 9:06 am

Pirate Elf wrote:It just shows blanks of texts? perhaps I have to name it splittedtext? in which case how can I do that without getting customfield_splitted text
You can call the variable you put the return value from the splitLongWords-sub. I assumed you where using the normal default Text-field when you used your shoutbox, this is the case right?

Pirate Elf wrote:I copied exactly but still not working :-( is there an easy way like every 15characters add a break?
Here I give you a perfect solution and you would like to have such a simple one, hrm.... ;-)

Pirate Elf wrote:My style using your code:

Well, that should work, even though I would like to change it to:
Code: Select all
<PerlCode>
  my $GuestPostdetails=$CustomField_PosterIP;
  my ($GP_IP, $GP_name, $GP_email ) = split(/\;\;/, $GuestPostdetails);
</PerlCode>
<table cellpadding="2" cellspacing="0" border=0" width="100%" class="table1">
<tr>
<td class="shoutbox">
<PerlCode>
if($CustomField_Website =~ m/^http:\/\//)
{
</PerlCode>
<a href="<Field: CustomField_Website>" class="inlinelink" target="blank"><b><Field: User></b></a>
<If: Else>
<b><Field: User></b>
</If>:
<PerlCode>
 $ShoutText = splitLongWords($Text);
</PerlCode>
<Field: ShoutText>
</td></tr></table>


If you like you could send me your cruser.pl so I can take a look at it?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Pirate Elf » Sun Jun 06, 2004 9:41 pm

Parahead wrote:You can call the variable you put the return value from the splitLongWords-sub. I assumed you where using the normal default Text-field when you used your shoutbox, this is the case right?


Fixed it. You're clue gave me the idea, and I should have seen it but I have been a bit stressed and just didn't pay attention

this line:

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


Made it work. Just had to change where it was calling. I have no idea why I didn't see this, but for some reason I just didn't. :oops: Thank you very much for all your help man.

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 Parahead » Mon Jun 07, 2004 6:19 am

Pirate Elf wrote:Fixed it. You're clue gave me the idea, and I should have seen it but I have been a bit stressed and just didn't pay attention
We all do these small misstakes and I guessed this might be the problem... ;-)

Pirate Elf wrote:Thank you.
You are welcome! :-D
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Pirate Elf » Tue May 16, 2006 1:48 am

How to bring old threads back to life:

When and if you gain the time Parahead could you tell me what I would need to change so that it would do something like this:


http://www.longwebsite.com/url/asddwews2sdd234swec.php

Convert to this:
http://www.longwebsite.com/... <<---that being the cut off length

Because at the current moment it does this:
http://www.long website.com/url asddwew2sdd234s wec.php

It adds a space which makes urls totally invalid. :-(
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 Parahead » Fri Jun 09, 2006 7:02 pm

Pirate Elf wrote:How to bring old threads back to life:

When and if you gain the time Parahead could you tell me what I would need to change so that it would do something like this:


http://www.longwebsite.com/url/asddwews2sdd234swec.php

Convert to this:
http://www.longwebsite.com/... <<---that being the cut off length

Because at the current moment it does this:
http://www.long website.com/url asddwew2sdd234s wec.php

It adds a space which makes urls totally invalid. :-(

Just to make it ignore snipping URL's starting with http:// you might try changing the line:
Code: Select all
if(length($word) > $max_word_length)

to this instead:
Code: Select all
if( (length($word) > $max_word_length) && ($word !~ ~^http\:/~) )

Not tested!
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden


Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest

cron