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 +43 -24 1.08.001.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 }
@@ -75,10 +85,11 @@
75 85 'left' => $this->get('left'),
76 86 'width' => $this->get('width'),
77 87 'height' => $this->get('height'),
78 88 'value' => $this->get('value'),
79 - 'properties' => serialize($this->get('properties')),
80 - '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'),
81 92 );
82 93 return $element;
83 94 }
84 95
@@ -92,26 +103,32 @@
92 103 return $this->get('element_id');
93 104 }
94 105 }
95 106
96 - public function load($element_id, $template_id) {
107 + public function load($element_id, $template_id, $revision_id = 0) {
97 108 global $wpdb;
98 - $element = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE element_id = %d AND template_id = %d", $element_id, $template_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);
99 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 + }
100 116 $this->element = $element;
101 - $this->set('properties', unserialize($element['properties']));
102 - $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']));
103 119 return true;
104 120 }
105 121 return false;
106 122 }
107 123
108 - public function get_last_element_id($template_id) {
124 + public function get_last_element_id($template_id, $revision_id = 0) {
109 125 global $wpdb;
110 126
111 127 $element = false;
112 128 if ($template_id) {
113 - $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);
114 131 }
115 132
116 133 if ($element) {
117 134 return $element['element_id'];
@@ -124,21 +141,24 @@
124 141 global $wpdb;
125 142 if ($this->get('element_id') && $this->get('template_id')) {
126 143 $where = array(
127 144 'element_id' => $this->get('element_id'),
128 - 'template_id' => $this->get('template_id')
145 + 'template_id' => $this->get('template_id'),
146 + 'revision_id' => $this->get('revision_id'),
129 147 );
130 148 $wpdb->delete($this->get_table(), $where);
131 149 }
132 150 }
133 151
134 - public function get_elements($page_id, $template_id) {
152 + public function get_elements($page_id, $template_id, $revision_id = 0) {
135 153 global $wpdb;
136 - $elements = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE page_id = %d AND template_id = %d", $page_id, $template_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);
137 157 if ($elements) {
138 158 $elements_list = array();
139 159 foreach ($elements as $element_key => $element) {
140 - $this->load($element['element_id'], $element['template_id']);
160 + $this->load($element['element_id'], $element['template_id'], $element['revision_id']);
141 161 $elements_list[] = $this->get_element();
142 162 }
143 163 return $elements_list;
144 164 }
@@ -143,6 +163,5 @@
143 163 return $elements_list;
144 164 }
145 165 return array();
146 166 }
147 -
148 167 }