Passed
Push — master ( a4754c...e0c6ec )
by Nazar
05:32
created

__htmlpurifier_autoload()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 2
1
<?php
2
/**
3
 * @package   CleverStyle Framework
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2011-2017, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
/**
9
 * Base system functions, do not edit this file, or make it very carefully
10
 * otherwise system workability may be broken
11
 */
12
use
13
	cs\Cache,
14
	cs\Config,
15
	cs\HTMLPurifier_Filter_iframe_sandbox,
16
	cs\Language,
17
	cs\Page;
18
19
/**
20
 * @param string $file
21
 *
22
 * @return array
23
 */
24
function __classes_get_from_cache ($file) {
25 297
	return defined('CACHE') && file_exists(CACHE."/classes/$file") ? file_get_json(CACHE."/classes/$file") : [];
26
}
27
28
/**
29
 * @param string $file
30
 * @param array  $content
31
 */
32
function __classes_put_into_cache ($file, $content) {
33 201
	if (defined('CACHE') && is_dir(CACHE)) {
34
		/** @noinspection MkdirRaceConditionInspection */
35 54
		@mkdir(CACHE.'/classes', 0770);
36 54
		file_put_json(CACHE."/classes/$file", $content);
37
	}
38 201
}
39
40
/**
41
 * Clean cache of classes autoload and customization
42
 */
43
function __classes_clean_cache () {
44
	@unlink(CACHE.'/classes/autoload');
45
	@unlink(CACHE.'/classes/aliases');
46
	@unlink(CACHE.'/classes/modified');
47
}
48
49
/**
50
 * Auto Loading of classes
51
 */
52 307
spl_autoload_register(
53
	function ($class) {
54 297
		static $cache, $aliases;
55 297
		if (!isset($cache)) {
56 297
			$cache   = __classes_get_from_cache('autoload');
57 297
			$aliases = __classes_get_from_cache('aliases');
58
		}
59 297
		if (isset($aliases[$class])) {
60 3
			spl_autoload_call($aliases[$class]);
61 3
			return class_exists($class, false) || (class_exists($aliases[$class], false) && class_alias($aliases[$class], $class));
62
		}
63 297
		if (isset($cache[$class])) {
64 147
			if ($cache[$class]) {
65 144
				require $cache[$class];
66
			}
67 147
			return (bool)$cache[$class];
68
		}
69 186
		$prepared_class_name = ltrim($class, '\\');
70 186
		if (strpos($prepared_class_name, 'cs\\') === 0) {
71 183
			$prepared_class_name = substr($prepared_class_name, 3);
72
		}
73 186
		$prepared_class_name = explode('\\', $prepared_class_name);
74 186
		$namespace           = count($prepared_class_name) > 1 ? implode('/', array_slice($prepared_class_name, 0, -1)) : '';
75 186
		$class_name          = array_pop($prepared_class_name);
76 186
		$cache[$class]       = false;
77
		/**
78
		 * Try to load classes from different places. If not found in one place - try in another.
79
		 */
80
		if (
81 186
			file_exists($file = CORE."/classes/$namespace/$class_name.php") ||    //Core classes
82 147
			file_exists($file = CORE."/thirdparty/$namespace/$class_name.php") || //Third party classes
83 141
			file_exists($file = CORE."/traits/$namespace/$class_name.php") ||     //Core traits
84 45
			file_exists($file = CORE."/drivers/$namespace/$class_name.php") ||    //Core drivers
85 186
			file_exists($file = MODULES."/../$namespace/$class_name.php")         //Classes in modules
86
		) {
87 186
			$cache[$class] = realpath($file);
88 186
			__classes_put_into_cache('autoload', $cache);
89 186
			require $file;
90 186
			return true;
91
		}
92 12
		__classes_put_into_cache('autoload', $cache);
93
		// Processing components aliases
94 12
		if (strpos($namespace, 'modules') === 0) {
95 3
			$Config      = Config::instance();
96 3
			$directories = [];
97 3
			foreach ($Config->components['modules'] ?: [] as $module_name => $module_data) {
98 3
				if ($module_data['active'] == Config\Module_Properties::UNINSTALLED) {
99 3
					continue;
100
				}
101 3
				$directories[] = MODULES."/$module_name";
102
			}
103 3
			$class_exploded = explode('\\', $class);
104 3
			foreach ($directories as $directory) {
105 3
				if (file_exists("$directory/meta.json")) {
106 3
					$meta = file_get_json("$directory/meta.json") + ['provide' => []];
107 3
					if ($class_exploded[2] != $meta['package'] && in_array($class_exploded[2], (array)$meta['provide'])) {
108 3
						$class_exploded[2] = $meta['package'];
109 3
						$alias             = implode('\\', $class_exploded);
110 3
						$aliases[$class]   = $alias;
111 3
						__classes_put_into_cache('aliases', $aliases);
112 3
						spl_autoload_call($alias);
113 3
						return class_exists($class, false) || (class_exists($alias, false) && class_alias($alias, $class));
114
					}
115
				}
116
			}
117
		}
118 12
		return false;
119 307
	}
120
);
121
122
/**
123
 * Get or set modified classes (used in Singleton trait)
124
 *
125
 * @param array|null $updated_modified_classes
126
 *
127
 * @return array
128
 */
