PluginProbe
CSS & JavaScript Toolbox / 6.0.6
CSS & JavaScript Toolbox v6.0.6
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | framework/db/mysql/queue-driver.inc.php +64 -94 trunk6.0.6 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 -*
3 +*
4 4 */
5 5
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
@@ -6,15 +6,15 @@
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
8 8
9 9 /**
10 -*
10 +*
11 11 */
12 12 class CJTMYSQLQueueDriver extends CJTHookableClass {
13 -
13 +
14 14 /**
15 15 * put your comment there...
16 - *
16 + *
17 17 * @var mixed
18 18 */
19 19 protected $queue = array();
20 20
@@ -19,16 +19,16 @@
19 19 protected $queue = array();
20 20
21 21 /**
22 22 * put your comment there...
23 - *
23 + *
24 24 * @var mixed
25 25 */
26 26 protected $onexec = array('parameters' => array('param'));
27 -
27 +
28 28 /**
29 29 * put your comment there...
30 - *
30 + *
31 31 * @var mixed
32 32 */
33 33 protected $onprocessqueue = array('parameters' => array('queue'));
34 34
@@ -33,16 +33,16 @@
33 33 protected $onprocessqueue = array('parameters' => array('queue'));
34 34
35 35 /**
36 36 * put your comment there...
37 - *
37 + *
38 38 * @var mixed
39 39 */
40 40 protected $onprocesscommand = array('parameters' => array('command'));
41 -
41 +
42 42 /**
43 43 * put your comment there...
44 - *
44 + *
45 45 * @var mixed
46 46 */
47 47 protected $onqueue = array('parameters' => array('query'));
48 48
@@ -47,9 +47,9 @@
47 47 protected $onqueue = array('parameters' => array('query'));
48 48
49 49 /**
50 50 * put your comment there...
51 - *
51 + *
52 52 * @var mixed
53 53 */
54 54 protected $onqueuereturn = array('parameters' => array('driver'));
55 55
@@ -54,23 +54,23 @@
54 54 protected $onqueuereturn = array('parameters' => array('driver'));
55 55
56 56 /**
57 57 * put your comment there...
58 - *
58 + *
59 59 * @var mixed
60 60 */
61 61 protected $onselect = array('parameters' => array('param'));
62 -
62 +
63 63 /**
64 64 * put your comment there...
65 - *
65 + *
66 66 * @var mixed
67 67 */
68 68 private $wpdb = null;
69 -
69 +
70 70 /**
71 71 * put your comment there...
72 - *
72 + *
73 73 */
74 74 public function __construct($mysqlDriver) {
75 75 // Hookable!
76 76 parent::__construct();
@@ -76,12 +76,12 @@
76 76 parent::__construct();
77 77 // Internal DB engine!
78 78 $this->wpdb = $mysqlDriver;
79 79 }
80 -
80 +
81 81 /**
82 82 * put your comment there...
83 - *
83 + *
84 84 * @param mixed $query
85 85 */
86 86 protected function addQueue($query) {
87 87 $query = $this->resolveTableName($query);
@@ -86,57 +86,52 @@
86 86 protected function addQueue($query) {
87 87 $query = $this->resolveTableName($query);
88 88 $key = md5($query);
89 89 if ($query = $this->onqueue($query)) {
90 - $this->queue[$key] = $query;
90 + $this->queue[$key] = $query;
91 91 }
92 92 return $this->onqueuereturn($this);
93 93 }
94 -
94 +
95 95 /**
96 96 * put your comment there...
97 - *
97 + *
98 98 */
99 99 public function clear() {
100 100 $this->queue = array();
101 101 }
102 -
102 +
103 103 /**
104 104 * Put your comments here...
105 105 *
106 106 *
107 - * @return
108 - */
107 + * @return
108 + */
109 109 public function commit() {
110 110 $this->addQueue('COMMIT;');
111 111 return $this;
112 112 }
113 -
113 +
114 114 /**
115 115 * put your comment there...
116 - *
116 + *
117 117 * @param mixed $query
118 118 */
119 119 public function delete($query) {
120 120 return $this->addQueue($query);
121 121 }
122 -
122 +
123 123 /**
124 124 * put your comment there...
125 - *
125 + *
126 126 * @param string $data
127 127 * @param mixed $field
128 128 * @return string
129 129 */
130 130 public function escapeValue($data, $field) {
131 - # MYSQLI doesn't has numeric field.
132 - if ($this->wpdb->use_mysqli) {
133 - $field->numeric = $field->flags & MYSQLI_NUM_FLAG;
134 - }
135 - # Check if numeric
136 131 switch ($field->numeric) {
137 132 case 0:
138 - $data = esc_sql($data);
133 + $data = mysql_real_escape_string($data, $this->wpdb->dbh);
139 134 $data = "'{$data}'";
140 135 break;
141 136 case 1:
142 137 $data = (int) $data;
@@ -143,12 +138,12 @@
143 138 break;
144 139 }
145 140 return $data;
146 141 }
147 -
142 +
148 143 /**
149 144 * put your comment there...
150 - *
145 + *
151 146 * @param mixed $query
152 147 */
153 148 public function exec($query) {
154 149 // Initialize!
@@ -158,29 +153,20 @@
158 153 extract($this->onexec(compact('query', 'resultSet')));
159 154 // filter can controller the returned value or customize the query!
160 155 if ($query && empty($result)) {
161 156 $result = $this->wpdb->query($query);
162 -
163 - if ( strpos( $query, 'SHOW TABLES' ) !== false && ! $result ) {
164 - echo 'Some tables could not be created! Please contact support with the error';
165 - echo '<br><strong>' . str_replace( 'SHOW TABLES LIKE ', '', $query ) . '</strong>';
166 -
167 - wp_die();
168 - }
169 157 }
170 -
171 -
172 158 return $result;
173 159 }
174 -
160 +
175 161 /**
176 162 * put your comment there...
177 - *
163 + *
178 164 * @param mixed $table
179 165 */
180 166 public function getColumns($table) {
181 167 $columns = array();
182 - $this->select("SELECT * FROM {$table} WHERE 1!=1 LIMIT 0,1;");
168 + $this->select("SELECT * FROM {$table} WHERE 1!=1;");
183 169 // Use field name as element key.
184 170 foreach ($this->wpdb->col_info as $index => $column) {
185 171 $columns[$column->name] = $column;
186 172 }
@@ -188,61 +174,45 @@
188 174 }
189 175
190 176 /**
191 177 * put your comment there...
192 - *
178 + *
193 179 */
194 180 public function getInsertId () {
195 - return $this->wpdb->insert_id;
181 + return $this->wpdb->insert_id;
196 182 }
197 -
183 +
198 184 /**
199 185 * put your comment there...
200 - *
201 - * @param mixed $query
202 - * @param mixed $returnType
203 - * @param mixed $default
186 + *
204 187 */
205 - public function getRow($query, $returnType = OBJECT_K, $default = null) {
206 - $row = null;
207 - // Fetch al result set!
208 - $result = $this->select($query, $returnType);
209 - if ($result) {
210 - $row = reset($result);
211 - }
212 - return $row;
213 - }
214 - /**
215 - * put your comment there...
216 - *
217 - */
218 188 public function getTableName($table) {
219 189 return "{$this->wpdb->prefix}{$table}";
220 190 }
221 -
191 +
222 192 /**
223 193 * put your comment there...
224 - *
194 + *
225 195 */
226 196 public function getVar($query, $row = 0, $column = 0) {
227 197 return $this->wpdb->get_var($query, $row, $column);
228 198 }
229 -
199 +
230 200 /**
231 201 * put your comment there...
232 - *
202 + *
233 203 * @param mixed $query
234 204 */
235 205 public function insert($query) {
236 206 return $this->addQueue($query);
237 207 }
238 -
208 +
239 209 /**
240 210 * Put your comments here...
241 211 *
242 212 *
243 - * @return
244 - */
213 + * @return
214 + */
245 215 public function merge($driver) {
246 216 // Put target driver queue at the end of our queue.
247 217 $this->queue = array_merge($this->queue, $driver->queue);
248 218 }
@@ -248,9 +218,9 @@
248 218 }
249 219
250 220 /**
251 221 * put your comment there...
252 - *
222 + *
253 223 * @param mixed $parameters
254 224 * @param mixed $operators
255 225 * @param mixed $defaultOperator
256 226 * @param mixed $excludeNulls
@@ -269,17 +239,17 @@
269 239 $value = $this->escapeValue($value, $field);
270 240 // Get name-value operator.
271 241 $operator = isset($operators[$name]) ? $operators[$name] : $defaultOperator;
272 242 $prepared[] = "`{$name}`{$operator}{$value}";
273 - }
243 + }
274 244 }
275 245 }
276 246 return $prepared;
277 247 }
278 -
248 +
279 249 /**
280 250 * put your comment there...
281 - *
251 + *
282 252 */
283 253 public function processQueue() {
284 254 $queue = $this->onprocessqueue($this->queue);
285 255 // Collect queue commands.
@@ -290,12 +260,12 @@
290 260 $this->clear();
291 261 // Chain.
292 262 return $this;
293 263 }
294 -
264 +
295 265 /**
296 266 * put your comment there...
297 - *
267 + *
298 268 * @param mixed $query
299 269 */
300 270 public function resolveTableName($query) {
301 271 // Define list of Prefixes to be replaced with Wordpress table prefix!
@@ -307,31 +277,31 @@
307 277 }
308 278 // Return new query with table names resolved.
309 279 return $query;
310 280 }
311 -
281 +
312 282 /**
313 283 * Put your comments here...
314 284 *
315 285 *
316 - * @return
317 - */
286 + * @return
287 + */
318 288 public function rollback() {
319 289 $this->addQueue('ROLLBACK;');
320 290 return $this;
321 291 }
322 -
292 +
323 293 /**
324 294 * put your comment there...
325 - *
295 + *
326 296 */
327 297 public function row($query) {
328 298 return $this->wpdb->get_row($query);
329 299 }
330 -
300 +
331 301 /**
332 302 * put your comment there...
333 - *
303 + *
334 304 * @param mixed $query
335 305 */
336 306 public function select($query, $returnType = OBJECT_K) {
337 307 // Initialize!
@@ -344,29 +314,29 @@
344 314 $resultSet = $this->wpdb->get_results($query, $returnType);
345 315 }
346 316 return $resultSet;
347 317 }
348 -
318 +
349 319 /**
350 320 * Put your comments here...
351 321 *
352 322 *
353 - * @return
354 - */
323 + * @return
324 + */
355 325 public function startTransaction() {
356 326 $this->addQueue('BEGIN WORK;');
357 327 return $this;
358 328 }
359 -
329 +
360 330 /**
361 331 * put your comment there...
362 - *
332 + *
363 333 * @param mixed $query
364 334 */
365 335 public function update($query) {
366 336 return $this->addQueue($query);
367 337 }
368 -
338 +
369 339 } // End class.
370 340
371 341 // Hooking!
372 342 CJTMYSQLQueueDriver::define('CJTMYSQLQueueDriver', array('hookType' => CJTWordpressEvents::HOOK_FILTER));