functions.php 202 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.42');
  5. // ===================================
  6. // Debugging output functions
  7. function debug_out($variable, $die = false) {
  8. $trace = debug_backtrace()[0];
  9. echo "<center><img height='200px' src='images/confused.png'></center>";
  10. echo "<center>Look's like something happened, here are the errors and perhaps how to fix them:</center>";
  11. echo '<pre style="white-space: pre-line; 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>';
  12. if ($die) { http_response_code(503); die(); }
  13. }
  14. // ==== Auth Plugins START ====
  15. if (function_exists('ldap_connect')) :
  16. // Pass credentials to LDAP backend
  17. function plugin_auth_ldap($username, $password) {
  18. $ldapServers = explode(',',AUTHBACKENDHOST);
  19. foreach($ldapServers as $key => $value) {
  20. // Calculate parts
  21. $digest = parse_url(trim($value));
  22. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  23. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  24. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  25. // Reassign
  26. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  27. }
  28. // returns true or false
  29. $ldap = ldap_connect(implode(' ',$ldapServers));
  30. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  31. writeLog("success", "LDAP authentication success");
  32. return true;
  33. } else {
  34. writeLog("error", "LDPA could not authenticate");
  35. return false;
  36. }
  37. writeLog("error", "LDPA could not authenticate");
  38. return false;
  39. }
  40. else :
  41. // Ldap Auth Missing Dependancy
  42. function plugin_auth_ldap_disabled() {
  43. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  44. }
  45. endif;
  46. // Pass credentials to FTP backend
  47. function plugin_auth_ftp($username, $password) {
  48. // Calculate parts
  49. $digest = parse_url(AUTHBACKENDHOST);
  50. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  51. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  52. $port = (isset($digest['port'])?$digest['port']:21);
  53. // Determine Connection Type
  54. if ($scheme == 'ftps') {
  55. $conn_id = ftp_ssl_connect($host, $port, 20);
  56. } elseif ($scheme == 'ftp') {
  57. $conn_id = ftp_connect($host, $port, 20);
  58. } else {
  59. debug_out('Invalid FTP scheme. Use ftp or ftps');
  60. writeLog("error", "invalid FTP scheme");
  61. return false;
  62. }
  63. // Check if valid FTP connection
  64. if ($conn_id) {
  65. // Attempt login
  66. @$login_result = ftp_login($conn_id, $username, $password);
  67. ftp_close($conn_id);
  68. // Return Result
  69. if ($login_result) {
  70. writeLog("success", "$username authenticated");
  71. return true;
  72. } else {
  73. writeLog("error", "$username could not authenticate");
  74. return false;
  75. }
  76. } else {
  77. return false;
  78. }
  79. return false;
  80. }
  81. // Pass credentials to Emby Backend
  82. function plugin_auth_emby_local($username, $password) {
  83. $embyAddress = qualifyURL(EMBYURL);
  84. $headers = array(
  85. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  86. 'Content-Type' => 'application/json',
  87. );
  88. $body = array(
  89. 'Username' => $username,
  90. 'Password' => sha1($password),
  91. 'PasswordMd5' => md5($password),
  92. );
  93. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  94. if (isset($response['content'])) {
  95. $json = json_decode($response['content'], true);
  96. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  97. // Login Success - Now Logout Emby Session As We No Longer Need It
  98. $headers = array(
  99. 'X-Mediabrowser-Token' => $json['AccessToken'],
  100. );
  101. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. if (function_exists('curl_version')) :
  108. // Authenticate Against Emby Local (first) and Emby Connect
  109. function plugin_auth_emby_all($username, $password) {
  110. $localResult = plugin_auth_emby_local($username, $password);
  111. if ($localResult) {
  112. return $localResult;
  113. } else {
  114. return plugin_auth_emby_connect($username, $password);
  115. }
  116. }
  117. // Authenicate against emby connect
  118. function plugin_auth_emby_connect($username, $password) {
  119. $embyAddress = qualifyURL(EMBYURL);
  120. // Get A User
  121. $connectId = '';
  122. $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  123. if (is_array($userIds)) {
  124. foreach ($userIds as $key => $value) { // Scan for this user
  125. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  126. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  127. $connectId = $value['ConnectUserId'];
  128. break;
  129. }
  130. }
  131. }
  132. if ($connectId) {
  133. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  134. $headers = array(
  135. 'Accept'=> 'application/json',
  136. 'Content-Type' => 'application/x-www-form-urlencoded',
  137. );
  138. $body = array(
  139. 'nameOrEmail' => $username,
  140. 'rawpw' => $password,
  141. );
  142. $result = curl_post($connectURL, $body, $headers);
  143. if (isset($result['content'])) {
  144. $json = json_decode($result['content'], true);
  145. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  146. return array(
  147. 'email' => $json['User']['Email'],
  148. 'image' => $json['User']['ImageUrl'],
  149. );
  150. }
  151. }
  152. }
  153. }
  154. return false;
  155. }
  156. // Pass credentials to Plex Backend
  157. function plugin_auth_plex($username, $password) {
  158. // Quick out
  159. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  160. writeLog("success", $username." authenticated by plex");
  161. return true;
  162. }
  163. //Get User List
  164. $userURL = 'https://plex.tv/pms/friends/all';
  165. $userHeaders = array(
  166. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  167. );
  168. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  169. if (is_array($userXML) || is_object($userXML)) {
  170. $isUser = false;
  171. $usernameLower = strtolower($username);
  172. foreach($userXML AS $child) {
  173. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  174. $isUser = true;
  175. writeLog("success", $usernameLower." was found in plex friends list");
  176. break;
  177. }
  178. }
  179. if ($isUser) {
  180. //Login User
  181. $connectURL = 'https://plex.tv/users/sign_in.json';
  182. $headers = array(
  183. 'Accept'=> 'application/json',
  184. 'Content-Type' => 'application/x-www-form-urlencoded',
  185. 'X-Plex-Product' => 'Organizr',
  186. 'X-Plex-Version' => '1.0',
  187. 'X-Plex-Client-Identifier' => '01010101-10101010',
  188. );
  189. $body = array(
  190. 'user[login]' => $username,
  191. 'user[password]' => $password,
  192. );
  193. $result = curl_post($connectURL, $body, $headers);
  194. if (isset($result['content'])) {
  195. $json = json_decode($result['content'], true);
  196. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  197. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  198. return array(
  199. 'email' => $json['user']['email'],
  200. 'image' => $json['user']['thumb']
  201. );
  202. }
  203. }
  204. }else{
  205. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  206. }
  207. }else{
  208. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  209. }
  210. return false;
  211. }
  212. else :
  213. // Plex Auth Missing Dependancy
  214. function plugin_auth_plex_disabled() {
  215. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  216. }
  217. // Emby Connect Auth Missing Dependancy
  218. function plugin_auth_emby_connect_disabled() {
  219. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  220. }
  221. // Emby Both Auth Missing Dependancy
  222. function plugin_auth_emby_both_disabled() {
  223. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  224. }
  225. endif;
  226. // ==== Auth Plugins END ====
  227. // ==== General Class Definitions START ====
  228. class setLanguage {
  229. private $language = null;
  230. private $langCode = null;
  231. function __construct($language = false) {
  232. // Default
  233. if (!$language) {
  234. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  235. }
  236. if (!file_exists("lang/{$language}.ini")) {
  237. $language = 'en';
  238. }
  239. $this->langCode = $language;
  240. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  241. if (file_exists("lang/{$language}.cust.ini")) {
  242. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  243. $this->language[$k] = $v;
  244. }
  245. }
  246. }
  247. public function getLang() {
  248. return $this->langCode;
  249. }
  250. public function translate($originalWord) {
  251. $getArg = func_num_args();
  252. if ($getArg > 1) {
  253. $allWords = func_get_args();
  254. array_shift($allWords);
  255. } else {
  256. $allWords = array();
  257. }
  258. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  259. if (!$translatedWord) {
  260. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  261. }
  262. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  263. return vsprintf($translatedWord, $allWords);
  264. }
  265. }
  266. $language = new setLanguage;
  267. // ==== General Class Definitions END ====
  268. // Direct request to curl if it exists, otherwise handle if not HTTPS
  269. function post_router($url, $data, $headers = array(), $referer='') {
  270. if (function_exists('curl_version')) {
  271. return curl_post($url, $data, $headers, $referer);
  272. } else {
  273. return post_request($url, $data, $headers, $referer);
  274. }
  275. }
  276. if (function_exists('curl_version')) :
  277. // Curl Post
  278. function curl_post($url, $data, $headers = array(), $referer='') {
  279. // Initiate cURL
  280. $curlReq = curl_init($url);
  281. // As post request
  282. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  283. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  284. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  285. // Format Data
  286. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  287. case 'application/json':
  288. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  289. break;
  290. case 'application/x-www-form-urlencoded';
  291. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  292. break;
  293. default:
  294. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  295. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  296. }
  297. // Format Headers
  298. $cHeaders = array();
  299. foreach ($headers as $k => $v) {
  300. $cHeaders[] = $k.': '.$v;
  301. }
  302. if (count($cHeaders)) {
  303. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  304. }
  305. // Execute
  306. $result = curl_exec($curlReq);
  307. $httpcode = curl_getinfo($curlReq);
  308. // Close
  309. curl_close($curlReq);
  310. // Return
  311. return array('content'=>$result, 'http_code'=>$httpcode);
  312. }
  313. //Curl Get Function
  314. function curl_get($url, $headers = array()) {
  315. // Initiate cURL
  316. $curlReq = curl_init($url);
  317. // As post request
  318. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  319. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  320. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  321. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  322. // Format Headers
  323. $cHeaders = array();
  324. foreach ($headers as $k => $v) {
  325. $cHeaders[] = $k.': '.$v;
  326. }
  327. if (count($cHeaders)) {
  328. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  329. }
  330. // Execute
  331. $result = curl_exec($curlReq);
  332. // Close
  333. curl_close($curlReq);
  334. // Return
  335. return $result;
  336. }
  337. //Curl Delete Function
  338. function curl_delete($url, $headers = array()) {
  339. // Initiate cURL
  340. $curlReq = curl_init($url);
  341. // As post request
  342. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  343. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  344. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  345. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  346. // Format Headers
  347. $cHeaders = array();
  348. foreach ($headers as $k => $v) {
  349. $cHeaders[] = $k.': '.$v;
  350. }
  351. if (count($cHeaders)) {
  352. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  353. }
  354. // Execute
  355. $result = curl_exec($curlReq);
  356. $httpcode = curl_getinfo($curlReq);
  357. // Close
  358. curl_close($curlReq);
  359. // Return
  360. return array('content'=>$result, 'http_code'=>$httpcode);
  361. }
  362. endif;
  363. //Case-Insensitive Function
  364. function in_arrayi($needle, $haystack) {
  365. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  366. }
  367. // HTTP post request (Removes need for curl, probably useless)
  368. function post_request($url, $data, $headers = array(), $referer='') {
  369. // Adapted from http://stackoverflow.com/a/28387011/6810513
  370. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  371. if (isset($headers['Content-Type'])) {
  372. switch ($headers['Content-Type']) {
  373. case 'application/json':
  374. $data = json_encode($data);
  375. break;
  376. case 'application/x-www-form-urlencoded':
  377. $data = http_build_query($data);
  378. break;
  379. }
  380. } else {
  381. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  382. $data = http_build_query($data);
  383. }
  384. // parse the given URL
  385. $urlDigest = parse_url($url);
  386. // extract host and path:
  387. $host = $urlDigest['host'];
  388. $path = $urlDigest['path'];
  389. if ($urlDigest['scheme'] != 'http') {
  390. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  391. }
  392. // open a socket connection on port 80 - timeout: 30 sec
  393. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  394. if ($fp){
  395. // send the request headers:
  396. fputs($fp, "POST $path HTTP/1.1\r\n");
  397. fputs($fp, "Host: $host\r\n");
  398. if ($referer != '')
  399. fputs($fp, "Referer: $referer\r\n");
  400. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  401. foreach($headers as $k => $v) {
  402. fputs($fp, $k.": ".$v."\r\n");
  403. }
  404. fputs($fp, "Connection: close\r\n\r\n");
  405. fputs($fp, $data);
  406. $result = '';
  407. while(!feof($fp)) {
  408. // receive the results of the request
  409. $result .= fgets($fp, 128);
  410. }
  411. }
  412. else {
  413. return array(
  414. 'status' => 'err',
  415. 'error' => "$errstr ($errno)"
  416. );
  417. }
  418. // close the socket connection:
  419. fclose($fp);
  420. // split the result header from the content
  421. $result = explode("\r\n\r\n", $result, 2);
  422. $header = isset($result[0]) ? $result[0] : '';
  423. $content = isset($result[1]) ? $result[1] : '';
  424. // return as structured array:
  425. return array(
  426. 'status' => 'ok',
  427. 'header' => $header,
  428. 'content' => $content,
  429. );
  430. }
  431. // Format item from Emby for Carousel
  432. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  433. // Static Height
  434. $height = 444;
  435. // Get Item Details
  436. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  437. if (substr_count(EMBYURL, ':') == 2) {
  438. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  439. }else{
  440. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  441. }
  442. //$URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  443. switch ($itemDetails['Type']) {
  444. case 'Episode':
  445. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  446. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  447. $width = 300;
  448. $style = '';
  449. $image = 'slick-image-tall';
  450. if(!$nowPlaying){
  451. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  452. $key = $itemDetails['Id'] . "-list";
  453. }else{
  454. $height = 281;
  455. $width = 500;
  456. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  457. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  458. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  459. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  460. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  461. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  462. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  463. $stream = $moreInfo['PlayState']['PlayMethod'];
  464. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  465. $id = $moreInfo['DeviceId'];
  466. $streamInfo = buildStream(array(
  467. 'platform' => (string) $moreInfo['Client'],
  468. 'device' => (string) $moreInfo['DeviceName'],
  469. 'stream' => "&nbsp;".streamType($stream),
  470. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  471. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  472. ));
  473. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  474. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  475. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  476. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  477. }
  478. break;
  479. case 'MusicAlbum':
  480. case 'Audio':
  481. $title = $itemDetails['Name'];
  482. $imageId = $itemDetails['Id'];
  483. $width = 444;
  484. $style = '';
  485. $image = 'slick-image-short';
  486. if(!$nowPlaying){
  487. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  488. $key = $itemDetails['Id'] . "-list";
  489. }else{
  490. $height = 281;
  491. $width = 500;
  492. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  493. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  494. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  495. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  496. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  497. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  498. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  499. $stream = $moreInfo['PlayState']['PlayMethod'];
  500. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  501. $id = $moreInfo['DeviceId'];
  502. $streamInfo = buildStream(array(
  503. 'platform' => (string) $moreInfo['Client'],
  504. 'device' => (string) $moreInfo['DeviceName'],
  505. 'stream' => "&nbsp;".streamType($stream),
  506. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  507. ));
  508. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  509. $topTitle = '<h5 class="text-center zero-m elip">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  510. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  511. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  512. }
  513. break;
  514. case 'TvChannel':
  515. $title = $itemDetails['CurrentProgram']['Name'];
  516. $imageId = $itemDetails['Id'];
  517. $width = 300;
  518. $style = '';
  519. $image = 'slick-image-tall';
  520. if(!$nowPlaying){
  521. $imageType = "Primary";
  522. $key = $itemDetails['Id'] . "-list";
  523. }else{
  524. $height = 281;
  525. $width = 500;
  526. $imageType = "Thumb";
  527. $key = $itemDetails['Id'] . "-np";
  528. $useImage = "images/livetv.png";
  529. $watched = "0";
  530. $stream = $moreInfo['PlayState']['PlayMethod'];
  531. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  532. $id = $moreInfo['DeviceId'];
  533. $streamInfo = buildStream(array(
  534. 'platform' => (string) $moreInfo['Client'],
  535. 'device' => (string) $moreInfo['DeviceName'],
  536. 'stream' => "&nbsp;".streamType($stream),
  537. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  538. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  539. ));
  540. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  541. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  542. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  543. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  544. }
  545. break;
  546. default:
  547. $title = $itemDetails['Name'];
  548. $imageId = $itemDetails['Id'];
  549. $width = 300;
  550. $style = '';
  551. $image = 'slick-image-tall';
  552. if(!$nowPlaying){
  553. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  554. $key = $itemDetails['Id'] . "-list";
  555. }else{
  556. $height = 281;
  557. $width = 500;
  558. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  559. $key = $itemDetails['Id'] . "-np";
  560. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  561. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  562. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  563. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  564. $stream = $moreInfo['PlayState']['PlayMethod'];
  565. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  566. $id = $moreInfo['DeviceId'];
  567. $streamInfo = buildStream(array(
  568. 'platform' => (string) $moreInfo['Client'],
  569. 'device' => (string) $moreInfo['DeviceName'],
  570. 'stream' => "&nbsp;".streamType($stream),
  571. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  572. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  573. ));
  574. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  575. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  576. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  577. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  578. }
  579. }
  580. // If No Overview
  581. if (!isset($itemDetails['Overview'])) {
  582. $itemDetails['Overview'] = '';
  583. }
  584. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  585. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  586. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  587. }
  588. if($nowPlaying){
  589. if(!$imageType){ $image_url = "images/no-np.png"; $key = "no-np"; }
  590. if(!$imageId){ $image_url = "images/no-np.png"; $key = "no-np"; }
  591. }else{
  592. if(!$imageType){ $image_url = "images/no-list.png"; $key = "no-list"; }
  593. if(!$imageId){ $image_url = "images/no-list.png"; $key = "no-list"; }
  594. }
  595. if(isset($useImage)){ $image_url = $useImage; }
  596. // Assemble Item And Cache Into Array
  597. if($nowPlaying){
  598. //prettyPrint($itemDetails);
  599. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$URL.'" target="_blank"><img style="width: 100%; display:inherit;" src="'.$image_url.'" alt="'.$itemDetails['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: 0%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  600. }else{
  601. return '<div class="item-'.$itemDetails['Type'].'"><a href="'.$URL.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
  602. }
  603. }
  604. // Format item from Plex for Carousel
  605. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  606. // Static Height
  607. $height = 444;
  608. $playlist = ($playlist) ? " playlist-$playlist" : "";
  609. switch ($item['type']) {
  610. case 'season':
  611. $title = $item['parentTitle'];
  612. $summary = $item['parentSummary'];
  613. $width = 300;
  614. $image = 'slick-image-tall';
  615. $style = '';
  616. if(!$nowPlaying){
  617. $thumb = $item['thumb'];
  618. $key = $item['ratingKey'] . "-list";
  619. }else {
  620. $height = 281;
  621. $width = 500;
  622. $thumb = $item['art'];
  623. $key = $item['ratingKey'] . "-np";
  624. $elapsed = $item['viewOffset'];
  625. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  626. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  627. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  628. $stream = $item->Media->Part->Stream['decision'];
  629. $user = $role == "admin" ? $item->User['title'] : "";
  630. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  631. $streamInfo = buildStream(array(
  632. 'platform' => (string) $item->Player['platform'],
  633. 'device' => (string) $item->Player['device'],
  634. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  635. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  636. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  637. ));
  638. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  639. }
  640. break;
  641. case 'episode':
  642. $title = $item['grandparentTitle'];
  643. $summary = $item['title'];
  644. $width = 300;
  645. $image = 'slick-image-tall';
  646. $style = '';
  647. if(!$nowPlaying){
  648. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  649. $key = $item['ratingKey'] . "-list";
  650. }else {
  651. $height = 281;
  652. $width = 500;
  653. $thumb = $item['art'];
  654. $key = $item['ratingKey'] . "-np";
  655. $elapsed = $item['viewOffset'];
  656. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  657. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  658. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  659. $stream = $item->Media->Part->Stream['decision'];
  660. $user = $role == "admin" ? $item->User['title'] : "";
  661. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  662. $streamInfo = buildStream(array(
  663. 'platform' => (string) $item->Player['platform'],
  664. 'device' => (string) $item->Player['device'],
  665. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  666. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  667. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  668. ));
  669. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  670. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  671. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  672. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  673. }
  674. break;
  675. case 'clip':
  676. $title = $item['title'];
  677. $summary = $item['summary'];
  678. $width = 300;
  679. $image = 'slick-image-tall';
  680. $style = '';
  681. if(!$nowPlaying){
  682. $thumb = $item['thumb'];
  683. $key = $item['ratingKey'] . "-list";
  684. }else {
  685. $height = 281;
  686. $width = 500;
  687. $thumb = $item['art'];
  688. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  689. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  690. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  691. $elapsed = $item['viewOffset'];
  692. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  693. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  694. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  695. $stream = $item->Media->Part->Stream['decision'];
  696. $user = $role == "admin" ? $item->User['title'] : "";
  697. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  698. $streamInfo = buildStream(array(
  699. 'platform' => (string) $item->Player['platform'],
  700. 'device' => (string) $item->Player['device'],
  701. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  702. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  703. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  704. ));
  705. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  706. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  707. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  708. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  709. }
  710. break;
  711. case 'album':
  712. case 'track':
  713. $title = $item['parentTitle'];
  714. $summary = $item['title'];
  715. $image = 'slick-image-short';
  716. $style = 'left: 160px !important;';
  717. $item['ratingKey'] = $item['parentRatingKey'];
  718. if(!$nowPlaying){
  719. $width = 444;
  720. $thumb = $item['thumb'];
  721. $key = $item['ratingKey'] . "-list";
  722. }else {
  723. $height = 281;
  724. $width = 500;
  725. $thumb = $item['art'];
  726. $key = $item['ratingKey'] . "-np";
  727. $elapsed = $item['viewOffset'];
  728. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  729. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  730. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  731. $stream = $item->Media->Part->Stream['decision'];
  732. $user = $role == "admin" ? $item->User['title'] : "";
  733. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  734. $streamInfo = buildStream(array(
  735. 'platform' => (string) $item->Player['platform'],
  736. 'device' => (string) $item->Player['device'],
  737. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  738. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  739. ));
  740. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  741. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  742. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  743. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  744. }
  745. break;
  746. default:
  747. $title = $item['title'];
  748. $summary = $item['summary'];
  749. $image = 'slick-image-tall';
  750. $style = '';
  751. if(!$nowPlaying){
  752. $width = 300;
  753. $thumb = $item['thumb'];
  754. $key = $item['ratingKey'] . "-list";
  755. }else {
  756. $height = 281;
  757. $width = 500;
  758. $thumb = $item['art'];
  759. $key = $item['ratingKey'] . "-np";
  760. $elapsed = $item['viewOffset'];
  761. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  762. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  763. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  764. $stream = $item->Media->Part->Stream['decision'];
  765. $user = $role == "admin" ? $item->User['title'] : "";
  766. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  767. $streamInfo = buildStream(array(
  768. 'platform' => (string) $item->Player['platform'],
  769. 'device' => (string) $item->Player['device'],
  770. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  771. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  772. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  773. ));
  774. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  775. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  776. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  777. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  778. }
  779. }
  780. if (substr_count(PLEXURL, '.') != 2) {
  781. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  782. }else{
  783. $address = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  784. }
  785. // If No Overview
  786. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  787. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  788. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  789. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  790. }
  791. if($nowPlaying){
  792. if(!$thumb){ $image_url = "images/no-np.png"; $key = "no-np"; }
  793. }else{
  794. if(!$thumb){ $image_url = "images/no-list.png"; $key = "no-list"; }
  795. }
  796. if(isset($useImage)){ $image_url = $useImage; }
  797. $openTab = (PLEXTABNAME) ? "true" : "false";
  798. // Assemble Item And Cache Into Array
  799. if($nowPlaying){
  800. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img style="width: 100%; display:inherit;" src="'.$image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  801. }else{
  802. return '<div class="item-'.$item['type'].$playlist.'"><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
  803. }
  804. }
  805. //Recent Added
  806. function outputRecentAdded($header, $items, $script = false, $array) {
  807. $hideMenu = '<div class="pull-right"><div class="btn-group" role="group"><button type="button" class="btn waves btn-default btn-sm dropdown-toggle waves-effect waves-float" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Filter &nbsp;<span class="caret"></span></button><ul style="right:0; left: auto" class="dropdown-menu filter-recent-event">';
  808. if($array["movie"] == "true"){
  809. $hideMenu .= '<li data-filter="item-movie" data-filter-on="false"><a class="js-filter-movie" href="javascript:void(0)">Movies</a></li>';
  810. }
  811. if($array["season"] == "true"){
  812. $hideMenu .= '<li data-filter="item-season" data-filter-on="false"><a class="js-filter-season" href="javascript:void(0)">Shows</a></li>';
  813. }
  814. if($array["album"] == "true"){
  815. $hideMenu .= '<li data-filter="item-album" data-filter-on="false"><a class="js-filter-album" href="javascript:void(0)">Music</a></li>';
  816. }
  817. $hideMenu .= '</ul></div></div>';
  818. // If None Populate Empty Item
  819. if (!count($items)) {
  820. return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Media Found</p></div>';
  821. }else{
  822. $className = str_replace(' ', '', $header);
  823. return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-recent" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  824. }
  825. }
  826. // Create Carousel
  827. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  828. // If None Populate Empty Item
  829. if (!count($items)) {
  830. return '<div id=streamz></div>'.($script?'<script>'.$script.'</script>':'');
  831. }else{
  832. return '<div id=streamz><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  833. }
  834. }
  835. // Get Now Playing Streams From Emby
  836. function getEmbyStreams($size, $showNames, $role) {
  837. $address = qualifyURL(EMBYURL);
  838. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  839. if (!is_array($api)) { return 'Could not load!'; }
  840. $playingItems = array();
  841. foreach($api as $key => $value) {
  842. if (isset($value['NowPlayingItem'])) {
  843. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  844. }
  845. }
  846. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY'), $size, 'streams-emby', $playingItems, "
  847. setInterval(function() {
  848. $('<div></div>').load('ajax.php?a=emby-streams',function() {
  849. var element = $(this).find('[id]');
  850. var loadedID = element.attr('id');
  851. $('#'+loadedID).replaceWith(element);
  852. console.log('Loaded updated: '+loadedID);
  853. });
  854. }, 15000);
  855. ");
  856. }
  857. // Get Now Playing Streams From Plex
  858. function getPlexStreams($size, $showNames, $role){
  859. $address = qualifyURL(PLEXURL);
  860. // Perform API requests
  861. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  862. $api = simplexml_load_string($api);
  863. if (is_array($api) || is_object($api)){
  864. if (!$api->head->title){
  865. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  866. if (!$getServer) { return 'Could not load!'; }
  867. // Identify the local machine
  868. $gotServer = $getServer['machineIdentifier'];
  869. $items = array();
  870. foreach($api AS $child) {
  871. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  872. }
  873. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, "
  874. setInterval(function() {
  875. $('<div></div>').load('ajax.php?a=plex-streams',function() {
  876. var element = $(this).find('[id]');
  877. var loadedID = element.attr('id');
  878. $('#'+loadedID).replaceWith(element);
  879. console.log('Loaded updated: '+loadedID);
  880. });
  881. }, 15000);
  882. ");
  883. }else{
  884. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  885. }
  886. }else{
  887. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  888. }
  889. }
  890. // Get Recent Content From Emby
  891. function getEmbyRecent($array) {
  892. $address = qualifyURL(EMBYURL);
  893. $header = translate('RECENT_CONTENT');
  894. // Currently Logged In User
  895. $username = false;
  896. if (isset($GLOBALS['USER'])) {
  897. $username = strtolower($GLOBALS['USER']->username);
  898. }
  899. // Get A User
  900. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  901. if (!is_array($userIds)) { return 'Could not load!'; }
  902. $showPlayed = true;
  903. foreach ($userIds as $value) { // Scan for admin user
  904. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  905. $userId = $value['Id'];
  906. }
  907. if ($username && strtolower($value['Name']) == $username) {
  908. $userId = $value['Id'];
  909. $showPlayed = false;
  910. break;
  911. }
  912. }
  913. // Get the latest Items
  914. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  915. // For Each Item In Category
  916. $items = array();
  917. foreach ($latest as $k => $v) {
  918. $type = (string) $v['Type'];
  919. if(@$array[$type] == "true"){
  920. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  921. }
  922. }
  923. $array["movie"] = $array["Movie"];
  924. $array["season"] = $array["Episode"];
  925. $array["album"] = $array["MusicAlbum"];
  926. unset($array["Movie"]);
  927. unset($array["Episode"]);
  928. unset($array["MusicAlbum"]);
  929. unset($array["Series"]);
  930. return outputRecentAdded($header, $items, "", $array);
  931. }
  932. // Get Recent Content From Plex
  933. function getPlexRecent($array){
  934. $address = qualifyURL(PLEXURL);
  935. $header = translate('RECENT_CONTENT');
  936. // Perform Requests
  937. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  938. $api = simplexml_load_string($api);
  939. if (is_array($api) || is_object($api)){
  940. if (!$api->head->title){
  941. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  942. if (!$getServer) { return 'Could not load!'; }
  943. // Identify the local machine
  944. $gotServer = $getServer['machineIdentifier'];
  945. $items = array();
  946. foreach($api AS $child) {
  947. $type = (string) $child['type'];
  948. if($array[$type] == "true"){
  949. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  950. }
  951. }
  952. return outputRecentAdded($header, $items, "", $array);
  953. }else{
  954. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  955. }
  956. }else{
  957. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  958. }
  959. }
  960. // Get Image From Emby
  961. function getEmbyImage() {
  962. $embyAddress = qualifyURL(EMBYURL);
  963. if (!file_exists('images/cache')) {
  964. mkdir('images/cache', 0777, true);
  965. }
  966. $itemId = $_GET['img'];
  967. $key = $_GET['key'];
  968. $itemType = $_GET['type'];
  969. $imgParams = array();
  970. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  971. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  972. if(isset($itemId)) {
  973. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  974. $cachefile = 'images/cache/'.$key.'.jpg';
  975. $cachetime = 604800;
  976. // Serve from the cache if it is younger than $cachetime
  977. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  978. header("Content-type: image/jpeg");
  979. @readfile($cachefile);
  980. exit;
  981. }
  982. ob_start(); // Start the output buffer
  983. header('Content-type: image/jpeg');
  984. @readfile($image_src);
  985. // Cache the output to a file
  986. $fp = fopen($cachefile, 'wb');
  987. fwrite($fp, ob_get_contents());
  988. fclose($fp);
  989. ob_end_flush(); // Send the output to the browser
  990. die();
  991. } else {
  992. debug_out('Invalid Request',1);
  993. }
  994. }
  995. // Get Image From Plex
  996. function getPlexImage() {
  997. $plexAddress = qualifyURL(PLEXURL);
  998. if (!file_exists('images/cache')) {
  999. mkdir('images/cache', 0777, true);
  1000. }
  1001. $image_url = $_GET['img'];
  1002. $key = $_GET['key'];
  1003. $image_height = $_GET['height'];
  1004. $image_width = $_GET['width'];
  1005. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1006. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1007. $cachefile = 'images/cache/'.$key.'.jpg';
  1008. $cachetime = 604800;
  1009. // Serve from the cache if it is younger than $cachetime
  1010. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  1011. header("Content-type: image/jpeg");
  1012. @readfile($cachefile);
  1013. exit;
  1014. }
  1015. ob_start(); // Start the output buffer
  1016. header('Content-type: image/jpeg');
  1017. @readfile($image_src);
  1018. // Cache the output to a file
  1019. $fp = fopen($cachefile, 'wb');
  1020. fwrite($fp, ob_get_contents());
  1021. fclose($fp);
  1022. ob_end_flush(); // Send the output to the browser
  1023. die();
  1024. } else {
  1025. echo "Invalid Plex Request";
  1026. }
  1027. }
  1028. // Simplier access to class
  1029. function translate($string) {
  1030. if (isset($GLOBALS['language'])) {
  1031. return $GLOBALS['language']->translate($string);
  1032. } else {
  1033. return '!Translations Not Loaded!';
  1034. }
  1035. }
  1036. // Generate Random string
  1037. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1038. $tmp = '';
  1039. for ($i = 0; $i < $length; $i++) {
  1040. $tmp .= substr(str_shuffle($chars), 0, 1);
  1041. }
  1042. return $tmp;
  1043. }
  1044. // Create config file in the return syntax
  1045. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1046. // Define Initial Value
  1047. $output = array();
  1048. // Sort Items
  1049. ksort($array);
  1050. // Update the current config version
  1051. if (!$nest) {
  1052. // Inject Current Version
  1053. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1054. }
  1055. unset($array['CONFIG_VERSION']);
  1056. unset($array['apply_CONFIG_VERSION']);
  1057. // Process Settings
  1058. foreach ($array as $k => $v) {
  1059. $allowCommit = true;
  1060. switch (gettype($v)) {
  1061. case 'boolean':
  1062. $item = ($v?'true':'false');
  1063. break;
  1064. case 'integer':
  1065. case 'double':
  1066. case 'integer':
  1067. case 'NULL':
  1068. $item = $v;
  1069. break;
  1070. case 'string':
  1071. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1072. break;
  1073. case 'array':
  1074. $item = createConfig($v, false, $nest+1);
  1075. break;
  1076. default:
  1077. $allowCommit = false;
  1078. }
  1079. if($allowCommit) {
  1080. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1081. }
  1082. }
  1083. // Build output
  1084. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1085. if (!$nest && $path) {
  1086. $pathDigest = pathinfo($path);
  1087. @mkdir($pathDigest['dirname'], 0770, true);
  1088. if (file_exists($path)) {
  1089. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1090. }
  1091. $file = fopen($path, 'w');
  1092. fwrite($file, $output);
  1093. fclose($file);
  1094. if (file_exists($path)) {
  1095. return true;
  1096. }
  1097. writeLog("error", "config was unable to write");
  1098. return false;
  1099. } else {
  1100. writeLog("success", "config was updated with new values");
  1101. return $output;
  1102. }
  1103. }
  1104. // Load a config file written in the return syntax
  1105. function loadConfig($path = 'config/config.php') {
  1106. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1107. if (!is_file($path)) {
  1108. return null;
  1109. } else {
  1110. return (array) call_user_func(function() use($path) {
  1111. return include($path);
  1112. });
  1113. }
  1114. }
  1115. // Commit new values to the configuration
  1116. function updateConfig($new, $current = false) {
  1117. // Get config if not supplied
  1118. if ($current === false) {
  1119. $current = loadConfig();
  1120. } else if (is_string($current) && is_file($current)) {
  1121. $current = loadConfig($current);
  1122. }
  1123. // Inject Parts
  1124. foreach ($new as $k => $v) {
  1125. $current[$k] = $v;
  1126. }
  1127. // Return Create
  1128. return createConfig($current);
  1129. }
  1130. // Inject Defaults As Needed
  1131. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1132. if (is_string($path)) {
  1133. $loadedDefaults = loadConfig($path);
  1134. } else {
  1135. $loadedDefaults = $path;
  1136. }
  1137. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1138. }
  1139. // support function for fillDefaultConfig()
  1140. function fillDefaultConfig_recurse($current, $defaults) {
  1141. foreach($defaults as $k => $v) {
  1142. if (!isset($current[$k])) {
  1143. $current[$k] = $v;
  1144. } else if (is_array($current[$k]) && is_array($v)) {
  1145. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1146. }
  1147. }
  1148. return $current;
  1149. };
  1150. // Define Scalar Variables (nest non-secular with underscores)
  1151. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1152. foreach($array as $k => $v) {
  1153. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1154. define($nest_prefix.$k, $v, $anyCase);
  1155. } else if (is_array($v)) {
  1156. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1157. }
  1158. }
  1159. }
  1160. // This function exists only because I am lazy
  1161. function configLazy($path = 'config/config.php') {
  1162. // Load config or default
  1163. if (file_exists($path)) {
  1164. $config = fillDefaultConfig(loadConfig($path));
  1165. } else {
  1166. $config = loadConfig('config/configDefaults.php');
  1167. }
  1168. if (is_array($config)) {
  1169. defineConfig($config);
  1170. }
  1171. return $config;
  1172. }
  1173. // Qualify URL
  1174. function qualifyURL($url) {
  1175. //local address?
  1176. if(substr($url, 0,1) == "/"){
  1177. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1178. $protocol = "https://";
  1179. } else {
  1180. $protocol = "http://";
  1181. }
  1182. $url = $protocol.getServer().$url;
  1183. }
  1184. // Get Digest
  1185. $digest = parse_url($url);
  1186. // http/https
  1187. if (!isset($digest['scheme'])) {
  1188. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1189. $scheme = 'http';
  1190. } else {
  1191. $scheme = 'https';
  1192. }
  1193. } else {
  1194. $scheme = $digest['scheme'];
  1195. }
  1196. // Host
  1197. $host = (isset($digest['host'])?$digest['host']:'');
  1198. // Port
  1199. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1200. // Path
  1201. $path = (isset($digest['path'])?$digest['path']:'');
  1202. // Output
  1203. return $scheme.'://'.$host.$port.$path;
  1204. }
  1205. // Function to be called at top of each to allow upgrading environment as the spec changes
  1206. function upgradeCheck() {
  1207. // Upgrade to 1.31
  1208. if (file_exists('homepageSettings.ini.php')) {
  1209. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1210. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1211. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1212. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1213. foreach($databaseConfig as $k => $v) {
  1214. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1215. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1216. }
  1217. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1218. unlink('homepageSettings.ini.php');
  1219. unset($databaseData);
  1220. unset($homepageConfig);
  1221. }
  1222. // Upgrade to 1.32
  1223. if (file_exists('databaseLocation.ini.php')) {
  1224. // Load Existing
  1225. $config = parse_ini_file('databaseLocation.ini.php', true);
  1226. // Refactor
  1227. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1228. $config['user_home'] = $config['database_Location'].'users/';
  1229. unset($config['databaseLocation']);
  1230. // Turn Off Emby And Plex Recent
  1231. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1232. unset($config["embyPort"]);
  1233. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1234. unset($config["plexPort"]);
  1235. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1236. unset($config["nzbgetPort"]);
  1237. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1238. unset($config["sabnzbdPort"]);
  1239. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1240. unset($config["headphonesPort"]);
  1241. // Write config file
  1242. $config['CONFIG_VERSION'] = '1.32';
  1243. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1244. $createConfigSuccess = createConfig($config);
  1245. // Create new config
  1246. if ($createConfigSuccess) {
  1247. if (file_exists('config/config.php')) {
  1248. // Remove Old ini file
  1249. unlink('databaseLocation.ini.php');
  1250. } else {
  1251. debug_out('Something is not right here!');
  1252. }
  1253. } else {
  1254. debug_out('Couldn\'t create updated configuration.' ,1);
  1255. }
  1256. }
  1257. // Upgrade to 1.33
  1258. $config = loadConfig();
  1259. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1260. // Fix User Directory
  1261. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1262. $config['user_home'] = $config['database_Location'].'users/';
  1263. unset($config['USER_HOME']);
  1264. // Backend auth merge
  1265. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1266. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1267. }
  1268. unset($config['authBackendPort']);
  1269. // If auth is being used move it to embyURL as that is now used in auth functions
  1270. if ((isset($config['authType']) && $config['authType'] == 'true') && (isset($config['authBackendHost']) && $config['authBackendHost'] == 'true') && (isset($config['authBackend']) && in_array($config['authBackend'], array('emby_all','emby_local','emby_connect')))) {
  1271. $config['embyURL'] = $config['authBackendHost'];
  1272. }
  1273. // Upgrade database to latest version
  1274. updateSQLiteDB($config['database_Location'],'1.32');
  1275. // Update Version and Commit
  1276. $config['apply_CONFIG_VERSION'] = '1.33';
  1277. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1278. $createConfigSuccess = createConfig($config);
  1279. unset($config);
  1280. }
  1281. // Upgrade to 1.34
  1282. $config = loadConfig();
  1283. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1284. // Upgrade database to latest version
  1285. updateSQLiteDB($config['database_Location'],'1.33');
  1286. // Update Version and Commit
  1287. $config['CONFIG_VERSION'] = '1.34';
  1288. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1289. $createConfigSuccess = createConfig($config);
  1290. unset($config);
  1291. }
  1292. // Upgrade to 1.40
  1293. $config = loadConfig();
  1294. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1295. // Upgrade database to latest version
  1296. updateSQLiteDB($config['database_Location'],'1.38');
  1297. // Update Version and Commit
  1298. $config['CONFIG_VERSION'] = '1.40';
  1299. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1300. $createConfigSuccess = createConfig($config);
  1301. unset($config);
  1302. }
  1303. return true;
  1304. }
  1305. // Get OS from server
  1306. function getOS(){
  1307. if(PHP_SHLIB_SUFFIX == "dll"){
  1308. return "win";
  1309. }else{
  1310. return "nix";
  1311. }
  1312. }
  1313. //Get Error by Server OS
  1314. function getError($os, $error){
  1315. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1316. $ext = (!empty(ini_get('extension_dir')) ? "uncomment ;extension_dir = and make sure it says -> extension_dir = '".ini_get('extension_dir')."'" : "uncomment ;extension_dir = and add path to 'ext' to make it like extension_dir = 'C:\nginx\php\ext'");
  1317. $errors = array(
  1318. 'pdo_sqlite' => array(
  1319. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1320. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1321. ),
  1322. 'sqlite3' => array(
  1323. 'win' => '<b>SQLite3</b> not enabled, uncomment ;extension=php_sqlite3.dll in the file php.ini | uncomment ;sqlite3.extension_dir = and add "ext" to make it sqlite3.extension_dir = ext',
  1324. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1325. ),
  1326. 'curl' => array(
  1327. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1328. 'nix' => '<b>cURL</b> not enabled, PHP7 -> sudo apt-get install php-curl | PHP5 -> run sudo apt-get install php5.6-curl',
  1329. ),
  1330. 'zip' => array(
  1331. 'win' => '<b>PHP Zip</b> not enabled, uncomment ;extension=php_zip.dll in the file php.ini, if that doesn\'t work remove that line',
  1332. 'nix' => '<b>PHP Zip</b> not enabled, PHP7 -> run sudo apt-get install php7.0-zip | PHP5 -> run sudo apt-get install php5.6-zip',
  1333. ),
  1334. );
  1335. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1336. }
  1337. // Check if all software dependancies are met
  1338. function dependCheck() {
  1339. $output = array();
  1340. $i = 1;
  1341. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1342. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1343. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1344. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1345. if ($output) {
  1346. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1347. $output["Step $i"] = "<b>Please visit here to also check status of necessary components after you fix them: <a href='check.php'>check.php<a/></b>"; $i++;
  1348. debug_out($output,1);
  1349. }
  1350. return true;
  1351. }
  1352. // Process file uploads
  1353. function uploadFiles($path, $ext_mask = null) {
  1354. if (isset($_FILES) && count($_FILES)) {
  1355. require_once('class.uploader.php');
  1356. $uploader = new Uploader();
  1357. $data = $uploader->upload($_FILES['files'], array(
  1358. 'limit' => 10,
  1359. 'maxSize' => 10,
  1360. 'extensions' => $ext_mask,
  1361. 'required' => false,
  1362. 'uploadDir' => str_replace('//','/',$path.'/'),
  1363. 'title' => array('name'),
  1364. 'removeFiles' => true,
  1365. 'replace' => true,
  1366. ));
  1367. if($data['isComplete']){
  1368. $files = $data['data'];
  1369. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1370. echo json_encode($files['metas'][0]['name']);
  1371. }
  1372. if($data['hasErrors']){
  1373. $errors = $data['errors'];
  1374. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1375. echo json_encode($errors);
  1376. }
  1377. } else {
  1378. writeLog("error", "image was not uploaded");
  1379. echo json_encode('No files submitted!');
  1380. }
  1381. }
  1382. // Remove file
  1383. function removeFiles($path) {
  1384. if(is_file($path)) {
  1385. writeLog("success", "image was removed");
  1386. unlink($path);
  1387. } else {
  1388. writeLog("error", "image was not removed");
  1389. echo json_encode('No file specified for removal!');
  1390. }
  1391. }
  1392. // Lazy select options
  1393. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1394. $output = array();
  1395. $selectedArr = ($multi?explode('|', $selected):array());
  1396. foreach ($array as $key => $value) {
  1397. if (is_array($value)) {
  1398. if (isset($value['optgroup'])) {
  1399. $output[] = '<optgroup label="'.$key.'">';
  1400. foreach($value['optgroup'] as $k => $v) {
  1401. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1402. }
  1403. } else {
  1404. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1405. }
  1406. } else {
  1407. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1408. }
  1409. }
  1410. return implode('',$output);
  1411. }
  1412. // Check if user is allowed to continue
  1413. function qualifyUser($type, $errOnFail = false) {
  1414. if (!isset($GLOBALS['USER'])) {
  1415. require_once("user.php");
  1416. $GLOBALS['USER'] = new User('registration_callback');
  1417. }
  1418. if (is_bool($type)) {
  1419. if ($type === true) {
  1420. $authorized = ($GLOBALS['USER']->authenticated == true);
  1421. } else {
  1422. $authorized = true;
  1423. }
  1424. } elseif (is_string($type) || is_array($type)) {
  1425. if ($type !== 'false') {
  1426. if (!is_array($type)) {
  1427. $type = explode('|',$type);
  1428. }
  1429. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1430. } else {
  1431. $authorized = true;
  1432. }
  1433. } else {
  1434. debug_out('Invalid Syntax!',1);
  1435. }
  1436. if (!$authorized && $errOnFail) {
  1437. if ($GLOBALS['USER']->authenticated) {
  1438. header('Location: error.php?error=401');
  1439. echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'/error.php?error=401\'</script>';
  1440. } else {
  1441. header('Location: error.php?error=999');
  1442. echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'/error.php?error=999\'</script>';
  1443. }
  1444. debug_out('Not Authorized' ,1);
  1445. } else {
  1446. return $authorized;
  1447. }
  1448. }
  1449. // Build an (optionally) tabbed settings page.
  1450. function buildSettings($array) {
  1451. /*
  1452. array(
  1453. 'title' => '',
  1454. 'id' => '',
  1455. 'fields' => array( See buildField() ),
  1456. 'tabs' => array(
  1457. array(
  1458. 'title' => '',
  1459. 'id' => '',
  1460. 'image' => '',
  1461. 'fields' => array( See buildField() ),
  1462. ),
  1463. ),
  1464. );
  1465. */
  1466. $notifyExplode = explode("-", NOTIFYEFFECT);
  1467. $fieldFunc = function($fieldArr) {
  1468. $fields = '<div class="row">';
  1469. foreach($fieldArr as $key => $value) {
  1470. $isSingle = isset($value['type']);
  1471. if ($isSingle) { $value = array($value); }
  1472. $tmpField = '';
  1473. $sizeLg = max(floor(12/count($value)),2);
  1474. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1475. foreach($value as $k => $v) {
  1476. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1477. }
  1478. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1479. }
  1480. $fields .= '</div>';
  1481. return $fields;
  1482. };
  1483. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1484. $tabSelectors = array();
  1485. $tabContent = array();
  1486. if (isset($array['tabs'])) {
  1487. foreach($array['tabs'] as $key => $value) {
  1488. $id = (isset($value['id'])?$value['id']:randString(32));
  1489. $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>';
  1490. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1491. }
  1492. }
  1493. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1494. return '
  1495. <div class="email-body">
  1496. <div class="email-header gray-bg">
  1497. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1498. <h1>'.$array['title'].'</h1>
  1499. </div>
  1500. <div class="email-inner small-box">
  1501. <div class="email-inner-section">
  1502. <div class="small-box fade in" id="'.$pageID.'_frame">
  1503. <div class="col-lg-12">
  1504. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1505. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1506. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm pull-right text-uppercase waves-effect waves-float">
  1507. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1508. </button>
  1509. '.$fields.($tabContent?'
  1510. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1511. <ul class="nav nav-tabs apps">
  1512. '.implode('', $tabSelectors).'
  1513. </ul>
  1514. <div class="clearfix"></div>
  1515. <div class="tab-content">
  1516. '.implode('', $tabContent).'
  1517. </div>
  1518. </div>':'').'
  1519. </form>
  1520. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1521. </div>
  1522. </div>
  1523. </div>
  1524. </div>
  1525. </div>
  1526. <script>
  1527. $(document).ready(function() {
  1528. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1529. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1530. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1531. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1532. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1533. var newVals = {};
  1534. var hasVals = false;
  1535. var errorFields = [];
  1536. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1537. hasVals = true;
  1538. if (this.type == \'checkbox\') {
  1539. newVals[this.name] = this.checked;
  1540. } else if ($(this).hasClass(\'summernote\')) {
  1541. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1542. } else {
  1543. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1544. var fieldVal = $(this).val();
  1545. if (typeof fieldVal == \'object\') {
  1546. if (typeof fieldVal.join == \'function\') {
  1547. fieldVal = fieldVal.join(\'|\');
  1548. } else {
  1549. fieldVal = JSON.stringify(fieldVal);
  1550. }
  1551. }
  1552. newVals[this.name] = fieldVal;
  1553. }
  1554. });
  1555. if (errorFields.length) {
  1556. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1557. } else if (hasVals) {
  1558. console.log(newVals);
  1559. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1560. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1561. });
  1562. } else {
  1563. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1564. }
  1565. return false;
  1566. });
  1567. '.(isset($array['onready'])?$array['onready']:'').'
  1568. });
  1569. </script>
  1570. ';
  1571. }
  1572. // Build Settings Fields
  1573. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1574. /*
  1575. array(
  1576. 'type' => '',
  1577. 'placeholder' => '',
  1578. 'label' => '',
  1579. 'labelTranslate' => '',
  1580. 'assist' => '',
  1581. 'name' => '',
  1582. 'pattern' => '',
  1583. 'options' => array( // For SELECT only
  1584. 'Display' => 'value',
  1585. ),
  1586. )
  1587. */
  1588. // Tags
  1589. $tags = array();
  1590. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick') as $value) {
  1591. if (isset($params[$value])) {
  1592. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1593. } else if ($params[$value] === true) { $tags[] = $value; }
  1594. }
  1595. }
  1596. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1597. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1598. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1599. $val = (isset($params['value'])?$params['value']:'');
  1600. $class = (isset($params['class'])?' '.$params['class']:'');
  1601. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1602. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1603. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1604. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1605. // Field Design
  1606. switch ($params['type']) {
  1607. case 'text':
  1608. case 'number':
  1609. case 'password':
  1610. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1611. break;
  1612. case 'select':
  1613. case 'dropdown':
  1614. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1615. break;
  1616. case 'select-multi':
  1617. case 'dropdown-multi':
  1618. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1619. break;
  1620. case 'check':
  1621. case 'checkbox':
  1622. case 'toggle':
  1623. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1624. $colour = (isset($params['colour'])?$params['colour']:'success');
  1625. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1626. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1627. break;
  1628. case 'radio':
  1629. $labelOut = '';
  1630. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1631. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1632. $field = '<div class="radio radio-'.$bType.'"><input id="'.$id.'" name="'.$name.'" type="radio" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'"'.$checked.'><label for="'.$id.'">'.$label.'</label></div>';
  1633. break;
  1634. case 'date':
  1635. $field = 'Unsupported, planned.';
  1636. break;
  1637. case 'hidden':
  1638. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1639. break;
  1640. case 'header':
  1641. $labelOut = '';
  1642. $headType = (isset($params['value'])?$params['value']:3);
  1643. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1644. break;
  1645. case 'button':
  1646. $labelOut = '';
  1647. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1648. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1649. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1650. $field = ($bDropdown?'<div class="btn-group">':'').'<button id="'.$id.'" type="button" class="btn waves btn-labeled btn-'.$bType.' btn-sm text-uppercase waves-effect waves-float'.$class.''.($bDropdown?' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"':'"').' '.implode(' ',$tags).'><span class="btn-label"><i class="fa fa-'.$icon.'"></i></span>'.$label.'</button>'.($bDropdown?$bDropdown.'</div>':'');
  1651. break;
  1652. case 'textarea':
  1653. $rows = (isset($params['rows'])?$params['rows']:5);
  1654. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1655. break;
  1656. case 'custom':
  1657. // Settings
  1658. $settings = array(
  1659. '$id' => $id,
  1660. '$name' => $name,
  1661. '$val' => $val,
  1662. '$label' => $label,
  1663. '$labelOut' => $labelOut,
  1664. );
  1665. // Get HTML
  1666. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1667. // If LabelOut is in html dont print it twice
  1668. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1669. // Replace variables in settings
  1670. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1671. // Build Field
  1672. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1673. break;
  1674. case 'space':
  1675. $labelOut = '';
  1676. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1677. break;
  1678. default:
  1679. $field = 'Unsupported field type';
  1680. break;
  1681. }
  1682. // Field Formats
  1683. switch ($format) {
  1684. case 'colour': // Fuckin Eh, Canada!
  1685. case 'color':
  1686. $labelBef = '<center>'.$label.'</center>';
  1687. $wrapClass = 'gray-bg colour-field';
  1688. $labelAft = '';
  1689. $field = str_replace(' material input-sm','',$field);
  1690. break;
  1691. default:
  1692. $labelBef = '';
  1693. $labelAft = $labelOut;
  1694. }
  1695. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1696. }
  1697. // Tab Settings Generation
  1698. function printTabRow($data) {
  1699. $hidden = false;
  1700. if ($data===false) {
  1701. $hidden = true;
  1702. $data = array( // New Tab Defaults
  1703. 'id' => 'new',
  1704. 'name' => '',
  1705. 'url' => '',
  1706. 'icon' => 'fa-diamond',
  1707. 'iconurl' => '',
  1708. 'active' => 'true',
  1709. 'user' => 'true',
  1710. 'guest' => 'true',
  1711. 'window' => 'false',
  1712. 'defaultz' => '',
  1713. );
  1714. }
  1715. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1716. $output = '
  1717. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1718. <tab class="content-form form-inline">
  1719. <div class="row">
  1720. '.buildField(array(
  1721. 'type' => 'custom',
  1722. 'html' => '<div class="action-btns tabIconView"><a style="margin-left: 0px">'.($data['iconurl']?'<img src="'.$data['iconurl'].'" height="30" width="30">':'<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa '.($data['icon']?$data['icon']:'hand-paper-o').'"></span>').'</a></div>',
  1723. ),12,1,1).'
  1724. '.buildField(array(
  1725. 'type' => 'hidden',
  1726. 'id' => 'tab-'.$data['id'].'-id',
  1727. 'name' => 'id['.$data['id'].']',
  1728. 'value' => $data['id'],
  1729. ),12,2,1).'
  1730. '.buildField(array(
  1731. 'type' => 'text',
  1732. 'id' => 'tab-'.$data['id'].'-name',
  1733. 'name' => 'name['.$data['id'].']',
  1734. 'required' => true,
  1735. 'placeholder' => 'Organizr Homepage',
  1736. 'labelTranslate' => 'TAB_NAME',
  1737. 'value' => $data['name'],
  1738. ),12,2,1).'
  1739. '.buildField(array(
  1740. 'type' => 'text',
  1741. 'id' => 'tab-'.$data['id'].'-url',
  1742. 'name' => 'url['.$data['id'].']',
  1743. 'required' => true,
  1744. 'placeholder' => 'homepage.php',
  1745. 'labelTranslate' => 'TAB_URL',
  1746. 'value' => $data['url'],
  1747. ),12,2,1).'
  1748. '.buildField(array(
  1749. 'type' => 'text',
  1750. 'id' => 'tab-'.$data['id'].'-iconurl',
  1751. 'name' => 'iconurl['.$data['id'].']',
  1752. 'placeholder' => 'images/organizr.png',
  1753. 'labelTranslate' => 'ICON_URL',
  1754. 'value' => $data['iconurl'],
  1755. ),12,2,1).'
  1756. '.buildField(array(
  1757. 'type' => 'custom',
  1758. 'id' => 'tab-'.$data['id'].'-icon',
  1759. 'name' => 'icon['.$data['id'].']',
  1760. 'html' => '- '.translate('OR').' - <div class="input-group"><input data-placement="bottomRight" class="form-control material icp-auto'.($hidden?'-pend':'').'" id="$id" name="$name" value="$val" type="text" /><span class="input-group-addon"></span></div>',
  1761. 'value' => $data['icon'],
  1762. ),12,1,1).'
  1763. '.buildField(array(
  1764. 'type' => 'checkbox',
  1765. 'labelTranslate' => 'ACTIVE',
  1766. 'name' => 'active['.$data['id'].']',
  1767. 'value' => $data['active'],
  1768. ),12,1,1).'
  1769. '.buildField(array(
  1770. 'type' => 'checkbox',
  1771. 'labelTranslate' => 'USER',
  1772. 'colour' => 'primary',
  1773. 'name' => 'user['.$data['id'].']',
  1774. 'value' => $data['user'],
  1775. ),12,1,1).'
  1776. '.buildField(array(
  1777. 'type' => 'checkbox',
  1778. 'labelTranslate' => 'GUEST',
  1779. 'colour' => 'warning',
  1780. 'name' => 'guest['.$data['id'].']',
  1781. 'value' => $data['guest'],
  1782. ),12,1,1).'
  1783. '.buildField(array(
  1784. 'type' => 'checkbox',
  1785. 'labelTranslate' => 'NO_IFRAME',
  1786. 'colour' => 'danger',
  1787. 'name' => 'window['.$data['id'].']',
  1788. 'value' => $data['window'],
  1789. ),12,1,1).'
  1790. '.buildField(array(
  1791. 'type' => 'radio',
  1792. 'labelTranslate' => 'DEFAULT',
  1793. 'name' => 'defaultz['.$data['id'].']',
  1794. 'value' => $data['defaultz'],
  1795. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1796. ),12,1,1).'
  1797. '.buildField(array(
  1798. 'type' => 'button',
  1799. 'icon' => 'trash',
  1800. 'buttonType' => 'danger',
  1801. 'labelTranslate' => 'REMOVE',
  1802. 'onclick' => "$(this).parents('li').remove();",
  1803. ),12,1,1).'
  1804. </div>
  1805. </tab>
  1806. </li>
  1807. ';
  1808. return $output;
  1809. }
  1810. // Timezone array
  1811. function timezoneOptions() {
  1812. $output = array();
  1813. $timezones = array();
  1814. $regions = array(
  1815. 'Africa' => DateTimeZone::AFRICA,
  1816. 'America' => DateTimeZone::AMERICA,
  1817. 'Antarctica' => DateTimeZone::ANTARCTICA,
  1818. 'Arctic' => DateTimeZone::ARCTIC,
  1819. 'Asia' => DateTimeZone::ASIA,
  1820. 'Atlantic' => DateTimeZone::ATLANTIC,
  1821. 'Australia' => DateTimeZone::AUSTRALIA,
  1822. 'Europe' => DateTimeZone::EUROPE,
  1823. 'Indian' => DateTimeZone::INDIAN,
  1824. 'Pacific' => DateTimeZone::PACIFIC
  1825. );
  1826. foreach ($regions as $name => $mask) {
  1827. $zones = DateTimeZone::listIdentifiers($mask);
  1828. foreach($zones as $timezone) {
  1829. $time = new DateTime(NULL, new DateTimeZone($timezone));
  1830. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  1831. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  1832. }
  1833. }
  1834. return $output;
  1835. }
  1836. // Build Database
  1837. function createSQLiteDB($path = false) {
  1838. if ($path === false) {
  1839. if (DATABASE_LOCATION){
  1840. $path = DATABASE_LOCATION;
  1841. } else {
  1842. debug_out('No Path Specified!');
  1843. }
  1844. }
  1845. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  1846. if (!isset($GLOBALS['file_db'])) {
  1847. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  1848. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1849. }
  1850. // Create Users
  1851. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  1852. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1853. `username` TEXT UNIQUE,
  1854. `password` TEXT,
  1855. `email` TEXT,
  1856. `token` TEXT,
  1857. `role` TEXT,
  1858. `active` TEXT,
  1859. `last` TEXT,
  1860. `auth_service` TEXT DEFAULT \'internal\'
  1861. );');
  1862. // Create Tabs
  1863. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  1864. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1865. `order` INTEGER,
  1866. `users_id` INTEGER,
  1867. `name` TEXT,
  1868. `url` TEXT,
  1869. `defaultz` TEXT,
  1870. `active` TEXT,
  1871. `user` TEXT,
  1872. `guest` TEXT,
  1873. `icon` TEXT,
  1874. `iconurl` TEXT,
  1875. `window` TEXT
  1876. );');
  1877. // Create Options
  1878. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  1879. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1880. `users_id` INTEGER UNIQUE,
  1881. `title` TEXT UNIQUE,
  1882. `topbar` TEXT,
  1883. `bottombar` TEXT,
  1884. `sidebar` TEXT,
  1885. `hoverbg` TEXT,
  1886. `topbartext` TEXT,
  1887. `activetabBG` TEXT,
  1888. `activetabicon` TEXT,
  1889. `activetabtext` TEXT,
  1890. `inactiveicon` TEXT,
  1891. `inactivetext` TEXT,
  1892. `loading` TEXT,
  1893. `hovertext` TEXT
  1894. );');
  1895. // Create Invites
  1896. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  1897. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1898. `code` TEXT UNIQUE,
  1899. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  1900. `email` TEXT,
  1901. `username` TEXT,
  1902. `dateused` TIMESTAMP,
  1903. `usedby` TEXT,
  1904. `ip` TEXT,
  1905. `valid` TEXT
  1906. );');
  1907. writeLog("success", "database created/saved");
  1908. return $users && $tabs && $options && $invites;
  1909. } else {
  1910. writeLog("error", "database was unable to be created/saved");
  1911. return false;
  1912. }
  1913. }
  1914. // Upgrade Database
  1915. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  1916. if (!$db_path) {
  1917. if (defined('DATABASE_LOCATION')) {
  1918. $db_path = DATABASE_LOCATION;
  1919. } else {
  1920. debug_out('No Path Specified',1);
  1921. }
  1922. }
  1923. if (!isset($GLOBALS['file_db'])) {
  1924. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  1925. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1926. }
  1927. // Cache current DB
  1928. $cache = array();
  1929. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  1930. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  1931. foreach($row as $k => $v) {
  1932. if (is_string($k)) {
  1933. $cache[$table['name']][$key][$k] = $v;
  1934. }
  1935. }
  1936. }
  1937. }
  1938. // Remove Current Database
  1939. $GLOBALS['file_db'] = null;
  1940. $pathDigest = pathinfo($db_path.'users.db');
  1941. if (file_exists($db_path.'users.db')) {
  1942. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  1943. }
  1944. // Create New Database
  1945. $success = createSQLiteDB($db_path);
  1946. // Restore Items
  1947. if ($success) {
  1948. foreach($cache as $table => $tableData) {
  1949. if ($tableData) {
  1950. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  1951. $insertValues = array();
  1952. reset($tableData);
  1953. foreach($tableData as $key => $value) {
  1954. $insertValues[] = '('.implode(',',array_map(function($d) {
  1955. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  1956. }, $value)).')';
  1957. }
  1958. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  1959. }
  1960. }
  1961. writeLog("success", "database values have been updated");
  1962. return true;
  1963. } else {
  1964. writeLog("error", "database values unable to be updated");
  1965. return false;
  1966. }
  1967. }
  1968. // Commit colours to database
  1969. function updateDBOptions($values) {
  1970. if (!isset($GLOBALS['file_db'])) {
  1971. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  1972. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1973. }
  1974. // Commit new values to database
  1975. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  1976. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  1977. }, $values, array_keys($values))).';')->rowCount()) {
  1978. return true;
  1979. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  1980. writeLog("success", "database values for options table have been updated");
  1981. return true;
  1982. } else {
  1983. writeLog("error", "database values for options table unable to be updated");
  1984. return false;
  1985. }
  1986. }
  1987. // Send AJAX notification
  1988. function sendNotification($success, $message = false, $send = true) {
  1989. $notifyExplode = explode("-", NOTIFYEFFECT);
  1990. if ($success) {
  1991. $msg = array(
  1992. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  1993. 'icon' => 'floppy-o',
  1994. 'type' => 'success',
  1995. 'length' => '5000',
  1996. 'layout' => $notifyExplode[0],
  1997. 'effect' => $notifyExplode[1],
  1998. );
  1999. } else {
  2000. $msg = array(
  2001. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2002. 'icon' => 'floppy-o',
  2003. 'type' => 'failed',
  2004. 'length' => '5000',
  2005. 'layout' => $notifyExplode[0],
  2006. 'effect' => $notifyExplode[1],
  2007. );
  2008. }
  2009. // Send and kill script?
  2010. if ($send) {
  2011. header('Content-Type: application/json');
  2012. echo json_encode(array('notify'=>$msg));
  2013. die();
  2014. }
  2015. return $msg;
  2016. }
  2017. // Load colours from the database
  2018. function loadAppearance() {
  2019. // Defaults
  2020. $defaults = array(
  2021. 'title' => 'Organizr',
  2022. 'topbartext' => '#66D9EF',
  2023. 'topbar' => '#333333',
  2024. 'bottombar' => '#333333',
  2025. 'sidebar' => '#393939',
  2026. 'hoverbg' => '#AD80FD',
  2027. 'activetabBG' => '#F92671',
  2028. 'activetabicon' => '#FFFFFF',
  2029. 'activetabtext' => '#FFFFFF',
  2030. 'inactiveicon' => '#66D9EF',
  2031. 'inactivetext' => '#66D9EF',
  2032. 'loading' => '#66D9EF',
  2033. 'hovertext' => '#000000',
  2034. );
  2035. if (DATABASE_LOCATION) {
  2036. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2037. if (!isset($GLOBALS['file_db'])) {
  2038. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2039. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2040. }
  2041. // Database Lookup
  2042. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2043. // Replace defaults with filled options
  2044. foreach($options as $row) {
  2045. foreach($defaults as $key => $value) {
  2046. if (isset($row[$key]) && $row[$key]) {
  2047. $defaults[$key] = $row[$key];
  2048. }
  2049. }
  2050. }
  2051. }
  2052. }
  2053. // Return the Results
  2054. return $defaults;
  2055. }
  2056. // Delete Database
  2057. function deleteDatabase() {
  2058. unset($_COOKIE['Organizr']);
  2059. setcookie('Organizr', '', time() - 3600, '/');
  2060. unset($_COOKIE['OrganizrU']);
  2061. setcookie('OrganizrU', '', time() - 3600, '/');
  2062. $GLOBALS['file_db'] = null;
  2063. unlink(DATABASE_LOCATION.'users.db');
  2064. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2065. if(is_dir($file)) {
  2066. rmdir($file);
  2067. } elseif (!is_dir($file)) {
  2068. unlink($file);
  2069. }
  2070. }
  2071. rmdir($userdirpath);
  2072. writeLog("success", "database has been deleted");
  2073. return true;
  2074. }
  2075. // Upgrade the installation
  2076. function upgradeInstall($branch = 'master') {
  2077. function downloadFile($url, $path){
  2078. ini_set('max_execution_time',0);
  2079. $folderPath = "upgrade/";
  2080. if(!mkdir($folderPath)){
  2081. writeLog("error", "organizr could not create upgrade folder");
  2082. }
  2083. $newfname = $folderPath . $path;
  2084. $file = fopen ($url, 'rb');
  2085. if ($file) {
  2086. $newf = fopen ($newfname, 'wb');
  2087. if ($newf) {
  2088. while(!feof($file)) {
  2089. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2090. }
  2091. }
  2092. }else{
  2093. writeLog("error", "organizr could not download $url");
  2094. }
  2095. if ($file) {
  2096. fclose($file);
  2097. writeLog("success", "organizr finished downloading the github zip file");
  2098. }else{
  2099. writeLog("error", "organizr could not download the github zip file");
  2100. }
  2101. if ($newf) {
  2102. fclose($newf);
  2103. writeLog("success", "organizr created upgrade zip file from github zip file");
  2104. }else{
  2105. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2106. }
  2107. }
  2108. function unzipFile($zipFile){
  2109. $zip = new ZipArchive;
  2110. $extractPath = "upgrade/";
  2111. if($zip->open($extractPath . $zipFile) != "true"){
  2112. writeLog("error", "organizr could not unzip upgrade.zip");
  2113. }else{
  2114. writeLog("success", "organizr unzipped upgrade.zip");
  2115. }
  2116. /* Extract Zip File */
  2117. $zip->extractTo($extractPath);
  2118. $zip->close();
  2119. }
  2120. // Function to remove folders and files
  2121. function rrmdir($dir) {
  2122. if (is_dir($dir)) {
  2123. $files = scandir($dir);
  2124. foreach ($files as $file)
  2125. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2126. rmdir($dir);
  2127. }
  2128. else if (file_exists($dir)) unlink($dir);
  2129. }
  2130. // Function to Copy folders and files
  2131. function rcopy($src, $dst) {
  2132. if (is_dir ( $src )) {
  2133. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2134. $files = scandir ( $src );
  2135. foreach ( $files as $file )
  2136. if ($file != "." && $file != "..")
  2137. rcopy ( "$src/$file", "$dst/$file" );
  2138. } else if (file_exists ( $src ))
  2139. copy ( $src, $dst );
  2140. }
  2141. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2142. $file = "upgrade.zip";
  2143. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2144. $cleanup = __DIR__ . "/upgrade/";
  2145. $destination = __DIR__ . "/";
  2146. writeLog("success", "starting organizr upgrade process");
  2147. downloadFile($url, $file);
  2148. unzipFile($file);
  2149. rcopy($source, $destination);
  2150. writeLog("success", "new organizr files copied");
  2151. rrmdir($cleanup);
  2152. writeLog("success", "organizr upgrade folder removed");
  2153. writeLog("success", "organizr has been updated");
  2154. return true;
  2155. }
  2156. // NzbGET Items
  2157. function nzbgetConnect($list = 'listgroups') {
  2158. $url = qualifyURL(NZBGETURL);
  2159. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2160. $api = json_decode($api, true);
  2161. $gotNZB = array();
  2162. if (is_array($api) || is_object($api)){
  2163. foreach ($api['result'] AS $child) {
  2164. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2165. $downloadStatus = $child['Status'];
  2166. $downloadCategory = $child['Category'];
  2167. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2168. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2169. if($child['Health'] <= "750"){
  2170. $downloadHealth = "danger";
  2171. }elseif($child['Health'] <= "900"){
  2172. $downloadHealth = "warning";
  2173. }elseif($child['Health'] <= "1000"){
  2174. $downloadHealth = "success";
  2175. }
  2176. $gotNZB[] = '<tr>
  2177. <td class="col-xs-7 nzbtable-file-row">'.$downloadName.'</td>
  2178. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2179. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2180. <td class="col-xs-2 nzbtable nzbtable-row">
  2181. <div class="progress">
  2182. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2183. <p class="text-center">'.round($downloadPercent).'%</p>
  2184. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2185. </div>
  2186. </div>
  2187. </td>
  2188. </tr>';
  2189. }
  2190. if ($gotNZB) {
  2191. return implode('',$gotNZB);
  2192. } else {
  2193. return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
  2194. }
  2195. }else{
  2196. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Usernamd and Password - if HTTPS, is cert valid");
  2197. }
  2198. }
  2199. // Sabnzbd Items
  2200. function sabnzbdConnect($list = 'queue') {
  2201. $url = qualifyURL(SABNZBDURL);
  2202. $api = file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2203. $api = json_decode($api, true);
  2204. $gotNZB = array();
  2205. foreach ($api[$list]['slots'] AS $child) {
  2206. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2207. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2208. $downloadStatus = $child['status'];
  2209. $gotNZB[] = '<tr>
  2210. <td>'.$downloadName.'</td>
  2211. <td>'.$downloadStatus.'</td>
  2212. <td>'.$downloadCategory.'</td>
  2213. <td>
  2214. <div class="progress">
  2215. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2216. <p class="text-center">'.round($downloadPercent).'%</p>
  2217. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2218. </div>
  2219. </div>
  2220. </td>
  2221. </tr>';
  2222. }
  2223. if ($gotNZB) {
  2224. return implode('',$gotNZB);
  2225. } else {
  2226. return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
  2227. }
  2228. }
  2229. // Apply new tab settings
  2230. function updateTabs($tabs) {
  2231. if (!isset($GLOBALS['file_db'])) {
  2232. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2233. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2234. }
  2235. // Validate
  2236. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2237. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2238. // Clear Existing Tabs
  2239. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2240. // Process New Tabs
  2241. $totalValid = 0;
  2242. foreach ($tabs['name'] as $key => $value) {
  2243. // Qualify
  2244. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2245. $totalValid++;
  2246. $fields = array();
  2247. foreach(array('id','name','url','icon','iconurl','order') as $v) {
  2248. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2249. }
  2250. foreach(array('active','user','guest','defaultz','window') as $v) {
  2251. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2252. }
  2253. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2254. }
  2255. writeLog("success", "tabs successfully saved");
  2256. return $totalValid;
  2257. } else {
  2258. writeLog("error", "tabs could not save");
  2259. return false;
  2260. }
  2261. writeLog("error", "tabs could not save");
  2262. return false;
  2263. }
  2264. // ==============
  2265. function clean($strin) {
  2266. $strout = null;
  2267. for ($i = 0; $i < strlen($strin); $i++) {
  2268. $ord = ord($strin[$i]);
  2269. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2270. $strout .= "&amp;#{$ord};";
  2271. }
  2272. else {
  2273. switch ($strin[$i]) {
  2274. case '<':
  2275. $strout .= '&lt;';
  2276. break;
  2277. case '>':
  2278. $strout .= '&gt;';
  2279. break;
  2280. case '&':
  2281. $strout .= '&amp;';
  2282. break;
  2283. case '"':
  2284. $strout .= '&quot;';
  2285. break;
  2286. default:
  2287. $strout .= $strin[$i];
  2288. }
  2289. }
  2290. }
  2291. return $strout;
  2292. }
  2293. function registration_callback($username, $email, $userdir){
  2294. global $data;
  2295. $data = array($username, $email, $userdir);
  2296. }
  2297. function printArray($arrayName){
  2298. $messageCount = count($arrayName);
  2299. $i = 0;
  2300. foreach ( $arrayName as $item ) :
  2301. $i++;
  2302. if($i < $messageCount) :
  2303. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2304. elseif($i = $messageCount) :
  2305. echo "<small class='text-uppercase'>" . $item . "</small>";
  2306. endif;
  2307. endforeach;
  2308. }
  2309. function write_ini_file($content, $path) {
  2310. if (!$handle = fopen($path, 'w')) {
  2311. return false;
  2312. }
  2313. $success = fwrite($handle, trim($content));
  2314. fclose($handle);
  2315. return $success;
  2316. }
  2317. function gotTimezone(){
  2318. $regions = array(
  2319. 'Africa' => DateTimeZone::AFRICA,
  2320. 'America' => DateTimeZone::AMERICA,
  2321. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2322. 'Arctic' => DateTimeZone::ARCTIC,
  2323. 'Asia' => DateTimeZone::ASIA,
  2324. 'Atlantic' => DateTimeZone::ATLANTIC,
  2325. 'Australia' => DateTimeZone::AUSTRALIA,
  2326. 'Europe' => DateTimeZone::EUROPE,
  2327. 'Indian' => DateTimeZone::INDIAN,
  2328. 'Pacific' => DateTimeZone::PACIFIC
  2329. );
  2330. $timezones = array();
  2331. foreach ($regions as $name => $mask) {
  2332. $zones = DateTimeZone::listIdentifiers($mask);
  2333. foreach($zones as $timezone) {
  2334. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2335. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2336. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2337. }
  2338. }
  2339. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2340. foreach($timezones as $region => $list) {
  2341. print '<optgroup label="' . $region . '">' . "\n";
  2342. foreach($list as $timezone => $name) {
  2343. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2344. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2345. }
  2346. print '</optgroup>' . "\n";
  2347. }
  2348. print '</select>';
  2349. }
  2350. function getTimezone(){
  2351. $regions = array(
  2352. 'Africa' => DateTimeZone::AFRICA,
  2353. 'America' => DateTimeZone::AMERICA,
  2354. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2355. 'Arctic' => DateTimeZone::ARCTIC,
  2356. 'Asia' => DateTimeZone::ASIA,
  2357. 'Atlantic' => DateTimeZone::ATLANTIC,
  2358. 'Australia' => DateTimeZone::AUSTRALIA,
  2359. 'Europe' => DateTimeZone::EUROPE,
  2360. 'Indian' => DateTimeZone::INDIAN,
  2361. 'Pacific' => DateTimeZone::PACIFIC
  2362. );
  2363. $timezones = array();
  2364. foreach ($regions as $name => $mask) {
  2365. $zones = DateTimeZone::listIdentifiers($mask);
  2366. foreach($zones as $timezone) {
  2367. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2368. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2369. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2370. }
  2371. }
  2372. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2373. foreach($timezones as $region => $list) {
  2374. print '<optgroup label="' . $region . '">' . "\n";
  2375. foreach($list as $timezone => $name) {
  2376. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2377. }
  2378. print '</optgroup>' . "\n";
  2379. }
  2380. print '</select>';
  2381. }
  2382. function explosion($string, $position){
  2383. $getWord = explode("|", $string);
  2384. return $getWord[$position];
  2385. }
  2386. function getServerPath() {
  2387. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2388. $protocol = "https://";
  2389. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2390. $protocol = "https://";
  2391. } else {
  2392. $protocol = "http://";
  2393. }
  2394. $domain = '';
  2395. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2396. $domain = $_SERVER['SERVER_NAME'];
  2397. }elseif(isset($_SERVER['HTTP_HOST'])){
  2398. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2399. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2400. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2401. if ($port == "80" || $port == "443"){
  2402. $domain = $domain;
  2403. }else{
  2404. $domain = $_SERVER['HTTP_HOST'];
  2405. }
  2406. }else{
  2407. $domain = $_SERVER['HTTP_HOST'];
  2408. }
  2409. }
  2410. return $protocol . $domain . dirname($_SERVER['REQUEST_URI']);
  2411. }
  2412. function get_browser_name() {
  2413. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2414. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2415. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2416. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2417. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2418. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2419. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2420. return 'Other';
  2421. }
  2422. function getSickrageCalendarWanted($array){
  2423. $array = json_decode($array, true);
  2424. $gotCalendar = "";
  2425. $i = 0;
  2426. foreach($array['data']['missed'] AS $child) {
  2427. $i++;
  2428. $seriesName = $child['show_name'];
  2429. $episodeID = $child['tvdbid'];
  2430. $episodeAirDate = $child['airdate'];
  2431. $episodeAirDateTime = explode(" ",$child['airs']);
  2432. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2433. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2434. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2435. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2436. $downloaded = "0";
  2437. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2438. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2439. }
  2440. foreach($array['data']['today'] AS $child) {
  2441. $i++;
  2442. $seriesName = $child['show_name'];
  2443. $episodeID = $child['tvdbid'];
  2444. $episodeAirDate = $child['airdate'];
  2445. $episodeAirDateTime = explode(" ",$child['airs']);
  2446. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2447. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2448. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2449. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2450. $downloaded = "0";
  2451. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2452. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2453. }
  2454. foreach($array['data']['soon'] AS $child) {
  2455. $i++;
  2456. $seriesName = $child['show_name'];
  2457. $episodeID = $child['tvdbid'];
  2458. $episodeAirDate = $child['airdate'];
  2459. $episodeAirDateTime = explode(" ",$child['airs']);
  2460. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2461. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2462. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2463. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2464. $downloaded = "0";
  2465. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2466. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2467. }
  2468. foreach($array['data']['later'] AS $child) {
  2469. $i++;
  2470. $seriesName = $child['show_name'];
  2471. $episodeID = $child['tvdbid'];
  2472. $episodeAirDate = $child['airdate'];
  2473. $episodeAirDateTime = explode(" ",$child['airs']);
  2474. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2475. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2476. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2477. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2478. $downloaded = "0";
  2479. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2480. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2481. }
  2482. if ($i != 0){ return $gotCalendar; }
  2483. }
  2484. function getSickrageCalendarHistory($array){
  2485. $array = json_decode($array, true);
  2486. $gotCalendar = "";
  2487. $i = 0;
  2488. foreach($array['data'] AS $child) {
  2489. $i++;
  2490. $seriesName = $child['show_name'];
  2491. $episodeID = $child['tvdbid'];
  2492. $episodeAirDate = $child['date'];
  2493. $downloaded = "green-bg";
  2494. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2495. }
  2496. if ($i != 0){ return $gotCalendar; }
  2497. }
  2498. function getSonarrCalendar($array){
  2499. $array = json_decode($array, true);
  2500. $gotCalendar = "";
  2501. $i = 0;
  2502. foreach($array AS $child) {
  2503. $i++;
  2504. $seriesName = $child['series']['title'];
  2505. $episodeID = $child['series']['tvdbId'];
  2506. if(!isset($episodeID)){ $episodeID = ""; }
  2507. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2508. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2509. $episodeAirDate = $child['airDateUtc'];
  2510. $episodeAirDate = strtotime($episodeAirDate);
  2511. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2512. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2513. $downloaded = $child['hasFile'];
  2514. 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"; }
  2515. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2516. }
  2517. if ($i != 0){ return $gotCalendar; }
  2518. }
  2519. function getRadarrCalendar($array){
  2520. $array = json_decode($array, true);
  2521. $gotCalendar = "";
  2522. $i = 0;
  2523. foreach($array AS $child) {
  2524. if(isset($child['inCinemas'])){
  2525. $i++;
  2526. $movieName = $child['title'];
  2527. $movieID = $child['tmdbId'];
  2528. if(!isset($movieID)){ $movieID = ""; }
  2529. if(isset($child['inCinemas']) && isset($child['physicalRelease'])){
  2530. $physicalRelease = $child['physicalRelease'];
  2531. $physicalRelease = strtotime($physicalRelease);
  2532. $physicalRelease = date("Y-m-d", $physicalRelease);
  2533. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2534. $downloaded = $child['hasFile'];
  2535. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2536. }else{
  2537. $physicalRelease = $child['inCinemas'];
  2538. $downloaded = "light-blue-bg";
  2539. }
  2540. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded movieID--$movieID\", imagetype: \"film\" }, \n";
  2541. }
  2542. }
  2543. if ($i != 0){ return $gotCalendar; }
  2544. }
  2545. function getHeadphonesCalendar($url, $key, $list){
  2546. $url = qualifyURL(HEADPHONESURL);
  2547. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2548. $api = json_decode($api, true);
  2549. $i = 0;
  2550. $gotCalendar = "";
  2551. if (is_array($api) || is_object($api)){
  2552. foreach($api AS $child) {
  2553. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2554. $i++;
  2555. $albumName = addslashes($child['AlbumTitle']);
  2556. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2557. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2558. $albumID = $child['AlbumID'];
  2559. $albumDate = strtotime($albumDate);
  2560. $albumDate = date("Y-m-d", $albumDate);
  2561. $albumStatus = $child['Status'];
  2562. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2563. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2564. $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2565. }
  2566. if($child['Status'] == "Processed" && $list == "getHistory"){
  2567. $i++;
  2568. $find = array('_','[', ']', '\n');
  2569. $replace = array(' ','(', ')', ' ');
  2570. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  2571. $albumDate = $child['DateAdded'];
  2572. $albumID = $child['AlbumID'];
  2573. $albumDate = strtotime($albumDate);
  2574. $albumDate = date("Y-m-d", $albumDate);
  2575. $albumStatusColor = "green-bg";
  2576. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2577. $gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2578. }
  2579. }
  2580. if ($i != 0){ return $gotCalendar; }
  2581. }else{
  2582. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2583. }
  2584. }
  2585. function checkRootPath($string){
  2586. if($string == "\\" || $string == "/"){
  2587. return "/";
  2588. }else{
  2589. return str_replace("\\", "/", $string) . "/";
  2590. }
  2591. }
  2592. function strip($string){
  2593. $string = strip_tags($string);
  2594. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  2595. }
  2596. function writeLog($type, $message){
  2597. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  2598. file_put_contents("org.log", $message, FILE_APPEND | LOCK_EX);
  2599. }
  2600. function readLog(){
  2601. $log = file("org.log");
  2602. $log = array_reverse($log);
  2603. foreach($log as $line){
  2604. $line = explode("|", strip($line));
  2605. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  2606. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  2607. }
  2608. }
  2609. function buildStream($array){
  2610. $result = "";
  2611. if (array_key_exists('platform', $array)) {
  2612. $result .= '<div class="reg-info" style="margin-top:0; padding-left:0; position: absolute; bottom: 10px; left: 10px;"><div style="margin-right: 0;" class="item pull-left text-center"><img alt="'.$array['platform'].'" class="img-circle" height="55px" src="images/platforms/'.getPlatform($array['platform']).'"></div></div><div class="clearfix"></div>';
  2613. }
  2614. if (array_key_exists('device', $array)) {
  2615. $result .= '<div class="reg-info" style="margin-top:0; padding-left:5%;"><div style="margin-right: 0;" class="item pull-left text-center"><span style="font-size: 15px;" class="block text-center"><i class="fa fa-laptop"></i>'.$array['device'].'</span></div></div><div class="clearfix"></div>';
  2616. }
  2617. if (array_key_exists('stream', $array)) {
  2618. $result .= '<div class="reg-info" style="margin-top:0; padding-left:5%;"><div style="margin-right: 0;" class="item pull-left text-center"><span style="font-size: 15px;" class="block text-center"><i class="fa fa-play"></i>'.$array['stream'].'</span></div></div><div class="clearfix"></div>';
  2619. }
  2620. if (array_key_exists('video', $array)) {
  2621. $result .= '<div class="reg-info" style="margin-top:0; padding-left:5%;"><div style="margin-right: 0;" class="item pull-left text-center"><span style="font-size: 15px;" class="block text-center"><i class="fa fa-film"></i>'.$array['video'].'</span></div></div><div class="clearfix"></div>';
  2622. }
  2623. if (array_key_exists('audio', $array)) {
  2624. $result .= '<div class="reg-info" style="margin-top:0; padding-left:5%;"><div style="margin-right: 0;" class="item pull-left text-center"><span style="font-size: 15px;" class="block text-center"><i class="fa fa-volume-up"></i>'.$array['audio'].'</span></div></div><div class="clearfix"></div>';
  2625. }
  2626. return $result;
  2627. }
  2628. function streamType($value){
  2629. if($value == "transcode" || $value == "Transcode"){
  2630. return "Transcode";
  2631. }elseif($value == "copy" || $value == "DirectStream"){
  2632. return "Direct Stream";
  2633. }elseif($value == "directplay" || $value == "DirectPlay"){
  2634. return "Direct Play";
  2635. }else{
  2636. return "Direct Play";
  2637. }
  2638. }
  2639. function getPlatform($platform){
  2640. $allPlatforms = array(
  2641. "Chrome" => "chrome.png",
  2642. "tvOS" => "atv.png",
  2643. "iOS" => "ios.png",
  2644. "Xbox One" => "xbox.png",
  2645. "Mystery 4" => "playstation.png",
  2646. "Samsung" => "samsung.png",
  2647. "Roku" => "roku.png",
  2648. "Emby for iOS" => "ios.png",
  2649. "Emby Mobile" => "emby.png",
  2650. "Emby Theater" => "emby.png",
  2651. "Emby Classic" => "emby.png",
  2652. "Safari" => "safari.png",
  2653. "Android" => "android.png",
  2654. "AndroidTv" => "android.png",
  2655. "Chromecast" => "chromecast.png",
  2656. "Dashboard" => "emby.png",
  2657. "Dlna" => "dlna.png",
  2658. "Windows Phone" => "wp.png",
  2659. "Windows RT" => "win8.png",
  2660. "Kodi" => "kodi.png",
  2661. );
  2662. if (array_key_exists($platform, $allPlatforms)) {
  2663. return $allPlatforms[$platform];
  2664. }else{
  2665. return "pmp.png";
  2666. }
  2667. }
  2668. function getServer(){
  2669. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  2670. return $server;
  2671. }
  2672. function prettyPrint($array) {
  2673. echo "<pre>";
  2674. print_r($array);
  2675. echo "</pre>";
  2676. echo "<br/>";
  2677. }
  2678. function checkFrame($array, $url){
  2679. if(array_key_exists("x-frame-options", $array)){
  2680. if($array['x-frame-options'] == "deny"){
  2681. return false;
  2682. }elseif($array['x-frame-options'] == "sameorgin"){
  2683. $digest = parse_url($url);
  2684. $host = (isset($digest['host'])?$digest['host']:'');
  2685. if(getServer() == $host){
  2686. return true;
  2687. }else{
  2688. return false;
  2689. }
  2690. }
  2691. }else{
  2692. if(!$array){
  2693. return false;
  2694. }
  2695. return true;
  2696. }
  2697. }
  2698. function frameTest($url){
  2699. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  2700. $url = qualifyURL($url);
  2701. if(checkFrame($array, $url)){
  2702. return true;
  2703. }else{
  2704. return false;
  2705. }
  2706. }
  2707. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  2708. $notifyExplode = explode("-", NOTIFYEFFECT);
  2709. if ($result) {
  2710. $msg = array(
  2711. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  2712. 'icon' => $icon,
  2713. 'type' => 'success',
  2714. 'length' => '5000',
  2715. 'layout' => $notifyExplode[0],
  2716. 'effect' => $notifyExplode[1],
  2717. );
  2718. } else {
  2719. $msg = array(
  2720. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  2721. 'icon' => $icon,
  2722. 'type' => 'error',
  2723. 'length' => '5000',
  2724. 'layout' => $notifyExplode[0],
  2725. 'effect' => $notifyExplode[1],
  2726. );
  2727. }
  2728. // Send and kill script?
  2729. if ($send) {
  2730. header('Content-Type: application/json');
  2731. echo json_encode(array('notify'=>$msg));
  2732. die();
  2733. }
  2734. return $msg;
  2735. }
  2736. function buildHomepageNotice($layout, $type, $title, $message){
  2737. switch ($layout) {
  2738. case 'elegant':
  2739. return '
  2740. <div id="homepageNotice" class="row">
  2741. <div class="col-lg-12">
  2742. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  2743. <div class="content-title i-block">
  2744. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  2745. <div class="content-tools i-block pull-right">
  2746. <a class="close-btn">
  2747. <i class="fa fa-times"></i>
  2748. </a>
  2749. </div>
  2750. </div>
  2751. '.$message.'
  2752. </div>
  2753. </div>
  2754. </div>
  2755. ';
  2756. break;
  2757. case 'basic':
  2758. return '
  2759. <div id="homepageNotice" class="row">
  2760. <div class="col-lg-12">
  2761. <div class="panel panel-'.$type.'">
  2762. <div class="panel-heading">
  2763. <h3 class="panel-title">'.$title.'</h3>
  2764. </div>
  2765. <div class="panel-body">
  2766. '.$message.'
  2767. </div>
  2768. </div>
  2769. </div>
  2770. </div>
  2771. ';
  2772. break;
  2773. case 'jumbotron';
  2774. return '
  2775. <div id="homepageNotice" class="row">
  2776. <div class="col-lg-12">
  2777. <div class="jumbotron">
  2778. <div class="container">
  2779. <h1>'.$title.'</h1>
  2780. <p>'.$message.'</p>
  2781. </div>
  2782. </div>
  2783. </div>
  2784. </div>
  2785. ';
  2786. }
  2787. }
  2788. function embyArray($array, $type) {
  2789. $key = ($type == "video" ? "Height" : "Channels");
  2790. if (array_key_exists($key, $array)) {
  2791. switch ($type) {
  2792. case "video":
  2793. $codec = $array["Codec"];
  2794. $height = $array["Height"];
  2795. $width = $array["Width"];
  2796. break;
  2797. default:
  2798. $codec = $array["Codec"];
  2799. $channels = $array["Channels"];
  2800. }
  2801. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  2802. }
  2803. foreach ($array as $element) {
  2804. if (is_array($element)) {
  2805. if (embyArray($element, $type)) {
  2806. return embyArray($element, $type);
  2807. }
  2808. }
  2809. }
  2810. }
  2811. // Get Now Playing Streams From Plex
  2812. function searchPlex($query){
  2813. $address = qualifyURL(PLEXURL);
  2814. $openTab = (PLEXTABNAME) ? "true" : "false";
  2815. // Perform API requests
  2816. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  2817. $api = simplexml_load_string($api);
  2818. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  2819. if (!$getServer) { return 'Could not load!'; }
  2820. // Identify the local machine
  2821. $server = $getServer['machineIdentifier'];
  2822. $pre = "<table class=\"table table-hover table-stripped\"><thead><tr><th>Cover</th><th>Title</th><th>Genre</th><th>Year</th><th>Type</th><th>Added</th><th>Extra Info</th></tr></thead><tbody>";
  2823. $items = "";
  2824. $albums = $movies = $shows = 0;
  2825. $style = 'style="vertical-align: middle"';
  2826. foreach($api AS $child) {
  2827. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  2828. $time = (string)$child['addedAt'];
  2829. $time = new DateTime("@$time");
  2830. $results = array(
  2831. "title" => (string)$child['title'],
  2832. "image" => (string)$child['thumb'],
  2833. "type" => (string)ucwords($child['type']),
  2834. "year" => (string)$child['year'],
  2835. "key" => (string)$child['ratingKey']."-search",
  2836. "ratingkey" => (string)$child['ratingKey'],
  2837. "genre" => (string)$child->Genre['tag'],
  2838. "added" => $time->format('Y-m-d'),
  2839. "extra" => "",
  2840. );
  2841. switch ($child['type']){
  2842. case "album":
  2843. $push = array(
  2844. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  2845. );
  2846. $results = array_replace($results,$push);
  2847. $albums++;
  2848. break;
  2849. case "movie":
  2850. $push = array(
  2851. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  2852. );
  2853. $results = array_replace($results,$push);
  2854. $movies++;
  2855. break;
  2856. case "show":
  2857. $push = array(
  2858. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  2859. );
  2860. $results = array_replace($results,$push);
  2861. $shows++;
  2862. break;
  2863. }
  2864. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  2865. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  2866. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  2867. }
  2868. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  2869. if (substr_count(PLEXURL, '.') != 2) {
  2870. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  2871. }else{
  2872. $link = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  2873. }
  2874. $items .= '<tr style="cursor: pointer;" class="openTab" openTab="'.$openTab.'" href="'.$link.'">
  2875. <th scope="row"><img src="'.$image_url.'"></th>
  2876. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  2877. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  2878. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  2879. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  2880. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  2881. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  2882. </tr>';
  2883. }
  2884. }
  2885. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  2886. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  2887. font-size: 23px;
  2888. ">&nbsp;'.$movies.'</strong></span>
  2889. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  2890. font-size: 23px;
  2891. ">&nbsp;'.$shows.'</strong></span>
  2892. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  2893. font-size: 23px;
  2894. ">&nbsp;'.$albums.'</strong></span>
  2895. </div>';
  2896. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  2897. }
  2898. function getBannedUsers($string){
  2899. if (strpos($string, ',') !== false) {
  2900. $banned = explode(",", $string);
  2901. }else{
  2902. $banned = array($string);
  2903. }
  2904. return $banned;
  2905. }
  2906. function getWhitelist($string){
  2907. if (strpos($string, ',') !== false) {
  2908. $whitelist = explode(",", $string);
  2909. }else{
  2910. $whitelist = array($string);
  2911. }
  2912. foreach($whitelist as &$ip){
  2913. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  2914. }
  2915. return $whitelist;
  2916. }
  2917. function get_client_ip() {
  2918. $ipaddress = '';
  2919. if (isset($_SERVER['HTTP_CLIENT_IP']))
  2920. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  2921. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  2922. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  2923. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  2924. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  2925. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  2926. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  2927. else if(isset($_SERVER['HTTP_FORWARDED']))
  2928. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  2929. else if(isset($_SERVER['REMOTE_ADDR']))
  2930. $ipaddress = $_SERVER['REMOTE_ADDR'];
  2931. else
  2932. $ipaddress = 'UNKNOWN';
  2933. return $ipaddress;
  2934. }
  2935. //EMAIL SHIT
  2936. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
  2937. $mail = new PHPMailer;
  2938. $mail->isSMTP();
  2939. $mail->Host = SMTPHOST;
  2940. $mail->SMTPAuth = SMTPHOSTAUTH;
  2941. $mail->Username = SMTPHOSTUSERNAME;
  2942. $mail->Password = SMTPHOSTPASSWORD;
  2943. $mail->SMTPSecure = SMTPHOSTTYPE;
  2944. $mail->Port = SMTPHOSTPORT;
  2945. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  2946. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  2947. $mail->isHTML(true);
  2948. $mail->addAddress($email, $username);
  2949. $mail->Subject = $subject;
  2950. $mail->Body = $body;
  2951. //$mail->send();
  2952. if(!$mail->send()) {
  2953. writeLog("error", "mail failed to send");
  2954. } else {
  2955. writeLog("success", "mail has been sent");
  2956. }
  2957. }
  2958. //EMAIL SHIT
  2959. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  2960. $mail = new PHPMailer;
  2961. $mail->isSMTP();
  2962. $mail->Host = $host;
  2963. $mail->SMTPAuth = $auth;
  2964. $mail->Username = $username;
  2965. $mail->Password = $password;
  2966. $mail->SMTPSecure = $type;
  2967. $mail->Port = $port;
  2968. $mail->setFrom($from, $sendername);
  2969. $mail->addReplyTo($from, $sendername);
  2970. $mail->isHTML(true);
  2971. $mail->addAddress($to, "Organizr Admin");
  2972. $mail->Subject = "Organizr Test E-Mail";
  2973. $mail->Body = "This was just a test!";
  2974. //$mail->send();
  2975. if(!$mail->send()) {
  2976. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  2977. return false;
  2978. } else {
  2979. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  2980. return true;
  2981. }
  2982. }
  2983. function libraryList(){
  2984. $address = qualifyURL(PLEXURL);
  2985. $headers = array(
  2986. "Accept" => "application/json",
  2987. "X-Plex-Token" => PLEXTOKEN
  2988. );
  2989. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  2990. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  2991. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  2992. $libraryList = array();
  2993. foreach($api->SharedServer->Section AS $child) {
  2994. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  2995. }
  2996. foreach($api->SharedServer AS $child) {
  2997. if(!empty($child['username'])){
  2998. $username = (string)strtolower($child['username']);
  2999. $email = (string)strtolower($child['email']);
  3000. $libraryList['users'][$username] = (string)$child['id'];
  3001. $libraryList['emails'][$email] = (string)$child['id'];
  3002. }
  3003. }
  3004. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3005. }
  3006. function plexUserShare($username){
  3007. $address = qualifyURL(PLEXURL);
  3008. $headers = array(
  3009. "Accept" => "application/json",
  3010. "Content-Type" => "application/json",
  3011. "X-Plex-Token" => PLEXTOKEN
  3012. );
  3013. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3014. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3015. $json = array(
  3016. "server_id" => $gotServer,
  3017. "shared_server" => array(
  3018. //"library_section_ids" => "[26527637]",
  3019. "invited_email" => $username
  3020. )
  3021. );
  3022. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3023. switch ($api['http_code']['http_code']){
  3024. case 400:
  3025. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3026. $result = "$username already has access to the shared libraries";
  3027. break;
  3028. case 401:
  3029. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3030. $result = "Invalid Plex Token";
  3031. break;
  3032. case 200:
  3033. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3034. $result = "$username now has access to your Plex Library";
  3035. break;
  3036. default:
  3037. writeLog("error", "PLEX INVITE: unknown error");
  3038. $result = false;
  3039. }
  3040. return (!empty($result) ? $result : null );
  3041. }
  3042. function plexUserDelete($username){
  3043. $address = qualifyURL(PLEXURL);
  3044. $headers = array(
  3045. "Accept" => "application/json",
  3046. "Content-Type" => "application/json",
  3047. "X-Plex-Token" => PLEXTOKEN
  3048. );
  3049. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3050. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3051. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3052. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3053. switch ($api['http_code']['http_code']){
  3054. case 401:
  3055. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3056. $result = "Invalid Plex Token";
  3057. break;
  3058. case 200:
  3059. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3060. $result = "$username doesn't have access to your Plex Library anymore";
  3061. break;
  3062. default:
  3063. writeLog("error", "PLEX INVITE: unknown error");
  3064. $result = false;
  3065. }
  3066. return (!empty($result) ? $result : null );
  3067. }
  3068. function convertPlexName($user, $type){
  3069. $array = libraryList();
  3070. switch ($type){
  3071. case "username":
  3072. $plexUser = array_search ($user, $array['users']);
  3073. break;
  3074. case "id":
  3075. if (array_key_exists(strtolower($user), $array['users'])) {
  3076. $plexUser = $array['users'][strtolower($user)];
  3077. }
  3078. break;
  3079. default:
  3080. $plexUser = false;
  3081. }
  3082. return (!empty($plexUser) ? $plexUser : null );
  3083. }
  3084. function randomCode($length = 5, $type = null) {
  3085. switch ($type){
  3086. case "alpha":
  3087. $legend = array_merge(range('A', 'Z'));
  3088. break;
  3089. case "numeric":
  3090. $legend = array_merge(range(0,9));
  3091. break;
  3092. default:
  3093. $legend = array_merge(range(0,9),range('A', 'Z'));
  3094. }
  3095. $code = "";
  3096. for($i=0; $i < $length; $i++) {
  3097. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3098. }
  3099. return $code;
  3100. }
  3101. function inviteCodes($action, $code = null, $usedBy = null) {
  3102. if (!isset($GLOBALS['file_db'])) {
  3103. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3104. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3105. }
  3106. $now = date("Y-m-d H:i:s");
  3107. switch ($action) {
  3108. case "get":
  3109. // Start Array
  3110. $result = array();
  3111. // Database Lookup
  3112. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3113. // Get Codes
  3114. foreach($invites as $row) {
  3115. array_push($result, $row['code']);
  3116. }
  3117. // Return the Results
  3118. return (!empty($result) ? $result : false );
  3119. break;
  3120. case "check":
  3121. // Start Array
  3122. $result = array();
  3123. // Database Lookup
  3124. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3125. // Get Codes
  3126. foreach($invites as $row) {
  3127. $result = $row['code'];
  3128. }
  3129. // Return the Results
  3130. return (!empty($result) ? $result : false );
  3131. break;
  3132. case "use":
  3133. $currentIP = get_client_ip();
  3134. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3135. return (!empty($invites) ? true : false );
  3136. break;
  3137. }
  3138. }
  3139. function plexJoin($username, $email, $password){
  3140. $connectURL = 'https://plex.tv/users.json';
  3141. $headers = array(
  3142. 'Accept'=> 'application/json',
  3143. 'Content-Type' => 'application/x-www-form-urlencoded',
  3144. 'X-Plex-Product' => 'Organizr',
  3145. 'X-Plex-Version' => '1.0',
  3146. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3147. );
  3148. $body = array(
  3149. 'user[email]' => $email,
  3150. 'user[username]' => $username,
  3151. 'user[password]' => $password,
  3152. );
  3153. $api = curl_post($connectURL, $body, $headers);
  3154. $json = json_decode($api['content'], true);
  3155. $errors = (!empty($json['errors']) ? true : false);
  3156. $success = (!empty($json['user']) ? true : false);
  3157. //Use This for later
  3158. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3159. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3160. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3161. switch ($api['http_code']['http_code']){
  3162. case 400:
  3163. writeLog("error", "PLEX JOIN: $username already has access to the shared libraries");
  3164. break;
  3165. case 401:
  3166. writeLog("error", "PLEX JOIN: invalid Plex Token");
  3167. break;
  3168. case 422:
  3169. writeLog("error", "PLEX JOIN: user info error");
  3170. break;
  3171. case 429:
  3172. writeLog("error", "PLEX JOIN: too many requests to plex.tv please try later");
  3173. break;
  3174. case 200:
  3175. case 201:
  3176. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3177. break;
  3178. default:
  3179. writeLog("error", "PLEX JOIN: unknown error, Error: ".$api['http_code']['http_code']);
  3180. }
  3181. //prettyPrint($api);
  3182. //prettyPrint(json_decode($api['content'], true));
  3183. return (!empty($success) && empty($errors) ? true : false );
  3184. }
  3185. function getCert(){
  3186. $url = "http://curl.haxx.se/ca/cacert.pem";
  3187. $file = getcwd()."/config/cacert.pem";
  3188. $directory = getcwd()."/config/";
  3189. @mkdir($directory, 0770, true);
  3190. if(!file_exists($file)){
  3191. file_put_contents( $file, fopen($url, 'r'));
  3192. writeLog("success", "CERT PEM: pem file created");
  3193. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3194. writeLog("success", "CERT PEM: downloaded new pem file");
  3195. }
  3196. return $file;
  3197. }
  3198. function customCSS(){
  3199. if(CUSTOMCSS == "true") {
  3200. $template_file = "custom.css";
  3201. $file_handle = fopen($template_file, "rb");
  3202. echo "\n";
  3203. echo fread($file_handle, filesize($template_file));
  3204. fclose($file_handle);
  3205. echo "\n";
  3206. }
  3207. }
  3208. function tvdbToken(){
  3209. $headers = array(
  3210. "Accept" => "application/json",
  3211. "Content-Type" => "application/json"
  3212. );
  3213. $json = array(
  3214. "apikey" => "FBE7B62621F4CAD7",
  3215. "userkey" => "328BB46EB1E9A0F5",
  3216. "username" => "causefx"
  3217. );
  3218. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3219. return json_decode($api['content'], true)['token'];
  3220. }
  3221. function tvdbGet($id){
  3222. $headers = array(
  3223. "Accept" => "application/json",
  3224. "Authorization" => "Bearer ".tvdbToken(),
  3225. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3226. "trakt-api-version" => "2"
  3227. );
  3228. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3229. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3230. if(empty($api['trakt'])){
  3231. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3232. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3233. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3234. $api['series'] = json_decode($series, true)['data'];
  3235. $api['poster'] = json_decode($poster, true)['data'];
  3236. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3237. }
  3238. return $api;
  3239. }
  3240. function getPlexPlaylists(){
  3241. $address = qualifyURL(PLEXURL);
  3242. // Perform API requests
  3243. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3244. $api = simplexml_load_string($api);
  3245. if (is_array($api) || is_object($api)){
  3246. if (!$api->head->title){
  3247. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3248. if (!$getServer) { return 'Could not load!'; }
  3249. // Identify the local machine
  3250. $gotServer = $getServer['machineIdentifier'];
  3251. $output = "";
  3252. $hideMenu = '<div class="pull-right"><div class="btn-group" role="group"><button type="button" id="playlist-Name" class="btn waves btn-default btn-sm dropdown-toggle waves-effect waves-float" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Choose A Playlist &nbsp;<span class="caret"></span></button><ul style="right:0; left: auto" class="dropdown-menu filter-recent-playlist">';
  3253. foreach($api AS $child) {
  3254. $items = "";
  3255. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3256. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3257. $api = simplexml_load_string($api);
  3258. if (is_array($api) || is_object($api)){
  3259. if (!$api->head->title){
  3260. $className = preg_replace("/(\W)+/", "", $api['title']);
  3261. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3262. foreach($api->Video AS $child){
  3263. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3264. }
  3265. if (count($items)) {
  3266. $output .= ''.implode('',$items).'';
  3267. }
  3268. }
  3269. }
  3270. }
  3271. }
  3272. $hideMenu .= '</ul></div></div>';
  3273. return '<div id="playlist-all" class="content-box box-shadow big-box"><h5 id="playlist-title" style="margin-bottom: -20px" class="text-center">All Playlists</h5><div class="recentHeader inbox-pagination all">'.$hideMenu.'</div><br/><br/><div class="recentItems-playlists" data-name="all">'.$output.'</div></div>';
  3274. }else{
  3275. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3276. }
  3277. }else{
  3278. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3279. }
  3280. }
  3281. function readExternalLog($type,$filename,$name = null){
  3282. $log = file($filename);
  3283. $log = array_reverse($log);
  3284. foreach($log as $line){
  3285. if(!empty($line) && $line[0] != " "){
  3286. $line = strip($line);
  3287. if($type == "single"){
  3288. if( strpos( strtolower($line), "ror" ) !== false ) {
  3289. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3290. }else{
  3291. echo "<tr><td>".$line."</td></tr>";
  3292. }
  3293. }elseif($type == "all"){
  3294. if( strpos( strtolower($line), "ror" ) !== false ) {
  3295. echo "<tr><td class='red-bg'>".$name."</td>";
  3296. echo "<td class='red-bg'>".$line."</td></tr>";
  3297. }else{
  3298. echo "<tr><td>".$name."</td>";
  3299. echo "<td>".$line."</td></tr>";
  3300. }
  3301. }
  3302. }
  3303. }
  3304. }
  3305. function getLogs(){
  3306. $path = __DIR__ ."/logs/";
  3307. @mkdir($path, 0770, true);
  3308. $logs = array();
  3309. $files = array_diff(scandir($path), array('.', '..'));
  3310. foreach($files as $v){
  3311. $title = explode(".", $v)[0];
  3312. $logs[$title] = $path.$v;
  3313. }
  3314. return $logs;
  3315. }
  3316. function getExtension($string) {
  3317. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3318. }
  3319. function showFile(){
  3320. $file = $_GET['file'];
  3321. $fileType = getExtension($file);
  3322. if($fileType != 'php' && strpos( strtolower($file), "http" ) !== false ){
  3323. header("Content-type: ".mimeTypes()[$fileType]);
  3324. @readfile($file);
  3325. }
  3326. }
  3327. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  3328. $path = getServerPath();
  3329. return '
  3330. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3331. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  3332. <head>
  3333. <!--[if gte mso 9]><xml>
  3334. <o:OfficeDocumentSettings>
  3335. <o:AllowPNG/>
  3336. <o:PixelsPerInch>96</o:PixelsPerInch>
  3337. </o:OfficeDocumentSettings>
  3338. </xml><![endif]-->
  3339. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3340. <meta name="viewport" content="width=device-width">
  3341. <!--[if !mso]><!-->
  3342. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  3343. <!--<![endif]-->
  3344. <title></title>
  3345. <!--[if !mso]><!-- -->
  3346. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  3347. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  3348. <!--<![endif]-->
  3349. <style type="text/css" id="media-query">
  3350. body {
  3351. margin: 0;
  3352. padding: 0;
  3353. }
  3354. table,
  3355. tr,
  3356. td {
  3357. vertical-align: top;
  3358. border-collapse: collapse;
  3359. }
  3360. .ie-browser table,
  3361. .mso-container table {
  3362. table-layout: fixed;
  3363. }
  3364. * {
  3365. line-height: inherit;
  3366. }
  3367. a[x-apple-data-detectors=true] {
  3368. color: inherit !important;
  3369. text-decoration: none !important;
  3370. }
  3371. [owa] .img-container div,
  3372. [owa] .img-container button {
  3373. display: block !important;
  3374. }
  3375. [owa] .fullwidth button {
  3376. width: 100% !important;
  3377. }
  3378. [owa] .block-grid .col {
  3379. display: table-cell;
  3380. float: none !important;
  3381. vertical-align: top;
  3382. }
  3383. .ie-browser .num12,
  3384. .ie-browser .block-grid,
  3385. [owa] .num12,
  3386. [owa] .block-grid {
  3387. width: 615px !important;
  3388. }
  3389. .ExternalClass,
  3390. .ExternalClass p,
  3391. .ExternalClass span,
  3392. .ExternalClass font,
  3393. .ExternalClass td,
  3394. .ExternalClass div {
  3395. line-height: 100%;
  3396. }
  3397. .ie-browser .mixed-two-up .num4,
  3398. [owa] .mixed-two-up .num4 {
  3399. width: 204px !important;
  3400. }
  3401. .ie-browser .mixed-two-up .num8,
  3402. [owa] .mixed-two-up .num8 {
  3403. width: 408px !important;
  3404. }
  3405. .ie-browser .block-grid.two-up .col,
  3406. [owa] .block-grid.two-up .col {
  3407. width: 307px !important;
  3408. }
  3409. .ie-browser .block-grid.three-up .col,
  3410. [owa] .block-grid.three-up .col {
  3411. width: 205px !important;
  3412. }
  3413. .ie-browser .block-grid.four-up .col,
  3414. [owa] .block-grid.four-up .col {
  3415. width: 153px !important;
  3416. }
  3417. .ie-browser .block-grid.five-up .col,
  3418. [owa] .block-grid.five-up .col {
  3419. width: 123px !important;
  3420. }
  3421. .ie-browser .block-grid.six-up .col,
  3422. [owa] .block-grid.six-up .col {
  3423. width: 102px !important;
  3424. }
  3425. .ie-browser .block-grid.seven-up .col,
  3426. [owa] .block-grid.seven-up .col {
  3427. width: 87px !important;
  3428. }
  3429. .ie-browser .block-grid.eight-up .col,
  3430. [owa] .block-grid.eight-up .col {
  3431. width: 76px !important;
  3432. }
  3433. .ie-browser .block-grid.nine-up .col,
  3434. [owa] .block-grid.nine-up .col {
  3435. width: 68px !important;
  3436. }
  3437. .ie-browser .block-grid.ten-up .col,
  3438. [owa] .block-grid.ten-up .col {
  3439. width: 61px !important;
  3440. }
  3441. .ie-browser .block-grid.eleven-up .col,
  3442. [owa] .block-grid.eleven-up .col {
  3443. width: 55px !important;
  3444. }
  3445. .ie-browser .block-grid.twelve-up .col,
  3446. [owa] .block-grid.twelve-up .col {
  3447. width: 51px !important;
  3448. }
  3449. @media only screen and (min-width: 635px) {
  3450. .block-grid {
  3451. width: 615px !important;
  3452. }
  3453. .block-grid .col {
  3454. display: table-cell;
  3455. Float: none !important;
  3456. vertical-align: top;
  3457. }
  3458. .block-grid .col.num12 {
  3459. width: 615px !important;
  3460. }
  3461. .block-grid.mixed-two-up .col.num4 {
  3462. width: 204px !important;
  3463. }
  3464. .block-grid.mixed-two-up .col.num8 {
  3465. width: 408px !important;
  3466. }
  3467. .block-grid.two-up .col {
  3468. width: 307px !important;
  3469. }
  3470. .block-grid.three-up .col {
  3471. width: 205px !important;
  3472. }
  3473. .block-grid.four-up .col {
  3474. width: 153px !important;
  3475. }
  3476. .block-grid.five-up .col {
  3477. width: 123px !important;
  3478. }
  3479. .block-grid.six-up .col {
  3480. width: 102px !important;
  3481. }
  3482. .block-grid.seven-up .col {
  3483. width: 87px !important;
  3484. }
  3485. .block-grid.eight-up .col {
  3486. width: 76px !important;
  3487. }
  3488. .block-grid.nine-up .col {
  3489. width: 68px !important;
  3490. }
  3491. .block-grid.ten-up .col {
  3492. width: 61px !important;
  3493. }
  3494. .block-grid.eleven-up .col {
  3495. width: 55px !important;
  3496. }
  3497. .block-grid.twelve-up .col {
  3498. width: 51px !important;
  3499. }
  3500. }
  3501. @media (max-width: 635px) {
  3502. .block-grid,
  3503. .col {
  3504. min-width: 320px !important;
  3505. max-width: 100% !important;
  3506. }
  3507. .block-grid {
  3508. width: calc(100% - 40px) !important;
  3509. }
  3510. .col {
  3511. width: 100% !important;
  3512. }
  3513. .col>div {
  3514. margin: 0 auto;
  3515. }
  3516. img.fullwidth {
  3517. max-width: 100% !important;
  3518. }
  3519. }
  3520. </style>
  3521. </head>
  3522. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  3523. <!--[if IE]><div class="ie-browser"><![endif]-->
  3524. <!--[if mso]><div class="mso-container"><![endif]-->
  3525. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  3526. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  3527. <div style="background-color:#333333;">
  3528. <div style="Margin: 0 auto;min-width: 320px;max-width: 615px;width: 615px;width: calc(30500% - 193060px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;"
  3529. class="block-grid ">
  3530. <div style="border-collapse: collapse;display: table;width: 100%;">
  3531. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#333333;" align="center"><table cellpadding="0" cellspacing="0" border="0" style="width: 615px;"><tr class="layout-full-width" style="background-color:transparent;"><![endif]-->
  3532. <!--[if (mso)|(IE)]><td align="center" width="615" style=" width:615px; padding-right: 0px; padding-left: 0px; padding-top:0px; padding-bottom:0px; border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent;" valign="top"><![endif]-->
  3533. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3534. <div style="background-color: transparent; width: 100% !important;">
  3535. <!--[if (!mso)&(!IE)]><!-->
  3536. <div style="border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent; padding-top:0px; padding-bottom:0px; padding-right: 0px; padding-left: 0px;">
  3537. <!--<![endif]-->
  3538. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  3539. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  3540. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  3541. style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: 0;height: auto;float: none;width: 100%;max-width: 555px"
  3542. width="555">
  3543. <!--[if mso]></td></tr></table><![endif]-->
  3544. </div>
  3545. <!--[if (!mso)&(!IE)]><!-->
  3546. </div>
  3547. <!--<![endif]-->
  3548. </div>
  3549. </div>
  3550. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3551. </div>
  3552. </div>
  3553. </div>
  3554. <div style="background-color:#333333;">
  3555. <div style="Margin: 0 auto;min-width: 320px;max-width: 615px;width: 615px;width: calc(30500% - 193060px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;"
  3556. class="block-grid ">
  3557. <div style="border-collapse: collapse;display: table;width: 100%;">
  3558. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#333333;" align="center"><table cellpadding="0" cellspacing="0" border="0" style="width: 615px;"><tr class="layout-full-width" style="background-color:transparent;"><![endif]-->
  3559. <!--[if (mso)|(IE)]><td align="center" width="615" style=" width:615px; padding-right: 0px; padding-left: 0px; padding-top:0px; padding-bottom:0px; border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent;" valign="top"><![endif]-->
  3560. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3561. <div style="background-color: transparent; width: 100% !important;">
  3562. <!--[if (!mso)&(!IE)]><!-->
  3563. <div style="border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent; padding-top:0px; padding-bottom:0px; padding-right: 0px; padding-left: 0px;">
  3564. <!--<![endif]-->
  3565. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 0px; padding-left: 0px; padding-top: 0px; padding-bottom: 0px;"><![endif]-->
  3566. <div style="font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;line-height:120%;color:#FFFFFF; padding-right: 0px; padding-left: 0px; padding-top: 0px; padding-bottom: 0px;">
  3567. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3568. <p style="margin: 0;font-size: 12px;line-height: 14px;text-align: center"><span style="font-size: 16px; line-height: 19px;"><strong><span style="line-height: 19px; font-size: 16px;">'.$header.'</span></strong>
  3569. </span>
  3570. </p>
  3571. </div>
  3572. </div>
  3573. <!--[if mso]></td></tr></table><![endif]-->
  3574. <!--[if (!mso)&(!IE)]><!-->
  3575. </div>
  3576. <!--<![endif]-->
  3577. </div>
  3578. </div>
  3579. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3580. </div>
  3581. </div>
  3582. </div>
  3583. <div style="background-color:#393939;">
  3584. <div style="Margin: 0 auto;min-width: 320px;max-width: 615px;width: 615px;width: calc(30500% - 193060px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;"
  3585. class="block-grid ">
  3586. <div style="border-collapse: collapse;display: table;width: 100%;">
  3587. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#393939;" align="center"><table cellpadding="0" cellspacing="0" border="0" style="width: 615px;"><tr class="layout-full-width" style="background-color:transparent;"><![endif]-->
  3588. <!--[if (mso)|(IE)]><td align="center" width="615" style=" width:615px; padding-right: 0px; padding-left: 0px; padding-top:5px; padding-bottom:5px; border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent;" valign="top"><![endif]-->
  3589. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3590. <div style="background-color: transparent; width: 100% !important;">
  3591. <!--[if (!mso)&(!IE)]><!-->
  3592. <div style="border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent; padding-top:5px; padding-bottom:5px; padding-right: 0px; padding-left: 0px;">
  3593. <!--<![endif]-->
  3594. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px; padding-top: 0px; padding-bottom: 0px;"><![endif]-->
  3595. <div style="font-family:\'Ubuntu\', Tahoma, Verdana, Segoe, sans-serif;line-height:120%;color:#FFFFFF; padding-right: 30px; padding-left: 30px; padding-top: 0px; padding-bottom: 0px;">
  3596. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  3597. <p style="margin: 0;font-size: 12px;line-height: 14px;text-align: center"><span style="font-size: 16px; line-height: 19px;"><strong>'.$title.'</strong></span></p>
  3598. </div>
  3599. </div>
  3600. <!--[if mso]></td></tr></table><![endif]-->
  3601. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  3602. <!--[if (mso)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px;padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><table width="55%" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]-->
  3603. <div align="center">
  3604. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  3605. </div>
  3606. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  3607. </div>
  3608. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px; padding-top: 15px; padding-bottom: 10px;"><![endif]-->
  3609. <div style="font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;line-height:120%;color:#FFFFFF; padding-right: 30px; padding-left: 30px; padding-top: 15px; padding-bottom: 10px;">
  3610. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  3611. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  3612. </div>
  3613. </div>
  3614. <!--[if mso]></td></tr></table><![endif]-->
  3615. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 15px; padding-left: 30px; padding-top: 10px; padding-bottom: 25px;"><![endif]-->
  3616. <div style="font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;line-height:180%;color:#FFFFFF; padding-right: 15px; padding-left: 30px; padding-top: 10px; padding-bottom: 25px;">
  3617. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  3618. <p style="margin: 0;font-size: 14px;line-height: 25px"><span style="font-size: 18px; line-height: 32px;"><em><span style="line-height: 32px; font-size: 18px;">'.$mainMessage.'</span></em>
  3619. </span>
  3620. </p>
  3621. </div>
  3622. </div>
  3623. <!--[if mso]></td></tr></table><![endif]-->
  3624. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  3625. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-spacing: 0; border-collapse: collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;"><tr><td style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;" align="center"><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="'.$path.'" style="height:48px; v-text-anchor:middle; width:194px;" arcsize="53%" strokecolor="" fillcolor="#66D9EF"><w:anchorlock/><center style="color:#000; font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif; font-size:18px;"><![endif]-->
  3626. <a href="'.$buttonURL.'" target="_blank" style="display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #000; background-color: #66D9EF; border-radius: 25px; -webkit-border-radius: 25px; -moz-border-radius: 25px; max-width: 180px; width: 114px; width: auto; border-top: 3px solid transparent; border-right: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 3px solid transparent; padding-top: 5px; padding-right: 30px; padding-bottom: 5px; padding-left: 30px; font-family: \'Lato\', Tahoma, Verdana, Segoe, sans-serif;mso-border-alt: none">
  3627. <span style="font-size:12px;line-height:21px;"><span style="font-size: 18px; line-height: 32px;" data-mce-style="font-size: 18px; line-height: 44px;">'.$button.'</span></span></a>
  3628. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  3629. </div>
  3630. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  3631. </div>
  3632. <!--[if (!mso)&(!IE)]><!-->
  3633. </div>
  3634. <!--<![endif]-->
  3635. </div>
  3636. </div>
  3637. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3638. </div>
  3639. </div>
  3640. </div>
  3641. <div style="background-color:#ffffff;">
  3642. <div style="Margin: 0 auto;min-width: 320px;max-width: 615px;width: 615px;width: calc(30500% - 193060px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;"
  3643. class="block-grid ">
  3644. <div style="border-collapse: collapse;display: table;width: 100%;">
  3645. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#ffffff;" align="center"><table cellpadding="0" cellspacing="0" border="0" style="width: 615px;"><tr class="layout-full-width" style="background-color:transparent;"><![endif]-->
  3646. <!--[if (mso)|(IE)]><td align="center" width="615" style=" width:615px; padding-right: 0px; padding-left: 0px; padding-top:5px; padding-bottom:30px; border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent;" valign="top"><![endif]-->
  3647. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3648. <div style="background-color: transparent; width: 100% !important;">
  3649. <!--[if (!mso)&(!IE)]><!-->
  3650. <div style="border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent; padding-top:5px; padding-bottom:30px; padding-right: 0px; padding-left: 0px;">
  3651. <!--<![endif]-->
  3652. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 10px; padding-left: 10px; padding-top: 0px; padding-bottom: 10px;"><![endif]-->
  3653. <div style="font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;line-height:120%;color:#555555; padding-right: 10px; padding-left: 10px; padding-top: 0px; padding-bottom: 10px;">
  3654. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3655. <p style="margin: 0;font-size: 14px;line-height: 17px;text-align: center"><strong><span style="font-size: 26px; line-height: 31px;">'.$subTitle.'<br></span></strong></p>
  3656. </div>
  3657. </div>
  3658. <!--[if mso]></td></tr></table><![endif]-->
  3659. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  3660. <!--[if (mso)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 20px;padding-left: 20px; padding-top: 15px; padding-bottom: 20px;"><table width="40%" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]-->
  3661. <div align="center">
  3662. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  3663. </div>
  3664. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  3665. </div>
  3666. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 10px; padding-left: 10px; padding-top: 0px; padding-bottom: 0px;"><![endif]-->
  3667. <div style="font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;line-height:180%;color:#7E7D7D; padding-right: 10px; padding-left: 10px; padding-top: 0px; padding-bottom: 0px;">
  3668. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3669. <p style="margin: 0;font-size: 14px;line-height: 25px;text-align: center"><em><span style="font-size: 18px; line-height: 32px;">'.$subMessage.'</span></em></p>
  3670. </div>
  3671. </div>
  3672. <!--[if mso]></td></tr></table><![endif]-->
  3673. <!--[if (!mso)&(!IE)]><!-->
  3674. </div>
  3675. <!--<![endif]-->
  3676. </div>
  3677. </div>
  3678. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3679. </div>
  3680. </div>
  3681. </div>
  3682. <div style="background-color:#333333;">
  3683. <div style="Margin: 0 auto;min-width: 320px;max-width: 615px;width: 615px;width: calc(30500% - 193060px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;"
  3684. class="block-grid ">
  3685. <div style="border-collapse: collapse;display: table;width: 100%;">
  3686. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#333333;" align="center"><table cellpadding="0" cellspacing="0" border="0" style="width: 615px;"><tr class="layout-full-width" style="background-color:transparent;"><![endif]-->
  3687. <!--[if (mso)|(IE)]><td align="center" width="615" style=" width:615px; padding-right: 0px; padding-left: 0px; padding-top:5px; padding-bottom:5px; border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent;" valign="top"><![endif]-->
  3688. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3689. <div style="background-color: transparent; width: 100% !important;">
  3690. <!--[if (!mso)&(!IE)]><!-->
  3691. <div style="border-top: 0px solid transparent; border-left: 0px solid transparent; border-bottom: 0px solid transparent; border-right: 0px solid transparent; padding-top:5px; padding-bottom:5px; padding-right: 0px; padding-left: 0px;">
  3692. <!--<![endif]-->
  3693. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 10px; padding-left: 10px; padding-top: 10px; padding-bottom: 10px;"><![endif]-->
  3694. <div style="font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;line-height:120%;color:#959595; padding-right: 10px; padding-left: 10px; padding-top: 10px; padding-bottom: 10px;">
  3695. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3696. <p style="margin: 0;font-size: 14px;line-height: 17px;text-align: center">This&#160;email was sent by <a style="color:#AD80FD;text-decoration: underline;" title="Organizr"
  3697. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  3698. </div>
  3699. </div>
  3700. <!--[if mso]></td></tr></table><![endif]-->
  3701. <!--[if (!mso)&(!IE)]><!-->
  3702. </div>
  3703. <!--<![endif]-->
  3704. </div>
  3705. </div>
  3706. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3707. </div>
  3708. </div>
  3709. </div>
  3710. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  3711. </div>
  3712. <!--[if (mso)|(IE)]></div><![endif]-->
  3713. </body>
  3714. </html>
  3715. ';
  3716. }
  3717. function mimeTypes(){
  3718. return array(
  3719. '123' => 'application/vnd.lotus-1-2-3',
  3720. '3dml' => 'text/vnd.in3d.3dml',
  3721. '3ds' => 'image/x-3ds',
  3722. '3g2' => 'video/3gpp2',
  3723. '3gp' => 'video/3gpp',
  3724. '7z' => 'application/x-7z-compressed',
  3725. 'aab' => 'application/x-authorware-bin',
  3726. 'aac' => 'audio/x-aac',
  3727. 'aam' => 'application/x-authorware-map',
  3728. 'aas' => 'application/x-authorware-seg',
  3729. 'abw' => 'application/x-abiword',
  3730. 'ac' => 'application/pkix-attr-cert',
  3731. 'acc' => 'application/vnd.americandynamics.acc',
  3732. 'ace' => 'application/x-ace-compressed',
  3733. 'acu' => 'application/vnd.acucobol',
  3734. 'acutc' => 'application/vnd.acucorp',
  3735. 'adp' => 'audio/adpcm',
  3736. 'aep' => 'application/vnd.audiograph',
  3737. 'afm' => 'application/x-font-type1',
  3738. 'afp' => 'application/vnd.ibm.modcap',
  3739. 'ahead' => 'application/vnd.ahead.space',
  3740. 'ai' => 'application/postscript',
  3741. 'aif' => 'audio/x-aiff',
  3742. 'aifc' => 'audio/x-aiff',
  3743. 'aiff' => 'audio/x-aiff',
  3744. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  3745. 'ait' => 'application/vnd.dvb.ait',
  3746. 'ami' => 'application/vnd.amiga.ami',
  3747. 'apk' => 'application/vnd.android.package-archive',
  3748. 'appcache' => 'text/cache-manifest',
  3749. 'application' => 'application/x-ms-application',
  3750. 'apr' => 'application/vnd.lotus-approach',
  3751. 'arc' => 'application/x-freearc',
  3752. 'asc' => 'application/pgp-signature',
  3753. 'asf' => 'video/x-ms-asf',
  3754. 'asm' => 'text/x-asm',
  3755. 'aso' => 'application/vnd.accpac.simply.aso',
  3756. 'asx' => 'video/x-ms-asf',
  3757. 'atc' => 'application/vnd.acucorp',
  3758. 'atom' => 'application/atom+xml',
  3759. 'atomcat' => 'application/atomcat+xml',
  3760. 'atomsvc' => 'application/atomsvc+xml',
  3761. 'atx' => 'application/vnd.antix.game-component',
  3762. 'au' => 'audio/basic',
  3763. 'avi' => 'video/x-msvideo',
  3764. 'aw' => 'application/applixware',
  3765. 'azf' => 'application/vnd.airzip.filesecure.azf',
  3766. 'azs' => 'application/vnd.airzip.filesecure.azs',
  3767. 'azw' => 'application/vnd.amazon.ebook',
  3768. 'bat' => 'application/x-msdownload',
  3769. 'bcpio' => 'application/x-bcpio',
  3770. 'bdf' => 'application/x-font-bdf',
  3771. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  3772. 'bed' => 'application/vnd.realvnc.bed',
  3773. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  3774. 'bin' => 'application/octet-stream',
  3775. 'blb' => 'application/x-blorb',
  3776. 'blorb' => 'application/x-blorb',
  3777. 'bmi' => 'application/vnd.bmi',
  3778. 'bmp' => 'image/bmp',
  3779. 'book' => 'application/vnd.framemaker',
  3780. 'box' => 'application/vnd.previewsystems.box',
  3781. 'boz' => 'application/x-bzip2',
  3782. 'bpk' => 'application/octet-stream',
  3783. 'btif' => 'image/prs.btif',
  3784. 'bz' => 'application/x-bzip',
  3785. 'bz2' => 'application/x-bzip2',
  3786. 'c' => 'text/x-c',
  3787. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  3788. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  3789. 'c4d' => 'application/vnd.clonk.c4group',
  3790. 'c4f' => 'application/vnd.clonk.c4group',
  3791. 'c4g' => 'application/vnd.clonk.c4group',
  3792. 'c4p' => 'application/vnd.clonk.c4group',
  3793. 'c4u' => 'application/vnd.clonk.c4group',
  3794. 'cab' => 'application/vnd.ms-cab-compressed',
  3795. 'caf' => 'audio/x-caf',
  3796. 'cap' => 'application/vnd.tcpdump.pcap',
  3797. 'car' => 'application/vnd.curl.car',
  3798. 'cat' => 'application/vnd.ms-pki.seccat',
  3799. 'cb7' => 'application/x-cbr',
  3800. 'cba' => 'application/x-cbr',
  3801. 'cbr' => 'application/x-cbr',
  3802. 'cbt' => 'application/x-cbr',
  3803. 'cbz' => 'application/x-cbr',
  3804. 'cc' => 'text/x-c',
  3805. 'cct' => 'application/x-director',
  3806. 'ccxml' => 'application/ccxml+xml',
  3807. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  3808. 'cdf' => 'application/x-netcdf',
  3809. 'cdkey' => 'application/vnd.mediastation.cdkey',
  3810. 'cdmia' => 'application/cdmi-capability',
  3811. 'cdmic' => 'application/cdmi-container',
  3812. 'cdmid' => 'application/cdmi-domain',
  3813. 'cdmio' => 'application/cdmi-object',
  3814. 'cdmiq' => 'application/cdmi-queue',
  3815. 'cdx' => 'chemical/x-cdx',
  3816. 'cdxml' => 'application/vnd.chemdraw+xml',
  3817. 'cdy' => 'application/vnd.cinderella',
  3818. 'cer' => 'application/pkix-cert',
  3819. 'cfs' => 'application/x-cfs-compressed',
  3820. 'cgm' => 'image/cgm',
  3821. 'chat' => 'application/x-chat',
  3822. 'chm' => 'application/vnd.ms-htmlhelp',
  3823. 'chrt' => 'application/vnd.kde.kchart',
  3824. 'cif' => 'chemical/x-cif',
  3825. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  3826. 'cil' => 'application/vnd.ms-artgalry',
  3827. 'cla' => 'application/vnd.claymore',
  3828. 'class' => 'application/java-vm',
  3829. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  3830. 'clkp' => 'application/vnd.crick.clicker.palette',
  3831. 'clkt' => 'application/vnd.crick.clicker.template',
  3832. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  3833. 'clkx' => 'application/vnd.crick.clicker',
  3834. 'clp' => 'application/x-msclip',
  3835. 'cmc' => 'application/vnd.cosmocaller',
  3836. 'cmdf' => 'chemical/x-cmdf',
  3837. 'cml' => 'chemical/x-cml',
  3838. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  3839. 'cmx' => 'image/x-cmx',
  3840. 'cod' => 'application/vnd.rim.cod',
  3841. 'com' => 'application/x-msdownload',
  3842. 'conf' => 'text/plain',
  3843. 'cpio' => 'application/x-cpio',
  3844. 'cpp' => 'text/x-c',
  3845. 'cpt' => 'application/mac-compactpro',
  3846. 'crd' => 'application/x-mscardfile',
  3847. 'crl' => 'application/pkix-crl',
  3848. 'crt' => 'application/x-x509-ca-cert',
  3849. 'cryptonote' => 'application/vnd.rig.cryptonote',
  3850. 'csh' => 'application/x-csh',
  3851. 'csml' => 'chemical/x-csml',
  3852. 'csp' => 'application/vnd.commonspace',
  3853. 'css' => 'text/css',
  3854. 'cst' => 'application/x-director',
  3855. 'csv' => 'text/csv',
  3856. 'cu' => 'application/cu-seeme',
  3857. 'curl' => 'text/vnd.curl',
  3858. 'cww' => 'application/prs.cww',
  3859. 'cxt' => 'application/x-director',
  3860. 'cxx' => 'text/x-c',
  3861. 'dae' => 'model/vnd.collada+xml',
  3862. 'daf' => 'application/vnd.mobius.daf',
  3863. 'dart' => 'application/vnd.dart',
  3864. 'dataless' => 'application/vnd.fdsn.seed',
  3865. 'davmount' => 'application/davmount+xml',
  3866. 'dbk' => 'application/docbook+xml',
  3867. 'dcr' => 'application/x-director',
  3868. 'dcurl' => 'text/vnd.curl.dcurl',
  3869. 'dd2' => 'application/vnd.oma.dd2+xml',
  3870. 'ddd' => 'application/vnd.fujixerox.ddd',
  3871. 'deb' => 'application/x-debian-package',
  3872. 'def' => 'text/plain',
  3873. 'deploy' => 'application/octet-stream',
  3874. 'der' => 'application/x-x509-ca-cert',
  3875. 'dfac' => 'application/vnd.dreamfactory',
  3876. 'dgc' => 'application/x-dgc-compressed',
  3877. 'dic' => 'text/x-c',
  3878. 'dir' => 'application/x-director',
  3879. 'dis' => 'application/vnd.mobius.dis',
  3880. 'dist' => 'application/octet-stream',
  3881. 'distz' => 'application/octet-stream',
  3882. 'djv' => 'image/vnd.djvu',
  3883. 'djvu' => 'image/vnd.djvu',
  3884. 'dll' => 'application/x-msdownload',
  3885. 'dmg' => 'application/x-apple-diskimage',
  3886. 'dmp' => 'application/vnd.tcpdump.pcap',
  3887. 'dms' => 'application/octet-stream',
  3888. 'dna' => 'application/vnd.dna',
  3889. 'doc' => 'application/msword',
  3890. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  3891. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  3892. 'dot' => 'application/msword',
  3893. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  3894. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  3895. 'dp' => 'application/vnd.osgi.dp',
  3896. 'dpg' => 'application/vnd.dpgraph',
  3897. 'dra' => 'audio/vnd.dra',
  3898. 'dsc' => 'text/prs.lines.tag',
  3899. 'dssc' => 'application/dssc+der',
  3900. 'dtb' => 'application/x-dtbook+xml',
  3901. 'dtd' => 'application/xml-dtd',
  3902. 'dts' => 'audio/vnd.dts',
  3903. 'dtshd' => 'audio/vnd.dts.hd',
  3904. 'dump' => 'application/octet-stream',
  3905. 'dvb' => 'video/vnd.dvb.file',
  3906. 'dvi' => 'application/x-dvi',
  3907. 'dwf' => 'model/vnd.dwf',
  3908. 'dwg' => 'image/vnd.dwg',
  3909. 'dxf' => 'image/vnd.dxf',
  3910. 'dxp' => 'application/vnd.spotfire.dxp',
  3911. 'dxr' => 'application/x-director',
  3912. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  3913. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  3914. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  3915. 'ecma' => 'application/ecmascript',
  3916. 'edm' => 'application/vnd.novadigm.edm',
  3917. 'edx' => 'application/vnd.novadigm.edx',
  3918. 'efif' => 'application/vnd.picsel',
  3919. 'ei6' => 'application/vnd.pg.osasli',
  3920. 'elc' => 'application/octet-stream',
  3921. 'emf' => 'application/x-msmetafile',
  3922. 'eml' => 'message/rfc822',
  3923. 'emma' => 'application/emma+xml',
  3924. 'emz' => 'application/x-msmetafile',
  3925. 'eol' => 'audio/vnd.digital-winds',
  3926. 'eot' => 'application/vnd.ms-fontobject',
  3927. 'eps' => 'application/postscript',
  3928. 'epub' => 'application/epub+zip',
  3929. 'es3' => 'application/vnd.eszigno3+xml',
  3930. 'esa' => 'application/vnd.osgi.subsystem',
  3931. 'esf' => 'application/vnd.epson.esf',
  3932. 'et3' => 'application/vnd.eszigno3+xml',
  3933. 'etx' => 'text/x-setext',
  3934. 'eva' => 'application/x-eva',
  3935. 'evy' => 'application/x-envoy',
  3936. 'exe' => 'application/x-msdownload',
  3937. 'exi' => 'application/exi',
  3938. 'ext' => 'application/vnd.novadigm.ext',
  3939. 'ez' => 'application/andrew-inset',
  3940. 'ez2' => 'application/vnd.ezpix-album',
  3941. 'ez3' => 'application/vnd.ezpix-package',
  3942. 'f' => 'text/x-fortran',
  3943. 'f4v' => 'video/x-f4v',
  3944. 'f77' => 'text/x-fortran',
  3945. 'f90' => 'text/x-fortran',
  3946. 'fbs' => 'image/vnd.fastbidsheet',
  3947. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  3948. 'fcs' => 'application/vnd.isac.fcs',
  3949. 'fdf' => 'application/vnd.fdf',
  3950. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  3951. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  3952. 'fgd' => 'application/x-director',
  3953. 'fh' => 'image/x-freehand',
  3954. 'fh4' => 'image/x-freehand',
  3955. 'fh5' => 'image/x-freehand',
  3956. 'fh7' => 'image/x-freehand',
  3957. 'fhc' => 'image/x-freehand',
  3958. 'fig' => 'application/x-xfig',
  3959. 'flac' => 'audio/x-flac',
  3960. 'fli' => 'video/x-fli',
  3961. 'flo' => 'application/vnd.micrografx.flo',
  3962. 'flv' => 'video/x-flv',
  3963. 'flw' => 'application/vnd.kde.kivio',
  3964. 'flx' => 'text/vnd.fmi.flexstor',
  3965. 'fly' => 'text/vnd.fly',
  3966. 'fm' => 'application/vnd.framemaker',
  3967. 'fnc' => 'application/vnd.frogans.fnc',
  3968. 'for' => 'text/x-fortran',
  3969. 'fpx' => 'image/vnd.fpx',
  3970. 'frame' => 'application/vnd.framemaker',
  3971. 'fsc' => 'application/vnd.fsc.weblaunch',
  3972. 'fst' => 'image/vnd.fst',
  3973. 'ftc' => 'application/vnd.fluxtime.clip',
  3974. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  3975. 'fvt' => 'video/vnd.fvt',
  3976. 'fxp' => 'application/vnd.adobe.fxp',
  3977. 'fxpl' => 'application/vnd.adobe.fxp',
  3978. 'fzs' => 'application/vnd.fuzzysheet',
  3979. 'g2w' => 'application/vnd.geoplan',
  3980. 'g3' => 'image/g3fax',
  3981. 'g3w' => 'application/vnd.geospace',
  3982. 'gac' => 'application/vnd.groove-account',
  3983. 'gam' => 'application/x-tads',
  3984. 'gbr' => 'application/rpki-ghostbusters',
  3985. 'gca' => 'application/x-gca-compressed',
  3986. 'gdl' => 'model/vnd.gdl',
  3987. 'geo' => 'application/vnd.dynageo',
  3988. 'gex' => 'application/vnd.geometry-explorer',
  3989. 'ggb' => 'application/vnd.geogebra.file',
  3990. 'ggt' => 'application/vnd.geogebra.tool',
  3991. 'ghf' => 'application/vnd.groove-help',
  3992. 'gif' => 'image/gif',
  3993. 'gim' => 'application/vnd.groove-identity-message',
  3994. 'gml' => 'application/gml+xml',
  3995. 'gmx' => 'application/vnd.gmx',
  3996. 'gnumeric' => 'application/x-gnumeric',
  3997. 'gph' => 'application/vnd.flographit',
  3998. 'gpx' => 'application/gpx+xml',
  3999. 'gqf' => 'application/vnd.grafeq',
  4000. 'gqs' => 'application/vnd.grafeq',
  4001. 'gram' => 'application/srgs',
  4002. 'gramps' => 'application/x-gramps-xml',
  4003. 'gre' => 'application/vnd.geometry-explorer',
  4004. 'grv' => 'application/vnd.groove-injector',
  4005. 'grxml' => 'application/srgs+xml',
  4006. 'gsf' => 'application/x-font-ghostscript',
  4007. 'gtar' => 'application/x-gtar',
  4008. 'gtm' => 'application/vnd.groove-tool-message',
  4009. 'gtw' => 'model/vnd.gtw',
  4010. 'gv' => 'text/vnd.graphviz',
  4011. 'gxf' => 'application/gxf',
  4012. 'gxt' => 'application/vnd.geonext',
  4013. 'h' => 'text/x-c',
  4014. 'h261' => 'video/h261',
  4015. 'h263' => 'video/h263',
  4016. 'h264' => 'video/h264',
  4017. 'hal' => 'application/vnd.hal+xml',
  4018. 'hbci' => 'application/vnd.hbci',
  4019. 'hdf' => 'application/x-hdf',
  4020. 'hh' => 'text/x-c',
  4021. 'hlp' => 'application/winhlp',
  4022. 'hpgl' => 'application/vnd.hp-hpgl',
  4023. 'hpid' => 'application/vnd.hp-hpid',
  4024. 'hps' => 'application/vnd.hp-hps',
  4025. 'hqx' => 'application/mac-binhex40',
  4026. 'htke' => 'application/vnd.kenameaapp',
  4027. 'htm' => 'text/html',
  4028. 'html' => 'text/html',
  4029. 'hvd' => 'application/vnd.yamaha.hv-dic',
  4030. 'hvp' => 'application/vnd.yamaha.hv-voice',
  4031. 'hvs' => 'application/vnd.yamaha.hv-script',
  4032. 'i2g' => 'application/vnd.intergeo',
  4033. 'icc' => 'application/vnd.iccprofile',
  4034. 'ice' => 'x-conference/x-cooltalk',
  4035. 'icm' => 'application/vnd.iccprofile',
  4036. 'ico' => 'image/x-icon',
  4037. 'ics' => 'text/calendar',
  4038. 'ief' => 'image/ief',
  4039. 'ifb' => 'text/calendar',
  4040. 'ifm' => 'application/vnd.shana.informed.formdata',
  4041. 'iges' => 'model/iges',
  4042. 'igl' => 'application/vnd.igloader',
  4043. 'igm' => 'application/vnd.insors.igm',
  4044. 'igs' => 'model/iges',
  4045. 'igx' => 'application/vnd.micrografx.igx',
  4046. 'iif' => 'application/vnd.shana.informed.interchange',
  4047. 'imp' => 'application/vnd.accpac.simply.imp',
  4048. 'ims' => 'application/vnd.ms-ims',
  4049. 'in' => 'text/plain',
  4050. 'ink' => 'application/inkml+xml',
  4051. 'inkml' => 'application/inkml+xml',
  4052. 'install' => 'application/x-install-instructions',
  4053. 'iota' => 'application/vnd.astraea-software.iota',
  4054. 'ipfix' => 'application/ipfix',
  4055. 'ipk' => 'application/vnd.shana.informed.package',
  4056. 'irm' => 'application/vnd.ibm.rights-management',
  4057. 'irp' => 'application/vnd.irepository.package+xml',
  4058. 'iso' => 'application/x-iso9660-image',
  4059. 'itp' => 'application/vnd.shana.informed.formtemplate',
  4060. 'ivp' => 'application/vnd.immervision-ivp',
  4061. 'ivu' => 'application/vnd.immervision-ivu',
  4062. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  4063. 'jam' => 'application/vnd.jam',
  4064. 'jar' => 'application/java-archive',
  4065. 'java' => 'text/x-java-source',
  4066. 'jisp' => 'application/vnd.jisp',
  4067. 'jlt' => 'application/vnd.hp-jlyt',
  4068. 'jnlp' => 'application/x-java-jnlp-file',
  4069. 'joda' => 'application/vnd.joost.joda-archive',
  4070. 'jpe' => 'image/jpeg',
  4071. 'jpeg' => 'image/jpeg',
  4072. 'jpg' => 'image/jpeg',
  4073. 'jpgm' => 'video/jpm',
  4074. 'jpgv' => 'video/jpeg',
  4075. 'jpm' => 'video/jpm',
  4076. 'js' => 'application/javascript',
  4077. 'json' => 'application/json',
  4078. 'jsonml' => 'application/jsonml+json',
  4079. 'kar' => 'audio/midi',
  4080. 'karbon' => 'application/vnd.kde.karbon',
  4081. 'kfo' => 'application/vnd.kde.kformula',
  4082. 'kia' => 'application/vnd.kidspiration',
  4083. 'kml' => 'application/vnd.google-earth.kml+xml',
  4084. 'kmz' => 'application/vnd.google-earth.kmz',
  4085. 'kne' => 'application/vnd.kinar',
  4086. 'knp' => 'application/vnd.kinar',
  4087. 'kon' => 'application/vnd.kde.kontour',
  4088. 'kpr' => 'application/vnd.kde.kpresenter',
  4089. 'kpt' => 'application/vnd.kde.kpresenter',
  4090. 'kpxx' => 'application/vnd.ds-keypoint',
  4091. 'ksp' => 'application/vnd.kde.kspread',
  4092. 'ktr' => 'application/vnd.kahootz',
  4093. 'ktx' => 'image/ktx',
  4094. 'ktz' => 'application/vnd.kahootz',
  4095. 'kwd' => 'application/vnd.kde.kword',
  4096. 'kwt' => 'application/vnd.kde.kword',
  4097. 'lasxml' => 'application/vnd.las.las+xml',
  4098. 'latex' => 'application/x-latex',
  4099. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  4100. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  4101. 'les' => 'application/vnd.hhe.lesson-player',
  4102. 'lha' => 'application/x-lzh-compressed',
  4103. 'link66' => 'application/vnd.route66.link66+xml',
  4104. 'list' => 'text/plain',
  4105. 'list3820' => 'application/vnd.ibm.modcap',
  4106. 'listafp' => 'application/vnd.ibm.modcap',
  4107. 'lnk' => 'application/x-ms-shortcut',
  4108. 'log' => 'text/plain',
  4109. 'lostxml' => 'application/lost+xml',
  4110. 'lrf' => 'application/octet-stream',
  4111. 'lrm' => 'application/vnd.ms-lrm',
  4112. 'ltf' => 'application/vnd.frogans.ltf',
  4113. 'lvp' => 'audio/vnd.lucent.voice',
  4114. 'lwp' => 'application/vnd.lotus-wordpro',
  4115. 'lzh' => 'application/x-lzh-compressed',
  4116. 'm13' => 'application/x-msmediaview',
  4117. 'm14' => 'application/x-msmediaview',
  4118. 'm1v' => 'video/mpeg',
  4119. 'm21' => 'application/mp21',
  4120. 'm2a' => 'audio/mpeg',
  4121. 'm2v' => 'video/mpeg',
  4122. 'm3a' => 'audio/mpeg',
  4123. 'm3u' => 'audio/x-mpegurl',
  4124. 'm3u8' => 'application/vnd.apple.mpegurl',
  4125. 'm4a' => 'audio/mp4',
  4126. 'm4u' => 'video/vnd.mpegurl',
  4127. 'm4v' => 'video/x-m4v',
  4128. 'ma' => 'application/mathematica',
  4129. 'mads' => 'application/mads+xml',
  4130. 'mag' => 'application/vnd.ecowin.chart',
  4131. 'maker' => 'application/vnd.framemaker',
  4132. 'man' => 'text/troff',
  4133. 'mar' => 'application/octet-stream',
  4134. 'mathml' => 'application/mathml+xml',
  4135. 'mb' => 'application/mathematica',
  4136. 'mbk' => 'application/vnd.mobius.mbk',
  4137. 'mbox' => 'application/mbox',
  4138. 'mc1' => 'application/vnd.medcalcdata',
  4139. 'mcd' => 'application/vnd.mcd',
  4140. 'mcurl' => 'text/vnd.curl.mcurl',
  4141. 'mdb' => 'application/x-msaccess',
  4142. 'mdi' => 'image/vnd.ms-modi',
  4143. 'me' => 'text/troff',
  4144. 'mesh' => 'model/mesh',
  4145. 'meta4' => 'application/metalink4+xml',
  4146. 'metalink' => 'application/metalink+xml',
  4147. 'mets' => 'application/mets+xml',
  4148. 'mfm' => 'application/vnd.mfmp',
  4149. 'mft' => 'application/rpki-manifest',
  4150. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  4151. 'mgz' => 'application/vnd.proteus.magazine',
  4152. 'mid' => 'audio/midi',
  4153. 'midi' => 'audio/midi',
  4154. 'mie' => 'application/x-mie',
  4155. 'mif' => 'application/vnd.mif',
  4156. 'mime' => 'message/rfc822',
  4157. 'mj2' => 'video/mj2',
  4158. 'mjp2' => 'video/mj2',
  4159. 'mk3d' => 'video/x-matroska',
  4160. 'mka' => 'audio/x-matroska',
  4161. 'mks' => 'video/x-matroska',
  4162. 'mkv' => 'video/x-matroska',
  4163. 'mlp' => 'application/vnd.dolby.mlp',
  4164. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  4165. 'mmf' => 'application/vnd.smaf',
  4166. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  4167. 'mng' => 'video/x-mng',
  4168. 'mny' => 'application/x-msmoney',
  4169. 'mobi' => 'application/x-mobipocket-ebook',
  4170. 'mods' => 'application/mods+xml',
  4171. 'mov' => 'video/quicktime',
  4172. 'movie' => 'video/x-sgi-movie',
  4173. 'mp2' => 'audio/mpeg',
  4174. 'mp21' => 'application/mp21',
  4175. 'mp2a' => 'audio/mpeg',
  4176. 'mp3' => 'audio/mpeg',
  4177. 'mp4' => 'video/mp4',
  4178. 'mp4a' => 'audio/mp4',
  4179. 'mp4s' => 'application/mp4',
  4180. 'mp4v' => 'video/mp4',
  4181. 'mpc' => 'application/vnd.mophun.certificate',
  4182. 'mpe' => 'video/mpeg',
  4183. 'mpeg' => 'video/mpeg',
  4184. 'mpg' => 'video/mpeg',
  4185. 'mpg4' => 'video/mp4',
  4186. 'mpga' => 'audio/mpeg',
  4187. 'mpkg' => 'application/vnd.apple.installer+xml',
  4188. 'mpm' => 'application/vnd.blueice.multipass',
  4189. 'mpn' => 'application/vnd.mophun.application',
  4190. 'mpp' => 'application/vnd.ms-project',
  4191. 'mpt' => 'application/vnd.ms-project',
  4192. 'mpy' => 'application/vnd.ibm.minipay',
  4193. 'mqy' => 'application/vnd.mobius.mqy',
  4194. 'mrc' => 'application/marc',
  4195. 'mrcx' => 'application/marcxml+xml',
  4196. 'ms' => 'text/troff',
  4197. 'mscml' => 'application/mediaservercontrol+xml',
  4198. 'mseed' => 'application/vnd.fdsn.mseed',
  4199. 'mseq' => 'application/vnd.mseq',
  4200. 'msf' => 'application/vnd.epson.msf',
  4201. 'msh' => 'model/mesh',
  4202. 'msi' => 'application/x-msdownload',
  4203. 'msl' => 'application/vnd.mobius.msl',
  4204. 'msty' => 'application/vnd.muvee.style',
  4205. 'mts' => 'model/vnd.mts',
  4206. 'mus' => 'application/vnd.musician',
  4207. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  4208. 'mvb' => 'application/x-msmediaview',
  4209. 'mwf' => 'application/vnd.mfer',
  4210. 'mxf' => 'application/mxf',
  4211. 'mxl' => 'application/vnd.recordare.musicxml',
  4212. 'mxml' => 'application/xv+xml',
  4213. 'mxs' => 'application/vnd.triscape.mxs',
  4214. 'mxu' => 'video/vnd.mpegurl',
  4215. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  4216. 'n3' => 'text/n3',
  4217. 'nb' => 'application/mathematica',
  4218. 'nbp' => 'application/vnd.wolfram.player',
  4219. 'nc' => 'application/x-netcdf',
  4220. 'ncx' => 'application/x-dtbncx+xml',
  4221. 'nfo' => 'text/x-nfo',
  4222. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  4223. 'nitf' => 'application/vnd.nitf',
  4224. 'nlu' => 'application/vnd.neurolanguage.nlu',
  4225. 'nml' => 'application/vnd.enliven',
  4226. 'nnd' => 'application/vnd.noblenet-directory',
  4227. 'nns' => 'application/vnd.noblenet-sealer',
  4228. 'nnw' => 'application/vnd.noblenet-web',
  4229. 'npx' => 'image/vnd.net-fpx',
  4230. 'nsc' => 'application/x-conference',
  4231. 'nsf' => 'application/vnd.lotus-notes',
  4232. 'ntf' => 'application/vnd.nitf',
  4233. 'nzb' => 'application/x-nzb',
  4234. 'oa2' => 'application/vnd.fujitsu.oasys2',
  4235. 'oa3' => 'application/vnd.fujitsu.oasys3',
  4236. 'oas' => 'application/vnd.fujitsu.oasys',
  4237. 'obd' => 'application/x-msbinder',
  4238. 'obj' => 'application/x-tgif',
  4239. 'oda' => 'application/oda',
  4240. 'odb' => 'application/vnd.oasis.opendocument.database',
  4241. 'odc' => 'application/vnd.oasis.opendocument.chart',
  4242. 'odf' => 'application/vnd.oasis.opendocument.formula',
  4243. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  4244. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  4245. 'odi' => 'application/vnd.oasis.opendocument.image',
  4246. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  4247. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  4248. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  4249. 'odt' => 'application/vnd.oasis.opendocument.text',
  4250. 'oga' => 'audio/ogg',
  4251. 'ogg' => 'audio/ogg',
  4252. 'ogv' => 'video/ogg',
  4253. 'ogx' => 'application/ogg',
  4254. 'omdoc' => 'application/omdoc+xml',
  4255. 'onepkg' => 'application/onenote',
  4256. 'onetmp' => 'application/onenote',
  4257. 'onetoc' => 'application/onenote',
  4258. 'onetoc2' => 'application/onenote',
  4259. 'opf' => 'application/oebps-package+xml',
  4260. 'opml' => 'text/x-opml',
  4261. 'oprc' => 'application/vnd.palm',
  4262. 'org' => 'application/vnd.lotus-organizer',
  4263. 'osf' => 'application/vnd.yamaha.openscoreformat',
  4264. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  4265. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  4266. 'otf' => 'application/x-font-otf',
  4267. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  4268. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  4269. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  4270. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  4271. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  4272. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  4273. 'oxps' => 'application/oxps',
  4274. 'oxt' => 'application/vnd.openofficeorg.extension',
  4275. 'p' => 'text/x-pascal',
  4276. 'p10' => 'application/pkcs10',
  4277. 'p12' => 'application/x-pkcs12',
  4278. 'p7b' => 'application/x-pkcs7-certificates',
  4279. 'p7c' => 'application/pkcs7-mime',
  4280. 'p7m' => 'application/pkcs7-mime',
  4281. 'p7r' => 'application/x-pkcs7-certreqresp',
  4282. 'p7s' => 'application/pkcs7-signature',
  4283. 'p8' => 'application/pkcs8',
  4284. 'pas' => 'text/x-pascal',
  4285. 'paw' => 'application/vnd.pawaafile',
  4286. 'pbd' => 'application/vnd.powerbuilder6',
  4287. 'pbm' => 'image/x-portable-bitmap',
  4288. 'pcap' => 'application/vnd.tcpdump.pcap',
  4289. 'pcf' => 'application/x-font-pcf',
  4290. 'pcl' => 'application/vnd.hp-pcl',
  4291. 'pclxl' => 'application/vnd.hp-pclxl',
  4292. 'pct' => 'image/x-pict',
  4293. 'pcurl' => 'application/vnd.curl.pcurl',
  4294. 'pcx' => 'image/x-pcx',
  4295. 'pdb' => 'application/vnd.palm',
  4296. 'pdf' => 'application/pdf',
  4297. 'pfa' => 'application/x-font-type1',
  4298. 'pfb' => 'application/x-font-type1',
  4299. 'pfm' => 'application/x-font-type1',
  4300. 'pfr' => 'application/font-tdpfr',
  4301. 'pfx' => 'application/x-pkcs12',
  4302. 'pgm' => 'image/x-portable-graymap',
  4303. 'pgn' => 'application/x-chess-pgn',
  4304. 'pgp' => 'application/pgp-encrypted',
  4305. 'pic' => 'image/x-pict',
  4306. 'pkg' => 'application/octet-stream',
  4307. 'pki' => 'application/pkixcmp',
  4308. 'pkipath' => 'application/pkix-pkipath',
  4309. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  4310. 'plc' => 'application/vnd.mobius.plc',
  4311. 'plf' => 'application/vnd.pocketlearn',
  4312. 'pls' => 'application/pls+xml',
  4313. 'pml' => 'application/vnd.ctc-posml',
  4314. 'png' => 'image/png',
  4315. 'pnm' => 'image/x-portable-anymap',
  4316. 'portpkg' => 'application/vnd.macports.portpkg',
  4317. 'pot' => 'application/vnd.ms-powerpoint',
  4318. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  4319. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  4320. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  4321. 'ppd' => 'application/vnd.cups-ppd',
  4322. 'ppm' => 'image/x-portable-pixmap',
  4323. 'pps' => 'application/vnd.ms-powerpoint',
  4324. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  4325. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  4326. 'ppt' => 'application/vnd.ms-powerpoint',
  4327. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  4328. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  4329. 'pqa' => 'application/vnd.palm',
  4330. 'prc' => 'application/x-mobipocket-ebook',
  4331. 'pre' => 'application/vnd.lotus-freelance',
  4332. 'prf' => 'application/pics-rules',
  4333. 'ps' => 'application/postscript',
  4334. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  4335. 'psd' => 'image/vnd.adobe.photoshop',
  4336. 'psf' => 'application/x-font-linux-psf',
  4337. 'pskcxml' => 'application/pskc+xml',
  4338. 'ptid' => 'application/vnd.pvi.ptid1',
  4339. 'pub' => 'application/x-mspublisher',
  4340. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  4341. 'pwn' => 'application/vnd.3m.post-it-notes',
  4342. 'pya' => 'audio/vnd.ms-playready.media.pya',
  4343. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  4344. 'qam' => 'application/vnd.epson.quickanime',
  4345. 'qbo' => 'application/vnd.intu.qbo',
  4346. 'qfx' => 'application/vnd.intu.qfx',
  4347. 'qps' => 'application/vnd.publishare-delta-tree',
  4348. 'qt' => 'video/quicktime',
  4349. 'qwd' => 'application/vnd.quark.quarkxpress',
  4350. 'qwt' => 'application/vnd.quark.quarkxpress',
  4351. 'qxb' => 'application/vnd.quark.quarkxpress',
  4352. 'qxd' => 'application/vnd.quark.quarkxpress',
  4353. 'qxl' => 'application/vnd.quark.quarkxpress',
  4354. 'qxt' => 'application/vnd.quark.quarkxpress',
  4355. 'ra' => 'audio/x-pn-realaudio',
  4356. 'ram' => 'audio/x-pn-realaudio',
  4357. 'rar' => 'application/x-rar-compressed',
  4358. 'ras' => 'image/x-cmu-raster',
  4359. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  4360. 'rdf' => 'application/rdf+xml',
  4361. 'rdz' => 'application/vnd.data-vision.rdz',
  4362. 'rep' => 'application/vnd.businessobjects',
  4363. 'res' => 'application/x-dtbresource+xml',
  4364. 'rgb' => 'image/x-rgb',
  4365. 'rif' => 'application/reginfo+xml',
  4366. 'rip' => 'audio/vnd.rip',
  4367. 'ris' => 'application/x-research-info-systems',
  4368. 'rl' => 'application/resource-lists+xml',
  4369. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  4370. 'rld' => 'application/resource-lists-diff+xml',
  4371. 'rm' => 'application/vnd.rn-realmedia',
  4372. 'rmi' => 'audio/midi',
  4373. 'rmp' => 'audio/x-pn-realaudio-plugin',
  4374. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  4375. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  4376. 'rnc' => 'application/relax-ng-compact-syntax',
  4377. 'roa' => 'application/rpki-roa',
  4378. 'roff' => 'text/troff',
  4379. 'rp9' => 'application/vnd.cloanto.rp9',
  4380. 'rpss' => 'application/vnd.nokia.radio-presets',
  4381. 'rpst' => 'application/vnd.nokia.radio-preset',
  4382. 'rq' => 'application/sparql-query',
  4383. 'rs' => 'application/rls-services+xml',
  4384. 'rsd' => 'application/rsd+xml',
  4385. 'rss' => 'application/rss+xml',
  4386. 'rtf' => 'application/rtf',
  4387. 'rtx' => 'text/richtext',
  4388. 's' => 'text/x-asm',
  4389. 's3m' => 'audio/s3m',
  4390. 'saf' => 'application/vnd.yamaha.smaf-audio',
  4391. 'sbml' => 'application/sbml+xml',
  4392. 'sc' => 'application/vnd.ibm.secure-container',
  4393. 'scd' => 'application/x-msschedule',
  4394. 'scm' => 'application/vnd.lotus-screencam',
  4395. 'scq' => 'application/scvp-cv-request',
  4396. 'scs' => 'application/scvp-cv-response',
  4397. 'scurl' => 'text/vnd.curl.scurl',
  4398. 'sda' => 'application/vnd.stardivision.draw',
  4399. 'sdc' => 'application/vnd.stardivision.calc',
  4400. 'sdd' => 'application/vnd.stardivision.impress',
  4401. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  4402. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  4403. 'sdp' => 'application/sdp',
  4404. 'sdw' => 'application/vnd.stardivision.writer',
  4405. 'see' => 'application/vnd.seemail',
  4406. 'seed' => 'application/vnd.fdsn.seed',
  4407. 'sema' => 'application/vnd.sema',
  4408. 'semd' => 'application/vnd.semd',
  4409. 'semf' => 'application/vnd.semf',
  4410. 'ser' => 'application/java-serialized-object',
  4411. 'setpay' => 'application/set-payment-initiation',
  4412. 'setreg' => 'application/set-registration-initiation',
  4413. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  4414. 'sfs' => 'application/vnd.spotfire.sfs',
  4415. 'sfv' => 'text/x-sfv',
  4416. 'sgi' => 'image/sgi',
  4417. 'sgl' => 'application/vnd.stardivision.writer-global',
  4418. 'sgm' => 'text/sgml',
  4419. 'sgml' => 'text/sgml',
  4420. 'sh' => 'application/x-sh',
  4421. 'shar' => 'application/x-shar',
  4422. 'shf' => 'application/shf+xml',
  4423. 'sid' => 'image/x-mrsid-image',
  4424. 'sig' => 'application/pgp-signature',
  4425. 'sil' => 'audio/silk',
  4426. 'silo' => 'model/mesh',
  4427. 'sis' => 'application/vnd.symbian.install',
  4428. 'sisx' => 'application/vnd.symbian.install',
  4429. 'sit' => 'application/x-stuffit',
  4430. 'sitx' => 'application/x-stuffitx',
  4431. 'skd' => 'application/vnd.koan',
  4432. 'skm' => 'application/vnd.koan',
  4433. 'skp' => 'application/vnd.koan',
  4434. 'skt' => 'application/vnd.koan',
  4435. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  4436. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  4437. 'slt' => 'application/vnd.epson.salt',
  4438. 'sm' => 'application/vnd.stepmania.stepchart',
  4439. 'smf' => 'application/vnd.stardivision.math',
  4440. 'smi' => 'application/smil+xml',
  4441. 'smil' => 'application/smil+xml',
  4442. 'smv' => 'video/x-smv',
  4443. 'smzip' => 'application/vnd.stepmania.package',
  4444. 'snd' => 'audio/basic',
  4445. 'snf' => 'application/x-font-snf',
  4446. 'so' => 'application/octet-stream',
  4447. 'spc' => 'application/x-pkcs7-certificates',
  4448. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  4449. 'spl' => 'application/x-futuresplash',
  4450. 'spot' => 'text/vnd.in3d.spot',
  4451. 'spp' => 'application/scvp-vp-response',
  4452. 'spq' => 'application/scvp-vp-request',
  4453. 'spx' => 'audio/ogg',
  4454. 'sql' => 'application/x-sql',
  4455. 'src' => 'application/x-wais-source',
  4456. 'srt' => 'application/x-subrip',
  4457. 'sru' => 'application/sru+xml',
  4458. 'srx' => 'application/sparql-results+xml',
  4459. 'ssdl' => 'application/ssdl+xml',
  4460. 'sse' => 'application/vnd.kodak-descriptor',
  4461. 'ssf' => 'application/vnd.epson.ssf',
  4462. 'ssml' => 'application/ssml+xml',
  4463. 'st' => 'application/vnd.sailingtracker.track',
  4464. 'stc' => 'application/vnd.sun.xml.calc.template',
  4465. 'std' => 'application/vnd.sun.xml.draw.template',
  4466. 'stf' => 'application/vnd.wt.stf',
  4467. 'sti' => 'application/vnd.sun.xml.impress.template',
  4468. 'stk' => 'application/hyperstudio',
  4469. 'stl' => 'application/vnd.ms-pki.stl',
  4470. 'str' => 'application/vnd.pg.format',
  4471. 'stw' => 'application/vnd.sun.xml.writer.template',
  4472. 'sub' => 'image/vnd.dvb.subtitle',
  4473. 'sub' => 'text/vnd.dvb.subtitle',
  4474. 'sus' => 'application/vnd.sus-calendar',
  4475. 'susp' => 'application/vnd.sus-calendar',
  4476. 'sv4cpio' => 'application/x-sv4cpio',
  4477. 'sv4crc' => 'application/x-sv4crc',
  4478. 'svc' => 'application/vnd.dvb.service',
  4479. 'svd' => 'application/vnd.svd',
  4480. 'svg' => 'image/svg+xml',
  4481. 'svgz' => 'image/svg+xml',
  4482. 'swa' => 'application/x-director',
  4483. 'swf' => 'application/x-shockwave-flash',
  4484. 'swi' => 'application/vnd.aristanetworks.swi',
  4485. 'sxc' => 'application/vnd.sun.xml.calc',
  4486. 'sxd' => 'application/vnd.sun.xml.draw',
  4487. 'sxg' => 'application/vnd.sun.xml.writer.global',
  4488. 'sxi' => 'application/vnd.sun.xml.impress',
  4489. 'sxm' => 'application/vnd.sun.xml.math',
  4490. 'sxw' => 'application/vnd.sun.xml.writer',
  4491. 't' => 'text/troff',
  4492. 't3' => 'application/x-t3vm-image',
  4493. 'taglet' => 'application/vnd.mynfc',
  4494. 'tao' => 'application/vnd.tao.intent-module-archive',
  4495. 'tar' => 'application/x-tar',
  4496. 'tcap' => 'application/vnd.3gpp2.tcap',
  4497. 'tcl' => 'application/x-tcl',
  4498. 'teacher' => 'application/vnd.smart.teacher',
  4499. 'tei' => 'application/tei+xml',
  4500. 'teicorpus' => 'application/tei+xml',
  4501. 'tex' => 'application/x-tex',
  4502. 'texi' => 'application/x-texinfo',
  4503. 'texinfo' => 'application/x-texinfo',
  4504. 'text' => 'text/plain',
  4505. 'tfi' => 'application/thraud+xml',
  4506. 'tfm' => 'application/x-tex-tfm',
  4507. 'tga' => 'image/x-tga',
  4508. 'thmx' => 'application/vnd.ms-officetheme',
  4509. 'tif' => 'image/tiff',
  4510. 'tiff' => 'image/tiff',
  4511. 'tmo' => 'application/vnd.tmobile-livetv',
  4512. 'torrent' => 'application/x-bittorrent',
  4513. 'tpl' => 'application/vnd.groove-tool-template',
  4514. 'tpt' => 'application/vnd.trid.tpt',
  4515. 'tr' => 'text/troff',
  4516. 'tra' => 'application/vnd.trueapp',
  4517. 'trm' => 'application/x-msterminal',
  4518. 'tsd' => 'application/timestamped-data',
  4519. 'tsv' => 'text/tab-separated-values',
  4520. 'ttc' => 'application/x-font-ttf',
  4521. 'ttf' => 'application/x-font-ttf',
  4522. 'ttl' => 'text/turtle',
  4523. 'twd' => 'application/vnd.simtech-mindmapper',
  4524. 'twds' => 'application/vnd.simtech-mindmapper',
  4525. 'txd' => 'application/vnd.genomatix.tuxedo',
  4526. 'txf' => 'application/vnd.mobius.txf',
  4527. 'txt' => 'text/plain',
  4528. 'u32' => 'application/x-authorware-bin',
  4529. 'udeb' => 'application/x-debian-package',
  4530. 'ufd' => 'application/vnd.ufdl',
  4531. 'ufdl' => 'application/vnd.ufdl',
  4532. 'ulx' => 'application/x-glulx',
  4533. 'umj' => 'application/vnd.umajin',
  4534. 'unityweb' => 'application/vnd.unity',
  4535. 'uoml' => 'application/vnd.uoml+xml',
  4536. 'uri' => 'text/uri-list',
  4537. 'uris' => 'text/uri-list',
  4538. 'urls' => 'text/uri-list',
  4539. 'ustar' => 'application/x-ustar',
  4540. 'utz' => 'application/vnd.uiq.theme',
  4541. 'uu' => 'text/x-uuencode',
  4542. 'uva' => 'audio/vnd.dece.audio',
  4543. 'uvd' => 'application/vnd.dece.data',
  4544. 'uvf' => 'application/vnd.dece.data',
  4545. 'uvg' => 'image/vnd.dece.graphic',
  4546. 'uvh' => 'video/vnd.dece.hd',
  4547. 'uvi' => 'image/vnd.dece.graphic',
  4548. 'uvm' => 'video/vnd.dece.mobile',
  4549. 'uvp' => 'video/vnd.dece.pd',
  4550. 'uvs' => 'video/vnd.dece.sd',
  4551. 'uvt' => 'application/vnd.dece.ttml+xml',
  4552. 'uvu' => 'video/vnd.uvvu.mp4',
  4553. 'uvv' => 'video/vnd.dece.video',
  4554. 'uvva' => 'audio/vnd.dece.audio',
  4555. 'uvvd' => 'application/vnd.dece.data',
  4556. 'uvvf' => 'application/vnd.dece.data',
  4557. 'uvvg' => 'image/vnd.dece.graphic',
  4558. 'uvvh' => 'video/vnd.dece.hd',
  4559. 'uvvi' => 'image/vnd.dece.graphic',
  4560. 'uvvm' => 'video/vnd.dece.mobile',
  4561. 'uvvp' => 'video/vnd.dece.pd',
  4562. 'uvvs' => 'video/vnd.dece.sd',
  4563. 'uvvt' => 'application/vnd.dece.ttml+xml',
  4564. 'uvvu' => 'video/vnd.uvvu.mp4',
  4565. 'uvvv' => 'video/vnd.dece.video',
  4566. 'uvvx' => 'application/vnd.dece.unspecified',
  4567. 'uvvz' => 'application/vnd.dece.zip',
  4568. 'uvx' => 'application/vnd.dece.unspecified',
  4569. 'uvz' => 'application/vnd.dece.zip',
  4570. 'vcard' => 'text/vcard',
  4571. 'vcd' => 'application/x-cdlink',
  4572. 'vcf' => 'text/x-vcard',
  4573. 'vcg' => 'application/vnd.groove-vcard',
  4574. 'vcs' => 'text/x-vcalendar',
  4575. 'vcx' => 'application/vnd.vcx',
  4576. 'vis' => 'application/vnd.visionary',
  4577. 'viv' => 'video/vnd.vivo',
  4578. 'vob' => 'video/x-ms-vob',
  4579. 'vor' => 'application/vnd.stardivision.writer',
  4580. 'vox' => 'application/x-authorware-bin',
  4581. 'vrml' => 'model/vrml',
  4582. 'vsd' => 'application/vnd.visio',
  4583. 'vsf' => 'application/vnd.vsf',
  4584. 'vss' => 'application/vnd.visio',
  4585. 'vst' => 'application/vnd.visio',
  4586. 'vsw' => 'application/vnd.visio',
  4587. 'vtu' => 'model/vnd.vtu',
  4588. 'vxml' => 'application/voicexml+xml',
  4589. 'w3d' => 'application/x-director',
  4590. 'wad' => 'application/x-doom',
  4591. 'wav' => 'audio/x-wav',
  4592. 'wax' => 'audio/x-ms-wax',
  4593. 'wbmp' => 'image/vnd.wap.wbmp',
  4594. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  4595. 'wbxml' => 'application/vnd.wap.wbxml',
  4596. 'wcm' => 'application/vnd.ms-works',
  4597. 'wdb' => 'application/vnd.ms-works',
  4598. 'wdp' => 'image/vnd.ms-photo',
  4599. 'weba' => 'audio/webm',
  4600. 'webm' => 'video/webm',
  4601. 'webp' => 'image/webp',
  4602. 'wg' => 'application/vnd.pmi.widget',
  4603. 'wgt' => 'application/widget',
  4604. 'wks' => 'application/vnd.ms-works',
  4605. 'wm' => 'video/x-ms-wm',
  4606. 'wma' => 'audio/x-ms-wma',
  4607. 'wmd' => 'application/x-ms-wmd',
  4608. 'wmf' => 'application/x-msmetafile',
  4609. 'wml' => 'text/vnd.wap.wml',
  4610. 'wmlc' => 'application/vnd.wap.wmlc',
  4611. 'wmls' => 'text/vnd.wap.wmlscript',
  4612. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  4613. 'wmv' => 'video/x-ms-wmv',
  4614. 'wmx' => 'video/x-ms-wmx',
  4615. 'wmz' => 'application/x-ms-wmz',
  4616. 'wmz' => 'application/x-msmetafile',
  4617. 'woff' => 'application/font-woff',
  4618. 'wpd' => 'application/vnd.wordperfect',
  4619. 'wpl' => 'application/vnd.ms-wpl',
  4620. 'wps' => 'application/vnd.ms-works',
  4621. 'wqd' => 'application/vnd.wqd',
  4622. 'wri' => 'application/x-mswrite',
  4623. 'wrl' => 'model/vrml',
  4624. 'wsdl' => 'application/wsdl+xml',
  4625. 'wspolicy' => 'application/wspolicy+xml',
  4626. 'wtb' => 'application/vnd.webturbo',
  4627. 'wvx' => 'video/x-ms-wvx',
  4628. 'x32' => 'application/x-authorware-bin',
  4629. 'x3d' => 'model/x3d+xml',
  4630. 'x3db' => 'model/x3d+binary',
  4631. 'x3dbz' => 'model/x3d+binary',
  4632. 'x3dv' => 'model/x3d+vrml',
  4633. 'x3dvz' => 'model/x3d+vrml',
  4634. 'x3dz' => 'model/x3d+xml',
  4635. 'xaml' => 'application/xaml+xml',
  4636. 'xap' => 'application/x-silverlight-app',
  4637. 'xar' => 'application/vnd.xara',
  4638. 'xbap' => 'application/x-ms-xbap',
  4639. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  4640. 'xbm' => 'image/x-xbitmap',
  4641. 'xdf' => 'application/xcap-diff+xml',
  4642. 'xdm' => 'application/vnd.syncml.dm+xml',
  4643. 'xdp' => 'application/vnd.adobe.xdp+xml',
  4644. 'xdssc' => 'application/dssc+xml',
  4645. 'xdw' => 'application/vnd.fujixerox.docuworks',
  4646. 'xenc' => 'application/xenc+xml',
  4647. 'xer' => 'application/patch-ops-error+xml',
  4648. 'xfdf' => 'application/vnd.adobe.xfdf',
  4649. 'xfdl' => 'application/vnd.xfdl',
  4650. 'xht' => 'application/xhtml+xml',
  4651. 'xhtml' => 'application/xhtml+xml',
  4652. 'xhvml' => 'application/xv+xml',
  4653. 'xif' => 'image/vnd.xiff',
  4654. 'xla' => 'application/vnd.ms-excel',
  4655. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  4656. 'xlc' => 'application/vnd.ms-excel',
  4657. 'xlf' => 'application/x-xliff+xml',
  4658. 'xlm' => 'application/vnd.ms-excel',
  4659. 'xls' => 'application/vnd.ms-excel',
  4660. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  4661. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  4662. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  4663. 'xlt' => 'application/vnd.ms-excel',
  4664. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  4665. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  4666. 'xlw' => 'application/vnd.ms-excel',
  4667. 'xm' => 'audio/xm',
  4668. 'xml' => 'application/xml',
  4669. 'xo' => 'application/vnd.olpc-sugar',
  4670. 'xop' => 'application/xop+xml',
  4671. 'xpi' => 'application/x-xpinstall',
  4672. 'xpl' => 'application/xproc+xml',
  4673. 'xpm' => 'image/x-xpixmap',
  4674. 'xpr' => 'application/vnd.is-xpr',
  4675. 'xps' => 'application/vnd.ms-xpsdocument',
  4676. 'xpw' => 'application/vnd.intercon.formnet',
  4677. 'xpx' => 'application/vnd.intercon.formnet',
  4678. 'xsl' => 'application/xml',
  4679. 'xslt' => 'application/xslt+xml',
  4680. 'xsm' => 'application/vnd.syncml+xml',
  4681. 'xspf' => 'application/xspf+xml',
  4682. 'xul' => 'application/vnd.mozilla.xul+xml',
  4683. 'xvm' => 'application/xv+xml',
  4684. 'xvml' => 'application/xv+xml',
  4685. 'xwd' => 'image/x-xwindowdump',
  4686. 'xyz' => 'chemical/x-xyz',
  4687. 'xz' => 'application/x-xz',
  4688. 'yang' => 'application/yang',
  4689. 'yin' => 'application/yin+xml',
  4690. 'z1' => 'application/x-zmachine',
  4691. 'z2' => 'application/x-zmachine',
  4692. 'z3' => 'application/x-zmachine',
  4693. 'z4' => 'application/x-zmachine',
  4694. 'z5' => 'application/x-zmachine',
  4695. 'z6' => 'application/x-zmachine',
  4696. 'z7' => 'application/x-zmachine',
  4697. 'z8' => 'application/x-zmachine',
  4698. 'zaz' => 'application/vnd.zzazz.deck+xml',
  4699. 'zip' => 'application/zip',
  4700. 'zir' => 'application/vnd.zul',
  4701. 'zirz' => 'application/vnd.zul',
  4702. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  4703. );
  4704. }
  4705. // Always run this
  4706. dependCheck();