Changeset 994077
- Timestamp:
- 09/21/2014 02:17:43 AM (11 years ago)
- Location:
- theme-to-browser-t2b-control/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (6 diffs)
-
t2b.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
theme-to-browser-t2b-control/trunk/readme.txt
r991519 r994077 2 2 Contributors: federico_jacobi 3 3 Donate link: http://www.federicojacobi.com/ 4 Tags: themes, browser, design, control, browser control, mobile, blackberry, ps3 4 Tags: themes, browser, design, control, browser control, mobile, blackberry, ps3, ie, internet explorer 5 5 Requires at least: 3.4 6 6 Tested up to: 4.0 7 Stable tag: 0.57 Stable tag: 1.0 8 8 9 9 Displays different themes based on the browser used. … … 15 15 PLEASE vote and/or rate if it works for you or let me know if there's a fix needed at web[at]federicojacobi.com. 16 16 17 Supported browsers for now: Internet Explorer, FireFox, Chrome, Opera, iPad/iPhone/iPod, Safari, Playstation 3, BlackBerry8310 specifically, and other BlackBerry models (non-specific). All of them modern versions, however, version specific detection will come in future upgrades of the plugin.17 Supported browsers for now: Internet Explorer, FireFox, Chrome, Opera, iPad/iPhone/iPod, Safari, Playstation 3, and BlackBerries. 18 18 19 19 Thanks to Drazen Mokic, Nicholas McQuillin and Paul Gregory for their help and suggestions. … … 27 27 == Frequently Asked Questions == 28 28 What browsers are detected? 29 Internet Explorer, FireFox, Opera, iPad/iPhone/iPod, Safari, BlackBerry 8310, BlackBerry29 Internet Explorer, FireFox, Opera, iPad/iPhone/iPod, Safari, BlackBerry 30 30 31 31 Can I add other browsers? … … 33 33 34 34 What about browser versions (ie5, ie6, operamini) ? 35 Not yet, but you can add your own. See question 2. 35 Not yet, but you can add your own. See question 2. You can alternatively use the Theme to Browser Control - IE Pack to handle versions of IE. More packs to come! 36 36 37 37 What if the browser is not detected? … … 51 51 52 52 == Changelog == 53 = 1.0 = 54 A couple of security fixes (nothing huge) and minor logic change. Also added filters so the plugin is pluggable itself. Moved to 1.0 as this is now fairly mature :-) 55 Removed BlackBerry8310 from the list of browsers. 56 53 57 = 0.5 = 54 58 Complete modernization and rewrite. Cleared a bunch of notices and deprecated functions. … … 69 73 = 0.1 = 70 74 First version published. Yay! 71 72 == Upgrade Notice ==73 = 0.21 =74 The plugin wasn't working with child themes, now it is! Important fix. iPad added to browser list.75 76 = 0.2 =77 Non critical update. It adds support for BlackBerry phones.78 79 = 0.1 =80 First version -
theme-to-browser-t2b-control/trunk/t2b.php
r991519 r994077 2 2 /* 3 3 Plugin Name: Theme to Browser (T2B) Control 4 Plugin URI: http://www.federicojacobi.com/wp/work/t2b-control/5 4 Description: Display a different theme depending on the users browser. It is perfect for a quick way out of CSS annoyances and also for customization on mobile devices. Supports: Internet Explorer, FireFox, Opera, iPhone/iPod, iPad, Safari, BlackBerries, Playstation 3 6 Version: 0.55 Version: 1.0 7 6 Author: Federico Jacobi 8 7 Author URI: http://www.federicojacobi.com 9 8 */ 10 9 10 defined('ABSPATH') or die("No script kiddies please!"); 11 11 12 class Theme2Browser { 12 13 13 var $supported_browsers = array ( 14 '|MSIE ([0-9]?.[0-9]{1,2})|' => array('ie','Internet Explorer'), 15 '|Firefox/([0-9\.]+)|' => array('firefox','FireFox'), 16 '/Opera|OPR\/(.[0-9]){1,5}/' => array('opera','Opera'), 17 18 '|Chrome/[0-9]{1,3}(.[0-9]{1,3}){1,5}|' => array('chrome','Chrome'), 19 20 '/\(iPhone|iPod/' => array('iphone','iPhone, iPod'), 21 '/\(iPad/' => array('ipad','iPad'), 22 '|Safari|' => array('safari','Safari'), 23 24 '/BlackBerry8310/' => array('blackberry8310','BlackBerry 8310'), 25 '/BlackBerry/' => array('blackberry','All BlackBerry'), 26 '/PLAYSTATION 3|PS3/' => array('ps3','Playstation 3') 27 ); 28 14 var $supported_browsers = array(); 29 15 var $user_agent = ''; 30 var $debug = 0;31 16 var $theme = ''; 32 17 var $theme_parent = ''; 33 18 34 19 function __construct() { 35 add_action( ' plugins_loaded', array( $this, 'init' ) );20 add_action( 'setup_theme', array( $this, 'init' ) ); 36 21 } 37 22 38 23 function init() { 39 24 $options = get_option( 't2b_options' ); 40 $this->debug = intval( $options[ 'debug' ] ); 25 26 $this->supported_browsers = apply_filters( 't2b-browsers', array ( 27 28 'ie' => array( 29 'regex' => '/(MSIE [0-9]?.[0-9]{1,2})|(Mozilla\/5\.0.*rv:11.[0-9]{1,2})/', 30 'title' => 'Internet Explorer' 31 ), 32 'firefox' => array( 33 'regex' => '|Firefox/([0-9\.]+)|', 34 'title' => 'Firefox' 35 ), 36 'opera' => array( 37 'regex' => '/Opera|OPR\/(.[0-9]){1,5}/', 38 'title' => 'Opera' 39 ), 40 'chrome' => array( 41 'regex' => '|Chrome/[0-9]{1,3}(.[0-9]{1,3}){1,5}|', 42 'title' => 'Chrome' 43 ), 44 'iphone' => array( 45 'regex' => '/\(iPhone|iPod/', 46 'title' => 'iPhone' 47 ), 48 'ipad' => array( 49 'regex' => '/\(iPad/', 50 'title' => 'iPad' 51 ), 52 'safari' => array( 53 'regex' => '|Safari|', 54 'title' => 'Safari' 55 ), 56 'blackberry' => array( 57 'regex' => '/BlackBerry/', 58 'title' => 'All BlackBerry' 59 ), 60 'ps3' => array( 61 'regex' => '/PLAYSTATION 3|PS3/', 62 'title' => 'Playstation 3' 63 ) 64 ) ); 65 41 66 42 67 register_activation_hook( __FILE__, array( $this, 'onActivation' ) ); … … 48 73 49 74 function T2B() { 75 if ( ! is_array( $this->supported_browsers ) ) 76 return false; 77 50 78 $this->user_agent = $_SERVER['HTTP_USER_AGENT']; 51 79 if ( ! is_admin() ) { 52 80 $option = get_option( 't2b_options' ); 53 81 54 foreach ( $this->supported_browsers as $ browser_regex => $browser_name) {55 if ( preg_match( $browser_ regex, $this->user_agent, $matched ) ) {56 $this->theme = $option[ $ browser_name[0]];82 foreach ( $this->supported_browsers as $id => $browser_data ) { 83 if ( preg_match( $browser_data[ 'regex' ], $this->user_agent, $matched ) ) { 84 $this->theme = $option[ $id ]; 57 85 break; 58 86 } … … 90 118 add_settings_section( 'debug', 'Debug Mode', null , 't2b_control' ); 91 119 92 foreach ( $this->supported_browsers as $ browser_regex => $browser_name) {93 add_settings_field( 't2b_' . $ browser_name[0], $browser_name[1], array( $this, 'render_browser_option' ), 't2b_control', 'browsers', array( 'browser_info' => $browser_name, 'regex' => $browser_regex) );120 foreach ( $this->supported_browsers as $id => $browser_data ) { 121 add_settings_field( 't2b_' . $id, $browser_data[ 'title' ], array( $this, 'render_browser_option' ), 't2b_control', 'browsers', array( 'id' => $id ) ); 94 122 } 95 123 … … 100 128 $options = get_option( 't2b_options' ); 101 129 102 $browser_slug = $args[ 'browser_info' ][ 0 ]; 103 $browser_name = $args[ 'browser_info' ][ 1 ]; 104 105 $selected_theme = $options[ $browser_slug ]; 130 $browser_slug = sanitize_text_field( $args[ 'id' ] ); 131 132 if ( isset( $options[ $browser_slug ] ) ) 133 $selected_theme = $options[ $browser_slug ]; 134 else 135 $selected_theme = false; 106 136 107 137 $themes = wp_get_themes(); … … 152 182 ?> 153 183 <h2>Theme to Browser Control a.k.a. T2B (v.<?php echo esc_html( $plugin_data[ 'Version' ] ) ?>)</h2> 184 <?php echo apply_filters( 't2b-extra-text', '' ); ?> 154 185 155 186 <form action="options.php" method="post"> … … 168 199 <h3>How to add your browser/variation/version</h3> 169 200 <p>First you need some really basic knowledge of regular expressions and php.</p> 170 <p>Because you are loading a completely different theme using filters is not an option, so you have to dive 171 into the plugin's code to do it, however, it is easy enough. 172 </p> 201 <p>Because you are loading a completely different theme using filters in your theme is not an option. It kicks in too late. 202 So you have to dive into the plugin's code to do it, however, it is easy enough.</p> 203 204 <p>Alternatively you could hook into <code>plugins_loaded</code> with a plugin and use the 205 <code>t2b-browsers</code> filter to make you own extension.</p> 173 206 <p> 174 207 Find the <code>$supported_browsers</code> array and add the proper regular expression to evaluate against the user agent string. … … 176 209 </p> 177 210 <pre> 178 var $supported_browsers = array ( 179 '|MSIE ([0-9]?.[0-9]{1,2})|' => array('ie','Internet Explorer'), 180 '|Firefox/([0-9\.]+)|' => array('firefox','FireFox'), 181 '/Opera|OPR\/(.[0-9]){1,5}/' => array('opera','Opera'), 182 183 '|Chrome/[0-9]{1,3}(.[0-9]{1,3}){1,5}|' => array('chrome','Chrome'), 184 185 '/\(iPhone|iPod/' => array('iphone','iPhone, iPod'), 186 '/\(iPad/' => array('ipad','iPad'), 187 '|Safari|' => array('safari','Safari'), 188 189 '/BlackBerry8310/' => array('blackberry8310','BlackBerry 8310'), 190 '/BlackBerry/' => array('blackberry','All BlackBerry'), 191 '/PLAYSTATION 3|PS3/' => array('ps3','Playstation 3'), 192 '/Nintendo Wii/' => array('wii','Nintendo Wii') // <------ THIS LINE ADDED 193 ); 211 $this->supported_browsers = apply_filters( 't2b-browsers', array ( 212 'ie' => array( 213 'regex' => '|MSIE ([0-9]?.[0-9]{1,2})|', 214 'title' => 'Internet Explorer' 215 ), 216 'firefox' => array( 217 'regex' => '|Firefox/([0-9\.]+)|', 218 'title' => 'Firefox' 219 ), 220 . 221 . 222 . 223 'ps3' => array( 224 'regex' => '/PLAYSTATION 3|PS3/', 225 'title' => 'Playstation 3' 226 ), 227 // ADDING NINTENDO WII BROWSER EXCEPTION 228 'wii' => array( 229 'regex' => '/Nintendo Wii/', 230 'title' => 'Nintendo Wii' 231 ) 232 ); 194 233 </pre> 195 234 … … 204 243 <?php 205 244 $browsers = array(); 206 foreach ( $this->supported_browsers as $ browser_regex => $browser_info) {207 $browsers[] = $browser_ info[1];245 foreach ( $this->supported_browsers as $id => $browser_data ) { 246 $browsers[] = $browser_data[ 'title' ]; 208 247 } 209 248 echo esc_html( implode( ', ', $browsers ) ); … … 215 254 216 255 function debugInfo() { 217 if ( ! $this->debug ) 256 $options = get_option( 't2b_options' ); 257 $debug = $options[ 'debug' ]; 258 if ( ! $debug ) 218 259 return; 219 260 ?>
Note: See TracChangeset
for help on using the changeset viewer.