Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

new_normalizer.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 5.35 KiB


001  <?php
002  /**
003  *
004  * @package install
005  * @version $Id$
006  * @copyright (c) 2007 phpBB Group
007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
008  *
009  */
010   
011  /**
012  * @ignore
013  */
014  if (!defined('IN_PHPBB'))
015  {
016      exit;
017  }
018   
019  /**
020  * A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
021  * to be in NFC (Normalization Form Composition).
022  *
023  * @param    mixed    $strings    a string or an array of strings to normalize
024  * @return    mixed                the normalized content, preserving array keys if array given.
025  */
026  function utf8_new_normalize_nfc($strings)
027  {
028      if (empty($strings))
029      {
030          return $strings;
031      }
032   
033      if (!is_array($strings))
034      {
035          utf_new_normalizer::nfc($strings);
036      }
037      else if (is_array($strings))
038      {
039          foreach ($strings as $key => $string)
040          {
041              if (is_array($string))
042              {
043                  foreach ($string as $_key => $_string)
044                  {
045                      utf_new_normalizer::nfc($strings[$key][$_key]);
046                  }
047              }
048              else
049              {
050                  utf_new_normalizer::nfc($strings[$key]);
051              }
052          }
053      }
054   
055      return $strings;
056  }
057   
058  class utf_new_normalizer
059  {
060      /**
061      * Validate, cleanup and normalize a string
062      *
063      * The ultimate convenience function! Clean up invalid UTF-8 sequences,
064      * and convert to Normal Form C, canonical composition.
065      *
066      * @param    string    &$str    The dirty string
067      * @return    string            The same string, all shiny and cleaned-up
068      */
069      function cleanup(&$str)
070      {
071          // The string below is the list of all autorized characters, sorted by frequency in latin text
072          $pos = strspn($str, "\x20\x65\x69\x61\x73\x6E\x74\x72\x6F\x6C\x75\x64\x5D\x5B\x63\x6D\x70\x27\x0A\x67\x7C\x68\x76\x2E\x66\x62\x2C\x3A\x3D\x2D\x71\x31\x30\x43\x32\x2A\x79\x78\x29\x28\x4C\x39\x41\x53\x2F\x50\x22\x45\x6A\x4D\x49\x6B\x33\x3E\x35\x54\x3C\x44\x34\x7D\x42\x7B\x38\x46\x77\x52\x36\x37\x55\x47\x4E\x3B\x4A\x7A\x56\x23\x48\x4F\x57\x5F\x26\x21\x4B\x3F\x58\x51\x25\x59\x5C\x09\x5A\x2B\x7E\x5E\x24\x40\x60\x7F\x0D");
073          $len = strlen($str);
074   
075          if ($pos == $len)
076          {
077              // ASCII strings with no special chars return immediately
078              return;
079          }
080   
081          // Note: we do not check for $GLOBALS['utf_canonical_decomp']. It is assumed they are always loaded together
082          if (!isset($GLOBALS['utf_nfc_qc']))
083          {
084              global $phpbb_root_path, $phpEx;
085              include($phpbb_root_path . 'includes/utf/data/utf_nfc_qc.' . $phpEx);
086          }
087   
088          if (!isset($GLOBALS['utf_canonical_decomp']))
089          {
090              global $phpbb_root_path, $phpEx;
091              include($phpbb_root_path . 'includes/utf/data/utf_canonical_decomp.' . $phpEx);
092          }
093   
094          // Replace any byte in the range 0x00..0x1F, except for \r, \n and \t
095          // We replace those characters with a 0xFF byte, which is illegal in UTF-8 and will in turn be replaced with a UTF replacement char
096          $str = strtr(
097              $str,
098              "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
099              "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
100          );
101   
102          $str = utf_new_normalizer::recompose($str, $pos, $len, $GLOBALS['utf_nfc_qc'], $GLOBALS['utf_canonical_decomp']);
103      }
104   
105      /**
106      * Validate and normalize a UTF string to NFC
107      *
108      * @param    string    &$str    Unchecked UTF string
109      * @return    string            The string, validated and in normal form
110      */
111      function nfc(&$str)
112      {
113          $pos = strspn($str, UTF8_ASCII_RANGE);
114          $len = strlen($str);
115   
116          if ($pos == $len)
117          {
118              // ASCII strings return immediately
119              return;
120          }
121   
122          if (!isset($GLOBALS['utf_nfc_qc']))
123          {
124              global $phpbb_root_path, $phpEx;
125              include($phpbb_root_path . 'includes/utf/data/utf_nfc_qc.' . $phpEx);
126          }
127   
128          if (!isset($GLOBALS['utf_canonical_decomp']))
129          {
130              global $phpbb_root_path, $phpEx;
131              include($phpbb_root_path . 'includes/utf/data/utf_canonical_decomp.' . $phpEx);
132          }
133   
134          $str = utf_new_normalizer::recompose($str, $pos, $len, $GLOBALS['utf_nfc_qc'], $GLOBALS['utf_canonical_decomp']);
135      }
136   
137      /**
138      * Validate and normalize a UTF string to NFKC
139      *
140      * @param    string    &$str    Unchecked UTF string
141      * @return    string            The string, validated and in normal form
142      */
143      function nfkc(&$str)
144      {
145          $pos = strspn($str, UTF8_ASCII_RANGE);
146          $len = strlen($str);
147   
148          if ($pos == $len)
149          {
150              // ASCII strings return immediately
151              return;
152          }
153   
154          if (!isset($GLOBALS['utf_nfkc_qc']))
155          {
156              global $phpbb_root_path, $phpEx;
157              include($phpbb_root_path . 'includes/utf/data/utf_nfkc_qc.' . $phpEx);
158          }
159   
160          if (!isset($GLOBALS['utf_compatibility_decomp']))
161          {
162              global $phpbb_root_path, $phpEx;
163              include($phpbb_root_path . 'includes/utf/data/utf_compatibility_decomp.' . $phpEx);
164          }
165   
166          $str = utf_new_normalizer::recompose($str, $pos, $len, $GLOBALS['utf_nfkc_qc'], $GLOBALS['utf_compatibility_decomp']);
167      }
168   
169      /**
170      * Recompose a UTF string
171      *
172      * @param    string    $str            Unchecked UTF string
173      * @param    integer    $pos            Position of the first UTF char (in bytes)
174      * @param    integer    $len            Length of the string (in bytes)
175      * @param    array    &$qc            Quick-check array, passed by reference but never modified
176      * @param    array    &$decomp_map    Decomposition mapping, passed by reference but never modified
177      * @return    string                    The string, validated and recomposed
178      *
179      * @access    private
180      */
181      function recompose($str, $pos, $len, &$qc, &$decomp_map)
182      {
183          global $utf_canonical_comp;
184   
185          // Load the canonical composition table
186          if (!isset($utf_canonical_comp))
187          {
188              global $phpbb_root_path, $phpEx;
189              include($phpbb_root_path . 'includes/utf/data/utf_canonical_comp.' . $phpEx);
190          }
191   
192          return utf_normalizer::recompose($str, $pos, $len, $qc, $decomp_map);
193      }
194  }
195   
196  ?>