×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Max line length

Max line length 15 years 1 week ago #3707

  • jono
  • jono's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Hi there. I started using this component today. I am enjoying its ease of use but am having a few issues.

First of all, I was having the same problem as others with intermittent line breaks. So I followed the advice on here and set the line max length to -1. This solved the line break problem but now the comments extend outside the boundaries of my page.

So I can either set the max line length to 80, have the correct width but have intermittent line breaks appear, or set the max line length to -1, correct the line break issue but have the width far too wide.

Any thoughts on solving this?

Please see the link below.

www.melbourneclinicalhypnotherapy.com.au...&view=article&id=109

Cheers!

Max line length 15 years 1 week ago #3710

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
first change the template to the mordern one - it should not go out of "boundaries."

The length is not an issue. We count the characters from the first character to the first <br /> and then from the br to the next br. Also you have length for words.

Try the demo section. Do you see there such behavior? Try to find out the right line length for your template. It can be 80, but also 160 chars.

Max line length 15 years 1 week ago #3711

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
hm, ok - there is a problem with this - you are right. I will try to look for it. :(

Max line length 15 years 1 week ago #3713

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
OK, I think that I finally managed to make it:

Open components/com_comment/joscomment/utils.php and find the utf8_wrapword function

and change it to this:
     function utf8_wordwrap($str, $width=75, $break="\n", $cut=false)
    {
        $splitedArray    = array();
        $lines            = explode("\n", $str);
        foreach ($lines as $line) {
            $lineLength = JString::strlen($line);
            if ($lineLength > $width) {
                $words = explode("\040", $line);
                $lineByWords = '';
                $addNewLine = true;
                foreach ($words as $word) {
                    $lineByWordsLength        = JString::strlen($lineByWords);
                    $tmpLine                = $lineByWords.((JString::strlen($lineByWords) !== 0) ? ' ' : '').$word;
                    $tmplineByWordsLength    = JString::strlen($tmpLine);
                    if ($tmplineByWordsLength > $width && $lineByWordsLength <= $width && $lineByWordsLength !== 0) {
                        $splitedArray[]    = $lineByWords;
                        $lineByWords    = '';
                    }
 
                    $newLineByWords            = $lineByWords.((JString::strlen($lineByWords) !== 0) ? ' ' : '').$word;
                    $newLineByWordsLength    = JString::strlen($newLineByWords);
                    if ($cut && $newLineByWordsLength > $width) {
                        for ($i = 0; $i < $newLineByWordsLength; $i = $i + $width) {
                            $splitedArray[] = JString::substr($newLineByWords, $i, $width);
                        }
                        $addNewLine = false;
                    } else {
                        $lineByWords = $newLineByWords;
                    }
                }
                if ($addNewLine) {
                    $splitedArray[] = $lineByWords;
                }
            } else {
                $splitedArray[] = $line;
            }
        }
        return implode($break, $splitedArray);
    }

Ah, and please tell me if it is working!

Max line length 15 years 1 week ago #3724

  • jono
  • jono's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Cheers for the suggestion. I changed the code in the utils file but am still have the same problem. Any other suggestions?

Thanks

Max line length 15 years 1 week ago #3726

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
right now on the page you gave us you have line length -1? Can you change it so I can see what is wrong?

Max line length 15 years 1 week ago #3741

  • jono
  • jono's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Hi Daniel. I have changed the line length to 70.

Cheers

Max line length 15 years 1 week ago #3742

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Ok, at least the words don't have any spaces. What I can say is that these utf8 aware wordwrap functions suck :)
I will have to write one myself and not copy them from php.net :)

Stay tuned.

Max line length 15 years 3 days ago #3827

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hm, I tested it again. And it seems fine for me. Can you post the string that you input in your website so I can see how it is transformed?

Thanks!

Max line length 14 years 11 months ago #4112

  • Juan Velez
  • Juan Velez's Avatar
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 24
Works for me, changed the function for this one and max length untouched, still at 80. No word cutting.

Thanks!

Max line length 14 years 10 months ago #4454

  • JonusC
  • JonusC's Avatar
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 785
  • Thank you received: 48
Your code snippet there did help Daniel, thanks for that. But I did make a correction, it wasn't making new lines when it was supposed to (i.e. it was putting everything on one line no matter what).

So I changed....
$lines            = explode("\n", $str);
...to....
$lines            = explode("<br />\n", $str);
...and now it works :)


I do have Line length on -1 though, and I am using the modern theme.

But I noticed it still sometimes enters a space randomly. It only did it once on a sequence of periods/fullstops...

This is a test message for visuals and whatnot...........................
that message came out as -
This is a test message for visuals and whatnot.......................... .


Since it only happened with dots and not the bunch of random letters after it (about 500 letters of gibberish), i'm pretty happy :)

EDIT: The space between the dots was because I reached the max word length - sorry haha. It works flawlessly now! Thanks!


Looking forward to the next release!
  • Page:
  • 1
Time to create page: 0.179 seconds