functions.php 207 KB

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