-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.php
272 lines (221 loc) · 11 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>plexWatch</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="css/plexwatch.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet" >
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<!-- touch icons -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/icon_iphone.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/icon_ipad.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/[email protected]">
<link rel="apple-touch-icon" sizes="144x144" href="images/[email protected]">
</head>
<body>
<div class="container">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<a href="index.php"><div class="logo hidden-phone"></div></a>
<ul class="nav">
<li class="active"><a href="index.php"><i class="icon-2x icon-home icon-white" data-toggle="tooltip" data-placement="bottom" title="Home" id="home"></i></a></li>
<li><a href="history.php"><i class="icon-2x icon-calendar icon-white" data-toggle="tooltip" data-placement="bottom" title="History" id="history"></i></a></li>
<li><a href="stats.php"><i class="icon-2x icon-tasks icon-white" data-toggle="tooltip" data-placement="bottom" title="Stats" id="stats"></i></a></li>
<li><a href="users.php"><i class="icon-2x icon-group icon-white" data-toggle="tooltip" data-placement="bottom" title="Users" id="users"></i></a></li>
<li><a href="charts.php"><i class="icon-2x icon-bar-chart icon-white" data-toggle="tooltip" data-placement="bottom" title="Charts" id="charts"></i></a></li>
<li><a href="settings.php"><i class="icon-2x icon-wrench icon-white" data-toggle="tooltip" data-placement="bottom" title="Settings" id="settings"></i></a></li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<div class='row-fluid'>
<div class='span12'>
</div>
</div>
<div class='row-fluid'>
<div class='span12'>
<?php
$guisettingsFile = "config/config.php";
if (file_exists($guisettingsFile)) {
require_once(dirname(__FILE__) . '/config/config.php');
}else{
header("Location: settings.php");
}
if ($plexWatch['https'] == 'yes') {
$plexWatchPmsUrl = "https://".$plexWatch['pmsIp'].":".$plexWatch['pmsHttpsPort']."";
}else if ($plexWatch['https'] == 'no') {
$plexWatchPmsUrl = "http://".$plexWatch['pmsIp'].":".$plexWatch['pmsHttpPort']."";
}
if (!empty($plexWatch['myPlexAuthToken'])) {
$myPlexAuthToken = $plexWatch['myPlexAuthToken'];
$fileContents = '';
if ($fileContents = file_get_contents("".$plexWatchPmsUrl."/status/sessions?X-Plex-Token=".$myPlexAuthToken."")) {
$statusSessions = simplexml_load_string($fileContents) or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
}
$sections = simplexml_load_file("".$plexWatchPmsUrl."/library/sections?X-Plex-Token=".$myPlexAuthToken."") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
}else{
$myPlexAuthToken = '';
if ($fileContents = file_get_contents("".$plexWatchPmsUrl."/status/sessions?X-Plex-Token=".$myPlexAuthToken."")) {
$statusSessions = simplexml_load_string($fileContents) or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
}
$sections = simplexml_load_file("".$plexWatchPmsUrl."/library/sections") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
}
echo "<div class='wellbg'>";
echo "<div class='wellheader'>";
echo "<div class='dashboard-wellheader'>";
echo "<h3>Statistics</h3>";
echo "</div>";
echo "</div>";
echo "<div class='stats'>";
echo "<ul>";
foreach ($sections->children() as $section) {
if (!empty($plexWatch['myPlexAuthToken'])) {
if ($section['type'] == "movie") {
$sectionDetails = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?type=1&sort=addedAt:desc&X-Plex-Container-Start=0&X-Plex-Container-Size=1&X-Plex-Token=".$myPlexAuthToken."") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
echo "<li>";
echo "<h1>".$sectionDetails['totalSize']."</h1><h5>".$section['title']."</h5>";
echo "</li>";
}else if ($section['type'] == "show") {
$sectionDetails = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?type=2&sort=addedAt:desc&X-Plex-Container-Start=0&X-Plex-Container-Size=1&X-Plex-Token=".$myPlexAuthToken."") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
$tvEpisodeCount = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?type=4&X-Plex-Container-Start=0&X-Plex-Container-Size=1&X-Plex-Token=".$myPlexAuthToken."") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
echo "<li>";
echo "<h1>".$sectionDetails['totalSize']."</h1><h5>".$section['title']."</h5>";
echo "</li>";
echo "<li>";
echo "<h1>".$tvEpisodeCount['totalSize']."</h1><h5>TV Episodes</h5>";
echo "</li>";
}else if ($section['type'] == "artist") {
$sectionDetails = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?sort=addedAt:desc&X-Plex-Container-Start=0&X-Plex-Container-Size=1&X-Plex-Token=".$myPlexAuthToken."") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
echo "<li>";
echo "<h1>".$sectionDetails['totalSize']."</h1><h5>".$section['title']."</h5>";
echo "</li>";
}
}else{
if ($section['type'] == "movie") {
$sectionDetails = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?type=1&sort=addedAt:desc&X-Plex-Container-Start=0&X-Plex-Container-Size=1") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
echo "<li>";
echo "<h1>".$sectionDetails['totalSize']."</h1><h5>".$section['title']."</h5>";
echo "</li>";
}else if ($section['type'] == "show") {
$sectionDetails = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?type=2&sort=addedAt:desc&X-Plex-Container-Start=0&X-Plex-Container-Size=1") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
$tvEpisodeCount = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?type=4&X-Plex-Container-Start=0&X-Plex-Container-Size=1") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
echo "<li>";
echo "<h1>".$sectionDetails['totalSize']."</h1><h5>".$section['title']."</h5>";
echo "</li>";
echo "<li>";
echo "<h1>".$tvEpisodeCount['totalSize']."</h1><h5>TV Episodes</h5>";
echo "</li>";
}else if ($section['type'] == "artist") {
$sectionDetails = simplexml_load_file("".$plexWatchPmsUrl."/library/sections/".$section['key']."/all?sort=addedAt:desc&X-Plex-Container-Start=0&X-Plex-Container-Size=1") or die ("<div class=\"alert alert-warning \">Failed to access Plex Media Server. Please check your settings.</div>");
echo "<li>";
echo "<h1>".$sectionDetails['totalSize']."</h1><h5>".$section['title']."</h5>";
echo "</li>";
}
}
}
date_default_timezone_set(@date_default_timezone_get());
$db = dbconnect();
$users = $db->querySingle("SELECT count(DISTINCT user) as users FROM processed") or die ("Failed to access plexWatch database. Please check your settings.");
echo "<li>";
echo "<h1>".$users."</h1><h5>Users</h5>";
echo "</li>";
echo "</ul>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid'>";
echo "<div class='span12'>";
echo "<div class='wellbg'>";
echo "<div class='wellheader'>";
echo "<div class='dashboard-wellheader'>";
echo "<div id='currentActivityHeader'>";
require("includes/current_activity_header.php");
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div id='currentActivity'>";
require("includes/current_activity.php");
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
/* recently added rows -- dynamic */
echo "<div class='row-fluid'>";
echo "<div class='wellbg'>";
echo "<div class='wellheader'>";
echo "<div class='dashboard-wellheader'>";
echo "<h3>Recently Added</h3>";
echo "</div>";
echo "</div>";
echo "<div id='recentlyAdded'></div>";
echo "</div>";
?>
<footer>
</footer>
</div><!--/.fluid-container-->
<!-- javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-2.0.3.js"></script>
<script src="js/bootstrap.js"></script>
<script>
function currentActivityHeader() {
$('#currentActivityHeader').load('includes/current_activity_header.php');
}
setInterval('currentActivityHeader()', 15000);
</script>
<script>
function currentActivity() {
$('#currentActivity').load('includes/current_activity.php');
}
setInterval('currentActivity()', 15000);
</script>
<script>
function recentlyAdded() {
var widthVal= $('body').find(".container-fluid").width();
$('#recentlyAdded').load('includes/recently_added.php?width=' + widthVal);
}
$(document).ready(function () {
recentlyAdded()
$(window).resize(function() {
recentlyAdded()
});
});
</script>
<script>
$(document).ready(function() {
$('#home').tooltip();
});
$(document).ready(function() {
$('#history').tooltip();
});
$(document).ready(function() {
$('#users').tooltip();
});
$(document).ready(function() {
$('#charts').tooltip();
});
$(document).ready(function() {
$('#settings').tooltip();
});
$(document).ready(function() {
$('#stats').tooltip();
});
</script>
</body>
</html>