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