functions.php 210 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344
  1. <?php
  2. // ===================================
  3. // Define Version
  4. define('INSTALLEDVERSION', '1.42');
  5. // ===================================
  6. use Kryptonit3\Sonarr\Sonarr;
  7. use Kryptonit3\SickRage\SickRage;
  8. // Debugging output functions
  9. function debug_out($variable, $die = false) {
  10. $trace = debug_backtrace()[0];
  11. echo "<center><img height='200px' src='images/confused.png'></center>";
  12. echo "<center>Look's like something happened, here are the errors and perhaps how to fix them:</center>";
  13. echo '<pre style="white-space: pre-line; background-color: #f2f2f2; border: 2px solid black; border-radius: 5px; padding: 5px; margin: 5px;">'.$trace['file'].':'.$trace['line']."\n\n".print_r($variable, true).'</pre>';
  14. if ($die) { http_response_code(503); die(); }
  15. }
  16. // ==== Auth Plugins START ====
  17. if (function_exists('ldap_connect')) :
  18. // Pass credentials to LDAP backend
  19. function plugin_auth_ldap($username, $password) {
  20. $ldapServers = explode(',',AUTHBACKENDHOST);
  21. foreach($ldapServers as $key => $value) {
  22. // Calculate parts
  23. $digest = parse_url(trim($value));
  24. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:'ldap'));
  25. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  26. $port = (isset($digest['port'])?$digest['port']:(strtolower($scheme)=='ldap'?389:636));
  27. // Reassign
  28. $ldapServers[$key] = $scheme.'://'.$host.':'.$port;
  29. }
  30. // returns true or false
  31. $ldap = ldap_connect(implode(' ',$ldapServers));
  32. if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
  33. writeLog("success", "LDAP authentication success");
  34. return true;
  35. } else {
  36. writeLog("error", "LDPA could not authenticate");
  37. return false;
  38. }
  39. writeLog("error", "LDPA could not authenticate");
  40. return false;
  41. }
  42. else :
  43. // Ldap Auth Missing Dependancy
  44. function plugin_auth_ldap_disabled() {
  45. return 'LDAP - Disabled (Dependancy: php-ldap missing!)';
  46. }
  47. endif;
  48. // Pass credentials to FTP backend
  49. function plugin_auth_ftp($username, $password) {
  50. // Calculate parts
  51. $digest = parse_url(AUTHBACKENDHOST);
  52. $scheme = strtolower((isset($digest['scheme'])?$digest['scheme']:(function_exists('ftp_ssl_connect')?'ftps':'ftp')));
  53. $host = (isset($digest['host'])?$digest['host']:(isset($digest['path'])?$digest['path']:''));
  54. $port = (isset($digest['port'])?$digest['port']:21);
  55. // Determine Connection Type
  56. if ($scheme == 'ftps') {
  57. $conn_id = ftp_ssl_connect($host, $port, 20);
  58. } elseif ($scheme == 'ftp') {
  59. $conn_id = ftp_connect($host, $port, 20);
  60. } else {
  61. debug_out('Invalid FTP scheme. Use ftp or ftps');
  62. writeLog("error", "invalid FTP scheme");
  63. return false;
  64. }
  65. // Check if valid FTP connection
  66. if ($conn_id) {
  67. // Attempt login
  68. @$login_result = ftp_login($conn_id, $username, $password);
  69. ftp_close($conn_id);
  70. // Return Result
  71. if ($login_result) {
  72. writeLog("success", "$username authenticated");
  73. return true;
  74. } else {
  75. writeLog("error", "$username could not authenticate");
  76. return false;
  77. }
  78. } else {
  79. return false;
  80. }
  81. return false;
  82. }
  83. // Pass credentials to Emby Backend
  84. function plugin_auth_emby_local($username, $password) {
  85. $embyAddress = qualifyURL(EMBYURL);
  86. $headers = array(
  87. 'Authorization'=> 'MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="None", Device="Organizr", DeviceId="xxx", Version="1.0.0.0"',
  88. 'Content-Type' => 'application/json',
  89. );
  90. $body = array(
  91. 'Username' => $username,
  92. 'Password' => sha1($password),
  93. 'PasswordMd5' => md5($password),
  94. );
  95. $response = post_router($embyAddress.'/Users/AuthenticateByName', $body, $headers);
  96. if (isset($response['content'])) {
  97. $json = json_decode($response['content'], true);
  98. if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['HasPassword'] == true) {
  99. // Login Success - Now Logout Emby Session As We No Longer Need It
  100. $headers = array(
  101. 'X-Mediabrowser-Token' => $json['AccessToken'],
  102. );
  103. $response = post_router($embyAddress.'/Sessions/Logout', array(), $headers);
  104. return true;
  105. }
  106. }
  107. return false;
  108. }
  109. if (function_exists('curl_version')) :
  110. // Authenticate Against Emby Local (first) and Emby Connect
  111. function plugin_auth_emby_all($username, $password) {
  112. $localResult = plugin_auth_emby_local($username, $password);
  113. if ($localResult) {
  114. return $localResult;
  115. } else {
  116. return plugin_auth_emby_connect($username, $password);
  117. }
  118. }
  119. // Authenicate against emby connect
  120. function plugin_auth_emby_connect($username, $password) {
  121. $embyAddress = qualifyURL(EMBYURL);
  122. // Get A User
  123. $connectId = '';
  124. $userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
  125. if (is_array($userIds)) {
  126. foreach ($userIds as $key => $value) { // Scan for this user
  127. if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
  128. if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
  129. $connectId = $value['ConnectUserId'];
  130. break;
  131. }
  132. }
  133. }
  134. if ($connectId) {
  135. $connectURL = 'https://connect.emby.media/service/user/authenticate';
  136. $headers = array(
  137. 'Accept'=> 'application/json',
  138. 'Content-Type' => 'application/x-www-form-urlencoded',
  139. );
  140. $body = array(
  141. 'nameOrEmail' => $username,
  142. 'rawpw' => $password,
  143. );
  144. $result = curl_post($connectURL, $body, $headers);
  145. if (isset($result['content'])) {
  146. $json = json_decode($result['content'], true);
  147. if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
  148. return array(
  149. 'email' => $json['User']['Email'],
  150. 'image' => $json['User']['ImageUrl'],
  151. );
  152. }
  153. }
  154. }
  155. }
  156. return false;
  157. }
  158. // Pass credentials to Plex Backend
  159. function plugin_auth_plex($username, $password) {
  160. // Quick out
  161. if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
  162. writeLog("success", $username." authenticated by plex");
  163. return true;
  164. }
  165. //Get User List
  166. $userURL = 'https://plex.tv/pms/friends/all';
  167. $userHeaders = array(
  168. 'Authorization' => 'Basic '.base64_encode(PLEXUSERNAME.':'.PLEXPASSWORD),
  169. );
  170. $userXML = simplexml_load_string(curl_get($userURL, $userHeaders));
  171. if (is_array($userXML) || is_object($userXML)) {
  172. $isUser = false;
  173. $usernameLower = strtolower($username);
  174. foreach($userXML AS $child) {
  175. if(isset($child['username']) && strtolower($child['username']) == $usernameLower) {
  176. $isUser = true;
  177. writeLog("success", $usernameLower." was found in plex friends list");
  178. break;
  179. }
  180. }
  181. if ($isUser) {
  182. //Login User
  183. $connectURL = 'https://plex.tv/users/sign_in.json';
  184. $headers = array(
  185. 'Accept'=> 'application/json',
  186. 'Content-Type' => 'application/x-www-form-urlencoded',
  187. 'X-Plex-Product' => 'Organizr',
  188. 'X-Plex-Version' => '1.0',
  189. 'X-Plex-Client-Identifier' => '01010101-10101010',
  190. );
  191. $body = array(
  192. 'user[login]' => $username,
  193. 'user[password]' => $password,
  194. );
  195. $result = curl_post($connectURL, $body, $headers);
  196. if (isset($result['content'])) {
  197. $json = json_decode($result['content'], true);
  198. if (is_array($json) && isset($json['user']) && isset($json['user']['username']) && strtolower($json['user']['username']) == $usernameLower) {
  199. writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
  200. return array(
  201. 'email' => $json['user']['email'],
  202. 'image' => $json['user']['thumb']
  203. );
  204. }
  205. }
  206. }else{
  207. writeLog("error", "$username is not an authorized PLEX user or entered invalid password");
  208. }
  209. }else{
  210. writeLog("error", "error occured logging into plex might want to check curl.cainfo=/path/to/downloaded/cacert.pem in php.ini");
  211. }
  212. return false;
  213. }
  214. else :
  215. // Plex Auth Missing Dependancy
  216. function plugin_auth_plex_disabled() {
  217. return 'Plex - Disabled (Dependancy: php-curl missing!)';
  218. }
  219. // Emby Connect Auth Missing Dependancy
  220. function plugin_auth_emby_connect_disabled() {
  221. return 'Emby Connect - Disabled (Dependancy: php-curl missing!)';
  222. }
  223. // Emby Both Auth Missing Dependancy
  224. function plugin_auth_emby_both_disabled() {
  225. return 'Emby Both - Disabled (Dependancy: php-curl missing!)';
  226. }
  227. endif;
  228. // ==== Auth Plugins END ====
  229. // ==== General Class Definitions START ====
  230. class setLanguage {
  231. private $language = null;
  232. private $langCode = null;
  233. function __construct($language = false) {
  234. // Default
  235. if (!$language) {
  236. $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
  237. }
  238. if (!file_exists("lang/{$language}.ini")) {
  239. $language = 'en';
  240. }
  241. $this->langCode = $language;
  242. $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW);
  243. if (file_exists("lang/{$language}.cust.ini")) {
  244. foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) {
  245. $this->language[$k] = $v;
  246. }
  247. }
  248. }
  249. public function getLang() {
  250. return $this->langCode;
  251. }
  252. public function translate($originalWord) {
  253. $getArg = func_num_args();
  254. if ($getArg > 1) {
  255. $allWords = func_get_args();
  256. array_shift($allWords);
  257. } else {
  258. $allWords = array();
  259. }
  260. $translatedWord = isset($this->language[$originalWord]) ? $this->language[$originalWord] : null;
  261. if (!$translatedWord) {
  262. return ucwords(str_replace("_", " ", strtolower($originalWord)));
  263. }
  264. $translatedWord = htmlspecialchars($translatedWord, ENT_QUOTES);
  265. return vsprintf($translatedWord, $allWords);
  266. }
  267. }
  268. $language = new setLanguage;
  269. // ==== General Class Definitions END ====
  270. // Direct request to curl if it exists, otherwise handle if not HTTPS
  271. function post_router($url, $data, $headers = array(), $referer='') {
  272. if (function_exists('curl_version')) {
  273. return curl_post($url, $data, $headers, $referer);
  274. } else {
  275. return post_request($url, $data, $headers, $referer);
  276. }
  277. }
  278. if (function_exists('curl_version')) :
  279. // Curl Post
  280. function curl_post($url, $data, $headers = array(), $referer='') {
  281. // Initiate cURL
  282. $curlReq = curl_init($url);
  283. // As post request
  284. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "POST");
  285. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  286. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  287. if(localURL($url)){
  288. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  289. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  290. }
  291. // Format Data
  292. switch (isset($headers['Content-Type'])?$headers['Content-Type']:'') {
  293. case 'application/json':
  294. curl_setopt($curlReq, CURLOPT_POSTFIELDS, json_encode($data));
  295. break;
  296. case 'application/x-www-form-urlencoded';
  297. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  298. break;
  299. default:
  300. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  301. curl_setopt($curlReq, CURLOPT_POSTFIELDS, http_build_query($data));
  302. }
  303. // Format Headers
  304. $cHeaders = array();
  305. foreach ($headers as $k => $v) {
  306. $cHeaders[] = $k.': '.$v;
  307. }
  308. if (count($cHeaders)) {
  309. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  310. }
  311. // Execute
  312. $result = curl_exec($curlReq);
  313. $httpcode = curl_getinfo($curlReq);
  314. // Close
  315. curl_close($curlReq);
  316. // Return
  317. return array('content'=>$result, 'http_code'=>$httpcode);
  318. }
  319. //Curl Get Function
  320. function curl_get($url, $headers = array()) {
  321. // Initiate cURL
  322. $curlReq = curl_init($url);
  323. // As post request
  324. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET");
  325. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  326. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  327. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  328. if(localURL($url)){
  329. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  330. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  331. }
  332. // Format Headers
  333. $cHeaders = array();
  334. foreach ($headers as $k => $v) {
  335. $cHeaders[] = $k.': '.$v;
  336. }
  337. if (count($cHeaders)) {
  338. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  339. }
  340. // Execute
  341. $result = curl_exec($curlReq);
  342. // Close
  343. curl_close($curlReq);
  344. // Return
  345. return $result;
  346. }
  347. //Curl Delete Function
  348. function curl_delete($url, $headers = array()) {
  349. // Initiate cURL
  350. $curlReq = curl_init($url);
  351. // As post request
  352. curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "DELETE");
  353. curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true);
  354. curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5);
  355. curl_setopt($curlReq, CURLOPT_CAINFO, getCert());
  356. if(localURL($url)){
  357. curl_setopt($curlReq, CURLOPT_SSL_VERIFYHOST, 0);
  358. curl_setopt($curlReq, CURLOPT_SSL_VERIFYPEER, 0);
  359. }
  360. // Format Headers
  361. $cHeaders = array();
  362. foreach ($headers as $k => $v) {
  363. $cHeaders[] = $k.': '.$v;
  364. }
  365. if (count($cHeaders)) {
  366. curl_setopt($curlReq, CURLOPT_HTTPHEADER, $cHeaders);
  367. }
  368. // Execute
  369. $result = curl_exec($curlReq);
  370. $httpcode = curl_getinfo($curlReq);
  371. // Close
  372. curl_close($curlReq);
  373. // Return
  374. return array('content'=>$result, 'http_code'=>$httpcode);
  375. }
  376. endif;
  377. //Case-Insensitive Function
  378. function in_arrayi($needle, $haystack) {
  379. return in_array(strtolower($needle), array_map('strtolower', $haystack));
  380. }
  381. // HTTP post request (Removes need for curl, probably useless)
  382. function post_request($url, $data, $headers = array(), $referer='') {
  383. // Adapted from http://stackoverflow.com/a/28387011/6810513
  384. // Convert the data array into URL Parameters like a=b&foo=bar etc.
  385. if (isset($headers['Content-Type'])) {
  386. switch ($headers['Content-Type']) {
  387. case 'application/json':
  388. $data = json_encode($data);
  389. break;
  390. case 'application/x-www-form-urlencoded':
  391. $data = http_build_query($data);
  392. break;
  393. }
  394. } else {
  395. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  396. $data = http_build_query($data);
  397. }
  398. // parse the given URL
  399. $urlDigest = parse_url($url);
  400. // extract host and path:
  401. $host = $urlDigest['host'];
  402. $path = $urlDigest['path'];
  403. if ($urlDigest['scheme'] != 'http') {
  404. die('Error: Only HTTP request are supported, please use cURL to add HTTPS support! ('.$urlDigest['scheme'].'://'.$host.')');
  405. }
  406. // open a socket connection on port 80 - timeout: 30 sec
  407. $fp = fsockopen($host, (isset($urlDigest['port'])?':'.$urlDigest['port']:80), $errno, $errstr, 30);
  408. if ($fp){
  409. // send the request headers:
  410. fputs($fp, "POST $path HTTP/1.1\r\n");
  411. fputs($fp, "Host: $host\r\n");
  412. if ($referer != '')
  413. fputs($fp, "Referer: $referer\r\n");
  414. fputs($fp, "Content-length: ". strlen($data) ."\r\n");
  415. foreach($headers as $k => $v) {
  416. fputs($fp, $k.": ".$v."\r\n");
  417. }
  418. fputs($fp, "Connection: close\r\n\r\n");
  419. fputs($fp, $data);
  420. $result = '';
  421. while(!feof($fp)) {
  422. // receive the results of the request
  423. $result .= fgets($fp, 128);
  424. }
  425. }
  426. else {
  427. return array(
  428. 'status' => 'err',
  429. 'error' => "$errstr ($errno)"
  430. );
  431. }
  432. // close the socket connection:
  433. fclose($fp);
  434. // split the result header from the content
  435. $result = explode("\r\n\r\n", $result, 2);
  436. $header = isset($result[0]) ? $result[0] : '';
  437. $content = isset($result[1]) ? $result[1] : '';
  438. // return as structured array:
  439. return array(
  440. 'status' => 'ok',
  441. 'header' => $header,
  442. 'content' => $content,
  443. );
  444. }
  445. // Format item from Emby for Carousel
  446. function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) {
  447. // Static Height
  448. $height = 444;
  449. // Get Item Details
  450. $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
  451. if (substr_count(EMBYURL, ':') == 2) {
  452. $URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  453. }else{
  454. $URL = EMBYURL."/web/itemdetails.html?id=".$itemDetails['Id'];
  455. }
  456. //$URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
  457. switch ($itemDetails['Type']) {
  458. case 'Episode':
  459. $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
  460. $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']);
  461. $width = 300;
  462. $style = '';
  463. $image = 'slick-image-tall';
  464. if(!$nowPlaying){
  465. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  466. $key = $itemDetails['Id'] . "-list";
  467. }else{
  468. $height = 281;
  469. $width = 500;
  470. $imageId = isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  471. $imageType = isset($itemDetails['ParentThumbItemId']) ? "Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  472. $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
  473. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  474. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  475. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  476. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  477. $stream = $moreInfo['PlayState']['PlayMethod'];
  478. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  479. $id = $moreInfo['DeviceId'];
  480. $streamInfo = buildStream(array(
  481. 'platform' => (string) $moreInfo['Client'],
  482. 'device' => (string) $moreInfo['DeviceName'],
  483. 'stream' => "&nbsp;".streamType($stream),
  484. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  485. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  486. ));
  487. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  488. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$itemDetails['Name'].'</h5>';
  489. $bottomTitle = '<small class="zero-m">S'.$itemDetails['ParentIndexNumber'].' · E'.$itemDetails['IndexNumber'].'</small>';
  490. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  491. }
  492. break;
  493. case 'MusicAlbum':
  494. case 'Audio':
  495. $title = $itemDetails['Name'];
  496. $imageId = $itemDetails['Id'];
  497. $width = 444;
  498. $style = '';
  499. $image = 'slick-image-short';
  500. if(!$nowPlaying){
  501. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  502. $key = $itemDetails['Id'] . "-list";
  503. }else{
  504. $height = 281;
  505. $width = 500;
  506. $imageId = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
  507. $imageType = (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
  508. $key = (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : "no-np") . "-np";
  509. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  510. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  511. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  512. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  513. $stream = $moreInfo['PlayState']['PlayMethod'];
  514. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  515. $id = $moreInfo['DeviceId'];
  516. $streamInfo = buildStream(array(
  517. 'platform' => (string) $moreInfo['Client'],
  518. 'device' => (string) $moreInfo['DeviceName'],
  519. 'stream' => "&nbsp;".streamType($stream),
  520. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  521. ));
  522. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  523. $topTitle = '<h5 class="text-center zero-m elip">'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'</h5>';
  524. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  525. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  526. }
  527. break;
  528. case 'TvChannel':
  529. $title = $itemDetails['CurrentProgram']['Name'];
  530. $imageId = $itemDetails['Id'];
  531. $width = 300;
  532. $style = '';
  533. $image = 'slick-image-tall';
  534. if(!$nowPlaying){
  535. $imageType = "Primary";
  536. $key = $itemDetails['Id'] . "-list";
  537. }else{
  538. $height = 281;
  539. $width = 500;
  540. $imageType = "Thumb";
  541. $key = $itemDetails['Id'] . "-np";
  542. $useImage = "images/livetv.png";
  543. $watched = "0";
  544. $stream = $moreInfo['PlayState']['PlayMethod'];
  545. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  546. $id = $moreInfo['DeviceId'];
  547. $streamInfo = buildStream(array(
  548. 'platform' => (string) $moreInfo['Client'],
  549. 'device' => (string) $moreInfo['DeviceName'],
  550. 'stream' => "&nbsp;".streamType($stream),
  551. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  552. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  553. ));
  554. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  555. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  556. $bottomTitle = '<small class="zero-m">'.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].'</small>';
  557. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  558. }
  559. break;
  560. default:
  561. $title = $itemDetails['Name'];
  562. $imageId = $itemDetails['Id'];
  563. $width = 300;
  564. $style = '';
  565. $image = 'slick-image-tall';
  566. if(!$nowPlaying){
  567. $imageType = (isset($itemDetails['ImageTags']['Primary']) ? "Primary" : false);
  568. $key = $itemDetails['Id'] . "-list";
  569. }else{
  570. $height = 281;
  571. $width = 500;
  572. $imageType = isset($itemDetails['ImageTags']['Thumb']) ? "Thumb" : (isset($itemDetails['BackdropImageTags']) ? "Backdrop" : false);
  573. $key = $itemDetails['Id'] . "-np";
  574. $elapsed = $moreInfo['PlayState']['PositionTicks'];
  575. $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
  576. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  577. //$transcoded = floor($item->TranscodeSession['progress']- $watched);
  578. $stream = $moreInfo['PlayState']['PlayMethod'];
  579. $user = $role == "admin" ? $moreInfo['UserName'] : "";
  580. $id = $moreInfo['DeviceId'];
  581. $streamInfo = buildStream(array(
  582. 'platform' => (string) $moreInfo['Client'],
  583. 'device' => (string) $moreInfo['DeviceName'],
  584. 'stream' => "&nbsp;".streamType($stream),
  585. 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"),
  586. 'audio' => "&nbsp;".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"),
  587. ));
  588. $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play");
  589. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  590. $bottomTitle = '<small class="zero-m">'.$moreInfo['NowPlayingItem']['ProductionYear'].'</small>';
  591. if($showNames == "true"){ $bottomTitle .= '</small><small class="zero-m pull-right">'.$user.'</small>'; }
  592. }
  593. }
  594. // If No Overview
  595. if (!isset($itemDetails['Overview'])) {
  596. $itemDetails['Overview'] = '';
  597. }
  598. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  599. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  600. $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.'';
  601. }
  602. if($nowPlaying){
  603. if(!$imageType){ $image_url = "images/no-np.png"; $key = "no-np"; }
  604. if(!$imageId){ $image_url = "images/no-np.png"; $key = "no-np"; }
  605. }else{
  606. if(!$imageType){ $image_url = "images/no-list.png"; $key = "no-list"; }
  607. if(!$imageId){ $image_url = "images/no-list.png"; $key = "no-list"; }
  608. }
  609. if(isset($useImage)){ $image_url = $useImage; }
  610. // Assemble Item And Cache Into Array
  611. if($nowPlaying){
  612. //prettyPrint($itemDetails);
  613. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$URL.'" target="_blank"><img style="width: 100%; display:inherit;" src="'.$image_url.'" alt="'.$itemDetails['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: 0%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  614. }else{
  615. return '<div class="item-'.$itemDetails['Type'].'"><a href="'.$URL.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
  616. }
  617. }
  618. // Format item from Plex for Carousel
  619. function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
  620. // Static Height
  621. $height = 444;
  622. $playlist = ($playlist) ? " playlist-$playlist" : "";
  623. switch ($item['type']) {
  624. case 'season':
  625. $title = $item['parentTitle'];
  626. $summary = $item['parentSummary'];
  627. $width = 300;
  628. $image = 'slick-image-tall';
  629. $style = '';
  630. if(!$nowPlaying){
  631. $thumb = $item['thumb'];
  632. $key = $item['ratingKey'] . "-list";
  633. }else {
  634. $height = 281;
  635. $width = 500;
  636. $thumb = $item['art'];
  637. $key = $item['ratingKey'] . "-np";
  638. $elapsed = $item['viewOffset'];
  639. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  640. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  641. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  642. $stream = $item->Media->Part->Stream['decision'];
  643. $user = $role == "admin" ? $item->User['title'] : "";
  644. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  645. $streamInfo = buildStream(array(
  646. 'platform' => (string) $item->Player['platform'],
  647. 'device' => (string) $item->Player['device'],
  648. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  649. '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'].")",
  650. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  651. ));
  652. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  653. }
  654. break;
  655. case 'episode':
  656. $title = $item['grandparentTitle'];
  657. $summary = $item['title'];
  658. $width = 300;
  659. $image = 'slick-image-tall';
  660. $style = '';
  661. if(!$nowPlaying){
  662. $thumb = ($item['parentThumb'] ? $item['parentThumb'] : $item['grandparentThumb']);
  663. $key = $item['ratingKey'] . "-list";
  664. }else {
  665. $height = 281;
  666. $width = 500;
  667. $thumb = $item['art'];
  668. $key = $item['ratingKey'] . "-np";
  669. $elapsed = $item['viewOffset'];
  670. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  671. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  672. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  673. $stream = $item->Media->Part->Stream['decision'];
  674. $user = $role == "admin" ? $item->User['title'] : "";
  675. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  676. $streamInfo = buildStream(array(
  677. 'platform' => (string) $item->Player['platform'],
  678. 'device' => (string) $item->Player['device'],
  679. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  680. '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'].")",
  681. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  682. ));
  683. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  684. $topTitle = '<h5 class="text-center zero-m elip">'.$title.' - '.$item['title'].'</h5>';
  685. $bottomTitle = '<small class="zero-m">S'.$item['parentIndex'].' · E'.$item['index'].'</small>';
  686. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  687. }
  688. break;
  689. case 'clip':
  690. $title = $item['title'];
  691. $summary = $item['summary'];
  692. $width = 300;
  693. $image = 'slick-image-tall';
  694. $style = '';
  695. if(!$nowPlaying){
  696. $thumb = $item['thumb'];
  697. $key = $item['ratingKey'] . "-list";
  698. }else {
  699. $height = 281;
  700. $width = 500;
  701. $thumb = $item['art'];
  702. $key = isset($item['ratingKey']) ? $item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  703. $useImage = (isset($item['live']) ? "images/livetv.png" : null);
  704. $extraInfo = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  705. $elapsed = $item['viewOffset'];
  706. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  707. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  708. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  709. $stream = $item->Media->Part->Stream['decision'];
  710. $user = $role == "admin" ? $item->User['title'] : "";
  711. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  712. $streamInfo = buildStream(array(
  713. 'platform' => (string) $item->Player['platform'],
  714. 'device' => (string) $item->Player['device'],
  715. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  716. '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'].")",
  717. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  718. ));
  719. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  720. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  721. $bottomTitle = '<small class="zero-m">'.$extraInfo.'</small>';
  722. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  723. }
  724. break;
  725. case 'album':
  726. case 'track':
  727. $title = $item['parentTitle'];
  728. $summary = $item['title'];
  729. $image = 'slick-image-short';
  730. $style = 'left: 160px !important;';
  731. $item['ratingKey'] = $item['parentRatingKey'];
  732. if(!$nowPlaying){
  733. $width = 444;
  734. $thumb = $item['thumb'];
  735. $key = $item['ratingKey'] . "-list";
  736. }else {
  737. $height = 281;
  738. $width = 500;
  739. $thumb = $item['art'];
  740. $key = $item['ratingKey'] . "-np";
  741. $elapsed = $item['viewOffset'];
  742. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  743. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  744. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  745. $stream = $item->Media->Part->Stream['decision'];
  746. $user = $role == "admin" ? $item->User['title'] : "";
  747. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  748. $streamInfo = buildStream(array(
  749. 'platform' => (string) $item->Player['platform'],
  750. 'device' => (string) $item->Player['device'],
  751. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  752. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['channels']."ch)",
  753. ));
  754. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  755. $topTitle = '<h5 class="text-center zero-m elip">'.$item['grandparentTitle'].' - '.$item['title'].'</h5>';
  756. $bottomTitle = '<small class="zero-m">'.$title.'</small>';
  757. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  758. }
  759. break;
  760. default:
  761. $title = $item['title'];
  762. $summary = $item['summary'];
  763. $image = 'slick-image-tall';
  764. $style = '';
  765. if(!$nowPlaying){
  766. $width = 300;
  767. $thumb = $item['thumb'];
  768. $key = $item['ratingKey'] . "-list";
  769. }else {
  770. $height = 281;
  771. $width = 500;
  772. $thumb = $item['art'];
  773. $key = $item['ratingKey'] . "-np";
  774. $elapsed = $item['viewOffset'];
  775. $duration = ($item['duration']) ? $item['duration'] : $item->Media['duration'];
  776. $watched = (!empty($elapsed) ? floor(($elapsed / $duration) * 100) : 0);
  777. $transcoded = floor($item->TranscodeSession['progress']- $watched);
  778. $stream = $item->Media->Part->Stream['decision'];
  779. $user = $role == "admin" ? $item->User['title'] : "";
  780. $id = str_replace('"', '', $item->Player['machineIdentifier']);
  781. $streamInfo = buildStream(array(
  782. 'platform' => (string) $item->Player['platform'],
  783. 'device' => (string) $item->Player['device'],
  784. 'stream' => "&nbsp;".streamType($item->Media->Part['decision']),
  785. 'video' => streamType($item->Media->Part->Stream[0]['decision'])." (".$item->Media->Part->Stream[0]['codec'].") (".$item->Media->Part->Stream[0]['width']."x".$item->Media->Part->Stream[0]['height'].")",
  786. 'audio' => "&nbsp;".streamType($item->Media->Part->Stream[1]['decision'])." (".$item->Media->Part->Stream[1]['codec'].") (".$item->Media->Part->Stream[1]['channels']."ch)",
  787. ));
  788. $state = (($item->Player['state'] == "paused") ? "pause" : "play");
  789. $topTitle = '<h5 class="text-center zero-m elip">'.$title.'</h5>';
  790. $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
  791. if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
  792. }
  793. }
  794. if (substr_count(PLEXURL, '.') != 2) {
  795. $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  796. }else{
  797. $address = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
  798. }
  799. // If No Overview
  800. if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
  801. if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; }
  802. if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) {
  803. $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';
  804. }
  805. if($nowPlaying){
  806. if(!$thumb){ $image_url = "images/no-np.png"; $key = "no-np"; }
  807. }else{
  808. if(!$thumb){ $image_url = "images/no-list.png"; $key = "no-list"; }
  809. }
  810. if(isset($useImage)){ $image_url = $useImage; }
  811. $openTab = (PLEXTABNAME) ? "true" : "false";
  812. // Assemble Item And Cache Into Array
  813. if($nowPlaying){
  814. return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img style="width: 100%; display:inherit;" src="'.$image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
  815. }else{
  816. return '<div class="item-'.$item['type'].$playlist.'"><a class="openTab" extraTitle="'.$title.'" extraType="'.$item['type'].'" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
  817. }
  818. }
  819. //$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  820. //Recent Added
  821. function outputRecentAdded($header, $items, $script = false, $array) {
  822. $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">';
  823. if(preg_grep("/item-movie/", $items)){
  824. $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>';
  825. }
  826. if(preg_grep("/item-season/", $items)){
  827. $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>';
  828. }
  829. if(preg_grep("/item-album/", $items)){
  830. $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>';
  831. }
  832. $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>';
  833. $hideMenu .= '</ul></div></div>';
  834. // If None Populate Empty Item
  835. if (!count($items)) {
  836. return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Media Found</p></div>';
  837. }else{
  838. $className = str_replace(' ', '', $header);
  839. return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 id="recentContent-title" style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-recent" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
  840. }
  841. }
  842. // Create Carousel
  843. function outputNowPlaying($header, $size, $type, $items, $script = false) {
  844. // If None Populate Empty Item
  845. if (!count($items)) {
  846. return '<div id=streamz></div>'.($script?'<script>'.$script.'</script>':'');
  847. }else{
  848. return '<div id=streamz><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  849. }
  850. }
  851. // Get Now Playing Streams From Emby
  852. function getEmbyStreams($size, $showNames, $role) {
  853. $address = qualifyURL(EMBYURL);
  854. $api = json_decode(@file_get_contents($address.'/Sessions?api_key='.EMBYTOKEN),true);
  855. if (!is_array($api)) { return 'Could not load!'; }
  856. $playingItems = array();
  857. foreach($api as $key => $value) {
  858. if (isset($value['NowPlayingItem'])) {
  859. $playingItems[] = resolveEmbyItem($address, EMBYTOKEN, $value['NowPlayingItem'], true, $showNames, $role, $value);
  860. }
  861. }
  862. return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY'), $size, 'streams-emby', $playingItems, "
  863. setInterval(function() {
  864. $('<div></div>').load('ajax.php?a=emby-streams',function() {
  865. var element = $(this).find('[id]');
  866. var loadedID = element.attr('id');
  867. $('#'+loadedID).replaceWith(element);
  868. console.log('Loaded updated: '+loadedID);
  869. });
  870. }, 15000);
  871. ");
  872. }
  873. // Get Now Playing Streams From Plex
  874. function getPlexStreams($size, $showNames, $role){
  875. $address = qualifyURL(PLEXURL);
  876. // Perform API requests
  877. $api = @curl_get($address."/status/sessions?X-Plex-Token=".PLEXTOKEN);
  878. $api = simplexml_load_string($api);
  879. if (is_array($api) || is_object($api)){
  880. if (!$api->head->title){
  881. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  882. if (!$getServer) { return 'Could not load!'; }
  883. // Identify the local machine
  884. $gotServer = $getServer['machineIdentifier'];
  885. $items = array();
  886. foreach($api AS $child) {
  887. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, true, $showNames, $role);
  888. }
  889. return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, "
  890. setInterval(function() {
  891. $('<div></div>').load('ajax.php?a=plex-streams',function() {
  892. var element = $(this).find('[id]');
  893. var loadedID = element.attr('id');
  894. $('#'+loadedID).replaceWith(element);
  895. console.log('Loaded updated: '+loadedID);
  896. });
  897. }, 15000);
  898. ");
  899. }else{
  900. writeLog("error", "PLEX STREAM ERROR: could not connect - check token - if HTTPS, is cert valid");
  901. }
  902. }else{
  903. writeLog("error", "PLEX STREAM ERROR: could not connect - check URL - if HTTPS, is cert valid");
  904. }
  905. }
  906. // Get Recent Content From Emby
  907. function getEmbyRecent($array) {
  908. $address = qualifyURL(EMBYURL);
  909. $header = translate('RECENT_CONTENT');
  910. // Currently Logged In User
  911. $username = false;
  912. if (isset($GLOBALS['USER'])) {
  913. $username = strtolower($GLOBALS['USER']->username);
  914. }
  915. // Get A User
  916. $userIds = json_decode(@file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
  917. if (!is_array($userIds)) { return 'Could not load!'; }
  918. $showPlayed = true;
  919. foreach ($userIds as $value) { // Scan for admin user
  920. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  921. $userId = $value['Id'];
  922. }
  923. if ($username && strtolower($value['Name']) == $username) {
  924. $userId = $value['Id'];
  925. $showPlayed = false;
  926. break;
  927. }
  928. }
  929. // Get the latest Items
  930. $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
  931. // For Each Item In Category
  932. $items = array();
  933. foreach ($latest as $k => $v) {
  934. $type = (string) $v['Type'];
  935. if(@$array[$type] == "true"){
  936. $items[] = resolveEmbyItem($address, EMBYTOKEN, $v, false, false, false);
  937. }
  938. }
  939. $array["movie"] = $array["Movie"];
  940. $array["season"] = $array["Episode"];
  941. $array["album"] = $array["MusicAlbum"];
  942. unset($array["Movie"]);
  943. unset($array["Episode"]);
  944. unset($array["MusicAlbum"]);
  945. unset($array["Series"]);
  946. return outputRecentAdded($header, $items, "", $array);
  947. }
  948. // Get Recent Content From Plex
  949. function getPlexRecent($array){
  950. $address = qualifyURL(PLEXURL);
  951. $header = translate('RECENT_CONTENT');
  952. // Perform Requests
  953. $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
  954. $api = simplexml_load_string($api);
  955. if (is_array($api) || is_object($api)){
  956. if (!$api->head->title){
  957. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  958. if (!$getServer) { return 'Could not load!'; }
  959. // Identify the local machine
  960. $gotServer = $getServer['machineIdentifier'];
  961. $items = array();
  962. foreach($api AS $child) {
  963. $type = (string) $child['type'];
  964. if($array[$type] == "true"){
  965. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false, false);
  966. }
  967. }
  968. return outputRecentAdded($header, $items, "", $array);
  969. }else{
  970. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check token - if HTTPS, is cert valid");
  971. }
  972. }else{
  973. writeLog("error", "PLEX RECENT-ITEMS ERROR: could not connect - check URL - if HTTPS, is cert valid");
  974. }
  975. }
  976. // Get Image From Emby
  977. function getEmbyImage() {
  978. $embyAddress = qualifyURL(EMBYURL);
  979. if (!file_exists('images/cache')) {
  980. mkdir('images/cache', 0777, true);
  981. }
  982. $itemId = $_GET['img'];
  983. $key = $_GET['key'];
  984. $itemType = $_GET['type'];
  985. $imgParams = array();
  986. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  987. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  988. if(isset($itemId)) {
  989. $image_src = $embyAddress . '/Items/'.$itemId.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  990. $cachefile = 'images/cache/'.$key.'.jpg';
  991. $cachetime = 604800;
  992. // Serve from the cache if it is younger than $cachetime
  993. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  994. header("Content-type: image/jpeg");
  995. @readfile($cachefile);
  996. exit;
  997. }
  998. ob_start(); // Start the output buffer
  999. header('Content-type: image/jpeg');
  1000. @readfile($image_src);
  1001. // Cache the output to a file
  1002. $fp = fopen($cachefile, 'wb');
  1003. fwrite($fp, ob_get_contents());
  1004. fclose($fp);
  1005. ob_end_flush(); // Send the output to the browser
  1006. die();
  1007. } else {
  1008. debug_out('Invalid Request',1);
  1009. }
  1010. }
  1011. // Get Image From Plex
  1012. function getPlexImage() {
  1013. $plexAddress = qualifyURL(PLEXURL);
  1014. if (!file_exists('images/cache')) {
  1015. mkdir('images/cache', 0777, true);
  1016. }
  1017. $image_url = $_GET['img'];
  1018. $key = $_GET['key'];
  1019. $image_height = $_GET['height'];
  1020. $image_width = $_GET['width'];
  1021. if(isset($image_url) && isset($image_height) && isset($image_width)) {
  1022. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
  1023. $cachefile = 'images/cache/'.$key.'.jpg';
  1024. $cachetime = 604800;
  1025. // Serve from the cache if it is younger than $cachetime
  1026. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  1027. header("Content-type: image/jpeg");
  1028. @readfile($cachefile);
  1029. exit;
  1030. }
  1031. ob_start(); // Start the output buffer
  1032. header('Content-type: image/jpeg');
  1033. @readfile($image_src);
  1034. // Cache the output to a file
  1035. $fp = fopen($cachefile, 'wb');
  1036. fwrite($fp, ob_get_contents());
  1037. fclose($fp);
  1038. ob_end_flush(); // Send the output to the browser
  1039. die();
  1040. } else {
  1041. echo "Invalid Plex Request";
  1042. }
  1043. }
  1044. // Simplier access to class
  1045. function translate($string) {
  1046. if (isset($GLOBALS['language'])) {
  1047. return $GLOBALS['language']->translate($string);
  1048. } else {
  1049. return '!Translations Not Loaded!';
  1050. }
  1051. }
  1052. // Generate Random string
  1053. function randString($length = 10, $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  1054. $tmp = '';
  1055. for ($i = 0; $i < $length; $i++) {
  1056. $tmp .= substr(str_shuffle($chars), 0, 1);
  1057. }
  1058. return $tmp;
  1059. }
  1060. // Create config file in the return syntax
  1061. function createConfig($array, $path = 'config/config.php', $nest = 0) {
  1062. // Define Initial Value
  1063. $output = array();
  1064. // Sort Items
  1065. ksort($array);
  1066. // Update the current config version
  1067. if (!$nest) {
  1068. // Inject Current Version
  1069. $output[] = "\t'CONFIG_VERSION' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:INSTALLEDVERSION)."'";
  1070. }
  1071. unset($array['CONFIG_VERSION']);
  1072. unset($array['apply_CONFIG_VERSION']);
  1073. // Process Settings
  1074. foreach ($array as $k => $v) {
  1075. $allowCommit = true;
  1076. switch (gettype($v)) {
  1077. case 'boolean':
  1078. $item = ($v?'true':'false');
  1079. break;
  1080. case 'integer':
  1081. case 'double':
  1082. case 'integer':
  1083. case 'NULL':
  1084. $item = $v;
  1085. break;
  1086. case 'string':
  1087. $item = "'".str_replace(array('\\',"'"),array('\\\\',"\'"),$v)."'";
  1088. break;
  1089. case 'array':
  1090. $item = createConfig($v, false, $nest+1);
  1091. break;
  1092. default:
  1093. $allowCommit = false;
  1094. }
  1095. if($allowCommit) {
  1096. $output[] = str_repeat("\t",$nest+1)."'$k' => $item";
  1097. }
  1098. }
  1099. // Build output
  1100. $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
  1101. if (!$nest && $path) {
  1102. $pathDigest = pathinfo($path);
  1103. @mkdir($pathDigest['dirname'], 0770, true);
  1104. if (file_exists($path)) {
  1105. rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
  1106. }
  1107. $file = fopen($path, 'w');
  1108. fwrite($file, $output);
  1109. fclose($file);
  1110. if (file_exists($path)) {
  1111. return true;
  1112. }
  1113. writeLog("error", "config was unable to write");
  1114. return false;
  1115. } else {
  1116. writeLog("success", "config was updated with new values");
  1117. return $output;
  1118. }
  1119. }
  1120. // Load a config file written in the return syntax
  1121. function loadConfig($path = 'config/config.php') {
  1122. // Adapted from http://stackoverflow.com/a/14173339/6810513
  1123. if (!is_file($path)) {
  1124. return null;
  1125. } else {
  1126. return (array) call_user_func(function() use($path) {
  1127. return include($path);
  1128. });
  1129. }
  1130. }
  1131. // Commit new values to the configuration
  1132. function updateConfig($new, $current = false) {
  1133. // Get config if not supplied
  1134. if ($current === false) {
  1135. $current = loadConfig();
  1136. } else if (is_string($current) && is_file($current)) {
  1137. $current = loadConfig($current);
  1138. }
  1139. // Inject Parts
  1140. foreach ($new as $k => $v) {
  1141. $current[$k] = $v;
  1142. }
  1143. // Return Create
  1144. return createConfig($current);
  1145. }
  1146. // Inject Defaults As Needed
  1147. function fillDefaultConfig($array, $path = 'config/configDefaults.php') {
  1148. if (is_string($path)) {
  1149. $loadedDefaults = loadConfig($path);
  1150. } else {
  1151. $loadedDefaults = $path;
  1152. }
  1153. return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  1154. }
  1155. // support function for fillDefaultConfig()
  1156. function fillDefaultConfig_recurse($current, $defaults) {
  1157. foreach($defaults as $k => $v) {
  1158. if (!isset($current[$k])) {
  1159. $current[$k] = $v;
  1160. } else if (is_array($current[$k]) && is_array($v)) {
  1161. $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
  1162. }
  1163. }
  1164. return $current;
  1165. };
  1166. // Define Scalar Variables (nest non-secular with underscores)
  1167. function defineConfig($array, $anyCase = true, $nest_prefix = false) {
  1168. foreach($array as $k => $v) {
  1169. if (is_scalar($v) && !defined($nest_prefix.$k)) {
  1170. define($nest_prefix.$k, $v, $anyCase);
  1171. } else if (is_array($v)) {
  1172. defineConfig($v, $anyCase, $nest_prefix.$k.'_');
  1173. }
  1174. }
  1175. }
  1176. // This function exists only because I am lazy
  1177. function configLazy($path = 'config/config.php') {
  1178. // Load config or default
  1179. if (file_exists($path)) {
  1180. $config = fillDefaultConfig(loadConfig($path));
  1181. } else {
  1182. $config = loadConfig('config/configDefaults.php');
  1183. }
  1184. if (is_array($config)) {
  1185. defineConfig($config);
  1186. }
  1187. return $config;
  1188. }
  1189. // Qualify URL
  1190. function qualifyURL($url) {
  1191. //local address?
  1192. if(substr($url, 0,1) == "/"){
  1193. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  1194. $protocol = "https://";
  1195. } else {
  1196. $protocol = "http://";
  1197. }
  1198. $url = $protocol.getServer().$url;
  1199. }
  1200. // Get Digest
  1201. $digest = parse_url($url);
  1202. // http/https
  1203. if (!isset($digest['scheme'])) {
  1204. if (isset($digest['port']) && in_array($digest['port'], array(80,8080,8096,32400,7878,8989,8182,8081,6789))) {
  1205. $scheme = 'http';
  1206. } else {
  1207. $scheme = 'https';
  1208. }
  1209. } else {
  1210. $scheme = $digest['scheme'];
  1211. }
  1212. // Host
  1213. $host = (isset($digest['host'])?$digest['host']:'');
  1214. // Port
  1215. $port = (isset($digest['port'])?':'.$digest['port']:'');
  1216. // Path
  1217. $path = (isset($digest['path'])?$digest['path']:'');
  1218. // Output
  1219. return $scheme.'://'.$host.$port.$path;
  1220. }
  1221. // Function to be called at top of each to allow upgrading environment as the spec changes
  1222. function upgradeCheck() {
  1223. // Upgrade to 1.31
  1224. if (file_exists('homepageSettings.ini.php')) {
  1225. $databaseConfig = parse_ini_file('databaseLocation.ini.php', true);
  1226. $homepageConfig = parse_ini_file('homepageSettings.ini.php', true);
  1227. $databaseConfig = array_merge($databaseConfig, $homepageConfig);
  1228. $databaseData = '; <?php die("Access denied"); ?>' . "\r\n";
  1229. foreach($databaseConfig as $k => $v) {
  1230. if(substr($v, -1) == "/") : $v = rtrim($v, "/"); endif;
  1231. $databaseData .= $k . " = \"" . $v . "\"\r\n";
  1232. }
  1233. write_ini_file($databaseData, 'databaseLocation.ini.php');
  1234. unlink('homepageSettings.ini.php');
  1235. unset($databaseData);
  1236. unset($homepageConfig);
  1237. }
  1238. // Upgrade to 1.32
  1239. if (file_exists('databaseLocation.ini.php')) {
  1240. // Load Existing
  1241. $config = parse_ini_file('databaseLocation.ini.php', true);
  1242. // Refactor
  1243. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['databaseLocation'].'/');
  1244. $config['user_home'] = $config['database_Location'].'users/';
  1245. unset($config['databaseLocation']);
  1246. // Turn Off Emby And Plex Recent
  1247. $config["embyURL"] = $config["embyURL"].(!empty($config["embyPort"])?':'.$config["embyPort"]:'');
  1248. unset($config["embyPort"]);
  1249. $config["plexURL"] = $config["plexURL"].(!empty($config["plexPort"])?':'.$config["plexPort"]:'');
  1250. unset($config["plexPort"]);
  1251. $config["nzbgetURL"] = $config["nzbgetURL"].(!empty($config["nzbgetPort"])?':'.$config["nzbgetPort"]:'');
  1252. unset($config["nzbgetPort"]);
  1253. $config["sabnzbdURL"] = $config["sabnzbdURL"].(!empty($config["sabnzbdPort"])?':'.$config["sabnzbdPort"]:'');
  1254. unset($config["sabnzbdPort"]);
  1255. $config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
  1256. unset($config["headphonesPort"]);
  1257. // Write config file
  1258. $config['CONFIG_VERSION'] = '1.32';
  1259. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][pre1.32].bak.php');
  1260. $createConfigSuccess = createConfig($config);
  1261. // Create new config
  1262. if ($createConfigSuccess) {
  1263. if (file_exists('config/config.php')) {
  1264. // Remove Old ini file
  1265. unlink('databaseLocation.ini.php');
  1266. } else {
  1267. debug_out('Something is not right here!');
  1268. }
  1269. } else {
  1270. debug_out('Couldn\'t create updated configuration.' ,1);
  1271. }
  1272. }
  1273. // Upgrade to 1.33
  1274. $config = loadConfig();
  1275. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
  1276. // Fix User Directory
  1277. $config['database_Location'] = preg_replace('/\/\/$/','/',$config['database_Location'].'/');
  1278. $config['user_home'] = $config['database_Location'].'users/';
  1279. unset($config['USER_HOME']);
  1280. // Backend auth merge
  1281. if (isset($config['authBackendPort']) && !isset(parse_url($config['authBackendHost'])['port'])) {
  1282. $config['authBackendHost'] .= ':'.$config['authBackendPort'];
  1283. }
  1284. unset($config['authBackendPort']);
  1285. // If auth is being used move it to embyURL as that is now used in auth functions
  1286. 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')))) {
  1287. $config['embyURL'] = $config['authBackendHost'];
  1288. }
  1289. // Upgrade database to latest version
  1290. updateSQLiteDB($config['database_Location'],'1.32');
  1291. // Update Version and Commit
  1292. $config['apply_CONFIG_VERSION'] = '1.33';
  1293. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.32].bak.php');
  1294. $createConfigSuccess = createConfig($config);
  1295. unset($config);
  1296. }
  1297. // Upgrade to 1.34
  1298. $config = loadConfig();
  1299. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.34')) {
  1300. // Upgrade database to latest version
  1301. updateSQLiteDB($config['database_Location'],'1.33');
  1302. // Update Version and Commit
  1303. $config['CONFIG_VERSION'] = '1.34';
  1304. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.33].bak.php');
  1305. $createConfigSuccess = createConfig($config);
  1306. unset($config);
  1307. }
  1308. // Upgrade to 1.40
  1309. $config = loadConfig();
  1310. if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.40')) {
  1311. // Upgrade database to latest version
  1312. updateSQLiteDB($config['database_Location'],'1.38');
  1313. // Update Version and Commit
  1314. $config['CONFIG_VERSION'] = '1.40';
  1315. copy('config/config.php', 'config/config['.date('Y-m-d_H-i-s').'][1.38].bak.php');
  1316. $createConfigSuccess = createConfig($config);
  1317. unset($config);
  1318. }
  1319. return true;
  1320. }
  1321. // Get OS from server
  1322. function getOS(){
  1323. if(PHP_SHLIB_SUFFIX == "dll"){
  1324. return "win";
  1325. }else{
  1326. return "nix";
  1327. }
  1328. }
  1329. //Get Error by Server OS
  1330. function getError($os, $error){
  1331. $ini = (!empty(php_ini_loaded_file()) ? php_ini_loaded_file() : "php.ini");
  1332. $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'");
  1333. $errors = array(
  1334. 'pdo_sqlite' => array(
  1335. 'win' => '<b>PDO:SQLite</b> not enabled, uncomment ;extension=php_pdo_sqlite.dll in the file php.ini | '.$ext,
  1336. 'nix' => '<b>PDO:SQLite</b> not enabled, PHP7 -> run sudo apt-get install php7.0-sqlite | PHP5 -> run sudo apt-get install php5-sqlite',
  1337. ),
  1338. 'sqlite3' => array(
  1339. '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',
  1340. 'nix' => '<b>SQLite3</b> not enabled, run sudo apt-get install php-sqlite3',
  1341. ),
  1342. 'curl' => array(
  1343. 'win' => '<b>cURL</b> not enabled, uncomment ;extension=php_curl.dll in the file php.ini | '.$ext,
  1344. 'nix' => '<b>cURL</b> not enabled, PHP7 -> sudo apt-get install php-curl | PHP5 -> run sudo apt-get install php5.6-curl',
  1345. ),
  1346. 'zip' => array(
  1347. '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',
  1348. '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',
  1349. ),
  1350. );
  1351. return (isset($errors[$error][$os]) ? $errors[$error][$os] : 'No Error Info Found');
  1352. }
  1353. // Check if all software dependancies are met
  1354. function dependCheck() {
  1355. $output = array();
  1356. $i = 1;
  1357. if (!extension_loaded('pdo_sqlite')) { $output["Step $i"] = getError(getOS(),'pdo_sqlite'); $i++; }
  1358. if (!extension_loaded('curl')) { $output["Step $i"] = getError(getOS(),'curl'); $i++; }
  1359. if (!extension_loaded('zip')) { $output["Step $i"] = getError(getOS(),'zip'); $i++; }
  1360. //if (!extension_loaded('sqlite3')) { $output[] = getError(getOS(),'sqlite3'); }
  1361. if ($output) {
  1362. $output["Step $i"] = "<b>Restart PHP and/or Webserver to apply changes</b>"; $i++;
  1363. $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++;
  1364. debug_out($output,1);
  1365. }
  1366. return true;
  1367. }
  1368. // Process file uploads
  1369. function uploadFiles($path, $ext_mask = null) {
  1370. if (isset($_FILES) && count($_FILES)) {
  1371. require_once('class.uploader.php');
  1372. $uploader = new Uploader();
  1373. $data = $uploader->upload($_FILES['files'], array(
  1374. 'limit' => 10,
  1375. 'maxSize' => 10,
  1376. 'extensions' => $ext_mask,
  1377. 'required' => false,
  1378. 'uploadDir' => str_replace('//','/',$path.'/'),
  1379. 'title' => array('name'),
  1380. 'removeFiles' => true,
  1381. 'replace' => true,
  1382. ));
  1383. if($data['isComplete']){
  1384. $files = $data['data'];
  1385. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1386. echo json_encode($files['metas'][0]['name']);
  1387. }
  1388. if($data['hasErrors']){
  1389. $errors = $data['errors'];
  1390. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1391. echo json_encode($errors);
  1392. }
  1393. } else {
  1394. writeLog("error", "image was not uploaded");
  1395. echo json_encode('No files submitted!');
  1396. }
  1397. }
  1398. // Process file uploads
  1399. function uploadAvatar($path, $ext_mask = null) {
  1400. if (isset($_FILES) && count($_FILES)) {
  1401. require_once('class.uploader.php');
  1402. $uploader = new Uploader();
  1403. $data = $uploader->upload($_FILES['files'], array(
  1404. 'limit' => 10,
  1405. 'maxSize' => 10,
  1406. 'extensions' => $ext_mask,
  1407. 'required' => false,
  1408. 'uploadDir' => str_replace('//','/',$path.'/'),
  1409. 'title' => array('name'),
  1410. 'removeFiles' => true,
  1411. 'replace' => true,
  1412. ));
  1413. if($data['isComplete']){
  1414. $files = $data['data'];
  1415. writeLog("success", $files['metas'][0]['name']." was uploaded");
  1416. echo json_encode($files['metas'][0]['name']);
  1417. }
  1418. if($data['hasErrors']){
  1419. $errors = $data['errors'];
  1420. writeLog("error", $files['metas'][0]['name']." was not able to upload");
  1421. echo json_encode($errors);
  1422. }
  1423. } else {
  1424. writeLog("error", "image was not uploaded");
  1425. echo json_encode('No files submitted!');
  1426. }
  1427. }
  1428. // Remove file
  1429. function removeFiles($path) {
  1430. if(is_file($path)) {
  1431. writeLog("success", "image was removed");
  1432. unlink($path);
  1433. } else {
  1434. writeLog("error", "image was not removed");
  1435. echo json_encode('No file specified for removal!');
  1436. }
  1437. }
  1438. // Lazy select options
  1439. function resolveSelectOptions($array, $selected = '', $multi = false) {
  1440. $output = array();
  1441. $selectedArr = ($multi?explode('|', $selected):array());
  1442. foreach ($array as $key => $value) {
  1443. if (is_array($value)) {
  1444. if (isset($value['optgroup'])) {
  1445. $output[] = '<optgroup label="'.$key.'">';
  1446. foreach($value['optgroup'] as $k => $v) {
  1447. $output[] = '<option value="'.$v['value'].'"'.($selected===$v['value']||in_array($v['value'],$selectedArr)?' selected':'').(isset($v['disabled']) && $v['disabled']?' disabled':'').'>'.$k.'</option>';
  1448. }
  1449. } else {
  1450. $output[] = '<option value="'.$value['value'].'"'.($selected===$value['value']||in_array($value['value'],$selectedArr)?' selected':'').(isset($value['disabled']) && $value['disabled']?' disabled':'').'>'.$key.'</option>';
  1451. }
  1452. } else {
  1453. $output[] = '<option value="'.$value.'"'.($selected===$value||in_array($value,$selectedArr)?' selected':'').'>'.$key.'</option>';
  1454. }
  1455. }
  1456. return implode('',$output);
  1457. }
  1458. // Check if user is allowed to continue
  1459. function qualifyUser($type, $errOnFail = false) {
  1460. if (!isset($GLOBALS['USER'])) {
  1461. require_once("user.php");
  1462. $GLOBALS['USER'] = new User('registration_callback');
  1463. }
  1464. if (is_bool($type)) {
  1465. if ($type === true) {
  1466. $authorized = ($GLOBALS['USER']->authenticated == true);
  1467. } else {
  1468. $authorized = true;
  1469. }
  1470. } elseif (is_string($type) || is_array($type)) {
  1471. if ($type !== 'false') {
  1472. if (!is_array($type)) {
  1473. $type = explode('|',$type);
  1474. }
  1475. $authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
  1476. } else {
  1477. $authorized = true;
  1478. }
  1479. } else {
  1480. debug_out('Invalid Syntax!',1);
  1481. }
  1482. if (!$authorized && $errOnFail) {
  1483. if ($GLOBALS['USER']->authenticated) {
  1484. header('Location: '.dirname($_SERVER['SCRIPT_NAME']).'error.php?error=401');
  1485. echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'error.php?error=401\'</script>';
  1486. } else {
  1487. header('Location: '.dirname($_SERVER['SCRIPT_NAME']).'error.php?error=999');
  1488. echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'error.php?error=999\'</script>';
  1489. }
  1490. debug_out('Not Authorized' ,1);
  1491. } else {
  1492. return $authorized;
  1493. }
  1494. }
  1495. // Build an (optionally) tabbed settings page.
  1496. function buildSettings($array) {
  1497. /*
  1498. array(
  1499. 'title' => '',
  1500. 'id' => '',
  1501. 'fields' => array( See buildField() ),
  1502. 'tabs' => array(
  1503. array(
  1504. 'title' => '',
  1505. 'id' => '',
  1506. 'image' => '',
  1507. 'fields' => array( See buildField() ),
  1508. ),
  1509. ),
  1510. );
  1511. */
  1512. $notifyExplode = explode("-", NOTIFYEFFECT);
  1513. $fieldFunc = function($fieldArr) {
  1514. $fields = '<div class="row">';
  1515. foreach($fieldArr as $key => $value) {
  1516. $isSingle = isset($value['type']);
  1517. if ($isSingle) { $value = array($value); }
  1518. $tmpField = '';
  1519. $sizeLg = max(floor(12/count($value)),2);
  1520. $sizeMd = max(floor(($isSingle?12:6)/count($value)),3);
  1521. foreach($value as $k => $v) {
  1522. $tmpField .= buildField($v, 12, $sizeMd, $sizeLg);
  1523. }
  1524. $fields .= ($isSingle?$tmpField:'<div class="row col-sm-12 content-form">'.$tmpField.'</div>');
  1525. }
  1526. $fields .= '</div>';
  1527. return $fields;
  1528. };
  1529. $fields = (isset($array['fields'])?$fieldFunc($array['fields']):'');
  1530. $tabSelectors = array();
  1531. $tabContent = array();
  1532. if (isset($array['tabs'])) {
  1533. foreach($array['tabs'] as $key => $value) {
  1534. $id = (isset($value['id'])?$value['id']:randString(32));
  1535. $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>';
  1536. $tabContent[$key] = '<div class="tab-pane big-box fade'.($tabContent?'':' active in').'" id="tab-'.$id.'">'.$fieldFunc($value['fields']).'</div>';
  1537. }
  1538. }
  1539. $pageID = (isset($array['id'])?$array['id']:str_replace(array(' ','"',"'"),array('_'),strtolower($array['id'])));
  1540. return '
  1541. <div class="email-body">
  1542. <div class="email-header gray-bg">
  1543. <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
  1544. <h1>'.$array['title'].'</h1>
  1545. </div>
  1546. <div class="email-inner small-box">
  1547. <div class="email-inner-section">
  1548. <div class="small-box fade in" id="'.$pageID.'_frame">
  1549. <div class="col-lg-12">
  1550. '.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
  1551. <form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
  1552. <button id="'.$pageID.'_form_submit" class="btn waves btn-labeled btn-success btn btn-sm pull-right text-uppercase waves-effect waves-float">
  1553. <span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
  1554. </button>
  1555. '.$fields.($tabContent?'
  1556. <div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
  1557. <ul class="nav nav-tabs apps">
  1558. '.implode('', $tabSelectors).'
  1559. </ul>
  1560. <div class="clearfix"></div>
  1561. <div class="tab-content">
  1562. '.implode('', $tabContent).'
  1563. </div>
  1564. </div>':'').'
  1565. </form>
  1566. '.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
  1567. </div>
  1568. </div>
  1569. </div>
  1570. </div>
  1571. </div>
  1572. <script>
  1573. $(document).ready(function() {
  1574. $(\'#'.$pageID.'_form\').find(\'input, select, textarea\').on(\'change\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1575. var '.$pageID.'Validate = function() { if (this.value && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { $(this).addClass(\'invalid\'); } else { $(this).removeClass(\'invalid\'); } };
  1576. $(\'#'.$pageID.'_form\').find(\'input[pattern]\').each('.$pageID.'Validate).on(\'keyup\', '.$pageID.'Validate);
  1577. $(\'#'.$pageID.'_form\').find(\'select[multiple]\').on(\'change click\', function() { $(this).attr(\'data-changed\', \'true\'); });
  1578. $(\'#'.$pageID.'_form_submit\').on(\'click\', function () {
  1579. var newVals = {};
  1580. var hasVals = false;
  1581. var errorFields = [];
  1582. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').each(function() {
  1583. hasVals = true;
  1584. if (this.type == \'checkbox\') {
  1585. newVals[this.name] = this.checked;
  1586. } else if ($(this).hasClass(\'summernote\')) {
  1587. newVals[$(this).attr(\'name\')] = $(this).siblings(\'.note-editor\').find(\'.panel-body\').html();
  1588. } else {
  1589. if (this.value && this.pattern && !RegExp(\'^\'+this.pattern+\'$\').test(this.value)) { errorFields.push(this.name); }
  1590. var fieldVal = $(this).val();
  1591. if (typeof fieldVal == \'object\') {
  1592. if (typeof fieldVal.join == \'function\') {
  1593. fieldVal = fieldVal.join(\'|\');
  1594. } else {
  1595. fieldVal = JSON.stringify(fieldVal);
  1596. }
  1597. }
  1598. newVals[this.name] = fieldVal;
  1599. }
  1600. });
  1601. if (errorFields.length) {
  1602. parent.notify(\'Fields have errors: \'+errorFields.join(\', \')+\'!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1603. } else if (hasVals) {
  1604. console.log(newVals);
  1605. ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
  1606. $(\'#'.$pageID.'_form\').find(\'[data-changed=true][name]\').removeAttr(\'data-changed\');
  1607. });
  1608. } else {
  1609. parent.notify(\'Nothing to update!\', \'bullhorn\', \'error\', 5000, \''.$notifyExplode[0].'\', \''.$notifyExplode[1].'\');
  1610. }
  1611. return false;
  1612. });
  1613. '.(isset($array['onready'])?$array['onready']:'').'
  1614. });
  1615. </script>
  1616. ';
  1617. }
  1618. // Build Settings Fields
  1619. function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
  1620. /*
  1621. array(
  1622. 'type' => '',
  1623. 'placeholder' => '',
  1624. 'label' => '',
  1625. 'labelTranslate' => '',
  1626. 'assist' => '',
  1627. 'name' => '',
  1628. 'pattern' => '',
  1629. 'options' => array( // For SELECT only
  1630. 'Display' => 'value',
  1631. ),
  1632. )
  1633. */
  1634. // Tags
  1635. $tags = array();
  1636. foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href','onclick') as $value) {
  1637. if (isset($params[$value])) {
  1638. if (is_string($params[$value])) { $tags[] = $value.'="'.$params[$value].'"';
  1639. } else if ($params[$value] === true) { $tags[] = $value; }
  1640. }
  1641. }
  1642. $format = (isset($params['format']) && in_array($params['format'],array(false,'colour','color'))?$params['format']:false);
  1643. $name = (isset($params['name'])?$params['name']:(isset($params['id'])?$params['id']:''));
  1644. $id = (isset($params['id'])?$params['id']:(isset($params['name'])?$params['name'].'_id':randString(32)));
  1645. $val = (isset($params['value'])?$params['value']:'');
  1646. $class = (isset($params['class'])?' '.$params['class']:'');
  1647. $wrapClass = (isset($params['wrapClass'])?$params['wrapClass']:'form-content');
  1648. $assist = (isset($params['assist'])?' - i.e. '.$params['assist']:'');
  1649. $label = (isset($params['labelTranslate'])?translate($params['labelTranslate']):(isset($params['label'])?$params['label']:''));
  1650. $labelOut = '<p class="help-text">'.$label.$assist.'</p>';
  1651. // Field Design
  1652. switch ($params['type']) {
  1653. case 'text':
  1654. case 'number':
  1655. case 'password':
  1656. $field = '<input id="'.$id.'" name="'.$name.'" type="'.$params['type'].'" class="form-control material input-sm'.$class.'" '.implode(' ',$tags).' autocorrect="off" autocapitalize="off" value="'.$val.'">';
  1657. break;
  1658. case 'select':
  1659. case 'dropdown':
  1660. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control material input-sm" '.implode(' ',$tags).'>'.resolveSelectOptions($params['options'], $val).'</select>';
  1661. break;
  1662. case 'select-multi':
  1663. case 'dropdown-multi':
  1664. $field = '<select id="'.$id.'" name="'.$name.'" class="form-control input-sm" '.implode(' ',$tags).' multiple="multiple">'.resolveSelectOptions($params['options'], $val, true).'</select>';
  1665. break;
  1666. case 'check':
  1667. case 'checkbox':
  1668. case 'toggle':
  1669. $checked = ((is_bool($val) && $val) || trim($val) === 'true'?' checked':'');
  1670. $colour = (isset($params['colour'])?$params['colour']:'success');
  1671. $labelOut = '<label for="'.$id.'"></label>'.$label;
  1672. $field = '<input id="'.$id.'" name="'.$name.'" type="checkbox" class="switcher switcher-'.$colour.' '.$class.'" '.implode(' ',$tags).' data-value="'.$val.'"'.$checked.'>';
  1673. break;
  1674. case 'radio':
  1675. $labelOut = '';
  1676. $checked = ((is_bool($val) && $val) || ($val && trim($val) !== 'false')?' checked':'');
  1677. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1678. $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>';
  1679. break;
  1680. case 'date':
  1681. $field = 'Unsupported, planned.';
  1682. break;
  1683. case 'hidden':
  1684. return '<input id="'.$id.'" name="'.$name.'" type="hidden" class="'.$class.'" '.implode(' ',$tags).' value="'.$val.'">';
  1685. break;
  1686. case 'header':
  1687. $labelOut = '';
  1688. $headType = (isset($params['value'])?$params['value']:3);
  1689. $field = '<h'.$headType.' class="'.$class.'" '.implode(' ',$tags).'>'.$label.'</h'.$headType.'>';
  1690. break;
  1691. case 'button':
  1692. $labelOut = '';
  1693. $icon = (isset($params['icon'])?$params['icon']:'flask');
  1694. $bType = (isset($params['buttonType'])?$params['buttonType']:'success');
  1695. $bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
  1696. $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>'.$label.'</button>'.($bDropdown?$bDropdown.'</div>':'');
  1697. break;
  1698. case 'textarea':
  1699. $rows = (isset($params['rows'])?$params['rows']:5);
  1700. $field = '<textarea id="'.$id.'" name="'.$name.'" class="form-control'.$class.'" rows="'.$rows.'" '.implode(' ',$tags).'>'.$val.'</textarea>';
  1701. break;
  1702. case 'custom':
  1703. // Settings
  1704. $settings = array(
  1705. '$id' => $id,
  1706. '$name' => $name,
  1707. '$val' => $val,
  1708. '$label' => $label,
  1709. '$labelOut' => $labelOut,
  1710. );
  1711. // Get HTML
  1712. $html = (isset($params['html'])?$params['html']:'Nothing Specified!');
  1713. // If LabelOut is in html dont print it twice
  1714. $labelOut = (strpos($html,'$label')!==false?'':$labelOut);
  1715. // Replace variables in settings
  1716. $html = preg_replace_callback('/\$\w+\b/', function ($match) use ($settings) { return (isset($settings[$match[0]])?$settings[$match[0]]:'{'.$match[0].' is undefined}'); }, $html);
  1717. // Build Field
  1718. $field = '<div id="'.$id.'_html" class="custom-field">'.$html.'</div>';
  1719. break;
  1720. case 'space':
  1721. $labelOut = '';
  1722. $field = str_repeat('<br>', (isset($params['value'])?$params['value']:1));
  1723. break;
  1724. default:
  1725. $field = 'Unsupported field type';
  1726. break;
  1727. }
  1728. // Field Formats
  1729. switch ($format) {
  1730. case 'colour': // Fuckin Eh, Canada!
  1731. case 'color':
  1732. $labelBef = '<center>'.$label.'</center>';
  1733. $wrapClass = 'gray-bg colour-field';
  1734. $labelAft = '';
  1735. $field = str_replace(' material input-sm','',$field);
  1736. break;
  1737. default:
  1738. $labelBef = '';
  1739. $labelAft = $labelOut;
  1740. }
  1741. return '<div class="'.$wrapClass.' col-sm-'.$sizeSm.' col-md-'.$sizeMd.' col-lg-'.$sizeLg.'">'.$labelBef.$field.$labelAft.'</div>';
  1742. }
  1743. // Tab Settings Generation
  1744. function printTabRow($data) {
  1745. $hidden = false;
  1746. if ($data===false) {
  1747. $hidden = true;
  1748. $data = array( // New Tab Defaults
  1749. 'id' => 'new',
  1750. 'name' => '',
  1751. 'url' => '',
  1752. 'icon' => 'fa-diamond',
  1753. 'iconurl' => '',
  1754. 'active' => 'true',
  1755. 'user' => 'true',
  1756. 'guest' => 'true',
  1757. 'window' => 'false',
  1758. 'defaultz' => '',
  1759. );
  1760. }
  1761. $image = '<span style="font: normal normal normal 30px/1 FontAwesome;" class="fa fa-hand-paper-o"></span>';
  1762. $output = '
  1763. <li id="tab-'.$data['id'].'" class="list-group-item" style="position: relative; left: 0px; top: 0px; '.($hidden?' display: none;':'').'">
  1764. <tab class="content-form form-inline">
  1765. <div class="row">
  1766. '.buildField(array(
  1767. 'type' => 'custom',
  1768. '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>',
  1769. ),12,1,1).'
  1770. '.buildField(array(
  1771. 'type' => 'hidden',
  1772. 'id' => 'tab-'.$data['id'].'-id',
  1773. 'name' => 'id['.$data['id'].']',
  1774. 'value' => $data['id'],
  1775. ),12,2,1).'
  1776. '.buildField(array(
  1777. 'type' => 'text',
  1778. 'id' => 'tab-'.$data['id'].'-name',
  1779. 'name' => 'name['.$data['id'].']',
  1780. 'required' => true,
  1781. 'placeholder' => 'Organizr Homepage',
  1782. 'labelTranslate' => 'TAB_NAME',
  1783. 'value' => $data['name'],
  1784. ),12,2,1).'
  1785. '.buildField(array(
  1786. 'type' => 'text',
  1787. 'id' => 'tab-'.$data['id'].'-url',
  1788. 'name' => 'url['.$data['id'].']',
  1789. 'required' => true,
  1790. 'placeholder' => 'homepage.php',
  1791. 'labelTranslate' => 'TAB_URL',
  1792. 'value' => $data['url'],
  1793. ),12,2,1).'
  1794. '.buildField(array(
  1795. 'type' => 'text',
  1796. 'id' => 'tab-'.$data['id'].'-iconurl',
  1797. 'name' => 'iconurl['.$data['id'].']',
  1798. 'placeholder' => 'images/organizr.png',
  1799. 'labelTranslate' => 'ICON_URL',
  1800. 'value' => $data['iconurl'],
  1801. ),12,2,1).'
  1802. '.buildField(array(
  1803. 'type' => 'custom',
  1804. 'id' => 'tab-'.$data['id'].'-icon',
  1805. 'name' => 'icon['.$data['id'].']',
  1806. 'html' => '- '.translate('OR').' - <div class="input-group"><input data-placement="bottomRight" class="form-control material icp-auto'.($hidden?'-pend':'').'" id="$id" name="$name" value="$val" type="text" /><span class="input-group-addon"></span></div>',
  1807. 'value' => $data['icon'],
  1808. ),12,1,1).'
  1809. '.buildField(array(
  1810. 'type' => 'checkbox',
  1811. 'labelTranslate' => 'ACTIVE',
  1812. 'name' => 'active['.$data['id'].']',
  1813. 'value' => $data['active'],
  1814. ),12,1,1).'
  1815. '.buildField(array(
  1816. 'type' => 'checkbox',
  1817. 'labelTranslate' => 'USER',
  1818. 'colour' => 'primary',
  1819. 'name' => 'user['.$data['id'].']',
  1820. 'value' => $data['user'],
  1821. ),12,1,1).'
  1822. '.buildField(array(
  1823. 'type' => 'checkbox',
  1824. 'labelTranslate' => 'GUEST',
  1825. 'colour' => 'warning',
  1826. 'name' => 'guest['.$data['id'].']',
  1827. 'value' => $data['guest'],
  1828. ),12,1,1).'
  1829. '.buildField(array(
  1830. 'type' => 'checkbox',
  1831. 'labelTranslate' => 'NO_IFRAME',
  1832. 'colour' => 'danger',
  1833. 'name' => 'window['.$data['id'].']',
  1834. 'value' => $data['window'],
  1835. ),12,1,1).'
  1836. '.buildField(array(
  1837. 'type' => 'radio',
  1838. 'labelTranslate' => 'DEFAULT',
  1839. 'name' => 'defaultz['.$data['id'].']',
  1840. 'value' => $data['defaultz'],
  1841. 'onclick' => "$('[type=radio][id!=\''+this.id+'\']').each(function() { this.checked=false; });",
  1842. ),12,1,1).'
  1843. '.buildField(array(
  1844. 'type' => 'button',
  1845. 'icon' => 'trash',
  1846. 'buttonType' => 'danger',
  1847. 'labelTranslate' => 'REMOVE',
  1848. 'onclick' => "$(this).parents('li').remove();",
  1849. ),12,1,1).'
  1850. </div>
  1851. </tab>
  1852. </li>
  1853. ';
  1854. return $output;
  1855. }
  1856. // Timezone array
  1857. function timezoneOptions() {
  1858. $output = array();
  1859. $timezones = array();
  1860. $regions = array(
  1861. 'Africa' => DateTimeZone::AFRICA,
  1862. 'America' => DateTimeZone::AMERICA,
  1863. 'Antarctica' => DateTimeZone::ANTARCTICA,
  1864. 'Arctic' => DateTimeZone::ARCTIC,
  1865. 'Asia' => DateTimeZone::ASIA,
  1866. 'Atlantic' => DateTimeZone::ATLANTIC,
  1867. 'Australia' => DateTimeZone::AUSTRALIA,
  1868. 'Europe' => DateTimeZone::EUROPE,
  1869. 'Indian' => DateTimeZone::INDIAN,
  1870. 'Pacific' => DateTimeZone::PACIFIC
  1871. );
  1872. foreach ($regions as $name => $mask) {
  1873. $zones = DateTimeZone::listIdentifiers($mask);
  1874. foreach($zones as $timezone) {
  1875. $time = new DateTime(NULL, new DateTimeZone($timezone));
  1876. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  1877. $output[$name]['optgroup'][substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm]['value'] = $timezone;
  1878. }
  1879. }
  1880. return $output;
  1881. }
  1882. // Build Database
  1883. function createSQLiteDB($path = false) {
  1884. if ($path === false) {
  1885. if (DATABASE_LOCATION){
  1886. $path = DATABASE_LOCATION;
  1887. } else {
  1888. debug_out('No Path Specified!');
  1889. }
  1890. }
  1891. if (!is_file($path.'users.db') || filesize($path.'users.db') <= 0) {
  1892. if (!isset($GLOBALS['file_db'])) {
  1893. $GLOBALS['file_db'] = new PDO('sqlite:'.$path.'users.db');
  1894. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1895. }
  1896. // Create Users
  1897. $users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
  1898. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1899. `username` TEXT UNIQUE,
  1900. `password` TEXT,
  1901. `email` TEXT,
  1902. `token` TEXT,
  1903. `role` TEXT,
  1904. `active` TEXT,
  1905. `last` TEXT,
  1906. `auth_service` TEXT DEFAULT \'internal\'
  1907. );');
  1908. // Create Tabs
  1909. $tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
  1910. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1911. `order` INTEGER,
  1912. `users_id` INTEGER,
  1913. `name` TEXT,
  1914. `url` TEXT,
  1915. `defaultz` TEXT,
  1916. `active` TEXT,
  1917. `user` TEXT,
  1918. `guest` TEXT,
  1919. `icon` TEXT,
  1920. `iconurl` TEXT,
  1921. `window` TEXT
  1922. );');
  1923. // Create Options
  1924. $options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
  1925. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1926. `users_id` INTEGER UNIQUE,
  1927. `title` TEXT UNIQUE,
  1928. `topbar` TEXT,
  1929. `bottombar` TEXT,
  1930. `sidebar` TEXT,
  1931. `hoverbg` TEXT,
  1932. `topbartext` TEXT,
  1933. `activetabBG` TEXT,
  1934. `activetabicon` TEXT,
  1935. `activetabtext` TEXT,
  1936. `inactiveicon` TEXT,
  1937. `inactivetext` TEXT,
  1938. `loading` TEXT,
  1939. `hovertext` TEXT
  1940. );');
  1941. // Create Invites
  1942. $invites = $GLOBALS['file_db']->query('CREATE TABLE `invites` (
  1943. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  1944. `code` TEXT UNIQUE,
  1945. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  1946. `email` TEXT,
  1947. `username` TEXT,
  1948. `dateused` TIMESTAMP,
  1949. `usedby` TEXT,
  1950. `ip` TEXT,
  1951. `valid` TEXT
  1952. );');
  1953. writeLog("success", "database created/saved");
  1954. return $users && $tabs && $options && $invites;
  1955. } else {
  1956. writeLog("error", "database was unable to be created/saved");
  1957. return false;
  1958. }
  1959. }
  1960. // Upgrade Database
  1961. function updateSQLiteDB($db_path = false, $oldVerNum = false) {
  1962. if (!$db_path) {
  1963. if (defined('DATABASE_LOCATION')) {
  1964. $db_path = DATABASE_LOCATION;
  1965. } else {
  1966. debug_out('No Path Specified',1);
  1967. }
  1968. }
  1969. if (!isset($GLOBALS['file_db'])) {
  1970. $GLOBALS['file_db'] = new PDO('sqlite:'.$db_path.'users.db');
  1971. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1972. }
  1973. // Cache current DB
  1974. $cache = array();
  1975. foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
  1976. foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
  1977. foreach($row as $k => $v) {
  1978. if (is_string($k)) {
  1979. $cache[$table['name']][$key][$k] = $v;
  1980. }
  1981. }
  1982. }
  1983. }
  1984. // Remove Current Database
  1985. $GLOBALS['file_db'] = null;
  1986. $pathDigest = pathinfo($db_path.'users.db');
  1987. if (file_exists($db_path.'users.db')) {
  1988. rename($db_path.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'['.date('Y-m-d_H-i-s').']'.($oldVerNum?'['.$oldVerNum.']':'').'.bak.db');
  1989. }
  1990. // Create New Database
  1991. $success = createSQLiteDB($db_path);
  1992. // Restore Items
  1993. if ($success) {
  1994. foreach($cache as $table => $tableData) {
  1995. if ($tableData) {
  1996. $queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
  1997. $insertValues = array();
  1998. reset($tableData);
  1999. foreach($tableData as $key => $value) {
  2000. $insertValues[] = '('.implode(',',array_map(function($d) {
  2001. return (isset($d)?$GLOBALS['file_db']->quote($d):'null');
  2002. }, $value)).')';
  2003. }
  2004. $GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
  2005. }
  2006. }
  2007. writeLog("success", "database values have been updated");
  2008. return true;
  2009. } else {
  2010. writeLog("error", "database values unable to be updated");
  2011. return false;
  2012. }
  2013. }
  2014. // Commit colours to database
  2015. function updateDBOptions($values) {
  2016. if (!isset($GLOBALS['file_db'])) {
  2017. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2018. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2019. }
  2020. // Commit new values to database
  2021. if ($GLOBALS['file_db']->query('UPDATE options SET '.implode(',',array_map(function($d, $k) {
  2022. return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
  2023. }, $values, array_keys($values))).';')->rowCount()) {
  2024. return true;
  2025. } else if ($GLOBALS['file_db']->query('INSERT OR IGNORE INTO options (`'.implode('`,`',array_keys($values)).'`) VALUES (\''.implode("','",$values).'\');')->rowCount()) {
  2026. writeLog("success", "database values for options table have been updated");
  2027. return true;
  2028. } else {
  2029. writeLog("error", "database values for options table unable to be updated");
  2030. return false;
  2031. }
  2032. }
  2033. // Send AJAX notification
  2034. function sendNotification($success, $message = false, $send = true) {
  2035. $notifyExplode = explode("-", NOTIFYEFFECT);
  2036. if ($success) {
  2037. $msg = array(
  2038. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
  2039. 'icon' => 'floppy-o',
  2040. 'type' => 'success',
  2041. 'length' => '5000',
  2042. 'layout' => $notifyExplode[0],
  2043. 'effect' => $notifyExplode[1],
  2044. );
  2045. } else {
  2046. $msg = array(
  2047. 'html' => ($message?''.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
  2048. 'icon' => 'floppy-o',
  2049. 'type' => 'failed',
  2050. 'length' => '5000',
  2051. 'layout' => $notifyExplode[0],
  2052. 'effect' => $notifyExplode[1],
  2053. );
  2054. }
  2055. // Send and kill script?
  2056. if ($send) {
  2057. header('Content-Type: application/json');
  2058. echo json_encode(array('notify'=>$msg));
  2059. die();
  2060. }
  2061. return $msg;
  2062. }
  2063. // Load colours from the database
  2064. function loadAppearance() {
  2065. // Defaults
  2066. $defaults = array(
  2067. 'title' => 'Organizr',
  2068. 'topbartext' => '#66D9EF',
  2069. 'topbar' => '#333333',
  2070. 'bottombar' => '#333333',
  2071. 'sidebar' => '#393939',
  2072. 'hoverbg' => '#AD80FD',
  2073. 'activetabBG' => '#F92671',
  2074. 'activetabicon' => '#FFFFFF',
  2075. 'activetabtext' => '#FFFFFF',
  2076. 'inactiveicon' => '#66D9EF',
  2077. 'inactivetext' => '#66D9EF',
  2078. 'loading' => '#66D9EF',
  2079. 'hovertext' => '#000000',
  2080. );
  2081. if (DATABASE_LOCATION) {
  2082. if(is_file(DATABASE_LOCATION.'users.db') && filesize(DATABASE_LOCATION.'users.db') > 0){
  2083. if (!isset($GLOBALS['file_db'])) {
  2084. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2085. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2086. }
  2087. // Database Lookup
  2088. $options = $GLOBALS['file_db']->query('SELECT * FROM options');
  2089. // Replace defaults with filled options
  2090. foreach($options as $row) {
  2091. foreach($defaults as $key => $value) {
  2092. if (isset($row[$key]) && $row[$key]) {
  2093. $defaults[$key] = $row[$key];
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. // Return the Results
  2100. return $defaults;
  2101. }
  2102. // Delete Database
  2103. function deleteDatabase() {
  2104. unset($_COOKIE['Organizr']);
  2105. setcookie('Organizr', '', time() - 3600, '/');
  2106. unset($_COOKIE['OrganizrU']);
  2107. setcookie('OrganizrU', '', time() - 3600, '/');
  2108. $GLOBALS['file_db'] = null;
  2109. unlink(DATABASE_LOCATION.'users.db');
  2110. foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
  2111. if(is_dir($file)) {
  2112. rmdir($file);
  2113. } elseif (!is_dir($file)) {
  2114. unlink($file);
  2115. }
  2116. }
  2117. rmdir($userdirpath);
  2118. writeLog("success", "database has been deleted");
  2119. return true;
  2120. }
  2121. // Upgrade the installation
  2122. function upgradeInstall($branch = 'master') {
  2123. function downloadFile($url, $path){
  2124. ini_set('max_execution_time',0);
  2125. $folderPath = "upgrade/";
  2126. if(!mkdir($folderPath)){
  2127. writeLog("error", "organizr could not create upgrade folder");
  2128. }
  2129. $newfname = $folderPath . $path;
  2130. $file = fopen ($url, 'rb');
  2131. if ($file) {
  2132. $newf = fopen ($newfname, 'wb');
  2133. if ($newf) {
  2134. while(!feof($file)) {
  2135. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  2136. }
  2137. }
  2138. }else{
  2139. writeLog("error", "organizr could not download $url");
  2140. }
  2141. if ($file) {
  2142. fclose($file);
  2143. writeLog("success", "organizr finished downloading the github zip file");
  2144. }else{
  2145. writeLog("error", "organizr could not download the github zip file");
  2146. }
  2147. if ($newf) {
  2148. fclose($newf);
  2149. writeLog("success", "organizr created upgrade zip file from github zip file");
  2150. }else{
  2151. writeLog("error", "organizr could not create upgrade zip file from github zip file");
  2152. }
  2153. }
  2154. function unzipFile($zipFile){
  2155. $zip = new ZipArchive;
  2156. $extractPath = "upgrade/";
  2157. if($zip->open($extractPath . $zipFile) != "true"){
  2158. writeLog("error", "organizr could not unzip upgrade.zip");
  2159. }else{
  2160. writeLog("success", "organizr unzipped upgrade.zip");
  2161. }
  2162. /* Extract Zip File */
  2163. $zip->extractTo($extractPath);
  2164. $zip->close();
  2165. }
  2166. // Function to remove folders and files
  2167. function rrmdir($dir) {
  2168. if (is_dir($dir)) {
  2169. $files = scandir($dir);
  2170. foreach ($files as $file)
  2171. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  2172. rmdir($dir);
  2173. }
  2174. else if (file_exists($dir)) unlink($dir);
  2175. }
  2176. // Function to Copy folders and files
  2177. function rcopy($src, $dst) {
  2178. if (is_dir ( $src )) {
  2179. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  2180. $files = scandir ( $src );
  2181. foreach ( $files as $file )
  2182. if ($file != "." && $file != "..")
  2183. rcopy ( "$src/$file", "$dst/$file" );
  2184. } else if (file_exists ( $src ))
  2185. copy ( $src, $dst );
  2186. }
  2187. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  2188. $file = "upgrade.zip";
  2189. $source = __DIR__ . '/upgrade/Organizr-'.$branch.'/';
  2190. $cleanup = __DIR__ . "/upgrade/";
  2191. $destination = __DIR__ . "/";
  2192. writeLog("success", "starting organizr upgrade process");
  2193. downloadFile($url, $file);
  2194. unzipFile($file);
  2195. rcopy($source, $destination);
  2196. writeLog("success", "new organizr files copied");
  2197. rrmdir($cleanup);
  2198. writeLog("success", "organizr upgrade folder removed");
  2199. writeLog("success", "organizr has been updated");
  2200. return true;
  2201. }
  2202. // NzbGET Items
  2203. function nzbgetConnect($list = 'listgroups') {
  2204. $url = qualifyURL(NZBGETURL);
  2205. $api = curl_get($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);
  2206. $api = json_decode($api, true);
  2207. $gotNZB = array();
  2208. if (is_array($api) || is_object($api)){
  2209. foreach ($api['result'] AS $child) {
  2210. $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
  2211. $downloadStatus = $child['Status'];
  2212. $downloadCategory = $child['Category'];
  2213. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  2214. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  2215. if($child['Health'] <= "750"){
  2216. $downloadHealth = "danger";
  2217. }elseif($child['Health'] <= "900"){
  2218. $downloadHealth = "warning";
  2219. }elseif($child['Health'] <= "1000"){
  2220. $downloadHealth = "success";
  2221. }
  2222. $gotNZB[] = '<tr>
  2223. <td class="col-xs-7 nzbtable-file-row">'.$downloadName.'</td>
  2224. <td class="col-xs-2 nzbtable nzbtable-row">'.$downloadStatus.'</td>
  2225. <td class="col-xs-1 nzbtable nzbtable-row">'.$downloadCategory.'</td>
  2226. <td class="col-xs-2 nzbtable nzbtable-row">
  2227. <div class="progress">
  2228. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2229. <p class="text-center">'.round($downloadPercent).'%</p>
  2230. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2231. </div>
  2232. </div>
  2233. </td>
  2234. </tr>';
  2235. }
  2236. if ($gotNZB) {
  2237. return implode('',$gotNZB);
  2238. } else {
  2239. return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
  2240. }
  2241. }else{
  2242. writeLog("error", "NZBGET ERROR: could not connect - check URL and/or check token and/or Usernamd and Password - if HTTPS, is cert valid");
  2243. }
  2244. }
  2245. // Sabnzbd Items
  2246. function sabnzbdConnect($list = 'queue') {
  2247. $url = qualifyURL(SABNZBDURL);
  2248. $api = file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY);
  2249. $api = json_decode($api, true);
  2250. $gotNZB = array();
  2251. foreach ($api[$list]['slots'] AS $child) {
  2252. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  2253. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  2254. $downloadStatus = $child['status'];
  2255. $gotNZB[] = '<tr>
  2256. <td>'.$downloadName.'</td>
  2257. <td>'.$downloadStatus.'</td>
  2258. <td>'.$downloadCategory.'</td>
  2259. <td>
  2260. <div class="progress">
  2261. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  2262. <p class="text-center">'.round($downloadPercent).'%</p>
  2263. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  2264. </div>
  2265. </div>
  2266. </td>
  2267. </tr>';
  2268. }
  2269. if ($gotNZB) {
  2270. return implode('',$gotNZB);
  2271. } else {
  2272. return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
  2273. }
  2274. }
  2275. // Apply new tab settings
  2276. function updateTabs($tabs) {
  2277. if (!isset($GLOBALS['file_db'])) {
  2278. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  2279. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  2280. }
  2281. // Validate
  2282. if (!isset($tabs['defaultz'])) { $tabs['defaultz'][current(array_keys($tabs['name']))] = 'true'; }
  2283. if (isset($tabs['name']) && isset($tabs['url']) && is_array($tabs['name'])) {
  2284. // Clear Existing Tabs
  2285. $GLOBALS['file_db']->query("DELETE FROM tabs");
  2286. // Process New Tabs
  2287. $totalValid = 0;
  2288. foreach ($tabs['name'] as $key => $value) {
  2289. // Qualify
  2290. if (!$value || !isset($tabs['url']) || !$tabs['url'][$key]) { continue; }
  2291. $totalValid++;
  2292. $fields = array();
  2293. foreach(array('id','name','url','icon','iconurl','order') as $v) {
  2294. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = $tabs[$v][$key]; }
  2295. }
  2296. foreach(array('active','user','guest','defaultz','window') as $v) {
  2297. if (isset($tabs[$v]) && isset($tabs[$v][$key])) { $fields[$v] = ($tabs[$v][$key]!=='false'?'true':'false'); }
  2298. }
  2299. $GLOBALS['file_db']->query('INSERT INTO tabs (`'.implode('`,`',array_keys($fields)).'`) VALUES (\''.implode("','",$fields).'\');');
  2300. }
  2301. writeLog("success", "tabs successfully saved");
  2302. return $totalValid;
  2303. } else {
  2304. writeLog("error", "tabs could not save");
  2305. return false;
  2306. }
  2307. writeLog("error", "tabs could not save");
  2308. return false;
  2309. }
  2310. // ==============
  2311. function clean($strin) {
  2312. $strout = null;
  2313. for ($i = 0; $i < strlen($strin); $i++) {
  2314. $ord = ord($strin[$i]);
  2315. if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
  2316. $strout .= "&amp;#{$ord};";
  2317. }
  2318. else {
  2319. switch ($strin[$i]) {
  2320. case '<':
  2321. $strout .= '&lt;';
  2322. break;
  2323. case '>':
  2324. $strout .= '&gt;';
  2325. break;
  2326. case '&':
  2327. $strout .= '&amp;';
  2328. break;
  2329. case '"':
  2330. $strout .= '&quot;';
  2331. break;
  2332. default:
  2333. $strout .= $strin[$i];
  2334. }
  2335. }
  2336. }
  2337. return $strout;
  2338. }
  2339. function registration_callback($username, $email, $userdir){
  2340. global $data;
  2341. $data = array($username, $email, $userdir);
  2342. }
  2343. function printArray($arrayName){
  2344. $messageCount = count($arrayName);
  2345. $i = 0;
  2346. foreach ( $arrayName as $item ) :
  2347. $i++;
  2348. if($i < $messageCount) :
  2349. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  2350. elseif($i = $messageCount) :
  2351. echo "<small class='text-uppercase'>" . $item . "</small>";
  2352. endif;
  2353. endforeach;
  2354. }
  2355. function write_ini_file($content, $path) {
  2356. if (!$handle = fopen($path, 'w')) {
  2357. return false;
  2358. }
  2359. $success = fwrite($handle, trim($content));
  2360. fclose($handle);
  2361. return $success;
  2362. }
  2363. function gotTimezone(){
  2364. $regions = array(
  2365. 'Africa' => DateTimeZone::AFRICA,
  2366. 'America' => DateTimeZone::AMERICA,
  2367. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2368. 'Arctic' => DateTimeZone::ARCTIC,
  2369. 'Asia' => DateTimeZone::ASIA,
  2370. 'Atlantic' => DateTimeZone::ATLANTIC,
  2371. 'Australia' => DateTimeZone::AUSTRALIA,
  2372. 'Europe' => DateTimeZone::EUROPE,
  2373. 'Indian' => DateTimeZone::INDIAN,
  2374. 'Pacific' => DateTimeZone::PACIFIC
  2375. );
  2376. $timezones = array();
  2377. foreach ($regions as $name => $mask) {
  2378. $zones = DateTimeZone::listIdentifiers($mask);
  2379. foreach($zones as $timezone) {
  2380. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2381. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2382. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2383. }
  2384. }
  2385. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  2386. foreach($timezones as $region => $list) {
  2387. print '<optgroup label="' . $region . '">' . "\n";
  2388. foreach($list as $timezone => $name) {
  2389. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  2390. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  2391. }
  2392. print '</optgroup>' . "\n";
  2393. }
  2394. print '</select>';
  2395. }
  2396. function getTimezone(){
  2397. $regions = array(
  2398. 'Africa' => DateTimeZone::AFRICA,
  2399. 'America' => DateTimeZone::AMERICA,
  2400. 'Antarctica' => DateTimeZone::ANTARCTICA,
  2401. 'Arctic' => DateTimeZone::ARCTIC,
  2402. 'Asia' => DateTimeZone::ASIA,
  2403. 'Atlantic' => DateTimeZone::ATLANTIC,
  2404. 'Australia' => DateTimeZone::AUSTRALIA,
  2405. 'Europe' => DateTimeZone::EUROPE,
  2406. 'Indian' => DateTimeZone::INDIAN,
  2407. 'Pacific' => DateTimeZone::PACIFIC
  2408. );
  2409. $timezones = array();
  2410. foreach ($regions as $name => $mask) {
  2411. $zones = DateTimeZone::listIdentifiers($mask);
  2412. foreach($zones as $timezone) {
  2413. $time = new DateTime(NULL, new DateTimeZone($timezone));
  2414. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  2415. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  2416. }
  2417. }
  2418. print '<select name="timezone" id="timezone" class="form-control material" required>';
  2419. foreach($timezones as $region => $list) {
  2420. print '<optgroup label="' . $region . '">' . "\n";
  2421. foreach($list as $timezone => $name) {
  2422. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  2423. }
  2424. print '</optgroup>' . "\n";
  2425. }
  2426. print '</select>';
  2427. }
  2428. function explosion($string, $position){
  2429. $getWord = explode("|", $string);
  2430. return $getWord[$position];
  2431. }
  2432. function getServerPath() {
  2433. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https"){
  2434. $protocol = "https://";
  2435. }elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  2436. $protocol = "https://";
  2437. } else {
  2438. $protocol = "http://";
  2439. }
  2440. $domain = '';
  2441. if (isset($_SERVER['SERVER_NAME']) && strpos($_SERVER['SERVER_NAME'], '.') !== false){
  2442. $domain = $_SERVER['SERVER_NAME'];
  2443. }elseif(isset($_SERVER['HTTP_HOST'])){
  2444. if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
  2445. $domain = explode(':', $_SERVER['HTTP_HOST'])[0];
  2446. $port = explode(':', $_SERVER['HTTP_HOST'])[1];
  2447. if ($port == "80" || $port == "443"){
  2448. $domain = $domain;
  2449. }else{
  2450. $domain = $_SERVER['HTTP_HOST'];
  2451. }
  2452. }else{
  2453. $domain = $_SERVER['HTTP_HOST'];
  2454. }
  2455. }
  2456. return $protocol . $domain . dirname($_SERVER['REQUEST_URI']);
  2457. }
  2458. function get_browser_name() {
  2459. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2460. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  2461. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  2462. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  2463. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  2464. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  2465. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  2466. return 'Other';
  2467. }
  2468. function getSickrageCalendarWanted($array){
  2469. $array = json_decode($array, true);
  2470. //$gotCalendar = "";
  2471. $gotCalendar = array();
  2472. $i = 0;
  2473. foreach($array['data']['missed'] AS $child) {
  2474. $i++;
  2475. $seriesName = $child['show_name'];
  2476. $episodeID = $child['tvdbid'];
  2477. $episodeAirDate = $child['airdate'];
  2478. $episodeAirDateTime = explode(" ",$child['airs']);
  2479. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2480. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2481. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2482. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2483. $downloaded = "0";
  2484. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2485. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2486. array_push($gotCalendar, array(
  2487. "id" => "Sick-Miss-".$i,
  2488. "title" => $seriesName,
  2489. "start" => $episodeAirDate,
  2490. "className" => $downloaded." tvID--".$episodeID,
  2491. "imagetype" => "tv",
  2492. ));
  2493. }
  2494. foreach($array['data']['today'] AS $child) {
  2495. $i++;
  2496. $seriesName = $child['show_name'];
  2497. $episodeID = $child['tvdbid'];
  2498. $episodeAirDate = $child['airdate'];
  2499. $episodeAirDateTime = explode(" ",$child['airs']);
  2500. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2501. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2502. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2503. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2504. $downloaded = "0";
  2505. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2506. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2507. array_push($gotCalendar, array(
  2508. "id" => "Sick-Today-".$i,
  2509. "title" => $seriesName,
  2510. "start" => $episodeAirDate,
  2511. "className" => $downloaded." tvID--".$episodeID,
  2512. "imagetype" => "tv",
  2513. ));
  2514. }
  2515. foreach($array['data']['soon'] AS $child) {
  2516. $i++;
  2517. $seriesName = $child['show_name'];
  2518. $episodeID = $child['tvdbid'];
  2519. $episodeAirDate = $child['airdate'];
  2520. $episodeAirDateTime = explode(" ",$child['airs']);
  2521. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2522. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2523. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2524. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2525. $downloaded = "0";
  2526. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2527. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2528. array_push($gotCalendar, array(
  2529. "id" => "Sick-Soon-".$i,
  2530. "title" => $seriesName,
  2531. "start" => $episodeAirDate,
  2532. "className" => $downloaded." tvID--".$episodeID,
  2533. "imagetype" => "tv",
  2534. ));
  2535. }
  2536. foreach($array['data']['later'] AS $child) {
  2537. $i++;
  2538. $seriesName = $child['show_name'];
  2539. $episodeID = $child['tvdbid'];
  2540. $episodeAirDate = $child['airdate'];
  2541. $episodeAirDateTime = explode(" ",$child['airs']);
  2542. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  2543. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  2544. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2545. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2546. $downloaded = "0";
  2547. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  2548. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2549. array_push($gotCalendar, array(
  2550. "id" => "Sick-Later-".$i,
  2551. "title" => $seriesName,
  2552. "start" => $episodeAirDate,
  2553. "className" => $downloaded." tvID--".$episodeID,
  2554. "imagetype" => "tv",
  2555. ));
  2556. }
  2557. if ($i != 0){ return $gotCalendar; }
  2558. }
  2559. function getSickrageCalendarHistory($array){
  2560. $array = json_decode($array, true);
  2561. //$gotCalendar = "";
  2562. $gotCalendar = array();
  2563. $i = 0;
  2564. foreach($array['data'] AS $child) {
  2565. $i++;
  2566. $seriesName = $child['show_name'];
  2567. $episodeID = $child['tvdbid'];
  2568. $episodeAirDate = $child['date'];
  2569. $downloaded = "green-bg";
  2570. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2571. array_push($gotCalendar, array(
  2572. "id" => "Sick-History-".$i,
  2573. "title" => $seriesName,
  2574. "start" => $episodeAirDate,
  2575. "className" => $downloaded." tvID--".$episodeID,
  2576. "imagetype" => "tv",
  2577. ));
  2578. }
  2579. if ($i != 0){ return $gotCalendar; }
  2580. }
  2581. function getSonarrCalendar($array){
  2582. $array = json_decode($array, true);
  2583. //$gotCalendar = "";
  2584. $gotCalendar = array();
  2585. $i = 0;
  2586. foreach($array AS $child) {
  2587. $i++;
  2588. $seriesName = $child['series']['title'];
  2589. $episodeID = $child['series']['tvdbId'];
  2590. if(!isset($episodeID)){ $episodeID = ""; }
  2591. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  2592. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  2593. $episodeAirDate = $child['airDateUtc'];
  2594. $episodeAirDate = strtotime($episodeAirDate);
  2595. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  2596. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  2597. $downloaded = $child['hasFile'];
  2598. 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"; }
  2599. //$gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded tvID--$episodeID\", imagetype: \"tv\" }, \n";
  2600. array_push($gotCalendar, array(
  2601. "id" => "Sonarr-".$i,
  2602. "title" => $seriesName,
  2603. "start" => $episodeAirDate,
  2604. "className" => $downloaded." tvID--".$episodeID,
  2605. "imagetype" => "tv",
  2606. ));
  2607. }
  2608. if ($i != 0){ return $gotCalendar; }
  2609. }
  2610. function getRadarrCalendar($array){
  2611. $array = json_decode($array, true);
  2612. $gotCalendar = array();
  2613. $i = 0;
  2614. foreach($array AS $child) {
  2615. if(isset($child['physicalRelease'])){
  2616. $i++;
  2617. $movieName = $child['title'];
  2618. $movieID = $child['tmdbId'];
  2619. if(!isset($movieID)){ $movieID = ""; }
  2620. $physicalRelease = $child['physicalRelease'];
  2621. $physicalRelease = strtotime($physicalRelease);
  2622. $physicalRelease = date("Y-m-d", $physicalRelease);
  2623. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2624. $downloaded = $child['hasFile'];
  2625. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  2626. array_push($gotCalendar, array(
  2627. "id" => "Radarr-".$i,
  2628. "title" => $movieName,
  2629. "start" => $physicalRelease,
  2630. "className" => $downloaded." movieID--".$movieID,
  2631. "imagetype" => "film",
  2632. ));
  2633. }
  2634. }
  2635. if ($i != 0){ return $gotCalendar; }
  2636. }
  2637. function getHeadphonesCalendar($url, $key, $list){
  2638. $url = qualifyURL(HEADPHONESURL);
  2639. $api = curl_get($url."/api?apikey=".$key."&cmd=$list");
  2640. $api = json_decode($api, true);
  2641. $i = 0;
  2642. //$gotCalendar = "";
  2643. $gotCalendar = array();;
  2644. if (is_array($api) || is_object($api)){
  2645. foreach($api AS $child) {
  2646. if($child['Status'] == "Wanted" && $list == "getWanted" && $child['ReleaseDate']){
  2647. $i++;
  2648. $albumName = addslashes($child['AlbumTitle']);
  2649. $albumArtist = htmlentities($child['ArtistName'], ENT_QUOTES);
  2650. $albumDate = (strlen($child['ReleaseDate']) > 4) ? $child['ReleaseDate'] : $child['ReleaseDate']."-01-01";
  2651. $albumID = $child['AlbumID'];
  2652. $albumDate = strtotime($albumDate);
  2653. $albumDate = date("Y-m-d", $albumDate);
  2654. $albumStatus = $child['Status'];
  2655. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2656. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  2657. //$gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2658. array_push($gotCalendar, array(
  2659. "id" => "Headphones-".$i,
  2660. "title" => $albumArtist.' - '.$albumName,
  2661. "start" => $albumDate,
  2662. "className" => $albumStatusColor,
  2663. "imagetype" => "music",
  2664. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2665. ));
  2666. }
  2667. if($child['Status'] == "Processed" && $list == "getHistory"){
  2668. $i++;
  2669. $find = array('_','[', ']', '\n');
  2670. $replace = array(' ','(', ')', ' ');
  2671. $albumName = addslashes(str_replace($find,$replace,$child['FolderName']));
  2672. $albumDate = $child['DateAdded'];
  2673. $albumID = $child['AlbumID'];
  2674. $albumDate = strtotime($albumDate);
  2675. $albumDate = date("Y-m-d", $albumDate);
  2676. $albumStatusColor = "green-bg";
  2677. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  2678. //$gotCalendar .= "{ title: \"$albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\", url: \"https://musicbrainz.org/release-group/$albumID\" }, \n";
  2679. array_push($gotCalendar, array(
  2680. "id" => "Headphones-".$i,
  2681. "title" => $albumName,
  2682. "start" => $albumDate,
  2683. "className" => $albumStatusColor,
  2684. "imagetype" => "music",
  2685. 'url' => "https://musicbrainz.org/release-group/".$albumID,
  2686. ));
  2687. }
  2688. }
  2689. if ($i != 0){ return $gotCalendar; }
  2690. }else{
  2691. writeLog("error", "HEADPHONES $list ERROR: could not connect - check URL and/or check API key - if HTTPS, is cert valid");
  2692. }
  2693. }
  2694. function checkRootPath($string){
  2695. if($string == "\\" || $string == "/"){
  2696. return "/";
  2697. }else{
  2698. return str_replace("\\", "/", $string) . "/";
  2699. }
  2700. }
  2701. function strip($string){
  2702. $string = strip_tags($string);
  2703. return preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $string));
  2704. }
  2705. function writeLog($type, $message){
  2706. $message = date("Y-m-d H:i:s")."|".$type."|".strip($message)."\n";
  2707. file_put_contents("org.log", $message, FILE_APPEND | LOCK_EX);
  2708. }
  2709. function readLog(){
  2710. $log = file("org.log");
  2711. $log = array_reverse($log);
  2712. foreach($log as $line){
  2713. $line = explode("|", strip($line));
  2714. $line[1] = ($line[1] == "error") ? '<span class="label label-danger">Error</span>' : '<span class="label label-primary">Success</span>';
  2715. echo "<tr><td>".$line[0]."</td><td>".$line[2]."</td><td>".$line[1]."</td></tr>";
  2716. }
  2717. }
  2718. function buildStream($array){
  2719. $result = "";
  2720. if (array_key_exists('platform', $array)) {
  2721. $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>';
  2722. }
  2723. if (array_key_exists('device', $array)) {
  2724. $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"></i>'.$array['device'].'</span></div></div><div class="clearfix"></div>';
  2725. }
  2726. if (array_key_exists('stream', $array)) {
  2727. $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"></i>'.$array['stream'].'</span></div></div><div class="clearfix"></div>';
  2728. }
  2729. if (array_key_exists('video', $array)) {
  2730. $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"></i>'.$array['video'].'</span></div></div><div class="clearfix"></div>';
  2731. }
  2732. if (array_key_exists('audio', $array)) {
  2733. $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"></i>'.$array['audio'].'</span></div></div><div class="clearfix"></div>';
  2734. }
  2735. return $result;
  2736. }
  2737. function streamType($value){
  2738. if($value == "transcode" || $value == "Transcode"){
  2739. return "Transcode";
  2740. }elseif($value == "copy" || $value == "DirectStream"){
  2741. return "Direct Stream";
  2742. }elseif($value == "directplay" || $value == "DirectPlay"){
  2743. return "Direct Play";
  2744. }else{
  2745. return "Direct Play";
  2746. }
  2747. }
  2748. function getPlatform($platform){
  2749. $allPlatforms = array(
  2750. "Chrome" => "chrome.png",
  2751. "tvOS" => "atv.png",
  2752. "iOS" => "ios.png",
  2753. "Xbox One" => "xbox.png",
  2754. "Mystery 4" => "playstation.png",
  2755. "Samsung" => "samsung.png",
  2756. "Roku" => "roku.png",
  2757. "Emby for iOS" => "ios.png",
  2758. "Emby Mobile" => "emby.png",
  2759. "Emby Theater" => "emby.png",
  2760. "Emby Classic" => "emby.png",
  2761. "Safari" => "safari.png",
  2762. "Android" => "android.png",
  2763. "AndroidTv" => "android.png",
  2764. "Chromecast" => "chromecast.png",
  2765. "Dashboard" => "emby.png",
  2766. "Dlna" => "dlna.png",
  2767. "Windows Phone" => "wp.png",
  2768. "Windows RT" => "win8.png",
  2769. "Kodi" => "kodi.png",
  2770. );
  2771. if (array_key_exists($platform, $allPlatforms)) {
  2772. return $allPlatforms[$platform];
  2773. }else{
  2774. return "pmp.png";
  2775. }
  2776. }
  2777. function getServer(){
  2778. $server = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
  2779. return $server;
  2780. }
  2781. function prettyPrint($array) {
  2782. echo "<pre>";
  2783. print_r($array);
  2784. echo "</pre>";
  2785. echo "<br/>";
  2786. }
  2787. function checkFrame($array, $url){
  2788. if(array_key_exists("x-frame-options", $array)){
  2789. if($array['x-frame-options'] == "deny"){
  2790. return false;
  2791. }elseif($array['x-frame-options'] == "sameorgin"){
  2792. $digest = parse_url($url);
  2793. $host = (isset($digest['host'])?$digest['host']:'');
  2794. if(getServer() == $host){
  2795. return true;
  2796. }else{
  2797. return false;
  2798. }
  2799. }
  2800. }else{
  2801. if(!$array){
  2802. return false;
  2803. }
  2804. return true;
  2805. }
  2806. }
  2807. function frameTest($url){
  2808. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  2809. $url = qualifyURL($url);
  2810. if(checkFrame($array, $url)){
  2811. return true;
  2812. }else{
  2813. return false;
  2814. }
  2815. }
  2816. function sendResult($result, $icon = "floppy-o", $message = false, $success = "WAS_SUCCESSFUL", $fail = "HAS_FAILED", $send = true) {
  2817. $notifyExplode = explode("-", NOTIFYEFFECT);
  2818. if ($result) {
  2819. $msg = array(
  2820. 'html' => ($message?''.$message.' <strong>'.translate($success).'</strong>':'<strong>'.translate($success).'</strong>'),
  2821. 'icon' => $icon,
  2822. 'type' => 'success',
  2823. 'length' => '5000',
  2824. 'layout' => $notifyExplode[0],
  2825. 'effect' => $notifyExplode[1],
  2826. );
  2827. } else {
  2828. $msg = array(
  2829. 'html' => ($message?''.$message.' <strong>'.translate($fail).'</strong>':'<strong>'.translate($fail).'</strong>'),
  2830. 'icon' => $icon,
  2831. 'type' => 'error',
  2832. 'length' => '5000',
  2833. 'layout' => $notifyExplode[0],
  2834. 'effect' => $notifyExplode[1],
  2835. );
  2836. }
  2837. // Send and kill script?
  2838. if ($send) {
  2839. header('Content-Type: application/json');
  2840. echo json_encode(array('notify'=>$msg));
  2841. die();
  2842. }
  2843. return $msg;
  2844. }
  2845. function buildHomepageNotice($layout, $type, $title, $message){
  2846. switch ($layout) {
  2847. case 'elegant':
  2848. return '
  2849. <div id="homepageNotice" class="row">
  2850. <div class="col-lg-12">
  2851. <div class="content-box big-box box-shadow panel-box panel-'.$type.'">
  2852. <div class="content-title i-block">
  2853. <h4 class="zero-m"><strong>'.$title.'</strong></h4>
  2854. <div class="content-tools i-block pull-right">
  2855. <a class="close-btn">
  2856. <i class="fa fa-times"></i>
  2857. </a>
  2858. </div>
  2859. </div>
  2860. '.$message.'
  2861. </div>
  2862. </div>
  2863. </div>
  2864. ';
  2865. break;
  2866. case 'basic':
  2867. return '
  2868. <div id="homepageNotice" class="row">
  2869. <div class="col-lg-12">
  2870. <div class="panel panel-'.$type.'">
  2871. <div class="panel-heading">
  2872. <h3 class="panel-title">'.$title.'</h3>
  2873. </div>
  2874. <div class="panel-body">
  2875. '.$message.'
  2876. </div>
  2877. </div>
  2878. </div>
  2879. </div>
  2880. ';
  2881. break;
  2882. case 'jumbotron';
  2883. return '
  2884. <div id="homepageNotice" class="row">
  2885. <div class="col-lg-12">
  2886. <div class="jumbotron">
  2887. <div class="container">
  2888. <h1>'.$title.'</h1>
  2889. <p>'.$message.'</p>
  2890. </div>
  2891. </div>
  2892. </div>
  2893. </div>
  2894. ';
  2895. }
  2896. }
  2897. function embyArray($array, $type) {
  2898. $key = ($type == "video" ? "Height" : "Channels");
  2899. if (array_key_exists($key, $array)) {
  2900. switch ($type) {
  2901. case "video":
  2902. $codec = $array["Codec"];
  2903. $height = $array["Height"];
  2904. $width = $array["Width"];
  2905. break;
  2906. default:
  2907. $codec = $array["Codec"];
  2908. $channels = $array["Channels"];
  2909. }
  2910. return ($type == "video" ? "(".$codec.") (".$width."x".$height.")" : "(".$codec.") (".$channels."ch)");
  2911. }
  2912. foreach ($array as $element) {
  2913. if (is_array($element)) {
  2914. if (embyArray($element, $type)) {
  2915. return embyArray($element, $type);
  2916. }
  2917. }
  2918. }
  2919. }
  2920. // Get Now Playing Streams From Plex
  2921. function searchPlex($query){
  2922. $address = qualifyURL(PLEXURL);
  2923. $openTab = (PLEXTABNAME) ? "true" : "false";
  2924. // Perform API requests
  2925. $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
  2926. $api = simplexml_load_string($api);
  2927. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  2928. if (!$getServer) { return 'Could not load!'; }
  2929. // Identify the local machine
  2930. $server = $getServer['machineIdentifier'];
  2931. $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>";
  2932. $items = "";
  2933. $albums = $movies = $shows = 0;
  2934. $style = 'style="vertical-align: middle"';
  2935. foreach($api AS $child) {
  2936. if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
  2937. $time = (string)$child['addedAt'];
  2938. $time = new DateTime("@$time");
  2939. $results = array(
  2940. "title" => (string)$child['title'],
  2941. "image" => (string)$child['thumb'],
  2942. "type" => (string)ucwords($child['type']),
  2943. "year" => (string)$child['year'],
  2944. "key" => (string)$child['ratingKey']."-search",
  2945. "ratingkey" => (string)$child['ratingKey'],
  2946. "genre" => (string)$child->Genre['tag'],
  2947. "added" => $time->format('Y-m-d'),
  2948. "extra" => "",
  2949. );
  2950. switch ($child['type']){
  2951. case "album":
  2952. $push = array(
  2953. "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
  2954. );
  2955. $results = array_replace($results,$push);
  2956. $albums++;
  2957. break;
  2958. case "movie":
  2959. $push = array(
  2960. "extra" => "Content Rating: ".(string)$child['contentRating']."<br/>Movie Rating: ".(string)$child['rating'],
  2961. );
  2962. $results = array_replace($results,$push);
  2963. $movies++;
  2964. break;
  2965. case "show":
  2966. $push = array(
  2967. "extra" => "Seasons: ".(string)$child['childCount']."<br/>Episodes: ".(string)$child['leafCount'],
  2968. );
  2969. $results = array_replace($results,$push);
  2970. $shows++;
  2971. break;
  2972. }
  2973. if (file_exists('images/cache/'.$results['key'].'.jpg')){ $image_url = 'images/cache/'.$results['key'].'.jpg'; }
  2974. if (file_exists('images/cache/'.$results['key'].'.jpg') && (time() - 604800) > filemtime('images/cache/'.$results['key'].'.jpg') || !file_exists('images/cache/'.$results['key'].'.jpg')) {
  2975. $image_url = 'ajax.php?a=plex-image&img='.$results['image'].'&height=150&width=100&key='.$results['key'];
  2976. }
  2977. if(!$results['image']){ $image_url = "images/no-search.png"; $key = "no-search"; }
  2978. if (substr_count(PLEXURL, '.') != 2) {
  2979. $link = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  2980. }else{
  2981. $link = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$results['ratingkey'];
  2982. }
  2983. $items .= '<tr style="cursor: pointer;" class="openTab" extraTitle="'.$results['title'].'" extraType="'.$child['type'].'" openTab="'.$openTab.'" href="'.$link.'">
  2984. <th scope="row"><img src="'.$image_url.'"></th>
  2985. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
  2986. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
  2987. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
  2988. <td class="col-xs-1 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
  2989. <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
  2990. <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['extra'].'</td>
  2991. </tr>';
  2992. }
  2993. }
  2994. $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
  2995. <span class="badge gray-bg"><i class="fa fa-film fa-2x white"></i><strong style="
  2996. font-size: 23px;
  2997. ">&nbsp;'.$movies.'</strong></span>
  2998. <span class="badge gray-bg"><i class="fa fa-tv fa-2x white"></i><strong style="
  2999. font-size: 23px;
  3000. ">&nbsp;'.$shows.'</strong></span>
  3001. <span class="badge gray-bg"><i class="fa fa-music fa-2x white"></i><strong style="
  3002. font-size: 23px;
  3003. ">&nbsp;'.$albums.'</strong></span>
  3004. </div>';
  3005. return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
  3006. }
  3007. function getBannedUsers($string){
  3008. if (strpos($string, ',') !== false) {
  3009. $banned = explode(",", $string);
  3010. }else{
  3011. $banned = array($string);
  3012. }
  3013. return $banned;
  3014. }
  3015. function getWhitelist($string){
  3016. if (strpos($string, ',') !== false) {
  3017. $whitelist = explode(",", $string);
  3018. }else{
  3019. $whitelist = array($string);
  3020. }
  3021. foreach($whitelist as &$ip){
  3022. $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
  3023. }
  3024. return $whitelist;
  3025. }
  3026. function get_client_ip() {
  3027. $ipaddress = '';
  3028. if (isset($_SERVER['HTTP_CLIENT_IP']))
  3029. $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  3030. else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  3031. $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3032. else if(isset($_SERVER['HTTP_X_FORWARDED']))
  3033. $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  3034. else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
  3035. $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  3036. else if(isset($_SERVER['HTTP_FORWARDED']))
  3037. $ipaddress = $_SERVER['HTTP_FORWARDED'];
  3038. else if(isset($_SERVER['REMOTE_ADDR']))
  3039. $ipaddress = $_SERVER['REMOTE_ADDR'];
  3040. else
  3041. $ipaddress = 'UNKNOWN';
  3042. return $ipaddress;
  3043. }
  3044. //EMAIL SHIT
  3045. function sendEmail($email, $username = "Organizr User", $subject, $body, $cc = null){
  3046. $mail = new PHPMailer;
  3047. $mail->isSMTP();
  3048. $mail->Host = SMTPHOST;
  3049. $mail->SMTPAuth = SMTPHOSTAUTH;
  3050. $mail->Username = SMTPHOSTUSERNAME;
  3051. $mail->Password = SMTPHOSTPASSWORD;
  3052. $mail->SMTPSecure = SMTPHOSTTYPE;
  3053. $mail->Port = SMTPHOSTPORT;
  3054. $mail->setFrom(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3055. $mail->addReplyTo(SMTPHOSTSENDEREMAIL, SMTPHOSTSENDERNAME);
  3056. $mail->isHTML(true);
  3057. $mail->addAddress($email, $username);
  3058. $mail->Subject = $subject;
  3059. $mail->Body = $body;
  3060. //$mail->send();
  3061. if(!$mail->send()) {
  3062. writeLog("error", "mail failed to send");
  3063. } else {
  3064. writeLog("success", "mail has been sent");
  3065. }
  3066. }
  3067. //EMAIL SHIT
  3068. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  3069. $mail = new PHPMailer;
  3070. $mail->isSMTP();
  3071. $mail->Host = $host;
  3072. $mail->SMTPAuth = $auth;
  3073. $mail->Username = $username;
  3074. $mail->Password = $password;
  3075. $mail->SMTPSecure = $type;
  3076. $mail->Port = $port;
  3077. $mail->setFrom($from, $sendername);
  3078. $mail->addReplyTo($from, $sendername);
  3079. $mail->isHTML(true);
  3080. $mail->addAddress($to, "Organizr Admin");
  3081. $mail->Subject = "Organizr Test E-Mail";
  3082. $mail->Body = "This was just a test!";
  3083. //$mail->send();
  3084. if(!$mail->send()) {
  3085. writeLog("error", "EMAIL TEST: mail failed to send - Error:".$mail->ErrorInfo);
  3086. return false;
  3087. } else {
  3088. writeLog("success", "EMAIL TEST: mail has been sent successfully");
  3089. return true;
  3090. }
  3091. }
  3092. function libraryList(){
  3093. $address = qualifyURL(PLEXURL);
  3094. $headers = array(
  3095. "Accept" => "application/json",
  3096. "X-Plex-Token" => PLEXTOKEN
  3097. );
  3098. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3099. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3100. $api = simplexml_load_string(@curl_get("https://plex.tv/api/servers/$gotServer/shared_servers", $headers));
  3101. $libraryList = array();
  3102. foreach($api->SharedServer->Section AS $child) {
  3103. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  3104. }
  3105. foreach($api->SharedServer AS $child) {
  3106. if(!empty($child['username'])){
  3107. $username = (string)strtolower($child['username']);
  3108. $email = (string)strtolower($child['email']);
  3109. $libraryList['users'][$username] = (string)$child['id'];
  3110. $libraryList['emails'][$email] = (string)$child['id'];
  3111. }
  3112. }
  3113. return (!empty($libraryList) ? array_change_key_case($libraryList,CASE_LOWER) : null );
  3114. }
  3115. function plexUserShare($username){
  3116. $address = qualifyURL(PLEXURL);
  3117. $headers = array(
  3118. "Accept" => "application/json",
  3119. "Content-Type" => "application/json",
  3120. "X-Plex-Token" => PLEXTOKEN
  3121. );
  3122. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3123. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3124. $json = array(
  3125. "server_id" => $gotServer,
  3126. "shared_server" => array(
  3127. //"library_section_ids" => "[26527637]",
  3128. "invited_email" => $username
  3129. )
  3130. );
  3131. $api = curl_post("https://plex.tv/api/servers/$gotServer/shared_servers/", $json, $headers);
  3132. switch ($api['http_code']['http_code']){
  3133. case 400:
  3134. writeLog("error", "PLEX INVITE: $username already has access to the shared libraries");
  3135. $result = "$username already has access to the shared libraries";
  3136. break;
  3137. case 401:
  3138. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3139. $result = "Invalid Plex Token";
  3140. break;
  3141. case 200:
  3142. writeLog("success", "PLEX INVITE: $username now has access to your Plex Library");
  3143. $result = "$username now has access to your Plex Library";
  3144. break;
  3145. default:
  3146. writeLog("error", "PLEX INVITE: unknown error");
  3147. $result = false;
  3148. }
  3149. return (!empty($result) ? $result : null );
  3150. }
  3151. function plexUserDelete($username){
  3152. $address = qualifyURL(PLEXURL);
  3153. $headers = array(
  3154. "Accept" => "application/json",
  3155. "Content-Type" => "application/json",
  3156. "X-Plex-Token" => PLEXTOKEN
  3157. );
  3158. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3159. if (!$getServer) { return 'Could not load!'; }else { $gotServer = $getServer['machineIdentifier']; }
  3160. $id = (is_numeric($username) ? $id : convertPlexName($username, "id"));
  3161. $api = curl_delete("https://plex.tv/api/servers/$gotServer/shared_servers/$id", $headers);
  3162. switch ($api['http_code']['http_code']){
  3163. case 401:
  3164. writeLog("error", "PLEX INVITE: Invalid Plex Token");
  3165. $result = "Invalid Plex Token";
  3166. break;
  3167. case 200:
  3168. writeLog("success", "PLEX INVITE: $username doesn't have access to your Plex Library anymore");
  3169. $result = "$username doesn't have access to your Plex Library anymore";
  3170. break;
  3171. default:
  3172. writeLog("error", "PLEX INVITE: unknown error");
  3173. $result = false;
  3174. }
  3175. return (!empty($result) ? $result : null );
  3176. }
  3177. function convertPlexName($user, $type){
  3178. $array = libraryList();
  3179. switch ($type){
  3180. case "username":
  3181. $plexUser = array_search ($user, $array['users']);
  3182. break;
  3183. case "id":
  3184. if (array_key_exists(strtolower($user), $array['users'])) {
  3185. $plexUser = $array['users'][strtolower($user)];
  3186. }
  3187. break;
  3188. default:
  3189. $plexUser = false;
  3190. }
  3191. return (!empty($plexUser) ? $plexUser : null );
  3192. }
  3193. function randomCode($length = 5, $type = null) {
  3194. switch ($type){
  3195. case "alpha":
  3196. $legend = array_merge(range('A', 'Z'));
  3197. break;
  3198. case "numeric":
  3199. $legend = array_merge(range(0,9));
  3200. break;
  3201. default:
  3202. $legend = array_merge(range(0,9),range('A', 'Z'));
  3203. }
  3204. $code = "";
  3205. for($i=0; $i < $length; $i++) {
  3206. $code .= $legend[mt_rand(0, count($legend) - 1)];
  3207. }
  3208. return $code;
  3209. }
  3210. function inviteCodes($action, $code = null, $usedBy = null) {
  3211. if (!isset($GLOBALS['file_db'])) {
  3212. $GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
  3213. $GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3214. }
  3215. $now = date("Y-m-d H:i:s");
  3216. switch ($action) {
  3217. case "get":
  3218. // Start Array
  3219. $result = array();
  3220. // Database Lookup
  3221. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes"');
  3222. // Get Codes
  3223. foreach($invites as $row) {
  3224. array_push($result, $row['code']);
  3225. }
  3226. // Return the Results
  3227. return (!empty($result) ? $result : false );
  3228. break;
  3229. case "check":
  3230. // Start Array
  3231. $result = array();
  3232. // Database Lookup
  3233. $invites = $GLOBALS['file_db']->query('SELECT * FROM invites WHERE valid = "Yes" AND code = "'.$code.'"');
  3234. // Get Codes
  3235. foreach($invites as $row) {
  3236. $result = $row['code'];
  3237. }
  3238. // Return the Results
  3239. return (!empty($result) ? $result : false );
  3240. break;
  3241. case "use":
  3242. $currentIP = get_client_ip();
  3243. $invites = $GLOBALS['file_db']->query('UPDATE invites SET valid = "No", usedby = "'.$usedBy.'", dateused = "'.$now.'", ip = "'.$currentIP.'" WHERE code = "'.$code.'"');
  3244. return (!empty($invites) ? true : false );
  3245. break;
  3246. }
  3247. }
  3248. function plexJoin($username, $email, $password){
  3249. $connectURL = 'https://plex.tv/users.json';
  3250. $headers = array(
  3251. 'Accept'=> 'application/json',
  3252. 'Content-Type' => 'application/x-www-form-urlencoded',
  3253. 'X-Plex-Product' => 'Organizr',
  3254. 'X-Plex-Version' => '1.0',
  3255. 'X-Plex-Client-Identifier' => '01010101-10101010',
  3256. );
  3257. $body = array(
  3258. 'user[email]' => $email,
  3259. 'user[username]' => $username,
  3260. 'user[password]' => $password,
  3261. );
  3262. $api = curl_post($connectURL, $body, $headers);
  3263. $json = json_decode($api['content'], true);
  3264. $errors = (!empty($json['errors']) ? true : false);
  3265. $success = (!empty($json['user']) ? true : false);
  3266. //Use This for later
  3267. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  3268. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  3269. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  3270. switch ($api['http_code']['http_code']){
  3271. case 400:
  3272. writeLog("error", "PLEX JOIN: $username already has access to the shared libraries");
  3273. break;
  3274. case 401:
  3275. writeLog("error", "PLEX JOIN: invalid Plex Token");
  3276. break;
  3277. case 422:
  3278. writeLog("error", "PLEX JOIN: user info error");
  3279. break;
  3280. case 429:
  3281. writeLog("error", "PLEX JOIN: too many requests to plex.tv please try later");
  3282. break;
  3283. case 200:
  3284. case 201:
  3285. writeLog("success", "PLEX JOIN: $username now has access to your Plex Library");
  3286. break;
  3287. default:
  3288. writeLog("error", "PLEX JOIN: unknown error, Error: ".$api['http_code']['http_code']);
  3289. }
  3290. //prettyPrint($api);
  3291. //prettyPrint(json_decode($api['content'], true));
  3292. return (!empty($success) && empty($errors) ? true : false );
  3293. }
  3294. function getCert(){
  3295. $url = "http://curl.haxx.se/ca/cacert.pem";
  3296. $file = getcwd()."/config/cacert.pem";
  3297. $directory = getcwd()."/config/";
  3298. @mkdir($directory, 0770, true);
  3299. if(!file_exists($file)){
  3300. file_put_contents( $file, fopen($url, 'r'));
  3301. writeLog("success", "CERT PEM: pem file created");
  3302. }elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  3303. file_put_contents( $file, fopen($url, 'r'));
  3304. writeLog("success", "CERT PEM: downloaded new pem file");
  3305. }
  3306. return $file;
  3307. }
  3308. function customCSS(){
  3309. if(CUSTOMCSS == "true") {
  3310. $template_file = "custom.css";
  3311. $file_handle = fopen($template_file, "rb");
  3312. echo "\n";
  3313. echo fread($file_handle, filesize($template_file));
  3314. fclose($file_handle);
  3315. echo "\n";
  3316. }
  3317. }
  3318. function tvdbToken(){
  3319. $headers = array(
  3320. "Accept" => "application/json",
  3321. "Content-Type" => "application/json"
  3322. );
  3323. $json = array(
  3324. "apikey" => "FBE7B62621F4CAD7",
  3325. "userkey" => "328BB46EB1E9A0F5",
  3326. "username" => "causefx"
  3327. );
  3328. $api = curl_post("https://api.thetvdb.com/login", $json, $headers);
  3329. return json_decode($api['content'], true)['token'];
  3330. }
  3331. function tvdbGet($id){
  3332. $headers = array(
  3333. "Accept" => "application/json",
  3334. "Authorization" => "Bearer ".tvdbToken(),
  3335. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3336. "trakt-api-version" => "2"
  3337. );
  3338. $trakt = curl_get("https://api.trakt.tv/search/tvdb/$id?type=show", $headers);
  3339. @$api['trakt'] = json_decode($trakt, true)[0]['show']['ids'];
  3340. if(empty($api['trakt'])){
  3341. $series = curl_get("https://api.thetvdb.com/series/$id", $headers);
  3342. $poster = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=poster", $headers);
  3343. $backdrop = curl_get("https://api.thetvdb.com/series/$id/images/query?keyType=fanart", $headers);
  3344. $api['series'] = json_decode($series, true)['data'];
  3345. $api['poster'] = json_decode($poster, true)['data'];
  3346. $api['backdrop'] = json_decode($backdrop, true)['data'];
  3347. }
  3348. return $api;
  3349. }
  3350. function tvdbSearch($name, $type){
  3351. $name = rawurlencode(preg_replace("/\(([^()]*+|(?R))*\)/","", $name));
  3352. $headers = array(
  3353. "Accept" => "application/json",
  3354. "Authorization" => "Bearer ".tvdbToken(),
  3355. "trakt-api-key" => "4502cfdf8f7282fe454878ff8583f5636392cdc5fcac30d0cc4565f7173bf443",
  3356. "trakt-api-version" => "2"
  3357. );
  3358. $trakt = curl_get("https://api.trakt.tv/search/$type?query=$name", $headers);
  3359. @$api['trakt'] = json_decode($trakt, true)[0][$type]['ids'];
  3360. return $api;
  3361. }
  3362. function getPlexPlaylists(){
  3363. $address = qualifyURL(PLEXURL);
  3364. // Perform API requests
  3365. $api = @curl_get($address."/playlists?X-Plex-Token=".PLEXTOKEN);
  3366. $api = simplexml_load_string($api);
  3367. if (is_array($api) || is_object($api)){
  3368. if (!$api->head->title){
  3369. $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
  3370. if (!$getServer) { return 'Could not load!'; }
  3371. // Identify the local machine
  3372. $gotServer = $getServer['machineIdentifier'];
  3373. $output = "";
  3374. $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" class="dropdown-menu filter-recent-playlist">';
  3375. foreach($api AS $child) {
  3376. $items = array();
  3377. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  3378. $api = @curl_get($address.$child['key']."?X-Plex-Token=".PLEXTOKEN);
  3379. $api = simplexml_load_string($api);
  3380. if (is_array($api) || is_object($api)){
  3381. if (!$api->head->title){
  3382. $className = preg_replace("/(\W)+/", "", $api['title']);
  3383. $hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
  3384. foreach($api->Video AS $child){
  3385. $items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
  3386. }
  3387. if (count($items)) {
  3388. $output .= ''.implode('',$items).'';
  3389. }
  3390. }
  3391. }
  3392. }
  3393. }
  3394. $hideMenu .= '</ul></div></div>';
  3395. 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>';
  3396. }else{
  3397. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
  3398. }
  3399. }else{
  3400. writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check URL - if HTTPS, is cert valid");
  3401. }
  3402. }
  3403. function readExternalLog($type,$filename,$name = null){
  3404. $log = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  3405. $log = array_reverse($log);
  3406. foreach($log as $line){
  3407. if(!empty($line) && $line[0] != " "){
  3408. $line = strip($line);
  3409. if($type == "single"){
  3410. if( strpos( strtolower($line), "ror" ) !== false ) {
  3411. echo "<tr><td class='red-bg'>".$line."</td></tr>";
  3412. }else{
  3413. echo "<tr><td>".$line."</td></tr>";
  3414. }
  3415. }elseif($type == "all"){
  3416. if( strpos( strtolower($line), "ror" ) !== false ) {
  3417. echo "<tr><td class='red-bg'>".$name."</td>";
  3418. echo "<td class='red-bg'>".$line."</td></tr>";
  3419. }else{
  3420. echo "<tr><td>".$name."</td>";
  3421. echo "<td>".$line."</td></tr>";
  3422. }
  3423. }
  3424. }
  3425. }
  3426. }
  3427. function getLogs(){
  3428. $path = __DIR__ ."/logs/";
  3429. @mkdir($path, 0770, true);
  3430. $logs = array();
  3431. $files = array_diff(scandir($path), array('.', '..'));
  3432. foreach($files as $v){
  3433. $title = explode(".", $v)[0];
  3434. $logs[$title] = $path.$v;
  3435. }
  3436. return $logs;
  3437. }
  3438. function getBackups(){
  3439. $path = DATABASE_LOCATION ."backups/";
  3440. @mkdir($path, 0770, true);
  3441. $backups = array();
  3442. $files = array_diff(scandir($path), array('.', '..'));
  3443. return array_reverse($files);
  3444. }
  3445. function getExtension($string) {
  3446. return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
  3447. }
  3448. function showFile(){
  3449. $file = $_GET['file'];
  3450. $fileType = getExtension($file);
  3451. if($fileType != 'php'){
  3452. header("Content-type: ".mimeTypes()[$fileType]);
  3453. @readfile($file);
  3454. }
  3455. }
  3456. function getCalendar(){
  3457. $sonarr = new Sonarr(SONARRURL, SONARRKEY);
  3458. $radarr = new Sonarr(RADARRURL, RADARRKEY);
  3459. $sickrage = new SickRage(SICKRAGEURL, SICKRAGEKEY);
  3460. $startDate = date('Y-m-d',strtotime("-".CALENDARSTARTDAY." days"));
  3461. $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
  3462. $calendarItems = array();
  3463. if (SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)){
  3464. try {
  3465. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate));
  3466. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  3467. } catch (Exception $e) {
  3468. writeLog("error", "SONARR ERROR: ".strip($e->getMessage()));
  3469. }
  3470. }
  3471. if (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)){
  3472. try {
  3473. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate));
  3474. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  3475. } catch (Exception $e) {
  3476. writeLog("error", "RADARR ERROR: ".strip($e->getMessage()));
  3477. }
  3478. }
  3479. if (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)){
  3480. $headphonesHistory = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getHistory");
  3481. $headphonesWanted = getHeadphonesCalendar(HEADPHONESURL, HEADPHONESKEY, "getWanted");
  3482. if(!empty($headphonesHistory)) { $calendarItems = array_merge($calendarItems, $headphonesHistory); }
  3483. if(!empty($headphonesWanted)) { $calendarItems = array_merge($calendarItems, $headphonesWanted); }
  3484. }
  3485. if (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH)){
  3486. try {
  3487. $sickrageFuture = getSickrageCalendarWanted($sickrage->future());
  3488. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  3489. } catch (Exception $e) {
  3490. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3491. } try {
  3492. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"));
  3493. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  3494. } catch (Exception $e) {
  3495. writeLog("error", "SICKRAGE/BEARD ERROR: ".strip($e->getMessage()));
  3496. }
  3497. }
  3498. return $calendarItems;
  3499. }
  3500. function localURL($url){
  3501. if (strpos($url, 'https') !== false) {
  3502. preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $url, $result);
  3503. $result = (!empty($result) ? true : false);
  3504. return $result;
  3505. }
  3506. }
  3507. function fileArray($files){
  3508. foreach($files as $file){
  3509. if(file_exists($file)){
  3510. $list[] = $file;
  3511. }
  3512. }
  3513. if(!empty($list)){ return $list; }
  3514. }
  3515. function backupDB(){
  3516. if (extension_loaded('ZIP')) {
  3517. $directory = DATABASE_LOCATION."backups/";
  3518. @mkdir($directory, 0770, true);
  3519. $orgFiles = array(
  3520. 'css' => 'custom.css',
  3521. 'temp' => 'cus.sd',
  3522. 'orgLog' => 'org.log',
  3523. 'loginLog' => 'loginLog.json',
  3524. 'chatDB' => 'chatpack.db',
  3525. 'config' => 'config/config.php',
  3526. 'database' => DATABASE_LOCATION.'users.db'
  3527. );
  3528. $files = fileArray($orgFiles);
  3529. if(!empty($files)){
  3530. writeLog("success", "BACKUP: backup process started");
  3531. $zipname = $directory.'backup['.date('Y-m-d_H-i').']['.INSTALLEDVERSION.'].zip';
  3532. $zip = new ZipArchive;
  3533. $zip->open($zipname, ZipArchive::CREATE);
  3534. foreach ($files as $file) {
  3535. $zip->addFile($file);
  3536. }
  3537. $zip->close();
  3538. writeLog("success", "BACKUP: backup process finished");
  3539. return true;
  3540. }else{
  3541. return false;
  3542. }
  3543. }else{
  3544. return false;
  3545. }
  3546. }
  3547. function orgEmail($header = "Message From Admin", $title = "Important Message", $user = "Organizr User", $mainMessage = "", $button = null, $buttonURL = null, $subTitle = "", $subMessage = ""){
  3548. $path = getServerPath();
  3549. return '
  3550. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3551. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  3552. <head>
  3553. <!--[if gte mso 9]><xml>
  3554. <o:OfficeDocumentSettings>
  3555. <o:AllowPNG/>
  3556. <o:PixelsPerInch>96</o:PixelsPerInch>
  3557. </o:OfficeDocumentSettings>
  3558. </xml><![endif]-->
  3559. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3560. <meta name="viewport" content="width=device-width">
  3561. <!--[if !mso]><!-->
  3562. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  3563. <!--<![endif]-->
  3564. <title></title>
  3565. <!--[if !mso]><!-- -->
  3566. <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css">
  3567. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  3568. <!--<![endif]-->
  3569. <style type="text/css" id="media-query">
  3570. body {
  3571. margin: 0;
  3572. padding: 0;
  3573. }
  3574. table,
  3575. tr,
  3576. td {
  3577. vertical-align: top;
  3578. border-collapse: collapse;
  3579. }
  3580. .ie-browser table,
  3581. .mso-container table {
  3582. table-layout: fixed;
  3583. }
  3584. * {
  3585. line-height: inherit;
  3586. }
  3587. a[x-apple-data-detectors=true] {
  3588. color: inherit !important;
  3589. text-decoration: none !important;
  3590. }
  3591. [owa] .img-container div,
  3592. [owa] .img-container button {
  3593. display: block !important;
  3594. }
  3595. [owa] .fullwidth button {
  3596. width: 100% !important;
  3597. }
  3598. [owa] .block-grid .col {
  3599. display: table-cell;
  3600. float: none !important;
  3601. vertical-align: top;
  3602. }
  3603. .ie-browser .num12,
  3604. .ie-browser .block-grid,
  3605. [owa] .num12,
  3606. [owa] .block-grid {
  3607. width: 615px !important;
  3608. }
  3609. .ExternalClass,
  3610. .ExternalClass p,
  3611. .ExternalClass span,
  3612. .ExternalClass font,
  3613. .ExternalClass td,
  3614. .ExternalClass div {
  3615. line-height: 100%;
  3616. }
  3617. .ie-browser .mixed-two-up .num4,
  3618. [owa] .mixed-two-up .num4 {
  3619. width: 204px !important;
  3620. }
  3621. .ie-browser .mixed-two-up .num8,
  3622. [owa] .mixed-two-up .num8 {
  3623. width: 408px !important;
  3624. }
  3625. .ie-browser .block-grid.two-up .col,
  3626. [owa] .block-grid.two-up .col {
  3627. width: 307px !important;
  3628. }
  3629. .ie-browser .block-grid.three-up .col,
  3630. [owa] .block-grid.three-up .col {
  3631. width: 205px !important;
  3632. }
  3633. .ie-browser .block-grid.four-up .col,
  3634. [owa] .block-grid.four-up .col {
  3635. width: 153px !important;
  3636. }
  3637. .ie-browser .block-grid.five-up .col,
  3638. [owa] .block-grid.five-up .col {
  3639. width: 123px !important;
  3640. }
  3641. .ie-browser .block-grid.six-up .col,
  3642. [owa] .block-grid.six-up .col {
  3643. width: 102px !important;
  3644. }
  3645. .ie-browser .block-grid.seven-up .col,
  3646. [owa] .block-grid.seven-up .col {
  3647. width: 87px !important;
  3648. }
  3649. .ie-browser .block-grid.eight-up .col,
  3650. [owa] .block-grid.eight-up .col {
  3651. width: 76px !important;
  3652. }
  3653. .ie-browser .block-grid.nine-up .col,
  3654. [owa] .block-grid.nine-up .col {
  3655. width: 68px !important;
  3656. }
  3657. .ie-browser .block-grid.ten-up .col,
  3658. [owa] .block-grid.ten-up .col {
  3659. width: 61px !important;
  3660. }
  3661. .ie-browser .block-grid.eleven-up .col,
  3662. [owa] .block-grid.eleven-up .col {
  3663. width: 55px !important;
  3664. }
  3665. .ie-browser .block-grid.twelve-up .col,
  3666. [owa] .block-grid.twelve-up .col {
  3667. width: 51px !important;
  3668. }
  3669. @media only screen and (min-width: 635px) {
  3670. .block-grid {
  3671. width: 615px !important;
  3672. }
  3673. .block-grid .col {
  3674. display: table-cell;
  3675. Float: none !important;
  3676. vertical-align: top;
  3677. }
  3678. .block-grid .col.num12 {
  3679. width: 615px !important;
  3680. }
  3681. .block-grid.mixed-two-up .col.num4 {
  3682. width: 204px !important;
  3683. }
  3684. .block-grid.mixed-two-up .col.num8 {
  3685. width: 408px !important;
  3686. }
  3687. .block-grid.two-up .col {
  3688. width: 307px !important;
  3689. }
  3690. .block-grid.three-up .col {
  3691. width: 205px !important;
  3692. }
  3693. .block-grid.four-up .col {
  3694. width: 153px !important;
  3695. }
  3696. .block-grid.five-up .col {
  3697. width: 123px !important;
  3698. }
  3699. .block-grid.six-up .col {
  3700. width: 102px !important;
  3701. }
  3702. .block-grid.seven-up .col {
  3703. width: 87px !important;
  3704. }
  3705. .block-grid.eight-up .col {
  3706. width: 76px !important;
  3707. }
  3708. .block-grid.nine-up .col {
  3709. width: 68px !important;
  3710. }
  3711. .block-grid.ten-up .col {
  3712. width: 61px !important;
  3713. }
  3714. .block-grid.eleven-up .col {
  3715. width: 55px !important;
  3716. }
  3717. .block-grid.twelve-up .col {
  3718. width: 51px !important;
  3719. }
  3720. }
  3721. @media (max-width: 635px) {
  3722. .block-grid,
  3723. .col {
  3724. min-width: 320px !important;
  3725. max-width: 100% !important;
  3726. }
  3727. .block-grid {
  3728. width: calc(100% - 40px) !important;
  3729. }
  3730. .col {
  3731. width: 100% !important;
  3732. }
  3733. .col>div {
  3734. margin: 0 auto;
  3735. }
  3736. img.fullwidth {
  3737. max-width: 100% !important;
  3738. }
  3739. }
  3740. </style>
  3741. </head>
  3742. <body class="clean-body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #FFFFFF">
  3743. <!--[if IE]><div class="ie-browser"><![endif]-->
  3744. <!--[if mso]><div class="mso-container"><![endif]-->
  3745. <div class="nl-container" style="min-width: 320px;Margin: 0 auto;background-color: #FFFFFF">
  3746. <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #FFFFFF;"><![endif]-->
  3747. <div style="background-color:#333333;">
  3748. <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;"
  3749. class="block-grid ">
  3750. <div style="border-collapse: collapse;display: table;width: 100%;">
  3751. <!--[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]-->
  3752. <!--[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]-->
  3753. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3754. <div style="background-color: transparent; width: 100% !important;">
  3755. <!--[if (!mso)&(!IE)]><!-->
  3756. <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;">
  3757. <!--<![endif]-->
  3758. <div align="left" class="img-container left fullwidth" style="padding-right: 30px; padding-left: 30px;">
  3759. <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 30px; padding-left: 30px;" align="left"><![endif]-->
  3760. <img class="left fullwidth" align="left" border="0" src="'.$path.'images/organizr-logo-h.png" alt="Image" title="Image"
  3761. 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"
  3762. width="555">
  3763. <!--[if mso]></td></tr></table><![endif]-->
  3764. </div>
  3765. <!--[if (!mso)&(!IE)]><!-->
  3766. </div>
  3767. <!--<![endif]-->
  3768. </div>
  3769. </div>
  3770. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3771. </div>
  3772. </div>
  3773. </div>
  3774. <div style="background-color:#333333;">
  3775. <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;"
  3776. class="block-grid ">
  3777. <div style="border-collapse: collapse;display: table;width: 100%;">
  3778. <!--[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]-->
  3779. <!--[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]-->
  3780. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3781. <div style="background-color: transparent; width: 100% !important;">
  3782. <!--[if (!mso)&(!IE)]><!-->
  3783. <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;">
  3784. <!--<![endif]-->
  3785. <!--[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]-->
  3786. <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;">
  3787. <div style="font-size:12px;line-height:14px;color:#FFFFFF;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3788. <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>
  3789. </span>
  3790. </p>
  3791. </div>
  3792. </div>
  3793. <!--[if mso]></td></tr></table><![endif]-->
  3794. <!--[if (!mso)&(!IE)]><!-->
  3795. </div>
  3796. <!--<![endif]-->
  3797. </div>
  3798. </div>
  3799. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3800. </div>
  3801. </div>
  3802. </div>
  3803. <div style="background-color:#393939;">
  3804. <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;"
  3805. class="block-grid ">
  3806. <div style="border-collapse: collapse;display: table;width: 100%;">
  3807. <!--[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]-->
  3808. <!--[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]-->
  3809. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3810. <div style="background-color: transparent; width: 100% !important;">
  3811. <!--[if (!mso)&(!IE)]><!-->
  3812. <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;">
  3813. <!--<![endif]-->
  3814. <!--[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]-->
  3815. <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;">
  3816. <div style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  3817. <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>
  3818. </div>
  3819. </div>
  3820. <!--[if mso]></td></tr></table><![endif]-->
  3821. <div style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">
  3822. <!--[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]-->
  3823. <div align="center">
  3824. <div style="border-top: 2px solid #66D9EF; width:55%; line-height:2px; height:2px; font-size:2px;">&#160;</div>
  3825. </div>
  3826. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  3827. </div>
  3828. <!--[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]-->
  3829. <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;">
  3830. <div style="font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;font-size:12px;line-height:14px;color:#FFFFFF;text-align:left;">
  3831. <p style="margin: 0;font-size: 12px;line-height: 14px"><span style="font-size: 28px; line-height: 33px;">Hey '.$user.',</span></p>
  3832. </div>
  3833. </div>
  3834. <!--[if mso]></td></tr></table><![endif]-->
  3835. <!--[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]-->
  3836. <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;">
  3837. <div style="font-size:12px;line-height:22px;font-family:\'Lato\',Tahoma,Verdana,Segoe,sans-serif;color:#FFFFFF;text-align:left;">
  3838. <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>
  3839. </span>
  3840. </p>
  3841. </div>
  3842. </div>
  3843. <!--[if mso]></td></tr></table><![endif]-->
  3844. <div align="center" class="button-container center" style="padding-right: 30px; padding-left: 30px; padding-top:15px; padding-bottom:15px;">
  3845. <!--[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]-->
  3846. <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">
  3847. <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>
  3848. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  3849. </div>
  3850. <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
  3851. </div>
  3852. <!--[if (!mso)&(!IE)]><!-->
  3853. </div>
  3854. <!--<![endif]-->
  3855. </div>
  3856. </div>
  3857. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3858. </div>
  3859. </div>
  3860. </div>
  3861. <div style="background-color:#ffffff;">
  3862. <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;"
  3863. class="block-grid ">
  3864. <div style="border-collapse: collapse;display: table;width: 100%;">
  3865. <!--[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]-->
  3866. <!--[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]-->
  3867. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3868. <div style="background-color: transparent; width: 100% !important;">
  3869. <!--[if (!mso)&(!IE)]><!-->
  3870. <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;">
  3871. <!--<![endif]-->
  3872. <!--[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]-->
  3873. <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;">
  3874. <div style="font-size:12px;line-height:14px;color:#555555;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3875. <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>
  3876. </div>
  3877. </div>
  3878. <!--[if mso]></td></tr></table><![endif]-->
  3879. <div style="padding-right: 20px; padding-left: 20px; padding-top: 15px; padding-bottom: 20px;">
  3880. <!--[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]-->
  3881. <div align="center">
  3882. <div style="border-top: 3px solid #66D9EF; width:40%; line-height:3px; height:3px; font-size:3px;">&#160;</div>
  3883. </div>
  3884. <!--[if (mso)]></td></tr></table></td></tr></table><![endif]-->
  3885. </div>
  3886. <!--[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]-->
  3887. <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;">
  3888. <div style="font-size:12px;line-height:22px;color:#7E7D7D;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3889. <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>
  3890. </div>
  3891. </div>
  3892. <!--[if mso]></td></tr></table><![endif]-->
  3893. <!--[if (!mso)&(!IE)]><!-->
  3894. </div>
  3895. <!--<![endif]-->
  3896. </div>
  3897. </div>
  3898. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3899. </div>
  3900. </div>
  3901. </div>
  3902. <div style="background-color:#333333;">
  3903. <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;"
  3904. class="block-grid ">
  3905. <div style="border-collapse: collapse;display: table;width: 100%;">
  3906. <!--[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]-->
  3907. <!--[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]-->
  3908. <div class="col num12" style="min-width: 320px;max-width: 615px;width: 615px;width: calc(29500% - 180810px);background-color: transparent;">
  3909. <div style="background-color: transparent; width: 100% !important;">
  3910. <!--[if (!mso)&(!IE)]><!-->
  3911. <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;">
  3912. <!--<![endif]-->
  3913. <!--[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]-->
  3914. <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;">
  3915. <div style="font-size:12px;line-height:14px;color:#959595;font-family:\'Lato\', Tahoma, Verdana, Segoe, sans-serif;text-align:left;">
  3916. <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"
  3917. href="https://github.com/causefx/Organizr" target="_blank" rel="noopener noreferrer">Organizr</a><strong><br></strong></p>
  3918. </div>
  3919. </div>
  3920. <!--[if mso]></td></tr></table><![endif]-->
  3921. <!--[if (!mso)&(!IE)]><!-->
  3922. </div>
  3923. <!--<![endif]-->
  3924. </div>
  3925. </div>
  3926. <!--[if (mso)|(IE)]></td></tr></table></td></tr></table><![endif]-->
  3927. </div>
  3928. </div>
  3929. </div>
  3930. <!--[if (mso)|(IE)]></td></tr></table><![endif]-->
  3931. </div>
  3932. <!--[if (mso)|(IE)]></div><![endif]-->
  3933. </body>
  3934. </html>
  3935. ';
  3936. }
  3937. function mimeTypes(){
  3938. return array(
  3939. '123' => 'application/vnd.lotus-1-2-3',
  3940. '3dml' => 'text/vnd.in3d.3dml',
  3941. '3ds' => 'image/x-3ds',
  3942. '3g2' => 'video/3gpp2',
  3943. '3gp' => 'video/3gpp',
  3944. '7z' => 'application/x-7z-compressed',
  3945. 'aab' => 'application/x-authorware-bin',
  3946. 'aac' => 'audio/x-aac',
  3947. 'aam' => 'application/x-authorware-map',
  3948. 'aas' => 'application/x-authorware-seg',
  3949. 'abw' => 'application/x-abiword',
  3950. 'ac' => 'application/pkix-attr-cert',
  3951. 'acc' => 'application/vnd.americandynamics.acc',
  3952. 'ace' => 'application/x-ace-compressed',
  3953. 'acu' => 'application/vnd.acucobol',
  3954. 'acutc' => 'application/vnd.acucorp',
  3955. 'adp' => 'audio/adpcm',
  3956. 'aep' => 'application/vnd.audiograph',
  3957. 'afm' => 'application/x-font-type1',
  3958. 'afp' => 'application/vnd.ibm.modcap',
  3959. 'ahead' => 'application/vnd.ahead.space',
  3960. 'ai' => 'application/postscript',
  3961. 'aif' => 'audio/x-aiff',
  3962. 'aifc' => 'audio/x-aiff',
  3963. 'aiff' => 'audio/x-aiff',
  3964. 'air' => 'application/vnd.adobe.air-application-installer-package+zip',
  3965. 'ait' => 'application/vnd.dvb.ait',
  3966. 'ami' => 'application/vnd.amiga.ami',
  3967. 'apk' => 'application/vnd.android.package-archive',
  3968. 'appcache' => 'text/cache-manifest',
  3969. 'application' => 'application/x-ms-application',
  3970. 'apr' => 'application/vnd.lotus-approach',
  3971. 'arc' => 'application/x-freearc',
  3972. 'asc' => 'application/pgp-signature',
  3973. 'asf' => 'video/x-ms-asf',
  3974. 'asm' => 'text/x-asm',
  3975. 'aso' => 'application/vnd.accpac.simply.aso',
  3976. 'asx' => 'video/x-ms-asf',
  3977. 'atc' => 'application/vnd.acucorp',
  3978. 'atom' => 'application/atom+xml',
  3979. 'atomcat' => 'application/atomcat+xml',
  3980. 'atomsvc' => 'application/atomsvc+xml',
  3981. 'atx' => 'application/vnd.antix.game-component',
  3982. 'au' => 'audio/basic',
  3983. 'avi' => 'video/x-msvideo',
  3984. 'aw' => 'application/applixware',
  3985. 'azf' => 'application/vnd.airzip.filesecure.azf',
  3986. 'azs' => 'application/vnd.airzip.filesecure.azs',
  3987. 'azw' => 'application/vnd.amazon.ebook',
  3988. 'bat' => 'application/x-msdownload',
  3989. 'bcpio' => 'application/x-bcpio',
  3990. 'bdf' => 'application/x-font-bdf',
  3991. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  3992. 'bed' => 'application/vnd.realvnc.bed',
  3993. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  3994. 'bin' => 'application/octet-stream',
  3995. 'blb' => 'application/x-blorb',
  3996. 'blorb' => 'application/x-blorb',
  3997. 'bmi' => 'application/vnd.bmi',
  3998. 'bmp' => 'image/bmp',
  3999. 'book' => 'application/vnd.framemaker',
  4000. 'box' => 'application/vnd.previewsystems.box',
  4001. 'boz' => 'application/x-bzip2',
  4002. 'bpk' => 'application/octet-stream',
  4003. 'btif' => 'image/prs.btif',
  4004. 'bz' => 'application/x-bzip',
  4005. 'bz2' => 'application/x-bzip2',
  4006. 'c' => 'text/x-c',
  4007. 'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
  4008. 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
  4009. 'c4d' => 'application/vnd.clonk.c4group',
  4010. 'c4f' => 'application/vnd.clonk.c4group',
  4011. 'c4g' => 'application/vnd.clonk.c4group',
  4012. 'c4p' => 'application/vnd.clonk.c4group',
  4013. 'c4u' => 'application/vnd.clonk.c4group',
  4014. 'cab' => 'application/vnd.ms-cab-compressed',
  4015. 'caf' => 'audio/x-caf',
  4016. 'cap' => 'application/vnd.tcpdump.pcap',
  4017. 'car' => 'application/vnd.curl.car',
  4018. 'cat' => 'application/vnd.ms-pki.seccat',
  4019. 'cb7' => 'application/x-cbr',
  4020. 'cba' => 'application/x-cbr',
  4021. 'cbr' => 'application/x-cbr',
  4022. 'cbt' => 'application/x-cbr',
  4023. 'cbz' => 'application/x-cbr',
  4024. 'cc' => 'text/x-c',
  4025. 'cct' => 'application/x-director',
  4026. 'ccxml' => 'application/ccxml+xml',
  4027. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  4028. 'cdf' => 'application/x-netcdf',
  4029. 'cdkey' => 'application/vnd.mediastation.cdkey',
  4030. 'cdmia' => 'application/cdmi-capability',
  4031. 'cdmic' => 'application/cdmi-container',
  4032. 'cdmid' => 'application/cdmi-domain',
  4033. 'cdmio' => 'application/cdmi-object',
  4034. 'cdmiq' => 'application/cdmi-queue',
  4035. 'cdx' => 'chemical/x-cdx',
  4036. 'cdxml' => 'application/vnd.chemdraw+xml',
  4037. 'cdy' => 'application/vnd.cinderella',
  4038. 'cer' => 'application/pkix-cert',
  4039. 'cfs' => 'application/x-cfs-compressed',
  4040. 'cgm' => 'image/cgm',
  4041. 'chat' => 'application/x-chat',
  4042. 'chm' => 'application/vnd.ms-htmlhelp',
  4043. 'chrt' => 'application/vnd.kde.kchart',
  4044. 'cif' => 'chemical/x-cif',
  4045. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  4046. 'cil' => 'application/vnd.ms-artgalry',
  4047. 'cla' => 'application/vnd.claymore',
  4048. 'class' => 'application/java-vm',
  4049. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  4050. 'clkp' => 'application/vnd.crick.clicker.palette',
  4051. 'clkt' => 'application/vnd.crick.clicker.template',
  4052. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  4053. 'clkx' => 'application/vnd.crick.clicker',
  4054. 'clp' => 'application/x-msclip',
  4055. 'cmc' => 'application/vnd.cosmocaller',
  4056. 'cmdf' => 'chemical/x-cmdf',
  4057. 'cml' => 'chemical/x-cml',
  4058. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  4059. 'cmx' => 'image/x-cmx',
  4060. 'cod' => 'application/vnd.rim.cod',
  4061. 'com' => 'application/x-msdownload',
  4062. 'conf' => 'text/plain',
  4063. 'cpio' => 'application/x-cpio',
  4064. 'cpp' => 'text/x-c',
  4065. 'cpt' => 'application/mac-compactpro',
  4066. 'crd' => 'application/x-mscardfile',
  4067. 'crl' => 'application/pkix-crl',
  4068. 'crt' => 'application/x-x509-ca-cert',
  4069. 'cryptonote' => 'application/vnd.rig.cryptonote',
  4070. 'csh' => 'application/x-csh',
  4071. 'csml' => 'chemical/x-csml',
  4072. 'csp' => 'application/vnd.commonspace',
  4073. 'css' => 'text/css',
  4074. 'cst' => 'application/x-director',
  4075. 'csv' => 'text/csv',
  4076. 'cu' => 'application/cu-seeme',
  4077. 'curl' => 'text/vnd.curl',
  4078. 'cww' => 'application/prs.cww',
  4079. 'cxt' => 'application/x-director',
  4080. 'cxx' => 'text/x-c',
  4081. 'dae' => 'model/vnd.collada+xml',
  4082. 'daf' => 'application/vnd.mobius.daf',
  4083. 'dart' => 'application/vnd.dart',
  4084. 'dataless' => 'application/vnd.fdsn.seed',
  4085. 'davmount' => 'application/davmount+xml',
  4086. 'dbk' => 'application/docbook+xml',
  4087. 'dcr' => 'application/x-director',
  4088. 'dcurl' => 'text/vnd.curl.dcurl',
  4089. 'dd2' => 'application/vnd.oma.dd2+xml',
  4090. 'ddd' => 'application/vnd.fujixerox.ddd',
  4091. 'deb' => 'application/x-debian-package',
  4092. 'def' => 'text/plain',
  4093. 'deploy' => 'application/octet-stream',
  4094. 'der' => 'application/x-x509-ca-cert',
  4095. 'dfac' => 'application/vnd.dreamfactory',
  4096. 'dgc' => 'application/x-dgc-compressed',
  4097. 'dic' => 'text/x-c',
  4098. 'dir' => 'application/x-director',
  4099. 'dis' => 'application/vnd.mobius.dis',
  4100. 'dist' => 'application/octet-stream',
  4101. 'distz' => 'application/octet-stream',
  4102. 'djv' => 'image/vnd.djvu',
  4103. 'djvu' => 'image/vnd.djvu',
  4104. 'dll' => 'application/x-msdownload',
  4105. 'dmg' => 'application/x-apple-diskimage',
  4106. 'dmp' => 'application/vnd.tcpdump.pcap',
  4107. 'dms' => 'application/octet-stream',
  4108. 'dna' => 'application/vnd.dna',
  4109. 'doc' => 'application/msword',
  4110. 'docm' => 'application/vnd.ms-word.document.macroenabled.12',
  4111. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  4112. 'dot' => 'application/msword',
  4113. 'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
  4114. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  4115. 'dp' => 'application/vnd.osgi.dp',
  4116. 'dpg' => 'application/vnd.dpgraph',
  4117. 'dra' => 'audio/vnd.dra',
  4118. 'dsc' => 'text/prs.lines.tag',
  4119. 'dssc' => 'application/dssc+der',
  4120. 'dtb' => 'application/x-dtbook+xml',
  4121. 'dtd' => 'application/xml-dtd',
  4122. 'dts' => 'audio/vnd.dts',
  4123. 'dtshd' => 'audio/vnd.dts.hd',
  4124. 'dump' => 'application/octet-stream',
  4125. 'dvb' => 'video/vnd.dvb.file',
  4126. 'dvi' => 'application/x-dvi',
  4127. 'dwf' => 'model/vnd.dwf',
  4128. 'dwg' => 'image/vnd.dwg',
  4129. 'dxf' => 'image/vnd.dxf',
  4130. 'dxp' => 'application/vnd.spotfire.dxp',
  4131. 'dxr' => 'application/x-director',
  4132. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  4133. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  4134. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  4135. 'ecma' => 'application/ecmascript',
  4136. 'edm' => 'application/vnd.novadigm.edm',
  4137. 'edx' => 'application/vnd.novadigm.edx',
  4138. 'efif' => 'application/vnd.picsel',
  4139. 'ei6' => 'application/vnd.pg.osasli',
  4140. 'elc' => 'application/octet-stream',
  4141. 'emf' => 'application/x-msmetafile',
  4142. 'eml' => 'message/rfc822',
  4143. 'emma' => 'application/emma+xml',
  4144. 'emz' => 'application/x-msmetafile',
  4145. 'eol' => 'audio/vnd.digital-winds',
  4146. 'eot' => 'application/vnd.ms-fontobject',
  4147. 'eps' => 'application/postscript',
  4148. 'epub' => 'application/epub+zip',
  4149. 'es3' => 'application/vnd.eszigno3+xml',
  4150. 'esa' => 'application/vnd.osgi.subsystem',
  4151. 'esf' => 'application/vnd.epson.esf',
  4152. 'et3' => 'application/vnd.eszigno3+xml',
  4153. 'etx' => 'text/x-setext',
  4154. 'eva' => 'application/x-eva',
  4155. 'evy' => 'application/x-envoy',
  4156. 'exe' => 'application/x-msdownload',
  4157. 'exi' => 'application/exi',
  4158. 'ext' => 'application/vnd.novadigm.ext',
  4159. 'ez' => 'application/andrew-inset',
  4160. 'ez2' => 'application/vnd.ezpix-album',
  4161. 'ez3' => 'application/vnd.ezpix-package',
  4162. 'f' => 'text/x-fortran',
  4163. 'f4v' => 'video/x-f4v',
  4164. 'f77' => 'text/x-fortran',
  4165. 'f90' => 'text/x-fortran',
  4166. 'fbs' => 'image/vnd.fastbidsheet',
  4167. 'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
  4168. 'fcs' => 'application/vnd.isac.fcs',
  4169. 'fdf' => 'application/vnd.fdf',
  4170. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  4171. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  4172. 'fgd' => 'application/x-director',
  4173. 'fh' => 'image/x-freehand',
  4174. 'fh4' => 'image/x-freehand',
  4175. 'fh5' => 'image/x-freehand',
  4176. 'fh7' => 'image/x-freehand',
  4177. 'fhc' => 'image/x-freehand',
  4178. 'fig' => 'application/x-xfig',
  4179. 'flac' => 'audio/x-flac',
  4180. 'fli' => 'video/x-fli',
  4181. 'flo' => 'application/vnd.micrografx.flo',
  4182. 'flv' => 'video/x-flv',
  4183. 'flw' => 'application/vnd.kde.kivio',
  4184. 'flx' => 'text/vnd.fmi.flexstor',
  4185. 'fly' => 'text/vnd.fly',
  4186. 'fm' => 'application/vnd.framemaker',
  4187. 'fnc' => 'application/vnd.frogans.fnc',
  4188. 'for' => 'text/x-fortran',
  4189. 'fpx' => 'image/vnd.fpx',
  4190. 'frame' => 'application/vnd.framemaker',
  4191. 'fsc' => 'application/vnd.fsc.weblaunch',
  4192. 'fst' => 'image/vnd.fst',
  4193. 'ftc' => 'application/vnd.fluxtime.clip',
  4194. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  4195. 'fvt' => 'video/vnd.fvt',
  4196. 'fxp' => 'application/vnd.adobe.fxp',
  4197. 'fxpl' => 'application/vnd.adobe.fxp',
  4198. 'fzs' => 'application/vnd.fuzzysheet',
  4199. 'g2w' => 'application/vnd.geoplan',
  4200. 'g3' => 'image/g3fax',
  4201. 'g3w' => 'application/vnd.geospace',
  4202. 'gac' => 'application/vnd.groove-account',
  4203. 'gam' => 'application/x-tads',
  4204. 'gbr' => 'application/rpki-ghostbusters',
  4205. 'gca' => 'application/x-gca-compressed',
  4206. 'gdl' => 'model/vnd.gdl',
  4207. 'geo' => 'application/vnd.dynageo',
  4208. 'gex' => 'application/vnd.geometry-explorer',
  4209. 'ggb' => 'application/vnd.geogebra.file',
  4210. 'ggt' => 'application/vnd.geogebra.tool',
  4211. 'ghf' => 'application/vnd.groove-help',
  4212. 'gif' => 'image/gif',
  4213. 'gim' => 'application/vnd.groove-identity-message',
  4214. 'gml' => 'application/gml+xml',
  4215. 'gmx' => 'application/vnd.gmx',
  4216. 'gnumeric' => 'application/x-gnumeric',
  4217. 'gph' => 'application/vnd.flographit',
  4218. 'gpx' => 'application/gpx+xml',
  4219. 'gqf' => 'application/vnd.grafeq',
  4220. 'gqs' => 'application/vnd.grafeq',
  4221. 'gram' => 'application/srgs',
  4222. 'gramps' => 'application/x-gramps-xml',
  4223. 'gre' => 'application/vnd.geometry-explorer',
  4224. 'grv' => 'application/vnd.groove-injector',
  4225. 'grxml' => 'application/srgs+xml',
  4226. 'gsf' => 'application/x-font-ghostscript',
  4227. 'gtar' => 'application/x-gtar',
  4228. 'gtm' => 'application/vnd.groove-tool-message',
  4229. 'gtw' => 'model/vnd.gtw',
  4230. 'gv' => 'text/vnd.graphviz',
  4231. 'gxf' => 'application/gxf',
  4232. 'gxt' => 'application/vnd.geonext',
  4233. 'h' => 'text/x-c',
  4234. 'h261' => 'video/h261',
  4235. 'h263' => 'video/h263',
  4236. 'h264' => 'video/h264',
  4237. 'hal' => 'application/vnd.hal+xml',
  4238. 'hbci' => 'application/vnd.hbci',
  4239. 'hdf' => 'application/x-hdf',
  4240. 'hh' => 'text/x-c',
  4241. 'hlp' => 'application/winhlp',
  4242. 'hpgl' => 'application/vnd.hp-hpgl',
  4243. 'hpid' => 'application/vnd.hp-hpid',
  4244. 'hps' => 'application/vnd.hp-hps',
  4245. 'hqx' => 'application/mac-binhex40',
  4246. 'htke' => 'application/vnd.kenameaapp',
  4247. 'htm' => 'text/html',
  4248. 'html' => 'text/html',
  4249. 'hvd' => 'application/vnd.yamaha.hv-dic',
  4250. 'hvp' => 'application/vnd.yamaha.hv-voice',
  4251. 'hvs' => 'application/vnd.yamaha.hv-script',
  4252. 'i2g' => 'application/vnd.intergeo',
  4253. 'icc' => 'application/vnd.iccprofile',
  4254. 'ice' => 'x-conference/x-cooltalk',
  4255. 'icm' => 'application/vnd.iccprofile',
  4256. 'ico' => 'image/x-icon',
  4257. 'ics' => 'text/calendar',
  4258. 'ief' => 'image/ief',
  4259. 'ifb' => 'text/calendar',
  4260. 'ifm' => 'application/vnd.shana.informed.formdata',
  4261. 'iges' => 'model/iges',
  4262. 'igl' => 'application/vnd.igloader',
  4263. 'igm' => 'application/vnd.insors.igm',
  4264. 'igs' => 'model/iges',
  4265. 'igx' => 'application/vnd.micrografx.igx',
  4266. 'iif' => 'application/vnd.shana.informed.interchange',
  4267. 'imp' => 'application/vnd.accpac.simply.imp',
  4268. 'ims' => 'application/vnd.ms-ims',
  4269. 'in' => 'text/plain',
  4270. 'ink' => 'application/inkml+xml',
  4271. 'inkml' => 'application/inkml+xml',
  4272. 'install' => 'application/x-install-instructions',
  4273. 'iota' => 'application/vnd.astraea-software.iota',
  4274. 'ipfix' => 'application/ipfix',
  4275. 'ipk' => 'application/vnd.shana.informed.package',
  4276. 'irm' => 'application/vnd.ibm.rights-management',
  4277. 'irp' => 'application/vnd.irepository.package+xml',
  4278. 'iso' => 'application/x-iso9660-image',
  4279. 'itp' => 'application/vnd.shana.informed.formtemplate',
  4280. 'ivp' => 'application/vnd.immervision-ivp',
  4281. 'ivu' => 'application/vnd.immervision-ivu',
  4282. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  4283. 'jam' => 'application/vnd.jam',
  4284. 'jar' => 'application/java-archive',
  4285. 'java' => 'text/x-java-source',
  4286. 'jisp' => 'application/vnd.jisp',
  4287. 'jlt' => 'application/vnd.hp-jlyt',
  4288. 'jnlp' => 'application/x-java-jnlp-file',
  4289. 'joda' => 'application/vnd.joost.joda-archive',
  4290. 'jpe' => 'image/jpeg',
  4291. 'jpeg' => 'image/jpeg',
  4292. 'jpg' => 'image/jpeg',
  4293. 'jpgm' => 'video/jpm',
  4294. 'jpgv' => 'video/jpeg',
  4295. 'jpm' => 'video/jpm',
  4296. 'js' => 'application/javascript',
  4297. 'json' => 'application/json',
  4298. 'jsonml' => 'application/jsonml+json',
  4299. 'kar' => 'audio/midi',
  4300. 'karbon' => 'application/vnd.kde.karbon',
  4301. 'kfo' => 'application/vnd.kde.kformula',
  4302. 'kia' => 'application/vnd.kidspiration',
  4303. 'kml' => 'application/vnd.google-earth.kml+xml',
  4304. 'kmz' => 'application/vnd.google-earth.kmz',
  4305. 'kne' => 'application/vnd.kinar',
  4306. 'knp' => 'application/vnd.kinar',
  4307. 'kon' => 'application/vnd.kde.kontour',
  4308. 'kpr' => 'application/vnd.kde.kpresenter',
  4309. 'kpt' => 'application/vnd.kde.kpresenter',
  4310. 'kpxx' => 'application/vnd.ds-keypoint',
  4311. 'ksp' => 'application/vnd.kde.kspread',
  4312. 'ktr' => 'application/vnd.kahootz',
  4313. 'ktx' => 'image/ktx',
  4314. 'ktz' => 'application/vnd.kahootz',
  4315. 'kwd' => 'application/vnd.kde.kword',
  4316. 'kwt' => 'application/vnd.kde.kword',
  4317. 'lasxml' => 'application/vnd.las.las+xml',
  4318. 'latex' => 'application/x-latex',
  4319. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  4320. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  4321. 'les' => 'application/vnd.hhe.lesson-player',
  4322. 'lha' => 'application/x-lzh-compressed',
  4323. 'link66' => 'application/vnd.route66.link66+xml',
  4324. 'list' => 'text/plain',
  4325. 'list3820' => 'application/vnd.ibm.modcap',
  4326. 'listafp' => 'application/vnd.ibm.modcap',
  4327. 'lnk' => 'application/x-ms-shortcut',
  4328. 'log' => 'text/plain',
  4329. 'lostxml' => 'application/lost+xml',
  4330. 'lrf' => 'application/octet-stream',
  4331. 'lrm' => 'application/vnd.ms-lrm',
  4332. 'ltf' => 'application/vnd.frogans.ltf',
  4333. 'lvp' => 'audio/vnd.lucent.voice',
  4334. 'lwp' => 'application/vnd.lotus-wordpro',
  4335. 'lzh' => 'application/x-lzh-compressed',
  4336. 'm13' => 'application/x-msmediaview',
  4337. 'm14' => 'application/x-msmediaview',
  4338. 'm1v' => 'video/mpeg',
  4339. 'm21' => 'application/mp21',
  4340. 'm2a' => 'audio/mpeg',
  4341. 'm2v' => 'video/mpeg',
  4342. 'm3a' => 'audio/mpeg',
  4343. 'm3u' => 'audio/x-mpegurl',
  4344. 'm3u8' => 'application/vnd.apple.mpegurl',
  4345. 'm4a' => 'audio/mp4',
  4346. 'm4u' => 'video/vnd.mpegurl',
  4347. 'm4v' => 'video/x-m4v',
  4348. 'ma' => 'application/mathematica',
  4349. 'mads' => 'application/mads+xml',
  4350. 'mag' => 'application/vnd.ecowin.chart',
  4351. 'maker' => 'application/vnd.framemaker',
  4352. 'man' => 'text/troff',
  4353. 'mar' => 'application/octet-stream',
  4354. 'mathml' => 'application/mathml+xml',
  4355. 'mb' => 'application/mathematica',
  4356. 'mbk' => 'application/vnd.mobius.mbk',
  4357. 'mbox' => 'application/mbox',
  4358. 'mc1' => 'application/vnd.medcalcdata',
  4359. 'mcd' => 'application/vnd.mcd',
  4360. 'mcurl' => 'text/vnd.curl.mcurl',
  4361. 'mdb' => 'application/x-msaccess',
  4362. 'mdi' => 'image/vnd.ms-modi',
  4363. 'me' => 'text/troff',
  4364. 'mesh' => 'model/mesh',
  4365. 'meta4' => 'application/metalink4+xml',
  4366. 'metalink' => 'application/metalink+xml',
  4367. 'mets' => 'application/mets+xml',
  4368. 'mfm' => 'application/vnd.mfmp',
  4369. 'mft' => 'application/rpki-manifest',
  4370. 'mgp' => 'application/vnd.osgeo.mapguide.package',
  4371. 'mgz' => 'application/vnd.proteus.magazine',
  4372. 'mid' => 'audio/midi',
  4373. 'midi' => 'audio/midi',
  4374. 'mie' => 'application/x-mie',
  4375. 'mif' => 'application/vnd.mif',
  4376. 'mime' => 'message/rfc822',
  4377. 'mj2' => 'video/mj2',
  4378. 'mjp2' => 'video/mj2',
  4379. 'mk3d' => 'video/x-matroska',
  4380. 'mka' => 'audio/x-matroska',
  4381. 'mks' => 'video/x-matroska',
  4382. 'mkv' => 'video/x-matroska',
  4383. 'mlp' => 'application/vnd.dolby.mlp',
  4384. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  4385. 'mmf' => 'application/vnd.smaf',
  4386. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  4387. 'mng' => 'video/x-mng',
  4388. 'mny' => 'application/x-msmoney',
  4389. 'mobi' => 'application/x-mobipocket-ebook',
  4390. 'mods' => 'application/mods+xml',
  4391. 'mov' => 'video/quicktime',
  4392. 'movie' => 'video/x-sgi-movie',
  4393. 'mp2' => 'audio/mpeg',
  4394. 'mp21' => 'application/mp21',
  4395. 'mp2a' => 'audio/mpeg',
  4396. 'mp3' => 'audio/mpeg',
  4397. 'mp4' => 'video/mp4',
  4398. 'mp4a' => 'audio/mp4',
  4399. 'mp4s' => 'application/mp4',
  4400. 'mp4v' => 'video/mp4',
  4401. 'mpc' => 'application/vnd.mophun.certificate',
  4402. 'mpe' => 'video/mpeg',
  4403. 'mpeg' => 'video/mpeg',
  4404. 'mpg' => 'video/mpeg',
  4405. 'mpg4' => 'video/mp4',
  4406. 'mpga' => 'audio/mpeg',
  4407. 'mpkg' => 'application/vnd.apple.installer+xml',
  4408. 'mpm' => 'application/vnd.blueice.multipass',
  4409. 'mpn' => 'application/vnd.mophun.application',
  4410. 'mpp' => 'application/vnd.ms-project',
  4411. 'mpt' => 'application/vnd.ms-project',
  4412. 'mpy' => 'application/vnd.ibm.minipay',
  4413. 'mqy' => 'application/vnd.mobius.mqy',
  4414. 'mrc' => 'application/marc',
  4415. 'mrcx' => 'application/marcxml+xml',
  4416. 'ms' => 'text/troff',
  4417. 'mscml' => 'application/mediaservercontrol+xml',
  4418. 'mseed' => 'application/vnd.fdsn.mseed',
  4419. 'mseq' => 'application/vnd.mseq',
  4420. 'msf' => 'application/vnd.epson.msf',
  4421. 'msh' => 'model/mesh',
  4422. 'msi' => 'application/x-msdownload',
  4423. 'msl' => 'application/vnd.mobius.msl',
  4424. 'msty' => 'application/vnd.muvee.style',
  4425. 'mts' => 'model/vnd.mts',
  4426. 'mus' => 'application/vnd.musician',
  4427. 'musicxml' => 'application/vnd.recordare.musicxml+xml',
  4428. 'mvb' => 'application/x-msmediaview',
  4429. 'mwf' => 'application/vnd.mfer',
  4430. 'mxf' => 'application/mxf',
  4431. 'mxl' => 'application/vnd.recordare.musicxml',
  4432. 'mxml' => 'application/xv+xml',
  4433. 'mxs' => 'application/vnd.triscape.mxs',
  4434. 'mxu' => 'video/vnd.mpegurl',
  4435. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  4436. 'n3' => 'text/n3',
  4437. 'nb' => 'application/mathematica',
  4438. 'nbp' => 'application/vnd.wolfram.player',
  4439. 'nc' => 'application/x-netcdf',
  4440. 'ncx' => 'application/x-dtbncx+xml',
  4441. 'nfo' => 'text/x-nfo',
  4442. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  4443. 'nitf' => 'application/vnd.nitf',
  4444. 'nlu' => 'application/vnd.neurolanguage.nlu',
  4445. 'nml' => 'application/vnd.enliven',
  4446. 'nnd' => 'application/vnd.noblenet-directory',
  4447. 'nns' => 'application/vnd.noblenet-sealer',
  4448. 'nnw' => 'application/vnd.noblenet-web',
  4449. 'npx' => 'image/vnd.net-fpx',
  4450. 'nsc' => 'application/x-conference',
  4451. 'nsf' => 'application/vnd.lotus-notes',
  4452. 'ntf' => 'application/vnd.nitf',
  4453. 'nzb' => 'application/x-nzb',
  4454. 'oa2' => 'application/vnd.fujitsu.oasys2',
  4455. 'oa3' => 'application/vnd.fujitsu.oasys3',
  4456. 'oas' => 'application/vnd.fujitsu.oasys',
  4457. 'obd' => 'application/x-msbinder',
  4458. 'obj' => 'application/x-tgif',
  4459. 'oda' => 'application/oda',
  4460. 'odb' => 'application/vnd.oasis.opendocument.database',
  4461. 'odc' => 'application/vnd.oasis.opendocument.chart',
  4462. 'odf' => 'application/vnd.oasis.opendocument.formula',
  4463. 'odft' => 'application/vnd.oasis.opendocument.formula-template',
  4464. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  4465. 'odi' => 'application/vnd.oasis.opendocument.image',
  4466. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  4467. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  4468. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  4469. 'odt' => 'application/vnd.oasis.opendocument.text',
  4470. 'oga' => 'audio/ogg',
  4471. 'ogg' => 'audio/ogg',
  4472. 'ogv' => 'video/ogg',
  4473. 'ogx' => 'application/ogg',
  4474. 'omdoc' => 'application/omdoc+xml',
  4475. 'onepkg' => 'application/onenote',
  4476. 'onetmp' => 'application/onenote',
  4477. 'onetoc' => 'application/onenote',
  4478. 'onetoc2' => 'application/onenote',
  4479. 'opf' => 'application/oebps-package+xml',
  4480. 'opml' => 'text/x-opml',
  4481. 'oprc' => 'application/vnd.palm',
  4482. 'org' => 'application/vnd.lotus-organizer',
  4483. 'osf' => 'application/vnd.yamaha.openscoreformat',
  4484. 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
  4485. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  4486. 'otf' => 'application/x-font-otf',
  4487. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  4488. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  4489. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  4490. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  4491. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  4492. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  4493. 'oxps' => 'application/oxps',
  4494. 'oxt' => 'application/vnd.openofficeorg.extension',
  4495. 'p' => 'text/x-pascal',
  4496. 'p10' => 'application/pkcs10',
  4497. 'p12' => 'application/x-pkcs12',
  4498. 'p7b' => 'application/x-pkcs7-certificates',
  4499. 'p7c' => 'application/pkcs7-mime',
  4500. 'p7m' => 'application/pkcs7-mime',
  4501. 'p7r' => 'application/x-pkcs7-certreqresp',
  4502. 'p7s' => 'application/pkcs7-signature',
  4503. 'p8' => 'application/pkcs8',
  4504. 'pas' => 'text/x-pascal',
  4505. 'paw' => 'application/vnd.pawaafile',
  4506. 'pbd' => 'application/vnd.powerbuilder6',
  4507. 'pbm' => 'image/x-portable-bitmap',
  4508. 'pcap' => 'application/vnd.tcpdump.pcap',
  4509. 'pcf' => 'application/x-font-pcf',
  4510. 'pcl' => 'application/vnd.hp-pcl',
  4511. 'pclxl' => 'application/vnd.hp-pclxl',
  4512. 'pct' => 'image/x-pict',
  4513. 'pcurl' => 'application/vnd.curl.pcurl',
  4514. 'pcx' => 'image/x-pcx',
  4515. 'pdb' => 'application/vnd.palm',
  4516. 'pdf' => 'application/pdf',
  4517. 'pfa' => 'application/x-font-type1',
  4518. 'pfb' => 'application/x-font-type1',
  4519. 'pfm' => 'application/x-font-type1',
  4520. 'pfr' => 'application/font-tdpfr',
  4521. 'pfx' => 'application/x-pkcs12',
  4522. 'pgm' => 'image/x-portable-graymap',
  4523. 'pgn' => 'application/x-chess-pgn',
  4524. 'pgp' => 'application/pgp-encrypted',
  4525. 'pic' => 'image/x-pict',
  4526. 'pkg' => 'application/octet-stream',
  4527. 'pki' => 'application/pkixcmp',
  4528. 'pkipath' => 'application/pkix-pkipath',
  4529. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  4530. 'plc' => 'application/vnd.mobius.plc',
  4531. 'plf' => 'application/vnd.pocketlearn',
  4532. 'pls' => 'application/pls+xml',
  4533. 'pml' => 'application/vnd.ctc-posml',
  4534. 'png' => 'image/png',
  4535. 'pnm' => 'image/x-portable-anymap',
  4536. 'portpkg' => 'application/vnd.macports.portpkg',
  4537. 'pot' => 'application/vnd.ms-powerpoint',
  4538. 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
  4539. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  4540. 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
  4541. 'ppd' => 'application/vnd.cups-ppd',
  4542. 'ppm' => 'image/x-portable-pixmap',
  4543. 'pps' => 'application/vnd.ms-powerpoint',
  4544. 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
  4545. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  4546. 'ppt' => 'application/vnd.ms-powerpoint',
  4547. 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
  4548. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  4549. 'pqa' => 'application/vnd.palm',
  4550. 'prc' => 'application/x-mobipocket-ebook',
  4551. 'pre' => 'application/vnd.lotus-freelance',
  4552. 'prf' => 'application/pics-rules',
  4553. 'ps' => 'application/postscript',
  4554. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  4555. 'psd' => 'image/vnd.adobe.photoshop',
  4556. 'psf' => 'application/x-font-linux-psf',
  4557. 'pskcxml' => 'application/pskc+xml',
  4558. 'ptid' => 'application/vnd.pvi.ptid1',
  4559. 'pub' => 'application/x-mspublisher',
  4560. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  4561. 'pwn' => 'application/vnd.3m.post-it-notes',
  4562. 'pya' => 'audio/vnd.ms-playready.media.pya',
  4563. 'pyv' => 'video/vnd.ms-playready.media.pyv',
  4564. 'qam' => 'application/vnd.epson.quickanime',
  4565. 'qbo' => 'application/vnd.intu.qbo',
  4566. 'qfx' => 'application/vnd.intu.qfx',
  4567. 'qps' => 'application/vnd.publishare-delta-tree',
  4568. 'qt' => 'video/quicktime',
  4569. 'qwd' => 'application/vnd.quark.quarkxpress',
  4570. 'qwt' => 'application/vnd.quark.quarkxpress',
  4571. 'qxb' => 'application/vnd.quark.quarkxpress',
  4572. 'qxd' => 'application/vnd.quark.quarkxpress',
  4573. 'qxl' => 'application/vnd.quark.quarkxpress',
  4574. 'qxt' => 'application/vnd.quark.quarkxpress',
  4575. 'ra' => 'audio/x-pn-realaudio',
  4576. 'ram' => 'audio/x-pn-realaudio',
  4577. 'rar' => 'application/x-rar-compressed',
  4578. 'ras' => 'image/x-cmu-raster',
  4579. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  4580. 'rdf' => 'application/rdf+xml',
  4581. 'rdz' => 'application/vnd.data-vision.rdz',
  4582. 'rep' => 'application/vnd.businessobjects',
  4583. 'res' => 'application/x-dtbresource+xml',
  4584. 'rgb' => 'image/x-rgb',
  4585. 'rif' => 'application/reginfo+xml',
  4586. 'rip' => 'audio/vnd.rip',
  4587. 'ris' => 'application/x-research-info-systems',
  4588. 'rl' => 'application/resource-lists+xml',
  4589. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  4590. 'rld' => 'application/resource-lists-diff+xml',
  4591. 'rm' => 'application/vnd.rn-realmedia',
  4592. 'rmi' => 'audio/midi',
  4593. 'rmp' => 'audio/x-pn-realaudio-plugin',
  4594. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  4595. 'rmvb' => 'application/vnd.rn-realmedia-vbr',
  4596. 'rnc' => 'application/relax-ng-compact-syntax',
  4597. 'roa' => 'application/rpki-roa',
  4598. 'roff' => 'text/troff',
  4599. 'rp9' => 'application/vnd.cloanto.rp9',
  4600. 'rpss' => 'application/vnd.nokia.radio-presets',
  4601. 'rpst' => 'application/vnd.nokia.radio-preset',
  4602. 'rq' => 'application/sparql-query',
  4603. 'rs' => 'application/rls-services+xml',
  4604. 'rsd' => 'application/rsd+xml',
  4605. 'rss' => 'application/rss+xml',
  4606. 'rtf' => 'application/rtf',
  4607. 'rtx' => 'text/richtext',
  4608. 's' => 'text/x-asm',
  4609. 's3m' => 'audio/s3m',
  4610. 'saf' => 'application/vnd.yamaha.smaf-audio',
  4611. 'sbml' => 'application/sbml+xml',
  4612. 'sc' => 'application/vnd.ibm.secure-container',
  4613. 'scd' => 'application/x-msschedule',
  4614. 'scm' => 'application/vnd.lotus-screencam',
  4615. 'scq' => 'application/scvp-cv-request',
  4616. 'scs' => 'application/scvp-cv-response',
  4617. 'scurl' => 'text/vnd.curl.scurl',
  4618. 'sda' => 'application/vnd.stardivision.draw',
  4619. 'sdc' => 'application/vnd.stardivision.calc',
  4620. 'sdd' => 'application/vnd.stardivision.impress',
  4621. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  4622. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  4623. 'sdp' => 'application/sdp',
  4624. 'sdw' => 'application/vnd.stardivision.writer',
  4625. 'see' => 'application/vnd.seemail',
  4626. 'seed' => 'application/vnd.fdsn.seed',
  4627. 'sema' => 'application/vnd.sema',
  4628. 'semd' => 'application/vnd.semd',
  4629. 'semf' => 'application/vnd.semf',
  4630. 'ser' => 'application/java-serialized-object',
  4631. 'setpay' => 'application/set-payment-initiation',
  4632. 'setreg' => 'application/set-registration-initiation',
  4633. 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
  4634. 'sfs' => 'application/vnd.spotfire.sfs',
  4635. 'sfv' => 'text/x-sfv',
  4636. 'sgi' => 'image/sgi',
  4637. 'sgl' => 'application/vnd.stardivision.writer-global',
  4638. 'sgm' => 'text/sgml',
  4639. 'sgml' => 'text/sgml',
  4640. 'sh' => 'application/x-sh',
  4641. 'shar' => 'application/x-shar',
  4642. 'shf' => 'application/shf+xml',
  4643. 'sid' => 'image/x-mrsid-image',
  4644. 'sig' => 'application/pgp-signature',
  4645. 'sil' => 'audio/silk',
  4646. 'silo' => 'model/mesh',
  4647. 'sis' => 'application/vnd.symbian.install',
  4648. 'sisx' => 'application/vnd.symbian.install',
  4649. 'sit' => 'application/x-stuffit',
  4650. 'sitx' => 'application/x-stuffitx',
  4651. 'skd' => 'application/vnd.koan',
  4652. 'skm' => 'application/vnd.koan',
  4653. 'skp' => 'application/vnd.koan',
  4654. 'skt' => 'application/vnd.koan',
  4655. 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
  4656. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  4657. 'slt' => 'application/vnd.epson.salt',
  4658. 'sm' => 'application/vnd.stepmania.stepchart',
  4659. 'smf' => 'application/vnd.stardivision.math',
  4660. 'smi' => 'application/smil+xml',
  4661. 'smil' => 'application/smil+xml',
  4662. 'smv' => 'video/x-smv',
  4663. 'smzip' => 'application/vnd.stepmania.package',
  4664. 'snd' => 'audio/basic',
  4665. 'snf' => 'application/x-font-snf',
  4666. 'so' => 'application/octet-stream',
  4667. 'spc' => 'application/x-pkcs7-certificates',
  4668. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  4669. 'spl' => 'application/x-futuresplash',
  4670. 'spot' => 'text/vnd.in3d.spot',
  4671. 'spp' => 'application/scvp-vp-response',
  4672. 'spq' => 'application/scvp-vp-request',
  4673. 'spx' => 'audio/ogg',
  4674. 'sql' => 'application/x-sql',
  4675. 'src' => 'application/x-wais-source',
  4676. 'srt' => 'application/x-subrip',
  4677. 'sru' => 'application/sru+xml',
  4678. 'srx' => 'application/sparql-results+xml',
  4679. 'ssdl' => 'application/ssdl+xml',
  4680. 'sse' => 'application/vnd.kodak-descriptor',
  4681. 'ssf' => 'application/vnd.epson.ssf',
  4682. 'ssml' => 'application/ssml+xml',
  4683. 'st' => 'application/vnd.sailingtracker.track',
  4684. 'stc' => 'application/vnd.sun.xml.calc.template',
  4685. 'std' => 'application/vnd.sun.xml.draw.template',
  4686. 'stf' => 'application/vnd.wt.stf',
  4687. 'sti' => 'application/vnd.sun.xml.impress.template',
  4688. 'stk' => 'application/hyperstudio',
  4689. 'stl' => 'application/vnd.ms-pki.stl',
  4690. 'str' => 'application/vnd.pg.format',
  4691. 'stw' => 'application/vnd.sun.xml.writer.template',
  4692. 'sub' => 'image/vnd.dvb.subtitle',
  4693. 'sub' => 'text/vnd.dvb.subtitle',
  4694. 'sus' => 'application/vnd.sus-calendar',
  4695. 'susp' => 'application/vnd.sus-calendar',
  4696. 'sv4cpio' => 'application/x-sv4cpio',
  4697. 'sv4crc' => 'application/x-sv4crc',
  4698. 'svc' => 'application/vnd.dvb.service',
  4699. 'svd' => 'application/vnd.svd',
  4700. 'svg' => 'image/svg+xml',
  4701. 'svgz' => 'image/svg+xml',
  4702. 'swa' => 'application/x-director',
  4703. 'swf' => 'application/x-shockwave-flash',
  4704. 'swi' => 'application/vnd.aristanetworks.swi',
  4705. 'sxc' => 'application/vnd.sun.xml.calc',
  4706. 'sxd' => 'application/vnd.sun.xml.draw',
  4707. 'sxg' => 'application/vnd.sun.xml.writer.global',
  4708. 'sxi' => 'application/vnd.sun.xml.impress',
  4709. 'sxm' => 'application/vnd.sun.xml.math',
  4710. 'sxw' => 'application/vnd.sun.xml.writer',
  4711. 't' => 'text/troff',
  4712. 't3' => 'application/x-t3vm-image',
  4713. 'taglet' => 'application/vnd.mynfc',
  4714. 'tao' => 'application/vnd.tao.intent-module-archive',
  4715. 'tar' => 'application/x-tar',
  4716. 'tcap' => 'application/vnd.3gpp2.tcap',
  4717. 'tcl' => 'application/x-tcl',
  4718. 'teacher' => 'application/vnd.smart.teacher',
  4719. 'tei' => 'application/tei+xml',
  4720. 'teicorpus' => 'application/tei+xml',
  4721. 'tex' => 'application/x-tex',
  4722. 'texi' => 'application/x-texinfo',
  4723. 'texinfo' => 'application/x-texinfo',
  4724. 'text' => 'text/plain',
  4725. 'tfi' => 'application/thraud+xml',
  4726. 'tfm' => 'application/x-tex-tfm',
  4727. 'tga' => 'image/x-tga',
  4728. 'thmx' => 'application/vnd.ms-officetheme',
  4729. 'tif' => 'image/tiff',
  4730. 'tiff' => 'image/tiff',
  4731. 'tmo' => 'application/vnd.tmobile-livetv',
  4732. 'torrent' => 'application/x-bittorrent',
  4733. 'tpl' => 'application/vnd.groove-tool-template',
  4734. 'tpt' => 'application/vnd.trid.tpt',
  4735. 'tr' => 'text/troff',
  4736. 'tra' => 'application/vnd.trueapp',
  4737. 'trm' => 'application/x-msterminal',
  4738. 'tsd' => 'application/timestamped-data',
  4739. 'tsv' => 'text/tab-separated-values',
  4740. 'ttc' => 'application/x-font-ttf',
  4741. 'ttf' => 'application/x-font-ttf',
  4742. 'ttl' => 'text/turtle',
  4743. 'twd' => 'application/vnd.simtech-mindmapper',
  4744. 'twds' => 'application/vnd.simtech-mindmapper',
  4745. 'txd' => 'application/vnd.genomatix.tuxedo',
  4746. 'txf' => 'application/vnd.mobius.txf',
  4747. 'txt' => 'text/plain',
  4748. 'u32' => 'application/x-authorware-bin',
  4749. 'udeb' => 'application/x-debian-package',
  4750. 'ufd' => 'application/vnd.ufdl',
  4751. 'ufdl' => 'application/vnd.ufdl',
  4752. 'ulx' => 'application/x-glulx',
  4753. 'umj' => 'application/vnd.umajin',
  4754. 'unityweb' => 'application/vnd.unity',
  4755. 'uoml' => 'application/vnd.uoml+xml',
  4756. 'uri' => 'text/uri-list',
  4757. 'uris' => 'text/uri-list',
  4758. 'urls' => 'text/uri-list',
  4759. 'ustar' => 'application/x-ustar',
  4760. 'utz' => 'application/vnd.uiq.theme',
  4761. 'uu' => 'text/x-uuencode',
  4762. 'uva' => 'audio/vnd.dece.audio',
  4763. 'uvd' => 'application/vnd.dece.data',
  4764. 'uvf' => 'application/vnd.dece.data',
  4765. 'uvg' => 'image/vnd.dece.graphic',
  4766. 'uvh' => 'video/vnd.dece.hd',
  4767. 'uvi' => 'image/vnd.dece.graphic',
  4768. 'uvm' => 'video/vnd.dece.mobile',
  4769. 'uvp' => 'video/vnd.dece.pd',
  4770. 'uvs' => 'video/vnd.dece.sd',
  4771. 'uvt' => 'application/vnd.dece.ttml+xml',
  4772. 'uvu' => 'video/vnd.uvvu.mp4',
  4773. 'uvv' => 'video/vnd.dece.video',
  4774. 'uvva' => 'audio/vnd.dece.audio',
  4775. 'uvvd' => 'application/vnd.dece.data',
  4776. 'uvvf' => 'application/vnd.dece.data',
  4777. 'uvvg' => 'image/vnd.dece.graphic',
  4778. 'uvvh' => 'video/vnd.dece.hd',
  4779. 'uvvi' => 'image/vnd.dece.graphic',
  4780. 'uvvm' => 'video/vnd.dece.mobile',
  4781. 'uvvp' => 'video/vnd.dece.pd',
  4782. 'uvvs' => 'video/vnd.dece.sd',
  4783. 'uvvt' => 'application/vnd.dece.ttml+xml',
  4784. 'uvvu' => 'video/vnd.uvvu.mp4',
  4785. 'uvvv' => 'video/vnd.dece.video',
  4786. 'uvvx' => 'application/vnd.dece.unspecified',
  4787. 'uvvz' => 'application/vnd.dece.zip',
  4788. 'uvx' => 'application/vnd.dece.unspecified',
  4789. 'uvz' => 'application/vnd.dece.zip',
  4790. 'vcard' => 'text/vcard',
  4791. 'vcd' => 'application/x-cdlink',
  4792. 'vcf' => 'text/x-vcard',
  4793. 'vcg' => 'application/vnd.groove-vcard',
  4794. 'vcs' => 'text/x-vcalendar',
  4795. 'vcx' => 'application/vnd.vcx',
  4796. 'vis' => 'application/vnd.visionary',
  4797. 'viv' => 'video/vnd.vivo',
  4798. 'vob' => 'video/x-ms-vob',
  4799. 'vor' => 'application/vnd.stardivision.writer',
  4800. 'vox' => 'application/x-authorware-bin',
  4801. 'vrml' => 'model/vrml',
  4802. 'vsd' => 'application/vnd.visio',
  4803. 'vsf' => 'application/vnd.vsf',
  4804. 'vss' => 'application/vnd.visio',
  4805. 'vst' => 'application/vnd.visio',
  4806. 'vsw' => 'application/vnd.visio',
  4807. 'vtu' => 'model/vnd.vtu',
  4808. 'vxml' => 'application/voicexml+xml',
  4809. 'w3d' => 'application/x-director',
  4810. 'wad' => 'application/x-doom',
  4811. 'wav' => 'audio/x-wav',
  4812. 'wax' => 'audio/x-ms-wax',
  4813. 'wbmp' => 'image/vnd.wap.wbmp',
  4814. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  4815. 'wbxml' => 'application/vnd.wap.wbxml',
  4816. 'wcm' => 'application/vnd.ms-works',
  4817. 'wdb' => 'application/vnd.ms-works',
  4818. 'wdp' => 'image/vnd.ms-photo',
  4819. 'weba' => 'audio/webm',
  4820. 'webm' => 'video/webm',
  4821. 'webp' => 'image/webp',
  4822. 'wg' => 'application/vnd.pmi.widget',
  4823. 'wgt' => 'application/widget',
  4824. 'wks' => 'application/vnd.ms-works',
  4825. 'wm' => 'video/x-ms-wm',
  4826. 'wma' => 'audio/x-ms-wma',
  4827. 'wmd' => 'application/x-ms-wmd',
  4828. 'wmf' => 'application/x-msmetafile',
  4829. 'wml' => 'text/vnd.wap.wml',
  4830. 'wmlc' => 'application/vnd.wap.wmlc',
  4831. 'wmls' => 'text/vnd.wap.wmlscript',
  4832. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  4833. 'wmv' => 'video/x-ms-wmv',
  4834. 'wmx' => 'video/x-ms-wmx',
  4835. 'wmz' => 'application/x-ms-wmz',
  4836. 'wmz' => 'application/x-msmetafile',
  4837. 'woff' => 'application/font-woff',
  4838. 'wpd' => 'application/vnd.wordperfect',
  4839. 'wpl' => 'application/vnd.ms-wpl',
  4840. 'wps' => 'application/vnd.ms-works',
  4841. 'wqd' => 'application/vnd.wqd',
  4842. 'wri' => 'application/x-mswrite',
  4843. 'wrl' => 'model/vrml',
  4844. 'wsdl' => 'application/wsdl+xml',
  4845. 'wspolicy' => 'application/wspolicy+xml',
  4846. 'wtb' => 'application/vnd.webturbo',
  4847. 'wvx' => 'video/x-ms-wvx',
  4848. 'x32' => 'application/x-authorware-bin',
  4849. 'x3d' => 'model/x3d+xml',
  4850. 'x3db' => 'model/x3d+binary',
  4851. 'x3dbz' => 'model/x3d+binary',
  4852. 'x3dv' => 'model/x3d+vrml',
  4853. 'x3dvz' => 'model/x3d+vrml',
  4854. 'x3dz' => 'model/x3d+xml',
  4855. 'xaml' => 'application/xaml+xml',
  4856. 'xap' => 'application/x-silverlight-app',
  4857. 'xar' => 'application/vnd.xara',
  4858. 'xbap' => 'application/x-ms-xbap',
  4859. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  4860. 'xbm' => 'image/x-xbitmap',
  4861. 'xdf' => 'application/xcap-diff+xml',
  4862. 'xdm' => 'application/vnd.syncml.dm+xml',
  4863. 'xdp' => 'application/vnd.adobe.xdp+xml',
  4864. 'xdssc' => 'application/dssc+xml',
  4865. 'xdw' => 'application/vnd.fujixerox.docuworks',
  4866. 'xenc' => 'application/xenc+xml',
  4867. 'xer' => 'application/patch-ops-error+xml',
  4868. 'xfdf' => 'application/vnd.adobe.xfdf',
  4869. 'xfdl' => 'application/vnd.xfdl',
  4870. 'xht' => 'application/xhtml+xml',
  4871. 'xhtml' => 'application/xhtml+xml',
  4872. 'xhvml' => 'application/xv+xml',
  4873. 'xif' => 'image/vnd.xiff',
  4874. 'xla' => 'application/vnd.ms-excel',
  4875. 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
  4876. 'xlc' => 'application/vnd.ms-excel',
  4877. 'xlf' => 'application/x-xliff+xml',
  4878. 'xlm' => 'application/vnd.ms-excel',
  4879. 'xls' => 'application/vnd.ms-excel',
  4880. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
  4881. 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
  4882. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  4883. 'xlt' => 'application/vnd.ms-excel',
  4884. 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
  4885. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  4886. 'xlw' => 'application/vnd.ms-excel',
  4887. 'xm' => 'audio/xm',
  4888. 'xml' => 'application/xml',
  4889. 'xo' => 'application/vnd.olpc-sugar',
  4890. 'xop' => 'application/xop+xml',
  4891. 'xpi' => 'application/x-xpinstall',
  4892. 'xpl' => 'application/xproc+xml',
  4893. 'xpm' => 'image/x-xpixmap',
  4894. 'xpr' => 'application/vnd.is-xpr',
  4895. 'xps' => 'application/vnd.ms-xpsdocument',
  4896. 'xpw' => 'application/vnd.intercon.formnet',
  4897. 'xpx' => 'application/vnd.intercon.formnet',
  4898. 'xsl' => 'application/xml',
  4899. 'xslt' => 'application/xslt+xml',
  4900. 'xsm' => 'application/vnd.syncml+xml',
  4901. 'xspf' => 'application/xspf+xml',
  4902. 'xul' => 'application/vnd.mozilla.xul+xml',
  4903. 'xvm' => 'application/xv+xml',
  4904. 'xvml' => 'application/xv+xml',
  4905. 'xwd' => 'image/x-xwindowdump',
  4906. 'xyz' => 'chemical/x-xyz',
  4907. 'xz' => 'application/x-xz',
  4908. 'yang' => 'application/yang',
  4909. 'yin' => 'application/yin+xml',
  4910. 'z1' => 'application/x-zmachine',
  4911. 'z2' => 'application/x-zmachine',
  4912. 'z3' => 'application/x-zmachine',
  4913. 'z4' => 'application/x-zmachine',
  4914. 'z5' => 'application/x-zmachine',
  4915. 'z6' => 'application/x-zmachine',
  4916. 'z7' => 'application/x-zmachine',
  4917. 'z8' => 'application/x-zmachine',
  4918. 'zaz' => 'application/vnd.zzazz.deck+xml',
  4919. 'zip' => 'application/zip',
  4920. 'zir' => 'application/vnd.zul',
  4921. 'zirz' => 'application/vnd.zul',
  4922. 'zmm' => 'application/vnd.handheld-entertainment+xml'
  4923. );
  4924. }
  4925. // Always run this
  4926. dependCheck();