コード例 #1
1
function runGeoLookup()
{
    global $GEOIP_REGION_NAME;
    $geoip = Net_GeoIP::getInstance(BT_ROOT . "/bt-config/GeoLiteCity.dat");
    $location = null;
    try {
        $location = $geoip->lookupLocation($_SERVER['REMOTE_ADDR']);
    } catch (Exception $e) {
        //ignore it, seriously dude, friggin ignore it.
    }
    if ($location) {
        $country = DB::quote($location->countryCode);
        $country_full = DB::quote($location->countryName);
        $state = DB::quote($location->region);
        $state_full = @DB::quote($GEOIP_REGION_NAME[strtoupper($location->countryCode)][strtoupper($location->region)]);
        $city = DB::quote($location->city);
        $timezone = @DB::quote(get_time_zone($location->countryCode, $location->region));
        $postalcode = DB::quote($location->postalCode);
    } else {
        return 0;
    }
    $sql = "select location_id from bt_g_geo_locations where country='{$country}' and state='{$state}' and city='{$city}'";
    $id = DB::getVar($sql);
    if (!$id) {
        $sql = "insert into bt_g_geo_locations values ('','{$country}','{$country_full}','{$state}','{$state_full}','{$city}','{$timezone}','{$postalcode}')";
        DB::query($sql);
        $id = DB::insertId();
    }
    return $id;
}
コード例 #2
0
ファイル: geo_ip_data.php プロジェクト: afzet/cake-cart
 function GeoIpData($record, $ip)
 {
     if (!$ip) {
         trigger_error('GeoIpData wants an IP address!', E_USER_WARNING);
     } elseif (!is_a($record, 'geoiprecord') && !is_a($record, 'geoipdnsrecord')) {
         trigger_error('GeoIpData can only be created from a geoiprecord or geoipdnsrecord object!', E_USER_WARNING);
     } else {
         $mapping = array('ip' => 'ip', 'country_name' => 'countryName', 'country_code' => 'countryCode', 'country_code3' => 'longCountryCode', 'region' => 'region', 'regionname' => 'regionName', 'city' => 'city', 'postal_code' => 'postalCode', 'area_code' => 'areaCode', 'dma_code' => 'dmaCode', 'dmacode' => 'dmaCode', 'latitude' => 'latitude', 'longitude' => 'longitude', 'isp' => 'isp', 'org' => 'org', 'timezone' => 'timezone');
         // Add IP address to the record.
         $record->ip = $ip;
         // Add timezone to the record.
         $record->timezone = get_time_zone($record->country_code, $record->region);
         foreach ($mapping as $rKey => $dataKey) {
             if (isset($record->{$rKey})) {
                 $value = $record->{$rKey};
                 if ($value) {
                     $this->{$dataKey} = $value;
                 }
             }
         }
         // Some alias properties.
         $this->remoteAddress = $this->ip;
         $this->internetServiceProvider = $this->isp;
         $this->organization = $this->org;
     }
 }
コード例 #3
0
function geoip_detect_add_timezone_information_to_record($record)
{
    if ($record) {
        $record->timezone = get_time_zone($record->country_code, $record->region);
    }
    return $record;
}
コード例 #4
0
function geoip_get_timezone($details)
{
    if ($details) {
        $timezone = get_time_zone($details->country_code, $details->region);
        if (!$timezone) {
            $timezone = $details->country_name . '/' . $details->city;
        }
        return $timezone;
    } else {
        return 'UTC';
    }
}
コード例 #5
0
ファイル: CityTest.php プロジェクト: Alambos/geoip-api-php
 public function testCity()
 {
     global $GEOIP_REGION_NAME;
     $gi = geoip_open("tests/data/GeoIPCity.dat", GEOIP_STANDARD);
     $record = geoip_record_by_addr($gi, "64.17.254.216");
     $this->assertEquals(310, $record->area_code);
     $this->assertEquals('El Segundo', $record->city);
     $this->assertEquals('US', $record->country_code);
     $this->assertEquals('USA', $record->country_code3);
     $this->assertEquals('United States', $record->country_name);
     $this->assertEquals(803, $record->dma_code);
     $this->assertEquals(33.91, $record->latitude, '', 0.01);
     $this->assertEquals(-118.4, $record->longitude, '', 0.01);
     $this->assertEquals(803, $record->metro_code);
     $this->assertEquals('90245', $record->postal_code);
     $this->assertEquals('CA', $record->region);
     $this->assertEquals('California', $GEOIP_REGION_NAME[$record->country_code][$record->region]);
     $this->assertEquals('America/Los_Angeles', get_time_zone($record->country_code, $record->region));
 }
