PluginProbe
The WP Remote WordPress Plugin / 5.88
The WP Remote WordPress Plugin v5.88
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.88, at wp_db.php

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