We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

location.php 2.52 KB
Newer Older
tobyink's avatar
tobyink committed
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
<?php

/* Libre.fm -- a free network service for sharing your music listening habits

   Copyright (C) 2009 Libre.fm Project

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

require_once('database.php');
require_once('templating.php');
require_once('data/sanitize.php');
require_once('data/Server.php');
require_once('data/User.php');

if ( strtolower(substr($mdb2->phptype, 0, 5)) == 'mysql'  )
	$random = 'RAND';
elseif ( strtolower(substr($mdb2->phptype, 0, 5)) == 'mssql'  )
	$random = 'NEWID';  // I don't think we try to support MSSQL, but here's how it's done theoretically anyway
else
	$random = 'RANDOM';  // postgresql, sqlite, possibly others
	
if ($_REQUEST['country'])
{
	$q = sprintf("SELECT u.* FROM Users u INNER JOIN Places p ON u.location_uri=p.location_uri AND p.country=%s ORDER BY %s() LIMIT 100",
		$mdb2->quote(strtoupper($_REQUEST['country']), 'text'),
		$random);
	
	$res = $mdb2->query($q);
	
	while ( $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )
	{
		$userlist[] = new User($row['username'], $row);
46 47 48 49 50 51 52
		
		/* This is a joke. Someone can remove it later if they like. */
		if (($_SESSION['user']->name == 'kabniel'||$_SESSION['user']->name == 'tobyink')
		&& $row['username'] == 'kabniel')
			for ($i = 0; $i < 99; $i++)
				$userlist[] = new User($row['username'], $row);
		/* End of joke. */
tobyink's avatar
tobyink committed
53 54
	}
	
tobyink's avatar
start  
tobyink committed
55 56 57 58 59 60 61 62 63 64 65 66
	// We really need $country_name too! TODO: add Countries(code, name, wikilink) table.
	$smarty->assign('country', $_REQUEST['country']);
	
	$smarty->assign('userlist', $userlist);
	
	$smarty->assign('extra_head_links', array(
			array(
				'rel' => 'meta',
				'type' => 'application/rdf+xml' ,
				'title' => 'FOAF',
				'href' => $base_url.'/rdf.php?fmt=xml&page='.htmlentities($_SERVER['REQUEST_URI'])
				)
tobyink's avatar
Fix  
tobyink committed
67
		));
tobyink's avatar
start  
tobyink committed
68 69 70 71 72 73 74 75 76
		
	$smarty->display('location-country.tpl');
}

else
{
	$smarty->assign('error', 'Location not found');
	$smarty->assign('details', 'Shall I call in a missing locations report?');
	$smarty->display('error.tpl');
tobyink's avatar
tobyink committed
77
}