WordPress.org

Plugin Directory

Changeset 632295


Ignore:
Timestamp:
11/30/12 17:43:38 (17 months ago)
Author:
trepmal
Message:

1.2-beta

Location:
simple-mobile-url-redirect/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • simple-mobile-url-redirect/trunk/mobile-redirect.php

    r535633 r632295  
    33Plugin Name: Mobile Redirect 
    44Description: Select a URL to point mobile users to 
    5 Author: InsideOut Solutions (JW) 
    6 Version: 1.1 
     5Author: InsideOut Solutions (JW/KDL) 
     6Version: 1.2 
    77Author URI: http://insideout.com/ 
    88*/ 
     
    1010/*  Copyright 2012  InsideOut Solutions  (email : info@insideout.com) 
    1111 
    12     This program is free software; you can redistribute it and/or modify 
    13     it under the terms of the GNU General Public License, version 2, as  
    14     published by the Free Software Foundation. 
     12    This program is free software; you can redistribute it and/or modify 
     13    it under the terms of the GNU General Public License, version 2, as 
     14    published by the Free Software Foundation. 
    1515 
    16     This program is distributed in the hope that it will be useful, 
    17     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    19     GNU General Public License for more details. 
     16    This program is distributed in the hope that it will be useful, 
     17    but WITHOUT ANY WARRANTY; without even the implied warranty of 
     18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     19    GNU General Public License for more details. 
    2020 
    21     You should have received a copy of the GNU General Public License 
    22     along with this program; if not, write to the Free Software 
    23     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     21    You should have received a copy of the GNU General Public License 
     22    along with this program; if not, write to the Free Software 
     23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2424 
    2525*/ 
    2626 
    27 $mobileredirect = new mobileredirect(); 
     27$ios_mobile_redirect = new IOS_Mobile_Redirect(); 
    2828 
    29 class mobileredirect{ 
    30      
    31     function mobileredirect(){ //init function 
    32         add_action('admin_menu', array(&$this, 'menu')); 
    33         add_action('template_redirect', array( &$this, 'checkmobile' ) ); 
    34         register_uninstall_hook(__FILE__, 'uninstall_mobile_redirect'); 
    35         function uninstall_mobile_redirect() { delete_option( 'mobileredirecturl' ); delete_option( 'mobileredirecttoggle' ); delete_option('mobileredirectmode'); } 
     29register_uninstall_hook( __FILE__, 'uninstall_mobile_redirect' ); 
     30function uninstall_mobile_redirect() { 
     31    delete_option( 'mobileredirecturl' ); 
     32    delete_option( 'mobileredirecttoggle' ); 
     33    delete_option('mobileredirectmode'); 
     34} 
     35 
     36class IOS_Mobile_Redirect{ 
     37 
     38    function __construct() { //init function 
     39        add_action( 'admin_init', array( &$this, 'admin_init' ) ); 
     40        add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); 
     41        add_action( 'template_redirect', array( &$this, 'template_redirect' ) ); 
     42        // upgrade option from 1.1 to 1.2 
     43        if ( get_option( 'mobileredirecttoggle' ) == 'true' ) 
     44            update_option( 'mobileredirecttoggle', true ); 
    3645    } 
    37      
    38     function menu(){ //adds submenu to options menu 
    39         add_submenu_page( 'options-general.php', 'Mobile Redirect', 'Mobile Redirect', 'administrator', __FILE__, array( &$this, 'page' ) ); 
     46 
     47    function admin_init() { 
     48        add_filter( 'plugin_action_links_'. plugin_basename( __FILE__ ), array( &$this, 'plugin_action_links' ), 10, 4 ); 
    4049    } 
    41       
    42     function page( ) { //admin options page 
    43         if ( isset( $_POST['mobile_update'] ) ) { //do stuff if form is submitted 
    44             if($_POST['mobileurl']) update_option( 'mobileredirecturl',esc_url($_POST['mobileurl'])); 
    45             if($_POST['mobiletoggle']){ update_option( 'mobileredirecttoggle', $_POST['mobiletoggle']); } 
    46             if($_POST['mobilemode']){ update_option( 'mobileredirectmode', $_POST['mobilemode']); } 
    47             else { update_option('mobileredirecttoggle','false'); } 
    48             echo "Updated"; 
     50 
     51    function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) { 
     52        if ( is_plugin_active( $plugin_file ) ) 
     53            $actions[] = '<a href="' . admin_url('options-general.php?page=simple-mobile-url-redirect/mobile-redirect.php') . '">Configure</a>'; 
     54        return $actions; 
     55    } 
     56 
     57    function admin_menu() { 
     58        add_submenu_page( 'options-general.php', __( 'Mobile Redirect', 'mobile-redirect' ), __( 'Mobile Redirect', 'mobile-redirect' ), 'administrator', __FILE__, array( &$this, 'page' ) ); 
     59    } 
     60 
     61    function page() { //admin options page 
     62 
     63        //do stuff if form is submitted 
     64        if ( isset( $_POST['mobileurl'] ) ) { 
     65            update_option( 'mobileredirecturl', esc_url_raw( $_POST['mobileurl'] ) ); 
     66            update_option( 'mobileredirecttoggle', isset( $_POST['mobiletoggle'] ) ? true : false ); 
     67 
     68            if ( $_POST['mobilemode'] ) 
     69                update_option( 'mobileredirectmode', intval( $_POST['mobilemode'] ) ); 
     70 
     71            echo '<div class="updated"><p>' . __( 'Updated', 'mobile-redirect' ) . '</p></div>'; 
    4972        } 
    50         echo ' 
    51         <style> 
    52             .mrWrap p{ background: #eee; width: 50%; border: 1px solid #ccc; padding: 10px; } 
    53             .mrWrap label {  width: 100px; display: block; float: left; }  
    54             .mrWrap div{ margin: 0 0 5px 0;} 
    55         </style> 
    56         '; 
    57         echo '<div class="mrWrap">'; 
    58         echo '<h2>' . __( 'Mobile Redirect' ) . '</h2>'; 
    59         echo '<p>If the checkbox is checked, and a valid URL is inputted, this site will redirect to the specified URL when visited by a mobile device.  This does not include the iPad, but will include most other mobile devices.</p>'; 
    60         echo '<form method="post">'; 
    61         echo '<div><label for="mobiletoggle">Enable Redirect:</label><input type="checkbox" value="true" name="mobiletoggle" id="mobiletoggle" '; 
    62             if(get_option('mobileredirecttoggle',false) == "true") echo "checked"; 
    63         echo '/></div>'; 
    64         echo '<div><label for="mobileurl">Redirect URL:</label><input type="text" name="mobileurl" id="mobileurl" value="'; 
    65             if(get_option('mobileredirecturl',false)) echo get_option('mobileredirecturl',false); 
    66         echo '"></input></div>'; 
    67         echo '<div><label for="mobilemode">Redirect Mode:</label>'; 
    68             echo '<select id="mobilemode" name="mobilemode">'; 
    69             echo '<option value="301" '; 
    70             if(get_option('mobilemode',false) != "302") echo "checked"; 
    71             echo '>301</option>'; 
    72             echo '<option value="302" '; 
    73             if(get_option('mobilemode',false) == "302") echo "checked"; 
    74             echo '>302</option>'; 
    75         echo '</select></div>'; 
    76         echo '<input type="hidden" name="mobile_update" />'; 
    77         echo '<input type="submit" value="Save">'; 
    78         echo '</form>'; 
    79         echo '</div>'; 
    80         echo '<br/><br/>'; 
    81         echo '<div class="copyFooter"> 
    82         Plugin written by <a href="http://insideout.com">InsideOut Solutions</a>.  For more information on our plugins visit <a href="http://insideout.com/the-insideout-advantage/web-hosting/custom-development/">our custom coding page</a>. 
    83         </div>'; 
     73 
     74        ?> 
     75        <div class="wrap"><h2><?php _e( 'Mobile Redirect', 'mobile-redirect' ); ?></h2> 
     76        <p> 
     77            <?php _e( 'If the checkbox is checked, and a valid URL is inputted, this site will redirect to the specified URL when visited by a mobile device.This does not include the iPad, but will include most other mobile devices.', 'mobile-redirect' ); ?> 
     78            <?php _e( 'This does not include the iPad, but will include most other mobile devices.', 'mobile-redirect' ); ?> 
     79        </p> 
     80 
     81        <form method="post"> 
     82        <p> 
     83            <label for="mobiletoggle"><?php _e( 'Enable Redirect:', 'mobile-redirect' ); ?> 
     84            <input type="checkbox" value="1" name="mobiletoggle" id="mobiletoggle" <?php checked( get_option('mobileredirecttoggle', ''), 1 ); ?> /></label> 
     85        </p> 
     86        <p> 
     87            <label for="mobileurl"><?php _e( 'Redirect URL:', 'mobile-redirect' ); ?> 
     88            <input type="text" name="mobileurl" id="mobileurl" value="<?php echo esc_url( get_option('mobileredirecturl', '') ); ?>" /></label> 
     89        </p> 
     90        <p> 
     91            <label for="mobilemode"><?php _e( 'Redirect Mode:', 'mobile-redirect' ); ?> 
     92            <select id="mobilemode" name="mobilemode"> 
     93                <option value="301" <?php selected( get_option('mobileredirectmode', 301 ), 301 ); ?>>301</option> 
     94                <option value="302" <?php selected( get_option('mobileredirectmode'), 302 ); ?>>302</option> 
     95            </select> 
     96            </label> 
     97        </p> 
     98            <?php submit_button(); ?> 
     99        </form> 
     100        </div> 
     101 
     102        <div class="copyFooter">Plugin written by <a href="http://insideout.com">InsideOut Solutions</a>. For more information on our plugins visit <a href="http://insideout.com/the-insideout-advantage/web-hosting/custom-development/">our custom development page</a>.</div> 
     103        <?php 
    84104    } 
    85      
    86     function checkmobile(){ //the magic: checks for mobile, if the toggle is checked, and then sends you to url 
    87         $cur_url = esc_url("http://".$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); 
    88         if(self::is_mobile()){ 
    89             if(get_option('mobileredirecttoggle',false) == "true"){ 
    90                 $mr_url = esc_url(get_option('mobileredirecturl',false)); 
    91                 $mr_mode = get_option('mobileredirectmode',false); 
    92                 if($mr_mode == '') $mr_mode = 301; 
    93                 if($mr_url != '') { 
    94                     if($mr_url != $cur_url){  
    95                         wp_redirect($mr_url, $mr_mode); 
    96                         exit;    
    97                     } 
    98                 } 
    99             } 
     105 
     106    function template_redirect() { 
     107 
     108        // not mobile 
     109        if ( ! wp_is_mobile() ) 
     110            return; 
     111 
     112        // not enabled 
     113        if ( ! get_option('mobileredirecttoggle') ) 
     114            return; 
     115 
     116        $mr_url = esc_url( get_option('mobileredirecturl', '') ); 
     117        // empty url 
     118        if ( empty( $mr_url ) ) 
     119            return; 
     120 
     121        $cur_url = esc_url("http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ); 
     122        // make sure we don't redirect to ourself 
     123        if ( $mr_url != $cur_url ) { 
     124            wp_redirect( $mr_url, get_option('mobileredirectmode', '301' ) ); 
     125            exit; 
    100126        } 
     127 
    101128    } 
    102     // tweeked code from: http://mobiforge.com/developing/story/lightweight-device-detection-php  
    103     function is_mobile() {  
    104         $mobile_browser = '0'; 
    105         if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { 
    106             $mobile_browser++; 
    107         } 
    108         if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) { 
    109             $mobile_browser++; 
    110         }     
    111         $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4)); 
    112         $mobile_agents = array( 
    113             'w3c ','acs-','alav','alca','amoi','audi','avan','andr','benq','bird','blac', 
    114             'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno', 
    115             'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 
    116             'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-', 
    117             'newt','noki','palm','pana','pant','phil','play','port','prox', 
    118             'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar', 
    119             'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 
    120             'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp', 
    121             'wapr','webc','winw','winw','xda','xda-'); 
    122         if(in_array($mobile_ua,$mobile_agents)) { 
    123             $mobile_browser++; 
    124         } 
    125         if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) { 
    126             $mobile_browser++; 
    127         }    
    128         if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'mobile safari')>0) { 
    129             $mobile_browser++; 
    130         } 
    131         if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) { 
    132             $mobile_browser=0; 
    133         } 
    134         if($mobile_browser>0) { return true; } 
    135         else { return false; } 
    136     } 
     129 
    137130} 
  • simple-mobile-url-redirect/trunk/readme.txt

    r535634 r632295  
    1111== Description == 
    1212 
    13 A simple mobile redirect plugin for those who use a seperate website URL for their mobile content.  Simple put in the full path URL and you are ready to send users to your mobile-only content. 
     13A simple mobile redirect plugin for those who use a separate website URL for their mobile content.  Simply put in the full path URL and you are ready to send users to your mobile-only content. 
    1414 
    1515== Installation == 
     
    2020 
    21211. Upload `mobile-redirect.php` to the `/wp-content/plugins/` directory. 
    22 2. Activate the plugin through the 'Plugins' menu in WordPress. 
    23 3. Go to Settings > Mobile Redirect. 
    24 4. Check `Enable Redirect`. 
    25 5. Put in a full path URL (inluding http://) to the website you would like to redirect mobile traffic to. 
    26 6. Select the method of redirect you want.  301 is generally the best option. 
    27 7. Hit `Save` and you are done. 
     221. Activate the plugin through the 'Plugins' menu in WordPress. 
     231. Go to Settings > Mobile Redirect. 
     241. Check `Enable Redirect`. 
     251. Put in a full path URL (inluding http://) to the website you would like to redirect mobile traffic to. 
     261. Select the method of redirect you want.  301 is generally the best option. 
     271. Hit `Save` and you are done. 
    2828 
    2929== Frequently Asked Questions == 
     
    5050= 1.0 = 
    5151No upgrades at this time. 
    52  
    53 Here's a link to [WordPress](http://wordpress.org/ "Your favorite software") and one to [Markdown's Syntax Documentation][markdown syntax]. 
    54 Titles are optional, naturally. 
    55  
    56 [markdown syntax]: http://daringfireball.net/projects/markdown/syntax 
    57             "Markdown is what the parser uses to process much of the readme file" 
    58  
    59 Markdown uses email style notation for blockquotes and I've been told: 
    60 > Asterisks for *emphasis*. Double it up  for **strong**. 
    61  
    62 `<?php code(); // goes in backticks ?>` 
Note: See TracChangeset for help on using the changeset viewer.