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 +184 -54 1.02.021.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,27 +22,24 @@
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 - if (isset($el_value['hidden']) && $el_value['hidden']) {
41 + if ((isset($el_value['hidden']) && $el_value['hidden']) || ($el_value['page_id'] != $page['page_id'])) {
51 42 unset($page['elements'][$el_key]);
52 43 }
53 44 }
54 45 }
@@ -53,14 +44,64 @@
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 - private function process_action($element, $action) {
82 + public function process_page_id($page) {
83 + $elements = array();
84 + if ($page && $this->extension) {
85 + if (!empty($page['elements'])) {
86 + foreach ($page['elements'] as $el_key => $el_value) {
87 + if (isset($el_value['actions']) && !empty($el_value['actions'])) {
88 + foreach ($el_value['actions'] as $action_key => $action) {
89 + if ($action['action'] == 'change' && isset($action['property']) && $action['property'] == 'page_id') {
90 + $el_value = $this->process_action($el_value, $action, $action_key);
91 + }
92 + }
93 + if ($el_value['page_id'] != $page['page_id']) {
94 + $elements[] = $el_value;
95 + }
96 + }
97 + }
98 + }
99 + }
100 + return $elements;
101 + }
62 102
103 + private function process_action($element, $action, $action_key) {
63 104 $apply = false;
64 105 if (isset($action['conditions']) && !empty($action['conditions'])) {
65 106 foreach ($action['conditions'] as $condition) {
66 107 $apply = $this->process_condition($condition);
@@ -70,94 +111,183 @@
70 111 break;
71 112 }
72 113 }
73 114 }
74 -
75 115 if ($apply) {
76 - $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);
77 119 }
78 -
79 120 return $element;
80 121 }
81 122
82 123 private function process_condition($condition) {
83 -
84 124 $result = false;
85 -
86 - $if = $this->extension->render($condition['if'], 'value');
87 - $value = $this->extension->render($condition['value'], 'value');
88 -
125 + $if = $this->extension->render($condition['if']);
126 + $value = $this->extension->render($condition['value']);
89 127 switch ($condition['condition']) {
90 128 case '=':
91 129 $result = $if == $value ? true : false;
92 130 break;
93 -
94 131 case '!=':
95 132 $result = $if != $value ? true : false;
96 133 break;
97 -
98 134 case '>':
99 135 $result = $if > $value ? true : false;
100 136 break;
101 -
102 137 case '>=':
103 138 $result = $if >= $value ? true : false;
104 139 break;
105 -
106 140 case '<':
107 141 $result = $if < $value ? true : false;
108 142 break;
109 -
110 143 case '<=':
111 144 $result = $if <= $value ? true : false;
112 145 break;
113 -
114 146 case 'like':
115 - $result = strpos($if, $value) !== false ? true : false;
147 + if (empty($value) && empty($if)) {
148 + $result = true;
149 + } else {
150 + $result = !empty($value) && strpos($if, $value) !== false ? true : false;
151 + }
116 152 break;
117 -
118 153 case 'not_like':
119 - $result = strpos($if, $value) === false ? true : false;
154 + if (empty($value) && empty($if)) {
155 + $result = false;
156 + } elseif (empty($value) && !empty($if)) {
157 + $result = true;
158 + } else {
159 + $result = !empty($value) && strpos($if, $value) === false ? true : false;
160 + }
120 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;
121 202 }
122 -
123 203 return $result;
124 204 }
125 205
126 - private function apply_action($element, $action) {
206 + private function apply_action($element, $action, $action_key) {
127 207 if ($action['action'] == 'hide') {
128 208 $element['hidden'] = true;
129 209 } elseif ($action['action'] == 'show') {
130 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 + }
131 217 } elseif ($action['action'] == 'change' && $action['property']) {
132 -
133 218 $number_properties = array(
134 - 'width', 'height', 'left', 'top'
219 + 'width', 'height', 'left', 'top',
135 220 );
136 -
137 221 $not_properties = array(
138 - 'top', 'left', 'width', 'height', 'value'
222 + 'top', 'left', 'width', 'height', 'value', 'page_id',
139 223 );
140 -
141 - $change = $this->extension->render($action['change'], 'value');
142 -
143 - if ((substr($change, 0, 1) === "+" || substr($change, 0, 1) === "-") && in_array($action['property'], $number_properties)) {
224 + if ($action['property'] == 'value') {
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 + }
263 + } else {
264 + $change = $this->extension->render($action['change']);
265 + }
266 + if ((substr($change, 0, 1) === '+' || substr($change, 0, 1) === '-') && in_array($action['property'], $number_properties, true)) {
144 267 if (isset($element['element_id'])) {
145 268 $value = isset($element[$action['property']]) ? $element[$action['property']] : 0;
146 269 } else {
147 270 $value = isset($element['properties'][$action['property']]) ? $element['properties'][$action['property']] : 0;
148 271 }
149 -
150 272 $change = $value + floatval($change);
151 273 }
152 -
153 - if (in_array($action['property'], $not_properties) && isset($element['element_id'])) {
274 + if (in_array($action['property'], $not_properties, true) && isset($element['element_id'])) {
154 275 $element[$action['property']] = $change;
155 276 } else {
156 277 $element['properties'][$action['property']] = $change;
157 278 }
279 + } elseif (isset($element['action'])) {
280 + $element['success'] = true;
158 281 }
282 + return $element;
283 + }
159 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 + }
160 291 return $element;
161 292 }
162 -
163 293 }