git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit fe161892 authored by P. J. McDermott's avatar P. J. McDermott

Clean up code in Nixtape views.

Changes include:
  - Correct braces around conditional and loop constructs, enforcing the
    one true brace style.
  - Fix cases where spaces were used for indentation.
  - Fix incorrect indentation.
  - Delete whitespace at the ends of lines.
  - Delete stray whitespace in the middle of lines.
  - Change double quotes to single quotes where escape sequences and
    variable substitutions are not used.
  - Fix some letter casing in symbol names (e.g. "Exception" instead of
    "exception").
These changes make the codebase more consistent and compliant with the
coding standard.
parent 714a6aaf
......@@ -41,8 +41,7 @@ function sendEmail($email) {
try {
$adodb->Execute($sql);
}
catch (exception $e) {
} catch (Exception $e) {
die($e->getMessage());
}
......
......@@ -32,7 +32,7 @@ try {
die();
}
if(!isset($this_user) || !$this_user->manages($artist->name)) {
if (!isset($this_user) || !$this_user->manages($artist->name)) {
$smarty->assign('pageheading', 'Permission denied');
$smarty->assign('error', 'You don\'t have permission to edit this artist\'s details.');
$smarty->display('error.tpl');
......@@ -51,15 +51,15 @@ if (isset($_POST['submit'])) {
if (empty($_POST['image'])) {
$image = '';
} elseif (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['image'])) {
} else if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['image'])) {
$errors[] = 'Cover image must be a valid URL';
} elseif (preg_match('/\s/', $_POST['homepage'])) {
} else if (preg_match('/\s/', $_POST['homepage'])) {
$errors[] = 'Cover image must be a URL, as such it cannot contain whitespace.';
} else {
$image = $_POST['image'];
}
if($errors) {
if ($errors) {
$smarty->assign('errors', $errors);
$smarty->assign('image', $image);
$smarty->assign('name', $_POST['name']);
......
......@@ -45,16 +45,16 @@ if ($aAlbumTracks) {
$smarty->assign('tracks', $aAlbumTracks);
}
if(isset($this_user) && $this_user->manages($artist->name)) {
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('add_track_link', $album->getAddTrackURL());
}
$smarty->assign('extra_head_links', array(
array(
'rel' => 'meta',
'type' => 'application/rdf+xml' ,
'type' => 'application/rdf+xml',
'title' => 'Album Metadata',
'href' => $base_url.'/rdf.php?fmt=xml&page='.urlencode(htmlentities(str_replace($base_url, '', $album->getURL())))
'href' => $base_url . '/rdf.php?fmt=xml&page=' . urlencode(htmlentities(str_replace($base_url, '', $album->getURL())))
)
));
......
......@@ -27,14 +27,14 @@ require_once('data/TagCloud.php');
try {
$artist = new Artist(urldecode($_GET['artist']));
} catch (exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist '.($_GET['artist']).' was not found in the database.');
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if(!isset($this_user) || !$this_user->manages($artist->name)) {
if (!isset($this_user) || !$this_user->manages($artist->name)) {
$smarty->assign('pageheading', 'Permission denied');
$smarty->assign('error', 'You don\'t have permission to edit this artist\'s details.');
$smarty->display('error.tpl');
......@@ -46,7 +46,7 @@ if (isset($_POST['submit'])) {
$artist->setBiography($_POST['bio_content']);
if (!empty($_POST['homepage']) && !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['homepage'])) {
$errors[] = 'Home page must be a valid URL';
} elseif (!empty($_POST['homepage']) && preg_match('/\s/', $_POST['homepage'])) {
} else if (!empty($_POST['homepage']) && preg_match('/\s/', $_POST['homepage'])) {
$errors[] = 'Home page must be a URL, as such it cannot contain whitespace.';
} else {
$artist->setHomepage($_POST['homepage']);
......@@ -54,15 +54,15 @@ if (isset($_POST['submit'])) {
if (!empty($_POST['image']) && !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['image'])) {
$errors[] = 'Image must be a valid URL';
} elseif (!empty($_POST['image']) && preg_match('/\s/', $_POST['image'])) {
} else if (!empty($_POST['image']) && preg_match('/\s/', $_POST['image'])) {
$errors[] = 'Image must be a URL, as such it cannot contain whitespace.';
} else {
$artist->setImage($_POST['image']);
}
$artist->setFlattr($_POST['flattr_uid']);
if($errors) {
if ($errors) {
$smarty->assign('errors', $errors);
} else {
// If the editing was successful send the user back to the view page
......@@ -79,4 +79,4 @@ $smarty->assign('image', $artist->image_medium);
$smarty->assign('flattr_uid', $artist->flattr_uid);
$smarty->assign('pageheading', 'Managing ' . $artist->name);
$smarty->display("artist-manage.tpl");
$smarty->display('artist-manage.tpl');
......@@ -26,7 +26,7 @@ require_once('data/Server.php');
require_once('data/TagCloud.php');
require_once('artist-menu.php');
if($logged_in == false) {
if ($logged_in == false) {
$smarty->assign('pageheading', 'Log in required');
$smarty->assign('details', 'You need to log in to tag artists.');
$smarty->display('error.tpl');
......@@ -35,9 +35,9 @@ if($logged_in == false) {
try {
$artist = new Artist(urldecode($_GET['artist']));
} catch (exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist '.($_GET['artist']).' was not found in the database.');
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
......@@ -49,10 +49,10 @@ if ($_POST['tag']) {
$smarty->assign('name', $artist->name);
$smarty->assign('pagetitle', $artist->name);
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, $artist->name, "artist");
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, $artist->name, 'artist');
$smarty->assign('tagcloud', $tagCloud);
} catch (exception $ex) {
} catch (Exception $e) {
$tagCloud = array();
}
......@@ -62,4 +62,4 @@ $submenu = artist_menu($artist, 'Tag');
$smarty->assign('submenu', $submenu);
$smarty->assign('headerfile', 'artist-header.tpl');
$smarty->display("artist-tag.tpl");
$smarty->display('artist-tag.tpl');
......@@ -28,15 +28,15 @@ require_once('artist-menu.php');
try {
$artist = new Artist(urldecode($_GET['artist']));
} catch (exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist '.($_GET['artist']).' was not found in the database.');
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
$station = 'librefm://artist/' . $artist->name;
if(isset($this_user)) {
if (isset($this_user)) {
$radio_session = $this_user->getRadioSession($station);
} else {
$radio_session = Server::getRadioSession($station);
......@@ -61,15 +61,15 @@ if ($aArtistAlbums) {
$smarty->assign('albums', $aArtistAlbums);
}
if(isset($this_user) && $this_user->manages($artist->name)) {
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('manage_link', $artist->getManagementURL());
$smarty->assign('add_album_link', $artist->getAddAlbumURL());
}
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, $artist->name, "artist");
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, $artist->name, 'artist');
$smarty->assign('tagcloud', $tagCloud);
} catch (exception $ex) {
} catch (Exception $ex) {
$tagCloud = array();
}
......@@ -77,4 +77,4 @@ $submenu = artist_menu($artist, 'Overview');
$smarty->assign('submenu', $submenu);
$smarty->assign('headerfile', 'artist-header.tpl');
$smarty->display("artist.tpl");
$smarty->display('artist.tpl');
......@@ -24,18 +24,17 @@ require_once('data/User.php');
require_once($install_path . '/temp-utils.php'); // this is extremely dodgy and shameful
session_start();
if(isset($_COOKIE['session_id'])) {
if (isset($_COOKIE['session_id'])) {
$err = 0;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
try {
$row = $adodb->GetRow('SELECT userid FROM Scrobble_Sessions WHERE '
. 'sessionid = ' . $adodb->qstr($_COOKIE['session_id'])
. ' AND expires > ' . (int)(time()));
}
catch (exception $e) {
} catch (Exception $e) {
$err = 1;
}
if($err || !$row) {
if ($err || !$row) {
// Session is invalid
setcookie('session_id', '', time() - 3600);
session_unset();
......
......@@ -20,7 +20,7 @@
*/
if(!file_exists(dirname(__FILE__) . '/config.php')) {
if (!file_exists(dirname(__FILE__) . '/config.php')) {
die('Please run the <a href=\'install.php\'>Install</a> script to configure your installation');
}
......@@ -30,7 +30,7 @@ require_once('adodb/adodb.inc.php');
try {
$adodb =& NewADOConnection($connect_string);
} catch (exception $e) {
} catch (Exception $e) {
var_dump($e);
adodb_backtrace($e->gettrace());
}
......
......@@ -27,44 +27,43 @@ if ($logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Not logged in! You shouldn\'t be here!');
$smarty->display('error.tpl');
die ();
} elseif ( isset ($_GET['code'])) {
die();
} else if (isset($_GET['code'])) {
$adodb->Execute('DELETE FROM Delete_Request WHERE expires < ' . (int)(time()));
$username = $this_user->name;
$code = $_GET['code'];
try {
$res = $adodb->GetRow('SELECT * FROM Delete_Request WHERE username = ' . $adodb->qstr($username) . ' AND code = ' . $adodb->qstr($code));
}
catch (exception $e) {
try {
$res = $adodb->GetRow('SELECT * FROM Delete_Request WHERE username = ' . $adodb->qstr($username) . ' AND code = ' . $adodb->qstr($code));
} catch (Exception $e) {
exit;
}
if (!$res) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Invalid code.');
$smarty->display('error.tpl');
die ();
die();
} else {
try {
$adodb->Execute('DELETE FROM Scrobble_Sessions WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Delete_Request WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Auth WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Group_Members WHERE member = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Radio_Sessions WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Recovery_Request WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Scrobbles WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationship_Flags WHERE uid1 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationship_Flags WHERE uid2 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationships WHERE uid1 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationships WHERE uid2 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Banned_Tracks WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Loved_Tracks WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Users WHERE uniqueid = ' . $this_user->uniqueid);
} catch (exception $e) {
$adodb->Execute('DELETE FROM Scrobble_Sessions WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Delete_Request WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Auth WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Group_Members WHERE member = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Radio_Sessions WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Recovery_Request WHERE username = ' . $adodb->qstr($username));
$adodb->Execute('DELETE FROM Scrobbles WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationship_Flags WHERE uid1 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationship_Flags WHERE uid2 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationships WHERE uid1 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM User_Relationships WHERE uid2 = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Banned_Tracks WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Loved_Tracks WHERE userid = ' . $this_user->uniqueid);
$adodb->Execute('DELETE FROM Users WHERE uniqueid = ' . $this_user->uniqueid);
} catch (Exception $e) {
$smarty->assign('error', 'Error!');
$smarty->assign('details', 'Something went amiss.');
$smarty->display('error.tpl');
die ();
die();
}
session_destroy();
$smarty->display('account-deleted.tpl');
......@@ -74,7 +73,7 @@ catch (exception $e) {
$username = $this_user->name;
$email = $this_user->email;
$expire = time()+86400;
$adodb->Execute('INSERT INTO Delete_Request (code, expires, username) VALUES (' . $adodb->qstr($code) . ', ' . $adodb->qstr($expire) . "," . $adodb->qstr($username) . ')');
$adodb->Execute('INSERT INTO Delete_Request (code, expires, username) VALUES (' . $adodb->qstr($code) . ', ' . $adodb->qstr($expire) . ',' . $adodb->qstr($username) . ')');
$url = $base_url . '/delete-profile.php?code=' . $code;
$content = "Hi!\n\nSomeone from the IP address " . $_SERVER['REMOTE_ADDR'] . " requested account deletion at libre.fm. To remove this account click: \n\n" . $url . "\n\n- The Libre.fm Team";
$headers = 'From: Libre.fm <account@libre.fm>';
......
......@@ -25,21 +25,18 @@ require_once('data/User.php');
require_once('data/Group.php');
require_once('data/TagCloud.php');
if($logged_in == false)
{
if ($logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Not logged in! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
}
if ($_REQUEST['group']=='new')
{
if ($_REQUEST['new'])
{
if ($_REQUEST['group']=='new') {
if ($_REQUEST['new']) {
try {
$result = Group::create(strtolower($_REQUEST['new']), $this_user);
} catch (exception $e) {
} catch (Exception $e) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', $e->getMessage());
$smarty->display('error.tpl');
......@@ -49,14 +46,12 @@ if ($_REQUEST['group']=='new')
header('Location: ' . $base_url . '/edit_group.php?group=' . $_REQUEST['new']);
exit();
}
}
else
{
} else {
$smarty->assign('newform', true);
try {
$aTagCloud = TagCloud::GenerateTagCloud(TagCloud::scrobblesTable(), 'artist');
$smarty->assign('tagcloud', $aTagCloud);
} catch (exception $e) {}
} catch (Exception $e) {}
$smarty->display('edit_group.tpl');
exit();
}
......@@ -64,8 +59,7 @@ if ($_REQUEST['group']=='new')
$group = new Group($_REQUEST['group']);
if ($group->owner->name != $this_user->name)
{
if ($group->owner->name != $this_user->name) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'You don\'t own this group!');
$smarty->display('error.tpl');
......@@ -74,32 +68,31 @@ if ($group->owner->name != $this_user->name)
$errors = array();
if ($_POST['submit'])
{
if (!empty($_POST['homepage']))
{
if ($_POST['submit']) {
if (!empty($_POST['homepage'])) {
# Need better URI validation, but this will do for now. I think
# PEAR has a suitable module to help out here.
if ( !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['homepage']) )
if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['homepage'])) {
$errors[] = 'Homepage must be a URI.';
if ( preg_match('/\s/', $_POST['homepage']) )
}
if (preg_match('/\s/', $_POST['homepage'])) {
$errors[] = 'Homepage must be a URI. Valid URIs cannot contain whitespace.';
}
}
if (!empty($_POST['avatar_uri']))
{
if (!empty($_POST['avatar_uri'])) {
# Need better URI validation, but this will do for now. I think
# PEAR has a suitable module to help out here.
if ( !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['avatar_uri']) )
if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['avatar_uri'])) {
$errors[] = 'Avatar must be a URI.';
if ( preg_match('/\s/', $_POST['avatar_uri']) )
}
if (preg_match('/\s/', $_POST['avatar_uri'])) {
$errors[] = 'Avatar must be a URI. Valid URIs cannot contain whitespace.';
}
}
if (!isset($errors[0]))
{
if ($_POST['owner'] != $group->owner->username)
{
if (!isset($errors[0])) {
if ($_POST['owner'] != $group->owner->username) {
try {
$new_owner = new User($_POST['owner']);
} catch (Exception $e) {
......@@ -109,15 +102,12 @@ if ($_POST['submit'])
die();
}
if (! $group->memberCheck($new_owner))
{
if (!$group->memberCheck($new_owner)) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Cannot assign group ownership to someone who is not a member!');
$smarty->display('error.tpl');
die();
}
else
{
} else {
$group->owner = $new_owner;
}
}
......@@ -133,28 +123,23 @@ if ($_POST['submit'])
exit;
}
if (isset($errors[0]))
{
if (isset($errors[0])) {
header('Content-Type: text/plain');
//($errors);
exit;
}
}
if(isset($group->name))
{
if (isset($group->name)) {
# Stuff which cannot be changed.
$smarty->assign('group', $group->name);
if ($_POST['submit'])
{
if ($_POST['submit']) {
$smarty->assign('fullname', $_POST['fullname']);
$smarty->assign('bio', $_POST['bio']);
$smarty->assign('homepage', $_POST['homepage']);
$smarty->assign('avatar_uri', $_POST['avatar_uri']);
}
else
{
} else {
$smarty->assign('fullname', $group->fullname);
$smarty->assign('bio', $group->bio);
$smarty->assign('homepage', $group->homepage);
......@@ -170,12 +155,9 @@ if(isset($group->name))
try {
$aUserTagCloud = $group->tagCloudData();
$smarty->assign('tagcloud', $aTagCloud);
} catch (exception $e) {}
} catch (Exception $e) {}
$smarty->display('edit_group.tpl');
}
else
{
} else {
$smarty->assign('pageheading', 'Group not found');
$smarty->assign('details', 'Shall I call in a missing peoples report? This shouldn\'t happen.');
$smarty->display('error.tpl');
......
......@@ -28,13 +28,13 @@ require_once('data/TagCloud.php');
// This should be contextual based on the mode= parameter?
try {
$aTagCloud = TagCloud::GenerateTagCloud(TagCloud::scrobblesTable(), 'artist');
$smarty->assign('tagcloud', $aTagCloud);
} catch (exception $e) {}
$aTagCloud = TagCloud::GenerateTagCloud(TagCloud::scrobblesTable(), 'artist');
$smarty->assign('tagcloud', $aTagCloud);
} catch (Exception $e) {}
$aTopArtists = Server::getTopArtists(20);
if (!PEAR::isError ($aTopArtists)) {
$smarty->assign('topartists', $aTopArtists);
$smarty->assign('topartists', $aTopArtists);
}
$smarty->assign('explore', true);
$smarty->display('explore-artists.tpl');
......@@ -27,8 +27,8 @@ require_once('data/TagCloud.php');
try {
$aTagCloud = TagCloud::GenerateTagCloud('loved_tracks', 'artist');
$smarty->assign('tagcloud', $aTagCloud);
} catch(Exception $ex) {
$smarty->assign('tagcloud', $aTagCloud);
} catch(Exception $e) {
// Installation doesn't have any loved tracks yet
}
......
......@@ -24,7 +24,7 @@ require_once('adodb/adodb.inc.php');
require_once('version.php');
require_once('utils/get_absolute_url.php');
if(file_exists('config.php')) {
if (file_exists('config.php')) {
die('A configuration file already exists. Please delete <i>config.php</i> if you wish to reinstall.');
}
......@@ -32,20 +32,19 @@ if (isset($_POST['install'])) {
//Get the database connection string
$dbms = $_POST['dbms'];
if($dbms == 'sqlite') {
if ($dbms == 'sqlite') {
$filename = urlencode($_POST['filename']);
$connect_string = 'sqlite://' . $filename;
} else {
$connect_string = $dbms . '://' . $_POST['username'] . ':' . $_POST['password'] . '@' . $_POST['hostname'] . ':' . $_POST['port'] . '/' . $_POST['dbname'];
}
$adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string );
$adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string);
// Check the connection
try {
$adodb =& NewADOConnection($connect_string);
}
catch (exception $e) {
} catch (Exception $e) {
die($e->getMessage());
}
$adodb->Close();
......@@ -55,7 +54,7 @@ if (isset($_POST['install'])) {
$default_theme = $_POST['default_theme'];
$base_url = $_POST['base_url'];
if($base_url[strlen($base_url)-1] === '/') {
if ($base_url[strlen($base_url)-1] === '/') {
$base_url = substr($base_url, 0, -1);
}
......@@ -68,7 +67,7 @@ if (isset($_POST['install'])) {
$result = fwrite($conf_file, $config);
fclose($conf_file);
if(!$result) {
if (!$result) {
$print_config = str_replace('<', '&lt;', $config);
die('Unable to write to file \'<i>config.php</i>\'. Please create this file and copy the following in to it: <br /><pre>' . $print_config . '</pre>');
}
......@@ -119,8 +118,8 @@ if (isset($_POST['install'])) {
Default Theme: <select name="default_theme">
<?php
$dir = opendir('themes');
while($theme = readdir($dir)) {
if(is_dir('themes/' . $theme) && $theme[0] != '.') {
while ($theme = readdir($dir)) {
if (is_dir('themes/' . $theme) && $theme[0] != '.') {
echo '<option>' . $theme . '</option>';
}
}
......
......@@ -22,14 +22,14 @@
require_once('database.php');
require_once('templating.php');
if(isset($_GET['tag'])) {
if (isset($_GET['tag'])) {
$station = 'librefm://globaltags/' . $_GET['tag'];
} else if(isset($_GET['station'])) {
} else if (isset($_GET['station'])) {
$station = $_GET['station'];
}
if(isset($station)) {
if(isset($this_user)) {
if (isset($station)) {
if (isset($this_user)) {
$radio_session = $this_user->getRadioSession($station);
} else {
$radio_session = Server::getRadioSession($station);
......
......@@ -25,15 +25,15 @@ require_once('data/sanitize.php');
require_once('data/Server.php');
require_once('data/User.php');
if ( strtolower(substr($connect_string, 0, 5)) == 'mysql' )
if (strtolower(substr($connect_string, 0, 5)) == 'mysql') {
$random = 'RAND';
elseif ( strtolower(substr($connect_string, 0, 5)) == 'mssql' )
} else if (strtolower(substr($connect_string, 0, 5)) == 'mssql') {
$random = 'NEWID'; // I don't think we try to support MSSQL, but here's how it's done theoretically anyway
else
} else {
$random = 'RANDOM'; // postgresql, sqlite, possibly others
}
if ($_REQUEST['country'])
{
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',
$adodb->qstr(strtoupper($_REQUEST['country'])),
$random);
......@@ -41,7 +41,7 @@ if ($_REQUEST['country'])
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->GetAll($q);
foreach($res as &$row) {
foreach ($res as &$row) {
try {
$userlist[] = new User($row['username'], $row);
} catch (Exception $e) {}
......@@ -50,7 +50,7 @@ if ($_REQUEST['country'])
$smarty->assign('country', strtoupper($_REQUEST['country']));
$row = $adodb->GetRow(sprintf('SELECT * FROM Countries WHERE country=%s LIMIT 1',
$adodb->qstr(strtoupper($_REQUEST['country']))));
if ( $row ) {
if ($row) {
$smarty->assign('country_info', $row);
}
......@@ -58,18 +58,15 @@ if ($_REQUEST['country'])
$smarty->assign('extra_head_links', array(
array(
'rel' => 'meta',
'type' => 'application/rdf+xml' ,
'rel' => 'meta',
'type' => 'application/rdf+xml',
'title' => 'FOAF',
'href' => $base_url.'/rdf.php?fmt=xml&page='.urlencode(str_replace($base_url, '', $_SERVER['REQUEST_URI']))
'href' => $base_url . '/rdf.php?fmt=xml&page=' . urlencode(str_replace($base_url, '', $_SERVER['REQUEST_URI']))
)
));
$smarty->display('location-country.tpl');
}
else
{
} else {
$smarty->assign('pageheading', 'Location not found');
$smarty->assign('details', 'Shall I call in a missing locations report?');
$smarty->display('error.tpl');
......
......@@ -23,44 +23,43 @@ require_once('database.php');
require_once('templating.php');
require_once($install_path . '/data/User.php');
if(isset($_COOKIE['session_id']) && $_GET['action'] == 'logout') {
if (isset($_COOKIE['session_id']) && $_GET['action'] == 'logout') {
setcookie('session_id', '', time() - 3600);
header('Location: index.php');
}
if(isset($_POST['login'])) {
if (isset($_POST['login'])) {
$errors = '';
$username = $_POST['username'];
$password = $_POST['password'];
$remember = $_POST['remember'];
if(empty($username)) {
if (empty($username)) {
$errors .= 'You must enter a username.<br />';
}
if(empty($errors)) {
if (empty($errors)) {
try {
$sql = 'SELECT uniqueid, active FROM Users WHERE '
. ' lower(username) = ' . $adodb->qstr(strtolower($username))
. ' AND password = ' . $adodb->qstr(md5($password));
. ' AND password = ' . $adodb->qstr(md5($password));
$row = $adodb->GetRow($sql);
$userid = $row['uniqueid'];
$active = $row['active'];
}
catch (exception $e) {
} catch (Exception $e) {
$errors .= 'A database error happened.';
}
if(!$userid) {
if (!$userid) {
$errors .= 'Invalid username or password. Would you like to <a href="' . $base_url . '/reset.php">recover your password?</a>';
$smarty->assign('invalid', true);
} elseif (!$active) {
} else if (!$active) {
$errors .= 'This account hasn\'t been activated. Please follow the link in the e-mail you received when you signed up to activate your account.</a>';
$smarty->assign('invalid', true);
} else {
// Give the user a session id, like any other client
$session_id = md5(md5($password) . time());
if(isset($remember)){
if (isset($remember)) {
$session_time = time() + 31536000; // 1 year
} else {
$session_time = time() + 86400; // 1 day
......@@ -76,16 +75,15 @@ if(isset($_POST['login'])) {
}