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 +44 -24 1.05.031.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
@@ -91,26 +103,32 @@
91 103 return $this->get('element_id');
92 104 }
93 105 }
94 106
95 - public function load($element_id, $template_id) {
107 + public function load($element_id, $template_id, $revision_id = 0) {
96 108 global $wpdb;
97 - $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);
98 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 + }
99 116 $this->element = $element;
100 - $this->set('properties', unserialize($element['properties']));
101 - $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']));
102 119 return true;
103 120 }
104 121 return false;
105 122 }
106 123
107 - public function get_last_element_id($template_id) {
124 + public function get_last_element_id($template_id, $revision_id = 0) {
108 125 global $wpdb;
109 126
110 127 $element = false;
111 128 if ($template_id) {
112 - $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);
113 131 }
114 132
115 133 if ($element) {
116 134 return $element['element_id'];
@@ -123,21 +141,24 @@
123 141 global $wpdb;
124 142 if ($this->get('element_id') && $this->get('template_id')) {
125 143 $where = array(
126 144 'element_id' => $this->get('element_id'),
127 - 'template_id' => $this->get('template_id')
145 + 'template_id' => $this->get('template_id'),
146 + 'revision_id' => $this->get('revision_id'),
128 147 );
129 148 $wpdb->delete($this->get_table(), $where);
130 149 }
131 150 }
132 151
133 - public function get_elements($page_id, $template_id) {
152 + public function get_elements($page_id, $template_id, $revision_id = 0) {
134 153 global $wpdb;
135 - $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);
136 157 if ($elements) {
137 158 $elements_list = array();
138 159 foreach ($elements as $element_key => $element) {
139 - $this->load($element['element_id'], $element['template_id']);
160 + $this->load($element['element_id'], $element['template_id'], $element['revision_id']);
140 161 $elements_list[] = $this->get_element();
141 162 }
142 163 return $elements_list;
143 164 }
@@ -142,6 +163,5 @@
142 163 return $elements_list;
143 164 }
144 165 return array();
145 166 }
146 -
147 167 }