Plugin Directory

Changeset 994077


Ignore:
Timestamp:
09/21/2014 02:17:43 AM (11 years ago)
Author:
federico_jacobi
Message:

Small update, logic change, and added security fix

Location:
theme-to-browser-t2b-control/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • theme-to-browser-t2b-control/trunk/readme.txt

    r991519 r994077  
    22Contributors: federico_jacobi
    33Donate link: http://www.federicojacobi.com/
    4 Tags: themes, browser, design, control, browser control, mobile, blackberry, ps3
     4Tags: themes, browser, design, control, browser control, mobile, blackberry, ps3, ie, internet explorer
    55Requires at least: 3.4
    66Tested up to: 4.0
    7 Stable tag: 0.5
     7Stable tag: 1.0
    88
    99Displays different themes based on the browser used.
     
    1515PLEASE vote and/or rate if it works for you or let me know if there's a fix needed at web[at]federicojacobi.com.
    1616
    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.
     17Supported browsers for now: Internet Explorer, FireFox, Chrome, Opera, iPad/iPhone/iPod, Safari, Playstation 3, and BlackBerries.
    1818
    1919Thanks to Drazen Mokic, Nicholas McQuillin and Paul Gregory for their help and suggestions.
     
    2727== Frequently Asked Questions ==
    2828What browsers are detected?
    29 Internet Explorer, FireFox, Opera, iPad/iPhone/iPod, Safari, BlackBerry8310, BlackBerry
     29Internet Explorer, FireFox, Opera, iPad/iPhone/iPod, Safari, BlackBerry
    3030
    3131Can I add other browsers?
     
    3333
    3434What about browser versions (ie5, ie6, operamini) ?
    35 Not yet, but you can add your own. See question 2.
     35Not 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!
    3636
    3737What if the browser is not detected?
     
    5151
    5252== Changelog ==
     53= 1.0 =
     54A 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 :-)
     55Removed BlackBerry8310 from the list of browsers.
     56
    5357= 0.5 =
    5458Complete modernization and rewrite. Cleared a bunch of notices and deprecated functions.
     
    6973= 0.1 =
    7074First 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  
    22/*
    33Plugin Name: Theme to Browser (T2B) Control
    4 Plugin URI: http://www.federicojacobi.com/wp/work/t2b-control/
    54Description: 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.5
     5Version: 1.0
    76Author: Federico Jacobi
    87Author URI: http://www.federicojacobi.com
    98*/
    109
     10defined('ABSPATH') or die("No script kiddies please!");
     11
    1112class Theme2Browser {
    1213
    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();
    2915    var $user_agent = '';
    30     var $debug = 0;
    3116    var $theme = '';
    3217    var $theme_parent = '';
    3318
    3419    function __construct() {
    35         add_action( 'plugins_loaded', array( $this, 'init' ) );
     20        add_action( 'setup_theme', array( $this, 'init' ) );
    3621    }
    3722   
    3823    function init() {
    3924        $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       
    4166       
    4267        register_activation_hook( __FILE__, array( $this, 'onActivation' ) );
     
    4873   
    4974    function T2B() {
     75        if ( ! is_array( $this->supported_browsers ) )
     76            return false;
     77   
    5078        $this->user_agent = $_SERVER['HTTP_USER_AGENT'];
    5179        if ( ! is_admin() ) {
    5280            $option = get_option( 't2b_options' );
    5381           
    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 ];
    5785                    break;
    5886                }
     
    90118        add_settings_section( 'debug', 'Debug Mode', null , 't2b_control' );
    91119       
    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 ) );
    94122        }
    95123       
     
    100128        $options = get_option( 't2b_options' );
    101129       
    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;
    106136
    107137        $themes = wp_get_themes();
     
    152182            ?>
    153183            <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', '' ); ?>
    154185           
    155186            <form action="options.php" method="post">
     
    168199            <h3>How to add your browser/variation/version</h3>
    169200            <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>
    173206            <p>
    174207                Find the <code>$supported_browsers</code> array and add the proper regular expression to evaluate against the user agent string.
     
    176209            </p>
    177210<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);
    194233</pre>
    195234
     
    204243                <?php
    205244                $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' ];
    208247                }
    209248                echo esc_html( implode( ', ', $browsers ) );
     
    215254
    216255    function debugInfo() {
    217         if ( ! $this->debug )
     256        $options = get_option( 't2b_options' );
     257        $debug = $options[ 'debug' ];
     258        if ( ! $debug )
    218259            return;
    219260    ?>
Note: See TracChangeset for help on using the changeset viewer.