* Sub-Ajax page, requires AJAX_INCLUDE */ if (!defined('AJAX_INCLUDE')) { exit; } $results = array(); switch ($_REQUEST['action']) { case 'geolocation': if (AmpConfig::get('geolocation')) { if ($GLOBALS['user']->id) { $latitude = floatval($_REQUEST['latitude']); $longitude = floatval($_REQUEST['longitude']); $name = $_REQUEST['name']; if (empty($name)) { // First try to get from local cache (avoid external api requests) $name = Stats::get_cached_place_name($latitude, $longitude); if (empty($name)) { foreach (Plugin::get_plugins('get_location_name') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $name = $plugin->_plugin->get_location_name($latitude, $longitude); if (!empty($name)) { break; } } } } } // Better to check for bugged values here and keep previous user good location // Someone listing music at 0.0,0.0 location would need a waterproof music player btw if ($latitude > 0 && $longitude > 0) {
/** * get_recently_played * This function returns the last X songs that have been played * it uses the popular threshold to figure out how many to pull * it will only return unique object * @param int $user_id * @return array */ public static function get_recently_played($user_id = 0) { $user_id = intval($user_id); $sql = "SELECT `object_id`, `user`, `object_type`, `date`, `agent`, `geo_latitude`, `geo_longitude`, `geo_name` " . "FROM `object_count` WHERE `object_type` = 'song' AND `count_type` = 'stream' "; if (AmpConfig::get('catalog_disable')) { $sql .= "AND " . Catalog::get_enable_filter('song', '`object_id`') . " "; } if ($user_id) { // If user is not empty, we're looking directly to user personal info (admin view) $sql .= "AND `user`='{$user_id}' "; } else { if (!Access::check('interface', '100')) { // If user identifier is empty, we need to retrieve only users which have allowed view of personnal info $personal_info_id = Preference::id_from_name('allow_personal_info_recent'); if ($personal_info_id) { $current_user = $GLOBALS['user']->id; $sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='{$personal_info_id}' AND `value`='1') OR `user`='{$current_user}') "; } } } $sql .= "ORDER BY `date` DESC "; $db_results = Dba::read($sql); $results = array(); while ($row = Dba::fetch_assoc($db_results)) { if (empty($row['geo_name']) && $row['latitude'] && $row['longitude']) { $row['geo_name'] = Stats::get_cached_place_name($row['latitude'], $row['longitude']); } $results[] = $row; if (count($results) >= AmpConfig::get('popular_threshold')) { break; } } return $results; }