functions.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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 START ====
  9. if (function_exists('ldap_connect')) :
  10. // Pass credentials to LDAP backend
  11. function plugin_auth_ldap($username, $password) {
  12. // returns true or false
  13. $ldap = ldap_connect(AUTHBACKENDHOST.(AUTHBACKENDPORT?':'.AUTHBACKENDPORT:'389'));
  14. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  15. return true;
  16. } else {
  17. return false;
  18. }
  19. return false;
  20. }
  21. endif;
  22. // Pass credentials to FTP backend
  23. function plugin_auth_ftp($username, $password) {
  24. // returns true or false
  25. // Connect to FTP
  26. $conn_id = ftp_ssl_connect(AUTHBACKENDHOST, (AUTHBACKENDPORT?AUTHBACKENDPORT:21), 20); // 20 Second Timeout
  27. // Check if valid FTP connection
  28. if ($conn_id) {
  29. // Attempt login
  30. @$login_result = ftp_login($conn_id, $username, $password);
  31. // Return Result
  32. if ($login_result) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. } else {
  38. return false;
  39. }
  40. return false;
  41. }
  42. // Pass credentials to Emby Backend
  43. function plugin_auth_emby_local($username, $password) {
  44. $urlCheck = stripos(AUTHBACKENDHOST, "http");
  45. if ($urlCheck === false) {
  46. $embyAddress = "http://" . AUTHBACKENDHOST;
  47. } else {
  48. $embyAddress = AUTHBACKENDHOST;
  49. }
  50. if(AUTHBACKENDPORT !== ""){ $embyAddress .= ":" . AUTHBACKENDPORT; }
  51. $headers = array(
  52. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  53. 'Content-Type' => 'application/json',
  54. );
  55. $body = array(
  56. 'Username' => $username,
  57. 'Password' => sha1($password),
  58. 'PasswordMd5' => md5($password),
  59. );
  60. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  61. if (isset($response['content'])) {
  62. $json = json_decode($response['content'], true);
  63. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  64. // Login Success - Now Logout Emby Session As We No Longer Need It
  65. $headers = array(
  66. 'X-Mediabrowser-Token' => $json['AccessToken'],
  67. );
  68. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  69. return true;
  70. }
  71. }
  72. return false;
  73. }
  74. if (function_exists('curl_version')) :
  75. // Authenticate Against Emby Local (first) and Emby Connect
  76. function plugin_auth_emby_all($username, $password) {
  77. return plugin_auth_emby_local($username, $password) || plugin_auth_emby_connect($username, $password);
  78. }
  79. // Authenicate against emby connect
  80. function plugin_auth_emby_connect($username, $password) {
  81. $urlCheck = stripos(AUTHBACKENDHOST, "http");
  82. if ($urlCheck === false) {
  83. $embyAddress = "http://" . AUTHBACKENDHOST;
  84. } else {
  85. $embyAddress = AUTHBACKENDHOST;
  86. }
  87. if(AUTHBACKENDPORT !== "") { $embyAddress .= ":" . AUTHBACKENDPORT; }
  88. // Get A User
  89. $connectId = '';
  90. $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  91. if (is_array($userIds)) {
  92. foreach ($userIds as $key => $value) { // Scan for this user
  93. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  94. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  95. $connectId = $value['ConnectUserId'];
  96. break;
  97. }
  98. }
  99. }
  100. if ($connectId) {
  101. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  102. $headers = array(
  103. 'Accept'=> 'application/json',
  104. 'Content-Type' => 'application/x-www-form-urlencoded',
  105. );
  106. $body = array(
  107. 'nameOrEmail' => $username,
  108. 'rawpw' => $password,
  109. );
  110. $result = curl_post($connectURL, $body, $headers);
  111. if (isset($result['content'])) {
  112. $json = json_decode($result['content'], true);
  113. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  114. return true;
  115. }
  116. }
  117. }
  118. }
  119. return false;
  120. }
  121. // Pass credentials to Plex Backend
  122. function plugin_auth_plex($username, $password) {
  123. // Quick out
  124. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  125. return true;
  126. }
  127. //Get User List
  128. $approvedUsers = array();
  129. $userURL = 'https://plex.tv/pms/friends/all';
  130. $userHeaders = array(
  131. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  132. );
  133. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  134. if (is_array($userXML) || is_object($userXML)) {
  135. //Build User List array
  136. $isUser = false;
  137. $usernameLower = strtolower($username);
  138. foreach($userXML AS $child) {
  139. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  140. $isUser = true;
  141. break;
  142. }
  143. }
  144. if ($isUser) {
  145. //Login User
  146. $connectURL = 'https://plex.tv/users/sign_in.json';
  147. $headers = array(
  148. 'Accept'=> 'application/json',
  149. 'Content-Type' => 'application/x-www-form-urlencoded',
  150. 'X-Plex-Product' => 'Organizr',
  151. 'X-Plex-Version' => '1.0',
  152. 'X-Plex-Client-Identifier' => '01010101-10101010',
  153. );
  154. $body = array(
  155. 'user[login]' => $username,
  156. 'user[password]' => $password,
  157. );
  158. $result = curl_post($connectURL, $body, $headers);
  159. if (isset($result['content'])) {
  160. $json = json_decode($result['content'], true);
  161. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && $json['user']['username'] == $username) {
  162. return true;
  163. }
  164. }
  165. }
  166. }
  167. return false;
  168. }
  169. endif;
  170. // ==== Auth Plugins END ====
  171. // ==== General Class Definitions START ====
  172. class setLanguage {
  173. private $language = null;
  174. private $langCode = null;
  175. function __construct($language = false) {
  176. // Default
  177. if (!$language) {
  178. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  179. }
  180. $this->langCode = $language;
  181. if (file_exists("lang/{$language}.ini")) {
  182. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  183. } else {
  184. $this->language = parse_ini_file("lang/en.ini", false, INI_SCANNER_RAW);
  185. }
  186. }
  187. public function getLang() {
  188. return $this->langCode;
  189. }
  190. public function translate($originalWord) {
  191. $getArg = func_num_args();
  192. if ($getArg > 1) {
  193. $allWords = func_get_args();
  194. array_shift($allWords);
  195. } else {
  196. $allWords = array();
  197. }
  198. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  199. if (!$translatedWord) {
  200. echo ("Translation not found for: $originalWord");
  201. }
  202. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  203. return vsprintf($translatedWord, $allWords);
  204. }
  205. }
  206. $language = new setLanguage;
  207. // ==== General Class Definitions END ====
  208. // Direct request to curl if it exists, otherwise handle if not HTTPS
  209. function post_router($url, $data, $headers = array(), $referer='') {
  210. if (function_exists('curl_version')) {
  211. return curl_post($url, $data, $headers, $referer);
  212. } else {
  213. return post_request($url, $data, $headers, $referer);
  214. }
  215. }
  216. if (function_exists('curl_version')) :
  217. // Curl Post
  218. function curl_post($url, $data, $headers = array(), $referer='') {
  219. // Initiate cURL
  220. $curlReq = curl_init($url);
  221. // As post request
  222. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  223. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  224. // Format Data
  225. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  226. case 'application/json':
  227. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  228. break;
  229. case 'application/x-www-form-urlencoded';
  230. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  231. break;
  232. default:
  233. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  234. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  235. }
  236. // Format Headers
  237. $cHeaders = array();
  238. foreach ($headers as $k => $v) {
  239. $cHeaders[] = $k.': '.$v;
  240. }
  241. if (count($cHeaders)) {
  242. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  243. }
  244. // Execute
  245. $result = curl_exec($curlReq);
  246. // Close
  247. curl_close($curlReq);
  248. // Return
  249. return array('content'=>$result);
  250. }
  251. //Curl Get Function
  252. function curl_get($url, $headers = array()) {
  253. // Initiate cURL
  254. $curlReq = curl_init($url);
  255. // As post request
  256. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  257. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  258. // Format Headers
  259. $cHeaders = array();
  260. foreach ($headers as $k => $v) {
  261. $cHeaders[] = $k.': '.$v;
  262. }
  263. if (count($cHeaders)) {
  264. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  265. }
  266. // Execute
  267. $result = curl_exec($curlReq);
  268. // Close
  269. curl_close($curlReq);
  270. // Return
  271. return $result;
  272. }
  273. endif;
  274. //Case-Insensitive Function
  275. function in_arrayi($needle, $haystack) {
  276. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  277. }
  278. // HTTP post request (Removes need for curl, probably useless)
  279. function post_request($url, $data, $headers = array(), $referer='') {
  280. // Adapted from http://stackoverflow.com/a/28387011/6810513
  281. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  282. if (isset($headers['Content-Type'])) {
  283. switch ($headers['Content-Type']) {
  284. case 'application/json':
  285. $data = json_encode($data);
  286. break;
  287. case 'application/x-www-form-urlencoded':
  288. $data = http_build_query($data);
  289. break;
  290. }
  291. } else {
  292. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  293. $data = http_build_query($data);
  294. }
  295. // parse the given URL
  296. $urlDigest = parse_url($url);
  297. // extract host and path:
  298. $host = $urlDigest['host'].(isset($urlDigest['port'])?':'.$urlDigest['port']:'');
  299. $path = $urlDigest['path'];
  300. if ($urlDigest['scheme'] != 'http') {
  301. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  302. }
  303. // open a socket connection on port 80 - timeout: 30 sec
  304. $fp = fsockopen($host, 80, $errno, $errstr, 30);
  305. if ($fp){
  306. // send the request headers:
  307. fputs($fp, "POST $path HTTP/1.1\r\n");
  308. fputs($fp, "Host: $host\r\n");
  309. if ($referer != '')
  310. fputs($fp, "Referer: $referer\r\n");
  311. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  312. foreach($headers as $k => $v) {
  313. fputs($fp, $k.": ".$v."\r\n");
  314. }
  315. fputs($fp, "Connection: close\r\n\r\n");
  316. fputs($fp, $data);
  317. $result = '';
  318. while(!feof($fp)) {
  319. // receive the results of the request
  320. $result .= fgets($fp, 128);
  321. }
  322. }
  323. else {
  324. return array(
  325. 'status' => 'err',
  326. 'error' => "$errstr ($errno)"
  327. );
  328. }
  329. // close the socket connection:
  330. fclose($fp);
  331. // split the result header from the content
  332. $result = explode("\r\n\r\n", $result, 2);
  333. $header = isset($result[0]) ? $result[0] : '';
  334. $content = isset($result[1]) ? $result[1] : '';
  335. // return as structured array:
  336. return array(
  337. 'status' => 'ok',
  338. 'header' => $header,
  339. 'content' => $content,
  340. );
  341. }
  342. // Format item from Emby for Carousel
  343. function resolveEmbyItem($address, $token, $item) {
  344. // Static Height
  345. $height = 150;
  346. // Get Item Details
  347. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0];
  348. switch ($item['Type']) {
  349. case 'Episode':
  350. $title = $item['SeriesName'].': '.$item['Name'].' (Season '.$item['ParentIndexNumber'].': Episode '.$item['IndexNumber'].')';
  351. $imageId = $itemDetails['SeriesId'];
  352. $width = 100;
  353. $image = 'carousel-image season';
  354. $style = '';
  355. break;
  356. case 'MusicAlbum':
  357. $title = $item['Name'];
  358. $imageId = $itemDetails['Id'];
  359. $width = 150;
  360. $image = 'music';
  361. $style = 'left: 160px !important;';
  362. break;
  363. default:
  364. $title = $item['Name'];
  365. $imageId = $item['Id'];
  366. $width = 100;
  367. $image = 'carousel-image movie';
  368. $style = '';
  369. }
  370. // If No Overview
  371. if (!isset($itemDetails['Overview'])) {
  372. $itemDetails['Overview'] = '';
  373. }
  374. // Assemble Item And Cache Into Array
  375. 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>';
  376. }
  377. // Format item from Plex for Carousel
  378. function resolvePlexItem($server, $token, $item) {
  379. // Static Height
  380. $height = 150;
  381. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  382. switch ($item['type']) {
  383. case 'season':
  384. $title = $item['parentTitle'];
  385. $summary = $item['parentSummary'];
  386. $width = 100;
  387. $image = 'carousel-image season';
  388. $style = '';
  389. break;
  390. case 'album':
  391. $title = $item['parentTitle'];
  392. $summary = $item['title'];
  393. $width = 150;
  394. $image = 'album';
  395. $style = 'left: 160px !important;';
  396. break;
  397. default:
  398. $title = $item['title'];
  399. $summary = $item['summary'];
  400. $width = 100;
  401. $image = 'carousel-image movie';
  402. $style = '';
  403. }
  404. // If No Overview
  405. if (!isset($itemDetails['Overview'])) {
  406. $itemDetails['Overview'] = '';
  407. }
  408. // Assemble Item And Cache Into Array
  409. return '<div class="item"><a href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" src="image.php?source=plex&img='.$item['thumb'].'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption" style="'.$style.'"><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  410. }
  411. // Create Carousel
  412. function outputCarousel($header, $size, $type, $items) {
  413. // If None Populate Empty Item
  414. if (!count($items)) {
  415. $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>');
  416. }
  417. // Set First As Active
  418. $items[0] = preg_replace('/^<div class="item ?">/','<div class="item active">', $items[0]);
  419. // Add Buttons
  420. $buttons = '';
  421. if (count($items) > 1) {
  422. $buttons = '
  423. <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>
  424. <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>';
  425. }
  426. return '
  427. <div class="col-lg-'.$size.'">
  428. <h5 class="text-center">'.$header.'</h5>
  429. <div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">
  430. '.implode('',$items).'
  431. </div>'.$buttons.'
  432. </div></div>';
  433. }
  434. // Get Now Playing Streams From Emby
  435. function getEmbyStreams($url, $port, $token, $size, $header) {
  436. if (stripos($url, "http") === false) {
  437. $url = "http://" . $url;
  438. }
  439. if ($port !== "") {
  440. $url = $url . ":" . $port;
  441. }
  442. $address = $url;
  443. $api = json_decode(file_get_contents($address.'/Sessions?api_key='.$token),true);
  444. $playingItems = array();
  445. foreach($api as $key => $value) {
  446. if (isset($value['NowPlayingItem'])) {
  447. $playingItems[] = resolveEmbyItem($address, $token, $value['NowPlayingItem']);
  448. }
  449. }
  450. return outputCarousel($header, $size, 'streams-emby', $playingItems);
  451. }
  452. // Get Now Playing Streams From Plex
  453. function getPlexStreams($url, $port, $token, $size, $header){
  454. if (stripos($url, "http") === false) {
  455. $url = "http://" . $url;
  456. }
  457. if ($port !== "") {
  458. $url = $url . ":" . $port;
  459. }
  460. $address = $url;
  461. // Perform API requests
  462. $api = file_get_contents($address."/status/sessions?X-Plex-Token=".$token);
  463. $api = simplexml_load_string($api);
  464. $getServer = simplexml_load_string(file_get_contents($address."/?X-Plex-Token=".$token));
  465. // Identify the local machine
  466. $gotServer = $getServer['machineIdentifier'];
  467. $items = array();
  468. foreach($api AS $child) {
  469. $items[] = resolvePlexItem($gotServer, $token, $child);
  470. }
  471. return outputCarousel($header, $size, 'streams-plex', $items);
  472. }
  473. // Get Recent Content From Emby
  474. function getEmbyRecent($url, $port, $type, $token, $size, $header) {
  475. if (stripos($url, "http") === false) {
  476. $url = "http://" . $url;
  477. }
  478. if ($port !== "") {
  479. $url = $url . ":" . $port;
  480. }
  481. $address = $url;
  482. // Resolve Types
  483. switch ($type) {
  484. case 'movie':
  485. $embyTypeQuery = 'IncludeItemTypes=Movie&';
  486. break;
  487. case 'season':
  488. $embyTypeQuery = 'IncludeItemTypes=Episode&';
  489. break;
  490. case 'album':
  491. $embyTypeQuery = 'IncludeItemTypes=MusicAlbum&';
  492. break;
  493. default:
  494. $embyTypeQuery = '';
  495. }
  496. // Get A User
  497. $userIds = json_decode(file_get_contents($address.'/Users?api_key='.$token),true);
  498. foreach ($userIds as $value) { // Scan for admin user
  499. $userId = $value['Id'];
  500. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  501. break;
  502. }
  503. }
  504. // Get the latest Items
  505. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.$token),true);
  506. // For Each Item In Category
  507. $items = array();
  508. foreach ($latest as $k => $v) {
  509. $items[] = resolveEmbyItem($address, $token, $v);
  510. }
  511. return outputCarousel($header, $size, $type.'-emby', $items);
  512. }
  513. // Get Recent Content From Plex
  514. function getPlexRecent($url, $port, $type, $token, $size, $header){
  515. if (stripos($url, "http") === false) {
  516. $url = "http://" . $url;
  517. }
  518. if ($port !== "") {
  519. $url = $url . ":" . $port;
  520. }
  521. $address = $url;
  522. // Perform Requests
  523. $api = file_get_contents($address."/library/recentlyAdded?X-Plex-Token=".$token);
  524. $api = simplexml_load_string($api);
  525. $getServer = simplexml_load_string(file_get_contents($address."/?X-Plex-Token=".$token));
  526. // Identify the local machine
  527. $gotServer = $getServer['machineIdentifier'];
  528. $items = array();
  529. foreach($api AS $child) {
  530. if($child['type'] == $type){
  531. $items[] = resolvePlexItem($gotServer, $token, $child);
  532. }
  533. }
  534. return outputCarousel($header, $size, $type.'-plex', $items);
  535. }
  536. // Simplier access to class
  537. function translate($string) {
  538. if (isset($GLOBALS['language'])) {
  539. return $GLOBALS['language']->translate($string);
  540. } else {
  541. return '!Translations Not Loaded!';
  542. }
  543. }
  544. // Generate Random string
  545. function randString($length = 10) {
  546. $tmp = '';
  547. $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
  548. for ($i = 0; $i < $length; $i++) {
  549. $tmp .= substr(str_shuffle($chars), 0, 1);
  550. }
  551. return $tmp;
  552. }
  553. // Create config file in the return syntax
  554. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  555. $output = array();
  556. foreach ($array as $k => $v) {
  557. $allowCommit = true;
  558. switch (gettype($v)) {
  559. case 'boolean':
  560. $item = ($v?'true':'false');
  561. break;
  562. case 'integer':
  563. case 'double':
  564. case 'integer':
  565. case 'NULL':
  566. $item = $v;
  567. break;
  568. case 'string':
  569. $item = '"'.addslashes($v).'"';
  570. break;
  571. case 'array':
  572. $item = createConfig($v, false, $nest+1);
  573. break;
  574. default:
  575. $allowCommit = false;
  576. }
  577. if($allowCommit) {
  578. $output[] = str_repeat("\t",$nest+1).'"'.$k.'" => '.$item;
  579. }
  580. }
  581. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  582. if (!$nest && $path) {
  583. $pathDigest = pathinfo($path);
  584. @mkdir($pathDigest['dirname'], 0770, true);
  585. if (file_exists($path)) {
  586. rename($path, $path.'.bak');
  587. }
  588. $file = fopen($path, 'w');
  589. fwrite($file, $output);
  590. fclose($file);
  591. if (file_exists($path)) {
  592. @unlink($path.'.bak');
  593. return true;
  594. }
  595. return false;
  596. } else {
  597. return $output;
  598. }
  599. }
  600. // Load a config file written in the return syntax
  601. function loadConfig($path = 'config/config.php') {
  602. // Adapted from http://stackoverflow.com/a/14173339/6810513
  603. if (!is_file($path)) {
  604. return null;
  605. } else {
  606. return (array) call_user_func(function() use($path) {
  607. return include($path);
  608. });
  609. }
  610. }
  611. function updateConfig($new, $current = false) {
  612. // Get config if not supplied
  613. if (!$current) {
  614. $current = loadConfig();
  615. }
  616. // Inject Parts
  617. foreach ($new as $k => $v) {
  618. $current[$k] = $v;
  619. }
  620. // Return Create
  621. return createConfig($current);
  622. }
  623. // Inject Defaults As Needed
  624. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  625. if (is_string($path)) {
  626. $loadedDefaults = loadConfig($path);
  627. } else {
  628. $loadedDefaults = $path;
  629. }
  630. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  631. }
  632. // support function for fillDefaultConfig()
  633. function fillDefaultConfig_recurse($current, $defaults) {
  634. foreach($defaults as $k => $v) {
  635. if (!isset($current[$k])) {
  636. $current[$k] = $v;
  637. } else if (is_array($current[$k]) && is_array($v)) {
  638. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  639. }
  640. }
  641. return $current;
  642. };
  643. // Define Scalar Variables (nest non-secular with underscores)
  644. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  645. foreach($array as $k => $v) {
  646. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  647. define($nest_prefix.$k, $v, $anyCase);
  648. } else if (is_array($v)) {
  649. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  650. }
  651. }
  652. }
  653. // This function exists only because I am lazy
  654. function configLazy($path) {
  655. $config = fillDefaultConfig(loadConfig($path));
  656. if (is_array($config)) {
  657. defineConfig($config);
  658. }
  659. return $config;
  660. }
  661. // Function to be called at top of each to allow upgrading environment as the spec changes
  662. function upgradeCheck() {
  663. // Upgrade to 1.31
  664. if (file_exists('homepageSettings.ini.php')) {
  665. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  666. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  667. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  668. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  669. foreach($databaseConfig as $k => $v) {
  670. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  671. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  672. }
  673. write_ini_file($databaseData, 'databaseLocation.ini.php');
  674. unlink('homepageSettings.ini.php');
  675. unset($databaseData);
  676. unset($homepageConfig);
  677. }
  678. // Upgrade to 1.32
  679. if (file_exists('databaseLocation.ini.php')) {
  680. // Load Existing
  681. $config = parse_ini_file('databaseLocation.ini.php', true);
  682. // Refactor
  683. $config['database_Location'] = str_replace('//','/',$config['databaseLocation'].'/');
  684. $config['user_home'] = $config['databaseLocation'].'users/';
  685. unset($config['databaseLocation']);
  686. $createConfigSuccess = createConfig($config, 'config/config.php', $nest = 0);
  687. // Create new config
  688. if ($createConfigSuccess) {
  689. // Make Config Dir (this should never happen as the dir and defaults file should be there);
  690. @mkdir('config', 0775, true);
  691. // Remove Old ini file
  692. unlink('databaseLocation.ini.php');
  693. }
  694. }
  695. return true;
  696. }
  697. // Check if all software dependancies are met
  698. function dependCheck() {
  699. return true;
  700. }
  701. // ==============
  702. function clean($strin) {
  703. $strout = null;
  704. for ($i = 0; $i < strlen($strin); $i++) {
  705. $ord = ord($strin[$i]);
  706. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  707. $strout .= "&amp;#{$ord};";
  708. }
  709. else {
  710. switch ($strin[$i]) {
  711. case '<':
  712. $strout .= '&lt;';
  713. break;
  714. case '>':
  715. $strout .= '&gt;';
  716. break;
  717. case '&':
  718. $strout .= '&amp;';
  719. break;
  720. case '"':
  721. $strout .= '&quot;';
  722. break;
  723. default:
  724. $strout .= $strin[$i];
  725. }
  726. }
  727. }
  728. return $strout;
  729. }
  730. function registration_callback($username, $email, $userdir){
  731. global $data;
  732. $data = array($username, $email, $userdir);
  733. }
  734. function printArray($arrayName){
  735. $messageCount = count($arrayName);
  736. $i = 0;
  737. foreach ( $arrayName as $item ) :
  738. $i++;
  739. if($i < $messageCount) :
  740. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  741. elseif($i = $messageCount) :
  742. echo "<small class='text-uppercase'>" . $item . "</small>";
  743. endif;
  744. endforeach;
  745. }
  746. function write_ini_file($content, $path) {
  747. if (!$handle = fopen($path, 'w')) {
  748. return false;
  749. }
  750. $success = fwrite($handle, trim($content));
  751. fclose($handle);
  752. return $success;
  753. }
  754. function gotTimezone(){
  755. $regions = array(
  756. 'Africa' => DateTimeZone::AFRICA,
  757. 'America' => DateTimeZone::AMERICA,
  758. 'Antarctica' => DateTimeZone::ANTARCTICA,
  759. 'Arctic' => DateTimeZone::ARCTIC,
  760. 'Asia' => DateTimeZone::ASIA,
  761. 'Atlantic' => DateTimeZone::ATLANTIC,
  762. 'Australia' => DateTimeZone::AUSTRALIA,
  763. 'Europe' => DateTimeZone::EUROPE,
  764. 'Indian' => DateTimeZone::INDIAN,
  765. 'Pacific' => DateTimeZone::PACIFIC
  766. );
  767. $timezones = array();
  768. foreach ($regions as $name => $mask) {
  769. $zones = DateTimeZone::listIdentifiers($mask);
  770. foreach($zones as $timezone) {
  771. $time = new DateTime(NULL, new DateTimeZone($timezone));
  772. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  773. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  774. }
  775. }
  776. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  777. foreach($timezones as $region => $list) {
  778. print '<optgroup label="' . $region . '">' . "\n";
  779. foreach($list as $timezone => $name) {
  780. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  781. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  782. }
  783. print '</optgroup>' . "\n";
  784. }
  785. print '</select>';
  786. }
  787. function getTimezone(){
  788. $regions = array(
  789. 'Africa' => DateTimeZone::AFRICA,
  790. 'America' => DateTimeZone::AMERICA,
  791. 'Antarctica' => DateTimeZone::ANTARCTICA,
  792. 'Arctic' => DateTimeZone::ARCTIC,
  793. 'Asia' => DateTimeZone::ASIA,
  794. 'Atlantic' => DateTimeZone::ATLANTIC,
  795. 'Australia' => DateTimeZone::AUSTRALIA,
  796. 'Europe' => DateTimeZone::EUROPE,
  797. 'Indian' => DateTimeZone::INDIAN,
  798. 'Pacific' => DateTimeZone::PACIFIC
  799. );
  800. $timezones = array();
  801. foreach ($regions as $name => $mask) {
  802. $zones = DateTimeZone::listIdentifiers($mask);
  803. foreach($zones as $timezone) {
  804. $time = new DateTime(NULL, new DateTimeZone($timezone));
  805. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  806. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  807. }
  808. }
  809. print '<select name="timezone" id="timezone" class="form-control material" required>';
  810. foreach($timezones as $region => $list) {
  811. print '<optgroup label="' . $region . '">' . "\n";
  812. foreach($list as $timezone => $name) {
  813. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  814. }
  815. print '</optgroup>' . "\n";
  816. }
  817. print '</select>';
  818. }
  819. function explosion($string, $position){
  820. $getWord = explode("|", $string);
  821. return $getWord[$position];
  822. }
  823. function getServerPath() {
  824. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  825. $protocol = "https://";
  826. } else {
  827. $protocol = "http://";
  828. }
  829. return $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  830. }
  831. function get_browser_name() {
  832. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  833. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  834. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  835. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  836. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  837. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  838. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  839. return 'Other';
  840. }
  841. function getSickrageCalendarWanted($array){
  842. $array = json_decode($array, true);
  843. $gotCalendar = "";
  844. $i = 0;
  845. foreach($array['data']['missed'] AS $child) {
  846. $i++;
  847. $seriesName = $child['show_name'];
  848. $episodeID = $child['tvdbid'];
  849. $episodeAirDate = $child['airdate'];
  850. $episodeAirDateTime = explode(" ",$child['airs']);
  851. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  852. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  853. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  854. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  855. $downloaded = "0";
  856. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  857. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  858. }
  859. foreach($array['data']['today'] AS $child) {
  860. $i++;
  861. $seriesName = $child['show_name'];
  862. $episodeID = $child['tvdbid'];
  863. $episodeAirDate = $child['airdate'];
  864. $episodeAirDateTime = explode(" ",$child['airs']);
  865. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  866. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  867. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  868. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  869. $downloaded = "0";
  870. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  871. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  872. }
  873. foreach($array['data']['soon'] AS $child) {
  874. $i++;
  875. $seriesName = $child['show_name'];
  876. $episodeID = $child['tvdbid'];
  877. $episodeAirDate = $child['airdate'];
  878. $episodeAirDateTime = explode(" ",$child['airs']);
  879. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  880. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  881. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  882. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  883. $downloaded = "0";
  884. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  885. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  886. }
  887. foreach($array['data']['later'] AS $child) {
  888. $i++;
  889. $seriesName = $child['show_name'];
  890. $episodeID = $child['tvdbid'];
  891. $episodeAirDate = $child['airdate'];
  892. $episodeAirDateTime = explode(" ",$child['airs']);
  893. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  894. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  895. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  896. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  897. $downloaded = "0";
  898. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  899. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  900. }
  901. if ($i != 0){ return $gotCalendar; }
  902. }
  903. function getSickrageCalendarHistory($array){
  904. $array = json_decode($array, true);
  905. $gotCalendar = "";
  906. $i = 0;
  907. foreach($array['data'] AS $child) {
  908. $i++;
  909. $seriesName = $child['show_name'];
  910. $episodeID = $child['tvdbid'];
  911. $episodeAirDate = $child['date'];
  912. $downloaded = "green-bg";
  913. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  914. }
  915. if ($i != 0){ return $gotCalendar; }
  916. }
  917. function getSonarrCalendar($array){
  918. $array = json_decode($array, true);
  919. $gotCalendar = "";
  920. $i = 0;
  921. foreach($array AS $child) {
  922. $i++;
  923. $seriesName = $child['series']['title'];
  924. $episodeID = $child['series']['tvdbId'];
  925. if(!isset($episodeID)){ $episodeID = ""; }
  926. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  927. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  928. $episodeAirDate = $child['airDateUtc'];
  929. $episodeAirDate = strtotime($episodeAirDate);
  930. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  931. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  932. $downloaded = $child['hasFile'];
  933. 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"; }
  934. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  935. }
  936. if ($i != 0){ return $gotCalendar; }
  937. }
  938. function getRadarrCalendar($array){
  939. $array = json_decode($array, true);
  940. $gotCalendar = "";
  941. $i = 0;
  942. foreach($array AS $child) {
  943. if(isset($child['inCinemas'])){
  944. $i++;
  945. $movieName = $child['title'];
  946. $movieID = $child['tmdbId'];
  947. if(!isset($movieID)){ $movieID = ""; }
  948. if(isset($child['inCinemas']) && isset($child['physicalRelease'])){
  949. $physicalRelease = $child['physicalRelease'];
  950. $physicalRelease = strtotime($physicalRelease);
  951. $physicalRelease = date("Y-m-d", $physicalRelease);
  952. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  953. $downloaded = $child['hasFile'];
  954. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  955. }else{
  956. $physicalRelease = $child['inCinemas'];
  957. $downloaded = "light-blue-bg";
  958. }
  959. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\", url: \"https://www.themoviedb.org/movie/$movieID\" }, \n";
  960. }
  961. }
  962. if ($i != 0){ return $gotCalendar; }
  963. }
  964. function nzbgetConnect($url, $port, $username, $password, $list){
  965. $urlCheck = stripos($url, "http");
  966. if ($urlCheck === false) {
  967. $url = "http://" . $url;
  968. }
  969. if($port !== ""){ $url = $url . ":" . $port; }
  970. $address = $url;
  971. $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
  972. $api = json_decode($api, true);
  973. $i = 0;
  974. $gotNZB = "";
  975. foreach ($api['result'] AS $child) {
  976. $i++;
  977. //echo '<pre>' . var_export($child, true) . '</pre>';
  978. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  979. $downloadStatus = $child['Status'];
  980. $downloadCategory = $child['Category'];
  981. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  982. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  983. if($child['Health'] <= "750"){
  984. $downloadHealth = "danger";
  985. }elseif($child['Health'] <= "900"){
  986. $downloadHealth = "warning";
  987. }elseif($child['Health'] <= "1000"){
  988. $downloadHealth = "success";
  989. }
  990. $gotNZB .= '<tr>
  991. <td>'.$downloadName.'</td>
  992. <td>'.$downloadStatus.'</td>
  993. <td>'.$downloadCategory.'</td>
  994. <td>
  995. <div class="progress">
  996. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  997. <p class="text-center">'.round($downloadPercent).'%</p>
  998. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  999. </div>
  1000. </div>
  1001. </td>
  1002. </tr>';
  1003. }
  1004. if($i > 0){ return $gotNZB; }
  1005. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  1006. }
  1007. function sabnzbdConnect($url, $port, $key, $list){
  1008. $urlCheck = stripos($url, "http");
  1009. if ($urlCheck === false) {
  1010. $url = "http://" . $url;
  1011. }
  1012. if($port !== ""){ $url = $url . ":" . $port; }
  1013. $address = $url;
  1014. $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
  1015. $api = json_decode($api, true);
  1016. $i = 0;
  1017. $gotNZB = "";
  1018. foreach ($api[$list]['slots'] AS $child) {
  1019. $i++;
  1020. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  1021. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  1022. $downloadStatus = $child['status'];
  1023. $gotNZB .= '<tr>
  1024. <td>'.$downloadName.'</td>
  1025. <td>'.$downloadStatus.'</td>
  1026. <td>'.$downloadCategory.'</td>
  1027. <td>
  1028. <div class="progress">
  1029. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  1030. <p class="text-center">'.round($downloadPercent).'%</p>
  1031. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  1032. </div>
  1033. </div>
  1034. </td>
  1035. </tr>';
  1036. }
  1037. if($i > 0){ return $gotNZB; }
  1038. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  1039. }
  1040. function getHeadphonesCalendar($url, $port, $key, $list){
  1041. $urlCheck = stripos($url, "http");
  1042. if ($urlCheck === false) {
  1043. $url = "http://" . $url;
  1044. }
  1045. if($port !== ""){ $url = $url . ":" . $port; }
  1046. $address = $url;
  1047. $api = file_get_contents($address."/api?apikey=".$key."&cmd=$list");
  1048. $api = json_decode($api, true);
  1049. $i = 0;
  1050. $gotCalendar = "";
  1051. foreach($api AS $child) {
  1052. if($child['Status'] == "Wanted"){
  1053. $i++;
  1054. $albumName = addslashes($child['AlbumTitle']);
  1055. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  1056. $albumDate = $child['ReleaseDate'];
  1057. $albumID = $child['AlbumID'];
  1058. $albumDate = strtotime($albumDate);
  1059. $albumDate = date("Y-m-d", $albumDate);
  1060. $albumStatus = $child['Status'];
  1061. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  1062. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  1063. $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  1064. }
  1065. }
  1066. if ($i != 0){ return $gotCalendar; }
  1067. }
  1068. ?>