1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
<?php /** * @author ThemePunch <[email protected]> * @link https://www.themepunch.com/ * @copyright 2024 ThemePunch */
if (!defined('ABSPATH')) exit();
class RevSliderSvgSubject { /** * @var DOMElement */ protected $element;
/** * @var RevSliderSvgSubject[] */ protected $use = [];
/** * @var RevSliderSvgSubject[] */ protected $usedIn = [];
/** * @var int */ protected $nestingLimit;
/** * @param DOMElement $element * @param int $limit */ public function __construct($element, $limit) { $this->element = $element; $this->nestingLimit = $limit; }
/** * @return DOMElement */ public function getElement() { return $this->element; }
/** * @return string */ public function getElementId() { return $this->element->getAttribute('id'); }
/** * @param array $subjects Previously processed subjects * @param int $level The current level of nesting. * @return DOMElement|bool */ public function hasInfiniteLoop(array $subjects = [], $level = 1) { if ($level > $this->nestingLimit) { return $this->getElement(); }
if (in_array($this, $subjects, true)) return true; $subjects[] = $this; foreach ($this->use as $subjectUse) { $result = $subjectUse['subject']->hasInfiniteLoop($subjects, $level + 1); if ($result instanceof DOMElement) return $result; if ($result) return true; } return false; }
/** * @param RevSliderSvgSubject $subject * @param string $arrName */ protected function doAdd($subject, $arrName) { if ($subject === $this) { throw new LogicException('Cannot add self usage'); }
$id = $subject->getElementId(); if (isset($this->$arrName[$id])) { $this->$arrName[$id]['count']++; return; }
$this->$arrName[$id] = [ 'subject' => $subject, 'count' => 1, ]; }
/** * @param RevSliderSvgSubject $subject */ public function addUse($subject) { $this->doAdd($subject, 'use'); }
/** * @param RevSliderSvgSubject $subject */ public function addUsedIn($subject) { $this->doAdd($subject, 'usedIn'); }
/** * @param string $arrName * @param string $countFunc * @return int */ protected function doCount($arrName, $countFunc) { $count = 0; foreach ($this->$arrName as $subject) { $count += $subject['count'] * max(1, $subject['subject']->$countFunc()); } return $count; }
/** * @return int */ public function countUse() { return $this->doCount('use', 'countUse'); }
/** * @return int */ public function countUsedIn() { return $this->doCount('usedIn', 'countUsedIn'); }
/** * get all affected DOMElement's * * @return array */ public function getAffectedElements() { $elements = array_map(function ($subjectUse) { return $subjectUse['subject']->getElement(); }, $this->use);
$this->usedIn = []; $this->use = [];
return $elements; } }
|