Skip to content

Commit 5fb020b

Browse files
pagePage-
authored andcommitted
Catch and handle exceptions everywhere.
1 parent 6fe8f58 commit 5fb020b

26 files changed

+1714
-1634
lines changed

htdocs/album/album_comment.php

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,82 @@
1-
<?
1+
<?php
22

33
function create_error_offline($msg)
44
{
55
header('Location: '.URL.'/error.php?msg=' . rawurlencode(htmlspecialchars($msg, ENT_QUOTES)));
66
exit;
77
}
88

9-
10-
require_once('../config.inc');
11-
require_once(ENGINE . 'Default/smr.inc');
12-
require_once(get_file_loc('SmrMySqlDatabase.class.inc'));
13-
require_once(get_file_loc('SmrSession.class.inc'));
14-
15-
require_once(LIB . 'Album/album_functions.php');
16-
17-
if (SmrSession::$account_id == 0)
18-
create_error_offline('You need to logged in to post comments!');
19-
20-
if (!isset($_GET['album_id']) || empty($_GET['album_id']))
21-
create_error_offline('Which picture do you want comment?');
22-
else
23-
$album_id = $_GET['album_id'];
24-
25-
if (!is_numeric($album_id))
26-
create_error_offline('Picture ID has to be numeric!');
27-
28-
if ($album_id < 1)
29-
create_error_offline('Picture ID has to be positive!');
30-
31-
require_once(get_file_loc('SmrAccount.class.inc'));
32-
$account =& SmrAccount::getAccount(SmrSession::$account_id);
33-
34-
if (isset($_GET['action']) && $_GET['action'] == 'Moderate')
9+
try
3510
{
36-
if(!$account->hasPermission(PERMISSION_MODERATE_PHOTO_ALBUM))
37-
create_error_offline('You do not have permission to do that!');
38-
$container = create_container('skeleton.php', 'album_moderate.php');
39-
$container['account_id'] = $album_id;
40-
41-
forward($container);
11+
require_once('../config.inc');
12+
require_once(ENGINE . 'Default/smr.inc');
13+
require_once(get_file_loc('SmrMySqlDatabase.class.inc'));
14+
require_once(get_file_loc('SmrSession.class.inc'));
15+
16+
require_once(LIB . 'Album/album_functions.php');
17+
18+
if (SmrSession::$account_id == 0)
19+
create_error_offline('You need to logged in to post comments!');
20+
21+
if (!isset($_GET['album_id']) || empty($_GET['album_id']))
22+
create_error_offline('Which picture do you want comment?');
23+
else
24+
$album_id = $_GET['album_id'];
25+
26+
if (!is_numeric($album_id))
27+
create_error_offline('Picture ID has to be numeric!');
28+
29+
if ($album_id < 1)
30+
create_error_offline('Picture ID has to be positive!');
31+
32+
require_once(get_file_loc('SmrAccount.class.inc'));
33+
$account =& SmrAccount::getAccount(SmrSession::$account_id);
34+
35+
if (isset($_GET['action']) && $_GET['action'] == 'Moderate')
36+
{
37+
if(!$account->hasPermission(PERMISSION_MODERATE_PHOTO_ALBUM))
38+
create_error_offline('You do not have permission to do that!');
39+
$container = create_container('skeleton.php', 'album_moderate.php');
40+
$container['account_id'] = $album_id;
41+
42+
forward($container);
43+
exit;
44+
45+
}
46+
47+
$db = new SmrMySqlDatabase();
48+
49+
if (!isset($_GET['comment']) || empty($_GET['comment']))
50+
create_error_offline('Please enter a comment');
51+
else
52+
$comment = $_GET['comment'];
53+
54+
// get current time
55+
$curr_time = TIME;
56+
57+
$comment = word_filter($comment);
58+
$account->sendMessageToBox(BOX_ALBUM_COMMENTS,$comment);
59+
60+
// check if we have comments for this album already
61+
$db->lockTable('album_has_comments');
62+
63+
$db->query('SELECT MAX(comment_id) FROM album_has_comments WHERE album_id = '.$album_id);
64+
if ($db->nextRecord())
65+
$comment_id = $db->getField('MAX(comment_id)') + 1;
66+
else
67+
$comment_id = 1;
68+
69+
$db->query('INSERT INTO album_has_comments
70+
(album_id, comment_id, time, post_id, msg)
71+
VALUES ('.$album_id.', '.$comment_id.', '.$curr_time.', '.SmrSession::$account_id.', '.$db->escapeString($comment).')');
72+
$db->unlock();
73+
74+
header('Location: '.URL.'/album/?' . get_album_nick($album_id));
4275
exit;
43-
4476
}
45-
46-
$db = new SmrMySqlDatabase();
47-
48-
if (!isset($_GET['comment']) || empty($_GET['comment']))
49-
create_error_offline('Please enter a comment');
50-
else
51-
$comment = $_GET['comment'];
52-
53-
// get current time
54-
$curr_time = TIME;
55-
56-
$comment = word_filter($comment);
57-
$account->sendMessageToBox(BOX_ALBUM_COMMENTS,$comment);
58-
59-
// check if we have comments for this album already
60-
$db->lockTable('album_has_comments');
61-
62-
$db->query('SELECT MAX(comment_id) FROM album_has_comments WHERE album_id = '.$album_id);
63-
if ($db->nextRecord())
64-
$comment_id = $db->getField('MAX(comment_id)') + 1;
65-
else
66-
$comment_id = 1;
67-
68-
$db->query('INSERT INTO album_has_comments
69-
(album_id, comment_id, time, post_id, msg)
70-
VALUES ('.$album_id.', '.$comment_id.', '.$curr_time.', '.SmrSession::$account_id.', '.$db->escapeString($comment).')');
71-
$db->unlock();
72-
73-
header('Location: '.URL.'/album/?' . get_album_nick($album_id));
74-
exit;
77+
catch(Exception $e)
78+
{
79+
handleException($e);
80+
}
7581

7682
?>

htdocs/album/index.php

Lines changed: 85 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,102 @@
1-
<?
2-
3-
require_once('../config.inc');
4-
require_once(LIB . 'Default/SmrMySqlDatabase.class.inc');
5-
require_once(LIB . 'Default/Globals.class.inc');
6-
require_once(ENGINE . 'Default/smr.inc');
7-
require_once(get_file_loc('SmrSession.class.inc'));
8-
9-
require_once(LIB . 'Album/album_functions.php');
10-
11-
// database object
12-
$db = new SmrMySqlDatabase();
13-
$db2 = new SmrMySqlDatabase();
14-
?>
15-
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
16-
<html>
17-
<head>
18-
<link rel="stylesheet" type="text/css" href="<?php echo URL;?>/css/classic.css">
19-
<title>Space Merchant Realms - Photo Album</title>
20-
<meta http-equiv="pragma" content="no-cache">
21-
</head>
22-
<body>
23-
24-
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0" >
25-
<tr>
26-
<td align="center" colspan="2"><h1>Space Merchant Realms - Photo Album</h1></td>
27-
</tr>
28-
<tr>
29-
<td>
30-
<table width="750" border="0" cellspacing="0" cellpadding="0">
31-
<tr>
32-
<td>
33-
34-
<table cellspacing="0" cellpadding="0" border="0" width="700">
35-
<tr>
36-
<td colspan="3" height="1" bgcolor="#0B8D35"></td>
37-
</tr>
38-
<tr>
39-
<td width="1" bgcolor="#0B8D35"></td>
40-
<td align="left" valign="top" bgcolor="#06240E">
41-
<table width="100%" height="100%" border="0" cellspacing="5" cellpadding="5">
42-
<tr>
43-
<td valign="top">
441
<?php
45-
if (!empty($_SERVER['QUERY_STRING']))
2+
try
463
{
47-
// query string should be a nick or some letters of a nick
48-
$query = urldecode($_SERVER['QUERY_STRING']);
49-
50-
$db->query('SELECT account_id as album_id
51-
FROM album JOIN account USING(account_id)
52-
WHERE hof_name LIKE '.$db->escapeString($query.'%').' AND
53-
approved = \'YES\'
54-
ORDER BY hof_name');
55-
56-
if ($db->getNumRows() > 1)
4+
require_once('../config.inc');
5+
require_once(LIB . 'Default/SmrMySqlDatabase.class.inc');
6+
require_once(LIB . 'Default/Globals.class.inc');
7+
require_once(ENGINE . 'Default/smr.inc');
8+
require_once(get_file_loc('SmrSession.class.inc'));
9+
10+
require_once(LIB . 'Album/album_functions.php');
11+
12+
// database object
13+
$db = new SmrMySqlDatabase();
14+
$db2 = new SmrMySqlDatabase();
15+
?>
16+
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
17+
<html>
18+
<head>
19+
<link rel="stylesheet" type="text/css" href="<?php echo URL;?>/css/classic.css">
20+
<title>Space Merchant Realms - Photo Album</title>
21+
<meta http-equiv="pragma" content="no-cache">
22+
</head>
23+
<body>
24+
25+
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0" >
26+
<tr>
27+
<td align="center" colspan="2"><h1>Space Merchant Realms - Photo Album</h1></td>
28+
</tr>
29+
<tr>
30+
<td>
31+
<table width="750" border="0" cellspacing="0" cellpadding="0">
32+
<tr>
33+
<td>
34+
35+
<table cellspacing="0" cellpadding="0" border="0" width="700">
36+
<tr>
37+
<td colspan="3" height="1" bgcolor="#0B8D35"></td>
38+
</tr>
39+
<tr>
40+
<td width="1" bgcolor="#0B8D35"></td>
41+
<td align="left" valign="top" bgcolor="#06240E">
42+
<table width="100%" height="100%" border="0" cellspacing="5" cellpadding="5">
43+
<tr>
44+
<td valign="top">
45+
<?php
46+
if (!empty($_SERVER['QUERY_STRING']))
5747
{
58-
$db2->query('SELECT account_id as album_id
59-
FROM album JOIN account USING(account_id)
60-
WHERE hof_name = '.$db->escapeString($query).' AND
61-
approved = \'YES\'
62-
ORDER BY hof_name');
63-
64-
if ($db2->nextRecord())
65-
album_entry($db2->getField('album_id'));
66-
else
67-
{
68-
// get all id's and build array
69-
$album_ids = array();
48+
// query string should be a nick or some letters of a nick
49+
$query = urldecode($_SERVER['QUERY_STRING']);
7050

71-
while ($db->nextRecord())
72-
$album_ids[] = $db->getField('album_id');
51+
$db->query('SELECT account_id as album_id
52+
FROM album JOIN account USING(account_id)
53+
WHERE hof_name LIKE '.$db->escapeString($query.'%').' AND
54+
approved = \'YES\'
55+
ORDER BY hof_name');
7356

74-
// double check if we have id's
75-
if (count($album_ids) > 0)
76-
search_result($album_ids);
57+
if ($db->getNumRows() > 1)
58+
{
59+
$db2->query('SELECT account_id as album_id
60+
FROM album JOIN account USING(account_id)
61+
WHERE hof_name = '.$db->escapeString($query).' AND
62+
approved = \'YES\'
63+
ORDER BY hof_name');
64+
65+
if ($db2->nextRecord())
66+
album_entry($db2->getField('album_id'));
67+
else
68+
{
69+
// get all id's and build array
70+
$album_ids = array();
71+
72+
while ($db->nextRecord())
73+
$album_ids[] = $db->getField('album_id');
74+
75+
// double check if we have id's
76+
if (count($album_ids) > 0)
77+
search_result($album_ids);
78+
else
79+
main_page();
80+
}
81+
82+
}
83+
elseif ($db->getNumRows() == 1)
84+
{
85+
if ($db->nextRecord())
86+
album_entry($db->getField('album_id'));
7787
else
7888
main_page();
7989
}
80-
81-
}
82-
elseif ($db->getNumRows() == 1)
83-
{
84-
if ($db->nextRecord())
85-
album_entry($db->getField('album_id'));
8690
else
8791
main_page();
8892
}
8993
else
9094
main_page();
9195
}
92-
else
93-
main_page();
96+
catch(Exception $e)
97+
{
98+
handleException($e);
99+
}
94100
?>
95101
</td>
96102
</tr>

0 commit comments

Comments
 (0)