4
0

functions.php 347 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420
  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. //Cookie Function
  39. function coookie($type, $name, $value = '', $days = -1){
  40. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  41. $Secure = true;
  42. $HTTPOnly = true;
  43. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  44. $Secure = true;
  45. $HTTPOnly = true;
  46. } else {
  47. $Secure = false;
  48. $HTTPOnly = false;
  49. }
  50. $Path = '/';
  51. $Domain = $_SERVER['HTTP_HOST'];
  52. $Port = strpos($Domain, ':');
  53. if ($Port !== false) $Domain = substr($Domain, 0, $Port);
  54. $Port = strpos($Domain, ':');
  55. $check = substr_count($Domain, '.');
  56. if($check >= 3){
  57. if(is_numeric($Domain[0])){
  58. $Domain = '';
  59. }else{
  60. $Domain = '.'.explode('.',$Domain)[1].'.'.explode('.',$Domain)[2].'.'.explode('.',$Domain)[3];
  61. }
  62. }elseif($check == 2){
  63. $Domain = '.'.explode('.',$Domain)[1].'.'.explode('.',$Domain)[2];
  64. }elseif($check == 1){
  65. $Domain = '.' . $Domain;
  66. }else{
  67. $Domain = '';
  68. }
  69. if($type = 'set'){
  70. $_COOKIE[$name] = $value;
  71. header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)
  72. . (empty($days) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', time() + (86400 * $days)) . ' GMT')
  73. . (empty($Path) ? '' : '; path=' . $Path)
  74. . (empty($Domain) ? '' : '; domain=' . $Domain)
  75. . (!$Secure ? '' : '; secure')
  76. . (!$HTTPOnly ? '' : '; HttpOnly'), false);
  77. }elseif($type = 'delete'){
  78. unset($_COOKIE[$name]);
  79. header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)
  80. . (empty($days) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', time() - 3600) . ' GMT')
  81. . (empty($Path) ? '' : '; path=' . $Path)
  82. . (empty($Domain) ? '' : '; domain=' . $Domain)
  83. . (!$Secure ? '' : '; secure')
  84. . (!$HTTPOnly ? '' : '; HttpOnly'), false);
  85. }
  86. }
  87. // ==== Auth Plugins START ====
  88. if (function_exists('ldap_connect')) :
  89. // Pass credentials to LDAP backend
  90. function plugin_auth_ldap($username, $password) {
  91. $ldapServers = explode(',',AUTHBACKENDHOST);
  92. foreach($ldapServers as $key => $value) {
  93. // Calculate parts
  94. $digest = parse_url(trim($value));
  95. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  96. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  97. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  98. // Reassign
  99. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  100. }
  101. // returns true or false
  102. $ldap = ldap_connect(implode(' ',$ldapServers));
  103. if(empty(AUTHBACKENDDOMAINFORMAT)){
  104. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  105. writeLog("success", "LDAP authentication success");
  106. return true;
  107. } else {
  108. writeLog("error", "LDAP could not authenticate");
  109. return false;
  110. }
  111. }else{
  112. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  113. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  114. $bind = @ldap_bind($ldap, sprintf(AUTHBACKENDDOMAINFORMAT, $username), $password);
  115. if ($bind) {
  116. writeLog("success", "LDAP authentication success");
  117. return true;
  118. } else {
  119. writeLog("error", "LDPA could not authenticate");
  120. return false;
  121. }
  122. }
  123. writeLog("error", "LDAP could not authenticate");
  124. return false;
  125. }
  126. else :
  127. // Ldap Auth Missing Dependancy
  128. function plugin_auth_ldap_disabled() {
  129. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  130. }
  131. endif;
  132. // Pass credentials to FTP backend
  133. function plugin_auth_ftp($username, $password) {
  134. // Calculate parts
  135. $digest = parse_url(AUTHBACKENDHOST);
  136. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  137. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  138. $port = (isset($digest['port'])?$digest['port']:21);
  139. // Determine Connection Type
  140. if ($scheme == 'ftps') {
  141. $conn_id = ftp_ssl_connect($host, $port, 20);
  142. } elseif ($scheme == 'ftp') {
  143. $conn_id = ftp_connect($host, $port, 20);
  144. } else {
  145. debug_out('Invalid FTP scheme. Use ftp or ftps');
  146. writeLog("error", "invalid FTP scheme");
  147. return false;
  148. }
  149. // Check if valid FTP connection
  150. if ($conn_id) {
  151. // Attempt login
  152. @$login_result = ftp_login($conn_id, $username, $password);
  153. ftp_close($conn_id);
  154. // Return Result
  155. if ($login_result) {
  156. writeLog("success", "$username authenticated");
  157. return true;
  158. } else {
  159. writeLog("error", "$username could not authenticate");
  160. return false;
  161. }
  162. } else {
  163. return false;
  164. }
  165. return false;
  166. }
  167. // Pass credentials to Emby Backend
  168. function plugin_auth_emby_local($username, $password) {
  169. $embyAddress = qualifyURL(EMBYURL);
  170. $headers = array(
  171. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  172. 'Content-Type' => 'application/json',
  173. );
  174. $body = array(
  175. 'Username' => $username,
  176. 'Password' => sha1($password),
  177. 'PasswordMd5' => md5($password),
  178. );
  179. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  180. if (isset($response['content'])) {
  181. $json = json_decode($response['content'], true);
  182. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  183. // Login Success - Now Logout Emby Session As We No Longer Need It
  184. $headers = array(
  185. 'X-Mediabrowser-Token' => $json['AccessToken'],
  186. );
  187. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. if (function_exists('curl_version')) :
  194. // Authenticate Against Emby Local (first) and Emby Connect
  195. function plugin_auth_emby_all($username, $password) {
  196. $localResult = plugin_auth_emby_local($username, $password);
  197. if ($localResult) {
  198. return $localResult;
  199. } else {
  200. return plugin_auth_emby_connect($username, $password);
  201. }
  202. }
  203. // Authenicate against emby connect
  204. function plugin_auth_emby_connect($username, $password) {
  205. $embyAddress = qualifyURL(EMBYURL);
  206. // Get A User
  207. $connectId = '';
  208. $userIds = json_decode(@file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  209. if (is_array($userIds)) {
  210. foreach ($userIds as $key => $value) { // Scan for this user
  211. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  212. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  213. $connectId = $value['ConnectUserId'];
  214. break;
  215. }
  216. }
  217. }
  218. if ($connectId) {
  219. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  220. $headers = array(
  221. 'Accept'=> 'application/json',
  222. 'Content-Type' => 'application/x-www-form-urlencoded',
  223. );
  224. $body = array(
  225. 'nameOrEmail' => $username,
  226. 'rawpw' => $password,
  227. );
  228. $result = curl_post($connectURL, $body, $headers);
  229. if (isset($result['content'])) {
  230. $json = json_decode($result['content'], true);
  231. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  232. return array(
  233. 'email' => $json['User']['Email'],
  234. 'image' => $json['User']['ImageUrl'],
  235. );
  236. }
  237. }
  238. }
  239. }
  240. return false;
  241. }
  242. // Pass credentials to Plex Backend
  243. function plugin_auth_plex($username, $password) {
  244. // Quick out
  245. $isAdmin = false;
  246. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  247. writeLog("success", "Admin: ".$username." authenticated by plex");
  248. //return true;
  249. $isAdmin = true;
  250. }
  251. //Get User List
  252. $userURL = 'https://plex.tv/pms/friends/all';
  253. $userHeaders = array(
  254. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  255. );
  256. libxml_use_internal_errors(true);
  257. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  258. if (is_array($userXML) || is_object($userXML)) {
  259. $isUser = false;
  260. $usernameLower = strtolower($username);
  261. foreach($userXML AS $child) {
  262. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  263. $isUser = true;
  264. writeLog("success", $usernameLower." was found in plex friends list");
  265. break;
  266. }
  267. }
  268. if ($isUser || $isAdmin) {
  269. //Login User
  270. $connectURL = 'https://plex.tv/users/sign_in.json';
  271. $headers = array(
  272. 'Accept'=> 'application/json',
  273. 'Content-Type' => 'application/x-www-form-urlencoded',
  274. 'X-Plex-Product' => 'Organizr',
  275. 'X-Plex-Version' => '1.0',
  276. 'X-Plex-Client-Identifier' => '01010101-10101010',
  277. );
  278. $body = array(
  279. 'user[login]' => $username,
  280. 'user[password]' => $password,
  281. );
  282. $result = curl_post($connectURL, $body, $headers);
  283. if (isset($result['content'])) {
  284. $json = json_decode($result['content'], true);
  285. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  286. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  287. return array(
  288. 'email' => $json['user']['email'],
  289. 'image' => $json['user']['thumb'],
  290. 'token' => $json['user']['authToken']
  291. );
  292. }
  293. }
  294. }else{
  295. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  296. }
  297. }else{
  298. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  299. }
  300. return false;
  301. }
  302. else :
  303. // Plex Auth Missing Dependancy
  304. function plugin_auth_plex_disabled() {
  305. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  306. }
  307. // Emby Connect Auth Missing Dependancy
  308. function plugin_auth_emby_connect_disabled() {
  309. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  310. }
  311. // Emby Both Auth Missing Dependancy
  312. function plugin_auth_emby_both_disabled() {
  313. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  314. }
  315. endif;
  316. // ==== Auth Plugins END ====
  317. // ==== General Class Definitions START ====
  318. $userLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  319. class setLanguage {
  320. private $language = null;
  321. private $langCode = null;
  322. function __construct($language = false) {
  323. // Default
  324. if (!$language) {
  325. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  326. }
  327. if (!file_exists("lang/{$language}.ini")) {
  328. $language = 'en';
  329. }
  330. $this->langCode = $language;
  331. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  332. if (file_exists("lang/{$language}.cust.ini")) {
  333. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  334. $this->language[$k] = $v;
  335. }
  336. }
  337. }
  338. public function getLang() {
  339. return $this->langCode;
  340. }
  341. public function translate($originalWord) {
  342. $getArg = func_num_args();
  343. if ($getArg > 1) {
  344. $allWords = func_get_args();
  345. array_shift($allWords);
  346. } else {
  347. $allWords = array();
  348. }
  349. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  350. if (!$translatedWord) {
  351. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  352. //echo "WHOA!!!!!!! $originalWord";
  353. }
  354. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  355. return vsprintf($translatedWord, $allWords);
  356. }
  357. }
  358. $language = new setLanguage;
  359. // ==== General Class Definitions END ====
  360. // Direct request to curl if it exists, otherwise handle if not HTTPS
  361. function post_router($url, $data, $headers = array(), $referer='') {
  362. if (function_exists('curl_version')) {
  363. return curl_post($url, $data, $headers, $referer);
  364. } else {
  365. return post_request($url, $data, $headers, $referer);
  366. }
  367. }
  368. if (function_exists('curl_version')) :
  369. // Curl Post
  370. function curl_post($url, $data, $headers = array(), $referer='') {
  371. // Initiate cURL
  372. $curlReq = curl_init($url);
  373. // As post request
  374. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  375. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  376. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  377. if(localURL($url)){
  378. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  379. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  380. }
  381. // Format Data
  382. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  383. case 'application/json':
  384. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  385. break;
  386. case 'application/x-www-form-urlencoded':
  387. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  388. break;
  389. default:
  390. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  391. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  392. }
  393. // Format Headers
  394. $cHeaders = array();
  395. foreach ($headers as $k => $v) {
  396. $cHeaders[] = $k.': '.$v;
  397. }
  398. if (count($cHeaders)) {
  399. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  400. }
  401. // Execute
  402. $result = curl_exec($curlReq);
  403. $httpcode = curl_getinfo($curlReq);
  404. // Close
  405. curl_close($curlReq);
  406. // Return
  407. return array('content'=>$result, 'http_code'=>$httpcode);
  408. }
  409. // Curl Put
  410. function curl_put($url, $data, $headers = array(), $referer='') {
  411. // Initiate cURL
  412. $curlReq = curl_init($url);
  413. // As post request
  414. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "PUT");
  415. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  416. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  417. if(localURL($url)){
  418. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  419. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  420. }
  421. // Format Data
  422. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  423. case 'application/json':
  424. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  425. break;
  426. case 'application/x-www-form-urlencoded':
  427. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  428. break;
  429. default:
  430. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  431. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  432. }
  433. // Format Headers
  434. $cHeaders = array();
  435. foreach ($headers as $k => $v) {
  436. $cHeaders[] = $k.': '.$v;
  437. }
  438. if (count($cHeaders)) {
  439. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  440. }
  441. // Execute
  442. $result = curl_exec($curlReq);
  443. $httpcode = curl_getinfo($curlReq);
  444. // Close
  445. curl_close($curlReq);
  446. // Return
  447. return array('content'=>$result, 'http_code'=>$httpcode);
  448. }
  449. //Curl Get Function
  450. function curl_get($url, $headers = array()) {
  451. // Initiate cURL
  452. $curlReq = curl_init($url);
  453. // As post request
  454. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  455. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  456. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  457. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  458. if(localURL($url)){
  459. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  460. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  461. }
  462. // Format Headers
  463. $cHeaders = array();
  464. foreach ($headers as $k => $v) {
  465. $cHeaders[] = $k.': '.$v;
  466. }
  467. if (count($cHeaders)) {
  468. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  469. }
  470. // Execute
  471. $result = curl_exec($curlReq);
  472. // Close
  473. curl_close($curlReq);
  474. // Return
  475. return $result;
  476. }
  477. //Curl Delete Function
  478. function curl_delete($url, $headers = array()) {
  479. // Initiate cURL
  480. $curlReq = curl_init($url);
  481. // As post request
  482. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  483. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  484. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  485. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  486. if(localURL($url)){
  487. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  488. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  489. }
  490. // Format Headers
  491. $cHeaders = array();
  492. foreach ($headers as $k => $v) {
  493. $cHeaders[] = $k.': '.$v;
  494. }
  495. if (count($cHeaders)) {
  496. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  497. }
  498. // Execute
  499. $result = curl_exec($curlReq);
  500. $httpcode = curl_getinfo($curlReq);
  501. // Close
  502. curl_close($curlReq);
  503. // Return
  504. return array('content'=>$result, 'http_code'=>$httpcode);
  505. }
  506. endif;
  507. //Case-Insensitive Function
  508. function in_arrayi($needle, $haystack) {
  509. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  510. }
  511. // HTTP post request (Removes need for curl, probably useless)
  512. function post_request($url, $data, $headers = array(), $referer='') {
  513. // Adapted from http://stackoverflow.com/a/28387011/6810513
  514. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  515. if (isset($headers['Content-Type'])) {
  516. switch ($headers['Content-Type']) {
  517. case 'application/json':
  518. $data = json_encode($data);
  519. break;
  520. case 'application/x-www-form-urlencoded':
  521. $data = http_build_query($data);
  522. break;
  523. }
  524. } else {
  525. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  526. $data = http_build_query($data);
  527. }
  528. // parse the given URL
  529. $urlDigest = parse_url($url);
  530. // extract host and path:
  531. $host = $urlDigest['host'];
  532. $path = $urlDigest['path'];
  533. if ($urlDigest['scheme'] != 'http') {
  534. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  535. }
  536. // open a socket connection on port 80 - timeout: 30 sec
  537. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  538. if ($fp){
  539. // send the request headers:
  540. fputs($fp, "POST $path HTTP/1.1\r\n");
  541. fputs($fp, "Host: $host\r\n");
  542. if ($referer != '')
  543. fputs($fp, "Referer: $referer\r\n");
  544. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  545. foreach($headers as $k => $v) {
  546. fputs($fp, $k.": ".$v."\r\n");
  547. }
  548. fputs($fp, "Connection: close\r\n\r\n");
  549. fputs($fp, $data);
  550. $result = '';
  551. while(!feof($fp)) {
  552. // receive the results of the request
  553. $result .= fgets($fp, 128);
  554. }
  555. }
  556. else {
  557. return array(
  558. 'status' => 'err',
  559. 'error' => "$errstr ($errno)"
  560. );
  561. }
  562. // close the socket connection:
  563. fclose($fp);
  564. // split the result header from the content
  565. $result = explode("\r\n\r\n", $result, 2);
  566. $header = isset($result[0]) ? $result[0] : '';
  567. $content = isset($result[1]) ? $result[1] : '';
  568. // return as structured array:
  569. return array(
  570. 'status' => 'ok',
  571. 'header' => $header,
  572. 'content' => $content,
  573. );
  574. }
  575. // Format item from Emby for Carousel
  576. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  577. // Static Height
  578. $height = 444;
  579. // Get Item Details
  580. $itemDetails = json_decode(@file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  581. /*if (substr_count(EMBYURL, ':') == 2) {
  582. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  583. }else{
  584. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  585. }*/
  586. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  587. switch ($itemDetails['Type']) {
  588. case 'Episode':
  589. case 'Series':
  590. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  591. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  592. $width = 300;
  593. $style = '';
  594. $image = 'slick-image-tall';
  595. if(!$nowPlaying){
  596. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  597. $key = $itemDetails['Id'] . "-list";
  598. $itemType = 'season';
  599. }else{
  600. $height = 281;
  601. $width = 500;
  602. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  603. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  604. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  605. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  606. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  607. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  608. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  609. $stream = $moreInfo['PlayState']['PlayMethod'];
  610. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  611. $id = $moreInfo['DeviceId'];
  612. $streamInfo = buildStream(array(
  613. 'platform' => (string) $moreInfo['Client'],
  614. 'device' => (string) $moreInfo['DeviceName'],
  615. 'stream' => streamType($stream),
  616. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  617. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  618. ));
  619. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  620. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  621. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  622. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  623. }
  624. break;
  625. case 'MusicAlbum':
  626. case 'Audio':
  627. $title = $itemDetails['Name'];
  628. $imageId = $itemDetails['Id'];
  629. $width = 444;
  630. $style = '';
  631. $image = 'slick-image-short';
  632. if(!$nowPlaying){
  633. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  634. $key = $itemDetails['Id'] . "-list";
  635. $itemType = 'album';
  636. }else{
  637. $height = 281;
  638. $width = 500;
  639. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  640. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  641. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  642. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  643. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  644. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  645. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  646. $stream = $moreInfo['PlayState']['PlayMethod'];
  647. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  648. $id = $moreInfo['DeviceId'];
  649. $streamInfo = buildStream(array(
  650. 'platform' => (string) $moreInfo['Client'],
  651. 'device' => (string) $moreInfo['DeviceName'],
  652. 'stream' => streamType($stream),
  653. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  654. ));
  655. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  656. $topTitle = '<h5 class="text-center zero-m elip">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  657. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  658. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  659. }
  660. break;
  661. case 'TvChannel':
  662. $title = $itemDetails['CurrentProgram']['Name'];
  663. $imageId = $itemDetails['Id'];
  664. $width = 300;
  665. $style = '';
  666. $image = 'slick-image-tall';
  667. if(!$nowPlaying){
  668. $imageType = "Primary";
  669. $key = $itemDetails['Id'] . "-list";
  670. }else{
  671. $height = 281;
  672. $width = 500;
  673. $imageType = "Thumb";
  674. $key = $itemDetails['Id'] . "-np";
  675. $useImage = "images/livetv.png";
  676. $watched = "0";
  677. $stream = $moreInfo['PlayState']['PlayMethod'];
  678. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  679. $id = $moreInfo['DeviceId'];
  680. $streamInfo = buildStream(array(
  681. 'platform' => (string) $moreInfo['Client'],
  682. 'device' => (string) $moreInfo['DeviceName'],
  683. 'stream' => streamType($stream),
  684. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  685. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  686. ));
  687. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  688. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  689. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  690. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  691. }
  692. break;
  693. default:
  694. $title = $itemDetails['Name'];
  695. $imageId = $itemDetails['Id'];
  696. $width = 300;
  697. $style = '';
  698. $image = 'slick-image-tall';
  699. if(!$nowPlaying){
  700. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  701. $key = $itemDetails['Id'] . "-list";
  702. $itemType = 'movie';
  703. }else{
  704. $height = 281;
  705. $width = 500;
  706. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  707. $key = $itemDetails['Id'] . "-np";
  708. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  709. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  710. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  711. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  712. $stream = $moreInfo['PlayState']['PlayMethod'];
  713. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  714. $id = $moreInfo['DeviceId'];
  715. $streamInfo = buildStream(array(
  716. 'platform' => (string) $moreInfo['Client'],
  717. 'device' => (string) $moreInfo['DeviceName'],
  718. 'stream' => streamType($stream),
  719. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  720. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  721. ));
  722. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  723. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  724. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  725. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  726. }
  727. }
  728. // If No Overview
  729. if (!isset($itemDetails['Overview'])) {
  730. $itemDetails['Overview'] = '';
  731. }
  732. $original_image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  733. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  734. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  735. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  736. }
  737. if($nowPlaying){
  738. if(!$imageType){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  739. if(!$imageId){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  740. }else{
  741. if(!$imageType){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  742. if(!$imageId){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  743. }
  744. if(isset($useImage)){ $image_url = $useImage; }
  745. // Assemble Item And Cache Into Array
  746. if($nowPlaying){
  747. //prettyPrint($itemDetails);
  748. 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>';
  749. }else{
  750. 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>';
  751. }
  752. }
  753. // Format item from Plex for Carousel
  754. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  755. // Static Height
  756. $height = 444;
  757. $widthOverride = 100;
  758. $playlist = ($playlist) ? " playlist-$playlist" : "";
  759. switch ($item['type']) {
  760. case 'season':
  761. $title = $item['parentTitle'];
  762. $summary = $item['parentSummary'];
  763. $width = 300;
  764. $image = 'slick-image-tall';
  765. $style = '';
  766. if(!$nowPlaying){
  767. $thumb = $item['thumb'];
  768. $key = $item['ratingKey'] . "-list";
  769. }else {
  770. $height = 281;
  771. $width = 500;
  772. $thumb = $item['art'];
  773. $key = $item['ratingKey'] . "-np";
  774. $elapsed = $item['viewOffset'];
  775. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  776. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  777. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  778. $stream = $item->Media->Part->Stream['decision'];
  779. $user = $role == "admin" ? $item->User['title'] : "";
  780. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  781. $streamInfo = buildStream(array(
  782. 'platform' => (string) $item->Player['platform'],
  783. 'device' => (string) $item->Player['device'],
  784. 'stream' => streamType($item->Media->Part['decision']),
  785. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  786. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  787. ));
  788. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  789. }
  790. break;
  791. case 'episode':
  792. $title = $item['grandparentTitle'];
  793. $summary = $item['title'];
  794. $width = 300;
  795. $image = 'slick-image-tall';
  796. $style = '';
  797. if(!$nowPlaying){
  798. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  799. $key = $item['ratingKey'] . "-list";
  800. }else {
  801. $height = 281;
  802. $width = 500;
  803. $thumb = $item['art'];
  804. $key = $item['ratingKey'] . "-np";
  805. $elapsed = $item['viewOffset'];
  806. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  807. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  808. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  809. $stream = $item->Media->Part->Stream['decision'];
  810. $user = $role == "admin" ? $item->User['title'] : "";
  811. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  812. $streamInfo = buildStream(array(
  813. 'platform' => (string) $item->Player['platform'],
  814. 'device' => (string) $item->Player['device'],
  815. 'stream' => streamType($item->Media->Part['decision']),
  816. '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'].")",
  817. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  818. ));
  819. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  820. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  821. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  822. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  823. }
  824. break;
  825. case 'clip':
  826. $title = $item['title'];
  827. $summary = $item['summary'];
  828. $width = 300;
  829. $image = 'slick-image-tall';
  830. $style = '';
  831. if(!$nowPlaying){
  832. $thumb = $item['thumb'];
  833. $key = $item['ratingKey'] . "-list";
  834. }else {
  835. $height = 281;
  836. $width = 500;
  837. $thumb = $item['art'];
  838. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  839. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  840. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  841. $elapsed = $item['viewOffset'];
  842. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  843. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  844. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  845. $stream = $item->Media->Part->Stream['decision'];
  846. $user = $role == "admin" ? $item->User['title'] : "";
  847. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  848. $streamInfo = buildStream(array(
  849. 'platform' => (string) $item->Player['platform'],
  850. 'device' => (string) $item->Player['device'],
  851. 'stream' => streamType($item->Media->Part['decision']),
  852. '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'].")",
  853. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  854. ));
  855. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  856. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  857. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  858. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  859. }
  860. break;
  861. case 'album':
  862. case 'track':
  863. $title = $item['parentTitle'];
  864. $summary = $item['title'];
  865. $image = 'slick-image-short';
  866. $style = 'left: 160px !important;';
  867. $item['ratingKey'] = $item['parentRatingKey'];
  868. if(!$nowPlaying){
  869. $width = 444;
  870. $thumb = $item['thumb'];
  871. $key = $item['ratingKey'] . "-list";
  872. }else {
  873. $height = 281;
  874. $width = 500;
  875. $thumb = ($item['art']) ? $item['art'] : $item['parentThumb'];
  876. $widthOverride = ($item['art']) ? 100 : 56;
  877. $key = $item['ratingKey'] . "-np";
  878. $elapsed = $item['viewOffset'];
  879. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  880. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  881. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  882. $stream = $item->Media->Part->Stream['decision'];
  883. $user = $role == "admin" ? $item->User['title'] : "";
  884. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  885. $streamInfo = buildStream(array(
  886. 'platform' => (string) $item->Player['platform'],
  887. 'device' => (string) $item->Player['device'],
  888. 'stream' => streamType($item->Media->Part['decision']),
  889. 'audio' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  890. ));
  891. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  892. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  893. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  894. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  895. }
  896. break;
  897. default:
  898. $title = $item['title'];
  899. $summary = $item['summary'];
  900. $image = 'slick-image-tall';
  901. $style = '';
  902. if(!$nowPlaying){
  903. $width = 300;
  904. $thumb = $item['thumb'];
  905. $key = $item['ratingKey'] . "-list";
  906. }else {
  907. $height = 281;
  908. $width = 500;
  909. $thumb = $item['art'];
  910. $key = $item['ratingKey'] . "-np";
  911. $elapsed = $item['viewOffset'];
  912. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  913. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  914. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  915. $stream = $item->Media->Part->Stream['decision'];
  916. $user = $role == "admin" ? $item->User['title'] : "";
  917. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  918. $streamInfo = buildStream(array(
  919. 'platform' => (string) $item->Player['platform'],
  920. 'device' => (string) $item->Player['device'],
  921. 'stream' => streamType($item->Media->Part['decision']),
  922. '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'].")",
  923. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  924. ));
  925. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  926. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  927. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  928. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  929. }
  930. }
  931. if (PLEXTABURL) {
  932. $address = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  933. }else{
  934. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  935. }
  936. // If No Overview
  937. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  938. $original_image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  939. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  940. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  941. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  942. }
  943. if($nowPlaying){
  944. if(!$thumb){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  945. }else{
  946. if(!$thumb){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  947. }
  948. if(isset($useImage)){ $image_url = $useImage; }
  949. $openTab = (PLEXTABNAME) ? "true" : "false";
  950. // Assemble Item And Cache Into Array
  951. if($nowPlaying){
  952. 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>';
  953. }else{
  954. 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>';
  955. }
  956. }
  957. //$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  958. //Recent Added
  959. function outputRecentAdded($header, $items, $script = false, $array, $type) {
  960. $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">';
  961. if(preg_grep("/item-movie/", $items)){
  962. $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>';
  963. }
  964. if(preg_grep("/item-season/", $items)){
  965. $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>';
  966. }
  967. if(preg_grep("/item-album/", $items)){
  968. $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>';
  969. }
  970. $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>';
  971. $hideMenu .= '</ul></div></div>';
  972. // If None Populate Empty Item
  973. if (!count($items)) {
  974. 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>';
  975. }else{
  976. $className = str_replace(' ', '', $header.' on '.$type);
  977. 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>':'');
  978. }
  979. }
  980. // Create Carousel
  981. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  982. // If None Populate Empty Item
  983. if (!count($items)) {
  984. return '<div id="'.$type.'"></div>'.($script?'<script>'.$script.'</script>':'');
  985. }else{
  986. return '<div id="'.$type.'"><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  987. }
  988. }
  989. // Get Now Playing Streams From Emby
  990. function getEmbyStreams($size, $showNames, $role) {
  991. $address = qualifyURL(EMBYURL);
  992. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  993. if (!is_array($api)) { return 'Could not load!'; }
  994. $playingItems = array();
  995. foreach($api as $key => $value) {
  996. if (isset($value['NowPlayingItem'])) {
  997. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  998. }
  999. }
  1000. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY')." ( ".count($playingItems)." Streams )", $size, 'streams-emby', $playingItems, ajaxLoop('emby-streams',NOWPLAYINGREFRESH));
  1001. }
  1002. // Get Now Playing Streams From Plex
  1003. function getPlexStreams($size, $showNames, $role){
  1004. $address = qualifyURL(PLEXURL);
  1005. // Perform API requests
  1006. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  1007. libxml_use_internal_errors(true);
  1008. $api = simplexml_load_string($api);
  1009. if (is_array($api) || is_object($api)){
  1010. if (!$api->head->title){
  1011. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  1012. if (!$getServer) { return 'Could not load!'; }
  1013. // Identify the local machine
  1014. $gotServer = $getServer['machineIdentifier'];
  1015. $items = array();
  1016. foreach($api AS $child) {
  1017. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  1018. }
  1019. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, ajaxLoop('plex-streams',NOWPLAYINGREFRESH));
  1020. }else{
  1021. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  1022. }
  1023. }else{
  1024. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1025. }
  1026. }
  1027. // Get Recent Content From Emby
  1028. function getEmbyRecent($array) {
  1029. $address = qualifyURL(EMBYURL);
  1030. $header = translate('RECENT_CONTENT');
  1031. // Currently Logged In User
  1032. $username = false;
  1033. if (isset($GLOBALS['USER'])) {
  1034. $username = strtolower($GLOBALS['USER']->username);
  1035. }
  1036. // Get A User
  1037. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  1038. if (!is_array($userIds)) { return 'Could not load!'; }
  1039. $showPlayed = true;
  1040. foreach ($userIds as $value) { // Scan for admin user
  1041. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  1042. $userId = $value['Id'];
  1043. }
  1044. if ($username && strtolower($value['Name']) == $username) {
  1045. $userId = $value['Id'];
  1046. $showPlayed = false;
  1047. break;
  1048. }
  1049. }
  1050. // Get the latest Items
  1051. $latest = json_decode(@file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  1052. // For Each Item In Category
  1053. $items = array();
  1054. foreach ($latest as $k => $v) {
  1055. $type = (string) $v['Type'];
  1056. if(@$array[$type] == "true"){
  1057. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  1058. }
  1059. }
  1060. $array["movie"] = $array["Movie"];
  1061. $array["season"] = $array["Episode"];
  1062. $array["album"] = $array["MusicAlbum"];
  1063. unset($array["Movie"]);
  1064. unset($array["Episode"]);
  1065. unset($array["MusicAlbum"]);
  1066. unset($array["Series"]);
  1067. return outputRecentAdded($header, $items, ajaxLoop('emby-recent',RECENTREFRESH,'loadSlick();'), $array, 'Emby');
  1068. }
  1069. // Get Recent Content From Plex
  1070. function getPlexRecent($array){
  1071. $address = qualifyURL(PLEXURL);
  1072. $header = translate('RECENT_CONTENT');
  1073. // Perform Requests
  1074. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  1075. libxml_use_internal_errors(true);
  1076. $api = simplexml_load_string($api);
  1077. if (is_array($api) || is_object($api)){
  1078. if (!$api->head->title){
  1079. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  1080. if (!$getServer) { return 'Could not load!'; }
  1081. // Identify the local machine
  1082. $gotServer = $getServer['machineIdentifier'];
  1083. $items = array();
  1084. foreach($api AS $child) {
  1085. $type = (string) $child['type'];
  1086. if($array[$type] == "true"){
  1087. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  1088. }
  1089. }
  1090. return outputRecentAdded($header, $items, ajaxLoop('plex-recent',RECENTREFRESH,'loadSlick();'), $array, 'Plex');
  1091. }else{
  1092. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  1093. }
  1094. }else{
  1095. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1096. }
  1097. }
  1098. // Get Image From Emby
  1099. function getEmbyImage() {
  1100. $refresh = false;
  1101. $embyAddress = qualifyURL(EMBYURL);
  1102. if (!file_exists('images/cache')) {
  1103. mkdir('images/cache', 0777, true);
  1104. }
  1105. $itemId = $_GET['img'];
  1106. $key = $_GET['key'];
  1107. if(strpos($key, '$') !== false){
  1108. $key = explode('$', $key)[0];
  1109. $refresh = true;
  1110. }
  1111. $itemType = $_GET['type'];
  1112. $imgParams = array();
  1113. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  1114. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  1115. if(isset($itemId)) {
  1116. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  1117. $cachefile = 'images/cache/'.$key.'.jpg';
  1118. $cachetime = 604800;
  1119. // Serve from the cache if it is younger than $cachetime
  1120. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh !== true) {
  1121. header("Content-type: image/jpeg");
  1122. @readfile($cachefile);
  1123. exit;
  1124. }
  1125. ob_start(); // Start the output buffer
  1126. header('Content-type: image/jpeg');
  1127. //@readfile($image_src);
  1128. echo @curl_get($image_src);
  1129. // Cache the output to a file
  1130. $fp = fopen($cachefile, 'wb');
  1131. fwrite($fp, ob_get_contents());
  1132. fclose($fp);
  1133. ob_end_flush(); // Send the output to the browser
  1134. die();
  1135. } else {
  1136. debug_out('Invalid Request',1);
  1137. }
  1138. }
  1139. // Get Image From Plex
  1140. function getPlexImage() {
  1141. $refresh = false;
  1142. $plexAddress = qualifyURL(PLEXURL);
  1143. if (!file_exists('images/cache')) {
  1144. mkdir('images/cache', 0777, true);
  1145. }
  1146. $image_url = $_GET['img'];
  1147. $key = $_GET['key'];
  1148. if(strpos($key, '$') !== false){
  1149. $key = explode('$', $key)[0];
  1150. $refresh = true;
  1151. }
  1152. $image_height = $_GET['height'];
  1153. $image_width = $_GET['width'];
  1154. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1155. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1156. $cachefile = 'images/cache/'.$key.'.jpg';
  1157. $cachetime = 604800;
  1158. // Serve from the cache if it is younger than $cachetime
  1159. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1160. header("Content-type: image/jpeg");
  1161. @readfile($cachefile);
  1162. exit;
  1163. }
  1164. ob_start(); // Start the output buffer
  1165. header('Content-type: image/jpeg');
  1166. //@readfile($image_src);
  1167. echo @curl_get($image_src);
  1168. // Cache the output to a file
  1169. $fp = fopen($cachefile, 'wb');
  1170. fwrite($fp, ob_get_contents());
  1171. fclose($fp);
  1172. ob_end_flush(); // Send the output to the browser
  1173. die();
  1174. } else {
  1175. echo "Invalid Plex Request";
  1176. }
  1177. }
  1178. // Simplier access to class
  1179. function translate($string) {
  1180. if (isset($GLOBALS['language'])) {
  1181. return $GLOBALS['language']->translate($string);
  1182. } else {
  1183. return '!Translations Not Loaded!';
  1184. }
  1185. }
  1186. // Generate Random string
  1187. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1188. $tmp = '';
  1189. for ($i = 0; $i < $length; $i++) {
  1190. $tmp .= substr(str_shuffle($chars), 0, 1);
  1191. }
  1192. return $tmp;
  1193. }
  1194. // Create config file in the return syntax
  1195. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1196. // Define Initial Value
  1197. $output = array();
  1198. // Sort Items
  1199. ksort($array);
  1200. // Update the current config version
  1201. if (!$nest) {
  1202. // Inject Current Version
  1203. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1204. }
  1205. unset($array['CONFIG_VERSION']);
  1206. unset($array['apply_CONFIG_VERSION']);
  1207. // Process Settings
  1208. foreach ($array as $k => $v) {
  1209. $allowCommit = true;
  1210. switch (gettype($v)) {
  1211. case 'boolean':
  1212. $item = ($v?'true':'false');
  1213. break;
  1214. case 'integer':
  1215. case 'double':
  1216. case 'integer':
  1217. case 'NULL':
  1218. $item = $v;
  1219. break;
  1220. case 'string':
  1221. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1222. break;
  1223. case 'array':
  1224. $item = createConfig($v, false, $nest+1);
  1225. break;
  1226. default:
  1227. $allowCommit = false;
  1228. }
  1229. if($allowCommit) {
  1230. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1231. }
  1232. }
  1233. // Build output
  1234. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1235. if (!$nest && $path) {
  1236. $pathDigest = pathinfo($path);
  1237. @mkdir($pathDigest['dirname'], 0770, true);
  1238. if (file_exists($path)) {
  1239. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1240. }
  1241. $file = fopen($path, 'w');
  1242. fwrite($file, $output);
  1243. fclose($file);
  1244. if (file_exists($path)) {
  1245. return true;
  1246. }
  1247. writeLog("error", "config was unable to write");
  1248. return false;
  1249. } else {
  1250. writeLog("success", "config was updated with new values");
  1251. return $output;
  1252. }
  1253. }
  1254. // Load a config file written in the return syntax
  1255. function loadConfig($path = 'config/config.php') {
  1256. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1257. if (!is_file($path)) {
  1258. return null;
  1259. } else {
  1260. return (array) call_user_func(function() use($path) {
  1261. return include($path);
  1262. });
  1263. }
  1264. }
  1265. // Commit new values to the configuration
  1266. function updateConfig($new, $current = false) {
  1267. // Get config if not supplied
  1268. if ($current === false) {
  1269. $current = loadConfig();
  1270. } else if (is_string($current) && is_file($current)) {
  1271. $current = loadConfig($current);
  1272. }
  1273. // Inject Parts
  1274. foreach ($new as $k => $v) {
  1275. $current[$k] = $v;
  1276. }
  1277. // Return Create
  1278. return createConfig($current);
  1279. }
  1280. // Inject Defaults As Needed
  1281. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1282. if (is_string($path)) {
  1283. $loadedDefaults = loadConfig($path);
  1284. } else {
  1285. $loadedDefaults = $path;
  1286. }
  1287. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1288. }
  1289. // support function for fillDefaultConfig()
  1290. function fillDefaultConfig_recurse($current, $defaults) {
  1291. foreach($defaults as $k => $v) {
  1292. if (!isset($current[$k])) {
  1293. $current[$k] = $v;
  1294. } else if (is_array($current[$k]) && is_array($v)) {
  1295. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1296. }
  1297. }
  1298. return $current;
  1299. };
  1300. // Define Scalar Variables (nest non-secular with underscores)
  1301. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1302. foreach($array as $k => $v) {
  1303. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1304. define($nest_prefix.$k, $v, $anyCase);
  1305. } else if (is_array($v)) {
  1306. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1307. }
  1308. }
  1309. }
  1310. // This function exists only because I am lazy
  1311. function configLazy($path = 'config/config.php') {
  1312. // Load config or default
  1313. if (file_exists($path)) {
  1314. $config = fillDefaultConfig(loadConfig($path));
  1315. } else {
  1316. $config = loadConfig('config/configDefaults.php');
  1317. }
  1318. if (is_array($config)) {
  1319. defineConfig($config);
  1320. }
  1321. return $config;
  1322. }
  1323. // Qualify URL
  1324. function qualifyURL($url) {
  1325. //local address?
  1326. if(substr($url, 0,1) == "/"){
  1327. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1328. $protocol = "https://";
  1329. } else {
  1330. $protocol = "http://";
  1331. }
  1332. $url = $protocol.getServer().$url;
  1333. }
  1334. // Get Digest
  1335. $digest = parse_url($url);
  1336. // http/https
  1337. if (!isset($digest['scheme'])) {
  1338. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1339. $scheme = 'http';
  1340. } else {
  1341. $scheme = 'https';
  1342. }
  1343. } else {
  1344. $scheme = $digest['scheme'];
  1345. }
  1346. // Host
  1347. $host = (isset($digest['host'])?$digest['host']:'');
  1348. // Port
  1349. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1350. // Path
  1351. $path = (isset($digest['path'])?$digest['path']:'');
  1352. // Output
  1353. return $scheme.'://'.$host.$port.$path;
  1354. }
  1355. // Function to be called at top of each to allow upgrading environment as the spec changes
  1356. function upgradeCheck() {
  1357. // Upgrade to 1.31
  1358. if (file_exists('homepageSettings.ini.php')) {
  1359. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1360. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1361. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1362. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1363. foreach($databaseConfig as $k => $v) {
  1364. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1365. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1366. }
  1367. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1368. unlink('homepageSettings.ini.php');
  1369. unset($databaseData);
  1370. unset($homepageConfig);
  1371. }
  1372. // Upgrade to 1.32
  1373. if (file_exists('databaseLocation.ini.php')) {
  1374. // Load Existing
  1375. $config = parse_ini_file('databaseLocation.ini.php', true);
  1376. // Refactor
  1377. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1378. $config['user_home'] = $config['database_Location'].'users/';
  1379. unset($config['databaseLocation']);
  1380. // Turn Off Emby And Plex Recent
  1381. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1382. unset($config["embyPort"]);
  1383. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1384. unset($config["plexPort"]);
  1385. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1386. unset($config["nzbgetPort"]);
  1387. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1388. unset($config["sabnzbdPort"]);
  1389. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1390. unset($config["headphonesPort"]);
  1391. // Write config file
  1392. $config['CONFIG_VERSION'] = '1.32';
  1393. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1394. $createConfigSuccess = createConfig($config);
  1395. // Create new config
  1396. if ($createConfigSuccess) {
  1397. if (file_exists('config/config.php')) {
  1398. // Remove Old ini file
  1399. unlink('databaseLocation.ini.php');
  1400. } else {
  1401. debug_out('Something is not right here!');
  1402. }
  1403. } else {
  1404. debug_out('Couldn\'t create updated configuration.' ,1);
  1405. }
  1406. }
  1407. // Upgrade to 1.33
  1408. $config = loadConfig();
  1409. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1410. // Fix User Directory
  1411. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1412. $config['user_home'] = $config['database_Location'].'users/';
  1413. unset($config['USER_HOME']);
  1414. // Backend auth merge
  1415. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1416. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1417. }
  1418. unset($config['authBackendPort']);
  1419. // If auth is being used move it to embyURL as that is now used in auth functions
  1420. 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')))) {
  1421. $config['embyURL'] = $config['authBackendHost'];
  1422. }
  1423. // Upgrade database to latest version
  1424. updateSQLiteDB($config['database_Location'],'1.32');
  1425. // Update Version and Commit
  1426. $config['apply_CONFIG_VERSION'] = '1.33';
  1427. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1428. $createConfigSuccess = createConfig($config);
  1429. unset($config);
  1430. }
  1431. // Upgrade to 1.34
  1432. $config = loadConfig();
  1433. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1434. // Upgrade database to latest version
  1435. updateSQLiteDB($config['database_Location'],'1.33');
  1436. // Update Version and Commit
  1437. $config['CONFIG_VERSION'] = '1.34';
  1438. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1439. $createConfigSuccess = createConfig($config);
  1440. unset($config);
  1441. }
  1442. // Upgrade to 1.40
  1443. $config = loadConfig();
  1444. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1445. // Upgrade database to latest version
  1446. updateSQLiteDB($config['database_Location'],'1.38');
  1447. // Update Version and Commit
  1448. $config['CONFIG_VERSION'] = '1.40';
  1449. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1450. $createConfigSuccess = createConfig($config);
  1451. unset($config);
  1452. }
  1453. // Upgrade to 1.50
  1454. $config = loadConfig();
  1455. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.50')) {
  1456. // Upgrade database to latest version
  1457. updateSQLiteDB($config['database_Location'],'1.40');
  1458. // Update Version and Commit
  1459. $config['CONFIG_VERSION'] = '1.50';
  1460. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.40].bak.php');
  1461. $createConfigSuccess = createConfig($config);
  1462. unset($config);
  1463. }
  1464. // Upgrade to 1.603
  1465. $config = loadConfig();
  1466. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.603')) {
  1467. // Update Version and Commit
  1468. $config['CONFIG_VERSION'] = '1.603';
  1469. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.601].bak.php');
  1470. $createConfigSuccess = createConfig($config);
  1471. unset($config);
  1472. if(file_exists('org.log')){
  1473. copy('org.log', DATABASE_LOCATION.'org.log');
  1474. unlink('org.log');
  1475. }
  1476. if(file_exists('loginLog.json')){
  1477. copy('loginLog.json', DATABASE_LOCATION.'loginLog.json');
  1478. unlink('loginLog.json');
  1479. }
  1480. }
  1481. return true;
  1482. }
  1483. // Get OS from server
  1484. function getOS(){
  1485. if(PHP_SHLIB_SUFFIX == "dll"){
  1486. return "win";
  1487. }else{
  1488. return "nix";
  1489. }
  1490. }
  1491. //Get Error by Server OS
  1492. function getError($os, $error){
  1493. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1494. $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'");
  1495. $errors = array(
  1496. 'pdo_sqlite' => array(
  1497. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1498. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1499. ),
  1500. 'sqlite3' => array(
  1501. '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',
  1502. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1503. ),
  1504. 'curl' => array(
  1505. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1506. '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',
  1507. ),
  1508. 'zip' => array(
  1509. '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',
  1510. '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',
  1511. ),
  1512. );
  1513. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1514. }
  1515. // Check if all software dependancies are met
  1516. function dependCheck() {
  1517. $output = array();
  1518. $i = 1;
  1519. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1520. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1521. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1522. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1523. if ($output) {
  1524. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1525. $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++;
  1526. debug_out($output,1);
  1527. }
  1528. return true;
  1529. }
  1530. // Process file uploads
  1531. function uploadFiles($path, $ext_mask = null) {
  1532. if (isset($_FILES) && count($_FILES)) {
  1533. require_once('class.uploader.php');
  1534. $uploader = new Uploader();
  1535. $data = $uploader->upload($_FILES['files'], array(
  1536. 'limit' => 10,
  1537. 'maxSize' => 10,
  1538. 'extensions' => $ext_mask,
  1539. 'required' => false,
  1540. 'uploadDir' => str_replace('//','/',$path.'/'),
  1541. 'title' => array('name'),
  1542. 'removeFiles' => true,
  1543. 'replace' => true,
  1544. ));
  1545. if($data['isComplete']){
  1546. $files = $data['data'];
  1547. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1548. echo json_encode($files['metas'][0]['name']);
  1549. }
  1550. if($data['hasErrors']){
  1551. $errors = $data['errors'];
  1552. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1553. echo json_encode($errors);
  1554. }
  1555. } else {
  1556. writeLog("error", "image was not uploaded");
  1557. echo json_encode('No files submitted!');
  1558. }
  1559. }
  1560. // Process file uploads
  1561. function uploadAvatar($path, $ext_mask = null) {
  1562. if (isset($_FILES) && count($_FILES)) {
  1563. require_once('class.uploader.php');
  1564. $uploader = new Uploader();
  1565. $data = $uploader->upload($_FILES['files'], array(
  1566. 'limit' => 10,
  1567. 'maxSize' => 10,
  1568. 'extensions' => $ext_mask,
  1569. 'required' => false,
  1570. 'uploadDir' => str_replace('//','/',$path.'/'),
  1571. 'title' => array('name'),
  1572. 'removeFiles' => true,
  1573. 'replace' => true,
  1574. ));
  1575. if($data['isComplete']){
  1576. $files = $data['data'];
  1577. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1578. echo json_encode($files['metas'][0]['name']);
  1579. }
  1580. if($data['hasErrors']){
  1581. $errors = $data['errors'];
  1582. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1583. echo json_encode($errors);
  1584. }
  1585. } else {
  1586. writeLog("error", "image was not uploaded");
  1587. echo json_encode('No files submitted!');
  1588. }
  1589. }
  1590. // Remove file
  1591. function removeFiles($path) {
  1592. if(is_file($path)) {
  1593. writeLog("success", "file was removed");
  1594. unlink($path);
  1595. } else {
  1596. writeLog("error", "file was not removed");
  1597. echo json_encode('No file specified for removal!');
  1598. }
  1599. }
  1600. // Lazy select options
  1601. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1602. $output = array();
  1603. $selectedArr = ($multi?explode('|', $selected):array());
  1604. foreach ($array as $key => $value) {
  1605. if (is_array($value)) {
  1606. if (isset($value['optgroup'])) {
  1607. $output[] = '<optgroup label="'.$key.'">';
  1608. foreach($value['optgroup'] as $k => $v) {
  1609. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1610. }
  1611. } else {
  1612. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1613. }
  1614. } else {
  1615. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1616. }
  1617. }
  1618. return implode('',$output);
  1619. }
  1620. // Check if user is allowed to continue
  1621. function qualifyUser($type, $errOnFail = false) {
  1622. if (!isset($GLOBALS['USER'])) {
  1623. require_once("user.php");
  1624. $GLOBALS['USER'] = new User('registration_callback');
  1625. }
  1626. if (is_bool($type)) {
  1627. if ($type === true) {
  1628. $authorized = ($GLOBALS['USER']->authenticated == true);
  1629. } else {
  1630. $authorized = true;
  1631. }
  1632. } elseif (is_string($type) || is_array($type)) {
  1633. if ($type !== 'false') {
  1634. if (!is_array($type)) {
  1635. $type = explode('|',$type);
  1636. }
  1637. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1638. } else {
  1639. $authorized = true;
  1640. }
  1641. } else {
  1642. debug_out('Invalid Syntax!',1);
  1643. }
  1644. if (!$authorized && $errOnFail) {
  1645. if ($GLOBALS['USER']->authenticated) {
  1646. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401');
  1647. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401\'</script>';
  1648. } else {
  1649. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999');
  1650. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999\'</script>';
  1651. }
  1652. debug_out('Not Authorized' ,1);
  1653. } else {
  1654. return $authorized;
  1655. }
  1656. }
  1657. // Build an (optionally) tabbed settings page.
  1658. function buildSettings($array) {
  1659. /*
  1660. array(
  1661. 'title' => '',
  1662. 'id' => '',
  1663. 'fields' => array( See buildField() ),
  1664. 'tabs' => array(
  1665. array(
  1666. 'title' => '',
  1667. 'id' => '',
  1668. 'image' => '',
  1669. 'fields' => array( See buildField() ),
  1670. ),
  1671. ),
  1672. );
  1673. */
  1674. $notifyExplode = explode("-", NOTIFYEFFECT);
  1675. $fieldFunc = function($fieldArr) {
  1676. $fields = '<div class="row">';
  1677. foreach($fieldArr as $key => $value) {
  1678. $isSingle = isset($value['type']);
  1679. if ($isSingle) { $value = array($value); }
  1680. $tmpField = '';
  1681. $sizeLg = max(floor(12/count($value)),2);
  1682. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1683. foreach($value as $k => $v) {
  1684. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1685. }
  1686. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1687. }
  1688. $fields .= '</div>';
  1689. return $fields;
  1690. };
  1691. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1692. $tabSelectors = array();
  1693. $tabContent = array();
  1694. if (isset($array['tabs'])) {
  1695. foreach($array['tabs'] as $key => $value) {
  1696. $id = (isset($value['id'])?$value['id']:randString(32));
  1697. $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>';
  1698. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1699. }
  1700. }
  1701. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1702. $extraClick = ($pageID == 'appearance_settings' ? "$('#advanced_settings_form_submit').click();console.log('add theme settings');" : "");
  1703. return '
  1704. <div class="email-body">
  1705. <div class="email-header gray-bg">
  1706. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1707. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float save-btn-form">
  1708. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1709. </button>
  1710. <h1>'.$array['title'].'</h1>
  1711. </div>
  1712. <div class="email-inner small-box">
  1713. <div class="email-inner-section">
  1714. <div class="small-box fade in" id="'.$pageID.'_frame">
  1715. <div class="col-lg-12">
  1716. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1717. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1718. '.$fields.($tabContent?'
  1719. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1720. <ul class="nav nav-tabs apps">
  1721. '.implode('', $tabSelectors).'
  1722. </ul>
  1723. <div class="clearfix"></div>
  1724. <div class="tab-content">
  1725. '.implode('', $tabContent).'
  1726. </div>
  1727. </div>':'').'
  1728. </form>
  1729. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1730. </div>
  1731. </div>
  1732. </div>
  1733. </div>
  1734. </div>
  1735. <script>
  1736. $(document).ready(function() {
  1737. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1738. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1739. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1740. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1741. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1742. var newVals = {};
  1743. var hasVals = false;
  1744. var errorFields = [];
  1745. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1746. hasVals = true;
  1747. if (this.type == \'checkbox\') {
  1748. newVals[this.name] = this.checked;
  1749. } else if ($(this).hasClass(\'summernote\')) {
  1750. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1751. } else {
  1752. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1753. var fieldVal = $(this).val();
  1754. if (typeof fieldVal == \'object\') {
  1755. if (typeof fieldVal.join == \'function\') {
  1756. fieldVal = fieldVal.join(\'|\');
  1757. } else {
  1758. fieldVal = JSON.stringify(fieldVal);
  1759. }
  1760. }
  1761. newVals[this.name] = fieldVal;
  1762. }
  1763. });
  1764. if (errorFields.length) {
  1765. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1766. } else if (hasVals) {
  1767. console.log(newVals);
  1768. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1769. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1770. });
  1771. '.$extraClick.'
  1772. } else {
  1773. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1774. }
  1775. return false;
  1776. });
  1777. '.(isset($array['onready'])?$array['onready']:'').'
  1778. });
  1779. </script>
  1780. ';
  1781. }
  1782. // Build Settings Fields
  1783. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1784. /*
  1785. array(
  1786. 'type' => '',
  1787. 'placeholder' => '',
  1788. 'label' => '',
  1789. 'labelTranslate' => '',
  1790. 'assist' => '',
  1791. 'name' => '',
  1792. 'pattern' => '',
  1793. 'options' => array( // For SELECT only
  1794. 'Display' => 'value',
  1795. ),
  1796. )
  1797. */
  1798. // Tags
  1799. $tags = array();
  1800. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick') as $value) {
  1801. if (isset($params[$value])) {
  1802. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1803. } else if ($params[$value] === true) { $tags[] = $value; }
  1804. }
  1805. }
  1806. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1807. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1808. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1809. $val = (isset($params['value'])?$params['value']:'');
  1810. $class = (isset($params['class'])?' '.$params['class']:'');
  1811. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1812. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1813. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1814. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1815. // Field Design
  1816. switch ($params['type']) {
  1817. case 'text':
  1818. case 'number':
  1819. case 'password':
  1820. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1821. break;
  1822. case 'select':
  1823. case 'dropdown':
  1824. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1825. break;
  1826. case 'select-multi':
  1827. case 'dropdown-multi':
  1828. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1829. break;
  1830. case 'check':
  1831. case 'checkbox':
  1832. case 'toggle':
  1833. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1834. $colour = (isset($params['colour'])?$params['colour']:'success');
  1835. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1836. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1837. break;
  1838. case 'radio':
  1839. $labelOut = '';
  1840. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1841. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1842. $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>';
  1843. break;
  1844. case 'date':
  1845. $field = 'Unsupported, planned.';
  1846. break;
  1847. case 'hidden':
  1848. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1849. break;
  1850. case 'header':
  1851. $labelOut = '';
  1852. $headType = (isset($params['value'])?$params['value']:3);
  1853. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1854. break;
  1855. case 'button':
  1856. $labelOut = '';
  1857. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1858. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1859. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1860. $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>':'');
  1861. break;
  1862. case 'textarea':
  1863. $rows = (isset($params['rows'])?$params['rows']:5);
  1864. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1865. break;
  1866. case 'custom':
  1867. // Settings
  1868. $settings = array(
  1869. '$id' => $id,
  1870. '$name' => $name,
  1871. '$val' => $val,
  1872. '$label' => $label,
  1873. '$labelOut' => $labelOut,
  1874. );
  1875. // Get HTML
  1876. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1877. // If LabelOut is in html dont print it twice
  1878. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1879. // Replace variables in settings
  1880. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1881. // Build Field
  1882. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1883. break;
  1884. case 'space':
  1885. $labelOut = '';
  1886. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1887. break;
  1888. default:
  1889. $field = 'Unsupported field type';
  1890. break;
  1891. }
  1892. // Field Formats
  1893. switch ($format) {
  1894. case 'colour': // Fuckin Eh, Canada!
  1895. case 'color':
  1896. $labelBef = '<center>'.$label.'</center>';
  1897. $wrapClass = 'gray-bg colour-field';
  1898. $labelAft = '';
  1899. $field = str_replace(' material input-sm','',$field);
  1900. break;
  1901. default:
  1902. $labelBef = '';
  1903. $labelAft = $labelOut;
  1904. }
  1905. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1906. }
  1907. // Tab Settings Generation
  1908. function printTabRow($data) {
  1909. $hidden = false;
  1910. if ($data===false) {
  1911. $hidden = true;
  1912. $data = array( // New Tab Defaults
  1913. 'id' => 'new',
  1914. 'name' => '',
  1915. 'url' => '',
  1916. 'icon' => 'fa-diamond',
  1917. 'iconurl' => '',
  1918. 'active' => 'true',
  1919. 'user' => 'true',
  1920. 'guest' => 'true',
  1921. 'window' => 'false',
  1922. 'splash' => 'true',
  1923. 'ping' => 'false',
  1924. 'ping_url' => '',
  1925. 'defaultz' => '',
  1926. );
  1927. }
  1928. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1929. $output = '
  1930. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1931. <tab class="content-form form-inline">
  1932. <div class="row">
  1933. '.buildField(array(
  1934. 'type' => 'custom',
  1935. '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>',
  1936. ),12,1,1).'
  1937. '.buildField(array(
  1938. 'type' => 'hidden',
  1939. 'id' => 'tab-'.$data['id'].'-id',
  1940. 'name' => 'id['.$data['id'].']',
  1941. 'value' => $data['id'],
  1942. ),12,2,1).'
  1943. '.buildField(array(
  1944. 'type' => 'text',
  1945. 'id' => 'tab-'.$data['id'].'-name',
  1946. 'name' => 'name['.$data['id'].']',
  1947. 'required' => true,
  1948. 'placeholder' => 'Organizr Homepage',
  1949. 'labelTranslate' => 'TAB_NAME',
  1950. 'value' => $data['name'],
  1951. 'class' => 'darkBold',
  1952. ),12,2,1).'
  1953. '.buildField(array(
  1954. 'type' => 'text',
  1955. 'id' => 'tab-'.$data['id'].'-url',
  1956. 'name' => 'url['.$data['id'].']',
  1957. 'required' => true,
  1958. 'placeholder' => 'homepage.php',
  1959. 'labelTranslate' => 'TAB_URL',
  1960. 'value' => $data['url'],
  1961. 'class' => 'darkBold',
  1962. ),12,2,2).'
  1963. '.buildField(array(
  1964. 'type' => 'text',
  1965. 'id' => 'tab-'.$data['id'].'-iconurl',
  1966. 'name' => 'iconurl['.$data['id'].']',
  1967. 'placeholder' => 'images/organizr.png',
  1968. 'labelTranslate' => 'ICON_URL',
  1969. 'value' => $data['iconurl'],
  1970. 'class' => 'darkBold',
  1971. ),12,2,1).'
  1972. '.buildField(array(
  1973. 'type' => 'text',
  1974. 'id' => 'tab-'.$data['id'].'-icon',
  1975. 'name' => 'icon['.$data['id'].']',
  1976. 'placeholder' => 'fa-icon',
  1977. 'labelTranslate' => 'OR_ICON_NAME',
  1978. 'value' => $data['icon'],
  1979. 'class' => 'iconpickeradd darkBold',
  1980. ),12,1,1).'
  1981. '.buildField(array(
  1982. 'type' => 'text',
  1983. 'id' => 'tab-'.$data['id'].'-ping_url',
  1984. 'name' => 'ping_url['.$data['id'].']',
  1985. 'placeholder' => 'host:port',
  1986. 'labelTranslate' => 'PING_URL',
  1987. 'value' => $data['ping_url'],
  1988. 'class' => 'darkBold',
  1989. ),12,2,1).'
  1990. '.buildField(array(
  1991. 'type' => 'radio',
  1992. 'labelTranslate' => 'DEFAULT',
  1993. 'name' => 'defaultz['.$data['id'].']',
  1994. 'value' => $data['defaultz'],
  1995. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1996. ),12,1,1).'
  1997. '.buildField(array(
  1998. 'type' => 'button',
  1999. 'icon' => 'chevron-down',
  2000. 'buttonType' => 'success',
  2001. 'labelTranslate' => 'MORE',
  2002. 'onclick' => "$(this).parent().parent().parent().find('.slideInUp').toggle()",
  2003. 'class' => 'toggleTabExtra',
  2004. ),12,1,1).'
  2005. '.buildField(array(
  2006. 'type' => 'button',
  2007. 'icon' => 'trash',
  2008. 'buttonType' => 'danger',
  2009. 'labelTranslate' => 'REMOVE',
  2010. 'onclick' => "$(this).parents('li').remove();",
  2011. ),12,1,1).'</div><div id = "tab-'.$data['id'].'-row" class = "row animated slideInUp" style = "display:none;" ><div></div>
  2012. '.buildField(array(
  2013. 'type' => 'checkbox',
  2014. 'labelTranslate' => 'ACTIVE',
  2015. 'name' => 'active['.$data['id'].']',
  2016. 'value' => $data['active'],
  2017. ),12,1,1).'
  2018. '.buildField(array(
  2019. 'type' => 'checkbox',
  2020. 'labelTranslate' => 'USER',
  2021. 'colour' => 'primary',
  2022. 'name' => 'user['.$data['id'].']',
  2023. 'value' => $data['user'],
  2024. ),12,1,1).'
  2025. '.buildField(array(
  2026. 'type' => 'checkbox',
  2027. 'labelTranslate' => 'GUEST',
  2028. 'colour' => 'warning',
  2029. 'name' => 'guest['.$data['id'].']',
  2030. 'value' => $data['guest'],
  2031. ),12,1,1).'
  2032. '.buildField(array(
  2033. 'type' => 'checkbox',
  2034. 'labelTranslate' => 'NO_IFRAME',
  2035. 'colour' => 'danger',
  2036. 'name' => 'window['.$data['id'].']',
  2037. 'value' => $data['window'],
  2038. ),12,1,1).'
  2039. '.buildField(array(
  2040. 'type' => 'checkbox',
  2041. 'labelTranslate' => 'SPLASH',
  2042. 'colour' => 'success',
  2043. 'name' => 'splash['.$data['id'].']',
  2044. 'value' => $data['splash'],
  2045. ),12,1,1).'
  2046. '.buildField(array(
  2047. 'type' => 'checkbox',
  2048. 'labelTranslate' => 'PING',
  2049. 'colour' => 'success',
  2050. 'name' => 'ping['.$data['id'].']',
  2051. 'value' => $data['ping'],
  2052. ),12,1,1).'
  2053. </div>
  2054. </tab>
  2055. </li>
  2056. ';
  2057. return $output;
  2058. }
  2059. // Timezone array
  2060. function timezoneOptions() {
  2061. $output = array();
  2062. $timezones = array();
  2063. $regions = array(
  2064. 'Africa' => DateTimeZone::AFRICA,
  2065. 'America' => DateTimeZone::AMERICA,
  2066. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2067. 'Arctic' => DateTimeZone::ARCTIC,
  2068. 'Asia' => DateTimeZone::ASIA,
  2069. 'Atlantic' => DateTimeZone::ATLANTIC,
  2070. 'Australia' => DateTimeZone::AUSTRALIA,
  2071. 'Europe' => DateTimeZone::EUROPE,
  2072. 'Indian' => DateTimeZone::INDIAN,
  2073. 'Pacific' => DateTimeZone::PACIFIC
  2074. );
  2075. foreach ($regions as $name => $mask) {
  2076. $zones = DateTimeZone::listIdentifiers($mask);
  2077. foreach($zones as $timezone) {
  2078. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2079. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2080. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  2081. }
  2082. }
  2083. return $output;
  2084. }
  2085. // Build Database
  2086. function createSQLiteDB($path = false) {
  2087. if ($path === false) {
  2088. if (DATABASE_LOCATION){
  2089. $path = DATABASE_LOCATION;
  2090. } else {
  2091. debug_out('No Path Specified!');
  2092. }
  2093. }
  2094. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  2095. if (!isset($GLOBALS['file_db'])) {
  2096. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  2097. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2098. }
  2099. // Create Users
  2100. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  2101. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2102. `username` TEXT UNIQUE,
  2103. `password` TEXT,
  2104. `email` TEXT,
  2105. `token` TEXT,
  2106. `role` TEXT,
  2107. `active` TEXT,
  2108. `last` TEXT,
  2109. `auth_service` TEXT DEFAULT \'internal\'
  2110. );');
  2111. // Create Tabs
  2112. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  2113. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2114. `order` INTEGER,
  2115. `users_id` INTEGER,
  2116. `name` TEXT,
  2117. `url` TEXT,
  2118. `defaultz` TEXT,
  2119. `active` TEXT,
  2120. `user` TEXT,
  2121. `guest` TEXT,
  2122. `icon` TEXT,
  2123. `iconurl` TEXT,
  2124. `window` TEXT,
  2125. `splash` TEXT,
  2126. `ping` TEXT,
  2127. `ping_url` TEXT
  2128. );');
  2129. // Create Options
  2130. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  2131. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2132. `users_id` INTEGER UNIQUE,
  2133. `title` TEXT UNIQUE,
  2134. `topbar` TEXT,
  2135. `bottombar` TEXT,
  2136. `sidebar` TEXT,
  2137. `hoverbg` TEXT,
  2138. `topbartext` TEXT,
  2139. `activetabBG` TEXT,
  2140. `activetabicon` TEXT,
  2141. `activetabtext` TEXT,
  2142. `inactiveicon` TEXT,
  2143. `inactivetext` TEXT,
  2144. `loading` TEXT,
  2145. `hovertext` TEXT
  2146. );');
  2147. // Create Invites
  2148. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  2149. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2150. `code` TEXT UNIQUE,
  2151. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  2152. `email` TEXT,
  2153. `username` TEXT,
  2154. `dateused` TIMESTAMP,
  2155. `usedby` TEXT,
  2156. `ip` TEXT,
  2157. `valid` TEXT
  2158. );');
  2159. writeLog("success", "database created/saved");
  2160. return $users && $tabs && $options && $invites;
  2161. } else {
  2162. writeLog("error", "database was unable to be created/saved");
  2163. return false;
  2164. }
  2165. }
  2166. // Upgrade Database
  2167. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  2168. if (!$db_path) {
  2169. if (defined('DATABASE_LOCATION')) {
  2170. $db_path = DATABASE_LOCATION;
  2171. } else {
  2172. debug_out('No Path Specified',1);
  2173. }
  2174. }
  2175. if (!isset($GLOBALS['file_db'])) {
  2176. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  2177. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2178. }
  2179. // Cache current DB
  2180. $cache = array();
  2181. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  2182. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  2183. foreach($row as $k => $v) {
  2184. if (is_string($k)) {
  2185. $cache[$table['name']][$key][$k] = $v;
  2186. }
  2187. }
  2188. }
  2189. }
  2190. // Remove Current Database
  2191. $GLOBALS['file_db'] = null;
  2192. $pathDigest = pathinfo($db_path.'users.db');
  2193. if (file_exists($db_path.'users.db')) {
  2194. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  2195. }
  2196. // Create New Database
  2197. $success = createSQLiteDB($db_path);
  2198. // Restore Items
  2199. if ($success) {
  2200. foreach($cache as $table => $tableData) {
  2201. if ($tableData) {
  2202. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  2203. $insertValues = array();
  2204. reset($tableData);
  2205. foreach($tableData as $key => $value) {
  2206. $insertValues[] = '('.implode(',',array_map(function($d) {
  2207. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  2208. }, $value)).')';
  2209. }
  2210. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  2211. }
  2212. }
  2213. writeLog("success", "database values have been updated");
  2214. return true;
  2215. } else {
  2216. writeLog("error", "database values unable to be updated");
  2217. return false;
  2218. }
  2219. }
  2220. // Commit colours to database
  2221. function updateDBOptions($values) {
  2222. if (!isset($GLOBALS['file_db'])) {
  2223. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2224. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2225. }
  2226. // Commit new values to database
  2227. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  2228. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  2229. }, $values, array_keys($values))).';')->rowCount()) {
  2230. return true;
  2231. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  2232. writeLog("success", "database values for options table have been updated");
  2233. return true;
  2234. } else {
  2235. writeLog("error", "database values for options table unable to be updated");
  2236. return false;
  2237. }
  2238. }
  2239. // Send AJAX notification
  2240. function sendNotification($success, $message = false, $send = true) {
  2241. $notifyExplode = explode("-", NOTIFYEFFECT);
  2242. if ($success) {
  2243. $msg = array(
  2244. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  2245. 'icon' => 'floppy-o',
  2246. 'type' => 'success',
  2247. 'length' => '5000',
  2248. 'layout' => $notifyExplode[0],
  2249. 'effect' => $notifyExplode[1],
  2250. );
  2251. } else {
  2252. $msg = array(
  2253. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2254. 'icon' => 'floppy-o',
  2255. 'type' => 'failed',
  2256. 'length' => '5000',
  2257. 'layout' => $notifyExplode[0],
  2258. 'effect' => $notifyExplode[1],
  2259. );
  2260. }
  2261. // Send and kill script?
  2262. if ($send) {
  2263. header('Content-Type: application/json');
  2264. echo json_encode(array('notify'=>$msg));
  2265. die();
  2266. }
  2267. return $msg;
  2268. }
  2269. // Load colours from the database
  2270. function loadAppearance() {
  2271. // Defaults
  2272. $defaults = array(
  2273. 'title' => 'Organizr',
  2274. 'topbartext' => '#66D9EF',
  2275. 'topbar' => '#333333',
  2276. 'bottombar' => '#333333',
  2277. 'sidebar' => '#393939',
  2278. 'hoverbg' => '#AD80FD',
  2279. 'activetabBG' => '#F92671',
  2280. 'activetabicon' => '#FFFFFF',
  2281. 'activetabtext' => '#FFFFFF',
  2282. 'inactiveicon' => '#66D9EF',
  2283. 'inactivetext' => '#66D9EF',
  2284. 'loading' => '#66D9EF',
  2285. 'hovertext' => '#000000',
  2286. );
  2287. if (DATABASE_LOCATION) {
  2288. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2289. if (!isset($GLOBALS['file_db'])) {
  2290. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2291. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2292. }
  2293. // Database Lookup
  2294. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2295. // Replace defaults with filled options
  2296. foreach($options as $row) {
  2297. foreach($defaults as $key => $value) {
  2298. if (isset($row[$key]) && $row[$key]) {
  2299. $defaults[$key] = $row[$key];
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. // Return the Results
  2306. return $defaults;
  2307. }
  2308. // Delete Database
  2309. function deleteDatabase() {
  2310. unset($_COOKIE['Organizr']);
  2311. setcookie('Organizr', '', time() - 3600, '/');
  2312. unset($_COOKIE['OrganizrU']);
  2313. setcookie('OrganizrU', '', time() - 3600, '/');
  2314. $GLOBALS['file_db'] = null;
  2315. unlink(DATABASE_LOCATION.'users.db');
  2316. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2317. if(is_dir($file)) {
  2318. rmdir($file);
  2319. } elseif (!is_dir($file)) {
  2320. unlink($file);
  2321. }
  2322. }
  2323. rmdir($userdirpath);
  2324. writeLog("success", "database has been deleted");
  2325. return true;
  2326. }
  2327. // Upgrade the installation
  2328. function upgradeInstall($branch = 'master') {
  2329. function downloadFile($url, $path){
  2330. ini_set('max_execution_time',0);
  2331. $folderPath = "upgrade/";
  2332. if(!mkdir($folderPath)){
  2333. writeLog("error", "organizr could not create upgrade folder");
  2334. }
  2335. $newfname = $folderPath . $path;
  2336. $file = fopen ($url, 'rb');
  2337. if ($file) {
  2338. $newf = fopen ($newfname, 'wb');
  2339. if ($newf) {
  2340. while(!feof($file)) {
  2341. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2342. }
  2343. }
  2344. }else{
  2345. writeLog("error", "organizr could not download $url");
  2346. }
  2347. if ($file) {
  2348. fclose($file);
  2349. writeLog("success", "organizr finished downloading the github zip file");
  2350. }else{
  2351. writeLog("error", "organizr could not download the github zip file");
  2352. }
  2353. if ($newf) {
  2354. fclose($newf);
  2355. writeLog("success", "organizr created upgrade zip file from github zip file");
  2356. }else{
  2357. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2358. }
  2359. }
  2360. function unzipFile($zipFile){
  2361. $zip = new ZipArchive;
  2362. $extractPath = "upgrade/";
  2363. if($zip->open($extractPath . $zipFile) != "true"){
  2364. writeLog("error", "organizr could not unzip upgrade.zip");
  2365. }else{
  2366. writeLog("success", "organizr unzipped upgrade.zip");
  2367. }
  2368. /* Extract Zip File */
  2369. $zip->extractTo($extractPath);
  2370. $zip->close();
  2371. }
  2372. // Function to remove folders and files
  2373. function rrmdir($dir) {
  2374. if (is_dir($dir)) {
  2375. $files = scandir($dir);
  2376. foreach ($files as $file)
  2377. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2378. rmdir($dir);
  2379. }
  2380. else if (file_exists($dir)) unlink($dir);
  2381. }
  2382. // Function to Copy folders and files
  2383. function rcopy($src, $dst) {
  2384. if (is_dir ( $src )) {
  2385. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2386. $files = scandir ( $src );
  2387. foreach ( $files as $file )
  2388. if ($file != "." && $file != "..")
  2389. rcopy ( "$src/$file", "$dst/$file" );
  2390. } else if (file_exists ( $src ))
  2391. copy ( $src, $dst );
  2392. }
  2393. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2394. $file = "upgrade.zip";
  2395. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2396. $cleanup = __DIR__ . "/upgrade/";
  2397. $destination = __DIR__ . "/";
  2398. writeLog("success", "starting organizr upgrade process");
  2399. downloadFile($url, $file);
  2400. unzipFile($file);
  2401. rcopy($source, $destination);
  2402. writeLog("success", "new organizr files copied");
  2403. rrmdir($cleanup);
  2404. writeLog("success", "organizr upgrade folder removed");
  2405. writeLog("success", "organizr has been updated");
  2406. return true;
  2407. }
  2408. // NzbGET Items
  2409. function nzbgetConnect($list = 'listgroups') {
  2410. $url = qualifyURL(NZBGETURL);
  2411. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2412. $api = json_decode($api, true);
  2413. $gotNZB = array();
  2414. if (is_array($api) || is_object($api)){
  2415. foreach ($api['result'] AS $child) {
  2416. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2417. $downloadStatus = $child['Status'];
  2418. $downloadCategory = $child['Category'];
  2419. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2420. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2421. if($child['Health'] <= "750"){
  2422. $downloadHealth = "danger";
  2423. }elseif($child['Health'] <= "900"){
  2424. $downloadHealth = "warning";
  2425. }elseif($child['Health'] <= "1000"){
  2426. $downloadHealth = "success";
  2427. }
  2428. $gotNZB[] = '<tr>
  2429. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2430. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2431. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2432. <td class="col-xs-1 nzbtable nzbtable-row">'.realSize(($child['FileSizeMB']*1024)*1024).'</td>
  2433. <td class="col-xs-2 nzbtable nzbtable-row">
  2434. <div class="progress">
  2435. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2436. <p class="text-center">'.round($downloadPercent).'%</p>
  2437. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2438. </div>
  2439. </div>
  2440. </td>
  2441. </tr>';
  2442. }
  2443. if ($gotNZB) {
  2444. return implode('',$gotNZB);
  2445. } else {
  2446. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2447. }
  2448. }else{
  2449. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Username and Password - if HTTPS, is cert valid");
  2450. }
  2451. }
  2452. // Sabnzbd Items
  2453. function sabnzbdConnect($list = 'queue') {
  2454. $url = qualifyURL(SABNZBDURL);
  2455. $api = @file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2456. $api = json_decode($api, true);
  2457. $gotNZB = array();
  2458. if (is_array($api) || is_object($api)){
  2459. foreach ($api[$list]['slots'] AS $child) {
  2460. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2461. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2462. $downloadStatus = $child['status'];
  2463. $gotNZB[] = '<tr>
  2464. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2465. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2466. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2467. <td class="col-xs-1 nzbtable nzbtable-row">'.$child['size'].'</td>
  2468. <td class="col-xs-2 nzbtable nzbtable-row">
  2469. <div class="progress">
  2470. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2471. <p class="text-center">'.round($downloadPercent).'%</p>
  2472. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2473. </div>
  2474. </div>
  2475. </td>
  2476. </tr>';
  2477. }
  2478. if ($gotNZB) {
  2479. return implode('',$gotNZB);
  2480. } else {
  2481. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2482. }
  2483. }else{
  2484. writeLog("error", "SABNZBD ERROR: could not connect - check URL and/or check token - if HTTPS, is cert valid");
  2485. }
  2486. }
  2487. // Apply new tab settings
  2488. function updateTabs($tabs) {
  2489. if (!isset($GLOBALS['file_db'])) {
  2490. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2491. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2492. }
  2493. // Validate
  2494. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2495. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2496. // Clear Existing Tabs
  2497. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2498. // Process New Tabs
  2499. $totalValid = 0;
  2500. foreach ($tabs['name'] as $key => $value) {
  2501. // Qualify
  2502. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2503. $totalValid++;
  2504. $fields = array();
  2505. foreach(array('id','name','url','icon','iconurl','order','ping_url') as $v) {
  2506. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2507. }
  2508. foreach(array('active','user','guest','defaultz','window','splash','ping') as $v) {
  2509. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2510. }
  2511. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2512. }
  2513. writeLog("success", "tabs successfully saved");
  2514. return $totalValid;
  2515. } else {
  2516. writeLog("error", "tabs could not save");
  2517. return false;
  2518. }
  2519. writeLog("error", "tabs could not save");
  2520. return false;
  2521. }
  2522. // ==============
  2523. function clean($strin) {
  2524. $strout = null;
  2525. for ($i = 0; $i < strlen($strin); $i++) {
  2526. $ord = ord($strin[$i]);
  2527. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2528. $strout .= "&amp;#{$ord};";
  2529. }
  2530. else {
  2531. switch ($strin[$i]) {
  2532. case '<':
  2533. $strout .= '&lt;';
  2534. break;
  2535. case '>':
  2536. $strout .= '&gt;';
  2537. break;
  2538. case '&':
  2539. $strout .= '&amp;';
  2540. break;
  2541. case '"':
  2542. $strout .= '&quot;';
  2543. break;
  2544. default:
  2545. $strout .= $strin[$i];
  2546. }
  2547. }
  2548. }
  2549. return $strout;
  2550. }
  2551. function registration_callback($username, $email, $userdir){
  2552. global $data;
  2553. $data = array($username, $email, $userdir);
  2554. }
  2555. function printArray($arrayName){
  2556. $messageCount = count($arrayName);
  2557. $i = 0;
  2558. foreach ( $arrayName as $item ) :
  2559. $i++;
  2560. if($i < $messageCount) :
  2561. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2562. elseif($i = $messageCount) :
  2563. echo "<small class='text-uppercase'>" . $item . "</small>";
  2564. endif;
  2565. endforeach;
  2566. }
  2567. function write_ini_file($content, $path) {
  2568. if (!$handle = fopen($path, 'w')) {
  2569. return false;
  2570. }
  2571. $success = fwrite($handle, trim($content));
  2572. fclose($handle);
  2573. return $success;
  2574. }
  2575. function gotTimezone(){
  2576. $regions = array(
  2577. 'Africa' => DateTimeZone::AFRICA,
  2578. 'America' => DateTimeZone::AMERICA,
  2579. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2580. 'Arctic' => DateTimeZone::ARCTIC,
  2581. 'Asia' => DateTimeZone::ASIA,
  2582. 'Atlantic' => DateTimeZone::ATLANTIC,
  2583. 'Australia' => DateTimeZone::AUSTRALIA,
  2584. 'Europe' => DateTimeZone::EUROPE,
  2585. 'Indian' => DateTimeZone::INDIAN,
  2586. 'Pacific' => DateTimeZone::PACIFIC
  2587. );
  2588. $timezones = array();
  2589. foreach ($regions as $name => $mask) {
  2590. $zones = DateTimeZone::listIdentifiers($mask);
  2591. foreach($zones as $timezone) {
  2592. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2593. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2594. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2595. }
  2596. }
  2597. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2598. foreach($timezones as $region => $list) {
  2599. print '<optgroup label="' . $region . '">' . "\n";
  2600. foreach($list as $timezone => $name) {
  2601. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2602. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2603. }
  2604. print '</optgroup>' . "\n";
  2605. }
  2606. print '</select>';
  2607. }
  2608. function getTimezone(){
  2609. $regions = array(
  2610. 'Africa' => DateTimeZone::AFRICA,
  2611. 'America' => DateTimeZone::AMERICA,
  2612. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2613. 'Arctic' => DateTimeZone::ARCTIC,
  2614. 'Asia' => DateTimeZone::ASIA,
  2615. 'Atlantic' => DateTimeZone::ATLANTIC,
  2616. 'Australia' => DateTimeZone::AUSTRALIA,
  2617. 'Europe' => DateTimeZone::EUROPE,
  2618. 'Indian' => DateTimeZone::INDIAN,
  2619. 'Pacific' => DateTimeZone::PACIFIC
  2620. );
  2621. $timezones = array();
  2622. foreach ($regions as $name => $mask) {
  2623. $zones = DateTimeZone::listIdentifiers($mask);
  2624. foreach($zones as $timezone) {
  2625. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2626. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2627. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2628. }
  2629. }
  2630. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2631. foreach($timezones as $region => $list) {
  2632. print '<optgroup label="' . $region . '">' . "\n";
  2633. foreach($list as $timezone => $name) {
  2634. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2635. }
  2636. print '</optgroup>' . "\n";
  2637. }
  2638. print '</select>';
  2639. }
  2640. function explosion($string, $position){
  2641. $getWord = explode("|", $string);
  2642. return $getWord[$position];
  2643. }
  2644. function getServerPath() {
  2645. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2646. $protocol = "https://";
  2647. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2648. $protocol = "https://";
  2649. } else {
  2650. $protocol = "http://";
  2651. }
  2652. $domain = '';
  2653. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2654. $domain = $_SERVER['SERVER_NAME'];
  2655. }elseif(isset($_SERVER['HTTP_HOST'])){
  2656. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2657. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2658. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2659. if ($port == "80" || $port == "443"){
  2660. $domain = $domain;
  2661. }else{
  2662. $domain = $_SERVER['HTTP_HOST'];
  2663. }
  2664. }else{
  2665. $domain = $_SERVER['HTTP_HOST'];
  2666. }
  2667. }
  2668. return $protocol . $domain . str_replace("\\", "/", dirname($_SERVER['REQUEST_URI']));
  2669. }
  2670. function get_browser_name() {
  2671. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2672. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2673. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2674. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2675. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2676. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2677. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2678. return 'Other';
  2679. }
  2680. function getSickrageCalendarWanted($array){
  2681. $array = json_decode($array, true);
  2682. //$gotCalendar = "";
  2683. $gotCalendar = array();
  2684. $i = 0;
  2685. foreach($array['data']['missed'] AS $child) {
  2686. $i++;
  2687. $seriesName = $child['show_name'];
  2688. $episodeID = $child['tvdbid'];
  2689. $episodeAirDate = $child['airdate'];
  2690. $episodeAirDateTime = explode(" ",$child['airs']);
  2691. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2692. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2693. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2694. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2695. $downloaded = "0";
  2696. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2697. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2698. array_push($gotCalendar, array(
  2699. "id" => "Sick-Miss-".$i,
  2700. "title" => $seriesName,
  2701. "start" => $episodeAirDate,
  2702. "className" => $downloaded." tvID--".$episodeID,
  2703. "imagetype" => "tv",
  2704. ));
  2705. }
  2706. foreach($array['data']['today'] AS $child) {
  2707. $i++;
  2708. $seriesName = $child['show_name'];
  2709. $episodeID = $child['tvdbid'];
  2710. $episodeAirDate = $child['airdate'];
  2711. $episodeAirDateTime = explode(" ",$child['airs']);
  2712. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2713. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2714. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2715. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2716. $downloaded = "0";
  2717. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2718. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2719. array_push($gotCalendar, array(
  2720. "id" => "Sick-Today-".$i,
  2721. "title" => $seriesName,
  2722. "start" => $episodeAirDate,
  2723. "className" => $downloaded." tvID--".$episodeID,
  2724. "imagetype" => "tv",
  2725. ));
  2726. }
  2727. foreach($array['data']['soon'] AS $child) {
  2728. $i++;
  2729. $seriesName = $child['show_name'];
  2730. $episodeID = $child['tvdbid'];
  2731. $episodeAirDate = $child['airdate'];
  2732. $episodeAirDateTime = explode(" ",$child['airs']);
  2733. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2734. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2735. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2736. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2737. $downloaded = "0";
  2738. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2739. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2740. array_push($gotCalendar, array(
  2741. "id" => "Sick-Soon-".$i,
  2742. "title" => $seriesName,
  2743. "start" => $episodeAirDate,
  2744. "className" => $downloaded." tvID--".$episodeID,
  2745. "imagetype" => "tv",
  2746. ));
  2747. }
  2748. foreach($array['data']['later'] AS $child) {
  2749. $i++;
  2750. $seriesName = $child['show_name'];
  2751. $episodeID = $child['tvdbid'];
  2752. $episodeAirDate = $child['airdate'];
  2753. $episodeAirDateTime = explode(" ",$child['airs']);
  2754. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2755. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2756. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2757. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2758. $downloaded = "0";
  2759. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2760. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2761. array_push($gotCalendar, array(
  2762. "id" => "Sick-Later-".$i,
  2763. "title" => $seriesName,
  2764. "start" => $episodeAirDate,
  2765. "className" => $downloaded." tvID--".$episodeID,
  2766. "imagetype" => "tv",
  2767. ));
  2768. }
  2769. if ($i != 0){ return $gotCalendar; }
  2770. }
  2771. function getSickrageCalendarHistory($array){
  2772. $array = json_decode($array, true);
  2773. //$gotCalendar = "";
  2774. $gotCalendar = array();
  2775. $i = 0;
  2776. foreach($array['data'] AS $child) {
  2777. $i++;
  2778. $seriesName = $child['show_name'];
  2779. $episodeID = $child['tvdbid'];
  2780. $episodeAirDate = $child['date'];
  2781. $downloaded = "green-bg";
  2782. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2783. array_push($gotCalendar, array(
  2784. "id" => "Sick-History-".$i,
  2785. "title" => $seriesName,
  2786. "start" => $episodeAirDate,
  2787. "className" => $downloaded." tvID--".$episodeID,
  2788. "imagetype" => "tv",
  2789. ));
  2790. }
  2791. if ($i != 0){ return $gotCalendar; }
  2792. }
  2793. function getSonarrCalendar($array){
  2794. $array = json_decode($array, true);
  2795. //$gotCalendar = "";
  2796. $gotCalendar = array();
  2797. $i = 0;
  2798. foreach($array AS $child) {
  2799. $i++;
  2800. $seriesName = $child['series']['title'];
  2801. $episodeID = $child['series']['tvdbId'];
  2802. if(!isset($episodeID)){ $episodeID = ""; }
  2803. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2804. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2805. $episodeAirDate = $child['airDateUtc'];
  2806. $episodeAirDate = strtotime($episodeAirDate);
  2807. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2808. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2809. $downloaded = $child['hasFile'];
  2810. 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"; }
  2811. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2812. array_push($gotCalendar, array(
  2813. "id" => "Sonarr-".$i,
  2814. "title" => $seriesName,
  2815. "start" => $episodeAirDate,
  2816. "className" => $downloaded." tvID--".$episodeID,
  2817. "imagetype" => "tv",
  2818. ));
  2819. }
  2820. if ($i != 0){ return $gotCalendar; }
  2821. }
  2822. function getCouchCalendar(){
  2823. $url = qualifyURL(COUCHURL);
  2824. $api = curl_get($url."/api/".COUCHAPI."/media.list");
  2825. $api = json_decode($api, true);
  2826. $i = 0;
  2827. $gotCalendar = array();
  2828. if (is_array($api) || is_object($api)){
  2829. foreach($api['movies'] AS $child) {
  2830. if($child['status'] == "active" || $child['status'] == "done" ){
  2831. $i++;
  2832. $movieName = $child['info']['original_title'];
  2833. $movieID = $child['info']['tmdb_id'];
  2834. if(!isset($movieID)){ $movieID = ""; }
  2835. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  2836. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  2837. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  2838. $physicalRelease = strtotime($physicalRelease);
  2839. $physicalRelease = date("Y-m-d", $physicalRelease);
  2840. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2841. $downloaded = ($child['status'] == "active") ? "0" : "1";
  2842. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2843. array_push($gotCalendar, array(
  2844. "id" => "CouchPotato-".$i,
  2845. "title" => $movieName,
  2846. "start" => $physicalRelease,
  2847. "className" => $downloaded." movieID--".$movieID,
  2848. "imagetype" => "film",
  2849. ));
  2850. }
  2851. }
  2852. if ($i != 0){ return $gotCalendar; }
  2853. }else{
  2854. writeLog("error", "CouchPotato ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2855. }
  2856. }
  2857. function getRadarrCalendar($array){
  2858. $array = json_decode($array, true);
  2859. $gotCalendar = array();
  2860. $i = 0;
  2861. foreach($array AS $child) {
  2862. if(isset($child['physicalRelease'])){
  2863. $i++;
  2864. $movieName = $child['title'];
  2865. $movieID = $child['tmdbId'];
  2866. if(!isset($movieID)){ $movieID = ""; }
  2867. $physicalRelease = $child['physicalRelease'];
  2868. $physicalRelease = strtotime($physicalRelease);
  2869. $physicalRelease = date("Y-m-d", $physicalRelease);
  2870. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2871. $downloaded = $child['hasFile'];
  2872. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2873. array_push($gotCalendar, array(
  2874. "id" => "Radarr-".$i,
  2875. "title" => $movieName,
  2876. "start" => $physicalRelease,
  2877. "className" => $downloaded." movieID--".$movieID,
  2878. "imagetype" => "film",
  2879. ));
  2880. }
  2881. }
  2882. if ($i != 0){ return $gotCalendar; }
  2883. }
  2884. function getHeadphonesCalendar($url, $key, $list){
  2885. $url = qualifyURL(HEADPHONESURL);
  2886. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2887. $api = json_decode($api, true);
  2888. $i = 0;
  2889. //$gotCalendar = "";
  2890. $gotCalendar = array();;
  2891. if (is_array($api) || is_object($api)){
  2892. foreach($api AS $child) {
  2893. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2894. $i++;
  2895. $albumName = addslashes($child['AlbumTitle']);
  2896. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2897. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2898. $albumID = $child['AlbumID'];
  2899. $albumDate = strtotime($albumDate);
  2900. $albumDate = date("Y-m-d", $albumDate);
  2901. $albumStatus = $child['Status'];
  2902. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2903. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2904. //$gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2905. array_push($gotCalendar, array(
  2906. "id" => "Headphones-".$i,
  2907. "title" => $albumArtist.' - '.$albumName,
  2908. "start" => $albumDate,
  2909. "className" => $albumStatusColor,
  2910. "imagetype" => "music",
  2911. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2912. ));
  2913. }
  2914. if($child['Status'] == "Processed" && $list == "getHistory"){
  2915. $i++;
  2916. $find = array('_','[', ']', '\n');
  2917. $replace = array(' ','(', ')', ' ');
  2918. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  2919. $albumDate = $child['DateAdded'];
  2920. $albumID = $child['AlbumID'];
  2921. $albumDate = strtotime($albumDate);
  2922. $albumDate = date("Y-m-d", $albumDate);
  2923. $albumStatusColor = "green-bg";
  2924. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2925. //$gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2926. array_push($gotCalendar, array(
  2927. "id" => "Headphones-".$i,
  2928. "title" => $albumName,
  2929. "start" => $albumDate,
  2930. "className" => $albumStatusColor,
  2931. "imagetype" => "music",
  2932. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2933. ));
  2934. }
  2935. }
  2936. if ($i != 0){ return $gotCalendar; }
  2937. }else{
  2938. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2939. }
  2940. }
  2941. function checkRootPath($string){
  2942. if($string == "\\" || $string == "/"){
  2943. return "/";
  2944. }else{
  2945. return str_replace("\\", "/", $string) . "/";
  2946. }
  2947. }
  2948. function strip($string){
  2949. $string = strip_tags($string);
  2950. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  2951. }
  2952. function writeLog($type, $message){
  2953. if(file_exists(DATABASE_LOCATION."org.log")){
  2954. if(filesize(DATABASE_LOCATION."org.log") > 500000){
  2955. rename(DATABASE_LOCATION.'org.log',DATABASE_LOCATION.'org['.date('Y-m-d').'].log');
  2956. $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";
  2957. file_put_contents(DATABASE_LOCATION."org.log", $message2, FILE_APPEND | LOCK_EX);
  2958. }
  2959. }
  2960. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  2961. file_put_contents(DATABASE_LOCATION."org.log", $message, FILE_APPEND | LOCK_EX);
  2962. }
  2963. function readLog(){
  2964. $log = file(DATABASE_LOCATION."org.log",FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  2965. $log = array_reverse($log);
  2966. foreach($log as $line){
  2967. if(substr_count($line, '|') == 2){
  2968. $line = explode("|", strip($line));
  2969. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  2970. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  2971. }
  2972. }
  2973. }
  2974. function buildStream($array){
  2975. $result = "";
  2976. if (array_key_exists('platform', $array)) {
  2977. $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>';
  2978. }
  2979. if (array_key_exists('device', $array)) {
  2980. $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>';
  2981. }
  2982. if (array_key_exists('stream', $array)) {
  2983. $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>';
  2984. }
  2985. if (array_key_exists('video', $array)) {
  2986. $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>';
  2987. }
  2988. if (array_key_exists('audio', $array)) {
  2989. $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>';
  2990. }
  2991. return $result;
  2992. }
  2993. function streamType($value){
  2994. if($value == "transcode" || $value == "Transcode"){
  2995. return "Transcode";
  2996. }elseif($value == "copy" || $value == "DirectStream"){
  2997. return "Direct Stream";
  2998. }elseif($value == "directplay" || $value == "DirectPlay"){
  2999. return "Direct Play";
  3000. }else{
  3001. return "Direct Play";
  3002. }
  3003. }
  3004. function getPlatform($platform){
  3005. $allPlatforms = array(
  3006. "Chrome" => "chrome.png",
  3007. "tvOS" => "atv.png",
  3008. "iOS" => "ios.png",
  3009. "Xbox One" => "xbox.png",
  3010. "Mystery 4" => "playstation.png",
  3011. "Samsung" => "samsung.png",
  3012. "Roku" => "roku.png",
  3013. "Emby for iOS" => "ios.png",
  3014. "Emby Mobile" => "emby.png",
  3015. "Emby Theater" => "emby.png",
  3016. "Emby Classic" => "emby.png",
  3017. "Safari" => "safari.png",
  3018. "Android" => "android.png",
  3019. "AndroidTv" => "android.png",
  3020. "Chromecast" => "chromecast.png",
  3021. "Dashboard" => "emby.png",
  3022. "Dlna" => "dlna.png",
  3023. "Windows Phone" => "wp.png",
  3024. "Windows RT" => "win8.png",
  3025. "Kodi" => "kodi.png",
  3026. );
  3027. if (array_key_exists($platform, $allPlatforms)) {
  3028. return $allPlatforms[$platform];
  3029. }else{
  3030. return "pmp.png";
  3031. }
  3032. }
  3033. function getServer(){
  3034. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  3035. return $server;
  3036. }
  3037. function prettyPrint($array) {
  3038. echo "<pre>";
  3039. print_r($array);
  3040. echo "</pre>";
  3041. echo "<br/>";
  3042. }
  3043. function checkFrame($array, $url){
  3044. if(array_key_exists("x-frame-options", $array)){
  3045. if($array['x-frame-options'] == "deny"){
  3046. return false;
  3047. }elseif($array['x-frame-options'] == "sameorgin"){
  3048. $digest = parse_url($url);
  3049. $host = (isset($digest['host'])?$digest['host']:'');
  3050. if(getServer() == $host){
  3051. return true;
  3052. }else{
  3053. return false;
  3054. }
  3055. }
  3056. }else{
  3057. if(!$array){
  3058. return false;
  3059. }
  3060. return true;
  3061. }
  3062. }
  3063. function frameTest($url){
  3064. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  3065. $url = qualifyURL($url);
  3066. if(checkFrame($array, $url)){
  3067. return true;
  3068. }else{
  3069. return false;
  3070. }
  3071. }
  3072. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  3073. $notifyExplode = explode("-", NOTIFYEFFECT);
  3074. if ($result) {
  3075. $msg = array(
  3076. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  3077. 'icon' => $icon,
  3078. 'type' => 'success',
  3079. 'length' => '5000',
  3080. 'layout' => $notifyExplode[0],
  3081. 'effect' => $notifyExplode[1],
  3082. );
  3083. } else {
  3084. $msg = array(
  3085. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  3086. 'icon' => $icon,
  3087. 'type' => 'error',
  3088. 'length' => '5000',
  3089. 'layout' => $notifyExplode[0],
  3090. 'effect' => $notifyExplode[1],
  3091. );
  3092. }
  3093. // Send and kill script?
  3094. if ($send) {
  3095. header('Content-Type: application/json');
  3096. echo json_encode(array('notify'=>$msg));
  3097. die();
  3098. }
  3099. return $msg;
  3100. }
  3101. function buildHomepageNotice($layout, $type, $title, $message){
  3102. switch ($layout) {
  3103. case 'elegant':
  3104. return '
  3105. <div id="homepageNotice" class="row">
  3106. <div class="col-lg-12">
  3107. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  3108. <div class="content-title i-block">
  3109. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  3110. <div class="content-tools i-block pull-right">
  3111. <a class="close-btn">
  3112. <i class="fa fa-times"></i>
  3113. </a>
  3114. </div>
  3115. </div>
  3116. '.$message.'
  3117. </div>
  3118. </div>
  3119. </div>
  3120. ';
  3121. break;
  3122. case 'basic':
  3123. return '
  3124. <div id="homepageNotice" class="row">
  3125. <div class="col-lg-12">
  3126. <div class="panel panel-'.$type.'">
  3127. <div class="panel-heading">
  3128. <h3 class="panel-title">'.$title.'</h3>
  3129. </div>
  3130. <div class="panel-body">
  3131. '.$message.'
  3132. </div>
  3133. </div>
  3134. </div>
  3135. </div>
  3136. ';
  3137. break;
  3138. case 'jumbotron';
  3139. return '
  3140. <div id="homepageNotice" class="row">
  3141. <div class="col-lg-12">
  3142. <div class="jumbotron">
  3143. <div class="container">
  3144. <h1>'.$title.'</h1>
  3145. <p>'.$message.'</p>
  3146. </div>
  3147. </div>
  3148. </div>
  3149. </div>
  3150. ';
  3151. }
  3152. }
  3153. function embyArray($array, $type) {
  3154. $key = ($type == "video" ? "Height" : "Channels");
  3155. if (array_key_exists($key, $array)) {
  3156. switch ($type) {
  3157. case "video":
  3158. $codec = $array["Codec"];
  3159. $height = $array["Height"];
  3160. $width = $array["Width"];
  3161. break;
  3162. default:
  3163. $codec = $array["Codec"];
  3164. $channels = $array["Channels"];
  3165. }
  3166. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  3167. }
  3168. foreach ($array as $element) {
  3169. if (is_array($element)) {
  3170. if (embyArray($element, $type)) {
  3171. return embyArray($element, $type);
  3172. }
  3173. }
  3174. }
  3175. }
  3176. // Get Now Playing Streams From Plex
  3177. function searchPlex($query){
  3178. $address = qualifyURL(PLEXURL);
  3179. $openTab = (PLEXTABNAME) ? "true" : "false";
  3180. // Perform API requests
  3181. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  3182. libxml_use_internal_errors(true);
  3183. $api = simplexml_load_string($api);
  3184. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3185. if (!$getServer) { return 'Could not load!'; }
  3186. // Identify the local machine
  3187. $server = $getServer['machineIdentifier'];
  3188. $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>";
  3189. $items = "";
  3190. $albums = $movies = $shows = 0;
  3191. $style = 'style="vertical-align: middle"';
  3192. foreach($api AS $child) {
  3193. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  3194. $time = (string)$child['addedAt'];
  3195. $time = new DateTime("@$time");
  3196. $results = array(
  3197. "title" => (string)$child['title'],
  3198. "image" => (string)$child['thumb'],
  3199. "type" => (string)ucwords($child['type']),
  3200. "year" => (string)$child['year'],
  3201. "key" => (string)$child['ratingKey']."-search",
  3202. "ratingkey" => (string)$child['ratingKey'],
  3203. "genre" => (string)$child->Genre['tag'],
  3204. "added" => $time->format('Y-m-d'),
  3205. "extra" => "",
  3206. );
  3207. switch ($child['type']){
  3208. case "album":
  3209. $push = array(
  3210. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  3211. );
  3212. $results = array_replace($results,$push);
  3213. $albums++;
  3214. break;
  3215. case "movie":
  3216. $push = array(
  3217. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  3218. );
  3219. $results = array_replace($results,$push);
  3220. $movies++;
  3221. break;
  3222. case "show":
  3223. $push = array(
  3224. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  3225. );
  3226. $results = array_replace($results,$push);
  3227. $shows++;
  3228. break;
  3229. }
  3230. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  3231. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  3232. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  3233. }
  3234. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  3235. if (PLEXTABURL) {
  3236. $link = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3237. }else{
  3238. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3239. }
  3240. $items .= '<tr style="cursor: pointer;" class="openTab" extraTitle="'.$results['title'].'" extraType="'.$child['type'].'" openTab="'.$openTab.'" href="'.$link.'">
  3241. <th scope="row"><img src="'.$image_url.'"></th>
  3242. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  3243. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  3244. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  3245. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  3246. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  3247. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  3248. </tr>';
  3249. }
  3250. }
  3251. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  3252. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  3253. font-size: 23px;
  3254. ">&nbsp;'.$movies.'</strong></span>
  3255. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  3256. font-size: 23px;
  3257. ">&nbsp;'.$shows.'</strong></span>
  3258. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  3259. font-size: 23px;
  3260. ">&nbsp;'.$albums.'</strong></span>
  3261. </div>';
  3262. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  3263. }
  3264. function getBannedUsers($string){
  3265. if (strpos($string, ',') !== false) {
  3266. $banned = explode(",", $string);
  3267. }else{
  3268. $banned = array($string);
  3269. }
  3270. return $banned;
  3271. }
  3272. function getWhitelist($string){
  3273. if (strpos($string, ',') !== false) {
  3274. $whitelist = explode(",", $string);
  3275. }else{
  3276. $whitelist = array($string);
  3277. }
  3278. foreach($whitelist as &$ip){
  3279. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  3280. }
  3281. return $whitelist;
  3282. }
  3283. function get_client_ip() {
  3284. $ipaddress = '';
  3285. if (isset($_SERVER['HTTP_CLIENT_IP']))
  3286. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  3287. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  3288. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3289. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  3290. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  3291. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  3292. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  3293. else if(isset($_SERVER['HTTP_FORWARDED']))
  3294. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  3295. else if(isset($_SERVER['REMOTE_ADDR']))
  3296. $ipaddress = $_SERVER['REMOTE_ADDR'];
  3297. else
  3298. $ipaddress = 'UNKNOWN';
  3299. return $ipaddress;
  3300. }
  3301. //EMAIL SHIT
  3302. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  3303. $mail = new PHPMailer;
  3304. $mail->isSMTP();
  3305. $mail->Host = SMTPHOST;
  3306. $mail->SMTPAuth = SMTPHOSTAUTH;
  3307. $mail->Username = SMTPHOSTUSERNAME;
  3308. $mail->Password = SMTPHOSTPASSWORD;
  3309. $mail->SMTPSecure = SMTPHOSTTYPE;
  3310. $mail->Port = SMTPHOSTPORT;
  3311. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3312. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3313. $mail->isHTML(true);
  3314. if($email){
  3315. $mail->addAddress($email, $username);
  3316. }
  3317. if($cc){
  3318. $mail->addCC($cc);
  3319. }
  3320. if($bcc){
  3321. if(strpos($bcc , ',') === false){
  3322. $mail->addBCC($bcc);
  3323. }else{
  3324. $allEmails = explode(",",$bcc);
  3325. foreach($allEmails as $gotEmail){
  3326. $mail->addBCC($gotEmail);
  3327. }
  3328. }
  3329. }
  3330. $mail->Subject = $subject;
  3331. $mail->Body = $body;
  3332. //$mail->send();
  3333. if(!$mail->send()) {
  3334. writeLog("error", "mail failed to send");
  3335. } else {
  3336. writeLog("success", "mail has been sent");
  3337. }
  3338. }
  3339. //EMAIL SHIT
  3340. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  3341. $mail = new PHPMailer;
  3342. $mail->isSMTP();
  3343. $mail->Host = $host;
  3344. $mail->SMTPAuth = $auth;
  3345. $mail->Username = $username;
  3346. $mail->Password = $password;
  3347. $mail->SMTPSecure = $type;
  3348. $mail->Port = $port;
  3349. $mail->setFrom($from, $sendername);
  3350. $mail->addReplyTo($from, $sendername);
  3351. $mail->isHTML(true);
  3352. $mail->addAddress($to, "Organizr Admin");
  3353. $mail->Subject = "Organizr Test E-Mail";
  3354. $mail->Body = "This was just a test!";
  3355. //$mail->send();
  3356. if(!$mail->send()) {
  3357. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  3358. return false;
  3359. } else {
  3360. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  3361. return true;
  3362. }
  3363. }
  3364. function libraryList(){
  3365. $address = qualifyURL(PLEXURL);
  3366. $headers = array(
  3367. "Accept" => "application/json",
  3368. "X-Plex-Token" => PLEXTOKEN
  3369. );
  3370. libxml_use_internal_errors(true);
  3371. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3372. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3373. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  3374. $libraryList = array();
  3375. foreach($api->SharedServer->Section AS $child) {
  3376. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  3377. }
  3378. foreach($api->SharedServer AS $child) {
  3379. if(!empty($child['username'])){
  3380. $username = (string)strtolower($child['username']);
  3381. $email = (string)strtolower($child['email']);
  3382. $libraryList['users'][$username] = (string)$child['id'];
  3383. $libraryList['emails'][$email] = (string)$child['id'];
  3384. $libraryList['both'][$username] = $email;
  3385. }
  3386. }
  3387. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3388. }
  3389. function plexUserShare($username){
  3390. $address = qualifyURL(PLEXURL);
  3391. $headers = array(
  3392. "Accept" => "application/json",
  3393. "Content-Type" => "application/json",
  3394. "X-Plex-Token" => PLEXTOKEN
  3395. );
  3396. libxml_use_internal_errors(true);
  3397. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3398. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3399. $json = array(
  3400. "server_id" => $gotServer,
  3401. "shared_server" => array(
  3402. //"library_section_ids" => "[26527637]",
  3403. "invited_email" => $username
  3404. )
  3405. );
  3406. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3407. switch ($api['http_code']['http_code']){
  3408. case 400:
  3409. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3410. $result = "$username already has access to the shared libraries";
  3411. break;
  3412. case 401:
  3413. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3414. $result = "Invalid Plex Token";
  3415. break;
  3416. case 200:
  3417. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3418. $result = "$username now has access to your Plex Library";
  3419. break;
  3420. default:
  3421. writeLog("error", "PLEX INVITE: unknown error");
  3422. $result = false;
  3423. }
  3424. return (!empty($result) ? $result : null );
  3425. }
  3426. function plexUserDelete($username){
  3427. $address = qualifyURL(PLEXURL);
  3428. $headers = array(
  3429. "Accept" => "application/json",
  3430. "Content-Type" => "application/json",
  3431. "X-Plex-Token" => PLEXTOKEN
  3432. );
  3433. libxml_use_internal_errors(true);
  3434. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3435. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3436. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3437. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3438. switch ($api['http_code']['http_code']){
  3439. case 401:
  3440. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3441. $result = "Invalid Plex Token";
  3442. break;
  3443. case 200:
  3444. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3445. $result = "$username doesn't have access to your Plex Library anymore";
  3446. break;
  3447. default:
  3448. writeLog("error", "PLEX INVITE: unknown error");
  3449. $result = false;
  3450. }
  3451. return (!empty($result) ? $result : null );
  3452. }
  3453. function convertPlexName($user, $type){
  3454. $array = libraryList();
  3455. switch ($type){
  3456. case "username":
  3457. $plexUser = array_search ($user, $array['users']);
  3458. break;
  3459. case "id":
  3460. if (array_key_exists(strtolower($user), $array['users'])) {
  3461. $plexUser = $array['users'][strtolower($user)];
  3462. }
  3463. break;
  3464. default:
  3465. $plexUser = false;
  3466. }
  3467. return (!empty($plexUser) ? $plexUser : null );
  3468. }
  3469. function randomCode($length = 5, $type = null) {
  3470. switch ($type){
  3471. case "alpha":
  3472. $legend = array_merge(range('A', 'Z'));
  3473. break;
  3474. case "numeric":
  3475. $legend = array_merge(range(0,9));
  3476. break;
  3477. default:
  3478. $legend = array_merge(range(0,9),range('A', 'Z'));
  3479. }
  3480. $code = "";
  3481. for($i=0; $i < $length; $i++) {
  3482. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3483. }
  3484. return $code;
  3485. }
  3486. function inviteCodes($action, $code = null, $usedBy = null) {
  3487. if (!isset($GLOBALS['file_db'])) {
  3488. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3489. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3490. }
  3491. $now = date("Y-m-d H:i:s");
  3492. switch ($action) {
  3493. case "get":
  3494. // Start Array
  3495. $result = array();
  3496. // Database Lookup
  3497. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3498. // Get Codes
  3499. foreach($invites as $row) {
  3500. array_push($result, $row['code']);
  3501. }
  3502. // Return the Results
  3503. return (!empty($result) ? $result : false );
  3504. break;
  3505. case "check":
  3506. // Start Array
  3507. $result = array();
  3508. // Database Lookup
  3509. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3510. // Get Codes
  3511. foreach($invites as $row) {
  3512. $result = $row['code'];
  3513. }
  3514. // Return the Results
  3515. return (!empty($result) ? $result : false );
  3516. break;
  3517. case "use":
  3518. $currentIP = get_client_ip();
  3519. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3520. if(ENABLEMAIL){
  3521. if (!isset($GLOBALS['USER'])) {
  3522. require_once("user.php");
  3523. $GLOBALS['USER'] = new User('registration_callback');
  3524. }
  3525. 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."));
  3526. }
  3527. return (!empty($invites) ? true : false );
  3528. break;
  3529. }
  3530. }
  3531. function plexJoin($username, $email, $password){
  3532. $connectURL = 'https://plex.tv/users.json';
  3533. $headers = array(
  3534. 'Accept'=> 'application/json',
  3535. 'Content-Type' => 'application/x-www-form-urlencoded',
  3536. 'X-Plex-Product' => 'Organizr',
  3537. 'X-Plex-Version' => '1.0',
  3538. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3539. );
  3540. $body = array(
  3541. 'user[email]' => $email,
  3542. 'user[username]' => $username,
  3543. 'user[password]' => $password,
  3544. );
  3545. $api = curl_post($connectURL, $body, $headers);
  3546. $json = json_decode($api['content'], true);
  3547. $errors = (!empty($json['errors']) ? true : false);
  3548. $success = (!empty($json['user']) ? true : false);
  3549. //Use This for later
  3550. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3551. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3552. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3553. $errorMessage = "";
  3554. if($errors){
  3555. if($usernameError){ $errorMessage .= "[Username Error: ". $usernameError ."]"; }
  3556. if($emailError){ $errorMessage .= "[Email Error: ". $emailError ."]"; }
  3557. if($passwordError){ $errorMessage .= "[Password Error: ". $passwordError ."]"; }
  3558. }
  3559. switch ($api['http_code']['http_code']){
  3560. case 400:
  3561. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." $username already has access to the shared libraries $errorMessage");
  3562. break;
  3563. case 401:
  3564. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." invalid Plex Token $errorMessage");
  3565. break;
  3566. case 422:
  3567. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." user info error $errorMessage");
  3568. break;
  3569. case 429:
  3570. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." too many requests to plex.tv please try later $errorMessage");
  3571. break;
  3572. case 200:
  3573. case 201:
  3574. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3575. break;
  3576. default:
  3577. writeLog("error", "PLEX JOIN: unknown error, $errorMessage Error: ".$api['http_code']['http_code']);
  3578. }
  3579. //prettyPrint($api);
  3580. //prettyPrint(json_decode($api['content'], true));
  3581. return (!empty($success) && empty($errors) ? true : false );
  3582. }
  3583. function getCert(){
  3584. $url = "http://curl.haxx.se/ca/cacert.pem";
  3585. $file = getcwd()."/config/cacert.pem";
  3586. $directory = getcwd()."/config/";
  3587. @mkdir($directory, 0770, true);
  3588. if(!file_exists($file)){
  3589. file_put_contents( $file, fopen($url, 'r'));
  3590. writeLog("success", "CERT PEM: pem file created");
  3591. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3592. file_put_contents( $file, fopen($url, 'r'));
  3593. writeLog("success", "CERT PEM: downloaded new pem file");
  3594. }
  3595. return $file;
  3596. }
  3597. function customCSS(){
  3598. if(CUSTOMCSS == "true") {
  3599. $template_file = "custom.css";
  3600. $file_handle = fopen($template_file, "rb");
  3601. echo "\n";
  3602. echo fread($file_handle, filesize($template_file));
  3603. fclose($file_handle);
  3604. echo "\n";
  3605. }
  3606. }
  3607. function tvdbToken(){
  3608. $headers = array(
  3609. "Accept" => "application/json",
  3610. "Content-Type" => "application/json"
  3611. );
  3612. $json = array(
  3613. "apikey" => "FBE7B62621F4CAD7",
  3614. "userkey" => "328BB46EB1E9A0F5",
  3615. "username" => "causefx"
  3616. );
  3617. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3618. return json_decode($api['content'], true)['token'];
  3619. }
  3620. function tvdbGet($id){
  3621. $headers = array(
  3622. "Accept" => "application/json",
  3623. "Authorization" => "Bearer ".tvdbToken(),
  3624. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3625. "trakt-api-version" => "2"
  3626. );
  3627. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3628. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3629. if(empty($api['trakt'])){
  3630. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3631. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3632. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3633. $api['series'] = json_decode($series, true)['data'];
  3634. $api['poster'] = json_decode($poster, true)['data'];
  3635. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3636. }
  3637. return $api;
  3638. }
  3639. function tvdbSearch($name, $type){
  3640. $name = rawurlencode(preg_replace("/\(([^()]*+|(?R))*\)/","", $name));
  3641. $headers = array(
  3642. "Accept" => "application/json",
  3643. "Authorization" => "Bearer ".tvdbToken(),
  3644. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3645. "trakt-api-version" => "2"
  3646. );
  3647. $trakt = curl_get("https://api.trakt.tv/search/$type?query=$name", $headers);
  3648. @$api['trakt'] = json_decode($trakt, true)[0][$type]['ids'];
  3649. return $api;
  3650. }
  3651. function getPlexPlaylists(){
  3652. $address = qualifyURL(PLEXURL);
  3653. // Perform API requests
  3654. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3655. libxml_use_internal_errors(true);
  3656. $api = simplexml_load_string($api);
  3657. if (is_array($api) || is_object($api)){
  3658. if (!$api->head->title){
  3659. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3660. if (!$getServer) { return 'Could not load!'; }
  3661. // Identify the local machine
  3662. $gotServer = $getServer['machineIdentifier'];
  3663. $output = "";
  3664. $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">';
  3665. foreach($api AS $child) {
  3666. $items = array();
  3667. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3668. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3669. $api = simplexml_load_string($api);
  3670. if (is_array($api) || is_object($api)){
  3671. if (!$api->head->title){
  3672. $className = preg_replace("/(\W)+/", "", $api['title']);
  3673. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3674. foreach($api->Video AS $child){
  3675. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3676. }
  3677. if (count($items)) {
  3678. $output .= ''.implode('',$items).'';
  3679. }
  3680. }
  3681. }
  3682. }
  3683. }
  3684. $hideMenu .= '</ul></div></div>';
  3685. 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>';
  3686. }else{
  3687. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3688. }
  3689. }else{
  3690. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3691. }
  3692. }
  3693. function readExternalLog($type,$filename,$name = null){
  3694. $log = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3695. $log = array_reverse($log);
  3696. foreach($log as $line){
  3697. if(!empty($line) && $line[0] != " "){
  3698. $line = strip($line);
  3699. if($type == "single"){
  3700. if( strpos( strtolower($line), "ror" ) !== false ) {
  3701. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3702. }else{
  3703. echo "<tr><td>".$line."</td></tr>";
  3704. }
  3705. }elseif($type == "all"){
  3706. if( strpos( strtolower($line), "ror" ) !== false ) {
  3707. echo "<tr><td class='red-bg'>".$name."</td>";
  3708. echo "<td class='red-bg'>".$line."</td></tr>";
  3709. }else{
  3710. echo "<tr><td>".$name."</td>";
  3711. echo "<td>".$line."</td></tr>";
  3712. }
  3713. }
  3714. }
  3715. }
  3716. }
  3717. function getLogs(){
  3718. $path = __DIR__ ."/logs/";
  3719. @mkdir($path, 0770, true);
  3720. $logs = array();
  3721. $files = array_diff(scandir($path), array('.', '..'));
  3722. foreach($files as $v){
  3723. $title = explode(".", $v)[0];
  3724. $logs[$title] = $path.$v;
  3725. }
  3726. return $logs;
  3727. }
  3728. function getBackups(){
  3729. $path = DATABASE_LOCATION ."backups/";
  3730. @mkdir($path, 0770, true);
  3731. $backups = array();
  3732. $files = array_diff(scandir($path), array('.', '..'));
  3733. return array_reverse($files);
  3734. }
  3735. function getExtension($string) {
  3736. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3737. }
  3738. function showFile(){
  3739. $file = $_GET['file'];
  3740. $fileType = getExtension($file);
  3741. if($fileType != 'php'){
  3742. header("Content-type: ".mimeTypes()[$fileType]);
  3743. @readfile($file);
  3744. }
  3745. }
  3746. function getCalendar(){
  3747. $sonarr = new Sonarr(SONARRURL, SONARRKEY);
  3748. $radarr = new Sonarr(RADARRURL, RADARRKEY);
  3749. $sickrage = new SickRage(SICKRAGEURL, SICKRAGEKEY);
  3750. $startDate = date('Y-m-d',strtotime("-".CALENDARSTARTDAY." days"));
  3751. $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
  3752. $calendarItems = array();
  3753. if (SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)){
  3754. try {
  3755. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate));
  3756. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  3757. } catch (Exception $e) {
  3758. writeLog("error", "SONARR ERROR: ".strip($e->getMessage()));
  3759. }
  3760. }
  3761. if (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)){
  3762. try {
  3763. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate));
  3764. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  3765. } catch (Exception $e) {
  3766. writeLog("error", "RADARR ERROR: ".strip($e->getMessage()));
  3767. }
  3768. }
  3769. if (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH)){
  3770. $couchCalendar = getCouchCalendar();
  3771. if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
  3772. }
  3773. if (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)){
  3774. $headphonesHistory = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getHistory");
  3775. $headphonesWanted = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getWanted");
  3776. if(!empty($headphonesHistory)) { $calendarItems = array_merge($calendarItems, $headphonesHistory); }
  3777. if(!empty($headphonesWanted)) { $calendarItems = array_merge($calendarItems, $headphonesWanted); }
  3778. }
  3779. if (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)){
  3780. try {
  3781. $sickrageFuture = getSickrageCalendarWanted($sickrage->future());
  3782. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  3783. } catch (Exception $e) {
  3784. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3785. } try {
  3786. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"));
  3787. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  3788. } catch (Exception $e) {
  3789. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3790. }
  3791. }
  3792. return $calendarItems;
  3793. }
  3794. function localURL($url){
  3795. if (strpos($url, 'https') !== false) {
  3796. preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $url, $result);
  3797. $result = (!empty($result) ? true : false);
  3798. return $result;
  3799. }
  3800. }
  3801. function fileArray($files){
  3802. foreach($files as $file){
  3803. if(file_exists($file)){
  3804. $list[] = $file;
  3805. }
  3806. }
  3807. if(!empty($list)){ return $list; }
  3808. }
  3809. function backupDB(){
  3810. if (extension_loaded('ZIP')) {
  3811. $directory = DATABASE_LOCATION."backups/";
  3812. @mkdir($directory, 0770, true);
  3813. $orgFiles = array(
  3814. 'css' => 'custom.css',
  3815. 'temp' => 'cus.sd',
  3816. 'orgLog' => DATABASE_LOCATION.'org.log',
  3817. 'loginLog' => DATABASE_LOCATION.'loginLog.json',
  3818. 'chatDB' => 'chatpack.db',
  3819. 'config' => 'config/config.php',
  3820. 'database' => DATABASE_LOCATION.'users.db'
  3821. );
  3822. $files = fileArray($orgFiles);
  3823. if(!empty($files)){
  3824. writeLog("success", "BACKUP: backup process started");
  3825. $zipname = $directory.'backup['.date('Y-m-d_H-i').']['.INSTALLEDVERSION.'].zip';
  3826. $zip = new ZipArchive;
  3827. $zip->open($zipname, ZipArchive::CREATE);
  3828. foreach ($files as $file) {
  3829. $zip->addFile($file);
  3830. }
  3831. $zip->close();
  3832. writeLog("success", "BACKUP: backup process finished");
  3833. return true;
  3834. }else{
  3835. return false;
  3836. }
  3837. }else{
  3838. return false;
  3839. }
  3840. }
  3841. class Ping {
  3842. private $host;
  3843. private $ttl;
  3844. private $timeout;
  3845. private $port = 80;
  3846. private $data = 'Ping';
  3847. private $commandOutput;
  3848. /**
  3849. * Called when the Ping object is created.
  3850. *
  3851. * @param string $host
  3852. * The host to be pinged.
  3853. * @param int $ttl
  3854. * Time-to-live (TTL) (You may get a 'Time to live exceeded' error if this
  3855. * value is set too low. The TTL value indicates the scope or range in which
  3856. * a packet may be forwarded. By convention:
  3857. * - 0 = same host
  3858. * - 1 = same subnet
  3859. * - 32 = same site
  3860. * - 64 = same region
  3861. * - 128 = same continent
  3862. * - 255 = unrestricted
  3863. * @param int $timeout
  3864. * Timeout (in seconds) used for ping and fsockopen().
  3865. * @throws \Exception if the host is not set.
  3866. */
  3867. public function __construct($host, $ttl = 255, $timeout = 10) {
  3868. if (!isset($host)) {
  3869. throw new \Exception("Error: Host name not supplied.");
  3870. }
  3871. $this->host = $host;
  3872. $this->ttl = $ttl;
  3873. $this->timeout = $timeout;
  3874. }
  3875. /**
  3876. * Set the ttl (in hops).
  3877. *
  3878. * @param int $ttl
  3879. * TTL in hops.
  3880. */
  3881. public function setTtl($ttl) {
  3882. $this->ttl = $ttl;
  3883. }
  3884. /**
  3885. * Get the ttl.
  3886. *
  3887. * @return int
  3888. * The current ttl for Ping.
  3889. */
  3890. public function getTtl() {
  3891. return $this->ttl;
  3892. }
  3893. /**
  3894. * Set the timeout.
  3895. *
  3896. * @param int $timeout
  3897. * Time to wait in seconds.
  3898. */
  3899. public function setTimeout($timeout) {
  3900. $this->timeout = $timeout;
  3901. }
  3902. /**
  3903. * Get the timeout.
  3904. *
  3905. * @return int
  3906. * Current timeout for Ping.
  3907. */
  3908. public function getTimeout() {
  3909. return $this->timeout;
  3910. }
  3911. /**
  3912. * Set the host.
  3913. *
  3914. * @param string $host
  3915. * Host name or IP address.
  3916. */
  3917. public function setHost($host) {
  3918. $this->host = $host;
  3919. }
  3920. /**
  3921. * Get the host.
  3922. *
  3923. * @return string
  3924. * The current hostname for Ping.
  3925. */
  3926. public function getHost() {
  3927. return $this->host;
  3928. }
  3929. /**
  3930. * Set the port (only used for fsockopen method).
  3931. *
  3932. * Since regular pings use ICMP and don't need to worry about the concept of
  3933. * 'ports', this is only used for the fsockopen method, which pings servers by
  3934. * checking port 80 (by default).
  3935. *
  3936. * @param int $port
  3937. * Port to use for fsockopen ping (defaults to 80 if not set).
  3938. */
  3939. public function setPort($port) {
  3940. $this->port = $port;
  3941. }
  3942. /**
  3943. * Get the port (only used for fsockopen method).
  3944. *
  3945. * @return int
  3946. * The port used by fsockopen pings.
  3947. */
  3948. public function getPort() {
  3949. return $this->port;
  3950. }
  3951. /**
  3952. * Return the command output when method=exec.
  3953. * @return string
  3954. */
  3955. public function getCommandOutput(){
  3956. return $this->commandOutput;
  3957. }
  3958. /**
  3959. * Matches an IP on command output and returns.
  3960. * @return string
  3961. */
  3962. public function getIpAddress() {
  3963. $out = array();
  3964. if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->commandOutput, $out)){
  3965. return $out[0];
  3966. }
  3967. return null;
  3968. }
  3969. /**
  3970. * Ping a host.
  3971. *
  3972. * @param string $method
  3973. * Method to use when pinging:
  3974. * - exec (default): Pings through the system ping command. Fast and
  3975. * robust, but a security risk if you pass through user-submitted data.
  3976. * - fsockopen: Pings a server on port 80.
  3977. * - socket: Creates a RAW network socket. Only usable in some
  3978. * environments, as creating a SOCK_RAW socket requires root privileges.
  3979. *
  3980. * @throws InvalidArgumentException if $method is not supported.
  3981. *
  3982. * @return mixed
  3983. * Latency as integer, in ms, if host is reachable or FALSE if host is down.
  3984. */
  3985. public function ping($method = 'exec') {
  3986. $latency = false;
  3987. switch ($method) {
  3988. case 'exec':
  3989. $latency = $this->pingExec();
  3990. break;
  3991. case 'fsockopen':
  3992. $latency = $this->pingFsockopen();
  3993. break;
  3994. case 'socket':
  3995. $latency = $this->pingSocket();
  3996. break;
  3997. default:
  3998. throw new \InvalidArgumentException('Unsupported ping method.');
  3999. }
  4000. // Return the latency.
  4001. return $latency;
  4002. }
  4003. /**
  4004. * The exec method uses the possibly insecure exec() function, which passes
  4005. * the input to the system. This is potentially VERY dangerous if you pass in
  4006. * any user-submitted data. Be SURE you sanitize your inputs!
  4007. *
  4008. * @return int
  4009. * Latency, in ms.
  4010. */
  4011. private function pingExec() {
  4012. $latency = false;
  4013. $ttl = escapeshellcmd($this->ttl);
  4014. $timeout = escapeshellcmd($this->timeout);
  4015. $host = escapeshellcmd($this->host);
  4016. // Exec string for Windows-based systems.
  4017. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  4018. // -n = number of pings; -i = ttl; -w = timeout (in milliseconds).
  4019. $exec_string = 'ping -n 1 -i ' . $ttl . ' -w ' . ($timeout * 1000) . ' ' . $host;
  4020. }
  4021. // Exec string for Darwin based systems (OS X).
  4022. else if(strtoupper(PHP_OS) === 'DARWIN') {
  4023. // -n = numeric output; -c = number of pings; -m = ttl; -t = timeout.
  4024. $exec_string = 'ping -n -c 1 -m ' . $ttl . ' -t ' . $timeout . ' ' . $host;
  4025. }
  4026. // Exec string for other UNIX-based systems (Linux).
  4027. else {
  4028. // -n = numeric output; -c = number of pings; -t = ttl; -W = timeout
  4029. $exec_string = 'ping -n -c 1 -t ' . $ttl . ' -W ' . $timeout . ' ' . $host . ' 2>&1';
  4030. }
  4031. exec($exec_string, $output, $return);
  4032. // Strip empty lines and reorder the indexes from 0 (to make results more
  4033. // uniform across OS versions).
  4034. $this->commandOutput = implode($output, '');
  4035. $output = array_values(array_filter($output));
  4036. // If the result line in the output is not empty, parse it.
  4037. if (!empty($output[1])) {
  4038. // Search for a 'time' value in the result line.
  4039. $response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)ms/", $output[1], $matches);
  4040. // If there's a result and it's greater than 0, return the latency.
  4041. if ($response > 0 && isset($matches['time'])) {
  4042. $latency = round($matches['time'], 2);
  4043. }
  4044. }
  4045. return $latency;
  4046. }
  4047. /**
  4048. * The fsockopen method simply tries to reach the host on a port. This method
  4049. * is often the fastest, but not necessarily the most reliable. Even if a host
  4050. * doesn't respond, fsockopen may still make a connection.
  4051. *
  4052. * @return int
  4053. * Latency, in ms.
  4054. */
  4055. private function pingFsockopen() {
  4056. $start = microtime(true);
  4057. // fsockopen prints a bunch of errors if a host is unreachable. Hide those
  4058. // irrelevant errors and deal with the results instead.
  4059. $fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  4060. if (!$fp) {
  4061. $latency = false;
  4062. }
  4063. else {
  4064. $latency = microtime(true) - $start;
  4065. $latency = round($latency * 1000, 2);
  4066. }
  4067. return $latency;
  4068. }
  4069. /**
  4070. * The socket method uses raw network packet data to try sending an ICMP ping
  4071. * packet to a server, then measures the response time. Using this method
  4072. * requires the script to be run with root privileges, though, so this method
  4073. * only works reliably on Windows systems and on Linux servers where the
  4074. * script is not being run as a web user.
  4075. *
  4076. * @return int
  4077. * Latency, in ms.
  4078. */
  4079. private function pingSocket() {
  4080. // Create a package.
  4081. $type = "\x08";
  4082. $code = "\x00";
  4083. $checksum = "\x00\x00";
  4084. $identifier = "\x00\x00";
  4085. $seq_number = "\x00\x00";
  4086. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4087. // Calculate the checksum.
  4088. $checksum = $this->calculateChecksum($package);
  4089. // Finalize the package.
  4090. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4091. // Create a socket, connect to server, then read socket and calculate.
  4092. if ($socket = socket_create(AF_INET, SOCK_RAW, 1)) {
  4093. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array(
  4094. 'sec' => 10,
  4095. 'usec' => 0,
  4096. ));
  4097. // Prevent errors from being printed when host is unreachable.
  4098. @socket_connect($socket, $this->host, null);
  4099. $start = microtime(true);
  4100. // Send the package.
  4101. @socket_send($socket, $package, strlen($package), 0);
  4102. if (socket_read($socket, 255) !== false) {
  4103. $latency = microtime(true) - $start;
  4104. $latency = round($latency * 1000, 2);
  4105. }
  4106. else {
  4107. $latency = false;
  4108. }
  4109. }
  4110. else {
  4111. $latency = false;
  4112. }
  4113. // Close the socket.
  4114. socket_close($socket);
  4115. return $latency;
  4116. }
  4117. /**
  4118. * Calculate a checksum.
  4119. *
  4120. * @param string $data
  4121. * Data for which checksum will be calculated.
  4122. *
  4123. * @return string
  4124. * Binary string checksum of $data.
  4125. */
  4126. private function calculateChecksum($data) {
  4127. if (strlen($data) % 2) {
  4128. $data .= "\x00";
  4129. }
  4130. $bit = unpack('n*', $data);
  4131. $sum = array_sum($bit);
  4132. while ($sum >> 16) {
  4133. $sum = ($sum >> 16) + ($sum & 0xffff);
  4134. }
  4135. return pack('n*', ~$sum);
  4136. }
  4137. }
  4138. function ping($pings, $type = "string") {
  4139. $ping = new Ping("");
  4140. $ping->setTtl(128);
  4141. $ping->setTimeout(2);
  4142. switch ($type){
  4143. case "array":
  4144. $results = [];
  4145. foreach ($pings as $k => $v) {
  4146. if(strpos($v, ':') !== false){
  4147. $domain = explode(':', $v)[0];
  4148. $port = explode(':', $v)[1];
  4149. $ping->setHost($domain);
  4150. $ping->setPort($port);
  4151. $latency = $ping->ping('fsockopen');
  4152. }else{
  4153. $ping->setHost($v);
  4154. $latency = $ping->ping();
  4155. }
  4156. if ($latency || $latency === 0) {
  4157. $results[$k] = $latency;
  4158. } else {
  4159. $results[$k] = 0;
  4160. }
  4161. }
  4162. break;
  4163. case "string":
  4164. if(strpos($pings, ':') !== false){
  4165. $domain = explode(':', $pings)[0];
  4166. $port = explode(':', $pings)[1];
  4167. $ping->setHost($domain);
  4168. $ping->setPort($port);
  4169. $latency = $ping->ping('fsockopen');
  4170. }else{
  4171. $ping->setHost($pings);
  4172. $latency = $ping->ping();
  4173. }
  4174. if ($latency || $latency === 0) {
  4175. $results = $latency;
  4176. } else {
  4177. $results = 0;
  4178. }
  4179. break;
  4180. }
  4181. return $results;
  4182. }
  4183. function getPing($url, $style, $refresh = null){
  4184. if(ping($url) !== 0){
  4185. $class = 'success';
  4186. if(!$refresh){
  4187. $class .= " animated slideInLeft";
  4188. }
  4189. }else{
  4190. $class = "warning";
  4191. if(!$refresh){
  4192. $class .= " animated flash loop-animation-timeout";
  4193. }
  4194. }
  4195. echo '<span class="pingcheck badge ping-'.$class.'" style="position: absolute;z-index: 100;right: 5px; padding: 0px 0px;'.$style.';font-size: 10px;">&nbsp;</span>';
  4196. }
  4197. function speedTestData(){
  4198. $file_db = DATABASE_LOCATION."speedtest.db";
  4199. if(file_exists($file_db)){
  4200. $conn = new PDO("sqlite:$file_db") or die("1");
  4201. $result = $conn->query('SELECT * FROM speedtest_users');
  4202. $conn = null;
  4203. if (is_array($result) || is_object($result)){
  4204. foreach($result as $k => $v){
  4205. $return[$k] = $v;
  4206. }
  4207. return $return;
  4208. }
  4209. }
  4210. }
  4211. function speedTestDisplay($array, $output){
  4212. if (is_array($array) || is_object($array)){
  4213. if($output == "graph"){
  4214. $result = "Morris.Line({element: 'morris-line',data: [";
  4215. foreach($array as $k => $v){
  4216. $result .= "{ y: '".substr($v['timestamp'],0,10)."', a: ".$v['ul'].", b: ".$v['dl'].", c: ".$v['ping']." },";
  4217. }
  4218. $result .= "],xkey: 'y',ykeys: ['a', 'b', 'c'],labels: ['Upload', 'Download', 'Ping'],hideHover: 'auto',resize: true,lineColors: ['#63A8EB','#ccc','#000'] });";
  4219. }elseif($output == "table"){
  4220. $result = "";
  4221. foreach($array as $k => $v){
  4222. $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>";
  4223. }
  4224. }
  4225. return $result;
  4226. }
  4227. }
  4228. function buildMenuPhone($array){
  4229. if (is_array($array) || is_object($array)){
  4230. $result = '
  4231. <div class="content-box profile-sidebar box-shadow">
  4232. <img src="images/organizr-logo-h-d.png" width="100%" style="margin-top: -10px;">
  4233. <div class="profile-usermenu">
  4234. <ul class="nav" id="settings-list">
  4235. ';
  4236. foreach($array as $k => $v){
  4237. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4238. continue;
  4239. }
  4240. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4241. continue;
  4242. }
  4243. /*$result .= '
  4244. <li>
  4245. <a id="'.$v['id'].'" box="'.$v['box'].'">'.$v['name'].'
  4246. <span class="fa-stack fa-fw pull-right" style="margin-top: -5px;margin-right: -10px;">
  4247. <i class="fa fa-'.$v['icon_1'].' fa-stack-2x '.$v['color'].'" style="font-size:null;"></i>
  4248. <i class="fa fa-'.$v['icon_2'].' fa-stack-1x fa-inverse"></i>
  4249. </span>
  4250. </a>
  4251. </li>
  4252. ';*/
  4253. $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>';
  4254. }
  4255. $result .= '</ul></div></div>';
  4256. return $result;
  4257. }
  4258. }
  4259. function buildMenu($array){
  4260. if (is_array($array) || is_object($array)){
  4261. $result = '<div class="settingsList">';
  4262. foreach($array as $k => $v){
  4263. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4264. continue;
  4265. }
  4266. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4267. continue;
  4268. }
  4269. $result .= '
  4270. <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">
  4271. <i class="mdi mdi-'.$v['icon_1'].' fa-fw pull-left" style="padding-left: '.$v['padding'].'px;font-size: 30px"></i>
  4272. <p class="" style="text-align: center;direction: rtl;display:none;margin: 2px;"><strong>'.$v['name'].'</strong></p>
  4273. </button>
  4274. ';
  4275. }
  4276. $result .= '</div>';
  4277. return $result;
  4278. }
  4279. }
  4280. function requestInvite($email, $username){
  4281. //sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
  4282. //orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  4283. 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."));
  4284. }
  4285. function errormessage($msg) {
  4286. echo "<div style=\"margin-top: 50px;\">";
  4287. echo "<span style=\"color:#d89334;\">error </span>";
  4288. echo $msg;
  4289. echo "</div>";
  4290. }
  4291. function ajaxLoop($ajaxFunction, $refresh, $extraFunction = ''){
  4292. return "
  4293. setInterval(function() {
  4294. $.ajax({
  4295. url: 'ajax.php?a=".$ajaxFunction."',
  4296. timeout: 10000,
  4297. type: 'GET',
  4298. success: function(response) {
  4299. var getDiv = response;
  4300. var loadedID = $(getDiv).attr('id');
  4301. if (typeof loadedID !== 'undefined') {
  4302. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  4303. ".$extraFunction."
  4304. console.log('".$ajaxFunction." has been updated');
  4305. }else{
  4306. console.log('".$ajaxFunction." data was not sufficent or is offline');
  4307. }
  4308. },
  4309. error: function(jqXHR, textStatus, errorThrown) {
  4310. console.error('".$ajaxFunction." could not be updated');
  4311. }
  4312. });
  4313. }, ".$refresh.");
  4314. ";
  4315. }
  4316. function getOrgUsers(){
  4317. $file_db = DATABASE_LOCATION."users.db";
  4318. if(file_exists($file_db)){
  4319. $conn = new PDO("sqlite:$file_db") or die("1");
  4320. $result = $conn->query('SELECT * FROM users');
  4321. $conn = null;
  4322. if (is_array($result) || is_object($result)){
  4323. foreach($result as $k => $v){
  4324. $return[$v['username']] = $v['email'];
  4325. }
  4326. return $return;
  4327. }
  4328. }
  4329. }
  4330. function getEmails($type = 'org'){
  4331. if($type == 'plex'){
  4332. $emails = array_merge(libraryList()['both'],getOrgUsers());
  4333. }elseif($type == 'emby'){
  4334. $emails = getOrgUsers();
  4335. }else{
  4336. $emails = getOrgUsers();
  4337. }
  4338. return $emails;
  4339. }
  4340. function printEmails($emails){
  4341. $result = '';
  4342. foreach($emails as $k => $v){
  4343. $result .= '<option value="'.$v.'">'.$k.'</option>';
  4344. }
  4345. return $result;
  4346. }
  4347. function massEmail($to, $subject, $message){
  4348. if (!isset($GLOBALS['file_db'])) {
  4349. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  4350. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4351. }
  4352. 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);
  4353. }
  4354. function q2a($q){
  4355. if (is_array($q) || is_object($q)){
  4356. foreach ($q as $k => $v){
  4357. $a[$k] = $v;
  4358. }
  4359. if(!empty($a)){
  4360. return $a;
  4361. }
  4362. }
  4363. }
  4364. function getOmbiToken($username, $password){
  4365. $headers = array(
  4366. "Accept" => "application/json",
  4367. "Content-Type" => "application/json"
  4368. );
  4369. $json = array(
  4370. "username" => $username,
  4371. "password" => $password,
  4372. "rememberMe" => "true",
  4373. );
  4374. $api = curl_post(OMBIURL."/api/v1/Token", $json, $headers);
  4375. if (isset($api['content'])) {
  4376. return json_decode($api['content'], true)['access_token'];
  4377. }else{
  4378. return false;
  4379. }
  4380. }
  4381. function ombiAction($id, $action, $type){
  4382. $headers = array(
  4383. "Accept" => "application/json",
  4384. "Content-Type" => "application/json",
  4385. "Apikey" => OMBIKEY
  4386. );
  4387. $body = array(
  4388. 'id' => $id,
  4389. );
  4390. switch ($type) {
  4391. case 'season':
  4392. case 'tv':
  4393. $type = 'tv';
  4394. break;
  4395. default:
  4396. $type = 'movie';
  4397. break;
  4398. }
  4399. switch ($action) {
  4400. case 'approve':
  4401. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/approve", $body, $headers);
  4402. break;
  4403. case 'available':
  4404. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/available", $body, $headers);
  4405. break;
  4406. case 'unavailable':
  4407. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/unavailable", $body, $headers);
  4408. break;
  4409. case 'deny':
  4410. $api = curl_put(OMBIURL."/api/v1/Request/".$type."/deny", $body, $headers);
  4411. break;
  4412. case 'delete':
  4413. $api = curl_delete(OMBIURL."/api/v1/Request/".$type."/".$id, $headers);
  4414. break;
  4415. default:
  4416. # code...
  4417. break;
  4418. }
  4419. switch ($api['http_code']['http_code']){
  4420. case 401:
  4421. writeLog("error", "OMBI: Invalid API KEY");
  4422. return false;
  4423. break;
  4424. case 200:
  4425. writeLog("success", "OMBI: action completed successfully for [type: $type - action: $action - id: $id]");
  4426. return true;
  4427. break;
  4428. default:
  4429. writeLog("error", "OMBI: unknown error with request [type: $type - action: $action - id: $id]");
  4430. return false;
  4431. }
  4432. //return (!empty($result) ? $result : null );
  4433. }
  4434. function getOmbiRequests($type = "both"){
  4435. $headers = array(
  4436. "Accept" => "application/json",
  4437. "Apikey" => OMBIKEY,
  4438. );
  4439. $requests = array();
  4440. switch ($type) {
  4441. case 'movie':
  4442. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4443. break;
  4444. case 'tv':
  4445. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4446. break;
  4447. default:
  4448. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4449. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4450. break;
  4451. }
  4452. if(isset($movie)){
  4453. //$movie = array_reverse($movie);
  4454. foreach ($movie as $key => $value) {
  4455. $poster = explode('/',$value['posterPath']);
  4456. $requests[] = array(
  4457. 'id' => $value['theMovieDbId'],
  4458. 'title' => $value['title'],
  4459. 'poster' => (strpos($value['posterPath'], "/") !== false) ? 'https://image.tmdb.org/t/p/w300/'.end($poster) : 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'],
  4460. 'approved' => $value['approved'],
  4461. 'available' => $value['available'],
  4462. 'denied' => $value['denied'],
  4463. 'deniedReason' => $value['deniedReason'],
  4464. 'user' => $value['requestedUser']['userName'],
  4465. 'request_id' => $value['id'],
  4466. 'request_date' => $value['requestedDate'],
  4467. 'release_date' => $value['releaseDate'],
  4468. 'type' => 'movie',
  4469. 'icon' => 'mdi mdi-filmstrip',
  4470. 'color' => 'palette-Deep-Purple-900 bg white',
  4471. );
  4472. }
  4473. }
  4474. if(isset($tv) && (is_array($tv) || is_object($tv))){
  4475. foreach ($tv as $key => $value) {
  4476. if(is_array($value['childRequests'][0])){
  4477. $requests[] = array(
  4478. 'id' => $value['tvDbId'],
  4479. 'title' => $value['title'],
  4480. 'poster' => $value['posterPath'],
  4481. 'approved' => $value['childRequests'][0]['approved'],
  4482. 'available' => $value['childRequests'][0]['available'],
  4483. 'denied' => $value['childRequests'][0]['denied'],
  4484. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  4485. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  4486. 'request_id' => $value['id'],
  4487. 'request_date' => $value['childRequests'][0]['requestedDate'],
  4488. 'release_date' => $value['releaseDate'],
  4489. 'type' => 'tv',
  4490. 'icon' => 'mdi mdi-television',
  4491. 'color' => 'grayish-blue-bg',
  4492. );
  4493. }
  4494. }
  4495. }
  4496. return (empty($requests)) ? '' : $requests;
  4497. }
  4498. function convertOmbiString($type, $value){
  4499. switch ($type) {
  4500. case 'approved':
  4501. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4502. $string['icon'] = ($value) ? 'mdi mdi-check' : 'mdi mdi-clock';
  4503. $string['color'] = ($value) ? 'green-bg' : 'yellow-bg';
  4504. break;
  4505. case 'available':
  4506. $string['string'] = ($value) ? 'Available' : 'Not Downloaded';
  4507. $string['icon'] = ($value) ? 'mdi mdi-server' : 'mdi mdi-server-off';
  4508. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4509. break;
  4510. case 'denied':
  4511. $string['string'] = ($value) ? 'Denied' : 'Approved';
  4512. $string['icon'] = ($value) ? 'mdi mdi-emoticon-sad' : 'mdi mdi-emoticon-happy';
  4513. $string['color'] = ($value) ? 'red-bg' : 'green-bg';
  4514. break;
  4515. case 'status':
  4516. switch ($value) {
  4517. case '1':
  4518. $string['string'] = 'Denied';
  4519. $string['icon'] = 'mdi mdi-window-close';
  4520. $string['color'] = 'red-bg';
  4521. break;
  4522. case '2':
  4523. $string['string'] = 'Approved';
  4524. $string['icon'] = 'mdi mdi-check';
  4525. $string['color'] = 'green-bg';
  4526. break;
  4527. case '3':
  4528. $string['string'] = 'Not Approved';
  4529. $string['icon'] = 'mdi mdi-clock';
  4530. $string['color'] = 'yellow-bg';
  4531. break;
  4532. default:
  4533. # code...
  4534. break;
  4535. }
  4536. break;
  4537. default:
  4538. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4539. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4540. break;
  4541. }
  4542. return $string;
  4543. }
  4544. function buildOmbiItem($type, $group, $user, $request){
  4545. if (is_array($request) || is_object($request)){
  4546. $actions = '';
  4547. if($request['denied']){
  4548. $status = 1;
  4549. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4550. }else{
  4551. if($request['approved']){
  4552. $status = 2;
  4553. }else{
  4554. $status = 3;
  4555. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4556. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="deny"><a class="requestAction" href="javascript:void(0)">Deny</a></li>';
  4557. }
  4558. }
  4559. if($request['available']){
  4560. $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>';
  4561. }else{
  4562. $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>';
  4563. }
  4564. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="delete"><a class="requestAction" href="javascript:void(0)">Delete</a></li>';
  4565. if(isset($group) && $group == 'admin'){
  4566. $actionMenu = '
  4567. <div class="requestOptions">
  4568. <div class="btn-group transparent" role="group">
  4569. <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>
  4570. <ul class="dropdown-menu"><h6 class="text-center requestHeader gray-bg">'.$request['user'].'</h6>'.$actions.'</ul>
  4571. </div>
  4572. </div>
  4573. ';
  4574. }else{
  4575. $actionMenu = '';
  4576. }
  4577. if((isset($group)) && $group == 'admin' || REQUESTEDUSERONLY == 'false'){
  4578. return '
  4579. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4580. '.$actionMenu.'
  4581. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4582. <div class="requestBottom text-center">
  4583. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4584. <i class="'.$request['icon'].'"></i>
  4585. </div>
  4586. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4587. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4588. </div>
  4589. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4590. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4591. </div>
  4592. </div>
  4593. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4594. </div>';
  4595. }else{
  4596. if(strtolower($request['user']) == strtolower($user)){
  4597. return '
  4598. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4599. '.$actionMenu.'
  4600. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4601. <div class="requestBottom text-center">
  4602. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4603. <i class="'.$request['icon'].'"></i>
  4604. </div>
  4605. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4606. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4607. </div>
  4608. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4609. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4610. </div>
  4611. </div>
  4612. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4613. </div>';
  4614. }
  4615. }
  4616. }
  4617. }
  4618. function buildOmbiList($group, $user){
  4619. $requests = array();
  4620. $movieList = getOmbiRequests('movie');
  4621. $tvList = getOmbiRequests('tv');
  4622. if(is_array($movieList) && is_array($tvList)){
  4623. $result = array_merge($movieList , $tvList );
  4624. }else{
  4625. if(is_array($movieList)){
  4626. $result = $movieList;
  4627. }elseif(is_array($movieList)){
  4628. $result = $tvList;
  4629. }else{
  4630. $result = false;
  4631. }
  4632. }
  4633. if (is_array($result) || is_object($result)){
  4634. usort($result, function ($item1, $item2) {
  4635. if ($item1['request_date'] == $item2['request_date']) return 0;
  4636. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  4637. });
  4638. foreach ($result as $request) {
  4639. if($request['type'] == 'movie'){
  4640. $requests[] = buildOmbiItem('movie', $group, $user, $request);
  4641. }elseif($request['type'] == 'tv'){
  4642. $requests[] = buildOmbiItem('season', $group, $user, $request);
  4643. }
  4644. }
  4645. }
  4646. return outputOmbiRequests("Requested Content", $requests, ajaxLoop('ombi-requests',REQUESTREFRESH,'loadSlick();'), false);
  4647. }
  4648. function outputOmbiRequests($header = "Requested Content", $items, $script = false, $array) {
  4649. $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">';
  4650. if(preg_grep("/item-movie-Approved/", $items)){
  4651. $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>';
  4652. }
  4653. if(preg_grep("/item-movie-Approval-Pending/", $items)){
  4654. $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>';
  4655. }
  4656. if(preg_grep("/item-season-Approved/", $items)){
  4657. $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>';
  4658. }
  4659. if(preg_grep("/item-season-Approval-Pending/", $items)){
  4660. $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>';
  4661. }
  4662. $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>';
  4663. $hideMenu .= '</ul></div></div>';
  4664. // If None Populate Empty Item
  4665. //if (count(array_flip($items)) < 1) {
  4666. if (!count($items)) {
  4667. 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>';
  4668. }else{
  4669. $className = str_replace(' ', '', $header);
  4670. 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>':'');
  4671. }
  4672. }
  4673. function loadIcons(){
  4674. $dirname = "images/";
  4675. $images = scandir($dirname);
  4676. $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");
  4677. $allIcons = '';
  4678. foreach($images as $curimg){
  4679. if(!in_array($curimg, $ignore)) {
  4680. $allIcons .= '
  4681. <div class="col-xs-2" style="width: 75px; height: 75px; padding-right: 0px;">
  4682. <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);">
  4683. <img style="width: 50px; height: 50px;" data-src="'.$dirname.$curimg.'" alt="thumbnail" class="allIcons lazyload shadow">
  4684. </a>
  4685. </div>
  4686. ';
  4687. }
  4688. }
  4689. return $allIcons;
  4690. }
  4691. function buildHomepageSettings(){
  4692. $homepageOrder = homepageOrder();
  4693. $homepageList = '<h4>Drag Homepage Items to Order Them</h4><div id="homepage-items" class="external-events">';
  4694. $inputList = '<div id="homepage-values" class="row">';
  4695. foreach ($homepageOrder as $key => $val) {
  4696. switch ($key) {
  4697. case 'homepageOrdercustomhtml':
  4698. $class = 'palette-Deep-Purple-100 bg gray';
  4699. $image = 'images/html.png';
  4700. if(empty(HOMEPAGECUSTOMHTML1)){
  4701. $class .= ' faded';
  4702. }
  4703. break;
  4704. case 'homepageOrdernotice':
  4705. $class = 'palette-Cyan-A400 bg gray';
  4706. $image = 'images/pin.png';
  4707. if(empty(HOMEPAGENOTICETITLE) && empty(HOMEPAGENOTICEMESSAGE)){
  4708. $class .= ' faded';
  4709. }
  4710. break;
  4711. case 'homepageOrderspeedtest':
  4712. $class = 'red-bg';
  4713. $image = 'images/settings/full-color/png/64px/speedometer.png';
  4714. if(SPEEDTEST !== "true"){
  4715. $class .= ' faded';
  4716. }
  4717. break;
  4718. case 'homepageOrdernzbget':
  4719. $class = 'green-bg';
  4720. $image = 'images/nzbget.png';
  4721. if(empty(NZBGETURL)){
  4722. $class .= ' faded';
  4723. }
  4724. break;
  4725. case 'homepageOrdersabnzbd':
  4726. $class = 'yellow-bg';
  4727. $image = 'images/sabnzbd.png';
  4728. if(empty(SABNZBDURL)){
  4729. $class .= ' faded';
  4730. }
  4731. break;
  4732. case 'homepageOrderplexsearch':
  4733. case 'homepageOrderplexnowplaying':
  4734. case 'homepageOrderplexrecent':
  4735. case 'homepageOrderplexplaylist':
  4736. $class = 'palette-Amber-A700 bg gray';
  4737. $image = 'images/plex.png';
  4738. if(empty(PLEXURL)){
  4739. $class .= ' faded';
  4740. }
  4741. break;
  4742. case 'homepageOrderembynowplaying':
  4743. case 'homepageOrderembyrecent':
  4744. $class = 'palette-Green-A700 bg gray';
  4745. $image = 'images/emby.png';
  4746. if(empty(EMBYURL)){
  4747. $class .= ' faded';
  4748. }
  4749. break;
  4750. case 'homepageOrderombi':
  4751. $class = 'orange-bg';
  4752. $image = 'images/ombi.png';
  4753. if(empty(OMBIURL)){
  4754. $class .= ' faded';
  4755. }
  4756. break;
  4757. case 'homepageOrdercalendar':
  4758. $class = 'palette-Blue-400 bg gray';
  4759. $image = 'images/calendar.png';
  4760. if(SONARRURL == "" && RADARRURL == "" && HEADPHONESURL == "" && SICKRAGEURL == "" && COUCHURL == "" ){
  4761. $class .= ' faded';
  4762. }
  4763. break;
  4764. default:
  4765. $class = 'blue-bg';
  4766. $image = '';
  4767. break;
  4768. }
  4769. $homepageList .= '
  4770. <div class="col-md-3 sort-homepage"><div class="fc-event '.$class.'">
  4771. <span class="ordinal-position text-uppercase badge badge-gray" data-link="'.$key.'" style="float:left;width: 30px;">'.$val.'</span>
  4772. &nbsp; '.strtoupper(substr($key, 13)).'
  4773. <span class="remove-event"><img style="width: 22px;" src="'.$image.'"></span>
  4774. </div></div>';
  4775. $inputList .= '<input type="hidden" name="'.$key.'">';
  4776. }
  4777. $homepageList .= '</div>';
  4778. $inputList .= '</div>';
  4779. return $homepageList.$inputList;
  4780. }
  4781. function buildHomepage($group, $user){
  4782. $homepageOrder = homepageOrder();
  4783. $homepageBuilt = '';
  4784. foreach ($homepageOrder as $key => $value) {
  4785. $homepageBuilt .= buildHomepageItem($key, $group, $user);
  4786. }
  4787. return $homepageBuilt;
  4788. }
  4789. function realSize($bytes, $decimals = 2) {
  4790. $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
  4791. $factor = floor((strlen($bytes) - 1) / 3);
  4792. return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' '.@$size[$factor];
  4793. }
  4794. function buildHomepageItem($homepageItem, $group, $user){
  4795. $homepageItemBuilt = '';
  4796. switch ($homepageItem) {
  4797. case 'homepageOrderplexsearch':
  4798. if((qualifyUser(PLEXSEARCHAUTH) && PLEXSEARCH == "true" && qualifyUser(PLEXHOMEAUTH))) {
  4799. $homepageItemBuilt .= '
  4800. <div id="searchPlexRow" class="row">
  4801. <div class="col-lg-12">
  4802. <div class="content-box box-shadow big-box todo-list">
  4803. <form id="plexSearchForm" onsubmit="return false;" autocomplete="off">
  4804. <div class="">
  4805. <div class="input-group">
  4806. <div style="border-radius: 25px 0 0 25px; border:0" class="input-group-addon gray-bg"><i class="fa fa-search white"></i></div>
  4807. <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">
  4808. <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>
  4809. <button style="display:none" id="plexSearchForm_submit" class="btn btn-primary waves"></button>
  4810. </div>
  4811. </div>
  4812. </form>
  4813. <div id="resultshere" class="table-responsive"></div>
  4814. </div>
  4815. </div>
  4816. </div>
  4817. ';
  4818. }
  4819. break;
  4820. case 'homepageOrdercustomhtml':
  4821. if (qualifyUser(HOMEPAGECUSTOMHTML1AUTH) && HOMEPAGECUSTOMHTML1) {
  4822. $homepageItemBuilt .= "<div>" . HOMEPAGECUSTOMHTML1 . "</div>";
  4823. }
  4824. break;
  4825. case 'homepageOrdernotice':
  4826. if (qualifyUser(HOMEPAGENOTICEAUTH) && HOMEPAGENOTICETITLE && HOMEPAGENOTICETYPE && HOMEPAGENOTICEMESSAGE && HOMEPAGENOTICELAYOUT) {
  4827. $homepageItemBuilt .= buildHomepageNotice(HOMEPAGENOTICELAYOUT, HOMEPAGENOTICETYPE, HOMEPAGENOTICETITLE, HOMEPAGENOTICEMESSAGE);
  4828. }
  4829. break;
  4830. case 'homepageOrderspeedtest':
  4831. if(SPEEDTEST == "true" && qualifyUser(SPEEDTESTAUTH)){
  4832. $homepageItemBuilt .= '
  4833. <style type="text/css">
  4834. .flash {
  4835. animation: flash 0.6s linear infinite;
  4836. }
  4837. @keyframes flash {
  4838. 0% { opacity: 0.6; }
  4839. 50% { opacity: 1; }
  4840. }
  4841. </style>
  4842. <script type="text/javascript">
  4843. var w = null
  4844. function runTest() {
  4845. document.getElementById("startBtn").style.display = "none"
  4846. document.getElementById("testArea").style.display = ""
  4847. document.getElementById("abortBtn").style.display = ""
  4848. w = new Worker("bower_components/speed/speedtest_worker.js")
  4849. var interval = setInterval(function () { w.postMessage("status") }, 100)
  4850. w.onmessage = function (event) {
  4851. var data = event.data.split(";")
  4852. var status = Number(data[0])
  4853. var dl = document.getElementById("download")
  4854. var ul = document.getElementById("upload")
  4855. var ping = document.getElementById("ping")
  4856. var jitter = document.getElementById("jitter")
  4857. dl.className = status === 1 ? "w-name flash" : "w-name"
  4858. ping.className = status === 2 ? "w-name flash" : "w-name"
  4859. jitter.className = ul.className = status === 3 ? "w-name flash" : "w-name"
  4860. if (status >= 4) {
  4861. clearInterval(interval)
  4862. document.getElementById("abortBtn").style.display = "none"
  4863. document.getElementById("startBtn").style.display = ""
  4864. w = null
  4865. }
  4866. if (status === 5) {
  4867. document.getElementById("testArea").style.display = "none"
  4868. }
  4869. dl.textContent = data[1] + " Mbit/s";
  4870. $("#downloadpercent").attr("style", "width: " + data[1] + "%;");
  4871. $("#uploadpercent").attr("style", "width: " + data[2] + "%;");
  4872. $("#pingpercent").attr("style", "width: " + data[3] + "%;");
  4873. $("#jitterpercent").attr("style", "width: " + data[5] + "%;");
  4874. ul.textContent = data[2] + " Mbit/s";
  4875. ping.textContent = data[3] + " ms";
  4876. jitter.textContent = data[5] + " ms";
  4877. }
  4878. w.postMessage(\'start {"telemetry_level":"basic"}\')
  4879. //w.postMessage("start")
  4880. }
  4881. function abortTest() {
  4882. if (w) w.postMessage("abort")
  4883. }
  4884. </script>
  4885. <div class="row" id="testArea" style="display:none">
  4886. <div class="test col-sm-3 col-lg-3">
  4887. <div class="content-box ultra-widget green-bg" data-counter="">
  4888. <div id="downloadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4889. <div class="w-content">
  4890. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-download"></i></div>
  4891. <div class="w-descr left pull-left text-center">
  4892. <span class="testName text-uppercase w-name">Download</span>
  4893. <br>
  4894. <span class="w-name counter" id="download" ></span>
  4895. </div>
  4896. </div>
  4897. </div>
  4898. </div>
  4899. <div class="test col-sm-3 col-lg-3">
  4900. <div class="content-box ultra-widget red-bg" data-counter="">
  4901. <div id="uploadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4902. <div class="w-content">
  4903. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-upload"></i></div>
  4904. <div class="w-descr left pull-left text-center">
  4905. <span class="testName text-uppercase w-name">Upload</span>
  4906. <br>
  4907. <span class="w-name counter" id="upload" ></span>
  4908. </div>
  4909. </div>
  4910. </div>
  4911. </div>
  4912. <div class="test col-sm-3 col-lg-3">
  4913. <div class="content-box ultra-widget yellow-bg" data-counter="">
  4914. <div id="pingpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4915. <div class="w-content">
  4916. <div class="w-icon right pull-right"><i class="mdi mdi-timer"></i></div>
  4917. <div class="w-descr left pull-left text-center">
  4918. <span class="testName text-uppercase w-name">Latency</span>
  4919. <br>
  4920. <span class="w-name counter" id="ping" ></span>
  4921. </div>
  4922. </div>
  4923. </div>
  4924. </div>
  4925. <div class="test col-sm-3 col-lg-3">
  4926. <div class="content-box ultra-widget blue-bg" data-counter="">
  4927. <div id="jitterpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4928. <div class="w-content">
  4929. <div class="w-icon right pull-right"><i class="mdi mdi-pulse"></i></div>
  4930. <div class="w-descr left pull-left text-center">
  4931. <span class="testName text-uppercase w-name">Jitter</span>
  4932. <br>
  4933. <span class="w-name counter" id="jitter" ></span>
  4934. </div>
  4935. </div>
  4936. </div>
  4937. </div>
  4938. <br/>
  4939. </div>
  4940. <div id="abortBtn" class="row" style="display: none" onclick="javascript:abortTest()">
  4941. <div class="col-lg-12">
  4942. <div class="content-box red-bg" style="cursor: pointer;">
  4943. <h1 style="margin: 10px" class="text-uppercase text-center">Abort Speed Test</h1>
  4944. <div class="clearfix"></div>
  4945. </div>
  4946. </div>
  4947. </div>
  4948. <div id="startBtn" class="row" onclick="javascript:runTest()">
  4949. <div class="col-lg-12">
  4950. <div class="content-box green-bg" style="cursor: pointer;">
  4951. <h1 style="margin: 10px" class="text-uppercase text-center">Run Speed Test</h1>
  4952. <div class="clearfix"></div>
  4953. </div>
  4954. </div>
  4955. </div>
  4956. ';
  4957. }
  4958. break;
  4959. case 'homepageOrdernzbget':
  4960. if(NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)){
  4961. $homepageItemBuilt .= buildDownloader('nzbget');
  4962. }
  4963. break;
  4964. case 'homepageOrdersabnzbd':
  4965. if(SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH)) {
  4966. $homepageItemBuilt .= buildDownloader('sabnzbd');
  4967. }
  4968. break;
  4969. case 'homepageOrderplexnowplaying':
  4970. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4971. if(qualifyUser(PLEXPLAYINGNOWAUTH) && PLEXPLAYINGNOW == "true"){
  4972. $homepageItemBuilt .= '<div id="plexRowNowPlaying" class="row">';
  4973. $homepageItemBuilt .= getPlexStreams(12, PLEXSHOWNAMES, $group);
  4974. $homepageItemBuilt .= '</div>';
  4975. }
  4976. }
  4977. break;
  4978. case 'homepageOrderplexrecent':
  4979. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4980. if(qualifyUser(PLEXRECENTMOVIEAUTH) && PLEXRECENTMOVIE == "true" || qualifyUser(PLEXRECENTTVAUTH) && PLEXRECENTTV == "true" || qualifyUser(PLEXRECENTMUSICAUTH) && PLEXRECENTMUSIC == "true"){
  4981. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  4982. $homepageItemBuilt .= '<div id="plexRow" class="row"><div class="col-lg-12">';
  4983. $homepageItemBuilt .= getPlexRecent($plexArray);
  4984. $homepageItemBuilt .= '</div></div>';
  4985. }
  4986. }
  4987. break;
  4988. case 'homepageOrderplexplaylist':
  4989. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4990. if(qualifyUser(PLEXPLAYLISTSAUTH) && PLEXPLAYLISTS == "true"){
  4991. $homepageItemBuilt .= '<div id="plexPlaylists" class="row"><div class="col-lg-12">';
  4992. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  4993. $homepageItemBuilt .= getPlexPlaylists($plexArray);
  4994. $homepageItemBuilt .= '</div> </div>';
  4995. }
  4996. }
  4997. break;
  4998. case 'homepageOrderembynowplaying':
  4999. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  5000. if(qualifyUser(EMBYPLAYINGNOWAUTH) && EMBYPLAYINGNOW == "true"){
  5001. $homepageItemBuilt .= '<div id="embyRowNowPlaying" class="row">';
  5002. $homepageItemBuilt .= getEmbyStreams(12, EMBYSHOWNAMES, $group);
  5003. $homepageItemBuilt .= '</div>';
  5004. }
  5005. }
  5006. break;
  5007. case 'homepageOrderembyrecent':
  5008. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  5009. if(qualifyUser(EMBYRECENTMOVIEAUTH) && EMBYRECENTMOVIE == "true" || qualifyUser(EMBYRECENTTVAUTH) && EMBYRECENTTV == "true" || qualifyUser(EMBYRECENTMUSICAUTH) && EMBYRECENTMUSIC == "true"){
  5010. $embyArray = array("Movie" => EMBYRECENTMOVIE, "Episode" => EMBYRECENTTV, "MusicAlbum" => EMBYRECENTMUSIC, "Series" => EMBYRECENTTV);
  5011. $homepageItemBuilt .= '<div id="embyRow" class="row"><div class="col-lg-12">';
  5012. $homepageItemBuilt .= getEmbyRecent($embyArray);
  5013. $homepageItemBuilt .= '</div></div>';
  5014. }
  5015. }
  5016. break;
  5017. case 'homepageOrderombi':
  5018. if (qualifyUser(OMBIAUTH) && OMBIURL) {
  5019. $homepageItemBuilt .= '<div id="ombiRequests" class="row"><div class="col-lg-12">';
  5020. $homepageItemBuilt .= buildOmbiList($group, $user);
  5021. $homepageItemBuilt .= '</div></div>';
  5022. }
  5023. break;
  5024. case 'homepageOrdercalendar':
  5025. if ((SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)) || (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)) || (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)) || (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)) || (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH))) {
  5026. $calendarItems = '';
  5027. if(RADARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="film" href="javascript:void(0)">Movies</a></li>'; }
  5028. if(SONARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="tv" href="javascript:void(0)">TV Shows</a></li>'; }
  5029. if(HEADPHONESURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="music" href="javascript:void(0)">Music</a></li>'; }
  5030. $homepageItemBuilt .= '
  5031. <div id="calendarLegendRow" class="row" style="padding: 0 0 10px 0;">
  5032. <div class="col-lg-12 content-form form-inline">
  5033. <div class="form-group pull-right">
  5034. <span class="swal-legend label label-primary well-sm">Legend</span>&nbsp;
  5035. <div class="btn-group" role="group">
  5036. <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>
  5037. <ul style="right:0; left: auto" class="dropdown-menu">
  5038. <li><a class="calendarOption" calendarOption="all" href="javascript:void(0)">View All</a></li>
  5039. '.$calendarItems.'
  5040. </ul>
  5041. </div>
  5042. </div>
  5043. </div>
  5044. </div>
  5045. <div id="calendarRow" class="row">
  5046. <div class="col-lg-12">
  5047. <div id="calendar" class="fc-calendar box-shadow fc fc-ltr fc-unthemed"></div>
  5048. </div>
  5049. </div>
  5050. ';
  5051. }
  5052. break;
  5053. default:
  5054. # code...
  5055. break;
  5056. }
  5057. return $homepageItemBuilt;
  5058. }
  5059. function buildDownloader($name){
  5060. return '
  5061. <div id="downloadClientRow" class="row">
  5062. <div class="col-xs-12 col-md-12">
  5063. <div class="content-box">
  5064. <div class="tabbable panel with-nav-tabs panel-default">
  5065. <div class="panel-heading">
  5066. <div class="content-tools i-block pull-right">
  5067. <a id="getDownloader" class="repeat-btn">
  5068. <i class="fa fa-repeat"></i>
  5069. </a>
  5070. </div>
  5071. <h3 class="pull-left">'.strtoupper($name).'</h3>
  5072. <ul class="nav nav-tabs pull-right">
  5073. <li class="active"><a href="#downloadQueue-'.$name.'" data-toggle="tab" aria-expanded="true">'.translate("QUEUE").'</a></li>
  5074. <li class=""><a href="#downloadHistory-'.$name.'" data-toggle="tab" aria-expanded="false">'.translate("HISTORY").'</a></li>
  5075. </ul>
  5076. <div class="clearfix"></div>
  5077. </div>
  5078. <div class="panel-body">
  5079. <div class="tab-content">
  5080. <div class="tab-pane fade active in" id="downloadQueue-'.$name.'">
  5081. <div class="table-responsive" style="max-height: 300px">
  5082. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5083. <thead>
  5084. <tr>
  5085. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5086. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5087. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5088. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5089. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5090. </tr>
  5091. </thead>
  5092. <tbody class="dl-queue '.$name.'"></tbody>
  5093. </table>
  5094. </div>
  5095. </div>
  5096. <div class="tab-pane fade" id="downloadHistory-'.$name.'">
  5097. <div class="table-responsive" style="max-height: 300px">
  5098. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5099. <thead>
  5100. <tr>
  5101. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5102. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5103. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5104. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5105. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5106. </tr>
  5107. </thead>
  5108. <tbody class="dl-history '.$name.'"></tbody>
  5109. </table>
  5110. </div>
  5111. </div>
  5112. </div>
  5113. </div>
  5114. </div>
  5115. </div>
  5116. </div>
  5117. </div>';
  5118. }
  5119. class Mobile_Detect
  5120. {
  5121. /**
  5122. * Mobile detection type.
  5123. *
  5124. * @deprecated since version 2.6.9
  5125. */
  5126. const DETECTION_TYPE_MOBILE = 'mobile';
  5127. /**
  5128. * Extended detection type.
  5129. *
  5130. * @deprecated since version 2.6.9
  5131. */
  5132. const DETECTION_TYPE_EXTENDED = 'extended';
  5133. /**
  5134. * A frequently used regular expression to extract version #s.
  5135. *
  5136. * @deprecated since version 2.6.9
  5137. */
  5138. const VER = '([\w._\+]+)';
  5139. /**
  5140. * Top-level device.
  5141. */
  5142. const MOBILE_GRADE_A = 'A';
  5143. /**
  5144. * Mid-level device.
  5145. */
  5146. const MOBILE_GRADE_B = 'B';
  5147. /**
  5148. * Low-level device.
  5149. */
  5150. const MOBILE_GRADE_C = 'C';
  5151. /**
  5152. * Stores the version number of the current release.
  5153. */
  5154. const VERSION = '2.8.26';
  5155. /**
  5156. * A type for the version() method indicating a string return value.
  5157. */
  5158. const VERSION_TYPE_STRING = 'text';
  5159. /**
  5160. * A type for the version() method indicating a float return value.
  5161. */
  5162. const VERSION_TYPE_FLOAT = 'float';
  5163. /**
  5164. * A cache for resolved matches
  5165. * @var array
  5166. */
  5167. protected $cache = array();
  5168. /**
  5169. * The User-Agent HTTP header is stored in here.
  5170. * @var string
  5171. */
  5172. protected $userAgent = null;
  5173. /**
  5174. * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.
  5175. * @var array
  5176. */
  5177. protected $httpHeaders = array();
  5178. /**
  5179. * CloudFront headers. E.g. CloudFront-Is-Desktop-Viewer, CloudFront-Is-Mobile-Viewer & CloudFront-Is-Tablet-Viewer.
  5180. * @var array
  5181. */
  5182. protected $cloudfrontHeaders = array();
  5183. /**
  5184. * The matching Regex.
  5185. * This is good for debug.
  5186. * @var string
  5187. */
  5188. protected $matchingRegex = null;
  5189. /**
  5190. * The matches extracted from the regex expression.
  5191. * This is good for debug.
  5192. * @var string
  5193. */
  5194. protected $matchesArray = null;
  5195. /**
  5196. * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.
  5197. *
  5198. * @deprecated since version 2.6.9
  5199. *
  5200. * @var string
  5201. */
  5202. protected $detectionType = self::DETECTION_TYPE_MOBILE;
  5203. /**
  5204. * HTTP headers that trigger the 'isMobile' detection
  5205. * to be true.
  5206. *
  5207. * @var array
  5208. */
  5209. protected static $mobileHeaders = array(
  5210. 'HTTP_ACCEPT' => array('matches' => array(
  5211. // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
  5212. 'application/x-obml2d',
  5213. // BlackBerry devices.
  5214. 'application/vnd.rim.html',
  5215. 'text/vnd.wap.wml',
  5216. 'application/vnd.wap.xhtml+xml'
  5217. )),
  5218. 'HTTP_X_WAP_PROFILE' => null,
  5219. 'HTTP_X_WAP_CLIENTID' => null,
  5220. 'HTTP_WAP_CONNECTION' => null,
  5221. 'HTTP_PROFILE' => null,
  5222. // Reported by Opera on Nokia devices (eg. C3).
  5223. 'HTTP_X_OPERAMINI_PHONE_UA' => null,
  5224. 'HTTP_X_NOKIA_GATEWAY_ID' => null,
  5225. 'HTTP_X_ORANGE_ID' => null,
  5226. 'HTTP_X_VODAFONE_3GPDPCONTEXT' => null,
  5227. 'HTTP_X_HUAWEI_USERID' => null,
  5228. // Reported by Windows Smartphones.
  5229. 'HTTP_UA_OS' => null,
  5230. // Reported by Verizon, Vodafone proxy system.
  5231. 'HTTP_X_MOBILE_GATEWAY' => null,
  5232. // Seen this on HTC Sensation. SensationXE_Beats_Z715e.
  5233. 'HTTP_X_ATT_DEVICEID' => null,
  5234. // Seen this on a HTC.
  5235. 'HTTP_UA_CPU' => array('matches' => array('ARM')),
  5236. );
  5237. /**
  5238. * List of mobile devices (phones).
  5239. *
  5240. * @var array
  5241. */
  5242. protected static $phoneDevices = array(
  5243. 'iPhone' => '\biPhone\b|\biPod\b', // |\biTunes
  5244. 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+',
  5245. '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',
  5246. 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 6',
  5247. // @todo: Is 'Dell Streak' a tablet or a phone? ;)
  5248. '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',
  5249. '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',
  5250. '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',
  5251. '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)',
  5252. 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|LT26w|SonyEricssonMT27i|C5303|C6902|C6903|C6906|C6943|D2533',
  5253. 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile',
  5254. 'NokiaLumia' => 'Lumia [0-9]{3,4}',
  5255. // http://www.micromaxinfo.com/mobiles/smartphones
  5256. // Added because the codes might conflict with Acer Tablets.
  5257. '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',
  5258. // @todo Complete the regex.
  5259. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ;
  5260. 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
  5261. // http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
  5262. // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android.
  5263. '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',
  5264. // http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones.
  5265. 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250',
  5266. // http://fr.wikomobile.com
  5267. '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',
  5268. 'iMobile' => 'i-mobile (IQ|i-STYLE|idea|ZAA|Hitz)',
  5269. // Added simvalley mobile just for fun. They have some interesting devices.
  5270. // http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html
  5271. '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',
  5272. // Wolfgang - a brand that is sold by Aldi supermarkets.
  5273. // http://www.wolfgangmobile.com/
  5274. 'Wolfgang' => 'AT-B24D|AT-AS50HD|AT-AS40W|AT-AS55HD|AT-AS45q2|AT-B26D|AT-AS50Q',
  5275. 'Alcatel' => 'Alcatel',
  5276. 'Nintendo' => 'Nintendo 3DS',
  5277. // http://en.wikipedia.org/wiki/Amoi
  5278. 'Amoi' => 'Amoi',
  5279. // http://en.wikipedia.org/wiki/INQ
  5280. 'INQ' => 'INQ',
  5281. // @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039
  5282. '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',
  5283. );
  5284. /**
  5285. * List of tablet devices.
  5286. *
  5287. * @var array
  5288. */
  5289. protected static $tabletDevices = array(
  5290. // @todo: check for mobile friendly emails topic.
  5291. 'iPad' => 'iPad|iPad.*Mobile',
  5292. // Removed |^.*Android.*Nexus(?!(?:Mobile).)*$
  5293. // @see #442
  5294. 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)',
  5295. '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.
  5296. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
  5297. '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)',
  5298. // Only the Surface tablets with Windows RT are considered mobile.
  5299. // http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx
  5300. 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;.*(Tablet|ARMBJS)',
  5301. // http://shopping1.hp.com/is-bin/INTERSHOP.enfinity/WFS/WW-USSMBPublicStore-Site/en_US/-/USD/ViewStandardCatalog-Browse?CatalogCategoryID=JfIQ7EN5lqMAAAEyDcJUDwMT
  5302. 'HPTablet' => 'HP Slate (7|8|10)|HP ElitePad 900|hp-tablet|EliteBook.*Touch|HP 8|Slate 21|HP SlateBook 10',
  5303. // Watch out for PadFone, see #132.
  5304. // http://www.asus.com/de/Tablets_Mobile/Memo_Pad_Products/
  5305. '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',
  5306. 'BlackBerryTablet' => 'PlayBook|RIM Tablet',
  5307. 'HTCtablet' => 'HTC_Flyer_P512|HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200|PG09410',
  5308. 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617',
  5309. 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2',
  5310. // http://www.acer.ro/ac/ro/RO/content/drivers
  5311. // http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer)
  5312. // http://us.acer.com/ac/en/US/content/group/tablets
  5313. // http://www.acer.de/ac/de/DE/content/models/tablets/
  5314. // Can conflict with Micromax and Motorola phones codes.
  5315. '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',
  5316. // http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/
  5317. // http://us.toshiba.com/tablets/tablet-finder
  5318. // http://www.toshiba.co.jp/regza/tablet/
  5319. 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO',
  5320. // http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html
  5321. // http://www.lg.com/us/tablets
  5322. 'LGTablet' => '\bL-06C|LG-V909|LG-V900|LG-V700|LG-V510|LG-V500|LG-V410|LG-V400|LG-VK810\b',
  5323. 'FujitsuTablet' => 'Android.*\b(F-01D|F-02F|F-05E|F-10D|M532|Q572)\b',
  5324. // Prestigio Tablets http://www.prestigio.com/support
  5325. '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',
  5326. // http://support.lenovo.com/en_GB/downloads/default.page?#
  5327. '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|)',
  5328. // http://www.dell.com/support/home/us/en/04/Products/tab_mob/tablets
  5329. 'DellTablet' => 'Venue 11|Venue 8|Venue 7|Dell Streak 10|Dell Streak 7',
  5330. // http://www.yarvik.com/en/matrix/tablets/
  5331. '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',
  5332. 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB',
  5333. 'ArnovaTablet' => '97G4|AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT|AN9G2',
  5334. // http://www.intenso.de/kategorie_en.php?kategorie=33
  5335. // @todo: http://www.nbhkdz.com/read/b8e64202f92a2df129126bff.html - investigate
  5336. 'IntensoTablet' => 'INM8002KP|INM1010FP|INM805ND|Intenso Tab|TAB1004',
  5337. // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/
  5338. 'IRUTablet' => 'M702pro',
  5339. 'MegafonTablet' => 'MegaFon V9|\bZTE V9\b|Android.*\bMT7A\b',
  5340. // http://www.e-boda.ro/tablete-pc.html
  5341. 'EbodaTablet' => 'E-Boda (Supreme|Impresspeed|Izzycomm|Essential)',
  5342. // http://www.allview.ro/produse/droseries/lista-tablete-pc/
  5343. 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)',
  5344. // http://wiki.archosfans.com/index.php?title=Main_Page
  5345. // @note Rewrite the regex format after we add more UAs.
  5346. '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',
  5347. // http://www.ainol.com/plugin.php?identifier=ainol&module=product
  5348. 'AinolTablet' => 'NOVO7|NOVO8|NOVO10|Novo7Aurora|Novo7Basic|NOVO7PALADIN|novo9-Spark',
  5349. 'NokiaLumiaTablet' => 'Lumia 2520',
  5350. // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER
  5351. // Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser
  5352. // http://www.sony.jp/support/tablet/
  5353. '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',
  5354. // 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
  5355. 'PhilipsTablet' => '\b(PI2010|PI3000|PI3100|PI3105|PI3110|PI3205|PI3210|PI3900|PI4010|PI7000|PI7100)\b',
  5356. // db + http://www.cube-tablet.com/buy-products.html
  5357. 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT',
  5358. // http://www.cobyusa.com/?p=pcat&pcat_id=3001
  5359. 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010',
  5360. // http://www.match.net.cn/products.asp
  5361. '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',
  5362. // http://www.msi.com/support
  5363. // @todo Research the Windows Tablets.
  5364. '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',
  5365. // @todo http://www.kyoceramobile.com/support/drivers/
  5366. // 'KyoceraTablet' => null,
  5367. // @todo http://intexuae.com/index.php/category/mobile-devices/tablets-products/
  5368. // 'IntextTablet' => null,
  5369. // http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets)
  5370. // http://www.imp3.net/14/show.php?itemid=20454
  5371. 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)',
  5372. // http://www.rock-chips.com/index.php?do=prod&pid=2
  5373. 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A',
  5374. // http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/
  5375. 'FlyTablet' => 'IQ310|Fly Vision',
  5376. // http://www.bqreaders.com/gb/tablets-prices-sale.html
  5377. 'bqTablet' => 'Android.*(bq)?.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris [E|M]10)|Maxwell.*Lite|Maxwell.*Plus',
  5378. // http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
  5379. // http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
  5380. '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',
  5381. // Nec or Medias Tab
  5382. 'NecTablet' => '\bN-06D|\bN-08D',
  5383. // Pantech Tablets: http://www.pantechusa.com/phones/
  5384. 'PantechTablet' => 'Pantech.*P4100',
  5385. // Broncho Tablets: http://www.broncho.cn/ (hard to find)
  5386. 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)',
  5387. // http://versusuk.com/support.html
  5388. 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b',
  5389. // http://www.zync.in/index.php/our-products/tablet-phablets
  5390. 'ZyncTablet' => 'z1000|Z99 2G|z99|z930|z999|z990|z909|Z919|z900',
  5391. // http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/
  5392. 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA',
  5393. // https://www.nabitablet.com/
  5394. 'NabiTablet' => 'Android.*\bNabi',
  5395. 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build',
  5396. // French Danew Tablets http://www.danew.com/produits-tablette.php
  5397. 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b',
  5398. // Texet Tablets and Readers http://www.texet.ru/tablet/
  5399. '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',
  5400. // Avoid detecting 'PLAYSTATION 3' as mobile.
  5401. 'PlaystationTablet' => 'Playstation.*(Portable|Vita)',
  5402. // http://www.trekstor.de/surftabs.html
  5403. 'TrekstorTablet' => 'ST10416-1|VT10416-1|ST70408-1|ST702xx-1|ST702xx-2|ST80208|ST97216|ST70104-2|VT10416-2|ST10216-2A|SurfTab',
  5404. // http://www.pyleaudio.com/Products.aspx?%2fproducts%2fPersonal-Electronics%2fTablets
  5405. 'PyleAudioTablet' => '\b(PTBL10CEU|PTBL10C|PTBL72BC|PTBL72BCEU|PTBL7CEU|PTBL7C|PTBL92BC|PTBL92BCEU|PTBL9CEU|PTBL9CUK|PTBL9C)\b',
  5406. // http://www.advandigital.com/index.php?link=content-product&jns=JP001
  5407. // because of the short codenames we have to include whitespaces to reduce the possible conflicts.
  5408. '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 ',
  5409. // http://www.danytech.com/category/tablet-pc
  5410. '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',
  5411. // http://www.galapad.net/product.html
  5412. 'GalapadTablet' => 'Android.*\bG1\b',
  5413. // http://www.micromaxinfo.com/tablet/funbook
  5414. 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b',
  5415. // http://www.karbonnmobiles.com/products_tablet.php
  5416. 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b',
  5417. // http://www.myallfine.com/Products.asp
  5418. 'AllFineTablet' => 'Fine7 Genius|Fine7 Shine|Fine7 Air|Fine8 Style|Fine9 More|Fine10 Joy|Fine11 Wide',
  5419. // http://www.proscanvideo.com/products-search.asp?itemClass=TABLET&itemnmbr=
  5420. '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',
  5421. // http://www.yonesnav.com/products/products.php
  5422. 'YONESTablet' => 'BQ1078|BC1003|BC1077|RK9702|BC9730|BC9001|IT9001|BC7008|BC7010|BC708|BC728|BC7012|BC7030|BC7027|BC7026',
  5423. // http://www.cjshowroom.com/eproducts.aspx?classcode=004001001
  5424. // China manufacturer makes tablets for different small brands (eg. http://www.zeepad.net/index.html)
  5425. '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',
  5426. // http://www.gloryunion.cn/products.asp
  5427. // http://www.allwinnertech.com/en/apply/mobile.html
  5428. // http://www.ptcl.com.pk/pd_content.php?pd_id=284 (EVOTAB)
  5429. // @todo: Softwiner tablets?
  5430. // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions.
  5431. '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
  5432. // http://www.pointofview-online.com/showroom.php?shop_mode=product_listing&category_id=118
  5433. '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',
  5434. // http://www.overmax.pl/pl/katalog-produktow,p8/tablety,c14/
  5435. // @todo: add more tests.
  5436. 'OvermaxTablet' => 'OV-(SteelCore|NewBase|Basecore|Baseone|Exellen|Quattor|EduTab|Solution|ACTION|BasicTab|TeddyTab|MagicTab|Stream|TB-08|TB-09)',
  5437. // http://hclmetablet.com/India/index.php
  5438. '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',
  5439. // http://www.edigital.hu/Tablet_es_e-book_olvaso/Tablet-c18385.html
  5440. 'DPSTablet' => 'DPS Dream 9|DPS Dual 7',
  5441. // http://www.visture.com/index.asp
  5442. 'VistureTablet' => 'V97 HD|i75 3G|Visture V4( HD)?|Visture V5( HD)?|Visture V10',
  5443. // http://www.mijncresta.nl/tablet
  5444. 'CrestaTablet' => 'CTP(-)?810|CTP(-)?818|CTP(-)?828|CTP(-)?838|CTP(-)?888|CTP(-)?978|CTP(-)?980|CTP(-)?987|CTP(-)?988|CTP(-)?989',
  5445. // MediaTek - http://www.mediatek.com/_en/01_products/02_proSys.php?cata_sn=1&cata1_sn=1&cata2_sn=309
  5446. 'MediatekTablet' => '\bMT8125|MT8389|MT8135|MT8377\b',
  5447. // Concorde tab
  5448. 'ConcordeTablet' => 'Concorde([ ]+)?Tab|ConCorde ReadMan',
  5449. // GoClever Tablets - http://www.goclever.com/uk/products,c1/tablet,c5/
  5450. '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',
  5451. // Modecom Tablets - http://www.modecom.eu/tablets/portal/
  5452. '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',
  5453. // Vonino Tablets - http://www.vonino.eu/tablets
  5454. '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',
  5455. // ECS Tablets - http://www.ecs.com.tw/ECSWebSite/Product/Product_Tablet_List.aspx?CategoryID=14&MenuID=107&childid=M_107&LanID=0
  5456. 'ECSTablet' => 'V07OT2|TM105A|S10OT1|TR10CS1',
  5457. // Storex Tablets - http://storex.fr/espace_client/support.html
  5458. // @note: no need to add all the tablet codes since they are guided by the first regex.
  5459. 'StorexTablet' => 'eZee[_\']?(Tab|Go)[0-9]+|TabLC7|Looney Tunes Tab',
  5460. // Generic Vodafone tablets.
  5461. 'VodafoneTablet' => 'SmartTab([ ]+)?[0-9]+|SmartTabII10|SmartTabII7|VF-1497',
  5462. // French tablets - Essentiel B http://www.boulanger.fr/tablette_tactile_e-book/tablette_tactile_essentiel_b/cl_68908.htm?multiChoiceToDelete=brand&mc_brand=essentielb
  5463. // Aka: http://www.essentielb.fr/
  5464. 'EssentielBTablet' => 'Smart[ \']?TAB[ ]+?[0-9]+|Family[ \']?TAB2',
  5465. // Ross & Moor - http://ross-moor.ru/
  5466. 'RossMoorTablet' => 'RM-790|RM-997|RMD-878G|RMD-974R|RMT-705A|RMT-701|RME-601|RMT-501|RMT-711',
  5467. // i-mobile http://product.i-mobilephone.com/Mobile_Device
  5468. 'iMobileTablet' => 'i-mobile i-note',
  5469. // http://www.tolino.de/de/vergleichen/
  5470. 'TolinoTablet' => 'tolino tab [0-9.]+|tolino shine',
  5471. // AudioSonic - a Kmart brand
  5472. // 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
  5473. 'AudioSonicTablet' => '\bC-22Q|T7-QC|T-17B|T-17P\b',
  5474. // AMPE Tablets - http://www.ampe.com.my/product-category/tablets/
  5475. // @todo: add them gradually to avoid conflicts.
  5476. 'AMPETablet' => 'Android.* A78 ',
  5477. // Skk Mobile - http://skkmobile.com.ph/product_tablets.php
  5478. 'SkkTablet' => 'Android.* (SKYPAD|PHOENIX|CYCLOPS)',
  5479. // Tecno Mobile (only tablet) - http://www.tecno-mobile.com/index.php/product?filterby=smart&list_order=all&page=1
  5480. 'TecnoTablet' => 'TECNO P9',
  5481. // JXD (consoles & tablets) - http://jxd.hk/products.asp?selectclassid=009008&clsid=3
  5482. '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',
  5483. // i-Joy tablets - http://www.i-joy.es/en/cat/products/tablets/
  5484. '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)',
  5485. // http://www.intracon.eu/tablet
  5486. 'FX2Tablet' => 'FX2 PAD7|FX2 PAD10',
  5487. // http://www.xoro.de/produkte/
  5488. // @note: Might be the same brand with 'Simply tablets'
  5489. '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',
  5490. // http://www1.viewsonic.com/products/computing/tablets/
  5491. 'ViewsonicTablet' => 'ViewPad 10pi|ViewPad 10e|ViewPad 10s|ViewPad E72|ViewPad7|ViewPad E100|ViewPad 7e|ViewSonic VB733|VB100a',
  5492. // http://www.odys.de/web/internet-tablet_en.html
  5493. 'OdysTablet' => 'LOOX|XENO10|ODYS[ -](Space|EVO|Xpress|NOON)|\bXELIO\b|Xelio10Pro|XELIO7PHONETAB|XELIO10EXTREME|XELIOPT2|NEO_QUAD10',
  5494. // http://www.captiva-power.de/products.html#tablets-en
  5495. 'CaptivaTablet' => 'CAPTIVA PAD',
  5496. // IconBIT - http://www.iconbit.com/products/tablets/
  5497. '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',
  5498. // http://www.teclast.com/topic.php?channelID=70&topicID=140&pid=63
  5499. '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',
  5500. // Onda - http://www.onda-tablet.com/buy-android-onda.html?dir=desc&limit=all&order=price
  5501. '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]+',
  5502. 'JaytechTablet' => 'TPC-PA762',
  5503. 'BlaupunktTablet' => 'Endeavour 800NG|Endeavour 1010',
  5504. // http://www.digma.ru/support/download/
  5505. // @todo: Ebooks also (if requested)
  5506. 'DigmaTablet' => '\b(iDx10|iDx9|iDx8|iDx7|iDxD7|iDxD8|iDsQ8|iDsQ7|iDsQ8|iDsD10|iDnD7|3TS804H|iDsQ11|iDj7|iDs10)\b',
  5507. // http://www.evolioshop.com/ro/tablete-pc.html
  5508. // http://www.evolio.ro/support/downloads_static.html?cat=2
  5509. // @todo: Research some more
  5510. 'EvolioTablet' => 'ARIA_Mini_wifi|Aria[ _]Mini|Evolio X10|Evolio X7|Evolio X8|\bEvotab\b|\bNeura\b',
  5511. // @todo http://www.lavamobiles.com/tablets-data-cards
  5512. 'LavaTablet' => 'QPAD E704|\bIvoryS\b|E-TAB IVORY|\bE-TAB\b',
  5513. // http://www.breezetablet.com/
  5514. 'AocTablet' => 'MW0811|MW0812|MW0922|MTK8382|MW1031|MW0831|MW0821|MW0931|MW0712',
  5515. // http://www.mpmaneurope.com/en/products/internet-tablets-14/android-tablets-14/
  5516. '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',
  5517. // https://www.celkonmobiles.com/?_a=categoryphones&sid=2
  5518. 'CelkonTablet' => 'CT695|CT888|CT[\s]?910|CT7 Tab|CT9 Tab|CT3 Tab|CT2 Tab|CT1 Tab|C820|C720|\bCT-1\b',
  5519. // http://www.wolderelectronics.com/productos/manuales-y-guias-rapidas/categoria-2-miTab
  5520. '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',
  5521. // http://www.mi.com/en
  5522. 'MiTablet' => '\bMI PAD\b|\bHM NOTE 1W\b',
  5523. // http://www.nbru.cn/index.html
  5524. 'NibiruTablet' => 'Nibiru M1|Nibiru Jupiter One',
  5525. // http://navroad.com/products/produkty/tablety/
  5526. // http://navroad.com/products/produkty/tablety/
  5527. 'NexoTablet' => 'NEXO NOVA|NEXO 10|NEXO AVIO|NEXO FREE|NEXO GO|NEXO EVO|NEXO 3G|NEXO SMART|NEXO KIDDO|NEXO MOBI',
  5528. // http://leader-online.com/new_site/product-category/tablets/
  5529. // http://www.leader-online.net.au/List/Tablet
  5530. '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',
  5531. // http://www.datawind.com/ubislate/
  5532. 'UbislateTablet' => 'UbiSlate[\s]?7C',
  5533. // http://www.pocketbook-int.com/ru/support
  5534. 'PocketBookTablet' => 'Pocketbook',
  5535. // http://www.kocaso.com/product_tablet.html
  5536. 'KocasoTablet' => '\b(TB-1207)\b',
  5537. // http://global.hisense.com/product/asia/tablet/Sero7/201412/t20141215_91832.htm
  5538. 'HisenseTablet' => '\b(F5281|E2371)\b',
  5539. // http://www.tesco.com/direct/hudl/
  5540. 'Hudl' => 'Hudl HT7S3|Hudl 2',
  5541. // http://www.telstra.com.au/home-phone/thub-2/
  5542. 'TelstraTablet' => 'T-Hub2',
  5543. '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'
  5544. );
  5545. /**
  5546. * List of mobile Operating Systems.
  5547. *
  5548. * @var array
  5549. */
  5550. protected static $operatingSystems = array(
  5551. 'AndroidOS' => 'Android',
  5552. 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os',
  5553. 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
  5554. 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
  5555. // @reference: http://en.wikipedia.org/wiki/Windows_Mobile
  5556. 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;',
  5557. // @reference: http://en.wikipedia.org/wiki/Windows_Phone
  5558. // http://wifeng.cn/?r=blog&a=view&id=106
  5559. // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx
  5560. // http://msdn.microsoft.com/library/ms537503.aspx
  5561. // https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
  5562. 'WindowsPhoneOS' => 'Windows Phone 10.0|Windows Phone 8.1|Windows Phone 8.0|Windows Phone OS|XBLWP7|ZuneWP7|Windows NT 6.[23]; ARM;',
  5563. 'iOS' => '\biPhone.*Mobile|\biPod|\biPad',
  5564. // http://en.wikipedia.org/wiki/MeeGo
  5565. // @todo: research MeeGo in UAs
  5566. 'MeeGoOS' => 'MeeGo',
  5567. // http://en.wikipedia.org/wiki/Maemo
  5568. // @todo: research Maemo in UAs
  5569. 'MaemoOS' => 'Maemo',
  5570. 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135
  5571. 'webOS' => 'webOS|hpwOS',
  5572. 'badaOS' => '\bBada\b',
  5573. 'BREWOS' => 'BREW',
  5574. );
  5575. /**
  5576. * List of mobile User Agents.
  5577. *
  5578. * IMPORTANT: This is a list of only mobile browsers.
  5579. * Mobile Detect 2.x supports only mobile browsers,
  5580. * it was never designed to detect all browsers.
  5581. * The change will come in 2017 in the 3.x release for PHP7.
  5582. *
  5583. * @var array
  5584. */
  5585. protected static $browsers = array(
  5586. //'Vivaldi' => 'Vivaldi',
  5587. // @reference: https://developers.google.com/chrome/mobile/docs/user-agent
  5588. 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?',
  5589. 'Dolfin' => '\bDolfin\b',
  5590. 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+|Coast/[0-9.]+',
  5591. 'Skyfire' => 'Skyfire',
  5592. 'Edge' => 'Mobile Safari/[.0-9]* Edge',
  5593. 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+
  5594. 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS',
  5595. 'Bolt' => 'bolt',
  5596. 'TeaShark' => 'teashark',
  5597. 'Blazer' => 'Blazer',
  5598. // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3
  5599. 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari',
  5600. // http://en.wikipedia.org/wiki/Midori_(web_browser)
  5601. //'Midori' => 'midori',
  5602. //'Tizen' => 'Tizen',
  5603. 'UCBrowser' => 'UC.*Browser|UCWEB',
  5604. 'baiduboxapp' => 'baiduboxapp',
  5605. 'baidubrowser' => 'baidubrowser',
  5606. // https://github.com/serbanghita/Mobile-Detect/issues/7
  5607. 'DiigoBrowser' => 'DiigoBrowser',
  5608. // http://www.puffinbrowser.com/index.php
  5609. 'Puffin' => 'Puffin',
  5610. // http://mercury-browser.com/index.html
  5611. 'Mercury' => '\bMercury\b',
  5612. // http://en.wikipedia.org/wiki/Obigo_Browser
  5613. 'ObigoBrowser' => 'Obigo',
  5614. // http://en.wikipedia.org/wiki/NetFront
  5615. 'NetFront' => 'NF-Browser',
  5616. // @reference: http://en.wikipedia.org/wiki/Minimo
  5617. // http://en.wikipedia.org/wiki/Vision_Mobile_Browser
  5618. 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger',
  5619. // @reference: https://en.wikipedia.org/wiki/Pale_Moon_(web_browser)
  5620. 'PaleMoon' => 'Android.*PaleMoon|Mobile.*PaleMoon',
  5621. );
  5622. /**
  5623. * Utilities.
  5624. *
  5625. * @var array
  5626. */
  5627. protected static $utilities = array(
  5628. // Experimental. When a mobile device wants to switch to 'Desktop Mode'.
  5629. // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/
  5630. // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011
  5631. // https://developers.facebook.com/docs/sharing/best-practices
  5632. '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',
  5633. 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2',
  5634. 'DesktopMode' => 'WPDesktop',
  5635. 'TV' => 'SonyDTV|HbbTV', // experimental
  5636. 'WebKit' => '(webkit)[ /]([\w.]+)',
  5637. // @todo: Include JXD consoles.
  5638. 'Console' => '\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b',
  5639. 'Watch' => 'SM-V700',
  5640. );
  5641. /**
  5642. * All possible HTTP headers that represent the
  5643. * User-Agent string.
  5644. *
  5645. * @var array
  5646. */
  5647. protected static $uaHttpHeaders = array(
  5648. // The default User-Agent string.
  5649. 'HTTP_USER_AGENT',
  5650. // Header can occur on devices using Opera Mini.
  5651. 'HTTP_X_OPERAMINI_PHONE_UA',
  5652. // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
  5653. 'HTTP_X_DEVICE_USER_AGENT',
  5654. 'HTTP_X_ORIGINAL_USER_AGENT',
  5655. 'HTTP_X_SKYFIRE_PHONE',
  5656. 'HTTP_X_BOLT_PHONE_UA',
  5657. 'HTTP_DEVICE_STOCK_UA',
  5658. 'HTTP_X_UCBROWSER_DEVICE_UA'
  5659. );
  5660. /**
  5661. * The individual segments that could exist in a User-Agent string. VER refers to the regular
  5662. * expression defined in the constant self::VER.
  5663. *
  5664. * @var array
  5665. */
  5666. protected static $properties = array(
  5667. // Build
  5668. 'Mobile' => 'Mobile/[VER]',
  5669. 'Build' => 'Build/[VER]',
  5670. 'Version' => 'Version/[VER]',
  5671. 'VendorID' => 'VendorID/[VER]',
  5672. // Devices
  5673. 'iPad' => 'iPad.*CPU[a-z ]+[VER]',
  5674. 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]',
  5675. 'iPod' => 'iPod.*CPU[a-z ]+[VER]',
  5676. //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'),
  5677. 'Kindle' => 'Kindle/[VER]',
  5678. // Browser
  5679. 'Chrome' => array('Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'),
  5680. 'Coast' => array('Coast/[VER]'),
  5681. 'Dolfin' => 'Dolfin/[VER]',
  5682. // @reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
  5683. 'Firefox' => array('Firefox/[VER]', 'FxiOS/[VER]'),
  5684. 'Fennec' => 'Fennec/[VER]',
  5685. // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
  5686. // https://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
  5687. 'Edge' => 'Edge/[VER]',
  5688. 'IE' => array('IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'Trident/[0-9.]+;.*rv:[VER]'),
  5689. // http://en.wikipedia.org/wiki/NetFront
  5690. 'NetFront' => 'NetFront/[VER]',
  5691. 'NokiaBrowser' => 'NokiaBrowser/[VER]',
  5692. 'Opera' => array( ' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]' ),
  5693. 'Opera Mini' => 'Opera Mini/[VER]',
  5694. 'Opera Mobi' => 'Version/[VER]',
  5695. 'UC Browser' => 'UC Browser[VER]',
  5696. 'MQQBrowser' => 'MQQBrowser/[VER]',
  5697. 'MicroMessenger' => 'MicroMessenger/[VER]',
  5698. 'baiduboxapp' => 'baiduboxapp/[VER]',
  5699. 'baidubrowser' => 'baidubrowser/[VER]',
  5700. 'SamsungBrowser' => 'SamsungBrowser/[VER]',
  5701. 'Iron' => 'Iron/[VER]',
  5702. // @note: Safari 7534.48.3 is actually Version 5.1.
  5703. // @note: On BlackBerry the Version is overwriten by the OS.
  5704. 'Safari' => array( 'Version/[VER]', 'Safari/[VER]' ),
  5705. 'Skyfire' => 'Skyfire/[VER]',
  5706. 'Tizen' => 'Tizen/[VER]',
  5707. 'Webkit' => 'webkit[ /][VER]',
  5708. 'PaleMoon' => 'PaleMoon/[VER]',
  5709. // Engine
  5710. 'Gecko' => 'Gecko/[VER]',
  5711. 'Trident' => 'Trident/[VER]',
  5712. 'Presto' => 'Presto/[VER]',
  5713. 'Goanna' => 'Goanna/[VER]',
  5714. // OS
  5715. 'iOS' => ' \bi?OS\b [VER][ ;]{1}',
  5716. 'Android' => 'Android [VER]',
  5717. 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'),
  5718. 'BREW' => 'BREW [VER]',
  5719. 'Java' => 'Java/[VER]',
  5720. // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx
  5721. // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases
  5722. 'Windows Phone OS' => array( 'Windows Phone OS [VER]', 'Windows Phone [VER]'),
  5723. 'Windows Phone' => 'Windows Phone [VER]',
  5724. 'Windows CE' => 'Windows CE/[VER]',
  5725. // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd
  5726. 'Windows NT' => 'Windows NT [VER]',
  5727. 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'),
  5728. 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'),
  5729. );
  5730. /**
  5731. * Construct an instance of this class.
  5732. *
  5733. * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored.
  5734. * If left empty, will use the global _SERVER['HTTP_*'] vars instead.
  5735. * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
  5736. * from the $headers array instead.
  5737. */
  5738. public function __construct(
  5739. array $headers = null,
  5740. $userAgent = null
  5741. ) {
  5742. $this->setHttpHeaders($headers);
  5743. $this->setUserAgent($userAgent);
  5744. }
  5745. /**
  5746. * Get the current script version.
  5747. * This is useful for the demo.php file,
  5748. * so people can check on what version they are testing
  5749. * for mobile devices.
  5750. *
  5751. * @return string The version number in semantic version format.
  5752. */
  5753. public static function getScriptVersion()
  5754. {
  5755. return self::VERSION;
  5756. }
  5757. /**
  5758. * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
  5759. *
  5760. * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
  5761. * the headers. The default null is left for backwards compatibility.
  5762. */
  5763. public function setHttpHeaders($httpHeaders = null)
  5764. {
  5765. // use global _SERVER if $httpHeaders aren't defined
  5766. if (!is_array($httpHeaders) || !count($httpHeaders)) {
  5767. $httpHeaders = $_SERVER;
  5768. }
  5769. // clear existing headers
  5770. $this->httpHeaders = array();
  5771. // Only save HTTP headers. In PHP land, that means only _SERVER vars that
  5772. // start with HTTP_.
  5773. foreach ($httpHeaders as $key => $value) {
  5774. if (substr($key, 0, 5) === 'HTTP_') {
  5775. $this->httpHeaders[$key] = $value;
  5776. }
  5777. }
  5778. // In case we're dealing with CloudFront, we need to know.
  5779. $this->setCfHeaders($httpHeaders);
  5780. }
  5781. /**
  5782. * Retrieves the HTTP headers.
  5783. *
  5784. * @return array
  5785. */
  5786. public function getHttpHeaders()
  5787. {
  5788. return $this->httpHeaders;
  5789. }
  5790. /**
  5791. * Retrieves a particular header. If it doesn't exist, no exception/error is caused.
  5792. * Simply null is returned.
  5793. *
  5794. * @param string $header The name of the header to retrieve. Can be HTTP compliant such as
  5795. * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the
  5796. * all-caps, HTTP_ prefixed, underscore seperated awesomeness.
  5797. *
  5798. * @return string|null The value of the header.
  5799. */
  5800. public function getHttpHeader($header)
  5801. {
  5802. // are we using PHP-flavored headers?
  5803. if (strpos($header, '_') === false) {
  5804. $header = str_replace('-', '_', $header);
  5805. $header = strtoupper($header);
  5806. }
  5807. // test the alternate, too
  5808. $altHeader = 'HTTP_' . $header;
  5809. //Test both the regular and the HTTP_ prefix
  5810. if (isset($this->httpHeaders[$header])) {
  5811. return $this->httpHeaders[$header];
  5812. } elseif (isset($this->httpHeaders[$altHeader])) {
  5813. return $this->httpHeaders[$altHeader];
  5814. }
  5815. return null;
  5816. }
  5817. public function getMobileHeaders()
  5818. {
  5819. return self::$mobileHeaders;
  5820. }
  5821. /**
  5822. * Get all possible HTTP headers that
  5823. * can contain the User-Agent string.
  5824. *
  5825. * @return array List of HTTP headers.
  5826. */
  5827. public function getUaHttpHeaders()
  5828. {
  5829. return self::$uaHttpHeaders;
  5830. }
  5831. /**
  5832. * Set CloudFront headers
  5833. * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device
  5834. *
  5835. * @param array $cfHeaders List of HTTP headers
  5836. *
  5837. * @return boolean If there were CloudFront headers to be set
  5838. */
  5839. public function setCfHeaders($cfHeaders = null) {
  5840. // use global _SERVER if $cfHeaders aren't defined
  5841. if (!is_array($cfHeaders) || !count($cfHeaders)) {
  5842. $cfHeaders = $_SERVER;
  5843. }
  5844. // clear existing headers
  5845. $this->cloudfrontHeaders = array();
  5846. // Only save CLOUDFRONT headers. In PHP land, that means only _SERVER vars that
  5847. // start with cloudfront-.
  5848. $response = false;
  5849. foreach ($cfHeaders as $key => $value) {
  5850. if (substr(strtolower($key), 0, 16) === 'http_cloudfront_') {
  5851. $this->cloudfrontHeaders[strtoupper($key)] = $value;
  5852. $response = true;
  5853. }
  5854. }
  5855. return $response;
  5856. }
  5857. /**
  5858. * Retrieves the cloudfront headers.
  5859. *
  5860. * @return array
  5861. */
  5862. public function getCfHeaders()
  5863. {
  5864. return $this->cloudfrontHeaders;
  5865. }
  5866. /**
  5867. * Set the User-Agent to be used.
  5868. *
  5869. * @param string $userAgent The user agent string to set.
  5870. *
  5871. * @return string|null
  5872. */
  5873. public function setUserAgent($userAgent = null)
  5874. {
  5875. // Invalidate cache due to #375
  5876. $this->cache = array();
  5877. if (false === empty($userAgent)) {
  5878. return $this->userAgent = $userAgent;
  5879. } else {
  5880. $this->userAgent = null;
  5881. foreach ($this->getUaHttpHeaders() as $altHeader) {
  5882. if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban)
  5883. $this->userAgent .= $this->httpHeaders[$altHeader] . " ";
  5884. }
  5885. }
  5886. if (!empty($this->userAgent)) {
  5887. return $this->userAgent = trim($this->userAgent);
  5888. }
  5889. }
  5890. if (count($this->getCfHeaders()) > 0) {
  5891. return $this->userAgent = 'Amazon CloudFront';
  5892. }
  5893. return $this->userAgent = null;
  5894. }
  5895. /**
  5896. * Retrieve the User-Agent.
  5897. *
  5898. * @return string|null The user agent if it's set.
  5899. */
  5900. public function getUserAgent()
  5901. {
  5902. return $this->userAgent;
  5903. }
  5904. /**
  5905. * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or
  5906. * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set.
  5907. *
  5908. * @deprecated since version 2.6.9
  5909. *
  5910. * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
  5911. * parameter is null which will default to self::DETECTION_TYPE_MOBILE.
  5912. */
  5913. public function setDetectionType($type = null)
  5914. {
  5915. if ($type === null) {
  5916. $type = self::DETECTION_TYPE_MOBILE;
  5917. }
  5918. if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) {
  5919. return;
  5920. }
  5921. $this->detectionType = $type;
  5922. }
  5923. public function getMatchingRegex()
  5924. {
  5925. return $this->matchingRegex;
  5926. }
  5927. public function getMatchesArray()
  5928. {
  5929. return $this->matchesArray;
  5930. }
  5931. /**
  5932. * Retrieve the list of known phone devices.
  5933. *
  5934. * @return array List of phone devices.
  5935. */
  5936. public static function getPhoneDevices()
  5937. {
  5938. return self::$phoneDevices;
  5939. }
  5940. /**
  5941. * Retrieve the list of known tablet devices.
  5942. *
  5943. * @return array List of tablet devices.
  5944. */
  5945. public static function getTabletDevices()
  5946. {
  5947. return self::$tabletDevices;
  5948. }
  5949. /**
  5950. * Alias for getBrowsers() method.
  5951. *
  5952. * @return array List of user agents.
  5953. */
  5954. public static function getUserAgents()
  5955. {
  5956. return self::getBrowsers();
  5957. }
  5958. /**
  5959. * Retrieve the list of known browsers. Specifically, the user agents.
  5960. *
  5961. * @return array List of browsers / user agents.
  5962. */
  5963. public static function getBrowsers()
  5964. {
  5965. return self::$browsers;
  5966. }
  5967. /**
  5968. * Retrieve the list of known utilities.
  5969. *
  5970. * @return array List of utilities.
  5971. */
  5972. public static function getUtilities()
  5973. {
  5974. return self::$utilities;
  5975. }
  5976. /**
  5977. * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().
  5978. *
  5979. * @deprecated since version 2.6.9
  5980. *
  5981. * @return array All the rules (but not extended).
  5982. */
  5983. public static function getMobileDetectionRules()
  5984. {
  5985. static $rules;
  5986. if (!$rules) {
  5987. $rules = array_merge(
  5988. self::$phoneDevices,
  5989. self::$tabletDevices,
  5990. self::$operatingSystems,
  5991. self::$browsers
  5992. );
  5993. }
  5994. return $rules;
  5995. }
  5996. /**
  5997. * Method gets the mobile detection rules + utilities.
  5998. * The reason this is separate is because utilities rules
  5999. * don't necessary imply mobile. This method is used inside
  6000. * the new $detect->is('stuff') method.
  6001. *
  6002. * @deprecated since version 2.6.9
  6003. *
  6004. * @return array All the rules + extended.
  6005. */
  6006. public function getMobileDetectionRulesExtended()
  6007. {
  6008. static $rules;
  6009. if (!$rules) {
  6010. // Merge all rules together.
  6011. $rules = array_merge(
  6012. self::$phoneDevices,
  6013. self::$tabletDevices,
  6014. self::$operatingSystems,
  6015. self::$browsers,
  6016. self::$utilities
  6017. );
  6018. }
  6019. return $rules;
  6020. }
  6021. /**
  6022. * Retrieve the current set of rules.
  6023. *
  6024. * @deprecated since version 2.6.9
  6025. *
  6026. * @return array
  6027. */
  6028. public function getRules()
  6029. {
  6030. if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) {
  6031. return self::getMobileDetectionRulesExtended();
  6032. } else {
  6033. return self::getMobileDetectionRules();
  6034. }
  6035. }
  6036. /**
  6037. * Retrieve the list of mobile operating systems.
  6038. *
  6039. * @return array The list of mobile operating systems.
  6040. */
  6041. public static function getOperatingSystems()
  6042. {
  6043. return self::$operatingSystems;
  6044. }
  6045. /**
  6046. * Check the HTTP headers for signs of mobile.
  6047. * This is the fastest mobile check possible; it's used
  6048. * inside isMobile() method.
  6049. *
  6050. * @return bool
  6051. */
  6052. public function checkHttpHeadersForMobile()
  6053. {
  6054. foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) {
  6055. if (isset($this->httpHeaders[$mobileHeader])) {
  6056. if (is_array($matchType['matches'])) {
  6057. foreach ($matchType['matches'] as $_match) {
  6058. if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) {
  6059. return true;
  6060. }
  6061. }
  6062. return false;
  6063. } else {
  6064. return true;
  6065. }
  6066. }
  6067. }
  6068. return false;
  6069. }
  6070. /**
  6071. * Magic overloading method.
  6072. *
  6073. * @method boolean is[...]()
  6074. * @param string $name
  6075. * @param array $arguments
  6076. * @return mixed
  6077. * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
  6078. */
  6079. public function __call($name, $arguments)
  6080. {
  6081. // make sure the name starts with 'is', otherwise
  6082. if (substr($name, 0, 2) !== 'is') {
  6083. throw new BadMethodCallException("No such method exists: $name");
  6084. }
  6085. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6086. $key = substr($name, 2);
  6087. return $this->matchUAAgainstKey($key);
  6088. }
  6089. /**
  6090. * Find a detection rule that matches the current User-agent.
  6091. *
  6092. * @param null $userAgent deprecated
  6093. * @return boolean
  6094. */
  6095. protected function matchDetectionRulesAgainstUA($userAgent = null)
  6096. {
  6097. // Begin general search.
  6098. foreach ($this->getRules() as $_regex) {
  6099. if (empty($_regex)) {
  6100. continue;
  6101. }
  6102. if ($this->match($_regex, $userAgent)) {
  6103. return true;
  6104. }
  6105. }
  6106. return false;
  6107. }
  6108. /**
  6109. * Search for a certain key in the rules array.
  6110. * If the key is found then try to match the corresponding
  6111. * regex against the User-Agent.
  6112. *
  6113. * @param string $key
  6114. *
  6115. * @return boolean
  6116. */
  6117. protected function matchUAAgainstKey($key)
  6118. {
  6119. // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
  6120. $key = strtolower($key);
  6121. if (false === isset($this->cache[$key])) {
  6122. // change the keys to lower case
  6123. $_rules = array_change_key_case($this->getRules());
  6124. if (false === empty($_rules[$key])) {
  6125. $this->cache[$key] = $this->match($_rules[$key]);
  6126. }
  6127. if (false === isset($this->cache[$key])) {
  6128. $this->cache[$key] = false;
  6129. }
  6130. }
  6131. return $this->cache[$key];
  6132. }
  6133. /**
  6134. * Check if the device is mobile.
  6135. * Returns true if any type of mobile device detected, including special ones
  6136. * @param null $userAgent deprecated
  6137. * @param null $httpHeaders deprecated
  6138. * @return bool
  6139. */
  6140. public function isMobile($userAgent = null, $httpHeaders = null)
  6141. {
  6142. if ($httpHeaders) {
  6143. $this->setHttpHeaders($httpHeaders);
  6144. }
  6145. if ($userAgent) {
  6146. $this->setUserAgent($userAgent);
  6147. }
  6148. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6149. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6150. $cfHeaders = $this->getCfHeaders();
  6151. if(array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') {
  6152. return true;
  6153. }
  6154. }
  6155. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6156. if ($this->checkHttpHeadersForMobile()) {
  6157. return true;
  6158. } else {
  6159. return $this->matchDetectionRulesAgainstUA();
  6160. }
  6161. }
  6162. /**
  6163. * Check if the device is a tablet.
  6164. * Return true if any type of tablet device is detected.
  6165. *
  6166. * @param string $userAgent deprecated
  6167. * @param array $httpHeaders deprecated
  6168. * @return bool
  6169. */
  6170. public function isTablet($userAgent = null, $httpHeaders = null)
  6171. {
  6172. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6173. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6174. $cfHeaders = $this->getCfHeaders();
  6175. if(array_key_exists('HTTP_CLOUDFRONT_IS_TABLET_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] === 'true') {
  6176. return true;
  6177. }
  6178. }
  6179. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6180. foreach (self::$tabletDevices as $_regex) {
  6181. if ($this->match($_regex, $userAgent)) {
  6182. return true;
  6183. }
  6184. }
  6185. return false;
  6186. }
  6187. /**
  6188. * This method checks for a certain property in the
  6189. * userAgent.
  6190. * @todo: The httpHeaders part is not yet used.
  6191. *
  6192. * @param string $key
  6193. * @param string $userAgent deprecated
  6194. * @param string $httpHeaders deprecated
  6195. * @return bool|int|null
  6196. */
  6197. public function is($key, $userAgent = null, $httpHeaders = null)
  6198. {
  6199. // Set the UA and HTTP headers only if needed (eg. batch mode).
  6200. if ($httpHeaders) {
  6201. $this->setHttpHeaders($httpHeaders);
  6202. }
  6203. if ($userAgent) {
  6204. $this->setUserAgent($userAgent);
  6205. }
  6206. $this->setDetectionType(self::DETECTION_TYPE_EXTENDED);
  6207. return $this->matchUAAgainstKey($key);
  6208. }
  6209. /**
  6210. * Some detection rules are relative (not standard),
  6211. * because of the diversity of devices, vendors and
  6212. * their conventions in representing the User-Agent or
  6213. * the HTTP headers.
  6214. *
  6215. * This method will be used to check custom regexes against
  6216. * the User-Agent string.
  6217. *
  6218. * @param $regex
  6219. * @param string $userAgent
  6220. * @return bool
  6221. *
  6222. * @todo: search in the HTTP headers too.
  6223. */
  6224. public function match($regex, $userAgent = null)
  6225. {
  6226. $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches);
  6227. // If positive match is found, store the results for debug.
  6228. if ($match) {
  6229. $this->matchingRegex = $regex;
  6230. $this->matchesArray = $matches;
  6231. }
  6232. return $match;
  6233. }
  6234. /**
  6235. * Get the properties array.
  6236. *
  6237. * @return array
  6238. */
  6239. public static function getProperties()
  6240. {
  6241. return self::$properties;
  6242. }
  6243. /**
  6244. * Prepare the version number.
  6245. *
  6246. * @todo Remove the error supression from str_replace() call.
  6247. *
  6248. * @param string $ver The string version, like "2.6.21.2152";
  6249. *
  6250. * @return float
  6251. */
  6252. public function prepareVersionNo($ver)
  6253. {
  6254. $ver = str_replace(array('_', ' ', '/'), '.', $ver);
  6255. $arrVer = explode('.', $ver, 2);
  6256. if (isset($arrVer[1])) {
  6257. $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions.
  6258. }
  6259. return (float) implode('.', $arrVer);
  6260. }
  6261. /**
  6262. * Check the version of the given property in the User-Agent.
  6263. * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
  6264. *
  6265. * @param string $propertyName The name of the property. See self::getProperties() array
  6266. * keys for all possible properties.
  6267. * @param string $type Either self::VERSION_TYPE_STRING to get a string value or
  6268. * self::VERSION_TYPE_FLOAT indicating a float value. This parameter
  6269. * is optional and defaults to self::VERSION_TYPE_STRING. Passing an
  6270. * invalid parameter will default to the this type as well.
  6271. *
  6272. * @return string|float The version of the property we are trying to extract.
  6273. */
  6274. public function version($propertyName, $type = self::VERSION_TYPE_STRING)
  6275. {
  6276. if (empty($propertyName)) {
  6277. return false;
  6278. }
  6279. // set the $type to the default if we don't recognize the type
  6280. if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
  6281. $type = self::VERSION_TYPE_STRING;
  6282. }
  6283. $properties = self::getProperties();
  6284. // Check if the property exists in the properties array.
  6285. if (true === isset($properties[$propertyName])) {
  6286. // Prepare the pattern to be matched.
  6287. // Make sure we always deal with an array (string is converted).
  6288. $properties[$propertyName] = (array) $properties[$propertyName];
  6289. foreach ($properties[$propertyName] as $propertyMatchString) {
  6290. $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
  6291. // Identify and extract the version.
  6292. preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);
  6293. if (false === empty($match[1])) {
  6294. $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);
  6295. return $version;
  6296. }
  6297. }
  6298. }
  6299. return false;
  6300. }
  6301. /**
  6302. * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
  6303. *
  6304. * @return string One of the self::MOBILE_GRADE_* constants.
  6305. */
  6306. public function mobileGrade()
  6307. {
  6308. $isMobile = $this->isMobile();
  6309. if (
  6310. // 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)
  6311. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6312. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6313. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6314. // 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)
  6315. // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
  6316. // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
  6317. // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
  6318. ( $this->version('Android', self::VERSION_TYPE_FLOAT)>2.1 && $this->is('Webkit') ) ||
  6319. // 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)
  6320. $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 ||
  6321. // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry® Torch 9810 (7), BlackBerry Z10 (10)
  6322. $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 ||
  6323. // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
  6324. $this->match('Playbook.*Tablet') ||
  6325. // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0)
  6326. ( $this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi') ) ||
  6327. // Palm WebOS 3.0 - Tested on HP TouchPad
  6328. $this->match('hp.*TouchPad') ||
  6329. // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices
  6330. ( $this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18 ) ||
  6331. // Chrome for Android - Tested on Android 4.0, 4.1 device
  6332. ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0 ) ||
  6333. // Skyfire 4.1 - Tested on Android 2.3 device
  6334. ( $this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6335. // Opera Mobile 11.5-12: Tested on Android 2.3
  6336. ( $this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS') ) ||
  6337. // Meego 1.2 - Tested on Nokia 950 and N9
  6338. $this->is('MeeGoOS') ||
  6339. // Tizen (pre-release) - Tested on early hardware
  6340. $this->is('Tizen') ||
  6341. // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
  6342. // @todo: more tests here!
  6343. $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 ||
  6344. // UC Browser - Tested on Android 2.3 device
  6345. ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6346. // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
  6347. ( $this->match('Kindle Fire') ||
  6348. $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0 ) ||
  6349. // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
  6350. $this->is('AndroidOS') && $this->is('NookTablet') ||
  6351. // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7
  6352. $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && !$isMobile ||
  6353. // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7
  6354. $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && !$isMobile ||
  6355. // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7
  6356. $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && !$isMobile ||
  6357. // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
  6358. $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && !$isMobile ||
  6359. // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
  6360. $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && !$isMobile
  6361. ){
  6362. return self::MOBILE_GRADE_A;
  6363. }
  6364. if (
  6365. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT)<4.3 ||
  6366. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT)<4.3 ||
  6367. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT)<4.3 ||
  6368. // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
  6369. $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT)<6 ||
  6370. //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
  6371. ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 &&
  6372. ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS')) ) ||
  6373. // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
  6374. $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
  6375. // @todo: report this (tested on Nokia N71)
  6376. $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS')
  6377. ){
  6378. return self::MOBILE_GRADE_B;
  6379. }
  6380. if (
  6381. // Blackberry 4.x - Tested on the Curve 8330
  6382. $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 ||
  6383. // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
  6384. $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 ||
  6385. // Tested on original iPhone (3.1), iPhone 3 (3.2)
  6386. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6387. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6388. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6389. // Internet Explorer 7 and older - Tested on Windows XP
  6390. $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && !$isMobile
  6391. ){
  6392. return self::MOBILE_GRADE_C;
  6393. }
  6394. // All older smartphone platforms and featurephones - Any device that doesn't support media queries
  6395. // will receive the basic, C grade experience.
  6396. return self::MOBILE_GRADE_C;
  6397. }
  6398. }
  6399. $mobileDetect = new Mobile_Detect;
  6400. $userDevice = ($mobileDetect->isMobile() ? ($mobileDetect->isTablet() ? 'tablet' : 'phone') : 'computer');
  6401. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  6402. $path = getServerPath();
  6403. return '
  6404. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6405. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  6406. <head>
  6407. <!--[if gte mso 9]><xml>
  6408. <o:OfficeDocumentSettings>
  6409. <o:AllowPNG/>
  6410. <o:PixelsPerInch>96</o:PixelsPerInch>
  6411. </o:OfficeDocumentSettings>
  6412. </xml><![endif]-->
  6413. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6414. <meta name="viewport" content="width=device-width">
  6415. <!--[if !mso]><!-->
  6416. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6417. <!--<![endif]-->
  6418. <title></title>
  6419. <!--[if !mso]><!-- -->
  6420. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  6421. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  6422. <!--<![endif]-->
  6423. <style type="text/css" id="media-query">
  6424. body {
  6425. margin: 0;
  6426. padding: 0;
  6427. }
  6428. table,
  6429. tr,
  6430. td {
  6431. vertical-align: top;
  6432. border-collapse: collapse;
  6433. }
  6434. .ie-browser table,
  6435. .mso-container table {
  6436. table-layout: fixed;
  6437. }
  6438. * {
  6439. line-height: inherit;
  6440. }
  6441. a[x-apple-data-detectors=true] {
  6442. color: inherit !important;
  6443. text-decoration: none !important;
  6444. }
  6445. [owa] .img-container div,
  6446. [owa] .img-container button {
  6447. display: block !important;
  6448. }
  6449. [owa] .fullwidth button {
  6450. width: 100% !important;
  6451. }
  6452. [owa] .block-grid .col {
  6453. display: table-cell;
  6454. float: none !important;
  6455. vertical-align: top;
  6456. }
  6457. .ie-browser .num12,
  6458. .ie-browser .block-grid,
  6459. [owa] .num12,
  6460. [owa] .block-grid {
  6461. width: 615px !important;
  6462. }
  6463. .ExternalClass,
  6464. .ExternalClass p,
  6465. .ExternalClass span,
  6466. .ExternalClass font,
  6467. .ExternalClass td,
  6468. .ExternalClass div {
  6469. line-height: 100%;
  6470. }
  6471. .ie-browser .mixed-two-up .num4,
  6472. [owa] .mixed-two-up .num4 {
  6473. width: 204px !important;
  6474. }
  6475. .ie-browser .mixed-two-up .num8,
  6476. [owa] .mixed-two-up .num8 {
  6477. width: 408px !important;
  6478. }
  6479. .ie-browser .block-grid.two-up .col,
  6480. [owa] .block-grid.two-up .col {
  6481. width: 307px !important;
  6482. }
  6483. .ie-browser .block-grid.three-up .col,
  6484. [owa] .block-grid.three-up .col {
  6485. width: 205px !important;
  6486. }
  6487. .ie-browser .block-grid.four-up .col,
  6488. [owa] .block-grid.four-up .col {
  6489. width: 153px !important;
  6490. }
  6491. .ie-browser .block-grid.five-up .col,
  6492. [owa] .block-grid.five-up .col {
  6493. width: 123px !important;
  6494. }
  6495. .ie-browser .block-grid.six-up .col,
  6496. [owa] .block-grid.six-up .col {
  6497. width: 102px !important;
  6498. }
  6499. .ie-browser .block-grid.seven-up .col,
  6500. [owa] .block-grid.seven-up .col {
  6501. width: 87px !important;
  6502. }
  6503. .ie-browser .block-grid.eight-up .col,
  6504. [owa] .block-grid.eight-up .col {
  6505. width: 76px !important;
  6506. }
  6507. .ie-browser .block-grid.nine-up .col,
  6508. [owa] .block-grid.nine-up .col {
  6509. width: 68px !important;
  6510. }
  6511. .ie-browser .block-grid.ten-up .col,
  6512. [owa] .block-grid.ten-up .col {
  6513. width: 61px !important;
  6514. }
  6515. .ie-browser .block-grid.eleven-up .col,
  6516. [owa] .block-grid.eleven-up .col {
  6517. width: 55px !important;
  6518. }
  6519. .ie-browser .block-grid.twelve-up .col,
  6520. [owa] .block-grid.twelve-up .col {
  6521. width: 51px !important;
  6522. }
  6523. @media only screen and (min-width: 635px) {
  6524. .block-grid {
  6525. width: 615px !important;
  6526. }
  6527. .block-grid .col {
  6528. display: table-cell;
  6529. Float: none !important;
  6530. vertical-align: top;
  6531. }
  6532. .block-grid .col.num12 {
  6533. width: 615px !important;
  6534. }
  6535. .block-grid.mixed-two-up .col.num4 {
  6536. width: 204px !important;
  6537. }
  6538. .block-grid.mixed-two-up .col.num8 {
  6539. width: 408px !important;
  6540. }
  6541. .block-grid.two-up .col {
  6542. width: 307px !important;
  6543. }
  6544. .block-grid.three-up .col {
  6545. width: 205px !important;
  6546. }
  6547. .block-grid.four-up .col {
  6548. width: 153px !important;
  6549. }
  6550. .block-grid.five-up .col {
  6551. width: 123px !important;
  6552. }
  6553. .block-grid.six-up .col {
  6554. width: 102px !important;
  6555. }
  6556. .block-grid.seven-up .col {
  6557. width: 87px !important;
  6558. }
  6559. .block-grid.eight-up .col {
  6560. width: 76px !important;
  6561. }
  6562. .block-grid.nine-up .col {
  6563. width: 68px !important;
  6564. }
  6565. .block-grid.ten-up .col {
  6566. width: 61px !important;
  6567. }
  6568. .block-grid.eleven-up .col {
  6569. width: 55px !important;
  6570. }
  6571. .block-grid.twelve-up .col {
  6572. width: 51px !important;
  6573. }
  6574. }
  6575. @media (max-width: 635px) {
  6576. .block-grid,
  6577. .col {
  6578. min-width: 320px !important;
  6579. max-width: 100% !important;
  6580. }
  6581. .block-grid {
  6582. width: calc(100% - 40px) !important;
  6583. }
  6584. .col {
  6585. width: 100% !important;
  6586. }
  6587. .col>div {
  6588. margin: 0 auto;
  6589. }
  6590. img.fullwidth {
  6591. max-width: 100% !important;
  6592. }
  6593. }
  6594. </style>
  6595. </head>
  6596. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  6597. <!--[if IE]><div class="ie-browser"><![endif]-->
  6598. <!--[if mso]><div class="mso-container"><![endif]-->
  6599. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  6600. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  6601. <div style="background-color:#333333;">
  6602. <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;"
  6603. class="block-grid ">
  6604. <div style="border-collapse: collapse;display: table;width: 100%;">
  6605. <!--[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]-->
  6606. <!--[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]-->
  6607. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6608. <div style="background-color: transparent; width: 100% !important;">
  6609. <!--[if (!mso)&(!IE)]><!-->
  6610. <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;">
  6611. <!--<![endif]-->
  6612. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  6613. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  6614. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  6615. 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"
  6616. width="555">
  6617. <!--[if mso]></td></tr></table><![endif]-->
  6618. </div>
  6619. <!--[if (!mso)&(!IE)]><!-->
  6620. </div>
  6621. <!--<![endif]-->
  6622. </div>
  6623. </div>
  6624. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6625. </div>
  6626. </div>
  6627. </div>
  6628. <div style="background-color:#333333;">
  6629. <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;"
  6630. class="block-grid ">
  6631. <div style="border-collapse: collapse;display: table;width: 100%;">
  6632. <!--[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]-->
  6633. <!--[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]-->
  6634. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6635. <div style="background-color: transparent; width: 100% !important;">
  6636. <!--[if (!mso)&(!IE)]><!-->
  6637. <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;">
  6638. <!--<![endif]-->
  6639. <!--[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]-->
  6640. <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;">
  6641. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6642. <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>
  6643. </span>
  6644. </p>
  6645. </div>
  6646. </div>
  6647. <!--[if mso]></td></tr></table><![endif]-->
  6648. <!--[if (!mso)&(!IE)]><!-->
  6649. </div>
  6650. <!--<![endif]-->
  6651. </div>
  6652. </div>
  6653. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6654. </div>
  6655. </div>
  6656. </div>
  6657. <div style="background-color:#393939;">
  6658. <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;"
  6659. class="block-grid ">
  6660. <div style="border-collapse: collapse;display: table;width: 100%;">
  6661. <!--[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]-->
  6662. <!--[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]-->
  6663. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6664. <div style="background-color: transparent; width: 100% !important;">
  6665. <!--[if (!mso)&(!IE)]><!-->
  6666. <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;">
  6667. <!--<![endif]-->
  6668. <!--[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]-->
  6669. <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;">
  6670. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6671. <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>
  6672. </div>
  6673. </div>
  6674. <!--[if mso]></td></tr></table><![endif]-->
  6675. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  6676. <!--[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]-->
  6677. <div align="center">
  6678. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  6679. </div>
  6680. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6681. </div>
  6682. <!--[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]-->
  6683. <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;">
  6684. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6685. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  6686. </div>
  6687. </div>
  6688. <!--[if mso]></td></tr></table><![endif]-->
  6689. <!--[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]-->
  6690. <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;">
  6691. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  6692. <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>
  6693. </span>
  6694. </p>
  6695. </div>
  6696. </div>
  6697. <!--[if mso]></td></tr></table><![endif]-->
  6698. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  6699. <!--[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]-->
  6700. <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">
  6701. <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>
  6702. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6703. </div>
  6704. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6705. </div>
  6706. <!--[if (!mso)&(!IE)]><!-->
  6707. </div>
  6708. <!--<![endif]-->
  6709. </div>
  6710. </div>
  6711. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6712. </div>
  6713. </div>
  6714. </div>
  6715. <div style="background-color:#ffffff;">
  6716. <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;"
  6717. class="block-grid ">
  6718. <div style="border-collapse: collapse;display: table;width: 100%;">
  6719. <!--[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]-->
  6720. <!--[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]-->
  6721. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6722. <div style="background-color: transparent; width: 100% !important;">
  6723. <!--[if (!mso)&(!IE)]><!-->
  6724. <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;">
  6725. <!--<![endif]-->
  6726. <!--[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]-->
  6727. <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;">
  6728. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6729. <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>
  6730. </div>
  6731. </div>
  6732. <!--[if mso]></td></tr></table><![endif]-->
  6733. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  6734. <!--[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]-->
  6735. <div align="center">
  6736. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  6737. </div>
  6738. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6739. </div>
  6740. <!--[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]-->
  6741. <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;">
  6742. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6743. <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>
  6744. </div>
  6745. </div>
  6746. <!--[if mso]></td></tr></table><![endif]-->
  6747. <!--[if (!mso)&(!IE)]><!-->
  6748. </div>
  6749. <!--<![endif]-->
  6750. </div>
  6751. </div>
  6752. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6753. </div>
  6754. </div>
  6755. </div>
  6756. <div style="background-color:#333333;">
  6757. <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;"
  6758. class="block-grid ">
  6759. <div style="border-collapse: collapse;display: table;width: 100%;">
  6760. <!--[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]-->
  6761. <!--[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]-->
  6762. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6763. <div style="background-color: transparent; width: 100% !important;">
  6764. <!--[if (!mso)&(!IE)]><!-->
  6765. <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;">
  6766. <!--<![endif]-->
  6767. <!--[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]-->
  6768. <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;">
  6769. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6770. <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"
  6771. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  6772. </div>
  6773. </div>
  6774. <!--[if mso]></td></tr></table><![endif]-->
  6775. <!--[if (!mso)&(!IE)]><!-->
  6776. </div>
  6777. <!--<![endif]-->
  6778. </div>
  6779. </div>
  6780. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6781. </div>
  6782. </div>
  6783. </div>
  6784. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  6785. </div>
  6786. <!--[if (mso)|(IE)]></div><![endif]-->
  6787. </body>
  6788. </html>
  6789. ';
  6790. }
  6791. function mimeTypes(){
  6792. return array(
  6793. '123' => 'application/vnd.lotus-1-2-3',
  6794. '3dml' => 'text/vnd.in3d.3dml',
  6795. '3ds' => 'image/x-3ds',
  6796. '3g2' => 'video/3gpp2',
  6797. '3gp' => 'video/3gpp',
  6798. '7z' => 'application/x-7z-compressed',
  6799. 'aab' => 'application/x-authorware-bin',
  6800. 'aac' => 'audio/x-aac',
  6801. 'aam' => 'application/x-authorware-map',
  6802. 'aas' => 'application/x-authorware-seg',
  6803. 'abw' => 'application/x-abiword',
  6804. 'ac' => 'application/pkix-attr-cert',
  6805. 'acc' => 'application/vnd.americandynamics.acc',
  6806. 'ace' => 'application/x-ace-compressed',
  6807. 'acu' => 'application/vnd.acucobol',
  6808. 'acutc' => 'application/vnd.acucorp',
  6809. 'adp' => 'audio/adpcm',
  6810. 'aep' => 'application/vnd.audiograph',
  6811. 'afm' => 'application/x-font-type1',
  6812. 'afp' => 'application/vnd.ibm.modcap',
  6813. 'ahead' => 'application/vnd.ahead.space',
  6814. 'ai' => 'application/postscript',
  6815. 'aif' => 'audio/x-aiff',
  6816. 'aifc' => 'audio/x-aiff',
  6817. 'aiff' => 'audio/x-aiff',
  6818. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  6819. 'ait' => 'application/vnd.dvb.ait',
  6820. 'ami' => 'application/vnd.amiga.ami',
  6821. 'apk' => 'application/vnd.android.package-archive',
  6822. 'appcache' => 'text/cache-manifest',
  6823. 'application' => 'application/x-ms-application',
  6824. 'apr' => 'application/vnd.lotus-approach',
  6825. 'arc' => 'application/x-freearc',
  6826. 'asc' => 'application/pgp-signature',
  6827. 'asf' => 'video/x-ms-asf',
  6828. 'asm' => 'text/x-asm',
  6829. 'aso' => 'application/vnd.accpac.simply.aso',
  6830. 'asx' => 'video/x-ms-asf',
  6831. 'atc' => 'application/vnd.acucorp',
  6832. 'atom' => 'application/atom+xml',
  6833. 'atomcat' => 'application/atomcat+xml',
  6834. 'atomsvc' => 'application/atomsvc+xml',
  6835. 'atx' => 'application/vnd.antix.game-component',
  6836. 'au' => 'audio/basic',
  6837. 'avi' => 'video/x-msvideo',
  6838. 'aw' => 'application/applixware',
  6839. 'azf' => 'application/vnd.airzip.filesecure.azf',
  6840. 'azs' => 'application/vnd.airzip.filesecure.azs',
  6841. 'azw' => 'application/vnd.amazon.ebook',
  6842. 'bat' => 'application/x-msdownload',
  6843. 'bcpio' => 'application/x-bcpio',
  6844. 'bdf' => 'application/x-font-bdf',
  6845. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  6846. 'bed' => 'application/vnd.realvnc.bed',
  6847. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  6848. 'bin' => 'application/octet-stream',
  6849. 'blb' => 'application/x-blorb',
  6850. 'blorb' => 'application/x-blorb',
  6851. 'bmi' => 'application/vnd.bmi',
  6852. 'bmp' => 'image/bmp',
  6853. 'book' => 'application/vnd.framemaker',
  6854. 'box' => 'application/vnd.previewsystems.box',
  6855. 'boz' => 'application/x-bzip2',
  6856. 'bpk' => 'application/octet-stream',
  6857. 'btif' => 'image/prs.btif',
  6858. 'bz' => 'application/x-bzip',
  6859. 'bz2' => 'application/x-bzip2',
  6860. 'c' => 'text/x-c',
  6861. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  6862. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  6863. 'c4d' => 'application/vnd.clonk.c4group',
  6864. 'c4f' => 'application/vnd.clonk.c4group',
  6865. 'c4g' => 'application/vnd.clonk.c4group',
  6866. 'c4p' => 'application/vnd.clonk.c4group',
  6867. 'c4u' => 'application/vnd.clonk.c4group',
  6868. 'cab' => 'application/vnd.ms-cab-compressed',
  6869. 'caf' => 'audio/x-caf',
  6870. 'cap' => 'application/vnd.tcpdump.pcap',
  6871. 'car' => 'application/vnd.curl.car',
  6872. 'cat' => 'application/vnd.ms-pki.seccat',
  6873. 'cb7' => 'application/x-cbr',
  6874. 'cba' => 'application/x-cbr',
  6875. 'cbr' => 'application/x-cbr',
  6876. 'cbt' => 'application/x-cbr',
  6877. 'cbz' => 'application/x-cbr',
  6878. 'cc' => 'text/x-c',
  6879. 'cct' => 'application/x-director',
  6880. 'ccxml' => 'application/ccxml+xml',
  6881. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  6882. 'cdf' => 'application/x-netcdf',
  6883. 'cdkey' => 'application/vnd.mediastation.cdkey',
  6884. 'cdmia' => 'application/cdmi-capability',
  6885. 'cdmic' => 'application/cdmi-container',
  6886. 'cdmid' => 'application/cdmi-domain',
  6887. 'cdmio' => 'application/cdmi-object',
  6888. 'cdmiq' => 'application/cdmi-queue',
  6889. 'cdx' => 'chemical/x-cdx',
  6890. 'cdxml' => 'application/vnd.chemdraw+xml',
  6891. 'cdy' => 'application/vnd.cinderella',
  6892. 'cer' => 'application/pkix-cert',
  6893. 'cfs' => 'application/x-cfs-compressed',
  6894. 'cgm' => 'image/cgm',
  6895. 'chat' => 'application/x-chat',
  6896. 'chm' => 'application/vnd.ms-htmlhelp',
  6897. 'chrt' => 'application/vnd.kde.kchart',
  6898. 'cif' => 'chemical/x-cif',
  6899. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  6900. 'cil' => 'application/vnd.ms-artgalry',
  6901. 'cla' => 'application/vnd.claymore',
  6902. 'class' => 'application/java-vm',
  6903. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  6904. 'clkp' => 'application/vnd.crick.clicker.palette',
  6905. 'clkt' => 'application/vnd.crick.clicker.template',
  6906. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  6907. 'clkx' => 'application/vnd.crick.clicker',
  6908. 'clp' => 'application/x-msclip',
  6909. 'cmc' => 'application/vnd.cosmocaller',
  6910. 'cmdf' => 'chemical/x-cmdf',
  6911. 'cml' => 'chemical/x-cml',
  6912. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  6913. 'cmx' => 'image/x-cmx',
  6914. 'cod' => 'application/vnd.rim.cod',
  6915. 'com' => 'application/x-msdownload',
  6916. 'conf' => 'text/plain',
  6917. 'cpio' => 'application/x-cpio',
  6918. 'cpp' => 'text/x-c',
  6919. 'cpt' => 'application/mac-compactpro',
  6920. 'crd' => 'application/x-mscardfile',
  6921. 'crl' => 'application/pkix-crl',
  6922. 'crt' => 'application/x-x509-ca-cert',
  6923. 'cryptonote' => 'application/vnd.rig.cryptonote',
  6924. 'csh' => 'application/x-csh',
  6925. 'csml' => 'chemical/x-csml',
  6926. 'csp' => 'application/vnd.commonspace',
  6927. 'css' => 'text/css',
  6928. 'cst' => 'application/x-director',
  6929. 'csv' => 'text/csv',
  6930. 'cu' => 'application/cu-seeme',
  6931. 'curl' => 'text/vnd.curl',
  6932. 'cww' => 'application/prs.cww',
  6933. 'cxt' => 'application/x-director',
  6934. 'cxx' => 'text/x-c',
  6935. 'dae' => 'model/vnd.collada+xml',
  6936. 'daf' => 'application/vnd.mobius.daf',
  6937. 'dart' => 'application/vnd.dart',
  6938. 'dataless' => 'application/vnd.fdsn.seed',
  6939. 'davmount' => 'application/davmount+xml',
  6940. 'dbk' => 'application/docbook+xml',
  6941. 'dcr' => 'application/x-director',
  6942. 'dcurl' => 'text/vnd.curl.dcurl',
  6943. 'dd2' => 'application/vnd.oma.dd2+xml',
  6944. 'ddd' => 'application/vnd.fujixerox.ddd',
  6945. 'deb' => 'application/x-debian-package',
  6946. 'def' => 'text/plain',
  6947. 'deploy' => 'application/octet-stream',
  6948. 'der' => 'application/x-x509-ca-cert',
  6949. 'dfac' => 'application/vnd.dreamfactory',
  6950. 'dgc' => 'application/x-dgc-compressed',
  6951. 'dic' => 'text/x-c',
  6952. 'dir' => 'application/x-director',
  6953. 'dis' => 'application/vnd.mobius.dis',
  6954. 'dist' => 'application/octet-stream',
  6955. 'distz' => 'application/octet-stream',
  6956. 'djv' => 'image/vnd.djvu',
  6957. 'djvu' => 'image/vnd.djvu',
  6958. 'dll' => 'application/x-msdownload',
  6959. 'dmg' => 'application/x-apple-diskimage',
  6960. 'dmp' => 'application/vnd.tcpdump.pcap',
  6961. 'dms' => 'application/octet-stream',
  6962. 'dna' => 'application/vnd.dna',
  6963. 'doc' => 'application/msword',
  6964. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  6965. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  6966. 'dot' => 'application/msword',
  6967. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  6968. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  6969. 'dp' => 'application/vnd.osgi.dp',
  6970. 'dpg' => 'application/vnd.dpgraph',
  6971. 'dra' => 'audio/vnd.dra',
  6972. 'dsc' => 'text/prs.lines.tag',
  6973. 'dssc' => 'application/dssc+der',
  6974. 'dtb' => 'application/x-dtbook+xml',
  6975. 'dtd' => 'application/xml-dtd',
  6976. 'dts' => 'audio/vnd.dts',
  6977. 'dtshd' => 'audio/vnd.dts.hd',
  6978. 'dump' => 'application/octet-stream',
  6979. 'dvb' => 'video/vnd.dvb.file',
  6980. 'dvi' => 'application/x-dvi',
  6981. 'dwf' => 'model/vnd.dwf',
  6982. 'dwg' => 'image/vnd.dwg',
  6983. 'dxf' => 'image/vnd.dxf',
  6984. 'dxp' => 'application/vnd.spotfire.dxp',
  6985. 'dxr' => 'application/x-director',
  6986. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  6987. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  6988. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  6989. 'ecma' => 'application/ecmascript',
  6990. 'edm' => 'application/vnd.novadigm.edm',
  6991. 'edx' => 'application/vnd.novadigm.edx',
  6992. 'efif' => 'application/vnd.picsel',
  6993. 'ei6' => 'application/vnd.pg.osasli',
  6994. 'elc' => 'application/octet-stream',
  6995. 'emf' => 'application/x-msmetafile',
  6996. 'eml' => 'message/rfc822',
  6997. 'emma' => 'application/emma+xml',
  6998. 'emz' => 'application/x-msmetafile',
  6999. 'eol' => 'audio/vnd.digital-winds',
  7000. 'eot' => 'application/vnd.ms-fontobject',
  7001. 'eps' => 'application/postscript',
  7002. 'epub' => 'application/epub+zip',
  7003. 'es3' => 'application/vnd.eszigno3+xml',
  7004. 'esa' => 'application/vnd.osgi.subsystem',
  7005. 'esf' => 'application/vnd.epson.esf',
  7006. 'et3' => 'application/vnd.eszigno3+xml',
  7007. 'etx' => 'text/x-setext',
  7008. 'eva' => 'application/x-eva',
  7009. 'evy' => 'application/x-envoy',
  7010. 'exe' => 'application/x-msdownload',
  7011. 'exi' => 'application/exi',
  7012. 'ext' => 'application/vnd.novadigm.ext',
  7013. 'ez' => 'application/andrew-inset',
  7014. 'ez2' => 'application/vnd.ezpix-album',
  7015. 'ez3' => 'application/vnd.ezpix-package',
  7016. 'f' => 'text/x-fortran',
  7017. 'f4v' => 'video/x-f4v',
  7018. 'f77' => 'text/x-fortran',
  7019. 'f90' => 'text/x-fortran',
  7020. 'fbs' => 'image/vnd.fastbidsheet',
  7021. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  7022. 'fcs' => 'application/vnd.isac.fcs',
  7023. 'fdf' => 'application/vnd.fdf',
  7024. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  7025. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  7026. 'fgd' => 'application/x-director',
  7027. 'fh' => 'image/x-freehand',
  7028. 'fh4' => 'image/x-freehand',
  7029. 'fh5' => 'image/x-freehand',
  7030. 'fh7' => 'image/x-freehand',
  7031. 'fhc' => 'image/x-freehand',
  7032. 'fig' => 'application/x-xfig',
  7033. 'flac' => 'audio/x-flac',
  7034. 'fli' => 'video/x-fli',
  7035. 'flo' => 'application/vnd.micrografx.flo',
  7036. 'flv' => 'video/x-flv',
  7037. 'flw' => 'application/vnd.kde.kivio',
  7038. 'flx' => 'text/vnd.fmi.flexstor',
  7039. 'fly' => 'text/vnd.fly',
  7040. 'fm' => 'application/vnd.framemaker',
  7041. 'fnc' => 'application/vnd.frogans.fnc',
  7042. 'for' => 'text/x-fortran',
  7043. 'fpx' => 'image/vnd.fpx',
  7044. 'frame' => 'application/vnd.framemaker',
  7045. 'fsc' => 'application/vnd.fsc.weblaunch',
  7046. 'fst' => 'image/vnd.fst',
  7047. 'ftc' => 'application/vnd.fluxtime.clip',
  7048. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  7049. 'fvt' => 'video/vnd.fvt',
  7050. 'fxp' => 'application/vnd.adobe.fxp',
  7051. 'fxpl' => 'application/vnd.adobe.fxp',
  7052. 'fzs' => 'application/vnd.fuzzysheet',
  7053. 'g2w' => 'application/vnd.geoplan',
  7054. 'g3' => 'image/g3fax',
  7055. 'g3w' => 'application/vnd.geospace',
  7056. 'gac' => 'application/vnd.groove-account',
  7057. 'gam' => 'application/x-tads',
  7058. 'gbr' => 'application/rpki-ghostbusters',
  7059. 'gca' => 'application/x-gca-compressed',
  7060. 'gdl' => 'model/vnd.gdl',
  7061. 'geo' => 'application/vnd.dynageo',
  7062. 'gex' => 'application/vnd.geometry-explorer',
  7063. 'ggb' => 'application/vnd.geogebra.file',
  7064. 'ggt' => 'application/vnd.geogebra.tool',
  7065. 'ghf' => 'application/vnd.groove-help',
  7066. 'gif' => 'image/gif',
  7067. 'gim' => 'application/vnd.groove-identity-message',
  7068. 'gml' => 'application/gml+xml',
  7069. 'gmx' => 'application/vnd.gmx',
  7070. 'gnumeric' => 'application/x-gnumeric',
  7071. 'gph' => 'application/vnd.flographit',
  7072. 'gpx' => 'application/gpx+xml',
  7073. 'gqf' => 'application/vnd.grafeq',
  7074. 'gqs' => 'application/vnd.grafeq',
  7075. 'gram' => 'application/srgs',
  7076. 'gramps' => 'application/x-gramps-xml',
  7077. 'gre' => 'application/vnd.geometry-explorer',
  7078. 'grv' => 'application/vnd.groove-injector',
  7079. 'grxml' => 'application/srgs+xml',
  7080. 'gsf' => 'application/x-font-ghostscript',
  7081. 'gtar' => 'application/x-gtar',
  7082. 'gtm' => 'application/vnd.groove-tool-message',
  7083. 'gtw' => 'model/vnd.gtw',
  7084. 'gv' => 'text/vnd.graphviz',
  7085. 'gxf' => 'application/gxf',
  7086. 'gxt' => 'application/vnd.geonext',
  7087. 'h' => 'text/x-c',
  7088. 'h261' => 'video/h261',
  7089. 'h263' => 'video/h263',
  7090. 'h264' => 'video/h264',
  7091. 'hal' => 'application/vnd.hal+xml',
  7092. 'hbci' => 'application/vnd.hbci',
  7093. 'hdf' => 'application/x-hdf',
  7094. 'hh' => 'text/x-c',
  7095. 'hlp' => 'application/winhlp',
  7096. 'hpgl' => 'application/vnd.hp-hpgl',
  7097. 'hpid' => 'application/vnd.hp-hpid',
  7098. 'hps' => 'application/vnd.hp-hps',
  7099. 'hqx' => 'application/mac-binhex40',
  7100. 'htke' => 'application/vnd.kenameaapp',
  7101. 'htm' => 'text/html',
  7102. 'html' => 'text/html',
  7103. 'hvd' => 'application/vnd.yamaha.hv-dic',
  7104. 'hvp' => 'application/vnd.yamaha.hv-voice',
  7105. 'hvs' => 'application/vnd.yamaha.hv-script',
  7106. 'i2g' => 'application/vnd.intergeo',
  7107. 'icc' => 'application/vnd.iccprofile',
  7108. 'ice' => 'x-conference/x-cooltalk',
  7109. 'icm' => 'application/vnd.iccprofile',
  7110. 'ico' => 'image/x-icon',
  7111. 'ics' => 'text/calendar',
  7112. 'ief' => 'image/ief',
  7113. 'ifb' => 'text/calendar',
  7114. 'ifm' => 'application/vnd.shana.informed.formdata',
  7115. 'iges' => 'model/iges',
  7116. 'igl' => 'application/vnd.igloader',
  7117. 'igm' => 'application/vnd.insors.igm',
  7118. 'igs' => 'model/iges',
  7119. 'igx' => 'application/vnd.micrografx.igx',
  7120. 'iif' => 'application/vnd.shana.informed.interchange',
  7121. 'imp' => 'application/vnd.accpac.simply.imp',
  7122. 'ims' => 'application/vnd.ms-ims',
  7123. 'in' => 'text/plain',
  7124. 'ink' => 'application/inkml+xml',
  7125. 'inkml' => 'application/inkml+xml',
  7126. 'install' => 'application/x-install-instructions',
  7127. 'iota' => 'application/vnd.astraea-software.iota',
  7128. 'ipfix' => 'application/ipfix',
  7129. 'ipk' => 'application/vnd.shana.informed.package',
  7130. 'irm' => 'application/vnd.ibm.rights-management',
  7131. 'irp' => 'application/vnd.irepository.package+xml',
  7132. 'iso' => 'application/x-iso9660-image',
  7133. 'itp' => 'application/vnd.shana.informed.formtemplate',
  7134. 'ivp' => 'application/vnd.immervision-ivp',
  7135. 'ivu' => 'application/vnd.immervision-ivu',
  7136. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  7137. 'jam' => 'application/vnd.jam',
  7138. 'jar' => 'application/java-archive',
  7139. 'java' => 'text/x-java-source',
  7140. 'jisp' => 'application/vnd.jisp',
  7141. 'jlt' => 'application/vnd.hp-jlyt',
  7142. 'jnlp' => 'application/x-java-jnlp-file',
  7143. 'joda' => 'application/vnd.joost.joda-archive',
  7144. 'jpe' => 'image/jpeg',
  7145. 'jpeg' => 'image/jpeg',
  7146. 'jpg' => 'image/jpeg',
  7147. 'jpgm' => 'video/jpm',
  7148. 'jpgv' => 'video/jpeg',
  7149. 'jpm' => 'video/jpm',
  7150. 'js' => 'application/javascript',
  7151. 'json' => 'application/json',
  7152. 'jsonml' => 'application/jsonml+json',
  7153. 'kar' => 'audio/midi',
  7154. 'karbon' => 'application/vnd.kde.karbon',
  7155. 'kfo' => 'application/vnd.kde.kformula',
  7156. 'kia' => 'application/vnd.kidspiration',
  7157. 'kml' => 'application/vnd.google-earth.kml+xml',
  7158. 'kmz' => 'application/vnd.google-earth.kmz',
  7159. 'kne' => 'application/vnd.kinar',
  7160. 'knp' => 'application/vnd.kinar',
  7161. 'kon' => 'application/vnd.kde.kontour',
  7162. 'kpr' => 'application/vnd.kde.kpresenter',
  7163. 'kpt' => 'application/vnd.kde.kpresenter',
  7164. 'kpxx' => 'application/vnd.ds-keypoint',
  7165. 'ksp' => 'application/vnd.kde.kspread',
  7166. 'ktr' => 'application/vnd.kahootz',
  7167. 'ktx' => 'image/ktx',
  7168. 'ktz' => 'application/vnd.kahootz',
  7169. 'kwd' => 'application/vnd.kde.kword',
  7170. 'kwt' => 'application/vnd.kde.kword',
  7171. 'lasxml' => 'application/vnd.las.las+xml',
  7172. 'latex' => 'application/x-latex',
  7173. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  7174. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  7175. 'les' => 'application/vnd.hhe.lesson-player',
  7176. 'lha' => 'application/x-lzh-compressed',
  7177. 'link66' => 'application/vnd.route66.link66+xml',
  7178. 'list' => 'text/plain',
  7179. 'list3820' => 'application/vnd.ibm.modcap',
  7180. 'listafp' => 'application/vnd.ibm.modcap',
  7181. 'lnk' => 'application/x-ms-shortcut',
  7182. 'log' => 'text/plain',
  7183. 'lostxml' => 'application/lost+xml',
  7184. 'lrf' => 'application/octet-stream',
  7185. 'lrm' => 'application/vnd.ms-lrm',
  7186. 'ltf' => 'application/vnd.frogans.ltf',
  7187. 'lvp' => 'audio/vnd.lucent.voice',
  7188. 'lwp' => 'application/vnd.lotus-wordpro',
  7189. 'lzh' => 'application/x-lzh-compressed',
  7190. 'm13' => 'application/x-msmediaview',
  7191. 'm14' => 'application/x-msmediaview',
  7192. 'm1v' => 'video/mpeg',
  7193. 'm21' => 'application/mp21',
  7194. 'm2a' => 'audio/mpeg',
  7195. 'm2v' => 'video/mpeg',
  7196. 'm3a' => 'audio/mpeg',
  7197. 'm3u' => 'audio/x-mpegurl',
  7198. 'm3u8' => 'application/vnd.apple.mpegurl',
  7199. 'm4a' => 'audio/mp4',
  7200. 'm4u' => 'video/vnd.mpegurl',
  7201. 'm4v' => 'video/x-m4v',
  7202. 'ma' => 'application/mathematica',
  7203. 'mads' => 'application/mads+xml',
  7204. 'mag' => 'application/vnd.ecowin.chart',
  7205. 'maker' => 'application/vnd.framemaker',
  7206. 'man' => 'text/troff',
  7207. 'mar' => 'application/octet-stream',
  7208. 'mathml' => 'application/mathml+xml',
  7209. 'mb' => 'application/mathematica',
  7210. 'mbk' => 'application/vnd.mobius.mbk',
  7211. 'mbox' => 'application/mbox',
  7212. 'mc1' => 'application/vnd.medcalcdata',
  7213. 'mcd' => 'application/vnd.mcd',
  7214. 'mcurl' => 'text/vnd.curl.mcurl',
  7215. 'mdb' => 'application/x-msaccess',
  7216. 'mdi' => 'image/vnd.ms-modi',
  7217. 'me' => 'text/troff',
  7218. 'mesh' => 'model/mesh',
  7219. 'meta4' => 'application/metalink4+xml',
  7220. 'metalink' => 'application/metalink+xml',
  7221. 'mets' => 'application/mets+xml',
  7222. 'mfm' => 'application/vnd.mfmp',
  7223. 'mft' => 'application/rpki-manifest',
  7224. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  7225. 'mgz' => 'application/vnd.proteus.magazine',
  7226. 'mid' => 'audio/midi',
  7227. 'midi' => 'audio/midi',
  7228. 'mie' => 'application/x-mie',
  7229. 'mif' => 'application/vnd.mif',
  7230. 'mime' => 'message/rfc822',
  7231. 'mj2' => 'video/mj2',
  7232. 'mjp2' => 'video/mj2',
  7233. 'mk3d' => 'video/x-matroska',
  7234. 'mka' => 'audio/x-matroska',
  7235. 'mks' => 'video/x-matroska',
  7236. 'mkv' => 'video/x-matroska',
  7237. 'mlp' => 'application/vnd.dolby.mlp',
  7238. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  7239. 'mmf' => 'application/vnd.smaf',
  7240. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  7241. 'mng' => 'video/x-mng',
  7242. 'mny' => 'application/x-msmoney',
  7243. 'mobi' => 'application/x-mobipocket-ebook',
  7244. 'mods' => 'application/mods+xml',
  7245. 'mov' => 'video/quicktime',
  7246. 'movie' => 'video/x-sgi-movie',
  7247. 'mp2' => 'audio/mpeg',
  7248. 'mp21' => 'application/mp21',
  7249. 'mp2a' => 'audio/mpeg',
  7250. 'mp3' => 'audio/mpeg',
  7251. 'mp4' => 'video/mp4',
  7252. 'mp4a' => 'audio/mp4',
  7253. 'mp4s' => 'application/mp4',
  7254. 'mp4v' => 'video/mp4',
  7255. 'mpc' => 'application/vnd.mophun.certificate',
  7256. 'mpe' => 'video/mpeg',
  7257. 'mpeg' => 'video/mpeg',
  7258. 'mpg' => 'video/mpeg',
  7259. 'mpg4' => 'video/mp4',
  7260. 'mpga' => 'audio/mpeg',
  7261. 'mpkg' => 'application/vnd.apple.installer+xml',
  7262. 'mpm' => 'application/vnd.blueice.multipass',
  7263. 'mpn' => 'application/vnd.mophun.application',
  7264. 'mpp' => 'application/vnd.ms-project',
  7265. 'mpt' => 'application/vnd.ms-project',
  7266. 'mpy' => 'application/vnd.ibm.minipay',
  7267. 'mqy' => 'application/vnd.mobius.mqy',
  7268. 'mrc' => 'application/marc',
  7269. 'mrcx' => 'application/marcxml+xml',
  7270. 'ms' => 'text/troff',
  7271. 'mscml' => 'application/mediaservercontrol+xml',
  7272. 'mseed' => 'application/vnd.fdsn.mseed',
  7273. 'mseq' => 'application/vnd.mseq',
  7274. 'msf' => 'application/vnd.epson.msf',
  7275. 'msh' => 'model/mesh',
  7276. 'msi' => 'application/x-msdownload',
  7277. 'msl' => 'application/vnd.mobius.msl',
  7278. 'msty' => 'application/vnd.muvee.style',
  7279. 'mts' => 'model/vnd.mts',
  7280. 'mus' => 'application/vnd.musician',
  7281. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  7282. 'mvb' => 'application/x-msmediaview',
  7283. 'mwf' => 'application/vnd.mfer',
  7284. 'mxf' => 'application/mxf',
  7285. 'mxl' => 'application/vnd.recordare.musicxml',
  7286. 'mxml' => 'application/xv+xml',
  7287. 'mxs' => 'application/vnd.triscape.mxs',
  7288. 'mxu' => 'video/vnd.mpegurl',
  7289. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  7290. 'n3' => 'text/n3',
  7291. 'nb' => 'application/mathematica',
  7292. 'nbp' => 'application/vnd.wolfram.player',
  7293. 'nc' => 'application/x-netcdf',
  7294. 'ncx' => 'application/x-dtbncx+xml',
  7295. 'nfo' => 'text/x-nfo',
  7296. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  7297. 'nitf' => 'application/vnd.nitf',
  7298. 'nlu' => 'application/vnd.neurolanguage.nlu',
  7299. 'nml' => 'application/vnd.enliven',
  7300. 'nnd' => 'application/vnd.noblenet-directory',
  7301. 'nns' => 'application/vnd.noblenet-sealer',
  7302. 'nnw' => 'application/vnd.noblenet-web',
  7303. 'npx' => 'image/vnd.net-fpx',
  7304. 'nsc' => 'application/x-conference',
  7305. 'nsf' => 'application/vnd.lotus-notes',
  7306. 'ntf' => 'application/vnd.nitf',
  7307. 'nzb' => 'application/x-nzb',
  7308. 'oa2' => 'application/vnd.fujitsu.oasys2',
  7309. 'oa3' => 'application/vnd.fujitsu.oasys3',
  7310. 'oas' => 'application/vnd.fujitsu.oasys',
  7311. 'obd' => 'application/x-msbinder',
  7312. 'obj' => 'application/x-tgif',
  7313. 'oda' => 'application/oda',
  7314. 'odb' => 'application/vnd.oasis.opendocument.database',
  7315. 'odc' => 'application/vnd.oasis.opendocument.chart',
  7316. 'odf' => 'application/vnd.oasis.opendocument.formula',
  7317. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  7318. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  7319. 'odi' => 'application/vnd.oasis.opendocument.image',
  7320. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  7321. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  7322. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  7323. 'odt' => 'application/vnd.oasis.opendocument.text',
  7324. 'oga' => 'audio/ogg',
  7325. 'ogg' => 'audio/ogg',
  7326. 'ogv' => 'video/ogg',
  7327. 'ogx' => 'application/ogg',
  7328. 'omdoc' => 'application/omdoc+xml',
  7329. 'onepkg' => 'application/onenote',
  7330. 'onetmp' => 'application/onenote',
  7331. 'onetoc' => 'application/onenote',
  7332. 'onetoc2' => 'application/onenote',
  7333. 'opf' => 'application/oebps-package+xml',
  7334. 'opml' => 'text/x-opml',
  7335. 'oprc' => 'application/vnd.palm',
  7336. 'org' => 'application/vnd.lotus-organizer',
  7337. 'osf' => 'application/vnd.yamaha.openscoreformat',
  7338. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  7339. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  7340. 'otf' => 'application/x-font-otf',
  7341. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  7342. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  7343. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  7344. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  7345. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  7346. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  7347. 'oxps' => 'application/oxps',
  7348. 'oxt' => 'application/vnd.openofficeorg.extension',
  7349. 'p' => 'text/x-pascal',
  7350. 'p10' => 'application/pkcs10',
  7351. 'p12' => 'application/x-pkcs12',
  7352. 'p7b' => 'application/x-pkcs7-certificates',
  7353. 'p7c' => 'application/pkcs7-mime',
  7354. 'p7m' => 'application/pkcs7-mime',
  7355. 'p7r' => 'application/x-pkcs7-certreqresp',
  7356. 'p7s' => 'application/pkcs7-signature',
  7357. 'p8' => 'application/pkcs8',
  7358. 'pas' => 'text/x-pascal',
  7359. 'paw' => 'application/vnd.pawaafile',
  7360. 'pbd' => 'application/vnd.powerbuilder6',
  7361. 'pbm' => 'image/x-portable-bitmap',
  7362. 'pcap' => 'application/vnd.tcpdump.pcap',
  7363. 'pcf' => 'application/x-font-pcf',
  7364. 'pcl' => 'application/vnd.hp-pcl',
  7365. 'pclxl' => 'application/vnd.hp-pclxl',
  7366. 'pct' => 'image/x-pict',
  7367. 'pcurl' => 'application/vnd.curl.pcurl',
  7368. 'pcx' => 'image/x-pcx',
  7369. 'pdb' => 'application/vnd.palm',
  7370. 'pdf' => 'application/pdf',
  7371. 'pfa' => 'application/x-font-type1',
  7372. 'pfb' => 'application/x-font-type1',
  7373. 'pfm' => 'application/x-font-type1',
  7374. 'pfr' => 'application/font-tdpfr',
  7375. 'pfx' => 'application/x-pkcs12',
  7376. 'pgm' => 'image/x-portable-graymap',
  7377. 'pgn' => 'application/x-chess-pgn',
  7378. 'pgp' => 'application/pgp-encrypted',
  7379. 'pic' => 'image/x-pict',
  7380. 'pkg' => 'application/octet-stream',
  7381. 'pki' => 'application/pkixcmp',
  7382. 'pkipath' => 'application/pkix-pkipath',
  7383. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  7384. 'plc' => 'application/vnd.mobius.plc',
  7385. 'plf' => 'application/vnd.pocketlearn',
  7386. 'pls' => 'application/pls+xml',
  7387. 'pml' => 'application/vnd.ctc-posml',
  7388. 'png' => 'image/png',
  7389. 'pnm' => 'image/x-portable-anymap',
  7390. 'portpkg' => 'application/vnd.macports.portpkg',
  7391. 'pot' => 'application/vnd.ms-powerpoint',
  7392. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  7393. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  7394. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  7395. 'ppd' => 'application/vnd.cups-ppd',
  7396. 'ppm' => 'image/x-portable-pixmap',
  7397. 'pps' => 'application/vnd.ms-powerpoint',
  7398. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  7399. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  7400. 'ppt' => 'application/vnd.ms-powerpoint',
  7401. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  7402. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  7403. 'pqa' => 'application/vnd.palm',
  7404. 'prc' => 'application/x-mobipocket-ebook',
  7405. 'pre' => 'application/vnd.lotus-freelance',
  7406. 'prf' => 'application/pics-rules',
  7407. 'ps' => 'application/postscript',
  7408. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  7409. 'psd' => 'image/vnd.adobe.photoshop',
  7410. 'psf' => 'application/x-font-linux-psf',
  7411. 'pskcxml' => 'application/pskc+xml',
  7412. 'ptid' => 'application/vnd.pvi.ptid1',
  7413. 'pub' => 'application/x-mspublisher',
  7414. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  7415. 'pwn' => 'application/vnd.3m.post-it-notes',
  7416. 'pya' => 'audio/vnd.ms-playready.media.pya',
  7417. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  7418. 'qam' => 'application/vnd.epson.quickanime',
  7419. 'qbo' => 'application/vnd.intu.qbo',
  7420. 'qfx' => 'application/vnd.intu.qfx',
  7421. 'qps' => 'application/vnd.publishare-delta-tree',
  7422. 'qt' => 'video/quicktime',
  7423. 'qwd' => 'application/vnd.quark.quarkxpress',
  7424. 'qwt' => 'application/vnd.quark.quarkxpress',
  7425. 'qxb' => 'application/vnd.quark.quarkxpress',
  7426. 'qxd' => 'application/vnd.quark.quarkxpress',
  7427. 'qxl' => 'application/vnd.quark.quarkxpress',
  7428. 'qxt' => 'application/vnd.quark.quarkxpress',
  7429. 'ra' => 'audio/x-pn-realaudio',
  7430. 'ram' => 'audio/x-pn-realaudio',
  7431. 'rar' => 'application/x-rar-compressed',
  7432. 'ras' => 'image/x-cmu-raster',
  7433. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  7434. 'rdf' => 'application/rdf+xml',
  7435. 'rdz' => 'application/vnd.data-vision.rdz',
  7436. 'rep' => 'application/vnd.businessobjects',
  7437. 'res' => 'application/x-dtbresource+xml',
  7438. 'rgb' => 'image/x-rgb',
  7439. 'rif' => 'application/reginfo+xml',
  7440. 'rip' => 'audio/vnd.rip',
  7441. 'ris' => 'application/x-research-info-systems',
  7442. 'rl' => 'application/resource-lists+xml',
  7443. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  7444. 'rld' => 'application/resource-lists-diff+xml',
  7445. 'rm' => 'application/vnd.rn-realmedia',
  7446. 'rmi' => 'audio/midi',
  7447. 'rmp' => 'audio/x-pn-realaudio-plugin',
  7448. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  7449. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  7450. 'rnc' => 'application/relax-ng-compact-syntax',
  7451. 'roa' => 'application/rpki-roa',
  7452. 'roff' => 'text/troff',
  7453. 'rp9' => 'application/vnd.cloanto.rp9',
  7454. 'rpss' => 'application/vnd.nokia.radio-presets',
  7455. 'rpst' => 'application/vnd.nokia.radio-preset',
  7456. 'rq' => 'application/sparql-query',
  7457. 'rs' => 'application/rls-services+xml',
  7458. 'rsd' => 'application/rsd+xml',
  7459. 'rss' => 'application/rss+xml',
  7460. 'rtf' => 'application/rtf',
  7461. 'rtx' => 'text/richtext',
  7462. 's' => 'text/x-asm',
  7463. 's3m' => 'audio/s3m',
  7464. 'saf' => 'application/vnd.yamaha.smaf-audio',
  7465. 'sbml' => 'application/sbml+xml',
  7466. 'sc' => 'application/vnd.ibm.secure-container',
  7467. 'scd' => 'application/x-msschedule',
  7468. 'scm' => 'application/vnd.lotus-screencam',
  7469. 'scq' => 'application/scvp-cv-request',
  7470. 'scs' => 'application/scvp-cv-response',
  7471. 'scurl' => 'text/vnd.curl.scurl',
  7472. 'sda' => 'application/vnd.stardivision.draw',
  7473. 'sdc' => 'application/vnd.stardivision.calc',
  7474. 'sdd' => 'application/vnd.stardivision.impress',
  7475. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  7476. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  7477. 'sdp' => 'application/sdp',
  7478. 'sdw' => 'application/vnd.stardivision.writer',
  7479. 'see' => 'application/vnd.seemail',
  7480. 'seed' => 'application/vnd.fdsn.seed',
  7481. 'sema' => 'application/vnd.sema',
  7482. 'semd' => 'application/vnd.semd',
  7483. 'semf' => 'application/vnd.semf',
  7484. 'ser' => 'application/java-serialized-object',
  7485. 'setpay' => 'application/set-payment-initiation',
  7486. 'setreg' => 'application/set-registration-initiation',
  7487. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  7488. 'sfs' => 'application/vnd.spotfire.sfs',
  7489. 'sfv' => 'text/x-sfv',
  7490. 'sgi' => 'image/sgi',
  7491. 'sgl' => 'application/vnd.stardivision.writer-global',
  7492. 'sgm' => 'text/sgml',
  7493. 'sgml' => 'text/sgml',
  7494. 'sh' => 'application/x-sh',
  7495. 'shar' => 'application/x-shar',
  7496. 'shf' => 'application/shf+xml',
  7497. 'sid' => 'image/x-mrsid-image',
  7498. 'sig' => 'application/pgp-signature',
  7499. 'sil' => 'audio/silk',
  7500. 'silo' => 'model/mesh',
  7501. 'sis' => 'application/vnd.symbian.install',
  7502. 'sisx' => 'application/vnd.symbian.install',
  7503. 'sit' => 'application/x-stuffit',
  7504. 'sitx' => 'application/x-stuffitx',
  7505. 'skd' => 'application/vnd.koan',
  7506. 'skm' => 'application/vnd.koan',
  7507. 'skp' => 'application/vnd.koan',
  7508. 'skt' => 'application/vnd.koan',
  7509. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  7510. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  7511. 'slt' => 'application/vnd.epson.salt',
  7512. 'sm' => 'application/vnd.stepmania.stepchart',
  7513. 'smf' => 'application/vnd.stardivision.math',
  7514. 'smi' => 'application/smil+xml',
  7515. 'smil' => 'application/smil+xml',
  7516. 'smv' => 'video/x-smv',
  7517. 'smzip' => 'application/vnd.stepmania.package',
  7518. 'snd' => 'audio/basic',
  7519. 'snf' => 'application/x-font-snf',
  7520. 'so' => 'application/octet-stream',
  7521. 'spc' => 'application/x-pkcs7-certificates',
  7522. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  7523. 'spl' => 'application/x-futuresplash',
  7524. 'spot' => 'text/vnd.in3d.spot',
  7525. 'spp' => 'application/scvp-vp-response',
  7526. 'spq' => 'application/scvp-vp-request',
  7527. 'spx' => 'audio/ogg',
  7528. 'sql' => 'application/x-sql',
  7529. 'src' => 'application/x-wais-source',
  7530. 'srt' => 'application/x-subrip',
  7531. 'sru' => 'application/sru+xml',
  7532. 'srx' => 'application/sparql-results+xml',
  7533. 'ssdl' => 'application/ssdl+xml',
  7534. 'sse' => 'application/vnd.kodak-descriptor',
  7535. 'ssf' => 'application/vnd.epson.ssf',
  7536. 'ssml' => 'application/ssml+xml',
  7537. 'st' => 'application/vnd.sailingtracker.track',
  7538. 'stc' => 'application/vnd.sun.xml.calc.template',
  7539. 'std' => 'application/vnd.sun.xml.draw.template',
  7540. 'stf' => 'application/vnd.wt.stf',
  7541. 'sti' => 'application/vnd.sun.xml.impress.template',
  7542. 'stk' => 'application/hyperstudio',
  7543. 'stl' => 'application/vnd.ms-pki.stl',
  7544. 'str' => 'application/vnd.pg.format',
  7545. 'stw' => 'application/vnd.sun.xml.writer.template',
  7546. 'sub' => 'image/vnd.dvb.subtitle',
  7547. 'sub' => 'text/vnd.dvb.subtitle',
  7548. 'sus' => 'application/vnd.sus-calendar',
  7549. 'susp' => 'application/vnd.sus-calendar',
  7550. 'sv4cpio' => 'application/x-sv4cpio',
  7551. 'sv4crc' => 'application/x-sv4crc',
  7552. 'svc' => 'application/vnd.dvb.service',
  7553. 'svd' => 'application/vnd.svd',
  7554. 'svg' => 'image/svg+xml',
  7555. 'svgz' => 'image/svg+xml',
  7556. 'swa' => 'application/x-director',
  7557. 'swf' => 'application/x-shockwave-flash',
  7558. 'swi' => 'application/vnd.aristanetworks.swi',
  7559. 'sxc' => 'application/vnd.sun.xml.calc',
  7560. 'sxd' => 'application/vnd.sun.xml.draw',
  7561. 'sxg' => 'application/vnd.sun.xml.writer.global',
  7562. 'sxi' => 'application/vnd.sun.xml.impress',
  7563. 'sxm' => 'application/vnd.sun.xml.math',
  7564. 'sxw' => 'application/vnd.sun.xml.writer',
  7565. 't' => 'text/troff',
  7566. 't3' => 'application/x-t3vm-image',
  7567. 'taglet' => 'application/vnd.mynfc',
  7568. 'tao' => 'application/vnd.tao.intent-module-archive',
  7569. 'tar' => 'application/x-tar',
  7570. 'tcap' => 'application/vnd.3gpp2.tcap',
  7571. 'tcl' => 'application/x-tcl',
  7572. 'teacher' => 'application/vnd.smart.teacher',
  7573. 'tei' => 'application/tei+xml',
  7574. 'teicorpus' => 'application/tei+xml',
  7575. 'tex' => 'application/x-tex',
  7576. 'texi' => 'application/x-texinfo',
  7577. 'texinfo' => 'application/x-texinfo',
  7578. 'text' => 'text/plain',
  7579. 'tfi' => 'application/thraud+xml',
  7580. 'tfm' => 'application/x-tex-tfm',
  7581. 'tga' => 'image/x-tga',
  7582. 'thmx' => 'application/vnd.ms-officetheme',
  7583. 'tif' => 'image/tiff',
  7584. 'tiff' => 'image/tiff',
  7585. 'tmo' => 'application/vnd.tmobile-livetv',
  7586. 'torrent' => 'application/x-bittorrent',
  7587. 'tpl' => 'application/vnd.groove-tool-template',
  7588. 'tpt' => 'application/vnd.trid.tpt',
  7589. 'tr' => 'text/troff',
  7590. 'tra' => 'application/vnd.trueapp',
  7591. 'trm' => 'application/x-msterminal',
  7592. 'tsd' => 'application/timestamped-data',
  7593. 'tsv' => 'text/tab-separated-values',
  7594. 'ttc' => 'application/x-font-ttf',
  7595. 'ttf' => 'application/x-font-ttf',
  7596. 'ttl' => 'text/turtle',
  7597. 'twd' => 'application/vnd.simtech-mindmapper',
  7598. 'twds' => 'application/vnd.simtech-mindmapper',
  7599. 'txd' => 'application/vnd.genomatix.tuxedo',
  7600. 'txf' => 'application/vnd.mobius.txf',
  7601. 'txt' => 'text/plain',
  7602. 'u32' => 'application/x-authorware-bin',
  7603. 'udeb' => 'application/x-debian-package',
  7604. 'ufd' => 'application/vnd.ufdl',
  7605. 'ufdl' => 'application/vnd.ufdl',
  7606. 'ulx' => 'application/x-glulx',
  7607. 'umj' => 'application/vnd.umajin',
  7608. 'unityweb' => 'application/vnd.unity',
  7609. 'uoml' => 'application/vnd.uoml+xml',
  7610. 'uri' => 'text/uri-list',
  7611. 'uris' => 'text/uri-list',
  7612. 'urls' => 'text/uri-list',
  7613. 'ustar' => 'application/x-ustar',
  7614. 'utz' => 'application/vnd.uiq.theme',
  7615. 'uu' => 'text/x-uuencode',
  7616. 'uva' => 'audio/vnd.dece.audio',
  7617. 'uvd' => 'application/vnd.dece.data',
  7618. 'uvf' => 'application/vnd.dece.data',
  7619. 'uvg' => 'image/vnd.dece.graphic',
  7620. 'uvh' => 'video/vnd.dece.hd',
  7621. 'uvi' => 'image/vnd.dece.graphic',
  7622. 'uvm' => 'video/vnd.dece.mobile',
  7623. 'uvp' => 'video/vnd.dece.pd',
  7624. 'uvs' => 'video/vnd.dece.sd',
  7625. 'uvt' => 'application/vnd.dece.ttml+xml',
  7626. 'uvu' => 'video/vnd.uvvu.mp4',
  7627. 'uvv' => 'video/vnd.dece.video',
  7628. 'uvva' => 'audio/vnd.dece.audio',
  7629. 'uvvd' => 'application/vnd.dece.data',
  7630. 'uvvf' => 'application/vnd.dece.data',
  7631. 'uvvg' => 'image/vnd.dece.graphic',
  7632. 'uvvh' => 'video/vnd.dece.hd',
  7633. 'uvvi' => 'image/vnd.dece.graphic',
  7634. 'uvvm' => 'video/vnd.dece.mobile',
  7635. 'uvvp' => 'video/vnd.dece.pd',
  7636. 'uvvs' => 'video/vnd.dece.sd',
  7637. 'uvvt' => 'application/vnd.dece.ttml+xml',
  7638. 'uvvu' => 'video/vnd.uvvu.mp4',
  7639. 'uvvv' => 'video/vnd.dece.video',
  7640. 'uvvx' => 'application/vnd.dece.unspecified',
  7641. 'uvvz' => 'application/vnd.dece.zip',
  7642. 'uvx' => 'application/vnd.dece.unspecified',
  7643. 'uvz' => 'application/vnd.dece.zip',
  7644. 'vcard' => 'text/vcard',
  7645. 'vcd' => 'application/x-cdlink',
  7646. 'vcf' => 'text/x-vcard',
  7647. 'vcg' => 'application/vnd.groove-vcard',
  7648. 'vcs' => 'text/x-vcalendar',
  7649. 'vcx' => 'application/vnd.vcx',
  7650. 'vis' => 'application/vnd.visionary',
  7651. 'viv' => 'video/vnd.vivo',
  7652. 'vob' => 'video/x-ms-vob',
  7653. 'vor' => 'application/vnd.stardivision.writer',
  7654. 'vox' => 'application/x-authorware-bin',
  7655. 'vrml' => 'model/vrml',
  7656. 'vsd' => 'application/vnd.visio',
  7657. 'vsf' => 'application/vnd.vsf',
  7658. 'vss' => 'application/vnd.visio',
  7659. 'vst' => 'application/vnd.visio',
  7660. 'vsw' => 'application/vnd.visio',
  7661. 'vtu' => 'model/vnd.vtu',
  7662. 'vxml' => 'application/voicexml+xml',
  7663. 'w3d' => 'application/x-director',
  7664. 'wad' => 'application/x-doom',
  7665. 'wav' => 'audio/x-wav',
  7666. 'wax' => 'audio/x-ms-wax',
  7667. 'wbmp' => 'image/vnd.wap.wbmp',
  7668. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  7669. 'wbxml' => 'application/vnd.wap.wbxml',
  7670. 'wcm' => 'application/vnd.ms-works',
  7671. 'wdb' => 'application/vnd.ms-works',
  7672. 'wdp' => 'image/vnd.ms-photo',
  7673. 'weba' => 'audio/webm',
  7674. 'webm' => 'video/webm',
  7675. 'webp' => 'image/webp',
  7676. 'wg' => 'application/vnd.pmi.widget',
  7677. 'wgt' => 'application/widget',
  7678. 'wks' => 'application/vnd.ms-works',
  7679. 'wm' => 'video/x-ms-wm',
  7680. 'wma' => 'audio/x-ms-wma',
  7681. 'wmd' => 'application/x-ms-wmd',
  7682. 'wmf' => 'application/x-msmetafile',
  7683. 'wml' => 'text/vnd.wap.wml',
  7684. 'wmlc' => 'application/vnd.wap.wmlc',
  7685. 'wmls' => 'text/vnd.wap.wmlscript',
  7686. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  7687. 'wmv' => 'video/x-ms-wmv',
  7688. 'wmx' => 'video/x-ms-wmx',
  7689. 'wmz' => 'application/x-ms-wmz',
  7690. 'wmz' => 'application/x-msmetafile',
  7691. 'woff' => 'application/font-woff',
  7692. 'wpd' => 'application/vnd.wordperfect',
  7693. 'wpl' => 'application/vnd.ms-wpl',
  7694. 'wps' => 'application/vnd.ms-works',
  7695. 'wqd' => 'application/vnd.wqd',
  7696. 'wri' => 'application/x-mswrite',
  7697. 'wrl' => 'model/vrml',
  7698. 'wsdl' => 'application/wsdl+xml',
  7699. 'wspolicy' => 'application/wspolicy+xml',
  7700. 'wtb' => 'application/vnd.webturbo',
  7701. 'wvx' => 'video/x-ms-wvx',
  7702. 'x32' => 'application/x-authorware-bin',
  7703. 'x3d' => 'model/x3d+xml',
  7704. 'x3db' => 'model/x3d+binary',
  7705. 'x3dbz' => 'model/x3d+binary',
  7706. 'x3dv' => 'model/x3d+vrml',
  7707. 'x3dvz' => 'model/x3d+vrml',
  7708. 'x3dz' => 'model/x3d+xml',
  7709. 'xaml' => 'application/xaml+xml',
  7710. 'xap' => 'application/x-silverlight-app',
  7711. 'xar' => 'application/vnd.xara',
  7712. 'xbap' => 'application/x-ms-xbap',
  7713. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  7714. 'xbm' => 'image/x-xbitmap',
  7715. 'xdf' => 'application/xcap-diff+xml',
  7716. 'xdm' => 'application/vnd.syncml.dm+xml',
  7717. 'xdp' => 'application/vnd.adobe.xdp+xml',
  7718. 'xdssc' => 'application/dssc+xml',
  7719. 'xdw' => 'application/vnd.fujixerox.docuworks',
  7720. 'xenc' => 'application/xenc+xml',
  7721. 'xer' => 'application/patch-ops-error+xml',
  7722. 'xfdf' => 'application/vnd.adobe.xfdf',
  7723. 'xfdl' => 'application/vnd.xfdl',
  7724. 'xht' => 'application/xhtml+xml',
  7725. 'xhtml' => 'application/xhtml+xml',
  7726. 'xhvml' => 'application/xv+xml',
  7727. 'xif' => 'image/vnd.xiff',
  7728. 'xla' => 'application/vnd.ms-excel',
  7729. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  7730. 'xlc' => 'application/vnd.ms-excel',
  7731. 'xlf' => 'application/x-xliff+xml',
  7732. 'xlm' => 'application/vnd.ms-excel',
  7733. 'xls' => 'application/vnd.ms-excel',
  7734. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  7735. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  7736. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  7737. 'xlt' => 'application/vnd.ms-excel',
  7738. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  7739. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  7740. 'xlw' => 'application/vnd.ms-excel',
  7741. 'xm' => 'audio/xm',
  7742. 'xml' => 'application/xml',
  7743. 'xo' => 'application/vnd.olpc-sugar',
  7744. 'xop' => 'application/xop+xml',
  7745. 'xpi' => 'application/x-xpinstall',
  7746. 'xpl' => 'application/xproc+xml',
  7747. 'xpm' => 'image/x-xpixmap',
  7748. 'xpr' => 'application/vnd.is-xpr',
  7749. 'xps' => 'application/vnd.ms-xpsdocument',
  7750. 'xpw' => 'application/vnd.intercon.formnet',
  7751. 'xpx' => 'application/vnd.intercon.formnet',
  7752. 'xsl' => 'application/xml',
  7753. 'xslt' => 'application/xslt+xml',
  7754. 'xsm' => 'application/vnd.syncml+xml',
  7755. 'xspf' => 'application/xspf+xml',
  7756. 'xul' => 'application/vnd.mozilla.xul+xml',
  7757. 'xvm' => 'application/xv+xml',
  7758. 'xvml' => 'application/xv+xml',
  7759. 'xwd' => 'image/x-xwindowdump',
  7760. 'xyz' => 'chemical/x-xyz',
  7761. 'xz' => 'application/x-xz',
  7762. 'yang' => 'application/yang',
  7763. 'yin' => 'application/yin+xml',
  7764. 'z1' => 'application/x-zmachine',
  7765. 'z2' => 'application/x-zmachine',
  7766. 'z3' => 'application/x-zmachine',
  7767. 'z4' => 'application/x-zmachine',
  7768. 'z5' => 'application/x-zmachine',
  7769. 'z6' => 'application/x-zmachine',
  7770. 'z7' => 'application/x-zmachine',
  7771. 'z8' => 'application/x-zmachine',
  7772. 'zaz' => 'application/vnd.zzazz.deck+xml',
  7773. 'zip' => 'application/zip',
  7774. 'zir' => 'application/vnd.zul',
  7775. 'zirz' => 'application/vnd.zul',
  7776. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  7777. );
  7778. }
  7779. // Always run this
  7780. if(strpos($_SERVER['SCRIPT_NAME'], 'check.php') == false){
  7781. dependCheck();
  7782. }