1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | <?php // // Open Web Analytics - An Open Source Web Analytics Framework // // Copyright 2008 Peter Adams. All rights reserved. // // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // $Id$ // /** * Geolocation Class * * @author Peter Adams <peter@openwebanalytics.com> * @copyright Copyright © 2008 Peter Adams <peter@openwebanalytics.com> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.3.0 */ class owa_geolocation { var $properties = array(); public static function getInstance() { return new owa_geolocation(); } function __construct() { } function __destruct() { } function getGeolocationFromIp($ip_address, $refresh = false) { if (empty($this->properties) || $refresh === true) { $geo = array('ip_address' => $ip_address, 'city' => '', 'country' => '', 'state' => '', 'country_code' => '', 'latitude' => '', 'longitude' => ''); if ( owa_coreAPI::getSetting( 'base', 'geolocation_lookup' ) ) { $eq = owa_coreAPI::getEventDispatch(); $geo = $eq->filter('geolocation', $geo); } foreach ($geo as $k => $v) { if ( ! $v ) { $geo[$k] = '(not set)'; } } $this->properties = $geo; } } function getProperty($name) { if (array_key_exists($name, $this->properties)) { return $this->properties[$name]; } } function setProperty($name, $value) { $this->properties[$name] = $value; } function getCity() { if (array_key_exists('city', $this->properties)) { return $this->properties['city']; } } function getState() { if (array_key_exists('state', $this->properties)) { return $this->properties['state']; } } function getCountry() { if (array_key_exists('country', $this->properties)) { return $this->properties['country']; } } function getCountryCode() { if (array_key_exists('country_code', $this->properties)) { return $this->properties['country_code']; } } function getLatitude() { if (array_key_exists('latitude', $this->properties)) { return $this->properties['latitude']; } } function getLongitude() { if (array_key_exists('longitude', $this->properties)) { return $this->properties['longitude']; } } function generateId($country = '', $state = '', $city = '') { if ( ! $country ) { $country = $this->getCountry(); } if ( ! $state ) { $state = $this->getState(); } if ( ! $city ) { $city = $this->getCity(); } $id_string = trim( strtolower($country)) . trim( strtolower($state)) . trim( strtolower($city)); return owa_lib::setStringGuid( $id_string ); } } ?> |