| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767 |
- <?php
- // ===================================
- // Define Version
- define('INSTALLEDVERSION', '1.33');
- // ===================================
- // Debugging output functions
- function debug_out($variable, $die = false) {
- $trace = debug_backtrace()[0];
- 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>';
- if ($die) { http_response_code(503); die(); }
- }
- // ==== Auth Plugins START ====
- if (function_exists('ldap_connect')) :
- // Pass credentials to LDAP backend
- function plugin_auth_ldap($username, $password) {
- // returns true or false
- $ldap = ldap_connect(AUTHBACKENDHOST, (AUTHBACKENDPORT ? AUTHBACKENDPORT : '389'));
- if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
- return true;
- } else {
- return false;
- }
- return false;
- }
- else :
- // Ldap Auth Missing Dependancy
- function plugin_auth_ldap_disabled() {
- return 'Plex - Disabled (Dependancy: php-ldap missing!)';
- }
- endif;
- // Pass credentials to FTP backend
- function plugin_auth_ftp($username, $password) {
- // returns true or false
-
- // Connect to FTP
- $conn_id = ftp_ssl_connect(AUTHBACKENDHOST, (AUTHBACKENDPORT?AUTHBACKENDPORT:21), 20); // 20 Second Timeout
-
- // Check if valid FTP connection
- if ($conn_id) {
- // Attempt login
- @$login_result = ftp_login($conn_id, $username, $password);
-
- // Return Result
- if ($login_result) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- return false;
- }
- // Pass credentials to Emby Backend
- function plugin_auth_emby_local($username, $password) {
- $urlCheck = stripos(AUTHBACKENDHOST, "http");
- if ($urlCheck === false) {
- $embyAddress = "http://" . AUTHBACKENDHOST;
- } else {
- $embyAddress = AUTHBACKENDHOST;
- }
- if(AUTHBACKENDPORT !== ""){ $embyAddress .= ":" . AUTHBACKENDPORT; }
-
- $headers = array(
- 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
- 'Content-Type' => 'application/json',
- );
- $body = array(
- 'Username' => $username,
- 'Password' => sha1($password),
- 'PasswordMd5' => md5($password),
- );
-
- $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
-
- if (isset($response['content'])) {
- $json = json_decode($response['content'], true);
- if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
- // Login Success - Now Logout Emby Session As We No Longer Need It
- $headers = array(
- 'X-Mediabrowser-Token' => $json['AccessToken'],
- );
- $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
- return true;
- }
- }
- return false;
- }
- if (function_exists('curl_version')) :
- // Authenticate Against Emby Local (first) and Emby Connect
- function plugin_auth_emby_all($username, $password) {
- $localResult = plugin_auth_emby_local($username, $password);
- if ($localResult) {
- return $localResult;
- } else {
- return plugin_auth_emby_connect($username, $password);
- }
- }
-
- // Authenicate against emby connect
- function plugin_auth_emby_connect($username, $password) {
- $urlCheck = stripos(AUTHBACKENDHOST, "http");
- if ($urlCheck === false) {
- $embyAddress = "http://" . AUTHBACKENDHOST;
- } else {
- $embyAddress = AUTHBACKENDHOST;
- }
- if(AUTHBACKENDPORT !== "") { $embyAddress .= ":" . AUTHBACKENDPORT; }
-
- // Get A User
- $connectId = '';
- $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
- if (is_array($userIds)) {
- foreach ($userIds as $key => $value) { // Scan for this user
- if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
- if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
- $connectId = $value['ConnectUserId'];
- break;
- }
-
- }
- }
-
- if ($connectId) {
- $connectURL = 'https://connect.emby.media/service/user/authenticate';
- $headers = array(
- 'Accept'=> 'application/json',
- 'Content-Type' => 'application/x-www-form-urlencoded',
- );
- $body = array(
- 'nameOrEmail' => $username,
- 'rawpw' => $password,
- );
-
- $result = curl_post($connectURL, $body, $headers);
-
- if (isset($result['content'])) {
- $json = json_decode($result['content'], true);
- if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
- return array(
- 'email' => $json['User']['Email'],
- 'image' => $json['User']['ImageUrl'],
- );
- }
- }
- }
- }
-
- return false;
- }
- // Pass credentials to Plex Backend
- function plugin_auth_plex($username, $password) {
- // Quick out
- if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
- return true;
- }
-
- //Get User List
- $userURL = 'https://plex.tv/pms/friends/all';
- $userHeaders = array(
- 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
- );
- $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
-
- if (is_array($userXML) || is_object($userXML)) {
- $isUser = false;
- $usernameLower = strtolower($username);
- foreach($userXML AS $child) {
- if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
- $isUser = true;
- break;
- }
- }
-
- if ($isUser) {
- //Login User
- $connectURL = 'https://plex.tv/users/sign_in.json';
- $headers = array(
- 'Accept'=> 'application/json',
- 'Content-Type' => 'application/x-www-form-urlencoded',
- 'X-Plex-Product' => 'Organizr',
- 'X-Plex-Version' => '1.0',
- 'X-Plex-Client-Identifier' => '01010101-10101010',
- );
- $body = array(
- 'user[login]' => $username,
- 'user[password]' => $password,
- );
- $result = curl_post($connectURL, $body, $headers);
- if (isset($result['content'])) {
- $json = json_decode($result['content'], true);
- if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
- return array(
- 'email' => $json['user']['email'],
- 'image' => $json['user']['thumb']
- );
- }
- }
- }
- }
- return false;
- }
- else :
- // Plex Auth Missing Dependancy
- function plugin_auth_plex_disabled() {
- return 'Plex - Disabled (Dependancy: php-curl missing!)';
- }
-
- // Emby Connect Auth Missing Dependancy
- function plugin_auth_emby_connect_disabled() {
- return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
- }
-
- // Emby Both Auth Missing Dependancy
- function plugin_auth_emby_both_disabled() {
- return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
- }
- endif;
- // ==== Auth Plugins END ====
- // ==== General Class Definitions START ====
- class setLanguage {
- private $language = null;
- private $langCode = null;
-
- function __construct($language = false) {
- // Default
- if (!$language) {
- $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
- }
-
- $this->langCode = $language;
-
- if (file_exists("lang/{$language}.ini")) {
- $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
- } else {
- $this->language = parse_ini_file("lang/en.ini", false, INI_SCANNER_RAW);
- }
- }
-
- public function getLang() {
- return $this->langCode;
- }
-
- public function translate($originalWord) {
- $getArg = func_num_args();
- if ($getArg > 1) {
- $allWords = func_get_args();
- array_shift($allWords);
- } else {
- $allWords = array();
- }
- $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
- if (!$translatedWord) {
- echo ("Translation not found for: $originalWord");
- }
- $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
-
- return vsprintf($translatedWord, $allWords);
- }
- }
- $language = new setLanguage;
- // ==== General Class Definitions END ====
- // Direct request to curl if it exists, otherwise handle if not HTTPS
- function post_router($url, $data, $headers = array(), $referer='') {
- if (function_exists('curl_version')) {
- return curl_post($url, $data, $headers, $referer);
- } else {
- return post_request($url, $data, $headers, $referer);
- }
- }
- if (function_exists('curl_version')) :
- // Curl Post
- function curl_post($url, $data, $headers = array(), $referer='') {
- // Initiate cURL
- $curlReq = curl_init($url);
- // As post request
- curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
- // Format Data
- switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
- case 'application/json':
- curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
- break;
- case 'application/x-www-form-urlencoded';
- curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
- break;
- default:
- $headers['Content-Type'] = 'application/x-www-form-urlencoded';
- curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
- }
- // Format Headers
- $cHeaders = array();
- foreach ($headers as $k => $v) {
- $cHeaders[] = $k.': '.$v;
- }
- if (count($cHeaders)) {
- curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
- }
- // Execute
- $result = curl_exec($curlReq);
- // Close
- curl_close($curlReq);
- // Return
- return array('content'=>$result);
- }
- //Curl Get Function
- function curl_get($url, $headers = array()) {
- // Initiate cURL
- $curlReq = curl_init($url);
- // As post request
- curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
- curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
- // Format Headers
- $cHeaders = array();
- foreach ($headers as $k => $v) {
- $cHeaders[] = $k.': '.$v;
- }
- if (count($cHeaders)) {
- curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
- }
- // Execute
- $result = curl_exec($curlReq);
- // Close
- curl_close($curlReq);
- // Return
- return $result;
- }
- endif;
- //Case-Insensitive Function
- function in_arrayi($needle, $haystack) {
- return in_array(strtolower($needle), array_map('strtolower', $haystack));
- }
- // HTTP post request (Removes need for curl, probably useless)
- function post_request($url, $data, $headers = array(), $referer='') {
- // Adapted from http://stackoverflow.com/a/28387011/6810513
-
- // Convert the data array into URL Parameters like a=b&foo=bar etc.
- if (isset($headers['Content-Type'])) {
- switch ($headers['Content-Type']) {
- case 'application/json':
- $data = json_encode($data);
- break;
- case 'application/x-www-form-urlencoded':
- $data = http_build_query($data);
- break;
- }
- } else {
- $headers['Content-Type'] = 'application/x-www-form-urlencoded';
- $data = http_build_query($data);
- }
-
- // parse the given URL
- $urlDigest = parse_url($url);
- // extract host and path:
- $host = $urlDigest['host'].(isset($urlDigest['port'])?':'.$urlDigest['port']:'');
- $path = $urlDigest['path'];
-
- if ($urlDigest['scheme'] != 'http') {
- die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
- }
- // open a socket connection on port 80 - timeout: 30 sec
- $fp = fsockopen($host, 80, $errno, $errstr, 30);
- if ($fp){
- // send the request headers:
- fputs($fp, "POST $path HTTP/1.1\r\n");
- fputs($fp, "Host: $host\r\n");
- if ($referer != '')
- fputs($fp, "Referer: $referer\r\n");
-
- fputs($fp, "Content-length: ". strlen($data) ."\r\n");
- foreach($headers as $k => $v) {
- fputs($fp, $k.": ".$v."\r\n");
- }
- fputs($fp, "Connection: close\r\n\r\n");
- fputs($fp, $data);
- $result = '';
- while(!feof($fp)) {
- // receive the results of the request
- $result .= fgets($fp, 128);
- }
- }
- else {
- return array(
- 'status' => 'err',
- 'error' => "$errstr ($errno)"
- );
- }
- // close the socket connection:
- fclose($fp);
- // split the result header from the content
- $result = explode("\r\n\r\n", $result, 2);
- $header = isset($result[0]) ? $result[0] : '';
- $content = isset($result[1]) ? $result[1] : '';
- // return as structured array:
- return array(
- 'status' => 'ok',
- 'header' => $header,
- 'content' => $content,
- );
- }
- // Format item from Emby for Carousel
- function resolveEmbyItem($address, $token, $item) {
- // Static Height
- $height = 150;
-
- // Get Item Details
- $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0];
-
- switch ($itemDetails['Type']) {
- case 'Episode':
- $title = $itemDetails['SeriesName'].': '.$itemDetails['Name'].' (Season '.$itemDetails['ParentIndexNumber'].': Episode '.$itemDetails['IndexNumber'].')';
- $imageId = $itemDetails['SeriesId'];
- $width = 100;
- $image = 'carousel-image season';
- $style = '';
- break;
- case 'MusicAlbum':
- $title = $itemDetails['Name'];
- $imageId = $itemDetails['Id'];
- $width = 150;
- $image = 'music';
- $style = 'left: 160px !important;';
- break;
- default:
- $title = $itemDetails['Name'];
- $imageId = $itemDetails['Id'];
- $width = 100;
- $image = 'carousel-image movie';
- $style = '';
- }
-
- // If No Overview
- if (!isset($itemDetails['Overview'])) {
- $itemDetails['Overview'] = '';
- }
-
- // Assemble Item And Cache Into Array
- 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>';
- }
- // Format item from Plex for Carousel
- function resolvePlexItem($server, $token, $item) {
- // Static Height
- $height = 150;
-
- $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
-
- switch ($item['type']) {
- case 'season':
- $title = $item['parentTitle'];
- $summary = $item['parentSummary'];
- $width = 100;
- $image = 'carousel-image season';
- $style = '';
- break;
- case 'album':
- $title = $item['parentTitle'];
- $summary = $item['title'];
- $width = 150;
- $image = 'album';
- $style = 'left: 160px !important;';
- break;
- default:
- $title = $item['title'];
- $summary = $item['summary'];
- $width = 100;
- $image = 'carousel-image movie';
- $style = '';
- }
-
- // If No Overview
- if (!isset($itemDetails['Overview'])) {
- $itemDetails['Overview'] = '';
- }
-
- // Assemble Item And Cache Into Array
- 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>';
- }
- // Create Carousel
- function outputCarousel($header, $size, $type, $items, $script = false) {
- // If None Populate Empty Item
- if (!count($items)) {
- $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>');
- }
-
- // Set First As Active
- $items[0] = preg_replace('/^<div class="item ?">/','<div class="item active">', $items[0]);
-
- // Add Buttons
- $buttons = '';
- if (count($items) > 1) {
- $buttons = '
- <a class="left carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a>
- <a class="right carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
- }
-
- return '
- <div class="col-lg-'.$size.'">
- <h5 class="text-center">'.$header.'</h5>
- <div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">
- '.implode('',$items).'
- </div>'.$buttons.'
- </div></div>'.($script?'<script>'.$script.'</script>':'');
- }
- // Get Now Playing Streams From Emby
- function getEmbyStreams($size) {
- $address = qualifyURL(EMBYURL);
-
- $api = json_decode(file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
-
- $playingItems = array();
- foreach($api as $key => $value) {
- if (isset($value['NowPlayingItem'])) {
- $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem']);
- }
- }
-
- return outputCarousel(translate('PLAYING_NOW_ON_EMBY'), $size, 'streams-emby', $playingItems, "
- setInterval(function() {
- $('<div></div>').load('ajax.php?a=emby-streams',function() {
- var element = $(this).find('[id]');
- var loadedID = element.attr('id');
- $('#'+loadedID).replaceWith(element);
- console.log('Loaded updated: '+loadedID);
- });
- }, 10000);
- ");
- }
- // Get Now Playing Streams From Plex
- function getPlexStreams($size){
- $address = qualifyURL(PLEXURL);
-
- // Perform API requests
- $api = file_get_contents($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
- $api = simplexml_load_string($api);
- $getServer = simplexml_load_string(file_get_contents($address."/?X-Plex-Token=".PLEXTOKEN));
-
- // Identify the local machine
- $gotServer = $getServer['machineIdentifier'];
-
- $items = array();
- foreach($api AS $child) {
- $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child);
- }
-
- return outputCarousel(translate('PLAYING_NOW_ON_PLEX'), $size, 'streams-plex', $items, "
- setInterval(function() {
- $('<div></div>').load('ajax.php?a=plex-streams',function() {
- var element = $(this).find('[id]');
- var loadedID = element.attr('id');
- $('#'+loadedID).replaceWith(element);
- console.log('Loaded updated: '+loadedID);
- });
- }, 10000);
- ");
- }
- // Get Recent Content From Emby
- function getEmbyRecent($type, $size) {
- $address = qualifyURL(EMBYURL);
-
- // Resolve Types
- switch ($type) {
- case 'movie':
- $embyTypeQuery = 'IncludeItemTypes=Movie&';
- $header = translate('MOVIES');
- break;
- case 'season':
- $embyTypeQuery = 'IncludeItemTypes=Episode&';
- $header = translate('TV_SHOWS');
- break;
- case 'album':
- $embyTypeQuery = 'IncludeItemTypes=MusicAlbum&';
- $header = translate('MUSIC');
- break;
- default:
- $embyTypeQuery = '';
- $header = translate('RECENT_CONTENT');
- }
-
- // Get A User
- $userIds = json_decode(file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
- foreach ($userIds as $value) { // Scan for admin user
- $userId = $value['Id'];
- if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
- break;
- }
- }
-
- // Get the latest Items
- $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.EMBYTOKEN),true);
-
- // For Each Item In Category
- $items = array();
- foreach ($latest as $k => $v) {
- $items[] = resolveEmbyItem($address, EMBYTOKEN, $v);
- }
-
- return outputCarousel($header, $size, $type.'-emby', $items);
- }
- // Get Recent Content From Plex
- function getPlexRecent($type, $size){
- $address = qualifyURL(PLEXURL);
-
- // Resolve Types
- switch ($type) {
- case 'movie':
- $header = translate('MOVIES');
- break;
- case 'season':
- $header = translate('TV_SHOWS');
- break;
- case 'album':
- $header = translate('MUSIC');
- break;
- default:
- $header = translate('RECENT_CONTENT');
- }
-
- // Perform Requests
- $api = file_get_contents($address."/library/recentlyAdded?X-Plex-Token=".PLEXTOKEN);
- $api = simplexml_load_string($api);
- $getServer = simplexml_load_string(file_get_contents($address."/?X-Plex-Token=".PLEXTOKEN));
-
- // Identify the local machine
- $gotServer = $getServer['machineIdentifier'];
-
- $items = array();
- foreach($api AS $child) {
- if($child['type'] == $type){
- $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child);
- }
- }
-
- return outputCarousel($header, $size, $type.'-plex', $items);
- }
- // Get Image From Emby
- function getEmbyImage() {
- $embyAddress = qualifyURL(EMBYURL);
-
- $itemId = $_GET['img'];
- $imgParams = array();
- if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
- if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
- if(isset($itemId)) {
- $image_src = $embyAddress . '/Items/'.$itemId.'/Images/Primary?'.implode('&', $imgParams);
- header('Content-type: image/jpeg');
- readfile($image_src);
- } else {
- debug_out('Invalid Request',1);
- }
- }
- // Get Image From Plex
- function getPlexImage() {
- $plexAddress = qualifyURL(PLEXURL);
-
- $image_url = $_GET['img'];
- $image_height = $_GET['height'];
- $image_width = $_GET['width'];
-
- if(isset($image_url) && isset($image_height) && isset($image_width)) {
- $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
- header('Content-type: image/jpeg');
- readfile($image_src);
- } else {
- echo "Invalid Plex Request";
- }
- }
- // Simplier access to class
- function translate($string) {
- if (isset($GLOBALS['language'])) {
- return $GLOBALS['language']->translate($string);
- } else {
- return '!Translations Not Loaded!';
- }
- }
- // Generate Random string
- function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
- $tmp = '';
- for ($i = 0; $i < $length; $i++) {
- $tmp .= substr(str_shuffle($chars), 0, 1);
- }
- return $tmp;
- }
- // Create config file in the return syntax
- function createConfig($array, $path = 'config/config.php', $nest = 0) {
- // Define Initial Value
- $output = array();
-
- // Sort Items
- ksort($array);
-
- // Unset the current version
- unset($array['CONFIG_VERSION']);
-
- // Process Settings
- foreach ($array as $k => $v) {
- $allowCommit = true;
- switch (gettype($v)) {
- case 'boolean':
- $item = ($v?'true':'false');
- break;
- case 'integer':
- case 'double':
- case 'integer':
- case 'NULL':
- $item = $v;
- break;
- case 'string':
- $item = '"'.addslashes($v).'"';
- break;
- case 'array':
- $item = createConfig($v, false, $nest+1);
- break;
- default:
- $allowCommit = false;
- }
-
- if($allowCommit) {
- $output[] = str_repeat("\t",$nest+1).'"'.$k.'" => '.$item;
- }
- }
-
- if (!$nest) {
- // Inject Current Version
- $output[] = "\t".'"CONFIG_VERSION" => "'.INSTALLEDVERSION.'"';
- }
-
- // Build output
- $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
-
- if (!$nest && $path) {
- $pathDigest = pathinfo($path);
-
- @mkdir($pathDigest['dirname'], 0770, true);
-
- if (file_exists($path)) {
- rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
- }
-
- $file = fopen($path, 'w');
- fwrite($file, $output);
- fclose($file);
- if (file_exists($path)) {
- return true;
- }
-
- return false;
- } else {
- return $output;
- }
- }
- // Load a config file written in the return syntax
- function loadConfig($path = 'config/config.php') {
- // Adapted from http://stackoverflow.com/a/14173339/6810513
- if (!is_file($path)) {
- return null;
- } else {
- return (array) call_user_func(function() use($path) {
- return include($path);
- });
- }
- }
- // Commit new values to the configuration
- function updateConfig($new, $current = false) {
- // Get config if not supplied
- if (!$current) {
- $current = loadConfig();
- }
-
- // Inject Parts
- foreach ($new as $k => $v) {
- $current[$k] = $v;
- }
-
- // Return Create
- return createConfig($current);
- }
- // Inject Defaults As Needed
- function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
- if (is_string($path)) {
- $loadedDefaults = loadConfig($path);
- } else {
- $loadedDefaults = $path;
- }
-
- return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
- }
- // support function for fillDefaultConfig()
- function fillDefaultConfig_recurse($current, $defaults) {
- foreach($defaults as $k => $v) {
- if (!isset($current[$k])) {
- $current[$k] = $v;
- } else if (is_array($current[$k]) && is_array($v)) {
- $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
- }
- }
- return $current;
- };
- // Define Scalar Variables (nest non-secular with underscores)
- function defineConfig($array, $anyCase = true, $nest_prefix = false) {
- foreach($array as $k => $v) {
- if (is_scalar($v) && !defined($nest_prefix.$k)) {
- define($nest_prefix.$k, $v, $anyCase);
- } else if (is_array($v)) {
- defineConfig($v, $anyCase, $nest_prefix.$k.'_');
- }
- }
- }
- // This function exists only because I am lazy
- function configLazy($path = null) {
- $config = fillDefaultConfig(loadConfig($path));
- if (is_array($config)) {
- defineConfig($config);
- }
- return $config;
- }
- // Qualify URL
- function qualifyURL($url) {
- // Get Digest
- $digest = parse_url($url);
-
- // http/https
- if (!isset($digest['scheme'])) {
- if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
- $scheme = 'http';
- } else {
- $scheme = 'https';
- }
- } else {
- $scheme = $digest['scheme'];
- }
-
- // Host
- $host = (isset($digest['host'])?$digest['host']:'');
-
- // Port
- $port = (isset($digest['port'])?':'.$digest['port']:'');
-
- // Path
- $path = (isset($digest['path'])?$digest['path']:'');
-
- // Output
- return $scheme.'://'.$host.$port.$path;
- }
- // Function to be called at top of each to allow upgrading environment as the spec changes
- function upgradeCheck() {
- // Upgrade to 1.31
- if (file_exists('homepageSettings.ini.php')) {
- $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
- $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
-
- $databaseConfig = array_merge($databaseConfig, $homepageConfig);
-
- $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
- foreach($databaseConfig as $k => $v) {
- if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
- $databaseData .= $k . " = \"" . $v . "\"\r\n";
- }
-
- write_ini_file($databaseData, 'databaseLocation.ini.php');
- unlink('homepageSettings.ini.php');
- unset($databaseData);
- unset($homepageConfig);
- }
-
- // Upgrade to 1.32
- if (file_exists('databaseLocation.ini.php')) {
- // Load Existing
- $config = parse_ini_file('databaseLocation.ini.php', true);
-
- // Refactor
- $config['database_Location'] = str_replace('//','/',$config['databaseLocation'].'/');
- $config['user_home'] = $config['database_Location'].'users/';
- unset($config['databaseLocation']);
-
- // Turn Off Emby And Plex Recent
- $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
- unset($config["embyPort"]);
- $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
- unset($config["plexPort"]);
- $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
- unset($config["nzbgetPort"]);
- $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
- unset($config["sabnzbdPort"]);
- $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
- unset($config["headphonesPort"]);
-
- $createConfigSuccess = createConfig($config);
-
- // Create new config
- if ($createConfigSuccess) {
- // Make Config Dir (this should never happen as the dir and defaults file should be there);
- @mkdir('config', 0775, true);
-
- // Remove Old ini file
- unlink('databaseLocation.ini.php');
- } else {
- debug_out('Couldn\'t create updated configuration.' ,1);
- }
- }
-
- // Upgrade
- $config = loadConfig();
- if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
- $config['user_home'] = $config['database_Location'].'users/';
- unset($config['USER_HOME']);
- $createConfigSuccess = createConfig($config);
- }
- unset($config);
-
- return true;
- }
- // Check if all software dependancies are met
- function dependCheck() {
- return true;
- }
- // Process file uploads
- function uploadFiles($path, $ext_mask = null) {
- if (isset($_FILES) && count($_FILES)) {
- require_once('class.uploader.php');
- $uploader = new Uploader();
- $data = $uploader->upload($_FILES['files'], array(
- 'limit' => 10,
- 'maxSize' => 10,
- 'extensions' => $ext_mask,
- 'required' => false,
- 'uploadDir' => str_replace('//','/',$path.'/'),
- 'title' => array('name'),
- 'removeFiles' => true,
- 'replace' => true,
- ));
- if($data['isComplete']){
- $files = $data['data'];
- echo json_encode($files['metas'][0]['name']);
- }
- if($data['hasErrors']){
- $errors = $data['errors'];
- echo json_encode($errors);
- }
- } else {
- echo json_encode('No files submitted!');
- }
- }
- // Remove file
- function removeFiles($path) {
- if(is_file($path)) {
- unlink($path);
- } else {
- echo json_encode('No file specified for removal!');
- }
- }
- // Lazy select options
- function resolveSelectOptions($array, $selected = '') {
- $output = array();
- foreach ($array as $key => $value) {
- $output[] = '<option value="'.$value.'"'.($selected===$value?' selected':'').'>'.$key.'</option>';
- }
- return implode('',$output);
- }
- // Check if user is allowed to continue
- function qualifyUser($type, $errOnFail = false) {
- if (!isset($GLOBALS['USER'])) {
- require_once("user.php");
- $GLOBALS['USER'] = new User('registration_callback');
- }
-
- if (is_bool($type)) {
- if ($type === true) {
- $authorized = ($GLOBALS['USER']->authenticated == true);
- } else {
- $authorized = true;
- }
- } elseif (is_string($type)) {
- if ($type !== 'false') {
- $type = explode('|',$type);
- $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
- } else {
- $authorized = true;
- }
- } else {
- debug_out('Invalid Syntax!',1);
- }
-
- if (!$authorized && $errOnFail) {
- debug_out('Not Authorized' ,1);
- } else {
- return $authorized;
- }
- }
- // Build an (optionally) tabbed settings page.
- function buildSettings($array) {
- /*
- array(
- 'title' => '',
- 'id' => '',
- 'fields' => array( See buildField() ),
- 'tabs' => array(
- array(
- 'title' => '',
- 'id' => '',
- 'image' => '',
- 'fields' => array( See buildField() ),
- ),
- ),
- );
- */
-
- $fieldFunc = function($fieldArr) {
- $fields = '<div class="row">';
- foreach($fieldArr as $key => $value) {
- $isSingle = isset($value['type']);
- if ($isSingle) { $value = array($value); }
- $tmpField = '';
- foreach($value as $k => $v) {
- $tmpField .= '<div class="form-group">'.buildField($v).'</div>';
- }
- $fields .= ($isSingle?$tmpField:'<div class="content-form form-inline">'.$tmpField.'</div>');
- }
- $fields .= '</div>';
- return $fields;
- };
-
- $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
-
- $tabSelectors = array();
- $tabContent = array();
- if (isset($array['tabs'])) {
- foreach($array['tabs'] as $key => $value) {
- $id = (isset($value['id'])?$value['id']:randString(32));
- $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>';
- $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
- }
- }
-
- $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
-
- return '
- <div class="email-body">
- <div class="email-header gray-bg">
- <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
- <h1>'.$array['title'].'</h1>
- </div>
- <div class="email-inner small-box">
- <div class="email-inner-section">
- <div class="small-box fade in" id="'.$pageID.'_frame">
- <div class="row">
- <div class="col-lg-12">
- <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
- <input type="hidden" name="action" value="'.$pageID.'" />
- '.$fields.'
- <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
- <ul class="nav nav-tabs apps">
- '.implode('', $tabSelectors).'
- </ul>
- <div class="clearfix"></div>
- <div class="tab-content">
- '.implode('', $tabContent).'
- </div>
- </div>
- <button type="submit" class="btn waves btn-labeled btn-success btn btn-sm pull-right text-uppercase waves-effect waves-float">
- <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
- </button>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- $(document).ready(function() {
- $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() {
- $(this).attr(\'data-changed\', \'true\');
- });
- $(\'#'.$pageID.'_form\').submit(function () {
- var newVals = {};
- $(\'#'.$pageID.'_form\').find(\'[data-changed=true]\').each(function() {
- newVals[$(this).attr(\'name\')] = $(this).val();
- });
- $.post(\'ajax.php?a=update-config\', newVals, function(data) {
- console.log(data);
- parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect);
- }, \'json\');
- return false;
- });
- });
- </script>
- ';
- }
- // Build Settings Fields
- function buildField($params) {
- /*
- array(
- 'type' => '',
- 'placeholder' => '',
- 'label' => '',
- 'labelTranslate' => '',
- 'assist' => '',
- 'name' => '',
- 'pattern' => '',
- 'options' => array( // For SELECT only
- 'Display' => 'value',
- ),
- )
- */
-
- // Tags
- $tags = array();
- foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave') as $value) {
- $tags[] = (isset($params[$value])?$value.'="'.$params[$value].'"':'');
- }
-
- $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
- $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
- $val = (isset($params['value'])?$params['value']:'');
- $class = (isset($params['class'])?' '.$params['class']:'');
- $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
- $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
-
- switch ($params['type']) {
- case 'input':
- case 'text':
- $field = '
- <input id="'.$id.'" name="'.$name.'" type="text" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">
- ';
- break;
- case 'select':
- case 'dropdown':
- $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>
- '.resolveSelectOptions($params['options'], $val).'
- </select>';
- break;
- case 'check':
- case 'checkbox':
- case 'toggle':
- $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
- return '
- <input id="'.$id.'_disabled" name="'.$name.'" type="hidden" class="switcher switcher-success" value="false">
- <input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-success'.$class.'" '.implode(' ',$tags).' value="'.$val.'"'.$checked.'><label for="'.$id.'"></label>'.$label.'
- ';
- break;
- case 'date':
- $field = '
-
- ';
- break;
- case 'number':
- $field = '
- <input id="'.$id.'" name="'.$name.'" type="number" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">
- ';
- break;
- case 'password':
- $field = '
- <input id="'.$id.'" name="'.$name.'" type="password" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">
- ';
- break;
- default:
- $field = '';
- }
-
- $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
- return $field.$labelOut;
- }
- // ==============
- function clean($strin) {
- $strout = null;
- for ($i = 0; $i < strlen($strin); $i++) {
- $ord = ord($strin[$i]);
- if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
- $strout .= "&#{$ord};";
- }
- else {
- switch ($strin[$i]) {
- case '<':
- $strout .= '<';
- break;
- case '>':
- $strout .= '>';
- break;
- case '&':
- $strout .= '&';
- break;
- case '"':
- $strout .= '"';
- break;
- default:
- $strout .= $strin[$i];
- }
- }
- }
- return $strout;
-
- }
- function registration_callback($username, $email, $userdir){
-
- global $data;
-
- $data = array($username, $email, $userdir);
- }
- function printArray($arrayName){
-
- $messageCount = count($arrayName);
-
- $i = 0;
-
- foreach ( $arrayName as $item ) :
-
- $i++;
-
- if($i < $messageCount) :
-
- echo "<small class='text-uppercase'>" . $item . "</small> & ";
-
- elseif($i = $messageCount) :
-
- echo "<small class='text-uppercase'>" . $item . "</small>";
-
- endif;
-
- endforeach;
-
- }
- function write_ini_file($content, $path) {
-
- if (!$handle = fopen($path, 'w')) {
-
- return false;
-
- }
-
- $success = fwrite($handle, trim($content));
-
- fclose($handle);
-
- return $success;
- }
- function gotTimezone(){
- $regions = array(
- 'Africa' => DateTimeZone::AFRICA,
- 'America' => DateTimeZone::AMERICA,
- 'Antarctica' => DateTimeZone::ANTARCTICA,
- 'Arctic' => DateTimeZone::ARCTIC,
- 'Asia' => DateTimeZone::ASIA,
- 'Atlantic' => DateTimeZone::ATLANTIC,
- 'Australia' => DateTimeZone::AUSTRALIA,
- 'Europe' => DateTimeZone::EUROPE,
- 'Indian' => DateTimeZone::INDIAN,
- 'Pacific' => DateTimeZone::PACIFIC
- );
-
- $timezones = array();
- foreach ($regions as $name => $mask) {
-
- $zones = DateTimeZone::listIdentifiers($mask);
- foreach($zones as $timezone) {
- $time = new DateTime(NULL, new DateTimeZone($timezone));
- $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
- $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
- }
-
- }
-
- print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
-
- foreach($timezones as $region => $list) {
-
- print '<optgroup label="' . $region . '">' . "\n";
-
- foreach($list as $timezone => $name) {
-
- if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
-
- print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
-
- }
-
- print '</optgroup>' . "\n";
-
- }
-
- print '</select>';
-
- }
- function getTimezone(){
- $regions = array(
- 'Africa' => DateTimeZone::AFRICA,
- 'America' => DateTimeZone::AMERICA,
- 'Antarctica' => DateTimeZone::ANTARCTICA,
- 'Arctic' => DateTimeZone::ARCTIC,
- 'Asia' => DateTimeZone::ASIA,
- 'Atlantic' => DateTimeZone::ATLANTIC,
- 'Australia' => DateTimeZone::AUSTRALIA,
- 'Europe' => DateTimeZone::EUROPE,
- 'Indian' => DateTimeZone::INDIAN,
- 'Pacific' => DateTimeZone::PACIFIC
- );
-
- $timezones = array();
- foreach ($regions as $name => $mask) {
-
- $zones = DateTimeZone::listIdentifiers($mask);
- foreach($zones as $timezone) {
- $time = new DateTime(NULL, new DateTimeZone($timezone));
- $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
- $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
- }
-
- }
-
- print '<select name="timezone" id="timezone" class="form-control material" required>';
-
- foreach($timezones as $region => $list) {
-
- print '<optgroup label="' . $region . '">' . "\n";
-
- foreach($list as $timezone => $name) {
-
- print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
-
- }
-
- print '</optgroup>' . "\n";
-
- }
-
- print '</select>';
-
- }
- function explosion($string, $position){
-
- $getWord = explode("|", $string);
- return $getWord[$position];
-
- }
- function getServerPath() {
-
- if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
-
- $protocol = "https://";
-
- } else {
-
- $protocol = "http://";
-
- }
-
- return $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
-
- }
- function get_browser_name() {
-
- $user_agent = $_SERVER['HTTP_USER_AGENT'];
-
- if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
- elseif (strpos($user_agent, 'Edge')) return 'Edge';
- elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
- elseif (strpos($user_agent, 'Safari')) return 'Safari';
- elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
- elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
-
- return 'Other';
-
- }
- function getSickrageCalendarWanted($array){
-
- $array = json_decode($array, true);
- $gotCalendar = "";
- $i = 0;
- foreach($array['data']['missed'] AS $child) {
- $i++;
- $seriesName = $child['show_name'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ",$child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
- $downloaded = "0";
- if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
- $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
-
- }
-
- foreach($array['data']['today'] AS $child) {
- $i++;
- $seriesName = $child['show_name'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ",$child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
- $downloaded = "0";
- if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
- $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
-
- }
-
- foreach($array['data']['soon'] AS $child) {
- $i++;
- $seriesName = $child['show_name'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ",$child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
- $downloaded = "0";
- if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
- $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
-
- }
-
- foreach($array['data']['later'] AS $child) {
- $i++;
- $seriesName = $child['show_name'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ",$child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
- $downloaded = "0";
- if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
- $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
-
- }
- if ($i != 0){ return $gotCalendar; }
- }
- function getSickrageCalendarHistory($array){
-
- $array = json_decode($array, true);
- $gotCalendar = "";
- $i = 0;
- foreach($array['data'] AS $child) {
- $i++;
- $seriesName = $child['show_name'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['date'];
- $downloaded = "green-bg";
- $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
-
- }
- if ($i != 0){ return $gotCalendar; }
- }
- function getSonarrCalendar($array){
-
- $array = json_decode($array, true);
- $gotCalendar = "";
- $i = 0;
- foreach($array AS $child) {
- $i++;
- $seriesName = $child['series']['title'];
- $episodeID = $child['series']['tvdbId'];
- if(!isset($episodeID)){ $episodeID = ""; }
- $episodeName = htmlentities($child['title'], ENT_QUOTES);
- if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
- $episodeAirDate = $child['airDateUtc'];
- $episodeAirDate = strtotime($episodeAirDate);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
-
- if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
- $downloaded = $child['hasFile'];
- 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"; }
-
- $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\", url: \"https://thetvdb.com/?tab=series&id=$episodeID\" }, \n";
-
- }
- if ($i != 0){ return $gotCalendar; }
- }
- function getRadarrCalendar($array){
-
- $array = json_decode($array, true);
- $gotCalendar = "";
- $i = 0;
- foreach($array AS $child) {
-
- if(isset($child['inCinemas'])){
-
- $i++;
- $movieName = $child['title'];
- $movieID = $child['tmdbId'];
- if(!isset($movieID)){ $movieID = ""; }
-
- if(isset($child['inCinemas']) && isset($child['physicalRelease'])){
-
- $physicalRelease = $child['physicalRelease'];
- $physicalRelease = strtotime($physicalRelease);
- $physicalRelease = date("Y-m-d", $physicalRelease);
- if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
- $downloaded = $child['hasFile'];
- if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
-
- }else{
-
- $physicalRelease = $child['inCinemas'];
- $downloaded = "light-blue-bg";
-
- }
-
- $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\", url: \"https://www.themoviedb.org/movie/$movieID\" }, \n";
- }
-
- }
- if ($i != 0){ return $gotCalendar; }
- }
- function nzbgetConnect($url, $username, $password, $list){
- $url = qualifyURL(NZBGETURL);
-
- $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
-
- $api = json_decode($api, true);
-
- $i = 0;
-
- $gotNZB = "";
-
- foreach ($api['result'] AS $child) {
-
- $i++;
- //echo '<pre>' . var_export($child, true) . '</pre>';
- $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
- $downloadStatus = $child['Status'];
- $downloadCategory = $child['Category'];
- if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
- if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
- if($child['Health'] <= "750"){
- $downloadHealth = "danger";
- }elseif($child['Health'] <= "900"){
- $downloadHealth = "warning";
- }elseif($child['Health'] <= "1000"){
- $downloadHealth = "success";
- }
-
- $gotNZB .= '<tr>
- <td>'.$downloadName.'</td>
- <td>'.$downloadStatus.'</td>
- <td>'.$downloadCategory.'</td>
- <td>
- <div class="progress">
- <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
- <p class="text-center">'.round($downloadPercent).'%</p>
- <span class="sr-only">'.$downloadPercent.'% Complete</span>
- </div>
- </div>
- </td>
- </tr>';
-
-
- }
-
- if($i > 0){ return $gotNZB; }
- if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
- }
- function sabnzbdConnect($url, $key, $list){
- $url = qualifyURL(SABNZBDURL);
- $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
-
- $api = json_decode($api, true);
-
- $i = 0;
-
- $gotNZB = "";
-
- foreach ($api[$list]['slots'] AS $child) {
-
- $i++;
- if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
- if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
- $downloadStatus = $child['status'];
-
- $gotNZB .= '<tr>
- <td>'.$downloadName.'</td>
- <td>'.$downloadStatus.'</td>
- <td>'.$downloadCategory.'</td>
- <td>
- <div class="progress">
- <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
- <p class="text-center">'.round($downloadPercent).'%</p>
- <span class="sr-only">'.$downloadPercent.'% Complete</span>
- </div>
- </div>
- </td>
- </tr>';
-
-
- }
-
- if($i > 0){ return $gotNZB; }
- if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
- }
- function getHeadphonesCalendar($url, $key, $list){
- $url = qualifyURL(HEADPHONESURL);
-
- $api = file_get_contents($url."/api?apikey=".$key."&cmd=$list");
-
- $api = json_decode($api, true);
-
- $i = 0;
-
- $gotCalendar = "";
-
- foreach($api AS $child) {
- if($child['Status'] == "Wanted"){
-
- $i++;
- $albumName = addslashes($child['AlbumTitle']);
- $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
- $albumDate = $child['ReleaseDate'];
- $albumID = $child['AlbumID'];
- $albumDate = strtotime($albumDate);
- $albumDate = date("Y-m-d", $albumDate);
- $albumStatus = $child['Status'];
-
- if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
- if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
- $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
-
- }
-
- }
- if ($i != 0){ return $gotCalendar; }
- }
- ?>
|