Force Word Wrap Mod problems

Advertise a phpBB hack or request help with an existing one.

Moderator: TerraFrost

Force Word Wrap Mod problems

Postby Cold Philter » Thu Apr 21, 2005 2:50 am

Hello,

I have attempted to use the Force Word Wrap Mod and I followed the instructions from the file install.txt, and the text wraps in the post body but some of the other text still isn't wrapping. Mainly the text in the subject line of topics when viewing a particular forum and also long web site addresses in members profiles do no wrap.

Examples:

http://www.philterphilosophy.com/forum/ ... m.php?f=15

http://www.philterphilosophy.com/forum/ ... unanswered

http://www.philterphilosophy.com/forum/ ... ofile&u=10

http://www.philterphilosophy.com/forum/ ... ofile&u=18

Do I need to use the install-config.txt to fix these problems? I plan on following the directions in that file as well, but I get stuck on the first step which is:

Code: Select all
# STEP NUMBER I: Prepare phpBB
 
#
 
#-----[ SQL ]-------------------------------------------
 
#
 
ALTER TABLE phpbb_users ADD user_wordwrap SMALLINT(3) DEFAULT '70' NOT NULL;
 
INSERT INTO `phpbb_config` (`config_name`, `config_value`) VALUES ('wrap_enable',1),
 
   ('wrap_min',50),('wrap_max',99),('wrap_def',70);


I don't know what this is telling me to do. Any help would be greatly appreciated. Thanks,

Alex
Cold Philter
Traveler
 
Posts: 5
Joined: Thu Apr 21, 2005 2:32 am

Postby TerraFrost » Thu Apr 21, 2005 4:41 am

This MOD doesn't stretch those things because it wasn't written to. However, it can be easily made to. Since the code for profile.php is very similar to something I've already done here, I was able to come up with pretty quickly:

Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_viewprofile.php

#
#-----[ FIND ]------------------------------------------
#
if ( !defined('IN_PHPBB') )

#
#-----[ BEFORE, ADD ]-----------------------------------
#
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

#
#-----[ FIND ]------------------------------------------
#
'WWW' => $www,
#
#-----[ REPLACE WITH ]----------------------------------
#
'WWW' => word_wrap_pass($www),

The other two will take a bit more time, but I'll try to have something for you, none-the-less, in a few days...

As far as how to install install-config.txt...

the things in the first step are sql queries. you can run them in phpmyadmin or run them via this tool:

http://www.phpbbhacks.com/forums/db_generator.php
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Cold Philter » Sat Apr 23, 2005 5:54 am

It's not working because the number of characters it stops at to prevent wrapping in bbcode.php is longer than what is needed in the profile web address. The web address needs to wrap at about 25 characters or so. I appreciate your help and the quick reply. Thanks,

Alex
Cold Philter
Traveler
 
Posts: 5
Joined: Thu Apr 21, 2005 2:32 am

Postby Cold Philter » Sat Apr 23, 2005 6:24 am

Hey TerraFrost,

I fixed the problem with web address in the profile.


What I did was copy all of the code that was supposed to go into the bbcode.php file from the install.txt file and inserted it into the usercp_viewprofile.php file before the closing '?>' and changed the function name to word_wrap_pro instead of word_wrap_pass.

Then I replaced the number or characters it wraps at from 65 to 25 and I deleted this code:

Code: Select all
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);



I deleted it because it was no longer calling the function from bbcode.php
Then I deleted this code:

Code: Select all
'WWW' => word_wrap_pass($www),



And replaced it with:

Code: Select all
'WWW' => word_wrap_pro($www),



Do you think what I did is correct? It seems to be working in the profile's now. If you think I entered any of the code wrong, please let me know.

Here are the URL's of the profiles:

http://www.philterphilosophy.com/forum/ ... ofile&u=18

http://www.philterphilosophy.com/forum/ ... ofile&u=10


Thanks,

Alex
Cold Philter
Traveler
 
Posts: 5
Joined: Thu Apr 21, 2005 2:32 am

Postby TerraFrost » Sat Apr 23, 2005 10:28 pm

to word wrap thread titles...

Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
viewforum.php
#
#-----[ FIND ]------------------------------------------
#
include($phpbb_root_path . 'common.'.$phpEx);
#
#-----[ AFTER, ADD ]-----------------------------------
#
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
#
#-----[ FIND ]------------------------------------------
#
         'TOPIC_TITLE' => $topic_title,
#
#-----[ REPLACE WITH ]----------------------------------
#
         'TOPIC_TITLE' => word_wrap_pass($topic_title),


