forked from Regss/movielib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
910 lines (815 loc) · 41.2 KB
/
index.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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
<?PHP
session_start();
header('Content-type: text/html; charset=utf-8');
include('config.php');
include('function.php');
if (!file_exists('db.php')) {
if (file_exists('install.php')) {
header('Location:install.php');
die('Can\'t redirect to install.php');
}
die('Copy install.php file to script directory');
}
// connect to database
connect($mysql_ml);
// get settings from db
$setting = get_settings();
include('lang/' . $setting['language'] . '/lang.php');
/* ##################
* # CHECK PASSWORD #
*/##################
if ($setting['protect_site'] == 1) {
if ($_SESSION['logged'] !== true) {
header('Location:login.php');
die('Can\'t redirect to login.php');
}
}
/* #################
* # DEFINE ARRAYS #
*/#################
if (!isset($_GET['video'])) {
$video = 'movies';
} else {
$video = $_GET['video'];
}
/* ############
* # FACEBOOK #
*/############
if ($fb_link !== '') {
if ($video == 'tvshows') {
$face_sql = 'SELECT id FROM tvshows WHERE title="' . urldecode($fb_link) . '" LIMIT 0, 1';
} else {
$face_sql = 'SELECT id FROM movies WHERE title="' . urldecode(substr($fb_link, 0, -4)) . '" AND year="' . substr($fb_link, -4, 4) . '" LIMIT 0, 1';
}
$face_res = mysql_q($face_sql);
$face_id = mysql_fetch_assoc($face_res);
$id = $face_id['id'];
}
// views
$view = $setting['view'];
if (isset($_COOKIE['view'])) {
$view = $_COOKIE['view'];
}
if (isset($_GET['view'])) {
$view = $_GET['view'];
setcookie('view', $view, time()+(60 * 60 * 24 * 7));
}
if ($id == 0) {
$include_view = $view;
} else {
$include_view = 0;
}
// output and show arrays
$output = array();
$show = array();
foreach ($item as $val) {
$output[$val] = '';
$show[$val] = 0;
}
// sort selected
if (isset($_GET['sort'])) {
$sort = $_GET['sort'];
} else {
$sort = $setting['default_sort'];
}
// sort selected
if (isset($_GET['watch'])) {
$watch = $_GET['watch'];
} else {
$watch = $setting['default_watch'];
}
$output['version'] = $version;
$output['view'] = $view;
$output['include_view'] = $views[$include_view];
$output['video'] = $video;
$output['watch'] = $watch;
if ($id == 0) {
$output['url_delete_filter'] = create_url($setting, array('video' => $video, 'view' => $view, 'sort' => $sort));
} else {
$output['url_delete_filter'] = create_url($setting, array('video' => $video, 'view' => $view, 'sort' => $sort, 'filter' => $filter, 'filterid' => $filterid));
}
/* ################
* # SELECT MEDIA #
*/################
if ($video == 'tvshows') {
$mysql_table = 'tvshows';
} else {
$mysql_table = 'movies';
}
$output['select_media'] = '<a class="' . ($video == 'movies' ? "selected" : "") . '" href="' . create_url($setting, array('video' => 'movies', 'view' => $view)) . '">' . mb_strtoupper($lang['i_movies']) . '</a><a class="' . ($video == 'tvshows' ? "selected" : "") . '" href="' . create_url($setting, array('video' => 'tvshows', 'view' => $view)) . '">' . mb_strtoupper($lang['i_tvshows']) . '</a>';
if ($setting['select_media_header'] == 1) {
$count_movies = mysql_result(mysql_q('SELECT COUNT( * ) FROM movies'), 0);
$count_tvshows = mysql_result(mysql_q('SELECT COUNT( * ) FROM tvshows'), 0);
if ($count_movies == 0 or $count_tvshows == 0) {
$output['select_media'] = '';
}
}
/* #############
* # TOP PANEL #
*/#############
$show['panel_top'] = $setting['panel_top'];
if ($setting['panel_top'] == 1) {
$top_panel_sql = array(
'top_item_last_added' => 'SELECT id, title, date_added, hide FROM ' . $mysql_table . ' WHERE hide=0 ORDER BY date_added DESC LIMIT ' . $setting['panel_top_limit'],
'top_item_most_watched' => 'SELECT id, title, hide FROM ' . $mysql_table . ' WHERE hide=0 ORDER BY play_count DESC LIMIT ' . $setting['panel_top_limit'],
'top_item_last_played' => 'SELECT id, title, last_played, hide FROM ' . $mysql_table . ' WHERE hide=0 ORDER BY last_played DESC LIMIT ' . $setting['panel_top_limit'],
'top_item_top_rated' => 'SELECT id, title, rating, hide FROM ' . $mysql_table . ' WHERE hide=0 ORDER BY rating DESC LIMIT ' . $setting['panel_top_limit']
);
foreach ($top_panel_sql as $name => $item_top_sql) {
$output[$name] = '';
$item_top_result = mysql_q($item_top_sql);
while ($item_top = mysql_fetch_array($item_top_result)) {
if (file_exists('cache/' . $mysql_table . '_' . $item_top['id'] . '.jpg')) {
$output[$name].= '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'id' => $item_top['id'])) . '"><img src="cache/' . $mysql_table . '_' . $item_top['id'] . '.jpg" title="' . $item_top['title'] . '" alt=""></a>';
}
}
}
}
/* ####################
* # ARRAYS FOR PANEL #
*/####################
if ($video == 'tvshows') {
$columns = array('actor', 'genre', 'premiered');
} else {
$columns = array('actor', 'genre', 'country', 'year', 'director', 'set', 'studio');
}
$panels_array = panels_array($columns, $mysql_table);
$filter_array = array('actor', 'genre', 'country', 'studio', 'director');
if ($filter == '') {
$mysql_table2 = '';
$filter_mysql = '';
} else if (in_array($filter, $filter_array)) {
$mysql_table2 = ', ' . $mysql_table . '_' . $filter;
$filter_mysql = $mysql_table . '_' . $filter . '.' . $filter . 'id = '. $filterid . ' AND ' . $mysql_table . '.id = ' . $mysql_table . '_' . $filter . '.id AND';
} else {
$mysql_table2 = '';
$filter_mysql = $mysql_table . '.' . $filter . ' LIKE "%' . $panels_array[$filter][$filterid] . '%" AND';
}
/* ##############
* # LEFT PANEL #
*/##############
// overall panel
$show['panel_overall'] = $setting['panel_overall'];
if ($setting['panel_overall'] > 0) {
$overall_sql = 'SELECT play_count, hide FROM ' . $mysql_table . ' WHERE hide=0';
$overall_result = mysql_q($overall_sql);
$overall_all = mysql_num_rows($overall_result);
$overall_watched = 0;
while($overall = mysql_fetch_array($overall_result)) {
if ($overall['play_count'] > 0) {
$overall_watched++;
}
}
$output['overall_all'] = $overall_all;
$output['overall_watched'] = $overall_watched;
$output['overall_unwatched'] = $overall_all - $overall_watched;
}
// menu panel
$menu_array = array('genre', 'year', 'country', 'set', 'studio');
foreach ($menu_array as $menu_name) {
$output['panel_' . $menu_name] = '';
if ($setting['panel_' . $menu_name] <> 0 && isset($panels_array[$menu_name]) && count($panels_array[$menu_name]) > 0) {
$show['panel_' . $menu_name] = 1;
foreach ($panels_array[$menu_name] as $key => $val) {
if ($filter == $menu_name && $filterid == $key) {
$output['panel_' . $menu_name].= '<li>' . $val . '</li>';
} else {
$output['panel_' . $menu_name].= '<li><a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => $menu_name, 'filterid' => $key)) . '">' . $val . '</a></li>';
}
}
}
}
/* ########
* # SORT #
*/########
$sort_array = array(
1 => array($lang['i_title'], 'title ASC'),
2 => array($lang['i_premiered'], 'premiered DESC'),
3 => array($lang['i_year'], 'year DESC'),
4 => array($lang['i_rating'], 'rating DESC'),
5 => array($lang['i_added'], 'date_added DESC'),
6 => array($lang['i_runtime'], ' CAST( runtime AS DECIMAL( 10, 2 ) ) DESC'),
7 => array($lang['i_last_played'], 'last_played DESC'),
8 => array($lang['i_most_watched'], 'play_count DESC')
);
if ($video == 'tvshows') {
unset($sort_array[3], $sort_array[6]);
} else {
unset($sort_array[2]);
}
$output['panel_sort'] = '';
foreach ($sort_array as $key => $val) {
$output['panel_sort'].= ($sort == $key ?
'<span>' . $val[0] . '</span>' :
'<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $key,
'filter' => $filter,
'filterid' => $filterid)) .
'" title="' . $lang['i_sort'] . '">' . $val[0] . '</a>');
}
/* #########
* # WATCH #
*/#########
$show['panel_watch'] = 1;
$watch_arr = array(0 => 'all', 1 => 'watched', 2 => 'unwatched');
$output['panel_watch'].= '<div id="watch_menu"><div id="watch_title">' . $lang['i_watched_status'] . ': ' . $lang['i_' . $watch_arr[$watch]] . '</div><div id="watches">';
foreach ($watch_arr as $key => $val) {
if ($watch == $key) {
$output['panel_watch'].= '<span>' . $lang['i_' . $val] . '</span>';
} else {
$output['panel_watch'].= '<a href="' . create_url($setting, array('id' => $id, 'video' => $video, 'view' => $view, 'watch' => $key, 'sort' => $sort, 'filter' => $filter, 'filterid' => $filterid)) . '">' . $lang['i_' . $val] . '</a>';
}
}
if ($watch == 1) {
$watch_mysql = ' > 0';
} elseif ($watch == 2) {
$watch_mysql = ' = 0';
} else {
$watch_mysql = ' >= 0';
}
$output['panel_watch'].= '</div></div>';
/* ########
* # VIEW #
*/########
if ($setting['panel_view'] > 0) {
$show['panel_view'] = 1;
$output['panel_view'].= '<div id="view_menu"><div id="view_title">' . $lang['i_view'] . ': ' . $lang['i_' . $views[$view]] . '</div><div id="views">';
foreach ($views as $key => $val) {
if ($view == $key) {
$output['panel_view'].= '<span>' . $lang['i_' . $val] . '</span>';
} else {
$output['panel_view'].= '<a href="' . create_url($setting, array('id' => $id, 'video' => $video, 'view' => $key, 'watch' => $watch, 'sort' => $sort, 'filter' => $filter, 'filterid' => $filterid)) . '">' . $lang['i_' . $val] . '</a>';
}
}
$output['panel_view'].= '</div></div>';
}
/* ##########
* # SEARCH #
*/##########
$show['panel_live_search'] = $setting['live_search'];
$search_mysql = '%';
if ($search !== '') {
$search_mysql = $search;
}
/* #############
* # PANEL NAV #
*/#############
$id_mysql = ($id == 0 ? '%' : $id);
$nav_sql = 'SELECT ' . $mysql_table . '.id FROM ' . $mysql_table . $mysql_table2 . ' WHERE
' . $filter_mysql . '
' . $mysql_table . '.title LIKE "%' . $search_mysql . '%" AND
' . $mysql_table . '.id LIKE "' . $id_mysql . '" AND
' . $mysql_table . '.play_count ' . $watch_mysql . ' AND
' . $mysql_table . '.hide=0
ORDER BY ' . $sort_array[$sort][1];
$nav_result = mysql_q($nav_sql);
$row = mysql_num_rows($nav_result);
if ($setting['per_page'] == 0) {
$i_pages = 1;
$output['panel_nav'] = '';
} else {
$i_pages = (ceil($row / $setting['per_page']));
$output['panel_nav'] = ($page == 1 ? '<span>' . $lang['i_previous'] . '</span>' : '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'page' => ($page - 1), 'filter' => $filter, 'filterid' => $filterid, 'search' => $search)) . '">' . $lang['i_previous'] . '</a>')
. ' <span>' . $lang['i_page'] . ' ' . $page . ' / ' . $i_pages . '</span> ' .
($page == $i_pages ? '<span>' . $lang['i_next'] . '</span>' : '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'page' => ($page + 1), 'filter' => $filter, 'filterid' => $filterid, 'search' => $search)) . '">' . $lang['i_next'] . '</a>');
if ($row == 0) {
$output['panel_nav'] = '';
}
}
/* ################
* # PANEL FILTER #
*/################
if ($filter !== '') {
$output['panel_filter'] = '<span>' . $lang['i_filter'] . ': </span>' . $lang['i_' . $filter] . ' » ' . $panels_array[$filter][$filterid];
$show['panel_filter'] = 1;
}
if ($search !== '') {
$output['panel_filter'] = '<span>' . $lang['i_search'] . ': </span>' . $lang['i_result'] . ' » ' . $search;
$show['panel_filter'] = 1;
}
if ($id > 0) {
$output['panel_filter'] = '<span>' . $lang['i_filter'] . ': </span>' . $lang['i_title'];
$show['panel_filter'] = 1;
}
/* ##################
* # CONTROL REMOTE #
*/##################
if (isset($_SESSION['logged_admin']) && $_SESSION['logged_admin'] == true) {
$show['panel_remote'] = 1;
}
/* ##############
* # MOVIE LIST #
*/##############
if ($setting['per_page'] == 0) {
$limit_sql = '';
} else {
$start = ($page - 1) * $setting['per_page'];
$limit_sql = ' LIMIT ' . $start . ', ' . $setting['per_page'];
}
$list_sql = 'SELECT ' . $mysql_table . '.* FROM ' . $mysql_table . $mysql_table2 . ' WHERE
' . $filter_mysql . '
' . $mysql_table . '.title LIKE "%' . $search_mysql . '%" AND
' . $mysql_table . '.id LIKE "' . $id_mysql . '" AND
' . $mysql_table . '.play_count ' . $watch_mysql . ' AND
' . $mysql_table . '.hide=0
ORDER BY ' . $sort_array[$sort][1] . $limit_sql;
$list_result = mysql_q($list_sql);
// get date for last added
$new_sql = 'SELECT ' . $mysql_table . '.date_added FROM ' . $mysql_table . ' ORDER BY ' . $mysql_table . '.date_added DESC LIMIT 0, 1';
$new_result = mysql_q($new_sql);
$new_date = mysql_fetch_assoc($new_result);
$new_date = substr($new_date['date_added'], 0, 10);
$output_panel_list = '';
while ($list = mysql_fetch_assoc($list_result)) {
// output and show desc arrays
$output_desc = array();
$show_desc = array();
foreach ($item_desc as $val) {
$output_desc[$val] = '';
$show_desc[$val] = 0;
}
$output_desc['mysql_table'] = $mysql_table;
$output_desc['id'] = $list['id'];
$output_desc['video'] = $video;
$output_desc['view'] = $view;
$output_desc['sort'] = $sort;
$output_desc['title'] = $list['title'];
$show_desc['mysql_table'] = 1;
$show_desc['id'] = 1;
$show_desc['video'] = 1;
$show_desc['title'] = 1;
if (isset($_SESSION['logged_admin']) && $_SESSION['logged_admin'] == true && $video == 'movies') {
$show_desc['xbmc'] = 1;
}
// link title
$output_desc['url_title'] = create_url($setting, array('id' => $list['id'], 'video' => $video, 'view' => $view, 'sort' => $sort, 'filter' => $filter, 'filterid' => $filterid));
// originaltitle
if ($list['originaltitle'] !== '') {
$show_desc['originaltitle'] = 1;
$output_desc['originaltitle'] = $list['originaltitle'];
}
// file
if ($video == 'movies') {
$output_desc['file'] = 'http://' . $setting['xbmc_login'] . ':' . $setting['xbmc_pass'] . '@' . $setting['xbmc_host'] . ':' . $setting['xbmc_port'] . '/vfs/' . urlencode($list['file']);
}
// poster
$poster = 'cache/' . $mysql_table . '_' . $list['id'] . '.jpg';
if (!file_exists($poster)) {
$output_desc['poster'] = 'templates/' . $setting['theme'] . '/img/d_poster.jpg';
} else {
$output_desc['poster'] = $poster;
}
// wached status
if ($setting['watched_status'] == 1 && $list['play_count'] > 0) {
$output_desc['watched_img'] = '<img class="watched_img" src="templates/' . $setting['theme'] . '/img/watched.png" title="' . $lang['i_last_played'] . ': ' . $list['last_played'] . '" alt="">';
}
// play count
if ($setting['show_playcount'] == 1 && $list['play_count'] > 0) {
$playcount_array = str_split($list['play_count']);
$output_desc['playcount_img'] = '<div class="playcount_block">';
foreach ($playcount_array as $int) {
$output_desc['playcount_img'].= '<img class="playcount_img" src="templates/' . $setting['theme'] . '/img/' . $int . '.png" title="' . $lang['i_last_played'] . ': ' . $list['last_played'] . '" alt="">';
}
$output_desc['playcount_img'].= '</div>';
}
// genre
$output_genre_array = array();
$genre_sql = 'SELECT genre.id, genre.genre FROM genre, ' . $video . '_genre WHERE ' . $video . '_genre.id = "' . $list['id'] . '" AND genre.id = ' . $video . '_genre.genreid';
$genre_res = mysql_q($genre_sql);
while ($val = mysql_fetch_assoc($genre_res)) {
$output_genre_array[] = '<a href="'. create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'genre', 'filterid' => $val['id'])) . '">' . $val['genre'] . '</a>';
}
if (count($output_genre_array) > 0) {
$show_desc['genre'] = 1;
$output_desc['genre'] = implode(' / ', $output_genre_array);
}
// rating
if ($list['rating'] !== '') {
$show_desc['rating'] = 1;
$output_desc['rating'] = $list['rating'];
$show_desc['rating_star'] = 1;
$output_desc['rating_star'] = '';
$r = $output_desc['rating'];
for ($s = 1; $s <= 10; $s++) {
if ($r >= 1) {
$output_desc['rating_star'].= '<img src="templates/' . $setting['theme'] . '/img/star.png"> ';
} else if ($r >= 0.5) {
$output_desc['rating_star'].= '<img src="templates/' . $setting['theme'] . '/img/star_h.png"> ';
} else {
$output_desc['rating_star'].= '<img src="templates/' . $setting['theme'] . '/img/star_g.png"> ';
}
$r--;
}
}
// actors
$output_actor_array = array();
$actor_sql = 'SELECT actor.id, actor.actor FROM actor, ' . $video . '_actor WHERE ' . $video . '_actor.id = "' . $list['id'] . '" AND actor.id = ' . $video . '_actor.actorid ORDER BY ' . $video . '_actor.order';
$actor_res = mysql_q($actor_sql);
while ($val = mysql_fetch_assoc($actor_res)) {
if ($val['actor'] !== '') {
if (file_exists('cache/actors/' . substr(md5($val['actor']), 0, 10) . '.jpg')) {
$actor_thumb = '<img class="actor_thumb" src="cache/actors/' . substr(md5($val['actor']), 0, 10) . '.jpg">';
} else {
$actor_thumb = '';
}
$output_actor_array[] = '<a class="actor_img" href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'actor', 'filterid' => $val['id'])) . '" alt="' . substr(md5($val['actor']), 0, 10) . '">' . $actor_thumb . $val['actor'] . '</a>';
}
}
if (count($output_actor_array) > 0) {
$show_desc['actor'] = 1;
$output_desc['actor'] = implode(' / ', $output_actor_array);
}
// plot
if ($list['plot'] !== '') {
$show_desc['plot'] = 1;
$output_desc['plot'] = $list['plot'];
}
// only movies
if ($video == 'movies') {
// year
if ($list['year'] !== '') {
$show_desc['year'] = 1;
$output_desc['year'] = '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'year', 'filterid' => array_search($list['year'], $panels_array['year']))) . '">' . $list['year'] . '</a>';
}
// country
$output_country_array = array();
$country_sql = 'SELECT country.id, country.country FROM country, ' . $video . '_country WHERE ' . $video . '_country.id = "' . $list['id'] . '" AND country.id = ' . $video . '_country.countryid';
$country_res = mysql_q($country_sql);
while ($val = mysql_fetch_assoc($country_res)) {
$output_country_array[] = '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'country', 'filterid' => $val['id'])) . '">' . $val['country'] . '</a>';
}
if (count($output_country_array) > 0) {
$show_desc['country'] = 1;
$output_desc['country'] = implode(' / ', $output_country_array);
}
// runtime
if ($list['runtime'] !== NULL) {
$show_desc['runtime'] = 1;
$output_desc['runtime'] = $list['runtime'];
}
// director
$director_sql = 'SELECT director.id, director.director FROM director, ' . $video . '_director WHERE ' . $video . '_director.id = "' . $list['id'] . '" AND director.id = ' . $video . '_director.directorid';
$director_res = mysql_q($director_sql);
$val = mysql_fetch_assoc($director_res);
if (isset($val['director'])) {
$show_desc['director'] = 1;
$output_desc['director'] = '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'director', 'filterid' => $val['id'])) . '">' . $val['director'] . '</a>';
}
// set
if ($list['set'] !== '') {
$show_desc['set'] = 1;
$output_desc['set'] = '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'set', 'filterid' => array_search($list['set'], $panels_array['set']))) . '">' . $list['set'] . '</a>';
}
// imdb id
if ($list['imdbid'] !== '' && $list['imdbid']{0} == 't') {
$output_desc['imdb_url'] = '<a target="_blank" href="http://www.imdb.com/title/' . $list['imdbid'] . '/"><img class="imdb_img" src="templates/' . $setting['theme'] . '/img/imdb.png"></a>';
}
// studio
$studio_sql = 'SELECT studio.id, studio.studio FROM studio, ' . $video . '_studio WHERE ' . $video . '_studio.id = "' . $list['id'] . '" AND studio.id = ' . $video . '_studio.studioid';
$studio_res = mysql_q($studio_sql);
$val = mysql_fetch_assoc($studio_res);
if (isset($val['studio'])) {
$show_desc['studio'] = 1;
$output_desc['studio'] = '<a href="' . create_url($setting, array('video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => 'studio', 'filterid' => $val['id'])) . '">' . $val['studio'] . '</a>';
if (file_exists('templates/' . $setting['theme'] . '/img/studios/' . $val['studio'] . '.png')) {
$show_desc['studio_art'] = 1;
$output_desc['studio_art'] = '<img class="studio" src="templates/' . $setting['theme'] . '/img/studios/' . $val['studio'] . '.png">';
}
}
// ribbon new
if (substr($list['date_added'], 0, 10) == $new_date) {
$show_desc['ribbon_new'] = 1;
$output_desc['ribbon_new'] = '<div class="ribbon_new_text">' . mb_strtoupper($lang['i_ribbon_new']) . '</div><img class="ribbon_new" src="templates/' . $setting['theme'] . '/img/ribbon_new.png">';
}
// streams
$stream_sql = 'SELECT * FROM `movies_stream` WHERE id = "' . $list['id'] . '"';
$stream_res = mysql_q($stream_sql);
if (mysql_num_rows($stream_res) > 0) {
$str = array('v' => array(), 'a' => array(), 's' => array());
while ($stream = mysql_fetch_assoc($stream_res)) {
$str[$stream['type']][] = $stream;
}
}
$img_flag_vres = '';
$img_flag_vtype = '';
$img_flag_vq = '';
if (isset($str['v'])) {
foreach ($str['v'] as $s) {
// video resolution
foreach ($vres_assoc as $key => $val) {
if (is_numeric($s['v_width']) && $s['v_width'] >= $key) {
$img_flag_vres = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/vres_' . $val . '.png" alt="">';
}
}
// video codec
foreach ($vtype_assoc as $key => $val) {
if (in_array($s['v_codec'], $vtype_assoc[$key])) {
$img_flag_vtype = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/vc_' . $key . '.png" alt="">';
}
}
// video sd, hd or uhd
$img_flag_vq = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/v_sd.png" alt="">';
if (is_numeric($s['v_width']) && $s['v_width'] >= 1280) {
$img_flag_vq = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/v_hd.png" alt="">';
}
if (is_numeric($s['v_width']) && $s['v_width'] >= 3000) {
$img_flag_vq = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/v_uhd.png" alt="">';
}
$output_desc['img_flag_v'].= '<div>' . $img_flag_vres . $img_flag_vtype . $img_flag_vq . '</div>';
}
}
if (isset($str['a'])) {
foreach ($str['a'] as $s) {
// audio codec
foreach ($atype_assoc as $key => $val) {
if(in_array($s['a_codec'], $atype_assoc[$key])) {
$img_flag_atype = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/ac_' . $key . '.png" alt="">';
}
}
// audio channel
foreach ($achan_assoc as $val) {
if (is_numeric($s['a_chan']) && $s['a_chan'] >= $val) {
$img_flag_achan = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/ach_' . $val . '.png" alt="">';
}
}
// audio language
if (file_exists('templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['a_lang'], $iso_lang) . '.png')) {
$img_flag_alang = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['a_lang'], $iso_lang) . '.png" alt="">';
} else {
$img_flag_alang = $s['a_lang'];
}
$output_desc['img_flag_a'].= '<div>' . $img_flag_atype . $img_flag_achan . $img_flag_alang . '</div>';
}
}
// subtitles
if (isset($str['s'])) {
foreach ($str['s'] as $s) {
if (file_exists('templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['s_lang'], $iso_lang) . '.png')) {
$img_flag_slang = '<img src="templates/' . $setting['theme'] . '/img/flags/sub.png" alt=""><img class="flag" src="templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['s_lang'], $iso_lang) . '.png" alt="">';
} else {
$img_flag_slang = $s['s_lang'];
}
$output_desc['img_flag_s'].= '<div>' . $img_flag_slang . '</div>';
}
}
// extra thumbs
$ex_thumb_array = array();
for ($c=1;$c<10;$c++) {
$ex_t = 'cache/movies_' . $list['id'] . '_t' . $c . 'm.jpg';
if (file_exists($ex_t)) {
$ex_thumb_array[] = '<img src="' . $ex_t . '">';
}
}
if (count($ex_thumb_array) > 0) {
$show_desc['extra_thumbs'] = 1;
$output_desc['extra_thumbs'] = '<div class="ex_thumbs">' . implode('', $ex_thumb_array) . '</div>';
}
// trailer
if ($list['trailer'] !== '' && $setting['show_trailer'] == 1) {
$output_desc['trailer_img'] = '<a href="' . create_url($setting, array('id' => $list['id'], 'video' => $video, 'view' => $view, 'watch' => $watch, 'sort' => $sort, 'filter' => $filter, 'filterid' => $filterid)) . '#trailer"><img class="trailer_img animate" src="templates/' . $setting['theme'] . '/img/trailer.png" title="' . $lang['i_show_trailer'] . '" alt=""></a>';
}
if ($list['trailer'] !== '' && $setting['show_trailer'] == 1 && $id <> 0) {
$show_desc['trailer'] = 1;
if (substr($list['trailer'], 0, 18) == 'http://www.youtube') {
$output_desc['trailer'].= '
<iframe id="player" type="text/html" width="560" height="260" src="' . $list['trailer'] . '" frameborder="0"></iframe>
';
} else {
$ext = substr($list['trailer'], strrpos($list['trailer'], '.')+1, strlen($list['trailer']));
foreach ($mimetype_assoc as $key => $val) {
if(in_array($ext, $val)) {
$mimetype = $key;
break;
} else {
$mimetype = '';
}
}
if ($ext == 'mov') {
$output_desc['trailer'].= '
<embed src="' . $list['trailer'] . '" width="560" height="260" cache="false" autoplay="false" scale="tofit" />';
} else {
$output_desc['trailer'].= '
<video id="player" class="video-js vjs-default-skin player" controls preload="none" width="560" height="260" data-setup="{}">
<source src="' . $list['trailer'] . '" type="' . $mimetype . '" />
</video>';
}
}
}
}
// only tvshows
if ($video == 'tvshows') {
// premiered
if ($list['premiered'] !== '') {
$show_desc['premiered'] = 1;
$output_desc['premiered'] = '<a href="' . create_url($setting, array('video' => 'tvshows', 'view' => $view, 'sort' => $sort, 'filter' => 'premiered', 'filterid' => array_search($list['premiered'], $panels_array['premiered']))) . '">' . $list['premiered'] . '</a>';
}
// seasons
$season_array = array();
$seasons_sql = 'SELECT season FROM episodes WHERE tvshow = "' . $list['id'] . '" ORDER BY season';
$seasons_result = mysql_q($seasons_sql);
while ($seasons = mysql_fetch_array($seasons_result)) {
if (!array_key_exists($seasons['season'], $season_array)) {
$season_array[$seasons['season']] = '<a href="' . create_url($setting, array('video' => 'tvshows', 'view' => $view, 'id' => $list['id'])) . '#season_' . $seasons['season'] . '">' . $lang['i_season'] . ' ' . $seasons['season'] . '</a>';
}
}
if (count($season_array) <> 0) {
$show_desc['seasons'] = 1;
$output_desc['seasons'] = implode(' / ', $season_array);
}
// episodes
if ($id <> 0) {
// get date for last added episode
$new_episode_sql = 'SELECT date_added FROM episodes ORDER BY date_added DESC LIMIT 0, 1';
$new_episode_result = mysql_q($new_episode_sql);
$new_episode_date = mysql_fetch_assoc($new_episode_result);
$new_episode_date = substr($new_episode_date['date_added'], 0, 10);
$show_desc['episodes'] = 1;
$episodes_sql = 'SELECT id, title, episode, season, plot, firstaired, file, play_count, date_added, last_played FROM episodes WHERE tvshow = "' . $list['id'] . '" ORDER BY season, episode ASC';
$episodes_result = mysql_q($episodes_sql);
$i = -1;
$output_epiosde_list = '';
while ($episodes = mysql_fetch_assoc($episodes_result)) {
// output and show episodes arrays
$output_episode = array();
$show_episode = array();
foreach ($item_episode as $val) {
$output_episode[$val] = '';
$show_episode[$val] = 0;
}
if (isset($_SESSION['logged_admin']) && $_SESSION['logged_admin'] == true && $video == 'tvshows') {
$show_episode['xbmc'] = 1;
}
$output_episode['episode'] = $episodes['id'];
$output_episode['season'] = $episodes['season'];
$output_episode['plot'] = $episodes['plot'];
$output_episode['aired'] = $episodes['firstaired'];
// title
$output_episode['title'] = $episodes['episode'] . '. ' . ($episodes['title'] == '' ? $lang['i_episode'] . ' ' . $episodes['episode'] : $episodes['title']);
// file
$output_episode['file'] = 'http://' . $setting['xbmc_login'] . ':' . $setting['xbmc_pass'] . '@' . $setting['xbmc_host'] . ':' . $setting['xbmc_port'] . '/vfs/' . urlencode($episodes['file']);
// thumbnail
if (file_exists('cache/episodes_' . $episodes['id'] . '.jpg')) {
$output_episode['thumbnail'] = '<img class="thumbnail" src="cache/episodes_' . $episodes['id'] . '.jpg">';
} else {
$output_episode['thumbnail'] = '<img class="thumbnail" src="templates/' . $setting['theme'] . '/img/d_thumbnail.jpg">';
}
// wached status
if ($setting['watched_status'] == 1 && $episodes['play_count'] > 0) {
$output_episode['watched_img'] = '<img class="episode_watched" src="templates/' . $setting['theme'] . '/img/watched.png" title="' . $lang['i_last_played'] . ': ' . $episodes['last_played'] . '" alt="">';
}
// episode ribbon new
if (substr($episodes['date_added'], 0, 10) == $new_episode_date) {
$output_episode['ribbon_new'] = '<div class="episode_ribbon_new_text">' . mb_strtoupper($lang['i_ribbon_new']) . '</div><img class="episode_ribbon_new" src="templates/' . $setting['theme'] . '/img/ribbon_new.png">';
}
// episode streams
$stream_sql = 'SELECT * FROM `episodes_stream` WHERE id = "' . $episodes['id'] . '"';
$stream_res = mysql_q($stream_sql);
if (mysql_num_rows($stream_res) > 0) {
$str = array('v' => array(), 'a' => array(), 's' => array());
while ($stream = mysql_fetch_assoc($stream_res)) {
$str[$stream['type']][] = $stream;
}
}
$img_flag_vres = '';
$img_flag_vtype = '';
$img_flag_vq = '';
if (isset($str['v'])) {
foreach ($str['v'] as $s) {
// episode video resolution
foreach ($vres_assoc as $key => $val) {
if (is_numeric($s['v_width']) && $s['v_width'] >= $key) {
$img_flag_vres = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/vres_' . $val . '.png" alt="">';
}
}
// episode video codec
foreach ($vtype_assoc as $key => $val) {
if (in_array($s['v_codec'], $vtype_assoc[$key])) {
$img_flag_vtype = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/vc_' . $key . '.png" alt="">';
}
}
// episode video sd, hd or uhd
$img_flag_vq = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/v_sd.png" alt="">';
if (is_numeric($s['v_width']) && $s['v_width'] >= 1280) {
$img_flag_vq = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/v_hd.png" alt="">';
}
if (is_numeric($s['v_width']) && $s['v_width'] >= 3000) {
$img_flag_vq = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/v_uhd.png" alt="">';
}
$output_episode['img_flag_v'].= $img_flag_vres . $img_flag_vtype . $img_flag_vq;
}
}
if (isset($str['a'])) {
foreach ($str['a'] as $s) {
// episode audio codec
foreach ($atype_assoc as $key => $val) {
if(in_array($s['a_codec'], $atype_assoc[$key])) {
$img_flag_atype = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/ac_' . $key . '.png" alt="">';
}
}
// episode audio channel
foreach ($achan_assoc as $val) {
if (is_numeric($s['a_chan']) && $s['a_chan'] >= $val) {
$img_flag_achan = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/ach_' . $val . '.png" alt="">';
}
}
// episode audio language
if (file_exists('templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['a_lang'], $iso_lang) . '.png')) {
$img_flag_alang = '<img class="flag" src="templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['a_lang'], $iso_lang) . '.png" alt="">';
} else {
$img_flag_alang = $s['a_lang'];
}
$output_episode['img_flag_a'].= $img_flag_atype . $img_flag_achan . $img_flag_alang;
}
}
if (isset($str['s'])) {
foreach ($str['s'] as $s) {
// episode subtitles
if (file_exists('templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['s_lang'], $iso_lang) . '.png')) {
$img_flag_slang = '<img src="templates/' . $setting['theme'] . '/img/flags/sub.png" alt=""><img class="flag" src="templates/' . $setting['theme'] . '/img/flags/l_' . check_flag($s['s_lang'], $iso_lang) . '.png" alt="">';
} else {
$img_flag_slang = $s['s_lang'];
}
$output_episode['img_flag_s'].= $img_flag_slang ;
}
}
if ($episodes['season'] <> $i) {
$show_episode['season_title'] = 1;
}
$i = $episodes['season'];
$episode_list = new Teamplate('episodes.tpl', $setting, $lang);
foreach ($output_episode as $key => $val) {
$episode_list->tpl($key, $val);
}
foreach ($show_episode as $key => $val) {
$episode_list->show($key, $val);
}
$output_epiosde_list.= $episode_list->init();
$output_desc['episodes'] = $output_epiosde_list;
}
}
}
// facebook meta data
if ($setting['show_facebook'] == 1) {
$show_desc['facebook_button'] = 1;
}
$url = 'http://' . $_SERVER['SERVER_NAME'] . implode('/', array_slice(explode('/', $_SERVER['REQUEST_URI']), 0, -1)) . '/';
$output_desc['fb_url'] = $url . 'index.php?video=' . $video . '&fb_link=' . urlencode($list['title']) . ($video == 'movies' ? $list['year'] : '');
if ($id <> 0) {
$output['meta_img'] = (file_exists('cache/' . $mysql_table . '_' . $id . '.jpg') ? $url . 'cache/' . $mysql_table . '_' . $id . '.jpg' : 'templates/' . $setting['theme'] . '/img/d_poster.jpg');
$output['meta_title'] = htmlspecialchars($list['title']);
$output['meta_desc'] = htmlspecialchars($list['plot']);
$output['meta_url'] = $output_desc['fb_url'];
$output['meta_type'] = ($video == 'tvshows' ? 'video.tv_show' : 'video.movie');
}
// panel movie
$panel_list = new Teamplate($views[$include_view] . '.tpl', $setting, $lang);
foreach ($output_desc as $key => $val) {
$panel_list->tpl($key, $val);
}
foreach ($show_desc as $key => $val) {
$panel_list->show($key, $val);
}
$output_panel_list.= $panel_list->init();
}
$output['panel_list'] = $output_panel_list;
$output['sort'] = $sort;
// faccebok meta data
if ($id == 0) {
$url = 'http://' . $_SERVER['SERVER_NAME'] . implode('/', array_slice(explode('/', $_SERVER['REQUEST_URI']), 0, -1)) . '/';
$output['meta_title'] = $setting['site_name'];
$output['meta_url'] = $url . 'index.php';
$output['meta_img'] = $url . ('templates/' . $setting['theme'] . '/img/logo.jpg');
$output['meta_type'] = 'website';
$output['meta_desc'] = 'Page whereby using XBMC can present your library of movies and TV series.';
}
if ($setting['show_facebook'] == 1) {
$show['facebook'] = 1;
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$get_lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
} else {
$get_lang = 'en';
}
if (array_key_exists ($get_lang , $lang_fb_assoc)) {
$lang_fb = $lang_fb_assoc[$get_lang];
} else {
$lang_fb = $lang_fb_assoc['en'];
}
$output['facebook'] = '<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/' . $lang_fb . '/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));</script>';
}
// create page
$index = new Teamplate('index.tpl', $setting, $lang);
foreach ($output as $key => $val) {
$index->tpl($key, $val);
}
foreach ($show as $key => $val) {
$index->show($key, $val);
}
$site = $index->init();
print $site;
?>