functions.php 346 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.5001');
  5. // ===================================
  6. use Kryptonit3\Sonarr\Sonarr;
  7. use Kryptonit3\SickRage\SickRage;
  8. //homepage order
  9. function homepageOrder(){
  10. $homepageOrder = array(
  11. "homepageOrdercustomhtml" => homepageOrdercustomhtml,
  12. "homepageOrdernotice" => homepageOrdernotice,
  13. "homepageOrderplexsearch" => homepageOrderplexsearch,
  14. "homepageOrderspeedtest" => homepageOrderspeedtest,
  15. "homepageOrdernzbget" => homepageOrdernzbget,
  16. "homepageOrdersabnzbd" => homepageOrdersabnzbd,
  17. "homepageOrderplexnowplaying" => homepageOrderplexnowplaying,
  18. "homepageOrderplexrecent" => homepageOrderplexrecent,
  19. "homepageOrderplexplaylist" => homepageOrderplexplaylist,
  20. "homepageOrderembynowplaying" => homepageOrderembynowplaying,
  21. "homepageOrderembyrecent" => homepageOrderembyrecent,
  22. "homepageOrderombi" => homepageOrderombi,
  23. "homepageOrdercalendar" => homepageOrdercalendar,
  24. );
  25. asort($homepageOrder);
  26. return $homepageOrder;
  27. }
  28. // Debugging output functions
  29. function debug_out($variable, $die = false) {
  30. $trace = debug_backtrace()[0];
  31. echo "<center><img height='200px' src='images/confused.png'></center>";
  32. echo "<center>Look's like something happened, here are the errors and perhaps how to fix them:</center>";
  33. 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>';
  34. if ($die) { http_response_code(503); die(); }
  35. }
  36. // ==== Auth Plugins START ====
  37. if (function_exists('ldap_connect')) :
  38. // Pass credentials to LDAP backend
  39. function plugin_auth_ldap($username, $password) {
  40. $ldapServers = explode(',',AUTHBACKENDHOST);
  41. foreach($ldapServers as $key => $value) {
  42. // Calculate parts
  43. $digest = parse_url(trim($value));
  44. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  45. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  46. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  47. // Reassign
  48. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  49. }
  50. // returns true or false
  51. $ldap = ldap_connect(implode(' ',$ldapServers));
  52. if(empty(AUTHBACKENDDOMAINFORMAT)){
  53. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  54. writeLog("success", "LDAP authentication success");
  55. return true;
  56. } else {
  57. writeLog("error", "LDAP could not authenticate");
  58. return false;
  59. }
  60. }else{
  61. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  62. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  63. $bind = @ldap_bind($ldap, sprintf(AUTHBACKENDDOMAINFORMAT, $username), $password);
  64. if ($bind) {
  65. writeLog("success", "LDAP authentication success");
  66. return true;
  67. } else {
  68. writeLog("error", "LDPA could not authenticate");
  69. return false;
  70. }
  71. }
  72. writeLog("error", "LDAP could not authenticate");
  73. return false;
  74. }
  75. else :
  76. // Ldap Auth Missing Dependancy
  77. function plugin_auth_ldap_disabled() {
  78. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  79. }
  80. endif;
  81. // Pass credentials to FTP backend
  82. function plugin_auth_ftp($username, $password) {
  83. // Calculate parts
  84. $digest = parse_url(AUTHBACKENDHOST);
  85. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  86. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  87. $port = (isset($digest['port'])?$digest['port']:21);
  88. // Determine Connection Type
  89. if ($scheme == 'ftps') {
  90. $conn_id = ftp_ssl_connect($host, $port, 20);
  91. } elseif ($scheme == 'ftp') {
  92. $conn_id = ftp_connect($host, $port, 20);
  93. } else {
  94. debug_out('Invalid FTP scheme. Use ftp or ftps');
  95. writeLog("error", "invalid FTP scheme");
  96. return false;
  97. }
  98. // Check if valid FTP connection
  99. if ($conn_id) {
  100. // Attempt login
  101. @$login_result = ftp_login($conn_id, $username, $password);
  102. ftp_close($conn_id);
  103. // Return Result
  104. if ($login_result) {
  105. writeLog("success", "$username authenticated");
  106. return true;
  107. } else {
  108. writeLog("error", "$username could not authenticate");
  109. return false;
  110. }
  111. } else {
  112. return false;
  113. }
  114. return false;
  115. }
  116. // Pass credentials to Emby Backend
  117. function plugin_auth_emby_local($username, $password) {
  118. $embyAddress = qualifyURL(EMBYURL);
  119. $headers = array(
  120. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  121. 'Content-Type' => 'application/json',
  122. );
  123. $body = array(
  124. 'Username' => $username,
  125. 'Password' => sha1($password),
  126. 'PasswordMd5' => md5($password),
  127. );
  128. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  129. if (isset($response['content'])) {
  130. $json = json_decode($response['content'], true);
  131. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  132. // Login Success - Now Logout Emby Session As We No Longer Need It
  133. $headers = array(
  134. 'X-Mediabrowser-Token' => $json['AccessToken'],
  135. );
  136. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  137. return true;
  138. }
  139. }
  140. return false;
  141. }
  142. if (function_exists('curl_version')) :
  143. // Authenticate Against Emby Local (first) and Emby Connect
  144. function plugin_auth_emby_all($username, $password) {
  145. $localResult = plugin_auth_emby_local($username, $password);
  146. if ($localResult) {
  147. return $localResult;
  148. } else {
  149. return plugin_auth_emby_connect($username, $password);
  150. }
  151. }
  152. // Authenicate against emby connect
  153. function plugin_auth_emby_connect($username, $password) {
  154. $embyAddress = qualifyURL(EMBYURL);
  155. // Get A User
  156. $connectId = '';
  157. $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  158. if (is_array($userIds)) {
  159. foreach ($userIds as $key => $value) { // Scan for this user
  160. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  161. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  162. $connectId = $value['ConnectUserId'];
  163. break;
  164. }
  165. }
  166. }
  167. if ($connectId) {
  168. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  169. $headers = array(
  170. 'Accept'=> 'application/json',
  171. 'Content-Type' => 'application/x-www-form-urlencoded',
  172. );
  173. $body = array(
  174. 'nameOrEmail' => $username,
  175. 'rawpw' => $password,
  176. );
  177. $result = curl_post($connectURL, $body, $headers);
  178. if (isset($result['content'])) {
  179. $json = json_decode($result['content'], true);
  180. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  181. return array(
  182. 'email' => $json['User']['Email'],
  183. 'image' => $json['User']['ImageUrl'],
  184. );
  185. }
  186. }
  187. }
  188. }
  189. return false;
  190. }
  191. // Pass credentials to Plex Backend
  192. function plugin_auth_plex($username, $password) {
  193. // Quick out
  194. $isAdmin = false;
  195. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  196. writeLog("success", "Admin: ".$username." authenticated by plex");
  197. //return true;
  198. $isAdmin = true;
  199. }
  200. //Get User List
  201. $userURL = 'https://plex.tv/pms/friends/all';
  202. $userHeaders = array(
  203. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  204. );
  205. libxml_use_internal_errors(true);
  206. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  207. if (is_array($userXML) || is_object($userXML)) {
  208. $isUser = false;
  209. $usernameLower = strtolower($username);
  210. foreach($userXML AS $child) {
  211. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  212. $isUser = true;
  213. writeLog("success", $usernameLower." was found in plex friends list");
  214. break;
  215. }
  216. }
  217. if ($isUser || $isAdmin) {
  218. //Login User
  219. $connectURL = 'https://plex.tv/users/sign_in.json';
  220. $headers = array(
  221. 'Accept'=> 'application/json',
  222. 'Content-Type' => 'application/x-www-form-urlencoded',
  223. 'X-Plex-Product' => 'Organizr',
  224. 'X-Plex-Version' => '1.0',
  225. 'X-Plex-Client-Identifier' => '01010101-10101010',
  226. );
  227. $body = array(
  228. 'user[login]' => $username,
  229. 'user[password]' => $password,
  230. );
  231. $result = curl_post($connectURL, $body, $headers);
  232. if (isset($result['content'])) {
  233. $json = json_decode($result['content'], true);
  234. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  235. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  236. return array(
  237. 'email' => $json['user']['email'],
  238. 'image' => $json['user']['thumb'],
  239. 'token' => $json['user']['authToken']
  240. );
  241. }
  242. }
  243. }else{
  244. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  245. }
  246. }else{
  247. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  248. }
  249. return false;
  250. }
  251. else :
  252. // Plex Auth Missing Dependancy
  253. function plugin_auth_plex_disabled() {
  254. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  255. }
  256. // Emby Connect Auth Missing Dependancy
  257. function plugin_auth_emby_connect_disabled() {
  258. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  259. }
  260. // Emby Both Auth Missing Dependancy
  261. function plugin_auth_emby_both_disabled() {
  262. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  263. }
  264. endif;
  265. // ==== Auth Plugins END ====
  266. // ==== General Class Definitions START ====
  267. $userLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  268. class setLanguage {
  269. private $language = null;
  270. private $langCode = null;
  271. function __construct($language = false) {
  272. // Default
  273. if (!$language) {
  274. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  275. }
  276. if (!file_exists("lang/{$language}.ini")) {
  277. $language = 'en';
  278. }
  279. $this->langCode = $language;
  280. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  281. if (file_exists("lang/{$language}.cust.ini")) {
  282. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  283. $this->language[$k] = $v;
  284. }
  285. }
  286. }
  287. public function getLang() {
  288. return $this->langCode;
  289. }
  290. public function translate($originalWord) {
  291. $getArg = func_num_args();
  292. if ($getArg > 1) {
  293. $allWords = func_get_args();
  294. array_shift($allWords);
  295. } else {
  296. $allWords = array();
  297. }
  298. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  299. if (!$translatedWord) {
  300. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  301. //echo "WHOA!!!!!!! $originalWord";
  302. }
  303. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  304. return vsprintf($translatedWord, $allWords);
  305. }
  306. }
  307. $language = new setLanguage;
  308. // ==== General Class Definitions END ====
  309. // Direct request to curl if it exists, otherwise handle if not HTTPS
  310. function post_router($url, $data, $headers = array(), $referer='') {
  311. if (function_exists('curl_version')) {
  312. return curl_post($url, $data, $headers, $referer);
  313. } else {
  314. return post_request($url, $data, $headers, $referer);
  315. }
  316. }
  317. if (function_exists('curl_version')) :
  318. // Curl Post
  319. function curl_post($url, $data, $headers = array(), $referer='') {
  320. // Initiate cURL
  321. $curlReq = curl_init($url);
  322. // As post request
  323. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  324. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  325. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  326. if(localURL($url)){
  327. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  328. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  329. }
  330. // Format Data
  331. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  332. case 'application/json':
  333. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  334. break;
  335. case 'application/x-www-form-urlencoded':
  336. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  337. break;
  338. default:
  339. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  340. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  341. }
  342. // Format Headers
  343. $cHeaders = array();
  344. foreach ($headers as $k => $v) {
  345. $cHeaders[] = $k.': '.$v;
  346. }
  347. if (count($cHeaders)) {
  348. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  349. }
  350. // Execute
  351. $result = curl_exec($curlReq);
  352. $httpcode = curl_getinfo($curlReq);
  353. // Close
  354. curl_close($curlReq);
  355. // Return
  356. return array('content'=>$result, 'http_code'=>$httpcode);
  357. }
  358. // Curl Put
  359. function curl_put($url, $data, $headers = array(), $referer='') {
  360. // Initiate cURL
  361. $curlReq = curl_init($url);
  362. // As post request
  363. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "PUT");
  364. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  365. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  366. if(localURL($url)){
  367. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  368. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  369. }
  370. // Format Data
  371. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  372. case 'application/json':
  373. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  374. break;
  375. case 'application/x-www-form-urlencoded':
  376. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  377. break;
  378. default:
  379. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  380. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  381. }
  382. // Format Headers
  383. $cHeaders = array();
  384. foreach ($headers as $k => $v) {
  385. $cHeaders[] = $k.': '.$v;
  386. }
  387. if (count($cHeaders)) {
  388. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  389. }
  390. // Execute
  391. $result = curl_exec($curlReq);
  392. $httpcode = curl_getinfo($curlReq);
  393. // Close
  394. curl_close($curlReq);
  395. // Return
  396. return array('content'=>$result, 'http_code'=>$httpcode);
  397. }
  398. //Curl Get Function
  399. function curl_get($url, $headers = array()) {
  400. // Initiate cURL
  401. $curlReq = curl_init($url);
  402. // As post request
  403. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  404. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  405. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  406. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  407. if(localURL($url)){
  408. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  409. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  410. }
  411. // Format Headers
  412. $cHeaders = array();
  413. foreach ($headers as $k => $v) {
  414. $cHeaders[] = $k.': '.$v;
  415. }
  416. if (count($cHeaders)) {
  417. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  418. }
  419. // Execute
  420. $result = curl_exec($curlReq);
  421. // Close
  422. curl_close($curlReq);
  423. // Return
  424. return $result;
  425. }
  426. //Curl Delete Function
  427. function curl_delete($url, $headers = array()) {
  428. // Initiate cURL
  429. $curlReq = curl_init($url);
  430. // As post request
  431. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  432. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  433. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  434. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  435. if(localURL($url)){
  436. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  437. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  438. }
  439. // Format Headers
  440. $cHeaders = array();
  441. foreach ($headers as $k => $v) {
  442. $cHeaders[] = $k.': '.$v;
  443. }
  444. if (count($cHeaders)) {
  445. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  446. }
  447. // Execute
  448. $result = curl_exec($curlReq);
  449. $httpcode = curl_getinfo($curlReq);
  450. // Close
  451. curl_close($curlReq);
  452. // Return
  453. return array('content'=>$result, 'http_code'=>$httpcode);
  454. }
  455. endif;
  456. //Case-Insensitive Function
  457. function in_arrayi($needle, $haystack) {
  458. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  459. }
  460. // HTTP post request (Removes need for curl, probably useless)
  461. function post_request($url, $data, $headers = array(), $referer='') {
  462. // Adapted from http://stackoverflow.com/a/28387011/6810513
  463. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  464. if (isset($headers['Content-Type'])) {
  465. switch ($headers['Content-Type']) {
  466. case 'application/json':
  467. $data = json_encode($data);
  468. break;
  469. case 'application/x-www-form-urlencoded':
  470. $data = http_build_query($data);
  471. break;
  472. }
  473. } else {
  474. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  475. $data = http_build_query($data);
  476. }
  477. // parse the given URL
  478. $urlDigest = parse_url($url);
  479. // extract host and path:
  480. $host = $urlDigest['host'];
  481. $path = $urlDigest['path'];
  482. if ($urlDigest['scheme'] != 'http') {
  483. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  484. }
  485. // open a socket connection on port 80 - timeout: 30 sec
  486. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  487. if ($fp){
  488. // send the request headers:
  489. fputs($fp, "POST $path HTTP/1.1\r\n");
  490. fputs($fp, "Host: $host\r\n");
  491. if ($referer != '')
  492. fputs($fp, "Referer: $referer\r\n");
  493. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  494. foreach($headers as $k => $v) {
  495. fputs($fp, $k.": ".$v."\r\n");
  496. }
  497. fputs($fp, "Connection: close\r\n\r\n");
  498. fputs($fp, $data);
  499. $result = '';
  500. while(!feof($fp)) {
  501. // receive the results of the request
  502. $result .= fgets($fp, 128);
  503. }
  504. }
  505. else {
  506. return array(
  507. 'status' => 'err',
  508. 'error' => "$errstr ($errno)"
  509. );
  510. }
  511. // close the socket connection:
  512. fclose($fp);
  513. // split the result header from the content
  514. $result = explode("\r\n\r\n", $result, 2);
  515. $header = isset($result[0]) ? $result[0] : '';
  516. $content = isset($result[1]) ? $result[1] : '';
  517. // return as structured array:
  518. return array(
  519. 'status' => 'ok',
  520. 'header' => $header,
  521. 'content' => $content,
  522. );
  523. }
  524. // Format item from Emby for Carousel
  525. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  526. // Static Height
  527. $height = 444;
  528. // Get Item Details
  529. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  530. /*if (substr_count(EMBYURL, ':') == 2) {
  531. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  532. }else{
  533. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  534. }*/
  535. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  536. switch ($itemDetails['Type']) {
  537. case 'Episode':
  538. case 'Series':
  539. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  540. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  541. $width = 300;
  542. $style = '';
  543. $image = 'slick-image-tall';
  544. if(!$nowPlaying){
  545. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  546. $key = $itemDetails['Id'] . "-list";
  547. $itemType = 'season';
  548. }else{
  549. $height = 281;
  550. $width = 500;
  551. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  552. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  553. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  554. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  555. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  556. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  557. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  558. $stream = $moreInfo['PlayState']['PlayMethod'];
  559. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  560. $id = $moreInfo['DeviceId'];
  561. $streamInfo = buildStream(array(
  562. 'platform' => (string) $moreInfo['Client'],
  563. 'device' => (string) $moreInfo['DeviceName'],
  564. 'stream' => streamType($stream),
  565. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  566. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  567. ));
  568. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  569. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  570. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  571. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  572. }
  573. break;
  574. case 'MusicAlbum':
  575. case 'Audio':
  576. $title = $itemDetails['Name'];
  577. $imageId = $itemDetails['Id'];
  578. $width = 444;
  579. $style = '';
  580. $image = 'slick-image-short';
  581. if(!$nowPlaying){
  582. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  583. $key = $itemDetails['Id'] . "-list";
  584. $itemType = 'album';
  585. }else{
  586. $height = 281;
  587. $width = 500;
  588. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  589. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  590. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  591. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  592. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  593. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  594. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  595. $stream = $moreInfo['PlayState']['PlayMethod'];
  596. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  597. $id = $moreInfo['DeviceId'];
  598. $streamInfo = buildStream(array(
  599. 'platform' => (string) $moreInfo['Client'],
  600. 'device' => (string) $moreInfo['DeviceName'],
  601. 'stream' => streamType($stream),
  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">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  606. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  607. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  608. }
  609. break;
  610. case 'TvChannel':
  611. $title = $itemDetails['CurrentProgram']['Name'];
  612. $imageId = $itemDetails['Id'];
  613. $width = 300;
  614. $style = '';
  615. $image = 'slick-image-tall';
  616. if(!$nowPlaying){
  617. $imageType = "Primary";
  618. $key = $itemDetails['Id'] . "-list";
  619. }else{
  620. $height = 281;
  621. $width = 500;
  622. $imageType = "Thumb";
  623. $key = $itemDetails['Id'] . "-np";
  624. $useImage = "images/livetv.png";
  625. $watched = "0";
  626. $stream = $moreInfo['PlayState']['PlayMethod'];
  627. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  628. $id = $moreInfo['DeviceId'];
  629. $streamInfo = buildStream(array(
  630. 'platform' => (string) $moreInfo['Client'],
  631. 'device' => (string) $moreInfo['DeviceName'],
  632. 'stream' => streamType($stream),
  633. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  634. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  635. ));
  636. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  637. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  638. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  639. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  640. }
  641. break;
  642. default:
  643. $title = $itemDetails['Name'];
  644. $imageId = $itemDetails['Id'];
  645. $width = 300;
  646. $style = '';
  647. $image = 'slick-image-tall';
  648. if(!$nowPlaying){
  649. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  650. $key = $itemDetails['Id'] . "-list";
  651. $itemType = 'movie';
  652. }else{
  653. $height = 281;
  654. $width = 500;
  655. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  656. $key = $itemDetails['Id'] . "-np";
  657. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  658. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  659. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  660. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  661. $stream = $moreInfo['PlayState']['PlayMethod'];
  662. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  663. $id = $moreInfo['DeviceId'];
  664. $streamInfo = buildStream(array(
  665. 'platform' => (string) $moreInfo['Client'],
  666. 'device' => (string) $moreInfo['DeviceName'],
  667. 'stream' => streamType($stream),
  668. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  669. 'audio' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  670. ));
  671. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  672. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  673. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  674. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  675. }
  676. }
  677. // If No Overview
  678. if (!isset($itemDetails['Overview'])) {
  679. $itemDetails['Overview'] = '';
  680. }
  681. $original_image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  682. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  683. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  684. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  685. }
  686. if($nowPlaying){
  687. if(!$imageType){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  688. if(!$imageId){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  689. }else{
  690. if(!$imageType){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  691. if(!$imageId){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  692. }
  693. if(isset($useImage)){ $image_url = $useImage; }
  694. // Assemble Item And Cache Into Array
  695. if($nowPlaying){
  696. //prettyPrint($itemDetails);
  697. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="refreshNP w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$URL.'" target="_blank"><img style="width: 100%; display:inherit;" src="'.$image_url.'" alt="'.$itemDetails['Name'].'" original-image="'.$original_image_url.'" class="refreshImageSource"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: 0%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  698. }else{
  699. return '<div class="item-'.$itemType.'"><div class="ultra-widget refreshImage"><span class="w-refresh w-p-icon gray"><span class="fa-stack fa-lg" style="font-size: .4em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-refresh fa-stack-1x fa-inverse"></i></span></span></div><a href="'.$URL.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.' refreshImageSource" data-lazy="'.$image_url.'" original-image="'.$original_image_url.'"></a><small class="elip slick-bottom-title">'.$title.'</small></div>';
  700. }
  701. }
  702. // Format item from Plex for Carousel
  703. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  704. // Static Height
  705. $height = 444;
  706. $widthOverride = 100;
  707. $playlist = ($playlist) ? " playlist-$playlist" : "";
  708. switch ($item['type']) {
  709. case 'season':
  710. $title = $item['parentTitle'];
  711. $summary = $item['parentSummary'];
  712. $width = 300;
  713. $image = 'slick-image-tall';
  714. $style = '';
  715. if(!$nowPlaying){
  716. $thumb = $item['thumb'];
  717. $key = $item['ratingKey'] . "-list";
  718. }else {
  719. $height = 281;
  720. $width = 500;
  721. $thumb = $item['art'];
  722. $key = $item['ratingKey'] . "-np";
  723. $elapsed = $item['viewOffset'];
  724. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  725. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  726. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  727. $stream = $item->Media->Part->Stream['decision'];
  728. $user = $role == "admin" ? $item->User['title'] : "";
  729. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  730. $streamInfo = buildStream(array(
  731. 'platform' => (string) $item->Player['platform'],
  732. 'device' => (string) $item->Player['device'],
  733. 'stream' => streamType($item->Media->Part['decision']),
  734. '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'].")",
  735. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  736. ));
  737. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  738. }
  739. break;
  740. case 'episode':
  741. $title = $item['grandparentTitle'];
  742. $summary = $item['title'];
  743. $width = 300;
  744. $image = 'slick-image-tall';
  745. $style = '';
  746. if(!$nowPlaying){
  747. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  748. $key = $item['ratingKey'] . "-list";
  749. }else {
  750. $height = 281;
  751. $width = 500;
  752. $thumb = $item['art'];
  753. $key = $item['ratingKey'] . "-np";
  754. $elapsed = $item['viewOffset'];
  755. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  756. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  757. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  758. $stream = $item->Media->Part->Stream['decision'];
  759. $user = $role == "admin" ? $item->User['title'] : "";
  760. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  761. $streamInfo = buildStream(array(
  762. 'platform' => (string) $item->Player['platform'],
  763. 'device' => (string) $item->Player['device'],
  764. 'stream' => streamType($item->Media->Part['decision']),
  765. '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'].")",
  766. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  767. ));
  768. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  769. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  770. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  771. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  772. }
  773. break;
  774. case 'clip':
  775. $title = $item['title'];
  776. $summary = $item['summary'];
  777. $width = 300;
  778. $image = 'slick-image-tall';
  779. $style = '';
  780. if(!$nowPlaying){
  781. $thumb = $item['thumb'];
  782. $key = $item['ratingKey'] . "-list";
  783. }else {
  784. $height = 281;
  785. $width = 500;
  786. $thumb = $item['art'];
  787. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  788. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  789. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  790. $elapsed = $item['viewOffset'];
  791. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  792. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  793. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  794. $stream = $item->Media->Part->Stream['decision'];
  795. $user = $role == "admin" ? $item->User['title'] : "";
  796. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  797. $streamInfo = buildStream(array(
  798. 'platform' => (string) $item->Player['platform'],
  799. 'device' => (string) $item->Player['device'],
  800. 'stream' => streamType($item->Media->Part['decision']),
  801. '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'].")",
  802. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  803. ));
  804. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  805. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  806. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  807. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  808. }
  809. break;
  810. case 'album':
  811. case 'track':
  812. $title = $item['parentTitle'];
  813. $summary = $item['title'];
  814. $image = 'slick-image-short';
  815. $style = 'left: 160px !important;';
  816. $item['ratingKey'] = $item['parentRatingKey'];
  817. if(!$nowPlaying){
  818. $width = 444;
  819. $thumb = $item['thumb'];
  820. $key = $item['ratingKey'] . "-list";
  821. }else {
  822. $height = 281;
  823. $width = 500;
  824. $thumb = ($item['art']) ? $item['art'] : $item['parentThumb'];
  825. $widthOverride = ($item['art']) ? 100 : 56;
  826. $key = $item['ratingKey'] . "-np";
  827. $elapsed = $item['viewOffset'];
  828. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  829. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  830. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  831. $stream = $item->Media->Part->Stream['decision'];
  832. $user = $role == "admin" ? $item->User['title'] : "";
  833. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  834. $streamInfo = buildStream(array(
  835. 'platform' => (string) $item->Player['platform'],
  836. 'device' => (string) $item->Player['device'],
  837. 'stream' => streamType($item->Media->Part['decision']),
  838. 'audio' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  839. ));
  840. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  841. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  842. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  843. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  844. }
  845. break;
  846. default:
  847. $title = $item['title'];
  848. $summary = $item['summary'];
  849. $image = 'slick-image-tall';
  850. $style = '';
  851. if(!$nowPlaying){
  852. $width = 300;
  853. $thumb = $item['thumb'];
  854. $key = $item['ratingKey'] . "-list";
  855. }else {
  856. $height = 281;
  857. $width = 500;
  858. $thumb = $item['art'];
  859. $key = $item['ratingKey'] . "-np";
  860. $elapsed = $item['viewOffset'];
  861. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  862. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  863. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  864. $stream = $item->Media->Part->Stream['decision'];
  865. $user = $role == "admin" ? $item->User['title'] : "";
  866. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  867. $streamInfo = buildStream(array(
  868. 'platform' => (string) $item->Player['platform'],
  869. 'device' => (string) $item->Player['device'],
  870. 'stream' => streamType($item->Media->Part['decision']),
  871. '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'].")",
  872. 'audio' => streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  873. ));
  874. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  875. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  876. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  877. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  878. }
  879. }
  880. if (PLEXTABURL) {
  881. $address = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  882. }else{
  883. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  884. }
  885. // If No Overview
  886. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  887. $original_image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'$'.randString();
  888. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  889. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  890. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  891. }
  892. if($nowPlaying){
  893. if(!$thumb){ $original_image_url = $image_url = "images/no-np.png"; $key = "no-np"; }
  894. }else{
  895. if(!$thumb){ $original_image_url = $image_url = "images/no-list.png"; $key = "no-list"; }
  896. }
  897. if(isset($useImage)){ $image_url = $useImage; }
  898. $openTab = (PLEXTABNAME) ? "true" : "false";
  899. // Assemble Item And Cache Into Array
  900. if($nowPlaying){
  901. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="refreshNP w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><div class="ultra-widget refreshImage"><span class="w-refresh w-p-icon gray"><span class="fa-stack fa-lg" style="font-size: .4em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-refresh fa-stack-1x fa-inverse"></i></span></span></div><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img class="refreshImageSource" style="width: '.$widthOverride.'%; display:block;" src="'.$image_url.'" original-image="'.$original_image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  902. }else{
  903. return '<div class="item-'.$item['type'].$playlist.'"><div style="" class="ultra-widget refreshImage"><span class="w-refresh w-p-icon gray"><span class="fa-stack fa-lg" style="font-size: .4em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-refresh fa-stack-1x fa-inverse"></i></span></span></div><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.' refreshImageSource" data-lazy="'.$image_url.'" original-image="'.$original_image_url.'"></a><small class="elip slick-bottom-title">'.$title.'</small></div>';
  904. }
  905. }
  906. //$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  907. //Recent Added
  908. function outputRecentAdded($header, $items, $script = false, $array, $type) {
  909. $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">';
  910. if(preg_grep("/item-movie/", $items)){
  911. $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>';
  912. }
  913. if(preg_grep("/item-season/", $items)){
  914. $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>';
  915. }
  916. if(preg_grep("/item-album/", $items)){
  917. $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>';
  918. }
  919. $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>';
  920. $hideMenu .= '</ul></div></div>';
  921. // If None Populate Empty Item
  922. if (!count($items)) {
  923. return '<div id="recentMedia'.$type.'" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Media Found</p></div>';
  924. }else{
  925. $className = str_replace(' ', '', $header.' on '.$type);
  926. return '<div id="recentMedia'.$type.'" class="content-box box-shadow big-box"><h5 id="recentContent-title-'.$type.'" style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-recent-'.$type.'" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  927. }
  928. }
  929. // Create Carousel
  930. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  931. // If None Populate Empty Item
  932. if (!count($items)) {
  933. return '<div id="'.$type.'"></div>'.($script?'<script>'.$script.'</script>':'');
  934. }else{
  935. return '<div id="'.$type.'"><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  936. }
  937. }
  938. // Get Now Playing Streams From Emby
  939. function getEmbyStreams($size, $showNames, $role) {
  940. $address = qualifyURL(EMBYURL);
  941. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  942. if (!is_array($api)) { return 'Could not load!'; }
  943. $playingItems = array();
  944. foreach($api as $key => $value) {
  945. if (isset($value['NowPlayingItem'])) {
  946. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  947. }
  948. }
  949. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY')." ( ".count($playingItems)." Streams )", $size, 'streams-emby', $playingItems, "
  950. setInterval(function() {
  951. $.ajax({
  952. url: 'ajax.php?a=emby-streams',
  953. timeout: 10000,
  954. type: 'GET',
  955. success: function(response) {
  956. var getDiv = response;
  957. var loadedID = $(getDiv).attr('id');
  958. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  959. console.log(loadedID+' has been updated');
  960. },
  961. error: function(jqXHR, textStatus, errorThrown) {
  962. console.error(loadedID+' could not be updated');
  963. }
  964. });
  965. }, ".NOWPLAYINGREFRESH.");
  966. ");
  967. }
  968. // Get Now Playing Streams From Plex
  969. function getPlexStreams($size, $showNames, $role){
  970. $address = qualifyURL(PLEXURL);
  971. // Perform API requests
  972. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  973. libxml_use_internal_errors(true);
  974. $api = simplexml_load_string($api);
  975. if (is_array($api) || is_object($api)){
  976. if (!$api->head->title){
  977. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  978. if (!$getServer) { return 'Could not load!'; }
  979. // Identify the local machine
  980. $gotServer = $getServer['machineIdentifier'];
  981. $items = array();
  982. foreach($api AS $child) {
  983. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  984. }
  985. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, "
  986. setInterval(function() {
  987. $.ajax({
  988. url: 'ajax.php?a=plex-streams',
  989. timeout: 10000,
  990. type: 'GET',
  991. success: function(response) {
  992. var getDiv = response;
  993. var loadedID = $(getDiv).attr('id');
  994. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  995. console.log(loadedID+' has been updated');
  996. },
  997. error: function(jqXHR, textStatus, errorThrown) {
  998. console.error(loadedID+' could not be updated');
  999. }
  1000. });
  1001. }, ".NOWPLAYINGREFRESH.");
  1002. ");
  1003. }else{
  1004. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  1005. }
  1006. }else{
  1007. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1008. }
  1009. }
  1010. // Get Recent Content From Emby
  1011. function getEmbyRecent($array) {
  1012. $address = qualifyURL(EMBYURL);
  1013. $header = translate('RECENT_CONTENT');
  1014. // Currently Logged In User
  1015. $username = false;
  1016. if (isset($GLOBALS['USER'])) {
  1017. $username = strtolower($GLOBALS['USER']->username);
  1018. }
  1019. // Get A User
  1020. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  1021. if (!is_array($userIds)) { return 'Could not load!'; }
  1022. $showPlayed = true;
  1023. foreach ($userIds as $value) { // Scan for admin user
  1024. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  1025. $userId = $value['Id'];
  1026. }
  1027. if ($username && strtolower($value['Name']) == $username) {
  1028. $userId = $value['Id'];
  1029. $showPlayed = false;
  1030. break;
  1031. }
  1032. }
  1033. // Get the latest Items
  1034. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  1035. // For Each Item In Category
  1036. $items = array();
  1037. foreach ($latest as $k => $v) {
  1038. $type = (string) $v['Type'];
  1039. if(@$array[$type] == "true"){
  1040. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  1041. }
  1042. }
  1043. $array["movie"] = $array["Movie"];
  1044. $array["season"] = $array["Episode"];
  1045. $array["album"] = $array["MusicAlbum"];
  1046. unset($array["Movie"]);
  1047. unset($array["Episode"]);
  1048. unset($array["MusicAlbum"]);
  1049. unset($array["Series"]);
  1050. return outputRecentAdded($header, $items, "
  1051. setInterval(function() {
  1052. $.ajax({
  1053. url: 'ajax.php?a=emby-recent',
  1054. timeout: 10000,
  1055. type: 'GET',
  1056. success: function(response) {
  1057. var getDiv = response;
  1058. var loadedID = $(getDiv).attr('id');
  1059. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  1060. loadSlick();
  1061. console.log(loadedID+' has been updated');
  1062. },
  1063. error: function(jqXHR, textStatus, errorThrown) {
  1064. console.error(loadedID+' could not be updated');
  1065. }
  1066. });
  1067. }, ".RECENTREFRESH.");
  1068. ", $array, 'Emby');
  1069. }
  1070. // Get Recent Content From Plex
  1071. function getPlexRecent($array){
  1072. $address = qualifyURL(PLEXURL);
  1073. $header = translate('RECENT_CONTENT');
  1074. // Perform Requests
  1075. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  1076. libxml_use_internal_errors(true);
  1077. $api = simplexml_load_string($api);
  1078. if (is_array($api) || is_object($api)){
  1079. if (!$api->head->title){
  1080. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  1081. if (!$getServer) { return 'Could not load!'; }
  1082. // Identify the local machine
  1083. $gotServer = $getServer['machineIdentifier'];
  1084. $items = array();
  1085. foreach($api AS $child) {
  1086. $type = (string) $child['type'];
  1087. if($array[$type] == "true"){
  1088. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  1089. }
  1090. }
  1091. return outputRecentAdded($header, $items, "
  1092. setInterval(function() {
  1093. $.ajax({
  1094. url: 'ajax.php?a=plex-recent',
  1095. timeout: 10000,
  1096. type: 'GET',
  1097. success: function(response) {
  1098. var getDiv = response;
  1099. var loadedID = $(getDiv).attr('id');
  1100. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  1101. loadSlick();
  1102. console.log(loadedID+' has been updated');
  1103. },
  1104. error: function(jqXHR, textStatus, errorThrown) {
  1105. console.error(loadedID+' could not be updated');
  1106. }
  1107. });
  1108. }, ".RECENTREFRESH.");
  1109. ", $array, 'Plex');
  1110. }else{
  1111. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  1112. }
  1113. }else{
  1114. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  1115. }
  1116. }
  1117. // Get Image From Emby
  1118. function getEmbyImage() {
  1119. $refresh = false;
  1120. $embyAddress = qualifyURL(EMBYURL);
  1121. if (!file_exists('images/cache')) {
  1122. mkdir('images/cache', 0777, true);
  1123. }
  1124. $itemId = $_GET['img'];
  1125. $key = $_GET['key'];
  1126. if(strpos($key, '$') !== false){
  1127. $key = explode('$', $key)[0];
  1128. $refresh = true;
  1129. }
  1130. $itemType = $_GET['type'];
  1131. $imgParams = array();
  1132. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  1133. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  1134. if(isset($itemId)) {
  1135. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  1136. $cachefile = 'images/cache/'.$key.'.jpg';
  1137. $cachetime = 604800;
  1138. // Serve from the cache if it is younger than $cachetime
  1139. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh !== true) {
  1140. header("Content-type: image/jpeg");
  1141. @readfile($cachefile);
  1142. exit;
  1143. }
  1144. ob_start(); // Start the output buffer
  1145. header('Content-type: image/jpeg');
  1146. //@readfile($image_src);
  1147. echo @curl_get($image_src);
  1148. // Cache the output to a file
  1149. $fp = fopen($cachefile, 'wb');
  1150. fwrite($fp, ob_get_contents());
  1151. fclose($fp);
  1152. ob_end_flush(); // Send the output to the browser
  1153. die();
  1154. } else {
  1155. debug_out('Invalid Request',1);
  1156. }
  1157. }
  1158. // Get Image From Plex
  1159. function getPlexImage() {
  1160. $refresh = false;
  1161. $plexAddress = qualifyURL(PLEXURL);
  1162. if (!file_exists('images/cache')) {
  1163. mkdir('images/cache', 0777, true);
  1164. }
  1165. $image_url = $_GET['img'];
  1166. $key = $_GET['key'];
  1167. if(strpos($key, '$') !== false){
  1168. $key = explode('$', $key)[0];
  1169. $refresh = true;
  1170. }
  1171. $image_height = $_GET['height'];
  1172. $image_width = $_GET['width'];
  1173. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1174. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1175. $cachefile = 'images/cache/'.$key.'.jpg';
  1176. $cachetime = 604800;
  1177. // Serve from the cache if it is younger than $cachetime
  1178. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1179. header("Content-type: image/jpeg");
  1180. @readfile($cachefile);
  1181. exit;
  1182. }
  1183. ob_start(); // Start the output buffer
  1184. header('Content-type: image/jpeg');
  1185. //@readfile($image_src);
  1186. echo @curl_get($image_src);
  1187. // Cache the output to a file
  1188. $fp = fopen($cachefile, 'wb');
  1189. fwrite($fp, ob_get_contents());
  1190. fclose($fp);
  1191. ob_end_flush(); // Send the output to the browser
  1192. die();
  1193. } else {
  1194. echo "Invalid Plex Request";
  1195. }
  1196. }
  1197. // Simplier access to class
  1198. function translate($string) {
  1199. if (isset($GLOBALS['language'])) {
  1200. return $GLOBALS['language']->translate($string);
  1201. } else {
  1202. return '!Translations Not Loaded!';
  1203. }
  1204. }
  1205. // Generate Random string
  1206. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1207. $tmp = '';
  1208. for ($i = 0; $i < $length; $i++) {
  1209. $tmp .= substr(str_shuffle($chars), 0, 1);
  1210. }
  1211. return $tmp;
  1212. }
  1213. // Create config file in the return syntax
  1214. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1215. // Define Initial Value
  1216. $output = array();
  1217. // Sort Items
  1218. ksort($array);
  1219. // Update the current config version
  1220. if (!$nest) {
  1221. // Inject Current Version
  1222. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1223. }
  1224. unset($array['CONFIG_VERSION']);
  1225. unset($array['apply_CONFIG_VERSION']);
  1226. // Process Settings
  1227. foreach ($array as $k => $v) {
  1228. $allowCommit = true;
  1229. switch (gettype($v)) {
  1230. case 'boolean':
  1231. $item = ($v?'true':'false');
  1232. break;
  1233. case 'integer':
  1234. case 'double':
  1235. case 'integer':
  1236. case 'NULL':
  1237. $item = $v;
  1238. break;
  1239. case 'string':
  1240. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1241. break;
  1242. case 'array':
  1243. $item = createConfig($v, false, $nest+1);
  1244. break;
  1245. default:
  1246. $allowCommit = false;
  1247. }
  1248. if($allowCommit) {
  1249. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1250. }
  1251. }
  1252. // Build output
  1253. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1254. if (!$nest && $path) {
  1255. $pathDigest = pathinfo($path);
  1256. @mkdir($pathDigest['dirname'], 0770, true);
  1257. if (file_exists($path)) {
  1258. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1259. }
  1260. $file = fopen($path, 'w');
  1261. fwrite($file, $output);
  1262. fclose($file);
  1263. if (file_exists($path)) {
  1264. return true;
  1265. }
  1266. writeLog("error", "config was unable to write");
  1267. return false;
  1268. } else {
  1269. writeLog("success", "config was updated with new values");
  1270. return $output;
  1271. }
  1272. }
  1273. // Load a config file written in the return syntax
  1274. function loadConfig($path = 'config/config.php') {
  1275. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1276. if (!is_file($path)) {
  1277. return null;
  1278. } else {
  1279. return (array) call_user_func(function() use($path) {
  1280. return include($path);
  1281. });
  1282. }
  1283. }
  1284. // Commit new values to the configuration
  1285. function updateConfig($new, $current = false) {
  1286. // Get config if not supplied
  1287. if ($current === false) {
  1288. $current = loadConfig();
  1289. } else if (is_string($current) && is_file($current)) {
  1290. $current = loadConfig($current);
  1291. }
  1292. // Inject Parts
  1293. foreach ($new as $k => $v) {
  1294. $current[$k] = $v;
  1295. }
  1296. // Return Create
  1297. return createConfig($current);
  1298. }
  1299. // Inject Defaults As Needed
  1300. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1301. if (is_string($path)) {
  1302. $loadedDefaults = loadConfig($path);
  1303. } else {
  1304. $loadedDefaults = $path;
  1305. }
  1306. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1307. }
  1308. // support function for fillDefaultConfig()
  1309. function fillDefaultConfig_recurse($current, $defaults) {
  1310. foreach($defaults as $k => $v) {
  1311. if (!isset($current[$k])) {
  1312. $current[$k] = $v;
  1313. } else if (is_array($current[$k]) && is_array($v)) {
  1314. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1315. }
  1316. }
  1317. return $current;
  1318. };
  1319. // Define Scalar Variables (nest non-secular with underscores)
  1320. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1321. foreach($array as $k => $v) {
  1322. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1323. define($nest_prefix.$k, $v, $anyCase);
  1324. } else if (is_array($v)) {
  1325. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1326. }
  1327. }
  1328. }
  1329. // This function exists only because I am lazy
  1330. function configLazy($path = 'config/config.php') {
  1331. // Load config or default
  1332. if (file_exists($path)) {
  1333. $config = fillDefaultConfig(loadConfig($path));
  1334. } else {
  1335. $config = loadConfig('config/configDefaults.php');
  1336. }
  1337. if (is_array($config)) {
  1338. defineConfig($config);
  1339. }
  1340. return $config;
  1341. }
  1342. // Qualify URL
  1343. function qualifyURL($url) {
  1344. //local address?
  1345. if(substr($url, 0,1) == "/"){
  1346. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1347. $protocol = "https://";
  1348. } else {
  1349. $protocol = "http://";
  1350. }
  1351. $url = $protocol.getServer().$url;
  1352. }
  1353. // Get Digest
  1354. $digest = parse_url($url);
  1355. // http/https
  1356. if (!isset($digest['scheme'])) {
  1357. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1358. $scheme = 'http';
  1359. } else {
  1360. $scheme = 'https';
  1361. }
  1362. } else {
  1363. $scheme = $digest['scheme'];
  1364. }
  1365. // Host
  1366. $host = (isset($digest['host'])?$digest['host']:'');
  1367. // Port
  1368. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1369. // Path
  1370. $path = (isset($digest['path'])?$digest['path']:'');
  1371. // Output
  1372. return $scheme.'://'.$host.$port.$path;
  1373. }
  1374. // Function to be called at top of each to allow upgrading environment as the spec changes
  1375. function upgradeCheck() {
  1376. // Upgrade to 1.31
  1377. if (file_exists('homepageSettings.ini.php')) {
  1378. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1379. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1380. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1381. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1382. foreach($databaseConfig as $k => $v) {
  1383. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1384. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1385. }
  1386. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1387. unlink('homepageSettings.ini.php');
  1388. unset($databaseData);
  1389. unset($homepageConfig);
  1390. }
  1391. // Upgrade to 1.32
  1392. if (file_exists('databaseLocation.ini.php')) {
  1393. // Load Existing
  1394. $config = parse_ini_file('databaseLocation.ini.php', true);
  1395. // Refactor
  1396. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1397. $config['user_home'] = $config['database_Location'].'users/';
  1398. unset($config['databaseLocation']);
  1399. // Turn Off Emby And Plex Recent
  1400. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1401. unset($config["embyPort"]);
  1402. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1403. unset($config["plexPort"]);
  1404. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1405. unset($config["nzbgetPort"]);
  1406. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1407. unset($config["sabnzbdPort"]);
  1408. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1409. unset($config["headphonesPort"]);
  1410. // Write config file
  1411. $config['CONFIG_VERSION'] = '1.32';
  1412. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1413. $createConfigSuccess = createConfig($config);
  1414. // Create new config
  1415. if ($createConfigSuccess) {
  1416. if (file_exists('config/config.php')) {
  1417. // Remove Old ini file
  1418. unlink('databaseLocation.ini.php');
  1419. } else {
  1420. debug_out('Something is not right here!');
  1421. }
  1422. } else {
  1423. debug_out('Couldn\'t create updated configuration.' ,1);
  1424. }
  1425. }
  1426. // Upgrade to 1.33
  1427. $config = loadConfig();
  1428. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1429. // Fix User Directory
  1430. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1431. $config['user_home'] = $config['database_Location'].'users/';
  1432. unset($config['USER_HOME']);
  1433. // Backend auth merge
  1434. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1435. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1436. }
  1437. unset($config['authBackendPort']);
  1438. // If auth is being used move it to embyURL as that is now used in auth functions
  1439. 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')))) {
  1440. $config['embyURL'] = $config['authBackendHost'];
  1441. }
  1442. // Upgrade database to latest version
  1443. updateSQLiteDB($config['database_Location'],'1.32');
  1444. // Update Version and Commit
  1445. $config['apply_CONFIG_VERSION'] = '1.33';
  1446. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1447. $createConfigSuccess = createConfig($config);
  1448. unset($config);
  1449. }
  1450. // Upgrade to 1.34
  1451. $config = loadConfig();
  1452. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1453. // Upgrade database to latest version
  1454. updateSQLiteDB($config['database_Location'],'1.33');
  1455. // Update Version and Commit
  1456. $config['CONFIG_VERSION'] = '1.34';
  1457. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1458. $createConfigSuccess = createConfig($config);
  1459. unset($config);
  1460. }
  1461. // Upgrade to 1.40
  1462. $config = loadConfig();
  1463. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1464. // Upgrade database to latest version
  1465. updateSQLiteDB($config['database_Location'],'1.38');
  1466. // Update Version and Commit
  1467. $config['CONFIG_VERSION'] = '1.40';
  1468. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1469. $createConfigSuccess = createConfig($config);
  1470. unset($config);
  1471. }
  1472. // Upgrade to 1.50
  1473. $config = loadConfig();
  1474. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.50')) {
  1475. // Upgrade database to latest version
  1476. updateSQLiteDB($config['database_Location'],'1.40');
  1477. // Update Version and Commit
  1478. $config['CONFIG_VERSION'] = '1.50';
  1479. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.40].bak.php');
  1480. $createConfigSuccess = createConfig($config);
  1481. unset($config);
  1482. }
  1483. return true;
  1484. }
  1485. // Get OS from server
  1486. function getOS(){
  1487. if(PHP_SHLIB_SUFFIX == "dll"){
  1488. return "win";
  1489. }else{
  1490. return "nix";
  1491. }
  1492. }
  1493. //Get Error by Server OS
  1494. function getError($os, $error){
  1495. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1496. $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'");
  1497. $errors = array(
  1498. 'pdo_sqlite' => array(
  1499. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1500. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1501. ),
  1502. 'sqlite3' => array(
  1503. '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',
  1504. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1505. ),
  1506. 'curl' => array(
  1507. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1508. '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',
  1509. ),
  1510. 'zip' => array(
  1511. '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',
  1512. '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',
  1513. ),
  1514. );
  1515. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1516. }
  1517. // Check if all software dependancies are met
  1518. function dependCheck() {
  1519. $output = array();
  1520. $i = 1;
  1521. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1522. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1523. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1524. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1525. if ($output) {
  1526. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1527. $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++;
  1528. debug_out($output,1);
  1529. }
  1530. return true;
  1531. }
  1532. // Process file uploads
  1533. function uploadFiles($path, $ext_mask = null) {
  1534. if (isset($_FILES) && count($_FILES)) {
  1535. require_once('class.uploader.php');
  1536. $uploader = new Uploader();
  1537. $data = $uploader->upload($_FILES['files'], array(
  1538. 'limit' => 10,
  1539. 'maxSize' => 10,
  1540. 'extensions' => $ext_mask,
  1541. 'required' => false,
  1542. 'uploadDir' => str_replace('//','/',$path.'/'),
  1543. 'title' => array('name'),
  1544. 'removeFiles' => true,
  1545. 'replace' => true,
  1546. ));
  1547. if($data['isComplete']){
  1548. $files = $data['data'];
  1549. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1550. echo json_encode($files['metas'][0]['name']);
  1551. }
  1552. if($data['hasErrors']){
  1553. $errors = $data['errors'];
  1554. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1555. echo json_encode($errors);
  1556. }
  1557. } else {
  1558. writeLog("error", "image was not uploaded");
  1559. echo json_encode('No files submitted!');
  1560. }
  1561. }
  1562. // Process file uploads
  1563. function uploadAvatar($path, $ext_mask = null) {
  1564. if (isset($_FILES) && count($_FILES)) {
  1565. require_once('class.uploader.php');
  1566. $uploader = new Uploader();
  1567. $data = $uploader->upload($_FILES['files'], array(
  1568. 'limit' => 10,
  1569. 'maxSize' => 10,
  1570. 'extensions' => $ext_mask,
  1571. 'required' => false,
  1572. 'uploadDir' => str_replace('//','/',$path.'/'),
  1573. 'title' => array('name'),
  1574. 'removeFiles' => true,
  1575. 'replace' => true,
  1576. ));
  1577. if($data['isComplete']){
  1578. $files = $data['data'];
  1579. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1580. echo json_encode($files['metas'][0]['name']);
  1581. }
  1582. if($data['hasErrors']){
  1583. $errors = $data['errors'];
  1584. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1585. echo json_encode($errors);
  1586. }
  1587. } else {
  1588. writeLog("error", "image was not uploaded");
  1589. echo json_encode('No files submitted!');
  1590. }
  1591. }
  1592. // Remove file
  1593. function removeFiles($path) {
  1594. if(is_file($path)) {
  1595. writeLog("success", "file was removed");
  1596. unlink($path);
  1597. } else {
  1598. writeLog("error", "file was not removed");
  1599. echo json_encode('No file specified for removal!');
  1600. }
  1601. }
  1602. // Lazy select options
  1603. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1604. $output = array();
  1605. $selectedArr = ($multi?explode('|', $selected):array());
  1606. foreach ($array as $key => $value) {
  1607. if (is_array($value)) {
  1608. if (isset($value['optgroup'])) {
  1609. $output[] = '<optgroup label="'.$key.'">';
  1610. foreach($value['optgroup'] as $k => $v) {
  1611. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1612. }
  1613. } else {
  1614. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1615. }
  1616. } else {
  1617. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1618. }
  1619. }
  1620. return implode('',$output);
  1621. }
  1622. // Check if user is allowed to continue
  1623. function qualifyUser($type, $errOnFail = false) {
  1624. if (!isset($GLOBALS['USER'])) {
  1625. require_once("user.php");
  1626. $GLOBALS['USER'] = new User('registration_callback');
  1627. }
  1628. if (is_bool($type)) {
  1629. if ($type === true) {
  1630. $authorized = ($GLOBALS['USER']->authenticated == true);
  1631. } else {
  1632. $authorized = true;
  1633. }
  1634. } elseif (is_string($type) || is_array($type)) {
  1635. if ($type !== 'false') {
  1636. if (!is_array($type)) {
  1637. $type = explode('|',$type);
  1638. }
  1639. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1640. } else {
  1641. $authorized = true;
  1642. }
  1643. } else {
  1644. debug_out('Invalid Syntax!',1);
  1645. }
  1646. if (!$authorized && $errOnFail) {
  1647. if ($GLOBALS['USER']->authenticated) {
  1648. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401');
  1649. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=401\'</script>';
  1650. } else {
  1651. header('Location: '.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999');
  1652. echo '<script>window.location.href = \''.rtrim(dirname($_SERVER['SCRIPT_NAME']), '/').'/error.php?error=999\'</script>';
  1653. }
  1654. debug_out('Not Authorized' ,1);
  1655. } else {
  1656. return $authorized;
  1657. }
  1658. }
  1659. // Build an (optionally) tabbed settings page.
  1660. function buildSettings($array) {
  1661. /*
  1662. array(
  1663. 'title' => '',
  1664. 'id' => '',
  1665. 'fields' => array( See buildField() ),
  1666. 'tabs' => array(
  1667. array(
  1668. 'title' => '',
  1669. 'id' => '',
  1670. 'image' => '',
  1671. 'fields' => array( See buildField() ),
  1672. ),
  1673. ),
  1674. );
  1675. */
  1676. $notifyExplode = explode("-", NOTIFYEFFECT);
  1677. $fieldFunc = function($fieldArr) {
  1678. $fields = '<div class="row">';
  1679. foreach($fieldArr as $key => $value) {
  1680. $isSingle = isset($value['type']);
  1681. if ($isSingle) { $value = array($value); }
  1682. $tmpField = '';
  1683. $sizeLg = max(floor(12/count($value)),2);
  1684. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1685. foreach($value as $k => $v) {
  1686. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1687. }
  1688. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1689. }
  1690. $fields .= '</div>';
  1691. return $fields;
  1692. };
  1693. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1694. $tabSelectors = array();
  1695. $tabContent = array();
  1696. if (isset($array['tabs'])) {
  1697. foreach($array['tabs'] as $key => $value) {
  1698. $id = (isset($value['id'])?$value['id']:randString(32));
  1699. $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>';
  1700. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1701. }
  1702. }
  1703. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1704. $extraClick = ($pageID == 'appearance_settings' ? "$('#advanced_settings_form_submit').click();console.log('add theme settings');" : "");
  1705. return '
  1706. <div class="email-body">
  1707. <div class="email-header gray-bg">
  1708. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1709. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float save-btn-form">
  1710. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1711. </button>
  1712. <h1>'.$array['title'].'</h1>
  1713. </div>
  1714. <div class="email-inner small-box">
  1715. <div class="email-inner-section">
  1716. <div class="small-box fade in" id="'.$pageID.'_frame">
  1717. <div class="col-lg-12">
  1718. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1719. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1720. '.$fields.($tabContent?'
  1721. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1722. <ul class="nav nav-tabs apps">
  1723. '.implode('', $tabSelectors).'
  1724. </ul>
  1725. <div class="clearfix"></div>
  1726. <div class="tab-content">
  1727. '.implode('', $tabContent).'
  1728. </div>
  1729. </div>':'').'
  1730. </form>
  1731. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1732. </div>
  1733. </div>
  1734. </div>
  1735. </div>
  1736. </div>
  1737. <script>
  1738. $(document).ready(function() {
  1739. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1740. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1741. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1742. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1743. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1744. var newVals = {};
  1745. var hasVals = false;
  1746. var errorFields = [];
  1747. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1748. hasVals = true;
  1749. if (this.type == \'checkbox\') {
  1750. newVals[this.name] = this.checked;
  1751. } else if ($(this).hasClass(\'summernote\')) {
  1752. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1753. } else {
  1754. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1755. var fieldVal = $(this).val();
  1756. if (typeof fieldVal == \'object\') {
  1757. if (typeof fieldVal.join == \'function\') {
  1758. fieldVal = fieldVal.join(\'|\');
  1759. } else {
  1760. fieldVal = JSON.stringify(fieldVal);
  1761. }
  1762. }
  1763. newVals[this.name] = fieldVal;
  1764. }
  1765. });
  1766. if (errorFields.length) {
  1767. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1768. } else if (hasVals) {
  1769. console.log(newVals);
  1770. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1771. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1772. });
  1773. '.$extraClick.'
  1774. } else {
  1775. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1776. }
  1777. return false;
  1778. });
  1779. '.(isset($array['onready'])?$array['onready']:'').'
  1780. });
  1781. </script>
  1782. ';
  1783. }
  1784. // Build Settings Fields
  1785. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1786. /*
  1787. array(
  1788. 'type' => '',
  1789. 'placeholder' => '',
  1790. 'label' => '',
  1791. 'labelTranslate' => '',
  1792. 'assist' => '',
  1793. 'name' => '',
  1794. 'pattern' => '',
  1795. 'options' => array( // For SELECT only
  1796. 'Display' => 'value',
  1797. ),
  1798. )
  1799. */
  1800. // Tags
  1801. $tags = array();
  1802. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick') as $value) {
  1803. if (isset($params[$value])) {
  1804. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1805. } else if ($params[$value] === true) { $tags[] = $value; }
  1806. }
  1807. }
  1808. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1809. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1810. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1811. $val = (isset($params['value'])?$params['value']:'');
  1812. $class = (isset($params['class'])?' '.$params['class']:'');
  1813. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1814. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1815. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1816. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1817. // Field Design
  1818. switch ($params['type']) {
  1819. case 'text':
  1820. case 'number':
  1821. case 'password':
  1822. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1823. break;
  1824. case 'select':
  1825. case 'dropdown':
  1826. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1827. break;
  1828. case 'select-multi':
  1829. case 'dropdown-multi':
  1830. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1831. break;
  1832. case 'check':
  1833. case 'checkbox':
  1834. case 'toggle':
  1835. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1836. $colour = (isset($params['colour'])?$params['colour']:'success');
  1837. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1838. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1839. break;
  1840. case 'radio':
  1841. $labelOut = '';
  1842. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1843. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1844. $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>';
  1845. break;
  1846. case 'date':
  1847. $field = 'Unsupported, planned.';
  1848. break;
  1849. case 'hidden':
  1850. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1851. break;
  1852. case 'header':
  1853. $labelOut = '';
  1854. $headType = (isset($params['value'])?$params['value']:3);
  1855. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1856. break;
  1857. case 'button':
  1858. $labelOut = '';
  1859. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1860. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1861. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1862. $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>':'');
  1863. break;
  1864. case 'textarea':
  1865. $rows = (isset($params['rows'])?$params['rows']:5);
  1866. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1867. break;
  1868. case 'custom':
  1869. // Settings
  1870. $settings = array(
  1871. '$id' => $id,
  1872. '$name' => $name,
  1873. '$val' => $val,
  1874. '$label' => $label,
  1875. '$labelOut' => $labelOut,
  1876. );
  1877. // Get HTML
  1878. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1879. // If LabelOut is in html dont print it twice
  1880. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1881. // Replace variables in settings
  1882. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1883. // Build Field
  1884. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1885. break;
  1886. case 'space':
  1887. $labelOut = '';
  1888. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1889. break;
  1890. default:
  1891. $field = 'Unsupported field type';
  1892. break;
  1893. }
  1894. // Field Formats
  1895. switch ($format) {
  1896. case 'colour': // Fuckin Eh, Canada!
  1897. case 'color':
  1898. $labelBef = '<center>'.$label.'</center>';
  1899. $wrapClass = 'gray-bg colour-field';
  1900. $labelAft = '';
  1901. $field = str_replace(' material input-sm','',$field);
  1902. break;
  1903. default:
  1904. $labelBef = '';
  1905. $labelAft = $labelOut;
  1906. }
  1907. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1908. }
  1909. // Tab Settings Generation
  1910. function printTabRow($data) {
  1911. $hidden = false;
  1912. if ($data===false) {
  1913. $hidden = true;
  1914. $data = array( // New Tab Defaults
  1915. 'id' => 'new',
  1916. 'name' => '',
  1917. 'url' => '',
  1918. 'icon' => 'fa-diamond',
  1919. 'iconurl' => '',
  1920. 'active' => 'true',
  1921. 'user' => 'true',
  1922. 'guest' => 'true',
  1923. 'window' => 'false',
  1924. 'splash' => 'true',
  1925. 'ping' => 'false',
  1926. 'ping_url' => '',
  1927. 'defaultz' => '',
  1928. );
  1929. }
  1930. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1931. $output = '
  1932. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1933. <tab class="content-form form-inline">
  1934. <div class="row">
  1935. '.buildField(array(
  1936. 'type' => 'custom',
  1937. '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>',
  1938. ),12,1,1).'
  1939. '.buildField(array(
  1940. 'type' => 'hidden',
  1941. 'id' => 'tab-'.$data['id'].'-id',
  1942. 'name' => 'id['.$data['id'].']',
  1943. 'value' => $data['id'],
  1944. ),12,2,1).'
  1945. '.buildField(array(
  1946. 'type' => 'text',
  1947. 'id' => 'tab-'.$data['id'].'-name',
  1948. 'name' => 'name['.$data['id'].']',
  1949. 'required' => true,
  1950. 'placeholder' => 'Organizr Homepage',
  1951. 'labelTranslate' => 'TAB_NAME',
  1952. 'value' => $data['name'],
  1953. 'class' => 'darkBold',
  1954. ),12,2,1).'
  1955. '.buildField(array(
  1956. 'type' => 'text',
  1957. 'id' => 'tab-'.$data['id'].'-url',
  1958. 'name' => 'url['.$data['id'].']',
  1959. 'required' => true,
  1960. 'placeholder' => 'homepage.php',
  1961. 'labelTranslate' => 'TAB_URL',
  1962. 'value' => $data['url'],
  1963. 'class' => 'darkBold',
  1964. ),12,2,2).'
  1965. '.buildField(array(
  1966. 'type' => 'text',
  1967. 'id' => 'tab-'.$data['id'].'-iconurl',
  1968. 'name' => 'iconurl['.$data['id'].']',
  1969. 'placeholder' => 'images/organizr.png',
  1970. 'labelTranslate' => 'ICON_URL',
  1971. 'value' => $data['iconurl'],
  1972. 'class' => 'darkBold',
  1973. ),12,2,1).'
  1974. '.buildField(array(
  1975. 'type' => 'text',
  1976. 'id' => 'tab-'.$data['id'].'-icon',
  1977. 'name' => 'icon['.$data['id'].']',
  1978. 'placeholder' => 'fa-icon',
  1979. 'labelTranslate' => 'OR_ICON_NAME',
  1980. 'value' => $data['icon'],
  1981. 'class' => 'iconpickeradd darkBold',
  1982. ),12,1,1).'
  1983. '.buildField(array(
  1984. 'type' => 'text',
  1985. 'id' => 'tab-'.$data['id'].'-ping_url',
  1986. 'name' => 'ping_url['.$data['id'].']',
  1987. 'placeholder' => 'host:port',
  1988. 'labelTranslate' => 'PING_URL',
  1989. 'value' => $data['ping_url'],
  1990. 'class' => 'darkBold',
  1991. ),12,2,1).'
  1992. '.buildField(array(
  1993. 'type' => 'radio',
  1994. 'labelTranslate' => 'DEFAULT',
  1995. 'name' => 'defaultz['.$data['id'].']',
  1996. 'value' => $data['defaultz'],
  1997. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1998. ),12,1,1).'
  1999. '.buildField(array(
  2000. 'type' => 'button',
  2001. 'icon' => 'chevron-down',
  2002. 'buttonType' => 'success',
  2003. 'labelTranslate' => 'MORE',
  2004. 'onclick' => "$(this).parent().parent().parent().find('.slideInUp').toggle()",
  2005. 'class' => 'toggleTabExtra',
  2006. ),12,1,1).'
  2007. '.buildField(array(
  2008. 'type' => 'button',
  2009. 'icon' => 'trash',
  2010. 'buttonType' => 'danger',
  2011. 'labelTranslate' => 'REMOVE',
  2012. 'onclick' => "$(this).parents('li').remove();",
  2013. ),12,1,1).'</div><div id = "tab-'.$data['id'].'-row" class = "row animated slideInUp" style = "display:none;" ><div></div>
  2014. '.buildField(array(
  2015. 'type' => 'checkbox',
  2016. 'labelTranslate' => 'ACTIVE',
  2017. 'name' => 'active['.$data['id'].']',
  2018. 'value' => $data['active'],
  2019. ),12,1,1).'
  2020. '.buildField(array(
  2021. 'type' => 'checkbox',
  2022. 'labelTranslate' => 'USER',
  2023. 'colour' => 'primary',
  2024. 'name' => 'user['.$data['id'].']',
  2025. 'value' => $data['user'],
  2026. ),12,1,1).'
  2027. '.buildField(array(
  2028. 'type' => 'checkbox',
  2029. 'labelTranslate' => 'GUEST',
  2030. 'colour' => 'warning',
  2031. 'name' => 'guest['.$data['id'].']',
  2032. 'value' => $data['guest'],
  2033. ),12,1,1).'
  2034. '.buildField(array(
  2035. 'type' => 'checkbox',
  2036. 'labelTranslate' => 'NO_IFRAME',
  2037. 'colour' => 'danger',
  2038. 'name' => 'window['.$data['id'].']',
  2039. 'value' => $data['window'],
  2040. ),12,1,1).'
  2041. '.buildField(array(
  2042. 'type' => 'checkbox',
  2043. 'labelTranslate' => 'SPLASH',
  2044. 'colour' => 'success',
  2045. 'name' => 'splash['.$data['id'].']',
  2046. 'value' => $data['splash'],
  2047. ),12,1,1).'
  2048. '.buildField(array(
  2049. 'type' => 'checkbox',
  2050. 'labelTranslate' => 'PING',
  2051. 'colour' => 'success',
  2052. 'name' => 'ping['.$data['id'].']',
  2053. 'value' => $data['ping'],
  2054. ),12,1,1).'
  2055. </div>
  2056. </tab>
  2057. </li>
  2058. ';
  2059. return $output;
  2060. }
  2061. // Timezone array
  2062. function timezoneOptions() {
  2063. $output = array();
  2064. $timezones = array();
  2065. $regions = array(
  2066. 'Africa' => DateTimeZone::AFRICA,
  2067. 'America' => DateTimeZone::AMERICA,
  2068. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2069. 'Arctic' => DateTimeZone::ARCTIC,
  2070. 'Asia' => DateTimeZone::ASIA,
  2071. 'Atlantic' => DateTimeZone::ATLANTIC,
  2072. 'Australia' => DateTimeZone::AUSTRALIA,
  2073. 'Europe' => DateTimeZone::EUROPE,
  2074. 'Indian' => DateTimeZone::INDIAN,
  2075. 'Pacific' => DateTimeZone::PACIFIC
  2076. );
  2077. foreach ($regions as $name => $mask) {
  2078. $zones = DateTimeZone::listIdentifiers($mask);
  2079. foreach($zones as $timezone) {
  2080. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2081. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2082. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  2083. }
  2084. }
  2085. return $output;
  2086. }
  2087. // Build Database
  2088. function createSQLiteDB($path = false) {
  2089. if ($path === false) {
  2090. if (DATABASE_LOCATION){
  2091. $path = DATABASE_LOCATION;
  2092. } else {
  2093. debug_out('No Path Specified!');
  2094. }
  2095. }
  2096. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  2097. if (!isset($GLOBALS['file_db'])) {
  2098. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  2099. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2100. }
  2101. // Create Users
  2102. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  2103. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2104. `username` TEXT UNIQUE,
  2105. `password` TEXT,
  2106. `email` TEXT,
  2107. `token` TEXT,
  2108. `role` TEXT,
  2109. `active` TEXT,
  2110. `last` TEXT,
  2111. `auth_service` TEXT DEFAULT \'internal\'
  2112. );');
  2113. // Create Tabs
  2114. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  2115. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2116. `order` INTEGER,
  2117. `users_id` INTEGER,
  2118. `name` TEXT,
  2119. `url` TEXT,
  2120. `defaultz` TEXT,
  2121. `active` TEXT,
  2122. `user` TEXT,
  2123. `guest` TEXT,
  2124. `icon` TEXT,
  2125. `iconurl` TEXT,
  2126. `window` TEXT,
  2127. `splash` TEXT,
  2128. `ping` TEXT,
  2129. `ping_url` TEXT
  2130. );');
  2131. // Create Options
  2132. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  2133. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2134. `users_id` INTEGER UNIQUE,
  2135. `title` TEXT UNIQUE,
  2136. `topbar` TEXT,
  2137. `bottombar` TEXT,
  2138. `sidebar` TEXT,
  2139. `hoverbg` TEXT,
  2140. `topbartext` TEXT,
  2141. `activetabBG` TEXT,
  2142. `activetabicon` TEXT,
  2143. `activetabtext` TEXT,
  2144. `inactiveicon` TEXT,
  2145. `inactivetext` TEXT,
  2146. `loading` TEXT,
  2147. `hovertext` TEXT
  2148. );');
  2149. // Create Invites
  2150. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  2151. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2152. `code` TEXT UNIQUE,
  2153. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  2154. `email` TEXT,
  2155. `username` TEXT,
  2156. `dateused` TIMESTAMP,
  2157. `usedby` TEXT,
  2158. `ip` TEXT,
  2159. `valid` TEXT
  2160. );');
  2161. writeLog("success", "database created/saved");
  2162. return $users && $tabs && $options && $invites;
  2163. } else {
  2164. writeLog("error", "database was unable to be created/saved");
  2165. return false;
  2166. }
  2167. }
  2168. // Upgrade Database
  2169. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  2170. if (!$db_path) {
  2171. if (defined('DATABASE_LOCATION')) {
  2172. $db_path = DATABASE_LOCATION;
  2173. } else {
  2174. debug_out('No Path Specified',1);
  2175. }
  2176. }
  2177. if (!isset($GLOBALS['file_db'])) {
  2178. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  2179. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2180. }
  2181. // Cache current DB
  2182. $cache = array();
  2183. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  2184. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  2185. foreach($row as $k => $v) {
  2186. if (is_string($k)) {
  2187. $cache[$table['name']][$key][$k] = $v;
  2188. }
  2189. }
  2190. }
  2191. }
  2192. // Remove Current Database
  2193. $GLOBALS['file_db'] = null;
  2194. $pathDigest = pathinfo($db_path.'users.db');
  2195. if (file_exists($db_path.'users.db')) {
  2196. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  2197. }
  2198. // Create New Database
  2199. $success = createSQLiteDB($db_path);
  2200. // Restore Items
  2201. if ($success) {
  2202. foreach($cache as $table => $tableData) {
  2203. if ($tableData) {
  2204. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  2205. $insertValues = array();
  2206. reset($tableData);
  2207. foreach($tableData as $key => $value) {
  2208. $insertValues[] = '('.implode(',',array_map(function($d) {
  2209. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  2210. }, $value)).')';
  2211. }
  2212. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  2213. }
  2214. }
  2215. writeLog("success", "database values have been updated");
  2216. return true;
  2217. } else {
  2218. writeLog("error", "database values unable to be updated");
  2219. return false;
  2220. }
  2221. }
  2222. // Commit colours to database
  2223. function updateDBOptions($values) {
  2224. if (!isset($GLOBALS['file_db'])) {
  2225. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2226. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2227. }
  2228. // Commit new values to database
  2229. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  2230. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  2231. }, $values, array_keys($values))).';')->rowCount()) {
  2232. return true;
  2233. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  2234. writeLog("success", "database values for options table have been updated");
  2235. return true;
  2236. } else {
  2237. writeLog("error", "database values for options table unable to be updated");
  2238. return false;
  2239. }
  2240. }
  2241. // Send AJAX notification
  2242. function sendNotification($success, $message = false, $send = true) {
  2243. $notifyExplode = explode("-", NOTIFYEFFECT);
  2244. if ($success) {
  2245. $msg = array(
  2246. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  2247. 'icon' => 'floppy-o',
  2248. 'type' => 'success',
  2249. 'length' => '5000',
  2250. 'layout' => $notifyExplode[0],
  2251. 'effect' => $notifyExplode[1],
  2252. );
  2253. } else {
  2254. $msg = array(
  2255. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2256. 'icon' => 'floppy-o',
  2257. 'type' => 'failed',
  2258. 'length' => '5000',
  2259. 'layout' => $notifyExplode[0],
  2260. 'effect' => $notifyExplode[1],
  2261. );
  2262. }
  2263. // Send and kill script?
  2264. if ($send) {
  2265. header('Content-Type: application/json');
  2266. echo json_encode(array('notify'=>$msg));
  2267. die();
  2268. }
  2269. return $msg;
  2270. }
  2271. // Load colours from the database
  2272. function loadAppearance() {
  2273. // Defaults
  2274. $defaults = array(
  2275. 'title' => 'Organizr',
  2276. 'topbartext' => '#66D9EF',
  2277. 'topbar' => '#333333',
  2278. 'bottombar' => '#333333',
  2279. 'sidebar' => '#393939',
  2280. 'hoverbg' => '#AD80FD',
  2281. 'activetabBG' => '#F92671',
  2282. 'activetabicon' => '#FFFFFF',
  2283. 'activetabtext' => '#FFFFFF',
  2284. 'inactiveicon' => '#66D9EF',
  2285. 'inactivetext' => '#66D9EF',
  2286. 'loading' => '#66D9EF',
  2287. 'hovertext' => '#000000',
  2288. );
  2289. if (DATABASE_LOCATION) {
  2290. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2291. if (!isset($GLOBALS['file_db'])) {
  2292. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2293. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2294. }
  2295. // Database Lookup
  2296. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2297. // Replace defaults with filled options
  2298. foreach($options as $row) {
  2299. foreach($defaults as $key => $value) {
  2300. if (isset($row[$key]) && $row[$key]) {
  2301. $defaults[$key] = $row[$key];
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. // Return the Results
  2308. return $defaults;
  2309. }
  2310. // Delete Database
  2311. function deleteDatabase() {
  2312. unset($_COOKIE['Organizr']);
  2313. setcookie('Organizr', '', time() - 3600, '/');
  2314. unset($_COOKIE['OrganizrU']);
  2315. setcookie('OrganizrU', '', time() - 3600, '/');
  2316. $GLOBALS['file_db'] = null;
  2317. unlink(DATABASE_LOCATION.'users.db');
  2318. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2319. if(is_dir($file)) {
  2320. rmdir($file);
  2321. } elseif (!is_dir($file)) {
  2322. unlink($file);
  2323. }
  2324. }
  2325. rmdir($userdirpath);
  2326. writeLog("success", "database has been deleted");
  2327. return true;
  2328. }
  2329. // Upgrade the installation
  2330. function upgradeInstall($branch = 'master') {
  2331. function downloadFile($url, $path){
  2332. ini_set('max_execution_time',0);
  2333. $folderPath = "upgrade/";
  2334. if(!mkdir($folderPath)){
  2335. writeLog("error", "organizr could not create upgrade folder");
  2336. }
  2337. $newfname = $folderPath . $path;
  2338. $file = fopen ($url, 'rb');
  2339. if ($file) {
  2340. $newf = fopen ($newfname, 'wb');
  2341. if ($newf) {
  2342. while(!feof($file)) {
  2343. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2344. }
  2345. }
  2346. }else{
  2347. writeLog("error", "organizr could not download $url");
  2348. }
  2349. if ($file) {
  2350. fclose($file);
  2351. writeLog("success", "organizr finished downloading the github zip file");
  2352. }else{
  2353. writeLog("error", "organizr could not download the github zip file");
  2354. }
  2355. if ($newf) {
  2356. fclose($newf);
  2357. writeLog("success", "organizr created upgrade zip file from github zip file");
  2358. }else{
  2359. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2360. }
  2361. }
  2362. function unzipFile($zipFile){
  2363. $zip = new ZipArchive;
  2364. $extractPath = "upgrade/";
  2365. if($zip->open($extractPath . $zipFile) != "true"){
  2366. writeLog("error", "organizr could not unzip upgrade.zip");
  2367. }else{
  2368. writeLog("success", "organizr unzipped upgrade.zip");
  2369. }
  2370. /* Extract Zip File */
  2371. $zip->extractTo($extractPath);
  2372. $zip->close();
  2373. }
  2374. // Function to remove folders and files
  2375. function rrmdir($dir) {
  2376. if (is_dir($dir)) {
  2377. $files = scandir($dir);
  2378. foreach ($files as $file)
  2379. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2380. rmdir($dir);
  2381. }
  2382. else if (file_exists($dir)) unlink($dir);
  2383. }
  2384. // Function to Copy folders and files
  2385. function rcopy($src, $dst) {
  2386. if (is_dir ( $src )) {
  2387. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2388. $files = scandir ( $src );
  2389. foreach ( $files as $file )
  2390. if ($file != "." && $file != "..")
  2391. rcopy ( "$src/$file", "$dst/$file" );
  2392. } else if (file_exists ( $src ))
  2393. copy ( $src, $dst );
  2394. }
  2395. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2396. $file = "upgrade.zip";
  2397. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2398. $cleanup = __DIR__ . "/upgrade/";
  2399. $destination = __DIR__ . "/";
  2400. writeLog("success", "starting organizr upgrade process");
  2401. downloadFile($url, $file);
  2402. unzipFile($file);
  2403. rcopy($source, $destination);
  2404. writeLog("success", "new organizr files copied");
  2405. rrmdir($cleanup);
  2406. writeLog("success", "organizr upgrade folder removed");
  2407. writeLog("success", "organizr has been updated");
  2408. return true;
  2409. }
  2410. // NzbGET Items
  2411. function nzbgetConnect($list = 'listgroups') {
  2412. $url = qualifyURL(NZBGETURL);
  2413. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2414. $api = json_decode($api, true);
  2415. $gotNZB = array();
  2416. if (is_array($api) || is_object($api)){
  2417. foreach ($api['result'] AS $child) {
  2418. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2419. $downloadStatus = $child['Status'];
  2420. $downloadCategory = $child['Category'];
  2421. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2422. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2423. if($child['Health'] <= "750"){
  2424. $downloadHealth = "danger";
  2425. }elseif($child['Health'] <= "900"){
  2426. $downloadHealth = "warning";
  2427. }elseif($child['Health'] <= "1000"){
  2428. $downloadHealth = "success";
  2429. }
  2430. $gotNZB[] = '<tr>
  2431. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2432. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2433. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2434. <td class="col-xs-1 nzbtable nzbtable-row">'.realSize(($child['FileSizeMB']*1024)*1024).'</td>
  2435. <td class="col-xs-2 nzbtable nzbtable-row">
  2436. <div class="progress">
  2437. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2438. <p class="text-center">'.round($downloadPercent).'%</p>
  2439. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2440. </div>
  2441. </div>
  2442. </td>
  2443. </tr>';
  2444. }
  2445. if ($gotNZB) {
  2446. return implode('',$gotNZB);
  2447. } else {
  2448. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2449. }
  2450. }else{
  2451. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Username and Password - if HTTPS, is cert valid");
  2452. }
  2453. }
  2454. // Sabnzbd Items
  2455. function sabnzbdConnect($list = 'queue') {
  2456. $url = qualifyURL(SABNZBDURL);
  2457. $api = file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2458. $api = json_decode($api, true);
  2459. $gotNZB = array();
  2460. foreach ($api[$list]['slots'] AS $child) {
  2461. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2462. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2463. $downloadStatus = $child['status'];
  2464. $gotNZB[] = '<tr>
  2465. <td class="col-xs-6 nzbtable-file-row">'.$downloadName.'</td>
  2466. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2467. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2468. <td class="col-xs-1 nzbtable nzbtable-row">'.$child['size'].'</td>
  2469. <td class="col-xs-2 nzbtable nzbtable-row">
  2470. <div class="progress">
  2471. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2472. <p class="text-center">'.round($downloadPercent).'%</p>
  2473. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2474. </div>
  2475. </div>
  2476. </td>
  2477. </tr>';
  2478. }
  2479. if ($gotNZB) {
  2480. return implode('',$gotNZB);
  2481. } else {
  2482. return '<tr><td colspan="5"><p class="text-center">No Results</p></td></tr>';
  2483. }
  2484. }
  2485. // Apply new tab settings
  2486. function updateTabs($tabs) {
  2487. if (!isset($GLOBALS['file_db'])) {
  2488. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2489. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2490. }
  2491. // Validate
  2492. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2493. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2494. // Clear Existing Tabs
  2495. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2496. // Process New Tabs
  2497. $totalValid = 0;
  2498. foreach ($tabs['name'] as $key => $value) {
  2499. // Qualify
  2500. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2501. $totalValid++;
  2502. $fields = array();
  2503. foreach(array('id','name','url','icon','iconurl','order','ping_url') as $v) {
  2504. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2505. }
  2506. foreach(array('active','user','guest','defaultz','window','splash','ping') as $v) {
  2507. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2508. }
  2509. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2510. }
  2511. writeLog("success", "tabs successfully saved");
  2512. return $totalValid;
  2513. } else {
  2514. writeLog("error", "tabs could not save");
  2515. return false;
  2516. }
  2517. writeLog("error", "tabs could not save");
  2518. return false;
  2519. }
  2520. // ==============
  2521. function clean($strin) {
  2522. $strout = null;
  2523. for ($i = 0; $i < strlen($strin); $i++) {
  2524. $ord = ord($strin[$i]);
  2525. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2526. $strout .= "&amp;#{$ord};";
  2527. }
  2528. else {
  2529. switch ($strin[$i]) {
  2530. case '<':
  2531. $strout .= '&lt;';
  2532. break;
  2533. case '>':
  2534. $strout .= '&gt;';
  2535. break;
  2536. case '&':
  2537. $strout .= '&amp;';
  2538. break;
  2539. case '"':
  2540. $strout .= '&quot;';
  2541. break;
  2542. default:
  2543. $strout .= $strin[$i];
  2544. }
  2545. }
  2546. }
  2547. return $strout;
  2548. }
  2549. function registration_callback($username, $email, $userdir){
  2550. global $data;
  2551. $data = array($username, $email, $userdir);
  2552. }
  2553. function printArray($arrayName){
  2554. $messageCount = count($arrayName);
  2555. $i = 0;
  2556. foreach ( $arrayName as $item ) :
  2557. $i++;
  2558. if($i < $messageCount) :
  2559. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2560. elseif($i = $messageCount) :
  2561. echo "<small class='text-uppercase'>" . $item . "</small>";
  2562. endif;
  2563. endforeach;
  2564. }
  2565. function write_ini_file($content, $path) {
  2566. if (!$handle = fopen($path, 'w')) {
  2567. return false;
  2568. }
  2569. $success = fwrite($handle, trim($content));
  2570. fclose($handle);
  2571. return $success;
  2572. }
  2573. function gotTimezone(){
  2574. $regions = array(
  2575. 'Africa' => DateTimeZone::AFRICA,
  2576. 'America' => DateTimeZone::AMERICA,
  2577. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2578. 'Arctic' => DateTimeZone::ARCTIC,
  2579. 'Asia' => DateTimeZone::ASIA,
  2580. 'Atlantic' => DateTimeZone::ATLANTIC,
  2581. 'Australia' => DateTimeZone::AUSTRALIA,
  2582. 'Europe' => DateTimeZone::EUROPE,
  2583. 'Indian' => DateTimeZone::INDIAN,
  2584. 'Pacific' => DateTimeZone::PACIFIC
  2585. );
  2586. $timezones = array();
  2587. foreach ($regions as $name => $mask) {
  2588. $zones = DateTimeZone::listIdentifiers($mask);
  2589. foreach($zones as $timezone) {
  2590. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2591. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2592. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2593. }
  2594. }
  2595. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2596. foreach($timezones as $region => $list) {
  2597. print '<optgroup label="' . $region . '">' . "\n";
  2598. foreach($list as $timezone => $name) {
  2599. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2600. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2601. }
  2602. print '</optgroup>' . "\n";
  2603. }
  2604. print '</select>';
  2605. }
  2606. function getTimezone(){
  2607. $regions = array(
  2608. 'Africa' => DateTimeZone::AFRICA,
  2609. 'America' => DateTimeZone::AMERICA,
  2610. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2611. 'Arctic' => DateTimeZone::ARCTIC,
  2612. 'Asia' => DateTimeZone::ASIA,
  2613. 'Atlantic' => DateTimeZone::ATLANTIC,
  2614. 'Australia' => DateTimeZone::AUSTRALIA,
  2615. 'Europe' => DateTimeZone::EUROPE,
  2616. 'Indian' => DateTimeZone::INDIAN,
  2617. 'Pacific' => DateTimeZone::PACIFIC
  2618. );
  2619. $timezones = array();
  2620. foreach ($regions as $name => $mask) {
  2621. $zones = DateTimeZone::listIdentifiers($mask);
  2622. foreach($zones as $timezone) {
  2623. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2624. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2625. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2626. }
  2627. }
  2628. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2629. foreach($timezones as $region => $list) {
  2630. print '<optgroup label="' . $region . '">' . "\n";
  2631. foreach($list as $timezone => $name) {
  2632. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2633. }
  2634. print '</optgroup>' . "\n";
  2635. }
  2636. print '</select>';
  2637. }
  2638. function explosion($string, $position){
  2639. $getWord = explode("|", $string);
  2640. return $getWord[$position];
  2641. }
  2642. function getServerPath() {
  2643. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2644. $protocol = "https://";
  2645. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2646. $protocol = "https://";
  2647. } else {
  2648. $protocol = "http://";
  2649. }
  2650. $domain = '';
  2651. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2652. $domain = $_SERVER['SERVER_NAME'];
  2653. }elseif(isset($_SERVER['HTTP_HOST'])){
  2654. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2655. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2656. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2657. if ($port == "80" || $port == "443"){
  2658. $domain = $domain;
  2659. }else{
  2660. $domain = $_SERVER['HTTP_HOST'];
  2661. }
  2662. }else{
  2663. $domain = $_SERVER['HTTP_HOST'];
  2664. }
  2665. }
  2666. return $protocol . $domain . str_replace("\\", "/", dirname($_SERVER['REQUEST_URI']));
  2667. }
  2668. function get_browser_name() {
  2669. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2670. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2671. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2672. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2673. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2674. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2675. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2676. return 'Other';
  2677. }
  2678. function getSickrageCalendarWanted($array){
  2679. $array = json_decode($array, true);
  2680. //$gotCalendar = "";
  2681. $gotCalendar = array();
  2682. $i = 0;
  2683. foreach($array['data']['missed'] AS $child) {
  2684. $i++;
  2685. $seriesName = $child['show_name'];
  2686. $episodeID = $child['tvdbid'];
  2687. $episodeAirDate = $child['airdate'];
  2688. $episodeAirDateTime = explode(" ",$child['airs']);
  2689. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2690. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2691. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2692. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2693. $downloaded = "0";
  2694. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2695. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2696. array_push($gotCalendar, array(
  2697. "id" => "Sick-Miss-".$i,
  2698. "title" => $seriesName,
  2699. "start" => $episodeAirDate,
  2700. "className" => $downloaded." tvID--".$episodeID,
  2701. "imagetype" => "tv",
  2702. ));
  2703. }
  2704. foreach($array['data']['today'] AS $child) {
  2705. $i++;
  2706. $seriesName = $child['show_name'];
  2707. $episodeID = $child['tvdbid'];
  2708. $episodeAirDate = $child['airdate'];
  2709. $episodeAirDateTime = explode(" ",$child['airs']);
  2710. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2711. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2712. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2713. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2714. $downloaded = "0";
  2715. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2716. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2717. array_push($gotCalendar, array(
  2718. "id" => "Sick-Today-".$i,
  2719. "title" => $seriesName,
  2720. "start" => $episodeAirDate,
  2721. "className" => $downloaded." tvID--".$episodeID,
  2722. "imagetype" => "tv",
  2723. ));
  2724. }
  2725. foreach($array['data']['soon'] AS $child) {
  2726. $i++;
  2727. $seriesName = $child['show_name'];
  2728. $episodeID = $child['tvdbid'];
  2729. $episodeAirDate = $child['airdate'];
  2730. $episodeAirDateTime = explode(" ",$child['airs']);
  2731. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2732. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2733. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2734. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2735. $downloaded = "0";
  2736. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2737. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2738. array_push($gotCalendar, array(
  2739. "id" => "Sick-Soon-".$i,
  2740. "title" => $seriesName,
  2741. "start" => $episodeAirDate,
  2742. "className" => $downloaded." tvID--".$episodeID,
  2743. "imagetype" => "tv",
  2744. ));
  2745. }
  2746. foreach($array['data']['later'] AS $child) {
  2747. $i++;
  2748. $seriesName = $child['show_name'];
  2749. $episodeID = $child['tvdbid'];
  2750. $episodeAirDate = $child['airdate'];
  2751. $episodeAirDateTime = explode(" ",$child['airs']);
  2752. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2753. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2754. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2755. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2756. $downloaded = "0";
  2757. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2758. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2759. array_push($gotCalendar, array(
  2760. "id" => "Sick-Later-".$i,
  2761. "title" => $seriesName,
  2762. "start" => $episodeAirDate,
  2763. "className" => $downloaded." tvID--".$episodeID,
  2764. "imagetype" => "tv",
  2765. ));
  2766. }
  2767. if ($i != 0){ return $gotCalendar; }
  2768. }
  2769. function getSickrageCalendarHistory($array){
  2770. $array = json_decode($array, true);
  2771. //$gotCalendar = "";
  2772. $gotCalendar = array();
  2773. $i = 0;
  2774. foreach($array['data'] AS $child) {
  2775. $i++;
  2776. $seriesName = $child['show_name'];
  2777. $episodeID = $child['tvdbid'];
  2778. $episodeAirDate = $child['date'];
  2779. $downloaded = "green-bg";
  2780. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2781. array_push($gotCalendar, array(
  2782. "id" => "Sick-History-".$i,
  2783. "title" => $seriesName,
  2784. "start" => $episodeAirDate,
  2785. "className" => $downloaded." tvID--".$episodeID,
  2786. "imagetype" => "tv",
  2787. ));
  2788. }
  2789. if ($i != 0){ return $gotCalendar; }
  2790. }
  2791. function getSonarrCalendar($array){
  2792. $array = json_decode($array, true);
  2793. //$gotCalendar = "";
  2794. $gotCalendar = array();
  2795. $i = 0;
  2796. foreach($array AS $child) {
  2797. $i++;
  2798. $seriesName = $child['series']['title'];
  2799. $episodeID = $child['series']['tvdbId'];
  2800. if(!isset($episodeID)){ $episodeID = ""; }
  2801. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2802. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2803. $episodeAirDate = $child['airDateUtc'];
  2804. $episodeAirDate = strtotime($episodeAirDate);
  2805. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2806. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2807. $downloaded = $child['hasFile'];
  2808. 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"; }
  2809. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2810. array_push($gotCalendar, array(
  2811. "id" => "Sonarr-".$i,
  2812. "title" => $seriesName,
  2813. "start" => $episodeAirDate,
  2814. "className" => $downloaded." tvID--".$episodeID,
  2815. "imagetype" => "tv",
  2816. ));
  2817. }
  2818. if ($i != 0){ return $gotCalendar; }
  2819. }
  2820. function getCouchCalendar(){
  2821. $url = qualifyURL(COUCHURL);
  2822. $api = curl_get($url."/api/".COUCHAPI."/media.list");
  2823. $api = json_decode($api, true);
  2824. $i = 0;
  2825. $gotCalendar = array();
  2826. if (is_array($api) || is_object($api)){
  2827. foreach($api['movies'] AS $child) {
  2828. if($child['status'] == "active" || $child['status'] == "done" ){
  2829. $i++;
  2830. $movieName = $child['info']['original_title'];
  2831. $movieID = $child['info']['tmdb_id'];
  2832. if(!isset($movieID)){ $movieID = ""; }
  2833. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  2834. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  2835. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  2836. $physicalRelease = strtotime($physicalRelease);
  2837. $physicalRelease = date("Y-m-d", $physicalRelease);
  2838. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2839. $downloaded = ($child['status'] == "active") ? "0" : "1";
  2840. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2841. array_push($gotCalendar, array(
  2842. "id" => "CouchPotato-".$i,
  2843. "title" => $movieName,
  2844. "start" => $physicalRelease,
  2845. "className" => $downloaded." movieID--".$movieID,
  2846. "imagetype" => "film",
  2847. ));
  2848. }
  2849. }
  2850. if ($i != 0){ return $gotCalendar; }
  2851. }else{
  2852. writeLog("error", "CouchPotato ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2853. }
  2854. }
  2855. function getRadarrCalendar($array){
  2856. $array = json_decode($array, true);
  2857. $gotCalendar = array();
  2858. $i = 0;
  2859. foreach($array AS $child) {
  2860. if(isset($child['physicalRelease'])){
  2861. $i++;
  2862. $movieName = $child['title'];
  2863. $movieID = $child['tmdbId'];
  2864. if(!isset($movieID)){ $movieID = ""; }
  2865. $physicalRelease = $child['physicalRelease'];
  2866. $physicalRelease = strtotime($physicalRelease);
  2867. $physicalRelease = date("Y-m-d", $physicalRelease);
  2868. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2869. $downloaded = $child['hasFile'];
  2870. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2871. array_push($gotCalendar, array(
  2872. "id" => "Radarr-".$i,
  2873. "title" => $movieName,
  2874. "start" => $physicalRelease,
  2875. "className" => $downloaded." movieID--".$movieID,
  2876. "imagetype" => "film",
  2877. ));
  2878. }
  2879. }
  2880. if ($i != 0){ return $gotCalendar; }
  2881. }
  2882. function getHeadphonesCalendar($url, $key, $list){
  2883. $url = qualifyURL(HEADPHONESURL);
  2884. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2885. $api = json_decode($api, true);
  2886. $i = 0;
  2887. //$gotCalendar = "";
  2888. $gotCalendar = array();;
  2889. if (is_array($api) || is_object($api)){
  2890. foreach($api AS $child) {
  2891. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2892. $i++;
  2893. $albumName = addslashes($child['AlbumTitle']);
  2894. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2895. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2896. $albumID = $child['AlbumID'];
  2897. $albumDate = strtotime($albumDate);
  2898. $albumDate = date("Y-m-d", $albumDate);
  2899. $albumStatus = $child['Status'];
  2900. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2901. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2902. //$gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2903. array_push($gotCalendar, array(
  2904. "id" => "Headphones-".$i,
  2905. "title" => $albumArtist.' - '.$albumName,
  2906. "start" => $albumDate,
  2907. "className" => $albumStatusColor,
  2908. "imagetype" => "music",
  2909. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2910. ));
  2911. }
  2912. if($child['Status'] == "Processed" && $list == "getHistory"){
  2913. $i++;
  2914. $find = array('_','[', ']', '\n');
  2915. $replace = array(' ','(', ')', ' ');
  2916. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  2917. $albumDate = $child['DateAdded'];
  2918. $albumID = $child['AlbumID'];
  2919. $albumDate = strtotime($albumDate);
  2920. $albumDate = date("Y-m-d", $albumDate);
  2921. $albumStatusColor = "green-bg";
  2922. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2923. //$gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2924. array_push($gotCalendar, array(
  2925. "id" => "Headphones-".$i,
  2926. "title" => $albumName,
  2927. "start" => $albumDate,
  2928. "className" => $albumStatusColor,
  2929. "imagetype" => "music",
  2930. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2931. ));
  2932. }
  2933. }
  2934. if ($i != 0){ return $gotCalendar; }
  2935. }else{
  2936. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2937. }
  2938. }
  2939. function checkRootPath($string){
  2940. if($string == "\\" || $string == "/"){
  2941. return "/";
  2942. }else{
  2943. return str_replace("\\", "/", $string) . "/";
  2944. }
  2945. }
  2946. function strip($string){
  2947. $string = strip_tags($string);
  2948. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  2949. }
  2950. function writeLog($type, $message){
  2951. if(file_exists("org.log")){
  2952. if(filesize("org.log") > 500000){
  2953. rename('org.log','org['.date('Y-m-d').'].log');
  2954. $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";
  2955. file_put_contents("org.log", $message2, FILE_APPEND | LOCK_EX);
  2956. }
  2957. }
  2958. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  2959. file_put_contents("org.log", $message, FILE_APPEND | LOCK_EX);
  2960. }
  2961. function readLog(){
  2962. $log = file("org.log",FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  2963. $log = array_reverse($log);
  2964. foreach($log as $line){
  2965. if(substr_count($line, '|') == 2){
  2966. $line = explode("|", strip($line));
  2967. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  2968. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  2969. }
  2970. }
  2971. }
  2972. function buildStream($array){
  2973. $result = "";
  2974. if (array_key_exists('platform', $array)) {
  2975. $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>';
  2976. }
  2977. if (array_key_exists('device', $array)) {
  2978. $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>';
  2979. }
  2980. if (array_key_exists('stream', $array)) {
  2981. $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>';
  2982. }
  2983. if (array_key_exists('video', $array)) {
  2984. $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>';
  2985. }
  2986. if (array_key_exists('audio', $array)) {
  2987. $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>';
  2988. }
  2989. return $result;
  2990. }
  2991. function streamType($value){
  2992. if($value == "transcode" || $value == "Transcode"){
  2993. return "Transcode";
  2994. }elseif($value == "copy" || $value == "DirectStream"){
  2995. return "Direct Stream";
  2996. }elseif($value == "directplay" || $value == "DirectPlay"){
  2997. return "Direct Play";
  2998. }else{
  2999. return "Direct Play";
  3000. }
  3001. }
  3002. function getPlatform($platform){
  3003. $allPlatforms = array(
  3004. "Chrome" => "chrome.png",
  3005. "tvOS" => "atv.png",
  3006. "iOS" => "ios.png",
  3007. "Xbox One" => "xbox.png",
  3008. "Mystery 4" => "playstation.png",
  3009. "Samsung" => "samsung.png",
  3010. "Roku" => "roku.png",
  3011. "Emby for iOS" => "ios.png",
  3012. "Emby Mobile" => "emby.png",
  3013. "Emby Theater" => "emby.png",
  3014. "Emby Classic" => "emby.png",
  3015. "Safari" => "safari.png",
  3016. "Android" => "android.png",
  3017. "AndroidTv" => "android.png",
  3018. "Chromecast" => "chromecast.png",
  3019. "Dashboard" => "emby.png",
  3020. "Dlna" => "dlna.png",
  3021. "Windows Phone" => "wp.png",
  3022. "Windows RT" => "win8.png",
  3023. "Kodi" => "kodi.png",
  3024. );
  3025. if (array_key_exists($platform, $allPlatforms)) {
  3026. return $allPlatforms[$platform];
  3027. }else{
  3028. return "pmp.png";
  3029. }
  3030. }
  3031. function getServer(){
  3032. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  3033. return $server;
  3034. }
  3035. function prettyPrint($array) {
  3036. echo "<pre>";
  3037. print_r($array);
  3038. echo "</pre>";
  3039. echo "<br/>";
  3040. }
  3041. function checkFrame($array, $url){
  3042. if(array_key_exists("x-frame-options", $array)){
  3043. if($array['x-frame-options'] == "deny"){
  3044. return false;
  3045. }elseif($array['x-frame-options'] == "sameorgin"){
  3046. $digest = parse_url($url);
  3047. $host = (isset($digest['host'])?$digest['host']:'');
  3048. if(getServer() == $host){
  3049. return true;
  3050. }else{
  3051. return false;
  3052. }
  3053. }
  3054. }else{
  3055. if(!$array){
  3056. return false;
  3057. }
  3058. return true;
  3059. }
  3060. }
  3061. function frameTest($url){
  3062. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  3063. $url = qualifyURL($url);
  3064. if(checkFrame($array, $url)){
  3065. return true;
  3066. }else{
  3067. return false;
  3068. }
  3069. }
  3070. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  3071. $notifyExplode = explode("-", NOTIFYEFFECT);
  3072. if ($result) {
  3073. $msg = array(
  3074. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  3075. 'icon' => $icon,
  3076. 'type' => 'success',
  3077. 'length' => '5000',
  3078. 'layout' => $notifyExplode[0],
  3079. 'effect' => $notifyExplode[1],
  3080. );
  3081. } else {
  3082. $msg = array(
  3083. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  3084. 'icon' => $icon,
  3085. 'type' => 'error',
  3086. 'length' => '5000',
  3087. 'layout' => $notifyExplode[0],
  3088. 'effect' => $notifyExplode[1],
  3089. );
  3090. }
  3091. // Send and kill script?
  3092. if ($send) {
  3093. header('Content-Type: application/json');
  3094. echo json_encode(array('notify'=>$msg));
  3095. die();
  3096. }
  3097. return $msg;
  3098. }
  3099. function buildHomepageNotice($layout, $type, $title, $message){
  3100. switch ($layout) {
  3101. case 'elegant':
  3102. return '
  3103. <div id="homepageNotice" class="row">
  3104. <div class="col-lg-12">
  3105. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  3106. <div class="content-title i-block">
  3107. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  3108. <div class="content-tools i-block pull-right">
  3109. <a class="close-btn">
  3110. <i class="fa fa-times"></i>
  3111. </a>
  3112. </div>
  3113. </div>
  3114. '.$message.'
  3115. </div>
  3116. </div>
  3117. </div>
  3118. ';
  3119. break;
  3120. case 'basic':
  3121. return '
  3122. <div id="homepageNotice" class="row">
  3123. <div class="col-lg-12">
  3124. <div class="panel panel-'.$type.'">
  3125. <div class="panel-heading">
  3126. <h3 class="panel-title">'.$title.'</h3>
  3127. </div>
  3128. <div class="panel-body">
  3129. '.$message.'
  3130. </div>
  3131. </div>
  3132. </div>
  3133. </div>
  3134. ';
  3135. break;
  3136. case 'jumbotron';
  3137. return '
  3138. <div id="homepageNotice" class="row">
  3139. <div class="col-lg-12">
  3140. <div class="jumbotron">
  3141. <div class="container">
  3142. <h1>'.$title.'</h1>
  3143. <p>'.$message.'</p>
  3144. </div>
  3145. </div>
  3146. </div>
  3147. </div>
  3148. ';
  3149. }
  3150. }
  3151. function embyArray($array, $type) {
  3152. $key = ($type == "video" ? "Height" : "Channels");
  3153. if (array_key_exists($key, $array)) {
  3154. switch ($type) {
  3155. case "video":
  3156. $codec = $array["Codec"];
  3157. $height = $array["Height"];
  3158. $width = $array["Width"];
  3159. break;
  3160. default:
  3161. $codec = $array["Codec"];
  3162. $channels = $array["Channels"];
  3163. }
  3164. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  3165. }
  3166. foreach ($array as $element) {
  3167. if (is_array($element)) {
  3168. if (embyArray($element, $type)) {
  3169. return embyArray($element, $type);
  3170. }
  3171. }
  3172. }
  3173. }
  3174. // Get Now Playing Streams From Plex
  3175. function searchPlex($query){
  3176. $address = qualifyURL(PLEXURL);
  3177. $openTab = (PLEXTABNAME) ? "true" : "false";
  3178. // Perform API requests
  3179. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  3180. libxml_use_internal_errors(true);
  3181. $api = simplexml_load_string($api);
  3182. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3183. if (!$getServer) { return 'Could not load!'; }
  3184. // Identify the local machine
  3185. $server = $getServer['machineIdentifier'];
  3186. $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>";
  3187. $items = "";
  3188. $albums = $movies = $shows = 0;
  3189. $style = 'style="vertical-align: middle"';
  3190. foreach($api AS $child) {
  3191. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  3192. $time = (string)$child['addedAt'];
  3193. $time = new DateTime("@$time");
  3194. $results = array(
  3195. "title" => (string)$child['title'],
  3196. "image" => (string)$child['thumb'],
  3197. "type" => (string)ucwords($child['type']),
  3198. "year" => (string)$child['year'],
  3199. "key" => (string)$child['ratingKey']."-search",
  3200. "ratingkey" => (string)$child['ratingKey'],
  3201. "genre" => (string)$child->Genre['tag'],
  3202. "added" => $time->format('Y-m-d'),
  3203. "extra" => "",
  3204. );
  3205. switch ($child['type']){
  3206. case "album":
  3207. $push = array(
  3208. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  3209. );
  3210. $results = array_replace($results,$push);
  3211. $albums++;
  3212. break;
  3213. case "movie":
  3214. $push = array(
  3215. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  3216. );
  3217. $results = array_replace($results,$push);
  3218. $movies++;
  3219. break;
  3220. case "show":
  3221. $push = array(
  3222. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  3223. );
  3224. $results = array_replace($results,$push);
  3225. $shows++;
  3226. break;
  3227. }
  3228. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  3229. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  3230. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  3231. }
  3232. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  3233. if (PLEXTABURL) {
  3234. $link = PLEXTABURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3235. }else{
  3236. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  3237. }
  3238. $items .= '<tr style="cursor: pointer;" class="openTab" extraTitle="'.$results['title'].'" extraType="'.$child['type'].'" openTab="'.$openTab.'" href="'.$link.'">
  3239. <th scope="row"><img src="'.$image_url.'"></th>
  3240. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  3241. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  3242. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  3243. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  3244. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  3245. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  3246. </tr>';
  3247. }
  3248. }
  3249. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  3250. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  3251. font-size: 23px;
  3252. ">&nbsp;'.$movies.'</strong></span>
  3253. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  3254. font-size: 23px;
  3255. ">&nbsp;'.$shows.'</strong></span>
  3256. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  3257. font-size: 23px;
  3258. ">&nbsp;'.$albums.'</strong></span>
  3259. </div>';
  3260. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  3261. }
  3262. function getBannedUsers($string){
  3263. if (strpos($string, ',') !== false) {
  3264. $banned = explode(",", $string);
  3265. }else{
  3266. $banned = array($string);
  3267. }
  3268. return $banned;
  3269. }
  3270. function getWhitelist($string){
  3271. if (strpos($string, ',') !== false) {
  3272. $whitelist = explode(",", $string);
  3273. }else{
  3274. $whitelist = array($string);
  3275. }
  3276. foreach($whitelist as &$ip){
  3277. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  3278. }
  3279. return $whitelist;
  3280. }
  3281. function get_client_ip() {
  3282. $ipaddress = '';
  3283. if (isset($_SERVER['HTTP_CLIENT_IP']))
  3284. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  3285. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  3286. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3287. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  3288. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  3289. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  3290. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  3291. else if(isset($_SERVER['HTTP_FORWARDED']))
  3292. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  3293. else if(isset($_SERVER['REMOTE_ADDR']))
  3294. $ipaddress = $_SERVER['REMOTE_ADDR'];
  3295. else
  3296. $ipaddress = 'UNKNOWN';
  3297. return $ipaddress;
  3298. }
  3299. //EMAIL SHIT
  3300. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  3301. $mail = new PHPMailer;
  3302. $mail->isSMTP();
  3303. $mail->Host = SMTPHOST;
  3304. $mail->SMTPAuth = SMTPHOSTAUTH;
  3305. $mail->Username = SMTPHOSTUSERNAME;
  3306. $mail->Password = SMTPHOSTPASSWORD;
  3307. $mail->SMTPSecure = SMTPHOSTTYPE;
  3308. $mail->Port = SMTPHOSTPORT;
  3309. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3310. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3311. $mail->isHTML(true);
  3312. if($email){
  3313. $mail->addAddress($email, $username);
  3314. }
  3315. if($cc){
  3316. $mail->addCC($cc);
  3317. }
  3318. if($bcc){
  3319. if(strpos($bcc , ',') === false){
  3320. $mail->addBCC($bcc);
  3321. }else{
  3322. $allEmails = explode(",",$bcc);
  3323. foreach($allEmails as $gotEmail){
  3324. $mail->addBCC($gotEmail);
  3325. }
  3326. }
  3327. }
  3328. $mail->Subject = $subject;
  3329. $mail->Body = $body;
  3330. //$mail->send();
  3331. if(!$mail->send()) {
  3332. writeLog("error", "mail failed to send");
  3333. } else {
  3334. writeLog("success", "mail has been sent");
  3335. }
  3336. }
  3337. //EMAIL SHIT
  3338. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  3339. $mail = new PHPMailer;
  3340. $mail->isSMTP();
  3341. $mail->Host = $host;
  3342. $mail->SMTPAuth = $auth;
  3343. $mail->Username = $username;
  3344. $mail->Password = $password;
  3345. $mail->SMTPSecure = $type;
  3346. $mail->Port = $port;
  3347. $mail->setFrom($from, $sendername);
  3348. $mail->addReplyTo($from, $sendername);
  3349. $mail->isHTML(true);
  3350. $mail->addAddress($to, "Organizr Admin");
  3351. $mail->Subject = "Organizr Test E-Mail";
  3352. $mail->Body = "This was just a test!";
  3353. //$mail->send();
  3354. if(!$mail->send()) {
  3355. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  3356. return false;
  3357. } else {
  3358. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  3359. return true;
  3360. }
  3361. }
  3362. function libraryList(){
  3363. $address = qualifyURL(PLEXURL);
  3364. $headers = array(
  3365. "Accept" => "application/json",
  3366. "X-Plex-Token" => PLEXTOKEN
  3367. );
  3368. libxml_use_internal_errors(true);
  3369. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3370. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3371. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  3372. $libraryList = array();
  3373. foreach($api->SharedServer->Section AS $child) {
  3374. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  3375. }
  3376. foreach($api->SharedServer AS $child) {
  3377. if(!empty($child['username'])){
  3378. $username = (string)strtolower($child['username']);
  3379. $email = (string)strtolower($child['email']);
  3380. $libraryList['users'][$username] = (string)$child['id'];
  3381. $libraryList['emails'][$email] = (string)$child['id'];
  3382. $libraryList['both'][$username] = $email;
  3383. }
  3384. }
  3385. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3386. }
  3387. function plexUserShare($username){
  3388. $address = qualifyURL(PLEXURL);
  3389. $headers = array(
  3390. "Accept" => "application/json",
  3391. "Content-Type" => "application/json",
  3392. "X-Plex-Token" => PLEXTOKEN
  3393. );
  3394. libxml_use_internal_errors(true);
  3395. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3396. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3397. $json = array(
  3398. "server_id" => $gotServer,
  3399. "shared_server" => array(
  3400. //"library_section_ids" => "[26527637]",
  3401. "invited_email" => $username
  3402. )
  3403. );
  3404. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3405. switch ($api['http_code']['http_code']){
  3406. case 400:
  3407. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3408. $result = "$username already has access to the shared libraries";
  3409. break;
  3410. case 401:
  3411. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3412. $result = "Invalid Plex Token";
  3413. break;
  3414. case 200:
  3415. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3416. $result = "$username now has access to your Plex Library";
  3417. break;
  3418. default:
  3419. writeLog("error", "PLEX INVITE: unknown error");
  3420. $result = false;
  3421. }
  3422. return (!empty($result) ? $result : null );
  3423. }
  3424. function plexUserDelete($username){
  3425. $address = qualifyURL(PLEXURL);
  3426. $headers = array(
  3427. "Accept" => "application/json",
  3428. "Content-Type" => "application/json",
  3429. "X-Plex-Token" => PLEXTOKEN
  3430. );
  3431. libxml_use_internal_errors(true);
  3432. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3433. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3434. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3435. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3436. switch ($api['http_code']['http_code']){
  3437. case 401:
  3438. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3439. $result = "Invalid Plex Token";
  3440. break;
  3441. case 200:
  3442. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3443. $result = "$username doesn't have access to your Plex Library anymore";
  3444. break;
  3445. default:
  3446. writeLog("error", "PLEX INVITE: unknown error");
  3447. $result = false;
  3448. }
  3449. return (!empty($result) ? $result : null );
  3450. }
  3451. function convertPlexName($user, $type){
  3452. $array = libraryList();
  3453. switch ($type){
  3454. case "username":
  3455. $plexUser = array_search ($user, $array['users']);
  3456. break;
  3457. case "id":
  3458. if (array_key_exists(strtolower($user), $array['users'])) {
  3459. $plexUser = $array['users'][strtolower($user)];
  3460. }
  3461. break;
  3462. default:
  3463. $plexUser = false;
  3464. }
  3465. return (!empty($plexUser) ? $plexUser : null );
  3466. }
  3467. function randomCode($length = 5, $type = null) {
  3468. switch ($type){
  3469. case "alpha":
  3470. $legend = array_merge(range('A', 'Z'));
  3471. break;
  3472. case "numeric":
  3473. $legend = array_merge(range(0,9));
  3474. break;
  3475. default:
  3476. $legend = array_merge(range(0,9),range('A', 'Z'));
  3477. }
  3478. $code = "";
  3479. for($i=0; $i < $length; $i++) {
  3480. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3481. }
  3482. return $code;
  3483. }
  3484. function inviteCodes($action, $code = null, $usedBy = null) {
  3485. if (!isset($GLOBALS['file_db'])) {
  3486. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3487. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3488. }
  3489. $now = date("Y-m-d H:i:s");
  3490. switch ($action) {
  3491. case "get":
  3492. // Start Array
  3493. $result = array();
  3494. // Database Lookup
  3495. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3496. // Get Codes
  3497. foreach($invites as $row) {
  3498. array_push($result, $row['code']);
  3499. }
  3500. // Return the Results
  3501. return (!empty($result) ? $result : false );
  3502. break;
  3503. case "check":
  3504. // Start Array
  3505. $result = array();
  3506. // Database Lookup
  3507. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3508. // Get Codes
  3509. foreach($invites as $row) {
  3510. $result = $row['code'];
  3511. }
  3512. // Return the Results
  3513. return (!empty($result) ? $result : false );
  3514. break;
  3515. case "use":
  3516. $currentIP = get_client_ip();
  3517. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3518. if(ENABLEMAIL){
  3519. if (!isset($GLOBALS['USER'])) {
  3520. require_once("user.php");
  3521. $GLOBALS['USER'] = new User('registration_callback');
  3522. }
  3523. 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."));
  3524. }
  3525. return (!empty($invites) ? true : false );
  3526. break;
  3527. }
  3528. }
  3529. function plexJoin($username, $email, $password){
  3530. $connectURL = 'https://plex.tv/users.json';
  3531. $headers = array(
  3532. 'Accept'=> 'application/json',
  3533. 'Content-Type' => 'application/x-www-form-urlencoded',
  3534. 'X-Plex-Product' => 'Organizr',
  3535. 'X-Plex-Version' => '1.0',
  3536. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3537. );
  3538. $body = array(
  3539. 'user[email]' => $email,
  3540. 'user[username]' => $username,
  3541. 'user[password]' => $password,
  3542. );
  3543. $api = curl_post($connectURL, $body, $headers);
  3544. $json = json_decode($api['content'], true);
  3545. $errors = (!empty($json['errors']) ? true : false);
  3546. $success = (!empty($json['user']) ? true : false);
  3547. //Use This for later
  3548. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3549. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3550. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3551. $errorMessage = "";
  3552. if($errors){
  3553. if($usernameError){ $errorMessage .= "[Username Error: ". $usernameError ."]"; }
  3554. if($emailError){ $errorMessage .= "[Email Error: ". $emailError ."]"; }
  3555. if($passwordError){ $errorMessage .= "[Password Error: ". $passwordError ."]"; }
  3556. }
  3557. switch ($api['http_code']['http_code']){
  3558. case 400:
  3559. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." $username already has access to the shared libraries $errorMessage");
  3560. break;
  3561. case 401:
  3562. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." invalid Plex Token $errorMessage");
  3563. break;
  3564. case 422:
  3565. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." user info error $errorMessage");
  3566. break;
  3567. case 429:
  3568. writeLog("error", "PLEX JOIN: Error: ".$api['http_code']['http_code']." too many requests to plex.tv please try later $errorMessage");
  3569. break;
  3570. case 200:
  3571. case 201:
  3572. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3573. break;
  3574. default:
  3575. writeLog("error", "PLEX JOIN: unknown error, $errorMessage Error: ".$api['http_code']['http_code']);
  3576. }
  3577. //prettyPrint($api);
  3578. //prettyPrint(json_decode($api['content'], true));
  3579. return (!empty($success) && empty($errors) ? true : false );
  3580. }
  3581. function getCert(){
  3582. $url = "http://curl.haxx.se/ca/cacert.pem";
  3583. $file = getcwd()."/config/cacert.pem";
  3584. $directory = getcwd()."/config/";
  3585. @mkdir($directory, 0770, true);
  3586. if(!file_exists($file)){
  3587. file_put_contents( $file, fopen($url, 'r'));
  3588. writeLog("success", "CERT PEM: pem file created");
  3589. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3590. file_put_contents( $file, fopen($url, 'r'));
  3591. writeLog("success", "CERT PEM: downloaded new pem file");
  3592. }
  3593. return $file;
  3594. }
  3595. function customCSS(){
  3596. if(CUSTOMCSS == "true") {
  3597. $template_file = "custom.css";
  3598. $file_handle = fopen($template_file, "rb");
  3599. echo "\n";
  3600. echo fread($file_handle, filesize($template_file));
  3601. fclose($file_handle);
  3602. echo "\n";
  3603. }
  3604. }
  3605. function tvdbToken(){
  3606. $headers = array(
  3607. "Accept" => "application/json",
  3608. "Content-Type" => "application/json"
  3609. );
  3610. $json = array(
  3611. "apikey" => "FBE7B62621F4CAD7",
  3612. "userkey" => "328BB46EB1E9A0F5",
  3613. "username" => "causefx"
  3614. );
  3615. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3616. return json_decode($api['content'], true)['token'];
  3617. }
  3618. function tvdbGet($id){
  3619. $headers = array(
  3620. "Accept" => "application/json",
  3621. "Authorization" => "Bearer ".tvdbToken(),
  3622. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3623. "trakt-api-version" => "2"
  3624. );
  3625. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3626. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3627. if(empty($api['trakt'])){
  3628. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3629. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3630. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3631. $api['series'] = json_decode($series, true)['data'];
  3632. $api['poster'] = json_decode($poster, true)['data'];
  3633. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3634. }
  3635. return $api;
  3636. }
  3637. function tvdbSearch($name, $type){
  3638. $name = rawurlencode(preg_replace("/\(([^()]*+|(?R))*\)/","", $name));
  3639. $headers = array(
  3640. "Accept" => "application/json",
  3641. "Authorization" => "Bearer ".tvdbToken(),
  3642. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3643. "trakt-api-version" => "2"
  3644. );
  3645. $trakt = curl_get("https://api.trakt.tv/search/$type?query=$name", $headers);
  3646. @$api['trakt'] = json_decode($trakt, true)[0][$type]['ids'];
  3647. return $api;
  3648. }
  3649. function getPlexPlaylists(){
  3650. $address = qualifyURL(PLEXURL);
  3651. // Perform API requests
  3652. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3653. libxml_use_internal_errors(true);
  3654. $api = simplexml_load_string($api);
  3655. if (is_array($api) || is_object($api)){
  3656. if (!$api->head->title){
  3657. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3658. if (!$getServer) { return 'Could not load!'; }
  3659. // Identify the local machine
  3660. $gotServer = $getServer['machineIdentifier'];
  3661. $output = "";
  3662. $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">';
  3663. foreach($api AS $child) {
  3664. $items = array();
  3665. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3666. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3667. $api = simplexml_load_string($api);
  3668. if (is_array($api) || is_object($api)){
  3669. if (!$api->head->title){
  3670. $className = preg_replace("/(\W)+/", "", $api['title']);
  3671. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3672. foreach($api->Video AS $child){
  3673. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3674. }
  3675. if (count($items)) {
  3676. $output .= ''.implode('',$items).'';
  3677. }
  3678. }
  3679. }
  3680. }
  3681. }
  3682. $hideMenu .= '</ul></div></div>';
  3683. 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>';
  3684. }else{
  3685. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3686. }
  3687. }else{
  3688. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3689. }
  3690. }
  3691. function readExternalLog($type,$filename,$name = null){
  3692. $log = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3693. $log = array_reverse($log);
  3694. foreach($log as $line){
  3695. if(!empty($line) && $line[0] != " "){
  3696. $line = strip($line);
  3697. if($type == "single"){
  3698. if( strpos( strtolower($line), "ror" ) !== false ) {
  3699. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3700. }else{
  3701. echo "<tr><td>".$line."</td></tr>";
  3702. }
  3703. }elseif($type == "all"){
  3704. if( strpos( strtolower($line), "ror" ) !== false ) {
  3705. echo "<tr><td class='red-bg'>".$name."</td>";
  3706. echo "<td class='red-bg'>".$line."</td></tr>";
  3707. }else{
  3708. echo "<tr><td>".$name."</td>";
  3709. echo "<td>".$line."</td></tr>";
  3710. }
  3711. }
  3712. }
  3713. }
  3714. }
  3715. function getLogs(){
  3716. $path = __DIR__ ."/logs/";
  3717. @mkdir($path, 0770, true);
  3718. $logs = array();
  3719. $files = array_diff(scandir($path), array('.', '..'));
  3720. foreach($files as $v){
  3721. $title = explode(".", $v)[0];
  3722. $logs[$title] = $path.$v;
  3723. }
  3724. return $logs;
  3725. }
  3726. function getBackups(){
  3727. $path = DATABASE_LOCATION ."backups/";
  3728. @mkdir($path, 0770, true);
  3729. $backups = array();
  3730. $files = array_diff(scandir($path), array('.', '..'));
  3731. return array_reverse($files);
  3732. }
  3733. function getExtension($string) {
  3734. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3735. }
  3736. function showFile(){
  3737. $file = $_GET['file'];
  3738. $fileType = getExtension($file);
  3739. if($fileType != 'php'){
  3740. header("Content-type: ".mimeTypes()[$fileType]);
  3741. @readfile($file);
  3742. }
  3743. }
  3744. function getCalendar(){
  3745. $sonarr = new Sonarr(SONARRURL, SONARRKEY);
  3746. $radarr = new Sonarr(RADARRURL, RADARRKEY);
  3747. $sickrage = new SickRage(SICKRAGEURL, SICKRAGEKEY);
  3748. $startDate = date('Y-m-d',strtotime("-".CALENDARSTARTDAY." days"));
  3749. $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
  3750. $calendarItems = array();
  3751. if (SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)){
  3752. try {
  3753. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate));
  3754. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  3755. } catch (Exception $e) {
  3756. writeLog("error", "SONARR ERROR: ".strip($e->getMessage()));
  3757. }
  3758. }
  3759. if (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)){
  3760. try {
  3761. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate));
  3762. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  3763. } catch (Exception $e) {
  3764. writeLog("error", "RADARR ERROR: ".strip($e->getMessage()));
  3765. }
  3766. }
  3767. if (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH)){
  3768. $couchCalendar = getCouchCalendar();
  3769. if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
  3770. }
  3771. if (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)){
  3772. $headphonesHistory = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getHistory");
  3773. $headphonesWanted = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getWanted");
  3774. if(!empty($headphonesHistory)) { $calendarItems = array_merge($calendarItems, $headphonesHistory); }
  3775. if(!empty($headphonesWanted)) { $calendarItems = array_merge($calendarItems, $headphonesWanted); }
  3776. }
  3777. if (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)){
  3778. try {
  3779. $sickrageFuture = getSickrageCalendarWanted($sickrage->future());
  3780. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  3781. } catch (Exception $e) {
  3782. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3783. } try {
  3784. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"));
  3785. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  3786. } catch (Exception $e) {
  3787. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3788. }
  3789. }
  3790. return $calendarItems;
  3791. }
  3792. function localURL($url){
  3793. if (strpos($url, 'https') !== false) {
  3794. preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $url, $result);
  3795. $result = (!empty($result) ? true : false);
  3796. return $result;
  3797. }
  3798. }
  3799. function fileArray($files){
  3800. foreach($files as $file){
  3801. if(file_exists($file)){
  3802. $list[] = $file;
  3803. }
  3804. }
  3805. if(!empty($list)){ return $list; }
  3806. }
  3807. function backupDB(){
  3808. if (extension_loaded('ZIP')) {
  3809. $directory = DATABASE_LOCATION."backups/";
  3810. @mkdir($directory, 0770, true);
  3811. $orgFiles = array(
  3812. 'css' => 'custom.css',
  3813. 'temp' => 'cus.sd',
  3814. 'orgLog' => 'org.log',
  3815. 'loginLog' => 'loginLog.json',
  3816. 'chatDB' => 'chatpack.db',
  3817. 'config' => 'config/config.php',
  3818. 'database' => DATABASE_LOCATION.'users.db'
  3819. );
  3820. $files = fileArray($orgFiles);
  3821. if(!empty($files)){
  3822. writeLog("success", "BACKUP: backup process started");
  3823. $zipname = $directory.'backup['.date('Y-m-d_H-i').']['.INSTALLEDVERSION.'].zip';
  3824. $zip = new ZipArchive;
  3825. $zip->open($zipname, ZipArchive::CREATE);
  3826. foreach ($files as $file) {
  3827. $zip->addFile($file);
  3828. }
  3829. $zip->close();
  3830. writeLog("success", "BACKUP: backup process finished");
  3831. return true;
  3832. }else{
  3833. return false;
  3834. }
  3835. }else{
  3836. return false;
  3837. }
  3838. }
  3839. class Ping {
  3840. private $host;
  3841. private $ttl;
  3842. private $timeout;
  3843. private $port = 80;
  3844. private $data = 'Ping';
  3845. private $commandOutput;
  3846. /**
  3847. * Called when the Ping object is created.
  3848. *
  3849. * @param string $host
  3850. * The host to be pinged.
  3851. * @param int $ttl
  3852. * Time-to-live (TTL) (You may get a 'Time to live exceeded' error if this
  3853. * value is set too low. The TTL value indicates the scope or range in which
  3854. * a packet may be forwarded. By convention:
  3855. * - 0 = same host
  3856. * - 1 = same subnet
  3857. * - 32 = same site
  3858. * - 64 = same region
  3859. * - 128 = same continent
  3860. * - 255 = unrestricted
  3861. * @param int $timeout
  3862. * Timeout (in seconds) used for ping and fsockopen().
  3863. * @throws \Exception if the host is not set.
  3864. */
  3865. public function __construct($host, $ttl = 255, $timeout = 10) {
  3866. if (!isset($host)) {
  3867. throw new \Exception("Error: Host name not supplied.");
  3868. }
  3869. $this->host = $host;
  3870. $this->ttl = $ttl;
  3871. $this->timeout = $timeout;
  3872. }
  3873. /**
  3874. * Set the ttl (in hops).
  3875. *
  3876. * @param int $ttl
  3877. * TTL in hops.
  3878. */
  3879. public function setTtl($ttl) {
  3880. $this->ttl = $ttl;
  3881. }
  3882. /**
  3883. * Get the ttl.
  3884. *
  3885. * @return int
  3886. * The current ttl for Ping.
  3887. */
  3888. public function getTtl() {
  3889. return $this->ttl;
  3890. }
  3891. /**
  3892. * Set the timeout.
  3893. *
  3894. * @param int $timeout
  3895. * Time to wait in seconds.
  3896. */
  3897. public function setTimeout($timeout) {
  3898. $this->timeout = $timeout;
  3899. }
  3900. /**
  3901. * Get the timeout.
  3902. *
  3903. * @return int
  3904. * Current timeout for Ping.
  3905. */
  3906. public function getTimeout() {
  3907. return $this->timeout;
  3908. }
  3909. /**
  3910. * Set the host.
  3911. *
  3912. * @param string $host
  3913. * Host name or IP address.
  3914. */
  3915. public function setHost($host) {
  3916. $this->host = $host;
  3917. }
  3918. /**
  3919. * Get the host.
  3920. *
  3921. * @return string
  3922. * The current hostname for Ping.
  3923. */
  3924. public function getHost() {
  3925. return $this->host;
  3926. }
  3927. /**
  3928. * Set the port (only used for fsockopen method).
  3929. *
  3930. * Since regular pings use ICMP and don't need to worry about the concept of
  3931. * 'ports', this is only used for the fsockopen method, which pings servers by
  3932. * checking port 80 (by default).
  3933. *
  3934. * @param int $port
  3935. * Port to use for fsockopen ping (defaults to 80 if not set).
  3936. */
  3937. public function setPort($port) {
  3938. $this->port = $port;
  3939. }
  3940. /**
  3941. * Get the port (only used for fsockopen method).
  3942. *
  3943. * @return int
  3944. * The port used by fsockopen pings.
  3945. */
  3946. public function getPort() {
  3947. return $this->port;
  3948. }
  3949. /**
  3950. * Return the command output when method=exec.
  3951. * @return string
  3952. */
  3953. public function getCommandOutput(){
  3954. return $this->commandOutput;
  3955. }
  3956. /**
  3957. * Matches an IP on command output and returns.
  3958. * @return string
  3959. */
  3960. public function getIpAddress() {
  3961. $out = array();
  3962. if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->commandOutput, $out)){
  3963. return $out[0];
  3964. }
  3965. return null;
  3966. }
  3967. /**
  3968. * Ping a host.
  3969. *
  3970. * @param string $method
  3971. * Method to use when pinging:
  3972. * - exec (default): Pings through the system ping command. Fast and
  3973. * robust, but a security risk if you pass through user-submitted data.
  3974. * - fsockopen: Pings a server on port 80.
  3975. * - socket: Creates a RAW network socket. Only usable in some
  3976. * environments, as creating a SOCK_RAW socket requires root privileges.
  3977. *
  3978. * @throws InvalidArgumentException if $method is not supported.
  3979. *
  3980. * @return mixed
  3981. * Latency as integer, in ms, if host is reachable or FALSE if host is down.
  3982. */
  3983. public function ping($method = 'exec') {
  3984. $latency = false;
  3985. switch ($method) {
  3986. case 'exec':
  3987. $latency = $this->pingExec();
  3988. break;
  3989. case 'fsockopen':
  3990. $latency = $this->pingFsockopen();
  3991. break;
  3992. case 'socket':
  3993. $latency = $this->pingSocket();
  3994. break;
  3995. default:
  3996. throw new \InvalidArgumentException('Unsupported ping method.');
  3997. }
  3998. // Return the latency.
  3999. return $latency;
  4000. }
  4001. /**
  4002. * The exec method uses the possibly insecure exec() function, which passes
  4003. * the input to the system. This is potentially VERY dangerous if you pass in
  4004. * any user-submitted data. Be SURE you sanitize your inputs!
  4005. *
  4006. * @return int
  4007. * Latency, in ms.
  4008. */
  4009. private function pingExec() {
  4010. $latency = false;
  4011. $ttl = escapeshellcmd($this->ttl);
  4012. $timeout = escapeshellcmd($this->timeout);
  4013. $host = escapeshellcmd($this->host);
  4014. // Exec string for Windows-based systems.
  4015. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  4016. // -n = number of pings; -i = ttl; -w = timeout (in milliseconds).
  4017. $exec_string = 'ping -n 1 -i ' . $ttl . ' -w ' . ($timeout * 1000) . ' ' . $host;
  4018. }
  4019. // Exec string for Darwin based systems (OS X).
  4020. else if(strtoupper(PHP_OS) === 'DARWIN') {
  4021. // -n = numeric output; -c = number of pings; -m = ttl; -t = timeout.
  4022. $exec_string = 'ping -n -c 1 -m ' . $ttl . ' -t ' . $timeout . ' ' . $host;
  4023. }
  4024. // Exec string for other UNIX-based systems (Linux).
  4025. else {
  4026. // -n = numeric output; -c = number of pings; -t = ttl; -W = timeout
  4027. $exec_string = 'ping -n -c 1 -t ' . $ttl . ' -W ' . $timeout . ' ' . $host . ' 2>&1';
  4028. }
  4029. exec($exec_string, $output, $return);
  4030. // Strip empty lines and reorder the indexes from 0 (to make results more
  4031. // uniform across OS versions).
  4032. $this->commandOutput = implode($output, '');
  4033. $output = array_values(array_filter($output));
  4034. // If the result line in the output is not empty, parse it.
  4035. if (!empty($output[1])) {
  4036. // Search for a 'time' value in the result line.
  4037. $response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)ms/", $output[1], $matches);
  4038. // If there's a result and it's greater than 0, return the latency.
  4039. if ($response > 0 && isset($matches['time'])) {
  4040. $latency = round($matches['time'], 2);
  4041. }
  4042. }
  4043. return $latency;
  4044. }
  4045. /**
  4046. * The fsockopen method simply tries to reach the host on a port. This method
  4047. * is often the fastest, but not necessarily the most reliable. Even if a host
  4048. * doesn't respond, fsockopen may still make a connection.
  4049. *
  4050. * @return int
  4051. * Latency, in ms.
  4052. */
  4053. private function pingFsockopen() {
  4054. $start = microtime(true);
  4055. // fsockopen prints a bunch of errors if a host is unreachable. Hide those
  4056. // irrelevant errors and deal with the results instead.
  4057. $fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  4058. if (!$fp) {
  4059. $latency = false;
  4060. }
  4061. else {
  4062. $latency = microtime(true) - $start;
  4063. $latency = round($latency * 1000, 2);
  4064. }
  4065. return $latency;
  4066. }
  4067. /**
  4068. * The socket method uses raw network packet data to try sending an ICMP ping
  4069. * packet to a server, then measures the response time. Using this method
  4070. * requires the script to be run with root privileges, though, so this method
  4071. * only works reliably on Windows systems and on Linux servers where the
  4072. * script is not being run as a web user.
  4073. *
  4074. * @return int
  4075. * Latency, in ms.
  4076. */
  4077. private function pingSocket() {
  4078. // Create a package.
  4079. $type = "\x08";
  4080. $code = "\x00";
  4081. $checksum = "\x00\x00";
  4082. $identifier = "\x00\x00";
  4083. $seq_number = "\x00\x00";
  4084. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4085. // Calculate the checksum.
  4086. $checksum = $this->calculateChecksum($package);
  4087. // Finalize the package.
  4088. $package = $type . $code . $checksum . $identifier . $seq_number . $this->data;
  4089. // Create a socket, connect to server, then read socket and calculate.
  4090. if ($socket = socket_create(AF_INET, SOCK_RAW, 1)) {
  4091. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array(
  4092. 'sec' => 10,
  4093. 'usec' => 0,
  4094. ));
  4095. // Prevent errors from being printed when host is unreachable.
  4096. @socket_connect($socket, $this->host, null);
  4097. $start = microtime(true);
  4098. // Send the package.
  4099. @socket_send($socket, $package, strlen($package), 0);
  4100. if (socket_read($socket, 255) !== false) {
  4101. $latency = microtime(true) - $start;
  4102. $latency = round($latency * 1000, 2);
  4103. }
  4104. else {
  4105. $latency = false;
  4106. }
  4107. }
  4108. else {
  4109. $latency = false;
  4110. }
  4111. // Close the socket.
  4112. socket_close($socket);
  4113. return $latency;
  4114. }
  4115. /**
  4116. * Calculate a checksum.
  4117. *
  4118. * @param string $data
  4119. * Data for which checksum will be calculated.
  4120. *
  4121. * @return string
  4122. * Binary string checksum of $data.
  4123. */
  4124. private function calculateChecksum($data) {
  4125. if (strlen($data) % 2) {
  4126. $data .= "\x00";
  4127. }
  4128. $bit = unpack('n*', $data);
  4129. $sum = array_sum($bit);
  4130. while ($sum >> 16) {
  4131. $sum = ($sum >> 16) + ($sum & 0xffff);
  4132. }
  4133. return pack('n*', ~$sum);
  4134. }
  4135. }
  4136. function ping($pings, $type = "string") {
  4137. $ping = new Ping("");
  4138. $ping->setTtl(128);
  4139. $ping->setTimeout(2);
  4140. switch ($type){
  4141. case "array":
  4142. $results = [];
  4143. foreach ($pings as $k => $v) {
  4144. if(strpos($v, ':') !== false){
  4145. $domain = explode(':', $v)[0];
  4146. $port = explode(':', $v)[1];
  4147. $ping->setHost($domain);
  4148. $ping->setPort($port);
  4149. $latency = $ping->ping('fsockopen');
  4150. }else{
  4151. $ping->setHost($v);
  4152. $latency = $ping->ping();
  4153. }
  4154. if ($latency || $latency === 0) {
  4155. $results[$k] = $latency;
  4156. } else {
  4157. $results[$k] = 0;
  4158. }
  4159. }
  4160. break;
  4161. case "string":
  4162. if(strpos($pings, ':') !== false){
  4163. $domain = explode(':', $pings)[0];
  4164. $port = explode(':', $pings)[1];
  4165. $ping->setHost($domain);
  4166. $ping->setPort($port);
  4167. $latency = $ping->ping('fsockopen');
  4168. }else{
  4169. $ping->setHost($pings);
  4170. $latency = $ping->ping();
  4171. }
  4172. if ($latency || $latency === 0) {
  4173. $results = $latency;
  4174. } else {
  4175. $results = 0;
  4176. }
  4177. break;
  4178. }
  4179. return $results;
  4180. }
  4181. function getPing($url, $style, $refresh = null){
  4182. if(ping($url) !== 0){
  4183. $class = 'success';
  4184. if(!$refresh){
  4185. $class .= " animated slideInLeft";
  4186. }
  4187. }else{
  4188. $class = "warning";
  4189. if(!$refresh){
  4190. $class .= " animated flash loop-animation-timeout";
  4191. }
  4192. }
  4193. echo '<span class="pingcheck badge ping-'.$class.'" style="position: absolute;z-index: 100;right: 5px; padding: 0px 0px;'.$style.';font-size: 10px;">&nbsp;</span>';
  4194. }
  4195. function speedTestData(){
  4196. $file_db = DATABASE_LOCATION."speedtest.db";
  4197. if(file_exists($file_db)){
  4198. $conn = new PDO("sqlite:$file_db") or die("1");
  4199. $result = $conn->query('SELECT * FROM speedtest_users');
  4200. $conn = null;
  4201. if (is_array($result) || is_object($result)){
  4202. foreach($result as $k => $v){
  4203. $return[$k] = $v;
  4204. }
  4205. return $return;
  4206. }
  4207. }
  4208. }
  4209. function speedTestDisplay($array, $output){
  4210. if (is_array($array) || is_object($array)){
  4211. if($output == "graph"){
  4212. $result = "Morris.Line({element: 'morris-line',data: [";
  4213. foreach($array as $k => $v){
  4214. $result .= "{ y: '".substr($v['timestamp'],0,10)."', a: ".$v['ul'].", b: ".$v['dl'].", c: ".$v['ping']." },";
  4215. }
  4216. $result .= "],xkey: 'y',ykeys: ['a', 'b', 'c'],labels: ['Upload', 'Download', 'Ping'],hideHover: 'auto',resize: true,lineColors: ['#63A8EB','#ccc','#000'] });";
  4217. }elseif($output == "table"){
  4218. $result = "";
  4219. foreach($array as $k => $v){
  4220. $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>";
  4221. }
  4222. }
  4223. return $result;
  4224. }
  4225. }
  4226. function buildMenuPhone($array){
  4227. if (is_array($array) || is_object($array)){
  4228. $result = '
  4229. <div class="content-box profile-sidebar box-shadow">
  4230. <img src="images/organizr-logo-h-d.png" width="100%" style="margin-top: -10px;">
  4231. <div class="profile-usermenu">
  4232. <ul class="nav" id="settings-list">
  4233. ';
  4234. foreach($array as $k => $v){
  4235. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4236. continue;
  4237. }
  4238. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4239. continue;
  4240. }
  4241. /*$result .= '
  4242. <li>
  4243. <a id="'.$v['id'].'" box="'.$v['box'].'">'.$v['name'].'
  4244. <span class="fa-stack fa-fw pull-right" style="margin-top: -5px;margin-right: -10px;">
  4245. <i class="fa fa-'.$v['icon_1'].' fa-stack-2x '.$v['color'].'" style="font-size:null;"></i>
  4246. <i class="fa fa-'.$v['icon_2'].' fa-stack-1x fa-inverse"></i>
  4247. </span>
  4248. </a>
  4249. </li>
  4250. ';*/
  4251. $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>';
  4252. }
  4253. $result .= '</ul></div></div>';
  4254. return $result;
  4255. }
  4256. }
  4257. function buildMenu($array){
  4258. if (is_array($array) || is_object($array)){
  4259. $result = '<div class="settingsList">';
  4260. foreach($array as $k => $v){
  4261. if($v['id'] == 'open-invites' && empty(PLEXURL)){
  4262. continue;
  4263. }
  4264. if($v['id'] == 'open-email' && ENABLEMAIL !== "true"){
  4265. continue;
  4266. }
  4267. $result .= '
  4268. <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">
  4269. <i class="mdi mdi-'.$v['icon_1'].' fa-fw pull-left" style="padding-left: '.$v['padding'].'px;font-size: 30px"></i>
  4270. <p class="" style="text-align: center;direction: rtl;display:none;margin: 2px;"><strong>'.$v['name'].'</strong></p>
  4271. </button>
  4272. ';
  4273. }
  4274. $result .= '</div>';
  4275. return $result;
  4276. }
  4277. }
  4278. function requestInvite($email, $username){
  4279. //sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
  4280. //orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  4281. 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."));
  4282. }
  4283. function errormessage($msg) {
  4284. echo "<div style=\"margin-top: 50px;\">";
  4285. echo "<span style=\"color:#d89334;\">error </span>";
  4286. echo $msg;
  4287. echo "</div>";
  4288. }
  4289. function getOrgUsers(){
  4290. $file_db = DATABASE_LOCATION."users.db";
  4291. if(file_exists($file_db)){
  4292. $conn = new PDO("sqlite:$file_db") or die("1");
  4293. $result = $conn->query('SELECT * FROM users');
  4294. $conn = null;
  4295. if (is_array($result) || is_object($result)){
  4296. foreach($result as $k => $v){
  4297. $return[$v['username']] = $v['email'];
  4298. }
  4299. return $return;
  4300. }
  4301. }
  4302. }
  4303. function getEmails($type = 'org'){
  4304. if($type == 'plex'){
  4305. $emails = array_merge(libraryList()['both'],getOrgUsers());
  4306. }elseif($type == 'emby'){
  4307. $emails = getOrgUsers();
  4308. }else{
  4309. $emails = getOrgUsers();
  4310. }
  4311. return $emails;
  4312. }
  4313. function printEmails($emails){
  4314. $result = '';
  4315. foreach($emails as $k => $v){
  4316. $result .= '<option value="'.$v.'">'.$k.'</option>';
  4317. }
  4318. return $result;
  4319. }
  4320. function massEmail($to, $subject, $message){
  4321. if (!isset($GLOBALS['file_db'])) {
  4322. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  4323. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4324. }
  4325. 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);
  4326. }
  4327. function q2a($q){
  4328. if (is_array($q) || is_object($q)){
  4329. foreach ($q as $k => $v){
  4330. $a[$k] = $v;
  4331. }
  4332. if(!empty($a)){
  4333. return $a;
  4334. }
  4335. }
  4336. }
  4337. function getOmbiToken($username, $password){
  4338. $headers = array(
  4339. "Accept" => "application/json",
  4340. "Content-Type" => "application/json"
  4341. );
  4342. $json = array(
  4343. "username" => $username,
  4344. "password" => $password,
  4345. "rememberMe" => "true",
  4346. );
  4347. $api = curl_post(OMBIURL."/api/v1/Token", $json, $headers);
  4348. return json_decode($api['content'], true)['access_token'];
  4349. }
  4350. function ombiAction($id, $action, $type){
  4351. $headers = array(
  4352. "Accept" => "application/json",
  4353. "Content-Type" => "application/json",
  4354. "Apikey" => OMBIKEY
  4355. );
  4356. $body = array(
  4357. 'id' => $id,
  4358. );
  4359. switch ($type) {
  4360. case 'season':
  4361. case 'tv':
  4362. $type = 'tv';
  4363. break;
  4364. default:
  4365. $type = 'movie';
  4366. break;
  4367. }
  4368. switch ($action) {
  4369. case 'approve':
  4370. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/approve", $body, $headers);
  4371. break;
  4372. case 'available':
  4373. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/available", $body, $headers);
  4374. break;
  4375. case 'unavailable':
  4376. $api = curl_post(OMBIURL."/api/v1/Request/".$type."/unavailable", $body, $headers);
  4377. break;
  4378. case 'deny':
  4379. $api = curl_put(OMBIURL."/api/v1/Request/".$type."/deny", $body, $headers);
  4380. break;
  4381. case 'delete':
  4382. $api = curl_delete(OMBIURL."/api/v1/Request/".$type."/".$id, $headers);
  4383. break;
  4384. default:
  4385. # code...
  4386. break;
  4387. }
  4388. switch ($api['http_code']['http_code']){
  4389. case 401:
  4390. writeLog("error", "OMBI: Invalid API KEY");
  4391. return false;
  4392. break;
  4393. case 200:
  4394. writeLog("success", "OMBI: action completed successfully for [type: $type - action: $action - id: $id]");
  4395. return true;
  4396. break;
  4397. default:
  4398. writeLog("error", "OMBI: unknown error with request [type: $type - action: $action - id: $id]");
  4399. return false;
  4400. }
  4401. //return (!empty($result) ? $result : null );
  4402. }
  4403. function getOmbiRequests($type = "both"){
  4404. $headers = array(
  4405. "Accept" => "application/json",
  4406. "Apikey" => OMBIKEY,
  4407. );
  4408. $requests = array();
  4409. switch ($type) {
  4410. case 'movie':
  4411. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4412. break;
  4413. case 'tv':
  4414. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4415. break;
  4416. default:
  4417. $movie = json_decode(curl_get(OMBIURL."/api/v1/Request/movie", $headers), true);
  4418. $tv = json_decode(curl_get(OMBIURL."/api/v1/Request/tv", $headers), true);
  4419. break;
  4420. }
  4421. if(isset($movie)){
  4422. //$movie = array_reverse($movie);
  4423. foreach ($movie as $key => $value) {
  4424. $poster = explode('/',$value['posterPath']);
  4425. $requests[] = array(
  4426. 'id' => $value['theMovieDbId'],
  4427. 'title' => $value['title'],
  4428. 'poster' => (strpos($value['posterPath'], "/") !== false) ? 'https://image.tmdb.org/t/p/w300/'.end($poster) : 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'],
  4429. 'approved' => $value['approved'],
  4430. 'available' => $value['available'],
  4431. 'denied' => $value['denied'],
  4432. 'deniedReason' => $value['deniedReason'],
  4433. 'user' => $value['requestedUser']['userName'],
  4434. 'request_id' => $value['id'],
  4435. 'request_date' => $value['requestedDate'],
  4436. 'release_date' => $value['releaseDate'],
  4437. 'type' => 'movie',
  4438. 'icon' => 'mdi mdi-filmstrip',
  4439. 'color' => 'palette-Deep-Purple-900 bg white',
  4440. );
  4441. }
  4442. }
  4443. if(isset($tv) && (is_array($tv) || is_object($tv))){
  4444. foreach ($tv as $key => $value) {
  4445. if(is_array($value['childRequests'][0])){
  4446. $requests[] = array(
  4447. 'id' => $value['tvDbId'],
  4448. 'title' => $value['title'],
  4449. 'poster' => $value['posterPath'],
  4450. 'approved' => $value['childRequests'][0]['approved'],
  4451. 'available' => $value['childRequests'][0]['available'],
  4452. 'denied' => $value['childRequests'][0]['denied'],
  4453. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  4454. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  4455. 'request_id' => $value['id'],
  4456. 'request_date' => $value['childRequests'][0]['requestedDate'],
  4457. 'release_date' => $value['releaseDate'],
  4458. 'type' => 'tv',
  4459. 'icon' => 'mdi mdi-television',
  4460. 'color' => 'grayish-blue-bg',
  4461. );
  4462. }
  4463. }
  4464. }
  4465. return (empty($requests)) ? '' : $requests;
  4466. }
  4467. function convertOmbiString($type, $value){
  4468. switch ($type) {
  4469. case 'approved':
  4470. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4471. $string['icon'] = ($value) ? 'mdi mdi-check' : 'mdi mdi-clock';
  4472. $string['color'] = ($value) ? 'green-bg' : 'yellow-bg';
  4473. break;
  4474. case 'available':
  4475. $string['string'] = ($value) ? 'Available' : 'Not Downloaded';
  4476. $string['icon'] = ($value) ? 'mdi mdi-server' : 'mdi mdi-server-off';
  4477. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4478. break;
  4479. case 'denied':
  4480. $string['string'] = ($value) ? 'Denied' : 'Approved';
  4481. $string['icon'] = ($value) ? 'mdi mdi-emoticon-sad' : 'mdi mdi-emoticon-happy';
  4482. $string['color'] = ($value) ? 'red-bg' : 'green-bg';
  4483. break;
  4484. case 'status':
  4485. switch ($value) {
  4486. case '1':
  4487. $string['string'] = 'Denied';
  4488. $string['icon'] = 'mdi mdi-window-close';
  4489. $string['color'] = 'red-bg';
  4490. break;
  4491. case '2':
  4492. $string['string'] = 'Approved';
  4493. $string['icon'] = 'mdi mdi-check';
  4494. $string['color'] = 'green-bg';
  4495. break;
  4496. case '3':
  4497. $string['string'] = 'Not Approved';
  4498. $string['icon'] = 'mdi mdi-clock';
  4499. $string['color'] = 'yellow-bg';
  4500. break;
  4501. default:
  4502. # code...
  4503. break;
  4504. }
  4505. break;
  4506. default:
  4507. $string['string'] = ($value) ? 'Approved' : 'Approval-Pending';
  4508. $string['color'] = ($value) ? 'green-bg' : 'red-bg';
  4509. break;
  4510. }
  4511. return $string;
  4512. }
  4513. function buildOmbiItem($type, $group, $user, $request){
  4514. if (is_array($request) || is_object($request)){
  4515. $actions = '';
  4516. if($request['denied']){
  4517. $status = 1;
  4518. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4519. }else{
  4520. if($request['approved']){
  4521. $status = 2;
  4522. }else{
  4523. $status = 3;
  4524. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="approve"><a class="requestAction" href="javascript:void(0)">Approve</a></li>';
  4525. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="deny"><a class="requestAction" href="javascript:void(0)">Deny</a></li>';
  4526. }
  4527. }
  4528. if($request['available']){
  4529. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="unavailable"><a class="requestAction" href="javascript:void(0)">Mark as Unavailable</a></li>';
  4530. }else{
  4531. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="available"><a class="requestAction" href="javascript:void(0)">Mark as Available</a></li>';
  4532. }
  4533. $actions .= '<li request-type="'.$type.'" request-id="'.$request['request_id'].'" request-name="delete"><a class="requestAction" href="javascript:void(0)">Delete</a></li>';
  4534. if(isset($group) && $group == 'admin'){
  4535. return '
  4536. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4537. <div class="requestOptions">
  4538. <div class="btn-group transparent" role="group">
  4539. <button type="button" class="btn waves btn-success btn-sm dropdown-toggle waves-effect waves-float transparent" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="mdi mdi-dots-vertical mdi-24px"></i></button>
  4540. <ul class="dropdown-menu"><h6 class="text-center requestHeader gray-bg">'.$request['user'].'</h6>'.$actions.'</ul>
  4541. </div>
  4542. </div>
  4543. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4544. <div class="requestBottom text-center">
  4545. <div data-toggle="tooltip" data-placement="top" data-original-title="'.$request['type'].'" class="zero-m requestGroup '.$request['color'].'">
  4546. <i class="'.$request['icon'].'"></i>
  4547. </div>
  4548. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4549. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4550. </div>
  4551. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4552. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4553. </div>
  4554. </div>
  4555. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4556. </div>';
  4557. }elseif(isset($group) && $group == 'user'){
  4558. if(strtolower($request['user']) == strtolower($user)){
  4559. return '
  4560. <div class="item-'.$type.'-'.convertOmbiString('approved', $request['approved'])['string'].'">
  4561. <a class="openTab" extraTitle="'.$request['title'].'" extraType="'.$type.'" openTab="true"><img alt="" class="slick-image-tall" data-lazy="'.$request['poster'].'"></a>
  4562. <div class="requestBottom text-center">
  4563. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('status', $status)['string'].'" class="zero-m requestGroup '.convertOmbiString('status', $status)['color'].'">
  4564. <i class="'.convertOmbiString('status', $status)['icon'].'"></i>
  4565. </div>
  4566. <div data-toggle="tooltip" data-placement="top" data-original-title="'.convertOmbiString('available', $request['available'])['string'].'" class="zero-m requestGroup '.convertOmbiString('available', $request['available'])['color'].'">
  4567. <i class="'.convertOmbiString('available', $request['available'])['icon'].'"></i>
  4568. </div>
  4569. </div>
  4570. <small class="elip slick-bottom-title">'.$request['title'].'</small>
  4571. </div>';
  4572. }
  4573. }
  4574. }
  4575. }
  4576. function buildOmbiList($group, $user){
  4577. $requests = array();
  4578. $movieList = getOmbiRequests('movie');
  4579. $tvList = getOmbiRequests('tv');
  4580. if(is_array($movieList) && is_array($tvList)){
  4581. $result = array_merge($movieList , $tvList );
  4582. }else{
  4583. if(is_array($movieList)){
  4584. $result = $movieList;
  4585. }elseif(is_array($movieList)){
  4586. $result = $tvList;
  4587. }else{
  4588. $result = false;
  4589. }
  4590. }
  4591. if (is_array($result) || is_object($result)){
  4592. usort($result, function ($item1, $item2) {
  4593. if ($item1['request_date'] == $item2['request_date']) return 0;
  4594. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  4595. });
  4596. foreach ($result as $request) {
  4597. if($request['type'] == 'movie'){
  4598. $requests[] = buildOmbiItem('movie', $group, $user, $request);
  4599. }elseif($request['type'] == 'tv'){
  4600. $requests[] = buildOmbiItem('season', $group, $user, $request);
  4601. }
  4602. }
  4603. }
  4604. return outputOmbiRequests("Requested Content", $requests, "
  4605. setInterval(function() {
  4606. $.ajax({
  4607. url: 'ajax.php?a=ombi-requests',
  4608. timeout: 10000,
  4609. type: 'GET',
  4610. success: function(response) {
  4611. var getDiv = response;
  4612. var loadedID = $(getDiv).attr('id');
  4613. $('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
  4614. loadSlick();
  4615. console.log(loadedID+' has been updated');
  4616. },
  4617. error: function(jqXHR, textStatus, errorThrown) {
  4618. console.error(loadedID+' could not be updated');
  4619. }
  4620. });
  4621. }, ".REQUESTREFRESH.");
  4622. ", false);
  4623. }
  4624. function outputOmbiRequests($header = "Requested Content", $items, $script = false, $array) {
  4625. $hideMenu = '<div class="pull-right"><div class="btn-group" role="group"><button type="button" class="btn waves btn-default btn-sm dropdown-toggle waves-effect waves-float" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Filter &nbsp;<span class="caret"></span></button><ul style="right:0; left: auto" class="dropdown-menu filter-request-event">';
  4626. if(preg_grep("/item-movie-Approved/", $items)){
  4627. $hideMenu .= '<li data-filter="item-movie-Approved" data-name="Approved Movies" data-filter-on="false"><a class="js-filter-movie" href="javascript:void(0)">Approved Movies</a></li>';
  4628. }
  4629. if(preg_grep("/item-movie-Approval-Pending/", $items)){
  4630. $hideMenu .= '<li data-filter="item-movie-Approval-Pending" data-name="Approval Pending Movies" data-filter-on="false"><a class="js-filter-movie" href="javascript:void(0)">Approval Pending Movies</a></li>';
  4631. }
  4632. if(preg_grep("/item-season-Approved/", $items)){
  4633. $hideMenu .= '<li data-filter="item-season-Approved" data-name="Approved TV Shows" data-filter-on="false"><a class="js-filter-season" href="javascript:void(0)">Approved Shows</a></li>';
  4634. }
  4635. if(preg_grep("/item-season-Approval-Pending/", $items)){
  4636. $hideMenu .= '<li data-filter="item-season-Approval-Pending" data-name="Approval Pending TV Shows" data-filter-on="false"><a class="js-filter-season" href="javascript:void(0)">Approval Pending Shows</a></li>';
  4637. }
  4638. $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>';
  4639. $hideMenu .= '</ul></div></div>';
  4640. // If None Populate Empty Item
  4641. if (!count($items)) {
  4642. return '<div id="recentRequests" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Requests Found</p></div>';
  4643. }else{
  4644. $className = str_replace(' ', '', $header);
  4645. return '<div id="recentRequests" class="content-box box-shadow big-box"><h5 id="requestContent-title" style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-request" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  4646. }
  4647. }
  4648. function loadIcons(){
  4649. $dirname = "images/";
  4650. $images = scandir($dirname);
  4651. $ignore = Array(".", "..", "favicon", "settings", "cache", "platforms", "._.DS_Store", ".DS_Store", "confused.png", "sowwy.png", "sort-btns", "loading.png", "titlelogo.png", "default.svg", "login.png", "no-np.png", "no-list.png", "no-np.psd", "no-list.psd", "themes", "nadaplaying.jpg", "organizr-logo-h-d.png", "organizr-logo-h.png");
  4652. $allIcons = '';
  4653. foreach($images as $curimg){
  4654. if(!in_array($curimg, $ignore)) {
  4655. $allIcons .= '
  4656. <div class="col-xs-2" style="width: 75px; height: 75px; padding-right: 0px;">
  4657. <a data-toggle="tooltip" data-placement="bottom" title="'.$dirname.$curimg.'" class="thumbnail" style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
  4658. <img style="width: 50px; height: 50px;" data-src="'.$dirname.$curimg.'" alt="thumbnail" class="allIcons lazyload shadow">
  4659. </a>
  4660. </div>
  4661. ';
  4662. }
  4663. }
  4664. return $allIcons;
  4665. }
  4666. function buildHomepageSettings(){
  4667. $homepageOrder = homepageOrder();
  4668. $homepageList = '<h4>Drag Homepage Items to Order Them</h4><div id="homepage-items" class="external-events">';
  4669. $inputList = '<div id="homepage-values" class="row">';
  4670. foreach ($homepageOrder as $key => $val) {
  4671. switch ($key) {
  4672. case 'homepageOrdercustomhtml':
  4673. $class = 'palette-Deep-Purple-100 bg gray';
  4674. $image = 'images/html.png';
  4675. if(empty(HOMEPAGECUSTOMHTML1)){
  4676. $class .= ' faded';
  4677. }
  4678. break;
  4679. case 'homepageOrdernotice':
  4680. $class = 'palette-Cyan-A400 bg gray';
  4681. $image = 'images/pin.png';
  4682. if(empty(HOMEPAGENOTICETITLE) && empty(HOMEPAGENOTICEMESSAGE)){
  4683. $class .= ' faded';
  4684. }
  4685. break;
  4686. case 'homepageOrderspeedtest':
  4687. $class = 'red-bg';
  4688. $image = 'images/settings/full-color/png/64px/speedometer.png';
  4689. if(SPEEDTEST !== "true"){
  4690. $class .= ' faded';
  4691. }
  4692. break;
  4693. case 'homepageOrdernzbget':
  4694. $class = 'green-bg';
  4695. $image = 'images/nzbget.png';
  4696. if(empty(NZBGETURL)){
  4697. $class .= ' faded';
  4698. }
  4699. break;
  4700. case 'homepageOrdersabnzbd':
  4701. $class = 'yellow-bg';
  4702. $image = 'images/sabnzbd.png';
  4703. if(empty(SABNZBDURL)){
  4704. $class .= ' faded';
  4705. }
  4706. break;
  4707. case 'homepageOrderplexsearch':
  4708. case 'homepageOrderplexnowplaying':
  4709. case 'homepageOrderplexrecent':
  4710. case 'homepageOrderplexplaylist':
  4711. $class = 'palette-Amber-A700 bg gray';
  4712. $image = 'images/plex.png';
  4713. if(empty(PLEXURL)){
  4714. $class .= ' faded';
  4715. }
  4716. break;
  4717. case 'homepageOrderembynowplaying':
  4718. case 'homepageOrderembyrecent':
  4719. $class = 'palette-Green-A700 bg gray';
  4720. $image = 'images/emby.png';
  4721. if(empty(EMBYURL)){
  4722. $class .= ' faded';
  4723. }
  4724. break;
  4725. case 'homepageOrderombi':
  4726. $class = 'orange-bg';
  4727. $image = 'images/ombi.png';
  4728. if(empty(OMBIURL)){
  4729. $class .= ' faded';
  4730. }
  4731. break;
  4732. case 'homepageOrdercalendar':
  4733. $class = 'palette-Blue-400 bg gray';
  4734. $image = 'images/calendar.png';
  4735. if(SONARRURL == "" && RADARRURL == "" && HEADPHONESURL == "" && SICKRAGEURL == "" && COUCHURL == "" ){
  4736. $class .= ' faded';
  4737. }
  4738. break;
  4739. default:
  4740. $class = 'blue-bg';
  4741. $image = '';
  4742. break;
  4743. }
  4744. $homepageList .= '
  4745. <div class="col-md-3 sort-homepage"><div class="fc-event '.$class.'">
  4746. <span class="ordinal-position text-uppercase badge badge-gray" data-link="'.$key.'" style="float:left;width: 30px;">'.$val.'</span>
  4747. &nbsp; '.strtoupper(substr($key, 13)).'
  4748. <span class="remove-event"><img style="width: 22px;" src="'.$image.'"></span>
  4749. </div></div>';
  4750. $inputList .= '<input type="hidden" name="'.$key.'">';
  4751. }
  4752. $homepageList .= '</div>';
  4753. $inputList .= '</div>';
  4754. return $homepageList.$inputList;
  4755. }
  4756. function buildHomepage($group, $user){
  4757. $homepageOrder = homepageOrder();
  4758. $homepageBuilt = '';
  4759. foreach ($homepageOrder as $key => $value) {
  4760. $homepageBuilt .= buildHomepageItem($key, $group, $user);
  4761. }
  4762. return $homepageBuilt;
  4763. }
  4764. function realSize($bytes, $decimals = 2) {
  4765. $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
  4766. $factor = floor((strlen($bytes) - 1) / 3);
  4767. return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' '.@$size[$factor];
  4768. }
  4769. function buildHomepageItem($homepageItem, $group, $user){
  4770. $homepageItemBuilt = '';
  4771. switch ($homepageItem) {
  4772. case 'homepageOrderplexsearch':
  4773. if((qualifyUser(PLEXSEARCHAUTH) && PLEXSEARCH == "true" && qualifyUser(PLEXHOMEAUTH))) {
  4774. $homepageItemBuilt .= '
  4775. <div id="searchPlexRow" class="row">
  4776. <div class="col-lg-12">
  4777. <div class="content-box box-shadow big-box todo-list">
  4778. <form id="plexSearchForm" onsubmit="return false;" autocomplete="off">
  4779. <div class="">
  4780. <div class="input-group">
  4781. <div style="border-radius: 25px 0 0 25px; border:0" class="input-group-addon gray-bg"><i class="fa fa-search white"></i></div>
  4782. <input id="searchInput" type="text" style="border-radius: 0;" autocomplete="off" name="search-title" class="form-control input-group-addon gray-bg" placeholder="Media Search">
  4783. <div id="clearSearch" style="border-radius: 0 25px 25px 0;border:0; cursor: pointer;" class="input-group-addon gray-bg"><i class="fa fa-close white"></i></div>
  4784. <button style="display:none" id="plexSearchForm_submit" class="btn btn-primary waves"></button>
  4785. </div>
  4786. </div>
  4787. </form>
  4788. <div id="resultshere" class="table-responsive"></div>
  4789. </div>
  4790. </div>
  4791. </div>
  4792. ';
  4793. }
  4794. break;
  4795. case 'homepageOrdercustomhtml':
  4796. if (qualifyUser(HOMEPAGECUSTOMHTML1AUTH) && HOMEPAGECUSTOMHTML1) {
  4797. $homepageItemBuilt .= "<div>" . HOMEPAGECUSTOMHTML1 . "</div>";
  4798. }
  4799. break;
  4800. case 'homepageOrdernotice':
  4801. if (qualifyUser(HOMEPAGENOTICEAUTH) && HOMEPAGENOTICETITLE && HOMEPAGENOTICETYPE && HOMEPAGENOTICEMESSAGE && HOMEPAGENOTICELAYOUT) {
  4802. $homepageItemBuilt .= buildHomepageNotice(HOMEPAGENOTICELAYOUT, HOMEPAGENOTICETYPE, HOMEPAGENOTICETITLE, HOMEPAGENOTICEMESSAGE);
  4803. }
  4804. break;
  4805. case 'homepageOrderspeedtest':
  4806. if(SPEEDTEST == "true" && qualifyUser(SPEEDTESTAUTH)){
  4807. $homepageItemBuilt .= '
  4808. <style type="text/css">
  4809. .flash {
  4810. animation: flash 0.6s linear infinite;
  4811. }
  4812. @keyframes flash {
  4813. 0% { opacity: 0.6; }
  4814. 50% { opacity: 1; }
  4815. }
  4816. </style>
  4817. <script type="text/javascript">
  4818. var w = null
  4819. function runTest() {
  4820. document.getElementById("startBtn").style.display = "none"
  4821. document.getElementById("testArea").style.display = ""
  4822. document.getElementById("abortBtn").style.display = ""
  4823. w = new Worker("bower_components/speed/speedtest_worker.js")
  4824. var interval = setInterval(function () { w.postMessage("status") }, 100)
  4825. w.onmessage = function (event) {
  4826. var data = event.data.split(";")
  4827. var status = Number(data[0])
  4828. var dl = document.getElementById("download")
  4829. var ul = document.getElementById("upload")
  4830. var ping = document.getElementById("ping")
  4831. var jitter = document.getElementById("jitter")
  4832. dl.className = status === 1 ? "w-name flash" : "w-name"
  4833. ping.className = status === 2 ? "w-name flash" : "w-name"
  4834. jitter.className = ul.className = status === 3 ? "w-name flash" : "w-name"
  4835. if (status >= 4) {
  4836. clearInterval(interval)
  4837. document.getElementById("abortBtn").style.display = "none"
  4838. document.getElementById("startBtn").style.display = ""
  4839. w = null
  4840. }
  4841. if (status === 5) {
  4842. document.getElementById("testArea").style.display = "none"
  4843. }
  4844. dl.textContent = data[1] + " Mbit/s";
  4845. $("#downloadpercent").attr("style", "width: " + data[1] + "%;");
  4846. $("#uploadpercent").attr("style", "width: " + data[2] + "%;");
  4847. $("#pingpercent").attr("style", "width: " + data[3] + "%;");
  4848. $("#jitterpercent").attr("style", "width: " + data[5] + "%;");
  4849. ul.textContent = data[2] + " Mbit/s";
  4850. ping.textContent = data[3] + " ms";
  4851. jitter.textContent = data[5] + " ms";
  4852. }
  4853. w.postMessage(\'start {"telemetry_level":"basic"}\')
  4854. //w.postMessage("start")
  4855. }
  4856. function abortTest() {
  4857. if (w) w.postMessage("abort")
  4858. }
  4859. </script>
  4860. <div class="row" id="testArea" style="display:none">
  4861. <div class="test col-sm-3 col-lg-3">
  4862. <div class="content-box ultra-widget green-bg" data-counter="">
  4863. <div id="downloadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4864. <div class="w-content">
  4865. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-download"></i></div>
  4866. <div class="w-descr left pull-left text-center">
  4867. <span class="testName text-uppercase w-name">Download</span>
  4868. <br>
  4869. <span class="w-name counter" id="download" ></span>
  4870. </div>
  4871. </div>
  4872. </div>
  4873. </div>
  4874. <div class="test col-sm-3 col-lg-3">
  4875. <div class="content-box ultra-widget red-bg" data-counter="">
  4876. <div id="uploadpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4877. <div class="w-content">
  4878. <div class="w-icon right pull-right"><i class="mdi mdi-cloud-upload"></i></div>
  4879. <div class="w-descr left pull-left text-center">
  4880. <span class="testName text-uppercase w-name">Upload</span>
  4881. <br>
  4882. <span class="w-name counter" id="upload" ></span>
  4883. </div>
  4884. </div>
  4885. </div>
  4886. </div>
  4887. <div class="test col-sm-3 col-lg-3">
  4888. <div class="content-box ultra-widget yellow-bg" data-counter="">
  4889. <div id="pingpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4890. <div class="w-content">
  4891. <div class="w-icon right pull-right"><i class="mdi mdi-timer"></i></div>
  4892. <div class="w-descr left pull-left text-center">
  4893. <span class="testName text-uppercase w-name">Latency</span>
  4894. <br>
  4895. <span class="w-name counter" id="ping" ></span>
  4896. </div>
  4897. </div>
  4898. </div>
  4899. </div>
  4900. <div class="test col-sm-3 col-lg-3">
  4901. <div class="content-box ultra-widget blue-bg" data-counter="">
  4902. <div id="jitterpercent" class="progress-bar progress-bar-striped active w-used" style=""></div>
  4903. <div class="w-content">
  4904. <div class="w-icon right pull-right"><i class="mdi mdi-pulse"></i></div>
  4905. <div class="w-descr left pull-left text-center">
  4906. <span class="testName text-uppercase w-name">Jitter</span>
  4907. <br>
  4908. <span class="w-name counter" id="jitter" ></span>
  4909. </div>
  4910. </div>
  4911. </div>
  4912. </div>
  4913. <br/>
  4914. </div>
  4915. <div id="abortBtn" class="row" style="display: none" onclick="javascript:abortTest()">
  4916. <div class="col-lg-12">
  4917. <div class="content-box red-bg" style="cursor: pointer;">
  4918. <h1 style="margin: 10px" class="text-uppercase text-center">Abort Speed Test</h1>
  4919. <div class="clearfix"></div>
  4920. </div>
  4921. </div>
  4922. </div>
  4923. <div id="startBtn" class="row" onclick="javascript:runTest()">
  4924. <div class="col-lg-12">
  4925. <div class="content-box green-bg" style="cursor: pointer;">
  4926. <h1 style="margin: 10px" class="text-uppercase text-center">Run Speed Test</h1>
  4927. <div class="clearfix"></div>
  4928. </div>
  4929. </div>
  4930. </div>
  4931. ';
  4932. }
  4933. break;
  4934. case 'homepageOrdernzbget':
  4935. if(NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)){
  4936. $homepageItemBuilt .= buildDownloader('nzbget');
  4937. }
  4938. break;
  4939. case 'homepageOrdersabnzbd':
  4940. if(SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH)) {
  4941. $homepageItemBuilt .= buildDownloader('sabnzbd');
  4942. }
  4943. break;
  4944. case 'homepageOrderplexnowplaying':
  4945. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4946. if(qualifyUser(PLEXPLAYINGNOWAUTH) && PLEXPLAYINGNOW == "true"){
  4947. $homepageItemBuilt .= '<div id="plexRowNowPlaying" class="row">';
  4948. $homepageItemBuilt .= getPlexStreams(12, PLEXSHOWNAMES, $group);
  4949. $homepageItemBuilt .= '</div>';
  4950. }
  4951. }
  4952. break;
  4953. case 'homepageOrderplexrecent':
  4954. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4955. if(qualifyUser(PLEXRECENTMOVIEAUTH) && PLEXRECENTMOVIE == "true" || qualifyUser(PLEXRECENTTVAUTH) && PLEXRECENTTV == "true" || qualifyUser(PLEXRECENTMUSICAUTH) && PLEXRECENTMUSIC == "true"){
  4956. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  4957. $homepageItemBuilt .= '<div id="plexRow" class="row"><div class="col-lg-12">';
  4958. $homepageItemBuilt .= getPlexRecent($plexArray);
  4959. $homepageItemBuilt .= '</div></div>';
  4960. }
  4961. }
  4962. break;
  4963. case 'homepageOrderplexplaylist':
  4964. if (qualifyUser(PLEXHOMEAUTH) && PLEXTOKEN) {
  4965. if(qualifyUser(PLEXPLAYLISTSAUTH) && PLEXPLAYLISTS == "true"){
  4966. $homepageItemBuilt .= '<div id="plexPlaylists" class="row"><div class="col-lg-12">';
  4967. $plexArray = array("movie" => PLEXRECENTMOVIE, "season" => PLEXRECENTTV, "album" => PLEXRECENTMUSIC);
  4968. $homepageItemBuilt .= getPlexPlaylists($plexArray);
  4969. $homepageItemBuilt .= '</div> </div>';
  4970. }
  4971. }
  4972. break;
  4973. case 'homepageOrderembynowplaying':
  4974. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  4975. if(qualifyUser(EMBYPLAYINGNOWAUTH) && EMBYPLAYINGNOW == "true"){
  4976. $homepageItemBuilt .= '<div id="embyRowNowPlaying" class="row">';
  4977. $homepageItemBuilt .= getEmbyStreams(12, EMBYSHOWNAMES, $group);
  4978. $homepageItemBuilt .= '</div>';
  4979. }
  4980. }
  4981. break;
  4982. case 'homepageOrderembyrecent':
  4983. if (qualifyUser(EMBYHOMEAUTH) && EMBYTOKEN) {
  4984. if(qualifyUser(EMBYRECENTMOVIEAUTH) && EMBYRECENTMOVIE == "true" || qualifyUser(EMBYRECENTTVAUTH) && EMBYRECENTTV == "true" || qualifyUser(EMBYRECENTMUSICAUTH) && EMBYRECENTMUSIC == "true"){
  4985. $embyArray = array("Movie" => EMBYRECENTMOVIE, "Episode" => EMBYRECENTTV, "MusicAlbum" => EMBYRECENTMUSIC, "Series" => EMBYRECENTTV);
  4986. $homepageItemBuilt .= '<div id="embyRow" class="row"><div class="col-lg-12">';
  4987. $homepageItemBuilt .= getEmbyRecent($embyArray);
  4988. $homepageItemBuilt .= '</div></div>';
  4989. }
  4990. }
  4991. break;
  4992. case 'homepageOrderombi':
  4993. if (qualifyUser(OMBIAUTH) && OMBIURL) {
  4994. $homepageItemBuilt .= '<div id="ombiRequests" class="row"><div class="col-lg-12">';
  4995. $homepageItemBuilt .= buildOmbiList($group, $user);
  4996. $homepageItemBuilt .= '</div></div>';
  4997. }
  4998. break;
  4999. case 'homepageOrdercalendar':
  5000. if ((SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)) || (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)) || (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)) || (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)) || (COUCHURL != "" && qualifyUser(COUCHHOMEAUTH))) {
  5001. $calendarItems = '';
  5002. if(RADARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="film" href="javascript:void(0)">Movies</a></li>'; }
  5003. if(SONARRURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="tv" href="javascript:void(0)">TV Shows</a></li>'; }
  5004. if(HEADPHONESURL != ""){ $calendarItems .= '<li><a class="calendarOption" calendarOption="music" href="javascript:void(0)">Music</a></li>'; }
  5005. $homepageItemBuilt .= '
  5006. <div id="calendarLegendRow" class="row" style="padding: 0 0 10px 0;">
  5007. <div class="col-lg-12 content-form form-inline">
  5008. <div class="form-group pull-right">
  5009. <span class="swal-legend label label-primary well-sm">Legend</span>&nbsp;
  5010. <div class="btn-group" role="group">
  5011. <button id="calendarSelected" style="margin-right: 0px;" type="button" class="btn waves btn-default btn-sm dropdown-toggle waves-effect waves-float" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">View All&nbsp;<span class="caret"></span></button>
  5012. <ul style="right:0; left: auto" class="dropdown-menu">
  5013. <li><a class="calendarOption" calendarOption="all" href="javascript:void(0)">View All</a></li>
  5014. '.$calendarItems.'
  5015. </ul>
  5016. </div>
  5017. </div>
  5018. </div>
  5019. </div>
  5020. <div id="calendarRow" class="row">
  5021. <div class="col-lg-12">
  5022. <div id="calendar" class="fc-calendar box-shadow fc fc-ltr fc-unthemed"></div>
  5023. </div>
  5024. </div>
  5025. ';
  5026. }
  5027. break;
  5028. default:
  5029. # code...
  5030. break;
  5031. }
  5032. return $homepageItemBuilt;
  5033. }
  5034. function buildDownloader($name){
  5035. return '
  5036. <div id="downloadClientRow" class="row">
  5037. <div class="col-xs-12 col-md-12">
  5038. <div class="content-box">
  5039. <div class="tabbable panel with-nav-tabs panel-default">
  5040. <div class="panel-heading">
  5041. <div class="content-tools i-block pull-right">
  5042. <a id="getDownloader" class="repeat-btn">
  5043. <i class="fa fa-repeat"></i>
  5044. </a>
  5045. </div>
  5046. <h3 class="pull-left">'.strtoupper($name).'</h3>
  5047. <ul class="nav nav-tabs pull-right">
  5048. <li class="active"><a href="#downloadQueue-'.$name.'" data-toggle="tab" aria-expanded="true">'.translate("QUEUE").'</a></li>
  5049. <li class=""><a href="#downloadHistory-'.$name.'" data-toggle="tab" aria-expanded="false">'.translate("HISTORY").'</a></li>
  5050. </ul>
  5051. <div class="clearfix"></div>
  5052. </div>
  5053. <div class="panel-body">
  5054. <div class="tab-content">
  5055. <div class="tab-pane fade active in" id="downloadQueue-'.$name.'">
  5056. <div class="table-responsive" style="max-height: 300px">
  5057. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5058. <thead>
  5059. <tr>
  5060. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5061. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5062. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5063. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5064. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5065. </tr>
  5066. </thead>
  5067. <tbody class="dl-queue '.$name.'"></tbody>
  5068. </table>
  5069. </div>
  5070. </div>
  5071. <div class="tab-pane fade" id="downloadHistory-'.$name.'">
  5072. <div class="table-responsive" style="max-height: 300px">
  5073. <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
  5074. <thead>
  5075. <tr>
  5076. <th class="col-xs-7 nzbtable-file-row">'.translate("FILE").'</th>
  5077. <th class="col-xs-2 nzbtable">'.translate("STATUS").'</th>
  5078. <th class="col-xs-1 nzbtable">'.translate("CATEGORY").'</th>
  5079. <th class="col-xs-1 nzbtable">'.translate("SIZE").'</th>
  5080. <th class="col-xs-2 nzbtable">'.translate("PROGRESS").'</th>
  5081. </tr>
  5082. </thead>
  5083. <tbody class="dl-history '.$name.'"></tbody>
  5084. </table>
  5085. </div>
  5086. </div>
  5087. </div>
  5088. </div>
  5089. </div>
  5090. </div>
  5091. </div>
  5092. </div>';
  5093. }
  5094. class Mobile_Detect
  5095. {
  5096. /**
  5097. * Mobile detection type.
  5098. *
  5099. * @deprecated since version 2.6.9
  5100. */
  5101. const DETECTION_TYPE_MOBILE = 'mobile';
  5102. /**
  5103. * Extended detection type.
  5104. *
  5105. * @deprecated since version 2.6.9
  5106. */
  5107. const DETECTION_TYPE_EXTENDED = 'extended';
  5108. /**
  5109. * A frequently used regular expression to extract version #s.
  5110. *
  5111. * @deprecated since version 2.6.9
  5112. */
  5113. const VER = '([\w._\+]+)';
  5114. /**
  5115. * Top-level device.
  5116. */
  5117. const MOBILE_GRADE_A = 'A';
  5118. /**
  5119. * Mid-level device.
  5120. */
  5121. const MOBILE_GRADE_B = 'B';
  5122. /**
  5123. * Low-level device.
  5124. */
  5125. const MOBILE_GRADE_C = 'C';
  5126. /**
  5127. * Stores the version number of the current release.
  5128. */
  5129. const VERSION = '2.8.26';
  5130. /**
  5131. * A type for the version() method indicating a string return value.
  5132. */
  5133. const VERSION_TYPE_STRING = 'text';
  5134. /**
  5135. * A type for the version() method indicating a float return value.
  5136. */
  5137. const VERSION_TYPE_FLOAT = 'float';
  5138. /**
  5139. * A cache for resolved matches
  5140. * @var array
  5141. */
  5142. protected $cache = array();
  5143. /**
  5144. * The User-Agent HTTP header is stored in here.
  5145. * @var string
  5146. */
  5147. protected $userAgent = null;
  5148. /**
  5149. * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.
  5150. * @var array
  5151. */
  5152. protected $httpHeaders = array();
  5153. /**
  5154. * CloudFront headers. E.g. CloudFront-Is-Desktop-Viewer, CloudFront-Is-Mobile-Viewer & CloudFront-Is-Tablet-Viewer.
  5155. * @var array
  5156. */
  5157. protected $cloudfrontHeaders = array();
  5158. /**
  5159. * The matching Regex.
  5160. * This is good for debug.
  5161. * @var string
  5162. */
  5163. protected $matchingRegex = null;
  5164. /**
  5165. * The matches extracted from the regex expression.
  5166. * This is good for debug.
  5167. * @var string
  5168. */
  5169. protected $matchesArray = null;
  5170. /**
  5171. * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.
  5172. *
  5173. * @deprecated since version 2.6.9
  5174. *
  5175. * @var string
  5176. */
  5177. protected $detectionType = self::DETECTION_TYPE_MOBILE;
  5178. /**
  5179. * HTTP headers that trigger the 'isMobile' detection
  5180. * to be true.
  5181. *
  5182. * @var array
  5183. */
  5184. protected static $mobileHeaders = array(
  5185. 'HTTP_ACCEPT' => array('matches' => array(
  5186. // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
  5187. 'application/x-obml2d',
  5188. // BlackBerry devices.
  5189. 'application/vnd.rim.html',
  5190. 'text/vnd.wap.wml',
  5191. 'application/vnd.wap.xhtml+xml'
  5192. )),
  5193. 'HTTP_X_WAP_PROFILE' => null,
  5194. 'HTTP_X_WAP_CLIENTID' => null,
  5195. 'HTTP_WAP_CONNECTION' => null,
  5196. 'HTTP_PROFILE' => null,
  5197. // Reported by Opera on Nokia devices (eg. C3).
  5198. 'HTTP_X_OPERAMINI_PHONE_UA' => null,
  5199. 'HTTP_X_NOKIA_GATEWAY_ID' => null,
  5200. 'HTTP_X_ORANGE_ID' => null,
  5201. 'HTTP_X_VODAFONE_3GPDPCONTEXT' => null,
  5202. 'HTTP_X_HUAWEI_USERID' => null,
  5203. // Reported by Windows Smartphones.
  5204. 'HTTP_UA_OS' => null,
  5205. // Reported by Verizon, Vodafone proxy system.
  5206. 'HTTP_X_MOBILE_GATEWAY' => null,
  5207. // Seen this on HTC Sensation. SensationXE_Beats_Z715e.
  5208. 'HTTP_X_ATT_DEVICEID' => null,
  5209. // Seen this on a HTC.
  5210. 'HTTP_UA_CPU' => array('matches' => array('ARM')),
  5211. );
  5212. /**
  5213. * List of mobile devices (phones).
  5214. *
  5215. * @var array
  5216. */
  5217. protected static $phoneDevices = array(
  5218. 'iPhone' => '\biPhone\b|\biPod\b', // |\biTunes
  5219. 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+',
  5220. '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',
  5221. 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 6',
  5222. // @todo: Is 'Dell Streak' a tablet or a phone? ;)
  5223. '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',
  5224. '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',
  5225. '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',
  5226. '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)',
  5227. 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|LT26w|SonyEricssonMT27i|C5303|C6902|C6903|C6906|C6943|D2533',
  5228. 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile',
  5229. 'NokiaLumia' => 'Lumia [0-9]{3,4}',
  5230. // http://www.micromaxinfo.com/mobiles/smartphones
  5231. // Added because the codes might conflict with Acer Tablets.
  5232. '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',
  5233. // @todo Complete the regex.
  5234. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ;
  5235. 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
  5236. // http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
  5237. // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android.
  5238. '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',
  5239. // http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones.
  5240. 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250',
  5241. // http://fr.wikomobile.com
  5242. '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',
  5243. 'iMobile' => 'i-mobile (IQ|i-STYLE|idea|ZAA|Hitz)',
  5244. // Added simvalley mobile just for fun. They have some interesting devices.
  5245. // http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html
  5246. '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',
  5247. // Wolfgang - a brand that is sold by Aldi supermarkets.
  5248. // http://www.wolfgangmobile.com/
  5249. 'Wolfgang' => 'AT-B24D|AT-AS50HD|AT-AS40W|AT-AS55HD|AT-AS45q2|AT-B26D|AT-AS50Q',
  5250. 'Alcatel' => 'Alcatel',
  5251. 'Nintendo' => 'Nintendo 3DS',
  5252. // http://en.wikipedia.org/wiki/Amoi
  5253. 'Amoi' => 'Amoi',
  5254. // http://en.wikipedia.org/wiki/INQ
  5255. 'INQ' => 'INQ',
  5256. // @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039
  5257. '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',
  5258. );
  5259. /**
  5260. * List of tablet devices.
  5261. *
  5262. * @var array
  5263. */
  5264. protected static $tabletDevices = array(
  5265. // @todo: check for mobile friendly emails topic.
  5266. 'iPad' => 'iPad|iPad.*Mobile',
  5267. // Removed |^.*Android.*Nexus(?!(?:Mobile).)*$
  5268. // @see #442
  5269. 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)',
  5270. '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.
  5271. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
  5272. '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)',
  5273. // Only the Surface tablets with Windows RT are considered mobile.
  5274. // http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx
  5275. 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;.*(Tablet|ARMBJS)',
  5276. // http://shopping1.hp.com/is-bin/INTERSHOP.enfinity/WFS/WW-USSMBPublicStore-Site/en_US/-/USD/ViewStandardCatalog-Browse?CatalogCategoryID=JfIQ7EN5lqMAAAEyDcJUDwMT
  5277. 'HPTablet' => 'HP Slate (7|8|10)|HP ElitePad 900|hp-tablet|EliteBook.*Touch|HP 8|Slate 21|HP SlateBook 10',
  5278. // Watch out for PadFone, see #132.
  5279. // http://www.asus.com/de/Tablets_Mobile/Memo_Pad_Products/
  5280. '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',
  5281. 'BlackBerryTablet' => 'PlayBook|RIM Tablet',
  5282. 'HTCtablet' => 'HTC_Flyer_P512|HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200|PG09410',
  5283. 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617',
  5284. 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2',
  5285. // http://www.acer.ro/ac/ro/RO/content/drivers
  5286. // http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer)
  5287. // http://us.acer.com/ac/en/US/content/group/tablets
  5288. // http://www.acer.de/ac/de/DE/content/models/tablets/
  5289. // Can conflict with Micromax and Motorola phones codes.
  5290. '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',
  5291. // http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/
  5292. // http://us.toshiba.com/tablets/tablet-finder
  5293. // http://www.toshiba.co.jp/regza/tablet/
  5294. 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO',
  5295. // http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html
  5296. // http://www.lg.com/us/tablets
  5297. 'LGTablet' => '\bL-06C|LG-V909|LG-V900|LG-V700|LG-V510|LG-V500|LG-V410|LG-V400|LG-VK810\b',
  5298. 'FujitsuTablet' => 'Android.*\b(F-01D|F-02F|F-05E|F-10D|M532|Q572)\b',
  5299. // Prestigio Tablets http://www.prestigio.com/support
  5300. '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',
  5301. // http://support.lenovo.com/en_GB/downloads/default.page?#
  5302. '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|)',
  5303. // http://www.dell.com/support/home/us/en/04/Products/tab_mob/tablets
  5304. 'DellTablet' => 'Venue 11|Venue 8|Venue 7|Dell Streak 10|Dell Streak 7',
  5305. // http://www.yarvik.com/en/matrix/tablets/
  5306. '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',
  5307. 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB',
  5308. 'ArnovaTablet' => '97G4|AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT|AN9G2',
  5309. // http://www.intenso.de/kategorie_en.php?kategorie=33
  5310. // @todo: http://www.nbhkdz.com/read/b8e64202f92a2df129126bff.html - investigate
  5311. 'IntensoTablet' => 'INM8002KP|INM1010FP|INM805ND|Intenso Tab|TAB1004',
  5312. // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/
  5313. 'IRUTablet' => 'M702pro',
  5314. 'MegafonTablet' => 'MegaFon V9|\bZTE V9\b|Android.*\bMT7A\b',
  5315. // http://www.e-boda.ro/tablete-pc.html
  5316. 'EbodaTablet' => 'E-Boda (Supreme|Impresspeed|Izzycomm|Essential)',
  5317. // http://www.allview.ro/produse/droseries/lista-tablete-pc/
  5318. 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)',
  5319. // http://wiki.archosfans.com/index.php?title=Main_Page
  5320. // @note Rewrite the regex format after we add more UAs.
  5321. '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',
  5322. // http://www.ainol.com/plugin.php?identifier=ainol&module=product
  5323. 'AinolTablet' => 'NOVO7|NOVO8|NOVO10|Novo7Aurora|Novo7Basic|NOVO7PALADIN|novo9-Spark',
  5324. 'NokiaLumiaTablet' => 'Lumia 2520',
  5325. // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER
  5326. // Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser
  5327. // http://www.sony.jp/support/tablet/
  5328. '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',
  5329. // 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
  5330. 'PhilipsTablet' => '\b(PI2010|PI3000|PI3100|PI3105|PI3110|PI3205|PI3210|PI3900|PI4010|PI7000|PI7100)\b',
  5331. // db + http://www.cube-tablet.com/buy-products.html
  5332. 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT',
  5333. // http://www.cobyusa.com/?p=pcat&pcat_id=3001
  5334. 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010',
  5335. // http://www.match.net.cn/products.asp
  5336. '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',
  5337. // http://www.msi.com/support
  5338. // @todo Research the Windows Tablets.
  5339. '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',
  5340. // @todo http://www.kyoceramobile.com/support/drivers/
  5341. // 'KyoceraTablet' => null,
  5342. // @todo http://intexuae.com/index.php/category/mobile-devices/tablets-products/
  5343. // 'IntextTablet' => null,
  5344. // http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets)
  5345. // http://www.imp3.net/14/show.php?itemid=20454
  5346. 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)',
  5347. // http://www.rock-chips.com/index.php?do=prod&pid=2
  5348. 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A',
  5349. // http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/
  5350. 'FlyTablet' => 'IQ310|Fly Vision',
  5351. // http://www.bqreaders.com/gb/tablets-prices-sale.html
  5352. 'bqTablet' => 'Android.*(bq)?.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris [E|M]10)|Maxwell.*Lite|Maxwell.*Plus',
  5353. // http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
  5354. // http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
  5355. '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',
  5356. // Nec or Medias Tab
  5357. 'NecTablet' => '\bN-06D|\bN-08D',
  5358. // Pantech Tablets: http://www.pantechusa.com/phones/
  5359. 'PantechTablet' => 'Pantech.*P4100',
  5360. // Broncho Tablets: http://www.broncho.cn/ (hard to find)
  5361. 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)',
  5362. // http://versusuk.com/support.html
  5363. 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b',
  5364. // http://www.zync.in/index.php/our-products/tablet-phablets
  5365. 'ZyncTablet' => 'z1000|Z99 2G|z99|z930|z999|z990|z909|Z919|z900',
  5366. // http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/
  5367. 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA',
  5368. // https://www.nabitablet.com/
  5369. 'NabiTablet' => 'Android.*\bNabi',
  5370. 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build',
  5371. // French Danew Tablets http://www.danew.com/produits-tablette.php
  5372. 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b',
  5373. // Texet Tablets and Readers http://www.texet.ru/tablet/
  5374. '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',
  5375. // Avoid detecting 'PLAYSTATION 3' as mobile.
  5376. 'PlaystationTablet' => 'Playstation.*(Portable|Vita)',
  5377. // http://www.trekstor.de/surftabs.html
  5378. 'TrekstorTablet' => 'ST10416-1|VT10416-1|ST70408-1|ST702xx-1|ST702xx-2|ST80208|ST97216|ST70104-2|VT10416-2|ST10216-2A|SurfTab',
  5379. // http://www.pyleaudio.com/Products.aspx?%2fproducts%2fPersonal-Electronics%2fTablets
  5380. 'PyleAudioTablet' => '\b(PTBL10CEU|PTBL10C|PTBL72BC|PTBL72BCEU|PTBL7CEU|PTBL7C|PTBL92BC|PTBL92BCEU|PTBL9CEU|PTBL9CUK|PTBL9C)\b',
  5381. // http://www.advandigital.com/index.php?link=content-product&jns=JP001
  5382. // because of the short codenames we have to include whitespaces to reduce the possible conflicts.
  5383. '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 ',
  5384. // http://www.danytech.com/category/tablet-pc
  5385. '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',
  5386. // http://www.galapad.net/product.html
  5387. 'GalapadTablet' => 'Android.*\bG1\b',
  5388. // http://www.micromaxinfo.com/tablet/funbook
  5389. 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b',
  5390. // http://www.karbonnmobiles.com/products_tablet.php
  5391. 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b',
  5392. // http://www.myallfine.com/Products.asp
  5393. 'AllFineTablet' => 'Fine7 Genius|Fine7 Shine|Fine7 Air|Fine8 Style|Fine9 More|Fine10 Joy|Fine11 Wide',
  5394. // http://www.proscanvideo.com/products-search.asp?itemClass=TABLET&itemnmbr=
  5395. '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',
  5396. // http://www.yonesnav.com/products/products.php
  5397. 'YONESTablet' => 'BQ1078|BC1003|BC1077|RK9702|BC9730|BC9001|IT9001|BC7008|BC7010|BC708|BC728|BC7012|BC7030|BC7027|BC7026',
  5398. // http://www.cjshowroom.com/eproducts.aspx?classcode=004001001
  5399. // China manufacturer makes tablets for different small brands (eg. http://www.zeepad.net/index.html)
  5400. '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',
  5401. // http://www.gloryunion.cn/products.asp
  5402. // http://www.allwinnertech.com/en/apply/mobile.html
  5403. // http://www.ptcl.com.pk/pd_content.php?pd_id=284 (EVOTAB)
  5404. // @todo: Softwiner tablets?
  5405. // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions.
  5406. '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
  5407. // http://www.pointofview-online.com/showroom.php?shop_mode=product_listing&category_id=118
  5408. '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',
  5409. // http://www.overmax.pl/pl/katalog-produktow,p8/tablety,c14/
  5410. // @todo: add more tests.
  5411. 'OvermaxTablet' => 'OV-(SteelCore|NewBase|Basecore|Baseone|Exellen|Quattor|EduTab|Solution|ACTION|BasicTab|TeddyTab|MagicTab|Stream|TB-08|TB-09)',
  5412. // http://hclmetablet.com/India/index.php
  5413. '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',
  5414. // http://www.edigital.hu/Tablet_es_e-book_olvaso/Tablet-c18385.html
  5415. 'DPSTablet' => 'DPS Dream 9|DPS Dual 7',
  5416. // http://www.visture.com/index.asp
  5417. 'VistureTablet' => 'V97 HD|i75 3G|Visture V4( HD)?|Visture V5( HD)?|Visture V10',
  5418. // http://www.mijncresta.nl/tablet
  5419. 'CrestaTablet' => 'CTP(-)?810|CTP(-)?818|CTP(-)?828|CTP(-)?838|CTP(-)?888|CTP(-)?978|CTP(-)?980|CTP(-)?987|CTP(-)?988|CTP(-)?989',
  5420. // MediaTek - http://www.mediatek.com/_en/01_products/02_proSys.php?cata_sn=1&cata1_sn=1&cata2_sn=309
  5421. 'MediatekTablet' => '\bMT8125|MT8389|MT8135|MT8377\b',
  5422. // Concorde tab
  5423. 'ConcordeTablet' => 'Concorde([ ]+)?Tab|ConCorde ReadMan',
  5424. // GoClever Tablets - http://www.goclever.com/uk/products,c1/tablet,c5/
  5425. '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',
  5426. // Modecom Tablets - http://www.modecom.eu/tablets/portal/
  5427. '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',
  5428. // Vonino Tablets - http://www.vonino.eu/tablets
  5429. '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',
  5430. // ECS Tablets - http://www.ecs.com.tw/ECSWebSite/Product/Product_Tablet_List.aspx?CategoryID=14&MenuID=107&childid=M_107&LanID=0
  5431. 'ECSTablet' => 'V07OT2|TM105A|S10OT1|TR10CS1',
  5432. // Storex Tablets - http://storex.fr/espace_client/support.html
  5433. // @note: no need to add all the tablet codes since they are guided by the first regex.
  5434. 'StorexTablet' => 'eZee[_\']?(Tab|Go)[0-9]+|TabLC7|Looney Tunes Tab',
  5435. // Generic Vodafone tablets.
  5436. 'VodafoneTablet' => 'SmartTab([ ]+)?[0-9]+|SmartTabII10|SmartTabII7|VF-1497',
  5437. // French tablets - Essentiel B http://www.boulanger.fr/tablette_tactile_e-book/tablette_tactile_essentiel_b/cl_68908.htm?multiChoiceToDelete=brand&mc_brand=essentielb
  5438. // Aka: http://www.essentielb.fr/
  5439. 'EssentielBTablet' => 'Smart[ \']?TAB[ ]+?[0-9]+|Family[ \']?TAB2',
  5440. // Ross & Moor - http://ross-moor.ru/
  5441. 'RossMoorTablet' => 'RM-790|RM-997|RMD-878G|RMD-974R|RMT-705A|RMT-701|RME-601|RMT-501|RMT-711',
  5442. // i-mobile http://product.i-mobilephone.com/Mobile_Device
  5443. 'iMobileTablet' => 'i-mobile i-note',
  5444. // http://www.tolino.de/de/vergleichen/
  5445. 'TolinoTablet' => 'tolino tab [0-9.]+|tolino shine',
  5446. // AudioSonic - a Kmart brand
  5447. // 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
  5448. 'AudioSonicTablet' => '\bC-22Q|T7-QC|T-17B|T-17P\b',
  5449. // AMPE Tablets - http://www.ampe.com.my/product-category/tablets/
  5450. // @todo: add them gradually to avoid conflicts.
  5451. 'AMPETablet' => 'Android.* A78 ',
  5452. // Skk Mobile - http://skkmobile.com.ph/product_tablets.php
  5453. 'SkkTablet' => 'Android.* (SKYPAD|PHOENIX|CYCLOPS)',
  5454. // Tecno Mobile (only tablet) - http://www.tecno-mobile.com/index.php/product?filterby=smart&list_order=all&page=1
  5455. 'TecnoTablet' => 'TECNO P9',
  5456. // JXD (consoles & tablets) - http://jxd.hk/products.asp?selectclassid=009008&clsid=3
  5457. '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',
  5458. // i-Joy tablets - http://www.i-joy.es/en/cat/products/tablets/
  5459. '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)',
  5460. // http://www.intracon.eu/tablet
  5461. 'FX2Tablet' => 'FX2 PAD7|FX2 PAD10',
  5462. // http://www.xoro.de/produkte/
  5463. // @note: Might be the same brand with 'Simply tablets'
  5464. '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',
  5465. // http://www1.viewsonic.com/products/computing/tablets/
  5466. 'ViewsonicTablet' => 'ViewPad 10pi|ViewPad 10e|ViewPad 10s|ViewPad E72|ViewPad7|ViewPad E100|ViewPad 7e|ViewSonic VB733|VB100a',
  5467. // http://www.odys.de/web/internet-tablet_en.html
  5468. 'OdysTablet' => 'LOOX|XENO10|ODYS[ -](Space|EVO|Xpress|NOON)|\bXELIO\b|Xelio10Pro|XELIO7PHONETAB|XELIO10EXTREME|XELIOPT2|NEO_QUAD10',
  5469. // http://www.captiva-power.de/products.html#tablets-en
  5470. 'CaptivaTablet' => 'CAPTIVA PAD',
  5471. // IconBIT - http://www.iconbit.com/products/tablets/
  5472. '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',
  5473. // http://www.teclast.com/topic.php?channelID=70&topicID=140&pid=63
  5474. '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',
  5475. // Onda - http://www.onda-tablet.com/buy-android-onda.html?dir=desc&limit=all&order=price
  5476. '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]+',
  5477. 'JaytechTablet' => 'TPC-PA762',
  5478. 'BlaupunktTablet' => 'Endeavour 800NG|Endeavour 1010',
  5479. // http://www.digma.ru/support/download/
  5480. // @todo: Ebooks also (if requested)
  5481. 'DigmaTablet' => '\b(iDx10|iDx9|iDx8|iDx7|iDxD7|iDxD8|iDsQ8|iDsQ7|iDsQ8|iDsD10|iDnD7|3TS804H|iDsQ11|iDj7|iDs10)\b',
  5482. // http://www.evolioshop.com/ro/tablete-pc.html
  5483. // http://www.evolio.ro/support/downloads_static.html?cat=2
  5484. // @todo: Research some more
  5485. 'EvolioTablet' => 'ARIA_Mini_wifi|Aria[ _]Mini|Evolio X10|Evolio X7|Evolio X8|\bEvotab\b|\bNeura\b',
  5486. // @todo http://www.lavamobiles.com/tablets-data-cards
  5487. 'LavaTablet' => 'QPAD E704|\bIvoryS\b|E-TAB IVORY|\bE-TAB\b',
  5488. // http://www.breezetablet.com/
  5489. 'AocTablet' => 'MW0811|MW0812|MW0922|MTK8382|MW1031|MW0831|MW0821|MW0931|MW0712',
  5490. // http://www.mpmaneurope.com/en/products/internet-tablets-14/android-tablets-14/
  5491. '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',
  5492. // https://www.celkonmobiles.com/?_a=categoryphones&sid=2
  5493. 'CelkonTablet' => 'CT695|CT888|CT[\s]?910|CT7 Tab|CT9 Tab|CT3 Tab|CT2 Tab|CT1 Tab|C820|C720|\bCT-1\b',
  5494. // http://www.wolderelectronics.com/productos/manuales-y-guias-rapidas/categoria-2-miTab
  5495. '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',
  5496. // http://www.mi.com/en
  5497. 'MiTablet' => '\bMI PAD\b|\bHM NOTE 1W\b',
  5498. // http://www.nbru.cn/index.html
  5499. 'NibiruTablet' => 'Nibiru M1|Nibiru Jupiter One',
  5500. // http://navroad.com/products/produkty/tablety/
  5501. // http://navroad.com/products/produkty/tablety/
  5502. 'NexoTablet' => 'NEXO NOVA|NEXO 10|NEXO AVIO|NEXO FREE|NEXO GO|NEXO EVO|NEXO 3G|NEXO SMART|NEXO KIDDO|NEXO MOBI',
  5503. // http://leader-online.com/new_site/product-category/tablets/
  5504. // http://www.leader-online.net.au/List/Tablet
  5505. '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',
  5506. // http://www.datawind.com/ubislate/
  5507. 'UbislateTablet' => 'UbiSlate[\s]?7C',
  5508. // http://www.pocketbook-int.com/ru/support
  5509. 'PocketBookTablet' => 'Pocketbook',
  5510. // http://www.kocaso.com/product_tablet.html
  5511. 'KocasoTablet' => '\b(TB-1207)\b',
  5512. // http://global.hisense.com/product/asia/tablet/Sero7/201412/t20141215_91832.htm
  5513. 'HisenseTablet' => '\b(F5281|E2371)\b',
  5514. // http://www.tesco.com/direct/hudl/
  5515. 'Hudl' => 'Hudl HT7S3|Hudl 2',
  5516. // http://www.telstra.com.au/home-phone/thub-2/
  5517. 'TelstraTablet' => 'T-Hub2',
  5518. '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'
  5519. );
  5520. /**
  5521. * List of mobile Operating Systems.
  5522. *
  5523. * @var array
  5524. */
  5525. protected static $operatingSystems = array(
  5526. 'AndroidOS' => 'Android',
  5527. 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os',
  5528. 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
  5529. 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
  5530. // @reference: http://en.wikipedia.org/wiki/Windows_Mobile
  5531. 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;',
  5532. // @reference: http://en.wikipedia.org/wiki/Windows_Phone
  5533. // http://wifeng.cn/?r=blog&a=view&id=106
  5534. // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx
  5535. // http://msdn.microsoft.com/library/ms537503.aspx
  5536. // https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
  5537. 'WindowsPhoneOS' => 'Windows Phone 10.0|Windows Phone 8.1|Windows Phone 8.0|Windows Phone OS|XBLWP7|ZuneWP7|Windows NT 6.[23]; ARM;',
  5538. 'iOS' => '\biPhone.*Mobile|\biPod|\biPad',
  5539. // http://en.wikipedia.org/wiki/MeeGo
  5540. // @todo: research MeeGo in UAs
  5541. 'MeeGoOS' => 'MeeGo',
  5542. // http://en.wikipedia.org/wiki/Maemo
  5543. // @todo: research Maemo in UAs
  5544. 'MaemoOS' => 'Maemo',
  5545. 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135
  5546. 'webOS' => 'webOS|hpwOS',
  5547. 'badaOS' => '\bBada\b',
  5548. 'BREWOS' => 'BREW',
  5549. );
  5550. /**
  5551. * List of mobile User Agents.
  5552. *
  5553. * IMPORTANT: This is a list of only mobile browsers.
  5554. * Mobile Detect 2.x supports only mobile browsers,
  5555. * it was never designed to detect all browsers.
  5556. * The change will come in 2017 in the 3.x release for PHP7.
  5557. *
  5558. * @var array
  5559. */
  5560. protected static $browsers = array(
  5561. //'Vivaldi' => 'Vivaldi',
  5562. // @reference: https://developers.google.com/chrome/mobile/docs/user-agent
  5563. 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?',
  5564. 'Dolfin' => '\bDolfin\b',
  5565. 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+|Coast/[0-9.]+',
  5566. 'Skyfire' => 'Skyfire',
  5567. 'Edge' => 'Mobile Safari/[.0-9]* Edge',
  5568. 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+
  5569. 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS',
  5570. 'Bolt' => 'bolt',
  5571. 'TeaShark' => 'teashark',
  5572. 'Blazer' => 'Blazer',
  5573. // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3
  5574. 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari',
  5575. // http://en.wikipedia.org/wiki/Midori_(web_browser)
  5576. //'Midori' => 'midori',
  5577. //'Tizen' => 'Tizen',
  5578. 'UCBrowser' => 'UC.*Browser|UCWEB',
  5579. 'baiduboxapp' => 'baiduboxapp',
  5580. 'baidubrowser' => 'baidubrowser',
  5581. // https://github.com/serbanghita/Mobile-Detect/issues/7
  5582. 'DiigoBrowser' => 'DiigoBrowser',
  5583. // http://www.puffinbrowser.com/index.php
  5584. 'Puffin' => 'Puffin',
  5585. // http://mercury-browser.com/index.html
  5586. 'Mercury' => '\bMercury\b',
  5587. // http://en.wikipedia.org/wiki/Obigo_Browser
  5588. 'ObigoBrowser' => 'Obigo',
  5589. // http://en.wikipedia.org/wiki/NetFront
  5590. 'NetFront' => 'NF-Browser',
  5591. // @reference: http://en.wikipedia.org/wiki/Minimo
  5592. // http://en.wikipedia.org/wiki/Vision_Mobile_Browser
  5593. 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger',
  5594. // @reference: https://en.wikipedia.org/wiki/Pale_Moon_(web_browser)
  5595. 'PaleMoon' => 'Android.*PaleMoon|Mobile.*PaleMoon',
  5596. );
  5597. /**
  5598. * Utilities.
  5599. *
  5600. * @var array
  5601. */
  5602. protected static $utilities = array(
  5603. // Experimental. When a mobile device wants to switch to 'Desktop Mode'.
  5604. // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/
  5605. // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011
  5606. // https://developers.facebook.com/docs/sharing/best-practices
  5607. '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',
  5608. 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2',
  5609. 'DesktopMode' => 'WPDesktop',
  5610. 'TV' => 'SonyDTV|HbbTV', // experimental
  5611. 'WebKit' => '(webkit)[ /]([\w.]+)',
  5612. // @todo: Include JXD consoles.
  5613. 'Console' => '\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b',
  5614. 'Watch' => 'SM-V700',
  5615. );
  5616. /**
  5617. * All possible HTTP headers that represent the
  5618. * User-Agent string.
  5619. *
  5620. * @var array
  5621. */
  5622. protected static $uaHttpHeaders = array(
  5623. // The default User-Agent string.
  5624. 'HTTP_USER_AGENT',
  5625. // Header can occur on devices using Opera Mini.
  5626. 'HTTP_X_OPERAMINI_PHONE_UA',
  5627. // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
  5628. 'HTTP_X_DEVICE_USER_AGENT',
  5629. 'HTTP_X_ORIGINAL_USER_AGENT',
  5630. 'HTTP_X_SKYFIRE_PHONE',
  5631. 'HTTP_X_BOLT_PHONE_UA',
  5632. 'HTTP_DEVICE_STOCK_UA',
  5633. 'HTTP_X_UCBROWSER_DEVICE_UA'
  5634. );
  5635. /**
  5636. * The individual segments that could exist in a User-Agent string. VER refers to the regular
  5637. * expression defined in the constant self::VER.
  5638. *
  5639. * @var array
  5640. */
  5641. protected static $properties = array(
  5642. // Build
  5643. 'Mobile' => 'Mobile/[VER]',
  5644. 'Build' => 'Build/[VER]',
  5645. 'Version' => 'Version/[VER]',
  5646. 'VendorID' => 'VendorID/[VER]',
  5647. // Devices
  5648. 'iPad' => 'iPad.*CPU[a-z ]+[VER]',
  5649. 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]',
  5650. 'iPod' => 'iPod.*CPU[a-z ]+[VER]',
  5651. //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'),
  5652. 'Kindle' => 'Kindle/[VER]',
  5653. // Browser
  5654. 'Chrome' => array('Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'),
  5655. 'Coast' => array('Coast/[VER]'),
  5656. 'Dolfin' => 'Dolfin/[VER]',
  5657. // @reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
  5658. 'Firefox' => array('Firefox/[VER]', 'FxiOS/[VER]'),
  5659. 'Fennec' => 'Fennec/[VER]',
  5660. // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
  5661. // https://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
  5662. 'Edge' => 'Edge/[VER]',
  5663. 'IE' => array('IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'Trident/[0-9.]+;.*rv:[VER]'),
  5664. // http://en.wikipedia.org/wiki/NetFront
  5665. 'NetFront' => 'NetFront/[VER]',
  5666. 'NokiaBrowser' => 'NokiaBrowser/[VER]',
  5667. 'Opera' => array( ' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]' ),
  5668. 'Opera Mini' => 'Opera Mini/[VER]',
  5669. 'Opera Mobi' => 'Version/[VER]',
  5670. 'UC Browser' => 'UC Browser[VER]',
  5671. 'MQQBrowser' => 'MQQBrowser/[VER]',
  5672. 'MicroMessenger' => 'MicroMessenger/[VER]',
  5673. 'baiduboxapp' => 'baiduboxapp/[VER]',
  5674. 'baidubrowser' => 'baidubrowser/[VER]',
  5675. 'SamsungBrowser' => 'SamsungBrowser/[VER]',
  5676. 'Iron' => 'Iron/[VER]',
  5677. // @note: Safari 7534.48.3 is actually Version 5.1.
  5678. // @note: On BlackBerry the Version is overwriten by the OS.
  5679. 'Safari' => array( 'Version/[VER]', 'Safari/[VER]' ),
  5680. 'Skyfire' => 'Skyfire/[VER]',
  5681. 'Tizen' => 'Tizen/[VER]',
  5682. 'Webkit' => 'webkit[ /][VER]',
  5683. 'PaleMoon' => 'PaleMoon/[VER]',
  5684. // Engine
  5685. 'Gecko' => 'Gecko/[VER]',
  5686. 'Trident' => 'Trident/[VER]',
  5687. 'Presto' => 'Presto/[VER]',
  5688. 'Goanna' => 'Goanna/[VER]',
  5689. // OS
  5690. 'iOS' => ' \bi?OS\b [VER][ ;]{1}',
  5691. 'Android' => 'Android [VER]',
  5692. 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'),
  5693. 'BREW' => 'BREW [VER]',
  5694. 'Java' => 'Java/[VER]',
  5695. // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx
  5696. // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases
  5697. 'Windows Phone OS' => array( 'Windows Phone OS [VER]', 'Windows Phone [VER]'),
  5698. 'Windows Phone' => 'Windows Phone [VER]',
  5699. 'Windows CE' => 'Windows CE/[VER]',
  5700. // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd
  5701. 'Windows NT' => 'Windows NT [VER]',
  5702. 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'),
  5703. 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'),
  5704. );
  5705. /**
  5706. * Construct an instance of this class.
  5707. *
  5708. * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored.
  5709. * If left empty, will use the global _SERVER['HTTP_*'] vars instead.
  5710. * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
  5711. * from the $headers array instead.
  5712. */
  5713. public function __construct(
  5714. array $headers = null,
  5715. $userAgent = null
  5716. ) {
  5717. $this->setHttpHeaders($headers);
  5718. $this->setUserAgent($userAgent);
  5719. }
  5720. /**
  5721. * Get the current script version.
  5722. * This is useful for the demo.php file,
  5723. * so people can check on what version they are testing
  5724. * for mobile devices.
  5725. *
  5726. * @return string The version number in semantic version format.
  5727. */
  5728. public static function getScriptVersion()
  5729. {
  5730. return self::VERSION;
  5731. }
  5732. /**
  5733. * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
  5734. *
  5735. * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
  5736. * the headers. The default null is left for backwards compatibility.
  5737. */
  5738. public function setHttpHeaders($httpHeaders = null)
  5739. {
  5740. // use global _SERVER if $httpHeaders aren't defined
  5741. if (!is_array($httpHeaders) || !count($httpHeaders)) {
  5742. $httpHeaders = $_SERVER;
  5743. }
  5744. // clear existing headers
  5745. $this->httpHeaders = array();
  5746. // Only save HTTP headers. In PHP land, that means only _SERVER vars that
  5747. // start with HTTP_.
  5748. foreach ($httpHeaders as $key => $value) {
  5749. if (substr($key, 0, 5) === 'HTTP_') {
  5750. $this->httpHeaders[$key] = $value;
  5751. }
  5752. }
  5753. // In case we're dealing with CloudFront, we need to know.
  5754. $this->setCfHeaders($httpHeaders);
  5755. }
  5756. /**
  5757. * Retrieves the HTTP headers.
  5758. *
  5759. * @return array
  5760. */
  5761. public function getHttpHeaders()
  5762. {
  5763. return $this->httpHeaders;
  5764. }
  5765. /**
  5766. * Retrieves a particular header. If it doesn't exist, no exception/error is caused.
  5767. * Simply null is returned.
  5768. *
  5769. * @param string $header The name of the header to retrieve. Can be HTTP compliant such as
  5770. * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the
  5771. * all-caps, HTTP_ prefixed, underscore seperated awesomeness.
  5772. *
  5773. * @return string|null The value of the header.
  5774. */
  5775. public function getHttpHeader($header)
  5776. {
  5777. // are we using PHP-flavored headers?
  5778. if (strpos($header, '_') === false) {
  5779. $header = str_replace('-', '_', $header);
  5780. $header = strtoupper($header);
  5781. }
  5782. // test the alternate, too
  5783. $altHeader = 'HTTP_' . $header;
  5784. //Test both the regular and the HTTP_ prefix
  5785. if (isset($this->httpHeaders[$header])) {
  5786. return $this->httpHeaders[$header];
  5787. } elseif (isset($this->httpHeaders[$altHeader])) {
  5788. return $this->httpHeaders[$altHeader];
  5789. }
  5790. return null;
  5791. }
  5792. public function getMobileHeaders()
  5793. {
  5794. return self::$mobileHeaders;
  5795. }
  5796. /**
  5797. * Get all possible HTTP headers that
  5798. * can contain the User-Agent string.
  5799. *
  5800. * @return array List of HTTP headers.
  5801. */
  5802. public function getUaHttpHeaders()
  5803. {
  5804. return self::$uaHttpHeaders;
  5805. }
  5806. /**
  5807. * Set CloudFront headers
  5808. * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device
  5809. *
  5810. * @param array $cfHeaders List of HTTP headers
  5811. *
  5812. * @return boolean If there were CloudFront headers to be set
  5813. */
  5814. public function setCfHeaders($cfHeaders = null) {
  5815. // use global _SERVER if $cfHeaders aren't defined
  5816. if (!is_array($cfHeaders) || !count($cfHeaders)) {
  5817. $cfHeaders = $_SERVER;
  5818. }
  5819. // clear existing headers
  5820. $this->cloudfrontHeaders = array();
  5821. // Only save CLOUDFRONT headers. In PHP land, that means only _SERVER vars that
  5822. // start with cloudfront-.
  5823. $response = false;
  5824. foreach ($cfHeaders as $key => $value) {
  5825. if (substr(strtolower($key), 0, 16) === 'http_cloudfront_') {
  5826. $this->cloudfrontHeaders[strtoupper($key)] = $value;
  5827. $response = true;
  5828. }
  5829. }
  5830. return $response;
  5831. }
  5832. /**
  5833. * Retrieves the cloudfront headers.
  5834. *
  5835. * @return array
  5836. */
  5837. public function getCfHeaders()
  5838. {
  5839. return $this->cloudfrontHeaders;
  5840. }
  5841. /**
  5842. * Set the User-Agent to be used.
  5843. *
  5844. * @param string $userAgent The user agent string to set.
  5845. *
  5846. * @return string|null
  5847. */
  5848. public function setUserAgent($userAgent = null)
  5849. {
  5850. // Invalidate cache due to #375
  5851. $this->cache = array();
  5852. if (false === empty($userAgent)) {
  5853. return $this->userAgent = $userAgent;
  5854. } else {
  5855. $this->userAgent = null;
  5856. foreach ($this->getUaHttpHeaders() as $altHeader) {
  5857. if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban)
  5858. $this->userAgent .= $this->httpHeaders[$altHeader] . " ";
  5859. }
  5860. }
  5861. if (!empty($this->userAgent)) {
  5862. return $this->userAgent = trim($this->userAgent);
  5863. }
  5864. }
  5865. if (count($this->getCfHeaders()) > 0) {
  5866. return $this->userAgent = 'Amazon CloudFront';
  5867. }
  5868. return $this->userAgent = null;
  5869. }
  5870. /**
  5871. * Retrieve the User-Agent.
  5872. *
  5873. * @return string|null The user agent if it's set.
  5874. */
  5875. public function getUserAgent()
  5876. {
  5877. return $this->userAgent;
  5878. }
  5879. /**
  5880. * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or
  5881. * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set.
  5882. *
  5883. * @deprecated since version 2.6.9
  5884. *
  5885. * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
  5886. * parameter is null which will default to self::DETECTION_TYPE_MOBILE.
  5887. */
  5888. public function setDetectionType($type = null)
  5889. {
  5890. if ($type === null) {
  5891. $type = self::DETECTION_TYPE_MOBILE;
  5892. }
  5893. if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) {
  5894. return;
  5895. }
  5896. $this->detectionType = $type;
  5897. }
  5898. public function getMatchingRegex()
  5899. {
  5900. return $this->matchingRegex;
  5901. }
  5902. public function getMatchesArray()
  5903. {
  5904. return $this->matchesArray;
  5905. }
  5906. /**
  5907. * Retrieve the list of known phone devices.
  5908. *
  5909. * @return array List of phone devices.
  5910. */
  5911. public static function getPhoneDevices()
  5912. {
  5913. return self::$phoneDevices;
  5914. }
  5915. /**
  5916. * Retrieve the list of known tablet devices.
  5917. *
  5918. * @return array List of tablet devices.
  5919. */
  5920. public static function getTabletDevices()
  5921. {
  5922. return self::$tabletDevices;
  5923. }
  5924. /**
  5925. * Alias for getBrowsers() method.
  5926. *
  5927. * @return array List of user agents.
  5928. */
  5929. public static function getUserAgents()
  5930. {
  5931. return self::getBrowsers();
  5932. }
  5933. /**
  5934. * Retrieve the list of known browsers. Specifically, the user agents.
  5935. *
  5936. * @return array List of browsers / user agents.
  5937. */
  5938. public static function getBrowsers()
  5939. {
  5940. return self::$browsers;
  5941. }
  5942. /**
  5943. * Retrieve the list of known utilities.
  5944. *
  5945. * @return array List of utilities.
  5946. */
  5947. public static function getUtilities()
  5948. {
  5949. return self::$utilities;
  5950. }
  5951. /**
  5952. * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*().
  5953. *
  5954. * @deprecated since version 2.6.9
  5955. *
  5956. * @return array All the rules (but not extended).
  5957. */
  5958. public static function getMobileDetectionRules()
  5959. {
  5960. static $rules;
  5961. if (!$rules) {
  5962. $rules = array_merge(
  5963. self::$phoneDevices,
  5964. self::$tabletDevices,
  5965. self::$operatingSystems,
  5966. self::$browsers
  5967. );
  5968. }
  5969. return $rules;
  5970. }
  5971. /**
  5972. * Method gets the mobile detection rules + utilities.
  5973. * The reason this is separate is because utilities rules
  5974. * don't necessary imply mobile. This method is used inside
  5975. * the new $detect->is('stuff') method.
  5976. *
  5977. * @deprecated since version 2.6.9
  5978. *
  5979. * @return array All the rules + extended.
  5980. */
  5981. public function getMobileDetectionRulesExtended()
  5982. {
  5983. static $rules;
  5984. if (!$rules) {
  5985. // Merge all rules together.
  5986. $rules = array_merge(
  5987. self::$phoneDevices,
  5988. self::$tabletDevices,
  5989. self::$operatingSystems,
  5990. self::$browsers,
  5991. self::$utilities
  5992. );
  5993. }
  5994. return $rules;
  5995. }
  5996. /**
  5997. * Retrieve the current set of rules.
  5998. *
  5999. * @deprecated since version 2.6.9
  6000. *
  6001. * @return array
  6002. */
  6003. public function getRules()
  6004. {
  6005. if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) {
  6006. return self::getMobileDetectionRulesExtended();
  6007. } else {
  6008. return self::getMobileDetectionRules();
  6009. }
  6010. }
  6011. /**
  6012. * Retrieve the list of mobile operating systems.
  6013. *
  6014. * @return array The list of mobile operating systems.
  6015. */
  6016. public static function getOperatingSystems()
  6017. {
  6018. return self::$operatingSystems;
  6019. }
  6020. /**
  6021. * Check the HTTP headers for signs of mobile.
  6022. * This is the fastest mobile check possible; it's used
  6023. * inside isMobile() method.
  6024. *
  6025. * @return bool
  6026. */
  6027. public function checkHttpHeadersForMobile()
  6028. {
  6029. foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) {
  6030. if (isset($this->httpHeaders[$mobileHeader])) {
  6031. if (is_array($matchType['matches'])) {
  6032. foreach ($matchType['matches'] as $_match) {
  6033. if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) {
  6034. return true;
  6035. }
  6036. }
  6037. return false;
  6038. } else {
  6039. return true;
  6040. }
  6041. }
  6042. }
  6043. return false;
  6044. }
  6045. /**
  6046. * Magic overloading method.
  6047. *
  6048. * @method boolean is[...]()
  6049. * @param string $name
  6050. * @param array $arguments
  6051. * @return mixed
  6052. * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
  6053. */
  6054. public function __call($name, $arguments)
  6055. {
  6056. // make sure the name starts with 'is', otherwise
  6057. if (substr($name, 0, 2) !== 'is') {
  6058. throw new BadMethodCallException("No such method exists: $name");
  6059. }
  6060. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6061. $key = substr($name, 2);
  6062. return $this->matchUAAgainstKey($key);
  6063. }
  6064. /**
  6065. * Find a detection rule that matches the current User-agent.
  6066. *
  6067. * @param null $userAgent deprecated
  6068. * @return boolean
  6069. */
  6070. protected function matchDetectionRulesAgainstUA($userAgent = null)
  6071. {
  6072. // Begin general search.
  6073. foreach ($this->getRules() as $_regex) {
  6074. if (empty($_regex)) {
  6075. continue;
  6076. }
  6077. if ($this->match($_regex, $userAgent)) {
  6078. return true;
  6079. }
  6080. }
  6081. return false;
  6082. }
  6083. /**
  6084. * Search for a certain key in the rules array.
  6085. * If the key is found then try to match the corresponding
  6086. * regex against the User-Agent.
  6087. *
  6088. * @param string $key
  6089. *
  6090. * @return boolean
  6091. */
  6092. protected function matchUAAgainstKey($key)
  6093. {
  6094. // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
  6095. $key = strtolower($key);
  6096. if (false === isset($this->cache[$key])) {
  6097. // change the keys to lower case
  6098. $_rules = array_change_key_case($this->getRules());
  6099. if (false === empty($_rules[$key])) {
  6100. $this->cache[$key] = $this->match($_rules[$key]);
  6101. }
  6102. if (false === isset($this->cache[$key])) {
  6103. $this->cache[$key] = false;
  6104. }
  6105. }
  6106. return $this->cache[$key];
  6107. }
  6108. /**
  6109. * Check if the device is mobile.
  6110. * Returns true if any type of mobile device detected, including special ones
  6111. * @param null $userAgent deprecated
  6112. * @param null $httpHeaders deprecated
  6113. * @return bool
  6114. */
  6115. public function isMobile($userAgent = null, $httpHeaders = null)
  6116. {
  6117. if ($httpHeaders) {
  6118. $this->setHttpHeaders($httpHeaders);
  6119. }
  6120. if ($userAgent) {
  6121. $this->setUserAgent($userAgent);
  6122. }
  6123. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6124. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6125. $cfHeaders = $this->getCfHeaders();
  6126. if(array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') {
  6127. return true;
  6128. }
  6129. }
  6130. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6131. if ($this->checkHttpHeadersForMobile()) {
  6132. return true;
  6133. } else {
  6134. return $this->matchDetectionRulesAgainstUA();
  6135. }
  6136. }
  6137. /**
  6138. * Check if the device is a tablet.
  6139. * Return true if any type of tablet device is detected.
  6140. *
  6141. * @param string $userAgent deprecated
  6142. * @param array $httpHeaders deprecated
  6143. * @return bool
  6144. */
  6145. public function isTablet($userAgent = null, $httpHeaders = null)
  6146. {
  6147. // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
  6148. if ($this->getUserAgent() === 'Amazon CloudFront') {
  6149. $cfHeaders = $this->getCfHeaders();
  6150. if(array_key_exists('HTTP_CLOUDFRONT_IS_TABLET_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] === 'true') {
  6151. return true;
  6152. }
  6153. }
  6154. $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
  6155. foreach (self::$tabletDevices as $_regex) {
  6156. if ($this->match($_regex, $userAgent)) {
  6157. return true;
  6158. }
  6159. }
  6160. return false;
  6161. }
  6162. /**
  6163. * This method checks for a certain property in the
  6164. * userAgent.
  6165. * @todo: The httpHeaders part is not yet used.
  6166. *
  6167. * @param string $key
  6168. * @param string $userAgent deprecated
  6169. * @param string $httpHeaders deprecated
  6170. * @return bool|int|null
  6171. */
  6172. public function is($key, $userAgent = null, $httpHeaders = null)
  6173. {
  6174. // Set the UA and HTTP headers only if needed (eg. batch mode).
  6175. if ($httpHeaders) {
  6176. $this->setHttpHeaders($httpHeaders);
  6177. }
  6178. if ($userAgent) {
  6179. $this->setUserAgent($userAgent);
  6180. }
  6181. $this->setDetectionType(self::DETECTION_TYPE_EXTENDED);
  6182. return $this->matchUAAgainstKey($key);
  6183. }
  6184. /**
  6185. * Some detection rules are relative (not standard),
  6186. * because of the diversity of devices, vendors and
  6187. * their conventions in representing the User-Agent or
  6188. * the HTTP headers.
  6189. *
  6190. * This method will be used to check custom regexes against
  6191. * the User-Agent string.
  6192. *
  6193. * @param $regex
  6194. * @param string $userAgent
  6195. * @return bool
  6196. *
  6197. * @todo: search in the HTTP headers too.
  6198. */
  6199. public function match($regex, $userAgent = null)
  6200. {
  6201. $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches);
  6202. // If positive match is found, store the results for debug.
  6203. if ($match) {
  6204. $this->matchingRegex = $regex;
  6205. $this->matchesArray = $matches;
  6206. }
  6207. return $match;
  6208. }
  6209. /**
  6210. * Get the properties array.
  6211. *
  6212. * @return array
  6213. */
  6214. public static function getProperties()
  6215. {
  6216. return self::$properties;
  6217. }
  6218. /**
  6219. * Prepare the version number.
  6220. *
  6221. * @todo Remove the error supression from str_replace() call.
  6222. *
  6223. * @param string $ver The string version, like "2.6.21.2152";
  6224. *
  6225. * @return float
  6226. */
  6227. public function prepareVersionNo($ver)
  6228. {
  6229. $ver = str_replace(array('_', ' ', '/'), '.', $ver);
  6230. $arrVer = explode('.', $ver, 2);
  6231. if (isset($arrVer[1])) {
  6232. $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions.
  6233. }
  6234. return (float) implode('.', $arrVer);
  6235. }
  6236. /**
  6237. * Check the version of the given property in the User-Agent.
  6238. * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
  6239. *
  6240. * @param string $propertyName The name of the property. See self::getProperties() array
  6241. * keys for all possible properties.
  6242. * @param string $type Either self::VERSION_TYPE_STRING to get a string value or
  6243. * self::VERSION_TYPE_FLOAT indicating a float value. This parameter
  6244. * is optional and defaults to self::VERSION_TYPE_STRING. Passing an
  6245. * invalid parameter will default to the this type as well.
  6246. *
  6247. * @return string|float The version of the property we are trying to extract.
  6248. */
  6249. public function version($propertyName, $type = self::VERSION_TYPE_STRING)
  6250. {
  6251. if (empty($propertyName)) {
  6252. return false;
  6253. }
  6254. // set the $type to the default if we don't recognize the type
  6255. if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
  6256. $type = self::VERSION_TYPE_STRING;
  6257. }
  6258. $properties = self::getProperties();
  6259. // Check if the property exists in the properties array.
  6260. if (true === isset($properties[$propertyName])) {
  6261. // Prepare the pattern to be matched.
  6262. // Make sure we always deal with an array (string is converted).
  6263. $properties[$propertyName] = (array) $properties[$propertyName];
  6264. foreach ($properties[$propertyName] as $propertyMatchString) {
  6265. $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
  6266. // Identify and extract the version.
  6267. preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);
  6268. if (false === empty($match[1])) {
  6269. $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);
  6270. return $version;
  6271. }
  6272. }
  6273. }
  6274. return false;
  6275. }
  6276. /**
  6277. * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
  6278. *
  6279. * @return string One of the self::MOBILE_GRADE_* constants.
  6280. */
  6281. public function mobileGrade()
  6282. {
  6283. $isMobile = $this->isMobile();
  6284. if (
  6285. // 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)
  6286. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6287. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6288. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 ||
  6289. // 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)
  6290. // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
  6291. // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
  6292. // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
  6293. ( $this->version('Android', self::VERSION_TYPE_FLOAT)>2.1 && $this->is('Webkit') ) ||
  6294. // 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)
  6295. $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 ||
  6296. // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry® Torch 9810 (7), BlackBerry Z10 (10)
  6297. $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 ||
  6298. // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
  6299. $this->match('Playbook.*Tablet') ||
  6300. // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0)
  6301. ( $this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi') ) ||
  6302. // Palm WebOS 3.0 - Tested on HP TouchPad
  6303. $this->match('hp.*TouchPad') ||
  6304. // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices
  6305. ( $this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18 ) ||
  6306. // Chrome for Android - Tested on Android 4.0, 4.1 device
  6307. ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0 ) ||
  6308. // Skyfire 4.1 - Tested on Android 2.3 device
  6309. ( $this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6310. // Opera Mobile 11.5-12: Tested on Android 2.3
  6311. ( $this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS') ) ||
  6312. // Meego 1.2 - Tested on Nokia 950 and N9
  6313. $this->is('MeeGoOS') ||
  6314. // Tizen (pre-release) - Tested on early hardware
  6315. $this->is('Tizen') ||
  6316. // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
  6317. // @todo: more tests here!
  6318. $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 ||
  6319. // UC Browser - Tested on Android 2.3 device
  6320. ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 ) ||
  6321. // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
  6322. ( $this->match('Kindle Fire') ||
  6323. $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0 ) ||
  6324. // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
  6325. $this->is('AndroidOS') && $this->is('NookTablet') ||
  6326. // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7
  6327. $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && !$isMobile ||
  6328. // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7
  6329. $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && !$isMobile ||
  6330. // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7
  6331. $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && !$isMobile ||
  6332. // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
  6333. $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && !$isMobile ||
  6334. // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
  6335. $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && !$isMobile
  6336. ){
  6337. return self::MOBILE_GRADE_A;
  6338. }
  6339. if (
  6340. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT)<4.3 ||
  6341. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT)<4.3 ||
  6342. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT)<4.3 ||
  6343. // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
  6344. $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT)<6 ||
  6345. //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
  6346. ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 &&
  6347. ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS')) ) ||
  6348. // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
  6349. $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
  6350. // @todo: report this (tested on Nokia N71)
  6351. $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS')
  6352. ){
  6353. return self::MOBILE_GRADE_B;
  6354. }
  6355. if (
  6356. // Blackberry 4.x - Tested on the Curve 8330
  6357. $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 ||
  6358. // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
  6359. $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 ||
  6360. // Tested on original iPhone (3.1), iPhone 3 (3.2)
  6361. $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6362. $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6363. $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 ||
  6364. // Internet Explorer 7 and older - Tested on Windows XP
  6365. $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && !$isMobile
  6366. ){
  6367. return self::MOBILE_GRADE_C;
  6368. }
  6369. // All older smartphone platforms and featurephones - Any device that doesn't support media queries
  6370. // will receive the basic, C grade experience.
  6371. return self::MOBILE_GRADE_C;
  6372. }
  6373. }
  6374. $mobileDetect = new Mobile_Detect;
  6375. $userDevice = ($mobileDetect->isMobile() ? ($mobileDetect->isTablet() ? 'tablet' : 'phone') : 'computer');
  6376. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  6377. $path = getServerPath();
  6378. return '
  6379. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6380. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  6381. <head>
  6382. <!--[if gte mso 9]><xml>
  6383. <o:OfficeDocumentSettings>
  6384. <o:AllowPNG/>
  6385. <o:PixelsPerInch>96</o:PixelsPerInch>
  6386. </o:OfficeDocumentSettings>
  6387. </xml><![endif]-->
  6388. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6389. <meta name="viewport" content="width=device-width">
  6390. <!--[if !mso]><!-->
  6391. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6392. <!--<![endif]-->
  6393. <title></title>
  6394. <!--[if !mso]><!-- -->
  6395. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  6396. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  6397. <!--<![endif]-->
  6398. <style type="text/css" id="media-query">
  6399. body {
  6400. margin: 0;
  6401. padding: 0;
  6402. }
  6403. table,
  6404. tr,
  6405. td {
  6406. vertical-align: top;
  6407. border-collapse: collapse;
  6408. }
  6409. .ie-browser table,
  6410. .mso-container table {
  6411. table-layout: fixed;
  6412. }
  6413. * {
  6414. line-height: inherit;
  6415. }
  6416. a[x-apple-data-detectors=true] {
  6417. color: inherit !important;
  6418. text-decoration: none !important;
  6419. }
  6420. [owa] .img-container div,
  6421. [owa] .img-container button {
  6422. display: block !important;
  6423. }
  6424. [owa] .fullwidth button {
  6425. width: 100% !important;
  6426. }
  6427. [owa] .block-grid .col {
  6428. display: table-cell;
  6429. float: none !important;
  6430. vertical-align: top;
  6431. }
  6432. .ie-browser .num12,
  6433. .ie-browser .block-grid,
  6434. [owa] .num12,
  6435. [owa] .block-grid {
  6436. width: 615px !important;
  6437. }
  6438. .ExternalClass,
  6439. .ExternalClass p,
  6440. .ExternalClass span,
  6441. .ExternalClass font,
  6442. .ExternalClass td,
  6443. .ExternalClass div {
  6444. line-height: 100%;
  6445. }
  6446. .ie-browser .mixed-two-up .num4,
  6447. [owa] .mixed-two-up .num4 {
  6448. width: 204px !important;
  6449. }
  6450. .ie-browser .mixed-two-up .num8,
  6451. [owa] .mixed-two-up .num8 {
  6452. width: 408px !important;
  6453. }
  6454. .ie-browser .block-grid.two-up .col,
  6455. [owa] .block-grid.two-up .col {
  6456. width: 307px !important;
  6457. }
  6458. .ie-browser .block-grid.three-up .col,
  6459. [owa] .block-grid.three-up .col {
  6460. width: 205px !important;
  6461. }
  6462. .ie-browser .block-grid.four-up .col,
  6463. [owa] .block-grid.four-up .col {
  6464. width: 153px !important;
  6465. }
  6466. .ie-browser .block-grid.five-up .col,
  6467. [owa] .block-grid.five-up .col {
  6468. width: 123px !important;
  6469. }
  6470. .ie-browser .block-grid.six-up .col,
  6471. [owa] .block-grid.six-up .col {
  6472. width: 102px !important;
  6473. }
  6474. .ie-browser .block-grid.seven-up .col,
  6475. [owa] .block-grid.seven-up .col {
  6476. width: 87px !important;
  6477. }
  6478. .ie-browser .block-grid.eight-up .col,
  6479. [owa] .block-grid.eight-up .col {
  6480. width: 76px !important;
  6481. }
  6482. .ie-browser .block-grid.nine-up .col,
  6483. [owa] .block-grid.nine-up .col {
  6484. width: 68px !important;
  6485. }
  6486. .ie-browser .block-grid.ten-up .col,
  6487. [owa] .block-grid.ten-up .col {
  6488. width: 61px !important;
  6489. }
  6490. .ie-browser .block-grid.eleven-up .col,
  6491. [owa] .block-grid.eleven-up .col {
  6492. width: 55px !important;
  6493. }
  6494. .ie-browser .block-grid.twelve-up .col,
  6495. [owa] .block-grid.twelve-up .col {
  6496. width: 51px !important;
  6497. }
  6498. @media only screen and (min-width: 635px) {
  6499. .block-grid {
  6500. width: 615px !important;
  6501. }
  6502. .block-grid .col {
  6503. display: table-cell;
  6504. Float: none !important;
  6505. vertical-align: top;
  6506. }
  6507. .block-grid .col.num12 {
  6508. width: 615px !important;
  6509. }
  6510. .block-grid.mixed-two-up .col.num4 {
  6511. width: 204px !important;
  6512. }
  6513. .block-grid.mixed-two-up .col.num8 {
  6514. width: 408px !important;
  6515. }
  6516. .block-grid.two-up .col {
  6517. width: 307px !important;
  6518. }
  6519. .block-grid.three-up .col {
  6520. width: 205px !important;
  6521. }
  6522. .block-grid.four-up .col {
  6523. width: 153px !important;
  6524. }
  6525. .block-grid.five-up .col {
  6526. width: 123px !important;
  6527. }
  6528. .block-grid.six-up .col {
  6529. width: 102px !important;
  6530. }
  6531. .block-grid.seven-up .col {
  6532. width: 87px !important;
  6533. }
  6534. .block-grid.eight-up .col {
  6535. width: 76px !important;
  6536. }
  6537. .block-grid.nine-up .col {
  6538. width: 68px !important;
  6539. }
  6540. .block-grid.ten-up .col {
  6541. width: 61px !important;
  6542. }
  6543. .block-grid.eleven-up .col {
  6544. width: 55px !important;
  6545. }
  6546. .block-grid.twelve-up .col {
  6547. width: 51px !important;
  6548. }
  6549. }
  6550. @media (max-width: 635px) {
  6551. .block-grid,
  6552. .col {
  6553. min-width: 320px !important;
  6554. max-width: 100% !important;
  6555. }
  6556. .block-grid {
  6557. width: calc(100% - 40px) !important;
  6558. }
  6559. .col {
  6560. width: 100% !important;
  6561. }
  6562. .col>div {
  6563. margin: 0 auto;
  6564. }
  6565. img.fullwidth {
  6566. max-width: 100% !important;
  6567. }
  6568. }
  6569. </style>
  6570. </head>
  6571. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  6572. <!--[if IE]><div class="ie-browser"><![endif]-->
  6573. <!--[if mso]><div class="mso-container"><![endif]-->
  6574. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  6575. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  6576. <div style="background-color:#333333;">
  6577. <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;"
  6578. class="block-grid ">
  6579. <div style="border-collapse: collapse;display: table;width: 100%;">
  6580. <!--[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]-->
  6581. <!--[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]-->
  6582. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6583. <div style="background-color: transparent; width: 100% !important;">
  6584. <!--[if (!mso)&(!IE)]><!-->
  6585. <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;">
  6586. <!--<![endif]-->
  6587. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  6588. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  6589. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  6590. 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"
  6591. width="555">
  6592. <!--[if mso]></td></tr></table><![endif]-->
  6593. </div>
  6594. <!--[if (!mso)&(!IE)]><!-->
  6595. </div>
  6596. <!--<![endif]-->
  6597. </div>
  6598. </div>
  6599. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6600. </div>
  6601. </div>
  6602. </div>
  6603. <div style="background-color:#333333;">
  6604. <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;"
  6605. class="block-grid ">
  6606. <div style="border-collapse: collapse;display: table;width: 100%;">
  6607. <!--[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]-->
  6608. <!--[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]-->
  6609. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6610. <div style="background-color: transparent; width: 100% !important;">
  6611. <!--[if (!mso)&(!IE)]><!-->
  6612. <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;">
  6613. <!--<![endif]-->
  6614. <!--[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]-->
  6615. <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;">
  6616. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6617. <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>
  6618. </span>
  6619. </p>
  6620. </div>
  6621. </div>
  6622. <!--[if mso]></td></tr></table><![endif]-->
  6623. <!--[if (!mso)&(!IE)]><!-->
  6624. </div>
  6625. <!--<![endif]-->
  6626. </div>
  6627. </div>
  6628. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6629. </div>
  6630. </div>
  6631. </div>
  6632. <div style="background-color:#393939;">
  6633. <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;"
  6634. class="block-grid ">
  6635. <div style="border-collapse: collapse;display: table;width: 100%;">
  6636. <!--[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]-->
  6637. <!--[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]-->
  6638. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6639. <div style="background-color: transparent; width: 100% !important;">
  6640. <!--[if (!mso)&(!IE)]><!-->
  6641. <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;">
  6642. <!--<![endif]-->
  6643. <!--[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]-->
  6644. <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;">
  6645. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6646. <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>
  6647. </div>
  6648. </div>
  6649. <!--[if mso]></td></tr></table><![endif]-->
  6650. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  6651. <!--[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]-->
  6652. <div align="center">
  6653. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  6654. </div>
  6655. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6656. </div>
  6657. <!--[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]-->
  6658. <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;">
  6659. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  6660. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  6661. </div>
  6662. </div>
  6663. <!--[if mso]></td></tr></table><![endif]-->
  6664. <!--[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]-->
  6665. <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;">
  6666. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  6667. <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>
  6668. </span>
  6669. </p>
  6670. </div>
  6671. </div>
  6672. <!--[if mso]></td></tr></table><![endif]-->
  6673. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  6674. <!--[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]-->
  6675. <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">
  6676. <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>
  6677. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6678. </div>
  6679. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  6680. </div>
  6681. <!--[if (!mso)&(!IE)]><!-->
  6682. </div>
  6683. <!--<![endif]-->
  6684. </div>
  6685. </div>
  6686. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6687. </div>
  6688. </div>
  6689. </div>
  6690. <div style="background-color:#ffffff;">
  6691. <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;"
  6692. class="block-grid ">
  6693. <div style="border-collapse: collapse;display: table;width: 100%;">
  6694. <!--[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]-->
  6695. <!--[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]-->
  6696. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6697. <div style="background-color: transparent; width: 100% !important;">
  6698. <!--[if (!mso)&(!IE)]><!-->
  6699. <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;">
  6700. <!--<![endif]-->
  6701. <!--[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]-->
  6702. <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;">
  6703. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6704. <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>
  6705. </div>
  6706. </div>
  6707. <!--[if mso]></td></tr></table><![endif]-->
  6708. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  6709. <!--[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]-->
  6710. <div align="center">
  6711. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  6712. </div>
  6713. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  6714. </div>
  6715. <!--[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]-->
  6716. <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;">
  6717. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6718. <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>
  6719. </div>
  6720. </div>
  6721. <!--[if mso]></td></tr></table><![endif]-->
  6722. <!--[if (!mso)&(!IE)]><!-->
  6723. </div>
  6724. <!--<![endif]-->
  6725. </div>
  6726. </div>
  6727. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6728. </div>
  6729. </div>
  6730. </div>
  6731. <div style="background-color:#333333;">
  6732. <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;"
  6733. class="block-grid ">
  6734. <div style="border-collapse: collapse;display: table;width: 100%;">
  6735. <!--[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]-->
  6736. <!--[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]-->
  6737. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  6738. <div style="background-color: transparent; width: 100% !important;">
  6739. <!--[if (!mso)&(!IE)]><!-->
  6740. <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;">
  6741. <!--<![endif]-->
  6742. <!--[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]-->
  6743. <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;">
  6744. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  6745. <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"
  6746. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  6747. </div>
  6748. </div>
  6749. <!--[if mso]></td></tr></table><![endif]-->
  6750. <!--[if (!mso)&(!IE)]><!-->
  6751. </div>
  6752. <!--<![endif]-->
  6753. </div>
  6754. </div>
  6755. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  6756. </div>
  6757. </div>
  6758. </div>
  6759. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  6760. </div>
  6761. <!--[if (mso)|(IE)]></div><![endif]-->
  6762. </body>
  6763. </html>
  6764. ';
  6765. }
  6766. function mimeTypes(){
  6767. return array(
  6768. '123' => 'application/vnd.lotus-1-2-3',
  6769. '3dml' => 'text/vnd.in3d.3dml',
  6770. '3ds' => 'image/x-3ds',
  6771. '3g2' => 'video/3gpp2',
  6772. '3gp' => 'video/3gpp',
  6773. '7z' => 'application/x-7z-compressed',
  6774. 'aab' => 'application/x-authorware-bin',
  6775. 'aac' => 'audio/x-aac',
  6776. 'aam' => 'application/x-authorware-map',
  6777. 'aas' => 'application/x-authorware-seg',
  6778. 'abw' => 'application/x-abiword',
  6779. 'ac' => 'application/pkix-attr-cert',
  6780. 'acc' => 'application/vnd.americandynamics.acc',
  6781. 'ace' => 'application/x-ace-compressed',
  6782. 'acu' => 'application/vnd.acucobol',
  6783. 'acutc' => 'application/vnd.acucorp',
  6784. 'adp' => 'audio/adpcm',
  6785. 'aep' => 'application/vnd.audiograph',
  6786. 'afm' => 'application/x-font-type1',
  6787. 'afp' => 'application/vnd.ibm.modcap',
  6788. 'ahead' => 'application/vnd.ahead.space',
  6789. 'ai' => 'application/postscript',
  6790. 'aif' => 'audio/x-aiff',
  6791. 'aifc' => 'audio/x-aiff',
  6792. 'aiff' => 'audio/x-aiff',
  6793. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  6794. 'ait' => 'application/vnd.dvb.ait',
  6795. 'ami' => 'application/vnd.amiga.ami',
  6796. 'apk' => 'application/vnd.android.package-archive',
  6797. 'appcache' => 'text/cache-manifest',
  6798. 'application' => 'application/x-ms-application',
  6799. 'apr' => 'application/vnd.lotus-approach',
  6800. 'arc' => 'application/x-freearc',
  6801. 'asc' => 'application/pgp-signature',
  6802. 'asf' => 'video/x-ms-asf',
  6803. 'asm' => 'text/x-asm',
  6804. 'aso' => 'application/vnd.accpac.simply.aso',
  6805. 'asx' => 'video/x-ms-asf',
  6806. 'atc' => 'application/vnd.acucorp',
  6807. 'atom' => 'application/atom+xml',
  6808. 'atomcat' => 'application/atomcat+xml',
  6809. 'atomsvc' => 'application/atomsvc+xml',
  6810. 'atx' => 'application/vnd.antix.game-component',
  6811. 'au' => 'audio/basic',
  6812. 'avi' => 'video/x-msvideo',
  6813. 'aw' => 'application/applixware',
  6814. 'azf' => 'application/vnd.airzip.filesecure.azf',
  6815. 'azs' => 'application/vnd.airzip.filesecure.azs',
  6816. 'azw' => 'application/vnd.amazon.ebook',
  6817. 'bat' => 'application/x-msdownload',
  6818. 'bcpio' => 'application/x-bcpio',
  6819. 'bdf' => 'application/x-font-bdf',
  6820. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  6821. 'bed' => 'application/vnd.realvnc.bed',
  6822. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  6823. 'bin' => 'application/octet-stream',
  6824. 'blb' => 'application/x-blorb',
  6825. 'blorb' => 'application/x-blorb',
  6826. 'bmi' => 'application/vnd.bmi',
  6827. 'bmp' => 'image/bmp',
  6828. 'book' => 'application/vnd.framemaker',
  6829. 'box' => 'application/vnd.previewsystems.box',
  6830. 'boz' => 'application/x-bzip2',
  6831. 'bpk' => 'application/octet-stream',
  6832. 'btif' => 'image/prs.btif',
  6833. 'bz' => 'application/x-bzip',
  6834. 'bz2' => 'application/x-bzip2',
  6835. 'c' => 'text/x-c',
  6836. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  6837. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  6838. 'c4d' => 'application/vnd.clonk.c4group',
  6839. 'c4f' => 'application/vnd.clonk.c4group',
  6840. 'c4g' => 'application/vnd.clonk.c4group',
  6841. 'c4p' => 'application/vnd.clonk.c4group',
  6842. 'c4u' => 'application/vnd.clonk.c4group',
  6843. 'cab' => 'application/vnd.ms-cab-compressed',
  6844. 'caf' => 'audio/x-caf',
  6845. 'cap' => 'application/vnd.tcpdump.pcap',
  6846. 'car' => 'application/vnd.curl.car',
  6847. 'cat' => 'application/vnd.ms-pki.seccat',
  6848. 'cb7' => 'application/x-cbr',
  6849. 'cba' => 'application/x-cbr',
  6850. 'cbr' => 'application/x-cbr',
  6851. 'cbt' => 'application/x-cbr',
  6852. 'cbz' => 'application/x-cbr',
  6853. 'cc' => 'text/x-c',
  6854. 'cct' => 'application/x-director',
  6855. 'ccxml' => 'application/ccxml+xml',
  6856. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  6857. 'cdf' => 'application/x-netcdf',
  6858. 'cdkey' => 'application/vnd.mediastation.cdkey',
  6859. 'cdmia' => 'application/cdmi-capability',
  6860. 'cdmic' => 'application/cdmi-container',
  6861. 'cdmid' => 'application/cdmi-domain',
  6862. 'cdmio' => 'application/cdmi-object',
  6863. 'cdmiq' => 'application/cdmi-queue',
  6864. 'cdx' => 'chemical/x-cdx',
  6865. 'cdxml' => 'application/vnd.chemdraw+xml',
  6866. 'cdy' => 'application/vnd.cinderella',
  6867. 'cer' => 'application/pkix-cert',
  6868. 'cfs' => 'application/x-cfs-compressed',
  6869. 'cgm' => 'image/cgm',
  6870. 'chat' => 'application/x-chat',
  6871. 'chm' => 'application/vnd.ms-htmlhelp',
  6872. 'chrt' => 'application/vnd.kde.kchart',
  6873. 'cif' => 'chemical/x-cif',
  6874. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  6875. 'cil' => 'application/vnd.ms-artgalry',
  6876. 'cla' => 'application/vnd.claymore',
  6877. 'class' => 'application/java-vm',
  6878. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  6879. 'clkp' => 'application/vnd.crick.clicker.palette',
  6880. 'clkt' => 'application/vnd.crick.clicker.template',
  6881. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  6882. 'clkx' => 'application/vnd.crick.clicker',
  6883. 'clp' => 'application/x-msclip',
  6884. 'cmc' => 'application/vnd.cosmocaller',
  6885. 'cmdf' => 'chemical/x-cmdf',
  6886. 'cml' => 'chemical/x-cml',
  6887. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  6888. 'cmx' => 'image/x-cmx',
  6889. 'cod' => 'application/vnd.rim.cod',
  6890. 'com' => 'application/x-msdownload',
  6891. 'conf' => 'text/plain',
  6892. 'cpio' => 'application/x-cpio',
  6893. 'cpp' => 'text/x-c',
  6894. 'cpt' => 'application/mac-compactpro',
  6895. 'crd' => 'application/x-mscardfile',
  6896. 'crl' => 'application/pkix-crl',
  6897. 'crt' => 'application/x-x509-ca-cert',
  6898. 'cryptonote' => 'application/vnd.rig.cryptonote',
  6899. 'csh' => 'application/x-csh',
  6900. 'csml' => 'chemical/x-csml',
  6901. 'csp' => 'application/vnd.commonspace',
  6902. 'css' => 'text/css',
  6903. 'cst' => 'application/x-director',
  6904. 'csv' => 'text/csv',
  6905. 'cu' => 'application/cu-seeme',
  6906. 'curl' => 'text/vnd.curl',
  6907. 'cww' => 'application/prs.cww',
  6908. 'cxt' => 'application/x-director',
  6909. 'cxx' => 'text/x-c',
  6910. 'dae' => 'model/vnd.collada+xml',
  6911. 'daf' => 'application/vnd.mobius.daf',
  6912. 'dart' => 'application/vnd.dart',
  6913. 'dataless' => 'application/vnd.fdsn.seed',
  6914. 'davmount' => 'application/davmount+xml',
  6915. 'dbk' => 'application/docbook+xml',
  6916. 'dcr' => 'application/x-director',
  6917. 'dcurl' => 'text/vnd.curl.dcurl',
  6918. 'dd2' => 'application/vnd.oma.dd2+xml',
  6919. 'ddd' => 'application/vnd.fujixerox.ddd',
  6920. 'deb' => 'application/x-debian-package',
  6921. 'def' => 'text/plain',
  6922. 'deploy' => 'application/octet-stream',
  6923. 'der' => 'application/x-x509-ca-cert',
  6924. 'dfac' => 'application/vnd.dreamfactory',
  6925. 'dgc' => 'application/x-dgc-compressed',
  6926. 'dic' => 'text/x-c',
  6927. 'dir' => 'application/x-director',
  6928. 'dis' => 'application/vnd.mobius.dis',
  6929. 'dist' => 'application/octet-stream',
  6930. 'distz' => 'application/octet-stream',
  6931. 'djv' => 'image/vnd.djvu',
  6932. 'djvu' => 'image/vnd.djvu',
  6933. 'dll' => 'application/x-msdownload',
  6934. 'dmg' => 'application/x-apple-diskimage',
  6935. 'dmp' => 'application/vnd.tcpdump.pcap',
  6936. 'dms' => 'application/octet-stream',
  6937. 'dna' => 'application/vnd.dna',
  6938. 'doc' => 'application/msword',
  6939. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  6940. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  6941. 'dot' => 'application/msword',
  6942. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  6943. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  6944. 'dp' => 'application/vnd.osgi.dp',
  6945. 'dpg' => 'application/vnd.dpgraph',
  6946. 'dra' => 'audio/vnd.dra',
  6947. 'dsc' => 'text/prs.lines.tag',
  6948. 'dssc' => 'application/dssc+der',
  6949. 'dtb' => 'application/x-dtbook+xml',
  6950. 'dtd' => 'application/xml-dtd',
  6951. 'dts' => 'audio/vnd.dts',
  6952. 'dtshd' => 'audio/vnd.dts.hd',
  6953. 'dump' => 'application/octet-stream',
  6954. 'dvb' => 'video/vnd.dvb.file',
  6955. 'dvi' => 'application/x-dvi',
  6956. 'dwf' => 'model/vnd.dwf',
  6957. 'dwg' => 'image/vnd.dwg',
  6958. 'dxf' => 'image/vnd.dxf',
  6959. 'dxp' => 'application/vnd.spotfire.dxp',
  6960. 'dxr' => 'application/x-director',
  6961. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  6962. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  6963. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  6964. 'ecma' => 'application/ecmascript',
  6965. 'edm' => 'application/vnd.novadigm.edm',
  6966. 'edx' => 'application/vnd.novadigm.edx',
  6967. 'efif' => 'application/vnd.picsel',
  6968. 'ei6' => 'application/vnd.pg.osasli',
  6969. 'elc' => 'application/octet-stream',
  6970. 'emf' => 'application/x-msmetafile',
  6971. 'eml' => 'message/rfc822',
  6972. 'emma' => 'application/emma+xml',
  6973. 'emz' => 'application/x-msmetafile',
  6974. 'eol' => 'audio/vnd.digital-winds',
  6975. 'eot' => 'application/vnd.ms-fontobject',
  6976. 'eps' => 'application/postscript',
  6977. 'epub' => 'application/epub+zip',
  6978. 'es3' => 'application/vnd.eszigno3+xml',
  6979. 'esa' => 'application/vnd.osgi.subsystem',
  6980. 'esf' => 'application/vnd.epson.esf',
  6981. 'et3' => 'application/vnd.eszigno3+xml',
  6982. 'etx' => 'text/x-setext',
  6983. 'eva' => 'application/x-eva',
  6984. 'evy' => 'application/x-envoy',
  6985. 'exe' => 'application/x-msdownload',
  6986. 'exi' => 'application/exi',
  6987. 'ext' => 'application/vnd.novadigm.ext',
  6988. 'ez' => 'application/andrew-inset',
  6989. 'ez2' => 'application/vnd.ezpix-album',
  6990. 'ez3' => 'application/vnd.ezpix-package',
  6991. 'f' => 'text/x-fortran',
  6992. 'f4v' => 'video/x-f4v',
  6993. 'f77' => 'text/x-fortran',
  6994. 'f90' => 'text/x-fortran',
  6995. 'fbs' => 'image/vnd.fastbidsheet',
  6996. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  6997. 'fcs' => 'application/vnd.isac.fcs',
  6998. 'fdf' => 'application/vnd.fdf',
  6999. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  7000. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  7001. 'fgd' => 'application/x-director',
  7002. 'fh' => 'image/x-freehand',
  7003. 'fh4' => 'image/x-freehand',
  7004. 'fh5' => 'image/x-freehand',
  7005. 'fh7' => 'image/x-freehand',
  7006. 'fhc' => 'image/x-freehand',
  7007. 'fig' => 'application/x-xfig',
  7008. 'flac' => 'audio/x-flac',
  7009. 'fli' => 'video/x-fli',
  7010. 'flo' => 'application/vnd.micrografx.flo',
  7011. 'flv' => 'video/x-flv',
  7012. 'flw' => 'application/vnd.kde.kivio',
  7013. 'flx' => 'text/vnd.fmi.flexstor',
  7014. 'fly' => 'text/vnd.fly',
  7015. 'fm' => 'application/vnd.framemaker',
  7016. 'fnc' => 'application/vnd.frogans.fnc',
  7017. 'for' => 'text/x-fortran',
  7018. 'fpx' => 'image/vnd.fpx',
  7019. 'frame' => 'application/vnd.framemaker',
  7020. 'fsc' => 'application/vnd.fsc.weblaunch',
  7021. 'fst' => 'image/vnd.fst',
  7022. 'ftc' => 'application/vnd.fluxtime.clip',
  7023. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  7024. 'fvt' => 'video/vnd.fvt',
  7025. 'fxp' => 'application/vnd.adobe.fxp',
  7026. 'fxpl' => 'application/vnd.adobe.fxp',
  7027. 'fzs' => 'application/vnd.fuzzysheet',
  7028. 'g2w' => 'application/vnd.geoplan',
  7029. 'g3' => 'image/g3fax',
  7030. 'g3w' => 'application/vnd.geospace',
  7031. 'gac' => 'application/vnd.groove-account',
  7032. 'gam' => 'application/x-tads',
  7033. 'gbr' => 'application/rpki-ghostbusters',
  7034. 'gca' => 'application/x-gca-compressed',
  7035. 'gdl' => 'model/vnd.gdl',
  7036. 'geo' => 'application/vnd.dynageo',
  7037. 'gex' => 'application/vnd.geometry-explorer',
  7038. 'ggb' => 'application/vnd.geogebra.file',
  7039. 'ggt' => 'application/vnd.geogebra.tool',
  7040. 'ghf' => 'application/vnd.groove-help',
  7041. 'gif' => 'image/gif',
  7042. 'gim' => 'application/vnd.groove-identity-message',
  7043. 'gml' => 'application/gml+xml',
  7044. 'gmx' => 'application/vnd.gmx',
  7045. 'gnumeric' => 'application/x-gnumeric',
  7046. 'gph' => 'application/vnd.flographit',
  7047. 'gpx' => 'application/gpx+xml',
  7048. 'gqf' => 'application/vnd.grafeq',
  7049. 'gqs' => 'application/vnd.grafeq',
  7050. 'gram' => 'application/srgs',
  7051. 'gramps' => 'application/x-gramps-xml',
  7052. 'gre' => 'application/vnd.geometry-explorer',
  7053. 'grv' => 'application/vnd.groove-injector',
  7054. 'grxml' => 'application/srgs+xml',
  7055. 'gsf' => 'application/x-font-ghostscript',
  7056. 'gtar' => 'application/x-gtar',
  7057. 'gtm' => 'application/vnd.groove-tool-message',
  7058. 'gtw' => 'model/vnd.gtw',
  7059. 'gv' => 'text/vnd.graphviz',
  7060. 'gxf' => 'application/gxf',
  7061. 'gxt' => 'application/vnd.geonext',
  7062. 'h' => 'text/x-c',
  7063. 'h261' => 'video/h261',
  7064. 'h263' => 'video/h263',
  7065. 'h264' => 'video/h264',
  7066. 'hal' => 'application/vnd.hal+xml',
  7067. 'hbci' => 'application/vnd.hbci',
  7068. 'hdf' => 'application/x-hdf',
  7069. 'hh' => 'text/x-c',
  7070. 'hlp' => 'application/winhlp',
  7071. 'hpgl' => 'application/vnd.hp-hpgl',
  7072. 'hpid' => 'application/vnd.hp-hpid',
  7073. 'hps' => 'application/vnd.hp-hps',
  7074. 'hqx' => 'application/mac-binhex40',
  7075. 'htke' => 'application/vnd.kenameaapp',
  7076. 'htm' => 'text/html',
  7077. 'html' => 'text/html',
  7078. 'hvd' => 'application/vnd.yamaha.hv-dic',
  7079. 'hvp' => 'application/vnd.yamaha.hv-voice',
  7080. 'hvs' => 'application/vnd.yamaha.hv-script',
  7081. 'i2g' => 'application/vnd.intergeo',
  7082. 'icc' => 'application/vnd.iccprofile',
  7083. 'ice' => 'x-conference/x-cooltalk',
  7084. 'icm' => 'application/vnd.iccprofile',
  7085. 'ico' => 'image/x-icon',
  7086. 'ics' => 'text/calendar',
  7087. 'ief' => 'image/ief',
  7088. 'ifb' => 'text/calendar',
  7089. 'ifm' => 'application/vnd.shana.informed.formdata',
  7090. 'iges' => 'model/iges',
  7091. 'igl' => 'application/vnd.igloader',
  7092. 'igm' => 'application/vnd.insors.igm',
  7093. 'igs' => 'model/iges',
  7094. 'igx' => 'application/vnd.micrografx.igx',
  7095. 'iif' => 'application/vnd.shana.informed.interchange',
  7096. 'imp' => 'application/vnd.accpac.simply.imp',
  7097. 'ims' => 'application/vnd.ms-ims',
  7098. 'in' => 'text/plain',
  7099. 'ink' => 'application/inkml+xml',
  7100. 'inkml' => 'application/inkml+xml',
  7101. 'install' => 'application/x-install-instructions',
  7102. 'iota' => 'application/vnd.astraea-software.iota',
  7103. 'ipfix' => 'application/ipfix',
  7104. 'ipk' => 'application/vnd.shana.informed.package',
  7105. 'irm' => 'application/vnd.ibm.rights-management',
  7106. 'irp' => 'application/vnd.irepository.package+xml',
  7107. 'iso' => 'application/x-iso9660-image',
  7108. 'itp' => 'application/vnd.shana.informed.formtemplate',
  7109. 'ivp' => 'application/vnd.immervision-ivp',
  7110. 'ivu' => 'application/vnd.immervision-ivu',
  7111. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  7112. 'jam' => 'application/vnd.jam',
  7113. 'jar' => 'application/java-archive',
  7114. 'java' => 'text/x-java-source',
  7115. 'jisp' => 'application/vnd.jisp',
  7116. 'jlt' => 'application/vnd.hp-jlyt',
  7117. 'jnlp' => 'application/x-java-jnlp-file',
  7118. 'joda' => 'application/vnd.joost.joda-archive',
  7119. 'jpe' => 'image/jpeg',
  7120. 'jpeg' => 'image/jpeg',
  7121. 'jpg' => 'image/jpeg',
  7122. 'jpgm' => 'video/jpm',
  7123. 'jpgv' => 'video/jpeg',
  7124. 'jpm' => 'video/jpm',
  7125. 'js' => 'application/javascript',
  7126. 'json' => 'application/json',
  7127. 'jsonml' => 'application/jsonml+json',
  7128. 'kar' => 'audio/midi',
  7129. 'karbon' => 'application/vnd.kde.karbon',
  7130. 'kfo' => 'application/vnd.kde.kformula',
  7131. 'kia' => 'application/vnd.kidspiration',
  7132. 'kml' => 'application/vnd.google-earth.kml+xml',
  7133. 'kmz' => 'application/vnd.google-earth.kmz',
  7134. 'kne' => 'application/vnd.kinar',
  7135. 'knp' => 'application/vnd.kinar',
  7136. 'kon' => 'application/vnd.kde.kontour',
  7137. 'kpr' => 'application/vnd.kde.kpresenter',
  7138. 'kpt' => 'application/vnd.kde.kpresenter',
  7139. 'kpxx' => 'application/vnd.ds-keypoint',
  7140. 'ksp' => 'application/vnd.kde.kspread',
  7141. 'ktr' => 'application/vnd.kahootz',
  7142. 'ktx' => 'image/ktx',
  7143. 'ktz' => 'application/vnd.kahootz',
  7144. 'kwd' => 'application/vnd.kde.kword',
  7145. 'kwt' => 'application/vnd.kde.kword',
  7146. 'lasxml' => 'application/vnd.las.las+xml',
  7147. 'latex' => 'application/x-latex',
  7148. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  7149. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  7150. 'les' => 'application/vnd.hhe.lesson-player',
  7151. 'lha' => 'application/x-lzh-compressed',
  7152. 'link66' => 'application/vnd.route66.link66+xml',
  7153. 'list' => 'text/plain',
  7154. 'list3820' => 'application/vnd.ibm.modcap',
  7155. 'listafp' => 'application/vnd.ibm.modcap',
  7156. 'lnk' => 'application/x-ms-shortcut',
  7157. 'log' => 'text/plain',
  7158. 'lostxml' => 'application/lost+xml',
  7159. 'lrf' => 'application/octet-stream',
  7160. 'lrm' => 'application/vnd.ms-lrm',
  7161. 'ltf' => 'application/vnd.frogans.ltf',
  7162. 'lvp' => 'audio/vnd.lucent.voice',
  7163. 'lwp' => 'application/vnd.lotus-wordpro',
  7164. 'lzh' => 'application/x-lzh-compressed',
  7165. 'm13' => 'application/x-msmediaview',
  7166. 'm14' => 'application/x-msmediaview',
  7167. 'm1v' => 'video/mpeg',
  7168. 'm21' => 'application/mp21',
  7169. 'm2a' => 'audio/mpeg',
  7170. 'm2v' => 'video/mpeg',
  7171. 'm3a' => 'audio/mpeg',
  7172. 'm3u' => 'audio/x-mpegurl',
  7173. 'm3u8' => 'application/vnd.apple.mpegurl',
  7174. 'm4a' => 'audio/mp4',
  7175. 'm4u' => 'video/vnd.mpegurl',
  7176. 'm4v' => 'video/x-m4v',
  7177. 'ma' => 'application/mathematica',
  7178. 'mads' => 'application/mads+xml',
  7179. 'mag' => 'application/vnd.ecowin.chart',
  7180. 'maker' => 'application/vnd.framemaker',
  7181. 'man' => 'text/troff',
  7182. 'mar' => 'application/octet-stream',
  7183. 'mathml' => 'application/mathml+xml',
  7184. 'mb' => 'application/mathematica',
  7185. 'mbk' => 'application/vnd.mobius.mbk',
  7186. 'mbox' => 'application/mbox',
  7187. 'mc1' => 'application/vnd.medcalcdata',
  7188. 'mcd' => 'application/vnd.mcd',
  7189. 'mcurl' => 'text/vnd.curl.mcurl',
  7190. 'mdb' => 'application/x-msaccess',
  7191. 'mdi' => 'image/vnd.ms-modi',
  7192. 'me' => 'text/troff',
  7193. 'mesh' => 'model/mesh',
  7194. 'meta4' => 'application/metalink4+xml',
  7195. 'metalink' => 'application/metalink+xml',
  7196. 'mets' => 'application/mets+xml',
  7197. 'mfm' => 'application/vnd.mfmp',
  7198. 'mft' => 'application/rpki-manifest',
  7199. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  7200. 'mgz' => 'application/vnd.proteus.magazine',
  7201. 'mid' => 'audio/midi',
  7202. 'midi' => 'audio/midi',
  7203. 'mie' => 'application/x-mie',
  7204. 'mif' => 'application/vnd.mif',
  7205. 'mime' => 'message/rfc822',
  7206. 'mj2' => 'video/mj2',
  7207. 'mjp2' => 'video/mj2',
  7208. 'mk3d' => 'video/x-matroska',
  7209. 'mka' => 'audio/x-matroska',
  7210. 'mks' => 'video/x-matroska',
  7211. 'mkv' => 'video/x-matroska',
  7212. 'mlp' => 'application/vnd.dolby.mlp',
  7213. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  7214. 'mmf' => 'application/vnd.smaf',
  7215. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  7216. 'mng' => 'video/x-mng',
  7217. 'mny' => 'application/x-msmoney',
  7218. 'mobi' => 'application/x-mobipocket-ebook',
  7219. 'mods' => 'application/mods+xml',
  7220. 'mov' => 'video/quicktime',
  7221. 'movie' => 'video/x-sgi-movie',
  7222. 'mp2' => 'audio/mpeg',
  7223. 'mp21' => 'application/mp21',
  7224. 'mp2a' => 'audio/mpeg',
  7225. 'mp3' => 'audio/mpeg',
  7226. 'mp4' => 'video/mp4',
  7227. 'mp4a' => 'audio/mp4',
  7228. 'mp4s' => 'application/mp4',
  7229. 'mp4v' => 'video/mp4',
  7230. 'mpc' => 'application/vnd.mophun.certificate',
  7231. 'mpe' => 'video/mpeg',
  7232. 'mpeg' => 'video/mpeg',
  7233. 'mpg' => 'video/mpeg',
  7234. 'mpg4' => 'video/mp4',
  7235. 'mpga' => 'audio/mpeg',
  7236. 'mpkg' => 'application/vnd.apple.installer+xml',
  7237. 'mpm' => 'application/vnd.blueice.multipass',
  7238. 'mpn' => 'application/vnd.mophun.application',
  7239. 'mpp' => 'application/vnd.ms-project',
  7240. 'mpt' => 'application/vnd.ms-project',
  7241. 'mpy' => 'application/vnd.ibm.minipay',
  7242. 'mqy' => 'application/vnd.mobius.mqy',
  7243. 'mrc' => 'application/marc',
  7244. 'mrcx' => 'application/marcxml+xml',
  7245. 'ms' => 'text/troff',
  7246. 'mscml' => 'application/mediaservercontrol+xml',
  7247. 'mseed' => 'application/vnd.fdsn.mseed',
  7248. 'mseq' => 'application/vnd.mseq',
  7249. 'msf' => 'application/vnd.epson.msf',
  7250. 'msh' => 'model/mesh',
  7251. 'msi' => 'application/x-msdownload',
  7252. 'msl' => 'application/vnd.mobius.msl',
  7253. 'msty' => 'application/vnd.muvee.style',
  7254. 'mts' => 'model/vnd.mts',
  7255. 'mus' => 'application/vnd.musician',
  7256. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  7257. 'mvb' => 'application/x-msmediaview',
  7258. 'mwf' => 'application/vnd.mfer',
  7259. 'mxf' => 'application/mxf',
  7260. 'mxl' => 'application/vnd.recordare.musicxml',
  7261. 'mxml' => 'application/xv+xml',
  7262. 'mxs' => 'application/vnd.triscape.mxs',
  7263. 'mxu' => 'video/vnd.mpegurl',
  7264. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  7265. 'n3' => 'text/n3',
  7266. 'nb' => 'application/mathematica',
  7267. 'nbp' => 'application/vnd.wolfram.player',
  7268. 'nc' => 'application/x-netcdf',
  7269. 'ncx' => 'application/x-dtbncx+xml',
  7270. 'nfo' => 'text/x-nfo',
  7271. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  7272. 'nitf' => 'application/vnd.nitf',
  7273. 'nlu' => 'application/vnd.neurolanguage.nlu',
  7274. 'nml' => 'application/vnd.enliven',
  7275. 'nnd' => 'application/vnd.noblenet-directory',
  7276. 'nns' => 'application/vnd.noblenet-sealer',
  7277. 'nnw' => 'application/vnd.noblenet-web',
  7278. 'npx' => 'image/vnd.net-fpx',
  7279. 'nsc' => 'application/x-conference',
  7280. 'nsf' => 'application/vnd.lotus-notes',
  7281. 'ntf' => 'application/vnd.nitf',
  7282. 'nzb' => 'application/x-nzb',
  7283. 'oa2' => 'application/vnd.fujitsu.oasys2',
  7284. 'oa3' => 'application/vnd.fujitsu.oasys3',
  7285. 'oas' => 'application/vnd.fujitsu.oasys',
  7286. 'obd' => 'application/x-msbinder',
  7287. 'obj' => 'application/x-tgif',
  7288. 'oda' => 'application/oda',
  7289. 'odb' => 'application/vnd.oasis.opendocument.database',
  7290. 'odc' => 'application/vnd.oasis.opendocument.chart',
  7291. 'odf' => 'application/vnd.oasis.opendocument.formula',
  7292. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  7293. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  7294. 'odi' => 'application/vnd.oasis.opendocument.image',
  7295. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  7296. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  7297. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  7298. 'odt' => 'application/vnd.oasis.opendocument.text',
  7299. 'oga' => 'audio/ogg',
  7300. 'ogg' => 'audio/ogg',
  7301. 'ogv' => 'video/ogg',
  7302. 'ogx' => 'application/ogg',
  7303. 'omdoc' => 'application/omdoc+xml',
  7304. 'onepkg' => 'application/onenote',
  7305. 'onetmp' => 'application/onenote',
  7306. 'onetoc' => 'application/onenote',
  7307. 'onetoc2' => 'application/onenote',
  7308. 'opf' => 'application/oebps-package+xml',
  7309. 'opml' => 'text/x-opml',
  7310. 'oprc' => 'application/vnd.palm',
  7311. 'org' => 'application/vnd.lotus-organizer',
  7312. 'osf' => 'application/vnd.yamaha.openscoreformat',
  7313. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  7314. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  7315. 'otf' => 'application/x-font-otf',
  7316. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  7317. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  7318. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  7319. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  7320. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  7321. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  7322. 'oxps' => 'application/oxps',
  7323. 'oxt' => 'application/vnd.openofficeorg.extension',
  7324. 'p' => 'text/x-pascal',
  7325. 'p10' => 'application/pkcs10',
  7326. 'p12' => 'application/x-pkcs12',
  7327. 'p7b' => 'application/x-pkcs7-certificates',
  7328. 'p7c' => 'application/pkcs7-mime',
  7329. 'p7m' => 'application/pkcs7-mime',
  7330. 'p7r' => 'application/x-pkcs7-certreqresp',
  7331. 'p7s' => 'application/pkcs7-signature',
  7332. 'p8' => 'application/pkcs8',
  7333. 'pas' => 'text/x-pascal',
  7334. 'paw' => 'application/vnd.pawaafile',
  7335. 'pbd' => 'application/vnd.powerbuilder6',
  7336. 'pbm' => 'image/x-portable-bitmap',
  7337. 'pcap' => 'application/vnd.tcpdump.pcap',
  7338. 'pcf' => 'application/x-font-pcf',
  7339. 'pcl' => 'application/vnd.hp-pcl',
  7340. 'pclxl' => 'application/vnd.hp-pclxl',
  7341. 'pct' => 'image/x-pict',
  7342. 'pcurl' => 'application/vnd.curl.pcurl',
  7343. 'pcx' => 'image/x-pcx',
  7344. 'pdb' => 'application/vnd.palm',
  7345. 'pdf' => 'application/pdf',
  7346. 'pfa' => 'application/x-font-type1',
  7347. 'pfb' => 'application/x-font-type1',
  7348. 'pfm' => 'application/x-font-type1',
  7349. 'pfr' => 'application/font-tdpfr',
  7350. 'pfx' => 'application/x-pkcs12',
  7351. 'pgm' => 'image/x-portable-graymap',
  7352. 'pgn' => 'application/x-chess-pgn',
  7353. 'pgp' => 'application/pgp-encrypted',
  7354. 'pic' => 'image/x-pict',
  7355. 'pkg' => 'application/octet-stream',
  7356. 'pki' => 'application/pkixcmp',
  7357. 'pkipath' => 'application/pkix-pkipath',
  7358. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  7359. 'plc' => 'application/vnd.mobius.plc',
  7360. 'plf' => 'application/vnd.pocketlearn',
  7361. 'pls' => 'application/pls+xml',
  7362. 'pml' => 'application/vnd.ctc-posml',
  7363. 'png' => 'image/png',
  7364. 'pnm' => 'image/x-portable-anymap',
  7365. 'portpkg' => 'application/vnd.macports.portpkg',
  7366. 'pot' => 'application/vnd.ms-powerpoint',
  7367. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  7368. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  7369. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  7370. 'ppd' => 'application/vnd.cups-ppd',
  7371. 'ppm' => 'image/x-portable-pixmap',
  7372. 'pps' => 'application/vnd.ms-powerpoint',
  7373. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  7374. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  7375. 'ppt' => 'application/vnd.ms-powerpoint',
  7376. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  7377. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  7378. 'pqa' => 'application/vnd.palm',
  7379. 'prc' => 'application/x-mobipocket-ebook',
  7380. 'pre' => 'application/vnd.lotus-freelance',
  7381. 'prf' => 'application/pics-rules',
  7382. 'ps' => 'application/postscript',
  7383. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  7384. 'psd' => 'image/vnd.adobe.photoshop',
  7385. 'psf' => 'application/x-font-linux-psf',
  7386. 'pskcxml' => 'application/pskc+xml',
  7387. 'ptid' => 'application/vnd.pvi.ptid1',
  7388. 'pub' => 'application/x-mspublisher',
  7389. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  7390. 'pwn' => 'application/vnd.3m.post-it-notes',
  7391. 'pya' => 'audio/vnd.ms-playready.media.pya',
  7392. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  7393. 'qam' => 'application/vnd.epson.quickanime',
  7394. 'qbo' => 'application/vnd.intu.qbo',
  7395. 'qfx' => 'application/vnd.intu.qfx',
  7396. 'qps' => 'application/vnd.publishare-delta-tree',
  7397. 'qt' => 'video/quicktime',
  7398. 'qwd' => 'application/vnd.quark.quarkxpress',
  7399. 'qwt' => 'application/vnd.quark.quarkxpress',
  7400. 'qxb' => 'application/vnd.quark.quarkxpress',
  7401. 'qxd' => 'application/vnd.quark.quarkxpress',
  7402. 'qxl' => 'application/vnd.quark.quarkxpress',
  7403. 'qxt' => 'application/vnd.quark.quarkxpress',
  7404. 'ra' => 'audio/x-pn-realaudio',
  7405. 'ram' => 'audio/x-pn-realaudio',
  7406. 'rar' => 'application/x-rar-compressed',
  7407. 'ras' => 'image/x-cmu-raster',
  7408. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  7409. 'rdf' => 'application/rdf+xml',
  7410. 'rdz' => 'application/vnd.data-vision.rdz',
  7411. 'rep' => 'application/vnd.businessobjects',
  7412. 'res' => 'application/x-dtbresource+xml',
  7413. 'rgb' => 'image/x-rgb',
  7414. 'rif' => 'application/reginfo+xml',
  7415. 'rip' => 'audio/vnd.rip',
  7416. 'ris' => 'application/x-research-info-systems',
  7417. 'rl' => 'application/resource-lists+xml',
  7418. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  7419. 'rld' => 'application/resource-lists-diff+xml',
  7420. 'rm' => 'application/vnd.rn-realmedia',
  7421. 'rmi' => 'audio/midi',
  7422. 'rmp' => 'audio/x-pn-realaudio-plugin',
  7423. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  7424. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  7425. 'rnc' => 'application/relax-ng-compact-syntax',
  7426. 'roa' => 'application/rpki-roa',
  7427. 'roff' => 'text/troff',
  7428. 'rp9' => 'application/vnd.cloanto.rp9',
  7429. 'rpss' => 'application/vnd.nokia.radio-presets',
  7430. 'rpst' => 'application/vnd.nokia.radio-preset',
  7431. 'rq' => 'application/sparql-query',
  7432. 'rs' => 'application/rls-services+xml',
  7433. 'rsd' => 'application/rsd+xml',
  7434. 'rss' => 'application/rss+xml',
  7435. 'rtf' => 'application/rtf',
  7436. 'rtx' => 'text/richtext',
  7437. 's' => 'text/x-asm',
  7438. 's3m' => 'audio/s3m',
  7439. 'saf' => 'application/vnd.yamaha.smaf-audio',
  7440. 'sbml' => 'application/sbml+xml',
  7441. 'sc' => 'application/vnd.ibm.secure-container',
  7442. 'scd' => 'application/x-msschedule',
  7443. 'scm' => 'application/vnd.lotus-screencam',
  7444. 'scq' => 'application/scvp-cv-request',
  7445. 'scs' => 'application/scvp-cv-response',
  7446. 'scurl' => 'text/vnd.curl.scurl',
  7447. 'sda' => 'application/vnd.stardivision.draw',
  7448. 'sdc' => 'application/vnd.stardivision.calc',
  7449. 'sdd' => 'application/vnd.stardivision.impress',
  7450. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  7451. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  7452. 'sdp' => 'application/sdp',
  7453. 'sdw' => 'application/vnd.stardivision.writer',
  7454. 'see' => 'application/vnd.seemail',
  7455. 'seed' => 'application/vnd.fdsn.seed',
  7456. 'sema' => 'application/vnd.sema',
  7457. 'semd' => 'application/vnd.semd',
  7458. 'semf' => 'application/vnd.semf',
  7459. 'ser' => 'application/java-serialized-object',
  7460. 'setpay' => 'application/set-payment-initiation',
  7461. 'setreg' => 'application/set-registration-initiation',
  7462. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  7463. 'sfs' => 'application/vnd.spotfire.sfs',
  7464. 'sfv' => 'text/x-sfv',
  7465. 'sgi' => 'image/sgi',
  7466. 'sgl' => 'application/vnd.stardivision.writer-global',
  7467. 'sgm' => 'text/sgml',
  7468. 'sgml' => 'text/sgml',
  7469. 'sh' => 'application/x-sh',
  7470. 'shar' => 'application/x-shar',
  7471. 'shf' => 'application/shf+xml',
  7472. 'sid' => 'image/x-mrsid-image',
  7473. 'sig' => 'application/pgp-signature',
  7474. 'sil' => 'audio/silk',
  7475. 'silo' => 'model/mesh',
  7476. 'sis' => 'application/vnd.symbian.install',
  7477. 'sisx' => 'application/vnd.symbian.install',
  7478. 'sit' => 'application/x-stuffit',
  7479. 'sitx' => 'application/x-stuffitx',
  7480. 'skd' => 'application/vnd.koan',
  7481. 'skm' => 'application/vnd.koan',
  7482. 'skp' => 'application/vnd.koan',
  7483. 'skt' => 'application/vnd.koan',
  7484. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  7485. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  7486. 'slt' => 'application/vnd.epson.salt',
  7487. 'sm' => 'application/vnd.stepmania.stepchart',
  7488. 'smf' => 'application/vnd.stardivision.math',
  7489. 'smi' => 'application/smil+xml',
  7490. 'smil' => 'application/smil+xml',
  7491. 'smv' => 'video/x-smv',
  7492. 'smzip' => 'application/vnd.stepmania.package',
  7493. 'snd' => 'audio/basic',
  7494. 'snf' => 'application/x-font-snf',
  7495. 'so' => 'application/octet-stream',
  7496. 'spc' => 'application/x-pkcs7-certificates',
  7497. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  7498. 'spl' => 'application/x-futuresplash',
  7499. 'spot' => 'text/vnd.in3d.spot',
  7500. 'spp' => 'application/scvp-vp-response',
  7501. 'spq' => 'application/scvp-vp-request',
  7502. 'spx' => 'audio/ogg',
  7503. 'sql' => 'application/x-sql',
  7504. 'src' => 'application/x-wais-source',
  7505. 'srt' => 'application/x-subrip',
  7506. 'sru' => 'application/sru+xml',
  7507. 'srx' => 'application/sparql-results+xml',
  7508. 'ssdl' => 'application/ssdl+xml',
  7509. 'sse' => 'application/vnd.kodak-descriptor',
  7510. 'ssf' => 'application/vnd.epson.ssf',
  7511. 'ssml' => 'application/ssml+xml',
  7512. 'st' => 'application/vnd.sailingtracker.track',
  7513. 'stc' => 'application/vnd.sun.xml.calc.template',
  7514. 'std' => 'application/vnd.sun.xml.draw.template',
  7515. 'stf' => 'application/vnd.wt.stf',
  7516. 'sti' => 'application/vnd.sun.xml.impress.template',
  7517. 'stk' => 'application/hyperstudio',
  7518. 'stl' => 'application/vnd.ms-pki.stl',
  7519. 'str' => 'application/vnd.pg.format',
  7520. 'stw' => 'application/vnd.sun.xml.writer.template',
  7521. 'sub' => 'image/vnd.dvb.subtitle',
  7522. 'sub' => 'text/vnd.dvb.subtitle',
  7523. 'sus' => 'application/vnd.sus-calendar',
  7524. 'susp' => 'application/vnd.sus-calendar',
  7525. 'sv4cpio' => 'application/x-sv4cpio',
  7526. 'sv4crc' => 'application/x-sv4crc',
  7527. 'svc' => 'application/vnd.dvb.service',
  7528. 'svd' => 'application/vnd.svd',
  7529. 'svg' => 'image/svg+xml',
  7530. 'svgz' => 'image/svg+xml',
  7531. 'swa' => 'application/x-director',
  7532. 'swf' => 'application/x-shockwave-flash',
  7533. 'swi' => 'application/vnd.aristanetworks.swi',
  7534. 'sxc' => 'application/vnd.sun.xml.calc',
  7535. 'sxd' => 'application/vnd.sun.xml.draw',
  7536. 'sxg' => 'application/vnd.sun.xml.writer.global',
  7537. 'sxi' => 'application/vnd.sun.xml.impress',
  7538. 'sxm' => 'application/vnd.sun.xml.math',
  7539. 'sxw' => 'application/vnd.sun.xml.writer',
  7540. 't' => 'text/troff',
  7541. 't3' => 'application/x-t3vm-image',
  7542. 'taglet' => 'application/vnd.mynfc',
  7543. 'tao' => 'application/vnd.tao.intent-module-archive',
  7544. 'tar' => 'application/x-tar',
  7545. 'tcap' => 'application/vnd.3gpp2.tcap',
  7546. 'tcl' => 'application/x-tcl',
  7547. 'teacher' => 'application/vnd.smart.teacher',
  7548. 'tei' => 'application/tei+xml',
  7549. 'teicorpus' => 'application/tei+xml',
  7550. 'tex' => 'application/x-tex',
  7551. 'texi' => 'application/x-texinfo',
  7552. 'texinfo' => 'application/x-texinfo',
  7553. 'text' => 'text/plain',
  7554. 'tfi' => 'application/thraud+xml',
  7555. 'tfm' => 'application/x-tex-tfm',
  7556. 'tga' => 'image/x-tga',
  7557. 'thmx' => 'application/vnd.ms-officetheme',
  7558. 'tif' => 'image/tiff',
  7559. 'tiff' => 'image/tiff',
  7560. 'tmo' => 'application/vnd.tmobile-livetv',
  7561. 'torrent' => 'application/x-bittorrent',
  7562. 'tpl' => 'application/vnd.groove-tool-template',
  7563. 'tpt' => 'application/vnd.trid.tpt',
  7564. 'tr' => 'text/troff',
  7565. 'tra' => 'application/vnd.trueapp',
  7566. 'trm' => 'application/x-msterminal',
  7567. 'tsd' => 'application/timestamped-data',
  7568. 'tsv' => 'text/tab-separated-values',
  7569. 'ttc' => 'application/x-font-ttf',
  7570. 'ttf' => 'application/x-font-ttf',
  7571. 'ttl' => 'text/turtle',
  7572. 'twd' => 'application/vnd.simtech-mindmapper',
  7573. 'twds' => 'application/vnd.simtech-mindmapper',
  7574. 'txd' => 'application/vnd.genomatix.tuxedo',
  7575. 'txf' => 'application/vnd.mobius.txf',
  7576. 'txt' => 'text/plain',
  7577. 'u32' => 'application/x-authorware-bin',
  7578. 'udeb' => 'application/x-debian-package',
  7579. 'ufd' => 'application/vnd.ufdl',
  7580. 'ufdl' => 'application/vnd.ufdl',
  7581. 'ulx' => 'application/x-glulx',
  7582. 'umj' => 'application/vnd.umajin',
  7583. 'unityweb' => 'application/vnd.unity',
  7584. 'uoml' => 'application/vnd.uoml+xml',
  7585. 'uri' => 'text/uri-list',
  7586. 'uris' => 'text/uri-list',
  7587. 'urls' => 'text/uri-list',
  7588. 'ustar' => 'application/x-ustar',
  7589. 'utz' => 'application/vnd.uiq.theme',
  7590. 'uu' => 'text/x-uuencode',
  7591. 'uva' => 'audio/vnd.dece.audio',
  7592. 'uvd' => 'application/vnd.dece.data',
  7593. 'uvf' => 'application/vnd.dece.data',
  7594. 'uvg' => 'image/vnd.dece.graphic',
  7595. 'uvh' => 'video/vnd.dece.hd',
  7596. 'uvi' => 'image/vnd.dece.graphic',
  7597. 'uvm' => 'video/vnd.dece.mobile',
  7598. 'uvp' => 'video/vnd.dece.pd',
  7599. 'uvs' => 'video/vnd.dece.sd',
  7600. 'uvt' => 'application/vnd.dece.ttml+xml',
  7601. 'uvu' => 'video/vnd.uvvu.mp4',
  7602. 'uvv' => 'video/vnd.dece.video',
  7603. 'uvva' => 'audio/vnd.dece.audio',
  7604. 'uvvd' => 'application/vnd.dece.data',
  7605. 'uvvf' => 'application/vnd.dece.data',
  7606. 'uvvg' => 'image/vnd.dece.graphic',
  7607. 'uvvh' => 'video/vnd.dece.hd',
  7608. 'uvvi' => 'image/vnd.dece.graphic',
  7609. 'uvvm' => 'video/vnd.dece.mobile',
  7610. 'uvvp' => 'video/vnd.dece.pd',
  7611. 'uvvs' => 'video/vnd.dece.sd',
  7612. 'uvvt' => 'application/vnd.dece.ttml+xml',
  7613. 'uvvu' => 'video/vnd.uvvu.mp4',
  7614. 'uvvv' => 'video/vnd.dece.video',
  7615. 'uvvx' => 'application/vnd.dece.unspecified',
  7616. 'uvvz' => 'application/vnd.dece.zip',
  7617. 'uvx' => 'application/vnd.dece.unspecified',
  7618. 'uvz' => 'application/vnd.dece.zip',
  7619. 'vcard' => 'text/vcard',
  7620. 'vcd' => 'application/x-cdlink',
  7621. 'vcf' => 'text/x-vcard',
  7622. 'vcg' => 'application/vnd.groove-vcard',
  7623. 'vcs' => 'text/x-vcalendar',
  7624. 'vcx' => 'application/vnd.vcx',
  7625. 'vis' => 'application/vnd.visionary',
  7626. 'viv' => 'video/vnd.vivo',
  7627. 'vob' => 'video/x-ms-vob',
  7628. 'vor' => 'application/vnd.stardivision.writer',
  7629. 'vox' => 'application/x-authorware-bin',
  7630. 'vrml' => 'model/vrml',
  7631. 'vsd' => 'application/vnd.visio',
  7632. 'vsf' => 'application/vnd.vsf',
  7633. 'vss' => 'application/vnd.visio',
  7634. 'vst' => 'application/vnd.visio',
  7635. 'vsw' => 'application/vnd.visio',
  7636. 'vtu' => 'model/vnd.vtu',
  7637. 'vxml' => 'application/voicexml+xml',
  7638. 'w3d' => 'application/x-director',
  7639. 'wad' => 'application/x-doom',
  7640. 'wav' => 'audio/x-wav',
  7641. 'wax' => 'audio/x-ms-wax',
  7642. 'wbmp' => 'image/vnd.wap.wbmp',
  7643. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  7644. 'wbxml' => 'application/vnd.wap.wbxml',
  7645. 'wcm' => 'application/vnd.ms-works',
  7646. 'wdb' => 'application/vnd.ms-works',
  7647. 'wdp' => 'image/vnd.ms-photo',
  7648. 'weba' => 'audio/webm',
  7649. 'webm' => 'video/webm',
  7650. 'webp' => 'image/webp',
  7651. 'wg' => 'application/vnd.pmi.widget',
  7652. 'wgt' => 'application/widget',
  7653. 'wks' => 'application/vnd.ms-works',
  7654. 'wm' => 'video/x-ms-wm',
  7655. 'wma' => 'audio/x-ms-wma',
  7656. 'wmd' => 'application/x-ms-wmd',
  7657. 'wmf' => 'application/x-msmetafile',
  7658. 'wml' => 'text/vnd.wap.wml',
  7659. 'wmlc' => 'application/vnd.wap.wmlc',
  7660. 'wmls' => 'text/vnd.wap.wmlscript',
  7661. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  7662. 'wmv' => 'video/x-ms-wmv',
  7663. 'wmx' => 'video/x-ms-wmx',
  7664. 'wmz' => 'application/x-ms-wmz',
  7665. 'wmz' => 'application/x-msmetafile',
  7666. 'woff' => 'application/font-woff',
  7667. 'wpd' => 'application/vnd.wordperfect',
  7668. 'wpl' => 'application/vnd.ms-wpl',
  7669. 'wps' => 'application/vnd.ms-works',
  7670. 'wqd' => 'application/vnd.wqd',
  7671. 'wri' => 'application/x-mswrite',
  7672. 'wrl' => 'model/vrml',
  7673. 'wsdl' => 'application/wsdl+xml',
  7674. 'wspolicy' => 'application/wspolicy+xml',
  7675. 'wtb' => 'application/vnd.webturbo',
  7676. 'wvx' => 'video/x-ms-wvx',
  7677. 'x32' => 'application/x-authorware-bin',
  7678. 'x3d' => 'model/x3d+xml',
  7679. 'x3db' => 'model/x3d+binary',
  7680. 'x3dbz' => 'model/x3d+binary',
  7681. 'x3dv' => 'model/x3d+vrml',
  7682. 'x3dvz' => 'model/x3d+vrml',
  7683. 'x3dz' => 'model/x3d+xml',
  7684. 'xaml' => 'application/xaml+xml',
  7685. 'xap' => 'application/x-silverlight-app',
  7686. 'xar' => 'application/vnd.xara',
  7687. 'xbap' => 'application/x-ms-xbap',
  7688. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  7689. 'xbm' => 'image/x-xbitmap',
  7690. 'xdf' => 'application/xcap-diff+xml',
  7691. 'xdm' => 'application/vnd.syncml.dm+xml',
  7692. 'xdp' => 'application/vnd.adobe.xdp+xml',
  7693. 'xdssc' => 'application/dssc+xml',
  7694. 'xdw' => 'application/vnd.fujixerox.docuworks',
  7695. 'xenc' => 'application/xenc+xml',
  7696. 'xer' => 'application/patch-ops-error+xml',
  7697. 'xfdf' => 'application/vnd.adobe.xfdf',
  7698. 'xfdl' => 'application/vnd.xfdl',
  7699. 'xht' => 'application/xhtml+xml',
  7700. 'xhtml' => 'application/xhtml+xml',
  7701. 'xhvml' => 'application/xv+xml',
  7702. 'xif' => 'image/vnd.xiff',
  7703. 'xla' => 'application/vnd.ms-excel',
  7704. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  7705. 'xlc' => 'application/vnd.ms-excel',
  7706. 'xlf' => 'application/x-xliff+xml',
  7707. 'xlm' => 'application/vnd.ms-excel',
  7708. 'xls' => 'application/vnd.ms-excel',
  7709. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  7710. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  7711. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  7712. 'xlt' => 'application/vnd.ms-excel',
  7713. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  7714. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  7715. 'xlw' => 'application/vnd.ms-excel',
  7716. 'xm' => 'audio/xm',
  7717. 'xml' => 'application/xml',
  7718. 'xo' => 'application/vnd.olpc-sugar',
  7719. 'xop' => 'application/xop+xml',
  7720. 'xpi' => 'application/x-xpinstall',
  7721. 'xpl' => 'application/xproc+xml',
  7722. 'xpm' => 'image/x-xpixmap',
  7723. 'xpr' => 'application/vnd.is-xpr',
  7724. 'xps' => 'application/vnd.ms-xpsdocument',
  7725. 'xpw' => 'application/vnd.intercon.formnet',
  7726. 'xpx' => 'application/vnd.intercon.formnet',
  7727. 'xsl' => 'application/xml',
  7728. 'xslt' => 'application/xslt+xml',
  7729. 'xsm' => 'application/vnd.syncml+xml',
  7730. 'xspf' => 'application/xspf+xml',
  7731. 'xul' => 'application/vnd.mozilla.xul+xml',
  7732. 'xvm' => 'application/xv+xml',
  7733. 'xvml' => 'application/xv+xml',
  7734. 'xwd' => 'image/x-xwindowdump',
  7735. 'xyz' => 'chemical/x-xyz',
  7736. 'xz' => 'application/x-xz',
  7737. 'yang' => 'application/yang',
  7738. 'yin' => 'application/yin+xml',
  7739. 'z1' => 'application/x-zmachine',
  7740. 'z2' => 'application/x-zmachine',
  7741. 'z3' => 'application/x-zmachine',
  7742. 'z4' => 'application/x-zmachine',
  7743. 'z5' => 'application/x-zmachine',
  7744. 'z6' => 'application/x-zmachine',
  7745. 'z7' => 'application/x-zmachine',
  7746. 'z8' => 'application/x-zmachine',
  7747. 'zaz' => 'application/vnd.zzazz.deck+xml',
  7748. 'zip' => 'application/zip',
  7749. 'zir' => 'application/vnd.zul',
  7750. 'zirz' => 'application/vnd.zul',
  7751. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  7752. );
  7753. }
  7754. // Always run this
  7755. if(strpos($_SERVER['SCRIPT_NAME'], 'check.php') == false){
  7756. dependCheck();
  7757. }