Completed
Push — master ( 6dab8b...b949bb )
by Michael
02:15 queued 11s
created

altsysUtils::getDelegateCallbackClassNames()   B

Complexity

Conditions 9
Paths 7

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
nc 7
nop 2
dl 0
loc 42
rs 7.6924
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class altsysUtils
5
 */
6
class altsysUtils
7
{
8
    /**
9
     * @param      $name
10
     * @param bool $doRegist
11
     * @return array
12
     */
13
14
    public static function getDelegateCallbackClassNames($name, $doRegist = true)
15
    {
16
        $names = [];
17
18
        if (!class_exists('XCube_Delegate')) {
19
            return $names;
20
        }
21
22
        if ($doRegist) {
23
            $delegate = new XCube_Delegate();
24
25
            $delegate->register($name);
26
        }
27
28
        $m = XCube_Root::getSingleton()->mDelegateManager;
29
30
        if ($m) {
31
            $delgates = $m->getDelegates();
32
33
            if (isset($delgates[$name])) {
34
                $d_target = $delgates[$name];
35
36
                $keys = array_keys($d_target);
37
38
                $callbacks = $d_target[$keys[0]]->_mCallbacks;
39
40
                foreach (array_keys($callbacks) as $priority) {
41
                    foreach (array_keys($callbacks[$priority]) as $idx) {
42
                        $callback = $callbacks[$priority][$idx][0];
43
44
                        $_name = is_array($callback) ? (is_object($callback[0]) ? get_class($callback[0]) : $callback[0]) : $callback;
45
46
                        $names[$priority] = $_name;
47
                    }
48
                }
49
50
                ksort($names, SORT_NUMERIC);
51
            }
52
        }
53
54
        return $names;
55
    }
56
57
    /**
58
     * @return bool
59
     */
60
61
    public static function isInstalledXclHtmleditor()
62
    {
63
        if (defined('LEGACY_BASE_VERSION') && version_compare(LEGACY_BASE_VERSION, '2.2.0.0', '>=')) {
64
            $cNames = self::getDelegateCallbackClassNames('Site.TextareaEditor.HTML.Show');
65
66
            if ($cNames) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cNames of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
67
                $last = array_pop($cNames);
68
69
                if ('Legacy_TextareaEditor' !== $last) {
70
                    return true;
71
                }
72
            }
73
        }
74
75
        return false;
76
    }
77
78
    /**
79
     * @param      $str
80
     * @param int  $flags
81
     * @param null $encoding
82
     * @param bool $double_encode
83
     * @return mixed|string
84
     */
85
86
    public static function htmlSpecialChars($str, $flags = ENT_COMPAT, $encoding = null, $double_encode = true)
87
    {
88
        static $php523 = null;
89
90
        if (null === $php523) {
91
            $php523 = version_compare(PHP_VERSION, '5.2.3', '>=');
92
        }
93
94
        if (null === $encoding) {
95
            $encoding = defined('_CHARSET') ? _CHARSET : '';
96
        }
97
98
        if ($php523) {
99
            return htmlspecialchars($str, $flags, $encoding, $double_encode);
100
        }
101
102
        $ret = htmlspecialchars($str, $flags, $encoding);
103
104
        if (!$double_encode) {
105
            $ret = str_replace('&amp;amp;', '&amp;', $ret);
106
        }
107
108
        return $ret;
109
    }
110
}
111