PluginProbe
The WP Remote WordPress Plugin / 5.85
The WP Remote WordPress Plugin v5.85
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / wp_db.php

wp_db.php in The WP Remote WordPress Plugin 5.85, at wp_db.php

266 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('WPRWPDb')) :
5
6 class WPRWPDb {
7 public function dbprefix() {
8 global $wpdb;
9 $prefix = $wpdb->base_prefix ? $wpdb->base_prefix : $wpdb->prefix;
10 return $prefix;
11 }
12
13 public function prepare($query, $args) {
14 global $wpdb;
15 if (!empty($args)) {
16 return $wpdb->prepare($query, $args); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
17 }
18 return $query;
19 }
20
21 public function getSiteId() {
22 global $wpdb;
23 return $wpdb->siteid;
24 }
25
26 public function getResult($query, $args = array(), $obj = ARRAY_A) {
27 global $wpdb;
28 $prepared_query = $this->prepare($query, $args);
29 return $wpdb->get_results($prepared_query, $obj); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
30 }
31
32 public function query($query, $args = array()) {
33 global $wpdb;
34 $prepared_query = $this->prepare($query, $args);
35 return $wpdb->query($prepared_query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36 }
37
38 public function getVar($query, $args = array(), $col = 0, $row = 0) {
39 global $wpdb;
40 $prepared_query = $this->prepare($query, $args);
41 return $wpdb->get_var($prepared_query, $col, $row); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
42 }
43
44 public function getCol($query, $args = array(), $col = 0) {
45 global $wpdb;
46 $prepared_query = $this->prepare($query, $args);
47 return $wpdb->get_col($prepared_query, $col); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
48 }
49
50 public function getAutoIncrement($table_name) {
51 $query = "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s";
52 $results = $this->getResult($query, array($table_name), ARRAY_A);
53 $auto_increment = null;
54 if (empty($results)) {
55 return $auto_increment;
56 }
57 $row = $results[0];
58 if ($row && isset($row["AUTO_INCREMENT"]) && is_numeric($row["AUTO_INCREMENT"])) {
59 $auto_increment = intval($row["AUTO_INCREMENT"]);
60 }
61 return $auto_increment;
62 }
63
64 public function tableName($table) {
65 return $table[0];
66 }
67
68 public function showTables() {
69 $tables = $this->getResult("SHOW TABLES", array(), ARRAY_N);
70 return array_map(array($this, 'tableName'), $tables);
71 }
72
73 public function showTableStatus() {
74 return $this->getResult("SHOW TABLE STATUS");
75 }
76
77 public function tableKeys($table) {
78 return $this->getResult("SHOW KEYS FROM %i;", array($table));
79 }
80
81 public function showDbVariables($variable) {
82 $variables = $this->getResult("SHOW VARIABLES LIKE %s", array('%' . $variable . '%'));
83 $result = array();
84 foreach ($variables as $variable) {
85 $result[$variable["Variable_name"]] = $variable["Value"];
86 }
87 return $result;
88 }
89
90 public function describeTable($table) {
91 return $this->getResult("DESCRIBE $table;");
92 }
93
94 public function showTableIndex($table) {
95 return $this->getResult("SHOW INDEX FROM $table");
96 }
97
98 public function checkTable($table, $type) {
99 return $this->getResult("CHECK TABLE $table $type;");
100 }
101
102 public function repairTable($table) {
103 return $this->getResult("REPAIR TABLE %i;", array($table));
104 }
105
106 public function showTableCreate($table) {
107 return $this->getVar("SHOW CREATE TABLE $table", array(), 1);
108 }
109
110 public function rowsCount($table) {
111 $count = $this->getVar("SELECT COUNT(*) FROM $table;");
112 return intval($count);
113 }
114
115 public function createTable($query, $name, $usedbdelta = false) {
116 $table = $this->getBVTable($name);
117 if (!$this->isTablePresent($table)) {
118 if ($usedbdelta) {
119 if (!function_exists('dbDelta'))
120 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
121 dbDelta($query);
122 } else {
123 $this->query($query);
124 }
125 }
126 return $this->isTablePresent($table);
127 }
128
129 public function createTables($tables, $usedbdelta = false) {
130 $result = array();
131 foreach ($tables as $table => $query) {
132 $result[$table] = $this->createTable($query, $table, $usedbdelta);
133 }
134 return $result;
135 }
136
137 public function alterBVTable($query, $name) {
138 $resp = false;
139 $table = $this->getBVTable($name);
140 if ($this->isTablePresent($table)) {
141 $resp = $this->query($query);
142 }
143 return $resp;
144 }
145
146 public function alterTables($tables) {
147 $result = array();
148 foreach ($tables as $table => $query) {
149 $result[$table] = $this->alterBVTable($query, $table);
150 }
151 return $result;
152 }
153
154 public function getTableContent($table, $fields = '*', $filter = '', $limit = 0, $offset = 0) {
155 $query = "SELECT $fields FROM $table $filter";
156 $args = array();
157 if ($limit > 0) {
158 $query .= " LIMIT %d";
159 $args[] = $limit;
160 }
161 if ($offset > 0) {
162 $query .= " OFFSET %d";
163 $args[] = $offset;
164 }
165 return $this->getResult($query, $args);
166 }
167
168 public function isTablePresent($table) {
169 return ($this->getVar("SHOW TABLES LIKE %s", array($table)) === $table);
170 }
171
172 public function getCharsetCollate() {
173 global $wpdb;
174 return $wpdb->get_charset_collate();
175 }
176
177 public function getWPTable($name) {
178 return ($this->dbprefix() . $name);
179 }
180
181 public function getBVTable($name) {
182 return ($this->getWPTable("bv_" . $name));
183 }
184
185 public function truncateBVTable($name) {
186 $table = $this->getBVTable($name);
187 if ($this->isTablePresent($table)) {
188 return $this->query("TRUNCATE TABLE %i;", array($table));
189 } else {
190 return false;
191 }
192 }
193
194 public function deleteBVTableContent($name, $filter = "") {
195 $table = $this->getBVTable($name);
196 if ($this->isTablePresent($table)) {
197 return $this->query("DELETE FROM %i $filter", array($table));
198 } else {
199 return false;
200 }
201 }
202
203 public function dropBVTable($name) {
204 $table = $this->getBVTable($name);
205 if ($this->isTablePresent($table)) {
206 $this->query("DROP TABLE IF EXISTS %i;", array($table));
207 }
208 return !$this->isTablePresent($table);
209 }
210
211 public function dropTables($tables) {
212 $result = array();
213 foreach ($tables as $table) {
214 $result[$table] = $this->dropBVTable($table);
215 }
216 return $result;
217 }
218
219 public function truncateTables($tables) {
220 $result = array();
221 foreach ($tables as $table) {
222 $result[$table] = $this->truncateBVTable($table);
223 }
224 return $result;
225 }
226
227 public function deleteRowsFromtable($name, $count = 1) {
228 $table = $this->getBVTable($name);
229 if ($this->isTablePresent($table)) {
230 return $this->getResult("DELETE FROM %i LIMIT %d;", array($table, $count));
231 } else {
232 return false;
233 }
234 }
235
236 public function replaceIntoBVTable($name, $value) {
237 global $wpdb;
238 $table = $this->getBVTable($name);
239 return $wpdb->replace($table, $value);
240 }
241
242 public function insertIntoBVTable($name, $value) {
243 global $wpdb;
244 $table = $this->getBVTable($name);
245 return $wpdb->insert($table, $value);
246 }
247
248 public function tinfo($name) {
249 $result = array();
250 $table = $this->getBVTable($name);
251
252 $result['name'] = $table;
253
254 if ($this->isTablePresent($table)) {
255 $result['exists'] = true;
256 $result['createquery'] = $this->showTableCreate($table);
257 }
258
259 return $result;
260 }
261
262 public function getMysqlVersion() {
263 return $this->showDbVariables('version')['version'];
264 }
265 }
266 endif;