Plugin Directory

Changeset 431960


Ignore:
Timestamp:
09/01/2011 10:35:21 PM (15 years ago)
Author:
Ladrower
Message:

New stable release

Location:
geographical-redirect/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • geographical-redirect/trunk/geo-redirect-admin.php

    r431665 r431960  
    1313function geo_redirect_admin_description(){
    1414    $html = '<p>This plugin allows you to redirect your visitors according to their country.</p>
    15              <p>Just add the country from selectbox and fill in preferable options. Domain redirect has higher priority if specified. <br />
    16              If you have some troubles accessing your site, because of incorrect redirect, just add to browser\'s url «no_redirect» (example: '.get_bloginfo('url').'/?page_id=5&<b>no_redirect</b>) to ignore redirection.</p>';
     15             <p>Just add the country from selectbox and fill in preferable options.</p>
     16             <p>Static URL redirect has the highest priority if not blank.<br />
     17             Domain redirect has lower priority if not blank.<br />
     18             Redirect by language has the lowest priority among the options.</p>
     19             <p>If you have some troubles accessing your site because of incorrect redirect,
     20             just add to browser\'s url «no_redirect» (example: '.get_bloginfo('url').'/?page_id=5&<b>no_redirect</b>) to ignore redirection.</p>';
    1721   
    1822    return $html;   
     
    5256    $countries = $geoip->GEOIP_COUNTRY_NAMES;
    5357    if (is_array($countries)) :
    54         $html .= '<div class="submit">';
     58        $html .= '<div class="tablenav top">';
     59        $html .= '<div class="alignleft actions">';
    5560        $html .= '<select class="countries" name="countries[]">';
    5661            foreach ($countries as $country_id => $country) :
     
    6166            endforeach;
    6267        $html .= '</select>';
    63         $html .= '<input onclick="return geoAddCountry();" type="submit" value="Add country" /></div>';
    64         $html .= '<br clear="all" />';
     68        $html .= '<input onclick="return geoAddCountry();" type="submit" class="button-secondary action" value="Add country" />';
     69        $html .= '</div></div><br clear="all" />';
    6570    endif;
    6671   
    67     $html .= '<div class="geo-redirect-options">';
     72    $html .= '<div class="geo-redirect-options">
     73    <table class="wp-list-table widefat plugins" cellspacing="0">
     74        <thead>
     75            <tr>
     76                <th scope="col" id="name" class="manage-column column-name" style="">Country</th>
     77                <th scope="col" id="name" class="manage-column column-name" style="">Language Code</th>
     78                <th scope="col" id="name" class="manage-column column-name" style="">Domain Name</th>
     79                <th scope="col" id="name" class="manage-column column-name" style="">Static URL</th>
     80                <th scope="col" id="name" class="manage-column column-name" style=""></th>
     81            </tr>
     82        </thead>
     83        <tbody>';
    6884    $default_shown = false;
    6985    if (is_array($redirect)) {
     
    7288            if ($data['country_id'] == -1) {
    7389                $default_shown = true;
    74                 $html .='<p class="geo-redirect-option">'.
    75                         '<input type="hidden" name="country_ids[]" value="-1">'.
    76                         '<b>Options for countries that not assigned</b><br />'.
    77                         '<label>Language code:<input id="geo-redirect-country--1" class="small-text" name="lang_codes[]" type="text" maxlength="2" value="'.stripslashes($data['lang_code']).'"></label>'.
    78                         '<label> or </label>'.
    79                         '<label>Domain name:<input class="regular-text" name="domains[]" type="text" value="'.stripslashes($data['domain']).'"></label>'.
    80                         '</p>';
     90                $html .='<tr class="geo-redirect-option active">'.
     91                            '<td>'.
     92                                '<input type="hidden" name="country_ids[]" value="-1">'.
     93                                '<p><b>Not assigned countries</b></p>'.
     94                            '</td>'.
     95                            '<td>'.
     96                                '<p><input id="geo-redirect-country--1" class="small-text" name="lang_codes[]" type="text" maxlength="2" value="'.stripslashes($data['lang_code']).'"></p>'.
     97                            '</td>'.
     98                            '<td>'.
     99                                '<p><input class="regular-text" name="domains[]" type="text" value="'.stripslashes($data['domain']).'"></p>'.
     100                            '</td>'.
     101                            '<td>'.
     102                                '<p><input class="regular-text" name="urls[]" type="text" value="'.stripslashes($data['url']).'"></p>'.
     103                            '</td>'.
     104                            '<td>'.
     105                            '</td>'.
     106                        '</tr>';
    81107                       
    82108            } else {
    83109           
    84                 $html .='<p class="geo-redirect-option">'.
    85                         '<input type="hidden" name="country_ids[]" value="'.$data['country_id'].'">'.
    86                         '<b>'.$countries[$data['country_id']].'</b><br />'.
    87                         '<label>Language code:<input id="geo-redirect-country-'.$data['country_id'].'" class="small-text" name="lang_codes[]" type="text" maxlength="2" value="'.stripslashes($data['lang_code']).'"></label>'.
    88                         '<label> or </label>'.
    89                         '<label>Domain name:<input class="regular-text" name="domains[]" type="text" value="'.stripslashes($data['domain']).'"></label>'.
    90                         '&nbsp;<a onclick="return geoRemoveCountry(this);" href="#" class="delete">Remove</a>'.
    91                         '</p>';
     110                $html .='<tr class="geo-redirect-option active">'.
     111                            '<td>'.
     112                                '<input type="hidden" name="country_ids[]" value="'.$data['country_id'].'">'.
     113                                '<p><b>'.$countries[$data['country_id']].'</b></p>'.
     114                            '</td>'.
     115                            '<td>'.
     116                                '<p><input id="geo-redirect-country-'.$data['country_id'].'" class="small-text" name="lang_codes[]" type="text" maxlength="2" value="'.stripslashes($data['lang_code']).'"></p>'.
     117                            '</td>'.
     118                            '<td>'.
     119                                '<p><input class="regular-text" name="domains[]" type="text" value="'.stripslashes($data['domain']).'"></p>'.
     120                            '</td>'.
     121                            '<td>'.
     122                                '<p><input class="regular-text" name="urls[]" type="text" value="'.stripslashes($data['url']).'"></p>'.
     123                            '</td>'.
     124                            '<td>'.
     125                                '<p style="line-height:2.3"><a onclick="return geoRemoveCountry(this);" href="#" class="delete">Remove</a></p>'.
     126                            '</td>'.
     127                        '</tr>';   
    92128            }
    93129           
     
    96132   
    97133    if (!$default_shown) {
    98         $html .='<p class="geo-redirect-option">'.
    99                 '<input type="hidden" name="country_ids[]" value="-1">'.
    100                 '<b>Options for countries that not assigned</b><br />'.
    101                 '<label>Language code:<input id="geo-redirect-country--1" class="small-text" name="lang_codes[]" type="text" maxlength="2"></label>'.
    102                 '<label> or </label>'.
    103                 '<label>Domain name:<input class="regular-text" name="domains[]" type="text"></label>'.
    104                 '</p>';
    105     }
    106            
    107     $html .= '</div>';
    108    
    109     $html .= '<p><label>Language URL variable:<input class="small-text" name="lang_slug" value="'.$lang_slug.'" type="text"></label>'.
    110              '<br />(example: '.get_bloginfo('url').'/?page_id=10&<b>lang</b>=en)</p>';
    111    
    112     $checked = ($only_outsite == 1) ? 'checked="checked"' : '';
    113     $html .= '<label><input type="checkbox" name="only_outsite" value="1" '.$checked.'> Redirect only visitors who came from another site by link or which have clean reference data</label>';
     134        $html .='<tr class="geo-redirect-option active">'.
     135                    '<td>'.
     136                        '<input type="hidden" name="country_ids[]" value="-1">'.
     137                        '<b>Not assigned countries</b></p>'.
     138                    '</td>'.
     139                    '<td>'.
     140                        '<p><input id="geo-redirect-country--1" class="small-text" name="lang_codes[]" type="text" maxlength="2"></p>'.
     141                    '</td>'.
     142                    '<td>'.
     143                        '<p><input class="regular-text" name="domains[]" type="text"></p>'.
     144                    '</td>'.
     145                    '<td>'.
     146                        '<p><input class="regular-text" name="urls[]" type="text"></p>'.
     147                    '</td>'.
     148                    '<td>'.
     149                    '</td>'.
     150                '</tr>';
     151    }
     152           
     153    $html .= '</tbody>
     154        </table>
     155    </div>';
     156   
     157    $html .= '<br clear="all" />';
     158   
     159    $html .= '<table class="wp-list-table widefat plugins" cellspacing="0">
     160                <thead>
     161                    <tr>
     162                        <th scope="col" id="name" class="manage-column column-name" style="">Language URL variable</th>
     163                    </tr>
     164                </thead>
     165                <tbody>
     166                    <tr>
     167                        <td>
     168                            <p><input class="small-text" name="lang_slug" value="'.$lang_slug.'" type="text">'.
     169                            ' (example: '.get_bloginfo('url').'/?page_id=10&<b>lang</b>=en)</p>
     170                        </td>
     171                    </tr>
     172                </tbody>
     173            </table>';
     174   
     175    $html .= '<br clear="all" />';
     176   
     177    $checked = ($only_outsite == 1)?'checked="checked"':'';
     178    $html .= '<label><input type="checkbox" name="only_outsite" value="1" '.$checked.'> Redirect only visitors who came from another site by link</label>';
    114179   
    115180    $html .= '  <p class="submit">
     
    148213           
    149214        var country_name = j('select.countries option:selected').text();
    150         var option_html =   '<p class="geo-redirect-option">'+
    151                             '<input type="hidden" name="country_ids[]" value="'+country_id+'">'+
    152                             '<b>'+country_name+'</b><br />'+
    153                             '<label>Language code:<input id="geo-redirect-country-'+country_id+'" class="small-text" name="lang_codes[]" type="text" maxlength="2"></label>'+
    154                             '<label> or </label>'+
    155                             '<label>Domain name:<input class="regular-text" name="domains[]" type="text"></label>'+
    156                             '&nbsp;<a onclick="return geoRemoveCountry(this);" href="#" class="delete">Remove</a>'+
    157                             '</p>';
    158         j('.geo-redirect-options').append(option_html);
     215        var option_html =   '<tr class="geo-redirect-option inactive">'+
     216                                '<td>'+
     217                                    '<input type="hidden" name="country_ids[]" value="'+country_id+'">'+
     218                                    '<p><b>'+country_name+'</b></p>'+
     219                                '</td>'+
     220                                '<td>'+
     221                                    '<p><input id="geo-redirect-country-'+country_id+'" class="small-text" name="lang_codes[]" type="text" maxlength="2"></p>'+
     222                                '</td>'+
     223                                '<td>'+
     224                                    '<p><input class="regular-text" name="domains[]" type="text"></p>'+
     225                                '</td>'+
     226                                '<td>'+
     227                                    '<p><input class="regular-text" name="urls[]" type="text"></p>'+
     228                                '</td>'+
     229                                '<td>'+
     230                                    '<p style="line-height:2.3"><a onclick="return geoRemoveCountry(this);" href="#" class="delete">Remove</a></p>'+
     231                                '</td>'+
     232                            '</tr>';
     233        j('.geo-redirect-options table tbody').prepend(option_html);
     234        setTimeout(function() {
     235            var first = j('.geo-redirect-option').first();
     236            first.addClass('active');
     237            first.removeClass('inactive');
     238        },500);
    159239        return false;
    160240    }
    161241   
    162     function geoRemoveCountry(option){         
    163         j(option).parent('.geo-redirect-option').slideUp('fast', function(){
    164             j(option).parent('.geo-redirect-option').remove();
    165         });
     242    function geoRemoveCountry(option){     
     243        j(option).parents('.geo-redirect-option').addClass('inactive');
     244        setTimeout(function() {
     245            j(option).parents('.geo-redirect-option').remove();
     246        },500);
    166247       
    167248        return false;
     
    177258    $lang_codes     = $_POST['lang_codes'];
    178259    $domains        = $_POST['domains'];
     260    $urls           = $_POST['urls'];
    179261    $only_outsite   = intval($_POST['only_outsite']);
    180262    $lang_slug      = (trim($_POST['lang_slug']) != '') ? (string)urlencode(strtolower(trim($_POST['lang_slug']))) : 'lang';
    181     if (is_array($country_ids) && is_array($lang_codes) && is_array($domains)) {
     263    if (is_array($country_ids)) {
    182264        $redirect = array();
    183265        foreach ($country_ids as $key => $country_id) {
    184266           
    185267            $redirect[] = array('country_id'    => intval($country_id),
    186                                 'lang_code'     => (string)strtolower(trim($lang_codes[$key])),
    187                                 'domain'        => (string)strtolower(trim(str_ireplace('http://','',$domains[$key]))) );   
     268                                'lang_code'     => (string)htmlspecialchars(strtolower(trim(strip_tags($lang_codes[$key])))),
     269                                'domain'        => (string)htmlspecialchars(strtolower(trim(str_ireplace('http://','',strip_tags($domains[$key]))))),
     270                                'url'           => (string)htmlspecialchars(trim(strip_tags($urls[$key]))) );   
    188271           
    189272        }
  • geographical-redirect/trunk/geo-redirect.php

    r431700 r431960  
    77Author URI: http://profiles.wordpress.org/users/Ladrower/
    88Author e-mail: ladrower@gmail.com
    9 Version: 1.0
     9Version: 2.0
    1010License: Free
    1111*/
     
    3232        $this->gi = geoip_open( dirname(__FILE__) . "/geoip/ipdatabase/GeoIP.dat/GeoIP.dat", GEOIP_STANDARD);
    3333        $this->site_domain = $_SERVER['SERVER_NAME'];
    34         $this->no_redirect = (isset($_GET['no_redirect']) || is_admin()) ? true : false;
     34        $this->no_redirect = (isset($_GET['no_redirect']) || (isset($_POST['pwd']) && isset($_POST['log']))) ? true : false;
    3535        $this->referer = $_SERVER['HTTP_REFERER'];
    3636        $this->lang_slug = 'lang';
     
    8585                    $lang_code = $data['lang_code'];
    8686                    $domain = $data['domain'];
    87                     if (!empty($domain)) {
     87                    $url = $data['url'];
     88                    if (!empty($url)) {
     89                        $current_url = 'http://' . $this->site_domain . $_SERVER['REQUEST_URI'];
     90                        if ($current_url != $url)
     91                            $this->redirectByUrl($url);
     92                       
     93                    } elseif (!empty($domain)) {
    8894                        if ($this->site_domain != $domain)
    8995                            $this->redirectByDomain($domain);
     
    102108                $lang_code = $default_data['lang_code'];
    103109                $domain = $default_data['domain'];
    104                 if (!empty($domain)) {
     110                $url = $default_data['url'];
     111                if (!empty($url)) {
     112                    if ('http://' . $this->site_domain . $_SERVER['REQUEST_URI'] != $url)
     113                        $this->redirectByUrl($url);
     114                       
     115                } elseif (!empty($domain)) {
    105116                    if ($this->site_domain != $domain)
    106117                        $this->redirectByDomain($domain);
     
    115126   
    116127    }
    117     private function redirectByLang($lang_code)
     128   
     129    private function redirectByUrl($url)
    118130    {
    119         if ($lang_code != ''){
    120             $lang_url = (strpos($_SERVER['REQUEST_URI'],'?') === false) ? '?' : '&';
    121             $to = get_bloginfo('url') . $_SERVER['REQUEST_URI'] . $lang_url . $this->lang_slug . '=' . $lang_code;
    122             $this->redirectTo($to);
     131        if ($url != ''){
     132            $this->redirectTo($url);
    123133        }
    124134    }
     
    128138        if ($domain != ''){
    129139            $to = 'http://' . $domain . $_SERVER['REQUEST_URI'];
     140            $this->redirectTo($to);
     141        }
     142    }
     143   
     144    private function redirectByLang($lang_code)
     145    {
     146        if ($lang_code != ''){
     147            $lang_url = (strpos($_SERVER['REQUEST_URI'],'?') === false) ? '?' : '&';
     148            $to = get_bloginfo('url') . $_SERVER['REQUEST_URI'] . $lang_url . $this->lang_slug . '=' . $lang_code;
    130149            $this->redirectTo($to);
    131150        }
     
    151170        if ($only_outsite == 1) {
    152171            if (empty($this->referer))
    153                 return false;
     172                return true;
    154173               
    155174            $outsite = parse_url($this->referer);
     
    174193    $geo->checkIfRedirectNeeded();
    175194}
    176 do_action('check_client_location');
     195
     196if (!is_admin())
     197    do_action('check_client_location');
    177198
    178199?>
  • geographical-redirect/trunk/readme.txt

    r431712 r431960  
    55Requires at least: 3.0
    66Tested up to: 3.2.1
    7 Stable tag: 1.0
     7Stable tag: 2.0
    88
    99This plugin allows you to redirect your visitors or switch language according to their country.
Note: See TracChangeset for help on using the changeset viewer.