Changeset 891 for trunk/includes


Ignore:
Timestamp:
Jan 13, 2023, 12:40:34 AM (23 months ago)
Author:
chronos
Message:
  • Fixed: HTML BBCode parser not supported for newer PHP 8.1. Replaced by simpler solution.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Global.php

    r888 r891  
    1010include_once(dirname(__FILE__).'/../Application/UpdateTrace.php');
    1111include_once(dirname(__FILE__).'/PageEdit.php');
    12 require_once(dirname(__FILE__).'/../HTML/BBCodeParser2.php');
    1312
    1413// Back compatibility, will be removed
     
    134133  $DbRow = $DbResult->fetch_assoc();
    135134  $lang = $DbRow['Code'];
    136   $url = 'http://translate.google.cz/?sl=en&tl='.$lang.'&text='.$text;
     135  $url = 'https://translate.google.cz/?sl=en&tl='.$lang.'&text='.$text;
    137136
    138137  error_reporting(E_ALL ^ E_WARNING);
     
    786785    else return $_SERVER['PHP_SELF'];
    787786}
     787
     788function ShowBBcodes($text)
     789{
     790    // NOTE : I had to update this sample code with below line to prevent obvious attacks as pointed out by many users.
     791    // Always ensure that user inputs are scanned and filtered properly.
     792    $text  = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
     793
     794    // BBcode array
     795    $find = array(
     796      '~\[b\](.*?)\[/b\]~s',
     797      '~\[i\](.*?)\[/i\]~s',
     798      '~\[u\](.*?)\[/u\]~s',
     799      '~\[quote\](.*?)\[/quote\]~s',
     800      '~\[size=(.*?)\](.*?)\[/size\]~s',
     801      '~\[color=(.*?)\](.*?)\[/color\]~s',
     802      '~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
     803      '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s'
     804    );
     805
     806    // HTML tags to replace BBcode
     807    $replace = array(
     808      '<b>$1</b>',
     809      '<i>$1</i>',
     810      '<span style="text-decoration:underline;">$1</span>',
     811      '<pre>$1</'.'pre>',
     812      '<span style="font-size:$1px;">$2</span>',
     813      '<span style="color:$1;">$2</span>',
     814      '<a href="$1">$1</a>',
     815      '<img src="$1" alt="" />'
     816    );
     817
     818    // Replacing the BBcodes with corresponding HTML tags
     819    return preg_replace($find, $replace, $text);
     820}
Note: See TracChangeset for help on using the changeset viewer.