-
Notifications
You must be signed in to change notification settings - Fork 1
/
games.php
executable file
·222 lines (196 loc) · 10.4 KB
/
games.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/* Copyright (C) 2011-2013 Josh Ventura <[email protected]>
*
* This file is part of the ENIGMA Developers Community (EDC).
*
* The EDC is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3 of the License, or (at your option) any later version.
*
* This source 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this code. If not, see <http://www.gnu.org/licenses/>.
*/
ob_start();
require_once('common.php');
require_once('reURL.php');
$smcFunc['db_select_db']($db_name);
$action = isset($_GET['action']) ? $_GET['action'] : 'view';
switch ($action)
{
case 'view':
// Where are we?
$_GET['action'] = 'edc_game_view';
// Grab some info about the game we're displaying
$game_id = !empty($_GET['game']) ? $_GET['game'] : -1;
$game_info_q = $smcFunc['db_query']('', 'SELECT * FROM edc_games WHERE id_game={int:gid}',array("gid" => $game_id));
if (($game_info = mysql_fetch_assoc($game_info_q)) === false) {
echo "Game doesn't exist.";
return false;
}
// Grab game files and screenshots
require_once('file-api.php');
$gfiles = get_game_files($game_id);
echo "<div class=\"edcpanes_left\">\n";
echo "<div class=\"edcpane\">
<div class=\"edctitlebar\">Game Information</div>";
if (($lmd = loadMemberData(array($game_info['id_author']))) === false)
echo " <b>Author:</b><br /><div style=\"padding:24px 0px 0px 12px\">unknown</div>\n";
else
{
$lmc = loadMemberContext($lmd[0]);
$author_info = $memberContext[$lmd[0]];// $user_profile[$game_info['id_author']];
echo " <center><div class=\"edcAvatar\">" . $author_info['avatar']['image'] . "</div></center>\n" .
" <b>Author:</b><br /><div style=\"padding: 0px 0px 12px 24px\"><a href=\"blogs.php?u=" . $game_info['id_author'] . "\">" . $author_info['name'] . "</a></div>\n";
}
echo " <b>Rating:</b><br /><div style=\"padding: 0px 0px 12px 24px\">" . ($game_info['ratecount'] ? $game_info['totalrating'] / $game_info['ratecount'] : "Unrated") . "</div>\n";
echo " <b>Type:</b><br /><div style=\"padding: 0px 0px 12px 24px\">" . htmlspecialchars($game_info['type']) . "</div>\n";
echo " <b>Genre:</b><br /><div style=\"padding: 0px 0px 12px 24px\">" . htmlspecialchars($game_info['genre']) . "</div>\n";
echo " <b>Submited:</b><br /><div style=\"padding: 0px 0px 12px 24px\">" . htmlspecialchars($game_info['date']) . "</div>\n";
echo " <b>Download" . (count($gfiles['links']) == 1? "" : "s (" . count($gfiles['links']) . ")") . ":</b><br />";
for ($i = 0; $i < count($gfiles['links']); ++$i)
echo "<div style=\"padding: 0px 0px 12px 24px\"><a href=\"" . $gfiles['links'][$i] . "\">" . $gfiles['cats'][$i] . "</a></div>\n";
echo "</div><br />";
include('panel_activeusers.php');
// Main panel, showing game
echo "</div><div class=\"edcmainpane\">";
echo " <div class=\"edcpane\">\n <div class=\"edctitlebar\">Recent Games</div>\n";
echo " <div class=\"edcContent\">\n";
echo " <h1 class=\"edcGameTitle\">" . htmlspecialchars($game_info['name']) . "</h1>\n";
echo " <div class=\"edcGameImage\"><img class=\"edcGameThumb\" alt=\"" . htmlspecialchars($game_info['name']) . "\" src=\"" . reURL($game_info['image']) . "\" /></div>\n";
echo parse_bbc(htmlspecialchars($game_info['text']));
echo " <div class=\"edcGameFooter\"><b>Screenshots</b>:<br />";
foreach ($gfiles['screens'] as $screen)
echo '<a href="' . $screen . '" target="_blank"><img class="screenshot" src="' . $screen . '" alt="Screenshot" /></a>';
if ($game_info['id_author'] == $context['user']['id'])
echo "<span style=\"float:right\"><a href=\"games.php?action=edit&game=" . $game_id . "\">Edit</a> | "
. "<a href=\"submit.php?action=delgame&game=" . $game_id . "\" onclick=\"javascript:return confirmDelete('game');\">Delete</a></span>";
echo "</div>\n";
echo " </div></div><br />\n";
$thread_id = $game_info['id_thread'];
include('panel_comments.php');
echo "</div>";
break;
case 'new':
require_once('form-game.php');
require_once('form-designer.php');
echo "<div class=\"edcpanes_left\">\n";
include('panel_user.php');
include('panel_blogs.php');
include('panel_activeusers.php');
echo "</div><div class=\"edcmainpane\"><div class=\"edcpane\">\n";
echo "<div class=\"edctitlebar\">Submit Game/Example</div>\n";
echo "<form method=\"post\" action=\"submit.php\" style=\"margin-top: 3px;\" enctype=\"multipart/form-data\">";
$gfres = print_game_form();
echo "<input type=\"hidden\" name=\"submittype\" value=\"game\" />";
echo "</form></div></div>";
print_designer_form($gfres);
break;
case 'edit':
// Grab some info about the game we're displaying
require_once('form-game.php');
require_once('form-designer.php');
$game_id = $_GET['game'];
if (empty($game_id)) {
echo "<h1>ERROR: No game to edit!</h1>";
return false;
}
$game_info_q = $smcFunc['db_query']('', 'SELECT * FROM edc_games WHERE id_game={int:gid}',array("gid" => $game_id));
if (($game_info = mysql_fetch_assoc($game_info_q)) === false) {
echo "<h1>Game doesn't exist.</h1>";
return false;
}
echo "<div class=\"edcpanes_left\">\n";
include('panel_user.php');
include('panel_blogs.php');
include('panel_activeusers.php');
echo "</div><div class=\"edcmainpane\"><div class=\"edcpane\">\n";
echo "<div class=\"edctitlebar\">Edit Game/Example</div>\n";
echo "<form method=\"post\" action=\"submit.php\" style=\"margin-top: 3px;\">";
$isgame = strtolower($game_info['type']) == "game";
require_once('file-api.php');
$gameFiles = get_game_files($game_id);
$gfres = print_game_form($game_info['name'], $game_info['genre'], $game_info['text'], $isgame, $game_info['wip'], $game_info['image'], $gameFiles['cats'], $gameFiles['links'], $gameFiles['screens']);
echo "<input type=\"hidden\" name=\"submittype\" value=\"editgame\" />";
echo "<input type=\"hidden\" name=\"game_id\" value=\"" . $game_id . "\" />";
echo "</form></div></div>";
print_designer_form($gfres);
break;
case 'list':
if (!empty($_GET['b'])) $begin = preg_replace("[^0-9]","",$_GET['b']);
if (empty($begin)) $begin = 0;
if (!empty($_GET['s'])) $show = preg_replace("[^0-9]","",$_GET['s']);
if (empty($show) || $show > 20 || $show < 1) $show = 20;
$game_list_q = $smcFunc['db_query']('', 'SELECT SQL_CALC_FOUND_ROWS * FROM edc_games ORDER BY `date` DESC LIMIT ' . $begin . ', ' . $show,array());
$games_printed = 0;
$games_total_q = mysql_query("SELECT FOUND_ROWS();");
$games_total = mysql_result($games_total_q,0);
echo "<script type=\"text/javascript\">
function togglescroll(obj) {
obj.focus();
if (obj.style.overflowY != 'scroll') {
obj.style.overflowY = 'scroll', obj.style.overflowX = 'auto';
return false;
}
return true;
}
function toggleoffscroll(obj) {
obj.style.overflow=\"hidden\";
}
</script>";
echo "<span style=\"font-style: italic; font-size: 8px;\">Double click a description to activate scroll.</span>";
echo "<table style=\"border: 3px double #0000C0; width: 80%;\">";
while (($tgame = mysql_fetch_assoc($game_list_q)) !== false) {
echo "<tr>";
// Game thumbnail image
echo "<td rowspan=\"2\" class=\"thumbnailcell\">"
. "<a href=\"games.php?game=" . $tgame["id_game"] . "\">"
. "<img class=\"edcGameThumb\" alt=\"" . htmlspecialchars($tgame['name'])
. "\" src=\"" . reURL($tgame['image']) . "\" style=\"vertical-align:top\"/></a></td>";
$sbs = "";
echo "<td class=\"bylinecell\"><a href=\"games.php?game="
. $tgame["id_game"] . '">' . htmlspecialchars($tgame["name"]) . "</a> <i>by</i> <a href=\"blogs.php?u="
. $tgame["id_author"] . '">';
if (($lmd = loadMemberData(array($tgame['id_author']))) === false)
echo "Some guy who's dead now";
else {
$lmc = loadMemberContext($lmd[0]);
$author_info = $memberContext[$lmd[0]];// $user_profile[$game_info['id_author']];
echo $author_info['name'];
}
echo "</a></td>";
echo "</tr><tr><td class=\"descriptioncell\"><div class=\"descpreview\" ondblclick=\"togglescroll(this)\" onmouseout=\"toggleoffscroll(this)\">"
. parse_bbc(htmlspecialchars($tgame['text'])) . "</div></td>";
echo "</td></tr>\n";
$games_printed++;
}
echo "</table>";
if ($games_printed == 0) {
echo "<h1>No games to display" . (s > 0? " in the given range" : "") . ".</h1>";
return false;
}
#$tcq = $smcFunc['db_query']('', 'SELECT NULL FROM edc_games',array());
echo "<p style=\"width: 80%;\">Showing games " . ($begin + 1) . "-" . ($begin+$games_printed) . " of $games_total.";
echo "<span style=\"float:right;\">";
if ($begin > 0) echo "<a href=\"games.php?action=list&b=" . (floor(($begin-1)/$show)*$show) . "&s=$show\" title=\"Previous Page\"><</a>";
else echo "<";
echo " Page ";
$pn = 0;
for ($gp = 0; $gp < $games_total; $gp += $show) {
echo " "; $pn++;
if ($gp >= $begin+$show || $gp < $begin)
echo "<a href=\"games.php?action=list&b=$gp&s=$show\" title=\"Games " . ($gp+1) . "-" . min($gp+$show,$games_total) . "\">$pn</a> ";
else echo "$pn ";
}
if ($begin + $show >= $games_total) echo ">";
else echo "<a href=\"games.php?action=list&b=" . (floor(($begin+$show)/$show)*$show) . "&s=$show\" title=\"Next Page\">></a>";
echo "</span></p>\n";
break;
default:
echo "I have no idea what you want from me.";
break;
}
?>