*/}}

index.php 349 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010
  1. <?php
  2. include 'Parsedown.php';
  3. include 'ParsedownExtra.php';
  4. ini_set('max_execution_time', 300);
  5. if($_SERVER['HTTP_HOST']=='localhost'){
  6. ini_set('display_errors', '0');
  7. ini_set('display_startup_errors', '1');
  8. error_reporting(E_ALL);
  9. }
  10. global $LA_GLOBAL_LANG;
  11. global $INDEXPHP;
  12. $INDEXPHP='index.php';
  13. if($LA_GLOBAL_LANG=='en'){
  14. $INDEXPHP='en.php';
  15. }
  16. class LA{
  17. protected $PDE;
  18. protected $style;
  19. public $PAGE;
  20. public $AFTER;
  21. public $PSTACK;
  22. protected $PNUMBER;
  23. /* config */
  24. protected $Title;
  25. protected $ShortTitle;
  26. protected $Admin;
  27. protected $Password;
  28. protected $DisplayName;
  29. protected $EMail;
  30. protected $SpecialNavigation;
  31. protected $SpecialSidebar;
  32. protected $SpecialFooter;
  33. protected $SpecialFooter2;
  34. protected $SpecialPinned;
  35. protected $DefaultGallery;
  36. protected $SelfAuthPath;
  37. protected $HereHost;
  38. protected $HereTitle;
  39. protected $HereShortTitle;
  40. protected $HereAlbum;
  41. protected $HereNavigation;
  42. protected $HereFooter;
  43. protected $ExpHost;
  44. protected $ExpAlbum;
  45. protected $ExpTitle;
  46. protected $ExpShortTitle;
  47. protected $ExpCaution;
  48. protected $ExpNavigation;
  49. protected $ExpFooter;
  50. protected $CommentEnabled;
  51. protected $MastodonToken;
  52. protected $MastodonURL;
  53. protected $MastodonPreferredLang;
  54. protected $HostURL;
  55. protected $GalleryStep;
  56. protected $AllowLanguageChoices;
  57. protected $Redirect;
  58. protected $Translations;
  59. protected $CustomTranslationContent;
  60. protected $CommentsPerPage;
  61. protected $UsePosts;
  62. protected $CurrentOffset;
  63. protected $PostsPerPage;
  64. protected $HotPostCount;
  65. protected $LoggedIn;
  66. protected $LoginTokens;
  67. protected $InHereMode;
  68. protected $InExperimentalMode;
  69. protected $LanguageAppendix;
  70. protected $UseRemoteFont;
  71. protected $Posts;
  72. protected $Threads; // [ keys: first last displayed count]
  73. protected $WaybackThreads;
  74. public $Images;
  75. protected $Galleries;
  76. protected $Anchors;
  77. protected $ArchiveHandles;
  78. protected $Archive;
  79. public $WayBack;
  80. protected $YearBegin;
  81. protected $YearEnd;
  82. protected $Markers;
  83. protected $ExtraScripts;
  84. protected $APubID;
  85. protected $APubActor;
  86. protected $APubPublicKey;
  87. protected $APubPrivateKey;
  88. protected $TIME_STRING;
  89. public $NULL_POST;
  90. public $NULL_IMAGE;
  91. public $NULL_IMAGE_DUMMY;
  92. public $NULL_Gallery;
  93. protected $DoneReadPosts;
  94. protected $DoneReadImages;
  95. protected $DoneReadArchive;
  96. protected $NeedWritePosts;
  97. protected $NeedWriteImages;
  98. protected $NeedWriteArchive;
  99. protected $HereDisplayTitle;
  100. protected $VisitedHere;
  101. protected $HereNumber;
  102. protected $HereMainImage;
  103. public $PageType;
  104. public $CurrentPostID;
  105. public $HereID;
  106. public $ActualPostID;
  107. public $TagID;
  108. function &_TRow(){ if(!isset($this->PAGE)){$this->PAGE=[];} if(!isset($this->PAGE[0])){$this->PAGE[]=[];} return $this->PAGE[array_key_last($this->PAGE)]; }
  109. function &TRow(){ $last=array_key_last($this->PAGE); if($this->PAGE[$last]==[]) return $this->PAGE[$last]; $this->PAGE[]=[]; return $this->PAGE[$last]; }
  110. function TFill($k,&$content,$span=null){ $a=&$this->_TRow();if(!isset($a[$k]))$a[$k]="";$a[$k].=$content; $content=''; if($span!=null && $span>1){ $a['span'.$k]=$span; } }
  111. function TExtra($rowextra){ $a=&$this->_TRow(); $a['extra']=$rowextra; }
  112. function TAfter(&$content){ $this->AFTER.=$content; $content=''; }
  113. function TBackup(){ if(!isset($this->PSTACK)){$this->PSTACK=[];}; $this->PSTACK[]=$this->PAGE; $this->PAGE=[]; }
  114. function TRestore($extra=""){ if(!isset($this->PSTACK) || $this->PSTACK==[]) return "";
  115. $S=$this->GeneratePage(0,$extra); $this->PAGE=end($this->PSTACK); unset($this->PSTACK[array_key_last($this->PSTACK)]); return $S;
  116. }
  117. function ReadableTime($id){
  118. $dt = DateTime::createFromFormat('YmdHis', $id);
  119. return $dt->format('Y/m/d H:i:s');
  120. }
  121. function StandardTime($id){
  122. $dt = DateTime::createFromFormat('YmdHis', $id);
  123. return $dt->format('Y-m-d\TH:i:sP');
  124. }
  125. function FullURL(){
  126. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  127. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  128. $_SERVER['REQUEST_URI'];
  129. }
  130. function T($str){
  131. if(!$this->LanguageAppendix) return $str;
  132. foreach($this->Translations as $entry){
  133. if($entry['zh']==$str)
  134. return $entry[$this->LanguageAppendix];
  135. }
  136. return $str;
  137. }
  138. function SwitchLanguageAndFont(){ global $LA_GLOBAL_LANG;
  139. $this->LanguageAppendix = 'zh';
  140. if(isset($_COOKIE['la_language'])){
  141. $this->LanguageAppendix = $_COOKIE['la_language'];
  142. }else{
  143. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  144. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  145. $lang = substr($lang,0,5);
  146. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  147. else $this->LanguageAppendix = 'en';
  148. }
  149. }
  150. if(isset($LA_GLOBAL_LANG)){
  151. if($LA_GLOBAL_LANG=='en'){ $this->LanguageAppendix = 'en'; setcookie('la_language','en',time()+3600*24*7); }
  152. else if($LA_GLOBAL_LANG=='zh'){ $this->LanguageAppendix = 'zh'; setcookie('la_language','zh',time()+3600*24*7); }
  153. }
  154. if(isset($_COOKIE['la_font'])){
  155. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  156. }
  157. }
  158. function SwitchWayBackMode(){
  159. if(isset($_COOKIE['la_wayback'])){
  160. $this->WayBack = $_COOKIE['la_wayback'];
  161. }else $this->WayBack = NULL;
  162. }
  163. function DisplayRedirectConfig(){
  164. $s = "";
  165. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  166. if($r['for']=='P'){
  167. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  168. }else if($r['for']=='S'){
  169. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  170. }
  171. }
  172. return $s;
  173. }
  174. function DoSiteRedirect(){ global $INDEXPHP;
  175. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  176. if($r['for']=='S'){
  177. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  178. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  179. header('Location:https://'.$r['domain'].'/'.$INDEXPHP.'?post='.$r['target']); exit;
  180. }else{
  181. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. function WriteHTACCESS(){
  188. $conf = fopen('.htaccess','w');
  189. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  190. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  191. if($r['for']=='P'){
  192. if(!preg_match('/[0-9]{14}/',$r['target'])){
  193. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?'.$r['target'].' [R=302,L,NC]'.PHP_EOL.PHP_EOL);
  194. }
  195. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L,NC]'.PHP_EOL.PHP_EOL);
  196. }// do site redirect in php.
  197. }
  198. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  199. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  200. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  201. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]'.PHP_EOL.PHP_EOL);
  202. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  203. fflush($conf);fclose($conf);
  204. }
  205. function BuildRedirectConfig($conf){
  206. $this->Redirect=[];
  207. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14}|.+)\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  208. foreach($ma as $m){
  209. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  210. $this->Redirect[]=$redirect;
  211. }
  212. }
  213. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  214. foreach($ma as $m){
  215. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  216. $this->Redirect[]=$redirect;
  217. }
  218. }
  219. }
  220. function WriteTokens(){
  221. $tf = fopen('la_tokens.php','w');
  222. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  223. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  224. foreach($this->LoginTokens as $t){
  225. fwrite($tf,'- '.$t.PHP_EOL);
  226. }
  227. }
  228. fflush($tf);fclose($tf);
  229. }
  230. function WriteConfig(){
  231. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  232. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  233. if(!isset($this->Admin)) $this->Admin = 'admin';
  234. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  235. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  236. $conf = fopen('la_config.php','w');
  237. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  238. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  239. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  240. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  241. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  242. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  243. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  244. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  245. fwrite($conf,'- SpecialSidebar = '.$this->SpecialSidebar.PHP_EOL);
  246. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  247. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  248. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  249. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  250. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  251. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  252. fwrite($conf,'- NewsletterEnabled = '.($this->NewsletterEnabled?"True":"False").PHP_EOL);
  253. fwrite($conf,'- HereHost = '.$this->HereHost.PHP_EOL);
  254. fwrite($conf,'- HereTitle = '.$this->HereTitle.PHP_EOL);
  255. fwrite($conf,'- HereShortTitle = '.$this->HereShortTitle.PHP_EOL);
  256. fwrite($conf,'- HereAlbum = '.$this->HereAlbum.PHP_EOL);
  257. fwrite($conf,'- HereNavigation = '.$this->HereNavigation.PHP_EOL);
  258. fwrite($conf,'- HereFooter = '.$this->HereFooter.PHP_EOL);
  259. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  260. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  261. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  262. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  263. fwrite($conf,'- ExpAlbum = '.$this->ExpAlbum.PHP_EOL);
  264. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  265. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  266. fwrite($conf,'- MastodonToken = '.$this->MastodonToken.PHP_EOL);
  267. fwrite($conf,'- MastodonURL = '.$this->MastodonURL.PHP_EOL);
  268. fwrite($conf,'- MastodonPreferredLang = '.$this->MastodonPreferredLang.PHP_EOL);
  269. fwrite($conf,'- HostURL = '.$this->HostURL.PHP_EOL);
  270. fwrite($conf,'- APubID = '.$this->APubID.PHP_EOL);
  271. fwrite($conf,'- GalleryStep = '.$this->GalleryStep.PHP_EOL);
  272. fwrite($conf,'- AllowLanguageChoices = '.$this->AllowLanguageChoices.PHP_EOL);
  273. fflush($conf);fclose($conf);
  274. $conf = fopen('la_redirect.md','w');
  275. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  276. $this->WriteHTACCESS();
  277. $this->WriteTokens();
  278. }
  279. function Install(){
  280. if(!file_exists('la_config.php')){
  281. $this->WriteConfig();
  282. }
  283. if(!is_dir('posts')) mkdir('posts');
  284. if(!is_dir('images')) mkdir('images');
  285. if(!is_dir('images/thumb')) mkdir('images/thumb');
  286. if(!is_dir('styles')) mkdir('styles');
  287. if(!is_dir('archive')) mkdir('archive');
  288. $this->WriteStyles();
  289. $this->WriteHTACCESS();
  290. }
  291. function ReadFromExistingConfig(){
  292. $f=null;
  293. if(file_exists('la_config.php')) $f='la_config.php';
  294. else if(file_exists('la_config.md')) $f='la_config.md';
  295. if(!isset($f)) return;
  296. $c = file_get_contents($f);
  297. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  298. $str = $m[1];
  299. $this->$str = $m[2];
  300. }
  301. $this->CommentEnabled = $this->CommentEnabled=="True";
  302. if(!isset($this->GalleryStep)) $this->GalleryStep=20;
  303. }
  304. function ReadConfig(){
  305. $this->ReadFromExistingConfig();
  306. if(file_exists('la_redirect.md')){
  307. $c = file_get_contents('la_redirect.md');
  308. $this->BuildRedirectConfig($c);
  309. }
  310. if(!file_exists('la_config.php')){
  311. $this->Install();
  312. }
  313. $this->Translations=[];
  314. if(file_exists("translations.md")){
  315. $c = file_get_contents('translations.md');
  316. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  317. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  318. $this->Translations[] = $entry;
  319. }
  320. }
  321. if(file_exists("custom_translations.md")){
  322. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  323. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  324. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  325. $this->Translations[] = $entry;
  326. }
  327. }
  328. $this->LoginTokens=[];
  329. if(file_exists('la_tokens.php')){
  330. $c = file_get_contents('la_tokens.php');
  331. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  332. $this->LoginTokens[] = $m[1];
  333. }
  334. }
  335. }
  336. function MastodonPostStatus($status){ return $this->MastodonCall('/api/v1/statuses', 'POST', $status); }
  337. function MastodonPostMedia($media){ return $this->MastodonCall('/api/v1/media', 'POST', $media); }
  338. function MastodonCall($endpoint, $method, $data){
  339. $headers = [
  340. 'Authorization: Bearer '.$this->MastodonToken,
  341. 'Content-Type: multipart/form-data',
  342. ];
  343. $ch = curl_init();
  344. curl_setopt($ch, CURLOPT_URL, $this->MastodonURL.$endpoint);
  345. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  346. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  347. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  348. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  349. $reply = curl_exec($ch);
  350. if (!$reply) {
  351. return json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch_status), 'curl_error' => curl_error(ch_status)]);
  352. }
  353. curl_close($ch);
  354. return json_decode($reply, true);
  355. }
  356. function MastodonSendPost(&$post, &$errmsg=NULL){
  357. if(isset($post['mark_value']) && $post['mark_value']==7){ return NULL; }
  358. $this->LanguageAppendix = 'zh';
  359. if(in_array($this->MastodonPreferredLang,['en','zh'])){ $this->LanguageAppendix = $this->MastodonPreferredLang; }
  360. $this->ConvertPost($post);
  361. $media_ids = NULL;
  362. $mastodon_post_url = NULL;
  363. $imcount = 0;
  364. if(isset($post['original_images']) && isset($post['original_images'][0])) foreach($post['original_images'] as $im){
  365. $curl_file = curl_file_create($im, mime_content_type($im), basename($im));
  366. $body = ['file' => $curl_file,]; $response = $this->MastodonPostMedia($body);
  367. if(isset($response['id'])){ if(!isset($media_ids)){$media_ids=[];} $media_ids[]=$response['id']; }
  368. else{ if(isset($response['error'])) $errmsg.=$response['error']."<br /><br />"; }
  369. $imcount++; if($imcount>=4){ break; }
  370. }
  371. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$post['html']));
  372. if(isset($this->HostURL) && $this->HostURL!=""){
  373. $text.=("\n\n".$this->T('来自').' '.$this->HostURL.'?post='.$post['id']);
  374. }
  375. $vis = (isset($post['mark_value']) && $post['mark_value']==6)?"private":"public";
  376. $status_data = [ 'status' => $text, 'visibility' => $vis, 'language' => $this->LanguageAppendix, ];
  377. if(isset($post['prev']) && ($pp=&$this->GetPost($post['prev']))!=$this->NULL_POST){
  378. if(isset($pp['mastodon_url'])){ $status_data['in_reply_to_id'] = basename($pp['mastodon_url']);
  379. }
  380. }
  381. if(isset($media_ids[0])){ $status_data['media_ids']=$media_ids; }
  382. $status_data = preg_replace('/(media_ids%5B)[0-9]+(%5D)/','$1$2', http_build_query($status_data));
  383. $status_response = $this->MastodonPostStatus($status_data);
  384. if(isset($status_response['url']) && $status_response['url']){
  385. $mastodon_post_url = $status_response['url'];
  386. $post['mastodon_url'] = $mastodon_post_url;
  387. $this->NeedWritePosts = 1;
  388. }
  389. if(isset($status_response['error'])) { $errmsg .= $status_response['error']; }
  390. return $mastodon_post_url;
  391. }
  392. function __construct() {
  393. $this->ReadConfig();
  394. $this->PDE = new ParsedownExtra();
  395. $this->PDE->SetInterlinkPath('/');
  396. $this->Posts = [];
  397. $this->Threads = [];
  398. $this->VisitedHere = [];
  399. $this->NULL_IMAGE_DUMMY = [];
  400. $this->NULL_IMAGE_DUMMY['name']=$this->NULL_IMAGE_DUMMY['file']=$this->NULL_IMAGE_DUMMY['thumb']="";
  401. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  402. $this->PostsPerPage = 40;
  403. $this->CommentsPerPage = 100;
  404. $this->HotPostCount = 15;
  405. $this->TIME_STRING = date('YmdHis');
  406. $this->WayBack = NULL;
  407. $this->YearBegin = $this->YearEnd = 2000;
  408. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  409. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  410. $this->UsePosts = &$this->Posts;
  411. $this->PNUMBER=0;
  412. }
  413. function DoLogout(){
  414. $this->LoggedIn = false;
  415. unset($_SESSION['user_id']);
  416. $this->RecordToken(true);
  417. }
  418. function RecordToken($unset_current=false){
  419. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  420. $t = $_COOKIE['la_token'];
  421. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  422. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  423. $this->WriteTokens();
  424. return null;
  425. }else{
  426. $t = uniqid('la_',true);
  427. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  428. $this->LoginTokens[] = $t;
  429. $this->WriteTokens();
  430. return $t;
  431. }
  432. }
  433. function LoginThroughToken(){
  434. if(!isset($_COOKIE['la_token'])) return false;
  435. $t = $_COOKIE['la_token'];
  436. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  437. $_SESSION['user_id']=$this->Admin;
  438. $this->LoggedIn = true;
  439. setcookie('la_token',$t,time()+3600*24*7);
  440. return true;
  441. }
  442. return false;
  443. }
  444. function DoLogin(){
  445. session_start();
  446. $redirect=false;
  447. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  448. else if(!isset($_SESSION['user_id'])){
  449. if(isset($_POST['login_button'])){
  450. $id = trim($_POST['login_id']);
  451. $pwd = trim($_POST['login_password']);
  452. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  453. $_SESSION['user_id']=$id;
  454. $this->RecordToken(false);
  455. }
  456. $redirect = true;
  457. }else if($this->LoginThroughToken()){
  458. // nothing;
  459. }
  460. }else{
  461. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  462. else{ $this->DoLogout();}
  463. }
  464. if($redirect){
  465. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  466. .(isset($_GET['settings'])?"?settings=true":""));
  467. }
  468. }
  469. function SetHereMainImage($im_this){
  470. if(isset($im_this) && isset($im_this['parent'])){ $this->HereMainImage = &$this->FindImage($im_this['parent'],true);}
  471. }
  472. function RecordVisitedHere($image_or_post_name, $image_title){
  473. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  474. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  475. if(!(isset($_SESSION[$visited_here][0]) && in_array($image_or_post_name,$_SESSION[$visited_here]))){
  476. $_SESSION[$visited_here][] = $image_or_post_name;
  477. }
  478. if(isset($image_title)){ $this->HereDisplayTitle=$image_title; }
  479. $this->HereNumber = array_search($image_or_post_name,$_SESSION[$visited_here])+1;
  480. $_SESSION['here_number'] = $this->HereNumber;
  481. $this->VisitedHere = $_SESSION[$visited_here];
  482. }
  483. function HereLinkFromNumber($number){
  484. $number -= 1; if($number<0){ $number=0; }
  485. if($number>=sizeof($this->VisitedHere)){ $number = sizeof($this->VisitedHere)-1; }
  486. if(preg_match('/(jpg|jpeg|png|gif)/u',$this->VisitedHere[$number])){ return "?here=images/".$this->VisitedHere[$number]; }
  487. else{ return "?post=".$this->VisitedHere[$number]; }
  488. }
  489. function WriteStyles(){
  490. $this->style="
  491. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  492. .page{overflow:none;}
  493. body{background-color:%white%;color:%black%;}
  494. sup,sub{line-height:0;} .lpctrl{display:none;}
  495. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  496. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  497. b,strong,th{font-weight:bold;}
  498. select{font-size:inherit;}
  499. .page,.page_gallery{padding:1em;padding-top:0;padding-bottom:0;}
  500. .hidden_on_desktop,.hidden_on_wide{display:none;}
  501. .hidden_on_desktop_force{display:none !important;}
  502. ::file-selector-button{background:none;border:none;}
  503. a,button,::file-selector-button{text-decoration:underline;color:%black%;text-decoration-thickness:2px;text-underline-offset:0.15em;}
  504. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  505. .button:disabled{background-color:%gray%;pointer-events:none;}
  506. header{position:fixed;top:0;width:calc(100% - 2em);background-color:%white%;z-index:10;padding-top:0.5em;box-shadow: 0.5em 0px %white%;}
  507. header::before{content:'';position:absolute;left:0;right:0;top:0;height:1.95em;box-shadow:-2em 0em 1em -1em inset %white%;pointer-events:none;}
  508. header>div{overflow:auto;white-space:nowrap;}
  509. .header_nav{display:inline;}
  510. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  511. header a:hover,.button:hover{color:%gray% !important;text-decoration:underline;text-decoration-thickness:2px;text-underline-offset:0.15em;}
  512. .exp_h_f{padding-top:0.3em !important;padding-bottom:0.3em !important;line-height:1.5em !important;height:2.1em !important;}
  513. .exp_f{text-align:center;}
  514. .toc_button{position:absolute;top:0.5em;right:0;text-shadow: 0px 0px 10px %white%;background-color:%white%88;}
  515. .footer{background-color:%white%;z-index:10;position:relative;}
  516. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  517. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  518. .gray,.gray a{color:%gray%;}
  519. hr{border:1px solid %gray%;}
  520. header ul,.small_footer ul,.small_footer span,header li,.small_footer li{display:inline-block;vertical-align:text-top;}
  521. header li::before,.small_footer li::before{content:' - '}
  522. header li ul{display:none;}
  523. header:hover li ul{display:inline;}
  524. header li ul li{display:block !important;margin-left:1em;}
  525. header li ul li a{font-size:0.9em;}
  526. //h1,h2,h3,h4,h5{font-size:1em;}
  527. //h1{text-decoration:underline;}
  528. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  529. .main{position:relative;word-spacing:-1em;top:2em;margin-bottom:2em;}
  530. .main *{word-spacing:initial;}
  531. pre{overflow:auto;display:block;line-break:anywhere;white-space:pre-wrap;}code{font-size:0.83em;}
  532. ul{display:block;}
  533. li{display:block;}
  534. .clean_table{border:none;font-size:1em !important;}.clean_table thead{box-shadow:none;}.clean_table td{vertical-align:top;}
  535. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  536. .settings input,.post inpiut{border:none!important;}
  537. .post table img{max-width:10rem !important;}
  538. td{padding-left:0.1em;padding-right:0.1em;}
  539. td:first-child{padding-left:0;}
  540. td:last-child{padding-right:0;}
  541. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  542. thead{box-shadow:inset 0 -1px 0 0px %black%;}
  543. .post table{font-size:0.85em;}
  544. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  545. .interesting_tbody td{display:contents;}
  546. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  547. .interesting_tbody td>*{display:table-cell;}
  548. .interesting_tbody td>.wscroll{display:none !important;}
  549. .interesting_tbody .post_access{padding-top:0;}
  550. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  551. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  552. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  553. .interesting_tbody td>.imd>a{display:flex;}
  554. .interesting_tbody img{object-fit:cover;width:100%;}
  555. .interesting_tbody .p_row{display:flex;position:absolute;left:1.4em;top:0.25em;z-index:-1;flex-wrap:nowrap;max-width:calc(100% - 1.4em);}
  556. .interesting_tbody .p_thumb{height:1em;}
  557. .interesting_tbody .p_thumb img,.interesting_tbody .p_thumb video{max-height:10rem !important;max-width:20rem !important;}
  558. tr:hover .post_menu_button{opacity:1;}
  559. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  560. .align_right{text-align:right;}
  561. .left{display:inline-block;vertical-align:top;width:25%;padding-right:1.5em;padding-bottom:4rem;position:sticky;top:2em;
  562. overflow:auto;max-height:calc(100vh - 2.6em);}
  563. .center{display:inline-block;vertical-align:top;width:50%;overflow:visible;padding-bottom:4rem;}
  564. .center_slides{display:block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;font-size:5vmin;user-select:none;}
  565. .center_slides .print_column{display:table;position:fixed;top:0;right:0;left:0;bottom:0;width:100%;height:100%;z-index:90;}
  566. .center_slides .print_column .post{display:table-cell;vertical-align:middle;padding:5vmin !important;max-height:100vh;width:100vw;overflow:auto;}
  567. .center_slides .active_post{background-color:%white%;}.center_slides .post{background-color:%white%;}
  568. .center_slides .post_access{display:none;}
  569. .center_slides .post_menu_button{display:none !important;}
  570. .center_slides .post_width{display:block;vertical-align:middle;max-height:100vh;overflow-y:auto;overflow-x:hidden;width:100%;}
  571. .center_slides .linked_posts{display:none;}.center_slides .ref_compact{position:relative!important;display:block!important;}
  572. .slides_buttons{position:fixed;z-index:200;right:0.5rem;bottom:0.5rem;user-select:none;background-color:%white%aa;padding:0.5rem;font-family:monospace;}
  573. .slides_buttons a{text-decoration: none;}
  574. .center_slides .imd{text-align:center;pointer-events:none;}
  575. .imd_float{float:right;width:50% !important;clear:both;margin-left:0.5em !important;}
  576. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  577. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  578. .center_wide .p_thumb{height:12rem;width:12rem;margin:0;margin-right:0.5rem;margin-bottom:0.5rem;box-shadow:5px 5px 15px 2px black;}
  579. .linked_posts{padding:0.5em;background-color:#0004;box-shadow:0px 0.2em 0.2em -0.2em inset %shadow%;}
  580. .active_post .linked_posts{background-color:%highlight_slice%;}
  581. input:checked~.linked_posts,input:checked~a{display:none;}
  582. .bkg_recent>.post,.bkg_section{background:%post_white%;box-shadow:0em 0em 0.5em %shadow%;margin-bottom:0.5em;}
  583. .bkg_recent>.post>.post_width :last-child{margin-bottom:0;}
  584. .sticky_title{position:sticky;top:calc(1.6rem + 2px);z-index:1;background-color:%white%;pointer-events:none;}
  585. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  586. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  587. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  588. textarea,input[type=text],input[type=password]{font-family:monospace;width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  589. select,textarea,input[type=text],input[type=password]{font-family:monospace;background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  590. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  591. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  592. .post{position:relative;scroll-margin:3.5em;}
  593. .active_post{background-color:%highlight_white%;}.active_post .post_access{background-color:%highlight_slice%;}
  594. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;}
  595. .post li,.footer_additional li,.footer_additional li,.post_dummy li
  596. {display:list-item;margin-left:1em;list-style:disc;}
  597. .post li li,.footer_additional li li,.footer_additional li li,.post_dummy li li
  598. {list-style:circle;}
  599. ol li{list-style:unset !important;}
  600. .post_width > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  601. .post > td:nth-child(3) > *{margin:0;margin-bottom:0.5rem}
  602. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  603. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  604. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  605. .gallery_left .selected{list-style:'→';}
  606. .bkg_section .post_width{padding-top:0;padding-bottom:0;}
  607. .bkg_section .restart+.post .post_width{padding-top:0.5em;}
  608. .post_width{display:inline-block;margin-left:0.5em;vertical-align:top;}
  609. .opt_compact .post_width,.ref_compact .post_width{padding-top:0;padding-bottom:0;}
  610. .p_thumb .post_menu_button{right:0.3rem;top:0.3em;}
  611. .post_menu_button{position:absolute;display:none;right:0rem;width:1.5rem;box-shadow:0px 0px 3px %shadow%;
  612. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;background-color:%post_white%aa;}
  613. .pointer{cursor:pointer;}
  614. .post:hover .post_menu_button{display:block;}
  615. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%grayslice%;
  616. padding:0.3em;right:0.3rem;text-align:right;border-radius:0.3em;font-size:1rem;
  617. box-shadow:0px 0px 10px %shadow%;}
  618. .pop_menu li{list-style:none;margin-left:0;}
  619. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  620. .toc{left:60%;width:40%;top:0;position:absolute;}
  621. .paa{width:1.4rem;min-width:1.4rem;}
  622. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;background-color:%post_white%;right:unset;left:-2em;}
  623. .active_post .opt_compact .post_access,.active_post .ref_compact .post_access{background-color:%highlight_white%;}
  624. .post_preview{overflow:hidden;margin-bottom:0.4em;background-color:%white%aa;box-shadow: 0px 0px 0.2em %shadow%;}
  625. .post_preview:hover{filter:contrast(90%);}
  626. .active_post .post_preview:hover{filter:contrast(90%);}
  627. .hide_long{max-height:12em;overflow:hidden !important;}
  628. .post .post_ref{margin:0;padding-left:1.5rem;}
  629. .post_ref_main{display:inline-block;vertical-align:top;max-height:6em;overflow:hidden;margin:0.4em;}
  630. .post_ref_images{overflow:hidden;margin:0.4em;margin-top:0;}
  631. .post_ref_hint{text-align:right;}
  632. .page_selector{padding-top:2rem;text-align:center;}
  633. .smaller{font-size:0.85em;} .bigger{font-size:1.3em;} .block{display:block;}
  634. .restart{text-align:left;padding-top:1rem;padding-bottom:0.5rem;}
  635. .opt_compact{margin-left:2rem;}
  636. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  637. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  638. .spacer{height:0.5em;}
  639. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  640. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  641. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  642. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  643. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  644. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  645. .backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0,0,0,0.5);transition-timing-function:ease-out;z-index:90;}
  646. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  647. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  648. .toc_entry_1{font-size:1.1em;}
  649. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  650. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  651. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  652. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  653. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  654. .post h1,.post h2,.post h3,.post h4,.post h5{margin-top:1rem;}
  655. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  656. .deleted_post{color:%gray%;text-decoration:line-through;}
  657. #file_list{margin-top:0.5em;}
  658. .file_thumb img,.file_thumb video{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  659. .file_thumb video{border:2px dashed %black%;}f
  660. #file_list li{margin-bottom:0.3em;}
  661. .ref_thumb{white-space:nowrap;overflow:hidden;}
  662. .ref_thumb .file_thumb{width:2em;height:2em;margin:0;margin-right:0.3em}
  663. .side_thumb li{margin:0.4em;display:inline-block;}
  664. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  665. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  666. .p_thumb{display:flex;flex-grow:100;height:6rem;overflow:hidden;position:relative;margin-right:0.5em;margin-bottom:0.5em;}
  667. .p_thumb_narrow{width:1rem !important;flex-grow:1;opacity:0.2;}
  668. .p_thumb img,.p_thumb video{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  669. .p_thumb:hover .post_menu_button{display:block;}
  670. .p_thumb_selected{color:%black% !important;}
  671. .p_thumb_selected{display:block;}
  672. .post .p_thumb img,.post .p_thumb video{max-height:6rem;}
  673. .p_thumb video{border-bottom:0.4em dashed %black%;border-top:0.4em dashed %black%;}
  674. .p_thumb_end{flex-grow:10000 !important;box-shadow:none;align-items:center;padding:2em !important;}
  675. .p_thumb_end:hover, .p_thumb_end a:hover{background-color:%gray%;cursor:pointer;}
  676. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  677. .big_image_box *{pointer-events:auto;}
  678. .big_image_box img,.big_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  679. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  680. .here_image_box img,.here_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  681. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;pointer-events:none;}
  682. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  683. .big_side_box a:hover{color:%gray%;}
  684. .big_side_box *{pointer-events:auto;}
  685. .big_side_box .post_preview{border-bottom:1px dotted %black%;background-color:unset;}
  686. .image_nav{pointer-events:none;}
  687. #dropping_background{background-color:rgba(255,255,255,0.4);position:fixed;top:0;right:0;bottom:0;left:0;z-index:100;text-align:center;
  688. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  689. img,video{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  690. .post img,.post video{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  691. .post > a > img,.post > a > video{display:block;margin:0.3em auto;}
  692. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  693. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  694. .center_exp .post .original_img{display:block;}
  695. .original_img img,.original_img video{max-height:90vh;max-width:100%;}
  696. .p_row .original_img{margin-bottom:0;}
  697. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  698. .imbtn{color:rgba(0,0,0,0);display:block;contain:content;padding:0.25em;margin-bottom:0.5em;text-decoration:none;}
  699. .imbtn img{display:block;object-fit:cover;position:absolute;top:0;left:0;bottom:0;right:0;margin:auto;z-index:-1;
  700. min-width:100% !important;min-height:100% !important;filter:opacity(70%);transition:0.1s;}
  701. .imbtn:hover img{filter:opacity(20%) blur(0.2em);} .imbtn:hover{color:%black% !important;}
  702. .imbtn:hover {color:%black%;text-shadow:0px 0px 5px %white%;}
  703. header .imbtn{display:inherit;border:none;padding:0em;height:unset;height:unset;margin:0em;contain:unset;}
  704. header .imbtn:hover{border:none;color:%gray% !important;} header .imbtn img{display:none;}
  705. .b ul{font-size:1.4em;}
  706. no_pop{cursor:unset;}
  707. p{min-height:0.8em;}
  708. .bold,.bold *{font-weight:bold;}
  709. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  710. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;box-shadow: 0.5em 0px %white%;}
  711. .small_footer>div{overflow:auto;white-space:nowrap;}
  712. .small_footer::before{content:'';position:absolute;left:0;right:0;bottom:0;height:1.95em;box-shadow:-2em 0em 1em -1em inset %white%;pointer-events:none;}
  713. .top_post_hint{margin-left:0.5em;font-weight:bold;}
  714. .white{color:%white%;}
  715. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  716. .image_nav_prev,.image_nav_next{z-index:100;position:absolute;line-height:0;height:50%;width:20%;top:25%;display:flex;align-items:center;
  717. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  718. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.4));
  719. background-repeat:no-repeat;background-size:0% 100%;}
  720. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  721. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  722. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  723. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  724. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  725. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  726. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  727. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  728. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  729. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  730. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  731. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  732. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  733. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  734. .special_paypal_inner{color:#169bd7;}
  735. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  736. animation:anim_loading 1s linear infinite;}
  737. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  738. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  739. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  740. .product_thumb img,{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  741. .product_ref p{margin-bottom:0.2em;text-align:left;}
  742. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  743. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  744. .page_break{page-break-after:always;}
  745. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  746. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  747. .show_on_print{display:none;}.inline_print{display:none;}
  748. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  749. .comment tbody tr:hover{box-shadow:none;}
  750. .comment table{border:none;}
  751. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  752. .comment ul{padding-left:1em;}
  753. .comment ul li *{margin-bottom:0.5em;}
  754. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  755. .history li li{list-style:circle;}
  756. .history ul{padding-left:1em;}
  757. .history a{text-decoration:underline;}
  758. .history .list{overflow:auto;white-space:nowrap;}
  759. .diff_table{table-layout:fixed;}
  760. .diff_table thead{font-size:0.9em;text-align:center;}
  761. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  762. .diff_table td{vertical-align:top;}
  763. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  764. .wayback_close{float:right;}
  765. .wayback_expand{display:inline;}
  766. .post_selecting .post>*>*{pointer-events:none;}
  767. .post_selected{background-color:%graybkg%;}
  768. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  769. .wscroll{scroll-margin:3.5em;padding-left:0.3em;display:none;font-weight:bold;font-size:0.75em;box-shadow: 13em 0em 4em -8em inset %gray%;color:%white%;}
  770. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  771. .wayback_link{display:inline;}
  772. .imd{object-fit:cover;width:100%;}
  773. .center_exp .post>.imd,.center_exp .p_row{width:60%;}
  774. .center_exp .p_thumb img,.center_exp .p_thumb video{max-height:3rem;}
  775. .center_exp .p_thumb{max-height:3rem;filter:opacity(40%);}
  776. .center_exp .p_thumb:hover{filter:unset;}
  777. #here_buttons{display:contents;}
  778. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  779. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  780. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  781. .round_btn{box-shadow: 0px 0px 0px 1px inset %black%;display:inline-block;padding-left:0.4em;padding-right:0.4em;border-radius:0.5em;}
  782. .center .center{width:100%;padding-bottom:unset;}
  783. .center{border:none;}
  784. .center{overflow:auto;}
  785. .center>tbody>tr:hover{box-shadow:none;}
  786. .center>tbody>tr>td{white-space:normal;vertical-align:top;min-width:1em;}
  787. .center>tbody>tr>td:first-child{text-align:center;color:%gray%;padding-left:0.1em;}
  788. .center>tbody>tr>td:nth-child(1)>*{}
  789. .center>tbody>tr>td:nth-child(2){text-align:center;color:%gray%;}
  790. .center>tbody>tr>td:nth-child(2) a{color:%gray%;}
  791. .center>tbody>tr>td:nth-child(2) .marked{color:%black% !important;}
  792. .center>tbody>tr>td:nth-child(3){width:100%;text-align:left;}
  793. .center>tbody>tr>td:nth-child(3)>div{overflow:auto;}
  794. .center>tbody>tr>td:last-child{padding-right:0.5em;}
  795. .main>.center>tbody>tr{border-bottom:1px dotted %black%;}
  796. .ref_count{cursor:pointer;} td .ref_count{text-align:left;display:block;}
  797. .big_side_box .center{width:100%;}
  798. #big_image_upload{max-width:100%;}
  799. label{text-align:left;display:inline-block;}
  800. @media screen and (max-width:1000px) and (min-width:666px){
  801. .left{width:35%;}
  802. .center,.center_wide{width:65%;}
  803. .center_wide .p_thumb{height:8rem;width:8rem;margin-right:0.4rem;margin-bottom:0.4rem;box-shadow:3px 3px 12px 2px black;}
  804. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  805. .hidden_on_wide{display:unset;}
  806. .pop_right{width:30%;}
  807. .pop_right_big{width:40%;}
  808. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  809. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  810. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  811. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  812. .big_side_box{width:35%;}
  813. .big_image_box{width:65%;}
  814. .inquiry_buttons{right:35%;}
  815. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  816. .post_dummy > *{width:80%;max-width:55rem;}
  817. .center_exp .post>.imd,.center_exp .p_row{width:80%;max-width:55rem;}
  818. .here_btn{width:1.5em;height:1.5em;}
  819. }
  820. @media screen and (max-width:666px){
  821. .main{top:unset;margin-bottom:unset;}
  822. html{font-size:16px;}
  823. pre{max-width:85vw;}
  824. #titlectrl:checked ~ header .mobile_fold{display:block !important;}
  825. #titlectrl:checked ~ .main .mobile_fold{display:block !important;}
  826. #titlectrl:checked ~ header li ul{display:inline;}
  827. .mobile_fold{display:none !important;}
  828. .hidden_m{display:none !important;}
  829. .block_m{display:block !important;}
  830. .hidden_on_desktop{display:inherit;}
  831. .hidden_on_wide{display:inherit;}
  832. header{position:inherit;}
  833. header ul{display:block;}
  834. header li{display:block;}
  835. header li::before{content:''}
  836. header::before{box-shadow:none;display:none;}
  837. .small_footer::before{box-shadow:none;display:none;}
  838. .left{position:relative;width:100%;top:unset;height:unset;max-height:unset;padding-right:0;display:block;}
  839. .center,.center_wide,.center_full{display:block;position:relative;line-break:anywhere;left:0;top:0;width:100%;padding-left:0;}
  840. .center_wide .p_thumb{height:6rem;width:6rem;margin-right:0.3rem;margin-bottom:0.3rem;box-shadow:2px 2px 10px 1px black;}
  841. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  842. .pop_right{height:30%;}
  843. .pop_right_big{height:70%;}
  844. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  845. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  846. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  847. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  848. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  849. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  850. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  851. .side_box_mobile_inner:hover{background-size:100% 100%;}
  852. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  853. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  854. .p_thumb{height:3rem;}
  855. .center .post{padding-right:0rem;padding-left:0rem;}
  856. .post .p_thumb img,.post .p_thumb video{max-height:3rem;}
  857. .page,.page_gallery{padding:0.2em;padding-top:0;}
  858. header{padding-top:0.3em;}
  859. .toc_button{top:0.3em;}
  860. .small_footer{padding-bottom:0.3em;}
  861. .footer_additional{display:block;width:100%;}
  862. .album_hint{display:block;font-size:1rem;}
  863. .image_nav{position:absolute !important;}
  864. .image_nav_prev,.image_nav_next{width:25%;}
  865. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  866. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  867. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  868. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  869. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  870. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  871. .opt_compact,.ref_compact{line-break:anywhere;}
  872. .table_top{left:unset;width:100%;overflow:auto;}
  873. .post table img{max-width:30vw !important;}
  874. .product_ref{width:100%;display:block;}
  875. .post_dummy > *{width:100%;max-width:25rem;}
  876. .center_exp .post>.imd,.center_exp .p_row{width:100%;max-width:25rem;}
  877. .center_exp .post .p_thumb img,.center_exp .post .p_thumb video{max-height:2rem;}
  878. .center_exp .p_thumb{height:2rem;filter:opacity(40%);}
  879. .center_exp .p_thumb:hover{filter:unset;}
  880. .sticky_title{top:0;}
  881. .small_footer{position:relative;}
  882. #upload_selector{width:100%;}
  883. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  884. .wayback_expand{display:block;text-align:center;}
  885. .wayback_link{display:block;}
  886. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  887. .center_exp .post{overflow:auto;}
  888. .center_exp .imd{width:100%;}
  889. .here_btn{width:1.2em;height:1.2em;}
  890. .exp_h_f{height:unset !important;}
  891. .exp_f{margin-bottom:1em;}
  892. .linked_posts{padding-left:1em;}
  893. .center>tbody>tr>td{min-width:unset;}
  894. .center>tbody>tr>td:last-child{padding-right:0.1em;}
  895. }
  896. @media print{
  897. .small_footer .hidden_on_print{display:none}
  898. header b,.small_footer b{font-weight:normal;}
  899. header{display:table-header-group;box-shadow:none;} .main{display:table-row-group;top:unset;margin-bottom:unset;} .small_footer{text-align:right;}
  900. header::before{box-shadow:none;display:none;} header::after{display:block;height:1em;content:' ';}
  901. .small_footer::before{box-shadow:none;display:block;height:1em;position:relative;}
  902. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  903. .bkg_section,.bkg_recent>.post,.active_post{background:none !important;box-shadow:none;}
  904. .post *,.post_dummy *{margin-bottom:0em;}
  905. .p_row,.post table,.post img,.post_ref img,.post_ref .original_img,
  906. .post_width>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  907. pre{white-space:pre-wrap;line-break:anywhere;}
  908. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  909. .post table img{margin:0 !important;}
  910. .post h1+p,.post h2+p,.post img+p,.post video+p,.post .imd+p,.post table+p,.last_wide p:first-of-type{text-indent:0;}
  911. .post ul,.post ol{margin:0.5rem !important;margin-left:1.4rem !important;margin-right: 0rem !important;}
  912. table{border-bottom:2px solid black;border-top:2px solid black;}
  913. .post table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  914. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  915. .linked_posts{display:none;}
  916. .post_width{overflow:clip;left:0;width:100%;padding-left:0em;padding-right:0em;}
  917. .section .post h2{font-size:1.8em;margin:1.5em auto 0 !important;}.list h2,.compact h2{margin:0 !important;}
  918. .section .post h3{font-size:1.5em;margin:1.0em auto 0 !important;}.list h3,.compact h3{margin:0 !important;}
  919. .section .post h4{font-size:1.1em;margin:0.5em auto 0 !important;}.list h4,.compact h4{margin:0 !important;}
  920. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  921. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  922. .left{display:none;}
  923. .center, .center_wide, .center_full{width:100%;padding:0;font-size:16px;line-height:1.3}
  924. hr{border:1px solid black;}
  925. .post_box_top{display:none;}
  926. .post_access{display:none;}
  927. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;background:unset;}
  928. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  929. .hidden_on_print{display:none !important;}
  930. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  931. .print_column .print_column{column-count:1;margin:unset;}
  932. .opt_compact{margin-left:0;left:1.5em;}
  933. .post .post_ref{padding-left:2rem;}
  934. .section .post h1:first-of-type{column-span:all;display:block;margin-top:1rem !important;margin-bottom:0.5rem !important;}
  935. .bkg_section .restart+.post .post_width{padding-top:0;}
  936. .restart{background-color:unset;padding:unset;}
  937. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  938. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  939. .header_nav{display:none;}
  940. .show_on_print{display:block;}.inline_print{display:inline;}
  941. blockquote{border-left:2px solid black;}
  942. .footer_additional{display:none;}
  943. .small_footer{margin-top:1rem;box-shadow:none;}
  944. .page{display:table;width:100%;}
  945. .page_selector{display:none;}
  946. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  947. .post .p_thumb img,.post .p_thumb video{max-height:4rem;}
  948. .sticky_title{box-shadow:none;}
  949. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  950. .center_wide .p_row{display:block;}
  951. .interesting_tbody{background:none;}
  952. .interesting_tbody img{display:none !important;}
  953. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  954. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  955. .center,.center>tbody,.center>tbody>tr,.center>tbody>tr>td{display:block;}
  956. .main>.center>tbody>tr{border:none;}
  957. .center>tbody>tr>td:first-child{display:none;color:rgba(0,0,0,0.5);}
  958. .center>tbody>tr>td:nth-child(2){display:none;color:rgba(0,0,0,0.5);}
  959. .center>tbody>tr>td:nth-child(2) a{display:none;color:rgba(0,0,0,0.5);}
  960. .center>tbody>tr>td:nth-child(3){margin:unset;padding:unset;}
  961. .post > td:nth-child(3) > *{margin:unset;padding:unset;}
  962. .wide_post_print{column-span:all;margin-top:1em;margin-bottom:1em;}
  963. }
  964. ";
  965. //$this->style=preg_replace('/%highlight_white%/','#5b3607',$this->style);
  966. //$this->style=preg_replace('/%highlight_slice%/','#734307',$this->style);
  967. //$this->style=preg_replace('/%grayslice%/','#442c0b',$this->style);
  968. //$this->style=preg_replace('/%post_white%/','#2d2110',$this->style);
  969. //$this->style=preg_replace('/%white%/','#231a0d',$this->style);
  970. //$this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  971. //$this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  972. //$this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  973. //$this->style=preg_replace('/%shadow%/','#000000cc',$this->style);
  974. $this->style=preg_replace('/%highlight_white%/','#804a06',$this->style);
  975. $this->style=preg_replace('/%highlight_slice%/','#ae6407',$this->style);
  976. $this->style=preg_replace('/%grayslice%/','#6a491c',$this->style);
  977. $this->style=preg_replace('/%post_white%/','#4a3413',$this->style);
  978. $this->style=preg_replace('/%white%/','#2d2214',$this->style);
  979. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  980. $this->style=preg_replace('/%gray%/','#f8ca9b88',$this->style);
  981. $this->style=preg_replace('/%graybkg%/','#a9270e',$this->style);
  982. $this->style=preg_replace('/%shadow%/','#000000ee',$this->style);
  983. $f = fopen('styles/main.css','w');
  984. fwrite($f,$this->style);
  985. fclose($f);
  986. }
  987. function GiveSafeEMail(){
  988. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  989. }
  990. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  991. if(isset($this->Images[0])) foreach($this->Images as &$im){
  992. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  993. else { if($im['name']==$name) return $im; }
  994. }
  995. return $this->NULL_IMAGE;
  996. }
  997. function &GiveImageInHere($rand=false){
  998. $this->ReadImages(); $this->DetectPageType();
  999. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  1000. if(!isset($album) || !$album){
  1001. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  1002. $imlist=[]; $imlist_fallback=[];
  1003. if(isset($this->Images[0])){
  1004. foreach($this->Images as &$im){
  1005. if(isset($im['galleries'][0]) && in_array($album,$im['galleries']) && $this->CanShowImage($im)){
  1006. if(!$rand) return $im; else {
  1007. $imlist_fallback[] = $im;
  1008. if(!in_array($im['name'],$this->VisitedHere)) $imlist[] = $im;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. if(!$rand || !isset($imlist_fallback[0])) return $this->NULL_IMAGE;
  1014. if(sizeof($imlist)){
  1015. $r = random_int(0, sizeof($imlist)-1);
  1016. return $imlist[$r];
  1017. }else{
  1018. $r = random_int(0, sizeof($imlist_fallback)-1);
  1019. return $imlist_fallback[$r];
  1020. }
  1021. }
  1022. function ImageTitle($im){
  1023. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  1024. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  1025. return $imtitle;
  1026. }
  1027. function ImageHasHere(&$im, $here_name){
  1028. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  1029. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  1030. }
  1031. function ReadImages($clear_non_exist = false){
  1032. $path = 'images/list.md';
  1033. if($this->DoneReadImages){ return; }
  1034. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  1035. $c = file_get_contents($path);
  1036. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  1037. $g=[]; $g['name']=$m[1];//$g['count']=0;
  1038. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  1039. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  1040. if(preg_match('/DESCRIPTION\s+([^;]+);/u', $m[2], $arg)){ $g['description']=$arg[1]; }
  1041. $this->Galleries[] = $g;
  1042. }
  1043. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  1044. $name = trim($m[1]);
  1045. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  1046. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  1047. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  1048. $item['refs']=[];
  1049. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  1050. }
  1051. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  1052. $item['galleries']=[];
  1053. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  1054. }
  1055. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  1056. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  1057. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  1058. if(preg_match('/ALIGN\s+([^;]*);/u',$m[2],$align)){ $item['align']=$align[1]; }
  1059. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  1060. $item['here']=[];
  1061. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  1062. }
  1063. if(preg_match('/\.mp4/u',$item['name'])){
  1064. $item['video']='video/mp4';
  1065. }
  1066. $this->Images[] = $item;
  1067. }
  1068. $files = array_merge([],glob('images/*.jpg'));
  1069. $files = array_merge($files,glob('images/*.jpeg'));
  1070. $files = array_merge($files,glob('images/*.png'));
  1071. $files = array_merge($files,glob('images/*.gif'));
  1072. $files = array_merge($files,glob('images/*.mp4'));
  1073. if(isset($files[0]))foreach($files as $file) {
  1074. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png|mp4)/u', $file, $m)) {
  1075. $name = trim($m[0]);
  1076. if(!$this->FindImage($name)){
  1077. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  1078. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  1079. $this->Images[] = $item;
  1080. }
  1081. }
  1082. }
  1083. if($clear_non_exist){
  1084. if(isset($this->Images[0]) && isset($files[0])){
  1085. foreach($this->Images as &$im){
  1086. if(!in_array($im['file'],$files)){
  1087. $im['deleted'] = 1;
  1088. }
  1089. }
  1090. }
  1091. }
  1092. function cmpf($a, $b){
  1093. if ($a['name'] == $b['name']) return 0;
  1094. return (($a['name'] > $b['name']) ? 1 : -1);
  1095. }
  1096. function cmpaf($a, $b){
  1097. if ($a['name'] == $b['name']) return 0;
  1098. return ($a['name'] > $b['name']) ? -1 : 1;
  1099. }
  1100. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  1101. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  1102. $this->DoneReadImages = 1;
  1103. }
  1104. function WriteImages(){
  1105. if(isset($this->WayBack)) return;
  1106. $path = 'images/list.md';
  1107. $f = fopen($path,'w');
  1108. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  1109. if(isset($g['deleted'])) continue;
  1110. fwrite($f,'GALLERY '.$g['name']);
  1111. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  1112. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  1113. if(isset($g['description']) && $g['description']!="") { fwrite($f,' DESCRIPTION '.$g['description'].';'); }
  1114. fwrite($f, PHP_EOL);
  1115. }
  1116. if(isset($this->Images[0]))foreach($this->Images as &$im){
  1117. if(isset($im['deleted'])) continue;
  1118. fwrite($f, "- ".$im['name'].'; ');
  1119. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  1120. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  1121. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  1122. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  1123. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  1124. if(isset($im['align']) && $im['align']!='' && $im['align']!='middle'){ fwrite($f, 'ALIGN '.$im['align']."; "); }
  1125. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  1126. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  1127. }
  1128. fwrite($f, PHP_EOL);
  1129. }
  1130. fflush($f);
  1131. fclose($f);
  1132. }
  1133. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL, $align=NULL){
  1134. if(!($im = &$this->FindImage($name))) return;
  1135. if(isset($link_gallery)){
  1136. if($do_remove){
  1137. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  1138. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  1139. $im['galleries'] = array_merge($im['galleries']);
  1140. }else{
  1141. if(!isset($im['galleries'])) $im['galleries']=[];
  1142. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  1143. $im['galleries'][]=$link_gallery;
  1144. }
  1145. }
  1146. if(isset($product_link)){
  1147. if($product_link!=''){$im['product']=$product_link;}
  1148. else{unset($im['product']);}
  1149. }
  1150. if(isset($rename) && $rename!=$im['name']){
  1151. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1152. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1153. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1154. $im['name'] = $rename.'.'.$ext;
  1155. }
  1156. if(isset($parent) && $parent!=$im['parent']){
  1157. if($parent==''){ unset($im['parent']); }
  1158. else{ $im['parent'] = $parent; }
  1159. }
  1160. if(isset($align) && in_array($align,['top','middle','bottom'])){
  1161. if($align=='middle'){ unset($im['align']); }
  1162. else{ $im['align']=$align; }
  1163. }
  1164. $this->NeedWriteImages = 1;
  1165. }
  1166. function RegenerateThumbnails(){
  1167. $glob = glob('images/*.jpg');
  1168. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1169. foreach($glob as $file) {
  1170. $thumb_destination = 'images/thumb/'.basename($file);
  1171. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1172. $width=$geo['width']; $height=$geo['height'];
  1173. $lim=400;
  1174. $scale = $lim / min($width,$height);
  1175. if($scale<1){
  1176. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1177. }
  1178. $img->setImageFormat('jpeg');
  1179. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1180. $img->setImageCompressionQuality(90);
  1181. $img->writeImage($thumb_destination);
  1182. }
  1183. }
  1184. function CleanupImageCompression($run=false){
  1185. $glob = glob('images/*.jpg');
  1186. if(!$run){
  1187. echo $this->T("将重新压缩下列文件:")."<style>img{max-width:10em;max-height:10em;}</style><ul>";
  1188. }
  1189. foreach($glob as $file) {
  1190. $destination = 'images/'.basename($file);
  1191. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1192. $width=$geo['width']; $height=$geo['height'];
  1193. $interlace=$img->getImageInterlaceScheme();
  1194. $progressive=($interlace==imagick::INTERLACE_NO || $interlace==imagick::INTERLACE_LINE || $interlace==imagick::INTERLACE_UNDEFINED);
  1195. $sizelim=1920;$abs_max=2560;
  1196. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1197. $sz=filesize($destination);
  1198. if($scale<0.98 && $sz>2097152 && $progressive){ /* need scale, greater than 2mb, and not interlaced */
  1199. if(!$run){
  1200. echo "<li><a href='index.php?pic=$destination'><img src='images/thumb/".basename($file)."'><br />$destination, $width x $height, $interlace</a></li>";
  1201. }else{
  1202. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1203. $img->setImageFormat('jpeg');
  1204. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1205. $img->setImageCompressionQuality(90);
  1206. $img->writeImage($destination);
  1207. }
  1208. }
  1209. $img->clear();
  1210. }
  1211. if(!$run){
  1212. echo "</ul><a href='index.php?cleanup_image_compression=true&run=true'>".$this->T("立即执行")."</a>"; exit;
  1213. }
  1214. }
  1215. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max, $ext) {
  1216. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1217. $width=$geo['width']; $height=$geo['height'];
  1218. $lim=400;
  1219. $scale = $lim / min($width,$height);
  1220. if($scale<1){
  1221. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1222. }
  1223. $img->setImageFormat('jpeg');
  1224. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1225. $img->setImageCompressionQuality($quality);
  1226. $img->writeImage($thumb_destination);
  1227. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1228. if($scale<0.98 || ($ext!='jpg'&&$ext!='jpeg')){
  1229. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1230. $img2->setImageFormat('jpeg');
  1231. $img2->setImageCompressionQuality($quality);
  1232. $img2->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1233. $img2->writeImage($destination);
  1234. }else{
  1235. rename($source,$destination);
  1236. }
  1237. }
  1238. function DoUpload(){
  1239. if(!isset($_FILES['upload_file_name'])) return 0;
  1240. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1241. if($_FILES['upload_file_name']['error']>0){
  1242. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1243. return -1;
  1244. }else{
  1245. $ext=strtolower(pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION));
  1246. if(!in_array($ext,['jpg','jpeg','png','gif','mp4'])) return 0;
  1247. $fp = fopen('.la_lock',"w");
  1248. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1249. usleep(10000);
  1250. }
  1251. $num=date('YmdHis'); $replace=0;
  1252. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1253. $num = $mim[1]; $replace=1;
  1254. }
  1255. $base = 'images/'.$num;
  1256. $thumb = 'images/thumb/'.$num;
  1257. $use_ext=($ext=='gif' || $ext=='mp4')?('.'.$ext):('.jpg');
  1258. $final_path = $base.$use_ext; $final_thumb = $thumb.$use_ext; $i=0;
  1259. if(!$replace) while(file_exists($final_path)){
  1260. $final_path = $base.strval($i).$use_ext; $final_thumb = $thumb.strval($i).$use_ext; $i++;
  1261. }
  1262. if($ext!='gif' && $ext!='mp4'){
  1263. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1264. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1265. $compress?800:1920, $compress?1920:2560, $ext);
  1266. }else{
  1267. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1268. }
  1269. flock($fp, LOCK_UN);
  1270. fclose($fp);
  1271. $this->ReadImages(true);
  1272. $this->WriteImages();
  1273. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1274. if(isset($_POST['image_replace_button'])){
  1275. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1276. }
  1277. exit;
  1278. return 1;
  1279. }
  1280. return 0;
  1281. }
  1282. function &GetGallery($name){
  1283. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1284. if($g['name'] == $name) return $g;
  1285. }
  1286. return $this->NULL_GALLERY;
  1287. }
  1288. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null,$desc=null){
  1289. $this->ReadImages();
  1290. $gallery = &$this->GetGallery($name);
  1291. if(!isset($gallery)){
  1292. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1293. $g = []; $g['name']=$new_name;
  1294. $this->Galleries[]=$g;
  1295. }else{
  1296. if(isset($new_name)) {
  1297. if(preg_match('/main|trash|\s/u',$new_name))return;
  1298. $gallery['name'] = $new_name;
  1299. foreach ($this->Images as &$im){
  1300. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1301. if($g == $name){ $g = $new_name; }
  1302. }
  1303. }
  1304. }
  1305. //if(isset($count)) $gallery['count'] = $count;
  1306. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1307. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1308. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1309. if(isset($desc)) $gallery['description'] = $desc;
  1310. }
  1311. if($do_rw) { $this->NeedWriteImages = 1; }
  1312. }
  1313. function ClearData(){
  1314. $this->Posts = [];
  1315. $this->Threads = [];
  1316. $this->Images = [];
  1317. $this->Archive = [];
  1318. $this->ArchiveHandles = [];
  1319. }
  1320. function InsertArchivePost(&$post){
  1321. $a = NULL;
  1322. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1323. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1324. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1325. }
  1326. $a['list'][] = $post;
  1327. $this->Archive[] = $post;
  1328. }
  1329. function ReadArchiveFromFile($path){
  1330. if(!file_exists($path)){
  1331. return;
  1332. }
  1333. $c = file_get_contents($path);
  1334. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1335. foreach($matches as $m){
  1336. $post = [];
  1337. $post['id'] = $m[1];
  1338. $post['content'] = trim($m[3]);
  1339. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1340. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1341. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1342. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1343. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1344. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1345. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1346. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1347. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1348. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1349. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1350. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1351. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1352. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1353. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1354. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1355. }
  1356. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1357. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1358. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1359. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1360. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1361. }
  1362. $this->InsertArchivePost($post);
  1363. }
  1364. }
  1365. }
  1366. function SortArchive(){
  1367. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1368. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1369. return (($a['id'] > $b['id']) ? 1 : -1);
  1370. };
  1371. if(isset($this->Archive[0])){
  1372. usort($this->Archive,$cmpap);
  1373. $year_begin = substr($this->Archive[0]['id'],0,4);
  1374. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1375. }
  1376. if(isset($this->ArchiveHandles[0])){
  1377. usort($this->ArchiveHandles,$cmpac);
  1378. foreach($this->ArchiveHandles as &$a){
  1379. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1380. $last_valid=NULL;
  1381. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1382. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1383. else{ $last_valid = $ver['content']; } }
  1384. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1385. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1386. }
  1387. }
  1388. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1389. $p['archive'] = &$a;
  1390. }
  1391. }
  1392. }
  1393. }
  1394. function ReadPostsFromFile($path){
  1395. if(!file_exists($path)){
  1396. $f = fopen($path,'w');
  1397. fclose($f);
  1398. }
  1399. $c = file_get_contents($path);
  1400. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1401. foreach($matches as $m){
  1402. $post = [];
  1403. $post['id'] = $m[1];
  1404. $post['real_content'] = trim($m[3]);
  1405. $post['content'] = &$post['real_content'];
  1406. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1407. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1408. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1409. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1410. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1411. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1412. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1413. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1414. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1415. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1416. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1417. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1418. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1419. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1420. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1421. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1422. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1423. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1424. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1425. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1426. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1427. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1428. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1429. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1430. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1431. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1432. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1433. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1434. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1435. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1436. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1437. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1438. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1439. }
  1440. if(preg_match('/NUM\s+([0-9]{1,})\s*;/u', $m[2], $n)){ $post['number']=$n[1]; $this->PNUMBER=max($post['number'],$this->PNUMBER); }
  1441. else{ $this->PNUMBER++; $post['number']=$this->PNUMBER; }
  1442. //$this->PNUMBER++; $post['number']=$this->PNUMBER;
  1443. if(isset($post['mark_value']) && $post['mark_value']==5){
  1444. $post['product']=[];
  1445. }
  1446. /* marks add here */
  1447. $this->Posts[] = $post;
  1448. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1449. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1450. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1451. }
  1452. }
  1453. }
  1454. }
  1455. function SortPosts($wayback=false){
  1456. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1457. $sortlist = &$this->Posts;
  1458. if($wayback) $sortlist = &$this->WaybackPosts;
  1459. if(isset($sortlist[0])){
  1460. usort($sortlist,$cmpp);
  1461. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1462. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1463. }
  1464. }
  1465. function ReadPosts(){
  1466. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1467. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1468. (!is_dir('posts') || is_readable('posts') == false) ||
  1469. (!is_dir('archive') || is_readable('archive') == false) ||
  1470. (!is_dir('images') || is_readable('images') == false) ||
  1471. (!is_dir('styles') || is_readable('styles') == false)){
  1472. $this->Install();
  1473. }
  1474. if($this->DoneReadPosts){ return; }
  1475. $file_list = [];
  1476. $glob = glob('posts/*');
  1477. foreach($glob as $file) {
  1478. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1479. $file_list[] = $file;
  1480. }
  1481. }
  1482. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1483. foreach($file_list as $f) {
  1484. $this->ReadPostsFromFile($f);
  1485. }
  1486. $this->SortPosts();
  1487. $this->DetectThreads();
  1488. $this->DoneReadPosts=1;
  1489. }
  1490. function UpdatePostRefsForWayback(){
  1491. if(!isset($this->WayBack)) return;
  1492. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1493. if(!isset($this->WaybackPosts[0])) return;
  1494. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1495. foreach($this->WaybackPosts as &$p){
  1496. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1497. $pr = &$this->GetPost($r); if(isset($pr)){
  1498. if(!isset($pr['refs'])) $pr['refs']=[];
  1499. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1500. }
  1501. }
  1502. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1503. $ir = &$this->FindImage($r); if(isset($ir)){
  1504. if(!isset($ir['refs'])) $ir['refs']=[];
  1505. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1506. }
  1507. }
  1508. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1509. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1510. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1511. }
  1512. }
  1513. }
  1514. function ReadArchive(){
  1515. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1516. if ($this->DoneReadArchive) return;
  1517. $file_list = []; $glob = glob('archive/*');
  1518. foreach($glob as $file) {
  1519. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1520. $file_list[] = $file;
  1521. }
  1522. }
  1523. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1524. foreach($file_list as $f) {
  1525. $this->ReadArchiveFromFile($f);
  1526. }
  1527. $this->SortArchive();
  1528. $this->DoneReadArchive=1;
  1529. $this->UpdateThreadForWayback();
  1530. $this->UpdatePostRefsForWayback();
  1531. }
  1532. function GetThreadForPost(&$post){
  1533. if(isset($post['tid'])) return;
  1534. $th = []; $iterp = NULL;
  1535. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1536. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1537. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1538. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1539. $np['tid'] = &$th;
  1540. $th['first'] = &$np;
  1541. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1542. }
  1543. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1544. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1545. $np['tid'] = &$th;
  1546. $th['last'] = &$np;
  1547. $iterp = isset($np['next'])?$np['next']:NULL;
  1548. }
  1549. if(isset($th['first']['mark_value'])){
  1550. if($th['first']['mark_value']==6) $th['exp'] = true;
  1551. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1552. }
  1553. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1554. $this->Threads[] = &$th;
  1555. }
  1556. function IdentifyThreadCategory(&$th,&$first_post){
  1557. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1558. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1559. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1560. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1561. }
  1562. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1563. }
  1564. if(preg_match('/\{\s*WIDE\s*\}/imu',$first_post['content'],$m)){ $first_post['wide'] = true; }
  1565. if(preg_match('/\{\s*NO_TIME\s*\}/imu',$first_post['content'],$m)){ $first_post['no_time'] = true; }
  1566. if(preg_match('/\{\s*NO_TITLE\s*\}/imu',$first_post['content'],$m)){ $first_post['no_title'] = true; }
  1567. if(preg_match('/\{\s*SLIDES\s*\}/imu',$first_post['content'],$m)){ $first_post['slides'] = true; }
  1568. if(preg_match('/\{\s*HEADER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['header'] = trim($m[1]); }
  1569. if(preg_match('/\{\s*FOOTER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['footer'] = trim($m[1]); }
  1570. if(!isset($th)) return;
  1571. if(isset($first_post['wide'])) $th['wide']=$first_post['wide'];
  1572. if(isset($first_post['header'])) $th['header']=$first_post['header'];
  1573. if(isset($first_post['footer'])) $th['footer']=$first_post['footer'];
  1574. if(isset($first_post['no_time'])) $th['no_time']=$first_post['no_time'];
  1575. if(isset($first_post['slides'])) $th['slides']=$first_post['slides'];
  1576. if(isset($first_post['no_title'])) $th['no_title']=$first_post['no_title'];
  1577. if(preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1578. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1579. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1580. }
  1581. }
  1582. if(preg_match('/\{\s*REVERSED(\s+.*?)?\}/imu',$first_post['content'],$m)){ $th['reversed'] = 'm';
  1583. if(isset($m[1])&&preg_match('/^\s*(y|m|d|p)/iu',$m[1],$ma)){ $th['reversed']=$ma[1]; }
  1584. }
  1585. }
  1586. function IsInterestingPost(&$p){
  1587. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1588. return false;
  1589. }
  1590. function IsReversedThread(&$th){
  1591. if(isset($th['reversed']) && $th['reversed']!=false) return true;
  1592. return false;
  1593. }
  1594. function GiveAllMergedPosts(&$po,&$arr){
  1595. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1596. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1597. }
  1598. if(isset($po['archive']) && isset($po['archive']['list'])){
  1599. foreach($po['archive']['list'] as &$ver){
  1600. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1601. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1602. }
  1603. }
  1604. }
  1605. function ThreadMakeWayback(&$th){
  1606. if(!isset($th['arr'][0])) return;
  1607. if(isset($this->WayBack)){
  1608. $remlist = [];
  1609. foreach($th['arr'] as &$pi){
  1610. $po = &$this->GetPost($pi['id'],true); if(!isset($po)){continue;/*merged*/}
  1611. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1612. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1613. }
  1614. $ah = &$this->GetArchiveHandle($po['id']);
  1615. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1616. if(!isset($ver['merged_thread'])) continue;
  1617. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1618. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1619. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1620. }
  1621. }
  1622. }
  1623. if(isset($remlist[0]) && isset($th['arr'][0])){
  1624. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1625. foreach($th['arr'] as $key => $pr){
  1626. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1627. $new_th = []; $new_arr = [];
  1628. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1629. $new_th['arr'] = &$new_arr;
  1630. $this->WaybackThreads[] = &$new_th;
  1631. $this->ThreadMakeWayback($new_th);
  1632. }
  1633. }
  1634. }
  1635. function AddMergedPosts(&$p, &$array){
  1636. if(isset($p['archive']) && isset($p['archive']['list'])){
  1637. foreach($p['archive']['list'] as &$ver){
  1638. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1639. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1640. }
  1641. }
  1642. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1643. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1644. }
  1645. function &array_shift_ref(&$array){if(count($array)>0){$key=key($array);$first=&$array[$key];}else{$first=null;}array_shift($array);return $first;}
  1646. function FinalizeThread(&$th, $relink_posts=false, $now=0){
  1647. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1648. if(!isset($th['arr'])){
  1649. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1650. $arr[]=&$p;
  1651. } $th['arr'] = &$arr;
  1652. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1653. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1654. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1655. $arr=&$new_arr; $th['arr']=&$new_arr;
  1656. $this->ThreadMakeWayback($th); }
  1657. }
  1658. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1659. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1660. if($relink_posts){ $count = $th['count'];
  1661. $arr = &$th['arr'];
  1662. for($i=0; $i<$count; $i++){ if($i>0) $arr[$i]['prev'] = $arr[$i-1]['id']; if($i<$count-1) $arr[$i]['next'] = $arr[$i+1]['id'];
  1663. $arr[$i]['tid']=&$th;}
  1664. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1665. }
  1666. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1667. $this->IdentifyThreadCategory($th, $th['first']);
  1668. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1669. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1670. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1671. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1672. if(isset($th['reversed'])){ $chunks=[]; $last_id=$last_y=$last_m=$last_d=0; $mo=$th['reversed']; $final=[];
  1673. $first_post=&$this->array_shift_ref($th['arr']); $ch=[];
  1674. while($n=&$this->array_shift_ref($th['arr'])){
  1675. $this_id=$n['id']; $this_y=substr($this_id,0,4); $this_m=substr($this_id,4,2); $this_d=substr($this_id,6,2);
  1676. if($mo=='y'&&$this_y!=$last_y){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y; }
  1677. if($mo=='m'&&$this_m!=$last_m){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m; }
  1678. if($mo=='d'&&$this_d!=$last_d){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m.'/'.$this_d; }
  1679. if($mo=='p'){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} }
  1680. $ch[]=&$n; $last_id=$this_id; $last_y=$this_y; $last_m=$this_m; $last_d=$this_d;
  1681. }if(isset($ch[0])){$chunks[]=$ch;} if(isset($chunks[0])){$use_chunks=array_reverse($chunks);}
  1682. $final[]=&$first_post;
  1683. foreach($use_chunks as &$ch){ foreach($ch as &$p){ $final[]=&$p;} }
  1684. $th['arr']=$final; }
  1685. }
  1686. function SortThreads(){
  1687. if (!function_exists('cmpt')) {
  1688. function cmpt($a, $b){
  1689. if ($a['score'] == $b['score']) return 0;
  1690. return ($a['score'] > $b['score']) ? -1 : 1;
  1691. }
  1692. }
  1693. usort($this->Threads,"cmpt");
  1694. }
  1695. function DetectThreads(){
  1696. foreach($this->Posts as &$p){
  1697. if(isset($p['tid'])) { continue; }
  1698. $this->GetThreadForPost($p);
  1699. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1700. }
  1701. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1702. $now = date_timestamp_get(date_create());
  1703. foreach($this->Threads as &$t){
  1704. $this->FinalizeThread($t,false,$now);
  1705. }
  1706. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1707. $this->FinalizeThread($th,false,$now);
  1708. $this->Threads[] = &$th;
  1709. }
  1710. $this->SortThreads();
  1711. }
  1712. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1713. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1714. foreach($this->Threads as &$t){
  1715. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1716. }
  1717. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1718. $this->FinalizeThread($th,true,$now);
  1719. $this->Threads[] = &$th;
  1720. }
  1721. $this->SortThreads();
  1722. $this->SortPosts(true);
  1723. $this->UsePosts = &$this->WaybackPosts;
  1724. }
  1725. function &GetMergedPost($id){
  1726. $this->ReadArchive();
  1727. $ah = &$this->GetArchiveHandle($id);
  1728. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1729. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1730. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1731. [$tp, $tver] = $ver['merged_into'];
  1732. if(isset($this->WayBack)){
  1733. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1734. else return $this->GetPost($id); /* should not happen directly. */
  1735. }
  1736. return $this->GetMergedPost($tp);
  1737. }
  1738. function &GetPost($id, $latest_only=false, $find_merged=false){
  1739. if(!isset($id)) return $this->NULL_POST;
  1740. $found=&$this->NULL_POST;
  1741. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1742. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1743. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1744. }
  1745. if($latest_only || !isset($this->WayBack)){ return $found; }
  1746. else{
  1747. if(isset($found)){
  1748. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1749. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1750. $last_ver = &$this->NULL_POST;
  1751. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1752. if($ver['version'] > $this->WayBack) return $last_ver;
  1753. $last_ver = &$ver;
  1754. }
  1755. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1756. else return $last_ver;
  1757. }else{
  1758. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1759. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1760. if($ver['version'] > $this->WayBack) return $last_ver;
  1761. $last_ver = &$ver;
  1762. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1763. [$tp, $tver] = $last_ver['merged_into'];
  1764. if($tver <= $this->WayBack) {
  1765. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1766. return $last_ver;
  1767. }
  1768. }
  1769. }
  1770. return $this->NULL_POST;
  1771. }
  1772. function &GetArchiveHandle($id){
  1773. if(!isset($id)) return $this->NULL_POST;
  1774. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1775. if($p && $p['id'] == $id) { return $p; }
  1776. }
  1777. return $this->NULL_POST;
  1778. }
  1779. function &GetArchive($id){
  1780. if(!isset($id)) return $this->NULL_POST;
  1781. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1782. if($p && $p['id'] == $id) { return $p; }
  1783. }
  1784. return $this->NULL_POST;
  1785. }
  1786. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1787. if(!isset($ah)) return $this->NULL_POST;
  1788. $found = NULL; $last_verp=NULL;
  1789. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1790. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1791. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1792. $last_verp = &$p;
  1793. }
  1794. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1795. return $this->NULL_POST;
  1796. }
  1797. function CacheArchiveOwnLinks(){
  1798. if(isset($this->WayBack)) return;
  1799. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1800. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1801. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1802. foreach($matches as $m){
  1803. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1804. }
  1805. }
  1806. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1807. foreach($matches as $m){
  1808. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1809. }
  1810. }
  1811. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1812. foreach($matches as $m){
  1813. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. function WriteArchive(){
  1819. if(isset($this->WayBack)) return;
  1820. $cf = NULL;$opened =NULL;
  1821. $this->SortArchive();
  1822. $this->CacheArchiveOwnLinks();
  1823. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1824. $nid = substr($p['id'], 0,6);
  1825. if($cf != $nid){
  1826. if($opened){
  1827. fflush($opened);
  1828. fclose($opened);
  1829. }
  1830. $cf = $nid;
  1831. $opened = fopen("archive/$cf.md", 'w');
  1832. }
  1833. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1834. "VER {$p['version']}; ".
  1835. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1836. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1837. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1838. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1839. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1840. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1841. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1842. ']';
  1843. if(isset($p['merged_thread'])){ $p['content']=""; }
  1844. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1845. }
  1846. }
  1847. function WritePosts(){
  1848. if(isset($this->WayBack)) return;
  1849. $cf = NULL;$opened =NULL;
  1850. $this->SortPosts();
  1851. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1852. $nid = substr($p['id'], 0,6);
  1853. if($cf != $nid){
  1854. if($opened){
  1855. fflush($opened);
  1856. fclose($opened);
  1857. }
  1858. $cf = $nid;
  1859. $opened = fopen("posts/$cf.md", 'w');
  1860. }
  1861. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1862. ((isset($p['number']) && $p['number'])?"NUM {$p['number']}; ":"").
  1863. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1864. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1865. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1866. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1867. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1868. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1869. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1870. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1871. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1872. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1873. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1874. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1875. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1876. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1877. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1878. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1879. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1880. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1881. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1882. ']';
  1883. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1884. }
  1885. }
  1886. function CachePostLinks(){
  1887. if(isset($this->WayBack)) return;
  1888. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1889. $this->ConvertPost($post);
  1890. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1891. //discard lost old version
  1892. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1893. }else return;
  1894. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1895. unset($im['refs']); unset($im['here']); unset($im['title']);
  1896. }
  1897. foreach ($this->Posts as &$post){
  1898. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1899. foreach($matches as $m){
  1900. $ref = &$this->GetPost($m[1],true);
  1901. if($ref!=NULL){
  1902. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1903. }
  1904. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1905. }
  1906. }
  1907. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1908. foreach($matches as $m){
  1909. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1910. }
  1911. }
  1912. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1913. foreach($matches as $m){
  1914. if(($im = &$this->FindImage($m[2]))!=NULL){
  1915. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1916. }
  1917. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1918. }
  1919. }
  1920. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\))(\R*(\R(-|\*).+){1,})/u",
  1921. $post['content'],$matches)){
  1922. $use_img_name = $matches[2];
  1923. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1924. if(preg_match_all("/(-|\*)\s+here\s*:\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s+images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))/u",
  1925. $matches[4],$mah,PREG_SET_ORDER)){
  1926. foreach($mah as $ma){
  1927. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1928. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. }foreach($this->Posts as &$post){
  1934. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1935. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1936. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1937. }
  1938. }
  1939. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1940. $min_id = '99999999999999';
  1941. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1942. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1943. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1944. }
  1945. }
  1946. }
  1947. function CreatePostAnchor(&$post){
  1948. $that=&$this;
  1949. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1950. $id = '_heading_'.sizeof($this->Anchors);
  1951. $entry=[(int)$ma[1], $id, $ma[2]];
  1952. $that->Anchors[] = $entry;
  1953. return "<h{$ma[1]} id='{$id}'>{$ma[2]}";
  1954. }, $post['html']);
  1955. }
  1956. function RenamePost(&$post, $rename){
  1957. foreach($this->Posts as &$p){
  1958. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1959. }
  1960. foreach($this->Posts as &$p){
  1961. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1962. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1963. }
  1964. $post['id'] = $rename;
  1965. }
  1966. function DetachPost(&$th,&$post){
  1967. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1968. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1969. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1970. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1971. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1972. unset($th['arr']); $now = date_timestamp_get(date_create());
  1973. $this->FinalizeThread($th, true, $now);
  1974. }
  1975. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1976. $a = &$this->GetArchiveHandle($post['id']);
  1977. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1978. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1979. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1980. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1981. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1982. $post['version'] = $optime_id;
  1983. if($mode==1){
  1984. $this->InsertArchivePost($ap);
  1985. }else if($mode==2){
  1986. $post['merged_from'] = $info;
  1987. $this->InsertArchivePost($ap);
  1988. }else if($mode==3){
  1989. $ap['merged_into'] = $info;
  1990. $this->InsertArchivePost($ap);
  1991. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1992. $this->DetachPost($post['tid'], $post);
  1993. }
  1994. }else if($mode==4){
  1995. $post['merged_thread'] = $info;
  1996. $this->InsertArchivePost($ap);
  1997. }
  1998. }
  1999. function &MergeThreads($post_id, $post_into_id){
  2000. $this->ReadPosts();
  2001. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  2002. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  2003. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  2004. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  2005. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  2006. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  2007. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  2008. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  2009. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  2010. $arr_combined = array_merge($tt['arr'],$th['arr']);
  2011. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  2012. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  2013. $tt['count'] = sizeof($tt['arr']);
  2014. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  2015. $first_post = &$this->NULL_POST;
  2016. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  2017. $this->NeedWritePosts=1;
  2018. $this->NeedWriteArchive=1;
  2019. return $first_post;
  2020. }
  2021. function &MergePosts($ids_string){
  2022. $ids = explode(" ", $ids_string);
  2023. $combined_content = ""; $first_id=NULL;
  2024. $this->ReadPosts(); $child_list=[];
  2025. foreach($ids as $id){
  2026. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  2027. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  2028. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  2029. }
  2030. if(!isset($child_list[0])) return $this->NULL_POST;
  2031. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  2032. foreach($child_list as $id){
  2033. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  2034. }
  2035. $this->NeedWritePosts=1;
  2036. $this->NeedWriteArchive=1;
  2037. return $first_post;
  2038. }
  2039. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  2040. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  2041. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  2042. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  2043. $this->ReadImages();
  2044. $this->ReadPosts();
  2045. if(isset($push_version) && $push_version){
  2046. $this->ReadArchive();
  2047. }
  2048. $p_success = NULL;
  2049. if(isset($id_if_edit)){
  2050. $post = &$this->GetPost($id_if_edit,true);
  2051. if($post===$this->NULL_POST) return $this->NULL_POST;
  2052. if($get_original_only){
  2053. return $post['real_content'];
  2054. }
  2055. if(isset($push_version) && $push_version){
  2056. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  2057. }
  2058. if(isset($content)) {$post['real_content'] = $content; $post['content'] = &$post['real_content'];}
  2059. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  2060. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  2061. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  2062. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  2063. $p_success = &$post;
  2064. }else{
  2065. if(!isset($content)) return $this->NULL_POST;
  2066. $id = date('YmdHis');
  2067. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  2068. $post = []; $post['id'] = $id;
  2069. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  2070. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  2071. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  2072. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  2073. }
  2074. $this->Posts[] = $post;
  2075. $p_success = &$this->Posts[count($this->Posts) - 1];
  2076. }
  2077. $this->NeedWritePosts=1;
  2078. $this->NeedWriteImages=1;
  2079. if(isset($push_version) && $push_version){
  2080. $this->NeedWriteArchive=1;
  2081. }
  2082. return $p_success;
  2083. }
  2084. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  2085. $this->ReadPosts();
  2086. $p_success = NULL;
  2087. if(isset($id_if_edit)){
  2088. $post = &$this->GetPost($id_if_edit,true);
  2089. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  2090. if(isset($content)) $post['content'] = $content;
  2091. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  2092. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  2093. if(isset($ip)) $post['ip'] = $ip;
  2094. $p_success = &$post;
  2095. }else{
  2096. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  2097. $id = date('YmdHis');
  2098. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  2099. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  2100. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  2101. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  2102. if(isset($ip)) $post['ip'] = $ip;
  2103. $this->Posts[] = $post;
  2104. $p_success = &$this->Posts[count($this->Posts) - 1];
  2105. }
  2106. $this->NeedWritePosts=1;
  2107. return $p_success;
  2108. }
  2109. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  2110. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  2111. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  2112. function($matches){
  2113. $rep = preg_replace('/->/','-@>',$matches[0]);
  2114. $rep = preg_replace('/=>/','=@>',$rep);
  2115. $rep = preg_replace('/<=/','<@=',$rep);
  2116. $rep = preg_replace('/<-/','<@-',$rep);
  2117. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  2118. $rep = preg_replace('/\[-/','[@-',$rep);
  2119. $rep = preg_replace('/\{/','{@',$rep);
  2120. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  2121. return $rep;
  2122. },
  2123. $replacement);
  2124. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  2125. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  2126. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  2127. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  2128. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  2129. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  2130. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  2131. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  2132. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  2133. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  2134. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  2135. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  2136. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  2137. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  2138. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  2139. function($matches){
  2140. $rep = preg_replace('/-@>/','->',$matches[0]);
  2141. $rep = preg_replace('/<@-/','<-',$rep);
  2142. $rep = preg_replace('/=@>/','=>',$rep);
  2143. $rep = preg_replace('/<@=/','<=',$rep);
  2144. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  2145. $rep = preg_replace('/\[@-/','[-',$rep);
  2146. $rep = preg_replace('/\{@/','{',$rep);
  2147. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  2148. return $rep;
  2149. }, $replacement);
  2150. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  2151. function($matches) use (&$post_for_it_is_here){
  2152. $rep = preg_replace("/(-|\*)\s+here\s*:\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s+images\/([0-9]{14,}\.(jpg|jpeg|png|gif))/u","", $matches[4]);
  2153. return $matches[1].$rep;
  2154. }, $replacement);
  2155. return $replacement;
  2156. }
  2157. function CanShowPost(&$p){
  2158. if(!isset($p) || isset($p['comment_to'])) return false;
  2159. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  2160. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  2161. if($is_mark_slf && !$this->LoggedIn){ return false; }
  2162. if(isset($this->WayBack)){
  2163. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  2164. else if ($p['id']>$this->WayBack) return false;
  2165. }
  2166. if(!$this->InExperimentalMode){
  2167. if(!$this->LoggedIn){
  2168. if($is_mark_exp) return false;
  2169. return true;
  2170. }
  2171. return true;
  2172. }else{
  2173. if($is_mark_exp) return true;
  2174. return false;
  2175. }
  2176. }
  2177. function SkipProduct(&$p){
  2178. if($this->LoggedIn) return false;
  2179. return (isset($p['mark_value']) && $p['mark_value']==5);
  2180. }
  2181. function GetRedirect($args=NULL, $force_index=NULL){ global $INDEXPHP;
  2182. $str = (isset($force_index)?$force_index:$INDEXPHP).'?';
  2183. if(isset($args['post'])) $str.='&post='.$args['post'];
  2184. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  2185. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  2186. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  2187. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  2188. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  2189. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  2190. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  2191. if(isset($args['statistics'])) $str.='&statistics='.$args['statistics'];
  2192. else if(isset($_GET['statistics'])) $str.='&statistics='.$_GET['statistics'];
  2193. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  2194. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  2195. if(isset($args['category'])) $str.='&category='.$args['category'];
  2196. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  2197. if(isset($args['history'])) $str.='&history='.$args['history'];
  2198. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  2199. if(isset($args['version'])) $str.='&version='.$args['version'];
  2200. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  2201. if(isset($args['search'])) $str.='&search='.$args['search'];
  2202. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  2203. if(isset($args['here'])) $str.='&here='.$args['here'];
  2204. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  2205. return $str;
  2206. }
  2207. function WriteAsNecessary(){
  2208. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  2209. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  2210. if($this->NeedWriteImages){ $this->WriteImages(); }
  2211. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  2212. }
  2213. function APubEnsureWebfinger($name, $host){
  2214. if(!is_dir('.well-known')) mkdir('.well-known');
  2215. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  2216. $f = fopen('.well-known/webfinger/index.php',"w");
  2217. $without_protocol = parse_url($host, PHP_URL_HOST);
  2218. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  2219. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  2220. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  2221. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2222. $res = openssl_pkey_new();
  2223. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2224. openssl_pkey_export($res, $this->APubPrivateKey);
  2225. $f = fopen('.well-known/apub_public_key.pem',"w");
  2226. fwrite($f, $this->APubPublicKey); fclose($f);
  2227. $f = fopen('.well-known/apub_private_key.php',"w");
  2228. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2229. }
  2230. }
  2231. function APubInit(){
  2232. $kf = file_get_contents('.well-known/apub_private_key.php'); if($kf===false) return;
  2233. preg_match("/(-----BEGIN PRIVATE KEY-----[\s\S]*)/",$kf,$ma); $this->APubPrivateKey=$ma[1];
  2234. }
  2235. function APubEnsureInfo(){
  2236. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2237. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2238. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2239. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2240. "id"=> $this->HostURL."?apub_actor=1",
  2241. "type"=> "Person",
  2242. "name"=> $this->DisplayName,
  2243. "url"=> $this->HostURL,
  2244. "summary"=> "Lazy... No summary",
  2245. "preferredUsername"=> $this->APubID,
  2246. "inbox"=> $this->HostURL."?apub_inbox=1",
  2247. "outbox"=> $this->HostURL."?apub_outbox=1",
  2248. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2249. "owner"=> $this->HostURL."?apub_actor=1",
  2250. "publicKeyPem"=>$pk]];
  2251. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2252. }
  2253. function APubMakeOutbox(){
  2254. $this->ReadPosts();$this->ReadImages();
  2255. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2256. "id"=>$this->HostURL."?apub_outbox=1",
  2257. "type"=>"OrderedCollection"];
  2258. $items=[]; $i=0;
  2259. foreach(array_reverse($this->Posts) as &$p){
  2260. $this->ConvertPost($p);
  2261. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2262. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2263. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2264. "type"=> "Create",
  2265. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2266. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2267. //"to"=> ["https://chatty.example/ben/"],
  2268. "actor"=> $this->HostURL."?apub_actor=1",
  2269. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2270. "object"=> ["type"=> "Note",
  2271. "id"=> $this->HostURL."?post=".$p['id'],
  2272. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2273. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2274. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2275. "content"=> $text]];
  2276. $items[] = $ob;
  2277. $i++; if($i>20) break;
  2278. }
  2279. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2280. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2281. }
  2282. function APubDeliver($body,$target){
  2283. $head_digest = base64_encode(hash("sha256",$body,true));
  2284. $body_digest = "SHA-256=".$head_digest;
  2285. // rfc standards require the timezone be declared as GMT and PHP's built-in formats all say UTC
  2286. // so we gotta do it manually
  2287. $d = new DateTimeImmutable("now", new DateTimeZone('Asia/Shanghai'));
  2288. $d=$d->setTimezone(new DateTimeZone('UTC'));
  2289. $date=$d->format("D, d M Y H:i:s")." GMT";
  2290. $data = "(request-target): post ".parse_url($target,PHP_URL_PATH)
  2291. ."\nhost: ".parse_url($target,PHP_URL_HOST)
  2292. ."\ndate: $date"
  2293. ."\ndigest: $body_digest";
  2294. if (openssl_sign($data, $signature, $this->APubPrivateKey, OPENSSL_ALGO_SHA256) === FALSE) {
  2295. http_response_code(500); die('unable to sign');
  2296. }
  2297. $signature = base64_encode($signature);
  2298. $keyid = 'keyId="'.$this->HostURL.'?apub_actor=1#main-key"';
  2299. $algo = 'algorithm="rsa-sha256"';
  2300. $headers = 'headers="(request-target) host date digest"';
  2301. $signature = "signature=\"$signature\"";
  2302. $h = array(
  2303. 'Content-Type: application/activity+json',
  2304. 'Accept: application/activity+json',
  2305. //"Content-Length: ".strlen($body),
  2306. "Host: ". parse_url($target,PHP_URL_HOST),
  2307. "Date: $date",
  2308. "Digest: $body_digest",
  2309. "Signature: $keyid,$algo,$headers,$signature"
  2310. );
  2311. $ch = curl_init($target);
  2312. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2313. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
  2314. curl_setopt($ch, CURLOPT_HTTPHEADER, $h);
  2315. curl_setopt($ch, CURLOPT_USERAGENT, "laMDWiki APub");
  2316. $result = curl_exec($ch);
  2317. curl_close($ch); echo "<pre>";
  2318. print_r($body); echo "\n\n".$target."\n\n";
  2319. print_r($result); echo "\n\n"; print_r($h);
  2320. echo "\n\n"; print_r(curl_getinfo($ch)); echo "</pre>"; exit;
  2321. return $result;
  2322. }
  2323. function APubTestDeliver(){
  2324. $this->APubInit();
  2325. $obj=[];
  2326. $obj['published']=gmdate("Y-m-d\TH:i:s\Z");
  2327. $obj['id']=""; //<-------------------
  2328. $obj['url']=$this->HostURL.""; //<-------------------
  2329. $obj['type']='Note';
  2330. $obj['attributedTo']=$this->HostURL."?apub_actor=1";
  2331. $tag=[]; $tag['type']='Mention'; $tag['name']="@chengdulittlea"; $tag['href']="https://mastodon.art/users/chengdulittlea";
  2332. $obj['tag']=[$tag];
  2333. // must have cc to have notification in mastodon.
  2334. $obj['cc']=["https://mastodon.art/users/chengdulittlea"];
  2335. $obj['content']="<p>@chengdulittlea Hello activitypub from laMDWiki!</p>";
  2336. $obj['to']="https://www.w3.org/ns/activitystreams#Public";
  2337. $obj['inReplyTo']=""; //<-------------------
  2338. $arr=[];
  2339. $arr['@context']="https://www.w3.org/ns/activitystreams";
  2340. $arr['id']=""; //<-------------------
  2341. $arr['actor']=$this->HostURL."?apub_actor=1";
  2342. $arr['type']="Create";
  2343. $arr['to']="https://www.w3.org/ns/activitystreams#Public";
  2344. $arr['object']=$obj;
  2345. $this->APubDeliver(json_encode($arr),"https://mastodon.example/inbox"); //<-------------------
  2346. }
  2347. function APubProcessInbox(){
  2348. $r = file_get_contents('php://input');
  2349. file_put_contents('postdump.txt',$r);
  2350. }
  2351. function MakeRSS(){
  2352. $this->ReadPosts();$this->ReadImages();
  2353. $posts = []; if(isset($this->UsePosts[0])){
  2354. $posts = array_reverse($this->UsePosts);
  2355. $last_updated = $this->StandardTime($posts[0]['id']);
  2356. }else{ $last_updated= $this->StandardTime("20000101000000"); }
  2357. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2358. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2359. "<id>".$this->HostURL."/?rss</id>".
  2360. "<updated>".$last_updated."</updated>".
  2361. "<title>".$this->T($this->Title)."</title>".
  2362. "<link href='".$this->HostURL."/index.php?rss=".($this->LanguageAppendix=='zh'?'zh':'en')."' rel='self'/>".
  2363. "<link href='".$this->HostURL."' />".$author;
  2364. $i=0;
  2365. if(isset($posts[0])) foreach($posts as &$p){
  2366. if($i>100) break;
  2367. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2368. if(isset($p['tid'])){ /* Should always be set. */
  2369. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2370. if(in_array($p['id'],
  2371. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  2372. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2373. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2374. $is_reversed=false;
  2375. $content="<entry>"; $title = NULL;
  2376. if($is_thread){
  2377. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2378. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2379. foreach($use_arr as &$po){
  2380. $this->ConvertPost($po);
  2381. if(!isset($title)){$title = htmlspecialchars($this->GetPostTitle($po, false, false)); if(!$title){$title='untitled';}
  2382. $content.="<id>".$this->HostURL."/?post=".$po['id']."</id>";
  2383. $content.="<title type='html'>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$po['id']."' />";
  2384. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2385. $content.="<updated>".$this->StandardTime(isset($po['tid']['last']['version'])?
  2386. $po['tid']['last']['version']:$po['tid']['last']['id'])."</updated>".$author;
  2387. $content.="<content type='html'>"; }
  2388. $content.= htmlspecialchars($po['html']);
  2389. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2390. }
  2391. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2392. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2393. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2394. $content.="</content>";
  2395. }else{
  2396. $this->ConvertPost($p);
  2397. if(!isset($title)){$title = htmlspecialchars($this->GetPostTitle($p, false, false)); if(!$title){$title='untitled';}
  2398. $content.="<id>".$this->HostURL."/?post=".$p['id']."</id>";
  2399. $content.="<title type='html'>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$p['id']."' />";
  2400. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2401. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2402. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2403. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2404. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2405. $content.=$this->ReadableTime($p['id'])." - ".
  2406. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2407. $content.="</content>";
  2408. }
  2409. $i++;
  2410. $content.="</entry>";
  2411. $all_content.=$content;
  2412. }
  2413. $all_content.="</feed>";
  2414. header( "Content-type: text/xml");
  2415. echo $all_content;
  2416. }
  2417. function MakeHereButtons($im, $insert_here){
  2418. if(isset($im['here'])&&isset($im['here'][0])){
  2419. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2420. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2421. foreach($im['here'] as $here){
  2422. if($insert_here){
  2423. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2424. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2425. }else{
  2426. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2427. }
  2428. }
  2429. echo "</div>".($insert_here?"</here>":"");
  2430. }
  2431. }
  2432. function ProcessRequest(&$message=NULL, &$redirect=NULL){ global $INDEXPHP;
  2433. if(isset($_GET['gallery_continue']) && $_GET['gallery']){
  2434. $this->ReadImages();
  2435. $this->GetImageBatch($_GET['gallery_continue'],0);
  2436. exit;
  2437. }
  2438. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2439. $redirect = "$INDEXPHP?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2440. return 0;
  2441. }
  2442. if(isset($_GET['set_language'])){
  2443. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2444. $redirect=$this->GetRedirect(); return 0;
  2445. }
  2446. if(isset($_GET['rss'])){
  2447. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2448. $this->MakeRSS(); exit;
  2449. }
  2450. if(isset($_GET['toggle_font'])){ $use_font='local';
  2451. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2452. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2453. $redirect=$this->GetRedirect(); return 0;
  2454. }
  2455. if(isset($_GET['set_wayback'])){
  2456. if($_GET['set_wayback']!='false'){
  2457. $wayback= date('YmdHis');
  2458. if($_GET['set_wayback']=='post'){
  2459. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2460. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2461. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2462. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2463. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2464. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2465. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2466. }else{
  2467. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2468. }
  2469. $redirect=$this->GetRedirect(); return 0;
  2470. }
  2471. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2472. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2473. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2474. if(isset($_GET['post'])){
  2475. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2476. }
  2477. if(isset($_GET['random_here'])){
  2478. $this->DoIdentifyExperimental(); $this->DetectPageType();
  2479. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2480. }
  2481. if(isset($_POST['search_content'])){ $redirect=$INDEXPHP.'?search='.$_POST['search_content'];return 0; }
  2482. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2483. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2484. $direct_return = !isset($_GET['show_image']);
  2485. $this->ReadImages(); $this->ReadPosts();
  2486. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2487. $im = &$this->FindImage($m);
  2488. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2489. if($direct_return){
  2490. echo "<ref>".sizeof($im['refs'])."</ref>";
  2491. echo "<insert>";
  2492. }else{ ob_start(); }
  2493. $STR="";
  2494. $this->TBackup();
  2495. foreach(array_reverse($im['refs']) as $ref){
  2496. $p = $this->GetPost($ref);
  2497. if(!$p || !$this->CanShowPost($p)) continue;
  2498. $this->MakeSinglePostV2($p, false, true, "post_preview", true, false, false, false, true);
  2499. }
  2500. $STR=$this->TRestore(" compact");
  2501. if($direct_return){
  2502. echo $STR;
  2503. echo "</insert>";
  2504. $this->MakeHereButtons($im, true);
  2505. }else{
  2506. $str = $STR;
  2507. $this->MakePageBegin($this->NULL_POST);
  2508. $side = "";
  2509. if(isset($im['refs'])&&isset($im['refs'][0])){
  2510. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2511. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2512. $static_image = isset($im['video'])?NULL:$im['file'];
  2513. $static_video = isset($im['video'])?$im['file']:NULL;
  2514. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$static_image,$static_video);
  2515. $this->MakePageEnd();
  2516. }
  2517. exit;
  2518. }
  2519. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2520. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2521. $redirect=$INDEXPHP.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2522. }
  2523. if(isset($_GET['apub_actor'])){
  2524. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2525. echo $this->APubActor; exit;
  2526. }
  2527. if(isset($_GET['apub_outbox'])){
  2528. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2529. echo $this->APubMakeOutbox(); exit;
  2530. }
  2531. if(isset($_GET['apub_inbox'])){
  2532. $this->APubProcessInbox();
  2533. http_response_code(202); exit;
  2534. }
  2535. if($this->LoggedIn){
  2536. if(isset($_GET['TestAPubDeliver'])){
  2537. $this->APubTestDeliver();
  2538. }
  2539. $this->DoUpload();
  2540. if(isset($_POST['settings_button'])){
  2541. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2542. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2543. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2544. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2545. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2546. if(isset($_POST['settings_special_sidebar'])) $this->SpecialSidebar=$_POST['settings_special_sidebar'];
  2547. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2548. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2549. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2550. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2551. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2552. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2553. if(isset($_POST['settings_enable_newsletter'])) $this->NewsletterEnabled=True; else $this->NewsletterEnabled=False;
  2554. if(isset($_POST['settings_gallery_step'])) $this->GalleryStep=$_POST['settings_gallery_step'];
  2555. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2556. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2557. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2558. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2559. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2560. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2561. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2562. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2563. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2564. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2565. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2566. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2567. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2568. if(isset($_POST['settings_allow_language'])) $this->AllowLanguageChoices=True; else $this->AllowLanguageChoices=False;
  2569. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2570. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2571. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2572. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2573. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2574. $this->APubID=$_POST['settings_apub_id'];
  2575. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2576. }
  2577. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2578. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2579. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2580. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2581. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2582. $redirect=$_SERVER['REQUEST_URI'];
  2583. $this->DoLogout();
  2584. }
  2585. $this->WriteConfig();
  2586. return 0;
  2587. }
  2588. if(isset($_POST['settings_save_redirect'])){
  2589. if(isset($_POST['settings_redirect'])){
  2590. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2591. }
  2592. $this->WriteConfig();
  2593. $redirect = $INDEXPHP.'?extras=true'; return 0;
  2594. }
  2595. if(isset($_POST['settings_save_translation'])){
  2596. if(isset($_POST['settings_translation'])){
  2597. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2598. }
  2599. $redirect = $INDEXPHP.'?extras=true'; return 0;
  2600. }
  2601. if(isset($_GET['post'])){
  2602. if(isset($_GET['post_original'])){
  2603. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2604. exit;
  2605. }
  2606. }
  2607. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2608. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2609. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2610. return 0;
  2611. }
  2612. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2613. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2614. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2615. return 0;
  2616. }
  2617. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2618. $c = $_POST['post_content'];
  2619. if('有什么想说的' == $c){ return 0;}
  2620. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2621. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2622. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2623. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2624. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2625. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2626. $redirect='?post='.$edited['id']; return 0;
  2627. };
  2628. }
  2629. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2630. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2631. $redirect='?post='.$edited['id']; return 0;
  2632. };
  2633. }
  2634. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2635. if(($edited =$this->EditPost(
  2636. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2637. $redirect='?post='.$edited['id']; return 0;
  2638. };
  2639. }
  2640. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2641. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2642. if(isset($post)){
  2643. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2644. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2645. echo "SUCCESS ".$mastodon_url;
  2646. }else{ echo $err; }
  2647. } exit;
  2648. }
  2649. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2650. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2651. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2652. }
  2653. }
  2654. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2655. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2656. $redirect='?post='.$pe['id']; return 0;
  2657. }
  2658. }
  2659. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2660. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2661. $c = $_POST['comment_box'];
  2662. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2663. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2664. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2665. if(($edited = $this->EditComment(NULL,
  2666. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2667. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2668. $_SERVER['REMOTE_ADDR']))!=NULL){
  2669. $redirect='?post='.$_GET['post'];
  2670. return 0;
  2671. };
  2672. }
  2673. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2674. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2675. $new_name = $_POST['gallery_edit_new_name'];
  2676. if($old_name!=''){
  2677. $desc=isset($_POST['gallery_edit_description'])?$_POST['gallery_edit_description']:null;
  2678. if(!preg_match('/[0-9]{14}/',$desc))$desc="";
  2679. $this->EditGallery($old_name, $new_name, false, true, null, null,$desc);
  2680. $redirect='?gallery='.$new_name;
  2681. }else{
  2682. $this->EditGallery(null, $new_name, false, true, null,null);
  2683. if(isset($_GET['gallery'])) $redirect=$INDEXPHP.'?gallery='.$_GET['gallery']; else $redirect=$INDEXPHP;
  2684. }
  2685. return 0;
  2686. }
  2687. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2688. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null,null);
  2689. if(isset($_GET['gallery'])) $redirect=$INDEXPHP.'?gallery=main'; else $redirect=$INDEXPHP;
  2690. return 0;
  2691. }
  2692. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2693. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2694. $this->ReadImages();
  2695. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2696. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL, NULL);
  2697. }
  2698. }
  2699. if(isset($_GET['gallery'])) $redirect=$INDEXPHP.'?gallery='.$_GET['gallery']; else $redirect=$INDEXPHP;
  2700. return 0;
  2701. }
  2702. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2703. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2704. if(isset($_GET['gallery'])) $redirect=$INDEXPHP.'?gallery='.$_GET['gallery']; else $redirect=$INDEXPHP;
  2705. return 0;
  2706. }
  2707. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2708. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2709. if(isset($_GET['gallery'])) $redirect=$INDEXPHP.'?gallery='.$_GET['gallery']; else $redirect=$INDEXPHP;
  2710. return 0;
  2711. }
  2712. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2713. $this->ReadImages();
  2714. $gallery = $_GET['image_list']; $count=0;
  2715. foreach($this->Images as $im){ if($count>25){ break; }
  2716. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; $count++; continue; }
  2717. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2718. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; $count++; }
  2719. }
  2720. exit;
  2721. }
  2722. $do_image_redirect = 0;
  2723. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2724. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4))/u',$_GET['pic'],$ma)){
  2725. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2726. if(isset($_POST['image_ops_product_link'])){
  2727. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL, NULL);
  2728. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2729. }
  2730. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2731. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL, NULL);
  2732. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2733. $do_image_redirect = 1;
  2734. }
  2735. if(isset($_POST['image_parent'])){ $parent="";
  2736. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2737. $this->EditImage($pic, NULL, false, NULL, NULL, $parent, NULL);
  2738. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2739. }
  2740. if(isset($_POST['image_align'])){$val=$_POST['image_align'];
  2741. $this->EditImage($pic, NULL, false, NULL, NULL, NULL, $val);
  2742. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2743. }
  2744. $this->NeedWriteImages = 1;
  2745. if($do_image_redirect) return 0;
  2746. }
  2747. if(isset($_GET['rewrite_styles'])){
  2748. $this->WriteStyles(); $redirect='?extras=true'; return 0;
  2749. }
  2750. if(isset($_GET['regenerate_thumbnails'])){
  2751. $this->RegenerateThumbnails(); $redirect='?extras=true'; return 0;
  2752. }
  2753. if(isset($_GET['cleanup_image_compression'])){ $run=false;
  2754. if(isset($_GET['run'])){ $run=true; }
  2755. $this->CleanupImageCompression($run); $redirect='?extras=true'; return 0;
  2756. }
  2757. if(isset($_GET['clear_all_logins'])){
  2758. $this->LoginTokens=[]; $this->WriteTokens();
  2759. }
  2760. if($_SERVER['HTTP_HOST']=='localhost'){$this->WriteStyles();}
  2761. }
  2762. return 0;
  2763. }
  2764. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null, &$end_wide=null, &$print_wide=null){
  2765. if(!$this->LoggedIn){
  2766. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2767. }
  2768. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2769. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2770. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2771. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2772. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2773. $html = preg_replace("/\{\s*(REVERSED|INTERESTING|HEADER|FOOTER)\s+(.*?)\}/imu","",$html);
  2774. $html = preg_replace("/\{\s*(REVERSED|NO_TIME|NO_TITLE|SLIDES)\s*\}/imu","",$html);
  2775. $html = preg_replace("/\{\s*WIDE\s*\}/imu","",$html,-1,$rep_count); if($rep_count){$print_wide=true;}
  2776. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2777. $html = preg_replace_callback(
  2778. "/(<p>\s*|<a\s.*?>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2779. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2780. if(isset($m[1])&&$m[1]&&$m[1][1]=='a'){ $height="";
  2781. if(preg_match("/([0-9]{1,2})em/u",$m[0],$hm)){$height=' style="height:'.$hm[1].'em;"';}
  2782. return "<a class='imbtn'".$height.substr($m[0],2); }
  2783. $orig_src = $src = $m[5]; $keep = false; $original = false; $float=false;
  2784. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2785. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2786. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2787. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2788. if (preg_match('/alt=[\'\"].*float.*[\'\"]/u',$m[3]) ||
  2789. preg_match('/alt=[\'\"].*float.*[\'\"]/u',$m[7])) { $keep=true;$original=true;$float=true; }
  2790. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2791. $src = $im['thumb']; $orig_src=$im['file'];
  2792. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2793. $media_start = $m[2];
  2794. $media_end = $m[7];
  2795. $dataset = " data-imgsrc='".$m[5]."'".
  2796. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2797. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2798. (isset($im['align'])?' data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':"").
  2799. ($original?" class='original_img'":"");
  2800. if(isset($im['video']) && isset($im['video'])!=''){
  2801. $media_start = "<video controls".$dataset."><source src='"; $media_end="' type='".$im['video']."'></video";
  2802. $src = $orig_src; $dataset="";
  2803. }
  2804. $float_add=""; if($float){ $float_add=" imd_float"; }
  2805. if($this->InHereMode){
  2806. $click = "<div class='imd$float_add'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2807. $media_start.($original?$orig_src:$src).$media_end."></a></div>";
  2808. $ret=""; if($keep) { $ret = $click; }
  2809. else { $images[] = $click; }
  2810. return $ret;
  2811. }else{
  2812. $click ="<div class='imd$float_add'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2813. $media_start.($original?$orig_src:$src).$media_end.$dataset."></a></div>";
  2814. $images_noclick[]=$media_start.$src.$media_end.">"; $images_orig_src_list[]=$orig_src;
  2815. $ret = "";
  2816. if($keep) { $ret = $click; }
  2817. else { $images[] = $click; }
  2818. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2819. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2820. }
  2821. },$html,-1,$count);
  2822. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2823. if(sizeof($images)){
  2824. if((!$this->InHereMode) && sizeof($images)==1){$html.= $images[0]; }
  2825. else{
  2826. $html.="<div class='p_row'>";
  2827. foreach($images as $img){
  2828. $html.="<div class='p_thumb'>".$img."</div>";
  2829. }
  2830. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2831. }
  2832. }
  2833. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2834. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2835. if($do_product_info){
  2836. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2837. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2838. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2839. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2840. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2841. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2842. else { $product_info['title'] = $this->T('商品'); }
  2843. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2844. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2845. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2846. $this->T('购买').' '.$product_info['title'].
  2847. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2848. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2849. }
  2850. if(preg_match("/(<\/div>|<\/table>|<\/video>)\s*$/u",$html)){$end_wide=true;}
  2851. return $html;
  2852. }
  2853. function ConvertPost(&$post){
  2854. if(!isset($post['html'])){
  2855. $info=[];
  2856. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2857. $post['images'],
  2858. isset($post['product']), $info,
  2859. $post['original_images'],
  2860. $post['end_wide'],
  2861. $post['wide']));
  2862. if(isset($post['product'])) $post['product']=$info;
  2863. }
  2864. }
  2865. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2866. if($h1_only){
  2867. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)) return strip_tags($this->TranslatePostParts($m[1]));
  2868. else return NULL;
  2869. }
  2870. if(!isset($post['title'])){
  2871. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[0];}
  2872. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2873. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2874. $post['title'].=($add_unamed?' (':'').$this->PDE->text($m[1]).($add_unamed?')':''); }
  2875. }
  2876. }
  2877. return strip_tags($this->TranslatePostParts($this->PDE->text($post['title'])));
  2878. }
  2879. function DetectPageType(){
  2880. if ($this->InExperimentalMode) $this->PageType='experimental';
  2881. else if($this->InHereMode) $this->PageType='here';
  2882. else if(isset($_GET['history'])) $this->PageType='history';
  2883. else if(isset($_GET['extras'])) $this->PageType='extras';
  2884. else if(isset($_GET['settings'])) $this->PageType='settings';
  2885. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2886. else if(isset($_GET['search'])) $this->PageType='search';
  2887. else if(isset($_GET['category'])) $this->PageType='category';
  2888. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2889. else if(isset($_GET['comments'])) $this->PageType='comments';
  2890. else if(isset($_GET['statistics'])) $this->PageType='statistics';
  2891. else $this->PageType = "main";
  2892. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2893. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2894. $this->VisitedHere = $_SESSION[$visited_here];
  2895. }
  2896. function MakePageBegin(&$p){ $title=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2897. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title)) ?>
  2898. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2899. <head>
  2900. <meta charset='utf-8'>
  2901. <meta content="width=device-width, initial-scale=1" name="viewport">
  2902. <title><?=$title?></title>
  2903. <meta property="og:title" content="<?=$title.(isset($p)?(" | ".$this->GetPostTitle($p)):"")?>">
  2904. <?php if(isset($p)&&isset($p['hasi'])&&isset($p['hasi'][0])){?> <meta property="twitter:card" content="summary_large_image" />
  2905. <meta property="og:image" content="<?=(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']==='on'?"https":"http").'://'.$_SERVER['HTTP_HOST'].'/images/thumb/'.$p['hasi'][0]?>"><?php } ?>
  2906. <?php if($this->UseRemoteFont){ ?><style>
  2907. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2908. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2909. </style><?php } ?>
  2910. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2911. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2912. <link rel="alternate" hreflang="zh" href="index.php?<?=$_SERVER['QUERY_STRING']?>" />
  2913. <link rel="alternate" hreflang="en" href="en.php?<?=$_SERVER['QUERY_STRING']?>" />
  2914. <link rel="alternate" hreflang="x-default" href="en.php?<?=$_SERVER['QUERY_STRING']?>" />
  2915. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2916. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2917. <noscript><style>.lb.post_access{top:unset;bottom:0;height:2em;} .active_post .lb.post_access{height:100%;}.post label{pointer-events:all;}</style></noscript>
  2918. </head>
  2919. <div class='page'>
  2920. <?php }
  2921. function MakeHeader(&$p){
  2922. $this->MakePageBegin($p) ?>
  2923. <script type='text/javascript'>
  2924. function toggle_mobile_show(a){a.classList.toggle('hidden_m')}
  2925. function ShowWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='';}
  2926. function HideWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='none';}
  2927. <?php if(!$this->InHereMode){ ?>
  2928. function la_auto_grow(element){
  2929. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2930. }
  2931. function ShowBackdrop(alpha=0.5){
  2932. b = document.getElementById('backdrop');
  2933. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2934. b.style.animation='backdrop_fade_in 0.3s forwards';
  2935. b.style.display = 'block';
  2936. }
  2937. function HideBackdrop(){
  2938. b = document.getElementById('backdrop');
  2939. b.style.animation='backdrop_fade_out 0.3s forwards';
  2940. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2941. }
  2942. function ShowRightSide(big,elem_to_clone){
  2943. p = document.getElementById('pop_right');
  2944. if(elem_to_clone){
  2945. c = elem_to_clone.cloneNode(true);
  2946. c.id='side_bar_cloned';c.className="";c.style="";
  2947. p.querySelector('._content').appendChild(c);
  2948. }
  2949. p.classList.remove('pop_right','pop_right_big');
  2950. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2951. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2952. p.style.display='block';
  2953. ShowBackdrop(0.5);
  2954. }
  2955. function HideRightSide(){
  2956. p = document.getElementById('pop_right');
  2957. if(side=p.querySelector('#side_bar_cloned')){
  2958. side.remove();
  2959. }
  2960. put = document.querySelector("#_uploader");
  2961. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2962. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2963. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2964. HideBackdrop();
  2965. }
  2966. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2967. function ScrollToPost(id){
  2968. post=null;
  2969. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2970. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2971. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2972. }
  2973. <?php } ?>
  2974. </script><input type='checkbox' class='lpctrl' id='titlectrl'>
  2975. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2976. <?php if($this->InHereMode){
  2977. $this->MakeExpNavButtons($p);
  2978. }else{
  2979. $this->MakeNavButtons($p);
  2980. if(isset($p['tid']['header'])){ ?><div style='float:right' class='show_on_print'><?=$this->ChoosePartsByLanguage($p['tid']['header']);?></div><?php }
  2981. echo "<hr class='hidden_m'>";
  2982. } ?>
  2983. <?php if(isset($this->WayBack)){
  2984. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2985. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2986. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2987. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_m")'>
  2988. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2989. <span class='hidden_m'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2990. + <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_m'>
  2991. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2992. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2993. <br class='hidden_on_desktop' />
  2994. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2995. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2996. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2997. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2998. <br class='hidden_on_desktop' />
  2999. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  3000. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  3001. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  3002. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  3003. <br class='hidden_on_desktop' />
  3004. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  3005. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  3006. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  3007. </div></div><?php } ?>
  3008. </div></header>
  3009. <div id='waiting_bar' style='display:none;'></div>
  3010. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  3011. <?php if(!$this->InHereMode){ ?>
  3012. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  3013. <ul>
  3014. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  3015. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  3016. <hr />
  3017. <?php if($this->LoggedIn){ ?>
  3018. <li><a id='menu_history'><?=$this->T('历史')?></a>
  3019. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  3020. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  3021. <?php if(!isset($this->WayBack)){ ?><li>
  3022. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  3023. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  3024. </li>
  3025. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  3026. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  3027. <li id='mark_details' style='display:none;'><b>
  3028. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  3029. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  3030. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  3031. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  3032. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  3033. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  3034. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  3035. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  3036. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  3037. </b></li>
  3038. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  3039. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  3040. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  3041. <input class='button' type='submit' form='post_rename_form'
  3042. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  3043. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  3044. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  3045. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  3046. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  3047. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  3048. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  3049. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  3050. <input class='button' type='submit' form='post_mastodon_form'
  3051. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  3052. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  3053. <?php }else{ ?>
  3054. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  3055. <?php } ?>
  3056. </ul>
  3057. </div>
  3058. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide();HideBigImage(1);'
  3059. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  3060. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  3061. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  3062. <?=$this->T('关闭')?>→</a></div>
  3063. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  3064. <div id='_uploader' style='display:none;'>
  3065. <?php $this->MakeUploader(true); ?>
  3066. <p>&nbsp;</p>
  3067. <?php $this->MakeSideGalleryCode(); ?>
  3068. </div>
  3069. <?php } ?>
  3070. <div class='_content'></div>
  3071. </div>
  3072. <?php } ?>
  3073. <?php
  3074. }
  3075. function ChoosePartsByLanguage($content,$use_p=false){ if(!isset($content)) return $content;
  3076. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  3077. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  3078. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  3079. if($split) for($i=0;$i<sizeof($split);$i+=4){
  3080. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  3081. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  3082. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  3083. }
  3084. if(!$reduced)$reduced = $content;
  3085. return $reduced;
  3086. }
  3087. function TranslatePostParts($html){
  3088. $html = preg_replace_callback('/>(\s*)([^><]+?)(\s*)</u', function($ma){
  3089. $reduced = $this->ChoosePartsByLanguage($ma[2], false);
  3090. return ">".$ma[1].$this->T($reduced).$ma[3]."<";
  3091. }, $html);
  3092. return $html;
  3093. }
  3094. function MakeNavButtons(&$p){ global $INDEXPHP; $interesting=$this->IsInterestingPost($p); $no_title=isset($p['tid']['first']['no_title']);?>
  3095. <a href='<?=$INDEXPHP?>' class='clean_a hidden_m<?=$no_title?" hidden_on_print":""?>' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title);?></b></a>
  3096. <?=$no_title?"<a class='inline_print'>&nbsp;</a>":""?>
  3097. <label for='titlectrl' id='mtitle'><b><a class='hidden_on_desktop'><?=$this->T($this->ShortTitle)?>...</a></b></label>
  3098. <div class='header_nav'>
  3099. <ul class='mobile_fold hidden_on_print' id='mobile_nav'>
  3100. <li class='hidden_m'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  3101. <li class='hidden_on_desktop_force block_m smaller'>&nbsp;</li>
  3102. <li class='hidden_on_desktop_force block_m bigger'>
  3103. <a href='<?=$INDEXPHP?>?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a>
  3104. <?php if($this->LoggedIn){ ?> | <span class='gray invert_a'>
  3105. <a href='<?=$INDEXPHP?>?comments=all'>@</a> <a href='<?=$INDEXPHP?>?statistics=all'>%</a></span><?php } ?></li>
  3106. <li class='hidden_on_desktop_force block_m bigger'>
  3107. <a href='<?=$INDEXPHP?>?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  3108. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  3109. echo $this->GenerateSinglePost($p, false, false, false, false);
  3110. } ?>
  3111. <?php if($this->LanguageAppendix=='zh'){ ?>
  3112. <li class='smaller gray'>
  3113. <a href='<?=$this->GetRedirect(null,'en.php').'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  3114. <?php }else { ?>
  3115. <li class='smaller gray'>
  3116. <a href='<?=$this->GetRedirect(null,'index.php').'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  3117. 汉语/<b>English</b></a>
  3118. <br class='hidden_on_desktop' />
  3119. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  3120. <?php } ?>
  3121. </ul></div>
  3122. <?php
  3123. }
  3124. function MakeExpNavButtons(&$p){ global $INDEXPHP; ?>
  3125. <a href='<?=$INDEXPHP?>' class='hidden_m'>
  3126. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  3127. <a class='hidden_on_desktop'
  3128. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b class='round_btn'>
  3129. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?></b></a>
  3130. <?php if(!$this->InExperimentalMode){ ?>
  3131. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  3132. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  3133. <span class='round_btn'>
  3134. <a href='<?=$this->HereNumber==sizeof($this->VisitedHere)?"?random_here=1":$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a>
  3135. <a href='?random_here=1'><?=$this->T("随机")?></a></span><span class='hidden_m'></span>
  3136. <?php } ?>
  3137. <ul class='hidden_m' id='mobile_nav' style='text-align:center;'>
  3138. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  3139. <li class='hidden_on_desktop block_m'><a href='<?=$INDEXPHP?>'><?=$this->T('主页')?></a></li>
  3140. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  3141. echo $this->GenerateSinglePost($p, false, false, false, false);
  3142. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  3143. echo $this->GenerateSinglePost($p, false, false, false, false);
  3144. } ?>
  3145. <?php if($this->AllowLanguageChoices){ ?>
  3146. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  3147. <?php if($this->LanguageAppendix=='zh'){ ?>
  3148. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  3149. <?php }else { ?>
  3150. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  3151. <li class='smaller invert_a gray'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  3152. <?php } ?>
  3153. <?php } ?>
  3154. </ul>
  3155. <?php
  3156. }
  3157. function MakePostingFieldsV2($reply_to=NULL, $show_hint=false){ $STR="";
  3158. if(isset($this->WayBack)){
  3159. $STR.="<span class='gray'><i>{$this->T('以过去日期浏览时不能发帖。')}</i></span>";
  3160. $this->TFill(2,$STR); $this->TRow(); return;
  3161. }
  3162. $STR.="<form action='{$_SERVER['REQUEST_URI']}' method='post' style='display:none;' id='post_form'></form>
  3163. <div class='smaller'><div style='display:".($show_hint?"block":"none")."'>
  3164. <span id='post_hint_text'>{$this->T('继续补充该话题:')}</span></div>
  3165. <div id='post_hint_modify' style='display:none;'>
  3166. <input type='checkbox' name='post_record_edit' value='1' form='post_form' checked> {$this->T('新增历史记录')}</div></div>
  3167. <textarea id='post_content' name='post_content' rows='4' form='post_form'
  3168. onfocus=\"if (value =='{$this->T('有什么想说的')}'){value ='';}la_auto_grow(this);\"
  3169. onblur=\"if (value ==''){value='{$this->T('有什么想说的')}';la_auto_grow(this);}\"
  3170. oninput=\"la_auto_grow(this);\" onload=\"la_auto_grow(this);\">{$this->T('有什么想说的')}</textarea>
  3171. <input class='button' form=\"post_form\" type=\"submit\" name='post_button' value='{$this->T('发送')}'
  3172. onclick='ShowWaitingBar();' />
  3173. | <a class='gray smaller pointer' onclick='ShowSideUploader();'>{$this->T('图片')}</a>
  3174. <div style='float:right;'>
  3175. <a class='gray smaller pointer' onclick=\"t=document.querySelector('#post_content');t.value='';la_auto_grow(t);\">
  3176. {$this->T('清空')}</a>
  3177. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3178. </div>
  3179. <input style='display:none;' type=input form='post_form' id='post_edit_target' name='post_edit_target' />
  3180. <script> la_auto_grow(document.getElementById('post_content'));</script>";
  3181. if($reply_to){
  3182. $STR.="<input style='display:none;' type=input form='post_form' id='post_reply_to' name='post_reply_to' value='{$reply_to}' />";
  3183. }
  3184. $this->TFill(2,$STR);$this->TExtra("class='hidden_on_print'"); $this->TRow();
  3185. }
  3186. function MakeLinkedPostsV2(&$p){ $STR="";
  3187. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); if(!$has_ref)return; $count=0;
  3188. $STR.="<input type='checkbox' class='lpctrl' id='fake{$p["id"]}' checked='checked'>";
  3189. $count_product=0;
  3190. $STR.="<div class='linked_posts smaller'>";
  3191. $refs=sizeof($p["refs"]);
  3192. $STR.="<label class='lb ref_count' for='fake{$p["id"]}'>× $refs".$this->T("个引用").":</label><hr />";
  3193. foreach(array_reverse($p['refs']) as &$pr){
  3194. $po = $this->GetPost($pr);
  3195. if(!$this->CanShowPost($po)){ continue; } $count++;
  3196. $this->TBackup();
  3197. $this->MakeSinglePostV2($po, false, true, 0, true, true, false, false, true, false, false);
  3198. $STR.=$this->TRestore(" compact");
  3199. }
  3200. $STR.="</div>";
  3201. $this->TFill(0,$S0);
  3202. $this->TFill(1,$STR,2);$this->TExtra("style='border-bottom:none;'"); $this->TRow();
  3203. }
  3204. function MakeSinglePostV2(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  3205. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  3206. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  3207. $STR=""; $EXTRA="";$S0=""; $S1="";
  3208. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  3209. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  3210. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  3211. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  3212. $number = isset($post['number'])?$post['number']:0;
  3213. $title = $generate_anchor?$this->ChoosePartsByLanguage($this->GetPostTitle($post, true)):NULL;
  3214. $this->ConvertPost($post);// NEEDED FOR WIDE;
  3215. $is_wide = (isset($post['wide'])&&$post['wide']) || (isset($post['tid']) && isset($post['tid']['wide']) && $post['tid']['wide']);
  3216. if($show_link && (!$side)){ $this->MakeLinkedPostsV2($post); }
  3217. $EXTRA.="class='post $extra_class_string".($is_deleted?" deleted_post":"").($is_wide?" wide_post_print":"")."'";
  3218. if(!$side) $EXTRA.=(" data-post-id='".$post['id']."'");
  3219. if($is_deleted) $EXTRA.=" data-mark-delete='true'";
  3220. if(!$side&&isset($post['mastodon_url'])) $EXTRA.=(" data-mastodon_url='".$post['mastodon_url']."'");
  3221. //if($is_wide) $EXTRA.=" class=''";
  3222. if(!$side && !$strip_tags && $show_link){ $STR.="<div class='post_menu_button _menu_hook' >+</div>"; }
  3223. $this->TFill(2,$STR);
  3224. $symbol=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:"#";
  3225. $S1.="<a".($symbol!='#'?' class="marked"':'').
  3226. " href='?post={$post['id']}' onclick=\"".(($show_thread_link||$side)?'ShowWaitingBar()':'ClickPost(this.parentNode.parentNode,event,true)')."\">".
  3227. $symbol."<span class='mobile_fold'>".$number."</span>";
  3228. if($ref_count && !$side){
  3229. $S0.="<label class='lb' ".($show_link?"for='fake{$post["id"]}":"")."'><div class='ref_count'>+<span class='hidden_m'>{$ref_count}</span></div></label>";
  3230. }
  3231. if($is_product&&!$generate_anchor){ $STR.="<p class='smaller gray'>".$this->T('商品')."</p>";}
  3232. $STR.=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, $show_link,
  3233. $generate_thumb,($show_thread_link||$side||$force_hide_long));
  3234. if($show_thread_link && (!$side) && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) && $post['tid']['first']['id']!=$post['id']){
  3235. $STR.="<div class='gray block'>";
  3236. $STR.="<div class='smaller'>{$this->T('回复给主题帖:')}</div>";
  3237. $this->TBackup();
  3238. $this->MakeSinglePostV2($post['tid']['first'], false, false, false, false, false, false,false, true, false, false);
  3239. $STR.=$this->TRestore(" compact");
  3240. $STR.="</div>";
  3241. }
  3242. if($show_reply_count && isset($post['tid'])){
  3243. $STR.="<a class='smaller block invert_a' href='?post={$post['tid']['last']['id']}'>{$post['tid']['count']} {$this->T('个回复')}</a>";
  3244. }
  3245. $this->TFill(2,$STR); $this->TFill(1,$S1); $this->TFill(0,$S0); $this->TExtra($EXTRA); $this->TRow();
  3246. }
  3247. function MakePostSectionV2(&$post){ $STR=""; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1;
  3248. $this->Anchors = []; if(isset($post['slides']) || ($is_thread&&isset($post['tid']['slides']))) $centerclass='center_slides'; else $centerclass='center';
  3249. if(isset($this->TagID)){ $STR.=<<<EOT
  3250. <style>{$this->CssNumberID($this->TagID)}{display:block;}</style>
  3251. EOT; } $th=NULL; $STR.="<br /><h2>";
  3252. $is_wide = (isset($post['wide'])&&$post['wide']) || ($is_thread && isset($post['tid']['wide']) && $post['tid']['wide']);
  3253. if($is_thread){ $th = $post['tid']; $STR.=$this->T('话题'); }else{ $STR.=$this->T('话题');$this->T('详细'); } $STR.="</h2>";
  3254. $this->TFill(2,$STR); $this->TExtra("class='hidden_on_print'"); $this->TRow();
  3255. $cat = NULL;
  3256. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3257. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3258. $this->MakePostTools();
  3259. if($cat){ $STR=<<<EOT
  3260. <p class='hidden_on_print'><b>{$this->T('分类')}</b> |
  3261. EOT; foreach($cat as $c){ $STR.=("<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "); }
  3262. $STR.="</p>";
  3263. }
  3264. $STR.="<br class='hidden_on_print' />"; $this->TFill(2,$STR); $this->TRow(); $is_reversed=false;
  3265. if($is_thread){ $use_arr = $th['arr']; $hinted=false;
  3266. $last_end_wide = true; $is_reversed=$this->IsReversedThread($th);
  3267. foreach($use_arr as &$p){$use_class="";if($p==$post){$use_class.=" active_post";}
  3268. if($last_end_wide){$use_class.=" last_wide";}
  3269. $make_title = ($p == $post);
  3270. if(isset($p['restart'])){ $STR="<li class='restart'><h3>{$p['restart']} …</h3></li>"; $this->TFill(0,$STR,3); $this->TRow(); }
  3271. $this->MakeSinglePostV2($p,true,false,$use_class,false, false, false, true, false, false);
  3272. if($make_title){ $STR.='<script>
  3273. document.title+=" | '.addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100))).'"</script>';
  3274. $this->TFill(2,$STR);
  3275. }
  3276. if($is_reversed && !$hinted){ $hinted = true;
  3277. if($this->LoggedIn && (!$this->InHereMode)){
  3278. $STR.="<div class='hidden_on_print'>";
  3279. $STR.=$this->MakePostingFieldsV2($is_thread?$th['last']['id']:$post['id'], true);
  3280. $STR.="</div><br />";
  3281. }
  3282. }
  3283. $last_end_wide = isset($p['end_wide']) && $p['end_wide'];
  3284. }
  3285. }else{
  3286. $this->MakeSinglePostV2($post,true, false,"active_post",false, false, false, true, false, false);
  3287. $STR.='<script>
  3288. document.title+=" | '.addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($post),0,100))).'"</script>';
  3289. $this->TFill(2,$STR); $this->TRow();
  3290. }
  3291. $STR="";
  3292. $class_add=""; if(isset($post['tid']['first']['no_time'])){ $class_add=' hidden_on_print'; }
  3293. $STR.="<div class='smaller align_right$class_add'>
  3294. <span class='gray'>".$this->ReadableTime($post['tid']['first']['id'])."</span>
  3295. <br class='hidden_on_desktop' />".
  3296. $this->ReadableTime(isset($post['tid']['last']['version'])?$post['tid']['last']['version']:$post['tid']['last']['id'])."
  3297. </div>";
  3298. $this->TFill(2,$STR); $this->TRow(); $STR="";
  3299. if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){
  3300. $STR.="<div class='hidden_on_print'><br />{$this->MakePostingFieldsV2($is_thread?$th['last']['id']:$post['id'], true)}</div>";
  3301. $this->TFill(2,$STR); $this->TRow();
  3302. }
  3303. if($this->NewsletterEnabled){ $STR=$this->MakeSubscription(); $this->TFill(2,$STR); $this->TRow(); }
  3304. //$this->MakeCommentSection($post);
  3305. $STR="";
  3306. if(isset($post['slides']) || ($is_thread&&isset($post['tid']['slides']))){
  3307. $STR.=<<<EOL
  3308. <div class='slides_buttons code' onclick="event.stopPropagation();">
  3309. <a onclick="SlidesFontCheck(-1)">T-</a> <a onclick="SlidesFontCheck(1)">T+</a>&nbsp;
  3310. <a onclick="SlidesStart(null)"><<</a> <a onclick="SlidesCheck(-1);"><</a>
  3311. <a onclick="SlidesStart(1)"><span id="slides_now">1</span>/<span id="slides_total">1</span></a>
  3312. <a onclick="SlidesCheck(1);">></a> <a onclick="SlidesEnd();">X</a>
  3313. </div>
  3314. <script>
  3315. function SlidesStart(from_here){
  3316. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return;
  3317. sdone=0; fp=0; if(from_here){
  3318. urlParams = new URLSearchParams(window.location.search);
  3319. fp = urlParams.get('post');
  3320. }
  3321. document.querySelector("#slides_total").innerText=slides.length; cur=document.querySelector("#slides_now");
  3322. for(i=0;i<slides.length;i++){ slides[i].style.display="none";
  3323. if(from_here && slides[i].dataset.postId==fp){ slides[i].style.display="table-cell";sdone=1; ClickPost(slides[i],0,true); cur.innerText=i+1; }
  3324. } if(!sdone){ slides[0].style.display="table-cell"; ClickPost(slides[0],0,true); cur.innerText=1; }
  3325. c=document.querySelector('.center'); if(!c) return;
  3326. c.classList.remove('center'); c.classList.add('center_slides'); if(c.dataset.fontSize){ c.style.fontSize=c.dataset.fontSize; }
  3327. c=document.querySelector('.left'); if(!c) return; c.style.display="none";
  3328. }
  3329. function SlidesCheck(offset){
  3330. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return; cur=document.querySelector("#slides_now");
  3331. for(i=0;i<slides.length;i++){ if(slides[i].style.display=="table-cell" && slides[i+offset] && (i+offset)>=0){
  3332. slides[i+offset].style.display="table-cell"; slides[i].style.display="none"; ClickPost(slides[i+offset],0,true); cur.innerText=i+offset+1; break;
  3333. }
  3334. }
  3335. }
  3336. function SlidesFontCheck(offset){
  3337. c=document.querySelector('.center_slides'); if(!c) return;
  3338. f=5; if(c.style.fontSize){ f=parseInt(c.style.fontSize); }
  3339. f+=offset; if(f<=0) f=1; if(f>12) f=12; c.style.fontSize=""+f+"vmin"; c.dataset.fontSize=c.style.fontSize;
  3340. }
  3341. function SlidesEnd(){
  3342. c=document.querySelector('.center_slides'); if(!c) return;
  3343. c.classList.remove('center_slides'); c.classList.add('center'); c.style.fontSize="";
  3344. c=document.querySelector('.left'); if(!c) return; c.style.display="inline-block";
  3345. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return;
  3346. for(i=0;i<slides.length;i++){ slides[i].style.display=""; }
  3347. }
  3348. //document.addEventListener("wheel", function(event){ if(event.deltaY>0) SlidesCheck(1); else SlidesCheck(-1); }, { passive: false });
  3349. document.addEventListener("click", function(event){ SlidesCheck(1); });
  3350. document.addEventListener('keydown', function(event) {
  3351. const key = event.key; // "ArrowRight", "ArrowLeft", "ArrowUp", or "ArrowDown"
  3352. switch(key){
  3353. case "ArrowUp": case "ArrowLeft": SlidesCheck(-1); break; case "ArrowDown": case "ArrowRight": SlidesCheck(1); break;
  3354. case "Escape": SlidesEnd(); break;
  3355. }
  3356. });
  3357. </script>
  3358. EOL; $this->TAfter($STR);
  3359. }
  3360. }
  3361. function MakeSubscription($smaller=false){
  3362. $STR="";$STR.="<div".($smaller?" class='smaller hidden_on_print'":"").">
  3363. <form action='mailsub.php?subscribe=1' method='post' id='subscribe_form' style='display:none;'></form>
  3364. <br />
  3365. <h".($smaller?"3":"2").">{$this->T("订阅我的新闻")}</h".($smaller?"3":"2").">
  3366. <span class='gray'>{$this->T("输入您的邮件:")}</span>
  3367. <input type='text' id='email_subscribe_name' name='email_subscribe_name' form='subscribe_form' ".
  3368. ($smaller?"style='border-color:#f8ca9b88;background:rgba(0,0,0,0.2);max-width:16em;'":"").">
  3369. <input class='button' form='subscribe_form' type='submit' value={$this->T("订阅")}>
  3370. <br /></div>";
  3371. return $STR;
  3372. }
  3373. function MakeRecentPostsV2($search_term=NULL, $category=NULL){ global $INDEXPHP;
  3374. $STR="";
  3375. if(!isset($search_term) && !isset($category) &&
  3376. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3377. $this->CanShowPost($p)){
  3378. $this->MakeSinglePostV2($p, true, false, "active_post", false, true, false, false, false, true, false);
  3379. }
  3380. if($this->NewsletterEnabled && !isset($category) && !isset($search_term)){
  3381. $STR=$this->MakeSubscription(); $this->TFill(2,$STR); $this->TRow(); $STR='';
  3382. }
  3383. $STR.="<br /><h2>".(isset($search_term)?$this->T('搜索'):
  3384. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3385. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3386. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3387. ($this->LoggedIn?"<a href='".$INDEXPHP."?comments=all'>@</a> <a href='".$INDEXPHP."?statistics=all'>%</a>":"")."</span>")).
  3388. "</h2><br />";
  3389. $this->TFill(2,$STR); $this->TRow();
  3390. if(isset($search_term)){
  3391. $STR.="<form action='".$INDEXPHP."' method='post' style='display:none;' id='search_form'></form>".
  3392. "<input id='search_content' name='search_content' rows='4' form='search_form' type='text' value='$search_term'>".
  3393. "<input class='button' form='search_form' type='submit' name='search_button' value='{$this->T('搜索')}'>";
  3394. $this->TFill(2,$STR); $this->TRow();
  3395. }else if(isset($category)){
  3396. $STR.="<div></div>";
  3397. $this->TFill(2,$STR); $this->TRow();
  3398. }else if($this->LoggedIn){
  3399. $this->TFill(2,$STR); $this->TRow();
  3400. $this->MakePostingFieldsV2(NULL,false);
  3401. }
  3402. $this->PostsPerPage=20;
  3403. $i = 0; $last_end_wide = true;
  3404. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3405. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3406. if(isset($p['tid'])){ /* Should always be set. */
  3407. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3408. if(!isset($search_term)) { $p = &$th['last']; }
  3409. }
  3410. if(isset($search_term)){
  3411. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3412. }else if(isset($category)){
  3413. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3414. (isset($p['categories'])?($p['categories']):[]);
  3415. if ($category=='none') { if($cat!=[]) continue; }
  3416. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3417. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3418. }else{
  3419. if(in_array($p['id'],
  3420. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  3421. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3422. }
  3423. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3424. if($last_end_wide){$use_class="last_wide";}else{$use_class="";}
  3425. $this->MakeSinglePostV2($p, true, false, $use_class, false, !isset($search_term), false, false, false, false, isset($search_term));
  3426. $i++;
  3427. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3428. $last_end_wide = sizeof($p['tid']['arr'])==1 && isset($p['end_wide']) && $p['end_wide'];
  3429. }
  3430. $STR=""; $EXTRA="class='clean_a'"; $STR.="<br /><br />".
  3431. "<a ".($this->CurrentOffset>0?("href='".$INDEXPHP."?offset=".($this->CurrentOffset-1).
  3432. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):"").
  3433. ($this->CurrentOffset==0?" class='gray'":"").">{$this->T('上一页')} ← </a>";
  3434. $STR.=" [ ".($this->CurrentOffset+1)." ] ";
  3435. $STR.="<a href='".$INDEXPHP."?offset=".($this->CurrentOffset+1).
  3436. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'>".
  3437. " → {$this->T('下一页')}</a>";
  3438. $this->TFill(0,$STR,3); $this->TExtra($EXTRA); $this->TRow();
  3439. }
  3440. function GeneratePage($is_section=false,$extra_classes=""){ $S="";
  3441. $S.="<table class='center print_column".($is_section?" clickable_section":"").($extra_classes)."'><tbody>";
  3442. foreach($this->PAGE as $r){ $S.="<tr ".(isset($r['extra'])?$r['extra']:"").">"; $spantotal=0; $sp="";
  3443. if(isset($r['span0'])){$sp=" colspan='".$r['span0']."'"; $spantotal+=$r['span0']; }else{ $spantotal++; };
  3444. if($spantotal<=3){ $S.="<td".$sp.">"; if(isset($r[0])){ $S.=$r[0]; } $S.="</td>"; }
  3445. if(isset($r['span1'])){$sp=" colspan='".$r['span1']."'"; $spantotal+=$r['span1']; }else{ $spantotal++; };
  3446. if($spantotal<=3){ $S.="<td".$sp.">"; if(isset($r[1])){ $S.=$r[1]; } $S.="</td>"; }
  3447. if(isset($r['span2'])){$sp=" colspan='".$r['span2']."'"; $spantotal+=$r['span2']; }else{ $spantotal++; };
  3448. if($spantotal<=3){ $S.="<td".$sp.">"; if(isset($r[2])){ $S.=$r[2]; } $S.="</td>"; }
  3449. $S.="</tr>";
  3450. }
  3451. $S.="</tbody></table>";
  3452. return $S;
  3453. }
  3454. function GenerateLinkedPosts($ht){
  3455. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  3456. function($m){
  3457. if(preg_match('/^\s*<img/u',$m[2])){ return $m[0]; }
  3458. $rp = &$this->GetPost($m[1], false, true);
  3459. $STR=$this->T("未找到该引用。");
  3460. if($rp!==NULL && $this->CanShowPost($rp)){
  3461. $this->TBackup();
  3462. $this->MakeSinglePostV2($rp, false, false, false, false, false, false,false, true, false, false);
  3463. $STR=$this->TRestore(" compact");
  3464. }
  3465. $s="<a class='smaller block' href='?post=".$m[1]."'>".$m[2]."</a><div class='block post gray'>".$STR."</div>";
  3466. return $s;
  3467. },
  3468. $ht
  3469. );
  3470. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  3471. function($m){
  3472. $rp = &$this->GetPost($m[1], false, true);
  3473. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  3474. (($rp!==NULL && $this->CanShowPost($rp))?
  3475. $this->GenerateSinglePost($rp,true,false,false,true,true):$this->T("未找到该引用。")).
  3476. "</a></div>";
  3477. return $s;
  3478. },
  3479. $ht
  3480. );
  3481. return $ht;
  3482. }
  3483. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  3484. $generate_thumbs=false, $hide_long = false){
  3485. $this->ConvertPost($post);
  3486. if($generate_anchor){ $this->CreatePostAnchor($post); }
  3487. $ht = $post['html'];
  3488. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  3489. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  3490. "<p class='bold'>".$post['product']['title']."</p>".
  3491. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  3492. "<p class='smaller bold'>".$post['product']['price']."</p>";
  3493. return $ht;
  3494. }
  3495. if($hide_long){
  3496. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  3497. }else{
  3498. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  3499. }
  3500. if ($strip_tags){
  3501. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  3502. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  3503. $ht = $ht;
  3504. }
  3505. else{
  3506. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  3507. }
  3508. if ($strip_tags && $generate_thumbs){
  3509. $ht="<div class='hide_long'>".$ht."</div>";
  3510. if(isset($post['images']) && isset($post['images'][0])){
  3511. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  3512. foreach($post['images'] as $im){
  3513. $ht.="<li class='file_thumb'>".$im."</li>";
  3514. }
  3515. $ht.="</ul></div>";
  3516. }
  3517. }
  3518. return $ht;
  3519. }
  3520. function MakeSinglePostExp(&$post){ ?>
  3521. <li class='post post_dummy'>
  3522. <?=$this->GenerateSinglePost($post, false, false, true, false, false); ?>
  3523. </li>
  3524. <?php
  3525. }
  3526. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  3527. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  3528. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  3529. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  3530. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  3531. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  3532. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  3533. $title = $generate_anchor?$this->ChoosePartsByLanguage($this->GetPostTitle($post, true)):NULL;
  3534. $this->ConvertPost($post);// NEEDED FOR WIDE;
  3535. $is_wide = (isset($post['wide'])&&$post['wide']) || (isset($post['tid']) && isset($post['tid']['wide']) && $post['tid']['wide']);
  3536. ?>
  3537. <?=$title?"<div class='print_title'><h1>".$title."</h1></div>":""?>
  3538. <div class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>'
  3539. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  3540. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?>
  3541. <?=$is_wide?" style='column-span:all;'":"";?>>
  3542. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  3543. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  3544. <?php }
  3545. if(!$side && !$strip_tags && $show_link){?><div class='post_menu_button _menu_hook' >+</div><?php } ?>
  3546. <?php if(!$side && $show_link){ $ref_count=100; ?>
  3547. <a href='?post=<?=$post['id']?>' onclick="<?=$show_thread_link||isset($_GET['search'])?'ShowWaitingBar()':'ClickPost(this.parentNode,event,true)'?>">
  3548. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3549. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"")?>
  3550. </div>
  3551. </a><?php if($ref_count){ ?>
  3552. <label class='lb post_access' for='fake<?=$post["id"]?>'><div class='ref_count'><?=$ref_count?></div></label><?php }
  3553. } ?>
  3554. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  3555. <?php if(!$strip_tags){ $this->MakeLinkedPosts($post); } ?>
  3556. <div class='<?=$side?"":'post_width'?><?=$is_deleted?" deleted_post":""?>'>
  3557. <?php if($is_product&&!$generate_anchor){
  3558. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  3559. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  3560. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  3561. $generate_thumb,($show_thread_link||$side||$force_hide_long)); ?>
  3562. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  3563. </div>
  3564. <?=$side?"</a>":""?> <?php
  3565. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  3566. $post['tid']['first']['id']!=$post['id']){ ?>
  3567. <div class='gray smaller block opt_compact post'>
  3568. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>#423
  3569. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  3570. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  3571. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  3572. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true, true);?>
  3573. </div>
  3574. </div>
  3575. <?php }
  3576. if($show_reply_count && isset($post['tid'])){ ?>
  3577. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  3578. <?=$this->T('个回复')?></a>
  3579. <?php } ?>
  3580. </div>
  3581. <?php
  3582. }
  3583. function MakePostingFields($reply_to=NULL, $show_hint=false){
  3584. if(isset($this->WayBack)){ ?>
  3585. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  3586. <?php return; } ?>
  3587. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  3588. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  3589. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  3590. <div id='post_hint_modify' style='display:none;'>
  3591. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  3592. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  3593. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  3594. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  3595. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3596. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3597. onclick='ShowWaitingBar();' />
  3598. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3599. <div style='float:right;'>
  3600. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3601. <?=$this->T('清空')?></a>
  3602. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3603. </div>
  3604. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3605. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3606. <?php if($reply_to){ ?>
  3607. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3608. <?php } ?>
  3609. <?php
  3610. }
  3611. function MakeCommentPosts(){ global $INDEXPHP;
  3612. if(!$this->LoggedIn) return; ?>
  3613. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3614. <?php if(!$this->CommentEnabled){
  3615. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3616. <div class='comment'><ul>
  3617. <?php $i=0;
  3618. foreach(array_reverse($this->Posts) as $p){
  3619. if(!isset($p['comment_to'])) continue;
  3620. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3621. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3622. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3623. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3624. if(!$post_to) $post_title = "?";
  3625. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3626. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3627. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3628. "<a href='$INDEXPHP?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3629. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3630. $i++;
  3631. }
  3632. ?>
  3633. </ul><br /></div>
  3634. <?php
  3635. }
  3636. function MakeRecentPosts($search_term=NULL, $category=NULL){ global $INDEXPHP; ?>
  3637. <div class='center' id='div_center'><br class='hidden_on_print' />
  3638. <?php if(!isset($search_term) && !isset($category) &&
  3639. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3640. $this->CanShowPost($p)){
  3641. ?><ul class='print_column list bkg_section'><?php
  3642. $this->MakeSinglePost($p, true, false, "active_post", false, true, false, false, false, true, false);
  3643. ?></ul><br /><?php
  3644. }?>
  3645. <h2><?=isset($search_term)?$this->T('搜索'):
  3646. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3647. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3648. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3649. ($this->LoggedIn?"<a href='$INDEXPHP?comments=all'>@</a> <a href='$INDEXPHP?statistics=all'>%</a>":"")."</span>")?></h2><br />
  3650. <?php if(isset($search_term)){ ?>
  3651. <form action="<?=$INDEXPHP?>" method="post" style='display:none;' id='search_form'></form>
  3652. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3653. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3654. <?php }else if(isset($category)){ ?>
  3655. <div></div>
  3656. <?php }else if($this->LoggedIn){ ?>
  3657. <div class='post_box_top _input_bundle'>
  3658. <?php $this->MakePostingFields(NULL,false); ?>
  3659. </div>
  3660. <?php } ?>
  3661. <ul class='print_column list bkg_recent'>
  3662. <?php
  3663. $i = 0; $last_end_wide = true;
  3664. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3665. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3666. if(isset($p['tid'])){ /* Should always be set. */
  3667. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3668. if(!isset($search_term)) { $p = &$th['last']; }
  3669. }
  3670. if(isset($search_term)){
  3671. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3672. }else if(isset($category)){
  3673. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3674. (isset($p['categories'])?($p['categories']):[]);
  3675. if ($category=='none') { if($cat!=[]) continue; }
  3676. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3677. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3678. }else{
  3679. if(in_array($p['id'],
  3680. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  3681. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3682. }
  3683. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3684. if($last_end_wide){$use_class="last_wide";}else{$use_class="";}
  3685. $this->MakeSinglePost($p, true, false, $use_class, false, !isset($search_term), false, false, false, false, isset($search_term));
  3686. $i++;
  3687. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3688. $last_end_wide = sizeof($p['tid']['arr'])==1 && isset($p['end_wide']) && $p['end_wide'];
  3689. }?>
  3690. </ul>
  3691. <div class='page_selector clean_a'>
  3692. <hr />
  3693. <a <?=$this->CurrentOffset>0?("href='".$INDEXPHP."?offset=".($this->CurrentOffset-1).
  3694. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3695. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3696. <?=$this->CurrentOffset+1?>
  3697. <a href='<?=$INDEXPHP?>?offset=<?=($this->CurrentOffset+1).
  3698. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3699. → <?=$this->T('下一页')?></a>
  3700. </div>
  3701. </div>
  3702. <?php
  3703. }
  3704. function MakeLinkedPosts(&$p){
  3705. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); if(!$has_ref)return; $count=0;?>
  3706. <input type='checkbox' class='lpctrl' id='fake<?=$p["id"]?>' checked='checked'>
  3707. <div class='linked_posts smaller'>
  3708. <ul><?php $count_product=0;
  3709. foreach(array_reverse($p['refs']) as &$pr){
  3710. $po = $this->GetPost($pr);
  3711. if(!$this->CanShowPost($po)){ continue; } $count++;
  3712. $this->MakeSinglePost($po, false, true, "post_preview invert_a", true, false, false, false, true, false, false);
  3713. }
  3714. ?></ul>
  3715. </div>
  3716. <?php
  3717. }
  3718. function MakeLinkedPostsExp(&$p){
  3719. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3720. <div class='center_exp post_dummy smaller'>
  3721. <hr />
  3722. <?php if(!$this->InExperimentalMode){ ?>
  3723. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3724. <?php if($has_ref){ ?>
  3725. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3726. <ul><?php $count_product=0;
  3727. foreach(array_reverse($p['refs']) as &$pr){
  3728. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3729. "</a></li>";
  3730. }
  3731. ?></ul>
  3732. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3733. }else{ ?>
  3734. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3735. <?php } }?>
  3736. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3737. </div>
  3738. <?php
  3739. }
  3740. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3741. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3742. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3743. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3744. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3745. if(!isset($title)) $title=$this->T('未命名');
  3746. if(!isset($ah)){ ?>
  3747. <h2><?=$this->T('没有历史记录')?></h2>
  3748. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3749. <?php }else{ ?>
  3750. <h2><?=$this->T('历史记录')?></h2>
  3751. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3752. <div class='list'><ul>
  3753. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3754. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3755. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3756. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3757. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3758. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3759. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3760. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3761. <?=$this->GetPostTitle($ver);?></a>
  3762. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3763. <?php } ?></ul><?php } ?>
  3764. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3765. $mah = &$this->GetArchiveHandle($pm);
  3766. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3767. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3768. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3769. <?php } ?>
  3770. </li><?php } ?>
  3771. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3772. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3773. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3774. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3775. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3776. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3777. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3778. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3779. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3780. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3781. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3782. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3783. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3784. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3785. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3786. <?=$this->GetPostTitle($ver);?></a>
  3787. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3788. <?php } ?></ul></li><?php } ?>
  3789. <?php } ?></ul></div>
  3790. <?php } ?>
  3791. <?php
  3792. }
  3793. function MakePostDiff(&$this_ver, &$last_ver){
  3794. if(!isset($this_ver)){ ?>
  3795. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3796. <?php }else{ ?>
  3797. <h2><?=$this->T('差异')?></h2>
  3798. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3799. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3800. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3801. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3802. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3803. <?php }else{ ?>
  3804. <table class='diff_table'><thead>
  3805. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3806. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3807. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3808. </thead><tbody>
  3809. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3810. </tbody>
  3811. </table>
  3812. <?php } ?>
  3813. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3814. <?php } ?>
  3815. <?php
  3816. }
  3817. function MakePostHistory(&$post, $version=NULL){
  3818. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3819. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3820. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3821. ?>
  3822. <div class='left mobile_fold history' id='div_left'>
  3823. <?php if (isset($version)){
  3824. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3825. }else{ echo "&nbsp;"; } ?>
  3826. </div>
  3827. <div class='center history' id='div_center'>
  3828. <?php if (!isset($version)){
  3829. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3830. }else{
  3831. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3832. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3833. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3834. $this->MakePostDiff($this_ver, $last_ver, $p);
  3835. } ?>
  3836. </div>
  3837. <?php
  3838. }
  3839. function MakeCommentSection(&$post){ global $INDEXPHP;
  3840. if(!$this->CommentEnabled){ return; }
  3841. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3842. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3843. ?><div class='comment'>
  3844. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3845. <?php if($comment_count) { echo "<ul>";
  3846. foreach($to_post['comments'] as $p){
  3847. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3848. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3849. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3850. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3851. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3852. }
  3853. echo "</ul>";
  3854. } else {
  3855. echo $this->T('还没有评论');
  3856. } ?>
  3857. <div class='hidden_on_print'>
  3858. <div class='spacer'></div>
  3859. <form action="<?=$INDEXPHP?>?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3860. method="post" style="display:none;" id="comment_form"></form>
  3861. <p><a class='text_highlight bold clean_a'
  3862. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3863. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3864. <div id='comment_box' style='display:none;'>
  3865. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3866. <table style='white-space:nowrap;'>
  3867. <tr><td colspan='2'>
  3868. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3869. oninput="CommentUpdated();" ></textarea>
  3870. </td></tr>
  3871. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3872. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3873. class='full_box' oninput="CommentUpdated();" /></td>
  3874. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3875. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3876. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3877. <tr><td colspan='2'>
  3878. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3879. class='full_box' oninput="CommentUpdated();" />
  3880. </td></tr>
  3881. <tr><td colspan='2'>
  3882. <div class='spacer'></div>
  3883. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3884. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3885. </td></tr>
  3886. </table></div>
  3887. <script>
  3888. const IsValidEmail = (email) => {
  3889. return String(email).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
  3890. };
  3891. function IsValidHttpUrl(string) {
  3892. let url; try{ url = new URL(string); } catch (_) { return false; }
  3893. return url.protocol === "http:" || url.protocol === "https:";
  3894. }
  3895. var cbox = document.getElementById('comment_box');
  3896. var cemail = document.getElementById('comment_email');
  3897. var cname = document.getElementById('comment_name');
  3898. var clink = document.getElementById('comment_link');
  3899. var cconfirm = document.getElementById('comment_confirm');
  3900. function CommentUpdated(){
  3901. cconfirm.disabled=true;
  3902. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3903. cbox.innerText.length>2 && cname.value.length>2 &&
  3904. clink.value=="" || IsValidHttpUrl(clink.value)){
  3905. cconfirm.removeAttribute("disabled");
  3906. }
  3907. }
  3908. CommentUpdated();
  3909. </script>
  3910. </div>
  3911. </div>
  3912. <?php
  3913. }
  3914. function MakeInterestingSection(&$th){
  3915. $this->Anchors = [];
  3916. $c = &$th['first']['content'];
  3917. $this->ConvertPost($th['first']);
  3918. $ht = $th['first']['html'];
  3919. ?>
  3920. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3921. <div class='center_full' id='div_center'>
  3922. <?php $this->MakePostTools(); ?>
  3923. <?php $cat = NULL;
  3924. if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; }
  3925. if($cat){ ?>
  3926. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3927. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3928. <?php } ?>
  3929. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3930. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3931. <ul><li class='post' data-post-id='<?=$th['first']['id']?>'>
  3932. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3933. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3934. <?php foreach($th['first']['refs'] as $ref){
  3935. $po = $this->GetPost($ref);
  3936. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3937. if(!$this->CanShowPost($po)){ continue; }
  3938. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3939. } ?>
  3940. </ul><?php } ?>
  3941. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3942. <div class='hidden_on_print'><br />
  3943. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3944. </div>
  3945. <?php } ?>
  3946. <table><thead><tr><?php foreach($th['interesting'] as $header){ ?>
  3947. <td><?=$this->T($header);?></td>
  3948. <?php } ?><td></td></tr></thead><tbody class='interesting_tbody'>
  3949. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3950. foreach($plist as &$p){
  3951. $this->ConvertPost($p);
  3952. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3953. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3954. $is_current = $p['id']==$this->CurrentPostID;
  3955. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3956. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3957. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3958. onDblClick='ClickImage(this)'><td>
  3959. <?php if($ref_count){ ?>
  3960. <div class='post_access ref_count'><?=$ref_count?></div>
  3961. <?php } ?></a>
  3962. <?=$p['html'];?>
  3963. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a>
  3964. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3965. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3966. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3967. </div></td></tr>
  3968. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3969. <?php foreach($p['refs'] as $ref){
  3970. $po = $this->GetPost($ref);
  3971. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3972. if(!$this->CanShowPost($po)){ continue; }
  3973. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3974. } ?>
  3975. </ul></td></tr><?php } ?>
  3976. <?php } ?>
  3977. </tbody></table>
  3978. </li></ul>
  3979. <br />
  3980. <?php $this->MakeCommentSection($th['first']); ?>
  3981. </div>
  3982. <?php return true;
  3983. }
  3984. function CssNumberID($id){
  3985. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3986. }
  3987. function MakePostTools(){
  3988. if($this->LoggedIn && !isset($this->WayBack)){ $STR=<<<EOT
  3989. <div class='smaller gray hidden_on_print clean_a'>
  3990. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3991. {$this->T('工具')}</a>:<div class='hidden_m' style='display:inline'>
  3992. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'>{$this->T('合并帖子')}</a></span>
  3993. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'>{$this->T('合并话题')}</a></span>
  3994. </div>
  3995. <select class='hidden_on_desktop' id='merge_select'
  3996. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3997. <option value='-1' selected>--</option>
  3998. <option value='1'>{$this->T('合并帖子')}</option>
  3999. <option value='2'>{$this->T('合并话题')}</option></select>
  4000. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  4001. <div style='display:inline;'>{$this->T('将合并')} <span id='merge_post_count'></span> {$this->T('个帖子')}</div>
  4002. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;{$this->T('执行')}</a></span></div>
  4003. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  4004. <div style='display:inline;'>{$this->T('合并到话题')}</div>
  4005. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  4006. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;{$this->T('执行')}</a></span></div>
  4007. </div><div class='spacer hidden_on_print'></div>
  4008. EOT;
  4009. }
  4010. $this->TFill(2,$STR); $this->TRow();
  4011. }
  4012. function MakeSidebar(){ ?>
  4013. <div class='left mobile_fold'><?php if(isset($this->SpecialSidebar) && ($p = &$this->GetPost($this->SpecialSidebar))!=NULL){
  4014. ?><span class='gray smaller'><br /></span><?php
  4015. //echo $this->GenerateSinglePost($p, false, false, false, false);
  4016. }?>
  4017. <div class='wayback_link clean_a smaller'><span class='gray'><br /><?=$this->T('工具')?></span><ul>
  4018. <li><a href='?search=' onclick='ShowWaitingBar()' class='bigger'><?=$this->T('搜索')?></a></li>
  4019. <li><?php if(!isset($this->WayBack)){ ?>
  4020. <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  4021. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?></li>
  4022. <li><a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  4023. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a></li>
  4024. <li><a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a></li>
  4025. </ul>
  4026. </div>
  4027. <?php if($this->NewsletterEnabled){ $STR=$this->MakeSubscription(1); echo $STR; }?>
  4028. <br />
  4029. <hr class="hidden_on_desktop" />
  4030. </div>
  4031. <?php }
  4032. function MakePostSection(&$post){ $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1;
  4033. $this->Anchors = []; if(isset($post['slides']) || ($is_thread&&isset($post['tid']['slides']))) $centerclass='center_slides'; else $centerclass='center';
  4034. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  4035. <div class='<?=$centerclass;?>' id='div_center'><br class='hidden_on_print' />
  4036. <h2 class='hidden_on_print'>
  4037. <?php $th=NULL;
  4038. $is_wide = (isset($post['wide'])&&$post['wide']) || ($is_thread && isset($post['tid']['wide']) && $post['tid']['wide']);
  4039. if($is_thread){ $th = $post['tid'];?> <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  4040. <?php } ?></h2>
  4041. <?php $cat = NULL;
  4042. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  4043. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  4044. $this->MakePostTools();
  4045. if($cat){ ?>
  4046. <p class='hidden_on_print'><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  4047. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  4048. <?php } ?><br class='hidden_on_print' />
  4049. <ul class='print_column bkg_section'>
  4050. <?php $is_reversed=false;
  4051. if($is_thread){
  4052. $use_arr = $th['arr']; $hinted=false;
  4053. $last_end_wide = true; $is_reversed=$this->IsReversedThread($th);
  4054. foreach($use_arr as &$p){$use_class="";if($p==$post){$use_class.=" active_post";}
  4055. if($last_end_wide){$use_class.=" last_wide";}
  4056. $make_title = ($p == $post);
  4057. if(isset($p['restart'])){ ?>
  4058. <li class='restart'><h3><?=$p['restart']?></h3></li><?php }
  4059. $this->MakeSinglePost($p,true,false,$use_class,false, false, false, true, false, false);
  4060. if($make_title){?>
  4061. <script>
  4062. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  4063. </script>
  4064. <?php } if($is_reversed && !$hinted){ ?><?php $hinted = true;
  4065. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4066. <div class='hidden_on_print'>
  4067. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  4068. <?php } }
  4069. $last_end_wide = isset($p['end_wide']) && $p['end_wide'];
  4070. }
  4071. }else{
  4072. $this->MakeSinglePost($post,true, false,"active_post",false, false, false, true, false, false);
  4073. ?><script>
  4074. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($post),0,100)))?>";
  4075. </script><?php
  4076. } $class_add=""; if(isset($post['tid']['first']['no_time'])){ $class_add=' hidden_on_print'; } ?>
  4077. </ul>
  4078. <div class='smaller align_right<?=$class_add;?>'>
  4079. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  4080. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  4081. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  4082. </div>
  4083. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  4084. <div class='hidden_on_print'>
  4085. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  4086. </div>
  4087. <?php }
  4088. $this->MakeCommentSection($post);
  4089. ?>
  4090. </div>
  4091. <?php if(isset($post['slides']) || ($is_thread&&isset($post['tid']['slides']))){ ?>
  4092. <div class='slides_buttons code' onclick="event.stopPropagation();">
  4093. <a onclick="SlidesFontCheck(-1)">T-</a> <a onclick="SlidesFontCheck(1)">T+</a>&nbsp;
  4094. <a onclick="SlidesStart(null)"><<</a> <a onclick="SlidesCheck(-1);"><</a>
  4095. <a onclick="SlidesStart(1)"><span id="slides_now">1</span>/<span id="slides_total">1</span></a>
  4096. <a onclick="SlidesCheck(1);">></a> <a onclick="SlidesEnd();">X</a>
  4097. </div>
  4098. <script>
  4099. function SlidesStart(from_here){
  4100. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return;
  4101. sdone=0; fp=0; if(from_here){
  4102. urlParams = new URLSearchParams(window.location.search);
  4103. fp = urlParams.get('post');
  4104. }
  4105. document.querySelector("#slides_total").innerText=slides.length; cur=document.querySelector("#slides_now");
  4106. for(i=0;i<slides.length;i++){ slides[i].style.display="none";
  4107. if(from_here && slides[i].dataset.postId==fp){ slides[i].style.display="table-cell";sdone=1; ClickPost(slides[i],0,true); cur.innerText=i+1; }
  4108. } if(!sdone){ slides[0].style.display="table-cell"; ClickPost(slides[0],0,true); cur.innerText=1; }
  4109. c=document.querySelector('.center'); if(!c) return;
  4110. c.classList.remove('center'); c.classList.add('center_slides'); if(c.dataset.fontSize){ c.style.fontSize=c.dataset.fontSize; }
  4111. c=document.querySelector('.left'); if(!c) return; c.style.display="none";
  4112. }
  4113. function SlidesCheck(offset){
  4114. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return; cur=document.querySelector("#slides_now");
  4115. for(i=0;i<slides.length;i++){ if(slides[i].style.display=="table-cell" && slides[i+offset] && (i+offset)>=0){
  4116. slides[i+offset].style.display="table-cell"; slides[i].style.display="none"; ClickPost(slides[i+offset],0,true); cur.innerText=i+offset+1; break;
  4117. }
  4118. }
  4119. }
  4120. function SlidesFontCheck(offset){
  4121. c=document.querySelector('.center_slides'); if(!c) return;
  4122. f=5; if(c.style.fontSize){ f=parseInt(c.style.fontSize); }
  4123. f+=offset; if(f<=0) f=1; if(f>12) f=12; c.style.fontSize=""+f+"vmin"; c.dataset.fontSize=c.style.fontSize;
  4124. }
  4125. function SlidesEnd(){
  4126. c=document.querySelector('.center_slides'); if(!c) return;
  4127. c.classList.remove('center_slides'); c.classList.add('center'); c.style.fontSize="";
  4128. c=document.querySelector('.left'); if(!c) return; c.style.display="inline-block";
  4129. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return;
  4130. for(i=0;i<slides.length;i++){ slides[i].style.display=""; }
  4131. }
  4132. //document.addEventListener("wheel", function(event){ if(event.deltaY>0) SlidesCheck(1); else SlidesCheck(-1); }, { passive: false });
  4133. document.addEventListener("click", function(event){ SlidesCheck(1); });
  4134. document.addEventListener('keydown', function(event) {
  4135. const key = event.key; // "ArrowRight", "ArrowLeft", "ArrowUp", or "ArrowDown"
  4136. switch(key){
  4137. case "ArrowUp": case "ArrowLeft": SlidesCheck(-1); break; case "ArrowDown": case "ArrowRight": SlidesCheck(1); break;
  4138. case "Escape": SlidesEnd(); break;
  4139. }
  4140. });
  4141. </script>
  4142. <?php }
  4143. }
  4144. function MakePostSectionExp(&$post){
  4145. $this->Anchors = []; $is_thread = isset($post['tid']);
  4146. ?>
  4147. <div class='center_exp' id='div_center'><br class='hidden_on_print' />
  4148. <ul>
  4149. <?php $is_reversed=false;
  4150. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false;
  4151. foreach($use_arr as &$p){
  4152. $this->MakeSinglePostExp($p);
  4153. if($p == $th['first']){?>
  4154. <script>
  4155. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  4156. </script>
  4157. <?php } if($is_reversed && !$hinted){ ?>
  4158. <li class='gray smaller bold' style='text-align:center;'>
  4159. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  4160. <?php $hinted = true; }
  4161. }
  4162. }else{
  4163. $this->MakeSinglePostExp($post);
  4164. ?><!--<script>
  4165. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  4166. </script>--><?php
  4167. } ?>
  4168. </ul>
  4169. </div>
  4170. <?php
  4171. }
  4172. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  4173. <div class='here_image_box clean_a'>
  4174. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  4175. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  4176. <?php if($image_okay){ ?>
  4177. <?php if(isset($im['video']) && isset($im['video'])!=""){ ?>
  4178. <video controls><source src='<?=$im['file'];?>' type='<?=$im['video']?>'></video>
  4179. <?php }else{ ?>
  4180. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  4181. <?php } ?>
  4182. <?php } $this->MakeHereButtons($im, false); ?>
  4183. </div>
  4184. <?php }
  4185. function MakeSideGalleryCode(){?>
  4186. <div>
  4187. <h3><?=$this->T('点击图片以插入:')?></h3>
  4188. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  4189. <option value="main"><?=$this->T('全部')?></option>
  4190. <?php if($this->LoggedIn){ ?>
  4191. <option value="trash"><?=$this->T('垃圾桶')?></option>
  4192. <?php }?>
  4193. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  4194. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  4195. <?php } ?>
  4196. </select>
  4197. <div id='side_gallery'>
  4198. </div>
  4199. </div>
  4200. <script>
  4201. function InsertImage(imgname){
  4202. t = document.querySelector("#post_content");
  4203. v = t.value;
  4204. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  4205. la_auto_grow(t);
  4206. }
  4207. function RefreshSideGallery(){
  4208. let xhr = new XMLHttpRequest();
  4209. xhr.onreadystatechange = (function(){
  4210. if (this.readyState === this.DONE) {
  4211. if (this.status === 200) {
  4212. ind = document.querySelector("#side_gallery");
  4213. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  4214. str = "<ul class='side_thumb'>"
  4215. for (const m of res) {
  4216. imgstr = "<img src='"+m[2]+"' />";
  4217. if(m[2].match('\.mp4')){
  4218. imgstr = "<video><source src='"+m[2]+"'></video>";
  4219. }
  4220. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+imgstr+"</div>"
  4221. }
  4222. str += "</ul>"
  4223. ind.innerHTML = str;
  4224. }
  4225. }
  4226. }
  4227. });
  4228. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  4229. xhr.send();
  4230. }
  4231. </script>
  4232. <?php
  4233. }
  4234. function MakeUploader($is_side=false){ ?>
  4235. <div id='upload_operation_area' class='hidden_on_print'>
  4236. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  4237. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  4238. <ul id='file_list'>
  4239. </ul>
  4240. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  4241. </div>
  4242. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  4243. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  4244. <script>
  4245. function pastehandler(event){
  4246. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  4247. for (index in items) {
  4248. var item = items[index];
  4249. if (item.kind === 'file') {
  4250. put = document.querySelector("#_uploader");
  4251. if(put) ShowSideUploader();
  4252. var blob = item.getAsFile();
  4253. AddImageFile(blob);
  4254. return;
  4255. }
  4256. }
  4257. }
  4258. let _fd_list = []; var uploading=0;
  4259. let hint=document.querySelector('#upload_hint');
  4260. function ToggleCompress(button){
  4261. li = button.parentNode;
  4262. num=li.dataset.number;
  4263. for(i=0;i<_fd_list.length;i++){
  4264. if (_fd_list[i][0] == num){
  4265. state = _fd_list[i][2];
  4266. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  4267. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  4268. }
  4269. }
  4270. }
  4271. function RemoveFromUpload(button){
  4272. li = button.parentNode;
  4273. num=li.dataset.number;
  4274. for(i=0;i<_fd_list.length;i++){
  4275. if (_fd_list[i][0] == num){
  4276. _fd_list.splice(i, 1);break;
  4277. }
  4278. }
  4279. li.parentNode.removeChild(li);
  4280. }
  4281. function EndThisUpload(){
  4282. unfinished = 0;
  4283. for(i=0;i<_fd_list.length;i++){
  4284. if (_fd_list[i][3]==0){
  4285. unfinished=1;
  4286. }
  4287. }
  4288. if(!unfinished){
  4289. uploading=0;
  4290. hint.innerHTML="<?=$this->T('上传完成。')?>";
  4291. cl=document.querySelector('#upload_click');
  4292. if(!cl.dataset.isSide){
  4293. cl.innerHTML="<?=$this->T('刷新页面')?>";
  4294. cl.href=window.location.href;
  4295. }else{
  4296. _fd_list.splice(0,_fd_list.length);
  4297. fl = document.querySelector("#file_list");
  4298. fl.innerHTML = "";
  4299. list=document.querySelector('#upload_operation_area');
  4300. list.style.pointerEvents='';
  4301. list.style.opacity='';
  4302. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  4303. document.onpaste=pastehandler;
  4304. RefreshSideGallery();
  4305. }
  4306. }
  4307. }
  4308. function UploadList(){
  4309. if(!_fd_list.length || uploading) return;
  4310. uploading=1;
  4311. hint.innerHTML="<?=$this->T('正在上传...')?>";
  4312. list=document.querySelector('#upload_operation_area');
  4313. list.style.pointerEvents='none';
  4314. list.style.opacity='0.5';
  4315. document.onpaste="";
  4316. for(i=0;i<_fd_list.length;i++){
  4317. let xhr = new XMLHttpRequest();
  4318. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  4319. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  4320. function wrap(li, i){
  4321. var ind = li.querySelector('._compress_toggle')
  4322. return function(){
  4323. if (this.readyState === this.DONE) {
  4324. if (this.status === 200) {
  4325. var response = xhr.responseText;
  4326. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  4327. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  4328. _fd_list[i][3] = 1;
  4329. }else{
  4330. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  4331. _fd_list[i][3] = 1;
  4332. }
  4333. EndThisUpload();
  4334. }
  4335. }
  4336. }
  4337. }
  4338. xhr.onreadystatechange = wrap(li, i);
  4339. xhr.send(_fd_list[i][1]);
  4340. }
  4341. }
  4342. function AddImageFile(blob){
  4343. var ext="";
  4344. if(blob.name.match(/png$/i))ext = 'png';
  4345. else if(blob.name.match(/jpg$/i))ext = 'jpg';
  4346. else if(blob.name.match(/jpeg$/i))ext = 'jpeg';
  4347. else if(blob.name.match(/gif$/i))ext = 'gif';
  4348. else if(blob.name.match(/mp4$/i))ext = 'mp4';
  4349. else return;
  4350. var fd = new FormData();
  4351. blob.name = blob.name=generateUID().toString();
  4352. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  4353. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  4354. var reader = new FileReader();
  4355. reader.onload = function(event){
  4356. fl = document.querySelector("#file_list");
  4357. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  4358. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  4359. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  4360. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  4361. fl.innerHTML+=ht;
  4362. };
  4363. reader.readAsDataURL(blob);
  4364. }
  4365. sel = document.querySelector('#upload_selector');
  4366. sel.addEventListener("change", function(){
  4367. var input = this;
  4368. function ff(file){
  4369. return function(e){
  4370. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  4371. blob.name = file.name;
  4372. AddImageFile(blob);
  4373. }
  4374. }
  4375. for(i=0;i<input.files.length;i++){
  4376. if(input.files[i].size){
  4377. let reader = new FileReader();
  4378. reader.onload = ff(input.files[i]);
  4379. reader.readAsArrayBuffer(input.files[i]);
  4380. }
  4381. }
  4382. });
  4383. function generateUID() {
  4384. var firstPart = (Math.random() * 46656) | 0;
  4385. var secondPart = (Math.random() * 46656) | 0;
  4386. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  4387. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  4388. return firstPart + secondPart;
  4389. }
  4390. document.onpaste = pastehandler;
  4391. function dropHandler(ev) {
  4392. put = document.querySelector("#_uploader");
  4393. if(put) ShowSideUploader();
  4394. bkg=document.querySelector('#dropping_background');
  4395. bkg.style.display="none";
  4396. console.log('File(s) dropped');
  4397. ev.preventDefault();ev.stopPropagation();
  4398. if (ev.dataTransfer && ev.dataTransfer.items) {
  4399. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  4400. if (ev.dataTransfer.items[i].kind === 'file') {
  4401. var file = ev.dataTransfer.items[i].getAsFile();
  4402. function ff(file){
  4403. return function(e){
  4404. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  4405. blob.name = file.name;
  4406. AddImageFile(blob);
  4407. }
  4408. }
  4409. if(file){
  4410. let reader = new FileReader();
  4411. reader.onload = ff(file);
  4412. reader.readAsArrayBuffer(file);
  4413. }
  4414. }
  4415. }
  4416. } else {
  4417. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  4418. function ff(file){
  4419. return function(e){
  4420. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  4421. blob.name = file.name;
  4422. AddImageFile(blob);
  4423. }
  4424. }
  4425. if(ev.dataTransfer.files[i].size){
  4426. let reader = new FileReader();
  4427. reader.onload = ff(ev.dataTransfer.files[i]);
  4428. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  4429. }
  4430. }
  4431. }
  4432. }
  4433. function dragOverHandler(ev) {
  4434. bkg=document.querySelector('#dropping_background');
  4435. bkg.style.display="";
  4436. console.log('File(s) in drop zone');
  4437. ev.preventDefault();
  4438. }
  4439. </script>
  4440. <?php
  4441. }
  4442. function CanShowGallery(&$g){
  4443. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  4444. return true;
  4445. }
  4446. function CanShowImage(&$im){
  4447. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  4448. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  4449. }
  4450. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  4451. return true;
  4452. }
  4453. function GetImageBatch($from,$show_all){
  4454. if(!isset($_GET['gallery'])) return;
  4455. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){$name=$_GET['gallery'];}
  4456. $reached=0; $count=0;
  4457. if(isset($this->Images[0])) foreach($this->Images as $im){
  4458. if(isset($from)&&!$reached){ if($from==$im['name']){ $reached=1; } continue; }
  4459. if(!$this->CanShowImage($im)){ continue; }
  4460. if($_GET['gallery']=='trash') $name='trash';
  4461. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;} ?>
  4462. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  4463. <?php if($this->LoggedIn){ ?>
  4464. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  4465. <?php } ?>
  4466. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  4467. <?php if(isset($im['video']) && $im['video']!=""){ ?>
  4468. <video data-imgsrc='<?=$im["name"]?>'><source src='<?=$im['file']?>' type='<?=$im['video']?>'></video>
  4469. <?php }else{ ?>
  4470. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  4471. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  4472. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>
  4473. <?=isset($im['align'])?'data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':""?>/>
  4474. <?php } ?>
  4475. </a>
  4476. </div>
  4477. <?php $count+=isset($im['parent'])?0:1; if((!$show_all)&&($count>=$this->GalleryStep)){ break; }
  4478. }
  4479. if($count<$this->GalleryStep){ ?><div style='display:none'>END_GALLERY</div><?php return 0; }
  4480. return 1;
  4481. }
  4482. function MakeGallerySection(){ global $INDEXPHP;
  4483. if(!isset($_GET['gallery'])) return;
  4484. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){ $name=$_GET['gallery'];}
  4485. $show_all=0; if(isset($_GET['show_all']) && $_GET['show_all']!='0'){ $show_all=1; } ?>
  4486. <script>
  4487. document.title+=" | <?=$this->T('画廊')?>";
  4488. </script>
  4489. <div class='center_wide' id='div_center' style='position:relative;'><br class='hidden_on_print' />
  4490. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  4491. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  4492. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  4493. <?php $description=(isset($gal) && isset($gal['description']))?$gal['description']:null; ?>
  4494. <div class='hidden_on_desktop'>
  4495. <?=$this->T('前往')?>
  4496. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  4497. <optgroup label="<?=$this->T('精选')?>">
  4498. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4499. if(!isset($g['featured']) || !$g['featured'] ||
  4500. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  4501. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  4502. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  4503. <?php } ?></optgroup><optgroup label="<?=$this->T('其他相册')?>">
  4504. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  4505. <?php if($this->LoggedIn){ ?>
  4506. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  4507. <?php } ?>
  4508. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4509. if((isset($g['featured']) && $g['featured']) ||
  4510. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  4511. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  4512. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  4513. <?php } ?></optgroup>
  4514. </select>
  4515. </div>
  4516. <?php if($this->LoggedIn){?>
  4517. <div>
  4518. <?php if(isset($name)){ ?>
  4519. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  4520. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  4521. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  4522. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  4523. <?=$this->T('取消精选')?></a>
  4524. <?php }else{ ?>
  4525. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  4526. <?=$this->T('设为精选')?></a>
  4527. <?php } ?><br />
  4528. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  4529. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  4530. <?=$this->T('取消实验')?></a>
  4531. <?php }else{ ?>
  4532. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  4533. <?=$this->T('设为实验')?></a>
  4534. <?php } ?>
  4535. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  4536. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  4537. <a href='javascript:HidePopMenu();'>×</a>
  4538. <hr />
  4539. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  4540. </div>
  4541. </div>
  4542. <?php } ?>
  4543. <?php $this->MakeUploader(false); ?>
  4544. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  4545. <div style='position:relative'>
  4546. <?php if(isset($name)){ ?>
  4547. <a href='javascript:ShowGalleryEditMenu("<?=$name?>",null)'><?=$this->T('改名')?></a>
  4548. <a href='javascript:ShowGalleryEditMenu("<?=$name?>","<?=$description?>")'><?=$this->T('描述')?></a>
  4549. <?php } ?>
  4550. <a href='javascript:ShowGalleryEditMenu(null,null)'><?=$this->T('添加')?></a>
  4551. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  4552. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  4553. method="post" style='display:none;' id='gallery_edit_form'></form>
  4554. <a style='float:left;'><?=$this->T('设置为:')?></a>
  4555. <a href='javascript:HidePopMenu();'>×</a>
  4556. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  4557. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  4558. <input type='text' form='gallery_edit_form' name='gallery_edit_description' id='gallery_edit_description' style='width:10em;display:none'>
  4559. <input class='button' type='submit' form='gallery_edit_form'
  4560. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  4561. </div>
  4562. </div>
  4563. </div>
  4564. <div class='smaller hidden_on_print'>
  4565. <form action="<?=$_SERVER['REQUEST_URI']?>"
  4566. method="post" style='display:none;' id='gallery_move_form'></form>
  4567. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  4568. id='gallery_move_ops' style='display:none'>
  4569. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  4570. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  4571. <p><?=$this->T('添加到')?>
  4572. <select id="gallery_move_to">
  4573. <option value="trash"><?=$this->T('垃圾桶')?></option>
  4574. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  4575. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  4576. <?php } ?>
  4577. </select>
  4578. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  4579. </p>
  4580. <p>
  4581. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  4582. </p>
  4583. </div>
  4584. </div>
  4585. <?php } $desc=isset($description)?$this->GetPost($description):null;
  4586. if(isset($desc)){ ?><ul class='print_column list'><br /><?php
  4587. $this->MakeSinglePost($desc, false, false, false, false, false, false, false, false, true, false);
  4588. ?></ul><?php } ?>
  4589. <br />
  4590. <div><div class='p_row'><?php $has_more=$this->GetImageBatch(NULL, $show_all);?>
  4591. <div class='p_thumb p_thumb_end' <?=$has_more?"onclick='ThisGetMore(this);'":""?>>
  4592. <a onclick='event.preventDefault();' href='<?=$INDEXPHP?>?gallery=<?=$_GET['gallery']?>&show_all=1'>
  4593. <h2 id="btn_more_images"><?=$has_more?$this->T("查看更多"):$this->T("没有更多的了");?></a></h2></div></div>
  4594. </div>
  4595. </div>
  4596. <script type='text/javascript'>
  4597. function ThisGetMore(end_ui){
  4598. var xhr = new XMLHttpRequest();
  4599. xhr.onreadystatechange = function() {
  4600. if (this.readyState == 4 && this.status == 200) {
  4601. doc = document.createElement("div"); doc.innerHTML=xhr.responseText.trim(); next_child=null;
  4602. for(child=doc.firstChild; child!==null; child=next_child) { next_child=child.nextSibling; end_ui.parentNode.insertBefore(child,end_ui); }
  4603. doc.remove();
  4604. if(xhr.responseText.search('END_GALLERY')>=0){ end_ui.onclick=null; end_ui.innerHTML="<h2><?=$this->T("没有更多的了");?></h2>"; }
  4605. UpdateImageClickables();
  4606. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("查看更多");?>";
  4607. }
  4608. };
  4609. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("稍等");?>";
  4610. im=end_ui.previousElementSibling.querySelector('img,video');
  4611. from=im?im.dataset.imgsrc:null; if(!from) return;
  4612. const urlParams = new URLSearchParams(window.location.search); const gallery = urlParams.get('gallery')
  4613. xhr.open("GET", "<?=$INDEXPHP?>?gallery_continue="+from+'&gallery='+gallery, true);
  4614. xhr.send();
  4615. }
  4616. <?php if($this->LoggedIn){ ?>
  4617. var selected_image = new Array();
  4618. function RemoveFromGallery(){
  4619. form = document.querySelector('#gallery_move_form');
  4620. ops = document.querySelector('#gallery_move_ops');
  4621. sel = document.querySelector('#gallery_move_to');
  4622. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  4623. form.submit();
  4624. }
  4625. function AddToGallery(){
  4626. form = document.querySelector('#gallery_move_form');
  4627. ops = document.querySelector('#gallery_move_ops');
  4628. sel = document.querySelector('#gallery_move_to');
  4629. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  4630. form.submit();
  4631. }
  4632. function ClearSelectedImages(){
  4633. selected_image.splice(0, selected_image.length);
  4634. checks = document.querySelectorAll('._select_hook');
  4635. [].forEach.call(checks, function(c){
  4636. c.classList.remove('p_thumb_selected');
  4637. });
  4638. count = document.querySelector('#gallery_selected_count');
  4639. count.innerHTML="0";
  4640. }
  4641. function ToggleSelectImage(elem, name){
  4642. count = document.querySelector('#gallery_selected_count');
  4643. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  4644. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  4645. count.innerHTML=selected_image.length.toString()
  4646. }
  4647. function ShowGalleryEditMenu(old_name,desc){
  4648. m = document.querySelector('#gallery_edit_menu');
  4649. old = document.querySelector('#gallery_edit_old_name');
  4650. newname = document.querySelector('#gallery_edit_new_name');
  4651. description = document.querySelector('#gallery_edit_description');
  4652. m.style.display='block';
  4653. if(desc!==null){ description.style.display='block';newname.style.display='none';description.value=desc;}
  4654. else{ description.style.display='none';newname.style.display='';}
  4655. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  4656. }
  4657. function ShowDeleteMenu(){
  4658. m=document.querySelector('#gallery_delete_menu');
  4659. m.style.display='block';
  4660. }
  4661. <?php } ?>
  4662. </script>
  4663. <?php
  4664. }
  4665. function MakeGalleryLeft(){?>
  4666. <div class='left hidden_m gallery_left' id='div_left'><div><br /></div>
  4667. <h2><?=$this->T('相册')?></h2>
  4668. <div>
  4669. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  4670. <ul>
  4671. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4672. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  4673. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4674. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  4675. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4676. <?php } ?>
  4677. </ul>
  4678. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  4679. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  4680. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  4681. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4682. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  4683. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4684. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  4685. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4686. <?php } ?>
  4687. <?php if($this->LoggedIn){ ?>
  4688. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  4689. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  4690. <?php } ?>
  4691. </ul></div>
  4692. <p>&nbsp;</p>
  4693. <script>
  4694. </script>
  4695. </div>
  4696. </div>
  4697. <?php
  4698. }
  4699. function MakeStatistics(){
  4700. $this->ReadPosts(); $this->ReadImages(); $this->ReadArchive();
  4701. $list=[]; $last_date=null; $info=[]; $info['count']=0; $info['edits']=0; $info['length']=0;
  4702. $imlist=[]; $imlast_date=null; $iminfo=[]; $iminfo['count']=0;
  4703. $maxposts=0; $maxlength=0; $maximages=0;
  4704. foreach($this->Posts as &$p){ $is_ref=0;
  4705. $this_date=substr($p['id'],0,8);
  4706. if($last_date!=null && $last_date!=$this_date){
  4707. if($maxposts<$info['count']+$info['edits'])$maxposts=$info['count']+$info['edits'];
  4708. if($maxlength<$info['length'])$maxlength=$info['length'];
  4709. $list[]=$info; $info=[]; $info['count']=0; $info['edits']=0; $info['length']=0;
  4710. }
  4711. $ah = &$this->GetArchiveHandle($p['id']); if(isset($ah)&&isset($ah['list'][0])) $info['edits']+=count($ah['list']);
  4712. $info['count']++; $info['id']=$this_date; if(isset($p['content']))$info['length']+=strlen($p['content']); $last_date=$this_date;
  4713. }
  4714. $last_date=null;
  4715. foreach($this->Images as &$im){ $is_ref=0;
  4716. $this_date=substr($im['name'],0,8);
  4717. if($last_date!=null && $last_date!=$this_date){
  4718. if($maximages<$iminfo['count'])$maximages=$iminfo['count'];
  4719. $imlist[]=$iminfo; $iminfo=[]; $iminfo['count']=0;
  4720. }
  4721. $iminfo['count']++; $iminfo['id']=$this_date; $last_date=$this_date;
  4722. }
  4723. if($info!=[]) $list[]=$info;
  4724. if($iminfo!=[]) $imlist[]=$iminfo;
  4725. if(!isset($list[0])) return;
  4726. $earliest=DateTimeImmutable::createFromFormat('!Ymd',$list[0]['id']); $ey=substr($list[0]['id'],0,4);
  4727. $latest=DateTimeImmutable::createFromFormat('!Ymd',end($list)['id']); $ly=substr(end($list)['id'],0,4);
  4728. $days=$earliest->diff($latest)->days; $lw=2.0; $dw=$days*$lw; $spw=20;
  4729. ?>
  4730. <style>.stastics_posts{direction:ltr;} .stastics_posts line,.stastics_posts circle{stroke:#f8ca9b; stroke-width:2px;}
  4731. .stastics_posts .line_edits{stroke:#f8ca9b40;}
  4732. .stastics_posts .line_year{stroke:#f8ca9b30; stroke-width:2px;} .stastics_posts text{fill:#f8ca9ba0; font: 0.9em serif;}
  4733. </style>
  4734. <div class='settings'><h2><?=$this->T('统计')?></h2><br />
  4735. <div style="overflow:auto;direction:rtl;width:100%;">
  4736. <svg class='stastics_posts' viewBox="-<?=$spw?> -<?=$spw?> <?=$days*$lw+$spw*6?> <?=200+4*$spw?>" height="<?=200+4*$spw?>" width="<?=$days*$lw+$spw*6?>">
  4737. <?php foreach($list as $info){ $itv=DateTimeImmutable::createFromFormat('!Ymd',$info['id'])->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);
  4738. $p1=100.0*(1-$info['count']/$maxposts); $p2=$p1-100.0*$info['edits']/$maxposts;
  4739. $p3=100.0*$info['length']/$maxlength+$spw+100; ?>
  4740. <line x1="<?=$ds?>" x2="<?=$ds?>" y1="100.0" y2="<?=$p1?>"/>
  4741. <?php if($info['edits']>0){ ?><line class='line_edits' x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=$p1?>" y2="<?=$p2?>"/><?php } ?>
  4742. <?php if($info['length']>0){ ?><line class='line_edits' x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=$spw+100?>" y2="<?=$p3?>"/><?php } ?>
  4743. <?php } ?>
  4744. <?php foreach($imlist as $im){ $itv=DateTimeImmutable::createFromFormat('!Ymd',$im['id'])->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);
  4745. $p1=100+$spw+100.0*($im['count']/$maximages); ?>
  4746. <circle cx="<?=$ds?>" cy="<?=$p1?>" r='3'/>
  4747. <?php } ?>
  4748. <?php for($y=$ey;$y<=$ly;$y++){ $itv=DateTimeImmutable::createFromFormat('!Y',$y)->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);?>
  4749. <line x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=220+$spw?>" y2="-<?=$spw?>" class='line_year'/>
  4750. <text x="<?=$ds+4?>" y="-4"><?=$y?></text>
  4751. <text x="<?=$ds+4?>" y="<?=$spw*2+200-4?>"><?=$y?></text>
  4752. <?php for($ym=1;$ym<=12;$ym++){ $st=str_pad($ym,2,'0',STR_PAD_LEFT); $itv2=DateTimeImmutable::createFromFormat('!Ym',$y.$st)->diff($earliest);
  4753. $dds=$lw/2+$lw*$itv2->days*($itv2->invert?1:-1); if($dds<0||$dds>$lw/2+$dw) continue; ?>
  4754. <line x1="<?=$dds?>" x2="<?=$dds?>" y1="<?=100+$spw?>" y2="100" class='line_year'/>
  4755. <text x="<?=$dds+4?>" y="<?=100+$spw-3?>"><?=$ym?></text>
  4756. <?php } } ?>
  4757. <line x1="<?=$lw/2+$dw?>" x2="<?=$days*$lw?>" y1="<?=220+$spw?>" y2="-<?=$spw?>" class='line_year'/>
  4758. <line x1="0" x2="<?=$dw?>" y1="0" y2="0" class='line_year'/>
  4759. <line x1="0" x2="<?=$dw?>" y1="100" y2="100" class='line_year'/>
  4760. <line x1="0" x2="<?=$dw?>" y1="<?=100+$spw?>" y2="<?=100+$spw?>" class='line_year'/>
  4761. <line x1="0" x2="<?=$dw?>" y1="<?=200+$spw?>" y2="<?=200+$spw?>" class='line_year'/>
  4762. <text x="<?=$dw+10?>" y="8"><?=$maxposts?></text>
  4763. <text x="<?=$dw+10?>" y="<?=$spw+8?>"><tspan style='fill:#f8ca9b;'>▪ <?=$this->T('新增')?></tspan></text>
  4764. <text x="<?=$dw+10?>" y="<?=$spw*2+8?>"><tspan style='fill:#f8ca9ba0;'>▪ <?=$this->T('改动')?></tspan></text>
  4765. <text x="<?=$dw+10?>" y="<?=$spw*2+200-4?>"><?=$maxlength?></text>
  4766. <text x="<?=$dw+10?>" y="<?=$spw+200-4?>"><tspan style='fill:#f8ca9b;'><?=$maximages?></tspan></text>
  4767. <text x="<?=$dw+10?>" y="<?=200-4?>"><tspan style='fill:#f8ca9b;'>▪ <?=$this->T('媒体')?></text>
  4768. <text x="<?=$dw+10?>" y="<?=200-4-$spw?>">▪ <?=$this->T('长度')?></tspan></text>
  4769. </svg></div>
  4770. <br /><br />
  4771. </div>
  4772. <?php
  4773. }
  4774. function MakeSettings(){ global $INDEXPHP; ?>
  4775. <div class='settings'>
  4776. <h2><?=$this->T('设置')?></h2>
  4777. <table style='white-space:nowrap;'>
  4778. <?php if($this->LoggedIn){ ?>
  4779. <form action="<?=$INDEXPHP?>?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4780. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4781. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4782. <tr><td><?=$this->T('网站标题')?></td>
  4783. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4784. value='<?=$this->Title?>'/></td></tr>
  4785. <tr><td><?=$this->T('短标题')?></td>
  4786. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4787. value='<?=$this->ShortTitle?>'/></td></tr>
  4788. <tr><td><?=$this->T('显示名称')?></td>
  4789. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4790. value='<?=$this->DisplayName?>'/></td></tr>
  4791. <tr><td><?=$this->T('电子邮件')?></td>
  4792. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4793. value='<?=$this->EMail?>'/></td></tr>
  4794. <tr><td><?=$this->T('导航栏')?>
  4795. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4796. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4797. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4798. <tr><td><?=$this->T('侧边栏')?>
  4799. <?=isset($this->SpecialSidebar)?"<a href='?post=".$this->SpecialSidebar."'>→</a>":""?></td>
  4800. <td><input type="text" form="settings_form" id='settings_special_sidebar' name='settings_special_sidebar'
  4801. value='<?=$this->SpecialSidebar?>'/></td></tr>
  4802. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4803. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4804. value='<?=$this->SpecialFooter?>'/></td></tr>
  4805. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4806. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4807. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4808. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4809. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4810. value='<?=$this->SpecialPinned?>'/></td></tr>
  4811. <tr><td><?=$this->T('默认相册')?></td>
  4812. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4813. value='<?=$this->DefaultGallery?>'/></td></tr>
  4814. <tr><td><?=$this->T('相册单步')?></td>
  4815. <td><input type="text" form="settings_form" id='settings_gallery_step' name='settings_gallery_step'
  4816. value='<?=$this->GalleryStep?>'/></td></tr>
  4817. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4818. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4819. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4820. <tr><td><?=$this->T('启用评论')?></td>
  4821. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4822. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4823. <tr><td><?=$this->T('启用新闻')?></td>
  4824. <td><input type="checkbox" id="settings_enable_newsletter" name="settings_enable_newsletter"
  4825. form="settings_form" <?=$this->NewsletterEnabled?"checked":""?>/></td></tr>
  4826. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='<?=$INDEXPHP?>?extras=true'><?=$this->T('进入')?></a></td></tr>
  4827. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4828. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4829. <tr><td><?=$this->T('长毛象实例')?></td>
  4830. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4831. value='<?=$this->MastodonURL?>'/></td></tr>
  4832. <tr><td><?=$this->T('长毛象令牌')?></td>
  4833. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4834. value='<?=$this->MastodonToken?>'/></td></tr>
  4835. <tr><td><?=$this->T('偏好语言')?></td>
  4836. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4837. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4838. <tr><td><?=$this->T('本站地址')?></td>
  4839. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4840. value='<?=$this->HostURL?>'/></td></tr>
  4841. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4842. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4843. <tr><td><?=$this->T('用户名')?></td>
  4844. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4845. value='<?=$this->APubID?>'/></td></tr>
  4846. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4847. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4848. <tr><td><?=$this->T('主机')?></td>
  4849. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4850. value='<?=$this->HereHost?>'/></td></tr>
  4851. <tr><td><?=$this->T('网站标题')?></td>
  4852. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4853. value='<?=$this->HereTitle?>'/></td></tr>
  4854. <tr><td><?=$this->T('短标题')?></td>
  4855. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4856. value='<?=$this->HereShortTitle?>'/></td></tr>
  4857. <tr><td><?=$this->T('相册')?></td>
  4858. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4859. value='<?=$this->HereAlbum?>'/></td></tr>
  4860. <tr><td><?=$this->T('导航栏')?>
  4861. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4862. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4863. value='<?=$this->HereNavigation?>'/></td></tr>
  4864. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4865. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4866. value='<?=$this->HereFooter?>'/></td></tr>
  4867. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4868. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4869. <tr><td><?=$this->T('主机')?></td>
  4870. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4871. value='<?=$this->ExpHost?>'/></td></tr>
  4872. <tr><td><?=$this->T('网站标题')?></td>
  4873. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4874. value='<?=$this->ExpTitle?>'/></td></tr>
  4875. <tr><td><?=$this->T('短标题')?></td>
  4876. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4877. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4878. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4879. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4880. value='<?=$this->ExpCaution?>'/></td></tr>
  4881. <tr><td><?=$this->T('相册')?></td>
  4882. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4883. value='<?=$this->ExpAlbum?>'/></td></tr>
  4884. <tr><td><?=$this->T('导航栏')?>
  4885. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4886. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4887. value='<?=$this->ExpNavigation?>'/></td></tr>
  4888. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4889. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4890. value='<?=$this->ExpFooter?>'/></td></tr>
  4891. <tr><td><?=$this->T('允许选择语言')?>
  4892. <td><input type="checkbox" id="settings_allow_language" name="settings_allow_language"
  4893. form="settings_form" <?=$this->AllowLanguageChoices?"checked":""?>/></td></tr>
  4894. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4895. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4896. <a href='<?=$INDEXPHP?>?logout=true'><?=$this->T('登出')?></a></td></tr>
  4897. <tr><td><?=$this->T('帐号')?></td>
  4898. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4899. value='<?=$this->Admin?>'/></td></tr>
  4900. <tr><td><?=$this->T('新密码')?></td>
  4901. <td><input type="password" form="settings_form"
  4902. id='settings_new_password' name='settings_new_password' /></td></tr>
  4903. <tr><td><?=$this->T('再次输入')?></td>
  4904. <td><input type="password" form="settings_form"
  4905. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4906. <tr><td><?=$this->T('旧密码')?></td>
  4907. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4908. <?php }else{ ?>
  4909. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4910. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4911. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4912. <tr><td><?=$this->T('帐号')?></td>
  4913. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4914. <tr><td><?=$this->T('密码')?></td>
  4915. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4916. <?php } ?>
  4917. </table>
  4918. <?php if($this->LoggedIn){ ?>
  4919. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4920. <?php }else{ ?>
  4921. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4922. <?php } ?>
  4923. </div>
  4924. <?php
  4925. }
  4926. function MakeExtraOperations(){ global $INDEXPHP; ?>
  4927. <div class='settings' style='overflow:auto;'>
  4928. <h2><?=$this->T('附加操作')?></h2>
  4929. <a href='<?=$INDEXPHP?>?&settings=true'><?=$this->T('返回一般设置')?></a>
  4930. <p>&nbsp;</p>
  4931. <h3><?=$this->T('自动重定向')?></h3>
  4932. <span class='smaller gray'>
  4933. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4934. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4935. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4936. <textarea id="settings_redirect" name="settings_redirect" rows="4" class='full_box' wrap="off"
  4937. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4938. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4939. value='<?=$this->T('保存重定向设置')?>' />
  4940. <p>&nbsp;</p>
  4941. <h3><?=$this->T('自定义翻译')?></h3>
  4942. <span class='smaller gray'>
  4943. <?=$this->T('填写格式:')?>
  4944. <br /><pre>- 语言 | Language</pre></span>
  4945. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4946. <textarea id="settings_translation" name="settings_translation" rows="4" class='full_box' wrap="off"
  4947. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4948. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4949. value='<?=$this->T('保存翻译')?>' />
  4950. <?php if($this->NewsletterEnabled){
  4951. $subs=file_get_contents("all_subscribers.php"); ?>
  4952. <br /><br /><h3><?=$this->T('邮件订阅者')?></h3>
  4953. <textarea rows="4" class='full_box' wrap="off"><?=$subs?substr($subs,5):"error"?></textarea>
  4954. <?php } ?>
  4955. <br />
  4956. <p class='smaller gray'><?=$this->T('ActivityPub 测试:')?></p>
  4957. <ul>
  4958. <li><a href='?TestAPubDeliver=1'><?=$this->T('测试发送')?></a></li></ui>
  4959. </ui>
  4960. <br />
  4961. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4962. <ul>
  4963. <li><label for='opbtn0' class='ref_count'><?=$this->T('重新写入默认CSS')?></label><input type="checkbox" class='lpctrl' id='opbtn0' checked='checked'/>
  4964. <a href='?rewrite_styles=true'>→</a></li>
  4965. <li><label for='opbtn1' class='ref_count'><?=$this->T('重新生成图片缩略图')?></label><input type="checkbox" class='lpctrl' id='opbtn1' checked='checked'/>
  4966. <a href='?regenerate_thumbnails=true'>→</a></li>
  4967. <li><label for='opbtn2' class='ref_count'><?=$this->T('清理未压缩的图像')?></label><input type="checkbox" class='lpctrl' id='opbtn2' checked='checked'/>
  4968. <a href='?cleanup_image_compression=true'>→</a></li>
  4969. <li><label for='opbtn3' class='ref_count'><?=$this->T('删除所有登录')?></label><input type="checkbox" class='lpctrl' id='opbtn3' checked='checked'/>
  4970. <a href='?clear_all_logins=true'>→</a></li>
  4971. </ui>
  4972. <br /><br /><br /><a href='?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4973. </div>
  4974. <?php
  4975. }
  4976. function MakeMainBegin(){?>
  4977. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4978. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4979. <?php
  4980. }
  4981. function MakeMainEnd(){?>
  4982. </div>
  4983. <?php
  4984. }
  4985. function MakeExpFooter(){
  4986. $exptitle = isset($this->HereDisplayTitle)?('"'.trim($this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle))).'"'):NULL;
  4987. if(!isset($exptitle)) $exptitle=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle);?>
  4988. <div class='small_footer exp_h_f exp_f'><div>
  4989. <?php if($this->InExperimentalMode){ ?>
  4990. <b><?=$exptitle?></b>
  4991. <?php }else{ ?>
  4992. <b><?=$exptitle?></b> ©<?=$this->T($this->DisplayName)?>
  4993. <?php }?>
  4994. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):""; ?>
  4995. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4996. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4997. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4998. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4999. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  5000. }?></div>
  5001. </div>
  5002. </div>
  5003. </div><!-- page -->
  5004. </body>
  5005. </html>
  5006. <script>
  5007. if(trans = document.getElementById('translate_button')){
  5008. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  5009. }
  5010. </script>
  5011. <?php
  5012. }
  5013. function MakeImageOverlay($side_info=null,$static_image=null,$static_video=null){
  5014. $static=isset($side_info); ?>
  5015. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  5016. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  5017. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  5018. <?php if(!$static_video){ ?>
  5019. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/><?php } ?>
  5020. <?php if(!$static_image){ ?>
  5021. <video id='big_video' onloadstart="HideWaitingBar();" controls><source id='big_video_src' type='video/mp4'
  5022. <?=isset($static_video)?("src='".$static_video."'"):""?>></video><?php } ?>
  5023. </div>
  5024. <div class='big_side_box' onclick='HideBigImage(1);'>
  5025. <?php if(!$static){ ?>
  5026. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  5027. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  5028. <div class='lr_buttons'>←</div></a></div>
  5029. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  5030. <div class='lr_buttons'>→</div></a></div>
  5031. <div id='here_buttons'></div>
  5032. </div><?php } ?>
  5033. <div class='side_box_mobile_inner'>
  5034. <?php if(!$static){ ?>
  5035. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  5036. <span style='display:none;' id='image_purchase' class='clean_a'>
  5037. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  5038. <br class='hidden_on_desktop block_m' /></span>
  5039. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  5040. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  5041. &nbsp;<a class='clean_a' id='image_inquiry'>
  5042. <b>@</b><?=$this->T('咨询')?></a>
  5043. <?php } ?><hr class='hidden_on_desktop block_m' />
  5044. </div>
  5045. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  5046. <li class='wayback_close'><a onclick='HideBigImage(1);'><?=$this->T('关闭')?> ×</a></li>
  5047. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  5048. <hr />
  5049. </div><?php } //static ?>
  5050. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  5051. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  5052. <br /><?=$this->T('印刷品链接')?>
  5053. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  5054. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  5055. <?=$this->T('重命名')?>
  5056. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  5057. <?=$this->T('主图')?>
  5058. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  5059. <?=$this->T('对齐')?> <select id='image_align' name='image_align' form="image_ops_form">
  5060. <option value='top'><?=$this->T('顶部')?></option>
  5061. <option value='middle'><?=$this->T('中间')?></option>
  5062. <option value='bottom'><?=$this->T('底部')?></option></select><br />
  5063. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  5064. <br /><br /><?=$this->T('替换图像')?>
  5065. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  5066. <input type="file" form='image_edit_form'
  5067. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  5068. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  5069. value=<?=$this->T('执行')?> />
  5070. </div><?php } ?>
  5071. </div>
  5072. </div>
  5073. </div>
  5074. <?php }
  5075. function MakePageEnd(){?>
  5076. </div><!-- page -->
  5077. </body>
  5078. </html>
  5079. <?php }
  5080. function MakeFooter(&$p){ global $INDEXPHP;
  5081. $is_slides=(isset($p['slides']) || (isset($p['tid'])&&isset($p['tid']['slides']))); $no_title=isset($p['tid']['first']['no_title']);?>
  5082. <div class='small_footer'><div>
  5083. <hr />
  5084. <?php if(isset($p['tid']['footer'])){ ?><div class='show_on_print'><?=$p['tid']['footer'];?></div><?php } ?>
  5085. <b<?=$no_title?" class='hidden_on_print'":"";?>><?=$this->T($this->Title)?></b>
  5086. <span onclick='event.stopPropagation()'<?=$no_title?" class='hidden_on_print'":"";?>
  5087. ondblclick='javascript:window.location.href="<?=$INDEXPHP?>?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  5088. <div class='smaller show_on_print'><?=$_SERVER['SERVER_NAME']?><br /><?=$this->EMail?></div>
  5089. </div></div>
  5090. <div class='footer'>
  5091. <div style='white-space:nowrap;'>
  5092. <div class='footer_additional'>
  5093. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  5094. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  5095. } ?>
  5096. </div>
  5097. <div class='footer_additional'>
  5098. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  5099. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  5100. } ?>
  5101. </div>
  5102. </div>
  5103. </div>
  5104. <p>&nbsp;<p>
  5105. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  5106. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  5107. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  5108. </div>
  5109. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  5110. <script>
  5111. <?php if($is_slides){ ?>SlidesStart(null);<?php } ?>
  5112. <?=$this->ExtraScripts?>
  5113. if(back = document.getElementById('button_back')){
  5114. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  5115. back.href='javascript:history.back()';
  5116. }else{
  5117. back.href='<?=$INDEXPHP?>';
  5118. }
  5119. }
  5120. function copy_text(t) {
  5121. ta = document.createElement('textarea'); document.body.appendChild(ta); ta.value = t; ta.select();
  5122. document.execCommand("copy"); document.body.removeChild(ta);
  5123. }
  5124. if(trans = document.getElementById('translate_button')){
  5125. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  5126. }
  5127. function ClickPost(p,e,pushstate){if(e)e.preventDefault();
  5128. id=p.dataset.postId; if(!id)return; list=p.parentNode;active=list.getElementsByClassName('active_post');
  5129. if(active&&active[0]&&active[0]!=p){
  5130. if(pushstate){window.history.pushState('?post='+id,null,'?post='+id);}
  5131. active[0].classList.remove('active_post'); p.classList.add('active_post');
  5132. }
  5133. if(!active[0]){ window.location.href="?post="+id; }
  5134. }function InitLabel(){
  5135. lb=document.querySelector('#mtitle'); lb.removeAttribute('for'); lb.onclick=function()
  5136. {c=document.querySelector('#titlectrl');if(c.checked)c.checked=false;else c.checked=true;}
  5137. lb=document.querySelectorAll('.bkg_section label');if(!lb||!lb[0])return;
  5138. for(i=0;i<lb.length;i++){ lb[i].removeAttribute('for');lb[i].onclick=function()
  5139. {c=this.parentNode.querySelector('.lpctrl');if(!c)return;if(c.checked)c.checked=false;else c.checked=true;} }
  5140. }InitLabel();
  5141. <?php if($this->LoggedIn){ ?>
  5142. var Scenter = document.querySelector('.center');
  5143. var Sposts = Scenter?Scenter.querySelectorAll('.post'):null;
  5144. <?php if(isset($this->MastodonToken)){ ?>
  5145. function MarkPostDoneMastodon(id,mastodon_url){
  5146. for(var i=0;i<Sposts.length;i++){
  5147. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  5148. }
  5149. <?php } ?>
  5150. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  5151. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  5152. var Smerge_post = Scenter.querySelector('#merge_post');
  5153. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  5154. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  5155. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  5156. var Smerge_select = Scenter.querySelector('#merge_select');
  5157. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  5158. var Smerge_thread = Scenter.querySelector('#merge_thread');
  5159. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  5160. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  5161. var select_mode = false; var merge_mode = false; var selected_posts = null;
  5162. function TogglePostSelectMode(force_on=false,force_off=false){
  5163. Scenter.classList.add('post_selecting');
  5164. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  5165. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  5166. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  5167. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  5168. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  5169. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  5170. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  5171. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  5172. Smerge_post_count.innerText="0";
  5173. Smerge_post.href="#";
  5174. }
  5175. function TogglePostSelect(elem){
  5176. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  5177. else{ elem.classList.add('post_selected'); }
  5178. selected_posts = new Array();
  5179. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  5180. selected_posts.push(Sposts[i].dataset.postId); } }
  5181. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  5182. Smerge_post_count.innerText=selected_posts.length;
  5183. }
  5184. function ThreadMergeInput(elem){
  5185. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  5186. else{ Smerge_thread.href="#"; }
  5187. }
  5188. function ToggleThreadMerge(force_on=false,force_off=false){
  5189. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  5190. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  5191. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  5192. else{ merge_mode = 0;
  5193. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  5194. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  5195. Smerge_thread.href="#";
  5196. Smerge_thread_target.value='';
  5197. }
  5198. <?php } ?>
  5199. function ShowSideUploader(){
  5200. ShowRightSide(true,null);
  5201. put = document.querySelector("#_uploader");
  5202. put.style.display='block';
  5203. RefreshSideGallery();
  5204. }
  5205. dmark = document.querySelector("#mark_details");
  5206. drename = document.querySelector("#rename_details");
  5207. dmastodon = document.querySelector("#mastodon_details");
  5208. drename_form = document.querySelector("#post_rename_form");
  5209. drename_input = document.querySelector("#post_rename_name");
  5210. var rp = document.querySelector('#post_reply_to');
  5211. var _reply_to = rp?rp.defaultValue:"";
  5212. function RestoreReply(){
  5213. if(rp){
  5214. rp.defaultValue = _reply_to;
  5215. }
  5216. document.querySelector('#post_reply_restore').style.display='none';
  5217. ht = document.querySelector('#post_hint_text');
  5218. if (_reply_to!=""){
  5219. ht.style.display='block';
  5220. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  5221. }else{
  5222. ht.style.display='none';
  5223. }
  5224. document.querySelector('#post_edit_target').value="";
  5225. ch = document.querySelector('#post_hint_modify');
  5226. ch.style.display='none';
  5227. }
  5228. function MakeRefer(id){
  5229. t = document.querySelector('#post_content')
  5230. t.focus();
  5231. v = t.value;
  5232. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  5233. la_auto_grow(t);
  5234. if(rp){
  5235. rp.defaultValue = "";
  5236. ht = document.querySelector('#post_hint_text');
  5237. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  5238. document.querySelector('#post_reply_restore').style.display='inline';
  5239. rs = document.querySelector('#post_reply_restore');
  5240. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  5241. document.getElementById('post_menu').style.display='none';
  5242. ch = document.querySelector('#post_hint_modify');
  5243. ch.style.display='none';
  5244. }
  5245. }
  5246. function CopyRefer(id){
  5247. copy_text(id.toString());
  5248. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  5249. }
  5250. function MakeEdit(id){
  5251. ed = document.getElementById('menu_edit');
  5252. ed.innerHTML="<?=$this->T('稍等')?>";
  5253. ed.href="#";
  5254. var xhr = new XMLHttpRequest();
  5255. xhr.onreadystatechange = function() {
  5256. if (this.readyState == 4 && this.status == 200) {
  5257. ed.innerHTML='——';
  5258. ch = document.querySelector('#post_hint_modify');
  5259. ch.style.display='block';
  5260. ht = document.querySelector('#post_hint_text');
  5261. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  5262. rs = document.querySelector('#post_reply_restore');
  5263. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  5264. t = document.querySelector('#post_content');
  5265. t.value=xhr.responseText.trim();
  5266. t.focus();
  5267. la_auto_grow(t);
  5268. document.querySelector('#post_edit_target').value=id;
  5269. document.getElementById('post_menu').style.display='none';
  5270. }
  5271. };
  5272. xhr.open("GET", "<?=$INDEXPHP?>?post="+id.toString()+'&post_original=true', true);
  5273. xhr.send();
  5274. }
  5275. function MarkDelete(id){
  5276. p = document.querySelector('[data-post-id="'+id+'"]');
  5277. op = p.dataset.markDelete?"false":"true";
  5278. window.location.href=
  5279. "<?=$INDEXPHP?>?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  5280. }
  5281. function SetMark(mark){
  5282. menu = document.getElementById('post_menu');
  5283. window.location.href=
  5284. "<?=$INDEXPHP?>?<?=$this->GetRedirect()?>&target="+
  5285. menu.parentNode.dataset.postId+"&set_mark="+mark;
  5286. }
  5287. function ToggleMarkDetails(){
  5288. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  5289. drename.style.display=dmastodon.style.display='none';
  5290. }
  5291. function ToggleRenameDetails(){
  5292. drename.style.display=(drename.style.display=='block')?'none':'block';
  5293. dmark.style.display=dmastodon.style.display='none';
  5294. }
  5295. function ToggleMastodonDetails(){
  5296. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  5297. dmark.style.display=drename.style.display='none';
  5298. }
  5299. <?php } if(isset($_GET['post'])){ ?> ScrollToPost("<?=$_GET['post']?>"); <?php } ?>
  5300. function ShowPostMenu(post){
  5301. menu = document.getElementById('post_menu');
  5302. menu.style.display='block';
  5303. menu.parentNode.removeChild(menu);
  5304. post.appendChild(menu);
  5305. menu.style.display='block';
  5306. id = post.dataset.postId
  5307. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  5308. ' '+id.substring(8,10)+':'+id.substring(10,12);
  5309. window.onClick="HidePopMenu()";
  5310. menu.onClick=(function(event){
  5311. event.stopPropagation();
  5312. });
  5313. hs = menu.querySelector('#menu_history');
  5314. hs.href='?post='+id+'&history=1';
  5315. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  5316. <?php if($this->PageType!='search'){?>
  5317. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  5318. ed = menu.querySelector('#menu_edit');ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  5319. <?php } ?>
  5320. ref = menu.querySelector('#menu_refer_copy')
  5321. ref.innerHTML='<?=$this->T("复制编号")?>';
  5322. ref.href='javascript:CopyRefer(id)';
  5323. d = menu.querySelector('#menu_delete');
  5324. d.href='javascript:MarkDelete(\"'+id+'\")';
  5325. p = document.querySelector('[data-post-id="'+id+'"]');
  5326. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  5327. menu.querySelector('#mark_details').dataset.id=id;
  5328. drename_input.value=id;
  5329. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  5330. <?php if(isset($this->MastodonToken)){ ?>
  5331. dmastodon_form = document.querySelector("#post_mastodon_form");
  5332. dmastodon_form.action='?mastodon_post='+id;
  5333. function MastodonSend(id){
  5334. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  5335. var xhr = new XMLHttpRequest();
  5336. function wrapidxhr(_id) { return function() {
  5337. if (this.readyState == 4 && this.status == 200) {
  5338. var response = xhr.responseText;
  5339. let content="";
  5340. if(res = response.match(/SUCCESS (\S+)/u)){
  5341. content="<?=$this->T('成功发送到长毛象')?>";
  5342. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  5343. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  5344. MarkPostDoneMastodon(_id, res[1]);
  5345. } }
  5346. };
  5347. xhr.onreadystatechange = wrapidxhr(id);
  5348. xhr.open("GET", "<?=$INDEXPHP?>?mastodon_send_post="+id, true); xhr.send();
  5349. }
  5350. menu_mastodon = menu.querySelector("#menu_mastodon");
  5351. mastodon_send = menu.querySelector("#menu_mastodon_send");
  5352. mastodon_view = menu.querySelector("#menu_mastodon_view");
  5353. mastodon_url = menu.querySelector("#post_mastodon_url");
  5354. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  5355. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  5356. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  5357. mastodon_url.value="";}
  5358. mastodon_send.onclick=function(){
  5359. this.onclick=function(){};
  5360. MastodonSend(id); };
  5361. <?php } } ?>
  5362. title = document.title;
  5363. copy = document.getElementById('share_copy');
  5364. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  5365. copy.addEventListener("click", function(){
  5366. url = window.location
  5367. path = location.pathname
  5368. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  5369. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  5370. });
  5371. }
  5372. function HidePopMenu(){
  5373. var menus = document.querySelectorAll('.pop_menu');
  5374. [].forEach.call(menus, function(m){m.style.display='none';});
  5375. }
  5376. var posts = document.querySelectorAll('.main>.center>tbody>.post'); if(!posts || !posts[0]) posts = document.querySelectorAll('.center_slides .post');
  5377. [].forEach.call(posts, function(p){
  5378. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  5379. ShowPostMenu(this.parentNode.parentNode);
  5380. if(document.querySelector('.clickable_section')!=null) ClickPost(this.parentNode.parentNode,null,true)
  5381. });
  5382. p.addEventListener("dblclick", function(){ ClickPost(this,null,true); lp=this.querySelector('.lpctrl'); if(lp){ if(lp.checked)lp.checked=false;else lp.checked=true; }});
  5383. });
  5384. //var post_clickables = document.querySelectorAll('.center .post a');
  5385. //[].forEach.call(post_clickables, function(p){
  5386. // p.addEventListener("click", function(event){
  5387. // event.stopPropagation();
  5388. // });
  5389. //});
  5390. function FindImage(imgsrc){
  5391. for(var i=0;i<document.images_filtered.length;i++){
  5392. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  5393. }
  5394. return null
  5395. }
  5396. var dottime1;
  5397. var dottime2;
  5398. function ToDataURL(url) {
  5399. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  5400. clearTimeout(dottime1);clearTimeout(dottime2);
  5401. ps = document.querySelector('#download_processing');
  5402. ps.innerHTML='↓';ps.style.opacity='';
  5403. return URL.createObjectURL(blob);});
  5404. }
  5405. async function DownloadAsImage(url,name) {
  5406. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  5407. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  5408. }
  5409. function basename(url){return url.split(/[\\/]/).pop();}
  5410. pushed=0;
  5411. function ShowBigImage(imgsrc,do_push){
  5412. ShowWaitingBar();
  5413. share = document.querySelector('#big_image_share');
  5414. img = document.querySelector('#big_image');
  5415. vid = document.querySelector('#big_video');
  5416. vidsrc = document.querySelector('#big_video_src');
  5417. down = document.querySelector('#image_download');
  5418. img.src = ""; vidsrc.src="";
  5419. if(imgsrc.match(/\.mp4$/)){
  5420. vidsrc.src = src = "images/"+imgsrc; img.style.display='none'; vid.load();vid.style.display='block';
  5421. }else{
  5422. img.src = src = "images/"+imgsrc; vid.style.display='none';img.style.display='block';
  5423. }
  5424. down.href="images/"+imgsrc;
  5425. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_<?=$this->GiveSafeEMail()?>_'+
  5426. basename(down.href);
  5427. img.alt = downname; down.download=downname;
  5428. var use_href = "images/"+imgsrc;
  5429. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  5430. ps = this.querySelector('#download_processing');ps.innerText='…';
  5431. var dotwait = function(ps){ var self = this;
  5432. dottime1 = setTimeout(function(ps){
  5433. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  5434. dotwait(this.querySelector('#download_processing'));
  5435. DownloadAsImage(use_href,downname);};
  5436. if(do_push){PushGalleryHistory(src)}
  5437. page_url = encodeURIComponent(window.location.href);
  5438. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  5439. inqb = document.querySelector('#image_inquiry');
  5440. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  5441. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  5442. (page_url)+encodeURIComponent('\n\n');
  5443. <?php } ?>
  5444. this_image = FindImage(imgsrc);
  5445. if(this_image&&this_image.dataset.prevsrc){
  5446. new_image = FindImage(this_image.dataset.prevsrc);
  5447. new_prev = new_image?new_image.dataset.prevsrc:null;
  5448. im = document.querySelector('#prev_image');
  5449. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  5450. else {im.style.opacity='0';im.removeAttribute("href");}
  5451. }
  5452. if(this_image&&this_image.dataset.nextsrc){
  5453. new_image = FindImage(this_image.dataset.nextsrc);
  5454. new_next = new_image?new_image.dataset.nextsrc:null;
  5455. im = document.querySelector('#next_image');
  5456. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  5457. else {im.style.opacity='0';im.removeAttribute("href");}
  5458. }
  5459. purchase = document.querySelector('#image_purchase');
  5460. purchase_btn = document.querySelector('#image_purchase_button');
  5461. <?php if($this->LoggedIn){ ?>
  5462. product_link = document.querySelector('#image_ops_product_link');
  5463. product_form = document.querySelector('#image_ops_form');
  5464. edit_form = document.querySelector('#image_edit_form');
  5465. edit_new_name = document.querySelector('#image_edit_new_name');
  5466. edit_parent = document.querySelector('#image_parent');
  5467. edit_align = document.querySelector('#image_align');
  5468. product_form.action = window.location.href;
  5469. edit_form.action = window.location.href;
  5470. edit_new_name.value = imgsrc.split('.')[0];
  5471. if(this_image){
  5472. if(this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  5473. if(this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  5474. if(this_image.dataset.align){ edit_align.value = this_image.dataset.align; }else{ edit_align.value = "middle"; }
  5475. }
  5476. <?php } ?>
  5477. if(this_image&&this_image.dataset.product){
  5478. purchase.style.display='';
  5479. href = this_image.dataset.product;
  5480. if(this_image.dataset.product.match('^[0-9]{14}$')){
  5481. href = '?post='+href;
  5482. }
  5483. purchase_btn.href = href;
  5484. }else{
  5485. purchase.style.display='none';
  5486. purchase_btn.removeAttribute("href");
  5487. }
  5488. DelayHideImgBtn(null);
  5489. title = encodeURIComponent(document.title);
  5490. copy = document.getElementById('big_share_copy');
  5491. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  5492. copy.addEventListener("click", function(){
  5493. copy_text(window.location.href);
  5494. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  5495. });
  5496. o = document.querySelector('#big_image_overlay');
  5497. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  5498. here = document.querySelector('#here_buttons');here.innerHTML='';
  5499. o.style.display="block";
  5500. ShowBackdrop(0.8);
  5501. var xhr = new XMLHttpRequest();
  5502. xhr.onreadystatechange = function() {
  5503. if (this.readyState == 4 && this.status == 200) {
  5504. info = document.querySelector('#big_image_info');
  5505. var response = xhr.responseText;
  5506. let content=""
  5507. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  5508. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  5509. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  5510. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){ content+=res[1]; }
  5511. info.innerHTML=content;
  5512. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  5513. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  5514. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  5515. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  5516. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  5517. }
  5518. }
  5519. };
  5520. xhr.open("GET", "<?=$INDEXPHP?>?image_info="+imgsrc+"", true);
  5521. xhr.send();
  5522. }
  5523. function HideBigImage(do_push){
  5524. o = document.querySelector('#big_image_overlay');
  5525. img = document.querySelector('#big_image');
  5526. vid = document.querySelector('#big_video');
  5527. vidsrc = document.querySelector('#big_video_src');
  5528. img.src = ""; vidsrc.src="";
  5529. if(o.style.display!='none'){
  5530. o.style.display="none";
  5531. HideBackdrop();
  5532. if(do_push){PushGalleryHistory("");}
  5533. HideWaitingBar();
  5534. }
  5535. }
  5536. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  5537. var inq=document.querySelector('#inquiry_buttons');
  5538. var overlay=document.querySelector('#big_image_overlay');
  5539. var hide_timeout;
  5540. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  5541. function DelayHideImgBtn(e){
  5542. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  5543. inq.classList.remove('img_btn_hidden');
  5544. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  5545. clearTimeout(hide_timeout);
  5546. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  5547. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  5548. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  5549. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  5550. }
  5551. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  5552. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  5553. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  5554. overlay.addEventListener('mousemove',DelayHideImgBtn);
  5555. function UpdateImageClickables(){
  5556. var images = document.querySelectorAll('.center img, .center video, .center_wide img, .center_wide video');
  5557. var images_filtered=new Array(); var imgadded = new Array();
  5558. var images_remaining=new Array();
  5559. [].forEach.call(images, function(img){
  5560. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  5561. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  5562. images_filtered.push(img);imgadded.push(imgsrc);
  5563. });
  5564. for(var i=0; i<images_filtered.length; i++){
  5565. previmg = nextimg = null; img = images_filtered[i];
  5566. if(i>0) previmg=images_filtered[i-1];
  5567. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  5568. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  5569. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  5570. function wrap(imgsrc){return function(event){ShowBigImage(imgsrc, 1);}}
  5571. var clone = img.cloneNode(true); img.replaceWith(clone);
  5572. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  5573. }
  5574. for(var i=0; i<images_remaining.length; i++){
  5575. img = images_remaining[i];
  5576. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  5577. var clone = img.cloneNode(true); img.replaceWith(clone);
  5578. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  5579. }
  5580. document.images_filtered = images_filtered;
  5581. }
  5582. UpdateImageClickables();
  5583. function PopGalleryHistory(){
  5584. if(pushed){
  5585. pushed = 0;
  5586. try{
  5587. history.back();
  5588. }catch{
  5589. console.log("can't do it.");
  5590. }
  5591. }
  5592. }
  5593. function PushGalleryHistory(src){
  5594. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  5595. title = "照片"
  5596. extra = "?";
  5597. sp = new URLSearchParams(window.location.search)
  5598. if(sp.has('post')){extra+="post="+sp.get('post')}
  5599. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  5600. try{
  5601. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  5602. }catch{
  5603. console.log("can't do it.");
  5604. }
  5605. pushed = 1;
  5606. }
  5607. document.addEventListener('keydown', function(e){
  5608. large = document.getElementById('big_image_overlay')
  5609. if (large.style.display!='block') return;
  5610. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  5611. HideBigImage(1);
  5612. }
  5613. }, true);
  5614. window.addEventListener('popstate', (event) => {
  5615. href=window.location.href;
  5616. let sp = new URLSearchParams(href.substring(href.indexOf('?')))
  5617. if(sp.has('pic')){
  5618. src = sp.get('pic')
  5619. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)) ShowBigImage(onlyimg[0], 0);
  5620. else{HideBigImage(0);}
  5621. }else{HideBigImage(0);}
  5622. if(sp.has('post')){
  5623. id=sp.get('post');post=document.querySelector('.post[data-post-id="'+id+'"]');
  5624. if(post){ClickPost(post,null,false);}
  5625. }
  5626. });
  5627. let searchParams = new URLSearchParams(window.location.search)
  5628. if(searchParams.has('pic')){
  5629. src = searchParams.get('pic')
  5630. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)){
  5631. ShowBigImage(onlyimg[0], 1);
  5632. }
  5633. }
  5634. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  5635. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  5636. </script>
  5637. </body>
  5638. <?php
  5639. }
  5640. function DoIdentifyExperimental(){
  5641. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  5642. $this->InExperimentalMode=True; $this->InHereMode=True;
  5643. if(!$this->AllowLanguageChoices){ $this->LanguageAppendix='en'; }
  5644. }
  5645. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  5646. $this->InHereMode=True;
  5647. }
  5648. //$this->InHereMode=True;
  5649. }
  5650. function DoExperimentalTopLink($p){
  5651. if($this->InHereMode && $p){
  5652. if(isset($p['tid']) && $p['tid']['first']!=$p){
  5653. header('Location: ?post='.$p['tid']['first']['id']); exit();
  5654. }
  5655. }
  5656. }
  5657. function MakeExperimentalConfirm(){ global $INDEXPHP;
  5658. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  5659. return false;
  5660. }
  5661. $caution_html =
  5662. $confirm = "<a class='text_highlight clean_a bold' href='".$INDEXPHP."?confirm_enter=1".
  5663. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  5664. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  5665. ?>
  5666. <div class='center_exp'><?php
  5667. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  5668. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  5669. ?></div>
  5670. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  5671. <?php return true;
  5672. }
  5673. }
  5674. $la = new LA;
  5675. $la->DoSiteRedirect();
  5676. $la->DoLogin();
  5677. $la->SwitchLanguageAndFont();
  5678. $err = $la->ProcessRequest($message, $redirect);
  5679. $la->WriteAsNecessary();
  5680. $la->DoIdentifyExperimental();
  5681. $la->SwitchWayBackMode();
  5682. if($err){
  5683. echo $message;
  5684. exit();
  5685. }
  5686. if(isset($redirect)){
  5687. header('Location: '.$redirect);
  5688. exit();
  5689. }
  5690. $la->DetectPageType();
  5691. $la->ReadImages(false);
  5692. $la->ReadPosts();
  5693. if(isset($la->WayBack)){
  5694. $la->ReadArchive();
  5695. }
  5696. $im = NULL;
  5697. if(isset($la->HereID) && preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  5698. if(!$la->CanShowImage($im)) { $im=&$la->NULL_IMAGE; }
  5699. }
  5700. $p = &$la->GetPost($la->CurrentPostID);
  5701. if(!isset($p)){
  5702. $p = &$la->GetMergedPost($la->CurrentPostID);
  5703. }
  5704. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  5705. else{ $la->DoExperimentalTopLink($p); }
  5706. if(isset($p)){ $la->ActualPostID = $p['id']; }
  5707. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5708. if($im){
  5709. $la->SetHereMainImage($im);
  5710. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  5711. }else if($p){
  5712. $la->RecordVisitedHere($p['id'],NULL);
  5713. }else {
  5714. $im = &$la->GiveImageInHere(false);
  5715. if($im){
  5716. $la->SetHereMainImage($im);
  5717. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  5718. }
  5719. }
  5720. }
  5721. $la->MakeHeader($p);
  5722. $la->MakeMainBegin();
  5723. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5724. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  5725. if($im){
  5726. $la->MakeHereSection($im);
  5727. }else if($p){
  5728. $la->MakePostSectionExp($p);
  5729. $la->MakeLinkedPostsExp($p);
  5730. }else {
  5731. if($im){
  5732. $la->MakeHereSection($im);
  5733. }else{
  5734. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5735. "</p><p><a href='".$INDEXPHP."'>".$la->T('返回首页')."</a></p><br />";
  5736. }
  5737. }
  5738. }
  5739. $la->MakeMainEnd();
  5740. $la->MakeExpFooter();
  5741. }else{
  5742. if($la->PageType=='extras'){
  5743. $la->MakeExtraOperations();
  5744. }else if($la->PageType=='settings'){
  5745. $la->MakeSettings();
  5746. }else if($la->PageType=='gallery'){
  5747. $la->MakeGalleryLeft();
  5748. $la->MakeGallerySection();
  5749. }else if($la->PageType=='post'){
  5750. if($p){
  5751. $made_interesting = false;
  5752. if($la->IsInterestingPost($p)){
  5753. $la->MakeInterestingSection($p['tid']);
  5754. }
  5755. else{
  5756. $la->MakeSidebar();
  5757. $la->MakePostSectionV2($p);
  5758. echo $la->GeneratePage(1," section");
  5759. //$la->MakePostSection($p);
  5760. }
  5761. }else{
  5762. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5763. "</p><p><a href='".$INDEXPHP."'>".$la->T('返回首页')."</a></p><br />";
  5764. }
  5765. }else if($la->PageType=='history'){
  5766. $la->ReadArchive();
  5767. $la->MakePostHistory($p, $_GET['version']??NULL);
  5768. }else if($la->PageType=='search'){
  5769. $la->MakeSidebar();
  5770. $la->MakeRecentPostsV2($_GET['search']);
  5771. echo $la->GeneratePage();
  5772. }else if($la->PageType=='category'){
  5773. $la->MakeSidebar();
  5774. $la->MakeRecentPostsV2(NULL,$_GET['category']);
  5775. echo $la->GeneratePage();
  5776. }else if($la->PageType=='comments'){
  5777. $la->MakeCommentPosts();
  5778. }else if($la->PageType=='statistics'){
  5779. $la->MakeStatistics();
  5780. }else{
  5781. $la->MakeSidebar();
  5782. $la->MakeRecentPostsV2();
  5783. echo $la->GeneratePage();
  5784. }
  5785. $la->MakeMainEnd();
  5786. $la->MakeFooter($p);
  5787. }
  5788. ?>