예제 #1
0
function getGeoPosty()
{
    global $geoMD5, $geoposty_api_key;
    if (!geoSpiderDetect()) {
        return false;
    }
    $geoPosty = get_transient('geo-' . $geoMD5);
    // only query quova if needed
    if (!is_array($geoPosty)) {
        // should replace the _SERVER variables (or at least do a bunch of checking on them).  also add some better error checking
        $ip = getGeoIpAddress();
        $host = $_SERVER['HTTP_HOST'];
        $server = GEOSERVER . 'domain=' . $host . '&ip=' . $ip . '&domainkey=' . $geoposty_api_key;
        if (GDEBUG) {
            error_log("geoposty:curl:getGeoPosty ip={$ip} server={$server}");
        }
        $data = wp_remote_retrieve_body(wp_remote_get($server));
        $geoPostyXML = @simplexml_load_string($data);
        if (!$geoPostyXML) {
            // check what was returned in $data
            // log that data into a geoposty option
            // report that in admin?
            $geoLogging = get_option('geoLogging');
            if (!is_array($geoLogging)) {
                $geoLogging = array();
            }
            $geoLogCount = count($geoLogging) + 1;
            $geoLogging[$geoLogCount]['time'] = time();
            $geoLogging[$geoLogCount]['message'] = trim($data);
            update_option('geoLogging', $geoLogging);
            return false;
        }
        // convert the simpleXML object to an array
        // can't serialize PHP built-in objects :(
        // fix case
        $geoPosty = array('IPAddress' => (string) $geoPostyXML->{IPAddress}, 'Carrier' => ucwords($geoPostyXML->{Network}->{Carrier}), 'Continent' => ucwords($geoPostyXML->{Location}->{Continent}->{Name}), 'Country' => strtoupper($geoPostyXML->{Location}->{Country}->{Name}), 'Region' => ucwords($geoPostyXML->{Location}->{Region}->{Name}), 'State' => strtoupper($geoPostyXML->{Location}->{State}->{Name}), 'City' => ucwords($geoPostyXML->{Location}->{City}->{Name}), 'PostalCode' => (string) $geoPostyXML->{Location}->{City}->{PostalCode}, 'AreaCode' => (string) $geoPostyXML->{Location}->{City}->{AreaCode}, 'Latitude' => (string) $geoPostyXML->{Location}->{City}->{Coordinates}->{Latitude}, 'Longitude' => (string) $geoPostyXML->{Location}->{City}->{Coordinates}->{Longitude});
        // cache quova info for 24 hours per IP
        set_transient('geo-' . $geoMD5, $geoPosty, 60 * 60 * 24);
        // save out last 100 visitors for fun & profit
        $geoLastHundred = get_option('geoHundred');
        if (!is_array($geoLastHundred)) {
            $geoLastHundred = array();
        }
        @array_unshift($geoLastHundred, $geoPosty);
        unset($geoLastHundred[100]);
        update_option('geoHundred', $geoLastHundred);
    }
    return $geoPosty;
}
예제 #2
0
	Plugin URI: http://geoposty.com/

	Description: Provide users a more geographically rich experience with GeoPosty.  Leveraging IP geo location data from the Quova platform, you can provide users with maps, weather, business, and text not only relevant to your topic, but relevant to your user's location.  Widgets and shortcodes are preloaded to make implementation a snap.
	Version: 0.9.8

	Author: GeoPosty Team
	Author URI: http://geoposty.com/
*/
define('GDEBUG', false);
define('SERVER', 'http://api.geoposty.com/');
define('GEOSERVER', 'http://api.geoposty.com/geo.php?');
require dirname(__FILE__) . '/functions.php';
// need to compress all databae entries into single array
$geoposty_api_key = get_option('geoposty_api_key');
$posty_plugin_url = trailingslashit(get_bloginfo('wpurl')) . PLUGINDIR . '/' . dirname(plugin_basename(__FILE__));
$geoMD5 = md5(getGeoIpAddress());
if (GDEBUG) {
    error_log("geoposty: api_key={$geoposty_api_key}");
}
if (empty($geoposty_api_key)) {
    function geoposty_warning()
    {
        echo "\n\t\t<div id='geoposty-warning' class='updated fade'><p><strong>" . __('GeoPosty needs your attention.') . "</strong> " . sprintf(__('You must <a href="%1$s">enter your API credentials</a> for it to work.'), "plugins.php?page=geoposty-key-config") . "</p></div>\n\t\t\t";
    }
    add_action('admin_notices', 'geoposty_warning');
    if (is_admin()) {
        require dirname(__FILE__) . '/admin.php';
        wp_enqueue_script('geopostyadminjs', $posty_plugin_url . "/js/geoposty-admin.js", array('jquery'));
        wp_enqueue_style('geopostyadmincss', $posty_plugin_url . "/css/geoposty-admin.css");
    }
} else {
예제 #3
0
function geo_ajax_confirm()
{
    global $current_user, $_GET;
    $ip = getGeoIpAddress();
    $host = $_SERVER['HTTP_HOST'];
    if (GDEBUG) {
        error_log("geoposty:admin:geo_ajax_confirm host={$host} ip={$ip}");
    }
    $geoRequestURL = GEOSERVER . 'domain=' . $host . '&ip=' . $ip . '&domainkey=' . $_GET['domainkey'];
    if (GDEBUG) {
        error_log("geoposty:admin:geo_ajax_confirm geoRequestURL={$geoRequestURL}");
    }
    $data = trim(wp_remote_retrieve_body(wp_remote_get($geoRequestURL)));
    $geoPostyXML = @simplexml_load_string($data);
    if (!$geoPostyXML) {
        echo 'There was some type of problem with your request. The API said: <em>' . $data . '</em>';
    }
    die;
}