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-element.php +48 -33 1.01.011.32.49 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Template Model
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 0.00.01
4 + * File: /model/e2pdf-element.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 }
@@ -17,9 +15,9 @@
17 15
18 16 private $element = array();
19 17 private $table;
20 18
21 - function __construct() {
19 + public function __construct() {
22 20 global $wpdb;
23 21 parent::__construct();
24 22 $this->table = $wpdb->prefix . 'e2pdf_elements';
25 23 }
@@ -28,9 +26,22 @@
28 26 return $this->table;
29 27 }
30 28
31 29 public function set($key, $value) {
32 - $this->element[$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 + }
33 44 }
34 45
35 46 public function get($key) {
36 47 if (isset($this->element[$key])) {
@@ -43,16 +54,15 @@
43 54 case 'width':
44 55 case 'height':
45 56 case 'page_id':
46 57 case 'template_id':
58 + case 'revision_id':
47 59 $value = 0;
48 60 break;
49 -
50 61 case 'properties':
51 62 case 'actions':
52 63 $value = array();
53 64 break;
54 -
55 65 default:
56 66 $value = '';
57 67 break;
58 68 }
@@ -69,15 +79,17 @@
69 79 'type' => $this->get('type'),
70 80 'page_id' => $this->get('page_id'),
71 81 'template_id' => $this->get('template_id'),
72 82 'element_id' => $this->get('element_id'),
83 + 'name' => $this->get('name'),
73 84 'top' => $this->get('top'),
74 85 'left' => $this->get('left'),
75 86 'width' => $this->get('width'),
76 87 'height' => $this->get('height'),
77 88 'value' => $this->get('value'),
78 - 'properties' => serialize($this->get('properties')),
79 - 'actions' => serialize($this->get('actions')),
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'),
80 92 );
81 93 return $element;
82 94 }
83 95
@@ -85,38 +97,38 @@
85 97 global $wpdb;
86 98
87 99 $element = $this->before_save();
88 100
89 - if ($this->get('ID')) {
90 - $where = array(
91 - 'ID' => $this->get('ID')
92 - );
93 - $wpdb->update($this->get_table(), $element, $where);
94 - return $this->get('ID');
95 - } else {
101 + if ($this->get('element_id') && $this->get('page_id') && $this->get('template_id')) {
96 102 $wpdb->insert($this->get_table(), $element);
97 - $this->set('ID', $wpdb->insert_id);
103 + return $this->get('element_id');
98 104 }
99 105 }
100 106
101 - public function load($element_id) {
107 + public function load($element_id, $template_id, $revision_id = 0) {
102 108 global $wpdb;
103 - $element = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE ID = %d", $element_id), ARRAY_A);
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);
104 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 + }
105 116 $this->element = $element;
106 - $this->set('properties', unserialize($element['properties']));
107 - $this->set('actions', unserialize($element['actions']));
117 + $this->set('properties', $this->helper->load('convert')->unserialize($element['properties']));
118 + $this->set('actions', $this->helper->load('convert')->unserialize($element['actions']));
108 119 return true;
109 120 }
110 121 return false;
111 122 }
112 123
113 - public function get_last_element_id($template_id) {
124 + public function get_last_element_id($template_id, $revision_id = 0) {
114 125 global $wpdb;
115 126
116 127 $element = false;
117 128 if ($template_id) {
118 - $element = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE template_id = %d ORDER BY element_id DESC", $template_id), ARRAY_A);
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);
119 131 }
120 132
121 133 if ($element) {
122 134 return $element['element_id'];
@@ -126,23 +138,27 @@
126 138 }
127 139
128 140 public function delete() {
129 141 global $wpdb;
130 - if ($this->get('ID')) {
142 + if ($this->get('element_id') && $this->get('template_id')) {
131 143 $where = array(
132 - 'ID' => $this->get('ID')
144 + 'element_id' => $this->get('element_id'),
145 + 'template_id' => $this->get('template_id'),
146 + 'revision_id' => $this->get('revision_id'),
133 147 );
134 148 $wpdb->delete($this->get_table(), $where);
135 149 }
136 150 }
137 151
138 - public function get_elements($page_id) {
152 + public function get_elements($page_id, $template_id, $revision_id = 0) {
139 153 global $wpdb;
140 - $elements = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE page_id = %d", $page_id), ARRAY_A);
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);
141 157 if ($elements) {
142 158 $elements_list = array();
143 159 foreach ($elements as $element_key => $element) {
144 - $this->load($element['ID']);
160 + $this->load($element['element_id'], $element['template_id'], $element['revision_id']);
145 161 $elements_list[] = $this->get_element();
146 162 }
147 163 return $elements_list;
148 164 }
@@ -147,6 +163,5 @@
147 163 return $elements_list;
148 164 }
149 165 return array();
150 166 }
151 -
152 167 }