functions.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. <?php
  2. // Debugging output functions
  3. function debug_out($variable, $die = false) {
  4. $trace = debug_backtrace()[0];
  5. 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>';
  6. if ($die) { http_response_code(503); die(); }
  7. }
  8. // Auth Plugins
  9. // Pass credentials to LDAP backend
  10. function plugin_auth_ldap($username, $password) {
  11. // returns true or false
  12. $ldap = ldap_connect(AUTHBACKENDHOST.(AUTHBACKENDPORT?':'.AUTHBACKENDPORT:'389'));
  13. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. return false;
  19. }
  20. // Pass credentials to FTP backend
  21. function plugin_auth_ftp($username, $password) {
  22. // returns true or false
  23. // Connect to FTP
  24. $conn_id = ftp_ssl_connect(AUTHBACKENDHOST, (AUTHBACKENDPORT?AUTHBACKENDPORT:21), 20); // 20 Second Timeout
  25. // Check if valid FTP connection
  26. if ($conn_id) {
  27. // Attempt login
  28. @$login_result = ftp_login($conn_id, $username, $password);
  29. // Return Result
  30. if ($login_result) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. } else {
  36. return false;
  37. }
  38. return false;
  39. }
  40. // Pass credentials to Emby Backend
  41. function plugin_auth_emby($username, $password) {
  42. $urlCheck = stripos(AUTHBACKENDHOST, "http");
  43. if ($urlCheck === false) {
  44. $embyAddress = "http://" . AUTHBACKENDHOST;
  45. } else {
  46. $embyAddress = AUTHBACKENDHOST;
  47. }
  48. if(AUTHBACKENDPORT !== ""){ $embyAddress .= ":" . AUTHBACKENDPORT; }
  49. $headers = array(
  50. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  51. 'Content-type' => 'application/json',
  52. );
  53. $body = array(
  54. 'Username' => $username,
  55. 'Password' => sha1($password),
  56. 'PasswordMd5' => md5($password),
  57. );
  58. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  59. if (isset($response['content'])) {
  60. $json = json_decode($response['content'], true);
  61. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  62. // Login Success - Now Logout Emby Session As We No Longer Need It
  63. $headers = array(
  64. 'X-Mediabrowser-Token' => $json['AccessToken'],
  65. );
  66. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72. function clean($strin) {
  73. $strout = null;
  74. for ($i = 0; $i < strlen($strin); $i++) {
  75. $ord = ord($strin[$i]);
  76. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  77. $strout .= "&amp;#{$ord};";
  78. }
  79. else {
  80. switch ($strin[$i]) {
  81. case '<':
  82. $strout .= '&lt;';
  83. break;
  84. case '>':
  85. $strout .= '&gt;';
  86. break;
  87. case '&':
  88. $strout .= '&amp;';
  89. break;
  90. case '"':
  91. $strout .= '&quot;';
  92. break;
  93. default:
  94. $strout .= $strin[$i];
  95. }
  96. }
  97. }
  98. return $strout;
  99. }
  100. function registration_callback($username, $email, $userdir){
  101. global $data;
  102. $data = array($username, $email, $userdir);
  103. }
  104. function printArray($arrayName){
  105. $messageCount = count($arrayName);
  106. $i = 0;
  107. foreach ( $arrayName as $item ) :
  108. $i++;
  109. if($i < $messageCount) :
  110. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  111. elseif($i = $messageCount) :
  112. echo "<small class='text-uppercase'>" . $item . "</small>";
  113. endif;
  114. endforeach;
  115. }
  116. function write_ini_file($content, $path) {
  117. if (!$handle = fopen($path, 'w')) {
  118. return false;
  119. }
  120. $success = fwrite($handle, trim($content));
  121. fclose($handle);
  122. return $success;
  123. }
  124. function gotTimezone(){
  125. $regions = array(
  126. 'Africa' => DateTimeZone::AFRICA,
  127. 'America' => DateTimeZone::AMERICA,
  128. 'Antarctica' => DateTimeZone::ANTARCTICA,
  129. 'Arctic' => DateTimeZone::ARCTIC,
  130. 'Asia' => DateTimeZone::ASIA,
  131. 'Atlantic' => DateTimeZone::ATLANTIC,
  132. 'Australia' => DateTimeZone::AUSTRALIA,
  133. 'Europe' => DateTimeZone::EUROPE,
  134. 'Indian' => DateTimeZone::INDIAN,
  135. 'Pacific' => DateTimeZone::PACIFIC
  136. );
  137. $timezones = array();
  138. foreach ($regions as $name => $mask) {
  139. $zones = DateTimeZone::listIdentifiers($mask);
  140. foreach($zones as $timezone) {
  141. $time = new DateTime(NULL, new DateTimeZone($timezone));
  142. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  143. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  144. }
  145. }
  146. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  147. foreach($timezones as $region => $list) {
  148. print '<optgroup label="' . $region . '">' . "\n";
  149. foreach($list as $timezone => $name) {
  150. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  151. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  152. }
  153. print '</optgroup>' . "\n";
  154. }
  155. print '</select>';
  156. }
  157. function getTimezone(){
  158. $regions = array(
  159. 'Africa' => DateTimeZone::AFRICA,
  160. 'America' => DateTimeZone::AMERICA,
  161. 'Antarctica' => DateTimeZone::ANTARCTICA,
  162. 'Arctic' => DateTimeZone::ARCTIC,
  163. 'Asia' => DateTimeZone::ASIA,
  164. 'Atlantic' => DateTimeZone::ATLANTIC,
  165. 'Australia' => DateTimeZone::AUSTRALIA,
  166. 'Europe' => DateTimeZone::EUROPE,
  167. 'Indian' => DateTimeZone::INDIAN,
  168. 'Pacific' => DateTimeZone::PACIFIC
  169. );
  170. $timezones = array();
  171. foreach ($regions as $name => $mask) {
  172. $zones = DateTimeZone::listIdentifiers($mask);
  173. foreach($zones as $timezone) {
  174. $time = new DateTime(NULL, new DateTimeZone($timezone));
  175. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  176. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  177. }
  178. }
  179. print '<select name="timezone" id="timezone" class="form-control material" required>';
  180. foreach($timezones as $region => $list) {
  181. print '<optgroup label="' . $region . '">' . "\n";
  182. foreach($list as $timezone => $name) {
  183. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  184. }
  185. print '</optgroup>' . "\n";
  186. }
  187. print '</select>';
  188. }
  189. function explosion($string, $position){
  190. $getWord = explode("|", $string);
  191. return $getWord[$position];
  192. }
  193. function getServerPath() {
  194. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  195. $protocol = "https://";
  196. } else {
  197. $protocol = "http://";
  198. }
  199. return $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  200. }
  201. function get_browser_name() {
  202. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  203. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  204. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  205. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  206. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  207. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  208. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  209. return 'Other';
  210. }
  211. function resolveEmbyItem($address, $token, $item) {
  212. // Static Height
  213. $height = 150;
  214. // Get Item Details
  215. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0];
  216. switch ($item['Type']) {
  217. case 'Episode':
  218. $title = $item['SeriesName'].': '.$item['Name'].' (Season '.$item['ParentIndexNumber'].': Episode '.$item['IndexNumber'].')';
  219. $imageId = $itemDetails['SeriesId'];
  220. $width = 100;
  221. $image = 'carousel-image season';
  222. $style = '';
  223. break;
  224. case 'MusicAlbum':
  225. $title = $item['Name'];
  226. $imageId = $itemDetails['Id'];
  227. $width = 150;
  228. $image = 'music';
  229. $style = 'left: 160px !important;';
  230. break;
  231. default:
  232. $title = $item['Name'];
  233. $imageId = $item['Id'];
  234. $width = 100;
  235. $image = 'carousel-image movie';
  236. $style = '';
  237. }
  238. // If No Overview
  239. if (!isset($itemDetails['Overview'])) {
  240. $itemDetails['Overview'] = '';
  241. }
  242. // Assemble Item And Cache Into Array
  243. return '<div class="item"><a href="'.$address.'/web/itemdetails.html?id='.$item['Id'].'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" src="image.php?source=emby&img='.$imageId.'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption" style="'.$style.'"><h4>'.$title.'</h4><small><em>'.$itemDetails['Overview'].'</em></small></div></div>';
  244. }
  245. function outputCarousel($header, $size, $type, $items) {
  246. // If None Populate Empty Item
  247. if (!count($items)) {
  248. $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>');
  249. }
  250. // Set First As Active
  251. $items[0] = preg_replace('/^<div class="item ?">/','<div class="item active">', $items[0]);
  252. // Add Buttons
  253. $buttons = '';
  254. if (count($items) > 1) {
  255. $buttons = '
  256. <a class="left carousel-control '.$type.'" href="#carousel-'.$type.'-emby" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a>
  257. <a class="right carousel-control '.$type.'" href="#carousel-'.$type.'-emby" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
  258. }
  259. return '
  260. <div class="col-lg-'.$size.'">
  261. <h5 class="text-center">'.$header.'</h5>
  262. <div id="carousel-'.$type.'-emby" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">
  263. '.implode('',$items).'
  264. </div>'.$buttons.'
  265. </div></div>';
  266. }
  267. function getEmbyStreams($url, $port, $token, $size, $header) {
  268. if (stripos($url, "http") === false) {
  269. $url = "http://" . $url;
  270. }
  271. if ($port !== "") {
  272. $url = $url . ":" . $port;
  273. }
  274. $address = $url;
  275. $api = json_decode(file_get_contents($address.'/Sessions?api_key='.$token),true);
  276. $playingItems = array();
  277. foreach($api as $key => $value) {
  278. if (isset($value['NowPlayingItem'])) {
  279. $playingItems[] = resolveEmbyItem($address, $token, $value['NowPlayingItem']);
  280. }
  281. }
  282. return outputCarousel($header, $size, 'streams', $playingItems);
  283. }
  284. function getEmbyRecent($url, $port, $type, $token, $size, $header) {
  285. if (stripos($url, "http") === false) {
  286. $url = "http://" . $url;
  287. }
  288. if ($port !== "") {
  289. $url = $url . ":" . $port;
  290. }
  291. $address = $url;
  292. // Resolve Types
  293. switch ($type) {
  294. case 'movie':
  295. $embyTypeQuery = 'IncludeItemTypes=Movie&';
  296. break;
  297. case 'season':
  298. $embyTypeQuery = 'IncludeItemTypes=Episode&';
  299. break;
  300. case 'album':
  301. $embyTypeQuery = 'IncludeItemTypes=MusicAlbum&';
  302. break;
  303. default:
  304. $embyTypeQuery = '';
  305. }
  306. // Get A User
  307. $userIds = json_decode(file_get_contents($address.'/Users?api_key='.$token),true);
  308. foreach ($userIds as $value) { // Scan for admin user
  309. $userId = $value['Id'];
  310. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  311. break;
  312. }
  313. }
  314. // Get the latest Items
  315. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.$token),true);
  316. // For Each Item In Category
  317. $items = array();
  318. foreach ($latest as $k => $v) {
  319. $items[] = resolveEmbyItem($address, $token, $v);
  320. }
  321. return outputCarousel($header, $size, $type, $items);
  322. }
  323. function getPlexRecent($url, $port, $type, $token, $size, $header){
  324. $urlCheck = stripos($url, "http");
  325. if ($urlCheck === false) {
  326. $url = "http://" . $url;
  327. }
  328. if($port !== ""){ $url = $url . ":" . $port; }
  329. $address = $url;
  330. $api = file_get_contents($address."/library/recentlyAdded?X-Plex-Token=".$token);
  331. $api = simplexml_load_string($api);
  332. $getServer = file_get_contents($address."/?X-Plex-Token=".$token);
  333. $getServer = simplexml_load_string($getServer);
  334. $gotServer = $getServer['machineIdentifier'];
  335. $i = 0;
  336. $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">';
  337. foreach($api AS $child) {
  338. if($child['type'] == $type){
  339. $i++;
  340. if($i == 1){ $active = "active"; }else{ $active = "";}
  341. $thumb = $child['thumb'];
  342. $plexLink = "https://app.plex.tv/web/app#!/server/$gotServer/details?key=/library/metadata/".$child['ratingKey'];
  343. if($type == "movie"){
  344. $title = $child['title'];
  345. $summary = $child['summary'];
  346. $height = "150";
  347. $width = "100";
  348. }elseif($type == "season"){
  349. $title = $child['parentTitle'];
  350. $summary = $child['parentSummary'];
  351. $height = "150";
  352. $width = "100";
  353. }elseif($type == "album"){
  354. $title = $child['parentTitle'];
  355. $summary = $child['title'];
  356. $height = "150";
  357. $width = "150";
  358. }
  359. $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>';
  360. $plexLink = "";
  361. }
  362. }
  363. $gotPlex .= '</div>';
  364. if ($i > 1){
  365. $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>';
  366. }
  367. $gotPlex .= '</div></div>';
  368. $noPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  369. $noPlex .= '<div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  370. $noPlex .= '<div class="carousel-inner" role="listbox">';
  371. $noPlex .= '<div class="item active">';
  372. $noPlex .= "<img alt='nada' class='carousel-image movie' src='images/nadaplaying.jpg'>";
  373. $noPlex .= '<div class="carousel-caption"> <h4>Nothing New</h4> <small> <em>Get to Adding!</em> </small></div></div></div></div></div>';
  374. if ($i != 0){ return $gotPlex; }
  375. if ($i == 0){ return $noPlex; }
  376. }
  377. function getPlexStreams($url, $port, $token, $size, $header){
  378. $urlCheck = stripos($url, "http");
  379. if ($urlCheck === false) {
  380. $url = "http://" . $url;
  381. }
  382. if($port !== ""){ $url = $url . ":" . $port; }
  383. $address = $url;
  384. $api = file_get_contents($address."/status/sessions?X-Plex-Token=".$token);
  385. $api = simplexml_load_string($api);
  386. $getServer = file_get_contents($address."/servers?X-Plex-Token=".$token);
  387. $getServer = simplexml_load_string($getServer);
  388. foreach($getServer AS $child) {
  389. $gotServer = $child['machineIdentifier'];
  390. }
  391. $i = 0;
  392. $gotPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  393. $gotPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  394. $gotPlex .= '<div class="carousel-inner" role="listbox">';
  395. foreach($api AS $child) {
  396. $type = $child['type'];
  397. $plexLink = "https://app.plex.tv/web/app#!/server/$gotServer/details?key=/library/metadata/".$child['ratingKey'];
  398. $i++;
  399. if($i == 1){ $active = "active"; }else{ $active = "";}
  400. if($type == "movie"){
  401. $title = $child['title'];
  402. $summary = htmlentities($child['summary'], ENT_QUOTES);
  403. $thumb = $child['thumb'];
  404. $image = "movie";
  405. $height = "150";
  406. $width = "100";
  407. }elseif($type == "episode"){
  408. $title = $child['grandparentTitle'];
  409. $summary = htmlentities($child['summary'], ENT_QUOTES);
  410. $thumb = $child['grandparentThumb'];
  411. $image = "season";
  412. $height = "150";
  413. $width = "100";
  414. }elseif($type == "track"){
  415. $title = $child['grandparentTitle'] . " - " . $child['parentTitle'];
  416. $summary = htmlentities($child['title'], ENT_QUOTES);
  417. $thumb = $child['thumb'];
  418. $image = "album";
  419. $height = "150";
  420. $width = "150";
  421. }elseif($type == "clip"){
  422. $title = $child['title'].' - Trailer';
  423. $summary = ($child['summary'] != "" ? $child['summary'] : "<i>No summary loaded.</i>");
  424. $thumb = ($child['thumb'] != "" ? $child['thumb'] : 'images/nadaplaying.jpg');
  425. $image = "movie";
  426. $height = "150";
  427. $width = "100";
  428. }
  429. $gotPlex .= '<div class="item '.$active.'">';
  430. $gotPlex .= "<a href='$plexLink' target='_blank'><img alt='$title' class='carousel-image $image' src='image.php?img=$thumb&height=$height&width=$width'></a>";
  431. $gotPlex .= '<div class="carousel-caption '. $image . '""><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  432. $plexLink = "";
  433. }
  434. $gotPlex .= '</div>';
  435. if ($i > 1){
  436. $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>';
  437. }
  438. $gotPlex .= '</div></div>';
  439. $noPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  440. $noPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  441. $noPlex .= '<div class="carousel-inner" role="listbox">';
  442. $noPlex .= '<div class="item active">';
  443. $noPlex .= "<img alt='nada' class='carousel-image movie' src='images/nadaplaying.jpg'>";
  444. $noPlex .= '<div class="carousel-caption"><h4>Nothing Playing</h4><small><em>Get to Streaming!</em></small></div></div></div></div></div>';
  445. if ($i != 0){ return $gotPlex; }
  446. if ($i == 0){ return $noPlex; }
  447. }
  448. function getSickrageCalendarWanted($array){
  449. $array = json_decode($array, true);
  450. $gotCalendar = "";
  451. $i = 0;
  452. foreach($array['data']['missed'] AS $child) {
  453. $i++;
  454. $seriesName = $child['show_name'];
  455. $episodeID = $child['tvdbid'];
  456. $episodeAirDate = $child['airdate'];
  457. $episodeAirDateTime = explode(" ",$child['airs']);
  458. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  459. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  460. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  461. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  462. $downloaded = "0";
  463. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  464. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  465. }
  466. foreach($array['data']['today'] AS $child) {
  467. $i++;
  468. $seriesName = $child['show_name'];
  469. $episodeID = $child['tvdbid'];
  470. $episodeAirDate = $child['airdate'];
  471. $episodeAirDateTime = explode(" ",$child['airs']);
  472. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  473. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  474. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  475. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  476. $downloaded = "0";
  477. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  478. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  479. }
  480. foreach($array['data']['soon'] AS $child) {
  481. $i++;
  482. $seriesName = $child['show_name'];
  483. $episodeID = $child['tvdbid'];
  484. $episodeAirDate = $child['airdate'];
  485. $episodeAirDateTime = explode(" ",$child['airs']);
  486. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  487. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  488. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  489. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  490. $downloaded = "0";
  491. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  492. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  493. }
  494. foreach($array['data']['later'] AS $child) {
  495. $i++;
  496. $seriesName = $child['show_name'];
  497. $episodeID = $child['tvdbid'];
  498. $episodeAirDate = $child['airdate'];
  499. $episodeAirDateTime = explode(" ",$child['airs']);
  500. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  501. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  502. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  503. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  504. $downloaded = "0";
  505. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  506. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  507. }
  508. if ($i != 0){ return $gotCalendar; }
  509. }
  510. function getSickrageCalendarHistory($array){
  511. $array = json_decode($array, true);
  512. $gotCalendar = "";
  513. $i = 0;
  514. foreach($array['data'] AS $child) {
  515. $i++;
  516. $seriesName = $child['show_name'];
  517. $episodeID = $child['tvdbid'];
  518. $episodeAirDate = $child['date'];
  519. $downloaded = "green-bg";
  520. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  521. }
  522. if ($i != 0){ return $gotCalendar; }
  523. }
  524. function getSonarrCalendar($array){
  525. $array = json_decode($array, true);
  526. $gotCalendar = "";
  527. $i = 0;
  528. foreach($array AS $child) {
  529. $i++;
  530. $seriesName = $child['series']['title'];
  531. $episodeID = $child['series']['tvdbId'];
  532. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  533. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  534. $episodeAirDate = $child['airDateUtc'];
  535. $episodeAirDate = strtotime($episodeAirDate);
  536. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  537. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  538. $downloaded = $child['hasFile'];
  539. 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"; }
  540. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  541. }
  542. if ($i != 0){ return $gotCalendar; }
  543. }
  544. function getRadarrCalendar($array){
  545. $array = json_decode($array, true);
  546. $gotCalendar = "";
  547. $i = 0;
  548. foreach($array AS $child) {
  549. if(isset($child['inCinemas'])){
  550. $i++;
  551. $movieName = $child['title'];
  552. $movieID = $child['imdbId'];
  553. if(!isset($movieID)){ $movieID = ""; }
  554. if(isset($child['inCinemas']) && isset($child['physicalRelease'])){
  555. $physicalRelease = $child['physicalRelease'];
  556. $physicalRelease = strtotime($physicalRelease);
  557. $physicalRelease = date("Y-m-d", $physicalRelease);
  558. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  559. $downloaded = $child['hasFile'];
  560. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  561. }else{
  562. $physicalRelease = $child['inCinemas'];
  563. $downloaded = "light-blue-bg";
  564. }
  565. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\", url: \"http://www.imdb.com/title/$movieID\" }, \n";
  566. }
  567. }
  568. if ($i != 0){ return $gotCalendar; }
  569. }
  570. function nzbgetConnect($url, $port, $username, $password, $list){
  571. $urlCheck = stripos($url, "http");
  572. if ($urlCheck === false) {
  573. $url = "http://" . $url;
  574. }
  575. if($port !== ""){ $url = $url . ":" . $port; }
  576. $address = $url;
  577. $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
  578. $api = json_decode($api, true);
  579. $i = 0;
  580. $gotNZB = "";
  581. foreach ($api['result'] AS $child) {
  582. $i++;
  583. //echo '<pre>' . var_export($child, true) . '</pre>';
  584. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  585. $downloadStatus = $child['Status'];
  586. $downloadCategory = $child['Category'];
  587. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  588. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  589. if($child['Health'] <= "750"){
  590. $downloadHealth = "danger";
  591. }elseif($child['Health'] <= "900"){
  592. $downloadHealth = "warning";
  593. }elseif($child['Health'] <= "1000"){
  594. $downloadHealth = "success";
  595. }
  596. $gotNZB .= '<tr>
  597. <td>'.$downloadName.'</td>
  598. <td>'.$downloadStatus.'</td>
  599. <td>'.$downloadCategory.'</td>
  600. <td>
  601. <div class="progress">
  602. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  603. <p class="text-center">'.round($downloadPercent).'%</p>
  604. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  605. </div>
  606. </div>
  607. </td>
  608. </tr>';
  609. }
  610. if($i > 0){ return $gotNZB; }
  611. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  612. }
  613. function sabnzbdConnect($url, $port, $key, $list){
  614. $urlCheck = stripos($url, "http");
  615. if ($urlCheck === false) {
  616. $url = "http://" . $url;
  617. }
  618. if($port !== ""){ $url = $url . ":" . $port; }
  619. $address = $url;
  620. $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
  621. $api = json_decode($api, true);
  622. $i = 0;
  623. $gotNZB = "";
  624. foreach ($api[$list]['slots'] AS $child) {
  625. $i++;
  626. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  627. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  628. $downloadStatus = $child['status'];
  629. $gotNZB .= '<tr>
  630. <td>'.$downloadName.'</td>
  631. <td>'.$downloadStatus.'</td>
  632. <td>'.$downloadCategory.'</td>
  633. <td>
  634. <div class="progress">
  635. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  636. <p class="text-center">'.round($downloadPercent).'%</p>
  637. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  638. </div>
  639. </div>
  640. </td>
  641. </tr>';
  642. }
  643. if($i > 0){ return $gotNZB; }
  644. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  645. }
  646. function getHeadphonesCalendar($url, $port, $key, $list){
  647. $urlCheck = stripos($url, "http");
  648. if ($urlCheck === false) {
  649. $url = "http://" . $url;
  650. }
  651. if($port !== ""){ $url = $url . ":" . $port; }
  652. $address = $url;
  653. $api = file_get_contents($address."/api?apikey=".$key."&cmd=$list");
  654. $api = json_decode($api, true);
  655. $i = 0;
  656. $gotCalendar = "";
  657. foreach($api AS $child) {
  658. if($child['Status'] == "Wanted"){
  659. $i++;
  660. $albumName = addslashes($child['AlbumTitle']);
  661. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  662. $albumDate = $child['ReleaseDate'];
  663. $albumID = $child['AlbumID'];
  664. $albumDate = strtotime($albumDate);
  665. $albumDate = date("Y-m-d", $albumDate);
  666. $albumStatus = $child['Status'];
  667. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  668. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  669. $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  670. }
  671. }
  672. if ($i != 0){ return $gotCalendar; }
  673. }
  674. function post_router($url, $data, $headers = array(), $referer='') {
  675. if (function_exists('curl_version')) {
  676. return curl_post($url, $data, $headers, $referer);
  677. } else {
  678. return post_request($url, $data, $headers, $referer);
  679. }
  680. }
  681. function curl_post($url, $data, $headers = array(), $referer='') {
  682. // Initiate cURL
  683. $curlReq = curl_init($url);
  684. // As post request
  685. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  686. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  687. // Format Headers
  688. $cHeaders = array();
  689. foreach ($headers as $k => $v) {
  690. $cHeaders[] = $k.': '.$v;
  691. }
  692. if (count($cHeaders)) {
  693. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  694. }
  695. // Format Data
  696. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  697. // Execute
  698. $result = curl_exec($curlReq);
  699. // Close
  700. curl_close($curlReq);
  701. // Return
  702. return array('content'=>$result);
  703. }
  704. function post_request($url, $data, $headers = array(), $referer='') {
  705. // Adapted from http://stackoverflow.com/a/28387011/6810513
  706. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  707. if (isset($headers['Content-type'])) {
  708. switch ($headers['Content-type']) {
  709. case 'application/json':
  710. $data = json_encode($data);
  711. break;
  712. case 'application/x-www-form-urlencoded':
  713. $data = http_build_query($data);
  714. break;
  715. }
  716. } else {
  717. $headers['Content-type'] = 'application/x-www-form-urlencoded';
  718. $data = http_build_query($data);
  719. }
  720. // parse the given URL
  721. $urlDigest = parse_url($url);
  722. // extract host and path:
  723. $host = $urlDigest['host'].(isset($urlDigest['port'])?':'.$urlDigest['port']:'');
  724. $path = $urlDigest['path'];
  725. if ($urlDigest['scheme'] != 'http') {
  726. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  727. }
  728. // open a socket connection on port 80 - timeout: 30 sec
  729. $fp = fsockopen($host, 80, $errno, $errstr, 30);
  730. if ($fp){
  731. // send the request headers:
  732. fputs($fp, "POST $path HTTP/1.1\r\n");
  733. fputs($fp, "Host: $host\r\n");
  734. if ($referer != '')
  735. fputs($fp, "Referer: $referer\r\n");
  736. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  737. foreach($headers as $k => $v) {
  738. fputs($fp, $k.": ".$v."\r\n");
  739. }
  740. fputs($fp, "Connection: close\r\n\r\n");
  741. fputs($fp, $data);
  742. $result = '';
  743. while(!feof($fp)) {
  744. // receive the results of the request
  745. $result .= fgets($fp, 128);
  746. }
  747. }
  748. else {
  749. return array(
  750. 'status' => 'err',
  751. 'error' => "$errstr ($errno)"
  752. );
  753. }
  754. // close the socket connection:
  755. fclose($fp);
  756. // split the result header from the content
  757. $result = explode("\r\n\r\n", $result, 2);
  758. $header = isset($result[0]) ? $result[0] : '';
  759. $content = isset($result[1]) ? $result[1] : '';
  760. // return as structured array:
  761. return array(
  762. 'status' => 'ok',
  763. 'header' => $header,
  764. 'content' => $content,
  765. );
  766. }
  767. ?>