to add word wrapping to posts in the search...

Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
search.php
#
#-----[ FIND ]------------------------------------------
#
               'TOPIC_TITLE' => $topic_title,
#
#-----[ REPLACE WITH ]----------------------------------
# the above find should match twice.  do this replacement on the second match.
#
               'TOPIC_TITLE' => word_wrap_pass($topic_title),
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Cold Philter » Mon Apr 25, 2005 5:11 am

I added the code into the thread titles and the subject line wrapping in the search. It works fine, but only if I set it to wrap on the 15th character in the bbcode.php.

The problem I now have is that spaces are added every 15th character in URL's and even in long words in the topics people are posting.

Is it possible to set the wrapping specifically to wrap the posts at the 65th character, the thread titles at the 25th character, and the subject line in the search at the 15th character? All three refer to the 15th character from bbcode.php when they each need to wrap at difference lengths. Is is possible to specify each one individually? Thanks again for you help. This is a great mod and my forum members and I appreciate your effort and hard work on it.

~Alex
Cold Philter
Traveler
 
Posts: 5
Joined: Thu Apr 21, 2005 2:32 am

Postby TerraFrost » Mon Apr 25, 2005 6:21 am

That's not currently all that easy to do. I'll try to think about how best to approach the problem and will try to have a working solution sometime (although i can't give you an eta)...
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Cold Philter » Sat Dec 23, 2006 9:47 pm

Hey there again.......after taking an extended hiatus from working on my forum.......(one and a half years....heh), I've decided to fix the word-wrapping issue I was having once and for all.

The problem I was having was that I wanted to be able to wrap my users posts at 65th character when they post long URLs, the thread titles at the 25th character, and the subject line in the search at the 15th character.

I have successfully accomplished this by adding additional code into the bbcode.php file. What I did was effectively copied your original code and duplicated twice more in the file, so that there were 3 instances of the code. Then I changed the 'word_wrap_pass' to 'word_wrap_title' and 'word_wrap_search' specified for the title wrapping and the search wrapping.

After that I changed the character each one wraps at so they wrap correctly at the 65th, 25th, and 15th character. Then I changed your addwrap helper function to 'addwraptitle' and 'addwrapsearch', so that no fatal errors occur by calling the same 'addwrap' function twice.

It seems to be working fine, I'm sure the code could be trimmed down more. Here are some links showing the breaks in the posts, thread titles, and search title:

Here it is wrapping in the post at the 65th character:

http://www.philterphilosophy.com/forum/ ... light=#151

Here it is wrapping in the thread titles at the 25th character:

http://www.philterphilosophy.com/forum/ ... m.php?f=15

And if you go to the search and search for 'hegel' a thread will come up breaking at the 15th character.


Here is the complete code changes I made in the file so you can take a look at them:


bbcode.php

Code: Select all
// Force Word Wrapping (by TerraFrost)
function word_wrap_pass($message)
{
   $userdata['user_wordwrap'] = 65;
   $tempText = '';
   $finalText = '';
   $curCount = $tempCount = 0;
   $longestAmp = 9;
   $inTag = false;
   $ampText = '';
   $len = strlen($message);

   for ($num=0;$num<$len;$num++)
   {
      $curChar = $message{$num};

      if ($curChar == '<')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addWrap($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         $ampText = '';
         $tempText .= '<';
         $inTag = true;
      }
      elseif ($inTag && $curChar == '>')
      {
         $tempText .= '>';
         $inTag = false;
      }
      elseif ($inTag)
      {
         $tempText .= $curChar;
      }
      elseif ($curChar == '&')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addWrap($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         $ampText = '&';
      }
      elseif (strlen($ampText) < $longestAmp && $curChar == ';' && function_exists('html_entity_decode') &&
             (strlen(html_entity_decode("$ampText;")) == 1 || preg_match('/^&#[0-9]+$/',$ampText)))
      {
         addWrap($ampText.';',$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         $ampText = '';
      }
      elseif (strlen($ampText) >= $longestAmp || $curChar == ';')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addWrap($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         addWrap($curChar,$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         $ampText = '';
      }
      elseif (strlen($ampText) != 0 && strlen($ampText) < $longestAmp)
      {
         $ampText .= $curChar;
      }
      else
      {
         addWrap($curChar,$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
      }
   }

   return $finalText . $tempText;
}

function addWrap($curChar,$nextChar,$maxChars,&$finalText,&$tempText,&$curCount,&$tempCount) {
   $wrapProhibitedChars = "([{!;,\\/:?}])";

   if ($curChar == ' ' || $curChar == "\n")
   {
      $finalText .= $tempText . $curChar;
      $tempText = '';
      $curCount = 0;
      $curChar = '';
   }
   elseif ($curCount >= $maxChars)
   {
      $finalText .= $tempText . ' ';
      $tempText = '';
      $curCount = 1;
   }
   else
   {
      $tempText .= $curChar;
      $curCount++;
   }

   // the following code takes care of (unicode) characters prohibiting non-mandatory breaks directly before them.

   // $curChar isn't a " " or "\n"
   if ($tempText != '' && $curChar != '')
   {
      $tempCount++;
   }
   // $curChar is " " or "\n", but $nextChar prohibits wrapping.
   elseif ( ($curCount == 1 && strstr($wrapProhibitedChars,$curChar) !== false) ||
            ($curCount == 0 && $nextChar != '' && $nextChar != ' ' && $nextChar != "\n" && strstr($wrapProhibitedChars,$nextChar) !== false))
   {
      $tempCount++;
   }
   // $curChar and $nextChar aren't both either " " or "\n"
   elseif (!($curCount == 0 && ($nextChar == ' ' || $nextChar == "\n")))
   {
      $tempCount = 0;
   }

   if ($tempCount >= $maxChars && $tempText == '')
   {
      $finalText .= '&nbsp;';
      $tempCount = 1;
      $curCount = 2;
   }

   if ($tempText == ''  && $curCount > 0)
   {
      $finalText .= $curChar;
   }
}




// Force Word Wrapping (by TerraFrost)
function word_wrap_title($message)
{
   $userdata['user_wordwrap'] = 25;
   $tempText = '';
   $finalText = '';
   $curCount = $tempCount = 0;
   $longestAmp = 9;
   $inTag = false;
   $ampText = '';
   $len = strlen($message);

   for ($num=0;$num<$len;$num++)
   {
      $curChar = $message{$num};

      if ($curChar == '<')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addwraptitle($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         $ampText = '';
         $tempText .= '<';
         $inTag = true;
      }
      elseif ($inTag && $curChar == '>')
      {
         $tempText .= '>';
         $inTag = false;
      }
      elseif ($inTag)
      {
         $tempText .= $curChar;
      }
      elseif ($curChar == '&')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addwraptitle($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         $ampText = '&';
      }
      elseif (strlen($ampText) < $longestAmp && $curChar == ';' && function_exists('html_entity_decode') &&
             (strlen(html_entity_decode("$ampText;")) == 1 || preg_match('/^&#[0-9]+$/',$ampText)))
      {
         addwraptitle($ampText.';',$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         $ampText = '';
      }
      elseif (strlen($ampText) >= $longestAmp || $curChar == ';')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addwraptitle($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         addwraptitle($curChar,$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         $ampText = '';
      }
      elseif (strlen($ampText) != 0 && strlen($ampText) < $longestAmp)
      {
         $ampText .= $curChar;
      }
      else
      {
         addwraptitle($curChar,$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
      }
   }

   return $finalText . $tempText;
}

function addwraptitle($curChar,$nextChar,$maxChars,&$finalText,&$tempText,&$curCount,&$tempCount) {
   $wrapProhibitedChars = "([{!;,\\/:?}])";

   if ($curChar == ' ' || $curChar == "\n")
   {
      $finalText .= $tempText . $curChar;
      $tempText = '';
      $curCount = 0;
      $curChar = '';
   }
   elseif ($curCount >= $maxChars)
   {
      $finalText .= $tempText . ' ';
      $tempText = '';
      $curCount = 1;
   }
   else
   {
      $tempText .= $curChar;
      $curCount++;
   }

   // the following code takes care of (unicode) characters prohibiting non-mandatory breaks directly before them.

   // $curChar isn't a " " or "\n"
   if ($tempText != '' && $curChar != '')
   {
      $tempCount++;
   }
   // $curChar is " " or "\n", but $nextChar prohibits wrapping.
   elseif ( ($curCount == 1 && strstr($wrapProhibitedChars,$curChar) !== false) ||
            ($curCount == 0 && $nextChar != '' && $nextChar != ' ' && $nextChar != "\n" && strstr($wrapProhibitedChars,$nextChar) !== false))
   {
      $tempCount++;
   }
   // $curChar and $nextChar aren't both either " " or "\n"
   elseif (!($curCount == 0 && ($nextChar == ' ' || $nextChar == "\n")))
   {
      $tempCount = 0;
   }

   if ($tempCount >= $maxChars && $tempText == '')
   {
      $finalText .= '&nbsp;';
      $tempCount = 1;
      $curCount = 2;
   }

   if ($tempText == ''  && $curCount > 0)
   {
      $finalText .= $curChar;
   }
}



// Force Word Wrapping (by TerraFrost)
function word_wrap_search($message)
{
   $userdata['user_wordwrap'] = 15;
   $tempText = '';
   $finalText = '';
   $curCount = $tempCount = 0;
   $longestAmp = 9;
   $inTag = false;
   $ampText = '';
   $len = strlen($message);

   for ($num=0;$num<$len;$num++)
   {
      $curChar = $message{$num};

      if ($curChar == '<')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addwrapsearch($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         $ampText = '';
         $tempText .= '<';
         $inTag = true;
      }
      elseif ($inTag && $curChar == '>')
      {
         $tempText .= '>';
         $inTag = false;
      }
      elseif ($inTag)
      {
         $tempText .= $curChar;
      }
      elseif ($curChar == '&')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addwrapsearch($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         $ampText = '&';
      }
      elseif (strlen($ampText) < $longestAmp && $curChar == ';' && function_exists('html_entity_decode') &&
             (strlen(html_entity_decode("$ampText;")) == 1 || preg_match('/^&#[0-9]+$/',$ampText)))
      {
         addwrapsearch($ampText.';',$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         $ampText = '';
      }
      elseif (strlen($ampText) >= $longestAmp || $curChar == ';')
      {
         for ($snum=0;$snum<strlen($ampText);$snum++)
         {
            addwrapsearch($ampText{$snum},$ampText{$snum+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         }
         addwrapsearch($curChar,$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
         $ampText = '';
      }
      elseif (strlen($ampText) != 0 && strlen($ampText) < $longestAmp)
      {
         $ampText .= $curChar;
      }
      else
      {
         addwrapsearch($curChar,$message{$num+1},$userdata['user_wordwrap'],$finalText,$tempText,$curCount,$tempCount);
      }
   }

   return $finalText . $tempText;
}

function addwrapsearch($curChar,$nextChar,$maxChars,&$finalText,&$tempText,&$curCount,&$tempCount) {
   $wrapProhibitedChars = "([{!;,\\/:?}])";

   if ($curChar == ' ' || $curChar == "\n")
   {
      $finalText .= $tempText . $curChar;
      $tempText = '';
      $curCount = 0;
      $curChar = '';
   }
   elseif ($curCount >= $maxChars)
   {
      $finalText .= $tempText . ' ';
      $tempText = '';
      $curCount = 1;
   }
   else
   {
      $tempText .= $curChar;
      $curCount++;
   }

   // the following code takes care of (unicode) characters prohibiting non-mandatory breaks directly before them.

   // $curChar isn't a " " or "\n"
   if ($tempText != '' && $curChar != '')
   {
      $tempCount++;
   }
   // $curChar is " " or "\n", but $nextChar prohibits wrapping.
   elseif ( ($curCount == 1 && strstr($wrapProhibitedChars,$curChar) !== false) ||
            ($curCount == 0 && $nextChar != '' && $nextChar != ' ' && $nextChar != "\n" && strstr($wrapProhibitedChars,$nextChar) !== false))
   {
      $tempCount++;
   }
   // $curChar and $nextChar aren't both either " " or "\n"
   elseif (!($curCount == 0 && ($nextChar == ' ' || $nextChar == "\n")))
   {
      $tempCount = 0;
   }

   if ($tempCount >= $maxChars && $tempText == '')
   {
      $finalText .= '&nbsp;';
      $tempCount = 1;
      $curCount = 2;
   }

   if ($tempText == ''  && $curCount > 0)
   {
      $finalText .= $curChar;
   }
}




viewforum.php

Code: Select all
#
#-----[ FIND ]------------------------------------------
#
         'TOPIC_TITLE' => word_wrap_pass($topic_title),
#
#-----[ REPLACE WITH ]----------------------------------
#
         'TOPIC_TITLE' => word_wrap_title($topic_title),



search.php


Code: Select all
#
#-----[ FIND ]------------------------------------------
#
               'TOPIC_TITLE' => word_wrap_pass($topic_title),
#
#-----[ REPLACE WITH ]----------------------------------
#
#
               'TOPIC_TITLE' => word_wrap_search($topic_title),


So what do you think?
Cold Philter
Traveler
 
Posts: 5
Joined: Thu Apr 21, 2005 2:32 am

Postby TerraFrost » Wed Feb 14, 2007 4:30 pm

Sorry for not replying to you, sooner (phpbb.com is kinda keeping me busy, these days, heh).

Anyway, instead of having three sep. functions, what about passing the size as a parameter to a single function?
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am


Return to phpBB Hacks and MODs

Who is online

Users browsing this forum: No registered users and 2 guests

cron