Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for phpPlatonLib/Platon/Platon.php between version 1.42 and 1.43

version 1.42, 2017/11/08 00:34:18 version 1.43, 2017/11/08 01:09:07
Line 25 
Line 25 
  * @access      public   * @access      public
  */   */
   
 /* $Platon: phpPlatonLib/Platon/Platon.php,v 1.41 2017/11/08 00:33:44 nepto Exp $ */  /* $Platon: phpPlatonLib/Platon/Platon.php,v 1.42 2017/11/08 00:34:18 nepto Exp $ */
   
 class Platon  class Platon
 {  {
Line 612  class Platon
Line 612  class Platon
         return $number;          return $number;
     } /* }}} */      } /* }}} */
   
           private static $_htmlspecialchars_encoding = '';
   
       /**
        * Set charset/encoding for out Platon::htmlspecialchars()
        *
        * @param   string  $encoding  encoding, for more info
        *                             see _deduct_htmlspecialchars_encoding()
        * @return  boolean            always true
        */
       static function htmlspecialchars_encoding($encoding) /* {{{ */
           {
                   Platon::$_htmlspecialchars_encoding = $encoding;
           return true;
           } /* }}} */
   
       /**
        * Encode special HTML characters based on encoding and PHP version
        *
        * @param   string  $string    string to encode
        * @param   string  $encoding  encoding to use (use default when empty)
        * @return  string             HTML encoded string
        */
           static function htmlspecialchars($string, $encoding = '') /* {{{ */
           {
           // no default encoding maps to no special transformation
           static $map = array('' => '');
           if (strlen($encoding) <= 0) {
               $encoding = Platon::$_htmlspecialchars_encoding;
           }
           if (! array_key_exists($encoding, $map)) {
                       if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 4) {
                   $map[$encoding]['flags']    = ENT_COMPAT | ENT_HTML401;
                   $map[$encoding]['encoding'] = Platon::_deduct_htmlspecialchars_encoding($encoding);
               } elseif ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 6)
                       || PHP_MAJOR_VERSION >= 7) {
                   $map[$encoding]['flags']    = ENT_QUOTES | ENT_HTML5 | ENT_DISALLOWED | ENT_SUBSTITUTE;
                   $map[$encoding]['encoding'] = Platon::_deduct_htmlspecialchars_encoding($encoding);
               } else {
                   $map[$encoding] = ''; // no special htmlspecialchars()
               }
           }
           if (is_array($map[$encoding])) {
               return htmlspecialchars($string,
                       $map[$encoding]['flags'],
                       $map[$encoding]['encoding']);
           }
                   // default
                   return htmlspecialchars($string);
           } /* }}} */
   
           static function _deduct_htmlspecialchars_encoding($encoding) /* {{{ */
           {
                   // List of supported charsets http://php.net/manual/en/function.htmlspecialchars.php
                   $allowed = array(
                           'ISO-8859-1', 'ISO8859-1',                                                      // Western European, Latin-1
                           'ISO-8859-5', 'ISO8859-5',                                                      // Little used cyrillic charset (Latin/Cyrillic)
                           'ISO-8859-15', 'ISO8859-15',                                            // Western European, Latin-9. Adds the Euro sign and others
                           'UTF-8',                                                                                        // ASCII compatible multi-byte 8-bit Unicode
                           'cp866', 'ibm866', '866',                                                       // DOS-specific Cyrillic charset
                           'cp1251', 'Windows-1251', 'win-1251', '1251',           // Windows-specific Cyrillic charset
                           'cp1252', 'Windows-1252', '1252',                                       // Windows specific charset for Western European
                           'KOI8-R', 'koi8-ru', 'koi8r',                                           // Russian
                           'BIG5', '950',                                                                          // Traditional Chinese, mainly used in Taiwan
                           'GB2312', '936',                                                                        // Simplified Chinese, national standard character set
                           'BIG5-HKSCS',                                                                           // Big5 with Hong Kong extensions, Traditional Chinese
                           'Shift_JIS', 'SJIS', 'SJIS-win', 'cp932', '932',        // Japanese
                           'EUC-JP', 'EUCJP', 'eucJP-win',                                         // Japanese
                           'MacRoman',                                                                                     // Charset that was used by Mac OS.
                           ''  // An empty string activates detection from script encoding (Zend multibyte),
                   // default_charset and current locale (see nl_langinfo() and setlocale()), in this order. Not recommended.
                   );
           if (in_array($encoding, $allowed)) {
               return $encoding;
           }
           $encoding_upper = strtoupper($encoding);
           foreach ($allowed as $allow) {
               if (strtoupper($allow) == $encoding_upper) {
                   return $allow;
               }
           }
           for ($len = strlen($encoding) - 1; $len > 0; $len--) {
               $encoding_prefix = substr($encoding_upper, 0, $len);
               foreach ($allowed as $allow) {
                   if (strtoupper(substr($allow, 0, min($len, strlen($allow)))) == $encoding_prefix) {
                       return $allow;
                   }
               }
           }
           return null;
       } /* }}} */
   
     /**      /**
      * HTML special characters substitution with replacing space for '&nbsp;'.       * HTML special characters substitution with replacing space for '&nbsp;'.
      *       *
Line 620  class Platon
Line 711  class Platon
      */       */
     static function htmlspecialchars2($str) /* {{{ */      static function htmlspecialchars2($str) /* {{{ */
     {      {
         return str_replace(' ', '&nbsp;', htmlspecialchars($str));          return str_replace(' ', '&nbsp;', Platon::htmlspecialchars($str));
     } /* }}} */      } /* }}} */
   
     /*      /*

Legend:
Removed from v.1.42  
changed lines
  Added in v.1.43

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top