]> dev.renevier.net Git - syj.git/blob - application/controllers/helpers/SyjGeoip.php
cleanup po files
[syj.git] / application / controllers / helpers / SyjGeoip.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class Syj_Controller_Action_Helper_SyjGeoip extends Zend_Controller_Action_Helper_Abstract
6 {
7
8     public function direct ($ip) {
9         $db = Zend_Db_Table_Abstract::getDefaultAdapter();
10         $select = $db->select(null)->from('geoip', null)->where('geoip.begin_ip <= inet_to_bigint(?)', (string)$ip)
11                                   ->where('geoip.end_ip >= inet_to_bigint(?)', (string)$ip)
12                                   ->limit(1)
13                                   ->join('geonames', 'geonames.country = geoip.country', array(
14                                   'geonames.minlon', 'geonames.minlat', 'geonames.maxlon', 'geonames.maxlat'
15                                   ));
16         try {
17             $stmt = $db->query($select);
18             $row = $db->query($select)->fetch();
19         } catch (Exception $e) {
20             $row = null;
21         }
22         if (!$row) {
23             $row = Zend_Controller_Front::getInstance()->getParam('defaultloc');
24         }
25         return array_map(function($elem) { return (float)$elem;},$row);
26     }
27 }