PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.01.01
E2Pdf – Export Pdf Tool for WordPress v1.01.01
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
e2pdf / classes / model / e2pdf-action.php

e2pdf-action.php in E2Pdf – Export Pdf Tool for WordPress 1.01.01, at classes/model/e2pdf-action.php

165 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
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
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Model_E2pdf_Action extends Model_E2pdf_Model {
17
18 private $extension;
19
20 function __construct() {
21 parent::__construct();
22 }
23
24 public function load($extension) {
25 $this->extension = $extension;
26 }
27
28 public function process_actions($page) {
29 if (!$page || !$this->extension) {
30 return $page;
31 }
32
33 if (isset($page['actions']) && !empty($page['actions'])) {
34 foreach ($page['actions'] as $action) {
35 $page = $this->process_action($page, $action);
36 }
37 if (isset($page['hidden']) && $page['hidden']) {
38 $page = false;
39 }
40 }
41
42 if ($page) {
43 if (!empty($page['elements'])) {
44 foreach ($page['elements'] as $el_key => $el_value) {
45 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);
48 }
49 $page['elements'][$el_key] = $el_value;
50 if (isset($el_value['hidden']) && $el_value['hidden']) {
51 unset($page['elements'][$el_key]);
52 break;
53 }
54 }
55 }
56 }
57 }
58
59 return $page;
60 }
61
62 private function process_action($element, $action) {
63
64 $apply = false;
65 if (isset($action['conditions']) && !empty($action['conditions'])) {
66 foreach ($action['conditions'] as $condition) {
67 $apply = $this->process_condition($condition);
68 if ($action['apply'] == 'any' && $apply) {
69 break;
70 } elseif ($action['apply'] == 'all' && !$apply) {
71 break;
72 }
73 }
74 }
75
76 if ($apply) {
77 $element = $this->apply_action($element, $action);
78 }
79
80 return $element;
81 }
82
83 private function process_condition($condition) {
84
85 $result = false;
86
87 $if = $this->extension->render($condition['if']);
88 $value = $this->extension->render($condition['value']);
89
90 switch ($condition['condition']) {
91 case '=':
92 $result = $if == $value ? true : false;
93 break;
94
95 case '!=':
96 $result = $if != $value ? true : false;
97 break;
98
99 case '>':
100 $result = $if > $value ? true : false;
101 break;
102
103 case '>=':
104 $result = $if >= $value ? true : false;
105 break;
106
107 case '<':
108 $result = $if < $value ? true : false;
109 break;
110
111 case '<=':
112 $result = $if <= $value ? true : false;
113 break;
114
115 case 'like':
116 $result = strpos($if, $value) !== false ? true : false;
117 break;
118
119 case 'not_like':
120 $result = strpos($if, $value) === false ? true : false;
121 break;
122 }
123
124 return $result;
125 }
126
127 private function apply_action($element, $action) {
128 if ($action['action'] == 'hide') {
129 $element['hidden'] = true;
130 } elseif ($action['action'] == 'show') {
131 $element['hidden'] = false;
132 } elseif ($action['action'] == 'change' && $action['property']) {
133
134 $number_properties = array(
135 'width', 'height', 'left', 'top'
136 );
137
138 $not_properties = array(
139 'top', 'left', 'width', 'height', 'value'
140 );
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)) {
145 if (isset($element['element_id'])) {
146 $value = isset($element[$action['property']]) ? $element[$action['property']] : 0;
147 } else {
148 $value = isset($element['properties'][$action['property']]) ? $element['properties'][$action['property']] : 0;
149 }
150
151 $change = $value + floatval($change);
152 }
153
154 if (in_array($action['property'], $not_properties) && isset($element['element_id'])) {
155 $element[$action['property']] = $change;
156 } else {
157 $element['properties'][$action['property']] = $change;
158 }
159 }
160
161 return $element;
162 }
163
164 }
165