-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistings.php
484 lines (418 loc) · 17.2 KB
/
listings.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<?php
include_once 'IndexStyles.php';
include_once 'config_listings.php';
include_once 'secrets.php';
include_once 'menuItems.php';
include_once 'page.php';
include_once 'filterMenu.php';
include_once 'utils/javascript.php';
$page = $_GET['page'];
$page = $page ?? 1;
$topParentId = $_GET['topParentId'];
$folderType = $_GET['folderType'];
$collectionType = $_GET['collectionType'];
$name = $_GET['name'];
$topParentName = $_GET['topParentName'];
$backdropId = $_GET['backdropId'];
$backdrop = getBackdropIDandTag(null, $backdropId);
class ListingsPage extends Page
{
public $items;
public $menuItems = array();
public $cbp;
public $QSBase;
protected $renderFiltering;
protected $filters;
protected $titleLetters;
protected $singleLetterTVIDs;
protected $letterToNumber;
public $dynamicGridPage = false;
public function __construct($title, $renderFiltering = true)
{
global $topParentName, $topParentId, $parentId, $folderType, $collectionType;
global $name, $backdropId;
parent::__construct($title);
$this->renderFiltering = $renderFiltering;
if ($renderFiltering) {
$this->titleLetters = range("A", "Z");
array_unshift($this->titleLetters, "#");
$this->singleLetterTVIDs = array("#"=>"1",
"A"=>"2", "B"=>"22", "C"=>"222",
"D"=>"3", "E"=>"33", "F"=>"333",
"G"=>"4", "H"=>"44", "I"=>"444",
"J"=>"5", "K"=>"55", "L"=>"555",
"M"=>"6", "N"=>"66", "O"=>"666",
"P"=>"7", "Q"=>"77", "R"=>"777", "S"=>"7777",
"T"=>"8", "U"=>"88", "V"=>"888",
"W"=>"9", "X"=>"99", "Y"=>"999", "Z"=>"9999"
);
$this->additionalCSS = 'filter.css';
}
$this->cbp = new CategoryBrowseParams();
$this->cbp->topParentName = $topParentName;
$this->cbp->topParentId = $topParentId;
$this->cbp->folderType = $folderType;
$this->cbp->collectionType = $collectionType;
$this->cbp->name = $name;
$this->cbp->backdropId = $backdropId;
$this->cbp->params->setFromQueryString();
$this->QSBase = http_build_query($this->cbp);
}
public function printJavascript()
{
global $folderType, $collectionType;
global $topParentId, $topParentName;
global $page, $numPages;
$listingsData = 'var asMenuTitle = ' . getJSArray(array_map(function ($i) { return $i->Name; }, $this->menuItems), true) . ";\n";
$listingsData .= 'var asMenuSubtitle = ' . getJSArray(array_map(function ($i) { return $i->Subtitle; }, $this->menuItems), true) . ";\n";
$listingsData .= 'var asMenuURL = ' . getJSArray(array_map(function ($i) { return $i->DetailURL; }, $this->menuItems), true) . ";\n";
if ($this->dynamicGridPage) {
$listingsData .= 'var asMenuImage = ' . getJSArray(array_map(function ($i) { return $i->PosterURL; }, $this->menuItems), true) . ";\n";
}
$_SESSION['listingsData'] = $listingsData;
?>
<script type="text/javascript" src="js/listings.js"></script>
<script type="text/javascript" src="js/uiUpdateUtils.js"></script>
<script type="text/javascript">
var iPage = <?= $this->dynamicGridPage ? $page : 1 ?>;
var iPageSize = <?= $this->indexStyle->Limit ?>;
var iNumPages = <?= $numPages ?>;
var iRowSize = <?= $this->indexStyle->nbThumbnailsPerLine ?>;
var iNumRows = <?= ceil(count($this->menuItems) / $this->indexStyle->nbThumbnailsPerLine) ?>;
</script>
<script type="text/javascript" src="js/listingsData.js.php"></script>
<?
if ($this->renderFiltering) {
//clear some options that would be reset by filter
$filterCBP = clone $this->cbp;
$filterCBP->backdropId = null;
$filterCBP->name = null;
$filterCBP->params->ParentID = null;
?>
<script type="text/javascript">
var filteringBaseURL = '<?= categoryBrowseURLEx($filterCBP) ?>';
</script>
<script type="text/javascript" src="js/filter/filters.js.php?topParentId=<?= $topParentId ?>&topParentName=<?= $topParentName ?>&itemType=<?= mapFolderTypeToSingleItemType($folderType, $collectionType) ?>"></script>
<script type="text/javascript" src="js/filter/filter.js"></script>
<?
} else {
//empty initMenu function to prevent JS error
?>
<script type="text/javascript">function initMenu() {}</script>
<?
}
}
public function printHead()
{
//initialize menuitems
if ($this->items) {
foreach ($this->items as $item) {
$menuItem = getMenuItem($item);
if ($menuItem) {
array_push($this->menuItems, $menuItem);
}
}
}
$this->onload .= "initpage(" . ((isset($this->indexStyle->popupHeight) || isset($this->indexStyle->popupWidth)) ? 'true' : 'false') . ")";
parent::printHead();
}
private function toSingleLetterNumberpad($str)
{
return $this->singleLetterTVIDs[$str];
}
private function printTVIDLink($url, $tvid)
{
print("<a href=\"$url\" tvid=\"$tvid\" tabindex=\"-1\" ></a>\n");
}
private function printTVIDLinks($categoryName, $items, $getTVID)
{
global $folderType, $collectionType, $topParentId, $topParentName;
$browseType = mapItemTypeToCollectionType(mapFolderTypeToSingleItemType($folderType, $collectionType));
$this->cbp = new CategoryBrowseParams();
$this->cbp->topParentName = $topParentName;
$this->cbp->topParentId = $topParentId;
$this->cbp->folderType = $folderType;
$this->cbp->collectionType = $browseType;
foreach ($items as $item) {
//filter by the displayed folder/collectiontype, tv, movie, boxset...
$this->cbp->params->addParam($categoryName, $item);
$url = categoryBrowseURLEx($this->cbp);
$this->printTVIDLink($url, call_user_func($getTVID, $item));
}
}
private function printSpeedDial()
{
if ($this->renderFiltering) {
//speed dial TVIDs
$this->printTVIDLinks('NameStartsWith', $this->titleLetters, 'ListingsPage::toSingleLetterNumberpad');
}
}
public function printContentWrapperStart()
{
?>
<table border="0" cellpadding="0" cellspacing="0" align="<?= $this->indexStyle->moviesTableAlign ?>">
<tr valign="<?= $this->indexStyle->moviesTableVAlign ?>"><td class="posterTableParent">
<?
}
public function printContent()
{
$this->printPosterTable($this->items);
}
public function printPosterTable($items, $wrapBottomRowToTop = true)
{
global $lastRow;
global $diplay_menuitems, $offset, $page;
if ($this->dynamicGridPage) {
$offset = $this->indexStyle->Limit * ($page - 1);
$diplay_menuitems = array_slice($this->menuItems, $offset, $this->indexStyle->Limit, true);
} else {
$diplay_menuitems = $this->menuItems;
}
$lastRow = min(ceil(count($items) / $this->indexStyle->nbThumbnailsPerLine), ceil($this->indexStyle->Limit / $this->indexStyle->nbThumbnailsPerLine));
?>
<table class="movies" border="0" cellpadding="<?= $this->indexStyle->moviesTableCellpadding ?? 0 ?>" cellspacing="<?= $this->indexStyle->moviesTableCellspacing ?? 0 ?>" align="<?= $this->indexStyle->moviesTableAlign ?>">
<?
//add empty menuitems so will always print limit
$max = $this->dynamicGridPage ? min($this->indexStyle->Limit, count($diplay_menuitems)) : count($diplay_menuitems);
for ($i=0; $i < $max; $i++) {
$key = $offset + $i;
$menuItem = $diplay_menuitems[$key];
//first item in row
if (ListingsPage::isStartOfRow($i)) {
echo "<tr>";
}
ListingsPage::printPosterTD($menuItem, $key, ceil(($i + 1) / $this->indexStyle->nbThumbnailsPerLine), $wrapBottomRowToTop);
//last item in row
if (ListingsPage::isEndOfRow($i)) {
echo "</tr>";
}
}
?>
</table>
<?
}
private function printPCMenu()
{
?>
<div id="popupWrapper"><div id="noNMT">
<a href="#" onclick="toggleMenu(); toggleMenuLinks(); return false;">menu</a>
<div id="menuLinks">
<table id="menuLinkTbl" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="leftTd"><a href="#" onclick="catUp(); return false;">Up</a></td>
<td><a href="#" onclick="genUp(); return false;">Up</a></td>
</tr>
<tr>
<td class="leftTd"><a href="#" onclick="catDown(); return false;">Down</a></td>
<td><a href="#" onclick="genDown(); return false;">Down</a></td>
</tr>
<tr>
<td class="leftTd"> </td>
<td class="selectLink"><a href="#" onclick="openLink('genLink5'); return false;">Select</a></td>
</tr>
</table>
</div>
</div></div>
<?
}
protected function printPaging($currentPage = 1, $numPages = 1)
{
global $tvid_page_pgup, $tvid_page_pgdn;
if ($numPages > 1) {
if ($this->dynamicGridPage) {
?>
<a href="#" name="pgupload" onfocus="updateSelectedItem(-1)"></a>
<a href="#" name="pgdnload" onfocus="updateSelectedItem(1)"></a>
<a href="#" onclick="updateSelectedItem(-1); return false;" TVID="<?= $tvid_page_pgup ?>" id="currentPage"><?= $currentPage ?></a> /
<a href="#" onclick="updateSelectedItem(1); return false;" TVID="<?= $tvid_page_pgdn ?>"><?= $numPages ?></a>
<?
} else {
parent::printPaging($currentPage, $numPages);
}
}
}
public function printFooter()
{
global $tvid_filter_menu;
global $diplay_menuitems, $offset;
if ($this->renderFiltering) {
?>
<div id="popupWrapper">
<?
FilterMenu::printFooter();
?>
</div>
<?
if ($this->PCMenu) {
$this->printPCMenu();
}
}
?>
<div id="popupWrapper">
<?
//print popups last of all, so they have highest z-index on NMT
if (!is_null($diplay_menuitems) && (isset($this->indexStyle->popupHeight) || isset($this->indexStyle->popupWidth))) {
//print popups last of all, so they have highest z-index on NMT
$max = $this->dynamicGridPage ? $this->indexStyle->Limit : count($diplay_menuitems);
for ($i=0; $i < $max; $i++) {
$key = $offset + $i;
$menuItem = $diplay_menuitems[$key];
ListingsPage::printPopup($menuItem, $key);
}
}
?>
</div>
<?
if ($this->renderFiltering) {
?>
<div id="navigationlinks">
<a TVID="<?= $tvid_filter_menu ?>" name="showMenu" onfocusset="catLink5" onclick="toggleMenu()" href="#" ></a>
<a name="catLinkUp" href="#" onfocusset="catLink5" onfocus="catUp();" onfocusload=""></a>
<a name="catLinkDown" href="#" onfocusset="catLink5" onfocus="catDown();" onfocusload=""></a>
<a name="genLinkUp" href="#" onfocusset="genLink5" onfocus="genUp();" onfocusload=""></a>
<a name="genLinkDown" href="#" onfocusset="genLink5" onfocus="genDown();" onfocusload=""></a>
</div>
<?
$this->printSpeedDial();
}
parent::printFooter();
}
public static function setNumPagesAndIndexCount($totalRecordCount)
{
global $page, $numPages, $indexStyle, $pageObj;
$pageObj->indexStyle = $indexStyle;
$numPages = ceil($totalRecordCount / $indexStyle->Limit);
$indexStyle->setIndexCount($page < $numPages ?
$indexStyle->Limit :
$totalRecordCount - ($indexStyle->Limit * ($page-1)));
}
private static function isStartOfRow($position)
{
global $indexStyle;
return ($position % $indexStyle->nbThumbnailsPerLine == 0);
}
private static function isLastRow($row)
{
global $lastRow;
return ($row == $lastRow);
}
private static function isEndOfRow($position)
{
global $indexStyle;
return ($position % $indexStyle->nbThumbnailsPerLine == $indexStyle->nbThumbnailsPerLine - 1);
}
private function isEndOfMenuItems($position)
{
// check if position would be past valid menuitems limit
return ($position >= count($this->menuItems) - 1);
}
private static function printPopup($menuItem, $position)
{
global $indexStyle;
$placement = ($position % $indexStyle->Limit);
$row = intdiv($position % $indexStyle->Limit, $indexStyle->nbThumbnailsPerLine); // mod position by limit to support client side paging
$col = $position % $indexStyle->nbThumbnailsPerLine;
if (!$menuItem || $menuItem->PosterURL) {
?>
<img id="imgDVD<?= $placement ?>" class="menu<?= $placement ?> imgRow<?= $row ?> imgCol<?= $col ?>" src="<?= $menuItem->PosterURL ?>" <?= $indexStyle->hoverFrame ? null : 'onclick="openLinkURL(asMenuURL[iActiveItem]);"' ?> />
<?php
if ($indexStyle->hoverFrame) {
?>
<img id="frmDVD<?= $placement ?>" class="menu<?= $placement ?> frmRow<?= $row ?> frmCol<?= $col ?>" src="<?= $indexStyle->hoverFrame ?>" onclick="openLinkURL(asMenuURL[iActiveItem]);" />
<?php
}
}
}
private function getOnkeyleftset($placement)
{
global $numPages;
$retval = null;
//start of row
if (ListingsPage::isStartOfRow($placement)) {
if ($placement == 0) {
if ($numPages == 1) {
$retval = 'onkeyleftset="' . (count($this->menuItems) - 1) . '"';
} else {
$retval = 'onkeyleftset="pgupload"';
}
} else {
$retval = "onkeyleftset=\"" . ($placement - 1) . "\"";
}
}
return $retval;
}
private function getOnkeyrightset($placement, $row)
{
global $numPages;
$retval = null;
if ((ListingsPage::isEndOfRow($placement) && ListingsPage::isLastRow($row))
|| $this->isEndOfMenuItems($placement)
) {
if ($numPages == 1) {
//go to first item
$retval = 'onkeyrightset="0"';
} else {
$retval = 'onkeyrightset="pgdnload"';
}
} else {
$retval = "onkeyrightset=\"" . ($placement + 1) . "\"";
}
return $retval;
}
private function getOnkeydownset($placement, $row, $wrapBottomRowToTop)
{
global $indexStyle, $numPages;
$retval = null;
//last row
if (ListingsPage::isLastRow($row)) {
if ($numPages == 1) {
if ($wrapBottomRowToTop) {
//go to top row
$topofcolumn = $placement % $indexStyle->nbThumbnailsPerLine;
$retval = " onkeydownset=\"" . $topofcolumn . "\" ";
}
} else {
//down arrow goes to next page
$retval = " onkeydownset=\"pgdnload\"";
}
} else {
// go to next row
$nextdown = min($placement + $indexStyle->nbThumbnailsPerLine, count($this->menuItems) - 1);
$retval = " onkeydownset=\"" . $nextdown . "\" ";
}
return $retval;
}
//gap is for skipping rows, in sets on the bottom
private function printPosterTD($menuItem, $position, $row, $wrapBottomRowToTop)
{
global $indexStyle;
$placement = ($position % $indexStyle->Limit);
if (!$menuItem) {
$menuItem = (object) [];
$menuItem->PosterURL = "images/wall/transparent.png";
}
?>
<td align="center" <?
if (!$menuItem->PosterURL) {
?>class="defaultCardBackground<?= ($position % 5) + 1 ?>" width="<?= $indexStyle->thumbnailsWidth ?>" height="<?= $indexStyle->thumbnailsHeight ?>"<?
} ?> >
<a href="#" onclick="openLinkURL(asMenuURL[iActiveItem]);" <?= $menuItem->OnDemandTag ?? null ?> name="<?= $placement ?>" onmouseover="show(<?= $placement ?>)" onfocus="show(<?= $placement ?>)" onblur="hide(<?= $placement ?>)"
id="<?= $placement ?>"
<?php
echo ListingsPage::getOnkeyleftset($placement);
echo ListingsPage::getOnkeyrightset($placement, $row);
echo ListingsPage::getOnkeydownset($placement, $row, $wrapBottomRowToTop);
?>>
<?
if ($menuItem->PosterURL) {
?>
<img id="menuImg<?= $placement ?>" src="<?= $menuItem->PosterURL ?>" width="<?= $indexStyle->thumbnailsWidth ?>" height="<?= $indexStyle->thumbnailsHeight ?>" onfocussrc="images/wall/transparent.png" />
<?
} else {
echo $menuItem->Name;
}
?></a>
</td>
<?php
}
}