functions.php 346 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.603');
  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. );
  27. asort($homepageOrder);
  28. return $homepageOrder;
  29. }
  30. // Debugging output functions
  31. function debug_out($variable, $die = false) {
  32. $trace = debug_backtrace()[0];
  33. echo "<center><img height='200px' src='images/confused.png'></center>";
  34. echo "<center>Look's like something happened, here are the errors and perhaps how to fix them:</center>";
  35. 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>';
  36. if ($die) { http_response_code(503); die(); }
  37. }
  38. // ==== Auth Plugins START ====
  39. if (function_exists('ldap_connect')) :
  40. // Pass credentials to LDAP backend
  41. function plugin_auth_ldap($username, $password) {
  42. $ldapServers = explode(',',AUTHBACKENDHOST);
  43. foreach($ldapServers as $key => $value) {
  44. // Calculate parts
  45. $digest = parse_url(trim($value));
  46. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  47. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  48. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  49. // Reassign
  50. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  51. }
  52. // returns true or false
  53. $ldap = ldap_connect(implode(' ',$ldapServers));
  54. if(empty(AUTHBACKENDDOMAINFORMAT)){
  55. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  56. writeLog("success", "LDAP authentication success");
  57. return true;
  58. } else {
  59. writeLog("error", "LDAP could not authenticate");
  60. return false;
  61. }
  62. }else{
  63. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  64. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  65. $bind = @ldap_bind($ldap, sprintf(AUTHBACKENDDOMAINFORMAT, $username), $password);
  66. if ($bind) {
  67. writeLog("success", "LDAP authentication success");
  68. return true;
  69. } else {
  70. writeLog("error", "LDPA could not authenticate");
  71. return false;
  72. }
  73. }
  74. writeLog("error", "LDAP could not authenticate");
  75. return false;
  76. }
  77. else :
  78. // Ldap Auth Missing Dependancy
  79. function plugin_auth_ldap_disabled() {
  80. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  81. }
  82. endif;
  83. // Pass credentials to FTP backend
  84. function plugin_auth_ftp($username, $password) {
  85. // Calculate parts
  86. $digest = parse_url(AUTHBACKENDHOST);
  87. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  88. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  89. $port = (isset($digest['port'])?$digest['port']:21);
  90. // Determine Connection Type
  91. if ($scheme == 'ftps') {
  92. $conn_id = ftp_ssl_connect($host, $port, 20);
  93. } elseif ($scheme == 'ftp') {
  94. $conn_id = ftp_connect($host, $port, 20);
  95. } else {
  96. debug_out('Invalid FTP scheme. Use ftp or ftps');
  97. writeLog("error", "invalid FTP scheme");
  98. return false;
  99. }
  100. // Check if valid FTP connection
  101. if ($conn_id) {
  102. // Attempt login
  103. @$login_result = ftp_login($conn_id, $username, $password);
  104. ftp_close($conn_id);
  105. // Return Result
  106. if ($login_result) {
  107. writeLog("success", "$username authenticated");
  108. return true;
  109. } else {
  110. writeLog("error", "$username could not authenticate");
  111. return false;
  112. }
  113. } else {
  114. return false;
  115. }
  116. return false;
  117. }
  118. // Pass credentials to Emby Backend
  119. function plugin_auth_emby_local($username, $password) {
  120. $embyAddress = qualifyURL(EMBYURL);
  121. $headers = array(
  122. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  123. 'Content-Type' => 'application/json',
  124. );
  125. $body = array(
  126. 'Username' => $username,
  127. 'Password' => sha1($password),
  128. 'PasswordMd5' => md5($password),
  129. );
  130. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  131. if (isset($response['content'])) {
  132. $json = json_decode($response['content'], true);
  133. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  134. // Login Success - Now Logout Emby Session As We No Longer Need It
  135. $headers = array(
  136. 'X-Mediabrowser-Token' => $json['AccessToken'],
  137. );
  138. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  139. return true;
  140. }
  141. }
  142. return false;
  143. }
  144. if (function_exists('curl_version')) :
  145. // Authenticate Against Emby Local (first) and Emby Connect
  146. function plugin_auth_emby_all($username, $password) {
  147. $localResult = plugin_auth_emby_local($username, $password);
  148. if ($localResult) {
  149. return $localResult;
  150. } else {
  151. return plugin_auth_emby_connect($username, $password);
  152. }
  153. }
  154. // Authenicate against emby connect
  155. function plugin_auth_emby_connect($username, $password) {
  156. $embyAddress = qualifyURL(EMBYURL);
  157. // Get A User
  158. $connectId = '';
  159. $userIds = json_decode(@file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  160. if (is_array($userIds)) {
  161. foreach ($userIds as $key => $value) { // Scan for this user
  162. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  163. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  164. $connectId = $value['ConnectUserId'];
  165. break;
  166. }
  167. }
  168. }
  169. if ($connectId) {
  170. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  171. $headers = array(
  172. 'Accept'=> 'application/json',
  173. 'Content-Type' => 'application/x-www-form-urlencoded',
  174. );
  175. $body = array(
  176. 'nameOrEmail' => $username,
  177. 'rawpw' => $password,
  178. );
  179. $result = curl_post($connectURL, $body, $headers);
  180. if (isset($result['content'])) {
  181. $json = json_decode($result['content'], true);
  182. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  183. return array(
  184. 'email' => $json['User']['Email'],
  185. 'image' => $json['User']['ImageUrl'],
  186. );
  187. }
  188. }
  189. }
  190. }
  191. return false;
  192. }
  193. // Pass credentials to Plex Backend
  194. function plugin_auth_plex($username, $password) {
  195. // Quick out
  196. $isAdmin = false;
  197. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  198. writeLog("success", "Admin: ".$username." authenticated by plex");
  199. //return true;
  200. $isAdmin = true;
  201. }
  202. //Get User List
  203. $userURL = 'https://plex.tv/pms/friends/all';
  204. $userHeaders = array(
  205. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  206. );
  207. libxml_use_internal_errors(true);
  208. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  209. if (is_array($userXML) || is_object($userXML)) {
  210. $isUser = false;
  211. $usernameLower = strtolower($username);
  212. foreach($userXML AS $child) {
  213. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  214. $isUser = true;
  215. writeLog("success", $usernameLower." was found in plex friends list");
  216. break;
  217. }
  218. }
  219. if ($isUser || $isAdmin) {
  220. //Login User
  221. $connectURL = 'https://plex.tv/users/sign_in.json';
  222. $headers = array(
  223. 'Accept'=> 'application/json',
  224. 'Content-Type' => 'application/x-www-form-urlencoded',
  225. 'X-Plex-Product' => 'Organizr',
  226. 'X-Plex-Version' => '1.0',
  227. 'X-Plex-Client-Identifier' => '01010101-10101010',
  228. );
  229. $body = array(
  230. 'user[login]' => $username,
  231. 'user[password]' => $password,
  232. );
  233. $result = curl_post($connectURL, $body, $headers);
  234. if (isset($result['content'])) {
  235. $json = json_decode($result['content'], true);
  236. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  237. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  238. return array(
  239. 'email' => $json['user']['email'],
  240. 'image' => $json['user']['thumb'],
  241. 'token' => $json['user']['authToken']
  242. );
  243. }
  244. }
  245. }else{
  246. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  247. }
  248. }else{
  249. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  250. }
  251. return false;
  252. }
  253. else :
  254. // Plex Auth Missing Dependancy
  255. function plugin_auth_plex_disabled() {
  256. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  257. }
  258. // Emby Connect Auth Missing Dependancy
  259. function plugin_auth_emby_connect_disabled() {
  260. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  261. }
  262. // Emby Both Auth Missing Dependancy
  263. function plugin_auth_emby_both_disabled() {
  264. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  265. }
  266. endif;
  267. // ==== Auth Plugins END ====
  268. // ==== General Class Definitions START ====
  269. $userLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  270. class setLanguage {
  271. private $language = null;
  272. private $langCode = null;
  273. function __construct($language = false) {
  274. // Default
  275. if (!$language) {
  276. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  277. }
  278. if (!file_exists("lang/{$language}.ini")) {
  279. $language = 'en';
  280. }
  281. $this->langCode = $language;
  282. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  283. if (file_exists("lang/{$language}.cust.ini")) {
  284. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  285. $this->language[$k] = $v;
  286. }
  287. }
  288. }
  289. public function getLang() {
  290. return $this->langCode;
  291. }
  292. public function translate($originalWord) {
  293. $getArg = func_num_args();
  294. if ($getArg > 1) {
  295. $allWords = func_get_args();
  296. array_shift($allWords);
  297. } else {
  298. $allWords = array();
  299. }
  300. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  301. if (!$translatedWord) {
  302. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  303. //echo "WHOA!!!!!!! $originalWord";
  304. }
  305. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  306. return vsprintf($translatedWord, $allWords);
  307. }
  308. }
  309. $language = new setLanguage;
  310. // ==== General Class Definitions END ====
  311. // Direct request to curl if it exists, otherwise handle if not HTTPS
  312. function post_router($url, $data, $headers = array(), $referer='') {
  313. if (function_exists('curl_version')) {
  314. return curl_post($url, $data, $headers, $referer);
  315. } else {
  316. return post_request($url, $data, $headers, $referer);
  317. }
  318. }
  319. if (function_exists('curl_version')) :
  320. // Curl Post
  321. function curl_post($url, $data, $headers = array(), $referer='') {
  322. // Initiate cURL
  323. $curlReq = curl_init($url);
  324. // As post request
  325. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  326. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  327. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  328. if(localURL($url)){
  329. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  330. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  331. }
  332. // Format Data
  333. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  334. case 'application/json':
  335. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  336. break;
  337. case 'application/x-www-form-urlencoded':
  338. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  339. break;
  340. default:
  341. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  342. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  343. }
  344. // Format Headers
  345. $cHeaders = array();
  346. foreach ($headers as $k => $v) {
  347. $cHeaders[] = $k.': '.$v;
  348. }
  349. if (count($cHeaders)) {
  350. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  351. }
  352. // Execute
  353. $result = curl_exec($curlReq);
  354. $httpcode = curl_getinfo($curlReq);
  355. // Close
  356. curl_close($curlReq);
  357. // Return
  358. return array('content'=>$result, 'http_code'=>$httpcode);
  359. }
  360. // Curl Put
  361. function curl_put($url, $data, $headers = array(), $referer='') {
  362. // Initiate cURL
  363. $curlReq = curl_init($url);
  364. // As post request
  365. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "PUT");
  366. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  367. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  368. if(localURL($url)){
  369. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  370. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  371. }
  372. // Format Data
  373. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  374. case 'application/json':
  375. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  376. break;
  377. case 'application/x-www-form-urlencoded':
  378. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  379. break;
  380. default:
  381. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  382. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  383. }
  384. // Format Headers
  385. $cHeaders = array();
  386. foreach ($headers as $k => $v) {
  387. $cHeaders[] = $k.': '.$v;
  388. }
  389. if (count($cHeaders)) {
  390. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  391. }
  392. // Execute
  393. $result = curl_exec($curlReq);
  394. $httpcode = curl_getinfo($curlReq);
  395. // Close
  396. curl_close($curlReq);
  397. // Return
  398. return array('content'=>$result, 'http_code'=>$httpcode);
  399. }
  400. //Curl Get Function
  401. function curl_get($url, $headers = array()) {
  402. // Initiate cURL
  403. $curlReq = curl_init($url);
  404. // As post request
  405. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  406. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  407. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  408. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  409. if(localURL($url)){
  410. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  411. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  412. }
  413. // Format Headers
  414. $cHeaders = array();
  415. foreach ($headers as $k => $v) {
  416. $cHeaders[] = $k.': '.$v;
  417. }
  418. if (count($cHeaders)) {
  419. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  420. }
  421. // Execute
  422. $result = curl_exec($curlReq);
  423. // Close
  424. curl_close($curlReq);
  425. // Return
  426. return $result;
  427. }
  428. //Curl Delete Function
  429. function curl_delete($url, $headers = array()) {
  430. // Initiate cURL
  431. $curlReq = curl_init($url);
  432. // As post request
  433. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  434. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  435. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  436. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  437. if(localURL($url)){
  438. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  439. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  440. }
  441. // Format Headers
  442. $cHeaders = array();
  443. foreach ($headers as $k => $v) {
  444. $cHeaders[] = $k.': '.$v;
  445. }
  446. if (count($cHeaders)) {
  447. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  448. }
  449. // Execute
  450. $result = curl_exec($curlReq);
  451. $httpcode = curl_getinfo($curlReq);
  452. // Close
  453. curl_close($curlReq);
  454. // Return
  455. return array('content'=>$result, 'http_code'=>$httpcode);
  456. }
  457. endif;
  458. //Case-Insensitive Function
  459. function in_arrayi($needle, $haystack) {
  460. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  461. }
  462. // HTTP post request (Removes need for curl, probably useless)
  463. function post_request($url, $data, $headers = array(), $referer='') {
  464. // Adapted from http://stackoverflow.com/a/28387011/6810513
  465. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  466. if (isset($headers['Content-Type'])) {
  467. switch ($headers['Content-Type']) {
  468. case 'application/json':
  469. $data = json_encode($data);
  470. break;
  471. case 'application/x-www-form-urlencoded':
  472. $data = http_build_query($data);
  473. break;
  474. }
  475. } else {
  476. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  477. $data = http_build_query($data);
  478. }
  479. // parse the given URL
  480. $urlDigest = parse_url($url);
  481. // extract host and path:
  482. $host = $urlDigest['host'];
  483. $path = $urlDigest['path'];
  484. if ($urlDigest['scheme'] != 'http') {
  485. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  486. }
  487. // open a socket connection on port 80 - timeout: 30 sec
  488. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  489. if ($fp){
  490. // send the request headers:
  491. fputs($fp, "POST $path HTTP/1.1\r\n");
  492. fputs($fp, "Host: $host\r\n");
  493. if ($referer != '')
  494. fputs($fp, "Referer: $referer\r\n");
  495. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  496. foreach($headers as $k => $v) {
  497. fputs($fp, $k.": ".$v."\r\n");
  498. }
  499. fputs($fp, "Connection: close\r\n\r\n");
  500. fputs($fp, $data);
  501. $result = '';
  502. while(!feof($fp)) {
  503. // receive the results of the request
  504. $result .= fgets($fp, 128);
  505. }
  506. }
  507. else {
  508. return array(
  509. 'status' => 'err',
  510. 'error' => "$errstr ($errno)"
  511. );
  512. }
  513. // close the socket connection:
  514. fclose($fp);
  515. // split the result header from the content
  516. $result = explode("\r\n\r\n", $result, 2);
  517. $header = isset($result[0]) ? $result[0] : '';
  518. $content = isset($result[1]) ? $result[1] : '';
  519. // return as structured array:
  520. return array(
  521. 'status' => 'ok',
  522. 'header' => $header,
  523. 'content' => $content,
  524. );
  525. }
  526. // Format item from Emby for Carousel
  527. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  528. // Static Height
  529. $height = 444;
  530. // Get Item Details
  531. $itemDetails = json_decode(@file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  532. /*if (substr_count(EMBYURL, ':') == 2) {
  533. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  534. }else{
  535. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  536. }*/
  537. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  538. switch ($itemDetails['Type']) {
  539. case 'Episode':
  540. case 'Series':
  541. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  542. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  543. $width = 300;
  544. $style = '';
  545. $image = 'slick-image-tall';
  546. if(!$nowPlaying){
  547. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  548. $key = $itemDetails['Id'] . "-list";
  549. $itemType = 'season';
  550. }else{
  551. $height = 281;
  552. $width = 500;
  553. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  554. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  555. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  556. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  557. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  558. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  559. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  560. $stream = $moreInfo['PlayState']['PlayMethod'];
  561. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  562. $id = $moreInfo['DeviceId'];
  563. $streamInfo = buildStream(array(
  564. 'platform' => (string) $moreInfo['Client'],
  565. 'device' => (string) $moreInfo['DeviceName'],
  566. 'stream' => streamType($stream),
  567. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  568. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  569. ));
  570. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  571. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  572. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  573. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  574. }
  575. break;
  576. case 'MusicAlbum':
  577. case 'Audio':
  578. $title = $itemDetails['Name'];
  579. $imageId = $itemDetails['Id'];
  580. $width = 444;
  581. $style = '';
  582. $image = 'slick-image-short';
  583. if(!$nowPlaying){
  584. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  585. $key = $itemDetails['Id'] . "-list";
  586. $itemType = 'album';
  587. }else{
  588. $height = 281;
  589. $width = 500;
  590. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  591. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  592. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  593. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  594. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  595. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  596. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  597. $stream = $moreInfo['PlayState']['PlayMethod'];
  598. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  599. $id = $moreInfo['DeviceId'];
  600. $streamInfo = buildStream(array(
  601. 'platform' => (string) $moreInfo['Client'],
  602. 'device' => (string) $moreInfo['DeviceName'],
  603. 'stream' => streamType($stream),
  604. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  605. ));
  606. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  607. $topTitle = '<h5 class="text-center zero-m elip">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  608. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  609. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  610. }
  611. break;
  612. case 'TvChannel':
  613. $title = $itemDetails['CurrentProgram']['Name'];
  614. $imageId = $itemDetails['Id'];
  615. $width = 300;
  616. $style = '';
  617. $image = 'slick-image-tall';
  618. if(!$nowPlaying){
  619. $imageType = "Primary";
  620. $key = $itemDetails['Id'] . "-list";
  621. }else{
  622. $height = 281;
  623. $width = 500;
  624. $imageType = "Thumb";
  625. $key = $itemDetails['Id'] . "-np";
  626. $useImage = "images/livetv.png";
  627. $watched = "0";
  628. $stream = $moreInfo['PlayState']['PlayMethod'];
  629. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  630. $id = $moreInfo['DeviceId'];
  631. $streamInfo = buildStream(array(
  632. 'platform' => (string) $moreInfo['Client'],
  633. 'device' => (string) $moreInfo['DeviceName'],
  634. 'stream' => streamType($stream),
  635. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  636. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  637. ));
  638. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  639. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  640. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  641. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  642. }
  643. break;
  644. default:
  645. $title = $itemDetails['Name'];
  646. $imageId = $itemDetails['Id'];
  647. $width = 300;
  648. $style = '';
  649. $image = 'slick-image-tall';
  650. if(!$nowPlaying){
  651. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  652. $key = $itemDetails['Id'] . "-list";
  653. $itemType = 'movie';
  654. }else{
  655. $height = 281;
  656. $width = 500;
  657. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  658. $key = $itemDetails['Id'] . "-np";
  659. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  660. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  661. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  662. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  663. $stream = $moreInfo['PlayState']['PlayMethod'];
  664. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  665. $id = $moreInfo['DeviceId'];
  666. $streamInfo = buildStream(array(
  667. 'platform' => (string) $moreInfo['Client'],
  668. 'device' => (string) $moreInfo['DeviceName'],
  669. 'stream' => streamType($stream),
  670. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  671. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  672. ));
  673. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  674. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  675. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  676. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  677. }
  678. }
  679. // If No Overview
  680. if (!isset($itemDetails['Overview'])) {
  681. $itemDetails['Overview'] = '';
  682. }
  683. $original_image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  684. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  685. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  686. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  687. }
  688. if($nowPlaying){
  689. if(!$imageType){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  690. if(!$imageId){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  691. }else{
  692. if(!$imageType){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  693. if(!$imageId){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  694. }
  695. if(isset($useImage)){ $image_url = $useImage; }
  696. // Assemble Item And Cache Into Array
  697. if($nowPlaying){
  698. //prettyPrint($itemDetails);
  699. 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>';
  700. }else{
  701. 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>';
  702. }
  703. }
  704. // Format item from Plex for Carousel
  705. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  706. // Static Height
  707. $height = 444;
  708. $widthOverride = 100;
  709. $playlist = ($playlist) ? " playlist-$playlist" : "";
  710. switch ($item['type']) {
  711. case 'season':
  712. $title = $item['parentTitle'];
  713. $summary = $item['parentSummary'];
  714. $width = 300;
  715. $image = 'slick-image-tall';
  716. $style = '';
  717. if(!$nowPlaying){
  718. $thumb = $item['thumb'];
  719. $key = $item['ratingKey'] . "-list";
  720. }else {
  721. $height = 281;
  722. $width = 500;
  723. $thumb = $item['art'];
  724. $key = $item['ratingKey'] . "-np";
  725. $elapsed = $item['viewOffset'];
  726. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  727. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  728. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  729. $stream = $item->Media->Part->Stream['decision'];
  730. $user = $role == "admin" ? $item->User['title'] : "";
  731. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  732. $streamInfo = buildStream(array(
  733. 'platform' => (string) $item->Player['platform'],
  734. 'device' => (string) $item->Player['device'],
  735. 'stream' => streamType($item->Media->Part['decision']),
  736. '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'].")",
  737. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  738. ));
  739. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  740. }
  741. break;
  742. case 'episode':
  743. $title = $item['grandparentTitle'];
  744. $summary = $item['title'];
  745. $width = 300;
  746. $image = 'slick-image-tall';
  747. $style = '';
  748. if(!$nowPlaying){
  749. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  750. $key = $item['ratingKey'] . "-list";
  751. }else {
  752. $height = 281;
  753. $width = 500;
  754. $thumb = $item['art'];
  755. $key = $item['ratingKey'] . "-np";
  756. $elapsed = $item['viewOffset'];
  757. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  758. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  759. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  760. $stream = $item->Media->Part->Stream['decision'];
  761. $user = $role == "admin" ? $item->User['title'] : "";
  762. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  763. $streamInfo = buildStream(array(
  764. 'platform' => (string) $item->Player['platform'],
  765. 'device' => (string) $item->Player['device'],
  766. 'stream' => streamType($item->Media->Part['decision']),
  767. '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'].")",
  768. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  769. ));
  770. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  771. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  772. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  773. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  774. }
  775. break;
  776. case 'clip':
  777. $title = $item['title'];
  778. $summary = $item['summary'];
  779. $width = 300;
  780. $image = 'slick-image-tall';
  781. $style = '';
  782. if(!$nowPlaying){
  783. $thumb = $item['thumb'];
  784. $key = $item['ratingKey'] . "-list";
  785. }else {
  786. $height = 281;
  787. $width = 500;
  788. $thumb = $item['art'];
  789. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  790. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  791. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  792. $elapsed = $item['viewOffset'];
  793. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  794. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  795. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  796. $stream = $item->Media->Part->Stream['decision'];
  797. $user = $role == "admin" ? $item->User['title'] : "";
  798. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  799. $streamInfo = buildStream(array(
  800. 'platform' => (string) $item->Player['platform'],
  801. 'device' => (string) $item->Player['device'],
  802. 'stream' => streamType($item->Media->Part['decision']),
  803. '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'].")",
  804. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  805. ));
  806. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  807. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  808. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  809. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  810. }
  811. break;
  812. case 'album':
  813. case 'track':
  814. $title = $item['parentTitle'];
  815. $summary = $item['title'];
  816. $image = 'slick-image-short';
  817. $style = 'left: 160px !important;';
  818. $item['ratingKey'] = $item['parentRatingKey'];
  819. if(!$nowPlaying){
  820. $width = 444;
  821. $thumb = $item['thumb'];
  822. $key = $item['ratingKey'] . "-list";
  823. }else {
  824. $height = 281;
  825. $width = 500;
  826. $thumb = ($item['art']) ? $item['art'] : $item['parentThumb'];
  827. $widthOverride = ($item['art']) ? 100 : 56;
  828. $key = $item['ratingKey'] . "-np";
  829. $elapsed = $item['viewOffset'];
  830. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  831. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  832. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  833. $stream = $item->Media->Part->Stream['decision'];
  834. $user = $role == "admin" ? $item->User['title'] : "";
  835. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  836. $streamInfo = buildStream(array(
  837. 'platform' => (string) $item->Player['platform'],
  838. 'device' => (string) $item->Player['device'],
  839. 'stream' => streamType($item->Media->Part['decision']),
  840. 'audio' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  841. ));
  842. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  843. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  844. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  845. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  846. }
  847. break;
  848. default:
  849. $title = $item['title'];
  850. $summary = $item['summary'];
  851. $image = 'slick-image-tall';
  852. $style = '';
  853. if(!$nowPlaying){
  854. $width = 300;
  855. $thumb = $item['thumb'];
  856. $key = $item['ratingKey'] . "-list";
  857. }else {
  858. $height = 281;
  859. $width = 500;
  860. $thumb = $item['art'];
  861. $key = $item['ratingKey'] . "-np";
  862. $elapsed = $item['viewOffset'];
  863. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  864. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  865. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  866. $stream = $item->Media->Part->Stream['decision'];
  867. $user = $role == "admin" ? $item->User['title'] : "";
  868. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  869. $streamInfo = buildStream(array(
  870. 'platform' => (string) $item->Player['platform'],
  871. 'device' => (string) $item->Player['device'],
  872. 'stream' => streamType($item->Media->Part['decision']),
  873. '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'].")",
  874. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  875. ));
  876. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  877. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  878. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  879. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  880. }
  881. }
  882. if (PLEXTABURL) {
  883. $address = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  884. }else{
  885. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  886. }
  887. // If No Overview
  888. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  889. $original_image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  890. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  891. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  892. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  893. }
  894. if($nowPlaying){
  895. if(!$thumb){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  896. }else{
  897. if(!$thumb){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  898. }
  899. if(isset($useImage)){ $image_url = $useImage; }
  900. $openTab = (PLEXTABNAME) ? "true" : "false";
  901. // Assemble Item And Cache Into Array
  902. if($nowPlaying){
  903. 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>';
  904. }else{
  905. 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>';
  906. }
  907. }
  908. //$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  909. //Recent Added
  910. function outputRecentAdded($header, $items, $script = false, $array, $type) {
  911. $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">';
  912. if(preg_grep("/item-movie/", $items)){
  913. $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>';
  914. }
  915. if(preg_grep("/item-season/", $items)){
  916. $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>';
  917. }
  918. if(preg_grep("/item-album/", $items)){
  919. $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>';
  920. }
  921. $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>';
  922. $hideMenu .= '</ul></div></div>';
  923. // If None Populate Empty Item
  924. if (!count($items)) {
  925. 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>';
  926. }else{
  927. $className = str_replace(' ', '', $header.' on '.$type);
  928. 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>':'');
  929. }
  930. }
  931. // Create Carousel
  932. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  933. // If None Populate Empty Item
  934. if (!count($items)) {
  935. return '<div id="'.$type.'"></div>'.($script?'<script>'.$script.'</script>':'');
  936. }else{
  937. return '<div id="'.$type.'"><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  938. }
  939. }
  940. // Get Now Playing Streams From Emby
  941. function getEmbyStreams($size, $showNames, $role) {
  942. $address = qualifyURL(EMBYURL);
  943. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  944. if (!is_array($api)) { return 'Could not load!'; }
  945. $playingItems = array();
  946. foreach($api as $key => $value) {
  947. if (isset($value['NowPlayingItem'])) {
  948. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  949. }
  950. }
  951. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY')." ( ".count($playingItems)." Streams )", $size, 'streams-emby', $playingItems, ajaxLoop('emby-streams',NOWPLAYINGREFRESH));
  952. }
  953. // Get Now Playing Streams From Plex
  954. function getPlexStreams($size, $showNames, $role){
  955. $address = qualifyURL(PLEXURL);
  956. // Perform API requests
  957. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  958. libxml_use_internal_errors(true);
  959. $api = simplexml_load_string($api);
  960. if (is_array($api) || is_object($api)){
  961. if (!$api->head->title){
  962. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  963. if (!$getServer) { return 'Could not load!'; }
  964. // Identify the local machine
  965. $gotServer = $getServer['machineIdentifier'];
  966. $items = array();
  967. foreach($api AS $child) {
  968. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  969. }
  970. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, ajaxLoop('plex-streams',NOWPLAYINGREFRESH));
  971. }else{
  972. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  973. }
  974. }else{
  975. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  976. }
  977. }
  978. // Get Recent Content From Emby
  979. function getEmbyRecent($array) {
  980. $address = qualifyURL(EMBYURL);
  981. $header = translate('RECENT_CONTENT');
  982. // Currently Logged In User
  983. $username = false;
  984. if (isset($GLOBALS['USER'])) {
  985. $username = strtolower($GLOBALS['USER']->username);
  986. }
  987. // Get A User
  988. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  989. if (!is_array($userIds)) { return 'Could not load!'; }
  990. $showPlayed = true;
  991. foreach ($userIds as $value) { // Scan for admin user
  992. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  993. $userId = $value['Id'];
  994. }
  995. if ($username && strtolower($value['Name']) == $username) {
  996. $userId = $value['Id'];
  997. $showPlayed = false;
  998. break;
  999. }
  1000. }
  1001. // Get the latest Items
  1002. $latest = json_decode(@file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  1003. // For Each Item In Category
  1004. $items = array();
  1005. foreach ($latest as $k => $v) {
  1006. $type = (string) $v['Type'];
  1007. if(@$array[$type] == "true"){
  1008. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  1009. }
  1010. }
  1011. $array["movie"] = $array["Movie"];
  1012. $array["season"] = $array["Episode"];
  1013. $array["album"] = $array["MusicAlbum"];
  1014. unset($array["Movie"]);
  1015. unset($array["Episode"]);
  1016. unset($array["MusicAlbum"]);
  1017. unset($array["Series"]);
  1018. return outputRecentAdded($header, $items, ajaxLoop('emby-recent',RECENTREFRESH,'loadSlick();'), $array, 'Emby');
  1019. }
  1020. // Get Recent Content From Plex
  1021. function getPlexRecent($array){
  1022. $address = qualifyURL(PLEXURL);
  1023. $header = translate('RECENT_CONTENT');
  1024. // Perform Requests
  1025. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  1026. libxml_use_internal_errors(true);
  1027. $api = simplexml_load_string($api);
  1028. if (is_array($api) || is_object($api)){
  1029. if (!$api->head->title){
  1030. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  1031. if (!$getServer) { return 'Could not load!'; }
  1032. // Identify the local machine
  1033. $gotServer = $getServer['machineIdentifier'];
  1034. $items = array();
  1035. foreach($api AS $child) {
  1036. $type = (string) $child['type'];
  1037. if($array[$type] == "true"){
  1038. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  1039. }
  1040. }
  1041. return outputRecentAdded($header, $items, ajaxLoop('plex-recent',RECENTREFRESH,'loadSlick();'), $array, 'Plex');
  1042. }else{
  1043. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  1044. }
  1045. }else{
  1046. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1047. }
  1048. }
  1049. // Get Image From Emby
  1050. function getEmbyImage() {
  1051. $refresh = false;
  1052. $embyAddress = qualifyURL(EMBYURL);
  1053. if (!file_exists('images/cache')) {
  1054. mkdir('images/cache', 0777, true);
  1055. }
  1056. $itemId = $_GET['img'];
  1057. $key = $_GET['key'];
  1058. if(strpos($key, '$') !== false){
  1059. $key = explode('$', $key)[0];
  1060. $refresh = true;
  1061. }
  1062. $itemType = $_GET['type'];
  1063. $imgParams = array();
  1064. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  1065. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  1066. if(isset($itemId)) {
  1067. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  1068. $cachefile = 'images/cache/'.$key.'.jpg';
  1069. $cachetime = 604800;
  1070. // Serve from the cache if it is younger than $cachetime
  1071. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh !== true) {
  1072. header("Content-type: image/jpeg");
  1073. @readfile($cachefile);
  1074. exit;
  1075. }
  1076. ob_start(); // Start the output buffer
  1077. header('Content-type: image/jpeg');
  1078. //@readfile($image_src);
  1079. echo @curl_get($image_src);
  1080. // Cache the output to a file
  1081. $fp = fopen($cachefile, 'wb');
  1082. fwrite($fp, ob_get_contents());
  1083. fclose($fp);
  1084. ob_end_flush(); // Send the output to the browser
  1085. die();
  1086. } else {
  1087. debug_out('Invalid Request',1);
  1088. }
  1089. }
  1090. // Get Image From Plex
  1091. function getPlexImage() {
  1092. $refresh = false;
  1093. $plexAddress = qualifyURL(PLEXURL);
  1094. if (!file_exists('images/cache')) {
  1095. mkdir('images/cache', 0777, true);
  1096. }
  1097. $image_url = $_GET['img'];
  1098. $key = $_GET['key'];
  1099. if(strpos($key, '$') !== false){
  1100. $key = explode('$', $key)[0];
  1101. $refresh = true;
  1102. }
  1103. $image_height = $_GET['height'];
  1104. $image_width = $_GET['width'];
  1105. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1106. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1107. $cachefile = 'images/cache/'.$key.'.jpg';
  1108. $cachetime = 604800;
  1109. // Serve from the cache if it is younger than $cachetime
  1110. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1111. header("Content-type: image/jpeg");
  1112. @readfile($cachefile);
  1113. exit;
  1114. }
  1115. ob_start(); // Start the output buffer
  1116. header('Content-type: image/jpeg');
  1117. //@readfile($image_src);
  1118. echo @curl_get($image_src);
  1119. // Cache the output to a file
  1120. $fp = fopen($cachefile, 'wb');
  1121. fwrite($fp, ob_get_contents());
  1122. fclose($fp);
  1123. ob_end_flush(); // Send the output to the browser
  1124. die();
  1125. } else {
  1126. echo "Invalid Plex Request";
  1127. }
  1128. }
  1129. // Simplier access to class
  1130. function translate($string) {
  1131. if (isset($GLOBALS['language'])) {
  1132. return $GLOBALS['language']->translate($string);
  1133. } else {
  1134. return '!Translations Not Loaded!';
  1135. }
  1136. }
  1137. // Generate Random string
  1138. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1139. $tmp = '';
  1140. for ($i = 0; $i < $length; $i++) {
  1141. $tmp .= substr(str_shuffle($chars), 0, 1);
  1142. }
  1143. return $tmp;
  1144. }
  1145. // Create config file in the return syntax
  1146. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1147. // Define Initial Value
  1148. $output = array();
  1149. // Sort Items
  1150. ksort($array);
  1151. // Update the current config version
  1152. if (!$nest) {
  1153. // Inject Current Version
  1154. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1155. }
  1156. unset($array['CONFIG_VERSION']);
  1157. unset($array['apply_CONFIG_VERSION']);
  1158. // Process Settings
  1159. foreach ($array as $k => $v) {
  1160. $allowCommit = true;
  1161. switch (gettype($v)) {
  1162. case 'boolean':
  1163. $item = ($v?'true':'false');
  1164. break;
  1165. case 'integer':
  1166. case 'double':
  1167. case 'integer':
  1168. case 'NULL':
  1169. $item = $v;
  1170. break;
  1171. case 'string':
  1172. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1173. break;
  1174. case 'array':
  1175. $item = createConfig($v, false, $nest+1);
  1176. break;
  1177. default:
  1178. $allowCommit = false;
  1179. }
  1180. if($allowCommit) {
  1181. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1182. }
  1183. }
  1184. // Build output
  1185. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1186. if (!$nest && $path) {
  1187. $pathDigest = pathinfo($path);
  1188. @mkdir($pathDigest['dirname'], 0770, true);
  1189. if (file_exists($path)) {
  1190. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1191. }
  1192. $file = fopen($path, 'w');
  1193. fwrite($file, $output);
  1194. fclose($file);
  1195. if (file_exists($path)) {
  1196. return true;
  1197. }
  1198. writeLog("error", "config was unable to write");
  1199. return false;
  1200. } else {
  1201. writeLog("success", "config was updated with new values");
  1202. return $output;
  1203. }
  1204. }
  1205. // Load a config file written in the return syntax
  1206. function loadConfig($path = 'config/config.php') {
  1207. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1208. if (!is_file($path)) {
  1209. return null;
  1210. } else {
  1211. return (array) call_user_func(function() use($path) {
  1212. return include($path);
  1213. });
  1214. }
  1215. }
  1216. // Commit new values to the configuration
  1217. function updateConfig($new, $current = false) {
  1218. // Get config if not supplied
  1219. if ($current === false) {
  1220. $current = loadConfig();
  1221. } else if (is_string($current) && is_file($current)) {
  1222. $current = loadConfig($current);
  1223. }
  1224. // Inject Parts
  1225. foreach ($new as $k => $v) {
  1226. $current[$k] = $v;
  1227. }
  1228. // Return Create
  1229. return createConfig($current);
  1230. }
  1231. // Inject Defaults As Needed
  1232. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1233. if (is_string($path)) {
  1234. $loadedDefaults = loadConfig($path);
  1235. } else {
  1236. $loadedDefaults = $path;
  1237. }
  1238. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1239. }
  1240. // support function for fillDefaultConfig()
  1241. function fillDefaultConfig_recurse($current, $defaults) {
  1242. foreach($defaults as $k => $v) {
  1243. if (!isset($current[$k])) {
  1244. $current[$k] = $v;
  1245. } else if (is_array($current[$k]) && is_array($v)) {
  1246. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1247. }
  1248. }
  1249. return $current;
  1250. };
  1251. // Define Scalar Variables (nest non-secular with underscores)
  1252. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1253. foreach($array as $k => $v) {
  1254. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1255. define($nest_prefix.$k, $v, $anyCase);
  1256. } else if (is_array($v)) {
  1257. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1258. }
  1259. }
  1260. }
  1261. // This function exists only because I am lazy
  1262. function configLazy($path = 'config/config.php') {
  1263. // Load config or default
  1264. if (file_exists($path)) {
  1265. $config = fillDefaultConfig(loadConfig($path));
  1266. } else {
  1267. $config = loadConfig('config/configDefaults.php');
  1268. }
  1269. if (is_array($config)) {
  1270. defineConfig($config);
  1271. }
  1272. return $config;
  1273. }
  1274. // Qualify URL
  1275. function qualifyURL($url) {
  1276. //local address?
  1277. if(substr($url, 0,1) == "/"){
  1278. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1279. $protocol = "https://";
  1280. } else {
  1281. $protocol = "http://";
  1282. }
  1283. $url = $protocol.getServer().$url;
  1284. }
  1285. // Get Digest
  1286. $digest = parse_url($url);
  1287. // http/https
  1288. if (!isset($digest['scheme'])) {
  1289. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1290. $scheme = 'http';
  1291. } else {
  1292. $scheme = 'https';
  1293. }
  1294. } else {
  1295. $scheme = $digest['scheme'];
  1296. }
  1297. // Host
  1298. $host = (isset($digest['host'])?$digest['host']:'');
  1299. // Port
  1300. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1301. // Path
  1302. $path = (isset($digest['path'])?$digest['path']:'');
  1303. // Output
  1304. return $scheme.'://'.$host.$port.$path;
  1305. }
  1306. // Function to be called at top of each to allow upgrading environment as the spec changes
  1307. function upgradeCheck() {
  1308. // Upgrade to 1.31
  1309. if (file_exists('homepageSettings.ini.php')) {
  1310. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1311. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1312. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1313. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1314. foreach($databaseConfig as $k => $v) {
  1315. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1316. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1317. }
  1318. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1319. unlink('homepageSettings.ini.php');
  1320. unset($databaseData);
  1321. unset($homepageConfig);
  1322. }
  1323. // Upgrade to 1.32
  1324. if (file_exists('databaseLocation.ini.php')) {
  1325. // Load Existing
  1326. $config = parse_ini_file('databaseLocation.ini.php', true);
  1327. // Refactor
  1328. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1329. $config['user_home'] = $config['database_Location'].'users/';
  1330. unset($config['databaseLocation']);
  1331. // Turn Off Emby And Plex Recent
  1332. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1333. unset($config["embyPort"]);
  1334. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1335. unset($config["plexPort"]);
  1336. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1337. unset($config["nzbgetPort"]);
  1338. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1339. unset($config["sabnzbdPort"]);
  1340. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1341. unset($config["headphonesPort"]);
  1342. // Write config file
  1343. $config['CONFIG_VERSION'] = '1.32';
  1344. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1345. $createConfigSuccess = createConfig($config);
  1346. // Create new config
  1347. if ($createConfigSuccess) {
  1348. if (file_exists('config/config.php')) {
  1349. // Remove Old ini file
  1350. unlink('databaseLocation.ini.php');
  1351. } else {
  1352. debug_out('Something is not right here!');
  1353. }
  1354. } else {
  1355. debug_out('Couldn\'t create updated configuration.' ,1);
  1356. }
  1357. }
  1358. // Upgrade to 1.33
  1359. $config = loadConfig();
  1360. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1361. // Fix User Directory
  1362. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1363. $config['user_home'] = $config['database_Location'].'users/';
  1364. unset($config['USER_HOME']);
  1365. // Backend auth merge
  1366. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1367. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1368. }
  1369. unset($config['authBackendPort']);
  1370. // If auth is being used move it to embyURL as that is now used in auth functions
  1371. 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')))) {
  1372. $config['embyURL'] = $config['authBackendHost'];
  1373. }
  1374. // Upgrade database to latest version
  1375. updateSQLiteDB($config['database_Location'],'1.32');
  1376. // Update Version and Commit
  1377. $config['apply_CONFIG_VERSION'] = '1.33';
  1378. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1379. $createConfigSuccess = createConfig($config);
  1380. unset($config);
  1381. }
  1382. // Upgrade to 1.34
  1383. $config = loadConfig();
  1384. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1385. // Upgrade database to latest version
  1386. updateSQLiteDB($config['database_Location'],'1.33');
  1387. // Update Version and Commit
  1388. $config['CONFIG_VERSION'] = '1.34';
  1389. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1390. $createConfigSuccess = createConfig($config);
  1391. unset($config);
  1392. }
  1393. // Upgrade to 1.40
  1394. $config = loadConfig();
  1395. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1396. // Upgrade database to latest version
  1397. updateSQLiteDB($config['database_Location'],'1.38');
  1398. // Update Version and Commit
  1399. $config['CONFIG_VERSION'] = '1.40';
  1400. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1401. $createConfigSuccess = createConfig($config);
  1402. unset($config);
  1403. }
  1404. // Upgrade to 1.50
  1405. $config = loadConfig();
  1406. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.50')) {
  1407. // Upgrade database to latest version
  1408. updateSQLiteDB($config['database_Location'],'1.40');
  1409. // Update Version and Commit
  1410. $config['CONFIG_VERSION'] = '1.50';
  1411. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.40].bak.php');
  1412. $createConfigSuccess = createConfig($config);
  1413. unset($config);
  1414. }
  1415. // Upgrade to 1.603
  1416. $config = loadConfig();
  1417. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.603')) {
  1418. // Update Version and Commit
  1419. $config['CONFIG_VERSION'] = '1.603';
  1420. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.601].bak.php');
  1421. $createConfigSuccess = createConfig($config);
  1422. unset($config);
  1423. if(file_exists('org.log')){
  1424. copy('org.log', DATABASE_LOCATION.'org.log');
  1425. unlink('org.log');
  1426. }
  1427. if(file_exists('loginLog.json')){
  1428. copy('loginLog.json', DATABASE_LOCATION.'loginLog.json');
  1429. unlink('loginLog.json');
  1430. }
  1431. }
  1432. return true;
  1433. }
  1434. // Get OS from server
  1435. function getOS(){
  1436. if(PHP_SHLIB_SUFFIX == "dll"){
  1437. return "win";
  1438. }else{
  1439. return "nix";
  1440. }
  1441. }
  1442. //Get Error by Server OS
  1443. function getError($os, $error){
  1444. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1445. $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'");
  1446. $errors = array(
  1447. 'pdo_sqlite' => array(
  1448. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1449. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1450. ),
  1451. 'sqlite3' => array(
  1452. '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',
  1453. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1454. ),
  1455. 'curl' => array(
  1456. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1457. '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',
  1458. ),
  1459. 'zip' => array(
  1460. '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',
  1461. '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',
  1462. ),
  1463. );
  1464. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1465. }
  1466. // Check if all software dependancies are met
  1467. function dependCheck() {
  1468. $output = array();
  1469. $i = 1;
  1470. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1471. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1472. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1473. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1474. if ($output) {
  1475. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1476. $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++;
  1477. debug_out($output,1);
  1478. }
  1479. return true;
  1480. }
  1481. // Process file uploads
  1482. function uploadFiles($path, $ext_mask = null) {
  1483. if (isset($_FILES) && count($_FILES)) {
  1484. require_once('class.uploader.php');
  1485. $uploader = new Uploader();
  1486. $data = $uploader->upload($_FILES['files'], array(
  1487. 'limit' => 10,
  1488. 'maxSize' => 10,
  1489. 'extensions' => $ext_mask,
  1490. 'required' => false,
  1491. 'uploadDir' => str_replace('//','/',$path.'/'),
  1492. 'title' => array('name'),
  1493. 'removeFiles' => true,
  1494. 'replace' => true,
  1495. ));
  1496. if($data['isComplete']){
  1497. $files = $data['data'];
  1498. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1499. echo json_encode($files['metas'][0]['name']);
  1500. }
  1501. if($data['hasErrors']){
  1502. $errors = $data['errors'];
  1503. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1504. echo json_encode($errors);
  1505. }
  1506. } else {
  1507. writeLog("error", "image was not uploaded");
  1508. echo json_encode('No files submitted!');
  1509. }
  1510. }
  1511. // Process file uploads
  1512. function uploadAvatar($path, $ext_mask = null) {
  1513. if (isset($_FILES) && count($_FILES)) {
  1514. require_once('class.uploader.php');
  1515. $uploader = new Uploader();
  1516. $data = $uploader->upload($_FILES['files'], array(
  1517. 'limit' => 10,
  1518. 'maxSize' => 10,
  1519. 'extensions' => $ext_mask,
  1520. 'required' => false,
  1521. 'uploadDir' => str_replace('//','/',$path.'/'),
  1522. 'title' => array('name'),
  1523. 'removeFiles' => true,
  1524. 'replace' => true,
  1525. ));
  1526. if($data['isComplete']){
  1527. $files = $data['data'];
  1528. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1529. echo json_encode($files['metas'][0]['name']);
  1530. }
  1531. if($data['hasErrors']){
  1532. $errors = $data['errors'];
  1533. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1534. echo json_encode($errors);
  1535. }
  1536. } else {
  1537. writeLog("error", "image was not uploaded");
  1538. echo json_encode('No files submitted!');
  1539. }
  1540. }
  1541. // Remove file
  1542. function removeFiles($path) {
  1543. if(is_file($path)) {
  1544. writeLog("success", "file was removed");
  1545. unlink($path);
  1546. } else {
  1547. writeLog("error", "file was not removed");
  1548. echo json_encode('No file specified for removal!');
  1549. }
  1550. }
  1551. // Lazy select options
  1552. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1553. $output = array();
  1554. $selectedArr = ($multi?explode('|', $selected):array());
  1555. foreach ($array as $key => $value) {
  1556. if (is_array($value)) {
  1557. if (isset($value['optgroup'])) {
  1558. $output[] = '<optgroup label="'.$key.'">';
  1559. foreach($value['optgroup'] as $k => $v) {
  1560. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1561. }
  1562. } else {
  1563. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1564. }
  1565. } else {
  1566. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1567. }
  1568. }
  1569. return implode('',$output);
  1570. }
  1571. // Check if user is allowed to continue
  1572. function qualifyUser($type, $errOnFail = false) {
  1573. if (!isset($GLOBALS['USER'])) {
  1574. require_once("user.php");
  1575. $GLOBALS['USER'] = new User('registration_callback');
  1576. }
  1577. if (is_bool($type)) {
  1578. if ($type === true) {
  1579. $authorized = ($GLOBALS['USER']->authenticated == true);
  1580. } else {
  1581. $authorized = true;
  1582. }
  1583. } elseif (is_string($type) || is_array($type)) {
  1584. if ($type !== 'false') {
  1585. if (!is_array($type)) {
  1586. $type = explode('|',$type);
  1587. }
  1588. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1589. } else {
  1590. $authorized = true;
  1591. }
  1592. } else {
  1593. debug_out('Invalid Syntax!',1);
  1594. }
  1595. if (!$authorized && $errOnFail) {
  1596. if ($GLOBALS['USER']->authenticated) {
  1597. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401');
  1598. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401\'</script>';
  1599. } else {
  1600. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999');
  1601. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999\'</script>';
  1602. }
  1603. debug_out('Not Authorized' ,1);
  1604. } else {
  1605. return $authorized;
  1606. }
  1607. }
  1608. // Build an (optionally) tabbed settings page.
  1609. function buildSettings($array) {
  1610. /*
  1611. array(
  1612. 'title' => '',
  1613. 'id' => '',
  1614. 'fields' => array( See buildField() ),
  1615. 'tabs' => array(
  1616. array(
  1617. 'title' => '',
  1618. 'id' => '',
  1619. 'image' => '',
  1620. 'fields' => array( See buildField() ),
  1621. ),
  1622. ),
  1623. );
  1624. */
  1625. $notifyExplode = explode("-", NOTIFYEFFECT);
  1626. $fieldFunc = function($fieldArr) {
  1627. $fields = '<div class="row">';
  1628. foreach($fieldArr as $key => $value) {
  1629. $isSingle = isset($value['type']);
  1630. if ($isSingle) { $value = array($value); }
  1631. $tmpField = '';
  1632. $sizeLg = max(floor(12/count($value)),2);
  1633. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1634. foreach($value as $k => $v) {
  1635. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1636. }
  1637. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1638. }
  1639. $fields .= '</div>';
  1640. return $fields;
  1641. };
  1642. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1643. $tabSelectors = array();
  1644. $tabContent = array();
  1645. if (isset($array['tabs'])) {
  1646. foreach($array['tabs'] as $key => $value) {
  1647. $id = (isset($value['id'])?$value['id']:randString(32));
  1648. $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>';
  1649. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1650. }
  1651. }
  1652. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1653. $extraClick = ($pageID == 'appearance_settings' ? "$('#advanced_settings_form_submit').click();console.log('add theme settings');" : "");
  1654. return '
  1655. <div class="email-body">
  1656. <div class="email-header gray-bg">
  1657. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1658. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float save-btn-form">
  1659. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1660. </button>
  1661. <h1>'.$array['title'].'</h1>
  1662. </div>
  1663. <div class="email-inner small-box">
  1664. <div class="email-inner-section">
  1665. <div class="small-box fade in" id="'.$pageID.'_frame">
  1666. <div class="col-lg-12">
  1667. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1668. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1669. '.$fields.($tabContent?'
  1670. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1671. <ul class="nav nav-tabs apps">
  1672. '.implode('', $tabSelectors).'
  1673. </ul>
  1674. <div class="clearfix"></div>
  1675. <div class="tab-content">
  1676. '.implode('', $tabContent).'
  1677. </div>
  1678. </div>':'').'
  1679. </form>
  1680. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1681. </div>
  1682. </div>
  1683. </div>
  1684. </div>
  1685. </div>
  1686. <script>
  1687. $(document).ready(function() {
  1688. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1689. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1690. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1691. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1692. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1693. var newVals = {};
  1694. var hasVals = false;
  1695. var errorFields = [];
  1696. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1697. hasVals = true;
  1698. if (this.type == \'checkbox\') {
  1699. newVals[this.name] = this.checked;
  1700. } else if ($(this).hasClass(\'summernote\')) {
  1701. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1702. } else {
  1703. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1704. var fieldVal = $(this).val();
  1705. if (typeof fieldVal == \'object\') {
  1706. if (typeof fieldVal.join == \'function\') {
  1707. fieldVal = fieldVal.join(\'|\');
  1708. } else {
  1709. fieldVal = JSON.stringify(fieldVal);
  1710. }
  1711. }
  1712. newVals[this.name] = fieldVal;
  1713. }
  1714. });
  1715. if (errorFields.length) {
  1716. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1717. } else if (hasVals) {
  1718. console.log(newVals);
  1719. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1720. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1721. });
  1722. '.$extraClick.'
  1723. } else {
  1724. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1725. }
  1726. return false;
  1727. });
  1728. '.(isset($array['onready'])?$array['onready']:'').'
  1729. });
  1730. </script>
  1731. ';
  1732. }
  1733. // Build Settings Fields
  1734. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1735. /*
  1736. array(
  1737. 'type' => '',
  1738. 'placeholder' => '',
  1739. 'label' => '',
  1740. 'labelTranslate' => '',
  1741. 'assist' => '',
  1742. 'name' => '',
  1743. 'pattern' => '',
  1744. 'options' => array( // For SELECT only
  1745. 'Display' => 'value',
  1746. ),
  1747. )
  1748. */
  1749. // Tags
  1750. $tags = array();
  1751. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick') as $value) {
  1752. if (isset($params[$value])) {
  1753. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1754. } else if ($params[$value] === true) { $tags[] = $value; }
  1755. }
  1756. }
  1757. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1758. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1759. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1760. $val = (isset($params['value'])?$params['value']:'');
  1761. $class = (isset($params['class'])?' '.$params['class']:'');
  1762. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1763. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1764. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1765. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1766. // Field Design
  1767. switch ($params['type']) {
  1768. case 'text':
  1769. case 'number':
  1770. case 'password':
  1771. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1772. break;
  1773. case 'select':
  1774. case 'dropdown':
  1775. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1776. break;
  1777. case 'select-multi':
  1778. case 'dropdown-multi':
  1779. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1780. break;
  1781. case 'check':
  1782. case 'checkbox':
  1783. case 'toggle':
  1784. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1785. $colour = (isset($params['colour'])?$params['colour']:'success');
  1786. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1787. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1788. break;
  1789. case 'radio':
  1790. $labelOut = '';
  1791. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1792. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1793. $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>';
  1794. break;
  1795. case 'date':
  1796. $field = 'Unsupported, planned.';
  1797. break;
  1798. case 'hidden':
  1799. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1800. break;
  1801. case 'header':
  1802. $labelOut = '';
  1803. $headType = (isset($params['value'])?$params['value']:3);
  1804. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1805. break;
  1806. case 'button':
  1807. $labelOut = '';
  1808. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1809. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1810. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1811. $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>':'');
  1812. break;
  1813. case 'textarea':
  1814. $rows = (isset($params['rows'])?$params['rows']:5);
  1815. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1816. break;
  1817. case 'custom':
  1818. // Settings
  1819. $settings = array(
  1820. '$id' => $id,
  1821. '$name' => $name,
  1822. '$val' => $val,
  1823. '$label' => $label,
  1824. '$labelOut' => $labelOut,
  1825. );
  1826. // Get HTML
  1827. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1828. // If LabelOut is in html dont print it twice
  1829. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1830. // Replace variables in settings
  1831. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1832. // Build Field
  1833. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1834. break;
  1835. case 'space':
  1836. $labelOut = '';
  1837. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1838. break;
  1839. default:
  1840. $field = 'Unsupported field type';
  1841. break;
  1842. }
  1843. // Field Formats
  1844. switch ($format) {
  1845. case 'colour': // Fuckin Eh, Canada!
  1846. case 'color':
  1847. $labelBef = '<center>'.$label.'</center>';
  1848. $wrapClass = 'gray-bg colour-field';
  1849. $labelAft = '';
  1850. $field = str_replace(' material input-sm','',$field);
  1851. break;
  1852. default:
  1853. $labelBef = '';
  1854. $labelAft = $labelOut;
  1855. }
  1856. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1857. }
  1858. // Tab Settings Generation
  1859. function printTabRow($data) {
  1860. $hidden = false;
  1861. if ($data===false) {
  1862. $hidden = true;
  1863. $data = array( // New Tab Defaults
  1864. 'id' => 'new',
  1865. 'name' => '',
  1866. 'url' => '',
  1867. 'icon' => 'fa-diamond',
  1868. 'iconurl' => '',
  1869. 'active' => 'true',
  1870. 'user' => 'true',
  1871. 'guest' => 'true',
  1872. 'window' => 'false',
  1873. 'splash' => 'true',
  1874. 'ping' => 'false',
  1875. 'ping_url' => '',
  1876. 'defaultz' => '',
  1877. );
  1878. }
  1879. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1880. $output = '
  1881. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1882. <tab class="content-form form-inline">
  1883. <div class="row">
  1884. '.buildField(array(
  1885. 'type' => 'custom',
  1886. '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>',
  1887. ),12,1,1).'
  1888. '.buildField(array(
  1889. 'type' => 'hidden',
  1890. 'id' => 'tab-'.$data['id'].'-id',
  1891. 'name' => 'id['.$data['id'].']',
  1892. 'value' => $data['id'],
  1893. ),12,2,1).'
  1894. '.buildField(array(
  1895. 'type' => 'text',
  1896. 'id' => 'tab-'.$data['id'].'-name',
  1897. 'name' => 'name['.$data['id'].']',
  1898. 'required' => true,
  1899. 'placeholder' => 'Organizr Homepage',
  1900. 'labelTranslate' => 'TAB_NAME',
  1901. 'value' => $data['name'],
  1902. 'class' => 'darkBold',
  1903. ),12,2,1).'
  1904. '.buildField(array(
  1905. 'type' => 'text',
  1906. 'id' => 'tab-'.$data['id'].'-url',
  1907. 'name' => 'url['.$data['id'].']',
  1908. 'required' => true,
  1909. 'placeholder' => 'homepage.php',
  1910. 'labelTranslate' => 'TAB_URL',
  1911. 'value' => $data['url'],
  1912. 'class' => 'darkBold',
  1913. ),12,2,2).'
  1914. '.buildField(array(
  1915. 'type' => 'text',
  1916. 'id' => 'tab-'.$data['id'].'-iconurl',
  1917. 'name' => 'iconurl['.$data['id'].']',
  1918. 'placeholder' => 'images/organizr.png',
  1919. 'labelTranslate' => 'ICON_URL',
  1920. 'value' => $data['iconurl'],
  1921. 'class' => 'darkBold',
  1922. ),12,2,1).'
  1923. '.buildField(array(
  1924. 'type' => 'text',
  1925. 'id' => 'tab-'.$data['id'].'-icon',
  1926. 'name' => 'icon['.$data['id'].']',
  1927. 'placeholder' => 'fa-icon',
  1928. 'labelTranslate' => 'OR_ICON_NAME',
  1929. 'value' => $data['icon'],
  1930. 'class' => 'iconpickeradd darkBold',
  1931. ),12,1,1).'
  1932. '.buildField(array(
  1933. 'type' => 'text',
  1934. 'id' => 'tab-'.$data['id'].'-ping_url',
  1935. 'name' => 'ping_url['.$data['id'].']',
  1936. 'placeholder' => 'host:port',
  1937. 'labelTranslate' => 'PING_URL',
  1938. 'value' => $data['ping_url'],
  1939. 'class' => 'darkBold',
  1940. ),12,2,1).'
  1941. '.buildField(array(
  1942. 'type' => 'radio',
  1943. 'labelTranslate' => 'DEFAULT',
  1944. 'name' => 'defaultz['.$data['id'].']',
  1945. 'value' => $data['defaultz'],
  1946. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1947. ),12,1,1).'
  1948. '.buildField(array(
  1949. 'type' => 'button',
  1950. 'icon' => 'chevron-down',
  1951. 'buttonType' => 'success',
  1952. 'labelTranslate' => 'MORE',
  1953. 'onclick' => "$(this).parent().parent().parent().find('.slideInUp').toggle()",
  1954. 'class' => 'toggleTabExtra',
  1955. ),12,1,1).'
  1956. '.buildField(array(
  1957. 'type' => 'button',
  1958. 'icon' => 'trash',
  1959. 'buttonType' => 'danger',
  1960. 'labelTranslate' => 'REMOVE',
  1961. 'onclick' => "$(this).parents('li').remove();",
  1962. ),12,1,1).'</div><div id = "tab-'.$data['id'].'-row" class = "row animated slideInUp" style = "display:none;" ><div></div>
  1963. '.buildField(array(
  1964. 'type' => 'checkbox',
  1965. 'labelTranslate' => 'ACTIVE',
  1966. 'name' => 'active['.$data['id'].']',
  1967. 'value' => $data['active'],
  1968. ),12,1,1).'
  1969. '.buildField(array(
  1970. 'type' => 'checkbox',
  1971. 'labelTranslate' => 'USER',
  1972. 'colour' => 'primary',
  1973. 'name' => 'user['.$data['id'].']',
  1974. 'value' => $data['user'],
  1975. ),12,1,1).'
  1976. '.buildField(array(
  1977. 'type' => 'checkbox',
  1978. 'labelTranslate' => 'GUEST',
  1979. 'colour' => 'warning',
  1980. 'name' => 'guest['.$data['id'].']',
  1981. 'value' => $data['guest'],
  1982. ),12,1,1).'
  1983. '.buildField(array(
  1984. 'type' => 'checkbox',
  1985. 'labelTranslate' => 'NO_IFRAME',
  1986. 'colour' => 'danger',
  1987. 'name' => 'window['.$data['id'].']',
  1988. 'value' => $data['window'],
  1989. ),12,1,1).'
  1990. '.buildField(array(
  1991. 'type' => 'checkbox',
  1992. 'labelTranslate' => 'SPLASH',
  1993. 'colour' => 'success',
  1994. 'name' => 'splash['.$data['id'].']',
  1995. 'value' => $data['splash'],
  1996. ),12,1,1).'
  1997. '.buildField(array(
  1998. 'type' => 'checkbox',
  1999. 'labelTranslate' => 'PING',
  2000. 'colour' => 'success',
  2001. 'name' => 'ping['.$data['id'].']',
  2002. 'value' => $data['ping'],
  2003. ),12,1,1).'
  2004. </div>
  2005. </tab>
  2006. </li>
  2007. ';
  2008. return $output;
  2009. }
  2010. // Timezone array
  2011. function timezoneOptions() {
  2012. $output = array();
  2013. $timezones = array();
  2014. $regions = array(
  2015. 'Africa' => DateTimeZone::AFRICA,
  2016. 'America' => DateTimeZone::AMERICA,
  2017. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2018. 'Arctic' => DateTimeZone::ARCTIC,
  2019. 'Asia' => DateTimeZone::ASIA,
  2020. 'Atlantic' => DateTimeZone::ATLANTIC,
  2021. 'Australia' => DateTimeZone::AUSTRALIA,
  2022. 'Europe' => DateTimeZone::EUROPE,
  2023. 'Indian' => DateTimeZone::INDIAN,
  2024. 'Pacific' => DateTimeZone::PACIFIC
  2025. );
  2026. foreach ($regions as $name => $mask) {
  2027. $zones = DateTimeZone::listIdentifiers($mask);
  2028. foreach($zones as $timezone) {
  2029. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2030. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2031. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  2032. }
  2033. }
  2034. return $output;
  2035. }
  2036. // Build Database
  2037. function createSQLiteDB($path = false) {
  2038. if ($path === false) {
  2039. if (DATABASE_LOCATION){
  2040. $path = DATABASE_LOCATION;
  2041. } else {
  2042. debug_out('No Path Specified!');
  2043. }
  2044. }
  2045. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  2046. if (!isset($GLOBALS['file_db'])) {
  2047. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  2048. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2049. }
  2050. // Create Users
  2051. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  2052. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2053. `username` TEXT UNIQUE,
  2054. `password` TEXT,
  2055. `email` TEXT,
  2056. `token` TEXT,
  2057. `role` TEXT,
  2058. `active` TEXT,
  2059. `last` TEXT,
  2060. `auth_service` TEXT DEFAULT \'internal\'
  2061. );');
  2062. // Create Tabs
  2063. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  2064. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2065. `order` INTEGER,
  2066. `users_id` INTEGER,
  2067. `name` TEXT,
  2068. `url` TEXT,
  2069. `defaultz` TEXT,
  2070. `active` TEXT,
  2071. `user` TEXT,
  2072. `guest` TEXT,
  2073. `icon` TEXT,
  2074. `iconurl` TEXT,
  2075. `window` TEXT,
  2076. `splash` TEXT,
  2077. `ping` TEXT,
  2078. `ping_url` TEXT
  2079. );');
  2080. // Create Options
  2081. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  2082. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2083. `users_id` INTEGER UNIQUE,
  2084. `title` TEXT UNIQUE,
  2085. `topbar` TEXT,
  2086. `bottombar` TEXT,
  2087. `sidebar` TEXT,
  2088. `hoverbg` TEXT,
  2089. `topbartext` TEXT,
  2090. `activetabBG` TEXT,
  2091. `activetabicon` TEXT,
  2092. `activetabtext` TEXT,
  2093. `inactiveicon` TEXT,
  2094. `inactivetext` TEXT,
  2095. `loading` TEXT,
  2096. `hovertext` TEXT
  2097. );');
  2098. // Create Invites
  2099. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  2100. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2101. `code` TEXT UNIQUE,
  2102. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  2103. `email` TEXT,
  2104. `username` TEXT,
  2105. `dateused` TIMESTAMP,
  2106. `usedby` TEXT,
  2107. `ip` TEXT,
  2108. `valid` TEXT
  2109. );');
  2110. writeLog("success", "database created/saved");
  2111. return $users && $tabs && $options && $invites;
  2112. } else {
  2113. writeLog("error", "database was unable to be created/saved");
  2114. return false;
  2115. }
  2116. }
  2117. // Upgrade Database
  2118. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  2119. if (!$db_path) {
  2120. if (defined('DATABASE_LOCATION')) {
  2121. $db_path = DATABASE_LOCATION;
  2122. } else {
  2123. debug_out('No Path Specified',1);
  2124. }
  2125. }
  2126. if (!isset($GLOBALS['file_db'])) {
  2127. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  2128. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2129. }
  2130. // Cache current DB
  2131. $cache = array();
  2132. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  2133. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  2134. foreach($row as $k => $v) {
  2135. if (is_string($k)) {
  2136. $cache[$table['name']][$key][$k] = $v;
  2137. }
  2138. }
  2139. }
  2140. }
  2141. // Remove Current Database
  2142. $GLOBALS['file_db'] = null;
  2143. $pathDigest = pathinfo($db_path.'users.db');
  2144. if (file_exists($db_path.'users.db')) {
  2145. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  2146. }
  2147. // Create New Database
  2148. $success = createSQLiteDB($db_path);
  2149. // Restore Items
  2150. if ($success) {
  2151. foreach($cache as $table => $tableData) {
  2152. if ($tableData) {
  2153. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  2154. $insertValues = array();
  2155. reset($tableData);
  2156. foreach($tableData as $key => $value) {
  2157. $insertValues[] = '('.implode(',',array_map(function($d) {
  2158. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  2159. }, $value)).')';
  2160. }
  2161. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  2162. }
  2163. }
  2164. writeLog("success", "database values have been updated");
  2165. return true;
  2166. } else {
  2167. writeLog("error", "database values unable to be updated");
  2168. return false;
  2169. }
  2170. }
  2171. // Commit colours to database
  2172. function updateDBOptions($values) {
  2173. if (!isset($GLOBALS['file_db'])) {
  2174. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2175. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2176. }
  2177. // Commit new values to database
  2178. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  2179. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  2180. }, $values, array_keys($values))).';')->rowCount()) {
  2181. return true;
  2182. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  2183. writeLog("success", "database values for options table have been updated");
  2184. return true;
  2185. } else {
  2186. writeLog("error", "database values for options table unable to be updated");
  2187. return false;
  2188. }
  2189. }
  2190. // Send AJAX notification
  2191. function sendNotification($success, $message = false, $send = true) {
  2192. $notifyExplode = explode("-", NOTIFYEFFECT);
  2193. if ($success) {
  2194. $msg = array(
  2195. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  2196. 'icon' => 'floppy-o',
  2197. 'type' => 'success',
  2198. 'length' => '5000',
  2199. 'layout' => $notifyExplode[0],
  2200. 'effect' => $notifyExplode[1],
  2201. );
  2202. } else {
  2203. $msg = array(
  2204. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2205. 'icon' => 'floppy-o',
  2206. 'type' => 'failed',
  2207. 'length' => '5000',
  2208. 'layout' => $notifyExplode[0],
  2209. 'effect' => $notifyExplode[1],
  2210. );
  2211. }
  2212. // Send and kill script?
  2213. if ($send) {
  2214. header('Content-Type: application/json');
  2215. echo json_encode(array('notify'=>$msg));
  2216. die();
  2217. }
  2218. return $msg;
  2219. }
  2220. // Load colours from the database
  2221. function loadAppearance() {
  2222. // Defaults
  2223. $defaults = array(
  2224. 'title' => 'Organizr',
  2225. 'topbartext' => '#66D9EF',
  2226. 'topbar' => '#333333',
  2227. 'bottombar' => '#333333',
  2228. 'sidebar' => '#393939',
  2229. 'hoverbg' => '#AD80FD',
  2230. 'activetabBG' => '#F92671',
  2231. 'activetabicon' => '#FFFFFF',
  2232. 'activetabtext' => '#FFFFFF',
  2233. 'inactiveicon' => '#66D9EF',
  2234. 'inactivetext' => '#66D9EF',
  2235. 'loading' => '#66D9EF',
  2236. 'hovertext' => '#000000',
  2237. );
  2238. if (DATABASE_LOCATION) {
  2239. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2240. if (!isset($GLOBALS['file_db'])) {
  2241. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2242. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2243. }
  2244. // Database Lookup
  2245. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2246. // Replace defaults with filled options
  2247. foreach($options as $row) {
  2248. foreach($defaults as $key => $value) {
  2249. if (isset($row[$key]) && $row[$key]) {
  2250. $defaults[$key] = $row[$key];
  2251. }
  2252. }
  2253. }
  2254. }
  2255. }
  2256. // Return the Results
  2257. return $defaults;
  2258. }
  2259. // Delete Database
  2260. function deleteDatabase() {
  2261. unset($_COOKIE['Organizr']);
  2262. setcookie('Organizr', '', time() - 3600, '/');
  2263. unset($_COOKIE['OrganizrU']);
  2264. setcookie('OrganizrU', '', time() - 3600, '/');
  2265. $GLOBALS['file_db'] = null;
  2266. unlink(DATABASE_LOCATION.'users.db');
  2267. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2268. if(is_dir($file)) {
  2269. rmdir($file);
  2270. } elseif (!is_dir($file)) {
  2271. unlink($file);
  2272. }
  2273. }
  2274. rmdir($userdirpath);
  2275. writeLog("success", "database has been deleted");
  2276. return true;
  2277. }
  2278. // Upgrade the installation
  2279. function upgradeInstall($branch = 'master') {
  2280. function downloadFile($url, $path){
  2281. ini_set('max_execution_time',0);
  2282. $folderPath = "upgrade/";
  2283. if(!mkdir($folderPath)){
  2284. writeLog("error", "organizr could not create upgrade folder");
  2285. }
  2286. $newfname = $folderPath . $path;
  2287. $file = fopen ($url, 'rb');
  2288. if ($file) {
  2289. $newf = fopen ($newfname, 'wb');
  2290. if ($newf) {
  2291. while(!feof($file)) {
  2292. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2293. }
  2294. }
  2295. }else{
  2296. writeLog("error", "organizr could not download $url");
  2297. }
  2298. if ($file) {
  2299. fclose($file);
  2300. writeLog("success", "organizr finished downloading the github zip file");
  2301. }else{
  2302. writeLog("error", "organizr could not download the github zip file");
  2303. }
  2304. if ($newf) {
  2305. fclose($newf);
  2306. writeLog("success", "organizr created upgrade zip file from github zip file");
  2307. }else{
  2308. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2309. }
  2310. }
  2311. function unzipFile($zipFile){
  2312. $zip = new ZipArchive;
  2313. $extractPath = "upgrade/";
  2314. if($zip->open($extractPath . $zipFile) != "true"){
  2315. writeLog("error", "organizr could not unzip upgrade.zip");
  2316. }else{
  2317. writeLog("success", "organizr unzipped upgrade.zip");
  2318. }
  2319. /* Extract Zip File */
  2320. $zip->extractTo($extractPath);
  2321. $zip->close();
  2322. }
  2323. // Function to remove folders and files
  2324. function rrmdir($dir) {
  2325. if (is_dir($dir)) {
  2326. $files = scandir($dir);
  2327. foreach ($files as $file)
  2328. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2329. rmdir($dir);
  2330. }
  2331. else if (file_exists($dir)) unlink($dir);
  2332. }
  2333. // Function to Copy folders and files
  2334. function rcopy($src, $dst) {
  2335. if (is_dir ( $src )) {
  2336. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2337. $files = scandir ( $src );
  2338. foreach ( $files as $file )
  2339. if ($file != "." && $file != "..")
  2340. rcopy ( "$src/$file", "$dst/$file" );
  2341. } else if (file_exists ( $src ))
  2342. copy ( $src, $dst );
  2343. }
  2344. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2345. $file = "upgrade.zip";
  2346. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2347. $cleanup = __DIR__ . "/upgrade/";
  2348. $destination = __DIR__ . "/";
  2349. writeLog("success", "starting organizr upgrade process");
  2350. downloadFile($url, $file);
  2351. unzipFile($file);
  2352. rcopy($source, $destination);
  2353. writeLog("success", "new organizr files copied");
  2354. rrmdir($cleanup);
  2355. writeLog("success", "organizr upgrade folder removed");
  2356. writeLog("success", "organizr has been updated");
  2357. return true;
  2358. }
  2359. // NzbGET Items
  2360. function nzbgetConnect($list = 'listgroups') {
  2361. $url = qualifyURL(NZBGETURL);
  2362. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2363. $api = json_decode($api, true);
  2364. $gotNZB = array();
  2365. if (is_array($api) || is_object($api)){
  2366. foreach ($api['result'] AS $child) {
  2367. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2368. $downloadStatus = $child['Status'];
  2369. $downloadCategory = $child['Category'];
  2370. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2371. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2372. if($child['Health'] <= "750"){
  2373. $downloadHealth = "danger";
  2374. }elseif($child['Health'] <= "900"){
  2375. $downloadHealth = "warning";
  2376. }elseif($child['Health'] <= "1000"){
  2377. $downloadHealth = "success";
  2378. }
  2379. $gotNZB[] = '<tr>
  2380. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2381. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2382. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2383. <td class="col-xs-1 nzbtable nzbtable-row">'.realSize(($child['FileSizeMB']*1024)*1024).'</td>
  2384. <td class="col-xs-2 nzbtable nzbtable-row">
  2385. <div class="progress">
  2386. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2387. <p class="text-center">'.round($downloadPercent).'%</p>
  2388. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2389. </div>
  2390. </div>
  2391. </td>
  2392. </tr>';
  2393. }
  2394. if ($gotNZB) {
  2395. return implode('',$gotNZB);
  2396. } else {
  2397. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2398. }
  2399. }else{
  2400. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Username and Password - if HTTPS, is cert valid");
  2401. }
  2402. }
  2403. // Sabnzbd Items
  2404. function sabnzbdConnect($list = 'queue') {
  2405. $url = qualifyURL(SABNZBDURL);
  2406. $api = @file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2407. $api = json_decode($api, true);
  2408. $gotNZB = array();
  2409. if (is_array($api) || is_object($api)){
  2410. foreach ($api[$list]['slots'] AS $child) {
  2411. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2412. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2413. $downloadStatus = $child['status'];
  2414. $gotNZB[] = '<tr>
  2415. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2416. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2417. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2418. <td class="col-xs-1 nzbtable nzbtable-row">'.$child['size'].'</td>
  2419. <td class="col-xs-2 nzbtable nzbtable-row">
  2420. <div class="progress">
  2421. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2422. <p class="text-center">'.round($downloadPercent).'%</p>
  2423. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2424. </div>
  2425. </div>
  2426. </td>
  2427. </tr>';
  2428. }
  2429. if ($gotNZB) {
  2430. return implode('',$gotNZB);
  2431. } else {
  2432. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2433. }
  2434. }else{
  2435. writeLog("error", "SABNZBD ERROR: could not connect - check URL and/or check token - if HTTPS, is cert valid");
  2436. }
  2437. }
  2438. // Apply new tab settings
  2439. function updateTabs($tabs) {
  2440. if (!isset($GLOBALS['file_db'])) {
  2441. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2442. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2443. }
  2444. // Validate
  2445. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2446. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2447. // Clear Existing Tabs
  2448. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2449. // Process New Tabs
  2450. $totalValid = 0;
  2451. foreach ($tabs['name'] as $key => $value) {
  2452. // Qualify
  2453. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2454. $totalValid++;
  2455. $fields = array();
  2456. foreach(array('id','name','url','icon','iconurl','order','ping_url') as $v) {
  2457. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2458. }
  2459. foreach(array('active','user','guest','defaultz','window','splash','ping') as $v) {
  2460. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2461. }
  2462. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2463. }
  2464. writeLog("success", "tabs successfully saved");
  2465. return $totalValid;
  2466. } else {
  2467. writeLog("error", "tabs could not save");
  2468. return false;
  2469. }
  2470. writeLog("error", "tabs could not save");
  2471. return false;
  2472. }
  2473. // ==============
  2474. function clean($strin) {
  2475. $strout = null;
  2476. for ($i = 0; $i < strlen($strin); $i++) {
  2477. $ord = ord($strin[$i]);
  2478. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2479. $strout .= "&amp;#{$ord};";
  2480. }
  2481. else {
  2482. switch ($strin[$i]) {
  2483. case '<':
  2484. $strout .= '&lt;';
  2485. break;
  2486. case '>':
  2487. $strout .= '&gt;';
  2488. break;
  2489. case '&':
  2490. $strout .= '&amp;';
  2491. break;
  2492. case '"':
  2493. $strout .= '&quot;';
  2494. break;
  2495. default:
  2496. $strout .= $strin[$i];
  2497. }
  2498. }
  2499. }
  2500. return $strout;
  2501. }
  2502. function registration_callback($username, $email, $userdir){
  2503. global $data;
  2504. $data = array($username, $email, $userdir);
  2505. }
  2506. function printArray($arrayName){
  2507. $messageCount = count($arrayName);
  2508. $i = 0;
  2509. foreach ( $arrayName as $item ) :
  2510. $i++;
  2511. if($i < $messageCount) :
  2512. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2513. elseif($i = $messageCount) :
  2514. echo "<small class='text-uppercase'>" . $item . "</small>";
  2515. endif;
  2516. endforeach;
  2517. }
  2518. function write_ini_file($content, $path) {
  2519. if (!$handle = fopen($path, 'w')) {
  2520. return false;
  2521. }
  2522. $success = fwrite($handle, trim($content));
  2523. fclose($handle);
  2524. return $success;
  2525. }
  2526. function gotTimezone(){
  2527. $regions = array(
  2528. 'Africa' => DateTimeZone::AFRICA,
  2529. 'America' => DateTimeZone::AMERICA,
  2530. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2531. 'Arctic' => DateTimeZone::ARCTIC,
  2532. 'Asia' => DateTimeZone::ASIA,
  2533. 'Atlantic' => DateTimeZone::ATLANTIC,
  2534. 'Australia' => DateTimeZone::AUSTRALIA,
  2535. 'Europe' => DateTimeZone::EUROPE,
  2536. 'Indian' => DateTimeZone::INDIAN,
  2537. 'Pacific' => DateTimeZone::PACIFIC
  2538. );
  2539. $timezones = array();
  2540. foreach ($regions as $name => $mask) {
  2541. $zones = DateTimeZone::listIdentifiers($mask);
  2542. foreach($zones as $timezone) {
  2543. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2544. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2545. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2546. }
  2547. }
  2548. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2549. foreach($timezones as $region => $list) {
  2550. print '<optgroup label="' . $region . '">' . "\n";
  2551. foreach($list as $timezone => $name) {
  2552. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2553. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2554. }
  2555. print '</optgroup>' . "\n";
  2556. }
  2557. print '</select>';
  2558. }
  2559. function getTimezone(){
  2560. $regions = array(
  2561. 'Africa' => DateTimeZone::AFRICA,
  2562. 'America' => DateTimeZone::AMERICA,
  2563. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2564. 'Arctic' => DateTimeZone::ARCTIC,
  2565. 'Asia' => DateTimeZone::ASIA,
  2566. 'Atlantic' => DateTimeZone::ATLANTIC,
  2567. 'Australia' => DateTimeZone::AUSTRALIA,
  2568. 'Europe' => DateTimeZone::EUROPE,
  2569. 'Indian' => DateTimeZone::INDIAN,
  2570. 'Pacific' => DateTimeZone::PACIFIC
  2571. );
  2572. $timezones = array();
  2573. foreach ($regions as $name => $mask) {
  2574. $zones = DateTimeZone::listIdentifiers($mask);
  2575. foreach($zones as $timezone) {
  2576. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2577. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2578. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2579. }
  2580. }
  2581. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2582. foreach($timezones as $region => $list) {
  2583. print '<optgroup label="' . $region . '">' . "\n";
  2584. foreach($list as $timezone => $name) {
  2585. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2586. }
  2587. print '</optgroup>' . "\n";
  2588. }
  2589. print '</select>';
  2590. }
  2591. function explosion($string, $position){
  2592. $getWord = explode("|", $string);
  2593. return $getWord[$position];
  2594. }
  2595. function getServerPath() {
  2596. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2597. $protocol = "https://";
  2598. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2599. $protocol = "https://";
  2600. } else {
  2601. $protocol = "http://";
  2602. }
  2603. $domain = '';
  2604. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2605. $domain = $_SERVER['SERVER_NAME'];
  2606. }elseif(isset($_SERVER['HTTP_HOST'])){
  2607. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2608. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2609. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2610. if ($port == "80" || $port == "443"){
  2611. $domain = $domain;
  2612. }else{
  2613. $domain = $_SERVER['HTTP_HOST'];
  2614. }
  2615. }else{
  2616. $domain = $_SERVER['HTTP_HOST'];
  2617. }
  2618. }
  2619. return $protocol . $domain . str_replace("\\", "/", dirname($_SERVER['REQUEST_URI']));
  2620. }
  2621. function get_browser_name() {
  2622. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2623. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2624. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2625. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2626. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2627. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2628. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2629. return 'Other';
  2630. }
  2631. function getSickrageCalendarWanted($array){
  2632. $array = json_decode($array, true);
  2633. //$gotCalendar = "";
  2634. $gotCalendar = array();
  2635. $i = 0;
  2636. foreach($array['data']['missed'] AS $child) {
  2637. $i++;
  2638. $seriesName = $child['show_name'];
  2639. $episodeID = $child['tvdbid'];
  2640. $episodeAirDate = $child['airdate'];
  2641. $episodeAirDateTime = explode(" ",$child['airs']);
  2642. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2643. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2644. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2645. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2646. $downloaded = "0";
  2647. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2648. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2649. array_push($gotCalendar, array(
  2650. "id" => "Sick-Miss-".$i,
  2651. "title" => $seriesName,
  2652. "start" => $episodeAirDate,
  2653. "className" => $downloaded." tvID--".$episodeID,
  2654. "imagetype" => "tv",
  2655. ));
  2656. }
  2657. foreach($array['data']['today'] AS $child) {
  2658. $i++;
  2659. $seriesName = $child['show_name'];
  2660. $episodeID = $child['tvdbid'];
  2661. $episodeAirDate = $child['airdate'];
  2662. $episodeAirDateTime = explode(" ",$child['airs']);
  2663. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2664. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2665. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2666. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2667. $downloaded = "0";
  2668. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2669. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2670. array_push($gotCalendar, array(
  2671. "id" => "Sick-Today-".$i,
  2672. "title" => $seriesName,
  2673. "start" => $episodeAirDate,
  2674. "className" => $downloaded." tvID--".$episodeID,
  2675. "imagetype" => "tv",
  2676. ));
  2677. }
  2678. foreach($array['data']['soon'] AS $child) {
  2679. $i++;
  2680. $seriesName = $child['show_name'];
  2681. $episodeID = $child['tvdbid'];
  2682. $episodeAirDate = $child['airdate'];
  2683. $episodeAirDateTime = explode(" ",$child['airs']);
  2684. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2685. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2686. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2687. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2688. $downloaded = "0";
  2689. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2690. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2691. array_push($gotCalendar, array(
  2692. "id" => "Sick-Soon-".$i,
  2693. "title" => $seriesName,
  2694. "start" => $episodeAirDate,
  2695. "className" => $downloaded." tvID--".$episodeID,
  2696. "imagetype" => "tv",
  2697. ));
  2698. }
  2699. foreach($array['data']['later'] AS $child) {
  2700. $i++;
  2701. $seriesName = $child['show_name'];
  2702. $episodeID = $child['tvdbid'];
  2703. $episodeAirDate = $child['airdate'];
  2704. $episodeAirDateTime = explode(" ",$child['airs']);
  2705. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2706. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2707. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2708. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2709. $downloaded = "0";
  2710. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2711. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2712. array_push($gotCalendar, array(
  2713. "id" => "Sick-Later-".$i,
  2714. "title" => $seriesName,
  2715. "start" => $episodeAirDate,
  2716. "className" => $downloaded." tvID--".$episodeID,
  2717. "imagetype" => "tv",
  2718. ));
  2719. }
  2720. if ($i != 0){ return $gotCalendar; }
  2721. }
  2722. function getSickrageCalendarHistory($array){
  2723. $array = json_decode($array, true);
  2724. //$gotCalendar = "";
  2725. $gotCalendar = array();
  2726. $i = 0;
  2727. foreach($array['data'] AS $child) {
  2728. $i++;
  2729. $seriesName = $child['show_name'];
  2730. $episodeID = $child['tvdbid'];
  2731. $episodeAirDate = $child['date'];
  2732. $downloaded = "green-bg";
  2733. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2734. array_push($gotCalendar, array(
  2735. "id" => "Sick-History-".$i,
  2736. "title" => $seriesName,
  2737. "start" => $episodeAirDate,
  2738. "className" => $downloaded." tvID--".$episodeID,
  2739. "imagetype" => "tv",
  2740. ));
  2741. }
  2742. if ($i != 0){ return $gotCalendar; }
  2743. }
  2744. function getSonarrCalendar($array){
  2745. $array = json_decode($array, true);
  2746. //$gotCalendar = "";
  2747. $gotCalendar = array();
  2748. $i = 0;
  2749. foreach($array AS $child) {
  2750. $i++;
  2751. $seriesName = $child['series']['title'];
  2752. $episodeID = $child['series']['tvdbId'];
  2753. if(!isset($episodeID)){ $episodeID = ""; }
  2754. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2755. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2756. $episodeAirDate = $child['airDateUtc'];
  2757. $episodeAirDate = strtotime($episodeAirDate);
  2758. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2759. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2760. $downloaded = $child['hasFile'];
  2761. 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"; }
  2762. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2763. array_push($gotCalendar, array(
  2764. "id" => "Sonarr-".$i,
  2765. "title" => $seriesName,
  2766. "start" => $episodeAirDate,
  2767. "className" => $downloaded." tvID--".$episodeID,
  2768. "imagetype" => "tv",
  2769. ));
  2770. }
  2771. if ($i != 0){ return $gotCalendar; }
  2772. }
  2773. function getCouchCalendar(){
  2774. $url = qualifyURL(COUCHURL);
  2775. $api = curl_get($url."/api/".COUCHAPI."/media.list");
  2776. $api = json_decode($api, true);
  2777. $i = 0;
  2778. $gotCalendar = array();
  2779. if (is_array($api) || is_object($api)){
  2780. foreach($api['movies'] AS $child) {
  2781. if($child['status'] == "active" || $child['status'] == "done" ){
  2782. $i++;
  2783. $movieName = $child['info']['original_title'];
  2784. $movieID = $child['info']['tmdb_id'];
  2785. if(!isset($movieID)){ $movieID = ""; }
  2786. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  2787. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  2788. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  2789. $physicalRelease = strtotime($physicalRelease);
  2790. $physicalRelease = date("Y-m-d", $physicalRelease);
  2791. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2792. $downloaded = ($child['status'] == "active") ? "0" : "1";
  2793. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2794. array_push($gotCalendar, array(
  2795. "id" => "CouchPotato-".$i,
  2796. "title" => $movieName,
  2797. "start" => $physicalRelease,
  2798. "className" => $downloaded." movieID--".$movieID,
  2799. "imagetype" => "film",
  2800. ));
  2801. }
  2802. }
  2803. if ($i != 0){ return $gotCalendar; }
  2804. }else{
  2805. writeLog("error", "CouchPotato ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2806. }
  2807. }
  2808. function getRadarrCalendar($array){
  2809. $array = json_decode($array, true);
  2810. $gotCalendar = array();
  2811. $i = 0;
  2812. foreach($array AS $child) {
  2813. if(isset($child['physicalRelease'])){
  2814. $i++;
  2815. $movieName = $child['title'];
  2816. $movieID = $child['tmdbId'];
  2817. if(!isset($movieID)){ $movieID = ""; }
  2818. $physicalRelease = $child['physicalRelease'];
  2819. $physicalRelease = strtotime($physicalRelease);
  2820. $physicalRelease = date("Y-m-d", $physicalRelease);
  2821. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2822. $downloaded = $child['hasFile'];
  2823. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2824. array_push($gotCalendar, array(
  2825. "id" => "Radarr-".$i,
  2826. "title" => $movieName,
  2827. "start" => $physicalRelease,
  2828. "className" => $downloaded." movieID--".$movieID,
  2829. "imagetype" => "film",
  2830. ));
  2831. }
  2832. }
  2833. if ($i != 0){ return $gotCalendar; }
  2834. }
  2835. function getHeadphonesCalendar($url, $key, $list){
  2836. $url = qualifyURL(HEADPHONESURL);
  2837. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2838. $api = json_decode($api, true);
  2839. $i = 0;
  2840. //$gotCalendar = "";
  2841. $gotCalendar = array();;
  2842. if (is_array($api) || is_object($api)){
  2843. foreach($api AS $child) {
  2844. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2845. $i++;
  2846. $albumName = addslashes($child['AlbumTitle']);
  2847. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2848. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2849. $albumID = $child['AlbumID'];
  2850. $albumDate = strtotime($albumDate);
  2851. $albumDate = date("Y-m-d", $albumDate);
  2852. $albumStatus = $child['Status'];
  2853. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2854. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2855. //$gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2856. array_push($gotCalendar, array(
  2857. "id" => "Headphones-".$i,
  2858. "title" => $albumArtist.' - '.$albumName,
  2859. "start" => $albumDate,
  2860. "className" => $albumStatusColor,
  2861. "imagetype" => "music",
  2862. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2863. ));
  2864. }
  2865. if($child['Status'] == "Processed" && $list == "getHistory"){
  2866. $i++;
  2867. $find = array('_','[', ']', '\n');
  2868. $replace = array(' ','(', ')', ' ');
  2869. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  2870. $albumDate = $child['DateAdded'];
  2871. $albumID = $child['AlbumID'];
  2872. $albumDate = strtotime($albumDate);
  2873. $albumDate = date("Y-m-d", $albumDate);
  2874. $albumStatusColor = "green-bg";
  2875. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2876. //$gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2877. array_push($gotCalendar, array(
  2878. "id" => "Headphones-".$i,
  2879. "title" => $albumName,
  2880. "start" => $albumDate,
  2881. "className" => $albumStatusColor,
  2882. "imagetype" => "music",
  2883. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2884. ));
  2885. }
  2886. }
  2887. if ($i != 0){ return $gotCalendar; }
  2888. }else{
  2889. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2890. }
  2891. }
  2892. function checkRootPath($string){
  2893. if($string == "\\" || $string == "/"){
  2894. return "/";
  2895. }else{
  2896. return str_replace("\\", "/", $string) . "/";
  2897. }
  2898. }
  2899. function strip($string){
  2900. $string = strip_tags($string);
  2901. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  2902. }
  2903. function writeLog($type, $message){
  2904. if(file_exists(DATABASE_LOCATION."org.log")){
  2905. if(filesize(DATABASE_LOCATION."org.log") > 500000){
  2906. rename(DATABASE_LOCATION.'org.log',DATABASE_LOCATION.'org['.date('Y-m-d').'].log');
  2907. $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";
  2908. file_put_contents(DATABASE_LOCATION."org.log", $message2, FILE_APPEND | LOCK_EX);
  2909. }
  2910. }
  2911. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  2912. file_put_contents(DATABASE_LOCATION."org.log", $message, FILE_APPEND | LOCK_EX);
  2913. }
  2914. function readLog(){
  2915. $log = file(DATABASE_LOCATION."org.log",FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  2916. $log = array_reverse($log);
  2917. foreach($log as $line){
  2918. if(substr_count($line, '|') == 2){
  2919. $line = explode("|", strip($line));
  2920. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  2921. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  2922. }
  2923. }
  2924. }
  2925. function buildStream($array){
  2926. $result = "";
  2927. if (array_key_exists('platform', $array)) {
  2928. $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>';
  2929. }
  2930. if (array_key_exists('device', $array)) {
  2931. $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>';
  2932. }
  2933. if (array_key_exists('stream', $array)) {
  2934. $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>';
  2935. }
  2936. if (array_key_exists('video', $array)) {
  2937. $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>';
  2938. }
  2939. if (array_key_exists('audio', $array)) {
  2940. $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>';
  2941. }
  2942. return $result;
  2943. }
  2944. function streamType($value){
  2945. if($value == "transcode" || $value == "Transcode"){
  2946. return "Transcode";
  2947. }elseif($value == "copy" || $value == "DirectStream"){
  2948. return "Direct Stream";
  2949. }elseif($value == "directplay" || $value == "DirectPlay"){
  2950. return "Direct Play";
  2951. }else{
  2952. return "Direct Play";
  2953. }
  2954. }
  2955. function getPlatform($platform){
  2956. $allPlatforms = array(
  2957. "Chrome" => "chrome.png",
  2958. "tvOS" => "atv.png",
  2959. "iOS" => "ios.png",
  2960. "Xbox One" => "xbox.png",
  2961. "Mystery 4" => "playstation.png",
  2962. "Samsung" => "samsung.png",
  2963. "Roku" => "roku.png",
  2964. "Emby for iOS" => "ios.png",
  2965. "Emby Mobile" => "emby.png",
  2966. "Emby Theater" => "emby.png",
  2967. "Emby Classic" => "emby.png",
  2968. "Safari" => "safari.png",
  2969. "Android" => "android.png",
  2970. "AndroidTv" => "android.png",
  2971. "Chromecast" => "chromecast.png",
  2972. "Dashboard" => "emby.png",
  2973. "Dlna" => "dlna.png",
  2974. "Windows Phone" => "wp.png",
  2975. "Windows RT" => "win8.png",
  2976. "Kodi" => "kodi.png",
  2977. );
  2978. if (array_key_exists($platform, $allPlatforms)) {
  2979. return $allPlatforms[$platform];
  2980. }else{
  2981. return "pmp.png";
  2982. }
  2983. }
  2984. function getServer(){
  2985. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  2986. return $server;
  2987. }
  2988. function prettyPrint($array) {
  2989. echo "<pre>";
  2990. print_r($array);
  2991. echo "</pre>";
  2992. echo "<br/>";
  2993. }
  2994. function checkFrame($array, $url){
  2995. if(array_key_exists("x-frame-options", $array)){
  2996. if($array['x-frame-options'] == "deny"){
  2997. return false;
  2998. }elseif($array['x-frame-options'] == "sameorgin"){
  2999. $digest = parse_url($url);
  3000. $host = (isset($digest['host'])?$digest['host']:'');
  3001. if(getServer() == $host){
  3002. return true;
  3003. }else{
  3004. return false;
  3005. }
  3006. }
  3007. }else{
  3008. if(!$array){
  3009. return false;
  3010. }
  3011. return true;
  3012. }
  3013. }
  3014. function frameTest($url){
  3015. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  3016. $url = qualifyURL($url);
  3017. if(checkFrame($array, $url)){
  3018. return true;
  3019. }else{
  3020. return false;
  3021. }
  3022. }
  3023. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  3024. $notifyExplode = explode("-", NOTIFYEFFECT);
  3025. if ($result) {
  3026. $msg = array(
  3027. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  3028. 'icon' => $icon,
  3029. 'type' => 'success',
  3030. 'length' => '5000',
  3031. 'layout' => $notifyExplode[0],
  3032. 'effect' => $notifyExplode[1],
  3033. );
  3034. } else {
  3035. $msg = array(
  3036. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  3037. 'icon' => $icon,
  3038. 'type' => 'error',
  3039. 'length' => '5000',
  3040. 'layout' => $notifyExplode[0],
  3041. 'effect' => $notifyExplode[1],
  3042. );
  3043. }
  3044. // Send and kill script?
  3045. if ($send) {
  3046. header('Content-Type: application/json');
  3047. echo json_encode(array('notify'=>$msg));
  3048. die();
  3049. }
  3050. return $msg;
  3051. }
  3052. function buildHomepageNotice($layout, $type, $title, $message){
  3053. switch ($layout) {
  3054. case 'elegant':
  3055. return '
  3056. <div id="homepageNotice" class="row">
  3057. <div class="col-lg-12">
  3058. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  3059. <div class="content-title i-block">
  3060. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  3061. <div class="content-tools i-block pull-right">
  3062. <a class="close-btn">
  3063. <i class="fa fa-times"></i>
  3064. </a>
  3065. </div>
  3066. </div>
  3067. '.$message.'
  3068. </div>
  3069. </div>
  3070. </div>
  3071. ';
  3072. break;
  3073. case 'basic':
  3074. return '
  3075. <div id="homepageNotice" class="row">
  3076. <div class="col-lg-12">
  3077. <div class="panel panel-'.$type.'">
  3078. <div class="panel-heading">
  3079. <h3 class="panel-title">'.$title.'</h3>
  3080. </div>
  3081. <div class="panel-body">
  3082. '.$message.'
  3083. </div>
  3084. </div>
  3085. </div>
  3086. </div>
  3087. ';
  3088. break;
  3089. case 'jumbotron';
  3090. return '
  3091. <div id="homepageNotice" class="row">
  3092. <div class="col-lg-12">
  3093. <div class="jumbotron">
  3094. <div class="container">
  3095. <h1>'.$title.'</h1>
  3096. <p>'.$message.'</p>
  3097. </div>
  3098. </div>
  3099. </div>
  3100. </div>
  3101. ';
  3102. }
  3103. }
  3104. function embyArray($array, $type) {
  3105. $key = ($type == "video" ? "Height" : "Channels");
  3106. if (array_key_exists($key, $array)) {
  3107. switch ($type) {
  3108. case "video":
  3109. $codec = $array["Codec"];
  3110. $height = $array["Height"];
  3111. $width = $array["Width"];
  3112. break;
  3113. default:
  3114. $codec = $array["Codec"];
  3115. $channels = $array["Channels"];
  3116. }
  3117. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  3118. }
  3119. foreach ($array as $element) {
  3120. if (is_array($element)) {
  3121. if (embyArray($element, $type)) {
  3122. return embyArray($element, $type);
  3123. }
  3124. }
  3125. }
  3126. }
  3127. // Get Now Playing Streams From Plex
  3128. function searchPlex($query){
  3129. $address = qualifyURL(PLEXURL);
  3130. $openTab = (PLEXTABNAME) ? "true" : "false";
  3131. // Perform API requests
  3132. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  3133. libxml_use_internal_errors(true);
  3134. $api = simplexml_load_string($api);
  3135. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3136. if (!$getServer) { return 'Could not load!'; }
  3137. // Identify the local machine
  3138. $server = $getServer['machineIdentifier'];
  3139. $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>";
  3140. $items = "";
  3141. $albums = $movies = $shows = 0;
  3142. $style = 'style="vertical-align: middle"';
  3143. foreach($api AS $child) {
  3144. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  3145. $time = (string)$child['addedAt'];
  3146. $time = new DateTime("@$time");
  3147. $results = array(
  3148. "title" => (string)$child['title'],
  3149. "image" => (string)$child['thumb'],
  3150. "type" => (string)ucwords($child['type']),
  3151. "year" => (string)$child['year'],
  3152. "key" => (string)$child['ratingKey']."-search",
  3153. "ratingkey" => (string)$child['ratingKey'],
  3154. "genre" => (string)$child->Genre['tag'],
  3155. "added" => $time->format('Y-m-d'),
  3156. "extra" => "",
  3157. );
  3158. switch ($child['type']){
  3159. case "album":
  3160. $push = array(
  3161. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  3162. );
  3163. $results = array_replace($results,$push);
  3164. $albums++;
  3165. break;
  3166. case "movie":
  3167. $push = array(
  3168. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  3169. );
  3170. $results = array_replace($results,$push);
  3171. $movies++;
  3172. break;
  3173. case "show":
  3174. $push = array(
  3175. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  3176. );
  3177. $results = array_replace($results,$push);
  3178. $shows++;
  3179. break;
  3180. }
  3181. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  3182. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  3183. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  3184. }
  3185. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  3186. if (PLEXTABURL) {
  3187. $link = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3188. }else{
  3189. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3190. }
  3191. $items .= '<tr style="cursor: pointer;" class="openTab" extraTitle="'.$results['title'].'" extraType="'.$child['type'].'" openTab="'.$openTab.'" href="'.$link.'">
  3192. <th scope="row"><img src="'.$image_url.'"></th>
  3193. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  3194. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  3195. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  3196. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  3197. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  3198. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  3199. </tr>';
  3200. }
  3201. }
  3202. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  3203. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  3204. font-size: 23px;
  3205. ">&nbsp;'.$movies.'</strong></span>
  3206. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  3207. font-size: 23px;
  3208. ">&nbsp;'.$shows.'</strong></span>
  3209. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  3210. font-size: 23px;
  3211. ">&nbsp;'.$albums.'</strong></span>
  3212. </div>';
  3213. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  3214. }
  3215. function getBannedUsers($string){
  3216. if (strpos($string, ',') !== false) {
  3217. $banned = explode(",", $string);
  3218. }else{
  3219. $banned = array($string);
  3220. }
  3221. return $banned;
  3222. }
  3223. function getWhitelist($string){
  3224. if (strpos($string, ',') !== false) {
  3225. $whitelist = explode(",", $string);
  3226. }else{
  3227. $whitelist = array($string);
  3228. }
  3229. foreach($whitelist as &$ip){
  3230. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  3231. }
  3232. return $whitelist;
  3233. }
  3234. function get_client_ip() {
  3235. $ipaddress = '';
  3236. if (isset($_SERVER['HTTP_CLIENT_IP']))
  3237. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  3238. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  3239. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3240. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  3241. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  3242. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  3243. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  3244. else if(isset($_SERVER['HTTP_FORWARDED']))
  3245. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  3246. else if(isset($_SERVER['REMOTE_ADDR']))
  3247. $ipaddress = $_SERVER['REMOTE_ADDR'];
  3248. else
  3249. $ipaddress = 'UNKNOWN';
  3250. return $ipaddress;
  3251. }
  3252. //EMAIL SHIT
  3253. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  3254. $mail = new PHPMailer;
  3255. $mail->isSMTP();
  3256. $mail->Host = SMTPHOST;
  3257. $mail->SMTPAuth = SMTPHOSTAUTH;
  3258. $mail->Username = SMTPHOSTUSERNAME;
  3259. $mail->Password = SMTPHOSTPASSWORD;
  3260. $mail->SMTPSecure = SMTPHOSTTYPE;
  3261. $mail->Port = SMTPHOSTPORT;
  3262. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3263. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3264. $mail->isHTML(true);
  3265. if($email){
  3266. $mail->addAddress($email, $username);
  3267. }
  3268. if($cc){
  3269. $mail->addCC($cc);
  3270. }
  3271. if($bcc){
  3272. if(strpos($bcc , ',') === false){
  3273. $mail->addBCC($bcc);
  3274. }else{
  3275. $allEmails = explode(",",$bcc);
  3276. foreach($allEmails as $gotEmail){
  3277. $mail->addBCC($gotEmail);
  3278. }
  3279. }
  3280. }
  3281. $mail->Subject = $subject;
  3282. $mail->Body = $body;
  3283. //$mail->send();
  3284. if(!$mail->send()) {
  3285. writeLog("error", "mail failed to send");
  3286. } else {
  3287. writeLog("success", "mail has been sent");
  3288. }
  3289. }
  3290. //EMAIL SHIT
  3291. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  3292. $mail = new PHPMailer;
  3293. $mail->isSMTP();
  3294. $mail->Host = $host;
  3295. $mail->SMTPAuth = $auth;
  3296. $mail->Username = $username;
  3297. $mail->Password = $password;
  3298. $mail->SMTPSecure = $type;
  3299. $mail->Port = $port;
  3300. $mail->setFrom($from, $sendername);
  3301. $mail->addReplyTo($from, $sendername);
  3302. $mail->isHTML(true);
  3303. $mail->addAddress($to, "Organizr Admin");
  3304. $mail->Subject = "Organizr Test E-Mail";
  3305. $mail->Body = "This was just a test!";
  3306. //$mail->send();
  3307. if(!$mail->send()) {
  3308. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  3309. return false;
  3310. } else {
  3311. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  3312. return true;
  3313. }
  3314. }
  3315. function libraryList(){
  3316. $address = qualifyURL(PLEXURL);
  3317. $headers = array(
  3318. "Accept" => "application/json",
  3319. "X-Plex-Token" => PLEXTOKEN
  3320. );
  3321. libxml_use_internal_errors(true);
  3322. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3323. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3324. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  3325. $libraryList = array();
  3326. foreach($api->SharedServer->Section AS $child) {
  3327. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  3328. }
  3329. foreach($api->SharedServer AS $child) {
  3330. if(!empty($child['username'])){
  3331. $username = (string)strtolower($child['username']);
  3332. $email = (string)strtolower($child['email']);
  3333. $libraryList['users'][$username] = (string)$child['id'];
  3334. $libraryList['emails'][$email] = (string)$child['id'];
  3335. $libraryList['both'][$username] = $email;
  3336. }
  3337. }
  3338. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3339. }
  3340. function plexUserShare($username){
  3341. $address = qualifyURL(PLEXURL);
  3342. $headers = array(
  3343. "Accept" => "application/json",
  3344. "Content-Type" => "application/json",
  3345. "X-Plex-Token" => PLEXTOKEN
  3346. );
  3347. libxml_use_internal_errors(true);
  3348. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3349. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3350. $json = array(
  3351. "server_id" => $gotServer,
  3352. "shared_server" => array(
  3353. //"library_section_ids" => "[26527637]",
  3354. "invited_email" => $username
  3355. )
  3356. );
  3357. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3358. switch ($api['http_code']['http_code']){
  3359. case 400:
  3360. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3361. $result = "$username already has access to the shared libraries";
  3362. break;
  3363. case 401:
  3364. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3365. $result = "Invalid Plex Token";
  3366. break;
  3367. case 200:
  3368. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3369. $result = "$username now has access to your Plex Library";
  3370. break;
  3371. default:
  3372. writeLog("error", "PLEX INVITE: unknown error");
  3373. $result = false;
  3374. }
  3375. return (!empty($result) ? $result : null );
  3376. }
  3377. function plexUserDelete($username){
  3378. $address = qualifyURL(PLEXURL);
  3379. $headers = array(
  3380. "Accept" => "application/json",
  3381. "Content-Type" => "application/json",
  3382. "X-Plex-Token" => PLEXTOKEN
  3383. );
  3384. libxml_use_internal_errors(true);
  3385. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3386. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3387. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3388. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3389. switch ($api['http_code']['http_code']){
  3390. case 401:
  3391. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3392. $result = "Invalid Plex Token";
  3393. break;
  3394. case 200:
  3395. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3396. $result = "$username doesn't have access to your Plex Library anymore";
  3397. break;
  3398. default:
  3399. writeLog("error", "PLEX INVITE: unknown error");
  3400. $result = false;
  3401. }
  3402. return (!empty($result) ? $result : null );
  3403. }
  3404. function convertPlexName($user, $type){
  3405. $array = libraryList();
  3406. switch ($type){
  3407. case "username":
  3408. $plexUser = array_search ($user, $array['users']);
  3409. break;
  3410. case "id":
  3411. if (array_key_exists(strtolower($user), $array['users'])) {
  3412. $plexUser = $array['users'][strtolower($user)];
  3413. }
  3414. break;
  3415. default:
  3416. $plexUser = false;
  3417. }
  3418. return (!empty($plexUser) ? $plexUser : null );
  3419. }
  3420. function randomCode($length = 5, $type = null) {
  3421. switch ($type){
  3422. case "alpha":
  3423. $legend = array_merge(range('A', 'Z'));
  3424. break;
  3425. case "numeric":
  3426. $legend = array_merge(range(0,9));
  3427. break;
  3428. default:
  3429. $legend = array_merge(range(0,9),range('A', 'Z'));
  3430. }
  3431. $code = "";
  3432. for($i=0; $i < $length; $i++) {
  3433. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3434. }
  3435. return $code;
  3436. }
  3437. function inviteCodes($action, $code = null, $usedBy = null) {
  3438. if (!isset($GLOBALS['file_db'])) {
  3439. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3440. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3441. }
  3442. $now = date("Y-m-d H:i:s");
  3443. switch ($action) {
  3444. case "get":
  3445. // Start Array
  3446. $result = array();
  3447. // Database Lookup
  3448. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3449. // Get Codes
  3450. foreach($invites as $row) {
  3451. array_push($result, $row['code']);
  3452. }
  3453. // Return the Results
  3454. return (!empty($result) ? $result : false );
  3455. break;
  3456. case "check":
  3457. // Start Array
  3458. $result = array();
  3459. // Database Lookup
  3460. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3461. // Get Codes
  3462. foreach($invites as $row) {
  3463. $result = $row['code'];
  3464. }
  3465. // Return the Results
  3466. return (!empty($result) ? $result : false );
  3467. break;
  3468. case "use":
  3469. $currentIP = get_client_ip();
  3470. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3471. if(ENABLEMAIL){
  3472. if (!isset($GLOBALS['USER'])) {
  3473. require_once("user.php");
  3474. $GLOBALS['USER'] = new User('registration_callback');
  3475. }
  3476. 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."));
  3477. }
  3478. return (!empty($invites) ? true : false );
  3479. break;
  3480. }
  3481. }
  3482. function plexJoin($username, $email, $password){
  3483. $connectURL = 'https://plex.tv/users.json';
  3484. $headers = array(
  3485. 'Accept'=> 'application/json',
  3486. 'Content-Type' => 'application/x-www-form-urlencoded',
  3487. 'X-Plex-Product' => 'Organizr',
  3488. 'X-Plex-Version' => '1.0',
  3489. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3490. );
  3491. $body = array(
  3492. 'user[email]' => $email,
  3493. 'user[username]' => $username,
  3494. 'user[password]' => $password,
  3495. );
  3496. $api = curl_post($connectURL, $body, $headers);
  3497. $json = json_decode($api['content'], true);
  3498. $errors = (!empty($json['errors']) ? true : false);
  3499. $success = (!empty($json['user']) ? true : false);
  3500. //Use This for later
  3501. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3502. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3503. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3504. $errorMessage = "";
  3505. if($errors){
  3506. if($usernameError){ $errorMessage .= "[Username Error: ". $usernameError ."]"; }
  3507. if($emailError){ $errorMessage .= "[Email Error: ". $emailError ."]"; }
  3508. if($passwordError){ $errorMessage .= "[Password Error: ". $passwordError ."]"; }
  3509. }
  3510. switch ($api['http_code']['http_code']){
  3511. case 400:
  3512. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." $username already has access to the shared libraries $errorMessage");
  3513. break;
  3514. case 401:
  3515. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." invalid Plex Token $errorMessage");
  3516. break;
  3517. case 422:
  3518. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." user info error $errorMessage");
  3519. break;
  3520. case 429:
  3521. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." too many requests to plex.tv please try later $errorMessage");
  3522. break;
  3523. case 200:
  3524. case 201:
  3525. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3526. break;
  3527. default:
  3528. writeLog("error", "PLEX JOIN: unknown error, $errorMessage Error: ".$api['http_code']['http_code']);
  3529. }
  3530. //prettyPrint($api);
  3531. //prettyPrint(json_decode($api['content'], true));
  3532. return (!empty($success) && empty($errors) ? true : false );
  3533. }
  3534. function getCert(){
  3535. $url = "http://curl.haxx.se/ca/cacert.pem";
  3536. $file = getcwd()."/config/cacert.pem";
  3537. $directory = getcwd()."/config/";
  3538. @mkdir($directory, 0770, true);
  3539. if(!file_exists($file)){
  3540. file_put_contents( $file, fopen($url, 'r'));
  3541. writeLog("success", "CERT PEM: pem file created");
  3542. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3543. file_put_contents( $file, fopen($url, 'r'));
  3544. writeLog("success", "CERT PEM: downloaded new pem file");
  3545. }
  3546. return $file;
  3547. }
  3548. function customCSS(){
  3549. if(CUSTOMCSS == "true") {
  3550. $template_file = "custom.css";
  3551. $file_handle = fopen($template_file, "rb");
  3552. echo "\n";
  3553. echo fread($file_handle, filesize($template_file));
  3554. fclose($file_handle);
  3555. echo "\n";
  3556. }
  3557. }
  3558. function tvdbToken(){
  3559. $headers = array(
  3560. "Accept" => "application/json",
  3561. "Content-Type" => "application/json"
  3562. );
  3563. $json = array(
  3564. "apikey" => "FBE7B62621F4CAD7",
  3565. "userkey" => "328BB46EB1E9A0F5",
  3566. "username" => "causefx"
  3567. );
  3568. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3569. return json_decode($api['content'], true)['token'];
  3570. }
  3571. function tvdbGet($id){
  3572. $headers = array(
  3573. "Accept" => "application/json",
  3574. "Authorization" => "Bearer ".tvdbToken(),
  3575. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3576. "trakt-api-version" => "2"
  3577. );
  3578. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3579. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3580. if(empty($api['trakt'])){
  3581. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3582. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3583. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3584. $api['series'] = json_decode($series, true)['data'];
  3585. $api['poster'] = json_decode($poster, true)['data'];
  3586. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3587. }
  3588. return $api;
  3589. }
  3590. function tvdbSearch($name, $type){
  3591. $name = rawurlencode(preg_replace("/\(([^()]*+|(?R))*\)/","", $name));
  3592. $headers = array(
  3593. "Accept" => "application/json",
  3594. "Authorization" => "Bearer ".tvdbToken(),
  3595. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3596. "trakt-api-version" => "2"
  3597. );
  3598. $trakt = curl_get("https://api.trakt.tv/search/$type?query=$name", $headers);
  3599. @$api['trakt'] = json_decode($trakt, true)[0][$type]['ids'];
  3600. return $api;
  3601. }
  3602. function getPlexPlaylists(){
  3603. $address = qualifyURL(PLEXURL);
  3604. // Perform API requests
  3605. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3606. libxml_use_internal_errors(true);
  3607. $api = simplexml_load_string($api);
  3608. if (is_array($api) || is_object($api)){
  3609. if (!$api->head->title){
  3610. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3611. if (!$getServer) { return 'Could not load!'; }
  3612. // Identify the local machine
  3613. $gotServer = $getServer['machineIdentifier'];
  3614. $output = "";
  3615. $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">';
  3616. foreach($api AS $child) {
  3617. $items = array();
  3618. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3619. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3620. $api = simplexml_load_string($api);
  3621. if (is_array($api) || is_object($api)){
  3622. if (!$api->head->title){
  3623. $className = preg_replace("/(\W)+/", "", $api['title']);
  3624. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3625. foreach($api->Video AS $child){
  3626. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3627. }
  3628. if (count($items)) {
  3629. $output .= ''.implode('',$items).'';
  3630. }
  3631. }
  3632. }
  3633. }
  3634. }
  3635. $hideMenu .= '</ul></div></div>';
  3636. 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>';
  3637. }else{
  3638. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3639. }
  3640. }else{
  3641. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3642. }
  3643. }
  3644. function readExternalLog($type,$filename,$name = null){
  3645. $log = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3646. $log = array_reverse($log);
  3647. foreach($log as $line){
  3648. if(!empty($line) && $line[0] != " "){
  3649. $line = strip($line);
  3650. if($type == "single"){
  3651. if( strpos( strtolower($line), "ror" ) !== false ) {
  3652. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3653. }else{
  3654. echo "<tr><td>".$line."</td></tr>";
  3655. }
  3656. }elseif($type == "all"){
  3657. if( strpos( strtolower($line), "ror" ) !== false ) {
  3658. echo "<tr><td class='red-bg'>".$name."</td>";
  3659. echo "<td class='red-bg'>".$line."</td></tr>";
  3660. }else{
  3661. echo "<tr><td>".$name."</td>";
  3662. echo "<td>".$line."</td></tr>";
  3663. }
  3664. }
  3665. }
  3666. }
  3667. }
  3668. function getLogs(){
  3669. $path = __DIR__ ."/logs/";
  3670. @mkdir($path, 0770, true);
  3671. $logs = array();
  3672. $files = array_diff(scandir($path), array('.', '..'));
  3673. foreach($files as $v){
  3674. $title = explode(".", $v)[0];
  3675. $logs[$title] = $path.$v;
  3676. }
  3677. return $logs;
  3678. }
  3679. function getBackups(){
  3680. $path = DATABASE_LOCATION ."backups/";
  3681. @mkdir($path, 0770, true);
  3682. $backups = array();
  3683. $files = array_diff(scandir($path), array('.', '..'));
  3684. return array_reverse($files);
  3685. }
  3686. function getExtension($string) {
  3687. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3688. }
  3689. function showFile(){
  3690. $file = $_GET['file'];
  3691. $fileType = getExtension($file);
  3692. if($fileType != 'php'){
  3693. header("Content-type: ".mimeTypes()[$fileType]);
  3694. @readfile($file);
  3695. }
  3696. }
  3697. function getCalendar(){
  3698. $sonarr = new Sonarr(SONARRURL, SONARRKEY);
  3699. $radarr = new Sonarr(RADARRURL, RADARRKEY);
  3700. $sickrage = new SickRage(SICKRAGEURL, SICKRAGEKEY);
  3701. $startDate = date('Y-m-d',strtotime("-".CALENDARSTARTDAY." days"));
  3702. $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
  3703. $calendarItems = array();
  3704. if (SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)){
  3705. try {
  3706. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate));
  3707. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  3708. } catch (Exception $e) {
  3709. writeLog("error", "SONARR ERROR: ".strip($e->getMessage()));
  3710. }
  3711. }
  3712. if (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)){
  3713. try {
  3714. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate));
  3715. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  3716. } catch (Exception $e) {
  3717. writeLog("error", "RADARR ERROR: ".strip($e->getMessage()));
  3718. }
  3719. }
  3720. if (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH)){
  3721. $couchCalendar = getCouchCalendar();
  3722. if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
  3723. }
  3724. if (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)){
  3725. $headphonesHistory = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getHistory");
  3726. $headphonesWanted = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getWanted");
  3727. if(!empty($headphonesHistory)) { $calendarItems = array_merge($calendarItems, $headphonesHistory); }
  3728. if(!empty($headphonesWanted)) { $calendarItems = array_merge($calendarItems, $headphonesWanted); }
  3729. }
  3730. if (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)){
  3731. try {
  3732. $sickrageFuture = getSickrageCalendarWanted($sickrage->future());
  3733. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  3734. } catch (Exception $e) {
  3735. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3736. } try {
  3737. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"));
  3738. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  3739. } catch (Exception $e) {
  3740. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3741. }
  3742. }
  3743. return $calendarItems;
  3744. }
  3745. function localURL($url){
  3746. if (strpos($url, 'https') !== false) {
  3747. preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $url, $result);
  3748. $result = (!empty($result) ? true : false);
  3749. return $result;
  3750. }
  3751. }
  3752. function fileArray($files){
  3753. foreach($files as $file){
  3754. if(file_exists($file)){
  3755. $list[] = $file;
  3756. }
  3757. }
  3758. if(!empty($list)){ return $list; }
  3759. }
  3760. function backupDB(){
  3761. if (extension_loaded('ZIP')) {
  3762. $directory = DATABASE_LOCATION."backups/";
  3763. @mkdir($directory, 0770, true);
  3764. $orgFiles = array(
  3765. 'css' => 'custom.css',
  3766. 'temp' => 'cus.sd',
  3767. 'orgLog' => DATABASE_LOCATION.'org.log',
  3768. 'loginLog' => DATABASE_LOCATION.'loginLog.json',
  3769. 'chatDB' => 'chatpack.db',
  3770. 'config' => 'config/config.php',
  3771. 'database' => DATABASE_LOCATION.'users.db'
  3772. );
  3773. $files = fileArray($orgFiles);
  3774. if(!empty($files)){
  3775. writeLog("success", "BACKUP: backup process started");
  3776. $zipname = $directory.'backup['.date('Y-m-d_H-i').']['.INSTALLEDVERSION.'].zip';
  3777. $zip = new ZipArchive;
  3778. $zip->open($zipname, ZipArchive::CREATE);
  3779. foreach ($files as $file) {
  3780. $zip->addFile($file);
  3781. }
  3782. $zip->close();
  3783. writeLog("success", "BACKUP: backup process finished");
  3784. return true;
  3785. }else{
  3786. return false;
  3787. }
  3788. }else{
  3789. return false;
  3790. }
  3791. }
  3792. class Ping {
  3793. private $host;
  3794. private $ttl;
  3795. private $timeout;
  3796. private $port = 80;
  3797. private $data = 'Ping';
  3798. private $commandOutput;
  3799. /**
  3800. * Called when the Ping object is created.
  3801. *
  3802. * @param string $host
  3803. * The host to be pinged.
  3804. * @param int $ttl
  3805. * Time-to-live (TTL) (You may get a 'Time to live exceeded' error if this
  3806. * value is set too low. The TTL value indicates the scope or range in which
  3807. * a packet may be forwarded. By convention:
  3808. * - 0 = same host
  3809. * - 1 = same subnet
  3810. * - 32 = same site
  3811. * - 64 = same region
  3812. * - 128 = same continent
  3813. * - 255 = unrestricted
  3814. * @param int $timeout
  3815. * Timeout (in seconds) used for ping and fsockopen().
  3816. * @throws \Exception if the host is not set.
  3817. */
  3818. public function __construct($host, $ttl = 255, $timeout = 10) {
  3819. if (!isset($host)) {
  3820. throw new \Exception("Error: Host name not supplied.");
  3821. }
  3822. $this->host = $host;
  3823. $this->ttl = $ttl;
  3824. $this->timeout = $timeout;
  3825. }
  3826. /**
  3827. * Set the ttl (in hops).
  3828. *
  3829. * @param int $ttl
  3830. * TTL in hops.
  3831. */
  3832. public function setTtl($ttl) {
  3833. $this->ttl = $ttl;
  3834. }
  3835. /**
  3836. * Get the ttl.
  3837. *
  3838. * @return int
  3839. * The current ttl for Ping.
  3840. */
  3841. public function getTtl() {
  3842. return $this->ttl;
  3843. }
  3844. /**
  3845. * Set the timeout.
  3846. *
  3847. * @param int $timeout
  3848. * Time to wait in seconds.
  3849. */
  3850. public function setTimeout($timeout) {
  3851. $this->timeout = $timeout;
  3852. }
  3853. /**
  3854. * Get the timeout.
  3855. *
  3856. * @return int
  3857. * Current timeout for Ping.
  3858. */
  3859. public function getTimeout() {
  3860. return $this->timeout;
  3861. }
  3862. /**
  3863. * Set the host.
  3864. *
  3865. * @param string $host
  3866. * Host name or IP address.
  3867. */
  3868. public function setHost($host) {
  3869. $this->host = $host;
  3870. }
  3871. /**
  3872. * Get the host.
  3873. *
  3874. * @return string
  3875. * The current hostname for Ping.
  3876. */
  3877. public function getHost() {
  3878. return $this->host;
  3879. }
  3880. /**
  3881. * Set the port (only used for fsockopen method).
  3882. *
  3883. * Since regular pings use ICMP and don't need to worry about the concept of
  3884. * 'ports', this is only used for the fsockopen method, which pings servers by
  3885. * checking port 80 (by default).
  3886. *
  3887. * @param int $port
  3888. * Port to use for fsockopen ping (defaults to 80 if not set).
  3889. */
  3890. public function setPort($port) {
  3891. $this->port = $port;
  3892. }
  3893. /**
  3894. * Get the port (only used for fsockopen method).
  3895. *
  3896. * @return int
  3897. * The port used by fsockopen pings.
  3898. */
  3899. public function getPort() {
  3900. return $this->port;
  3901. }
  3902. /**
  3903. * Return the command output when method=exec.
  3904. * @return string
  3905. */
  3906. public function getCommandOutput(){
  3907. return $this->commandOutput;
  3908. }
  3909. /**
  3910. * Matches an IP on command output and returns.
  3911. * @return string
  3912. */
  3913. public function getIpAddress() {
  3914. $out = array();
  3915. if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->commandOutput, $out)){
  3916. return $out[0];
  3917. }
  3918. return null;
  3919. }
  3920. /**
  3921. * Ping a host.
  3922. *
  3923. * @param string $method
  3924. * Method to use when pinging:
  3925. * - exec (default): Pings through the system ping command. Fast and
  3926. * robust, but a security risk if you pass through user-submitted data.
  3927. * - fsockopen: Pings a server on port 80.
  3928. * - socket: Creates a RAW network socket. Only usable in some
  3929. * environments, as creating a SOCK_RAW socket requires root privileges.
  3930. *
  3931. * @throws InvalidArgumentException if $method is not supported.
  3932. *
  3933. * @return mixed
  3934. * Latency as integer, in ms, if host is reachable or FALSE if host is down.
  3935. */
  3936. public function ping($method = 'exec') {
  3937. $latency = false;
  3938. switch ($method) {
  3939. case 'exec':
  3940. $latency = $this->pingExec();
  3941. break;
  3942. case 'fsockopen':
  3943. $latency = $this->pingFsockopen();
  3944. break;
  3945. case 'socket':
  3946. $latency = $this->pingSocket();
  3947. break;
  3948. default:
  3949. throw new \InvalidArgumentException('Unsupported ping method.');
  3950. }
  3951. // Return the latency.
  3952. return $latency;
  3953. }
  3954. /**
  3955. * The exec method uses the possibly insecure exec() function, which passes
  3956. * the input to the system. This is potentially VERY dangerous if you pass in
  3957. * any user-submitted data. Be SURE you sanitize your inputs!
  3958. *
  3959. * @return int
  3960. * Latency, in ms.
  3961. */
  3962. private function pingExec() {
  3963. $latency = false;
  3964. $ttl = escapeshellcmd($this->ttl);
  3965. $timeout = escapeshellcmd($this->timeout);
  3966. $host = escapeshellcmd($this->host);
  3967. // Exec string for Windows-based systems.
  3968. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  3969. // -n = number of pings; -i = ttl; -w = timeout (in milliseconds).
  3970. $exec_string = 'ping -n 1 -i ' . $ttl . ' -w ' . ($timeout * 1000) . ' ' . $host;
  3971. }
  3972. // Exec string for Darwin based systems (OS X).
  3973. else if(strtoupper(PHP_OS) === 'DARWIN') {
  3974. // -n = numeric output; -c = number of pings; -m = ttl; -t = timeout.
  3975. $exec_string = 'ping -n -c 1 -m ' . $ttl . ' -t ' . $timeout . ' ' . $host;
  3976. }
  3977. // Exec string for other UNIX-based systems (Linux).
  3978. else {
  3979. // -n = numeric output; -c = number of pings; -t = ttl; -W = timeout
  3980. $exec_string = 'ping -n -c 1 -t ' . $ttl . ' -W ' . $timeout . ' ' . $host . ' 2>&1';
  3981. }
  3982. exec($exec_string, $output, $return);
  3983. // Strip empty lines and reorder the indexes from 0 (to make results more
  3984. // uniform across OS versions).
  3985. $this->commandOutput = implode($output, '');
  3986. $output = array_values(array_filter($output));
  3987. // If the result line in the output is not empty, parse it.
  3988. if (!empty($output[1])) {
  3989. // Search for a 'time' value in the result line.
  3990. $response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)ms/", $output[1], $matches);
  3991. // If there's a result and it's greater than 0, return the latency.
  3992. if ($response > 0 && isset($matches['time'])) {
  3993. $latency = round($matches['time'], 2);
  3994. }
  3995. }
  3996. return $latency;
  3997. }
  3998. /**
  3999. * The fsockopen method simply tries to reach the host on a port. This method
  4000. * is often the fastest, but not necessarily the most reliable. Even if a host
  4001. * doesn't respond, fsockopen may still make a connection.
  4002. *
  4003. * @return int
  4004. * Latency, in ms.
  4005. */
  4006. private function pingFsockopen() {
  4007. $start = microtime(true);
  4008. // fsockopen prints a bunch of errors if a host is unreachable. Hide those
  4009. // irrelevant errors and deal with the results instead.
  4010. $fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  4011. if (!$fp) {
  4012. $latency = false;
  4013. }
  4014. else {
  4015. $latency = microtime(true) - $start;
  4016. $latency = round($latency * 1000, 2);
  4017. }
  4018. return $latency;
  4019. }
  4020. /**
  4021. * The socket method uses raw network packet data to try sending an ICMP ping
  4022. * packet to a server, then measures the response time. Using this method
  4023. * requires the script to be run with root privileges, though, so this method
  4024. * only works reliably on Windows systems and on Linux servers where the
  4025. * script is not being run as a web user.
  4026. *
  4027. * @return int
  4028. * Latency, in ms.
  4029. */
  4030. private function pingSocket() {
  4031. // Create a package.
  4032. $type = "\x08";
  4033. $code = "\x00";
  4034. $checksum = "\x00\x00";
  4035. $identifier = "\x00\x00";
  4036. $seq_number = "\x00\x00";
  4037. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4038. // Calculate the checksum.
  4039. $checksum = $this->calculateChecksum($package);
  4040. // Finalize the package.
  4041. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4042. // Create a socket, connect to server, then read socket and calculate.
  4043. if ($socket = socket_create(AF_INET, SOCK_RAW, 1)) {
  4044. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array(
  4045. 'sec' => 10,
  4046. 'usec' => 0,
  4047. ));
  4048. // Prevent errors from being printed when host is unreachable.
  4049. @socket_connect($socket, $this->host, null);
  4050. $start = microtime(true);
  4051. // Send the package.
  4052. @socket_send($socket, $package, strlen($package), 0);
  4053. if (socket_read($socket, 255) !== false) {
  4054. $latency = microtime(true) - $start;
  4055. $latency = round($latency * 1000, 2);
  4056. }
  4057. else {
  4058. $latency = false;
  4059. }
  4060. }
  4061. else {
  4062. $latency = false;
  4063. }
  4064. // Close the socket.
  4065. socket_close($socket);
  4066. return $latency;
  4067. }
  4068. /**
  4069. * Calculate a checksum.
  4070. *
  4071. * @param string $data
  4072. * Data for which checksum will be calculated.
  4073. *
  4074. * @return string
  4075. * Binary string checksum of $data.
  4076. */
  4077. private function calculateChecksum($data) {
  4078. if (strlen($data) % 2) {
  4079. $data .= "\x00";
  4080. }
  4081. $bit = unpack('n*', $data);
  4082. $sum = array_sum($bit);
  4083. while ($sum >> 16) {
  4084. $sum = ($sum >> 16) + ($sum & 0xffff);
  4085. }
  4086. return pack('n*', ~$sum);
  4087. }
  4088. }
  4089. function ping($pings, $type = "string") {
  4090. $ping = new Ping("");
  4091. $ping->setTtl(128);
  4092. $ping->setTimeout(2);
  4093. switch ($type){
  4094. case "array":
  4095. $results = [];
  4096. foreach ($pings as $k => $v) {
  4097. if(strpos($v, ':') !== false){
  4098. $domain = explode(':', $v)[0];
  4099. $port = explode(':', $v)[1];
  4100. $ping->setHost($domain);
  4101. $ping->setPort($port);
  4102. $latency = $ping->ping('fsockopen');
  4103. }else{
  4104. $ping->setHost($v);
  4105. $latency = $ping->ping();
  4106. }
  4107. if ($latency || $latency === 0) {
  4108. $results[$k] = $latency;
  4109. } else {
  4110. $results[$k] = 0;
  4111. }
  4112. }
  4113. break;
  4114. case "string":
  4115. if(strpos($pings, ':') !== false){
  4116. $domain = explode(':', $pings)[0];
  4117. $port = explode(':', $pings)[1];
  4118. $ping->setHost($domain);
  4119. $ping->setPort($port);
  4120. $latency = $ping->ping('fsockopen');
  4121. }else{
  4122. $ping->setHost($pings);
  4123. $latency = $ping->ping();
  4124. }
  4125. if ($latency || $latency === 0) {
  4126. $results = $latency;
  4127. } else {
  4128. $results = 0;
  4129. }
  4130. break;
  4131. }
  4132. return $results;
  4133. }
  4134. function getPing($url, $style, $refresh = null){
  4135. if(ping($url) !== 0){
  4136. $class = 'success';
  4137. if(!$refresh){
  4138. $class .= " animated slideInLeft";
  4139. }
  4140. }else{
  4141. $class = "warning";
  4142. if(!$refresh){
  4143. $class .= " animated flash loop-animation-timeout";
  4144. }
  4145. }
  4146. echo '<span class="pingcheck badge ping-'.$class.'" style="position: absolute;z-index: 100;right: 5px; padding: 0px 0px;'.$style.';font-size: 10px;">&nbsp;</span>';
  4147. }
  4148. function speedTestData(){
  4149. $file_db = DATABASE_LOCATION."speedtest.db";
  4150. if(file_exists($file_db)){
  4151. $conn = new PDO("sqlite:$file_db") or die("1");
  4152. $result = $conn->query('SELECT * FROM speedtest_users');
  4153. $conn = null;
  4154. if (is_array($result) || is_object($result)){
  4155. foreach($result as $k => $v){
  4156. $return[$k] = $v;
  4157. }
  4158. return $return;
  4159. }
  4160. }
  4161. }
  4162. function speedTestDisplay($array, $output){
  4163. if (is_array($array) || is_object($array)){
  4164. if($output == "graph"){
  4165. $result = "Morris.Line({element: 'morris-line',data: [";
  4166. foreach($array as $k => $v){
  4167. $result .= "{ y: '".substr($v['timestamp'],0,10)."', a: ".$v['ul'].", b: ".$v['dl'].", c: ".$v['ping']." },";
  4168. }
  4169. $result .= "],xkey: 'y',ykeys: ['a', 'b', 'c'],labels: ['Upload', 'Download', 'Ping'],hideHover: 'auto',resize: true,lineColors: ['#63A8EB','#ccc','#000'] });";
  4170. }elseif($output == "table"){
  4171. $result = "";
  4172. foreach($array as $k => $v){
  4173. $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>";
  4174. }
  4175. }
  4176. return $result;
  4177. }
  4178. }
  4179. function buildMenuPhone($array){
  4180. if (is_array($array) || is_object($array)){
  4181. $result = '
  4182. <div class="content-box profile-sidebar box-shadow">
  4183. <img src="images/organizr-logo-h-d.png" width="100%" style="margin-top: -10px;">
  4184. <div class="profile-usermenu">
  4185. <ul class="nav" id="settings-list">
  4186. ';
  4187. foreach($array as $k => $v){
  4188. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4189. continue;
  4190. }
  4191. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4192. continue;
  4193. }
  4194. /*$result .= '
  4195. <li>
  4196. <a id="'.$v['id'].'" box="'.$v['box'].'">'.$v['name'].'
  4197. <span class="fa-stack fa-fw pull-right" style="margin-top: -5px;margin-right: -10px;">
  4198. <i class="fa fa-'.$v['icon_1'].' fa-stack-2x '.$v['color'].'" style="font-size:null;"></i>
  4199. <i class="fa fa-'.$v['icon_2'].' fa-stack-1x fa-inverse"></i>
  4200. </span>
  4201. </a>
  4202. </li>
  4203. ';*/
  4204. $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>';
  4205. }
  4206. $result .= '</ul></div></div>';
  4207. return $result;
  4208. }
  4209. }
  4210. function buildMenu($array){
  4211. if (is_array($array) || is_object($array)){
  4212. $result = '<div class="settingsList">';
  4213. foreach($array as $k => $v){
  4214. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4215. continue;
  4216. }
  4217. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4218. continue;
  4219. }
  4220. $result .= '
  4221. <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">
  4222. <i class="mdi mdi-'.$v['icon_1'].' fa-fw pull-left" style="padding-left: '.$v['padding'].'px;font-size: 30px"></i>
  4223. <p class="" style="text-align: center;direction: rtl;display:none;margin: 2px;"><strong>'.$v['name'].'</strong></p>
  4224. </button>
  4225. ';
  4226. }
  4227. $result .= '</div>';
  4228. return $result;
  4229. }
  4230. }
  4231. function requestInvite($email, $username){
  4232. //sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
  4233. //orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  4234. 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."));
  4235. }
  4236. function errormessage($msg) {
  4237. echo "<div style=\"margin-top: 50px;\">";
  4238. echo "<span style=\"color:#d89334;\">error </span>";
  4239. echo $msg;
  4240. echo "</div>";
  4241. }
  4242. function ajaxLoop($ajaxFunction, $refresh, $extraFunction = ''){
  4243. return "
  4244. setInterval(function() {
  4245. $.ajax({
  4246. url: 'ajax.php?a=".$ajaxFunction."',
  4247. timeout: 10000,
  4248. type: 'GET',
  4249. success: function(response) {
  4250. var getDiv = response;
  4251. var loadedID = $(getDiv).attr('id');
  4252. if (typeof loadedID !== 'undefined') {
  4253. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  4254. ".$extraFunction."
  4255. console.log('".$ajaxFunction." has been updated');
  4256. }else{
  4257. console.log('".$ajaxFunction." data was not sufficent or is offline');
  4258. }
  4259. },
  4260. error: function(jqXHR, textStatus, errorThrown) {
  4261. console.error('".$ajaxFunction." could not be updated');
  4262. }
  4263. });
  4264. }, ".$refresh.");
  4265. ";
  4266. }
  4267. function getOrgUsers(){
  4268. $file_db = DATABASE_LOCATION."users.db";
  4269. if(file_exists($file_db)){
  4270. $conn = new PDO("sqlite:$file_db") or die("1");
  4271. $result = $conn->query('SELECT * FROM users');
  4272. $conn = null;
  4273. if (is_array($result) || is_object($result)){
  4274. foreach($result as $k => $v){
  4275. $return[$v['username']] = $v['email'];
  4276. }
  4277. return $return;
  4278. }
  4279. }
  4280. }
  4281. function getEmails($type = 'org'){
  4282. if($type == 'plex'){
  4283. $emails = array_merge(libraryList()['both'],getOrgUsers());
  4284. }elseif($type == 'emby'){
  4285. $emails = getOrgUsers();
  4286. }else{
  4287. $emails = getOrgUsers();
  4288. }
  4289. return $emails;
  4290. }
  4291. function printEmails($emails){
  4292. $result = '';
  4293. foreach($emails as $k => $v){
  4294. $result .= '<option value="'.$v.'">'.$k.'</option>';
  4295. }
  4296. return $result;
  4297. }
  4298. function massEmail($to, $subject, $message){
  4299. if (!isset($GLOBALS['file_db'])) {
  4300. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  4301. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4302. }
  4303. 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);
  4304. }
  4305. function q2a($q){
  4306. if (is_array($q) || is_object($q)){
  4307. foreach ($q as $k => $v){
  4308. $a[$k] = $v;
  4309. }
  4310. if(!empty($a)){
  4311. return $a;
  4312. }
  4313. }
  4314. }
  4315. function getOmbiToken($username, $password){
  4316. $headers = array(
  4317. "Accept" => "application/json",
  4318. "Content-Type" => "application/json"
  4319. );
  4320. $json = array(
  4321. "username" => $username,
  4322. "password" => $password,
  4323. "rememberMe" => "true",
  4324. );
  4325. $api = curl_post(OMBIURL."/api/v1/Token", $json, $headers);
  4326. if (isset($result['content'])) {
  4327. return json_decode($api['content'], true)['access_token'];
  4328. }else{
  4329. return false;
  4330. }
  4331. }
  4332. function ombiAction($id, $action, $type){
  4333. $headers = array(
  4334. "Accept" => "application/json",
  4335. "Content-Type" => "application/json",
  4336. "Apikey" => OMBIKEY
  4337. );
  4338. $body = array(
  4339. 'id' => $id,
  4340. );
  4341. switch ($type) {
  4342. case 'season':
  4343. case 'tv':
  4344. $type = 'tv';
  4345. break;
  4346. default:
  4347. $type = 'movie';
  4348. break;
  4349. }
  4350. switch ($action) {
  4351. case 'approve':
  4352. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/approve", $body, $headers);
  4353. break;
  4354. case 'available':
  4355. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/available", $body, $headers);
  4356. break;
  4357. case 'unavailable':
  4358. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/unavailable", $body, $headers);
  4359. break;
  4360. case 'deny':
  4361. $api = curl_put(OMBIURL."/api/v1/Request/".$type."/deny", $body, $headers);
  4362. break;
  4363. case 'delete':
  4364. $api = curl_delete(OMBIURL."/api/v1/Request/".$type."/".$id, $headers);
  4365. break;
  4366. default:
  4367. # code...
  4368. break;
  4369. }
  4370. switch ($api['http_code']['http_code']){
  4371. case 401:
  4372. writeLog("error", "OMBI: Invalid API KEY");
  4373. return false;
  4374. break;
  4375. case 200:
  4376. writeLog("success", "OMBI: action completed successfully for [type: $type - action: $action - id: $id]");
  4377. return true;
  4378. break;
  4379. default:
  4380. writeLog("error", "OMBI: unknown error with request [type: $type - action: $action - id: $id]");
  4381. return false;
  4382. }
  4383. //return (!empty($result) ? $result : null );
  4384. }
  4385. function getOmbiRequests($type = "both"){
  4386. $headers = array(
  4387. "Accept" => "application/json",
  4388. "Apikey" => OMBIKEY,
  4389. );
  4390. $requests = array();
  4391. switch ($type) {
  4392. case 'movie':
  4393. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4394. break;
  4395. case 'tv':
  4396. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4397. break;
  4398. default:
  4399. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4400. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4401. break;
  4402. }
  4403. if(isset($movie)){
  4404. //$movie = array_reverse($movie);
  4405. foreach ($movie as $key => $value) {
  4406. $poster = explode('/',$value['posterPath']);
  4407. $requests[] = array(
  4408. 'id' => $value['theMovieDbId'],
  4409. 'title' => $value['title'],
  4410. 'poster' => (strpos($value['posterPath'], "/") !== false) ? 'https://image.tmdb.org/t/p/w300/'.end($poster) : 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'],
  4411. 'approved' => $value['approved'],
  4412. 'available' => $value['available'],
  4413. 'denied' => $value['denied'],
  4414. 'deniedReason' => $value['deniedReason'],
  4415. 'user' => $value['requestedUser']['userName'],
  4416. 'request_id' => $value['id'],
  4417. 'request_date' => $value['requestedDate'],
  4418. 'release_date' => $value['releaseDate'],
  4419. 'type' => 'movie',
  4420. 'icon' => 'mdi mdi-filmstrip',
  4421. 'color' => 'palette-Deep-Purple-900 bg white',
  4422. );
  4423. }
  4424. }
  4425. if(isset($tv) && (is_array($tv) || is_object($tv))){
  4426. foreach ($tv as $key => $value) {
  4427. if(is_array($value['childRequests'][0])){
  4428. $requests[] = array(
  4429. 'id' => $value['tvDbId'],
  4430. 'title' => $value['title'],
  4431. 'poster' => $value['posterPath'],
  4432. 'approved' => $value['childRequests'][0]['approved'],
  4433. 'available' => $value['childRequests'][0]['available'],
  4434. 'denied' => $value['childRequests'][0]['denied'],
  4435. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  4436. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  4437. 'request_id' => $value['id'],
  4438. 'request_date' => $value['childRequests'][0]['requestedDate'],
  4439. 'release_date' => $value['releaseDate'],
  4440. 'type' => 'tv',
  4441. 'icon' => 'mdi mdi-television',
  4442. 'color' => 'grayish-blue-bg',
  4443. );
  4444. }
  4445. }
  4446. }
  4447. return (empty($requests)) ? '' : $requests;
  4448. }
  4449. function convertOmbiString($type, $value){
  4450. switch ($type) {
  4451. case 'approved':
  4452. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4453. $string['icon'] = ($value) ? 'mdi mdi-check' : 'mdi mdi-clock';
  4454. $string['color'] = ($value) ? 'green-bg' : 'yellow-bg';
  4455. break;
  4456. case 'available':
  4457. $string['string'] = ($value) ? 'Available' : 'Not Downloaded';
  4458. $string['icon'] = ($value) ? 'mdi mdi-server' : 'mdi mdi-server-off';
  4459. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4460. break;
  4461. case 'denied':
  4462. $string['string'] = ($value) ? 'Denied' : 'Approved';
  4463. $string['icon'] = ($value) ? 'mdi mdi-emoticon-sad' : 'mdi mdi-emoticon-happy';
  4464. $string['color'] = ($value) ? 'red-bg' : 'green-bg';
  4465. break;
  4466. case 'status':
  4467. switch ($value) {
  4468. case '1':
  4469. $string['string'] = 'Denied';
  4470. $string['icon'] = 'mdi mdi-window-close';
  4471. $string['color'] = 'red-bg';
  4472. break;
  4473. case '2':
  4474. $string['string'] = 'Approved';
  4475. $string['icon'] = 'mdi mdi-check';
  4476. $string['color'] = 'green-bg';
  4477. break;
  4478. case '3':
  4479. $string['string'] = 'Not Approved';
  4480. $string['icon'] = 'mdi mdi-clock';
  4481. $string['color'] = 'yellow-bg';
  4482. break;
  4483. default:
  4484. # code...
  4485. break;
  4486. }
  4487. break;
  4488. default:
  4489. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4490. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4491. break;
  4492. }
  4493. return $string;
  4494. }
  4495. function buildOmbiItem($type, $group, $user, $request){
  4496. if (is_array($request) || is_object($request)){
  4497. $actions = '';
  4498. if($request['denied']){
  4499. $status = 1;
  4500. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4501. }else{
  4502. if($request['approved']){
  4503. $status = 2;
  4504. }else{
  4505. $status = 3;
  4506. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4507. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="deny"><a class="requestAction" href="javascript:void(0)">Deny</a></li>';
  4508. }
  4509. }
  4510. if($request['available']){
  4511. $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>';
  4512. }else{
  4513. $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>';
  4514. }
  4515. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="delete"><a class="requestAction" href="javascript:void(0)">Delete</a></li>';
  4516. if(isset($group) && $group == 'admin'){
  4517. $actionMenu = '
  4518. <div class="requestOptions">
  4519. <div class="btn-group transparent" role="group">
  4520. <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>
  4521. <ul class="dropdown-menu"><h6 class="text-center requestHeader gray-bg">'.$request['user'].'</h6>'.$actions.'</ul>
  4522. </div>
  4523. </div>
  4524. ';
  4525. }else{
  4526. $actionMenu = '';
  4527. }
  4528. if((isset($group)) && $group == 'admin' || REQUESTEDUSERONLY == 'false'){
  4529. return '
  4530. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4531. '.$actionMenu.'
  4532. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4533. <div class="requestBottom text-center">
  4534. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4535. <i class="'.$request['icon'].'"></i>
  4536. </div>
  4537. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4538. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4539. </div>
  4540. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4541. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4542. </div>
  4543. </div>
  4544. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4545. </div>';
  4546. }else{
  4547. if(strtolower($request['user']) == strtolower($user)){
  4548. return '
  4549. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4550. '.$actionMenu.'
  4551. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4552. <div class="requestBottom text-center">
  4553. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4554. <i class="'.$request['icon'].'"></i>
  4555. </div>
  4556. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4557. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4558. </div>
  4559. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4560. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4561. </div>
  4562. </div>
  4563. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4564. </div>';
  4565. }
  4566. }
  4567. }
  4568. }
  4569. function buildOmbiList($group, $user){
  4570. $requests = array();
  4571. $movieList = getOmbiRequests('movie');
  4572. $tvList = getOmbiRequests('tv');
  4573. if(is_array($movieList) && is_array($tvList)){
  4574. $result = array_merge($movieList , $tvList );
  4575. }else{
  4576. if(is_array($movieList)){
  4577. $result = $movieList;
  4578. }elseif(is_array($movieList)){
  4579. $result = $tvList;
  4580. }else{
  4581. $result = false;
  4582. }
  4583. }
  4584. if (is_array($result) || is_object($result)){
  4585. usort($result, function ($item1, $item2) {
  4586. if ($item1['request_date'] == $item2['request_date']) return 0;
  4587. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  4588. });
  4589. foreach ($result as $request) {
  4590. if($request['type'] == 'movie'){
  4591. $requests[] = buildOmbiItem('movie', $group, $user, $request);
  4592. }elseif($request['type'] == 'tv'){
  4593. $requests[] = buildOmbiItem('season', $group, $user, $request);
  4594. }
  4595. }
  4596. }
  4597. return outputOmbiRequests("Requested Content", $requests, ajaxLoop('ombi-requests',REQUESTREFRESH,'loadSlick();'), false);
  4598. }
  4599. function outputOmbiRequests($header = "Requested Content", $items, $script = false, $array) {
  4600. $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">';
  4601. if(preg_grep("/item-movie-Approved/", $items)){
  4602. $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>';
  4603. }
  4604. if(preg_grep("/item-movie-Approval-Pending/", $items)){
  4605. $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>';
  4606. }
  4607. if(preg_grep("/item-season-Approved/", $items)){
  4608. $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>';
  4609. }
  4610. if(preg_grep("/item-season-Approval-Pending/", $items)){
  4611. $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>';
  4612. }
  4613. $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>';
  4614. $hideMenu .= '</ul></div></div>';
  4615. // If None Populate Empty Item
  4616. if (count(array_flip($items)) < 1) {
  4617. return '<div id="recentRequests" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Requests Found</p></div>';
  4618. }else{
  4619. $className = str_replace(' ', '', $header);
  4620. 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>':'');
  4621. }
  4622. }
  4623. function loadIcons(){
  4624. $dirname = "images/";
  4625. $images = scandir($dirname);
  4626. $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");
  4627. $allIcons = '';
  4628. foreach($images as $curimg){
  4629. if(!in_array($curimg, $ignore)) {
  4630. $allIcons .= '
  4631. <div class="col-xs-2" style="width: 75px; height: 75px; padding-right: 0px;">
  4632. <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);">
  4633. <img style="width: 50px; height: 50px;" data-src="'.$dirname.$curimg.'" alt="thumbnail" class="allIcons lazyload shadow">
  4634. </a>
  4635. </div>
  4636. ';
  4637. }
  4638. }
  4639. return $allIcons;
  4640. }
  4641. function buildHomepageSettings(){
  4642. $homepageOrder = homepageOrder();
  4643. $homepageList = '<h4>Drag Homepage Items to Order Them</h4><div id="homepage-items" class="external-events">';
  4644. $inputList = '<div id="homepage-values" class="row">';
  4645. foreach ($homepageOrder as $key => $val) {
  4646. switch ($key) {
  4647. case 'homepageOrdercustomhtml':
  4648. $class = 'palette-Deep-Purple-100 bg gray';
  4649. $image = 'images/html.png';
  4650. if(empty(HOMEPAGECUSTOMHTML1)){
  4651. $class .= ' faded';
  4652. }
  4653. break;
  4654. case 'homepageOrdernotice':
  4655. $class = 'palette-Cyan-A400 bg gray';
  4656. $image = 'images/pin.png';
  4657. if(empty(HOMEPAGENOTICETITLE) && empty(HOMEPAGENOTICEMESSAGE)){
  4658. $class .= ' faded';
  4659. }
  4660. break;
  4661. case 'homepageOrderspeedtest':
  4662. $class = 'red-bg';
  4663. $image = 'images/settings/full-color/png/64px/speedometer.png';
  4664. if(SPEEDTEST !== "true"){
  4665. $class .= ' faded';
  4666. }
  4667. break;
  4668. case 'homepageOrdernzbget':
  4669. $class = 'green-bg';
  4670. $image = 'images/nzbget.png';
  4671. if(empty(NZBGETURL)){
  4672. $class .= ' faded';
  4673. }
  4674. break;
  4675. case 'homepageOrdersabnzbd':
  4676. $class = 'yellow-bg';
  4677. $image = 'images/sabnzbd.png';
  4678. if(empty(SABNZBDURL)){
  4679. $class .= ' faded';
  4680. }
  4681. break;
  4682. case 'homepageOrderplexsearch':
  4683. case 'homepageOrderplexnowplaying':
  4684. case 'homepageOrderplexrecent':
  4685. case 'homepageOrderplexplaylist':
  4686. $class = 'palette-Amber-A700 bg gray';
  4687. $image = 'images/plex.png';
  4688. if(empty(PLEXURL)){
  4689. $class .= ' faded';
  4690. }
  4691. break;
  4692. case 'homepageOrderembynowplaying':
  4693. case 'homepageOrderembyrecent':
  4694. $class = 'palette-Green-A700 bg gray';
  4695. $image = 'images/emby.png';
  4696. if(empty(EMBYURL)){
  4697. $class .= ' faded';
  4698. }
  4699. break;
  4700. case 'homepageOrderombi':
  4701. $class = 'orange-bg';
  4702. $image = 'images/ombi.png';
  4703. if(empty(OMBIURL)){
  4704. $class .= ' faded';
  4705. }
  4706. break;
  4707. case 'homepageOrdercalendar':
  4708. $class = 'palette-Blue-400 bg gray';
  4709. $image = 'images/calendar.png';
  4710. if(SONARRURL == "" && RADARRURL == "" && HEADPHONESURL == "" && SICKRAGEURL == "" && COUCHURL == "" ){
  4711. $class .= ' faded';
  4712. }
  4713. break;
  4714. default:
  4715. $class = 'blue-bg';
  4716. $image = '';
  4717. break;
  4718. }
  4719. $homepageList .= '
  4720. <div class="col-md-3 sort-homepage"><div class="fc-event '.$class.'">
  4721. <span class="ordinal-position text-uppercase badge badge-gray" data-link="'.$key.'" style="float:left;width: 30px;">'.$val.'</span>
  4722. &nbsp; '.strtoupper(substr($key, 13)).'
  4723. <span class="remove-event"><img style="width: 22px;" src="'.$image.'"></span>
  4724. </div></div>';
  4725. $inputList .= '<input type="hidden" name="'.$key.'">';
  4726. }
  4727. $homepageList .= '</div>';
  4728. $inputList .= '</div>';
  4729. return $homepageList.$inputList;
  4730. }
  4731. function buildHomepage($group, $user){
  4732. $homepageOrder = homepageOrder();
  4733. $homepageBuilt = '';
  4734. foreach ($homepageOrder as $key => $value) {
  4735. $homepageBuilt .= buildHomepageItem($key, $group, $user);
  4736. }
  4737. return $homepageBuilt;
  4738. }
  4739. function realSize($bytes, $decimals = 2) {
  4740. $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
  4741. $factor = floor((strlen($bytes) - 1) / 3);
  4742. return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' '.@$size[$factor];
  4743. }
  4744. function buildHomepageItem($homepageItem, $group, $user){
  4745. $homepageItemBuilt = '';
  4746. switch ($homepageItem) {
  4747. case 'homepageOrderplexsearch':
  4748. if((qualifyUser(PLEXSEARCHAUTH) && PLEXSEARCH == "true" && qualifyUser(PLEXHOMEAUTH))) {
  4749. $homepageItemBuilt .= '
  4750. <div id="searchPlexRow" class="row">
  4751. <div class="col-lg-12">
  4752. <div class="content-box box-shadow big-box todo-list">
  4753. <form id="plexSearchForm" onsubmit="return false;" autocomplete="off">
  4754. <div class="">
  4755. <div class="input-group">
  4756. <div style="border-radius: 25px 0 0 25px; border:0" class="input-group-addon gray-bg"><i class="fa fa-search white"></i></div>
  4757. <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">
  4758. <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>
  4759. <button style="display:none" id="plexSearchForm_submit" class="btn btn-primary waves"></button>
  4760. </div>
  4761. </div>
  4762. </form>
  4763. <div id="resultshere" class="table-responsive"></div>
  4764. </div>
  4765. </div>
  4766. </div>
  4767. ';
  4768. }
  4769. break;
  4770. case 'homepageOrdercustomhtml':
  4771. if (qualifyUser(HOMEPAGECUSTOMHTML1AUTH) && HOMEPAGECUSTOMHTML1) {
  4772. $homepageItemBuilt .= "<div>" . HOMEPAGECUSTOMHTML1 . "</div>";
  4773. }
  4774. break;
  4775. case 'homepageOrdernotice':
  4776. if (qualifyUser(HOMEPAGENOTICEAUTH) && HOMEPAGENOTICETITLE && HOMEPAGENOTICETYPE && HOMEPAGENOTICEMESSAGE && HOMEPAGENOTICELAYOUT) {
  4777. $homepageItemBuilt .= buildHomepageNotice(HOMEPAGENOTICELAYOUT, HOMEPAGENOTICETYPE, HOMEPAGENOTICETITLE, HOMEPAGENOTICEMESSAGE);
  4778. }
  4779. break;
  4780. case 'homepageOrderspeedtest':
  4781. if(SPEEDTEST == "true" && qualifyUser(SPEEDTESTAUTH)){
  4782. $homepageItemBuilt .= '
  4783. <style type="text/css">
  4784. .flash {
  4785. animation: flash 0.6s linear infinite;
  4786. }
  4787. @keyframes flash {
  4788. 0% { opacity: 0.6; }
  4789. 50% { opacity: 1; }
  4790. }
  4791. </style>
  4792. <script type="text/javascript">
  4793. var w = null
  4794. function runTest() {
  4795. document.getElementById("startBtn").style.display = "none"
  4796. document.getElementById("testArea").style.display = ""
  4797. document.getElementById("abortBtn").style.display = ""
  4798. w = new Worker("bower_components/speed/speedtest_worker.js")
  4799. var interval = setInterval(function () { w.postMessage("status") }, 100)
  4800. w.onmessage = function (event) {
  4801. var data = event.data.split(";")
  4802. var status = Number(data[0])
  4803. var dl = document.getElementById("download")
  4804. var ul = document.getElementById("upload")
  4805. var ping = document.getElementById("ping")
  4806. var jitter = document.getElementById("jitter")
  4807. dl.className = status === 1 ? "w-name flash" : "w-name"
  4808. ping.className = status === 2 ? "w-name flash" : "w-name"
  4809. jitter.className = ul.className = status === 3 ? "w-name flash" : "w-name"
  4810. if (status >= 4) {
  4811. clearInterval(interval)
  4812. document.getElementById("abortBtn").style.display = "none"
  4813. document.getElementById("startBtn").style.display = ""
  4814. w = null
  4815. }
  4816. if (status === 5) {
  4817. document.getElementById("testArea").style.display = "none"
  4818. }
  4819. dl.textContent = data[1] + " Mbit/s";
  4820. $("#downloadpercent").attr("style", "width: " + data[1] + "%;");
  4821. $("#uploadpercent").attr("style", "width: " + data[2] + "%;");
  4822. $("#pingpercent").attr("style", "width: " + data[3] + "%;");
  4823. $("#jitterpercent").attr("style", "width: " + data[5] + "%;");
  4824. ul.textContent = data[2] + " Mbit/s";
  4825. ping.textContent = data[3] + " ms";
  4826. jitter.textContent = data[5] + " ms";
  4827. }
  4828. w.postMessage(\'start {"telemetry_level":"basic"}\')
  4829. //w.postMessage("start")
  4830. }
  4831. function abortTest() {
  4832. if (w) w.postMessage("abort")
  4833. }
  4834. </script>
  4835. <div class="row" id="testArea" style="display:none">
  4836. <div class="test col-sm-3 col-lg-3">
  4837. <div class="content-box ultra-widget green-bg" data-counter="">
  4838. <div id="downloadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4839. <div class="w-content">
  4840. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-download"></i></div>
  4841. <div class="w-descr left pull-left text-center">
  4842. <span class="testName text-uppercase w-name">Download</span>
  4843. <br>
  4844. <span class="w-name counter" id="download" ></span>
  4845. </div>
  4846. </div>
  4847. </div>
  4848. </div>
  4849. <div class="test col-sm-3 col-lg-3">
  4850. <div class="content-box ultra-widget red-bg" data-counter="">
  4851. <div id="uploadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4852. <div class="w-content">
  4853. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-upload"></i></div>
  4854. <div class="w-descr left pull-left text-center">
  4855. <span class="testName text-uppercase w-name">Upload</span>
  4856. <br>
  4857. <span class="w-name counter" id="upload" ></span>
  4858. </div>
  4859. </div>
  4860. </div>
  4861. </div>
  4862. <div class="test col-sm-3 col-lg-3">
  4863. <div class="content-box ultra-widget yellow-bg" data-counter="">
  4864. <div id="pingpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4865. <div class="w-content">
  4866. <div class="w-icon right pull-right"><i class="mdi mdi-timer"></i></div>
  4867. <div class="w-descr left pull-left text-center">
  4868. <span class="testName text-uppercase w-name">Latency</span>
  4869. <br>
  4870. <span class="w-name counter" id="ping" ></span>
  4871. </div>
  4872. </div>
  4873. </div>
  4874. </div>
  4875. <div class="test col-sm-3 col-lg-3">
  4876. <div class="content-box ultra-widget blue-bg" data-counter="">
  4877. <div id="jitterpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4878. <div class="w-content">
  4879. <div class="w-icon right pull-right"><i class="mdi mdi-pulse"></i></div>
  4880. <div class="w-descr left pull-left text-center">
  4881. <span class="testName text-uppercase w-name">Jitter</span>
  4882. <br>
  4883. <span class="w-name counter" id="jitter" ></span>
  4884. </div>
  4885. </div>
  4886. </div>
  4887. </div>
  4888. <br/>
  4889. </div>
  4890. <div id="abortBtn" class="row" style="display: none" onclick="javascript:abortTest()">
  4891. <div class="col-lg-12">
  4892. <div class="content-box red-bg" style="cursor: pointer;">
  4893. <h1 style="margin: 10px" class="text-uppercase text-center">Abort Speed Test</h1>
  4894. <div class="clearfix"></div>
  4895. </div>
  4896. </div>
  4897. </div>
  4898. <div id="startBtn" class="row" onclick="javascript:runTest()">
  4899. <div class="col-lg-12">
  4900. <div class="content-box green-bg" style="cursor: pointer;">
  4901. <h1 style="margin: 10px" class="text-uppercase text-center">Run Speed Test</h1>
  4902. <div class="clearfix"></div>
  4903. </div>
  4904. </div>
  4905. </div>
  4906. ';
  4907. }
  4908. break;
  4909. case 'homepageOrdernzbget':
  4910. if(NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)){
  4911. $homepageItemBuilt .= buildDownloader('nzbget');
  4912. }
  4913. break;
  4914. case 'homepageOrdersabnzbd':
  4915. if(SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH)) {
  4916. $homepageItemBuilt .= buildDownloader('sabnzbd');
  4917. }
  4918. break;
  4919. case 'homepageOrderplexnowplaying':
  4920. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4921. if(qualifyUser(PLEXPLAYINGNOWAUTH) && PLEXPLAYINGNOW == "true"){
  4922. $homepageItemBuilt .= '<div id="plexRowNowPlaying" class="row">';
  4923. $homepageItemBuilt .= getPlexStreams(12, PLEXSHOWNAMES, $group);
  4924. $homepageItemBuilt .= '</div>';
  4925. }
  4926. }
  4927. break;
  4928. case 'homepageOrderplexrecent':
  4929. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4930. if(qualifyUser(PLEXRECENTMOVIEAUTH) && PLEXRECENTMOVIE == "true" || qualifyUser(PLEXRECENTTVAUTH) && PLEXRECENTTV == "true" || qualifyUser(PLEXRECENTMUSICAUTH) && PLEXRECENTMUSIC == "true"){
  4931. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  4932. $homepageItemBuilt .= '<div id="plexRow" class="row"><div class="col-lg-12">';
  4933. $homepageItemBuilt .= getPlexRecent($plexArray);
  4934. $homepageItemBuilt .= '</div></div>';
  4935. }
  4936. }
  4937. break;
  4938. case 'homepageOrderplexplaylist':
  4939. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4940. if(qualifyUser(PLEXPLAYLISTSAUTH) && PLEXPLAYLISTS == "true"){
  4941. $homepageItemBuilt .= '<div id="plexPlaylists" class="row"><div class="col-lg-12">';
  4942. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  4943. $homepageItemBuilt .= getPlexPlaylists($plexArray);
  4944. $homepageItemBuilt .= '</div> </div>';
  4945. }
  4946. }
  4947. break;
  4948. case 'homepageOrderembynowplaying':
  4949. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  4950. if(qualifyUser(EMBYPLAYINGNOWAUTH) && EMBYPLAYINGNOW == "true"){
  4951. $homepageItemBuilt .= '<div id="embyRowNowPlaying" class="row">';
  4952. $homepageItemBuilt .= getEmbyStreams(12, EMBYSHOWNAMES, $group);
  4953. $homepageItemBuilt .= '</div>';
  4954. }
  4955. }
  4956. break;
  4957. case 'homepageOrderembyrecent':
  4958. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  4959. if(qualifyUser(EMBYRECENTMOVIEAUTH) && EMBYRECENTMOVIE == "true" || qualifyUser(EMBYRECENTTVAUTH) && EMBYRECENTTV == "true" || qualifyUser(EMBYRECENTMUSICAUTH) && EMBYRECENTMUSIC == "true"){
  4960. $embyArray = array("Movie" => EMBYRECENTMOVIE, "Episode" => EMBYRECENTTV, "MusicAlbum" => EMBYRECENTMUSIC, "Series" => EMBYRECENTTV);
  4961. $homepageItemBuilt .= '<div id="embyRow" class="row"><div class="col-lg-12">';
  4962. $homepageItemBuilt .= getEmbyRecent($embyArray);
  4963. $homepageItemBuilt .= '</div></div>';
  4964. }
  4965. }
  4966. break;
  4967. case 'homepageOrderombi':
  4968. if (qualifyUser(OMBIAUTH) && OMBIURL) {
  4969. $homepageItemBuilt .= '<div id="ombiRequests" class="row"><div class="col-lg-12">';
  4970. $homepageItemBuilt .= buildOmbiList($group, $user);
  4971. $homepageItemBuilt .= '</div></div>';
  4972. }
  4973. break;
  4974. case 'homepageOrdercalendar':
  4975. if ((SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)) || (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)) || (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)) || (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)) || (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH))) {
  4976. $calendarItems = '';
  4977. if(RADARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="film" href="javascript:void(0)">Movies</a></li>'; }
  4978. if(SONARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="tv" href="javascript:void(0)">TV Shows</a></li>'; }
  4979. if(HEADPHONESURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="music" href="javascript:void(0)">Music</a></li>'; }
  4980. $homepageItemBuilt .= '
  4981. <div id="calendarLegendRow" class="row" style="padding: 0 0 10px 0;">
  4982. <div class="col-lg-12 content-form form-inline">
  4983. <div class="form-group pull-right">
  4984. <span class="swal-legend label label-primary well-sm">Legend</span>&nbsp;
  4985. <div class="btn-group" role="group">
  4986. <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>
  4987. <ul style="right:0; left: auto" class="dropdown-menu">
  4988. <li><a class="calendarOption" calendarOption="all" href="javascript:void(0)">View All</a></li>
  4989. '.$calendarItems.'
  4990. </ul>
  4991. </div>
  4992. </div>
  4993. </div>
  4994. </div>
  4995. <div id="calendarRow" class="row">
  4996. <div class="col-lg-12">
  4997. <div id="calendar" class="fc-calendar box-shadow fc fc-ltr fc-unthemed"></div>
  4998. </div>
  4999. </div>
  5000. ';
  5001. }
  5002. break;
  5003. default:
  5004. # code...
  5005. break;
  5006. }
  5007. return $homepageItemBuilt;
  5008. }
  5009. function buildDownloader($name){
  5010. return '
  5011. <div id="downloadClientRow" class="row">
  5012. <div class="col-xs-12 col-md-12">
  5013. <div class="content-box">
  5014. <div class="tabbable panel with-nav-tabs panel-default">
  5015. <div class="panel-heading">
  5016. <div class="content-tools i-block pull-right">
  5017. <a id="getDownloader" class="repeat-btn">
  5018. <i class="fa fa-repeat"></i>
  5019. </a>
  5020. </div>
  5021. <h3 class="pull-left">'.strtoupper($name).'</h3>
  5022. <ul class="nav nav-tabs pull-right">
  5023. <li class="active"><a href="#downloadQueue-'.$name.'" data-toggle="tab" aria-expanded="true">'.translate("QUEUE").'</a></li>
  5024. <li class=""><a href="#downloadHistory-'.$name.'" data-toggle="tab" aria-expanded="false">'.translate("HISTORY").'</a></li>
  5025. </ul>
  5026. <div class="clearfix"></div>
  5027. </div>
  5028. <div class="panel-body">
  5029. <div class="tab-content">
  5030. <div class="tab-pane fade active in" id="downloadQueue-'.$name.'">
  5031. <div class="table-responsive" style="max-height: 300px">
  5032. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5033. <thead>
  5034. <tr>
  5035. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5036. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5037. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5038. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5039. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5040. </tr>
  5041. </thead>
  5042. <tbody class="dl-queue '.$name.'"></tbody>
  5043. </table>
  5044. </div>
  5045. </div>
  5046. <div class="tab-pane fade" id="downloadHistory-'.$name.'">
  5047. <div class="table-responsive" style="max-height: 300px">
  5048. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5049. <thead>
  5050. <tr>
  5051. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5052. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5053. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5054. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5055. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5056. </tr>
  5057. </thead>
  5058. <tbody class="dl-history '.$name.'"></tbody>
  5059. </table>
  5060. </div>
  5061. </div>
  5062. </div>
  5063. </div>
  5064. </div>
  5065. </div>
  5066. </div>
  5067. </div>';
  5068. }
  5069. class Mobile_Detect
  5070. {
  5071. /**
  5072. * Mobile detection type.
  5073. *
  5074. * @deprecated since version 2.6.9
  5075. */
  5076. const DETECTION_TYPE_MOBILE = 'mobile';
  5077. /**
  5078. * Extended detection type.
  5079. *
  5080. * @deprecated since version 2.6.9
  5081. */
  5082. const DETECTION_TYPE_EXTENDED = 'extended';
  5083. /**
  5084. * A frequently used regular expression to extract version #s.
  5085. *
  5086. * @deprecated since version 2.6.9
  5087. */
  5088. const VER = '([\w._\+]+)';
  5089. /**
  5090. * Top-level device.
  5091. */
  5092. const MOBILE_GRADE_A = 'A';
  5093. /**
  5094. * Mid-level device.
  5095. */
  5096. const MOBILE_GRADE_B = 'B';
  5097. /**
  5098. * Low-level device.
  5099. */
  5100. const MOBILE_GRADE_C = 'C';
  5101. /**
  5102. * Stores the version number of the current release.
  5103. */
  5104. const VERSION = '2.8.26';
  5105. /**
  5106. * A type for the version() method indicating a string return value.
  5107. */
  5108. const VERSION_TYPE_STRING = 'text';
  5109. /**
  5110. * A type for the version() method indicating a float return value.
  5111. */
  5112. const VERSION_TYPE_FLOAT = 'float';
  5113. /**
  5114. * A cache for resolved matches
  5115. * @var array
  5116. */
  5117. protected $cache = array();
  5118. /**
  5119. * The User-Agent HTTP header is stored in here.
  5120. * @var string
  5121. */
  5122. protected $userAgent = null;
  5123. /**
  5124. * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.
  5125. * @var array
  5126. */
  5127. protected $httpHeaders = array();
  5128. /**
  5129. * CloudFront headers. E.g. CloudFront-Is-Desktop-Viewer, CloudFront-Is-Mobile-Viewer & CloudFront-Is-Tablet-Viewer.
  5130. * @var array
  5131. */
  5132. protected $cloudfrontHeaders = array();
  5133. /**
  5134. * The matching Regex.
  5135. * This is good for debug.
  5136. * @var string
  5137. */
  5138. protected $matchingRegex = null;
  5139. /**
  5140. * The matches extracted from the regex expression.
  5141. * This is good for debug.
  5142. * @var string
  5143. */
  5144. protected $matchesArray = null;
  5145. /**
  5146. * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.
  5147. *
  5148. * @deprecated since version 2.6.9
  5149. *
  5150. * @var string
  5151. */
  5152. protected $detectionType = self::DETECTION_TYPE_MOBILE;
  5153. /**
  5154. * HTTP headers that trigger the 'isMobile' detection
  5155. * to be true.
  5156. *
  5157. * @var array
  5158. */
  5159. protected static $mobileHeaders = array(
  5160. 'HTTP_ACCEPT' => array('matches' => array(
  5161. // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
  5162. 'application/x-obml2d',
  5163. // BlackBerry devices.
  5164. 'application/vnd.rim.html',
  5165. 'text/vnd.wap.wml',
  5166. 'application/vnd.wap.xhtml+xml'
  5167. )),
  5168. 'HTTP_X_WAP_PROFILE' => null,
  5169. 'HTTP_X_WAP_CLIENTID' => null,
  5170. 'HTTP_WAP_CONNECTION' => null,
  5171. 'HTTP_PROFILE' => null,
  5172. // Reported by Opera on Nokia devices (eg. C3).
  5173. 'HTTP_X_OPERAMINI_PHONE_UA' => null,
  5174. 'HTTP_X_NOKIA_GATEWAY_ID' => null,
  5175. 'HTTP_X_ORANGE_ID' => null,
  5176. 'HTTP_X_VODAFONE_3GPDPCONTEXT' => null,
  5177. 'HTTP_X_HUAWEI_USERID' => null,
  5178. // Reported by Windows Smartphones.
  5179. 'HTTP_UA_OS' => null,
  5180. // Reported by Verizon, Vodafone proxy system.
  5181. 'HTTP_X_MOBILE_GATEWAY' => null,
  5182. // Seen this on HTC Sensation. SensationXE_Beats_Z715e.
  5183. 'HTTP_X_ATT_DEVICEID' => null,
  5184. // Seen this on a HTC.
  5185. 'HTTP_UA_CPU' => array('matches' => array('ARM')),
  5186. );
  5187. /**
  5188. * List of mobile devices (phones).
  5189. *
  5190. * @var array
  5191. */
  5192. protected static $phoneDevices = array(
  5193. 'iPhone' => '\biPhone\b|\biPod\b', // |\biTunes
  5194. 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+',
  5195. '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',
  5196. 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 6',
  5197. // @todo: Is 'Dell Streak' a tablet or a phone? ;)
  5198. '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',
  5199. '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',
  5200. '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',
  5201. '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)',
  5202. 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|LT26w|SonyEricssonMT27i|C5303|C6902|C6903|C6906|C6943|D2533',
  5203. 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile',
  5204. 'NokiaLumia' => 'Lumia [0-9]{3,4}',
  5205. // http://www.micromaxinfo.com/mobiles/smartphones
  5206. // Added because the codes might conflict with Acer Tablets.
  5207. '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',
  5208. // @todo Complete the regex.
  5209. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ;
  5210. 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
  5211. // http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
  5212. // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android.
  5213. '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',
  5214. // http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones.
  5215. 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250',
  5216. // http://fr.wikomobile.com
  5217. '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',
  5218. 'iMobile' => 'i-mobile (IQ|i-STYLE|idea|ZAA|Hitz)',
  5219. // Added simvalley mobile just for fun. They have some interesting devices.
  5220. // http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html
  5221. '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',
  5222. // Wolfgang - a brand that is sold by Aldi supermarkets.
  5223. // http://www.wolfgangmobile.com/
  5224. 'Wolfgang' => 'AT-B24D|AT-AS50HD|AT-AS40W|AT-AS55HD|AT-AS45q2|AT-B26D|AT-AS50Q',
  5225. 'Alcatel' => 'Alcatel',
  5226. 'Nintendo' => 'Nintendo 3DS',
  5227. // http://en.wikipedia.org/wiki/Amoi
  5228. 'Amoi' => 'Amoi',
  5229. // http://en.wikipedia.org/wiki/INQ
  5230. 'INQ' => 'INQ',
  5231. // @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039
  5232. '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',
  5233. );
  5234. /**
  5235. * List of tablet devices.
  5236. *
  5237. * @var array
  5238. */
  5239. protected static $tabletDevices = array(
  5240. // @todo: check for mobile friendly emails topic.
  5241. 'iPad' => 'iPad|iPad.*Mobile',
  5242. // Removed |^.*Android.*Nexus(?!(?:Mobile).)*$
  5243. // @see #442
  5244. 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)',
  5245. '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.
  5246. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
  5247. '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)',
  5248. // Only the Surface tablets with Windows RT are considered mobile.
  5249. // http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx
  5250. 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;.*(Tablet|ARMBJS)',
  5251. // http://shopping1.hp.com/is-bin/INTERSHOP.enfinity/WFS/WW-USSMBPublicStore-Site/en_US/-/USD/ViewStandardCatalog-Browse?CatalogCategoryID=JfIQ7EN5lqMAAAEyDcJUDwMT
  5252. 'HPTablet' => 'HP Slate (7|8|10)|HP ElitePad 900|hp-tablet|EliteBook.*Touch|HP 8|Slate 21|HP SlateBook 10',
  5253. // Watch out for PadFone, see #132.
  5254. // http://www.asus.com/de/Tablets_Mobile/Memo_Pad_Products/
  5255. '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',
  5256. 'BlackBerryTablet' => 'PlayBook|RIM Tablet',
  5257. 'HTCtablet' => 'HTC_Flyer_P512|HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200|PG09410',
  5258. 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617',
  5259. 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2',
  5260. // http://www.acer.ro/ac/ro/RO/content/drivers
  5261. // http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer)
  5262. // http://us.acer.com/ac/en/US/content/group/tablets
  5263. // http://www.acer.de/ac/de/DE/content/models/tablets/
  5264. // Can conflict with Micromax and Motorola phones codes.
  5265. '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',
  5266. // http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/
  5267. // http://us.toshiba.com/tablets/tablet-finder
  5268. // http://www.toshiba.co.jp/regza/tablet/
  5269. 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO',
  5270. // http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html
  5271. // http://www.lg.com/us/tablets
  5272. 'LGTablet' => '\bL-06C|LG-V909|LG-V900|LG-V700|LG-V510|LG-V500|LG-V410|LG-V400|LG-VK810\b',
  5273. 'FujitsuTablet' => 'Android.*\b(F-01D|F-02F|F-05E|F-10D|M532|Q572)\b',
  5274. // Prestigio Tablets http://www.prestigio.com/support
  5275. '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',
  5276. // http://support.lenovo.com/en_GB/downloads/default.page?#
  5277. '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|)',
  5278. // http://www.dell.com/support/home/us/en/04/Products/tab_mob/tablets
  5279. 'DellTablet' => 'Venue 11|Venue 8|Venue 7|Dell Streak 10|Dell Streak 7',
  5280. // http://www.yarvik.com/en/matrix/tablets/
  5281. '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',
  5282. 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB',
  5283. 'ArnovaTablet' => '97G4|AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT|AN9G2',
  5284. // http://www.intenso.de/kategorie_en.php?kategorie=33
  5285. // @todo: http://www.nbhkdz.com/read/b8e64202f92a2df129126bff.html - investigate
  5286. 'IntensoTablet' => 'INM8002KP|INM1010FP|INM805ND|Intenso Tab|TAB1004',
  5287. // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/
  5288. 'IRUTablet' => 'M702pro',
  5289. 'MegafonTablet' => 'MegaFon V9|\bZTE V9\b|Android.*\bMT7A\b',
  5290. // http://www.e-boda.ro/tablete-pc.html
  5291. 'EbodaTablet' => 'E-Boda (Supreme|Impresspeed|Izzycomm|Essential)',
  5292. // http://www.allview.ro/produse/droseries/lista-tablete-pc/
  5293. 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)',
  5294. // http://wiki.archosfans.com/index.php?title=Main_Page
  5295. // @note Rewrite the regex format after we add more UAs.
  5296. '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',
  5297. // http://www.ainol.com/plugin.php?identifier=ainol&module=product
  5298. 'AinolTablet' => 'NOVO7|NOVO8|NOVO10|Novo7Aurora|Novo7Basic|NOVO7PALADIN|novo9-Spark',
  5299. 'NokiaLumiaTablet' => 'Lumia 2520',
  5300. // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER
  5301. // Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser
  5302. // http://www.sony.jp/support/tablet/
  5303. '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',
  5304. // 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
  5305. 'PhilipsTablet' => '\b(PI2010|PI3000|PI3100|PI3105|PI3110|PI3205|PI3210|PI3900|PI4010|PI7000|PI7100)\b',
  5306. // db + http://www.cube-tablet.com/buy-products.html
  5307. 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT',
  5308. // http://www.cobyusa.com/?p=pcat&pcat_id=3001
  5309. 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010',
  5310. // http://www.match.net.cn/products.asp
  5311. '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',
  5312. // http://www.msi.com/support
  5313. // @todo Research the Windows Tablets.
  5314. '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',
  5315. // @todo http://www.kyoceramobile.com/support/drivers/
  5316. // 'KyoceraTablet' => null,
  5317. // @todo http://intexuae.com/index.php/category/mobile-devices/tablets-products/
  5318. // 'IntextTablet' => null,
  5319. // http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets)
  5320. // http://www.imp3.net/14/show.php?itemid=20454
  5321. 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)',
  5322. // http://www.rock-chips.com/index.php?do=prod&pid=2
  5323. 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A',
  5324. // http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/
  5325. 'FlyTablet' => 'IQ310|Fly Vision',
  5326. // http://www.bqreaders.com/gb/tablets-prices-sale.html
  5327. 'bqTablet' => 'Android.*(bq)?.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris [E|M]10)|Maxwell.*Lite|Maxwell.*Plus',
  5328. // http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
  5329. // http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
  5330. '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',
  5331. // Nec or Medias Tab
  5332. 'NecTablet' => '\bN-06D|\bN-08D',
  5333. // Pantech Tablets: http://www.pantechusa.com/phones/
  5334. 'PantechTablet' => 'Pantech.*P4100',
  5335. // Broncho Tablets: http://www.broncho.cn/ (hard to find)
  5336. 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)',
  5337. // http://versusuk.com/support.html
  5338. 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b',
  5339. // http://www.zync.in/index.php/our-products/tablet-phablets
  5340. 'ZyncTablet' => 'z1000|Z99 2G|z99|z930|z999|z990|z909|Z919|z900',
  5341. // http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/
  5342. 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA',
  5343. // https://www.nabitablet.com/
  5344. 'NabiTablet' => 'Android.*\bNabi',
  5345. 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build',
  5346. // French Danew Tablets http://www.danew.com/produits-tablette.php
  5347. 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b',
  5348. // Texet Tablets and Readers http://www.texet.ru/tablet/
  5349. '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',
  5350. // Avoid detecting 'PLAYSTATION 3' as mobile.
  5351. 'PlaystationTablet' => 'Playstation.*(Portable|Vita)',
  5352. // http://www.trekstor.de/surftabs.html
  5353. 'TrekstorTablet' => 'ST10416-1|VT10416-1|ST70408-1|ST702xx-1|ST702xx-2|ST80208|ST97216|ST70104-2|VT10416-2|ST10216-2A|SurfTab',
  5354. // http://www.pyleaudio.com/Products.aspx?%2fproducts%2fPersonal-Electronics%2fTablets
  5355. 'PyleAudioTablet' => '\b(PTBL10CEU|PTBL10C|PTBL72BC|PTBL72BCEU|PTBL7CEU|PTBL7C|PTBL92BC|PTBL92BCEU|PTBL9CEU|PTBL9CUK|PTBL9C)\b',
  5356. // http://www.advandigital.com/index.php?link=content-product&jns=JP001
  5357. // because of the short codenames we have to include whitespaces to reduce the possible conflicts.
  5358. '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 ',
  5359. // http://www.danytech.com/category/tablet-pc
  5360. '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',
  5361. // http://www.galapad.net/product.html
  5362. 'GalapadTablet' => 'Android.*\bG1\b',
  5363. // http://www.micromaxinfo.com/tablet/funbook
  5364. 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b',
  5365. // http://www.karbonnmobiles.com/products_tablet.php
  5366. 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b',
  5367. // http://www.myallfine.com/Products.asp
  5368. 'AllFineTablet' => 'Fine7 Genius|Fine7 Shine|Fine7 Air|Fine8 Style|Fine9 More|Fine10 Joy|Fine11 Wide',
  5369. // http://www.proscanvideo.com/products-search.asp?itemClass=TABLET&itemnmbr=
  5370. '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',
  5371. // http://www.yonesnav.com/products/products.php
  5372. 'YONESTablet' => 'BQ1078|BC1003|BC1077|RK9702|BC9730|BC9001|IT9001|BC7008|BC7010|BC708|BC728|BC7012|BC7030|BC7027|BC7026',
  5373. // http://www.cjshowroom.com/eproducts.aspx?classcode=004001001
  5374. // China manufacturer makes tablets for different small brands (eg. http://www.zeepad.net/index.html)
  5375. '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',
  5376. // http://www.gloryunion.cn/products.asp
  5377. // http://www.allwinnertech.com/en/apply/mobile.html
  5378. // http://www.ptcl.com.pk/pd_content.php?pd_id=284 (EVOTAB)
  5379. // @todo: Softwiner tablets?
  5380. // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions.
  5381. '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
  5382. // http://www.pointofview-online.com/showroom.php?shop_mode=product_listing&category_id=118
  5383. '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',
  5384. // http://www.overmax.pl/pl/katalog-produktow,p8/tablety,c14/
  5385. // @todo: add more tests.
  5386. 'OvermaxTablet' => 'OV-(SteelCore|NewBase|Basecore|Baseone|Exellen|Quattor|EduTab|Solution|ACTION|BasicTab|TeddyTab|MagicTab|Stream|TB-08|TB-09)',
  5387. // http://hclmetablet.com/India/index.php
  5388. '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',
  5389. // http://www.edigital.hu/Tablet_es_e-book_olvaso/Tablet-c18385.html
  5390. 'DPSTablet' => 'DPS Dream 9|DPS Dual 7',
  5391. // http://www.visture.com/index.asp
  5392. 'VistureTablet' => 'V97 HD|i75 3G|Visture V4( HD)?|Visture V5( HD)?|Visture V10',
  5393. // http://www.mijncresta.nl/tablet
  5394. 'CrestaTablet' => 'CTP(-)?810|CTP(-)?818|CTP(-)?828|CTP(-)?838|CTP(-)?888|CTP(-)?978|CTP(-)?980|CTP(-)?987|CTP(-)?988|CTP(-)?989',
  5395. // MediaTek - http://www.mediatek.com/_en/01_products/02_proSys.php?cata_sn=1&cata1_sn=1&cata2_sn=309
  5396. 'MediatekTablet' => '\bMT8125|MT8389|MT8135|MT8377\b',
  5397. // Concorde tab
  5398. 'ConcordeTablet' => 'Concorde([ ]+)?Tab|ConCorde ReadMan',
  5399. // GoClever Tablets - http://www.goclever.com/uk/products,c1/tablet,c5/
  5400. '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',
  5401. // Modecom Tablets - http://www.modecom.eu/tablets/portal/
  5402. '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',
  5403. // Vonino Tablets - http://www.vonino.eu/tablets
  5404. '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',
  5405. // ECS Tablets - http://www.ecs.com.tw/ECSWebSite/Product/Product_Tablet_List.aspx?CategoryID=14&MenuID=107&childid=M_107&LanID=0
  5406. 'ECSTablet' => 'V07OT2|TM105A|S10OT1|TR10CS1',
  5407. // Storex Tablets - http://storex.fr/espace_client/support.html
  5408. // @note: no need to add all the tablet codes since they are guided by the first regex.
  5409. 'StorexTablet' => 'eZee[_\']?(Tab|Go)[0-9]+|TabLC7|Looney Tunes Tab',
  5410. // Generic Vodafone tablets.
  5411. 'VodafoneTablet' => 'SmartTab([ ]+)?[0-9]+|SmartTabII10|SmartTabII7|VF-1497',
  5412. // French tablets - Essentiel B http://www.boulanger.fr/tablette_tactile_e-book/tablette_tactile_essentiel_b/cl_68908.htm?multiChoiceToDelete=brand&mc_brand=essentielb
  5413. // Aka: http://www.essentielb.fr/
  5414. 'EssentielBTablet' => 'Smart[ \']?TAB[ ]+?[0-9]+|Family[ \']?TAB2',
  5415. // Ross & Moor - http://ross-moor.ru/
  5416. 'RossMoorTablet' => 'RM-790|RM-997|RMD-878G|RMD-974R|RMT-705A|RMT-701|RME-601|RMT-501|RMT-711',
  5417. // i-mobile http://product.i-mobilephone.com/Mobile_Device
  5418. 'iMobileTablet' => 'i-mobile i-note',
  5419. // http://www.tolino.de/de/vergleichen/
  5420. 'TolinoTablet' => 'tolino tab [0-9.]+|tolino shine',
  5421. // AudioSonic - a Kmart brand
  5422. // 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
  5423. 'AudioSonicTablet' => '\bC-22Q|T7-QC|T-17B|T-17P\b',
  5424. // AMPE Tablets - http://www.ampe.com.my/product-category/tablets/
  5425. // @todo: add them gradually to avoid conflicts.
  5426. 'AMPETablet' => 'Android.* A78 ',
  5427. // Skk Mobile - http://skkmobile.com.ph/product_tablets.php
  5428. 'SkkTablet' => 'Android.* (SKYPAD|PHOENIX|CYCLOPS)',
  5429. // Tecno Mobile (only tablet) - http://www.tecno-mobile.com/index.php/product?filterby=smart&list_order=all&page=1
  5430. 'TecnoTablet' => 'TECNO P9',
  5431. // JXD (consoles & tablets) - http://jxd.hk/products.asp?selectclassid=009008&clsid=3
  5432. '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',
  5433. // i-Joy tablets - http://www.i-joy.es/en/cat/products/tablets/
  5434. '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)',
  5435. // http://www.intracon.eu/tablet
  5436. 'FX2Tablet' => 'FX2 PAD7|FX2 PAD10',
  5437. // http://www.xoro.de/produkte/
  5438. // @note: Might be the same brand with 'Simply tablets'
  5439. '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',
  5440. // http://www1.viewsonic.com/products/computing/tablets/
  5441. 'ViewsonicTablet' => 'ViewPad 10pi|ViewPad 10e|ViewPad 10s|ViewPad E72|ViewPad7|ViewPad E100|ViewPad 7e|ViewSonic VB733|VB100a',
  5442. // http://www.odys.de/web/internet-tablet_en.html
  5443. 'OdysTablet' => 'LOOX|XENO10|ODYS[ -](Space|EVO|Xpress|NOON)|\bXELIO\b|Xelio10Pro|XELIO7PHONETAB|XELIO10EXTREME|XELIOPT2|NEO_QUAD10',
  5444. // http://www.captiva-power.de/products.html#tablets-en
  5445. 'CaptivaTablet' => 'CAPTIVA PAD',
  5446. // IconBIT - http://www.iconbit.com/products/tablets/
  5447. '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',
  5448. // http://www.teclast.com/topic.php?channelID=70&topicID=140&pid=63
  5449. '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',
  5450. // Onda - http://www.onda-tablet.com/buy-android-onda.html?dir=desc&limit=all&order=price
  5451. '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]+',
  5452. 'JaytechTablet' => 'TPC-PA762',
  5453. 'BlaupunktTablet' => 'Endeavour 800NG|Endeavour 1010',
  5454. // http://www.digma.ru/support/download/
  5455. // @todo: Ebooks also (if requested)
  5456. 'DigmaTablet' => '\b(iDx10|iDx9|iDx8|iDx7|iDxD7|iDxD8|iDsQ8|iDsQ7|iDsQ8|iDsD10|iDnD7|3TS804H|iDsQ11|iDj7|iDs10)\b',
  5457. // http://www.evolioshop.com/ro/tablete-pc.html
  5458. // http://www.evolio.ro/support/downloads_static.html?cat=2
  5459. // @todo: Research some more
  5460. 'EvolioTablet' => 'ARIA_Mini_wifi|Aria[ _]Mini|Evolio X10|Evolio X7|Evolio X8|\bEvotab\b|\bNeura\b',
  5461. // @todo http://www.lavamobiles.com/tablets-data-cards
  5462. 'LavaTablet' => 'QPAD E704|\bIvoryS\b|E-TAB IVORY|\bE-TAB\b',
  5463. // http://www.breezetablet.com/
  5464. 'AocTablet' => 'MW0811|MW0812|MW0922|MTK8382|MW1031|MW0831|MW0821|MW0931|MW0712',
  5465. // http://www.mpmaneurope.com/en/products/internet-tablets-14/android-tablets-14/
  5466. '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',
  5467. // https://www.celkonmobiles.com/?_a=categoryphones&sid=2
  5468. 'CelkonTablet' => 'CT695|CT888|CT[\s]?910|CT7 Tab|CT9 Tab|CT3 Tab|CT2 Tab|CT1 Tab|C820|C720|\bCT-1\b',
  5469. // http://www.wolderelectronics.com/productos/manuales-y-guias-rapidas/categoria-2-miTab
  5470. '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',
  5471. // http://www.mi.com/en
  5472. 'MiTablet' => '\bMI PAD\b|\bHM NOTE 1W\b',
  5473. // http://www.nbru.cn/index.html
  5474. 'NibiruTablet' => 'Nibiru M1|Nibiru Jupiter One',
  5475. // http://navroad.com/products/produkty/tablety/
  5476. // http://navroad.com/products/produkty/tablety/
  5477. 'NexoTablet' => 'NEXO NOVA|NEXO 10|NEXO AVIO|NEXO FREE|NEXO GO|NEXO EVO|NEXO 3G|NEXO SMART|NEXO KIDDO|NEXO MOBI',
  5478. // http://leader-online.com/new_site/product-category/tablets/
  5479. // http://www.leader-online.net.au/List/Tablet
  5480. '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',
  5481. // http://www.datawind.com/ubislate/
  5482. 'UbislateTablet' => 'UbiSlate[\s]?7C',
  5483. // http://www.pocketbook-int.com/ru/support
  5484. 'PocketBookTablet' => 'Pocketbook',
  5485. // http://www.kocaso.com/product_tablet.html
  5486. 'KocasoTablet' => '\b(TB-1207)\b',
  5487. // http://global.hisense.com/product/asia/tablet/Sero7/201412/t20141215_91832.htm
  5488. 'HisenseTablet' => '\b(F5281|E2371)\b',
  5489. // http://www.tesco.com/direct/hudl/
  5490. 'Hudl' => 'Hudl HT7S3|Hudl 2',
  5491. // http://www.telstra.com.au/home-phone/thub-2/
  5492. 'TelstraTablet' => 'T-Hub2',
  5493. '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'
  5494. );
  5495. /**
  5496. * List of mobile Operating Systems.
  5497. *
  5498. * @var array
  5499. */
  5500. protected static $operatingSystems = array(
  5501. 'AndroidOS' => 'Android',
  5502. 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os',
  5503. 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
  5504. 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
  5505. // @reference: http://en.wikipedia.org/wiki/Windows_Mobile
  5506. 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;',
  5507. // @reference: http://en.wikipedia.org/wiki/Windows_Phone
  5508. // http://wifeng.cn/?r=blog&a=view&id=106
  5509. // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx
  5510. // http://msdn.microsoft.com/library/ms537503.aspx
  5511. // https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
  5512. 'WindowsPhoneOS' => 'Windows Phone 10.0|Windows Phone 8.1|Windows Phone 8.0|Windows Phone OS|XBLWP7|ZuneWP7|Windows NT 6.[23]; ARM;',
  5513. 'iOS' => '\biPhone.*Mobile|\biPod|\biPad',
  5514. // http://en.wikipedia.org/wiki/MeeGo
  5515. // @todo: research MeeGo in UAs
  5516. 'MeeGoOS' => 'MeeGo',
  5517. // http://en.wikipedia.org/wiki/Maemo
  5518. // @todo: research Maemo in UAs
  5519. 'MaemoOS' => 'Maemo',
  5520. 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135
  5521. 'webOS' => 'webOS|hpwOS',
  5522. 'badaOS' => '\bBada\b',
  5523. 'BREWOS' => 'BREW',
  5524. );
  5525. /**
  5526. * List of mobile User Agents.
  5527. *
  5528. * IMPORTANT: This is a list of only mobile browsers.
  5529. * Mobile Detect 2.x supports only mobile browsers,
  5530. * it was never designed to detect all browsers.
  5531. * The change will come in 2017 in the 3.x release for PHP7.
  5532. *
  5533. * @var array
  5534. */
  5535. protected static $browsers = array(
  5536. //'Vivaldi' => 'Vivaldi',
  5537. // @reference: https://developers.google.com/chrome/mobile/docs/user-agent
  5538. 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?',
  5539. 'Dolfin' => '\bDolfin\b',
  5540. 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+|Coast/[0-9.]+',
  5541. 'Skyfire' => 'Skyfire',
  5542. 'Edge' => 'Mobile Safari/[.0-9]* Edge',
  5543. 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+
  5544. 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS',
  5545. 'Bolt' => 'bolt',
  5546. 'TeaShark' => 'teashark',
  5547. 'Blazer' => 'Blazer',
  5548. // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3
  5549. 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari',
  5550. // http://en.wikipedia.org/wiki/Midori_(web_browser)
  5551. //'Midori' => 'midori',
  5552. //'Tizen' => 'Tizen',
  5553. 'UCBrowser' => 'UC.*Browser|UCWEB',
  5554. 'baiduboxapp' => 'baiduboxapp',
  5555. 'baidubrowser' => 'baidubrowser',
  5556. // https://github.com/serbanghita/Mobile-Detect/issues/7
  5557. 'DiigoBrowser' => 'DiigoBrowser',
  5558. // http://www.puffinbrowser.com/index.php
  5559. 'Puffin' => 'Puffin',
  5560. // http://mercury-browser.com/index.html
  5561. 'Mercury' => '\bMercury\b',
  5562. // http://en.wikipedia.org/wiki/Obigo_Browser
  5563. 'ObigoBrowser' => 'Obigo',
  5564. // http://en.wikipedia.org/wiki/NetFront
  5565. 'NetFront' => 'NF-Browser',
  5566. // @reference: http://en.wikipedia.org/wiki/Minimo
  5567. // http://en.wikipedia.org/wiki/Vision_Mobile_Browser
  5568. 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger',
  5569. // @reference: https://en.wikipedia.org/wiki/Pale_Moon_(web_browser)
  5570. 'PaleMoon' => 'Android.*PaleMoon|Mobile.*PaleMoon',
  5571. );
  5572. /**
  5573. * Utilities.
  5574. *
  5575. * @var array
  5576. */
  5577. protected static $utilities = array(
  5578. // Experimental. When a mobile device wants to switch to 'Desktop Mode'.
  5579. // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/
  5580. // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011
  5581. // https://developers.facebook.com/docs/sharing/best-practices
  5582. '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',
  5583. 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2',
  5584. 'DesktopMode' => 'WPDesktop',
  5585. 'TV' => 'SonyDTV|HbbTV', // experimental
  5586. 'WebKit' => '(webkit)[ /]([\w.]+)',
  5587. // @todo: Include JXD consoles.
  5588. 'Console' => '\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b',
  5589. 'Watch' => 'SM-V700',
  5590. );
  5591. /**
  5592. * All possible HTTP headers that represent the
  5593. * User-Agent string.
  5594. *
  5595. * @var array
  5596. */
  5597. protected static $uaHttpHeaders = array(
  5598. // The default User-Agent string.
  5599. 'HTTP_USER_AGENT',
  5600. // Header can occur on devices using Opera Mini.
  5601. 'HTTP_X_OPERAMINI_PHONE_UA',
  5602. // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
  5603. 'HTTP_X_DEVICE_USER_AGENT',
  5604. 'HTTP_X_ORIGINAL_USER_AGENT',
  5605. 'HTTP_X_SKYFIRE_PHONE',
  5606. 'HTTP_X_BOLT_PHONE_UA',
  5607. 'HTTP_DEVICE_STOCK_UA',
  5608. 'HTTP_X_UCBROWSER_DEVICE_UA'
  5609. );
  5610. /**
  5611. * The individual segments that could exist in a User-Agent string. VER refers to the regular
  5612. * expression defined in the constant self::VER.
  5613. *
  5614. * @var array
  5615. */
  5616. protected static $properties = array(
  5617. // Build
  5618. 'Mobile' => 'Mobile/[VER]',
  5619. 'Build' => 'Build/[VER]',
  5620. 'Version' => 'Version/[VER]',
  5621. 'VendorID' => 'VendorID/[VER]',
  5622. // Devices
  5623. 'iPad' => 'iPad.*CPU[a-z ]+[VER]',
  5624. 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]',
  5625. 'iPod' => 'iPod.*CPU[a-z ]+[VER]',
  5626. //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'),
  5627. 'Kindle' => 'Kindle/[VER]',
  5628. // Browser
  5629. 'Chrome' => array('Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'),
  5630. 'Coast' => array('Coast/[VER]'),
  5631. 'Dolfin' => 'Dolfin/[VER]',
  5632. // @reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
  5633. 'Firefox' => array('Firefox/[VER]', 'FxiOS/[VER]'),
  5634. 'Fennec' => 'Fennec/[VER]',
  5635. // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
  5636. // https://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
  5637. 'Edge' => 'Edge/[VER]',
  5638. 'IE' => array('IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'Trident/[0-9.]+;.*rv:[VER]'),
  5639. // http://en.wikipedia.org/wiki/NetFront
  5640. 'NetFront' => 'NetFront/[VER]',
  5641. 'NokiaBrowser' => 'NokiaBrowser/[VER]',
  5642. 'Opera' => array( ' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]' ),
  5643. 'Opera Mini' => 'Opera Mini/[VER]',
  5644. 'Opera Mobi' => 'Version/[VER]',
  5645. 'UC Browser' => 'UC Browser[VER]',
  5646. 'MQQBrowser' => 'MQQBrowser/[VER]',
  5647. 'MicroMessenger' => 'MicroMessenger/[VER]',
  5648. 'baiduboxapp' => 'baiduboxapp/[VER]',
  5649. 'baidubrowser' => 'baidubrowser/[VER]',
  5650. 'SamsungBrowser' => 'SamsungBrowser/[VER]',
  5651. 'Iron' => 'Iron/[VER]',
  5652. // @note: Safari 7534.48.3 is actually Version 5.1.
  5653. // @note: On BlackBerry the Version is overwriten by the OS.
  5654. 'Safari' => array( 'Version/[VER]', 'Safari/[VER]' ),
  5655. 'Skyfire' => 'Skyfire/[VER]',
  5656. 'Tizen' => 'Tizen/[VER]',
  5657. 'Webkit' => 'webkit[ /][VER]',
  5658. 'PaleMoon' => 'PaleMoon/[VER]',
  5659. // Engine
  5660. 'Gecko' => 'Gecko/[VER]',
  5661. 'Trident' => 'Trident/[VER]',
  5662. 'Presto' => 'Presto/[VER]',
  5663. 'Goanna' => 'Goanna/[VER]',
  5664. // OS
  5665. 'iOS' => ' \bi?OS\b [VER][ ;]{1}',
  5666. 'Android' => 'Android [VER]',
  5667. 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'),
  5668. 'BREW' => 'BREW [VER]',
  5669. 'Java' => 'Java/[VER]',
  5670. // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx
  5671. // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases
  5672. 'Windows Phone OS' => array( 'Windows Phone OS [VER]', 'Windows Phone [VER]'),
  5673. 'Windows Phone' => 'Windows Phone [VER]',
  5674. 'Windows CE' => 'Windows CE/[VER]',
  5675. // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd
  5676. 'Windows NT' => 'Windows NT [VER]',
  5677. 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'),
  5678. 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'),
  5679. );
  5680. /**
  5681. * Construct an instance of this class.
  5682. *
  5683. * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored.
  5684. * If left empty, will use the global _SERVER['HTTP_*'] vars instead.
  5685. * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
  5686. * from the $headers array instead.
  5687. */
  5688. public function __construct(
  5689. array $headers = null,
  5690. $userAgent = null
  5691. ) {
  5692. $this->setHttpHeaders($headers);
  5693. $this->setUserAgent($userAgent);
  5694. }
  5695. /**
  5696. * Get the current script version.
  5697. * This is useful for the demo.php file,
  5698. * so people can check on what version they are testing
  5699. * for mobile devices.
  5700. *
  5701. * @return string The version number in semantic version format.
  5702. */
  5703. public static function getScriptVersion()
  5704. {
  5705. return self::VERSION;
  5706. }
  5707. /**
  5708. * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
  5709. *
  5710. * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
  5711. * the headers. The default null is left for backwards compatibility.
  5712. */
  5713. public function setHttpHeaders($httpHeaders = null)
  5714. {
  5715. // use global _SERVER if $httpHeaders aren't defined
  5716. if (!is_array($httpHeaders) || !count($httpHeaders)) {
  5717. $httpHeaders = $_SERVER;
  5718. }
  5719. // clear existing headers
  5720. $this->httpHeaders = array();
  5721. // Only save HTTP headers. In PHP land, that means only _SERVER vars that
  5722. // start with HTTP_.
  5723. foreach ($httpHeaders as $key => $value) {
  5724. if (substr($key, 0, 5) === 'HTTP_') {
  5725. $this->httpHeaders[$key] = $value;
  5726. }
  5727. }
  5728. // In case we're dealing with CloudFront, we need to know.
  5729. $this->setCfHeaders($httpHeaders);
  5730. }
  5731. /**
  5732. * Retrieves the HTTP headers.
  5733. *
  5734. * @return array
  5735. */
  5736. public function getHttpHeaders()
  5737. {
  5738. return $this->httpHeaders;
  5739. }
  5740. /**
  5741. * Retrieves a particular header. If it doesn't exist, no exception/error is caused.
  5742. * Simply null is returned.
  5743. *
  5744. * @param string $header The name of the header to retrieve. Can be HTTP compliant such as
  5745. * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the
  5746. * all-caps, HTTP_ prefixed, underscore seperated awesomeness.
  5747. *
  5748. * @return string|null The value of the header.
  5749. */
  5750. public function getHttpHeader($header)
  5751. {
  5752. // are we using PHP-flavored headers?
  5753. if (strpos($header, '_') === false) {
  5754. $header = str_replace('-', '_', $header);
  5755. $header = strtoupper($header);
  5756. }
  5757. // test the alternate, too
  5758. $altHeader = 'HTTP_' . $header;
  5759. //Test both the regular and the HTTP_ prefix
  5760. if (isset($this->httpHeaders[$header])) {
  5761. return $this->httpHeaders[$header];
  5762. } elseif (isset($this->httpHeaders[$altHeader])) {
  5763. return $this->httpHeaders[$altHeader];
  5764. }
  5765. return null;
  5766. }
  5767. public function getMobileHeaders()
  5768. {
  5769. return self::$mobileHeaders;
  5770. }
  5771. /**
  5772. * Get all possible HTTP headers that
  5773. * can contain the User-Agent string.
  5774. *
  5775. * @return array List of HTTP headers.
  5776. */
  5777. public function getUaHttpHeaders()
  5778. {
  5779. return self::$uaHttpHeaders;
  5780. }
  5781. /**
  5782. * Set CloudFront headers
  5783. * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device
  5784. *
  5785. * @param array $cfHeaders List of HTTP headers
  5786. *
  5787. * @return boolean If there were CloudFront headers to be set
  5788. */
  5789. public function setCfHeaders($cfHeaders = null) {
  5790. // use global _SERVER if $cfHeaders aren't defined
  5791. if (!is_array($cfHeaders) || !count($cfHeaders)) {
  5792. $cfHeaders = $_SERVER;
  5793. }
  5794. // clear existing headers
  5795. $this->cloudfrontHeaders = array();
  5796. // Only save CLOUDFRONT headers. In PHP land, that means only _SERVER vars that
  5797. // start with cloudfront-.
  5798. $response = false;
  5799. foreach ($cfHeaders as $key => $value) {
  5800. if (substr(strtolower($key), 0, 16) === 'http_cloudfront_') {
  5801. $this->cloudfrontHeaders[strtoupper($key)] = $value;
  5802. $response = true;
  5803. }
  5804. }
  5805. return $response;
  5806. }
  5807. /**
  5808. * Retrieves the cloudfront headers.
  5809. *
  5810. * @return array
  5811. */
  5812. public function getCfHeaders()
  5813. {
  5814. return $this->cloudfrontHeaders;
  5815. }
  5816. /**
  5817. * Set the User-Agent to be used.
  5818. *
  5819. * @param string $userAgent The user agent string to set.
  5820. *
  5821. * @return string|null
  5822. */
  5823. public function setUserAgent($userAgent = null)
  5824. {
  5825. // Invalidate cache due to #375
  5826. $this->cache = array();
  5827. if (false === empty($userAgent)) {
  5828. return $this->userAgent = $userAgent;
  5829. } else {
  5830. $this->userAgent = null;
  5831. foreach ($this->getUaHttpHeaders() as $altHeader) {
  5832. if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban)
  5833. $this->userAgent .= $this->httpHeaders[$altHeader] . " ";
  5834. }
  5835. }
  5836. if (!empty($this->userAgent)) {
  5837. return $this->userAgent = trim($this->userAgent);
  5838. }
  5839. }
  5840. if (count($this->getCfHeaders()) > 0) {
  5841. return $this->userAgent = 'Amazon CloudFront';
  5842. }
  5843. return $this->userAgent = null;
  5844. }
  5845. /**
  5846. * Retrieve the User-Agent.
  5847. *
  5848. * @return string|null The user agent if it's set.
  5849. */
  5850. public function getUserAgent()
  5851. {
  5852. return $this->userAgent;
  5853. }
  5854. /**
  5855. * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or
  5856. * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set.
  5857. *
  5858. * @deprecated since version 2.6.9
  5859. *
  5860. * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
  5861. * parameter is null which will default to self::DETECTION_TYPE_MOBILE.
  5862. */
  5863. public function setDetectionType($type = null)
  5864. {
  5865. if ($type === null) {
  5866. $type = self::DETECTION_TYPE_MOBILE;
  5867. }
  5868. if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) {
  5869. return;
  5870. }
  5871. $this->detectionType = $type;
  5872. }
  5873. public function getMatchingRegex()
  5874. {
  5875. return $this->matchingRegex;
  5876. }
  5877. public function getMatchesArray()
  5878. {
  5879. return $this->matchesArray;
  5880. }
  5881. /**
  5882. * Retrieve the list of known phone devices.
  5883. *
  5884. * @return array List of phone devices.
  5885. */
  5886. public static function getPhoneDevices()
  5887. {
  5888. return self::$phoneDevices;
  5889. }
  5890. /**
  5891. * Retrieve the list of known tablet devices.
  5892. *
  5893. * @return array List of tablet devices.
  5894. */
  5895. public static function getTabletDevices()
  5896. {
  5897. return self::$tabletDevices;
  5898. }
  5899. /**
  5900. * Alias for getBrowsers() method.
  5901. *
  5902. * @return array List of user agents.
  5903. */
  5904. public static function getUserAgents()
  5905. {
  5906. return self::getBrowsers();
  5907. }
  5908. /**
  5909. * Retrieve the list of known browsers. Specifically, the user agents.
  5910. *
  5911. * @return array List of browsers / user agents.
  5912. */
  5913. public static function getBrowsers()
  5914. {
  5915. return self::$browsers;
  5916. }
  5917. /**
  5918. * Retrieve the list of known utilities.
  5919. *
  5920. * @return array List of utilities.
  5921. */
  5922. public static function getUtilities()
  5923. {
  5924. return self::$utilities;
  5925. }
  5926. /**
  5927. * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().
  5928. *
  5929. * @deprecated since version 2.6.9
  5930. *
  5931. * @return array All the rules (but not extended).
  5932. */
  5933. public static function getMobileDetectionRules()
  5934. {
  5935. static $rules;
  5936. if (!$rules) {
  5937. $rules = array_merge(
  5938. self::$phoneDevices,
  5939. self::$tabletDevices,
  5940. self::$operatingSystems,
  5941. self::$browsers
  5942. );
  5943. }
  5944. return $rules;
  5945. }
  5946. /**
  5947. * Method gets the mobile detection rules + utilities.
  5948. * The reason this is separate is because utilities rules
  5949. * don't necessary imply mobile. This method is used inside
  5950. * the new $detect->is('stuff') method.
  5951. *
  5952. * @deprecated since version 2.6.9
  5953. *
  5954. * @return array All the rules + extended.
  5955. */
  5956. public function getMobileDetectionRulesExtended()
  5957. {
  5958. static $rules;
  5959. if (!$rules) {
  5960. // Merge all rules together.
  5961. $rules = array_merge(
  5962. self::$phoneDevices,
  5963. self::$tabletDevices,
  5964. self::$operatingSystems,
  5965. self::$browsers,
  5966. self::$utilities
  5967. );
  5968. }
  5969. return $rules;
  5970. }
  5971. /**
  5972. * Retrieve the current set of rules.
  5973. *
  5974. * @deprecated since version 2.6.9
  5975. *
  5976. * @return array
  5977. */
  5978. public function getRules()
  5979. {
  5980. if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) {
  5981. return self::getMobileDetectionRulesExtended();
  5982. } else {
  5983. return self::getMobileDetectionRules();
  5984. }
  5985. }
  5986. /**
  5987. * Retrieve the list of mobile operating systems.
  5988. *
  5989. * @return array The list of mobile operating systems.
  5990. */
  5991. public static function getOperatingSystems()
  5992. {
  5993. return self::$operatingSystems;
  5994. }
  5995. /**
  5996. * Check the HTTP headers for signs of mobile.
  5997. * This is the fastest mobile check possible; it's used
  5998. * inside isMobile() method.
  5999. *
  6000. * @return bool
  6001. */
  6002. public function checkHttpHeadersForMobile()
  6003. {
  6004. foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) {
  6005. if (isset($this->httpHeaders[$mobileHeader])) {
  6006. if (is_array($matchType['matches'])) {
  6007. foreach ($matchType['matches'] as $_match) {
  6008. if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) {
  6009. return true;
  6010. }
  6011. }
  6012. return false;
  6013. } else {
  6014. return true;
  6015. }
  6016. }
  6017. }
  6018. return false;
  6019. }
  6020. /**
  6021. * Magic overloading method.
  6022. *
  6023. * @method boolean is[...]()
  6024. * @param string $name
  6025. * @param array $arguments
  6026. * @return mixed
  6027. * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
  6028. */
  6029. public function __call($name, $arguments)
  6030. {
  6031. // make sure the name starts with 'is', otherwise
  6032. if (substr($name, 0, 2) !== 'is') {
  6033. throw new BadMethodCallException("No such method exists: $name");
  6034. }
  6035. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6036. $key = substr($name, 2);
  6037. return $this->matchUAAgainstKey($key);
  6038. }
  6039. /**
  6040. * Find a detection rule that matches the current User-agent.
  6041. *
  6042. * @param null $userAgent deprecated
  6043. * @return boolean
  6044. */
  6045. protected function matchDetectionRulesAgainstUA($userAgent = null)
  6046. {
  6047. // Begin general search.
  6048. foreach ($this->getRules() as $_regex) {
  6049. if (empty($_regex)) {
  6050. continue;
  6051. }
  6052. if ($this->match($_regex, $userAgent)) {
  6053. return true;
  6054. }
  6055. }
  6056. return false;
  6057. }
  6058. /**
  6059. * Search for a certain key in the rules array.
  6060. * If the key is found then try to match the corresponding
  6061. * regex against the User-Agent.
  6062. *
  6063. * @param string $key
  6064. *
  6065. * @return boolean
  6066. */
  6067. protected function matchUAAgainstKey($key)
  6068. {
  6069. // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
  6070. $key = strtolower($key);
  6071. if (false === isset($this->cache[$key])) {
  6072. // change the keys to lower case
  6073. $_rules = array_change_key_case($this->getRules());
  6074. if (false === empty($_rules[$key])) {
  6075. $this->cache[$key] = $this->match($_rules[$key]);
  6076. }
  6077. if (false === isset($this->cache[$key])) {
  6078. $this->cache[$key] = false;
  6079. }
  6080. }
  6081. return $this->cache[$key];
  6082. }
  6083. /**
  6084. * Check if the device is mobile.
  6085. * Returns true if any type of mobile device detected, including special ones
  6086. * @param null $userAgent deprecated
  6087. * @param null $httpHeaders deprecated
  6088. * @return bool
  6089. */
  6090. public function isMobile($userAgent = null, $httpHeaders = null)
  6091. {
  6092. if ($httpHeaders) {
  6093. $this->setHttpHeaders($httpHeaders);
  6094. }
  6095. if ($userAgent) {
  6096. $this->setUserAgent($userAgent);
  6097. }
  6098. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6099. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6100. $cfHeaders = $this->getCfHeaders();
  6101. if(array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') {
  6102. return true;
  6103. }
  6104. }
  6105. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6106. if ($this->checkHttpHeadersForMobile()) {
  6107. return true;
  6108. } else {
  6109. return $this->matchDetectionRulesAgainstUA();
  6110. }
  6111. }
  6112. /**
  6113. * Check if the device is a tablet.
  6114. * Return true if any type of tablet device is detected.
  6115. *
  6116. * @param string $userAgent deprecated
  6117. * @param array $httpHeaders deprecated
  6118. * @return bool
  6119. */
  6120. public function isTablet($userAgent = null, $httpHeaders = null)
  6121. {
  6122. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6123. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6124. $cfHeaders = $this->getCfHeaders();
  6125. if(array_key_exists('HTTP_CLOUDFRONT_IS_TABLET_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] === 'true') {
  6126. return true;
  6127. }
  6128. }
  6129. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6130. foreach (self::$tabletDevices as $_regex) {
  6131. if ($this->match($_regex, $userAgent)) {
  6132. return true;
  6133. }
  6134. }
  6135. return false;
  6136. }
  6137. /**
  6138. * This method checks for a certain property in the
  6139. * userAgent.
  6140. * @todo: The httpHeaders part is not yet used.
  6141. *
  6142. * @param string $key
  6143. * @param string $userAgent deprecated
  6144. * @param string $httpHeaders deprecated
  6145. * @return bool|int|null
  6146. */
  6147. public function is($key, $userAgent = null, $httpHeaders = null)
  6148. {
  6149. // Set the UA and HTTP headers only if needed (eg. batch mode).
  6150. if ($httpHeaders) {
  6151. $this->setHttpHeaders($httpHeaders);
  6152. }
  6153. if ($userAgent) {
  6154. $this->setUserAgent($userAgent);
  6155. }
  6156. $this->setDetectionType(self::DETECTION_TYPE_EXTENDED);
  6157. return $this->matchUAAgainstKey($key);
  6158. }
  6159. /**
  6160. * Some detection rules are relative (not standard),
  6161. * because of the diversity of devices, vendors and
  6162. * their conventions in representing the User-Agent or
  6163. * the HTTP headers.
  6164. *
  6165. * This method will be used to check custom regexes against
  6166. * the User-Agent string.
  6167. *
  6168. * @param $regex
  6169. * @param string $userAgent
  6170. * @return bool
  6171. *
  6172. * @todo: search in the HTTP headers too.
  6173. */
  6174. public function match($regex, $userAgent = null)
  6175. {
  6176. $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches);
  6177. // If positive match is found, store the results for debug.
  6178. if ($match) {
  6179. $this->matchingRegex = $regex;
  6180. $this->matchesArray = $matches;
  6181. }
  6182. return $match;
  6183. }
  6184. /**
  6185. * Get the properties array.
  6186. *
  6187. * @return array
  6188. */
  6189. public static function getProperties()
  6190. {
  6191. return self::$properties;
  6192. }
  6193. /**
  6194. * Prepare the version number.
  6195. *
  6196. * @todo Remove the error supression from str_replace() call.
  6197. *
  6198. * @param string $ver The string version, like "2.6.21.2152";
  6199. *
  6200. * @return float
  6201. */
  6202. public function prepareVersionNo($ver)
  6203. {
  6204. $ver = str_replace(array('_', ' ', '/'), '.', $ver);
  6205. $arrVer = explode('.', $ver, 2);
  6206. if (isset($arrVer[1])) {
  6207. $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions.
  6208. }
  6209. return (float) implode('.', $arrVer);
  6210. }
  6211. /**
  6212. * Check the version of the given property in the User-Agent.
  6213. * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
  6214. *
  6215. * @param string $propertyName The name of the property. See self::getProperties() array
  6216. * keys for all possible properties.
  6217. * @param string $type Either self::VERSION_TYPE_STRING to get a string value or
  6218. * self::VERSION_TYPE_FLOAT indicating a float value. This parameter
  6219. * is optional and defaults to self::VERSION_TYPE_STRING. Passing an
  6220. * invalid parameter will default to the this type as well.
  6221. *
  6222. * @return string|float The version of the property we are trying to extract.
  6223. */
  6224. public function version($propertyName, $type = self::VERSION_TYPE_STRING)
  6225. {
  6226. if (empty($propertyName)) {
  6227. return false;
  6228. }
  6229. // set the $type to the default if we don't recognize the type
  6230. if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
  6231. $type = self::VERSION_TYPE_STRING;
  6232. }
  6233. $properties = self::getProperties();
  6234. // Check if the property exists in the properties array.
  6235. if (true === isset($properties[$propertyName])) {
  6236. // Prepare the pattern to be matched.
  6237. // Make sure we always deal with an array (string is converted).
  6238. $properties[$propertyName] = (array) $properties[$propertyName];
  6239. foreach ($properties[$propertyName] as $propertyMatchString) {
  6240. $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
  6241. // Identify and extract the version.
  6242. preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);
  6243. if (false === empty($match[1])) {
  6244. $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);
  6245. return $version;
  6246. }
  6247. }
  6248. }
  6249. return false;
  6250. }
  6251. /**
  6252. * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
  6253. *
  6254. * @return string One of the self::MOBILE_GRADE_* constants.
  6255. */
  6256. public function mobileGrade()
  6257. {
  6258. $isMobile = $this->isMobile();
  6259. if (
  6260. // 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)
  6261. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6262. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6263. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6264. // 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)
  6265. // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
  6266. // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
  6267. // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
  6268. ( $this->version('Android', self::VERSION_TYPE_FLOAT)>2.1 && $this->is('Webkit') ) ||
  6269. // 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)
  6270. $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 ||
  6271. // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry® Torch 9810 (7), BlackBerry Z10 (10)
  6272. $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 ||
  6273. // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
  6274. $this->match('Playbook.*Tablet') ||
  6275. // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0)
  6276. ( $this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi') ) ||
  6277. // Palm WebOS 3.0 - Tested on HP TouchPad
  6278. $this->match('hp.*TouchPad') ||
  6279. // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices
  6280. ( $this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18 ) ||
  6281. // Chrome for Android - Tested on Android 4.0, 4.1 device
  6282. ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0 ) ||
  6283. // Skyfire 4.1 - Tested on Android 2.3 device
  6284. ( $this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6285. // Opera Mobile 11.5-12: Tested on Android 2.3
  6286. ( $this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS') ) ||
  6287. // Meego 1.2 - Tested on Nokia 950 and N9
  6288. $this->is('MeeGoOS') ||
  6289. // Tizen (pre-release) - Tested on early hardware
  6290. $this->is('Tizen') ||
  6291. // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
  6292. // @todo: more tests here!
  6293. $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 ||
  6294. // UC Browser - Tested on Android 2.3 device
  6295. ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6296. // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
  6297. ( $this->match('Kindle Fire') ||
  6298. $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0 ) ||
  6299. // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
  6300. $this->is('AndroidOS') && $this->is('NookTablet') ||
  6301. // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7
  6302. $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && !$isMobile ||
  6303. // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7
  6304. $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && !$isMobile ||
  6305. // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7
  6306. $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && !$isMobile ||
  6307. // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
  6308. $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && !$isMobile ||
  6309. // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
  6310. $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && !$isMobile
  6311. ){
  6312. return self::MOBILE_GRADE_A;
  6313. }
  6314. if (
  6315. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT)<4.3 ||
  6316. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT)<4.3 ||
  6317. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT)<4.3 ||
  6318. // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
  6319. $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT)<6 ||
  6320. //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
  6321. ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 &&
  6322. ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS')) ) ||
  6323. // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
  6324. $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
  6325. // @todo: report this (tested on Nokia N71)
  6326. $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS')
  6327. ){
  6328. return self::MOBILE_GRADE_B;
  6329. }
  6330. if (
  6331. // Blackberry 4.x - Tested on the Curve 8330
  6332. $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 ||
  6333. // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
  6334. $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 ||
  6335. // Tested on original iPhone (3.1), iPhone 3 (3.2)
  6336. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6337. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6338. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6339. // Internet Explorer 7 and older - Tested on Windows XP
  6340. $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && !$isMobile
  6341. ){
  6342. return self::MOBILE_GRADE_C;
  6343. }
  6344. // All older smartphone platforms and featurephones - Any device that doesn't support media queries
  6345. // will receive the basic, C grade experience.
  6346. return self::MOBILE_GRADE_C;
  6347. }
  6348. }
  6349. $mobileDetect = new Mobile_Detect;
  6350. $userDevice = ($mobileDetect->isMobile() ? ($mobileDetect->isTablet() ? 'tablet' : 'phone') : 'computer');
  6351. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  6352. $path = getServerPath();
  6353. return '
  6354. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6355. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  6356. <head>
  6357. <!--[if gte mso 9]><xml>
  6358. <o:OfficeDocumentSettings>
  6359. <o:AllowPNG/>
  6360. <o:PixelsPerInch>96</o:PixelsPerInch>
  6361. </o:OfficeDocumentSettings>
  6362. </xml><![endif]-->
  6363. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6364. <meta name="viewport" content="width=device-width">
  6365. <!--[if !mso]><!-->
  6366. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6367. <!--<![endif]-->
  6368. <title></title>
  6369. <!--[if !mso]><!-- -->
  6370. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  6371. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  6372. <!--<![endif]-->
  6373. <style type="text/css" id="media-query">
  6374. body {
  6375. margin: 0;
  6376. padding: 0;
  6377. }
  6378. table,
  6379. tr,
  6380. td {
  6381. vertical-align: top;
  6382. border-collapse: collapse;
  6383. }
  6384. .ie-browser table,
  6385. .mso-container table {
  6386. table-layout: fixed;
  6387. }
  6388. * {
  6389. line-height: inherit;
  6390. }
  6391. a[x-apple-data-detectors=true] {
  6392. color: inherit !important;
  6393. text-decoration: none !important;
  6394. }
  6395. [owa] .img-container div,
  6396. [owa] .img-container button {
  6397. display: block !important;
  6398. }
  6399. [owa] .fullwidth button {
  6400. width: 100% !important;
  6401. }
  6402. [owa] .block-grid .col {
  6403. display: table-cell;
  6404. float: none !important;
  6405. vertical-align: top;
  6406. }
  6407. .ie-browser .num12,
  6408. .ie-browser .block-grid,
  6409. [owa] .num12,
  6410. [owa] .block-grid {
  6411. width: 615px !important;
  6412. }
  6413. .ExternalClass,
  6414. .ExternalClass p,
  6415. .ExternalClass span,
  6416. .ExternalClass font,
  6417. .ExternalClass td,
  6418. .ExternalClass div {
  6419. line-height: 100%;
  6420. }
  6421. .ie-browser .mixed-two-up .num4,
  6422. [owa] .mixed-two-up .num4 {
  6423. width: 204px !important;
  6424. }
  6425. .ie-browser .mixed-two-up .num8,
  6426. [owa] .mixed-two-up .num8 {
  6427. width: 408px !important;
  6428. }
  6429. .ie-browser .block-grid.two-up .col,
  6430. [owa] .block-grid.two-up .col {
  6431. width: 307px !important;
  6432. }
  6433. .ie-browser .block-grid.three-up .col,
  6434. [owa] .block-grid.three-up .col {
  6435. width: 205px !important;
  6436. }
  6437. .ie-browser .block-grid.four-up .col,
  6438. [owa] .block-grid.four-up .col {
  6439. width: 153px !important;
  6440. }
  6441. .ie-browser .block-grid.five-up .col,
  6442. [owa] .block-grid.five-up .col {
  6443. width: 123px !important;
  6444. }
  6445. .ie-browser .block-grid.six-up .col,
  6446. [owa] .block-grid.six-up .col {
  6447. width: 102px !important;
  6448. }
  6449. .ie-browser .block-grid.seven-up .col,
  6450. [owa] .block-grid.seven-up .col {
  6451. width: 87px !important;
  6452. }
  6453. .ie-browser .block-grid.eight-up .col,
  6454. [owa] .block-grid.eight-up .col {
  6455. width: 76px !important;
  6456. }
  6457. .ie-browser .block-grid.nine-up .col,
  6458. [owa] .block-grid.nine-up .col {
  6459. width: 68px !important;
  6460. }
  6461. .ie-browser .block-grid.ten-up .col,
  6462. [owa] .block-grid.ten-up .col {
  6463. width: 61px !important;
  6464. }
  6465. .ie-browser .block-grid.eleven-up .col,
  6466. [owa] .block-grid.eleven-up .col {
  6467. width: 55px !important;
  6468. }
  6469. .ie-browser .block-grid.twelve-up .col,
  6470. [owa] .block-grid.twelve-up .col {
  6471. width: 51px !important;
  6472. }
  6473. @media only screen and (min-width: 635px) {
  6474. .block-grid {
  6475. width: 615px !important;
  6476. }
  6477. .block-grid .col {
  6478. display: table-cell;
  6479. Float: none !important;
  6480. vertical-align: top;
  6481. }
  6482. .block-grid .col.num12 {
  6483. width: 615px !important;
  6484. }
  6485. .block-grid.mixed-two-up .col.num4 {
  6486. width: 204px !important;
  6487. }
  6488. .block-grid.mixed-two-up .col.num8 {
  6489. width: 408px !important;
  6490. }
  6491. .block-grid.two-up .col {
  6492. width: 307px !important;
  6493. }
  6494. .block-grid.three-up .col {
  6495. width: 205px !important;
  6496. }
  6497. .block-grid.four-up .col {
  6498. width: 153px !important;
  6499. }
  6500. .block-grid.five-up .col {
  6501. width: 123px !important;
  6502. }
  6503. .block-grid.six-up .col {
  6504. width: 102px !important;
  6505. }
  6506. .block-grid.seven-up .col {
  6507. width: 87px !important;
  6508. }
  6509. .block-grid.eight-up .col {
  6510. width: 76px !important;
  6511. }
  6512. .block-grid.nine-up .col {
  6513. width: 68px !important;
  6514. }
  6515. .block-grid.ten-up .col {
  6516. width: 61px !important;
  6517. }
  6518. .block-grid.eleven-up .col {
  6519. width: 55px !important;
  6520. }
  6521. .block-grid.twelve-up .col {
  6522. width: 51px !important;
  6523. }
  6524. }
  6525. @media (max-width: 635px) {
  6526. .block-grid,
  6527. .col {
  6528. min-width: 320px !important;
  6529. max-width: 100% !important;
  6530. }
  6531. .block-grid {
  6532. width: calc(100% - 40px) !important;
  6533. }
  6534. .col {
  6535. width: 100% !important;
  6536. }
  6537. .col>div {
  6538. margin: 0 auto;
  6539. }
  6540. img.fullwidth {
  6541. max-width: 100% !important;
  6542. }
  6543. }
  6544. </style>
  6545. </head>
  6546. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  6547. <!--[if IE]><div class="ie-browser"><![endif]-->
  6548. <!--[if mso]><div class="mso-container"><![endif]-->
  6549. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  6550. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  6551. <div style="background-color:#333333;">
  6552. <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;"
  6553. class="block-grid ">
  6554. <div style="border-collapse: collapse;display: table;width: 100%;">
  6555. <!--[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]-->
  6556. <!--[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]-->
  6557. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6558. <div style="background-color: transparent; width: 100% !important;">
  6559. <!--[if (!mso)&(!IE)]><!-->
  6560. <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;">
  6561. <!--<![endif]-->
  6562. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  6563. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  6564. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  6565. 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"
  6566. width="555">
  6567. <!--[if mso]></td></tr></table><![endif]-->
  6568. </div>
  6569. <!--[if (!mso)&(!IE)]><!-->
  6570. </div>
  6571. <!--<![endif]-->
  6572. </div>
  6573. </div>
  6574. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6575. </div>
  6576. </div>
  6577. </div>
  6578. <div style="background-color:#333333;">
  6579. <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;"
  6580. class="block-grid ">
  6581. <div style="border-collapse: collapse;display: table;width: 100%;">
  6582. <!--[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]-->
  6583. <!--[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]-->
  6584. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6585. <div style="background-color: transparent; width: 100% !important;">
  6586. <!--[if (!mso)&(!IE)]><!-->
  6587. <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;">
  6588. <!--<![endif]-->
  6589. <!--[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]-->
  6590. <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;">
  6591. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6592. <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>
  6593. </span>
  6594. </p>
  6595. </div>
  6596. </div>
  6597. <!--[if mso]></td></tr></table><![endif]-->
  6598. <!--[if (!mso)&(!IE)]><!-->
  6599. </div>
  6600. <!--<![endif]-->
  6601. </div>
  6602. </div>
  6603. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6604. </div>
  6605. </div>
  6606. </div>
  6607. <div style="background-color:#393939;">
  6608. <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;"
  6609. class="block-grid ">
  6610. <div style="border-collapse: collapse;display: table;width: 100%;">
  6611. <!--[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]-->
  6612. <!--[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]-->
  6613. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6614. <div style="background-color: transparent; width: 100% !important;">
  6615. <!--[if (!mso)&(!IE)]><!-->
  6616. <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;">
  6617. <!--<![endif]-->
  6618. <!--[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]-->
  6619. <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;">
  6620. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6621. <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>
  6622. </div>
  6623. </div>
  6624. <!--[if mso]></td></tr></table><![endif]-->
  6625. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  6626. <!--[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]-->
  6627. <div align="center">
  6628. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  6629. </div>
  6630. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6631. </div>
  6632. <!--[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]-->
  6633. <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;">
  6634. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6635. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  6636. </div>
  6637. </div>
  6638. <!--[if mso]></td></tr></table><![endif]-->
  6639. <!--[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]-->
  6640. <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;">
  6641. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  6642. <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>
  6643. </span>
  6644. </p>
  6645. </div>
  6646. </div>
  6647. <!--[if mso]></td></tr></table><![endif]-->
  6648. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  6649. <!--[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]-->
  6650. <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">
  6651. <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>
  6652. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6653. </div>
  6654. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6655. </div>
  6656. <!--[if (!mso)&(!IE)]><!-->
  6657. </div>
  6658. <!--<![endif]-->
  6659. </div>
  6660. </div>
  6661. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6662. </div>
  6663. </div>
  6664. </div>
  6665. <div style="background-color:#ffffff;">
  6666. <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;"
  6667. class="block-grid ">
  6668. <div style="border-collapse: collapse;display: table;width: 100%;">
  6669. <!--[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]-->
  6670. <!--[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]-->
  6671. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6672. <div style="background-color: transparent; width: 100% !important;">
  6673. <!--[if (!mso)&(!IE)]><!-->
  6674. <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;">
  6675. <!--<![endif]-->
  6676. <!--[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]-->
  6677. <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;">
  6678. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6679. <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>
  6680. </div>
  6681. </div>
  6682. <!--[if mso]></td></tr></table><![endif]-->
  6683. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  6684. <!--[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]-->
  6685. <div align="center">
  6686. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  6687. </div>
  6688. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6689. </div>
  6690. <!--[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]-->
  6691. <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;">
  6692. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6693. <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>
  6694. </div>
  6695. </div>
  6696. <!--[if mso]></td></tr></table><![endif]-->
  6697. <!--[if (!mso)&(!IE)]><!-->
  6698. </div>
  6699. <!--<![endif]-->
  6700. </div>
  6701. </div>
  6702. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6703. </div>
  6704. </div>
  6705. </div>
  6706. <div style="background-color:#333333;">
  6707. <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;"
  6708. class="block-grid ">
  6709. <div style="border-collapse: collapse;display: table;width: 100%;">
  6710. <!--[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]-->
  6711. <!--[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]-->
  6712. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6713. <div style="background-color: transparent; width: 100% !important;">
  6714. <!--[if (!mso)&(!IE)]><!-->
  6715. <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;">
  6716. <!--<![endif]-->
  6717. <!--[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]-->
  6718. <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;">
  6719. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6720. <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"
  6721. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  6722. </div>
  6723. </div>
  6724. <!--[if mso]></td></tr></table><![endif]-->
  6725. <!--[if (!mso)&(!IE)]><!-->
  6726. </div>
  6727. <!--<![endif]-->
  6728. </div>
  6729. </div>
  6730. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6731. </div>
  6732. </div>
  6733. </div>
  6734. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  6735. </div>
  6736. <!--[if (mso)|(IE)]></div><![endif]-->
  6737. </body>
  6738. </html>
  6739. ';
  6740. }
  6741. function mimeTypes(){
  6742. return array(
  6743. '123' => 'application/vnd.lotus-1-2-3',
  6744. '3dml' => 'text/vnd.in3d.3dml',
  6745. '3ds' => 'image/x-3ds',
  6746. '3g2' => 'video/3gpp2',
  6747. '3gp' => 'video/3gpp',
  6748. '7z' => 'application/x-7z-compressed',
  6749. 'aab' => 'application/x-authorware-bin',
  6750. 'aac' => 'audio/x-aac',
  6751. 'aam' => 'application/x-authorware-map',
  6752. 'aas' => 'application/x-authorware-seg',
  6753. 'abw' => 'application/x-abiword',
  6754. 'ac' => 'application/pkix-attr-cert',
  6755. 'acc' => 'application/vnd.americandynamics.acc',
  6756. 'ace' => 'application/x-ace-compressed',
  6757. 'acu' => 'application/vnd.acucobol',
  6758. 'acutc' => 'application/vnd.acucorp',
  6759. 'adp' => 'audio/adpcm',
  6760. 'aep' => 'application/vnd.audiograph',
  6761. 'afm' => 'application/x-font-type1',
  6762. 'afp' => 'application/vnd.ibm.modcap',
  6763. 'ahead' => 'application/vnd.ahead.space',
  6764. 'ai' => 'application/postscript',
  6765. 'aif' => 'audio/x-aiff',
  6766. 'aifc' => 'audio/x-aiff',
  6767. 'aiff' => 'audio/x-aiff',
  6768. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  6769. 'ait' => 'application/vnd.dvb.ait',
  6770. 'ami' => 'application/vnd.amiga.ami',
  6771. 'apk' => 'application/vnd.android.package-archive',
  6772. 'appcache' => 'text/cache-manifest',
  6773. 'application' => 'application/x-ms-application',
  6774. 'apr' => 'application/vnd.lotus-approach',
  6775. 'arc' => 'application/x-freearc',
  6776. 'asc' => 'application/pgp-signature',
  6777. 'asf' => 'video/x-ms-asf',
  6778. 'asm' => 'text/x-asm',
  6779. 'aso' => 'application/vnd.accpac.simply.aso',
  6780. 'asx' => 'video/x-ms-asf',
  6781. 'atc' => 'application/vnd.acucorp',
  6782. 'atom' => 'application/atom+xml',
  6783. 'atomcat' => 'application/atomcat+xml',
  6784. 'atomsvc' => 'application/atomsvc+xml',
  6785. 'atx' => 'application/vnd.antix.game-component',
  6786. 'au' => 'audio/basic',
  6787. 'avi' => 'video/x-msvideo',
  6788. 'aw' => 'application/applixware',
  6789. 'azf' => 'application/vnd.airzip.filesecure.azf',
  6790. 'azs' => 'application/vnd.airzip.filesecure.azs',
  6791. 'azw' => 'application/vnd.amazon.ebook',
  6792. 'bat' => 'application/x-msdownload',
  6793. 'bcpio' => 'application/x-bcpio',
  6794. 'bdf' => 'application/x-font-bdf',
  6795. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  6796. 'bed' => 'application/vnd.realvnc.bed',
  6797. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  6798. 'bin' => 'application/octet-stream',
  6799. 'blb' => 'application/x-blorb',
  6800. 'blorb' => 'application/x-blorb',
  6801. 'bmi' => 'application/vnd.bmi',
  6802. 'bmp' => 'image/bmp',
  6803. 'book' => 'application/vnd.framemaker',
  6804. 'box' => 'application/vnd.previewsystems.box',
  6805. 'boz' => 'application/x-bzip2',
  6806. 'bpk' => 'application/octet-stream',
  6807. 'btif' => 'image/prs.btif',
  6808. 'bz' => 'application/x-bzip',
  6809. 'bz2' => 'application/x-bzip2',
  6810. 'c' => 'text/x-c',
  6811. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  6812. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  6813. 'c4d' => 'application/vnd.clonk.c4group',
  6814. 'c4f' => 'application/vnd.clonk.c4group',
  6815. 'c4g' => 'application/vnd.clonk.c4group',
  6816. 'c4p' => 'application/vnd.clonk.c4group',
  6817. 'c4u' => 'application/vnd.clonk.c4group',
  6818. 'cab' => 'application/vnd.ms-cab-compressed',
  6819. 'caf' => 'audio/x-caf',
  6820. 'cap' => 'application/vnd.tcpdump.pcap',
  6821. 'car' => 'application/vnd.curl.car',
  6822. 'cat' => 'application/vnd.ms-pki.seccat',
  6823. 'cb7' => 'application/x-cbr',
  6824. 'cba' => 'application/x-cbr',
  6825. 'cbr' => 'application/x-cbr',
  6826. 'cbt' => 'application/x-cbr',
  6827. 'cbz' => 'application/x-cbr',
  6828. 'cc' => 'text/x-c',
  6829. 'cct' => 'application/x-director',
  6830. 'ccxml' => 'application/ccxml+xml',
  6831. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  6832. 'cdf' => 'application/x-netcdf',
  6833. 'cdkey' => 'application/vnd.mediastation.cdkey',
  6834. 'cdmia' => 'application/cdmi-capability',
  6835. 'cdmic' => 'application/cdmi-container',
  6836. 'cdmid' => 'application/cdmi-domain',
  6837. 'cdmio' => 'application/cdmi-object',
  6838. 'cdmiq' => 'application/cdmi-queue',
  6839. 'cdx' => 'chemical/x-cdx',
  6840. 'cdxml' => 'application/vnd.chemdraw+xml',
  6841. 'cdy' => 'application/vnd.cinderella',
  6842. 'cer' => 'application/pkix-cert',
  6843. 'cfs' => 'application/x-cfs-compressed',
  6844. 'cgm' => 'image/cgm',
  6845. 'chat' => 'application/x-chat',
  6846. 'chm' => 'application/vnd.ms-htmlhelp',
  6847. 'chrt' => 'application/vnd.kde.kchart',
  6848. 'cif' => 'chemical/x-cif',
  6849. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  6850. 'cil' => 'application/vnd.ms-artgalry',
  6851. 'cla' => 'application/vnd.claymore',
  6852. 'class' => 'application/java-vm',
  6853. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  6854. 'clkp' => 'application/vnd.crick.clicker.palette',
  6855. 'clkt' => 'application/vnd.crick.clicker.template',
  6856. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  6857. 'clkx' => 'application/vnd.crick.clicker',
  6858. 'clp' => 'application/x-msclip',
  6859. 'cmc' => 'application/vnd.cosmocaller',
  6860. 'cmdf' => 'chemical/x-cmdf',
  6861. 'cml' => 'chemical/x-cml',
  6862. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  6863. 'cmx' => 'image/x-cmx',
  6864. 'cod' => 'application/vnd.rim.cod',
  6865. 'com' => 'application/x-msdownload',
  6866. 'conf' => 'text/plain',
  6867. 'cpio' => 'application/x-cpio',
  6868. 'cpp' => 'text/x-c',
  6869. 'cpt' => 'application/mac-compactpro',
  6870. 'crd' => 'application/x-mscardfile',
  6871. 'crl' => 'application/pkix-crl',
  6872. 'crt' => 'application/x-x509-ca-cert',
  6873. 'cryptonote' => 'application/vnd.rig.cryptonote',
  6874. 'csh' => 'application/x-csh',
  6875. 'csml' => 'chemical/x-csml',
  6876. 'csp' => 'application/vnd.commonspace',
  6877. 'css' => 'text/css',
  6878. 'cst' => 'application/x-director',
  6879. 'csv' => 'text/csv',
  6880. 'cu' => 'application/cu-seeme',
  6881. 'curl' => 'text/vnd.curl',
  6882. 'cww' => 'application/prs.cww',
  6883. 'cxt' => 'application/x-director',
  6884. 'cxx' => 'text/x-c',
  6885. 'dae' => 'model/vnd.collada+xml',
  6886. 'daf' => 'application/vnd.mobius.daf',
  6887. 'dart' => 'application/vnd.dart',
  6888. 'dataless' => 'application/vnd.fdsn.seed',
  6889. 'davmount' => 'application/davmount+xml',
  6890. 'dbk' => 'application/docbook+xml',
  6891. 'dcr' => 'application/x-director',
  6892. 'dcurl' => 'text/vnd.curl.dcurl',
  6893. 'dd2' => 'application/vnd.oma.dd2+xml',
  6894. 'ddd' => 'application/vnd.fujixerox.ddd',
  6895. 'deb' => 'application/x-debian-package',
  6896. 'def' => 'text/plain',
  6897. 'deploy' => 'application/octet-stream',
  6898. 'der' => 'application/x-x509-ca-cert',
  6899. 'dfac' => 'application/vnd.dreamfactory',
  6900. 'dgc' => 'application/x-dgc-compressed',
  6901. 'dic' => 'text/x-c',
  6902. 'dir' => 'application/x-director',
  6903. 'dis' => 'application/vnd.mobius.dis',
  6904. 'dist' => 'application/octet-stream',
  6905. 'distz' => 'application/octet-stream',
  6906. 'djv' => 'image/vnd.djvu',
  6907. 'djvu' => 'image/vnd.djvu',
  6908. 'dll' => 'application/x-msdownload',
  6909. 'dmg' => 'application/x-apple-diskimage',
  6910. 'dmp' => 'application/vnd.tcpdump.pcap',
  6911. 'dms' => 'application/octet-stream',
  6912. 'dna' => 'application/vnd.dna',
  6913. 'doc' => 'application/msword',
  6914. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  6915. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  6916. 'dot' => 'application/msword',
  6917. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  6918. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  6919. 'dp' => 'application/vnd.osgi.dp',
  6920. 'dpg' => 'application/vnd.dpgraph',
  6921. 'dra' => 'audio/vnd.dra',
  6922. 'dsc' => 'text/prs.lines.tag',
  6923. 'dssc' => 'application/dssc+der',
  6924. 'dtb' => 'application/x-dtbook+xml',
  6925. 'dtd' => 'application/xml-dtd',
  6926. 'dts' => 'audio/vnd.dts',
  6927. 'dtshd' => 'audio/vnd.dts.hd',
  6928. 'dump' => 'application/octet-stream',
  6929. 'dvb' => 'video/vnd.dvb.file',
  6930. 'dvi' => 'application/x-dvi',
  6931. 'dwf' => 'model/vnd.dwf',
  6932. 'dwg' => 'image/vnd.dwg',
  6933. 'dxf' => 'image/vnd.dxf',
  6934. 'dxp' => 'application/vnd.spotfire.dxp',
  6935. 'dxr' => 'application/x-director',
  6936. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  6937. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  6938. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  6939. 'ecma' => 'application/ecmascript',
  6940. 'edm' => 'application/vnd.novadigm.edm',
  6941. 'edx' => 'application/vnd.novadigm.edx',
  6942. 'efif' => 'application/vnd.picsel',
  6943. 'ei6' => 'application/vnd.pg.osasli',
  6944. 'elc' => 'application/octet-stream',
  6945. 'emf' => 'application/x-msmetafile',
  6946. 'eml' => 'message/rfc822',
  6947. 'emma' => 'application/emma+xml',
  6948. 'emz' => 'application/x-msmetafile',
  6949. 'eol' => 'audio/vnd.digital-winds',
  6950. 'eot' => 'application/vnd.ms-fontobject',
  6951. 'eps' => 'application/postscript',
  6952. 'epub' => 'application/epub+zip',
  6953. 'es3' => 'application/vnd.eszigno3+xml',
  6954. 'esa' => 'application/vnd.osgi.subsystem',
  6955. 'esf' => 'application/vnd.epson.esf',
  6956. 'et3' => 'application/vnd.eszigno3+xml',
  6957. 'etx' => 'text/x-setext',
  6958. 'eva' => 'application/x-eva',
  6959. 'evy' => 'application/x-envoy',
  6960. 'exe' => 'application/x-msdownload',
  6961. 'exi' => 'application/exi',
  6962. 'ext' => 'application/vnd.novadigm.ext',
  6963. 'ez' => 'application/andrew-inset',
  6964. 'ez2' => 'application/vnd.ezpix-album',
  6965. 'ez3' => 'application/vnd.ezpix-package',
  6966. 'f' => 'text/x-fortran',
  6967. 'f4v' => 'video/x-f4v',
  6968. 'f77' => 'text/x-fortran',
  6969. 'f90' => 'text/x-fortran',
  6970. 'fbs' => 'image/vnd.fastbidsheet',
  6971. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  6972. 'fcs' => 'application/vnd.isac.fcs',
  6973. 'fdf' => 'application/vnd.fdf',
  6974. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  6975. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  6976. 'fgd' => 'application/x-director',
  6977. 'fh' => 'image/x-freehand',
  6978. 'fh4' => 'image/x-freehand',
  6979. 'fh5' => 'image/x-freehand',
  6980. 'fh7' => 'image/x-freehand',
  6981. 'fhc' => 'image/x-freehand',
  6982. 'fig' => 'application/x-xfig',
  6983. 'flac' => 'audio/x-flac',
  6984. 'fli' => 'video/x-fli',
  6985. 'flo' => 'application/vnd.micrografx.flo',
  6986. 'flv' => 'video/x-flv',
  6987. 'flw' => 'application/vnd.kde.kivio',
  6988. 'flx' => 'text/vnd.fmi.flexstor',
  6989. 'fly' => 'text/vnd.fly',
  6990. 'fm' => 'application/vnd.framemaker',
  6991. 'fnc' => 'application/vnd.frogans.fnc',
  6992. 'for' => 'text/x-fortran',
  6993. 'fpx' => 'image/vnd.fpx',
  6994. 'frame' => 'application/vnd.framemaker',
  6995. 'fsc' => 'application/vnd.fsc.weblaunch',
  6996. 'fst' => 'image/vnd.fst',
  6997. 'ftc' => 'application/vnd.fluxtime.clip',
  6998. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  6999. 'fvt' => 'video/vnd.fvt',
  7000. 'fxp' => 'application/vnd.adobe.fxp',
  7001. 'fxpl' => 'application/vnd.adobe.fxp',
  7002. 'fzs' => 'application/vnd.fuzzysheet',
  7003. 'g2w' => 'application/vnd.geoplan',
  7004. 'g3' => 'image/g3fax',
  7005. 'g3w' => 'application/vnd.geospace',
  7006. 'gac' => 'application/vnd.groove-account',
  7007. 'gam' => 'application/x-tads',
  7008. 'gbr' => 'application/rpki-ghostbusters',
  7009. 'gca' => 'application/x-gca-compressed',
  7010. 'gdl' => 'model/vnd.gdl',
  7011. 'geo' => 'application/vnd.dynageo',
  7012. 'gex' => 'application/vnd.geometry-explorer',
  7013. 'ggb' => 'application/vnd.geogebra.file',
  7014. 'ggt' => 'application/vnd.geogebra.tool',
  7015. 'ghf' => 'application/vnd.groove-help',
  7016. 'gif' => 'image/gif',
  7017. 'gim' => 'application/vnd.groove-identity-message',
  7018. 'gml' => 'application/gml+xml',
  7019. 'gmx' => 'application/vnd.gmx',
  7020. 'gnumeric' => 'application/x-gnumeric',
  7021. 'gph' => 'application/vnd.flographit',
  7022. 'gpx' => 'application/gpx+xml',
  7023. 'gqf' => 'application/vnd.grafeq',
  7024. 'gqs' => 'application/vnd.grafeq',
  7025. 'gram' => 'application/srgs',
  7026. 'gramps' => 'application/x-gramps-xml',
  7027. 'gre' => 'application/vnd.geometry-explorer',
  7028. 'grv' => 'application/vnd.groove-injector',
  7029. 'grxml' => 'application/srgs+xml',
  7030. 'gsf' => 'application/x-font-ghostscript',
  7031. 'gtar' => 'application/x-gtar',
  7032. 'gtm' => 'application/vnd.groove-tool-message',
  7033. 'gtw' => 'model/vnd.gtw',
  7034. 'gv' => 'text/vnd.graphviz',
  7035. 'gxf' => 'application/gxf',
  7036. 'gxt' => 'application/vnd.geonext',
  7037. 'h' => 'text/x-c',
  7038. 'h261' => 'video/h261',
  7039. 'h263' => 'video/h263',
  7040. 'h264' => 'video/h264',
  7041. 'hal' => 'application/vnd.hal+xml',
  7042. 'hbci' => 'application/vnd.hbci',
  7043. 'hdf' => 'application/x-hdf',
  7044. 'hh' => 'text/x-c',
  7045. 'hlp' => 'application/winhlp',
  7046. 'hpgl' => 'application/vnd.hp-hpgl',
  7047. 'hpid' => 'application/vnd.hp-hpid',
  7048. 'hps' => 'application/vnd.hp-hps',
  7049. 'hqx' => 'application/mac-binhex40',
  7050. 'htke' => 'application/vnd.kenameaapp',
  7051. 'htm' => 'text/html',
  7052. 'html' => 'text/html',
  7053. 'hvd' => 'application/vnd.yamaha.hv-dic',
  7054. 'hvp' => 'application/vnd.yamaha.hv-voice',
  7055. 'hvs' => 'application/vnd.yamaha.hv-script',
  7056. 'i2g' => 'application/vnd.intergeo',
  7057. 'icc' => 'application/vnd.iccprofile',
  7058. 'ice' => 'x-conference/x-cooltalk',
  7059. 'icm' => 'application/vnd.iccprofile',
  7060. 'ico' => 'image/x-icon',
  7061. 'ics' => 'text/calendar',
  7062. 'ief' => 'image/ief',
  7063. 'ifb' => 'text/calendar',
  7064. 'ifm' => 'application/vnd.shana.informed.formdata',
  7065. 'iges' => 'model/iges',
  7066. 'igl' => 'application/vnd.igloader',
  7067. 'igm' => 'application/vnd.insors.igm',
  7068. 'igs' => 'model/iges',
  7069. 'igx' => 'application/vnd.micrografx.igx',
  7070. 'iif' => 'application/vnd.shana.informed.interchange',
  7071. 'imp' => 'application/vnd.accpac.simply.imp',
  7072. 'ims' => 'application/vnd.ms-ims',
  7073. 'in' => 'text/plain',
  7074. 'ink' => 'application/inkml+xml',
  7075. 'inkml' => 'application/inkml+xml',
  7076. 'install' => 'application/x-install-instructions',
  7077. 'iota' => 'application/vnd.astraea-software.iota',
  7078. 'ipfix' => 'application/ipfix',
  7079. 'ipk' => 'application/vnd.shana.informed.package',
  7080. 'irm' => 'application/vnd.ibm.rights-management',
  7081. 'irp' => 'application/vnd.irepository.package+xml',
  7082. 'iso' => 'application/x-iso9660-image',
  7083. 'itp' => 'application/vnd.shana.informed.formtemplate',
  7084. 'ivp' => 'application/vnd.immervision-ivp',
  7085. 'ivu' => 'application/vnd.immervision-ivu',
  7086. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  7087. 'jam' => 'application/vnd.jam',
  7088. 'jar' => 'application/java-archive',
  7089. 'java' => 'text/x-java-source',
  7090. 'jisp' => 'application/vnd.jisp',
  7091. 'jlt' => 'application/vnd.hp-jlyt',
  7092. 'jnlp' => 'application/x-java-jnlp-file',
  7093. 'joda' => 'application/vnd.joost.joda-archive',
  7094. 'jpe' => 'image/jpeg',
  7095. 'jpeg' => 'image/jpeg',
  7096. 'jpg' => 'image/jpeg',
  7097. 'jpgm' => 'video/jpm',
  7098. 'jpgv' => 'video/jpeg',
  7099. 'jpm' => 'video/jpm',
  7100. 'js' => 'application/javascript',
  7101. 'json' => 'application/json',
  7102. 'jsonml' => 'application/jsonml+json',
  7103. 'kar' => 'audio/midi',
  7104. 'karbon' => 'application/vnd.kde.karbon',
  7105. 'kfo' => 'application/vnd.kde.kformula',
  7106. 'kia' => 'application/vnd.kidspiration',
  7107. 'kml' => 'application/vnd.google-earth.kml+xml',
  7108. 'kmz' => 'application/vnd.google-earth.kmz',
  7109. 'kne' => 'application/vnd.kinar',
  7110. 'knp' => 'application/vnd.kinar',
  7111. 'kon' => 'application/vnd.kde.kontour',
  7112. 'kpr' => 'application/vnd.kde.kpresenter',
  7113. 'kpt' => 'application/vnd.kde.kpresenter',
  7114. 'kpxx' => 'application/vnd.ds-keypoint',
  7115. 'ksp' => 'application/vnd.kde.kspread',
  7116. 'ktr' => 'application/vnd.kahootz',
  7117. 'ktx' => 'image/ktx',
  7118. 'ktz' => 'application/vnd.kahootz',
  7119. 'kwd' => 'application/vnd.kde.kword',
  7120. 'kwt' => 'application/vnd.kde.kword',
  7121. 'lasxml' => 'application/vnd.las.las+xml',
  7122. 'latex' => 'application/x-latex',
  7123. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  7124. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  7125. 'les' => 'application/vnd.hhe.lesson-player',
  7126. 'lha' => 'application/x-lzh-compressed',
  7127. 'link66' => 'application/vnd.route66.link66+xml',
  7128. 'list' => 'text/plain',
  7129. 'list3820' => 'application/vnd.ibm.modcap',
  7130. 'listafp' => 'application/vnd.ibm.modcap',
  7131. 'lnk' => 'application/x-ms-shortcut',
  7132. 'log' => 'text/plain',
  7133. 'lostxml' => 'application/lost+xml',
  7134. 'lrf' => 'application/octet-stream',
  7135. 'lrm' => 'application/vnd.ms-lrm',
  7136. 'ltf' => 'application/vnd.frogans.ltf',
  7137. 'lvp' => 'audio/vnd.lucent.voice',
  7138. 'lwp' => 'application/vnd.lotus-wordpro',
  7139. 'lzh' => 'application/x-lzh-compressed',
  7140. 'm13' => 'application/x-msmediaview',
  7141. 'm14' => 'application/x-msmediaview',
  7142. 'm1v' => 'video/mpeg',
  7143. 'm21' => 'application/mp21',
  7144. 'm2a' => 'audio/mpeg',
  7145. 'm2v' => 'video/mpeg',
  7146. 'm3a' => 'audio/mpeg',
  7147. 'm3u' => 'audio/x-mpegurl',
  7148. 'm3u8' => 'application/vnd.apple.mpegurl',
  7149. 'm4a' => 'audio/mp4',
  7150. 'm4u' => 'video/vnd.mpegurl',
  7151. 'm4v' => 'video/x-m4v',
  7152. 'ma' => 'application/mathematica',
  7153. 'mads' => 'application/mads+xml',
  7154. 'mag' => 'application/vnd.ecowin.chart',
  7155. 'maker' => 'application/vnd.framemaker',
  7156. 'man' => 'text/troff',
  7157. 'mar' => 'application/octet-stream',
  7158. 'mathml' => 'application/mathml+xml',
  7159. 'mb' => 'application/mathematica',
  7160. 'mbk' => 'application/vnd.mobius.mbk',
  7161. 'mbox' => 'application/mbox',
  7162. 'mc1' => 'application/vnd.medcalcdata',
  7163. 'mcd' => 'application/vnd.mcd',
  7164. 'mcurl' => 'text/vnd.curl.mcurl',
  7165. 'mdb' => 'application/x-msaccess',
  7166. 'mdi' => 'image/vnd.ms-modi',
  7167. 'me' => 'text/troff',
  7168. 'mesh' => 'model/mesh',
  7169. 'meta4' => 'application/metalink4+xml',
  7170. 'metalink' => 'application/metalink+xml',
  7171. 'mets' => 'application/mets+xml',
  7172. 'mfm' => 'application/vnd.mfmp',
  7173. 'mft' => 'application/rpki-manifest',
  7174. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  7175. 'mgz' => 'application/vnd.proteus.magazine',
  7176. 'mid' => 'audio/midi',
  7177. 'midi' => 'audio/midi',
  7178. 'mie' => 'application/x-mie',
  7179. 'mif' => 'application/vnd.mif',
  7180. 'mime' => 'message/rfc822',
  7181. 'mj2' => 'video/mj2',
  7182. 'mjp2' => 'video/mj2',
  7183. 'mk3d' => 'video/x-matroska',
  7184. 'mka' => 'audio/x-matroska',
  7185. 'mks' => 'video/x-matroska',
  7186. 'mkv' => 'video/x-matroska',
  7187. 'mlp' => 'application/vnd.dolby.mlp',
  7188. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  7189. 'mmf' => 'application/vnd.smaf',
  7190. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  7191. 'mng' => 'video/x-mng',
  7192. 'mny' => 'application/x-msmoney',
  7193. 'mobi' => 'application/x-mobipocket-ebook',
  7194. 'mods' => 'application/mods+xml',
  7195. 'mov' => 'video/quicktime',
  7196. 'movie' => 'video/x-sgi-movie',
  7197. 'mp2' => 'audio/mpeg',
  7198. 'mp21' => 'application/mp21',
  7199. 'mp2a' => 'audio/mpeg',
  7200. 'mp3' => 'audio/mpeg',
  7201. 'mp4' => 'video/mp4',
  7202. 'mp4a' => 'audio/mp4',
  7203. 'mp4s' => 'application/mp4',
  7204. 'mp4v' => 'video/mp4',
  7205. 'mpc' => 'application/vnd.mophun.certificate',
  7206. 'mpe' => 'video/mpeg',
  7207. 'mpeg' => 'video/mpeg',
  7208. 'mpg' => 'video/mpeg',
  7209. 'mpg4' => 'video/mp4',
  7210. 'mpga' => 'audio/mpeg',
  7211. 'mpkg' => 'application/vnd.apple.installer+xml',
  7212. 'mpm' => 'application/vnd.blueice.multipass',
  7213. 'mpn' => 'application/vnd.mophun.application',
  7214. 'mpp' => 'application/vnd.ms-project',
  7215. 'mpt' => 'application/vnd.ms-project',
  7216. 'mpy' => 'application/vnd.ibm.minipay',
  7217. 'mqy' => 'application/vnd.mobius.mqy',
  7218. 'mrc' => 'application/marc',
  7219. 'mrcx' => 'application/marcxml+xml',
  7220. 'ms' => 'text/troff',
  7221. 'mscml' => 'application/mediaservercontrol+xml',
  7222. 'mseed' => 'application/vnd.fdsn.mseed',
  7223. 'mseq' => 'application/vnd.mseq',
  7224. 'msf' => 'application/vnd.epson.msf',
  7225. 'msh' => 'model/mesh',
  7226. 'msi' => 'application/x-msdownload',
  7227. 'msl' => 'application/vnd.mobius.msl',
  7228. 'msty' => 'application/vnd.muvee.style',
  7229. 'mts' => 'model/vnd.mts',
  7230. 'mus' => 'application/vnd.musician',
  7231. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  7232. 'mvb' => 'application/x-msmediaview',
  7233. 'mwf' => 'application/vnd.mfer',
  7234. 'mxf' => 'application/mxf',
  7235. 'mxl' => 'application/vnd.recordare.musicxml',
  7236. 'mxml' => 'application/xv+xml',
  7237. 'mxs' => 'application/vnd.triscape.mxs',
  7238. 'mxu' => 'video/vnd.mpegurl',
  7239. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  7240. 'n3' => 'text/n3',
  7241. 'nb' => 'application/mathematica',
  7242. 'nbp' => 'application/vnd.wolfram.player',
  7243. 'nc' => 'application/x-netcdf',
  7244. 'ncx' => 'application/x-dtbncx+xml',
  7245. 'nfo' => 'text/x-nfo',
  7246. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  7247. 'nitf' => 'application/vnd.nitf',
  7248. 'nlu' => 'application/vnd.neurolanguage.nlu',
  7249. 'nml' => 'application/vnd.enliven',
  7250. 'nnd' => 'application/vnd.noblenet-directory',
  7251. 'nns' => 'application/vnd.noblenet-sealer',
  7252. 'nnw' => 'application/vnd.noblenet-web',
  7253. 'npx' => 'image/vnd.net-fpx',
  7254. 'nsc' => 'application/x-conference',
  7255. 'nsf' => 'application/vnd.lotus-notes',
  7256. 'ntf' => 'application/vnd.nitf',
  7257. 'nzb' => 'application/x-nzb',
  7258. 'oa2' => 'application/vnd.fujitsu.oasys2',
  7259. 'oa3' => 'application/vnd.fujitsu.oasys3',
  7260. 'oas' => 'application/vnd.fujitsu.oasys',
  7261. 'obd' => 'application/x-msbinder',
  7262. 'obj' => 'application/x-tgif',
  7263. 'oda' => 'application/oda',
  7264. 'odb' => 'application/vnd.oasis.opendocument.database',
  7265. 'odc' => 'application/vnd.oasis.opendocument.chart',
  7266. 'odf' => 'application/vnd.oasis.opendocument.formula',
  7267. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  7268. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  7269. 'odi' => 'application/vnd.oasis.opendocument.image',
  7270. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  7271. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  7272. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  7273. 'odt' => 'application/vnd.oasis.opendocument.text',
  7274. 'oga' => 'audio/ogg',
  7275. 'ogg' => 'audio/ogg',
  7276. 'ogv' => 'video/ogg',
  7277. 'ogx' => 'application/ogg',
  7278. 'omdoc' => 'application/omdoc+xml',
  7279. 'onepkg' => 'application/onenote',
  7280. 'onetmp' => 'application/onenote',
  7281. 'onetoc' => 'application/onenote',
  7282. 'onetoc2' => 'application/onenote',
  7283. 'opf' => 'application/oebps-package+xml',
  7284. 'opml' => 'text/x-opml',
  7285. 'oprc' => 'application/vnd.palm',
  7286. 'org' => 'application/vnd.lotus-organizer',
  7287. 'osf' => 'application/vnd.yamaha.openscoreformat',
  7288. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  7289. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  7290. 'otf' => 'application/x-font-otf',
  7291. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  7292. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  7293. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  7294. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  7295. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  7296. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  7297. 'oxps' => 'application/oxps',
  7298. 'oxt' => 'application/vnd.openofficeorg.extension',
  7299. 'p' => 'text/x-pascal',
  7300. 'p10' => 'application/pkcs10',
  7301. 'p12' => 'application/x-pkcs12',
  7302. 'p7b' => 'application/x-pkcs7-certificates',
  7303. 'p7c' => 'application/pkcs7-mime',
  7304. 'p7m' => 'application/pkcs7-mime',
  7305. 'p7r' => 'application/x-pkcs7-certreqresp',
  7306. 'p7s' => 'application/pkcs7-signature',
  7307. 'p8' => 'application/pkcs8',
  7308. 'pas' => 'text/x-pascal',
  7309. 'paw' => 'application/vnd.pawaafile',
  7310. 'pbd' => 'application/vnd.powerbuilder6',
  7311. 'pbm' => 'image/x-portable-bitmap',
  7312. 'pcap' => 'application/vnd.tcpdump.pcap',
  7313. 'pcf' => 'application/x-font-pcf',
  7314. 'pcl' => 'application/vnd.hp-pcl',
  7315. 'pclxl' => 'application/vnd.hp-pclxl',
  7316. 'pct' => 'image/x-pict',
  7317. 'pcurl' => 'application/vnd.curl.pcurl',
  7318. 'pcx' => 'image/x-pcx',
  7319. 'pdb' => 'application/vnd.palm',
  7320. 'pdf' => 'application/pdf',
  7321. 'pfa' => 'application/x-font-type1',
  7322. 'pfb' => 'application/x-font-type1',
  7323. 'pfm' => 'application/x-font-type1',
  7324. 'pfr' => 'application/font-tdpfr',
  7325. 'pfx' => 'application/x-pkcs12',
  7326. 'pgm' => 'image/x-portable-graymap',
  7327. 'pgn' => 'application/x-chess-pgn',
  7328. 'pgp' => 'application/pgp-encrypted',
  7329. 'pic' => 'image/x-pict',
  7330. 'pkg' => 'application/octet-stream',
  7331. 'pki' => 'application/pkixcmp',
  7332. 'pkipath' => 'application/pkix-pkipath',
  7333. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  7334. 'plc' => 'application/vnd.mobius.plc',
  7335. 'plf' => 'application/vnd.pocketlearn',
  7336. 'pls' => 'application/pls+xml',
  7337. 'pml' => 'application/vnd.ctc-posml',
  7338. 'png' => 'image/png',
  7339. 'pnm' => 'image/x-portable-anymap',
  7340. 'portpkg' => 'application/vnd.macports.portpkg',
  7341. 'pot' => 'application/vnd.ms-powerpoint',
  7342. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  7343. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  7344. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  7345. 'ppd' => 'application/vnd.cups-ppd',
  7346. 'ppm' => 'image/x-portable-pixmap',
  7347. 'pps' => 'application/vnd.ms-powerpoint',
  7348. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  7349. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  7350. 'ppt' => 'application/vnd.ms-powerpoint',
  7351. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  7352. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  7353. 'pqa' => 'application/vnd.palm',
  7354. 'prc' => 'application/x-mobipocket-ebook',
  7355. 'pre' => 'application/vnd.lotus-freelance',
  7356. 'prf' => 'application/pics-rules',
  7357. 'ps' => 'application/postscript',
  7358. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  7359. 'psd' => 'image/vnd.adobe.photoshop',
  7360. 'psf' => 'application/x-font-linux-psf',
  7361. 'pskcxml' => 'application/pskc+xml',
  7362. 'ptid' => 'application/vnd.pvi.ptid1',
  7363. 'pub' => 'application/x-mspublisher',
  7364. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  7365. 'pwn' => 'application/vnd.3m.post-it-notes',
  7366. 'pya' => 'audio/vnd.ms-playready.media.pya',
  7367. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  7368. 'qam' => 'application/vnd.epson.quickanime',
  7369. 'qbo' => 'application/vnd.intu.qbo',
  7370. 'qfx' => 'application/vnd.intu.qfx',
  7371. 'qps' => 'application/vnd.publishare-delta-tree',
  7372. 'qt' => 'video/quicktime',
  7373. 'qwd' => 'application/vnd.quark.quarkxpress',
  7374. 'qwt' => 'application/vnd.quark.quarkxpress',
  7375. 'qxb' => 'application/vnd.quark.quarkxpress',
  7376. 'qxd' => 'application/vnd.quark.quarkxpress',
  7377. 'qxl' => 'application/vnd.quark.quarkxpress',
  7378. 'qxt' => 'application/vnd.quark.quarkxpress',
  7379. 'ra' => 'audio/x-pn-realaudio',
  7380. 'ram' => 'audio/x-pn-realaudio',
  7381. 'rar' => 'application/x-rar-compressed',
  7382. 'ras' => 'image/x-cmu-raster',
  7383. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  7384. 'rdf' => 'application/rdf+xml',
  7385. 'rdz' => 'application/vnd.data-vision.rdz',
  7386. 'rep' => 'application/vnd.businessobjects',
  7387. 'res' => 'application/x-dtbresource+xml',
  7388. 'rgb' => 'image/x-rgb',
  7389. 'rif' => 'application/reginfo+xml',
  7390. 'rip' => 'audio/vnd.rip',
  7391. 'ris' => 'application/x-research-info-systems',
  7392. 'rl' => 'application/resource-lists+xml',
  7393. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  7394. 'rld' => 'application/resource-lists-diff+xml',
  7395. 'rm' => 'application/vnd.rn-realmedia',
  7396. 'rmi' => 'audio/midi',
  7397. 'rmp' => 'audio/x-pn-realaudio-plugin',
  7398. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  7399. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  7400. 'rnc' => 'application/relax-ng-compact-syntax',
  7401. 'roa' => 'application/rpki-roa',
  7402. 'roff' => 'text/troff',
  7403. 'rp9' => 'application/vnd.cloanto.rp9',
  7404. 'rpss' => 'application/vnd.nokia.radio-presets',
  7405. 'rpst' => 'application/vnd.nokia.radio-preset',
  7406. 'rq' => 'application/sparql-query',
  7407. 'rs' => 'application/rls-services+xml',
  7408. 'rsd' => 'application/rsd+xml',
  7409. 'rss' => 'application/rss+xml',
  7410. 'rtf' => 'application/rtf',
  7411. 'rtx' => 'text/richtext',
  7412. 's' => 'text/x-asm',
  7413. 's3m' => 'audio/s3m',
  7414. 'saf' => 'application/vnd.yamaha.smaf-audio',
  7415. 'sbml' => 'application/sbml+xml',
  7416. 'sc' => 'application/vnd.ibm.secure-container',
  7417. 'scd' => 'application/x-msschedule',
  7418. 'scm' => 'application/vnd.lotus-screencam',
  7419. 'scq' => 'application/scvp-cv-request',
  7420. 'scs' => 'application/scvp-cv-response',
  7421. 'scurl' => 'text/vnd.curl.scurl',
  7422. 'sda' => 'application/vnd.stardivision.draw',
  7423. 'sdc' => 'application/vnd.stardivision.calc',
  7424. 'sdd' => 'application/vnd.stardivision.impress',
  7425. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  7426. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  7427. 'sdp' => 'application/sdp',
  7428. 'sdw' => 'application/vnd.stardivision.writer',
  7429. 'see' => 'application/vnd.seemail',
  7430. 'seed' => 'application/vnd.fdsn.seed',
  7431. 'sema' => 'application/vnd.sema',
  7432. 'semd' => 'application/vnd.semd',
  7433. 'semf' => 'application/vnd.semf',
  7434. 'ser' => 'application/java-serialized-object',
  7435. 'setpay' => 'application/set-payment-initiation',
  7436. 'setreg' => 'application/set-registration-initiation',
  7437. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  7438. 'sfs' => 'application/vnd.spotfire.sfs',
  7439. 'sfv' => 'text/x-sfv',
  7440. 'sgi' => 'image/sgi',
  7441. 'sgl' => 'application/vnd.stardivision.writer-global',
  7442. 'sgm' => 'text/sgml',
  7443. 'sgml' => 'text/sgml',
  7444. 'sh' => 'application/x-sh',
  7445. 'shar' => 'application/x-shar',
  7446. 'shf' => 'application/shf+xml',
  7447. 'sid' => 'image/x-mrsid-image',
  7448. 'sig' => 'application/pgp-signature',
  7449. 'sil' => 'audio/silk',
  7450. 'silo' => 'model/mesh',
  7451. 'sis' => 'application/vnd.symbian.install',
  7452. 'sisx' => 'application/vnd.symbian.install',
  7453. 'sit' => 'application/x-stuffit',
  7454. 'sitx' => 'application/x-stuffitx',
  7455. 'skd' => 'application/vnd.koan',
  7456. 'skm' => 'application/vnd.koan',
  7457. 'skp' => 'application/vnd.koan',
  7458. 'skt' => 'application/vnd.koan',
  7459. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  7460. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  7461. 'slt' => 'application/vnd.epson.salt',
  7462. 'sm' => 'application/vnd.stepmania.stepchart',
  7463. 'smf' => 'application/vnd.stardivision.math',
  7464. 'smi' => 'application/smil+xml',
  7465. 'smil' => 'application/smil+xml',
  7466. 'smv' => 'video/x-smv',
  7467. 'smzip' => 'application/vnd.stepmania.package',
  7468. 'snd' => 'audio/basic',
  7469. 'snf' => 'application/x-font-snf',
  7470. 'so' => 'application/octet-stream',
  7471. 'spc' => 'application/x-pkcs7-certificates',
  7472. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  7473. 'spl' => 'application/x-futuresplash',
  7474. 'spot' => 'text/vnd.in3d.spot',
  7475. 'spp' => 'application/scvp-vp-response',
  7476. 'spq' => 'application/scvp-vp-request',
  7477. 'spx' => 'audio/ogg',
  7478. 'sql' => 'application/x-sql',
  7479. 'src' => 'application/x-wais-source',
  7480. 'srt' => 'application/x-subrip',
  7481. 'sru' => 'application/sru+xml',
  7482. 'srx' => 'application/sparql-results+xml',
  7483. 'ssdl' => 'application/ssdl+xml',
  7484. 'sse' => 'application/vnd.kodak-descriptor',
  7485. 'ssf' => 'application/vnd.epson.ssf',
  7486. 'ssml' => 'application/ssml+xml',
  7487. 'st' => 'application/vnd.sailingtracker.track',
  7488. 'stc' => 'application/vnd.sun.xml.calc.template',
  7489. 'std' => 'application/vnd.sun.xml.draw.template',
  7490. 'stf' => 'application/vnd.wt.stf',
  7491. 'sti' => 'application/vnd.sun.xml.impress.template',
  7492. 'stk' => 'application/hyperstudio',
  7493. 'stl' => 'application/vnd.ms-pki.stl',
  7494. 'str' => 'application/vnd.pg.format',
  7495. 'stw' => 'application/vnd.sun.xml.writer.template',
  7496. 'sub' => 'image/vnd.dvb.subtitle',
  7497. 'sub' => 'text/vnd.dvb.subtitle',
  7498. 'sus' => 'application/vnd.sus-calendar',
  7499. 'susp' => 'application/vnd.sus-calendar',
  7500. 'sv4cpio' => 'application/x-sv4cpio',
  7501. 'sv4crc' => 'application/x-sv4crc',
  7502. 'svc' => 'application/vnd.dvb.service',
  7503. 'svd' => 'application/vnd.svd',
  7504. 'svg' => 'image/svg+xml',
  7505. 'svgz' => 'image/svg+xml',
  7506. 'swa' => 'application/x-director',
  7507. 'swf' => 'application/x-shockwave-flash',
  7508. 'swi' => 'application/vnd.aristanetworks.swi',
  7509. 'sxc' => 'application/vnd.sun.xml.calc',
  7510. 'sxd' => 'application/vnd.sun.xml.draw',
  7511. 'sxg' => 'application/vnd.sun.xml.writer.global',
  7512. 'sxi' => 'application/vnd.sun.xml.impress',
  7513. 'sxm' => 'application/vnd.sun.xml.math',
  7514. 'sxw' => 'application/vnd.sun.xml.writer',
  7515. 't' => 'text/troff',
  7516. 't3' => 'application/x-t3vm-image',
  7517. 'taglet' => 'application/vnd.mynfc',
  7518. 'tao' => 'application/vnd.tao.intent-module-archive',
  7519. 'tar' => 'application/x-tar',
  7520. 'tcap' => 'application/vnd.3gpp2.tcap',
  7521. 'tcl' => 'application/x-tcl',
  7522. 'teacher' => 'application/vnd.smart.teacher',
  7523. 'tei' => 'application/tei+xml',
  7524. 'teicorpus' => 'application/tei+xml',
  7525. 'tex' => 'application/x-tex',
  7526. 'texi' => 'application/x-texinfo',
  7527. 'texinfo' => 'application/x-texinfo',
  7528. 'text' => 'text/plain',
  7529. 'tfi' => 'application/thraud+xml',
  7530. 'tfm' => 'application/x-tex-tfm',
  7531. 'tga' => 'image/x-tga',
  7532. 'thmx' => 'application/vnd.ms-officetheme',
  7533. 'tif' => 'image/tiff',
  7534. 'tiff' => 'image/tiff',
  7535. 'tmo' => 'application/vnd.tmobile-livetv',
  7536. 'torrent' => 'application/x-bittorrent',
  7537. 'tpl' => 'application/vnd.groove-tool-template',
  7538. 'tpt' => 'application/vnd.trid.tpt',
  7539. 'tr' => 'text/troff',
  7540. 'tra' => 'application/vnd.trueapp',
  7541. 'trm' => 'application/x-msterminal',
  7542. 'tsd' => 'application/timestamped-data',
  7543. 'tsv' => 'text/tab-separated-values',
  7544. 'ttc' => 'application/x-font-ttf',
  7545. 'ttf' => 'application/x-font-ttf',
  7546. 'ttl' => 'text/turtle',
  7547. 'twd' => 'application/vnd.simtech-mindmapper',
  7548. 'twds' => 'application/vnd.simtech-mindmapper',
  7549. 'txd' => 'application/vnd.genomatix.tuxedo',
  7550. 'txf' => 'application/vnd.mobius.txf',
  7551. 'txt' => 'text/plain',
  7552. 'u32' => 'application/x-authorware-bin',
  7553. 'udeb' => 'application/x-debian-package',
  7554. 'ufd' => 'application/vnd.ufdl',
  7555. 'ufdl' => 'application/vnd.ufdl',
  7556. 'ulx' => 'application/x-glulx',
  7557. 'umj' => 'application/vnd.umajin',
  7558. 'unityweb' => 'application/vnd.unity',
  7559. 'uoml' => 'application/vnd.uoml+xml',
  7560. 'uri' => 'text/uri-list',
  7561. 'uris' => 'text/uri-list',
  7562. 'urls' => 'text/uri-list',
  7563. 'ustar' => 'application/x-ustar',
  7564. 'utz' => 'application/vnd.uiq.theme',
  7565. 'uu' => 'text/x-uuencode',
  7566. 'uva' => 'audio/vnd.dece.audio',
  7567. 'uvd' => 'application/vnd.dece.data',
  7568. 'uvf' => 'application/vnd.dece.data',
  7569. 'uvg' => 'image/vnd.dece.graphic',
  7570. 'uvh' => 'video/vnd.dece.hd',
  7571. 'uvi' => 'image/vnd.dece.graphic',
  7572. 'uvm' => 'video/vnd.dece.mobile',
  7573. 'uvp' => 'video/vnd.dece.pd',
  7574. 'uvs' => 'video/vnd.dece.sd',
  7575. 'uvt' => 'application/vnd.dece.ttml+xml',
  7576. 'uvu' => 'video/vnd.uvvu.mp4',
  7577. 'uvv' => 'video/vnd.dece.video',
  7578. 'uvva' => 'audio/vnd.dece.audio',
  7579. 'uvvd' => 'application/vnd.dece.data',
  7580. 'uvvf' => 'application/vnd.dece.data',
  7581. 'uvvg' => 'image/vnd.dece.graphic',
  7582. 'uvvh' => 'video/vnd.dece.hd',
  7583. 'uvvi' => 'image/vnd.dece.graphic',
  7584. 'uvvm' => 'video/vnd.dece.mobile',
  7585. 'uvvp' => 'video/vnd.dece.pd',
  7586. 'uvvs' => 'video/vnd.dece.sd',
  7587. 'uvvt' => 'application/vnd.dece.ttml+xml',
  7588. 'uvvu' => 'video/vnd.uvvu.mp4',
  7589. 'uvvv' => 'video/vnd.dece.video',
  7590. 'uvvx' => 'application/vnd.dece.unspecified',
  7591. 'uvvz' => 'application/vnd.dece.zip',
  7592. 'uvx' => 'application/vnd.dece.unspecified',
  7593. 'uvz' => 'application/vnd.dece.zip',
  7594. 'vcard' => 'text/vcard',
  7595. 'vcd' => 'application/x-cdlink',
  7596. 'vcf' => 'text/x-vcard',
  7597. 'vcg' => 'application/vnd.groove-vcard',
  7598. 'vcs' => 'text/x-vcalendar',
  7599. 'vcx' => 'application/vnd.vcx',
  7600. 'vis' => 'application/vnd.visionary',
  7601. 'viv' => 'video/vnd.vivo',
  7602. 'vob' => 'video/x-ms-vob',
  7603. 'vor' => 'application/vnd.stardivision.writer',
  7604. 'vox' => 'application/x-authorware-bin',
  7605. 'vrml' => 'model/vrml',
  7606. 'vsd' => 'application/vnd.visio',
  7607. 'vsf' => 'application/vnd.vsf',
  7608. 'vss' => 'application/vnd.visio',
  7609. 'vst' => 'application/vnd.visio',
  7610. 'vsw' => 'application/vnd.visio',
  7611. 'vtu' => 'model/vnd.vtu',
  7612. 'vxml' => 'application/voicexml+xml',
  7613. 'w3d' => 'application/x-director',
  7614. 'wad' => 'application/x-doom',
  7615. 'wav' => 'audio/x-wav',
  7616. 'wax' => 'audio/x-ms-wax',
  7617. 'wbmp' => 'image/vnd.wap.wbmp',
  7618. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  7619. 'wbxml' => 'application/vnd.wap.wbxml',
  7620. 'wcm' => 'application/vnd.ms-works',
  7621. 'wdb' => 'application/vnd.ms-works',
  7622. 'wdp' => 'image/vnd.ms-photo',
  7623. 'weba' => 'audio/webm',
  7624. 'webm' => 'video/webm',
  7625. 'webp' => 'image/webp',
  7626. 'wg' => 'application/vnd.pmi.widget',
  7627. 'wgt' => 'application/widget',
  7628. 'wks' => 'application/vnd.ms-works',
  7629. 'wm' => 'video/x-ms-wm',
  7630. 'wma' => 'audio/x-ms-wma',
  7631. 'wmd' => 'application/x-ms-wmd',
  7632. 'wmf' => 'application/x-msmetafile',
  7633. 'wml' => 'text/vnd.wap.wml',
  7634. 'wmlc' => 'application/vnd.wap.wmlc',
  7635. 'wmls' => 'text/vnd.wap.wmlscript',
  7636. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  7637. 'wmv' => 'video/x-ms-wmv',
  7638. 'wmx' => 'video/x-ms-wmx',
  7639. 'wmz' => 'application/x-ms-wmz',
  7640. 'wmz' => 'application/x-msmetafile',
  7641. 'woff' => 'application/font-woff',
  7642. 'wpd' => 'application/vnd.wordperfect',
  7643. 'wpl' => 'application/vnd.ms-wpl',
  7644. 'wps' => 'application/vnd.ms-works',
  7645. 'wqd' => 'application/vnd.wqd',
  7646. 'wri' => 'application/x-mswrite',
  7647. 'wrl' => 'model/vrml',
  7648. 'wsdl' => 'application/wsdl+xml',
  7649. 'wspolicy' => 'application/wspolicy+xml',
  7650. 'wtb' => 'application/vnd.webturbo',
  7651. 'wvx' => 'video/x-ms-wvx',
  7652. 'x32' => 'application/x-authorware-bin',
  7653. 'x3d' => 'model/x3d+xml',
  7654. 'x3db' => 'model/x3d+binary',
  7655. 'x3dbz' => 'model/x3d+binary',
  7656. 'x3dv' => 'model/x3d+vrml',
  7657. 'x3dvz' => 'model/x3d+vrml',
  7658. 'x3dz' => 'model/x3d+xml',
  7659. 'xaml' => 'application/xaml+xml',
  7660. 'xap' => 'application/x-silverlight-app',
  7661. 'xar' => 'application/vnd.xara',
  7662. 'xbap' => 'application/x-ms-xbap',
  7663. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  7664. 'xbm' => 'image/x-xbitmap',
  7665. 'xdf' => 'application/xcap-diff+xml',
  7666. 'xdm' => 'application/vnd.syncml.dm+xml',
  7667. 'xdp' => 'application/vnd.adobe.xdp+xml',
  7668. 'xdssc' => 'application/dssc+xml',
  7669. 'xdw' => 'application/vnd.fujixerox.docuworks',
  7670. 'xenc' => 'application/xenc+xml',
  7671. 'xer' => 'application/patch-ops-error+xml',
  7672. 'xfdf' => 'application/vnd.adobe.xfdf',
  7673. 'xfdl' => 'application/vnd.xfdl',
  7674. 'xht' => 'application/xhtml+xml',
  7675. 'xhtml' => 'application/xhtml+xml',
  7676. 'xhvml' => 'application/xv+xml',
  7677. 'xif' => 'image/vnd.xiff',
  7678. 'xla' => 'application/vnd.ms-excel',
  7679. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  7680. 'xlc' => 'application/vnd.ms-excel',
  7681. 'xlf' => 'application/x-xliff+xml',
  7682. 'xlm' => 'application/vnd.ms-excel',
  7683. 'xls' => 'application/vnd.ms-excel',
  7684. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  7685. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  7686. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  7687. 'xlt' => 'application/vnd.ms-excel',
  7688. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  7689. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  7690. 'xlw' => 'application/vnd.ms-excel',
  7691. 'xm' => 'audio/xm',
  7692. 'xml' => 'application/xml',
  7693. 'xo' => 'application/vnd.olpc-sugar',
  7694. 'xop' => 'application/xop+xml',
  7695. 'xpi' => 'application/x-xpinstall',
  7696. 'xpl' => 'application/xproc+xml',
  7697. 'xpm' => 'image/x-xpixmap',
  7698. 'xpr' => 'application/vnd.is-xpr',
  7699. 'xps' => 'application/vnd.ms-xpsdocument',
  7700. 'xpw' => 'application/vnd.intercon.formnet',
  7701. 'xpx' => 'application/vnd.intercon.formnet',
  7702. 'xsl' => 'application/xml',
  7703. 'xslt' => 'application/xslt+xml',
  7704. 'xsm' => 'application/vnd.syncml+xml',
  7705. 'xspf' => 'application/xspf+xml',
  7706. 'xul' => 'application/vnd.mozilla.xul+xml',
  7707. 'xvm' => 'application/xv+xml',
  7708. 'xvml' => 'application/xv+xml',
  7709. 'xwd' => 'image/x-xwindowdump',
  7710. 'xyz' => 'chemical/x-xyz',
  7711. 'xz' => 'application/x-xz',
  7712. 'yang' => 'application/yang',
  7713. 'yin' => 'application/yin+xml',
  7714. 'z1' => 'application/x-zmachine',
  7715. 'z2' => 'application/x-zmachine',
  7716. 'z3' => 'application/x-zmachine',
  7717. 'z4' => 'application/x-zmachine',
  7718. 'z5' => 'application/x-zmachine',
  7719. 'z6' => 'application/x-zmachine',
  7720. 'z7' => 'application/x-zmachine',
  7721. 'z8' => 'application/x-zmachine',
  7722. 'zaz' => 'application/vnd.zzazz.deck+xml',
  7723. 'zip' => 'application/zip',
  7724. 'zir' => 'application/vnd.zul',
  7725. 'zirz' => 'application/vnd.zul',
  7726. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  7727. );
  7728. }
  7729. // Always run this
  7730. if(strpos($_SERVER['SCRIPT_NAME'], 'check.php') == false){
  7731. dependCheck();
  7732. }