Plugin Directory

Changeset 615816


Ignore:
Timestamp:
10/22/2012 10:18:34 PM (13 years ago)
Author:
mikelynn
Message:

checking in version 1.0.5 - multiple location support for conditional shortcodes

Location:
wpgeocode/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wpgeocode/trunk/readme.txt

    r606470 r615816  
    44Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GDQD948MQ3G3G
    55Tags: geocode, geocode filter, geotag, geomarketing, geomarking, geolocation, geofilter, location, local marketing, keywords
    6 Version: 1.0.4
     6Version: 1.0.5
    77Requires at least: 3.0
    88Tested up to: 3.0.1
     
    3333* [wpgc_is_city_and_state city="Yardley" state_code="PA"]
    3434* [wpgc_is_ip" ip="xx.xx.xx.xx"]
     35* [wpgc_is_ips" ip="xx.xx.xx.xx,aa.bb.cc.dd"]
    3536* [wpgc_is_not_ip" ip="xx.xx.xx.xx"]
     37* [wpgc_is_not_ips" ip="xx.xx.xx.xx,aa.bb.cc.dd"]
    3638* [wpgc_is_city" city=""]
     39* [wpgc_is_cities" cities="city one,city two,city three"]
    3740* [wpgc_is_not_city" city=""]
     41* [wpgc_is_not_cities" cities="city one,city two,city three"]
    3842* [wpgc_is_nearby"] - Uses the value you specify in the Nearby Range setting from the administrative panel
    3943* [wpgc_is_not_nearby"]
     
    4145* [wpgc_is_within kilometers="12"]
    4246* [wpgc_is_country_name" country_name=""]
     47* [wpgc_is_country_names" country_name="United States,Egypt,Albania"]
    4348* [wpgc_is_country_code" country_code=""]
     49* [wpgc_is_country_codes" country_codes="US,GB,AZ"]
    4450* [wpgc_is_state_code" state_code=""]
     51* [wpgc_is_state_codes" state_codes="PA,NJ,TX"]
    4552* [wpgc_is_not_country_name" country_name=""]
     53* [wpgc_is_not_country_names" country_names="United States,Egypt,Albania"]
    4654* [wpgc_is_not_country_code" country_code=""]
     55* [wpgc_is_not_country_codes" country_codes="US,GB,AZ"]
    4756* [wpgc_is_not_state_code" state_code=""]
     57* [wpgc_is_not_state_codes" state_codes="PA,NJ,TX"]
    4858
    4959**Examples**
     
    5363    [wpgc_is_ip ip=123.123.123.123] I used to own this IP Address [/wpgc_is_ip] - Will display the message only if the user has that specific IP Address.
    5464    [wpgc_is_city city="Yardley"] Hello Fellow Yardlian [/wpgc_is_city] - Will display the message only if the user has that specific IP Address.
     65    [wpgc_is_not_cities cities="Yardley,Morrisville"] Glad you don't live in Yardley or Morrisville? [/wpgc_is_not_cities] - Will display only when visitor is not viewing the page from Yardley or Morrisville
    5566
    5667Configurable options allow you to set a default phrase for each available shortcode in the event that the user was unable to be geo-located.
     
    75862. screenshot-2.png is the plugin in action.
    7687
     88== Change Log ==
    7789
    78 == Change Log ==
     90= 1.0.5 =
     91* Add support for multiple locations (i.e. cities, states, etc.) in conditional shortcodes eg: [wpgc_is_cities cities="one,two,three"]
    7992
    8093= 1.0.4 =
     
    108121= 1.0.4 =
    109122* Fix Readme
     123
     124= 1.0.5 =
     125* Multiple location conditional shortcodes
  • wpgeocode/trunk/wpgeocode.php

    r606456 r615816  
    55Tags: geocode, geotagging, geolocation, geotags, latitude, longitude, city, state, geomarketing, geolocation marketing
    66Description: Use WPGeocode to customize the content of your blog based on the location of your readers.
    7 Version: 1.0.4
     7Version: 1.0.5
    88Author: Michael Lynn
    99Author URI: http://www.mlynn.org/
     
    3232}
    3333$log = new logfile();
    34 $log->write("test");
     34// $log->write("test");
    3535
    3636function wpgc_shortcode_env($atts, $content="") {
     
    7474    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_ip'));
    7575}
     76function wpgc_is_not_ips($atts, $content="") {
     77    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_ips'));
     78}
    7679function wpgc_is_not_country_code($atts, $content="") {
    7780    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_country_code'));
    7881}
     82function wpgc_is_not_country_codes($atts, $content="") {
     83    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_country_codes'));
     84}
    7985function wpgc_is_not_country_name($atts, $content="") {
    8086    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_country_name'));
    8187}
     88function wpgc_is_not_country_names($atts, $content="") {
     89    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_country_names'));
     90}
     91function wpgc_is_not_state_codes($atts, $content="") {
     92    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_state_codes'));
     93}
    8294function wpgc_is_not_state_code($atts, $content="") {
    8395    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_state_code'));
     
    8698    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_city'));
    8799}
     100function wpgc_is_not_cities($atts, $content="") {
     101    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_cities'));
     102}
    88103function wpgc_is_not_city_and_state($atts, $content="") {
    89104    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_not_city_and_state'));
     
    92107    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_ip'));
    93108}
     109function wpgc_is_ips($atts, $content="") {
     110    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_ips'));
     111}
    94112function wpgc_is_country_code($atts, $content="") {
    95113    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_country_code'));
    96114}
     115function wpgc_is_country_codes($atts, $content="") {
     116    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_country_codes'));
     117}
    97118function wpgc_is_country_name($atts, $content="") {
    98119    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_country_name'));
    99120}
     121function wpgc_is_country_names($atts, $content="") {
     122    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_country_names'));
     123}
     124function wpgc_is_state_codes($atts, $content="") {
     125    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_state_codes'));
     126}
    100127function wpgc_is_state_code($atts, $content="") {
    101128    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_state_code'));
     
    104131    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_city'));
    105132}
     133function wpgc_is_cities($atts, $content="") {
     134    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_cities'));
     135}
    106136function wpgc_is_city_and_state_code($atts, $content="") {
    107137    return do_shortcode(wpgc_conditional_shortcode($atts, $content, 'is_city_and_state_code'));
     
    120150}
    121151function wpgc_conditional_shortcode($atts, $content, $condition) {
    122         $options = get_option('wpgc_options');
     152    $options = get_option('wpgc_options');
    123153    extract(shortcode_atts(array(
    124154                'longitude' => '',
    125155                'latitude' => '',
    126156                'ip' => '',
     157                'ips' => '',
    127158                'country_name' => '',
     159                'country_names' => '',
    128160                'country_code' => '',
     161                'country_codes' => '',
    129162                'state_code' => '',
     163                'state_codes' => '',
     164                'cities' => '',
    130165                'city' => '',
    131166                'miles' => '',
    132         'kilometers' => ''
     167            'kilometers' => ''
    133168        ), $atts));
    134169        $user_ip = wpgc_get_ip_address();
     
    151186    switch( $condition ) {
    152187        case 'env':
    153             return $_ENV;
     188            return implode('<br>',$_ENV);
    154189            break;
    155190        case 'database_date' :
     
    199234            return $user_distance_kilometers;
    200235            break;
    201                 case 'is_not_nearby':
    202                         if (!$options['txt_home_latitude'] && !$options['txt_home_longitude'] && !$latitude && !$longitude) {
    203                                 return; // don't return content if we haven't specified our home base
    204                         }
     236        case 'is_not_nearby':
     237            if (!$options['txt_home_latitude'] && !$options['txt_home_longitude'] && !$latitude && !$longitude) {
     238                    return; // don't return content if we haven't specified our home base
     239            }
    205240            if ($latitude && longitude) {
    206241                $compare_lat=$latitude;
     
    227262                }
    228263            }
    229                         break;
    230                 case 'is_nearby':
     264            break;
     265        case 'is_nearby':
    231266// will assume home lat and lon if no lat and lon are specified in the shortcode atts
    232                         if (!$options['txt_home_latitude'] && !$options['txt_home_longitude'] && !$latitude && !$longitude) {
    233                                 return; // don't return content if we haven't specified our home base
    234                         }
     267            if (!$options['txt_home_latitude'] && !$options['txt_home_longitude'] && !$latitude && !$longitude) {
     268                    return; // don't return content if we haven't specified our home base
     269            }
    235270            if ($latitude && longitude) {
    236271                $compare_lat=$latitude;
     
    257292                }
    258293            }
    259                         break;
     294            break;
    260295        case 'is_within':
    261296            if (!$options['txt_home_latitude'] && !$options['txt_home_longitude']) {
     
    279314            }
    280315            break;
     316        case 'is_not_cities':
     317            $is_not_city=wpgc_csv_find($cities,$loc_arr['city_name']);
     318            if ($is_not_city==false) {
     319                return $content;
     320            }
     321            break;
    281322        case 'is_not_city':
    282             if ($city!=$loc_arr['city_name']) {
     323            $is_not_city=wpgc_csv_find($city,$loc_arr['city_name']);
     324            if ($is_not_city==false) {
    283325                return $content;
    284326            }
     
    289331            }
    290332            break;
     333        case 'is_not_state_codes':
     334            $found=wpgc_csv_find($states,$loc_arr['state_code']);
     335            if ($found==false) {
     336                return $content;
     337            }
     338            break;
    291339        case 'is_not_country_name':
    292340            if ($country_name!=$loc_arr['country_name']) {
     
    294342            }
    295343            break;
     344        case 'is_not_country_names':
     345            $found=wpgc_csv_find($country_names,$loc_arr['country_name']);
     346            if ($found==false) {
     347                return $content;
     348            }
     349            break;
    296350        case 'is_not_country_code':
    297351            if ($country_code!=$loc_arr['country_code']) {
     
    299353            }
    300354            break;
     355        case 'is_not_country_codes':
     356            $found=wpgc_csv_find($country_codes,$loc_arr['country_codes']);
     357            if ($found==false) {
     358                return $content;
     359            }
     360            break;
    301361        case 'is_city_and_state_code':
    302362            if ($city==$loc_arr['city_name'] && $state_code!=$loc_arr['state_code']) {
     
    309369            }
    310370            break;
     371        case 'is_cities':
     372            $found=wpgc_csv_find($cities,$loc_arr['city_name']);
     373            if ($found) {
     374                return $content;
     375            }
     376            break;
    311377        case 'is_state_code':
    312378            if ($state_code==$loc_arr['state_code']) {
     
    314380            }
    315381            break;
     382        case 'is_state_code':
     383            $found=wpgc_csv_find($state_codes,$loc_arr['state_code']);
     384            if ($state_code==$loc_arr['state_code']) {
     385                return $content;
     386            }
     387            break;
    316388        case 'is_country_name':
    317389            if ($country_name==$loc_arr['country_name']) {
     
    319391            }
    320392            break;
     393        case 'is_country_names':
     394            $found=wpgc_csv_find($country_names,$loc_arr['country_name']);
     395            if ($found) {
     396                return $content;
     397            }
     398            break;
    321399        case 'is_country_code':
    322400            if ($country_code==$loc_arr['country_code']) {
     
    324402            }
    325403            break;
     404        case 'is_country_code':
     405            $found=wpgc_csv_find($country_codes,$loc_arr['country_code']);
     406            if ($found) {
     407                return $content;
     408            }
     409            break;
    326410        case 'is_ip':
    327                         if ($ip==$user_ip) {
    328                                 return $content;
    329                         }
    330                         break;
     411            if ($ip==$user_ip) {
     412                    return $content;
     413            }
     414            break;
     415        case 'is_ips':
     416            $found=wpgc_csv_find($ips,$user_ip);
     417            if ($found) {
     418                return $content;
     419            }
     420            break;
    331421        case 'is_not_ip':
    332                         if ($ip!=$user_ip) {
    333                                 return $content;
    334                         }
    335                         break;
    336 
     422            if ($ip!=$user_ip) {
     423                    return $content;
     424            }
     425            break;
     426        case 'is_not_ip':
     427            $found=wpgc_csv_find($ips,$user_ip);
     428            if ($found==false) {
     429                    return $content;
     430            }
     431            break;
    337432        default:
    338433    }
     
    353448add_shortcode("wpgc_is_city_and_state_code", "wpgc_is_city_and_state_code");
    354449add_shortcode("wpgc_is_ip", "wpgc_is_ip");
     450add_shortcode("wpgc_is_ips", "wpgc_is_ips");
    355451add_shortcode("wpgc_is_not_ip", "wpgc_is_not_ip");
     452add_shortcode("wpgc_is_not_ips", "wpgc_is_not_ips");
    356453add_shortcode("wpgc_is_city", "wpgc_is_city");
     454add_shortcode("wpgc_is_cities", "wpgc_is_cities");
     455add_shortcode("wpgc_is_not_cities", "wpgc_is_not_cities");
    357456add_shortcode("wpgc_is_not_city", "wpgc_is_not_city");
    358457add_shortcode("wpgc_is_nearby", "wpgc_is_nearby");
     
    360459add_shortcode("wpgc_is_within", "wpgc_is_within");
    361460add_shortcode("wpgc_is_country_name", "wpgc_is_country_name");
     461add_shortcode("wpgc_is_country_names", "wpgc_is_country_names");
    362462add_shortcode("wpgc_is_country_code", "wpgc_is_country_code");
     463add_shortcode("wpgc_is_country_codes", "wpgc_is_country_codes");
    363464add_shortcode("wpgc_is_state_code", "wpgc_is_state_code");
     465add_shortcode("wpgc_is_state_codes", "wpgc_is_state_codes");
    364466add_shortcode("wpgc_is_not_country_name", "wpgc_is_not_country_name");
     467add_shortcode("wpgc_is_not_country_names", "wpgc_is_not_country_names");
    365468add_shortcode("wpgc_is_not_country_code", "wpgc_is_not_country_code");
     469add_shortcode("wpgc_is_not_country_codes", "wpgc_is_not_country_codes");
    366470add_shortcode("wpgc_is_not_state_code", "wpgc_is_not_state_code");
     471add_shortcode("wpgc_is_not_state_codes", "wpgc_is_not_state_codes");
    367472
    368473// delete options table entries ONLY when plugin deactivated AND deleted
     
    458563<li> [wpgc_is_city_and_state city="Yardley" state_code="PA"]
    459564<li> [wpgc_is_ip ip="xx.xx.xx.xx"]
     565<li> [wpgc_is_ips ips="xx.xx.xx.xx,aa.bb.cc.dd"]
    460566<li> [wpgc_is_not_ip ip="xx.xx.xx.xx"]
    461567<li> [wpgc_is_city city=""]
     568<li> [wpgc_is_not_cities" city="cityone,citytwo,citythree"]
    462569<li> [wpgc_is_not_city" city=""]
    463570<li> [wpgc_is_nearby"] - Uses the value you specify in the Nearby Range setting from the administrative panel
     
    492599                          <label for="chk_enable_plugin">Enable WP Geocode Plugin</label>
    493600
     601                    </td>
     602                </tr>
     603                <tr>
     604                    <th scope="row">Your Google Maps API Key</th>
     605                    <td>
     606                        <label><input size=40 name="wpgc_options[txt_gmaps_key]" value="<?php echo $options['txt_gmaps_key'];?>">
     607                        <span style="color:#666666;margin-left:2px;">This is used when displaying Google Maps.  See <a href=https://developers.google.com/maps/signup>https://developers.google.com/maps/signup</a> for more information.</span>
    494608                    </td>
    495609                </tr>
     
    713827
    714828function wpgc_validate_options($input) {
     829    $input['txt_gmap_key'] =  wp_filter_nohtml_kses($input['txt_gmap_key']);
    715830    $input['txt_def_city'] =  wp_filter_nohtml_kses($input['txt_def_city']);
    716831    $input['txt_def_state_code'] = wp_filter_nohtml_kses($input['txt_def_state_code']);
     
    841956    return ($miles ? ($km * 0.621371192) : $km);
    842957}//end function distance
     958
     959function wpgc_csv_find($string1,$string2) {
     960// string1 is a csv list eg: one,two,three
     961// string2 is a static value
     962
     963    $strarr = explode(',',$string1);
     964    foreach($strarr as $ii) {
     965        if(trim(strtolower($ii)) == trim(strtolower($string2))) {
     966            return true;
     967        }
     968    }
     969    return false;
     970} // end function wpgc_find_string_in_array
Note: See TracChangeset for help on using the changeset viewer.