-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.php
More file actions
369 lines (250 loc) · 12.1 KB
/
analytics.php
File metadata and controls
369 lines (250 loc) · 12.1 KB
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
<?php
require_once "_includes/init.php";
//REQUIREMENTS / PERMISSIONS
//- Requires Login
if (!$_USER->logged_in) { redirect("/login"); exit(); }
$Countries = $engine->countries();
if (isset($_GET["page"])) {
switch ($_GET["page"]) {
case "subscribers" :
$Analytics_Page = "Subscribers";
break;
case "videos" :
$Analytics_Page = "Videos";
break;
default :
redirect("/analytics"); exit();
}
} else {
$Analytics_Page = "Default";
}
if (isset($_GET["time"])) {
switch ($_GET["time"]) {
case "0" :
$Date = 0; //ALL TIME
break;
case "1" :
$Date = 1; //THIS MONTH
break;
case "2" :
$Date = 2; //THIS WEEK
break;
case "3" :
$Date = 3; //THIS YEAR
break;
case "4" :
$Date = 4; //TODAY
break;
default :
redirect("/analytics"); exit();
}
} else {
$Date = 0; // ALL TIME
}
switch ($Date) {
case 0 :
$Subscriber_Date = "";
break;
case 1 :
$Subscriber_Date = " AND MONTH(subscriptions.submit_date) = MONTH(CURDATE()) AND YEAR(subscriptions.submit_date) = YEAR(CURDATE())";
break;
case 2 :
$Subscriber_Date = " AND YEARWEEK(subscriptions.submit_date) = YEARWEEK(NOW())";
break;
case 3 :
$Subscriber_Date = " AND YEAR(subscriptions.submit_date) = YEAR(CURDATE())";
break;
case 4 :
$Subscriber_Date = " AND DATE(subscriptions.submit_date) = CURDATE() ";
break;
}
switch ($Date) {
case 0 :
$Video_Date = "";
break;
case 1 :
$Video_Date = " AND MONTH(videos_views.submit_date) = MONTH(CURDATE()) AND YEAR(videos_views.submit_date) = YEAR(CURDATE())";
break;
case 2 :
$Video_Date = " AND YEARWEEK(videos_views.submit_date) = YEARWEEK(NOW())";
break;
case 3 :
$Video_Date = " AND YEAR(videos_views.submit_date) = YEAR(CURDATE())";
break;
case 4 :
$Video_Date = " AND DATE(videos_views.submit_date) = CURDATE() ";
break;
}
$Videos = $DB->execute("SELECT url, title FROM videos WHERE uploaded_by = :USERNAME ORDER BY title ASC", false, [":USERNAME" => $_USER->username]);
if ($Analytics_Page == "Default") {
$Subscribers = $DB->execute("SELECT count(users.username) as amount, users.country FROM subscriptions INNER JOIN users ON users.username = subscriptions.subscriber WHERE subscriptions.subscription = :USERNAME $Subscriber_Date GROUP BY users.country ORDER BY amount DESC LIMIT 5", false,
[
":USERNAME" => $_USER->username
]);
$Average_Age = $DB->execute("SELECT AVG(TIMESTAMPDIFF(YEAR, users.birthday, CURDATE())) as average FROM subscriptions INNER JOIN users ON users.username = subscriptions.subscriber WHERE subscriptions.subscription = :USERNAME AND (TIMESTAMPDIFF(YEAR, users.birthday, CURDATE())) > 13 AND (TIMESTAMPDIFF(YEAR, users.birthday, CURDATE())) < 70", true,
[
":USERNAME" => $_USER->username
]);
if (empty($Average_Age["average"])) {
$Average_Age = false;
}
$Average_Rating = $DB->execute("SELECT (1_star * 1 + 2_star * 2 + 3_star * 3 + 4_star * 4 + 5_star * 5) / (1_star + 2_star + 3_star + 4_star + 5_star) as average FROM videos WHERE uploaded_by = :USERNAME", false,
[
":USERNAME" => $_USER->username
]);
if ($DB->RowNum > 0) {
$Array = [];
foreach ($Average_Rating as $Rating) {
$Array[] = $Rating["average"];
}
$a = array_filter($Array);
$Average_Rating = (count($a) >= 1) ? array_sum($a) / count($a) : 0;
} else {
$Average_Rating = false;
}
$Views_Per_Day = $DB->execute("SELECT SUM(videos_views.views) as average FROM videos_views INNER JOIN videos ON videos_views.vid = videos.url WHERE videos.uploaded_by = :USERNAME GROUP BY DATE(videos_views.submit_date)", false,
[
":USERNAME" => $_USER->username
]);
switch ($Date) {
case 0 :
$Watch_Date = "";
break;
case 1 :
$Watch_Date = " AND MONTH(videos_watched.submit_date) = MONTH(CURDATE()) AND YEAR(videos_watched.submit_date) = YEAR(CURDATE())";
break;
case 2 :
$Watch_Date = " AND YEARWEEK(videos_watched.submit_date) = YEARWEEK(NOW())";
break;
case 3 :
$Watch_Date = " AND YEAR(videos_watched.submit_date) = YEAR(CURDATE())";
break;
case 4 :
$Watch_Date = " AND DATE(videos_watched.submit_date) = CURDATE() ";
break;
}
// At some point, `SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));` must be executed only once.
$Watchtime_Per_Day = $DB->execute("SELECT (SUM(videos_watched.watchtime) / 60) as amount, videos_watched.submit_date FROM videos_watched INNER JOIN videos ON videos_watched.vid = videos.url WHERE videos.uploaded_by = :USERNAME $Watch_Date GROUP BY DATE(videos_watched.submit_date)", false,
[
":USERNAME" => $_USER->username
]);
if ($DB->RowNum == 0) {
$Watchtime_Per_Day = false;
}
if ($DB->RowNum > 0) {
$Array = [];
foreach ($Views_Per_Day as $Views) {
$Array[] = $Views["average"];
}
$a = array_filter($Array);
$Views_Per_Day = array_sum($a)/count($a);
} else {
$Views_Per_Day = false;
}
$Popular_Videos = new Videos($DB, $_USER);
$Popular_Videos->Shadowbanned_Users = true;
$Popular_Videos->Banned_Users = true;
$Popular_Videos->Private_Videos = true;
$Popular_Videos->Unlisted_Videos = true;
if ($Date != 0) {
$Popular_Videos->JOIN = "INNER JOIN videos_views ON videos_views.vid = videos.url";
$Popular_Videos->SELECT .= ", sum(videos_views.views) as day_views";
$Popular_Videos->Group_By = " GROUP BY videos.url ";
} else {
$Popular_Videos->SELECT .= ", videos.displayviews as day_views";
}
$Popular_Videos->ORDER_BY = "day_views DESC";
$Popular_Videos->WHERE_C = $Video_Date;
$Popular_Videos->WHERE_P = ["uploaded_by" => $_USER->username];
$Popular_Videos->LIMIT = 5;
$Popular_Videos->get();
if ($Popular_Videos::$Videos) {
$Popular_Videos = $Popular_Videos->fixed();
} else {
$Popular_Videos = [];
}
} elseif ($Analytics_Page == "Subscribers") {
if (!isset($_GET["type"]) || $_GET["type"] == 0) {
if (isset($_GET["country"])) {
if (!isset($Countries[$_GET["country"]])) { redirect("/analytics"); exit(); }
$Country = " AND users.country = '".$_GET["country"]."'";
} else {
$Country = "";
}
$Subscribers_Growth = $DB->execute("SELECT count(subscriptions.subscriber) as amount, subscriptions.submit_date FROM subscriptions INNER JOIN users ON users.username = subscriptions.subscriber WHERE subscriptions.subscription = :USERNAME $Subscriber_Date $Country AND subscriptions.submit_date <> '0000-00-00' GROUP BY DATE(subscriptions.submit_date)", false,
[
":USERNAME" => $_USER->username
]);
$Subscribers = $DB->execute("SELECT count(users.username) as amount, users.country FROM subscriptions INNER JOIN users ON users.username = subscriptions.subscriber WHERE subscriptions.subscription = :USERNAME $Subscriber_Date $Country GROUP BY users.country ORDER BY amount DESC LIMIT 100", false,
[
":USERNAME" => $_USER->username
]);
} else {
$Subscribers = $DB->execute("SELECT count(subscriptions.subscriber) as amount, subscriptions.source FROM subscriptions WHERE subscriptions.subscription = :USERNAME $Subscriber_Date GROUP BY subscriptions.source ORDER BY amount DESC LIMIT 30", false,
[
":USERNAME" => $_USER->username
]);
}
} elseif ($Analytics_Page == "Videos") {
if (!isset($_GET["video"])) {
$Popular_Videos = new Videos($DB, $_USER);
if ($Date != 0) {
$Popular_Videos->JOIN = "INNER JOIN videos_views ON videos_views.vid = videos.url";
$Popular_Videos->SELECT .= ", sum(videos_views.views) as day_views";
$Popular_Videos->Group_By = " GROUP BY videos.url ";
} else {
$Popular_Videos->SELECT .= ", videos.displayviews as day_views";
}
$Popular_Videos->Shadowbanned_Users = true;
$Popular_Videos->Banned_Users = true;
$Popular_Videos->Private_Videos = true;
$Popular_Videos->WHERE_C = $Video_Date;
$Popular_Videos->Unlisted_Videos = true;
$Popular_Videos->ORDER_BY = "day_views DESC";
$Popular_Videos->WHERE_P = ["uploaded_by" => $_USER->username];
$Popular_Videos->LIMIT = 25;
$Popular_Videos->get();
if ($Popular_Videos::$Videos) {
$Popular_Videos = $Popular_Videos->fixed();
} else {
$Popular_Videos = [];
}
$Videos_Growth = $DB->execute("SELECT sum(videos_views.views) as amount, videos_views.vid, videos_views.submit_date FROM videos_views INNER JOIN videos ON videos_views.vid = videos.url WHERE videos.uploaded_by = :USERNAME $Video_Date GROUP BY DATE(videos_views.submit_date), videos.uploaded_by", false,
[
":USERNAME" => $_USER->username
]);
} else {
$Videos_Growth = $DB->execute("SELECT sum(videos_views.views) as amount, videos_views.vid, videos_views.submit_date FROM videos_views INNER JOIN videos ON videos_views.vid = videos.url WHERE (videos.uploaded_by = :USERNAME OR '$_USER->Is_Admin' = '1' OR '$_USER->Is_Mod' = '1') AND videos.url = :URL $Video_Date GROUP BY DATE(videos_views.submit_date)", false,
[
":URL" => $_GET["video"],
":USERNAME" => $_USER->username
]);
$Selected_Video = $DB->execute("SELECT sum(videos_views.views) as amount, videos_views.source FROM videos_views RIGHT JOIN videos ON videos_views.vid = videos.url WHERE (videos.uploaded_by = :USERNAME OR '$_USER->Is_Admin' = '1' OR '$_USER->Is_Mod' = '1') AND videos.url = :URL $Video_Date GROUP BY videos_views.source ORDER BY amount DESC", false,
[
":URL" => $_GET["video"],
":USERNAME" => $_USER->username
]);
if ($DB->RowNum == 0) { redirect("/analytics"); exit(); }
}
}
$_USER->get_profile();
$Channel_Version = $_USER->Info["channel_version"];
$Popular_Videos = [];
$Types = array(
0 => "Default",
1 => "Director",
2 => "Musician",
3 => "Comedian",
4 => "Gamer",
5 => "Reporter",
6 => "Guru",
7 => "Animator"
);
$Account_Title = "Channel Analytics";
$_PAGE->set_variables(array(
"Page_Title" => "Analytics - VidLii",
"Page" => "Analytics",
"Page_Type" => "Home",
"Show_Search" => false
));
require_once "_templates/settings_structure.php";