*/}}

index.php 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385
  1. <?php
  2. include 'Parsedown.php';
  3. include 'ParsedownExtra.php';
  4. ini_set('max_execution_time', 300);
  5. ini_set('display_errors', '1');
  6. ini_set('display_startup_errors', '1');
  7. error_reporting(E_ALL);
  8. class LA{
  9. protected $PDE;
  10. protected $style;
  11. /* config */
  12. protected $Title;
  13. protected $ShortTitle;
  14. protected $Admin;
  15. protected $Password;
  16. protected $DisplayName;
  17. protected $EMail;
  18. protected $SpecialNavigation;
  19. protected $SpecialSidebar;
  20. protected $SpecialFooter;
  21. protected $SpecialFooter2;
  22. protected $SpecialPinned;
  23. protected $DefaultGallery;
  24. protected $SelfAuthPath;
  25. protected $HereHost;
  26. protected $HereTitle;
  27. protected $HereShortTitle;
  28. protected $HereAlbum;
  29. protected $HereNavigation;
  30. protected $HereFooter;
  31. protected $ExpHost;
  32. protected $ExpAlbum;
  33. protected $ExpTitle;
  34. protected $ExpShortTitle;
  35. protected $ExpCaution;
  36. protected $ExpNavigation;
  37. protected $ExpFooter;
  38. protected $CommentEnabled;
  39. protected $MastodonToken;
  40. protected $MastodonURL;
  41. protected $MastodonPreferredLang;
  42. protected $HostURL;
  43. protected $GalleryStep;
  44. protected $AllowLanguageChoices;
  45. protected $Redirect;
  46. protected $Translations;
  47. protected $CustomTranslationContent;
  48. protected $CurrentOffset;
  49. protected $PostsPerPage;
  50. protected $HotPostCount;
  51. protected $LoggedIn;
  52. protected $LoginTokens;
  53. protected $InHereMode;
  54. protected $InExperimentalMode;
  55. protected $LanguageAppendix;
  56. protected $UseRemoteFont;
  57. protected $Posts;
  58. protected $Threads; // [ keys: first last displayed count]
  59. protected $WaybackThreads;
  60. public $Images;
  61. protected $Galleries;
  62. protected $Anchors;
  63. protected $ArchiveHandles;
  64. protected $Archive;
  65. public $WayBack;
  66. protected $YearBegin;
  67. protected $YearEnd;
  68. protected $Markers;
  69. protected $ExtraScripts;
  70. protected $APubID;
  71. protected $APubActor;
  72. protected $APubPublicKey;
  73. protected $APubPrivateKey;
  74. protected $TIME_STRING;
  75. public $NULL_POST;
  76. public $NULL_IMAGE;
  77. public $NULL_IMAGE_DUMMY;
  78. public $NULL_Gallery;
  79. protected $DoneReadPosts;
  80. protected $DoneReadImages;
  81. protected $DoneReadArchive;
  82. protected $NeedWritePosts;
  83. protected $NeedWriteImages;
  84. protected $NeedWriteArchive;
  85. protected $HereDisplayTitle;
  86. protected $VisitedHere;
  87. protected $HereNumber;
  88. protected $HereMainImage;
  89. public $PageType;
  90. public $CurrentPostID;
  91. public $HereID;
  92. public $ActualPostID;
  93. public $TagID;
  94. function ReadableTime($id){
  95. $dt = DateTime::createFromFormat('YmdHis', $id);
  96. return $dt->format('Y/m/d H:i:s');
  97. }
  98. function StandardTime($id){
  99. $dt = DateTime::createFromFormat('YmdHis', $id);
  100. return $dt->format('Y-m-d\TH:i:sP');
  101. }
  102. function FullURL(){
  103. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  104. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  105. $_SERVER['REQUEST_URI'];
  106. }
  107. function T($str){
  108. if(!$this->LanguageAppendix) return $str;
  109. foreach($this->Translations as $entry){
  110. if($entry['zh']==$str)
  111. return $entry[$this->LanguageAppendix];
  112. }
  113. return $str;
  114. }
  115. function SwitchLanguageAndFont(){
  116. $this->LanguageAppendix = 'zh';
  117. if(isset($_COOKIE['la_language'])){
  118. $this->LanguageAppendix = $_COOKIE['la_language'];
  119. }else{
  120. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  121. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  122. $lang = substr($lang,0,5);
  123. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  124. else $this->LanguageAppendix = 'en';
  125. }
  126. }
  127. if(isset($_COOKIE['la_font'])){
  128. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  129. }
  130. }
  131. function SwitchWayBackMode(){
  132. if(isset($_COOKIE['la_wayback'])){
  133. $this->WayBack = $_COOKIE['la_wayback'];
  134. }else $this->WayBack = NULL;
  135. }
  136. function DisplayRedirectConfig(){
  137. $s = "";
  138. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  139. if($r['for']=='P'){
  140. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  141. }else if($r['for']=='S'){
  142. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  143. }
  144. }
  145. return $s;
  146. }
  147. function DoSiteRedirect(){
  148. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  149. if($r['for']=='S'){
  150. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  151. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  152. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  153. }else{
  154. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. function WriteHTACCESS(){
  161. $conf = fopen('.htaccess','w');
  162. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  163. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  164. if($r['for']=='P'){
  165. if(!preg_match('/[0-9]{14}/',$r['target'])){
  166. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?'.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  167. }
  168. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  169. }// do site redirect in php.
  170. }
  171. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  172. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  173. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  174. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  175. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  176. fflush($conf);fclose($conf);
  177. }
  178. function BuildRedirectConfig($conf){
  179. $this->Redirect=[];
  180. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14}|.+)\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  181. foreach($ma as $m){
  182. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  183. $this->Redirect[]=$redirect;
  184. }
  185. }
  186. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  187. foreach($ma as $m){
  188. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  189. $this->Redirect[]=$redirect;
  190. }
  191. }
  192. }
  193. function WriteTokens(){
  194. $tf = fopen('la_tokens.php','w');
  195. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  196. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  197. foreach($this->LoginTokens as $t){
  198. fwrite($tf,'- '.$t.PHP_EOL);
  199. }
  200. }
  201. fflush($tf);fclose($tf);
  202. }
  203. function WriteConfig(){
  204. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  205. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  206. if(!isset($this->Admin)) $this->Admin = 'admin';
  207. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  208. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  209. $conf = fopen('la_config.php','w');
  210. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  211. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  212. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  213. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  214. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  215. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  216. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  217. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  218. fwrite($conf,'- SpecialSidebar = '.$this->SpecialSidebar.PHP_EOL);
  219. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  220. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  221. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  222. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  223. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  224. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  225. fwrite($conf,'- HereHost = '.$this->HereHost.PHP_EOL);
  226. fwrite($conf,'- HereTitle = '.$this->HereTitle.PHP_EOL);
  227. fwrite($conf,'- HereShortTitle = '.$this->HereShortTitle.PHP_EOL);
  228. fwrite($conf,'- HereAlbum = '.$this->HereAlbum.PHP_EOL);
  229. fwrite($conf,'- HereNavigation = '.$this->HereNavigation.PHP_EOL);
  230. fwrite($conf,'- HereFooter = '.$this->HereFooter.PHP_EOL);
  231. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  232. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  233. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  234. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  235. fwrite($conf,'- ExpAlbum = '.$this->ExpAlbum.PHP_EOL);
  236. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  237. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  238. fwrite($conf,'- MastodonToken = '.$this->MastodonToken.PHP_EOL);
  239. fwrite($conf,'- MastodonURL = '.$this->MastodonURL.PHP_EOL);
  240. fwrite($conf,'- MastodonPreferredLang = '.$this->MastodonPreferredLang.PHP_EOL);
  241. fwrite($conf,'- HostURL = '.$this->HostURL.PHP_EOL);
  242. fwrite($conf,'- APubID = '.$this->APubID.PHP_EOL);
  243. fwrite($conf,'- GalleryStep = '.$this->GalleryStep.PHP_EOL);
  244. fwrite($conf,'- AllowLanguageChoices = '.$this->AllowLanguageChoices.PHP_EOL);
  245. fflush($conf);fclose($conf);
  246. $conf = fopen('la_redirect.md','w');
  247. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  248. $this->WriteHTACCESS();
  249. $this->WriteTokens();
  250. }
  251. function Install(){
  252. if(!file_exists('la_config.php')){
  253. $this->WriteConfig();
  254. }
  255. if(!is_dir('posts')) mkdir('posts');
  256. if(!is_dir('images')) mkdir('images');
  257. if(!is_dir('images/thumb')) mkdir('images/thumb');
  258. if(!is_dir('styles')) mkdir('styles');
  259. if(!is_dir('archive')) mkdir('archive');
  260. $this->WriteStyles();
  261. $this->WriteHTACCESS();
  262. }
  263. function ReadFromExistingConfig(){
  264. $f=null;
  265. if(file_exists('la_config.php')) $f='la_config.php';
  266. else if(file_exists('la_config.md')) $f='la_config.md';
  267. if(!isset($f)) return;
  268. $c = file_get_contents($f);
  269. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  270. $str = $m[1];
  271. $this->$str = $m[2];
  272. }
  273. $this->CommentEnabled = $this->CommentEnabled=="True";
  274. if(!isset($this->GalleryStep)) $this->GalleryStep=20;
  275. }
  276. function ReadConfig(){
  277. $this->ReadFromExistingConfig();
  278. if(file_exists('la_redirect.md')){
  279. $c = file_get_contents('la_redirect.md');
  280. $this->BuildRedirectConfig($c);
  281. }
  282. if(!file_exists('la_config.php')){
  283. $this->Install();
  284. }
  285. $this->Translations=[];
  286. if(file_exists("translations.md")){
  287. $c = file_get_contents('translations.md');
  288. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  289. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  290. $this->Translations[] = $entry;
  291. }
  292. }
  293. if(file_exists("custom_translations.md")){
  294. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  295. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  296. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  297. $this->Translations[] = $entry;
  298. }
  299. }
  300. $this->LoginTokens=[];
  301. if(file_exists('la_tokens.php')){
  302. $c = file_get_contents('la_tokens.php');
  303. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  304. $this->LoginTokens[] = $m[1];
  305. }
  306. }
  307. }
  308. function MastodonPostStatus($status){ return $this->MastodonCall('/api/v1/statuses', 'POST', $status); }
  309. function MastodonPostMedia($media){ return $this->MastodonCall('/api/v1/media', 'POST', $media); }
  310. function MastodonCall($endpoint, $method, $data){
  311. $headers = [
  312. 'Authorization: Bearer '.$this->MastodonToken,
  313. 'Content-Type: multipart/form-data',
  314. ];
  315. $ch = curl_init();
  316. curl_setopt($ch, CURLOPT_URL, $this->MastodonURL.$endpoint);
  317. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  318. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  319. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  320. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  321. $reply = curl_exec($ch);
  322. if (!$reply) {
  323. return json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch_status), 'curl_error' => curl_error(ch_status)]);
  324. }
  325. curl_close($ch);
  326. return json_decode($reply, true);
  327. }
  328. function MastodonSendPost(&$post, &$errmsg=NULL){
  329. if(isset($post['mark_value']) && $post['mark_value']==7){ return NULL; }
  330. $this->LanguageAppendix = 'zh';
  331. if(in_array($this->MastodonPreferredLang,['en','zh'])){ $this->LanguageAppendix = $this->MastodonPreferredLang; }
  332. $this->ConvertPost($post);
  333. $media_ids = NULL;
  334. $mastodon_post_url = NULL;
  335. $imcount = 0;
  336. if(isset($post['original_images']) && isset($post['original_images'][0])) foreach($post['original_images'] as $im){
  337. $curl_file = curl_file_create($im, mime_content_type($im), basename($im));
  338. $body = ['file' => $curl_file,]; $response = $this->MastodonPostMedia($body);
  339. if(isset($response['id'])){ if(!isset($media_ids)){$media_ids=[];} $media_ids[]=$response['id']; }
  340. else{ if(isset($response['error'])) $errmsg.=$response['error']."<br /><br />"; }
  341. $imcount++; if($imcount>=4){ break; }
  342. }
  343. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$post['html']));
  344. if(isset($this->HostURL) && $this->HostURL!=""){
  345. $text.=("\n\n".$this->T('来自').' '.$this->HostURL.'?post='.$post['id']);
  346. }
  347. $vis = (isset($post['mark_value']) && $post['mark_value']==6)?"private":"public";
  348. $status_data = [ 'status' => $text, 'visibility' => $vis, 'language' => $this->LanguageAppendix, ];
  349. if(isset($post['prev']) && ($pp=&$this->GetPost($post['prev']))!=$this->NULL_POST){
  350. if(isset($pp['mastodon_url'])){ $status_data['in_reply_to_id'] = basename($pp['mastodon_url']);
  351. }
  352. }
  353. if(isset($media_ids[0])){ $status_data['media_ids']=$media_ids; }
  354. $status_data = preg_replace('/(media_ids%5B)[0-9]+(%5D)/','$1$2', http_build_query($status_data));
  355. $status_response = $this->MastodonPostStatus($status_data);
  356. if(isset($status_response['url']) && $status_response['url']){
  357. $mastodon_post_url = $status_response['url'];
  358. $post['mastodon_url'] = $mastodon_post_url;
  359. $this->NeedWritePosts = 1;
  360. }
  361. if(isset($status_response['error'])) { $errmsg .= $status_response['error']; }
  362. return $mastodon_post_url;
  363. }
  364. function __construct() {
  365. $this->ReadConfig();
  366. $this->PDE = new ParsedownExtra();
  367. $this->PDE->SetInterlinkPath('/');
  368. $this->Posts = [];
  369. $this->Threads = [];
  370. $this->VisitedHere = [];
  371. $this->NULL_IMAGE_DUMMY = [];
  372. $this->NULL_IMAGE_DUMMY['name']=$this->NULL_IMAGE_DUMMY['file']=$this->NULL_IMAGE_DUMMY['thumb']="";
  373. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  374. $this->PostsPerPage = 40;
  375. $this->CommentsPerPage = 100;
  376. $this->HotPostCount = 15;
  377. $this->TIME_STRING = date('YmdHis');
  378. $this->WayBack = NULL;
  379. $this->YearBegin = $this->YearEnd = 2000;
  380. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  381. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  382. $this->UsePosts = &$this->Posts;
  383. }
  384. function DoLogout(){
  385. $this->LoggedIn = false;
  386. unset($_SESSION['user_id']);
  387. $this->RecordToken(true);
  388. }
  389. function RecordToken($unset_current=false){
  390. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  391. $t = $_COOKIE['la_token'];
  392. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  393. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  394. $this->WriteTokens();
  395. return null;
  396. }else{
  397. $t = uniqid('la_',true);
  398. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  399. $this->LoginTokens[] = $t;
  400. $this->WriteTokens();
  401. return $t;
  402. }
  403. }
  404. function LoginThroughToken(){
  405. if(!isset($_COOKIE['la_token'])) return false;
  406. $t = $_COOKIE['la_token'];
  407. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  408. $_SESSION['user_id']=$this->Admin;
  409. $this->LoggedIn = true;
  410. setcookie('la_token',$t,time()+3600*24*7);
  411. return true;
  412. }
  413. return false;
  414. }
  415. function DoLogin(){
  416. session_start();
  417. $redirect=false;
  418. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  419. else if(!isset($_SESSION['user_id'])){
  420. if(isset($_POST['login_button'])){
  421. $id = trim($_POST['login_id']);
  422. $pwd = trim($_POST['login_password']);
  423. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  424. $_SESSION['user_id']=$id;
  425. $this->RecordToken(false);
  426. }
  427. $redirect = true;
  428. }else if($this->LoginThroughToken()){
  429. // nothing;
  430. }
  431. }else{
  432. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  433. else{ $this->DoLogout();}
  434. }
  435. if($redirect){
  436. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  437. .(isset($_GET['settings'])?"?settings=true":""));
  438. }
  439. }
  440. function SetHereMainImage($im_this){
  441. if(isset($im_this) && isset($im_this['parent'])){ $this->HereMainImage = &$this->FindImage($im_this['parent'],true);}
  442. }
  443. function RecordVisitedHere($image_or_post_name, $image_title){
  444. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  445. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  446. if(!(isset($_SESSION[$visited_here][0]) && in_array($image_or_post_name,$_SESSION[$visited_here]))){
  447. $_SESSION[$visited_here][] = $image_or_post_name;
  448. }
  449. if(isset($image_title)){ $this->HereDisplayTitle=$image_title; }
  450. $this->HereNumber = array_search($image_or_post_name,$_SESSION[$visited_here])+1;
  451. $_SESSION['here_number'] = $this->HereNumber;
  452. $this->VisitedHere = $_SESSION[$visited_here];
  453. }
  454. function HereLinkFromNumber($number){
  455. $number -= 1; if($number<0){ $number=0; }
  456. if($number>=sizeof($this->VisitedHere)){ $number = sizeof($this->VisitedHere)-1; }
  457. if(preg_match('/(jpg|jpeg|png|gif)/u',$this->VisitedHere[$number])){ return "?here=images/".$this->VisitedHere[$number]; }
  458. else{ return "?post=".$this->VisitedHere[$number]; }
  459. }
  460. function WriteStyles(){
  461. $this->style="
  462. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  463. body{background-color:%white%;color:%black%;}
  464. sup,sub{line-height:0;} .lpctrl{display:none;}
  465. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  466. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  467. b,strong,th{font-weight:bold;}
  468. select{font-size:inherit;}
  469. .page,.page_gallery{padding:1em;padding-top:0;padding-bottom:0;}
  470. .hidden_on_desktop,.hidden_on_wide{display:none;}
  471. .hidden_on_desktop_force{display:none !important;}
  472. ::file-selector-button{background:none;border:none;}
  473. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  474. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  475. .button:disabled{background-color:%gray%;pointer-events:none;}
  476. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;box-shadow: 0.5em 0px %white%;}
  477. 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;}
  478. header>div{overflow:auto;white-space:nowrap;}
  479. .header_nav{display:inline;}
  480. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  481. header a:hover,.button:hover{color:%gray% !important;}
  482. .exp_h_f{padding-top:0.3em !important;padding-bottom:0.3em !important;line-height:1.5em !important;height:2.1em !important;}
  483. .exp_f{text-align:center;}
  484. .toc_button{position:absolute;top:0.5em;right:0;text-shadow: 0px 0px 10px %white%;background-color:%white%88;}
  485. .footer{background-color:%white%;z-index:10;position:relative;}
  486. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  487. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  488. .gray,.gray a{color:%gray%;}
  489. hr{border:1px solid %gray%aa;}
  490. header ul,.small_footer ul,.small_footer span,header li,.small_footer li{display:inline-block;}
  491. header li::before,.small_footer li::before{content:' - '}
  492. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  493. .main{position:relative;word-spacing:-1em;}
  494. .main *{word-spacing:initial;}
  495. pre{overflow:auto;max-width:100%;display:block;}code{font-size:0.83em;}
  496. ul{display:block;}
  497. li{display:block;}
  498. .clean_table{border:none;font-size:1em !important;}.clean_table thead{box-shadow:none;}.clean_table td{vertical-align:top;}
  499. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  500. table input{border:none!important;}
  501. table img{max-width:10rem !important;}
  502. td{padding-left:0.1em;padding-right:0.1em;}
  503. td:first-child{padding-left:0;}
  504. td:last-child{padding-right:0;}
  505. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  506. thead{box-shadow:inset 0 -1px 0 0px %black%;}
  507. .post table{font-size:0.85em;}
  508. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  509. .interesting_tbody td{display:contents;}
  510. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  511. .interesting_tbody td>*{display:table-cell;}
  512. .interesting_tbody td>.wscroll{display:none !important;}
  513. .interesting_tbody .post_access{padding-top:0;}
  514. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  515. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  516. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  517. .interesting_tbody td>.imd>a{display:flex;}
  518. .interesting_tbody img{object-fit:cover;width:100%;}
  519. .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);}
  520. .interesting_tbody .p_thumb{height:1em;}
  521. .interesting_tbody .p_thumb img,.interesting_tbody .p_thumb video{max-height:10rem !important;max-width:20rem !important;}
  522. tr:hover .post_menu_button{opacity:1;}
  523. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  524. .align_right{text-align:right;}
  525. .left{display:inline-block;vertical-align:top;width:25%;padding-right:1.5em;padding-bottom:4rem;position:sticky;top:2em;
  526. overflow:auto;max-height:calc(100vh - 2.6em);}
  527. .center{display:inline-block;vertical-align:top;width:50%;overflow:visible;padding-bottom:4rem;}
  528. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  529. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  530. .center_wide .p_thumb{height:12rem;margin:0;}
  531. .linked_posts{margin-right:1.5em;padding:0.5em;padding-left:2.5em;background-color:%grayslice%;box-shadow:0px 0.2em 0.2em -0.2em inset %shadow%;}
  532. .active_post .linked_posts{background-color:%highlight_slice%;}
  533. input:checked~.linked_posts{display:none;}
  534. .bkg_recent>.post,.bkg_section{background:%post_white%;box-shadow:0em 0em 0.4em %shadow%;margin-bottom:0.5em;}
  535. .bkg_recent>.post>.post_width :last-child{margin-bottom:0;}
  536. .sticky_title{position:sticky;top:calc(1.6rem + 2px);z-index:1;background-color:%white%;pointer-events:none;}
  537. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  538. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  539. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  540. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  541. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  542. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  543. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  544. .post{position:relative;scroll-margin:3.5em;}
  545. .active_post{background-color:%highlight_white%;}.active_post .post_access{background-color:%highlight_slice%;}
  546. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;}
  547. .post_width li,.footer_additional li,.footer_additional li,.post_dummy li
  548. {display:list-item;margin-left:1em;list-style:disc;}
  549. .post_width li li,.footer_additional li li,.footer_additional li li,.post_dummy li li
  550. {list-style:circle;}
  551. ol li{list-style:unset !important;}
  552. .post_width > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  553. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  554. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  555. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  556. .gallery_left .selected{list-style:'→';}
  557. .bkg_section .post_width{padding-top:0;padding-bottom:0;}
  558. .bkg_section .print_title+.post .post_width{padding-top:0.5em;}
  559. .bkg_section .post:not(.print_title):first-of-type .post_width{padding-top:0.5em;}
  560. .bkg_section .restart+.post .post_width{padding-top:0.5em;}
  561. .post_width{position:relative;width:calc(100% - 1.5rem);overflow:auto;padding:0.5rem;}
  562. .ref_count{position:absolute;width:100%;bottom:0.5em;font-weight:bold;color:%gray%;}
  563. .active_post .ref_count{color:%black%;}
  564. .ref_count::after{content: \" \";display:block;width:10em;background:linear-gradient(to right,#0000,%gray%);height:2px;
  565. bottom:-0.5em;position:absolute;right:0;}
  566. //.ref_count::after{content: \" \";display:block;width:0.1em;background-color:%gray%;height:100%;margin-left:0.7em;}
  567. //.lpctrl:checked~.post_width{box-shadow: 1px 1px 1px 1px inset black;}
  568. .opt_compact .post_width,.ref_compact .post_width{padding-top:0;padding-bottom:0;}
  569. .p_thumb .post_menu_button{right:0.3rem;}
  570. .post_menu_button{position:absolute;display:none;top:0.3em;right:1.8rem;width:1.5rem;box-shadow:0px 0px 3px %shadow%;
  571. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;background-color:%post_white%aa;}
  572. .pointer{cursor:pointer;}
  573. .post:hover .post_menu_button{display:block;}
  574. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%grayslice%;
  575. padding:0.3em;right:1.8rem;text-align:right;border-radius:0.3em;font-size:1rem;
  576. box-shadow:0px 0px 10px %shadow%;}
  577. .pop_menu li{list-style:none;margin-left:0;}
  578. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  579. .toc{left:60%;width:40%;top:0;position:absolute;}
  580. .post_access{width:1.5rem;top:0;right:0;position:absolute;height:100%;text-align:center;font-weight:bold;background-color:%grayslice%;user-select:none;}
  581. .post_access:hover{filter:contrast(75%);}.post label{pointer-events:none;}.active_post label{pointer-events:all;}
  582. .paa{width:1.4rem;min-width:1.4rem;}
  583. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;background-color:%post_white%;right:unset;left:-2em;}
  584. .post_preview{overflow:hidden;margin-bottom:0.4em;background-color:%white%aa;box-shadow: 0px 0px 0.2em %shadow%;}
  585. .post_preview:hover{filter:contrast(90%);}
  586. .active_post .post_preview:hover{filter:contrast(90%);}
  587. .post .post_ref{margin:0;padding-left:1.5rem;}
  588. .post_ref_main{display:inline-block;vertical-align:top;max-height:6em;overflow:hidden;margin:0.4em;}
  589. .post_ref_images{overflow:hidden;margin:0.4em;margin-top:0;}
  590. .post_ref_hint{text-align:right;}
  591. .page_selector{padding-top:2rem;text-align:center;}
  592. .smaller{font-size:0.85em;} .bigger{font-size:1.3em;} .block{display:block;}
  593. .restart{text-align:right;padding:0.5rem;background-color:%grayslice%;}
  594. .opt_compact{margin-left:2rem;}.ref_compact{margin-left:1.5rem;}
  595. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  596. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  597. .spacer{height:0.5em;}
  598. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  599. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  600. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  601. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  602. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  603. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  604. .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;}
  605. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  606. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  607. .toc_entry_1{font-size:1.1em;}
  608. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  609. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  610. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  611. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  612. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  613. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  614. .deleted_post{color:%gray%;text-decoration:line-through;}
  615. #file_list{margin-top:0.5em;}
  616. .file_thumb img,.file_thumb video{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  617. .file_thumb video{border:2px dashed %black%;}f
  618. #file_list li{margin-bottom:0.3em;}
  619. .ref_thumb{white-space:nowrap;overflow:hidden;}
  620. .ref_thumb .file_thumb{width:2em;height:2em;margin:0;}
  621. .side_thumb li{margin:0.4em;display:inline-block;}
  622. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  623. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  624. .p_thumb{display:flex;flex-grow:100;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  625. .p_thumb_narrow{width:1rem;flex-grow:1;opacity:0.2;}
  626. .p_thumb img,.p_thumb video{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  627. .p_thumb:hover .post_menu_button{display:block;}
  628. .p_thumb_selected{color:%black% !important;}
  629. .p_thumb_selected{display:block;}
  630. .post .p_thumb img,.post .p_thumb video{max-height:6rem;}
  631. .p_thumb video{border-bottom:0.4em dashed %black%;border-top:0.4em dashed %black%;}
  632. .p_thumb_end{flex-grow:10000 !important;box-shadow:none;align-items:center;padding:2em !important;}
  633. .p_thumb_end:hover, .p_thumb_end a:hover{background-color:%gray%40;cursor:pointer;}
  634. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  635. .big_image_box *{pointer-events:auto;}
  636. .big_image_box img,.big_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  637. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  638. .here_image_box img,.here_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  639. .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;}
  640. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  641. .big_side_box a:hover{color:%gray%;}
  642. .big_side_box *{pointer-events:auto;}
  643. .big_side_box .post_preview{border:1px solid %gray%;background-color:unset;border-radius:0.3em;}
  644. .image_nav{pointer-events:none;}
  645. #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;
  646. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  647. img,video{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  648. .post img,.post video{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  649. .post > a > img,.post > a > video{display:block;margin:0.3em auto;}
  650. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  651. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  652. .center_exp .post .original_img{display:block;}
  653. .original_img img,.original_img video{max-height:90vh;max-width:100%;}
  654. .p_row .original_img{margin-bottom:0;}
  655. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  656. .imbtn{display:block;contain:content;padding:0.25em;margin-bottom:0.5em;text-decoration:none;text-shadow:0px 0px 5px %white%;}
  657. .imbtn img{display:block;object-fit:cover;position:absolute;top:0;left:0;bottom:0;right:0;margin:auto;z-index:-1;
  658. min-width:100% !important;min-height:100% !important;filter:opacity(40%);}
  659. .imbtn:hover img{filter:opacity(20%) blur(0.1em);} .imbtn:hover{color:%black% !important;}
  660. header .imbtn{display:inherit;border:none;padding:0em;height:unset;height:unset;margin:0em;contain:unset;}
  661. header .imbtn:hover{border:none;color:%gray% !important;} header .imbtn img{display:none;}
  662. .b ul{font-size:1.4em;}
  663. no_pop{cursor:unset;}
  664. p{min-height:0.8em;}
  665. .bold,.bold *{font-weight:bold;}
  666. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  667. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;box-shadow: 0.5em 0px %white%;}
  668. .small_footer>div{overflow:auto;white-space:nowrap;}
  669. .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;}
  670. .top_post_hint{margin-left:0.5em;font-weight:bold;}
  671. .white{color:%white%;}
  672. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  673. .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;
  674. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  675. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.4));
  676. background-repeat:no-repeat;background-size:0% 100%;}
  677. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  678. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  679. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  680. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  681. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  682. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  683. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  684. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  685. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  686. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  687. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  688. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  689. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  690. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  691. .special_paypal_inner{color:#169bd7;}
  692. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  693. animation:anim_loading 1s linear infinite;}
  694. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  695. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  696. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  697. .product_thumb img,{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  698. .product_ref p{margin-bottom:0.2em;text-align:left;}
  699. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  700. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  701. .page_break{page-break-after:always;}
  702. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  703. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  704. .print_title{display:none;}.show_on_print{display:none;}.inline_print{display:none;}
  705. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  706. .comment tbody tr:hover{box-shadow:none;}
  707. .comment table{border:none;}
  708. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  709. .comment ul{padding-left:1em;}
  710. .comment ul li *{margin-bottom:0.5em;}
  711. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  712. .history li li{list-style:circle;}
  713. .history ul{padding-left:1em;}
  714. .history a{text-decoration:underline;}
  715. .history .list{overflow:auto;white-space:nowrap;}
  716. .diff_table{table-layout:fixed;}
  717. .diff_table thead{font-size:0.9em;text-align:center;}
  718. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  719. .diff_table td{vertical-align:top;}
  720. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  721. .wayback_close{float:right;}
  722. .wayback_expand{display:inline;}
  723. .post_selecting .post *{pointer-events:none;}
  724. .post_selected{background-color:%graybkg%;}
  725. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  726. .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%;}
  727. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  728. .wayback_link{display:inline;}
  729. .imd{object-fit:cover;width:100%;}
  730. .center_exp .post>.imd,.center_exp .p_row{width:60%;}
  731. .center_exp .p_thumb img,.center_exp .p_thumb video{max-height:3rem;}
  732. .center_exp .p_thumb{max-height:3rem;filter:opacity(40%);}
  733. .center_exp .p_thumb:hover{filter:unset;}
  734. #here_buttons{display:contents;}
  735. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  736. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  737. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  738. .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;}
  739. @media screen and (max-width:1000px) and (min-width:666px){
  740. .left{width:35%;}
  741. .center,.center_wide{width:65%;}
  742. .center_wide .p_thumb{height:8rem;}
  743. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  744. .hidden_on_wide{display:unset;}
  745. .pop_right{width:30%;}
  746. .pop_right_big{width:40%;}
  747. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  748. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  749. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  750. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  751. .big_side_box{width:35%;}
  752. .big_image_box{width:65%;}
  753. .inquiry_buttons{right:35%;}
  754. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  755. .post_dummy > *{width:80%;max-width:55rem;}
  756. .center_exp .post>.imd,.center_exp .p_row{width:80%;max-width:55rem;}
  757. .here_btn{width:1.5em;height:1.5em;}
  758. }
  759. @media screen and (max-width:666px){
  760. html{font-size:16px;}
  761. #titlectrl:checked ~ header .mobile_fold{display:block !important;}
  762. #titlectrl:checked ~ .main .mobile_fold{display:block !important;}
  763. .mobile_fold{display:none !important;}
  764. .hidden_m{display:none !important;}
  765. .block_m{display:block !important;}
  766. .hidden_on_desktop{display:unset;}
  767. .hidden_on_wide{display:unset;}
  768. header{position:unset;}
  769. header ul{display:block;}
  770. header li{display:block;}
  771. header li::before{content:''}
  772. header::before{box-shadow:none;display:none;}
  773. .small_footer::before{box-shadow:none;display:none;}
  774. .left{position:relative;width:100%;top:unset;height:unset;max-height:unset;padding-right:0;display:block;}
  775. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  776. .center_wide .p_thumb{height:6rem;}
  777. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  778. .pop_right{height:30%;}
  779. .pop_right_big{height:70%;}
  780. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  781. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  782. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  783. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  784. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  785. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  786. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  787. .side_box_mobile_inner:hover{background-size:100% 100%;}
  788. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  789. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  790. .p_thumb{height:3rem;}
  791. .center .post{padding-right:0rem;padding-left:0rem;}
  792. .post .p_thumb img,.post .p_thumb video{max-height:3rem;}
  793. .page,.page_gallery{padding:0.2em;padding-top:0;}
  794. header{padding-top:0.3em;}
  795. .toc_button{top:0.3em;}
  796. .small_footer{padding-bottom:0.3em;}
  797. .footer_additional{display:block;width:100%;}
  798. .album_hint{display:block;font-size:1rem;}
  799. .image_nav{position:absolute !important;}
  800. .image_nav_prev,.image_nav_next{width:25%;}
  801. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  802. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  803. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  804. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  805. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  806. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  807. .opt_compact,.ref_compact{line-break:anywhere;}
  808. .table_top{left:unset;width:100%;overflow:auto;}
  809. table img{max-width:30vw !important;}
  810. .product_ref{width:100%;display:block;}
  811. .post_dummy > *{width:100%;max-width:25rem;}
  812. .center_exp .post>.imd,.center_exp .p_row{width:100%;max-width:25rem;}
  813. .center_exp .post .p_thumb img,.center_exp .post .p_thumb video{max-height:2rem;}
  814. .center_exp .p_thumb{height:2rem;filter:opacity(40%);}
  815. .center_exp .p_thumb:hover{filter:unset;}
  816. .sticky_title{top:0;}
  817. .small_footer{position:relative;}
  818. #upload_selector{width:100%;}
  819. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  820. .wayback_expand{display:block;text-align:center;}
  821. .wayback_link{display:block;}
  822. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  823. .center_exp .post{overflow:auto;}
  824. .center_exp .imd{width:100%;}
  825. .here_btn{width:1.2em;height:1.2em;}
  826. .exp_h_f{height:unset !important;}
  827. .exp_f{margin-bottom:1em;}
  828. .linked_posts{padding-left:1em;}
  829. }
  830. @media print{
  831. .small_footer .hidden_on_print{display:none;}
  832. header b,.small_footer b{font-weight:normal;}
  833. header{display:table-header-group;box-shadow:none;} .main{display:table-row-group;} .small_footer{text-align:right;}
  834. header::before{box-shadow:none;display:none;} header::after{display:block;height:1em;content:' ';}
  835. .small_footer::before{box-shadow:none;display:block;height:1em;position:relative;}
  836. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  837. .bkg_section,.bkg_recent>.post,.active_post{background:none !important;box-shadow:none;}
  838. .post *,.post_dummy *{margin-bottom:0em;}
  839. .p_row,.post table,.post_width>img,.post_ref>img,.post_ref>.original_img,
  840. .post_width>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  841. pre{white-space:pre-wrap;line-break:anywhere;}
  842. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  843. table img{margin:0 !important;}
  844. .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;}
  845. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  846. table{border-bottom:2px solid black;border-top:2px solid black;}
  847. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  848. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  849. .linked_posts{display:none;}
  850. .post_width{overflow:clip;left:0;width:100%;padding-left:0em;padding-right:0em;}
  851. .post h1{margin-top:0.5rem;}
  852. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  853. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h3{margin:0 !important;}
  854. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  855. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  856. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  857. .left{display:none;}
  858. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  859. hr{border:1px solid black;}
  860. .post_box_top{display:none;}
  861. .post_access{display:none;}
  862. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;background:unset;}
  863. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  864. .hidden_on_print{display:none;}
  865. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  866. .opt_compact{margin-left:0;left:1.5em;}
  867. .post .post_ref{padding-left:2rem;}
  868. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  869. .print_title:first-of-type{margin-top:1em;}
  870. .print_title+.post h1:first-of-type{display:none;}
  871. .bkg_section .print_title+.post .post_width{padding-top:0;}
  872. .bkg_section .post:not(.print_title):first-of-type .post_width{padding-top:0;}
  873. .bkg_section .restart+.post .post_width{padding-top:0;}
  874. .restart{background-color:unset;padding:unset;}
  875. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  876. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  877. .header_nav{display:none;}
  878. .show_on_print{display:block;}.inline_print{display:inline;}
  879. blockquote{border-left:2px solid black;}
  880. .footer_additional{display:none;}
  881. .small_footer{margin-top:1rem;box-shadow:none;}
  882. .page{display:table;width:100%;}
  883. .page_selector{display:none;}
  884. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  885. .post .p_thumb img,.post .p_thumb video{max-height:4rem;}
  886. .sticky_title{box-shadow:none;}
  887. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  888. .center_wide .p_row{display:block;}
  889. .interesting_tbody{background:none;}
  890. .interesting_tbody img{display:none !important;}
  891. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  892. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  893. }
  894. ";
  895. $this->style=preg_replace('/%highlight_white%/','#5b3607',$this->style);
  896. $this->style=preg_replace('/%highlight_slice%/','#734307',$this->style);
  897. $this->style=preg_replace('/%grayslice%/','#442c0b',$this->style);
  898. $this->style=preg_replace('/%post_white%/','#2d2110',$this->style);
  899. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  900. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  901. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  902. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  903. $this->style=preg_replace('/%shadow%/','#000000cc',$this->style);
  904. $f = fopen('styles/main.css','w');
  905. fwrite($f,$this->style);
  906. fclose($f);
  907. }
  908. function GiveSafeEMail(){
  909. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  910. }
  911. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  912. if(isset($this->Images[0])) foreach($this->Images as &$im){
  913. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  914. else { if($im['name']==$name) return $im; }
  915. }
  916. return $this->NULL_IMAGE;
  917. }
  918. function &GiveImageInHere($rand=false){
  919. $this->ReadImages(); $this->DetectPageType();
  920. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  921. if(!isset($album) || !$album){
  922. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  923. $imlist=[]; $imlist_fallback=[];
  924. if(isset($this->Images[0])){
  925. foreach($this->Images as &$im){
  926. if(isset($im['galleries'][0]) && in_array($album,$im['galleries']) && $this->CanShowImage($im)){
  927. if(!$rand) return $im; else {
  928. $imlist_fallback[] = $im;
  929. if(!in_array($im['name'],$this->VisitedHere)) $imlist[] = $im;
  930. }
  931. }
  932. }
  933. }
  934. if(!$rand || !isset($imlist_fallback[0])) return $this->NULL_IMAGE;
  935. if(sizeof($imlist)){
  936. $r = random_int(0, sizeof($imlist)-1);
  937. return $imlist[$r];
  938. }else{
  939. $r = random_int(0, sizeof($imlist_fallback)-1);
  940. return $imlist_fallback[$r];
  941. }
  942. }
  943. function ImageTitle($im){
  944. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  945. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  946. return $imtitle;
  947. }
  948. function ImageHasHere(&$im, $here_name){
  949. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  950. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  951. }
  952. function ReadImages($clear_non_exist = false){
  953. $path = 'images/list.md';
  954. if($this->DoneReadImages){ return; }
  955. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  956. $c = file_get_contents($path);
  957. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  958. $g=[]; $g['name']=$m[1];//$g['count']=0;
  959. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  960. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  961. $this->Galleries[] = $g;
  962. }
  963. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  964. $name = trim($m[1]);
  965. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  966. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  967. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  968. $item['refs']=[];
  969. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  970. }
  971. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  972. $item['galleries']=[];
  973. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  974. }
  975. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  976. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  977. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  978. if(preg_match('/ALIGN\s+([^;]*);/u',$m[2],$align)){ $item['align']=$align[1]; }
  979. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  980. $item['here']=[];
  981. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  982. }
  983. if(preg_match('/\.mp4/u',$item['name'])){
  984. $item['video']='video/mp4';
  985. }
  986. $this->Images[] = $item;
  987. }
  988. $files = array_merge([],glob('images/*.jpg'));
  989. $files = array_merge($files,glob('images/*.jpeg'));
  990. $files = array_merge($files,glob('images/*.png'));
  991. $files = array_merge($files,glob('images/*.gif'));
  992. $files = array_merge($files,glob('images/*.mp4'));
  993. if(isset($files[0]))foreach($files as $file) {
  994. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png|mp4)/u', $file, $m)) {
  995. $name = trim($m[0]);
  996. if(!$this->FindImage($name)){
  997. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  998. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  999. $this->Images[] = $item;
  1000. }
  1001. }
  1002. }
  1003. if($clear_non_exist){
  1004. if(isset($this->Images[0]) && isset($files[0])){
  1005. foreach($this->Images as &$im){
  1006. if(!in_array($im['file'],$files)){
  1007. $im['deleted'] = 1;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. function cmpf($a, $b){
  1013. if ($a['name'] == $b['name']) return 0;
  1014. return (($a['name'] > $b['name']) ? 1 : -1);
  1015. }
  1016. function cmpaf($a, $b){
  1017. if ($a['name'] == $b['name']) return 0;
  1018. return ($a['name'] > $b['name']) ? -1 : 1;
  1019. }
  1020. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  1021. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  1022. $this->DoneReadImages = 1;
  1023. }
  1024. function WriteImages(){
  1025. if(isset($this->WayBack)) return;
  1026. $path = 'images/list.md';
  1027. $f = fopen($path,'w');
  1028. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  1029. if(isset($g['deleted'])) continue;
  1030. fwrite($f,'GALLERY '.$g['name']);
  1031. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  1032. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  1033. fwrite($f, PHP_EOL);
  1034. }
  1035. if(isset($this->Images[0]))foreach($this->Images as &$im){
  1036. if(isset($im['deleted'])) continue;
  1037. fwrite($f, "- ".$im['name'].'; ');
  1038. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  1039. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  1040. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  1041. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  1042. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  1043. if(isset($im['align']) && $im['align']!='' && $im['align']!='middle'){ fwrite($f, 'ALIGN '.$im['align']."; "); }
  1044. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  1045. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  1046. }
  1047. fwrite($f, PHP_EOL);
  1048. }
  1049. fflush($f);
  1050. fclose($f);
  1051. }
  1052. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL, $align=NULL){
  1053. if(!($im = &$this->FindImage($name))) return;
  1054. if(isset($link_gallery)){
  1055. if($do_remove){
  1056. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  1057. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  1058. $im['galleries'] = array_merge($im['galleries']);
  1059. }else{
  1060. if(!isset($im['galleries'])) $im['galleries']=[];
  1061. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  1062. $im['galleries'][]=$link_gallery;
  1063. }
  1064. }
  1065. if(isset($product_link)){
  1066. if($product_link!=''){$im['product']=$product_link;}
  1067. else{unset($im['product']);}
  1068. }
  1069. if(isset($rename) && $rename!=$im['name']){
  1070. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1071. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1072. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1073. $im['name'] = $rename.'.'.$ext;
  1074. }
  1075. if(isset($parent) && $parent!=$im['parent']){
  1076. if($parent==''){ unset($im['parent']); }
  1077. else{ $im['parent'] = $parent; }
  1078. }
  1079. if(isset($align) && in_array($align,['top','middle','bottom'])){
  1080. if($align=='middle'){ unset($im['align']); }
  1081. else{ $im['align']=$align; }
  1082. }
  1083. $this->NeedWriteImages = 1;
  1084. }
  1085. function RegenerateThumbnails(){
  1086. $glob = glob('images/*.jpg');
  1087. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1088. foreach($glob as $file) {
  1089. $thumb_destination = 'images/thumb/'.basename($file);
  1090. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1091. $width=$geo['width']; $height=$geo['height'];
  1092. $lim=400;
  1093. $scale = $lim / min($width,$height);
  1094. if($scale<1){
  1095. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1096. }
  1097. $img->setImageFormat('jpeg');
  1098. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1099. $img->setImageCompressionQuality(90);
  1100. $img->writeImage($thumb_destination);
  1101. }
  1102. }
  1103. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max, $ext) {
  1104. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1105. $width=$geo['width']; $height=$geo['height'];
  1106. $lim=400;
  1107. $scale = $lim / min($width,$height);
  1108. if($scale<1){
  1109. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1110. }
  1111. $img->setImageFormat('jpeg');
  1112. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1113. $img->setImageCompressionQuality($quality);
  1114. $img->writeImage($thumb_destination);
  1115. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1116. if($scale<1){
  1117. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1118. }
  1119. if($ext!='jpg'){
  1120. $img2->setImageFormat('jpeg');
  1121. $img2->setImageCompressionQuality($quality);
  1122. $img2->writeImage($destination);
  1123. }else{
  1124. rename($source,$destination);
  1125. }
  1126. }
  1127. function DoUpload(){
  1128. if(!isset($_FILES['upload_file_name'])) return 0;
  1129. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1130. if($_FILES['upload_file_name']['error']>0){
  1131. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1132. return -1;
  1133. }else{
  1134. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  1135. if(!in_array($ext,['jpg','jpeg','png','gif','mp4'])) return 0;
  1136. $fp = fopen('.la_lock',"w");
  1137. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1138. usleep(10000);
  1139. }
  1140. $num=date('YmdHis'); $replace=0;
  1141. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1142. $num = $mim[1]; $replace=1;
  1143. }
  1144. $base = 'images/'.$num;
  1145. $thumb = 'images/thumb/'.$num;
  1146. if($ext=='png') $ext='jpg';
  1147. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  1148. if(!$replace) while(file_exists($final_path)){
  1149. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  1150. }
  1151. if($ext!='gif' && $ext!='mp4'){
  1152. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1153. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1154. $compress?800:1920, $compress?1920:2560, $ext);
  1155. }else{
  1156. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1157. }
  1158. flock($fp, LOCK_UN);
  1159. fclose($fp);
  1160. $this->ReadImages(true);
  1161. $this->WriteImages();
  1162. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1163. if(isset($_POST['image_replace_button'])){
  1164. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1165. }
  1166. exit;
  1167. return 1;
  1168. }
  1169. return 0;
  1170. }
  1171. function &GetGallery($name){
  1172. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1173. if($g['name'] == $name) return $g;
  1174. }
  1175. return $this->NULL_GALLERY;
  1176. }
  1177. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  1178. $this->ReadImages();
  1179. $gallery = &$this->GetGallery($name);
  1180. if(!isset($gallery)){
  1181. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1182. $g = []; $g['name']=$new_name;
  1183. $this->Galleries[]=$g;
  1184. }else{
  1185. if(isset($new_name)) {
  1186. if(preg_match('/main|trash|\s/u',$new_name))return;
  1187. $gallery['name'] = $new_name;
  1188. foreach ($this->Images as &$im){
  1189. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1190. if($g == $name){ $g = $new_name; }
  1191. }
  1192. }
  1193. }
  1194. //if(isset($count)) $gallery['count'] = $count;
  1195. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1196. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1197. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1198. }
  1199. if($do_rw) { $this->NeedWriteImages = 1; }
  1200. }
  1201. function ClearData(){
  1202. $this->Posts = [];
  1203. $this->Threads = [];
  1204. $this->Images = [];
  1205. $this->Archive = [];
  1206. $this->ArchiveHandles = [];
  1207. }
  1208. function InsertArchivePost(&$post){
  1209. $a = NULL;
  1210. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1211. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1212. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1213. }
  1214. $a['list'][] = $post;
  1215. $this->Archive[] = $post;
  1216. }
  1217. function ReadArchiveFromFile($path){
  1218. if(!file_exists($path)){
  1219. return;
  1220. }
  1221. $c = file_get_contents($path);
  1222. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1223. foreach($matches as $m){
  1224. $post = [];
  1225. $post['id'] = $m[1];
  1226. $post['content'] = trim($m[3]);
  1227. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1228. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1229. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1230. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1231. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1232. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1233. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1234. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1235. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1236. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1237. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1238. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1239. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1240. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1241. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1242. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1243. }
  1244. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1245. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1246. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1247. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1248. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1249. }
  1250. $this->InsertArchivePost($post);
  1251. }
  1252. }
  1253. }
  1254. function SortArchive(){
  1255. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1256. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1257. return (($a['id'] > $b['id']) ? 1 : -1);
  1258. };
  1259. if(isset($this->Archive[0])){
  1260. usort($this->Archive,$cmpap);
  1261. $year_begin = substr($this->Archive[0]['id'],0,4);
  1262. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1263. }
  1264. if(isset($this->ArchiveHandles[0])){
  1265. usort($this->ArchiveHandles,$cmpac);
  1266. foreach($this->ArchiveHandles as &$a){
  1267. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1268. $last_valid=NULL;
  1269. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1270. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1271. else{ $last_valid = $ver['content']; } }
  1272. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1273. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1274. }
  1275. }
  1276. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1277. $p['archive'] = &$a;
  1278. }
  1279. }
  1280. }
  1281. }
  1282. function ReadPostsFromFile($path){
  1283. if(!file_exists($path)){
  1284. $f = fopen($path,'w');
  1285. fclose($f);
  1286. }
  1287. $c = file_get_contents($path);
  1288. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1289. foreach($matches as $m){
  1290. $post = [];
  1291. $post['id'] = $m[1];
  1292. $post['real_content'] = trim($m[3]);
  1293. $post['content'] = &$post['real_content'];
  1294. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1295. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1296. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1297. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1298. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1299. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1300. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1301. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1302. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1303. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1304. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1305. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1306. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1307. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1308. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1309. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1310. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1311. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1312. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1313. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1314. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1315. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1316. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1317. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1318. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1319. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1320. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1321. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1322. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1323. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1324. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1325. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1326. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1327. }
  1328. if(isset($post['mark_value']) && $post['mark_value']==5){
  1329. $post['product']=[];
  1330. }
  1331. /* marks add here */
  1332. $this->Posts[] = $post;
  1333. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1334. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1335. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1336. }
  1337. }
  1338. }
  1339. }
  1340. function SortPosts($wayback=false){
  1341. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1342. $sortlist = &$this->Posts;
  1343. if($wayback) $sortlist = &$this->WaybackPosts;
  1344. if(isset($sortlist[0])){
  1345. usort($sortlist,$cmpp);
  1346. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1347. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1348. }
  1349. }
  1350. function ReadPosts(){
  1351. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1352. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1353. (!is_dir('posts') || is_readable('posts') == false) ||
  1354. (!is_dir('archive') || is_readable('archive') == false) ||
  1355. (!is_dir('images') || is_readable('images') == false) ||
  1356. (!is_dir('styles') || is_readable('styles') == false)){
  1357. $this->Install();
  1358. }
  1359. if($this->DoneReadPosts){ return; }
  1360. $file_list = [];
  1361. $glob = glob('posts/*');
  1362. foreach($glob as $file) {
  1363. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1364. $file_list[] = $file;
  1365. }
  1366. }
  1367. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1368. foreach($file_list as $f) {
  1369. $this->ReadPostsFromFile($f);
  1370. }
  1371. $this->SortPosts();
  1372. $this->DetectThreads();
  1373. $this->DoneReadPosts=1;
  1374. }
  1375. function UpdatePostRefsForWayback(){
  1376. if(!isset($this->WayBack)) return;
  1377. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1378. if(!isset($this->WaybackPosts[0])) return;
  1379. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1380. foreach($this->WaybackPosts as &$p){
  1381. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1382. $pr = &$this->GetPost($r); if(isset($pr)){
  1383. if(!isset($pr['refs'])) $pr['refs']=[];
  1384. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1385. }
  1386. }
  1387. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1388. $ir = &$this->FindImage($r); if(isset($ir)){
  1389. if(!isset($ir['refs'])) $ir['refs']=[];
  1390. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1391. }
  1392. }
  1393. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1394. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1395. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1396. }
  1397. }
  1398. }
  1399. function ReadArchive(){
  1400. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1401. if ($this->DoneReadArchive) return;
  1402. $file_list = []; $glob = glob('archive/*');
  1403. foreach($glob as $file) {
  1404. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1405. $file_list[] = $file;
  1406. }
  1407. }
  1408. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1409. foreach($file_list as $f) {
  1410. $this->ReadArchiveFromFile($f);
  1411. }
  1412. $this->SortArchive();
  1413. $this->DoneReadArchive=1;
  1414. $this->UpdateThreadForWayback();
  1415. $this->UpdatePostRefsForWayback();
  1416. }
  1417. function GetThreadForPost(&$post){
  1418. if(isset($post['tid'])) return;
  1419. $th = []; $iterp = NULL;
  1420. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1421. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1422. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1423. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1424. $np['tid'] = &$th;
  1425. $th['first'] = &$np;
  1426. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1427. }
  1428. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1429. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1430. $np['tid'] = &$th;
  1431. $th['last'] = &$np;
  1432. $iterp = isset($np['next'])?$np['next']:NULL;
  1433. }
  1434. if(isset($th['first']['mark_value'])){
  1435. if($th['first']['mark_value']==6) $th['exp'] = true;
  1436. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1437. }
  1438. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1439. $this->Threads[] = &$th;
  1440. }
  1441. function IdentifyThreadCategory(&$th,&$first_post){
  1442. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1443. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1444. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1445. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1446. }
  1447. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1448. }
  1449. if(preg_match('/\{\s*WIDE\s*\}/imu',$first_post['content'],$m)){ $first_post['wide'] = true; }
  1450. if(preg_match('/\{\s*NO_TIME\s*\}/imu',$first_post['content'],$m)){ $first_post['no_time'] = true; }
  1451. if(preg_match('/\{\s*NO_TITLE\s*\}/imu',$first_post['content'],$m)){ $first_post['no_title'] = true; }
  1452. if(preg_match('/\{\s*HEADER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['header'] = trim($m[1]); }
  1453. if(preg_match('/\{\s*FOOTER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['footer'] = trim($m[1]); }
  1454. if(!isset($th)) return;
  1455. if(isset($first_post['wide'])) $th['wide']=$first_post['wide'];
  1456. if(isset($first_post['header'])) $th['header']=$first_post['header'];
  1457. if(isset($first_post['footer'])) $th['footer']=$first_post['footer'];
  1458. if(isset($first_post['no_time'])) $th['no_time']=$first_post['no_time'];
  1459. if(isset($first_post['no_title'])) $th['no_title']=$first_post['no_title'];
  1460. if(preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1461. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1462. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1463. }
  1464. }
  1465. if(preg_match('/\{\s*REVERSED(\s+.*?)?\}/imu',$first_post['content'],$m)){ $th['reversed'] = 'm';
  1466. if(isset($m[1])&&preg_match('/^\s*(y|m|d|p)/iu',$m[1],$ma)){ $th['reversed']=$ma[1]; }
  1467. }
  1468. }
  1469. function IsInterestingPost(&$p){
  1470. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1471. return false;
  1472. }
  1473. function IsReversedThread(&$th){
  1474. if(isset($th['reversed']) && $th['reversed']!=false) return true;
  1475. return false;
  1476. }
  1477. function GiveAllMergedPosts(&$po,&$arr){
  1478. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1479. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1480. }
  1481. if(isset($po['archive']) && isset($po['archive']['list'])){
  1482. foreach($po['archive']['list'] as &$ver){
  1483. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1484. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1485. }
  1486. }
  1487. }
  1488. function ThreadMakeWayback(&$th){
  1489. if(!isset($th['arr'][0])) return;
  1490. if(isset($this->WayBack)){
  1491. $remlist = [];
  1492. foreach($th['arr'] as &$pi){
  1493. $po = &$this->GetPost($pi['id'],true); if(!isset($po)){continue;/*merged*/}
  1494. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1495. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1496. }
  1497. $ah = &$this->GetArchiveHandle($po['id']);
  1498. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1499. if(!isset($ver['merged_thread'])) continue;
  1500. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1501. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1502. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1503. }
  1504. }
  1505. }
  1506. if(isset($remlist[0]) && isset($th['arr'][0])){
  1507. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1508. foreach($th['arr'] as $key => $pr){
  1509. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1510. $new_th = []; $new_arr = [];
  1511. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1512. $new_th['arr'] = &$new_arr;
  1513. $this->WaybackThreads[] = &$new_th;
  1514. $this->ThreadMakeWayback($new_th);
  1515. }
  1516. }
  1517. }
  1518. function AddMergedPosts(&$p, &$array){
  1519. if(isset($p['archive']) && isset($p['archive']['list'])){
  1520. foreach($p['archive']['list'] as &$ver){
  1521. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1522. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1523. }
  1524. }
  1525. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1526. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1527. }
  1528. function &array_shift_ref(&$array){if(count($array)>0){$key=key($array);$first=&$array[$key];}else{$first=null;}array_shift($array);return $first;}
  1529. function FinalizeThread(&$th, $relink_posts=false, $now){
  1530. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1531. if(!isset($th['arr'])){
  1532. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1533. $arr[]=&$p;
  1534. } $th['arr'] = &$arr;
  1535. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1536. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1537. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1538. $arr=&$new_arr; $th['arr']=&$new_arr;
  1539. $this->ThreadMakeWayback($th); }
  1540. }
  1541. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1542. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1543. if($relink_posts){ $count = $th['count'];
  1544. $arr = &$th['arr'];
  1545. 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'];
  1546. $arr[$i]['tid']=&$th;}
  1547. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1548. }
  1549. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1550. $this->IdentifyThreadCategory($th, $th['first']);
  1551. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1552. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1553. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1554. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1555. if(isset($th['reversed'])){ $chunks=[]; $last_id=$last_y=$last_m=$last_d=0; $mo=$th['reversed']; $final=[];
  1556. $first_post=&$this->array_shift_ref($th['arr']); $ch=[];
  1557. while($n=&$this->array_shift_ref($th['arr'])){
  1558. $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);
  1559. if($mo=='y'&&$this_y!=$last_y){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y; }
  1560. if($mo=='m'&&$this_m!=$last_m){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m; }
  1561. if($mo=='d'&&$this_d!=$last_d){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m.'/'.$this_d; }
  1562. if($mo=='p'){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} }
  1563. $ch[]=$n; $last_id=$this_id; $last_y=$this_y; $last_m=$this_m; $last_d=$this_d;
  1564. }if(isset($ch[0])){$chunks[]=$ch;} if(isset($chunks[0])){$use_chunks=array_reverse($chunks);}
  1565. $final[]=&$first_post;
  1566. foreach($use_chunks as &$ch){ foreach($ch as &$p){ $final[]=&$p;} }
  1567. $th['arr']=$final; }
  1568. }
  1569. function SortThreads(){
  1570. if (!function_exists('cmpt')) {
  1571. function cmpt($a, $b){
  1572. if ($a['score'] == $b['score']) return 0;
  1573. return ($a['score'] > $b['score']) ? -1 : 1;
  1574. }
  1575. }
  1576. usort($this->Threads,"cmpt");
  1577. }
  1578. function DetectThreads(){
  1579. foreach($this->Posts as &$p){
  1580. if(isset($p['tid'])) { continue; }
  1581. $this->GetThreadForPost($p);
  1582. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1583. }
  1584. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1585. $now = date_timestamp_get(date_create());
  1586. foreach($this->Threads as &$t){
  1587. $this->FinalizeThread($t,false,$now);
  1588. }
  1589. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1590. $this->FinalizeThread($th,false,$now);
  1591. $this->Threads[] = &$th;
  1592. }
  1593. $this->SortThreads();
  1594. }
  1595. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1596. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1597. foreach($this->Threads as &$t){
  1598. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1599. }
  1600. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1601. $this->FinalizeThread($th,true,$now);
  1602. $this->Threads[] = &$th;
  1603. }
  1604. $this->SortThreads();
  1605. $this->SortPosts(true);
  1606. $this->UsePosts = &$this->WaybackPosts;
  1607. }
  1608. function &GetMergedPost($id){
  1609. $this->ReadArchive();
  1610. $ah = &$this->GetArchiveHandle($id);
  1611. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1612. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1613. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1614. [$tp, $tver] = $ver['merged_into'];
  1615. if(isset($this->WayBack)){
  1616. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1617. else return $this->GetPost($id); /* should not happen directly. */
  1618. }
  1619. return $this->GetMergedPost($tp);
  1620. }
  1621. function &GetPost($id, $latest_only=false, $find_merged=false){
  1622. if(!isset($id)) return $this->NULL_POST;
  1623. $found=&$this->NULL_POST;
  1624. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1625. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1626. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1627. }
  1628. if($latest_only || !isset($this->WayBack)){ return $found; }
  1629. else{
  1630. if(isset($found)){
  1631. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1632. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1633. $last_ver = &$this->NULL_POST;
  1634. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1635. if($ver['version'] > $this->WayBack) return $last_ver;
  1636. $last_ver = &$ver;
  1637. }
  1638. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1639. else return $last_ver;
  1640. }else{
  1641. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1642. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1643. if($ver['version'] > $this->WayBack) return $last_ver;
  1644. $last_ver = &$ver;
  1645. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1646. [$tp, $tver] = $last_ver['merged_into'];
  1647. if($tver <= $this->WayBack) {
  1648. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1649. return $last_ver;
  1650. }
  1651. }
  1652. }
  1653. return $this->NULL_POST;
  1654. }
  1655. function &GetArchiveHandle($id){
  1656. if(!isset($id)) return $this->NULL_POST;
  1657. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1658. if($p && $p['id'] == $id) { return $p; }
  1659. }
  1660. return $this->NULL_POST;
  1661. }
  1662. function &GetArchive($id){
  1663. if(!isset($id)) return $this->NULL_POST;
  1664. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1665. if($p && $p['id'] == $id) { return $p; }
  1666. }
  1667. return $this->NULL_POST;
  1668. }
  1669. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1670. if(!isset($ah)) return $this->NULL_POST;
  1671. $found = NULL; $last_verp=NULL;
  1672. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1673. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1674. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1675. $last_verp = &$p;
  1676. }
  1677. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1678. return $this->NULL_POST;
  1679. }
  1680. function CacheArchiveOwnLinks(){
  1681. if(isset($this->WayBack)) return;
  1682. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1683. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1684. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1685. foreach($matches as $m){
  1686. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1687. }
  1688. }
  1689. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1690. foreach($matches as $m){
  1691. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1692. }
  1693. }
  1694. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1695. foreach($matches as $m){
  1696. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1697. }
  1698. }
  1699. }
  1700. }
  1701. function WriteArchive(){
  1702. if(isset($this->WayBack)) return;
  1703. $cf = NULL;$opened =NULL;
  1704. $this->SortArchive();
  1705. $this->CacheArchiveOwnLinks();
  1706. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1707. $nid = substr($p['id'], 0,6);
  1708. if($cf != $nid){
  1709. if($opened){
  1710. fflush($opened);
  1711. fclose($opened);
  1712. }
  1713. $cf = $nid;
  1714. $opened = fopen("archive/$cf.md", 'w');
  1715. }
  1716. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1717. "VER {$p['version']}; ".
  1718. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1719. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1720. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1721. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1722. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1723. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1724. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1725. ']';
  1726. if(isset($p['merged_thread'])){ $p['content']=""; }
  1727. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1728. }
  1729. }
  1730. function WritePosts(){
  1731. if(isset($this->WayBack)) return;
  1732. $cf = NULL;$opened =NULL;
  1733. $this->SortPosts();
  1734. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1735. $nid = substr($p['id'], 0,6);
  1736. if($cf != $nid){
  1737. if($opened){
  1738. fflush($opened);
  1739. fclose($opened);
  1740. }
  1741. $cf = $nid;
  1742. $opened = fopen("posts/$cf.md", 'w');
  1743. }
  1744. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1745. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1746. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1747. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1748. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1749. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1750. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1751. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1752. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1753. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1754. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1755. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1756. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1757. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1758. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1759. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1760. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1761. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1762. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1763. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1764. ']';
  1765. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1766. }
  1767. }
  1768. function CachePostLinks(){
  1769. if(isset($this->WayBack)) return;
  1770. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1771. $this->ConvertPost($post);
  1772. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1773. //discard lost old version
  1774. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1775. }else return;
  1776. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1777. unset($im['refs']); unset($im['here']); unset($im['title']);
  1778. }
  1779. foreach ($this->Posts as &$post){
  1780. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1781. foreach($matches as $m){
  1782. $ref = &$this->GetPost($m[1],true);
  1783. if($ref!=NULL){
  1784. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1785. }
  1786. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1787. }
  1788. }
  1789. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1790. foreach($matches as $m){
  1791. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1792. }
  1793. }
  1794. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1795. foreach($matches as $m){
  1796. if(($im = &$this->FindImage($m[2]))!=NULL){
  1797. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1798. }
  1799. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1800. }
  1801. }
  1802. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\))(\R*(\R(-|\*).+){1,})/u",
  1803. $post['content'],$matches)){
  1804. $use_img_name = $matches[2];
  1805. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1806. 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",
  1807. $matches[4],$mah,PREG_SET_ORDER)){
  1808. foreach($mah as $ma){
  1809. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1810. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }foreach($this->Posts as &$post){
  1816. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1817. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1818. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1819. }
  1820. }
  1821. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1822. $min_id = '99999999999999';
  1823. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1824. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1825. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1826. }
  1827. }
  1828. }
  1829. function CreatePostAnchor(&$post){
  1830. $that=&$this;
  1831. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1832. $id = '_heading_'.sizeof($this->Anchors);
  1833. $entry=[(int)$ma[1], $id, $ma[2]];
  1834. $that->Anchors[] = $entry;
  1835. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1836. }, $post['html']);
  1837. }
  1838. function RenamePost(&$post, $rename){
  1839. foreach($this->Posts as &$p){
  1840. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1841. }
  1842. foreach($this->Posts as &$p){
  1843. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1844. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1845. }
  1846. $post['id'] = $rename;
  1847. }
  1848. function DetachPost(&$th,&$post){
  1849. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1850. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1851. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1852. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1853. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1854. unset($th['arr']); $now = date_timestamp_get(date_create());
  1855. $this->FinalizeThread($th, true, $now);
  1856. }
  1857. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1858. $a = &$this->GetArchiveHandle($post['id']);
  1859. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1860. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1861. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1862. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1863. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1864. $post['version'] = $optime_id;
  1865. if($mode==1){
  1866. $this->InsertArchivePost($ap);
  1867. }else if($mode==2){
  1868. $post['merged_from'] = $info;
  1869. $this->InsertArchivePost($ap);
  1870. }else if($mode==3){
  1871. $ap['merged_into'] = $info;
  1872. $this->InsertArchivePost($ap);
  1873. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1874. $this->DetachPost($post['tid'], $post);
  1875. }
  1876. }else if($mode==4){
  1877. $post['merged_thread'] = $info;
  1878. $this->InsertArchivePost($ap);
  1879. }
  1880. }
  1881. function &MergeThreads($post_id, $post_into_id){
  1882. $this->ReadPosts();
  1883. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1884. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1885. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1886. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1887. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1888. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1889. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1890. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1891. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  1892. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1893. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1894. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1895. $tt['count'] = sizeof($tt['arr']);
  1896. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1897. $first_post = &$this->NULL_POST;
  1898. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1899. $this->NeedWritePosts=1;
  1900. $this->NeedWriteArchive=1;
  1901. return $first_post;
  1902. }
  1903. function &MergePosts($ids_string){
  1904. $ids = explode(" ", $ids_string);
  1905. $combined_content = ""; $first_id=NULL;
  1906. $this->ReadPosts(); $child_list=[];
  1907. foreach($ids as $id){
  1908. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1909. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1910. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  1911. }
  1912. if(!isset($child_list[0])) return $this->NULL_POST;
  1913. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  1914. foreach($child_list as $id){
  1915. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  1916. }
  1917. $this->NeedWritePosts=1;
  1918. $this->NeedWriteArchive=1;
  1919. return $first_post;
  1920. }
  1921. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1922. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1923. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1924. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  1925. $this->ReadImages();
  1926. $this->ReadPosts();
  1927. if(isset($push_version) && $push_version){
  1928. $this->ReadArchive();
  1929. }
  1930. $p_success = NULL;
  1931. if(isset($id_if_edit)){
  1932. $post = &$this->GetPost($id_if_edit,true);
  1933. if($post===$this->NULL_POST) return $this->NULL_POST;
  1934. if($get_original_only){
  1935. return $post['real_content'];
  1936. }
  1937. if(isset($push_version) && $push_version){
  1938. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1939. }
  1940. if(isset($content)) {$post['real_content'] = $content; $post['content'] = &$post['real_content'];}
  1941. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1942. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1943. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1944. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  1945. $p_success = &$post;
  1946. }else{
  1947. if(!isset($content)) return $this->NULL_POST;
  1948. $id = date('YmdHis');
  1949. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1950. $post = []; $post['id'] = $id;
  1951. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1952. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1953. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1954. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1955. }
  1956. $this->Posts[] = $post;
  1957. $p_success = &$this->Posts[count($this->Posts) - 1];
  1958. }
  1959. $this->NeedWritePosts=1;
  1960. $this->NeedWriteImages=1;
  1961. if(isset($push_version) && $push_version){
  1962. $this->NeedWriteArchive=1;
  1963. }
  1964. return $p_success;
  1965. }
  1966. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1967. $this->ReadPosts();
  1968. $p_success = NULL;
  1969. if(isset($id_if_edit)){
  1970. $post = &$this->GetPost($id_if_edit,true);
  1971. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1972. if(isset($content)) $post['content'] = $content;
  1973. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1974. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1975. if(isset($ip)) $post['ip'] = $ip;
  1976. $p_success = &$post;
  1977. }else{
  1978. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1979. $id = date('YmdHis');
  1980. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1981. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1982. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1983. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1984. if(isset($ip)) $post['ip'] = $ip;
  1985. $this->Posts[] = $post;
  1986. $p_success = &$this->Posts[count($this->Posts) - 1];
  1987. }
  1988. $this->NeedWritePosts=1;
  1989. return $p_success;
  1990. }
  1991. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  1992. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1993. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1994. function($matches){
  1995. $rep = preg_replace('/->/','-@>',$matches[0]);
  1996. $rep = preg_replace('/=>/','=@>',$rep);
  1997. $rep = preg_replace('/<=/','<@=',$rep);
  1998. $rep = preg_replace('/<-/','<@-',$rep);
  1999. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  2000. $rep = preg_replace('/\[-/','[@-',$rep);
  2001. $rep = preg_replace('/\{/','{@',$rep);
  2002. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  2003. return $rep;
  2004. },
  2005. $replacement);
  2006. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  2007. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  2008. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  2009. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  2010. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  2011. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  2012. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  2013. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  2014. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  2015. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  2016. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  2017. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  2018. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  2019. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  2020. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  2021. function($matches){
  2022. $rep = preg_replace('/-@>/','->',$matches[0]);
  2023. $rep = preg_replace('/<@-/','<-',$rep);
  2024. $rep = preg_replace('/=@>/','=>',$rep);
  2025. $rep = preg_replace('/<@=/','<=',$rep);
  2026. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  2027. $rep = preg_replace('/\[@-/','[-',$rep);
  2028. $rep = preg_replace('/\{@/','{',$rep);
  2029. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  2030. return $rep;
  2031. }, $replacement);
  2032. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  2033. function($matches) use (&$post_for_it_is_here){
  2034. $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]);
  2035. return $matches[1].$rep;
  2036. }, $replacement);
  2037. return $replacement;
  2038. }
  2039. function CanShowPost(&$p){
  2040. if(!isset($p) || isset($p['comment_to'])) return false;
  2041. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  2042. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  2043. if($is_mark_slf && !$this->LoggedIn){ return false; }
  2044. if(isset($this->WayBack)){
  2045. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  2046. else if ($p['id']>$this->WayBack) return false;
  2047. }
  2048. if(!$this->InExperimentalMode){
  2049. if(!$this->LoggedIn){
  2050. if($is_mark_exp) return false;
  2051. return true;
  2052. }
  2053. return true;
  2054. }else{
  2055. if($is_mark_exp) return true;
  2056. return false;
  2057. }
  2058. }
  2059. function SkipProduct(&$p){
  2060. if($this->LoggedIn) return false;
  2061. return (isset($p['mark_value']) && $p['mark_value']==5);
  2062. }
  2063. function GetRedirect($args=NULL){
  2064. $str = 'index.php?';
  2065. if(isset($args['post'])) $str.='&post='.$args['post'];
  2066. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  2067. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  2068. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  2069. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  2070. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  2071. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  2072. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  2073. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  2074. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  2075. if(isset($args['category'])) $str.='&category='.$args['category'];
  2076. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  2077. if(isset($args['history'])) $str.='&history='.$args['history'];
  2078. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  2079. if(isset($args['version'])) $str.='&version='.$args['version'];
  2080. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  2081. if(isset($args['search'])) $str.='&search='.$args['search'];
  2082. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  2083. if(isset($args['here'])) $str.='&here='.$args['here'];
  2084. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  2085. return $str;
  2086. }
  2087. function WriteAsNecessary(){
  2088. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  2089. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  2090. if($this->NeedWriteImages){ $this->WriteImages(); }
  2091. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  2092. }
  2093. function APubEnsureWebfinger($name, $host){
  2094. if(!is_dir('.well-known')) mkdir('.well-known');
  2095. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  2096. $f = fopen('.well-known/webfinger/index.php',"w");
  2097. $without_protocol = parse_url($host, PHP_URL_HOST);
  2098. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  2099. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  2100. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  2101. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2102. $res = openssl_pkey_new();
  2103. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2104. openssl_pkey_export($res, $this->APubPrivateKey);
  2105. $f = fopen('.well-known/apub_public_key.pem',"w");
  2106. fwrite($f, $this->APubPublicKey); fclose($f);
  2107. $f = fopen('.well-known/apub_private_key.php',"w");
  2108. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2109. }
  2110. }
  2111. function APubInit(){
  2112. $kf = file_get_contents('.well-known/apub_private_key.php'); if($kf===false) return;
  2113. preg_match("/(-----BEGIN PRIVATE KEY-----[\s\S]*)/",$kf,$ma); $this->APubPrivateKey=$ma[1];
  2114. }
  2115. function APubEnsureInfo(){
  2116. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2117. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2118. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2119. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2120. "id"=> $this->HostURL."?apub_actor=1",
  2121. "type"=> "Person",
  2122. "name"=> $this->DisplayName,
  2123. "url"=> $this->HostURL,
  2124. "summary"=> "Lazy... No summary",
  2125. "preferredUsername"=> $this->APubID,
  2126. "inbox"=> $this->HostURL."?apub_inbox=1",
  2127. "outbox"=> $this->HostURL."?apub_outbox=1",
  2128. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2129. "owner"=> $this->HostURL."?apub_actor=1",
  2130. "publicKeyPem"=>$pk]];
  2131. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2132. }
  2133. function APubMakeOutbox(){
  2134. $this->ReadPosts();$this->ReadImages();
  2135. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2136. "id"=>$this->HostURL."?apub_outbox=1",
  2137. "type"=>"OrderedCollection"];
  2138. $items=[]; $i=0;
  2139. foreach(array_reverse($this->Posts) as &$p){
  2140. $this->ConvertPost($p);
  2141. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2142. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2143. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2144. "type"=> "Create",
  2145. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2146. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2147. //"to"=> ["https://chatty.example/ben/"],
  2148. "actor"=> $this->HostURL."?apub_actor=1",
  2149. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2150. "object"=> ["type"=> "Note",
  2151. "id"=> $this->HostURL."?post=".$p['id'],
  2152. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2153. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2154. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2155. "content"=> $text]];
  2156. $items[] = $ob;
  2157. $i++; if($i>20) break;
  2158. }
  2159. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2160. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2161. }
  2162. function APubDeliver($body,$target){
  2163. $head_digest = base64_encode(hash("sha256",$body,true));
  2164. $body_digest = "SHA-256=".$head_digest;
  2165. // rfc standards require the timezone be declared as GMT and PHP's built-in formats all say UTC
  2166. // so we gotta do it manually
  2167. $d = new DateTimeImmutable("now", new DateTimeZone('Asia/Shanghai'));
  2168. $d=$d->setTimezone(new DateTimeZone('UTC'));
  2169. $date=$d->format("D, d M Y H:i:s")." GMT";
  2170. $data = "(request-target): post ".parse_url($target,PHP_URL_PATH)
  2171. ."\nhost: ".parse_url($target,PHP_URL_HOST)
  2172. ."\ndate: $date"
  2173. ."\ndigest: $body_digest";
  2174. if (openssl_sign($data, $signature, $this->APubPrivateKey, OPENSSL_ALGO_SHA256) === FALSE) {
  2175. http_response_code(500); die('unable to sign');
  2176. }
  2177. $signature = base64_encode($signature);
  2178. $keyid = 'keyId="'.$this->HostURL.'?apub_actor=1#main-key"';
  2179. $algo = 'algorithm="rsa-sha256"';
  2180. $headers = 'headers="(request-target) host date digest"';
  2181. $signature = "signature=\"$signature\"";
  2182. $h = array(
  2183. 'Content-Type: application/activity+json',
  2184. 'Accept: application/activity+json',
  2185. //"Content-Length: ".strlen($body),
  2186. "Host: ". parse_url($target,PHP_URL_HOST),
  2187. "Date: $date",
  2188. "Digest: $body_digest",
  2189. "Signature: $keyid,$algo,$headers,$signature"
  2190. );
  2191. $ch = curl_init($target);
  2192. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2193. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
  2194. curl_setopt($ch, CURLOPT_HTTPHEADER, $h);
  2195. curl_setopt($ch, CURLOPT_USERAGENT, "laMDWiki APub");
  2196. $result = curl_exec($ch);
  2197. curl_close($ch); echo "<pre>";
  2198. print_r($body); echo "\n\n".$target."\n\n";
  2199. print_r($result); echo "\n\n"; print_r($h);
  2200. echo "\n\n"; print_r(curl_getinfo($ch)); echo "</pre>"; exit;
  2201. return $result;
  2202. }
  2203. function APubTestDeliver(){
  2204. $this->APubInit();
  2205. $obj=[];
  2206. $obj['published']=gmdate("Y-m-d\TH:i:s\Z");
  2207. $obj['id']=""; //<-------------------
  2208. $obj['url']=$this->HostURL.""; //<-------------------
  2209. $obj['type']='Note';
  2210. $obj['attributedTo']=$this->HostURL."?apub_actor=1";
  2211. $tag=[]; $tag['type']='Mention'; $tag['name']="@chengdulittlea"; $tag['href']="https://mastodon.art/users/chengdulittlea";
  2212. $obj['tag']=[$tag];
  2213. // must have cc to have notification in mastodon.
  2214. $obj['cc']=["https://mastodon.art/users/chengdulittlea"];
  2215. $obj['content']="<p>@chengdulittlea Hello activitypub from laMDWiki!</p>";
  2216. $obj['to']="https://www.w3.org/ns/activitystreams#Public";
  2217. $obj['inReplyTo']=""; //<-------------------
  2218. $arr=[];
  2219. $arr['@context']="https://www.w3.org/ns/activitystreams";
  2220. $arr['id']=""; //<-------------------
  2221. $arr['actor']=$this->HostURL."?apub_actor=1";
  2222. $arr['type']="Create";
  2223. $arr['to']="https://www.w3.org/ns/activitystreams#Public";
  2224. $arr['object']=$obj;
  2225. $this->APubDeliver(json_encode($arr),"https://mastodon.example/inbox"); //<-------------------
  2226. }
  2227. function APubProcessInbox(){
  2228. $r = file_get_contents('php://input');
  2229. file_put_contents('postdump.txt',$r);
  2230. }
  2231. function MakeRSS(){
  2232. $this->ReadPosts();$this->ReadImages();
  2233. $posts = []; if(isset($this->UsePosts[0])){
  2234. $posts = array_reverse($this->UsePosts);
  2235. $last_updated = $this->StandardTime($posts[0]['id']);
  2236. }else{ $last_updated= $this->StandardTime("20000101000000"); }
  2237. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2238. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2239. "<id>".$this->HostURL."/?rss</id>".
  2240. "<updated>".$last_updated."</updated>".
  2241. "<title>".$this->T($this->Title)."</title>".
  2242. "<link href='".$this->HostURL."/?rss' rel='self'/>".
  2243. "<link href='".$this->HostURL."' />".$author;
  2244. $i=0;
  2245. if(isset($posts[0])) foreach($posts as &$p){
  2246. if($i>100) break;
  2247. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2248. if(isset($p['tid'])){ /* Should always be set. */
  2249. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2250. if(in_array($p['id'],
  2251. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  2252. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2253. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2254. $is_reversed=false;
  2255. $content="<entry>"; $title = NULL;
  2256. if($is_thread){
  2257. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2258. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2259. foreach($use_arr as &$po){
  2260. $this->ConvertPost($po);
  2261. if(!isset($title)){$title = $this->GetPostTitle($po, false, false);
  2262. $content.="<id>".$this->HostURL."?post=".$po['id']."</id>";
  2263. $content.="<title>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$po['id']."' />";
  2264. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2265. $content.="<updated>".$this->StandardTime(isset($po['tid']['last']['version'])?
  2266. $po['tid']['last']['version']:$po['tid']['last']['id'])."</updated>".$author;
  2267. $content.="<content type='html'>"; }
  2268. $content.= htmlspecialchars($po['html']);
  2269. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2270. }
  2271. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2272. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2273. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2274. $content.="</content>";
  2275. }else{
  2276. $this->ConvertPost($p);
  2277. if(!isset($title)){$title = $this->GetPostTitle($p, false, false);
  2278. $content.="<id>".$this->HostURL."?post=".$p['id']."</id>";
  2279. $content.="<title>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$p['id']."' />";
  2280. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2281. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2282. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2283. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2284. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2285. $content.=$this->ReadableTime($p['id'])." - ".
  2286. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2287. $content.="</content>";
  2288. }
  2289. $i++;
  2290. $content.="</entry>";
  2291. $all_content.=$content;
  2292. }
  2293. $all_content.="</feed>";
  2294. header( "Content-type: text/xml");
  2295. echo $all_content;
  2296. }
  2297. function MakeHereButtons($im, $insert_here){
  2298. if(isset($im['here'])&&isset($im['here'][0])){
  2299. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2300. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2301. foreach($im['here'] as $here){
  2302. if($insert_here){
  2303. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2304. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2305. }else{
  2306. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2307. }
  2308. }
  2309. echo "</div>".($insert_here?"</here>":"");
  2310. }
  2311. }
  2312. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  2313. if(isset($_GET['gallery_continue']) && $_GET['gallery']){
  2314. $this->ReadImages();
  2315. $this->GetImageBatch($_GET['gallery_continue'],0);
  2316. exit;
  2317. }
  2318. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2319. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2320. return 0;
  2321. }
  2322. if(isset($_GET['set_language'])){
  2323. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2324. $redirect=$this->GetRedirect(); return 0;
  2325. }
  2326. if(isset($_GET['rss'])){
  2327. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2328. $this->MakeRSS(); exit;
  2329. }
  2330. if(isset($_GET['toggle_font'])){ $use_font='local';
  2331. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2332. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2333. $redirect=$this->GetRedirect(); return 0;
  2334. }
  2335. if(isset($_GET['set_wayback'])){
  2336. if($_GET['set_wayback']!='false'){
  2337. $wayback= date('YmdHis');
  2338. if($_GET['set_wayback']=='post'){
  2339. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2340. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2341. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2342. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2343. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2344. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2345. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2346. }else{
  2347. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2348. }
  2349. $redirect=$this->GetRedirect(); return 0;
  2350. }
  2351. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2352. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2353. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2354. if(isset($_GET['post'])){
  2355. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2356. }
  2357. if(isset($_GET['random_here'])){
  2358. $this->DoIdentifyExperimental(); $this->DetectPageType();
  2359. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2360. }
  2361. if(isset($_POST['search_content'])){ $redirect='index.php?search='.$_POST['search_content'];return 0; }
  2362. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2363. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2364. $direct_return = !isset($_GET['show_image']);
  2365. $this->ReadImages(); $this->ReadPosts();
  2366. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2367. $im = &$this->FindImage($m);
  2368. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2369. if($direct_return){
  2370. echo "<ref>".sizeof($im['refs'])."</ref>";
  2371. echo "<insert><ul>";
  2372. }else{ ob_start(); }
  2373. foreach(array_reverse($im['refs']) as $ref){
  2374. $p = $this->GetPost($ref);
  2375. if(!$p || !$this->CanShowPost($p)) continue;
  2376. $this->MakeSinglePost($p, false, true, "post_preview invert_a", true, false, false, false, true);"</li>";
  2377. }
  2378. if($direct_return){
  2379. echo "</ul></insert>";
  2380. $this->MakeHereButtons($im, true);
  2381. }else{
  2382. $str = ob_get_clean();
  2383. $this->MakePageBegin($this->NULL_POST);
  2384. $side = "";
  2385. if(isset($im['refs'])&&isset($im['refs'][0])){
  2386. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2387. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2388. $static_image = isset($im['video'])?NULL:$im['file'];
  2389. $static_video = isset($im['video'])?$im['file']:NULL;
  2390. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$static_image,$static_video);
  2391. $this->MakePageEnd();
  2392. }
  2393. exit;
  2394. }
  2395. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2396. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2397. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2398. }
  2399. if(isset($_GET['apub_actor'])){
  2400. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2401. echo $this->APubActor; exit;
  2402. }
  2403. if(isset($_GET['apub_outbox'])){
  2404. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2405. echo $this->APubMakeOutbox(); exit;
  2406. }
  2407. if(isset($_GET['apub_inbox'])){
  2408. $this->APubProcessInbox();
  2409. http_response_code(202); exit;
  2410. }
  2411. if($this->LoggedIn){
  2412. if(isset($_GET['TestAPubDeliver'])){
  2413. $this->APubTestDeliver();
  2414. }
  2415. $this->DoUpload();
  2416. if(isset($_POST['settings_button'])){
  2417. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2418. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2419. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2420. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2421. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2422. if(isset($_POST['settings_special_sidebar'])) $this->SpecialSidebar=$_POST['settings_special_sidebar'];
  2423. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2424. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2425. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2426. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2427. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2428. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2429. if(isset($_POST['settings_gallery_step'])) $this->GalleryStep=$_POST['settings_gallery_step'];
  2430. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2431. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2432. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2433. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2434. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2435. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2436. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2437. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2438. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2439. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2440. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2441. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2442. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2443. if(isset($_POST['settings_allow_language'])) $this->AllowLanguageChoices=True; else $this->AllowLanguageChoices=False;
  2444. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2445. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2446. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2447. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2448. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2449. $this->APubID=$_POST['settings_apub_id'];
  2450. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2451. }
  2452. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2453. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2454. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2455. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2456. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2457. $redirect=$_SERVER['REQUEST_URI'];
  2458. $this->DoLogout();
  2459. }
  2460. $this->WriteConfig();
  2461. return 0;
  2462. }
  2463. if(isset($_POST['settings_save_redirect'])){
  2464. if(isset($_POST['settings_redirect'])){
  2465. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2466. }
  2467. $this->WriteConfig();
  2468. $redirect = 'index.php?extras=true'; return 0;
  2469. }
  2470. if(isset($_POST['settings_save_translation'])){
  2471. if(isset($_POST['settings_translation'])){
  2472. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2473. }
  2474. $redirect = 'index.php?extras=true'; return 0;
  2475. }
  2476. if(isset($_GET['post'])){
  2477. if(isset($_GET['post_original'])){
  2478. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2479. exit;
  2480. }
  2481. }
  2482. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2483. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2484. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2485. return 0;
  2486. }
  2487. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2488. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2489. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2490. return 0;
  2491. }
  2492. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2493. $c = $_POST['post_content'];
  2494. if('有什么想说的' == $c){ return 0;}
  2495. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2496. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2497. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2498. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2499. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2500. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2501. $redirect='?post='.$edited['id']; return 0;
  2502. };
  2503. }
  2504. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2505. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2506. $redirect='?post='.$edited['id']; return 0;
  2507. };
  2508. }
  2509. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2510. if(($edited =$this->EditPost(
  2511. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2512. $redirect='?post='.$edited['id']; return 0;
  2513. };
  2514. }
  2515. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2516. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2517. if(isset($post)){
  2518. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2519. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2520. echo "SUCCESS ".$mastodon_url;
  2521. }else{ echo $err; }
  2522. } exit;
  2523. }
  2524. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2525. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2526. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2527. }
  2528. }
  2529. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2530. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2531. $redirect='?post='.$pe['id']; return 0;
  2532. }
  2533. }
  2534. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2535. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2536. $c = $_POST['comment_box'];
  2537. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2538. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2539. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2540. if(($edited = $this->EditComment(NULL,
  2541. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2542. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2543. $_SERVER['REMOTE_ADDR']))!=NULL){
  2544. $redirect='?post='.$_GET['post'];
  2545. return 0;
  2546. };
  2547. }
  2548. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2549. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2550. $new_name = $_POST['gallery_edit_new_name'];
  2551. if($old_name!=''){
  2552. $this->EditGallery($old_name, $new_name, false, true, null, null);
  2553. $redirect='?gallery='.$new_name;
  2554. }else{
  2555. $this->EditGallery(null, $new_name, false, true, null);
  2556. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2557. }
  2558. return 0;
  2559. }
  2560. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2561. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  2562. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  2563. return 0;
  2564. }
  2565. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2566. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2567. $this->ReadImages();
  2568. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2569. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL, NULL);
  2570. }
  2571. }
  2572. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2573. return 0;
  2574. }
  2575. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2576. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2577. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2578. return 0;
  2579. }
  2580. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2581. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2582. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2583. return 0;
  2584. }
  2585. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2586. $this->ReadImages();
  2587. $gallery = $_GET['image_list'];
  2588. foreach($this->Images as $im){
  2589. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2590. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2591. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2592. }
  2593. exit;
  2594. }
  2595. $do_image_redirect = 0;
  2596. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2597. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4))/u',$_GET['pic'],$ma)){
  2598. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2599. if(isset($_POST['image_ops_product_link'])){
  2600. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL, NULL);
  2601. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2602. }
  2603. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2604. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL, NULL);
  2605. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2606. $do_image_redirect = 1;
  2607. }
  2608. if(isset($_POST['image_parent'])){ $parent="";
  2609. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2610. $this->EditImage($pic, NULL, false, NULL, NULL, $parent, NULL);
  2611. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2612. }
  2613. if(isset($_POST['image_align'])){$val=$_POST['image_align'];
  2614. $this->EditImage($pic, NULL, false, NULL, NULL, NULL, $val);
  2615. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2616. }
  2617. $this->NeedWriteImages = 1;
  2618. if($do_image_redirect) return 0;
  2619. }
  2620. if(isset($_GET['rewrite_styles'])){
  2621. $this->WriteStyles();
  2622. $redirect='?extras=true'; return 0;
  2623. }
  2624. if(isset($_GET['regenerate_thumbnails'])){
  2625. $this->RegenerateThumbnails();
  2626. $redirect='?extras=true'; return 0;
  2627. }
  2628. if(isset($_GET['clear_all_logins'])){
  2629. $this->LoginTokens=[];
  2630. $this->WriteTokens();
  2631. }
  2632. }
  2633. return 0;
  2634. }
  2635. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null, &$end_wide=null, &$print_wide=null){
  2636. if(!$this->LoggedIn){
  2637. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2638. }
  2639. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2640. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2641. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2642. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2643. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2644. $html = preg_replace("/\{\s*(REVERSED|INTERESTING|HEADER|FOOTER)\s+(.*?)\}/imu","",$html);
  2645. $html = preg_replace("/\{\s*(NO_TIME|NO_TITLE)\s*\}/imu","",$html);
  2646. $html = preg_replace("/\{\s*WIDE\s*\}/imu","",$html,-1,$rep_count); if($rep_count){$print_wide=true;}
  2647. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2648. $html = preg_replace_callback(
  2649. "/(<p>\s*|<a\s.*?>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2650. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2651. if(isset($m[1])&&$m[1]&&$m[1][1]=='a'){ $height="";
  2652. if(preg_match("/([0-9]{1,2})em/u",$m[0],$hm)){$height=' style="height:'.$hm[1].'em;"';}
  2653. return "<a class='imbtn'".$height.substr($m[0],2); }
  2654. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2655. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2656. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2657. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2658. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2659. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2660. $src = $im['thumb']; $orig_src=$im['file'];
  2661. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2662. $media_start = $m[2];
  2663. $media_end = $m[7];
  2664. $dataset = " data-imgsrc='".$m[5]."'".
  2665. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2666. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2667. (isset($im['align'])?' data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':"").
  2668. ($original?" class='original_img'":"");
  2669. if(isset($im['video']) && isset($im['video'])!=''){
  2670. $media_start = "<video controls".$dataset."><source src='"; $media_end="' type='".$im['video']."'></video";
  2671. $src = $orig_src; $dataset="";
  2672. }
  2673. if($this->InHereMode){
  2674. $click = "<div class='imd'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2675. $media_start.($original?$orig_src:$src).$media_end."></a></div>";
  2676. $ret=""; if($keep) { $ret = $click; }
  2677. else { $images[] = $click; }
  2678. return $ret;
  2679. }else{
  2680. $click ="<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2681. $media_start.($original?$orig_src:$src).$media_end.$dataset."></a></div>";
  2682. $images_noclick[]=$media_start.$src.$media_end.">"; $images_orig_src_list[]=$orig_src;
  2683. $ret = "";
  2684. if($keep) { $ret = $click; }
  2685. else { $images[] = $click; }
  2686. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2687. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2688. }
  2689. },$html,-1,$count);
  2690. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2691. if(sizeof($images)){
  2692. if((!$this->InHereMode) && sizeof($images)==1){$html.= $images[0]; }
  2693. else{
  2694. $html.="<div class='p_row'>";
  2695. foreach($images as $img){
  2696. $html.="<div class='p_thumb'>".$img."</div>";
  2697. }
  2698. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2699. }
  2700. }
  2701. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2702. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2703. if($do_product_info){
  2704. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2705. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2706. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2707. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2708. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2709. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2710. else { $product_info['title'] = $this->T('商品'); }
  2711. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2712. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2713. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2714. $this->T('购买').' '.$product_info['title'].
  2715. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2716. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2717. }
  2718. if(preg_match("/(<\/div>|<\/table>|<\/video>)\s*$/u",$html)){$end_wide=true;}
  2719. return $html;
  2720. }
  2721. function ConvertPost(&$post){
  2722. if(!isset($post['html'])){
  2723. $info=[];
  2724. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2725. $post['images'],
  2726. isset($post['product']), $info,
  2727. $post['original_images'],
  2728. $post['end_wide'],
  2729. $post['wide']));
  2730. if(isset($post['product'])) $post['product']=$info;
  2731. }
  2732. }
  2733. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2734. if(!isset($post['title'])){
  2735. if($h1_only){
  2736. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2737. else return NULL;
  2738. }
  2739. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2740. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2741. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2742. $post['title'].=($add_unamed?' (':'').strip_tags($this->PDE->text($m[1])).($add_unamed?')':''); }
  2743. }
  2744. }
  2745. return $this->ChoosePartsByLanguage($post['title']);
  2746. }
  2747. function DetectPageType(){
  2748. if ($this->InExperimentalMode) $this->PageType='experimental';
  2749. else if($this->InHereMode) $this->PageType='here';
  2750. else if(isset($_GET['history'])) $this->PageType='history';
  2751. else if(isset($_GET['extras'])) $this->PageType='extras';
  2752. else if(isset($_GET['settings'])) $this->PageType='settings';
  2753. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2754. else if(isset($_GET['search'])) $this->PageType='search';
  2755. else if(isset($_GET['category'])) $this->PageType='category';
  2756. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2757. else if(isset($_GET['comments'])) $this->PageType='comments';
  2758. else $this->PageType = "main";
  2759. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2760. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2761. $this->VisitedHere = $_SESSION[$visited_here];
  2762. }
  2763. function MakePageBegin(&$p){ $title=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2764. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title)) ?>
  2765. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2766. <head>
  2767. <meta charset='utf-8'>
  2768. <meta content="width=device-width, initial-scale=1" name="viewport">
  2769. <title><?=$title?></title>
  2770. <meta property="og:title" content="<?=$title.(isset($p)?(" | ".$this->GetPostTitle($p)):"")?>">
  2771. <?php if(isset($p)&&isset($p['hasi'])&&isset($p['hasi'][0])){?> <meta property="twitter:card" content="summary_large_image" />
  2772. <meta property="og:image" content="<?=(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']==='on'?"https":"http").'://'.$_SERVER['HTTP_HOST'].'/images/thumb/'.$p['hasi'][0]?>"><?php } ?>
  2773. <?php if($this->UseRemoteFont){ ?><style>
  2774. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2775. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2776. </style><?php } ?>
  2777. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2778. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2779. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2780. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2781. <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>
  2782. </head>
  2783. <div class='page'>
  2784. <?php }
  2785. function MakeHeader(&$p){
  2786. $this->MakePageBegin($p) ?>
  2787. <script type='text/javascript'>
  2788. function toggle_mobile_show(a){a.classList.toggle('hidden_m')}
  2789. function ShowWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='';}
  2790. function HideWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='none';}
  2791. <?php if(!$this->InHereMode){ ?>
  2792. function la_auto_grow(element){
  2793. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2794. }
  2795. function ShowBackdrop(alpha=0.5){
  2796. b = document.getElementById('backdrop');
  2797. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2798. b.style.animation='backdrop_fade_in 0.3s forwards';
  2799. b.style.display = 'block';
  2800. }
  2801. function HideBackdrop(){
  2802. b = document.getElementById('backdrop');
  2803. b.style.animation='backdrop_fade_out 0.3s forwards';
  2804. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2805. }
  2806. function ShowRightSide(big,elem_to_clone){
  2807. p = document.getElementById('pop_right');
  2808. if(elem_to_clone){
  2809. c = elem_to_clone.cloneNode(true);
  2810. c.id='side_bar_cloned';c.className="";c.style="";
  2811. p.querySelector('._content').appendChild(c);
  2812. }
  2813. p.classList.remove('pop_right','pop_right_big');
  2814. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2815. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2816. p.style.display='block';
  2817. ShowBackdrop(0.5);
  2818. }
  2819. function HideRightSide(){
  2820. p = document.getElementById('pop_right');
  2821. if(side=p.querySelector('#side_bar_cloned')){
  2822. side.remove();
  2823. }
  2824. put = document.querySelector("#_uploader");
  2825. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2826. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2827. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2828. HideBackdrop();
  2829. }
  2830. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2831. function ScrollToPost(id){
  2832. post=null;
  2833. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2834. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2835. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2836. }
  2837. <?php } ?>
  2838. </script><input type='checkbox' class='lpctrl' id='titlectrl'>
  2839. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2840. <?php if($this->InHereMode){
  2841. $this->MakeExpNavButtons($p);
  2842. }else{
  2843. $this->MakeNavButtons($p);
  2844. if(isset($p['tid']['header'])){ ?><div style='float:right' class='show_on_print'><?=$p['tid']['header'];?></div><?php }
  2845. echo "<hr class='hidden_m'>";
  2846. } ?>
  2847. <?php if(isset($this->WayBack)){
  2848. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2849. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2850. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2851. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_m")'>
  2852. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2853. <span class='hidden_m'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2854. + <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_m'>
  2855. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2856. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2857. <br class='hidden_on_desktop' />
  2858. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2859. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2860. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2861. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2862. <br class='hidden_on_desktop' />
  2863. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2864. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2865. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2866. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2867. <br class='hidden_on_desktop' />
  2868. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2869. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2870. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2871. </div></div><?php } ?>
  2872. </div></header>
  2873. <div id='waiting_bar' style='display:none;'></div>
  2874. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2875. <?php if(!$this->InHereMode){ ?>
  2876. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2877. <ul>
  2878. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2879. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2880. <hr />
  2881. <?php if($this->LoggedIn){ ?>
  2882. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2883. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2884. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2885. <?php if(!isset($this->WayBack)){ ?><li>
  2886. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2887. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2888. </li>
  2889. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2890. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2891. <li id='mark_details' style='display:none;'><b>
  2892. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2893. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2894. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2895. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2896. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2897. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2898. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2899. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2900. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2901. </b></li>
  2902. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2903. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2904. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2905. <input class='button' type='submit' form='post_rename_form'
  2906. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2907. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  2908. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  2909. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  2910. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  2911. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  2912. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  2913. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  2914. <input class='button' type='submit' form='post_mastodon_form'
  2915. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  2916. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  2917. <?php }else{ ?>
  2918. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2919. <?php } ?>
  2920. </ul>
  2921. </div>
  2922. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide();HideBigImage(1);'
  2923. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2924. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2925. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2926. <?=$this->T('关闭')?>→</a></div>
  2927. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2928. <div id='_uploader' style='display:none;'>
  2929. <?php $this->MakeUploader(true); ?>
  2930. <p>&nbsp;</p>
  2931. <?php $this->MakeSideGalleryCode(); ?>
  2932. </div>
  2933. <?php } ?>
  2934. <div class='_content'></div>
  2935. </div>
  2936. <?php } ?>
  2937. <?php
  2938. }
  2939. function ChoosePartsByLanguage($content,$use_p=false){
  2940. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  2941. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  2942. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  2943. if($split) for($i=0;$i<sizeof($split);$i+=4){
  2944. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  2945. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  2946. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  2947. }
  2948. if(!$reduced)$reduced = $content;
  2949. return $reduced;
  2950. }
  2951. function TranslatePostParts($html){
  2952. $html = preg_replace_callback('/>(\s*)([^><]+?)(\s*)</u', function($ma){
  2953. $reduced = $this->ChoosePartsByLanguage($ma[2], false);
  2954. return ">".$ma[1].$this->T($reduced).$ma[3]."<";
  2955. }, $html);
  2956. return $html;
  2957. }
  2958. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); $no_title=isset($p['tid']['first']['no_title']);?>
  2959. <a href='index.php' class='clean_a hidden_m<?=$no_title?" hidden_on_print":""?>' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title);?></b></a>
  2960. <?=$no_title?"<a class='inline_print'>&nbsp;</a>":""?>
  2961. <label for='titlectrl' id='mtitle'><b><a class='hidden_on_desktop'><?=$this->T($this->ShortTitle)?>...</a></b></label>
  2962. <div class='header_nav'>
  2963. <ul class='mobile_fold hidden_on_print' id='mobile_nav'>
  2964. <li class='hidden_m'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2965. <li class='hidden_on_desktop_force block_m smaller'>&nbsp;</li>
  2966. <li class='hidden_on_desktop_force block_m bigger'>
  2967. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a>
  2968. <?php if($this->LoggedIn){ ?>
  2969. | <span class='gray invert_a'><a href='index.php?comments=all'>@</a></span><?php } ?></li>
  2970. <li class='hidden_on_desktop_force block_m bigger'>
  2971. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2972. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2973. echo $this->GenerateSinglePost($p, false, false, false, false);
  2974. } ?>
  2975. </ul></div>
  2976. <?php
  2977. }
  2978. function MakeExpNavButtons(&$p){ ?>
  2979. <a href='index.php' class='hidden_m'>
  2980. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  2981. <a class='hidden_on_desktop'
  2982. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b class='round_btn'>
  2983. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?></b></a>
  2984. <?php if(!$this->InExperimentalMode){ ?>
  2985. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  2986. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  2987. <span class='round_btn'>
  2988. <a href='<?=$this->HereNumber==sizeof($this->VisitedHere)?"?random_here=1":$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a>
  2989. <a href='?random_here=1'><?=$this->T("随机")?></a></span><span class='hidden_m'></span>
  2990. <?php } ?>
  2991. <ul class='hidden_m' id='mobile_nav' style='text-align:center;'>
  2992. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  2993. <li class='hidden_on_desktop block_m'><a href='index.php'><?=$this->T('主页')?></a></li>
  2994. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2995. echo $this->GenerateSinglePost($p, false, false, false, false);
  2996. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  2997. echo $this->GenerateSinglePost($p, false, false, false, false);
  2998. } ?>
  2999. <?php if($this->AllowLanguageChoices){ ?>
  3000. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  3001. <?php if($this->LanguageAppendix=='zh'){ ?>
  3002. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  3003. <?php }else { ?>
  3004. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  3005. <li class='smaller invert_a gray'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  3006. <?php } ?>
  3007. <?php } ?>
  3008. </ul>
  3009. <?php
  3010. }
  3011. function GenerateLinkedPosts($ht){
  3012. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  3013. function($m){
  3014. if(preg_match('/^\s*<img/u',$m[2])){ return $m[0]; }
  3015. $rp = &$this->GetPost($m[1], false, true);
  3016. $s="<div class='smaller block post ref_compact gray'>".
  3017. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  3018. "<div class='post_width'><div class='smaller'>".$m[2]."</div>".
  3019. (($rp!==NULL && $this->CanShowPost($rp))?
  3020. $this->GenerateSinglePost($rp,false,false,false,true,true):$this->T("未找到该引用。")).
  3021. "</div></div>";
  3022. return $s;
  3023. },
  3024. $ht
  3025. );
  3026. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  3027. function($m){
  3028. $rp = &$this->GetPost($m[1], false, true);
  3029. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  3030. (($rp!==NULL && $this->CanShowPost($rp))?
  3031. $this->GenerateSinglePost($rp,true,false,false,true,true):$this->T("未找到该引用。")).
  3032. "</a></div>";
  3033. return $s;
  3034. },
  3035. $ht
  3036. );
  3037. return $ht;
  3038. }
  3039. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  3040. $generate_thumbs=false, $hide_long = false){
  3041. $this->ConvertPost($post);
  3042. if($generate_anchor){ $this->CreatePostAnchor($post); }
  3043. $ht = $post['html'];
  3044. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  3045. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  3046. "<p class='bold'>".$post['product']['title']."</p>".
  3047. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  3048. "<p class='smaller bold'>".$post['product']['price']."</p>";
  3049. return $ht;
  3050. }
  3051. if($hide_long){
  3052. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  3053. }else{
  3054. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  3055. }
  3056. if ($strip_tags){
  3057. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  3058. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  3059. $ht = "<div class='post_ref_main'>".$ht."</div>";
  3060. }
  3061. else{
  3062. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  3063. }
  3064. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  3065. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  3066. foreach($post['images'] as $im){
  3067. $ht.="<li class='file_thumb'>".$im."</li>";
  3068. }
  3069. $ht.="</ul></div>";
  3070. }
  3071. return $ht;
  3072. }
  3073. function MakeSinglePostExp(&$post){ ?>
  3074. <li class='post post_dummy'>
  3075. <?=$this->GenerateSinglePost($post, false, false, true, false, false); ?>
  3076. </li>
  3077. <?php
  3078. }
  3079. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  3080. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  3081. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  3082. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  3083. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  3084. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  3085. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  3086. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  3087. $this->ConvertPost($post);// NEEDED FOR WIDE;
  3088. $is_wide = (isset($post['wide'])&&$post['wide']) || (isset($post['tid']) && isset($post['tid']['wide']) && $post['tid']['wide']);
  3089. ?>
  3090. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  3091. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>'
  3092. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  3093. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?>
  3094. <?=$is_wide?" style='column-span:all;'":"";?>>
  3095. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  3096. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  3097. <?php } ?>
  3098. <?php if($is_top){?>
  3099. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  3100. <?php }
  3101. if(!$side && !$strip_tags){?><div class='post_menu_button _menu_hook' >+</div><?php } ?>
  3102. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  3103. <div class='<?=$side?"":'post_width'?><?=$is_deleted?" deleted_post":""?>'>
  3104. <?php if($is_product&&!$generate_anchor){
  3105. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  3106. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  3107. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  3108. $generate_thumb,($show_thread_link||$side||$force_hide_long)); ?>
  3109. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  3110. </div>
  3111. <?=$side?"</a>":""?> <?php
  3112. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  3113. $post['tid']['first']['id']!=$post['id']){ ?>
  3114. <div class='gray smaller block opt_compact post'>
  3115. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  3116. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  3117. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  3118. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  3119. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true, true);?>
  3120. </div>
  3121. </div>
  3122. <?php }if(!$side && $show_link){ if($ref_count){ ?><?php } ?>
  3123. <a href='?post=<?=$post['id']?>' onclick="<?=$show_thread_link||isset($_GET['search'])?'ShowWaitingBar()':'ClickPost(this.parentNode,event,true)'?>">
  3124. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3125. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"")?>
  3126. </div>
  3127. </a><?php if($ref_count){ ?>
  3128. <label class='lb post_access' for='fake<?=$post["id"]?>'><div class='ref_count'><?=$ref_count?></div></label><?php }
  3129. }
  3130. if($show_reply_count && isset($post['tid'])){ ?>
  3131. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  3132. <?=$this->T('个回复')?></a>
  3133. <?php } if(!$strip_tags){
  3134. $this->MakeLinkedPosts($post);
  3135. } ?>
  3136. </li>
  3137. <?php
  3138. }
  3139. function MakePostingFields($reply_to=NULL, $show_hint=false){
  3140. if(isset($this->WayBack)){ ?>
  3141. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  3142. <?php return; } ?>
  3143. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  3144. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  3145. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  3146. <div id='post_hint_modify' style='display:none;'>
  3147. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  3148. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  3149. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  3150. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  3151. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3152. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3153. onclick='ShowWaitingBar();' />
  3154. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3155. <div style='float:right;'>
  3156. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3157. <?=$this->T('清空')?></a>
  3158. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3159. </div>
  3160. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3161. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3162. <?php if($reply_to){ ?>
  3163. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3164. <?php } ?>
  3165. <?php
  3166. }
  3167. function MakeCommentPosts(){
  3168. if(!$this->LoggedIn) return; ?>
  3169. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3170. <?php if(!$this->CommentEnabled){
  3171. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3172. <div class='comment'><ul>
  3173. <?php $i=0;
  3174. foreach(array_reverse($this->Posts) as $p){
  3175. if(!isset($p['comment_to'])) continue;
  3176. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3177. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3178. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3179. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3180. if(!$post_to) $post_title = "?";
  3181. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3182. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3183. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3184. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3185. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3186. $i++;
  3187. }
  3188. ?>
  3189. </ul><br /></div>
  3190. <?php
  3191. }
  3192. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  3193. <div class='center' id='div_center'><div><br /></div>
  3194. <h2><?=isset($search_term)?$this->T('搜索'):
  3195. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3196. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3197. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3198. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  3199. <?php if(isset($search_term)){ ?>
  3200. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  3201. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3202. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3203. <?php }else if(isset($category)){ ?>
  3204. <div></div>
  3205. <?php }else if($this->LoggedIn){ ?>
  3206. <div class='post_box_top _input_bundle'>
  3207. <?php $this->MakePostingFields(NULL,false); ?>
  3208. </div>
  3209. <?php } ?>
  3210. <ul class='print_column list bkg_recent'>
  3211. <?php
  3212. if(!isset($search_term) && !isset($category) &&
  3213. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3214. $this->CanShowPost($p)){
  3215. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  3216. }
  3217. $i = 0; $last_end_wide = true;
  3218. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3219. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3220. if(isset($p['tid'])){ /* Should always be set. */
  3221. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3222. if(!isset($search_term)) { $p = &$th['last']; }
  3223. }
  3224. if(isset($search_term)){
  3225. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3226. }else if(isset($category)){
  3227. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3228. (isset($p['categories'])?($p['categories']):[]);
  3229. if ($category=='none') { if($cat!=[]) continue; }
  3230. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3231. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3232. }else{
  3233. if(in_array($p['id'],
  3234. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  3235. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3236. }
  3237. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3238. if($last_end_wide){$use_class="last_wide";}else{$use_class="";}
  3239. $this->MakeSinglePost($p, true, false, $use_class, false, !isset($search_term), false, false, false, false, isset($search_term));
  3240. $i++;
  3241. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3242. $last_end_wide = sizeof($p['tid']['arr'])==1 && isset($p['end_wide']) && $p['end_wide'];
  3243. }?>
  3244. </ul>
  3245. <div class='page_selector clean_a'>
  3246. <hr />
  3247. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  3248. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3249. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3250. <?=$this->CurrentOffset+1?>
  3251. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  3252. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3253. → <?=$this->T('下一页')?></a>
  3254. </div>
  3255. </div>
  3256. <?php
  3257. }
  3258. function MakeLinkedPosts(&$p){
  3259. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); if(!$has_ref)return; $count=0;?>
  3260. <input type='checkbox' class='lpctrl' id='fake<?=$p["id"]?>' checked='checked'>
  3261. <div class='linked_posts smaller'>
  3262. <ul><?php $count_product=0;
  3263. foreach(array_reverse($p['refs']) as &$pr){
  3264. $po = $this->GetPost($pr);
  3265. if(!$this->CanShowPost($po)){ continue; } $count++;
  3266. $this->MakeSinglePost($po, false, true, "post_preview invert_a", true, false, false, false, true, false, false);
  3267. }
  3268. ?></ul>
  3269. </div>
  3270. <?php
  3271. }
  3272. function MakeLinkedPostsExp(&$p){
  3273. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3274. <div class='center_exp post_dummy smaller'>
  3275. <hr />
  3276. <?php if(!$this->InExperimentalMode){ ?>
  3277. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3278. <?php if($has_ref){ ?>
  3279. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3280. <ul><?php $count_product=0;
  3281. foreach(array_reverse($p['refs']) as &$pr){
  3282. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3283. "</a></li>";
  3284. }
  3285. ?></ul>
  3286. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3287. }else{ ?>
  3288. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3289. <?php } }?>
  3290. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3291. </div>
  3292. <?php
  3293. }
  3294. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3295. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3296. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3297. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3298. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3299. if(!isset($title)) $title=$this->T('未命名');
  3300. if(!isset($ah)){ ?>
  3301. <h2><?=$this->T('没有历史记录')?></h2>
  3302. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3303. <?php }else{ ?>
  3304. <h2><?=$this->T('历史记录')?></h2>
  3305. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3306. <div class='list'><ul>
  3307. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3308. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3309. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3310. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3311. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3312. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3313. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3314. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3315. <?=$this->GetPostTitle($ver);?></a>
  3316. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3317. <?php } ?></ul><?php } ?>
  3318. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3319. $mah = &$this->GetArchiveHandle($pm);
  3320. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3321. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3322. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3323. <?php } ?>
  3324. </li><?php } ?>
  3325. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3326. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3327. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3328. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3329. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3330. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3331. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3332. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3333. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3334. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3335. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3336. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3337. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3338. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3339. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3340. <?=$this->GetPostTitle($ver);?></a>
  3341. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3342. <?php } ?></ul></li><?php } ?>
  3343. <?php } ?></ul></div>
  3344. <?php } ?>
  3345. <?php
  3346. }
  3347. function MakePostDiff(&$this_ver, &$last_ver){
  3348. if(!isset($this_ver)){ ?>
  3349. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3350. <?php }else{ ?>
  3351. <h2><?=$this->T('差异')?></h2>
  3352. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3353. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3354. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3355. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3356. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3357. <?php }else{ ?>
  3358. <table class='diff_table'><thead>
  3359. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3360. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3361. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3362. </thead><tbody>
  3363. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3364. </tbody>
  3365. </table>
  3366. <?php } ?>
  3367. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3368. <?php } ?>
  3369. <?php
  3370. }
  3371. function MakePostHistory(&$post, $version=NULL){
  3372. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3373. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3374. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3375. ?>
  3376. <div class='left mobile_fold history' id='div_left'>
  3377. <?php if (isset($version)){
  3378. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3379. }else{ echo "&nbsp;"; } ?>
  3380. </div>
  3381. <div class='center history' id='div_center'>
  3382. <?php if (!isset($version)){
  3383. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3384. }else{
  3385. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3386. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3387. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3388. $this->MakePostDiff($this_ver, $last_ver, $p);
  3389. } ?>
  3390. </div>
  3391. <?php
  3392. }
  3393. function MakeCommentSection(&$post){
  3394. if(!$this->CommentEnabled){ return; }
  3395. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3396. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3397. ?><div class='comment'>
  3398. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3399. <?php if($comment_count) { echo "<ul>";
  3400. foreach($to_post['comments'] as $p){
  3401. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3402. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3403. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3404. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3405. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3406. }
  3407. echo "</ul>";
  3408. } else {
  3409. echo $this->T('还没有评论');
  3410. } ?>
  3411. <div class='hidden_on_print'>
  3412. <div class='spacer'></div>
  3413. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3414. method="post" style="display:none;" id="comment_form"></form>
  3415. <p><a class='text_highlight bold clean_a'
  3416. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3417. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3418. <div id='comment_box' style='display:none;'>
  3419. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3420. <table style='white-space:nowrap;'>
  3421. <tr><td colspan='2'>
  3422. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3423. oninput="CommentUpdated();" ></textarea>
  3424. </td></tr>
  3425. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3426. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3427. class='full_box' oninput="CommentUpdated();" /></td>
  3428. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3429. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3430. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3431. <tr><td colspan='2'>
  3432. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3433. class='full_box' oninput="CommentUpdated();" />
  3434. </td></tr>
  3435. <tr><td colspan='2'>
  3436. <div class='spacer'></div>
  3437. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3438. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3439. </td></tr>
  3440. </table></div>
  3441. <script>
  3442. const IsValidEmail = (email) => {
  3443. 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,}))$/);
  3444. };
  3445. function IsValidHttpUrl(string) {
  3446. let url; try{ url = new URL(string); } catch (_) { return false; }
  3447. return url.protocol === "http:" || url.protocol === "https:";
  3448. }
  3449. var cbox = document.getElementById('comment_box');
  3450. var cemail = document.getElementById('comment_email');
  3451. var cname = document.getElementById('comment_name');
  3452. var clink = document.getElementById('comment_link');
  3453. var cconfirm = document.getElementById('comment_confirm');
  3454. function CommentUpdated(){
  3455. cconfirm.disabled=true;
  3456. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3457. cbox.innerText.length>2 && cname.value.length>2 &&
  3458. clink.value=="" || IsValidHttpUrl(clink.value)){
  3459. cconfirm.removeAttribute("disabled");
  3460. }
  3461. }
  3462. CommentUpdated();
  3463. </script>
  3464. </div>
  3465. </div>
  3466. <?php
  3467. }
  3468. function MakeInterestingSection(&$th){
  3469. $this->Anchors = [];
  3470. $c = &$th['first']['content'];
  3471. $this->ConvertPost($th['first']);
  3472. $ht = $th['first']['html'];
  3473. ?>
  3474. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3475. <div class='center_full' id='div_center'>
  3476. <?php $this->MakePostTools(); ?>
  3477. <?php $cat = NULL;
  3478. if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; }
  3479. if($cat){ ?>
  3480. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3481. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3482. <?php } ?>
  3483. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3484. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3485. <ul><li class='post' data-post-id='<?=$th['first']['id']?>'>
  3486. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3487. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3488. <?php foreach($th['first']['refs'] as $ref){
  3489. $po = $this->GetPost($ref);
  3490. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3491. if(!$this->CanShowPost($po)){ continue; }
  3492. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3493. } ?>
  3494. </ul><?php } ?>
  3495. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3496. <div class='hidden_on_print'><br />
  3497. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3498. </div>
  3499. <?php } ?>
  3500. <table><thead><tr><?php foreach($th['interesting'] as $header){ ?>
  3501. <td><?=$this->T($header);?></td>
  3502. <?php } ?><td></td></tr></thead><tbody class='interesting_tbody'>
  3503. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3504. foreach($plist as &$p){
  3505. $this->ConvertPost($p);
  3506. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3507. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3508. $is_current = $p['id']==$this->CurrentPostID;
  3509. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3510. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3511. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3512. onDblClick='ClickImage(this)'><td>
  3513. <?php if($ref_count){ ?>
  3514. <div class='post_access ref_count'><?=$ref_count?></div>
  3515. <?php } ?></a>
  3516. <?=$p['html'];?>
  3517. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a>
  3518. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3519. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3520. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3521. </div></td></tr>
  3522. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3523. <?php foreach($p['refs'] as $ref){
  3524. $po = $this->GetPost($ref);
  3525. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3526. if(!$this->CanShowPost($po)){ continue; }
  3527. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3528. } ?>
  3529. </ul></td></tr><?php } ?>
  3530. <?php } ?>
  3531. </tbody></table>
  3532. </li></ul>
  3533. <br />
  3534. <?php $this->MakeCommentSection($th['first']); ?>
  3535. </div>
  3536. <?php return true;
  3537. }
  3538. function CssNumberID($id){
  3539. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3540. }
  3541. function MakePostTools(){
  3542. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3543. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3544. <?=$this->T('工具')?></a>:<div class='hidden_m' style='display:inline'>
  3545. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3546. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3547. </div>
  3548. <select class='hidden_on_desktop' id='merge_select'
  3549. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3550. <option value='-1' selected>--</option>
  3551. <option value='1'><?=$this->T('合并帖子')?></option>
  3552. <option value='2'><?=$this->T('合并话题')?></option></select>
  3553. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3554. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3555. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3556. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3557. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3558. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3559. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3560. </div><div class='spacer hidden_on_print'></div><?php
  3561. }
  3562. }
  3563. function MakeSidebar(){ ?>
  3564. <div class='left mobile_fold'><?php if(isset($this->SpecialSidebar) && ($p = &$this->GetPost($this->SpecialSidebar))!=NULL){
  3565. ?><span class='gray smaller'><br /></span><?php
  3566. echo $this->GenerateSinglePost($p, false, false, false, false); }?>
  3567. <div class='wayback_link clean_a smaller'><span class='gray'><br /><?=$this->T('工具')?></span><ul>
  3568. <li><a href='?search=' onclick='ShowWaitingBar()' class='bigger'><?=$this->T('搜索')?></a></li>
  3569. <li><?php if(!isset($this->WayBack)){ ?>
  3570. <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  3571. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?></li>
  3572. <li><a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  3573. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a></li>
  3574. <li><a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a></li>
  3575. <?php if($this->LanguageAppendix=='zh'){ ?>
  3576. <li class='smaller'>
  3577. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  3578. <?php }else { ?>
  3579. <li class='smaller'>
  3580. <a href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  3581. 汉语/<b>English</b></a>
  3582. <br class='hidden_on_desktop' />
  3583. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  3584. <?php } ?></ul>
  3585. </div>
  3586. </div>
  3587. <?php }
  3588. function MakePostSection(&$post){
  3589. $this->Anchors = [];
  3590. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3591. <div class='center' id='div_center'><div><br /></div>
  3592. <h2 class='hidden_on_print'>
  3593. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1;
  3594. $is_wide = (isset($post['wide'])&&$post['wide']) || ($is_thread && isset($post['tid']['wide']) && $post['tid']['wide']);
  3595. if($is_thread){ $th = $post['tid'];?> <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3596. <?php } ?></h2>
  3597. <?php $cat = NULL;
  3598. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3599. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3600. $this->MakePostTools();
  3601. if($cat){ ?>
  3602. <p class='hidden_on_print'><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3603. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3604. <?php } ?>
  3605. <ul class='print_column bkg_section'>
  3606. <?php $is_reversed=false;
  3607. if($is_thread){
  3608. $use_arr = $th['arr']; $hinted=false;
  3609. $last_end_wide = true; $is_reversed=$this->IsReversedThread($th);
  3610. foreach($use_arr as &$p){$use_class="";if($p==$post){$use_class.=" active_post";}
  3611. if($last_end_wide){$use_class.=" last_wide";}
  3612. $make_title = ($p == $post);
  3613. if(isset($p['restart'])){ ?>
  3614. <li class='restart'><h3><?=$p['restart']?></h3></li><?php }
  3615. $this->MakeSinglePost($p,true,false,$use_class,false, false, false, true, false, false);
  3616. if($make_title){?>
  3617. <script>
  3618. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  3619. </script>
  3620. <?php } if($is_reversed && !$hinted){ ?><?php $hinted = true;
  3621. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3622. <div class='hidden_on_print'>
  3623. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3624. <?php } }
  3625. $last_end_wide = isset($p['end_wide']) && $p['end_wide'];
  3626. }
  3627. }else{
  3628. $this->MakeSinglePost($post,true, false,"active_post",false, false, false, true, false, false);
  3629. ?><script>
  3630. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($post),0,100)))?>";
  3631. </script><?php
  3632. } $class_add=""; if(isset($post['tid']['first']['no_time'])){ $class_add=' hidden_on_print'; } ?>
  3633. </ul>
  3634. <div class='smaller align_right<?=$class_add;?>'>
  3635. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3636. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3637. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3638. </div>
  3639. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  3640. <div class='hidden_on_print'>
  3641. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3642. </div>
  3643. <?php }
  3644. $this->MakeCommentSection($post);
  3645. ?>
  3646. </div>
  3647. <?php
  3648. }
  3649. function MakePostSectionExp(&$post){
  3650. $this->Anchors = []; $is_thread = isset($post['tid']);
  3651. ?>
  3652. <div class='center_exp' id='div_center'><div><br /></div>
  3653. <ul>
  3654. <?php $is_reversed=false;
  3655. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false;
  3656. foreach($use_arr as &$p){
  3657. $this->MakeSinglePostExp($p);
  3658. if($p == $th['first']){?>
  3659. <script>
  3660. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  3661. </script>
  3662. <?php } if($is_reversed && !$hinted){ ?>
  3663. <li class='gray smaller bold' style='text-align:center;'>
  3664. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3665. <?php $hinted = true; }
  3666. }
  3667. }else{
  3668. $this->MakeSinglePostExp($post);
  3669. ?><!--<script>
  3670. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  3671. </script>--><?php
  3672. } ?>
  3673. </ul>
  3674. </div>
  3675. <?php
  3676. }
  3677. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  3678. <div class='here_image_box clean_a'>
  3679. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  3680. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  3681. <?php if($image_okay){ ?>
  3682. <?php if(isset($im['video']) && isset($im['video'])!=""){ ?>
  3683. <video controls><source src='<?=$im['file'];?>' type='<?=$im['video']?>'></video>
  3684. <?php }else{ ?>
  3685. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  3686. <?php } ?>
  3687. <?php } $this->MakeHereButtons($im, false); ?>
  3688. </div>
  3689. <?php }
  3690. function MakeSideGalleryCode(){?>
  3691. <div>
  3692. <h3><?=$this->T('点击图片以插入:')?></h3>
  3693. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3694. <option value="main"><?=$this->T('全部')?></option>
  3695. <?php if($this->LoggedIn){ ?>
  3696. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3697. <?php }?>
  3698. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3699. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3700. <?php } ?>
  3701. </select>
  3702. <div id='side_gallery'>
  3703. </div>
  3704. </div>
  3705. <script>
  3706. function InsertImage(imgname){
  3707. t = document.querySelector("#post_content");
  3708. v = t.value;
  3709. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3710. la_auto_grow(t);
  3711. }
  3712. function RefreshSideGallery(){
  3713. let xhr = new XMLHttpRequest();
  3714. xhr.onreadystatechange = (function(){
  3715. if (this.readyState === this.DONE) {
  3716. if (this.status === 200) {
  3717. ind = document.querySelector("#side_gallery");
  3718. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3719. str = "<ul class='side_thumb'>"
  3720. for (const m of res) {
  3721. imgstr = "<img src='"+m[2]+"' />";
  3722. if(m[2].match('\.mp4')){
  3723. imgstr = "<video><source src='"+m[2]+"'></video>";
  3724. }
  3725. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+imgstr+"</div>"
  3726. }
  3727. str += "</ul>"
  3728. ind.innerHTML = str;
  3729. }
  3730. }
  3731. }
  3732. });
  3733. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3734. xhr.send();
  3735. }
  3736. </script>
  3737. <?php
  3738. }
  3739. function MakeUploader($is_side=false){ ?>
  3740. <div id='upload_operation_area' class='hidden_on_print'>
  3741. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3742. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3743. <ul id='file_list'>
  3744. </ul>
  3745. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3746. </div>
  3747. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3748. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3749. <script>
  3750. function pastehandler(event){
  3751. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3752. for (index in items) {
  3753. var item = items[index];
  3754. if (item.kind === 'file') {
  3755. put = document.querySelector("#_uploader");
  3756. if(put) ShowSideUploader();
  3757. var blob = item.getAsFile();
  3758. AddImageFile(blob);
  3759. return;
  3760. }
  3761. }
  3762. }
  3763. let _fd_list = []; var uploading=0;
  3764. let hint=document.querySelector('#upload_hint');
  3765. function ToggleCompress(button){
  3766. li = button.parentNode;
  3767. num=li.dataset.number;
  3768. for(i=0;i<_fd_list.length;i++){
  3769. if (_fd_list[i][0] == num){
  3770. state = _fd_list[i][2];
  3771. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3772. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3773. }
  3774. }
  3775. }
  3776. function RemoveFromUpload(button){
  3777. li = button.parentNode;
  3778. num=li.dataset.number;
  3779. for(i=0;i<_fd_list.length;i++){
  3780. if (_fd_list[i][0] == num){
  3781. _fd_list.splice(i, 1);break;
  3782. }
  3783. }
  3784. li.parentNode.removeChild(li);
  3785. }
  3786. function EndThisUpload(){
  3787. unfinished = 0;
  3788. for(i=0;i<_fd_list.length;i++){
  3789. if (_fd_list[i][3]==0){
  3790. unfinished=1;
  3791. }
  3792. }
  3793. if(!unfinished){
  3794. uploading=0;
  3795. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3796. cl=document.querySelector('#upload_click');
  3797. if(!cl.dataset.isSide){
  3798. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3799. cl.href=window.location.href;
  3800. }else{
  3801. _fd_list.splice(0,_fd_list.length);
  3802. fl = document.querySelector("#file_list");
  3803. fl.innerHTML = "";
  3804. list=document.querySelector('#upload_operation_area');
  3805. list.style.pointerEvents='';
  3806. list.style.opacity='';
  3807. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3808. document.onpaste=pastehandler;
  3809. RefreshSideGallery();
  3810. }
  3811. }
  3812. }
  3813. function UploadList(){
  3814. if(!_fd_list.length || uploading) return;
  3815. uploading=1;
  3816. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3817. list=document.querySelector('#upload_operation_area');
  3818. list.style.pointerEvents='none';
  3819. list.style.opacity='0.5';
  3820. document.onpaste="";
  3821. for(i=0;i<_fd_list.length;i++){
  3822. let xhr = new XMLHttpRequest();
  3823. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3824. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3825. function wrap(li, i){
  3826. var ind = li.querySelector('._compress_toggle')
  3827. return function(){
  3828. if (this.readyState === this.DONE) {
  3829. if (this.status === 200) {
  3830. var response = xhr.responseText;
  3831. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3832. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3833. _fd_list[i][3] = 1;
  3834. }else{
  3835. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3836. _fd_list[i][3] = 1;
  3837. }
  3838. EndThisUpload();
  3839. }
  3840. }
  3841. }
  3842. }
  3843. xhr.onreadystatechange = wrap(li, i);
  3844. xhr.send(_fd_list[i][1]);
  3845. }
  3846. }
  3847. function AddImageFile(blob){
  3848. var ext="";
  3849. if(blob.name.match(/png$/))ext = 'png';
  3850. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3851. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3852. else if(blob.name.match(/gif$/))ext = 'gif';
  3853. else if(blob.name.match(/mp4$/))ext = 'mp4';
  3854. else return;
  3855. var fd = new FormData();
  3856. blob.name = blob.name=generateUID().toString();
  3857. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3858. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3859. var reader = new FileReader();
  3860. reader.onload = function(event){
  3861. fl = document.querySelector("#file_list");
  3862. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3863. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3864. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3865. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3866. fl.innerHTML+=ht;
  3867. };
  3868. reader.readAsDataURL(blob);
  3869. }
  3870. sel = document.querySelector('#upload_selector');
  3871. sel.addEventListener("change", function(){
  3872. var input = this;
  3873. function ff(file){
  3874. return function(e){
  3875. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3876. blob.name = file.name;
  3877. AddImageFile(blob);
  3878. }
  3879. }
  3880. for(i=0;i<input.files.length;i++){
  3881. if(input.files[i].size){
  3882. let reader = new FileReader();
  3883. reader.onload = ff(input.files[i]);
  3884. reader.readAsArrayBuffer(input.files[i]);
  3885. }
  3886. }
  3887. });
  3888. function generateUID() {
  3889. var firstPart = (Math.random() * 46656) | 0;
  3890. var secondPart = (Math.random() * 46656) | 0;
  3891. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3892. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3893. return firstPart + secondPart;
  3894. }
  3895. document.onpaste = pastehandler;
  3896. function dropHandler(ev) {
  3897. put = document.querySelector("#_uploader");
  3898. if(put) ShowSideUploader();
  3899. bkg=document.querySelector('#dropping_background');
  3900. bkg.style.display="none";
  3901. console.log('File(s) dropped');
  3902. ev.preventDefault();ev.stopPropagation();
  3903. if (ev.dataTransfer && ev.dataTransfer.items) {
  3904. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3905. if (ev.dataTransfer.items[i].kind === 'file') {
  3906. var file = ev.dataTransfer.items[i].getAsFile();
  3907. function ff(file){
  3908. return function(e){
  3909. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3910. blob.name = file.name;
  3911. AddImageFile(blob);
  3912. }
  3913. }
  3914. if(file){
  3915. let reader = new FileReader();
  3916. reader.onload = ff(file);
  3917. reader.readAsArrayBuffer(file);
  3918. }
  3919. }
  3920. }
  3921. } else {
  3922. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3923. function ff(file){
  3924. return function(e){
  3925. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3926. blob.name = file.name;
  3927. AddImageFile(blob);
  3928. }
  3929. }
  3930. if(ev.dataTransfer.files[i].size){
  3931. let reader = new FileReader();
  3932. reader.onload = ff(ev.dataTransfer.files[i]);
  3933. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3934. }
  3935. }
  3936. }
  3937. }
  3938. function dragOverHandler(ev) {
  3939. bkg=document.querySelector('#dropping_background');
  3940. bkg.style.display="";
  3941. console.log('File(s) in drop zone');
  3942. ev.preventDefault();
  3943. }
  3944. </script>
  3945. <?php
  3946. }
  3947. function CanShowGallery(&$g){
  3948. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  3949. return true;
  3950. }
  3951. function CanShowImage(&$im){
  3952. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3953. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3954. }
  3955. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3956. return true;
  3957. }
  3958. function GetImageBatch($from,$show_all){
  3959. if(!isset($_GET['gallery'])) return;
  3960. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){$name=$_GET['gallery'];}
  3961. $reached=0; $count=0;
  3962. if(isset($this->Images[0])) foreach($this->Images as $im){
  3963. if(isset($from)&&!$reached){ if($from==$im['name']){ $reached=1; } continue; }
  3964. if(!$this->CanShowImage($im)){ continue; }
  3965. if($_GET['gallery']=='trash') $name='trash';
  3966. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;} ?>
  3967. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  3968. <?php if($this->LoggedIn){ ?>
  3969. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3970. <?php } ?>
  3971. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  3972. <?php if(isset($im['video']) && $im['video']!=""){ ?>
  3973. <video data-imgsrc='<?=$im["name"]?>'><source src='<?=$im['file']?>' type='<?=$im['video']?>'></video>
  3974. <?php }else{ ?>
  3975. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  3976. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  3977. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>
  3978. <?=isset($im['align'])?'data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':""?>/>
  3979. <?php } ?>
  3980. </a>
  3981. </div>
  3982. <?php $count+=isset($im['parent'])?0:1; if((!$show_all)&&($count>=$this->GalleryStep)){ break; }
  3983. }
  3984. if($count<$this->GalleryStep){ ?><div style='display:none'>END_GALLERY</div><?php return 0; }
  3985. return 1;
  3986. }
  3987. function MakeGallerySection(){
  3988. if(!isset($_GET['gallery'])) return;
  3989. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3990. $name=$_GET['gallery'];}
  3991. $show_all=0; if(isset($_GET['show_all']) && $_GET['show_all']!='0'){ $show_all=1; } ?>
  3992. <script>
  3993. document.title+=" | <?=$this->T('画廊')?>";
  3994. </script>
  3995. <div class='center_wide' id='div_center' style='position:relative;'><div><br /></div>
  3996. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3997. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3998. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3999. <div class='hidden_on_desktop'>
  4000. <?=$this->T('前往')?>
  4001. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  4002. <optgroup label="<?=$this->T('精选')?>">
  4003. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4004. if(!isset($g['featured']) || !$g['featured'] ||
  4005. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  4006. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  4007. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  4008. <?php } ?></optgroup><optgroup label="<?=$this->T('其他相册')?>">
  4009. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  4010. <?php if($this->LoggedIn){ ?>
  4011. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  4012. <?php } ?>
  4013. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4014. if((isset($g['featured']) && $g['featured']) ||
  4015. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  4016. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  4017. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  4018. <?php } ?></optgroup>
  4019. </select>
  4020. </div>
  4021. <?php if($this->LoggedIn){?>
  4022. <div>
  4023. <?php if(isset($name)){ ?>
  4024. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  4025. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  4026. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  4027. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  4028. <?=$this->T('取消精选')?></a>
  4029. <?php }else{ ?>
  4030. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  4031. <?=$this->T('设为精选')?></a>
  4032. <?php } ?><br />
  4033. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  4034. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  4035. <?=$this->T('取消实验')?></a>
  4036. <?php }else{ ?>
  4037. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  4038. <?=$this->T('设为实验')?></a>
  4039. <?php } ?>
  4040. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  4041. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  4042. <a href='javascript:HidePopMenu();'>×</a>
  4043. <hr />
  4044. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  4045. </div>
  4046. </div>
  4047. <?php } ?>
  4048. <?php $this->MakeUploader(false); ?>
  4049. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  4050. <div style='position:relative'>
  4051. <?php if(isset($name)){ ?>
  4052. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  4053. <?php } ?>
  4054. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  4055. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  4056. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  4057. method="post" style='display:none;' id='gallery_edit_form'></form>
  4058. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  4059. <a href='javascript:HidePopMenu();'>×</a>
  4060. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  4061. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  4062. <input class='button' type='submit' form='gallery_edit_form'
  4063. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  4064. </div>
  4065. </div>
  4066. </div>
  4067. <div class='smaller hidden_on_print'>
  4068. <form action="<?=$_SERVER['REQUEST_URI']?>"
  4069. method="post" style='display:none;' id='gallery_move_form'></form>
  4070. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  4071. id='gallery_move_ops' style='display:none'>
  4072. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  4073. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  4074. <p><?=$this->T('添加到')?>
  4075. <select id="gallery_move_to">
  4076. <option value="trash"><?=$this->T('垃圾桶')?></option>
  4077. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  4078. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  4079. <?php } ?>
  4080. </select>
  4081. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  4082. </p>
  4083. <p>
  4084. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  4085. </p>
  4086. </div>
  4087. </div>
  4088. <?php } ?>
  4089. <p>&nbsp;</p>
  4090. <div><div class='p_row'><?php $has_more=$this->GetImageBatch(NULL, $show_all);?>
  4091. <div class='p_thumb p_thumb_end' <?=$has_more?"onclick='ThisGetMore(this);'":""?>>
  4092. <a onclick='event.preventDefault();' href='index.php?gallery=<?=$_GET['gallery']?>&show_all=1'>
  4093. <h2 id="btn_more_images"><?=$has_more?$this->T("查看更多"):$this->T("没有更多的了");?></a></h2></div></div>
  4094. </div>
  4095. </div>
  4096. <script type='text/javascript'>
  4097. function ThisGetMore(end_ui){
  4098. var xhr = new XMLHttpRequest();
  4099. xhr.onreadystatechange = function() {
  4100. if (this.readyState == 4 && this.status == 200) {
  4101. doc = document.createElement("div"); doc.innerHTML=xhr.responseText.trim(); next_child=null;
  4102. for(child=doc.firstChild; child!==null; child=next_child) { next_child=child.nextSibling; end_ui.parentNode.insertBefore(child,end_ui); }
  4103. doc.remove();
  4104. if(xhr.responseText.search('END_GALLERY')>=0){ end_ui.onclick=null; end_ui.innerHTML="<h2><?=$this->T("没有更多的了");?></h2>"; }
  4105. UpdateImageClickables();
  4106. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("查看更多");?>";
  4107. }
  4108. };
  4109. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("稍等");?>";
  4110. im=end_ui.previousElementSibling.querySelector('img,video');
  4111. from=im?im.dataset.imgsrc:null; if(!from) return;
  4112. const urlParams = new URLSearchParams(window.location.search); const gallery = urlParams.get('gallery')
  4113. xhr.open("GET", "index.php?gallery_continue="+from+'&gallery='+gallery, true);
  4114. xhr.send();
  4115. }
  4116. <?php if($this->LoggedIn){ ?>
  4117. var selected_image = new Array();
  4118. function RemoveFromGallery(){
  4119. form = document.querySelector('#gallery_move_form');
  4120. ops = document.querySelector('#gallery_move_ops');
  4121. sel = document.querySelector('#gallery_move_to');
  4122. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  4123. form.submit();
  4124. }
  4125. function AddToGallery(){
  4126. form = document.querySelector('#gallery_move_form');
  4127. ops = document.querySelector('#gallery_move_ops');
  4128. sel = document.querySelector('#gallery_move_to');
  4129. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  4130. form.submit();
  4131. }
  4132. function ClearSelectedImages(){
  4133. selected_image.splice(0, selected_image.length);
  4134. checks = document.querySelectorAll('._select_hook');
  4135. [].forEach.call(checks, function(c){
  4136. c.classList.remove('p_thumb_selected');
  4137. });
  4138. count = document.querySelector('#gallery_selected_count');
  4139. count.innerHTML="0";
  4140. }
  4141. function ToggleSelectImage(elem, name){
  4142. count = document.querySelector('#gallery_selected_count');
  4143. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  4144. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  4145. count.innerHTML=selected_image.length.toString()
  4146. }
  4147. function ShowGalleryEditMenu(old_name){
  4148. m = document.querySelector('#gallery_edit_menu');
  4149. old = document.querySelector('#gallery_edit_old_name');
  4150. newname = document.querySelector('#gallery_edit_new_name');
  4151. m.style.display='block';
  4152. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  4153. }
  4154. function ShowDeleteMenu(){
  4155. m=document.querySelector('#gallery_delete_menu');
  4156. m.style.display='block';
  4157. }
  4158. <?php } ?>
  4159. </script>
  4160. <?php
  4161. }
  4162. function MakeGalleryLeft(){?>
  4163. <div class='left hidden_m gallery_left' id='div_left'><div><br /></div>
  4164. <h2><?=$this->T('相册')?></h2>
  4165. <div>
  4166. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  4167. <ul>
  4168. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4169. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  4170. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4171. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  4172. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4173. <?php } ?>
  4174. </ul>
  4175. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  4176. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  4177. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  4178. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4179. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  4180. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4181. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  4182. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4183. <?php } ?>
  4184. <?php if($this->LoggedIn){ ?>
  4185. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  4186. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  4187. <?php } ?>
  4188. </ul></div>
  4189. <p>&nbsp;</p>
  4190. <script>
  4191. </script>
  4192. </div>
  4193. </div>
  4194. <?php
  4195. }
  4196. function MakeSettings(){?>
  4197. <div class='settings'>
  4198. <h2><?=$this->T('设置')?></h2>
  4199. <table style='white-space:nowrap;'>
  4200. <?php if($this->LoggedIn){ ?>
  4201. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4202. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4203. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4204. <tr><td><?=$this->T('网站标题')?></td>
  4205. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4206. value='<?=$this->Title?>'/></td></tr>
  4207. <tr><td><?=$this->T('短标题')?></td>
  4208. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4209. value='<?=$this->ShortTitle?>'/></td></tr>
  4210. <tr><td><?=$this->T('显示名称')?></td>
  4211. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4212. value='<?=$this->DisplayName?>'/></td></tr>
  4213. <tr><td><?=$this->T('电子邮件')?></td>
  4214. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4215. value='<?=$this->EMail?>'/></td></tr>
  4216. <tr><td><?=$this->T('导航栏')?>
  4217. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4218. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4219. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4220. <tr><td><?=$this->T('侧边栏')?>
  4221. <?=isset($this->SpecialSidebar)?"<a href='?post=".$this->SpecialSidebar."'>→</a>":""?></td>
  4222. <td><input type="text" form="settings_form" id='settings_special_sidebar' name='settings_special_sidebar'
  4223. value='<?=$this->SpecialSidebar?>'/></td></tr>
  4224. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4225. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4226. value='<?=$this->SpecialFooter?>'/></td></tr>
  4227. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4228. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4229. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4230. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4231. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4232. value='<?=$this->SpecialPinned?>'/></td></tr>
  4233. <tr><td><?=$this->T('默认相册')?></td>
  4234. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4235. value='<?=$this->DefaultGallery?>'/></td></tr>
  4236. <tr><td><?=$this->T('相册单步')?></td>
  4237. <td><input type="text" form="settings_form" id='settings_gallery_step' name='settings_gallery_step'
  4238. value='<?=$this->GalleryStep?>'/></td></tr>
  4239. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4240. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4241. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4242. <tr><td><?=$this->T('启用评论')?></td>
  4243. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4244. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4245. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  4246. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4247. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4248. <tr><td><?=$this->T('长毛象实例')?></td>
  4249. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4250. value='<?=$this->MastodonURL?>'/></td></tr>
  4251. <tr><td><?=$this->T('长毛象令牌')?></td>
  4252. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4253. value='<?=$this->MastodonToken?>'/></td></tr>
  4254. <tr><td><?=$this->T('偏好语言')?></td>
  4255. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4256. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4257. <tr><td><?=$this->T('本站地址')?></td>
  4258. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4259. value='<?=$this->HostURL?>'/></td></tr>
  4260. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4261. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4262. <tr><td><?=$this->T('用户名')?></td>
  4263. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4264. value='<?=$this->APubID?>'/></td></tr>
  4265. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4266. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4267. <tr><td><?=$this->T('主机')?></td>
  4268. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4269. value='<?=$this->HereHost?>'/></td></tr>
  4270. <tr><td><?=$this->T('网站标题')?></td>
  4271. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4272. value='<?=$this->HereTitle?>'/></td></tr>
  4273. <tr><td><?=$this->T('短标题')?></td>
  4274. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4275. value='<?=$this->HereShortTitle?>'/></td></tr>
  4276. <tr><td><?=$this->T('相册')?></td>
  4277. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4278. value='<?=$this->HereAlbum?>'/></td></tr>
  4279. <tr><td><?=$this->T('导航栏')?>
  4280. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4281. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4282. value='<?=$this->HereNavigation?>'/></td></tr>
  4283. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4284. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4285. value='<?=$this->HereFooter?>'/></td></tr>
  4286. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4287. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4288. <tr><td><?=$this->T('主机')?></td>
  4289. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4290. value='<?=$this->ExpHost?>'/></td></tr>
  4291. <tr><td><?=$this->T('网站标题')?></td>
  4292. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4293. value='<?=$this->ExpTitle?>'/></td></tr>
  4294. <tr><td><?=$this->T('短标题')?></td>
  4295. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4296. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4297. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4298. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4299. value='<?=$this->ExpCaution?>'/></td></tr>
  4300. <tr><td><?=$this->T('相册')?></td>
  4301. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4302. value='<?=$this->ExpAlbum?>'/></td></tr>
  4303. <tr><td><?=$this->T('导航栏')?>
  4304. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4305. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4306. value='<?=$this->ExpNavigation?>'/></td></tr>
  4307. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4308. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4309. value='<?=$this->ExpFooter?>'/></td></tr>
  4310. <tr><td><?=$this->T('允许选择语言')?>
  4311. <td><input type="checkbox" id="settings_allow_language" name="settings_allow_language"
  4312. form="settings_form" <?=$this->AllowLanguageChoices?"checked":""?>/></td></tr>
  4313. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4314. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4315. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  4316. <tr><td><?=$this->T('帐号')?></td>
  4317. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4318. value='<?=$this->Admin?>'/></td></tr>
  4319. <tr><td><?=$this->T('新密码')?></td>
  4320. <td><input type="password" form="settings_form"
  4321. id='settings_new_password' name='settings_new_password' /></td></tr>
  4322. <tr><td><?=$this->T('再次输入')?></td>
  4323. <td><input type="password" form="settings_form"
  4324. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4325. <tr><td><?=$this->T('旧密码')?></td>
  4326. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4327. <?php }else{ ?>
  4328. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4329. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4330. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4331. <tr><td><?=$this->T('帐号')?></td>
  4332. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4333. <tr><td><?=$this->T('密码')?></td>
  4334. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4335. <?php } ?>
  4336. </table>
  4337. <?php if($this->LoggedIn){ ?>
  4338. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4339. <?php }else{ ?>
  4340. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4341. <?php } ?>
  4342. </div>
  4343. <?php
  4344. }
  4345. function MakeExtraOperations(){?>
  4346. <div class='settings' style='overflow:auto;'>
  4347. <h2><?=$this->T('附加操作')?></h2>
  4348. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  4349. <p>&nbsp;</p>
  4350. <h3><?=$this->T('自动重定向')?></h3>
  4351. <span class='smaller gray'>
  4352. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4353. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4354. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4355. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  4356. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4357. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4358. value='<?=$this->T('保存重定向设置')?>' />
  4359. <p>&nbsp;</p>
  4360. <h3><?=$this->T('自定义翻译')?></h3>
  4361. <span class='smaller gray'>
  4362. <?=$this->T('填写格式:')?>
  4363. <br /><pre>- 语言 | Language</pre></span>
  4364. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4365. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  4366. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4367. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4368. value='<?=$this->T('保存翻译')?>' />
  4369. <p>&nbsp;</p>
  4370. <p class='smaller gray'><?=$this->T('ActivityPub 测试:')?></p>
  4371. <ul>
  4372. <li><a href='index.php?TestAPubDeliver=1'><?=$this->T('测试发送')?></a></li></ui>
  4373. </ui>
  4374. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4375. <ul>
  4376. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  4377. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  4378. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  4379. </ui>
  4380. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4381. </div>
  4382. <?php
  4383. }
  4384. function MakeMainBegin(){?>
  4385. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4386. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4387. <?php
  4388. }
  4389. function MakeMainEnd(){?>
  4390. </div>
  4391. <?php
  4392. }
  4393. function MakeExpFooter(){
  4394. $exptitle = isset($this->HereDisplayTitle)?('"'.trim($this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle))).'"'):NULL;
  4395. if(!isset($exptitle)) $exptitle=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle);?>
  4396. <div class='small_footer exp_h_f exp_f'><div>
  4397. <?php if($this->InExperimentalMode){ ?>
  4398. <b><?=$exptitle?></b>
  4399. <?php }else{ ?>
  4400. <b><?=$exptitle?></b> ©<?=$this->T($this->DisplayName)?>
  4401. <?php }?>
  4402. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):""; ?>
  4403. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4404. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4405. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4406. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4407. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4408. }?></div>
  4409. </div>
  4410. </div>
  4411. </div><!-- page -->
  4412. </body>
  4413. </html>
  4414. <script>
  4415. if(trans = document.getElementById('translate_button')){
  4416. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4417. }
  4418. </script>
  4419. <?php
  4420. }
  4421. function MakeImageOverlay($side_info=null,$static_image=null,$static_video=null){
  4422. $static=isset($side_info); ?>
  4423. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  4424. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  4425. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  4426. <?php if(!$static_video){ ?>
  4427. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/><?php } ?>
  4428. <?php if(!$static_image){ ?>
  4429. <video id='big_video' onloadstart="HideWaitingBar();" controls><source id='big_video_src' type='video/mp4'
  4430. <?=isset($static_video)?("src='".$static_video."'"):""?>></video><?php } ?>
  4431. </div>
  4432. <div class='big_side_box' onclick='HideBigImage(1);'>
  4433. <?php if(!$static){ ?>
  4434. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  4435. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  4436. <div class='lr_buttons'>←</div></a></div>
  4437. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  4438. <div class='lr_buttons'>→</div></a></div>
  4439. <div id='here_buttons'></div>
  4440. </div><?php } ?>
  4441. <div class='side_box_mobile_inner'>
  4442. <?php if(!$static){ ?>
  4443. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  4444. <span style='display:none;' id='image_purchase' class='clean_a'>
  4445. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  4446. <br class='hidden_on_desktop block_m' /></span>
  4447. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  4448. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4449. &nbsp;<a class='clean_a' id='image_inquiry'>
  4450. <b>@</b><?=$this->T('咨询')?></a>
  4451. <?php } ?><hr class='hidden_on_desktop block_m' />
  4452. </div>
  4453. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  4454. <li class='wayback_close'><a onclick='HideBigImage(1);'><?=$this->T('关闭')?> ×</a></li>
  4455. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  4456. <hr />
  4457. </div><?php } //static ?>
  4458. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  4459. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  4460. <br /><?=$this->T('印刷品链接')?>
  4461. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  4462. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  4463. <?=$this->T('重命名')?>
  4464. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  4465. <?=$this->T('主图')?>
  4466. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  4467. <?=$this->T('对齐')?> <select id='image_align' name='image_align' form="image_ops_form">
  4468. <option value='top'><?=$this->T('顶部')?></option>
  4469. <option value='middle'><?=$this->T('中间')?></option>
  4470. <option value='bottom'><?=$this->T('底部')?></option></select><br />
  4471. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  4472. <br /><br /><?=$this->T('替换图像')?>
  4473. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  4474. <input type="file" form='image_edit_form'
  4475. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  4476. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  4477. value=<?=$this->T('执行')?> />
  4478. </div><?php } ?>
  4479. </div>
  4480. </div>
  4481. </div>
  4482. <?php }
  4483. function MakePageEnd(){?>
  4484. </div><!-- page -->
  4485. </body>
  4486. </html>
  4487. <?php }
  4488. function MakeFooter(&$p){ $no_title=isset($p['tid']['first']['no_title']);?>
  4489. <div class='small_footer'><div>
  4490. <hr />
  4491. <?php if(isset($p['tid']['footer'])){ ?><div class='show_on_print'><?=$p['tid']['footer'];?></div><?php } ?>
  4492. <b<?=$no_title?" class='hidden_on_print'":"";?>><?=$this->T($this->Title)?></b>
  4493. <span onclick='event.stopPropagation()'<?=$no_title?" class='hidden_on_print'":"";?>
  4494. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  4495. <div class='smaller show_on_print'><?=$_SERVER['SERVER_NAME']?><br /><?=$this->EMail?></div>
  4496. </div></div>
  4497. <div class='footer'>
  4498. <div style='white-space:nowrap;'>
  4499. <div class='footer_additional'>
  4500. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  4501. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4502. } ?>
  4503. </div>
  4504. <div class='footer_additional'>
  4505. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  4506. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4507. } ?>
  4508. </div>
  4509. </div>
  4510. </div>
  4511. <p>&nbsp;<p>
  4512. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  4513. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  4514. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  4515. </div>
  4516. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  4517. <script>
  4518. <?=$this->ExtraScripts?>
  4519. if(back = document.getElementById('button_back')){
  4520. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  4521. back.href='javascript:history.back()';
  4522. }else{
  4523. back.href='index.php';
  4524. }
  4525. }
  4526. function copy_text(t) {
  4527. ta = document.createElement('textarea'); document.body.appendChild(ta); ta.value = t; ta.select();
  4528. document.execCommand("copy"); document.body.removeChild(ta);
  4529. }
  4530. if(trans = document.getElementById('translate_button')){
  4531. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4532. }
  4533. function ClickPost(p,e,pushstate){if(e)e.preventDefault();
  4534. id=p.dataset.postId; list=p.parentNode;active=list.getElementsByClassName('active_post');
  4535. lp=p.querySelector('.lpctrl');
  4536. if(active&&active[0]&&active[0]!=p){
  4537. if(pushstate){window.history.pushState('?post='+id,null,'?post='+id);}
  4538. active[0].classList.remove('active_post'); p.classList.add('active_post');
  4539. }
  4540. }function InitLabel(){
  4541. lb=document.querySelector('#mtitle'); lb.removeAttribute('for'); lb.onclick=function()
  4542. {c=document.querySelector('#titlectrl');if(c.checked)c.checked=false;else c.checked=true;}
  4543. lb=document.querySelectorAll('.bkg_section label');if(!lb||!lb[0])return;
  4544. for(i=0;i<lb.length;i++){ lb[i].removeAttribute('for');lb[i].onclick=function()
  4545. {c=this.parentNode.querySelector('.lpctrl');if(!c)return;if(c.checked)c.checked=false;else c.checked=true;} }
  4546. }InitLabel();
  4547. <?php if($this->LoggedIn){ ?>
  4548. var Scenter = document.querySelector('#div_center');
  4549. var Sposts = Scenter?Scenter.querySelectorAll('.post'):null;
  4550. <?php if(isset($this->MastodonToken)){ ?>
  4551. function MarkPostDoneMastodon(id,mastodon_url){
  4552. for(var i=0;i<Sposts.length;i++){
  4553. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  4554. }
  4555. <?php } ?>
  4556. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  4557. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  4558. var Smerge_post = Scenter.querySelector('#merge_post');
  4559. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  4560. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  4561. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  4562. var Smerge_select = Scenter.querySelector('#merge_select');
  4563. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  4564. var Smerge_thread = Scenter.querySelector('#merge_thread');
  4565. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  4566. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  4567. var select_mode = false; var merge_mode = false; var selected_posts = null;
  4568. function TogglePostSelectMode(force_on=false,force_off=false){
  4569. Scenter.classList.add('post_selecting');
  4570. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  4571. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  4572. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  4573. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  4574. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  4575. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4576. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  4577. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  4578. Smerge_post_count.innerText="0";
  4579. Smerge_post.href="#";
  4580. }
  4581. function TogglePostSelect(elem){
  4582. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  4583. else{ elem.classList.add('post_selected'); }
  4584. selected_posts = new Array();
  4585. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  4586. selected_posts.push(Sposts[i].dataset.postId); } }
  4587. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  4588. Smerge_post_count.innerText=selected_posts.length;
  4589. }
  4590. function ThreadMergeInput(elem){
  4591. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  4592. else{ Smerge_thread.href="#"; }
  4593. }
  4594. function ToggleThreadMerge(force_on=false,force_off=false){
  4595. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  4596. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  4597. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  4598. else{ merge_mode = 0;
  4599. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  4600. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4601. Smerge_thread.href="#";
  4602. Smerge_thread_target.value='';
  4603. }
  4604. <?php } ?>
  4605. function ShowSideUploader(){
  4606. ShowRightSide(true,null);
  4607. put = document.querySelector("#_uploader");
  4608. put.style.display='block';
  4609. RefreshSideGallery();
  4610. }
  4611. dmark = document.querySelector("#mark_details");
  4612. drename = document.querySelector("#rename_details");
  4613. dmastodon = document.querySelector("#mastodon_details");
  4614. drename_form = document.querySelector("#post_rename_form");
  4615. drename_input = document.querySelector("#post_rename_name");
  4616. var rp = document.querySelector('#post_reply_to');
  4617. var _reply_to = rp?rp.defaultValue:"";
  4618. function RestoreReply(){
  4619. if(rp){
  4620. rp.defaultValue = _reply_to;
  4621. }
  4622. document.querySelector('#post_reply_restore').style.display='none';
  4623. ht = document.querySelector('#post_hint_text');
  4624. if (_reply_to!=""){
  4625. ht.style.display='block';
  4626. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  4627. }else{
  4628. ht.style.display='none';
  4629. }
  4630. document.querySelector('#post_edit_target').value="";
  4631. ch = document.querySelector('#post_hint_modify');
  4632. ch.style.display='none';
  4633. }
  4634. function MakeRefer(id){
  4635. t = document.querySelector('#post_content')
  4636. t.focus();
  4637. v = t.value;
  4638. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  4639. la_auto_grow(t);
  4640. if(rp){
  4641. rp.defaultValue = "";
  4642. ht = document.querySelector('#post_hint_text');
  4643. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  4644. document.querySelector('#post_reply_restore').style.display='inline';
  4645. rs = document.querySelector('#post_reply_restore');
  4646. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  4647. document.getElementById('post_menu').style.display='none';
  4648. ch = document.querySelector('#post_hint_modify');
  4649. ch.style.display='none';
  4650. }
  4651. }
  4652. function CopyRefer(id){
  4653. copy_text(id.toString());
  4654. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  4655. }
  4656. function MakeEdit(id){
  4657. ed = document.getElementById('menu_edit');
  4658. ed.innerHTML="<?=$this->T('稍等')?>";
  4659. ed.href="#";
  4660. var xhr = new XMLHttpRequest();
  4661. xhr.onreadystatechange = function() {
  4662. if (this.readyState == 4 && this.status == 200) {
  4663. ed.innerHTML='——';
  4664. ch = document.querySelector('#post_hint_modify');
  4665. ch.style.display='block';
  4666. ht = document.querySelector('#post_hint_text');
  4667. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  4668. rs = document.querySelector('#post_reply_restore');
  4669. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  4670. t = document.querySelector('#post_content');
  4671. t.value=xhr.responseText.trim();
  4672. t.focus();
  4673. la_auto_grow(t);
  4674. document.querySelector('#post_edit_target').value=id;
  4675. document.getElementById('post_menu').style.display='none';
  4676. }
  4677. };
  4678. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4679. xhr.send();
  4680. }
  4681. function MarkDelete(id){
  4682. p = document.querySelector('[data-post-id="'+id+'"]');
  4683. op = p.dataset.markDelete?"false":"true";
  4684. window.location.href=
  4685. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4686. }
  4687. function SetMark(mark){
  4688. menu = document.getElementById('post_menu');
  4689. window.location.href=
  4690. "index.php?<?=$this->GetRedirect()?>&target="+
  4691. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4692. }
  4693. function ToggleMarkDetails(){
  4694. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  4695. drename.style.display=dmastodon.style.display='none';
  4696. }
  4697. function ToggleRenameDetails(){
  4698. drename.style.display=(drename.style.display=='block')?'none':'block';
  4699. dmark.style.display=dmastodon.style.display='none';
  4700. }
  4701. function ToggleMastodonDetails(){
  4702. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  4703. dmark.style.display=drename.style.display='none';
  4704. }
  4705. <?php } ?>
  4706. function ShowPostMenu(post){
  4707. menu = document.getElementById('post_menu');
  4708. menu.style.display='block';
  4709. menu.parentNode.removeChild(menu);
  4710. post.appendChild(menu);
  4711. menu.style.display='block';
  4712. id = post.dataset.postId
  4713. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4714. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4715. window.onClick="HidePopMenu()";
  4716. menu.onClick=(function(event){
  4717. event.stopPropagation();
  4718. });
  4719. hs = menu.querySelector('#menu_history');
  4720. hs.href='?post='+id+'&history=1';
  4721. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4722. <?php if($this->PageType!='search'){?>
  4723. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4724. ed = menu.querySelector('#menu_edit');ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4725. <?php } ?>
  4726. ref = menu.querySelector('#menu_refer_copy')
  4727. ref.innerHTML='<?=$this->T("复制编号")?>';
  4728. ref.href='javascript:CopyRefer(id)';
  4729. d = menu.querySelector('#menu_delete');
  4730. d.href='javascript:MarkDelete(\"'+id+'\")';
  4731. p = document.querySelector('[data-post-id="'+id+'"]');
  4732. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4733. menu.querySelector('#mark_details').dataset.id=id;
  4734. drename_input.value=id;
  4735. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4736. <?php if(isset($this->MastodonToken)){ ?>
  4737. dmastodon_form = document.querySelector("#post_mastodon_form");
  4738. dmastodon_form.action='?mastodon_post='+id;
  4739. function MastodonSend(id){
  4740. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  4741. var xhr = new XMLHttpRequest();
  4742. function wrapidxhr(_id) { return function() {
  4743. if (this.readyState == 4 && this.status == 200) {
  4744. var response = xhr.responseText;
  4745. let content="";
  4746. if(res = response.match(/SUCCESS (\S+)/u)){
  4747. content="<?=$this->T('成功发送到长毛象')?>";
  4748. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  4749. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  4750. MarkPostDoneMastodon(_id, res[1]);
  4751. } }
  4752. };
  4753. xhr.onreadystatechange = wrapidxhr(id);
  4754. xhr.open("GET", "index.php?mastodon_send_post="+id, true); xhr.send();
  4755. }
  4756. menu_mastodon = menu.querySelector("#menu_mastodon");
  4757. mastodon_send = menu.querySelector("#menu_mastodon_send");
  4758. mastodon_view = menu.querySelector("#menu_mastodon_view");
  4759. mastodon_url = menu.querySelector("#post_mastodon_url");
  4760. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  4761. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  4762. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  4763. mastodon_url.value="";}
  4764. mastodon_send.onclick=function(){
  4765. this.onclick=function(){};
  4766. MastodonSend(id); };
  4767. <?php } } ?>
  4768. title = document.title;
  4769. copy = document.getElementById('share_copy');
  4770. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4771. copy.addEventListener("click", function(){
  4772. url = window.location
  4773. path = location.pathname
  4774. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4775. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4776. });
  4777. }
  4778. function HidePopMenu(){
  4779. var menus = document.querySelectorAll('.pop_menu');
  4780. [].forEach.call(menus, function(m){m.style.display='none';});
  4781. }
  4782. var posts = document.querySelectorAll('.center .post');
  4783. [].forEach.call(posts, function(p){
  4784. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4785. ShowPostMenu(this.parentNode);ClickPost(this.parentNode,null,true)
  4786. });
  4787. });
  4788. var post_clickables = document.querySelectorAll('.center .post a');
  4789. [].forEach.call(post_clickables, function(p){
  4790. p.addEventListener("click", function(event){
  4791. event.stopPropagation();
  4792. });
  4793. });
  4794. function FindImage(imgsrc){
  4795. for(var i=0;i<document.images_filtered.length;i++){
  4796. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4797. }
  4798. return null
  4799. }
  4800. var dottime1;
  4801. var dottime2;
  4802. function ToDataURL(url) {
  4803. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4804. clearTimeout(dottime1);clearTimeout(dottime2);
  4805. ps = document.querySelector('#download_processing');
  4806. ps.innerHTML='↓';ps.style.opacity='';
  4807. return URL.createObjectURL(blob);});
  4808. }
  4809. async function DownloadAsImage(url,name) {
  4810. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4811. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4812. }
  4813. function basename(url){return url.split(/[\\/]/).pop();}
  4814. pushed=0;
  4815. function ShowBigImage(imgsrc,do_push){
  4816. ShowWaitingBar();
  4817. share = document.querySelector('#big_image_share');
  4818. img = document.querySelector('#big_image');
  4819. vid = document.querySelector('#big_video');
  4820. vidsrc = document.querySelector('#big_video_src');
  4821. down = document.querySelector('#image_download');
  4822. img.src = ""; vidsrc.src="";
  4823. if(imgsrc.match(/\.mp4$/)){
  4824. vidsrc.src = src = "images/"+imgsrc; img.style.display='none'; vid.load();vid.style.display='block';
  4825. }else{
  4826. img.src = src = "images/"+imgsrc; vid.style.display='none';img.style.display='block';
  4827. }
  4828. down.href="images/"+imgsrc;
  4829. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_<?=$this->GiveSafeEMail()?>_'+
  4830. basename(down.href);
  4831. img.alt = downname; down.download=downname;
  4832. var use_href = "images/"+imgsrc;
  4833. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4834. ps = this.querySelector('#download_processing');ps.innerText='…';
  4835. var dotwait = function(ps){ var self = this;
  4836. dottime1 = setTimeout(function(ps){
  4837. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4838. dotwait(this.querySelector('#download_processing'));
  4839. DownloadAsImage(use_href,downname);};
  4840. if(do_push){PushGalleryHistory(src)}
  4841. page_url = encodeURIComponent(window.location.href);
  4842. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4843. inqb = document.querySelector('#image_inquiry');
  4844. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4845. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4846. (page_url)+encodeURIComponent('\n\n');
  4847. <?php } ?>
  4848. this_image = FindImage(imgsrc);
  4849. if(this_image&&this_image.dataset.prevsrc){
  4850. new_image = FindImage(this_image.dataset.prevsrc);
  4851. new_prev = new_image?new_image.dataset.prevsrc:null;
  4852. im = document.querySelector('#prev_image');
  4853. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4854. else {im.style.opacity='0';im.removeAttribute("href");}
  4855. }
  4856. if(this_image&&this_image.dataset.nextsrc){
  4857. new_image = FindImage(this_image.dataset.nextsrc);
  4858. new_next = new_image?new_image.dataset.nextsrc:null;
  4859. im = document.querySelector('#next_image');
  4860. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4861. else {im.style.opacity='0';im.removeAttribute("href");}
  4862. }
  4863. purchase = document.querySelector('#image_purchase');
  4864. purchase_btn = document.querySelector('#image_purchase_button');
  4865. <?php if($this->LoggedIn){ ?>
  4866. product_link = document.querySelector('#image_ops_product_link');
  4867. product_form = document.querySelector('#image_ops_form');
  4868. edit_form = document.querySelector('#image_edit_form');
  4869. edit_new_name = document.querySelector('#image_edit_new_name');
  4870. edit_parent = document.querySelector('#image_parent');
  4871. edit_align = document.querySelector('#image_align');
  4872. product_form.action = window.location.href;
  4873. edit_form.action = window.location.href;
  4874. edit_new_name.value = imgsrc.split('.')[0];
  4875. if(this_image){
  4876. if(this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  4877. if(this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  4878. if(this_image.dataset.align){ edit_align.value = this_image.dataset.align; }else{ edit_align.value = "middle"; }
  4879. }
  4880. <?php } ?>
  4881. if(this_image&&this_image.dataset.product){
  4882. purchase.style.display='';
  4883. href = this_image.dataset.product;
  4884. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4885. href = '?post='+href;
  4886. }
  4887. purchase_btn.href = href;
  4888. }else{
  4889. purchase.style.display='none';
  4890. purchase_btn.removeAttribute("href");
  4891. }
  4892. DelayHideImgBtn(null);
  4893. title = encodeURIComponent(document.title);
  4894. copy = document.getElementById('big_share_copy');
  4895. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4896. copy.addEventListener("click", function(){
  4897. copy_text(window.location.href);
  4898. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4899. });
  4900. o = document.querySelector('#big_image_overlay');
  4901. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  4902. here = document.querySelector('#here_buttons');here.innerHTML='';
  4903. o.style.display="block";
  4904. ShowBackdrop(0.8);
  4905. var xhr = new XMLHttpRequest();
  4906. xhr.onreadystatechange = function() {
  4907. if (this.readyState == 4 && this.status == 200) {
  4908. info = document.querySelector('#big_image_info');
  4909. var response = xhr.responseText;
  4910. let content=""
  4911. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4912. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4913. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4914. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4915. content+="<div class='clean_a'>"+res[1]+"</div>"; }
  4916. info.innerHTML=content;
  4917. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  4918. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  4919. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  4920. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  4921. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  4922. }
  4923. }
  4924. };
  4925. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4926. xhr.send();
  4927. }
  4928. function HideBigImage(do_push){
  4929. o = document.querySelector('#big_image_overlay');
  4930. img = document.querySelector('#big_image');
  4931. vid = document.querySelector('#big_video');
  4932. vidsrc = document.querySelector('#big_video_src');
  4933. img.src = ""; vidsrc.src="";
  4934. if(o.style.display!='none'){
  4935. o.style.display="none";
  4936. HideBackdrop();
  4937. if(do_push){PushGalleryHistory("");}
  4938. HideWaitingBar();
  4939. }
  4940. }
  4941. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4942. var inq=document.querySelector('#inquiry_buttons');
  4943. var overlay=document.querySelector('#big_image_overlay');
  4944. var hide_timeout;
  4945. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4946. function DelayHideImgBtn(e){
  4947. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  4948. inq.classList.remove('img_btn_hidden');
  4949. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  4950. clearTimeout(hide_timeout);
  4951. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  4952. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  4953. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  4954. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  4955. }
  4956. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4957. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4958. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4959. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4960. function UpdateImageClickables(){
  4961. var images = document.querySelectorAll('img, video');
  4962. var images_filtered=new Array(); var imgadded = new Array();
  4963. var images_remaining=new Array();
  4964. [].forEach.call(images, function(img){
  4965. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4966. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4967. images_filtered.push(img);imgadded.push(imgsrc);
  4968. });
  4969. for(var i=0; i<images_filtered.length; i++){
  4970. previmg = nextimg = null; img = images_filtered[i];
  4971. if(i>0) previmg=images_filtered[i-1];
  4972. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4973. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4974. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4975. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4976. var clone = img.cloneNode(true); img.replaceWith(clone);
  4977. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  4978. }
  4979. for(var i=0; i<images_remaining.length; i++){
  4980. img = images_remaining[i];
  4981. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4982. var clone = img.cloneNode(true); img.replaceWith(clone);
  4983. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  4984. }
  4985. document.images_filtered = images_filtered;
  4986. }
  4987. UpdateImageClickables();
  4988. function PopGalleryHistory(){
  4989. if(pushed){
  4990. pushed = 0;
  4991. try{
  4992. history.back();
  4993. }catch{
  4994. console.log("can't do it.");
  4995. }
  4996. }
  4997. }
  4998. function PushGalleryHistory(src){
  4999. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  5000. title = "照片"
  5001. extra = "?";
  5002. sp = new URLSearchParams(window.location.search)
  5003. if(sp.has('post')){extra+="post="+sp.get('post')}
  5004. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  5005. try{
  5006. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  5007. }catch{
  5008. console.log("can't do it.");
  5009. }
  5010. pushed = 1;
  5011. }
  5012. document.addEventListener('keydown', function(e){
  5013. large = document.getElementById('big_image_overlay')
  5014. if (large.style.display!='block') return;
  5015. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  5016. HideBigImage(1);
  5017. }
  5018. }, true);
  5019. window.addEventListener('popstate', (event) => {
  5020. href=window.location.href;
  5021. let sp = new URLSearchParams(href.substring(href.indexOf('?')))
  5022. if(sp.has('pic')){
  5023. src = sp.get('pic')
  5024. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)) ShowBigImage(onlyimg[0], 0);
  5025. else{HideBigImage(0);}
  5026. }else{HideBigImage(0);}
  5027. if(sp.has('post')){
  5028. id=sp.get('post');post=document.querySelector('.post[data-post-id="'+id+'"]');
  5029. if(post){ClickPost(post,null,false);}
  5030. }
  5031. });
  5032. let searchParams = new URLSearchParams(window.location.search)
  5033. if(searchParams.has('pic')){
  5034. src = searchParams.get('pic')
  5035. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)){
  5036. ShowBigImage(onlyimg[0], 1);
  5037. }
  5038. }
  5039. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  5040. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  5041. </script>
  5042. </body>
  5043. <?php
  5044. }
  5045. function DoIdentifyExperimental(){
  5046. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  5047. $this->InExperimentalMode=True; $this->InHereMode=True;
  5048. if(!$this->AllowLanguageChoices){ $this->LanguageAppendix='en'; }
  5049. }
  5050. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  5051. $this->InHereMode=True;
  5052. }
  5053. }
  5054. function DoExperimentalTopLink($p){
  5055. if($this->InHereMode && $p){
  5056. if(isset($p['tid']) && $p['tid']['first']!=$p){
  5057. header('Location: ?post='.$p['tid']['first']['id']); exit();
  5058. }
  5059. }
  5060. }
  5061. function MakeExperimentalConfirm(){
  5062. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  5063. return false;
  5064. }
  5065. $caution_html =
  5066. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  5067. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  5068. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  5069. ?>
  5070. <div class='center_exp'><?php
  5071. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  5072. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  5073. ?></div>
  5074. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  5075. <?php return true;
  5076. }
  5077. }
  5078. $la = new LA;
  5079. $la->DoSiteRedirect();
  5080. $la->DoLogin();
  5081. $la->SwitchLanguageAndFont();
  5082. $err = $la->ProcessRequest($message, $redirect);
  5083. $la->WriteAsNecessary();
  5084. $la->DoIdentifyExperimental();
  5085. $la->SwitchWayBackMode();
  5086. if($err){
  5087. echo $message;
  5088. exit();
  5089. }
  5090. if(isset($redirect)){
  5091. header('Location: '.$redirect);
  5092. exit();
  5093. }
  5094. $la->DetectPageType();
  5095. $la->ReadImages(false);
  5096. $la->ReadPosts();
  5097. if(isset($la->WayBack)){
  5098. $la->ReadArchive();
  5099. }
  5100. $im = NULL;
  5101. if(preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  5102. if(!$la->CanShowImage($im)) { $im=&$la->NULL_IMAGE; }
  5103. }
  5104. $p = &$la->GetPost($la->CurrentPostID);
  5105. if(!isset($p)){
  5106. $p = &$la->GetMergedPost($la->CurrentPostID);
  5107. }
  5108. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  5109. else{ $la->DoExperimentalTopLink($p); }
  5110. if(isset($p)){ $la->ActualPostID = $p['id']; }
  5111. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5112. if($im){
  5113. $la->SetHereMainImage($im);
  5114. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  5115. }else if($p){
  5116. $la->RecordVisitedHere($p['id'],NULL);
  5117. }else {
  5118. $im = &$la->GiveImageInHere(false);
  5119. if($im){
  5120. $la->SetHereMainImage($im);
  5121. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  5122. }
  5123. }
  5124. }
  5125. $la->MakeHeader($p);
  5126. $la->MakeMainBegin();
  5127. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5128. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  5129. if($im){
  5130. $la->MakeHereSection($im);
  5131. }else if($p){
  5132. $la->MakePostSectionExp($p);
  5133. $la->MakeLinkedPostsExp($p);
  5134. }else {
  5135. if($im){
  5136. $la->MakeHereSection($im);
  5137. }else{
  5138. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5139. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  5140. }
  5141. }
  5142. }
  5143. $la->MakeMainEnd();
  5144. $la->MakeExpFooter();
  5145. }else{
  5146. if($la->PageType=='extras'){
  5147. $la->MakeExtraOperations();
  5148. }else if($la->PageType=='settings'){
  5149. $la->MakeSettings();
  5150. }else if($la->PageType=='gallery'){
  5151. $la->MakeGalleryLeft();
  5152. $la->MakeGallerySection();
  5153. }else if($la->PageType=='post'){
  5154. if($p){
  5155. $made_interesting = false;
  5156. if($la->IsInterestingPost($p)){
  5157. $la->MakeInterestingSection($p['tid']);
  5158. }
  5159. else{
  5160. $la->MakeSidebar();
  5161. $la->MakePostSection($p);
  5162. }
  5163. }else{
  5164. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5165. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  5166. }
  5167. }else if($la->PageType=='history'){
  5168. $la->ReadArchive();
  5169. $la->MakePostHistory($p, $_GET['version']??NULL);
  5170. }else if($la->PageType=='search'){
  5171. $la->MakeSidebar();
  5172. $la->MakeRecentPosts($_GET['search']);
  5173. }else if($la->PageType=='category'){
  5174. $la->MakeSidebar();
  5175. $la->MakeRecentPosts(NULL,$_GET['category']);
  5176. }else if($la->PageType=='comments'){
  5177. $la->MakeCommentPosts();
  5178. }else{
  5179. $la->MakeSidebar();
  5180. $la->MakeRecentPosts();
  5181. }
  5182. $la->MakeMainEnd();
  5183. $la->MakeFooter($p);
  5184. }
  5185. ?>