WordPress.org

Plugin Directory

Changeset 632299


Ignore:
Timestamp:
11/30/12 17:45:25 (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

    r632295 r632299  
    88*/ 
    99 
    10 /*  Copyright 2012  InsideOut Solutions (email : info@insideout.com) 
     10/*  Copyright 2012 InsideOut Solutions (email : info@insideout.com) 
    1111 
    1212    This program is free software; you can redistribute it and/or modify 
     
    1616    This program is distributed in the hope that it will be useful, 
    1717    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    1919    GNU General Public License for more details. 
    2020 
    2121    You should have received a copy of the GNU General Public License 
    2222    along with this program; if not, write to the Free Software 
    23     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA 
     23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
    2424 
    2525*/ 
     
    3131    delete_option( 'mobileredirecturl' ); 
    3232    delete_option( 'mobileredirecttoggle' ); 
    33     delete_option('mobileredirectmode'); 
     33    delete_option( 'mobileredirectmode' ); 
    3434} 
    3535 
     
    6666            update_option( 'mobileredirecttoggle', isset( $_POST['mobiletoggle'] ) ? true : false ); 
    6767 
    68             if ( $_POST['mobilemode'] ) 
    69                 update_option( 'mobileredirectmode', intval( $_POST['mobilemode'] ) ); 
     68            update_option( 'mobileredirectmode', intval( $_POST['mobilemode'] ) ); 
     69 
     70            update_option( 'mobileredirectonce', isset( $_POST['mobileredirectonce'] ) ? true : false ); 
     71            update_option( 'mobileredirectoncedays', intval( $_POST['mobileredirectoncedays'] ) ); 
    7072 
    7173            echo '<div class="updated"><p>' . __( 'Updated', 'mobile-redirect' ) . '</p></div>'; 
     
    9698            </label> 
    9799        </p> 
     100        <p> 
     101            <label for="mobileredirectonce"><?php _e( 'Redirect Once:', 'mobile-redirect' ); ?> 
     102            <input type="checkbox" value="1" name="mobileredirectonce" id="mobileredirectonce" <?php checked( get_option('mobileredirectonce', ''), 1 ); ?> /></label> 
     103        </p> 
     104        <p> 
     105            <label for="mobileredirectoncedays"><?php _e( 'Redirect Once Cookie Expiry:', 'mobile-redirect' ); ?> 
     106            <input type="text" name="mobileredirectoncedays" id="mobileredirectoncedays" value="<?php echo esc_attr( get_option('mobileredirectoncedays', 7 ) ); ?>" /> days.</label> 
     107            <span class="description">If <em>Redirect Once</em> is checked, a cookie will be set for the user to prevent them from being continually redirected to the same page. This cookie will expire by default after 7 days. Setting to zero or less is effectively the same as unchecking Redirect Once</span> 
     108        </p> 
    98109            <?php submit_button(); ?> 
    99110        </form> 
     
    120131 
    121132        $cur_url = esc_url("http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ); 
     133        $cookiedays = intval( get_option( 'mobileredirectoncedays', 7 ) ); 
     134        // cookie can be expired by setting to a negative number 
     135        // but it's better just to uncheck the redirect once option 
     136        if ( $cookiedays <= 0 || ! get_option( 'mobileredirectonce' ) ) { 
     137            setcookie( 'mobile_single_redirect', true, time()-(60*60), '/' ); 
     138            unset($_COOKIE['mobile_single_redirect']); 
     139        } 
     140 
    122141        // make sure we don't redirect to ourself 
    123142        if ( $mr_url != $cur_url ) { 
     143            if ( isset( $_COOKIE['mobile_single_redirect'] ) ) return; 
     144 
     145            if ( get_option( 'mobileredirectonce', '' ) ) 
     146                setcookie( 'mobile_single_redirect', true, time()+(60*60*24*$cookiedays ), '/' ); 
     147 
    124148            wp_redirect( $mr_url, get_option('mobileredirectmode', '301' ) ); 
    125149            exit; 
     
    129153 
    130154} 
     155// eof 
  • simple-mobile-url-redirect/trunk/readme.txt

    r632295 r632299  
    4040== Changelog == 
    4141 
     42= 1.2 = 
     43* Code clean up 
     44* Use core's mobile detection 
     45* New option to redirect only once. 
     46 
    4247= 1.1 = 
    4348* Fixed bug with missing functon is_mobile() 
Note: See TracChangeset for help on using the changeset viewer.