functions.php 26 KB

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