functions.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.33');
  5. // ===================================
  6. // Debugging output functions
  7. function debug_out($variable, $die = false) {
  8. $trace = debug_backtrace()[0];
  9. 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>';
  10. if ($die) { http_response_code(503); die(); }
  11. }
  12. // ==== Auth Plugins START ====
  13. if (function_exists('ldap_connect')) :
  14. // Pass credentials to LDAP backend
  15. function plugin_auth_ldap($username, $password) {
  16. $ldapServers = explode(',',AUTHBACKENDHOST);
  17. foreach($ldapServers as $key => $value) {
  18. // Calculate parts
  19. $digest = parse_url(trim($value));
  20. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  21. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  22. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  23. // Reassign
  24. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  25. }
  26. // returns true or false
  27. $ldap = ldap_connect(implode(' ',$ldapServers));
  28. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  29. return true;
  30. } else {
  31. return false;
  32. }
  33. return false;
  34. }
  35. else :
  36. // Ldap Auth Missing Dependancy
  37. function plugin_auth_ldap_disabled() {
  38. return 'Plex - Disabled (Dependancy: php-ldap missing!)';
  39. }
  40. endif;
  41. // Pass credentials to FTP backend
  42. function plugin_auth_ftp($username, $password) {
  43. // Calculate parts
  44. $digest = parse_url(AUTHBACKENDHOST);
  45. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  46. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  47. $port = (isset($digest['port'])?$digest['port']:21);
  48. // Determine Connection Type
  49. if ($scheme == 'ftps') {
  50. $conn_id = ftp_ssl_connect($host, $port, 20);
  51. } elseif ($scheme == 'ftp') {
  52. $conn_id = ftp_connect($host, $port, 20);
  53. } else {
  54. debug_out('Invalid FTP scheme. Use ftp or ftps');
  55. return false;
  56. }
  57. // Check if valid FTP connection
  58. if ($conn_id) {
  59. // Attempt login
  60. @$login_result = ftp_login($conn_id, $username, $password);
  61. ftp_close($conn_id);
  62. // Return Result
  63. if ($login_result) {
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. } else {
  69. return false;
  70. }
  71. return false;
  72. }
  73. // Pass credentials to Emby Backend
  74. function plugin_auth_emby_local($username, $password) {
  75. $embyAddress = qualifyURL(AUTHBACKENDHOST);
  76. $headers = array(
  77. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  78. 'Content-Type' => 'application/json',
  79. );
  80. $body = array(
  81. 'Username' => $username,
  82. 'Password' => sha1($password),
  83. 'PasswordMd5' => md5($password),
  84. );
  85. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  86. if (isset($response['content'])) {
  87. $json = json_decode($response['content'], true);
  88. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  89. // Login Success - Now Logout Emby Session As We No Longer Need It
  90. $headers = array(
  91. 'X-Mediabrowser-Token' => $json['AccessToken'],
  92. );
  93. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  94. return true;
  95. }
  96. }
  97. return false;
  98. }
  99. if (function_exists('curl_version')) :
  100. // Authenticate Against Emby Local (first) and Emby Connect
  101. function plugin_auth_emby_all($username, $password) {
  102. $localResult = plugin_auth_emby_local($username, $password);
  103. if ($localResult) {
  104. return $localResult;
  105. } else {
  106. return plugin_auth_emby_connect($username, $password);
  107. }
  108. }
  109. // Authenicate against emby connect
  110. function plugin_auth_emby_connect($username, $password) {
  111. $embyAddress = qualifyURL(AUTHBACKENDHOST);
  112. // Get A User
  113. $connectId = '';
  114. $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  115. if (is_array($userIds)) {
  116. foreach ($userIds as $key => $value) { // Scan for this user
  117. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  118. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  119. $connectId = $value['ConnectUserId'];
  120. break;
  121. }
  122. }
  123. }
  124. if ($connectId) {
  125. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  126. $headers = array(
  127. 'Accept'=> 'application/json',
  128. 'Content-Type' => 'application/x-www-form-urlencoded',
  129. );
  130. $body = array(
  131. 'nameOrEmail' => $username,
  132. 'rawpw' => $password,
  133. );
  134. $result = curl_post($connectURL, $body, $headers);
  135. if (isset($result['content'])) {
  136. $json = json_decode($result['content'], true);
  137. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  138. return array(
  139. 'email' => $json['User']['Email'],
  140. 'image' => $json['User']['ImageUrl'],
  141. );
  142. }
  143. }
  144. }
  145. }
  146. return false;
  147. }
  148. // Pass credentials to Plex Backend
  149. function plugin_auth_plex($username, $password) {
  150. // Quick out
  151. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  152. return true;
  153. }
  154. //Get User List
  155. $userURL = 'https://plex.tv/pms/friends/all';
  156. $userHeaders = array(
  157. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  158. );
  159. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  160. if (is_array($userXML) || is_object($userXML)) {
  161. $isUser = false;
  162. $usernameLower = strtolower($username);
  163. foreach($userXML AS $child) {
  164. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  165. $isUser = true;
  166. break;
  167. }
  168. }
  169. if ($isUser) {
  170. //Login User
  171. $connectURL = 'https://plex.tv/users/sign_in.json';
  172. $headers = array(
  173. 'Accept'=> 'application/json',
  174. 'Content-Type' => 'application/x-www-form-urlencoded',
  175. 'X-Plex-Product' => 'Organizr',
  176. 'X-Plex-Version' => '1.0',
  177. 'X-Plex-Client-Identifier' => '01010101-10101010',
  178. );
  179. $body = array(
  180. 'user[login]' => $username,
  181. 'user[password]' => $password,
  182. );
  183. $result = curl_post($connectURL, $body, $headers);
  184. if (isset($result['content'])) {
  185. $json = json_decode($result['content'], true);
  186. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  187. return array(
  188. 'email' => $json['user']['email'],
  189. 'image' => $json['user']['thumb']
  190. );
  191. }
  192. }
  193. }
  194. }
  195. return false;
  196. }
  197. else :
  198. // Plex Auth Missing Dependancy
  199. function plugin_auth_plex_disabled() {
  200. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  201. }
  202. // Emby Connect Auth Missing Dependancy
  203. function plugin_auth_emby_connect_disabled() {
  204. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  205. }
  206. // Emby Both Auth Missing Dependancy
  207. function plugin_auth_emby_both_disabled() {
  208. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  209. }
  210. endif;
  211. // ==== Auth Plugins END ====
  212. // ==== General Class Definitions START ====
  213. class setLanguage {
  214. private $language = null;
  215. private $langCode = null;
  216. function __construct($language = false) {
  217. // Default
  218. if (!$language) {
  219. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  220. }
  221. $this->langCode = $language;
  222. if (file_exists("lang/{$language}.ini")) {
  223. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  224. } else {
  225. $this->language = parse_ini_file("lang/en.ini", false, INI_SCANNER_RAW);
  226. }
  227. }
  228. public function getLang() {
  229. return $this->langCode;
  230. }
  231. public function translate($originalWord) {
  232. $getArg = func_num_args();
  233. if ($getArg > 1) {
  234. $allWords = func_get_args();
  235. array_shift($allWords);
  236. } else {
  237. $allWords = array();
  238. }
  239. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  240. if (!$translatedWord) {
  241. echo ("Translation not found for: $originalWord");
  242. }
  243. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  244. return vsprintf($translatedWord, $allWords);
  245. }
  246. }
  247. $language = new setLanguage;
  248. // ==== General Class Definitions END ====
  249. // Direct request to curl if it exists, otherwise handle if not HTTPS
  250. function post_router($url, $data, $headers = array(), $referer='') {
  251. if (function_exists('curl_version')) {
  252. return curl_post($url, $data, $headers, $referer);
  253. } else {
  254. return post_request($url, $data, $headers, $referer);
  255. }
  256. }
  257. if (function_exists('curl_version')) :
  258. // Curl Post
  259. function curl_post($url, $data, $headers = array(), $referer='') {
  260. // Initiate cURL
  261. $curlReq = curl_init($url);
  262. // As post request
  263. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  264. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  265. // Format Data
  266. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  267. case 'application/json':
  268. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  269. break;
  270. case 'application/x-www-form-urlencoded';
  271. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  272. break;
  273. default:
  274. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  275. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  276. }
  277. // Format Headers
  278. $cHeaders = array();
  279. foreach ($headers as $k => $v) {
  280. $cHeaders[] = $k.': '.$v;
  281. }
  282. if (count($cHeaders)) {
  283. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  284. }
  285. // Execute
  286. $result = curl_exec($curlReq);
  287. // Close
  288. curl_close($curlReq);
  289. // Return
  290. return array('content'=>$result);
  291. }
  292. //Curl Get Function
  293. function curl_get($url, $headers = array()) {
  294. // Initiate cURL
  295. $curlReq = curl_init($url);
  296. // As post request
  297. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  298. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  299. // Format Headers
  300. $cHeaders = array();
  301. foreach ($headers as $k => $v) {
  302. $cHeaders[] = $k.': '.$v;
  303. }
  304. if (count($cHeaders)) {
  305. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  306. }
  307. // Execute
  308. $result = curl_exec($curlReq);
  309. // Close
  310. curl_close($curlReq);
  311. // Return
  312. return $result;
  313. }
  314. endif;
  315. //Case-Insensitive Function
  316. function in_arrayi($needle, $haystack) {
  317. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  318. }
  319. // HTTP post request (Removes need for curl, probably useless)
  320. function post_request($url, $data, $headers = array(), $referer='') {
  321. // Adapted from http://stackoverflow.com/a/28387011/6810513
  322. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  323. if (isset($headers['Content-Type'])) {
  324. switch ($headers['Content-Type']) {
  325. case 'application/json':
  326. $data = json_encode($data);
  327. break;
  328. case 'application/x-www-form-urlencoded':
  329. $data = http_build_query($data);
  330. break;
  331. }
  332. } else {
  333. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  334. $data = http_build_query($data);
  335. }
  336. // parse the given URL
  337. $urlDigest = parse_url($url);
  338. // extract host and path:
  339. $host = $urlDigest['host'].(isset($urlDigest['port'])?':'.$urlDigest['port']:'');
  340. $path = $urlDigest['path'];
  341. if ($urlDigest['scheme'] != 'http') {
  342. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  343. }
  344. // open a socket connection on port 80 - timeout: 30 sec
  345. $fp = fsockopen($host, 80, $errno, $errstr, 30);
  346. if ($fp){
  347. // send the request headers:
  348. fputs($fp, "POST $path HTTP/1.1\r\n");
  349. fputs($fp, "Host: $host\r\n");
  350. if ($referer != '')
  351. fputs($fp, "Referer: $referer\r\n");
  352. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  353. foreach($headers as $k => $v) {
  354. fputs($fp, $k.": ".$v."\r\n");
  355. }
  356. fputs($fp, "Connection: close\r\n\r\n");
  357. fputs($fp, $data);
  358. $result = '';
  359. while(!feof($fp)) {
  360. // receive the results of the request
  361. $result .= fgets($fp, 128);
  362. }
  363. }
  364. else {
  365. return array(
  366. 'status' => 'err',
  367. 'error' => "$errstr ($errno)"
  368. );
  369. }
  370. // close the socket connection:
  371. fclose($fp);
  372. // split the result header from the content
  373. $result = explode("\r\n\r\n", $result, 2);
  374. $header = isset($result[0]) ? $result[0] : '';
  375. $content = isset($result[1]) ? $result[1] : '';
  376. // return as structured array:
  377. return array(
  378. 'status' => 'ok',
  379. 'header' => $header,
  380. 'content' => $content,
  381. );
  382. }
  383. // Format item from Emby for Carousel
  384. function resolveEmbyItem($address, $token, $item) {
  385. // Static Height
  386. $height = 150;
  387. // Get Item Details
  388. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0];
  389. switch ($itemDetails['Type']) {
  390. case 'Episode':
  391. $title = $itemDetails['SeriesName'].': '.$itemDetails['Name'].' (Season '.$itemDetails['ParentIndexNumber'].': Episode '.$itemDetails['IndexNumber'].')';
  392. $imageId = $itemDetails['SeriesId'];
  393. $width = 100;
  394. $image = 'carousel-image season';
  395. $style = '';
  396. break;
  397. case 'MusicAlbum':
  398. $title = $itemDetails['Name'];
  399. $imageId = $itemDetails['Id'];
  400. $width = 150;
  401. $image = 'music';
  402. $style = 'left: 160px !important;';
  403. break;
  404. default:
  405. $title = $itemDetails['Name'];
  406. $imageId = $itemDetails['Id'];
  407. $width = 100;
  408. $image = 'carousel-image movie';
  409. $style = '';
  410. }
  411. // If No Overview
  412. if (!isset($itemDetails['Overview'])) {
  413. $itemDetails['Overview'] = '';
  414. }
  415. // Assemble Item And Cache Into Array
  416. return '<div class="item"><a href="'.$address.'/web/itemdetails.html?id='.$itemDetails['Id'].'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" src="ajax.php?a=emby-image&img='.$imageId.'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption" style="'.$style.'"><h4>'.$title.'</h4><small><em>'.$itemDetails['Overview'].'</em></small></div></div>';
  417. }
  418. // Format item from Plex for Carousel
  419. function resolvePlexItem($server, $token, $item) {
  420. // Static Height
  421. $height = 150;
  422. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  423. switch ($item['type']) {
  424. case 'season':
  425. $title = $item['parentTitle'];
  426. $summary = $item['parentSummary'];
  427. $width = 100;
  428. $image = 'carousel-image season';
  429. $style = '';
  430. break;
  431. case 'album':
  432. $title = $item['parentTitle'];
  433. $summary = $item['title'];
  434. $width = 150;
  435. $image = 'album';
  436. $style = 'left: 160px !important;';
  437. break;
  438. default:
  439. $title = $item['title'];
  440. $summary = $item['summary'];
  441. $width = 100;
  442. $image = 'carousel-image movie';
  443. $style = '';
  444. }
  445. // If No Overview
  446. if (!isset($itemDetails['Overview'])) {
  447. $itemDetails['Overview'] = '';
  448. }
  449. // Assemble Item And Cache Into Array
  450. return '<div class="item"><a href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" src="ajax.php?a=plex-image&img='.$item['thumb'].'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption" style="'.$style.'"><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  451. }
  452. // Create Carousel
  453. function outputCarousel($header, $size, $type, $items, $script = false) {
  454. // If None Populate Empty Item
  455. if (!count($items)) {
  456. $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>');
  457. }
  458. // Set First As Active
  459. $items[0] = preg_replace('/^<div class="item ?">/','<div class="item active">', $items[0]);
  460. // Add Buttons
  461. $buttons = '';
  462. if (count($items) > 1) {
  463. $buttons = '
  464. <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>
  465. <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>';
  466. }
  467. return '
  468. <div class="col-lg-'.$size.'">
  469. <h5 class="text-center">'.$header.'</h5>
  470. <div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">
  471. '.implode('',$items).'
  472. </div>'.$buttons.'
  473. </div></div>'.($script?'<script>'.$script.'</script>':'');
  474. }
  475. // Get Now Playing Streams From Emby
  476. function getEmbyStreams($size) {
  477. $address = qualifyURL(EMBYURL);
  478. $api = json_decode(file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  479. $playingItems = array();
  480. foreach($api as $key => $value) {
  481. if (isset($value['NowPlayingItem'])) {
  482. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem']);
  483. }
  484. }
  485. return outputCarousel(translate('PLAYING_NOW_ON_EMBY'), $size, 'streams-emby', $playingItems, "
  486. setInterval(function() {
  487. $('<div></div>').load('ajax.php?a=emby-streams',function() {
  488. var element = $(this).find('[id]');
  489. var loadedID = element.attr('id');
  490. $('#'+loadedID).replaceWith(element);
  491. console.log('Loaded updated: '+loadedID);
  492. });
  493. }, 10000);
  494. ");
  495. }
  496. // Get Now Playing Streams From Plex
  497. function getPlexStreams($size){
  498. $address = qualifyURL(PLEXURL);
  499. // Perform API requests
  500. $api = file_get_contents($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  501. $api = simplexml_load_string($api);
  502. $getServer = simplexml_load_string(file_get_contents($address."/?X-Plex-Token=".PLEXTOKEN));
  503. // Identify the local machine
  504. $gotServer = $getServer['machineIdentifier'];
  505. $items = array();
  506. foreach($api AS $child) {
  507. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child);
  508. }
  509. return outputCarousel(translate('PLAYING_NOW_ON_PLEX'), $size, 'streams-plex', $items, "
  510. setInterval(function() {
  511. $('<div></div>').load('ajax.php?a=plex-streams',function() {
  512. var element = $(this).find('[id]');
  513. var loadedID = element.attr('id');
  514. $('#'+loadedID).replaceWith(element);
  515. console.log('Loaded updated: '+loadedID);
  516. });
  517. }, 10000);
  518. ");
  519. }
  520. // Get Recent Content From Emby
  521. function getEmbyRecent($type, $size) {
  522. $address = qualifyURL(EMBYURL);
  523. // Resolve Types
  524. switch ($type) {
  525. case 'movie':
  526. $embyTypeQuery = 'IncludeItemTypes=Movie&';
  527. $header = translate('MOVIES');
  528. break;
  529. case 'season':
  530. $embyTypeQuery = 'IncludeItemTypes=Episode&';
  531. $header = translate('TV_SHOWS');
  532. break;
  533. case 'album':
  534. $embyTypeQuery = 'IncludeItemTypes=MusicAlbum&';
  535. $header = translate('MUSIC');
  536. break;
  537. default:
  538. $embyTypeQuery = '';
  539. $header = translate('RECENT_CONTENT');
  540. }
  541. // Get A User
  542. $userIds = json_decode(file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  543. foreach ($userIds as $value) { // Scan for admin user
  544. $userId = $value['Id'];
  545. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  546. break;
  547. }
  548. }
  549. // Get the latest Items
  550. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.EMBYTOKEN),true);
  551. // For Each Item In Category
  552. $items = array();
  553. foreach ($latest as $k => $v) {
  554. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v);
  555. }
  556. return outputCarousel($header, $size, $type.'-emby', $items);
  557. }
  558. // Get Recent Content From Plex
  559. function getPlexRecent($type, $size){
  560. $address = qualifyURL(PLEXURL);
  561. // Resolve Types
  562. switch ($type) {
  563. case 'movie':
  564. $header = translate('MOVIES');
  565. break;
  566. case 'season':
  567. $header = translate('TV_SHOWS');
  568. break;
  569. case 'album':
  570. $header = translate('MUSIC');
  571. break;
  572. default:
  573. $header = translate('RECENT_CONTENT');
  574. }
  575. // Perform Requests
  576. $api = file_get_contents($address."/library/recentlyAdded?X-Plex-Token=".PLEXTOKEN);
  577. $api = simplexml_load_string($api);
  578. $getServer = simplexml_load_string(file_get_contents($address."/?X-Plex-Token=".PLEXTOKEN));
  579. // Identify the local machine
  580. $gotServer = $getServer['machineIdentifier'];
  581. $items = array();
  582. foreach($api AS $child) {
  583. if($child['type'] == $type){
  584. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child);
  585. }
  586. }
  587. return outputCarousel($header, $size, $type.'-plex', $items);
  588. }
  589. // Get Image From Emby
  590. function getEmbyImage() {
  591. $embyAddress = qualifyURL(EMBYURL);
  592. $itemId = $_GET['img'];
  593. $imgParams = array();
  594. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  595. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  596. if(isset($itemId)) {
  597. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/Primary?'.implode('&', $imgParams);
  598. header('Content-type: image/jpeg');
  599. readfile($image_src);
  600. } else {
  601. debug_out('Invalid Request',1);
  602. }
  603. }
  604. // Get Image From Plex
  605. function getPlexImage() {
  606. $plexAddress = qualifyURL(PLEXURL);
  607. $image_url = $_GET['img'];
  608. $image_height = $_GET['height'];
  609. $image_width = $_GET['width'];
  610. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  611. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  612. header('Content-type: image/jpeg');
  613. readfile($image_src);
  614. } else {
  615. echo "Invalid Plex Request";
  616. }
  617. }
  618. // Simplier access to class
  619. function translate($string) {
  620. if (isset($GLOBALS['language'])) {
  621. return $GLOBALS['language']->translate($string);
  622. } else {
  623. return '!Translations Not Loaded!';
  624. }
  625. }
  626. // Generate Random string
  627. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  628. $tmp = '';
  629. for ($i = 0; $i < $length; $i++) {
  630. $tmp .= substr(str_shuffle($chars), 0, 1);
  631. }
  632. return $tmp;
  633. }
  634. // Create config file in the return syntax
  635. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  636. // Define Initial Value
  637. $output = array();
  638. // Sort Items
  639. ksort($array);
  640. // Unset the current version
  641. unset($array['CONFIG_VERSION']);
  642. // Process Settings
  643. foreach ($array as $k => $v) {
  644. $allowCommit = true;
  645. switch (gettype($v)) {
  646. case 'boolean':
  647. $item = ($v?'true':'false');
  648. break;
  649. case 'integer':
  650. case 'double':
  651. case 'integer':
  652. case 'NULL':
  653. $item = $v;
  654. break;
  655. case 'string':
  656. $item = '"'.addslashes($v).'"';
  657. break;
  658. case 'array':
  659. $item = createConfig($v, false, $nest+1);
  660. break;
  661. default:
  662. $allowCommit = false;
  663. }
  664. if($allowCommit) {
  665. $output[] = str_repeat("\t",$nest+1).'"'.$k.'" => '.$item;
  666. }
  667. }
  668. if (!$nest) {
  669. // Inject Current Version
  670. $output[] = "\t".'"CONFIG_VERSION" => "'.INSTALLEDVERSION.'"';
  671. }
  672. // Build output
  673. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  674. if (!$nest && $path) {
  675. $pathDigest = pathinfo($path);
  676. @mkdir($pathDigest['dirname'], 0770, true);
  677. if (file_exists($path)) {
  678. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  679. }
  680. $file = fopen($path, 'w');
  681. fwrite($file, $output);
  682. fclose($file);
  683. if (file_exists($path)) {
  684. return true;
  685. }
  686. return false;
  687. } else {
  688. return $output;
  689. }
  690. }
  691. // Load a config file written in the return syntax
  692. function loadConfig($path = 'config/config.php') {
  693. // Adapted from http://stackoverflow.com/a/14173339/6810513
  694. if (!is_file($path)) {
  695. return null;
  696. } else {
  697. return (array) call_user_func(function() use($path) {
  698. return include($path);
  699. });
  700. }
  701. }
  702. // Commit new values to the configuration
  703. function updateConfig($new, $current = false) {
  704. // Get config if not supplied
  705. if (!$current) {
  706. $current = loadConfig();
  707. }
  708. // Inject Parts
  709. foreach ($new as $k => $v) {
  710. $current[$k] = $v;
  711. }
  712. // Return Create
  713. return createConfig($current);
  714. }
  715. // Inject Defaults As Needed
  716. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  717. if (is_string($path)) {
  718. $loadedDefaults = loadConfig($path);
  719. } else {
  720. $loadedDefaults = $path;
  721. }
  722. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  723. }
  724. // support function for fillDefaultConfig()
  725. function fillDefaultConfig_recurse($current, $defaults) {
  726. foreach($defaults as $k => $v) {
  727. if (!isset($current[$k])) {
  728. $current[$k] = $v;
  729. } else if (is_array($current[$k]) && is_array($v)) {
  730. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  731. }
  732. }
  733. return $current;
  734. };
  735. // Define Scalar Variables (nest non-secular with underscores)
  736. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  737. foreach($array as $k => $v) {
  738. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  739. define($nest_prefix.$k, $v, $anyCase);
  740. } else if (is_array($v)) {
  741. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  742. }
  743. }
  744. }
  745. // This function exists only because I am lazy
  746. function configLazy($path = null) {
  747. $config = fillDefaultConfig(loadConfig($path));
  748. if (is_array($config)) {
  749. defineConfig($config);
  750. }
  751. return $config;
  752. }
  753. // Qualify URL
  754. function qualifyURL($url) {
  755. // Get Digest
  756. $digest = parse_url($url);
  757. // http/https
  758. if (!isset($digest['scheme'])) {
  759. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  760. $scheme = 'http';
  761. } else {
  762. $scheme = 'https';
  763. }
  764. } else {
  765. $scheme = $digest['scheme'];
  766. }
  767. // Host
  768. $host = (isset($digest['host'])?$digest['host']:'');
  769. // Port
  770. $port = (isset($digest['port'])?':'.$digest['port']:'');
  771. // Path
  772. $path = (isset($digest['path'])?$digest['path']:'');
  773. // Output
  774. return $scheme.'://'.$host.$port.$path;
  775. }
  776. // Function to be called at top of each to allow upgrading environment as the spec changes
  777. function upgradeCheck() {
  778. // Upgrade to 1.31
  779. if (file_exists('homepageSettings.ini.php')) {
  780. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  781. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  782. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  783. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  784. foreach($databaseConfig as $k => $v) {
  785. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  786. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  787. }
  788. write_ini_file($databaseData, 'databaseLocation.ini.php');
  789. unlink('homepageSettings.ini.php');
  790. unset($databaseData);
  791. unset($homepageConfig);
  792. }
  793. // Upgrade to 1.32
  794. if (file_exists('databaseLocation.ini.php')) {
  795. // Load Existing
  796. $config = parse_ini_file('databaseLocation.ini.php', true);
  797. // Refactor
  798. $config['database_Location'] = str_replace('//','/',$config['databaseLocation'].'/');
  799. $config['user_home'] = $config['database_Location'].'users/';
  800. unset($config['databaseLocation']);
  801. // Turn Off Emby And Plex Recent
  802. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  803. unset($config["embyPort"]);
  804. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  805. unset($config["plexPort"]);
  806. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  807. unset($config["nzbgetPort"]);
  808. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  809. unset($config["sabnzbdPort"]);
  810. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  811. unset($config["headphonesPort"]);
  812. $createConfigSuccess = createConfig($config);
  813. // Create new config
  814. if ($createConfigSuccess) {
  815. // Make Config Dir (this should never happen as the dir and defaults file should be there);
  816. @mkdir('config', 0775, true);
  817. // Remove Old ini file
  818. unlink('databaseLocation.ini.php');
  819. } else {
  820. debug_out('Couldn\'t create updated configuration.' ,1);
  821. }
  822. }
  823. // Upgrade to 1.33
  824. $config = loadConfig();
  825. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  826. // Fix User Directory
  827. $config['user_home'] = $config['database_Location'].'users/';
  828. unset($config['USER_HOME']);
  829. // Backend auth merge
  830. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  831. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  832. }
  833. unset($config['authBackendPort']);
  834. // Update Version and Commit
  835. $config['CONFIG_VERSION'] = '1.33';
  836. $createConfigSuccess = createConfig($config);
  837. }
  838. unset($config);
  839. return true;
  840. }
  841. // Check if all software dependancies are met
  842. function dependCheck() {
  843. return true;
  844. }
  845. // Process file uploads
  846. function uploadFiles($path, $ext_mask = null) {
  847. if (isset($_FILES) && count($_FILES)) {
  848. require_once('class.uploader.php');
  849. $uploader = new Uploader();
  850. $data = $uploader->upload($_FILES['files'], array(
  851. 'limit' => 10,
  852. 'maxSize' => 10,
  853. 'extensions' => $ext_mask,
  854. 'required' => false,
  855. 'uploadDir' => str_replace('//','/',$path.'/'),
  856. 'title' => array('name'),
  857. 'removeFiles' => true,
  858. 'replace' => true,
  859. ));
  860. if($data['isComplete']){
  861. $files = $data['data'];
  862. echo json_encode($files['metas'][0]['name']);
  863. }
  864. if($data['hasErrors']){
  865. $errors = $data['errors'];
  866. echo json_encode($errors);
  867. }
  868. } else {
  869. echo json_encode('No files submitted!');
  870. }
  871. }
  872. // Remove file
  873. function removeFiles($path) {
  874. if(is_file($path)) {
  875. unlink($path);
  876. } else {
  877. echo json_encode('No file specified for removal!');
  878. }
  879. }
  880. // Lazy select options
  881. function resolveSelectOptions($array, $selected = '') {
  882. $output = array();
  883. foreach ($array as $key => $value) {
  884. if (is_array($value)) {
  885. if (isset($value['optgroup'])) {
  886. $output[] = '<optgroup label="'.$key.'">';
  887. foreach($value['optgroup'] as $k => $v) {
  888. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  889. }
  890. } else {
  891. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  892. }
  893. } else {
  894. $output[] = '<option value="'.$value.'"'.($selected===$value?' selected':'').'>'.$key.'</option>';
  895. }
  896. }
  897. return implode('',$output);
  898. }
  899. // Check if user is allowed to continue
  900. function qualifyUser($type, $errOnFail = false) {
  901. if (!isset($GLOBALS['USER'])) {
  902. require_once("user.php");
  903. $GLOBALS['USER'] = new User('registration_callback');
  904. }
  905. if (is_bool($type)) {
  906. if ($type === true) {
  907. $authorized = ($GLOBALS['USER']->authenticated == true);
  908. } else {
  909. $authorized = true;
  910. }
  911. } elseif (is_string($type)) {
  912. if ($type !== 'false') {
  913. $type = explode('|',$type);
  914. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  915. } else {
  916. $authorized = true;
  917. }
  918. } else {
  919. debug_out('Invalid Syntax!',1);
  920. }
  921. if (!$authorized && $errOnFail) {
  922. header('Location: error.php?error=401');
  923. echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'/error.php?error=401\'</script>';
  924. debug_out('Not Authorized' ,1);
  925. } else {
  926. return $authorized;
  927. }
  928. }
  929. // Build an (optionally) tabbed settings page.
  930. function buildSettings($array) {
  931. /*
  932. array(
  933. 'title' => '',
  934. 'id' => '',
  935. 'fields' => array( See buildField() ),
  936. 'tabs' => array(
  937. array(
  938. 'title' => '',
  939. 'id' => '',
  940. 'image' => '',
  941. 'fields' => array( See buildField() ),
  942. ),
  943. ),
  944. );
  945. */
  946. $fieldFunc = function($fieldArr) {
  947. $fields = '<div class="row">';
  948. foreach($fieldArr as $key => $value) {
  949. $isSingle = isset($value['type']);
  950. if ($isSingle) { $value = array($value); }
  951. $tmpField = '';
  952. foreach($value as $k => $v) {
  953. $tmpField .= '<div class="form-group">'.buildField($v).'</div>';
  954. }
  955. $fields .= ($isSingle?$tmpField:'<div class="content-form form-inline">'.$tmpField.'</div>');
  956. }
  957. $fields .= '</div>';
  958. return $fields;
  959. };
  960. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  961. $tabSelectors = array();
  962. $tabContent = array();
  963. if (isset($array['tabs'])) {
  964. foreach($array['tabs'] as $key => $value) {
  965. $id = (isset($value['id'])?$value['id']:randString(32));
  966. $tabSelectors[$key] = '<li class="apps'.($tabSelectors?'':' active').'"><a href="#tab-'.$id.'" data-toggle="tab" aria-expanded="true"><img style="height:40px; width:40px;" src="'.(isset($value['image'])?$value['image']:'images/organizr.png').'"></a></li>';
  967. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  968. }
  969. }
  970. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  971. return '
  972. <div class="email-body">
  973. <div class="email-header gray-bg">
  974. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  975. <h1>'.$array['title'].'</h1>
  976. </div>
  977. <div class="email-inner small-box">
  978. <div class="email-inner-section">
  979. <div class="small-box fade in" id="'.$pageID.'_frame">
  980. <div class="row">
  981. <div class="col-lg-12">
  982. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  983. <div style="position: relative; left: 2.5%; width: 95%;">
  984. '.$fields.'
  985. </div>
  986. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  987. <ul class="nav nav-tabs apps">
  988. '.implode('', $tabSelectors).'
  989. </ul>
  990. <div class="clearfix"></div>
  991. <div class="tab-content">
  992. '.implode('', $tabContent).'
  993. </div>
  994. </div>
  995. <button type="submit" class="btn waves btn-labeled btn-success btn btn-sm pull-right text-uppercase waves-effect waves-float">
  996. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  997. </button>
  998. </form>
  999. </div>
  1000. </div>
  1001. </div>
  1002. </div>
  1003. </div>
  1004. </div>
  1005. <script>
  1006. $(document).ready(function() {
  1007. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() {
  1008. $(this).attr(\'data-changed\', \'true\');
  1009. });
  1010. $(\'#'.$pageID.'_form\').submit(function () {
  1011. var newVals = {};
  1012. $(\'#'.$pageID.'_form\').find(\'[data-changed=true]\').each(function() {
  1013. if (this.type == \'checkbox\') {
  1014. newVals[this.name] = this.checked;
  1015. } else {
  1016. newVals[this.name] = $(this).val();
  1017. }
  1018. });
  1019. $.post(\'ajax.php?a=update-config\', newVals, function(data) {
  1020. console.log(data);
  1021. parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect);
  1022. }, \'json\');
  1023. return false;
  1024. });
  1025. '.(isset($array['onready'])?$array['onready']:'').'
  1026. });
  1027. </script>
  1028. ';
  1029. }
  1030. // Build Settings Fields
  1031. function buildField($params) {
  1032. /*
  1033. array(
  1034. 'type' => '',
  1035. 'placeholder' => '',
  1036. 'label' => '',
  1037. 'labelTranslate' => '',
  1038. 'assist' => '',
  1039. 'name' => '',
  1040. 'pattern' => '',
  1041. 'options' => array( // For SELECT only
  1042. 'Display' => 'value',
  1043. ),
  1044. )
  1045. */
  1046. // Tags
  1047. $tags = array();
  1048. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave') as $value) {
  1049. $tags[] = (isset($params[$value])?$value.'="'.$params[$value].'"':'');
  1050. }
  1051. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1052. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1053. $val = (isset($params['value'])?$params['value']:'');
  1054. $class = (isset($params['class'])?' '.$params['class']:'');
  1055. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1056. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1057. switch ($params['type']) {
  1058. case 'text':
  1059. case 'number':
  1060. case 'password':
  1061. $field = '
  1062. <input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">
  1063. ';
  1064. break;
  1065. case 'select':
  1066. case 'dropdown':
  1067. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>
  1068. '.resolveSelectOptions($params['options'], $val).'
  1069. </select>';
  1070. break;
  1071. case 'check':
  1072. case 'checkbox':
  1073. case 'toggle':
  1074. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1075. return '
  1076. <input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-success'.$class.'" '.implode(' ',$tags).' value="'.$val.'"'.$checked.'><label for="'.$id.'"></label>'.$label.'
  1077. ';
  1078. case 'date':
  1079. $field = '
  1080. ';
  1081. break;
  1082. case 'hidden':
  1083. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1084. case 'header':
  1085. return '<h3 class="'.$class.'" '.implode(' ',$tags).'>'.$val.'</h3>';
  1086. case 'button':
  1087. return '<button id="'.$id.'" type="button" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float'.$class.'"><span class="btn-label"><i class="fa fa-flask" '.implode(' ',$tags).'></i></span>'.$label.'</button>';
  1088. default:
  1089. $field = '';
  1090. }
  1091. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1092. return $field.$labelOut;
  1093. }
  1094. // Timezone array
  1095. function timezoneOptions() {
  1096. $output = array();
  1097. $timezones = array();
  1098. $regions = array(
  1099. 'Africa' => DateTimeZone::AFRICA,
  1100. 'America' => DateTimeZone::AMERICA,
  1101. 'Antarctica' => DateTimeZone::ANTARCTICA,
  1102. 'Arctic' => DateTimeZone::ARCTIC,
  1103. 'Asia' => DateTimeZone::ASIA,
  1104. 'Atlantic' => DateTimeZone::ATLANTIC,
  1105. 'Australia' => DateTimeZone::AUSTRALIA,
  1106. 'Europe' => DateTimeZone::EUROPE,
  1107. 'Indian' => DateTimeZone::INDIAN,
  1108. 'Pacific' => DateTimeZone::PACIFIC
  1109. );
  1110. foreach ($regions as $name => $mask) {
  1111. $zones = DateTimeZone::listIdentifiers($mask);
  1112. foreach($zones as $timezone) {
  1113. $time = new DateTime(NULL, new DateTimeZone($timezone));
  1114. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  1115. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  1116. }
  1117. }
  1118. return $output;
  1119. }
  1120. // ==============
  1121. function clean($strin) {
  1122. $strout = null;
  1123. for ($i = 0; $i < strlen($strin); $i++) {
  1124. $ord = ord($strin[$i]);
  1125. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  1126. $strout .= "&amp;#{$ord};";
  1127. }
  1128. else {
  1129. switch ($strin[$i]) {
  1130. case '<':
  1131. $strout .= '&lt;';
  1132. break;
  1133. case '>':
  1134. $strout .= '&gt;';
  1135. break;
  1136. case '&':
  1137. $strout .= '&amp;';
  1138. break;
  1139. case '"':
  1140. $strout .= '&quot;';
  1141. break;
  1142. default:
  1143. $strout .= $strin[$i];
  1144. }
  1145. }
  1146. }
  1147. return $strout;
  1148. }
  1149. function registration_callback($username, $email, $userdir){
  1150. global $data;
  1151. $data = array($username, $email, $userdir);
  1152. }
  1153. function printArray($arrayName){
  1154. $messageCount = count($arrayName);
  1155. $i = 0;
  1156. foreach ( $arrayName as $item ) :
  1157. $i++;
  1158. if($i < $messageCount) :
  1159. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  1160. elseif($i = $messageCount) :
  1161. echo "<small class='text-uppercase'>" . $item . "</small>";
  1162. endif;
  1163. endforeach;
  1164. }
  1165. function write_ini_file($content, $path) {
  1166. if (!$handle = fopen($path, 'w')) {
  1167. return false;
  1168. }
  1169. $success = fwrite($handle, trim($content));
  1170. fclose($handle);
  1171. return $success;
  1172. }
  1173. function gotTimezone(){
  1174. $regions = array(
  1175. 'Africa' => DateTimeZone::AFRICA,
  1176. 'America' => DateTimeZone::AMERICA,
  1177. 'Antarctica' => DateTimeZone::ANTARCTICA,
  1178. 'Arctic' => DateTimeZone::ARCTIC,
  1179. 'Asia' => DateTimeZone::ASIA,
  1180. 'Atlantic' => DateTimeZone::ATLANTIC,
  1181. 'Australia' => DateTimeZone::AUSTRALIA,
  1182. 'Europe' => DateTimeZone::EUROPE,
  1183. 'Indian' => DateTimeZone::INDIAN,
  1184. 'Pacific' => DateTimeZone::PACIFIC
  1185. );
  1186. $timezones = array();
  1187. foreach ($regions as $name => $mask) {
  1188. $zones = DateTimeZone::listIdentifiers($mask);
  1189. foreach($zones as $timezone) {
  1190. $time = new DateTime(NULL, new DateTimeZone($timezone));
  1191. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  1192. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  1193. }
  1194. }
  1195. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  1196. foreach($timezones as $region => $list) {
  1197. print '<optgroup label="' . $region . '">' . "\n";
  1198. foreach($list as $timezone => $name) {
  1199. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  1200. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  1201. }
  1202. print '</optgroup>' . "\n";
  1203. }
  1204. print '</select>';
  1205. }
  1206. function getTimezone(){
  1207. $regions = array(
  1208. 'Africa' => DateTimeZone::AFRICA,
  1209. 'America' => DateTimeZone::AMERICA,
  1210. 'Antarctica' => DateTimeZone::ANTARCTICA,
  1211. 'Arctic' => DateTimeZone::ARCTIC,
  1212. 'Asia' => DateTimeZone::ASIA,
  1213. 'Atlantic' => DateTimeZone::ATLANTIC,
  1214. 'Australia' => DateTimeZone::AUSTRALIA,
  1215. 'Europe' => DateTimeZone::EUROPE,
  1216. 'Indian' => DateTimeZone::INDIAN,
  1217. 'Pacific' => DateTimeZone::PACIFIC
  1218. );
  1219. $timezones = array();
  1220. foreach ($regions as $name => $mask) {
  1221. $zones = DateTimeZone::listIdentifiers($mask);
  1222. foreach($zones as $timezone) {
  1223. $time = new DateTime(NULL, new DateTimeZone($timezone));
  1224. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  1225. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  1226. }
  1227. }
  1228. print '<select name="timezone" id="timezone" class="form-control material" required>';
  1229. foreach($timezones as $region => $list) {
  1230. print '<optgroup label="' . $region . '">' . "\n";
  1231. foreach($list as $timezone => $name) {
  1232. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  1233. }
  1234. print '</optgroup>' . "\n";
  1235. }
  1236. print '</select>';
  1237. }
  1238. function explosion($string, $position){
  1239. $getWord = explode("|", $string);
  1240. return $getWord[$position];
  1241. }
  1242. function getServerPath() {
  1243. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1244. $protocol = "https://";
  1245. } else {
  1246. $protocol = "http://";
  1247. }
  1248. return $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  1249. }
  1250. function get_browser_name() {
  1251. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  1252. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  1253. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  1254. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  1255. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  1256. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  1257. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  1258. return 'Other';
  1259. }
  1260. function getSickrageCalendarWanted($array){
  1261. $array = json_decode($array, true);
  1262. $gotCalendar = "";
  1263. $i = 0;
  1264. foreach($array['data']['missed'] AS $child) {
  1265. $i++;
  1266. $seriesName = $child['show_name'];
  1267. $episodeID = $child['tvdbid'];
  1268. $episodeAirDate = $child['airdate'];
  1269. $episodeAirDateTime = explode(" ",$child['airs']);
  1270. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1271. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1272. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1273. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1274. $downloaded = "0";
  1275. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  1276. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  1277. }
  1278. foreach($array['data']['today'] AS $child) {
  1279. $i++;
  1280. $seriesName = $child['show_name'];
  1281. $episodeID = $child['tvdbid'];
  1282. $episodeAirDate = $child['airdate'];
  1283. $episodeAirDateTime = explode(" ",$child['airs']);
  1284. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1285. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1286. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1287. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1288. $downloaded = "0";
  1289. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  1290. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  1291. }
  1292. foreach($array['data']['soon'] AS $child) {
  1293. $i++;
  1294. $seriesName = $child['show_name'];
  1295. $episodeID = $child['tvdbid'];
  1296. $episodeAirDate = $child['airdate'];
  1297. $episodeAirDateTime = explode(" ",$child['airs']);
  1298. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1299. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1300. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1301. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1302. $downloaded = "0";
  1303. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  1304. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  1305. }
  1306. foreach($array['data']['later'] AS $child) {
  1307. $i++;
  1308. $seriesName = $child['show_name'];
  1309. $episodeID = $child['tvdbid'];
  1310. $episodeAirDate = $child['airdate'];
  1311. $episodeAirDateTime = explode(" ",$child['airs']);
  1312. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1313. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1314. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1315. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1316. $downloaded = "0";
  1317. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  1318. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  1319. }
  1320. if ($i != 0){ return $gotCalendar; }
  1321. }
  1322. function getSickrageCalendarHistory($array){
  1323. $array = json_decode($array, true);
  1324. $gotCalendar = "";
  1325. $i = 0;
  1326. foreach($array['data'] AS $child) {
  1327. $i++;
  1328. $seriesName = $child['show_name'];
  1329. $episodeID = $child['tvdbid'];
  1330. $episodeAirDate = $child['date'];
  1331. $downloaded = "green-bg";
  1332. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  1333. }
  1334. if ($i != 0){ return $gotCalendar; }
  1335. }
  1336. function getSonarrCalendar($array){
  1337. $array = json_decode($array, true);
  1338. $gotCalendar = "";
  1339. $i = 0;
  1340. foreach($array AS $child) {
  1341. $i++;
  1342. $seriesName = $child['series']['title'];
  1343. $episodeID = $child['series']['tvdbId'];
  1344. if(!isset($episodeID)){ $episodeID = ""; }
  1345. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  1346. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  1347. $episodeAirDate = $child['airDateUtc'];
  1348. $episodeAirDate = strtotime($episodeAirDate);
  1349. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1350. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1351. $downloaded = $child['hasFile'];
  1352. 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"; }
  1353. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
  1354. }
  1355. if ($i != 0){ return $gotCalendar; }
  1356. }
  1357. function getRadarrCalendar($array){
  1358. $array = json_decode($array, true);
  1359. $gotCalendar = "";
  1360. $i = 0;
  1361. foreach($array AS $child) {
  1362. if(isset($child['inCinemas'])){
  1363. $i++;
  1364. $movieName = $child['title'];
  1365. $movieID = $child['tmdbId'];
  1366. if(!isset($movieID)){ $movieID = ""; }
  1367. if(isset($child['inCinemas']) && isset($child['physicalRelease'])){
  1368. $physicalRelease = $child['physicalRelease'];
  1369. $physicalRelease = strtotime($physicalRelease);
  1370. $physicalRelease = date("Y-m-d", $physicalRelease);
  1371. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  1372. $downloaded = $child['hasFile'];
  1373. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  1374. }else{
  1375. $physicalRelease = $child['inCinemas'];
  1376. $downloaded = "light-blue-bg";
  1377. }
  1378. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\", url: \"https://www.themoviedb.org/movie/$movieID\" }, \n";
  1379. }
  1380. }
  1381. if ($i != 0){ return $gotCalendar; }
  1382. }
  1383. function nzbgetConnect($url, $username, $password, $list){
  1384. $url = qualifyURL(NZBGETURL);
  1385. $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
  1386. $api = json_decode($api, true);
  1387. $i = 0;
  1388. $gotNZB = "";
  1389. foreach ($api['result'] AS $child) {
  1390. $i++;
  1391. //echo '<pre>' . var_export($child, true) . '</pre>';
  1392. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  1393. $downloadStatus = $child['Status'];
  1394. $downloadCategory = $child['Category'];
  1395. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  1396. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  1397. if($child['Health'] <= "750"){
  1398. $downloadHealth = "danger";
  1399. }elseif($child['Health'] <= "900"){
  1400. $downloadHealth = "warning";
  1401. }elseif($child['Health'] <= "1000"){
  1402. $downloadHealth = "success";
  1403. }
  1404. $gotNZB .= '<tr>
  1405. <td>'.$downloadName.'</td>
  1406. <td>'.$downloadStatus.'</td>
  1407. <td>'.$downloadCategory.'</td>
  1408. <td>
  1409. <div class="progress">
  1410. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  1411. <p class="text-center">'.round($downloadPercent).'%</p>
  1412. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  1413. </div>
  1414. </div>
  1415. </td>
  1416. </tr>';
  1417. }
  1418. if($i > 0){ return $gotNZB; }
  1419. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  1420. }
  1421. function sabnzbdConnect($url, $key, $list){
  1422. $url = qualifyURL(SABNZBDURL);
  1423. $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
  1424. $api = json_decode($api, true);
  1425. $i = 0;
  1426. $gotNZB = "";
  1427. foreach ($api[$list]['slots'] AS $child) {
  1428. $i++;
  1429. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  1430. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  1431. $downloadStatus = $child['status'];
  1432. $gotNZB .= '<tr>
  1433. <td>'.$downloadName.'</td>
  1434. <td>'.$downloadStatus.'</td>
  1435. <td>'.$downloadCategory.'</td>
  1436. <td>
  1437. <div class="progress">
  1438. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  1439. <p class="text-center">'.round($downloadPercent).'%</p>
  1440. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  1441. </div>
  1442. </div>
  1443. </td>
  1444. </tr>';
  1445. }
  1446. if($i > 0){ return $gotNZB; }
  1447. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  1448. }
  1449. function getHeadphonesCalendar($url, $key, $list){
  1450. $url = qualifyURL(HEADPHONESURL);
  1451. $api = file_get_contents($url."/api?apikey=".$key."&cmd=$list");
  1452. $api = json_decode($api, true);
  1453. $i = 0;
  1454. $gotCalendar = "";
  1455. foreach($api AS $child) {
  1456. if($child['Status'] == "Wanted"){
  1457. $i++;
  1458. $albumName = addslashes($child['AlbumTitle']);
  1459. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  1460. $albumDate = $child['ReleaseDate'];
  1461. $albumID = $child['AlbumID'];
  1462. $albumDate = strtotime($albumDate);
  1463. $albumDate = date("Y-m-d", $albumDate);
  1464. $albumStatus = $child['Status'];
  1465. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  1466. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  1467. $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  1468. }
  1469. }
  1470. if ($i != 0){ return $gotCalendar; }
  1471. }
  1472. ?>