functions.php 354 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.61');
  5. // ===================================
  6. $debugOrganizr = true;
  7. if($debugOrganizr == true && file_exists('debug.php')){ require_once('debug.php'); }
  8. use Kryptonit3\Sonarr\Sonarr;
  9. use Kryptonit3\SickRage\SickRage;
  10. //homepage order
  11. function homepageOrder(){
  12. $homepageOrder = array(
  13. "homepageOrdercustomhtml" => homepageOrdercustomhtml,
  14. "homepageOrdernotice" => homepageOrdernotice,
  15. "homepageOrderplexsearch" => homepageOrderplexsearch,
  16. "homepageOrderspeedtest" => homepageOrderspeedtest,
  17. "homepageOrdernzbget" => homepageOrdernzbget,
  18. "homepageOrdersabnzbd" => homepageOrdersabnzbd,
  19. "homepageOrderplexnowplaying" => homepageOrderplexnowplaying,
  20. "homepageOrderplexrecent" => homepageOrderplexrecent,
  21. "homepageOrderplexplaylist" => homepageOrderplexplaylist,
  22. "homepageOrderembynowplaying" => homepageOrderembynowplaying,
  23. "homepageOrderembyrecent" => homepageOrderembyrecent,
  24. "homepageOrderombi" => homepageOrderombi,
  25. "homepageOrdercalendar" => homepageOrdercalendar,
  26. "homepageOrdernoticeguest" => homepageOrdernoticeguest,
  27. "homepageOrdertransmisson" => homepageOrdertransmisson,
  28. );
  29. asort($homepageOrder);
  30. return $homepageOrder;
  31. }
  32. // Debugging output functions
  33. function debug_out($variable, $die = false) {
  34. $trace = debug_backtrace()[0];
  35. echo "<center><img height='200px' src='images/confused.png'></center>";
  36. echo "<center>Look's like something happened, here are the errors and perhaps how to fix them:</center>";
  37. 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>';
  38. if ($die) { http_response_code(503); die(); }
  39. }
  40. //Cookie Function
  41. function coookie($type, $name, $value = '', $days = -1, $http = true){
  42. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  43. $Secure = true;
  44. $HTTPOnly = true;
  45. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  46. $Secure = true;
  47. $HTTPOnly = true;
  48. } else {
  49. $Secure = false;
  50. $HTTPOnly = false;
  51. }
  52. if(!$http){ $HTTPOnly = false; }
  53. $Path = '/';
  54. $Domain = $_SERVER['HTTP_HOST'];
  55. $Port = strpos($Domain, ':');
  56. if ($Port !== false) $Domain = substr($Domain, 0, $Port);
  57. $Port = strpos($Domain, ':');
  58. $check = substr_count($Domain, '.');
  59. if($check >= 3){
  60. if(is_numeric($Domain[0])){
  61. $Domain = '';
  62. }else{
  63. $Domain = '.'.explode('.',$Domain)[1].'.'.explode('.',$Domain)[2].'.'.explode('.',$Domain)[3];
  64. }
  65. }elseif($check == 2){
  66. $Domain = '.'.explode('.',$Domain)[1].'.'.explode('.',$Domain)[2];
  67. }elseif($check == 1){
  68. $Domain = '.' . $Domain;
  69. }else{
  70. $Domain = '';
  71. }
  72. if($type = 'set'){
  73. $_COOKIE[$name] = $value;
  74. header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)
  75. . (empty($days) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', time() + (86400 * $days)) . ' GMT')
  76. . (empty($Path) ? '' : '; path=' . $Path)
  77. . (empty($Domain) ? '' : '; domain=' . $Domain)
  78. . (!$Secure ? '' : '; secure')
  79. . (!$HTTPOnly ? '' : '; HttpOnly'), false);
  80. }elseif($type = 'delete'){
  81. unset($_COOKIE[$name]);
  82. header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)
  83. . (empty($days) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', time() - 3600) . ' GMT')
  84. . (empty($Path) ? '' : '; path=' . $Path)
  85. . (empty($Domain) ? '' : '; domain=' . $Domain)
  86. . (!$Secure ? '' : '; secure')
  87. . (!$HTTPOnly ? '' : '; HttpOnly'), false);
  88. }
  89. }
  90. // ==== Auth Plugins START ====
  91. if (function_exists('ldap_connect')) :
  92. // Pass credentials to LDAP backend
  93. function plugin_auth_ldap($username, $password) {
  94. $ldapServers = explode(',',AUTHBACKENDHOST);
  95. foreach($ldapServers as $key => $value) {
  96. // Calculate parts
  97. $digest = parse_url(trim($value));
  98. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  99. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  100. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  101. // Reassign
  102. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  103. }
  104. // returns true or false
  105. $ldap = ldap_connect(implode(' ',$ldapServers));
  106. if(empty(AUTHBACKENDDOMAINFORMAT)){
  107. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  108. writeLog("success", "LDAP authentication success");
  109. return true;
  110. } else {
  111. writeLog("error", "LDAP could not authenticate");
  112. return false;
  113. }
  114. }else{
  115. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  116. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  117. $bind = @ldap_bind($ldap, sprintf(AUTHBACKENDDOMAINFORMAT, $username), $password);
  118. if ($bind) {
  119. writeLog("success", "LDAP authentication success");
  120. return true;
  121. } else {
  122. writeLog("error", "LDPA could not authenticate");
  123. return false;
  124. }
  125. }
  126. writeLog("error", "LDAP could not authenticate");
  127. return false;
  128. }
  129. else :
  130. // Ldap Auth Missing Dependancy
  131. function plugin_auth_ldap_disabled() {
  132. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  133. }
  134. endif;
  135. // Pass credentials to FTP backend
  136. function plugin_auth_ftp($username, $password) {
  137. // Calculate parts
  138. $digest = parse_url(AUTHBACKENDHOST);
  139. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  140. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  141. $port = (isset($digest['port'])?$digest['port']:21);
  142. // Determine Connection Type
  143. if ($scheme == 'ftps') {
  144. $conn_id = ftp_ssl_connect($host, $port, 20);
  145. } elseif ($scheme == 'ftp') {
  146. $conn_id = ftp_connect($host, $port, 20);
  147. } else {
  148. debug_out('Invalid FTP scheme. Use ftp or ftps');
  149. writeLog("error", "invalid FTP scheme");
  150. return false;
  151. }
  152. // Check if valid FTP connection
  153. if ($conn_id) {
  154. // Attempt login
  155. @$login_result = ftp_login($conn_id, $username, $password);
  156. ftp_close($conn_id);
  157. // Return Result
  158. if ($login_result) {
  159. writeLog("success", "$username authenticated");
  160. return true;
  161. } else {
  162. writeLog("error", "$username could not authenticate");
  163. return false;
  164. }
  165. } else {
  166. return false;
  167. }
  168. return false;
  169. }
  170. // Pass credentials to Emby Backend
  171. function plugin_auth_emby_local($username, $password) {
  172. $embyAddress = qualifyURL(EMBYURL);
  173. $headers = array(
  174. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  175. 'Content-Type' => 'application/json',
  176. );
  177. $body = array(
  178. 'Username' => $username,
  179. 'Password' => sha1($password),
  180. 'PasswordMd5' => md5($password),
  181. );
  182. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  183. if (isset($response['content'])) {
  184. $json = json_decode($response['content'], true);
  185. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  186. // Login Success - Now Logout Emby Session As We No Longer Need It
  187. $headers = array(
  188. 'X-Mediabrowser-Token' => $json['AccessToken'],
  189. );
  190. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  191. return true;
  192. }
  193. }
  194. return false;
  195. }
  196. if (function_exists('curl_version')) :
  197. // Authenticate Against Emby Local (first) and Emby Connect
  198. function plugin_auth_emby_all($username, $password) {
  199. $localResult = plugin_auth_emby_local($username, $password);
  200. if ($localResult) {
  201. return $localResult;
  202. } else {
  203. return plugin_auth_emby_connect($username, $password);
  204. }
  205. }
  206. // Authenicate against emby connect
  207. function plugin_auth_emby_connect($username, $password) {
  208. $embyAddress = qualifyURL(EMBYURL);
  209. // Get A User
  210. $connectId = '';
  211. $userIds = json_decode(@file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  212. if (is_array($userIds)) {
  213. foreach ($userIds as $key => $value) { // Scan for this user
  214. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  215. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  216. $connectId = $value['ConnectUserId'];
  217. break;
  218. }
  219. }
  220. }
  221. if ($connectId) {
  222. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  223. $headers = array(
  224. 'Accept'=> 'application/json',
  225. 'Content-Type' => 'application/x-www-form-urlencoded',
  226. );
  227. $body = array(
  228. 'nameOrEmail' => $username,
  229. 'rawpw' => $password,
  230. );
  231. $result = curl_post($connectURL, $body, $headers);
  232. if (isset($result['content'])) {
  233. $json = json_decode($result['content'], true);
  234. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  235. return array(
  236. 'email' => $json['User']['Email'],
  237. 'image' => $json['User']['ImageUrl'],
  238. );
  239. }
  240. }
  241. }
  242. }
  243. return false;
  244. }
  245. // Pass credentials to Plex Backend
  246. function plugin_auth_plex($username, $password) {
  247. // Quick out
  248. $isAdmin = false;
  249. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  250. writeLog("success", "Admin: ".$username." authenticated as plex Admin");
  251. $isAdmin = true;
  252. }
  253. //Get User List
  254. $userURL = 'https://plex.tv/pms/friends/all';
  255. $userHeaders = array(
  256. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  257. );
  258. libxml_use_internal_errors(true);
  259. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  260. if (is_array($userXML) || is_object($userXML)) {
  261. $isUser = false;
  262. $usernameLower = strtolower($username);
  263. foreach($userXML AS $child) {
  264. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  265. $isUser = true;
  266. writeLog("success", $usernameLower." was found in plex friends list");
  267. break;
  268. }
  269. }
  270. if ($isUser || $isAdmin) {
  271. //Login User
  272. $connectURL = 'https://plex.tv/users/sign_in.json';
  273. $headers = array(
  274. 'Accept'=> 'application/json',
  275. 'Content-Type' => 'application/x-www-form-urlencoded',
  276. 'X-Plex-Product' => 'Organizr',
  277. 'X-Plex-Version' => '1.0',
  278. 'X-Plex-Client-Identifier' => '01010101-10101010',
  279. );
  280. $body = array(
  281. 'user[login]' => $username,
  282. 'user[password]' => $password,
  283. );
  284. $result = curl_post($connectURL, $body, $headers);
  285. if (isset($result['content'])) {
  286. $json = json_decode($result['content'], true);
  287. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  288. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  289. return array(
  290. 'email' => $json['user']['email'],
  291. 'image' => $json['user']['thumb'],
  292. 'token' => $json['user']['authToken'],
  293. 'type' => $isAdmin ? 'admin' : 'user',
  294. );
  295. }
  296. }
  297. }else{
  298. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  299. }
  300. }else{
  301. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  302. }
  303. return false;
  304. }
  305. else :
  306. // Plex Auth Missing Dependancy
  307. function plugin_auth_plex_disabled() {
  308. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  309. }
  310. // Emby Connect Auth Missing Dependancy
  311. function plugin_auth_emby_connect_disabled() {
  312. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  313. }
  314. // Emby Both Auth Missing Dependancy
  315. function plugin_auth_emby_both_disabled() {
  316. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  317. }
  318. endif;
  319. // ==== Auth Plugins END ====
  320. // ==== General Class Definitions START ====
  321. $userLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  322. class setLanguage {
  323. private $language = null;
  324. private $langCode = null;
  325. function __construct($language = false) {
  326. // Default
  327. if (!$language) {
  328. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  329. }
  330. if (!file_exists("lang/{$language}.ini")) {
  331. $language = 'en';
  332. }
  333. $this->langCode = $language;
  334. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  335. if (file_exists("lang/{$language}.cust.ini")) {
  336. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  337. $this->language[$k] = $v;
  338. }
  339. }
  340. }
  341. public function getLang() {
  342. return $this->langCode;
  343. }
  344. public function translate($originalWord) {
  345. $getArg = func_num_args();
  346. if ($getArg > 1) {
  347. $allWords = func_get_args();
  348. array_shift($allWords);
  349. } else {
  350. $allWords = array();
  351. }
  352. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  353. if (!$translatedWord) {
  354. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  355. //echo "WHOA!!!!!!! $originalWord";
  356. }
  357. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  358. return vsprintf($translatedWord, $allWords);
  359. }
  360. }
  361. $language = new setLanguage;
  362. // ==== General Class Definitions END ====
  363. // Direct request to curl if it exists, otherwise handle if not HTTPS
  364. function post_router($url, $data, $headers = array(), $referer='') {
  365. if (function_exists('curl_version')) {
  366. return curl_post($url, $data, $headers, $referer);
  367. } else {
  368. return post_request($url, $data, $headers, $referer);
  369. }
  370. }
  371. if (function_exists('curl_version')) :
  372. // Curl Post
  373. function curl_post($url, $data, $headers = array(), $referer='') {
  374. // Initiate cURL
  375. $curlReq = curl_init($url);
  376. // As post request
  377. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  378. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  379. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  380. if(localURL($url)){
  381. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  382. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  383. }
  384. // Format Data
  385. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  386. case 'application/json':
  387. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  388. break;
  389. case 'application/x-www-form-urlencoded':
  390. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  391. break;
  392. default:
  393. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  394. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  395. }
  396. // Format Headers
  397. $cHeaders = array();
  398. foreach ($headers as $k => $v) {
  399. $cHeaders[] = $k.': '.$v;
  400. }
  401. if (count($cHeaders)) {
  402. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  403. }
  404. // Execute
  405. $result = curl_exec($curlReq);
  406. $httpcode = curl_getinfo($curlReq);
  407. // Close
  408. curl_close($curlReq);
  409. // Return
  410. return array('content'=>$result, 'http_code'=>$httpcode);
  411. }
  412. // Curl Put
  413. function curl_put($url, $data, $headers = array(), $referer='') {
  414. // Initiate cURL
  415. $curlReq = curl_init($url);
  416. // As post request
  417. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "PUT");
  418. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  419. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  420. if(localURL($url)){
  421. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  422. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  423. }
  424. // Format Data
  425. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  426. case 'application/json':
  427. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  428. break;
  429. case 'application/x-www-form-urlencoded':
  430. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  431. break;
  432. default:
  433. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  434. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  435. }
  436. // Format Headers
  437. $cHeaders = array();
  438. foreach ($headers as $k => $v) {
  439. $cHeaders[] = $k.': '.$v;
  440. }
  441. if (count($cHeaders)) {
  442. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  443. }
  444. // Execute
  445. $result = curl_exec($curlReq);
  446. $httpcode = curl_getinfo($curlReq);
  447. // Close
  448. curl_close($curlReq);
  449. // Return
  450. return array('content'=>$result, 'http_code'=>$httpcode);
  451. }
  452. //Curl Get Function
  453. function curl_get($url, $headers = array()) {
  454. // Initiate cURL
  455. $curlReq = curl_init($url);
  456. // As post request
  457. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  458. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  459. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  460. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  461. if(localURL($url)){
  462. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  463. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  464. }
  465. // Format Headers
  466. $cHeaders = array();
  467. foreach ($headers as $k => $v) {
  468. $cHeaders[] = $k.': '.$v;
  469. }
  470. if (count($cHeaders)) {
  471. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  472. }
  473. // Execute
  474. $result = curl_exec($curlReq);
  475. // Close
  476. curl_close($curlReq);
  477. // Return
  478. return $result;
  479. }
  480. //Curl Delete Function
  481. function curl_delete($url, $headers = array()) {
  482. // Initiate cURL
  483. $curlReq = curl_init($url);
  484. // As post request
  485. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  486. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  487. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  488. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  489. if(localURL($url)){
  490. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  491. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  492. }
  493. // Format Headers
  494. $cHeaders = array();
  495. foreach ($headers as $k => $v) {
  496. $cHeaders[] = $k.': '.$v;
  497. }
  498. if (count($cHeaders)) {
  499. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  500. }
  501. // Execute
  502. $result = curl_exec($curlReq);
  503. $httpcode = curl_getinfo($curlReq);
  504. // Close
  505. curl_close($curlReq);
  506. // Return
  507. return array('content'=>$result, 'http_code'=>$httpcode);
  508. }
  509. endif;
  510. //Case-Insensitive Function
  511. function in_arrayi($needle, $haystack) {
  512. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  513. }
  514. // HTTP post request (Removes need for curl, probably useless)
  515. function post_request($url, $data, $headers = array(), $referer='') {
  516. // Adapted from http://stackoverflow.com/a/28387011/6810513
  517. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  518. if (isset($headers['Content-Type'])) {
  519. switch ($headers['Content-Type']) {
  520. case 'application/json':
  521. $data = json_encode($data);
  522. break;
  523. case 'application/x-www-form-urlencoded':
  524. $data = http_build_query($data);
  525. break;
  526. }
  527. } else {
  528. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  529. $data = http_build_query($data);
  530. }
  531. // parse the given URL
  532. $urlDigest = parse_url($url);
  533. // extract host and path:
  534. $host = $urlDigest['host'];
  535. $path = $urlDigest['path'];
  536. if ($urlDigest['scheme'] != 'http') {
  537. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  538. }
  539. // open a socket connection on port 80 - timeout: 30 sec
  540. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  541. if ($fp){
  542. // send the request headers:
  543. fputs($fp, "POST $path HTTP/1.1\r\n");
  544. fputs($fp, "Host: $host\r\n");
  545. if ($referer != '')
  546. fputs($fp, "Referer: $referer\r\n");
  547. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  548. foreach($headers as $k => $v) {
  549. fputs($fp, $k.": ".$v."\r\n");
  550. }
  551. fputs($fp, "Connection: close\r\n\r\n");
  552. fputs($fp, $data);
  553. $result = '';
  554. while(!feof($fp)) {
  555. // receive the results of the request
  556. $result .= fgets($fp, 128);
  557. }
  558. }
  559. else {
  560. return array(
  561. 'status' => 'err',
  562. 'error' => "$errstr ($errno)"
  563. );
  564. }
  565. // close the socket connection:
  566. fclose($fp);
  567. // split the result header from the content
  568. $result = explode("\r\n\r\n", $result, 2);
  569. $header = isset($result[0]) ? $result[0] : '';
  570. $content = isset($result[1]) ? $result[1] : '';
  571. // return as structured array:
  572. return array(
  573. 'status' => 'ok',
  574. 'header' => $header,
  575. 'content' => $content,
  576. );
  577. }
  578. // Format item from Emby for Carousel
  579. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  580. // Static Height
  581. $height = 444;
  582. // Get Item Details
  583. $itemDetails = json_decode(@file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  584. /*if (substr_count(EMBYURL, ':') == 2) {
  585. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  586. }else{
  587. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  588. }*/
  589. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  590. switch ($itemDetails['Type']) {
  591. case 'Episode':
  592. case 'Series':
  593. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  594. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  595. $width = 300;
  596. $style = '';
  597. $image = 'slick-image-tall';
  598. if(!$nowPlaying){
  599. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  600. $key = $itemDetails['Id'] . "-list";
  601. $itemType = 'season';
  602. }else{
  603. $height = 281;
  604. $width = 500;
  605. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  606. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  607. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  608. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  609. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  610. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  611. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  612. $stream = $moreInfo['PlayState']['PlayMethod'];
  613. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  614. $id = $moreInfo['DeviceId'];
  615. $streamInfo = buildStream(array(
  616. 'platform' => (string) $moreInfo['Client'],
  617. 'device' => (string) $moreInfo['DeviceName'],
  618. 'stream' => streamType($stream),
  619. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  620. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  621. ));
  622. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  623. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  624. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  625. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  626. }
  627. break;
  628. case 'MusicAlbum':
  629. case 'Audio':
  630. $title = $itemDetails['Name'];
  631. $imageId = $itemDetails['Id'];
  632. $width = 444;
  633. $style = '';
  634. $image = 'slick-image-short';
  635. if(!$nowPlaying){
  636. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  637. $key = $itemDetails['Id'] . "-list";
  638. $itemType = 'album';
  639. }else{
  640. $height = 281;
  641. $width = 500;
  642. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  643. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  644. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  645. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  646. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  647. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  648. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  649. $stream = $moreInfo['PlayState']['PlayMethod'];
  650. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  651. $id = $moreInfo['DeviceId'];
  652. $streamInfo = buildStream(array(
  653. 'platform' => (string) $moreInfo['Client'],
  654. 'device' => (string) $moreInfo['DeviceName'],
  655. 'stream' => streamType($stream),
  656. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  657. ));
  658. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  659. $topTitle = '<h5 class="text-center zero-m elip">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  660. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  661. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  662. }
  663. break;
  664. case 'TvChannel':
  665. $title = $itemDetails['CurrentProgram']['Name'];
  666. $imageId = $itemDetails['Id'];
  667. $width = 300;
  668. $style = '';
  669. $image = 'slick-image-tall';
  670. if(!$nowPlaying){
  671. $imageType = "Primary";
  672. $key = $itemDetails['Id'] . "-list";
  673. }else{
  674. $height = 281;
  675. $width = 500;
  676. $imageType = "Thumb";
  677. $key = $itemDetails['Id'] . "-np";
  678. $useImage = "images/livetv.png";
  679. $watched = "0";
  680. $stream = $moreInfo['PlayState']['PlayMethod'];
  681. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  682. $id = $moreInfo['DeviceId'];
  683. $streamInfo = buildStream(array(
  684. 'platform' => (string) $moreInfo['Client'],
  685. 'device' => (string) $moreInfo['DeviceName'],
  686. 'stream' => streamType($stream),
  687. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  688. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  689. ));
  690. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  691. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  692. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  693. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  694. }
  695. break;
  696. default:
  697. $title = $itemDetails['Name'];
  698. $imageId = $itemDetails['Id'];
  699. $width = 300;
  700. $style = '';
  701. $image = 'slick-image-tall';
  702. if(!$nowPlaying){
  703. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  704. $key = $itemDetails['Id'] . "-list";
  705. $itemType = 'movie';
  706. }else{
  707. $height = 281;
  708. $width = 500;
  709. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  710. $key = $itemDetails['Id'] . "-np";
  711. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  712. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  713. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  714. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  715. $stream = $moreInfo['PlayState']['PlayMethod'];
  716. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  717. $id = $moreInfo['DeviceId'];
  718. $streamInfo = buildStream(array(
  719. 'platform' => (string) $moreInfo['Client'],
  720. 'device' => (string) $moreInfo['DeviceName'],
  721. 'stream' => streamType($stream),
  722. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  723. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  724. ));
  725. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  726. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  727. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  728. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  729. }
  730. }
  731. // If No Overview
  732. if (!isset($itemDetails['Overview'])) {
  733. $itemDetails['Overview'] = '';
  734. }
  735. $original_image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  736. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  737. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  738. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  739. }
  740. if($nowPlaying){
  741. if(!$imageType){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  742. if(!$imageId){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  743. }else{
  744. if(!$imageType){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  745. if(!$imageId){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  746. }
  747. if(isset($useImage)){ $image_url = $useImage; }
  748. // Assemble Item And Cache Into Array
  749. if($nowPlaying){
  750. //prettyPrint($itemDetails);
  751. 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="refreshNP 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'].'" original-image="'.$original_image_url.'" class="refreshImageSource"></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>';
  752. }else{
  753. return '<div class="item-'.$itemType.'"><div class="ultra-widget refreshImage"><span class="w-refresh w-p-icon gray"><span class="fa-stack fa-lg" style="font-size: .4em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-refresh fa-stack-1x fa-inverse"></i></span></span></div><a href="'.$URL.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.' refreshImageSource" data-lazy="'.$image_url.'" original-image="'.$original_image_url.'"></a><small class="elip slick-bottom-title">'.$title.'</small></div>';
  754. }
  755. }
  756. // Format item from Plex for Carousel
  757. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  758. // Static Height
  759. $height = 444;
  760. $widthOverride = 100;
  761. $playlist = ($playlist) ? " playlist-$playlist" : "";
  762. switch ($item['type']) {
  763. case 'season':
  764. $title = $item['parentTitle'];
  765. $summary = $item['parentSummary'];
  766. $width = 300;
  767. $image = 'slick-image-tall';
  768. $style = '';
  769. if(!$nowPlaying){
  770. $thumb = $item['thumb'];
  771. $key = $item['ratingKey'] . "-list";
  772. }else {
  773. $height = 281;
  774. $width = 500;
  775. $thumb = $item['art'];
  776. $key = $item['ratingKey'] . "-np";
  777. $elapsed = $item['viewOffset'];
  778. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  779. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  780. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  781. $stream = $item->Media->Part->Stream['decision'];
  782. $user = $role == "admin" ? $item->User['title'] : "";
  783. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  784. $streamInfo = buildStream(array(
  785. 'platform' => (string) $item->Player['platform'],
  786. 'device' => (string) $item->Player['device'],
  787. 'stream' => streamType($item->Media->Part['decision']),
  788. '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'].")",
  789. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  790. ));
  791. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  792. }
  793. break;
  794. case 'episode':
  795. $title = $item['grandparentTitle'];
  796. $summary = $item['title'];
  797. $width = 300;
  798. $image = 'slick-image-tall';
  799. $style = '';
  800. if(!$nowPlaying){
  801. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  802. $key = $item['ratingKey'] . "-list";
  803. }else {
  804. $height = 281;
  805. $width = 500;
  806. $thumb = $item['art'];
  807. $key = $item['ratingKey'] . "-np";
  808. $elapsed = $item['viewOffset'];
  809. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  810. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  811. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  812. $stream = $item->Media->Part->Stream['decision'];
  813. $user = $role == "admin" ? $item->User['title'] : "";
  814. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  815. $streamInfo = buildStream(array(
  816. 'platform' => (string) $item->Player['platform'],
  817. 'device' => (string) $item->Player['device'],
  818. 'stream' => streamType($item->Media->Part['decision']),
  819. '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'].")",
  820. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  821. ));
  822. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  823. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  824. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  825. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  826. }
  827. break;
  828. case 'clip':
  829. $title = $item['title'];
  830. $summary = $item['summary'];
  831. $width = 300;
  832. $image = 'slick-image-tall';
  833. $style = '';
  834. if(!$nowPlaying){
  835. $thumb = $item['thumb'];
  836. $key = $item['ratingKey'] . "-list";
  837. }else {
  838. $height = 281;
  839. $width = 500;
  840. $thumb = $item['art'];
  841. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  842. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  843. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  844. $elapsed = $item['viewOffset'];
  845. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  846. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  847. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  848. $stream = $item->Media->Part->Stream['decision'];
  849. $user = $role == "admin" ? $item->User['title'] : "";
  850. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  851. $streamInfo = buildStream(array(
  852. 'platform' => (string) $item->Player['platform'],
  853. 'device' => (string) $item->Player['device'],
  854. 'stream' => streamType($item->Media->Part['decision']),
  855. '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'].")",
  856. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  857. ));
  858. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  859. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  860. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  861. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  862. }
  863. break;
  864. case 'album':
  865. case 'track':
  866. $title = $item['parentTitle'];
  867. $summary = $item['title'];
  868. $image = 'slick-image-short';
  869. $style = 'left: 160px !important;';
  870. $item['ratingKey'] = $item['parentRatingKey'];
  871. if(!$nowPlaying){
  872. $width = 444;
  873. $thumb = $item['thumb'];
  874. $key = $item['ratingKey'] . "-list";
  875. }else {
  876. $height = 281;
  877. $width = 500;
  878. $thumb = ($item['art']) ? $item['art'] : $item['parentThumb'];
  879. $widthOverride = ($item['art']) ? 100 : 56;
  880. $key = $item['ratingKey'] . "-np";
  881. $elapsed = $item['viewOffset'];
  882. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  883. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  884. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  885. $stream = $item->Media->Part->Stream['decision'];
  886. $user = $role == "admin" ? $item->User['title'] : "";
  887. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  888. $streamInfo = buildStream(array(
  889. 'platform' => (string) $item->Player['platform'],
  890. 'device' => (string) $item->Player['device'],
  891. 'stream' => streamType($item->Media->Part['decision']),
  892. 'audio' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  893. ));
  894. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  895. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  896. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  897. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  898. }
  899. break;
  900. default:
  901. $title = $item['title'];
  902. $summary = $item['summary'];
  903. $image = 'slick-image-tall';
  904. $style = '';
  905. if(!$nowPlaying){
  906. $width = 300;
  907. $thumb = $item['thumb'];
  908. $key = $item['ratingKey'] . "-list";
  909. }else {
  910. $height = 281;
  911. $width = 500;
  912. $thumb = $item['art'];
  913. $key = $item['ratingKey'] . "-np";
  914. $elapsed = $item['viewOffset'];
  915. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  916. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  917. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  918. $stream = $item->Media->Part->Stream['decision'];
  919. $user = $role == "admin" ? $item->User['title'] : "";
  920. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  921. $streamInfo = buildStream(array(
  922. 'platform' => (string) $item->Player['platform'],
  923. 'device' => (string) $item->Player['device'],
  924. 'stream' => streamType($item->Media->Part['decision']),
  925. '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'].")",
  926. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  927. ));
  928. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  929. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  930. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  931. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  932. }
  933. }
  934. if (PLEXTABURL) {
  935. $address = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  936. }else{
  937. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  938. }
  939. // If No Overview
  940. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  941. $original_image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  942. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  943. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  944. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  945. }
  946. if($nowPlaying){
  947. if(!$thumb){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  948. }else{
  949. if(!$thumb){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  950. }
  951. if(isset($useImage)){ $image_url = $useImage; }
  952. $openTab = (PLEXTABNAME) ? "true" : "false";
  953. // Assemble Item And Cache Into Array
  954. if($nowPlaying){
  955. 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="refreshNP 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><div class="ultra-widget refreshImage"><span class="w-refresh w-p-icon gray"><span class="fa-stack fa-lg" style="font-size: .4em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-refresh fa-stack-1x fa-inverse"></i></span></span></div><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img class="refreshImageSource" style="width: '.$widthOverride.'%; display:block;" src="'.$image_url.'" original-image="'.$original_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>';
  956. }else{
  957. return '<div class="item-'.$item['type'].$playlist.'"><div style="" class="ultra-widget refreshImage"><span class="w-refresh w-p-icon gray"><span class="fa-stack fa-lg" style="font-size: .4em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-refresh fa-stack-1x fa-inverse"></i></span></span></div><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.' refreshImageSource" data-lazy="'.$image_url.'" original-image="'.$original_image_url.'"></a><small class="elip slick-bottom-title">'.$title.'</small></div>';
  958. }
  959. }
  960. //$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  961. //Recent Added
  962. function outputRecentAdded($header, $items, $script = false, $array, $type) {
  963. $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">';
  964. if(preg_grep("/item-movie/", $items)){
  965. $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>';
  966. }
  967. if(preg_grep("/item-season/", $items)){
  968. $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>';
  969. }
  970. if(preg_grep("/item-album/", $items)){
  971. $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>';
  972. }
  973. $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>';
  974. $hideMenu .= '</ul></div></div>';
  975. // If None Populate Empty Item
  976. if (!count($items)) {
  977. return '<div id="recentMedia'.$type.'" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Media Found</p></div>';
  978. }else{
  979. $className = str_replace(' ', '', $header.' on '.$type);
  980. return '<div id="recentMedia'.$type.'" class="content-box box-shadow big-box"><h5 id="recentContent-title-'.$type.'" style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-recent-'.$type.'" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  981. }
  982. }
  983. // Create Carousel
  984. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  985. // If None Populate Empty Item
  986. if (!count($items)) {
  987. return '<div id="'.$type.'"></div>'.($script?'<script>'.$script.'</script>':'');
  988. }else{
  989. return '<div id="'.$type.'"><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  990. }
  991. }
  992. // Get Now Playing Streams From Emby
  993. function getEmbyStreams($size, $showNames, $role) {
  994. $address = qualifyURL(EMBYURL);
  995. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  996. if (!is_array($api)) { return 'Could not load!'; }
  997. $playingItems = array();
  998. foreach($api as $key => $value) {
  999. if (isset($value['NowPlayingItem'])) {
  1000. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  1001. }
  1002. }
  1003. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY')." ( ".count($playingItems)." Streams )", $size, 'streams-emby', $playingItems, ajaxLoop('emby-streams',NOWPLAYINGREFRESH));
  1004. }
  1005. // Get Now Playing Streams From Plex
  1006. function getPlexStreams($size, $showNames, $role){
  1007. $address = qualifyURL(PLEXURL);
  1008. // Perform API requests
  1009. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  1010. libxml_use_internal_errors(true);
  1011. $api = simplexml_load_string($api);
  1012. if (is_array($api) || is_object($api)){
  1013. if (!$api->head->title){
  1014. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  1015. if (!$getServer) { return 'Could not load!'; }
  1016. // Identify the local machine
  1017. $gotServer = $getServer['machineIdentifier'];
  1018. $items = array();
  1019. foreach($api AS $child) {
  1020. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  1021. }
  1022. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, ajaxLoop('plex-streams',NOWPLAYINGREFRESH));
  1023. }else{
  1024. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  1025. }
  1026. }else{
  1027. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1028. }
  1029. }
  1030. // Get Recent Content From Emby
  1031. function getEmbyRecent($array) {
  1032. $address = qualifyURL(EMBYURL);
  1033. $header = translate('RECENT_CONTENT');
  1034. // Currently Logged In User
  1035. $username = false;
  1036. if (isset($GLOBALS['USER'])) {
  1037. $username = strtolower($GLOBALS['USER']->username);
  1038. }
  1039. // Get A User
  1040. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  1041. if (!is_array($userIds)) { return 'Could not load!'; }
  1042. $showPlayed = true;
  1043. foreach ($userIds as $value) { // Scan for admin user
  1044. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  1045. $userId = $value['Id'];
  1046. }
  1047. if ($username && strtolower($value['Name']) == $username) {
  1048. $userId = $value['Id'];
  1049. $showPlayed = false;
  1050. break;
  1051. }
  1052. }
  1053. // Get the latest Items
  1054. $latest = json_decode(@file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  1055. // For Each Item In Category
  1056. $items = array();
  1057. foreach ($latest as $k => $v) {
  1058. $type = (string) $v['Type'];
  1059. if(@$array[$type] == "true"){
  1060. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  1061. }
  1062. }
  1063. $array["movie"] = $array["Movie"];
  1064. $array["season"] = $array["Episode"];
  1065. $array["album"] = $array["MusicAlbum"];
  1066. unset($array["Movie"]);
  1067. unset($array["Episode"]);
  1068. unset($array["MusicAlbum"]);
  1069. unset($array["Series"]);
  1070. return outputRecentAdded($header, $items, ajaxLoop('emby-recent',RECENTREFRESH,'loadSlick();'), $array, 'Emby');
  1071. }
  1072. // Get Recent Content From Plex
  1073. function getPlexRecent($array){
  1074. $address = qualifyURL(PLEXURL);
  1075. $header = translate('RECENT_CONTENT');
  1076. // Perform Requests
  1077. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  1078. libxml_use_internal_errors(true);
  1079. $api = simplexml_load_string($api);
  1080. if (is_array($api) || is_object($api)){
  1081. if (!$api->head->title){
  1082. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  1083. if (!$getServer) { return 'Could not load!'; }
  1084. // Identify the local machine
  1085. $gotServer = $getServer['machineIdentifier'];
  1086. $items = array();
  1087. foreach($api AS $child) {
  1088. $type = (string) $child['type'];
  1089. if($array[$type] == "true"){
  1090. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  1091. }
  1092. }
  1093. return outputRecentAdded($header, $items, ajaxLoop('plex-recent',RECENTREFRESH,'loadSlick();'), $array, 'Plex');
  1094. }else{
  1095. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  1096. }
  1097. }else{
  1098. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1099. }
  1100. }
  1101. // Get Image From Emby
  1102. function getEmbyImage() {
  1103. $refresh = false;
  1104. $embyAddress = qualifyURL(EMBYURL);
  1105. if (!file_exists('images/cache')) {
  1106. mkdir('images/cache', 0777, true);
  1107. }
  1108. $itemId = $_GET['img'];
  1109. $key = $_GET['key'];
  1110. if(strpos($key, '$') !== false){
  1111. $key = explode('$', $key)[0];
  1112. $refresh = true;
  1113. }
  1114. $itemType = $_GET['type'];
  1115. $imgParams = array();
  1116. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  1117. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  1118. if(isset($itemId)) {
  1119. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  1120. $cachefile = 'images/cache/'.$key.'.jpg';
  1121. $cachetime = 604800;
  1122. // Serve from the cache if it is younger than $cachetime
  1123. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh !== true) {
  1124. header("Content-type: image/jpeg");
  1125. @readfile($cachefile);
  1126. exit;
  1127. }
  1128. ob_start(); // Start the output buffer
  1129. header('Content-type: image/jpeg');
  1130. //@readfile($image_src);
  1131. echo @curl_get($image_src);
  1132. // Cache the output to a file
  1133. $fp = fopen($cachefile, 'wb');
  1134. fwrite($fp, ob_get_contents());
  1135. fclose($fp);
  1136. ob_end_flush(); // Send the output to the browser
  1137. die();
  1138. } else {
  1139. debug_out('Invalid Request',1);
  1140. }
  1141. }
  1142. // Get Image From Plex
  1143. function getPlexImage() {
  1144. $refresh = false;
  1145. $plexAddress = qualifyURL(PLEXURL);
  1146. if (!file_exists('images/cache')) {
  1147. mkdir('images/cache', 0777, true);
  1148. }
  1149. $image_url = $_GET['img'];
  1150. $key = $_GET['key'];
  1151. if(strpos($key, '$') !== false){
  1152. $key = explode('$', $key)[0];
  1153. $refresh = true;
  1154. }
  1155. $image_height = $_GET['height'];
  1156. $image_width = $_GET['width'];
  1157. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1158. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1159. $cachefile = 'images/cache/'.$key.'.jpg';
  1160. $cachetime = 604800;
  1161. // Serve from the cache if it is younger than $cachetime
  1162. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1163. header("Content-type: image/jpeg");
  1164. @readfile($cachefile);
  1165. exit;
  1166. }
  1167. ob_start(); // Start the output buffer
  1168. header('Content-type: image/jpeg');
  1169. //@readfile($image_src);
  1170. echo @curl_get($image_src);
  1171. // Cache the output to a file
  1172. $fp = fopen($cachefile, 'wb');
  1173. fwrite($fp, ob_get_contents());
  1174. fclose($fp);
  1175. ob_end_flush(); // Send the output to the browser
  1176. die();
  1177. } else {
  1178. echo "Invalid Plex Request";
  1179. }
  1180. }
  1181. // Simplier access to class
  1182. function translate($string) {
  1183. if (isset($GLOBALS['language'])) {
  1184. return $GLOBALS['language']->translate($string);
  1185. } else {
  1186. return '!Translations Not Loaded!';
  1187. }
  1188. }
  1189. // Generate Random string
  1190. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1191. $tmp = '';
  1192. for ($i = 0; $i < $length; $i++) {
  1193. $tmp .= substr(str_shuffle($chars), 0, 1);
  1194. }
  1195. return $tmp;
  1196. }
  1197. // Create config file in the return syntax
  1198. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1199. // Define Initial Value
  1200. $output = array();
  1201. // Sort Items
  1202. ksort($array);
  1203. // Update the current config version
  1204. if (!$nest) {
  1205. // Inject Current Version
  1206. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1207. }
  1208. unset($array['CONFIG_VERSION']);
  1209. unset($array['apply_CONFIG_VERSION']);
  1210. // Process Settings
  1211. foreach ($array as $k => $v) {
  1212. $allowCommit = true;
  1213. switch (gettype($v)) {
  1214. case 'boolean':
  1215. $item = ($v?'true':'false');
  1216. break;
  1217. case 'integer':
  1218. case 'double':
  1219. case 'integer':
  1220. case 'NULL':
  1221. $item = $v;
  1222. break;
  1223. case 'string':
  1224. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1225. break;
  1226. case 'array':
  1227. $item = createConfig($v, false, $nest+1);
  1228. break;
  1229. default:
  1230. $allowCommit = false;
  1231. }
  1232. if($allowCommit) {
  1233. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1234. }
  1235. }
  1236. // Build output
  1237. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1238. if (!$nest && $path) {
  1239. $pathDigest = pathinfo($path);
  1240. @mkdir($pathDigest['dirname'], 0770, true);
  1241. if (file_exists($path)) {
  1242. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1243. }
  1244. $file = fopen($path, 'w');
  1245. fwrite($file, $output);
  1246. fclose($file);
  1247. if (file_exists($path)) {
  1248. return true;
  1249. }
  1250. writeLog("error", "config was unable to write");
  1251. return false;
  1252. } else {
  1253. writeLog("success", "config was updated with new values");
  1254. return $output;
  1255. }
  1256. }
  1257. // Load a config file written in the return syntax
  1258. function loadConfig($path = 'config/config.php') {
  1259. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1260. if (!is_file($path)) {
  1261. return null;
  1262. } else {
  1263. return (array) call_user_func(function() use($path) {
  1264. return include($path);
  1265. });
  1266. }
  1267. }
  1268. // Commit new values to the configuration
  1269. function updateConfig($new, $current = false) {
  1270. // Get config if not supplied
  1271. if ($current === false) {
  1272. $current = loadConfig();
  1273. } else if (is_string($current) && is_file($current)) {
  1274. $current = loadConfig($current);
  1275. }
  1276. // Inject Parts
  1277. foreach ($new as $k => $v) {
  1278. $current[$k] = $v;
  1279. }
  1280. // Return Create
  1281. return createConfig($current);
  1282. }
  1283. // Inject Defaults As Needed
  1284. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1285. if (is_string($path)) {
  1286. $loadedDefaults = loadConfig($path);
  1287. } else {
  1288. $loadedDefaults = $path;
  1289. }
  1290. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1291. }
  1292. // support function for fillDefaultConfig()
  1293. function fillDefaultConfig_recurse($current, $defaults) {
  1294. foreach($defaults as $k => $v) {
  1295. if (!isset($current[$k])) {
  1296. $current[$k] = $v;
  1297. } else if (is_array($current[$k]) && is_array($v)) {
  1298. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1299. }
  1300. }
  1301. return $current;
  1302. };
  1303. // Define Scalar Variables (nest non-secular with underscores)
  1304. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1305. foreach($array as $k => $v) {
  1306. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1307. define($nest_prefix.$k, $v, $anyCase);
  1308. } else if (is_array($v)) {
  1309. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1310. }
  1311. }
  1312. }
  1313. // This function exists only because I am lazy
  1314. function configLazy($path = 'config/config.php') {
  1315. // Load config or default
  1316. if (file_exists($path)) {
  1317. $config = fillDefaultConfig(loadConfig($path));
  1318. } else {
  1319. $config = loadConfig('config/configDefaults.php');
  1320. }
  1321. if (is_array($config)) {
  1322. defineConfig($config);
  1323. }
  1324. return $config;
  1325. }
  1326. // Qualify URL
  1327. function qualifyURL($url) {
  1328. //local address?
  1329. if(substr($url, 0,1) == "/"){
  1330. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1331. $protocol = "https://";
  1332. } else {
  1333. $protocol = "http://";
  1334. }
  1335. $url = $protocol.getServer().$url;
  1336. }
  1337. // Get Digest
  1338. $digest = parse_url($url);
  1339. // http/https
  1340. if (!isset($digest['scheme'])) {
  1341. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1342. $scheme = 'http';
  1343. } else {
  1344. $scheme = 'https';
  1345. }
  1346. } else {
  1347. $scheme = $digest['scheme'];
  1348. }
  1349. // Host
  1350. $host = (isset($digest['host'])?$digest['host']:'');
  1351. // Port
  1352. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1353. // Path
  1354. $path = (isset($digest['path'])?$digest['path']:'');
  1355. // Output
  1356. return $scheme.'://'.$host.$port.$path;
  1357. }
  1358. // Function to be called at top of each to allow upgrading environment as the spec changes
  1359. function upgradeCheck() {
  1360. // Upgrade to 1.31
  1361. if (file_exists('homepageSettings.ini.php')) {
  1362. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1363. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1364. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1365. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1366. foreach($databaseConfig as $k => $v) {
  1367. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1368. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1369. }
  1370. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1371. unlink('homepageSettings.ini.php');
  1372. unset($databaseData);
  1373. unset($homepageConfig);
  1374. }
  1375. // Upgrade to 1.32
  1376. if (file_exists('databaseLocation.ini.php')) {
  1377. // Load Existing
  1378. $config = parse_ini_file('databaseLocation.ini.php', true);
  1379. // Refactor
  1380. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1381. $config['user_home'] = $config['database_Location'].'users/';
  1382. unset($config['databaseLocation']);
  1383. // Turn Off Emby And Plex Recent
  1384. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1385. unset($config["embyPort"]);
  1386. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1387. unset($config["plexPort"]);
  1388. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1389. unset($config["nzbgetPort"]);
  1390. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1391. unset($config["sabnzbdPort"]);
  1392. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1393. unset($config["headphonesPort"]);
  1394. // Write config file
  1395. $config['CONFIG_VERSION'] = '1.32';
  1396. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1397. $createConfigSuccess = createConfig($config);
  1398. // Create new config
  1399. if ($createConfigSuccess) {
  1400. if (file_exists('config/config.php')) {
  1401. // Remove Old ini file
  1402. unlink('databaseLocation.ini.php');
  1403. } else {
  1404. debug_out('Something is not right here!');
  1405. }
  1406. } else {
  1407. debug_out('Couldn\'t create updated configuration.' ,1);
  1408. }
  1409. }
  1410. // Upgrade to 1.33
  1411. $config = loadConfig();
  1412. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1413. // Fix User Directory
  1414. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1415. $config['user_home'] = $config['database_Location'].'users/';
  1416. unset($config['USER_HOME']);
  1417. // Backend auth merge
  1418. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1419. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1420. }
  1421. unset($config['authBackendPort']);
  1422. // If auth is being used move it to embyURL as that is now used in auth functions
  1423. 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')))) {
  1424. $config['embyURL'] = $config['authBackendHost'];
  1425. }
  1426. // Upgrade database to latest version
  1427. updateSQLiteDB($config['database_Location'],'1.32');
  1428. // Update Version and Commit
  1429. $config['apply_CONFIG_VERSION'] = '1.33';
  1430. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1431. $createConfigSuccess = createConfig($config);
  1432. unset($config);
  1433. }
  1434. // Upgrade to 1.34
  1435. $config = loadConfig();
  1436. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1437. // Upgrade database to latest version
  1438. updateSQLiteDB($config['database_Location'],'1.33');
  1439. // Update Version and Commit
  1440. $config['CONFIG_VERSION'] = '1.34';
  1441. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1442. $createConfigSuccess = createConfig($config);
  1443. unset($config);
  1444. }
  1445. // Upgrade to 1.40
  1446. $config = loadConfig();
  1447. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1448. // Upgrade database to latest version
  1449. updateSQLiteDB($config['database_Location'],'1.38');
  1450. // Update Version and Commit
  1451. $config['CONFIG_VERSION'] = '1.40';
  1452. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1453. $createConfigSuccess = createConfig($config);
  1454. unset($config);
  1455. }
  1456. // Upgrade to 1.50
  1457. $config = loadConfig();
  1458. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.50')) {
  1459. // Upgrade database to latest version
  1460. updateSQLiteDB($config['database_Location'],'1.40');
  1461. // Update Version and Commit
  1462. $config['CONFIG_VERSION'] = '1.50';
  1463. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.40].bak.php');
  1464. $createConfigSuccess = createConfig($config);
  1465. unset($config);
  1466. }
  1467. // Upgrade to 1.603
  1468. $config = loadConfig();
  1469. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.603')) {
  1470. // Update Version and Commit
  1471. $config['CONFIG_VERSION'] = '1.603';
  1472. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.601].bak.php');
  1473. $createConfigSuccess = createConfig($config);
  1474. unset($config);
  1475. if(file_exists('org.log')){
  1476. copy('org.log', DATABASE_LOCATION.'org.log');
  1477. unlink('org.log');
  1478. }
  1479. if(file_exists('loginLog.json')){
  1480. copy('loginLog.json', DATABASE_LOCATION.'loginLog.json');
  1481. unlink('loginLog.json');
  1482. }
  1483. }
  1484. return true;
  1485. }
  1486. // Get OS from server
  1487. function getOS(){
  1488. if(PHP_SHLIB_SUFFIX == "dll"){
  1489. return "win";
  1490. }else{
  1491. return "nix";
  1492. }
  1493. }
  1494. //Get Error by Server OS
  1495. function getError($os, $error){
  1496. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1497. $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'");
  1498. $errors = array(
  1499. 'pdo_sqlite' => array(
  1500. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1501. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1502. ),
  1503. 'sqlite3' => array(
  1504. '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',
  1505. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1506. ),
  1507. 'curl' => array(
  1508. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1509. 'nix' => '<b>cURL</b> not enabled, PHP7 -> sudo apt-get install php-curl or sudo apt-get install php7.0-curl | PHP5 -> run sudo apt-get install php5.6-curl',
  1510. ),
  1511. 'zip' => array(
  1512. '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',
  1513. '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',
  1514. ),
  1515. );
  1516. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1517. }
  1518. // Check if all software dependancies are met
  1519. function dependCheck() {
  1520. $output = array();
  1521. $i = 1;
  1522. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1523. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1524. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1525. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1526. if ($output) {
  1527. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1528. $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++;
  1529. debug_out($output,1);
  1530. }
  1531. return true;
  1532. }
  1533. // Process file uploads
  1534. function uploadFiles($path, $ext_mask = null) {
  1535. if (isset($_FILES) && count($_FILES)) {
  1536. require_once('class.uploader.php');
  1537. $uploader = new Uploader();
  1538. $data = $uploader->upload($_FILES['files'], array(
  1539. 'limit' => 10,
  1540. 'maxSize' => 10,
  1541. 'extensions' => $ext_mask,
  1542. 'required' => false,
  1543. 'uploadDir' => str_replace('//','/',$path.'/'),
  1544. 'title' => array('name'),
  1545. 'removeFiles' => true,
  1546. 'replace' => true,
  1547. ));
  1548. if($data['isComplete']){
  1549. $files = $data['data'];
  1550. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1551. echo json_encode($files['metas'][0]['name']);
  1552. }
  1553. if($data['hasErrors']){
  1554. $errors = $data['errors'];
  1555. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1556. echo json_encode($errors);
  1557. }
  1558. } else {
  1559. writeLog("error", "image was not uploaded");
  1560. echo json_encode('No files submitted!');
  1561. }
  1562. }
  1563. // Process file uploads
  1564. function uploadAvatar($path, $ext_mask = null) {
  1565. if (isset($_FILES) && count($_FILES)) {
  1566. require_once('class.uploader.php');
  1567. $uploader = new Uploader();
  1568. $data = $uploader->upload($_FILES['files'], array(
  1569. 'limit' => 10,
  1570. 'maxSize' => 10,
  1571. 'extensions' => $ext_mask,
  1572. 'required' => false,
  1573. 'uploadDir' => str_replace('//','/',$path.'/'),
  1574. 'title' => array('name'),
  1575. 'removeFiles' => true,
  1576. 'replace' => true,
  1577. ));
  1578. if($data['isComplete']){
  1579. $files = $data['data'];
  1580. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1581. echo json_encode($files['metas'][0]['name']);
  1582. }
  1583. if($data['hasErrors']){
  1584. $errors = $data['errors'];
  1585. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1586. echo json_encode($errors);
  1587. }
  1588. } else {
  1589. writeLog("error", "image was not uploaded");
  1590. echo json_encode('No files submitted!');
  1591. }
  1592. }
  1593. // Remove file
  1594. function removeFiles($path) {
  1595. if(is_file($path)) {
  1596. writeLog("success", "file was removed");
  1597. unlink($path);
  1598. } else {
  1599. writeLog("error", "file was not removed");
  1600. echo json_encode('No file specified for removal!');
  1601. }
  1602. }
  1603. // Lazy select options
  1604. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1605. $output = array();
  1606. $selectedArr = ($multi?explode('|', $selected):array());
  1607. foreach ($array as $key => $value) {
  1608. if (is_array($value)) {
  1609. if (isset($value['optgroup'])) {
  1610. $output[] = '<optgroup label="'.$key.'">';
  1611. foreach($value['optgroup'] as $k => $v) {
  1612. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1613. }
  1614. } else {
  1615. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1616. }
  1617. } else {
  1618. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1619. }
  1620. }
  1621. return implode('',$output);
  1622. }
  1623. // Check if user is allowed to continue
  1624. function qualifyUser($type, $errOnFail = false) {
  1625. if (!isset($GLOBALS['USER'])) {
  1626. require_once("user.php");
  1627. $GLOBALS['USER'] = new User('registration_callback');
  1628. }
  1629. if (is_bool($type)) {
  1630. if ($type === true) {
  1631. $authorized = ($GLOBALS['USER']->authenticated == true);
  1632. } else {
  1633. $authorized = true;
  1634. }
  1635. } elseif (is_string($type) || is_array($type)) {
  1636. if ($type !== 'false') {
  1637. if (!is_array($type)) {
  1638. $type = explode('|',$type);
  1639. }
  1640. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1641. } else {
  1642. $authorized = true;
  1643. }
  1644. } else {
  1645. debug_out('Invalid Syntax!',1);
  1646. }
  1647. if (!$authorized && $errOnFail) {
  1648. if ($GLOBALS['USER']->authenticated) {
  1649. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401');
  1650. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401\'</script>';
  1651. } else {
  1652. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999');
  1653. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999\'</script>';
  1654. }
  1655. debug_out('Not Authorized' ,1);
  1656. } else {
  1657. return $authorized;
  1658. }
  1659. }
  1660. // Build an (optionally) tabbed settings page.
  1661. function buildSettings($array) {
  1662. /*
  1663. array(
  1664. 'title' => '',
  1665. 'id' => '',
  1666. 'fields' => array( See buildField() ),
  1667. 'tabs' => array(
  1668. array(
  1669. 'title' => '',
  1670. 'id' => '',
  1671. 'image' => '',
  1672. 'fields' => array( See buildField() ),
  1673. ),
  1674. ),
  1675. );
  1676. */
  1677. $notifyExplode = explode("-", NOTIFYEFFECT);
  1678. $fieldFunc = function($fieldArr) {
  1679. $fields = '<div class="row">';
  1680. foreach($fieldArr as $key => $value) {
  1681. $isSingle = isset($value['type']);
  1682. if ($isSingle) { $value = array($value); }
  1683. $tmpField = '';
  1684. $sizeLg = max(floor(12/count($value)),2);
  1685. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1686. foreach($value as $k => $v) {
  1687. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1688. }
  1689. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1690. }
  1691. $fields .= '</div>';
  1692. return $fields;
  1693. };
  1694. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1695. $tabSelectors = array();
  1696. $tabContent = array();
  1697. if (isset($array['tabs'])) {
  1698. foreach($array['tabs'] as $key => $value) {
  1699. $id = (isset($value['id'])?$value['id']:randString(32));
  1700. $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>';
  1701. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1702. }
  1703. }
  1704. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1705. $extraClick = ($pageID == 'appearance_settings' ? "$('#advanced_settings_form_submit').click();console.log('add theme settings');" : "");
  1706. return '
  1707. <div class="email-body">
  1708. <div class="email-header gray-bg">
  1709. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1710. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float save-btn-form">
  1711. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1712. </button>
  1713. <h1>'.$array['title'].'</h1>
  1714. </div>
  1715. <div class="email-inner small-box">
  1716. <div class="email-inner-section">
  1717. <div class="small-box fade in" id="'.$pageID.'_frame">
  1718. <div class="col-lg-12">
  1719. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1720. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1721. '.$fields.($tabContent?'
  1722. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1723. <ul class="nav nav-tabs apps">
  1724. '.implode('', $tabSelectors).'
  1725. </ul>
  1726. <div class="clearfix"></div>
  1727. <div class="tab-content">
  1728. '.implode('', $tabContent).'
  1729. </div>
  1730. </div>':'').'
  1731. </form>
  1732. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1733. </div>
  1734. </div>
  1735. </div>
  1736. </div>
  1737. </div>
  1738. <script>
  1739. $(document).ready(function() {
  1740. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1741. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1742. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1743. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1744. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1745. var newVals = {};
  1746. var hasVals = false;
  1747. var errorFields = [];
  1748. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1749. hasVals = true;
  1750. if (this.type == \'checkbox\') {
  1751. newVals[this.name] = this.checked;
  1752. } else if ($(this).hasClass(\'summernote\')) {
  1753. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1754. } else {
  1755. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1756. var fieldVal = $(this).val();
  1757. if (typeof fieldVal == \'object\') {
  1758. if (typeof fieldVal.join == \'function\') {
  1759. fieldVal = fieldVal.join(\'|\');
  1760. } else {
  1761. fieldVal = JSON.stringify(fieldVal);
  1762. }
  1763. }
  1764. newVals[this.name] = fieldVal;
  1765. }
  1766. });
  1767. if (errorFields.length) {
  1768. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1769. } else if (hasVals) {
  1770. console.log(newVals);
  1771. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1772. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1773. });
  1774. '.$extraClick.'
  1775. } else {
  1776. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1777. }
  1778. return false;
  1779. });
  1780. '.(isset($array['onready'])?$array['onready']:'').'
  1781. });
  1782. </script>
  1783. ';
  1784. }
  1785. // Build Settings Fields
  1786. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1787. /*
  1788. array(
  1789. 'type' => '',
  1790. 'placeholder' => '',
  1791. 'label' => '',
  1792. 'labelTranslate' => '',
  1793. 'assist' => '',
  1794. 'name' => '',
  1795. 'pattern' => '',
  1796. 'options' => array( // For SELECT only
  1797. 'Display' => 'value',
  1798. ),
  1799. )
  1800. */
  1801. // Tags
  1802. $tags = array();
  1803. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick','autocomplete') as $value) {
  1804. if (isset($params[$value])) {
  1805. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1806. } else if ($params[$value] === true) { $tags[] = $value; }
  1807. }
  1808. }
  1809. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1810. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1811. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1812. $val = (isset($params['value'])?$params['value']:'');
  1813. $class = (isset($params['class'])?' '.$params['class']:'');
  1814. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1815. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1816. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1817. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1818. // Field Design
  1819. switch ($params['type']) {
  1820. case 'text':
  1821. case 'number':
  1822. case 'password':
  1823. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1824. break;
  1825. case 'select':
  1826. case 'dropdown':
  1827. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1828. break;
  1829. case 'select-multi':
  1830. case 'dropdown-multi':
  1831. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1832. break;
  1833. case 'check':
  1834. case 'checkbox':
  1835. case 'toggle':
  1836. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1837. $colour = (isset($params['colour'])?$params['colour']:'success');
  1838. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1839. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1840. break;
  1841. case 'radio':
  1842. $labelOut = '';
  1843. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1844. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1845. $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>';
  1846. break;
  1847. case 'date':
  1848. $field = 'Unsupported, planned.';
  1849. break;
  1850. case 'hidden':
  1851. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1852. break;
  1853. case 'header':
  1854. $labelOut = '';
  1855. $headType = (isset($params['value'])?$params['value']:3);
  1856. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1857. break;
  1858. case 'button':
  1859. $labelOut = '';
  1860. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1861. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1862. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1863. $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><span class="btn-text">'.$label.'</span></button>'.($bDropdown?$bDropdown.'</div>':'');
  1864. break;
  1865. case 'textarea':
  1866. $rows = (isset($params['rows'])?$params['rows']:5);
  1867. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1868. break;
  1869. case 'custom':
  1870. // Settings
  1871. $settings = array(
  1872. '$id' => $id,
  1873. '$name' => $name,
  1874. '$val' => $val,
  1875. '$label' => $label,
  1876. '$labelOut' => $labelOut,
  1877. );
  1878. // Get HTML
  1879. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1880. // If LabelOut is in html dont print it twice
  1881. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1882. // Replace variables in settings
  1883. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1884. // Build Field
  1885. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1886. break;
  1887. case 'space':
  1888. $labelOut = '';
  1889. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1890. break;
  1891. default:
  1892. $field = 'Unsupported field type';
  1893. break;
  1894. }
  1895. // Field Formats
  1896. switch ($format) {
  1897. case 'colour': // Fuckin Eh, Canada!
  1898. case 'color':
  1899. $labelBef = '<center>'.$label.'</center>';
  1900. $wrapClass = 'gray-bg colour-field';
  1901. $labelAft = '';
  1902. $field = str_replace(' material input-sm','',$field);
  1903. break;
  1904. default:
  1905. $labelBef = '';
  1906. $labelAft = $labelOut;
  1907. }
  1908. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1909. }
  1910. // Tab Settings Generation
  1911. function printTabRow($data) {
  1912. $hidden = false;
  1913. if ($data===false) {
  1914. $hidden = true;
  1915. $data = array( // New Tab Defaults
  1916. 'id' => 'new',
  1917. 'name' => '',
  1918. 'url' => '',
  1919. 'icon' => 'fa-diamond',
  1920. 'iconurl' => '',
  1921. 'active' => 'true',
  1922. 'user' => 'true',
  1923. 'guest' => 'true',
  1924. 'window' => 'false',
  1925. 'splash' => 'true',
  1926. 'ping' => 'false',
  1927. 'ping_url' => '',
  1928. 'defaultz' => '',
  1929. );
  1930. }
  1931. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1932. $output = '
  1933. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1934. <tab class="content-form form-inline">
  1935. <div class="row">
  1936. '.buildField(array(
  1937. 'type' => 'custom',
  1938. '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>',
  1939. ),12,1,1).'
  1940. '.buildField(array(
  1941. 'type' => 'hidden',
  1942. 'id' => 'tab-'.$data['id'].'-id',
  1943. 'name' => 'id['.$data['id'].']',
  1944. 'value' => $data['id'],
  1945. ),12,2,1).'
  1946. '.buildField(array(
  1947. 'type' => 'text',
  1948. 'id' => 'tab-'.$data['id'].'-name',
  1949. 'name' => 'name['.$data['id'].']',
  1950. 'required' => true,
  1951. 'placeholder' => 'Organizr Homepage',
  1952. 'labelTranslate' => 'TAB_NAME',
  1953. 'value' => $data['name'],
  1954. 'class' => 'darkBold',
  1955. ),12,2,1).'
  1956. '.buildField(array(
  1957. 'type' => 'text',
  1958. 'id' => 'tab-'.$data['id'].'-url',
  1959. 'name' => 'url['.$data['id'].']',
  1960. 'required' => true,
  1961. 'placeholder' => 'homepage.php',
  1962. 'labelTranslate' => 'TAB_URL',
  1963. 'value' => $data['url'],
  1964. 'class' => 'darkBold',
  1965. ),12,2,2).'
  1966. '.buildField(array(
  1967. 'type' => 'text',
  1968. 'id' => 'tab-'.$data['id'].'-iconurl',
  1969. 'name' => 'iconurl['.$data['id'].']',
  1970. 'placeholder' => 'images/organizr.png',
  1971. 'labelTranslate' => 'ICON_URL',
  1972. 'value' => $data['iconurl'],
  1973. 'class' => 'darkBold',
  1974. ),12,2,1).'
  1975. '.buildField(array(
  1976. 'type' => 'text',
  1977. 'id' => 'tab-'.$data['id'].'-icon',
  1978. 'name' => 'icon['.$data['id'].']',
  1979. 'placeholder' => 'fa-icon',
  1980. 'labelTranslate' => 'OR_ICON_NAME',
  1981. 'value' => $data['icon'],
  1982. 'class' => 'iconpickeradd darkBold',
  1983. ),12,1,1).'
  1984. '.buildField(array(
  1985. 'type' => 'text',
  1986. 'id' => 'tab-'.$data['id'].'-ping_url',
  1987. 'name' => 'ping_url['.$data['id'].']',
  1988. 'placeholder' => 'host:port',
  1989. 'labelTranslate' => 'PING_URL',
  1990. 'value' => $data['ping_url'],
  1991. 'class' => 'darkBold',
  1992. ),12,2,1).'
  1993. '.buildField(array(
  1994. 'type' => 'radio',
  1995. 'labelTranslate' => 'DEFAULT',
  1996. 'name' => 'defaultz['.$data['id'].']',
  1997. 'value' => $data['defaultz'],
  1998. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1999. ),12,1,1).'
  2000. '.buildField(array(
  2001. 'type' => 'button',
  2002. 'icon' => 'chevron-down',
  2003. 'buttonType' => 'success',
  2004. 'labelTranslate' => 'MORE',
  2005. 'onclick' => "$(this).parent().parent().parent().find('.slideInUp').toggle()",
  2006. 'class' => 'toggleTabExtra',
  2007. ),12,1,1).'
  2008. '.buildField(array(
  2009. 'type' => 'button',
  2010. 'icon' => 'trash',
  2011. 'buttonType' => 'danger',
  2012. 'labelTranslate' => 'REMOVE',
  2013. 'onclick' => "$(this).parents('li').remove();",
  2014. ),12,1,1).'</div><div id = "tab-'.$data['id'].'-row" class = "row animated slideInUp" style = "display:none;" ><div></div>
  2015. '.buildField(array(
  2016. 'type' => 'checkbox',
  2017. 'labelTranslate' => 'ACTIVE',
  2018. 'name' => 'active['.$data['id'].']',
  2019. 'value' => $data['active'],
  2020. ),12,1,1).'
  2021. '.buildField(array(
  2022. 'type' => 'checkbox',
  2023. 'labelTranslate' => 'USER',
  2024. 'colour' => 'primary',
  2025. 'name' => 'user['.$data['id'].']',
  2026. 'value' => $data['user'],
  2027. ),12,1,1).'
  2028. '.buildField(array(
  2029. 'type' => 'checkbox',
  2030. 'labelTranslate' => 'GUEST',
  2031. 'colour' => 'warning',
  2032. 'name' => 'guest['.$data['id'].']',
  2033. 'value' => $data['guest'],
  2034. ),12,1,1).'
  2035. '.buildField(array(
  2036. 'type' => 'checkbox',
  2037. 'labelTranslate' => 'NO_IFRAME',
  2038. 'colour' => 'danger',
  2039. 'name' => 'window['.$data['id'].']',
  2040. 'value' => $data['window'],
  2041. ),12,1,1).'
  2042. '.buildField(array(
  2043. 'type' => 'checkbox',
  2044. 'labelTranslate' => 'SPLASH',
  2045. 'colour' => 'success',
  2046. 'name' => 'splash['.$data['id'].']',
  2047. 'value' => $data['splash'],
  2048. ),12,1,1).'
  2049. '.buildField(array(
  2050. 'type' => 'checkbox',
  2051. 'labelTranslate' => 'PING',
  2052. 'colour' => 'success',
  2053. 'name' => 'ping['.$data['id'].']',
  2054. 'value' => $data['ping'],
  2055. ),12,1,1).'
  2056. </div>
  2057. </tab>
  2058. </li>
  2059. ';
  2060. return $output;
  2061. }
  2062. // Timezone array
  2063. function timezoneOptions() {
  2064. $output = array();
  2065. $timezones = array();
  2066. $regions = array(
  2067. 'Africa' => DateTimeZone::AFRICA,
  2068. 'America' => DateTimeZone::AMERICA,
  2069. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2070. 'Arctic' => DateTimeZone::ARCTIC,
  2071. 'Asia' => DateTimeZone::ASIA,
  2072. 'Atlantic' => DateTimeZone::ATLANTIC,
  2073. 'Australia' => DateTimeZone::AUSTRALIA,
  2074. 'Europe' => DateTimeZone::EUROPE,
  2075. 'Indian' => DateTimeZone::INDIAN,
  2076. 'Pacific' => DateTimeZone::PACIFIC
  2077. );
  2078. foreach ($regions as $name => $mask) {
  2079. $zones = DateTimeZone::listIdentifiers($mask);
  2080. foreach($zones as $timezone) {
  2081. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2082. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2083. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  2084. }
  2085. }
  2086. return $output;
  2087. }
  2088. // Build Database
  2089. function createSQLiteDB($path = false) {
  2090. if ($path === false) {
  2091. if (DATABASE_LOCATION){
  2092. $path = DATABASE_LOCATION;
  2093. } else {
  2094. debug_out('No Path Specified!');
  2095. }
  2096. }
  2097. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  2098. if (!isset($GLOBALS['file_db'])) {
  2099. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  2100. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2101. }
  2102. // Create Users
  2103. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  2104. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2105. `username` TEXT UNIQUE,
  2106. `password` TEXT,
  2107. `email` TEXT,
  2108. `token` TEXT,
  2109. `role` TEXT,
  2110. `active` TEXT,
  2111. `last` TEXT,
  2112. `auth_service` TEXT DEFAULT \'internal\'
  2113. );');
  2114. // Create Tabs
  2115. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  2116. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2117. `order` INTEGER,
  2118. `users_id` INTEGER,
  2119. `name` TEXT,
  2120. `url` TEXT,
  2121. `defaultz` TEXT,
  2122. `active` TEXT,
  2123. `user` TEXT,
  2124. `guest` TEXT,
  2125. `icon` TEXT,
  2126. `iconurl` TEXT,
  2127. `window` TEXT,
  2128. `splash` TEXT,
  2129. `ping` TEXT,
  2130. `ping_url` TEXT
  2131. );');
  2132. // Create Options
  2133. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  2134. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2135. `users_id` INTEGER UNIQUE,
  2136. `title` TEXT UNIQUE,
  2137. `topbar` TEXT,
  2138. `bottombar` TEXT,
  2139. `sidebar` TEXT,
  2140. `hoverbg` TEXT,
  2141. `topbartext` TEXT,
  2142. `activetabBG` TEXT,
  2143. `activetabicon` TEXT,
  2144. `activetabtext` TEXT,
  2145. `inactiveicon` TEXT,
  2146. `inactivetext` TEXT,
  2147. `loading` TEXT,
  2148. `hovertext` TEXT
  2149. );');
  2150. // Create Invites
  2151. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  2152. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2153. `code` TEXT UNIQUE,
  2154. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  2155. `email` TEXT,
  2156. `username` TEXT,
  2157. `dateused` TIMESTAMP,
  2158. `usedby` TEXT,
  2159. `ip` TEXT,
  2160. `valid` TEXT
  2161. );');
  2162. writeLog("success", "database created/saved");
  2163. return $users && $tabs && $options && $invites;
  2164. } else {
  2165. writeLog("error", "database was unable to be created/saved");
  2166. return false;
  2167. }
  2168. }
  2169. // Upgrade Database
  2170. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  2171. if (!$db_path) {
  2172. if (defined('DATABASE_LOCATION')) {
  2173. $db_path = DATABASE_LOCATION;
  2174. } else {
  2175. debug_out('No Path Specified',1);
  2176. }
  2177. }
  2178. if (!isset($GLOBALS['file_db'])) {
  2179. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  2180. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2181. }
  2182. // Cache current DB
  2183. $cache = array();
  2184. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  2185. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  2186. foreach($row as $k => $v) {
  2187. if (is_string($k)) {
  2188. $cache[$table['name']][$key][$k] = $v;
  2189. }
  2190. }
  2191. }
  2192. }
  2193. // Remove Current Database
  2194. $GLOBALS['file_db'] = null;
  2195. $pathDigest = pathinfo($db_path.'users.db');
  2196. if (file_exists($db_path.'users.db')) {
  2197. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  2198. }
  2199. // Create New Database
  2200. $success = createSQLiteDB($db_path);
  2201. // Restore Items
  2202. if ($success) {
  2203. foreach($cache as $table => $tableData) {
  2204. if ($tableData) {
  2205. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  2206. $insertValues = array();
  2207. reset($tableData);
  2208. foreach($tableData as $key => $value) {
  2209. $insertValues[] = '('.implode(',',array_map(function($d) {
  2210. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  2211. }, $value)).')';
  2212. }
  2213. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  2214. }
  2215. }
  2216. writeLog("success", "database values have been updated");
  2217. return true;
  2218. } else {
  2219. writeLog("error", "database values unable to be updated");
  2220. return false;
  2221. }
  2222. }
  2223. // Commit colours to database
  2224. function updateDBOptions($values) {
  2225. if (!isset($GLOBALS['file_db'])) {
  2226. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2227. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2228. }
  2229. // Commit new values to database
  2230. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  2231. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  2232. }, $values, array_keys($values))).';')->rowCount()) {
  2233. return true;
  2234. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  2235. writeLog("success", "database values for options table have been updated");
  2236. return true;
  2237. } else {
  2238. writeLog("error", "database values for options table unable to be updated");
  2239. return false;
  2240. }
  2241. }
  2242. // Send AJAX notification
  2243. function sendNotification($success, $message = false, $send = true) {
  2244. $notifyExplode = explode("-", NOTIFYEFFECT);
  2245. if ($success) {
  2246. $msg = array(
  2247. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  2248. 'icon' => 'floppy-o',
  2249. 'type' => 'success',
  2250. 'length' => '5000',
  2251. 'layout' => $notifyExplode[0],
  2252. 'effect' => $notifyExplode[1],
  2253. );
  2254. } else {
  2255. $msg = array(
  2256. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2257. 'icon' => 'floppy-o',
  2258. 'type' => 'failed',
  2259. 'length' => '5000',
  2260. 'layout' => $notifyExplode[0],
  2261. 'effect' => $notifyExplode[1],
  2262. );
  2263. }
  2264. // Send and kill script?
  2265. if ($send) {
  2266. header('Content-Type: application/json');
  2267. echo json_encode(array('notify'=>$msg));
  2268. die();
  2269. }
  2270. return $msg;
  2271. }
  2272. // Load colours from the database
  2273. function loadAppearance() {
  2274. // Defaults
  2275. $defaults = array(
  2276. 'title' => 'Organizr',
  2277. 'topbartext' => '#66D9EF',
  2278. 'topbar' => '#333333',
  2279. 'bottombar' => '#333333',
  2280. 'sidebar' => '#393939',
  2281. 'hoverbg' => '#AD80FD',
  2282. 'activetabBG' => '#F92671',
  2283. 'activetabicon' => '#FFFFFF',
  2284. 'activetabtext' => '#FFFFFF',
  2285. 'inactiveicon' => '#66D9EF',
  2286. 'inactivetext' => '#66D9EF',
  2287. 'loading' => '#66D9EF',
  2288. 'hovertext' => '#000000',
  2289. );
  2290. if (DATABASE_LOCATION) {
  2291. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2292. if (!isset($GLOBALS['file_db'])) {
  2293. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2294. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2295. }
  2296. // Database Lookup
  2297. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2298. // Replace defaults with filled options
  2299. foreach($options as $row) {
  2300. foreach($defaults as $key => $value) {
  2301. if (isset($row[$key]) && $row[$key]) {
  2302. $defaults[$key] = $row[$key];
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. // Return the Results
  2309. return $defaults;
  2310. }
  2311. // Delete Database
  2312. function deleteDatabase() {
  2313. unset($_COOKIE['Organizr']);
  2314. setcookie('Organizr', '', time() - 3600, '/');
  2315. unset($_COOKIE['OrganizrU']);
  2316. setcookie('OrganizrU', '', time() - 3600, '/');
  2317. $GLOBALS['file_db'] = null;
  2318. unlink(DATABASE_LOCATION.'users.db');
  2319. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2320. if(is_dir($file)) {
  2321. rmdir($file);
  2322. } elseif (!is_dir($file)) {
  2323. unlink($file);
  2324. }
  2325. }
  2326. rmdir($userdirpath);
  2327. writeLog("success", "database has been deleted");
  2328. return true;
  2329. }
  2330. // Upgrade the installation
  2331. function upgradeInstall($branch = 'master') {
  2332. function downloadFile($url, $path){
  2333. ini_set('max_execution_time',0);
  2334. $folderPath = "upgrade/";
  2335. if(!mkdir($folderPath)){
  2336. writeLog("error", "organizr could not create upgrade folder");
  2337. }
  2338. $newfname = $folderPath . $path;
  2339. $file = fopen ($url, 'rb');
  2340. if ($file) {
  2341. $newf = fopen ($newfname, 'wb');
  2342. if ($newf) {
  2343. while(!feof($file)) {
  2344. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2345. }
  2346. }
  2347. }else{
  2348. writeLog("error", "organizr could not download $url");
  2349. }
  2350. if ($file) {
  2351. fclose($file);
  2352. writeLog("success", "organizr finished downloading the github zip file");
  2353. }else{
  2354. writeLog("error", "organizr could not download the github zip file");
  2355. }
  2356. if ($newf) {
  2357. fclose($newf);
  2358. writeLog("success", "organizr created upgrade zip file from github zip file");
  2359. }else{
  2360. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2361. }
  2362. }
  2363. function unzipFile($zipFile){
  2364. $zip = new ZipArchive;
  2365. $extractPath = "upgrade/";
  2366. if($zip->open($extractPath . $zipFile) != "true"){
  2367. writeLog("error", "organizr could not unzip upgrade.zip");
  2368. }else{
  2369. writeLog("success", "organizr unzipped upgrade.zip");
  2370. }
  2371. /* Extract Zip File */
  2372. $zip->extractTo($extractPath);
  2373. $zip->close();
  2374. }
  2375. // Function to remove folders and files
  2376. function rrmdir($dir) {
  2377. if (is_dir($dir)) {
  2378. $files = scandir($dir);
  2379. foreach ($files as $file)
  2380. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2381. rmdir($dir);
  2382. }
  2383. else if (file_exists($dir)) unlink($dir);
  2384. }
  2385. // Function to Copy folders and files
  2386. function rcopy($src, $dst) {
  2387. if (is_dir ( $src )) {
  2388. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2389. $files = scandir ( $src );
  2390. foreach ( $files as $file )
  2391. if ($file != "." && $file != "..")
  2392. rcopy ( "$src/$file", "$dst/$file" );
  2393. } else if (file_exists ( $src ))
  2394. copy ( $src, $dst );
  2395. }
  2396. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2397. $file = "upgrade.zip";
  2398. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2399. $cleanup = __DIR__ . "/upgrade/";
  2400. $destination = __DIR__ . "/";
  2401. writeLog("success", "starting organizr upgrade process");
  2402. downloadFile($url, $file);
  2403. unzipFile($file);
  2404. rcopy($source, $destination);
  2405. writeLog("success", "new organizr files copied");
  2406. rrmdir($cleanup);
  2407. writeLog("success", "organizr upgrade folder removed");
  2408. writeLog("success", "organizr has been updated");
  2409. return true;
  2410. }
  2411. // Transmission Items
  2412. function transmissionConnect($list = 'listgroups') {
  2413. $url = qualifyURL(TRANSMISSIONURL);
  2414. $digest = parse_url($url);
  2415. $scheme = (isset($digest['scheme'])) ? $digest['scheme'].'://' : 'http://';
  2416. $host = (isset($digest['host'])) ? $digest['host'] : '';
  2417. $port = (isset($digest['port'])) ? ':'.$digest['port'] : '';
  2418. $path = (isset($digest['path'])) ? $digest['path'] : '';
  2419. $passwordInclude = (TRANSMISSIONUSERNAME != '' && TRANSMISSIONPASSWORD != '') ? TRANSMISSIONUSERNAME.':'.TRANSMISSIONPASSWORD."@" : '';
  2420. $url = $scheme.$passwordInclude.$host.$port.$path.'/rpc';
  2421. $contextopts = array(
  2422. 'http' => array(
  2423. 'user_agent' => 'HTTP_UA',
  2424. 'ignore_errors' => true,
  2425. )
  2426. );
  2427. $context = stream_context_create( $contextopts );
  2428. $fp = @fopen( $url, 'r', false, $context );
  2429. $stream_meta = stream_get_meta_data( $fp );
  2430. fclose( $fp );
  2431. foreach( $stream_meta['wrapper_data'] as $header ){
  2432. if( strpos( $header, 'X-Transmission-Session-Id: ' ) === 0 ){
  2433. $session_id = trim( substr( $header, 27 ) );
  2434. break;
  2435. }
  2436. }
  2437. $headers = array(
  2438. 'X-Transmission-Session-Id' => $session_id,
  2439. 'Content-Type' => 'application/json'
  2440. );
  2441. $data = array(
  2442. 'method' => 'torrent-get',
  2443. 'arguments' => array(
  2444. 'fields' => array(
  2445. "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir"
  2446. ),
  2447. ),
  2448. 'tags' => ''
  2449. );
  2450. $api = curl_post($url, $data, $headers);
  2451. $api = json_decode($api['content'], true);
  2452. $gotTorrent = array();
  2453. if (is_array($api) || is_object($api)){
  2454. foreach ($api['arguments']['torrents'] AS $child) {
  2455. $downloadName = htmlentities($child['name'], ENT_QUOTES);
  2456. $downloadDirectory = $child['downloadDir'];
  2457. $downloadPercent = $child['percentDone'] * 100;
  2458. $progressBar = "progress-bar-striped active";
  2459. if($child['status'] == "6"){
  2460. $downloadStatus = "Seeding";
  2461. $downloadHealth = "success";
  2462. }elseif($child['status'] == "4"){
  2463. $downloadStatus = "Downloading";
  2464. $downloadHealth = "danger";
  2465. }elseif($child['status'] == "3"){
  2466. $downloadStatus = "Queued";
  2467. $downloadHealth = "warning";
  2468. }elseif($child['status'] == "0"){
  2469. $downloadStatus = "Complete";
  2470. $downloadHealth = "success";
  2471. }
  2472. $gotTorrent[] = '<tr>
  2473. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2474. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2475. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadDirectory.'</td>
  2476. <td class="col-xs-1 nzbtable nzbtable-row">'.realSize($child['totalSize']).'</td>
  2477. <td class="col-xs-2 nzbtable nzbtable-row">
  2478. <div class="progress">
  2479. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2480. <p class="text-center">'.round($downloadPercent).'%</p>
  2481. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2482. </div>
  2483. </div>
  2484. </td>
  2485. </tr>';
  2486. }
  2487. if ($gotTorrent) {
  2488. return implode('',$gotTorrent);
  2489. } else {
  2490. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2491. }
  2492. }else{
  2493. writeLog("error", "TRANSMISSION ERROR: could not connect - check URL and/or check token and/or Username and Password - if HTTPS, is cert valid");
  2494. }
  2495. }
  2496. // NzbGET Items
  2497. function nzbgetConnect($list = 'listgroups') {
  2498. $url = qualifyURL(NZBGETURL);
  2499. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2500. $api = json_decode($api, true);
  2501. $gotNZB = array();
  2502. if (is_array($api) || is_object($api)){
  2503. foreach ($api['result'] AS $child) {
  2504. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2505. $downloadStatus = $child['Status'];
  2506. $downloadCategory = $child['Category'];
  2507. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2508. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2509. if($child['Health'] <= "750"){
  2510. $downloadHealth = "danger";
  2511. }elseif($child['Health'] <= "900"){
  2512. $downloadHealth = "warning";
  2513. }elseif($child['Health'] <= "1000"){
  2514. $downloadHealth = "success";
  2515. }
  2516. $gotNZB[] = '<tr>
  2517. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2518. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2519. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2520. <td class="col-xs-1 nzbtable nzbtable-row">'.realSize(($child['FileSizeMB']*1024)*1024).'</td>
  2521. <td class="col-xs-2 nzbtable nzbtable-row">
  2522. <div class="progress">
  2523. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2524. <p class="text-center">'.round($downloadPercent).'%</p>
  2525. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2526. </div>
  2527. </div>
  2528. </td>
  2529. </tr>';
  2530. }
  2531. if ($gotNZB) {
  2532. return implode('',$gotNZB);
  2533. } else {
  2534. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2535. }
  2536. }else{
  2537. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Username and Password - if HTTPS, is cert valid");
  2538. }
  2539. }
  2540. // Sabnzbd Items
  2541. function sabnzbdConnect($list = 'queue') {
  2542. $url = qualifyURL(SABNZBDURL);
  2543. $api = @file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2544. $api = json_decode($api, true);
  2545. $gotNZB = array();
  2546. if (is_array($api) || is_object($api)){
  2547. foreach ($api[$list]['slots'] AS $child) {
  2548. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2549. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2550. $downloadStatus = $child['status'];
  2551. $gotNZB[] = '<tr>
  2552. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2553. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2554. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2555. <td class="col-xs-1 nzbtable nzbtable-row">'.$child['size'].'</td>
  2556. <td class="col-xs-2 nzbtable nzbtable-row">
  2557. <div class="progress">
  2558. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2559. <p class="text-center">'.round($downloadPercent).'%</p>
  2560. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2561. </div>
  2562. </div>
  2563. </td>
  2564. </tr>';
  2565. }
  2566. if ($gotNZB) {
  2567. return implode('',$gotNZB);
  2568. } else {
  2569. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2570. }
  2571. }else{
  2572. writeLog("error", "SABNZBD ERROR: could not connect - check URL and/or check token - if HTTPS, is cert valid");
  2573. }
  2574. }
  2575. // Apply new tab settings
  2576. function updateTabs($tabs) {
  2577. if (!isset($GLOBALS['file_db'])) {
  2578. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2579. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2580. }
  2581. // Validate
  2582. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2583. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2584. // Clear Existing Tabs
  2585. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2586. // Process New Tabs
  2587. $totalValid = 0;
  2588. foreach ($tabs['name'] as $key => $value) {
  2589. // Qualify
  2590. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2591. $totalValid++;
  2592. $fields = array();
  2593. foreach(array('id','name','url','icon','iconurl','order','ping_url') as $v) {
  2594. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2595. }
  2596. foreach(array('active','user','guest','defaultz','window','splash','ping') as $v) {
  2597. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2598. }
  2599. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2600. }
  2601. writeLog("success", "tabs successfully saved");
  2602. return $totalValid;
  2603. } else {
  2604. writeLog("error", "tabs could not save");
  2605. return false;
  2606. }
  2607. writeLog("error", "tabs could not save");
  2608. return false;
  2609. }
  2610. // ==============
  2611. function clean($strin) {
  2612. $strout = null;
  2613. for ($i = 0; $i < strlen($strin); $i++) {
  2614. $ord = ord($strin[$i]);
  2615. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2616. $strout .= "&amp;#{$ord};";
  2617. }
  2618. else {
  2619. switch ($strin[$i]) {
  2620. case '<':
  2621. $strout .= '&lt;';
  2622. break;
  2623. case '>':
  2624. $strout .= '&gt;';
  2625. break;
  2626. case '&':
  2627. $strout .= '&amp;';
  2628. break;
  2629. case '"':
  2630. $strout .= '&quot;';
  2631. break;
  2632. default:
  2633. $strout .= $strin[$i];
  2634. }
  2635. }
  2636. }
  2637. return $strout;
  2638. }
  2639. function registration_callback($username, $email, $userdir){
  2640. global $data;
  2641. $data = array($username, $email, $userdir);
  2642. }
  2643. function printArray($arrayName){
  2644. $messageCount = count($arrayName);
  2645. $i = 0;
  2646. foreach ( $arrayName as $item ) :
  2647. $i++;
  2648. if($i < $messageCount) :
  2649. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2650. elseif($i = $messageCount) :
  2651. echo "<small class='text-uppercase'>" . $item . "</small>";
  2652. endif;
  2653. endforeach;
  2654. }
  2655. function write_ini_file($content, $path) {
  2656. if (!$handle = fopen($path, 'w')) {
  2657. return false;
  2658. }
  2659. $success = fwrite($handle, trim($content));
  2660. fclose($handle);
  2661. return $success;
  2662. }
  2663. function gotTimezone(){
  2664. $regions = array(
  2665. 'Africa' => DateTimeZone::AFRICA,
  2666. 'America' => DateTimeZone::AMERICA,
  2667. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2668. 'Arctic' => DateTimeZone::ARCTIC,
  2669. 'Asia' => DateTimeZone::ASIA,
  2670. 'Atlantic' => DateTimeZone::ATLANTIC,
  2671. 'Australia' => DateTimeZone::AUSTRALIA,
  2672. 'Europe' => DateTimeZone::EUROPE,
  2673. 'Indian' => DateTimeZone::INDIAN,
  2674. 'Pacific' => DateTimeZone::PACIFIC
  2675. );
  2676. $timezones = array();
  2677. foreach ($regions as $name => $mask) {
  2678. $zones = DateTimeZone::listIdentifiers($mask);
  2679. foreach($zones as $timezone) {
  2680. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2681. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2682. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2683. }
  2684. }
  2685. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2686. foreach($timezones as $region => $list) {
  2687. print '<optgroup label="' . $region . '">' . "\n";
  2688. foreach($list as $timezone => $name) {
  2689. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2690. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2691. }
  2692. print '</optgroup>' . "\n";
  2693. }
  2694. print '</select>';
  2695. }
  2696. function getTimezone(){
  2697. $regions = array(
  2698. 'Africa' => DateTimeZone::AFRICA,
  2699. 'America' => DateTimeZone::AMERICA,
  2700. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2701. 'Arctic' => DateTimeZone::ARCTIC,
  2702. 'Asia' => DateTimeZone::ASIA,
  2703. 'Atlantic' => DateTimeZone::ATLANTIC,
  2704. 'Australia' => DateTimeZone::AUSTRALIA,
  2705. 'Europe' => DateTimeZone::EUROPE,
  2706. 'Indian' => DateTimeZone::INDIAN,
  2707. 'Pacific' => DateTimeZone::PACIFIC
  2708. );
  2709. $timezones = array();
  2710. foreach ($regions as $name => $mask) {
  2711. $zones = DateTimeZone::listIdentifiers($mask);
  2712. foreach($zones as $timezone) {
  2713. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2714. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2715. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2716. }
  2717. }
  2718. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2719. foreach($timezones as $region => $list) {
  2720. print '<optgroup label="' . $region . '">' . "\n";
  2721. foreach($list as $timezone => $name) {
  2722. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2723. }
  2724. print '</optgroup>' . "\n";
  2725. }
  2726. print '</select>';
  2727. }
  2728. function explosion($string, $position){
  2729. $getWord = explode("|", $string);
  2730. return $getWord[$position];
  2731. }
  2732. function getServerPath() {
  2733. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2734. $protocol = "https://";
  2735. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2736. $protocol = "https://";
  2737. } else {
  2738. $protocol = "http://";
  2739. }
  2740. $domain = '';
  2741. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2742. $domain = $_SERVER['SERVER_NAME'];
  2743. }elseif(isset($_SERVER['HTTP_HOST'])){
  2744. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2745. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2746. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2747. if ($port == "80" || $port == "443"){
  2748. $domain = $domain;
  2749. }else{
  2750. $domain = $_SERVER['HTTP_HOST'];
  2751. }
  2752. }else{
  2753. $domain = $_SERVER['HTTP_HOST'];
  2754. }
  2755. }
  2756. return $protocol . $domain . str_replace("\\", "/", dirname($_SERVER['REQUEST_URI']));
  2757. }
  2758. function get_browser_name() {
  2759. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2760. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2761. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2762. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2763. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2764. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2765. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2766. return 'Other';
  2767. }
  2768. function getSickrageCalendarWanted($array){
  2769. $array = json_decode($array, true);
  2770. //$gotCalendar = "";
  2771. $gotCalendar = array();
  2772. $i = 0;
  2773. foreach($array['data']['missed'] AS $child) {
  2774. $i++;
  2775. $seriesName = $child['show_name'];
  2776. $episodeID = $child['tvdbid'];
  2777. $episodeAirDate = $child['airdate'];
  2778. $episodeAirDateTime = explode(" ",$child['airs']);
  2779. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2780. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2781. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2782. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2783. $downloaded = "0";
  2784. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2785. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2786. array_push($gotCalendar, array(
  2787. "id" => "Sick-Miss-".$i,
  2788. "title" => $seriesName,
  2789. "start" => $episodeAirDate,
  2790. "className" => $downloaded." tvID--".$episodeID,
  2791. "imagetype" => "tv",
  2792. ));
  2793. }
  2794. foreach($array['data']['today'] AS $child) {
  2795. $i++;
  2796. $seriesName = $child['show_name'];
  2797. $episodeID = $child['tvdbid'];
  2798. $episodeAirDate = $child['airdate'];
  2799. $episodeAirDateTime = explode(" ",$child['airs']);
  2800. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2801. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2802. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2803. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2804. $downloaded = "0";
  2805. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2806. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2807. array_push($gotCalendar, array(
  2808. "id" => "Sick-Today-".$i,
  2809. "title" => $seriesName,
  2810. "start" => $episodeAirDate,
  2811. "className" => $downloaded." tvID--".$episodeID,
  2812. "imagetype" => "tv",
  2813. ));
  2814. }
  2815. foreach($array['data']['soon'] AS $child) {
  2816. $i++;
  2817. $seriesName = $child['show_name'];
  2818. $episodeID = $child['tvdbid'];
  2819. $episodeAirDate = $child['airdate'];
  2820. $episodeAirDateTime = explode(" ",$child['airs']);
  2821. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2822. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2823. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2824. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2825. $downloaded = "0";
  2826. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2827. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2828. array_push($gotCalendar, array(
  2829. "id" => "Sick-Soon-".$i,
  2830. "title" => $seriesName,
  2831. "start" => $episodeAirDate,
  2832. "className" => $downloaded." tvID--".$episodeID,
  2833. "imagetype" => "tv",
  2834. ));
  2835. }
  2836. foreach($array['data']['later'] AS $child) {
  2837. $i++;
  2838. $seriesName = $child['show_name'];
  2839. $episodeID = $child['tvdbid'];
  2840. $episodeAirDate = $child['airdate'];
  2841. $episodeAirDateTime = explode(" ",$child['airs']);
  2842. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2843. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2844. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2845. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2846. $downloaded = "0";
  2847. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2848. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2849. array_push($gotCalendar, array(
  2850. "id" => "Sick-Later-".$i,
  2851. "title" => $seriesName,
  2852. "start" => $episodeAirDate,
  2853. "className" => $downloaded." tvID--".$episodeID,
  2854. "imagetype" => "tv",
  2855. ));
  2856. }
  2857. if ($i != 0){ return $gotCalendar; }
  2858. }
  2859. function getSickrageCalendarHistory($array){
  2860. $array = json_decode($array, true);
  2861. //$gotCalendar = "";
  2862. $gotCalendar = array();
  2863. $i = 0;
  2864. foreach($array['data'] AS $child) {
  2865. $i++;
  2866. $seriesName = $child['show_name'];
  2867. $episodeID = $child['tvdbid'];
  2868. $episodeAirDate = $child['date'];
  2869. $downloaded = "green-bg";
  2870. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2871. array_push($gotCalendar, array(
  2872. "id" => "Sick-History-".$i,
  2873. "title" => $seriesName,
  2874. "start" => $episodeAirDate,
  2875. "className" => $downloaded." tvID--".$episodeID,
  2876. "imagetype" => "tv",
  2877. ));
  2878. }
  2879. if ($i != 0){ return $gotCalendar; }
  2880. }
  2881. function getSonarrCalendar($array){
  2882. $array = json_decode($array, true);
  2883. //$gotCalendar = "";
  2884. $gotCalendar = array();
  2885. $i = 0;
  2886. foreach($array AS $child) {
  2887. $i++;
  2888. $seriesName = $child['series']['title'];
  2889. $episodeID = $child['series']['tvdbId'];
  2890. if(!isset($episodeID)){ $episodeID = ""; }
  2891. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2892. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2893. $episodeAirDate = $child['airDateUtc'];
  2894. $episodeAirDate = strtotime($episodeAirDate);
  2895. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2896. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2897. $downloaded = $child['hasFile'];
  2898. 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"; }
  2899. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2900. array_push($gotCalendar, array(
  2901. "id" => "Sonarr-".$i,
  2902. "title" => $seriesName,
  2903. "start" => $episodeAirDate,
  2904. "className" => $downloaded." tvID--".$episodeID,
  2905. "imagetype" => "tv",
  2906. ));
  2907. }
  2908. if ($i != 0){ return $gotCalendar; }
  2909. }
  2910. function getCouchCalendar(){
  2911. $url = qualifyURL(COUCHURL);
  2912. $api = curl_get($url."/api/".COUCHAPI."/media.list");
  2913. $api = json_decode($api, true);
  2914. $i = 0;
  2915. $gotCalendar = array();
  2916. if (is_array($api) || is_object($api)){
  2917. foreach($api['movies'] AS $child) {
  2918. if($child['status'] == "active" || $child['status'] == "done" ){
  2919. $i++;
  2920. $movieName = $child['info']['original_title'];
  2921. $movieID = $child['info']['tmdb_id'];
  2922. if(!isset($movieID)){ $movieID = ""; }
  2923. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  2924. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  2925. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  2926. $physicalRelease = strtotime($physicalRelease);
  2927. $physicalRelease = date("Y-m-d", $physicalRelease);
  2928. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2929. $downloaded = ($child['status'] == "active") ? "0" : "1";
  2930. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2931. array_push($gotCalendar, array(
  2932. "id" => "CouchPotato-".$i,
  2933. "title" => $movieName,
  2934. "start" => $physicalRelease,
  2935. "className" => $downloaded." movieID--".$movieID,
  2936. "imagetype" => "film",
  2937. ));
  2938. }
  2939. }
  2940. if ($i != 0){ return $gotCalendar; }
  2941. }else{
  2942. writeLog("error", "CouchPotato ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2943. }
  2944. }
  2945. function getRadarrCalendar($array){
  2946. $array = json_decode($array, true);
  2947. $gotCalendar = array();
  2948. $i = 0;
  2949. foreach($array AS $child) {
  2950. if(isset($child['physicalRelease'])){
  2951. $i++;
  2952. $movieName = $child['title'];
  2953. $movieID = $child['tmdbId'];
  2954. if(!isset($movieID)){ $movieID = ""; }
  2955. $physicalRelease = $child['physicalRelease'];
  2956. $physicalRelease = strtotime($physicalRelease);
  2957. $physicalRelease = date("Y-m-d", $physicalRelease);
  2958. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2959. $downloaded = $child['hasFile'];
  2960. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2961. array_push($gotCalendar, array(
  2962. "id" => "Radarr-".$i,
  2963. "title" => $movieName,
  2964. "start" => $physicalRelease,
  2965. "className" => $downloaded." movieID--".$movieID,
  2966. "imagetype" => "film",
  2967. ));
  2968. }
  2969. }
  2970. if ($i != 0){ return $gotCalendar; }
  2971. }
  2972. function getHeadphonesCalendar($url, $key, $list){
  2973. $url = qualifyURL(HEADPHONESURL);
  2974. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2975. $api = json_decode($api, true);
  2976. $i = 0;
  2977. //$gotCalendar = "";
  2978. $gotCalendar = array();;
  2979. if (is_array($api) || is_object($api)){
  2980. foreach($api AS $child) {
  2981. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2982. $i++;
  2983. $albumName = addslashes($child['AlbumTitle']);
  2984. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2985. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2986. $albumID = $child['AlbumID'];
  2987. $albumDate = strtotime($albumDate);
  2988. $albumDate = date("Y-m-d", $albumDate);
  2989. $albumStatus = $child['Status'];
  2990. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2991. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2992. //$gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2993. array_push($gotCalendar, array(
  2994. "id" => "Headphones-".$i,
  2995. "title" => $albumArtist.' - '.$albumName,
  2996. "start" => $albumDate,
  2997. "className" => $albumStatusColor,
  2998. "imagetype" => "music",
  2999. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  3000. ));
  3001. }
  3002. if($child['Status'] == "Processed" && $list == "getHistory"){
  3003. $i++;
  3004. $find = array('_','[', ']', '\n');
  3005. $replace = array(' ','(', ')', ' ');
  3006. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  3007. $albumDate = $child['DateAdded'];
  3008. $albumID = $child['AlbumID'];
  3009. $albumDate = strtotime($albumDate);
  3010. $albumDate = date("Y-m-d", $albumDate);
  3011. $albumStatusColor = "green-bg";
  3012. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  3013. //$gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  3014. array_push($gotCalendar, array(
  3015. "id" => "Headphones-".$i,
  3016. "title" => $albumName,
  3017. "start" => $albumDate,
  3018. "className" => $albumStatusColor,
  3019. "imagetype" => "music",
  3020. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  3021. ));
  3022. }
  3023. }
  3024. if ($i != 0){ return $gotCalendar; }
  3025. }else{
  3026. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  3027. }
  3028. }
  3029. function checkRootPath($string){
  3030. if($string == "\\" || $string == "/"){
  3031. return "/";
  3032. }else{
  3033. return str_replace("\\", "/", $string) . "/";
  3034. }
  3035. }
  3036. function strip($string){
  3037. $string = strip_tags($string);
  3038. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  3039. }
  3040. function writeLog($type, $message){
  3041. if(file_exists(DATABASE_LOCATION."org.log")){
  3042. if(filesize(DATABASE_LOCATION."org.log") > 500000){
  3043. rename(DATABASE_LOCATION.'org.log',DATABASE_LOCATION.'org['.date('Y-m-d').'].log');
  3044. $message2 = date("Y-m-d H:i:s")."|".$type."|".strip("ORG LOG: Creating backup of org.log to org[".date('Y-m-d')."].log ")."\n";
  3045. file_put_contents(DATABASE_LOCATION."org.log", $message2, FILE_APPEND | LOCK_EX);
  3046. }
  3047. }
  3048. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  3049. file_put_contents(DATABASE_LOCATION."org.log", $message, FILE_APPEND | LOCK_EX);
  3050. }
  3051. function readLog(){
  3052. $log = file(DATABASE_LOCATION."org.log",FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3053. $log = array_reverse($log);
  3054. foreach($log as $line){
  3055. if(substr_count($line, '|') == 2){
  3056. $line = explode("|", strip($line));
  3057. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  3058. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  3059. }
  3060. }
  3061. }
  3062. function buildStream($array){
  3063. $result = "";
  3064. if (array_key_exists('platform', $array)) {
  3065. $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>';
  3066. }
  3067. if (array_key_exists('device', $array)) {
  3068. $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 fa-fw"></i>'.$array['device'].'</span></div></div><div class="clearfix"></div>';
  3069. }
  3070. if (array_key_exists('stream', $array)) {
  3071. $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 fa-fw"></i>'.$array['stream'].'</span></div></div><div class="clearfix"></div>';
  3072. }
  3073. if (array_key_exists('video', $array)) {
  3074. $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 fa-fw"></i>'.$array['video'].'</span></div></div><div class="clearfix"></div>';
  3075. }
  3076. if (array_key_exists('audio', $array)) {
  3077. $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 fa-fw"></i>'.$array['audio'].'</span></div></div><div class="clearfix"></div>';
  3078. }
  3079. return $result;
  3080. }
  3081. function streamType($value){
  3082. if($value == "transcode" || $value == "Transcode"){
  3083. return "Transcode";
  3084. }elseif($value == "copy" || $value == "DirectStream"){
  3085. return "Direct Stream";
  3086. }elseif($value == "directplay" || $value == "DirectPlay"){
  3087. return "Direct Play";
  3088. }else{
  3089. return "Direct Play";
  3090. }
  3091. }
  3092. function getPlatform($platform){
  3093. $allPlatforms = array(
  3094. "Chrome" => "chrome.png",
  3095. "tvOS" => "atv.png",
  3096. "iOS" => "ios.png",
  3097. "Xbox One" => "xbox.png",
  3098. "Mystery 4" => "playstation.png",
  3099. "Samsung" => "samsung.png",
  3100. "Roku" => "roku.png",
  3101. "Emby for iOS" => "ios.png",
  3102. "Emby Mobile" => "emby.png",
  3103. "Emby Theater" => "emby.png",
  3104. "Emby Classic" => "emby.png",
  3105. "Safari" => "safari.png",
  3106. "Android" => "android.png",
  3107. "AndroidTv" => "android.png",
  3108. "Chromecast" => "chromecast.png",
  3109. "Dashboard" => "emby.png",
  3110. "Dlna" => "dlna.png",
  3111. "Windows Phone" => "wp.png",
  3112. "Windows RT" => "win8.png",
  3113. "Kodi" => "kodi.png",
  3114. );
  3115. if (array_key_exists($platform, $allPlatforms)) {
  3116. return $allPlatforms[$platform];
  3117. }else{
  3118. return "pmp.png";
  3119. }
  3120. }
  3121. function getServer(){
  3122. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  3123. return $server;
  3124. }
  3125. function prettyPrint($array) {
  3126. echo "<pre>";
  3127. print_r($array);
  3128. echo "</pre>";
  3129. echo "<br/>";
  3130. }
  3131. function checkFrame($array, $url){
  3132. if(array_key_exists("x-frame-options", $array)){
  3133. if($array['x-frame-options'] == "deny"){
  3134. return false;
  3135. }elseif($array['x-frame-options'] == "sameorgin"){
  3136. $digest = parse_url($url);
  3137. $host = (isset($digest['host'])?$digest['host']:'');
  3138. if(getServer() == $host){
  3139. return true;
  3140. }else{
  3141. return false;
  3142. }
  3143. }
  3144. }else{
  3145. if(!$array){
  3146. return false;
  3147. }
  3148. return true;
  3149. }
  3150. }
  3151. function frameTest($url){
  3152. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  3153. $url = qualifyURL($url);
  3154. if(checkFrame($array, $url)){
  3155. return true;
  3156. }else{
  3157. return false;
  3158. }
  3159. }
  3160. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  3161. $notifyExplode = explode("-", NOTIFYEFFECT);
  3162. if ($result) {
  3163. $msg = array(
  3164. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  3165. 'icon' => $icon,
  3166. 'type' => 'success',
  3167. 'length' => '5000',
  3168. 'layout' => $notifyExplode[0],
  3169. 'effect' => $notifyExplode[1],
  3170. );
  3171. } else {
  3172. $msg = array(
  3173. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  3174. 'icon' => $icon,
  3175. 'type' => 'error',
  3176. 'length' => '5000',
  3177. 'layout' => $notifyExplode[0],
  3178. 'effect' => $notifyExplode[1],
  3179. );
  3180. }
  3181. // Send and kill script?
  3182. if ($send) {
  3183. header('Content-Type: application/json');
  3184. echo json_encode(array('notify'=>$msg));
  3185. die();
  3186. }
  3187. return $msg;
  3188. }
  3189. function buildHomepageNotice($layout, $type, $title, $message){
  3190. switch ($layout) {
  3191. case 'elegant':
  3192. return '
  3193. <div id="homepageNotice" class="row">
  3194. <div class="col-lg-12">
  3195. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  3196. <div class="content-title i-block">
  3197. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  3198. <div class="content-tools i-block pull-right">
  3199. <a class="close-btn">
  3200. <i class="fa fa-times"></i>
  3201. </a>
  3202. </div>
  3203. </div>
  3204. '.$message.'
  3205. </div>
  3206. </div>
  3207. </div>
  3208. ';
  3209. break;
  3210. case 'basic':
  3211. return '
  3212. <div id="homepageNotice" class="row">
  3213. <div class="col-lg-12">
  3214. <div class="panel panel-'.$type.'">
  3215. <div class="panel-heading">
  3216. <h3 class="panel-title">'.$title.'</h3>
  3217. </div>
  3218. <div class="panel-body">
  3219. '.$message.'
  3220. </div>
  3221. </div>
  3222. </div>
  3223. </div>
  3224. ';
  3225. break;
  3226. case 'jumbotron';
  3227. return '
  3228. <div id="homepageNotice" class="row">
  3229. <div class="col-lg-12">
  3230. <div class="jumbotron">
  3231. <div class="container">
  3232. <h1>'.$title.'</h1>
  3233. <p>'.$message.'</p>
  3234. </div>
  3235. </div>
  3236. </div>
  3237. </div>
  3238. ';
  3239. }
  3240. }
  3241. function embyArray($array, $type) {
  3242. $key = ($type == "video" ? "Height" : "Channels");
  3243. if (array_key_exists($key, $array)) {
  3244. switch ($type) {
  3245. case "video":
  3246. $codec = $array["Codec"];
  3247. $height = $array["Height"];
  3248. $width = $array["Width"];
  3249. break;
  3250. default:
  3251. $codec = $array["Codec"];
  3252. $channels = $array["Channels"];
  3253. }
  3254. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  3255. }
  3256. foreach ($array as $element) {
  3257. if (is_array($element)) {
  3258. if (embyArray($element, $type)) {
  3259. return embyArray($element, $type);
  3260. }
  3261. }
  3262. }
  3263. }
  3264. // Get Now Playing Streams From Plex
  3265. function searchPlex($query){
  3266. $address = qualifyURL(PLEXURL);
  3267. $openTab = (PLEXTABNAME) ? "true" : "false";
  3268. // Perform API requests
  3269. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  3270. libxml_use_internal_errors(true);
  3271. $api = simplexml_load_string($api);
  3272. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3273. if (!$getServer) { return 'Could not load!'; }
  3274. // Identify the local machine
  3275. $server = $getServer['machineIdentifier'];
  3276. $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>";
  3277. $items = "";
  3278. $albums = $movies = $shows = 0;
  3279. $style = 'style="vertical-align: middle"';
  3280. foreach($api AS $child) {
  3281. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  3282. $time = (string)$child['addedAt'];
  3283. $time = new DateTime("@$time");
  3284. $results = array(
  3285. "title" => (string)$child['title'],
  3286. "image" => (string)$child['thumb'],
  3287. "type" => (string)ucwords($child['type']),
  3288. "year" => (string)$child['year'],
  3289. "key" => (string)$child['ratingKey']."-search",
  3290. "ratingkey" => (string)$child['ratingKey'],
  3291. "genre" => (string)$child->Genre['tag'],
  3292. "added" => $time->format('Y-m-d'),
  3293. "extra" => "",
  3294. );
  3295. switch ($child['type']){
  3296. case "album":
  3297. $push = array(
  3298. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  3299. );
  3300. $results = array_replace($results,$push);
  3301. $albums++;
  3302. break;
  3303. case "movie":
  3304. $push = array(
  3305. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  3306. );
  3307. $results = array_replace($results,$push);
  3308. $movies++;
  3309. break;
  3310. case "show":
  3311. $push = array(
  3312. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  3313. );
  3314. $results = array_replace($results,$push);
  3315. $shows++;
  3316. break;
  3317. }
  3318. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  3319. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  3320. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  3321. }
  3322. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  3323. if (PLEXTABURL) {
  3324. $link = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3325. }else{
  3326. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3327. }
  3328. $items .= '<tr style="cursor: pointer;" class="openTab" extraTitle="'.$results['title'].'" extraType="'.$child['type'].'" openTab="'.$openTab.'" href="'.$link.'">
  3329. <th scope="row"><img src="'.$image_url.'"></th>
  3330. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  3331. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  3332. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  3333. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  3334. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  3335. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  3336. </tr>';
  3337. }
  3338. }
  3339. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  3340. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  3341. font-size: 23px;
  3342. ">&nbsp;'.$movies.'</strong></span>
  3343. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  3344. font-size: 23px;
  3345. ">&nbsp;'.$shows.'</strong></span>
  3346. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  3347. font-size: 23px;
  3348. ">&nbsp;'.$albums.'</strong></span>
  3349. </div>';
  3350. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  3351. }
  3352. function getBannedUsers($string){
  3353. if (strpos($string, ',') !== false) {
  3354. $banned = explode(",", $string);
  3355. }else{
  3356. $banned = array($string);
  3357. }
  3358. return $banned;
  3359. }
  3360. function getWhitelist($string){
  3361. if (strpos($string, ',') !== false) {
  3362. $whitelist = explode(",", $string);
  3363. }else{
  3364. $whitelist = array($string);
  3365. }
  3366. foreach($whitelist as &$ip){
  3367. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  3368. }
  3369. return $whitelist;
  3370. }
  3371. function get_client_ip() {
  3372. $ipaddress = '';
  3373. if (isset($_SERVER['HTTP_CLIENT_IP']))
  3374. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  3375. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  3376. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3377. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  3378. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  3379. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  3380. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  3381. else if(isset($_SERVER['HTTP_FORWARDED']))
  3382. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  3383. else if(isset($_SERVER['REMOTE_ADDR']))
  3384. $ipaddress = $_SERVER['REMOTE_ADDR'];
  3385. else
  3386. $ipaddress = 'UNKNOWN';
  3387. return $ipaddress;
  3388. }
  3389. //EMAIL SHIT
  3390. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  3391. $mail = new PHPMailer;
  3392. $mail->isSMTP();
  3393. $mail->Host = SMTPHOST;
  3394. $mail->SMTPAuth = SMTPHOSTAUTH;
  3395. $mail->Username = SMTPHOSTUSERNAME;
  3396. $mail->Password = SMTPHOSTPASSWORD;
  3397. $mail->SMTPSecure = SMTPHOSTTYPE;
  3398. $mail->Port = SMTPHOSTPORT;
  3399. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3400. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3401. $mail->isHTML(true);
  3402. if($email){
  3403. $mail->addAddress($email, $username);
  3404. }
  3405. if($cc){
  3406. $mail->addCC($cc);
  3407. }
  3408. if($bcc){
  3409. if(strpos($bcc , ',') === false){
  3410. $mail->addBCC($bcc);
  3411. }else{
  3412. $allEmails = explode(",",$bcc);
  3413. foreach($allEmails as $gotEmail){
  3414. $mail->addBCC($gotEmail);
  3415. }
  3416. }
  3417. }
  3418. $mail->Subject = $subject;
  3419. $mail->Body = $body;
  3420. //$mail->send();
  3421. if(!$mail->send()) {
  3422. writeLog("error", "mail failed to send");
  3423. } else {
  3424. writeLog("success", "mail has been sent");
  3425. }
  3426. }
  3427. //EMAIL SHIT
  3428. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  3429. $mail = new PHPMailer;
  3430. $mail->isSMTP();
  3431. $mail->Host = $host;
  3432. $mail->SMTPAuth = $auth;
  3433. $mail->Username = $username;
  3434. $mail->Password = $password;
  3435. $mail->SMTPSecure = $type;
  3436. $mail->Port = $port;
  3437. $mail->setFrom($from, $sendername);
  3438. $mail->addReplyTo($from, $sendername);
  3439. $mail->isHTML(true);
  3440. $mail->addAddress($to, "Organizr Admin");
  3441. $mail->Subject = "Organizr Test E-Mail";
  3442. $mail->Body = "This was just a test!";
  3443. //$mail->send();
  3444. if(!$mail->send()) {
  3445. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  3446. return false;
  3447. } else {
  3448. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  3449. return true;
  3450. }
  3451. }
  3452. function libraryList(){
  3453. $address = qualifyURL(PLEXURL);
  3454. $headers = array(
  3455. "Accept" => "application/json",
  3456. "X-Plex-Token" => PLEXTOKEN
  3457. );
  3458. libxml_use_internal_errors(true);
  3459. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3460. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3461. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  3462. $libraryList = array();
  3463. foreach($api->SharedServer->Section AS $child) {
  3464. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  3465. }
  3466. foreach($api->SharedServer AS $child) {
  3467. if(!empty($child['username'])){
  3468. $username = (string)strtolower($child['username']);
  3469. $email = (string)strtolower($child['email']);
  3470. $libraryList['users'][$username] = (string)$child['id'];
  3471. $libraryList['emails'][$email] = (string)$child['id'];
  3472. $libraryList['both'][$username] = $email;
  3473. }
  3474. }
  3475. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3476. }
  3477. function plexUserShare($username){
  3478. $address = qualifyURL(PLEXURL);
  3479. $headers = array(
  3480. "Accept" => "application/json",
  3481. "Content-Type" => "application/json",
  3482. "X-Plex-Token" => PLEXTOKEN
  3483. );
  3484. libxml_use_internal_errors(true);
  3485. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3486. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3487. $json = array(
  3488. "server_id" => $gotServer,
  3489. "shared_server" => array(
  3490. //"library_section_ids" => "[26527637]",
  3491. "invited_email" => $username
  3492. )
  3493. );
  3494. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3495. switch ($api['http_code']['http_code']){
  3496. case 400:
  3497. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3498. $result = "$username already has access to the shared libraries";
  3499. break;
  3500. case 401:
  3501. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3502. $result = "Invalid Plex Token";
  3503. break;
  3504. case 200:
  3505. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3506. $result = "$username now has access to your Plex Library";
  3507. break;
  3508. default:
  3509. writeLog("error", "PLEX INVITE: unknown error");
  3510. $result = false;
  3511. }
  3512. return (!empty($result) ? $result : null );
  3513. }
  3514. function plexUserDelete($username){
  3515. $address = qualifyURL(PLEXURL);
  3516. $headers = array(
  3517. "Accept" => "application/json",
  3518. "Content-Type" => "application/json",
  3519. "X-Plex-Token" => PLEXTOKEN
  3520. );
  3521. libxml_use_internal_errors(true);
  3522. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3523. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3524. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3525. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3526. switch ($api['http_code']['http_code']){
  3527. case 401:
  3528. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3529. $result = "Invalid Plex Token";
  3530. break;
  3531. case 200:
  3532. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3533. $result = "$username doesn't have access to your Plex Library anymore";
  3534. break;
  3535. default:
  3536. writeLog("error", "PLEX INVITE: unknown error");
  3537. $result = false;
  3538. }
  3539. return (!empty($result) ? $result : null );
  3540. }
  3541. function convertPlexName($user, $type){
  3542. $array = libraryList();
  3543. switch ($type){
  3544. case "username":
  3545. $plexUser = array_search ($user, $array['users']);
  3546. break;
  3547. case "id":
  3548. if (array_key_exists(strtolower($user), $array['users'])) {
  3549. $plexUser = $array['users'][strtolower($user)];
  3550. }
  3551. break;
  3552. default:
  3553. $plexUser = false;
  3554. }
  3555. return (!empty($plexUser) ? $plexUser : null );
  3556. }
  3557. function randomCode($length = 5, $type = null) {
  3558. switch ($type){
  3559. case "alpha":
  3560. $legend = array_merge(range('A', 'Z'));
  3561. break;
  3562. case "numeric":
  3563. $legend = array_merge(range(0,9));
  3564. break;
  3565. default:
  3566. $legend = array_merge(range(0,9),range('A', 'Z'));
  3567. }
  3568. $code = "";
  3569. for($i=0; $i < $length; $i++) {
  3570. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3571. }
  3572. return $code;
  3573. }
  3574. function inviteCodes($action, $code = null, $usedBy = null) {
  3575. if (!isset($GLOBALS['file_db'])) {
  3576. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3577. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3578. }
  3579. $now = date("Y-m-d H:i:s");
  3580. switch ($action) {
  3581. case "get":
  3582. // Start Array
  3583. $result = array();
  3584. // Database Lookup
  3585. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3586. // Get Codes
  3587. foreach($invites as $row) {
  3588. array_push($result, $row['code']);
  3589. }
  3590. // Return the Results
  3591. return (!empty($result) ? $result : false );
  3592. break;
  3593. case "check":
  3594. // Start Array
  3595. $result = array();
  3596. // Database Lookup
  3597. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3598. // Get Codes
  3599. foreach($invites as $row) {
  3600. $result = $row['code'];
  3601. }
  3602. // Return the Results
  3603. return (!empty($result) ? $result : false );
  3604. break;
  3605. case "use":
  3606. $currentIP = get_client_ip();
  3607. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3608. if(ENABLEMAIL){
  3609. if (!isset($GLOBALS['USER'])) {
  3610. require_once("user.php");
  3611. $GLOBALS['USER'] = new User('registration_callback');
  3612. }
  3613. sendEmail($GLOBALS['USER']->adminEmail, "Admin", "Plex Invite Used", orgEmail("PLEX Invite Used", "Look who joined the cool club", "Admin", "Hey, The User: $usedBy has redeemd their invite code: [$code], their IP Address was: $currentIP", null, null, "What Next?", "Well, That is up to you. You can go check on them if you like."));
  3614. }
  3615. return (!empty($invites) ? true : false );
  3616. break;
  3617. }
  3618. }
  3619. function plexJoin($username, $email, $password){
  3620. $connectURL = 'https://plex.tv/users.json';
  3621. $headers = array(
  3622. 'Accept'=> 'application/json',
  3623. 'Content-Type' => 'application/x-www-form-urlencoded',
  3624. 'X-Plex-Product' => 'Organizr',
  3625. 'X-Plex-Version' => '1.0',
  3626. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3627. );
  3628. $body = array(
  3629. 'user[email]' => $email,
  3630. 'user[username]' => $username,
  3631. 'user[password]' => $password,
  3632. );
  3633. $api = curl_post($connectURL, $body, $headers);
  3634. $json = json_decode($api['content'], true);
  3635. $errors = (!empty($json['errors']) ? true : false);
  3636. $success = (!empty($json['user']) ? true : false);
  3637. //Use This for later
  3638. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3639. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3640. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3641. $errorMessage = "";
  3642. if($errors){
  3643. if($usernameError){ $errorMessage .= "[Username Error: ". $usernameError ."]"; }
  3644. if($emailError){ $errorMessage .= "[Email Error: ". $emailError ."]"; }
  3645. if($passwordError){ $errorMessage .= "[Password Error: ". $passwordError ."]"; }
  3646. }
  3647. switch ($api['http_code']['http_code']){
  3648. case 400:
  3649. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." $username already has access to the shared libraries $errorMessage");
  3650. break;
  3651. case 401:
  3652. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." invalid Plex Token $errorMessage");
  3653. break;
  3654. case 422:
  3655. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." user info error $errorMessage");
  3656. break;
  3657. case 429:
  3658. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." too many requests to plex.tv please try later $errorMessage");
  3659. break;
  3660. case 200:
  3661. case 201:
  3662. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3663. break;
  3664. default:
  3665. writeLog("error", "PLEX JOIN: unknown error, $errorMessage Error: ".$api['http_code']['http_code']);
  3666. }
  3667. //prettyPrint($api);
  3668. //prettyPrint(json_decode($api['content'], true));
  3669. return (!empty($success) && empty($errors) ? true : false );
  3670. }
  3671. function getCert(){
  3672. $url = "http://curl.haxx.se/ca/cacert.pem";
  3673. $file = getcwd()."/config/cacert.pem";
  3674. $directory = getcwd()."/config/";
  3675. @mkdir($directory, 0770, true);
  3676. if(!file_exists($file)){
  3677. file_put_contents( $file, fopen($url, 'r'));
  3678. writeLog("success", "CERT PEM: pem file created");
  3679. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3680. file_put_contents( $file, fopen($url, 'r'));
  3681. writeLog("success", "CERT PEM: downloaded new pem file");
  3682. }
  3683. return $file;
  3684. }
  3685. function customCSS(){
  3686. if(CUSTOMCSS == "true") {
  3687. $template_file = "custom.css";
  3688. $file_handle = fopen($template_file, "rb");
  3689. echo "\n";
  3690. echo fread($file_handle, filesize($template_file));
  3691. fclose($file_handle);
  3692. echo "\n";
  3693. }
  3694. }
  3695. function tvdbToken(){
  3696. $headers = array(
  3697. "Accept" => "application/json",
  3698. "Content-Type" => "application/json"
  3699. );
  3700. $json = array(
  3701. "apikey" => "FBE7B62621F4CAD7",
  3702. "userkey" => "328BB46EB1E9A0F5",
  3703. "username" => "causefx"
  3704. );
  3705. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3706. return json_decode($api['content'], true)['token'];
  3707. }
  3708. function tvdbGet($id){
  3709. $headers = array(
  3710. "Accept" => "application/json",
  3711. "Authorization" => "Bearer ".tvdbToken(),
  3712. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3713. "trakt-api-version" => "2"
  3714. );
  3715. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3716. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3717. if(empty($api['trakt'])){
  3718. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3719. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3720. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3721. $api['series'] = json_decode($series, true)['data'];
  3722. $api['poster'] = json_decode($poster, true)['data'];
  3723. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3724. }
  3725. return $api;
  3726. }
  3727. function tvdbSearch($name, $type){
  3728. $name = rawurlencode(preg_replace("/\(([^()]*+|(?R))*\)/","", $name));
  3729. $headers = array(
  3730. "Accept" => "application/json",
  3731. "Authorization" => "Bearer ".tvdbToken(),
  3732. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3733. "trakt-api-version" => "2"
  3734. );
  3735. $trakt = curl_get("https://api.trakt.tv/search/$type?query=$name", $headers);
  3736. @$api['trakt'] = json_decode($trakt, true)[0][$type]['ids'];
  3737. return $api;
  3738. }
  3739. function getPlexPlaylists(){
  3740. $address = qualifyURL(PLEXURL);
  3741. // Perform API requests
  3742. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3743. libxml_use_internal_errors(true);
  3744. $api = simplexml_load_string($api);
  3745. if (is_array($api) || is_object($api)){
  3746. if (!$api->head->title){
  3747. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3748. if (!$getServer) { return 'Could not load!'; }
  3749. // Identify the local machine
  3750. $gotServer = $getServer['machineIdentifier'];
  3751. $output = "";
  3752. $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; height: 200px;" class="dropdown-menu filter-recent-playlist playlist-listing">';
  3753. foreach($api AS $child) {
  3754. $items = array();
  3755. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3756. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3757. $api = simplexml_load_string($api);
  3758. if (is_array($api) || is_object($api)){
  3759. if (!$api->head->title){
  3760. $className = preg_replace("/(\W)+/", "", $api['title']);
  3761. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3762. foreach($api->Video AS $child){
  3763. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3764. }
  3765. if (count($items)) {
  3766. $output .= ''.implode('',$items).'';
  3767. }
  3768. }
  3769. }
  3770. }
  3771. }
  3772. $hideMenu .= '</ul></div></div>';
  3773. 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>';
  3774. }else{
  3775. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3776. }
  3777. }else{
  3778. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3779. }
  3780. }
  3781. function readExternalLog($type,$filename,$name = null){
  3782. $log = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3783. $log = array_reverse($log);
  3784. foreach($log as $line){
  3785. if(!empty($line) && $line[0] != " "){
  3786. $line = strip($line);
  3787. if($type == "single"){
  3788. if( strpos( strtolower($line), "ror" ) !== false ) {
  3789. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3790. }else{
  3791. echo "<tr><td>".$line."</td></tr>";
  3792. }
  3793. }elseif($type == "all"){
  3794. if( strpos( strtolower($line), "ror" ) !== false ) {
  3795. echo "<tr><td class='red-bg'>".$name."</td>";
  3796. echo "<td class='red-bg'>".$line."</td></tr>";
  3797. }else{
  3798. echo "<tr><td>".$name."</td>";
  3799. echo "<td>".$line."</td></tr>";
  3800. }
  3801. }
  3802. }
  3803. }
  3804. }
  3805. function getLogs(){
  3806. $path = __DIR__ ."/logs/";
  3807. @mkdir($path, 0770, true);
  3808. $logs = array();
  3809. $files = array_diff(scandir($path), array('.', '..'));
  3810. foreach($files as $v){
  3811. $title = explode(".", $v)[0];
  3812. $logs[$title] = $path.$v;
  3813. }
  3814. return $logs;
  3815. }
  3816. function getBackups(){
  3817. $path = DATABASE_LOCATION ."backups/";
  3818. @mkdir($path, 0770, true);
  3819. $backups = array();
  3820. $files = array_diff(scandir($path), array('.', '..'));
  3821. return array_reverse($files);
  3822. }
  3823. function getExtension($string) {
  3824. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3825. }
  3826. function showFile(){
  3827. $file = $_GET['file'];
  3828. $fileType = getExtension($file);
  3829. if($fileType != 'php'){
  3830. header("Content-type: ".mimeTypes()[$fileType]);
  3831. @readfile($file);
  3832. }
  3833. }
  3834. function getCalendar(){
  3835. $sonarr = new Sonarr(SONARRURL, SONARRKEY);
  3836. $radarr = new Sonarr(RADARRURL, RADARRKEY);
  3837. $sickrage = new SickRage(SICKRAGEURL, SICKRAGEKEY);
  3838. $startDate = date('Y-m-d',strtotime("-".CALENDARSTARTDAY." days"));
  3839. $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
  3840. $calendarItems = array();
  3841. if (SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)){
  3842. try {
  3843. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate));
  3844. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  3845. } catch (Exception $e) {
  3846. writeLog("error", "SONARR ERROR: ".strip($e->getMessage()));
  3847. }
  3848. }
  3849. if (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)){
  3850. try {
  3851. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate));
  3852. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  3853. } catch (Exception $e) {
  3854. writeLog("error", "RADARR ERROR: ".strip($e->getMessage()));
  3855. }
  3856. }
  3857. if (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH)){
  3858. $couchCalendar = getCouchCalendar();
  3859. if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
  3860. }
  3861. if (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)){
  3862. $headphonesHistory = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getHistory");
  3863. $headphonesWanted = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getWanted");
  3864. if(!empty($headphonesHistory)) { $calendarItems = array_merge($calendarItems, $headphonesHistory); }
  3865. if(!empty($headphonesWanted)) { $calendarItems = array_merge($calendarItems, $headphonesWanted); }
  3866. }
  3867. if (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)){
  3868. try {
  3869. $sickrageFuture = getSickrageCalendarWanted($sickrage->future());
  3870. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  3871. } catch (Exception $e) {
  3872. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3873. } try {
  3874. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"));
  3875. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  3876. } catch (Exception $e) {
  3877. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3878. }
  3879. }
  3880. return $calendarItems;
  3881. }
  3882. function localURL($url){
  3883. if (strpos($url, 'https') !== false) {
  3884. preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $url, $result);
  3885. $result = (!empty($result) ? true : false);
  3886. return $result;
  3887. }
  3888. }
  3889. function fileArray($files){
  3890. foreach($files as $file){
  3891. if(file_exists($file)){
  3892. $list[] = $file;
  3893. }
  3894. }
  3895. if(!empty($list)){ return $list; }
  3896. }
  3897. function backupDB(){
  3898. if (extension_loaded('ZIP')) {
  3899. $directory = DATABASE_LOCATION."backups/";
  3900. @mkdir($directory, 0770, true);
  3901. $orgFiles = array(
  3902. 'css' => 'custom.css',
  3903. 'temp' => 'cus.sd',
  3904. 'orgLog' => DATABASE_LOCATION.'org.log',
  3905. 'loginLog' => DATABASE_LOCATION.'loginLog.json',
  3906. 'chatDB' => 'chatpack.db',
  3907. 'config' => 'config/config.php',
  3908. 'database' => DATABASE_LOCATION.'users.db'
  3909. );
  3910. $files = fileArray($orgFiles);
  3911. if(!empty($files)){
  3912. writeLog("success", "BACKUP: backup process started");
  3913. $zipname = $directory.'backup['.date('Y-m-d_H-i').']['.INSTALLEDVERSION.'].zip';
  3914. $zip = new ZipArchive;
  3915. $zip->open($zipname, ZipArchive::CREATE);
  3916. foreach ($files as $file) {
  3917. $zip->addFile($file);
  3918. }
  3919. $zip->close();
  3920. writeLog("success", "BACKUP: backup process finished");
  3921. return true;
  3922. }else{
  3923. return false;
  3924. }
  3925. }else{
  3926. return false;
  3927. }
  3928. }
  3929. class Ping {
  3930. private $host;
  3931. private $ttl;
  3932. private $timeout;
  3933. private $port = 80;
  3934. private $data = 'Ping';
  3935. private $commandOutput;
  3936. /**
  3937. * Called when the Ping object is created.
  3938. *
  3939. * @param string $host
  3940. * The host to be pinged.
  3941. * @param int $ttl
  3942. * Time-to-live (TTL) (You may get a 'Time to live exceeded' error if this
  3943. * value is set too low. The TTL value indicates the scope or range in which
  3944. * a packet may be forwarded. By convention:
  3945. * - 0 = same host
  3946. * - 1 = same subnet
  3947. * - 32 = same site
  3948. * - 64 = same region
  3949. * - 128 = same continent
  3950. * - 255 = unrestricted
  3951. * @param int $timeout
  3952. * Timeout (in seconds) used for ping and fsockopen().
  3953. * @throws \Exception if the host is not set.
  3954. */
  3955. public function __construct($host, $ttl = 255, $timeout = 10) {
  3956. if (!isset($host)) {
  3957. throw new \Exception("Error: Host name not supplied.");
  3958. }
  3959. $this->host = $host;
  3960. $this->ttl = $ttl;
  3961. $this->timeout = $timeout;
  3962. }
  3963. /**
  3964. * Set the ttl (in hops).
  3965. *
  3966. * @param int $ttl
  3967. * TTL in hops.
  3968. */
  3969. public function setTtl($ttl) {
  3970. $this->ttl = $ttl;
  3971. }
  3972. /**
  3973. * Get the ttl.
  3974. *
  3975. * @return int
  3976. * The current ttl for Ping.
  3977. */
  3978. public function getTtl() {
  3979. return $this->ttl;
  3980. }
  3981. /**
  3982. * Set the timeout.
  3983. *
  3984. * @param int $timeout
  3985. * Time to wait in seconds.
  3986. */
  3987. public function setTimeout($timeout) {
  3988. $this->timeout = $timeout;
  3989. }
  3990. /**
  3991. * Get the timeout.
  3992. *
  3993. * @return int
  3994. * Current timeout for Ping.
  3995. */
  3996. public function getTimeout() {
  3997. return $this->timeout;
  3998. }
  3999. /**
  4000. * Set the host.
  4001. *
  4002. * @param string $host
  4003. * Host name or IP address.
  4004. */
  4005. public function setHost($host) {
  4006. $this->host = $host;
  4007. }
  4008. /**
  4009. * Get the host.
  4010. *
  4011. * @return string
  4012. * The current hostname for Ping.
  4013. */
  4014. public function getHost() {
  4015. return $this->host;
  4016. }
  4017. /**
  4018. * Set the port (only used for fsockopen method).
  4019. *
  4020. * Since regular pings use ICMP and don't need to worry about the concept of
  4021. * 'ports', this is only used for the fsockopen method, which pings servers by
  4022. * checking port 80 (by default).
  4023. *
  4024. * @param int $port
  4025. * Port to use for fsockopen ping (defaults to 80 if not set).
  4026. */
  4027. public function setPort($port) {
  4028. $this->port = $port;
  4029. }
  4030. /**
  4031. * Get the port (only used for fsockopen method).
  4032. *
  4033. * @return int
  4034. * The port used by fsockopen pings.
  4035. */
  4036. public function getPort() {
  4037. return $this->port;
  4038. }
  4039. /**
  4040. * Return the command output when method=exec.
  4041. * @return string
  4042. */
  4043. public function getCommandOutput(){
  4044. return $this->commandOutput;
  4045. }
  4046. /**
  4047. * Matches an IP on command output and returns.
  4048. * @return string
  4049. */
  4050. public function getIpAddress() {
  4051. $out = array();
  4052. if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->commandOutput, $out)){
  4053. return $out[0];
  4054. }
  4055. return null;
  4056. }
  4057. /**
  4058. * Ping a host.
  4059. *
  4060. * @param string $method
  4061. * Method to use when pinging:
  4062. * - exec (default): Pings through the system ping command. Fast and
  4063. * robust, but a security risk if you pass through user-submitted data.
  4064. * - fsockopen: Pings a server on port 80.
  4065. * - socket: Creates a RAW network socket. Only usable in some
  4066. * environments, as creating a SOCK_RAW socket requires root privileges.
  4067. *
  4068. * @throws InvalidArgumentException if $method is not supported.
  4069. *
  4070. * @return mixed
  4071. * Latency as integer, in ms, if host is reachable or FALSE if host is down.
  4072. */
  4073. public function ping($method = 'exec') {
  4074. $latency = false;
  4075. switch ($method) {
  4076. case 'exec':
  4077. $latency = $this->pingExec();
  4078. break;
  4079. case 'fsockopen':
  4080. $latency = $this->pingFsockopen();
  4081. break;
  4082. case 'socket':
  4083. $latency = $this->pingSocket();
  4084. break;
  4085. default:
  4086. throw new \InvalidArgumentException('Unsupported ping method.');
  4087. }
  4088. // Return the latency.
  4089. return $latency;
  4090. }
  4091. /**
  4092. * The exec method uses the possibly insecure exec() function, which passes
  4093. * the input to the system. This is potentially VERY dangerous if you pass in
  4094. * any user-submitted data. Be SURE you sanitize your inputs!
  4095. *
  4096. * @return int
  4097. * Latency, in ms.
  4098. */
  4099. private function pingExec() {
  4100. $latency = false;
  4101. $ttl = escapeshellcmd($this->ttl);
  4102. $timeout = escapeshellcmd($this->timeout);
  4103. $host = escapeshellcmd($this->host);
  4104. // Exec string for Windows-based systems.
  4105. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  4106. // -n = number of pings; -i = ttl; -w = timeout (in milliseconds).
  4107. $exec_string = 'ping -n 1 -i ' . $ttl . ' -w ' . ($timeout * 1000) . ' ' . $host;
  4108. }
  4109. // Exec string for Darwin based systems (OS X).
  4110. else if(strtoupper(PHP_OS) === 'DARWIN') {
  4111. // -n = numeric output; -c = number of pings; -m = ttl; -t = timeout.
  4112. $exec_string = 'ping -n -c 1 -m ' . $ttl . ' -t ' . $timeout . ' ' . $host;
  4113. }
  4114. // Exec string for other UNIX-based systems (Linux).
  4115. else {
  4116. // -n = numeric output; -c = number of pings; -t = ttl; -W = timeout
  4117. $exec_string = 'ping -n -c 1 -t ' . $ttl . ' -W ' . $timeout . ' ' . $host . ' 2>&1';
  4118. }
  4119. exec($exec_string, $output, $return);
  4120. // Strip empty lines and reorder the indexes from 0 (to make results more
  4121. // uniform across OS versions).
  4122. $this->commandOutput = implode($output, '');
  4123. $output = array_values(array_filter($output));
  4124. // If the result line in the output is not empty, parse it.
  4125. if (!empty($output[1])) {
  4126. // Search for a 'time' value in the result line.
  4127. $response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)ms/", $output[1], $matches);
  4128. // If there's a result and it's greater than 0, return the latency.
  4129. if ($response > 0 && isset($matches['time'])) {
  4130. $latency = round($matches['time'], 2);
  4131. }
  4132. }
  4133. return $latency;
  4134. }
  4135. /**
  4136. * The fsockopen method simply tries to reach the host on a port. This method
  4137. * is often the fastest, but not necessarily the most reliable. Even if a host
  4138. * doesn't respond, fsockopen may still make a connection.
  4139. *
  4140. * @return int
  4141. * Latency, in ms.
  4142. */
  4143. private function pingFsockopen() {
  4144. $start = microtime(true);
  4145. // fsockopen prints a bunch of errors if a host is unreachable. Hide those
  4146. // irrelevant errors and deal with the results instead.
  4147. $fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  4148. if (!$fp) {
  4149. $latency = false;
  4150. }
  4151. else {
  4152. $latency = microtime(true) - $start;
  4153. $latency = round($latency * 1000, 2);
  4154. }
  4155. return $latency;
  4156. }
  4157. /**
  4158. * The socket method uses raw network packet data to try sending an ICMP ping
  4159. * packet to a server, then measures the response time. Using this method
  4160. * requires the script to be run with root privileges, though, so this method
  4161. * only works reliably on Windows systems and on Linux servers where the
  4162. * script is not being run as a web user.
  4163. *
  4164. * @return int
  4165. * Latency, in ms.
  4166. */
  4167. private function pingSocket() {
  4168. // Create a package.
  4169. $type = "\x08";
  4170. $code = "\x00";
  4171. $checksum = "\x00\x00";
  4172. $identifier = "\x00\x00";
  4173. $seq_number = "\x00\x00";
  4174. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4175. // Calculate the checksum.
  4176. $checksum = $this->calculateChecksum($package);
  4177. // Finalize the package.
  4178. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4179. // Create a socket, connect to server, then read socket and calculate.
  4180. if ($socket = socket_create(AF_INET, SOCK_RAW, 1)) {
  4181. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array(
  4182. 'sec' => 10,
  4183. 'usec' => 0,
  4184. ));
  4185. // Prevent errors from being printed when host is unreachable.
  4186. @socket_connect($socket, $this->host, null);
  4187. $start = microtime(true);
  4188. // Send the package.
  4189. @socket_send($socket, $package, strlen($package), 0);
  4190. if (socket_read($socket, 255) !== false) {
  4191. $latency = microtime(true) - $start;
  4192. $latency = round($latency * 1000, 2);
  4193. }
  4194. else {
  4195. $latency = false;
  4196. }
  4197. }
  4198. else {
  4199. $latency = false;
  4200. }
  4201. // Close the socket.
  4202. socket_close($socket);
  4203. return $latency;
  4204. }
  4205. /**
  4206. * Calculate a checksum.
  4207. *
  4208. * @param string $data
  4209. * Data for which checksum will be calculated.
  4210. *
  4211. * @return string
  4212. * Binary string checksum of $data.
  4213. */
  4214. private function calculateChecksum($data) {
  4215. if (strlen($data) % 2) {
  4216. $data .= "\x00";
  4217. }
  4218. $bit = unpack('n*', $data);
  4219. $sum = array_sum($bit);
  4220. while ($sum >> 16) {
  4221. $sum = ($sum >> 16) + ($sum & 0xffff);
  4222. }
  4223. return pack('n*', ~$sum);
  4224. }
  4225. }
  4226. function ping($pings, $type = "string") {
  4227. $ping = new Ping("");
  4228. $ping->setTtl(128);
  4229. $ping->setTimeout(2);
  4230. switch ($type){
  4231. case "array":
  4232. $results = [];
  4233. foreach ($pings as $k => $v) {
  4234. if(strpos($v, ':') !== false){
  4235. $domain = explode(':', $v)[0];
  4236. $port = explode(':', $v)[1];
  4237. $ping->setHost($domain);
  4238. $ping->setPort($port);
  4239. $latency = $ping->ping('fsockopen');
  4240. }else{
  4241. $ping->setHost($v);
  4242. $latency = $ping->ping();
  4243. }
  4244. if ($latency || $latency === 0) {
  4245. $results[$k] = $latency;
  4246. } else {
  4247. $results[$k] = 0;
  4248. }
  4249. }
  4250. break;
  4251. case "string":
  4252. if(strpos($pings, ':') !== false){
  4253. $domain = explode(':', $pings)[0];
  4254. $port = explode(':', $pings)[1];
  4255. $ping->setHost($domain);
  4256. $ping->setPort($port);
  4257. $latency = $ping->ping('fsockopen');
  4258. }else{
  4259. $ping->setHost($pings);
  4260. $latency = $ping->ping();
  4261. }
  4262. if ($latency || $latency === 0) {
  4263. $results = $latency;
  4264. } else {
  4265. $results = 0;
  4266. }
  4267. break;
  4268. }
  4269. return $results;
  4270. }
  4271. function getPing($url, $style, $refresh = null){
  4272. if(ping($url) !== 0){
  4273. $class = 'success';
  4274. if(!$refresh){
  4275. $class .= " animated slideInLeft";
  4276. }
  4277. }else{
  4278. $class = "warning";
  4279. if(!$refresh){
  4280. $class .= " animated flash loop-animation-timeout";
  4281. }
  4282. }
  4283. echo '<span class="pingcheck badge ping-'.$class.'" style="position: absolute;z-index: 100;right: 5px; padding: 0px 0px;'.$style.';font-size: 10px;">&nbsp;</span>';
  4284. }
  4285. function speedTestData(){
  4286. $file_db = DATABASE_LOCATION."speedtest.db";
  4287. if(file_exists($file_db)){
  4288. $conn = new PDO("sqlite:$file_db") or die("1");
  4289. $result = $conn->query('SELECT * FROM speedtest_users');
  4290. $conn = null;
  4291. if (is_array($result) || is_object($result)){
  4292. foreach($result as $k => $v){
  4293. $return[$k] = $v;
  4294. }
  4295. return $return;
  4296. }
  4297. }
  4298. }
  4299. function speedTestDisplay($array, $output){
  4300. if (is_array($array) || is_object($array)){
  4301. if($output == "graph"){
  4302. $result = "Morris.Line({element: 'morris-line',data: [";
  4303. foreach($array as $k => $v){
  4304. $result .= "{ y: '".substr($v['timestamp'],0,10)."', a: ".$v['ul'].", b: ".$v['dl'].", c: ".$v['ping']." },";
  4305. }
  4306. $result .= "],xkey: 'y',ykeys: ['a', 'b', 'c'],labels: ['Upload', 'Download', 'Ping'],hideHover: 'auto',resize: true,lineColors: ['#63A8EB','#ccc','#000'] });";
  4307. }elseif($output == "table"){
  4308. $result = "";
  4309. foreach($array as $k => $v){
  4310. $result .= "<tr><td>".$v['timestamp']."</td><td>".$v['ip']."</td><td>".$v['dl']."</td><td>".$v['ul']."</td><td>".$v['ping']."</td><td>".$v['jitter']."</td></tr>";
  4311. }
  4312. }
  4313. return $result;
  4314. }
  4315. }
  4316. function buildMenuPhone($array){
  4317. if (is_array($array) || is_object($array)){
  4318. $result = '
  4319. <div class="content-box profile-sidebar box-shadow">
  4320. <img src="images/organizr-logo-h-d.png" width="100%" style="margin-top: -10px;">
  4321. <div class="profile-usermenu">
  4322. <ul class="nav" id="settings-list">
  4323. ';
  4324. foreach($array as $k => $v){
  4325. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4326. continue;
  4327. }
  4328. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4329. continue;
  4330. }
  4331. /*$result .= '
  4332. <li>
  4333. <a id="'.$v['id'].'" box="'.$v['box'].'">'.$v['name'].'
  4334. <span class="fa-stack fa-fw pull-right" style="margin-top: -5px;margin-right: -10px;">
  4335. <i class="fa fa-'.$v['icon_1'].' fa-stack-2x '.$v['color'].'" style="font-size:null;"></i>
  4336. <i class="fa fa-'.$v['icon_2'].' fa-stack-1x fa-inverse"></i>
  4337. </span>
  4338. </a>
  4339. </li>
  4340. ';*/
  4341. $result .= '<li><a id="'.$v['id'].'" box="'.$v['box'].'"><i class="fa fa-'.$v['icon_2'].' '.$v['color'].' fa-fw pull-right"></i>'.$v['name'].'</a></li>';
  4342. }
  4343. $result .= '</ul></div></div>';
  4344. return $result;
  4345. }
  4346. }
  4347. function buildMenu($array){
  4348. if (is_array($array) || is_object($array)){
  4349. $result = '<div class="settingsList">';
  4350. foreach($array as $k => $v){
  4351. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4352. continue;
  4353. }
  4354. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4355. continue;
  4356. }
  4357. $result .= '
  4358. <button id="'.$v['id'].'" box="'.$v['box'].'" type="button" style="border-radius: 0px !important; -webkit-border-radius: 0px !important;margin-bottom: 3px;margin-left:5px;color:white;" class="btn '.$v['color2'].' btn-icon waves waves-circle waves-effect waves-float settingsMenu">
  4359. <i class="mdi mdi-'.$v['icon_1'].' fa-fw pull-left" style="padding-left: '.$v['padding'].'px;font-size: 30px"></i>
  4360. <p class="" style="text-align: center;direction: rtl;display:none;margin: 2px;"><strong>'.$v['name'].'</strong></p>
  4361. </button>
  4362. ';
  4363. }
  4364. $result .= '</div>';
  4365. return $result;
  4366. }
  4367. }
  4368. function requestInvite($email, $username){
  4369. sendEmail($GLOBALS['USER']->adminEmail, "Admin", "Plex Invite Request", orgEmail("PLEX Invite Request", "Look who wants to join the cool club", "Admin", "Hey, The User: $user has requested access to your Plex Library.", "Generate Invite", null, "What Next?", "Well, That is up to you. You can go check on them if you like."));
  4370. }
  4371. function errormessage($msg) {
  4372. echo "<div style=\"margin-top: 50px;\">";
  4373. echo "<span style=\"color:#d89334;\">error </span>";
  4374. echo $msg;
  4375. echo "</div>";
  4376. }
  4377. function ajaxLoop($ajaxFunction, $refresh, $extraFunction = ''){
  4378. return "
  4379. setInterval(function() {
  4380. $.ajax({
  4381. url: 'ajax.php?a=".$ajaxFunction."',
  4382. timeout: 10000,
  4383. type: 'GET',
  4384. success: function(response) {
  4385. var getDiv = response;
  4386. var loadedID = $(getDiv).attr('id');
  4387. if (typeof loadedID !== 'undefined') {
  4388. var oldElement = $('#'+loadedID).prop('outerHTML');
  4389. var newElement = $(getDiv).prop('outerHTML');
  4390. if(oldElement !== newElement){
  4391. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  4392. ".$extraFunction."
  4393. console.log('".$ajaxFunction." has been updated');
  4394. }
  4395. }else{
  4396. console.log('".$ajaxFunction." data was not sufficent or is offline');
  4397. }
  4398. },
  4399. error: function(jqXHR, textStatus, errorThrown) {
  4400. console.error('".$ajaxFunction." could not be updated');
  4401. }
  4402. });
  4403. }, ".$refresh.");
  4404. ";
  4405. }
  4406. function getOrgUsers(){
  4407. $file_db = DATABASE_LOCATION."users.db";
  4408. if(file_exists($file_db)){
  4409. $conn = new PDO("sqlite:$file_db") or die("1");
  4410. $result = $conn->query('SELECT * FROM users');
  4411. $conn = null;
  4412. if (is_array($result) || is_object($result)){
  4413. foreach($result as $k => $v){
  4414. $return[$v['username']] = $v['email'];
  4415. }
  4416. return $return;
  4417. }
  4418. }
  4419. }
  4420. function getEmails($type = 'org'){
  4421. if($type == 'plex'){
  4422. $emails = array_merge(libraryList()['both'],getOrgUsers());
  4423. }elseif($type == 'emby'){
  4424. $emails = getOrgUsers();
  4425. }else{
  4426. $emails = getOrgUsers();
  4427. }
  4428. return $emails;
  4429. }
  4430. function printEmails($emails){
  4431. $result = '';
  4432. foreach($emails as $k => $v){
  4433. $result .= '<option value="'.$v.'">'.$k.'</option>';
  4434. }
  4435. return $result;
  4436. }
  4437. function massEmail($to, $subject, $message){
  4438. if (!isset($GLOBALS['file_db'])) {
  4439. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  4440. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4441. }
  4442. sendEmail(null, null, $subject, orgEmail("Message From Admin", "Important Information", "There", $message, null, null, "Thank You!", "Thanks for taking the time to read this message from me."),$GLOBALS['USER']->adminEmail,$to);
  4443. }
  4444. function q2a($q){
  4445. if (is_array($q) || is_object($q)){
  4446. foreach ($q as $k => $v){
  4447. $a[$k] = $v;
  4448. }
  4449. if(!empty($a)){
  4450. return $a;
  4451. }
  4452. }
  4453. }
  4454. function getOmbiToken($username, $password){
  4455. $headers = array(
  4456. "Accept" => "application/json",
  4457. "Content-Type" => "application/json"
  4458. );
  4459. $json = array(
  4460. "username" => $username,
  4461. "password" => $password,
  4462. "rememberMe" => "true",
  4463. );
  4464. $api = curl_post(OMBIURL."/api/v1/Token", $json, $headers);
  4465. if (isset($api['content'])) {
  4466. return json_decode($api['content'], true)['access_token'];
  4467. }else{
  4468. return false;
  4469. }
  4470. }
  4471. function ombiAction($id, $action, $type){
  4472. $headers = array(
  4473. "Accept" => "application/json",
  4474. "Content-Type" => "application/json",
  4475. "Apikey" => OMBIKEY
  4476. );
  4477. $body = array(
  4478. 'id' => $id,
  4479. );
  4480. switch ($type) {
  4481. case 'season':
  4482. case 'tv':
  4483. $type = 'tv';
  4484. break;
  4485. default:
  4486. $type = 'movie';
  4487. break;
  4488. }
  4489. switch ($action) {
  4490. case 'approve':
  4491. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/approve", $body, $headers);
  4492. break;
  4493. case 'available':
  4494. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/available", $body, $headers);
  4495. break;
  4496. case 'unavailable':
  4497. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/unavailable", $body, $headers);
  4498. break;
  4499. case 'deny':
  4500. $api = curl_put(OMBIURL."/api/v1/Request/".$type."/deny", $body, $headers);
  4501. break;
  4502. case 'delete':
  4503. $api = curl_delete(OMBIURL."/api/v1/Request/".$type."/".$id, $headers);
  4504. break;
  4505. default:
  4506. # code...
  4507. break;
  4508. }
  4509. switch ($api['http_code']['http_code']){
  4510. case 401:
  4511. writeLog("error", "OMBI: Invalid API KEY");
  4512. return false;
  4513. break;
  4514. case 200:
  4515. writeLog("success", "OMBI: action completed successfully for [type: $type - action: $action - id: $id]");
  4516. return true;
  4517. break;
  4518. default:
  4519. writeLog("error", "OMBI: unknown error with request [type: $type - action: $action - id: $id]");
  4520. return false;
  4521. }
  4522. //return (!empty($result) ? $result : null );
  4523. }
  4524. function getOmbiRequests($type = "both"){
  4525. $headers = array(
  4526. "Accept" => "application/json",
  4527. "Apikey" => OMBIKEY,
  4528. );
  4529. $requests = array();
  4530. switch ($type) {
  4531. case 'movie':
  4532. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4533. break;
  4534. case 'tv':
  4535. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4536. break;
  4537. default:
  4538. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4539. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4540. break;
  4541. }
  4542. if(isset($movie)){
  4543. //$movie = array_reverse($movie);
  4544. foreach ($movie as $key => $value) {
  4545. $poster = explode('/',$value['posterPath']);
  4546. $requests[] = array(
  4547. 'id' => $value['theMovieDbId'],
  4548. 'title' => $value['title'],
  4549. 'poster' => (strpos($value['posterPath'], "/") !== false) ? 'https://image.tmdb.org/t/p/w300/'.end($poster) : 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'],
  4550. 'approved' => $value['approved'],
  4551. 'available' => $value['available'],
  4552. 'denied' => $value['denied'],
  4553. 'deniedReason' => $value['deniedReason'],
  4554. 'user' => $value['requestedUser']['userName'],
  4555. 'request_id' => $value['id'],
  4556. 'request_date' => $value['requestedDate'],
  4557. 'release_date' => $value['releaseDate'],
  4558. 'type' => 'movie',
  4559. 'icon' => 'mdi mdi-filmstrip',
  4560. 'color' => 'palette-Deep-Purple-900 bg white',
  4561. );
  4562. }
  4563. }
  4564. if(isset($tv) && (is_array($tv) || is_object($tv))){
  4565. foreach ($tv as $key => $value) {
  4566. if(is_array($value['childRequests'][0])){
  4567. $requests[] = array(
  4568. 'id' => $value['tvDbId'],
  4569. 'title' => $value['title'],
  4570. 'poster' => $value['posterPath'],
  4571. 'approved' => $value['childRequests'][0]['approved'],
  4572. 'available' => $value['childRequests'][0]['available'],
  4573. 'denied' => $value['childRequests'][0]['denied'],
  4574. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  4575. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  4576. 'request_id' => $value['id'],
  4577. 'request_date' => $value['childRequests'][0]['requestedDate'],
  4578. 'release_date' => $value['releaseDate'],
  4579. 'type' => 'tv',
  4580. 'icon' => 'mdi mdi-television',
  4581. 'color' => 'grayish-blue-bg',
  4582. );
  4583. }
  4584. }
  4585. }
  4586. return (empty($requests)) ? '' : $requests;
  4587. }
  4588. function convertOmbiString($type, $value){
  4589. switch ($type) {
  4590. case 'approved':
  4591. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4592. $string['icon'] = ($value) ? 'mdi mdi-check' : 'mdi mdi-clock';
  4593. $string['color'] = ($value) ? 'green-bg' : 'yellow-bg';
  4594. break;
  4595. case 'available':
  4596. $string['string'] = ($value) ? 'Available' : 'Not Downloaded';
  4597. $string['icon'] = ($value) ? 'mdi mdi-server' : 'mdi mdi-server-off';
  4598. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4599. break;
  4600. case 'denied':
  4601. $string['string'] = ($value) ? 'Denied' : 'Approved';
  4602. $string['icon'] = ($value) ? 'mdi mdi-emoticon-sad' : 'mdi mdi-emoticon-happy';
  4603. $string['color'] = ($value) ? 'red-bg' : 'green-bg';
  4604. break;
  4605. case 'status':
  4606. switch ($value) {
  4607. case '1':
  4608. $string['string'] = 'Denied';
  4609. $string['icon'] = 'mdi mdi-window-close';
  4610. $string['color'] = 'red-bg';
  4611. break;
  4612. case '2':
  4613. $string['string'] = 'Approved';
  4614. $string['icon'] = 'mdi mdi-check';
  4615. $string['color'] = 'green-bg';
  4616. break;
  4617. case '3':
  4618. $string['string'] = 'Not Approved';
  4619. $string['icon'] = 'mdi mdi-clock';
  4620. $string['color'] = 'yellow-bg';
  4621. break;
  4622. default:
  4623. # code...
  4624. break;
  4625. }
  4626. break;
  4627. default:
  4628. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4629. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4630. break;
  4631. }
  4632. return $string;
  4633. }
  4634. function buildOmbiItem($type, $group, $user, $request){
  4635. if (is_array($request) || is_object($request)){
  4636. $actions = '';
  4637. if($request['denied']){
  4638. $status = 1;
  4639. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4640. }else{
  4641. if($request['approved']){
  4642. $status = 2;
  4643. }else{
  4644. $status = 3;
  4645. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4646. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="deny"><a class="requestAction" href="javascript:void(0)">Deny</a></li>';
  4647. }
  4648. }
  4649. if($request['available']){
  4650. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="unavailable"><a class="requestAction" href="javascript:void(0)">Mark as Unavailable</a></li>';
  4651. }else{
  4652. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="available"><a class="requestAction" href="javascript:void(0)">Mark as Available</a></li>';
  4653. }
  4654. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="delete"><a class="requestAction" href="javascript:void(0)">Delete</a></li>';
  4655. if(isset($group) && $group == 'admin'){
  4656. $actionMenu = '
  4657. <div class="requestOptions">
  4658. <div class="btn-group transparent" role="group">
  4659. <button type="button" class="btn waves btn-success btn-sm dropdown-toggle waves-effect waves-float transparent" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="mdi mdi-dots-vertical mdi-24px"></i></button>
  4660. <ul class="dropdown-menu"><h6 class="text-center requestHeader gray-bg">'.$request['user'].'</h6>'.$actions.'</ul>
  4661. </div>
  4662. </div>
  4663. ';
  4664. }else{
  4665. $actionMenu = '';
  4666. }
  4667. if((isset($group)) && $group == 'admin' || REQUESTEDUSERONLY == 'false'){
  4668. return '
  4669. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4670. '.$actionMenu.'
  4671. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4672. <div class="requestBottom text-center">
  4673. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4674. <i class="'.$request['icon'].'"></i>
  4675. </div>
  4676. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4677. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4678. </div>
  4679. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4680. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4681. </div>
  4682. </div>
  4683. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4684. </div>';
  4685. }else{
  4686. if(strtolower($request['user']) == strtolower($user)){
  4687. return '
  4688. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4689. '.$actionMenu.'
  4690. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4691. <div class="requestBottom text-center">
  4692. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4693. <i class="'.$request['icon'].'"></i>
  4694. </div>
  4695. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4696. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4697. </div>
  4698. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4699. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4700. </div>
  4701. </div>
  4702. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4703. </div>';
  4704. }
  4705. }
  4706. }
  4707. }
  4708. function buildOmbiList($group, $user){
  4709. $requests = array();
  4710. $movieList = getOmbiRequests('movie');
  4711. $tvList = getOmbiRequests('tv');
  4712. if(is_array($movieList) && is_array($tvList)){
  4713. $result = array_merge($movieList , $tvList );
  4714. }else{
  4715. if(is_array($movieList)){
  4716. $result = $movieList;
  4717. }elseif(is_array($tvList)){
  4718. $result = $tvList;
  4719. }else{
  4720. $result = false;
  4721. }
  4722. }
  4723. if (is_array($result) || is_object($result)){
  4724. usort($result, function ($item1, $item2) {
  4725. if ($item1['request_date'] == $item2['request_date']) return 0;
  4726. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  4727. });
  4728. foreach ($result as $request) {
  4729. if($request['type'] == 'movie'){
  4730. $requests[] = buildOmbiItem('movie', $group, $user, $request);
  4731. }elseif($request['type'] == 'tv'){
  4732. $requests[] = buildOmbiItem('season', $group, $user, $request);
  4733. }
  4734. }
  4735. }
  4736. return outputOmbiRequests("Requested Content", $requests, ajaxLoop('ombi-requests',REQUESTREFRESH,'loadSlick();'), false);
  4737. }
  4738. function outputOmbiRequests($header = "Requested Content", $items, $script = false, $array) {
  4739. $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-request-event">';
  4740. if(preg_grep("/item-movie-Approved/", $items)){
  4741. $hideMenu .= '<li data-filter="item-movie-Approved" data-name="Approved Movies" data-filter-on="false"><a class="js-filter-movie" href="javascript:void(0)">Approved Movies</a></li>';
  4742. }
  4743. if(preg_grep("/item-movie-Approval-Pending/", $items)){
  4744. $hideMenu .= '<li data-filter="item-movie-Approval-Pending" data-name="Approval Pending Movies" data-filter-on="false"><a class="js-filter-movie" href="javascript:void(0)">Approval Pending Movies</a></li>';
  4745. }
  4746. if(preg_grep("/item-season-Approved/", $items)){
  4747. $hideMenu .= '<li data-filter="item-season-Approved" data-name="Approved TV Shows" data-filter-on="false"><a class="js-filter-season" href="javascript:void(0)">Approved Shows</a></li>';
  4748. }
  4749. if(preg_grep("/item-season-Approval-Pending/", $items)){
  4750. $hideMenu .= '<li data-filter="item-season-Approval-Pending" data-name="Approval Pending TV Shows" data-filter-on="false"><a class="js-filter-season" href="javascript:void(0)">Approval Pending Shows</a></li>';
  4751. }
  4752. $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>';
  4753. $hideMenu .= '</ul></div></div>';
  4754. // If None Populate Empty Item
  4755. //if (count(array_flip($items)) < 1) {
  4756. if(!array_filter($items)) {
  4757. return '<div id="recentRequests"></div>';
  4758. }else{
  4759. $className = str_replace(' ', '', $header);
  4760. return '<div id="recentRequests" class="content-box box-shadow big-box"><h5 id="requestContent-title" style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-request" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  4761. }
  4762. }
  4763. function ombiAPI($action){
  4764. $headers = array(
  4765. "Accept" => "application/json",
  4766. "Content-Type" => "application/json",
  4767. "Apikey" => OMBIKEY
  4768. );
  4769. $body = array();
  4770. switch ($action) {
  4771. case 'plex-cache':
  4772. $api = curl_post(OMBIURL."/api/v1/Job/plexcontentcacher", $body, $headers);
  4773. break;
  4774. default:
  4775. break;
  4776. }
  4777. if(is_array($api) || is_object($api)){
  4778. switch ($api['http_code']['http_code']){
  4779. case 200:
  4780. return true;
  4781. break;
  4782. default:
  4783. return false;
  4784. }
  4785. }else{
  4786. return false;
  4787. }
  4788. }
  4789. function loadIcons(){
  4790. $dirname = "images/";
  4791. $images = scandir($dirname);
  4792. $ignore = Array(".", "..", "favicon", "settings", "cache", "platforms", "._.DS_Store", ".DS_Store", "confused.png", "sowwy.png", "sort-btns", "loading.png", "titlelogo.png", "default.svg", "login.png", "no-np.png", "no-list.png", "no-np.psd", "no-list.psd", "themes", "nadaplaying.jpg", "organizr-logo-h-d.png", "organizr-logo-h.png");
  4793. $allIcons = '';
  4794. foreach($images as $curimg){
  4795. if(!in_array($curimg, $ignore)) {
  4796. $allIcons .= '
  4797. <div class="col-xs-2" style="width: 75px; height: 75px; padding-right: 0px;">
  4798. <a data-toggle="tooltip" data-placement="bottom" title="'.$dirname.$curimg.'" class="thumbnail" style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
  4799. <img style="width: 50px; height: 50px;" data-src="'.$dirname.$curimg.'" alt="thumbnail" class="allIcons lazyload shadow">
  4800. </a>
  4801. </div>
  4802. ';
  4803. }
  4804. }
  4805. return $allIcons;
  4806. }
  4807. function buildHomepageSettings(){
  4808. $homepageOrder = homepageOrder();
  4809. $homepageList = '<h4>Drag Homepage Items to Order Them</h4><div id="homepage-items" class="external-events">';
  4810. $inputList = '<div id="homepage-values" class="row">';
  4811. foreach ($homepageOrder as $key => $val) {
  4812. switch ($key) {
  4813. case 'homepageOrdercustomhtml':
  4814. $class = 'palette-Deep-Purple-100 bg gray';
  4815. $image = 'images/html.png';
  4816. if(empty(HOMEPAGECUSTOMHTML1)){
  4817. $class .= ' faded';
  4818. }
  4819. break;
  4820. case 'homepageOrdernotice':
  4821. $class = 'palette-Cyan-A400 bg gray';
  4822. $image = 'images/pin.png';
  4823. if(empty(HOMEPAGENOTICETITLE) && empty(HOMEPAGENOTICEMESSAGE)){
  4824. $class .= ' faded';
  4825. }
  4826. break;
  4827. case 'homepageOrdernoticeguest':
  4828. $class = 'palette-Cyan-A400 bg gray';
  4829. $image = 'images/pin.png';
  4830. if(empty(HOMEPAGENOTICETITLEGUEST) && empty(HOMEPAGENOTICEMESSAGEGUEST)){
  4831. $class .= ' faded';
  4832. }
  4833. break;
  4834. case 'homepageOrderspeedtest':
  4835. $class = 'red-bg';
  4836. $image = 'images/settings/full-color/png/64px/speedometer.png';
  4837. if(SPEEDTEST !== "true"){
  4838. $class .= ' faded';
  4839. }
  4840. break;
  4841. case 'homepageOrdertransmisson':
  4842. $class = 'green-bg';
  4843. $image = 'images/transmission.png';
  4844. if(empty(TRANSMISSIONURL)){
  4845. $class .= ' faded';
  4846. }
  4847. break;
  4848. case 'homepageOrdernzbget':
  4849. $class = 'green-bg';
  4850. $image = 'images/nzbget.png';
  4851. if(empty(NZBGETURL)){
  4852. $class .= ' faded';
  4853. }
  4854. break;
  4855. case 'homepageOrdersabnzbd':
  4856. $class = 'yellow-bg';
  4857. $image = 'images/sabnzbd.png';
  4858. if(empty(SABNZBDURL)){
  4859. $class .= ' faded';
  4860. }
  4861. break;
  4862. case 'homepageOrderplexsearch':
  4863. case 'homepageOrderplexnowplaying':
  4864. case 'homepageOrderplexrecent':
  4865. case 'homepageOrderplexplaylist':
  4866. $class = 'palette-Amber-A700 bg gray';
  4867. $image = 'images/plex.png';
  4868. if(empty(PLEXURL)){
  4869. $class .= ' faded';
  4870. }
  4871. break;
  4872. case 'homepageOrderembynowplaying':
  4873. case 'homepageOrderembyrecent':
  4874. $class = 'palette-Green-A700 bg gray';
  4875. $image = 'images/emby.png';
  4876. if(empty(EMBYURL)){
  4877. $class .= ' faded';
  4878. }
  4879. break;
  4880. case 'homepageOrderombi':
  4881. $class = 'orange-bg';
  4882. $image = 'images/ombi.png';
  4883. if(empty(OMBIURL)){
  4884. $class .= ' faded';
  4885. }
  4886. break;
  4887. case 'homepageOrdercalendar':
  4888. $class = 'palette-Blue-400 bg gray';
  4889. $image = 'images/calendar.png';
  4890. if(SONARRURL == "" && RADARRURL == "" && HEADPHONESURL == "" && SICKRAGEURL == "" && COUCHURL == "" ){
  4891. $class .= ' faded';
  4892. }
  4893. break;
  4894. default:
  4895. $class = 'blue-bg';
  4896. $image = '';
  4897. break;
  4898. }
  4899. $homepageList .= '
  4900. <div class="col-md-3 sort-homepage"><div class="fc-event '.$class.'">
  4901. <span class="ordinal-position text-uppercase badge badge-gray" data-link="'.$key.'" style="float:left;width: 30px;">'.$val.'</span>
  4902. &nbsp; '.strtoupper(substr($key, 13)).'
  4903. <span class="remove-event"><img style="width: 22px;" src="'.$image.'"></span>
  4904. </div></div>';
  4905. $inputList .= '<input type="hidden" name="'.$key.'">';
  4906. }
  4907. $homepageList .= '</div>';
  4908. $inputList .= '</div>';
  4909. return $homepageList.$inputList;
  4910. }
  4911. function buildHomepage($group, $user){
  4912. $homepageOrder = homepageOrder();
  4913. $homepageBuilt = '';
  4914. foreach ($homepageOrder as $key => $value) {
  4915. $homepageBuilt .= buildHomepageItem($key, $group, $user);
  4916. }
  4917. return $homepageBuilt;
  4918. }
  4919. function realSize($bytes, $decimals = 2) {
  4920. $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
  4921. $factor = floor((strlen($bytes) - 1) / 3);
  4922. return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' '.@$size[$factor];
  4923. }
  4924. function buildHomepageItem($homepageItem, $group, $user){
  4925. $homepageItemBuilt = '';
  4926. switch ($homepageItem) {
  4927. case 'homepageOrderplexsearch':
  4928. if((qualifyUser(PLEXSEARCHAUTH) && PLEXSEARCH == "true" && qualifyUser(PLEXHOMEAUTH))) {
  4929. $homepageItemBuilt .= '
  4930. <div id="searchPlexRow" class="row">
  4931. <div class="col-lg-12">
  4932. <div class="content-box box-shadow big-box todo-list">
  4933. <form id="plexSearchForm" onsubmit="return false;" autocomplete="off">
  4934. <div class="">
  4935. <div class="input-group">
  4936. <div style="border-radius: 25px 0 0 25px; border:0" class="input-group-addon gray-bg"><i class="fa fa-search white"></i></div>
  4937. <input id="searchInput" type="text" style="border-radius: 0;" autocomplete="off" name="search-title" class="form-control input-group-addon gray-bg" placeholder="Media Search">
  4938. <div id="clearSearch" style="border-radius: 0 25px 25px 0;border:0; cursor: pointer;" class="input-group-addon gray-bg"><i class="fa fa-close white"></i></div>
  4939. <button style="display:none" id="plexSearchForm_submit" class="btn btn-primary waves"></button>
  4940. </div>
  4941. </div>
  4942. </form>
  4943. <div id="resultshere" class="table-responsive"></div>
  4944. </div>
  4945. </div>
  4946. </div>
  4947. ';
  4948. }
  4949. break;
  4950. case 'homepageOrdercustomhtml':
  4951. if (qualifyUser(HOMEPAGECUSTOMHTML1AUTH) && HOMEPAGECUSTOMHTML1) {
  4952. $homepageItemBuilt .= "<div>" . HOMEPAGECUSTOMHTML1 . "</div>";
  4953. }
  4954. break;
  4955. case 'homepageOrdernotice':
  4956. if (qualifyUser(HOMEPAGENOTICEAUTH) && HOMEPAGENOTICETITLE && HOMEPAGENOTICETYPE && HOMEPAGENOTICEMESSAGE && HOMEPAGENOTICELAYOUT) {
  4957. $homepageItemBuilt .= buildHomepageNotice(HOMEPAGENOTICELAYOUT, HOMEPAGENOTICETYPE, HOMEPAGENOTICETITLE, HOMEPAGENOTICEMESSAGE);
  4958. }
  4959. break;
  4960. case 'homepageOrdernoticeguest':
  4961. if ($group == 'guest' && HOMEPAGENOTICETITLEGUEST && HOMEPAGENOTICETYPEGUEST && HOMEPAGENOTICEMESSAGEGUEST && HOMEPAGENOTICELAYOUTGUEST) {
  4962. $homepageItemBuilt .= buildHomepageNotice(HOMEPAGENOTICELAYOUTGUEST, HOMEPAGENOTICETYPEGUEST, HOMEPAGENOTICETITLEGUEST, HOMEPAGENOTICEMESSAGEGUEST);
  4963. }
  4964. break;
  4965. case 'homepageOrderspeedtest':
  4966. if(SPEEDTEST == "true" && qualifyUser(SPEEDTESTAUTH)){
  4967. $homepageItemBuilt .= '
  4968. <style type="text/css">
  4969. .flash {
  4970. animation: flash 0.6s linear infinite;
  4971. }
  4972. @keyframes flash {
  4973. 0% { opacity: 0.6; }
  4974. 50% { opacity: 1; }
  4975. }
  4976. </style>
  4977. <script type="text/javascript">
  4978. var w = null
  4979. function runTest() {
  4980. document.getElementById("startBtn").style.display = "none"
  4981. document.getElementById("testArea").style.display = ""
  4982. document.getElementById("abortBtn").style.display = ""
  4983. w = new Worker("bower_components/speed/speedtest_worker.js")
  4984. var interval = setInterval(function () { w.postMessage("status") }, 100)
  4985. w.onmessage = function (event) {
  4986. var data = event.data.split(";")
  4987. var status = Number(data[0])
  4988. var dl = document.getElementById("download")
  4989. var ul = document.getElementById("upload")
  4990. var ping = document.getElementById("ping")
  4991. var jitter = document.getElementById("jitter")
  4992. dl.className = status === 1 ? "w-name flash" : "w-name"
  4993. ping.className = status === 2 ? "w-name flash" : "w-name"
  4994. jitter.className = ul.className = status === 3 ? "w-name flash" : "w-name"
  4995. if (status >= 4) {
  4996. clearInterval(interval)
  4997. document.getElementById("abortBtn").style.display = "none"
  4998. document.getElementById("startBtn").style.display = ""
  4999. w = null
  5000. }
  5001. if (status === 5) {
  5002. document.getElementById("testArea").style.display = "none"
  5003. }
  5004. dl.textContent = data[1] + " Mbit/s";
  5005. $("#downloadpercent").attr("style", "width: " + data[1] + "%;");
  5006. $("#uploadpercent").attr("style", "width: " + data[2] + "%;");
  5007. $("#pingpercent").attr("style", "width: " + data[3] + "%;");
  5008. $("#jitterpercent").attr("style", "width: " + data[5] + "%;");
  5009. ul.textContent = data[2] + " Mbit/s";
  5010. ping.textContent = data[3] + " ms";
  5011. jitter.textContent = data[5] + " ms";
  5012. }
  5013. w.postMessage(\'start {"telemetry_level":"basic"}\')
  5014. //w.postMessage("start")
  5015. }
  5016. function abortTest() {
  5017. if (w) w.postMessage("abort")
  5018. }
  5019. </script>
  5020. <div class="row" id="testArea" style="display:none">
  5021. <div class="test col-sm-3 col-lg-3">
  5022. <div class="content-box ultra-widget green-bg" data-counter="">
  5023. <div id="downloadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  5024. <div class="w-content">
  5025. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-download"></i></div>
  5026. <div class="w-descr left pull-left text-center">
  5027. <span class="testName text-uppercase w-name">Download</span>
  5028. <br>
  5029. <span class="w-name counter" id="download" ></span>
  5030. </div>
  5031. </div>
  5032. </div>
  5033. </div>
  5034. <div class="test col-sm-3 col-lg-3">
  5035. <div class="content-box ultra-widget red-bg" data-counter="">
  5036. <div id="uploadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  5037. <div class="w-content">
  5038. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-upload"></i></div>
  5039. <div class="w-descr left pull-left text-center">
  5040. <span class="testName text-uppercase w-name">Upload</span>
  5041. <br>
  5042. <span class="w-name counter" id="upload" ></span>
  5043. </div>
  5044. </div>
  5045. </div>
  5046. </div>
  5047. <div class="test col-sm-3 col-lg-3">
  5048. <div class="content-box ultra-widget yellow-bg" data-counter="">
  5049. <div id="pingpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  5050. <div class="w-content">
  5051. <div class="w-icon right pull-right"><i class="mdi mdi-timer"></i></div>
  5052. <div class="w-descr left pull-left text-center">
  5053. <span class="testName text-uppercase w-name">Latency</span>
  5054. <br>
  5055. <span class="w-name counter" id="ping" ></span>
  5056. </div>
  5057. </div>
  5058. </div>
  5059. </div>
  5060. <div class="test col-sm-3 col-lg-3">
  5061. <div class="content-box ultra-widget blue-bg" data-counter="">
  5062. <div id="jitterpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  5063. <div class="w-content">
  5064. <div class="w-icon right pull-right"><i class="mdi mdi-pulse"></i></div>
  5065. <div class="w-descr left pull-left text-center">
  5066. <span class="testName text-uppercase w-name">Jitter</span>
  5067. <br>
  5068. <span class="w-name counter" id="jitter" ></span>
  5069. </div>
  5070. </div>
  5071. </div>
  5072. </div>
  5073. <br/>
  5074. </div>
  5075. <div id="abortBtn" class="row" style="display: none" onclick="javascript:abortTest()">
  5076. <div class="col-lg-12">
  5077. <div class="content-box red-bg" style="cursor: pointer;">
  5078. <h1 style="margin: 10px" class="text-uppercase text-center">Abort Speed Test</h1>
  5079. <div class="clearfix"></div>
  5080. </div>
  5081. </div>
  5082. </div>
  5083. <div id="startBtn" class="row" onclick="javascript:runTest()">
  5084. <div class="col-lg-12">
  5085. <div class="content-box green-bg" style="cursor: pointer;">
  5086. <h1 style="margin: 10px" class="text-uppercase text-center">Run Speed Test</h1>
  5087. <div class="clearfix"></div>
  5088. </div>
  5089. </div>
  5090. </div>
  5091. ';
  5092. }
  5093. break;
  5094. case 'homepageOrdertransmisson':
  5095. if(TRANSMISSIONURL != "" && qualifyUser(TRANSMISSIONHOMEAUTH)){
  5096. $homepageItemBuilt .= buildDownloader('transmission', 'no');
  5097. }
  5098. break;
  5099. case 'homepageOrdernzbget':
  5100. if(NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)){
  5101. $homepageItemBuilt .= buildDownloader('nzbget');
  5102. }
  5103. break;
  5104. case 'homepageOrdersabnzbd':
  5105. if(SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH)) {
  5106. $homepageItemBuilt .= buildDownloader('sabnzbd');
  5107. }
  5108. break;
  5109. case 'homepageOrderplexnowplaying':
  5110. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  5111. if(qualifyUser(PLEXPLAYINGNOWAUTH) && PLEXPLAYINGNOW == "true"){
  5112. $homepageItemBuilt .= '<div id="plexRowNowPlaying" class="row">';
  5113. $homepageItemBuilt .= getPlexStreams(12, PLEXSHOWNAMES, $group);
  5114. $homepageItemBuilt .= '</div>';
  5115. }
  5116. }
  5117. break;
  5118. case 'homepageOrderplexrecent':
  5119. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  5120. if(qualifyUser(PLEXRECENTMOVIEAUTH) && PLEXRECENTMOVIE == "true" || qualifyUser(PLEXRECENTTVAUTH) && PLEXRECENTTV == "true" || qualifyUser(PLEXRECENTMUSICAUTH) && PLEXRECENTMUSIC == "true"){
  5121. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  5122. $homepageItemBuilt .= '<div id="plexRow" class="row"><div class="col-lg-12">';
  5123. $homepageItemBuilt .= getPlexRecent($plexArray);
  5124. $homepageItemBuilt .= '</div></div>';
  5125. }
  5126. }
  5127. break;
  5128. case 'homepageOrderplexplaylist':
  5129. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  5130. if(qualifyUser(PLEXPLAYLISTSAUTH) && PLEXPLAYLISTS == "true"){
  5131. $homepageItemBuilt .= '<div id="plexPlaylists" class="row"><div class="col-lg-12">';
  5132. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  5133. $homepageItemBuilt .= getPlexPlaylists($plexArray);
  5134. $homepageItemBuilt .= '</div> </div>';
  5135. }
  5136. }
  5137. break;
  5138. case 'homepageOrderembynowplaying':
  5139. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  5140. if(qualifyUser(EMBYPLAYINGNOWAUTH) && EMBYPLAYINGNOW == "true"){
  5141. $homepageItemBuilt .= '<div id="embyRowNowPlaying" class="row">';
  5142. $homepageItemBuilt .= getEmbyStreams(12, EMBYSHOWNAMES, $group);
  5143. $homepageItemBuilt .= '</div>';
  5144. }
  5145. }
  5146. break;
  5147. case 'homepageOrderembyrecent':
  5148. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  5149. if(qualifyUser(EMBYRECENTMOVIEAUTH) && EMBYRECENTMOVIE == "true" || qualifyUser(EMBYRECENTTVAUTH) && EMBYRECENTTV == "true" || qualifyUser(EMBYRECENTMUSICAUTH) && EMBYRECENTMUSIC == "true"){
  5150. $embyArray = array("Movie" => EMBYRECENTMOVIE, "Episode" => EMBYRECENTTV, "MusicAlbum" => EMBYRECENTMUSIC, "Series" => EMBYRECENTTV);
  5151. $homepageItemBuilt .= '<div id="embyRow" class="row"><div class="col-lg-12">';
  5152. $homepageItemBuilt .= getEmbyRecent($embyArray);
  5153. $homepageItemBuilt .= '</div></div>';
  5154. }
  5155. }
  5156. break;
  5157. case 'homepageOrderombi':
  5158. if (qualifyUser(OMBIAUTH) && OMBIURL) {
  5159. $homepageItemBuilt .= '<div id="ombiRequests" class="row"><div class="col-lg-12">';
  5160. $homepageItemBuilt .= buildOmbiList($group, $user);
  5161. $homepageItemBuilt .= '</div></div>';
  5162. }
  5163. break;
  5164. case 'homepageOrdercalendar':
  5165. if ((SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)) || (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)) || (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)) || (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)) || (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH))) {
  5166. $calendarItems = '';
  5167. if(RADARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="film" href="javascript:void(0)">Movies</a></li>'; }
  5168. if(SONARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="tv" href="javascript:void(0)">TV Shows</a></li>'; }
  5169. if(HEADPHONESURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="music" href="javascript:void(0)">Music</a></li>'; }
  5170. $homepageItemBuilt .= '
  5171. <div id="calendarLegendRow" class="row" style="padding: 0 0 10px 0;">
  5172. <div class="col-lg-12 content-form form-inline">
  5173. <div class="form-group pull-right">
  5174. <span class="swal-legend label label-primary well-sm">Legend</span>&nbsp;
  5175. <div class="btn-group" role="group">
  5176. <button id="calendarSelected" style="margin-right: 0px;" type="button" class="btn waves btn-default btn-sm dropdown-toggle waves-effect waves-float" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">View All&nbsp;<span class="caret"></span></button>
  5177. <ul style="right:0; left: auto" class="dropdown-menu">
  5178. <li><a class="calendarOption" calendarOption="all" href="javascript:void(0)">View All</a></li>
  5179. '.$calendarItems.'
  5180. </ul>
  5181. </div>
  5182. </div>
  5183. </div>
  5184. </div>
  5185. <div id="calendarRow" class="row">
  5186. <div class="col-lg-12">
  5187. <div id="calendar" class="fc-calendar box-shadow fc fc-ltr fc-unthemed"></div>
  5188. </div>
  5189. </div>
  5190. ';
  5191. }
  5192. break;
  5193. default:
  5194. # code...
  5195. break;
  5196. }
  5197. return $homepageItemBuilt;
  5198. }
  5199. function buildAccordion($items){
  5200. $i = 1;
  5201. $variables = '&nbsp; Available Variables: ';
  5202. $accordion = '<div style="margin-bottom: 0px;" class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">';
  5203. foreach ($items as $key => $value) {
  5204. foreach ($value['variables'] as $variable) {
  5205. $variables .= '<mark>'.$variable.'</mark>';
  5206. }
  5207. $accordion .= '
  5208. <div class="panel panel-default">
  5209. <div class="panel-heading" role="tab" id="heading-'.$i.'">
  5210. <h4 class="panel-title" style="text-decoration: none;" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-'.$i.'" aria-expanded="true" aria-controls="collapse-'.$i.'">'.$value['title'].'</h4>
  5211. </div>
  5212. <div id="collapse-'.$i.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-'.$i.'" aria-expanded="true">
  5213. <br/>'.$variables.'<br/></br/>
  5214. <div class="form-content col-sm-12 col-md-12 col-lg-12">
  5215. <input id="'.$value['template'].'Subject_id" name="'.$value['template'].'Subject" type="text" class="form-control material input-sm" autocorrect="off" autocapitalize="off" value="'.$value['subject'].'">
  5216. <p class="help-text">Email Subject</p>
  5217. </div>
  5218. <br/></br/>
  5219. <div class="summernote" name="'.$value['template'].'">'.$value['body'].'</div>
  5220. </div>
  5221. </div>
  5222. ';
  5223. $i++;
  5224. $variables = '&nbsp; Available Variables: ';
  5225. }
  5226. $accordion .= '</div>';
  5227. return $accordion;
  5228. }
  5229. function emailTemplate($emailTemplate){
  5230. $variables = [
  5231. '{user}' => $emailTemplate['user'],
  5232. '{domain}' => DOMAIN,
  5233. '{password}' => $emailTemplate['password'],
  5234. '{inviteCode}' => $emailTemplate['inviteCode'],
  5235. '{fullDomain}' => getServerPath(),
  5236. ];
  5237. $emailTemplate['body'] = strtr($emailTemplate['body'], $variables);
  5238. $emailTemplate['subject'] = strtr($emailTemplate['subject'], $variables);
  5239. return $emailTemplate;
  5240. }
  5241. function buildEmail($email){
  5242. $subject = (isset($email['subject'])) ? $email['subject'] : 'Message from Server';
  5243. $body = (isset($email['body'])) ? $email['body'] : 'Message Error Occured';
  5244. $type = (isset($email['type'])) ? $email['type'] : 'No Type';
  5245. switch ($type) {
  5246. case 'invite':
  5247. $extra = 'invite';
  5248. break;
  5249. case 'reset':
  5250. $extra = 'reset';
  5251. break;
  5252. default:
  5253. $extra = null;
  5254. break;
  5255. }
  5256. include('email.php');
  5257. return $email;
  5258. }
  5259. function buildDownloader($name, $type = 'both'){
  5260. if($type == 'both'){
  5261. $tabs = '
  5262. <ul class="nav nav-tabs pull-right">
  5263. <li class="active"><a href="#downloadQueue-'.$name.'" data-toggle="tab" aria-expanded="true">'.translate("QUEUE").'</a></li>
  5264. <li class=""><a href="#downloadHistory-'.$name.'" data-toggle="tab" aria-expanded="false">'.translate("HISTORY").'</a></li>
  5265. </ul>
  5266. ';
  5267. $bodyHistory = '
  5268. <div class="tab-pane fade" id="downloadHistory-'.$name.'">
  5269. <div class="table-responsive" style="max-height: 300px">
  5270. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5271. <thead>
  5272. <tr>
  5273. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5274. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5275. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5276. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5277. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5278. </tr>
  5279. </thead>
  5280. <tbody class="dl-history '.$name.'"></tbody>
  5281. </table>
  5282. </div>
  5283. </div>
  5284. ';
  5285. }else{
  5286. $tabs = '';
  5287. $bodyHistory = '';
  5288. }
  5289. return '
  5290. <div id="downloadClientRow" class="row">
  5291. <div class="col-xs-12 col-md-12">
  5292. <div class="content-box">
  5293. <div class="tabbable panel with-nav-tabs panel-default">
  5294. <div class="panel-heading">
  5295. <div class="content-tools i-block pull-right">
  5296. <a id="getDownloader" class="repeat-btn">
  5297. <i class="fa fa-repeat"></i>
  5298. </a>
  5299. </div>
  5300. <h3 class="pull-left">'.strtoupper($name).'</h3>
  5301. '.$tabs.'
  5302. <div class="clearfix"></div>
  5303. </div>
  5304. <div class="panel-body">
  5305. <div class="tab-content">
  5306. <div class="tab-pane fade active in" id="downloadQueue-'.$name.'">
  5307. <div class="table-responsive" style="max-height: 300px">
  5308. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5309. <thead>
  5310. <tr>
  5311. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5312. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5313. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5314. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5315. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5316. </tr>
  5317. </thead>
  5318. <tbody class="dl-queue '.$name.'"></tbody>
  5319. </table>
  5320. </div>
  5321. </div>
  5322. '.$bodyHistory.'
  5323. </div>
  5324. </div>
  5325. </div>
  5326. </div>
  5327. </div>
  5328. </div>';
  5329. }
  5330. class Mobile_Detect
  5331. {
  5332. /**
  5333. * Mobile detection type.
  5334. *
  5335. * @deprecated since version 2.6.9
  5336. */
  5337. const DETECTION_TYPE_MOBILE = 'mobile';
  5338. /**
  5339. * Extended detection type.
  5340. *
  5341. * @deprecated since version 2.6.9
  5342. */
  5343. const DETECTION_TYPE_EXTENDED = 'extended';
  5344. /**
  5345. * A frequently used regular expression to extract version #s.
  5346. *
  5347. * @deprecated since version 2.6.9
  5348. */
  5349. const VER = '([\w._\+]+)';
  5350. /**
  5351. * Top-level device.
  5352. */
  5353. const MOBILE_GRADE_A = 'A';
  5354. /**
  5355. * Mid-level device.
  5356. */
  5357. const MOBILE_GRADE_B = 'B';
  5358. /**
  5359. * Low-level device.
  5360. */
  5361. const MOBILE_GRADE_C = 'C';
  5362. /**
  5363. * Stores the version number of the current release.
  5364. */
  5365. const VERSION = '2.8.26';
  5366. /**
  5367. * A type for the version() method indicating a string return value.
  5368. */
  5369. const VERSION_TYPE_STRING = 'text';
  5370. /**
  5371. * A type for the version() method indicating a float return value.
  5372. */
  5373. const VERSION_TYPE_FLOAT = 'float';
  5374. /**
  5375. * A cache for resolved matches
  5376. * @var array
  5377. */
  5378. protected $cache = array();
  5379. /**
  5380. * The User-Agent HTTP header is stored in here.
  5381. * @var string
  5382. */
  5383. protected $userAgent = null;
  5384. /**
  5385. * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.
  5386. * @var array
  5387. */
  5388. protected $httpHeaders = array();
  5389. /**
  5390. * CloudFront headers. E.g. CloudFront-Is-Desktop-Viewer, CloudFront-Is-Mobile-Viewer & CloudFront-Is-Tablet-Viewer.
  5391. * @var array
  5392. */
  5393. protected $cloudfrontHeaders = array();
  5394. /**
  5395. * The matching Regex.
  5396. * This is good for debug.
  5397. * @var string
  5398. */
  5399. protected $matchingRegex = null;
  5400. /**
  5401. * The matches extracted from the regex expression.
  5402. * This is good for debug.
  5403. * @var string
  5404. */
  5405. protected $matchesArray = null;
  5406. /**
  5407. * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.
  5408. *
  5409. * @deprecated since version 2.6.9
  5410. *
  5411. * @var string
  5412. */
  5413. protected $detectionType = self::DETECTION_TYPE_MOBILE;
  5414. /**
  5415. * HTTP headers that trigger the 'isMobile' detection
  5416. * to be true.
  5417. *
  5418. * @var array
  5419. */
  5420. protected static $mobileHeaders = array(
  5421. 'HTTP_ACCEPT' => array('matches' => array(
  5422. // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
  5423. 'application/x-obml2d',
  5424. // BlackBerry devices.
  5425. 'application/vnd.rim.html',
  5426. 'text/vnd.wap.wml',
  5427. 'application/vnd.wap.xhtml+xml'
  5428. )),
  5429. 'HTTP_X_WAP_PROFILE' => null,
  5430. 'HTTP_X_WAP_CLIENTID' => null,
  5431. 'HTTP_WAP_CONNECTION' => null,
  5432. 'HTTP_PROFILE' => null,
  5433. // Reported by Opera on Nokia devices (eg. C3).
  5434. 'HTTP_X_OPERAMINI_PHONE_UA' => null,
  5435. 'HTTP_X_NOKIA_GATEWAY_ID' => null,
  5436. 'HTTP_X_ORANGE_ID' => null,
  5437. 'HTTP_X_VODAFONE_3GPDPCONTEXT' => null,
  5438. 'HTTP_X_HUAWEI_USERID' => null,
  5439. // Reported by Windows Smartphones.
  5440. 'HTTP_UA_OS' => null,
  5441. // Reported by Verizon, Vodafone proxy system.
  5442. 'HTTP_X_MOBILE_GATEWAY' => null,
  5443. // Seen this on HTC Sensation. SensationXE_Beats_Z715e.
  5444. 'HTTP_X_ATT_DEVICEID' => null,
  5445. // Seen this on a HTC.
  5446. 'HTTP_UA_CPU' => array('matches' => array('ARM')),
  5447. );
  5448. /**
  5449. * List of mobile devices (phones).
  5450. *
  5451. * @var array
  5452. */
  5453. protected static $phoneDevices = array(
  5454. 'iPhone' => '\biPhone\b|\biPod\b', // |\biTunes
  5455. 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+',
  5456. 'HTC' => 'HTC|HTC.*(Sensation|Evo|Vision|Explorer|6800|8100|8900|A7272|S510e|C110e|Legend|Desire|T8282)|APX515CKT|Qtek9090|APA9292KT|HD_mini|Sensation.*Z710e|PG86100|Z715e|Desire.*(A8181|HD)|ADR6200|ADR6400L|ADR6425|001HT|Inspire 4G|Android.*\bEVO\b|T-Mobile G1|Z520m',
  5457. 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 6',
  5458. // @todo: Is 'Dell Streak' a tablet or a phone? ;)
  5459. 'Dell' => 'Dell.*Streak|Dell.*Aero|Dell.*Venue|DELL.*Venue Pro|Dell Flash|Dell Smoke|Dell Mini 3iX|XCD28|XCD35|\b001DL\b|\b101DL\b|\bGS01\b',
  5460. 'Motorola' => 'Motorola|DROIDX|DROID BIONIC|\bDroid\b.*Build|Android.*Xoom|HRI39|MOT-|A1260|A1680|A555|A853|A855|A953|A955|A956|Motorola.*ELECTRIFY|Motorola.*i1|i867|i940|MB200|MB300|MB501|MB502|MB508|MB511|MB520|MB525|MB526|MB611|MB612|MB632|MB810|MB855|MB860|MB861|MB865|MB870|ME501|ME502|ME511|ME525|ME600|ME632|ME722|ME811|ME860|ME863|ME865|MT620|MT710|MT716|MT720|MT810|MT870|MT917|Motorola.*TITANIUM|WX435|WX445|XT300|XT301|XT311|XT316|XT317|XT319|XT320|XT390|XT502|XT530|XT531|XT532|XT535|XT603|XT610|XT611|XT615|XT681|XT701|XT702|XT711|XT720|XT800|XT806|XT860|XT862|XT875|XT882|XT883|XT894|XT901|XT907|XT909|XT910|XT912|XT928|XT926|XT915|XT919|XT925|XT1021|\bMoto E\b',
  5461. 'Samsung' => '\bSamsung\b|SM-G9250|GT-19300|SGH-I337|BGT-S5230|GT-B2100|GT-B2700|GT-B2710|GT-B3210|GT-B3310|GT-B3410|GT-B3730|GT-B3740|GT-B5510|GT-B5512|GT-B5722|GT-B6520|GT-B7300|GT-B7320|GT-B7330|GT-B7350|GT-B7510|GT-B7722|GT-B7800|GT-C3010|GT-C3011|GT-C3060|GT-C3200|GT-C3212|GT-C3212I|GT-C3262|GT-C3222|GT-C3300|GT-C3300K|GT-C3303|GT-C3303K|GT-C3310|GT-C3322|GT-C3330|GT-C3350|GT-C3500|GT-C3510|GT-C3530|GT-C3630|GT-C3780|GT-C5010|GT-C5212|GT-C6620|GT-C6625|GT-C6712|GT-E1050|GT-E1070|GT-E1075|GT-E1080|GT-E1081|GT-E1085|GT-E1087|GT-E1100|GT-E1107|GT-E1110|GT-E1120|GT-E1125|GT-E1130|GT-E1160|GT-E1170|GT-E1175|GT-E1180|GT-E1182|GT-E1200|GT-E1210|GT-E1225|GT-E1230|GT-E1390|GT-E2100|GT-E2120|GT-E2121|GT-E2152|GT-E2220|GT-E2222|GT-E2230|GT-E2232|GT-E2250|GT-E2370|GT-E2550|GT-E2652|GT-E3210|GT-E3213|GT-I5500|GT-I5503|GT-I5700|GT-I5800|GT-I5801|GT-I6410|GT-I6420|GT-I7110|GT-I7410|GT-I7500|GT-I8000|GT-I8150|GT-I8160|GT-I8190|GT-I8320|GT-I8330|GT-I8350|GT-I8530|GT-I8700|GT-I8703|GT-I8910|GT-I9000|GT-I9001|GT-I9003|GT-I9010|GT-I9020|GT-I9023|GT-I9070|GT-I9082|GT-I9100|GT-I9103|GT-I9220|GT-I9250|GT-I9300|GT-I9305|GT-I9500|GT-I9505|GT-M3510|GT-M5650|GT-M7500|GT-M7600|GT-M7603|GT-M8800|GT-M8910|GT-N7000|GT-S3110|GT-S3310|GT-S3350|GT-S3353|GT-S3370|GT-S3650|GT-S3653|GT-S3770|GT-S3850|GT-S5210|GT-S5220|GT-S5229|GT-S5230|GT-S5233|GT-S5250|GT-S5253|GT-S5260|GT-S5263|GT-S5270|GT-S5300|GT-S5330|GT-S5350|GT-S5360|GT-S5363|GT-S5369|GT-S5380|GT-S5380D|GT-S5560|GT-S5570|GT-S5600|GT-S5603|GT-S5610|GT-S5620|GT-S5660|GT-S5670|GT-S5690|GT-S5750|GT-S5780|GT-S5830|GT-S5839|GT-S6102|GT-S6500|GT-S7070|GT-S7200|GT-S7220|GT-S7230|GT-S7233|GT-S7250|GT-S7500|GT-S7530|GT-S7550|GT-S7562|GT-S7710|GT-S8000|GT-S8003|GT-S8500|GT-S8530|GT-S8600|SCH-A310|SCH-A530|SCH-A570|SCH-A610|SCH-A630|SCH-A650|SCH-A790|SCH-A795|SCH-A850|SCH-A870|SCH-A890|SCH-A930|SCH-A950|SCH-A970|SCH-A990|SCH-I100|SCH-I110|SCH-I400|SCH-I405|SCH-I500|SCH-I510|SCH-I515|SCH-I600|SCH-I730|SCH-I760|SCH-I770|SCH-I830|SCH-I910|SCH-I920|SCH-I959|SCH-LC11|SCH-N150|SCH-N300|SCH-R100|SCH-R300|SCH-R351|SCH-R400|SCH-R410|SCH-T300|SCH-U310|SCH-U320|SCH-U350|SCH-U360|SCH-U365|SCH-U370|SCH-U380|SCH-U410|SCH-U430|SCH-U450|SCH-U460|SCH-U470|SCH-U490|SCH-U540|SCH-U550|SCH-U620|SCH-U640|SCH-U650|SCH-U660|SCH-U700|SCH-U740|SCH-U750|SCH-U810|SCH-U820|SCH-U900|SCH-U940|SCH-U960|SCS-26UC|SGH-A107|SGH-A117|SGH-A127|SGH-A137|SGH-A157|SGH-A167|SGH-A177|SGH-A187|SGH-A197|SGH-A227|SGH-A237|SGH-A257|SGH-A437|SGH-A517|SGH-A597|SGH-A637|SGH-A657|SGH-A667|SGH-A687|SGH-A697|SGH-A707|SGH-A717|SGH-A727|SGH-A737|SGH-A747|SGH-A767|SGH-A777|SGH-A797|SGH-A817|SGH-A827|SGH-A837|SGH-A847|SGH-A867|SGH-A877|SGH-A887|SGH-A897|SGH-A927|SGH-B100|SGH-B130|SGH-B200|SGH-B220|SGH-C100|SGH-C110|SGH-C120|SGH-C130|SGH-C140|SGH-C160|SGH-C170|SGH-C180|SGH-C200|SGH-C207|SGH-C210|SGH-C225|SGH-C230|SGH-C417|SGH-C450|SGH-D307|SGH-D347|SGH-D357|SGH-D407|SGH-D415|SGH-D780|SGH-D807|SGH-D980|SGH-E105|SGH-E200|SGH-E315|SGH-E316|SGH-E317|SGH-E335|SGH-E590|SGH-E635|SGH-E715|SGH-E890|SGH-F300|SGH-F480|SGH-I200|SGH-I300|SGH-I320|SGH-I550|SGH-I577|SGH-I600|SGH-I607|SGH-I617|SGH-I627|SGH-I637|SGH-I677|SGH-I700|SGH-I717|SGH-I727|SGH-i747M|SGH-I777|SGH-I780|SGH-I827|SGH-I847|SGH-I857|SGH-I896|SGH-I897|SGH-I900|SGH-I907|SGH-I917|SGH-I927|SGH-I937|SGH-I997|SGH-J150|SGH-J200|SGH-L170|SGH-L700|SGH-M110|SGH-M150|SGH-M200|SGH-N105|SGH-N500|SGH-N600|SGH-N620|SGH-N625|SGH-N700|SGH-N710|SGH-P107|SGH-P207|SGH-P300|SGH-P310|SGH-P520|SGH-P735|SGH-P777|SGH-Q105|SGH-R210|SGH-R220|SGH-R225|SGH-S105|SGH-S307|SGH-T109|SGH-T119|SGH-T139|SGH-T209|SGH-T219|SGH-T229|SGH-T239|SGH-T249|SGH-T259|SGH-T309|SGH-T319|SGH-T329|SGH-T339|SGH-T349|SGH-T359|SGH-T369|SGH-T379|SGH-T409|SGH-T429|SGH-T439|SGH-T459|SGH-T469|SGH-T479|SGH-T499|SGH-T509|SGH-T519|SGH-T539|SGH-T559|SGH-T589|SGH-T609|SGH-T619|SGH-T629|SGH-T639|SGH-T659|SGH-T669|SGH-T679|SGH-T709|SGH-T719|SGH-T729|SGH-T739|SGH-T746|SGH-T749|SGH-T759|SGH-T769|SGH-T809|SGH-T819|SGH-T839|SGH-T919|SGH-T929|SGH-T939|SGH-T959|SGH-T989|SGH-U100|SGH-U200|SGH-U800|SGH-V205|SGH-V206|SGH-X100|SGH-X105|SGH-X120|SGH-X140|SGH-X426|SGH-X427|SGH-X475|SGH-X495|SGH-X497|SGH-X507|SGH-X600|SGH-X610|SGH-X620|SGH-X630|SGH-X700|SGH-X820|SGH-X890|SGH-Z130|SGH-Z150|SGH-Z170|SGH-ZX10|SGH-ZX20|SHW-M110|SPH-A120|SPH-A400|SPH-A420|SPH-A460|SPH-A500|SPH-A560|SPH-A600|SPH-A620|SPH-A660|SPH-A700|SPH-A740|SPH-A760|SPH-A790|SPH-A800|SPH-A820|SPH-A840|SPH-A880|SPH-A900|SPH-A940|SPH-A960|SPH-D600|SPH-D700|SPH-D710|SPH-D720|SPH-I300|SPH-I325|SPH-I330|SPH-I350|SPH-I500|SPH-I600|SPH-I700|SPH-L700|SPH-M100|SPH-M220|SPH-M240|SPH-M300|SPH-M305|SPH-M320|SPH-M330|SPH-M350|SPH-M360|SPH-M370|SPH-M380|SPH-M510|SPH-M540|SPH-M550|SPH-M560|SPH-M570|SPH-M580|SPH-M610|SPH-M620|SPH-M630|SPH-M800|SPH-M810|SPH-M850|SPH-M900|SPH-M910|SPH-M920|SPH-M930|SPH-N100|SPH-N200|SPH-N240|SPH-N300|SPH-N400|SPH-Z400|SWC-E100|SCH-i909|GT-N7100|GT-N7105|SCH-I535|SM-N900A|SGH-I317|SGH-T999L|GT-S5360B|GT-I8262|GT-S6802|GT-S6312|GT-S6310|GT-S5312|GT-S5310|GT-I9105|GT-I8510|GT-S6790N|SM-G7105|SM-N9005|GT-S5301|GT-I9295|GT-I9195|SM-C101|GT-S7392|GT-S7560|GT-B7610|GT-I5510|GT-S7582|GT-S7530E|GT-I8750|SM-G9006V|SM-G9008V|SM-G9009D|SM-G900A|SM-G900D|SM-G900F|SM-G900H|SM-G900I|SM-G900J|SM-G900K|SM-G900L|SM-G900M|SM-G900P|SM-G900R4|SM-G900S|SM-G900T|SM-G900V|SM-G900W8|SHV-E160K|SCH-P709|SCH-P729|SM-T2558|GT-I9205|SM-G9350|SM-J120F|SM-G920F|SM-G920V|SM-G930F|SM-N910C',
  5462. 'LG' => '\bLG\b;|LG[- ]?(C800|C900|E400|E610|E900|E-900|F160|F180K|F180L|F180S|730|855|L160|LS740|LS840|LS970|LU6200|MS690|MS695|MS770|MS840|MS870|MS910|P500|P700|P705|VM696|AS680|AS695|AX840|C729|E970|GS505|272|C395|E739BK|E960|L55C|L75C|LS696|LS860|P769BK|P350|P500|P509|P870|UN272|US730|VS840|VS950|LN272|LN510|LS670|LS855|LW690|MN270|MN510|P509|P769|P930|UN200|UN270|UN510|UN610|US670|US740|US760|UX265|UX840|VN271|VN530|VS660|VS700|VS740|VS750|VS910|VS920|VS930|VX9200|VX11000|AX840A|LW770|P506|P925|P999|E612|D955|D802|MS323)',
  5463. 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|LT26w|SonyEricssonMT27i|C5303|C6902|C6903|C6906|C6943|D2533',
  5464. 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile',
  5465. 'NokiaLumia' => 'Lumia [0-9]{3,4}',
  5466. // http://www.micromaxinfo.com/mobiles/smartphones
  5467. // Added because the codes might conflict with Acer Tablets.
  5468. 'Micromax' => 'Micromax.*\b(A210|A92|A88|A72|A111|A110Q|A115|A116|A110|A90S|A26|A51|A35|A54|A25|A27|A89|A68|A65|A57|A90)\b',
  5469. // @todo Complete the regex.
  5470. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ;
  5471. 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
  5472. // http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
  5473. // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android.
  5474. 'Pantech' => 'PANTECH|IM-A850S|IM-A840S|IM-A830L|IM-A830K|IM-A830S|IM-A820L|IM-A810K|IM-A810S|IM-A800S|IM-T100K|IM-A725L|IM-A780L|IM-A775C|IM-A770K|IM-A760S|IM-A750K|IM-A740S|IM-A730S|IM-A720L|IM-A710K|IM-A690L|IM-A690S|IM-A650S|IM-A630K|IM-A600S|VEGA PTL21|PT003|P8010|ADR910L|P6030|P6020|P9070|P4100|P9060|P5000|CDM8992|TXT8045|ADR8995|IS11PT|P2030|P6010|P8000|PT002|IS06|CDM8999|P9050|PT001|TXT8040|P2020|P9020|P2000|P7040|P7000|C790',
  5475. // http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones.
  5476. 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250',
  5477. // http://fr.wikomobile.com
  5478. 'Wiko' => 'KITE 4G|HIGHWAY|GETAWAY|STAIRWAY|DARKSIDE|DARKFULL|DARKNIGHT|DARKMOON|SLIDE|WAX 4G|RAINBOW|BLOOM|SUNSET|GOA(?!nna)|LENNY|BARRY|IGGY|OZZY|CINK FIVE|CINK PEAX|CINK PEAX 2|CINK SLIM|CINK SLIM 2|CINK +|CINK KING|CINK PEAX|CINK SLIM|SUBLIM',
  5479. 'iMobile' => 'i-mobile (IQ|i-STYLE|idea|ZAA|Hitz)',
  5480. // Added simvalley mobile just for fun. They have some interesting devices.
  5481. // http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html
  5482. 'SimValley' => '\b(SP-80|XT-930|SX-340|XT-930|SX-310|SP-360|SP60|SPT-800|SP-120|SPT-800|SP-140|SPX-5|SPX-8|SP-100|SPX-8|SPX-12)\b',
  5483. // Wolfgang - a brand that is sold by Aldi supermarkets.
  5484. // http://www.wolfgangmobile.com/
  5485. 'Wolfgang' => 'AT-B24D|AT-AS50HD|AT-AS40W|AT-AS55HD|AT-AS45q2|AT-B26D|AT-AS50Q',
  5486. 'Alcatel' => 'Alcatel',
  5487. 'Nintendo' => 'Nintendo 3DS',
  5488. // http://en.wikipedia.org/wiki/Amoi
  5489. 'Amoi' => 'Amoi',
  5490. // http://en.wikipedia.org/wiki/INQ
  5491. 'INQ' => 'INQ',
  5492. // @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039
  5493. 'GenericPhone' => 'Tapatalk|PDA;|SAGEM|\bmmp\b|pocket|\bpsp\b|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|\bwap\b|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser',
  5494. );
  5495. /**
  5496. * List of tablet devices.
  5497. *
  5498. * @var array
  5499. */
  5500. protected static $tabletDevices = array(
  5501. // @todo: check for mobile friendly emails topic.
  5502. 'iPad' => 'iPad|iPad.*Mobile',
  5503. // Removed |^.*Android.*Nexus(?!(?:Mobile).)*$
  5504. // @see #442
  5505. 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)',
  5506. 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P1000|GT-P1003|GT-P1010|GT-P3105|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3108|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P7501|GT-N5100|GT-N5105|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-P5200|GT-P5210|GT-P5210X|SM-T311|SM-T310|SM-T310X|SM-T210|SM-T210R|SM-T211|SM-P600|SM-P601|SM-P605|SM-P900|SM-P901|SM-T217|SM-T217A|SM-T217S|SM-P6000|SM-T3100|SGH-I467|XE500|SM-T110|GT-P5220|GT-I9200X|GT-N5110X|GT-N5120|SM-P905|SM-T111|SM-T2105|SM-T315|SM-T320|SM-T320X|SM-T321|SM-T520|SM-T525|SM-T530NU|SM-T230NU|SM-T330NU|SM-T900|XE500T1C|SM-P605V|SM-P905V|SM-T337V|SM-T537V|SM-T707V|SM-T807V|SM-P600X|SM-P900X|SM-T210X|SM-T230|SM-T230X|SM-T325|GT-P7503|SM-T531|SM-T330|SM-T530|SM-T705|SM-T705C|SM-T535|SM-T331|SM-T800|SM-T700|SM-T537|SM-T807|SM-P907A|SM-T337A|SM-T537A|SM-T707A|SM-T807A|SM-T237|SM-T807P|SM-P607T|SM-T217T|SM-T337T|SM-T807T|SM-T116NQ|SM-T116BU|SM-P550|SM-T350|SM-T550|SM-T9000|SM-P9000|SM-T705Y|SM-T805|GT-P3113|SM-T710|SM-T810|SM-T815|SM-T360|SM-T533|SM-T113|SM-T335|SM-T715|SM-T560|SM-T670|SM-T677|SM-T377|SM-T567|SM-T357T|SM-T555|SM-T561|SM-T713|SM-T719|SM-T813|SM-T819|SM-T580|SM-T355Y|SM-T280|SM-T817A|SM-T820|SM-W700|SM-P580|SM-T587|SM-P350|SM-P555M|SM-P355M|SM-T113NU|SM-T815Y', // SCH-P709|SCH-P729|SM-T2558|GT-I9205 - Samsung Mega - treat them like a regular phone.
  5507. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
  5508. 'Kindle' => 'Kindle|Silk.*Accelerated|Android.*\b(KFOT|KFTT|KFJWI|KFJWA|KFOTE|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|WFJWAE|KFSAWA|KFSAWI|KFASWI|KFARWI|KFFOWI|KFGIWI|KFMEWI)\b|Android.*Silk/[0-9.]+ like Chrome/[0-9.]+ (?!Mobile)',
  5509. // Only the Surface tablets with Windows RT are considered mobile.
  5510. // http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx
  5511. 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;.*(Tablet|ARMBJS)',
  5512. // http://shopping1.hp.com/is-bin/INTERSHOP.enfinity/WFS/WW-USSMBPublicStore-Site/en_US/-/USD/ViewStandardCatalog-Browse?CatalogCategoryID=JfIQ7EN5lqMAAAEyDcJUDwMT
  5513. 'HPTablet' => 'HP Slate (7|8|10)|HP ElitePad 900|hp-tablet|EliteBook.*Touch|HP 8|Slate 21|HP SlateBook 10',
  5514. // Watch out for PadFone, see #132.
  5515. // http://www.asus.com/de/Tablets_Mobile/Memo_Pad_Products/
  5516. 'AsusTablet' => '^.*PadFone((?!Mobile).)*$|Transformer|TF101|TF101G|TF300T|TF300TG|TF300TL|TF700T|TF700KL|TF701T|TF810C|ME171|ME301T|ME302C|ME371MG|ME370T|ME372MG|ME172V|ME173X|ME400C|Slider SL101|\bK00F\b|\bK00C\b|\bK00E\b|\bK00L\b|TX201LA|ME176C|ME102A|\bM80TA\b|ME372CL|ME560CG|ME372CG|ME302KL| K010 | K011 | K017 | K01E |ME572C|ME103K|ME170C|ME171C|\bME70C\b|ME581C|ME581CL|ME8510C|ME181C|P01Y|PO1MA|P01Z|\bP027\b',
  5517. 'BlackBerryTablet' => 'PlayBook|RIM Tablet',
  5518. 'HTCtablet' => 'HTC_Flyer_P512|HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200|PG09410',
  5519. 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617',
  5520. 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2',
  5521. // http://www.acer.ro/ac/ro/RO/content/drivers
  5522. // http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer)
  5523. // http://us.acer.com/ac/en/US/content/group/tablets
  5524. // http://www.acer.de/ac/de/DE/content/models/tablets/
  5525. // Can conflict with Micromax and Motorola phones codes.
  5526. 'AcerTablet' => 'Android.*; \b(A100|A101|A110|A200|A210|A211|A500|A501|A510|A511|A700|A701|W500|W500P|W501|W501P|W510|W511|W700|G100|G100W|B1-A71|B1-710|B1-711|A1-810|A1-811|A1-830)\b|W3-810|\bA3-A10\b|\bA3-A11\b|\bA3-A20\b|\bA3-A30',
  5527. // http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/
  5528. // http://us.toshiba.com/tablets/tablet-finder
  5529. // http://www.toshiba.co.jp/regza/tablet/
  5530. 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO',
  5531. // http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html
  5532. // http://www.lg.com/us/tablets
  5533. 'LGTablet' => '\bL-06C|LG-V909|LG-V900|LG-V700|LG-V510|LG-V500|LG-V410|LG-V400|LG-VK810\b',
  5534. 'FujitsuTablet' => 'Android.*\b(F-01D|F-02F|F-05E|F-10D|M532|Q572)\b',
  5535. // Prestigio Tablets http://www.prestigio.com/support
  5536. 'PrestigioTablet' => 'PMP3170B|PMP3270B|PMP3470B|PMP7170B|PMP3370B|PMP3570C|PMP5870C|PMP3670B|PMP5570C|PMP5770D|PMP3970B|PMP3870C|PMP5580C|PMP5880D|PMP5780D|PMP5588C|PMP7280C|PMP7280C3G|PMP7280|PMP7880D|PMP5597D|PMP5597|PMP7100D|PER3464|PER3274|PER3574|PER3884|PER5274|PER5474|PMP5097CPRO|PMP5097|PMP7380D|PMP5297C|PMP5297C_QUAD|PMP812E|PMP812E3G|PMP812F|PMP810E|PMP880TD|PMT3017|PMT3037|PMT3047|PMT3057|PMT7008|PMT5887|PMT5001|PMT5002',
  5537. // http://support.lenovo.com/en_GB/downloads/default.page?#
  5538. 'LenovoTablet' => 'Lenovo TAB|Idea(Tab|Pad)( A1|A10| K1|)|ThinkPad([ ]+)?Tablet|YT3-850M|YT3-X90L|YT3-X90F|YT3-X90X|Lenovo.*(S2109|S2110|S5000|S6000|K3011|A3000|A3500|A1000|A2107|A2109|A1107|A5500|A7600|B6000|B8000|B8080)(-|)(FL|F|HV|H|)',
  5539. // http://www.dell.com/support/home/us/en/04/Products/tab_mob/tablets
  5540. 'DellTablet' => 'Venue 11|Venue 8|Venue 7|Dell Streak 10|Dell Streak 7',
  5541. // http://www.yarvik.com/en/matrix/tablets/
  5542. 'YarvikTablet' => 'Android.*\b(TAB210|TAB211|TAB224|TAB250|TAB260|TAB264|TAB310|TAB360|TAB364|TAB410|TAB411|TAB420|TAB424|TAB450|TAB460|TAB461|TAB464|TAB465|TAB467|TAB468|TAB07-100|TAB07-101|TAB07-150|TAB07-151|TAB07-152|TAB07-200|TAB07-201-3G|TAB07-210|TAB07-211|TAB07-212|TAB07-214|TAB07-220|TAB07-400|TAB07-485|TAB08-150|TAB08-200|TAB08-201-3G|TAB08-201-30|TAB09-100|TAB09-211|TAB09-410|TAB10-150|TAB10-201|TAB10-211|TAB10-400|TAB10-410|TAB13-201|TAB274EUK|TAB275EUK|TAB374EUK|TAB462EUK|TAB474EUK|TAB9-200)\b',
  5543. 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB',
  5544. 'ArnovaTablet' => '97G4|AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT|AN9G2',
  5545. // http://www.intenso.de/kategorie_en.php?kategorie=33
  5546. // @todo: http://www.nbhkdz.com/read/b8e64202f92a2df129126bff.html - investigate
  5547. 'IntensoTablet' => 'INM8002KP|INM1010FP|INM805ND|Intenso Tab|TAB1004',
  5548. // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/
  5549. 'IRUTablet' => 'M702pro',
  5550. 'MegafonTablet' => 'MegaFon V9|\bZTE V9\b|Android.*\bMT7A\b',
  5551. // http://www.e-boda.ro/tablete-pc.html
  5552. 'EbodaTablet' => 'E-Boda (Supreme|Impresspeed|Izzycomm|Essential)',
  5553. // http://www.allview.ro/produse/droseries/lista-tablete-pc/
  5554. 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)',
  5555. // http://wiki.archosfans.com/index.php?title=Main_Page
  5556. // @note Rewrite the regex format after we add more UAs.
  5557. 'ArchosTablet' => '\b(101G9|80G9|A101IT)\b|Qilive 97R|Archos5|\bARCHOS (70|79|80|90|97|101|FAMILYPAD|)(b|c|)(G10| Cobalt| TITANIUM(HD|)| Xenon| Neon|XSK| 2| XS 2| PLATINUM| CARBON|GAMEPAD)\b',
  5558. // http://www.ainol.com/plugin.php?identifier=ainol&module=product
  5559. 'AinolTablet' => 'NOVO7|NOVO8|NOVO10|Novo7Aurora|Novo7Basic|NOVO7PALADIN|novo9-Spark',
  5560. 'NokiaLumiaTablet' => 'Lumia 2520',
  5561. // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER
  5562. // Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser
  5563. // http://www.sony.jp/support/tablet/
  5564. 'SonyTablet' => 'Sony.*Tablet|Xperia Tablet|Sony Tablet S|SO-03E|SGPT12|SGPT13|SGPT114|SGPT121|SGPT122|SGPT123|SGPT111|SGPT112|SGPT113|SGPT131|SGPT132|SGPT133|SGPT211|SGPT212|SGPT213|SGP311|SGP312|SGP321|EBRD1101|EBRD1102|EBRD1201|SGP351|SGP341|SGP511|SGP512|SGP521|SGP541|SGP551|SGP621|SGP612|SOT31',
  5565. // http://www.support.philips.com/support/catalog/worldproducts.jsp?userLanguage=en&userCountry=cn&categoryid=3G_LTE_TABLET_SU_CN_CARE&title=3G%20tablets%20/%20LTE%20range&_dyncharset=UTF-8
  5566. 'PhilipsTablet' => '\b(PI2010|PI3000|PI3100|PI3105|PI3110|PI3205|PI3210|PI3900|PI4010|PI7000|PI7100)\b',
  5567. // db + http://www.cube-tablet.com/buy-products.html
  5568. 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT',
  5569. // http://www.cobyusa.com/?p=pcat&pcat_id=3001
  5570. 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010',
  5571. // http://www.match.net.cn/products.asp
  5572. 'MIDTablet' => 'M9701|M9000|M9100|M806|M1052|M806|T703|MID701|MID713|MID710|MID727|MID760|MID830|MID728|MID933|MID125|MID810|MID732|MID120|MID930|MID800|MID731|MID900|MID100|MID820|MID735|MID980|MID130|MID833|MID737|MID960|MID135|MID860|MID736|MID140|MID930|MID835|MID733|MID4X10',
  5573. // http://www.msi.com/support
  5574. // @todo Research the Windows Tablets.
  5575. 'MSITablet' => 'MSI \b(Primo 73K|Primo 73L|Primo 81L|Primo 77|Primo 93|Primo 75|Primo 76|Primo 73|Primo 81|Primo 91|Primo 90|Enjoy 71|Enjoy 7|Enjoy 10)\b',
  5576. // @todo http://www.kyoceramobile.com/support/drivers/
  5577. // 'KyoceraTablet' => null,
  5578. // @todo http://intexuae.com/index.php/category/mobile-devices/tablets-products/
  5579. // 'IntextTablet' => null,
  5580. // http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets)
  5581. // http://www.imp3.net/14/show.php?itemid=20454
  5582. 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)',
  5583. // http://www.rock-chips.com/index.php?do=prod&pid=2
  5584. 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A',
  5585. // http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/
  5586. 'FlyTablet' => 'IQ310|Fly Vision',
  5587. // http://www.bqreaders.com/gb/tablets-prices-sale.html
  5588. 'bqTablet' => 'Android.*(bq)?.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris [E|M]10)|Maxwell.*Lite|Maxwell.*Plus',
  5589. // http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
  5590. // http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
  5591. 'HuaweiTablet' => 'MediaPad|MediaPad 7 Youth|IDEOS S7|S7-201c|S7-202u|S7-101|S7-103|S7-104|S7-105|S7-106|S7-201|S7-Slim',
  5592. // Nec or Medias Tab
  5593. 'NecTablet' => '\bN-06D|\bN-08D',
  5594. // Pantech Tablets: http://www.pantechusa.com/phones/
  5595. 'PantechTablet' => 'Pantech.*P4100',
  5596. // Broncho Tablets: http://www.broncho.cn/ (hard to find)
  5597. 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)',
  5598. // http://versusuk.com/support.html
  5599. 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b',
  5600. // http://www.zync.in/index.php/our-products/tablet-phablets
  5601. 'ZyncTablet' => 'z1000|Z99 2G|z99|z930|z999|z990|z909|Z919|z900',
  5602. // http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/
  5603. 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA',
  5604. // https://www.nabitablet.com/
  5605. 'NabiTablet' => 'Android.*\bNabi',
  5606. 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build',
  5607. // French Danew Tablets http://www.danew.com/produits-tablette.php
  5608. 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b',
  5609. // Texet Tablets and Readers http://www.texet.ru/tablet/
  5610. 'TexetTablet' => 'NaviPad|TB-772A|TM-7045|TM-7055|TM-9750|TM-7016|TM-7024|TM-7026|TM-7041|TM-7043|TM-7047|TM-8041|TM-9741|TM-9747|TM-9748|TM-9751|TM-7022|TM-7021|TM-7020|TM-7011|TM-7010|TM-7023|TM-7025|TM-7037W|TM-7038W|TM-7027W|TM-9720|TM-9725|TM-9737W|TM-1020|TM-9738W|TM-9740|TM-9743W|TB-807A|TB-771A|TB-727A|TB-725A|TB-719A|TB-823A|TB-805A|TB-723A|TB-715A|TB-707A|TB-705A|TB-709A|TB-711A|TB-890HD|TB-880HD|TB-790HD|TB-780HD|TB-770HD|TB-721HD|TB-710HD|TB-434HD|TB-860HD|TB-840HD|TB-760HD|TB-750HD|TB-740HD|TB-730HD|TB-722HD|TB-720HD|TB-700HD|TB-500HD|TB-470HD|TB-431HD|TB-430HD|TB-506|TB-504|TB-446|TB-436|TB-416|TB-146SE|TB-126SE',
  5611. // Avoid detecting 'PLAYSTATION 3' as mobile.
  5612. 'PlaystationTablet' => 'Playstation.*(Portable|Vita)',
  5613. // http://www.trekstor.de/surftabs.html
  5614. 'TrekstorTablet' => 'ST10416-1|VT10416-1|ST70408-1|ST702xx-1|ST702xx-2|ST80208|ST97216|ST70104-2|VT10416-2|ST10216-2A|SurfTab',
  5615. // http://www.pyleaudio.com/Products.aspx?%2fproducts%2fPersonal-Electronics%2fTablets
  5616. 'PyleAudioTablet' => '\b(PTBL10CEU|PTBL10C|PTBL72BC|PTBL72BCEU|PTBL7CEU|PTBL7C|PTBL92BC|PTBL92BCEU|PTBL9CEU|PTBL9CUK|PTBL9C)\b',
  5617. // http://www.advandigital.com/index.php?link=content-product&jns=JP001
  5618. // because of the short codenames we have to include whitespaces to reduce the possible conflicts.
  5619. 'AdvanTablet' => 'Android.* \b(E3A|T3X|T5C|T5B|T3E|T3C|T3B|T1J|T1F|T2A|T1H|T1i|E1C|T1-E|T5-A|T4|E1-B|T2Ci|T1-B|T1-D|O1-A|E1-A|T1-A|T3A|T4i)\b ',
  5620. // http://www.danytech.com/category/tablet-pc
  5621. 'DanyTechTablet' => 'Genius Tab G3|Genius Tab S2|Genius Tab Q3|Genius Tab G4|Genius Tab Q4|Genius Tab G-II|Genius TAB GII|Genius TAB GIII|Genius Tab S1',
  5622. // http://www.galapad.net/product.html
  5623. 'GalapadTablet' => 'Android.*\bG1\b',
  5624. // http://www.micromaxinfo.com/tablet/funbook
  5625. 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b',
  5626. // http://www.karbonnmobiles.com/products_tablet.php
  5627. 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b',
  5628. // http://www.myallfine.com/Products.asp
  5629. 'AllFineTablet' => 'Fine7 Genius|Fine7 Shine|Fine7 Air|Fine8 Style|Fine9 More|Fine10 Joy|Fine11 Wide',
  5630. // http://www.proscanvideo.com/products-search.asp?itemClass=TABLET&itemnmbr=
  5631. 'PROSCANTablet' => '\b(PEM63|PLT1023G|PLT1041|PLT1044|PLT1044G|PLT1091|PLT4311|PLT4311PL|PLT4315|PLT7030|PLT7033|PLT7033D|PLT7035|PLT7035D|PLT7044K|PLT7045K|PLT7045KB|PLT7071KG|PLT7072|PLT7223G|PLT7225G|PLT7777G|PLT7810K|PLT7849G|PLT7851G|PLT7852G|PLT8015|PLT8031|PLT8034|PLT8036|PLT8080K|PLT8082|PLT8088|PLT8223G|PLT8234G|PLT8235G|PLT8816K|PLT9011|PLT9045K|PLT9233G|PLT9735|PLT9760G|PLT9770G)\b',
  5632. // http://www.yonesnav.com/products/products.php
  5633. 'YONESTablet' => 'BQ1078|BC1003|BC1077|RK9702|BC9730|BC9001|IT9001|BC7008|BC7010|BC708|BC728|BC7012|BC7030|BC7027|BC7026',
  5634. // http://www.cjshowroom.com/eproducts.aspx?classcode=004001001
  5635. // China manufacturer makes tablets for different small brands (eg. http://www.zeepad.net/index.html)
  5636. 'ChangJiaTablet' => 'TPC7102|TPC7103|TPC7105|TPC7106|TPC7107|TPC7201|TPC7203|TPC7205|TPC7210|TPC7708|TPC7709|TPC7712|TPC7110|TPC8101|TPC8103|TPC8105|TPC8106|TPC8203|TPC8205|TPC8503|TPC9106|TPC9701|TPC97101|TPC97103|TPC97105|TPC97106|TPC97111|TPC97113|TPC97203|TPC97603|TPC97809|TPC97205|TPC10101|TPC10103|TPC10106|TPC10111|TPC10203|TPC10205|TPC10503',
  5637. // http://www.gloryunion.cn/products.asp
  5638. // http://www.allwinnertech.com/en/apply/mobile.html
  5639. // http://www.ptcl.com.pk/pd_content.php?pd_id=284 (EVOTAB)
  5640. // @todo: Softwiner tablets?
  5641. // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions.
  5642. 'GUTablet' => 'TX-A1301|TX-M9002|Q702|kf026', // A12R|D75A|D77|D79|R83|A95|A106C|R15|A75|A76|D71|D72|R71|R73|R77|D82|R85|D92|A97|D92|R91|A10F|A77F|W71F|A78F|W78F|W81F|A97F|W91F|W97F|R16G|C72|C73E|K72|K73|R96G
  5643. // http://www.pointofview-online.com/showroom.php?shop_mode=product_listing&category_id=118
  5644. 'PointOfViewTablet' => 'TAB-P506|TAB-navi-7-3G-M|TAB-P517|TAB-P-527|TAB-P701|TAB-P703|TAB-P721|TAB-P731N|TAB-P741|TAB-P825|TAB-P905|TAB-P925|TAB-PR945|TAB-PL1015|TAB-P1025|TAB-PI1045|TAB-P1325|TAB-PROTAB[0-9]+|TAB-PROTAB25|TAB-PROTAB26|TAB-PROTAB27|TAB-PROTAB26XL|TAB-PROTAB2-IPS9|TAB-PROTAB30-IPS9|TAB-PROTAB25XXL|TAB-PROTAB26-IPS10|TAB-PROTAB30-IPS10',
  5645. // http://www.overmax.pl/pl/katalog-produktow,p8/tablety,c14/
  5646. // @todo: add more tests.
  5647. 'OvermaxTablet' => 'OV-(SteelCore|NewBase|Basecore|Baseone|Exellen|Quattor|EduTab|Solution|ACTION|BasicTab|TeddyTab|MagicTab|Stream|TB-08|TB-09)',
  5648. // http://hclmetablet.com/India/index.php
  5649. 'HCLTablet' => 'HCL.*Tablet|Connect-3G-2.0|Connect-2G-2.0|ME Tablet U1|ME Tablet U2|ME Tablet G1|ME Tablet X1|ME Tablet Y2|ME Tablet Sync',
  5650. // http://www.edigital.hu/Tablet_es_e-book_olvaso/Tablet-c18385.html
  5651. 'DPSTablet' => 'DPS Dream 9|DPS Dual 7',
  5652. // http://www.visture.com/index.asp
  5653. 'VistureTablet' => 'V97 HD|i75 3G|Visture V4( HD)?|Visture V5( HD)?|Visture V10',
  5654. // http://www.mijncresta.nl/tablet
  5655. 'CrestaTablet' => 'CTP(-)?810|CTP(-)?818|CTP(-)?828|CTP(-)?838|CTP(-)?888|CTP(-)?978|CTP(-)?980|CTP(-)?987|CTP(-)?988|CTP(-)?989',
  5656. // MediaTek - http://www.mediatek.com/_en/01_products/02_proSys.php?cata_sn=1&cata1_sn=1&cata2_sn=309
  5657. 'MediatekTablet' => '\bMT8125|MT8389|MT8135|MT8377\b',
  5658. // Concorde tab
  5659. 'ConcordeTablet' => 'Concorde([ ]+)?Tab|ConCorde ReadMan',
  5660. // GoClever Tablets - http://www.goclever.com/uk/products,c1/tablet,c5/
  5661. 'GoCleverTablet' => 'GOCLEVER TAB|A7GOCLEVER|M1042|M7841|M742|R1042BK|R1041|TAB A975|TAB A7842|TAB A741|TAB A741L|TAB M723G|TAB M721|TAB A1021|TAB I921|TAB R721|TAB I720|TAB T76|TAB R70|TAB R76.2|TAB R106|TAB R83.2|TAB M813G|TAB I721|GCTA722|TAB I70|TAB I71|TAB S73|TAB R73|TAB R74|TAB R93|TAB R75|TAB R76.1|TAB A73|TAB A93|TAB A93.2|TAB T72|TAB R83|TAB R974|TAB R973|TAB A101|TAB A103|TAB A104|TAB A104.2|R105BK|M713G|A972BK|TAB A971|TAB R974.2|TAB R104|TAB R83.3|TAB A1042',
  5662. // Modecom Tablets - http://www.modecom.eu/tablets/portal/
  5663. 'ModecomTablet' => 'FreeTAB 9000|FreeTAB 7.4|FreeTAB 7004|FreeTAB 7800|FreeTAB 2096|FreeTAB 7.5|FreeTAB 1014|FreeTAB 1001 |FreeTAB 8001|FreeTAB 9706|FreeTAB 9702|FreeTAB 7003|FreeTAB 7002|FreeTAB 1002|FreeTAB 7801|FreeTAB 1331|FreeTAB 1004|FreeTAB 8002|FreeTAB 8014|FreeTAB 9704|FreeTAB 1003',
  5664. // Vonino Tablets - http://www.vonino.eu/tablets
  5665. 'VoninoTablet' => '\b(Argus[ _]?S|Diamond[ _]?79HD|Emerald[ _]?78E|Luna[ _]?70C|Onyx[ _]?S|Onyx[ _]?Z|Orin[ _]?HD|Orin[ _]?S|Otis[ _]?S|SpeedStar[ _]?S|Magnet[ _]?M9|Primus[ _]?94[ _]?3G|Primus[ _]?94HD|Primus[ _]?QS|Android.*\bQ8\b|Sirius[ _]?EVO[ _]?QS|Sirius[ _]?QS|Spirit[ _]?S)\b',
  5666. // ECS Tablets - http://www.ecs.com.tw/ECSWebSite/Product/Product_Tablet_List.aspx?CategoryID=14&MenuID=107&childid=M_107&LanID=0
  5667. 'ECSTablet' => 'V07OT2|TM105A|S10OT1|TR10CS1',
  5668. // Storex Tablets - http://storex.fr/espace_client/support.html
  5669. // @note: no need to add all the tablet codes since they are guided by the first regex.
  5670. 'StorexTablet' => 'eZee[_\']?(Tab|Go)[0-9]+|TabLC7|Looney Tunes Tab',
  5671. // Generic Vodafone tablets.
  5672. 'VodafoneTablet' => 'SmartTab([ ]+)?[0-9]+|SmartTabII10|SmartTabII7|VF-1497',
  5673. // French tablets - Essentiel B http://www.boulanger.fr/tablette_tactile_e-book/tablette_tactile_essentiel_b/cl_68908.htm?multiChoiceToDelete=brand&mc_brand=essentielb
  5674. // Aka: http://www.essentielb.fr/
  5675. 'EssentielBTablet' => 'Smart[ \']?TAB[ ]+?[0-9]+|Family[ \']?TAB2',
  5676. // Ross & Moor - http://ross-moor.ru/
  5677. 'RossMoorTablet' => 'RM-790|RM-997|RMD-878G|RMD-974R|RMT-705A|RMT-701|RME-601|RMT-501|RMT-711',
  5678. // i-mobile http://product.i-mobilephone.com/Mobile_Device
  5679. 'iMobileTablet' => 'i-mobile i-note',
  5680. // http://www.tolino.de/de/vergleichen/
  5681. 'TolinoTablet' => 'tolino tab [0-9.]+|tolino shine',
  5682. // AudioSonic - a Kmart brand
  5683. // http://www.kmart.com.au/webapp/wcs/stores/servlet/Search?langId=-1&storeId=10701&catalogId=10001&categoryId=193001&pageSize=72&currentPage=1&searchCategory=193001%2b4294965664&sortBy=p_MaxPrice%7c1
  5684. 'AudioSonicTablet' => '\bC-22Q|T7-QC|T-17B|T-17P\b',
  5685. // AMPE Tablets - http://www.ampe.com.my/product-category/tablets/
  5686. // @todo: add them gradually to avoid conflicts.
  5687. 'AMPETablet' => 'Android.* A78 ',
  5688. // Skk Mobile - http://skkmobile.com.ph/product_tablets.php
  5689. 'SkkTablet' => 'Android.* (SKYPAD|PHOENIX|CYCLOPS)',
  5690. // Tecno Mobile (only tablet) - http://www.tecno-mobile.com/index.php/product?filterby=smart&list_order=all&page=1
  5691. 'TecnoTablet' => 'TECNO P9',
  5692. // JXD (consoles & tablets) - http://jxd.hk/products.asp?selectclassid=009008&clsid=3
  5693. 'JXDTablet' => 'Android.* \b(F3000|A3300|JXD5000|JXD3000|JXD2000|JXD300B|JXD300|S5800|S7800|S602b|S5110b|S7300|S5300|S602|S603|S5100|S5110|S601|S7100a|P3000F|P3000s|P101|P200s|P1000m|P200m|P9100|P1000s|S6600b|S908|P1000|P300|S18|S6600|S9100)\b',
  5694. // i-Joy tablets - http://www.i-joy.es/en/cat/products/tablets/
  5695. 'iJoyTablet' => 'Tablet (Spirit 7|Essentia|Galatea|Fusion|Onix 7|Landa|Titan|Scooby|Deox|Stella|Themis|Argon|Unique 7|Sygnus|Hexen|Finity 7|Cream|Cream X2|Jade|Neon 7|Neron 7|Kandy|Scape|Saphyr 7|Rebel|Biox|Rebel|Rebel 8GB|Myst|Draco 7|Myst|Tab7-004|Myst|Tadeo Jones|Tablet Boing|Arrow|Draco Dual Cam|Aurix|Mint|Amity|Revolution|Finity 9|Neon 9|T9w|Amity 4GB Dual Cam|Stone 4GB|Stone 8GB|Andromeda|Silken|X2|Andromeda II|Halley|Flame|Saphyr 9,7|Touch 8|Planet|Triton|Unique 10|Hexen 10|Memphis 4GB|Memphis 8GB|Onix 10)',
  5696. // http://www.intracon.eu/tablet
  5697. 'FX2Tablet' => 'FX2 PAD7|FX2 PAD10',
  5698. // http://www.xoro.de/produkte/
  5699. // @note: Might be the same brand with 'Simply tablets'
  5700. 'XoroTablet' => 'KidsPAD 701|PAD[ ]?712|PAD[ ]?714|PAD[ ]?716|PAD[ ]?717|PAD[ ]?718|PAD[ ]?720|PAD[ ]?721|PAD[ ]?722|PAD[ ]?790|PAD[ ]?792|PAD[ ]?900|PAD[ ]?9715D|PAD[ ]?9716DR|PAD[ ]?9718DR|PAD[ ]?9719QR|PAD[ ]?9720QR|TelePAD1030|Telepad1032|TelePAD730|TelePAD731|TelePAD732|TelePAD735Q|TelePAD830|TelePAD9730|TelePAD795|MegaPAD 1331|MegaPAD 1851|MegaPAD 2151',
  5701. // http://www1.viewsonic.com/products/computing/tablets/
  5702. 'ViewsonicTablet' => 'ViewPad 10pi|ViewPad 10e|ViewPad 10s|ViewPad E72|ViewPad7|ViewPad E100|ViewPad 7e|ViewSonic VB733|VB100a',
  5703. // http://www.odys.de/web/internet-tablet_en.html
  5704. 'OdysTablet' => 'LOOX|XENO10|ODYS[ -](Space|EVO|Xpress|NOON)|\bXELIO\b|Xelio10Pro|XELIO7PHONETAB|XELIO10EXTREME|XELIOPT2|NEO_QUAD10',
  5705. // http://www.captiva-power.de/products.html#tablets-en
  5706. 'CaptivaTablet' => 'CAPTIVA PAD',
  5707. // IconBIT - http://www.iconbit.com/products/tablets/
  5708. 'IconbitTablet' => 'NetTAB|NT-3702|NT-3702S|NT-3702S|NT-3603P|NT-3603P|NT-0704S|NT-0704S|NT-3805C|NT-3805C|NT-0806C|NT-0806C|NT-0909T|NT-0909T|NT-0907S|NT-0907S|NT-0902S|NT-0902S',
  5709. // http://www.teclast.com/topic.php?channelID=70&topicID=140&pid=63
  5710. 'TeclastTablet' => 'T98 4G|\bP80\b|\bX90HD\b|X98 Air|X98 Air 3G|\bX89\b|P80 3G|\bX80h\b|P98 Air|\bX89HD\b|P98 3G|\bP90HD\b|P89 3G|X98 3G|\bP70h\b|P79HD 3G|G18d 3G|\bP79HD\b|\bP89s\b|\bA88\b|\bP10HD\b|\bP19HD\b|G18 3G|\bP78HD\b|\bA78\b|\bP75\b|G17s 3G|G17h 3G|\bP85t\b|\bP90\b|\bP11\b|\bP98t\b|\bP98HD\b|\bG18d\b|\bP85s\b|\bP11HD\b|\bP88s\b|\bA80HD\b|\bA80se\b|\bA10h\b|\bP89\b|\bP78s\b|\bG18\b|\bP85\b|\bA70h\b|\bA70\b|\bG17\b|\bP18\b|\bA80s\b|\bA11s\b|\bP88HD\b|\bA80h\b|\bP76s\b|\bP76h\b|\bP98\b|\bA10HD\b|\bP78\b|\bP88\b|\bA11\b|\bA10t\b|\bP76a\b|\bP76t\b|\bP76e\b|\bP85HD\b|\bP85a\b|\bP86\b|\bP75HD\b|\bP76v\b|\bA12\b|\bP75a\b|\bA15\b|\bP76Ti\b|\bP81HD\b|\bA10\b|\bT760VE\b|\bT720HD\b|\bP76\b|\bP73\b|\bP71\b|\bP72\b|\bT720SE\b|\bC520Ti\b|\bT760\b|\bT720VE\b|T720-3GE|T720-WiFi',
  5711. // Onda - http://www.onda-tablet.com/buy-android-onda.html?dir=desc&limit=all&order=price
  5712. 'OndaTablet' => '\b(V975i|Vi30|VX530|V701|Vi60|V701s|Vi50|V801s|V719|Vx610w|VX610W|V819i|Vi10|VX580W|Vi10|V711s|V813|V811|V820w|V820|Vi20|V711|VI30W|V712|V891w|V972|V819w|V820w|Vi60|V820w|V711|V813s|V801|V819|V975s|V801|V819|V819|V818|V811|V712|V975m|V101w|V961w|V812|V818|V971|V971s|V919|V989|V116w|V102w|V973|Vi40)\b[\s]+',
  5713. 'JaytechTablet' => 'TPC-PA762',
  5714. 'BlaupunktTablet' => 'Endeavour 800NG|Endeavour 1010',
  5715. // http://www.digma.ru/support/download/
  5716. // @todo: Ebooks also (if requested)
  5717. 'DigmaTablet' => '\b(iDx10|iDx9|iDx8|iDx7|iDxD7|iDxD8|iDsQ8|iDsQ7|iDsQ8|iDsD10|iDnD7|3TS804H|iDsQ11|iDj7|iDs10)\b',
  5718. // http://www.evolioshop.com/ro/tablete-pc.html
  5719. // http://www.evolio.ro/support/downloads_static.html?cat=2
  5720. // @todo: Research some more
  5721. 'EvolioTablet' => 'ARIA_Mini_wifi|Aria[ _]Mini|Evolio X10|Evolio X7|Evolio X8|\bEvotab\b|\bNeura\b',
  5722. // @todo http://www.lavamobiles.com/tablets-data-cards
  5723. 'LavaTablet' => 'QPAD E704|\bIvoryS\b|E-TAB IVORY|\bE-TAB\b',
  5724. // http://www.breezetablet.com/
  5725. 'AocTablet' => 'MW0811|MW0812|MW0922|MTK8382|MW1031|MW0831|MW0821|MW0931|MW0712',
  5726. // http://www.mpmaneurope.com/en/products/internet-tablets-14/android-tablets-14/
  5727. 'MpmanTablet' => 'MP11 OCTA|MP10 OCTA|MPQC1114|MPQC1004|MPQC994|MPQC974|MPQC973|MPQC804|MPQC784|MPQC780|\bMPG7\b|MPDCG75|MPDCG71|MPDC1006|MP101DC|MPDC9000|MPDC905|MPDC706HD|MPDC706|MPDC705|MPDC110|MPDC100|MPDC99|MPDC97|MPDC88|MPDC8|MPDC77|MP709|MID701|MID711|MID170|MPDC703|MPQC1010',
  5728. // https://www.celkonmobiles.com/?_a=categoryphones&sid=2
  5729. 'CelkonTablet' => 'CT695|CT888|CT[\s]?910|CT7 Tab|CT9 Tab|CT3 Tab|CT2 Tab|CT1 Tab|C820|C720|\bCT-1\b',
  5730. // http://www.wolderelectronics.com/productos/manuales-y-guias-rapidas/categoria-2-miTab
  5731. 'WolderTablet' => 'miTab \b(DIAMOND|SPACE|BROOKLYN|NEO|FLY|MANHATTAN|FUNK|EVOLUTION|SKY|GOCAR|IRON|GENIUS|POP|MINT|EPSILON|BROADWAY|JUMP|HOP|LEGEND|NEW AGE|LINE|ADVANCE|FEEL|FOLLOW|LIKE|LINK|LIVE|THINK|FREEDOM|CHICAGO|CLEVELAND|BALTIMORE-GH|IOWA|BOSTON|SEATTLE|PHOENIX|DALLAS|IN 101|MasterChef)\b',
  5732. // http://www.mi.com/en
  5733. 'MiTablet' => '\bMI PAD\b|\bHM NOTE 1W\b',
  5734. // http://www.nbru.cn/index.html
  5735. 'NibiruTablet' => 'Nibiru M1|Nibiru Jupiter One',
  5736. // http://navroad.com/products/produkty/tablety/
  5737. // http://navroad.com/products/produkty/tablety/
  5738. 'NexoTablet' => 'NEXO NOVA|NEXO 10|NEXO AVIO|NEXO FREE|NEXO GO|NEXO EVO|NEXO 3G|NEXO SMART|NEXO KIDDO|NEXO MOBI',
  5739. // http://leader-online.com/new_site/product-category/tablets/
  5740. // http://www.leader-online.net.au/List/Tablet
  5741. 'LeaderTablet' => 'TBLT10Q|TBLT10I|TBL-10WDKB|TBL-10WDKBO2013|TBL-W230V2|TBL-W450|TBL-W500|SV572|TBLT7I|TBA-AC7-8G|TBLT79|TBL-8W16|TBL-10W32|TBL-10WKB|TBL-W100',
  5742. // http://www.datawind.com/ubislate/
  5743. 'UbislateTablet' => 'UbiSlate[\s]?7C',
  5744. // http://www.pocketbook-int.com/ru/support
  5745. 'PocketBookTablet' => 'Pocketbook',
  5746. // http://www.kocaso.com/product_tablet.html
  5747. 'KocasoTablet' => '\b(TB-1207)\b',
  5748. // http://global.hisense.com/product/asia/tablet/Sero7/201412/t20141215_91832.htm
  5749. 'HisenseTablet' => '\b(F5281|E2371)\b',
  5750. // http://www.tesco.com/direct/hudl/
  5751. 'Hudl' => 'Hudl HT7S3|Hudl 2',
  5752. // http://www.telstra.com.au/home-phone/thub-2/
  5753. 'TelstraTablet' => 'T-Hub2',
  5754. 'GenericTablet' => 'Android.*\b97D\b|Tablet(?!.*PC)|BNTV250A|MID-WCDMA|LogicPD Zoom2|\bA7EB\b|CatNova8|A1_07|CT704|CT1002|\bM721\b|rk30sdk|\bEVOTAB\b|M758A|ET904|ALUMIUM10|Smartfren Tab|Endeavour 1010|Tablet-PC-4|Tagi Tab|\bM6pro\b|CT1020W|arc 10HD|\bTP750\b|\bQTAQZ3\b'
  5755. );
  5756. /**
  5757. * List of mobile Operating Systems.
  5758. *
  5759. * @var array
  5760. */
  5761. protected static $operatingSystems = array(
  5762. 'AndroidOS' => 'Android',
  5763. 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os',
  5764. 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
  5765. 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
  5766. // @reference: http://en.wikipedia.org/wiki/Windows_Mobile
  5767. 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;',
  5768. // @reference: http://en.wikipedia.org/wiki/Windows_Phone
  5769. // http://wifeng.cn/?r=blog&a=view&id=106
  5770. // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx
  5771. // http://msdn.microsoft.com/library/ms537503.aspx
  5772. // https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
  5773. 'WindowsPhoneOS' => 'Windows Phone 10.0|Windows Phone 8.1|Windows Phone 8.0|Windows Phone OS|XBLWP7|ZuneWP7|Windows NT 6.[23]; ARM;',
  5774. 'iOS' => '\biPhone.*Mobile|\biPod|\biPad',
  5775. // http://en.wikipedia.org/wiki/MeeGo
  5776. // @todo: research MeeGo in UAs
  5777. 'MeeGoOS' => 'MeeGo',
  5778. // http://en.wikipedia.org/wiki/Maemo
  5779. // @todo: research Maemo in UAs
  5780. 'MaemoOS' => 'Maemo',
  5781. 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135
  5782. 'webOS' => 'webOS|hpwOS',
  5783. 'badaOS' => '\bBada\b',
  5784. 'BREWOS' => 'BREW',
  5785. );
  5786. /**
  5787. * List of mobile User Agents.
  5788. *
  5789. * IMPORTANT: This is a list of only mobile browsers.
  5790. * Mobile Detect 2.x supports only mobile browsers,
  5791. * it was never designed to detect all browsers.
  5792. * The change will come in 2017 in the 3.x release for PHP7.
  5793. *
  5794. * @var array
  5795. */
  5796. protected static $browsers = array(
  5797. //'Vivaldi' => 'Vivaldi',
  5798. // @reference: https://developers.google.com/chrome/mobile/docs/user-agent
  5799. 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?',
  5800. 'Dolfin' => '\bDolfin\b',
  5801. 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+|Coast/[0-9.]+',
  5802. 'Skyfire' => 'Skyfire',
  5803. 'Edge' => 'Mobile Safari/[.0-9]* Edge',
  5804. 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+
  5805. 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS',
  5806. 'Bolt' => 'bolt',
  5807. 'TeaShark' => 'teashark',
  5808. 'Blazer' => 'Blazer',
  5809. // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3
  5810. 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari',
  5811. // http://en.wikipedia.org/wiki/Midori_(web_browser)
  5812. //'Midori' => 'midori',
  5813. //'Tizen' => 'Tizen',
  5814. 'UCBrowser' => 'UC.*Browser|UCWEB',
  5815. 'baiduboxapp' => 'baiduboxapp',
  5816. 'baidubrowser' => 'baidubrowser',
  5817. // https://github.com/serbanghita/Mobile-Detect/issues/7
  5818. 'DiigoBrowser' => 'DiigoBrowser',
  5819. // http://www.puffinbrowser.com/index.php
  5820. 'Puffin' => 'Puffin',
  5821. // http://mercury-browser.com/index.html
  5822. 'Mercury' => '\bMercury\b',
  5823. // http://en.wikipedia.org/wiki/Obigo_Browser
  5824. 'ObigoBrowser' => 'Obigo',
  5825. // http://en.wikipedia.org/wiki/NetFront
  5826. 'NetFront' => 'NF-Browser',
  5827. // @reference: http://en.wikipedia.org/wiki/Minimo
  5828. // http://en.wikipedia.org/wiki/Vision_Mobile_Browser
  5829. 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger',
  5830. // @reference: https://en.wikipedia.org/wiki/Pale_Moon_(web_browser)
  5831. 'PaleMoon' => 'Android.*PaleMoon|Mobile.*PaleMoon',
  5832. );
  5833. /**
  5834. * Utilities.
  5835. *
  5836. * @var array
  5837. */
  5838. protected static $utilities = array(
  5839. // Experimental. When a mobile device wants to switch to 'Desktop Mode'.
  5840. // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/
  5841. // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011
  5842. // https://developers.facebook.com/docs/sharing/best-practices
  5843. 'Bot' => 'Googlebot|facebookexternalhit|AdsBot-Google|Google Keyword Suggestion|Facebot|YandexBot|YandexMobileBot|bingbot|ia_archiver|AhrefsBot|Ezooms|GSLFbot|WBSearchBot|Twitterbot|TweetmemeBot|Twikle|PaperLiBot|Wotbox|UnwindFetchor|Exabot|MJ12bot|YandexImages|TurnitinBot|Pingdom',
  5844. 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2',
  5845. 'DesktopMode' => 'WPDesktop',
  5846. 'TV' => 'SonyDTV|HbbTV', // experimental
  5847. 'WebKit' => '(webkit)[ /]([\w.]+)',
  5848. // @todo: Include JXD consoles.
  5849. 'Console' => '\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b',
  5850. 'Watch' => 'SM-V700',
  5851. );
  5852. /**
  5853. * All possible HTTP headers that represent the
  5854. * User-Agent string.
  5855. *
  5856. * @var array
  5857. */
  5858. protected static $uaHttpHeaders = array(
  5859. // The default User-Agent string.
  5860. 'HTTP_USER_AGENT',
  5861. // Header can occur on devices using Opera Mini.
  5862. 'HTTP_X_OPERAMINI_PHONE_UA',
  5863. // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
  5864. 'HTTP_X_DEVICE_USER_AGENT',
  5865. 'HTTP_X_ORIGINAL_USER_AGENT',
  5866. 'HTTP_X_SKYFIRE_PHONE',
  5867. 'HTTP_X_BOLT_PHONE_UA',
  5868. 'HTTP_DEVICE_STOCK_UA',
  5869. 'HTTP_X_UCBROWSER_DEVICE_UA'
  5870. );
  5871. /**
  5872. * The individual segments that could exist in a User-Agent string. VER refers to the regular
  5873. * expression defined in the constant self::VER.
  5874. *
  5875. * @var array
  5876. */
  5877. protected static $properties = array(
  5878. // Build
  5879. 'Mobile' => 'Mobile/[VER]',
  5880. 'Build' => 'Build/[VER]',
  5881. 'Version' => 'Version/[VER]',
  5882. 'VendorID' => 'VendorID/[VER]',
  5883. // Devices
  5884. 'iPad' => 'iPad.*CPU[a-z ]+[VER]',
  5885. 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]',
  5886. 'iPod' => 'iPod.*CPU[a-z ]+[VER]',
  5887. //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'),
  5888. 'Kindle' => 'Kindle/[VER]',
  5889. // Browser
  5890. 'Chrome' => array('Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'),
  5891. 'Coast' => array('Coast/[VER]'),
  5892. 'Dolfin' => 'Dolfin/[VER]',
  5893. // @reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
  5894. 'Firefox' => array('Firefox/[VER]', 'FxiOS/[VER]'),
  5895. 'Fennec' => 'Fennec/[VER]',
  5896. // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
  5897. // https://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
  5898. 'Edge' => 'Edge/[VER]',
  5899. 'IE' => array('IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'Trident/[0-9.]+;.*rv:[VER]'),
  5900. // http://en.wikipedia.org/wiki/NetFront
  5901. 'NetFront' => 'NetFront/[VER]',
  5902. 'NokiaBrowser' => 'NokiaBrowser/[VER]',
  5903. 'Opera' => array( ' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]' ),
  5904. 'Opera Mini' => 'Opera Mini/[VER]',
  5905. 'Opera Mobi' => 'Version/[VER]',
  5906. 'UC Browser' => 'UC Browser[VER]',
  5907. 'MQQBrowser' => 'MQQBrowser/[VER]',
  5908. 'MicroMessenger' => 'MicroMessenger/[VER]',
  5909. 'baiduboxapp' => 'baiduboxapp/[VER]',
  5910. 'baidubrowser' => 'baidubrowser/[VER]',
  5911. 'SamsungBrowser' => 'SamsungBrowser/[VER]',
  5912. 'Iron' => 'Iron/[VER]',
  5913. // @note: Safari 7534.48.3 is actually Version 5.1.
  5914. // @note: On BlackBerry the Version is overwriten by the OS.
  5915. 'Safari' => array( 'Version/[VER]', 'Safari/[VER]' ),
  5916. 'Skyfire' => 'Skyfire/[VER]',
  5917. 'Tizen' => 'Tizen/[VER]',
  5918. 'Webkit' => 'webkit[ /][VER]',
  5919. 'PaleMoon' => 'PaleMoon/[VER]',
  5920. // Engine
  5921. 'Gecko' => 'Gecko/[VER]',
  5922. 'Trident' => 'Trident/[VER]',
  5923. 'Presto' => 'Presto/[VER]',
  5924. 'Goanna' => 'Goanna/[VER]',
  5925. // OS
  5926. 'iOS' => ' \bi?OS\b [VER][ ;]{1}',
  5927. 'Android' => 'Android [VER]',
  5928. 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'),
  5929. 'BREW' => 'BREW [VER]',
  5930. 'Java' => 'Java/[VER]',
  5931. // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx
  5932. // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases
  5933. 'Windows Phone OS' => array( 'Windows Phone OS [VER]', 'Windows Phone [VER]'),
  5934. 'Windows Phone' => 'Windows Phone [VER]',
  5935. 'Windows CE' => 'Windows CE/[VER]',
  5936. // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd
  5937. 'Windows NT' => 'Windows NT [VER]',
  5938. 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'),
  5939. 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'),
  5940. );
  5941. /**
  5942. * Construct an instance of this class.
  5943. *
  5944. * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored.
  5945. * If left empty, will use the global _SERVER['HTTP_*'] vars instead.
  5946. * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
  5947. * from the $headers array instead.
  5948. */
  5949. public function __construct(
  5950. array $headers = null,
  5951. $userAgent = null
  5952. ) {
  5953. $this->setHttpHeaders($headers);
  5954. $this->setUserAgent($userAgent);
  5955. }
  5956. /**
  5957. * Get the current script version.
  5958. * This is useful for the demo.php file,
  5959. * so people can check on what version they are testing
  5960. * for mobile devices.
  5961. *
  5962. * @return string The version number in semantic version format.
  5963. */
  5964. public static function getScriptVersion()
  5965. {
  5966. return self::VERSION;
  5967. }
  5968. /**
  5969. * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
  5970. *
  5971. * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
  5972. * the headers. The default null is left for backwards compatibility.
  5973. */
  5974. public function setHttpHeaders($httpHeaders = null)
  5975. {
  5976. // use global _SERVER if $httpHeaders aren't defined
  5977. if (!is_array($httpHeaders) || !count($httpHeaders)) {
  5978. $httpHeaders = $_SERVER;
  5979. }
  5980. // clear existing headers
  5981. $this->httpHeaders = array();
  5982. // Only save HTTP headers. In PHP land, that means only _SERVER vars that
  5983. // start with HTTP_.
  5984. foreach ($httpHeaders as $key => $value) {
  5985. if (substr($key, 0, 5) === 'HTTP_') {
  5986. $this->httpHeaders[$key] = $value;
  5987. }
  5988. }
  5989. // In case we're dealing with CloudFront, we need to know.
  5990. $this->setCfHeaders($httpHeaders);
  5991. }
  5992. /**
  5993. * Retrieves the HTTP headers.
  5994. *
  5995. * @return array
  5996. */
  5997. public function getHttpHeaders()
  5998. {
  5999. return $this->httpHeaders;
  6000. }
  6001. /**
  6002. * Retrieves a particular header. If it doesn't exist, no exception/error is caused.
  6003. * Simply null is returned.
  6004. *
  6005. * @param string $header The name of the header to retrieve. Can be HTTP compliant such as
  6006. * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the
  6007. * all-caps, HTTP_ prefixed, underscore seperated awesomeness.
  6008. *
  6009. * @return string|null The value of the header.
  6010. */
  6011. public function getHttpHeader($header)
  6012. {
  6013. // are we using PHP-flavored headers?
  6014. if (strpos($header, '_') === false) {
  6015. $header = str_replace('-', '_', $header);
  6016. $header = strtoupper($header);
  6017. }
  6018. // test the alternate, too
  6019. $altHeader = 'HTTP_' . $header;
  6020. //Test both the regular and the HTTP_ prefix
  6021. if (isset($this->httpHeaders[$header])) {
  6022. return $this->httpHeaders[$header];
  6023. } elseif (isset($this->httpHeaders[$altHeader])) {
  6024. return $this->httpHeaders[$altHeader];
  6025. }
  6026. return null;
  6027. }
  6028. public function getMobileHeaders()
  6029. {
  6030. return self::$mobileHeaders;
  6031. }
  6032. /**
  6033. * Get all possible HTTP headers that
  6034. * can contain the User-Agent string.
  6035. *
  6036. * @return array List of HTTP headers.
  6037. */
  6038. public function getUaHttpHeaders()
  6039. {
  6040. return self::$uaHttpHeaders;
  6041. }
  6042. /**
  6043. * Set CloudFront headers
  6044. * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device
  6045. *
  6046. * @param array $cfHeaders List of HTTP headers
  6047. *
  6048. * @return boolean If there were CloudFront headers to be set
  6049. */
  6050. public function setCfHeaders($cfHeaders = null) {
  6051. // use global _SERVER if $cfHeaders aren't defined
  6052. if (!is_array($cfHeaders) || !count($cfHeaders)) {
  6053. $cfHeaders = $_SERVER;
  6054. }
  6055. // clear existing headers
  6056. $this->cloudfrontHeaders = array();
  6057. // Only save CLOUDFRONT headers. In PHP land, that means only _SERVER vars that
  6058. // start with cloudfront-.
  6059. $response = false;
  6060. foreach ($cfHeaders as $key => $value) {
  6061. if (substr(strtolower($key), 0, 16) === 'http_cloudfront_') {
  6062. $this->cloudfrontHeaders[strtoupper($key)] = $value;
  6063. $response = true;
  6064. }
  6065. }
  6066. return $response;
  6067. }
  6068. /**
  6069. * Retrieves the cloudfront headers.
  6070. *
  6071. * @return array
  6072. */
  6073. public function getCfHeaders()
  6074. {
  6075. return $this->cloudfrontHeaders;
  6076. }
  6077. /**
  6078. * Set the User-Agent to be used.
  6079. *
  6080. * @param string $userAgent The user agent string to set.
  6081. *
  6082. * @return string|null
  6083. */
  6084. public function setUserAgent($userAgent = null)
  6085. {
  6086. // Invalidate cache due to #375
  6087. $this->cache = array();
  6088. if (false === empty($userAgent)) {
  6089. return $this->userAgent = $userAgent;
  6090. } else {
  6091. $this->userAgent = null;
  6092. foreach ($this->getUaHttpHeaders() as $altHeader) {
  6093. if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban)
  6094. $this->userAgent .= $this->httpHeaders[$altHeader] . " ";
  6095. }
  6096. }
  6097. if (!empty($this->userAgent)) {
  6098. return $this->userAgent = trim($this->userAgent);
  6099. }
  6100. }
  6101. if (count($this->getCfHeaders()) > 0) {
  6102. return $this->userAgent = 'Amazon CloudFront';
  6103. }
  6104. return $this->userAgent = null;
  6105. }
  6106. /**
  6107. * Retrieve the User-Agent.
  6108. *
  6109. * @return string|null The user agent if it's set.
  6110. */
  6111. public function getUserAgent()
  6112. {
  6113. return $this->userAgent;
  6114. }
  6115. /**
  6116. * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or
  6117. * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set.
  6118. *
  6119. * @deprecated since version 2.6.9
  6120. *
  6121. * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
  6122. * parameter is null which will default to self::DETECTION_TYPE_MOBILE.
  6123. */
  6124. public function setDetectionType($type = null)
  6125. {
  6126. if ($type === null) {
  6127. $type = self::DETECTION_TYPE_MOBILE;
  6128. }
  6129. if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) {
  6130. return;
  6131. }
  6132. $this->detectionType = $type;
  6133. }
  6134. public function getMatchingRegex()
  6135. {
  6136. return $this->matchingRegex;
  6137. }
  6138. public function getMatchesArray()
  6139. {
  6140. return $this->matchesArray;
  6141. }
  6142. /**
  6143. * Retrieve the list of known phone devices.
  6144. *
  6145. * @return array List of phone devices.
  6146. */
  6147. public static function getPhoneDevices()
  6148. {
  6149. return self::$phoneDevices;
  6150. }
  6151. /**
  6152. * Retrieve the list of known tablet devices.
  6153. *
  6154. * @return array List of tablet devices.
  6155. */
  6156. public static function getTabletDevices()
  6157. {
  6158. return self::$tabletDevices;
  6159. }
  6160. /**
  6161. * Alias for getBrowsers() method.
  6162. *
  6163. * @return array List of user agents.
  6164. */
  6165. public static function getUserAgents()
  6166. {
  6167. return self::getBrowsers();
  6168. }
  6169. /**
  6170. * Retrieve the list of known browsers. Specifically, the user agents.
  6171. *
  6172. * @return array List of browsers / user agents.
  6173. */
  6174. public static function getBrowsers()
  6175. {
  6176. return self::$browsers;
  6177. }
  6178. /**
  6179. * Retrieve the list of known utilities.
  6180. *
  6181. * @return array List of utilities.
  6182. */
  6183. public static function getUtilities()
  6184. {
  6185. return self::$utilities;
  6186. }
  6187. /**
  6188. * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().
  6189. *
  6190. * @deprecated since version 2.6.9
  6191. *
  6192. * @return array All the rules (but not extended).
  6193. */
  6194. public static function getMobileDetectionRules()
  6195. {
  6196. static $rules;
  6197. if (!$rules) {
  6198. $rules = array_merge(
  6199. self::$phoneDevices,
  6200. self::$tabletDevices,
  6201. self::$operatingSystems,
  6202. self::$browsers
  6203. );
  6204. }
  6205. return $rules;
  6206. }
  6207. /**
  6208. * Method gets the mobile detection rules + utilities.
  6209. * The reason this is separate is because utilities rules
  6210. * don't necessary imply mobile. This method is used inside
  6211. * the new $detect->is('stuff') method.
  6212. *
  6213. * @deprecated since version 2.6.9
  6214. *
  6215. * @return array All the rules + extended.
  6216. */
  6217. public function getMobileDetectionRulesExtended()
  6218. {
  6219. static $rules;
  6220. if (!$rules) {
  6221. // Merge all rules together.
  6222. $rules = array_merge(
  6223. self::$phoneDevices,
  6224. self::$tabletDevices,
  6225. self::$operatingSystems,
  6226. self::$browsers,
  6227. self::$utilities
  6228. );
  6229. }
  6230. return $rules;
  6231. }
  6232. /**
  6233. * Retrieve the current set of rules.
  6234. *
  6235. * @deprecated since version 2.6.9
  6236. *
  6237. * @return array
  6238. */
  6239. public function getRules()
  6240. {
  6241. if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) {
  6242. return self::getMobileDetectionRulesExtended();
  6243. } else {
  6244. return self::getMobileDetectionRules();
  6245. }
  6246. }
  6247. /**
  6248. * Retrieve the list of mobile operating systems.
  6249. *
  6250. * @return array The list of mobile operating systems.
  6251. */
  6252. public static function getOperatingSystems()
  6253. {
  6254. return self::$operatingSystems;
  6255. }
  6256. /**
  6257. * Check the HTTP headers for signs of mobile.
  6258. * This is the fastest mobile check possible; it's used
  6259. * inside isMobile() method.
  6260. *
  6261. * @return bool
  6262. */
  6263. public function checkHttpHeadersForMobile()
  6264. {
  6265. foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) {
  6266. if (isset($this->httpHeaders[$mobileHeader])) {
  6267. if (is_array($matchType['matches'])) {
  6268. foreach ($matchType['matches'] as $_match) {
  6269. if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) {
  6270. return true;
  6271. }
  6272. }
  6273. return false;
  6274. } else {
  6275. return true;
  6276. }
  6277. }
  6278. }
  6279. return false;
  6280. }
  6281. /**
  6282. * Magic overloading method.
  6283. *
  6284. * @method boolean is[...]()
  6285. * @param string $name
  6286. * @param array $arguments
  6287. * @return mixed
  6288. * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
  6289. */
  6290. public function __call($name, $arguments)
  6291. {
  6292. // make sure the name starts with 'is', otherwise
  6293. if (substr($name, 0, 2) !== 'is') {
  6294. throw new BadMethodCallException("No such method exists: $name");
  6295. }
  6296. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6297. $key = substr($name, 2);
  6298. return $this->matchUAAgainstKey($key);
  6299. }
  6300. /**
  6301. * Find a detection rule that matches the current User-agent.
  6302. *
  6303. * @param null $userAgent deprecated
  6304. * @return boolean
  6305. */
  6306. protected function matchDetectionRulesAgainstUA($userAgent = null)
  6307. {
  6308. // Begin general search.
  6309. foreach ($this->getRules() as $_regex) {
  6310. if (empty($_regex)) {
  6311. continue;
  6312. }
  6313. if ($this->match($_regex, $userAgent)) {
  6314. return true;
  6315. }
  6316. }
  6317. return false;
  6318. }
  6319. /**
  6320. * Search for a certain key in the rules array.
  6321. * If the key is found then try to match the corresponding
  6322. * regex against the User-Agent.
  6323. *
  6324. * @param string $key
  6325. *
  6326. * @return boolean
  6327. */
  6328. protected function matchUAAgainstKey($key)
  6329. {
  6330. // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
  6331. $key = strtolower($key);
  6332. if (false === isset($this->cache[$key])) {
  6333. // change the keys to lower case
  6334. $_rules = array_change_key_case($this->getRules());
  6335. if (false === empty($_rules[$key])) {
  6336. $this->cache[$key] = $this->match($_rules[$key]);
  6337. }
  6338. if (false === isset($this->cache[$key])) {
  6339. $this->cache[$key] = false;
  6340. }
  6341. }
  6342. return $this->cache[$key];
  6343. }
  6344. /**
  6345. * Check if the device is mobile.
  6346. * Returns true if any type of mobile device detected, including special ones
  6347. * @param null $userAgent deprecated
  6348. * @param null $httpHeaders deprecated
  6349. * @return bool
  6350. */
  6351. public function isMobile($userAgent = null, $httpHeaders = null)
  6352. {
  6353. if ($httpHeaders) {
  6354. $this->setHttpHeaders($httpHeaders);
  6355. }
  6356. if ($userAgent) {
  6357. $this->setUserAgent($userAgent);
  6358. }
  6359. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6360. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6361. $cfHeaders = $this->getCfHeaders();
  6362. if(array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') {
  6363. return true;
  6364. }
  6365. }
  6366. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6367. if ($this->checkHttpHeadersForMobile()) {
  6368. return true;
  6369. } else {
  6370. return $this->matchDetectionRulesAgainstUA();
  6371. }
  6372. }
  6373. /**
  6374. * Check if the device is a tablet.
  6375. * Return true if any type of tablet device is detected.
  6376. *
  6377. * @param string $userAgent deprecated
  6378. * @param array $httpHeaders deprecated
  6379. * @return bool
  6380. */
  6381. public function isTablet($userAgent = null, $httpHeaders = null)
  6382. {
  6383. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6384. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6385. $cfHeaders = $this->getCfHeaders();
  6386. if(array_key_exists('HTTP_CLOUDFRONT_IS_TABLET_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] === 'true') {
  6387. return true;
  6388. }
  6389. }
  6390. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6391. foreach (self::$tabletDevices as $_regex) {
  6392. if ($this->match($_regex, $userAgent)) {
  6393. return true;
  6394. }
  6395. }
  6396. return false;
  6397. }
  6398. /**
  6399. * This method checks for a certain property in the
  6400. * userAgent.
  6401. * @todo: The httpHeaders part is not yet used.
  6402. *
  6403. * @param string $key
  6404. * @param string $userAgent deprecated
  6405. * @param string $httpHeaders deprecated
  6406. * @return bool|int|null
  6407. */
  6408. public function is($key, $userAgent = null, $httpHeaders = null)
  6409. {
  6410. // Set the UA and HTTP headers only if needed (eg. batch mode).
  6411. if ($httpHeaders) {
  6412. $this->setHttpHeaders($httpHeaders);
  6413. }
  6414. if ($userAgent) {
  6415. $this->setUserAgent($userAgent);
  6416. }
  6417. $this->setDetectionType(self::DETECTION_TYPE_EXTENDED);
  6418. return $this->matchUAAgainstKey($key);
  6419. }
  6420. /**
  6421. * Some detection rules are relative (not standard),
  6422. * because of the diversity of devices, vendors and
  6423. * their conventions in representing the User-Agent or
  6424. * the HTTP headers.
  6425. *
  6426. * This method will be used to check custom regexes against
  6427. * the User-Agent string.
  6428. *
  6429. * @param $regex
  6430. * @param string $userAgent
  6431. * @return bool
  6432. *
  6433. * @todo: search in the HTTP headers too.
  6434. */
  6435. public function match($regex, $userAgent = null)
  6436. {
  6437. $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches);
  6438. // If positive match is found, store the results for debug.
  6439. if ($match) {
  6440. $this->matchingRegex = $regex;
  6441. $this->matchesArray = $matches;
  6442. }
  6443. return $match;
  6444. }
  6445. /**
  6446. * Get the properties array.
  6447. *
  6448. * @return array
  6449. */
  6450. public static function getProperties()
  6451. {
  6452. return self::$properties;
  6453. }
  6454. /**
  6455. * Prepare the version number.
  6456. *
  6457. * @todo Remove the error supression from str_replace() call.
  6458. *
  6459. * @param string $ver The string version, like "2.6.21.2152";
  6460. *
  6461. * @return float
  6462. */
  6463. public function prepareVersionNo($ver)
  6464. {
  6465. $ver = str_replace(array('_', ' ', '/'), '.', $ver);
  6466. $arrVer = explode('.', $ver, 2);
  6467. if (isset($arrVer[1])) {
  6468. $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions.
  6469. }
  6470. return (float) implode('.', $arrVer);
  6471. }
  6472. /**
  6473. * Check the version of the given property in the User-Agent.
  6474. * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
  6475. *
  6476. * @param string $propertyName The name of the property. See self::getProperties() array
  6477. * keys for all possible properties.
  6478. * @param string $type Either self::VERSION_TYPE_STRING to get a string value or
  6479. * self::VERSION_TYPE_FLOAT indicating a float value. This parameter
  6480. * is optional and defaults to self::VERSION_TYPE_STRING. Passing an
  6481. * invalid parameter will default to the this type as well.
  6482. *
  6483. * @return string|float The version of the property we are trying to extract.
  6484. */
  6485. public function version($propertyName, $type = self::VERSION_TYPE_STRING)
  6486. {
  6487. if (empty($propertyName)) {
  6488. return false;
  6489. }
  6490. // set the $type to the default if we don't recognize the type
  6491. if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
  6492. $type = self::VERSION_TYPE_STRING;
  6493. }
  6494. $properties = self::getProperties();
  6495. // Check if the property exists in the properties array.
  6496. if (true === isset($properties[$propertyName])) {
  6497. // Prepare the pattern to be matched.
  6498. // Make sure we always deal with an array (string is converted).
  6499. $properties[$propertyName] = (array) $properties[$propertyName];
  6500. foreach ($properties[$propertyName] as $propertyMatchString) {
  6501. $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
  6502. // Identify and extract the version.
  6503. preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);
  6504. if (false === empty($match[1])) {
  6505. $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);
  6506. return $version;
  6507. }
  6508. }
  6509. }
  6510. return false;
  6511. }
  6512. /**
  6513. * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
  6514. *
  6515. * @return string One of the self::MOBILE_GRADE_* constants.
  6516. */
  6517. public function mobileGrade()
  6518. {
  6519. $isMobile = $this->isMobile();
  6520. if (
  6521. // Apple iOS 4-7.0 – Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3 / 5.1 / 6.1), iPad 3 (5.1 / 6.0), iPad Mini (6.1), iPad Retina (7.0), iPhone 3GS (4.3), iPhone 4 (4.3 / 5.1), iPhone 4S (5.1 / 6.0), iPhone 5 (6.0), and iPhone 5S (7.0)
  6522. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6523. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6524. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6525. // Android 2.1-2.3 - Tested on the HTC Incredible (2.2), original Droid (2.2), HTC Aria (2.1), Google Nexus S (2.3). Functional on 1.5 & 1.6 but performance may be sluggish, tested on Google G1 (1.5)
  6526. // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
  6527. // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
  6528. // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
  6529. ( $this->version('Android', self::VERSION_TYPE_FLOAT)>2.1 && $this->is('Webkit') ) ||
  6530. // Windows Phone 7.5-8 - Tested on the HTC Surround (7.5), HTC Trophy (7.5), LG-E900 (7.5), Nokia 800 (7.8), HTC Mazaa (7.8), Nokia Lumia 520 (8), Nokia Lumia 920 (8), HTC 8x (8)
  6531. $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 ||
  6532. // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry® Torch 9810 (7), BlackBerry Z10 (10)
  6533. $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 ||
  6534. // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
  6535. $this->match('Playbook.*Tablet') ||
  6536. // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0)
  6537. ( $this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi') ) ||
  6538. // Palm WebOS 3.0 - Tested on HP TouchPad
  6539. $this->match('hp.*TouchPad') ||
  6540. // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices
  6541. ( $this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18 ) ||
  6542. // Chrome for Android - Tested on Android 4.0, 4.1 device
  6543. ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0 ) ||
  6544. // Skyfire 4.1 - Tested on Android 2.3 device
  6545. ( $this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6546. // Opera Mobile 11.5-12: Tested on Android 2.3
  6547. ( $this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS') ) ||
  6548. // Meego 1.2 - Tested on Nokia 950 and N9
  6549. $this->is('MeeGoOS') ||
  6550. // Tizen (pre-release) - Tested on early hardware
  6551. $this->is('Tizen') ||
  6552. // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
  6553. // @todo: more tests here!
  6554. $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 ||
  6555. // UC Browser - Tested on Android 2.3 device
  6556. ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6557. // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
  6558. ( $this->match('Kindle Fire') ||
  6559. $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0 ) ||
  6560. // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
  6561. $this->is('AndroidOS') && $this->is('NookTablet') ||
  6562. // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7
  6563. $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && !$isMobile ||
  6564. // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7
  6565. $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && !$isMobile ||
  6566. // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7
  6567. $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && !$isMobile ||
  6568. // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
  6569. $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && !$isMobile ||
  6570. // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
  6571. $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && !$isMobile
  6572. ){
  6573. return self::MOBILE_GRADE_A;
  6574. }
  6575. if (
  6576. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT)<4.3 ||
  6577. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT)<4.3 ||
  6578. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT)<4.3 ||
  6579. // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
  6580. $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT)<6 ||
  6581. //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
  6582. ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 &&
  6583. ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS')) ) ||
  6584. // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
  6585. $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
  6586. // @todo: report this (tested on Nokia N71)
  6587. $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS')
  6588. ){
  6589. return self::MOBILE_GRADE_B;
  6590. }
  6591. if (
  6592. // Blackberry 4.x - Tested on the Curve 8330
  6593. $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 ||
  6594. // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
  6595. $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 ||
  6596. // Tested on original iPhone (3.1), iPhone 3 (3.2)
  6597. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6598. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6599. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6600. // Internet Explorer 7 and older - Tested on Windows XP
  6601. $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && !$isMobile
  6602. ){
  6603. return self::MOBILE_GRADE_C;
  6604. }
  6605. // All older smartphone platforms and featurephones - Any device that doesn't support media queries
  6606. // will receive the basic, C grade experience.
  6607. return self::MOBILE_GRADE_C;
  6608. }
  6609. }
  6610. $mobileDetect = new Mobile_Detect;
  6611. $userDevice = ($mobileDetect->isMobile() ? ($mobileDetect->isTablet() ? 'tablet' : 'phone') : 'computer');
  6612. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  6613. $path = getServerPath();
  6614. return '
  6615. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6616. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  6617. <head>
  6618. <!--[if gte mso 9]><xml>
  6619. <o:OfficeDocumentSettings>
  6620. <o:AllowPNG/>
  6621. <o:PixelsPerInch>96</o:PixelsPerInch>
  6622. </o:OfficeDocumentSettings>
  6623. </xml><![endif]-->
  6624. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6625. <meta name="viewport" content="width=device-width">
  6626. <!--[if !mso]><!-->
  6627. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6628. <!--<![endif]-->
  6629. <title></title>
  6630. <!--[if !mso]><!-- -->
  6631. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  6632. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  6633. <!--<![endif]-->
  6634. <style type="text/css" id="media-query">
  6635. body {
  6636. margin: 0;
  6637. padding: 0;
  6638. }
  6639. table,
  6640. tr,
  6641. td {
  6642. vertical-align: top;
  6643. border-collapse: collapse;
  6644. }
  6645. .ie-browser table,
  6646. .mso-container table {
  6647. table-layout: fixed;
  6648. }
  6649. * {
  6650. line-height: inherit;
  6651. }
  6652. a[x-apple-data-detectors=true] {
  6653. color: inherit !important;
  6654. text-decoration: none !important;
  6655. }
  6656. [owa] .img-container div,
  6657. [owa] .img-container button {
  6658. display: block !important;
  6659. }
  6660. [owa] .fullwidth button {
  6661. width: 100% !important;
  6662. }
  6663. [owa] .block-grid .col {
  6664. display: table-cell;
  6665. float: none !important;
  6666. vertical-align: top;
  6667. }
  6668. .ie-browser .num12,
  6669. .ie-browser .block-grid,
  6670. [owa] .num12,
  6671. [owa] .block-grid {
  6672. width: 615px !important;
  6673. }
  6674. .ExternalClass,
  6675. .ExternalClass p,
  6676. .ExternalClass span,
  6677. .ExternalClass font,
  6678. .ExternalClass td,
  6679. .ExternalClass div {
  6680. line-height: 100%;
  6681. }
  6682. .ie-browser .mixed-two-up .num4,
  6683. [owa] .mixed-two-up .num4 {
  6684. width: 204px !important;
  6685. }
  6686. .ie-browser .mixed-two-up .num8,
  6687. [owa] .mixed-two-up .num8 {
  6688. width: 408px !important;
  6689. }
  6690. .ie-browser .block-grid.two-up .col,
  6691. [owa] .block-grid.two-up .col {
  6692. width: 307px !important;
  6693. }
  6694. .ie-browser .block-grid.three-up .col,
  6695. [owa] .block-grid.three-up .col {
  6696. width: 205px !important;
  6697. }
  6698. .ie-browser .block-grid.four-up .col,
  6699. [owa] .block-grid.four-up .col {
  6700. width: 153px !important;
  6701. }
  6702. .ie-browser .block-grid.five-up .col,
  6703. [owa] .block-grid.five-up .col {
  6704. width: 123px !important;
  6705. }
  6706. .ie-browser .block-grid.six-up .col,
  6707. [owa] .block-grid.six-up .col {
  6708. width: 102px !important;
  6709. }
  6710. .ie-browser .block-grid.seven-up .col,
  6711. [owa] .block-grid.seven-up .col {
  6712. width: 87px !important;
  6713. }
  6714. .ie-browser .block-grid.eight-up .col,
  6715. [owa] .block-grid.eight-up .col {
  6716. width: 76px !important;
  6717. }
  6718. .ie-browser .block-grid.nine-up .col,
  6719. [owa] .block-grid.nine-up .col {
  6720. width: 68px !important;
  6721. }
  6722. .ie-browser .block-grid.ten-up .col,
  6723. [owa] .block-grid.ten-up .col {
  6724. width: 61px !important;
  6725. }
  6726. .ie-browser .block-grid.eleven-up .col,
  6727. [owa] .block-grid.eleven-up .col {
  6728. width: 55px !important;
  6729. }
  6730. .ie-browser .block-grid.twelve-up .col,
  6731. [owa] .block-grid.twelve-up .col {
  6732. width: 51px !important;
  6733. }
  6734. @media only screen and (min-width: 635px) {
  6735. .block-grid {
  6736. width: 615px !important;
  6737. }
  6738. .block-grid .col {
  6739. display: table-cell;
  6740. Float: none !important;
  6741. vertical-align: top;
  6742. }
  6743. .block-grid .col.num12 {
  6744. width: 615px !important;
  6745. }
  6746. .block-grid.mixed-two-up .col.num4 {
  6747. width: 204px !important;
  6748. }
  6749. .block-grid.mixed-two-up .col.num8 {
  6750. width: 408px !important;
  6751. }
  6752. .block-grid.two-up .col {
  6753. width: 307px !important;
  6754. }
  6755. .block-grid.three-up .col {
  6756. width: 205px !important;
  6757. }
  6758. .block-grid.four-up .col {
  6759. width: 153px !important;
  6760. }
  6761. .block-grid.five-up .col {
  6762. width: 123px !important;
  6763. }
  6764. .block-grid.six-up .col {
  6765. width: 102px !important;
  6766. }
  6767. .block-grid.seven-up .col {
  6768. width: 87px !important;
  6769. }
  6770. .block-grid.eight-up .col {
  6771. width: 76px !important;
  6772. }
  6773. .block-grid.nine-up .col {
  6774. width: 68px !important;
  6775. }
  6776. .block-grid.ten-up .col {
  6777. width: 61px !important;
  6778. }
  6779. .block-grid.eleven-up .col {
  6780. width: 55px !important;
  6781. }
  6782. .block-grid.twelve-up .col {
  6783. width: 51px !important;
  6784. }
  6785. }
  6786. @media (max-width: 635px) {
  6787. .block-grid,
  6788. .col {
  6789. min-width: 320px !important;
  6790. max-width: 100% !important;
  6791. }
  6792. .block-grid {
  6793. width: calc(100% - 40px) !important;
  6794. }
  6795. .col {
  6796. width: 100% !important;
  6797. }
  6798. .col>div {
  6799. margin: 0 auto;
  6800. }
  6801. img.fullwidth {
  6802. max-width: 100% !important;
  6803. }
  6804. }
  6805. </style>
  6806. </head>
  6807. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  6808. <!--[if IE]><div class="ie-browser"><![endif]-->
  6809. <!--[if mso]><div class="mso-container"><![endif]-->
  6810. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  6811. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  6812. <div style="background-color:#333333;">
  6813. <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;"
  6814. class="block-grid ">
  6815. <div style="border-collapse: collapse;display: table;width: 100%;">
  6816. <!--[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]-->
  6817. <!--[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]-->
  6818. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6819. <div style="background-color: transparent; width: 100% !important;">
  6820. <!--[if (!mso)&(!IE)]><!-->
  6821. <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;">
  6822. <!--<![endif]-->
  6823. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  6824. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  6825. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  6826. 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"
  6827. width="555">
  6828. <!--[if mso]></td></tr></table><![endif]-->
  6829. </div>
  6830. <!--[if (!mso)&(!IE)]><!-->
  6831. </div>
  6832. <!--<![endif]-->
  6833. </div>
  6834. </div>
  6835. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6836. </div>
  6837. </div>
  6838. </div>
  6839. <div style="background-color:#333333;">
  6840. <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;"
  6841. class="block-grid ">
  6842. <div style="border-collapse: collapse;display: table;width: 100%;">
  6843. <!--[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]-->
  6844. <!--[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]-->
  6845. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6846. <div style="background-color: transparent; width: 100% !important;">
  6847. <!--[if (!mso)&(!IE)]><!-->
  6848. <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;">
  6849. <!--<![endif]-->
  6850. <!--[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]-->
  6851. <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;">
  6852. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6853. <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>
  6854. </span>
  6855. </p>
  6856. </div>
  6857. </div>
  6858. <!--[if mso]></td></tr></table><![endif]-->
  6859. <!--[if (!mso)&(!IE)]><!-->
  6860. </div>
  6861. <!--<![endif]-->
  6862. </div>
  6863. </div>
  6864. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6865. </div>
  6866. </div>
  6867. </div>
  6868. <div style="background-color:#393939;">
  6869. <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;"
  6870. class="block-grid ">
  6871. <div style="border-collapse: collapse;display: table;width: 100%;">
  6872. <!--[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]-->
  6873. <!--[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]-->
  6874. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6875. <div style="background-color: transparent; width: 100% !important;">
  6876. <!--[if (!mso)&(!IE)]><!-->
  6877. <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;">
  6878. <!--<![endif]-->
  6879. <!--[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]-->
  6880. <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;">
  6881. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6882. <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>
  6883. </div>
  6884. </div>
  6885. <!--[if mso]></td></tr></table><![endif]-->
  6886. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  6887. <!--[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]-->
  6888. <div align="center">
  6889. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  6890. </div>
  6891. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6892. </div>
  6893. <!--[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]-->
  6894. <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;">
  6895. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6896. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  6897. </div>
  6898. </div>
  6899. <!--[if mso]></td></tr></table><![endif]-->
  6900. <!--[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]-->
  6901. <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;">
  6902. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  6903. <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>
  6904. </span>
  6905. </p>
  6906. </div>
  6907. </div>
  6908. <!--[if mso]></td></tr></table><![endif]-->
  6909. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  6910. <!--[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]-->
  6911. <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">
  6912. <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>
  6913. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6914. </div>
  6915. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6916. </div>
  6917. <!--[if (!mso)&(!IE)]><!-->
  6918. </div>
  6919. <!--<![endif]-->
  6920. </div>
  6921. </div>
  6922. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6923. </div>
  6924. </div>
  6925. </div>
  6926. <div style="background-color:#ffffff;">
  6927. <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;"
  6928. class="block-grid ">
  6929. <div style="border-collapse: collapse;display: table;width: 100%;">
  6930. <!--[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]-->
  6931. <!--[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]-->
  6932. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6933. <div style="background-color: transparent; width: 100% !important;">
  6934. <!--[if (!mso)&(!IE)]><!-->
  6935. <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;">
  6936. <!--<![endif]-->
  6937. <!--[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]-->
  6938. <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;">
  6939. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6940. <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>
  6941. </div>
  6942. </div>
  6943. <!--[if mso]></td></tr></table><![endif]-->
  6944. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  6945. <!--[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]-->
  6946. <div align="center">
  6947. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  6948. </div>
  6949. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6950. </div>
  6951. <!--[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]-->
  6952. <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;">
  6953. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6954. <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>
  6955. </div>
  6956. </div>
  6957. <!--[if mso]></td></tr></table><![endif]-->
  6958. <!--[if (!mso)&(!IE)]><!-->
  6959. </div>
  6960. <!--<![endif]-->
  6961. </div>
  6962. </div>
  6963. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6964. </div>
  6965. </div>
  6966. </div>
  6967. <div style="background-color:#333333;">
  6968. <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;"
  6969. class="block-grid ">
  6970. <div style="border-collapse: collapse;display: table;width: 100%;">
  6971. <!--[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]-->
  6972. <!--[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]-->
  6973. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6974. <div style="background-color: transparent; width: 100% !important;">
  6975. <!--[if (!mso)&(!IE)]><!-->
  6976. <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;">
  6977. <!--<![endif]-->
  6978. <!--[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]-->
  6979. <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;">
  6980. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6981. <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"
  6982. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  6983. </div>
  6984. </div>
  6985. <!--[if mso]></td></tr></table><![endif]-->
  6986. <!--[if (!mso)&(!IE)]><!-->
  6987. </div>
  6988. <!--<![endif]-->
  6989. </div>
  6990. </div>
  6991. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6992. </div>
  6993. </div>
  6994. </div>
  6995. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  6996. </div>
  6997. <!--[if (mso)|(IE)]></div><![endif]-->
  6998. </body>
  6999. </html>
  7000. ';
  7001. }
  7002. function mimeTypes(){
  7003. return array(
  7004. '123' => 'application/vnd.lotus-1-2-3',
  7005. '3dml' => 'text/vnd.in3d.3dml',
  7006. '3ds' => 'image/x-3ds',
  7007. '3g2' => 'video/3gpp2',
  7008. '3gp' => 'video/3gpp',
  7009. '7z' => 'application/x-7z-compressed',
  7010. 'aab' => 'application/x-authorware-bin',
  7011. 'aac' => 'audio/x-aac',
  7012. 'aam' => 'application/x-authorware-map',
  7013. 'aas' => 'application/x-authorware-seg',
  7014. 'abw' => 'application/x-abiword',
  7015. 'ac' => 'application/pkix-attr-cert',
  7016. 'acc' => 'application/vnd.americandynamics.acc',
  7017. 'ace' => 'application/x-ace-compressed',
  7018. 'acu' => 'application/vnd.acucobol',
  7019. 'acutc' => 'application/vnd.acucorp',
  7020. 'adp' => 'audio/adpcm',
  7021. 'aep' => 'application/vnd.audiograph',
  7022. 'afm' => 'application/x-font-type1',
  7023. 'afp' => 'application/vnd.ibm.modcap',
  7024. 'ahead' => 'application/vnd.ahead.space',
  7025. 'ai' => 'application/postscript',
  7026. 'aif' => 'audio/x-aiff',
  7027. 'aifc' => 'audio/x-aiff',
  7028. 'aiff' => 'audio/x-aiff',
  7029. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  7030. 'ait' => 'application/vnd.dvb.ait',
  7031. 'ami' => 'application/vnd.amiga.ami',
  7032. 'apk' => 'application/vnd.android.package-archive',
  7033. 'appcache' => 'text/cache-manifest',
  7034. 'application' => 'application/x-ms-application',
  7035. 'apr' => 'application/vnd.lotus-approach',
  7036. 'arc' => 'application/x-freearc',
  7037. 'asc' => 'application/pgp-signature',
  7038. 'asf' => 'video/x-ms-asf',
  7039. 'asm' => 'text/x-asm',
  7040. 'aso' => 'application/vnd.accpac.simply.aso',
  7041. 'asx' => 'video/x-ms-asf',
  7042. 'atc' => 'application/vnd.acucorp',
  7043. 'atom' => 'application/atom+xml',
  7044. 'atomcat' => 'application/atomcat+xml',
  7045. 'atomsvc' => 'application/atomsvc+xml',
  7046. 'atx' => 'application/vnd.antix.game-component',
  7047. 'au' => 'audio/basic',
  7048. 'avi' => 'video/x-msvideo',
  7049. 'aw' => 'application/applixware',
  7050. 'azf' => 'application/vnd.airzip.filesecure.azf',
  7051. 'azs' => 'application/vnd.airzip.filesecure.azs',
  7052. 'azw' => 'application/vnd.amazon.ebook',
  7053. 'bat' => 'application/x-msdownload',
  7054. 'bcpio' => 'application/x-bcpio',
  7055. 'bdf' => 'application/x-font-bdf',
  7056. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  7057. 'bed' => 'application/vnd.realvnc.bed',
  7058. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  7059. 'bin' => 'application/octet-stream',
  7060. 'blb' => 'application/x-blorb',
  7061. 'blorb' => 'application/x-blorb',
  7062. 'bmi' => 'application/vnd.bmi',
  7063. 'bmp' => 'image/bmp',
  7064. 'book' => 'application/vnd.framemaker',
  7065. 'box' => 'application/vnd.previewsystems.box',
  7066. 'boz' => 'application/x-bzip2',
  7067. 'bpk' => 'application/octet-stream',
  7068. 'btif' => 'image/prs.btif',
  7069. 'bz' => 'application/x-bzip',
  7070. 'bz2' => 'application/x-bzip2',
  7071. 'c' => 'text/x-c',
  7072. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  7073. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  7074. 'c4d' => 'application/vnd.clonk.c4group',
  7075. 'c4f' => 'application/vnd.clonk.c4group',
  7076. 'c4g' => 'application/vnd.clonk.c4group',
  7077. 'c4p' => 'application/vnd.clonk.c4group',
  7078. 'c4u' => 'application/vnd.clonk.c4group',
  7079. 'cab' => 'application/vnd.ms-cab-compressed',
  7080. 'caf' => 'audio/x-caf',
  7081. 'cap' => 'application/vnd.tcpdump.pcap',
  7082. 'car' => 'application/vnd.curl.car',
  7083. 'cat' => 'application/vnd.ms-pki.seccat',
  7084. 'cb7' => 'application/x-cbr',
  7085. 'cba' => 'application/x-cbr',
  7086. 'cbr' => 'application/x-cbr',
  7087. 'cbt' => 'application/x-cbr',
  7088. 'cbz' => 'application/x-cbr',
  7089. 'cc' => 'text/x-c',
  7090. 'cct' => 'application/x-director',
  7091. 'ccxml' => 'application/ccxml+xml',
  7092. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  7093. 'cdf' => 'application/x-netcdf',
  7094. 'cdkey' => 'application/vnd.mediastation.cdkey',
  7095. 'cdmia' => 'application/cdmi-capability',
  7096. 'cdmic' => 'application/cdmi-container',
  7097. 'cdmid' => 'application/cdmi-domain',
  7098. 'cdmio' => 'application/cdmi-object',
  7099. 'cdmiq' => 'application/cdmi-queue',
  7100. 'cdx' => 'chemical/x-cdx',
  7101. 'cdxml' => 'application/vnd.chemdraw+xml',
  7102. 'cdy' => 'application/vnd.cinderella',
  7103. 'cer' => 'application/pkix-cert',
  7104. 'cfs' => 'application/x-cfs-compressed',
  7105. 'cgm' => 'image/cgm',
  7106. 'chat' => 'application/x-chat',
  7107. 'chm' => 'application/vnd.ms-htmlhelp',
  7108. 'chrt' => 'application/vnd.kde.kchart',
  7109. 'cif' => 'chemical/x-cif',
  7110. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  7111. 'cil' => 'application/vnd.ms-artgalry',
  7112. 'cla' => 'application/vnd.claymore',
  7113. 'class' => 'application/java-vm',
  7114. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  7115. 'clkp' => 'application/vnd.crick.clicker.palette',
  7116. 'clkt' => 'application/vnd.crick.clicker.template',
  7117. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  7118. 'clkx' => 'application/vnd.crick.clicker',
  7119. 'clp' => 'application/x-msclip',
  7120. 'cmc' => 'application/vnd.cosmocaller',
  7121. 'cmdf' => 'chemical/x-cmdf',
  7122. 'cml' => 'chemical/x-cml',
  7123. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  7124. 'cmx' => 'image/x-cmx',
  7125. 'cod' => 'application/vnd.rim.cod',
  7126. 'com' => 'application/x-msdownload',
  7127. 'conf' => 'text/plain',
  7128. 'cpio' => 'application/x-cpio',
  7129. 'cpp' => 'text/x-c',
  7130. 'cpt' => 'application/mac-compactpro',
  7131. 'crd' => 'application/x-mscardfile',
  7132. 'crl' => 'application/pkix-crl',
  7133. 'crt' => 'application/x-x509-ca-cert',
  7134. 'cryptonote' => 'application/vnd.rig.cryptonote',
  7135. 'csh' => 'application/x-csh',
  7136. 'csml' => 'chemical/x-csml',
  7137. 'csp' => 'application/vnd.commonspace',
  7138. 'css' => 'text/css',
  7139. 'cst' => 'application/x-director',
  7140. 'csv' => 'text/csv',
  7141. 'cu' => 'application/cu-seeme',
  7142. 'curl' => 'text/vnd.curl',
  7143. 'cww' => 'application/prs.cww',
  7144. 'cxt' => 'application/x-director',
  7145. 'cxx' => 'text/x-c',
  7146. 'dae' => 'model/vnd.collada+xml',
  7147. 'daf' => 'application/vnd.mobius.daf',
  7148. 'dart' => 'application/vnd.dart',
  7149. 'dataless' => 'application/vnd.fdsn.seed',
  7150. 'davmount' => 'application/davmount+xml',
  7151. 'dbk' => 'application/docbook+xml',
  7152. 'dcr' => 'application/x-director',
  7153. 'dcurl' => 'text/vnd.curl.dcurl',
  7154. 'dd2' => 'application/vnd.oma.dd2+xml',
  7155. 'ddd' => 'application/vnd.fujixerox.ddd',
  7156. 'deb' => 'application/x-debian-package',
  7157. 'def' => 'text/plain',
  7158. 'deploy' => 'application/octet-stream',
  7159. 'der' => 'application/x-x509-ca-cert',
  7160. 'dfac' => 'application/vnd.dreamfactory',
  7161. 'dgc' => 'application/x-dgc-compressed',
  7162. 'dic' => 'text/x-c',
  7163. 'dir' => 'application/x-director',
  7164. 'dis' => 'application/vnd.mobius.dis',
  7165. 'dist' => 'application/octet-stream',
  7166. 'distz' => 'application/octet-stream',
  7167. 'djv' => 'image/vnd.djvu',
  7168. 'djvu' => 'image/vnd.djvu',
  7169. 'dll' => 'application/x-msdownload',
  7170. 'dmg' => 'application/x-apple-diskimage',
  7171. 'dmp' => 'application/vnd.tcpdump.pcap',
  7172. 'dms' => 'application/octet-stream',
  7173. 'dna' => 'application/vnd.dna',
  7174. 'doc' => 'application/msword',
  7175. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  7176. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  7177. 'dot' => 'application/msword',
  7178. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  7179. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  7180. 'dp' => 'application/vnd.osgi.dp',
  7181. 'dpg' => 'application/vnd.dpgraph',
  7182. 'dra' => 'audio/vnd.dra',
  7183. 'dsc' => 'text/prs.lines.tag',
  7184. 'dssc' => 'application/dssc+der',
  7185. 'dtb' => 'application/x-dtbook+xml',
  7186. 'dtd' => 'application/xml-dtd',
  7187. 'dts' => 'audio/vnd.dts',
  7188. 'dtshd' => 'audio/vnd.dts.hd',
  7189. 'dump' => 'application/octet-stream',
  7190. 'dvb' => 'video/vnd.dvb.file',
  7191. 'dvi' => 'application/x-dvi',
  7192. 'dwf' => 'model/vnd.dwf',
  7193. 'dwg' => 'image/vnd.dwg',
  7194. 'dxf' => 'image/vnd.dxf',
  7195. 'dxp' => 'application/vnd.spotfire.dxp',
  7196. 'dxr' => 'application/x-director',
  7197. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  7198. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  7199. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  7200. 'ecma' => 'application/ecmascript',
  7201. 'edm' => 'application/vnd.novadigm.edm',
  7202. 'edx' => 'application/vnd.novadigm.edx',
  7203. 'efif' => 'application/vnd.picsel',
  7204. 'ei6' => 'application/vnd.pg.osasli',
  7205. 'elc' => 'application/octet-stream',
  7206. 'emf' => 'application/x-msmetafile',
  7207. 'eml' => 'message/rfc822',
  7208. 'emma' => 'application/emma+xml',
  7209. 'emz' => 'application/x-msmetafile',
  7210. 'eol' => 'audio/vnd.digital-winds',
  7211. 'eot' => 'application/vnd.ms-fontobject',
  7212. 'eps' => 'application/postscript',
  7213. 'epub' => 'application/epub+zip',
  7214. 'es3' => 'application/vnd.eszigno3+xml',
  7215. 'esa' => 'application/vnd.osgi.subsystem',
  7216. 'esf' => 'application/vnd.epson.esf',
  7217. 'et3' => 'application/vnd.eszigno3+xml',
  7218. 'etx' => 'text/x-setext',
  7219. 'eva' => 'application/x-eva',
  7220. 'evy' => 'application/x-envoy',
  7221. 'exe' => 'application/x-msdownload',
  7222. 'exi' => 'application/exi',
  7223. 'ext' => 'application/vnd.novadigm.ext',
  7224. 'ez' => 'application/andrew-inset',
  7225. 'ez2' => 'application/vnd.ezpix-album',
  7226. 'ez3' => 'application/vnd.ezpix-package',
  7227. 'f' => 'text/x-fortran',
  7228. 'f4v' => 'video/x-f4v',
  7229. 'f77' => 'text/x-fortran',
  7230. 'f90' => 'text/x-fortran',
  7231. 'fbs' => 'image/vnd.fastbidsheet',
  7232. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  7233. 'fcs' => 'application/vnd.isac.fcs',
  7234. 'fdf' => 'application/vnd.fdf',
  7235. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  7236. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  7237. 'fgd' => 'application/x-director',
  7238. 'fh' => 'image/x-freehand',
  7239. 'fh4' => 'image/x-freehand',
  7240. 'fh5' => 'image/x-freehand',
  7241. 'fh7' => 'image/x-freehand',
  7242. 'fhc' => 'image/x-freehand',
  7243. 'fig' => 'application/x-xfig',
  7244. 'flac' => 'audio/x-flac',
  7245. 'fli' => 'video/x-fli',
  7246. 'flo' => 'application/vnd.micrografx.flo',
  7247. 'flv' => 'video/x-flv',
  7248. 'flw' => 'application/vnd.kde.kivio',
  7249. 'flx' => 'text/vnd.fmi.flexstor',
  7250. 'fly' => 'text/vnd.fly',
  7251. 'fm' => 'application/vnd.framemaker',
  7252. 'fnc' => 'application/vnd.frogans.fnc',
  7253. 'for' => 'text/x-fortran',
  7254. 'fpx' => 'image/vnd.fpx',
  7255. 'frame' => 'application/vnd.framemaker',
  7256. 'fsc' => 'application/vnd.fsc.weblaunch',
  7257. 'fst' => 'image/vnd.fst',
  7258. 'ftc' => 'application/vnd.fluxtime.clip',
  7259. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  7260. 'fvt' => 'video/vnd.fvt',
  7261. 'fxp' => 'application/vnd.adobe.fxp',
  7262. 'fxpl' => 'application/vnd.adobe.fxp',
  7263. 'fzs' => 'application/vnd.fuzzysheet',
  7264. 'g2w' => 'application/vnd.geoplan',
  7265. 'g3' => 'image/g3fax',
  7266. 'g3w' => 'application/vnd.geospace',
  7267. 'gac' => 'application/vnd.groove-account',
  7268. 'gam' => 'application/x-tads',
  7269. 'gbr' => 'application/rpki-ghostbusters',
  7270. 'gca' => 'application/x-gca-compressed',
  7271. 'gdl' => 'model/vnd.gdl',
  7272. 'geo' => 'application/vnd.dynageo',
  7273. 'gex' => 'application/vnd.geometry-explorer',
  7274. 'ggb' => 'application/vnd.geogebra.file',
  7275. 'ggt' => 'application/vnd.geogebra.tool',
  7276. 'ghf' => 'application/vnd.groove-help',
  7277. 'gif' => 'image/gif',
  7278. 'gim' => 'application/vnd.groove-identity-message',
  7279. 'gml' => 'application/gml+xml',
  7280. 'gmx' => 'application/vnd.gmx',
  7281. 'gnumeric' => 'application/x-gnumeric',
  7282. 'gph' => 'application/vnd.flographit',
  7283. 'gpx' => 'application/gpx+xml',
  7284. 'gqf' => 'application/vnd.grafeq',
  7285. 'gqs' => 'application/vnd.grafeq',
  7286. 'gram' => 'application/srgs',
  7287. 'gramps' => 'application/x-gramps-xml',
  7288. 'gre' => 'application/vnd.geometry-explorer',
  7289. 'grv' => 'application/vnd.groove-injector',
  7290. 'grxml' => 'application/srgs+xml',
  7291. 'gsf' => 'application/x-font-ghostscript',
  7292. 'gtar' => 'application/x-gtar',
  7293. 'gtm' => 'application/vnd.groove-tool-message',
  7294. 'gtw' => 'model/vnd.gtw',
  7295. 'gv' => 'text/vnd.graphviz',
  7296. 'gxf' => 'application/gxf',
  7297. 'gxt' => 'application/vnd.geonext',
  7298. 'h' => 'text/x-c',
  7299. 'h261' => 'video/h261',
  7300. 'h263' => 'video/h263',
  7301. 'h264' => 'video/h264',
  7302. 'hal' => 'application/vnd.hal+xml',
  7303. 'hbci' => 'application/vnd.hbci',
  7304. 'hdf' => 'application/x-hdf',
  7305. 'hh' => 'text/x-c',
  7306. 'hlp' => 'application/winhlp',
  7307. 'hpgl' => 'application/vnd.hp-hpgl',
  7308. 'hpid' => 'application/vnd.hp-hpid',
  7309. 'hps' => 'application/vnd.hp-hps',
  7310. 'hqx' => 'application/mac-binhex40',
  7311. 'htke' => 'application/vnd.kenameaapp',
  7312. 'htm' => 'text/html',
  7313. 'html' => 'text/html',
  7314. 'hvd' => 'application/vnd.yamaha.hv-dic',
  7315. 'hvp' => 'application/vnd.yamaha.hv-voice',
  7316. 'hvs' => 'application/vnd.yamaha.hv-script',
  7317. 'i2g' => 'application/vnd.intergeo',
  7318. 'icc' => 'application/vnd.iccprofile',
  7319. 'ice' => 'x-conference/x-cooltalk',
  7320. 'icm' => 'application/vnd.iccprofile',
  7321. 'ico' => 'image/x-icon',
  7322. 'ics' => 'text/calendar',
  7323. 'ief' => 'image/ief',
  7324. 'ifb' => 'text/calendar',
  7325. 'ifm' => 'application/vnd.shana.informed.formdata',
  7326. 'iges' => 'model/iges',
  7327. 'igl' => 'application/vnd.igloader',
  7328. 'igm' => 'application/vnd.insors.igm',
  7329. 'igs' => 'model/iges',
  7330. 'igx' => 'application/vnd.micrografx.igx',
  7331. 'iif' => 'application/vnd.shana.informed.interchange',
  7332. 'imp' => 'application/vnd.accpac.simply.imp',
  7333. 'ims' => 'application/vnd.ms-ims',
  7334. 'in' => 'text/plain',
  7335. 'ink' => 'application/inkml+xml',
  7336. 'inkml' => 'application/inkml+xml',
  7337. 'install' => 'application/x-install-instructions',
  7338. 'iota' => 'application/vnd.astraea-software.iota',
  7339. 'ipfix' => 'application/ipfix',
  7340. 'ipk' => 'application/vnd.shana.informed.package',
  7341. 'irm' => 'application/vnd.ibm.rights-management',
  7342. 'irp' => 'application/vnd.irepository.package+xml',
  7343. 'iso' => 'application/x-iso9660-image',
  7344. 'itp' => 'application/vnd.shana.informed.formtemplate',
  7345. 'ivp' => 'application/vnd.immervision-ivp',
  7346. 'ivu' => 'application/vnd.immervision-ivu',
  7347. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  7348. 'jam' => 'application/vnd.jam',
  7349. 'jar' => 'application/java-archive',
  7350. 'java' => 'text/x-java-source',
  7351. 'jisp' => 'application/vnd.jisp',
  7352. 'jlt' => 'application/vnd.hp-jlyt',
  7353. 'jnlp' => 'application/x-java-jnlp-file',
  7354. 'joda' => 'application/vnd.joost.joda-archive',
  7355. 'jpe' => 'image/jpeg',
  7356. 'jpeg' => 'image/jpeg',
  7357. 'jpg' => 'image/jpeg',
  7358. 'jpgm' => 'video/jpm',
  7359. 'jpgv' => 'video/jpeg',
  7360. 'jpm' => 'video/jpm',
  7361. 'js' => 'application/javascript',
  7362. 'json' => 'application/json',
  7363. 'jsonml' => 'application/jsonml+json',
  7364. 'kar' => 'audio/midi',
  7365. 'karbon' => 'application/vnd.kde.karbon',
  7366. 'kfo' => 'application/vnd.kde.kformula',
  7367. 'kia' => 'application/vnd.kidspiration',
  7368. 'kml' => 'application/vnd.google-earth.kml+xml',
  7369. 'kmz' => 'application/vnd.google-earth.kmz',
  7370. 'kne' => 'application/vnd.kinar',
  7371. 'knp' => 'application/vnd.kinar',
  7372. 'kon' => 'application/vnd.kde.kontour',
  7373. 'kpr' => 'application/vnd.kde.kpresenter',
  7374. 'kpt' => 'application/vnd.kde.kpresenter',
  7375. 'kpxx' => 'application/vnd.ds-keypoint',
  7376. 'ksp' => 'application/vnd.kde.kspread',
  7377. 'ktr' => 'application/vnd.kahootz',
  7378. 'ktx' => 'image/ktx',
  7379. 'ktz' => 'application/vnd.kahootz',
  7380. 'kwd' => 'application/vnd.kde.kword',
  7381. 'kwt' => 'application/vnd.kde.kword',
  7382. 'lasxml' => 'application/vnd.las.las+xml',
  7383. 'latex' => 'application/x-latex',
  7384. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  7385. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  7386. 'les' => 'application/vnd.hhe.lesson-player',
  7387. 'lha' => 'application/x-lzh-compressed',
  7388. 'link66' => 'application/vnd.route66.link66+xml',
  7389. 'list' => 'text/plain',
  7390. 'list3820' => 'application/vnd.ibm.modcap',
  7391. 'listafp' => 'application/vnd.ibm.modcap',
  7392. 'lnk' => 'application/x-ms-shortcut',
  7393. 'log' => 'text/plain',
  7394. 'lostxml' => 'application/lost+xml',
  7395. 'lrf' => 'application/octet-stream',
  7396. 'lrm' => 'application/vnd.ms-lrm',
  7397. 'ltf' => 'application/vnd.frogans.ltf',
  7398. 'lvp' => 'audio/vnd.lucent.voice',
  7399. 'lwp' => 'application/vnd.lotus-wordpro',
  7400. 'lzh' => 'application/x-lzh-compressed',
  7401. 'm13' => 'application/x-msmediaview',
  7402. 'm14' => 'application/x-msmediaview',
  7403. 'm1v' => 'video/mpeg',
  7404. 'm21' => 'application/mp21',
  7405. 'm2a' => 'audio/mpeg',
  7406. 'm2v' => 'video/mpeg',
  7407. 'm3a' => 'audio/mpeg',
  7408. 'm3u' => 'audio/x-mpegurl',
  7409. 'm3u8' => 'application/vnd.apple.mpegurl',
  7410. 'm4a' => 'audio/mp4',
  7411. 'm4u' => 'video/vnd.mpegurl',
  7412. 'm4v' => 'video/x-m4v',
  7413. 'ma' => 'application/mathematica',
  7414. 'mads' => 'application/mads+xml',
  7415. 'mag' => 'application/vnd.ecowin.chart',
  7416. 'maker' => 'application/vnd.framemaker',
  7417. 'man' => 'text/troff',
  7418. 'mar' => 'application/octet-stream',
  7419. 'mathml' => 'application/mathml+xml',
  7420. 'mb' => 'application/mathematica',
  7421. 'mbk' => 'application/vnd.mobius.mbk',
  7422. 'mbox' => 'application/mbox',
  7423. 'mc1' => 'application/vnd.medcalcdata',
  7424. 'mcd' => 'application/vnd.mcd',
  7425. 'mcurl' => 'text/vnd.curl.mcurl',
  7426. 'mdb' => 'application/x-msaccess',
  7427. 'mdi' => 'image/vnd.ms-modi',
  7428. 'me' => 'text/troff',
  7429. 'mesh' => 'model/mesh',
  7430. 'meta4' => 'application/metalink4+xml',
  7431. 'metalink' => 'application/metalink+xml',
  7432. 'mets' => 'application/mets+xml',
  7433. 'mfm' => 'application/vnd.mfmp',
  7434. 'mft' => 'application/rpki-manifest',
  7435. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  7436. 'mgz' => 'application/vnd.proteus.magazine',
  7437. 'mid' => 'audio/midi',
  7438. 'midi' => 'audio/midi',
  7439. 'mie' => 'application/x-mie',
  7440. 'mif' => 'application/vnd.mif',
  7441. 'mime' => 'message/rfc822',
  7442. 'mj2' => 'video/mj2',
  7443. 'mjp2' => 'video/mj2',
  7444. 'mk3d' => 'video/x-matroska',
  7445. 'mka' => 'audio/x-matroska',
  7446. 'mks' => 'video/x-matroska',
  7447. 'mkv' => 'video/x-matroska',
  7448. 'mlp' => 'application/vnd.dolby.mlp',
  7449. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  7450. 'mmf' => 'application/vnd.smaf',
  7451. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  7452. 'mng' => 'video/x-mng',
  7453. 'mny' => 'application/x-msmoney',
  7454. 'mobi' => 'application/x-mobipocket-ebook',
  7455. 'mods' => 'application/mods+xml',
  7456. 'mov' => 'video/quicktime',
  7457. 'movie' => 'video/x-sgi-movie',
  7458. 'mp2' => 'audio/mpeg',
  7459. 'mp21' => 'application/mp21',
  7460. 'mp2a' => 'audio/mpeg',
  7461. 'mp3' => 'audio/mpeg',
  7462. 'mp4' => 'video/mp4',
  7463. 'mp4a' => 'audio/mp4',
  7464. 'mp4s' => 'application/mp4',
  7465. 'mp4v' => 'video/mp4',
  7466. 'mpc' => 'application/vnd.mophun.certificate',
  7467. 'mpe' => 'video/mpeg',
  7468. 'mpeg' => 'video/mpeg',
  7469. 'mpg' => 'video/mpeg',
  7470. 'mpg4' => 'video/mp4',
  7471. 'mpga' => 'audio/mpeg',
  7472. 'mpkg' => 'application/vnd.apple.installer+xml',
  7473. 'mpm' => 'application/vnd.blueice.multipass',
  7474. 'mpn' => 'application/vnd.mophun.application',
  7475. 'mpp' => 'application/vnd.ms-project',
  7476. 'mpt' => 'application/vnd.ms-project',
  7477. 'mpy' => 'application/vnd.ibm.minipay',
  7478. 'mqy' => 'application/vnd.mobius.mqy',
  7479. 'mrc' => 'application/marc',
  7480. 'mrcx' => 'application/marcxml+xml',
  7481. 'ms' => 'text/troff',
  7482. 'mscml' => 'application/mediaservercontrol+xml',
  7483. 'mseed' => 'application/vnd.fdsn.mseed',
  7484. 'mseq' => 'application/vnd.mseq',
  7485. 'msf' => 'application/vnd.epson.msf',
  7486. 'msh' => 'model/mesh',
  7487. 'msi' => 'application/x-msdownload',
  7488. 'msl' => 'application/vnd.mobius.msl',
  7489. 'msty' => 'application/vnd.muvee.style',
  7490. 'mts' => 'model/vnd.mts',
  7491. 'mus' => 'application/vnd.musician',
  7492. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  7493. 'mvb' => 'application/x-msmediaview',
  7494. 'mwf' => 'application/vnd.mfer',
  7495. 'mxf' => 'application/mxf',
  7496. 'mxl' => 'application/vnd.recordare.musicxml',
  7497. 'mxml' => 'application/xv+xml',
  7498. 'mxs' => 'application/vnd.triscape.mxs',
  7499. 'mxu' => 'video/vnd.mpegurl',
  7500. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  7501. 'n3' => 'text/n3',
  7502. 'nb' => 'application/mathematica',
  7503. 'nbp' => 'application/vnd.wolfram.player',
  7504. 'nc' => 'application/x-netcdf',
  7505. 'ncx' => 'application/x-dtbncx+xml',
  7506. 'nfo' => 'text/x-nfo',
  7507. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  7508. 'nitf' => 'application/vnd.nitf',
  7509. 'nlu' => 'application/vnd.neurolanguage.nlu',
  7510. 'nml' => 'application/vnd.enliven',
  7511. 'nnd' => 'application/vnd.noblenet-directory',
  7512. 'nns' => 'application/vnd.noblenet-sealer',
  7513. 'nnw' => 'application/vnd.noblenet-web',
  7514. 'npx' => 'image/vnd.net-fpx',
  7515. 'nsc' => 'application/x-conference',
  7516. 'nsf' => 'application/vnd.lotus-notes',
  7517. 'ntf' => 'application/vnd.nitf',
  7518. 'nzb' => 'application/x-nzb',
  7519. 'oa2' => 'application/vnd.fujitsu.oasys2',
  7520. 'oa3' => 'application/vnd.fujitsu.oasys3',
  7521. 'oas' => 'application/vnd.fujitsu.oasys',
  7522. 'obd' => 'application/x-msbinder',
  7523. 'obj' => 'application/x-tgif',
  7524. 'oda' => 'application/oda',
  7525. 'odb' => 'application/vnd.oasis.opendocument.database',
  7526. 'odc' => 'application/vnd.oasis.opendocument.chart',
  7527. 'odf' => 'application/vnd.oasis.opendocument.formula',
  7528. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  7529. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  7530. 'odi' => 'application/vnd.oasis.opendocument.image',
  7531. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  7532. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  7533. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  7534. 'odt' => 'application/vnd.oasis.opendocument.text',
  7535. 'oga' => 'audio/ogg',
  7536. 'ogg' => 'audio/ogg',
  7537. 'ogv' => 'video/ogg',
  7538. 'ogx' => 'application/ogg',
  7539. 'omdoc' => 'application/omdoc+xml',
  7540. 'onepkg' => 'application/onenote',
  7541. 'onetmp' => 'application/onenote',
  7542. 'onetoc' => 'application/onenote',
  7543. 'onetoc2' => 'application/onenote',
  7544. 'opf' => 'application/oebps-package+xml',
  7545. 'opml' => 'text/x-opml',
  7546. 'oprc' => 'application/vnd.palm',
  7547. 'org' => 'application/vnd.lotus-organizer',
  7548. 'osf' => 'application/vnd.yamaha.openscoreformat',
  7549. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  7550. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  7551. 'otf' => 'application/x-font-otf',
  7552. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  7553. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  7554. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  7555. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  7556. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  7557. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  7558. 'oxps' => 'application/oxps',
  7559. 'oxt' => 'application/vnd.openofficeorg.extension',
  7560. 'p' => 'text/x-pascal',
  7561. 'p10' => 'application/pkcs10',
  7562. 'p12' => 'application/x-pkcs12',
  7563. 'p7b' => 'application/x-pkcs7-certificates',
  7564. 'p7c' => 'application/pkcs7-mime',
  7565. 'p7m' => 'application/pkcs7-mime',
  7566. 'p7r' => 'application/x-pkcs7-certreqresp',
  7567. 'p7s' => 'application/pkcs7-signature',
  7568. 'p8' => 'application/pkcs8',
  7569. 'pas' => 'text/x-pascal',
  7570. 'paw' => 'application/vnd.pawaafile',
  7571. 'pbd' => 'application/vnd.powerbuilder6',
  7572. 'pbm' => 'image/x-portable-bitmap',
  7573. 'pcap' => 'application/vnd.tcpdump.pcap',
  7574. 'pcf' => 'application/x-font-pcf',
  7575. 'pcl' => 'application/vnd.hp-pcl',
  7576. 'pclxl' => 'application/vnd.hp-pclxl',
  7577. 'pct' => 'image/x-pict',
  7578. 'pcurl' => 'application/vnd.curl.pcurl',
  7579. 'pcx' => 'image/x-pcx',
  7580. 'pdb' => 'application/vnd.palm',
  7581. 'pdf' => 'application/pdf',
  7582. 'pfa' => 'application/x-font-type1',
  7583. 'pfb' => 'application/x-font-type1',
  7584. 'pfm' => 'application/x-font-type1',
  7585. 'pfr' => 'application/font-tdpfr',
  7586. 'pfx' => 'application/x-pkcs12',
  7587. 'pgm' => 'image/x-portable-graymap',
  7588. 'pgn' => 'application/x-chess-pgn',
  7589. 'pgp' => 'application/pgp-encrypted',
  7590. 'pic' => 'image/x-pict',
  7591. 'pkg' => 'application/octet-stream',
  7592. 'pki' => 'application/pkixcmp',
  7593. 'pkipath' => 'application/pkix-pkipath',
  7594. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  7595. 'plc' => 'application/vnd.mobius.plc',
  7596. 'plf' => 'application/vnd.pocketlearn',
  7597. 'pls' => 'application/pls+xml',
  7598. 'pml' => 'application/vnd.ctc-posml',
  7599. 'png' => 'image/png',
  7600. 'pnm' => 'image/x-portable-anymap',
  7601. 'portpkg' => 'application/vnd.macports.portpkg',
  7602. 'pot' => 'application/vnd.ms-powerpoint',
  7603. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  7604. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  7605. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  7606. 'ppd' => 'application/vnd.cups-ppd',
  7607. 'ppm' => 'image/x-portable-pixmap',
  7608. 'pps' => 'application/vnd.ms-powerpoint',
  7609. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  7610. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  7611. 'ppt' => 'application/vnd.ms-powerpoint',
  7612. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  7613. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  7614. 'pqa' => 'application/vnd.palm',
  7615. 'prc' => 'application/x-mobipocket-ebook',
  7616. 'pre' => 'application/vnd.lotus-freelance',
  7617. 'prf' => 'application/pics-rules',
  7618. 'ps' => 'application/postscript',
  7619. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  7620. 'psd' => 'image/vnd.adobe.photoshop',
  7621. 'psf' => 'application/x-font-linux-psf',
  7622. 'pskcxml' => 'application/pskc+xml',
  7623. 'ptid' => 'application/vnd.pvi.ptid1',
  7624. 'pub' => 'application/x-mspublisher',
  7625. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  7626. 'pwn' => 'application/vnd.3m.post-it-notes',
  7627. 'pya' => 'audio/vnd.ms-playready.media.pya',
  7628. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  7629. 'qam' => 'application/vnd.epson.quickanime',
  7630. 'qbo' => 'application/vnd.intu.qbo',
  7631. 'qfx' => 'application/vnd.intu.qfx',
  7632. 'qps' => 'application/vnd.publishare-delta-tree',
  7633. 'qt' => 'video/quicktime',
  7634. 'qwd' => 'application/vnd.quark.quarkxpress',
  7635. 'qwt' => 'application/vnd.quark.quarkxpress',
  7636. 'qxb' => 'application/vnd.quark.quarkxpress',
  7637. 'qxd' => 'application/vnd.quark.quarkxpress',
  7638. 'qxl' => 'application/vnd.quark.quarkxpress',
  7639. 'qxt' => 'application/vnd.quark.quarkxpress',
  7640. 'ra' => 'audio/x-pn-realaudio',
  7641. 'ram' => 'audio/x-pn-realaudio',
  7642. 'rar' => 'application/x-rar-compressed',
  7643. 'ras' => 'image/x-cmu-raster',
  7644. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  7645. 'rdf' => 'application/rdf+xml',
  7646. 'rdz' => 'application/vnd.data-vision.rdz',
  7647. 'rep' => 'application/vnd.businessobjects',
  7648. 'res' => 'application/x-dtbresource+xml',
  7649. 'rgb' => 'image/x-rgb',
  7650. 'rif' => 'application/reginfo+xml',
  7651. 'rip' => 'audio/vnd.rip',
  7652. 'ris' => 'application/x-research-info-systems',
  7653. 'rl' => 'application/resource-lists+xml',
  7654. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  7655. 'rld' => 'application/resource-lists-diff+xml',
  7656. 'rm' => 'application/vnd.rn-realmedia',
  7657. 'rmi' => 'audio/midi',
  7658. 'rmp' => 'audio/x-pn-realaudio-plugin',
  7659. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  7660. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  7661. 'rnc' => 'application/relax-ng-compact-syntax',
  7662. 'roa' => 'application/rpki-roa',
  7663. 'roff' => 'text/troff',
  7664. 'rp9' => 'application/vnd.cloanto.rp9',
  7665. 'rpss' => 'application/vnd.nokia.radio-presets',
  7666. 'rpst' => 'application/vnd.nokia.radio-preset',
  7667. 'rq' => 'application/sparql-query',
  7668. 'rs' => 'application/rls-services+xml',
  7669. 'rsd' => 'application/rsd+xml',
  7670. 'rss' => 'application/rss+xml',
  7671. 'rtf' => 'application/rtf',
  7672. 'rtx' => 'text/richtext',
  7673. 's' => 'text/x-asm',
  7674. 's3m' => 'audio/s3m',
  7675. 'saf' => 'application/vnd.yamaha.smaf-audio',
  7676. 'sbml' => 'application/sbml+xml',
  7677. 'sc' => 'application/vnd.ibm.secure-container',
  7678. 'scd' => 'application/x-msschedule',
  7679. 'scm' => 'application/vnd.lotus-screencam',
  7680. 'scq' => 'application/scvp-cv-request',
  7681. 'scs' => 'application/scvp-cv-response',
  7682. 'scurl' => 'text/vnd.curl.scurl',
  7683. 'sda' => 'application/vnd.stardivision.draw',
  7684. 'sdc' => 'application/vnd.stardivision.calc',
  7685. 'sdd' => 'application/vnd.stardivision.impress',
  7686. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  7687. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  7688. 'sdp' => 'application/sdp',
  7689. 'sdw' => 'application/vnd.stardivision.writer',
  7690. 'see' => 'application/vnd.seemail',
  7691. 'seed' => 'application/vnd.fdsn.seed',
  7692. 'sema' => 'application/vnd.sema',
  7693. 'semd' => 'application/vnd.semd',
  7694. 'semf' => 'application/vnd.semf',
  7695. 'ser' => 'application/java-serialized-object',
  7696. 'setpay' => 'application/set-payment-initiation',
  7697. 'setreg' => 'application/set-registration-initiation',
  7698. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  7699. 'sfs' => 'application/vnd.spotfire.sfs',
  7700. 'sfv' => 'text/x-sfv',
  7701. 'sgi' => 'image/sgi',
  7702. 'sgl' => 'application/vnd.stardivision.writer-global',
  7703. 'sgm' => 'text/sgml',
  7704. 'sgml' => 'text/sgml',
  7705. 'sh' => 'application/x-sh',
  7706. 'shar' => 'application/x-shar',
  7707. 'shf' => 'application/shf+xml',
  7708. 'sid' => 'image/x-mrsid-image',
  7709. 'sig' => 'application/pgp-signature',
  7710. 'sil' => 'audio/silk',
  7711. 'silo' => 'model/mesh',
  7712. 'sis' => 'application/vnd.symbian.install',
  7713. 'sisx' => 'application/vnd.symbian.install',
  7714. 'sit' => 'application/x-stuffit',
  7715. 'sitx' => 'application/x-stuffitx',
  7716. 'skd' => 'application/vnd.koan',
  7717. 'skm' => 'application/vnd.koan',
  7718. 'skp' => 'application/vnd.koan',
  7719. 'skt' => 'application/vnd.koan',
  7720. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  7721. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  7722. 'slt' => 'application/vnd.epson.salt',
  7723. 'sm' => 'application/vnd.stepmania.stepchart',
  7724. 'smf' => 'application/vnd.stardivision.math',
  7725. 'smi' => 'application/smil+xml',
  7726. 'smil' => 'application/smil+xml',
  7727. 'smv' => 'video/x-smv',
  7728. 'smzip' => 'application/vnd.stepmania.package',
  7729. 'snd' => 'audio/basic',
  7730. 'snf' => 'application/x-font-snf',
  7731. 'so' => 'application/octet-stream',
  7732. 'spc' => 'application/x-pkcs7-certificates',
  7733. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  7734. 'spl' => 'application/x-futuresplash',
  7735. 'spot' => 'text/vnd.in3d.spot',
  7736. 'spp' => 'application/scvp-vp-response',
  7737. 'spq' => 'application/scvp-vp-request',
  7738. 'spx' => 'audio/ogg',
  7739. 'sql' => 'application/x-sql',
  7740. 'src' => 'application/x-wais-source',
  7741. 'srt' => 'application/x-subrip',
  7742. 'sru' => 'application/sru+xml',
  7743. 'srx' => 'application/sparql-results+xml',
  7744. 'ssdl' => 'application/ssdl+xml',
  7745. 'sse' => 'application/vnd.kodak-descriptor',
  7746. 'ssf' => 'application/vnd.epson.ssf',
  7747. 'ssml' => 'application/ssml+xml',
  7748. 'st' => 'application/vnd.sailingtracker.track',
  7749. 'stc' => 'application/vnd.sun.xml.calc.template',
  7750. 'std' => 'application/vnd.sun.xml.draw.template',
  7751. 'stf' => 'application/vnd.wt.stf',
  7752. 'sti' => 'application/vnd.sun.xml.impress.template',
  7753. 'stk' => 'application/hyperstudio',
  7754. 'stl' => 'application/vnd.ms-pki.stl',
  7755. 'str' => 'application/vnd.pg.format',
  7756. 'stw' => 'application/vnd.sun.xml.writer.template',
  7757. 'sub' => 'image/vnd.dvb.subtitle',
  7758. 'sub' => 'text/vnd.dvb.subtitle',
  7759. 'sus' => 'application/vnd.sus-calendar',
  7760. 'susp' => 'application/vnd.sus-calendar',
  7761. 'sv4cpio' => 'application/x-sv4cpio',
  7762. 'sv4crc' => 'application/x-sv4crc',
  7763. 'svc' => 'application/vnd.dvb.service',
  7764. 'svd' => 'application/vnd.svd',
  7765. 'svg' => 'image/svg+xml',
  7766. 'svgz' => 'image/svg+xml',
  7767. 'swa' => 'application/x-director',
  7768. 'swf' => 'application/x-shockwave-flash',
  7769. 'swi' => 'application/vnd.aristanetworks.swi',
  7770. 'sxc' => 'application/vnd.sun.xml.calc',
  7771. 'sxd' => 'application/vnd.sun.xml.draw',
  7772. 'sxg' => 'application/vnd.sun.xml.writer.global',
  7773. 'sxi' => 'application/vnd.sun.xml.impress',
  7774. 'sxm' => 'application/vnd.sun.xml.math',
  7775. 'sxw' => 'application/vnd.sun.xml.writer',
  7776. 't' => 'text/troff',
  7777. 't3' => 'application/x-t3vm-image',
  7778. 'taglet' => 'application/vnd.mynfc',
  7779. 'tao' => 'application/vnd.tao.intent-module-archive',
  7780. 'tar' => 'application/x-tar',
  7781. 'tcap' => 'application/vnd.3gpp2.tcap',
  7782. 'tcl' => 'application/x-tcl',
  7783. 'teacher' => 'application/vnd.smart.teacher',
  7784. 'tei' => 'application/tei+xml',
  7785. 'teicorpus' => 'application/tei+xml',
  7786. 'tex' => 'application/x-tex',
  7787. 'texi' => 'application/x-texinfo',
  7788. 'texinfo' => 'application/x-texinfo',
  7789. 'text' => 'text/plain',
  7790. 'tfi' => 'application/thraud+xml',
  7791. 'tfm' => 'application/x-tex-tfm',
  7792. 'tga' => 'image/x-tga',
  7793. 'thmx' => 'application/vnd.ms-officetheme',
  7794. 'tif' => 'image/tiff',
  7795. 'tiff' => 'image/tiff',
  7796. 'tmo' => 'application/vnd.tmobile-livetv',
  7797. 'torrent' => 'application/x-bittorrent',
  7798. 'tpl' => 'application/vnd.groove-tool-template',
  7799. 'tpt' => 'application/vnd.trid.tpt',
  7800. 'tr' => 'text/troff',
  7801. 'tra' => 'application/vnd.trueapp',
  7802. 'trm' => 'application/x-msterminal',
  7803. 'tsd' => 'application/timestamped-data',
  7804. 'tsv' => 'text/tab-separated-values',
  7805. 'ttc' => 'application/x-font-ttf',
  7806. 'ttf' => 'application/x-font-ttf',
  7807. 'ttl' => 'text/turtle',
  7808. 'twd' => 'application/vnd.simtech-mindmapper',
  7809. 'twds' => 'application/vnd.simtech-mindmapper',
  7810. 'txd' => 'application/vnd.genomatix.tuxedo',
  7811. 'txf' => 'application/vnd.mobius.txf',
  7812. 'txt' => 'text/plain',
  7813. 'u32' => 'application/x-authorware-bin',
  7814. 'udeb' => 'application/x-debian-package',
  7815. 'ufd' => 'application/vnd.ufdl',
  7816. 'ufdl' => 'application/vnd.ufdl',
  7817. 'ulx' => 'application/x-glulx',
  7818. 'umj' => 'application/vnd.umajin',
  7819. 'unityweb' => 'application/vnd.unity',
  7820. 'uoml' => 'application/vnd.uoml+xml',
  7821. 'uri' => 'text/uri-list',
  7822. 'uris' => 'text/uri-list',
  7823. 'urls' => 'text/uri-list',
  7824. 'ustar' => 'application/x-ustar',
  7825. 'utz' => 'application/vnd.uiq.theme',
  7826. 'uu' => 'text/x-uuencode',
  7827. 'uva' => 'audio/vnd.dece.audio',
  7828. 'uvd' => 'application/vnd.dece.data',
  7829. 'uvf' => 'application/vnd.dece.data',
  7830. 'uvg' => 'image/vnd.dece.graphic',
  7831. 'uvh' => 'video/vnd.dece.hd',
  7832. 'uvi' => 'image/vnd.dece.graphic',
  7833. 'uvm' => 'video/vnd.dece.mobile',
  7834. 'uvp' => 'video/vnd.dece.pd',
  7835. 'uvs' => 'video/vnd.dece.sd',
  7836. 'uvt' => 'application/vnd.dece.ttml+xml',
  7837. 'uvu' => 'video/vnd.uvvu.mp4',
  7838. 'uvv' => 'video/vnd.dece.video',
  7839. 'uvva' => 'audio/vnd.dece.audio',
  7840. 'uvvd' => 'application/vnd.dece.data',
  7841. 'uvvf' => 'application/vnd.dece.data',
  7842. 'uvvg' => 'image/vnd.dece.graphic',
  7843. 'uvvh' => 'video/vnd.dece.hd',
  7844. 'uvvi' => 'image/vnd.dece.graphic',
  7845. 'uvvm' => 'video/vnd.dece.mobile',
  7846. 'uvvp' => 'video/vnd.dece.pd',
  7847. 'uvvs' => 'video/vnd.dece.sd',
  7848. 'uvvt' => 'application/vnd.dece.ttml+xml',
  7849. 'uvvu' => 'video/vnd.uvvu.mp4',
  7850. 'uvvv' => 'video/vnd.dece.video',
  7851. 'uvvx' => 'application/vnd.dece.unspecified',
  7852. 'uvvz' => 'application/vnd.dece.zip',
  7853. 'uvx' => 'application/vnd.dece.unspecified',
  7854. 'uvz' => 'application/vnd.dece.zip',
  7855. 'vcard' => 'text/vcard',
  7856. 'vcd' => 'application/x-cdlink',
  7857. 'vcf' => 'text/x-vcard',
  7858. 'vcg' => 'application/vnd.groove-vcard',
  7859. 'vcs' => 'text/x-vcalendar',
  7860. 'vcx' => 'application/vnd.vcx',
  7861. 'vis' => 'application/vnd.visionary',
  7862. 'viv' => 'video/vnd.vivo',
  7863. 'vob' => 'video/x-ms-vob',
  7864. 'vor' => 'application/vnd.stardivision.writer',
  7865. 'vox' => 'application/x-authorware-bin',
  7866. 'vrml' => 'model/vrml',
  7867. 'vsd' => 'application/vnd.visio',
  7868. 'vsf' => 'application/vnd.vsf',
  7869. 'vss' => 'application/vnd.visio',
  7870. 'vst' => 'application/vnd.visio',
  7871. 'vsw' => 'application/vnd.visio',
  7872. 'vtu' => 'model/vnd.vtu',
  7873. 'vxml' => 'application/voicexml+xml',
  7874. 'w3d' => 'application/x-director',
  7875. 'wad' => 'application/x-doom',
  7876. 'wav' => 'audio/x-wav',
  7877. 'wax' => 'audio/x-ms-wax',
  7878. 'wbmp' => 'image/vnd.wap.wbmp',
  7879. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  7880. 'wbxml' => 'application/vnd.wap.wbxml',
  7881. 'wcm' => 'application/vnd.ms-works',
  7882. 'wdb' => 'application/vnd.ms-works',
  7883. 'wdp' => 'image/vnd.ms-photo',
  7884. 'weba' => 'audio/webm',
  7885. 'webm' => 'video/webm',
  7886. 'webp' => 'image/webp',
  7887. 'wg' => 'application/vnd.pmi.widget',
  7888. 'wgt' => 'application/widget',
  7889. 'wks' => 'application/vnd.ms-works',
  7890. 'wm' => 'video/x-ms-wm',
  7891. 'wma' => 'audio/x-ms-wma',
  7892. 'wmd' => 'application/x-ms-wmd',
  7893. 'wmf' => 'application/x-msmetafile',
  7894. 'wml' => 'text/vnd.wap.wml',
  7895. 'wmlc' => 'application/vnd.wap.wmlc',
  7896. 'wmls' => 'text/vnd.wap.wmlscript',
  7897. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  7898. 'wmv' => 'video/x-ms-wmv',
  7899. 'wmx' => 'video/x-ms-wmx',
  7900. 'wmz' => 'application/x-ms-wmz',
  7901. 'wmz' => 'application/x-msmetafile',
  7902. 'woff' => 'application/font-woff',
  7903. 'wpd' => 'application/vnd.wordperfect',
  7904. 'wpl' => 'application/vnd.ms-wpl',
  7905. 'wps' => 'application/vnd.ms-works',
  7906. 'wqd' => 'application/vnd.wqd',
  7907. 'wri' => 'application/x-mswrite',
  7908. 'wrl' => 'model/vrml',
  7909. 'wsdl' => 'application/wsdl+xml',
  7910. 'wspolicy' => 'application/wspolicy+xml',
  7911. 'wtb' => 'application/vnd.webturbo',
  7912. 'wvx' => 'video/x-ms-wvx',
  7913. 'x32' => 'application/x-authorware-bin',
  7914. 'x3d' => 'model/x3d+xml',
  7915. 'x3db' => 'model/x3d+binary',
  7916. 'x3dbz' => 'model/x3d+binary',
  7917. 'x3dv' => 'model/x3d+vrml',
  7918. 'x3dvz' => 'model/x3d+vrml',
  7919. 'x3dz' => 'model/x3d+xml',
  7920. 'xaml' => 'application/xaml+xml',
  7921. 'xap' => 'application/x-silverlight-app',
  7922. 'xar' => 'application/vnd.xara',
  7923. 'xbap' => 'application/x-ms-xbap',
  7924. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  7925. 'xbm' => 'image/x-xbitmap',
  7926. 'xdf' => 'application/xcap-diff+xml',
  7927. 'xdm' => 'application/vnd.syncml.dm+xml',
  7928. 'xdp' => 'application/vnd.adobe.xdp+xml',
  7929. 'xdssc' => 'application/dssc+xml',
  7930. 'xdw' => 'application/vnd.fujixerox.docuworks',
  7931. 'xenc' => 'application/xenc+xml',
  7932. 'xer' => 'application/patch-ops-error+xml',
  7933. 'xfdf' => 'application/vnd.adobe.xfdf',
  7934. 'xfdl' => 'application/vnd.xfdl',
  7935. 'xht' => 'application/xhtml+xml',
  7936. 'xhtml' => 'application/xhtml+xml',
  7937. 'xhvml' => 'application/xv+xml',
  7938. 'xif' => 'image/vnd.xiff',
  7939. 'xla' => 'application/vnd.ms-excel',
  7940. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  7941. 'xlc' => 'application/vnd.ms-excel',
  7942. 'xlf' => 'application/x-xliff+xml',
  7943. 'xlm' => 'application/vnd.ms-excel',
  7944. 'xls' => 'application/vnd.ms-excel',
  7945. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  7946. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  7947. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  7948. 'xlt' => 'application/vnd.ms-excel',
  7949. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  7950. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  7951. 'xlw' => 'application/vnd.ms-excel',
  7952. 'xm' => 'audio/xm',
  7953. 'xml' => 'application/xml',
  7954. 'xo' => 'application/vnd.olpc-sugar',
  7955. 'xop' => 'application/xop+xml',
  7956. 'xpi' => 'application/x-xpinstall',
  7957. 'xpl' => 'application/xproc+xml',
  7958. 'xpm' => 'image/x-xpixmap',
  7959. 'xpr' => 'application/vnd.is-xpr',
  7960. 'xps' => 'application/vnd.ms-xpsdocument',
  7961. 'xpw' => 'application/vnd.intercon.formnet',
  7962. 'xpx' => 'application/vnd.intercon.formnet',
  7963. 'xsl' => 'application/xml',
  7964. 'xslt' => 'application/xslt+xml',
  7965. 'xsm' => 'application/vnd.syncml+xml',
  7966. 'xspf' => 'application/xspf+xml',
  7967. 'xul' => 'application/vnd.mozilla.xul+xml',
  7968. 'xvm' => 'application/xv+xml',
  7969. 'xvml' => 'application/xv+xml',
  7970. 'xwd' => 'image/x-xwindowdump',
  7971. 'xyz' => 'chemical/x-xyz',
  7972. 'xz' => 'application/x-xz',
  7973. 'yang' => 'application/yang',
  7974. 'yin' => 'application/yin+xml',
  7975. 'z1' => 'application/x-zmachine',
  7976. 'z2' => 'application/x-zmachine',
  7977. 'z3' => 'application/x-zmachine',
  7978. 'z4' => 'application/x-zmachine',
  7979. 'z5' => 'application/x-zmachine',
  7980. 'z6' => 'application/x-zmachine',
  7981. 'z7' => 'application/x-zmachine',
  7982. 'z8' => 'application/x-zmachine',
  7983. 'zaz' => 'application/vnd.zzazz.deck+xml',
  7984. 'zip' => 'application/zip',
  7985. 'zir' => 'application/vnd.zul',
  7986. 'zirz' => 'application/vnd.zul',
  7987. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  7988. );
  7989. }
  7990. // Always run this
  7991. if(strpos($_SERVER['SCRIPT_NAME'], 'check.php') == false){
  7992. dependCheck();
  7993. }