-
Notifications
You must be signed in to change notification settings - Fork 28
/
party.php
350 lines (303 loc) · 12.6 KB
/
party.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
require_once("bootstrap.inc.php");
class PouetBoxPartyHeader extends PouetBox
{
public $party;
public $partylinks;
public $year;
public $years;
function __construct( $partyView )
{
parent::__construct();
$this->uniqueID = "pouetbox_partyheader";
$this->party = $partyView->party;
$this->year = $partyView->year;
$this->title = _html($this->party->name." ".$this->year);
}
function LoadFromDB()
{
$this->partylinks = SQLLib::selectRow(sprintf("SELECT * FROM `partylinks` WHERE party = %d and year = %d",$this->party->id,$this->year));
$this->years = array();
$rows = SQLLib::selectRows(sprintf("SELECT party_year FROM prods WHERE party = %d GROUP BY party_year",$this->party->id));
foreach($rows as $v)
$this->years[$v->party_year] = true;
$rows = SQLLib::selectRows(sprintf("SELECT invitationyear FROM prods WHERE invitation = %d GROUP BY invitationyear",$this->party->id));
foreach($rows as $v)
$this->years[$v->invitationyear] = true;
ksort($this->years);
}
function RenderContent()
{
global $currentUser;
if ($this->party->web)
printf("[<a href='%s'>web</a>]\n",_html($this->party->web));
if(file_exists($this->party->GetResultsLocalFileName($this->year)))
echo $this->party->RenderResultsLink( $this->year );
else if ($currentUser && $currentUser->CanSubmitItems())
printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+results</a>]\n",$this->party->id,$this->year);
if($this->partylinks && $this->partylinks->download)
echo "[<a href='".$this->partylinks->download."'>download</a>]\n";
else if ($currentUser && $currentUser->CanSubmitItems())
printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+download</a>]\n",$this->party->id,$this->year);
if($this->partylinks && $this->partylinks->slengpung)
echo " [<a href='http://www.slengpung.com/?eventid=".(int)$this->partylinks->slengpung."'>slengpung</a>]";
else if ($currentUser && $currentUser->CanSubmitItems())
printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+slengpung</a>]\n",$this->party->id,$this->year);
if($this->partylinks && $this->partylinks->csdb)
echo " [<a href='http://csdb.dk/event/?id=".(int)$this->partylinks->csdb."'>csdb</a>]";
else if ($currentUser && $currentUser->CanSubmitItems())
printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+csdb</a>]\n",$this->party->id,$this->year);
if($this->partylinks && $this->partylinks->zxdemo)
echo " [<a href='http://zxdemo.org/party.php?id=".(int)$this->partylinks->zxdemo."'>zxdemo</a>]";
//else if ($currentUser && $currentUser->CanSubmitItems())
// printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+zxdemo</a>]\n",$this->party->id,$this->year);
if($this->partylinks && $this->partylinks->demozoo)
echo " [<a href='http://demozoo.org/parties/".(int)$this->partylinks->demozoo."/'>demozoo</a>]";
else if ($currentUser && $currentUser->CanSubmitItems())
printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+demozoo</a>]\n",$this->party->id,$this->year);
if($this->partylinks && $this->partylinks->artcity)
echo " [<a href='http://artcity.bitfellas.org/index.php?a=search&type=tag&text=".rawurlencode($this->partylinks->artcity)."'>artcity</a>]";
else if ($currentUser && $currentUser->CanSubmitItems())
printf(" [<a class='submitadditional' href='submit_party_edition_info.php?which=%d&when=%d'>+artcity</a>]\n",$this->party->id,$this->year);
if ($currentUser && $currentUser->CanEditItems())
{
printf(" [<a href='admin_party_edit.php?which=%d' class='adminlink'>edit</a>]\n",$this->party->id);
printf(" [<a href='admin_party_edition_edit.php?which=%d&when=%d' class='adminlink'>edit year</a>]\n",$this->party->id,$this->year);
}
printf(" [<a href='gloperator_log.php?which=%d&what=party'>glöplog</a>]\n",$this->party->id);
}
function RenderFooter()
{
$y = array();
foreach($this->years as $v=>$dummy)
$y[] = "<a href='party.php?which=".rawurlencode($this->party->id)."&when=".$v."'>".$v."</a>";
echo " <div class='yearselect'>".implode(" |\n",$y)."</div>\n";
echo " <div class='foot'>added on the ".$this->party->addedDate." by ".$this->party->addedUser->PrintLinkedName()." ".$this->party->addedUser->PrintLinkedAvatar()."</div>\n";
echo "</div>\n";
}
};
class PouetBoxPartyView extends PouetBox
{
public $party;
public $year;
public $prods;
public $sortByCompo;
function __construct()
{
parent::__construct();
$this->uniqueID = "pouetbox_partyview";
}
function LoadFromDB()
{
$this->party = PouetParty::spawn($_GET["which"]);
if (!$this->party) return;
$this->party->addedUser = PouetUser::spawn( $this->party->addedUser );
if (isset($_GET["when"]))
{
$this->year = $_GET["when"];
}
else
{
$r = SQLLib::selectRow(sprintf_esc("select party_year from prods where party = %d order by rand() limit 1",$_GET["which"]));
if (!$r)
{
$r = SQLLib::selectRow(sprintf_esc("select invitationyear as party_year from prods where invitation = %d order by rand() limit 1",$_GET["which"]));
}
$this->year = $r ? $r->party_year : 0;
}
if ($this->year < 100)
{
$this->year += ($this->year < 50 ? 2000 : 1900);
}
$this->prods = array();
$s = new BM_Query("prods");
$s->AddWhere( sprintf_esc("(prods.party = %d AND prods.party_year = %d) or (prodotherparty.party = %d AND prodotherparty.party_year = %d)",$this->party->id,$this->year,$this->party->id,$this->year) );
// this is where it gets nasty; luckily we can fake it relatively elegantly: ORM won't notice if we override some of the field selections
$s->AddJoin("left","prodotherparty",sprintf_esc("prodotherparty.prod = prods.id and (prodotherparty.party = %d AND prodotherparty.party_year = %d)",$this->party->id,$this->year));
foreach($s->GetFields() as &$v)
{
if ($v == "prods.party_compo as prods_party_compo")
{
$v = "COALESCE(prodotherparty.party_compo,prods.party_compo) as prods_party_compo";
}
if ($v == "prods.party_place as prods_party_place")
{
$v = "COALESCE(prodotherparty.party_place,prods.party_place) as prods_party_place";
}
}
$dir = "DESC";
if (@$_GET["reverse"])
$dir = "ASC";
$this->sortByCompo = false;
switch(@$_GET["order"])
{
case "type": $s->AddOrder("prods.type ".$dir); break;
case "name": $s->AddOrder("prods.name ".$dir); break;
case "group": $s->AddOrder("prods.group1 ".$dir); $s->AddOrder("prods.group2 ".$dir); $s->AddOrder("prods.group3 ".$dir); break;
case "party": $s->AddOrder("prods_party.name ".$dir); $s->AddOrder("prods.party_year ".$dir); $s->AddOrder("prods.party_place ".$dir); break;
case "thumbup": $s->AddOrder("prods.voteup ".$dir); break;
case "thumbpig": $s->AddOrder("prods.votepig ".$dir); break;
case "thumbdown": $s->AddOrder("prods.votedown ".$dir); break;
case "avg": $s->AddOrder("prods.voteavg ".$dir); break;
case "views": $s->AddOrder("prods.views ".$dir); break;
default:
{
$s->AddOrder( "COALESCE(prodotherparty.party_compo,prods.party_compo)" );
$s->AddOrder( "COALESCE(prodotherparty.party_place,prods.party_place)" );
$s->AddOrder( "prods.name" );
$s->AddOrder( "prods.id" );
$this->sortByCompo = true;
// include invitations on top
$inv = new BM_Query("prods");
$inv->AddWhere( sprintf_esc("(prods.invitation = %d AND prods.invitationyear = %d)",$this->party->id,$this->year,$this->party->id,$this->year) );
$inv->AddOrder( "prods.addedDate" );
$prods = $inv->perform();
foreach($prods as &$v)
{
$v->party_compo = 1; // invit
$v->placings = array();
}
$this->prods = array_merge( $this->prods, $prods );
} break;
}
$prods = $s->perform();
$this->prods = array_merge( $this->prods, $prods );
PouetCollectPlatforms($this->prods);
PouetCollectAwards($this->prods);
}
function Render()
{
echo "<table id='".$this->uniqueID."' class='boxtable'>\n";
$headers = array(
"compo"=>"compo",
"type"=>"type",
"name"=>"prodname",
/*
"platform"=>"platform",
"group"=>"group",
"party"=>"release party",
"release"=>"release",
"added"=>"added",
*/
"thumbup"=>"<span class='rulez' title='rulez'>rulez</span>",
"thumbpig"=>"<span class='isok' title='piggie'>piggie</span>",
"thumbdown"=>"<span class='sucks' title='sucks'>sucks</span>",
"avg"=>"avg",
"views"=>"popularity",
);
$lastCompo = "*";
$headerDone = false;
global $COMPOTYPES;
foreach($this->prods as $p)
{
if ($p->party_compo != $lastCompo && !$headerDone)
{
echo "<tr class='sortable'>\n";
foreach($headers as $key=>$text)
{
$out = sprintf("<th><a href='%s' class='%s%s %s'>%s</a></th>\n",
adjust_query_header(array("order"=>$key)),@$_GET["order"]==$key?"selected":"",(@$_GET["order"]==$key && @$_GET["reverse"])?" reverse":"","sort_".$key,$text);
if ($key == "type" || $key == "name") $out = str_replace("</th>","",$out);
if ($key == "platform" || $key == "name") $out = str_replace("<th>"," ",$out);
if ($key == "compo" && $this->sortByCompo && $p->party_compo && $COMPOTYPES[$p->party_compo]) $out = sprintf("<th id='%s'>%s</th>",hashify($COMPOTYPES[$p->party_compo]),$COMPOTYPES[$p->party_compo]);
echo $out;
}
echo "</tr>\n";
if (!$this->sortByCompo)
$headerDone = true;
$lastCompo = $p->party_compo;
}
echo "<tr>\n";
echo "<td>\n";
if (!$this->sortByCompo)
echo @$COMPOTYPES[$p->party_compo]." ";
if (@$p->placings[0])
echo $p->placings[0]->PrintRanking();
echo "</td>\n";
echo "<td class='prod'>\n";
echo $p->RenderTypeIcons();
echo $p->RenderPlatformIcons();
echo "".$p->RenderLink()." ";
if ($p->groups)
echo "by ".$p->RenderGroupsLong()."\n";
echo $p->RenderAccolades();
echo "</td>\n";
echo "<td class='votes'>".$p->voteup."</td>\n";
echo "<td class='votes'>".$p->votepig."</td>\n";
echo "<td class='votes'>".$p->votedown."</td>\n";
echo "<td class='votesavg'>".$p->RenderAvg()."</td>\n";
$pop = (int)calculate_popularity( $p->views );
echo "<td>".progress_bar_solo( $pop, $pop."%" )."</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
};
class PouetBoxPartyLists extends PouetBox
{
var $id;
var $topic;
var $posts;
var $data;
function __construct($id)
{
parent::__construct();
$this->uniqueID = "pouetbox_partylists";
$this->title = "lists containing this party";
$this->id = (int)$id;
}
function LoadFromDB()
{
$s = new BM_Query();
$s->AddField("lists.id as id");
$s->AddField("lists.name as name");
$s->AddTable("list_items");
$s->AddJoin("","lists","list_items.list=lists.id");
$s->attach(array("lists"=>"owner"),array("users as user"=>"id"));
$s->AddWhere("list_items.itemid=".$this->id);
$s->AddWhere("list_items.type='party'");
$s->AddOrder("lists.name");
$this->data = $s->perform();
}
function RenderBody()
{
echo "<ul class='boxlist boxlisttable'>\n";
foreach($this->data as $list)
{
echo "<li>\n";
printf(" <span><a href='lists.php?which=%d'>%s</a></span>\n",$list->id,_html($list->name));
echo " <span>".$list->user->PrintLinkedAvatar()." ".$list->user->PrintLinkedName()."</span>\n";
echo "</li>\n";
}
echo "</ul>\n";
}
};
///////////////////////////////////////////////////////////////////////////////
$partyBox = new PouetBoxPartyView();
$partyBox->Load();
if (!$partyBox->party)
{
redirect("parties.php");
}
if (!$partyBox->prods && isset($_GET["when"]))
{
redirect("party.php?which=".(int)$partyBox->party->id);
}
$TITLE = $partyBox->party->name." ".$partyBox->year;
require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");
echo "<div id='content'>\n";
$headerBox = new PouetBoxPartyHeader($partyBox);
$headerBox->Load();
$headerBox->Render();
$partyBox->Render();
$lists = new PouetBoxPartyLists((int)$partyBox->party->id);
$lists->Load();
if ($lists->data)
{
$lists->Render();
}
echo "</div>\n";
require("include_pouet/menu.inc.php");
require_once("include_pouet/footer.php");
?>