Server Help

Trash Talk - Go Team Barry!

Mine GO BOOM - Sat Nov 19, 2005 11:14 pm
Post subject: Go Team Barry!
Yet another reason why phpbb code is horrible:

After running the code through indent because half of it was on one line, I finally found the double [code] problem, and why it didn't effect me nor some others. Apparently, the smilie parsing code was written by someone who learned php 10 minutes ago. I like the spelling of pieces too.

Code: Show/Hide
//
// Smilies code ... would this be better tagged on to the end of bbcode.php?
// Probably so and I'll move it before B2
//
function smilies_pass ($message)
{
  static $orig, $repl;
  if (!isset ($orig))
    {
      global $db, $board_config, $bbcode_tpl;
      $orig = $repl = array ();
      $sql = 'SELECT code, smile_url FROM '.SMILIES_TABLE;
      if (!$result = $db->sql_query ($sql))
   {
     message_die (GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
   }
      $smilies = $db->sql_fetchrowset ($result);
      usort ($smilies, 'smiley_sort');
      for ($i = 0; $i < count ($smilies); $i++)
   {
     $orig[] = "/(?<=.\W|\W.|^\W)" . phpbb_preg_quote ($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/";
     $repl[] = '<img src="' . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['smile_url'] . '" border="0" />';
   }
    }

  if (count ($orig))
    {
      $peaces = array ();
      if (isset ($bbcode_tpl))
   {
     // bbcode_tlp is present, make split pattern
     $code_start_html = preg_quote ($bbcode_tpl['code_open']);
     $code_split_pattern = "#(".$code_start_html.")#s";
     $peaces = preg_split ($code_split_pattern, $message, -1);
   }
      if (count ($peaces) <= 1)
   {
     // no code block, parse all smilies
     $message = preg_replace ($orig, $repl, ' '.$message.' ');
     $message = substr ($message, 1, -1);
   }
      else
   {
     // code block detected...
     $message = "";
     for ($i = 0; $i < count ($peaces); $i++)
       {
//         if (($i % 2 == 0))
//MGB HACK: Fix smilie parsing out [ code ] html
      if ($i == 0)
      {
        // normal text, parse for smilies
        $peaces[$i] =
          preg_replace ($orig, $repl, ' '.$peaces[$i].' ');
        $peaces[$i] = substr ($peaces[$i], 1, -1);
        $message .= $peaces[$i];
      }
         else
      {
        // code block, do not do smilie parsing for code

        // find position of code close HTML
        $pos = strpos($peaces[$i], $bbcode_tpl['code_close']);
        $len = strlen($bbcode_tpl['code_close']);

        // split this peace in code text and normal text
        $code_text = substr($peaces[$i], 0, $pos);
        $normal_text = substr($peaces[$i], $pos + $len);

        // parse normal text for smilies
        $normal_text = preg_replace($orig, $repl, ' ' . $normal_text . ' ');
        $normal_text = substr($normal_text, 1, -1);

        // put boundries, code text and normal text together and add to message
        $message .= $bbcode_tpl['code_open'] . $code_text . $bbcode_tpl['code_close'] . $normal_text;
      }
       }
   }
    }
  return $message;
}


Apparently, they thought that when you split around a specific block, it would somehow magically split around the ending block. Thus, they loop over the peaces (SIC) array. Well, the final code doesn't bother with that stupid checking, and instead just starts the for loop at 1.

Once Team Barry finishes his new forums software and makes it public, I'm so switching...
Confess - Sun Nov 20, 2005 12:30 am
Post subject:
Why not go to IPB 1.3?
Anonymous - Sun Nov 20, 2005 1:09 am
Post subject:
Get UBB5 and run the perl/cgi ver.
Cyan~Fire - Sun Nov 20, 2005 1:28 am
Post subject:
Yep, there's a reason I switched to SMF (without a hitch).
Mine GO BOOM - Sun Nov 20, 2005 1:55 am
Post subject:
Confess wrote:
Why not go to IPB 1.3?

Because I want to upgrade the forums, not just change to someone else. Got too many damn hacks in here already, might as well keep them.
D1st0rt - Sun Nov 20, 2005 8:26 pm
Post subject:
Cyan, I can't ignore Spyed on SMF
Purge - Sun Nov 20, 2005 11:04 pm
Post subject:
D1st0rt wrote:
Cyan, I can't ignore Spyed on SMF


Because 1st is using an open Beta version of SMF 1.1.
Cyan~Fire - Sun Nov 20, 2005 11:05 pm
Post subject:
You can't ignore Spyed on a non-modded phpbb either.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group