*/}}

index.php 321 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561
  1. <?php
  2. include 'Parsedown.php';
  3. include 'ParsedownExtra.php';
  4. ini_set('max_execution_time', 300);
  5. ini_set('display_errors', '1');
  6. ini_set('display_startup_errors', '1');
  7. error_reporting(E_ALL);
  8. class LA{
  9. protected $PDE;
  10. protected $style;
  11. /* config */
  12. protected $Title;
  13. protected $ShortTitle;
  14. protected $Admin;
  15. protected $Password;
  16. protected $DisplayName;
  17. protected $EMail;
  18. protected $SpecialNavigation;
  19. protected $SpecialSidebar;
  20. protected $SpecialFooter;
  21. protected $SpecialFooter2;
  22. protected $SpecialPinned;
  23. protected $DefaultGallery;
  24. protected $SelfAuthPath;
  25. protected $HereHost;
  26. protected $HereTitle;
  27. protected $HereShortTitle;
  28. protected $HereAlbum;
  29. protected $HereNavigation;
  30. protected $HereFooter;
  31. protected $ExpHost;
  32. protected $ExpAlbum;
  33. protected $ExpTitle;
  34. protected $ExpShortTitle;
  35. protected $ExpCaution;
  36. protected $ExpNavigation;
  37. protected $ExpFooter;
  38. protected $CommentEnabled;
  39. protected $MastodonToken;
  40. protected $MastodonURL;
  41. protected $MastodonPreferredLang;
  42. protected $HostURL;
  43. protected $GalleryStep;
  44. protected $AllowLanguageChoices;
  45. protected $Redirect;
  46. protected $Translations;
  47. protected $CustomTranslationContent;
  48. protected $CurrentOffset;
  49. protected $PostsPerPage;
  50. protected $HotPostCount;
  51. protected $LoggedIn;
  52. protected $LoginTokens;
  53. protected $InHereMode;
  54. protected $InExperimentalMode;
  55. protected $LanguageAppendix;
  56. protected $UseRemoteFont;
  57. protected $Posts;
  58. protected $Threads; // [ keys: first last displayed count]
  59. protected $WaybackThreads;
  60. public $Images;
  61. protected $Galleries;
  62. protected $Anchors;
  63. protected $ArchiveHandles;
  64. protected $Archive;
  65. public $WayBack;
  66. protected $YearBegin;
  67. protected $YearEnd;
  68. protected $Markers;
  69. protected $ExtraScripts;
  70. protected $APubID;
  71. protected $APubActor;
  72. protected $APubPublicKey;
  73. protected $APubPrivateKey;
  74. protected $TIME_STRING;
  75. public $NULL_POST;
  76. public $NULL_IMAGE;
  77. public $NULL_IMAGE_DUMMY;
  78. public $NULL_Gallery;
  79. protected $DoneReadPosts;
  80. protected $DoneReadImages;
  81. protected $DoneReadArchive;
  82. protected $NeedWritePosts;
  83. protected $NeedWriteImages;
  84. protected $NeedWriteArchive;
  85. protected $HereDisplayTitle;
  86. protected $VisitedHere;
  87. protected $HereNumber;
  88. protected $HereMainImage;
  89. public $PageType;
  90. public $CurrentPostID;
  91. public $HereID;
  92. public $ActualPostID;
  93. public $TagID;
  94. function ReadableTime($id){
  95. $dt = DateTime::createFromFormat('YmdHis', $id);
  96. return $dt->format('Y/m/d H:i:s');
  97. }
  98. function StandardTime($id){
  99. $dt = DateTime::createFromFormat('YmdHis', $id);
  100. return $dt->format('Y-m-d\TH:i:sP');
  101. }
  102. function FullURL(){
  103. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  104. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  105. $_SERVER['REQUEST_URI'];
  106. }
  107. function T($str){
  108. if(!$this->LanguageAppendix) return $str;
  109. foreach($this->Translations as $entry){
  110. if($entry['zh']==$str)
  111. return $entry[$this->LanguageAppendix];
  112. }
  113. return $str;
  114. }
  115. function SwitchLanguageAndFont(){
  116. $this->LanguageAppendix = 'zh';
  117. if(isset($_COOKIE['la_language'])){
  118. $this->LanguageAppendix = $_COOKIE['la_language'];
  119. }else{
  120. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  121. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  122. $lang = substr($lang,0,5);
  123. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  124. else $this->LanguageAppendix = 'en';
  125. }
  126. }
  127. if(isset($_COOKIE['la_font'])){
  128. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  129. }
  130. }
  131. function SwitchWayBackMode(){
  132. if(isset($_COOKIE['la_wayback'])){
  133. $this->WayBack = $_COOKIE['la_wayback'];
  134. }else $this->WayBack = NULL;
  135. }
  136. function DisplayRedirectConfig(){
  137. $s = "";
  138. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  139. if($r['for']=='P'){
  140. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  141. }else if($r['for']=='S'){
  142. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  143. }
  144. }
  145. return $s;
  146. }
  147. function DoSiteRedirect(){
  148. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  149. if($r['for']=='S'){
  150. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  151. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  152. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  153. }else{
  154. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. function WriteHTACCESS(){
  161. $conf = fopen('.htaccess','w');
  162. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  163. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  164. if($r['for']=='P'){
  165. if(!preg_match('/[0-9]{14}/',$r['target'])){
  166. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?'.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  167. }
  168. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  169. }// do site redirect in php.
  170. }
  171. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  172. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  173. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  174. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  175. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  176. fflush($conf);fclose($conf);
  177. }
  178. function BuildRedirectConfig($conf){
  179. $this->Redirect=[];
  180. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14}|.+)\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  181. foreach($ma as $m){
  182. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  183. $this->Redirect[]=$redirect;
  184. }
  185. }
  186. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  187. foreach($ma as $m){
  188. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  189. $this->Redirect[]=$redirect;
  190. }
  191. }
  192. }
  193. function WriteTokens(){
  194. $tf = fopen('la_tokens.php','w');
  195. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  196. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  197. foreach($this->LoginTokens as $t){
  198. fwrite($tf,'- '.$t.PHP_EOL);
  199. }
  200. }
  201. fflush($tf);fclose($tf);
  202. }
  203. function WriteConfig(){
  204. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  205. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  206. if(!isset($this->Admin)) $this->Admin = 'admin';
  207. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  208. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  209. $conf = fopen('la_config.php','w');
  210. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  211. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  212. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  213. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  214. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  215. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  216. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  217. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  218. fwrite($conf,'- SpecialSidebar = '.$this->SpecialSidebar.PHP_EOL);
  219. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  220. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  221. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  222. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  223. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  224. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  225. fwrite($conf,'- HereHost = '.$this->HereHost.PHP_EOL);
  226. fwrite($conf,'- HereTitle = '.$this->HereTitle.PHP_EOL);
  227. fwrite($conf,'- HereShortTitle = '.$this->HereShortTitle.PHP_EOL);
  228. fwrite($conf,'- HereAlbum = '.$this->HereAlbum.PHP_EOL);
  229. fwrite($conf,'- HereNavigation = '.$this->HereNavigation.PHP_EOL);
  230. fwrite($conf,'- HereFooter = '.$this->HereFooter.PHP_EOL);
  231. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  232. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  233. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  234. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  235. fwrite($conf,'- ExpAlbum = '.$this->ExpAlbum.PHP_EOL);
  236. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  237. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  238. fwrite($conf,'- MastodonToken = '.$this->MastodonToken.PHP_EOL);
  239. fwrite($conf,'- MastodonURL = '.$this->MastodonURL.PHP_EOL);
  240. fwrite($conf,'- MastodonPreferredLang = '.$this->MastodonPreferredLang.PHP_EOL);
  241. fwrite($conf,'- HostURL = '.$this->HostURL.PHP_EOL);
  242. fwrite($conf,'- APubID = '.$this->APubID.PHP_EOL);
  243. fwrite($conf,'- GalleryStep = '.$this->GalleryStep.PHP_EOL);
  244. fwrite($conf,'- AllowLanguageChoices = '.$this->AllowLanguageChoices.PHP_EOL);
  245. fflush($conf);fclose($conf);
  246. $conf = fopen('la_redirect.md','w');
  247. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  248. $this->WriteHTACCESS();
  249. $this->WriteTokens();
  250. }
  251. function Install(){
  252. if(!file_exists('la_config.php')){
  253. $this->WriteConfig();
  254. }
  255. if(!is_dir('posts')) mkdir('posts');
  256. if(!is_dir('images')) mkdir('images');
  257. if(!is_dir('images/thumb')) mkdir('images/thumb');
  258. if(!is_dir('styles')) mkdir('styles');
  259. if(!is_dir('archive')) mkdir('archive');
  260. $this->WriteStyles();
  261. $this->WriteHTACCESS();
  262. }
  263. function ReadFromExistingConfig(){
  264. $f=null;
  265. if(file_exists('la_config.php')) $f='la_config.php';
  266. else if(file_exists('la_config.md')) $f='la_config.md';
  267. if(!isset($f)) return;
  268. $c = file_get_contents($f);
  269. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  270. $str = $m[1];
  271. $this->$str = $m[2];
  272. }
  273. $this->CommentEnabled = $this->CommentEnabled=="True";
  274. if(!isset($this->GalleryStep)) $this->GalleryStep=20;
  275. }
  276. function ReadConfig(){
  277. $this->ReadFromExistingConfig();
  278. if(file_exists('la_redirect.md')){
  279. $c = file_get_contents('la_redirect.md');
  280. $this->BuildRedirectConfig($c);
  281. }
  282. if(!file_exists('la_config.php')){
  283. $this->Install();
  284. }
  285. $this->Translations=[];
  286. if(file_exists("translations.md")){
  287. $c = file_get_contents('translations.md');
  288. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  289. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  290. $this->Translations[] = $entry;
  291. }
  292. }
  293. if(file_exists("custom_translations.md")){
  294. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  295. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  296. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  297. $this->Translations[] = $entry;
  298. }
  299. }
  300. $this->LoginTokens=[];
  301. if(file_exists('la_tokens.php')){
  302. $c = file_get_contents('la_tokens.php');
  303. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  304. $this->LoginTokens[] = $m[1];
  305. }
  306. }
  307. }
  308. function MastodonPostStatus($status){ return $this->MastodonCall('/api/v1/statuses', 'POST', $status); }
  309. function MastodonPostMedia($media){ return $this->MastodonCall('/api/v1/media', 'POST', $media); }
  310. function MastodonCall($endpoint, $method, $data){
  311. $headers = [
  312. 'Authorization: Bearer '.$this->MastodonToken,
  313. 'Content-Type: multipart/form-data',
  314. ];
  315. $ch = curl_init();
  316. curl_setopt($ch, CURLOPT_URL, $this->MastodonURL.$endpoint);
  317. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  318. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  319. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  320. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  321. $reply = curl_exec($ch);
  322. if (!$reply) {
  323. return json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch_status), 'curl_error' => curl_error(ch_status)]);
  324. }
  325. curl_close($ch);
  326. return json_decode($reply, true);
  327. }
  328. function MastodonSendPost(&$post, &$errmsg=NULL){
  329. if(isset($post['mark_value']) && $post['mark_value']==7){ return NULL; }
  330. $this->LanguageAppendix = 'zh';
  331. if(in_array($this->MastodonPreferredLang,['en','zh'])){ $this->LanguageAppendix = $this->MastodonPreferredLang; }
  332. $this->ConvertPost($post);
  333. $media_ids = NULL;
  334. $mastodon_post_url = NULL;
  335. $imcount = 0;
  336. if(isset($post['original_images']) && isset($post['original_images'][0])) foreach($post['original_images'] as $im){
  337. $curl_file = curl_file_create($im, mime_content_type($im), basename($im));
  338. $body = ['file' => $curl_file,]; $response = $this->MastodonPostMedia($body);
  339. if(isset($response['id'])){ if(!isset($media_ids)){$media_ids=[];} $media_ids[]=$response['id']; }
  340. else{ if(isset($response['error'])) $errmsg.=$response['error']."<br /><br />"; }
  341. $imcount++; if($imcount>=4){ break; }
  342. }
  343. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$post['html']));
  344. if(isset($this->HostURL) && $this->HostURL!=""){
  345. $text.=("\n\n".$this->T('来自').' '.$this->HostURL.'?post='.$post['id']);
  346. }
  347. $vis = (isset($post['mark_value']) && $post['mark_value']==6)?"private":"public";
  348. $status_data = [ 'status' => $text, 'visibility' => $vis, 'language' => $this->LanguageAppendix, ];
  349. if(isset($post['prev']) && ($pp=&$this->GetPost($post['prev']))!=$this->NULL_POST){
  350. if(isset($pp['mastodon_url'])){ $status_data['in_reply_to_id'] = basename($pp['mastodon_url']);
  351. }
  352. }
  353. if(isset($media_ids[0])){ $status_data['media_ids']=$media_ids; }
  354. $status_data = preg_replace('/(media_ids%5B)[0-9]+(%5D)/','$1$2', http_build_query($status_data));
  355. $status_response = $this->MastodonPostStatus($status_data);
  356. if(isset($status_response['url']) && $status_response['url']){
  357. $mastodon_post_url = $status_response['url'];
  358. $post['mastodon_url'] = $mastodon_post_url;
  359. $this->NeedWritePosts = 1;
  360. }
  361. if(isset($status_response['error'])) { $errmsg .= $status_response['error']; }
  362. return $mastodon_post_url;
  363. }
  364. function __construct() {
  365. $this->ReadConfig();
  366. $this->PDE = new ParsedownExtra();
  367. $this->PDE->SetInterlinkPath('/');
  368. $this->Posts = [];
  369. $this->Threads = [];
  370. $this->VisitedHere = [];
  371. $this->NULL_IMAGE_DUMMY = [];
  372. $this->NULL_IMAGE_DUMMY['name']=$this->NULL_IMAGE_DUMMY['file']=$this->NULL_IMAGE_DUMMY['thumb']="";
  373. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  374. $this->PostsPerPage = 40;
  375. $this->CommentsPerPage = 100;
  376. $this->HotPostCount = 15;
  377. $this->TIME_STRING = date('YmdHis');
  378. $this->WayBack = NULL;
  379. $this->YearBegin = $this->YearEnd = 2000;
  380. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  381. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  382. $this->UsePosts = &$this->Posts;
  383. }
  384. function DoLogout(){
  385. $this->LoggedIn = false;
  386. unset($_SESSION['user_id']);
  387. $this->RecordToken(true);
  388. }
  389. function RecordToken($unset_current=false){
  390. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  391. $t = $_COOKIE['la_token'];
  392. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  393. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  394. $this->WriteTokens();
  395. return null;
  396. }else{
  397. $t = uniqid('la_',true);
  398. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  399. $this->LoginTokens[] = $t;
  400. $this->WriteTokens();
  401. return $t;
  402. }
  403. }
  404. function LoginThroughToken(){
  405. if(!isset($_COOKIE['la_token'])) return false;
  406. $t = $_COOKIE['la_token'];
  407. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  408. $_SESSION['user_id']=$this->Admin;
  409. $this->LoggedIn = true;
  410. setcookie('la_token',$t,time()+3600*24*7);
  411. return true;
  412. }
  413. return false;
  414. }
  415. function DoLogin(){
  416. session_start();
  417. $redirect=false;
  418. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  419. else if(!isset($_SESSION['user_id'])){
  420. if(isset($_POST['login_button'])){
  421. $id = trim($_POST['login_id']);
  422. $pwd = trim($_POST['login_password']);
  423. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  424. $_SESSION['user_id']=$id;
  425. $this->RecordToken(false);
  426. }
  427. $redirect = true;
  428. }else if($this->LoginThroughToken()){
  429. // nothing;
  430. }
  431. }else{
  432. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  433. else{ $this->DoLogout();}
  434. }
  435. if($redirect){
  436. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  437. .(isset($_GET['settings'])?"?settings=true":""));
  438. }
  439. }
  440. function SetHereMainImage($im_this){
  441. if(isset($im_this) && isset($im_this['parent'])){ $this->HereMainImage = &$this->FindImage($im_this['parent'],true);}
  442. }
  443. function RecordVisitedHere($image_or_post_name, $image_title){
  444. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  445. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  446. if(!(isset($_SESSION[$visited_here][0]) && in_array($image_or_post_name,$_SESSION[$visited_here]))){
  447. $_SESSION[$visited_here][] = $image_or_post_name;
  448. }
  449. if(isset($image_title)){ $this->HereDisplayTitle=$image_title; }
  450. $this->HereNumber = array_search($image_or_post_name,$_SESSION[$visited_here])+1;
  451. $_SESSION['here_number'] = $this->HereNumber;
  452. $this->VisitedHere = $_SESSION[$visited_here];
  453. }
  454. function HereLinkFromNumber($number){
  455. $number -= 1; if($number<0){ $number=0; }
  456. if($number>=sizeof($this->VisitedHere)){ $number = sizeof($this->VisitedHere)-1; }
  457. if(preg_match('/(jpg|jpeg|png|gif)/u',$this->VisitedHere[$number])){ return "?here=images/".$this->VisitedHere[$number]; }
  458. else{ return "?post=".$this->VisitedHere[$number]; }
  459. }
  460. function WriteStyles(){
  461. $this->style="
  462. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  463. body{background-color:%white%;color:%black%;}
  464. sup,sub{line-height:0;} .lpctrl{display:none;}
  465. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  466. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  467. b,strong,th{font-weight:bold;}
  468. select{font-size:inherit;}
  469. .page,.page_gallery{padding:1em;padding-top:0;padding-bottom:0;}
  470. .hidden_on_desktop,.hidden_on_wide{display:none;}
  471. .hidden_on_desktop_force{display:none !important;}
  472. ::file-selector-button{background:none;border:none;}
  473. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  474. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  475. .button:disabled{background-color:%gray%;pointer-events:none;}
  476. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;box-shadow: 0.5em 0px %white%;}
  477. header::before{content:'';position:absolute;left:0;right:0;top:0;height:1.95em;box-shadow:-2em 0em 1em -1em inset %white%;pointer-events:none;}
  478. header>div{overflow:auto;white-space:nowrap;}
  479. .header_nav{display:inline;}
  480. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  481. header a:hover,.button:hover{color:%gray% !important;}
  482. .exp_h_f{padding-top:0.3em !important;padding-bottom:0.3em !important;line-height:1.5em !important;height:2.1em !important;}
  483. .exp_f{text-align:center;}
  484. .toc_button{position:absolute;top:0.5em;right:0;text-shadow: 0px 0px 10px %white%;background-color:%white%88;}
  485. .footer{background-color:%white%;z-index:10;position:relative;}
  486. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  487. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  488. .gray,.gray a{color:%gray%;}
  489. hr{border:1px solid %gray%;}
  490. header ul,.small_footer ul,.small_footer span,header li,.small_footer li{display:inline-block;}
  491. header li::before,.small_footer li::before{content:' - '}
  492. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  493. .main{position:relative;word-spacing:-1em;}
  494. .main *{word-spacing:initial;}
  495. pre{overflow:auto;max-width:100%;display:block;}code{font-size:0.83em;}
  496. ul{display:block;}
  497. li{display:block;}
  498. .clean_table{border:none;font-size:1em !important;}.clean_table thead{box-shadow:none;}.clean_table td{vertical-align:top;}
  499. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  500. table input{border:none!important;}
  501. table img{max-width:10rem !important;}
  502. td{padding-left:0.1em;padding-right:0.1em;}
  503. td:first-child{padding-left:0;}
  504. td:last-child{padding-right:0;}
  505. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  506. thead{box-shadow:inset 0 -1px 0 0px %black%;}
  507. .post table{font-size:0.85em;}
  508. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  509. .interesting_tbody td{display:contents;}
  510. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  511. .interesting_tbody td>*{display:table-cell;}
  512. .interesting_tbody td>.wscroll{display:none !important;}
  513. .interesting_tbody .post_access{padding-top:0;}
  514. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  515. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  516. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  517. .interesting_tbody td>.imd>a{display:flex;}
  518. .interesting_tbody img{object-fit:cover;width:100%;}
  519. .interesting_tbody .p_row{display:flex;position:absolute;left:1.4em;top:0.25em;z-index:-1;flex-wrap:nowrap;max-width:calc(100% - 1.4em);}
  520. .interesting_tbody .p_thumb{height:1em;}
  521. .interesting_tbody .p_thumb img,.interesting_tbody .p_thumb video{max-height:10rem !important;max-width:20rem !important;}
  522. tr:hover .post_menu_button{opacity:1;}
  523. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  524. .align_right{text-align:right;}
  525. .left{display:inline-block;vertical-align:top;width:25%;padding-right:1.5em;padding-bottom:4rem;position:sticky;top:2em;
  526. overflow:auto;max-height:calc(100vh - 2.6em);}
  527. .center{display:inline-block;vertical-align:top;width:50%;overflow:visible;padding-bottom:4rem;}
  528. .center_slides{display:block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;font-size:5vmin;user-select:none;}
  529. .center_slides .print_column{display:table;position:fixed;top:0;right:0;left:0;bottom:0;width:100%;height:100%;z-index:90;}
  530. .center_slides .print_column .post{display:table-cell;vertical-align:middle;padding:5vmin !important;max-height:100vh;width:100vw;overflow:auto;}
  531. .center_slides .active_post{background-color:%white%;}.center_slides .post{background-color:%white%;}
  532. .center_slides .post_access{display:none;}
  533. .center_slides .post_menu_button{display:none !important;}
  534. .center_slides .post_width{display:block;vertical-align:middle;max-height:100vh;overflow-y:auto;overflow-x:hidden;width:100%;}
  535. .center_slides .linked_posts{display:none;}.center_slides .ref_compact{position:relative!important;display:block!important;}
  536. .slides_buttons{position:fixed;z-index:200;right:0.5rem;bottom:0.5rem;user-select:none;background-color:%white%aa;padding:0.5rem;font-family:monospace;}
  537. .slides_buttons a{text-decoration: none;}
  538. .center_slides .imd{text-align:center;pointer-events:none;}
  539. .imd_float{float:right;width:50% !important;clear:both;margin-left:0.5em !important;}
  540. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  541. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  542. .center_wide .p_thumb{height:12rem;margin:0;margin-right:1em;margin-bottom:1em;box-shadow:5px 5px 15px 2px black;}
  543. .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%;}
  544. .active_post .linked_posts{background-color:%highlight_slice%;}
  545. input:checked~.linked_posts{display:none;}
  546. .bkg_recent>.post,.bkg_section{background:%post_white%;box-shadow:0em 0em 0.5em %shadow%;margin-bottom:0.5em;}
  547. .bkg_recent>.post>.post_width :last-child{margin-bottom:0;}
  548. .sticky_title{position:sticky;top:calc(1.6rem + 2px);z-index:1;background-color:%white%;pointer-events:none;}
  549. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  550. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  551. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  552. textarea,input[type=text],input[type=password]{font-family:monospace;width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  553. select,textarea,input[type=text],input[type=password]{font-family:monospace;background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  554. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  555. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  556. .post{position:relative;scroll-margin:3.5em;}
  557. .active_post{background-color:%highlight_white%;}.active_post .post_access{background-color:%highlight_slice%;}
  558. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;}
  559. .post_width li,.footer_additional li,.footer_additional li,.post_dummy li
  560. {display:list-item;margin-left:1em;list-style:disc;}
  561. .post_width li li,.footer_additional li li,.footer_additional li li,.post_dummy li li
  562. {list-style:circle;}
  563. ol li{list-style:unset !important;}
  564. .post_width > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  565. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  566. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  567. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  568. .gallery_left .selected{list-style:'→';}
  569. .bkg_section .post_width{padding-top:0;padding-bottom:0;}
  570. .bkg_section .print_title+.post .post_width{padding-top:0.5em;}
  571. .bkg_section .post:not(.print_title):first-of-type .post_width{padding-top:0.5em;}
  572. .bkg_section .restart+.post .post_width{padding-top:0.5em;}
  573. .post_width{position:relative;width:calc(100% - 1.5rem);overflow:auto;padding:0.5rem;}
  574. .ref_count{position:absolute;width:100%;bottom:0.5em;font-weight:bold;color:%gray%;}
  575. .active_post .ref_count{color:%black%;}
  576. .ref_count::after{content: \" \";display:block;width:10em;background:linear-gradient(to right,#0000,%gray%);height:2px;
  577. bottom:-0.5em;position:absolute;right:0;}
  578. //.ref_count::after{content: \" \";display:block;width:0.1em;background-color:%gray%;height:100%;margin-left:0.7em;}
  579. //.lpctrl:checked~.post_width{box-shadow: 1px 1px 1px 1px inset black;}
  580. .opt_compact .post_width,.ref_compact .post_width{padding-top:0;padding-bottom:0;}
  581. .p_thumb .post_menu_button{right:0.3rem;}
  582. .post_menu_button{position:absolute;display:none;top:0.3em;right:1.8rem;width:1.5rem;box-shadow:0px 0px 3px %shadow%;
  583. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;background-color:%post_white%aa;}
  584. .pointer{cursor:pointer;}
  585. .post:hover .post_menu_button{display:block;}
  586. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%grayslice%;
  587. padding:0.3em;right:1.8rem;text-align:right;border-radius:0.3em;font-size:1rem;
  588. box-shadow:0px 0px 10px %shadow%;}
  589. .pop_menu li{list-style:none;margin-left:0;}
  590. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  591. .toc{left:60%;width:40%;top:0;position:absolute;}
  592. .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;}
  593. .post_access:hover{filter:brightness(150%);}.post label{pointer-events:none;}.active_post label{pointer-events:all;}
  594. .paa{width:1.4rem;min-width:1.4rem;}
  595. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;background-color:%post_white%;right:unset;left:-2em;}
  596. .active_post .opt_compact .post_access,.active_post .ref_compact .post_access{background-color:%highlight_white%;}
  597. .post_preview{overflow:hidden;margin-bottom:0.4em;background-color:%white%aa;box-shadow: 0px 0px 0.2em %shadow%;}
  598. .post_preview:hover{filter:contrast(90%);}
  599. .active_post .post_preview:hover{filter:contrast(90%);}
  600. .post .post_ref{margin:0;padding-left:1.5rem;}
  601. .post_ref_main{display:inline-block;vertical-align:top;max-height:6em;overflow:hidden;margin:0.4em;}
  602. .post_ref_images{overflow:hidden;margin:0.4em;margin-top:0;}
  603. .post_ref_hint{text-align:right;}
  604. .page_selector{padding-top:2rem;text-align:center;}
  605. .smaller{font-size:0.85em;} .bigger{font-size:1.3em;} .block{display:block;}
  606. .restart{text-align:right;padding:0.5rem;background:linear-gradient(to left, %grayslice% 1.5em, %grayslice%00 10em);}
  607. .opt_compact{margin-left:2rem;}.ref_compact{margin-left:1.5rem;}
  608. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  609. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  610. .spacer{height:0.5em;}
  611. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  612. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  613. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  614. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  615. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  616. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  617. .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;}
  618. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  619. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  620. .toc_entry_1{font-size:1.1em;}
  621. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  622. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  623. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  624. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  625. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  626. .post h1,.post h2,.post h3,.post h4,.post h5{margin-top:1rem;}
  627. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  628. .deleted_post{color:%gray%;text-decoration:line-through;}
  629. #file_list{margin-top:0.5em;}
  630. .file_thumb img,.file_thumb video{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  631. .file_thumb video{border:2px dashed %black%;}f
  632. #file_list li{margin-bottom:0.3em;}
  633. .ref_thumb{white-space:nowrap;overflow:hidden;}
  634. .ref_thumb .file_thumb{width:2em;height:2em;margin:0;}
  635. .side_thumb li{margin:0.4em;display:inline-block;}
  636. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  637. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  638. .p_thumb{display:flex;flex-grow:100;height:6rem;overflow:hidden;position:relative;margin-right:0.5em;margin-bottom:0.5em;box-shadow:box-shadow:2px 2px 10px 1px #000a;}
  639. .p_thumb_narrow{width:1rem;flex-grow:1;opacity:0.2;}
  640. .p_thumb img,.p_thumb video{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  641. .p_thumb:hover .post_menu_button{display:block;}
  642. .p_thumb_selected{color:%black% !important;}
  643. .p_thumb_selected{display:block;}
  644. .post .p_thumb img,.post .p_thumb video{max-height:6rem;}
  645. .p_thumb video{border-bottom:0.4em dashed %black%;border-top:0.4em dashed %black%;}
  646. .p_thumb_end{flex-grow:10000 !important;box-shadow:none;align-items:center;padding:2em !important;}
  647. .p_thumb_end:hover, .p_thumb_end a:hover{background-color:%gray%;cursor:pointer;}
  648. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  649. .big_image_box *{pointer-events:auto;}
  650. .big_image_box img,.big_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  651. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  652. .here_image_box img,.here_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  653. .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;}
  654. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  655. .big_side_box a:hover{color:%gray%;}
  656. .big_side_box *{pointer-events:auto;}
  657. .big_side_box .post_preview{border:1px solid %gray%;background-color:unset;border-radius:0.3em;}
  658. .image_nav{pointer-events:none;}
  659. #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;
  660. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  661. img,video{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  662. .post img,.post video{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);margin-right:0.5em;margin-bottom:0.5em;box-shadow:2px 2px 10px 1px #000a;}
  663. .post > a > img,.post > a > video{display:block;margin:0.3em auto;}
  664. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  665. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;margin-right:0.5em;margin-bottom:0.5em;box-shadow:2px 2px 10px 1px #000a;}
  666. .center_exp .post .original_img{display:block;}
  667. .original_img img,.original_img video{max-height:90vh;max-width:100%;}
  668. .p_row .original_img{margin-bottom:0;}
  669. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  670. .imbtn{display:block;contain:content;padding:0.25em;margin-bottom:0.5em;text-decoration:none;text-shadow:0px 0px 5px %white%;}
  671. .imbtn img{display:block;object-fit:cover;position:absolute;top:0;left:0;bottom:0;right:0;margin:auto;z-index:-1;
  672. min-width:100% !important;min-height:100% !important;filter:opacity(40%);}
  673. .imbtn:hover img{filter:opacity(20%) blur(0.1em);} .imbtn:hover{color:%black% !important;}
  674. header .imbtn{display:inherit;border:none;padding:0em;height:unset;height:unset;margin:0em;contain:unset;}
  675. header .imbtn:hover{border:none;color:%gray% !important;} header .imbtn img{display:none;}
  676. .b ul{font-size:1.4em;}
  677. no_pop{cursor:unset;}
  678. p{min-height:0.8em;}
  679. .bold,.bold *{font-weight:bold;}
  680. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  681. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;box-shadow: 0.5em 0px %white%;}
  682. .small_footer>div{overflow:auto;white-space:nowrap;}
  683. .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;}
  684. .top_post_hint{margin-left:0.5em;font-weight:bold;}
  685. .white{color:%white%;}
  686. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  687. .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;
  688. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  689. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.4));
  690. background-repeat:no-repeat;background-size:0% 100%;}
  691. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  692. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  693. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  694. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  695. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  696. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  697. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  698. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  699. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  700. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  701. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  702. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  703. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  704. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  705. .special_paypal_inner{color:#169bd7;}
  706. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  707. animation:anim_loading 1s linear infinite;}
  708. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  709. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  710. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  711. .product_thumb img,{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  712. .product_ref p{margin-bottom:0.2em;text-align:left;}
  713. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  714. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  715. .page_break{page-break-after:always;}
  716. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  717. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  718. .print_title{display:none;}.show_on_print{display:none;}.inline_print{display:none;}
  719. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  720. .comment tbody tr:hover{box-shadow:none;}
  721. .comment table{border:none;}
  722. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  723. .comment ul{padding-left:1em;}
  724. .comment ul li *{margin-bottom:0.5em;}
  725. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  726. .history li li{list-style:circle;}
  727. .history ul{padding-left:1em;}
  728. .history a{text-decoration:underline;}
  729. .history .list{overflow:auto;white-space:nowrap;}
  730. .diff_table{table-layout:fixed;}
  731. .diff_table thead{font-size:0.9em;text-align:center;}
  732. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  733. .diff_table td{vertical-align:top;}
  734. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  735. .wayback_close{float:right;}
  736. .wayback_expand{display:inline;}
  737. .post_selecting .post *{pointer-events:none;}
  738. .post_selected{background-color:%graybkg%;}
  739. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  740. .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%;}
  741. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  742. .wayback_link{display:inline;}
  743. .imd{object-fit:cover;width:100%;}
  744. .center_exp .post>.imd,.center_exp .p_row{width:60%;}
  745. .center_exp .p_thumb img,.center_exp .p_thumb video{max-height:3rem;}
  746. .center_exp .p_thumb{max-height:3rem;filter:opacity(40%);}
  747. .center_exp .p_thumb:hover{filter:unset;}
  748. #here_buttons{display:contents;}
  749. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  750. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  751. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  752. .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;}
  753. @media screen and (max-width:1000px) and (min-width:666px){
  754. .left{width:35%;}
  755. .center,.center_wide{width:65%;}
  756. .center_wide .p_thumb{height:8rem;margin-right:0.7em;margin-bottom:0.7em;box-shadow:3px 3px 12px 2px black;}
  757. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  758. .hidden_on_wide{display:unset;}
  759. .pop_right{width:30%;}
  760. .pop_right_big{width:40%;}
  761. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  762. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  763. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  764. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  765. .big_side_box{width:35%;}
  766. .big_image_box{width:65%;}
  767. .inquiry_buttons{right:35%;}
  768. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  769. .post_dummy > *{width:80%;max-width:55rem;}
  770. .center_exp .post>.imd,.center_exp .p_row{width:80%;max-width:55rem;}
  771. .here_btn{width:1.5em;height:1.5em;}
  772. }
  773. @media screen and (max-width:666px){
  774. html{font-size:16px;}
  775. #titlectrl:checked ~ header .mobile_fold{display:block !important;}
  776. #titlectrl:checked ~ .main .mobile_fold{display:block !important;}
  777. .mobile_fold{display:none !important;}
  778. .hidden_m{display:none !important;}
  779. .block_m{display:block !important;}
  780. .hidden_on_desktop{display:unset;}
  781. .hidden_on_wide{display:unset;}
  782. header{position:unset;}
  783. header ul{display:block;}
  784. header li{display:block;}
  785. header li::before{content:''}
  786. header::before{box-shadow:none;display:none;}
  787. .small_footer::before{box-shadow:none;display:none;}
  788. .left{position:relative;width:100%;top:unset;height:unset;max-height:unset;padding-right:0;display:block;}
  789. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  790. .center_wide .p_thumb{height:6rem;margin-right:0.5em;margin-bottom:0.5em;box-shadow:2px 2px 10px 1px black;}
  791. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  792. .pop_right{height:30%;}
  793. .pop_right_big{height:70%;}
  794. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  795. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  796. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  797. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  798. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  799. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  800. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  801. .side_box_mobile_inner:hover{background-size:100% 100%;}
  802. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  803. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  804. .p_thumb{height:3rem;}
  805. .center .post{padding-right:0rem;padding-left:0rem;}
  806. .post .p_thumb img,.post .p_thumb video{max-height:3rem;}
  807. .page,.page_gallery{padding:0.2em;padding-top:0;}
  808. header{padding-top:0.3em;}
  809. .toc_button{top:0.3em;}
  810. .small_footer{padding-bottom:0.3em;}
  811. .footer_additional{display:block;width:100%;}
  812. .album_hint{display:block;font-size:1rem;}
  813. .image_nav{position:absolute !important;}
  814. .image_nav_prev,.image_nav_next{width:25%;}
  815. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  816. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  817. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  818. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  819. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  820. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  821. .opt_compact,.ref_compact{line-break:anywhere;}
  822. .table_top{left:unset;width:100%;overflow:auto;}
  823. table img{max-width:30vw !important;}
  824. .product_ref{width:100%;display:block;}
  825. .post_dummy > *{width:100%;max-width:25rem;}
  826. .center_exp .post>.imd,.center_exp .p_row{width:100%;max-width:25rem;}
  827. .center_exp .post .p_thumb img,.center_exp .post .p_thumb video{max-height:2rem;}
  828. .center_exp .p_thumb{height:2rem;filter:opacity(40%);}
  829. .center_exp .p_thumb:hover{filter:unset;}
  830. .sticky_title{top:0;}
  831. .small_footer{position:relative;}
  832. #upload_selector{width:100%;}
  833. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  834. .wayback_expand{display:block;text-align:center;}
  835. .wayback_link{display:block;}
  836. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  837. .center_exp .post{overflow:auto;}
  838. .center_exp .imd{width:100%;}
  839. .here_btn{width:1.2em;height:1.2em;}
  840. .exp_h_f{height:unset !important;}
  841. .exp_f{margin-bottom:1em;}
  842. .linked_posts{padding-left:1em;}
  843. }
  844. @media print{
  845. .small_footer .hidden_on_print{display:none;}
  846. header b,.small_footer b{font-weight:normal;}
  847. header{display:table-header-group;box-shadow:none;} .main{display:table-row-group;} .small_footer{text-align:right;}
  848. header::before{box-shadow:none;display:none;} header::after{display:block;height:1em;content:' ';}
  849. .small_footer::before{box-shadow:none;display:block;height:1em;position:relative;}
  850. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  851. .bkg_section,.bkg_recent>.post,.active_post{background:none !important;box-shadow:none;}
  852. .post *,.post_dummy *{margin-bottom:0em;}
  853. .p_row,.post table,.post_width>img,.post_ref>img,.post_ref>.original_img,
  854. .post_width>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  855. pre{white-space:pre-wrap;line-break:anywhere;}
  856. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  857. table img{margin:0 !important;}
  858. .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;}
  859. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  860. table{border-bottom:2px solid black;border-top:2px solid black;}
  861. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  862. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  863. .linked_posts{display:none;}
  864. .post_width{overflow:clip;left:0;width:100%;padding-left:0em;padding-right:0em;}
  865. .post h1{margin-top:0.5rem;}
  866. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  867. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h3{margin:0 !important;}
  868. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  869. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  870. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  871. .left{display:none;}
  872. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  873. hr{border:1px solid black;}
  874. .post_box_top{display:none;}
  875. .post_access{display:none;}
  876. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;background:unset;}
  877. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  878. .hidden_on_print{display:none;}
  879. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  880. .opt_compact{margin-left:0;left:1.5em;}
  881. .post .post_ref{padding-left:2rem;}
  882. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  883. .print_title:first-of-type{margin-top:1em;}
  884. .print_title+.post h1:first-of-type{display:none;}
  885. .bkg_section .print_title+.post .post_width{padding-top:0;}
  886. .bkg_section .post:not(.print_title):first-of-type .post_width{padding-top:0;}
  887. .bkg_section .restart+.post .post_width{padding-top:0;}
  888. .restart{background-color:unset;padding:unset;}
  889. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  890. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  891. .header_nav{display:none;}
  892. .show_on_print{display:block;}.inline_print{display:inline;}
  893. blockquote{border-left:2px solid black;}
  894. .footer_additional{display:none;}
  895. .small_footer{margin-top:1rem;box-shadow:none;}
  896. .page{display:table;width:100%;}
  897. .page_selector{display:none;}
  898. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  899. .post .p_thumb img,.post .p_thumb video{max-height:4rem;}
  900. .sticky_title{box-shadow:none;}
  901. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  902. .center_wide .p_row{display:block;}
  903. .interesting_tbody{background:none;}
  904. .interesting_tbody img{display:none !important;}
  905. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  906. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  907. }
  908. ";
  909. //$this->style=preg_replace('/%highlight_white%/','#5b3607',$this->style);
  910. //$this->style=preg_replace('/%highlight_slice%/','#734307',$this->style);
  911. //$this->style=preg_replace('/%grayslice%/','#442c0b',$this->style);
  912. //$this->style=preg_replace('/%post_white%/','#2d2110',$this->style);
  913. //$this->style=preg_replace('/%white%/','#231a0d',$this->style);
  914. //$this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  915. //$this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  916. //$this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  917. //$this->style=preg_replace('/%shadow%/','#000000cc',$this->style);
  918. $this->style=preg_replace('/%highlight_white%/','#804a06',$this->style);
  919. $this->style=preg_replace('/%highlight_slice%/','#ae6407',$this->style);
  920. $this->style=preg_replace('/%grayslice%/','#6a491c',$this->style);
  921. $this->style=preg_replace('/%post_white%/','#4a3413',$this->style);
  922. $this->style=preg_replace('/%white%/','#2d2214',$this->style);
  923. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  924. $this->style=preg_replace('/%gray%/','#f8ca9b88',$this->style);
  925. $this->style=preg_replace('/%graybkg%/','#a9270e',$this->style);
  926. $this->style=preg_replace('/%shadow%/','#000000ee',$this->style);
  927. $f = fopen('styles/main.css','w');
  928. fwrite($f,$this->style);
  929. fclose($f);
  930. }
  931. function GiveSafeEMail(){
  932. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  933. }
  934. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  935. if(isset($this->Images[0])) foreach($this->Images as &$im){
  936. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  937. else { if($im['name']==$name) return $im; }
  938. }
  939. return $this->NULL_IMAGE;
  940. }
  941. function &GiveImageInHere($rand=false){
  942. $this->ReadImages(); $this->DetectPageType();
  943. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  944. if(!isset($album) || !$album){
  945. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  946. $imlist=[]; $imlist_fallback=[];
  947. if(isset($this->Images[0])){
  948. foreach($this->Images as &$im){
  949. if(isset($im['galleries'][0]) && in_array($album,$im['galleries']) && $this->CanShowImage($im)){
  950. if(!$rand) return $im; else {
  951. $imlist_fallback[] = $im;
  952. if(!in_array($im['name'],$this->VisitedHere)) $imlist[] = $im;
  953. }
  954. }
  955. }
  956. }
  957. if(!$rand || !isset($imlist_fallback[0])) return $this->NULL_IMAGE;
  958. if(sizeof($imlist)){
  959. $r = random_int(0, sizeof($imlist)-1);
  960. return $imlist[$r];
  961. }else{
  962. $r = random_int(0, sizeof($imlist_fallback)-1);
  963. return $imlist_fallback[$r];
  964. }
  965. }
  966. function ImageTitle($im){
  967. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  968. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  969. return $imtitle;
  970. }
  971. function ImageHasHere(&$im, $here_name){
  972. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  973. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  974. }
  975. function ReadImages($clear_non_exist = false){
  976. $path = 'images/list.md';
  977. if($this->DoneReadImages){ return; }
  978. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  979. $c = file_get_contents($path);
  980. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  981. $g=[]; $g['name']=$m[1];//$g['count']=0;
  982. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  983. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  984. if(preg_match('/DESCRIPTION\s+([^;]+);/u', $m[2], $arg)){ $g['description']=$arg[1]; }
  985. $this->Galleries[] = $g;
  986. }
  987. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  988. $name = trim($m[1]);
  989. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  990. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  991. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  992. $item['refs']=[];
  993. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  994. }
  995. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  996. $item['galleries']=[];
  997. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  998. }
  999. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  1000. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  1001. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  1002. if(preg_match('/ALIGN\s+([^;]*);/u',$m[2],$align)){ $item['align']=$align[1]; }
  1003. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  1004. $item['here']=[];
  1005. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  1006. }
  1007. if(preg_match('/\.mp4/u',$item['name'])){
  1008. $item['video']='video/mp4';
  1009. }
  1010. $this->Images[] = $item;
  1011. }
  1012. $files = array_merge([],glob('images/*.jpg'));
  1013. $files = array_merge($files,glob('images/*.jpeg'));
  1014. $files = array_merge($files,glob('images/*.png'));
  1015. $files = array_merge($files,glob('images/*.gif'));
  1016. $files = array_merge($files,glob('images/*.mp4'));
  1017. if(isset($files[0]))foreach($files as $file) {
  1018. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png|mp4)/u', $file, $m)) {
  1019. $name = trim($m[0]);
  1020. if(!$this->FindImage($name)){
  1021. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  1022. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  1023. $this->Images[] = $item;
  1024. }
  1025. }
  1026. }
  1027. if($clear_non_exist){
  1028. if(isset($this->Images[0]) && isset($files[0])){
  1029. foreach($this->Images as &$im){
  1030. if(!in_array($im['file'],$files)){
  1031. $im['deleted'] = 1;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. function cmpf($a, $b){
  1037. if ($a['name'] == $b['name']) return 0;
  1038. return (($a['name'] > $b['name']) ? 1 : -1);
  1039. }
  1040. function cmpaf($a, $b){
  1041. if ($a['name'] == $b['name']) return 0;
  1042. return ($a['name'] > $b['name']) ? -1 : 1;
  1043. }
  1044. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  1045. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  1046. $this->DoneReadImages = 1;
  1047. }
  1048. function WriteImages(){
  1049. if(isset($this->WayBack)) return;
  1050. $path = 'images/list.md';
  1051. $f = fopen($path,'w');
  1052. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  1053. if(isset($g['deleted'])) continue;
  1054. fwrite($f,'GALLERY '.$g['name']);
  1055. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  1056. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  1057. if(isset($g['description']) && $g['description']!="") { fwrite($f,' DESCRIPTION '.$g['description'].';'); }
  1058. fwrite($f, PHP_EOL);
  1059. }
  1060. if(isset($this->Images[0]))foreach($this->Images as &$im){
  1061. if(isset($im['deleted'])) continue;
  1062. fwrite($f, "- ".$im['name'].'; ');
  1063. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  1064. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  1065. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  1066. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  1067. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  1068. if(isset($im['align']) && $im['align']!='' && $im['align']!='middle'){ fwrite($f, 'ALIGN '.$im['align']."; "); }
  1069. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  1070. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  1071. }
  1072. fwrite($f, PHP_EOL);
  1073. }
  1074. fflush($f);
  1075. fclose($f);
  1076. }
  1077. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL, $align=NULL){
  1078. if(!($im = &$this->FindImage($name))) return;
  1079. if(isset($link_gallery)){
  1080. if($do_remove){
  1081. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  1082. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  1083. $im['galleries'] = array_merge($im['galleries']);
  1084. }else{
  1085. if(!isset($im['galleries'])) $im['galleries']=[];
  1086. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  1087. $im['galleries'][]=$link_gallery;
  1088. }
  1089. }
  1090. if(isset($product_link)){
  1091. if($product_link!=''){$im['product']=$product_link;}
  1092. else{unset($im['product']);}
  1093. }
  1094. if(isset($rename) && $rename!=$im['name']){
  1095. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1096. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1097. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1098. $im['name'] = $rename.'.'.$ext;
  1099. }
  1100. if(isset($parent) && $parent!=$im['parent']){
  1101. if($parent==''){ unset($im['parent']); }
  1102. else{ $im['parent'] = $parent; }
  1103. }
  1104. if(isset($align) && in_array($align,['top','middle','bottom'])){
  1105. if($align=='middle'){ unset($im['align']); }
  1106. else{ $im['align']=$align; }
  1107. }
  1108. $this->NeedWriteImages = 1;
  1109. }
  1110. function RegenerateThumbnails(){
  1111. $glob = glob('images/*.jpg');
  1112. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1113. foreach($glob as $file) {
  1114. $thumb_destination = 'images/thumb/'.basename($file);
  1115. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1116. $width=$geo['width']; $height=$geo['height'];
  1117. $lim=400;
  1118. $scale = $lim / min($width,$height);
  1119. if($scale<1){
  1120. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1121. }
  1122. $img->setImageFormat('jpeg');
  1123. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1124. $img->setImageCompressionQuality(90);
  1125. $img->writeImage($thumb_destination);
  1126. }
  1127. }
  1128. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max, $ext) {
  1129. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1130. $width=$geo['width']; $height=$geo['height'];
  1131. $lim=400;
  1132. $scale = $lim / min($width,$height);
  1133. if($scale<1){
  1134. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1135. }
  1136. $img->setImageFormat('jpeg');
  1137. $img->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1138. $img->setImageCompressionQuality($quality);
  1139. $img->writeImage($thumb_destination);
  1140. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1141. if($scale<1){
  1142. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1143. }
  1144. if($ext!='jpg'){
  1145. $img2->setImageFormat('jpeg');
  1146. $img2->setImageCompressionQuality($quality);
  1147. $img2->setInterlaceScheme(Imagick::INTERLACE_PLANE);
  1148. $img2->writeImage($destination);
  1149. }else{
  1150. rename($source,$destination);
  1151. }
  1152. }
  1153. function DoUpload(){
  1154. if(!isset($_FILES['upload_file_name'])) return 0;
  1155. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1156. if($_FILES['upload_file_name']['error']>0){
  1157. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1158. return -1;
  1159. }else{
  1160. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  1161. if(!in_array($ext,['jpg','JPG','jpeg','png','gif','mp4'])) return 0;
  1162. $fp = fopen('.la_lock',"w");
  1163. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1164. usleep(10000);
  1165. }
  1166. $num=date('YmdHis'); $replace=0;
  1167. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1168. $num = $mim[1]; $replace=1;
  1169. }
  1170. $base = 'images/'.$num;
  1171. $thumb = 'images/thumb/'.$num;
  1172. $use_ext=($ext=='gif' || $ext=='mp4')?('.'.strtolower($ext)):('.jpg');
  1173. $final_path = $base.$use_ext; $final_thumb = $thumb.$use_ext; $i=0;
  1174. if(!$replace) while(file_exists($final_path)){
  1175. $final_path = $base.strval($i).$use_ext; $final_thumb = $thumb.strval($i).$use_ext; $i++;
  1176. }
  1177. if($ext!='gif' && $ext!='mp4'){
  1178. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1179. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1180. $compress?800:1920, $compress?1920:2560, $ext);
  1181. }else{
  1182. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1183. }
  1184. flock($fp, LOCK_UN);
  1185. fclose($fp);
  1186. $this->ReadImages(true);
  1187. $this->WriteImages();
  1188. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1189. if(isset($_POST['image_replace_button'])){
  1190. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1191. }
  1192. exit;
  1193. return 1;
  1194. }
  1195. return 0;
  1196. }
  1197. function &GetGallery($name){
  1198. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1199. if($g['name'] == $name) return $g;
  1200. }
  1201. return $this->NULL_GALLERY;
  1202. }
  1203. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null,$desc=null){
  1204. $this->ReadImages();
  1205. $gallery = &$this->GetGallery($name);
  1206. if(!isset($gallery)){
  1207. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1208. $g = []; $g['name']=$new_name;
  1209. $this->Galleries[]=$g;
  1210. }else{
  1211. if(isset($new_name)) {
  1212. if(preg_match('/main|trash|\s/u',$new_name))return;
  1213. $gallery['name'] = $new_name;
  1214. foreach ($this->Images as &$im){
  1215. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1216. if($g == $name){ $g = $new_name; }
  1217. }
  1218. }
  1219. }
  1220. //if(isset($count)) $gallery['count'] = $count;
  1221. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1222. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1223. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1224. if(isset($desc)) $gallery['description'] = $desc;
  1225. }
  1226. if($do_rw) { $this->NeedWriteImages = 1; }
  1227. }
  1228. function ClearData(){
  1229. $this->Posts = [];
  1230. $this->Threads = [];
  1231. $this->Images = [];
  1232. $this->Archive = [];
  1233. $this->ArchiveHandles = [];
  1234. }
  1235. function InsertArchivePost(&$post){
  1236. $a = NULL;
  1237. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1238. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1239. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1240. }
  1241. $a['list'][] = $post;
  1242. $this->Archive[] = $post;
  1243. }
  1244. function ReadArchiveFromFile($path){
  1245. if(!file_exists($path)){
  1246. return;
  1247. }
  1248. $c = file_get_contents($path);
  1249. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1250. foreach($matches as $m){
  1251. $post = [];
  1252. $post['id'] = $m[1];
  1253. $post['content'] = trim($m[3]);
  1254. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1255. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1256. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1257. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1258. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1259. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1260. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1261. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1262. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1263. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1264. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1265. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1266. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1267. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1268. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1269. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1270. }
  1271. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1272. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1273. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1274. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1275. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1276. }
  1277. $this->InsertArchivePost($post);
  1278. }
  1279. }
  1280. }
  1281. function SortArchive(){
  1282. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1283. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1284. return (($a['id'] > $b['id']) ? 1 : -1);
  1285. };
  1286. if(isset($this->Archive[0])){
  1287. usort($this->Archive,$cmpap);
  1288. $year_begin = substr($this->Archive[0]['id'],0,4);
  1289. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1290. }
  1291. if(isset($this->ArchiveHandles[0])){
  1292. usort($this->ArchiveHandles,$cmpac);
  1293. foreach($this->ArchiveHandles as &$a){
  1294. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1295. $last_valid=NULL;
  1296. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1297. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1298. else{ $last_valid = $ver['content']; } }
  1299. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1300. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1301. }
  1302. }
  1303. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1304. $p['archive'] = &$a;
  1305. }
  1306. }
  1307. }
  1308. }
  1309. function ReadPostsFromFile($path){
  1310. if(!file_exists($path)){
  1311. $f = fopen($path,'w');
  1312. fclose($f);
  1313. }
  1314. $c = file_get_contents($path);
  1315. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1316. foreach($matches as $m){
  1317. $post = [];
  1318. $post['id'] = $m[1];
  1319. $post['real_content'] = trim($m[3]);
  1320. $post['content'] = &$post['real_content'];
  1321. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1322. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1323. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1324. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1325. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1326. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1327. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1328. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1329. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1330. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1331. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1332. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1333. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1334. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1335. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1336. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1337. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1338. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1339. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1340. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1341. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1342. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1343. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1344. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1345. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1346. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1347. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1348. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1349. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1350. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1351. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1352. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1353. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1354. }
  1355. if(isset($post['mark_value']) && $post['mark_value']==5){
  1356. $post['product']=[];
  1357. }
  1358. /* marks add here */
  1359. $this->Posts[] = $post;
  1360. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1361. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1362. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1363. }
  1364. }
  1365. }
  1366. }
  1367. function SortPosts($wayback=false){
  1368. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1369. $sortlist = &$this->Posts;
  1370. if($wayback) $sortlist = &$this->WaybackPosts;
  1371. if(isset($sortlist[0])){
  1372. usort($sortlist,$cmpp);
  1373. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1374. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1375. }
  1376. }
  1377. function ReadPosts(){
  1378. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1379. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1380. (!is_dir('posts') || is_readable('posts') == false) ||
  1381. (!is_dir('archive') || is_readable('archive') == false) ||
  1382. (!is_dir('images') || is_readable('images') == false) ||
  1383. (!is_dir('styles') || is_readable('styles') == false)){
  1384. $this->Install();
  1385. }
  1386. if($this->DoneReadPosts){ return; }
  1387. $file_list = [];
  1388. $glob = glob('posts/*');
  1389. foreach($glob as $file) {
  1390. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1391. $file_list[] = $file;
  1392. }
  1393. }
  1394. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1395. foreach($file_list as $f) {
  1396. $this->ReadPostsFromFile($f);
  1397. }
  1398. $this->SortPosts();
  1399. $this->DetectThreads();
  1400. $this->DoneReadPosts=1;
  1401. }
  1402. function UpdatePostRefsForWayback(){
  1403. if(!isset($this->WayBack)) return;
  1404. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1405. if(!isset($this->WaybackPosts[0])) return;
  1406. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1407. foreach($this->WaybackPosts as &$p){
  1408. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1409. $pr = &$this->GetPost($r); if(isset($pr)){
  1410. if(!isset($pr['refs'])) $pr['refs']=[];
  1411. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1412. }
  1413. }
  1414. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1415. $ir = &$this->FindImage($r); if(isset($ir)){
  1416. if(!isset($ir['refs'])) $ir['refs']=[];
  1417. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1418. }
  1419. }
  1420. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1421. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1422. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1423. }
  1424. }
  1425. }
  1426. function ReadArchive(){
  1427. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1428. if ($this->DoneReadArchive) return;
  1429. $file_list = []; $glob = glob('archive/*');
  1430. foreach($glob as $file) {
  1431. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1432. $file_list[] = $file;
  1433. }
  1434. }
  1435. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1436. foreach($file_list as $f) {
  1437. $this->ReadArchiveFromFile($f);
  1438. }
  1439. $this->SortArchive();
  1440. $this->DoneReadArchive=1;
  1441. $this->UpdateThreadForWayback();
  1442. $this->UpdatePostRefsForWayback();
  1443. }
  1444. function GetThreadForPost(&$post){
  1445. if(isset($post['tid'])) return;
  1446. $th = []; $iterp = NULL;
  1447. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1448. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1449. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1450. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1451. $np['tid'] = &$th;
  1452. $th['first'] = &$np;
  1453. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1454. }
  1455. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1456. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1457. $np['tid'] = &$th;
  1458. $th['last'] = &$np;
  1459. $iterp = isset($np['next'])?$np['next']:NULL;
  1460. }
  1461. if(isset($th['first']['mark_value'])){
  1462. if($th['first']['mark_value']==6) $th['exp'] = true;
  1463. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1464. }
  1465. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1466. $this->Threads[] = &$th;
  1467. }
  1468. function IdentifyThreadCategory(&$th,&$first_post){
  1469. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1470. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1471. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1472. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1473. }
  1474. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1475. }
  1476. if(preg_match('/\{\s*WIDE\s*\}/imu',$first_post['content'],$m)){ $first_post['wide'] = true; }
  1477. if(preg_match('/\{\s*NO_TIME\s*\}/imu',$first_post['content'],$m)){ $first_post['no_time'] = true; }
  1478. if(preg_match('/\{\s*NO_TITLE\s*\}/imu',$first_post['content'],$m)){ $first_post['no_title'] = true; }
  1479. if(preg_match('/\{\s*SLIDES\s*\}/imu',$first_post['content'],$m)){ $first_post['slides'] = true; }
  1480. if(preg_match('/\{\s*HEADER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['header'] = trim($m[1]); }
  1481. if(preg_match('/\{\s*FOOTER\s+(.*?)\}/imu',$first_post['content'],$m)){ $first_post['footer'] = trim($m[1]); }
  1482. if(!isset($th)) return;
  1483. if(isset($first_post['wide'])) $th['wide']=$first_post['wide'];
  1484. if(isset($first_post['header'])) $th['header']=$first_post['header'];
  1485. if(isset($first_post['footer'])) $th['footer']=$first_post['footer'];
  1486. if(isset($first_post['no_time'])) $th['no_time']=$first_post['no_time'];
  1487. if(isset($first_post['slides'])) $th['slides']=$first_post['slides'];
  1488. if(isset($first_post['no_title'])) $th['no_title']=$first_post['no_title'];
  1489. if(preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1490. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1491. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1492. }
  1493. }
  1494. if(preg_match('/\{\s*REVERSED(\s+.*?)?\}/imu',$first_post['content'],$m)){ $th['reversed'] = 'm';
  1495. if(isset($m[1])&&preg_match('/^\s*(y|m|d|p)/iu',$m[1],$ma)){ $th['reversed']=$ma[1]; }
  1496. }
  1497. }
  1498. function IsInterestingPost(&$p){
  1499. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1500. return false;
  1501. }
  1502. function IsReversedThread(&$th){
  1503. if(isset($th['reversed']) && $th['reversed']!=false) return true;
  1504. return false;
  1505. }
  1506. function GiveAllMergedPosts(&$po,&$arr){
  1507. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1508. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1509. }
  1510. if(isset($po['archive']) && isset($po['archive']['list'])){
  1511. foreach($po['archive']['list'] as &$ver){
  1512. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1513. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1514. }
  1515. }
  1516. }
  1517. function ThreadMakeWayback(&$th){
  1518. if(!isset($th['arr'][0])) return;
  1519. if(isset($this->WayBack)){
  1520. $remlist = [];
  1521. foreach($th['arr'] as &$pi){
  1522. $po = &$this->GetPost($pi['id'],true); if(!isset($po)){continue;/*merged*/}
  1523. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1524. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1525. }
  1526. $ah = &$this->GetArchiveHandle($po['id']);
  1527. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1528. if(!isset($ver['merged_thread'])) continue;
  1529. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1530. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1531. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1532. }
  1533. }
  1534. }
  1535. if(isset($remlist[0]) && isset($th['arr'][0])){
  1536. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1537. foreach($th['arr'] as $key => $pr){
  1538. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1539. $new_th = []; $new_arr = [];
  1540. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1541. $new_th['arr'] = &$new_arr;
  1542. $this->WaybackThreads[] = &$new_th;
  1543. $this->ThreadMakeWayback($new_th);
  1544. }
  1545. }
  1546. }
  1547. function AddMergedPosts(&$p, &$array){
  1548. if(isset($p['archive']) && isset($p['archive']['list'])){
  1549. foreach($p['archive']['list'] as &$ver){
  1550. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1551. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1552. }
  1553. }
  1554. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1555. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1556. }
  1557. function &array_shift_ref(&$array){if(count($array)>0){$key=key($array);$first=&$array[$key];}else{$first=null;}array_shift($array);return $first;}
  1558. function FinalizeThread(&$th, $relink_posts=false, $now){
  1559. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1560. if(!isset($th['arr'])){
  1561. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1562. $arr[]=&$p;
  1563. } $th['arr'] = &$arr;
  1564. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1565. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1566. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1567. $arr=&$new_arr; $th['arr']=&$new_arr;
  1568. $this->ThreadMakeWayback($th); }
  1569. }
  1570. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1571. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1572. if($relink_posts){ $count = $th['count'];
  1573. $arr = &$th['arr'];
  1574. 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'];
  1575. $arr[$i]['tid']=&$th;}
  1576. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1577. }
  1578. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1579. $this->IdentifyThreadCategory($th, $th['first']);
  1580. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1581. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1582. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1583. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1584. if(isset($th['reversed'])){ $chunks=[]; $last_id=$last_y=$last_m=$last_d=0; $mo=$th['reversed']; $final=[];
  1585. $first_post=&$this->array_shift_ref($th['arr']); $ch=[];
  1586. while($n=&$this->array_shift_ref($th['arr'])){
  1587. $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);
  1588. if($mo=='y'&&$this_y!=$last_y){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y; }
  1589. if($mo=='m'&&$this_m!=$last_m){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m; }
  1590. if($mo=='d'&&$this_d!=$last_d){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} $n['restart']=$this_y.'/'.$this_m.'/'.$this_d; }
  1591. if($mo=='p'){ if(isset($ch[0])){$chunks[]=$ch;$ch=[];} }
  1592. $ch[]=&$n; $last_id=$this_id; $last_y=$this_y; $last_m=$this_m; $last_d=$this_d;
  1593. }if(isset($ch[0])){$chunks[]=$ch;} if(isset($chunks[0])){$use_chunks=array_reverse($chunks);}
  1594. $final[]=&$first_post;
  1595. foreach($use_chunks as &$ch){ foreach($ch as &$p){ $final[]=&$p;} }
  1596. $th['arr']=$final; }
  1597. }
  1598. function SortThreads(){
  1599. if (!function_exists('cmpt')) {
  1600. function cmpt($a, $b){
  1601. if ($a['score'] == $b['score']) return 0;
  1602. return ($a['score'] > $b['score']) ? -1 : 1;
  1603. }
  1604. }
  1605. usort($this->Threads,"cmpt");
  1606. }
  1607. function DetectThreads(){
  1608. foreach($this->Posts as &$p){
  1609. if(isset($p['tid'])) { continue; }
  1610. $this->GetThreadForPost($p);
  1611. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1612. }
  1613. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1614. $now = date_timestamp_get(date_create());
  1615. foreach($this->Threads as &$t){
  1616. $this->FinalizeThread($t,false,$now);
  1617. }
  1618. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1619. $this->FinalizeThread($th,false,$now);
  1620. $this->Threads[] = &$th;
  1621. }
  1622. $this->SortThreads();
  1623. }
  1624. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1625. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1626. foreach($this->Threads as &$t){
  1627. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1628. }
  1629. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1630. $this->FinalizeThread($th,true,$now);
  1631. $this->Threads[] = &$th;
  1632. }
  1633. $this->SortThreads();
  1634. $this->SortPosts(true);
  1635. $this->UsePosts = &$this->WaybackPosts;
  1636. }
  1637. function &GetMergedPost($id){
  1638. $this->ReadArchive();
  1639. $ah = &$this->GetArchiveHandle($id);
  1640. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1641. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1642. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1643. [$tp, $tver] = $ver['merged_into'];
  1644. if(isset($this->WayBack)){
  1645. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1646. else return $this->GetPost($id); /* should not happen directly. */
  1647. }
  1648. return $this->GetMergedPost($tp);
  1649. }
  1650. function &GetPost($id, $latest_only=false, $find_merged=false){
  1651. if(!isset($id)) return $this->NULL_POST;
  1652. $found=&$this->NULL_POST;
  1653. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1654. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1655. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1656. }
  1657. if($latest_only || !isset($this->WayBack)){ return $found; }
  1658. else{
  1659. if(isset($found)){
  1660. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1661. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1662. $last_ver = &$this->NULL_POST;
  1663. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1664. if($ver['version'] > $this->WayBack) return $last_ver;
  1665. $last_ver = &$ver;
  1666. }
  1667. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1668. else return $last_ver;
  1669. }else{
  1670. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1671. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1672. if($ver['version'] > $this->WayBack) return $last_ver;
  1673. $last_ver = &$ver;
  1674. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1675. [$tp, $tver] = $last_ver['merged_into'];
  1676. if($tver <= $this->WayBack) {
  1677. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1678. return $last_ver;
  1679. }
  1680. }
  1681. }
  1682. return $this->NULL_POST;
  1683. }
  1684. function &GetArchiveHandle($id){
  1685. if(!isset($id)) return $this->NULL_POST;
  1686. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1687. if($p && $p['id'] == $id) { return $p; }
  1688. }
  1689. return $this->NULL_POST;
  1690. }
  1691. function &GetArchive($id){
  1692. if(!isset($id)) return $this->NULL_POST;
  1693. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1694. if($p && $p['id'] == $id) { return $p; }
  1695. }
  1696. return $this->NULL_POST;
  1697. }
  1698. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1699. if(!isset($ah)) return $this->NULL_POST;
  1700. $found = NULL; $last_verp=NULL;
  1701. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1702. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1703. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1704. $last_verp = &$p;
  1705. }
  1706. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1707. return $this->NULL_POST;
  1708. }
  1709. function CacheArchiveOwnLinks(){
  1710. if(isset($this->WayBack)) return;
  1711. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1712. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1713. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1714. foreach($matches as $m){
  1715. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1716. }
  1717. }
  1718. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1719. foreach($matches as $m){
  1720. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1721. }
  1722. }
  1723. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1724. foreach($matches as $m){
  1725. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. function WriteArchive(){
  1731. if(isset($this->WayBack)) return;
  1732. $cf = NULL;$opened =NULL;
  1733. $this->SortArchive();
  1734. $this->CacheArchiveOwnLinks();
  1735. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1736. $nid = substr($p['id'], 0,6);
  1737. if($cf != $nid){
  1738. if($opened){
  1739. fflush($opened);
  1740. fclose($opened);
  1741. }
  1742. $cf = $nid;
  1743. $opened = fopen("archive/$cf.md", 'w');
  1744. }
  1745. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1746. "VER {$p['version']}; ".
  1747. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1748. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1749. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1750. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1751. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1752. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1753. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1754. ']';
  1755. if(isset($p['merged_thread'])){ $p['content']=""; }
  1756. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1757. }
  1758. }
  1759. function WritePosts(){
  1760. if(isset($this->WayBack)) return;
  1761. $cf = NULL;$opened =NULL;
  1762. $this->SortPosts();
  1763. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1764. $nid = substr($p['id'], 0,6);
  1765. if($cf != $nid){
  1766. if($opened){
  1767. fflush($opened);
  1768. fclose($opened);
  1769. }
  1770. $cf = $nid;
  1771. $opened = fopen("posts/$cf.md", 'w');
  1772. }
  1773. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1774. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1775. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1776. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1777. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1778. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1779. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1780. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1781. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1782. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1783. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1784. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1785. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1786. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1787. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1788. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1789. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1790. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1791. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1792. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1793. ']';
  1794. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1795. }
  1796. }
  1797. function CachePostLinks(){
  1798. if(isset($this->WayBack)) return;
  1799. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1800. $this->ConvertPost($post);
  1801. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1802. //discard lost old version
  1803. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1804. }else return;
  1805. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1806. unset($im['refs']); unset($im['here']); unset($im['title']);
  1807. }
  1808. foreach ($this->Posts as &$post){
  1809. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1810. foreach($matches as $m){
  1811. $ref = &$this->GetPost($m[1],true);
  1812. if($ref!=NULL){
  1813. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1814. }
  1815. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1816. }
  1817. }
  1818. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1819. foreach($matches as $m){
  1820. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1821. }
  1822. }
  1823. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1824. foreach($matches as $m){
  1825. if(($im = &$this->FindImage($m[2]))!=NULL){
  1826. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1827. }
  1828. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1829. }
  1830. }
  1831. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif|mp4))\))(\R*(\R(-|\*).+){1,})/u",
  1832. $post['content'],$matches)){
  1833. $use_img_name = $matches[2];
  1834. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1835. 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",
  1836. $matches[4],$mah,PREG_SET_ORDER)){
  1837. foreach($mah as $ma){
  1838. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1839. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }foreach($this->Posts as &$post){
  1845. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1846. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1847. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1848. }
  1849. }
  1850. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1851. $min_id = '99999999999999';
  1852. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1853. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1854. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1855. }
  1856. }
  1857. }
  1858. function CreatePostAnchor(&$post){
  1859. $that=&$this;
  1860. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1861. $id = '_heading_'.sizeof($this->Anchors);
  1862. $entry=[(int)$ma[1], $id, $ma[2]];
  1863. $that->Anchors[] = $entry;
  1864. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1865. }, $post['html']);
  1866. }
  1867. function RenamePost(&$post, $rename){
  1868. foreach($this->Posts as &$p){
  1869. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1870. }
  1871. foreach($this->Posts as &$p){
  1872. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1873. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1874. }
  1875. $post['id'] = $rename;
  1876. }
  1877. function DetachPost(&$th,&$post){
  1878. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1879. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1880. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1881. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1882. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1883. unset($th['arr']); $now = date_timestamp_get(date_create());
  1884. $this->FinalizeThread($th, true, $now);
  1885. }
  1886. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1887. $a = &$this->GetArchiveHandle($post['id']);
  1888. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1889. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1890. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1891. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1892. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1893. $post['version'] = $optime_id;
  1894. if($mode==1){
  1895. $this->InsertArchivePost($ap);
  1896. }else if($mode==2){
  1897. $post['merged_from'] = $info;
  1898. $this->InsertArchivePost($ap);
  1899. }else if($mode==3){
  1900. $ap['merged_into'] = $info;
  1901. $this->InsertArchivePost($ap);
  1902. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1903. $this->DetachPost($post['tid'], $post);
  1904. }
  1905. }else if($mode==4){
  1906. $post['merged_thread'] = $info;
  1907. $this->InsertArchivePost($ap);
  1908. }
  1909. }
  1910. function &MergeThreads($post_id, $post_into_id){
  1911. $this->ReadPosts();
  1912. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1913. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1914. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1915. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1916. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1917. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1918. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1919. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1920. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  1921. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1922. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1923. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1924. $tt['count'] = sizeof($tt['arr']);
  1925. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1926. $first_post = &$this->NULL_POST;
  1927. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1928. $this->NeedWritePosts=1;
  1929. $this->NeedWriteArchive=1;
  1930. return $first_post;
  1931. }
  1932. function &MergePosts($ids_string){
  1933. $ids = explode(" ", $ids_string);
  1934. $combined_content = ""; $first_id=NULL;
  1935. $this->ReadPosts(); $child_list=[];
  1936. foreach($ids as $id){
  1937. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1938. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1939. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  1940. }
  1941. if(!isset($child_list[0])) return $this->NULL_POST;
  1942. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  1943. foreach($child_list as $id){
  1944. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  1945. }
  1946. $this->NeedWritePosts=1;
  1947. $this->NeedWriteArchive=1;
  1948. return $first_post;
  1949. }
  1950. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1951. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1952. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1953. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  1954. $this->ReadImages();
  1955. $this->ReadPosts();
  1956. if(isset($push_version) && $push_version){
  1957. $this->ReadArchive();
  1958. }
  1959. $p_success = NULL;
  1960. if(isset($id_if_edit)){
  1961. $post = &$this->GetPost($id_if_edit,true);
  1962. if($post===$this->NULL_POST) return $this->NULL_POST;
  1963. if($get_original_only){
  1964. return $post['real_content'];
  1965. }
  1966. if(isset($push_version) && $push_version){
  1967. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1968. }
  1969. if(isset($content)) {$post['real_content'] = $content; $post['content'] = &$post['real_content'];}
  1970. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1971. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1972. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1973. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  1974. $p_success = &$post;
  1975. }else{
  1976. if(!isset($content)) return $this->NULL_POST;
  1977. $id = date('YmdHis');
  1978. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1979. $post = []; $post['id'] = $id;
  1980. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1981. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1982. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1983. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1984. }
  1985. $this->Posts[] = $post;
  1986. $p_success = &$this->Posts[count($this->Posts) - 1];
  1987. }
  1988. $this->NeedWritePosts=1;
  1989. $this->NeedWriteImages=1;
  1990. if(isset($push_version) && $push_version){
  1991. $this->NeedWriteArchive=1;
  1992. }
  1993. return $p_success;
  1994. }
  1995. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1996. $this->ReadPosts();
  1997. $p_success = NULL;
  1998. if(isset($id_if_edit)){
  1999. $post = &$this->GetPost($id_if_edit,true);
  2000. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  2001. if(isset($content)) $post['content'] = $content;
  2002. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  2003. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  2004. if(isset($ip)) $post['ip'] = $ip;
  2005. $p_success = &$post;
  2006. }else{
  2007. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  2008. $id = date('YmdHis');
  2009. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  2010. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  2011. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  2012. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  2013. if(isset($ip)) $post['ip'] = $ip;
  2014. $this->Posts[] = $post;
  2015. $p_success = &$this->Posts[count($this->Posts) - 1];
  2016. }
  2017. $this->NeedWritePosts=1;
  2018. return $p_success;
  2019. }
  2020. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  2021. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  2022. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  2023. function($matches){
  2024. $rep = preg_replace('/->/','-@>',$matches[0]);
  2025. $rep = preg_replace('/=>/','=@>',$rep);
  2026. $rep = preg_replace('/<=/','<@=',$rep);
  2027. $rep = preg_replace('/<-/','<@-',$rep);
  2028. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  2029. $rep = preg_replace('/\[-/','[@-',$rep);
  2030. $rep = preg_replace('/\{/','{@',$rep);
  2031. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  2032. return $rep;
  2033. },
  2034. $replacement);
  2035. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  2036. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  2037. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  2038. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  2039. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  2040. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  2041. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  2042. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  2043. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  2044. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  2045. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  2046. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  2047. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  2048. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  2049. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  2050. function($matches){
  2051. $rep = preg_replace('/-@>/','->',$matches[0]);
  2052. $rep = preg_replace('/<@-/','<-',$rep);
  2053. $rep = preg_replace('/=@>/','=>',$rep);
  2054. $rep = preg_replace('/<@=/','<=',$rep);
  2055. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  2056. $rep = preg_replace('/\[@-/','[-',$rep);
  2057. $rep = preg_replace('/\{@/','{',$rep);
  2058. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  2059. return $rep;
  2060. }, $replacement);
  2061. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  2062. function($matches) use (&$post_for_it_is_here){
  2063. $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]);
  2064. return $matches[1].$rep;
  2065. }, $replacement);
  2066. return $replacement;
  2067. }
  2068. function CanShowPost(&$p){
  2069. if(!isset($p) || isset($p['comment_to'])) return false;
  2070. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  2071. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  2072. if($is_mark_slf && !$this->LoggedIn){ return false; }
  2073. if(isset($this->WayBack)){
  2074. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  2075. else if ($p['id']>$this->WayBack) return false;
  2076. }
  2077. if(!$this->InExperimentalMode){
  2078. if(!$this->LoggedIn){
  2079. if($is_mark_exp) return false;
  2080. return true;
  2081. }
  2082. return true;
  2083. }else{
  2084. if($is_mark_exp) return true;
  2085. return false;
  2086. }
  2087. }
  2088. function SkipProduct(&$p){
  2089. if($this->LoggedIn) return false;
  2090. return (isset($p['mark_value']) && $p['mark_value']==5);
  2091. }
  2092. function GetRedirect($args=NULL){
  2093. $str = 'index.php?';
  2094. if(isset($args['post'])) $str.='&post='.$args['post'];
  2095. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  2096. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  2097. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  2098. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  2099. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  2100. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  2101. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  2102. if(isset($args['statistics'])) $str.='&statistics='.$args['statistics'];
  2103. else if(isset($_GET['statistics'])) $str.='&statistics='.$_GET['statistics'];
  2104. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  2105. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  2106. if(isset($args['category'])) $str.='&category='.$args['category'];
  2107. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  2108. if(isset($args['history'])) $str.='&history='.$args['history'];
  2109. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  2110. if(isset($args['version'])) $str.='&version='.$args['version'];
  2111. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  2112. if(isset($args['search'])) $str.='&search='.$args['search'];
  2113. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  2114. if(isset($args['here'])) $str.='&here='.$args['here'];
  2115. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  2116. return $str;
  2117. }
  2118. function WriteAsNecessary(){
  2119. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  2120. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  2121. if($this->NeedWriteImages){ $this->WriteImages(); }
  2122. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  2123. }
  2124. function APubEnsureWebfinger($name, $host){
  2125. if(!is_dir('.well-known')) mkdir('.well-known');
  2126. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  2127. $f = fopen('.well-known/webfinger/index.php',"w");
  2128. $without_protocol = parse_url($host, PHP_URL_HOST);
  2129. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  2130. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  2131. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  2132. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2133. $res = openssl_pkey_new();
  2134. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2135. openssl_pkey_export($res, $this->APubPrivateKey);
  2136. $f = fopen('.well-known/apub_public_key.pem',"w");
  2137. fwrite($f, $this->APubPublicKey); fclose($f);
  2138. $f = fopen('.well-known/apub_private_key.php',"w");
  2139. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2140. }
  2141. }
  2142. function APubInit(){
  2143. $kf = file_get_contents('.well-known/apub_private_key.php'); if($kf===false) return;
  2144. preg_match("/(-----BEGIN PRIVATE KEY-----[\s\S]*)/",$kf,$ma); $this->APubPrivateKey=$ma[1];
  2145. }
  2146. function APubEnsureInfo(){
  2147. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2148. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2149. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2150. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2151. "id"=> $this->HostURL."?apub_actor=1",
  2152. "type"=> "Person",
  2153. "name"=> $this->DisplayName,
  2154. "url"=> $this->HostURL,
  2155. "summary"=> "Lazy... No summary",
  2156. "preferredUsername"=> $this->APubID,
  2157. "inbox"=> $this->HostURL."?apub_inbox=1",
  2158. "outbox"=> $this->HostURL."?apub_outbox=1",
  2159. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2160. "owner"=> $this->HostURL."?apub_actor=1",
  2161. "publicKeyPem"=>$pk]];
  2162. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2163. }
  2164. function APubMakeOutbox(){
  2165. $this->ReadPosts();$this->ReadImages();
  2166. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2167. "id"=>$this->HostURL."?apub_outbox=1",
  2168. "type"=>"OrderedCollection"];
  2169. $items=[]; $i=0;
  2170. foreach(array_reverse($this->Posts) as &$p){
  2171. $this->ConvertPost($p);
  2172. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2173. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2174. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2175. "type"=> "Create",
  2176. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2177. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2178. //"to"=> ["https://chatty.example/ben/"],
  2179. "actor"=> $this->HostURL."?apub_actor=1",
  2180. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2181. "object"=> ["type"=> "Note",
  2182. "id"=> $this->HostURL."?post=".$p['id'],
  2183. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2184. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2185. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2186. "content"=> $text]];
  2187. $items[] = $ob;
  2188. $i++; if($i>20) break;
  2189. }
  2190. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2191. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2192. }
  2193. function APubDeliver($body,$target){
  2194. $head_digest = base64_encode(hash("sha256",$body,true));
  2195. $body_digest = "SHA-256=".$head_digest;
  2196. // rfc standards require the timezone be declared as GMT and PHP's built-in formats all say UTC
  2197. // so we gotta do it manually
  2198. $d = new DateTimeImmutable("now", new DateTimeZone('Asia/Shanghai'));
  2199. $d=$d->setTimezone(new DateTimeZone('UTC'));
  2200. $date=$d->format("D, d M Y H:i:s")." GMT";
  2201. $data = "(request-target): post ".parse_url($target,PHP_URL_PATH)
  2202. ."\nhost: ".parse_url($target,PHP_URL_HOST)
  2203. ."\ndate: $date"
  2204. ."\ndigest: $body_digest";
  2205. if (openssl_sign($data, $signature, $this->APubPrivateKey, OPENSSL_ALGO_SHA256) === FALSE) {
  2206. http_response_code(500); die('unable to sign');
  2207. }
  2208. $signature = base64_encode($signature);
  2209. $keyid = 'keyId="'.$this->HostURL.'?apub_actor=1#main-key"';
  2210. $algo = 'algorithm="rsa-sha256"';
  2211. $headers = 'headers="(request-target) host date digest"';
  2212. $signature = "signature=\"$signature\"";
  2213. $h = array(
  2214. 'Content-Type: application/activity+json',
  2215. 'Accept: application/activity+json',
  2216. //"Content-Length: ".strlen($body),
  2217. "Host: ". parse_url($target,PHP_URL_HOST),
  2218. "Date: $date",
  2219. "Digest: $body_digest",
  2220. "Signature: $keyid,$algo,$headers,$signature"
  2221. );
  2222. $ch = curl_init($target);
  2223. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2224. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
  2225. curl_setopt($ch, CURLOPT_HTTPHEADER, $h);
  2226. curl_setopt($ch, CURLOPT_USERAGENT, "laMDWiki APub");
  2227. $result = curl_exec($ch);
  2228. curl_close($ch); echo "<pre>";
  2229. print_r($body); echo "\n\n".$target."\n\n";
  2230. print_r($result); echo "\n\n"; print_r($h);
  2231. echo "\n\n"; print_r(curl_getinfo($ch)); echo "</pre>"; exit;
  2232. return $result;
  2233. }
  2234. function APubTestDeliver(){
  2235. $this->APubInit();
  2236. $obj=[];
  2237. $obj['published']=gmdate("Y-m-d\TH:i:s\Z");
  2238. $obj['id']=""; //<-------------------
  2239. $obj['url']=$this->HostURL.""; //<-------------------
  2240. $obj['type']='Note';
  2241. $obj['attributedTo']=$this->HostURL."?apub_actor=1";
  2242. $tag=[]; $tag['type']='Mention'; $tag['name']="@chengdulittlea"; $tag['href']="https://mastodon.art/users/chengdulittlea";
  2243. $obj['tag']=[$tag];
  2244. // must have cc to have notification in mastodon.
  2245. $obj['cc']=["https://mastodon.art/users/chengdulittlea"];
  2246. $obj['content']="<p>@chengdulittlea Hello activitypub from laMDWiki!</p>";
  2247. $obj['to']="https://www.w3.org/ns/activitystreams#Public";
  2248. $obj['inReplyTo']=""; //<-------------------
  2249. $arr=[];
  2250. $arr['@context']="https://www.w3.org/ns/activitystreams";
  2251. $arr['id']=""; //<-------------------
  2252. $arr['actor']=$this->HostURL."?apub_actor=1";
  2253. $arr['type']="Create";
  2254. $arr['to']="https://www.w3.org/ns/activitystreams#Public";
  2255. $arr['object']=$obj;
  2256. $this->APubDeliver(json_encode($arr),"https://mastodon.example/inbox"); //<-------------------
  2257. }
  2258. function APubProcessInbox(){
  2259. $r = file_get_contents('php://input');
  2260. file_put_contents('postdump.txt',$r);
  2261. }
  2262. function MakeRSS(){
  2263. $this->ReadPosts();$this->ReadImages();
  2264. $posts = []; if(isset($this->UsePosts[0])){
  2265. $posts = array_reverse($this->UsePosts);
  2266. $last_updated = $this->StandardTime($posts[0]['id']);
  2267. }else{ $last_updated= $this->StandardTime("20000101000000"); }
  2268. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2269. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2270. "<id>".$this->HostURL."/?rss</id>".
  2271. "<updated>".$last_updated."</updated>".
  2272. "<title>".$this->T($this->Title)."</title>".
  2273. "<link href='".$this->HostURL."/index.php?rss=".($this->LanguageAppendix=='zh'?'zh':'en')."' rel='self'/>".
  2274. "<link href='".$this->HostURL."' />".$author;
  2275. $i=0;
  2276. if(isset($posts[0])) foreach($posts as &$p){
  2277. if($i>100) break;
  2278. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2279. if(isset($p['tid'])){ /* Should always be set. */
  2280. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2281. if(in_array($p['id'],
  2282. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  2283. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2284. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2285. $is_reversed=false;
  2286. $content="<entry>"; $title = NULL;
  2287. if($is_thread){
  2288. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2289. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2290. foreach($use_arr as &$po){
  2291. $this->ConvertPost($po);
  2292. if(!isset($title)){$title = htmlspecialchars($this->GetPostTitle($po, false, false)); if(!$title){$title='untitled';}
  2293. $content.="<id>".$this->HostURL."/?post=".$po['id']."</id>";
  2294. $content.="<title type='html'>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$po['id']."' />";
  2295. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2296. $content.="<updated>".$this->StandardTime(isset($po['tid']['last']['version'])?
  2297. $po['tid']['last']['version']:$po['tid']['last']['id'])."</updated>".$author;
  2298. $content.="<content type='html'>"; }
  2299. $content.= htmlspecialchars($po['html']);
  2300. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2301. }
  2302. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2303. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2304. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2305. $content.="</content>";
  2306. }else{
  2307. $this->ConvertPost($p);
  2308. if(!isset($title)){$title = htmlspecialchars($this->GetPostTitle($p, false, false)); if(!$title){$title='untitled';}
  2309. $content.="<id>".$this->HostURL."/?post=".$p['id']."</id>";
  2310. $content.="<title type='html'>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$p['id']."' />";
  2311. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2312. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2313. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2314. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2315. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2316. $content.=$this->ReadableTime($p['id'])." - ".
  2317. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2318. $content.="</content>";
  2319. }
  2320. $i++;
  2321. $content.="</entry>";
  2322. $all_content.=$content;
  2323. }
  2324. $all_content.="</feed>";
  2325. header( "Content-type: text/xml");
  2326. echo $all_content;
  2327. }
  2328. function MakeHereButtons($im, $insert_here){
  2329. if(isset($im['here'])&&isset($im['here'][0])){
  2330. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2331. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2332. foreach($im['here'] as $here){
  2333. if($insert_here){
  2334. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2335. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2336. }else{
  2337. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2338. }
  2339. }
  2340. echo "</div>".($insert_here?"</here>":"");
  2341. }
  2342. }
  2343. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  2344. if(isset($_GET['gallery_continue']) && $_GET['gallery']){
  2345. $this->ReadImages();
  2346. $this->GetImageBatch($_GET['gallery_continue'],0);
  2347. exit;
  2348. }
  2349. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2350. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2351. return 0;
  2352. }
  2353. if(isset($_GET['set_language'])){
  2354. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2355. $redirect=$this->GetRedirect(); return 0;
  2356. }
  2357. if(isset($_GET['rss'])){
  2358. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2359. $this->MakeRSS(); exit;
  2360. }
  2361. if(isset($_GET['toggle_font'])){ $use_font='local';
  2362. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2363. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2364. $redirect=$this->GetRedirect(); return 0;
  2365. }
  2366. if(isset($_GET['set_wayback'])){
  2367. if($_GET['set_wayback']!='false'){
  2368. $wayback= date('YmdHis');
  2369. if($_GET['set_wayback']=='post'){
  2370. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2371. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2372. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2373. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2374. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2375. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2376. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2377. }else{
  2378. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2379. }
  2380. $redirect=$this->GetRedirect(); return 0;
  2381. }
  2382. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2383. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2384. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2385. if(isset($_GET['post'])){
  2386. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2387. }
  2388. if(isset($_GET['random_here'])){
  2389. $this->DoIdentifyExperimental(); $this->DetectPageType();
  2390. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2391. }
  2392. if(isset($_POST['search_content'])){ $redirect='index.php?search='.$_POST['search_content'];return 0; }
  2393. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2394. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2395. $direct_return = !isset($_GET['show_image']);
  2396. $this->ReadImages(); $this->ReadPosts();
  2397. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2398. $im = &$this->FindImage($m);
  2399. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2400. if($direct_return){
  2401. echo "<ref>".sizeof($im['refs'])."</ref>";
  2402. echo "<insert><ul>";
  2403. }else{ ob_start(); }
  2404. foreach(array_reverse($im['refs']) as $ref){
  2405. $p = $this->GetPost($ref);
  2406. if(!$p || !$this->CanShowPost($p)) continue;
  2407. $this->MakeSinglePost($p, false, true, "post_preview invert_a", true, false, false, false, true);"</li>";
  2408. }
  2409. if($direct_return){
  2410. echo "</ul></insert>";
  2411. $this->MakeHereButtons($im, true);
  2412. }else{
  2413. $str = ob_get_clean();
  2414. $this->MakePageBegin($this->NULL_POST);
  2415. $side = "";
  2416. if(isset($im['refs'])&&isset($im['refs'][0])){
  2417. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2418. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2419. $static_image = isset($im['video'])?NULL:$im['file'];
  2420. $static_video = isset($im['video'])?$im['file']:NULL;
  2421. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$static_image,$static_video);
  2422. $this->MakePageEnd();
  2423. }
  2424. exit;
  2425. }
  2426. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2427. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2428. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2429. }
  2430. if(isset($_GET['apub_actor'])){
  2431. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2432. echo $this->APubActor; exit;
  2433. }
  2434. if(isset($_GET['apub_outbox'])){
  2435. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2436. echo $this->APubMakeOutbox(); exit;
  2437. }
  2438. if(isset($_GET['apub_inbox'])){
  2439. $this->APubProcessInbox();
  2440. http_response_code(202); exit;
  2441. }
  2442. if($this->LoggedIn){
  2443. if(isset($_GET['TestAPubDeliver'])){
  2444. $this->APubTestDeliver();
  2445. }
  2446. $this->DoUpload();
  2447. if(isset($_POST['settings_button'])){
  2448. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2449. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2450. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2451. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2452. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2453. if(isset($_POST['settings_special_sidebar'])) $this->SpecialSidebar=$_POST['settings_special_sidebar'];
  2454. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2455. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2456. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2457. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2458. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2459. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2460. if(isset($_POST['settings_gallery_step'])) $this->GalleryStep=$_POST['settings_gallery_step'];
  2461. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2462. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2463. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2464. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2465. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2466. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2467. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2468. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2469. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2470. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2471. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2472. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2473. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2474. if(isset($_POST['settings_allow_language'])) $this->AllowLanguageChoices=True; else $this->AllowLanguageChoices=False;
  2475. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2476. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2477. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2478. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2479. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2480. $this->APubID=$_POST['settings_apub_id'];
  2481. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2482. }
  2483. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2484. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2485. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2486. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2487. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2488. $redirect=$_SERVER['REQUEST_URI'];
  2489. $this->DoLogout();
  2490. }
  2491. $this->WriteConfig();
  2492. return 0;
  2493. }
  2494. if(isset($_POST['settings_save_redirect'])){
  2495. if(isset($_POST['settings_redirect'])){
  2496. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2497. }
  2498. $this->WriteConfig();
  2499. $redirect = 'index.php?extras=true'; return 0;
  2500. }
  2501. if(isset($_POST['settings_save_translation'])){
  2502. if(isset($_POST['settings_translation'])){
  2503. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2504. }
  2505. $redirect = 'index.php?extras=true'; return 0;
  2506. }
  2507. if(isset($_GET['post'])){
  2508. if(isset($_GET['post_original'])){
  2509. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2510. exit;
  2511. }
  2512. }
  2513. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2514. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2515. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2516. return 0;
  2517. }
  2518. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2519. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2520. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2521. return 0;
  2522. }
  2523. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2524. $c = $_POST['post_content'];
  2525. if('有什么想说的' == $c){ return 0;}
  2526. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2527. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2528. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2529. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2530. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2531. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2532. $redirect='?post='.$edited['id']; return 0;
  2533. };
  2534. }
  2535. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2536. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2537. $redirect='?post='.$edited['id']; return 0;
  2538. };
  2539. }
  2540. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2541. if(($edited =$this->EditPost(
  2542. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2543. $redirect='?post='.$edited['id']; return 0;
  2544. };
  2545. }
  2546. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2547. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2548. if(isset($post)){
  2549. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2550. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2551. echo "SUCCESS ".$mastodon_url;
  2552. }else{ echo $err; }
  2553. } exit;
  2554. }
  2555. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2556. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2557. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2558. }
  2559. }
  2560. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2561. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2562. $redirect='?post='.$pe['id']; return 0;
  2563. }
  2564. }
  2565. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2566. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2567. $c = $_POST['comment_box'];
  2568. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2569. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2570. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2571. if(($edited = $this->EditComment(NULL,
  2572. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2573. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2574. $_SERVER['REMOTE_ADDR']))!=NULL){
  2575. $redirect='?post='.$_GET['post'];
  2576. return 0;
  2577. };
  2578. }
  2579. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2580. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2581. $new_name = $_POST['gallery_edit_new_name'];
  2582. if($old_name!=''){
  2583. $desc=isset($_POST['gallery_edit_description'])?$_POST['gallery_edit_description']:null;
  2584. if(!preg_match('/[0-9]{14}/',$desc))$desc="";
  2585. $this->EditGallery($old_name, $new_name, false, true, null, null,$desc);
  2586. $redirect='?gallery='.$new_name;
  2587. }else{
  2588. $this->EditGallery(null, $new_name, false, true, null,null);
  2589. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2590. }
  2591. return 0;
  2592. }
  2593. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2594. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null,null);
  2595. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  2596. return 0;
  2597. }
  2598. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2599. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2600. $this->ReadImages();
  2601. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2602. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL, NULL);
  2603. }
  2604. }
  2605. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2606. return 0;
  2607. }
  2608. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2609. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2610. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2611. return 0;
  2612. }
  2613. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2614. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2615. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2616. return 0;
  2617. }
  2618. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2619. $this->ReadImages();
  2620. $gallery = $_GET['image_list']; $count=0;
  2621. foreach($this->Images as $im){ if($count>25){ break; }
  2622. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; $count++; continue; }
  2623. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2624. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; $count++; }
  2625. }
  2626. exit;
  2627. }
  2628. $do_image_redirect = 0;
  2629. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2630. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4))/u',$_GET['pic'],$ma)){
  2631. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2632. if(isset($_POST['image_ops_product_link'])){
  2633. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL, NULL);
  2634. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2635. }
  2636. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2637. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL, NULL);
  2638. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2639. $do_image_redirect = 1;
  2640. }
  2641. if(isset($_POST['image_parent'])){ $parent="";
  2642. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2643. $this->EditImage($pic, NULL, false, NULL, NULL, $parent, NULL);
  2644. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2645. }
  2646. if(isset($_POST['image_align'])){$val=$_POST['image_align'];
  2647. $this->EditImage($pic, NULL, false, NULL, NULL, NULL, $val);
  2648. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2649. }
  2650. $this->NeedWriteImages = 1;
  2651. if($do_image_redirect) return 0;
  2652. }
  2653. if(isset($_GET['rewrite_styles'])){
  2654. $this->WriteStyles();
  2655. $redirect='?extras=true'; return 0;
  2656. }
  2657. if(isset($_GET['regenerate_thumbnails'])){
  2658. $this->RegenerateThumbnails();
  2659. $redirect='?extras=true'; return 0;
  2660. }
  2661. if(isset($_GET['clear_all_logins'])){
  2662. $this->LoginTokens=[];
  2663. $this->WriteTokens();
  2664. }
  2665. }
  2666. return 0;
  2667. }
  2668. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null, &$end_wide=null, &$print_wide=null){
  2669. if(!$this->LoggedIn){
  2670. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2671. }
  2672. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2673. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2674. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2675. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2676. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2677. $html = preg_replace("/\{\s*(REVERSED|INTERESTING|HEADER|FOOTER)\s+(.*?)\}/imu","",$html);
  2678. $html = preg_replace("/\{\s*(REVERSED|NO_TIME|NO_TITLE|SLIDES)\s*\}/imu","",$html);
  2679. $html = preg_replace("/\{\s*WIDE\s*\}/imu","",$html,-1,$rep_count); if($rep_count){$print_wide=true;}
  2680. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2681. $html = preg_replace_callback(
  2682. "/(<p>\s*|<a\s.*?>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2683. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2684. if(isset($m[1])&&$m[1]&&$m[1][1]=='a'){ $height="";
  2685. if(preg_match("/([0-9]{1,2})em/u",$m[0],$hm)){$height=' style="height:'.$hm[1].'em;"';}
  2686. return "<a class='imbtn'".$height.substr($m[0],2); }
  2687. $orig_src = $src = $m[5]; $keep = false; $original = false; $float=false;
  2688. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2689. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2690. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2691. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2692. if (preg_match('/alt=[\'\"].*float.*[\'\"]/u',$m[3]) ||
  2693. preg_match('/alt=[\'\"].*float.*[\'\"]/u',$m[7])) { $keep=true;$original=true;$float=true; }
  2694. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2695. $src = $im['thumb']; $orig_src=$im['file'];
  2696. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2697. $media_start = $m[2];
  2698. $media_end = $m[7];
  2699. $dataset = " data-imgsrc='".$m[5]."'".
  2700. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2701. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2702. (isset($im['align'])?' data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':"").
  2703. ($original?" class='original_img'":"");
  2704. if(isset($im['video']) && isset($im['video'])!=''){
  2705. $media_start = "<video controls".$dataset."><source src='"; $media_end="' type='".$im['video']."'></video";
  2706. $src = $orig_src; $dataset="";
  2707. }
  2708. $float_add=""; if($float){ $float_add=" imd_float"; }
  2709. if($this->InHereMode){
  2710. $click = "<div class='imd$float_add'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2711. $media_start.($original?$orig_src:$src).$media_end."></a></div>";
  2712. $ret=""; if($keep) { $ret = $click; }
  2713. else { $images[] = $click; }
  2714. return $ret;
  2715. }else{
  2716. $click ="<div class='imd$float_add'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2717. $media_start.($original?$orig_src:$src).$media_end.$dataset."></a></div>";
  2718. $images_noclick[]=$media_start.$src.$media_end.">"; $images_orig_src_list[]=$orig_src;
  2719. $ret = "";
  2720. if($keep) { $ret = $click; }
  2721. else { $images[] = $click; }
  2722. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2723. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2724. }
  2725. },$html,-1,$count);
  2726. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2727. if(sizeof($images)){
  2728. if((!$this->InHereMode) && sizeof($images)==1){$html.= $images[0]; }
  2729. else{
  2730. $html.="<div class='p_row'>";
  2731. foreach($images as $img){
  2732. $html.="<div class='p_thumb'>".$img."</div>";
  2733. }
  2734. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2735. }
  2736. }
  2737. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2738. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2739. if($do_product_info){
  2740. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2741. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2742. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2743. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2744. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2745. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2746. else { $product_info['title'] = $this->T('商品'); }
  2747. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2748. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2749. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2750. $this->T('购买').' '.$product_info['title'].
  2751. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2752. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2753. }
  2754. if(preg_match("/(<\/div>|<\/table>|<\/video>)\s*$/u",$html)){$end_wide=true;}
  2755. return $html;
  2756. }
  2757. function ConvertPost(&$post){
  2758. if(!isset($post['html'])){
  2759. $info=[];
  2760. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2761. $post['images'],
  2762. isset($post['product']), $info,
  2763. $post['original_images'],
  2764. $post['end_wide'],
  2765. $post['wide']));
  2766. if(isset($post['product'])) $post['product']=$info;
  2767. }
  2768. }
  2769. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2770. if($h1_only){
  2771. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)) return $m[1];
  2772. else return NULL;
  2773. }
  2774. if(!isset($post['title'])){
  2775. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2776. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2777. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2778. $post['title'].=($add_unamed?' (':'').strip_tags($this->PDE->text($m[1])).($add_unamed?')':''); }
  2779. }
  2780. }
  2781. return $this->ChoosePartsByLanguage($post['title']);
  2782. }
  2783. function DetectPageType(){
  2784. if ($this->InExperimentalMode) $this->PageType='experimental';
  2785. else if($this->InHereMode) $this->PageType='here';
  2786. else if(isset($_GET['history'])) $this->PageType='history';
  2787. else if(isset($_GET['extras'])) $this->PageType='extras';
  2788. else if(isset($_GET['settings'])) $this->PageType='settings';
  2789. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2790. else if(isset($_GET['search'])) $this->PageType='search';
  2791. else if(isset($_GET['category'])) $this->PageType='category';
  2792. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2793. else if(isset($_GET['comments'])) $this->PageType='comments';
  2794. else if(isset($_GET['statistics'])) $this->PageType='statistics';
  2795. else $this->PageType = "main";
  2796. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2797. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2798. $this->VisitedHere = $_SESSION[$visited_here];
  2799. }
  2800. function MakePageBegin(&$p){ $title=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2801. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title)) ?>
  2802. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2803. <head>
  2804. <meta charset='utf-8'>
  2805. <meta content="width=device-width, initial-scale=1" name="viewport">
  2806. <title><?=$title?></title>
  2807. <meta property="og:title" content="<?=$title.(isset($p)?(" | ".$this->GetPostTitle($p)):"")?>">
  2808. <?php if(isset($p)&&isset($p['hasi'])&&isset($p['hasi'][0])){?> <meta property="twitter:card" content="summary_large_image" />
  2809. <meta property="og:image" content="<?=(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']==='on'?"https":"http").'://'.$_SERVER['HTTP_HOST'].'/images/thumb/'.$p['hasi'][0]?>"><?php } ?>
  2810. <?php if($this->UseRemoteFont){ ?><style>
  2811. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2812. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2813. </style><?php } ?>
  2814. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2815. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2816. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2817. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2818. <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>
  2819. </head>
  2820. <div class='page'>
  2821. <?php }
  2822. function MakeHeader(&$p){
  2823. $this->MakePageBegin($p) ?>
  2824. <script type='text/javascript'>
  2825. function toggle_mobile_show(a){a.classList.toggle('hidden_m')}
  2826. function ShowWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='';}
  2827. function HideWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='none';}
  2828. <?php if(!$this->InHereMode){ ?>
  2829. function la_auto_grow(element){
  2830. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2831. }
  2832. function ShowBackdrop(alpha=0.5){
  2833. b = document.getElementById('backdrop');
  2834. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2835. b.style.animation='backdrop_fade_in 0.3s forwards';
  2836. b.style.display = 'block';
  2837. }
  2838. function HideBackdrop(){
  2839. b = document.getElementById('backdrop');
  2840. b.style.animation='backdrop_fade_out 0.3s forwards';
  2841. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2842. }
  2843. function ShowRightSide(big,elem_to_clone){
  2844. p = document.getElementById('pop_right');
  2845. if(elem_to_clone){
  2846. c = elem_to_clone.cloneNode(true);
  2847. c.id='side_bar_cloned';c.className="";c.style="";
  2848. p.querySelector('._content').appendChild(c);
  2849. }
  2850. p.classList.remove('pop_right','pop_right_big');
  2851. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2852. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2853. p.style.display='block';
  2854. ShowBackdrop(0.5);
  2855. }
  2856. function HideRightSide(){
  2857. p = document.getElementById('pop_right');
  2858. if(side=p.querySelector('#side_bar_cloned')){
  2859. side.remove();
  2860. }
  2861. put = document.querySelector("#_uploader");
  2862. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2863. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2864. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2865. HideBackdrop();
  2866. }
  2867. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2868. function ScrollToPost(id){
  2869. post=null;
  2870. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2871. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2872. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2873. }
  2874. <?php } ?>
  2875. </script><input type='checkbox' class='lpctrl' id='titlectrl'>
  2876. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2877. <?php if($this->InHereMode){
  2878. $this->MakeExpNavButtons($p);
  2879. }else{
  2880. $this->MakeNavButtons($p);
  2881. if(isset($p['tid']['header'])){ ?><div style='float:right' class='show_on_print'><?=$this->ChoosePartsByLanguage($p['tid']['header']);?></div><?php }
  2882. echo "<hr class='hidden_m'>";
  2883. } ?>
  2884. <?php if(isset($this->WayBack)){
  2885. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2886. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2887. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2888. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_m")'>
  2889. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2890. <span class='hidden_m'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2891. + <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_m'>
  2892. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2893. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2894. <br class='hidden_on_desktop' />
  2895. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2896. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2897. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2898. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2899. <br class='hidden_on_desktop' />
  2900. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2901. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2902. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2903. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2904. <br class='hidden_on_desktop' />
  2905. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2906. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2907. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2908. </div></div><?php } ?>
  2909. </div></header>
  2910. <div id='waiting_bar' style='display:none;'></div>
  2911. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2912. <?php if(!$this->InHereMode){ ?>
  2913. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2914. <ul>
  2915. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2916. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2917. <hr />
  2918. <?php if($this->LoggedIn){ ?>
  2919. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2920. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2921. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2922. <?php if(!isset($this->WayBack)){ ?><li>
  2923. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2924. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2925. </li>
  2926. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2927. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2928. <li id='mark_details' style='display:none;'><b>
  2929. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2930. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2931. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2932. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2933. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2934. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2935. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2936. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2937. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2938. </b></li>
  2939. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2940. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2941. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2942. <input class='button' type='submit' form='post_rename_form'
  2943. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2944. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  2945. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  2946. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  2947. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  2948. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  2949. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  2950. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  2951. <input class='button' type='submit' form='post_mastodon_form'
  2952. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  2953. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  2954. <?php }else{ ?>
  2955. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2956. <?php } ?>
  2957. </ul>
  2958. </div>
  2959. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide();HideBigImage(1);'
  2960. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2961. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2962. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2963. <?=$this->T('关闭')?>→</a></div>
  2964. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2965. <div id='_uploader' style='display:none;'>
  2966. <?php $this->MakeUploader(true); ?>
  2967. <p>&nbsp;</p>
  2968. <?php $this->MakeSideGalleryCode(); ?>
  2969. </div>
  2970. <?php } ?>
  2971. <div class='_content'></div>
  2972. </div>
  2973. <?php } ?>
  2974. <?php
  2975. }
  2976. function ChoosePartsByLanguage($content,$use_p=false){
  2977. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  2978. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  2979. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  2980. if($split) for($i=0;$i<sizeof($split);$i+=4){
  2981. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  2982. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  2983. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  2984. }
  2985. if(!$reduced)$reduced = $content;
  2986. return $reduced;
  2987. }
  2988. function TranslatePostParts($html){
  2989. $html = preg_replace_callback('/>(\s*)([^><]+?)(\s*)</u', function($ma){
  2990. $reduced = $this->ChoosePartsByLanguage($ma[2], false);
  2991. return ">".$ma[1].$this->T($reduced).$ma[3]."<";
  2992. }, $html);
  2993. return $html;
  2994. }
  2995. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); $no_title=isset($p['tid']['first']['no_title']);?>
  2996. <a href='index.php' class='clean_a hidden_m<?=$no_title?" hidden_on_print":""?>' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title);?></b></a>
  2997. <?=$no_title?"<a class='inline_print'>&nbsp;</a>":""?>
  2998. <label for='titlectrl' id='mtitle'><b><a class='hidden_on_desktop'><?=$this->T($this->ShortTitle)?>...</a></b></label>
  2999. <div class='header_nav'>
  3000. <ul class='mobile_fold hidden_on_print' id='mobile_nav'>
  3001. <li class='hidden_m'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  3002. <li class='hidden_on_desktop_force block_m smaller'>&nbsp;</li>
  3003. <li class='hidden_on_desktop_force block_m bigger'>
  3004. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a>
  3005. <?php if($this->LoggedIn){ ?> | <span class='gray invert_a'>
  3006. <a href='index.php?comments=all'>@</a> <a href='index.php?statistics=all'>%</a></span><?php } ?></li>
  3007. <li class='hidden_on_desktop_force block_m bigger'>
  3008. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  3009. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  3010. echo $this->GenerateSinglePost($p, false, false, false, false);
  3011. } ?>
  3012. <?php if($this->LanguageAppendix=='zh'){ ?>
  3013. <li class='smaller gray'>
  3014. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  3015. <?php }else { ?>
  3016. <li class='smaller gray'>
  3017. <a href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  3018. 汉语/<b>English</b></a>
  3019. <br class='hidden_on_desktop' />
  3020. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  3021. <?php } ?>
  3022. </ul></div>
  3023. <?php
  3024. }
  3025. function MakeExpNavButtons(&$p){ ?>
  3026. <a href='index.php' class='hidden_m'>
  3027. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  3028. <a class='hidden_on_desktop'
  3029. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b class='round_btn'>
  3030. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?></b></a>
  3031. <?php if(!$this->InExperimentalMode){ ?>
  3032. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  3033. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  3034. <span class='round_btn'>
  3035. <a href='<?=$this->HereNumber==sizeof($this->VisitedHere)?"?random_here=1":$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a>
  3036. <a href='?random_here=1'><?=$this->T("随机")?></a></span><span class='hidden_m'></span>
  3037. <?php } ?>
  3038. <ul class='hidden_m' id='mobile_nav' style='text-align:center;'>
  3039. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  3040. <li class='hidden_on_desktop block_m'><a href='index.php'><?=$this->T('主页')?></a></li>
  3041. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  3042. echo $this->GenerateSinglePost($p, false, false, false, false);
  3043. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  3044. echo $this->GenerateSinglePost($p, false, false, false, false);
  3045. } ?>
  3046. <?php if($this->AllowLanguageChoices){ ?>
  3047. <li class='smaller hidden_on_desktop'>&nbsp;</li>
  3048. <?php if($this->LanguageAppendix=='zh'){ ?>
  3049. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  3050. <?php }else { ?>
  3051. <li class='smaller invert_a gray'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  3052. <li class='smaller invert_a gray'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  3053. <?php } ?>
  3054. <?php } ?>
  3055. </ul>
  3056. <?php
  3057. }
  3058. function GenerateLinkedPosts($ht){
  3059. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  3060. function($m){
  3061. if(preg_match('/^\s*<img/u',$m[2])){ return $m[0]; }
  3062. $rp = &$this->GetPost($m[1], false, true);
  3063. $s="<div class='smaller block post ref_compact gray'>".
  3064. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  3065. "<div class='post_width'><div class='smaller'>".$m[2]."</div>".
  3066. (($rp!==NULL && $this->CanShowPost($rp))?
  3067. $this->GenerateSinglePost($rp,false,false,false,true,true):$this->T("未找到该引用。")).
  3068. "</div></div>";
  3069. return $s;
  3070. },
  3071. $ht
  3072. );
  3073. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  3074. function($m){
  3075. $rp = &$this->GetPost($m[1], false, true);
  3076. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  3077. (($rp!==NULL && $this->CanShowPost($rp))?
  3078. $this->GenerateSinglePost($rp,true,false,false,true,true):$this->T("未找到该引用。")).
  3079. "</a></div>";
  3080. return $s;
  3081. },
  3082. $ht
  3083. );
  3084. return $ht;
  3085. }
  3086. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  3087. $generate_thumbs=false, $hide_long = false){
  3088. $this->ConvertPost($post);
  3089. if($generate_anchor){ $this->CreatePostAnchor($post); }
  3090. $ht = $post['html'];
  3091. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  3092. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  3093. "<p class='bold'>".$post['product']['title']."</p>".
  3094. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  3095. "<p class='smaller bold'>".$post['product']['price']."</p>";
  3096. return $ht;
  3097. }
  3098. if($hide_long){
  3099. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  3100. }else{
  3101. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  3102. }
  3103. if ($strip_tags){
  3104. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  3105. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  3106. $ht = "<div class='post_ref_main'>".$ht."</div>";
  3107. }
  3108. else{
  3109. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  3110. }
  3111. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  3112. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  3113. foreach($post['images'] as $im){
  3114. $ht.="<li class='file_thumb'>".$im."</li>";
  3115. }
  3116. $ht.="</ul></div>";
  3117. }
  3118. return $ht;
  3119. }
  3120. function MakeSinglePostExp(&$post){ ?>
  3121. <li class='post post_dummy'>
  3122. <?=$this->GenerateSinglePost($post, false, false, true, false, false); ?>
  3123. </li>
  3124. <?php
  3125. }
  3126. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  3127. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  3128. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  3129. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  3130. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  3131. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  3132. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  3133. $title = $generate_anchor?$this->ChoosePartsByLanguage($this->GetPostTitle($post, true)):NULL;
  3134. $this->ConvertPost($post);// NEEDED FOR WIDE;
  3135. $is_wide = (isset($post['wide'])&&$post['wide']) || (isset($post['tid']) && isset($post['tid']['wide']) && $post['tid']['wide']);
  3136. ?>
  3137. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  3138. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>'
  3139. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  3140. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?>
  3141. <?=$is_wide?" style='column-span:all;'":"";?>>
  3142. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  3143. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  3144. <?php }
  3145. if(!$side && !$strip_tags && $show_link){?><div class='post_menu_button _menu_hook' >+</div><?php } ?>
  3146. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  3147. <div class='<?=$side?"":'post_width'?><?=$is_deleted?" deleted_post":""?>'>
  3148. <?php if($is_product&&!$generate_anchor){
  3149. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  3150. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  3151. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  3152. $generate_thumb,($show_thread_link||$side||$force_hide_long)); ?>
  3153. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  3154. </div>
  3155. <?=$side?"</a>":""?> <?php
  3156. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  3157. $post['tid']['first']['id']!=$post['id']){ ?>
  3158. <div class='gray smaller block opt_compact post'>
  3159. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  3160. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  3161. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  3162. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  3163. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true, true);?>
  3164. </div>
  3165. </div>
  3166. <?php }if(!$side && $show_link){ if($ref_count){ ?><?php } ?>
  3167. <a href='?post=<?=$post['id']?>' onclick="<?=$show_thread_link||isset($_GET['search'])?'ShowWaitingBar()':'ClickPost(this.parentNode,event,true)'?>">
  3168. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3169. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"")?>
  3170. </div>
  3171. </a><?php if($ref_count){ ?>
  3172. <label class='lb post_access' for='fake<?=$post["id"]?>'><div class='ref_count'><?=$ref_count?></div></label><?php }
  3173. }
  3174. if($show_reply_count && isset($post['tid'])){ ?>
  3175. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  3176. <?=$this->T('个回复')?></a>
  3177. <?php } if(!$strip_tags){
  3178. $this->MakeLinkedPosts($post);
  3179. } ?>
  3180. </li>
  3181. <?php
  3182. }
  3183. function MakePostingFields($reply_to=NULL, $show_hint=false){
  3184. if(isset($this->WayBack)){ ?>
  3185. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  3186. <?php return; } ?>
  3187. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  3188. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  3189. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  3190. <div id='post_hint_modify' style='display:none;'>
  3191. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  3192. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  3193. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  3194. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  3195. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3196. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3197. onclick='ShowWaitingBar();' />
  3198. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3199. <div style='float:right;'>
  3200. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3201. <?=$this->T('清空')?></a>
  3202. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3203. </div>
  3204. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3205. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3206. <?php if($reply_to){ ?>
  3207. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3208. <?php } ?>
  3209. <?php
  3210. }
  3211. function MakeCommentPosts(){
  3212. if(!$this->LoggedIn) return; ?>
  3213. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3214. <?php if(!$this->CommentEnabled){
  3215. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3216. <div class='comment'><ul>
  3217. <?php $i=0;
  3218. foreach(array_reverse($this->Posts) as $p){
  3219. if(!isset($p['comment_to'])) continue;
  3220. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3221. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3222. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3223. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3224. if(!$post_to) $post_title = "?";
  3225. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3226. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3227. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3228. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3229. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3230. $i++;
  3231. }
  3232. ?>
  3233. </ul><br /></div>
  3234. <?php
  3235. }
  3236. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  3237. <div class='center' id='div_center'><br class='hidden_on_print' />
  3238. <?php if(!isset($search_term) && !isset($category) &&
  3239. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3240. $this->CanShowPost($p)){
  3241. ?><ul class='print_column list bkg_section'><?php
  3242. $this->MakeSinglePost($p, true, false, "active_post", false, true, false, false, false, true, false);
  3243. ?></ul><br /><?php
  3244. }?>
  3245. <h2><?=isset($search_term)?$this->T('搜索'):
  3246. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3247. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3248. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3249. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a> <a href='index.php?statistics=all'>%</a>":"")."</span>")?></h2><br />
  3250. <?php if(isset($search_term)){ ?>
  3251. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  3252. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3253. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3254. <?php }else if(isset($category)){ ?>
  3255. <div></div>
  3256. <?php }else if($this->LoggedIn){ ?>
  3257. <div class='post_box_top _input_bundle'>
  3258. <?php $this->MakePostingFields(NULL,false); ?>
  3259. </div>
  3260. <?php } ?>
  3261. <ul class='print_column list bkg_recent'>
  3262. <?php
  3263. $i = 0; $last_end_wide = true;
  3264. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3265. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3266. if(isset($p['tid'])){ /* Should always be set. */
  3267. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3268. if(!isset($search_term)) { $p = &$th['last']; }
  3269. }
  3270. if(isset($search_term)){
  3271. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3272. }else if(isset($category)){
  3273. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3274. (isset($p['categories'])?($p['categories']):[]);
  3275. if ($category=='none') { if($cat!=[]) continue; }
  3276. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3277. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3278. }else{
  3279. if(in_array($p['id'],
  3280. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation,$this->SpecialSidebar])) continue;
  3281. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3282. }
  3283. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3284. if($last_end_wide){$use_class="last_wide";}else{$use_class="";}
  3285. $this->MakeSinglePost($p, true, false, $use_class, false, !isset($search_term), false, false, false, false, isset($search_term));
  3286. $i++;
  3287. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3288. $last_end_wide = sizeof($p['tid']['arr'])==1 && isset($p['end_wide']) && $p['end_wide'];
  3289. }?>
  3290. </ul>
  3291. <div class='page_selector clean_a'>
  3292. <hr />
  3293. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  3294. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3295. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3296. <?=$this->CurrentOffset+1?>
  3297. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  3298. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3299. → <?=$this->T('下一页')?></a>
  3300. </div>
  3301. </div>
  3302. <?php
  3303. }
  3304. function MakeLinkedPosts(&$p){
  3305. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); if(!$has_ref)return; $count=0;?>
  3306. <input type='checkbox' class='lpctrl' id='fake<?=$p["id"]?>' checked='checked'>
  3307. <div class='linked_posts smaller'>
  3308. <ul><?php $count_product=0;
  3309. foreach(array_reverse($p['refs']) as &$pr){
  3310. $po = $this->GetPost($pr);
  3311. if(!$this->CanShowPost($po)){ continue; } $count++;
  3312. $this->MakeSinglePost($po, false, true, "post_preview invert_a", true, false, false, false, true, false, false);
  3313. }
  3314. ?></ul>
  3315. </div>
  3316. <?php
  3317. }
  3318. function MakeLinkedPostsExp(&$p){
  3319. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3320. <div class='center_exp post_dummy smaller'>
  3321. <hr />
  3322. <?php if(!$this->InExperimentalMode){ ?>
  3323. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3324. <?php if($has_ref){ ?>
  3325. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3326. <ul><?php $count_product=0;
  3327. foreach(array_reverse($p['refs']) as &$pr){
  3328. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3329. "</a></li>";
  3330. }
  3331. ?></ul>
  3332. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3333. }else{ ?>
  3334. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3335. <?php } }?>
  3336. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3337. </div>
  3338. <?php
  3339. }
  3340. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3341. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3342. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3343. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3344. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3345. if(!isset($title)) $title=$this->T('未命名');
  3346. if(!isset($ah)){ ?>
  3347. <h2><?=$this->T('没有历史记录')?></h2>
  3348. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3349. <?php }else{ ?>
  3350. <h2><?=$this->T('历史记录')?></h2>
  3351. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3352. <div class='list'><ul>
  3353. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3354. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3355. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3356. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3357. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3358. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3359. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3360. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3361. <?=$this->GetPostTitle($ver);?></a>
  3362. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3363. <?php } ?></ul><?php } ?>
  3364. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3365. $mah = &$this->GetArchiveHandle($pm);
  3366. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3367. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3368. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3369. <?php } ?>
  3370. </li><?php } ?>
  3371. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3372. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3373. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3374. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3375. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3376. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3377. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3378. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3379. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3380. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3381. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3382. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3383. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3384. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3385. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3386. <?=$this->GetPostTitle($ver);?></a>
  3387. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3388. <?php } ?></ul></li><?php } ?>
  3389. <?php } ?></ul></div>
  3390. <?php } ?>
  3391. <?php
  3392. }
  3393. function MakePostDiff(&$this_ver, &$last_ver){
  3394. if(!isset($this_ver)){ ?>
  3395. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3396. <?php }else{ ?>
  3397. <h2><?=$this->T('差异')?></h2>
  3398. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3399. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3400. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3401. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3402. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3403. <?php }else{ ?>
  3404. <table class='diff_table'><thead>
  3405. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3406. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3407. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3408. </thead><tbody>
  3409. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3410. </tbody>
  3411. </table>
  3412. <?php } ?>
  3413. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3414. <?php } ?>
  3415. <?php
  3416. }
  3417. function MakePostHistory(&$post, $version=NULL){
  3418. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3419. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3420. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3421. ?>
  3422. <div class='left mobile_fold history' id='div_left'>
  3423. <?php if (isset($version)){
  3424. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3425. }else{ echo "&nbsp;"; } ?>
  3426. </div>
  3427. <div class='center history' id='div_center'>
  3428. <?php if (!isset($version)){
  3429. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3430. }else{
  3431. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3432. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3433. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3434. $this->MakePostDiff($this_ver, $last_ver, $p);
  3435. } ?>
  3436. </div>
  3437. <?php
  3438. }
  3439. function MakeCommentSection(&$post){
  3440. if(!$this->CommentEnabled){ return; }
  3441. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3442. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3443. ?><div class='comment'>
  3444. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3445. <?php if($comment_count) { echo "<ul>";
  3446. foreach($to_post['comments'] as $p){
  3447. $ht = $this->GenerateSinglePost($p, false, false, false, false, false);
  3448. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3449. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3450. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3451. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3452. }
  3453. echo "</ul>";
  3454. } else {
  3455. echo $this->T('还没有评论');
  3456. } ?>
  3457. <div class='hidden_on_print'>
  3458. <div class='spacer'></div>
  3459. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3460. method="post" style="display:none;" id="comment_form"></form>
  3461. <p><a class='text_highlight bold clean_a'
  3462. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3463. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3464. <div id='comment_box' style='display:none;'>
  3465. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3466. <table style='white-space:nowrap;'>
  3467. <tr><td colspan='2'>
  3468. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3469. oninput="CommentUpdated();" ></textarea>
  3470. </td></tr>
  3471. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3472. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3473. class='full_box' oninput="CommentUpdated();" /></td>
  3474. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3475. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3476. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3477. <tr><td colspan='2'>
  3478. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3479. class='full_box' oninput="CommentUpdated();" />
  3480. </td></tr>
  3481. <tr><td colspan='2'>
  3482. <div class='spacer'></div>
  3483. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3484. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3485. </td></tr>
  3486. </table></div>
  3487. <script>
  3488. const IsValidEmail = (email) => {
  3489. 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,}))$/);
  3490. };
  3491. function IsValidHttpUrl(string) {
  3492. let url; try{ url = new URL(string); } catch (_) { return false; }
  3493. return url.protocol === "http:" || url.protocol === "https:";
  3494. }
  3495. var cbox = document.getElementById('comment_box');
  3496. var cemail = document.getElementById('comment_email');
  3497. var cname = document.getElementById('comment_name');
  3498. var clink = document.getElementById('comment_link');
  3499. var cconfirm = document.getElementById('comment_confirm');
  3500. function CommentUpdated(){
  3501. cconfirm.disabled=true;
  3502. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3503. cbox.innerText.length>2 && cname.value.length>2 &&
  3504. clink.value=="" || IsValidHttpUrl(clink.value)){
  3505. cconfirm.removeAttribute("disabled");
  3506. }
  3507. }
  3508. CommentUpdated();
  3509. </script>
  3510. </div>
  3511. </div>
  3512. <?php
  3513. }
  3514. function MakeInterestingSection(&$th){
  3515. $this->Anchors = [];
  3516. $c = &$th['first']['content'];
  3517. $this->ConvertPost($th['first']);
  3518. $ht = $th['first']['html'];
  3519. ?>
  3520. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3521. <div class='center_full' id='div_center'>
  3522. <?php $this->MakePostTools(); ?>
  3523. <?php $cat = NULL;
  3524. if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; }
  3525. if($cat){ ?>
  3526. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3527. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3528. <?php } ?>
  3529. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3530. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3531. <ul><li class='post' data-post-id='<?=$th['first']['id']?>'>
  3532. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3533. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3534. <?php foreach($th['first']['refs'] as $ref){
  3535. $po = $this->GetPost($ref);
  3536. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3537. if(!$this->CanShowPost($po)){ continue; }
  3538. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3539. } ?>
  3540. </ul><?php } ?>
  3541. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3542. <div class='hidden_on_print'><br />
  3543. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3544. </div>
  3545. <?php } ?>
  3546. <table><thead><tr><?php foreach($th['interesting'] as $header){ ?>
  3547. <td><?=$this->T($header);?></td>
  3548. <?php } ?><td></td></tr></thead><tbody class='interesting_tbody'>
  3549. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3550. foreach($plist as &$p){
  3551. $this->ConvertPost($p);
  3552. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3553. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3554. $is_current = $p['id']==$this->CurrentPostID;
  3555. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3556. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3557. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3558. onDblClick='ClickImage(this)'><td>
  3559. <?php if($ref_count){ ?>
  3560. <div class='post_access ref_count'><?=$ref_count?></div>
  3561. <?php } ?></a>
  3562. <?=$p['html'];?>
  3563. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a>
  3564. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3565. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3566. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3567. </div></td></tr>
  3568. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3569. <?php foreach($p['refs'] as $ref){
  3570. $po = $this->GetPost($ref);
  3571. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3572. if(!$this->CanShowPost($po)){ continue; }
  3573. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3574. } ?>
  3575. </ul></td></tr><?php } ?>
  3576. <?php } ?>
  3577. </tbody></table>
  3578. </li></ul>
  3579. <br />
  3580. <?php $this->MakeCommentSection($th['first']); ?>
  3581. </div>
  3582. <?php return true;
  3583. }
  3584. function CssNumberID($id){
  3585. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3586. }
  3587. function MakePostTools(){
  3588. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3589. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3590. <?=$this->T('工具')?></a>:<div class='hidden_m' style='display:inline'>
  3591. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3592. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3593. </div>
  3594. <select class='hidden_on_desktop' id='merge_select'
  3595. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3596. <option value='-1' selected>--</option>
  3597. <option value='1'><?=$this->T('合并帖子')?></option>
  3598. <option value='2'><?=$this->T('合并话题')?></option></select>
  3599. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3600. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3601. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3602. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3603. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3604. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3605. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3606. </div><div class='spacer hidden_on_print'></div><?php
  3607. }
  3608. }
  3609. function MakeSidebar(){ ?>
  3610. <div class='left mobile_fold'><?php if(isset($this->SpecialSidebar) && ($p = &$this->GetPost($this->SpecialSidebar))!=NULL){
  3611. ?><span class='gray smaller'><br /></span><?php
  3612. echo $this->GenerateSinglePost($p, false, false, false, false); }?>
  3613. <div class='wayback_link clean_a smaller'><span class='gray'><br /><?=$this->T('工具')?></span><ul>
  3614. <li><a href='?search=' onclick='ShowWaitingBar()' class='bigger'><?=$this->T('搜索')?></a></li>
  3615. <li><?php if(!isset($this->WayBack)){ ?>
  3616. <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  3617. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?></li>
  3618. <li><a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  3619. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a></li>
  3620. <li><a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a></li>
  3621. </ul>
  3622. </div>
  3623. </div>
  3624. <?php }
  3625. function MakePostSection(&$post){ $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1;
  3626. $this->Anchors = []; if(isset($post['slides']) || ($is_thread&&isset($post['tid']['slides']))) $centerclass='center_slides'; else $centerclass='center';
  3627. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3628. <div class='<?=$centerclass;?>' id='div_center'><br class='hidden_on_print' />
  3629. <h2 class='hidden_on_print'>
  3630. <?php $th=NULL;
  3631. $is_wide = (isset($post['wide'])&&$post['wide']) || ($is_thread && isset($post['tid']['wide']) && $post['tid']['wide']);
  3632. if($is_thread){ $th = $post['tid'];?> <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3633. <?php } ?></h2>
  3634. <?php $cat = NULL;
  3635. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3636. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3637. $this->MakePostTools();
  3638. if($cat){ ?>
  3639. <p class='hidden_on_print'><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3640. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3641. <?php } ?><br class='hidden_on_print' />
  3642. <ul class='print_column bkg_section'>
  3643. <?php $is_reversed=false;
  3644. if($is_thread){
  3645. $use_arr = $th['arr']; $hinted=false;
  3646. $last_end_wide = true; $is_reversed=$this->IsReversedThread($th);
  3647. foreach($use_arr as &$p){$use_class="";if($p==$post){$use_class.=" active_post";}
  3648. if($last_end_wide){$use_class.=" last_wide";}
  3649. $make_title = ($p == $post);
  3650. if(isset($p['restart'])){ ?>
  3651. <li class='restart'><h3><?=$p['restart']?></h3></li><?php }
  3652. $this->MakeSinglePost($p,true,false,$use_class,false, false, false, true, false, false);
  3653. if($make_title){?>
  3654. <script>
  3655. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  3656. </script>
  3657. <?php } if($is_reversed && !$hinted){ ?><?php $hinted = true;
  3658. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3659. <div class='hidden_on_print'>
  3660. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3661. <?php } }
  3662. $last_end_wide = isset($p['end_wide']) && $p['end_wide'];
  3663. }
  3664. }else{
  3665. $this->MakeSinglePost($post,true, false,"active_post",false, false, false, true, false, false);
  3666. ?><script>
  3667. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($post),0,100)))?>";
  3668. </script><?php
  3669. } $class_add=""; if(isset($post['tid']['first']['no_time'])){ $class_add=' hidden_on_print'; } ?>
  3670. </ul>
  3671. <div class='smaller align_right<?=$class_add;?>'>
  3672. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3673. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3674. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3675. </div>
  3676. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  3677. <div class='hidden_on_print'>
  3678. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3679. </div>
  3680. <?php }
  3681. $this->MakeCommentSection($post);
  3682. ?>
  3683. </div>
  3684. <?php if(isset($post['slides']) || ($is_thread&&isset($post['tid']['slides']))){ ?>
  3685. <div class='slides_buttons code' onclick="event.stopPropagation();">
  3686. <a onclick="SlidesFontCheck(-1)">T-</a> <a onclick="SlidesFontCheck(1)">T+</a>&nbsp;
  3687. <a onclick="SlidesStart(null)"><<</a> <a onclick="SlidesCheck(-1);"><</a>
  3688. <a onclick="SlidesStart(1)"><span id="slides_now">1</span>/<span id="slides_total">1</span></a>
  3689. <a onclick="SlidesCheck(1);">></a> <a onclick="SlidesEnd();">X</a>
  3690. </div>
  3691. <script>
  3692. function SlidesStart(from_here){
  3693. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return;
  3694. sdone=0; fp=0; if(from_here){
  3695. urlParams = new URLSearchParams(window.location.search);
  3696. fp = urlParams.get('post');
  3697. }
  3698. document.querySelector("#slides_total").innerText=slides.length; cur=document.querySelector("#slides_now");
  3699. for(i=0;i<slides.length;i++){ slides[i].style.display="none";
  3700. if(from_here && slides[i].dataset.postId==fp){ slides[i].style.display="table-cell";sdone=1; ClickPost(slides[i],0,true); cur.innerText=i+1; }
  3701. } if(!sdone){ slides[0].style.display="table-cell"; ClickPost(slides[0],0,true); cur.innerText=1; }
  3702. c=document.querySelector('.center'); if(!c) return;
  3703. c.classList.remove('center'); c.classList.add('center_slides'); if(c.dataset.fontSize){ c.style.fontSize=c.dataset.fontSize; }
  3704. c=document.querySelector('.left'); if(!c) return; c.style.display="none";
  3705. }
  3706. function SlidesCheck(offset){
  3707. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return; cur=document.querySelector("#slides_now");
  3708. for(i=0;i<slides.length;i++){ if(slides[i].style.display=="table-cell" && slides[i+offset] && (i+offset)>=0){
  3709. slides[i+offset].style.display="table-cell"; slides[i].style.display="none"; ClickPost(slides[i+offset],0,true); cur.innerText=i+offset+1; break;
  3710. }
  3711. }
  3712. }
  3713. function SlidesFontCheck(offset){
  3714. c=document.querySelector('.center_slides'); if(!c) return;
  3715. f=5; if(c.style.fontSize){ f=parseInt(c.style.fontSize); }
  3716. f+=offset; if(f<=0) f=1; if(f>12) f=12; c.style.fontSize=""+f+"vmin"; c.dataset.fontSize=c.style.fontSize;
  3717. }
  3718. function SlidesEnd(){
  3719. c=document.querySelector('.center_slides'); if(!c) return;
  3720. c.classList.remove('center_slides'); c.classList.add('center'); c.style.fontSize="";
  3721. c=document.querySelector('.left'); if(!c) return; c.style.display="inline-block";
  3722. slides=document.querySelectorAll('.print_column > .post'); if(!slides || !slides[0]) return;
  3723. for(i=0;i<slides.length;i++){ slides[i].style.display=""; }
  3724. }
  3725. //document.addEventListener("wheel", function(event){ if(event.deltaY>0) SlidesCheck(1); else SlidesCheck(-1); }, { passive: false });
  3726. document.addEventListener("click", function(event){ SlidesCheck(1); });
  3727. document.addEventListener('keydown', function(event) {
  3728. const key = event.key; // "ArrowRight", "ArrowLeft", "ArrowUp", or "ArrowDown"
  3729. switch(key){
  3730. case "ArrowUp": case "ArrowLeft": SlidesCheck(-1); break; case "ArrowDown": case "ArrowRight": SlidesCheck(1); break;
  3731. case "Escape": SlidesEnd(); break;
  3732. }
  3733. });
  3734. </script>
  3735. <?php }
  3736. }
  3737. function MakePostSectionExp(&$post){
  3738. $this->Anchors = []; $is_thread = isset($post['tid']);
  3739. ?>
  3740. <div class='center_exp' id='div_center'><br class='hidden_on_print' />
  3741. <ul>
  3742. <?php $is_reversed=false;
  3743. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false;
  3744. foreach($use_arr as &$p){
  3745. $this->MakeSinglePostExp($p);
  3746. if($p == $th['first']){?>
  3747. <script>
  3748. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  3749. </script>
  3750. <?php } if($is_reversed && !$hinted){ ?>
  3751. <li class='gray smaller bold' style='text-align:center;'>
  3752. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3753. <?php $hinted = true; }
  3754. }
  3755. }else{
  3756. $this->MakeSinglePostExp($post);
  3757. ?><!--<script>
  3758. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
  3759. </script>--><?php
  3760. } ?>
  3761. </ul>
  3762. </div>
  3763. <?php
  3764. }
  3765. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  3766. <div class='here_image_box clean_a'>
  3767. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  3768. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  3769. <?php if($image_okay){ ?>
  3770. <?php if(isset($im['video']) && isset($im['video'])!=""){ ?>
  3771. <video controls><source src='<?=$im['file'];?>' type='<?=$im['video']?>'></video>
  3772. <?php }else{ ?>
  3773. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  3774. <?php } ?>
  3775. <?php } $this->MakeHereButtons($im, false); ?>
  3776. </div>
  3777. <?php }
  3778. function MakeSideGalleryCode(){?>
  3779. <div>
  3780. <h3><?=$this->T('点击图片以插入:')?></h3>
  3781. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3782. <option value="main"><?=$this->T('全部')?></option>
  3783. <?php if($this->LoggedIn){ ?>
  3784. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3785. <?php }?>
  3786. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3787. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3788. <?php } ?>
  3789. </select>
  3790. <div id='side_gallery'>
  3791. </div>
  3792. </div>
  3793. <script>
  3794. function InsertImage(imgname){
  3795. t = document.querySelector("#post_content");
  3796. v = t.value;
  3797. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3798. la_auto_grow(t);
  3799. }
  3800. function RefreshSideGallery(){
  3801. let xhr = new XMLHttpRequest();
  3802. xhr.onreadystatechange = (function(){
  3803. if (this.readyState === this.DONE) {
  3804. if (this.status === 200) {
  3805. ind = document.querySelector("#side_gallery");
  3806. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3807. str = "<ul class='side_thumb'>"
  3808. for (const m of res) {
  3809. imgstr = "<img src='"+m[2]+"' />";
  3810. if(m[2].match('\.mp4')){
  3811. imgstr = "<video><source src='"+m[2]+"'></video>";
  3812. }
  3813. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+imgstr+"</div>"
  3814. }
  3815. str += "</ul>"
  3816. ind.innerHTML = str;
  3817. }
  3818. }
  3819. }
  3820. });
  3821. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3822. xhr.send();
  3823. }
  3824. </script>
  3825. <?php
  3826. }
  3827. function MakeUploader($is_side=false){ ?>
  3828. <div id='upload_operation_area' class='hidden_on_print'>
  3829. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3830. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3831. <ul id='file_list'>
  3832. </ul>
  3833. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3834. </div>
  3835. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3836. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3837. <script>
  3838. function pastehandler(event){
  3839. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3840. for (index in items) {
  3841. var item = items[index];
  3842. if (item.kind === 'file') {
  3843. put = document.querySelector("#_uploader");
  3844. if(put) ShowSideUploader();
  3845. var blob = item.getAsFile();
  3846. AddImageFile(blob);
  3847. return;
  3848. }
  3849. }
  3850. }
  3851. let _fd_list = []; var uploading=0;
  3852. let hint=document.querySelector('#upload_hint');
  3853. function ToggleCompress(button){
  3854. li = button.parentNode;
  3855. num=li.dataset.number;
  3856. for(i=0;i<_fd_list.length;i++){
  3857. if (_fd_list[i][0] == num){
  3858. state = _fd_list[i][2];
  3859. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3860. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3861. }
  3862. }
  3863. }
  3864. function RemoveFromUpload(button){
  3865. li = button.parentNode;
  3866. num=li.dataset.number;
  3867. for(i=0;i<_fd_list.length;i++){
  3868. if (_fd_list[i][0] == num){
  3869. _fd_list.splice(i, 1);break;
  3870. }
  3871. }
  3872. li.parentNode.removeChild(li);
  3873. }
  3874. function EndThisUpload(){
  3875. unfinished = 0;
  3876. for(i=0;i<_fd_list.length;i++){
  3877. if (_fd_list[i][3]==0){
  3878. unfinished=1;
  3879. }
  3880. }
  3881. if(!unfinished){
  3882. uploading=0;
  3883. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3884. cl=document.querySelector('#upload_click');
  3885. if(!cl.dataset.isSide){
  3886. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3887. cl.href=window.location.href;
  3888. }else{
  3889. _fd_list.splice(0,_fd_list.length);
  3890. fl = document.querySelector("#file_list");
  3891. fl.innerHTML = "";
  3892. list=document.querySelector('#upload_operation_area');
  3893. list.style.pointerEvents='';
  3894. list.style.opacity='';
  3895. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3896. document.onpaste=pastehandler;
  3897. RefreshSideGallery();
  3898. }
  3899. }
  3900. }
  3901. function UploadList(){
  3902. if(!_fd_list.length || uploading) return;
  3903. uploading=1;
  3904. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3905. list=document.querySelector('#upload_operation_area');
  3906. list.style.pointerEvents='none';
  3907. list.style.opacity='0.5';
  3908. document.onpaste="";
  3909. for(i=0;i<_fd_list.length;i++){
  3910. let xhr = new XMLHttpRequest();
  3911. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3912. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3913. function wrap(li, i){
  3914. var ind = li.querySelector('._compress_toggle')
  3915. return function(){
  3916. if (this.readyState === this.DONE) {
  3917. if (this.status === 200) {
  3918. var response = xhr.responseText;
  3919. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3920. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3921. _fd_list[i][3] = 1;
  3922. }else{
  3923. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3924. _fd_list[i][3] = 1;
  3925. }
  3926. EndThisUpload();
  3927. }
  3928. }
  3929. }
  3930. }
  3931. xhr.onreadystatechange = wrap(li, i);
  3932. xhr.send(_fd_list[i][1]);
  3933. }
  3934. }
  3935. function AddImageFile(blob){
  3936. var ext="";
  3937. if(blob.name.match(/png$/i))ext = 'png';
  3938. else if(blob.name.match(/jpg$/i))ext = 'jpg';
  3939. else if(blob.name.match(/jpeg$/i))ext = 'jpeg';
  3940. else if(blob.name.match(/gif$/i))ext = 'gif';
  3941. else if(blob.name.match(/mp4$/i))ext = 'mp4';
  3942. else return;
  3943. var fd = new FormData();
  3944. blob.name = blob.name=generateUID().toString();
  3945. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3946. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3947. var reader = new FileReader();
  3948. reader.onload = function(event){
  3949. fl = document.querySelector("#file_list");
  3950. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3951. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3952. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3953. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3954. fl.innerHTML+=ht;
  3955. };
  3956. reader.readAsDataURL(blob);
  3957. }
  3958. sel = document.querySelector('#upload_selector');
  3959. sel.addEventListener("change", function(){
  3960. var input = this;
  3961. function ff(file){
  3962. return function(e){
  3963. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3964. blob.name = file.name;
  3965. AddImageFile(blob);
  3966. }
  3967. }
  3968. for(i=0;i<input.files.length;i++){
  3969. if(input.files[i].size){
  3970. let reader = new FileReader();
  3971. reader.onload = ff(input.files[i]);
  3972. reader.readAsArrayBuffer(input.files[i]);
  3973. }
  3974. }
  3975. });
  3976. function generateUID() {
  3977. var firstPart = (Math.random() * 46656) | 0;
  3978. var secondPart = (Math.random() * 46656) | 0;
  3979. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3980. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3981. return firstPart + secondPart;
  3982. }
  3983. document.onpaste = pastehandler;
  3984. function dropHandler(ev) {
  3985. put = document.querySelector("#_uploader");
  3986. if(put) ShowSideUploader();
  3987. bkg=document.querySelector('#dropping_background');
  3988. bkg.style.display="none";
  3989. console.log('File(s) dropped');
  3990. ev.preventDefault();ev.stopPropagation();
  3991. if (ev.dataTransfer && ev.dataTransfer.items) {
  3992. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3993. if (ev.dataTransfer.items[i].kind === 'file') {
  3994. var file = ev.dataTransfer.items[i].getAsFile();
  3995. function ff(file){
  3996. return function(e){
  3997. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3998. blob.name = file.name;
  3999. AddImageFile(blob);
  4000. }
  4001. }
  4002. if(file){
  4003. let reader = new FileReader();
  4004. reader.onload = ff(file);
  4005. reader.readAsArrayBuffer(file);
  4006. }
  4007. }
  4008. }
  4009. } else {
  4010. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  4011. function ff(file){
  4012. return function(e){
  4013. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  4014. blob.name = file.name;
  4015. AddImageFile(blob);
  4016. }
  4017. }
  4018. if(ev.dataTransfer.files[i].size){
  4019. let reader = new FileReader();
  4020. reader.onload = ff(ev.dataTransfer.files[i]);
  4021. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  4022. }
  4023. }
  4024. }
  4025. }
  4026. function dragOverHandler(ev) {
  4027. bkg=document.querySelector('#dropping_background');
  4028. bkg.style.display="";
  4029. console.log('File(s) in drop zone');
  4030. ev.preventDefault();
  4031. }
  4032. </script>
  4033. <?php
  4034. }
  4035. function CanShowGallery(&$g){
  4036. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  4037. return true;
  4038. }
  4039. function CanShowImage(&$im){
  4040. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  4041. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  4042. }
  4043. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  4044. return true;
  4045. }
  4046. function GetImageBatch($from,$show_all){
  4047. if(!isset($_GET['gallery'])) return;
  4048. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){$name=$_GET['gallery'];}
  4049. $reached=0; $count=0;
  4050. if(isset($this->Images[0])) foreach($this->Images as $im){
  4051. if(isset($from)&&!$reached){ if($from==$im['name']){ $reached=1; } continue; }
  4052. if(!$this->CanShowImage($im)){ continue; }
  4053. if($_GET['gallery']=='trash') $name='trash';
  4054. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;} ?>
  4055. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  4056. <?php if($this->LoggedIn){ ?>
  4057. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  4058. <?php } ?>
  4059. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  4060. <?php if(isset($im['video']) && $im['video']!=""){ ?>
  4061. <video data-imgsrc='<?=$im["name"]?>'><source src='<?=$im['file']?>' type='<?=$im['video']?>'></video>
  4062. <?php }else{ ?>
  4063. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  4064. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  4065. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>
  4066. <?=isset($im['align'])?'data-align="'.$im["align"].'" style="object-position:'.$im['align'].';"':""?>/>
  4067. <?php } ?>
  4068. </a>
  4069. </div>
  4070. <?php $count+=isset($im['parent'])?0:1; if((!$show_all)&&($count>=$this->GalleryStep)){ break; }
  4071. }
  4072. if($count<$this->GalleryStep){ ?><div style='display:none'>END_GALLERY</div><?php return 0; }
  4073. return 1;
  4074. }
  4075. function MakeGallerySection(){
  4076. if(!isset($_GET['gallery'])) return;
  4077. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){ $name=$_GET['gallery'];}
  4078. $show_all=0; if(isset($_GET['show_all']) && $_GET['show_all']!='0'){ $show_all=1; } ?>
  4079. <script>
  4080. document.title+=" | <?=$this->T('画廊')?>";
  4081. </script>
  4082. <div class='center_wide' id='div_center' style='position:relative;'><br class='hidden_on_print' />
  4083. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  4084. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  4085. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  4086. <?php $description=(isset($gal) && isset($gal['description']))?$gal['description']:null; ?>
  4087. <div class='hidden_on_desktop'>
  4088. <?=$this->T('前往')?>
  4089. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  4090. <optgroup label="<?=$this->T('精选')?>">
  4091. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4092. if(!isset($g['featured']) || !$g['featured'] ||
  4093. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  4094. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  4095. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  4096. <?php } ?></optgroup><optgroup label="<?=$this->T('其他相册')?>">
  4097. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  4098. <?php if($this->LoggedIn){ ?>
  4099. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  4100. <?php } ?>
  4101. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4102. if((isset($g['featured']) && $g['featured']) ||
  4103. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  4104. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  4105. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  4106. <?php } ?></optgroup>
  4107. </select>
  4108. </div>
  4109. <?php if($this->LoggedIn){?>
  4110. <div>
  4111. <?php if(isset($name)){ ?>
  4112. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  4113. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  4114. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  4115. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  4116. <?=$this->T('取消精选')?></a>
  4117. <?php }else{ ?>
  4118. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  4119. <?=$this->T('设为精选')?></a>
  4120. <?php } ?><br />
  4121. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  4122. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  4123. <?=$this->T('取消实验')?></a>
  4124. <?php }else{ ?>
  4125. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  4126. <?=$this->T('设为实验')?></a>
  4127. <?php } ?>
  4128. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  4129. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  4130. <a href='javascript:HidePopMenu();'>×</a>
  4131. <hr />
  4132. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  4133. </div>
  4134. </div>
  4135. <?php } ?>
  4136. <?php $this->MakeUploader(false); ?>
  4137. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  4138. <div style='position:relative'>
  4139. <?php if(isset($name)){ ?>
  4140. <a href='javascript:ShowGalleryEditMenu("<?=$name?>",null)'><?=$this->T('改名')?></a>
  4141. <a href='javascript:ShowGalleryEditMenu("<?=$name?>","<?=$description?>")'><?=$this->T('描述')?></a>
  4142. <?php } ?>
  4143. <a href='javascript:ShowGalleryEditMenu(null,null)'><?=$this->T('添加')?></a>
  4144. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  4145. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  4146. method="post" style='display:none;' id='gallery_edit_form'></form>
  4147. <a style='float:left;'><?=$this->T('设置为:')?></a>
  4148. <a href='javascript:HidePopMenu();'>×</a>
  4149. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  4150. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  4151. <input type='text' form='gallery_edit_form' name='gallery_edit_description' id='gallery_edit_description' style='width:10em;display:none'>
  4152. <input class='button' type='submit' form='gallery_edit_form'
  4153. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  4154. </div>
  4155. </div>
  4156. </div>
  4157. <div class='smaller hidden_on_print'>
  4158. <form action="<?=$_SERVER['REQUEST_URI']?>"
  4159. method="post" style='display:none;' id='gallery_move_form'></form>
  4160. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  4161. id='gallery_move_ops' style='display:none'>
  4162. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  4163. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  4164. <p><?=$this->T('添加到')?>
  4165. <select id="gallery_move_to">
  4166. <option value="trash"><?=$this->T('垃圾桶')?></option>
  4167. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  4168. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  4169. <?php } ?>
  4170. </select>
  4171. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  4172. </p>
  4173. <p>
  4174. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  4175. </p>
  4176. </div>
  4177. </div>
  4178. <?php } $desc=isset($description)?$this->GetPost($description):null;
  4179. if(isset($desc)){ ?><ul class='print_column list'><br /><?php
  4180. $this->MakeSinglePost($desc, false, false, false, false, false, false, false, false, true, false);
  4181. ?></ul><?php } ?>
  4182. <br />
  4183. <div><div class='p_row'><?php $has_more=$this->GetImageBatch(NULL, $show_all);?>
  4184. <div class='p_thumb p_thumb_end' <?=$has_more?"onclick='ThisGetMore(this);'":""?>>
  4185. <a onclick='event.preventDefault();' href='index.php?gallery=<?=$_GET['gallery']?>&show_all=1'>
  4186. <h2 id="btn_more_images"><?=$has_more?$this->T("查看更多"):$this->T("没有更多的了");?></a></h2></div></div>
  4187. </div>
  4188. </div>
  4189. <script type='text/javascript'>
  4190. function ThisGetMore(end_ui){
  4191. var xhr = new XMLHttpRequest();
  4192. xhr.onreadystatechange = function() {
  4193. if (this.readyState == 4 && this.status == 200) {
  4194. doc = document.createElement("div"); doc.innerHTML=xhr.responseText.trim(); next_child=null;
  4195. for(child=doc.firstChild; child!==null; child=next_child) { next_child=child.nextSibling; end_ui.parentNode.insertBefore(child,end_ui); }
  4196. doc.remove();
  4197. if(xhr.responseText.search('END_GALLERY')>=0){ end_ui.onclick=null; end_ui.innerHTML="<h2><?=$this->T("没有更多的了");?></h2>"; }
  4198. UpdateImageClickables();
  4199. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("查看更多");?>";
  4200. }
  4201. };
  4202. btn=document.getElementById("btn_more_images"); if(btn) btn.innerText="<?=$this->T("稍等");?>";
  4203. im=end_ui.previousElementSibling.querySelector('img,video');
  4204. from=im?im.dataset.imgsrc:null; if(!from) return;
  4205. const urlParams = new URLSearchParams(window.location.search); const gallery = urlParams.get('gallery')
  4206. xhr.open("GET", "index.php?gallery_continue="+from+'&gallery='+gallery, true);
  4207. xhr.send();
  4208. }
  4209. <?php if($this->LoggedIn){ ?>
  4210. var selected_image = new Array();
  4211. function RemoveFromGallery(){
  4212. form = document.querySelector('#gallery_move_form');
  4213. ops = document.querySelector('#gallery_move_ops');
  4214. sel = document.querySelector('#gallery_move_to');
  4215. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  4216. form.submit();
  4217. }
  4218. function AddToGallery(){
  4219. form = document.querySelector('#gallery_move_form');
  4220. ops = document.querySelector('#gallery_move_ops');
  4221. sel = document.querySelector('#gallery_move_to');
  4222. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  4223. form.submit();
  4224. }
  4225. function ClearSelectedImages(){
  4226. selected_image.splice(0, selected_image.length);
  4227. checks = document.querySelectorAll('._select_hook');
  4228. [].forEach.call(checks, function(c){
  4229. c.classList.remove('p_thumb_selected');
  4230. });
  4231. count = document.querySelector('#gallery_selected_count');
  4232. count.innerHTML="0";
  4233. }
  4234. function ToggleSelectImage(elem, name){
  4235. count = document.querySelector('#gallery_selected_count');
  4236. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  4237. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  4238. count.innerHTML=selected_image.length.toString()
  4239. }
  4240. function ShowGalleryEditMenu(old_name,desc){
  4241. m = document.querySelector('#gallery_edit_menu');
  4242. old = document.querySelector('#gallery_edit_old_name');
  4243. newname = document.querySelector('#gallery_edit_new_name');
  4244. description = document.querySelector('#gallery_edit_description');
  4245. m.style.display='block';
  4246. if(desc!==null){ description.style.display='block';newname.style.display='none';description.value=desc;}
  4247. else{ description.style.display='none';newname.style.display='';}
  4248. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  4249. }
  4250. function ShowDeleteMenu(){
  4251. m=document.querySelector('#gallery_delete_menu');
  4252. m.style.display='block';
  4253. }
  4254. <?php } ?>
  4255. </script>
  4256. <?php
  4257. }
  4258. function MakeGalleryLeft(){?>
  4259. <div class='left hidden_m gallery_left' id='div_left'><div><br /></div>
  4260. <h2><?=$this->T('相册')?></h2>
  4261. <div>
  4262. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  4263. <ul>
  4264. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4265. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  4266. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4267. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  4268. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4269. <?php } ?>
  4270. </ul>
  4271. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  4272. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  4273. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  4274. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4275. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  4276. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4277. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  4278. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4279. <?php } ?>
  4280. <?php if($this->LoggedIn){ ?>
  4281. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  4282. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  4283. <?php } ?>
  4284. </ul></div>
  4285. <p>&nbsp;</p>
  4286. <script>
  4287. </script>
  4288. </div>
  4289. </div>
  4290. <?php
  4291. }
  4292. function MakeStatistics(){
  4293. $this->ReadPosts(); $this->ReadImages(); $this->ReadArchive();
  4294. $list=[]; $last_date=null; $info=[]; $info['count']=0; $info['edits']=0; $info['length']=0;
  4295. $imlist=[]; $imlast_date=null; $iminfo=[]; $iminfo['count']=0;
  4296. $maxposts=0; $maxlength=0; $maximages=0;
  4297. foreach($this->Posts as &$p){ $is_ref=0;
  4298. $this_date=substr($p['id'],0,8);
  4299. if($last_date!=null && $last_date!=$this_date){
  4300. if($maxposts<$info['count']+$info['edits'])$maxposts=$info['count']+$info['edits'];
  4301. if($maxlength<$info['length'])$maxlength=$info['length'];
  4302. $list[]=$info; $info=[]; $info['count']=0; $info['edits']=0; $info['length']=0;
  4303. }
  4304. $ah = &$this->GetArchiveHandle($p['id']); if(isset($ah)&&isset($ah['list'][0])) $info['edits']+=count($ah['list']);
  4305. $info['count']++; $info['id']=$this_date; if(isset($p['content']))$info['length']+=strlen($p['content']); $last_date=$this_date;
  4306. }
  4307. $last_date=null;
  4308. foreach($this->Images as &$im){ $is_ref=0;
  4309. $this_date=substr($im['name'],0,8);
  4310. if($last_date!=null && $last_date!=$this_date){
  4311. if($maximages<$iminfo['count'])$maximages=$iminfo['count'];
  4312. $imlist[]=$iminfo; $iminfo=[]; $iminfo['count']=0;
  4313. }
  4314. $iminfo['count']++; $iminfo['id']=$this_date; $last_date=$this_date;
  4315. }
  4316. if($info!=[]) $list[]=$info;
  4317. if($iminfo!=[]) $imlist[]=$iminfo;
  4318. if(!isset($list[0])) return;
  4319. $earliest=DateTimeImmutable::createFromFormat('!Ymd',$list[0]['id']); $ey=substr($list[0]['id'],0,4);
  4320. $latest=DateTimeImmutable::createFromFormat('!Ymd',end($list)['id']); $ly=substr(end($list)['id'],0,4);
  4321. $days=$earliest->diff($latest)->days; $lw=2.0; $dw=$days*$lw; $spw=20;
  4322. ?>
  4323. <style>.stastics_posts{direction:ltr;} .stastics_posts line,.stastics_posts circle{stroke:#f8ca9b; stroke-width:2px;}
  4324. .stastics_posts .line_edits{stroke:#f8ca9b40;}
  4325. .stastics_posts .line_year{stroke:#f8ca9b30; stroke-width:2px;} .stastics_posts text{fill:#f8ca9ba0; font: 0.9em serif;}
  4326. </style>
  4327. <div class='settings'><h2><?=$this->T('统计')?></h2><br />
  4328. <div style="overflow:auto;direction:rtl;width:100%;">
  4329. <svg class='stastics_posts' viewBox="-<?=$spw?> -<?=$spw?> <?=$days*$lw+$spw*6?> <?=200+4*$spw?>" height="<?=200+4*$spw?>" width="<?=$days*$lw+$spw*6?>">
  4330. <?php foreach($list as $info){ $itv=DateTimeImmutable::createFromFormat('!Ymd',$info['id'])->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);
  4331. $p1=100.0*(1-$info['count']/$maxposts); $p2=$p1-100.0*$info['edits']/$maxposts;
  4332. $p3=100.0*$info['length']/$maxlength+$spw+100; ?>
  4333. <line x1="<?=$ds?>" x2="<?=$ds?>" y1="100.0" y2="<?=$p1?>"/>
  4334. <?php if($info['edits']>0){ ?><line class='line_edits' x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=$p1?>" y2="<?=$p2?>"/><?php } ?>
  4335. <?php if($info['length']>0){ ?><line class='line_edits' x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=$spw+100?>" y2="<?=$p3?>"/><?php } ?>
  4336. <?php } ?>
  4337. <?php foreach($imlist as $im){ $itv=DateTimeImmutable::createFromFormat('!Ymd',$im['id'])->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);
  4338. $p1=100+$spw+100.0*($im['count']/$maximages); ?>
  4339. <circle cx="<?=$ds?>" cy="<?=$p1?>" r='3'/>
  4340. <?php } ?>
  4341. <?php for($y=$ey;$y<=$ly;$y++){ $itv=DateTimeImmutable::createFromFormat('!Y',$y)->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);?>
  4342. <line x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=220+$spw?>" y2="-<?=$spw?>" class='line_year'/>
  4343. <text x="<?=$ds+4?>" y="-4"><?=$y?></text>
  4344. <text x="<?=$ds+4?>" y="<?=$spw*2+200-4?>"><?=$y?></text>
  4345. <?php for($ym=1;$ym<=12;$ym++){ $st=str_pad($ym,2,'0',STR_PAD_LEFT); $itv2=DateTimeImmutable::createFromFormat('!Ym',$y.$st)->diff($earliest);
  4346. $dds=$lw/2+$lw*$itv2->days*($itv2->invert?1:-1); if($dds<0||$dds>$lw/2+$dw) continue; ?>
  4347. <line x1="<?=$dds?>" x2="<?=$dds?>" y1="<?=100+$spw?>" y2="100" class='line_year'/>
  4348. <text x="<?=$dds+4?>" y="<?=100+$spw-3?>"><?=$ym?></text>
  4349. <?php } } ?>
  4350. <line x1="<?=$lw/2+$dw?>" x2="<?=$days*$lw?>" y1="<?=220+$spw?>" y2="-<?=$spw?>" class='line_year'/>
  4351. <line x1="0" x2="<?=$dw?>" y1="0" y2="0" class='line_year'/>
  4352. <line x1="0" x2="<?=$dw?>" y1="100" y2="100" class='line_year'/>
  4353. <line x1="0" x2="<?=$dw?>" y1="<?=100+$spw?>" y2="<?=100+$spw?>" class='line_year'/>
  4354. <line x1="0" x2="<?=$dw?>" y1="<?=200+$spw?>" y2="<?=200+$spw?>" class='line_year'/>
  4355. <text x="<?=$dw+10?>" y="8"><?=$maxposts?></text>
  4356. <text x="<?=$dw+10?>" y="<?=$spw+8?>"><tspan style='fill:#f8ca9b;'>▪ <?=$this->T('新增')?></tspan></text>
  4357. <text x="<?=$dw+10?>" y="<?=$spw*2+8?>"><tspan style='fill:#f8ca9ba0;'>▪ <?=$this->T('改动')?></tspan></text>
  4358. <text x="<?=$dw+10?>" y="<?=$spw*2+200-4?>"><?=$maxlength?></text>
  4359. <text x="<?=$dw+10?>" y="<?=$spw+200-4?>"><tspan style='fill:#f8ca9b;'><?=$maximages?></tspan></text>
  4360. <text x="<?=$dw+10?>" y="<?=200-4?>"><tspan style='fill:#f8ca9b;'>▪ <?=$this->T('媒体')?></text>
  4361. <text x="<?=$dw+10?>" y="<?=200-4-$spw?>">▪ <?=$this->T('长度')?></tspan></text>
  4362. </svg></div>
  4363. <br /><br />
  4364. </div>
  4365. <?php
  4366. }
  4367. function MakeSettings(){?>
  4368. <div class='settings'>
  4369. <h2><?=$this->T('设置')?></h2>
  4370. <table style='white-space:nowrap;'>
  4371. <?php if($this->LoggedIn){ ?>
  4372. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4373. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4374. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4375. <tr><td><?=$this->T('网站标题')?></td>
  4376. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4377. value='<?=$this->Title?>'/></td></tr>
  4378. <tr><td><?=$this->T('短标题')?></td>
  4379. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4380. value='<?=$this->ShortTitle?>'/></td></tr>
  4381. <tr><td><?=$this->T('显示名称')?></td>
  4382. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4383. value='<?=$this->DisplayName?>'/></td></tr>
  4384. <tr><td><?=$this->T('电子邮件')?></td>
  4385. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4386. value='<?=$this->EMail?>'/></td></tr>
  4387. <tr><td><?=$this->T('导航栏')?>
  4388. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4389. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4390. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4391. <tr><td><?=$this->T('侧边栏')?>
  4392. <?=isset($this->SpecialSidebar)?"<a href='?post=".$this->SpecialSidebar."'>→</a>":""?></td>
  4393. <td><input type="text" form="settings_form" id='settings_special_sidebar' name='settings_special_sidebar'
  4394. value='<?=$this->SpecialSidebar?>'/></td></tr>
  4395. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4396. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4397. value='<?=$this->SpecialFooter?>'/></td></tr>
  4398. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4399. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4400. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4401. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4402. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4403. value='<?=$this->SpecialPinned?>'/></td></tr>
  4404. <tr><td><?=$this->T('默认相册')?></td>
  4405. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4406. value='<?=$this->DefaultGallery?>'/></td></tr>
  4407. <tr><td><?=$this->T('相册单步')?></td>
  4408. <td><input type="text" form="settings_form" id='settings_gallery_step' name='settings_gallery_step'
  4409. value='<?=$this->GalleryStep?>'/></td></tr>
  4410. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4411. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4412. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4413. <tr><td><?=$this->T('启用评论')?></td>
  4414. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4415. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4416. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  4417. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4418. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4419. <tr><td><?=$this->T('长毛象实例')?></td>
  4420. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4421. value='<?=$this->MastodonURL?>'/></td></tr>
  4422. <tr><td><?=$this->T('长毛象令牌')?></td>
  4423. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4424. value='<?=$this->MastodonToken?>'/></td></tr>
  4425. <tr><td><?=$this->T('偏好语言')?></td>
  4426. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4427. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4428. <tr><td><?=$this->T('本站地址')?></td>
  4429. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4430. value='<?=$this->HostURL?>'/></td></tr>
  4431. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4432. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4433. <tr><td><?=$this->T('用户名')?></td>
  4434. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4435. value='<?=$this->APubID?>'/></td></tr>
  4436. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4437. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4438. <tr><td><?=$this->T('主机')?></td>
  4439. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4440. value='<?=$this->HereHost?>'/></td></tr>
  4441. <tr><td><?=$this->T('网站标题')?></td>
  4442. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4443. value='<?=$this->HereTitle?>'/></td></tr>
  4444. <tr><td><?=$this->T('短标题')?></td>
  4445. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4446. value='<?=$this->HereShortTitle?>'/></td></tr>
  4447. <tr><td><?=$this->T('相册')?></td>
  4448. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4449. value='<?=$this->HereAlbum?>'/></td></tr>
  4450. <tr><td><?=$this->T('导航栏')?>
  4451. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4452. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4453. value='<?=$this->HereNavigation?>'/></td></tr>
  4454. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4455. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4456. value='<?=$this->HereFooter?>'/></td></tr>
  4457. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4458. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4459. <tr><td><?=$this->T('主机')?></td>
  4460. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4461. value='<?=$this->ExpHost?>'/></td></tr>
  4462. <tr><td><?=$this->T('网站标题')?></td>
  4463. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4464. value='<?=$this->ExpTitle?>'/></td></tr>
  4465. <tr><td><?=$this->T('短标题')?></td>
  4466. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4467. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4468. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4469. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4470. value='<?=$this->ExpCaution?>'/></td></tr>
  4471. <tr><td><?=$this->T('相册')?></td>
  4472. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4473. value='<?=$this->ExpAlbum?>'/></td></tr>
  4474. <tr><td><?=$this->T('导航栏')?>
  4475. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4476. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4477. value='<?=$this->ExpNavigation?>'/></td></tr>
  4478. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4479. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4480. value='<?=$this->ExpFooter?>'/></td></tr>
  4481. <tr><td><?=$this->T('允许选择语言')?>
  4482. <td><input type="checkbox" id="settings_allow_language" name="settings_allow_language"
  4483. form="settings_form" <?=$this->AllowLanguageChoices?"checked":""?>/></td></tr>
  4484. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4485. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4486. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  4487. <tr><td><?=$this->T('帐号')?></td>
  4488. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4489. value='<?=$this->Admin?>'/></td></tr>
  4490. <tr><td><?=$this->T('新密码')?></td>
  4491. <td><input type="password" form="settings_form"
  4492. id='settings_new_password' name='settings_new_password' /></td></tr>
  4493. <tr><td><?=$this->T('再次输入')?></td>
  4494. <td><input type="password" form="settings_form"
  4495. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4496. <tr><td><?=$this->T('旧密码')?></td>
  4497. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4498. <?php }else{ ?>
  4499. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4500. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4501. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4502. <tr><td><?=$this->T('帐号')?></td>
  4503. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4504. <tr><td><?=$this->T('密码')?></td>
  4505. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4506. <?php } ?>
  4507. </table>
  4508. <?php if($this->LoggedIn){ ?>
  4509. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4510. <?php }else{ ?>
  4511. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4512. <?php } ?>
  4513. </div>
  4514. <?php
  4515. }
  4516. function MakeExtraOperations(){?>
  4517. <div class='settings' style='overflow:auto;'>
  4518. <h2><?=$this->T('附加操作')?></h2>
  4519. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  4520. <p>&nbsp;</p>
  4521. <h3><?=$this->T('自动重定向')?></h3>
  4522. <span class='smaller gray'>
  4523. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4524. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4525. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4526. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  4527. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4528. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4529. value='<?=$this->T('保存重定向设置')?>' />
  4530. <p>&nbsp;</p>
  4531. <h3><?=$this->T('自定义翻译')?></h3>
  4532. <span class='smaller gray'>
  4533. <?=$this->T('填写格式:')?>
  4534. <br /><pre>- 语言 | Language</pre></span>
  4535. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4536. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  4537. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4538. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4539. value='<?=$this->T('保存翻译')?>' />
  4540. <p>&nbsp;</p>
  4541. <p class='smaller gray'><?=$this->T('ActivityPub 测试:')?></p>
  4542. <ul>
  4543. <li><a href='index.php?TestAPubDeliver=1'><?=$this->T('测试发送')?></a></li></ui>
  4544. </ui>
  4545. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4546. <ul>
  4547. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  4548. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  4549. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  4550. </ui>
  4551. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4552. </div>
  4553. <?php
  4554. }
  4555. function MakeMainBegin(){?>
  4556. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4557. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4558. <?php
  4559. }
  4560. function MakeMainEnd(){?>
  4561. </div>
  4562. <?php
  4563. }
  4564. function MakeExpFooter(){
  4565. $exptitle = isset($this->HereDisplayTitle)?('"'.trim($this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle))).'"'):NULL;
  4566. if(!isset($exptitle)) $exptitle=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle);?>
  4567. <div class='small_footer exp_h_f exp_f'><div>
  4568. <?php if($this->InExperimentalMode){ ?>
  4569. <b><?=$exptitle?></b>
  4570. <?php }else{ ?>
  4571. <b><?=$exptitle?></b> ©<?=$this->T($this->DisplayName)?>
  4572. <?php }?>
  4573. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):""; ?>
  4574. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4575. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4576. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4577. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4578. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4579. }?></div>
  4580. </div>
  4581. </div>
  4582. </div><!-- page -->
  4583. </body>
  4584. </html>
  4585. <script>
  4586. if(trans = document.getElementById('translate_button')){
  4587. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4588. }
  4589. </script>
  4590. <?php
  4591. }
  4592. function MakeImageOverlay($side_info=null,$static_image=null,$static_video=null){
  4593. $static=isset($side_info); ?>
  4594. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  4595. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  4596. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  4597. <?php if(!$static_video){ ?>
  4598. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/><?php } ?>
  4599. <?php if(!$static_image){ ?>
  4600. <video id='big_video' onloadstart="HideWaitingBar();" controls><source id='big_video_src' type='video/mp4'
  4601. <?=isset($static_video)?("src='".$static_video."'"):""?>></video><?php } ?>
  4602. </div>
  4603. <div class='big_side_box' onclick='HideBigImage(1);'>
  4604. <?php if(!$static){ ?>
  4605. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  4606. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  4607. <div class='lr_buttons'>←</div></a></div>
  4608. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  4609. <div class='lr_buttons'>→</div></a></div>
  4610. <div id='here_buttons'></div>
  4611. </div><?php } ?>
  4612. <div class='side_box_mobile_inner'>
  4613. <?php if(!$static){ ?>
  4614. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  4615. <span style='display:none;' id='image_purchase' class='clean_a'>
  4616. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  4617. <br class='hidden_on_desktop block_m' /></span>
  4618. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  4619. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4620. &nbsp;<a class='clean_a' id='image_inquiry'>
  4621. <b>@</b><?=$this->T('咨询')?></a>
  4622. <?php } ?><hr class='hidden_on_desktop block_m' />
  4623. </div>
  4624. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  4625. <li class='wayback_close'><a onclick='HideBigImage(1);'><?=$this->T('关闭')?> ×</a></li>
  4626. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  4627. <hr />
  4628. </div><?php } //static ?>
  4629. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  4630. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  4631. <br /><?=$this->T('印刷品链接')?>
  4632. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  4633. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  4634. <?=$this->T('重命名')?>
  4635. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  4636. <?=$this->T('主图')?>
  4637. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  4638. <?=$this->T('对齐')?> <select id='image_align' name='image_align' form="image_ops_form">
  4639. <option value='top'><?=$this->T('顶部')?></option>
  4640. <option value='middle'><?=$this->T('中间')?></option>
  4641. <option value='bottom'><?=$this->T('底部')?></option></select><br />
  4642. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  4643. <br /><br /><?=$this->T('替换图像')?>
  4644. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  4645. <input type="file" form='image_edit_form'
  4646. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  4647. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  4648. value=<?=$this->T('执行')?> />
  4649. </div><?php } ?>
  4650. </div>
  4651. </div>
  4652. </div>
  4653. <?php }
  4654. function MakePageEnd(){?>
  4655. </div><!-- page -->
  4656. </body>
  4657. </html>
  4658. <?php }
  4659. function MakeFooter(&$p){ $is_slides=(isset($p['slides']) || (isset($p['tid'])&&isset($p['tid']['slides']))); $no_title=isset($p['tid']['first']['no_title']);?>
  4660. <div class='small_footer'><div>
  4661. <hr />
  4662. <?php if(isset($p['tid']['footer'])){ ?><div class='show_on_print'><?=$p['tid']['footer'];?></div><?php } ?>
  4663. <b<?=$no_title?" class='hidden_on_print'":"";?>><?=$this->T($this->Title)?></b>
  4664. <span onclick='event.stopPropagation()'<?=$no_title?" class='hidden_on_print'":"";?>
  4665. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  4666. <div class='smaller show_on_print'><?=$_SERVER['SERVER_NAME']?><br /><?=$this->EMail?></div>
  4667. </div></div>
  4668. <div class='footer'>
  4669. <div style='white-space:nowrap;'>
  4670. <div class='footer_additional'>
  4671. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  4672. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4673. } ?>
  4674. </div>
  4675. <div class='footer_additional'>
  4676. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  4677. echo $this->GenerateSinglePost($p, false, false, false, false, false);
  4678. } ?>
  4679. </div>
  4680. </div>
  4681. </div>
  4682. <p>&nbsp;<p>
  4683. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  4684. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  4685. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  4686. </div>
  4687. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  4688. <script>
  4689. <?php if($is_slides){ ?>SlidesStart(null);<?php } ?>
  4690. <?=$this->ExtraScripts?>
  4691. if(back = document.getElementById('button_back')){
  4692. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  4693. back.href='javascript:history.back()';
  4694. }else{
  4695. back.href='index.php';
  4696. }
  4697. }
  4698. function copy_text(t) {
  4699. ta = document.createElement('textarea'); document.body.appendChild(ta); ta.value = t; ta.select();
  4700. document.execCommand("copy"); document.body.removeChild(ta);
  4701. }
  4702. if(trans = document.getElementById('translate_button')){
  4703. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4704. }
  4705. function ClickPost(p,e,pushstate){if(e)e.preventDefault();
  4706. id=p.dataset.postId; if(!id)return; list=p.parentNode;active=list.getElementsByClassName('active_post');
  4707. if(active&&active[0]&&active[0]!=p){
  4708. if(pushstate){window.history.pushState('?post='+id,null,'?post='+id);}
  4709. active[0].classList.remove('active_post'); p.classList.add('active_post');
  4710. }
  4711. if(!active[0]){ window.location.href="?post="+id; }
  4712. }function InitLabel(){
  4713. lb=document.querySelector('#mtitle'); lb.removeAttribute('for'); lb.onclick=function()
  4714. {c=document.querySelector('#titlectrl');if(c.checked)c.checked=false;else c.checked=true;}
  4715. lb=document.querySelectorAll('.bkg_section label');if(!lb||!lb[0])return;
  4716. for(i=0;i<lb.length;i++){ lb[i].removeAttribute('for');lb[i].onclick=function()
  4717. {c=this.parentNode.querySelector('.lpctrl');if(!c)return;if(c.checked)c.checked=false;else c.checked=true;} }
  4718. }InitLabel();
  4719. <?php if($this->LoggedIn){ ?>
  4720. var Scenter = document.querySelector('#div_center');
  4721. var Sposts = Scenter?Scenter.querySelectorAll('.post'):null;
  4722. <?php if(isset($this->MastodonToken)){ ?>
  4723. function MarkPostDoneMastodon(id,mastodon_url){
  4724. for(var i=0;i<Sposts.length;i++){
  4725. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  4726. }
  4727. <?php } ?>
  4728. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  4729. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  4730. var Smerge_post = Scenter.querySelector('#merge_post');
  4731. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  4732. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  4733. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  4734. var Smerge_select = Scenter.querySelector('#merge_select');
  4735. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  4736. var Smerge_thread = Scenter.querySelector('#merge_thread');
  4737. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  4738. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  4739. var select_mode = false; var merge_mode = false; var selected_posts = null;
  4740. function TogglePostSelectMode(force_on=false,force_off=false){
  4741. Scenter.classList.add('post_selecting');
  4742. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  4743. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  4744. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  4745. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  4746. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  4747. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4748. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  4749. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  4750. Smerge_post_count.innerText="0";
  4751. Smerge_post.href="#";
  4752. }
  4753. function TogglePostSelect(elem){
  4754. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  4755. else{ elem.classList.add('post_selected'); }
  4756. selected_posts = new Array();
  4757. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  4758. selected_posts.push(Sposts[i].dataset.postId); } }
  4759. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  4760. Smerge_post_count.innerText=selected_posts.length;
  4761. }
  4762. function ThreadMergeInput(elem){
  4763. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  4764. else{ Smerge_thread.href="#"; }
  4765. }
  4766. function ToggleThreadMerge(force_on=false,force_off=false){
  4767. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  4768. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  4769. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  4770. else{ merge_mode = 0;
  4771. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  4772. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4773. Smerge_thread.href="#";
  4774. Smerge_thread_target.value='';
  4775. }
  4776. <?php } ?>
  4777. function ShowSideUploader(){
  4778. ShowRightSide(true,null);
  4779. put = document.querySelector("#_uploader");
  4780. put.style.display='block';
  4781. RefreshSideGallery();
  4782. }
  4783. dmark = document.querySelector("#mark_details");
  4784. drename = document.querySelector("#rename_details");
  4785. dmastodon = document.querySelector("#mastodon_details");
  4786. drename_form = document.querySelector("#post_rename_form");
  4787. drename_input = document.querySelector("#post_rename_name");
  4788. var rp = document.querySelector('#post_reply_to');
  4789. var _reply_to = rp?rp.defaultValue:"";
  4790. function RestoreReply(){
  4791. if(rp){
  4792. rp.defaultValue = _reply_to;
  4793. }
  4794. document.querySelector('#post_reply_restore').style.display='none';
  4795. ht = document.querySelector('#post_hint_text');
  4796. if (_reply_to!=""){
  4797. ht.style.display='block';
  4798. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  4799. }else{
  4800. ht.style.display='none';
  4801. }
  4802. document.querySelector('#post_edit_target').value="";
  4803. ch = document.querySelector('#post_hint_modify');
  4804. ch.style.display='none';
  4805. }
  4806. function MakeRefer(id){
  4807. t = document.querySelector('#post_content')
  4808. t.focus();
  4809. v = t.value;
  4810. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  4811. la_auto_grow(t);
  4812. if(rp){
  4813. rp.defaultValue = "";
  4814. ht = document.querySelector('#post_hint_text');
  4815. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  4816. document.querySelector('#post_reply_restore').style.display='inline';
  4817. rs = document.querySelector('#post_reply_restore');
  4818. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  4819. document.getElementById('post_menu').style.display='none';
  4820. ch = document.querySelector('#post_hint_modify');
  4821. ch.style.display='none';
  4822. }
  4823. }
  4824. function CopyRefer(id){
  4825. copy_text(id.toString());
  4826. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  4827. }
  4828. function MakeEdit(id){
  4829. ed = document.getElementById('menu_edit');
  4830. ed.innerHTML="<?=$this->T('稍等')?>";
  4831. ed.href="#";
  4832. var xhr = new XMLHttpRequest();
  4833. xhr.onreadystatechange = function() {
  4834. if (this.readyState == 4 && this.status == 200) {
  4835. ed.innerHTML='——';
  4836. ch = document.querySelector('#post_hint_modify');
  4837. ch.style.display='block';
  4838. ht = document.querySelector('#post_hint_text');
  4839. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  4840. rs = document.querySelector('#post_reply_restore');
  4841. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  4842. t = document.querySelector('#post_content');
  4843. t.value=xhr.responseText.trim();
  4844. t.focus();
  4845. la_auto_grow(t);
  4846. document.querySelector('#post_edit_target').value=id;
  4847. document.getElementById('post_menu').style.display='none';
  4848. }
  4849. };
  4850. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4851. xhr.send();
  4852. }
  4853. function MarkDelete(id){
  4854. p = document.querySelector('[data-post-id="'+id+'"]');
  4855. op = p.dataset.markDelete?"false":"true";
  4856. window.location.href=
  4857. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4858. }
  4859. function SetMark(mark){
  4860. menu = document.getElementById('post_menu');
  4861. window.location.href=
  4862. "index.php?<?=$this->GetRedirect()?>&target="+
  4863. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4864. }
  4865. function ToggleMarkDetails(){
  4866. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  4867. drename.style.display=dmastodon.style.display='none';
  4868. }
  4869. function ToggleRenameDetails(){
  4870. drename.style.display=(drename.style.display=='block')?'none':'block';
  4871. dmark.style.display=dmastodon.style.display='none';
  4872. }
  4873. function ToggleMastodonDetails(){
  4874. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  4875. dmark.style.display=drename.style.display='none';
  4876. }
  4877. <?php } if(isset($_GET['post'])){ ?> ScrollToPost("<?=$_GET['post']?>"); <?php } ?>
  4878. function ShowPostMenu(post){
  4879. menu = document.getElementById('post_menu');
  4880. menu.style.display='block';
  4881. menu.parentNode.removeChild(menu);
  4882. post.appendChild(menu);
  4883. menu.style.display='block';
  4884. id = post.dataset.postId
  4885. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4886. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4887. window.onClick="HidePopMenu()";
  4888. menu.onClick=(function(event){
  4889. event.stopPropagation();
  4890. });
  4891. hs = menu.querySelector('#menu_history');
  4892. hs.href='?post='+id+'&history=1';
  4893. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4894. <?php if($this->PageType!='search'){?>
  4895. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4896. ed = menu.querySelector('#menu_edit');ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4897. <?php } ?>
  4898. ref = menu.querySelector('#menu_refer_copy')
  4899. ref.innerHTML='<?=$this->T("复制编号")?>';
  4900. ref.href='javascript:CopyRefer(id)';
  4901. d = menu.querySelector('#menu_delete');
  4902. d.href='javascript:MarkDelete(\"'+id+'\")';
  4903. p = document.querySelector('[data-post-id="'+id+'"]');
  4904. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4905. menu.querySelector('#mark_details').dataset.id=id;
  4906. drename_input.value=id;
  4907. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4908. <?php if(isset($this->MastodonToken)){ ?>
  4909. dmastodon_form = document.querySelector("#post_mastodon_form");
  4910. dmastodon_form.action='?mastodon_post='+id;
  4911. function MastodonSend(id){
  4912. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  4913. var xhr = new XMLHttpRequest();
  4914. function wrapidxhr(_id) { return function() {
  4915. if (this.readyState == 4 && this.status == 200) {
  4916. var response = xhr.responseText;
  4917. let content="";
  4918. if(res = response.match(/SUCCESS (\S+)/u)){
  4919. content="<?=$this->T('成功发送到长毛象')?>";
  4920. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  4921. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  4922. MarkPostDoneMastodon(_id, res[1]);
  4923. } }
  4924. };
  4925. xhr.onreadystatechange = wrapidxhr(id);
  4926. xhr.open("GET", "index.php?mastodon_send_post="+id, true); xhr.send();
  4927. }
  4928. menu_mastodon = menu.querySelector("#menu_mastodon");
  4929. mastodon_send = menu.querySelector("#menu_mastodon_send");
  4930. mastodon_view = menu.querySelector("#menu_mastodon_view");
  4931. mastodon_url = menu.querySelector("#post_mastodon_url");
  4932. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  4933. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  4934. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  4935. mastodon_url.value="";}
  4936. mastodon_send.onclick=function(){
  4937. this.onclick=function(){};
  4938. MastodonSend(id); };
  4939. <?php } } ?>
  4940. title = document.title;
  4941. copy = document.getElementById('share_copy');
  4942. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4943. copy.addEventListener("click", function(){
  4944. url = window.location
  4945. path = location.pathname
  4946. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4947. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4948. });
  4949. }
  4950. function HidePopMenu(){
  4951. var menus = document.querySelectorAll('.pop_menu');
  4952. [].forEach.call(menus, function(m){m.style.display='none';});
  4953. }
  4954. var posts = document.querySelectorAll('.center .post'); if(!posts || !posts[0]) posts = document.querySelectorAll('.center_slides .post');
  4955. [].forEach.call(posts, function(p){
  4956. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4957. ShowPostMenu(this.parentNode);ClickPost(this.parentNode,null,true)
  4958. });
  4959. p.addEventListener("dblclick", function(){ ClickPost(this,null,true); lp=this.querySelector('.lpctrl'); if(lp){ if(lp.checked)lp.checked=false;else lp.checked=true; }});
  4960. });
  4961. var post_clickables = document.querySelectorAll('.center .post a');
  4962. [].forEach.call(post_clickables, function(p){
  4963. p.addEventListener("click", function(event){
  4964. event.stopPropagation();
  4965. });
  4966. });
  4967. function FindImage(imgsrc){
  4968. for(var i=0;i<document.images_filtered.length;i++){
  4969. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4970. }
  4971. return null
  4972. }
  4973. var dottime1;
  4974. var dottime2;
  4975. function ToDataURL(url) {
  4976. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4977. clearTimeout(dottime1);clearTimeout(dottime2);
  4978. ps = document.querySelector('#download_processing');
  4979. ps.innerHTML='↓';ps.style.opacity='';
  4980. return URL.createObjectURL(blob);});
  4981. }
  4982. async function DownloadAsImage(url,name) {
  4983. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4984. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4985. }
  4986. function basename(url){return url.split(/[\\/]/).pop();}
  4987. pushed=0;
  4988. function ShowBigImage(imgsrc,do_push){
  4989. ShowWaitingBar();
  4990. share = document.querySelector('#big_image_share');
  4991. img = document.querySelector('#big_image');
  4992. vid = document.querySelector('#big_video');
  4993. vidsrc = document.querySelector('#big_video_src');
  4994. down = document.querySelector('#image_download');
  4995. img.src = ""; vidsrc.src="";
  4996. if(imgsrc.match(/\.mp4$/)){
  4997. vidsrc.src = src = "images/"+imgsrc; img.style.display='none'; vid.load();vid.style.display='block';
  4998. }else{
  4999. img.src = src = "images/"+imgsrc; vid.style.display='none';img.style.display='block';
  5000. }
  5001. down.href="images/"+imgsrc;
  5002. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_<?=$this->GiveSafeEMail()?>_'+
  5003. basename(down.href);
  5004. img.alt = downname; down.download=downname;
  5005. var use_href = "images/"+imgsrc;
  5006. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  5007. ps = this.querySelector('#download_processing');ps.innerText='…';
  5008. var dotwait = function(ps){ var self = this;
  5009. dottime1 = setTimeout(function(ps){
  5010. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  5011. dotwait(this.querySelector('#download_processing'));
  5012. DownloadAsImage(use_href,downname);};
  5013. if(do_push){PushGalleryHistory(src)}
  5014. page_url = encodeURIComponent(window.location.href);
  5015. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  5016. inqb = document.querySelector('#image_inquiry');
  5017. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  5018. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  5019. (page_url)+encodeURIComponent('\n\n');
  5020. <?php } ?>
  5021. this_image = FindImage(imgsrc);
  5022. if(this_image&&this_image.dataset.prevsrc){
  5023. new_image = FindImage(this_image.dataset.prevsrc);
  5024. new_prev = new_image?new_image.dataset.prevsrc:null;
  5025. im = document.querySelector('#prev_image');
  5026. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  5027. else {im.style.opacity='0';im.removeAttribute("href");}
  5028. }
  5029. if(this_image&&this_image.dataset.nextsrc){
  5030. new_image = FindImage(this_image.dataset.nextsrc);
  5031. new_next = new_image?new_image.dataset.nextsrc:null;
  5032. im = document.querySelector('#next_image');
  5033. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  5034. else {im.style.opacity='0';im.removeAttribute("href");}
  5035. }
  5036. purchase = document.querySelector('#image_purchase');
  5037. purchase_btn = document.querySelector('#image_purchase_button');
  5038. <?php if($this->LoggedIn){ ?>
  5039. product_link = document.querySelector('#image_ops_product_link');
  5040. product_form = document.querySelector('#image_ops_form');
  5041. edit_form = document.querySelector('#image_edit_form');
  5042. edit_new_name = document.querySelector('#image_edit_new_name');
  5043. edit_parent = document.querySelector('#image_parent');
  5044. edit_align = document.querySelector('#image_align');
  5045. product_form.action = window.location.href;
  5046. edit_form.action = window.location.href;
  5047. edit_new_name.value = imgsrc.split('.')[0];
  5048. if(this_image){
  5049. if(this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  5050. if(this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  5051. if(this_image.dataset.align){ edit_align.value = this_image.dataset.align; }else{ edit_align.value = "middle"; }
  5052. }
  5053. <?php } ?>
  5054. if(this_image&&this_image.dataset.product){
  5055. purchase.style.display='';
  5056. href = this_image.dataset.product;
  5057. if(this_image.dataset.product.match('^[0-9]{14}$')){
  5058. href = '?post='+href;
  5059. }
  5060. purchase_btn.href = href;
  5061. }else{
  5062. purchase.style.display='none';
  5063. purchase_btn.removeAttribute("href");
  5064. }
  5065. DelayHideImgBtn(null);
  5066. title = encodeURIComponent(document.title);
  5067. copy = document.getElementById('big_share_copy');
  5068. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  5069. copy.addEventListener("click", function(){
  5070. copy_text(window.location.href);
  5071. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  5072. });
  5073. o = document.querySelector('#big_image_overlay');
  5074. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  5075. here = document.querySelector('#here_buttons');here.innerHTML='';
  5076. o.style.display="block";
  5077. ShowBackdrop(0.8);
  5078. var xhr = new XMLHttpRequest();
  5079. xhr.onreadystatechange = function() {
  5080. if (this.readyState == 4 && this.status == 200) {
  5081. info = document.querySelector('#big_image_info');
  5082. var response = xhr.responseText;
  5083. let content=""
  5084. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  5085. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  5086. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  5087. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  5088. content+="<div class='clean_a'>"+res[1]+"</div>"; }
  5089. info.innerHTML=content;
  5090. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  5091. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  5092. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  5093. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  5094. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  5095. }
  5096. }
  5097. };
  5098. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  5099. xhr.send();
  5100. }
  5101. function HideBigImage(do_push){
  5102. o = document.querySelector('#big_image_overlay');
  5103. img = document.querySelector('#big_image');
  5104. vid = document.querySelector('#big_video');
  5105. vidsrc = document.querySelector('#big_video_src');
  5106. img.src = ""; vidsrc.src="";
  5107. if(o.style.display!='none'){
  5108. o.style.display="none";
  5109. HideBackdrop();
  5110. if(do_push){PushGalleryHistory("");}
  5111. HideWaitingBar();
  5112. }
  5113. }
  5114. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  5115. var inq=document.querySelector('#inquiry_buttons');
  5116. var overlay=document.querySelector('#big_image_overlay');
  5117. var hide_timeout;
  5118. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  5119. function DelayHideImgBtn(e){
  5120. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  5121. inq.classList.remove('img_btn_hidden');
  5122. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  5123. clearTimeout(hide_timeout);
  5124. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  5125. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  5126. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  5127. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  5128. }
  5129. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  5130. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  5131. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  5132. overlay.addEventListener('mousemove',DelayHideImgBtn);
  5133. function UpdateImageClickables(){
  5134. var images = document.querySelectorAll('img, video');
  5135. var images_filtered=new Array(); var imgadded = new Array();
  5136. var images_remaining=new Array();
  5137. [].forEach.call(images, function(img){
  5138. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  5139. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  5140. images_filtered.push(img);imgadded.push(imgsrc);
  5141. });
  5142. for(var i=0; i<images_filtered.length; i++){
  5143. previmg = nextimg = null; img = images_filtered[i];
  5144. if(i>0) previmg=images_filtered[i-1];
  5145. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  5146. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  5147. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  5148. function wrap(imgsrc){return function(event){ShowBigImage(imgsrc, 1);}}
  5149. var clone = img.cloneNode(true); img.replaceWith(clone);
  5150. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  5151. }
  5152. for(var i=0; i<images_remaining.length; i++){
  5153. img = images_remaining[i];
  5154. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  5155. var clone = img.cloneNode(true); img.replaceWith(clone);
  5156. clone.addEventListener("click", wrap(img.dataset.imgsrc));
  5157. }
  5158. document.images_filtered = images_filtered;
  5159. }
  5160. UpdateImageClickables();
  5161. function PopGalleryHistory(){
  5162. if(pushed){
  5163. pushed = 0;
  5164. try{
  5165. history.back();
  5166. }catch{
  5167. console.log("can't do it.");
  5168. }
  5169. }
  5170. }
  5171. function PushGalleryHistory(src){
  5172. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  5173. title = "照片"
  5174. extra = "?";
  5175. sp = new URLSearchParams(window.location.search)
  5176. if(sp.has('post')){extra+="post="+sp.get('post')}
  5177. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  5178. try{
  5179. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  5180. }catch{
  5181. console.log("can't do it.");
  5182. }
  5183. pushed = 1;
  5184. }
  5185. document.addEventListener('keydown', function(e){
  5186. large = document.getElementById('big_image_overlay')
  5187. if (large.style.display!='block') return;
  5188. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  5189. HideBigImage(1);
  5190. }
  5191. }, true);
  5192. window.addEventListener('popstate', (event) => {
  5193. href=window.location.href;
  5194. let sp = new URLSearchParams(href.substring(href.indexOf('?')))
  5195. if(sp.has('pic')){
  5196. src = sp.get('pic')
  5197. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)) ShowBigImage(onlyimg[0], 0);
  5198. else{HideBigImage(0);}
  5199. }else{HideBigImage(0);}
  5200. if(sp.has('post')){
  5201. id=sp.get('post');post=document.querySelector('.post[data-post-id="'+id+'"]');
  5202. if(post){ClickPost(post,null,false);}
  5203. }
  5204. });
  5205. let searchParams = new URLSearchParams(window.location.search)
  5206. if(searchParams.has('pic')){
  5207. src = searchParams.get('pic')
  5208. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)){
  5209. ShowBigImage(onlyimg[0], 1);
  5210. }
  5211. }
  5212. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  5213. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  5214. </script>
  5215. </body>
  5216. <?php
  5217. }
  5218. function DoIdentifyExperimental(){
  5219. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  5220. $this->InExperimentalMode=True; $this->InHereMode=True;
  5221. if(!$this->AllowLanguageChoices){ $this->LanguageAppendix='en'; }
  5222. }
  5223. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  5224. $this->InHereMode=True;
  5225. }
  5226. }
  5227. function DoExperimentalTopLink($p){
  5228. if($this->InHereMode && $p){
  5229. if(isset($p['tid']) && $p['tid']['first']!=$p){
  5230. header('Location: ?post='.$p['tid']['first']['id']); exit();
  5231. }
  5232. }
  5233. }
  5234. function MakeExperimentalConfirm(){
  5235. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  5236. return false;
  5237. }
  5238. $caution_html =
  5239. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  5240. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  5241. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  5242. ?>
  5243. <div class='center_exp'><?php
  5244. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  5245. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  5246. ?></div>
  5247. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  5248. <?php return true;
  5249. }
  5250. }
  5251. $la = new LA;
  5252. $la->DoSiteRedirect();
  5253. $la->DoLogin();
  5254. $la->SwitchLanguageAndFont();
  5255. $err = $la->ProcessRequest($message, $redirect);
  5256. $la->WriteAsNecessary();
  5257. $la->DoIdentifyExperimental();
  5258. $la->SwitchWayBackMode();
  5259. if($err){
  5260. echo $message;
  5261. exit();
  5262. }
  5263. if(isset($redirect)){
  5264. header('Location: '.$redirect);
  5265. exit();
  5266. }
  5267. $la->DetectPageType();
  5268. $la->ReadImages(false);
  5269. $la->ReadPosts();
  5270. if(isset($la->WayBack)){
  5271. $la->ReadArchive();
  5272. }
  5273. $im = NULL;
  5274. if(preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  5275. if(!$la->CanShowImage($im)) { $im=&$la->NULL_IMAGE; }
  5276. }
  5277. $p = &$la->GetPost($la->CurrentPostID);
  5278. if(!isset($p)){
  5279. $p = &$la->GetMergedPost($la->CurrentPostID);
  5280. }
  5281. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  5282. else{ $la->DoExperimentalTopLink($p); }
  5283. if(isset($p)){ $la->ActualPostID = $p['id']; }
  5284. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5285. if($im){
  5286. $la->SetHereMainImage($im);
  5287. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  5288. }else if($p){
  5289. $la->RecordVisitedHere($p['id'],NULL);
  5290. }else {
  5291. $im = &$la->GiveImageInHere(false);
  5292. if($im){
  5293. $la->SetHereMainImage($im);
  5294. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  5295. }
  5296. }
  5297. }
  5298. $la->MakeHeader($p);
  5299. $la->MakeMainBegin();
  5300. if($la->PageType=='here' ||$la->PageType=='experimental'){
  5301. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  5302. if($im){
  5303. $la->MakeHereSection($im);
  5304. }else if($p){
  5305. $la->MakePostSectionExp($p);
  5306. $la->MakeLinkedPostsExp($p);
  5307. }else {
  5308. if($im){
  5309. $la->MakeHereSection($im);
  5310. }else{
  5311. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5312. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  5313. }
  5314. }
  5315. }
  5316. $la->MakeMainEnd();
  5317. $la->MakeExpFooter();
  5318. }else{
  5319. if($la->PageType=='extras'){
  5320. $la->MakeExtraOperations();
  5321. }else if($la->PageType=='settings'){
  5322. $la->MakeSettings();
  5323. }else if($la->PageType=='gallery'){
  5324. $la->MakeGalleryLeft();
  5325. $la->MakeGallerySection();
  5326. }else if($la->PageType=='post'){
  5327. if($p){
  5328. $made_interesting = false;
  5329. if($la->IsInterestingPost($p)){
  5330. $la->MakeInterestingSection($p['tid']);
  5331. }
  5332. else{
  5333. $la->MakeSidebar();
  5334. $la->MakePostSection($p);
  5335. }
  5336. }else{
  5337. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  5338. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  5339. }
  5340. }else if($la->PageType=='history'){
  5341. $la->ReadArchive();
  5342. $la->MakePostHistory($p, $_GET['version']??NULL);
  5343. }else if($la->PageType=='search'){
  5344. $la->MakeSidebar();
  5345. $la->MakeRecentPosts($_GET['search']);
  5346. }else if($la->PageType=='category'){
  5347. $la->MakeSidebar();
  5348. $la->MakeRecentPosts(NULL,$_GET['category']);
  5349. }else if($la->PageType=='comments'){
  5350. $la->MakeCommentPosts();
  5351. }else if($la->PageType=='statistics'){
  5352. $la->MakeStatistics();
  5353. }else{
  5354. $la->MakeSidebar();
  5355. $la->MakeRecentPosts();
  5356. }
  5357. $la->MakeMainEnd();
  5358. $la->MakeFooter($p);
  5359. }
  5360. ?>