PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
← All changes | classes/max-utils.php +233 -232 6.246.28 View file →
@@ -1,39 +1,39 @@
1 1 <?php
2 2 namespace MaxButtons;
3 3 defined('ABSPATH') or die('No direct access permitted');
4 4
5 -// new class for the future.
5 +// new class for the future.
6 6 class maxUtils
7 7 {
8 -
8 +
9 9 protected static $timings = array();
10 - protected static $time_operations = array();
10 + protected static $time_operations = array();
11 11 protected static $timer = 0;
12 -
13 -
14 - /** Callback for array filter to prepend namepaces. **/
15 - public static function array_namespace($var)
12 +
13 +
14 + /** Callback for array filter to prepend namepaces. **/
15 + public static function array_namespace($var)
16 16 {
17 - $namespace = __NAMESPACE__ . '\\'; // PHP 5.3
18 - return ($namespace . $var);
19 - }
20 -
17 + $namespace = __NAMESPACE__ . '\\'; // PHP 5.3
18 + return ($namespace . $var);
19 + }
20 +
21 21 public static function namespaceit($var)
22 22 {
23 - $namespace = __NAMESPACE__ . '\\'; // PHP 5.3
23 + $namespace = __NAMESPACE__ . '\\'; // PHP 5.3
24 24 return $namespace . $var;
25 25 }
26 -
27 - // central ajax action handler
26 +
27 + // central ajax action handler
28 28 public static function ajax_action()
29 29 {
30 - $status = 'error';
30 + $status = 'error';
31 31
32 - $plugin_action = isset($_POST['plugin_action']) ? sanitize_text_field($_POST['plugin_action']) : '';
33 - $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : false;
34 - $message = __( sprintf("No Handler found for action %s ", $plugin_action), 'maxbuttons');
35 -
32 + $plugin_action = isset($_POST['plugin_action']) ? sanitize_text_field($_POST['plugin_action']) : '';
33 + $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : false;
34 + $message = __( sprintf("No Handler found for action %s ", $plugin_action), 'maxbuttons');
35 +
36 36 if (! wp_verify_nonce($nonce, 'maxajax') )
37 37 {
38 38 $message = __('Nonce not verified', 'maxbuttons');
39 39 }
@@ -38,22 +38,23 @@
38 38 $message = __('Nonce not verified', 'maxbuttons');
39 39 }
40 40 else
41 41 {
42 - do_action('maxbuttons/ajax/' . $plugin_action, $_POST);
42 + do_action('maxbuttons/ajax/' . $plugin_action, $_POST);
43 43 }
44 -
45 - echo json_encode( array( 'status' => $status,
46 - 'message' => $message,
44 +
45 + echo json_encode( array( 'status' => $status,
46 + 'message' => $message,
47 47 )
48 - );
49 - wp_die();
48 + );
49 + wp_die();
50 50 }
51 -
52 - public static function translit($string)
51 +
52 + public static function translit($string)
53 53 {
54 - require_once(MB()->get_plugin_path() . "assets/libraries/url_slug.php");
55 - $string = mb_url_slug($string, array("transliterate" => true));
54 + require_once(MB()->get_plugin_path() . "assets/libraries/url_slug.php");
55 +
56 + $string = mb_url_slug($string, array("transliterate" => true));
56 57 return $string;
57 58 }
58 59
59 60 public static function selectify($name, $array, $selected, $target = '', $class = '')
@@ -58,22 +59,22 @@
58 59
59 60 public static function selectify($name, $array, $selected, $target = '', $class = '')
60 61 {
61 62 // optional target for js updating
62 - if ($target != '' )
63 - $target = " data-target='$target' ";
64 - if ($class != '')
65 - $class = " class='$class' ";
63 + if ($target != '' )
64 + $target = " data-target='$target' ";
65 + if ($class != '')
66 + $class = " class='$class' ";
66 67 $output = "<select name='$name' id='$name' $target $class>";
67 -
68 - foreach($array as $key => $value)
68 +
69 + foreach($array as $key => $value)
69 70 {
70 - $output .= "<option value='$key' " . selected($key, $selected, false) . ">$value</option>";
71 + $output .= "<option value='$key' " . selected($key, $selected, false) . ">$value</option>";
71 72 }
72 - $output .= "</select>";
73 -
73 + $output .= "</select>";
74 +
74 75 return $output;
75 -
76 +
76 77 }
77 78
78 79
79 80 static function hex2rgba($color, $opacity) {
@@ -91,12 +92,12 @@
91 92 $r = hexdec(substr($hex, 0, 2));
92 93 $g = hexdec(substr($hex, 2, 2));
93 94 $b = hexdec(substr($hex, 4, 2));
94 95 }
95 -
96 +
96 97 // The array of rgb values
97 98 $rgb_array = array($r, $g, $b);
98 -
99 +
99 100 // Catch for opacity when the button has not been saved
100 101 if($opacity == '') {
101 102 $alpha = 1;
102 103 } else {
@@ -105,257 +106,257 @@
105 106 }
106 107
107 108 // The rgb values separated by commas
108 109 $rgb = implode(", ", $rgb_array);
109 -
110 +
110 111 // Spits out rgba(0, 0, 0, 0.5) format
111 112 return 'rgba(' . $rgb . ', ' . $alpha . ')';
112 113 }
113 -
114 +
114 115 static function strip_px($value) {
115 116 return rtrim( intval($value), 'px');
116 117 }
117 118
118 - static function generate_font_sizes($start, $end, $step = 1)
119 + static function generate_font_sizes($start, $end, $step = 1)
119 120 {
120 - $sizes = array();
121 -
121 + $sizes = array();
122 +
122 123 for ($i = $start; $i <= $end; $i += $step)
123 124 {
124 - $sizes[$i] = $i;
125 -
125 + $sizes[$i] = $i;
126 +
126 127 }
127 - return $sizes;
128 -
128 + return $sizes;
129 +
129 130 }
130 131
131 132
132 133 static function get_media_query($get_option = 1)
133 134 {
134 -
135 +
135 136 $queries = array("phone" => "only screen and (max-width : 480px)",
136 - "phone_land" => "only screen and (min-width : 321px) and (max-width : 480px)",
137 - "phone_portrait" => " only screen and (max-width : 320px)",
137 + "phone_land" => "only screen and (min-width : 321px) and (max-width : 480px)",
138 + "phone_portrait" => " only screen and (max-width : 320px)",
138 139 "ipad" => "only screen and (min-width : 768px) and (max-width : 1024px)",
139 140 "medium_phone" => "only screen and (min-width: 480px) and (max-width: 768px)",
140 - "ipad_land" => "only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape)",
141 + "ipad_land" => "only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape)",
141 142 "ipad_portrait" => "only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait)",
142 143 "desktop" => "only screen and (min-width : 1224px)",
143 - "large_desktop" => "only screen and (min-width : 1824px)",
144 + "large_desktop" => "only screen and (min-width : 1824px)",
144 145 );
145 -
146 +
146 147 $query_names = array(
147 - "phone" => __("Small phones","maxbuttons"),
148 - "phone_land" => __("Small phones (landscape)","maxbuttons"),
149 - "phone_portrait" => __("Small phones (portrait)","maxbuttons"),
148 + "phone" => __("Small phones","maxbuttons"),
149 + "phone_land" => __("Small phones (landscape)","maxbuttons"),
150 + "phone_portrait" => __("Small phones (portrait)","maxbuttons"),
150 151 "medium_phone" => __("Medium-size (smart)phone","maxbuttons"),
151 152 "ipad" => __("Ipad (all) / Large phones","maxbuttons"),
152 - "ipad_land" => __("Ipad landscape","maxbuttons"),
153 + "ipad_land" => __("Ipad landscape","maxbuttons"),
153 154 "ipad_portrait" => __("Ipad portrait","maxbuttons"),
154 155 "desktop" => __("Desktop","maxbuttons"),
155 - "large_desktop" => __("Large desktops","maxbuttons"),
156 - "custom" => __("Custom size","maxbuttons"),
157 - );
158 -
156 + "large_desktop" => __("Large desktops","maxbuttons"),
157 + "custom" => __("Custom size","maxbuttons"),
158 + );
159 +
159 160 $query_descriptions = array(
160 161 "phone" => __("Optimized for small smartphones ( screen sizes under 480px )","maxbuttons"),
161 - "phone_land" => __("Optimzed for small smartphones in landscape and higher ( screen sizes 321px - 480px)","maxbuttons"),
162 - "phone_portrait" => __("Optimized for small phones ( screen size max 320px )","maxbuttons"),
163 - "ipad" => __("Optimized for devices between 768px and 1024px","maxbuttons"),
164 - "medium_phone" => __("Optimized for medium sizes devices between 480px and 768px","maxbuttons"),
165 - "ipad_land" => __("Optimized for devices between 768px and 1024px in landscape","maxbuttons"),
166 - "ipad_portrait" => __("Optimized for deviced between 768px and 1024 in portrait","maxbuttons"),
162 + "phone_land" => __("Optimzed for small smartphones in landscape and higher ( screen sizes 321px - 480px)","maxbuttons"),
163 + "phone_portrait" => __("Optimized for small phones ( screen size max 320px )","maxbuttons"),
164 + "ipad" => __("Optimized for devices between 768px and 1024px","maxbuttons"),
165 + "medium_phone" => __("Optimized for medium sizes devices between 480px and 768px","maxbuttons"),
166 + "ipad_land" => __("Optimized for devices between 768px and 1024px in landscape","maxbuttons"),
167 + "ipad_portrait" => __("Optimized for deviced between 768px and 1024 in portrait","maxbuttons"),
167 168 "desktop" => __("Desktop screens from 1224px","maxbuttons"),
168 169 "large_desktop" => __("Large desktop screens, from 1824px","maxbuttons"),
169 - "custom" => __("Set your own breakpoints","maxbuttons"),
170 - );
171 -
172 -
170 + "custom" => __("Set your own breakpoints","maxbuttons"),
171 + );
172 +
173 +
173 174 switch($get_option)
174 175 {
175 - case 1:
176 + case 1:
176 177 return $query_names;
177 178 break;
178 - case 2:
179 - return $queries;
179 + case 2:
180 + return $queries;
180 181 break;
181 - case 3:
182 + case 3:
182 183 return $query_descriptions;
183 184 break;
184 185 }
185 -
186 +
186 187 }
187 -
188 - static function get_buttons_table_name($old = false)
188 +
189 + static function get_buttons_table_name($old = false)
189 190 {
190 - self::addTime('Legacy Function call : get_buttons_table_name');
191 + self::addTime('Legacy Function call : get_buttons_table_name');
191 192 return self::get_table_name($old);
192 193 }
193 -
194 +
194 195 static function get_table_name($old = false) {
195 196 global $wpdb;
196 197 if ($old)
197 198 return $wpdb->prefix . 'maxbuttons_buttons';
198 199 else
199 - return $wpdb->prefix . 'maxbuttonsv3';
200 + return $wpdb->prefix . 'maxbuttonsv3';
200 201 }
201 202
202 - static function get_collection_table_name() {
203 - global $wpdb;
204 - return $wpdb->prefix . 'maxbuttons_collections';
205 -
203 + static function get_collection_table_name() {
204 + global $wpdb;
205 + return $wpdb->prefix . 'maxbuttons_collections';
206 +
206 207 }
207 208
208 - static function get_coltrans_table_name() {
209 - global $wpdb;
210 - return $wpdb->prefix . 'maxbuttons_collections_trans';
211 -
209 + static function get_coltrans_table_name() {
210 + global $wpdb;
211 + return $wpdb->prefix . 'maxbuttons_collections_trans';
212 +
212 213 }
213 -
214 +
214 215 /* Replacement function for Wordpress' transients and problematic name length. */
215 - static function get_transient($name)
216 + static function get_transient($name)
216 217 {
217 - global $wpdb;
218 -// self::removeExpiredTrans();
219 -
220 - if ($name == '')
218 + global $wpdb;
219 +// self::removeExpiredTrans();
220 +
221 + if ($name == '')
221 222 return false;
222 -
223 +
223 224 $table = self::get_coltrans_table_name();
224 -
225 - $sql = "SELECT value FROM $table where name= '%s' ";
226 - $sql = $wpdb->prepare($sql, $name);
227 -
228 - $var = $wpdb->get_var($sql);
229 -
230 - if (is_null($var))
225 +
226 + $sql = "SELECT value FROM $table where name= '%s' ";
227 + $sql = $wpdb->prepare($sql, $name);
228 +
229 + $var = $wpdb->get_var($sql);
230 +
231 + if (is_null($var))
231 232 $var = false;
232 -
233 - return $var;
234 -
233 +
234 + return $var;
235 +
235 236 }
236 -
237 -
237 +
238 +
238 239 static function set_transient($name, $value , $expire = -1 )
239 240 {
240 - global $wpdb;
241 -
242 -
241 + global $wpdb;
242 +
243 +
243 244 if ($expire == -1 )
244 - $expire = HOUR_IN_SECONDS * 4;
245 -
246 - if ($name == '')
247 - return false;
248 -
249 - $expire_time = time() + $expire;
250 -
245 + $expire = HOUR_IN_SECONDS * 4;
246 +
247 + if ($name == '')
248 + return false;
249 +
250 + $expire_time = time() + $expire;
251 +
251 252 $table = self::get_coltrans_table_name();
252 -
253 +
253 254 // prevent doubles, remove any present by this name
254 - self::delete_transient($name);
255 -
256 - $wpdb->insert($table,
257 - array("name" => $name,
258 - "value" => $value,
255 + self::delete_transient($name);
256 +
257 + $wpdb->insert($table,
258 + array("name" => $name,
259 + "value" => $value,
259 260 "expire" => $expire_time
260 - ),
261 - array("%s","%s","%d"));
262 -
263 -
264 - }
265 -
266 - static function delete_transient($name)
261 + ),
262 + array("%s","%s","%d"));
263 +
264 +
265 + }
266 +
267 + static function delete_transient($name)
267 268 {
268 - global $wpdb;
269 -
270 -
269 + global $wpdb;
270 +
271 +
271 272 $table = self::get_coltrans_table_name();
272 - $wpdb->delete($table, array("name" => $name), array('%s') );
273 + $wpdb->delete($table, array("name" => $name), array('%s') );
273 274
274 275 }
275 -
276 - static function removeExpiredTrans()
276 +
277 + static function removeExpiredTrans()
277 278 {
278 - global $wpdb;
279 -
279 + global $wpdb;
280 +
280 281 $table = self::get_coltrans_table_name();
281 - $sql = "DELETE FROM $table WHERE expire < UNIX_TIMESTAMP(NOW())";
282 + $sql = "DELETE FROM $table WHERE expire < UNIX_TIMESTAMP(NOW())";
282 283 $return = $wpdb->query($sql);
283 -
284 +
284 285 if($return === false)
285 286 {
286 287 $error = "Database error " . $wpdb->last_error;
287 - MB()->add_notice('error', $error);
288 + MB()->add_notice('error', $error);
288 289 $install = MB()->getClass('install');
289 - $install->create_database_table();
290 + $install->create_database_table();
290 291 }
291 -
292 +
292 293 }
293 -
294 - /** Function will try to unload any FA scripts other than MB from WP. In case of conflict */
295 - static function fixFAConflict()
294 +
295 + /** Function will try to unload any FA scripts other than MB from WP. In case of conflict */
296 + static function fixFAConflict()
296 297 {
297 - $forcefa = get_option('maxbuttons_forcefa');
298 -
299 - if ($forcefa != '1')
298 + $forcefa = get_option('maxbuttons_forcefa');
299 +
300 + if ($forcefa != '1')
300 301 return;
301 -
302 +
302 303 global $wp_styles;
303 304
304 - $our_fa_there = false;
305 -
306 - foreach($wp_styles->registered as $script => $details)
305 + $our_fa_there = false;
306 +
307 + foreach($wp_styles->registered as $script => $details)
307 308 {
308 - if ($script == 'mbpro-font-awesome')
309 + if ($script == 'mbpro-font-awesome')
309 310 {
310 - $our_fa_there = true;
311 + $our_fa_there = true;
311 312 break;
312 - }
313 + }
313 314 }
314 -
315 +
315 316 // fix nothing on pages where we are not loading.
316 - if (! $our_fa_there)
317 - return;
318 -
317 + if (! $our_fa_there)
318 + return;
319 319
320 +
320 321 // Loop through all registered styles and remove any that appear to be Font Awesome.
321 322 foreach ( $wp_styles->registered as $script => $details ) {
322 323 $src = isset($details->src) ? $details->src : false;
323 324
324 - if ($script == 'mbpro-font-awesome')
325 + if ($script == 'mbpro-font-awesome')
325 326 {
326 327 $mbpro_src = $src;
327 328 continue; // exclude us
328 329 }
329 -
330 +
330 331 if ( false !== strpos( $script, 'fontawesome' ) || false !== strpos( $script, 'font-awesome' ) ) {
331 332 wp_dequeue_style( $script );
332 333 }
333 334 if ($src && ( false !== strpos($src, 'font-awesome') || false !== strpos($src, 'fontawesome') ) )
334 335 {
335 - wp_dequeue_style( $script );
336 + wp_dequeue_style( $script );
336 337 }
337 338
338 339 }
339 -
340 - // This is a fix specific for NGGallery since they load their scripts weirdly / wrongly, but do check for the presence of a style named 'fontawesome' .
340 +
341 + // This is a fix specific for NGGallery since they load their scripts weirdly / wrongly, but do check for the presence of a style named 'fontawesome' .
341 342 wp_register_style('fontawesome', $src);
342 343
343 344 }
344 -
345 345
346 +
346 347 static function timeInit()
347 348 {
348 349 if ( ! defined('MAXBUTTONS_BENCHMARK') || MAXBUTTONS_BENCHMARK !== true)
349 350 return;
350 -
351 +
351 352 self::$timer = microtime(true);
352 353
353 - if (is_admin())
354 - add_filter("admin_footer",array(self::namespaceit('maxUtils'), "showTime"), 100);
354 + if (is_admin())
355 + add_filter("admin_footer",array(self::namespaceit('maxUtils'), "showTime"), 100);
355 356 else
356 - add_action("wp_footer",array(self::namespaceit('maxUtils'), "showTime"));
357 -
357 + add_action("wp_footer",array(self::namespaceit('maxUtils'), "showTime"));
358 +
358 359 }
359 360
360 361 static function addTime($msg)
361 362 {
@@ -361,30 +362,30 @@
361 362 {
362 363 if ( ! defined('MAXBUTTONS_BENCHMARK') || MAXBUTTONS_BENCHMARK !== true)
363 364 return;
364 365
365 -
366 - self::$timings[] = array("msg" => $msg,"time" => microtime(true));
366 +
367 + self::$timings[] = array("msg" => $msg,"time" => microtime(true));
367 368 }
368 -
369 +
369 370 static function startTime($operation)
370 371 {
371 372 if ( ! defined('MAXBUTTONS_BENCHMARK') || MAXBUTTONS_BENCHMARK !== true)
372 373 return;
373 -
374 - self::$time_operations[$operation][] = array("start" => microtime(true),
375 - "end" => 0,
376 - );
377 -
374 +
375 + self::$time_operations[$operation][] = array("start" => microtime(true),
376 + "end" => 0,
377 + );
378 +
378 379 }
379 -
380 - static function endTime($operation)
380 +
381 + static function endTime($operation)
381 382 {
382 383 if ( ! defined('MAXBUTTONS_BENCHMARK') || MAXBUTTONS_BENCHMARK !== true)
383 384 return;
384 -
385 - $timedcount = count(self::$time_operations[$operation]);
386 - for ($i = 0; $i < $timedcount; $i++)
385 +
386 + $timedcount = count(self::$time_operations[$operation]);
387 + for ($i = 0; $i < $timedcount; $i++)
387 388 {
388 389 if (self::$time_operations[$operation][$i]["end"] == 0)
389 390 {
390 391 self::$time_operations[$operation][$i]["end"] = microtime(true);
@@ -390,80 +391,80 @@
390 391 self::$time_operations[$operation][$i]["end"] = microtime(true);
391 392 break;
392 393 }
393 394 }
394 -
395 +
395 396 }
396 -
397 +
397 398 static function showTime()
398 399 {
399 400 if ( ! defined('MAXBUTTONS_BENCHMARK') || MAXBUTTONS_BENCHMARK !== true)
400 401 return;
401 -
402 +
402 403 $timer = self::$timer;
403 - $text = '';
404 - $text .= "<div id='mb-timer'>";
405 - $text .= "<p><strong>Timed Operations</strong></p>";
406 -
407 - foreach(self::$time_operations as $operation => $operations)
404 + $text = '';
405 + $text .= "<div id='mb-timer'>";
406 + $text .= "<p><strong>Timed Operations</strong></p>";
407 +
408 + foreach(self::$time_operations as $operation => $operations)
408 409 {
409 410 foreach($operations as $index => $data)
410 411 {
411 - $start = $data["start"];
412 - $end = $data["end"];
413 - $duration = $end - $start;
414 -
415 -
412 + $start = $data["start"];
413 + $end = $data["end"];
414 + $duration = $end - $start;
415 +
416 +
416 417 $text .= "<span class='first'>$duration</span>
417 - <span class='second'>$operation</span>
418 - <span class='third'>&nbsp; </span><br />
419 - ";
420 -
421 -
418 + <span class='second'>$operation</span>
419 + <span class='third'>&nbsp; </span><br />
420 + ";
421 +
422 +
422 423 }
423 424 }
424 -
425 -
426 - $text .= "<p><strong>" . __("MaxButtons Loading Time:","maxbuttons") . "</strong></p>";
425 +
426 +
427 + $text .= "<p><strong>" . __("MaxButtons Loading Time:","maxbuttons") . "</strong></p>";
427 428 $prev_time =0;
428 -
429 - $time_array = array();
430 -
429 +
430 + $time_array = array();
431 +
431 432 foreach(self::$timings as $timing)
432 433 {
433 - $cum = ($timing["time"] - $prev_time);
434 - $text .= "<span class='first'>" . ($timing["time"] - $timer) . "</span><span class='second'> " . $timing["msg"] . "</span><span class='third'>$cum</span> <br /> ";
435 - //$time_array[$cum] = $timing["msg"];
434 + $cum = ($timing["time"] - $prev_time);
435 + $text .= "<span class='first'>" . ($timing["time"] - $timer) . "</span><span class='second'> " . $timing["msg"] . "</span><span class='third'>$cum</span> <br /> ";
436 + //$time_array[$cum] = $timing["msg"];
436 437 $prev_time = $timing["time"];
437 438 }
438 439
439 440 /*ksort($time_array);
440 -
441 - $text .= "<br><br><strong>By time taken:</strong><br>";
441 +
442 + $text .= "<br><br><strong>By time taken:</strong><br>";
442 443 foreach($time_array as $timeline)
443 444 {
444 - $text .= "$timeline <br />";
445 + $text .= "$timeline <br />";
445 446 }
446 447 */
447 448 $text .= "</div> ";
448 - $text .= "<style>#mb-timer { margin-left: 180px; }
449 - #mb-timer span {
449 + $text .= "<style>#mb-timer { margin-left: 180px; }
450 + #mb-timer span {
450 451 display: inline-block;
451 452 font-size: 12px;
452 453 }
453 - #mb-timer span.first {
454 - width: 170px;
454 + #mb-timer span.first {
455 + width: 170px;
455 456 }
456 - #mb-timer span.second {
457 - width: 300px;
457 + #mb-timer span.second {
458 + width: 300px;
458 459 }
459 - #mb-timer span.third {
460 - width: 150px;
461 - }
462 - </style>";
463 -
460 + #mb-timer span.third {
461 + width: 150px;
462 + }
463 + </style>";
464 +
464 465 echo $text;
465 -
466 -
467 - //return $filter . $text;
466 +
467 +
468 + //return $filter . $text;
468 469 }
469 470 }