129
function modified_classes ($updated_modified_classes = null) {
130 219
	static $modified_classes;
131 219
	if (!isset($modified_classes)) {
132 219
		$modified_classes = __classes_get_from_cache('modified');
133
	}
134 219
	if ($updated_modified_classes) {
135 105
		$modified_classes = $updated_modified_classes;
136 105
		__classes_put_into_cache('modified', $modified_classes);
137
	}
138 219
	return $modified_classes;
139
}
140
141
/**
142
 * Easy getting of translations
143
 *
144
 * @param string  $item
145
 * @param mixed[] $arguments There can be any necessary number of arguments here
146
 *
147
 * @return string
148
 */
149
function __ ($item, ...$arguments) {
150 3
	$L = Language::instance();
151 3
	if (func_num_args() > 1) {
152 3
		return $L->format($item, ...$arguments);
0 ignored issues
show
Bug introduced by
$arguments is expanded, but the parameter $arguments of cs\Language::format() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

152
		return $L->format($item, /** @scrutinizer ignore-type */ ...$arguments);
Loading history...
153
	} else {
154 3
		return $L->$item;
155
	}
156
}
157
158
/**
159
 * Public cache cleaning
160
 *
161
 * @return bool
162
 */
163
function clean_public_cache () {
164
	$ok   = true;
165
	$list = get_files_list(PUBLIC_CACHE, false, 'fd', true, true, 'name|desc');
0 ignored issues
show
Bug introduced by
'name|desc' of type string is incompatible with the type boolean expected by parameter $sort of get_files_list(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

165
	$list = get_files_list(PUBLIC_CACHE, false, 'fd', true, true, /** @scrutinizer ignore-type */ 'name|desc');
Loading history...
166
	foreach ($list as $item) {
167
		if (is_writable($item)) {
168
			is_dir($item) ? @rmdir_recursive($item) : @unlink($item);
169
		} else {
170
			$ok = false;
171
		}
172
	}
173
	return $ok;
174
}
175
176
/**
177
 * Formatting of time in seconds to human-readable form
178
 *
179
 * @param int $time Time in seconds
180
 *
181
 * @return string
182
 */
183
function format_time ($time) {
184 3
	if (!is_numeric($time)) {
185 3
		return $time;
186
	}
187 3
	$L     = Language::instance();
188 3
	$res   = [];
189
	$units = [
190 3
		60 * 60 * 24 * 365 => 'y',
191
		60 * 60 * 24 * 30  => 'M',
192
		60 * 60 * 24       => 'd',
193
		60 * 60            => 'h',
194
		60                 => 'm',
195
		1                  => 's'
196
	];
197 3
	foreach ($units as $time_frame => $key) {
198 3
		if ($time >= $time_frame) {
199 3
			$time_full = floor($time / $time_frame);
200 3
			$time      -= $time_full * $time_frame;
201 3
			$res[]     = $L->time($time_full, $key);
0 ignored issues
show
Bug introduced by
$time_full of type double is incompatible with the type integer expected by parameter $in of cs\Language::time(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

201
			$res[]     = $L->time(/** @scrutinizer ignore-type */ $time_full, $key);
Loading history...
202
		}
203
	}
204 3
	return implode(' ', $res);
205
}
206
207
/**
208
 * Formatting of data size in bytes to human-readable form
209
 *
210
 * @param int       $size
211
 * @param false|int $round
212
 *
213
 * @return string
214
 */
215
function format_filesize ($size, $round = false) {
216 3
	if (!is_numeric($size)) {
217 3
		return $size;
218
	}
219 3
	$L     = Language::prefix('system_filesize_');
220
	$units = [
221 3
		1024 * 1024 * 1024 * 1024 => $L->TiB,
0 ignored issues
show
Bug Best Practice introduced by
The property TiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
222 3
		1024 * 1024 * 1024        => $L->GiB,
0 ignored issues
show
Bug Best Practice introduced by
The property GiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
223 3
		1024 * 1024               => $L->MiB,
0 ignored issues
show
Bug Best Practice introduced by
The property MiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
224 3
		1024                      => $L->KiB,
0 ignored issues
show
Bug Best Practice introduced by
The property KiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
225 3
		0                         => $L->Bytes
0 ignored issues
show
Bug Best Practice introduced by
The property Bytes does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
226
	];
227 3
	foreach ($units as $size_frame => $unit) {
228 3
		if ($size >= $size_frame) {
229 3
			$size /= max($size_frame, 1);
230 3
			if ($round) {
231 3
				$size = round($size, $round);
232
			}
233 3
			return "$size $unit";
234
		}
235
	}
236
}
237
238
/**
239
 * Get list of timezones
240
 *
241
 * @return array
242
 */
243
function get_timezones_list () {
244 12
	$timezones = [];
245 12
	foreach (timezone_identifiers_list() as $timezone) {
246 12
		$offset          = (new DateTimeZone($timezone))->getOffset(new DateTime);
247 12
		$key             = (39600 + $offset).$timezone;
248 12
		$sign            = ($offset < 0 ? '-' : '+');
249 12
		$hours           = str_pad(floor(abs($offset / 3600)), 2, 0, STR_PAD_LEFT);
250 12
		$minutes         = str_pad(abs(($offset % 3600) / 60), 2, 0, STR_PAD_LEFT);
251 12
		$timezones[$key] = [
252 12
			'key'   => str_replace('_', ' ', $timezone)." ($sign$hours:$minutes)",
253 12
			'value' => $timezone
254
		];
255
	}
256 12
	ksort($timezones, SORT_NATURAL);
257 12
	return array_column($timezones, 'value', 'key');
258
}
259
260
/**
261
 * String representation of HTTP status code
262
 *
263
 * @param int $code
264
 *
265
 * @return null|string
266
 */
267
function status_code_string ($code) {
268
	$code_to_string = [
269 21
		201 => '201 Created',
270
		202 => '202 Accepted',
271
		301 => '301 Moved Permanently',
272
		302 => '302 Found',
273
		303 => '303 See Other',
274
		307 => '307 Temporary Redirect',
275
		400 => '400 Bad Request',
276
		403 => '403 Forbidden',
277
		404 => '404 Not Found',
278
		405 => '405 Method Not Allowed',
279
		409 => '409 Conflict',
280
		429 => '429 Too Many Requests',
281
		500 => '500 Internal Server Error',
282
		501 => '501 Not Implemented',
283
		503 => '503 Service Unavailable'
284
	];
285 21
	return @$code_to_string[$code];
286
}
287
288
/**
289
 * Pages navigation based on links
290
 *
291
 * @param int             $page       Current page
292
 * @param int             $total      Total pages number
293
 * @param callable|string $url        if string - it will be formatted with sprintf with one parameter - page number<br>
294
 *                                    if callable - one parameter will be given, callable should return url string
295
 * @param bool            $head_links If <b>true</b> - links with rel="prev" and rel="next" will be added
296
 *
297
 * @return bool|string <b>false</b> if single page, otherwise string, set of navigation links
298
 */
299
function pages ($page, $total, $url, $head_links = false) {
300 3
	if ($total == 1) {
301 3
		return false;
302
	}
303 3
	$Page             = Page::instance();
304 3
	$original_url     = $url;
305 3
	$base_url         = Config::instance()->base_url();
306
	$url              = function ($page) use ($original_url, $base_url) {
307 3
		$href = is_callable($original_url) ? $original_url($page) : sprintf($original_url, $page);
0 ignored issues
show
Bug introduced by
It seems like $original_url can also be of type callable; however, parameter $format of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

307
		$href = is_callable($original_url) ? $original_url($page) : sprintf(/** @scrutinizer ignore-type */ $original_url, $page);
Loading history...
308 3
		if (is_string($href) && strpos($href, 'http') !== 0) {
309 3
			$href = ltrim($href, '/');
310 3
			$href = "$base_url/$href";
311
		}
312 3
		return $href;
313 3
	};
314 3
	$output           = [];
315
	$render_page_item = function ($i) use ($Page, $page, $url, $head_links, &$output) {
316 3
		$href = $url($i);
317 3
		if ($head_links) {
318
			switch ($i) {
319 3
				case $page - 1:
320 3
					$Page->link(['href' => $href, 'rel' => 'prev']);
321 3
					break;
322 3
				case $page + 1:
323 3
					$Page->link(['href' => $href, 'rel' => 'next']);
324 3
					break;
325 3
				case $page:
326 3
					$Page->canonical_url($href);
327 3
					break;
328
			}
329
		}
330 3
		$output[] = [
331 3
			h::a(
0 ignored issues
show
Bug introduced by
The method a() does not exist on h. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

331
			h::/** @scrutinizer ignore-call */ 
332
      a(
Loading history...
332 3
				$i,
333
				[
334 3
					'href' => $i == $page ? false : $href
335
				]
336
			),
337
			[
338 3
				'primary' => $i == $page
339
			]
340
		];
341 3
	};
342 3
	if ($total <= 11) {
343 3
		array_map($render_page_item, range(1, $total));
344
	} else {
345
		$empty = [
346 3
			h::a(
347 3
				'...',
348
				[
349 3
					'disabled' => true
350
				]
351
			)
352
		];
353 3
		if ($page <= 6) {
354 3
			array_map($render_page_item, range(1, 7));
355 3
			$output[] = $empty;
356 3
			array_map($render_page_item, range($total - 2, $total));
357 3
		} elseif ($page >= $total - 5) {
358 3
			array_map($render_page_item, range(1, 3));
359 3
			$output[] = $empty;
360 3
			array_map($render_page_item, range($total - 6, $total));
361
		} else {
362 3
			array_map($render_page_item, range(1, 2));
363 3
			$output[] = $empty;
364 3
			array_map($render_page_item, range($page - 2, $page + 2));
365 3
			$output[] = $empty;
366 3
			array_map($render_page_item, range($total - 1, $total));
367
		}
368
	}
369 3
	return h::cs_link_button($output);
0 ignored issues
show
Bug introduced by
The method cs_link_button() does not exist on h. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

369
	return h::/** @scrutinizer ignore-call */ cs_link_button($output);
Loading history...
370
}
371
372
/**
373
 * Pages navigation based on buttons (for search forms, etc.)
374
 *
375
 * @param int                  $page  Current page
376
 * @param int                  $total Total pages number
377
 * @param bool|callable|string $url   Adds <i>formaction</i> parameter to every button<br>
378
 *                                    if <b>false</b> - only form parameter <i>page</i> will we added<br>
379
 *                                    if string - it will be formatted with sprintf with one parameter - page number<br>
380
 *                                    if callable - one parameter will be given, callable should return url string
381
 *
382
 * @return false|string                        <b>false</b> if single page, otherwise string, set of navigation buttons
383
 */
384
function pages_buttons ($page, $total, $url = false) {
385 3
	if ($total == 1) {
386 3
		return false;
387
	}
388 3
	if (!is_callable($url)) {
389 3
		$original_url = $url;
390
		$url          = function ($page) use ($original_url) {
391 3
			return sprintf($original_url, $page);
0 ignored issues
show
Bug introduced by
It seems like $original_url can also be of type callable; however, parameter $format of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

391
			return sprintf(/** @scrutinizer ignore-type */ $original_url, $page);
Loading history...
392 3
		};
393
	}
394 3
	$output           = [];
395
	$render_page_item = function ($i) use ($page, $url, &$output) {
396 3
		$output[] = [
397 3
			h::button(
398 3
				$i,
399
				[
400 3
					'name'       => 'page',
401 3
					'formaction' => $i == $page || $url === false ? false : $url($i),
402 3
					'value'      => $i == $page ? false : $i,
403 3
					'type'       => $i == $page ? 'button' : 'submit'
404
				]
405
			),
406
			[
407 3
				'primary' => $i == $page
408
			]
409
		];
410 3
	};
411 3
	if ($total <= 11) {
412 3
		array_map($render_page_item, range(1, $total));
413
	} else {
414
		$empty = [
415 3
			h::button(
416 3
				'...',
417
				[
418 3
					'type' => 'button',
419
					'disabled'
420
				]
421
			)
422
		];
423 3
		if ($page <= 6) {
424 3
			array_map($render_page_item, range(1, 7));
425 3
			$output[] = $empty;
426 3
			array_map($render_page_item, range($total - 2, $total));
427 3
		} elseif ($page >= $total - 5) {
428 3
			array_map($render_page_item, range(1, 3));
429 3
			$output[] = $empty;
430 3
			array_map($render_page_item, range($total - 6, $total));
431
		} else {
432 3
			array_map($render_page_item, range(1, 2));
433 3
			$output[] = $empty;
434 3
			array_map($render_page_item, range($page - 2, $page + 2));
435 3
			$output[] = $empty;
436 3
			array_map($render_page_item, range($total - 1, $total));
437
		}
438
	}
439 3
	return h::cs_button($output);
0 ignored issues
show
Bug introduced by
The method cs_button() does not exist on h. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

439
	return h::/** @scrutinizer ignore-call */ cs_button($output);
Loading history...
440
}
441
442
/**
443
 * Checks whether specified functionality available or not
444
 *
445
 * @param string|string[] $functionality One functionality or array of them
446
 *
447
 * @return bool `true` if all functionality available, `false` otherwise
448
 */
449
function functionality ($functionality) {
450 3
	if (is_array($functionality)) {
451 3
		return array_map_arguments_bool('functionality', $functionality);
452
	}
453 3
	$all = Cache::instance()->get(
454 3
		'functionality',
455
		function () {
456 3
			$functionality = [];
457 3
			$Config        = Config::instance();
458 3
			foreach (array_keys($Config->components['modules']) as $module) {
459 3
				if (!$Config->module($module)->enabled() || !file_exists(MODULES."/$module/meta.json")) {
460 3
					continue;
461
				}
462 3
				$functionality[] = [$module];
463 3
				$meta            = file_get_json(MODULES."/$module/meta.json");
464 3
				if (isset($meta['provide'])) {
465 3
					$functionality[] = (array)$meta['provide'];
466
				}
467
			}
468 3
			return array_merge(...$functionality);
0 ignored issues
show
Bug introduced by
$functionality is expanded, but the parameter $array1 of array_merge() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

468
			return array_merge(/** @scrutinizer ignore-type */ ...$functionality);
Loading history...
469 3
		}
470
	);
471 3
	return in_array($functionality, $all);
0 ignored issues
show
Bug introduced by
It seems like $all can also be of type false; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

471
	return in_array($functionality, /** @scrutinizer ignore-type */ $all);
Loading history...
472
}
473
474
/**
475
 * XSS Attack Protection. Returns secure string using several types of filters
476
 *
477
 * @param string|string[] $in     HTML code
478
 * @param bool|string     $html   <b>text</b> - text at output (default)<br>
479
 *                                <b>true</b> - processed HTML at output<br>
480
 *                                <b>false</b> - HTML tags will be deleted
481
 * @param bool            $iframe Whether to allow iframes without inner content (for example, video from youtube)<br>
482
 *                                Works only if <i>$html === true</i>
483
 *
484
 * @return string|string[]
485
 */
486
function xap ($in, $html = 'text', $iframe = false) {
487 78
	static $purifier, $purifier_iframe, $purifier_no_tags;
488 78
	if (is_array($in)) {
489 51
		return array_map_arguments('xap', $in, $html, $iframe);
0 ignored issues
show
Bug introduced by
$html of type string|boolean is incompatible with the type array expected by parameter $additional_arguments of array_map_arguments(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

489
		return array_map_arguments('xap', $in, /** @scrutinizer ignore-type */ $html, $iframe);
Loading history...
Bug introduced by
$iframe of type boolean is incompatible with the type array expected by parameter $additional_arguments of array_map_arguments(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

489
		return array_map_arguments('xap', $in, $html, /** @scrutinizer ignore-type */ $iframe);
Loading history...
490
	}
491
	/**
492
	 * Text mode
493
	 */
494 78
	if ($html === 'text') {
495 72
		return htmlspecialchars($in, ENT_NOQUOTES | ENT_HTML5 | ENT_DISALLOWED | ENT_SUBSTITUTE | ENT_HTML5);
496
	}
497 24
	if (!isset($purifier)) {
498
		$config_array = [
499 24
			'HTML.Doctype'         => 'HTML 4.01 Transitional',
500
			'Attr.EnableID'        => true,
501
			'Attr.ID.HTML5'        => true,
502
			'Attr.IDPrefix'        => 'content-',
503
			'CSS.MaxImgLength'     => null,
504
			'Cache.DefinitionImpl' => null,
505
			'Output.Newline'       => "\n",
506
			'URI.Munge'            => 'redirect/%s'
507
		];
508
509 24
		$config = HTMLPurifier_Config::createDefault();
0 ignored issues
show
Bug introduced by
The type HTMLPurifier_Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
510 24
		$config->loadArray($config_array);
511 24
		$purifier = new HTMLPurifier($config_array);
0 ignored issues
show
Bug introduced by
The type HTMLPurifier was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
512
513 24
		$config_no_tags = HTMLPurifier_Config::createDefault();
514 24
		$config_no_tags->loadArray($config_array);
515 24
		$config_no_tags->set('HTML.AllowedElements', []);
516 24
		$purifier_no_tags = new HTMLPurifier($config_no_tags);
517
518 24
		$config_iframe = HTMLPurifier_Config::createDefault();
519 24
		$config_iframe->loadArray($config_array);
520 24
		$config_iframe->set('Filter.Custom', [new HTMLPurifier_Filter_iframe_sandbox]);
521 24
		$purifier_iframe = new HTMLPurifier($config_iframe);
522
	}
523 24
	if ($html === false) {
524 3
		return $purifier_no_tags->purify($in);
525
	}
526 24
	if ($iframe) {
527 3
		return $purifier_iframe->purify($in);
528
	} else {
529 24
		return $purifier->purify($in);
530
	}
531
}
532
533
/**
534
 * @param string $class
535
 *
536
 * @return bool
537
 */
538
function __htmlpurifier_autoload ($class) {
539 297
	$class = ltrim($class, '\\');
540 297
	if (strpos($class, 'HTMLPurifier_') === 0) {
541 24
		spl_autoload_unregister('__htmlpurifier_autoload');
542 24
		Phar::loadPhar(__DIR__.'/thirdparty/htmlpurifier.phar');
543 24
		require_once 'phar://htmlpurifier.phar/HTMLPurifier.standalone.php';
544 24
		return true;
545
	}
546 294
}
547
548 307
spl_autoload_register('__htmlpurifier_autoload', true, true);
549
550
/**
551
 * @param callable $func
552
 * @param array    $arguments
553
 * @param array    $additional_arguments
554
 *
555
 * @return array
556
 */
557
function array_map_arguments (callable $func, array $arguments, ...$additional_arguments) {
558 51
	foreach ($arguments as &$a) {
559 51
		$a = $func($a, ...$additional_arguments);
560
	}
561 51
	return $arguments;
562
}
563
564
/**
565
 * @param callable $func
566
 * @param array    $arguments
567
 * @param array    $additional_arguments
568
 *
569
 * @return bool
570
 */
571
function array_map_arguments_bool (callable $func, array $arguments, ...$additional_arguments) {
572 9
	$result = true;
573 9
	foreach ($arguments as $a) {
574 9
		$result = $result && $func($a, ...$additional_arguments);
575
	}
576 9
	return $result;
577
}
578