functions.php 309 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.50');
  5. // ===================================
  6. use Kryptonit3\Sonarr\Sonarr;
  7. use Kryptonit3\SickRage\SickRage;
  8. // Debugging output functions
  9. function debug_out($variable, $die = false) {
  10. $trace = debug_backtrace()[0];
  11. echo "<center><img height='200px' src='images/confused.png'></center>";
  12. echo "<center>Look's like something happened, here are the errors and perhaps how to fix them:</center>";
  13. echo '<pre style="white-space: pre-line; background-color: #f2f2f2; border: 2px solid black; border-radius: 5px; padding: 5px; margin: 5px;">'.$trace['file'].':'.$trace['line']."\n\n".print_r($variable, true).'</pre>';
  14. if ($die) { http_response_code(503); die(); }
  15. }
  16. // ==== Auth Plugins START ====
  17. if (function_exists('ldap_connect')) :
  18. // Pass credentials to LDAP backend
  19. function plugin_auth_ldap($username, $password) {
  20. $ldapServers = explode(',',AUTHBACKENDHOST);
  21. foreach($ldapServers as $key => $value) {
  22. // Calculate parts
  23. $digest = parse_url(trim($value));
  24. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  25. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  26. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  27. // Reassign
  28. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  29. }
  30. // returns true or false
  31. $ldap = ldap_connect(implode(' ',$ldapServers));
  32. if(empty(AUTHBACKENDDOMAINFORMAT)){
  33. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  34. writeLog("success", "LDAP authentication success");
  35. return true;
  36. } else {
  37. writeLog("error", "LDAP could not authenticate");
  38. return false;
  39. }
  40. }else{
  41. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  42. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  43. $bind = @ldap_bind($ldap, sprintf(AUTHBACKENDDOMAINFORMAT, $username), $password);
  44. if ($bind) {
  45. writeLog("success", "LDAP authentication success");
  46. return true;
  47. } else {
  48. writeLog("error", "LDPA could not authenticate");
  49. return false;
  50. }
  51. }
  52. writeLog("error", "LDAP could not authenticate");
  53. return false;
  54. }
  55. else :
  56. // Ldap Auth Missing Dependancy
  57. function plugin_auth_ldap_disabled() {
  58. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  59. }
  60. endif;
  61. // Pass credentials to FTP backend
  62. function plugin_auth_ftp($username, $password) {
  63. // Calculate parts
  64. $digest = parse_url(AUTHBACKENDHOST);
  65. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  66. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  67. $port = (isset($digest['port'])?$digest['port']:21);
  68. // Determine Connection Type
  69. if ($scheme == 'ftps') {
  70. $conn_id = ftp_ssl_connect($host, $port, 20);
  71. } elseif ($scheme == 'ftp') {
  72. $conn_id = ftp_connect($host, $port, 20);
  73. } else {
  74. debug_out('Invalid FTP scheme. Use ftp or ftps');
  75. writeLog("error", "invalid FTP scheme");
  76. return false;
  77. }
  78. // Check if valid FTP connection
  79. if ($conn_id) {
  80. // Attempt login
  81. @$login_result = ftp_login($conn_id, $username, $password);
  82. ftp_close($conn_id);
  83. // Return Result
  84. if ($login_result) {
  85. writeLog("success", "$username authenticated");
  86. return true;
  87. } else {
  88. writeLog("error", "$username could not authenticate");
  89. return false;
  90. }
  91. } else {
  92. return false;
  93. }
  94. return false;
  95. }
  96. // Pass credentials to Emby Backend
  97. function plugin_auth_emby_local($username, $password) {
  98. $embyAddress = qualifyURL(EMBYURL);
  99. $headers = array(
  100. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  101. 'Content-Type' => 'application/json',
  102. );
  103. $body = array(
  104. 'Username' => $username,
  105. 'Password' => sha1($password),
  106. 'PasswordMd5' => md5($password),
  107. );
  108. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  109. if (isset($response['content'])) {
  110. $json = json_decode($response['content'], true);
  111. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  112. // Login Success - Now Logout Emby Session As We No Longer Need It
  113. $headers = array(
  114. 'X-Mediabrowser-Token' => $json['AccessToken'],
  115. );
  116. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  117. return true;
  118. }
  119. }
  120. return false;
  121. }
  122. if (function_exists('curl_version')) :
  123. // Authenticate Against Emby Local (first) and Emby Connect
  124. function plugin_auth_emby_all($username, $password) {
  125. $localResult = plugin_auth_emby_local($username, $password);
  126. if ($localResult) {
  127. return $localResult;
  128. } else {
  129. return plugin_auth_emby_connect($username, $password);
  130. }
  131. }
  132. // Authenicate against emby connect
  133. function plugin_auth_emby_connect($username, $password) {
  134. $embyAddress = qualifyURL(EMBYURL);
  135. // Get A User
  136. $connectId = '';
  137. $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  138. if (is_array($userIds)) {
  139. foreach ($userIds as $key => $value) { // Scan for this user
  140. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  141. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  142. $connectId = $value['ConnectUserId'];
  143. break;
  144. }
  145. }
  146. }
  147. if ($connectId) {
  148. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  149. $headers = array(
  150. 'Accept'=> 'application/json',
  151. 'Content-Type' => 'application/x-www-form-urlencoded',
  152. );
  153. $body = array(
  154. 'nameOrEmail' => $username,
  155. 'rawpw' => $password,
  156. );
  157. $result = curl_post($connectURL, $body, $headers);
  158. if (isset($result['content'])) {
  159. $json = json_decode($result['content'], true);
  160. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  161. return array(
  162. 'email' => $json['User']['Email'],
  163. 'image' => $json['User']['ImageUrl'],
  164. );
  165. }
  166. }
  167. }
  168. }
  169. return false;
  170. }
  171. // Pass credentials to Plex Backend
  172. function plugin_auth_plex($username, $password) {
  173. // Quick out
  174. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  175. writeLog("success", $username." authenticated by plex");
  176. return true;
  177. }
  178. //Get User List
  179. $userURL = 'https://plex.tv/pms/friends/all';
  180. $userHeaders = array(
  181. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  182. );
  183. libxml_use_internal_errors(true);
  184. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  185. if (is_array($userXML) || is_object($userXML)) {
  186. $isUser = false;
  187. $usernameLower = strtolower($username);
  188. foreach($userXML AS $child) {
  189. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  190. $isUser = true;
  191. writeLog("success", $usernameLower." was found in plex friends list");
  192. break;
  193. }
  194. }
  195. if ($isUser) {
  196. //Login User
  197. $connectURL = 'https://plex.tv/users/sign_in.json';
  198. $headers = array(
  199. 'Accept'=> 'application/json',
  200. 'Content-Type' => 'application/x-www-form-urlencoded',
  201. 'X-Plex-Product' => 'Organizr',
  202. 'X-Plex-Version' => '1.0',
  203. 'X-Plex-Client-Identifier' => '01010101-10101010',
  204. );
  205. $body = array(
  206. 'user[login]' => $username,
  207. 'user[password]' => $password,
  208. );
  209. $result = curl_post($connectURL, $body, $headers);
  210. if (isset($result['content'])) {
  211. $json = json_decode($result['content'], true);
  212. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  213. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  214. return array(
  215. 'email' => $json['user']['email'],
  216. 'image' => $json['user']['thumb']
  217. );
  218. }
  219. }
  220. }else{
  221. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  222. }
  223. }else{
  224. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  225. }
  226. return false;
  227. }
  228. else :
  229. // Plex Auth Missing Dependancy
  230. function plugin_auth_plex_disabled() {
  231. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  232. }
  233. // Emby Connect Auth Missing Dependancy
  234. function plugin_auth_emby_connect_disabled() {
  235. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  236. }
  237. // Emby Both Auth Missing Dependancy
  238. function plugin_auth_emby_both_disabled() {
  239. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  240. }
  241. endif;
  242. // ==== Auth Plugins END ====
  243. // ==== General Class Definitions START ====
  244. $userLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  245. class setLanguage {
  246. private $language = null;
  247. private $langCode = null;
  248. function __construct($language = false) {
  249. // Default
  250. if (!$language) {
  251. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  252. }
  253. if (!file_exists("lang/{$language}.ini")) {
  254. $language = 'en';
  255. }
  256. $this->langCode = $language;
  257. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  258. if (file_exists("lang/{$language}.cust.ini")) {
  259. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  260. $this->language[$k] = $v;
  261. }
  262. }
  263. }
  264. public function getLang() {
  265. return $this->langCode;
  266. }
  267. public function translate($originalWord) {
  268. $getArg = func_num_args();
  269. if ($getArg > 1) {
  270. $allWords = func_get_args();
  271. array_shift($allWords);
  272. } else {
  273. $allWords = array();
  274. }
  275. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  276. if (!$translatedWord) {
  277. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  278. //echo "WHOA!!!!!!! $originalWord";
  279. }
  280. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  281. return vsprintf($translatedWord, $allWords);
  282. }
  283. }
  284. $language = new setLanguage;
  285. // ==== General Class Definitions END ====
  286. // Direct request to curl if it exists, otherwise handle if not HTTPS
  287. function post_router($url, $data, $headers = array(), $referer='') {
  288. if (function_exists('curl_version')) {
  289. return curl_post($url, $data, $headers, $referer);
  290. } else {
  291. return post_request($url, $data, $headers, $referer);
  292. }
  293. }
  294. if (function_exists('curl_version')) :
  295. // Curl Post
  296. function curl_post($url, $data, $headers = array(), $referer='') {
  297. // Initiate cURL
  298. $curlReq = curl_init($url);
  299. // As post request
  300. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  301. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  302. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  303. if(localURL($url)){
  304. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  305. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  306. }
  307. // Format Data
  308. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  309. case 'application/json':
  310. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  311. break;
  312. case 'application/x-www-form-urlencoded';
  313. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  314. break;
  315. default:
  316. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  317. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  318. }
  319. // Format Headers
  320. $cHeaders = array();
  321. foreach ($headers as $k => $v) {
  322. $cHeaders[] = $k.': '.$v;
  323. }
  324. if (count($cHeaders)) {
  325. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  326. }
  327. // Execute
  328. $result = curl_exec($curlReq);
  329. $httpcode = curl_getinfo($curlReq);
  330. // Close
  331. curl_close($curlReq);
  332. // Return
  333. return array('content'=>$result, 'http_code'=>$httpcode);
  334. }
  335. //Curl Get Function
  336. function curl_get($url, $headers = array()) {
  337. // Initiate cURL
  338. $curlReq = curl_init($url);
  339. // As post request
  340. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  341. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  342. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  343. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  344. if(localURL($url)){
  345. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  346. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  347. }
  348. // Format Headers
  349. $cHeaders = array();
  350. foreach ($headers as $k => $v) {
  351. $cHeaders[] = $k.': '.$v;
  352. }
  353. if (count($cHeaders)) {
  354. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  355. }
  356. // Execute
  357. $result = curl_exec($curlReq);
  358. // Close
  359. curl_close($curlReq);
  360. // Return
  361. return $result;
  362. }
  363. //Curl Delete Function
  364. function curl_delete($url, $headers = array()) {
  365. // Initiate cURL
  366. $curlReq = curl_init($url);
  367. // As post request
  368. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  369. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  370. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  371. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  372. if(localURL($url)){
  373. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  374. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  375. }
  376. // Format Headers
  377. $cHeaders = array();
  378. foreach ($headers as $k => $v) {
  379. $cHeaders[] = $k.': '.$v;
  380. }
  381. if (count($cHeaders)) {
  382. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  383. }
  384. // Execute
  385. $result = curl_exec($curlReq);
  386. $httpcode = curl_getinfo($curlReq);
  387. // Close
  388. curl_close($curlReq);
  389. // Return
  390. return array('content'=>$result, 'http_code'=>$httpcode);
  391. }
  392. endif;
  393. //Case-Insensitive Function
  394. function in_arrayi($needle, $haystack) {
  395. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  396. }
  397. // HTTP post request (Removes need for curl, probably useless)
  398. function post_request($url, $data, $headers = array(), $referer='') {
  399. // Adapted from http://stackoverflow.com/a/28387011/6810513
  400. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  401. if (isset($headers['Content-Type'])) {
  402. switch ($headers['Content-Type']) {
  403. case 'application/json':
  404. $data = json_encode($data);
  405. break;
  406. case 'application/x-www-form-urlencoded':
  407. $data = http_build_query($data);
  408. break;
  409. }
  410. } else {
  411. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  412. $data = http_build_query($data);
  413. }
  414. // parse the given URL
  415. $urlDigest = parse_url($url);
  416. // extract host and path:
  417. $host = $urlDigest['host'];
  418. $path = $urlDigest['path'];
  419. if ($urlDigest['scheme'] != 'http') {
  420. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  421. }
  422. // open a socket connection on port 80 - timeout: 30 sec
  423. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  424. if ($fp){
  425. // send the request headers:
  426. fputs($fp, "POST $path HTTP/1.1\r\n");
  427. fputs($fp, "Host: $host\r\n");
  428. if ($referer != '')
  429. fputs($fp, "Referer: $referer\r\n");
  430. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  431. foreach($headers as $k => $v) {
  432. fputs($fp, $k.": ".$v."\r\n");
  433. }
  434. fputs($fp, "Connection: close\r\n\r\n");
  435. fputs($fp, $data);
  436. $result = '';
  437. while(!feof($fp)) {
  438. // receive the results of the request
  439. $result .= fgets($fp, 128);
  440. }
  441. }
  442. else {
  443. return array(
  444. 'status' => 'err',
  445. 'error' => "$errstr ($errno)"
  446. );
  447. }
  448. // close the socket connection:
  449. fclose($fp);
  450. // split the result header from the content
  451. $result = explode("\r\n\r\n", $result, 2);
  452. $header = isset($result[0]) ? $result[0] : '';
  453. $content = isset($result[1]) ? $result[1] : '';
  454. // return as structured array:
  455. return array(
  456. 'status' => 'ok',
  457. 'header' => $header,
  458. 'content' => $content,
  459. );
  460. }
  461. // Format item from Emby for Carousel
  462. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  463. // Static Height
  464. $height = 444;
  465. // Get Item Details
  466. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  467. /*if (substr_count(EMBYURL, ':') == 2) {
  468. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  469. }else{
  470. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  471. }*/
  472. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  473. switch ($itemDetails['Type']) {
  474. case 'Episode':
  475. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  476. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  477. $width = 300;
  478. $style = '';
  479. $image = 'slick-image-tall';
  480. if(!$nowPlaying){
  481. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  482. $key = $itemDetails['Id'] . "-list";
  483. }else{
  484. $height = 281;
  485. $width = 500;
  486. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  487. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  488. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  489. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  490. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  491. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  492. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  493. $stream = $moreInfo['PlayState']['PlayMethod'];
  494. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  495. $id = $moreInfo['DeviceId'];
  496. $streamInfo = buildStream(array(
  497. 'platform' => (string) $moreInfo['Client'],
  498. 'device' => (string) $moreInfo['DeviceName'],
  499. 'stream' => streamType($stream),
  500. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  501. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  502. ));
  503. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  504. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  505. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  506. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  507. }
  508. break;
  509. case 'MusicAlbum':
  510. case 'Audio':
  511. $title = $itemDetails['Name'];
  512. $imageId = $itemDetails['Id'];
  513. $width = 444;
  514. $style = '';
  515. $image = 'slick-image-short';
  516. if(!$nowPlaying){
  517. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  518. $key = $itemDetails['Id'] . "-list";
  519. }else{
  520. $height = 281;
  521. $width = 500;
  522. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  523. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  524. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  525. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  526. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  527. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  528. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  529. $stream = $moreInfo['PlayState']['PlayMethod'];
  530. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  531. $id = $moreInfo['DeviceId'];
  532. $streamInfo = buildStream(array(
  533. 'platform' => (string) $moreInfo['Client'],
  534. 'device' => (string) $moreInfo['DeviceName'],
  535. 'stream' => streamType($stream),
  536. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  537. ));
  538. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  539. $topTitle = '<h5 class="text-center zero-m elip">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  540. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  541. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  542. }
  543. break;
  544. case 'TvChannel':
  545. $title = $itemDetails['CurrentProgram']['Name'];
  546. $imageId = $itemDetails['Id'];
  547. $width = 300;
  548. $style = '';
  549. $image = 'slick-image-tall';
  550. if(!$nowPlaying){
  551. $imageType = "Primary";
  552. $key = $itemDetails['Id'] . "-list";
  553. }else{
  554. $height = 281;
  555. $width = 500;
  556. $imageType = "Thumb";
  557. $key = $itemDetails['Id'] . "-np";
  558. $useImage = "images/livetv.png";
  559. $watched = "0";
  560. $stream = $moreInfo['PlayState']['PlayMethod'];
  561. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  562. $id = $moreInfo['DeviceId'];
  563. $streamInfo = buildStream(array(
  564. 'platform' => (string) $moreInfo['Client'],
  565. 'device' => (string) $moreInfo['DeviceName'],
  566. 'stream' => streamType($stream),
  567. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  568. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  569. ));
  570. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  571. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  572. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  573. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  574. }
  575. break;
  576. default:
  577. $title = $itemDetails['Name'];
  578. $imageId = $itemDetails['Id'];
  579. $width = 300;
  580. $style = '';
  581. $image = 'slick-image-tall';
  582. if(!$nowPlaying){
  583. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  584. $key = $itemDetails['Id'] . "-list";
  585. }else{
  586. $height = 281;
  587. $width = 500;
  588. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  589. $key = $itemDetails['Id'] . "-np";
  590. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  591. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  592. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  593. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  594. $stream = $moreInfo['PlayState']['PlayMethod'];
  595. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  596. $id = $moreInfo['DeviceId'];
  597. $streamInfo = buildStream(array(
  598. 'platform' => (string) $moreInfo['Client'],
  599. 'device' => (string) $moreInfo['DeviceName'],
  600. 'stream' => streamType($stream),
  601. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  602. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  603. ));
  604. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  605. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  606. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  607. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  608. }
  609. }
  610. // If No Overview
  611. if (!isset($itemDetails['Overview'])) {
  612. $itemDetails['Overview'] = '';
  613. }
  614. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  615. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  616. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  617. }
  618. if($nowPlaying){
  619. if(!$imageType){ $image_url = "images/no-np.png"; $key = "no-np"; }
  620. if(!$imageId){ $image_url = "images/no-np.png"; $key = "no-np"; }
  621. }else{
  622. if(!$imageType){ $image_url = "images/no-list.png"; $key = "no-list"; }
  623. if(!$imageId){ $image_url = "images/no-list.png"; $key = "no-list"; }
  624. }
  625. if(isset($useImage)){ $image_url = $useImage; }
  626. // Assemble Item And Cache Into Array
  627. if($nowPlaying){
  628. //prettyPrint($itemDetails);
  629. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$URL.'" target="_blank"><img style="width: 100%; display:inherit;" src="'.$image_url.'" alt="'.$itemDetails['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: 0%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  630. }else{
  631. return '<div class="item-'.$itemDetails['Type'].'"><a href="'.$URL.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
  632. }
  633. }
  634. // Format item from Plex for Carousel
  635. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  636. // Static Height
  637. $height = 444;
  638. $widthOverride = 100;
  639. $playlist = ($playlist) ? " playlist-$playlist" : "";
  640. switch ($item['type']) {
  641. case 'season':
  642. $title = $item['parentTitle'];
  643. $summary = $item['parentSummary'];
  644. $width = 300;
  645. $image = 'slick-image-tall';
  646. $style = '';
  647. if(!$nowPlaying){
  648. $thumb = $item['thumb'];
  649. $key = $item['ratingKey'] . "-list";
  650. }else {
  651. $height = 281;
  652. $width = 500;
  653. $thumb = $item['art'];
  654. $key = $item['ratingKey'] . "-np";
  655. $elapsed = $item['viewOffset'];
  656. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  657. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  658. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  659. $stream = $item->Media->Part->Stream['decision'];
  660. $user = $role == "admin" ? $item->User['title'] : "";
  661. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  662. $streamInfo = buildStream(array(
  663. 'platform' => (string) $item->Player['platform'],
  664. 'device' => (string) $item->Player['device'],
  665. 'stream' => streamType($item->Media->Part['decision']),
  666. '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'].")",
  667. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  668. ));
  669. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  670. }
  671. break;
  672. case 'episode':
  673. $title = $item['grandparentTitle'];
  674. $summary = $item['title'];
  675. $width = 300;
  676. $image = 'slick-image-tall';
  677. $style = '';
  678. if(!$nowPlaying){
  679. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  680. $key = $item['ratingKey'] . "-list";
  681. }else {
  682. $height = 281;
  683. $width = 500;
  684. $thumb = $item['art'];
  685. $key = $item['ratingKey'] . "-np";
  686. $elapsed = $item['viewOffset'];
  687. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  688. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  689. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  690. $stream = $item->Media->Part->Stream['decision'];
  691. $user = $role == "admin" ? $item->User['title'] : "";
  692. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  693. $streamInfo = buildStream(array(
  694. 'platform' => (string) $item->Player['platform'],
  695. 'device' => (string) $item->Player['device'],
  696. 'stream' => streamType($item->Media->Part['decision']),
  697. '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'].")",
  698. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  699. ));
  700. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  701. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  702. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  703. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  704. }
  705. break;
  706. case 'clip':
  707. $title = $item['title'];
  708. $summary = $item['summary'];
  709. $width = 300;
  710. $image = 'slick-image-tall';
  711. $style = '';
  712. if(!$nowPlaying){
  713. $thumb = $item['thumb'];
  714. $key = $item['ratingKey'] . "-list";
  715. }else {
  716. $height = 281;
  717. $width = 500;
  718. $thumb = $item['art'];
  719. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  720. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  721. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  722. $elapsed = $item['viewOffset'];
  723. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  724. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  725. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  726. $stream = $item->Media->Part->Stream['decision'];
  727. $user = $role == "admin" ? $item->User['title'] : "";
  728. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  729. $streamInfo = buildStream(array(
  730. 'platform' => (string) $item->Player['platform'],
  731. 'device' => (string) $item->Player['device'],
  732. 'stream' => streamType($item->Media->Part['decision']),
  733. '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'].")",
  734. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  735. ));
  736. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  737. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  738. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  739. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  740. }
  741. break;
  742. case 'album':
  743. case 'track':
  744. $title = $item['parentTitle'];
  745. $summary = $item['title'];
  746. $image = 'slick-image-short';
  747. $style = 'left: 160px !important;';
  748. $item['ratingKey'] = $item['parentRatingKey'];
  749. if(!$nowPlaying){
  750. $width = 444;
  751. $thumb = $item['thumb'];
  752. $key = $item['ratingKey'] . "-list";
  753. }else {
  754. $height = 281;
  755. $width = 500;
  756. $thumb = ($item['art']) ? $item['art'] : $item['parentThumb'];
  757. $widthOverride = ($item['art']) ? 100 : 56;
  758. $key = $item['ratingKey'] . "-np";
  759. $elapsed = $item['viewOffset'];
  760. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  761. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  762. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  763. $stream = $item->Media->Part->Stream['decision'];
  764. $user = $role == "admin" ? $item->User['title'] : "";
  765. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  766. $streamInfo = buildStream(array(
  767. 'platform' => (string) $item->Player['platform'],
  768. 'device' => (string) $item->Player['device'],
  769. 'stream' => streamType($item->Media->Part['decision']),
  770. 'audio' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  771. ));
  772. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  773. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  774. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  775. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  776. }
  777. break;
  778. default:
  779. $title = $item['title'];
  780. $summary = $item['summary'];
  781. $image = 'slick-image-tall';
  782. $style = '';
  783. if(!$nowPlaying){
  784. $width = 300;
  785. $thumb = $item['thumb'];
  786. $key = $item['ratingKey'] . "-list";
  787. }else {
  788. $height = 281;
  789. $width = 500;
  790. $thumb = $item['art'];
  791. $key = $item['ratingKey'] . "-np";
  792. $elapsed = $item['viewOffset'];
  793. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  794. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  795. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  796. $stream = $item->Media->Part->Stream['decision'];
  797. $user = $role == "admin" ? $item->User['title'] : "";
  798. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  799. $streamInfo = buildStream(array(
  800. 'platform' => (string) $item->Player['platform'],
  801. 'device' => (string) $item->Player['device'],
  802. 'stream' => streamType($item->Media->Part['decision']),
  803. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  804. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  805. ));
  806. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  807. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  808. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  809. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  810. }
  811. }
  812. if (substr_count(PLEXURL, '.') != 2) {
  813. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  814. }else{
  815. $address = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  816. }
  817. // If No Overview
  818. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  819. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  820. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  821. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  822. }
  823. if($nowPlaying){
  824. if(!$thumb){ $image_url = "images/no-np.png"; $key = "no-np"; }
  825. }else{
  826. if(!$thumb){ $image_url = "images/no-list.png"; $key = "no-list"; }
  827. }
  828. if(isset($useImage)){ $image_url = $useImage; }
  829. $openTab = (PLEXTABNAME) ? "true" : "false";
  830. // Assemble Item And Cache Into Array
  831. if($nowPlaying){
  832. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img style="width: '.$widthOverride.'%; display:block;" src="'.$image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  833. }else{
  834. return '<div class="item-'.$item['type'].$playlist.'"><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
  835. }
  836. }
  837. //$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  838. //Recent Added
  839. function outputRecentAdded($header, $items, $script = false, $array) {
  840. $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">';
  841. if(preg_grep("/item-movie/", $items)){
  842. $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>';
  843. }
  844. if(preg_grep("/item-season/", $items)){
  845. $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>';
  846. }
  847. if(preg_grep("/item-album/", $items)){
  848. $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>';
  849. }
  850. $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>';
  851. $hideMenu .= '</ul></div></div>';
  852. // If None Populate Empty Item
  853. if (!count($items)) {
  854. return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Media Found</p></div>';
  855. }else{
  856. $className = str_replace(' ', '', $header);
  857. return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 id="recentContent-title" style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-recent" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  858. }
  859. }
  860. // Create Carousel
  861. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  862. // If None Populate Empty Item
  863. if (!count($items)) {
  864. return '<div id=streamz></div>'.($script?'<script>'.$script.'</script>':'');
  865. }else{
  866. return '<div id=streamz><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  867. }
  868. }
  869. // Get Now Playing Streams From Emby
  870. function getEmbyStreams($size, $showNames, $role) {
  871. $address = qualifyURL(EMBYURL);
  872. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  873. if (!is_array($api)) { return 'Could not load!'; }
  874. $playingItems = array();
  875. foreach($api as $key => $value) {
  876. if (isset($value['NowPlayingItem'])) {
  877. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  878. }
  879. }
  880. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY'), $size, 'streams-emby', $playingItems, "
  881. setInterval(function() {
  882. $('<div></div>').load('ajax.php?a=emby-streams',function() {
  883. var element = $(this).find('[id]');
  884. var loadedID = element.attr('id');
  885. $('#'+loadedID).replaceWith(element);
  886. console.log('Loaded updated: '+loadedID);
  887. });
  888. }, 15000);
  889. ");
  890. }
  891. // Get Now Playing Streams From Plex
  892. function getPlexStreams($size, $showNames, $role){
  893. $address = qualifyURL(PLEXURL);
  894. // Perform API requests
  895. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  896. libxml_use_internal_errors(true);
  897. $api = simplexml_load_string($api);
  898. if (is_array($api) || is_object($api)){
  899. if (!$api->head->title){
  900. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  901. if (!$getServer) { return 'Could not load!'; }
  902. // Identify the local machine
  903. $gotServer = $getServer['machineIdentifier'];
  904. $items = array();
  905. foreach($api AS $child) {
  906. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  907. }
  908. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, "
  909. setInterval(function() {
  910. $('<div></div>').load('ajax.php?a=plex-streams',function() {
  911. var element = $(this).find('[id]');
  912. var loadedID = element.attr('id');
  913. $('#'+loadedID).replaceWith(element);
  914. console.log('Loaded updated: '+loadedID);
  915. });
  916. }, 15000);
  917. ");
  918. }else{
  919. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  920. }
  921. }else{
  922. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  923. }
  924. }
  925. // Get Recent Content From Emby
  926. function getEmbyRecent($array) {
  927. $address = qualifyURL(EMBYURL);
  928. $header = translate('RECENT_CONTENT');
  929. // Currently Logged In User
  930. $username = false;
  931. if (isset($GLOBALS['USER'])) {
  932. $username = strtolower($GLOBALS['USER']->username);
  933. }
  934. // Get A User
  935. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  936. if (!is_array($userIds)) { return 'Could not load!'; }
  937. $showPlayed = true;
  938. foreach ($userIds as $value) { // Scan for admin user
  939. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  940. $userId = $value['Id'];
  941. }
  942. if ($username && strtolower($value['Name']) == $username) {
  943. $userId = $value['Id'];
  944. $showPlayed = false;
  945. break;
  946. }
  947. }
  948. // Get the latest Items
  949. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  950. // For Each Item In Category
  951. $items = array();
  952. foreach ($latest as $k => $v) {
  953. $type = (string) $v['Type'];
  954. if(@$array[$type] == "true"){
  955. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  956. }
  957. }
  958. $array["movie"] = $array["Movie"];
  959. $array["season"] = $array["Episode"];
  960. $array["album"] = $array["MusicAlbum"];
  961. unset($array["Movie"]);
  962. unset($array["Episode"]);
  963. unset($array["MusicAlbum"]);
  964. unset($array["Series"]);
  965. return outputRecentAdded($header, $items, "
  966. setInterval(function() {
  967. $('<div></div>').load('ajax.php?a=emby-recent',function() {
  968. var element = $(this).find('#recentMedia');
  969. var loadedID = element.attr('id');
  970. $('#recentMedia').replaceWith(element);
  971. console.log('Loaded recent: '+loadedID);
  972. loadSlick();
  973. });
  974. }, 600000);
  975. ", $array);
  976. }
  977. // Get Recent Content From Plex
  978. function getPlexRecent($array){
  979. $address = qualifyURL(PLEXURL);
  980. $header = translate('RECENT_CONTENT');
  981. // Perform Requests
  982. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  983. libxml_use_internal_errors(true);
  984. $api = simplexml_load_string($api);
  985. if (is_array($api) || is_object($api)){
  986. if (!$api->head->title){
  987. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  988. if (!$getServer) { return 'Could not load!'; }
  989. // Identify the local machine
  990. $gotServer = $getServer['machineIdentifier'];
  991. $items = array();
  992. foreach($api AS $child) {
  993. $type = (string) $child['type'];
  994. if($array[$type] == "true"){
  995. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  996. }
  997. }
  998. return outputRecentAdded($header, $items, "
  999. setInterval(function() {
  1000. $('<div></div>').load('ajax.php?a=plex-recent',function() {
  1001. var element = $(this).find('#recentMedia');
  1002. var loadedID = element.attr('id');
  1003. $('#recentMedia').replaceWith(element);
  1004. console.log('Loaded recent: '+loadedID);
  1005. loadSlick();
  1006. });
  1007. }, 600000);
  1008. ", $array);
  1009. }else{
  1010. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  1011. }
  1012. }else{
  1013. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1014. }
  1015. }
  1016. // Get Image From Emby
  1017. function getEmbyImage() {
  1018. $embyAddress = qualifyURL(EMBYURL);
  1019. if (!file_exists('images/cache')) {
  1020. mkdir('images/cache', 0777, true);
  1021. }
  1022. $itemId = $_GET['img'];
  1023. $key = $_GET['key'];
  1024. $itemType = $_GET['type'];
  1025. $imgParams = array();
  1026. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  1027. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  1028. if(isset($itemId)) {
  1029. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  1030. $cachefile = 'images/cache/'.$key.'.jpg';
  1031. $cachetime = 604800;
  1032. // Serve from the cache if it is younger than $cachetime
  1033. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  1034. header("Content-type: image/jpeg");
  1035. @readfile($cachefile);
  1036. exit;
  1037. }
  1038. ob_start(); // Start the output buffer
  1039. header('Content-type: image/jpeg');
  1040. @readfile($image_src);
  1041. // Cache the output to a file
  1042. $fp = fopen($cachefile, 'wb');
  1043. fwrite($fp, ob_get_contents());
  1044. fclose($fp);
  1045. ob_end_flush(); // Send the output to the browser
  1046. die();
  1047. } else {
  1048. debug_out('Invalid Request',1);
  1049. }
  1050. }
  1051. // Get Image From Plex
  1052. function getPlexImage() {
  1053. $plexAddress = qualifyURL(PLEXURL);
  1054. if (!file_exists('images/cache')) {
  1055. mkdir('images/cache', 0777, true);
  1056. }
  1057. $image_url = $_GET['img'];
  1058. $key = $_GET['key'];
  1059. $image_height = $_GET['height'];
  1060. $image_width = $_GET['width'];
  1061. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1062. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1063. $cachefile = 'images/cache/'.$key.'.jpg';
  1064. $cachetime = 604800;
  1065. // Serve from the cache if it is younger than $cachetime
  1066. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  1067. header("Content-type: image/jpeg");
  1068. @readfile($cachefile);
  1069. exit;
  1070. }
  1071. ob_start(); // Start the output buffer
  1072. header('Content-type: image/jpeg');
  1073. @readfile($image_src);
  1074. // Cache the output to a file
  1075. $fp = fopen($cachefile, 'wb');
  1076. fwrite($fp, ob_get_contents());
  1077. fclose($fp);
  1078. ob_end_flush(); // Send the output to the browser
  1079. die();
  1080. } else {
  1081. echo "Invalid Plex Request";
  1082. }
  1083. }
  1084. // Simplier access to class
  1085. function translate($string) {
  1086. if (isset($GLOBALS['language'])) {
  1087. return $GLOBALS['language']->translate($string);
  1088. } else {
  1089. return '!Translations Not Loaded!';
  1090. }
  1091. }
  1092. // Generate Random string
  1093. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1094. $tmp = '';
  1095. for ($i = 0; $i < $length; $i++) {
  1096. $tmp .= substr(str_shuffle($chars), 0, 1);
  1097. }
  1098. return $tmp;
  1099. }
  1100. // Create config file in the return syntax
  1101. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1102. // Define Initial Value
  1103. $output = array();
  1104. // Sort Items
  1105. ksort($array);
  1106. // Update the current config version
  1107. if (!$nest) {
  1108. // Inject Current Version
  1109. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1110. }
  1111. unset($array['CONFIG_VERSION']);
  1112. unset($array['apply_CONFIG_VERSION']);
  1113. // Process Settings
  1114. foreach ($array as $k => $v) {
  1115. $allowCommit = true;
  1116. switch (gettype($v)) {
  1117. case 'boolean':
  1118. $item = ($v?'true':'false');
  1119. break;
  1120. case 'integer':
  1121. case 'double':
  1122. case 'integer':
  1123. case 'NULL':
  1124. $item = $v;
  1125. break;
  1126. case 'string':
  1127. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1128. break;
  1129. case 'array':
  1130. $item = createConfig($v, false, $nest+1);
  1131. break;
  1132. default:
  1133. $allowCommit = false;
  1134. }
  1135. if($allowCommit) {
  1136. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1137. }
  1138. }
  1139. // Build output
  1140. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1141. if (!$nest && $path) {
  1142. $pathDigest = pathinfo($path);
  1143. @mkdir($pathDigest['dirname'], 0770, true);
  1144. if (file_exists($path)) {
  1145. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1146. }
  1147. $file = fopen($path, 'w');
  1148. fwrite($file, $output);
  1149. fclose($file);
  1150. if (file_exists($path)) {
  1151. return true;
  1152. }
  1153. writeLog("error", "config was unable to write");
  1154. return false;
  1155. } else {
  1156. writeLog("success", "config was updated with new values");
  1157. return $output;
  1158. }
  1159. }
  1160. // Load a config file written in the return syntax
  1161. function loadConfig($path = 'config/config.php') {
  1162. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1163. if (!is_file($path)) {
  1164. return null;
  1165. } else {
  1166. return (array) call_user_func(function() use($path) {
  1167. return include($path);
  1168. });
  1169. }
  1170. }
  1171. // Commit new values to the configuration
  1172. function updateConfig($new, $current = false) {
  1173. // Get config if not supplied
  1174. if ($current === false) {
  1175. $current = loadConfig();
  1176. } else if (is_string($current) && is_file($current)) {
  1177. $current = loadConfig($current);
  1178. }
  1179. // Inject Parts
  1180. foreach ($new as $k => $v) {
  1181. $current[$k] = $v;
  1182. }
  1183. // Return Create
  1184. return createConfig($current);
  1185. }
  1186. // Inject Defaults As Needed
  1187. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1188. if (is_string($path)) {
  1189. $loadedDefaults = loadConfig($path);
  1190. } else {
  1191. $loadedDefaults = $path;
  1192. }
  1193. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1194. }
  1195. // support function for fillDefaultConfig()
  1196. function fillDefaultConfig_recurse($current, $defaults) {
  1197. foreach($defaults as $k => $v) {
  1198. if (!isset($current[$k])) {
  1199. $current[$k] = $v;
  1200. } else if (is_array($current[$k]) && is_array($v)) {
  1201. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1202. }
  1203. }
  1204. return $current;
  1205. };
  1206. // Define Scalar Variables (nest non-secular with underscores)
  1207. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1208. foreach($array as $k => $v) {
  1209. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1210. define($nest_prefix.$k, $v, $anyCase);
  1211. } else if (is_array($v)) {
  1212. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1213. }
  1214. }
  1215. }
  1216. // This function exists only because I am lazy
  1217. function configLazy($path = 'config/config.php') {
  1218. // Load config or default
  1219. if (file_exists($path)) {
  1220. $config = fillDefaultConfig(loadConfig($path));
  1221. } else {
  1222. $config = loadConfig('config/configDefaults.php');
  1223. }
  1224. if (is_array($config)) {
  1225. defineConfig($config);
  1226. }
  1227. return $config;
  1228. }
  1229. // Qualify URL
  1230. function qualifyURL($url) {
  1231. //local address?
  1232. if(substr($url, 0,1) == "/"){
  1233. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1234. $protocol = "https://";
  1235. } else {
  1236. $protocol = "http://";
  1237. }
  1238. $url = $protocol.getServer().$url;
  1239. }
  1240. // Get Digest
  1241. $digest = parse_url($url);
  1242. // http/https
  1243. if (!isset($digest['scheme'])) {
  1244. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1245. $scheme = 'http';
  1246. } else {
  1247. $scheme = 'https';
  1248. }
  1249. } else {
  1250. $scheme = $digest['scheme'];
  1251. }
  1252. // Host
  1253. $host = (isset($digest['host'])?$digest['host']:'');
  1254. // Port
  1255. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1256. // Path
  1257. $path = (isset($digest['path'])?$digest['path']:'');
  1258. // Output
  1259. return $scheme.'://'.$host.$port.$path;
  1260. }
  1261. // Function to be called at top of each to allow upgrading environment as the spec changes
  1262. function upgradeCheck() {
  1263. // Upgrade to 1.31
  1264. if (file_exists('homepageSettings.ini.php')) {
  1265. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1266. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1267. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1268. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1269. foreach($databaseConfig as $k => $v) {
  1270. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1271. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1272. }
  1273. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1274. unlink('homepageSettings.ini.php');
  1275. unset($databaseData);
  1276. unset($homepageConfig);
  1277. }
  1278. // Upgrade to 1.32
  1279. if (file_exists('databaseLocation.ini.php')) {
  1280. // Load Existing
  1281. $config = parse_ini_file('databaseLocation.ini.php', true);
  1282. // Refactor
  1283. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1284. $config['user_home'] = $config['database_Location'].'users/';
  1285. unset($config['databaseLocation']);
  1286. // Turn Off Emby And Plex Recent
  1287. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1288. unset($config["embyPort"]);
  1289. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1290. unset($config["plexPort"]);
  1291. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1292. unset($config["nzbgetPort"]);
  1293. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1294. unset($config["sabnzbdPort"]);
  1295. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1296. unset($config["headphonesPort"]);
  1297. // Write config file
  1298. $config['CONFIG_VERSION'] = '1.32';
  1299. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1300. $createConfigSuccess = createConfig($config);
  1301. // Create new config
  1302. if ($createConfigSuccess) {
  1303. if (file_exists('config/config.php')) {
  1304. // Remove Old ini file
  1305. unlink('databaseLocation.ini.php');
  1306. } else {
  1307. debug_out('Something is not right here!');
  1308. }
  1309. } else {
  1310. debug_out('Couldn\'t create updated configuration.' ,1);
  1311. }
  1312. }
  1313. // Upgrade to 1.33
  1314. $config = loadConfig();
  1315. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1316. // Fix User Directory
  1317. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1318. $config['user_home'] = $config['database_Location'].'users/';
  1319. unset($config['USER_HOME']);
  1320. // Backend auth merge
  1321. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1322. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1323. }
  1324. unset($config['authBackendPort']);
  1325. // If auth is being used move it to embyURL as that is now used in auth functions
  1326. 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')))) {
  1327. $config['embyURL'] = $config['authBackendHost'];
  1328. }
  1329. // Upgrade database to latest version
  1330. updateSQLiteDB($config['database_Location'],'1.32');
  1331. // Update Version and Commit
  1332. $config['apply_CONFIG_VERSION'] = '1.33';
  1333. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1334. $createConfigSuccess = createConfig($config);
  1335. unset($config);
  1336. }
  1337. // Upgrade to 1.34
  1338. $config = loadConfig();
  1339. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1340. // Upgrade database to latest version
  1341. updateSQLiteDB($config['database_Location'],'1.33');
  1342. // Update Version and Commit
  1343. $config['CONFIG_VERSION'] = '1.34';
  1344. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1345. $createConfigSuccess = createConfig($config);
  1346. unset($config);
  1347. }
  1348. // Upgrade to 1.40
  1349. $config = loadConfig();
  1350. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1351. // Upgrade database to latest version
  1352. updateSQLiteDB($config['database_Location'],'1.38');
  1353. // Update Version and Commit
  1354. $config['CONFIG_VERSION'] = '1.40';
  1355. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1356. $createConfigSuccess = createConfig($config);
  1357. unset($config);
  1358. }
  1359. // Upgrade to 1.50
  1360. $config = loadConfig();
  1361. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.50')) {
  1362. // Upgrade database to latest version
  1363. updateSQLiteDB($config['database_Location'],'1.40');
  1364. // Update Version and Commit
  1365. $config['CONFIG_VERSION'] = '1.50';
  1366. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.40].bak.php');
  1367. $createConfigSuccess = createConfig($config);
  1368. unset($config);
  1369. }
  1370. return true;
  1371. }
  1372. // Get OS from server
  1373. function getOS(){
  1374. if(PHP_SHLIB_SUFFIX == "dll"){
  1375. return "win";
  1376. }else{
  1377. return "nix";
  1378. }
  1379. }
  1380. //Get Error by Server OS
  1381. function getError($os, $error){
  1382. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1383. $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'");
  1384. $errors = array(
  1385. 'pdo_sqlite' => array(
  1386. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1387. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1388. ),
  1389. 'sqlite3' => array(
  1390. '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',
  1391. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1392. ),
  1393. 'curl' => array(
  1394. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1395. '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',
  1396. ),
  1397. 'zip' => array(
  1398. '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',
  1399. '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',
  1400. ),
  1401. );
  1402. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1403. }
  1404. // Check if all software dependancies are met
  1405. function dependCheck() {
  1406. $output = array();
  1407. $i = 1;
  1408. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1409. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1410. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1411. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1412. if ($output) {
  1413. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1414. $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++;
  1415. debug_out($output,1);
  1416. }
  1417. return true;
  1418. }
  1419. // Process file uploads
  1420. function uploadFiles($path, $ext_mask = null) {
  1421. if (isset($_FILES) && count($_FILES)) {
  1422. require_once('class.uploader.php');
  1423. $uploader = new Uploader();
  1424. $data = $uploader->upload($_FILES['files'], array(
  1425. 'limit' => 10,
  1426. 'maxSize' => 10,
  1427. 'extensions' => $ext_mask,
  1428. 'required' => false,
  1429. 'uploadDir' => str_replace('//','/',$path.'/'),
  1430. 'title' => array('name'),
  1431. 'removeFiles' => true,
  1432. 'replace' => true,
  1433. ));
  1434. if($data['isComplete']){
  1435. $files = $data['data'];
  1436. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1437. echo json_encode($files['metas'][0]['name']);
  1438. }
  1439. if($data['hasErrors']){
  1440. $errors = $data['errors'];
  1441. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1442. echo json_encode($errors);
  1443. }
  1444. } else {
  1445. writeLog("error", "image was not uploaded");
  1446. echo json_encode('No files submitted!');
  1447. }
  1448. }
  1449. // Process file uploads
  1450. function uploadAvatar($path, $ext_mask = null) {
  1451. if (isset($_FILES) && count($_FILES)) {
  1452. require_once('class.uploader.php');
  1453. $uploader = new Uploader();
  1454. $data = $uploader->upload($_FILES['files'], array(
  1455. 'limit' => 10,
  1456. 'maxSize' => 10,
  1457. 'extensions' => $ext_mask,
  1458. 'required' => false,
  1459. 'uploadDir' => str_replace('//','/',$path.'/'),
  1460. 'title' => array('name'),
  1461. 'removeFiles' => true,
  1462. 'replace' => true,
  1463. ));
  1464. if($data['isComplete']){
  1465. $files = $data['data'];
  1466. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1467. echo json_encode($files['metas'][0]['name']);
  1468. }
  1469. if($data['hasErrors']){
  1470. $errors = $data['errors'];
  1471. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1472. echo json_encode($errors);
  1473. }
  1474. } else {
  1475. writeLog("error", "image was not uploaded");
  1476. echo json_encode('No files submitted!');
  1477. }
  1478. }
  1479. // Remove file
  1480. function removeFiles($path) {
  1481. if(is_file($path)) {
  1482. writeLog("success", "image was removed");
  1483. unlink($path);
  1484. } else {
  1485. writeLog("error", "image was not removed");
  1486. echo json_encode('No file specified for removal!');
  1487. }
  1488. }
  1489. // Lazy select options
  1490. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1491. $output = array();
  1492. $selectedArr = ($multi?explode('|', $selected):array());
  1493. foreach ($array as $key => $value) {
  1494. if (is_array($value)) {
  1495. if (isset($value['optgroup'])) {
  1496. $output[] = '<optgroup label="'.$key.'">';
  1497. foreach($value['optgroup'] as $k => $v) {
  1498. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1499. }
  1500. } else {
  1501. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1502. }
  1503. } else {
  1504. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1505. }
  1506. }
  1507. return implode('',$output);
  1508. }
  1509. // Check if user is allowed to continue
  1510. function qualifyUser($type, $errOnFail = false) {
  1511. if (!isset($GLOBALS['USER'])) {
  1512. require_once("user.php");
  1513. $GLOBALS['USER'] = new User('registration_callback');
  1514. }
  1515. if (is_bool($type)) {
  1516. if ($type === true) {
  1517. $authorized = ($GLOBALS['USER']->authenticated == true);
  1518. } else {
  1519. $authorized = true;
  1520. }
  1521. } elseif (is_string($type) || is_array($type)) {
  1522. if ($type !== 'false') {
  1523. if (!is_array($type)) {
  1524. $type = explode('|',$type);
  1525. }
  1526. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1527. } else {
  1528. $authorized = true;
  1529. }
  1530. } else {
  1531. debug_out('Invalid Syntax!',1);
  1532. }
  1533. if (!$authorized && $errOnFail) {
  1534. if ($GLOBALS['USER']->authenticated) {
  1535. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401');
  1536. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401\'</script>';
  1537. } else {
  1538. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999');
  1539. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999\'</script>';
  1540. }
  1541. debug_out('Not Authorized' ,1);
  1542. } else {
  1543. return $authorized;
  1544. }
  1545. }
  1546. // Build an (optionally) tabbed settings page.
  1547. function buildSettings($array) {
  1548. /*
  1549. array(
  1550. 'title' => '',
  1551. 'id' => '',
  1552. 'fields' => array( See buildField() ),
  1553. 'tabs' => array(
  1554. array(
  1555. 'title' => '',
  1556. 'id' => '',
  1557. 'image' => '',
  1558. 'fields' => array( See buildField() ),
  1559. ),
  1560. ),
  1561. );
  1562. */
  1563. $notifyExplode = explode("-", NOTIFYEFFECT);
  1564. $fieldFunc = function($fieldArr) {
  1565. $fields = '<div class="row">';
  1566. foreach($fieldArr as $key => $value) {
  1567. $isSingle = isset($value['type']);
  1568. if ($isSingle) { $value = array($value); }
  1569. $tmpField = '';
  1570. $sizeLg = max(floor(12/count($value)),2);
  1571. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1572. foreach($value as $k => $v) {
  1573. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1574. }
  1575. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1576. }
  1577. $fields .= '</div>';
  1578. return $fields;
  1579. };
  1580. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1581. $tabSelectors = array();
  1582. $tabContent = array();
  1583. if (isset($array['tabs'])) {
  1584. foreach($array['tabs'] as $key => $value) {
  1585. $id = (isset($value['id'])?$value['id']:randString(32));
  1586. $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>';
  1587. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1588. }
  1589. }
  1590. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1591. $extraClick = ($pageID == 'appearance_settings' ? "$('#advanced_settings_form_submit').click();console.log('add theme settings');" : "");
  1592. return '
  1593. <div class="email-body">
  1594. <div class="email-header gray-bg">
  1595. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1596. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float save-btn-form">
  1597. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1598. </button>
  1599. <h1>'.$array['title'].'</h1>
  1600. </div>
  1601. <div class="email-inner small-box">
  1602. <div class="email-inner-section">
  1603. <div class="small-box fade in" id="'.$pageID.'_frame">
  1604. <div class="col-lg-12">
  1605. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1606. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1607. '.$fields.($tabContent?'
  1608. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1609. <ul class="nav nav-tabs apps">
  1610. '.implode('', $tabSelectors).'
  1611. </ul>
  1612. <div class="clearfix"></div>
  1613. <div class="tab-content">
  1614. '.implode('', $tabContent).'
  1615. </div>
  1616. </div>':'').'
  1617. </form>
  1618. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1619. </div>
  1620. </div>
  1621. </div>
  1622. </div>
  1623. </div>
  1624. <script>
  1625. $(document).ready(function() {
  1626. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1627. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1628. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1629. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1630. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1631. var newVals = {};
  1632. var hasVals = false;
  1633. var errorFields = [];
  1634. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1635. hasVals = true;
  1636. if (this.type == \'checkbox\') {
  1637. newVals[this.name] = this.checked;
  1638. } else if ($(this).hasClass(\'summernote\')) {
  1639. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1640. } else {
  1641. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1642. var fieldVal = $(this).val();
  1643. if (typeof fieldVal == \'object\') {
  1644. if (typeof fieldVal.join == \'function\') {
  1645. fieldVal = fieldVal.join(\'|\');
  1646. } else {
  1647. fieldVal = JSON.stringify(fieldVal);
  1648. }
  1649. }
  1650. newVals[this.name] = fieldVal;
  1651. }
  1652. });
  1653. if (errorFields.length) {
  1654. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1655. } else if (hasVals) {
  1656. console.log(newVals);
  1657. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1658. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1659. });
  1660. '.$extraClick.'
  1661. } else {
  1662. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1663. }
  1664. return false;
  1665. });
  1666. '.(isset($array['onready'])?$array['onready']:'').'
  1667. });
  1668. </script>
  1669. ';
  1670. }
  1671. // Build Settings Fields
  1672. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1673. /*
  1674. array(
  1675. 'type' => '',
  1676. 'placeholder' => '',
  1677. 'label' => '',
  1678. 'labelTranslate' => '',
  1679. 'assist' => '',
  1680. 'name' => '',
  1681. 'pattern' => '',
  1682. 'options' => array( // For SELECT only
  1683. 'Display' => 'value',
  1684. ),
  1685. )
  1686. */
  1687. // Tags
  1688. $tags = array();
  1689. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick') as $value) {
  1690. if (isset($params[$value])) {
  1691. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1692. } else if ($params[$value] === true) { $tags[] = $value; }
  1693. }
  1694. }
  1695. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1696. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1697. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1698. $val = (isset($params['value'])?$params['value']:'');
  1699. $class = (isset($params['class'])?' '.$params['class']:'');
  1700. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1701. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1702. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1703. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1704. // Field Design
  1705. switch ($params['type']) {
  1706. case 'text':
  1707. case 'number':
  1708. case 'password':
  1709. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1710. break;
  1711. case 'select':
  1712. case 'dropdown':
  1713. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1714. break;
  1715. case 'select-multi':
  1716. case 'dropdown-multi':
  1717. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1718. break;
  1719. case 'check':
  1720. case 'checkbox':
  1721. case 'toggle':
  1722. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1723. $colour = (isset($params['colour'])?$params['colour']:'success');
  1724. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1725. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1726. break;
  1727. case 'radio':
  1728. $labelOut = '';
  1729. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1730. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1731. $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>';
  1732. break;
  1733. case 'date':
  1734. $field = 'Unsupported, planned.';
  1735. break;
  1736. case 'hidden':
  1737. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1738. break;
  1739. case 'header':
  1740. $labelOut = '';
  1741. $headType = (isset($params['value'])?$params['value']:3);
  1742. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1743. break;
  1744. case 'button':
  1745. $labelOut = '';
  1746. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1747. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1748. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1749. $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>':'');
  1750. break;
  1751. case 'textarea':
  1752. $rows = (isset($params['rows'])?$params['rows']:5);
  1753. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1754. break;
  1755. case 'custom':
  1756. // Settings
  1757. $settings = array(
  1758. '$id' => $id,
  1759. '$name' => $name,
  1760. '$val' => $val,
  1761. '$label' => $label,
  1762. '$labelOut' => $labelOut,
  1763. );
  1764. // Get HTML
  1765. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1766. // If LabelOut is in html dont print it twice
  1767. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1768. // Replace variables in settings
  1769. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1770. // Build Field
  1771. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1772. break;
  1773. case 'space':
  1774. $labelOut = '';
  1775. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1776. break;
  1777. default:
  1778. $field = 'Unsupported field type';
  1779. break;
  1780. }
  1781. // Field Formats
  1782. switch ($format) {
  1783. case 'colour': // Fuckin Eh, Canada!
  1784. case 'color':
  1785. $labelBef = '<center>'.$label.'</center>';
  1786. $wrapClass = 'gray-bg colour-field';
  1787. $labelAft = '';
  1788. $field = str_replace(' material input-sm','',$field);
  1789. break;
  1790. default:
  1791. $labelBef = '';
  1792. $labelAft = $labelOut;
  1793. }
  1794. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1795. }
  1796. // Tab Settings Generation
  1797. function printTabRow($data) {
  1798. $hidden = false;
  1799. if ($data===false) {
  1800. $hidden = true;
  1801. $data = array( // New Tab Defaults
  1802. 'id' => 'new',
  1803. 'name' => '',
  1804. 'url' => '',
  1805. 'icon' => 'fa-diamond',
  1806. 'iconurl' => '',
  1807. 'active' => 'true',
  1808. 'user' => 'true',
  1809. 'guest' => 'true',
  1810. 'window' => 'false',
  1811. 'splash' => 'true',
  1812. 'ping' => 'false',
  1813. 'ping_url' => '',
  1814. 'defaultz' => '',
  1815. );
  1816. }
  1817. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1818. $output = '
  1819. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1820. <tab class="content-form form-inline">
  1821. <div class="row">
  1822. '.buildField(array(
  1823. 'type' => 'custom',
  1824. '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>',
  1825. ),12,1,1).'
  1826. '.buildField(array(
  1827. 'type' => 'hidden',
  1828. 'id' => 'tab-'.$data['id'].'-id',
  1829. 'name' => 'id['.$data['id'].']',
  1830. 'value' => $data['id'],
  1831. ),12,2,1).'
  1832. '.buildField(array(
  1833. 'type' => 'text',
  1834. 'id' => 'tab-'.$data['id'].'-name',
  1835. 'name' => 'name['.$data['id'].']',
  1836. 'required' => true,
  1837. 'placeholder' => 'Organizr Homepage',
  1838. 'labelTranslate' => 'TAB_NAME',
  1839. 'value' => $data['name'],
  1840. 'class' => 'darkBold',
  1841. ),12,2,1).'
  1842. '.buildField(array(
  1843. 'type' => 'text',
  1844. 'id' => 'tab-'.$data['id'].'-url',
  1845. 'name' => 'url['.$data['id'].']',
  1846. 'required' => true,
  1847. 'placeholder' => 'homepage.php',
  1848. 'labelTranslate' => 'TAB_URL',
  1849. 'value' => $data['url'],
  1850. 'class' => 'darkBold',
  1851. ),12,2,2).'
  1852. '.buildField(array(
  1853. 'type' => 'text',
  1854. 'id' => 'tab-'.$data['id'].'-iconurl',
  1855. 'name' => 'iconurl['.$data['id'].']',
  1856. 'placeholder' => 'images/organizr.png',
  1857. 'labelTranslate' => 'ICON_URL',
  1858. 'value' => $data['iconurl'],
  1859. 'class' => 'darkBold',
  1860. ),12,2,1).'
  1861. '.buildField(array(
  1862. 'type' => 'text',
  1863. 'id' => 'tab-'.$data['id'].'-icon',
  1864. 'name' => 'icon['.$data['id'].']',
  1865. 'placeholder' => 'fa-icon',
  1866. 'labelTranslate' => 'OR_ICON_NAME',
  1867. 'value' => $data['icon'],
  1868. 'class' => 'iconpickeradd darkBold',
  1869. ),12,1,1).'
  1870. '.buildField(array(
  1871. 'type' => 'text',
  1872. 'id' => 'tab-'.$data['id'].'-ping_url',
  1873. 'name' => 'ping_url['.$data['id'].']',
  1874. 'placeholder' => 'host:port',
  1875. 'labelTranslate' => 'PING_URL',
  1876. 'value' => $data['ping_url'],
  1877. 'class' => 'darkBold',
  1878. ),12,2,1).'
  1879. '.buildField(array(
  1880. 'type' => 'radio',
  1881. 'labelTranslate' => 'DEFAULT',
  1882. 'name' => 'defaultz['.$data['id'].']',
  1883. 'value' => $data['defaultz'],
  1884. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1885. ),12,1,1).'
  1886. '.buildField(array(
  1887. 'type' => 'button',
  1888. 'icon' => 'chevron-down',
  1889. 'buttonType' => 'success',
  1890. 'labelTranslate' => 'MORE',
  1891. 'onclick' => "$(this).parent().parent().parent().find('.slideInUp').toggle()",
  1892. 'class' => 'toggleTabExtra',
  1893. ),12,1,1).'
  1894. '.buildField(array(
  1895. 'type' => 'button',
  1896. 'icon' => 'trash',
  1897. 'buttonType' => 'danger',
  1898. 'labelTranslate' => 'REMOVE',
  1899. 'onclick' => "$(this).parents('li').remove();",
  1900. ),12,1,1).'</div><div id = "tab-'.$data['id'].'-row" class = "row animated slideInUp" style = "display:none;" ><div></div>
  1901. '.buildField(array(
  1902. 'type' => 'checkbox',
  1903. 'labelTranslate' => 'ACTIVE',
  1904. 'name' => 'active['.$data['id'].']',
  1905. 'value' => $data['active'],
  1906. ),12,1,1).'
  1907. '.buildField(array(
  1908. 'type' => 'checkbox',
  1909. 'labelTranslate' => 'USER',
  1910. 'colour' => 'primary',
  1911. 'name' => 'user['.$data['id'].']',
  1912. 'value' => $data['user'],
  1913. ),12,1,1).'
  1914. '.buildField(array(
  1915. 'type' => 'checkbox',
  1916. 'labelTranslate' => 'GUEST',
  1917. 'colour' => 'warning',
  1918. 'name' => 'guest['.$data['id'].']',
  1919. 'value' => $data['guest'],
  1920. ),12,1,1).'
  1921. '.buildField(array(
  1922. 'type' => 'checkbox',
  1923. 'labelTranslate' => 'NO_IFRAME',
  1924. 'colour' => 'danger',
  1925. 'name' => 'window['.$data['id'].']',
  1926. 'value' => $data['window'],
  1927. ),12,1,1).'
  1928. '.buildField(array(
  1929. 'type' => 'checkbox',
  1930. 'labelTranslate' => 'SPLASH',
  1931. 'colour' => 'success',
  1932. 'name' => 'splash['.$data['id'].']',
  1933. 'value' => $data['splash'],
  1934. ),12,1,1).'
  1935. '.buildField(array(
  1936. 'type' => 'checkbox',
  1937. 'labelTranslate' => 'PING',
  1938. 'colour' => 'success',
  1939. 'name' => 'ping['.$data['id'].']',
  1940. 'value' => $data['ping'],
  1941. ),12,1,1).'
  1942. </div>
  1943. </tab>
  1944. </li>
  1945. ';
  1946. return $output;
  1947. }
  1948. // Timezone array
  1949. function timezoneOptions() {
  1950. $output = array();
  1951. $timezones = array();
  1952. $regions = array(
  1953. 'Africa' => DateTimeZone::AFRICA,
  1954. 'America' => DateTimeZone::AMERICA,
  1955. 'Antarctica' => DateTimeZone::ANTARCTICA,
  1956. 'Arctic' => DateTimeZone::ARCTIC,
  1957. 'Asia' => DateTimeZone::ASIA,
  1958. 'Atlantic' => DateTimeZone::ATLANTIC,
  1959. 'Australia' => DateTimeZone::AUSTRALIA,
  1960. 'Europe' => DateTimeZone::EUROPE,
  1961. 'Indian' => DateTimeZone::INDIAN,
  1962. 'Pacific' => DateTimeZone::PACIFIC
  1963. );
  1964. foreach ($regions as $name => $mask) {
  1965. $zones = DateTimeZone::listIdentifiers($mask);
  1966. foreach($zones as $timezone) {
  1967. $time = new DateTime(NULL, new DateTimeZone($timezone));
  1968. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  1969. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  1970. }
  1971. }
  1972. return $output;
  1973. }
  1974. // Build Database
  1975. function createSQLiteDB($path = false) {
  1976. if ($path === false) {
  1977. if (DATABASE_LOCATION){
  1978. $path = DATABASE_LOCATION;
  1979. } else {
  1980. debug_out('No Path Specified!');
  1981. }
  1982. }
  1983. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  1984. if (!isset($GLOBALS['file_db'])) {
  1985. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  1986. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1987. }
  1988. // Create Users
  1989. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  1990. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1991. `username` TEXT UNIQUE,
  1992. `password` TEXT,
  1993. `email` TEXT,
  1994. `token` TEXT,
  1995. `role` TEXT,
  1996. `active` TEXT,
  1997. `last` TEXT,
  1998. `auth_service` TEXT DEFAULT \'internal\'
  1999. );');
  2000. // Create Tabs
  2001. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  2002. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2003. `order` INTEGER,
  2004. `users_id` INTEGER,
  2005. `name` TEXT,
  2006. `url` TEXT,
  2007. `defaultz` TEXT,
  2008. `active` TEXT,
  2009. `user` TEXT,
  2010. `guest` TEXT,
  2011. `icon` TEXT,
  2012. `iconurl` TEXT,
  2013. `window` TEXT,
  2014. `splash` TEXT,
  2015. `ping` TEXT,
  2016. `ping_url` TEXT
  2017. );');
  2018. // Create Options
  2019. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  2020. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2021. `users_id` INTEGER UNIQUE,
  2022. `title` TEXT UNIQUE,
  2023. `topbar` TEXT,
  2024. `bottombar` TEXT,
  2025. `sidebar` TEXT,
  2026. `hoverbg` TEXT,
  2027. `topbartext` TEXT,
  2028. `activetabBG` TEXT,
  2029. `activetabicon` TEXT,
  2030. `activetabtext` TEXT,
  2031. `inactiveicon` TEXT,
  2032. `inactivetext` TEXT,
  2033. `loading` TEXT,
  2034. `hovertext` TEXT
  2035. );');
  2036. // Create Invites
  2037. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  2038. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2039. `code` TEXT UNIQUE,
  2040. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  2041. `email` TEXT,
  2042. `username` TEXT,
  2043. `dateused` TIMESTAMP,
  2044. `usedby` TEXT,
  2045. `ip` TEXT,
  2046. `valid` TEXT
  2047. );');
  2048. writeLog("success", "database created/saved");
  2049. return $users && $tabs && $options && $invites;
  2050. } else {
  2051. writeLog("error", "database was unable to be created/saved");
  2052. return false;
  2053. }
  2054. }
  2055. // Upgrade Database
  2056. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  2057. if (!$db_path) {
  2058. if (defined('DATABASE_LOCATION')) {
  2059. $db_path = DATABASE_LOCATION;
  2060. } else {
  2061. debug_out('No Path Specified',1);
  2062. }
  2063. }
  2064. if (!isset($GLOBALS['file_db'])) {
  2065. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  2066. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2067. }
  2068. // Cache current DB
  2069. $cache = array();
  2070. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  2071. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  2072. foreach($row as $k => $v) {
  2073. if (is_string($k)) {
  2074. $cache[$table['name']][$key][$k] = $v;
  2075. }
  2076. }
  2077. }
  2078. }
  2079. // Remove Current Database
  2080. $GLOBALS['file_db'] = null;
  2081. $pathDigest = pathinfo($db_path.'users.db');
  2082. if (file_exists($db_path.'users.db')) {
  2083. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  2084. }
  2085. // Create New Database
  2086. $success = createSQLiteDB($db_path);
  2087. // Restore Items
  2088. if ($success) {
  2089. foreach($cache as $table => $tableData) {
  2090. if ($tableData) {
  2091. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  2092. $insertValues = array();
  2093. reset($tableData);
  2094. foreach($tableData as $key => $value) {
  2095. $insertValues[] = '('.implode(',',array_map(function($d) {
  2096. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  2097. }, $value)).')';
  2098. }
  2099. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  2100. }
  2101. }
  2102. writeLog("success", "database values have been updated");
  2103. return true;
  2104. } else {
  2105. writeLog("error", "database values unable to be updated");
  2106. return false;
  2107. }
  2108. }
  2109. // Commit colours to database
  2110. function updateDBOptions($values) {
  2111. if (!isset($GLOBALS['file_db'])) {
  2112. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2113. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2114. }
  2115. // Commit new values to database
  2116. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  2117. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  2118. }, $values, array_keys($values))).';')->rowCount()) {
  2119. return true;
  2120. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  2121. writeLog("success", "database values for options table have been updated");
  2122. return true;
  2123. } else {
  2124. writeLog("error", "database values for options table unable to be updated");
  2125. return false;
  2126. }
  2127. }
  2128. // Send AJAX notification
  2129. function sendNotification($success, $message = false, $send = true) {
  2130. $notifyExplode = explode("-", NOTIFYEFFECT);
  2131. if ($success) {
  2132. $msg = array(
  2133. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  2134. 'icon' => 'floppy-o',
  2135. 'type' => 'success',
  2136. 'length' => '5000',
  2137. 'layout' => $notifyExplode[0],
  2138. 'effect' => $notifyExplode[1],
  2139. );
  2140. } else {
  2141. $msg = array(
  2142. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2143. 'icon' => 'floppy-o',
  2144. 'type' => 'failed',
  2145. 'length' => '5000',
  2146. 'layout' => $notifyExplode[0],
  2147. 'effect' => $notifyExplode[1],
  2148. );
  2149. }
  2150. // Send and kill script?
  2151. if ($send) {
  2152. header('Content-Type: application/json');
  2153. echo json_encode(array('notify'=>$msg));
  2154. die();
  2155. }
  2156. return $msg;
  2157. }
  2158. // Load colours from the database
  2159. function loadAppearance() {
  2160. // Defaults
  2161. $defaults = array(
  2162. 'title' => 'Organizr',
  2163. 'topbartext' => '#66D9EF',
  2164. 'topbar' => '#333333',
  2165. 'bottombar' => '#333333',
  2166. 'sidebar' => '#393939',
  2167. 'hoverbg' => '#AD80FD',
  2168. 'activetabBG' => '#F92671',
  2169. 'activetabicon' => '#FFFFFF',
  2170. 'activetabtext' => '#FFFFFF',
  2171. 'inactiveicon' => '#66D9EF',
  2172. 'inactivetext' => '#66D9EF',
  2173. 'loading' => '#66D9EF',
  2174. 'hovertext' => '#000000',
  2175. );
  2176. if (DATABASE_LOCATION) {
  2177. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2178. if (!isset($GLOBALS['file_db'])) {
  2179. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2180. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2181. }
  2182. // Database Lookup
  2183. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2184. // Replace defaults with filled options
  2185. foreach($options as $row) {
  2186. foreach($defaults as $key => $value) {
  2187. if (isset($row[$key]) && $row[$key]) {
  2188. $defaults[$key] = $row[$key];
  2189. }
  2190. }
  2191. }
  2192. }
  2193. }
  2194. // Return the Results
  2195. return $defaults;
  2196. }
  2197. // Delete Database
  2198. function deleteDatabase() {
  2199. unset($_COOKIE['Organizr']);
  2200. setcookie('Organizr', '', time() - 3600, '/');
  2201. unset($_COOKIE['OrganizrU']);
  2202. setcookie('OrganizrU', '', time() - 3600, '/');
  2203. $GLOBALS['file_db'] = null;
  2204. unlink(DATABASE_LOCATION.'users.db');
  2205. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2206. if(is_dir($file)) {
  2207. rmdir($file);
  2208. } elseif (!is_dir($file)) {
  2209. unlink($file);
  2210. }
  2211. }
  2212. rmdir($userdirpath);
  2213. writeLog("success", "database has been deleted");
  2214. return true;
  2215. }
  2216. // Upgrade the installation
  2217. function upgradeInstall($branch = 'master') {
  2218. function downloadFile($url, $path){
  2219. ini_set('max_execution_time',0);
  2220. $folderPath = "upgrade/";
  2221. if(!mkdir($folderPath)){
  2222. writeLog("error", "organizr could not create upgrade folder");
  2223. }
  2224. $newfname = $folderPath . $path;
  2225. $file = fopen ($url, 'rb');
  2226. if ($file) {
  2227. $newf = fopen ($newfname, 'wb');
  2228. if ($newf) {
  2229. while(!feof($file)) {
  2230. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2231. }
  2232. }
  2233. }else{
  2234. writeLog("error", "organizr could not download $url");
  2235. }
  2236. if ($file) {
  2237. fclose($file);
  2238. writeLog("success", "organizr finished downloading the github zip file");
  2239. }else{
  2240. writeLog("error", "organizr could not download the github zip file");
  2241. }
  2242. if ($newf) {
  2243. fclose($newf);
  2244. writeLog("success", "organizr created upgrade zip file from github zip file");
  2245. }else{
  2246. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2247. }
  2248. }
  2249. function unzipFile($zipFile){
  2250. $zip = new ZipArchive;
  2251. $extractPath = "upgrade/";
  2252. if($zip->open($extractPath . $zipFile) != "true"){
  2253. writeLog("error", "organizr could not unzip upgrade.zip");
  2254. }else{
  2255. writeLog("success", "organizr unzipped upgrade.zip");
  2256. }
  2257. /* Extract Zip File */
  2258. $zip->extractTo($extractPath);
  2259. $zip->close();
  2260. }
  2261. // Function to remove folders and files
  2262. function rrmdir($dir) {
  2263. if (is_dir($dir)) {
  2264. $files = scandir($dir);
  2265. foreach ($files as $file)
  2266. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2267. rmdir($dir);
  2268. }
  2269. else if (file_exists($dir)) unlink($dir);
  2270. }
  2271. // Function to Copy folders and files
  2272. function rcopy($src, $dst) {
  2273. if (is_dir ( $src )) {
  2274. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2275. $files = scandir ( $src );
  2276. foreach ( $files as $file )
  2277. if ($file != "." && $file != "..")
  2278. rcopy ( "$src/$file", "$dst/$file" );
  2279. } else if (file_exists ( $src ))
  2280. copy ( $src, $dst );
  2281. }
  2282. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2283. $file = "upgrade.zip";
  2284. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2285. $cleanup = __DIR__ . "/upgrade/";
  2286. $destination = __DIR__ . "/";
  2287. writeLog("success", "starting organizr upgrade process");
  2288. downloadFile($url, $file);
  2289. unzipFile($file);
  2290. rcopy($source, $destination);
  2291. writeLog("success", "new organizr files copied");
  2292. rrmdir($cleanup);
  2293. writeLog("success", "organizr upgrade folder removed");
  2294. writeLog("success", "organizr has been updated");
  2295. return true;
  2296. }
  2297. // NzbGET Items
  2298. function nzbgetConnect($list = 'listgroups') {
  2299. $url = qualifyURL(NZBGETURL);
  2300. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2301. $api = json_decode($api, true);
  2302. $gotNZB = array();
  2303. if (is_array($api) || is_object($api)){
  2304. foreach ($api['result'] AS $child) {
  2305. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2306. $downloadStatus = $child['Status'];
  2307. $downloadCategory = $child['Category'];
  2308. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2309. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2310. if($child['Health'] <= "750"){
  2311. $downloadHealth = "danger";
  2312. }elseif($child['Health'] <= "900"){
  2313. $downloadHealth = "warning";
  2314. }elseif($child['Health'] <= "1000"){
  2315. $downloadHealth = "success";
  2316. }
  2317. $gotNZB[] = '<tr>
  2318. <td class="col-xs-7 nzbtable-file-row">'.$downloadName.'</td>
  2319. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2320. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2321. <td class="col-xs-2 nzbtable nzbtable-row">
  2322. <div class="progress">
  2323. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2324. <p class="text-center">'.round($downloadPercent).'%</p>
  2325. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2326. </div>
  2327. </div>
  2328. </td>
  2329. </tr>';
  2330. }
  2331. if ($gotNZB) {
  2332. return implode('',$gotNZB);
  2333. } else {
  2334. return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
  2335. }
  2336. }else{
  2337. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Username and Password - if HTTPS, is cert valid");
  2338. }
  2339. }
  2340. // Sabnzbd Items
  2341. function sabnzbdConnect($list = 'queue') {
  2342. $url = qualifyURL(SABNZBDURL);
  2343. $api = file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2344. $api = json_decode($api, true);
  2345. $gotNZB = array();
  2346. foreach ($api[$list]['slots'] AS $child) {
  2347. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2348. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2349. $downloadStatus = $child['status'];
  2350. $gotNZB[] = '<tr>
  2351. <td class="col-xs-7 nzbtable-file-row">'.$downloadName.'</td>
  2352. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2353. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2354. <td class="col-xs-2 nzbtable nzbtable-row">
  2355. <div class="progress">
  2356. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2357. <p class="text-center">'.round($downloadPercent).'%</p>
  2358. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2359. </div>
  2360. </div>
  2361. </td>
  2362. </tr>';
  2363. }
  2364. if ($gotNZB) {
  2365. return implode('',$gotNZB);
  2366. } else {
  2367. return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
  2368. }
  2369. }
  2370. // Apply new tab settings
  2371. function updateTabs($tabs) {
  2372. if (!isset($GLOBALS['file_db'])) {
  2373. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2374. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2375. }
  2376. // Validate
  2377. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2378. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2379. // Clear Existing Tabs
  2380. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2381. // Process New Tabs
  2382. $totalValid = 0;
  2383. foreach ($tabs['name'] as $key => $value) {
  2384. // Qualify
  2385. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2386. $totalValid++;
  2387. $fields = array();
  2388. foreach(array('id','name','url','icon','iconurl','order','ping_url') as $v) {
  2389. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2390. }
  2391. foreach(array('active','user','guest','defaultz','window','splash','ping') as $v) {
  2392. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2393. }
  2394. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2395. }
  2396. writeLog("success", "tabs successfully saved");
  2397. return $totalValid;
  2398. } else {
  2399. writeLog("error", "tabs could not save");
  2400. return false;
  2401. }
  2402. writeLog("error", "tabs could not save");
  2403. return false;
  2404. }
  2405. // ==============
  2406. function clean($strin) {
  2407. $strout = null;
  2408. for ($i = 0; $i < strlen($strin); $i++) {
  2409. $ord = ord($strin[$i]);
  2410. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2411. $strout .= "&amp;#{$ord};";
  2412. }
  2413. else {
  2414. switch ($strin[$i]) {
  2415. case '<':
  2416. $strout .= '&lt;';
  2417. break;
  2418. case '>':
  2419. $strout .= '&gt;';
  2420. break;
  2421. case '&':
  2422. $strout .= '&amp;';
  2423. break;
  2424. case '"':
  2425. $strout .= '&quot;';
  2426. break;
  2427. default:
  2428. $strout .= $strin[$i];
  2429. }
  2430. }
  2431. }
  2432. return $strout;
  2433. }
  2434. function registration_callback($username, $email, $userdir){
  2435. global $data;
  2436. $data = array($username, $email, $userdir);
  2437. }
  2438. function printArray($arrayName){
  2439. $messageCount = count($arrayName);
  2440. $i = 0;
  2441. foreach ( $arrayName as $item ) :
  2442. $i++;
  2443. if($i < $messageCount) :
  2444. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2445. elseif($i = $messageCount) :
  2446. echo "<small class='text-uppercase'>" . $item . "</small>";
  2447. endif;
  2448. endforeach;
  2449. }
  2450. function write_ini_file($content, $path) {
  2451. if (!$handle = fopen($path, 'w')) {
  2452. return false;
  2453. }
  2454. $success = fwrite($handle, trim($content));
  2455. fclose($handle);
  2456. return $success;
  2457. }
  2458. function gotTimezone(){
  2459. $regions = array(
  2460. 'Africa' => DateTimeZone::AFRICA,
  2461. 'America' => DateTimeZone::AMERICA,
  2462. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2463. 'Arctic' => DateTimeZone::ARCTIC,
  2464. 'Asia' => DateTimeZone::ASIA,
  2465. 'Atlantic' => DateTimeZone::ATLANTIC,
  2466. 'Australia' => DateTimeZone::AUSTRALIA,
  2467. 'Europe' => DateTimeZone::EUROPE,
  2468. 'Indian' => DateTimeZone::INDIAN,
  2469. 'Pacific' => DateTimeZone::PACIFIC
  2470. );
  2471. $timezones = array();
  2472. foreach ($regions as $name => $mask) {
  2473. $zones = DateTimeZone::listIdentifiers($mask);
  2474. foreach($zones as $timezone) {
  2475. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2476. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2477. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2478. }
  2479. }
  2480. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2481. foreach($timezones as $region => $list) {
  2482. print '<optgroup label="' . $region . '">' . "\n";
  2483. foreach($list as $timezone => $name) {
  2484. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2485. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2486. }
  2487. print '</optgroup>' . "\n";
  2488. }
  2489. print '</select>';
  2490. }
  2491. function getTimezone(){
  2492. $regions = array(
  2493. 'Africa' => DateTimeZone::AFRICA,
  2494. 'America' => DateTimeZone::AMERICA,
  2495. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2496. 'Arctic' => DateTimeZone::ARCTIC,
  2497. 'Asia' => DateTimeZone::ASIA,
  2498. 'Atlantic' => DateTimeZone::ATLANTIC,
  2499. 'Australia' => DateTimeZone::AUSTRALIA,
  2500. 'Europe' => DateTimeZone::EUROPE,
  2501. 'Indian' => DateTimeZone::INDIAN,
  2502. 'Pacific' => DateTimeZone::PACIFIC
  2503. );
  2504. $timezones = array();
  2505. foreach ($regions as $name => $mask) {
  2506. $zones = DateTimeZone::listIdentifiers($mask);
  2507. foreach($zones as $timezone) {
  2508. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2509. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2510. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2511. }
  2512. }
  2513. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2514. foreach($timezones as $region => $list) {
  2515. print '<optgroup label="' . $region . '">' . "\n";
  2516. foreach($list as $timezone => $name) {
  2517. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2518. }
  2519. print '</optgroup>' . "\n";
  2520. }
  2521. print '</select>';
  2522. }
  2523. function explosion($string, $position){
  2524. $getWord = explode("|", $string);
  2525. return $getWord[$position];
  2526. }
  2527. function getServerPath() {
  2528. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2529. $protocol = "https://";
  2530. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2531. $protocol = "https://";
  2532. } else {
  2533. $protocol = "http://";
  2534. }
  2535. $domain = '';
  2536. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2537. $domain = $_SERVER['SERVER_NAME'];
  2538. }elseif(isset($_SERVER['HTTP_HOST'])){
  2539. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2540. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2541. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2542. if ($port == "80" || $port == "443"){
  2543. $domain = $domain;
  2544. }else{
  2545. $domain = $_SERVER['HTTP_HOST'];
  2546. }
  2547. }else{
  2548. $domain = $_SERVER['HTTP_HOST'];
  2549. }
  2550. }
  2551. return $protocol . $domain . str_replace("\\", "/", dirname($_SERVER['REQUEST_URI']));
  2552. }
  2553. function get_browser_name() {
  2554. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2555. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2556. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2557. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2558. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2559. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2560. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2561. return 'Other';
  2562. }
  2563. function getSickrageCalendarWanted($array){
  2564. $array = json_decode($array, true);
  2565. //$gotCalendar = "";
  2566. $gotCalendar = array();
  2567. $i = 0;
  2568. foreach($array['data']['missed'] AS $child) {
  2569. $i++;
  2570. $seriesName = $child['show_name'];
  2571. $episodeID = $child['tvdbid'];
  2572. $episodeAirDate = $child['airdate'];
  2573. $episodeAirDateTime = explode(" ",$child['airs']);
  2574. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2575. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2576. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2577. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2578. $downloaded = "0";
  2579. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2580. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2581. array_push($gotCalendar, array(
  2582. "id" => "Sick-Miss-".$i,
  2583. "title" => $seriesName,
  2584. "start" => $episodeAirDate,
  2585. "className" => $downloaded." tvID--".$episodeID,
  2586. "imagetype" => "tv",
  2587. ));
  2588. }
  2589. foreach($array['data']['today'] AS $child) {
  2590. $i++;
  2591. $seriesName = $child['show_name'];
  2592. $episodeID = $child['tvdbid'];
  2593. $episodeAirDate = $child['airdate'];
  2594. $episodeAirDateTime = explode(" ",$child['airs']);
  2595. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2596. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2597. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2598. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2599. $downloaded = "0";
  2600. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2601. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2602. array_push($gotCalendar, array(
  2603. "id" => "Sick-Today-".$i,
  2604. "title" => $seriesName,
  2605. "start" => $episodeAirDate,
  2606. "className" => $downloaded." tvID--".$episodeID,
  2607. "imagetype" => "tv",
  2608. ));
  2609. }
  2610. foreach($array['data']['soon'] AS $child) {
  2611. $i++;
  2612. $seriesName = $child['show_name'];
  2613. $episodeID = $child['tvdbid'];
  2614. $episodeAirDate = $child['airdate'];
  2615. $episodeAirDateTime = explode(" ",$child['airs']);
  2616. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2617. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2618. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2619. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2620. $downloaded = "0";
  2621. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2622. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2623. array_push($gotCalendar, array(
  2624. "id" => "Sick-Soon-".$i,
  2625. "title" => $seriesName,
  2626. "start" => $episodeAirDate,
  2627. "className" => $downloaded." tvID--".$episodeID,
  2628. "imagetype" => "tv",
  2629. ));
  2630. }
  2631. foreach($array['data']['later'] AS $child) {
  2632. $i++;
  2633. $seriesName = $child['show_name'];
  2634. $episodeID = $child['tvdbid'];
  2635. $episodeAirDate = $child['airdate'];
  2636. $episodeAirDateTime = explode(" ",$child['airs']);
  2637. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2638. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2639. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2640. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2641. $downloaded = "0";
  2642. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2643. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2644. array_push($gotCalendar, array(
  2645. "id" => "Sick-Later-".$i,
  2646. "title" => $seriesName,
  2647. "start" => $episodeAirDate,
  2648. "className" => $downloaded." tvID--".$episodeID,
  2649. "imagetype" => "tv",
  2650. ));
  2651. }
  2652. if ($i != 0){ return $gotCalendar; }
  2653. }
  2654. function getSickrageCalendarHistory($array){
  2655. $array = json_decode($array, true);
  2656. //$gotCalendar = "";
  2657. $gotCalendar = array();
  2658. $i = 0;
  2659. foreach($array['data'] AS $child) {
  2660. $i++;
  2661. $seriesName = $child['show_name'];
  2662. $episodeID = $child['tvdbid'];
  2663. $episodeAirDate = $child['date'];
  2664. $downloaded = "green-bg";
  2665. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2666. array_push($gotCalendar, array(
  2667. "id" => "Sick-History-".$i,
  2668. "title" => $seriesName,
  2669. "start" => $episodeAirDate,
  2670. "className" => $downloaded." tvID--".$episodeID,
  2671. "imagetype" => "tv",
  2672. ));
  2673. }
  2674. if ($i != 0){ return $gotCalendar; }
  2675. }
  2676. function getSonarrCalendar($array){
  2677. $array = json_decode($array, true);
  2678. //$gotCalendar = "";
  2679. $gotCalendar = array();
  2680. $i = 0;
  2681. foreach($array AS $child) {
  2682. $i++;
  2683. $seriesName = $child['series']['title'];
  2684. $episodeID = $child['series']['tvdbId'];
  2685. if(!isset($episodeID)){ $episodeID = ""; }
  2686. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2687. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2688. $episodeAirDate = $child['airDateUtc'];
  2689. $episodeAirDate = strtotime($episodeAirDate);
  2690. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2691. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2692. $downloaded = $child['hasFile'];
  2693. 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"; }
  2694. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2695. array_push($gotCalendar, array(
  2696. "id" => "Sonarr-".$i,
  2697. "title" => $seriesName,
  2698. "start" => $episodeAirDate,
  2699. "className" => $downloaded." tvID--".$episodeID,
  2700. "imagetype" => "tv",
  2701. ));
  2702. }
  2703. if ($i != 0){ return $gotCalendar; }
  2704. }
  2705. function getCouchCalendar(){
  2706. $url = qualifyURL(COUCHURL);
  2707. $api = curl_get($url."/api/".COUCHAPI."/media.list");
  2708. $api = json_decode($api, true);
  2709. $i = 0;
  2710. $gotCalendar = array();
  2711. if (is_array($api) || is_object($api)){
  2712. foreach($api['movies'] AS $child) {
  2713. if($child['status'] == "active" || $child['status'] == "done" ){
  2714. $i++;
  2715. $movieName = $child['info']['original_title'];
  2716. $movieID = $child['info']['tmdb_id'];
  2717. if(!isset($movieID)){ $movieID = ""; }
  2718. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  2719. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  2720. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  2721. $physicalRelease = strtotime($physicalRelease);
  2722. $physicalRelease = date("Y-m-d", $physicalRelease);
  2723. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2724. $downloaded = ($child['status'] == "active") ? "0" : "1";
  2725. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2726. array_push($gotCalendar, array(
  2727. "id" => "CouchPotato-".$i,
  2728. "title" => $movieName,
  2729. "start" => $physicalRelease,
  2730. "className" => $downloaded." movieID--".$movieID,
  2731. "imagetype" => "film",
  2732. ));
  2733. }
  2734. }
  2735. if ($i != 0){ return $gotCalendar; }
  2736. }else{
  2737. writeLog("error", "CouchPotato ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2738. }
  2739. }
  2740. function getRadarrCalendar($array){
  2741. $array = json_decode($array, true);
  2742. $gotCalendar = array();
  2743. $i = 0;
  2744. foreach($array AS $child) {
  2745. if(isset($child['physicalRelease'])){
  2746. $i++;
  2747. $movieName = $child['title'];
  2748. $movieID = $child['tmdbId'];
  2749. if(!isset($movieID)){ $movieID = ""; }
  2750. $physicalRelease = $child['physicalRelease'];
  2751. $physicalRelease = strtotime($physicalRelease);
  2752. $physicalRelease = date("Y-m-d", $physicalRelease);
  2753. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2754. $downloaded = $child['hasFile'];
  2755. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2756. array_push($gotCalendar, array(
  2757. "id" => "Radarr-".$i,
  2758. "title" => $movieName,
  2759. "start" => $physicalRelease,
  2760. "className" => $downloaded." movieID--".$movieID,
  2761. "imagetype" => "film",
  2762. ));
  2763. }
  2764. }
  2765. if ($i != 0){ return $gotCalendar; }
  2766. }
  2767. function getHeadphonesCalendar($url, $key, $list){
  2768. $url = qualifyURL(HEADPHONESURL);
  2769. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2770. $api = json_decode($api, true);
  2771. $i = 0;
  2772. //$gotCalendar = "";
  2773. $gotCalendar = array();;
  2774. if (is_array($api) || is_object($api)){
  2775. foreach($api AS $child) {
  2776. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2777. $i++;
  2778. $albumName = addslashes($child['AlbumTitle']);
  2779. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2780. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2781. $albumID = $child['AlbumID'];
  2782. $albumDate = strtotime($albumDate);
  2783. $albumDate = date("Y-m-d", $albumDate);
  2784. $albumStatus = $child['Status'];
  2785. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2786. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2787. //$gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2788. array_push($gotCalendar, array(
  2789. "id" => "Headphones-".$i,
  2790. "title" => $albumArtist.' - '.$albumName,
  2791. "start" => $albumDate,
  2792. "className" => $albumStatusColor,
  2793. "imagetype" => "music",
  2794. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2795. ));
  2796. }
  2797. if($child['Status'] == "Processed" && $list == "getHistory"){
  2798. $i++;
  2799. $find = array('_','[', ']', '\n');
  2800. $replace = array(' ','(', ')', ' ');
  2801. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  2802. $albumDate = $child['DateAdded'];
  2803. $albumID = $child['AlbumID'];
  2804. $albumDate = strtotime($albumDate);
  2805. $albumDate = date("Y-m-d", $albumDate);
  2806. $albumStatusColor = "green-bg";
  2807. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2808. //$gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2809. array_push($gotCalendar, array(
  2810. "id" => "Headphones-".$i,
  2811. "title" => $albumName,
  2812. "start" => $albumDate,
  2813. "className" => $albumStatusColor,
  2814. "imagetype" => "music",
  2815. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2816. ));
  2817. }
  2818. }
  2819. if ($i != 0){ return $gotCalendar; }
  2820. }else{
  2821. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2822. }
  2823. }
  2824. function checkRootPath($string){
  2825. if($string == "\\" || $string == "/"){
  2826. return "/";
  2827. }else{
  2828. return str_replace("\\", "/", $string) . "/";
  2829. }
  2830. }
  2831. function strip($string){
  2832. $string = strip_tags($string);
  2833. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  2834. }
  2835. function writeLog($type, $message){
  2836. if(file_exists("org.log")){
  2837. if(filesize("org.log") > 500000){
  2838. rename('org.log','org['.date('Y-m-d').'].log');
  2839. $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";
  2840. file_put_contents("org.log", $message2, FILE_APPEND | LOCK_EX);
  2841. }
  2842. }
  2843. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  2844. file_put_contents("org.log", $message, FILE_APPEND | LOCK_EX);
  2845. }
  2846. function readLog(){
  2847. $log = file("org.log",FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  2848. $log = array_reverse($log);
  2849. foreach($log as $line){
  2850. if(substr_count($line, '|') == 2){
  2851. $line = explode("|", strip($line));
  2852. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  2853. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  2854. }
  2855. }
  2856. }
  2857. function buildStream($array){
  2858. $result = "";
  2859. if (array_key_exists('platform', $array)) {
  2860. $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>';
  2861. }
  2862. if (array_key_exists('device', $array)) {
  2863. $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>';
  2864. }
  2865. if (array_key_exists('stream', $array)) {
  2866. $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>';
  2867. }
  2868. if (array_key_exists('video', $array)) {
  2869. $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>';
  2870. }
  2871. if (array_key_exists('audio', $array)) {
  2872. $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>';
  2873. }
  2874. return $result;
  2875. }
  2876. function streamType($value){
  2877. if($value == "transcode" || $value == "Transcode"){
  2878. return "Transcode";
  2879. }elseif($value == "copy" || $value == "DirectStream"){
  2880. return "Direct Stream";
  2881. }elseif($value == "directplay" || $value == "DirectPlay"){
  2882. return "Direct Play";
  2883. }else{
  2884. return "Direct Play";
  2885. }
  2886. }
  2887. function getPlatform($platform){
  2888. $allPlatforms = array(
  2889. "Chrome" => "chrome.png",
  2890. "tvOS" => "atv.png",
  2891. "iOS" => "ios.png",
  2892. "Xbox One" => "xbox.png",
  2893. "Mystery 4" => "playstation.png",
  2894. "Samsung" => "samsung.png",
  2895. "Roku" => "roku.png",
  2896. "Emby for iOS" => "ios.png",
  2897. "Emby Mobile" => "emby.png",
  2898. "Emby Theater" => "emby.png",
  2899. "Emby Classic" => "emby.png",
  2900. "Safari" => "safari.png",
  2901. "Android" => "android.png",
  2902. "AndroidTv" => "android.png",
  2903. "Chromecast" => "chromecast.png",
  2904. "Dashboard" => "emby.png",
  2905. "Dlna" => "dlna.png",
  2906. "Windows Phone" => "wp.png",
  2907. "Windows RT" => "win8.png",
  2908. "Kodi" => "kodi.png",
  2909. );
  2910. if (array_key_exists($platform, $allPlatforms)) {
  2911. return $allPlatforms[$platform];
  2912. }else{
  2913. return "pmp.png";
  2914. }
  2915. }
  2916. function getServer(){
  2917. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  2918. return $server;
  2919. }
  2920. function prettyPrint($array) {
  2921. echo "<pre>";
  2922. print_r($array);
  2923. echo "</pre>";
  2924. echo "<br/>";
  2925. }
  2926. function checkFrame($array, $url){
  2927. if(array_key_exists("x-frame-options", $array)){
  2928. if($array['x-frame-options'] == "deny"){
  2929. return false;
  2930. }elseif($array['x-frame-options'] == "sameorgin"){
  2931. $digest = parse_url($url);
  2932. $host = (isset($digest['host'])?$digest['host']:'');
  2933. if(getServer() == $host){
  2934. return true;
  2935. }else{
  2936. return false;
  2937. }
  2938. }
  2939. }else{
  2940. if(!$array){
  2941. return false;
  2942. }
  2943. return true;
  2944. }
  2945. }
  2946. function frameTest($url){
  2947. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  2948. $url = qualifyURL($url);
  2949. if(checkFrame($array, $url)){
  2950. return true;
  2951. }else{
  2952. return false;
  2953. }
  2954. }
  2955. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  2956. $notifyExplode = explode("-", NOTIFYEFFECT);
  2957. if ($result) {
  2958. $msg = array(
  2959. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  2960. 'icon' => $icon,
  2961. 'type' => 'success',
  2962. 'length' => '5000',
  2963. 'layout' => $notifyExplode[0],
  2964. 'effect' => $notifyExplode[1],
  2965. );
  2966. } else {
  2967. $msg = array(
  2968. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  2969. 'icon' => $icon,
  2970. 'type' => 'error',
  2971. 'length' => '5000',
  2972. 'layout' => $notifyExplode[0],
  2973. 'effect' => $notifyExplode[1],
  2974. );
  2975. }
  2976. // Send and kill script?
  2977. if ($send) {
  2978. header('Content-Type: application/json');
  2979. echo json_encode(array('notify'=>$msg));
  2980. die();
  2981. }
  2982. return $msg;
  2983. }
  2984. function buildHomepageNotice($layout, $type, $title, $message){
  2985. switch ($layout) {
  2986. case 'elegant':
  2987. return '
  2988. <div id="homepageNotice" class="row">
  2989. <div class="col-lg-12">
  2990. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  2991. <div class="content-title i-block">
  2992. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  2993. <div class="content-tools i-block pull-right">
  2994. <a class="close-btn">
  2995. <i class="fa fa-times"></i>
  2996. </a>
  2997. </div>
  2998. </div>
  2999. '.$message.'
  3000. </div>
  3001. </div>
  3002. </div>
  3003. ';
  3004. break;
  3005. case 'basic':
  3006. return '
  3007. <div id="homepageNotice" class="row">
  3008. <div class="col-lg-12">
  3009. <div class="panel panel-'.$type.'">
  3010. <div class="panel-heading">
  3011. <h3 class="panel-title">'.$title.'</h3>
  3012. </div>
  3013. <div class="panel-body">
  3014. '.$message.'
  3015. </div>
  3016. </div>
  3017. </div>
  3018. </div>
  3019. ';
  3020. break;
  3021. case 'jumbotron';
  3022. return '
  3023. <div id="homepageNotice" class="row">
  3024. <div class="col-lg-12">
  3025. <div class="jumbotron">
  3026. <div class="container">
  3027. <h1>'.$title.'</h1>
  3028. <p>'.$message.'</p>
  3029. </div>
  3030. </div>
  3031. </div>
  3032. </div>
  3033. ';
  3034. }
  3035. }
  3036. function embyArray($array, $type) {
  3037. $key = ($type == "video" ? "Height" : "Channels");
  3038. if (array_key_exists($key, $array)) {
  3039. switch ($type) {
  3040. case "video":
  3041. $codec = $array["Codec"];
  3042. $height = $array["Height"];
  3043. $width = $array["Width"];
  3044. break;
  3045. default:
  3046. $codec = $array["Codec"];
  3047. $channels = $array["Channels"];
  3048. }
  3049. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  3050. }
  3051. foreach ($array as $element) {
  3052. if (is_array($element)) {
  3053. if (embyArray($element, $type)) {
  3054. return embyArray($element, $type);
  3055. }
  3056. }
  3057. }
  3058. }
  3059. // Get Now Playing Streams From Plex
  3060. function searchPlex($query){
  3061. $address = qualifyURL(PLEXURL);
  3062. $openTab = (PLEXTABNAME) ? "true" : "false";
  3063. // Perform API requests
  3064. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  3065. libxml_use_internal_errors(true);
  3066. $api = simplexml_load_string($api);
  3067. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3068. if (!$getServer) { return 'Could not load!'; }
  3069. // Identify the local machine
  3070. $server = $getServer['machineIdentifier'];
  3071. $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>";
  3072. $items = "";
  3073. $albums = $movies = $shows = 0;
  3074. $style = 'style="vertical-align: middle"';
  3075. foreach($api AS $child) {
  3076. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  3077. $time = (string)$child['addedAt'];
  3078. $time = new DateTime("@$time");
  3079. $results = array(
  3080. "title" => (string)$child['title'],
  3081. "image" => (string)$child['thumb'],
  3082. "type" => (string)ucwords($child['type']),
  3083. "year" => (string)$child['year'],
  3084. "key" => (string)$child['ratingKey']."-search",
  3085. "ratingkey" => (string)$child['ratingKey'],
  3086. "genre" => (string)$child->Genre['tag'],
  3087. "added" => $time->format('Y-m-d'),
  3088. "extra" => "",
  3089. );
  3090. switch ($child['type']){
  3091. case "album":
  3092. $push = array(
  3093. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  3094. );
  3095. $results = array_replace($results,$push);
  3096. $albums++;
  3097. break;
  3098. case "movie":
  3099. $push = array(
  3100. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  3101. );
  3102. $results = array_replace($results,$push);
  3103. $movies++;
  3104. break;
  3105. case "show":
  3106. $push = array(
  3107. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  3108. );
  3109. $results = array_replace($results,$push);
  3110. $shows++;
  3111. break;
  3112. }
  3113. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  3114. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  3115. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  3116. }
  3117. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  3118. if (substr_count(PLEXURL, '.') != 2) {
  3119. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3120. }else{
  3121. $link = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3122. }
  3123. $items .= '<tr style="cursor: pointer;" class="openTab" extraTitle="'.$results['title'].'" extraType="'.$child['type'].'" openTab="'.$openTab.'" href="'.$link.'">
  3124. <th scope="row"><img src="'.$image_url.'"></th>
  3125. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  3126. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  3127. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  3128. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  3129. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  3130. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  3131. </tr>';
  3132. }
  3133. }
  3134. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  3135. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  3136. font-size: 23px;
  3137. ">&nbsp;'.$movies.'</strong></span>
  3138. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  3139. font-size: 23px;
  3140. ">&nbsp;'.$shows.'</strong></span>
  3141. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  3142. font-size: 23px;
  3143. ">&nbsp;'.$albums.'</strong></span>
  3144. </div>';
  3145. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  3146. }
  3147. function getBannedUsers($string){
  3148. if (strpos($string, ',') !== false) {
  3149. $banned = explode(",", $string);
  3150. }else{
  3151. $banned = array($string);
  3152. }
  3153. return $banned;
  3154. }
  3155. function getWhitelist($string){
  3156. if (strpos($string, ',') !== false) {
  3157. $whitelist = explode(",", $string);
  3158. }else{
  3159. $whitelist = array($string);
  3160. }
  3161. foreach($whitelist as &$ip){
  3162. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  3163. }
  3164. return $whitelist;
  3165. }
  3166. function get_client_ip() {
  3167. $ipaddress = '';
  3168. if (isset($_SERVER['HTTP_CLIENT_IP']))
  3169. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  3170. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  3171. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3172. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  3173. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  3174. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  3175. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  3176. else if(isset($_SERVER['HTTP_FORWARDED']))
  3177. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  3178. else if(isset($_SERVER['REMOTE_ADDR']))
  3179. $ipaddress = $_SERVER['REMOTE_ADDR'];
  3180. else
  3181. $ipaddress = 'UNKNOWN';
  3182. return $ipaddress;
  3183. }
  3184. //EMAIL SHIT
  3185. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  3186. $mail = new PHPMailer;
  3187. $mail->isSMTP();
  3188. $mail->Host = SMTPHOST;
  3189. $mail->SMTPAuth = SMTPHOSTAUTH;
  3190. $mail->Username = SMTPHOSTUSERNAME;
  3191. $mail->Password = SMTPHOSTPASSWORD;
  3192. $mail->SMTPSecure = SMTPHOSTTYPE;
  3193. $mail->Port = SMTPHOSTPORT;
  3194. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3195. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3196. $mail->isHTML(true);
  3197. if($email){
  3198. $mail->addAddress($email, $username);
  3199. }
  3200. if($cc){
  3201. $mail->addCC($cc);
  3202. }
  3203. if($bcc){
  3204. if(strpos($bcc , ',') === false){
  3205. $mail->addBCC($bcc);
  3206. }else{
  3207. $allEmails = explode(",",$bcc);
  3208. foreach($allEmails as $gotEmail){
  3209. $mail->addBCC($gotEmail);
  3210. }
  3211. }
  3212. }
  3213. $mail->Subject = $subject;
  3214. $mail->Body = $body;
  3215. //$mail->send();
  3216. if(!$mail->send()) {
  3217. writeLog("error", "mail failed to send");
  3218. } else {
  3219. writeLog("success", "mail has been sent");
  3220. }
  3221. }
  3222. //EMAIL SHIT
  3223. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  3224. $mail = new PHPMailer;
  3225. $mail->isSMTP();
  3226. $mail->Host = $host;
  3227. $mail->SMTPAuth = $auth;
  3228. $mail->Username = $username;
  3229. $mail->Password = $password;
  3230. $mail->SMTPSecure = $type;
  3231. $mail->Port = $port;
  3232. $mail->setFrom($from, $sendername);
  3233. $mail->addReplyTo($from, $sendername);
  3234. $mail->isHTML(true);
  3235. $mail->addAddress($to, "Organizr Admin");
  3236. $mail->Subject = "Organizr Test E-Mail";
  3237. $mail->Body = "This was just a test!";
  3238. //$mail->send();
  3239. if(!$mail->send()) {
  3240. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  3241. return false;
  3242. } else {
  3243. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  3244. return true;
  3245. }
  3246. }
  3247. function libraryList(){
  3248. $address = qualifyURL(PLEXURL);
  3249. $headers = array(
  3250. "Accept" => "application/json",
  3251. "X-Plex-Token" => PLEXTOKEN
  3252. );
  3253. libxml_use_internal_errors(true);
  3254. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3255. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3256. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  3257. $libraryList = array();
  3258. foreach($api->SharedServer->Section AS $child) {
  3259. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  3260. }
  3261. foreach($api->SharedServer AS $child) {
  3262. if(!empty($child['username'])){
  3263. $username = (string)strtolower($child['username']);
  3264. $email = (string)strtolower($child['email']);
  3265. $libraryList['users'][$username] = (string)$child['id'];
  3266. $libraryList['emails'][$email] = (string)$child['id'];
  3267. $libraryList['both'][$username] = $email;
  3268. }
  3269. }
  3270. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3271. }
  3272. function plexUserShare($username){
  3273. $address = qualifyURL(PLEXURL);
  3274. $headers = array(
  3275. "Accept" => "application/json",
  3276. "Content-Type" => "application/json",
  3277. "X-Plex-Token" => PLEXTOKEN
  3278. );
  3279. libxml_use_internal_errors(true);
  3280. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3281. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3282. $json = array(
  3283. "server_id" => $gotServer,
  3284. "shared_server" => array(
  3285. //"library_section_ids" => "[26527637]",
  3286. "invited_email" => $username
  3287. )
  3288. );
  3289. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3290. switch ($api['http_code']['http_code']){
  3291. case 400:
  3292. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3293. $result = "$username already has access to the shared libraries";
  3294. break;
  3295. case 401:
  3296. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3297. $result = "Invalid Plex Token";
  3298. break;
  3299. case 200:
  3300. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3301. $result = "$username now has access to your Plex Library";
  3302. break;
  3303. default:
  3304. writeLog("error", "PLEX INVITE: unknown error");
  3305. $result = false;
  3306. }
  3307. return (!empty($result) ? $result : null );
  3308. }
  3309. function plexUserDelete($username){
  3310. $address = qualifyURL(PLEXURL);
  3311. $headers = array(
  3312. "Accept" => "application/json",
  3313. "Content-Type" => "application/json",
  3314. "X-Plex-Token" => PLEXTOKEN
  3315. );
  3316. libxml_use_internal_errors(true);
  3317. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3318. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3319. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3320. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3321. switch ($api['http_code']['http_code']){
  3322. case 401:
  3323. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3324. $result = "Invalid Plex Token";
  3325. break;
  3326. case 200:
  3327. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3328. $result = "$username doesn't have access to your Plex Library anymore";
  3329. break;
  3330. default:
  3331. writeLog("error", "PLEX INVITE: unknown error");
  3332. $result = false;
  3333. }
  3334. return (!empty($result) ? $result : null );
  3335. }
  3336. function convertPlexName($user, $type){
  3337. $array = libraryList();
  3338. switch ($type){
  3339. case "username":
  3340. $plexUser = array_search ($user, $array['users']);
  3341. break;
  3342. case "id":
  3343. if (array_key_exists(strtolower($user), $array['users'])) {
  3344. $plexUser = $array['users'][strtolower($user)];
  3345. }
  3346. break;
  3347. default:
  3348. $plexUser = false;
  3349. }
  3350. return (!empty($plexUser) ? $plexUser : null );
  3351. }
  3352. function randomCode($length = 5, $type = null) {
  3353. switch ($type){
  3354. case "alpha":
  3355. $legend = array_merge(range('A', 'Z'));
  3356. break;
  3357. case "numeric":
  3358. $legend = array_merge(range(0,9));
  3359. break;
  3360. default:
  3361. $legend = array_merge(range(0,9),range('A', 'Z'));
  3362. }
  3363. $code = "";
  3364. for($i=0; $i < $length; $i++) {
  3365. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3366. }
  3367. return $code;
  3368. }
  3369. function inviteCodes($action, $code = null, $usedBy = null) {
  3370. if (!isset($GLOBALS['file_db'])) {
  3371. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3372. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3373. }
  3374. $now = date("Y-m-d H:i:s");
  3375. switch ($action) {
  3376. case "get":
  3377. // Start Array
  3378. $result = array();
  3379. // Database Lookup
  3380. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3381. // Get Codes
  3382. foreach($invites as $row) {
  3383. array_push($result, $row['code']);
  3384. }
  3385. // Return the Results
  3386. return (!empty($result) ? $result : false );
  3387. break;
  3388. case "check":
  3389. // Start Array
  3390. $result = array();
  3391. // Database Lookup
  3392. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3393. // Get Codes
  3394. foreach($invites as $row) {
  3395. $result = $row['code'];
  3396. }
  3397. // Return the Results
  3398. return (!empty($result) ? $result : false );
  3399. break;
  3400. case "use":
  3401. $currentIP = get_client_ip();
  3402. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3403. if(ENABLEMAIL){
  3404. if (!isset($GLOBALS['USER'])) {
  3405. require_once("user.php");
  3406. $GLOBALS['USER'] = new User('registration_callback');
  3407. }
  3408. 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."));
  3409. }
  3410. return (!empty($invites) ? true : false );
  3411. break;
  3412. }
  3413. }
  3414. function plexJoin($username, $email, $password){
  3415. $connectURL = 'https://plex.tv/users.json';
  3416. $headers = array(
  3417. 'Accept'=> 'application/json',
  3418. 'Content-Type' => 'application/x-www-form-urlencoded',
  3419. 'X-Plex-Product' => 'Organizr',
  3420. 'X-Plex-Version' => '1.0',
  3421. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3422. );
  3423. $body = array(
  3424. 'user[email]' => $email,
  3425. 'user[username]' => $username,
  3426. 'user[password]' => $password,
  3427. );
  3428. $api = curl_post($connectURL, $body, $headers);
  3429. $json = json_decode($api['content'], true);
  3430. $errors = (!empty($json['errors']) ? true : false);
  3431. $success = (!empty($json['user']) ? true : false);
  3432. //Use This for later
  3433. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3434. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3435. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3436. $errorMessage = "";
  3437. if($errors){
  3438. if($usernameError){ $errorMessage .= "[Username Error: ". $usernameError ."]"; }
  3439. if($emailError){ $errorMessage .= "[Email Error: ". $emailError ."]"; }
  3440. if($passwordError){ $errorMessage .= "[Password Error: ". $passwordError ."]"; }
  3441. }
  3442. switch ($api['http_code']['http_code']){
  3443. case 400:
  3444. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." $username already has access to the shared libraries $errorMessage");
  3445. break;
  3446. case 401:
  3447. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." invalid Plex Token $errorMessage");
  3448. break;
  3449. case 422:
  3450. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." user info error $errorMessage");
  3451. break;
  3452. case 429:
  3453. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." too many requests to plex.tv please try later $errorMessage");
  3454. break;
  3455. case 200:
  3456. case 201:
  3457. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3458. break;
  3459. default:
  3460. writeLog("error", "PLEX JOIN: unknown error, $errorMessage Error: ".$api['http_code']['http_code']);
  3461. }
  3462. //prettyPrint($api);
  3463. //prettyPrint(json_decode($api['content'], true));
  3464. return (!empty($success) && empty($errors) ? true : false );
  3465. }
  3466. function getCert(){
  3467. $url = "http://curl.haxx.se/ca/cacert.pem";
  3468. $file = getcwd()."/config/cacert.pem";
  3469. $directory = getcwd()."/config/";
  3470. @mkdir($directory, 0770, true);
  3471. if(!file_exists($file)){
  3472. file_put_contents( $file, fopen($url, 'r'));
  3473. writeLog("success", "CERT PEM: pem file created");
  3474. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3475. file_put_contents( $file, fopen($url, 'r'));
  3476. writeLog("success", "CERT PEM: downloaded new pem file");
  3477. }
  3478. return $file;
  3479. }
  3480. function customCSS(){
  3481. if(CUSTOMCSS == "true") {
  3482. $template_file = "custom.css";
  3483. $file_handle = fopen($template_file, "rb");
  3484. echo "\n";
  3485. echo fread($file_handle, filesize($template_file));
  3486. fclose($file_handle);
  3487. echo "\n";
  3488. }
  3489. }
  3490. function tvdbToken(){
  3491. $headers = array(
  3492. "Accept" => "application/json",
  3493. "Content-Type" => "application/json"
  3494. );
  3495. $json = array(
  3496. "apikey" => "FBE7B62621F4CAD7",
  3497. "userkey" => "328BB46EB1E9A0F5",
  3498. "username" => "causefx"
  3499. );
  3500. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3501. return json_decode($api['content'], true)['token'];
  3502. }
  3503. function tvdbGet($id){
  3504. $headers = array(
  3505. "Accept" => "application/json",
  3506. "Authorization" => "Bearer ".tvdbToken(),
  3507. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3508. "trakt-api-version" => "2"
  3509. );
  3510. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3511. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3512. if(empty($api['trakt'])){
  3513. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3514. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3515. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3516. $api['series'] = json_decode($series, true)['data'];
  3517. $api['poster'] = json_decode($poster, true)['data'];
  3518. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3519. }
  3520. return $api;
  3521. }
  3522. function tvdbSearch($name, $type){
  3523. $name = rawurlencode(preg_replace("/\(([^()]*+|(?R))*\)/","", $name));
  3524. $headers = array(
  3525. "Accept" => "application/json",
  3526. "Authorization" => "Bearer ".tvdbToken(),
  3527. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3528. "trakt-api-version" => "2"
  3529. );
  3530. $trakt = curl_get("https://api.trakt.tv/search/$type?query=$name", $headers);
  3531. @$api['trakt'] = json_decode($trakt, true)[0][$type]['ids'];
  3532. return $api;
  3533. }
  3534. function getPlexPlaylists(){
  3535. $address = qualifyURL(PLEXURL);
  3536. // Perform API requests
  3537. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3538. libxml_use_internal_errors(true);
  3539. $api = simplexml_load_string($api);
  3540. if (is_array($api) || is_object($api)){
  3541. if (!$api->head->title){
  3542. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3543. if (!$getServer) { return 'Could not load!'; }
  3544. // Identify the local machine
  3545. $gotServer = $getServer['machineIdentifier'];
  3546. $output = "";
  3547. $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">';
  3548. foreach($api AS $child) {
  3549. $items = array();
  3550. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3551. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3552. $api = simplexml_load_string($api);
  3553. if (is_array($api) || is_object($api)){
  3554. if (!$api->head->title){
  3555. $className = preg_replace("/(\W)+/", "", $api['title']);
  3556. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3557. foreach($api->Video AS $child){
  3558. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3559. }
  3560. if (count($items)) {
  3561. $output .= ''.implode('',$items).'';
  3562. }
  3563. }
  3564. }
  3565. }
  3566. }
  3567. $hideMenu .= '</ul></div></div>';
  3568. 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>';
  3569. }else{
  3570. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3571. }
  3572. }else{
  3573. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3574. }
  3575. }
  3576. function readExternalLog($type,$filename,$name = null){
  3577. $log = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3578. $log = array_reverse($log);
  3579. foreach($log as $line){
  3580. if(!empty($line) && $line[0] != " "){
  3581. $line = strip($line);
  3582. if($type == "single"){
  3583. if( strpos( strtolower($line), "ror" ) !== false ) {
  3584. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3585. }else{
  3586. echo "<tr><td>".$line."</td></tr>";
  3587. }
  3588. }elseif($type == "all"){
  3589. if( strpos( strtolower($line), "ror" ) !== false ) {
  3590. echo "<tr><td class='red-bg'>".$name."</td>";
  3591. echo "<td class='red-bg'>".$line."</td></tr>";
  3592. }else{
  3593. echo "<tr><td>".$name."</td>";
  3594. echo "<td>".$line."</td></tr>";
  3595. }
  3596. }
  3597. }
  3598. }
  3599. }
  3600. function getLogs(){
  3601. $path = __DIR__ ."/logs/";
  3602. @mkdir($path, 0770, true);
  3603. $logs = array();
  3604. $files = array_diff(scandir($path), array('.', '..'));
  3605. foreach($files as $v){
  3606. $title = explode(".", $v)[0];
  3607. $logs[$title] = $path.$v;
  3608. }
  3609. return $logs;
  3610. }
  3611. function getBackups(){
  3612. $path = DATABASE_LOCATION ."backups/";
  3613. @mkdir($path, 0770, true);
  3614. $backups = array();
  3615. $files = array_diff(scandir($path), array('.', '..'));
  3616. return array_reverse($files);
  3617. }
  3618. function getExtension($string) {
  3619. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3620. }
  3621. function showFile(){
  3622. $file = $_GET['file'];
  3623. $fileType = getExtension($file);
  3624. if($fileType != 'php'){
  3625. header("Content-type: ".mimeTypes()[$fileType]);
  3626. @readfile($file);
  3627. }
  3628. }
  3629. function getCalendar(){
  3630. $sonarr = new Sonarr(SONARRURL, SONARRKEY);
  3631. $radarr = new Sonarr(RADARRURL, RADARRKEY);
  3632. $sickrage = new SickRage(SICKRAGEURL, SICKRAGEKEY);
  3633. $startDate = date('Y-m-d',strtotime("-".CALENDARSTARTDAY." days"));
  3634. $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
  3635. $calendarItems = array();
  3636. if (SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)){
  3637. try {
  3638. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate));
  3639. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  3640. } catch (Exception $e) {
  3641. writeLog("error", "SONARR ERROR: ".strip($e->getMessage()));
  3642. }
  3643. }
  3644. if (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)){
  3645. try {
  3646. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate));
  3647. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  3648. } catch (Exception $e) {
  3649. writeLog("error", "RADARR ERROR: ".strip($e->getMessage()));
  3650. }
  3651. }
  3652. if (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH)){
  3653. $couchCalendar = getCouchCalendar();
  3654. if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
  3655. }
  3656. if (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)){
  3657. $headphonesHistory = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getHistory");
  3658. $headphonesWanted = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getWanted");
  3659. if(!empty($headphonesHistory)) { $calendarItems = array_merge($calendarItems, $headphonesHistory); }
  3660. if(!empty($headphonesWanted)) { $calendarItems = array_merge($calendarItems, $headphonesWanted); }
  3661. }
  3662. if (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)){
  3663. try {
  3664. $sickrageFuture = getSickrageCalendarWanted($sickrage->future());
  3665. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  3666. } catch (Exception $e) {
  3667. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3668. } try {
  3669. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"));
  3670. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  3671. } catch (Exception $e) {
  3672. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3673. }
  3674. }
  3675. return $calendarItems;
  3676. }
  3677. function localURL($url){
  3678. if (strpos($url, 'https') !== false) {
  3679. preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $url, $result);
  3680. $result = (!empty($result) ? true : false);
  3681. return $result;
  3682. }
  3683. }
  3684. function fileArray($files){
  3685. foreach($files as $file){
  3686. if(file_exists($file)){
  3687. $list[] = $file;
  3688. }
  3689. }
  3690. if(!empty($list)){ return $list; }
  3691. }
  3692. function backupDB(){
  3693. if (extension_loaded('ZIP')) {
  3694. $directory = DATABASE_LOCATION."backups/";
  3695. @mkdir($directory, 0770, true);
  3696. $orgFiles = array(
  3697. 'css' => 'custom.css',
  3698. 'temp' => 'cus.sd',
  3699. 'orgLog' => 'org.log',
  3700. 'loginLog' => 'loginLog.json',
  3701. 'chatDB' => 'chatpack.db',
  3702. 'config' => 'config/config.php',
  3703. 'database' => DATABASE_LOCATION.'users.db'
  3704. );
  3705. $files = fileArray($orgFiles);
  3706. if(!empty($files)){
  3707. writeLog("success", "BACKUP: backup process started");
  3708. $zipname = $directory.'backup['.date('Y-m-d_H-i').']['.INSTALLEDVERSION.'].zip';
  3709. $zip = new ZipArchive;
  3710. $zip->open($zipname, ZipArchive::CREATE);
  3711. foreach ($files as $file) {
  3712. $zip->addFile($file);
  3713. }
  3714. $zip->close();
  3715. writeLog("success", "BACKUP: backup process finished");
  3716. return true;
  3717. }else{
  3718. return false;
  3719. }
  3720. }else{
  3721. return false;
  3722. }
  3723. }
  3724. class Ping {
  3725. private $host;
  3726. private $ttl;
  3727. private $timeout;
  3728. private $port = 80;
  3729. private $data = 'Ping';
  3730. private $commandOutput;
  3731. /**
  3732. * Called when the Ping object is created.
  3733. *
  3734. * @param string $host
  3735. * The host to be pinged.
  3736. * @param int $ttl
  3737. * Time-to-live (TTL) (You may get a 'Time to live exceeded' error if this
  3738. * value is set too low. The TTL value indicates the scope or range in which
  3739. * a packet may be forwarded. By convention:
  3740. * - 0 = same host
  3741. * - 1 = same subnet
  3742. * - 32 = same site
  3743. * - 64 = same region
  3744. * - 128 = same continent
  3745. * - 255 = unrestricted
  3746. * @param int $timeout
  3747. * Timeout (in seconds) used for ping and fsockopen().
  3748. * @throws \Exception if the host is not set.
  3749. */
  3750. public function __construct($host, $ttl = 255, $timeout = 10) {
  3751. if (!isset($host)) {
  3752. throw new \Exception("Error: Host name not supplied.");
  3753. }
  3754. $this->host = $host;
  3755. $this->ttl = $ttl;
  3756. $this->timeout = $timeout;
  3757. }
  3758. /**
  3759. * Set the ttl (in hops).
  3760. *
  3761. * @param int $ttl
  3762. * TTL in hops.
  3763. */
  3764. public function setTtl($ttl) {
  3765. $this->ttl = $ttl;
  3766. }
  3767. /**
  3768. * Get the ttl.
  3769. *
  3770. * @return int
  3771. * The current ttl for Ping.
  3772. */
  3773. public function getTtl() {
  3774. return $this->ttl;
  3775. }
  3776. /**
  3777. * Set the timeout.
  3778. *
  3779. * @param int $timeout
  3780. * Time to wait in seconds.
  3781. */
  3782. public function setTimeout($timeout) {
  3783. $this->timeout = $timeout;
  3784. }
  3785. /**
  3786. * Get the timeout.
  3787. *
  3788. * @return int
  3789. * Current timeout for Ping.
  3790. */
  3791. public function getTimeout() {
  3792. return $this->timeout;
  3793. }
  3794. /**
  3795. * Set the host.
  3796. *
  3797. * @param string $host
  3798. * Host name or IP address.
  3799. */
  3800. public function setHost($host) {
  3801. $this->host = $host;
  3802. }
  3803. /**
  3804. * Get the host.
  3805. *
  3806. * @return string
  3807. * The current hostname for Ping.
  3808. */
  3809. public function getHost() {
  3810. return $this->host;
  3811. }
  3812. /**
  3813. * Set the port (only used for fsockopen method).
  3814. *
  3815. * Since regular pings use ICMP and don't need to worry about the concept of
  3816. * 'ports', this is only used for the fsockopen method, which pings servers by
  3817. * checking port 80 (by default).
  3818. *
  3819. * @param int $port
  3820. * Port to use for fsockopen ping (defaults to 80 if not set).
  3821. */
  3822. public function setPort($port) {
  3823. $this->port = $port;
  3824. }
  3825. /**
  3826. * Get the port (only used for fsockopen method).
  3827. *
  3828. * @return int
  3829. * The port used by fsockopen pings.
  3830. */
  3831. public function getPort() {
  3832. return $this->port;
  3833. }
  3834. /**
  3835. * Return the command output when method=exec.
  3836. * @return string
  3837. */
  3838. public function getCommandOutput(){
  3839. return $this->commandOutput;
  3840. }
  3841. /**
  3842. * Matches an IP on command output and returns.
  3843. * @return string
  3844. */
  3845. public function getIpAddress() {
  3846. $out = array();
  3847. if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->commandOutput, $out)){
  3848. return $out[0];
  3849. }
  3850. return null;
  3851. }
  3852. /**
  3853. * Ping a host.
  3854. *
  3855. * @param string $method
  3856. * Method to use when pinging:
  3857. * - exec (default): Pings through the system ping command. Fast and
  3858. * robust, but a security risk if you pass through user-submitted data.
  3859. * - fsockopen: Pings a server on port 80.
  3860. * - socket: Creates a RAW network socket. Only usable in some
  3861. * environments, as creating a SOCK_RAW socket requires root privileges.
  3862. *
  3863. * @throws InvalidArgumentException if $method is not supported.
  3864. *
  3865. * @return mixed
  3866. * Latency as integer, in ms, if host is reachable or FALSE if host is down.
  3867. */
  3868. public function ping($method = 'exec') {
  3869. $latency = false;
  3870. switch ($method) {
  3871. case 'exec':
  3872. $latency = $this->pingExec();
  3873. break;
  3874. case 'fsockopen':
  3875. $latency = $this->pingFsockopen();
  3876. break;
  3877. case 'socket':
  3878. $latency = $this->pingSocket();
  3879. break;
  3880. default:
  3881. throw new \InvalidArgumentException('Unsupported ping method.');
  3882. }
  3883. // Return the latency.
  3884. return $latency;
  3885. }
  3886. /**
  3887. * The exec method uses the possibly insecure exec() function, which passes
  3888. * the input to the system. This is potentially VERY dangerous if you pass in
  3889. * any user-submitted data. Be SURE you sanitize your inputs!
  3890. *
  3891. * @return int
  3892. * Latency, in ms.
  3893. */
  3894. private function pingExec() {
  3895. $latency = false;
  3896. $ttl = escapeshellcmd($this->ttl);
  3897. $timeout = escapeshellcmd($this->timeout);
  3898. $host = escapeshellcmd($this->host);
  3899. // Exec string for Windows-based systems.
  3900. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  3901. // -n = number of pings; -i = ttl; -w = timeout (in milliseconds).
  3902. $exec_string = 'ping -n 1 -i ' . $ttl . ' -w ' . ($timeout * 1000) . ' ' . $host;
  3903. }
  3904. // Exec string for Darwin based systems (OS X).
  3905. else if(strtoupper(PHP_OS) === 'DARWIN') {
  3906. // -n = numeric output; -c = number of pings; -m = ttl; -t = timeout.
  3907. $exec_string = 'ping -n -c 1 -m ' . $ttl . ' -t ' . $timeout . ' ' . $host;
  3908. }
  3909. // Exec string for other UNIX-based systems (Linux).
  3910. else {
  3911. // -n = numeric output; -c = number of pings; -t = ttl; -W = timeout
  3912. $exec_string = 'ping -n -c 1 -t ' . $ttl . ' -W ' . $timeout . ' ' . $host . ' 2>&1';
  3913. }
  3914. exec($exec_string, $output, $return);
  3915. // Strip empty lines and reorder the indexes from 0 (to make results more
  3916. // uniform across OS versions).
  3917. $this->commandOutput = implode($output, '');
  3918. $output = array_values(array_filter($output));
  3919. // If the result line in the output is not empty, parse it.
  3920. if (!empty($output[1])) {
  3921. // Search for a 'time' value in the result line.
  3922. $response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)ms/", $output[1], $matches);
  3923. // If there's a result and it's greater than 0, return the latency.
  3924. if ($response > 0 && isset($matches['time'])) {
  3925. $latency = round($matches['time'], 2);
  3926. }
  3927. }
  3928. return $latency;
  3929. }
  3930. /**
  3931. * The fsockopen method simply tries to reach the host on a port. This method
  3932. * is often the fastest, but not necessarily the most reliable. Even if a host
  3933. * doesn't respond, fsockopen may still make a connection.
  3934. *
  3935. * @return int
  3936. * Latency, in ms.
  3937. */
  3938. private function pingFsockopen() {
  3939. $start = microtime(true);
  3940. // fsockopen prints a bunch of errors if a host is unreachable. Hide those
  3941. // irrelevant errors and deal with the results instead.
  3942. $fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  3943. if (!$fp) {
  3944. $latency = false;
  3945. }
  3946. else {
  3947. $latency = microtime(true) - $start;
  3948. $latency = round($latency * 1000, 2);
  3949. }
  3950. return $latency;
  3951. }
  3952. /**
  3953. * The socket method uses raw network packet data to try sending an ICMP ping
  3954. * packet to a server, then measures the response time. Using this method
  3955. * requires the script to be run with root privileges, though, so this method
  3956. * only works reliably on Windows systems and on Linux servers where the
  3957. * script is not being run as a web user.
  3958. *
  3959. * @return int
  3960. * Latency, in ms.
  3961. */
  3962. private function pingSocket() {
  3963. // Create a package.
  3964. $type = "\x08";
  3965. $code = "\x00";
  3966. $checksum = "\x00\x00";
  3967. $identifier = "\x00\x00";
  3968. $seq_number = "\x00\x00";
  3969. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  3970. // Calculate the checksum.
  3971. $checksum = $this->calculateChecksum($package);
  3972. // Finalize the package.
  3973. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  3974. // Create a socket, connect to server, then read socket and calculate.
  3975. if ($socket = socket_create(AF_INET, SOCK_RAW, 1)) {
  3976. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array(
  3977. 'sec' => 10,
  3978. 'usec' => 0,
  3979. ));
  3980. // Prevent errors from being printed when host is unreachable.
  3981. @socket_connect($socket, $this->host, null);
  3982. $start = microtime(true);
  3983. // Send the package.
  3984. @socket_send($socket, $package, strlen($package), 0);
  3985. if (socket_read($socket, 255) !== false) {
  3986. $latency = microtime(true) - $start;
  3987. $latency = round($latency * 1000, 2);
  3988. }
  3989. else {
  3990. $latency = false;
  3991. }
  3992. }
  3993. else {
  3994. $latency = false;
  3995. }
  3996. // Close the socket.
  3997. socket_close($socket);
  3998. return $latency;
  3999. }
  4000. /**
  4001. * Calculate a checksum.
  4002. *
  4003. * @param string $data
  4004. * Data for which checksum will be calculated.
  4005. *
  4006. * @return string
  4007. * Binary string checksum of $data.
  4008. */
  4009. private function calculateChecksum($data) {
  4010. if (strlen($data) % 2) {
  4011. $data .= "\x00";
  4012. }
  4013. $bit = unpack('n*', $data);
  4014. $sum = array_sum($bit);
  4015. while ($sum >> 16) {
  4016. $sum = ($sum >> 16) + ($sum & 0xffff);
  4017. }
  4018. return pack('n*', ~$sum);
  4019. }
  4020. }
  4021. function ping($pings, $type = "string") {
  4022. $ping = new Ping("");
  4023. $ping->setTtl(128);
  4024. $ping->setTimeout(2);
  4025. switch ($type){
  4026. case "array":
  4027. $results = [];
  4028. foreach ($pings as $k => $v) {
  4029. if(strpos($v, ':') !== false){
  4030. $domain = explode(':', $v)[0];
  4031. $port = explode(':', $v)[1];
  4032. $ping->setHost($domain);
  4033. $ping->setPort($port);
  4034. $latency = $ping->ping('fsockopen');
  4035. }else{
  4036. $ping->setHost($v);
  4037. $latency = $ping->ping();
  4038. }
  4039. if ($latency || $latency === 0) {
  4040. $results[$k] = $latency;
  4041. } else {
  4042. $results[$k] = 0;
  4043. }
  4044. }
  4045. break;
  4046. case "string":
  4047. if(strpos($pings, ':') !== false){
  4048. $domain = explode(':', $pings)[0];
  4049. $port = explode(':', $pings)[1];
  4050. $ping->setHost($domain);
  4051. $ping->setPort($port);
  4052. $latency = $ping->ping('fsockopen');
  4053. }else{
  4054. $ping->setHost($pings);
  4055. $latency = $ping->ping();
  4056. }
  4057. if ($latency || $latency === 0) {
  4058. $results = $latency;
  4059. } else {
  4060. $results = 0;
  4061. }
  4062. break;
  4063. }
  4064. return $results;
  4065. }
  4066. function getPing($url, $style, $refresh = null){
  4067. if(ping($url) !== 0){
  4068. $class = 'success';
  4069. if(!$refresh){
  4070. $class .= " animated slideInLeft";
  4071. }
  4072. }else{
  4073. $class = "warning";
  4074. if(!$refresh){
  4075. $class .= " animated flash loop-animation-timeout";
  4076. }
  4077. }
  4078. echo '<span class="badge ping-'.$class.'" style="position: absolute;z-index: 100;right: 5px; padding: 0px 0px;'.$style.';font-size: 10px;">&nbsp;</span>';
  4079. }
  4080. function speedTestData(){
  4081. $file_db = DATABASE_LOCATION."speedtest.db";
  4082. if(file_exists($file_db)){
  4083. $conn = new PDO("sqlite:$file_db") or die("1");
  4084. $result = $conn->query('SELECT * FROM speedtest_users');
  4085. $conn = null;
  4086. if (is_array($result) || is_object($result)){
  4087. foreach($result as $k => $v){
  4088. $return[$k] = $v;
  4089. }
  4090. return $return;
  4091. }
  4092. }
  4093. }
  4094. function speedTestDisplay($array, $output){
  4095. if (is_array($array) || is_object($array)){
  4096. if($output == "graph"){
  4097. $result = "Morris.Line({element: 'morris-line',data: [";
  4098. foreach($array as $k => $v){
  4099. $result .= "{ y: '".substr($v['timestamp'],0,10)."', a: ".$v['ul'].", b: ".$v['dl'].", c: ".$v['ping']." },";
  4100. }
  4101. $result .= "],xkey: 'y',ykeys: ['a', 'b', 'c'],labels: ['Upload', 'Download', 'Ping'],hideHover: 'auto',resize: true,lineColors: ['#63A8EB','#ccc','#000'] });";
  4102. }elseif($output == "table"){
  4103. $result = "";
  4104. foreach($array as $k => $v){
  4105. $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>";
  4106. }
  4107. }
  4108. return $result;
  4109. }
  4110. }
  4111. function buildMenuPhone($array){
  4112. if (is_array($array) || is_object($array)){
  4113. $result = '
  4114. <div class="content-box profile-sidebar box-shadow">
  4115. <img src="images/organizr-logo-h-d.png" width="100%" style="margin-top: -10px;">
  4116. <div class="profile-usermenu">
  4117. <ul class="nav" id="settings-list">
  4118. ';
  4119. foreach($array as $k => $v){
  4120. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4121. continue;
  4122. }
  4123. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4124. continue;
  4125. }
  4126. /*$result .= '
  4127. <li>
  4128. <a id="'.$v['id'].'" box="'.$v['box'].'">'.$v['name'].'
  4129. <span class="fa-stack fa-fw pull-right" style="margin-top: -5px;margin-right: -10px;">
  4130. <i class="fa fa-'.$v['icon_1'].' fa-stack-2x '.$v['color'].'" style="font-size:null;"></i>
  4131. <i class="fa fa-'.$v['icon_2'].' fa-stack-1x fa-inverse"></i>
  4132. </span>
  4133. </a>
  4134. </li>
  4135. ';*/
  4136. $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>';
  4137. }
  4138. $result .= '</ul></div></div>';
  4139. return $result;
  4140. }
  4141. }
  4142. function buildMenu($array){
  4143. if (is_array($array) || is_object($array)){
  4144. $result = '<div class="settingsList">';
  4145. foreach($array as $k => $v){
  4146. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4147. continue;
  4148. }
  4149. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4150. continue;
  4151. }
  4152. $result .= '
  4153. <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">
  4154. <i class="mdi mdi-'.$v['icon_1'].' fa-fw pull-left" style="padding-left: '.$v['padding'].'px;font-size: 30px"></i>
  4155. <p class="" style="text-align: center;direction: rtl;display:none;margin: 2px;"><strong>'.$v['name'].'</strong></p>
  4156. </button>
  4157. ';
  4158. }
  4159. $result .= '</div>';
  4160. return $result;
  4161. }
  4162. }
  4163. function requestInvite($email, $username){
  4164. //sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
  4165. //orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  4166. 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."));
  4167. }
  4168. function errormessage($msg) {
  4169. echo "<div style=\"margin-top: 50px;\">";
  4170. echo "<span style=\"color:#d89334;\">error </span>";
  4171. echo $msg;
  4172. echo "</div>";
  4173. }
  4174. function getOrgUsers(){
  4175. $file_db = DATABASE_LOCATION."users.db";
  4176. if(file_exists($file_db)){
  4177. $conn = new PDO("sqlite:$file_db") or die("1");
  4178. $result = $conn->query('SELECT * FROM users');
  4179. $conn = null;
  4180. if (is_array($result) || is_object($result)){
  4181. foreach($result as $k => $v){
  4182. $return[$v['username']] = $v['email'];
  4183. }
  4184. return $return;
  4185. }
  4186. }
  4187. }
  4188. function getEmails($type = 'org'){
  4189. if($type == 'plex'){
  4190. $emails = array_merge(libraryList()['both'],getOrgUsers());
  4191. }elseif($type == 'emby'){
  4192. $emails = getOrgUsers();
  4193. }else{
  4194. $emails = getOrgUsers();
  4195. }
  4196. return $emails;
  4197. }
  4198. function printEmails($emails){
  4199. $result = '';
  4200. foreach($emails as $k => $v){
  4201. $result .= '<option value="'.$v.'">'.$k.'</option>';
  4202. }
  4203. return $result;
  4204. }
  4205. function massEmail($to, $subject, $message){
  4206. if (!isset($GLOBALS['file_db'])) {
  4207. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  4208. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4209. }
  4210. 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);
  4211. }
  4212. function q2a($q){
  4213. if (is_array($q) || is_object($q)){
  4214. foreach ($q as $k => $v){
  4215. $a[$k] = $v;
  4216. }
  4217. if(!empty($a)){
  4218. return $a;
  4219. }
  4220. }
  4221. }
  4222. class Mobile_Detect
  4223. {
  4224. /**
  4225. * Mobile detection type.
  4226. *
  4227. * @deprecated since version 2.6.9
  4228. */
  4229. const DETECTION_TYPE_MOBILE = 'mobile';
  4230. /**
  4231. * Extended detection type.
  4232. *
  4233. * @deprecated since version 2.6.9
  4234. */
  4235. const DETECTION_TYPE_EXTENDED = 'extended';
  4236. /**
  4237. * A frequently used regular expression to extract version #s.
  4238. *
  4239. * @deprecated since version 2.6.9
  4240. */
  4241. const VER = '([\w._\+]+)';
  4242. /**
  4243. * Top-level device.
  4244. */
  4245. const MOBILE_GRADE_A = 'A';
  4246. /**
  4247. * Mid-level device.
  4248. */
  4249. const MOBILE_GRADE_B = 'B';
  4250. /**
  4251. * Low-level device.
  4252. */
  4253. const MOBILE_GRADE_C = 'C';
  4254. /**
  4255. * Stores the version number of the current release.
  4256. */
  4257. const VERSION = '2.8.26';
  4258. /**
  4259. * A type for the version() method indicating a string return value.
  4260. */
  4261. const VERSION_TYPE_STRING = 'text';
  4262. /**
  4263. * A type for the version() method indicating a float return value.
  4264. */
  4265. const VERSION_TYPE_FLOAT = 'float';
  4266. /**
  4267. * A cache for resolved matches
  4268. * @var array
  4269. */
  4270. protected $cache = array();
  4271. /**
  4272. * The User-Agent HTTP header is stored in here.
  4273. * @var string
  4274. */
  4275. protected $userAgent = null;
  4276. /**
  4277. * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.
  4278. * @var array
  4279. */
  4280. protected $httpHeaders = array();
  4281. /**
  4282. * CloudFront headers. E.g. CloudFront-Is-Desktop-Viewer, CloudFront-Is-Mobile-Viewer & CloudFront-Is-Tablet-Viewer.
  4283. * @var array
  4284. */
  4285. protected $cloudfrontHeaders = array();
  4286. /**
  4287. * The matching Regex.
  4288. * This is good for debug.
  4289. * @var string
  4290. */
  4291. protected $matchingRegex = null;
  4292. /**
  4293. * The matches extracted from the regex expression.
  4294. * This is good for debug.
  4295. * @var string
  4296. */
  4297. protected $matchesArray = null;
  4298. /**
  4299. * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.
  4300. *
  4301. * @deprecated since version 2.6.9
  4302. *
  4303. * @var string
  4304. */
  4305. protected $detectionType = self::DETECTION_TYPE_MOBILE;
  4306. /**
  4307. * HTTP headers that trigger the 'isMobile' detection
  4308. * to be true.
  4309. *
  4310. * @var array
  4311. */
  4312. protected static $mobileHeaders = array(
  4313. 'HTTP_ACCEPT' => array('matches' => array(
  4314. // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
  4315. 'application/x-obml2d',
  4316. // BlackBerry devices.
  4317. 'application/vnd.rim.html',
  4318. 'text/vnd.wap.wml',
  4319. 'application/vnd.wap.xhtml+xml'
  4320. )),
  4321. 'HTTP_X_WAP_PROFILE' => null,
  4322. 'HTTP_X_WAP_CLIENTID' => null,
  4323. 'HTTP_WAP_CONNECTION' => null,
  4324. 'HTTP_PROFILE' => null,
  4325. // Reported by Opera on Nokia devices (eg. C3).
  4326. 'HTTP_X_OPERAMINI_PHONE_UA' => null,
  4327. 'HTTP_X_NOKIA_GATEWAY_ID' => null,
  4328. 'HTTP_X_ORANGE_ID' => null,
  4329. 'HTTP_X_VODAFONE_3GPDPCONTEXT' => null,
  4330. 'HTTP_X_HUAWEI_USERID' => null,
  4331. // Reported by Windows Smartphones.
  4332. 'HTTP_UA_OS' => null,
  4333. // Reported by Verizon, Vodafone proxy system.
  4334. 'HTTP_X_MOBILE_GATEWAY' => null,
  4335. // Seen this on HTC Sensation. SensationXE_Beats_Z715e.
  4336. 'HTTP_X_ATT_DEVICEID' => null,
  4337. // Seen this on a HTC.
  4338. 'HTTP_UA_CPU' => array('matches' => array('ARM')),
  4339. );
  4340. /**
  4341. * List of mobile devices (phones).
  4342. *
  4343. * @var array
  4344. */
  4345. protected static $phoneDevices = array(
  4346. 'iPhone' => '\biPhone\b|\biPod\b', // |\biTunes
  4347. 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+',
  4348. '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',
  4349. 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 6',
  4350. // @todo: Is 'Dell Streak' a tablet or a phone? ;)
  4351. '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',
  4352. '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',
  4353. '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',
  4354. '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)',
  4355. 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|LT26w|SonyEricssonMT27i|C5303|C6902|C6903|C6906|C6943|D2533',
  4356. 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile',
  4357. 'NokiaLumia' => 'Lumia [0-9]{3,4}',
  4358. // http://www.micromaxinfo.com/mobiles/smartphones
  4359. // Added because the codes might conflict with Acer Tablets.
  4360. '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',
  4361. // @todo Complete the regex.
  4362. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ;
  4363. 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
  4364. // http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
  4365. // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android.
  4366. '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',
  4367. // http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones.
  4368. 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250',
  4369. // http://fr.wikomobile.com
  4370. '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',
  4371. 'iMobile' => 'i-mobile (IQ|i-STYLE|idea|ZAA|Hitz)',
  4372. // Added simvalley mobile just for fun. They have some interesting devices.
  4373. // http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html
  4374. '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',
  4375. // Wolfgang - a brand that is sold by Aldi supermarkets.
  4376. // http://www.wolfgangmobile.com/
  4377. 'Wolfgang' => 'AT-B24D|AT-AS50HD|AT-AS40W|AT-AS55HD|AT-AS45q2|AT-B26D|AT-AS50Q',
  4378. 'Alcatel' => 'Alcatel',
  4379. 'Nintendo' => 'Nintendo 3DS',
  4380. // http://en.wikipedia.org/wiki/Amoi
  4381. 'Amoi' => 'Amoi',
  4382. // http://en.wikipedia.org/wiki/INQ
  4383. 'INQ' => 'INQ',
  4384. // @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039
  4385. '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',
  4386. );
  4387. /**
  4388. * List of tablet devices.
  4389. *
  4390. * @var array
  4391. */
  4392. protected static $tabletDevices = array(
  4393. // @todo: check for mobile friendly emails topic.
  4394. 'iPad' => 'iPad|iPad.*Mobile',
  4395. // Removed |^.*Android.*Nexus(?!(?:Mobile).)*$
  4396. // @see #442
  4397. 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)',
  4398. '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.
  4399. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
  4400. '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)',
  4401. // Only the Surface tablets with Windows RT are considered mobile.
  4402. // http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx
  4403. 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;.*(Tablet|ARMBJS)',
  4404. // http://shopping1.hp.com/is-bin/INTERSHOP.enfinity/WFS/WW-USSMBPublicStore-Site/en_US/-/USD/ViewStandardCatalog-Browse?CatalogCategoryID=JfIQ7EN5lqMAAAEyDcJUDwMT
  4405. 'HPTablet' => 'HP Slate (7|8|10)|HP ElitePad 900|hp-tablet|EliteBook.*Touch|HP 8|Slate 21|HP SlateBook 10',
  4406. // Watch out for PadFone, see #132.
  4407. // http://www.asus.com/de/Tablets_Mobile/Memo_Pad_Products/
  4408. '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',
  4409. 'BlackBerryTablet' => 'PlayBook|RIM Tablet',
  4410. 'HTCtablet' => 'HTC_Flyer_P512|HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200|PG09410',
  4411. 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617',
  4412. 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2',
  4413. // http://www.acer.ro/ac/ro/RO/content/drivers
  4414. // http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer)
  4415. // http://us.acer.com/ac/en/US/content/group/tablets
  4416. // http://www.acer.de/ac/de/DE/content/models/tablets/
  4417. // Can conflict with Micromax and Motorola phones codes.
  4418. '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',
  4419. // http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/
  4420. // http://us.toshiba.com/tablets/tablet-finder
  4421. // http://www.toshiba.co.jp/regza/tablet/
  4422. 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO',
  4423. // http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html
  4424. // http://www.lg.com/us/tablets
  4425. 'LGTablet' => '\bL-06C|LG-V909|LG-V900|LG-V700|LG-V510|LG-V500|LG-V410|LG-V400|LG-VK810\b',
  4426. 'FujitsuTablet' => 'Android.*\b(F-01D|F-02F|F-05E|F-10D|M532|Q572)\b',
  4427. // Prestigio Tablets http://www.prestigio.com/support
  4428. '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',
  4429. // http://support.lenovo.com/en_GB/downloads/default.page?#
  4430. '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|)',
  4431. // http://www.dell.com/support/home/us/en/04/Products/tab_mob/tablets
  4432. 'DellTablet' => 'Venue 11|Venue 8|Venue 7|Dell Streak 10|Dell Streak 7',
  4433. // http://www.yarvik.com/en/matrix/tablets/
  4434. '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',
  4435. 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB',
  4436. 'ArnovaTablet' => '97G4|AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT|AN9G2',
  4437. // http://www.intenso.de/kategorie_en.php?kategorie=33
  4438. // @todo: http://www.nbhkdz.com/read/b8e64202f92a2df129126bff.html - investigate
  4439. 'IntensoTablet' => 'INM8002KP|INM1010FP|INM805ND|Intenso Tab|TAB1004',
  4440. // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/
  4441. 'IRUTablet' => 'M702pro',
  4442. 'MegafonTablet' => 'MegaFon V9|\bZTE V9\b|Android.*\bMT7A\b',
  4443. // http://www.e-boda.ro/tablete-pc.html
  4444. 'EbodaTablet' => 'E-Boda (Supreme|Impresspeed|Izzycomm|Essential)',
  4445. // http://www.allview.ro/produse/droseries/lista-tablete-pc/
  4446. 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)',
  4447. // http://wiki.archosfans.com/index.php?title=Main_Page
  4448. // @note Rewrite the regex format after we add more UAs.
  4449. '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',
  4450. // http://www.ainol.com/plugin.php?identifier=ainol&module=product
  4451. 'AinolTablet' => 'NOVO7|NOVO8|NOVO10|Novo7Aurora|Novo7Basic|NOVO7PALADIN|novo9-Spark',
  4452. 'NokiaLumiaTablet' => 'Lumia 2520',
  4453. // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER
  4454. // Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser
  4455. // http://www.sony.jp/support/tablet/
  4456. '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',
  4457. // 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
  4458. 'PhilipsTablet' => '\b(PI2010|PI3000|PI3100|PI3105|PI3110|PI3205|PI3210|PI3900|PI4010|PI7000|PI7100)\b',
  4459. // db + http://www.cube-tablet.com/buy-products.html
  4460. 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT',
  4461. // http://www.cobyusa.com/?p=pcat&pcat_id=3001
  4462. 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010',
  4463. // http://www.match.net.cn/products.asp
  4464. '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',
  4465. // http://www.msi.com/support
  4466. // @todo Research the Windows Tablets.
  4467. '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',
  4468. // @todo http://www.kyoceramobile.com/support/drivers/
  4469. // 'KyoceraTablet' => null,
  4470. // @todo http://intexuae.com/index.php/category/mobile-devices/tablets-products/
  4471. // 'IntextTablet' => null,
  4472. // http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets)
  4473. // http://www.imp3.net/14/show.php?itemid=20454
  4474. 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)',
  4475. // http://www.rock-chips.com/index.php?do=prod&pid=2
  4476. 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A',
  4477. // http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/
  4478. 'FlyTablet' => 'IQ310|Fly Vision',
  4479. // http://www.bqreaders.com/gb/tablets-prices-sale.html
  4480. 'bqTablet' => 'Android.*(bq)?.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris [E|M]10)|Maxwell.*Lite|Maxwell.*Plus',
  4481. // http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
  4482. // http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
  4483. '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',
  4484. // Nec or Medias Tab
  4485. 'NecTablet' => '\bN-06D|\bN-08D',
  4486. // Pantech Tablets: http://www.pantechusa.com/phones/
  4487. 'PantechTablet' => 'Pantech.*P4100',
  4488. // Broncho Tablets: http://www.broncho.cn/ (hard to find)
  4489. 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)',
  4490. // http://versusuk.com/support.html
  4491. 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b',
  4492. // http://www.zync.in/index.php/our-products/tablet-phablets
  4493. 'ZyncTablet' => 'z1000|Z99 2G|z99|z930|z999|z990|z909|Z919|z900',
  4494. // http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/
  4495. 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA',
  4496. // https://www.nabitablet.com/
  4497. 'NabiTablet' => 'Android.*\bNabi',
  4498. 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build',
  4499. // French Danew Tablets http://www.danew.com/produits-tablette.php
  4500. 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b',
  4501. // Texet Tablets and Readers http://www.texet.ru/tablet/
  4502. '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',
  4503. // Avoid detecting 'PLAYSTATION 3' as mobile.
  4504. 'PlaystationTablet' => 'Playstation.*(Portable|Vita)',
  4505. // http://www.trekstor.de/surftabs.html
  4506. 'TrekstorTablet' => 'ST10416-1|VT10416-1|ST70408-1|ST702xx-1|ST702xx-2|ST80208|ST97216|ST70104-2|VT10416-2|ST10216-2A|SurfTab',
  4507. // http://www.pyleaudio.com/Products.aspx?%2fproducts%2fPersonal-Electronics%2fTablets
  4508. 'PyleAudioTablet' => '\b(PTBL10CEU|PTBL10C|PTBL72BC|PTBL72BCEU|PTBL7CEU|PTBL7C|PTBL92BC|PTBL92BCEU|PTBL9CEU|PTBL9CUK|PTBL9C)\b',
  4509. // http://www.advandigital.com/index.php?link=content-product&jns=JP001
  4510. // because of the short codenames we have to include whitespaces to reduce the possible conflicts.
  4511. '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 ',
  4512. // http://www.danytech.com/category/tablet-pc
  4513. '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',
  4514. // http://www.galapad.net/product.html
  4515. 'GalapadTablet' => 'Android.*\bG1\b',
  4516. // http://www.micromaxinfo.com/tablet/funbook
  4517. 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b',
  4518. // http://www.karbonnmobiles.com/products_tablet.php
  4519. 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b',
  4520. // http://www.myallfine.com/Products.asp
  4521. 'AllFineTablet' => 'Fine7 Genius|Fine7 Shine|Fine7 Air|Fine8 Style|Fine9 More|Fine10 Joy|Fine11 Wide',
  4522. // http://www.proscanvideo.com/products-search.asp?itemClass=TABLET&itemnmbr=
  4523. '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',
  4524. // http://www.yonesnav.com/products/products.php
  4525. 'YONESTablet' => 'BQ1078|BC1003|BC1077|RK9702|BC9730|BC9001|IT9001|BC7008|BC7010|BC708|BC728|BC7012|BC7030|BC7027|BC7026',
  4526. // http://www.cjshowroom.com/eproducts.aspx?classcode=004001001
  4527. // China manufacturer makes tablets for different small brands (eg. http://www.zeepad.net/index.html)
  4528. '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',
  4529. // http://www.gloryunion.cn/products.asp
  4530. // http://www.allwinnertech.com/en/apply/mobile.html
  4531. // http://www.ptcl.com.pk/pd_content.php?pd_id=284 (EVOTAB)
  4532. // @todo: Softwiner tablets?
  4533. // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions.
  4534. '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
  4535. // http://www.pointofview-online.com/showroom.php?shop_mode=product_listing&category_id=118
  4536. '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',
  4537. // http://www.overmax.pl/pl/katalog-produktow,p8/tablety,c14/
  4538. // @todo: add more tests.
  4539. 'OvermaxTablet' => 'OV-(SteelCore|NewBase|Basecore|Baseone|Exellen|Quattor|EduTab|Solution|ACTION|BasicTab|TeddyTab|MagicTab|Stream|TB-08|TB-09)',
  4540. // http://hclmetablet.com/India/index.php
  4541. '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',
  4542. // http://www.edigital.hu/Tablet_es_e-book_olvaso/Tablet-c18385.html
  4543. 'DPSTablet' => 'DPS Dream 9|DPS Dual 7',
  4544. // http://www.visture.com/index.asp
  4545. 'VistureTablet' => 'V97 HD|i75 3G|Visture V4( HD)?|Visture V5( HD)?|Visture V10',
  4546. // http://www.mijncresta.nl/tablet
  4547. 'CrestaTablet' => 'CTP(-)?810|CTP(-)?818|CTP(-)?828|CTP(-)?838|CTP(-)?888|CTP(-)?978|CTP(-)?980|CTP(-)?987|CTP(-)?988|CTP(-)?989',
  4548. // MediaTek - http://www.mediatek.com/_en/01_products/02_proSys.php?cata_sn=1&cata1_sn=1&cata2_sn=309
  4549. 'MediatekTablet' => '\bMT8125|MT8389|MT8135|MT8377\b',
  4550. // Concorde tab
  4551. 'ConcordeTablet' => 'Concorde([ ]+)?Tab|ConCorde ReadMan',
  4552. // GoClever Tablets - http://www.goclever.com/uk/products,c1/tablet,c5/
  4553. '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',
  4554. // Modecom Tablets - http://www.modecom.eu/tablets/portal/
  4555. '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',
  4556. // Vonino Tablets - http://www.vonino.eu/tablets
  4557. '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',
  4558. // ECS Tablets - http://www.ecs.com.tw/ECSWebSite/Product/Product_Tablet_List.aspx?CategoryID=14&MenuID=107&childid=M_107&LanID=0
  4559. 'ECSTablet' => 'V07OT2|TM105A|S10OT1|TR10CS1',
  4560. // Storex Tablets - http://storex.fr/espace_client/support.html
  4561. // @note: no need to add all the tablet codes since they are guided by the first regex.
  4562. 'StorexTablet' => 'eZee[_\']?(Tab|Go)[0-9]+|TabLC7|Looney Tunes Tab',
  4563. // Generic Vodafone tablets.
  4564. 'VodafoneTablet' => 'SmartTab([ ]+)?[0-9]+|SmartTabII10|SmartTabII7|VF-1497',
  4565. // French tablets - Essentiel B http://www.boulanger.fr/tablette_tactile_e-book/tablette_tactile_essentiel_b/cl_68908.htm?multiChoiceToDelete=brand&mc_brand=essentielb
  4566. // Aka: http://www.essentielb.fr/
  4567. 'EssentielBTablet' => 'Smart[ \']?TAB[ ]+?[0-9]+|Family[ \']?TAB2',
  4568. // Ross & Moor - http://ross-moor.ru/
  4569. 'RossMoorTablet' => 'RM-790|RM-997|RMD-878G|RMD-974R|RMT-705A|RMT-701|RME-601|RMT-501|RMT-711',
  4570. // i-mobile http://product.i-mobilephone.com/Mobile_Device
  4571. 'iMobileTablet' => 'i-mobile i-note',
  4572. // http://www.tolino.de/de/vergleichen/
  4573. 'TolinoTablet' => 'tolino tab [0-9.]+|tolino shine',
  4574. // AudioSonic - a Kmart brand
  4575. // 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
  4576. 'AudioSonicTablet' => '\bC-22Q|T7-QC|T-17B|T-17P\b',
  4577. // AMPE Tablets - http://www.ampe.com.my/product-category/tablets/
  4578. // @todo: add them gradually to avoid conflicts.
  4579. 'AMPETablet' => 'Android.* A78 ',
  4580. // Skk Mobile - http://skkmobile.com.ph/product_tablets.php
  4581. 'SkkTablet' => 'Android.* (SKYPAD|PHOENIX|CYCLOPS)',
  4582. // Tecno Mobile (only tablet) - http://www.tecno-mobile.com/index.php/product?filterby=smart&list_order=all&page=1
  4583. 'TecnoTablet' => 'TECNO P9',
  4584. // JXD (consoles & tablets) - http://jxd.hk/products.asp?selectclassid=009008&clsid=3
  4585. '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',
  4586. // i-Joy tablets - http://www.i-joy.es/en/cat/products/tablets/
  4587. '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)',
  4588. // http://www.intracon.eu/tablet
  4589. 'FX2Tablet' => 'FX2 PAD7|FX2 PAD10',
  4590. // http://www.xoro.de/produkte/
  4591. // @note: Might be the same brand with 'Simply tablets'
  4592. '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',
  4593. // http://www1.viewsonic.com/products/computing/tablets/
  4594. 'ViewsonicTablet' => 'ViewPad 10pi|ViewPad 10e|ViewPad 10s|ViewPad E72|ViewPad7|ViewPad E100|ViewPad 7e|ViewSonic VB733|VB100a',
  4595. // http://www.odys.de/web/internet-tablet_en.html
  4596. 'OdysTablet' => 'LOOX|XENO10|ODYS[ -](Space|EVO|Xpress|NOON)|\bXELIO\b|Xelio10Pro|XELIO7PHONETAB|XELIO10EXTREME|XELIOPT2|NEO_QUAD10',
  4597. // http://www.captiva-power.de/products.html#tablets-en
  4598. 'CaptivaTablet' => 'CAPTIVA PAD',
  4599. // IconBIT - http://www.iconbit.com/products/tablets/
  4600. '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',
  4601. // http://www.teclast.com/topic.php?channelID=70&topicID=140&pid=63
  4602. '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',
  4603. // Onda - http://www.onda-tablet.com/buy-android-onda.html?dir=desc&limit=all&order=price
  4604. '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]+',
  4605. 'JaytechTablet' => 'TPC-PA762',
  4606. 'BlaupunktTablet' => 'Endeavour 800NG|Endeavour 1010',
  4607. // http://www.digma.ru/support/download/
  4608. // @todo: Ebooks also (if requested)
  4609. 'DigmaTablet' => '\b(iDx10|iDx9|iDx8|iDx7|iDxD7|iDxD8|iDsQ8|iDsQ7|iDsQ8|iDsD10|iDnD7|3TS804H|iDsQ11|iDj7|iDs10)\b',
  4610. // http://www.evolioshop.com/ro/tablete-pc.html
  4611. // http://www.evolio.ro/support/downloads_static.html?cat=2
  4612. // @todo: Research some more
  4613. 'EvolioTablet' => 'ARIA_Mini_wifi|Aria[ _]Mini|Evolio X10|Evolio X7|Evolio X8|\bEvotab\b|\bNeura\b',
  4614. // @todo http://www.lavamobiles.com/tablets-data-cards
  4615. 'LavaTablet' => 'QPAD E704|\bIvoryS\b|E-TAB IVORY|\bE-TAB\b',
  4616. // http://www.breezetablet.com/
  4617. 'AocTablet' => 'MW0811|MW0812|MW0922|MTK8382|MW1031|MW0831|MW0821|MW0931|MW0712',
  4618. // http://www.mpmaneurope.com/en/products/internet-tablets-14/android-tablets-14/
  4619. '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',
  4620. // https://www.celkonmobiles.com/?_a=categoryphones&sid=2
  4621. 'CelkonTablet' => 'CT695|CT888|CT[\s]?910|CT7 Tab|CT9 Tab|CT3 Tab|CT2 Tab|CT1 Tab|C820|C720|\bCT-1\b',
  4622. // http://www.wolderelectronics.com/productos/manuales-y-guias-rapidas/categoria-2-miTab
  4623. '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',
  4624. // http://www.mi.com/en
  4625. 'MiTablet' => '\bMI PAD\b|\bHM NOTE 1W\b',
  4626. // http://www.nbru.cn/index.html
  4627. 'NibiruTablet' => 'Nibiru M1|Nibiru Jupiter One',
  4628. // http://navroad.com/products/produkty/tablety/
  4629. // http://navroad.com/products/produkty/tablety/
  4630. 'NexoTablet' => 'NEXO NOVA|NEXO 10|NEXO AVIO|NEXO FREE|NEXO GO|NEXO EVO|NEXO 3G|NEXO SMART|NEXO KIDDO|NEXO MOBI',
  4631. // http://leader-online.com/new_site/product-category/tablets/
  4632. // http://www.leader-online.net.au/List/Tablet
  4633. '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',
  4634. // http://www.datawind.com/ubislate/
  4635. 'UbislateTablet' => 'UbiSlate[\s]?7C',
  4636. // http://www.pocketbook-int.com/ru/support
  4637. 'PocketBookTablet' => 'Pocketbook',
  4638. // http://www.kocaso.com/product_tablet.html
  4639. 'KocasoTablet' => '\b(TB-1207)\b',
  4640. // http://global.hisense.com/product/asia/tablet/Sero7/201412/t20141215_91832.htm
  4641. 'HisenseTablet' => '\b(F5281|E2371)\b',
  4642. // http://www.tesco.com/direct/hudl/
  4643. 'Hudl' => 'Hudl HT7S3|Hudl 2',
  4644. // http://www.telstra.com.au/home-phone/thub-2/
  4645. 'TelstraTablet' => 'T-Hub2',
  4646. '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'
  4647. );
  4648. /**
  4649. * List of mobile Operating Systems.
  4650. *
  4651. * @var array
  4652. */
  4653. protected static $operatingSystems = array(
  4654. 'AndroidOS' => 'Android',
  4655. 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os',
  4656. 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
  4657. 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
  4658. // @reference: http://en.wikipedia.org/wiki/Windows_Mobile
  4659. 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;',
  4660. // @reference: http://en.wikipedia.org/wiki/Windows_Phone
  4661. // http://wifeng.cn/?r=blog&a=view&id=106
  4662. // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx
  4663. // http://msdn.microsoft.com/library/ms537503.aspx
  4664. // https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
  4665. 'WindowsPhoneOS' => 'Windows Phone 10.0|Windows Phone 8.1|Windows Phone 8.0|Windows Phone OS|XBLWP7|ZuneWP7|Windows NT 6.[23]; ARM;',
  4666. 'iOS' => '\biPhone.*Mobile|\biPod|\biPad',
  4667. // http://en.wikipedia.org/wiki/MeeGo
  4668. // @todo: research MeeGo in UAs
  4669. 'MeeGoOS' => 'MeeGo',
  4670. // http://en.wikipedia.org/wiki/Maemo
  4671. // @todo: research Maemo in UAs
  4672. 'MaemoOS' => 'Maemo',
  4673. 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135
  4674. 'webOS' => 'webOS|hpwOS',
  4675. 'badaOS' => '\bBada\b',
  4676. 'BREWOS' => 'BREW',
  4677. );
  4678. /**
  4679. * List of mobile User Agents.
  4680. *
  4681. * IMPORTANT: This is a list of only mobile browsers.
  4682. * Mobile Detect 2.x supports only mobile browsers,
  4683. * it was never designed to detect all browsers.
  4684. * The change will come in 2017 in the 3.x release for PHP7.
  4685. *
  4686. * @var array
  4687. */
  4688. protected static $browsers = array(
  4689. //'Vivaldi' => 'Vivaldi',
  4690. // @reference: https://developers.google.com/chrome/mobile/docs/user-agent
  4691. 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?',
  4692. 'Dolfin' => '\bDolfin\b',
  4693. 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+|Coast/[0-9.]+',
  4694. 'Skyfire' => 'Skyfire',
  4695. 'Edge' => 'Mobile Safari/[.0-9]* Edge',
  4696. 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+
  4697. 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS',
  4698. 'Bolt' => 'bolt',
  4699. 'TeaShark' => 'teashark',
  4700. 'Blazer' => 'Blazer',
  4701. // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3
  4702. 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari',
  4703. // http://en.wikipedia.org/wiki/Midori_(web_browser)
  4704. //'Midori' => 'midori',
  4705. //'Tizen' => 'Tizen',
  4706. 'UCBrowser' => 'UC.*Browser|UCWEB',
  4707. 'baiduboxapp' => 'baiduboxapp',
  4708. 'baidubrowser' => 'baidubrowser',
  4709. // https://github.com/serbanghita/Mobile-Detect/issues/7
  4710. 'DiigoBrowser' => 'DiigoBrowser',
  4711. // http://www.puffinbrowser.com/index.php
  4712. 'Puffin' => 'Puffin',
  4713. // http://mercury-browser.com/index.html
  4714. 'Mercury' => '\bMercury\b',
  4715. // http://en.wikipedia.org/wiki/Obigo_Browser
  4716. 'ObigoBrowser' => 'Obigo',
  4717. // http://en.wikipedia.org/wiki/NetFront
  4718. 'NetFront' => 'NF-Browser',
  4719. // @reference: http://en.wikipedia.org/wiki/Minimo
  4720. // http://en.wikipedia.org/wiki/Vision_Mobile_Browser
  4721. 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger',
  4722. // @reference: https://en.wikipedia.org/wiki/Pale_Moon_(web_browser)
  4723. 'PaleMoon' => 'Android.*PaleMoon|Mobile.*PaleMoon',
  4724. );
  4725. /**
  4726. * Utilities.
  4727. *
  4728. * @var array
  4729. */
  4730. protected static $utilities = array(
  4731. // Experimental. When a mobile device wants to switch to 'Desktop Mode'.
  4732. // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/
  4733. // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011
  4734. // https://developers.facebook.com/docs/sharing/best-practices
  4735. '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',
  4736. 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2',
  4737. 'DesktopMode' => 'WPDesktop',
  4738. 'TV' => 'SonyDTV|HbbTV', // experimental
  4739. 'WebKit' => '(webkit)[ /]([\w.]+)',
  4740. // @todo: Include JXD consoles.
  4741. 'Console' => '\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b',
  4742. 'Watch' => 'SM-V700',
  4743. );
  4744. /**
  4745. * All possible HTTP headers that represent the
  4746. * User-Agent string.
  4747. *
  4748. * @var array
  4749. */
  4750. protected static $uaHttpHeaders = array(
  4751. // The default User-Agent string.
  4752. 'HTTP_USER_AGENT',
  4753. // Header can occur on devices using Opera Mini.
  4754. 'HTTP_X_OPERAMINI_PHONE_UA',
  4755. // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
  4756. 'HTTP_X_DEVICE_USER_AGENT',
  4757. 'HTTP_X_ORIGINAL_USER_AGENT',
  4758. 'HTTP_X_SKYFIRE_PHONE',
  4759. 'HTTP_X_BOLT_PHONE_UA',
  4760. 'HTTP_DEVICE_STOCK_UA',
  4761. 'HTTP_X_UCBROWSER_DEVICE_UA'
  4762. );
  4763. /**
  4764. * The individual segments that could exist in a User-Agent string. VER refers to the regular
  4765. * expression defined in the constant self::VER.
  4766. *
  4767. * @var array
  4768. */
  4769. protected static $properties = array(
  4770. // Build
  4771. 'Mobile' => 'Mobile/[VER]',
  4772. 'Build' => 'Build/[VER]',
  4773. 'Version' => 'Version/[VER]',
  4774. 'VendorID' => 'VendorID/[VER]',
  4775. // Devices
  4776. 'iPad' => 'iPad.*CPU[a-z ]+[VER]',
  4777. 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]',
  4778. 'iPod' => 'iPod.*CPU[a-z ]+[VER]',
  4779. //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'),
  4780. 'Kindle' => 'Kindle/[VER]',
  4781. // Browser
  4782. 'Chrome' => array('Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'),
  4783. 'Coast' => array('Coast/[VER]'),
  4784. 'Dolfin' => 'Dolfin/[VER]',
  4785. // @reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
  4786. 'Firefox' => array('Firefox/[VER]', 'FxiOS/[VER]'),
  4787. 'Fennec' => 'Fennec/[VER]',
  4788. // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
  4789. // https://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
  4790. 'Edge' => 'Edge/[VER]',
  4791. 'IE' => array('IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'Trident/[0-9.]+;.*rv:[VER]'),
  4792. // http://en.wikipedia.org/wiki/NetFront
  4793. 'NetFront' => 'NetFront/[VER]',
  4794. 'NokiaBrowser' => 'NokiaBrowser/[VER]',
  4795. 'Opera' => array( ' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]' ),
  4796. 'Opera Mini' => 'Opera Mini/[VER]',
  4797. 'Opera Mobi' => 'Version/[VER]',
  4798. 'UC Browser' => 'UC Browser[VER]',
  4799. 'MQQBrowser' => 'MQQBrowser/[VER]',
  4800. 'MicroMessenger' => 'MicroMessenger/[VER]',
  4801. 'baiduboxapp' => 'baiduboxapp/[VER]',
  4802. 'baidubrowser' => 'baidubrowser/[VER]',
  4803. 'SamsungBrowser' => 'SamsungBrowser/[VER]',
  4804. 'Iron' => 'Iron/[VER]',
  4805. // @note: Safari 7534.48.3 is actually Version 5.1.
  4806. // @note: On BlackBerry the Version is overwriten by the OS.
  4807. 'Safari' => array( 'Version/[VER]', 'Safari/[VER]' ),
  4808. 'Skyfire' => 'Skyfire/[VER]',
  4809. 'Tizen' => 'Tizen/[VER]',
  4810. 'Webkit' => 'webkit[ /][VER]',
  4811. 'PaleMoon' => 'PaleMoon/[VER]',
  4812. // Engine
  4813. 'Gecko' => 'Gecko/[VER]',
  4814. 'Trident' => 'Trident/[VER]',
  4815. 'Presto' => 'Presto/[VER]',
  4816. 'Goanna' => 'Goanna/[VER]',
  4817. // OS
  4818. 'iOS' => ' \bi?OS\b [VER][ ;]{1}',
  4819. 'Android' => 'Android [VER]',
  4820. 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'),
  4821. 'BREW' => 'BREW [VER]',
  4822. 'Java' => 'Java/[VER]',
  4823. // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx
  4824. // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases
  4825. 'Windows Phone OS' => array( 'Windows Phone OS [VER]', 'Windows Phone [VER]'),
  4826. 'Windows Phone' => 'Windows Phone [VER]',
  4827. 'Windows CE' => 'Windows CE/[VER]',
  4828. // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd
  4829. 'Windows NT' => 'Windows NT [VER]',
  4830. 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'),
  4831. 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'),
  4832. );
  4833. /**
  4834. * Construct an instance of this class.
  4835. *
  4836. * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored.
  4837. * If left empty, will use the global _SERVER['HTTP_*'] vars instead.
  4838. * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
  4839. * from the $headers array instead.
  4840. */
  4841. public function __construct(
  4842. array $headers = null,
  4843. $userAgent = null
  4844. ) {
  4845. $this->setHttpHeaders($headers);
  4846. $this->setUserAgent($userAgent);
  4847. }
  4848. /**
  4849. * Get the current script version.
  4850. * This is useful for the demo.php file,
  4851. * so people can check on what version they are testing
  4852. * for mobile devices.
  4853. *
  4854. * @return string The version number in semantic version format.
  4855. */
  4856. public static function getScriptVersion()
  4857. {
  4858. return self::VERSION;
  4859. }
  4860. /**
  4861. * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
  4862. *
  4863. * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
  4864. * the headers. The default null is left for backwards compatibility.
  4865. */
  4866. public function setHttpHeaders($httpHeaders = null)
  4867. {
  4868. // use global _SERVER if $httpHeaders aren't defined
  4869. if (!is_array($httpHeaders) || !count($httpHeaders)) {
  4870. $httpHeaders = $_SERVER;
  4871. }
  4872. // clear existing headers
  4873. $this->httpHeaders = array();
  4874. // Only save HTTP headers. In PHP land, that means only _SERVER vars that
  4875. // start with HTTP_.
  4876. foreach ($httpHeaders as $key => $value) {
  4877. if (substr($key, 0, 5) === 'HTTP_') {
  4878. $this->httpHeaders[$key] = $value;
  4879. }
  4880. }
  4881. // In case we're dealing with CloudFront, we need to know.
  4882. $this->setCfHeaders($httpHeaders);
  4883. }
  4884. /**
  4885. * Retrieves the HTTP headers.
  4886. *
  4887. * @return array
  4888. */
  4889. public function getHttpHeaders()
  4890. {
  4891. return $this->httpHeaders;
  4892. }
  4893. /**
  4894. * Retrieves a particular header. If it doesn't exist, no exception/error is caused.
  4895. * Simply null is returned.
  4896. *
  4897. * @param string $header The name of the header to retrieve. Can be HTTP compliant such as
  4898. * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the
  4899. * all-caps, HTTP_ prefixed, underscore seperated awesomeness.
  4900. *
  4901. * @return string|null The value of the header.
  4902. */
  4903. public function getHttpHeader($header)
  4904. {
  4905. // are we using PHP-flavored headers?
  4906. if (strpos($header, '_') === false) {
  4907. $header = str_replace('-', '_', $header);
  4908. $header = strtoupper($header);
  4909. }
  4910. // test the alternate, too
  4911. $altHeader = 'HTTP_' . $header;
  4912. //Test both the regular and the HTTP_ prefix
  4913. if (isset($this->httpHeaders[$header])) {
  4914. return $this->httpHeaders[$header];
  4915. } elseif (isset($this->httpHeaders[$altHeader])) {
  4916. return $this->httpHeaders[$altHeader];
  4917. }
  4918. return null;
  4919. }
  4920. public function getMobileHeaders()
  4921. {
  4922. return self::$mobileHeaders;
  4923. }
  4924. /**
  4925. * Get all possible HTTP headers that
  4926. * can contain the User-Agent string.
  4927. *
  4928. * @return array List of HTTP headers.
  4929. */
  4930. public function getUaHttpHeaders()
  4931. {
  4932. return self::$uaHttpHeaders;
  4933. }
  4934. /**
  4935. * Set CloudFront headers
  4936. * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device
  4937. *
  4938. * @param array $cfHeaders List of HTTP headers
  4939. *
  4940. * @return boolean If there were CloudFront headers to be set
  4941. */
  4942. public function setCfHeaders($cfHeaders = null) {
  4943. // use global _SERVER if $cfHeaders aren't defined
  4944. if (!is_array($cfHeaders) || !count($cfHeaders)) {
  4945. $cfHeaders = $_SERVER;
  4946. }
  4947. // clear existing headers
  4948. $this->cloudfrontHeaders = array();
  4949. // Only save CLOUDFRONT headers. In PHP land, that means only _SERVER vars that
  4950. // start with cloudfront-.
  4951. $response = false;
  4952. foreach ($cfHeaders as $key => $value) {
  4953. if (substr(strtolower($key), 0, 16) === 'http_cloudfront_') {
  4954. $this->cloudfrontHeaders[strtoupper($key)] = $value;
  4955. $response = true;
  4956. }
  4957. }
  4958. return $response;
  4959. }
  4960. /**
  4961. * Retrieves the cloudfront headers.
  4962. *
  4963. * @return array
  4964. */
  4965. public function getCfHeaders()
  4966. {
  4967. return $this->cloudfrontHeaders;
  4968. }
  4969. /**
  4970. * Set the User-Agent to be used.
  4971. *
  4972. * @param string $userAgent The user agent string to set.
  4973. *
  4974. * @return string|null
  4975. */
  4976. public function setUserAgent($userAgent = null)
  4977. {
  4978. // Invalidate cache due to #375
  4979. $this->cache = array();
  4980. if (false === empty($userAgent)) {
  4981. return $this->userAgent = $userAgent;
  4982. } else {
  4983. $this->userAgent = null;
  4984. foreach ($this->getUaHttpHeaders() as $altHeader) {
  4985. if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban)
  4986. $this->userAgent .= $this->httpHeaders[$altHeader] . " ";
  4987. }
  4988. }
  4989. if (!empty($this->userAgent)) {
  4990. return $this->userAgent = trim($this->userAgent);
  4991. }
  4992. }
  4993. if (count($this->getCfHeaders()) > 0) {
  4994. return $this->userAgent = 'Amazon CloudFront';
  4995. }
  4996. return $this->userAgent = null;
  4997. }
  4998. /**
  4999. * Retrieve the User-Agent.
  5000. *
  5001. * @return string|null The user agent if it's set.
  5002. */
  5003. public function getUserAgent()
  5004. {
  5005. return $this->userAgent;
  5006. }
  5007. /**
  5008. * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or
  5009. * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set.
  5010. *
  5011. * @deprecated since version 2.6.9
  5012. *
  5013. * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
  5014. * parameter is null which will default to self::DETECTION_TYPE_MOBILE.
  5015. */
  5016. public function setDetectionType($type = null)
  5017. {
  5018. if ($type === null) {
  5019. $type = self::DETECTION_TYPE_MOBILE;
  5020. }
  5021. if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) {
  5022. return;
  5023. }
  5024. $this->detectionType = $type;
  5025. }
  5026. public function getMatchingRegex()
  5027. {
  5028. return $this->matchingRegex;
  5029. }
  5030. public function getMatchesArray()
  5031. {
  5032. return $this->matchesArray;
  5033. }
  5034. /**
  5035. * Retrieve the list of known phone devices.
  5036. *
  5037. * @return array List of phone devices.
  5038. */
  5039. public static function getPhoneDevices()
  5040. {
  5041. return self::$phoneDevices;
  5042. }
  5043. /**
  5044. * Retrieve the list of known tablet devices.
  5045. *
  5046. * @return array List of tablet devices.
  5047. */
  5048. public static function getTabletDevices()
  5049. {
  5050. return self::$tabletDevices;
  5051. }
  5052. /**
  5053. * Alias for getBrowsers() method.
  5054. *
  5055. * @return array List of user agents.
  5056. */
  5057. public static function getUserAgents()
  5058. {
  5059. return self::getBrowsers();
  5060. }
  5061. /**
  5062. * Retrieve the list of known browsers. Specifically, the user agents.
  5063. *
  5064. * @return array List of browsers / user agents.
  5065. */
  5066. public static function getBrowsers()
  5067. {
  5068. return self::$browsers;
  5069. }
  5070. /**
  5071. * Retrieve the list of known utilities.
  5072. *
  5073. * @return array List of utilities.
  5074. */
  5075. public static function getUtilities()
  5076. {
  5077. return self::$utilities;
  5078. }
  5079. /**
  5080. * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().
  5081. *
  5082. * @deprecated since version 2.6.9
  5083. *
  5084. * @return array All the rules (but not extended).
  5085. */
  5086. public static function getMobileDetectionRules()
  5087. {
  5088. static $rules;
  5089. if (!$rules) {
  5090. $rules = array_merge(
  5091. self::$phoneDevices,
  5092. self::$tabletDevices,
  5093. self::$operatingSystems,
  5094. self::$browsers
  5095. );
  5096. }
  5097. return $rules;
  5098. }
  5099. /**
  5100. * Method gets the mobile detection rules + utilities.
  5101. * The reason this is separate is because utilities rules
  5102. * don't necessary imply mobile. This method is used inside
  5103. * the new $detect->is('stuff') method.
  5104. *
  5105. * @deprecated since version 2.6.9
  5106. *
  5107. * @return array All the rules + extended.
  5108. */
  5109. public function getMobileDetectionRulesExtended()
  5110. {
  5111. static $rules;
  5112. if (!$rules) {
  5113. // Merge all rules together.
  5114. $rules = array_merge(
  5115. self::$phoneDevices,
  5116. self::$tabletDevices,
  5117. self::$operatingSystems,
  5118. self::$browsers,
  5119. self::$utilities
  5120. );
  5121. }
  5122. return $rules;
  5123. }
  5124. /**
  5125. * Retrieve the current set of rules.
  5126. *
  5127. * @deprecated since version 2.6.9
  5128. *
  5129. * @return array
  5130. */
  5131. public function getRules()
  5132. {
  5133. if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) {
  5134. return self::getMobileDetectionRulesExtended();
  5135. } else {
  5136. return self::getMobileDetectionRules();
  5137. }
  5138. }
  5139. /**
  5140. * Retrieve the list of mobile operating systems.
  5141. *
  5142. * @return array The list of mobile operating systems.
  5143. */
  5144. public static function getOperatingSystems()
  5145. {
  5146. return self::$operatingSystems;
  5147. }
  5148. /**
  5149. * Check the HTTP headers for signs of mobile.
  5150. * This is the fastest mobile check possible; it's used
  5151. * inside isMobile() method.
  5152. *
  5153. * @return bool
  5154. */
  5155. public function checkHttpHeadersForMobile()
  5156. {
  5157. foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) {
  5158. if (isset($this->httpHeaders[$mobileHeader])) {
  5159. if (is_array($matchType['matches'])) {
  5160. foreach ($matchType['matches'] as $_match) {
  5161. if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) {
  5162. return true;
  5163. }
  5164. }
  5165. return false;
  5166. } else {
  5167. return true;
  5168. }
  5169. }
  5170. }
  5171. return false;
  5172. }
  5173. /**
  5174. * Magic overloading method.
  5175. *
  5176. * @method boolean is[...]()
  5177. * @param string $name
  5178. * @param array $arguments
  5179. * @return mixed
  5180. * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
  5181. */
  5182. public function __call($name, $arguments)
  5183. {
  5184. // make sure the name starts with 'is', otherwise
  5185. if (substr($name, 0, 2) !== 'is') {
  5186. throw new BadMethodCallException("No such method exists: $name");
  5187. }
  5188. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  5189. $key = substr($name, 2);
  5190. return $this->matchUAAgainstKey($key);
  5191. }
  5192. /**
  5193. * Find a detection rule that matches the current User-agent.
  5194. *
  5195. * @param null $userAgent deprecated
  5196. * @return boolean
  5197. */
  5198. protected function matchDetectionRulesAgainstUA($userAgent = null)
  5199. {
  5200. // Begin general search.
  5201. foreach ($this->getRules() as $_regex) {
  5202. if (empty($_regex)) {
  5203. continue;
  5204. }
  5205. if ($this->match($_regex, $userAgent)) {
  5206. return true;
  5207. }
  5208. }
  5209. return false;
  5210. }
  5211. /**
  5212. * Search for a certain key in the rules array.
  5213. * If the key is found then try to match the corresponding
  5214. * regex against the User-Agent.
  5215. *
  5216. * @param string $key
  5217. *
  5218. * @return boolean
  5219. */
  5220. protected function matchUAAgainstKey($key)
  5221. {
  5222. // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
  5223. $key = strtolower($key);
  5224. if (false === isset($this->cache[$key])) {
  5225. // change the keys to lower case
  5226. $_rules = array_change_key_case($this->getRules());
  5227. if (false === empty($_rules[$key])) {
  5228. $this->cache[$key] = $this->match($_rules[$key]);
  5229. }
  5230. if (false === isset($this->cache[$key])) {
  5231. $this->cache[$key] = false;
  5232. }
  5233. }
  5234. return $this->cache[$key];
  5235. }
  5236. /**
  5237. * Check if the device is mobile.
  5238. * Returns true if any type of mobile device detected, including special ones
  5239. * @param null $userAgent deprecated
  5240. * @param null $httpHeaders deprecated
  5241. * @return bool
  5242. */
  5243. public function isMobile($userAgent = null, $httpHeaders = null)
  5244. {
  5245. if ($httpHeaders) {
  5246. $this->setHttpHeaders($httpHeaders);
  5247. }
  5248. if ($userAgent) {
  5249. $this->setUserAgent($userAgent);
  5250. }
  5251. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  5252. if ($this->getUserAgent() === 'Amazon CloudFront') {
  5253. $cfHeaders = $this->getCfHeaders();
  5254. if(array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') {
  5255. return true;
  5256. }
  5257. }
  5258. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  5259. if ($this->checkHttpHeadersForMobile()) {
  5260. return true;
  5261. } else {
  5262. return $this->matchDetectionRulesAgainstUA();
  5263. }
  5264. }
  5265. /**
  5266. * Check if the device is a tablet.
  5267. * Return true if any type of tablet device is detected.
  5268. *
  5269. * @param string $userAgent deprecated
  5270. * @param array $httpHeaders deprecated
  5271. * @return bool
  5272. */
  5273. public function isTablet($userAgent = null, $httpHeaders = null)
  5274. {
  5275. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  5276. if ($this->getUserAgent() === 'Amazon CloudFront') {
  5277. $cfHeaders = $this->getCfHeaders();
  5278. if(array_key_exists('HTTP_CLOUDFRONT_IS_TABLET_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] === 'true') {
  5279. return true;
  5280. }
  5281. }
  5282. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  5283. foreach (self::$tabletDevices as $_regex) {
  5284. if ($this->match($_regex, $userAgent)) {
  5285. return true;
  5286. }
  5287. }
  5288. return false;
  5289. }
  5290. /**
  5291. * This method checks for a certain property in the
  5292. * userAgent.
  5293. * @todo: The httpHeaders part is not yet used.
  5294. *
  5295. * @param string $key
  5296. * @param string $userAgent deprecated
  5297. * @param string $httpHeaders deprecated
  5298. * @return bool|int|null
  5299. */
  5300. public function is($key, $userAgent = null, $httpHeaders = null)
  5301. {
  5302. // Set the UA and HTTP headers only if needed (eg. batch mode).
  5303. if ($httpHeaders) {
  5304. $this->setHttpHeaders($httpHeaders);
  5305. }
  5306. if ($userAgent) {
  5307. $this->setUserAgent($userAgent);
  5308. }
  5309. $this->setDetectionType(self::DETECTION_TYPE_EXTENDED);
  5310. return $this->matchUAAgainstKey($key);
  5311. }
  5312. /**
  5313. * Some detection rules are relative (not standard),
  5314. * because of the diversity of devices, vendors and
  5315. * their conventions in representing the User-Agent or
  5316. * the HTTP headers.
  5317. *
  5318. * This method will be used to check custom regexes against
  5319. * the User-Agent string.
  5320. *
  5321. * @param $regex
  5322. * @param string $userAgent
  5323. * @return bool
  5324. *
  5325. * @todo: search in the HTTP headers too.
  5326. */
  5327. public function match($regex, $userAgent = null)
  5328. {
  5329. $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches);
  5330. // If positive match is found, store the results for debug.
  5331. if ($match) {
  5332. $this->matchingRegex = $regex;
  5333. $this->matchesArray = $matches;
  5334. }
  5335. return $match;
  5336. }
  5337. /**
  5338. * Get the properties array.
  5339. *
  5340. * @return array
  5341. */
  5342. public static function getProperties()
  5343. {
  5344. return self::$properties;
  5345. }
  5346. /**
  5347. * Prepare the version number.
  5348. *
  5349. * @todo Remove the error supression from str_replace() call.
  5350. *
  5351. * @param string $ver The string version, like "2.6.21.2152";
  5352. *
  5353. * @return float
  5354. */
  5355. public function prepareVersionNo($ver)
  5356. {
  5357. $ver = str_replace(array('_', ' ', '/'), '.', $ver);
  5358. $arrVer = explode('.', $ver, 2);
  5359. if (isset($arrVer[1])) {
  5360. $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions.
  5361. }
  5362. return (float) implode('.', $arrVer);
  5363. }
  5364. /**
  5365. * Check the version of the given property in the User-Agent.
  5366. * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
  5367. *
  5368. * @param string $propertyName The name of the property. See self::getProperties() array
  5369. * keys for all possible properties.
  5370. * @param string $type Either self::VERSION_TYPE_STRING to get a string value or
  5371. * self::VERSION_TYPE_FLOAT indicating a float value. This parameter
  5372. * is optional and defaults to self::VERSION_TYPE_STRING. Passing an
  5373. * invalid parameter will default to the this type as well.
  5374. *
  5375. * @return string|float The version of the property we are trying to extract.
  5376. */
  5377. public function version($propertyName, $type = self::VERSION_TYPE_STRING)
  5378. {
  5379. if (empty($propertyName)) {
  5380. return false;
  5381. }
  5382. // set the $type to the default if we don't recognize the type
  5383. if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
  5384. $type = self::VERSION_TYPE_STRING;
  5385. }
  5386. $properties = self::getProperties();
  5387. // Check if the property exists in the properties array.
  5388. if (true === isset($properties[$propertyName])) {
  5389. // Prepare the pattern to be matched.
  5390. // Make sure we always deal with an array (string is converted).
  5391. $properties[$propertyName] = (array) $properties[$propertyName];
  5392. foreach ($properties[$propertyName] as $propertyMatchString) {
  5393. $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
  5394. // Identify and extract the version.
  5395. preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);
  5396. if (false === empty($match[1])) {
  5397. $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);
  5398. return $version;
  5399. }
  5400. }
  5401. }
  5402. return false;
  5403. }
  5404. /**
  5405. * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
  5406. *
  5407. * @return string One of the self::MOBILE_GRADE_* constants.
  5408. */
  5409. public function mobileGrade()
  5410. {
  5411. $isMobile = $this->isMobile();
  5412. if (
  5413. // 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)
  5414. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  5415. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  5416. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  5417. // 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)
  5418. // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
  5419. // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
  5420. // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
  5421. ( $this->version('Android', self::VERSION_TYPE_FLOAT)>2.1 && $this->is('Webkit') ) ||
  5422. // 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)
  5423. $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 ||
  5424. // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry® Torch 9810 (7), BlackBerry Z10 (10)
  5425. $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 ||
  5426. // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
  5427. $this->match('Playbook.*Tablet') ||
  5428. // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0)
  5429. ( $this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi') ) ||
  5430. // Palm WebOS 3.0 - Tested on HP TouchPad
  5431. $this->match('hp.*TouchPad') ||
  5432. // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices
  5433. ( $this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18 ) ||
  5434. // Chrome for Android - Tested on Android 4.0, 4.1 device
  5435. ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0 ) ||
  5436. // Skyfire 4.1 - Tested on Android 2.3 device
  5437. ( $this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  5438. // Opera Mobile 11.5-12: Tested on Android 2.3
  5439. ( $this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS') ) ||
  5440. // Meego 1.2 - Tested on Nokia 950 and N9
  5441. $this->is('MeeGoOS') ||
  5442. // Tizen (pre-release) - Tested on early hardware
  5443. $this->is('Tizen') ||
  5444. // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
  5445. // @todo: more tests here!
  5446. $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 ||
  5447. // UC Browser - Tested on Android 2.3 device
  5448. ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  5449. // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
  5450. ( $this->match('Kindle Fire') ||
  5451. $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0 ) ||
  5452. // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
  5453. $this->is('AndroidOS') && $this->is('NookTablet') ||
  5454. // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7
  5455. $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && !$isMobile ||
  5456. // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7
  5457. $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && !$isMobile ||
  5458. // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7
  5459. $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && !$isMobile ||
  5460. // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
  5461. $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && !$isMobile ||
  5462. // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
  5463. $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && !$isMobile
  5464. ){
  5465. return self::MOBILE_GRADE_A;
  5466. }
  5467. if (
  5468. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT)<4.3 ||
  5469. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT)<4.3 ||
  5470. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT)<4.3 ||
  5471. // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
  5472. $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT)<6 ||
  5473. //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
  5474. ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 &&
  5475. ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS')) ) ||
  5476. // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
  5477. $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
  5478. // @todo: report this (tested on Nokia N71)
  5479. $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS')
  5480. ){
  5481. return self::MOBILE_GRADE_B;
  5482. }
  5483. if (
  5484. // Blackberry 4.x - Tested on the Curve 8330
  5485. $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 ||
  5486. // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
  5487. $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 ||
  5488. // Tested on original iPhone (3.1), iPhone 3 (3.2)
  5489. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  5490. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  5491. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  5492. // Internet Explorer 7 and older - Tested on Windows XP
  5493. $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && !$isMobile
  5494. ){
  5495. return self::MOBILE_GRADE_C;
  5496. }
  5497. // All older smartphone platforms and featurephones - Any device that doesn't support media queries
  5498. // will receive the basic, C grade experience.
  5499. return self::MOBILE_GRADE_C;
  5500. }
  5501. }
  5502. $mobileDetect = new Mobile_Detect;
  5503. $userDevice = ($mobileDetect->isMobile() ? ($mobileDetect->isTablet() ? 'tablet' : 'phone') : 'computer');
  5504. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  5505. $path = getServerPath();
  5506. return '
  5507. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5508. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  5509. <head>
  5510. <!--[if gte mso 9]><xml>
  5511. <o:OfficeDocumentSettings>
  5512. <o:AllowPNG/>
  5513. <o:PixelsPerInch>96</o:PixelsPerInch>
  5514. </o:OfficeDocumentSettings>
  5515. </xml><![endif]-->
  5516. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5517. <meta name="viewport" content="width=device-width">
  5518. <!--[if !mso]><!-->
  5519. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5520. <!--<![endif]-->
  5521. <title></title>
  5522. <!--[if !mso]><!-- -->
  5523. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  5524. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  5525. <!--<![endif]-->
  5526. <style type="text/css" id="media-query">
  5527. body {
  5528. margin: 0;
  5529. padding: 0;
  5530. }
  5531. table,
  5532. tr,
  5533. td {
  5534. vertical-align: top;
  5535. border-collapse: collapse;
  5536. }
  5537. .ie-browser table,
  5538. .mso-container table {
  5539. table-layout: fixed;
  5540. }
  5541. * {
  5542. line-height: inherit;
  5543. }
  5544. a[x-apple-data-detectors=true] {
  5545. color: inherit !important;
  5546. text-decoration: none !important;
  5547. }
  5548. [owa] .img-container div,
  5549. [owa] .img-container button {
  5550. display: block !important;
  5551. }
  5552. [owa] .fullwidth button {
  5553. width: 100% !important;
  5554. }
  5555. [owa] .block-grid .col {
  5556. display: table-cell;
  5557. float: none !important;
  5558. vertical-align: top;
  5559. }
  5560. .ie-browser .num12,
  5561. .ie-browser .block-grid,
  5562. [owa] .num12,
  5563. [owa] .block-grid {
  5564. width: 615px !important;
  5565. }
  5566. .ExternalClass,
  5567. .ExternalClass p,
  5568. .ExternalClass span,
  5569. .ExternalClass font,
  5570. .ExternalClass td,
  5571. .ExternalClass div {
  5572. line-height: 100%;
  5573. }
  5574. .ie-browser .mixed-two-up .num4,
  5575. [owa] .mixed-two-up .num4 {
  5576. width: 204px !important;
  5577. }
  5578. .ie-browser .mixed-two-up .num8,
  5579. [owa] .mixed-two-up .num8 {
  5580. width: 408px !important;
  5581. }
  5582. .ie-browser .block-grid.two-up .col,
  5583. [owa] .block-grid.two-up .col {
  5584. width: 307px !important;
  5585. }
  5586. .ie-browser .block-grid.three-up .col,
  5587. [owa] .block-grid.three-up .col {
  5588. width: 205px !important;
  5589. }
  5590. .ie-browser .block-grid.four-up .col,
  5591. [owa] .block-grid.four-up .col {
  5592. width: 153px !important;
  5593. }
  5594. .ie-browser .block-grid.five-up .col,
  5595. [owa] .block-grid.five-up .col {
  5596. width: 123px !important;
  5597. }
  5598. .ie-browser .block-grid.six-up .col,
  5599. [owa] .block-grid.six-up .col {
  5600. width: 102px !important;
  5601. }
  5602. .ie-browser .block-grid.seven-up .col,
  5603. [owa] .block-grid.seven-up .col {
  5604. width: 87px !important;
  5605. }
  5606. .ie-browser .block-grid.eight-up .col,
  5607. [owa] .block-grid.eight-up .col {
  5608. width: 76px !important;
  5609. }
  5610. .ie-browser .block-grid.nine-up .col,
  5611. [owa] .block-grid.nine-up .col {
  5612. width: 68px !important;
  5613. }
  5614. .ie-browser .block-grid.ten-up .col,
  5615. [owa] .block-grid.ten-up .col {
  5616. width: 61px !important;
  5617. }
  5618. .ie-browser .block-grid.eleven-up .col,
  5619. [owa] .block-grid.eleven-up .col {
  5620. width: 55px !important;
  5621. }
  5622. .ie-browser .block-grid.twelve-up .col,
  5623. [owa] .block-grid.twelve-up .col {
  5624. width: 51px !important;
  5625. }
  5626. @media only screen and (min-width: 635px) {
  5627. .block-grid {
  5628. width: 615px !important;
  5629. }
  5630. .block-grid .col {
  5631. display: table-cell;
  5632. Float: none !important;
  5633. vertical-align: top;
  5634. }
  5635. .block-grid .col.num12 {
  5636. width: 615px !important;
  5637. }
  5638. .block-grid.mixed-two-up .col.num4 {
  5639. width: 204px !important;
  5640. }
  5641. .block-grid.mixed-two-up .col.num8 {
  5642. width: 408px !important;
  5643. }
  5644. .block-grid.two-up .col {
  5645. width: 307px !important;
  5646. }
  5647. .block-grid.three-up .col {
  5648. width: 205px !important;
  5649. }
  5650. .block-grid.four-up .col {
  5651. width: 153px !important;
  5652. }
  5653. .block-grid.five-up .col {
  5654. width: 123px !important;
  5655. }
  5656. .block-grid.six-up .col {
  5657. width: 102px !important;
  5658. }
  5659. .block-grid.seven-up .col {
  5660. width: 87px !important;
  5661. }
  5662. .block-grid.eight-up .col {
  5663. width: 76px !important;
  5664. }
  5665. .block-grid.nine-up .col {
  5666. width: 68px !important;
  5667. }
  5668. .block-grid.ten-up .col {
  5669. width: 61px !important;
  5670. }
  5671. .block-grid.eleven-up .col {
  5672. width: 55px !important;
  5673. }
  5674. .block-grid.twelve-up .col {
  5675. width: 51px !important;
  5676. }
  5677. }
  5678. @media (max-width: 635px) {
  5679. .block-grid,
  5680. .col {
  5681. min-width: 320px !important;
  5682. max-width: 100% !important;
  5683. }
  5684. .block-grid {
  5685. width: calc(100% - 40px) !important;
  5686. }
  5687. .col {
  5688. width: 100% !important;
  5689. }
  5690. .col>div {
  5691. margin: 0 auto;
  5692. }
  5693. img.fullwidth {
  5694. max-width: 100% !important;
  5695. }
  5696. }
  5697. </style>
  5698. </head>
  5699. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  5700. <!--[if IE]><div class="ie-browser"><![endif]-->
  5701. <!--[if mso]><div class="mso-container"><![endif]-->
  5702. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  5703. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  5704. <div style="background-color:#333333;">
  5705. <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;"
  5706. class="block-grid ">
  5707. <div style="border-collapse: collapse;display: table;width: 100%;">
  5708. <!--[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]-->
  5709. <!--[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]-->
  5710. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  5711. <div style="background-color: transparent; width: 100% !important;">
  5712. <!--[if (!mso)&(!IE)]><!-->
  5713. <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;">
  5714. <!--<![endif]-->
  5715. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  5716. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  5717. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  5718. 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"
  5719. width="555">
  5720. <!--[if mso]></td></tr></table><![endif]-->
  5721. </div>
  5722. <!--[if (!mso)&(!IE)]><!-->
  5723. </div>
  5724. <!--<![endif]-->
  5725. </div>
  5726. </div>
  5727. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  5728. </div>
  5729. </div>
  5730. </div>
  5731. <div style="background-color:#333333;">
  5732. <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;"
  5733. class="block-grid ">
  5734. <div style="border-collapse: collapse;display: table;width: 100%;">
  5735. <!--[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]-->
  5736. <!--[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]-->
  5737. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  5738. <div style="background-color: transparent; width: 100% !important;">
  5739. <!--[if (!mso)&(!IE)]><!-->
  5740. <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;">
  5741. <!--<![endif]-->
  5742. <!--[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]-->
  5743. <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;">
  5744. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  5745. <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>
  5746. </span>
  5747. </p>
  5748. </div>
  5749. </div>
  5750. <!--[if mso]></td></tr></table><![endif]-->
  5751. <!--[if (!mso)&(!IE)]><!-->
  5752. </div>
  5753. <!--<![endif]-->
  5754. </div>
  5755. </div>
  5756. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  5757. </div>
  5758. </div>
  5759. </div>
  5760. <div style="background-color:#393939;">
  5761. <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;"
  5762. class="block-grid ">
  5763. <div style="border-collapse: collapse;display: table;width: 100%;">
  5764. <!--[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]-->
  5765. <!--[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]-->
  5766. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  5767. <div style="background-color: transparent; width: 100% !important;">
  5768. <!--[if (!mso)&(!IE)]><!-->
  5769. <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;">
  5770. <!--<![endif]-->
  5771. <!--[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]-->
  5772. <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;">
  5773. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  5774. <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>
  5775. </div>
  5776. </div>
  5777. <!--[if mso]></td></tr></table><![endif]-->
  5778. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  5779. <!--[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]-->
  5780. <div align="center">
  5781. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  5782. </div>
  5783. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  5784. </div>
  5785. <!--[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]-->
  5786. <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;">
  5787. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  5788. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  5789. </div>
  5790. </div>
  5791. <!--[if mso]></td></tr></table><![endif]-->
  5792. <!--[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]-->
  5793. <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;">
  5794. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  5795. <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>
  5796. </span>
  5797. </p>
  5798. </div>
  5799. </div>
  5800. <!--[if mso]></td></tr></table><![endif]-->
  5801. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  5802. <!--[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]-->
  5803. <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">
  5804. <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>
  5805. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  5806. </div>
  5807. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  5808. </div>
  5809. <!--[if (!mso)&(!IE)]><!-->
  5810. </div>
  5811. <!--<![endif]-->
  5812. </div>
  5813. </div>
  5814. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  5815. </div>
  5816. </div>
  5817. </div>
  5818. <div style="background-color:#ffffff;">
  5819. <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;"
  5820. class="block-grid ">
  5821. <div style="border-collapse: collapse;display: table;width: 100%;">
  5822. <!--[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]-->
  5823. <!--[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]-->
  5824. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  5825. <div style="background-color: transparent; width: 100% !important;">
  5826. <!--[if (!mso)&(!IE)]><!-->
  5827. <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;">
  5828. <!--<![endif]-->
  5829. <!--[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]-->
  5830. <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;">
  5831. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  5832. <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>
  5833. </div>
  5834. </div>
  5835. <!--[if mso]></td></tr></table><![endif]-->
  5836. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  5837. <!--[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]-->
  5838. <div align="center">
  5839. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  5840. </div>
  5841. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  5842. </div>
  5843. <!--[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]-->
  5844. <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;">
  5845. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  5846. <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>
  5847. </div>
  5848. </div>
  5849. <!--[if mso]></td></tr></table><![endif]-->
  5850. <!--[if (!mso)&(!IE)]><!-->
  5851. </div>
  5852. <!--<![endif]-->
  5853. </div>
  5854. </div>
  5855. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  5856. </div>
  5857. </div>
  5858. </div>
  5859. <div style="background-color:#333333;">
  5860. <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;"
  5861. class="block-grid ">
  5862. <div style="border-collapse: collapse;display: table;width: 100%;">
  5863. <!--[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]-->
  5864. <!--[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]-->
  5865. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  5866. <div style="background-color: transparent; width: 100% !important;">
  5867. <!--[if (!mso)&(!IE)]><!-->
  5868. <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;">
  5869. <!--<![endif]-->
  5870. <!--[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]-->
  5871. <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;">
  5872. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  5873. <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"
  5874. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  5875. </div>
  5876. </div>
  5877. <!--[if mso]></td></tr></table><![endif]-->
  5878. <!--[if (!mso)&(!IE)]><!-->
  5879. </div>
  5880. <!--<![endif]-->
  5881. </div>
  5882. </div>
  5883. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  5884. </div>
  5885. </div>
  5886. </div>
  5887. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  5888. </div>
  5889. <!--[if (mso)|(IE)]></div><![endif]-->
  5890. </body>
  5891. </html>
  5892. ';
  5893. }
  5894. function mimeTypes(){
  5895. return array(
  5896. '123' => 'application/vnd.lotus-1-2-3',
  5897. '3dml' => 'text/vnd.in3d.3dml',
  5898. '3ds' => 'image/x-3ds',
  5899. '3g2' => 'video/3gpp2',
  5900. '3gp' => 'video/3gpp',
  5901. '7z' => 'application/x-7z-compressed',
  5902. 'aab' => 'application/x-authorware-bin',
  5903. 'aac' => 'audio/x-aac',
  5904. 'aam' => 'application/x-authorware-map',
  5905. 'aas' => 'application/x-authorware-seg',
  5906. 'abw' => 'application/x-abiword',
  5907. 'ac' => 'application/pkix-attr-cert',
  5908. 'acc' => 'application/vnd.americandynamics.acc',
  5909. 'ace' => 'application/x-ace-compressed',
  5910. 'acu' => 'application/vnd.acucobol',
  5911. 'acutc' => 'application/vnd.acucorp',
  5912. 'adp' => 'audio/adpcm',
  5913. 'aep' => 'application/vnd.audiograph',
  5914. 'afm' => 'application/x-font-type1',
  5915. 'afp' => 'application/vnd.ibm.modcap',
  5916. 'ahead' => 'application/vnd.ahead.space',
  5917. 'ai' => 'application/postscript',
  5918. 'aif' => 'audio/x-aiff',
  5919. 'aifc' => 'audio/x-aiff',
  5920. 'aiff' => 'audio/x-aiff',
  5921. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  5922. 'ait' => 'application/vnd.dvb.ait',
  5923. 'ami' => 'application/vnd.amiga.ami',
  5924. 'apk' => 'application/vnd.android.package-archive',
  5925. 'appcache' => 'text/cache-manifest',
  5926. 'application' => 'application/x-ms-application',
  5927. 'apr' => 'application/vnd.lotus-approach',
  5928. 'arc' => 'application/x-freearc',
  5929. 'asc' => 'application/pgp-signature',
  5930. 'asf' => 'video/x-ms-asf',
  5931. 'asm' => 'text/x-asm',
  5932. 'aso' => 'application/vnd.accpac.simply.aso',
  5933. 'asx' => 'video/x-ms-asf',
  5934. 'atc' => 'application/vnd.acucorp',
  5935. 'atom' => 'application/atom+xml',
  5936. 'atomcat' => 'application/atomcat+xml',
  5937. 'atomsvc' => 'application/atomsvc+xml',
  5938. 'atx' => 'application/vnd.antix.game-component',
  5939. 'au' => 'audio/basic',
  5940. 'avi' => 'video/x-msvideo',
  5941. 'aw' => 'application/applixware',
  5942. 'azf' => 'application/vnd.airzip.filesecure.azf',
  5943. 'azs' => 'application/vnd.airzip.filesecure.azs',
  5944. 'azw' => 'application/vnd.amazon.ebook',
  5945. 'bat' => 'application/x-msdownload',
  5946. 'bcpio' => 'application/x-bcpio',
  5947. 'bdf' => 'application/x-font-bdf',
  5948. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  5949. 'bed' => 'application/vnd.realvnc.bed',
  5950. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  5951. 'bin' => 'application/octet-stream',
  5952. 'blb' => 'application/x-blorb',
  5953. 'blorb' => 'application/x-blorb',
  5954. 'bmi' => 'application/vnd.bmi',
  5955. 'bmp' => 'image/bmp',
  5956. 'book' => 'application/vnd.framemaker',
  5957. 'box' => 'application/vnd.previewsystems.box',
  5958. 'boz' => 'application/x-bzip2',
  5959. 'bpk' => 'application/octet-stream',
  5960. 'btif' => 'image/prs.btif',
  5961. 'bz' => 'application/x-bzip',
  5962. 'bz2' => 'application/x-bzip2',
  5963. 'c' => 'text/x-c',
  5964. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  5965. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  5966. 'c4d' => 'application/vnd.clonk.c4group',
  5967. 'c4f' => 'application/vnd.clonk.c4group',
  5968. 'c4g' => 'application/vnd.clonk.c4group',
  5969. 'c4p' => 'application/vnd.clonk.c4group',
  5970. 'c4u' => 'application/vnd.clonk.c4group',
  5971. 'cab' => 'application/vnd.ms-cab-compressed',
  5972. 'caf' => 'audio/x-caf',
  5973. 'cap' => 'application/vnd.tcpdump.pcap',
  5974. 'car' => 'application/vnd.curl.car',
  5975. 'cat' => 'application/vnd.ms-pki.seccat',
  5976. 'cb7' => 'application/x-cbr',
  5977. 'cba' => 'application/x-cbr',
  5978. 'cbr' => 'application/x-cbr',
  5979. 'cbt' => 'application/x-cbr',
  5980. 'cbz' => 'application/x-cbr',
  5981. 'cc' => 'text/x-c',
  5982. 'cct' => 'application/x-director',
  5983. 'ccxml' => 'application/ccxml+xml',
  5984. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  5985. 'cdf' => 'application/x-netcdf',
  5986. 'cdkey' => 'application/vnd.mediastation.cdkey',
  5987. 'cdmia' => 'application/cdmi-capability',
  5988. 'cdmic' => 'application/cdmi-container',
  5989. 'cdmid' => 'application/cdmi-domain',
  5990. 'cdmio' => 'application/cdmi-object',
  5991. 'cdmiq' => 'application/cdmi-queue',
  5992. 'cdx' => 'chemical/x-cdx',
  5993. 'cdxml' => 'application/vnd.chemdraw+xml',
  5994. 'cdy' => 'application/vnd.cinderella',
  5995. 'cer' => 'application/pkix-cert',
  5996. 'cfs' => 'application/x-cfs-compressed',
  5997. 'cgm' => 'image/cgm',
  5998. 'chat' => 'application/x-chat',
  5999. 'chm' => 'application/vnd.ms-htmlhelp',
  6000. 'chrt' => 'application/vnd.kde.kchart',
  6001. 'cif' => 'chemical/x-cif',
  6002. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  6003. 'cil' => 'application/vnd.ms-artgalry',
  6004. 'cla' => 'application/vnd.claymore',
  6005. 'class' => 'application/java-vm',
  6006. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  6007. 'clkp' => 'application/vnd.crick.clicker.palette',
  6008. 'clkt' => 'application/vnd.crick.clicker.template',
  6009. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  6010. 'clkx' => 'application/vnd.crick.clicker',
  6011. 'clp' => 'application/x-msclip',
  6012. 'cmc' => 'application/vnd.cosmocaller',
  6013. 'cmdf' => 'chemical/x-cmdf',
  6014. 'cml' => 'chemical/x-cml',
  6015. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  6016. 'cmx' => 'image/x-cmx',
  6017. 'cod' => 'application/vnd.rim.cod',
  6018. 'com' => 'application/x-msdownload',
  6019. 'conf' => 'text/plain',
  6020. 'cpio' => 'application/x-cpio',
  6021. 'cpp' => 'text/x-c',
  6022. 'cpt' => 'application/mac-compactpro',
  6023. 'crd' => 'application/x-mscardfile',
  6024. 'crl' => 'application/pkix-crl',
  6025. 'crt' => 'application/x-x509-ca-cert',
  6026. 'cryptonote' => 'application/vnd.rig.cryptonote',
  6027. 'csh' => 'application/x-csh',
  6028. 'csml' => 'chemical/x-csml',
  6029. 'csp' => 'application/vnd.commonspace',
  6030. 'css' => 'text/css',
  6031. 'cst' => 'application/x-director',
  6032. 'csv' => 'text/csv',
  6033. 'cu' => 'application/cu-seeme',
  6034. 'curl' => 'text/vnd.curl',
  6035. 'cww' => 'application/prs.cww',
  6036. 'cxt' => 'application/x-director',
  6037. 'cxx' => 'text/x-c',
  6038. 'dae' => 'model/vnd.collada+xml',
  6039. 'daf' => 'application/vnd.mobius.daf',
  6040. 'dart' => 'application/vnd.dart',
  6041. 'dataless' => 'application/vnd.fdsn.seed',
  6042. 'davmount' => 'application/davmount+xml',
  6043. 'dbk' => 'application/docbook+xml',
  6044. 'dcr' => 'application/x-director',
  6045. 'dcurl' => 'text/vnd.curl.dcurl',
  6046. 'dd2' => 'application/vnd.oma.dd2+xml',
  6047. 'ddd' => 'application/vnd.fujixerox.ddd',
  6048. 'deb' => 'application/x-debian-package',
  6049. 'def' => 'text/plain',
  6050. 'deploy' => 'application/octet-stream',
  6051. 'der' => 'application/x-x509-ca-cert',
  6052. 'dfac' => 'application/vnd.dreamfactory',
  6053. 'dgc' => 'application/x-dgc-compressed',
  6054. 'dic' => 'text/x-c',
  6055. 'dir' => 'application/x-director',
  6056. 'dis' => 'application/vnd.mobius.dis',
  6057. 'dist' => 'application/octet-stream',
  6058. 'distz' => 'application/octet-stream',
  6059. 'djv' => 'image/vnd.djvu',
  6060. 'djvu' => 'image/vnd.djvu',
  6061. 'dll' => 'application/x-msdownload',
  6062. 'dmg' => 'application/x-apple-diskimage',
  6063. 'dmp' => 'application/vnd.tcpdump.pcap',
  6064. 'dms' => 'application/octet-stream',
  6065. 'dna' => 'application/vnd.dna',
  6066. 'doc' => 'application/msword',
  6067. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  6068. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  6069. 'dot' => 'application/msword',
  6070. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  6071. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  6072. 'dp' => 'application/vnd.osgi.dp',
  6073. 'dpg' => 'application/vnd.dpgraph',
  6074. 'dra' => 'audio/vnd.dra',
  6075. 'dsc' => 'text/prs.lines.tag',
  6076. 'dssc' => 'application/dssc+der',
  6077. 'dtb' => 'application/x-dtbook+xml',
  6078. 'dtd' => 'application/xml-dtd',
  6079. 'dts' => 'audio/vnd.dts',
  6080. 'dtshd' => 'audio/vnd.dts.hd',
  6081. 'dump' => 'application/octet-stream',
  6082. 'dvb' => 'video/vnd.dvb.file',
  6083. 'dvi' => 'application/x-dvi',
  6084. 'dwf' => 'model/vnd.dwf',
  6085. 'dwg' => 'image/vnd.dwg',
  6086. 'dxf' => 'image/vnd.dxf',
  6087. 'dxp' => 'application/vnd.spotfire.dxp',
  6088. 'dxr' => 'application/x-director',
  6089. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  6090. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  6091. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  6092. 'ecma' => 'application/ecmascript',
  6093. 'edm' => 'application/vnd.novadigm.edm',
  6094. 'edx' => 'application/vnd.novadigm.edx',
  6095. 'efif' => 'application/vnd.picsel',
  6096. 'ei6' => 'application/vnd.pg.osasli',
  6097. 'elc' => 'application/octet-stream',
  6098. 'emf' => 'application/x-msmetafile',
  6099. 'eml' => 'message/rfc822',
  6100. 'emma' => 'application/emma+xml',
  6101. 'emz' => 'application/x-msmetafile',
  6102. 'eol' => 'audio/vnd.digital-winds',
  6103. 'eot' => 'application/vnd.ms-fontobject',
  6104. 'eps' => 'application/postscript',
  6105. 'epub' => 'application/epub+zip',
  6106. 'es3' => 'application/vnd.eszigno3+xml',
  6107. 'esa' => 'application/vnd.osgi.subsystem',
  6108. 'esf' => 'application/vnd.epson.esf',
  6109. 'et3' => 'application/vnd.eszigno3+xml',
  6110. 'etx' => 'text/x-setext',
  6111. 'eva' => 'application/x-eva',
  6112. 'evy' => 'application/x-envoy',
  6113. 'exe' => 'application/x-msdownload',
  6114. 'exi' => 'application/exi',
  6115. 'ext' => 'application/vnd.novadigm.ext',
  6116. 'ez' => 'application/andrew-inset',
  6117. 'ez2' => 'application/vnd.ezpix-album',
  6118. 'ez3' => 'application/vnd.ezpix-package',
  6119. 'f' => 'text/x-fortran',
  6120. 'f4v' => 'video/x-f4v',
  6121. 'f77' => 'text/x-fortran',
  6122. 'f90' => 'text/x-fortran',
  6123. 'fbs' => 'image/vnd.fastbidsheet',
  6124. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  6125. 'fcs' => 'application/vnd.isac.fcs',
  6126. 'fdf' => 'application/vnd.fdf',
  6127. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  6128. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  6129. 'fgd' => 'application/x-director',
  6130. 'fh' => 'image/x-freehand',
  6131. 'fh4' => 'image/x-freehand',
  6132. 'fh5' => 'image/x-freehand',
  6133. 'fh7' => 'image/x-freehand',
  6134. 'fhc' => 'image/x-freehand',
  6135. 'fig' => 'application/x-xfig',
  6136. 'flac' => 'audio/x-flac',
  6137. 'fli' => 'video/x-fli',
  6138. 'flo' => 'application/vnd.micrografx.flo',
  6139. 'flv' => 'video/x-flv',
  6140. 'flw' => 'application/vnd.kde.kivio',
  6141. 'flx' => 'text/vnd.fmi.flexstor',
  6142. 'fly' => 'text/vnd.fly',
  6143. 'fm' => 'application/vnd.framemaker',
  6144. 'fnc' => 'application/vnd.frogans.fnc',
  6145. 'for' => 'text/x-fortran',
  6146. 'fpx' => 'image/vnd.fpx',
  6147. 'frame' => 'application/vnd.framemaker',
  6148. 'fsc' => 'application/vnd.fsc.weblaunch',
  6149. 'fst' => 'image/vnd.fst',
  6150. 'ftc' => 'application/vnd.fluxtime.clip',
  6151. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  6152. 'fvt' => 'video/vnd.fvt',
  6153. 'fxp' => 'application/vnd.adobe.fxp',
  6154. 'fxpl' => 'application/vnd.adobe.fxp',
  6155. 'fzs' => 'application/vnd.fuzzysheet',
  6156. 'g2w' => 'application/vnd.geoplan',
  6157. 'g3' => 'image/g3fax',
  6158. 'g3w' => 'application/vnd.geospace',
  6159. 'gac' => 'application/vnd.groove-account',
  6160. 'gam' => 'application/x-tads',
  6161. 'gbr' => 'application/rpki-ghostbusters',
  6162. 'gca' => 'application/x-gca-compressed',
  6163. 'gdl' => 'model/vnd.gdl',
  6164. 'geo' => 'application/vnd.dynageo',
  6165. 'gex' => 'application/vnd.geometry-explorer',
  6166. 'ggb' => 'application/vnd.geogebra.file',
  6167. 'ggt' => 'application/vnd.geogebra.tool',
  6168. 'ghf' => 'application/vnd.groove-help',
  6169. 'gif' => 'image/gif',
  6170. 'gim' => 'application/vnd.groove-identity-message',
  6171. 'gml' => 'application/gml+xml',
  6172. 'gmx' => 'application/vnd.gmx',
  6173. 'gnumeric' => 'application/x-gnumeric',
  6174. 'gph' => 'application/vnd.flographit',
  6175. 'gpx' => 'application/gpx+xml',
  6176. 'gqf' => 'application/vnd.grafeq',
  6177. 'gqs' => 'application/vnd.grafeq',
  6178. 'gram' => 'application/srgs',
  6179. 'gramps' => 'application/x-gramps-xml',
  6180. 'gre' => 'application/vnd.geometry-explorer',
  6181. 'grv' => 'application/vnd.groove-injector',
  6182. 'grxml' => 'application/srgs+xml',
  6183. 'gsf' => 'application/x-font-ghostscript',
  6184. 'gtar' => 'application/x-gtar',
  6185. 'gtm' => 'application/vnd.groove-tool-message',
  6186. 'gtw' => 'model/vnd.gtw',
  6187. 'gv' => 'text/vnd.graphviz',
  6188. 'gxf' => 'application/gxf',
  6189. 'gxt' => 'application/vnd.geonext',
  6190. 'h' => 'text/x-c',
  6191. 'h261' => 'video/h261',
  6192. 'h263' => 'video/h263',
  6193. 'h264' => 'video/h264',
  6194. 'hal' => 'application/vnd.hal+xml',
  6195. 'hbci' => 'application/vnd.hbci',
  6196. 'hdf' => 'application/x-hdf',
  6197. 'hh' => 'text/x-c',
  6198. 'hlp' => 'application/winhlp',
  6199. 'hpgl' => 'application/vnd.hp-hpgl',
  6200. 'hpid' => 'application/vnd.hp-hpid',
  6201. 'hps' => 'application/vnd.hp-hps',
  6202. 'hqx' => 'application/mac-binhex40',
  6203. 'htke' => 'application/vnd.kenameaapp',
  6204. 'htm' => 'text/html',
  6205. 'html' => 'text/html',
  6206. 'hvd' => 'application/vnd.yamaha.hv-dic',
  6207. 'hvp' => 'application/vnd.yamaha.hv-voice',
  6208. 'hvs' => 'application/vnd.yamaha.hv-script',
  6209. 'i2g' => 'application/vnd.intergeo',
  6210. 'icc' => 'application/vnd.iccprofile',
  6211. 'ice' => 'x-conference/x-cooltalk',
  6212. 'icm' => 'application/vnd.iccprofile',
  6213. 'ico' => 'image/x-icon',
  6214. 'ics' => 'text/calendar',
  6215. 'ief' => 'image/ief',
  6216. 'ifb' => 'text/calendar',
  6217. 'ifm' => 'application/vnd.shana.informed.formdata',
  6218. 'iges' => 'model/iges',
  6219. 'igl' => 'application/vnd.igloader',
  6220. 'igm' => 'application/vnd.insors.igm',
  6221. 'igs' => 'model/iges',
  6222. 'igx' => 'application/vnd.micrografx.igx',
  6223. 'iif' => 'application/vnd.shana.informed.interchange',
  6224. 'imp' => 'application/vnd.accpac.simply.imp',
  6225. 'ims' => 'application/vnd.ms-ims',
  6226. 'in' => 'text/plain',
  6227. 'ink' => 'application/inkml+xml',
  6228. 'inkml' => 'application/inkml+xml',
  6229. 'install' => 'application/x-install-instructions',
  6230. 'iota' => 'application/vnd.astraea-software.iota',
  6231. 'ipfix' => 'application/ipfix',
  6232. 'ipk' => 'application/vnd.shana.informed.package',
  6233. 'irm' => 'application/vnd.ibm.rights-management',
  6234. 'irp' => 'application/vnd.irepository.package+xml',
  6235. 'iso' => 'application/x-iso9660-image',
  6236. 'itp' => 'application/vnd.shana.informed.formtemplate',
  6237. 'ivp' => 'application/vnd.immervision-ivp',
  6238. 'ivu' => 'application/vnd.immervision-ivu',
  6239. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  6240. 'jam' => 'application/vnd.jam',
  6241. 'jar' => 'application/java-archive',
  6242. 'java' => 'text/x-java-source',
  6243. 'jisp' => 'application/vnd.jisp',
  6244. 'jlt' => 'application/vnd.hp-jlyt',
  6245. 'jnlp' => 'application/x-java-jnlp-file',
  6246. 'joda' => 'application/vnd.joost.joda-archive',
  6247. 'jpe' => 'image/jpeg',
  6248. 'jpeg' => 'image/jpeg',
  6249. 'jpg' => 'image/jpeg',
  6250. 'jpgm' => 'video/jpm',
  6251. 'jpgv' => 'video/jpeg',
  6252. 'jpm' => 'video/jpm',
  6253. 'js' => 'application/javascript',
  6254. 'json' => 'application/json',
  6255. 'jsonml' => 'application/jsonml+json',
  6256. 'kar' => 'audio/midi',
  6257. 'karbon' => 'application/vnd.kde.karbon',
  6258. 'kfo' => 'application/vnd.kde.kformula',
  6259. 'kia' => 'application/vnd.kidspiration',
  6260. 'kml' => 'application/vnd.google-earth.kml+xml',
  6261. 'kmz' => 'application/vnd.google-earth.kmz',
  6262. 'kne' => 'application/vnd.kinar',
  6263. 'knp' => 'application/vnd.kinar',
  6264. 'kon' => 'application/vnd.kde.kontour',
  6265. 'kpr' => 'application/vnd.kde.kpresenter',
  6266. 'kpt' => 'application/vnd.kde.kpresenter',
  6267. 'kpxx' => 'application/vnd.ds-keypoint',
  6268. 'ksp' => 'application/vnd.kde.kspread',
  6269. 'ktr' => 'application/vnd.kahootz',
  6270. 'ktx' => 'image/ktx',
  6271. 'ktz' => 'application/vnd.kahootz',
  6272. 'kwd' => 'application/vnd.kde.kword',
  6273. 'kwt' => 'application/vnd.kde.kword',
  6274. 'lasxml' => 'application/vnd.las.las+xml',
  6275. 'latex' => 'application/x-latex',
  6276. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  6277. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  6278. 'les' => 'application/vnd.hhe.lesson-player',
  6279. 'lha' => 'application/x-lzh-compressed',
  6280. 'link66' => 'application/vnd.route66.link66+xml',
  6281. 'list' => 'text/plain',
  6282. 'list3820' => 'application/vnd.ibm.modcap',
  6283. 'listafp' => 'application/vnd.ibm.modcap',
  6284. 'lnk' => 'application/x-ms-shortcut',
  6285. 'log' => 'text/plain',
  6286. 'lostxml' => 'application/lost+xml',
  6287. 'lrf' => 'application/octet-stream',
  6288. 'lrm' => 'application/vnd.ms-lrm',
  6289. 'ltf' => 'application/vnd.frogans.ltf',
  6290. 'lvp' => 'audio/vnd.lucent.voice',
  6291. 'lwp' => 'application/vnd.lotus-wordpro',
  6292. 'lzh' => 'application/x-lzh-compressed',
  6293. 'm13' => 'application/x-msmediaview',
  6294. 'm14' => 'application/x-msmediaview',
  6295. 'm1v' => 'video/mpeg',
  6296. 'm21' => 'application/mp21',
  6297. 'm2a' => 'audio/mpeg',
  6298. 'm2v' => 'video/mpeg',
  6299. 'm3a' => 'audio/mpeg',
  6300. 'm3u' => 'audio/x-mpegurl',
  6301. 'm3u8' => 'application/vnd.apple.mpegurl',
  6302. 'm4a' => 'audio/mp4',
  6303. 'm4u' => 'video/vnd.mpegurl',
  6304. 'm4v' => 'video/x-m4v',
  6305. 'ma' => 'application/mathematica',
  6306. 'mads' => 'application/mads+xml',
  6307. 'mag' => 'application/vnd.ecowin.chart',
  6308. 'maker' => 'application/vnd.framemaker',
  6309. 'man' => 'text/troff',
  6310. 'mar' => 'application/octet-stream',
  6311. 'mathml' => 'application/mathml+xml',
  6312. 'mb' => 'application/mathematica',
  6313. 'mbk' => 'application/vnd.mobius.mbk',
  6314. 'mbox' => 'application/mbox',
  6315. 'mc1' => 'application/vnd.medcalcdata',
  6316. 'mcd' => 'application/vnd.mcd',
  6317. 'mcurl' => 'text/vnd.curl.mcurl',
  6318. 'mdb' => 'application/x-msaccess',
  6319. 'mdi' => 'image/vnd.ms-modi',
  6320. 'me' => 'text/troff',
  6321. 'mesh' => 'model/mesh',
  6322. 'meta4' => 'application/metalink4+xml',
  6323. 'metalink' => 'application/metalink+xml',
  6324. 'mets' => 'application/mets+xml',
  6325. 'mfm' => 'application/vnd.mfmp',
  6326. 'mft' => 'application/rpki-manifest',
  6327. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  6328. 'mgz' => 'application/vnd.proteus.magazine',
  6329. 'mid' => 'audio/midi',
  6330. 'midi' => 'audio/midi',
  6331. 'mie' => 'application/x-mie',
  6332. 'mif' => 'application/vnd.mif',
  6333. 'mime' => 'message/rfc822',
  6334. 'mj2' => 'video/mj2',
  6335. 'mjp2' => 'video/mj2',
  6336. 'mk3d' => 'video/x-matroska',
  6337. 'mka' => 'audio/x-matroska',
  6338. 'mks' => 'video/x-matroska',
  6339. 'mkv' => 'video/x-matroska',
  6340. 'mlp' => 'application/vnd.dolby.mlp',
  6341. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  6342. 'mmf' => 'application/vnd.smaf',
  6343. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  6344. 'mng' => 'video/x-mng',
  6345. 'mny' => 'application/x-msmoney',
  6346. 'mobi' => 'application/x-mobipocket-ebook',
  6347. 'mods' => 'application/mods+xml',
  6348. 'mov' => 'video/quicktime',
  6349. 'movie' => 'video/x-sgi-movie',
  6350. 'mp2' => 'audio/mpeg',
  6351. 'mp21' => 'application/mp21',
  6352. 'mp2a' => 'audio/mpeg',
  6353. 'mp3' => 'audio/mpeg',
  6354. 'mp4' => 'video/mp4',
  6355. 'mp4a' => 'audio/mp4',
  6356. 'mp4s' => 'application/mp4',
  6357. 'mp4v' => 'video/mp4',
  6358. 'mpc' => 'application/vnd.mophun.certificate',
  6359. 'mpe' => 'video/mpeg',
  6360. 'mpeg' => 'video/mpeg',
  6361. 'mpg' => 'video/mpeg',
  6362. 'mpg4' => 'video/mp4',
  6363. 'mpga' => 'audio/mpeg',
  6364. 'mpkg' => 'application/vnd.apple.installer+xml',
  6365. 'mpm' => 'application/vnd.blueice.multipass',
  6366. 'mpn' => 'application/vnd.mophun.application',
  6367. 'mpp' => 'application/vnd.ms-project',
  6368. 'mpt' => 'application/vnd.ms-project',
  6369. 'mpy' => 'application/vnd.ibm.minipay',
  6370. 'mqy' => 'application/vnd.mobius.mqy',
  6371. 'mrc' => 'application/marc',
  6372. 'mrcx' => 'application/marcxml+xml',
  6373. 'ms' => 'text/troff',
  6374. 'mscml' => 'application/mediaservercontrol+xml',
  6375. 'mseed' => 'application/vnd.fdsn.mseed',
  6376. 'mseq' => 'application/vnd.mseq',
  6377. 'msf' => 'application/vnd.epson.msf',
  6378. 'msh' => 'model/mesh',
  6379. 'msi' => 'application/x-msdownload',
  6380. 'msl' => 'application/vnd.mobius.msl',
  6381. 'msty' => 'application/vnd.muvee.style',
  6382. 'mts' => 'model/vnd.mts',
  6383. 'mus' => 'application/vnd.musician',
  6384. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  6385. 'mvb' => 'application/x-msmediaview',
  6386. 'mwf' => 'application/vnd.mfer',
  6387. 'mxf' => 'application/mxf',
  6388. 'mxl' => 'application/vnd.recordare.musicxml',
  6389. 'mxml' => 'application/xv+xml',
  6390. 'mxs' => 'application/vnd.triscape.mxs',
  6391. 'mxu' => 'video/vnd.mpegurl',
  6392. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  6393. 'n3' => 'text/n3',
  6394. 'nb' => 'application/mathematica',
  6395. 'nbp' => 'application/vnd.wolfram.player',
  6396. 'nc' => 'application/x-netcdf',
  6397. 'ncx' => 'application/x-dtbncx+xml',
  6398. 'nfo' => 'text/x-nfo',
  6399. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  6400. 'nitf' => 'application/vnd.nitf',
  6401. 'nlu' => 'application/vnd.neurolanguage.nlu',
  6402. 'nml' => 'application/vnd.enliven',
  6403. 'nnd' => 'application/vnd.noblenet-directory',
  6404. 'nns' => 'application/vnd.noblenet-sealer',
  6405. 'nnw' => 'application/vnd.noblenet-web',
  6406. 'npx' => 'image/vnd.net-fpx',
  6407. 'nsc' => 'application/x-conference',
  6408. 'nsf' => 'application/vnd.lotus-notes',
  6409. 'ntf' => 'application/vnd.nitf',
  6410. 'nzb' => 'application/x-nzb',
  6411. 'oa2' => 'application/vnd.fujitsu.oasys2',
  6412. 'oa3' => 'application/vnd.fujitsu.oasys3',
  6413. 'oas' => 'application/vnd.fujitsu.oasys',
  6414. 'obd' => 'application/x-msbinder',
  6415. 'obj' => 'application/x-tgif',
  6416. 'oda' => 'application/oda',
  6417. 'odb' => 'application/vnd.oasis.opendocument.database',
  6418. 'odc' => 'application/vnd.oasis.opendocument.chart',
  6419. 'odf' => 'application/vnd.oasis.opendocument.formula',
  6420. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  6421. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  6422. 'odi' => 'application/vnd.oasis.opendocument.image',
  6423. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  6424. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  6425. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  6426. 'odt' => 'application/vnd.oasis.opendocument.text',
  6427. 'oga' => 'audio/ogg',
  6428. 'ogg' => 'audio/ogg',
  6429. 'ogv' => 'video/ogg',
  6430. 'ogx' => 'application/ogg',
  6431. 'omdoc' => 'application/omdoc+xml',
  6432. 'onepkg' => 'application/onenote',
  6433. 'onetmp' => 'application/onenote',
  6434. 'onetoc' => 'application/onenote',
  6435. 'onetoc2' => 'application/onenote',
  6436. 'opf' => 'application/oebps-package+xml',
  6437. 'opml' => 'text/x-opml',
  6438. 'oprc' => 'application/vnd.palm',
  6439. 'org' => 'application/vnd.lotus-organizer',
  6440. 'osf' => 'application/vnd.yamaha.openscoreformat',
  6441. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  6442. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  6443. 'otf' => 'application/x-font-otf',
  6444. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  6445. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  6446. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  6447. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  6448. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  6449. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  6450. 'oxps' => 'application/oxps',
  6451. 'oxt' => 'application/vnd.openofficeorg.extension',
  6452. 'p' => 'text/x-pascal',
  6453. 'p10' => 'application/pkcs10',
  6454. 'p12' => 'application/x-pkcs12',
  6455. 'p7b' => 'application/x-pkcs7-certificates',
  6456. 'p7c' => 'application/pkcs7-mime',
  6457. 'p7m' => 'application/pkcs7-mime',
  6458. 'p7r' => 'application/x-pkcs7-certreqresp',
  6459. 'p7s' => 'application/pkcs7-signature',
  6460. 'p8' => 'application/pkcs8',
  6461. 'pas' => 'text/x-pascal',
  6462. 'paw' => 'application/vnd.pawaafile',
  6463. 'pbd' => 'application/vnd.powerbuilder6',
  6464. 'pbm' => 'image/x-portable-bitmap',
  6465. 'pcap' => 'application/vnd.tcpdump.pcap',
  6466. 'pcf' => 'application/x-font-pcf',
  6467. 'pcl' => 'application/vnd.hp-pcl',
  6468. 'pclxl' => 'application/vnd.hp-pclxl',
  6469. 'pct' => 'image/x-pict',
  6470. 'pcurl' => 'application/vnd.curl.pcurl',
  6471. 'pcx' => 'image/x-pcx',
  6472. 'pdb' => 'application/vnd.palm',
  6473. 'pdf' => 'application/pdf',
  6474. 'pfa' => 'application/x-font-type1',
  6475. 'pfb' => 'application/x-font-type1',
  6476. 'pfm' => 'application/x-font-type1',
  6477. 'pfr' => 'application/font-tdpfr',
  6478. 'pfx' => 'application/x-pkcs12',
  6479. 'pgm' => 'image/x-portable-graymap',
  6480. 'pgn' => 'application/x-chess-pgn',
  6481. 'pgp' => 'application/pgp-encrypted',
  6482. 'pic' => 'image/x-pict',
  6483. 'pkg' => 'application/octet-stream',
  6484. 'pki' => 'application/pkixcmp',
  6485. 'pkipath' => 'application/pkix-pkipath',
  6486. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  6487. 'plc' => 'application/vnd.mobius.plc',
  6488. 'plf' => 'application/vnd.pocketlearn',
  6489. 'pls' => 'application/pls+xml',
  6490. 'pml' => 'application/vnd.ctc-posml',
  6491. 'png' => 'image/png',
  6492. 'pnm' => 'image/x-portable-anymap',
  6493. 'portpkg' => 'application/vnd.macports.portpkg',
  6494. 'pot' => 'application/vnd.ms-powerpoint',
  6495. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  6496. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  6497. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  6498. 'ppd' => 'application/vnd.cups-ppd',
  6499. 'ppm' => 'image/x-portable-pixmap',
  6500. 'pps' => 'application/vnd.ms-powerpoint',
  6501. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  6502. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  6503. 'ppt' => 'application/vnd.ms-powerpoint',
  6504. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  6505. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  6506. 'pqa' => 'application/vnd.palm',
  6507. 'prc' => 'application/x-mobipocket-ebook',
  6508. 'pre' => 'application/vnd.lotus-freelance',
  6509. 'prf' => 'application/pics-rules',
  6510. 'ps' => 'application/postscript',
  6511. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  6512. 'psd' => 'image/vnd.adobe.photoshop',
  6513. 'psf' => 'application/x-font-linux-psf',
  6514. 'pskcxml' => 'application/pskc+xml',
  6515. 'ptid' => 'application/vnd.pvi.ptid1',
  6516. 'pub' => 'application/x-mspublisher',
  6517. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  6518. 'pwn' => 'application/vnd.3m.post-it-notes',
  6519. 'pya' => 'audio/vnd.ms-playready.media.pya',
  6520. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  6521. 'qam' => 'application/vnd.epson.quickanime',
  6522. 'qbo' => 'application/vnd.intu.qbo',
  6523. 'qfx' => 'application/vnd.intu.qfx',
  6524. 'qps' => 'application/vnd.publishare-delta-tree',
  6525. 'qt' => 'video/quicktime',
  6526. 'qwd' => 'application/vnd.quark.quarkxpress',
  6527. 'qwt' => 'application/vnd.quark.quarkxpress',
  6528. 'qxb' => 'application/vnd.quark.quarkxpress',
  6529. 'qxd' => 'application/vnd.quark.quarkxpress',
  6530. 'qxl' => 'application/vnd.quark.quarkxpress',
  6531. 'qxt' => 'application/vnd.quark.quarkxpress',
  6532. 'ra' => 'audio/x-pn-realaudio',
  6533. 'ram' => 'audio/x-pn-realaudio',
  6534. 'rar' => 'application/x-rar-compressed',
  6535. 'ras' => 'image/x-cmu-raster',
  6536. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  6537. 'rdf' => 'application/rdf+xml',
  6538. 'rdz' => 'application/vnd.data-vision.rdz',
  6539. 'rep' => 'application/vnd.businessobjects',
  6540. 'res' => 'application/x-dtbresource+xml',
  6541. 'rgb' => 'image/x-rgb',
  6542. 'rif' => 'application/reginfo+xml',
  6543. 'rip' => 'audio/vnd.rip',
  6544. 'ris' => 'application/x-research-info-systems',
  6545. 'rl' => 'application/resource-lists+xml',
  6546. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  6547. 'rld' => 'application/resource-lists-diff+xml',
  6548. 'rm' => 'application/vnd.rn-realmedia',
  6549. 'rmi' => 'audio/midi',
  6550. 'rmp' => 'audio/x-pn-realaudio-plugin',
  6551. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  6552. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  6553. 'rnc' => 'application/relax-ng-compact-syntax',
  6554. 'roa' => 'application/rpki-roa',
  6555. 'roff' => 'text/troff',
  6556. 'rp9' => 'application/vnd.cloanto.rp9',
  6557. 'rpss' => 'application/vnd.nokia.radio-presets',
  6558. 'rpst' => 'application/vnd.nokia.radio-preset',
  6559. 'rq' => 'application/sparql-query',
  6560. 'rs' => 'application/rls-services+xml',
  6561. 'rsd' => 'application/rsd+xml',
  6562. 'rss' => 'application/rss+xml',
  6563. 'rtf' => 'application/rtf',
  6564. 'rtx' => 'text/richtext',
  6565. 's' => 'text/x-asm',
  6566. 's3m' => 'audio/s3m',
  6567. 'saf' => 'application/vnd.yamaha.smaf-audio',
  6568. 'sbml' => 'application/sbml+xml',
  6569. 'sc' => 'application/vnd.ibm.secure-container',
  6570. 'scd' => 'application/x-msschedule',
  6571. 'scm' => 'application/vnd.lotus-screencam',
  6572. 'scq' => 'application/scvp-cv-request',
  6573. 'scs' => 'application/scvp-cv-response',
  6574. 'scurl' => 'text/vnd.curl.scurl',
  6575. 'sda' => 'application/vnd.stardivision.draw',
  6576. 'sdc' => 'application/vnd.stardivision.calc',
  6577. 'sdd' => 'application/vnd.stardivision.impress',
  6578. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  6579. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  6580. 'sdp' => 'application/sdp',
  6581. 'sdw' => 'application/vnd.stardivision.writer',
  6582. 'see' => 'application/vnd.seemail',
  6583. 'seed' => 'application/vnd.fdsn.seed',
  6584. 'sema' => 'application/vnd.sema',
  6585. 'semd' => 'application/vnd.semd',
  6586. 'semf' => 'application/vnd.semf',
  6587. 'ser' => 'application/java-serialized-object',
  6588. 'setpay' => 'application/set-payment-initiation',
  6589. 'setreg' => 'application/set-registration-initiation',
  6590. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  6591. 'sfs' => 'application/vnd.spotfire.sfs',
  6592. 'sfv' => 'text/x-sfv',
  6593. 'sgi' => 'image/sgi',
  6594. 'sgl' => 'application/vnd.stardivision.writer-global',
  6595. 'sgm' => 'text/sgml',
  6596. 'sgml' => 'text/sgml',
  6597. 'sh' => 'application/x-sh',
  6598. 'shar' => 'application/x-shar',
  6599. 'shf' => 'application/shf+xml',
  6600. 'sid' => 'image/x-mrsid-image',
  6601. 'sig' => 'application/pgp-signature',
  6602. 'sil' => 'audio/silk',
  6603. 'silo' => 'model/mesh',
  6604. 'sis' => 'application/vnd.symbian.install',
  6605. 'sisx' => 'application/vnd.symbian.install',
  6606. 'sit' => 'application/x-stuffit',
  6607. 'sitx' => 'application/x-stuffitx',
  6608. 'skd' => 'application/vnd.koan',
  6609. 'skm' => 'application/vnd.koan',
  6610. 'skp' => 'application/vnd.koan',
  6611. 'skt' => 'application/vnd.koan',
  6612. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  6613. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  6614. 'slt' => 'application/vnd.epson.salt',
  6615. 'sm' => 'application/vnd.stepmania.stepchart',
  6616. 'smf' => 'application/vnd.stardivision.math',
  6617. 'smi' => 'application/smil+xml',
  6618. 'smil' => 'application/smil+xml',
  6619. 'smv' => 'video/x-smv',
  6620. 'smzip' => 'application/vnd.stepmania.package',
  6621. 'snd' => 'audio/basic',
  6622. 'snf' => 'application/x-font-snf',
  6623. 'so' => 'application/octet-stream',
  6624. 'spc' => 'application/x-pkcs7-certificates',
  6625. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  6626. 'spl' => 'application/x-futuresplash',
  6627. 'spot' => 'text/vnd.in3d.spot',
  6628. 'spp' => 'application/scvp-vp-response',
  6629. 'spq' => 'application/scvp-vp-request',
  6630. 'spx' => 'audio/ogg',
  6631. 'sql' => 'application/x-sql',
  6632. 'src' => 'application/x-wais-source',
  6633. 'srt' => 'application/x-subrip',
  6634. 'sru' => 'application/sru+xml',
  6635. 'srx' => 'application/sparql-results+xml',
  6636. 'ssdl' => 'application/ssdl+xml',
  6637. 'sse' => 'application/vnd.kodak-descriptor',
  6638. 'ssf' => 'application/vnd.epson.ssf',
  6639. 'ssml' => 'application/ssml+xml',
  6640. 'st' => 'application/vnd.sailingtracker.track',
  6641. 'stc' => 'application/vnd.sun.xml.calc.template',
  6642. 'std' => 'application/vnd.sun.xml.draw.template',
  6643. 'stf' => 'application/vnd.wt.stf',
  6644. 'sti' => 'application/vnd.sun.xml.impress.template',
  6645. 'stk' => 'application/hyperstudio',
  6646. 'stl' => 'application/vnd.ms-pki.stl',
  6647. 'str' => 'application/vnd.pg.format',
  6648. 'stw' => 'application/vnd.sun.xml.writer.template',
  6649. 'sub' => 'image/vnd.dvb.subtitle',
  6650. 'sub' => 'text/vnd.dvb.subtitle',
  6651. 'sus' => 'application/vnd.sus-calendar',
  6652. 'susp' => 'application/vnd.sus-calendar',
  6653. 'sv4cpio' => 'application/x-sv4cpio',
  6654. 'sv4crc' => 'application/x-sv4crc',
  6655. 'svc' => 'application/vnd.dvb.service',
  6656. 'svd' => 'application/vnd.svd',
  6657. 'svg' => 'image/svg+xml',
  6658. 'svgz' => 'image/svg+xml',
  6659. 'swa' => 'application/x-director',
  6660. 'swf' => 'application/x-shockwave-flash',
  6661. 'swi' => 'application/vnd.aristanetworks.swi',
  6662. 'sxc' => 'application/vnd.sun.xml.calc',
  6663. 'sxd' => 'application/vnd.sun.xml.draw',
  6664. 'sxg' => 'application/vnd.sun.xml.writer.global',
  6665. 'sxi' => 'application/vnd.sun.xml.impress',
  6666. 'sxm' => 'application/vnd.sun.xml.math',
  6667. 'sxw' => 'application/vnd.sun.xml.writer',
  6668. 't' => 'text/troff',
  6669. 't3' => 'application/x-t3vm-image',
  6670. 'taglet' => 'application/vnd.mynfc',
  6671. 'tao' => 'application/vnd.tao.intent-module-archive',
  6672. 'tar' => 'application/x-tar',
  6673. 'tcap' => 'application/vnd.3gpp2.tcap',
  6674. 'tcl' => 'application/x-tcl',
  6675. 'teacher' => 'application/vnd.smart.teacher',
  6676. 'tei' => 'application/tei+xml',
  6677. 'teicorpus' => 'application/tei+xml',
  6678. 'tex' => 'application/x-tex',
  6679. 'texi' => 'application/x-texinfo',
  6680. 'texinfo' => 'application/x-texinfo',
  6681. 'text' => 'text/plain',
  6682. 'tfi' => 'application/thraud+xml',
  6683. 'tfm' => 'application/x-tex-tfm',
  6684. 'tga' => 'image/x-tga',
  6685. 'thmx' => 'application/vnd.ms-officetheme',
  6686. 'tif' => 'image/tiff',
  6687. 'tiff' => 'image/tiff',
  6688. 'tmo' => 'application/vnd.tmobile-livetv',
  6689. 'torrent' => 'application/x-bittorrent',
  6690. 'tpl' => 'application/vnd.groove-tool-template',
  6691. 'tpt' => 'application/vnd.trid.tpt',
  6692. 'tr' => 'text/troff',
  6693. 'tra' => 'application/vnd.trueapp',
  6694. 'trm' => 'application/x-msterminal',
  6695. 'tsd' => 'application/timestamped-data',
  6696. 'tsv' => 'text/tab-separated-values',
  6697. 'ttc' => 'application/x-font-ttf',
  6698. 'ttf' => 'application/x-font-ttf',
  6699. 'ttl' => 'text/turtle',
  6700. 'twd' => 'application/vnd.simtech-mindmapper',
  6701. 'twds' => 'application/vnd.simtech-mindmapper',
  6702. 'txd' => 'application/vnd.genomatix.tuxedo',
  6703. 'txf' => 'application/vnd.mobius.txf',
  6704. 'txt' => 'text/plain',
  6705. 'u32' => 'application/x-authorware-bin',
  6706. 'udeb' => 'application/x-debian-package',
  6707. 'ufd' => 'application/vnd.ufdl',
  6708. 'ufdl' => 'application/vnd.ufdl',
  6709. 'ulx' => 'application/x-glulx',
  6710. 'umj' => 'application/vnd.umajin',
  6711. 'unityweb' => 'application/vnd.unity',
  6712. 'uoml' => 'application/vnd.uoml+xml',
  6713. 'uri' => 'text/uri-list',
  6714. 'uris' => 'text/uri-list',
  6715. 'urls' => 'text/uri-list',
  6716. 'ustar' => 'application/x-ustar',
  6717. 'utz' => 'application/vnd.uiq.theme',
  6718. 'uu' => 'text/x-uuencode',
  6719. 'uva' => 'audio/vnd.dece.audio',
  6720. 'uvd' => 'application/vnd.dece.data',
  6721. 'uvf' => 'application/vnd.dece.data',
  6722. 'uvg' => 'image/vnd.dece.graphic',
  6723. 'uvh' => 'video/vnd.dece.hd',
  6724. 'uvi' => 'image/vnd.dece.graphic',
  6725. 'uvm' => 'video/vnd.dece.mobile',
  6726. 'uvp' => 'video/vnd.dece.pd',
  6727. 'uvs' => 'video/vnd.dece.sd',
  6728. 'uvt' => 'application/vnd.dece.ttml+xml',
  6729. 'uvu' => 'video/vnd.uvvu.mp4',
  6730. 'uvv' => 'video/vnd.dece.video',
  6731. 'uvva' => 'audio/vnd.dece.audio',
  6732. 'uvvd' => 'application/vnd.dece.data',
  6733. 'uvvf' => 'application/vnd.dece.data',
  6734. 'uvvg' => 'image/vnd.dece.graphic',
  6735. 'uvvh' => 'video/vnd.dece.hd',
  6736. 'uvvi' => 'image/vnd.dece.graphic',
  6737. 'uvvm' => 'video/vnd.dece.mobile',
  6738. 'uvvp' => 'video/vnd.dece.pd',
  6739. 'uvvs' => 'video/vnd.dece.sd',
  6740. 'uvvt' => 'application/vnd.dece.ttml+xml',
  6741. 'uvvu' => 'video/vnd.uvvu.mp4',
  6742. 'uvvv' => 'video/vnd.dece.video',
  6743. 'uvvx' => 'application/vnd.dece.unspecified',
  6744. 'uvvz' => 'application/vnd.dece.zip',
  6745. 'uvx' => 'application/vnd.dece.unspecified',
  6746. 'uvz' => 'application/vnd.dece.zip',
  6747. 'vcard' => 'text/vcard',
  6748. 'vcd' => 'application/x-cdlink',
  6749. 'vcf' => 'text/x-vcard',
  6750. 'vcg' => 'application/vnd.groove-vcard',
  6751. 'vcs' => 'text/x-vcalendar',
  6752. 'vcx' => 'application/vnd.vcx',
  6753. 'vis' => 'application/vnd.visionary',
  6754. 'viv' => 'video/vnd.vivo',
  6755. 'vob' => 'video/x-ms-vob',
  6756. 'vor' => 'application/vnd.stardivision.writer',
  6757. 'vox' => 'application/x-authorware-bin',
  6758. 'vrml' => 'model/vrml',
  6759. 'vsd' => 'application/vnd.visio',
  6760. 'vsf' => 'application/vnd.vsf',
  6761. 'vss' => 'application/vnd.visio',
  6762. 'vst' => 'application/vnd.visio',
  6763. 'vsw' => 'application/vnd.visio',
  6764. 'vtu' => 'model/vnd.vtu',
  6765. 'vxml' => 'application/voicexml+xml',
  6766. 'w3d' => 'application/x-director',
  6767. 'wad' => 'application/x-doom',
  6768. 'wav' => 'audio/x-wav',
  6769. 'wax' => 'audio/x-ms-wax',
  6770. 'wbmp' => 'image/vnd.wap.wbmp',
  6771. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  6772. 'wbxml' => 'application/vnd.wap.wbxml',
  6773. 'wcm' => 'application/vnd.ms-works',
  6774. 'wdb' => 'application/vnd.ms-works',
  6775. 'wdp' => 'image/vnd.ms-photo',
  6776. 'weba' => 'audio/webm',
  6777. 'webm' => 'video/webm',
  6778. 'webp' => 'image/webp',
  6779. 'wg' => 'application/vnd.pmi.widget',
  6780. 'wgt' => 'application/widget',
  6781. 'wks' => 'application/vnd.ms-works',
  6782. 'wm' => 'video/x-ms-wm',
  6783. 'wma' => 'audio/x-ms-wma',
  6784. 'wmd' => 'application/x-ms-wmd',
  6785. 'wmf' => 'application/x-msmetafile',
  6786. 'wml' => 'text/vnd.wap.wml',
  6787. 'wmlc' => 'application/vnd.wap.wmlc',
  6788. 'wmls' => 'text/vnd.wap.wmlscript',
  6789. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  6790. 'wmv' => 'video/x-ms-wmv',
  6791. 'wmx' => 'video/x-ms-wmx',
  6792. 'wmz' => 'application/x-ms-wmz',
  6793. 'wmz' => 'application/x-msmetafile',
  6794. 'woff' => 'application/font-woff',
  6795. 'wpd' => 'application/vnd.wordperfect',
  6796. 'wpl' => 'application/vnd.ms-wpl',
  6797. 'wps' => 'application/vnd.ms-works',
  6798. 'wqd' => 'application/vnd.wqd',
  6799. 'wri' => 'application/x-mswrite',
  6800. 'wrl' => 'model/vrml',
  6801. 'wsdl' => 'application/wsdl+xml',
  6802. 'wspolicy' => 'application/wspolicy+xml',
  6803. 'wtb' => 'application/vnd.webturbo',
  6804. 'wvx' => 'video/x-ms-wvx',
  6805. 'x32' => 'application/x-authorware-bin',
  6806. 'x3d' => 'model/x3d+xml',
  6807. 'x3db' => 'model/x3d+binary',
  6808. 'x3dbz' => 'model/x3d+binary',
  6809. 'x3dv' => 'model/x3d+vrml',
  6810. 'x3dvz' => 'model/x3d+vrml',
  6811. 'x3dz' => 'model/x3d+xml',
  6812. 'xaml' => 'application/xaml+xml',
  6813. 'xap' => 'application/x-silverlight-app',
  6814. 'xar' => 'application/vnd.xara',
  6815. 'xbap' => 'application/x-ms-xbap',
  6816. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  6817. 'xbm' => 'image/x-xbitmap',
  6818. 'xdf' => 'application/xcap-diff+xml',
  6819. 'xdm' => 'application/vnd.syncml.dm+xml',
  6820. 'xdp' => 'application/vnd.adobe.xdp+xml',
  6821. 'xdssc' => 'application/dssc+xml',
  6822. 'xdw' => 'application/vnd.fujixerox.docuworks',
  6823. 'xenc' => 'application/xenc+xml',
  6824. 'xer' => 'application/patch-ops-error+xml',
  6825. 'xfdf' => 'application/vnd.adobe.xfdf',
  6826. 'xfdl' => 'application/vnd.xfdl',
  6827. 'xht' => 'application/xhtml+xml',
  6828. 'xhtml' => 'application/xhtml+xml',
  6829. 'xhvml' => 'application/xv+xml',
  6830. 'xif' => 'image/vnd.xiff',
  6831. 'xla' => 'application/vnd.ms-excel',
  6832. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  6833. 'xlc' => 'application/vnd.ms-excel',
  6834. 'xlf' => 'application/x-xliff+xml',
  6835. 'xlm' => 'application/vnd.ms-excel',
  6836. 'xls' => 'application/vnd.ms-excel',
  6837. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  6838. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  6839. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  6840. 'xlt' => 'application/vnd.ms-excel',
  6841. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  6842. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  6843. 'xlw' => 'application/vnd.ms-excel',
  6844. 'xm' => 'audio/xm',
  6845. 'xml' => 'application/xml',
  6846. 'xo' => 'application/vnd.olpc-sugar',
  6847. 'xop' => 'application/xop+xml',
  6848. 'xpi' => 'application/x-xpinstall',
  6849. 'xpl' => 'application/xproc+xml',
  6850. 'xpm' => 'image/x-xpixmap',
  6851. 'xpr' => 'application/vnd.is-xpr',
  6852. 'xps' => 'application/vnd.ms-xpsdocument',
  6853. 'xpw' => 'application/vnd.intercon.formnet',
  6854. 'xpx' => 'application/vnd.intercon.formnet',
  6855. 'xsl' => 'application/xml',
  6856. 'xslt' => 'application/xslt+xml',
  6857. 'xsm' => 'application/vnd.syncml+xml',
  6858. 'xspf' => 'application/xspf+xml',
  6859. 'xul' => 'application/vnd.mozilla.xul+xml',
  6860. 'xvm' => 'application/xv+xml',
  6861. 'xvml' => 'application/xv+xml',
  6862. 'xwd' => 'image/x-xwindowdump',
  6863. 'xyz' => 'chemical/x-xyz',
  6864. 'xz' => 'application/x-xz',
  6865. 'yang' => 'application/yang',
  6866. 'yin' => 'application/yin+xml',
  6867. 'z1' => 'application/x-zmachine',
  6868. 'z2' => 'application/x-zmachine',
  6869. 'z3' => 'application/x-zmachine',
  6870. 'z4' => 'application/x-zmachine',
  6871. 'z5' => 'application/x-zmachine',
  6872. 'z6' => 'application/x-zmachine',
  6873. 'z7' => 'application/x-zmachine',
  6874. 'z8' => 'application/x-zmachine',
  6875. 'zaz' => 'application/vnd.zzazz.deck+xml',
  6876. 'zip' => 'application/zip',
  6877. 'zir' => 'application/vnd.zul',
  6878. 'zirz' => 'application/vnd.zul',
  6879. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  6880. );
  6881. }
  6882. // Always run this
  6883. dependCheck();