PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
← All changes | classes/model/e2pdf-action.php +150 -55 1.04.071.32.49 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Action Model
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 0.01.63
4 + * File: /model/e2pdf-action.php
5 + *
6 + * @package E2Pdf
7 + * @license GPLv3
8 + * @link https://e2pdf.com
11 9 */
12 10 if (!defined('ABSPATH')) {
13 11 die('Access denied.');
14 12 }
@@ -16,12 +14,8 @@
16 14 class Model_E2pdf_Action extends Model_E2pdf_Model {
17 15
18 16 private $extension;
19 17
20 - function __construct() {
21 - parent::__construct();
22 - }
23 -
24 18 public function load($extension) {
25 19 $this->extension = $extension;
26 20 }
27 21
@@ -28,24 +22,21 @@
28 22 public function process_actions($page) {
29 23 if (!$page || !$this->extension) {
30 24 return $page;
31 25 }
32 -
33 26 if (isset($page['actions']) && !empty($page['actions'])) {
34 - foreach ($page['actions'] as $action) {
35 - $page = $this->process_action($page, $action);
27 + foreach ($page['actions'] as $action_key => $action) {
28 + $page = $this->process_action($page, $action, $action_key);
36 29 }
37 - if (isset($page['hidden']) && $page['hidden']) {
38 - $page = false;
39 - }
40 30 }
41 31
42 - if ($page) {
32 + if (isset($page['hidden']) && $page['hidden']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
33 + } else {
43 34 if (!empty($page['elements'])) {
44 35 foreach ($page['elements'] as $el_key => $el_value) {
45 36 if (isset($el_value['actions']) && !empty($el_value['actions'])) {
46 - foreach ($el_value['actions'] as $action) {
47 - $el_value = $this->process_action($el_value, $action);
37 + foreach ($el_value['actions'] as $action_key => $action) {
38 + $el_value = $this->process_action($el_value, $action, $action_key);
48 39 }
49 40 $page['elements'][$el_key] = $el_value;
50 41 if ((isset($el_value['hidden']) && $el_value['hidden']) || ($el_value['page_id'] != $page['page_id'])) {
51 42 unset($page['elements'][$el_key]);
@@ -53,10 +44,40 @@
53 44 }
54 45 }
55 46 }
56 47 }
48 + return $page;
49 + }
57 50
58 - return $page;
51 + public function process_global_actions($actions = array()) {
52 + if (!empty($actions) && $this->extension) {
53 + foreach ($actions as $action_key => $action) {
54 + if (isset($action['action'])) {
55 + if ($action['action'] !== 'redirect_access_by_url') {
56 + // Backward Compatibility
57 + if (!isset($action['property'])) {
58 + if (false !== strpos($action['action'], 'restrict_')) {
59 + $action['property'] = 'disable';
60 + } else {
61 + $action['property'] = 'enable';
62 + }
63 + $action['action'] = str_replace(
64 + [
65 + 'restrict_process_shortcode_',
66 + 'process_shortcode_',
67 + 'restrict_process_',
68 + 'process_',
69 + 'restrict_',
70 + ], '', $action['action']
71 + );
72 + }
73 + $action['action'] = $action['property'] . '_' . $action['action'];
74 + }
75 + }
76 + $actions[$action_key] = $this->process_action($action, $action, $action_key);
77 + }
78 + }
79 + return $actions;
59 80 }
60 81
61 82 public function process_page_id($page) {
62 83 $elements = array();
@@ -63,11 +84,11 @@
63 84 if ($page && $this->extension) {
64 85 if (!empty($page['elements'])) {
65 86 foreach ($page['elements'] as $el_key => $el_value) {
66 87 if (isset($el_value['actions']) && !empty($el_value['actions'])) {
67 - foreach ($el_value['actions'] as $action) {
88 + foreach ($el_value['actions'] as $action_key => $action) {
68 89 if ($action['action'] == 'change' && isset($action['property']) && $action['property'] == 'page_id') {
69 - $el_value = $this->process_action($el_value, $action);
90 + $el_value = $this->process_action($el_value, $action, $action_key);
70 91 }
71 92 }
72 93 if ($el_value['page_id'] != $page['page_id']) {
73 94 $elements[] = $el_value;
@@ -78,10 +99,9 @@
78 99 }
79 100 return $elements;
80 101 }
81 102
82 - private function process_action($element, $action) {
83 -
103 + private function process_action($element, $action, $action_key) {
84 104 $apply = false;
85 105 if (isset($action['conditions']) && !empty($action['conditions'])) {
86 106 foreach ($action['conditions'] as $condition) {
87 107 $apply = $this->process_condition($condition);
@@ -91,48 +111,39 @@
91 111 break;
92 112 }
93 113 }
94 114 }
95 -
96 115 if ($apply) {
97 - $element = $this->apply_action($element, $action);
116 + $element = $this->apply_action($element, $action, $action_key);
117 + } else {
118 + $element = $this->apply_else_action($element, $action);
98 119 }
99 -
100 120 return $element;
101 121 }
102 122
103 123 private function process_condition($condition) {
104 -
105 124 $result = false;
106 -
107 - $if = $this->extension->render($condition['if'], 'value');
108 - $value = $this->extension->render($condition['value'], 'value');
109 -
125 + $if = $this->extension->render($condition['if']);
126 + $value = $this->extension->render($condition['value']);
110 127 switch ($condition['condition']) {
111 128 case '=':
112 129 $result = $if == $value ? true : false;
113 130 break;
114 -
115 131 case '!=':
116 132 $result = $if != $value ? true : false;
117 133 break;
118 -
119 134 case '>':
120 135 $result = $if > $value ? true : false;
121 136 break;
122 -
123 137 case '>=':
124 138 $result = $if >= $value ? true : false;
125 139 break;
126 -
127 140 case '<':
128 141 $result = $if < $value ? true : false;
129 142 break;
130 -
131 143 case '<=':
132 144 $result = $if <= $value ? true : false;
133 145 break;
134 -
135 146 case 'like':
136 147 if (empty($value) && empty($if)) {
137 148 $result = true;
138 149 } else {
@@ -138,9 +149,8 @@
138 149 } else {
139 150 $result = !empty($value) && strpos($if, $value) !== false ? true : false;
140 151 }
141 152 break;
142 -
143 153 case 'not_like':
144 154 if (empty($value) && empty($if)) {
145 155 $result = false;
146 156 } elseif (empty($value) && !empty($if)) {
@@ -148,51 +158,136 @@
148 158 } else {
149 159 $result = !empty($value) && strpos($if, $value) === false ? true : false;
150 160 }
151 161 break;
162 + case 'in_array':
163 + $unserialized = false;
164 + if (is_serialized($value)) {
165 + $unserialized = $this->helper->load('convert')->unserialize($value);
166 + }
167 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
168 + $result = is_array($unserialized) && in_array($if, $unserialized) ? true : false;
169 + break;
170 + case 'not_in_array':
171 + $unserialized = false;
172 + if (is_serialized($value)) {
173 + $unserialized = $this->helper->load('convert')->unserialize($value);
174 + }
175 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
176 + $result = is_array($unserialized) && in_array($if, $unserialized) ? false : true;
177 + break;
178 + case 'in_list':
179 + $list_if = array_map('trim', explode(',', $if));
180 + $list_value = array_map('trim', explode(',', $value));
181 + $result = !array_diff($list_if, $list_value) ? true : false;
182 + break;
183 + case 'not_in_list':
184 + $list_if = array_map('trim', explode(',', $if));
185 + $list_value = array_map('trim', explode(',', $value));
186 + $result = !array_diff($list_if, $list_value) ? false : true;
187 + break;
188 + case 'array_key_exists':
189 + $unserialized = false;
190 + if (is_serialized($value)) {
191 + $unserialized = $this->helper->load('convert')->unserialize($value);
192 + }
193 + $result = is_array($unserialized) && array_key_exists($if, $unserialized) ? true : false;
194 + break;
195 + case 'array_key_not_exists':
196 + $unserialized = false;
197 + if (is_serialized($value)) {
198 + $unserialized = $this->helper->load('convert')->unserialize($value);
199 + }
200 + $result = is_array($unserialized) && array_key_exists($if, $unserialized) ? false : true;
201 + break;
152 202 }
153 -
154 203 return $result;
155 204 }
156 205
157 - private function apply_action($element, $action) {
206 + private function apply_action($element, $action, $action_key) {
158 207 if ($action['action'] == 'hide') {
159 208 $element['hidden'] = true;
160 209 } elseif ($action['action'] == 'show') {
161 210 $element['hidden'] = false;
211 + } elseif ($action['action'] == 'merge' && $action['property']) {
212 + if ($action['property'] == 'value' && isset($element['element_id'])) {
213 + $value = isset($element[$action['property']]) ? $element[$action['property']] : '';
214 + $change = $value . $action['change'];
215 + $element[$action['property']] = $change;
216 + }
162 217 } elseif ($action['action'] == 'change' && $action['property']) {
163 -
164 218 $number_properties = array(
165 - 'width', 'height', 'left', 'top'
219 + 'width', 'height', 'left', 'top',
166 220 );
167 -
168 221 $not_properties = array(
169 - 'top', 'left', 'width', 'height', 'value', 'page_id'
222 + 'top', 'left', 'width', 'height', 'value', 'page_id',
170 223 );
171 -
172 224 if ($action['property'] == 'value') {
173 - $change = $action['change'];
225 + $action['change'] = $this->helper->load('translator')->pre_translate($action['change'], $element['template_id'], $element['element_id'], 'value_action_' . $action_key . '_change');
226 + if (isset($action['format']) && $action['format'] != 'replace') {
227 + if ($action['format'] == 'insert_before') {
228 + $value = isset($element[$action['property']]) ? $element[$action['property']] : '';
229 + $change = $action['change'] . $value;
230 + } elseif ($action['format'] == 'insert_after') {
231 + $value = isset($element[$action['property']]) ? $element[$action['property']] : '';
232 + $change = $value . $action['change'];
233 + } elseif ($action['format'] == 'search') {
234 + $search = isset($action['search']) ? $action['search'] : '';
235 + $replace = isset($action['change']) ? $action['change'] : '';
236 + if ($search) {
237 + $value = isset($element[$action['property']]) ? $element[$action['property']] : '';
238 + $pre_replace = isset($action['pre_replace']) ? $action['pre_replace'] : '';
239 + if ($pre_replace == 'render') {
240 + $type = isset($element['type']) ? $element['type'] : '';
241 + if (!isset($element['rendered'])) {
242 + if (in_array($type, array('e2pdf-html', 'e2pdf-page-number'), true)) {
243 + $value = $this->helper->load('filter')->filter_html_tags($this->extension->render($value, $element));
244 + } else {
245 + $value = $this->extension->render($value, $element);
246 + }
247 + }
248 + if (in_array($type, array('e2pdf-html', 'e2pdf-page-number'), true)) {
249 + $replace = $this->helper->load('filter')->filter_html_tags($this->extension->render($replace, $element));
250 + } else {
251 + $replace = $this->extension->render($replace, $element);
252 + }
253 + $element['rendered'] = true;
254 + }
255 + if ($value) {
256 + $change = str_replace($search, $replace, $value);
257 + }
258 + }
259 + }
260 + } else {
261 + $change = $action['change'];
262 + }
174 263 } else {
175 - $change = $this->extension->render($action['change'], 'value');
264 + $change = $this->extension->render($action['change']);
176 265 }
177 -
178 - if ((substr($change, 0, 1) === "+" || substr($change, 0, 1) === "-") && in_array($action['property'], $number_properties)) {
266 + if ((substr($change, 0, 1) === '+' || substr($change, 0, 1) === '-') && in_array($action['property'], $number_properties, true)) {
179 267 if (isset($element['element_id'])) {
180 268 $value = isset($element[$action['property']]) ? $element[$action['property']] : 0;
181 269 } else {
182 270 $value = isset($element['properties'][$action['property']]) ? $element['properties'][$action['property']] : 0;
183 271 }
184 -
185 272 $change = $value + floatval($change);
186 273 }
187 -
188 - if (in_array($action['property'], $not_properties) && isset($element['element_id'])) {
274 + if (in_array($action['property'], $not_properties, true) && isset($element['element_id'])) {
189 275 $element[$action['property']] = $change;
190 276 } else {
191 277 $element['properties'][$action['property']] = $change;
192 278 }
279 + } elseif (isset($element['action'])) {
280 + $element['success'] = true;
193 281 }
282 + return $element;
283 + }
194 284
285 + private function apply_else_action($element, $action) {
286 + if ($action['action'] == 'show') {
287 + if (isset($action['else']) && $action['else'] == 'hide') {
288 + $element['hidden'] = true;
289 + }
290 + }
195 291 return $element;
196 292 }
197 -
198 293 }