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

191 lines 4.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);
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 alterBVTable($query, $name) {
96 $resp = false;
97 $table = $this->getBVTable($name);
98 if ($this->isTablePresent($table)) {
99 $resp = $this->query($query);
100 }
101 return $resp;
102 }
103
104 public function getTableContent($table, $fields = '*', $filter = '', $limit = 0, $offset = 0) {
105 $query = "SELECT $fields from $table $filter";
106 if ($limit > 0)
107 $query .= " LIMIT $limit";
108 if ($offset > 0)
109 $query .= " OFFSET $offset";
110 $rows = $this->getResult($query);
111 return $rows;
112 }
113
114 public function isTablePresent($table) {
115 return ($this->getVar("SHOW TABLES LIKE '$table'") === $table);
116 }
117
118 public function getCharsetCollate() {
119 global $wpdb;
120 return $wpdb->get_charset_collate();
121 }
122
123 public function getWPTable($name) {
124 return ($this->dbprefix() . $name);
125 }
126
127 public function getBVTable($name) {
128 return ($this->getWPTable("bv_" . $name));
129 }
130
131 public function truncateBVTable($name) {
132 $table = $this->getBVTable($name);
133 if ($this->isTablePresent($table)) {
134 return $this->query("TRUNCATE TABLE $table;");
135 } else {
136 return false;
137 }
138 }
139
140 public function deleteBVTableContent($name, $filter = "") {
141 $table = $this->getBVTable($name);
142 if ($this->isTablePresent($table)) {
143 return $this->query("DELETE FROM $table $filter;");
144 } else {
145 return false;
146 }
147 }
148
149 public function dropBVTable($name) {
150 $table = $this->getBVTable($name);
151 if ($this->isTablePresent($table)) {
152 $this->query("DROP TABLE IF EXISTS $table;");
153 }
154 return !$this->isTablePresent($table);
155 }
156
157 public function deleteRowsFromtable($name, $count = 1) {
158 $table = $this->getBVTable($name);
159 if ($this->isTablePresent($table)) {
160 return $this->getResult("DELETE FROM $table LIMIT $count;");
161 } else {
162 return false;
163 }
164 }
165
166 public function replaceIntoBVTable($name, $value) {
167 global $wpdb;
168 $table = $this->getBVTable($name);
169 return $wpdb->replace($table, $value);
170 }
171
172 public function tinfo($name) {
173 $result = array();
174 $table = $this->getBVTable($name);
175
176 $result['name'] = $table;
177
178 if ($this->isTablePresent($table)) {
179 $result['exists'] = true;
180 $result['createquery'] = $this->showTableCreate($table);
181 }
182
183 return $result;
184 }
185
186 public function getMysqlVersion() {
187 global $wpdb;
188 return $wpdb->db_version();
189 }
190 }
191 endif;