PluginProbe
Multi Device Switcher / 1.1.0
Multi Device Switcher v1.1.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.1.0, at multi-device-switcher.php

691 lines 24.5 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.1.0
7 Author: thingsym
8 Author URI: http://www.thingslabo.com/
9 License: GPL2
10 */
11
12 /*
13 Copyright 2012 thingsym (http://www.thingslabo.com/)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
28 */
29
30 class Multi_Device_Switcher {
31
32 public function __construct() {
33
34 $userAgent = $this->get_options_userAgent();
35 $this->device = '';
36
37 if ( $userAgent['smart'] && preg_match( '/' . implode( '|', $userAgent['smart'] ) . '/i', $_SERVER['HTTP_USER_AGENT']) ) {
38 $this->device = 'smart';
39 }
40 elseif ( $userAgent['tablet'] && preg_match( '/' . implode( '|', $userAgent['tablet'] ) . '/i', $_SERVER['HTTP_USER_AGENT']) ) {
41 $this->device = 'tablet';
42 }
43 elseif ( $userAgent['mobile'] && preg_match( '/' . implode( '|', $userAgent['mobile'] ) . '/i', $_SERVER['HTTP_USER_AGENT']) ) {
44 $this->device = 'mobile';
45 }
46 elseif ( $userAgent['game'] && preg_match( '/' . implode( '|', $userAgent['game'] ) . '/i', $_SERVER['HTTP_USER_AGENT']) ) {
47 $this->device = 'game';
48 }
49 else {
50 foreach ( $userAgent as $key => $val ) {
51 if ( ! preg_match( "/^custom_switcher_/", $key ) )
52 continue;
53 if ($userAgent[$key] && preg_match( '/' . implode( '|', $userAgent[$key] ) . '/i', $_SERVER['HTTP_USER_AGENT']) ) {
54 $this->device = $key;
55 break;
56 }
57 }
58 }
59
60 if ($this->device) {
61 add_filter('stylesheet', array(&$this, 'get_stylesheet'));
62 add_filter('template', array(&$this, 'get_template'));
63 }
64 }
65
66 public function get_options_userAgent() {
67 $options = get_option('multi_device_switcher_options');
68 $default_options = multi_device_switcher_get_default_options();
69
70 if ( ! isset( $options['userAgent_smart'] ) )
71 $options['userAgent_smart'] = $default_options['userAgent_smart'];
72 if ( ! isset( $options['userAgent_tablet'] ) )
73 $options['userAgent_tablet'] = $default_options['userAgent_tablet'];
74 if ( ! isset( $options['userAgent_mobile'] ) )
75 $options['userAgent_mobile'] = $default_options['userAgent_mobile'];
76 if ( ! isset( $options['userAgent_game'] ) )
77 $options['userAgent_game'] = $default_options['userAgent_game'];
78
79 if ( $options['userAgent_smart'] )
80 $userAgent['smart'] = preg_split( "/,\s*/", $options['userAgent_smart'] );
81 if ( $options['userAgent_tablet'] )
82 $userAgent['tablet'] = preg_split( "/,\s*/", $options['userAgent_tablet'] );
83 if ( $options['userAgent_mobile'] )
84 $userAgent['mobile'] = preg_split( "/,\s*/", $options['userAgent_mobile'] );
85 if ( $options['userAgent_game'] )
86 $userAgent['game'] = preg_split( "/,\s*/", $options['userAgent_game'] );
87
88 foreach ( $options as $key => $val ) {
89 if ( ! preg_match( "/^custom_switcher_userAgent_/", $key ) )
90 continue;
91
92 $custom_switcher_name = preg_replace("/^custom_switcher_userAgent_/", '', $key);
93
94 if ($val)
95 $userAgent['custom_switcher_' . $custom_switcher_name] = preg_split( "/,\s*/", $val );
96 }
97
98 return $userAgent;
99 }
100
101 public function get_stylesheet($stylesheet = '') {
102 $name = $this->get_device_theme();
103
104 if ( empty($name) )
105 return $stylesheet;
106
107 $themes = wp_get_themes();
108 foreach ( $themes as $t ) {
109 if ($name == $t->get('Name')) {
110 $theme = $t;
111 break;
112 }
113 }
114
115 if ( empty($theme) )
116 return $stylesheet;
117
118 if ( $theme->get('Status') != 'publish' )
119 return $stylesheet;
120
121 return $theme['Stylesheet'];
122 }
123
124 public function get_template($template = '') {
125 $name = $this->get_device_theme();
126
127 if ( empty($name) )
128 return $template;
129
130 $themes = wp_get_themes();
131 foreach ( $themes as $t ) {
132 if ($name == $t->get('Name')) {
133 $theme = $t;
134 break;
135 }
136 }
137
138 if ( empty( $theme ) )
139 return $template;
140
141 if ( $theme->get('Status') != 'publish' )
142 return $template;
143
144 return $theme['Template'];
145 }
146
147 public function get_device_theme() {
148 $options = get_option('multi_device_switcher_options');
149
150 if ($this->device == 'smart') {
151 return $options['theme_smartphone'];
152 }
153 elseif ($this->device == 'tablet') {
154 return $options['theme_tablet'];
155 }
156 elseif ($this->device == 'mobile') {
157 return $options['theme_mobile'];
158 }
159 elseif ($this->device == 'game') {
160 return $options['theme_game'];
161 }
162 else {
163 foreach ( $options as $key => $val ) {
164 if ( ! preg_match( "/^custom_switcher_theme_/", $key ) )
165 continue;
166
167 $custom_switcher_name = preg_replace("/^custom_switcher_theme_/", '', $key);
168
169 if ($this->device == 'custom_switcher_' . $custom_switcher_name) {
170 return $options[$key];
171 }
172 }
173 }
174
175 return;
176 }
177 }
178
179 if ( ! is_admin() )
180 $multi_device_switcher = new Multi_Device_Switcher();
181
182 /**
183 * Properly enqueue scripts for our multi_device_switcher options page.
184 *
185 * This function is attached to the admin_enqueue_scripts action hook.
186 *
187 * @since 1.0
188 *
189 */
190 function multi_device_switcher_admin_enqueue_scripts( $hook_suffix ) {
191 wp_enqueue_script('jquery-ui-tabs');
192 wp_enqueue_script( 'multi-device-switcher-options', WP_PLUGIN_URL . '/multi-device-switcher/multi-device-switcher.js', array( 'jquery' ), '2011-08-22' );
193 }
194
195 /**
196 * Properly enqueue styles for our multi_device_switcher options page.
197 *
198 * This function is attached to the admin_enqueue_styles action hook.
199 *
200 * @since 1.0
201 *
202 */
203 function multi_device_switcher_admin_enqueue_styles( $hook_suffix ) {
204 wp_enqueue_style( 'multi-device-switcher-options', WP_PLUGIN_URL . '/multi-device-switcher/multi-device-switcher.css', false, '2011-08-22' );
205 wp_enqueue_style( 'thickbox', includes_url() . '/js/thickbox/thickbox.css', false, '20090514' );
206 }
207
208 /**
209 * Register the form setting for our multi_device_switcher array.
210 *
211 * This function is attached to the admin_init action hook.
212 *
213 * This call to register_setting() registers a validation callback, multi_device_switcher_validate(),
214 * which is used when the option is saved, to ensure that our option values are complete, properly
215 * formatted, and safe.
216 *
217 * @since 1.0
218 */
219 function multi_device_switcher_init() {
220 // If we have no options in the database, let's add them now.
221 if ( false === multi_device_switcher_get_options() )
222 add_option( 'multi_device_switcher_options' );
223
224 register_setting(
225 'multi_device_switcher', // Options group, see settings_fields() call in multi_device_switcher_render_page()
226 'multi_device_switcher_options', // Database option, see multi_device_switcher_get_options()
227 'multi_device_switcher_validate' // The sanitization callback, see multi_device_switcher_validate()
228 );
229 }
230
231 add_action( 'admin_init', 'multi_device_switcher_init' );
232
233 /**
234 * Change the capability required to save the 'multi_device_switcher' options group.
235 *
236 * @see multi_device_switcher_init() First parameter to register_setting() is the name of the options group.
237 * @see multi_device_switcher_add_page() The edit_theme_options capability is used for viewing the page.
238 *
239 * By default, the options groups for all registered settings require the manage_options capability.
240 * By default, only administrators have either of these capabilities, but the desire here is
241 * to allow for finer-grained control for roles and users.
242 *
243 * @param string $capability The capability used for the page, which is manage_options by default.
244 * @return string The capability to actually use.
245 */
246 function multi_device_switcher_page_capability( $capability ) {
247 return 'edit_theme_options';
248 }
249 add_filter( 'option_page_capability_multi_device_switcher', 'multi_device_switcher_page_capability' );
250
251 /**
252 * Add our options page to the admin menu, including some help documentation.
253 *
254 * This function is attached to the admin_menu action hook.
255 *
256 * @since 1.0
257 */
258 function multi_device_switcher_add_page() {
259 load_plugin_textdomain('multi-device-switcher', false, 'multi-device-switcher/languages');
260
261 $theme_page = add_theme_page(
262 __( 'Multi Device Switcher', 'multi-device-switcher' ), // Name of page
263 __( 'Multi Device Switcher', 'multi-device-switcher' ), // Label in menu
264 'manage_options', // Capability required
265 'multi-device-switcher', // Menu slug, used to uniquely identify the page
266 'multi_device_switcher_render_page' // Function that renders the options page
267 );
268
269 if ( ! $theme_page )
270 return;
271
272 $help = '';
273
274 if ($help)
275 add_contextual_help( $theme_page, $help );
276
277 add_action( "admin_print_scripts-$theme_page", 'multi_device_switcher_admin_enqueue_scripts' );
278 add_action( "admin_print_styles-$theme_page", 'multi_device_switcher_admin_enqueue_styles' );
279 }
280 add_action( 'admin_menu', 'multi_device_switcher_add_page' );
281
282 /**
283 * Returns the default options.
284 *
285 * @since 1.0
286 */
287 function multi_device_switcher_get_default_options() {
288 $default_theme_options = array(
289 'theme_smartphone' => 'None',
290 'theme_tablet' => 'None',
291 'theme_mobile' => 'None',
292 'theme_game' => 'None',
293 'userAgent_smart' => 'iPhone, iPod, Android, dream, CUPCAKE, Windows Phone, webOS, BlackBerry8707, BlackBerry9000, BlackBerry9300, BlackBerry9500, BlackBerry9530, BlackBerry9520, BlackBerry9550, BlackBerry9700, BlackBerry9800',
294 'userAgent_tablet' => 'iPad',
295 'userAgent_mobile' => 'DoCoMo, SoftBank, J-PHONE, Vodafone, KDDI, UP.Browser, WILLCOM, emobile, DDIPOCKET, Windows CE, BlackBerry, Symbian, PalmOS, Huawei, IAC, Nokia',
296 'userAgent_game' => 'PlayStation Portable, PlayStation Vita, PSP, PS2, PLAYSTATION 3, Nitro, Nintendo 3DS, Nintendo Wii',
297 );
298
299 return $default_theme_options;
300 }
301
302 /**
303 * Returns the options array.
304 *
305 * @since 1.0
306 */
307 function multi_device_switcher_get_options() {
308 $options = get_option( 'multi_device_switcher_options' );
309 $default_options = multi_device_switcher_get_default_options();
310
311 if ( ! isset( $options['theme_smartphone'] ) )
312 $options['theme_smartphone'] = $default_options['theme_smartphone'];
313 if ( ! isset( $options['theme_tablet'] ) )
314 $options['theme_tablet'] = $default_options['theme_tablet'];
315 if ( ! isset( $options['theme_mobile'] ) )
316 $options['theme_mobile'] = $default_options['theme_mobile'];
317 if ( ! isset( $options['theme_game'] ) )
318 $options['theme_game'] = $default_options['theme_game'];
319
320 if ( ! isset( $options['userAgent_smart'] ) )
321 $options['userAgent_smart'] = $default_options['userAgent_smart'];
322 if ( ! isset( $options['userAgent_tablet'] ) )
323 $options['userAgent_tablet'] = $default_options['userAgent_tablet'];
324 if ( ! isset( $options['userAgent_mobile'] ) )
325 $options['userAgent_mobile'] = $default_options['userAgent_mobile'];
326 if ( ! isset( $options['userAgent_game'] ) )
327 $options['userAgent_game'] = $default_options['userAgent_game'];
328
329 return $options;
330 }
331
332 /**
333 * Rendering Options Setting Page.
334 *
335 * @since 1.0
336 */
337 function multi_device_switcher_render_page() {
338 ?>
339 <div class="wrap" style="width: 60%; float: left;">
340 <div id="icon-themes" class="icon32"><br></div>
341 <h2><?php printf( __( 'Multi Device Switcher', 'multi-device-switcher' ), wp_get_theme()->get('Name') ); ?></h2>
342 <?php settings_errors(); ?>
343
344 <form method="post" action="options.php">
345 <?php
346 settings_fields( 'multi_device_switcher' );
347 $options = multi_device_switcher_get_options();
348
349 $default_theme = wp_get_theme()->get('Name');
350 $themes = wp_get_themes();
351 $theme_names = array();
352
353 if (count($themes)) {
354 foreach ( $themes as $t ) {
355 $theme_names[] = $t->get('Name');
356 }
357 natcasesort($theme_names);
358 }
359 ?>
360
361 <div id="admin-tabs">
362 <fieldset id="Theme" class="options">
363 <h3 class="label"><?php _e( 'Theme', 'multi-device-switcher' ); ?></h3>
364 <table class="form-table">
365 <tr><th scope="row"><?php _e( 'Smart Phone Theme', 'multi-device-switcher' ); ?></th>
366 <td>
367
368 <?php
369 if (count($theme_names)) {
370 $html = '<select name="multi_device_switcher_options[theme_smartphone]">';
371
372 if (($options['theme_smartphone'] == 'None') || ($options['theme_smartphone'] == '')) {
373 $html .= '<option value="None" selected="selected">None</option>';
374 }
375 else {
376 $html .= '<option value="None">None</option>';
377 }
378
379 foreach ($theme_names as $theme_name) {
380 if ($default_theme == $theme_name)
381 continue;
382 if ($options['theme_smartphone'] == $theme_name) {
383 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
384 }
385 else {
386 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
387 }
388 }
389 $html .= '</select>';
390 }
391 echo $html;
392 ?>
393 </td>
394 </tr>
395 <tr><th scope="row"><?php _e( 'Tablet PC Theme', 'multi-device-switcher' ); ?></th>
396 <td>
397
398 <?php
399 if (count($theme_names)) {
400 $html = '<select name="multi_device_switcher_options[theme_tablet]">';
401
402 if (($options['theme_tablet'] == 'None') || ($options['theme_tablet'] == '')) {
403 $html .= '<option value="None" selected="selected">None</option>';
404 }
405 else {
406 $html .= '<option value="None">None</option>';
407 }
408
409 foreach ($theme_names as $theme_name) {
410 if ($default_theme == $theme_name)
411 continue;
412 if ($options['theme_tablet'] == $theme_name) {
413 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
414 }
415 else {
416 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
417 }
418 }
419 $html .= '</select>';
420 }
421 echo $html;
422 ?>
423 </td>
424 </tr>
425 <tr><th scope="row"><?php _e( 'Mobile Phone Theme', 'multi-device-switcher' ); ?></th>
426 <td>
427
428 <?php
429 if (count($theme_names)) {
430 $html = '<select name="multi_device_switcher_options[theme_mobile]">';
431
432 if (($options['theme_mobile'] == 'None') || ($options['theme_mobile'] == '')) {
433 $html .= '<option value="None" selected="selected">None</option>';
434 }
435 else {
436 $html .= '<option value="None">None</option>';
437 }
438
439 foreach ($theme_names as $theme_name) {
440 if ($default_theme == $theme_name)
441 continue;
442 if ($options['theme_mobile'] == $theme_name) {
443 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
444 }
445 else {
446 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
447 }
448 }
449 $html .= '</select>';
450 }
451 echo $html;
452 ?>
453 </td>
454 </tr>
455 <tr><th scope="row"><?php _e( 'Game Platforms Theme', 'multi-device-switcher' ); ?></th>
456 <td>
457
458 <?php
459 if (count($theme_names)) {
460 $html = '<select name="multi_device_switcher_options[theme_game]">';
461
462 if (($options['theme_game'] == 'None') || ($options['theme_game'] == '')) {
463 $html .= '<option value="None" selected="selected">None</option>';
464 }
465 else {
466 $html .= '<option value="None">None</option>';
467 }
468
469 foreach ($theme_names as $theme_name) {
470 if ($default_theme == $theme_name)
471 continue;
472 if ($options['theme_game'] == $theme_name) {
473 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
474 }
475 else {
476 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
477 }
478 }
479 $html .= '</select>';
480 }
481 echo $html;
482 ?>
483 </td>
484 </tr>
485 </table>
486
487 <h3><?php _e( 'Custom Switcher Theme', 'multi-device-switcher' ); ?></h3>
488 <table class="form-table">
489
490 <?php
491 foreach ( $options as $key => $val ) {
492 if ( ! preg_match( "/^custom_switcher_theme_/", $key ) )
493 continue;
494
495 $custom_switcher_name = preg_replace("/^custom_switcher_theme_/", '', $key);
496 $custom_switcher_option = $key;
497 $custom_switcher_theme = $val;
498 ?>
499
500 <tr><th scope="row"><?php _e( $custom_switcher_name, 'multi-device-switcher' ); ?></th>
501 <td>
502
503 <?php
504 if (count($theme_names)) {
505 $html = '<select name="multi_device_switcher_options[' . $custom_switcher_option . ']">';
506
507 if (($custom_switcher_theme == 'None') || ($custom_switcher_theme == '')) {
508 $html .= '<option value="None" selected="selected">None</option>';
509 }
510 else {
511 $html .= '<option value="None">None</option>';
512 }
513
514 foreach ($theme_names as $theme_name) {
515 if ($default_theme == $theme_name)
516 continue;
517 if ($custom_switcher_theme == $theme_name) {
518 $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
519 }
520 else {
521 $html .= '<option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>';
522 }
523 }
524 $html .= '</select>';
525 $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 ) . '\');""></span>';
526 }
527 echo $html;
528 ?>
529 </td>
530 </tr>
531
532 <?php
533 }
534 ?>
535
536 <tr><th scope="row"><?php _e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></th>
537 <td>
538 <fieldset><legend class="screen-reader-text"><span><?php _e( 'Add Custom Switcher', 'thingscms' ); ?></span></legend>
539 <input type="text" name="multi_device_switcher_options[custom_switcher]" id="custom-switcher" value="" size="24" />
540 <span class="submit"><input type="submit" name="multi_device_switcher_options[add_custom_switcher]" value="<?php _e( 'Add', 'multi-device-switcher' ); ?>"></span><br>
541 <?php _e( '20 characters max, alphanumeric', 'multi-device-switcher' ); ?>
542 </td>
543 </tr>
544 </table>
545
546 </fieldset>
547
548 <fieldset id="UserAgent" class="options">
549 <h3 class="label"><?php _e( 'UserAgent', 'multi-device-switcher' ); ?></h3>
550 <p><?php _e( 'Enter Comma-separated values (csv) format.', 'multi-device-switcher' ); ?></p>
551
552 <table class="form-table">
553 <tr><th scope="row"><?php _e( 'Smart Phone', 'multi-device-switcher' ); ?></th>
554 <td><textarea name="multi_device_switcher_options[userAgent_smart]" rows="4" cols="42"><?php echo $options['userAgent_smart']; ?></textarea></td>
555 </tr>
556 <tr><th scope="row"><?php _e( 'Tablet PC', 'multi-device-switcher' ); ?></th>
557 <td><textarea name="multi_device_switcher_options[userAgent_tablet]" rows="4" cols="42"><?php echo $options['userAgent_tablet']; ?></textarea></td>
558 </tr>
559 <tr><th scope="row"><?php _e( 'Mobile Phone', 'multi-device-switcher' ); ?></th>
560 <td><textarea name="multi_device_switcher_options[userAgent_mobile]" rows="4" cols="42"><?php echo $options['userAgent_mobile']; ?></textarea></td>
561 </tr>
562 <tr><th scope="row"><?php _e( 'Game Platforms', 'multi-device-switcher' ); ?></th>
563 <td><textarea name="multi_device_switcher_options[userAgent_game]" rows="4" cols="42"><?php echo $options['userAgent_game']; ?></textarea></td>
564 </tr>
565 <tr><th></th>
566 <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' ); ?>"></span></td>
567 </tr>
568
569 <?php
570 foreach ( $options as $key => $val ) {
571 if ( ! preg_match( "/^custom_switcher_userAgent_/", $key ) )
572 continue;
573
574 $custom_switcher_name = preg_replace("/^custom_switcher_userAgent_/", '', $key);
575 $custom_switcher_option = $key;
576 $custom_switcher_userAgent = $val;
577 ?>
578
579 <tr><th scope="row"><?php _e( $custom_switcher_name, 'multi-device-switcher' ); ?></th>
580 <td><textarea name="multi_device_switcher_options[<?php echo $custom_switcher_option; ?>]" rows="4" cols="42"><?php echo $custom_switcher_userAgent; ?></textarea></td>
581 </tr>
582 <?php
583 }
584 ?>
585
586 </table>
587 </fieldset>
588 </div>
589 <?php submit_button(); ?>
590 </form>
591 </div>
592
593 <div id="donate" style="width: 36%; float: left; margin: 2em 0;padding: 0.4em;border: 1px solid #ddd;">
594 <h2><?php _e( 'Donationware', 'multi-device-switcher' ); ?></h2>
595 <p><?php _e( 'If you like this plugin, please donate to support development and maintenance.', 'multi-device-switcher' ); ?></p>
596 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
597 <input type="hidden" name="cmd" value="_s-xclick">
598 <input type="hidden" name="hosted_button_id" value="9L53NELFMHTWW">
599 <table>
600 <tr><td><input type="hidden" name="on0" value="Donationware">Donationware</td></tr><tr><td><select name="os0">
601 <option value="1. Donate">1. Donate $3.00 USD</option>
602 <option value="2. Donate">2. Donate $5.00 USD</option>
603 <option value="3. Donate">3. Donate $7.00 USD</option>
604 <option value="4. Donate" selected="selected">4. Donate $10.00 USD</option>
605 <option value="5. Donate">5. Donate $20.00 USD</option>
606 <option value="6. Donate">6. Donate $30.00 USD</option>
607 <option value="7. Donate">7. Donate $40.00 USD</option>
608 <option value="8. Donate">8. Donate $50.00 USD</option>
609 <option value="9. Donate">9. Donate $60.00 USD</option>
610 <option value="10. Donate">10. Donate $70.00 USD</option>
611 </select> </td></tr>
612 </table>
613 <input type="hidden" name="currency_code" value="USD">
614 <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!">
615 <img alt="" border="0" src="https://www.paypalobjects.com/ja_JP/i/scr/pixel.gif" width="1" height="1">
616 </form>
617 </div>
618
619 <?php
620 }
621
622 /**
623 * Sanitize and validate form input. Accepts an array, return a sanitized array.
624 *
625 * @see multi_device_switcher_init()
626 *
627 * @since 1.0
628 */
629 function multi_device_switcher_validate( $input ) {
630 $output = $default_options = multi_device_switcher_get_default_options();
631
632 if ( isset( $input['theme_smartphone'] ) )
633 $output['theme_smartphone'] = $input['theme_smartphone'];
634 if ( isset( $input['theme_tablet'] ) )
635 $output['theme_tablet'] = $input['theme_tablet'];
636 if ( isset( $input['theme_mobile'] ) )
637 $output['theme_mobile'] = $input['theme_mobile'];
638 if ( isset( $input['theme_game'] ) )
639 $output['theme_game'] = $input['theme_game'];
640
641 if (isset( $input['restore_UserAgent'] )) {
642 $output['userAgent_smart'] = $default_options['userAgent_smart'];
643 $output['userAgent_tablet'] = $default_options['userAgent_tablet'];
644 $output['userAgent_mobile'] = $default_options['userAgent_mobile'];
645 $output['userAgent_game'] = $default_options['userAgent_game'];
646 }
647 else {
648 if ( isset( $input['userAgent_smart'] ) )
649 $output['userAgent_smart'] = $input['userAgent_smart'];
650 if ( isset( $input['userAgent_tablet'] ) )
651 $output['userAgent_tablet'] = $input['userAgent_tablet'];
652 if ( isset( $input['userAgent_mobile'] ) )
653 $output['userAgent_mobile'] = $input['userAgent_mobile'];
654 if ( isset( $input['userAgent_game'] ) )
655 $output['userAgent_game'] = $input['userAgent_game'];
656 }
657
658 foreach ( $input as $key => $val ) {
659 if ( ! preg_match( "/^custom_switcher_theme_/", $key ) )
660 continue;
661
662 $custom_switcher_name = preg_replace("/^custom_switcher_theme_/", '', $key);
663
664 if ( isset( $input['custom_switcher_theme_' . $custom_switcher_name] ) )
665 $output['custom_switcher_theme_' . $custom_switcher_name] = $input['custom_switcher_theme_' . $custom_switcher_name];
666 if ( isset( $input['custom_switcher_userAgent_' . $custom_switcher_name] ) )
667 $output['custom_switcher_userAgent_' . $custom_switcher_name] = $input['custom_switcher_userAgent_' . $custom_switcher_name];
668 }
669
670 foreach ( $input as $key => $val ) {
671 if ( ! preg_match( "/^delete_custom_switcher_/", $key ) )
672 continue;
673
674 $custom_switcher_name = preg_replace("/^delete_custom_switcher_/", '', $key);
675
676 unset($output['custom_switcher_theme_' . $custom_switcher_name]);
677 unset($output['custom_switcher_userAgent_' . $custom_switcher_name]);
678 }
679
680 if ( isset( $input['add_custom_switcher'] ) && ! empty( $input['custom_switcher'] ) && ! $output['custom_switcher_theme_' . $input['custom_switcher']] ) {
681 if ( preg_match( "/^[A-Za-z0-9]{1,20}$/", $input['custom_switcher'] ) ) {
682 $output['custom_switcher_theme_' . $input['custom_switcher']] = 'None';
683 $output['custom_switcher_userAgent_' . $input['custom_switcher']] = '';
684 }
685 }
686
687 return apply_filters( 'multi_device_switcher_validate', $output, $input, $default_options );
688 }
689
690 ?>
691