functions.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. <?php
  2. function debug_out($variable, $die = false) {
  3. $trace = debug_backtrace()[0];
  4. echo '<pre style="background-color: #f2f2f2; border: 2px solid black; border-radius: 5px; padding: 5px; margin: 5px";>'.$trace['file'].':'.$trace['line']."\n\n".print_r($variable, true).'</pre>';
  5. if ($die) { http_response_code(503); die(); }
  6. }
  7. function clean($strin) {
  8. $strout = null;
  9. for ($i = 0; $i < strlen($strin); $i++) {
  10. $ord = ord($strin[$i]);
  11. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  12. $strout .= "&amp;#{$ord};";
  13. }
  14. else {
  15. switch ($strin[$i]) {
  16. case '<':
  17. $strout .= '&lt;';
  18. break;
  19. case '>':
  20. $strout .= '&gt;';
  21. break;
  22. case '&':
  23. $strout .= '&amp;';
  24. break;
  25. case '"':
  26. $strout .= '&quot;';
  27. break;
  28. default:
  29. $strout .= $strin[$i];
  30. }
  31. }
  32. }
  33. return $strout;
  34. }
  35. function registration_callback($username, $email, $userdir){
  36. global $data;
  37. $data = array($username, $email, $userdir);
  38. }
  39. function printArray($arrayName){
  40. $messageCount = count($arrayName);
  41. $i = 0;
  42. foreach ( $arrayName as $item ) :
  43. $i++;
  44. if($i < $messageCount) :
  45. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  46. elseif($i = $messageCount) :
  47. echo "<small class='text-uppercase'>" . $item . "</small>";
  48. endif;
  49. endforeach;
  50. }
  51. function write_ini_file($content, $path) {
  52. if (!$handle = fopen($path, 'w')) {
  53. return false;
  54. }
  55. $success = fwrite($handle, trim($content));
  56. fclose($handle);
  57. return $success;
  58. }
  59. function gotTimezone(){
  60. $regions = array(
  61. 'Africa' => DateTimeZone::AFRICA,
  62. 'America' => DateTimeZone::AMERICA,
  63. 'Antarctica' => DateTimeZone::ANTARCTICA,
  64. 'Arctic' => DateTimeZone::ARCTIC,
  65. 'Asia' => DateTimeZone::ASIA,
  66. 'Atlantic' => DateTimeZone::ATLANTIC,
  67. 'Australia' => DateTimeZone::AUSTRALIA,
  68. 'Europe' => DateTimeZone::EUROPE,
  69. 'Indian' => DateTimeZone::INDIAN,
  70. 'Pacific' => DateTimeZone::PACIFIC
  71. );
  72. $timezones = array();
  73. foreach ($regions as $name => $mask) {
  74. $zones = DateTimeZone::listIdentifiers($mask);
  75. foreach($zones as $timezone) {
  76. $time = new DateTime(NULL, new DateTimeZone($timezone));
  77. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  78. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  79. }
  80. }
  81. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  82. foreach($timezones as $region => $list) {
  83. print '<optgroup label="' . $region . '">' . "\n";
  84. foreach($list as $timezone => $name) {
  85. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  86. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  87. }
  88. print '</optgroup>' . "\n";
  89. }
  90. print '</select>';
  91. }
  92. function getTimezone(){
  93. $regions = array(
  94. 'Africa' => DateTimeZone::AFRICA,
  95. 'America' => DateTimeZone::AMERICA,
  96. 'Antarctica' => DateTimeZone::ANTARCTICA,
  97. 'Arctic' => DateTimeZone::ARCTIC,
  98. 'Asia' => DateTimeZone::ASIA,
  99. 'Atlantic' => DateTimeZone::ATLANTIC,
  100. 'Australia' => DateTimeZone::AUSTRALIA,
  101. 'Europe' => DateTimeZone::EUROPE,
  102. 'Indian' => DateTimeZone::INDIAN,
  103. 'Pacific' => DateTimeZone::PACIFIC
  104. );
  105. $timezones = array();
  106. foreach ($regions as $name => $mask) {
  107. $zones = DateTimeZone::listIdentifiers($mask);
  108. foreach($zones as $timezone) {
  109. $time = new DateTime(NULL, new DateTimeZone($timezone));
  110. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  111. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  112. }
  113. }
  114. print '<select name="timezone" id="timezone" class="form-control material" required>';
  115. foreach($timezones as $region => $list) {
  116. print '<optgroup label="' . $region . '">' . "\n";
  117. foreach($list as $timezone => $name) {
  118. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  119. }
  120. print '</optgroup>' . "\n";
  121. }
  122. print '</select>';
  123. }
  124. function explosion($string, $position){
  125. $getWord = explode("|", $string);
  126. return $getWord[$position];
  127. }
  128. function getServerPath() {
  129. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  130. $protocol = "https://";
  131. } else {
  132. $protocol = "http://";
  133. }
  134. return $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  135. }
  136. function get_browser_name() {
  137. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  138. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  139. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  140. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  141. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  142. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  143. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  144. return 'Other';
  145. }
  146. function resolveEmbyItem($address, $token, $item) {
  147. // Static Height
  148. $height = 150;
  149. // Get Item Details
  150. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0];
  151. switch ($item['Type']) {
  152. case 'Episode':
  153. $title = $item['SeriesName'].': '.$item['Name'].' (Season '.$item['ParentIndexNumber'].': Episode '.$item['IndexNumber'].')';
  154. $imageId = $itemDetails['SeriesId'];
  155. $width = 100;
  156. $image = 'season';
  157. break;
  158. case 'Music':
  159. $title = $item['Name'];
  160. $imageId = $itemDetails['AlbumId'];
  161. $width = 150;
  162. $image = 'music';
  163. break;
  164. default:
  165. $title = $item['Name'];
  166. $imageId = $item['Id'];
  167. $width = 100;
  168. $image = 'movie';
  169. }
  170. // If No Overview
  171. if (!isset($itemDetails['Overview'])) {
  172. $itemDetails['Overview'] = '';
  173. }
  174. // Assemble Item And Cache Into Array
  175. return '<div class="item"><a href="'.$address.'/web/itemdetails.html?id='.$item['Id'].'" target="_blank"><img alt="'.$item['Name'].'" class="carousel-image '.$image.'" src="image.php?source=emby&img='.$imageId.'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption '.$image.'""><h4>'.$title.'</h4><small><em>'.$itemDetails['Overview'].'</em></small></div></div>';
  176. }
  177. function outputCarousel($header, $size, $type, $items) {
  178. // If None Populate Empty Item
  179. if (!count($items)) {
  180. $items = array('<div class="item"><img alt="nada" class="carousel-image movie" src="images/nadaplaying.jpg"><div class="carousel-caption"><h4>Nothing To Show</h4><small><em>Get Some Stuff Going!</em></small></div></div>');
  181. }
  182. // Set First As Active
  183. $items[0] = preg_replace('/^<div class="item ?">/','<div class="item active">', $items[0]);
  184. // Add Buttons
  185. $buttons = '';
  186. if (count($items) > 1) {
  187. $buttons = '
  188. <a class="left carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a>
  189. <a class="right carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
  190. }
  191. return '
  192. <div class="col-lg-'.$size.'">
  193. <h5 class="text-center">'.$header.'</h5>
  194. <div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">
  195. '.implode('',$items).'
  196. </div>'.$buttons.'
  197. </div></div>';
  198. }
  199. function getEmbyStreams($url, $port, $token, $size, $header) {
  200. if (stripos($url, "http") === false) {
  201. $url = "http://" . $url;
  202. }
  203. if ($port !== "") {
  204. $url = $url . ":" . $port;
  205. }
  206. $address = $url;
  207. $api = json_decode(file_get_contents($address.'/Sessions?api_key='.$token),true);
  208. $playingItems = array();
  209. foreach($api as $key => $value) {
  210. if (isset($value['NowPlayingItem'])) {
  211. $playingItems[] = resolveEmbyItem($address, $token, $value['NowPlayingItem']);
  212. }
  213. }
  214. return outputCarousel($header, $size, 'streams', $playingItems);
  215. }
  216. function getEmbyRecent($url, $port, $type, $token, $size, $header) {
  217. if (stripos($url, "http") === false) {
  218. $url = "http://" . $url;
  219. }
  220. if ($port !== "") {
  221. $url = $url . ":" . $port;
  222. }
  223. $address = $url;
  224. // Resolve Types
  225. switch ($type) {
  226. case 'movie':
  227. $embyTypeQuery = 'IncludeItemTypes=Movie&';
  228. break;
  229. case 'season':
  230. $embyTypeQuery = 'IncludeItemTypes=Episode&';
  231. break;
  232. case 'album':
  233. $embyTypeQuery = 'IncludeItemTypes=Music&';
  234. break;
  235. default:
  236. $embyTypeQuery = '';
  237. }
  238. // Get A User
  239. $userId = json_decode(file_get_contents($address.'/Users?api_key='.$token),true)[0]['Id'];
  240. // Get the latest Items
  241. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.$token),true);
  242. // For Each Item In Category
  243. $items = array();
  244. foreach ($latest as $k => $v) {
  245. $items[] = resolveEmbyItem($address, $token, $v);
  246. }
  247. return outputCarousel($header, $size, $type, $items);
  248. }
  249. function getPlexRecent($url, $port, $type, $token, $size, $header){
  250. $urlCheck = stripos($url, "http");
  251. if ($urlCheck === false) {
  252. $url = "http://" . $url;
  253. }
  254. if($port !== ""){ $url = $url . ":" . $port; }
  255. $address = $url;
  256. $api = file_get_contents($address."/library/recentlyAdded?X-Plex-Token=".$token);
  257. $api = simplexml_load_string($api);
  258. $getServer = file_get_contents($address."/servers?X-Plex-Token=".$token);
  259. $getServer = simplexml_load_string($getServer);
  260. foreach($getServer AS $child) {
  261. $gotServer = $child['machineIdentifier'];
  262. }
  263. $i = 0;
  264. $gotPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5><div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">';
  265. foreach($api AS $child) {
  266. if($child['type'] == $type){
  267. $i++;
  268. if($i == 1){ $active = "active"; }else{ $active = "";}
  269. $thumb = $child['thumb'];
  270. $plexLink = "https://app.plex.tv/web/app#!/server/$gotServer/details?key=/library/metadata/".$child['ratingKey'];
  271. if($type == "movie"){
  272. $title = $child['title'];
  273. $summary = $child['summary'];
  274. $height = "150";
  275. $width = "100";
  276. }elseif($type == "season"){
  277. $title = $child['parentTitle'];
  278. $summary = $child['parentSummary'];
  279. $height = "150";
  280. $width = "100";
  281. }elseif($type == "album"){
  282. $title = $child['parentTitle'];
  283. $summary = $child['title'];
  284. $height = "150";
  285. $width = "150";
  286. }
  287. $gotPlex .= '<div class="item '.$active.'"> <a href="'.$plexLink.'" target="_blank"> <img alt="'.$title.'" class="carousel-image '.$type.'" src="image.php?img='.$thumb.'&height='.$height.'&width='.$width.'"> </a> <div class="carousel-caption '.$type.'"> <h4>'.$title.'</h4> <small> <em>'.$summary.'</em> </small> </div> </div>';
  288. $plexLink = "";
  289. }
  290. }
  291. $gotPlex .= '</div>';
  292. if ($i > 1){
  293. $gotPlex .= '<a class="left carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="right carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
  294. }
  295. $gotPlex .= '</div></div>';
  296. $noPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  297. $noPlex .= '<div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  298. $noPlex .= '<div class="carousel-inner" role="listbox">';
  299. $noPlex .= '<div class="item active">';
  300. $noPlex .= "<img alt='nada' class='carousel-image movie' src='images/nadaplaying.jpg'>";
  301. $noPlex .= '<div class="carousel-caption"> <h4>Nothing New</h4> <small> <em>Get to Adding!</em> </small></div></div></div></div></div>';
  302. if ($i != 0){ return $gotPlex; }
  303. if ($i == 0){ return $noPlex; }
  304. }
  305. function getPlexStreams($url, $port, $token, $size, $header){
  306. $urlCheck = stripos($url, "http");
  307. if ($urlCheck === false) {
  308. $url = "http://" . $url;
  309. }
  310. if($port !== ""){ $url = $url . ":" . $port; }
  311. $address = $url;
  312. $api = file_get_contents($address."/status/sessions?X-Plex-Token=".$token);
  313. $api = simplexml_load_string($api);
  314. $getServer = file_get_contents($address."/servers?X-Plex-Token=".$token);
  315. $getServer = simplexml_load_string($getServer);
  316. foreach($getServer AS $child) {
  317. $gotServer = $child['machineIdentifier'];
  318. }
  319. $i = 0;
  320. $gotPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  321. $gotPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  322. $gotPlex .= '<div class="carousel-inner" role="listbox">';
  323. foreach($api AS $child) {
  324. $type = $child['type'];
  325. $plexLink = "https://app.plex.tv/web/app#!/server/$gotServer/details?key=/library/metadata/".$child['ratingKey'];
  326. $i++;
  327. if($i == 1){ $active = "active"; }else{ $active = "";}
  328. if($type == "movie"){
  329. $title = $child['title'];
  330. $summary = htmlentities($child['summary'], ENT_QUOTES);
  331. $thumb = $child['thumb'];
  332. $image = "movie";
  333. $height = "150";
  334. $width = "100";
  335. }elseif($type == "episode"){
  336. $title = $child['grandparentTitle'];
  337. $summary = htmlentities($child['summary'], ENT_QUOTES);
  338. $thumb = $child['grandparentThumb'];
  339. $image = "season";
  340. $height = "150";
  341. $width = "100";
  342. }elseif($type == "track"){
  343. $title = $child['grandparentTitle'] . " - " . $child['parentTitle'];
  344. $summary = htmlentities($child['title'], ENT_QUOTES);
  345. $thumb = $child['thumb'];
  346. $image = "album";
  347. $height = "150";
  348. $width = "150";
  349. }elseif($type == "clip"){
  350. $title = $child['title'].' - Trailer';
  351. $summary = ($child['summary'] != "" ? $child['summary'] : "<i>No summary loaded.</i>");
  352. $thumb = ($child['thumb'] != "" ? $child['thumb'] : 'images/nadaplaying.jpg');
  353. $image = "movie";
  354. $height = "150";
  355. $width = "100";
  356. }
  357. $gotPlex .= '<div class="item '.$active.'">';
  358. $gotPlex .= "<a href='$plexLink' target='_blank'><img alt='$title' class='carousel-image $image' src='image.php?img=$thumb&height=$height&width=$width'></a>";
  359. $gotPlex .= '<div class="carousel-caption '. $image . '""><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  360. $plexLink = "";
  361. }
  362. $gotPlex .= '</div>';
  363. if ($i > 1){
  364. $gotPlex .= '<a class="left carousel-control streams" href="#carousel-streams" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="right carousel-control streams" href="#carousel-streams" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
  365. }
  366. $gotPlex .= '</div></div>';
  367. $noPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  368. $noPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  369. $noPlex .= '<div class="carousel-inner" role="listbox">';
  370. $noPlex .= '<div class="item active">';
  371. $noPlex .= "<img alt='nada' class='carousel-image movie' src='images/nadaplaying.jpg'>";
  372. $noPlex .= '<div class="carousel-caption"><h4>Nothing Playing</h4><small><em>Get to Streaming!</em></small></div></div></div></div></div>';
  373. if ($i != 0){ return $gotPlex; }
  374. if ($i == 0){ return $noPlex; }
  375. }
  376. function getSickrageCalendarWanted($array){
  377. $array = json_decode($array, true);
  378. $gotCalendar = "";
  379. $i = 0;
  380. foreach($array['data']['missed'] AS $child) {
  381. $i++;
  382. $seriesName = $child['show_name'];
  383. $episodeID = $child['tvdbid'];
  384. $episodeAirDate = $child['airdate'];
  385. $episodeAirDateTime = explode(" ",$child['airs']);
  386. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  387. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  388. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  389. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  390. $downloaded = "0";
  391. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  392. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  393. }
  394. foreach($array['data']['today'] AS $child) {
  395. $i++;
  396. $seriesName = $child['show_name'];
  397. $episodeID = $child['tvdbid'];
  398. $episodeAirDate = $child['airdate'];
  399. $episodeAirDateTime = explode(" ",$child['airs']);
  400. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  401. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  402. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  403. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  404. $downloaded = "0";
  405. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  406. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  407. }
  408. foreach($array['data']['soon'] AS $child) {
  409. $i++;
  410. $seriesName = $child['show_name'];
  411. $episodeID = $child['tvdbid'];
  412. $episodeAirDate = $child['airdate'];
  413. $episodeAirDateTime = explode(" ",$child['airs']);
  414. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  415. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  416. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  417. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  418. $downloaded = "0";
  419. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  420. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  421. }
  422. foreach($array['data']['later'] AS $child) {
  423. $i++;
  424. $seriesName = $child['show_name'];
  425. $episodeID = $child['tvdbid'];
  426. $episodeAirDate = $child['airdate'];
  427. $episodeAirDateTime = explode(" ",$child['airs']);
  428. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  429. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  430. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  431. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  432. $downloaded = "0";
  433. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  434. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  435. }
  436. if ($i != 0){ return $gotCalendar; }
  437. }
  438. function getSickrageCalendarHistory($array){
  439. $array = json_decode($array, true);
  440. $gotCalendar = "";
  441. $i = 0;
  442. foreach($array['data'] AS $child) {
  443. $i++;
  444. $seriesName = $child['show_name'];
  445. $episodeID = $child['tvdbid'];
  446. $episodeAirDate = $child['date'];
  447. $downloaded = "green-bg";
  448. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  449. }
  450. if ($i != 0){ return $gotCalendar; }
  451. }
  452. function getSonarrCalendar($array){
  453. $array = json_decode($array, true);
  454. $gotCalendar = "";
  455. $i = 0;
  456. foreach($array AS $child) {
  457. $i++;
  458. $seriesName = $child['series']['title'];
  459. $episodeID = $child['series']['imdbId'];
  460. if(!isset($episodeID)){ $episodeID = ""; }
  461. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  462. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  463. $episodeAirDate = $child['airDateUtc'];
  464. $episodeAirDate = strtotime($episodeAirDate);
  465. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  466. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  467. $downloaded = $child['hasFile'];
  468. if($downloaded == "0" && isset($unaired) && $episodePremier == "true"){ $downloaded = "light-blue-bg"; }elseif($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  469. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"http://www.imdb.com/title/$episodeID\" }, \n";
  470. }
  471. if ($i != 0){ return $gotCalendar; }
  472. }
  473. function getRadarrCalendar($array){
  474. $array = json_decode($array, true);
  475. $gotCalendar = "";
  476. $i = 0;
  477. foreach($array AS $child) {
  478. if(isset($child['inCinemas'])){
  479. $i++;
  480. $movieName = $child['title'];
  481. $movieID = $child['imdbId'];
  482. if(!isset($movieID)){ $movieID = ""; }
  483. if(isset($child['inCinemas']) && isset($child['physicalRelease'])){
  484. $physicalRelease = $child['physicalRelease'];
  485. $physicalRelease = strtotime($physicalRelease);
  486. $physicalRelease = date("Y-m-d", $physicalRelease);
  487. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  488. $downloaded = $child['hasFile'];
  489. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  490. }else{
  491. $physicalRelease = $child['inCinemas'];
  492. $downloaded = "light-blue-bg";
  493. }
  494. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\", url: \"http://www.imdb.com/title/$movieID\" }, \n";
  495. }
  496. }
  497. if ($i != 0){ return $gotCalendar; }
  498. }
  499. function nzbgetConnect($url, $port, $username, $password, $list){
  500. $urlCheck = stripos($url, "http");
  501. if ($urlCheck === false) {
  502. $url = "http://" . $url;
  503. }
  504. if($port !== ""){ $url = $url . ":" . $port; }
  505. $address = $url;
  506. $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
  507. $api = json_decode($api, true);
  508. $i = 0;
  509. $gotNZB = "";
  510. foreach ($api['result'] AS $child) {
  511. $i++;
  512. //echo '<pre>' . var_export($child, true) . '</pre>';
  513. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  514. $downloadStatus = $child['Status'];
  515. $downloadCategory = $child['Category'];
  516. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  517. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  518. if($child['Health'] <= "750"){
  519. $downloadHealth = "danger";
  520. }elseif($child['Health'] <= "900"){
  521. $downloadHealth = "warning";
  522. }elseif($child['Health'] <= "1000"){
  523. $downloadHealth = "success";
  524. }
  525. $gotNZB .= '<tr>
  526. <td>'.$downloadName.'</td>
  527. <td>'.$downloadStatus.'</td>
  528. <td>'.$downloadCategory.'</td>
  529. <td>
  530. <div class="progress">
  531. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  532. <p class="text-center">'.round($downloadPercent).'%</p>
  533. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  534. </div>
  535. </div>
  536. </td>
  537. </tr>';
  538. }
  539. if($i > 0){ return $gotNZB; }
  540. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  541. }
  542. function sabnzbdConnect($url, $port, $key, $list){
  543. $urlCheck = stripos($url, "http");
  544. if ($urlCheck === false) {
  545. $url = "http://" . $url;
  546. }
  547. if($port !== ""){ $url = $url . ":" . $port; }
  548. $address = $url;
  549. $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
  550. $api = json_decode($api, true);
  551. $i = 0;
  552. $gotNZB = "";
  553. foreach ($api[$list]['slots'] AS $child) {
  554. $i++;
  555. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  556. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  557. $downloadStatus = $child['status'];
  558. $gotNZB .= '<tr>
  559. <td>'.$downloadName.'</td>
  560. <td>'.$downloadStatus.'</td>
  561. <td>'.$downloadCategory.'</td>
  562. <td>
  563. <div class="progress">
  564. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  565. <p class="text-center">'.round($downloadPercent).'%</p>
  566. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  567. </div>
  568. </div>
  569. </td>
  570. </tr>';
  571. }
  572. if($i > 0){ return $gotNZB; }
  573. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  574. }
  575. function getHeadphonesCalendar($url, $port, $key, $list){
  576. $urlCheck = stripos($url, "http");
  577. if ($urlCheck === false) {
  578. $url = "http://" . $url;
  579. }
  580. if($port !== ""){ $url = $url . ":" . $port; }
  581. $address = $url;
  582. $api = file_get_contents($address."/api?apikey=".$key."&cmd=$list");
  583. $api = json_decode($api, true);
  584. $i = 0;
  585. $gotCalendar = "";
  586. foreach($api AS $child) {
  587. if($child['Status'] == "Wanted"){
  588. $i++;
  589. $albumName = addslashes($child['AlbumTitle']);
  590. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  591. $albumDate = $child['ReleaseDate'];
  592. $albumID = $child['AlbumID'];
  593. $albumDate = strtotime($albumDate);
  594. $albumDate = date("Y-m-d", $albumDate);
  595. $albumStatus = $child['Status'];
  596. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  597. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  598. $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  599. }
  600. }
  601. if ($i != 0){ return $gotCalendar; }
  602. }
  603. ?>