PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.18
E2Pdf – Export Pdf Tool for WordPress v1.32.18
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 1.08.09 All 71 releases
e2pdf / classes / model / e2pdf-element.php

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

168 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /model/e2pdf-element.php
5 *
6 * @package E2Pdf
7 * @license GPLv3
8 * @link https://e2pdf.com
9 */
10 if (!defined('ABSPATH')) {
11 die('Access denied.');
12 }
13
14 class Model_E2pdf_Element extends Model_E2pdf_Model {
15
16 private $element = array();
17 private $table;
18
19 public function __construct() {
20 global $wpdb;
21 parent::__construct();
22 $this->table = $wpdb->prefix . 'e2pdf_elements';
23 }
24
25 public function get_table() {
26 return $this->table;
27 }
28
29 public function set($key, $value) {
30 switch ($key) {
31 case 'properties':
32 case 'actions':
33 if (!is_array($value)) {
34 $this->element[$key] = array();
35 } else {
36 $this->element[$key] = $value;
37 }
38 break;
39
40 default:
41 $this->element[$key] = $value;
42 break;
43 }
44 }
45
46 public function get($key) {
47 if (isset($this->element[$key])) {
48 $value = $this->element[$key];
49 return $value;
50 } else {
51 switch ($key) {
52 case 'top':
53 case 'left':
54 case 'width':
55 case 'height':
56 case 'page_id':
57 case 'template_id':
58 case 'revision_id':
59 $value = 0;
60 break;
61 case 'properties':
62 case 'actions':
63 $value = array();
64 break;
65 default:
66 $value = '';
67 break;
68 }
69 return $value;
70 }
71 }
72
73 public function get_element() {
74 return $this->element;
75 }
76
77 public function before_save() {
78 $element = array(
79 'type' => $this->get('type'),
80 'page_id' => $this->get('page_id'),
81 'template_id' => $this->get('template_id'),
82 'element_id' => $this->get('element_id'),
83 'name' => $this->get('name'),
84 'top' => $this->get('top'),
85 'left' => $this->get('left'),
86 'width' => $this->get('width'),
87 'height' => $this->get('height'),
88 'value' => $this->get('value'),
89 'properties' => serialize($this->get('properties')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
90 'actions' => serialize($this->get('actions')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
91 'revision_id' => $this->get('revision_id'),
92 );
93 return $element;
94 }
95
96 public function save() {
97 global $wpdb;
98
99 $element = $this->before_save();
100
101 if ($this->get('element_id') && $this->get('page_id') && $this->get('template_id')) {
102 $wpdb->insert($this->get_table(), $element);
103 return $this->get('element_id');
104 }
105 }
106
107 public function load($element_id, $template_id, $revision_id = 0) {
108 global $wpdb;
109
110 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
111 $element = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . $this->get_table() . '` WHERE element_id = %d AND template_id = %d AND revision_id = %d', $element_id, $template_id, $revision_id), ARRAY_A);
112 if ($element) {
113 if ($element['type'] == 'e2pdf-html' || $element['type'] == 'e2pdf-page-number') {
114 $element['value'] = $this->helper->load('filter')->filter_html_tags($element['value']);
115 }
116 $this->element = $element;
117 $this->set('properties', $this->helper->load('convert')->unserialize($element['properties']));
118 $this->set('actions', $this->helper->load('convert')->unserialize($element['actions']));
119 return true;
120 }
121 return false;
122 }
123
124 public function get_last_element_id($template_id, $revision_id = 0) {
125 global $wpdb;
126
127 $element = false;
128 if ($template_id) {
129 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
130 $element = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . $this->get_table() . '` WHERE template_id = %d AND revision_id = %d ORDER BY element_id DESC', $template_id, $revision_id), ARRAY_A);
131 }
132
133 if ($element) {
134 return $element['element_id'];
135 } else {
136 return 0;
137 }
138 }
139
140 public function delete() {
141 global $wpdb;
142 if ($this->get('element_id') && $this->get('template_id')) {
143 $where = array(
144 'element_id' => $this->get('element_id'),
145 'template_id' => $this->get('template_id'),
146 'revision_id' => $this->get('revision_id'),
147 );
148 $wpdb->delete($this->get_table(), $where);
149 }
150 }
151
152 public function get_elements($page_id, $template_id, $revision_id = 0) {
153 global $wpdb;
154
155 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
156 $elements = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $this->get_table() . '` WHERE page_id = %d AND template_id = %d AND revision_id = %d', $page_id, $template_id, $revision_id), ARRAY_A);
157 if ($elements) {
158 $elements_list = array();
159 foreach ($elements as $element_key => $element) {
160 $this->load($element['element_id'], $element['template_id'], $element['revision_id']);
161 $elements_list[] = $this->get_element();
162 }
163 return $elements_list;
164 }
165 return array();
166 }
167 }
168