functions.php 45 KB

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