Changeset 431960
- Timestamp:
- 09/01/2011 10:35:21 PM (15 years ago)
- Location:
- geographical-redirect/trunk
- Files:
-
- 3 edited
-
geo-redirect-admin.php (modified) (7 diffs)
-
geo-redirect.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
geographical-redirect/trunk/geo-redirect-admin.php
r431665 r431960 13 13 function geo_redirect_admin_description(){ 14 14 $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>'; 17 21 18 22 return $html; … … 52 56 $countries = $geoip->GEOIP_COUNTRY_NAMES; 53 57 if (is_array($countries)) : 54 $html .= '<div class="submit">'; 58 $html .= '<div class="tablenav top">'; 59 $html .= '<div class="alignleft actions">'; 55 60 $html .= '<select class="countries" name="countries[]">'; 56 61 foreach ($countries as $country_id => $country) : … … 61 66 endforeach; 62 67 $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" />'; 65 70 endif; 66 71 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>'; 68 84 $default_shown = false; 69 85 if (is_array($redirect)) { … … 72 88 if ($data['country_id'] == -1) { 73 89 $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>'; 81 107 82 108 } else { 83 109 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 ' <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>'; 92 128 } 93 129 … … 96 132 97 133 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>'; 114 179 115 180 $html .= ' <p class="submit"> … … 148 213 149 214 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 ' <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); 159 239 return false; 160 240 } 161 241 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); 166 247 167 248 return false; … … 177 258 $lang_codes = $_POST['lang_codes']; 178 259 $domains = $_POST['domains']; 260 $urls = $_POST['urls']; 179 261 $only_outsite = intval($_POST['only_outsite']); 180 262 $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)) { 182 264 $redirect = array(); 183 265 foreach ($country_ids as $key => $country_id) { 184 266 185 267 $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]))) ); 188 271 189 272 } -
geographical-redirect/trunk/geo-redirect.php
r431700 r431960 7 7 Author URI: http://profiles.wordpress.org/users/Ladrower/ 8 8 Author e-mail: ladrower@gmail.com 9 Version: 1.09 Version: 2.0 10 10 License: Free 11 11 */ … … 32 32 $this->gi = geoip_open( dirname(__FILE__) . "/geoip/ipdatabase/GeoIP.dat/GeoIP.dat", GEOIP_STANDARD); 33 33 $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; 35 35 $this->referer = $_SERVER['HTTP_REFERER']; 36 36 $this->lang_slug = 'lang'; … … 85 85 $lang_code = $data['lang_code']; 86 86 $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)) { 88 94 if ($this->site_domain != $domain) 89 95 $this->redirectByDomain($domain); … … 102 108 $lang_code = $default_data['lang_code']; 103 109 $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)) { 105 116 if ($this->site_domain != $domain) 106 117 $this->redirectByDomain($domain); … … 115 126 116 127 } 117 private function redirectByLang($lang_code) 128 129 private function redirectByUrl($url) 118 130 { 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); 123 133 } 124 134 } … … 128 138 if ($domain != ''){ 129 139 $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; 130 149 $this->redirectTo($to); 131 150 } … … 151 170 if ($only_outsite == 1) { 152 171 if (empty($this->referer)) 153 return false;172 return true; 154 173 155 174 $outsite = parse_url($this->referer); … … 174 193 $geo->checkIfRedirectNeeded(); 175 194 } 176 do_action('check_client_location'); 195 196 if (!is_admin()) 197 do_action('check_client_location'); 177 198 178 199 ?> -
geographical-redirect/trunk/readme.txt
r431712 r431960 5 5 Requires at least: 3.0 6 6 Tested up to: 3.2.1 7 Stable tag: 1.07 Stable tag: 2.0 8 8 9 9 This plugin allows you to redirect your visitors or switch language according to their country.
Note: See TracChangeset
for help on using the changeset viewer.