PluginProbe
Multi Device Switcher / 1.3.0
Multi Device Switcher v1.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 All 34 releases
multi-device-switcher / multi-device-switcher.php

multi-device-switcher.php in Multi Device Switcher 1.3.0, at multi-device-switcher.php

855 lines 29.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Multi Device Switcher
4 Plugin URI: https://github.com/thingsym/multi-device-switcher
5 Description: This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game and custom).
6 Version: 1.3.0
7 Author: thingsym
8 Author URI: http://www.thingslabo.com/
9 License: GPL2
10 Text Domain: multi-device-switcher
11 Domain Path: /languages/
12 */
13
14 /*
15 Copyright 2012 thingsym (http://www.thingslabo.com/)
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
30 */
31
32 class Multi_Device_Switcher {
33
34 public function __construct() {
35 add_action('init', array(&$this, 'session'));
36
37 $userAgent = $this->get_options_userAgent();
38 $this->device = '';
39 $server_ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
40
41 foreach ( array_reverse($userAgent) as $key => $val ) {
42 if ( !preg_match( "/^custom_switcher_/", $key ) )
43 continue;
44 if ( $userAgent[$key] && preg_match( '/' . implode( '|', $userAgent[$key] ) . '/i', $server_ua) ) {
45 $this->device = $key;
46 break;
47 }
48 }
49
50 if ( !$this->device ) {
51 if ( $userAgent['game'] && preg_match( '/' . implode( '|', $userAgent['game'] ) . '/i', $server_ua) ) {
52 $this->device = 'game';
53 }
54 elseif ( $userAgent['tablet'] && preg_match( '/' . implode( '|', $userAgent['tablet'] ) . '/i', $server_ua) ) {
55 $this->device = 'tablet';
56 }
57 elseif ( $userAgent['smart'] && preg_match( '/' . implode( '|', $userAgent['smart'] ) . '/i', $server_ua) ) {
58 $this->device = 'smart';
59 }
60 elseif ( $userAgent['mobile'] && preg_match( '/' . implode( '|', $userAgent['mobile'] ) . '/i', $server_ua) ) {
61 $this->device = 'mobile';
62 }
63 }
64
65 if ($this->device) {
66 load_plugin_textdomain('multi-device-switcher', false, 'multi-device-switcher/languages');
67 add_filter('stylesheet', array(&$this, 'get_stylesheet'));
68 add_filter('template', array(&$this, 'get_template'));
69 add_action('wp_footer', array(&$this, 'add_pc_switcher'));
70 }
71
72 if ( isset($_COOKIE['pc-switcher']) ) {
73 remove_filter('stylesheet', array(&$this, 'get_stylesheet'));
74 remove_filter('template', array(&$this, 'get_template'));
75 }
76 }
77
78 public function get_options_userAgent() {
79 $options = get_option('multi_device_switcher_options');
80 $default_options = multi_device_switcher_get_default_options();
81
82 if ( !isset( $options['userAgent_smart'] ) )
83 $options['userAgent_smart'] = $default_options['userAgent_smart'];
84 if ( !isset( $options['userAgent_tablet'] ) )
85 $options['userAgent_tablet'] = $default_options['userAgent_tablet'];
86 if ( !isset( $options['userAgent_mobile'] ) )
87 $options['userAgent_mobile'] = $default_options['userAgent_mobile'];
88 if ( !isset( $options['userAgent_game'] ) )
89 $options['userAgent_game'] = $default_options['userAgent_game'];
90
91 if ( $options['userAgent_smart'] )
92 $userAgent['smart'] = preg_split( "/,\s*/", $options['userAgent_smart'] );
93 if ( $options['userAgent_tablet'] )
94 $userAgent['tablet'] = preg_split( "/,\s*/", $options['userAgent_tablet'] );
95 if ( $options['userAgent_mobile'] )
96 $userAgent['mobile'] = preg_split( "/,\s*/", $options['userAgent_mobile'] );
97 if ( $options['userAgent_game'] )
98 $userAgent['game'] = preg_split( "/,\s*/", $options['userAgent_game'] );
99
100 foreach ( $options as $key => $val ) {
101 if ( !preg_match( "/^custom_switcher_userAgent_/", $key ) )
102 continue;
103
104 $custom_switcher_name = preg_replace("/^custom_switcher_userAgent_/", '', $key);
105
106 if ($val)
107 $userAgent['custom_switcher_' . $custom_switcher_name] = preg_split( "/,\s*/", $val );
108 }
109
110 return $userAgent;
111 }
112
113 public function get_stylesheet($stylesheet = '') {
114 $name = $this->get_device_theme();
115
116 if ( empty($name) )
117 return $stylesheet;
118
119 $themes = wp_get_themes();
120 foreach ( $themes as $t ) {
121 if ( $name == $t->get('Name') ) {
122 $theme = $t;
123 break;
124 }
125 }
126
127 if ( empty($theme) )
128 return $stylesheet;
129
130 if ( $theme->get('Status') != 'publish' )
131 return $stylesheet;
132
133 return $theme['Stylesheet'];
134 }
135
136 public function get_template($template = '') {
137 $name = $this->get_device_theme();
138
139 if ( empty($name) )
140 return $template;
141
142 $themes = wp_get_themes();
143 foreach ( $themes as $t ) {
144 if ( $name == $t->get('Name') ) {
145 $theme = $t;
146 break;
147 }
148 }
149
150 if ( empty( $theme ) )
151 return $template;
152
153 if ( $theme->get('Status') != 'publish' )
154 return $template;
155
156 return $theme['Template'];
157 }
158
159 public function get_device_theme() {
160 $options = get_option('multi_device_switcher_options');
161
162 if ($this->device == 'smart') {
163 return $options['theme_smartphone'];
164 }
165 elseif ($this->device == 'tablet') {
166 return $options['theme_tablet'];
167 }
168 elseif ($this->device == 'mobile') {
169 return $options['theme_mobile'];
170 }
171 elseif ($this->device == 'game') {
172 return $options['theme_game'];
173 }
174 else {
175 foreach ( $options as $key => $val ) {
176 if ( !preg_match( "/^custom_switcher_theme_/", $key ) )
177 continue;
178
179 $custom_switcher_name = preg_replace("/^custom_switcher_theme_/", '', $key);
180
181 if ( $this->device == 'custom_switcher_' . $custom_switcher_name ) {
182 return $options[$key];
183 }
184 }
185 }
186
187 return;
188 }
189
190 public function session() {
191 if ( isset($_GET['pc-switcher']) ) {
192 setcookie( 'pc-switcher', $_GET['pc-switcher'] ? 1 : '', null, '/' );
193
194 $uri = preg_replace( '/^(.+?)(\?.*)$/', '$1', $_SERVER['REQUEST_URI'] );
195
196 unset( $_GET['pc-switcher'] );
197 if ( !empty($_GET) )
198 $uri = $uri . '?' . http_build_query($_GET);
199
200 wp_redirect( esc_attr($uri) );
201 exit;
202 }
203 }
204
205 public function add_pc_switcher($pc_switcher = 0) {
206 $options = get_option('multi_device_switcher_options');
207 $name = $this->get_device_theme();
208
209 if ($options['pc_switcher'])
210 $pc_switcher = 1;
211
212 if ( $pc_switcher && $name && $name != 'None' ) {
213 if ($options['default_css'])
214 wp_enqueue_style( 'pc-switcher-options', plugins_url() . '/multi-device-switcher/pc-switcher.css', false, '2013-03-20' );
215
216 if ( isset($_COOKIE['pc-switcher']) ) {
217 $uri = add_query_arg( 'pc-switcher', 0 );
218 ?>
219 <div class="pc-switcher"><a href="<?php echo $uri; ?>"><?php _e( 'Mobile', 'multi-device-switcher' ); ?></a><span class="active"><?php _e( 'PC', 'multi-device-switcher' ); ?></span></div>
220 <?php
221 }
222 else {
223 $uri = add_query_arg( 'pc-switcher', 1 );
224 ?>
225 <div class="pc-switcher"><span class="active"><?php _e( 'Mobile', 'multi-device-switcher' ); ?></span><a href="<?php echo $uri; ?>"><?php _e( 'PC', 'multi-device-switcher' ); ?></a></div>
226 <?php
227 }
228 }
229 }
230
231 public function is_multi_device( $device = '' ) {
232 if ( $this->device == $device )
233 return (boolean) 1;
234 if ( $this->device == 'custom_switcher_' . $device )
235 return (boolean) 1;
236
237 return (boolean) 0;
238 }
239 }
240
241 if ( !is_admin() )
242 $multi_device_switcher = new Multi_Device_Switcher();
243
244 /**
245 * Add HTTP/1.1 Vary header.
246 *
247 * @since 1.1.1
248 *
249 */
250 function multi_device_switcher_add_header_vary( $headers ) {
251 if ( !is_admin() ) {
252 $headers['Vary'] = 'User-Agent';
253 return $headers;
254 }
255 }
256 add_filter( 'wp_headers', 'multi_device_switcher_add_header_vary' );
257
258 /**
259 * Add PC Switcher.
260 *
261 * @since 1.2
262 *
263 */
264 function multi_device_switcher_add_pc_switcher() {
265 global $multi_device_switcher;
266 $multi_device_switcher->add_pc_switcher(1);
267 }
268
269 /**
270 * Return boolean whether a particular device.
271 *
272 * @since 1.2.4
273 *
274 */
275 if ( !function_exists( 'is_multi_device' ) ) :
276
277 function is_multi_device( $device = '' ) {
278 global $multi_device_switcher;
279 return $multi_device_switcher->is_multi_device($device);
280 }
281 endif;
282
283 /**
284 * Properly enqueue scripts for our multi_device_switcher options page.
285 *
286 * This function is attached to the admin_enqueue_scripts action hook.
287 *
288 * @since 1.0
289 *
290 */
291 function multi_device_switcher_admin_enqueue_scripts( $hook_suffix ) {
292 wp_enqueue_script( 'multi-device-switcher-options', plugins_url() . '/multi-device-switcher/multi-device-switcher.js', array( 'jquery', 'jquery-ui-tabs' ), '2011-08-22' );
293 }
294
295 /**
296 * Properly enqueue styles for our multi_device_switcher options page.
297 *
298 * This function is attached to the admin_enqueue_styles action hook.
299 *
300 * @since 1.0
301 *
302 */
303 function multi_device_switcher_admin_enqueue_styles( $hook_suffix ) {
304 wp_enqueue_style( 'multi-device-switcher-options', plugins_url() . '/multi-device-switcher/multi-device-switcher.css', false, '2011-08-22' );
305 }
306
307 /**
308 * Register the form setting for our multi_device_switcher array.
309 *
310 * This function is attached to the admin_init action hook.
311 *
312 * This call to register_setting() registers a validation callback, multi_device_switcher_validate(),
313 * which is used when the option is saved, to ensure that our option values are complete, properly
314 * formatted, and safe.
315 *
316 * @since 1.0
317 */
318 function multi_device_switcher_init() {
319 // If we have no options in the database, let's add them now.
320 if ( false === multi_device_switcher_get_options() )
321 add_option( 'multi_device_switcher_options' );
322
323 register_setting(
324 'multi_device_switcher', // Options group, see settings_fields() call in multi_device_switcher_render_page()
325 'multi_device_switcher_options', // Database option, see multi_device_switcher_get_options()
326 'multi_device_switcher_validate' // The sanitization callback, see multi_device_switcher_validate()
327 );
328 }
329
330 add_action( 'admin_init', 'multi_device_switcher_init' );
331
332 /**
333 * Change the capability required to save the 'multi_device_switcher' options group.
334 *
335 * @see multi_device_switcher_init() First parameter to register_setting() is the name of the options group.
336 * @see multi_device_switcher_add_page() The edit_theme_options capability is used for viewing the page.
337 *
338 * By default, the options groups for all registered settings require the manage_options capability.
339 * By default, only administrators have either of these capabilities, but the desire here is
340 * to allow for finer-grained control for roles and users.
341 *
342 * @param string $capability The capability used for the page, which is manage_options by default.
343 * @return string The capability to actually use.
344 */
345 function multi_device_switcher_page_capability( $capability ) {
346 return 'edit_theme_options';
347 }
348 add_filter( 'option_page_capability_multi_device_switcher', 'multi_device_switcher_page_capability' );
349
350 /**
351 * Add our options page to the admin menu, including some help documentation.
352 *
353 * This function is attached to the admin_menu action hook.
354 *
355 * @since 1.0
356 */
357 function multi_device_switcher_add_page() {
358 load_plugin_textdomain('multi-device-switcher', false, 'multi-device-switcher/languages');
359
360 add_filter( 'plugin_action_links', 'multi_device_switcher_plugin_action_links', 10, 2 );
361
362 $page_hook = add_theme_page(
363 __( 'Multi Device Switcher', 'multi-device-switcher' ), // Name of page
364 __( 'Multi Device Switcher', 'multi-device-switcher' ), // Label in menu
365 'manage_options', // Capability required
366 'multi-device-switcher', // Menu slug, used to uniquely identify the page
367 'multi_device_switcher_render_page' // Function that renders the options page
368 );
369
370 if ( !$page_hook )
371 return;
372
373 add_action( 'load-' . $page_hook , 'multi_device_switcher_page_hook_suffix' );
374 }
375 add_action( 'admin_menu', 'multi_device_switcher_add_page' );
376
377 /**
378 * Page Hook Suffix
379 *
380 * This function is attached to the load-** action hook.
381 *
382 * @since 1.2.4
383 */
384 function multi_device_switcher_page_hook_suffix() {
385 add_action( 'admin_enqueue_scripts', 'multi_device_switcher_admin_enqueue_scripts' );
386 add_action( 'admin_enqueue_scripts', 'multi_device_switcher_admin_enqueue_styles' );
387 }
388
389 /**
390 * Add the settings link to the plugin page.
391 *
392 * @since 1.2
393 */
394 function multi_device_switcher_plugin_action_links( $links, $file ) {
395 if ( $file != plugin_basename( __FILE__ ))
396 return $links;
397
398 $settings_link = '<a href="themes.php?page=multi-device-switcher">' . __( 'Settings', 'multi-device-switcher' ) . '</a>';
399
400 array_unshift( $links, $settings_link );
401
402 return $links;
403 }
404
405 /**
406 * Returns the default options.
407 *
408 * @since 1.0
409 */
410 function multi_device_switcher_get_default_options() {
411 $default_theme_options = array(
412 'pc_switcher' => 1,
413 'default_css' => 1,
414 'theme_smartphone' => 'None',
415 'theme_tablet' => 'None',
416 'theme_mobile' => 'None',
417 'theme_game' => 'None',
418 'userAgent_smart' => 'iPhone, iPod, Android, dream, CUPCAKE, Windows Phone, webOS, BB10, BlackBerry8707, BlackBerry9000, BlackBerry9300, BlackBerry9500, BlackBerry9530, BlackBerry9520, BlackBerry9550, BlackBerry9700, BlackBerry 93, BlackBerry 97, BlackBerry 99, BlackBerry 98',
419 'userAgent_tablet' => 'iPad, Kindle, Sony Tablet, Nexus 7',
420 'userAgent_mobile' => 'DoCoMo, SoftBank, J-PHONE, Vodafone, KDDI, UP.Browser, WILLCOM, emobile, DDIPOCKET, Windows CE, BlackBerry, Symbian, PalmOS, Huawei, IAC, Nokia',
421 'userAgent_game' => 'PlayStation Portable, PlayStation Vita, PSP, PS2, PLAYSTATION 3, PlayStation 4, Nitro, Nintendo 3DS, Nintendo Wii, Nintendo WiiU, Xbox',
422 );
423
424 return $default_theme_options;
425 }
426
427 /**
428 * Returns the options array.
429 *
430 * @since 1.0
431 */
432 function multi_device_switcher_get_options() {
433 $options = get_option( 'multi_device_switcher_options' );
434 $default_options = multi_device_switcher_get_default_options();
435
436 if ( !isset( $options['pc_switcher'] ) )
437 $options['pc_switcher'] = $default_options['pc_switcher'];
438 if ( !isset( $options['default_css'] ) )
439 $options['default_css'] = $default_options['default_css'];
440
441 if ( !isset( $options['theme_smartphone'] ) )
442 $options['theme_smartphone'] = $default_options['theme_smartphone'];
443 if ( !isset( $options['theme_tablet'] ) )
444 $options['theme_tablet'] = $default_options['theme_tablet'];
445 if ( !isset( $options['theme_mobile'] ) )
446 $options['theme_mobile'] = $default_options['theme_mobile'];
447 if ( !isset( $options['theme_game'] ) )
448 $options['theme_game'] = $default_options['theme_game'];
449
450 if ( !isset( $options['userAgent_smart'] ) )
451 $options['userAgent_smart'] = $default_options['userAgent_smart'];
452 if ( !isset( $options['userAgent_tablet'] ) )
453 $options['userAgent_tablet'] = $default_options['userAgent_tablet'];
454 if ( !isset( $options['userAgent_mobile'] ) )
455 $options['userAgent_mobile'] = $default_options['userAgent_mobile'];
456 if ( !isset( $options['userAgent_game'] ) )
457 $options['userAgent_game'] = $default_options['userAgent_game'];
458
459 return $options;
460 }
461
462 /**
463 * Rendering Options Setting Page.
464 *
465 * @since 1.0
466 */
467 function multi_device_switcher_render_page() {
468 ?>
469 <div class="wrap">
470 <div id="icon-themes" class="icon32"><br></div>
471 <h2><?php printf( __( 'Multi Device Switcher', 'multi-device-switcher' ), wp_get_theme()->get('Name') ); ?></h2>
472 <?php settings_errors(); ?>
473
474 <form method="post" action="options.php">
475 <?php
476 settings_fields( 'multi_device_switcher' );
477 $options = multi_device_switcher_get_options();
478
479 $default_theme = wp_get_theme()->get('Name');
480 $themes = wp_get_themes();
481 $theme_names = array();
482
483 if ( count($themes) ) {
484 foreach ( $themes as $t ) {
485 $theme_names[] = $t->get('Name');
486 }
487 natcasesort($theme_names);
488 }
489 ?>
490
491 <div id="admin-tabs">
492 <fieldset id="Theme" class="options">
493 <h3 class="label"><?php _e( 'Theme', 'multi-device-switcher' ); ?></h3>
494 <table class="form-table">
495 <tr><th scope="row"><?php _e( 'Smart Phone Theme', 'multi-device-switcher' ); ?></th>
496 <td>
497
498 <?php
499 if ( count($theme_names) ) {
500 $html = '<select name="multi_device_switcher_options[theme_smartphone]">';
501
502 if ( ($options['theme_smartphone'] == 'None') || ($options['theme_smartphone'] == '') ) {
503 $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
504 }
505 else {
506 $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
507 }
508
509 foreach ( $theme_names as $theme_name ) {
510 if ( $default_theme == $theme_name )
511 continue;
512 if ( $options['theme_smartphone'] == $theme_name ) {
513 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
514 }
515 else {
516 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
517 }
518 }
519 $html .= '</select>';
520 }
521 echo $html;
522 ?>
523 </td>
524 </tr>
525 <tr><th scope="row"><?php _e( 'Tablet PC Theme', 'multi-device-switcher' ); ?></th>
526 <td>
527
528 <?php
529 if ( count($theme_names) ) {
530 $html = '<select name="multi_device_switcher_options[theme_tablet]">';
531
532 if ( ($options['theme_tablet'] == 'None') || ($options['theme_tablet'] == '') ) {
533 $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
534 }
535 else {
536 $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
537 }
538
539 foreach ( $theme_names as $theme_name ) {
540 if ( $default_theme == $theme_name )
541 continue;
542 if ( $options['theme_tablet'] == $theme_name ) {
543 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
544 }
545 else {
546 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
547 }
548 }
549 $html .= '</select>';
550 }
551 echo $html;
552 ?>
553 </td>
554 </tr>
555 <tr><th scope="row"><?php _e( 'Mobile Phone Theme', 'multi-device-switcher' ); ?></th>
556 <td>
557
558 <?php
559 if ( count($theme_names) ) {
560 $html = '<select name="multi_device_switcher_options[theme_mobile]">';
561
562 if ( ($options['theme_mobile'] == 'None') || ($options['theme_mobile'] == '') ) {
563 $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
564 }
565 else {
566 $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
567 }
568
569 foreach ( $theme_names as $theme_name ) {
570 if ( $default_theme == $theme_name )
571 continue;
572 if ( $options['theme_mobile'] == $theme_name ) {
573 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
574 }
575 else {
576 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
577 }
578 }
579 $html .= '</select>';
580 }
581 echo $html;
582 ?>
583 </td>
584 </tr>
585 <tr><th scope="row"><?php _e( 'Game Platforms Theme', 'multi-device-switcher' ); ?></th>
586 <td>
587
588 <?php
589 if ( count($theme_names) ) {
590 $html = '<select name="multi_device_switcher_options[theme_game]">';
591
592 if ( ($options['theme_game'] == 'None') || ($options['theme_game'] == '') ) {
593 $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
594 }
595 else {
596 $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
597 }
598
599 foreach ( $theme_names as $theme_name ) {
600 if ( $default_theme == $theme_name )
601 continue;
602 if ( $options['theme_game'] == $theme_name ) {
603 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
604 }
605 else {
606 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
607 }
608 }
609 $html .= '</select>';
610 }
611 echo $html;
612 ?>
613 </td>
614 </tr>
615 </table>
616
617 <h3><?php _e( 'Custom Switcher Theme', 'multi-device-switcher' ); ?></h3>
618 <table class="form-table">
619
620 <?php
621 foreach ( $options as $key => $val ) {
622 if ( !preg_match( "/^custom_switcher_theme_/", $key ) )
623 continue;
624
625 $custom_switcher_name = preg_replace("/^custom_switcher_theme_/", '', $key);
626 $custom_switcher_option = $key;
627 $custom_switcher_theme = $val;
628 ?>
629
630 <tr><th scope="row"><?php _e( $custom_switcher_name, 'multi-device-switcher' ); ?></th>
631 <td>
632
633 <?php
634 if ( count($theme_names) ) {
635 $html = '<select name="multi_device_switcher_options[' . $custom_switcher_option . ']">';
636
637 if ( ($custom_switcher_theme == 'None') || ($custom_switcher_theme == '') ) {
638 $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
639 }
640 else {
641 $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
642 }
643
644 foreach ( $theme_names as $theme_name ) {
645 if ( $default_theme == $theme_name )
646 continue;
647 if ( $custom_switcher_theme == $theme_name ) {
648 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
649 }
650 else {
651 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
652 }
653 }
654 $html .= '</select>';
655 $html .= ' <span class="submit"><input type="submit" name="multi_device_switcher_options[delete_custom_switcher_' . $custom_switcher_name . ']" value="' . __( 'Delete', 'multi-device-switcher' ) . '" onclick="return confirm(\'' . sprintf( __( 'Are you sure you want to delete %1$s ?', 'multi-device-switcher' ), $custom_switcher_name ) . '\');" class="button"></span>';
656 }
657 echo $html;
658 ?>
659 </td>
660 </tr>
661
662 <?php
663 }
664 ?>
665
666 <tr><th scope="row"><?php _e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></th>
667 <td>
668 <legend class="screen-reader-text"><span><?php _e( 'Add Custom Switcher', 'thingscms' ); ?></span></legend>
669 <input type="text" name="multi_device_switcher_options[custom_switcher]" id="custom-switcher" value="" size="24">
670 <span class="submit"><input type="submit" name="multi_device_switcher_options[add_custom_switcher]" value="<?php _e( 'Add', 'multi-device-switcher' ); ?>" class="button"></span><br>
671 <?php _e( '20 characters max, alphanumeric', 'multi-device-switcher' ); ?>
672 </td>
673 </tr>
674 </table>
675
676 </fieldset>
677
678 <fieldset id="UserAgent" class="options">
679 <h3 class="label"><?php _e( 'UserAgent', 'multi-device-switcher' ); ?></h3>
680 <p><?php _e( 'Enter Comma-separated values (csv) format.', 'multi-device-switcher' ); ?></p>
681
682 <table class="form-table">
683 <tr><th scope="row"><?php _e( 'Smart Phone', 'multi-device-switcher' ); ?></th>
684 <td><textarea name="multi_device_switcher_options[userAgent_smart]" rows="4" cols="42"><?php echo $options['userAgent_smart']; ?></textarea></td>
685 </tr>
686 <tr><th scope="row"><?php _e( 'Tablet PC', 'multi-device-switcher' ); ?></th>
687 <td><textarea name="multi_device_switcher_options[userAgent_tablet]" rows="4" cols="42"><?php echo $options['userAgent_tablet']; ?></textarea></td>
688 </tr>
689 <tr><th scope="row"><?php _e( 'Mobile Phone', 'multi-device-switcher' ); ?></th>
690 <td><textarea name="multi_device_switcher_options[userAgent_mobile]" rows="4" cols="42"><?php echo $options['userAgent_mobile']; ?></textarea></td>
691 </tr>
692 <tr><th scope="row"><?php _e( 'Game Platforms', 'multi-device-switcher' ); ?></th>
693 <td><textarea name="multi_device_switcher_options[userAgent_game]" rows="4" cols="42"><?php echo $options['userAgent_game']; ?></textarea></td>
694 </tr>
695 <tr><th></th>
696 <td><span class="submit"><input type="submit" name="multi_device_switcher_options[restore_UserAgent]" value="<?php _e( 'Reset Settings to Default UserAgent', 'multi-device-switcher' ); ?>" class="button"></span></td>
697 </tr>
698
699 </table>
700
701 <h3><?php _e( 'Custom Switcher UserAgent', 'multi-device-switcher' ); ?></h3>
702 <table class="form-table">
703 <?php
704 foreach ( $options as $key => $val ) {
705 if ( !preg_match( "/^custom_switcher_userAgent_/", $key ) )
706 continue;
707
708 $custom_switcher_name = preg_replace("/^custom_switcher_userAgent_/", '', $key);
709 $custom_switcher_option = $key;
710 $custom_switcher_userAgent = $val;
711 ?>
712
713 <tr><th scope="row"><?php _e( $custom_switcher_name, 'multi-device-switcher' ); ?></th>
714 <td><textarea name="multi_device_switcher_options[<?php echo $custom_switcher_option; ?>]" rows="4" cols="42"><?php echo $custom_switcher_userAgent; ?></textarea></td>
715 </tr>
716 <?php
717 }
718 ?>
719
720 </table>
721 </fieldset>
722
723 <fieldset id="PC-Switcher" class="options">
724 <h3 class="label"><?php _e( 'PC Switcher', 'multi-device-switcher' ); ?></h3>
725
726 <table class="form-table">
727 <tr><th scope="row"><?php _e( 'Add PC Switcher', 'multi-device-switcher' ); ?></th>
728 <td>
729 <legend class="screen-reader-text"><span><?php _e( 'Add PC Switcher', 'multi-device-switcher' ); ?></span></legend>
730 <label><input type="checkbox" name="multi_device_switcher_options[pc_switcher]" id="pc-switcher" value="1"<?php checked(1, $options['pc_switcher']); ?>> <?php _e( 'Add a PC Switcher to the footer.', 'multi-device-switcher' ); ?></label>
731 </td>
732 </tr>
733 <tr><th scope="row"><?php _e( 'Add default CSS', 'multi-device-switcher' ); ?></th>
734 <td>
735 <legend class="screen-reader-text"><span><?php _e( 'Add default CSS', 'multi-device-switcher' ); ?></span></legend>
736 <label><input type="checkbox" name="multi_device_switcher_options[default_css]" id="add-default-css" value="1"<?php checked(1, $options['default_css']); ?>> <?php _e( 'Add a default CSS.', 'multi-device-switcher' ); ?></label>
737 </td>
738 </tr>
739 </table>
740 </fieldset>
741
742 </div>
743 <?php submit_button(); ?>
744 </form>
745 </div>
746
747 <div id="donate">
748 <h2><?php _e( 'Donationware', 'multi-device-switcher' ); ?></h2>
749 <p><?php _e( 'If you like this plugin, please donate to support development and maintenance.', 'multi-device-switcher' ); ?></p>
750 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
751 <input type="hidden" name="cmd" value="_s-xclick">
752 <input type="hidden" name="hosted_button_id" value="9L53NELFMHTWW">
753 <table>
754 <tr><td><input type="hidden" name="on0" value="Donationware">Donationware</td></tr><tr><td><select name="os0">
755 <option value="1. Donate">1. Donate $3.00 USD</option>
756 <option value="2. Donate">2. Donate $5.00 USD</option>
757 <option value="3. Donate">3. Donate $7.00 USD</option>
758 <option value="4. Donate" selected="selected">4. Donate $10.00 USD</option>
759 <option value="5. Donate">5. Donate $20.00 USD</option>
760 <option value="6. Donate">6. Donate $30.00 USD</option>
761 <option value="7. Donate">7. Donate $40.00 USD</option>
762 <option value="8. Donate">8. Donate $50.00 USD</option>
763 <option value="9. Donate">9. Donate $60.00 USD</option>
764 <option value="10. Donate">10. Donate $70.00 USD</option>
765 </select> </td></tr>
766 </table>
767 <input type="hidden" name="currency_code" value="USD">
768 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
769 <img alt="" border="0" src="https://www.paypalobjects.com/ja_JP/i/scr/pixel.gif" width="1" height="1">
770 </form>
771 </div>
772
773 <?php
774 }
775
776 /**
777 * Sanitize and validate form input. Accepts an array, return a sanitized array.
778 *
779 * @see multi_device_switcher_init()
780 *
781 * @since 1.0
782 */
783 function multi_device_switcher_validate( $input ) {
784 $output = $default_options = multi_device_switcher_get_default_options();
785
786 if ( isset( $input['theme_smartphone'] ) )
787 $output['theme_smartphone'] = $input['theme_smartphone'];
788 if ( isset( $input['theme_tablet'] ) )
789 $output['theme_tablet'] = $input['theme_tablet'];
790 if ( isset( $input['theme_mobile'] ) )
791 $output['theme_mobile'] = $input['theme_mobile'];
792 if ( isset( $input['theme_game'] ) )
793 $output['theme_game'] = $input['theme_game'];
794
795 if (isset( $input['restore_UserAgent'] )) {
796 $output['userAgent_smart'] = $default_options['userAgent_smart'];
797 $output['userAgent_tablet'] = $default_options['userAgent_tablet'];
798 $output['userAgent_mobile'] = $default_options['userAgent_mobile'];
799 $output['userAgent_game'] = $default_options['userAgent_game'];
800 }
801 else {
802 if ( isset( $input['userAgent_smart'] ) )
803 $output['userAgent_smart'] = $input['userAgent_smart'];
804 if ( isset( $input['userAgent_tablet'] ) )
805 $output['userAgent_tablet'] = $input['userAgent_tablet'];
806 if ( isset( $input['userAgent_mobile'] ) )
807 $output['userAgent_mobile'] = $input['userAgent_mobile'];
808 if ( isset( $input['userAgent_game'] ) )
809 $output['userAgent_game'] = $input['userAgent_game'];
810 }
811
812 foreach ( $input as $key => $val ) {
813 if ( !preg_match( "/^custom_switcher_theme_/", $key ) )
814 continue;
815
816 $custom_switcher_name = preg_replace("/^custom_switcher_theme_/", '', $key);
817
818 if ( isset( $input['custom_switcher_theme_' . $custom_switcher_name] ) )
819 $output['custom_switcher_theme_' . $custom_switcher_name] = $input['custom_switcher_theme_' . $custom_switcher_name];
820 if ( isset( $input['custom_switcher_userAgent_' . $custom_switcher_name] ) )
821 $output['custom_switcher_userAgent_' . $custom_switcher_name] = $input['custom_switcher_userAgent_' . $custom_switcher_name];
822 }
823
824 foreach ( $input as $key => $val ) {
825 if ( !preg_match( "/^delete_custom_switcher_/", $key ) )
826 continue;
827
828 $custom_switcher_name = preg_replace("/^delete_custom_switcher_/", '', $key);
829
830 unset($output['custom_switcher_theme_' . $custom_switcher_name]);
831 unset($output['custom_switcher_userAgent_' . $custom_switcher_name]);
832 }
833
834 if ( isset( $input['add_custom_switcher'] ) && !empty( $input['custom_switcher'] ) && !$output['custom_switcher_theme_' . $input['custom_switcher']] ) {
835 if ( preg_match( "/^[A-Za-z0-9]{1,20}$/", $input['custom_switcher'] ) ) {
836 $output['custom_switcher_theme_' . $input['custom_switcher']] = 'None';
837 $output['custom_switcher_userAgent_' . $input['custom_switcher']] = '';
838 }
839 }
840
841 $output['pc_switcher'] = isset($input['pc_switcher']) ? $input['pc_switcher'] : 0;
842 $output['default_css'] = isset($input['default_css']) ? $input['default_css'] : 0;
843
844 return apply_filters( 'multi_device_switcher_validate', $output, $input, $default_options );
845 }
846
847 /**
848 * include PC Switcher Widget.
849 *
850 * @since 1.2
851 */
852 require_once( dirname(__FILE__) . '/pc-switcher-widget.php' );
853
854 ?>
855