*/}}

index.php 300 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277
  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 $Redirect;
  45. protected $Translations;
  46. protected $CustomTranslationContent;
  47. protected $CurrentOffset;
  48. protected $PostsPerPage;
  49. protected $HotPostCount;
  50. protected $LoggedIn;
  51. protected $LoginTokens;
  52. protected $InHereMode;
  53. protected $InExperimentalMode;
  54. protected $LanguageAppendix;
  55. protected $UseRemoteFont;
  56. protected $Posts;
  57. protected $Threads; // [ keys: first last displayed count]
  58. protected $WaybackThreads;
  59. public $Images;
  60. protected $Galleries;
  61. protected $Anchors;
  62. protected $ArchiveHandles;
  63. protected $Archive;
  64. public $WayBack;
  65. protected $YearBegin;
  66. protected $YearEnd;
  67. protected $Markers;
  68. protected $ExtraScripts;
  69. protected $APubID;
  70. protected $APubActor;
  71. protected $APubPublicKey;
  72. protected $APubPrivateKey;
  73. protected $TIME_STRING;
  74. public $NULL_POST;
  75. public $NULL_IMAGE;
  76. public $NULL_IMAGE_DUMMY;
  77. public $NULL_Gallery;
  78. protected $DoneReadPosts;
  79. protected $DoneReadImages;
  80. protected $DoneReadArchive;
  81. protected $NeedWritePosts;
  82. protected $NeedWriteImages;
  83. protected $NeedWriteArchive;
  84. protected $HereDisplayTitle;
  85. protected $VisitedHere;
  86. protected $HereNumber;
  87. protected $HereMainImage;
  88. public $PageType;
  89. public $CurrentPostID;
  90. public $HereID;
  91. public $ActualPostID;
  92. public $TagID;
  93. function ReadableTime($id){
  94. $dt = DateTime::createFromFormat('YmdHis', $id);
  95. return $dt->format('Y/m/d H:i:s');
  96. }
  97. function StandardTime($id){
  98. $dt = DateTime::createFromFormat('YmdHis', $id);
  99. return $dt->format('Y-m-d\TH:i:sP');
  100. }
  101. function FullURL(){
  102. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  103. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  104. $_SERVER['REQUEST_URI'];
  105. }
  106. function T($str){
  107. if(!$this->LanguageAppendix) return $str;
  108. foreach($this->Translations as $entry){
  109. if($entry['zh']==$str)
  110. return $entry[$this->LanguageAppendix];
  111. }
  112. return $str;
  113. }
  114. function SwitchLanguageAndFont(){
  115. $this->LanguageAppendix = 'zh';
  116. if(isset($_COOKIE['la_language'])){
  117. $this->LanguageAppendix = $_COOKIE['la_language'];
  118. }else{
  119. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  120. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  121. $lang = substr($lang,0,5);
  122. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  123. else $this->LanguageAppendix = 'en';
  124. }
  125. }
  126. if(isset($_COOKIE['la_font'])){
  127. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  128. }
  129. }
  130. function SwitchWayBackMode(){
  131. if(isset($_COOKIE['la_wayback'])){
  132. $this->WayBack = $_COOKIE['la_wayback'];
  133. }else $this->WayBack = NULL;
  134. }
  135. function DisplayRedirectConfig(){
  136. $s = "";
  137. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  138. if($r['for']=='P'){
  139. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  140. }else if($r['for']=='S'){
  141. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  142. }
  143. }
  144. return $s;
  145. }
  146. function DoSiteRedirect(){
  147. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  148. if($r['for']=='S'){
  149. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  150. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  151. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  152. }else{
  153. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. function WriteHTACCESS(){
  160. $conf = fopen('.htaccess','w');
  161. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  162. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  163. if($r['for']=='P'){
  164. if(!preg_match('/[0-9]{14}/',$r['target'])){
  165. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?'.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  166. }
  167. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  168. }// do site redirect in php.
  169. }
  170. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  171. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  172. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  173. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  174. fwrite($conf, 'RewriteCond %{HTTP_HOST} !^www\.'.PHP_EOL.
  175. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  176. 'RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  177. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  178. fflush($conf);fclose($conf);
  179. }
  180. function BuildRedirectConfig($conf){
  181. $this->Redirect=[];
  182. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14}|.+)\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  183. foreach($ma as $m){
  184. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  185. $this->Redirect[]=$redirect;
  186. }
  187. }
  188. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  189. foreach($ma as $m){
  190. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  191. $this->Redirect[]=$redirect;
  192. }
  193. }
  194. }
  195. function WriteTokens(){
  196. $tf = fopen('la_tokens.php','w');
  197. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  198. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  199. foreach($this->LoginTokens as $t){
  200. fwrite($tf,'- '.$t.PHP_EOL);
  201. }
  202. }
  203. fflush($tf);fclose($tf);
  204. }
  205. function WriteConfig(){
  206. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  207. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  208. if(!isset($this->Admin)) $this->Admin = 'admin';
  209. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  210. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  211. $conf = fopen('la_config.php','w');
  212. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  213. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  214. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  215. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  216. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  217. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  218. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  219. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  220. fwrite($conf,'- SpecialSidebar = '.$this->SpecialSidebar.PHP_EOL);
  221. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  222. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  223. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  224. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  225. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  226. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  227. fwrite($conf,'- HereHost = '.$this->HereHost.PHP_EOL);
  228. fwrite($conf,'- HereTitle = '.$this->HereTitle.PHP_EOL);
  229. fwrite($conf,'- HereShortTitle = '.$this->HereShortTitle.PHP_EOL);
  230. fwrite($conf,'- HereAlbum = '.$this->HereAlbum.PHP_EOL);
  231. fwrite($conf,'- HereNavigation = '.$this->HereNavigation.PHP_EOL);
  232. fwrite($conf,'- HereFooter = '.$this->HereFooter.PHP_EOL);
  233. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  234. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  235. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  236. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  237. fwrite($conf,'- ExpAlbum = '.$this->ExpAlbum.PHP_EOL);
  238. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  239. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  240. fwrite($conf,'- MastodonToken = '.$this->MastodonToken.PHP_EOL);
  241. fwrite($conf,'- MastodonURL = '.$this->MastodonURL.PHP_EOL);
  242. fwrite($conf,'- MastodonPreferredLang = '.$this->MastodonPreferredLang.PHP_EOL);
  243. fwrite($conf,'- HostURL = '.$this->HostURL.PHP_EOL);
  244. fwrite($conf,'- APubID = '.$this->APubID.PHP_EOL);
  245. fwrite($conf,'- GalleryStep = '.$this->GalleryStep.PHP_EOL);
  246. fflush($conf);fclose($conf);
  247. $conf = fopen('la_redirect.md','w');
  248. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  249. $this->WriteHTACCESS();
  250. $this->WriteTokens();
  251. }
  252. function Install(){
  253. if(!file_exists('la_config.php')){
  254. $this->WriteConfig();
  255. }
  256. if(!is_dir('posts')) mkdir('posts');
  257. if(!is_dir('images')) mkdir('images');
  258. if(!is_dir('images/thumb')) mkdir('images/thumb');
  259. if(!is_dir('styles')) mkdir('styles');
  260. if(!is_dir('archive')) mkdir('archive');
  261. $this->WriteStyles();
  262. $this->WriteHTACCESS();
  263. }
  264. function ReadFromExistingConfig(){
  265. $f=null;
  266. if(file_exists('la_config.php')) $f='la_config.php';
  267. else if(file_exists('la_config.md')) $f='la_config.md';
  268. if(!isset($f)) return;
  269. $c = file_get_contents($f);
  270. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  271. $str = $m[1];
  272. $this->$str = $m[2];
  273. }
  274. $this->CommentEnabled = $this->CommentEnabled=="True";
  275. if(!isset($this->GalleryStep)) $this->GalleryStep=20;
  276. }
  277. function ReadConfig(){
  278. $this->ReadFromExistingConfig();
  279. if(file_exists('la_redirect.md')){
  280. $c = file_get_contents('la_redirect.md');
  281. $this->BuildRedirectConfig($c);
  282. }
  283. if(!file_exists('la_config.php')){
  284. $this->Install();
  285. }
  286. $this->Translations=[];
  287. if(file_exists("translations.md")){
  288. $c = file_get_contents('translations.md');
  289. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  290. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  291. $this->Translations[] = $entry;
  292. }
  293. }
  294. if(file_exists("custom_translations.md")){
  295. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  296. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  297. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  298. $this->Translations[] = $entry;
  299. }
  300. }
  301. $this->LoginTokens=[];
  302. if(file_exists('la_tokens.php')){
  303. $c = file_get_contents('la_tokens.php');
  304. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  305. $this->LoginTokens[] = $m[1];
  306. }
  307. }
  308. }
  309. function MastodonPostStatus($status){ return $this->MastodonCall('/api/v1/statuses', 'POST', $status); }
  310. function MastodonPostMedia($media){ return $this->MastodonCall('/api/v1/media', 'POST', $media); }
  311. function MastodonCall($endpoint, $method, $data){
  312. $headers = [
  313. 'Authorization: Bearer '.$this->MastodonToken,
  314. 'Content-Type: multipart/form-data',
  315. ];
  316. $ch = curl_init();
  317. curl_setopt($ch, CURLOPT_URL, $this->MastodonURL.$endpoint);
  318. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  319. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  320. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  321. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  322. $reply = curl_exec($ch);
  323. if (!$reply) {
  324. return json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch_status), 'curl_error' => curl_error(ch_status)]);
  325. }
  326. curl_close($ch);
  327. return json_decode($reply, true);
  328. }
  329. function MastodonSendPost(&$post, &$errmsg=NULL){
  330. if(isset($post['mark_value']) && $post['mark_value']==7){ return NULL; }
  331. $this->LanguageAppendix = 'zh';
  332. if(in_array($this->MastodonPreferredLang,['en','zh'])){ $this->LanguageAppendix = $this->MastodonPreferredLang; }
  333. $this->ConvertPost($post);
  334. $media_ids = NULL;
  335. $mastodon_post_url = NULL;
  336. $imcount = 0;
  337. if(isset($post['original_images']) && isset($post['original_images'][0])) foreach($post['original_images'] as $im){
  338. $curl_file = curl_file_create($im, mime_content_type($im), basename($im));
  339. $body = ['file' => $curl_file,]; $response = $this->MastodonPostMedia($body);
  340. if(isset($response['id'])){ if(!isset($media_ids)){$media_ids=[];} $media_ids[]=$response['id']; }
  341. else{ if(isset($response['error'])) $errmsg.=$response['error']."<br /><br />"; }
  342. $imcount++; if($imcount>=4){ break; }
  343. }
  344. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$post['html']));
  345. if(isset($this->HostURL) && $this->HostURL!=""){
  346. $text.=("\n\n".$this->T('来自').' '.$this->HostURL.'?post='.$post['id']);
  347. }
  348. $vis = (isset($post['mark_value']) && $post['mark_value']==6)?"private":"public";
  349. $status_data = [ 'status' => $text, 'visibility' => $vis, 'language' => $this->LanguageAppendix, ];
  350. if(isset($post['prev']) && ($pp=&$this->GetPost($post['prev']))!=$this->NULL_POST){
  351. if(isset($pp['mastodon_url'])){ $status_data['in_reply_to_id'] = basename($pp['mastodon_url']);
  352. }
  353. }
  354. if(isset($media_ids[0])){ $status_data['media_ids']=$media_ids; }
  355. $status_data = preg_replace('/(media_ids%5B)[0-9]+(%5D)/','$1$2', http_build_query($status_data));
  356. $status_response = $this->MastodonPostStatus($status_data);
  357. if(isset($status_response['url']) && $status_response['url']){
  358. $mastodon_post_url = $status_response['url'];
  359. $post['mastodon_url'] = $mastodon_post_url;
  360. $this->NeedWritePosts = 1;
  361. }
  362. if(isset($status_response['error'])) { $errmsg .= $status_response['error']; }
  363. return $mastodon_post_url;
  364. }
  365. function __construct() {
  366. $this->ReadConfig();
  367. $this->PDE = new ParsedownExtra();
  368. $this->PDE->SetInterlinkPath('/');
  369. $this->Posts = [];
  370. $this->Threads = [];
  371. $this->VisitedHere = [];
  372. $this->NULL_IMAGE_DUMMY = [];
  373. $this->NULL_IMAGE_DUMMY['name']=$this->NULL_IMAGE_DUMMY['file']=$this->NULL_IMAGE_DUMMY['thumb']="";
  374. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  375. $this->PostsPerPage = 40;
  376. $this->CommentsPerPage = 100;
  377. $this->HotPostCount = 15;
  378. $this->TIME_STRING = date('YmdHis');
  379. $this->WayBack = NULL;
  380. $this->YearBegin = $this->YearEnd = 2000;
  381. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  382. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  383. $this->UsePosts = &$this->Posts;
  384. }
  385. function DoLogout(){
  386. $this->LoggedIn = false;
  387. unset($_SESSION['user_id']);
  388. $this->RecordToken(true);
  389. }
  390. function RecordToken($unset_current=false){
  391. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  392. $t = $_COOKIE['la_token'];
  393. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  394. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  395. $this->WriteTokens();
  396. return null;
  397. }else{
  398. $t = uniqid('la_',true);
  399. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  400. $this->LoginTokens[] = $t;
  401. $this->WriteTokens();
  402. return $t;
  403. }
  404. }
  405. function LoginThroughToken(){
  406. if(!isset($_COOKIE['la_token'])) return false;
  407. $t = $_COOKIE['la_token'];
  408. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  409. $_SESSION['user_id']=$this->Admin;
  410. $this->LoggedIn = true;
  411. setcookie('la_token',$t,time()+3600*24*7);
  412. return true;
  413. }
  414. return false;
  415. }
  416. function DoLogin(){
  417. session_start();
  418. $redirect=false;
  419. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  420. else if(!isset($_SESSION['user_id'])){
  421. if(isset($_POST['login_button'])){
  422. $id = trim($_POST['login_id']);
  423. $pwd = trim($_POST['login_password']);
  424. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  425. $_SESSION['user_id']=$id;
  426. $this->RecordToken(false);
  427. }
  428. $redirect = true;
  429. }else if($this->LoginThroughToken()){
  430. // nothing;
  431. }
  432. }else{
  433. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  434. else{ $this->DoLogout();}
  435. }
  436. if($redirect){
  437. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  438. .(isset($_GET['settings'])?"?settings=true":""));
  439. }
  440. }
  441. function SetHereMainImage($im_this){
  442. if(isset($im_this) && isset($im_this['parent'])){ $this->HereMainImage = &$this->FindImage($im_this['parent'],true);}
  443. }
  444. function RecordVisitedHere($image_or_post_name, $image_title){
  445. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  446. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  447. if(!(isset($_SESSION[$visited_here][0]) && in_array($image_or_post_name,$_SESSION[$visited_here]))){
  448. $_SESSION[$visited_here][] = $image_or_post_name;
  449. }
  450. if(isset($image_title)){ $this->HereDisplayTitle=$image_title; }
  451. $this->HereNumber = array_search($image_or_post_name,$_SESSION[$visited_here])+1;
  452. $_SESSION['here_number'] = $this->HereNumber;
  453. $this->VisitedHere = $_SESSION[$visited_here];
  454. }
  455. function HereLinkFromNumber($number){
  456. $number -= 1; if($number<0){ $number=0; }
  457. if($number>=sizeof($this->VisitedHere)){ $number = sizeof($this->VisitedHere)-1; }
  458. if(preg_match('/(jpg|jpeg|png|gif)/u',$this->VisitedHere[$number])){ return "?here=images/".$this->VisitedHere[$number]; }
  459. else{ return "?post=".$this->VisitedHere[$number]; }
  460. }
  461. function WriteStyles(){
  462. $this->style="
  463. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  464. body{background-color:%white%;color:%black%;}
  465. sup,sub{line-height:0;} .lpctrl{display:none;}
  466. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  467. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  468. b,strong,th{font-weight:bold;}
  469. select{font-size:inherit;}
  470. .page,.page_gallery{padding:1em;padding-top:0;padding-bottom:0;}
  471. .hidden_on_desktop,.hidden_on_wide{display:none;}
  472. .hidden_on_desktop_force{display:none !important;}
  473. ::file-selector-button{background:none;border:none;}
  474. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  475. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  476. .button:disabled{background-color:%gray%;pointer-events:none;}
  477. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;box-shadow: 0.5em 0px %white%;}
  478. 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;}
  479. header>div{overflow:auto;white-space:nowrap;}
  480. .header_nav{display:inline;}
  481. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  482. header a:hover,.button:hover{color:%gray% !important;}
  483. .exp_h_f{padding-top:0.3em !important;padding-bottom:0.3em !important;line-height:1.5em !important;height:2.1em !important;}
  484. .exp_f{text-align:center;}
  485. .toc_button{position:absolute;top:0.5em;right:0;text-shadow: 0px 0px 10px %white%;background-color:%white%88;}
  486. .footer{background-color:%white%;z-index:10;position:relative;}
  487. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  488. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  489. .gray,.gray a{color:%gray%;}
  490. hr{border:1px solid %gray%aa;}
  491. header ul,.small_footer ul,.small_footer span,header li,.small_footer li{display:inline-block;}
  492. header li::before,.small_footer li::before{content:' - '}
  493. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  494. .main{position:relative;word-spacing:-1em;}
  495. .main *{word-spacing:initial;}
  496. pre{overflow:auto;max-width:100%;display:block;}code{font-size:0.83em;}
  497. ul{display:block;}
  498. li{display:block;}
  499. .clean_table{border:none;font-size:1em !important;}.clean_table thead{box-shadow:none;}.clean_table td{vertical-align:top;}
  500. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  501. table input{border:none!important;}
  502. table img{max-width:10rem !important;}
  503. td{padding-left:0.1em;padding-right:0.1em;}
  504. td:first-child{padding-left:0;}
  505. td:last-child{padding-right:0;}
  506. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  507. thead{box-shadow:inset 0 -1px 0 0px %black%;}
  508. .post table{font-size:0.85em;}
  509. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  510. .interesting_tbody td{display:contents;}
  511. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  512. .interesting_tbody td>*{display:table-cell;}
  513. .interesting_tbody td>.wscroll{display:none !important;}
  514. .interesting_tbody .post_access{padding-top:0;}
  515. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  516. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  517. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  518. .interesting_tbody td>.imd>a{display:flex;}
  519. .interesting_tbody img{object-fit:cover;width:100%;}
  520. .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);}
  521. .interesting_tbody .p_thumb{height:1em;}
  522. .interesting_tbody .p_thumb img,.interesting_tbody .p_thumb video{max-height:10rem !important;max-width:20rem !important;}
  523. tr:hover .post_menu_button{opacity:1;}
  524. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  525. .align_right{text-align:right;}
  526. .left{display:inline-block;vertical-align:top;width:25%;padding-right:1.5em;padding-bottom:4rem;position:sticky;top:2em;
  527. overflow:auto;max-height:calc(100vh - 2.6em);}
  528. .center{display:inline-block;vertical-align:top;width:50%;overflow:visible;padding-bottom:4rem;}
  529. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  530. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  531. .center_wide .p_thumb{height:12rem;margin:0;}
  532. .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%;}
  533. .active_post .linked_posts{background-color:%highlight_slice%;}
  534. input:checked~.linked_posts{display:none;}
  535. .bkg_recent>.post,.bkg_section{background:%post_white%;box-shadow:0em 0em 0.4em %shadow%;margin-bottom:0.5em;}
  536. .bkg_recent>.post>.post_width :last-child{margin-bottom:0;}
  537. .sticky_title{position:sticky;top:calc(1.6rem + 2px);z-index:1;background-color:%white%;pointer-events:none;}
  538. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  539. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  540. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  541. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  542. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  543. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  544. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  545. .post{position:relative;scroll-margin:3.5em;}
  546. .active_post{background-color:%highlight_white%;}.active_post .post_access{background-color:%highlight_slice%;}
  547. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;}
  548. .post_width li,.footer_additional li,.footer_additional li,.post_dummy li
  549. {display:list-item;margin-left:1em;list-style:disc;}
  550. .post_width li li,.footer_additional li li,.footer_additional li li,.post_dummy li li
  551. {list-style:circle;}
  552. ol li{list-style:unset !important;}
  553. .post_width > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  554. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  555. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  556. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  557. .gallery_left .selected{list-style:'→';}
  558. .bkg_section .post_width{padding-top:0;padding-bottom:0;}
  559. .bkg_section .print_title+.post .post_width{padding-top:0.5em;}
  560. .bkg_section .post:not(.print_title):first-of-type .post_width{padding-top:0.5em;}
  561. .bkg_section .restart+.post .post_width{padding-top:0.5em;}
  562. .post_width{position:relative;width:calc(100% - 1.5rem);overflow:auto;padding:0.5rem;}
  563. .ref_count{position:absolute;width:100%;bottom:0.5em;font-weight:bold;color:%gray%;}
  564. .active_post .ref_count{color:%black%;}
  565. .ref_count::after{content: \" \";display:block;width:10em;background:linear-gradient(to right,#0000,%gray%);height:2px;
  566. bottom:-0.5em;position:absolute;right:0;}
  567. //.ref_count::after{content: \" \";display:block;width:0.1em;background-color:%gray%;height:100%;margin-left:0.7em;}
  568. //.lpctrl:checked~.post_width{box-shadow: 1px 1px 1px 1px inset black;}
  569. .opt_compact .post_width,.ref_compact .post_width{padding-top:0;padding-bottom:0;}
  570. .p_thumb .post_menu_button{right:0.3rem;}
  571. .post_menu_button{position:absolute;display:none;top:0.3em;right:1.8rem;width:1.5rem;box-shadow:0px 0px 3px %shadow%;
  572. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;background-color:%post_white%aa;}
  573. .pointer{cursor:pointer;}
  574. .post:hover .post_menu_button{display:block;}
  575. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%grayslice%;
  576. padding:0.3em;right:1.8rem;text-align:right;border-radius:0.3em;font-size:1rem;
  577. box-shadow:0px 0px 10px %shadow%;}
  578. .pop_menu li{list-style:none;margin-left:0;}
  579. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  580. .toc{left:60%;width:40%;top:0;position:absolute;}
  581. .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;}
  582. .post_access:hover{filter:contrast(75%);}.post label{pointer-events:none;}.active_post label{pointer-events:all;}
  583. .paa{width:1.4rem;min-width:1.4rem;}
  584. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;background-color:%post_white%;right:unset;left:-2em;}
  585. .post_preview{overflow:hidden;margin-bottom:0.4em;background-color:%white%aa;box-shadow: 0px 0px 0.2em %shadow%;}
  586. .post_preview:hover{filter:contrast(90%);}
  587. .active_post .post_preview:hover{filter:contrast(90%);}
  588. .post .post_ref{margin:0;padding-left:1.5rem;}
  589. .post_ref_main{display:inline-block;vertical-align:top;max-height:6em;overflow:hidden;margin:0.4em;}
  590. .post_ref_images{overflow:hidden;margin:0.4em;margin-top:0;}
  591. .post_ref_hint{text-align:right;}
  592. .page_selector{padding-top:2rem;text-align:center;}
  593. .smaller{font-size:0.85em;} .bigger{font-size:1.3em;} .block{display:block;}
  594. .restart{text-align:right;padding:0.5rem;background-color:%grayslice%;}
  595. .opt_compact{margin-left:2rem;}.ref_compact{margin-left:1.5rem;}
  596. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  597. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  598. .spacer{height:0.5em;}
  599. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  600. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  601. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  602. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  603. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  604. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  605. .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;}
  606. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  607. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  608. .toc_entry_1{font-size:1.1em;}
  609. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  610. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  611. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  612. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  613. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  614. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  615. .deleted_post{color:%gray%;text-decoration:line-through;}
  616. #file_list{margin-top:0.5em;}
  617. .file_thumb img,.file_thumb video{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  618. .file_thumb video{border:2px dashed %black%;}f
  619. #file_list li{margin-bottom:0.3em;}
  620. .ref_thumb{white-space:nowrap;overflow:hidden;}
  621. .ref_thumb .file_thumb{width:2em;height:2em;margin:0;}
  622. .side_thumb li{margin:0.4em;display:inline-block;}
  623. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  624. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  625. .p_thumb{display:flex;flex-grow:100;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  626. .p_thumb_narrow{width:1rem;flex-grow:1;opacity:0.2;}
  627. .p_thumb img,.p_thumb video{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  628. .p_thumb:hover .post_menu_button{display:block;}
  629. .p_thumb_selected{color:%black% !important;}
  630. .p_thumb_selected{display:block;}
  631. .post .p_thumb img,.post .p_thumb video{max-height:6rem;}
  632. .p_thumb video{border-bottom:0.4em dashed %black%;border-top:0.4em dashed %black%;}
  633. .p_thumb_end{flex-grow:10000 !important;box-shadow:none;align-items:center;padding:2em !important;}
  634. .p_thumb_end:hover, .p_thumb_end a:hover{background-color:%gray%40;cursor:pointer;}
  635. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  636. .big_image_box *{pointer-events:auto;}
  637. .big_image_box img,.big_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  638. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  639. .here_image_box img,.here_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  640. .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;}
  641. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  642. .big_side_box a:hover{color:%gray%;}
  643. .big_side_box *{pointer-events:auto;}
  644. .big_side_box .post_preview{border:1px solid %gray%;background-color:unset;border-radius:0.3em;}
  645. .image_nav{pointer-events:none;}
  646. #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;
  647. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  648. img,video{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  649. .post img,.post video{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  650. .post > a > img,.post > a > video{display:block;margin:0.3em auto;}
  651. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  652. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  653. .center_exp .post .original_img{display:block;}
  654. .original_img img,.original_img video{max-height:90vh;max-width:100%;}
  655. .p_row .original_img{margin-bottom:0;}
  656. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  657. .imbtn{display:block;contain:content;padding:0.25em;margin-bottom:0.5em;text-decoration:none;text-shadow:0px 0px 5px %white%;}
  658. .imbtn img{display:block;object-fit:cover;position:absolute;top:0;left:0;bottom:0;right:0;margin:auto;z-index:-1;
  659. min-width:100% !important;min-height:100% !important;filter:opacity(40%);}
  660. .imbtn:hover img{filter:opacity(20%) blur(0.1em);} .imbtn:hover{color:%black% !important;}
  661. header .imbtn{display:inherit;border:none;padding:0em;height:unset;height:unset;margin:0em;contain:unset;}
  662. header .imbtn:hover{border:none;color:%gray% !important;} header .imbtn img{display:none;}
  663. .b ul{font-size:1.4em;}
  664. no_pop{cursor:unset;}
  665. p{min-height:0.8em;}
  666. .bold,.bold *{font-weight:bold;}
  667. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  668. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;box-shadow: 0.5em 0px %white%;}
  669. .small_footer>div{overflow:auto;white-space:nowrap;}
  670. .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;}
  671. .top_post_hint{margin-left:0.5em;font-weight:bold;}
  672. .white{color:%white%;}
  673. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  674. .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;
  675. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  676. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.4));
  677. background-repeat:no-repeat;background-size:0% 100%;}
  678. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  679. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  680. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  681. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  682. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  683. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  684. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  685. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  686. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  687. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  688. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  689. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  690. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  691. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  692. .special_paypal_inner{color:#169bd7;}
  693. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  694. animation:anim_loading 1s linear infinite;}
  695. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  696. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  697. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  698. .product_thumb img,{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  699. .product_ref p{margin-bottom:0.2em;text-align:left;}
  700. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  701. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  702. .page_break{page-break-after:always;}
  703. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  704. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  705. .print_title{display:none;}.show_on_print{display:none;}.inline_print{display:none;}
  706. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  707. .comment tbody tr:hover{box-shadow:none;}
  708. .comment table{border:none;}
  709. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  710. .comment ul{padding-left:1em;}
  711. .comment ul li *{margin-bottom:0.5em;}
  712. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  713. .history li li{list-style:circle;}
  714. .history ul{padding-left:1em;}
  715. .history a{text-decoration:underline;}
  716. .history .list{overflow:auto;white-space:nowrap;}
  717. .diff_table{table-layout:fixed;}
  718. .diff_table thead{font-size:0.9em;text-align:center;}
  719. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  720. .diff_table td{vertical-align:top;}
  721. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  722. .wayback_close{float:right;}
  723. .wayback_expand{display:inline;}
  724. .post_selecting .post *{pointer-events:none;}
  725. .post_selected{background-color:%graybkg%;}
  726. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  727. .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%;}
  728. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  729. .wayback_link{display:inline;}
  730. .imd{object-fit:cover;width:100%;}
  731. .center_exp .imd{width:60%;}
  732. #here_buttons{display:contents;}
  733. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  734. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  735. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  736. .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;}
  737. @media screen and (max-width:1000px) and (min-width:666px){
  738. .left{width:35%;}
  739. .center,.center_wide{width:65%;}
  740. .center_wide .p_thumb{height:8rem;}
  741. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  742. .hidden_on_wide{display:unset;}
  743. .pop_right{width:30%;}
  744. .pop_right_big{width:40%;}
  745. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  746. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  747. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  748. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  749. .big_side_box{width:35%;}
  750. .big_image_box{width:65%;}
  751. .inquiry_buttons{right:35%;}
  752. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  753. .post_dummy > *{width:80%;max-width:55rem;}
  754. .center_exp .imd{width:80%;}
  755. .here_btn{width:1.5em;height:1.5em;}
  756. }
  757. @media screen and (max-width:666px){
  758. html{font-size:16px;}
  759. #titlectrl:checked ~ header .mobile_fold{display:block !important;}
  760. #titlectrl:checked ~ .main .mobile_fold{display:block !important;}
  761. .mobile_fold{display:none !important;}
  762. .hidden_m{display:none !important;}
  763. .block_m{display:block !important;}
  764. .hidden_on_desktop{display:unset;}
  765. .hidden_on_wide{display:unset;}
  766. header{position:unset;}
  767. header ul{display:block;}
  768. header li{display:block;}
  769. header li::before{content:''}
  770. header::before{box-shadow:none;display:none;}
  771. .small_footer::before{box-shadow:none;display:none;}
  772. .left{position:relative;width:100%;top:unset;height:unset;max-height:unset;padding-right:0;display:block;}
  773. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  774. .center_wide .p_thumb{height:6rem;}
  775. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  776. .pop_right{height:30%;}
  777. .pop_right_big{height:70%;}
  778. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  779. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  780. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  781. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  782. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  783. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  784. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  785. .side_box_mobile_inner:hover{background-size:100% 100%;}
  786. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  787. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  788. .p_thumb{height:3rem;}
  789. .center .post{padding-right:0rem;padding-left:0rem;}
  790. .post .p_thumb img,.post .p_thumb video{max-height:3rem;}
  791. .page,.page_gallery{padding:0.2em;padding-top:0;}
  792. header{padding-top:0.3em;}
  793. .toc_button{top:0.3em;}
  794. .small_footer{padding-bottom:0.3em;}
  795. .footer_additional{display:block;width:100%;}
  796. .album_hint{display:block;font-size:1rem;}
  797. .image_nav{position:absolute !important;}
  798. .image_nav_prev,.image_nav_next{width:25%;}
  799. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  800. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  801. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  802. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  803. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  804. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  805. .opt_compact,.ref_compact{line-break:anywhere;}
  806. .table_top{left:unset;width:100%;overflow:auto;}
  807. table img{max-width:30vw !important;}
  808. .product_ref{width:100%;display:block;}
  809. .post_dummy > *{width:100%;max-width:25rem;}
  810. .sticky_title{top:0;}
  811. .small_footer{position:relative;}
  812. #upload_selector{width:100%;}
  813. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  814. .wayback_expand{display:block;text-align:center;}
  815. .wayback_link{display:block;}
  816. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  817. .center_exp .post{overflow:auto;}
  818. .center_exp .imd{width:100%;}
  819. .here_btn{width:1.2em;height:1.2em;}
  820. .exp_h_f{height:unset !important;}
  821. .exp_f{margin-bottom:1em;}
  822. .linked_posts{padding-left:1em;}
  823. }
  824. @media print{
  825. .small_footer .hidden_on_print{display:none;}
  826. header b,.small_footer b{font-weight:normal;}
  827. header{display:table-header-group;box-shadow:none;} .main{display:table-row-group;} .small_footer{text-align:right;}
  828. header::before{box-shadow:none;display:none;} header::after{display:block;height:1em;content:' ';}
  829. .small_footer::before{box-shadow:none;display:block;height:1em;position:relative;}
  830. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  831. .bkg_section,.bkg_recent>.post,.active_post{background:none !important;box-shadow:none;}
  832. .post *,.post_dummy *{margin-bottom:0em;}
  833. .p_row,.post table,.post_width>img,.post_ref>img,.post_ref>.original_img,
  834. .post_width>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  835. pre{white-space:pre-wrap;line-break:anywhere;}
  836. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  837. table img{margin:0 !important;}
  838. .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;}
  839. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  840. table{border-bottom:2px solid black;border-top:2px solid black;}
  841. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  842. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  843. .linked_posts{display:none;}
  844. .post_width{overflow:clip;left:0;width:100%;padding-left:0em;padding-right:0em;}
  845. .post h1{margin-top:0.5rem;}
  846. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  847. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h3{margin:0 !important;}
  848. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  849. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  850. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  851. .left{display:none;}
  852. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  853. hr{border:1px solid black;}
  854. .post_box_top{display:none;}
  855. .post_access{display:none;}
  856. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;background:unset;}
  857. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  858. .hidden_on_print{display:none;}
  859. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  860. .opt_compact{margin-left:0;left:1.5em;}
  861. .post .post_ref{padding-left:2rem;}
  862. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  863. .print_title:first-of-type{margin-top:1em;}
  864. .print_title+.post h1:first-of-type{display:none;}
  865. .bkg_section .print_title+.post .post_width{padding-top:0;}
  866. .bkg_section .post:not(.print_title):first-of-type .post_width{padding-top:0;}
  867. .bkg_section .restart+.post .post_width{padding-top:0;}
  868. .restart{background-color:unset;padding:unset;}
  869. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  870. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  871. .header_nav{display:none;}
  872. .show_on_print{display:block;}.inline_print{display:inline;}
  873. blockquote{border-left:2px solid black;}
  874. .footer_additional{display:none;}
  875. .small_footer{margin-top:1rem;box-shadow:none;}
  876. .page{display:table;width:100%;}
  877. .page_selector{display:none;}
  878. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  879. .post .p_thumb img,.post .p_thumb video{max-height:4rem;}
  880. .sticky_title{box-shadow:none;}
  881. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  882. .center_wide .p_row{display:block;}
  883. .interesting_tbody{background:none;}
  884. .interesting_tbody img{display:none !important;}
  885. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  886. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  887. }
  888. ";
  889. $this->style=preg_replace('/%highlight_white%/','#5b3607',$this->style);
  890. $this->style=preg_replace('/%highlight_slice%/','#734307',$this->style);
  891. $this->style=preg_replace('/%grayslice%/','#1a1002',$this->style);
  892. $this->style=preg_replace('/%post_white%/','#2d2110',$this->style);
  893. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  894. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  895. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  896. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  897. $this->style=preg_replace('/%shadow%/','#000000cc',$this->style);
  898. $f = fopen('styles/main.css','w');
  899. fwrite($f,$this->style);
  900. fclose($f);
  901. }
  902. function GiveSafeEMail(){
  903. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  904. }
  905. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  906. if(isset($this->Images[0])) foreach($this->Images as &$im){
  907. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  908. else { if($im['name']==$name) return $im; }
  909. }
  910. return $this->NULL_IMAGE;
  911. }
  912. function &GiveImageInHere($rand=false){
  913. $this->ReadImages(); $this->DetectPageType();
  914. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  915. if(!isset($album) || !$album){
  916. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  917. $imlist=[]; $imlist_fallback=[];
  918. if(isset($this->Images[0])){
  919. foreach($this->Images as &$im){
  920. if(isset($im['galleries'][0]) && in_array($album,$im['galleries']) && $this->CanShowImage($im)){
  921. if(!$rand) return $im; else {
  922. $imlist_fallback[] = $im;
  923. if(!in_array($im['name'],$this->VisitedHere)) $imlist[] = $im;
  924. }
  925. }
  926. }
  927. }
  928. if(!$rand || !isset($imlist_fallback[0])) return $this->NULL_IMAGE;
  929. if(sizeof($imlist)){
  930. $r = random_int(0, sizeof($imlist)-1);
  931. return $imlist[$r];
  932. }else{
  933. $r = random_int(0, sizeof($imlist_fallback)-1);
  934. return $imlist_fallback[$r];
  935. }
  936. }
  937. function ImageTitle($im){
  938. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  939. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  940. return $imtitle;
  941. }
  942. function ImageHasHere(&$im, $here_name){
  943. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  944. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  945. }
  946. function ReadImages($clear_non_exist = false){
  947. $path = 'images/list.md';
  948. if($this->DoneReadImages){ return; }
  949. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  950. $c = file_get_contents($path);
  951. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  952. $g=[]; $g['name']=$m[1];//$g['count']=0;
  953. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  954. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  955. $this->Galleries[] = $g;
  956. }
  957. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  958. $name = trim($m[1]);
  959. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  960. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  961. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  962. $item['refs']=[];
  963. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  964. }
  965. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  966. $item['galleries']=[];
  967. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  968. }
  969. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  970. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  971. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  972. if(preg_match('/ALIGN\s+([^;]*);/u',$m[2],$align)){ $item['align']=$align[1]; }
  973. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  974. $item['here']=[];
  975. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  976. }
  977. if(preg_match('/\.mp4/u',$item['name'])){
  978. $item['video']='video/mp4';
  979. }
  980. $this->Images[] = $item;
  981. }
  982. $files = array_merge([],glob('images/*.jpg'));
  983. $files = array_merge($files,glob('images/*.jpeg'));
  984. $files = array_merge($files,glob('images/*.png'));
  985. $files = array_merge($files,glob('images/*.gif'));
  986. $files = array_merge($files,glob('images/*.mp4'));
  987. if(isset($files[0]))foreach($files as $file) {
  988. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png|mp4)/u', $file, $m)) {
  989. $name = trim($m[0]);
  990. if(!$this->FindImage($name)){
  991. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  992. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  993. $this->Images[] = $item;
  994. }
  995. }
  996. }
  997. if($clear_non_exist){
  998. if(isset($this->Images[0]) && isset($files[0])){
  999. foreach($this->Images as &$im){
  1000. if(!in_array($im['file'],$files)){
  1001. $im['deleted'] = 1;
  1002. }
  1003. }
  1004. }
  1005. }
  1006. function cmpf($a, $b){
  1007. if ($a['name'] == $b['name']) return 0;
  1008. return (($a['name'] > $b['name']) ? 1 : -1);
  1009. }
  1010. function cmpaf($a, $b){
  1011. if ($a['name'] == $b['name']) return 0;
  1012. return ($a['name'] > $b['name']) ? -1 : 1;
  1013. }
  1014. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  1015. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  1016. $this->DoneReadImages = 1;
  1017. }
  1018. function WriteImages(){
  1019. if(isset($this->WayBack)) return;
  1020. $path = 'images/list.md';
  1021. $f = fopen($path,'w');
  1022. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  1023. if(isset($g['deleted'])) continue;
  1024. fwrite($f,'GALLERY '.$g['name']);
  1025. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  1026. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  1027. fwrite($f, PHP_EOL);
  1028. }
  1029. if(isset($this->Images[0]))foreach($this->Images as &$im){
  1030. if(isset($im['deleted'])) continue;
  1031. fwrite($f, "- ".$im['name'].'; ');
  1032. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  1033. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  1034. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  1035. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  1036. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  1037. if(isset($im['align']) && $im['align']!='' && $im['align']!='middle'){ fwrite($f, 'ALIGN '.$im['align']."; "); }
  1038. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  1039. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  1040. }
  1041. fwrite($f, PHP_EOL);
  1042. }
  1043. fflush($f);
  1044. fclose($f);
  1045. }
  1046. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL, $align=NULL){
  1047. if(!($im = &$this->FindImage($name))) return;
  1048. if(isset($link_gallery)){
  1049. if($do_remove){
  1050. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  1051. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  1052. $im['galleries'] = array_merge($im['galleries']);
  1053. }else{
  1054. if(!isset($im['galleries'])) $im['galleries']=[];
  1055. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  1056. $im['galleries'][]=$link_gallery;
  1057. }
  1058. }
  1059. if(isset($product_link)){
  1060. if($product_link!=''){$im['product']=$product_link;}
  1061. else{unset($im['product']);}
  1062. }
  1063. if(isset($rename) && $rename!=$im['name']){
  1064. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1065. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1066. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1067. $im['name'] = $rename.'.'.$ext;
  1068. }
  1069. if(isset($parent) && $parent!=$im['parent']){
  1070. if($parent==''){ unset($im['parent']); }
  1071. else{ $im['parent'] = $parent; }
  1072. }
  1073. if(isset($align) && in_array($align,['top','middle','bottom'])){
  1074. if($align=='middle'){ unset($im['align']); }
  1075. else{ $im['align']=$align; }
  1076. }
  1077. $this->NeedWriteImages = 1;
  1078. }
  1079. function RegenerateThumbnails(){
  1080. $glob = glob('images/*.jpg');
  1081. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1082. foreach($glob as $file) {
  1083. $thumb_destination = 'images/thumb/'.basename($file);
  1084. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1085. $width=$geo['width']; $height=$geo['height'];
  1086. $lim=400;
  1087. $scale = $lim / min($width,$height);
  1088. if($scale<1){
  1089. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1090. }
  1091. $img->setImageFormat('jpeg');
  1092. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1093. $img->setImageCompressionQuality(90);
  1094. $img->writeImage($thumb_destination);
  1095. }
  1096. }
  1097. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max, $ext) {
  1098. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1099. $width=$geo['width']; $height=$geo['height'];
  1100. $lim=400;
  1101. $scale = $lim / min($width,$height);
  1102. if($scale<1){
  1103. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1104. }
  1105. $img->setImageFormat('jpeg');
  1106. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1107. $img->setImageCompressionQuality($quality);
  1108. $img->writeImage($thumb_destination);
  1109. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1110. if($scale<1){
  1111. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1112. }
  1113. if($ext!='jpg'){
  1114. $img2->setImageFormat('jpeg');
  1115. $img2->setImageCompressionQuality($quality);
  1116. $img2->writeImage($destination);
  1117. }else{
  1118. rename($source,$destination);
  1119. }
  1120. }
  1121. function DoUpload(){
  1122. if(!isset($_FILES['upload_file_name'])) return 0;
  1123. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1124. if($_FILES['upload_file_name']['error']>0){
  1125. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1126. return -1;
  1127. }else{
  1128. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  1129. if(!in_array($ext,['jpg','jpeg','png','gif','mp4'])) return 0;
  1130. $fp = fopen('.la_lock',"w");
  1131. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1132. usleep(10000);
  1133. }
  1134. $num=date('YmdHis'); $replace=0;
  1135. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1136. $num = $mim[1]; $replace=1;
  1137. }
  1138. $base = 'images/'.$num;
  1139. $thumb = 'images/thumb/'.$num;
  1140. if($ext=='png') $ext='jpg';
  1141. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  1142. if(!$replace) while(file_exists($final_path)){
  1143. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  1144. }
  1145. if($ext!='gif' && $ext!='mp4'){
  1146. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1147. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1148. $compress?800:1920, $compress?1920:2560, $ext);
  1149. }else{
  1150. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1151. }
  1152. flock($fp, LOCK_UN);
  1153. fclose($fp);
  1154. $this->ReadImages(true);
  1155. $this->WriteImages();
  1156. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1157. if(isset($_POST['image_replace_button'])){
  1158. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1159. }
  1160. exit;
  1161. return 1;
  1162. }
  1163. return 0;
  1164. }
  1165. function &GetGallery($name){
  1166. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1167. if($g['name'] == $name) return $g;
  1168. }
  1169. return $this->NULL_GALLERY;
  1170. }
  1171. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  1172. $this->ReadImages();
  1173. $gallery = &$this->GetGallery($name);
  1174. if(!isset($gallery)){
  1175. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1176. $g = []; $g['name']=$new_name;
  1177. $this->Galleries[]=$g;
  1178. }else{
  1179. if(isset($new_name)) {
  1180. if(preg_match('/main|trash|\s/u',$new_name))return;
  1181. $gallery['name'] = $new_name;
  1182. foreach ($this->Images as &$im){
  1183. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1184. if($g == $name){ $g = $new_name; }
  1185. }
  1186. }
  1187. }
  1188. //if(isset($count)) $gallery['count'] = $count;
  1189. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1190. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1191. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1192. }
  1193. if($do_rw) { $this->NeedWriteImages = 1; }
  1194. }
  1195. function ClearData(){
  1196. $this->Posts = [];
  1197. $this->Threads = [];
  1198. $this->Images = [];
  1199. $this->Archive = [];
  1200. $this->ArchiveHandles = [];
  1201. }
  1202. function InsertArchivePost(&$post){
  1203. $a = NULL;
  1204. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1205. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1206. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1207. }
  1208. $a['list'][] = $post;
  1209. $this->Archive[] = $post;
  1210. }
  1211. function ReadArchiveFromFile($path){
  1212. if(!file_exists($path)){
  1213. return;
  1214. }
  1215. $c = file_get_contents($path);
  1216. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1217. foreach($matches as $m){
  1218. $post = [];
  1219. $post['id'] = $m[1];
  1220. $post['content'] = trim($m[3]);
  1221. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1222. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1223. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1224. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1225. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1226. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1227. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1228. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1229. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1230. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1231. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1232. if(preg_match('/HASTAG\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['hastag'] = $entries; } }
  1235. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1236. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1237. }
  1238. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\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['merged_thread'][0] = $entries; }
  1241. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1242. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1243. }
  1244. $this->InsertArchivePost($post);
  1245. }
  1246. }
  1247. }
  1248. function SortArchive(){
  1249. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1250. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1251. return (($a['id'] > $b['id']) ? 1 : -1);
  1252. };
  1253. if(isset($this->Archive[0])){
  1254. usort($this->Archive,$cmpap);
  1255. $year_begin = substr($this->Archive[0]['id'],0,4);
  1256. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1257. }
  1258. if(isset($this->ArchiveHandles[0])){
  1259. usort($this->ArchiveHandles,$cmpac);
  1260. foreach($this->ArchiveHandles as &$a){
  1261. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1262. $last_valid=NULL;
  1263. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1264. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1265. else{ $last_valid = $ver['content']; } }
  1266. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1267. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1268. }
  1269. }
  1270. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1271. $p['archive'] = &$a;
  1272. }
  1273. }
  1274. }
  1275. }
  1276. function ReadPostsFromFile($path){
  1277. if(!file_exists($path)){
  1278. $f = fopen($path,'w');
  1279. fclose($f);
  1280. }
  1281. $c = file_get_contents($path);
  1282. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1283. foreach($matches as $m){
  1284. $post = [];
  1285. $post['id'] = $m[1];
  1286. $post['real_content'] = trim($m[3]);
  1287. $post['content'] = &$post['real_content'];
  1288. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1289. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1290. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1291. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1292. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1293. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1294. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1295. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1296. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1297. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1298. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1299. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1300. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1301. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1302. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1303. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1304. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1305. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1306. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1307. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1308. if(preg_match('/HASTAG\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['hastag'] = $entries; } }
  1311. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1312. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1313. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1314. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1315. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1316. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1317. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1318. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1319. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1320. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1321. }
  1322. if(isset($post['mark_value']) && $post['mark_value']==5){
  1323. $post['product']=[];
  1324. }
  1325. /* marks add here */
  1326. $this->Posts[] = $post;
  1327. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1328. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1329. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1330. }
  1331. }
  1332. }
  1333. }
  1334. function SortPosts($wayback=false){
  1335. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1336. $sortlist = &$this->Posts;
  1337. if($wayback) $sortlist = &$this->WaybackPosts;
  1338. if(isset($sortlist[0])){
  1339. usort($sortlist,$cmpp);
  1340. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1341. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1342. }
  1343. }
  1344. function ReadPosts(){
  1345. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1346. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1347. (!is_dir('posts') || is_readable('posts') == false) ||
  1348. (!is_dir('archive') || is_readable('archive') == false) ||
  1349. (!is_dir('images') || is_readable('images') == false) ||
  1350. (!is_dir('styles') || is_readable('styles') == false)){
  1351. $this->Install();
  1352. }
  1353. if($this->DoneReadPosts){ return; }
  1354. $file_list = [];
  1355. $glob = glob('posts/*');
  1356. foreach($glob as $file) {
  1357. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1358. $file_list[] = $file;
  1359. }
  1360. }
  1361. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1362. foreach($file_list as $f) {
  1363. $this->ReadPostsFromFile($f);
  1364. }
  1365. $this->SortPosts();
  1366. $this->DetectThreads();
  1367. $this->DoneReadPosts=1;
  1368. }
  1369. function UpdatePostRefsForWayback(){
  1370. if(!isset($this->WayBack)) return;
  1371. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1372. if(!isset($this->WaybackPosts[0])) return;
  1373. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1374. foreach($this->WaybackPosts as &$p){
  1375. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1376. $pr = &$this->GetPost($r); if(isset($pr)){
  1377. if(!isset($pr['refs'])) $pr['refs']=[];
  1378. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1379. }
  1380. }
  1381. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1382. $ir = &$this->FindImage($r); if(isset($ir)){
  1383. if(!isset($ir['refs'])) $ir['refs']=[];
  1384. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1385. }
  1386. }
  1387. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1388. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1389. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1390. }
  1391. }
  1392. }
  1393. function ReadArchive(){
  1394. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1395. if ($this->DoneReadArchive) return;
  1396. $file_list = []; $glob = glob('archive/*');
  1397. foreach($glob as $file) {
  1398. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1399. $file_list[] = $file;
  1400. }
  1401. }
  1402. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1403. foreach($file_list as $f) {
  1404. $this->ReadArchiveFromFile($f);
  1405. }
  1406. $this->SortArchive();
  1407. $this->DoneReadArchive=1;
  1408. $this->UpdateThreadForWayback();
  1409. $this->UpdatePostRefsForWayback();
  1410. }
  1411. function GetThreadForPost(&$post){
  1412. if(isset($post['tid'])) return;
  1413. $th = []; $iterp = NULL;
  1414. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1415. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1416. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1417. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1418. $np['tid'] = &$th;
  1419. $th['first'] = &$np;
  1420. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1421. }
  1422. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1423. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1424. $np['tid'] = &$th;
  1425. $th['last'] = &$np;
  1426. $iterp = isset($np['next'])?$np['next']:NULL;
  1427. }
  1428. if(isset($th['first']['mark_value'])){
  1429. if($th['first']['mark_value']==6) $th['exp'] = true;
  1430. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1431. }
  1432. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1433. $this->Threads[] = &$th;
  1434. }
  1435. function IdentifyThreadCategory(&$th,&$first_post){
  1436. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1437. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1438. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1439. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1440. }
  1441. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1442. }
  1443. if(preg_match('/\{\s*WIDE\s*\}/imu',$first_post['content'],$m)){ $first_post['wide'] = true; }
  1444. if(preg_match('/\{\s*NO_TIME\s*\}/imu',$first_post['content'],$m)){ $first_post['no_time'] = true; }
  1445. if(preg_match('/\{\s*NO_TITLE\s*\}/imu',$first_post['content'],$m)){ $first_post['no_title'] = true; }
  1446. if(preg_match('/\{\s*HEADER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['header'] = trim($m[1]); }
  1447. if(preg_match('/\{\s*FOOTER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['footer'] = trim($m[1]); }
  1448. if(!isset($th)) return;
  1449. if(isset($first_post['wide'])) $th['wide']=$first_post['wide'];
  1450. if(isset($first_post['header'])) $th['header']=$first_post['header'];
  1451. if(isset($first_post['footer'])) $th['footer']=$first_post['footer'];
  1452. if(isset($first_post['no_time'])) $th['no_time']=$first_post['no_time'];
  1453. if(isset($first_post['no_title'])) $th['no_title']=$first_post['no_title'];
  1454. if(preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1455. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1456. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1457. }
  1458. }
  1459. if(preg_match('/\{\s*REVERSED\s*(\s+.*?)?\}/imu',$first_post['content'],$m)){ $th['reversed'] = 'm';
  1460. if(isset($m[1])&&preg_match('/$\s*(y|m|d)/iu',$m[1],$ma)){ $th['reversed']=$ma[0]; }
  1461. }
  1462. }
  1463. function IsInterestingPost(&$p){
  1464. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1465. return false;
  1466. }
  1467. function IsReversedThread(&$th){
  1468. if(isset($th['reversed']) && $th['reversed']!=false) return true;
  1469. return false;
  1470. }
  1471. function GiveAllMergedPosts(&$po,&$arr){
  1472. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1473. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1474. }
  1475. if(isset($po['archive']) && isset($po['archive']['list'])){
  1476. foreach($po['archive']['list'] as &$ver){
  1477. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1478. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1479. }
  1480. }
  1481. }
  1482. function ThreadMakeWayback(&$th){
  1483. if(!isset($th['arr'][0])) return;
  1484. if(isset($this->WayBack)){
  1485. $remlist = [];
  1486. foreach($th['arr'] as &$pi){
  1487. $po = &$this->GetPost($pi['id'],true); if(!isset($po)){continue;/*merged*/}
  1488. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1489. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1490. }
  1491. $ah = &$this->GetArchiveHandle($po['id']);
  1492. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1493. if(!isset($ver['merged_thread'])) continue;
  1494. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1495. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1496. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1497. }
  1498. }
  1499. }
  1500. if(isset($remlist[0]) && isset($th['arr'][0])){
  1501. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1502. foreach($th['arr'] as $key => $pr){
  1503. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1504. $new_th = []; $new_arr = [];
  1505. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1506. $new_th['arr'] = &$new_arr;
  1507. $this->WaybackThreads[] = &$new_th;
  1508. $this->ThreadMakeWayback($new_th);
  1509. }
  1510. }
  1511. }
  1512. function AddMergedPosts(&$p, &$array){
  1513. if(isset($p['archive']) && isset($p['archive']['list'])){
  1514. foreach($p['archive']['list'] as &$ver){
  1515. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1516. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1517. }
  1518. }
  1519. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1520. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1521. }
  1522. function &array_shift_ref(&$array){if(count($array)>0){$key=key($array);$first=&$array[$key];}else{$first=null;}array_shift($array);return $first;}
  1523. function FinalizeThread(&$th, $relink_posts=false, $now){
  1524. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1525. if(!isset($th['arr'])){
  1526. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1527. $arr[]=&$p;
  1528. } $th['arr'] = &$arr;
  1529. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1530. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1531. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1532. $arr=&$new_arr; $th['arr']=&$new_arr;
  1533. $this->ThreadMakeWayback($th); }
  1534. }
  1535. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1536. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1537. if($relink_posts){ $count = $th['count'];
  1538. $arr = &$th['arr'];
  1539. 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'];
  1540. $arr[$i]['tid']=&$th;}
  1541. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1542. }
  1543. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1544. $this->IdentifyThreadCategory($th, $th['first']);
  1545. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1546. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1547. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1548. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1549. if(isset($th['reversed'])){ $chunks=[]; $last_id=$last_y=$last_m=$last_d=0; $mo=$th['reversed']; $final=[];
  1550. $first_post=&$this->array_shift_ref($th['arr']); $ch=[];
  1551. while($n=&$this->array_shift_ref($th['arr'])){
  1552. $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);
  1553. if($mo=='y'&&$this_y!=$last_y){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y; }
  1554. if($mo=='m'&&$this_m!=$last_m){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m; }
  1555. if($mo=='d'&&$this_d!=$last_d){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m.'/'.$this_d; }
  1556. $ch[]=$n; $last_id=$this_id; $last_y=$this_y; $last_m=$this_m; $last_d=$this_d;
  1557. }if(isset($ch[0])){$chunks[]=$ch;} if(isset($chunks[0])){$use_chunks=array_reverse($chunks);}
  1558. $final[]=&$first_post;
  1559. foreach($use_chunks as &$ch){ foreach($ch as &$p){ $final[]=&$p;} }
  1560. $th['arr']=$final; }
  1561. }
  1562. function SortThreads(){
  1563. if (!function_exists('cmpt')) {
  1564. function cmpt($a, $b){
  1565. if ($a['score'] == $b['score']) return 0;
  1566. return ($a['score'] > $b['score']) ? -1 : 1;
  1567. }
  1568. }
  1569. usort($this->Threads,"cmpt");
  1570. }
  1571. function DetectThreads(){
  1572. foreach($this->Posts as &$p){
  1573. if(isset($p['tid'])) { continue; }
  1574. $this->GetThreadForPost($p);
  1575. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1576. }
  1577. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1578. $now = date_timestamp_get(date_create());
  1579. foreach($this->Threads as &$t){
  1580. $this->FinalizeThread($t,false,$now);
  1581. }
  1582. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1583. $this->FinalizeThread($th,false,$now);
  1584. $this->Threads[] = &$th;
  1585. }
  1586. $this->SortThreads();
  1587. }
  1588. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1589. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1590. foreach($this->Threads as &$t){
  1591. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1592. }
  1593. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1594. $this->FinalizeThread($th,true,$now);
  1595. $this->Threads[] = &$th;
  1596. }
  1597. $this->SortThreads();
  1598. $this->SortPosts(true);
  1599. $this->UsePosts = &$this->WaybackPosts;
  1600. }
  1601. function &GetMergedPost($id){
  1602. $this->ReadArchive();
  1603. $ah = &$this->GetArchiveHandle($id);
  1604. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1605. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1606. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1607. [$tp, $tver] = $ver['merged_into'];
  1608. if(isset($this->WayBack)){
  1609. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1610. else return $this->GetPost($id); /* should not happen directly. */
  1611. }
  1612. return $this->GetMergedPost($tp);
  1613. }
  1614. function &GetPost($id, $latest_only=false, $find_merged=false){
  1615. if(!isset($id)) return $this->NULL_POST;
  1616. $found=&$this->NULL_POST;
  1617. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1618. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1619. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1620. }
  1621. if($latest_only || !isset($this->WayBack)){ return $found; }
  1622. else{
  1623. if(isset($found)){
  1624. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1625. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1626. $last_ver = &$this->NULL_POST;
  1627. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1628. if($ver['version'] > $this->WayBack) return $last_ver;
  1629. $last_ver = &$ver;
  1630. }
  1631. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1632. else return $last_ver;
  1633. }else{
  1634. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1635. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1636. if($ver['version'] > $this->WayBack) return $last_ver;
  1637. $last_ver = &$ver;
  1638. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1639. [$tp, $tver] = $last_ver['merged_into'];
  1640. if($tver <= $this->WayBack) {
  1641. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1642. return $last_ver;
  1643. }
  1644. }
  1645. }
  1646. return $this->NULL_POST;
  1647. }
  1648. function &GetArchiveHandle($id){
  1649. if(!isset($id)) return $this->NULL_POST;
  1650. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1651. if($p && $p['id'] == $id) { return $p; }
  1652. }
  1653. return $this->NULL_POST;
  1654. }
  1655. function &GetArchive($id){
  1656. if(!isset($id)) return $this->NULL_POST;
  1657. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1658. if($p && $p['id'] == $id) { return $p; }
  1659. }
  1660. return $this->NULL_POST;
  1661. }
  1662. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1663. if(!isset($ah)) return $this->NULL_POST;
  1664. $found = NULL; $last_verp=NULL;
  1665. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1666. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1667. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1668. $last_verp = &$p;
  1669. }
  1670. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1671. return $this->NULL_POST;
  1672. }
  1673. function CacheArchiveOwnLinks(){
  1674. if(isset($this->WayBack)) return;
  1675. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1676. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1677. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1678. foreach($matches as $m){
  1679. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1680. }
  1681. }
  1682. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1683. foreach($matches as $m){
  1684. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1685. }
  1686. }
  1687. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1688. foreach($matches as $m){
  1689. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1690. }
  1691. }
  1692. }
  1693. }
  1694. function WriteArchive(){
  1695. if(isset($this->WayBack)) return;
  1696. $cf = NULL;$opened =NULL;
  1697. $this->SortArchive();
  1698. $this->CacheArchiveOwnLinks();
  1699. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1700. $nid = substr($p['id'], 0,6);
  1701. if($cf != $nid){
  1702. if($opened){
  1703. fflush($opened);
  1704. fclose($opened);
  1705. }
  1706. $cf = $nid;
  1707. $opened = fopen("archive/$cf.md", 'w');
  1708. }
  1709. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1710. "VER {$p['version']}; ".
  1711. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1712. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1713. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1714. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1715. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1716. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1717. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1718. ']';
  1719. if(isset($p['merged_thread'])){ $p['content']=""; }
  1720. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1721. }
  1722. }
  1723. function WritePosts(){
  1724. if(isset($this->WayBack)) return;
  1725. $cf = NULL;$opened =NULL;
  1726. $this->SortPosts();
  1727. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1728. $nid = substr($p['id'], 0,6);
  1729. if($cf != $nid){
  1730. if($opened){
  1731. fflush($opened);
  1732. fclose($opened);
  1733. }
  1734. $cf = $nid;
  1735. $opened = fopen("posts/$cf.md", 'w');
  1736. }
  1737. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1738. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1739. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1740. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1741. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1742. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1743. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1744. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1745. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1746. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1747. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1748. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1749. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1750. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1751. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1752. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1753. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1754. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1755. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1756. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1757. ']';
  1758. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1759. }
  1760. }
  1761. function CachePostLinks(){
  1762. if(isset($this->WayBack)) return;
  1763. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1764. $this->ConvertPost($post);
  1765. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1766. //discard lost old version
  1767. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1768. }else return;
  1769. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1770. unset($im['refs']); unset($im['here']); unset($im['title']);
  1771. }
  1772. foreach ($this->Posts as &$post){
  1773. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1774. foreach($matches as $m){
  1775. $ref = &$this->GetPost($m[1],true);
  1776. if($ref!=NULL){
  1777. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1778. }
  1779. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1780. }
  1781. }
  1782. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1783. foreach($matches as $m){
  1784. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1785. }
  1786. }
  1787. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1788. foreach($matches as $m){
  1789. if(($im = &$this->FindImage($m[2]))!=NULL){
  1790. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1791. }
  1792. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1793. }
  1794. }
  1795. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\))(\R*(\R(-|\*).+){1,})/u",
  1796. $post['content'],$matches)){
  1797. $use_img_name = $matches[2];
  1798. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1799. 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",
  1800. $matches[4],$mah,PREG_SET_ORDER)){
  1801. foreach($mah as $ma){
  1802. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1803. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. }foreach($this->Posts as &$post){
  1809. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1810. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1811. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1812. }
  1813. }
  1814. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1815. $min_id = '99999999999999';
  1816. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1817. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1818. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1819. }
  1820. }
  1821. }
  1822. function CreatePostAnchor(&$post){
  1823. $that=&$this;
  1824. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1825. $id = '_heading_'.sizeof($this->Anchors);
  1826. $entry=[(int)$ma[1], $id, $ma[2]];
  1827. $that->Anchors[] = $entry;
  1828. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1829. }, $post['html']);
  1830. }
  1831. function RenamePost(&$post, $rename){
  1832. foreach($this->Posts as &$p){
  1833. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1834. }
  1835. foreach($this->Posts as &$p){
  1836. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1837. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1838. }
  1839. $post['id'] = $rename;
  1840. }
  1841. function DetachPost(&$th,&$post){
  1842. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1843. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1844. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1845. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1846. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1847. unset($th['arr']); $now = date_timestamp_get(date_create());
  1848. $this->FinalizeThread($th, true, $now);
  1849. }
  1850. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1851. $a = &$this->GetArchiveHandle($post['id']);
  1852. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1853. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1854. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1855. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1856. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1857. $post['version'] = $optime_id;
  1858. if($mode==1){
  1859. $this->InsertArchivePost($ap);
  1860. }else if($mode==2){
  1861. $post['merged_from'] = $info;
  1862. $this->InsertArchivePost($ap);
  1863. }else if($mode==3){
  1864. $ap['merged_into'] = $info;
  1865. $this->InsertArchivePost($ap);
  1866. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1867. $this->DetachPost($post['tid'], $post);
  1868. }
  1869. }else if($mode==4){
  1870. $post['merged_thread'] = $info;
  1871. $this->InsertArchivePost($ap);
  1872. }
  1873. }
  1874. function &MergeThreads($post_id, $post_into_id){
  1875. $this->ReadPosts();
  1876. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1877. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1878. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1879. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1880. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1881. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1882. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1883. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1884. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  1885. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1886. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1887. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1888. $tt['count'] = sizeof($tt['arr']);
  1889. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1890. $first_post = &$this->NULL_POST;
  1891. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1892. $this->NeedWritePosts=1;
  1893. $this->NeedWriteArchive=1;
  1894. return $first_post;
  1895. }
  1896. function &MergePosts($ids_string){
  1897. $ids = explode(" ", $ids_string);
  1898. $combined_content = ""; $first_id=NULL;
  1899. $this->ReadPosts(); $child_list=[];
  1900. foreach($ids as $id){
  1901. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1902. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1903. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  1904. }
  1905. if(!isset($child_list[0])) return $this->NULL_POST;
  1906. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  1907. foreach($child_list as $id){
  1908. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  1909. }
  1910. $this->NeedWritePosts=1;
  1911. $this->NeedWriteArchive=1;
  1912. return $first_post;
  1913. }
  1914. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1915. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1916. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1917. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  1918. $this->ReadImages();
  1919. $this->ReadPosts();
  1920. if(isset($push_version) && $push_version){
  1921. $this->ReadArchive();
  1922. }
  1923. $p_success = NULL;
  1924. if(isset($id_if_edit)){
  1925. $post = &$this->GetPost($id_if_edit,true);
  1926. if($post===$this->NULL_POST) return $this->NULL_POST;
  1927. if($get_original_only){
  1928. return $post['real_content'];
  1929. }
  1930. if(isset($push_version) && $push_version){
  1931. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1932. }
  1933. if(isset($content)) {$post['real_content'] = $content; $post['content'] = &$post['real_content'];}
  1934. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1935. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1936. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1937. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  1938. $p_success = &$post;
  1939. }else{
  1940. if(!isset($content)) return $this->NULL_POST;
  1941. $id = date('YmdHis');
  1942. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1943. $post = []; $post['id'] = $id;
  1944. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1945. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1946. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1947. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1948. }
  1949. $this->Posts[] = $post;
  1950. $p_success = &$this->Posts[count($this->Posts) - 1];
  1951. }
  1952. $this->NeedWritePosts=1;
  1953. $this->NeedWriteImages=1;
  1954. if(isset($push_version) && $push_version){
  1955. $this->NeedWriteArchive=1;
  1956. }
  1957. return $p_success;
  1958. }
  1959. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1960. $this->ReadPosts();
  1961. $p_success = NULL;
  1962. if(isset($id_if_edit)){
  1963. $post = &$this->GetPost($id_if_edit,true);
  1964. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1965. if(isset($content)) $post['content'] = $content;
  1966. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1967. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1968. if(isset($ip)) $post['ip'] = $ip;
  1969. $p_success = &$post;
  1970. }else{
  1971. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1972. $id = date('YmdHis');
  1973. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1974. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1975. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1976. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1977. if(isset($ip)) $post['ip'] = $ip;
  1978. $this->Posts[] = $post;
  1979. $p_success = &$this->Posts[count($this->Posts) - 1];
  1980. }
  1981. $this->NeedWritePosts=1;
  1982. return $p_success;
  1983. }
  1984. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  1985. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1986. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1987. function($matches){
  1988. $rep = preg_replace('/->/','-@>',$matches[0]);
  1989. $rep = preg_replace('/=>/','=@>',$rep);
  1990. $rep = preg_replace('/<=/','<@=',$rep);
  1991. $rep = preg_replace('/<-/','<@-',$rep);
  1992. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  1993. $rep = preg_replace('/\[-/','[@-',$rep);
  1994. $rep = preg_replace('/\{/','{@',$rep);
  1995. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  1996. return $rep;
  1997. },
  1998. $replacement);
  1999. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  2000. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  2001. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  2002. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  2003. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  2004. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  2005. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  2006. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  2007. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  2008. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  2009. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  2010. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  2011. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  2012. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  2013. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  2014. function($matches){
  2015. $rep = preg_replace('/-@>/','->',$matches[0]);
  2016. $rep = preg_replace('/<@-/','<-',$rep);
  2017. $rep = preg_replace('/=@>/','=>',$rep);
  2018. $rep = preg_replace('/<@=/','<=',$rep);
  2019. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  2020. $rep = preg_replace('/\[@-/','[-',$rep);
  2021. $rep = preg_replace('/\{@/','{',$rep);
  2022. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  2023. return $rep;
  2024. }, $replacement);
  2025. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  2026. function($matches) use (&$post_for_it_is_here){
  2027. $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]);
  2028. return $matches[1].$rep;
  2029. }, $replacement);
  2030. return $replacement;
  2031. }
  2032. function CanShowPost(&$p){
  2033. if(!isset($p) || isset($p['comment_to'])) return false;
  2034. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  2035. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  2036. if($is_mark_slf && !$this->LoggedIn){ return false; }
  2037. if(isset($this->WayBack)){
  2038. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  2039. else if ($p['id']>$this->WayBack) return false;
  2040. }
  2041. if(!$this->InExperimentalMode){
  2042. if(!$this->LoggedIn){
  2043. if($is_mark_exp) return false;
  2044. return true;
  2045. }
  2046. return true;
  2047. }else{
  2048. if($is_mark_exp) return true;
  2049. return false;
  2050. }
  2051. }
  2052. function SkipProduct(&$p){
  2053. if($this->LoggedIn) return false;
  2054. return (isset($p['mark_value']) && $p['mark_value']==5);
  2055. }
  2056. function GetRedirect($args=NULL){
  2057. $str = 'index.php?';
  2058. if(isset($args['post'])) $str.='&post='.$args['post'];
  2059. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  2060. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  2061. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  2062. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  2063. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  2064. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  2065. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  2066. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  2067. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  2068. if(isset($args['category'])) $str.='&category='.$args['category'];
  2069. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  2070. if(isset($args['history'])) $str.='&history='.$args['history'];
  2071. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  2072. if(isset($args['version'])) $str.='&version='.$args['version'];
  2073. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  2074. if(isset($args['search'])) $str.='&search='.$args['search'];
  2075. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  2076. if(isset($args['here'])) $str.='&here='.$args['here'];
  2077. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  2078. return $str;
  2079. }
  2080. function WriteAsNecessary(){
  2081. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  2082. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  2083. if($this->NeedWriteImages){ $this->WriteImages(); }
  2084. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  2085. }
  2086. function APubEnsureWebfinger($name, $host){
  2087. if(!is_dir('.well-known')) mkdir('.well-known');
  2088. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  2089. $f = fopen('.well-known/webfinger/index.php',"w");
  2090. $without_protocol = parse_url($host, PHP_URL_HOST);
  2091. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  2092. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  2093. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  2094. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2095. $res = openssl_pkey_new();
  2096. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2097. openssl_pkey_export($res, $this->APubPrivateKey);
  2098. $f = fopen('.well-known/apub_public_key.pem',"w");
  2099. fwrite($f, $this->APubPublicKey); fclose($f);
  2100. $f = fopen('.well-known/apub_private_key.php',"w");
  2101. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2102. }
  2103. }
  2104. function APubEnsureInfo(){
  2105. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2106. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2107. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2108. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2109. "id"=> $this->HostURL."?apub_actor=1",
  2110. "type"=> "Person",
  2111. "name"=> $this->DisplayName,
  2112. "url"=> $this->HostURL,
  2113. "summary"=> "Lazy... No summary",
  2114. "preferredUsername"=> $this->APubID,
  2115. "inbox"=> $this->HostURL."?apub_inbox=1",
  2116. "outbox"=> $this->HostURL."?apub_outbox=1",
  2117. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2118. "owner"=> $this->HostURL."?apub_actor=1",
  2119. "publicKeyPem"=>$pk]];
  2120. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2121. }
  2122. function APubMakeOutbox(){
  2123. $this->ReadPosts();$this->ReadImages();
  2124. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2125. "id"=>$this->HostURL."?apub_outbox=1",
  2126. "type"=>"OrderedCollection"];
  2127. $items=[]; $i=0;
  2128. foreach(array_reverse($this->Posts) as &$p){
  2129. $this->ConvertPost($p);
  2130. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2131. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2132. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2133. "type"=> "Create",
  2134. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2135. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2136. //"to"=> ["https://chatty.example/ben/"],
  2137. "actor"=> $this->HostURL."?apub_actor=1",
  2138. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2139. "object"=> ["type"=> "Note",
  2140. "id"=> $this->HostURL."?post=".$p['id'],
  2141. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2142. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2143. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2144. "content"=> $text]];
  2145. $items[] = $ob;
  2146. $i++; if($i>20) break;
  2147. }
  2148. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2149. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2150. }
  2151. function MakeRSS(){
  2152. $this->ReadPosts();$this->ReadImages();
  2153. $posts = []; if(isset($this->UsePosts[0])){
  2154. $posts = array_reverse($this->UsePosts);
  2155. $last_updated = $this->StandardTime($posts[0]['id']);
  2156. }else{ $last_updated= $this->StandardTime("20000101000000"); }
  2157. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2158. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2159. "<id>".$this->HostURL."/?rss</id>".
  2160. "<updated>".$last_updated."</updated>".
  2161. "<title>".$this->T($this->Title)."</title>".
  2162. "<link href='".$this->HostURL."/?rss' rel='self'/>".
  2163. "<link href='".$this->HostURL."' />".$author;
  2164. $i=0;
  2165. if(isset($posts[0])) foreach($posts as &$p){
  2166. if($i>100) break;
  2167. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2168. if(isset($p['tid'])){ /* Should always be set. */
  2169. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2170. if(in_array($p['id'],
  2171. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  2172. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2173. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2174. $is_reversed=false;
  2175. $content="<entry>"; $title = NULL;
  2176. if($is_thread){
  2177. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2178. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2179. foreach($use_arr as &$po){
  2180. $this->ConvertPost($po);
  2181. if(!isset($title)){$title = $this->GetPostTitle($po, false, false);
  2182. $content.="<id>".$this->HostURL."?post=".$po['id']."</id>";
  2183. $content.="<title>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$po['id']."' />";
  2184. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2185. $content.="<updated>".$this->StandardTime(isset($po['tid']['last']['version'])?
  2186. $po['tid']['last']['version']:$po['tid']['last']['id'])."</updated>".$author;
  2187. $content.="<content type='html'>"; }
  2188. $content.= htmlspecialchars($po['html']);
  2189. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2190. }
  2191. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2192. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2193. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2194. $content.="</content>";
  2195. }else{
  2196. $this->ConvertPost($p);
  2197. if(!isset($title)){$title = $this->GetPostTitle($p, false, false);
  2198. $content.="<id>".$this->HostURL."?post=".$p['id']."</id>";
  2199. $content.="<title>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$p['id']."' />";
  2200. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2201. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2202. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2203. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2204. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2205. $content.=$this->ReadableTime($p['id'])." - ".
  2206. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2207. $content.="</content>";
  2208. }
  2209. $i++;
  2210. $content.="</entry>";
  2211. $all_content.=$content;
  2212. }
  2213. $all_content.="</feed>";
  2214. header( "Content-type: text/xml");
  2215. echo $all_content;
  2216. }
  2217. function MakeHereButtons($im, $insert_here){
  2218. if(isset($im['here'])&&isset($im['here'][0])){
  2219. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2220. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2221. foreach($im['here'] as $here){
  2222. if($insert_here){
  2223. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2224. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2225. }else{
  2226. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2227. }
  2228. }
  2229. echo "</div>".($insert_here?"</here>":"");
  2230. }
  2231. }
  2232. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  2233. if(isset($_GET['gallery_continue']) && $_GET['gallery']){
  2234. $this->ReadImages();
  2235. $this->GetImageBatch($_GET['gallery_continue'],0);
  2236. exit;
  2237. }
  2238. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2239. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2240. return 0;
  2241. }
  2242. if(isset($_GET['set_language'])){
  2243. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2244. $redirect=$this->GetRedirect(); return 0;
  2245. }
  2246. if(isset($_GET['rss'])){
  2247. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2248. $this->MakeRSS(); exit;
  2249. }
  2250. if(isset($_GET['toggle_font'])){ $use_font='local';
  2251. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2252. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2253. $redirect=$this->GetRedirect(); return 0;
  2254. }
  2255. if(isset($_GET['set_wayback'])){
  2256. if($_GET['set_wayback']!='false'){
  2257. $wayback= date('YmdHis');
  2258. if($_GET['set_wayback']=='post'){
  2259. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2260. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2261. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2262. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2263. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2264. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2265. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2266. }else{
  2267. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2268. }
  2269. $redirect=$this->GetRedirect(); return 0;
  2270. }
  2271. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2272. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2273. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2274. if(isset($_GET['post'])){
  2275. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2276. }
  2277. if(isset($_GET['random_here'])){
  2278. $this->DoIdentifyExperimental(); $this->DetectPageType();
  2279. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2280. }
  2281. if(isset($_POST['search_content'])){ $redirect='index.php?search='.$_POST['search_content'];return 0; }
  2282. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2283. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2284. $direct_return = !isset($_GET['show_image']);
  2285. $this->ReadImages(); $this->ReadPosts();
  2286. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2287. $im = &$this->FindImage($m);
  2288. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2289. if($direct_return){
  2290. echo "<ref>".sizeof($im['refs'])."</ref>";
  2291. echo "<insert><ul>";
  2292. }else{ ob_start(); }
  2293. foreach(array_reverse($im['refs']) as $ref){
  2294. $p = $this->GetPost($ref);
  2295. if(!$p || !$this->CanShowPost($p)) continue;
  2296. $this->MakeSinglePost($p, false, true, "post_preview invert_a", true, false, false, false, true);"</li>";
  2297. }
  2298. if($direct_return){
  2299. echo "</ul></insert>";
  2300. $this->MakeHereButtons($im, true);
  2301. }else{
  2302. $str = ob_get_clean();
  2303. $this->MakePageBegin();
  2304. $side = "";
  2305. if(isset($im['refs'])&&isset($im['refs'][0])){
  2306. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2307. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2308. $static_image = isset($im['video'])?NULL:$im['file'];
  2309. $static_video = isset($im['video'])?$im['file']:NULL;
  2310. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$static_image,$static_video);
  2311. $this->MakePageEnd();
  2312. }
  2313. exit;
  2314. }
  2315. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2316. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2317. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2318. }
  2319. if(isset($_GET['apub_actor'])){
  2320. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2321. echo $this->APubActor; exit;
  2322. }
  2323. if(isset($_GET['apub_outbox'])){
  2324. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2325. echo $this->APubMakeOutbox(); exit;
  2326. }
  2327. if($this->LoggedIn){
  2328. $this->DoUpload();
  2329. if(isset($_POST['settings_button'])){
  2330. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2331. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2332. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2333. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2334. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2335. if(isset($_POST['settings_special_sidebar'])) $this->SpecialSidebar=$_POST['settings_special_sidebar'];
  2336. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2337. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2338. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2339. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2340. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2341. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2342. if(isset($_POST['settings_gallery_step'])) $this->GalleryStep=$_POST['settings_gallery_step'];
  2343. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2344. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2345. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2346. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2347. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2348. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2349. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2350. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2351. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2352. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2353. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2354. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2355. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2356. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2357. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2358. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2359. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2360. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2361. $this->APubID=$_POST['settings_apub_id'];
  2362. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2363. }
  2364. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2365. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2366. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2367. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2368. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2369. $redirect=$_SERVER['REQUEST_URI'];
  2370. $this->DoLogout();
  2371. }
  2372. $this->WriteConfig();
  2373. return 0;
  2374. }
  2375. if(isset($_POST['settings_save_redirect'])){
  2376. if(isset($_POST['settings_redirect'])){
  2377. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2378. }
  2379. $this->WriteConfig();
  2380. $redirect = 'index.php?extras=true'; return 0;
  2381. }
  2382. if(isset($_POST['settings_save_translation'])){
  2383. if(isset($_POST['settings_translation'])){
  2384. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2385. }
  2386. $redirect = 'index.php?extras=true'; return 0;
  2387. }
  2388. if(isset($_GET['post'])){
  2389. if(isset($_GET['post_original'])){
  2390. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2391. exit;
  2392. }
  2393. }
  2394. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2395. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2396. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2397. return 0;
  2398. }
  2399. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2400. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2401. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2402. return 0;
  2403. }
  2404. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2405. $c = $_POST['post_content'];
  2406. if('有什么想说的' == $c){ return 0;}
  2407. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2408. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2409. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2410. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2411. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2412. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2413. $redirect='?post='.$edited['id']; return 0;
  2414. };
  2415. }
  2416. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2417. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2418. $redirect='?post='.$edited['id']; return 0;
  2419. };
  2420. }
  2421. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2422. if(($edited =$this->EditPost(
  2423. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2424. $redirect='?post='.$edited['id']; return 0;
  2425. };
  2426. }
  2427. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2428. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2429. if(isset($post)){
  2430. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2431. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2432. echo "SUCCESS ".$mastodon_url;
  2433. }else{ echo $err; }
  2434. } exit;
  2435. }
  2436. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2437. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2438. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2439. }
  2440. }
  2441. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2442. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2443. $redirect='?post='.$pe['id']; return 0;
  2444. }
  2445. }
  2446. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2447. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2448. $c = $_POST['comment_box'];
  2449. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2450. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2451. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2452. if(($edited = $this->EditComment(NULL,
  2453. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2454. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2455. $_SERVER['REMOTE_ADDR']))!=NULL){
  2456. $redirect='?post='.$_GET['post'];
  2457. return 0;
  2458. };
  2459. }
  2460. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2461. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2462. $new_name = $_POST['gallery_edit_new_name'];
  2463. if($old_name!=''){
  2464. $this->EditGallery($old_name, $new_name, false, true, null, null);
  2465. $redirect='?gallery='.$new_name;
  2466. }else{
  2467. $this->EditGallery(null, $new_name, false, true, null);
  2468. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2469. }
  2470. return 0;
  2471. }
  2472. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2473. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  2474. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  2475. return 0;
  2476. }
  2477. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2478. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2479. $this->ReadImages();
  2480. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2481. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL, NULL);
  2482. }
  2483. }
  2484. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2485. return 0;
  2486. }
  2487. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2488. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2489. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2490. return 0;
  2491. }
  2492. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2493. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2494. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2495. return 0;
  2496. }
  2497. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2498. $this->ReadImages();
  2499. $gallery = $_GET['image_list'];
  2500. foreach($this->Images as $im){
  2501. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2502. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2503. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2504. }
  2505. exit;
  2506. }
  2507. $do_image_redirect = 0;
  2508. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2509. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4))/u',$_GET['pic'],$ma)){
  2510. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2511. if(isset($_POST['image_ops_product_link'])){
  2512. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL, NULL);
  2513. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2514. }
  2515. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2516. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL, NULL);
  2517. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2518. $do_image_redirect = 1;
  2519. }
  2520. if(isset($_POST['image_parent'])){ $parent="";
  2521. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2522. $this->EditImage($pic, NULL, false, NULL, NULL, $parent, NULL);
  2523. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2524. }
  2525. if(isset($_POST['image_align'])){$val=$_POST['image_align'];
  2526. $this->EditImage($pic, NULL, false, NULL, NULL, NULL, $val);
  2527. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2528. }
  2529. $this->NeedWriteImages = 1;
  2530. if($do_image_redirect) return 0;
  2531. }
  2532. if(isset($_GET['rewrite_styles'])){
  2533. $this->WriteStyles();
  2534. $redirect='?extras=true'; return 0;
  2535. }
  2536. if(isset($_GET['regenerate_thumbnails'])){
  2537. $this->RegenerateThumbnails();
  2538. $redirect='?extras=true'; return 0;
  2539. }
  2540. if(isset($_GET['clear_all_logins'])){
  2541. $this->LoginTokens=[];
  2542. $this->WriteTokens();
  2543. }
  2544. }
  2545. return 0;
  2546. }
  2547. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null, &$end_wide=null, &$print_wide=null){
  2548. if(!$this->LoggedIn){
  2549. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2550. }
  2551. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2552. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2553. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2554. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2555. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2556. $html = preg_replace("/\{\s*(INTERESTING|HEADER|FOOTER)\s+(.*?)\}/imu","",$html);
  2557. $html = preg_replace("/\{\s*(REVERSED|NO_TIME|NO_TITLE)\s*\}/imu","",$html);
  2558. $html = preg_replace("/\{\s*WIDE\s*\}/imu","",$html,-1,$rep_count); if($rep_count){$print_wide=true;}
  2559. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2560. $html = preg_replace_callback(
  2561. "/(<p>\s*|<a\s.*?>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2562. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2563. if(isset($m[1])&&$m[1]&&$m[1][1]=='a'){ $height="";
  2564. if(preg_match("/([0-9]{1,2})em/u",$m[0],$hm)){$height=' style="height:'.$hm[1].'em;"';}
  2565. return "<a class='imbtn'".$height.substr($m[0],2); }
  2566. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2567. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2568. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2569. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2570. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2571. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2572. $src = $im['thumb']; $orig_src=$im['file'];
  2573. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2574. $media_start = $m[2];
  2575. $media_end = $m[7];
  2576. $dataset = " data-imgsrc='".$m[5]."'".
  2577. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2578. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2579. (isset($im['align'])?' data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':"").
  2580. ($original?" class='original_img'":"");
  2581. if(isset($im['video']) && isset($im['video'])!=''){
  2582. $media_start = "<video controls".$dataset."><source src='"; $media_end="' type='".$im['video']."'></video";
  2583. $src = $orig_src; $dataset="";
  2584. }
  2585. if($this->InHereMode){
  2586. $click = "<div class='imd'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2587. $media_start.$orig_src.$media_end."></a></div>";
  2588. return $click;
  2589. }else{
  2590. $click ="<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2591. $media_start.($original?$orig_src:$src).$media_end.$dataset."></a></div>";
  2592. $images_noclick[]=$media_start.$src.$media_end.">"; $images_orig_src_list[]=$orig_src;
  2593. $ret = "";
  2594. if($keep) { $ret = $click; }
  2595. else { $images[] = $click; }
  2596. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2597. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2598. }
  2599. },$html,-1,$count);
  2600. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2601. if(sizeof($images)){
  2602. if(sizeof($images)==1){$html.= $images[0]; }
  2603. else{
  2604. $html.="<div class='p_row'>";
  2605. foreach($images as $img){
  2606. $html.="<div class='p_thumb'>".$img."</div>";
  2607. }
  2608. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2609. }
  2610. }
  2611. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2612. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2613. if($do_product_info){
  2614. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2615. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2616. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2617. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2618. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2619. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2620. else { $product_info['title'] = $this->T('商品'); }
  2621. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2622. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2623. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2624. $this->T('购买').' '.$product_info['title'].
  2625. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2626. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2627. }
  2628. if(preg_match("/(<\/div>|<\/table>|<\/video>)\s*$/u",$html)){$end_wide=true;}
  2629. return $html;
  2630. }
  2631. function ConvertPost(&$post){
  2632. if(!isset($post['html'])){
  2633. $info=[];
  2634. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2635. $post['images'],
  2636. isset($post['product']), $info,
  2637. $post['original_images'],
  2638. $post['end_wide'],
  2639. $post['wide']));
  2640. if(isset($post['product'])) $post['product']=$info;
  2641. }
  2642. }
  2643. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2644. if(!isset($post['title'])){
  2645. if($h1_only){
  2646. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2647. else return NULL;
  2648. }
  2649. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2650. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2651. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2652. $post['title'].=($add_unamed?' (':'').strip_tags($this->PDE->text($m[1])).($add_unamed?')':''); }
  2653. }
  2654. }
  2655. return $this->ChoosePartsByLanguage($post['title']);
  2656. }
  2657. function DetectPageType(){
  2658. if ($this->InExperimentalMode) $this->PageType='experimental';
  2659. else if($this->InHereMode) $this->PageType='here';
  2660. else if(isset($_GET['history'])) $this->PageType='history';
  2661. else if(isset($_GET['extras'])) $this->PageType='extras';
  2662. else if(isset($_GET['settings'])) $this->PageType='settings';
  2663. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2664. else if(isset($_GET['search'])) $this->PageType='search';
  2665. else if(isset($_GET['category'])) $this->PageType='category';
  2666. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2667. else if(isset($_GET['comments'])) $this->PageType='comments';
  2668. else $this->PageType = "main";
  2669. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2670. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2671. $this->VisitedHere = $_SESSION[$visited_here];
  2672. }
  2673. function MakePageBegin(){ ?>
  2674. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2675. <head>
  2676. <meta charset='utf-8'>
  2677. <meta content="width=device-width, initial-scale=1" name="viewport">
  2678. <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2679. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title))?></title>
  2680. <?php if($this->UseRemoteFont){ ?><style>
  2681. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2682. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2683. </style><?php } ?>
  2684. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2685. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2686. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2687. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2688. <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>
  2689. </head>
  2690. <div class='page'>
  2691. <?php }
  2692. function MakeHeader(&$p){
  2693. $this->MakePageBegin() ?>
  2694. <script type='text/javascript'>
  2695. function toggle_mobile_show(a){a.classList.toggle('hidden_m')}
  2696. function ShowWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='';}
  2697. function HideWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='none';}
  2698. <?php if(!$this->InHereMode){ ?>
  2699. function la_auto_grow(element){
  2700. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2701. }
  2702. function ShowBackdrop(alpha=0.5){
  2703. b = document.getElementById('backdrop');
  2704. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2705. b.style.animation='backdrop_fade_in 0.3s forwards';
  2706. b.style.display = 'block';
  2707. }
  2708. function HideBackdrop(){
  2709. b = document.getElementById('backdrop');
  2710. b.style.animation='backdrop_fade_out 0.3s forwards';
  2711. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2712. }
  2713. function ShowRightSide(big,elem_to_clone){
  2714. p = document.getElementById('pop_right');
  2715. if(elem_to_clone){
  2716. c = elem_to_clone.cloneNode(true);
  2717. c.id='side_bar_cloned';c.className="";c.style="";
  2718. p.querySelector('._content').appendChild(c);
  2719. }
  2720. p.classList.remove('pop_right','pop_right_big');
  2721. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2722. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2723. p.style.display='block';
  2724. ShowBackdrop(0.5);
  2725. }
  2726. function HideRightSide(){
  2727. p = document.getElementById('pop_right');
  2728. if(side=p.querySelector('#side_bar_cloned')){
  2729. side.remove();
  2730. }
  2731. put = document.querySelector("#_uploader");
  2732. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2733. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2734. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2735. HideBackdrop();
  2736. }
  2737. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2738. function ScrollToPost(id){
  2739. post=null;
  2740. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2741. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2742. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2743. }
  2744. <?php } ?>
  2745. </script><input type='checkbox' class='lpctrl' id='titlectrl'>
  2746. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2747. <?php if($this->InHereMode){
  2748. $this->MakeExpNavButtons($p);
  2749. }else{
  2750. $this->MakeNavButtons($p);
  2751. if(isset($p['tid']['header'])){ ?><div style='float:right' class='show_on_print'><?=$p['tid']['header'];?></div><?php }
  2752. echo "<hr class='hidden_m'>";
  2753. } ?>
  2754. <?php if(isset($this->WayBack)){
  2755. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2756. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2757. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2758. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_m")'>
  2759. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2760. <span class='hidden_m'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2761. + <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_m'>
  2762. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2763. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2764. <br class='hidden_on_desktop' />
  2765. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2766. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2767. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2768. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2769. <br class='hidden_on_desktop' />
  2770. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2771. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2772. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2773. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2774. <br class='hidden_on_desktop' />
  2775. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2776. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2777. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2778. </div></div><?php } ?>
  2779. </div></header>
  2780. <div id='waiting_bar' style='display:none;'></div>
  2781. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2782. <?php if(!$this->InHereMode){ ?>
  2783. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2784. <ul>
  2785. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2786. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2787. <hr />
  2788. <?php if($this->LoggedIn){ ?>
  2789. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2790. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2791. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2792. <?php if(!isset($this->WayBack)){ ?><li>
  2793. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2794. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2795. </li>
  2796. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2797. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2798. <li id='mark_details' style='display:none;'><b>
  2799. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2800. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2801. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2802. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2803. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2804. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2805. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2806. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2807. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2808. </b></li>
  2809. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2810. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2811. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2812. <input class='button' type='submit' form='post_rename_form'
  2813. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2814. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  2815. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  2816. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  2817. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  2818. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  2819. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  2820. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  2821. <input class='button' type='submit' form='post_mastodon_form'
  2822. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  2823. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  2824. <?php }else{ ?>
  2825. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2826. <?php } ?>
  2827. </ul>
  2828. </div>
  2829. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide();HideBigImage(1);'
  2830. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2831. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2832. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2833. <?=$this->T('关闭')?>→</a></div>
  2834. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2835. <div id='_uploader' style='display:none;'>
  2836. <?php $this->MakeUploader(true); ?>
  2837. <p>&nbsp;</p>
  2838. <?php $this->MakeSideGalleryCode(); ?>
  2839. </div>
  2840. <?php } ?>
  2841. <div class='_content'></div>
  2842. </div>
  2843. <?php } ?>
  2844. <?php
  2845. }
  2846. function ChoosePartsByLanguage($content,$use_p=false){
  2847. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  2848. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  2849. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  2850. if($split) for($i=0;$i<sizeof($split);$i+=4){
  2851. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  2852. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  2853. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  2854. }
  2855. if(!$reduced)$reduced = $content;
  2856. return $reduced;
  2857. }
  2858. function TranslatePostParts($html){
  2859. $html = preg_replace_callback('/>(\s*)([^><]+?)(\s*)</u', function($ma){
  2860. $reduced = $this->ChoosePartsByLanguage($ma[2], false);
  2861. return ">".$ma[1].$this->T($reduced).$ma[3]."<";
  2862. }, $html);
  2863. return $html;
  2864. }
  2865. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); $no_title=isset($p['tid']['first']['no_title']);?>
  2866. <a href='index.php' class='clean_a hidden_m<?=$no_title?" hidden_on_print":""?>' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title);?></b></a>
  2867. <?=$no_title?"<a class='inline_print'>&nbsp;</a>":""?>
  2868. <label for='titlectrl' id='mtitle'><b><a class='hidden_on_desktop'><?=$this->T($this->ShortTitle)?>...</a></b></label>
  2869. <div class='header_nav'>
  2870. <ul class='mobile_fold hidden_on_print' id='mobile_nav'>
  2871. <li class='hidden_m'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2872. <li class='hidden_on_desktop_force block_m smaller'>&nbsp;</li>
  2873. <li class='hidden_on_desktop_force block_m bigger'>
  2874. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a>
  2875. <?php if($this->LoggedIn){ ?>
  2876. | <span class='gray invert_a'><a href='index.php?comments=all'>@</a></span><?php } ?></li>
  2877. <li class='hidden_on_desktop_force block_m bigger'>
  2878. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2879. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2880. echo $this->GenerateSinglePost($p, false, false, false, false);
  2881. } ?>
  2882. </ul></div>
  2883. <?php
  2884. }
  2885. function MakeExpNavButtons(&$p){ ?>
  2886. <a href='index.php' class='hidden_m'>
  2887. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  2888. <a class='hidden_on_desktop'
  2889. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b class='round_btn'>
  2890. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?></b></a>
  2891. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  2892. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  2893. <span class='round_btn'>
  2894. <a href='<?=$this->HereNumber==sizeof($this->VisitedHere)?"?random_here=1":$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a>
  2895. <a href='?random_here=1'><?=$this->T("随机")?></a></span><span class='hidden_m'></span>
  2896. <ul class='hidden_m' id='mobile_nav' style='text-align:center;'>
  2897. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  2898. <li class='hidden_on_desktop block_m'><a href='index.php'><?=$this->T('主页')?></a></li>
  2899. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2900. echo $this->GenerateSinglePost($p, false, false, false, false);
  2901. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  2902. echo $this->GenerateSinglePost($p, false, false, false, false);
  2903. } ?>
  2904. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  2905. <?php if($this->LanguageAppendix=='zh'){ ?>
  2906. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  2907. <?php }else { ?>
  2908. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  2909. <li class='smaller invert_a gray'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  2910. <?php } ?>
  2911. </ul>
  2912. <?php
  2913. }
  2914. function GenerateLinkedPosts($ht){
  2915. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  2916. function($m){
  2917. if(preg_match('/^\s*<img/u',$m[2])){ return $m[0]; }
  2918. $rp = &$this->GetPost($m[1], false, true);
  2919. $s="<div class='smaller block post ref_compact gray'>".
  2920. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  2921. "<div class='post_width'><div class='smaller'>".$m[2]."</div>".
  2922. (($rp!==NULL && $this->CanShowPost($rp))?
  2923. $this->GenerateSinglePost($rp,false,false,false,true,true):$this->T("未找到该引用。")).
  2924. "</div></div>";
  2925. return $s;
  2926. },
  2927. $ht
  2928. );
  2929. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  2930. function($m){
  2931. $rp = &$this->GetPost($m[1], false, true);
  2932. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  2933. (($rp!==NULL && $this->CanShowPost($rp))?
  2934. $this->GenerateSinglePost($rp,true,false,false,true,true):$this->T("未找到该引用。")).
  2935. "</a></div>";
  2936. return $s;
  2937. },
  2938. $ht
  2939. );
  2940. return $ht;
  2941. }
  2942. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  2943. $generate_thumbs=false, $hide_long = false){
  2944. $this->ConvertPost($post);
  2945. if($generate_anchor){ $this->CreatePostAnchor($post); }
  2946. $ht = $post['html'];
  2947. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  2948. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  2949. "<p class='bold'>".$post['product']['title']."</p>".
  2950. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  2951. "<p class='smaller bold'>".$post['product']['price']."</p>";
  2952. return $ht;
  2953. }
  2954. if($hide_long){
  2955. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  2956. }else{
  2957. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  2958. }
  2959. if ($strip_tags){
  2960. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  2961. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  2962. $ht = "<div class='post_ref_main'>".$ht."</div>";
  2963. }
  2964. else{
  2965. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  2966. }
  2967. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  2968. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  2969. foreach($post['images'] as $im){
  2970. $ht.="<li class='file_thumb'>".$im."</li>";
  2971. }
  2972. $ht.="</ul></div>";
  2973. }
  2974. return $ht;
  2975. }
  2976. function MakeSinglePostExp(&$post){ ?>
  2977. <li class='post post_dummy'>
  2978. <?=$this->GenerateSinglePost($post, false, false, true, false, false); ?>
  2979. </li>
  2980. <?php
  2981. }
  2982. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  2983. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  2984. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  2985. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  2986. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  2987. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  2988. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  2989. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  2990. $this->ConvertPost($post);// NEEDED FOR WIDE;
  2991. $is_wide = (isset($post['wide'])&&$post['wide']) || (isset($post['tid']) && isset($post['tid']['wide']) && $post['tid']['wide']);
  2992. ?>
  2993. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  2994. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>'
  2995. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  2996. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?>
  2997. <?=$is_wide?" style='column-span:all;'":"";?>>
  2998. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  2999. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  3000. <?php } ?>
  3001. <?php if($is_top){?>
  3002. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  3003. <?php }
  3004. if(!$side && !$strip_tags){?><div class='post_menu_button _menu_hook' >+</div><?php } ?>
  3005. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  3006. <div class='<?=$side?"":'post_width'?><?=$is_deleted?" deleted_post":""?>'>
  3007. <?php if($is_product&&!$generate_anchor){
  3008. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  3009. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  3010. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  3011. $generate_thumb,($show_thread_link||$side||$force_hide_long)); ?>
  3012. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  3013. </div>
  3014. <?=$side?"</a>":""?> <?php
  3015. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  3016. $post['tid']['first']['id']!=$post['id']){ ?>
  3017. <div class='gray smaller block opt_compact post'>
  3018. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  3019. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  3020. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  3021. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  3022. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true, true);?>
  3023. </div>
  3024. </div>
  3025. <?php }if(!$side && $show_link){ if($ref_count){ ?><?php } ?>
  3026. <a href='?post=<?=$post['id']?>' onclick="<?=$show_thread_link||isset($_GET['search'])?'ShowWaitingBar()':'ClickPost(this.parentNode,event,true)'?>">
  3027. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3028. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"")?>
  3029. </div>
  3030. </a><?php if($ref_count){ ?>
  3031. <label class='lb post_access' for='fake<?=$post["id"]?>'><div class='ref_count'><?=$ref_count?></div></label><?php }
  3032. }
  3033. if($show_reply_count && isset($post['tid'])){ ?>
  3034. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  3035. <?=$this->T('个回复')?></a>
  3036. <?php } if(!$strip_tags){
  3037. $this->MakeLinkedPosts($post);
  3038. } ?>
  3039. </li>
  3040. <?php
  3041. }
  3042. function MakePostingFields($reply_to=NULL, $show_hint=false){
  3043. if(isset($this->WayBack)){ ?>
  3044. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  3045. <?php return; } ?>
  3046. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  3047. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  3048. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  3049. <div id='post_hint_modify' style='display:none;'>
  3050. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  3051. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  3052. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  3053. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  3054. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3055. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3056. onclick='ShowWaitingBar();' />
  3057. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3058. <div style='float:right;'>
  3059. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3060. <?=$this->T('清空')?></a>
  3061. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3062. </div>
  3063. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3064. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3065. <?php if($reply_to){ ?>
  3066. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3067. <?php } ?>
  3068. <?php
  3069. }
  3070. function MakeCommentPosts(){
  3071. if(!$this->LoggedIn) return; ?>
  3072. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3073. <?php if(!$this->CommentEnabled){
  3074. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3075. <div class='comment'><ul>
  3076. <?php $i=0;
  3077. foreach(array_reverse($this->Posts) as $p){
  3078. if(!isset($p['comment_to'])) continue;
  3079. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3080. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3081. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3082. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3083. if(!$post_to) $post_title = "?";
  3084. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3085. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3086. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3087. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3088. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3089. $i++;
  3090. }
  3091. ?>
  3092. </ul><br /></div>
  3093. <?php
  3094. }
  3095. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  3096. <div class='center' id='div_center'>
  3097. <h2><?=isset($search_term)?$this->T('搜索'):
  3098. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3099. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3100. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3101. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  3102. <?php if(isset($search_term)){ ?>
  3103. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  3104. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3105. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3106. <?php }else if(isset($category)){ ?>
  3107. <div></div>
  3108. <?php }else if($this->LoggedIn){ ?>
  3109. <div class='post_box_top _input_bundle'>
  3110. <?php $this->MakePostingFields(NULL,false); ?>
  3111. </div>
  3112. <?php } ?>
  3113. <ul class='print_column list bkg_recent'>
  3114. <?php
  3115. if(!isset($search_term) && !isset($category) &&
  3116. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3117. $this->CanShowPost($p)){
  3118. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  3119. }
  3120. $i = 0; $last_end_wide = true;
  3121. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3122. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3123. if(isset($p['tid'])){ /* Should always be set. */
  3124. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3125. if(!isset($search_term)) { $p = &$th['last']; }
  3126. }
  3127. if(isset($search_term)){
  3128. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3129. }else if(isset($category)){
  3130. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3131. (isset($p['categories'])?($p['categories']):[]);
  3132. if ($category=='none') { if($cat!=[]) continue; }
  3133. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3134. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3135. }else{
  3136. if(in_array($p['id'],
  3137. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  3138. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3139. }
  3140. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3141. if($last_end_wide){$use_class="last_wide";}else{$use_class="";}
  3142. $this->MakeSinglePost($p, true, false, $use_class, false, !isset($search_term), false, false, false, false, isset($search_term));
  3143. $i++;
  3144. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3145. $last_end_wide = sizeof($p['tid']['arr'])==1 && isset($p['end_wide']) && $p['end_wide'];
  3146. }?>
  3147. </ul>
  3148. <div class='page_selector clean_a'>
  3149. <hr />
  3150. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  3151. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3152. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3153. <?=$this->CurrentOffset+1?>
  3154. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  3155. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3156. → <?=$this->T('下一页')?></a>
  3157. </div>
  3158. </div>
  3159. <?php
  3160. }
  3161. function MakeLinkedPosts(&$p){
  3162. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); if(!$has_ref)return; $count=0;?>
  3163. <input type='checkbox' class='lpctrl' id='fake<?=$p["id"]?>' checked='checked'>
  3164. <div class='linked_posts smaller'>
  3165. <ul><?php $count_product=0;
  3166. foreach(array_reverse($p['refs']) as &$pr){
  3167. $po = $this->GetPost($pr);
  3168. if(!$this->CanShowPost($po)){ continue; } $count++;
  3169. $this->MakeSinglePost($po, false, true, "post_preview invert_a", true, false, false, false, true, false, false);
  3170. }
  3171. ?></ul>
  3172. </div>
  3173. <?php
  3174. }
  3175. function MakeLinkedPostsExp(&$p){
  3176. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3177. <div class='center_exp post_dummy smaller'>
  3178. <hr />
  3179. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3180. <?php
  3181. if($has_ref){ ?>
  3182. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3183. <ul><?php $count_product=0;
  3184. foreach(array_reverse($p['refs']) as &$pr){
  3185. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3186. "</a></li>";
  3187. }
  3188. ?></ul>
  3189. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3190. }else{ ?>
  3191. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3192. <?php } ?>
  3193. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3194. </div>
  3195. <?php
  3196. }
  3197. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3198. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3199. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3200. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3201. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3202. if(!isset($title)) $title=$this->T('未命名');
  3203. if(!isset($ah)){ ?>
  3204. <h2><?=$this->T('没有历史记录')?></h2>
  3205. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3206. <?php }else{ ?>
  3207. <h2><?=$this->T('历史记录')?></h2>
  3208. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3209. <div class='list'><ul>
  3210. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3211. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3212. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3213. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3214. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3215. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3216. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3217. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3218. <?=$this->GetPostTitle($ver);?></a>
  3219. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3220. <?php } ?></ul><?php } ?>
  3221. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3222. $mah = &$this->GetArchiveHandle($pm);
  3223. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3224. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3225. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3226. <?php } ?>
  3227. </li><?php } ?>
  3228. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3229. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3230. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3231. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3232. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3233. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3234. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3235. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3236. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3237. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3238. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3239. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3240. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3241. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3242. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3243. <?=$this->GetPostTitle($ver);?></a>
  3244. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3245. <?php } ?></ul></li><?php } ?>
  3246. <?php } ?></ul></div>
  3247. <?php } ?>
  3248. <?php
  3249. }
  3250. function MakePostDiff(&$this_ver, &$last_ver){
  3251. if(!isset($this_ver)){ ?>
  3252. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3253. <?php }else{ ?>
  3254. <h2><?=$this->T('差异')?></h2>
  3255. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3256. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3257. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3258. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3259. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3260. <?php }else{ ?>
  3261. <table class='diff_table'><thead>
  3262. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3263. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3264. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3265. </thead><tbody>
  3266. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3267. </tbody>
  3268. </table>
  3269. <?php } ?>
  3270. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3271. <?php } ?>
  3272. <?php
  3273. }
  3274. function MakePostHistory(&$post, $version=NULL){
  3275. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3276. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3277. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3278. ?>
  3279. <div class='left mobile_fold history' id='div_left'>
  3280. <?php if (isset($version)){
  3281. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3282. }else{ echo "&nbsp;"; } ?>
  3283. </div>
  3284. <div class='center history' id='div_center'>
  3285. <?php if (!isset($version)){
  3286. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3287. }else{
  3288. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3289. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3290. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3291. $this->MakePostDiff($this_ver, $last_ver, $p);
  3292. } ?>
  3293. </div>
  3294. <?php
  3295. }
  3296. function MakeCommentSection(&$post){
  3297. if(!$this->CommentEnabled){ return; }
  3298. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3299. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3300. ?><div class='comment'>
  3301. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3302. <?php if($comment_count) { echo "<ul>";
  3303. foreach($to_post['comments'] as $p){
  3304. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3305. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3306. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3307. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3308. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3309. }
  3310. echo "</ul>";
  3311. } else {
  3312. echo $this->T('还没有评论');
  3313. } ?>
  3314. <div class='hidden_on_print'>
  3315. <div class='spacer'></div>
  3316. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3317. method="post" style="display:none;" id="comment_form"></form>
  3318. <p><a class='text_highlight bold clean_a'
  3319. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3320. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3321. <div id='comment_box' style='display:none;'>
  3322. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3323. <table style='white-space:nowrap;'>
  3324. <tr><td colspan='2'>
  3325. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3326. oninput="CommentUpdated();" ></textarea>
  3327. </td></tr>
  3328. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3329. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3330. class='full_box' oninput="CommentUpdated();" /></td>
  3331. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3332. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3333. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3334. <tr><td colspan='2'>
  3335. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3336. class='full_box' oninput="CommentUpdated();" />
  3337. </td></tr>
  3338. <tr><td colspan='2'>
  3339. <div class='spacer'></div>
  3340. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3341. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3342. </td></tr>
  3343. </table></div>
  3344. <script>
  3345. const IsValidEmail = (email) => {
  3346. 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,}))$/);
  3347. };
  3348. function IsValidHttpUrl(string) {
  3349. let url; try{ url = new URL(string); } catch (_) { return false; }
  3350. return url.protocol === "http:" || url.protocol === "https:";
  3351. }
  3352. var cbox = document.getElementById('comment_box');
  3353. var cemail = document.getElementById('comment_email');
  3354. var cname = document.getElementById('comment_name');
  3355. var clink = document.getElementById('comment_link');
  3356. var cconfirm = document.getElementById('comment_confirm');
  3357. function CommentUpdated(){
  3358. cconfirm.disabled=true;
  3359. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3360. cbox.innerText.length>2 && cname.value.length>2 &&
  3361. clink.value=="" || IsValidHttpUrl(clink.value)){
  3362. cconfirm.removeAttribute("disabled");
  3363. }
  3364. }
  3365. CommentUpdated();
  3366. </script>
  3367. </div>
  3368. </div>
  3369. <?php
  3370. }
  3371. function MakeInterestingSection(&$th){
  3372. $this->Anchors = [];
  3373. $c = &$th['first']['content'];
  3374. $this->ConvertPost($th['first']);
  3375. $ht = $th['first']['html'];
  3376. ?>
  3377. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3378. <div class='center_full' id='div_center'>
  3379. <?php $this->MakePostTools(); ?>
  3380. <?php $cat = NULL;
  3381. if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; }
  3382. if($cat){ ?>
  3383. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3384. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3385. <?php } ?>
  3386. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3387. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3388. <ul><li class='post' data-post-id='<?=$th['first']['id']?>'>
  3389. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3390. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3391. <?php foreach($th['first']['refs'] as $ref){
  3392. $po = $this->GetPost($ref);
  3393. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3394. if(!$this->CanShowPost($po)){ continue; }
  3395. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3396. } ?>
  3397. </ul><?php } ?>
  3398. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3399. <div class='hidden_on_print'><br />
  3400. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3401. </div>
  3402. <?php } ?>
  3403. <table><thead><tr><?php foreach($th['interesting'] as $header){ ?>
  3404. <td><?=$this->T($header);?></td>
  3405. <?php } ?><td></td></tr></thead><tbody class='interesting_tbody'>
  3406. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3407. foreach($plist as &$p){
  3408. $this->ConvertPost($p);
  3409. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3410. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3411. $is_current = $p['id']==$this->CurrentPostID;
  3412. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3413. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3414. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3415. onDblClick='ClickImage(this)'><td>
  3416. <?php if($ref_count){ ?>
  3417. <div class='post_access ref_count'><?=$ref_count?></div>
  3418. <?php } ?></a>
  3419. <?=$p['html'];?>
  3420. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a>
  3421. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3422. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3423. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3424. </div></td></tr>
  3425. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3426. <?php foreach($p['refs'] as $ref){
  3427. $po = $this->GetPost($ref);
  3428. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3429. if(!$this->CanShowPost($po)){ continue; }
  3430. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3431. } ?>
  3432. </ul></td></tr><?php } ?>
  3433. <?php } ?>
  3434. </tbody></table>
  3435. </li></ul>
  3436. <br />
  3437. <?php $this->MakeCommentSection($th['first']); ?>
  3438. </div>
  3439. <?php return true;
  3440. }
  3441. function CssNumberID($id){
  3442. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3443. }
  3444. function MakePostTools(){
  3445. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3446. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3447. <?=$this->T('工具')?></a>:<div class='hidden_m' style='display:inline'>
  3448. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3449. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3450. </div>
  3451. <select class='hidden_on_desktop' id='merge_select'
  3452. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3453. <option value='-1' selected>--</option>
  3454. <option value='1'><?=$this->T('合并帖子')?></option>
  3455. <option value='2'><?=$this->T('合并话题')?></option></select>
  3456. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3457. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3458. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3459. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3460. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3461. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3462. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3463. </div><div class='spacer hidden_on_print'></div><?php
  3464. }
  3465. }
  3466. function MakeSidebar(){ ?>
  3467. <div class='left mobile_fold'><?php if(isset($this->SpecialSidebar) && ($p = &$this->GetPost($this->SpecialSidebar))!=NULL){
  3468. ?><span class='gray smaller'><br /></span><?php
  3469. echo $this->GenerateSinglePost($p, false, false, false, false); }?>
  3470. <div class='wayback_link clean_a smaller'><span class='gray'><br /><?=$this->T('工具')?></span><ul>
  3471. <li><a href='?search=' onclick='ShowWaitingBar()' class='bigger'><?=$this->T('搜索')?></a></li>
  3472. <li><?php if(!isset($this->WayBack)){ ?>
  3473. <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  3474. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?></li>
  3475. <li><a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  3476. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a></li>
  3477. <li><a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a></li>
  3478. <?php if($this->LanguageAppendix=='zh'){ ?>
  3479. <li class='smaller'>
  3480. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  3481. <?php }else { ?>
  3482. <li class='smaller'>
  3483. <a href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  3484. 汉语/<b>English</b></a>
  3485. <br class='hidden_on_desktop' />
  3486. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  3487. <?php } ?></ul>
  3488. </div>
  3489. </div>
  3490. <?php }
  3491. function MakePostSection(&$post){
  3492. $this->Anchors = [];
  3493. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3494. <div class='center' id='div_center'>
  3495. <h2 class='hidden_on_print'>
  3496. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1;
  3497. $is_wide = (isset($post['wide'])&&$post['wide']) || ($is_thread && isset($post['tid']['wide']) && $post['tid']['wide']);
  3498. if($is_thread){ $th = $post['tid'];?> <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3499. <?php } ?></h2>
  3500. <?php $cat = NULL;
  3501. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3502. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3503. $this->MakePostTools();
  3504. if($cat){ ?>
  3505. <p class='hidden_on_print'><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3506. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3507. <?php } ?>
  3508. <ul class='print_column bkg_section'>
  3509. <?php $is_reversed=false;
  3510. if($is_thread){
  3511. $use_arr = $th['arr']; $hinted=false;
  3512. $last_end_wide = true; $is_reversed=$this->IsReversedThread($th);
  3513. foreach($use_arr as &$p){$use_class="";if($p==$post){$use_class.=" active_post";}
  3514. if($last_end_wide){$use_class.=" last_wide";}
  3515. $make_title = ($p == $post);
  3516. if(isset($p['restart'])){ ?>
  3517. <li class='restart'><h3><?=$p['restart']?></h3></li><?php }
  3518. $this->MakeSinglePost($p,true,false,$use_class,false, false, false, true, false, false);
  3519. if($make_title){?>
  3520. <script>
  3521. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3522. </script>
  3523. <?php } if($is_reversed && !$hinted){ ?><?php $hinted = true;
  3524. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3525. <div class='hidden_on_print'>
  3526. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3527. <?php } }
  3528. $last_end_wide = isset($p['end_wide']) && $p['end_wide'];
  3529. }
  3530. }else{
  3531. $this->MakeSinglePost($post,true, false,"active_post",false, false, false, true, false, false);
  3532. ?><script>
  3533. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3534. </script><?php
  3535. } $class_add=""; if(isset($post['tid']['first']['no_time'])){ $class_add=' hidden_on_print'; } ?>
  3536. </ul>
  3537. <div class='smaller align_right<?=$class_add;?>'>
  3538. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3539. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3540. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3541. </div>
  3542. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  3543. <div class='hidden_on_print'>
  3544. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3545. </div>
  3546. <?php }
  3547. $this->MakeCommentSection($post);
  3548. ?>
  3549. </div>
  3550. <?php
  3551. }
  3552. function MakePostSectionExp(&$post){
  3553. $this->Anchors = []; $is_thread = isset($post['tid']);
  3554. ?>
  3555. <div class='center_exp' id='div_center'>
  3556. <ul>
  3557. <?php $is_reversed=false;
  3558. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false;
  3559. foreach($use_arr as &$p){
  3560. $this->MakeSinglePostExp($p);
  3561. if($p == $th['first']){?>
  3562. <script>
  3563. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3564. </script>
  3565. <?php } if($is_reversed && !$hinted){ ?>
  3566. <li class='gray smaller bold' style='text-align:center;'>
  3567. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3568. <?php $hinted = true; }
  3569. }
  3570. }else{
  3571. $this->MakeSinglePostExp($post);
  3572. ?><!--<script>
  3573. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3574. </script>--><?php
  3575. } ?>
  3576. </ul>
  3577. </div>
  3578. <?php
  3579. }
  3580. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  3581. <div class='here_image_box clean_a'>
  3582. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  3583. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  3584. <?php if($image_okay){ ?>
  3585. <?php if(isset($im['video']) && isset($im['video'])!=""){ ?>
  3586. <video controls><source src='<?=$im['file'];?>' type='<?=$im['video']?>'></video>
  3587. <?php }else{ ?>
  3588. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  3589. <?php } ?>
  3590. <?php } $this->MakeHereButtons($im, false); ?>
  3591. </div>
  3592. <?php }
  3593. function MakeSideGalleryCode(){?>
  3594. <div>
  3595. <h3><?=$this->T('点击图片以插入:')?></h3>
  3596. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3597. <option value="main"><?=$this->T('全部')?></option>
  3598. <?php if($this->LoggedIn){ ?>
  3599. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3600. <?php }?>
  3601. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3602. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3603. <?php } ?>
  3604. </select>
  3605. <div id='side_gallery'>
  3606. </div>
  3607. </div>
  3608. <script>
  3609. function InsertImage(imgname){
  3610. t = document.querySelector("#post_content");
  3611. v = t.value;
  3612. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3613. la_auto_grow(t);
  3614. }
  3615. function RefreshSideGallery(){
  3616. let xhr = new XMLHttpRequest();
  3617. xhr.onreadystatechange = (function(){
  3618. if (this.readyState === this.DONE) {
  3619. if (this.status === 200) {
  3620. ind = document.querySelector("#side_gallery");
  3621. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3622. str = "<ul class='side_thumb'>"
  3623. for (const m of res) {
  3624. imgstr = "<img src='"+m[2]+"' />";
  3625. if(m[2].match('\.mp4')){
  3626. imgstr = "<video><source src='"+m[2]+"'></video>";
  3627. }
  3628. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+imgstr+"</div>"
  3629. }
  3630. str += "</ul>"
  3631. ind.innerHTML = str;
  3632. }
  3633. }
  3634. }
  3635. });
  3636. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3637. xhr.send();
  3638. }
  3639. </script>
  3640. <?php
  3641. }
  3642. function MakeUploader($is_side=false){ ?>
  3643. <div id='upload_operation_area' class='hidden_on_print'>
  3644. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3645. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3646. <ul id='file_list'>
  3647. </ul>
  3648. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3649. </div>
  3650. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3651. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3652. <script>
  3653. function pastehandler(event){
  3654. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3655. for (index in items) {
  3656. var item = items[index];
  3657. if (item.kind === 'file') {
  3658. put = document.querySelector("#_uploader");
  3659. if(put) ShowSideUploader();
  3660. var blob = item.getAsFile();
  3661. AddImageFile(blob);
  3662. return;
  3663. }
  3664. }
  3665. }
  3666. let _fd_list = []; var uploading=0;
  3667. let hint=document.querySelector('#upload_hint');
  3668. function ToggleCompress(button){
  3669. li = button.parentNode;
  3670. num=li.dataset.number;
  3671. for(i=0;i<_fd_list.length;i++){
  3672. if (_fd_list[i][0] == num){
  3673. state = _fd_list[i][2];
  3674. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3675. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3676. }
  3677. }
  3678. }
  3679. function RemoveFromUpload(button){
  3680. li = button.parentNode;
  3681. num=li.dataset.number;
  3682. for(i=0;i<_fd_list.length;i++){
  3683. if (_fd_list[i][0] == num){
  3684. _fd_list.splice(i, 1);break;
  3685. }
  3686. }
  3687. li.parentNode.removeChild(li);
  3688. }
  3689. function EndThisUpload(){
  3690. unfinished = 0;
  3691. for(i=0;i<_fd_list.length;i++){
  3692. if (_fd_list[i][3]==0){
  3693. unfinished=1;
  3694. }
  3695. }
  3696. if(!unfinished){
  3697. uploading=0;
  3698. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3699. cl=document.querySelector('#upload_click');
  3700. if(!cl.dataset.isSide){
  3701. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3702. cl.href=window.location.href;
  3703. }else{
  3704. _fd_list.splice(0,_fd_list.length);
  3705. fl = document.querySelector("#file_list");
  3706. fl.innerHTML = "";
  3707. list=document.querySelector('#upload_operation_area');
  3708. list.style.pointerEvents='';
  3709. list.style.opacity='';
  3710. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3711. document.onpaste=pastehandler;
  3712. RefreshSideGallery();
  3713. }
  3714. }
  3715. }
  3716. function UploadList(){
  3717. if(!_fd_list.length || uploading) return;
  3718. uploading=1;
  3719. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3720. list=document.querySelector('#upload_operation_area');
  3721. list.style.pointerEvents='none';
  3722. list.style.opacity='0.5';
  3723. document.onpaste="";
  3724. for(i=0;i<_fd_list.length;i++){
  3725. let xhr = new XMLHttpRequest();
  3726. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3727. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3728. function wrap(li, i){
  3729. var ind = li.querySelector('._compress_toggle')
  3730. return function(){
  3731. if (this.readyState === this.DONE) {
  3732. if (this.status === 200) {
  3733. var response = xhr.responseText;
  3734. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3735. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3736. _fd_list[i][3] = 1;
  3737. }else{
  3738. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3739. _fd_list[i][3] = 1;
  3740. }
  3741. EndThisUpload();
  3742. }
  3743. }
  3744. }
  3745. }
  3746. xhr.onreadystatechange = wrap(li, i);
  3747. xhr.send(_fd_list[i][1]);
  3748. }
  3749. }
  3750. function AddImageFile(blob){
  3751. var ext="";
  3752. if(blob.name.match(/png$/))ext = 'png';
  3753. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3754. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3755. else if(blob.name.match(/gif$/))ext = 'gif';
  3756. else if(blob.name.match(/mp4$/))ext = 'mp4';
  3757. else return;
  3758. var fd = new FormData();
  3759. blob.name = blob.name=generateUID().toString();
  3760. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3761. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3762. var reader = new FileReader();
  3763. reader.onload = function(event){
  3764. fl = document.querySelector("#file_list");
  3765. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3766. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3767. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3768. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3769. fl.innerHTML+=ht;
  3770. };
  3771. reader.readAsDataURL(blob);
  3772. }
  3773. sel = document.querySelector('#upload_selector');
  3774. sel.addEventListener("change", function(){
  3775. var input = this;
  3776. function ff(file){
  3777. return function(e){
  3778. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3779. blob.name = file.name;
  3780. AddImageFile(blob);
  3781. }
  3782. }
  3783. for(i=0;i<input.files.length;i++){
  3784. if(input.files[i].size){
  3785. let reader = new FileReader();
  3786. reader.onload = ff(input.files[i]);
  3787. reader.readAsArrayBuffer(input.files[i]);
  3788. }
  3789. }
  3790. });
  3791. function generateUID() {
  3792. var firstPart = (Math.random() * 46656) | 0;
  3793. var secondPart = (Math.random() * 46656) | 0;
  3794. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3795. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3796. return firstPart + secondPart;
  3797. }
  3798. document.onpaste = pastehandler;
  3799. function dropHandler(ev) {
  3800. put = document.querySelector("#_uploader");
  3801. if(put) ShowSideUploader();
  3802. bkg=document.querySelector('#dropping_background');
  3803. bkg.style.display="none";
  3804. console.log('File(s) dropped');
  3805. ev.preventDefault();ev.stopPropagation();
  3806. if (ev.dataTransfer && ev.dataTransfer.items) {
  3807. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3808. if (ev.dataTransfer.items[i].kind === 'file') {
  3809. var file = ev.dataTransfer.items[i].getAsFile();
  3810. function ff(file){
  3811. return function(e){
  3812. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3813. blob.name = file.name;
  3814. AddImageFile(blob);
  3815. }
  3816. }
  3817. if(file){
  3818. let reader = new FileReader();
  3819. reader.onload = ff(file);
  3820. reader.readAsArrayBuffer(file);
  3821. }
  3822. }
  3823. }
  3824. } else {
  3825. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3826. function ff(file){
  3827. return function(e){
  3828. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3829. blob.name = file.name;
  3830. AddImageFile(blob);
  3831. }
  3832. }
  3833. if(ev.dataTransfer.files[i].size){
  3834. let reader = new FileReader();
  3835. reader.onload = ff(ev.dataTransfer.files[i]);
  3836. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3837. }
  3838. }
  3839. }
  3840. }
  3841. function dragOverHandler(ev) {
  3842. bkg=document.querySelector('#dropping_background');
  3843. bkg.style.display="";
  3844. console.log('File(s) in drop zone');
  3845. ev.preventDefault();
  3846. }
  3847. </script>
  3848. <?php
  3849. }
  3850. function CanShowGallery(&$g){
  3851. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  3852. return true;
  3853. }
  3854. function CanShowImage(&$im){
  3855. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3856. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3857. }
  3858. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3859. return true;
  3860. }
  3861. function GetImageBatch($from,$show_all){
  3862. if(!isset($_GET['gallery'])) return;
  3863. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){$name=$_GET['gallery'];}
  3864. $reached=0; $count=0;
  3865. if(isset($this->Images[0])) foreach($this->Images as $im){
  3866. if(isset($from)&&!$reached){ if($from==$im['name']){ $reached=1; } continue; }
  3867. if(!$this->CanShowImage($im)){ continue; }
  3868. if($_GET['gallery']=='trash') $name='trash';
  3869. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;} ?>
  3870. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  3871. <?php if($this->LoggedIn){ ?>
  3872. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3873. <?php } ?>
  3874. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  3875. <?php if(isset($im['video']) && $im['video']!=""){ ?>
  3876. <video data-imgsrc='<?=$im["name"]?>'><source src='<?=$im['file']?>' type='<?=$im['video']?>'></video>
  3877. <?php }else{ ?>
  3878. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  3879. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  3880. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>
  3881. <?=isset($im['align'])?'data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':""?>/>
  3882. <?php } ?>
  3883. </a>
  3884. </div>
  3885. <?php $count+=isset($im['parent'])?0:1; if((!$show_all)&&($count>=$this->GalleryStep)){ break; }
  3886. }
  3887. if($count<$this->GalleryStep){ ?><div style='display:none'>END_GALLERY</div><?php return 0; }
  3888. return 1;
  3889. }
  3890. function MakeGallerySection(){
  3891. if(!isset($_GET['gallery'])) return;
  3892. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3893. $name=$_GET['gallery'];}
  3894. $show_all=0; if(isset($_GET['show_all']) && $_GET['show_all']!='0'){ $show_all=1; } ?>
  3895. <script>
  3896. document.title+=" | <?=$this->T('画廊')?>";
  3897. </script>
  3898. <div class='center_wide' id='div_center' style='position:relative;'>
  3899. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3900. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3901. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3902. <div class='hidden_on_desktop'>
  3903. <?=$this->T('前往')?>
  3904. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  3905. <optgroup label="<?=$this->T('精选')?>">
  3906. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3907. if(!isset($g['featured']) || !$g['featured'] ||
  3908. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3909. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3910. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3911. <?php } ?></optgroup><optgroup label="<?=$this->T('其他相册')?>">
  3912. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  3913. <?php if($this->LoggedIn){ ?>
  3914. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  3915. <?php } ?>
  3916. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3917. if((isset($g['featured']) && $g['featured']) ||
  3918. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3919. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3920. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3921. <?php } ?></optgroup>
  3922. </select>
  3923. </div>
  3924. <?php if($this->LoggedIn){?>
  3925. <div>
  3926. <?php if(isset($name)){ ?>
  3927. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  3928. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  3929. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  3930. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  3931. <?=$this->T('取消精选')?></a>
  3932. <?php }else{ ?>
  3933. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  3934. <?=$this->T('设为精选')?></a>
  3935. <?php } ?><br />
  3936. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  3937. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  3938. <?=$this->T('取消实验')?></a>
  3939. <?php }else{ ?>
  3940. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  3941. <?=$this->T('设为实验')?></a>
  3942. <?php } ?>
  3943. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  3944. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  3945. <a href='javascript:HidePopMenu();'>×</a>
  3946. <hr />
  3947. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  3948. </div>
  3949. </div>
  3950. <?php } ?>
  3951. <?php $this->MakeUploader(false); ?>
  3952. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  3953. <div style='position:relative'>
  3954. <?php if(isset($name)){ ?>
  3955. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  3956. <?php } ?>
  3957. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  3958. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  3959. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  3960. method="post" style='display:none;' id='gallery_edit_form'></form>
  3961. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  3962. <a href='javascript:HidePopMenu();'>×</a>
  3963. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  3964. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  3965. <input class='button' type='submit' form='gallery_edit_form'
  3966. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  3967. </div>
  3968. </div>
  3969. </div>
  3970. <div class='smaller hidden_on_print'>
  3971. <form action="<?=$_SERVER['REQUEST_URI']?>"
  3972. method="post" style='display:none;' id='gallery_move_form'></form>
  3973. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  3974. id='gallery_move_ops' style='display:none'>
  3975. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  3976. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  3977. <p><?=$this->T('添加到')?>
  3978. <select id="gallery_move_to">
  3979. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3980. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3981. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  3982. <?php } ?>
  3983. </select>
  3984. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  3985. </p>
  3986. <p>
  3987. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  3988. </p>
  3989. </div>
  3990. </div>
  3991. <?php } ?>
  3992. <p>&nbsp;</p>
  3993. <div><div class='p_row'><?php $has_more=$this->GetImageBatch(NULL, $show_all);?>
  3994. <div class='p_thumb p_thumb_end' <?=$has_more?"onclick='ThisGetMore(this);'":""?>>
  3995. <a onclick='event.preventDefault();' href='index.php?gallery=<?=$_GET['gallery']?>&show_all=1'>
  3996. <h2 id="btn_more_images"><?=$has_more?$this->T("查看更多"):$this->T("没有更多的了");?></a></h2></div></div>
  3997. </div>
  3998. </div>
  3999. <script type='text/javascript'>
  4000. function ThisGetMore(end_ui){
  4001. var xhr = new XMLHttpRequest();
  4002. xhr.onreadystatechange = function() {
  4003. if (this.readyState == 4 && this.status == 200) {
  4004. doc = document.createElement("div"); doc.innerHTML=xhr.responseText.trim(); next_child=null;
  4005. for(child=doc.firstChild; child!==null; child=next_child) { next_child=child.nextSibling; end_ui.parentNode.insertBefore(child,end_ui); }
  4006. doc.remove();
  4007. if(xhr.responseText.search('END_GALLERY')>=0){ end_ui.onclick=null; end_ui.innerHTML="<h2><?=$this->T("没有更多的了");?></h2>"; }
  4008. UpdateImageClickables();
  4009. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("查看更多");?>";
  4010. }
  4011. };
  4012. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("稍等");?>";
  4013. im=end_ui.previousElementSibling.querySelector('img,video');
  4014. from=im?im.dataset.imgsrc:null; if(!from) return;
  4015. const urlParams = new URLSearchParams(window.location.search); const gallery = urlParams.get('gallery')
  4016. xhr.open("GET", "index.php?gallery_continue="+from+'&gallery='+gallery, true);
  4017. xhr.send();
  4018. }
  4019. <?php if($this->LoggedIn){ ?>
  4020. var selected_image = new Array();
  4021. function RemoveFromGallery(){
  4022. form = document.querySelector('#gallery_move_form');
  4023. ops = document.querySelector('#gallery_move_ops');
  4024. sel = document.querySelector('#gallery_move_to');
  4025. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  4026. form.submit();
  4027. }
  4028. function AddToGallery(){
  4029. form = document.querySelector('#gallery_move_form');
  4030. ops = document.querySelector('#gallery_move_ops');
  4031. sel = document.querySelector('#gallery_move_to');
  4032. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  4033. form.submit();
  4034. }
  4035. function ClearSelectedImages(){
  4036. selected_image.splice(0, selected_image.length);
  4037. checks = document.querySelectorAll('._select_hook');
  4038. [].forEach.call(checks, function(c){
  4039. c.classList.remove('p_thumb_selected');
  4040. });
  4041. count = document.querySelector('#gallery_selected_count');
  4042. count.innerHTML="0";
  4043. }
  4044. function ToggleSelectImage(elem, name){
  4045. count = document.querySelector('#gallery_selected_count');
  4046. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  4047. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  4048. count.innerHTML=selected_image.length.toString()
  4049. }
  4050. function ShowGalleryEditMenu(old_name){
  4051. m = document.querySelector('#gallery_edit_menu');
  4052. old = document.querySelector('#gallery_edit_old_name');
  4053. newname = document.querySelector('#gallery_edit_new_name');
  4054. m.style.display='block';
  4055. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  4056. }
  4057. function ShowDeleteMenu(){
  4058. m=document.querySelector('#gallery_delete_menu');
  4059. m.style.display='block';
  4060. }
  4061. <?php } ?>
  4062. </script>
  4063. <?php
  4064. }
  4065. function MakeGalleryLeft(){?>
  4066. <div class='left hidden_m gallery_left' id='div_left'>
  4067. <h2><?=$this->T('相册')?></h2>
  4068. <div>
  4069. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  4070. <ul>
  4071. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4072. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  4073. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4074. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  4075. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4076. <?php } ?>
  4077. </ul>
  4078. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  4079. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  4080. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  4081. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4082. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  4083. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4084. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  4085. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4086. <?php } ?>
  4087. <?php if($this->LoggedIn){ ?>
  4088. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  4089. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  4090. <?php } ?>
  4091. </ul></div>
  4092. <p>&nbsp;</p>
  4093. <script>
  4094. </script>
  4095. </div>
  4096. </div>
  4097. <?php
  4098. }
  4099. function MakeSettings(){?>
  4100. <div class='settings'>
  4101. <h2><?=$this->T('设置')?></h2>
  4102. <table style='white-space:nowrap;'>
  4103. <?php if($this->LoggedIn){ ?>
  4104. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4105. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4106. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4107. <tr><td><?=$this->T('网站标题')?></td>
  4108. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4109. value='<?=$this->Title?>'/></td></tr>
  4110. <tr><td><?=$this->T('短标题')?></td>
  4111. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4112. value='<?=$this->ShortTitle?>'/></td></tr>
  4113. <tr><td><?=$this->T('显示名称')?></td>
  4114. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4115. value='<?=$this->DisplayName?>'/></td></tr>
  4116. <tr><td><?=$this->T('电子邮件')?></td>
  4117. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4118. value='<?=$this->EMail?>'/></td></tr>
  4119. <tr><td><?=$this->T('导航栏')?>
  4120. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4121. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4122. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4123. <tr><td><?=$this->T('侧边栏')?>
  4124. <?=isset($this->SpecialSidebar)?"<a href='?post=".$this->SpecialSidebar."'>→</a>":""?></td>
  4125. <td><input type="text" form="settings_form" id='settings_special_sidebar' name='settings_special_sidebar'
  4126. value='<?=$this->SpecialSidebar?>'/></td></tr>
  4127. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4128. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4129. value='<?=$this->SpecialFooter?>'/></td></tr>
  4130. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4131. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4132. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4133. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4134. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4135. value='<?=$this->SpecialPinned?>'/></td></tr>
  4136. <tr><td><?=$this->T('默认相册')?></td>
  4137. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4138. value='<?=$this->DefaultGallery?>'/></td></tr>
  4139. <tr><td><?=$this->T('相册单步')?></td>
  4140. <td><input type="text" form="settings_form" id='settings_gallery_step' name='settings_gallery_step'
  4141. value='<?=$this->GalleryStep?>'/></td></tr>
  4142. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4143. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4144. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4145. <tr><td><?=$this->T('启用评论')?></td>
  4146. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4147. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4148. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  4149. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4150. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4151. <tr><td><?=$this->T('长毛象实例')?></td>
  4152. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4153. value='<?=$this->MastodonURL?>'/></td></tr>
  4154. <tr><td><?=$this->T('长毛象令牌')?></td>
  4155. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4156. value='<?=$this->MastodonToken?>'/></td></tr>
  4157. <tr><td><?=$this->T('偏好语言')?></td>
  4158. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4159. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4160. <tr><td><?=$this->T('本站地址')?></td>
  4161. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4162. value='<?=$this->HostURL?>'/></td></tr>
  4163. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4164. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4165. <tr><td><?=$this->T('用户名')?></td>
  4166. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4167. value='<?=$this->APubID?>'/></td></tr>
  4168. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4169. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4170. <tr><td><?=$this->T('主机')?></td>
  4171. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4172. value='<?=$this->HereHost?>'/></td></tr>
  4173. <tr><td><?=$this->T('网站标题')?></td>
  4174. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4175. value='<?=$this->HereTitle?>'/></td></tr>
  4176. <tr><td><?=$this->T('短标题')?></td>
  4177. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4178. value='<?=$this->HereShortTitle?>'/></td></tr>
  4179. <tr><td><?=$this->T('相册')?></td>
  4180. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4181. value='<?=$this->HereAlbum?>'/></td></tr>
  4182. <tr><td><?=$this->T('导航栏')?>
  4183. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4184. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4185. value='<?=$this->HereNavigation?>'/></td></tr>
  4186. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4187. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4188. value='<?=$this->HereFooter?>'/></td></tr>
  4189. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4190. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4191. <tr><td><?=$this->T('主机')?></td>
  4192. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4193. value='<?=$this->ExpHost?>'/></td></tr>
  4194. <tr><td><?=$this->T('网站标题')?></td>
  4195. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4196. value='<?=$this->ExpTitle?>'/></td></tr>
  4197. <tr><td><?=$this->T('短标题')?></td>
  4198. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4199. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4200. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4201. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4202. value='<?=$this->ExpCaution?>'/></td></tr>
  4203. <tr><td><?=$this->T('相册')?></td>
  4204. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4205. value='<?=$this->ExpAlbum?>'/></td></tr>
  4206. <tr><td><?=$this->T('导航栏')?>
  4207. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4208. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4209. value='<?=$this->ExpNavigation?>'/></td></tr>
  4210. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4211. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4212. value='<?=$this->ExpFooter?>'/></td></tr>
  4213. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4214. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4215. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  4216. <tr><td><?=$this->T('帐号')?></td>
  4217. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4218. value='<?=$this->Admin?>'/></td></tr>
  4219. <tr><td><?=$this->T('新密码')?></td>
  4220. <td><input type="password" form="settings_form"
  4221. id='settings_new_password' name='settings_new_password' /></td></tr>
  4222. <tr><td><?=$this->T('再次输入')?></td>
  4223. <td><input type="password" form="settings_form"
  4224. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4225. <tr><td><?=$this->T('旧密码')?></td>
  4226. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4227. <?php }else{ ?>
  4228. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4229. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4230. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4231. <tr><td><?=$this->T('帐号')?></td>
  4232. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4233. <tr><td><?=$this->T('密码')?></td>
  4234. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4235. <?php } ?>
  4236. </table>
  4237. <?php if($this->LoggedIn){ ?>
  4238. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4239. <?php }else{ ?>
  4240. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4241. <?php } ?>
  4242. </div>
  4243. <?php
  4244. }
  4245. function MakeExtraOperations(){?>
  4246. <div class='settings' style='overflow:auto;'>
  4247. <h2><?=$this->T('附加操作')?></h2>
  4248. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  4249. <p>&nbsp;</p>
  4250. <h3><?=$this->T('自动重定向')?></h3>
  4251. <span class='smaller gray'>
  4252. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4253. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4254. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4255. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  4256. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4257. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4258. value='<?=$this->T('保存重定向设置')?>' />
  4259. <p>&nbsp;</p>
  4260. <h3><?=$this->T('自定义翻译')?></h3>
  4261. <span class='smaller gray'>
  4262. <?=$this->T('填写格式:')?>
  4263. <br /><pre>- 语言 | Language</pre></span>
  4264. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4265. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  4266. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4267. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4268. value='<?=$this->T('保存翻译')?>' />
  4269. <p>&nbsp;</p>
  4270. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4271. <ul>
  4272. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  4273. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  4274. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  4275. </ui>
  4276. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4277. </div>
  4278. <?php
  4279. }
  4280. function MakeMainBegin(){?>
  4281. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4282. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4283. <?php
  4284. }
  4285. function MakeMainEnd(){?>
  4286. </div>
  4287. <?php
  4288. }
  4289. function MakeExpFooter(){
  4290. $exptitle = isset($this->HereDisplayTitle)?('"'.trim($this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle))).'"'):NULL;
  4291. if(!isset($exptitle)) $exptitle=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle);?>
  4292. <div class='small_footer exp_h_f exp_f'><div>
  4293. <b><?=$exptitle?></b> ©<?=$this->T($this->DisplayName)?>
  4294. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):""; ?>
  4295. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4296. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4297. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4298. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4299. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4300. }?></div>
  4301. </div>
  4302. </div>
  4303. </div><!-- page -->
  4304. </body>
  4305. </html>
  4306. <script>
  4307. if(trans = document.getElementById('translate_button')){
  4308. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4309. }
  4310. </script>
  4311. <?php
  4312. }
  4313. function MakeImageOverlay($side_info=null,$static_image=null,$static_video=null){
  4314. $static=isset($side_info); ?>
  4315. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  4316. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  4317. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  4318. <?php if(!$static_video){ ?>
  4319. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/><?php } ?>
  4320. <?php if(!$static_image){ ?>
  4321. <video id='big_video' onloadstart="HideWaitingBar();" controls><source id='big_video_src' type='video/mp4'
  4322. <?=isset($static_video)?("src='".$static_video."'"):""?>></video><?php } ?>
  4323. </div>
  4324. <div class='big_side_box' onclick='HideBigImage(1);'>
  4325. <?php if(!$static){ ?>
  4326. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  4327. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  4328. <div class='lr_buttons'>←</div></a></div>
  4329. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  4330. <div class='lr_buttons'>→</div></a></div>
  4331. <div id='here_buttons'></div>
  4332. </div><?php } ?>
  4333. <div class='side_box_mobile_inner'>
  4334. <?php if(!$static){ ?>
  4335. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  4336. <span style='display:none;' id='image_purchase' class='clean_a'>
  4337. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  4338. <br class='hidden_on_desktop block_m' /></span>
  4339. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  4340. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4341. &nbsp;<a class='clean_a' id='image_inquiry'>
  4342. <b>@</b><?=$this->T('咨询')?></a>
  4343. <?php } ?><hr class='hidden_on_desktop block_m' />
  4344. </div>
  4345. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  4346. <li class='wayback_close'><a onclick='HideBigImage(1);'><?=$this->T('关闭')?> ×</a></li>
  4347. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  4348. <hr />
  4349. </div><?php } //static ?>
  4350. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  4351. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  4352. <br /><?=$this->T('印刷品链接')?>
  4353. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  4354. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  4355. <?=$this->T('重命名')?>
  4356. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  4357. <?=$this->T('主图')?>
  4358. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  4359. <?=$this->T('对齐')?> <select id='image_align' name='image_align' form="image_ops_form">
  4360. <option value='top'><?=$this->T('顶部')?></option>
  4361. <option value='middle'><?=$this->T('中间')?></option>
  4362. <option value='bottom'><?=$this->T('底部')?></option></select><br />
  4363. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  4364. <br /><br /><?=$this->T('替换图像')?>
  4365. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  4366. <input type="file" form='image_edit_form'
  4367. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  4368. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  4369. value=<?=$this->T('执行')?> />
  4370. </div><?php } ?>
  4371. </div>
  4372. </div>
  4373. </div>
  4374. <?php }
  4375. function MakePageEnd(){?>
  4376. </div><!-- page -->
  4377. </body>
  4378. </html>
  4379. <?php }
  4380. function MakeFooter(&$p){ $no_title=isset($p['tid']['first']['no_title']);?>
  4381. <div class='small_footer'><div>
  4382. <hr />
  4383. <?php if(isset($p['tid']['footer'])){ ?><div class='show_on_print'><?=$p['tid']['footer'];?></div><?php } ?>
  4384. <b<?=$no_title?" class='hidden_on_print'":"";?>><?=$this->T($this->Title)?></b>
  4385. <span onclick='event.stopPropagation()'<?=$no_title?" class='hidden_on_print'":"";?>
  4386. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  4387. <div class='smaller show_on_print'><?=$_SERVER['SERVER_NAME']?><br /><?=$this->EMail?></div>
  4388. </div></div>
  4389. <div class='footer'>
  4390. <div style='white-space:nowrap;'>
  4391. <div class='footer_additional'>
  4392. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  4393. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4394. } ?>
  4395. </div>
  4396. <div class='footer_additional'>
  4397. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  4398. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4399. } ?>
  4400. </div>
  4401. </div>
  4402. </div>
  4403. <p>&nbsp;<p>
  4404. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  4405. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  4406. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  4407. </div>
  4408. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  4409. <script>
  4410. <?=$this->ExtraScripts?>
  4411. if(back = document.getElementById('button_back')){
  4412. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  4413. back.href='javascript:history.back()';
  4414. }else{
  4415. back.href='index.php';
  4416. }
  4417. }
  4418. function copy_text(t) {
  4419. ta = document.createElement('textarea'); document.body.appendChild(ta); ta.value = t; ta.select();
  4420. document.execCommand("copy"); document.body.removeChild(ta);
  4421. }
  4422. if(trans = document.getElementById('translate_button')){
  4423. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4424. }
  4425. function ClickPost(p,e,pushstate){if(e)e.preventDefault();
  4426. id=p.dataset.postId; list=p.parentNode;active=list.getElementsByClassName('active_post');
  4427. lp=p.querySelector('.lpctrl');
  4428. if(active&&active[0]&&active[0]!=p){
  4429. if(pushstate){window.history.pushState('?post='+id,null,'?post='+id);}
  4430. active[0].classList.remove('active_post'); p.classList.add('active_post');
  4431. }
  4432. }function InitLabel(){
  4433. lb=document.querySelector('#mtitle'); lb.removeAttribute('for'); lb.onclick=function()
  4434. {c=document.querySelector('#titlectrl');if(c.checked)c.checked=false;else c.checked=true;}
  4435. lb=document.querySelectorAll('.bkg_section label');if(!lb||!lb[0])return;
  4436. for(i=0;i<lb.length;i++){ lb[i].removeAttribute('for');lb[i].onclick=function()
  4437. {c=this.parentNode.querySelector('.lpctrl');if(!c)return;if(c.checked)c.checked=false;else c.checked=true;} }
  4438. }InitLabel();
  4439. <?php if($this->LoggedIn){ ?>
  4440. var Scenter = document.querySelector('#div_center');
  4441. var Sposts = Scenter?Scenter.querySelectorAll('.post'):null;
  4442. <?php if(isset($this->MastodonToken)){ ?>
  4443. function MarkPostDoneMastodon(id,mastodon_url){
  4444. for(var i=0;i<Sposts.length;i++){
  4445. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  4446. }
  4447. <?php } ?>
  4448. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  4449. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  4450. var Smerge_post = Scenter.querySelector('#merge_post');
  4451. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  4452. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  4453. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  4454. var Smerge_select = Scenter.querySelector('#merge_select');
  4455. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  4456. var Smerge_thread = Scenter.querySelector('#merge_thread');
  4457. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  4458. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  4459. var select_mode = false; var merge_mode = false; var selected_posts = null;
  4460. function TogglePostSelectMode(force_on=false,force_off=false){
  4461. Scenter.classList.add('post_selecting');
  4462. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  4463. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  4464. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  4465. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  4466. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  4467. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4468. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  4469. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  4470. Smerge_post_count.innerText="0";
  4471. Smerge_post.href="#";
  4472. }
  4473. function TogglePostSelect(elem){
  4474. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  4475. else{ elem.classList.add('post_selected'); }
  4476. selected_posts = new Array();
  4477. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  4478. selected_posts.push(Sposts[i].dataset.postId); } }
  4479. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  4480. Smerge_post_count.innerText=selected_posts.length;
  4481. }
  4482. function ThreadMergeInput(elem){
  4483. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  4484. else{ Smerge_thread.href="#"; }
  4485. }
  4486. function ToggleThreadMerge(force_on=false,force_off=false){
  4487. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  4488. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  4489. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  4490. else{ merge_mode = 0;
  4491. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  4492. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4493. Smerge_thread.href="#";
  4494. Smerge_thread_target.value='';
  4495. }
  4496. <?php } ?>
  4497. function ShowSideUploader(){
  4498. ShowRightSide(true,null);
  4499. put = document.querySelector("#_uploader");
  4500. put.style.display='block';
  4501. RefreshSideGallery();
  4502. }
  4503. dmark = document.querySelector("#mark_details");
  4504. drename = document.querySelector("#rename_details");
  4505. dmastodon = document.querySelector("#mastodon_details");
  4506. drename_form = document.querySelector("#post_rename_form");
  4507. drename_input = document.querySelector("#post_rename_name");
  4508. var rp = document.querySelector('#post_reply_to');
  4509. var _reply_to = rp?rp.defaultValue:"";
  4510. function RestoreReply(){
  4511. if(rp){
  4512. rp.defaultValue = _reply_to;
  4513. }
  4514. document.querySelector('#post_reply_restore').style.display='none';
  4515. ht = document.querySelector('#post_hint_text');
  4516. if (_reply_to!=""){
  4517. ht.style.display='block';
  4518. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  4519. }else{
  4520. ht.style.display='none';
  4521. }
  4522. document.querySelector('#post_edit_target').value="";
  4523. ch = document.querySelector('#post_hint_modify');
  4524. ch.style.display='none';
  4525. }
  4526. function MakeRefer(id){
  4527. t = document.querySelector('#post_content')
  4528. t.focus();
  4529. v = t.value;
  4530. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  4531. la_auto_grow(t);
  4532. if(rp){
  4533. rp.defaultValue = "";
  4534. ht = document.querySelector('#post_hint_text');
  4535. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  4536. document.querySelector('#post_reply_restore').style.display='inline';
  4537. rs = document.querySelector('#post_reply_restore');
  4538. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  4539. document.getElementById('post_menu').style.display='none';
  4540. ch = document.querySelector('#post_hint_modify');
  4541. ch.style.display='none';
  4542. }
  4543. }
  4544. function CopyRefer(id){
  4545. copy_text(id.toString());
  4546. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  4547. }
  4548. function MakeEdit(id){
  4549. ed = document.getElementById('menu_edit');
  4550. ed.innerHTML="<?=$this->T('稍等')?>";
  4551. ed.href="#";
  4552. var xhr = new XMLHttpRequest();
  4553. xhr.onreadystatechange = function() {
  4554. if (this.readyState == 4 && this.status == 200) {
  4555. ed.innerHTML='——';
  4556. ch = document.querySelector('#post_hint_modify');
  4557. ch.style.display='block';
  4558. ht = document.querySelector('#post_hint_text');
  4559. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  4560. rs = document.querySelector('#post_reply_restore');
  4561. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  4562. t = document.querySelector('#post_content');
  4563. t.value=xhr.responseText.trim();
  4564. t.focus();
  4565. la_auto_grow(t);
  4566. document.querySelector('#post_edit_target').value=id;
  4567. document.getElementById('post_menu').style.display='none';
  4568. }
  4569. };
  4570. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4571. xhr.send();
  4572. }
  4573. function MarkDelete(id){
  4574. p = document.querySelector('[data-post-id="'+id+'"]');
  4575. op = p.dataset.markDelete?"false":"true";
  4576. window.location.href=
  4577. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4578. }
  4579. function SetMark(mark){
  4580. menu = document.getElementById('post_menu');
  4581. window.location.href=
  4582. "index.php?<?=$this->GetRedirect()?>&target="+
  4583. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4584. }
  4585. function ToggleMarkDetails(){
  4586. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  4587. drename.style.display=dmastodon.style.display='none';
  4588. }
  4589. function ToggleRenameDetails(){
  4590. drename.style.display=(drename.style.display=='block')?'none':'block';
  4591. dmark.style.display=dmastodon.style.display='none';
  4592. }
  4593. function ToggleMastodonDetails(){
  4594. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  4595. dmark.style.display=drename.style.display='none';
  4596. }
  4597. <?php } ?>
  4598. function ShowPostMenu(post){
  4599. menu = document.getElementById('post_menu');
  4600. menu.style.display='block';
  4601. menu.parentNode.removeChild(menu);
  4602. post.appendChild(menu);
  4603. menu.style.display='block';
  4604. id = post.dataset.postId
  4605. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4606. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4607. window.onClick="HidePopMenu()";
  4608. menu.onClick=(function(event){
  4609. event.stopPropagation();
  4610. });
  4611. hs = menu.querySelector('#menu_history');
  4612. hs.href='?post='+id+'&history=1';
  4613. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4614. <?php if($this->PageType!='search'){?>
  4615. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4616. ed = menu.querySelector('#menu_edit');ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4617. <?php } ?>
  4618. ref = menu.querySelector('#menu_refer_copy')
  4619. ref.innerHTML='<?=$this->T("复制编号")?>';
  4620. ref.href='javascript:CopyRefer(id)';
  4621. d = menu.querySelector('#menu_delete');
  4622. d.href='javascript:MarkDelete(\"'+id+'\")';
  4623. p = document.querySelector('[data-post-id="'+id+'"]');
  4624. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4625. menu.querySelector('#mark_details').dataset.id=id;
  4626. drename_input.value=id;
  4627. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4628. <?php if(isset($this->MastodonToken)){ ?>
  4629. dmastodon_form = document.querySelector("#post_mastodon_form");
  4630. dmastodon_form.action='?mastodon_post='+id;
  4631. function MastodonSend(id){
  4632. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  4633. var xhr = new XMLHttpRequest();
  4634. function wrapidxhr(_id) { return function() {
  4635. if (this.readyState == 4 && this.status == 200) {
  4636. var response = xhr.responseText;
  4637. let content="";
  4638. if(res = response.match(/SUCCESS (\S+)/u)){
  4639. content="<?=$this->T('成功发送到长毛象')?>";
  4640. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  4641. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  4642. MarkPostDoneMastodon(_id, res[1]);
  4643. } }
  4644. };
  4645. xhr.onreadystatechange = wrapidxhr(id);
  4646. xhr.open("GET", "index.php?mastodon_send_post="+id, true); xhr.send();
  4647. }
  4648. menu_mastodon = menu.querySelector("#menu_mastodon");
  4649. mastodon_send = menu.querySelector("#menu_mastodon_send");
  4650. mastodon_view = menu.querySelector("#menu_mastodon_view");
  4651. mastodon_url = menu.querySelector("#post_mastodon_url");
  4652. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  4653. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  4654. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  4655. mastodon_url.value="";}
  4656. mastodon_send.onclick=function(){
  4657. this.onclick=function(){};
  4658. MastodonSend(id); };
  4659. <?php } } ?>
  4660. title = document.title;
  4661. copy = document.getElementById('share_copy');
  4662. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4663. copy.addEventListener("click", function(){
  4664. url = window.location
  4665. path = location.pathname
  4666. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4667. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4668. });
  4669. }
  4670. function HidePopMenu(){
  4671. var menus = document.querySelectorAll('.pop_menu');
  4672. [].forEach.call(menus, function(m){m.style.display='none';});
  4673. }
  4674. var posts = document.querySelectorAll('.center .post');
  4675. [].forEach.call(posts, function(p){
  4676. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4677. ShowPostMenu(this.parentNode);ClickPost(this.parentNode,null,true)
  4678. });
  4679. });
  4680. var post_clickables = document.querySelectorAll('.center .post a');
  4681. [].forEach.call(post_clickables, function(p){
  4682. p.addEventListener("click", function(event){
  4683. event.stopPropagation();
  4684. });
  4685. });
  4686. function FindImage(imgsrc){
  4687. for(var i=0;i<document.images_filtered.length;i++){
  4688. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4689. }
  4690. return null
  4691. }
  4692. var dottime1;
  4693. var dottime2;
  4694. function ToDataURL(url) {
  4695. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4696. clearTimeout(dottime1);clearTimeout(dottime2);
  4697. ps = document.querySelector('#download_processing');
  4698. ps.innerHTML='↓';ps.style.opacity='';
  4699. return URL.createObjectURL(blob);});
  4700. }
  4701. async function DownloadAsImage(url,name) {
  4702. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4703. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4704. }
  4705. function basename(url){return url.split(/[\\/]/).pop();}
  4706. pushed=0;
  4707. function ShowBigImage(imgsrc,do_push){
  4708. ShowWaitingBar();
  4709. share = document.querySelector('#big_image_share');
  4710. img = document.querySelector('#big_image');
  4711. vid = document.querySelector('#big_video');
  4712. vidsrc = document.querySelector('#big_video_src');
  4713. down = document.querySelector('#image_download');
  4714. img.src = ""; vidsrc.src="";
  4715. if(imgsrc.match(/\.mp4$/)){
  4716. vidsrc.src = src = "images/"+imgsrc; img.style.display='none'; vid.load();vid.style.display='block';
  4717. }else{
  4718. img.src = src = "images/"+imgsrc; vid.style.display='none';img.style.display='block';
  4719. }
  4720. down.href="images/"+imgsrc;
  4721. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_<?=$this->GiveSafeEMail()?>_'+
  4722. basename(down.href);
  4723. img.alt = downname; down.download=downname;
  4724. var use_href = "images/"+imgsrc;
  4725. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4726. ps = this.querySelector('#download_processing');ps.innerText='…';
  4727. var dotwait = function(ps){ var self = this;
  4728. dottime1 = setTimeout(function(ps){
  4729. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4730. dotwait(this.querySelector('#download_processing'));
  4731. DownloadAsImage(use_href,downname);};
  4732. if(do_push){PushGalleryHistory(src)}
  4733. page_url = encodeURIComponent(window.location.href);
  4734. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4735. inqb = document.querySelector('#image_inquiry');
  4736. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4737. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4738. (page_url)+encodeURIComponent('\n\n');
  4739. <?php } ?>
  4740. this_image = FindImage(imgsrc);
  4741. if(this_image&&this_image.dataset.prevsrc){
  4742. new_image = FindImage(this_image.dataset.prevsrc);
  4743. new_prev = new_image?new_image.dataset.prevsrc:null;
  4744. im = document.querySelector('#prev_image');
  4745. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4746. else {im.style.opacity='0';im.removeAttribute("href");}
  4747. }
  4748. if(this_image&&this_image.dataset.nextsrc){
  4749. new_image = FindImage(this_image.dataset.nextsrc);
  4750. new_next = new_image?new_image.dataset.nextsrc:null;
  4751. im = document.querySelector('#next_image');
  4752. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4753. else {im.style.opacity='0';im.removeAttribute("href");}
  4754. }
  4755. purchase = document.querySelector('#image_purchase');
  4756. purchase_btn = document.querySelector('#image_purchase_button');
  4757. <?php if($this->LoggedIn){ ?>
  4758. product_link = document.querySelector('#image_ops_product_link');
  4759. product_form = document.querySelector('#image_ops_form');
  4760. edit_form = document.querySelector('#image_edit_form');
  4761. edit_new_name = document.querySelector('#image_edit_new_name');
  4762. edit_parent = document.querySelector('#image_parent');
  4763. edit_align = document.querySelector('#image_align');
  4764. product_form.action = window.location.href;
  4765. edit_form.action = window.location.href;
  4766. edit_new_name.value = imgsrc.split('.')[0];
  4767. if(this_image){
  4768. if(this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  4769. if(this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  4770. if(this_image.dataset.align){ edit_align.value = this_image.dataset.align; }else{ edit_align.value = "middle"; }
  4771. }
  4772. <?php } ?>
  4773. if(this_image&&this_image.dataset.product){
  4774. purchase.style.display='';
  4775. href = this_image.dataset.product;
  4776. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4777. href = '?post='+href;
  4778. }
  4779. purchase_btn.href = href;
  4780. }else{
  4781. purchase.style.display='none';
  4782. purchase_btn.removeAttribute("href");
  4783. }
  4784. DelayHideImgBtn(null);
  4785. title = encodeURIComponent(document.title);
  4786. copy = document.getElementById('big_share_copy');
  4787. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4788. copy.addEventListener("click", function(){
  4789. copy_text(window.location.href);
  4790. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4791. });
  4792. o = document.querySelector('#big_image_overlay');
  4793. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  4794. here = document.querySelector('#here_buttons');here.innerHTML='';
  4795. o.style.display="block";
  4796. ShowBackdrop(0.8);
  4797. var xhr = new XMLHttpRequest();
  4798. xhr.onreadystatechange = function() {
  4799. if (this.readyState == 4 && this.status == 200) {
  4800. info = document.querySelector('#big_image_info');
  4801. var response = xhr.responseText;
  4802. let content=""
  4803. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4804. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4805. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4806. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4807. content+="<div class='clean_a'>"+res[1]+"</div>"; }
  4808. info.innerHTML=content;
  4809. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  4810. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  4811. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  4812. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  4813. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  4814. }
  4815. }
  4816. };
  4817. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4818. xhr.send();
  4819. }
  4820. function HideBigImage(do_push){
  4821. o = document.querySelector('#big_image_overlay');
  4822. img = document.querySelector('#big_image');
  4823. vid = document.querySelector('#big_video');
  4824. vidsrc = document.querySelector('#big_video_src');
  4825. img.src = ""; vidsrc.src="";
  4826. if(o.style.display!='none'){
  4827. o.style.display="none";
  4828. HideBackdrop();
  4829. if(do_push){PushGalleryHistory("");}
  4830. HideWaitingBar();
  4831. }
  4832. }
  4833. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4834. var inq=document.querySelector('#inquiry_buttons');
  4835. var overlay=document.querySelector('#big_image_overlay');
  4836. var hide_timeout;
  4837. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4838. function DelayHideImgBtn(e){
  4839. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  4840. inq.classList.remove('img_btn_hidden');
  4841. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  4842. clearTimeout(hide_timeout);
  4843. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  4844. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  4845. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  4846. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  4847. }
  4848. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4849. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4850. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4851. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4852. function UpdateImageClickables(){
  4853. var images = document.querySelectorAll('img, video');
  4854. var images_filtered=new Array(); var imgadded = new Array();
  4855. var images_remaining=new Array();
  4856. [].forEach.call(images, function(img){
  4857. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4858. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4859. images_filtered.push(img);imgadded.push(imgsrc);
  4860. });
  4861. for(var i=0; i<images_filtered.length; i++){
  4862. previmg = nextimg = null; img = images_filtered[i];
  4863. if(i>0) previmg=images_filtered[i-1];
  4864. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4865. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4866. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4867. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4868. var clone = img.cloneNode(true); img.replaceWith(clone);
  4869. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  4870. }
  4871. for(var i=0; i<images_remaining.length; i++){
  4872. img = images_remaining[i];
  4873. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4874. var clone = img.cloneNode(true); img.replaceWith(clone);
  4875. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  4876. }
  4877. document.images_filtered = images_filtered;
  4878. }
  4879. UpdateImageClickables();
  4880. function PopGalleryHistory(){
  4881. if(pushed){
  4882. pushed = 0;
  4883. try{
  4884. history.back();
  4885. }catch{
  4886. console.log("can't do it.");
  4887. }
  4888. }
  4889. }
  4890. function PushGalleryHistory(src){
  4891. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  4892. title = "照片"
  4893. extra = "?";
  4894. sp = new URLSearchParams(window.location.search)
  4895. if(sp.has('post')){extra+="post="+sp.get('post')}
  4896. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  4897. try{
  4898. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  4899. }catch{
  4900. console.log("can't do it.");
  4901. }
  4902. pushed = 1;
  4903. }
  4904. document.addEventListener('keydown', function(e){
  4905. large = document.getElementById('big_image_overlay')
  4906. if (large.style.display!='block') return;
  4907. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  4908. HideBigImage(1);
  4909. }
  4910. }, true);
  4911. window.addEventListener('popstate', (event) => {
  4912. href=window.location.href;
  4913. let sp = new URLSearchParams(href.substring(href.indexOf('?')))
  4914. if(sp.has('pic')){
  4915. src = sp.get('pic')
  4916. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)) ShowBigImage(onlyimg[0], 0);
  4917. else{HideBigImage(0);}
  4918. }else{HideBigImage(0);}
  4919. if(sp.has('post')){
  4920. id=sp.get('post');post=document.querySelector('.post[data-post-id="'+id+'"]');
  4921. if(post){ClickPost(post,null,false);}
  4922. }
  4923. });
  4924. let searchParams = new URLSearchParams(window.location.search)
  4925. if(searchParams.has('pic')){
  4926. src = searchParams.get('pic')
  4927. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)){
  4928. ShowBigImage(onlyimg[0], 1);
  4929. }
  4930. }
  4931. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  4932. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  4933. </script>
  4934. </body>
  4935. <?php
  4936. }
  4937. function DoIdentifyExperimental(){
  4938. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  4939. $this->InExperimentalMode=True; $this->InHereMode=True;
  4940. }
  4941. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  4942. $this->InHereMode=True;
  4943. }
  4944. }
  4945. function DoExperimentalTopLink($p){
  4946. if($this->InHereMode && $p){
  4947. if(isset($p['tid']) && $p['tid']['first']!=$p){
  4948. header('Location: ?post='.$p['tid']['first']['id']); exit();
  4949. }
  4950. }
  4951. }
  4952. function MakeExperimentalConfirm(){
  4953. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  4954. return false;
  4955. }
  4956. $caution_html =
  4957. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  4958. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  4959. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  4960. ?>
  4961. <div class='center_exp'><?php
  4962. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  4963. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  4964. ?></div>
  4965. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  4966. <?php return true;
  4967. }
  4968. }
  4969. $la = new LA;
  4970. $la->DoSiteRedirect();
  4971. $la->DoLogin();
  4972. $la->SwitchLanguageAndFont();
  4973. $err = $la->ProcessRequest($message, $redirect);
  4974. $la->WriteAsNecessary();
  4975. $la->DoIdentifyExperimental();
  4976. $la->SwitchWayBackMode();
  4977. if($err){
  4978. echo $message;
  4979. exit();
  4980. }
  4981. if(isset($redirect)){
  4982. header('Location: '.$redirect);
  4983. exit();
  4984. }
  4985. $la->DetectPageType();
  4986. $la->ReadImages(false);
  4987. $la->ReadPosts();
  4988. if(isset($la->WayBack)){
  4989. $la->ReadArchive();
  4990. }
  4991. $im = NULL;
  4992. if(preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  4993. if(!$la->CanShowImage($im)) { $im=&$la->NULL_IMAGE; }
  4994. }
  4995. $p = &$la->GetPost($la->CurrentPostID);
  4996. if(!isset($p)){
  4997. $p = &$la->GetMergedPost($la->CurrentPostID);
  4998. }
  4999. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  5000. else{ $la->DoExperimentalTopLink($p); }
  5001. if(isset($p)){ $la->ActualPostID = $p['id']; }
  5002. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5003. if($im){
  5004. $la->SetHereMainImage($im);
  5005. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  5006. }else if($p){
  5007. $la->RecordVisitedHere($p['id'],NULL);
  5008. }else {
  5009. $im = &$la->GiveImageInHere(false);
  5010. if($im){
  5011. $la->SetHereMainImage($im);
  5012. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  5013. }
  5014. }
  5015. }
  5016. $la->MakeHeader($p);
  5017. $la->MakeMainBegin();
  5018. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5019. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  5020. if($im){
  5021. $la->MakeHereSection($im);
  5022. }else if($p){
  5023. $la->MakePostSectionExp($p);
  5024. $la->MakeLinkedPostsExp($p);
  5025. }else {
  5026. if($im){
  5027. $la->MakeHereSection($im);
  5028. }else{
  5029. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5030. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  5031. }
  5032. }
  5033. }
  5034. $la->MakeMainEnd();
  5035. $la->MakeExpFooter();
  5036. }else{
  5037. if($la->PageType=='extras'){
  5038. $la->MakeExtraOperations();
  5039. }else if($la->PageType=='settings'){
  5040. $la->MakeSettings();
  5041. }else if($la->PageType=='gallery'){
  5042. $la->MakeGalleryLeft();
  5043. $la->MakeGallerySection();
  5044. }else if($la->PageType=='post'){
  5045. if($p){
  5046. $made_interesting = false;
  5047. if($la->IsInterestingPost($p)){
  5048. $la->MakeInterestingSection($p['tid']);
  5049. }
  5050. else{
  5051. $la->MakeSidebar();
  5052. $la->MakePostSection($p);
  5053. }
  5054. }else{
  5055. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5056. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  5057. }
  5058. }else if($la->PageType=='history'){
  5059. $la->ReadArchive();
  5060. $la->MakePostHistory($p, $_GET['version']??NULL);
  5061. }else if($la->PageType=='search'){
  5062. $la->MakeSidebar();
  5063. $la->MakeRecentPosts($_GET['search']);
  5064. }else if($la->PageType=='category'){
  5065. $la->MakeSidebar();
  5066. $la->MakeRecentPosts(NULL,$_GET['category']);
  5067. }else if($la->PageType=='comments'){
  5068. $la->MakeCommentPosts();
  5069. }else{
  5070. $la->MakeSidebar();
  5071. $la->MakeRecentPosts();
  5072. }
  5073. $la->MakeMainEnd();
  5074. $la->MakeFooter($p);
  5075. }
  5076. ?>