Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FunctionProvider.php
001 <?php
002
003 /**
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2022 The s9e authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Configurator\JavaScript;
009
010 use InvalidArgumentException;
011
012 class FunctionProvider
013 {
014 /**
015 * @param array Function name as keys, JavaScript source as values
016 */
017 public static $cache = [
018 'addslashes' => 'function(str)
019 {
020 return str.replace(/["\'\\\\]/g, \'\\\\$&\').replace(/\\u0000/g, \'\\\\0\');
021 }',
022 'dechex' => 'function(str)
023 {
024 return parseInt(str).toString(16);
025 }',
026 'intval' => 'function(str)
027 {
028 return parseInt(str) || 0;
029 }',
030 'ltrim' => 'function(str)
031 {
032 return str.replace(/^[ \\n\\r\\t\\0\\x0B]+/g, \'\');
033 }',
034 'mb_strtolower' => 'function(str)
035 {
036 return str.toLowerCase();
037 }',
038 'mb_strtoupper' => 'function(str)
039 {
040 return str.toUpperCase();
041 }',
042 'mt_rand' => 'function(min, max)
043 {
044 return (min + Math.floor(Math.random() * (max + 1 - min)));
045 }',
046 'rawurlencode' => 'function(str)
047 {
048 return encodeURIComponent(str).replace(
049 /[!\'()*]/g,
050 /**
051 * @param {string} c
052 */
053 function(c)
054 {
055 return \'%\' + c.charCodeAt(0).toString(16).toUpperCase();
056 }
057 );
058 }',
059 'rtrim' => 'function(str)
060 {
061 return str.replace(/[ \\n\\r\\t\\0\\x0B]+$/g, \'\');
062 }',
063 'str_rot13' => 'function(str)
064 {
065 return str.replace(
066 /[a-z]/gi,
067 function(c)
068 {
069 return String.fromCharCode(c.charCodeAt(0) + ((c.toLowerCase() < \'n\') ? 13 : -13));
070 }
071 );
072 }',
073 'stripslashes' => 'function(str)
074 {
075 // NOTE: this will not correctly transform \\0 into a NULL byte. I consider this a feature
076 // rather than a bug. There\'s no reason to use NULL bytes in a text.
077 return str.replace(/\\\\([\\s\\S]?)/g, \'\\\\1\');
078 }',
079 'strrev' => 'function(str)
080 {
081 return str.split(\'\').reverse().join(\'\');
082 }',
083 'strtolower' => 'function(str)
084 {
085 return str.toLowerCase();
086 }',
087 'strtotime' => 'function(str)
088 {
089 return Date.parse(str) / 1000;
090 }',
091 'strtoupper' => 'function(str)
092 {
093 return str.toUpperCase();
094 }',
095 'trim' => 'function(str)
096 {
097 return str.replace(/^[ \\n\\r\\t\\0\\x0B]+/g, \'\').replace(/[ \\n\\r\\t\\0\\x0B]+$/g, \'\');
098 }',
099 'ucfirst' => 'function(str)
100 {
101 return str[0].toUpperCase() + str.substring(1);
102 }',
103 'ucwords' => 'function(str)
104 {
105 return str.replace(
106 /(?:^|\\s)[a-z]/g,
107 function(m)
108 {
109 return m.toUpperCase()
110 }
111 );
112 }',
113 'urldecode' => 'function(str)
114 {
115 return decodeURIComponent("" + str);
116 }',
117 'urlencode' => 'function(str)
118 {
119 return encodeURIComponent(str);
120 }'
121 ];
122
123 /**
124 * Return a function's source from the cache or the filesystem
125 *
126 * @param string $funcName Function's name
127 * @return string Function's source
128 */
129 public static function get($funcName)
130 {
131 if (isset(self::$cache[$funcName]))
132 {
133 return self::$cache[$funcName];
134 }
135 if (preg_match('(^[a-z_0-9]+$)D', $funcName))
136 {
137 $filepath = __DIR__ . '/functions/' . $funcName . '.js';
138 if (file_exists($filepath))
139 {
140 return file_get_contents($filepath);
141 }
142 }
143 throw new InvalidArgumentException("Unknown function '" . $funcName . "'");
144 }
145 }