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-page.php +57 -34 1.02.021.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-page.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 $page = 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_pages';
25 23 }
@@ -28,9 +26,22 @@
28 26 return $this->table;
29 27 }
30 28
31 29 public function set($key, $value) {
32 - $this->page[$key] = $value;
30 + switch ($key) {
31 + case 'properties':
32 + case 'actions':
33 + if (!is_array($value)) {
34 + $this->page[$key] = array();
35 + } else {
36 + $this->page[$key] = $value;
37 + }
38 + break;
39 +
40 + default:
41 + $this->page[$key] = $value;
42 + break;
43 + }
33 44 }
34 45
35 46 public function get($key) {
36 47 if (isset($this->page[$key])) {
@@ -38,16 +49,15 @@
38 49 return $value;
39 50 } else {
40 51 switch ($key) {
41 52 case 'template_id':
53 + case 'revision_id':
42 54 $value = 0;
43 55 break;
44 -
45 56 case 'properties':
46 57 case 'actions':
47 58 $value = array();
48 59 break;
49 -
50 60 default:
51 61 $value = '';
52 62 break;
53 63 }
@@ -62,10 +72,11 @@
62 72 public function before_save() {
63 73 $page = array(
64 74 'template_id' => $this->get('template_id'),
65 75 'page_id' => $this->get('page_id'),
66 - 'properties' => serialize($this->get('properties')),
67 - 'actions' => serialize($this->get('actions'))
76 + 'properties' => serialize($this->get('properties')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
77 + 'actions' => serialize($this->get('actions')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
78 + 'revision_id' => $this->get('revision_id'),
68 79 );
69 80 return $page;
70 81 }
71 82
@@ -72,30 +83,39 @@
72 83 public function save() {
73 84 global $wpdb;
74 85
75 86 $page = $this->before_save();
87 + if ($this->get('page_id') && $this->get('template_id')) {
88 + $show_errors = false;
89 + if ($wpdb->show_errors) {
90 + $wpdb->show_errors(false);
91 + $show_errors = true;
92 + }
76 93
77 - if ($this->get('ID')) {
78 - $where = array(
79 - 'ID' => $this->get('ID')
80 - );
81 - $wpdb->update($this->get_table(), $page, $where);
82 - return $this->get('ID');
83 - } else {
84 - $wpdb->insert($this->get_table(), $page);
85 - $this->set('ID', $wpdb->insert_id);
94 + $success = $wpdb->insert($this->get_table(), $page);
95 + if ($success === false) {
96 + $this->helper->load('db')->db_init($wpdb->prefix);
97 + $wpdb->insert($this->get_table(), $page);
98 + }
99 +
100 + if ($show_errors) {
101 + $wpdb->show_errors();
102 + }
103 + return $this->get('page_id');
86 104 }
87 105 }
88 106
89 - public function load($page_id) {
107 + public function load($page_id, $template_id, $revision_id = 0) {
90 108 global $wpdb;
91 - $page = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE ID = %d", $page_id), ARRAY_A);
109 +
110 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
111 + $page = $wpdb->get_row($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);
92 112 if ($page) {
93 113 $this->page = $page;
94 - $this->set('properties', unserialize($page['properties']));
95 - $this->set('actions', unserialize($page['actions']));
114 + $this->set('properties', $this->helper->load('convert')->unserialize($page['properties']));
115 + $this->set('actions', $this->helper->load('convert')->unserialize($page['actions']));
96 116 $model_e2pdf_element = new Model_E2pdf_Element();
97 - $this->set('elements', $model_e2pdf_element->get_elements($this->get('ID')));
117 + $this->set('elements', $model_e2pdf_element->get_elements($this->get('page_id'), $this->get('template_id'), $this->get('revision_id')));
98 118 return true;
99 119 }
100 120 return false;
101 121 }
@@ -101,30 +121,34 @@
101 121 }
102 122
103 123 public function delete() {
104 124 global $wpdb;
105 - if ($this->get('ID')) {
125 + if ($this->get('page_id') && $this->get('template_id')) {
106 126 $where = array(
107 - 'ID' => $this->get('ID')
127 + 'page_id' => $this->get('page_id'),
128 + 'template_id' => $this->get('template_id'),
129 + 'revision_id' => $this->get('revision_id'),
108 130 );
109 131 $wpdb->delete($this->get_table(), $where);
110 132
111 133 foreach ($this->get('elements') as $element) {
112 134 $model_e2pdf_element = new Model_E2pdf_Element();
113 - $model_e2pdf_element->load($element['ID']);
135 + $model_e2pdf_element->load($element['element_id'], $element['template_id'], $element['revision_id']);
114 136 $model_e2pdf_element->delete();
115 137 }
116 138 }
117 139 }
118 140
119 - public function get_pages($template_id) {
141 + public function get_pages($template_id, $revision_id = 0) {
120 142 global $wpdb;
121 - $pages = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE template_id = %d ORDER BY ID ASC", $template_id), ARRAY_A);
143 +
144 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
145 + $pages = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $this->get_table() . '` WHERE template_id = %d AND revision_id = %d ORDER BY page_id ASC', $template_id, $revision_id), ARRAY_A);
122 146 if ($pages) {
123 147 $pages_list = array();
124 148 $pages_list[] = array();
125 149 foreach ($pages as $page_key => $page) {
126 - $this->load($page['ID']);
150 + $this->load($page['page_id'], $page['template_id'], $page['revision_id']);
127 151 $pages_list[] = $this->get_page();
128 152 }
129 153 unset($pages_list[0]);
130 154 return $pages_list;
@@ -130,6 +154,5 @@
130 154 return $pages_list;
131 155 }
132 156 return array();
133 157 }
134 -
135 158 }