PluginProbe
Internal Link Juicer: SEO Auto Linker for WordPress / trunk
Internal Link Juicer: SEO Auto Linker for WordPress vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.5.2 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.15.1 1.2.16 1.2.17 All 75 releases
internal-links / helper / misc.php

misc.php in Internal Link Juicer: SEO Auto Linker for WordPress trunk, at helper/misc.php

48 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ILJ\Helper;
3
4 use function ILJ\ilj_try_include_file;
5
6 if (!class_exists('Brumann\Polyfill\DisallowedClassesSubstitutor')) ilj_try_include_file('vendor/brumann/polyfill-unserialize/src/DisallowedClassesSubstitutor.php', 'require_once');
7 if (!class_exists('Brumann\Polyfill\Unserialize')) ilj_try_include_file('vendor/brumann/polyfill-unserialize/src/Unserialize.php', 'require_once');
8
9 /**
10 * Loader
11 *
12 * Class for miscellaneous methods.
13 *
14 * @package ILJ\Helper
15 */
16 final class Misc {
17
18 /**
19 * Unserializes data only if it was serialized.
20 *
21 * @param string $data Data that might be unserialized.
22 * @return mixed Unserialized data can be any type.
23 */
24 public static function maybe_unserialize($data) {
25 if (is_serialized($data)) { // Don't attempt to unserialize data that wasn't serialized going in.
26 return self::unserialize(trim($data), false);
27 }
28 return $data;
29 }
30
31 /**
32 * Unserialize data while maintaining compatibility across PHP versions due to different number of arguments required by PHP's "unserialize" function
33 *
34 * @param string $serialized_data Data to be unserialized, should be one that is already serialized
35 * @param boolean|array $allowed_classes Either an array of class names which should be accepted, false to accept no classes, or true to accept all classes
36 * @param integer $max_depth The maximum depth of structures permitted during unserialization, and is intended to prevent stack overflows
37 * @return mixed Unserialized data can be any of types (integer, float, boolean, string, array or object)
38 */
39 public static function unserialize($serialized_data, $allowed_classes = false, $max_depth = 0) {
40 if (version_compare(PHP_VERSION, '5.2', '<=')) {
41 $result = unserialize($serialized_data); // For PHP 5.2 users, the search-replace feature has been removed, meaning that any input provided in this context will not undergo search-replace processing
42 } else {
43 $result = call_user_func(array('Brumann\Polyfill\Unserialize', 'unserialize'), $serialized_data, array('allowed_classes' => $allowed_classes, 'max_depth' => $max_depth));
44 }
45 return $result;
46 }
47 }
48