forked from andig/videodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.php
309 lines (260 loc) · 8.69 KB
/
show.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
<?php
/**
* Movie Detail View
*
* Shows all data of a movie
*
* @package videoDB
* @author Andreas Gohr <[email protected]>
* @author Andreas Goetz <[email protected]>
* @version $Id: show.php,v 2.52 2013/03/15 16:42:46 andig2 Exp $
*/
require_once './core/functions.php';
require_once './core/custom.php';
require_once './core/output.php';
/**
* Play movie on configured Boxee box
*/
function boxeePlay($filename) {
global $config;
$socket = fsockopen($config['boxeeHost'], $config['boxeePort']);
if (!$socket) {
throw new Exception("Couldn't connect to boxee on ".$config['boxeeHost'].':'.$config['boxeePort']);
}
$data = array(
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'XBMC.Play',
'params' => array('file' => $filename)
);
$json = json_encode($data, JSON_FORCE_OBJECT);
fputs($socket, $json);
/*
$response = '';
while (!(feof($socket))) {
$response .= fgets($socket);
}
*/
// close socket
$status = stream_get_meta_data($socket);
fclose($socket);
// check for timeout
if (@$status['timed_out']) {
$response['error'] = "Connection timed out";
}
return trim($response);
}
/**
* Toggle seen status
*
* @author Andreas Goetz <[email protected]>
*/
if ($ajax_update)
{
// add some delay for debugging
if ($config['debug'] && $_SERVER['SERVER_ADDR'] == '127.0.0.1') usleep(rand(200,1000)*1000);
if (isset($seen))
{
set_userseen($ajax_update, $seen);
header('X-JSON: '.json_encode(array('result' => $seen > 0)));
}
elseif (isset($rating))
{
// Permission check same as edit.php
// check for localnet
localnet_or_die();
// multiuser permission check
if (empty($id))
permission_or_die(PERM_WRITE);
else
permission_or_die(PERM_WRITE, get_owner_id($ajax_update));
runSQL('UPDATE '.TBL_DATA.' SET rating='.$rating.' WHERE id='.$ajax_update);
}
// make sure no artifacts
$smarty->clearCache('list.tpl');
exit;
}
// random view
if (empty($id))
{
$count = 0;
$all = strtoupper($lang['radio_all']);
$WHERES = '';
if ($config['multiuser'])
{
// explicit setting of owner
$owner = session_get('owner');
if ($owner && $owner == $all || check_permission(PERM_READ, $uid = get_userid($owner)))
{
if ($owner == $all) $uid = -1;
$owner_id = $uid;
}
elseif (check_permission(PERM_READ, get_current_user_id()))
{
$owner_id = get_current_user_id();
}
elseif (count($owners = out_owners(false, PERM_READ, true)) == 1)
{
// check if there is only one owner available
$owners = array_keys($owners);
$owner_id = $owners[0];
}
else
{
// help! take ALL
$owner_id = -1;
}
session_set('owner', ($owner_id && $owner_id >= 0) ? get_username($owner_id) : $all);
// if we don't have read all permissions, limit visibility using cross-user permissions
if (!check_permission(PERM_READ))
{
$JOINS = ' LEFT JOIN '.TBL_PERMISSIONS.' ON '.TBL_DATA.'.owner_id = '.TBL_PERMISSIONS.'.to_uid';
$WHERES .= ' AND '.TBL_PERMISSIONS.'.from_uid = '.get_current_user_id().' AND '.TBL_PERMISSIONS.'.permissions & '.PERM_READ.' != 0';
}
// further limit to single owner
if ($owner_id > 0) $WHERES .= " AND owner_id = '".$owner_id."' ";
}
// limit random to not unseen movies only
if ($config['showrandomunseen'])
{
// WARNING: this may make the SQL query expensive for large databases
$WHERES .= ' AND ('.TBL_DATA.'.id NOT IN (SELECT video_id FROM '.TBL_USERSEEN.'))';
}
// find a random id
$SELECT = 'SELECT id, REVERSE(RAND(NOW())) AS rnd
FROM '.TBL_DATA."
$JOINS
WHERE mediatype != ".MEDIA_WISHLIST." $WHERES
ORDER BY rnd
LIMIT 1";
while (!$id)
{
$result = runSQL($SELECT);
// prevent endless loop
if (!count($result) || ($count++ > 50)) break;
$id = $result[0]['id'];
if (!adultcheck($id)) $id = 0; //adult movie? -> try again
}
// id still empty? go back to index.
if (empty($id)) redirect('index.php');
}
// get data (id may be empty on a empty database)
if (!empty($id))
{
// no adult permissions? -> back to index
if (!adultcheck($id) || !check_videopermission(PERM_READ, $id)) redirect('index.php');
// XML / RSS / PDF export
if ($export && $config[$export])
{
// either (xml|rss|pdf)export
$func = $export.'export';
if ($export == 'rss') $export = 'xml';
require_once './core/'.$export.'.php';
if (function_exists($func)) $func('WHERE '.TBL_DATA.'.id = '.$id);
exit;
}
$SELECT = 'SELECT '.TBL_DATA.'.id, title, subtitle, language, diskid, comment,
disklabel, imdbID, year, imgurl, director, actors, runtime,
country, plot, filename, filesize, filedate, audio_codec,
video_codec, video_width, video_height, istv, lastupdate,
email, rating, custom1, custom2, custom3, custom4,
!ISNULL('.TBL_USERSEEN.'.video_id) AS seen,
'.TBL_USERS.'.name AS owner, '.TBL_MEDIATYPES.'.name AS mediatype
FROM '.TBL_DATA.'
LEFT JOIN '.TBL_USERS.' ON owner_id = '.TBL_USERS.'.id
LEFT JOIN '.TBL_USERSEEN.'
ON '.TBL_DATA.'.id = '.TBL_USERSEEN.'.video_id AND '.TBL_USERSEEN.'.user_id = '.get_current_user_id().'
LEFT JOIN '.TBL_MEDIATYPES.' ON mediatype = '.TBL_MEDIATYPES.'.id
WHERE '.TBL_DATA.'.id = '.$id;
$res = runSQL($SELECT);
// existing id?
if (!count($res)) redirect('index.php');
// get the item
$video = $res[0];
// is it editable/ copyable?
$video['editable'] = localnet();
$video['copyable'] = localnet();
// multi-user permissions
if ($config['multiuser'])
{
$video['editable'] = $video['editable'] && check_permission(PERM_WRITE, get_userid($video['owner']));
$video['copyable'] = $video['copyable'] && check_permission(PERM_WRITE, PERM_ANY);
}
// save seen state
if ($save)
{
set_userseen($id, $seen);
$video['seen'] = $seen; // store in video for display
}
// diskid to global scope:
$diskid = $video['diskid'];
// check if it is lent and to whom- save query if id not set
if ($diskid)
{
$SELECT = 'SELECT who
FROM '.TBL_LENT."
WHERE diskid = '".addslashes($diskid)."'";
$result = runSQL($SELECT);
if (isset($result[0]['who']))
{
$video['who'] = $result[0]['who'];
}
}
/*
// append child episodes
$SELECT = 'SELECT *
FROM '.TBL_DATA.'
WHERE '.TBL_DATA.'.parent_id = '.$id.'
ORDER BY season, episode, title, subtitle';
$episodes = runSQL($SELECT);
$video['episodes'] = $episodes;
*/
// previous/next buttons
if (is_array($ids = session_get('query_result')))
{
if (($key = array_search($id, $ids)) !== false)
{
$video['prev_id'] = ($key > 0) ? $ids[$key-1] : 0;
$video['next_id'] = ($key < count($ids)-1) ? $ids[$key+1] : 0;
}
}
// breadcrumbs
$breadcrumbs = session_get('breadcrumbs', array('current' => 0, 'crumbs' => array()));
if (sizeof($breadcrumbs['crumbs']) > 10)
$breadcrumbs['crumbs'] = array_slice($breadcrumbs['crumbs'], 0, -10);
$breadcrumbs['current'] = $id;
$breadcrumbs['crumbs'][] = array(
'id' => $id,
'title' => $video['title']);
$size = sizeof($breadcrumbs['crumbs']);
for ($i; $i < $size-1; $i++) {
if ($breadcrumbs['crumbs'][$i]['id'] == $id) {
unset($breadcrumbs['crumbs'][$size-1]);
break;
}
}
session_set('breadcrumbs', $breadcrumbs);
}
if ($method == 'boxeePlay') {
boxeePlay($video['filename']);
}
// prepare templates
tpl_page('detailview', $video['title']);
if (!empty($id)) tpl_show($video);
// caching enabled?
if ($config['http_caching'])
{
require_once('./core/httpcache.php');
httpCacheCaptureStart();
}
// display templates
smarty_display('header.tpl');
if (!$config['http_caching']) flush();
if (!empty($id)) smarty_display('show.tpl', $id);
smarty_display('footer.tpl');
// caching enabled?
if ($config['http_caching'])
{
httpCacheOutput('show'.$id, httpCacheCaptureEnd());
}
?>