PluginProbe
The WP Remote WordPress Plugin / 4.97
The WP Remote WordPress Plugin v4.97
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 4.97, at wp_db.php

223 lines 5.0 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);
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);
26 }
27
28 public function query($query) {
29 global $wpdb;
30 return $wpdb->query($query);
31 }
32
33 public function getVar($query, $col = 0, $row = 0) {
34 global $wpdb;
35 return $wpdb->get_var($query, $col, $row);
36 }
37
38 public function getCol($query, $col = 0) {
39 global $wpdb;
40 return $wpdb->get_col($query, $col);
41 }
42
43 public function tableName($table) {
44 return $table[0];
45 }
46
47 public function showTables() {
48 $tables = $this->getResult("SHOW TABLES", ARRAY_N);
49 return array_map(array($this, 'tableName'), $tables);
50 }
51
52 public function showTableStatus() {
53 return $this->getResult("SHOW TABLE STATUS");
54 }
55
56 public function tableKeys($table) {
57 return $this->getResult("SHOW KEYS FROM $table;");
58 }
59
60 public function describeTable($table) {
61 return $this->getResult("DESCRIBE $table;");
62 }
63
64 public function checkTable($table, $type) {
65 return $this->getResult("CHECK TABLE $table $type;");
66 }
67
68 public function repairTable($table) {
69 return $this->getResult("REPAIR TABLE $table;");
70 }
71
72 public function showTableCreate($table) {
73 return $this->getVar("SHOW CREATE TABLE $table;", 1);
74 }
75
76 public function rowsCount($table) {
77 $count = $this->getVar("SELECT COUNT(*) FROM $table;");
78 return intval($count);
79 }
80
81 public function createTable($query, $name, $usedbdelta = false) {
82 $table = $this->getBVTable($name);
83 if (!$this->isTablePresent($table)) {
84 if ($usedbdelta) {
85 if (!function_exists('dbDelta'))
86 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
87 dbDelta($query);
88 } else {
89 $this->query($query);
90 }
91 }
92 return $this->isTablePresent($table);
93 }
94
95 public function createTables($tables, $usedbdelta = false) {
96 $result = array();
97 foreach ($tables as $table => $query) {
98 $result[$table] = $this->createTable($query, $table, $usedbdelta);
99 }
100 return $result;
101 }
102
103 public function alterBVTable($query, $name) {
104 $resp = false;
105 $table = $this->getBVTable($name);
106 if ($this->isTablePresent($table)) {
107 $resp = $this->query($query);
108 }
109 return $resp;
110 }
111
112 public function alterTables($tables) {
113 $result = array();
114 foreach ($tables as $table => $query) {
115 $result[$table] = $this->alterBVTable($query, $table);
116 }
117 return $result;
118 }
119
120 public function getTableContent($table, $fields = '*', $filter = '', $limit = 0, $offset = 0) {
121 $query = "SELECT $fields from $table $filter";
122 if ($limit > 0)
123 $query .= " LIMIT $limit";
124 if ($offset > 0)
125 $query .= " OFFSET $offset";
126 $rows = $this->getResult($query);
127 return $rows;
128 }
129
130 public function isTablePresent($table) {
131 return ($this->getVar("SHOW TABLES LIKE '$table'") === $table);
132 }
133
134 public function getCharsetCollate() {
135 global $wpdb;
136 return $wpdb->get_charset_collate();
137 }
138
139 public function getWPTable($name) {
140 return ($this->dbprefix() . $name);
141 }
142
143 public function getBVTable($name) {
144 return ($this->getWPTable("bv_" . $name));
145 }
146
147 public function truncateBVTable($name) {
148 $table = $this->getBVTable($name);
149 if ($this->isTablePresent($table)) {
150 return $this->query("TRUNCATE TABLE $table;");
151 } else {
152 return false;
153 }
154 }
155
156 public function deleteBVTableContent($name, $filter = "") {
157 $table = $this->getBVTable($name);
158 if ($this->isTablePresent($table)) {
159 return $this->query("DELETE FROM $table $filter;");
160 } else {
161 return false;
162 }
163 }
164
165 public function dropBVTable($name) {
166 $table = $this->getBVTable($name);
167 if ($this->isTablePresent($table)) {
168 $this->query("DROP TABLE IF EXISTS $table;");
169 }
170 return !$this->isTablePresent($table);
171 }
172
173 public function dropTables($tables) {
174 $result = array();
175 foreach ($tables as $table) {
176 $result[$table] = $this->dropBVTable($table);
177 }
178 return $result;
179 }
180
181 public function truncateTables($tables) {
182 $result = array();
183 foreach ($tables as $table) {
184 $result[$table] = $this->truncateBVTable($table);
185 }
186 return $result;
187 }
188
189 public function deleteRowsFromtable($name, $count = 1) {
190 $table = $this->getBVTable($name);
191 if ($this->isTablePresent($table)) {
192 return $this->getResult("DELETE FROM $table LIMIT $count;");
193 } else {
194 return false;
195 }
196 }
197
198 public function replaceIntoBVTable($name, $value) {
199 global $wpdb;
200 $table = $this->getBVTable($name);
201 return $wpdb->replace($table, $value);
202 }
203
204 public function tinfo($name) {
205 $result = array();
206 $table = $this->getBVTable($name);
207
208 $result['name'] = $table;
209
210 if ($this->isTablePresent($table)) {
211 $result['exists'] = true;
212 $result['createquery'] = $this->showTableCreate($table);
213 }
214
215 return $result;
216 }
217
218 public function getMysqlVersion() {
219 global $wpdb;
220 return $wpdb->db_version();
221 }
222 }
223 endif;