-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathloader.php
124 lines (104 loc) · 4.18 KB
/
loader.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
<?php
// Copyright 2011 JMB Software, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
require_once('classes/Config.php');
$clip_id = $_REQUEST['id'];
$clip_url = $_REQUEST['u'];
$user_watching = $_REQUEST['un'];
$user = null;
$limit_exceeded = false;
StatsRollover();
$DB = GetDB();
if( !empty($user_watching) )
{
$user = $DB->Row('SELECT * FROM `tbx_user` JOIN `tbx_user_stat` USING (`username`) JOIN ' .
'`tbx_user_level` ON `tbx_user_level`.`user_level_id`=`tbx_user`.`user_level_id` WHERE `tbx_user`.`username`=?', array($user_watching));
if( !empty($user) )
{
$limit_exceeded = !empty($user) &&
(
($user['daily_bandwidth_limit'] > 0 && $user['today_bandwidth_used'] > $user['daily_bandwidth_limit']) ||
($user['daily_view_limit'] > 0 && $user['today_videos_watched'] > $user['daily_view_limit'])
);
if( !$limit_exceeded && $clip_url[0] == '/' )
{
$clip = $DB->Row('SELECT * FROM `tbx_video_clip` WHERE `clip_id`=?', array($clip_id));
if( $clip['filesize'] > 0 )
{
$DB->Update('UPDATE `tbx_user_stat` SET ' .
'`today_bandwidth_used`=`today_bandwidth_used`+?,' .
'`week_bandwidth_used`=`week_bandwidth_used`+?,' .
'`month_bandwidth_used`=`month_bandwidth_used`+?,' .
'`total_bandwidth_used`=`total_bandwidth_used`+? ' .
'WHERE `username`=?',
array($clip['filesize'],
$clip['filesize'],
$clip['filesize'],
$clip['filesize'],
$user_watching));
}
}
}
}
if( empty($user_watching) || empty($user) )
{
$ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));
$usage = $DB->Row('SELECT * FROM `tbx_guest_usage` WHERE `ip`=?', array($ip));
if( !empty($usage) )
{
$level = $DB->Row('SELECT * FROM `tbx_user_level` WHERE `is_guest`=1');
if( !empty($level) )
{
$limit_exceeded = ($level['daily_bandwidth_limit'] > 0 && $usage['bandwidth'] > $level['daily_bandwidth_limit']) ||
($level['daily_view_limit']> 0 && $usage['watched'] > $level['daily_view_limit']);
}
}
// Handle streaming
if( isset($_REQUEST['start']) )
{
$clip_url .= '?start=' . $_REQUEST['start'];
}
if( !$limit_exceeded && $clip_url[0] == '/' )
{
$clip = $DB->Row('SELECT * FROM `tbx_video_clip` WHERE `clip_id`=?', array($clip_id));
if( $clip['filesize'] > 0 )
{
if( empty($usage) )
{
$DB->Update('INSERT INTO `tbx_guest_usage` VALUES (?,?,1)', array($ip, $clip['filesize']));
}
else
{
$DB->Update('UPDATE `tbx_guest_usage` SET `bandwidth`=`bandwidth`+? WHERE `ip`=?', array($clip['filesize'], $ip));
}
}
}
}
if( $limit_exceeded )
{
switch($_GET['pt'])
{
case 'wmv':
$clip_url = Config::Get('template_uri') . '/images/limit.wmv';
break;
case 'flv':
$clip_url = Config::Get('template_uri') . '/images/limit.flv';
break;
default:
$clip_url = Config::Get('template_uri') . '/images/limit.png';
break;
}
}
header('Location: ' . $clip_url, true, 301);
?>