Commit d66de2b3 authored by Jonas Haraldsson's avatar Jonas Haraldsson

Refactor error template stuff

parent e453b90a
......@@ -26,17 +26,13 @@ require_once('data/Album.php');
try {
$artist = new Artist($_GET['artist']);
} 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();
displayError("Artist not found",
"The artist {$_GET['artist']} was not found in the database.");
}
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');
die();
displayError("Permission denied",
"You don't have permission to edit this artist's details.");
}
$edit = false;
......@@ -46,10 +42,8 @@ if (isset($_GET['album'])) {
try {
$album = new Album($_GET['album'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Album not found",
"The album {$_GET['album']} by artist {$artist->name} was not found in the database.");
}
}
......
......@@ -36,20 +36,16 @@ try {
$album = new Album($_GET['album'], $_GET['artist']);
$smarty->assign('album', $album);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Album not found",
"The album {$_GET['album']} by artist {$_GET['artist']} was not found in the database");
}
try {
$artist = new Artist($album->artist_name);
$smarty->assign('artist', $artist);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Artist not found",
"The artist {$track->artist_name} was not found int he database");
}
if (isset($this_user) && $this_user->manages($artist->name)) {
......
......@@ -28,17 +28,11 @@ require_once('data/TagCloud.php');
try {
$artist = new Artist($_GET['artist']);
} 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();
displayError("Artist not found", "The artist {$_GET['artist']} was not found in the database.");
}
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');
die();
displayError("Permission denied", "You don't have permission to edit this artist's details.");
}
if (isset($_POST['submit'])) {
......
......@@ -37,10 +37,7 @@ try {
$artist = new Artist($_GET['artist']);
$smarty->assign(artist, $artist);
} 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();
displayError("Artist not found", "The artist {$_GET['artist']} was not found in the database");
}
if (isset($this_user) && $this_user->manages($artist->name)) {
......
......@@ -27,10 +27,7 @@ require_once('data/TagCloud.php');
require_once('artist-menu.php');
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');
die();
displayError("Log in required", "You need to log in to tag artists.");
}
if ($_POST['tag']) {
......
......@@ -24,10 +24,7 @@ require_once('data/User.php');
require_once('utils/random_code_generator.php');
if ($logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Not logged in! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "Not logged in. You shouldn't be here.")
} else if (isset($_GET['code'])) {
$adodb->Execute('DELETE FROM Delete_Request WHERE expires < ' . (int)(time()));
......@@ -39,10 +36,7 @@ if ($logged_in == false) {
exit;
}
if (!$res) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Invalid code.');
$smarty->display('error.tpl');
die();
displayError("Error", "Invalid code.");
} else {
try {
$adodb->Execute('DELETE FROM Scrobble_Sessions WHERE userid = ' . $this_user->uniqueid);
......@@ -61,10 +55,7 @@ if ($logged_in == false) {
$adodb->Execute('DELETE FROM Service_Connections 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();
displayError("Error", "Something went amiss.");
}
session_destroy();
$smarty->display('account-deleted.tpl');
......
......@@ -67,7 +67,5 @@ if ($_REQUEST['country']) {
$smarty->display('location-country.tpl');
} else {
$smarty->assign('pageheading', 'Location not found');
$smarty->assign('details', 'Shall I call in a missing locations report?');
$smarty->display('error.tpl');
displayError("Location not found", "Location not found, shall i call in a missing locations report?");
}
......@@ -38,10 +38,7 @@ if (isset($_GET['auth'])) {
try {
$row = $adodb->GetRow('SELECT * FROM AccountActivation WHERE authcode = ' . $adodb->qstr($authcode));
} catch (Exception $e) {
$errors = 'Unknown activationcode.';
$smarty->assign('errors', $errors);
$smarty->display('error.tpl');
die();
displayError("Error", "Unknown activation code.");
}
$sql_update = 'UPDATE Users SET active = 1 WHERE username = ' . $adodb->qstr($row['username']);
......@@ -50,12 +47,7 @@ if (isset($_GET['auth'])) {
$res = $adodb->Execute($sql_update);
$res = $adodb->Execute($sql_delete);
} catch (Exception $e) {
$errors = 'An error occurred.';
$details = $e->getMessage();
$smarty->assign('pageheading', $errors);
$smarty->assign('details', $details);
$smarty->display('error.tpl');
die();
displayError("Error", $e->getMessage());
}
$smarty->assign('activated', true);
}
......@@ -115,12 +107,7 @@ if (isset($_POST['register'])) {
$insert = $adodb->Execute($sql);
} catch (Exception $e) {
reportError('Create user, insert, register.php', $e->getMessage());
$errors .= 'An error occurred.';
$details = $e->getMessage();
$smarty->assign('pageheading', $errors);
$smarty->assign('details', $details);
$smarty->display('error.tpl');
die();
displayError("Error", $e->getMessage());
}
$code = md5($username . time());
......@@ -132,12 +119,7 @@ if (isset($_POST['register'])) {
$res = $adodb->Execute($sql);
} catch (Exception $e) {
reportError('AccountActivation, insert, register.php', $e->getMessage());
$errors .= 'An error occurred.';
$details = $e->getMessage();
$smarty->assign('pageheading', $errors);
$smarty->assign('details', $details);
$smarty->display('error.tpl');
die();
displayError("Error", $e->getMessage());
}
$url = $base_url . '/register.php?auth=' . $code;
......
......@@ -37,10 +37,7 @@ if (isset($_GET['code'])) {
. ' AND expires > ' . $adodb->qstr(time());
$row = $adodb->GetRow($sql);
if (!$row) {
$errors .= "Invalid reset token.\n";
$smarty->assign('errors', $errors);
$smarty->display('error.tpl');
die();
displayError("Error", "Invalid reset token.");
}
$password = '';
......@@ -81,10 +78,7 @@ if (isset($_GET['code'])) {
}
if ($err || !$row) {
$errors .= "User not found.\n";
$smarty->assign('details', $errors);
$smarty->display('error.tpl');
die();
displayError("Error", "User not found.");
}
$username = $row['username'];
$code = md5($username . $row['email'] . time());
......@@ -100,10 +94,7 @@ if (isset($_GET['code'])) {
$adodb->Execute($sql);
}
} catch (Exception $e) {
$errors .= 'Error on: ' . $sql;
$smarty->assign('details', $errors);
$smarty->display('error.tpl');
die();
displayError("Error", "Error on: {$sql}");
}
$sql = 'INSERT INTO Recovery_Request (username, email, code, expires) VALUES('
......@@ -115,10 +106,7 @@ if (isset($_GET['code'])) {
try {
$res = $adodb->Execute($sql);
} catch (Exception $e) {
$errors .= 'Error on: ' . $sql;
$smarty->assign('details', $errors);
$smarty->display('error.tpl');
die();
displayError("Error", "Error on: {$sql}");
}
$url = $base_url . '/reset.php?code=' . $code;
......@@ -131,11 +119,8 @@ if (isset($_GET['code'])) {
$status = sendEmail($content, $row['email']);
if (!$status) {
$errors = 'Error while trying to send email to: ' . $row['email'];
$errors .= '. Please try again later, or contact the site administrators.';
$smarty->assign('details', $errors);
$smarty->display('error.tpl');
die();
displayError("Error",
"Error while trying to send email to: {$row['email']}. Please try again later, or contact the site administrators.")
}
$smarty->assign('sent', true);
......
......@@ -26,10 +26,8 @@ require_once('data/Server.php');
require_once('data/TagCloud.php');
if (!isset($_GET['tag'])) {
$smarty->assign('pageheading', 'No tag specified');
$smarty->assign('details', 'You need to specify what tag you wish to view details for.');
$smarty->display('error.tpl');
die();
displayError("No tag specified",
"You need to specify what tag you wish to view details for.");
}
$tag = $_GET['tag'];
......@@ -39,10 +37,8 @@ try {
$tagCloud = TagCloud::generateTagCloud('tags', 'artist', 40, 'tag', $tag);
$smarty->assign('tagcloud', $tagCloud);
} catch (Exception $e) {
$smarty->assign('pageheading', 'No artists found');
$smarty->assign('details', 'No artists could be found that have been tagged with "' . $tag . '"');
$smarty->display('error.tpl');
die();
displayError("No artists found",
"No artists could be found that have been tagged with '{$tag}'");
}
$smarty->display('tag.tpl');
......@@ -18,9 +18,7 @@ try {
$aTagCloud = TagCloud::GenerateTagCloud('Free_Scrobbles', 'artist', $n);
$smarty->assign('tagcloud', $aTagCloud);
} catch (Exception $e) {
$smarty->assign('errors', $errors);
$smarty->display('error.tpl');
die();
displayError("Error", $errors);
}
$smarty->display('tagcloud.tpl');
......@@ -24,6 +24,15 @@ require_once('config.php');
require_once('auth.php');
require_once(SMARTY_DIR . 'Smarty.class.php');
function displayError($error_title, $error_message) {
global $smarty;
$smarty->assign('pagetitle', $error_title);
$smarty->assign('pageheading', $error_title); #librefm theme compat, may be removed after switch to BS3 theme
$smarty->assign('error_message', $error_message);
$smarty->display('error.tpl');
die();
}
if (isset($_GET['lang'])) {
$languages = array($_GET['lang'] . '.UTF-8');
setcookie('lang', $_GET['lang'] . '.UTF-8', time() + 31536000, '/');
......
{include file='header.tpl'}
{$details|escape:'htmlall'}
{if $default_theme != 'librefm'} {* librefm theme compat, may be removed after switch to BS3 theme *}
<h1>{$pagetitle}</h1>
{/if}
{$error_message|escape:'htmlall'}
{include file='footer.tpl'}
......@@ -30,26 +30,20 @@ require_once('utils/oggclass/ogg.class.php');
try {
$artist = new Artist($_GET['artist']);
} 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();
displayError("Artist not found",
"The artist {$_GET['artist']} was not found in the database.");
}
try {
$album = new Album($_GET['album'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Album not found",
"The album {$_GET['album']} by artist {$artist->name} was not found in the database.");
}
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');
die();
displayError("Permission denied",
"You don't have permission to edit this artist's details");
}
$edit = false;
......@@ -59,10 +53,8 @@ if (isset($_GET['track'])) {
try {
$track = new Track($_GET['track'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Track not found.');
$smarty->assign('details', 'The track ' . $_GET['track'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Track not found",
"The track {$_GET['track']} by artist {$artist->name} was not found in the database.");
}
}
......
......@@ -38,10 +38,8 @@ try {
$track = new Track($_GET['track'], $_GET['artist']);
$smarty->assign('track', $track);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Track not found.');
$smarty->assign('details', 'The track ' . $_GET['track'] . ' by artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Track not found",
"The track {$_GET['track']} by artist {$_GET['artist']} was not found in the database.");
}
try {
......@@ -53,10 +51,8 @@ try {
$artist = new Artist($track->artist_name);
$smarty->assign('artist', $artist);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
displayError("Artist not found",
"The artist {$track->artist_name} was not found in the database");
}
if (isset($this_user) && $this_user->manages($artist->name)) {
......
......@@ -25,10 +25,7 @@ require_once('data/TagCloud.php');
require_once('track-menu.php');
if ($logged_in == false) {
$smarty->assign('pageheading', 'Log in required');
$smarty->assign('details', 'You need to log in to tag tracks.');
$smarty->display('error.tpl');
die();
displayError("Log in required", "You need to log in to tag tracks.");
}
if($_POST['tag']) {
......
......@@ -26,10 +26,7 @@ require_once('data/User.php');
require_once('data/TagCloud.php');
if ($logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Not logged in! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "Not logged in. You shouldn't be here.");
}
if (isset($_POST['remote_gnufm_url'])) {
......@@ -59,10 +56,7 @@ if (isset($_GET['token']) && isset($_GET['webservice_url'])) {
}
}
} elseif (!$xmlresponse || (!isset($remote_username) || !isset($remote_key))) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Sorry, we weren\'t able to authenticate your account.');
$smarty->display('error.tpl');
die();
displayError("Error", "Sorry, we weren't able to authenticate your account.");
}
// Delete any old connection to this service
......
......@@ -26,10 +26,7 @@ require_once('data/User.php');
require_once('data/TagCloud.php');
if ($logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'Not logged in! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "Not logged in. You shouldn't be here.");
}
$errors = array();
......@@ -184,7 +181,5 @@ if (isset($this_user->name)) {
$smarty->assign('errors', $errors);
$smarty->display('user-edit.tpl');
} else {
$smarty->assign('pageheading', 'User not found');
$smarty->assign('details', 'Shall I call in a missing persons report? This shouldn\'t happen.');
$smarty->display('error.tpl');
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
......@@ -28,19 +28,13 @@ require_once('data/Server.php');
if (!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'User not set! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "User not set. You shouldn't be here.");
}
try {
$user = new User($_GET['user']);
} catch (Exception $e) {
$smarty->assign('pageheading', 'User not found');
$smarty->assign('details', 'Shall I call in a missing persons report?');
$smarty->display('error.tpl');
die();
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
$smarty->assign('geo', Server::getLocationDetails($user->location_uri));
......
......@@ -25,19 +25,13 @@ require_once('data/Album.php');
require_once('data/Track.php');
if (!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'User not set! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "User not set. You shouldn't be here.");
}
try {
$user = new User($_GET['user']);
} catch (Exception $e) {
$smarty->assign('pageheading', 'User not found');
$smarty->assign('details', 'Shall I call in a missing persons report?');
$smarty->display('error.tpl');
die();
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
$submenu = user_menu($user, 'Library');
......@@ -69,9 +63,7 @@ if ($page->section == 'music') {
try {
$page->getArtists();
} catch (Exception $e) {
$smarty->assign('details', $e->getMessage());
$smarty->display('error.tpl');
die();
displayError("Error", $e->getMessage());
}
$smarty->assign('page', $page);
$smarty->display('user-library-music.tpl');
......
......@@ -28,10 +28,7 @@ require_once('data/TagCloud.php');
require_once('data/Server.php');
if (!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'User not set! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "User not set. You shouldn't be here.");
}
try {
......@@ -41,7 +38,7 @@ try {
$user = new User($_GET['user']);
}
} catch (Exception $e) {
$error = 'User not found';
$user = null;
}
if (isset($user->name)) {
......@@ -103,7 +100,5 @@ if (isset($user->name)) {
$smarty->display('user-profile.tpl');
} else {
$smarty->assign('pageheading', $error);
$smarty->assign('details', 'Shall I call in a missing persons report?');
$smarty->display('error.tpl');
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
......@@ -28,10 +28,7 @@ require_once('data/TagCloud.php');
require_once('data/Server.php');
if (!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'User not set! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "User not set. You shouldn't be here.");
}
try {
......@@ -41,10 +38,7 @@ try {
$user = new User($_GET['user']);
}
} catch (Exception $e) {
$smarty->assign('pageheading', 'User not found');
$smarty->assign('details', 'Shall I call in a missing persons report?');
$smarty->display('error.tpl');
die();
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
$scrobbleCount = (int)$_GET['count'];
......
......@@ -28,10 +28,7 @@ require_once('data/TagCloud.php');
require_once('data/Server.php');
if (!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'User not set! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "User not set. You shouldn't be here.");
}
try {
......@@ -43,7 +40,7 @@ try {
$remote = false;
}
} catch (Exception $e) {
$error = 'User not found';
$user = null;
}
if (isset($user->name)) {
......@@ -71,7 +68,5 @@ if (isset($user->name)) {
$smarty->assign('remote', $remote);
$smarty->display('user-station.tpl');
} else {
$smarty->assign('pageheading', $error);
$smarty->assign('details', 'Shall I call in a missing persons report?');
$smarty->display('error.tpl');
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
......@@ -29,10 +29,7 @@ require_once('data/Statistic.php');
require_once('data/GraphTypes.php');
if (!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('pageheading', 'Error!');
$smarty->assign('details', 'User not set! You shouldn\'t be here!');
$smarty->display('error.tpl');
die();
displayError("Error", "User not set. You shouldn't be here.");
}
try {
......@@ -43,9 +40,9 @@ try {
}
} catch (Exception $e) {
if ($e->getCode() == 22) {
echo('We had some trouble locating that user. Are you sure you spelled it correctly?' . "\n");
$error = "We had some trouble locating that user. Are you sure you spelled it correctly?";
} else {
echo 'Caught exception: ', $e->getMessage(), "\n";
$error = $e->getMessage();
}
$user = null;
}
......@@ -64,6 +61,10 @@ if (isset($user->name)) {
$begin = null;
$total_tracks_limit = 15000;
$total_tracks = $user->getTotalTracks();
if(!$total_tracks) {
displayError("No stats for user",
"User {$user->name} doesn't seem to have scrobbled anything yet.");
}
// Limit stats to timeperiod if track count is higher than limit
if($total_tracks > $total_tracks_limit) {
......@@ -84,12 +85,8 @@ if (isset($user->name)) {
$smarty->assign('toptrackspx', 25 * $toptracks);
try {
$smarty->assign('graphtoptracks', new GraphTopTracks($user, $toptracks, $begin));
} catch (exception $e) {
$smarty->assign('pageheading', 'Couldn\'t get users top tracks!');
$smarty->assign('details', 'User ' . $user->name . ' doesn\'t seem to have scrobbled anything yet.');
$smarty->display('error.tpl');
die();
}
} catch (exception $e) {}
$smarty->assign('totaltracks', $total_tracks);
$smarty->assign('me', $user);
......@@ -118,7 +115,5 @@ if (isset($user->name)) {
$smarty->assign('stats', true);
$smarty->display('user-stats.tpl');
} else {
$smarty->assign('pageheading', 'User not found');
$smarty->assign('details', 'Shall I call in a missing persons report?');
$smarty->display('error.tpl');
displayError("User not found", "User not found, shall i call in a missing persons report?");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment