-
Notifications
You must be signed in to change notification settings - Fork 0
/
movies.php
150 lines (126 loc) · 3.7 KB
/
movies.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
<?php
/**
* movies
*
* @package Sngine
* @author Zamblek
*/
// fetch bootloader
require('bootloader.php');
// movies enabled
if(!$system['movies_enabled']) {
_error(404);
}
// user access
if(!$system['system_public']) {
user_access();
}
try {
// get view content
$_GET['view'] = (isset($_GET['view']))? $_GET['view'] : '';
switch ($_GET['view']) {
case '':
// prepare query
/* prepare where query */
$where_query = "";
/* prepare pager url */
$url = "";
// page header
page_header($system['system_title'].' - '.__("Movies"));
break;
case 'search':
// check query
if(!isset($_GET['query']) || is_empty($_GET['query'])) {
redirect('/movies');
}
/* assign variables */
$smarty->assign('query', $_GET['query']);
// prepare query
/* prepare where query */
$where_query = sprintf('WHERE (title LIKE %1$s OR description LIKE %1$s OR stars LIKE %1$s)', secure($_GET['query'], 'search') );
/* prepare pager url */
$url = "/search/".$_GET['query'];
// page header
page_header($system['system_title'].' - '.__("Movies"));
break;
case 'genre':
// get genre
$genre = $user->get_movies_genre($_GET['genre_id']);
if(!$genre) {
_error(404);
}
/* assign variables */
$smarty->assign('genre', $genre);
// prepare query
/* prepare where query */
$where_query = sprintf("WHERE find_in_set(%s, genres) > 0", secure($genre['genre_id'], 'int'));
/* prepare pager url */
$url = "/genre/".$genre['genre_id']."/".$genre['genre_url'];
// page header
page_header($system['system_title'].' - '.__("Movies").' - '.__($genre['genre_name']), __($genre['genre_description']));
break;
case 'movie':
// movies permission
if($user->_logged_in) {
if(!$user->_data['can_watch_movies']) {
_error('PERMISSION');
}
} else {
if($system['movies_permission'] != "everyone") {
_error('PERMISSION');
}
}
// get movie
$movie = $user->get_movie($_GET['movie_id']);
if(!$movie) {
_error(404);
}
/* assign variables */
$smarty->assign('movie', $movie);
// page header
page_header($movie['title'], $movie['description'], $movie['poster']);
break;
default:
_error(404);
break;
}
if($_GET['view'] != "movie") {
// prepare pager
require('includes/class-pager.php');
$params['selected_page'] = ( (int) $_GET['page'] == 0) ? 1 : $_GET['page'];
$total = $db->query("SELECT COUNT(*) as count FROM movies ".$where_query) or _error("SQL_ERROR");
$params['total_items'] = $total->fetch_assoc()['count'];
$params['items_per_page'] = $system['min_results_even'];
$params['url'] = $system['system_url'].'/movies'.$url.'/%s';
$pager = new Pager($params);
$limit_query = $pager->getLimitSql();
// get movies
$movies = array();
$get_movies = $db->query("SELECT * FROM movies ".$where_query." ORDER BY movie_id DESC ".$limit_query) or _error("SQL_ERROR");
while($movie = $get_movies->fetch_assoc()) {
$movie['poster'] = get_picture($movie['poster'], 'movie');
$movie['movie_url'] = get_url_text($movie['title']);
$movie['genres_list'] = $user->get_movie_genres($movie['genres']);
$movies[] = $movie;
}
/* assign variables */
$smarty->assign('movies', $movies);
$smarty->assign('total', $params['total_items']);
$smarty->assign('pager', $pager->getPager());
// get ads
$ads = $user->ads('movies');
/* assign variables */
$smarty->assign('ads', $ads);
}
// assign view
$smarty->assign('view', $_GET['view']);
// get movies genres
$genres = $user->get_movies_genres();
/* assign variables */
$smarty->assign('genres', $genres);
} catch (Exception $e) {
_error(__("Error"), $e->getMessage());
}
// page footer
page_footer("movies");
?>