PluginProbe
The WP Remote WordPress Plugin / 4.84
The WP Remote WordPress Plugin v4.84
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 / callback / wings / db.php

db.php in The WP Remote WordPress Plugin 4.84, at callback/wings/db.php

328 lines 10.4 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('BVDBCallback')) :
5 require_once dirname( __FILE__ ) . '/../streams.php';
6
7 class BVDBCallback extends BVCallbackBase {
8 public $db;
9 public $stream;
10 public $account;
11
12 public static $bvTables = array("fw_requests", "lp_requests", "ip_store");
13
14 const DB_WING_VERSION = 1.1;
15
16 public function __construct($callback_handler) {
17 $this->db = $callback_handler->db;
18 $this->account = $callback_handler->account;
19 $this->siteinfo = $callback_handler->siteinfo;
20 }
21
22 public function getLastID($pkeys, $end_row) {
23 $last_ids = array();
24 foreach($pkeys as $pk) {
25 $last_ids[$pk] = $end_row[$pk];
26 }
27 return $last_ids;
28 }
29
30 public function getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) {
31 $tinfo = array();
32
33 $rows_count = $this->db->rowsCount($table);
34 $result = array('count' => $rows_count);
35 if ($limit == 0) {
36 $limit = $rows_count;
37 }
38 $srows = 1;
39 while (($limit > 0) && ($srows > 0)) {
40 if ($bsize > $limit)
41 $bsize = $limit;
42 $rows = $this->db->getTableContent($table, '*', $filter, $bsize, $offset);
43 $srows = sizeof($rows);
44 $data = array();
45 $data["table_name"] = $tname;
46 $data["offset"] = $offset;
47 $data["size"] = $srows;
48 $serialized_rows = serialize($rows);
49 $data['md5'] = md5($serialized_rows);
50 $data['length'] = strlen($serialized_rows);
51 array_push($tinfo, $data);
52 if (!empty($pkeys) && $srows > 0) {
53 $end_row = end($rows);
54 $last_ids = $this->getLastID($pkeys, $end_row);
55 $data['last_ids'] = $last_ids;
56 $result['last_ids'] = $last_ids;
57 }
58 if ($include_rows) {
59 $data["rows"] = $rows;
60 $str = serialize($data);
61 $this->stream->writeStream($str);
62 }
63 $offset += $srows;
64 $limit -= $srows;
65 }
66 $result['size'] = $offset;
67 $result['tinfo'] = $tinfo;
68 return $result;
69 }
70
71 public function getCreateTableQueries($tables) {
72 $resp = array();
73 foreach($tables as $table) {
74 $tname = urldecode($table);
75 $resp[$tname] = array("create" => $this->db->showTableCreate($table));
76 }
77 return $resp;
78 }
79
80 public function checkTables($tables, $type) {
81 $resp = array();
82 foreach($tables as $table) {
83 $tname = urldecode($table);
84 $resp[$tname] = array("status" => $this->db->checkTable($table, $type));
85 }
86 return $resp;
87 }
88
89 public function describeTables($tables) {
90 $resp = array();
91 foreach($tables as $table) {
92 $tname = urldecode($table);
93 $resp[$tname] = array("description" => $this->db->describeTable($table));
94 }
95 return $resp;
96 }
97
98 public function checkTablesExist($tables) {
99 $resp = array();
100 foreach($tables as $table) {
101 $tname = urldecode($table);
102 $resp[$tname] = array("tblexists" => $this->db->isTablePresent($table));
103 }
104 return $resp;
105 }
106
107 public function getTablesRowCount($tables) {
108 $resp = array();
109 foreach($tables as $table) {
110 $tname = urldecode($table);
111 $resp[$tname] = array("count" => $this->db->rowsCount($table));
112 }
113 return $resp;
114 }
115
116 public function getTablesKeys($tables) {
117 $resp = array();
118 foreach($tables as $table) {
119 $tname = urldecode($table);
120 $resp[$tname] = array("keys" => $this->db->tableKeys($table));
121 }
122 return $resp;
123 }
124
125 public function multiGetResult($queries) {
126 $resp = array();
127 foreach($queries as $query) {
128 array_push($resp, $this->db->getResult($query));
129 }
130 return $resp;
131 }
132
133 public function process($request) {
134 $db = $this->db;
135 $params = $request->params;
136 $stream_init_info = BVStream::startStream($this->account, $request);
137
138 if (array_key_exists('stream', $stream_init_info)) {
139 $this->stream = $stream_init_info['stream'];
140 switch ($request->method) {
141 case "gettbls":
142 $resp = array("tables" => $db->showTables());
143 break;
144 case "tblstatus":
145 $resp = array("statuses" => $db->showTableStatus());
146 break;
147 case "tablekeys":
148 $table = urldecode($params['table']);
149 $resp = array("table_keys" => $db->tableKeys($table));
150 break;
151 case "describetable":
152 $table = urldecode($params['table']);
153 $resp = array("table_description" => $db->describeTable($table));
154 break;
155 case "checktable":
156 $table = urldecode($params['table']);
157 $type = urldecode($params['type']);
158 $resp = array("status" => $db->checkTable($table, $type));
159 break;
160 case "repairtable":
161 $table = urldecode($params['table']);
162 $resp = array("status" => $db->repairTable($table));
163 break;
164 case "gettcrt":
165 $table = urldecode($params['table']);
166 $resp = array("create" => $db->showTableCreate($table));
167 break;
168 case "tblskys":
169 $tables = $params['tables'];
170 $resp = $this->getTablesKeys($tables);
171 break;
172 case "getmlticrt":
173 $tables = $params['tables'];
174 $resp = $this->getCreateTableQueries($tables);
175 break;
176 case "desctbls":
177 $tables = $params['tables'];
178 $resp = $this->describeTables($tables);
179 break;
180 case "mltirwscount":
181 $tables = $params['tables'];
182 $resp = $this->getTablesRowCount($tables);
183 break;
184 case "chktabls":
185 $tables = $params['tables'];
186 $type = urldecode($params['type']);
187 $resp = $this->checkTables($tables, $type);
188 break;
189 case "chktablsxist":
190 $tables = $params['tables'];
191 $resp = $this->checkTablesExist($tables);
192 break;
193 case "getrowscount":
194 $table = urldecode($params['table']);
195 $resp = array("count" => $db->rowsCount($table));
196 break;
197 case "gettablecontent":
198 $result = array();
199 $table = urldecode($params['table']);
200 $fields = urldecode($params['fields']);
201 $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : "";
202 $limit = intval(urldecode($params['limit']));
203 $offset = intval(urldecode($params['offset']));
204 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
205 $result['timestamp'] = time();
206 $result['tablename'] = $table;
207 $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset);
208 $srows = sizeof($rows);
209 if (!empty($pkeys) && $srows > 0) {
210 $end_row = end($rows);
211 $result['last_ids'] = $this->getLastID($pkeys, $end_row);
212 }
213 $result["rows"] = $rows;
214 $resp = $result;
215 break;
216 case "multitablecontent":
217 $tableParams = $params['table_params'];
218 $resp = array();
219 foreach($tableParams as $tableParam) {
220 $result = array();
221 $identifier = $tableParam['identifier'];
222 $table = $tableParam['table'];
223 $tname = $tableParam['tname'];
224 $fields = $tableParam['fields'];
225 $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : "";
226 $limit = $tableParam['limit'];
227 $offset = $tableParam['offset'];
228 $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array();
229 $result['timestamp'] = time();
230 $result['table_name'] = $tname;
231 $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset);
232 $srows = sizeof($rows);
233 if (!empty($pkeys) && $srows > 0) {
234 $end_row = end($rows);
235 $result['last_ids'] = $this->getLastID($pkeys, $end_row);
236 }
237 $result["rows"] = $rows;
238 $result["size"] = $srows;
239 $resp[$identifier] = $result;
240 }
241 break;
242 case "tableinfo":
243 $table = urldecode($params['table']);
244 $offset = intval(urldecode($params['offset']));
245 $limit = intval(urldecode($params['limit']));
246 $bsize = intval(urldecode($params['bsize']));
247 $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : "";
248 $rcount = intval(urldecode($params['rcount']));
249 $tname = urldecode($params['tname']);
250 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
251 $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, false);
252 break;
253 case "getmulttables":
254 $result = array();
255 $tableParams = $params['table_params'];
256 $resp = array();
257 foreach($tableParams as $tableParam) {
258 $table = urldecode($tableParam['table']);
259 $tname = urldecode($tableParam['tname']);
260 $rcount = intval(urldecode($tableParam['rcount']));
261 $filter = (array_key_exists('filter', $tableParam)) ? urldecode($tableParam['filter']) : "";
262 $limit = intval(urldecode($tableParam['limit']));
263 $offset = intval(urldecode($tableParam['offset']));
264 $bsize = intval(urldecode($tableParam['bsize']));
265 $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array();
266 $resp[$tname] = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true);
267 }
268 break;
269 case "uploadrows":
270 $table = urldecode($params['table']);
271 $offset = intval(urldecode($params['offset']));
272 $limit = intval(urldecode($params['limit']));
273 $bsize = intval(urldecode($params['bsize']));
274 $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : "";
275 $rcount = intval(urldecode($params['rcount']));
276 $tname = urldecode($params['tname']);
277 $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array();
278 $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true);
279 break;
280 case "tblexists":
281 $resp = array("tblexists" => $db->isTablePresent($params['table']));
282 break;
283 case "crttbl":
284 $usedbdelta = array_key_exists('usedbdelta', $params);
285 $resp = array("crttbl" => $db->createTable($params['query'], $params['table'], $usedbdelta));
286 break;
287 case "drptbl":
288 $resp = array("drptbl" => $db->dropBVTable($params['table']));
289 break;
290 case "trttbl":
291 $resp = array("trttbl" => $db->truncateBVTable($params['table']));
292 break;
293 case "altrtbl":
294 $resp = array("altrtbl" => $db->alterBVTable($params['query'], $params['query']));
295 break;
296 case "mltigtrslt":
297 $resp = array("mltigtrslt" => $this->multiGetResult($params['queries']));
298 break;
299 case "tbls":
300 $resp = array();
301
302 if (array_key_exists('truncate', $params))
303 $resp['truncate'] = $db->truncateTables($params['truncate']);
304
305 if (array_key_exists('drop', $params))
306 $resp['drop'] = $db->dropTables($params['drop']);
307
308 if (array_key_exists('create', $params))
309 $resp['create'] = $db->createTables($params['create']);
310
311 if (array_key_exists('alter', $params))
312 $resp['alter'] = $db->alterTables($params['alter']);
313
314 break;
315 default:
316 $resp = false;
317 }
318 $end_stream_info = $this->stream->endStream();
319 if (!empty($end_stream_info) && is_array($resp)) {
320 $resp = array_merge($resp, $end_stream_info);
321 }
322 } else {
323 $resp = $stream_init_info;
324 }
325 return $resp;
326 }
327 }
328 endif;