コード例 #6
0
#!/usr/bin/php -q
<?php 
require "timezone.php";
print get_time_zone("US", "WV");
コード例 #7
0
ファイル: sip_settings.php プロジェクト: AGProjects/cdrtool
function lookupGeoLocation($ip) {
    if ($_loc=geoip_record_by_name($ip)) {
        $_loc['timezone'] = get_time_zone($_loc['country_code'], $_loc['region']);
        $_loc['region'] = get_region($_loc['country_code'], $_loc['region']);

        $country_transition = array(
            "A1" => "N/A",
            "A2" => "N/A",
            "O1" => "N/A",
            "AP" => "N/A",
            "GB" => "UK");

        if (array_key_exists($_loc['country_code'],$country_transition)) {
            $_loc['country_code'] = $country_transition[$_loc['country_code']];
        }

        return $_loc;
    } else {
        return array();
    }
}
コード例 #8
0
ファイル: prep.inc.php プロジェクト: spiritwild/biorhythm
function get_timezone()
{
    global $geoip_record;
    $timezone = get_time_zone($geoip_record->country_code, $geoip_record->region);
    return $timezone;
}
コード例 #9
0
ファイル: referral.php プロジェクト: ddrmoscow/queXS
 //validate primary phone number supplied
 if (isset($_POST["v_{$pphone}"]) && only_numbers($_POST["v_{$pphone}"]) != "") {
     $phone = $db->qstr(only_numbers($_POST["v_{$pphone}"]));
     //Create a new sample record and add CASEREFERREDFROM to be this current case id
     $db->StartTrans();
     //create a new sample entry
     $sql = "SELECT s.import_id\r\n\t\t\tFROM `sample` as s, `case` as c\r\n\t\t\tWHERE c.case_id = '{$case_id}'\r\n\t\t\tAND s.sample_id = c.sample_id";
     $import_id = $db->GetOne($sql);
     //get all sample records
     $sql = "SELECT sivr.var,s.val, sivr.type\r\n\t\t\tFROM `sample_import_var_restrict` as sivr, `sample_var` as s, `case` as c\r\n\t\t\tWHERE c.case_id = '{$case_id}'\r\n\t\t\tAND s.sample_id = c.sample_id\r\n\t\t\tAND s.var_id = sivr.var_id";
     $rs = $db->GetAll($sql);
     $tzone = get_setting("DEFAULT_TIME_ZONE");
     //set this to default
     //Get the timezone
     foreach ($rs as $r) {
         $tz = get_time_zone($_POST["v_" . $r['var']], $r['type']);
         if ($tz !== false) {
             $tzone = $tz;
             break;
         }
     }
     $sql = "INSERT INTO `sample` (import_id,Time_zone_name,phone)\r\n\t\t\tVALUES ({$import_id},'{$tzone}',{$phone})";
     $db->Execute($sql);
     $sample_id = $db->Insert_ID();
     //insert sample var records
     foreach ($rs as $r) {
         $sql = "INSERT INTO `sample_import_var_restrict` (`var`,`type`)\r\n\t\t\t\t\tVALUES ('{$r['var']}','{$r['type']}')";
         $db->Execute($sql);
         $varid = $db->Insert_ID();
         $sql = "INSERT INTO `sample_var` (`sample_id`,`var_id`,`val`)\r\n\t\t\t\tVALUES ('{$sample_id}','{$varid}'," . $db->qstr($_POST['v_' . $r['var']]) . ")";
         $db->Execute($sql);
コード例 #10
0
ファイル: functions.import.php プロジェクト: ddrmoscow/queXS
/**
 * Import a CSV file to the sample database
 *
 * @param string $file File name to open
 * @param string $description A description of the sample
 * @param array $fields Which fields to import and what type they are assigned to
 *
 * @see verify_fields()
 * @see display_table()
 *
 */
function import_file($file, $description, $fields, $firstrow = 2)
{
    $row = 1;
    $handle = fopen($file, "r");
    //import into database
    global $db;
    $db->StartTrans();
    $sql = "INSERT INTO sample_import\r\n\t\t(sample_import_id, description)\r\n\t\tVALUES (NULL, '{$description}')";
    //	print("$sql<br/>");
    //	if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
    $rs = $db->Execute($sql);
    $id = $db->Insert_ID();
    $selected_type = array();
    $selected_name = array();
    $sirv_id = array();
    foreach ($fields as $key => $val) {
        if (strncmp($key, "i_", 2) == 0) {
            $selected_type[substr($key, 2)] = $fields["t_" . substr($key, 2)];
            $selected_name[substr($key, 2)] = $fields["n_" . substr($key, 2)];
            $restrict = 1;
            //Set restrictions on columns
            if (isset($fields["a_" . substr($key, 2)])) {
                $restrict = 0;
            }
            $sql = "INSERT INTO sample_import_var_restrict\r\n\t\t\t\t(`sample_import_id`,`var`,`type`,`restrict`)\r\n\t\t\t\tVALUES ({$id},'" . $fields["n_" . substr($key, 2)] . "','" . $fields["t_" . substr($key, 2)] . "',{$restrict})";
            $db->Execute($sql);
            $sirv_id[substr($key, 2)] = $db->Insert_ID();
            //
        }
    }
    /**
     * create an ordered index of columns that contain data for obtaining the timezone
     * type of 5,4,3,2 preferred
     */
    arsort($selected_type);
    $imported = 0;
    while (($data = fgetcsv($handle)) !== FALSE) {
        //data contains an array of elements in the csv
        //selected contains an indexed array of elements to import with the type attached
        if ($row >= $firstrow) {
            //determine if there is a phone number - if not - do not import
            $numberavail = 0;
            foreach ($selected_type as $key => $val) {
                if ($val == 2 || $val == 3) {
                    $dkey = only_numbers($data[$key - 1]);
                    if (!empty($dkey)) {
                        $data[$key - 1] = $dkey;
                        $numberavail = 1;
                    }
                }
            }
            if ($numberavail == 1) {
                //insert into sample field
                //first find the timezone
                $tzone = get_setting("DEFAULT_TIME_ZONE");
                //set this to default
                /**
                 * Determine time zone from all possible sources in sample_var_type table
                 *
                 */
                foreach ($selected_type as $key => $val) {
                    $tz = get_time_zone($data[$key - 1], $val);
                    if ($tz !== false) {
                        $tzone = $tz;
                        break;
                    }
                }
                /**
                 * insert using primary phone number (3)
                 */
                $ppid = array_search('3', $selected_type);
                $dppid = only_numbers($data[$ppid - 1]);
                $sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone)\r\n\t\t\t\t\tVALUES (NULL,'{$id}','{$tzone}','{$dppid}')";
                $db->Execute($sql);
                $sid = $db->Insert_Id();
                /**
                 * insert into sample_var field
                 */
                foreach ($selected_name as $key => $val) {
                    $dkey = $db->Quote($data[$key - 1]);
                    $sql = "INSERT INTO sample_var (sample_id,var_id,val)\r\n\t\t\t\t\t\tVALUES ('{$sid}','{$sirv_id[$key]}',{$dkey})";
                    $db->Execute($sql);
                }
                $imported++;
            }
        }
        $row++;
    }
    fclose($handle);
    //cleanup
    unlink($file);
    return $db->CompleteTrans();
}
コード例 #11
0
// AZERBAIJAN (824)
// MACAU (824)
// LUXEMBOURG (812)
// CYPRUS (754)
// KUWAIT (753)
// QATAR (736)
// PANAMA (695)
// HONDURAS (658)
// IRAQ (638)
// LEBANON (579)
// JAMAICA (575)
/*
* timezone: https://www.google.com.ph/?gfe_rd=cr&ei=FkKaVJWBOoaL8Qf7koHQCg&gws_rd=ssl#q=MANILA+url
*
*/
get_time_zone('NEW YORK');
function get_time_zone($capital_city)
{
    $url = '';
    $timezone = '';
    switch ($capital_city) {
        case 'NEW YORK':
            /* nyc,york,new york
             * 24720 = limit 505 
             */
            $url = 'EST';
            $timezone = 'http://www.timeanddate.com/worldclock/usa/new-york';
            break;
        case 'LONDON':
            /*
             * 22,242 = 463 
コード例 #12
0
ファイル: timezone.php プロジェクト: Simerjit-developer/geoip
<?php

require_once "geoipcity.inc";
//include geoip file
$gi = geoip_open("GeoLiteCity.dat", GEOIP_MEMORY_CACHE);
//include geoip.dat file
$record = GeoIP_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
//print_r($record);
$country = $record->country_code;
//get country code
$region = $record->region;
//get region code
$timezone = get_time_zone("{$country}", "{$region}");
//get timezone
echo $timezone;
geoip_close($gi);
コード例 #13
0
 /**
  * Run the application
  *
  * @param int $a_runtime Runtime mode
  */
 public function run($a_runtime = APINE_RUNTIME_HYBRID)
 {
     if ($a_runtime !== APINE_RUNTIME_HYBRID && $a_runtime !== APINE_RUNTIME_API && $a_runtime !== APINE_RUNTIME_APP) {
         $a_runtime = APINE_RUNTIME_HYBRID;
     }
     if ($this->use_composer && !strstr($this->apine_folder, 'vendor/youmy001')) {
         require_once 'vendor/autoload.php';
     }
     /**
      * Main Execution
      */
     try {
         // Make sure application runs with a valid execution mode
         if ($this->mode !== APINE_MODE_DEVELOPMENT && $this->mode !== APINE_MODE_PRODUCTION) {
             throw new GenericException('Invalid Execution Mode \\"' . $this->mode . '"', 418);
         }
         if (!file_exists('.htaccess') || !file_exists('config.ini')) {
             $protocol = isset(Request::server()['SERVER_PROTOCOL']) ? Request::server()['SERVER_PROTOCOL'] : 'HTTP/1.0';
             header($protocol . ' 503 Service Unavailable');
             die("Critical Error : Framework Installation Not Completed");
         }
         if (!Request::is_api_call() && (!empty(Request::get()['request']) && Request::get()['request'] != '/')) {
             $request = Request::get()['request'];
         } else {
             if (!Request::is_api_call()) {
                 $request = '/index';
             } else {
                 $request = Request::get()['request'];
             }
         }
         // Verify is the protocol is allowed
         if (Request::is_https() && !$this->use_https) {
             apine_internal_redirect($request, APINE_PROTOCOL_HTTP);
         }
         if (is_null($this->config)) {
             $this->config = new Config('config.ini');
         }
         // Find a timezone for the user
         // using geoip library and its local database
         if (function_exists('geoip_open')) {
             $gi = geoip_open($this->apine_folder . "/GeoLiteCity.dat", GEOIP_STANDARD);
             $record = GeoIP_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
             //$record = geoip_record_by_addr($gi, "24.230.215.89");
             //var_dump($record);
             if (isset($record)) {
                 $timezone = get_time_zone($record->country_code, $record->region != '' ? $record->region : 0);
             } else {
                 if (!is_null($this->config->get('dateformat', 'timezone'))) {
                     $timezone = $this->config->get('dateformat', 'timezone');
                 } else {
                     $timezone = 'America/New_York';
                 }
             }
             date_default_timezone_set($timezone);
         } else {
             if (!is_null($this->config->get('dateformat', 'timezone'))) {
                 date_default_timezone_set($this->config->get('dateformat', 'timezone'));
             }
         }
         // If a user is logged in; redirect to the allowed protocol
         // Secure session only work when Use HTTPS is set to "yes"
         if (SessionManager::is_logged_in()) {
             if ($this->secure_session) {
                 if (!Request::is_https() && $this->use_https) {
                     die(apine_internal_redirect($request, APINE_PROTOCOL_HTTPS)->draw());
                 } else {
                     if (Request::is_https() && !$this->use_https) {
                         die(apine_internal_redirect($request, APINE_PROTOCOL_HTTP)->draw());
                     }
                 }
             } else {
                 if (Request::is_https()) {
                     die(apine_internal_redirect($request, APINE_PROTOCOL_HTTP)->draw());
                 }
             }
         }
         unset($request);
         if (!Request::is_api_call()) {
             if ($a_runtime == APINE_RUNTIME_API) {
                 throw new GenericException('Web Application calls are not implemented', 501);
             }
             Engine::instance()->add_rule(new Rule('apine_data_loop', 'loopdata', '<?php foreach ($this->data as $element): $this->wrap($element); ?>'));
             Engine::instance()->add_rule(new Rule('apine_config', 'apine_config:(\\w+),(\\w+)', '<?php echo \\Apine\\Application\\Application::get_instance()->get_config()->get(\'$1\',\'$2\');?>'));
             Engine::instance()->add_rule(new Rule('apine_translate', 'apine_translate:(\\w+),(\\w+)', '<?php echo \\Apine\\Application\\Translator::get_instance()->translate(\'$1\',\'$2\');?>'));
             Engine::instance()->add_rule(new Rule('apine_format_date', 'apine_format_date:(\\w+),(\\w+)', '<?php echo \\Apine\\Application\\Translator::get_instance()->translation()->get_locale()->format_date("$1", Apine\\Application\\Translator::get_instance()->translation()->get_locale()->$2());?>'));
             Engine::instance()->add_rule(new Rule('apine_format_date_array', 'apine_format_date:(\\w+)\\[(\\w+)\\],(\\w+)', '<?php echo \\Apine\\Application\\Translator::get_instance()->translation()->get_locale()->format_date($this->data[\'$1\'][\'$2\'], Apine\\Application\\Translator::get_instance()->translation()->get_locale()->$3());?>'));
             Engine::instance()->add_rule(new Rule('apine_language', 'apine_language:(code|short|name)', '<?php switch("$1"){case "code": echo Apine\\Application\\Translator::get_instance()->translation()->get("language","code");break;case "short": echo Apine\\Application\\Translator::get_instance()->translation()->get("language","shortcode");break;case "name": echo Apine\\Application\\Translator::get_instance()->translation()->get("language","name");break;}?>'));
             Engine::instance()->add_rule(new Rule('apine_execution', 'apine_execution_time', '<?php echo apine_execution_time();?>'));
             Engine::instance()->add_rule(new Rule('apine_version', 'apine_version:(framework|application)', '<?php echo \\Apine\\Application\\Application::get_instance()->get_version()->$1();?>'));
             Engine::instance()->add_rule(new Rule('apine_url', 'apine_url_(path|resource):(([^\\/\\s]+\\/)?([^\\{\\}]*))', '<?php echo \\Apine\\MVC\\URLHelper::get_instance()->$1("$2");?>'));
             Engine::instance()->add_rule(new Rule('apine_url_secure', 'apine_url_(path|resource)_secure:(([^\\/\\s]+\\/)?([^\\{\\}]*))', '<?php echo Apine\\MVC\\URLHelper::get_instance()->$1("$2", APINE_PROTOCOL_HTTPS);?>'));
             Engine::instance()->add_rule(new Rule('apine_view_apply_meta', 'apine_apply_meta', '<?php echo Apine\\MVC\\HTMLView::apply_meta($data["apine_view_metatags"]);?>'));
             Engine::instance()->add_rule(new Rule('apine_view_apply_scripts', 'apine_apply_scripts', '<?php echo Apine\\MVC\\HTMLView::apply_scripts($data["apine_view_scripts"]);?>'));
             Engine::instance()->add_rule(new Rule('apine_view_apply_stylesheets', 'apine_apply_stylesheets', '<?php echo Apine\\MVC\\HTMLView::apply_stylesheets($data["apine_view_stylesheets"]);?>'));
             Engine::instance()->add_rule(new Rule('apine_user_has_group', 'if:apine_user\\[groups\\]==([0-9]+)', '<?php if (\\Apine\\Session\\SessionManager::get_user()->has_group($1)) : ?>'));
             Engine::instance()->add_rule(new Rule('apine_user_group', 'apine_user\\[groups\\]\\[([0-9]+)\\]', '<?php echo (\\Apine\\Session\\SessionManager::get_user()->has_group($1)) : \\Apine\\Session\\SessionManager::get_user()->get_group()->get_item($1)->get_name() : ""; ?>'));
             if (!empty(Request::get()['request']) && Request::get()['request'] != '/') {
                 $request = Request::get()['request'];
             } else {
                 $request = '/index';
             }
             $router = new WebRouter($this->routes_path, $this->routes_type);
         } else {
             if ($a_runtime == APINE_RUNTIME_APP) {
                 throw new GenericException('RESTful API calls are not implemented', 501);
             }
             $request = Request::get()['request'];
             $router = new APIRouter();
         }
         // Fetch and execute the route
         $route = $router->route($request);
         $view = $router->execute($route->controller, $route->action, $route->args);
         // Draw the output is a view is returned
         if (!is_null($view) && is_a($view, 'Apine\\MVC\\View')) {
             $view->draw();
         } else {
             throw new GenericException('Empty Apine View', 488);
         }
     } catch (GenericException $e) {
         // Handle application errors
         try {
             $error = new Controllers\ErrorController();
             if ($this->mode == APINE_MODE_PRODUCTION) {
                 if ($error_name = $error->method_for_code($e->getCode())) {
                     $view = $error->{$error_name}();
                 } else {
                     $view = $error->server();
                 }
             } else {
                 $view = $error->custom($e->getCode(), $e->getMessage(), $e);
             }
             $view->draw();
         } catch (Exception $e2) {
             var_dump($e2->getTraceAsString());
             $protocol = isset(Request::server()['SERVER_PROTOCOL']) ? Request::server()['SERVER_PROTOCOL'] : 'HTTP/1.0';
             header($protocol . ' 500 Internal Server Error');
             die("Critical Error : " . $e->getMessage());
         }
     } catch (Exception $e) {
         // Handle PHP exceptions
         try {
             $error = new Controllers\ErrorController();
             $view = $error->custom(500, $e->getMessage(), $e);
             $view->draw();
         } catch (Exception $e2) {
             $protocol = isset(Request::server()['SERVER_PROTOCOL']) ? Request::server()['SERVER_PROTOCOL'] : 'HTTP/1.0';
             header($protocol . ' 500 Internal Server Error');
             die("Critical Error : " . $e->getMessage());
         }
     }
 }