function testgeoipdatabase($type, $flags, $msg, $numlookups)
 {
     $gi = geoip_open($this->dbfilename[$type], $flags);
     if ($gi == null) {
         print "error: " . $this->dbfilename[$type] . " does not exist\n";
         return;
     }
     $t1 = $this->ftime();
     $i4 = 0;
     for ($i2 = 0; $i2 < $numlookups; $i2++) {
         switch ($type) {
             case GEOIP_COUNTRY_DATABASE:
                 geoip_country_code_by_addr($gi, $this->randomipaddress());
                 break;
             case GEOIP_REGION_DATABASE:
                 geoip_region_by_addr($gi, $this->randomipaddress());
                 break;
             case GEOIP_CITY_DATABASE:
                 GeoIP_record_by_addr($gi, $this->randomipaddress());
                 break;
         }
     }
     $t2 = $this->ftime();
     $t3 = $t2 - $t1;
     print $msg . "\n";
     print $numlookups . " lookups made in " . $t3 . " seconds \n";
     geoip_close($gi);
 }
function geoip_get_details_by_host($host)
{
    require_once 'geoipcity.php';
    $geoip = geoip_open('./GeoLiteCity.dat', GEOIP_STANDARD);
    $details = GeoIP_record_by_addr($geoip, gethostbyname($host));
    geoip_close($geoip);
    return $details;
}
Example #3
0
 /**
  * Lookup a record in the database.
  *
  * @param string $ip IP address to lookup
  * @access public
  * @return GeoIpData|false
  */
 function lookup($ip)
 {
     $record = GeoIP_record_by_addr($this->__geoip, $ip);
     if ($record) {
         return new GeoIpData($record, $ip);
     } else {
         return false;
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getGeocodedData($address)
 {
     if (false === filter_var($address, FILTER_VALIDATE_IP)) {
         throw new UnsupportedException('The MaxMindBinaryProvider does not support street addresses.');
     }
     $geoIp = geoip_open($this->datFile, $this->openFlag);
     $geoIpRecord = GeoIP_record_by_addr($geoIp, $address);
     geoip_close($geoIp);
     if (false === $geoIpRecord instanceof \geoiprecord) {
         throw new NoResultException(sprintf('No results found for IP address %s', $address));
     }
     return array($this->fixEncoding(array_merge($this->getDefaults(), array('countryCode' => $geoIpRecord->country_code, 'country' => $geoIpRecord->country_name, 'region' => $geoIpRecord->region, 'city' => $geoIpRecord->city, 'latitude' => $geoIpRecord->latitude, 'longitude' => $geoIpRecord->longitude))));
 }
Example #5
0
 /**
  *
  * @param null|string $ipAddress
  * @return \GeoipModule\Object\Record
  */
 public function find($ipAddress = null)
 {
     if (null === $ipAddress) {
         $ipAddress = $_SERVER['REMOTE_ADDR'];
     }
     $record = GeoIP_record_by_addr($this->geoip, $ipAddress);
     $recordObject = clone $this->getRecordInstance();
     if ($record !== null) {
         $hydrator = new ClassMethods();
         $hydrator->hydrate(get_object_vars($record), $recordObject);
     }
     return $recordObject;
 }
Example #6
0
 /**
  * Update Visitor info to include country and city
  */
 public static function location_update()
 {
     $db = JFactory::getDbo();
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     if (file_exists(JPATH_COMPONENT . DS . 'assets' . DS . 'geoip' . DS . 'geolitecity.dat')) {
         if (filesize(JPATH_COMPONENT . DS . 'assets' . DS . 'geoip' . DS . 'geolitecity.dat') != 0) {
             if (!function_exists('GeoIP_record_by_addr')) {
                 include JPATH_COMPONENT . DS . 'assets' . DS . 'geoip' . DS . 'geoipcity.inc';
             }
             $geoip = geoip_open(JPATH_COMPONENT . DS . 'assets' . DS . 'geoip' . DS . 'geolitecity.dat', GEOIP_STANDARD);
             $query = $db->getQuery(true);
             $query->select('id, ip');
             $query->from($db->quoteName('#__cwtraffic'));
             $query->where('country_code = "" OR country_code is null');
             $db->setQuery($query);
             foreach ($db->loadObjectList() as $row) {
                 $country_code = strtolower(geoip_country_code_by_addr($geoip, $row->ip));
                 $country_name = geoip_country_name_by_addr($geoip, $row->ip);
                 $addr = GeoIP_record_by_addr($geoip, $row->ip);
                 if (!empty($addr)) {
                     $city = $addr->city;
                 }
                 if ($country_code != '' && $country_name != '') {
                     $query = $db->getQuery(true);
                     $query->update('#__cwtraffic');
                     $query->set('country_code = ' . $db->quote($country_code));
                     $query->set('country_name = ' . $db->quote($country_name));
                     $query->set('city = ' . $db->quote($city));
                     $query->where('id = ' . $row->id);
                     $db->setQuery($query);
                     $db->query();
                 }
             }
             geoip_close($geoip);
             $query = $db->getQuery(true);
             $query->update('#__cwtraffic');
             $query->set('city = NULL');
             $query->where('city = ""');
             $db->setQuery($query);
             $db->query();
         }
     }
     return;
 }
Example #7
0
 /**
  * {@inheritDoc}
  */
 public function geocode($address)
 {
     if (false === filter_var($address, FILTER_VALIDATE_IP)) {
         throw new UnsupportedOperation('The MaxMindBinary provider does not support street addresses.');
     }
     // This API does not support IPv6
     if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
         throw new UnsupportedOperation('The MaxMindBinary provider does not support IPv6 addresses.');
     }
     $geoIp = geoip_open($this->datFile, $this->openFlag);
     $geoIpRecord = GeoIP_record_by_addr($geoIp, $address);
     geoip_close($geoIp);
     if (false === $geoIpRecord instanceof \GeoIpRecord) {
         throw new NoResult(sprintf('No results found for IP address %s', $address));
     }
     $adminLevels = [];
     if ($geoIpRecord->region) {
         $adminLevels[] = ['name' => $geoIpRecord->region, 'level' => 1];
     }
     return $this->returnResults([$this->fixEncoding(array_merge($this->getDefaults(), ['countryCode' => $geoIpRecord->country_code, 'country' => $geoIpRecord->country_name, 'adminLevels' => $adminLevels, 'locality' => $geoIpRecord->city, 'latitude' => $geoIpRecord->latitude, 'longitude' => $geoIpRecord->longitude]))]);
 }
Example #8
0
function luc_spyvisitors()
{
    global $wpdb;
    global $StatPressV_Option;
    $action = "spyvisitors";
    $table_name = STATPRESS_V_TABLE_NAME;
    // number of IP or bot by page
    $LIMIT = $StatPressV_Option['StatPressV_SpyVisitor_IP_Per_Page'] ? $StatPressV_Option['StatPressV_SpyVisitor_IP_Per_Page'] : 20;
    $LIMIT_PROOF = $StatPressV_Option['StatPressV_SpyVisitor_Visits_Per_IP'] ? $StatPressV_Option['StatPressV_SpyVisitor_Visits_Per_IP'] : 20;
    $pp = luc_page_periode();
    // Number of distinct ip (unique visitors)
    $NumIP = $wpdb->get_var("SELECT count(distinct ip)\n\t\t\t\t\t\t\t\t\tFROM {$table_name}\n\t\t\t\t\t\t\t\t\tWHERE spider='' ;");
    $NP = ceil($NumIP / $LIMIT);
    $LimitValue = $pp * $LIMIT - $LIMIT;
    $sql = "SELECT *\n\t\t\t\t\tFROM {$table_name} as T1\n\t\t\t\t\tJOIN\n\t\t\t\t\t\t(SELECT max(id) as MaxId,ip\n\t\t\t\t\t\t\tFROM {$table_name}\n\t\t\t\t\t\t\tWHERE spider=''\n\t\t\t\t\t\t\tGROUP BY ip\n\t\t\t\t\t\t\tORDER BY MaxId DESC LIMIT {$LimitValue}, {$LIMIT}\n\t\t\t\t\t\t) as T2\n\t\t\t\t\tON T1.ip = T2.ip\n\t\t\t\t\tORDER BY MaxId DESC, id DESC;\n\t\t\t\t";
    $qry = $wpdb->get_results($sql);
    if ($StatPressV_Option['StatPressV_Use_GeoIP'] == 'checked' & function_exists('geoip_open')) {
        // Open the database to read and save info
        if (file_exists(luc_GeoIP_dbname('city'))) {
            $gic = geoip_open(luc_GeoIP_dbname('city'), GEOIP_STANDARD);
            $geoip_isok = true;
        }
    }
    echo "<div class='wrap'><h2>" . __('Visitor Spy', 'statpress') . "</h2>";
    ?>
<script>
	function ttogle(thediv){
	if (document.getElementById(thediv).style.display=="inline") {
	document.getElementById(thediv).style.display="none"
	} else {document.getElementById(thediv).style.display="inline"}
	}
</script>
<?php 
    $MaxId = 0;
    $num_row = 0;
    // Add pagination
    luc_insert_pagination_options("spyvisitors", $NumIP, $LIMIT);
    luc_print_pp_link($NP, $pp, $action);
    echo '<table class="widefat" id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">';
    foreach ($qry as $rk) {
        // Visitor Spy
        if ($MaxId != $rk->MaxId) {
            if ($geoip_isok === true) {
                $gir = GeoIP_record_by_addr($gic, $rk->ip);
            }
            echo "<thead><tr><th scope='colgroup' colspan='2'>";
            if ($rk->country != '') {
                echo "HTTP country " . luc_HTML_IMG($rk->country, 'country', false);
            } else {
                echo "Hostip country <IMG SRC='http://api.hostip.info/flag.php?ip=" . $rk->ip . "' border=0 width=18 height=12>  ";
            }
            if ($geoip_isok === true) {
                $lookupsvc = "GeoIP details";
            } else {
                $lookupsvc = "Hostip details";
            }
            echo "\t<strong><span><font size='2' color='#7b7b7b'> " . $rk->ip . " </font></span></strong>\n\t\t\t\t\t<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;'\n\t\t\t\t\t\tonClick=ttogle('" . $rk->ip . "');>" . $lookupsvc . "</span></div>\n\t\t\t\t\t<div id='" . $rk->ip . "' name='" . $rk->ip . "'>";
            if ($geoip_isok === true) {
                echo "\t<small><br>\n\t\t\t\t\t\t\tCountry: " . utf8_encode($gir->country_name) . " (" . $gir->country_code . ")<br>\n\t\t\t\t\t\t\tCity: " . utf8_encode($gir->city) . "<br>\n\t\t\t\t\t\t\tLatitude/Longitude: <a href='http://maps.google.com/maps?q=" . $gir->latitude . "+" . $gir->longitude . "' target='_blank' title='Lookup latitude/longitude location on Google Maps...'>" . $gir->latitude . " " . $gir->longitude . "</a>\n\t\t\t\t\t\t</small>";
            } else {
                echo "\t<iframe style='overflow:hide;border:0px;width:100%;height:35px;font-family:helvetica;paddng:0;'\n\t\t\t\t\t\t\tscrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=" . $rk->ip . ">\n\t\t\t\t\t\t</iframe>";
            }
            echo "\t<small>\n\t\t\t\t\t\t<br>" . $rk->os . "\n\t\t\t\t\t\t<br>" . $rk->browser . "\n\t\t\t\t\t\t<br>" . gethostbyaddr($rk->ip) . "\n\t\t\t\t\t\t<br>" . $rk->agent . "\n\t\t\t\t\t</small></div></th></tr></thead><tbody>\n\t\t\t\t\t<script> document.getElementById('" . $rk->ip . "').style.display='none';</script>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>" . luc_hdate($rk->date) . " " . $rk->time . "</td>\n\t\t\t\t\t<td>" . (isset($rk->post_title) ? $rk->post_title : luc_post_title_Decode(urldecode($rk->urlrequested))) . "";
            if ($rk->searchengine != '') {
                echo "<br><small>arrived from <b>" . $rk->searchengine . "</b> searching <a target='_blank' href='" . $rk->referrer . "' >" . urldecode($rk->search) . "</a></small>";
            } elseif ($rk->referrer != '' && strpos($rk->referrer, $home) === false) {
                echo "<br><small>arrived from <a target='_blank' href='" . $rk->referrer . "' >" . $rk->referrer . "</a></small>";
            }
            echo "</div></td></tr>\n";
            $MaxId = $rk->MaxId;
            $num_row = 1;
        } elseif ($num_row < $LIMIT_PROOF) {
            echo "<tr><td>" . luc_hdate($rk->date) . " " . $rk->time . "</td>\n\t\t\t\t\t\t<td>" . (isset($rk->post_title) ? $rk->post_title : luc_post_title_Decode(urldecode($rk->urlrequested))) . "";
            if ($rk->searchengine != '') {
                echo "<br><small>arrived from <b>" . $rk->searchengine . "</b> searching <a target='_blank' href='" . $rk->referrer . "' >" . urldecode($rk->search) . "</a></small>";
            } elseif ($rk->referrer != '' && strpos($rk->referrer, $home) === false) {
                echo "<br><small>arrived from <a target='_blank' href='" . $rk->referrer . "' >" . $rk->referrer . "</a></small>";
            }
            $num_row += 1;
            echo "</td></tr></tbody>";
        }
    }
    echo "</div></td></tr>\n</table>";
    luc_print_pp_link($NP, $pp, $action);
    echo "</div>";
    luc_StatPressV_load_time();
}
Example #9
0
function luc_GeoIP_get_data($ipAddress)
{
    global $StatPressV_Option;
    $StatPressV_Use_GeoIP = $StatPressV_Option['StatPressV_Use_GeoIP'];
    if (file_exists(luc_GeoIP_dbname('country'))) {
        if ($StatPressV_Use_GeoIP == 'checked') {
            $gi = geoip_open(luc_GeoIP_dbname('country'), GEOIP_STANDARD);
            $array['cc'] = geoip_country_code_by_addr($gi, $ipAddress);
            $array['cn'] = utf8_encode(geoip_country_name_by_addr($gi, $ipAddress));
        }
    }
    if (file_exists(luc_GeoIP_dbname('city'))) {
        if ($StatPressV_Use_GeoIP == 'checked') {
            $gic = geoip_open(luc_GeoIP_dbname('city'), GEOIP_STANDARD);
            $gir = GeoIP_record_by_addr($gic, $ipAddress);
            $array['region'] = utf8_encode($gir->region);
            $array['city'] = utf8_encode($gir->city);
            $array['postal_code'] = $gir->postal_code;
            $array['latitude'] = $gir->latitude;
            $array['longitude'] = $gir->longitude;
            $array['area_code'] = $gir->area_code;
            $array['metro_code'] = $gir->metro_code;
            $array['continent_code'] = $gir->continent_code;
        }
    }
    if (count($array) > 0) {
        return $array;
    } else {
        return false;
    }
}
Example #10
0
 function widget_geotrace($host, $w = '100%', $h = '100%')
 {
     //http://maps.google.com/?ie=UTF8&ll=37.0625,-95.677068&spn=31.013085,55.634766&t=h&z=4
     $p = '';
     // GeoLiteCity
     if (file_exists('GeoLiteCity.dat')) {
         geoip_load_shared_mem('GeoLiteCity.dat');
         $gi = geoip_open('GeoLiteCity.dat', GEOIP_SHARED_MEMORY);
         $host = gethostbyname($host);
         $a = GeoIP_record_by_addr($gi, $host);
         geoip_close($gi);
         // DEBUG
         //      echo '<pre><tt>';
         //      print_r ($a);
         $p .= '' . '<iframe width="' . $w . '" height="' . $h . '"' . ' frameborder="0"' . ' scrolling="no"' . ' marginheight="0"' . ' marginwidth="0"' . ' src="http://www.openstreetmap.org/export/embed.html?bbox=' . ($a->longitude - 0.005) . ',' . ($a->latitude - 0.005) . ',' . ($a->longitude + 0.005) . ',' . ($a->latitude + 0.005) . '&layer=mapnik"' . '>' . '</iframe>';
     }
     return $p;
 }
Example #11
0
function GeoIP_country_name_by_addr($gi, $addr)
{
    if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
        $record = GeoIP_record_by_addr($gi, $addr);
        return $record->country_name;
    } else {
        $country_id = GeoIP_country_id_by_addr($gi, $addr);
        if ($country_id !== false) {
            return $gi->GEOIP_COUNTRY_NAMES[$country_id];
        }
    }
    return false;
}
Example #12
0
Db_Mysql::init(MYSQL_HOST, MYSQL_LOGIN, MYSQL_PASSWORD, MYSQL_DB);
$db = Db_Mysql::getInstance();
$db->query('SET NAMES "utf8" COLLATE "utf8_unicode_ci";');
$db->debug = defined('D_DEBUG');
$bot_id = $data_type = $raw_data = '';
GetServerData();
$bot_id = mysql_real_escape_string($bot_id);
$raw_data = mysql_real_escape_string($raw_data);
$cmds = "";
try {
    if ($data_type == SRV_TYPE_REPORT) {
        //---------------------------------------------------------------------------------------------------------------------
        parse_str($raw_data, $REC);
        $ip = getIP();
        $gi = geoip_open('geo/GeoIPCity.dat', GEOIP_STANDARD);
        $gip = GeoIP_record_by_addr($gi, $ip);
        if (empty($gip->country_code)) {
            $gip->country_code = 'UNKNOWN';
        }
        $botCountry = $gip->country_code;
        $bot = array('botName' => $bot_id, 'botIp' => ip2long($ip), 'botAccess' => strtotime('now'), 'botCountry' => $botCountry, 'botSystem' => $REC['os'], 'botBuildId' => $REC['bid']);
        $bot_s = $db->query("SELECT `botId`, `botClean` FROM bots WHERE botName='{$bot_id}'")->fetchAssoc();
        if (!is_array($bot_s)) {
            $bot['botClean'] = 'yes';
            $bot['botAdded'] = strtotime('now');
            $db->insert('bots', $bot);
            $botid = $db->lastInsert();
            $botClean = 'yes';
        } else {
            $db->update('bots', $bot, "botId={$bot_s['botId']}");
            $botid = $bot_s['botId'];
 function geoip_purephp($ip)
 {
     $g = geoip_open(dirname(__FILE__) . "/geoip/GeoLiteCity.dat", GEOIP_STANDARD);
     $rec = GeoIP_record_by_addr($g, $ip);
     geoip_close($g);
     $rec = (array) $rec;
     /*
     		$record["city"] = $rec->city;
     		$record["country_code"] = 
     		$record["country_name"] = $rec->country_name;
     		$record["postal_code"] = $rec->postal_code;
     		$record["region"] = $rec->region;
     
     		print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
     		print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
     		print $record->city . "\n";
     		print $record->postal_code . "\n";
     		print $record->latitude . "\n";
     		print $record->longitude . "\n";
     		print $record->metro_code . "\n";
     		print $record->area_code . "\n";
     */
     return $rec;
 }
Example #14
0
 function doGeoIP()
 {
     global $configArray;
     //Load GeoIP data
     require_once ROOT_DIR . '/sys/MaxMindGeoIP/geoip.inc';
     require_once ROOT_DIR . '/sys/MaxMindGeoIP/geoipcity.inc';
     $geoIP = geoip_open($configArray['Site']['local'] . '/../../sites/default/GeoIPCity.dat', GEOIP_MEMORY_CACHE);
     $geoRecord = GeoIP_record_by_addr($geoIP, $this->session->ip);
     if ($geoRecord) {
         $this->session->setCountry($geoRecord->country_code);
         $this->session->setState($geoRecord->region);
         $this->session->setCity($geoRecord->city);
         $this->session->latitude = $geoRecord->latitude;
         $this->session->longitude = $geoRecord->longitude;
     }
     geoip_close($geoIP);
 }
 /**
  * @param null $address
  * @return string
  */
 public function getPosition($address = null)
 {
     $record = GeoIP_record_by_addr($this->gic, $address);
     if (empty($record)) {
         return '41.766667,-50.233333';
     }
     $position = $record->latitude . ',' . $record->longitude;
     return $position;
 }
Example #16
0
<?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);
Example #17
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());
         }
     }
 }