/** * Encode a location into a latitude and longitude, caching the result. * * Works by triggering the 'geocode' 'location' plugin * hook, and requires a geocoding plugin to be installed. * * @param string $location The location, e.g. "London", or "24 Foobar Street, Gotham City" * @return string|false */ function elgg_geocode_location($location) { global $CONFIG; if (is_array($location)) { return false; } $location = sanitise_string($location); // Look for cached version $query = "SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='{$location}'"; $cached_location = get_data_row($query); if ($cached_location) { return array('lat' => $cached_location->lat, 'long' => $cached_location->long); } // Trigger geocode event if not cached $return = false; $return = elgg_trigger_plugin_hook('geocode', 'location', array('location' => $location), $return); // If returned, cache and return value if ($return && is_array($return)) { $lat = (double) $return['lat']; $long = (double) $return['long']; // Put into cache at the end of the page since we don't really care that much $query = "INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache " . " (location, lat, `long`) VALUES ('{$location}', '{$lat}', '{$long}')" . " ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"; execute_delayed_write_query($query); } return $return; }
/** * Encode a location into a latitude and longitude, caching the result. * * Works by triggering the 'geocode' 'location' plugin hook, and requires a geocoding module to be installed * activated in order to work. * * @param String $location The location, e.g. "London", or "24 Foobar Street, Gotham City" */ function elgg_geocode_location($location) { global $CONFIG; // Handle cases where we are passed an array (shouldn't be but can happen if location is a tag field) if (is_array($location)) { $location = implode(', ', $location); } $location = sanitise_string($location); // Look for cached version $cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='{$location}'"); if ($cached_location) { return array('lat' => $cached_location->lat, 'long' => $cached_location->long); } // Trigger geocode event if not cached $return = false; $return = trigger_plugin_hook('geocode', 'location', array('location' => $location), $return); // If returned, cache and return value if ($return && is_array($return)) { $lat = (double) $return['lat']; $long = (double) $return['long']; // Put into cache at the end of the page since we don't really care that much execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (location, lat, `long`) VALUES ('{$location}', '{$lat}', '{$long}') ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"); } return $return; }
/** * Encode a location into a latitude and longitude, caching the result. * * Works by triggering the 'geocode' 'location' plugin hook, and requires a geocoding module to be installed * activated in order to work. * * @param String $location The location, e.g. "London", or "24 Foobar Street, Gotham City" */ function elgg_geocode_location($location) { global $CONFIG; $location = sanitise_string($location); // Look for cached version $cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='{$location}'"); // Trigger geocode event $return = false; $return = trigger_plugin_hook('geocode', 'location', array('location' => $location, $return)); // If returned, cache and return value if ($return && is_array($return)) { $lat = (int) $return['lat']; $long = (int) $return['long']; // Put into cache at the end of the page since we don't really care that much execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (lat, long) VALUES ({$lat}, {$long}) ON DUPLICATE KEY UPDATE lat={$lat} long={$long}"); } return $return; }
/** * Sets the last logon time of the given user to right now. * * @param int $user_guid The user GUID */ function set_last_login($user_guid) { $user_guid = (int) $user_guid; global $CONFIG; $time = time(); execute_delayed_write_query("UPDATE {$CONFIG->dbprefix}users_entity set prev_last_login = last_login, last_login = {$time} where guid = {$user_guid}"); }
/** * Sets the last logon time of the given user to right now. * * @param int $user_guid The user GUID * * @return void */ function setLastLogin($user_guid) { $user_guid = (int) $user_guid; $time = time(); $query = "UPDATE {$this->CONFIG->dbprefix}users_entity\n\t\t\tset prev_last_login = last_login, last_login = {$time} where guid = {$user_guid}"; execute_delayed_write_query($query); }
/** * Sets the last logon time of the given user to right now. * * @param ElggUser $user User entity * @return void */ public function setLastLogin(ElggUser $user) { $time = $this->getCurrentTime()->getTimestamp(); if ($user->last_login == $time) { // no change required return; } $query = "\n\t\t\tUPDATE {$this->table}\n\t\t\tSET\n\t\t\t\tprev_last_login = last_login,\n\t\t\t\tlast_login = :last_login\n\t\t\tWHERE guid = :guid\n\t\t"; $params = [':last_login' => $time, ':guid' => (int) $user->guid]; $user->prev_last_login = $user->last_login; $user->last_login = $time; execute_delayed_write_query($query, null, $params); $this->entity_cache->set($user); // If we save the user to memcache during this request, then we'll end up with the // old (incorrect) attributes cached. Hence we want to invalidate as late as possible. // the user object gets saved register_shutdown_function(function () use($user) { $user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache')); }); }
/** * Log a system event related to a specific object. * * This is called by the event system and should not be called directly. * * @param object $object The object you're talking about. * @param string $event The event being logged * @return void */ function system_log($object, $event) { global $CONFIG; static $log_cache; static $cache_size = 0; if ($object instanceof Loggable) { /* @var \ElggEntity|\ElggExtender $object */ if (elgg_get_config('version') < 2012012000) { // this is a site that doesn't have the ip_address column yet return; } // reset cache if it has grown too large if (!is_array($log_cache) || $cache_size > 500) { $log_cache = array(); $cache_size = 0; } // Has loggable interface, extract the necessary information and store $object_id = (int) $object->getSystemLogID(); $object_class = get_class($object); $object_type = $object->getType(); $object_subtype = $object->getSubtype(); $event = sanitise_string($event); $time = time(); $ip_address = sanitize_string(_elgg_services()->request->getClientIp()); if (!$ip_address) { $ip_address = '0.0.0.0'; } $performed_by = elgg_get_logged_in_user_guid(); if (isset($object->access_id)) { $access_id = $object->access_id; } else { $access_id = ACCESS_PUBLIC; } if (isset($object->enabled)) { $enabled = $object->enabled; } else { $enabled = 'yes'; } if (isset($object->owner_guid)) { $owner_guid = $object->owner_guid; } else { $owner_guid = 0; } // Create log if we haven't already created it if (!isset($log_cache[$time][$object_id][$event])) { $query = "INSERT into {$CONFIG->dbprefix}system_log\n\t\t\t\t(object_id, object_class, object_type, object_subtype, event,\n\t\t\t\tperformed_by_guid, owner_guid, access_id, enabled, time_created, ip_address)\n\t\t\tVALUES\n\t\t\t\t('{$object_id}','{$object_class}','{$object_type}', '{$object_subtype}', '{$event}',\n\t\t\t\t{$performed_by}, {$owner_guid}, {$access_id}, '{$enabled}', '{$time}', '{$ip_address}')"; execute_delayed_write_query($query); $log_cache[$time][$object_id][$event] = true; $cache_size += 1; } } }