functions.php 209 KB

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