*/}}

index.php 288 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162
  1. <?php
  2. include 'Parsedown.php';
  3. include 'ParsedownExtra.php';
  4. ini_set('display_errors', '1');
  5. ini_set('display_startup_errors', '1');
  6. error_reporting(E_ALL);
  7. class LA{
  8. protected $PDE;
  9. protected $style;
  10. /* config */
  11. protected $Title;
  12. protected $ShortTitle;
  13. protected $Admin;
  14. protected $Password;
  15. protected $DisplayName;
  16. protected $EMail;
  17. protected $SpecialNavigation;
  18. protected $SpecialFooter;
  19. protected $SpecialFooter2;
  20. protected $SpecialPinned;
  21. protected $DefaultGallery;
  22. protected $SelfAuthPath;
  23. protected $HereHost;
  24. protected $HereTitle;
  25. protected $HereShortTitle;
  26. protected $HereAlbum;
  27. protected $HereNavigation;
  28. protected $HereFooter;
  29. protected $ExpHost;
  30. protected $ExpAlbum;
  31. protected $ExpTitle;
  32. protected $ExpShortTitle;
  33. protected $ExpCaution;
  34. protected $ExpNavigation;
  35. protected $ExpFooter;
  36. protected $CommentEnabled;
  37. protected $MastodonToken;
  38. protected $MastodonURL;
  39. protected $MastodonPreferredLang;
  40. protected $HostURL;
  41. protected $Redirect;
  42. protected $Translations;
  43. protected $CustomTranslationContent;
  44. protected $CurrentOffset;
  45. protected $PostsPerPage;
  46. protected $HotPostCount;
  47. protected $LoggedIn;
  48. protected $LoginTokens;
  49. protected $InHereMode;
  50. protected $InExperimentalMode;
  51. protected $LanguageAppendix;
  52. protected $UseRemoteFont;
  53. protected $Posts;
  54. protected $Threads; // [ keys: first last displayed count]
  55. protected $WaybackThreads;
  56. public $Images;
  57. protected $Galleries;
  58. protected $Anchors;
  59. protected $ArchiveHandles;
  60. protected $Archive;
  61. public $WayBack;
  62. protected $YearBegin;
  63. protected $YearEnd;
  64. protected $Markers;
  65. protected $ExtraScripts;
  66. protected $APubID;
  67. protected $APubActor;
  68. protected $APubPublicKey;
  69. protected $APubPrivateKey;
  70. protected $TIME_STRING;
  71. public $NULL_POST;
  72. public $NULL_IMAGE;
  73. public $NULL_IMAGE_DUMMY;
  74. public $NULL_Gallery;
  75. protected $DoneReadPosts;
  76. protected $DoneReadImages;
  77. protected $DoneReadArchive;
  78. protected $NeedWritePosts;
  79. protected $NeedWriteImages;
  80. protected $NeedWriteArchive;
  81. protected $HereDisplayTitle;
  82. protected $VisitedHere;
  83. protected $HereNumber;
  84. protected $HereMainImage;
  85. public $PageType;
  86. public $CurrentPostID;
  87. public $HereID;
  88. public $ActualPostID;
  89. public $TagID;
  90. function ReadableTime($id){
  91. $dt = DateTime::createFromFormat('YmdHis', $id);
  92. return $dt->format('Y/m/d H:i:s');
  93. }
  94. function StandardTime($id){
  95. $dt = DateTime::createFromFormat('YmdHis', $id);
  96. return $dt->format('Y-m-d\TH:i:s');
  97. }
  98. function FullURL(){
  99. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  100. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  101. $_SERVER['REQUEST_URI'];
  102. }
  103. function T($str){
  104. if(!$this->LanguageAppendix) return $str;
  105. foreach($this->Translations as $entry){
  106. if($entry['zh']==$str)
  107. return $entry[$this->LanguageAppendix];
  108. }
  109. return $str;
  110. }
  111. function SwitchLanguageAndFont(){
  112. $this->LanguageAppendix = 'zh';
  113. if(isset($_COOKIE['la_language'])){
  114. $this->LanguageAppendix = $_COOKIE['la_language'];
  115. }else{
  116. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  117. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  118. $lang = substr($lang,0,5);
  119. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  120. else $this->LanguageAppendix = 'en';
  121. }
  122. }
  123. if(isset($_COOKIE['la_font'])){
  124. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  125. }
  126. }
  127. function SwitchWayBackMode(){
  128. if(isset($_COOKIE['la_wayback'])){
  129. $this->WayBack = $_COOKIE['la_wayback'];
  130. }else $this->WayBack = NULL;
  131. }
  132. function DisplayRedirectConfig(){
  133. $s = "";
  134. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  135. if($r['for']=='P'){
  136. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  137. }else if($r['for']=='S'){
  138. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  139. }
  140. }
  141. return $s;
  142. }
  143. function DoSiteRedirect(){
  144. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  145. if($r['for']=='S'){
  146. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  147. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  148. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  149. }else{
  150. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. function WriteHTACCESS(){
  157. $conf = fopen('.htaccess','w');
  158. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  159. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  160. if($r['for']=='P'){
  161. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  162. }// do site redirect in php.
  163. }
  164. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  165. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  166. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  167. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  168. fwrite($conf, 'RewriteCond %{HTTP_HOST} !^www\.'.PHP_EOL.
  169. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  170. 'RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  171. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  172. fflush($conf);fclose($conf);
  173. }
  174. function BuildRedirectConfig($conf){
  175. $this->Redirect=[];
  176. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  177. foreach($ma as $m){
  178. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  179. $this->Redirect[]=$redirect;
  180. }
  181. }
  182. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  183. foreach($ma as $m){
  184. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  185. $this->Redirect[]=$redirect;
  186. }
  187. }
  188. }
  189. function WriteTokens(){
  190. $tf = fopen('la_tokens.php','w');
  191. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  192. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  193. foreach($this->LoginTokens as $t){
  194. fwrite($tf,'- '.$t.PHP_EOL);
  195. }
  196. }
  197. fflush($tf);fclose($tf);
  198. }
  199. function WriteConfig(){
  200. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  201. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  202. if(!isset($this->Admin)) $this->Admin = 'admin';
  203. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  204. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  205. $conf = fopen('la_config.php','w');
  206. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  207. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  208. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  209. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  210. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  211. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  212. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  213. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  214. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  215. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  216. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  217. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  218. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  219. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  220. fwrite($conf,'- HereHost = '.$this->HereHost.PHP_EOL);
  221. fwrite($conf,'- HereTitle = '.$this->HereTitle.PHP_EOL);
  222. fwrite($conf,'- HereShortTitle = '.$this->HereShortTitle.PHP_EOL);
  223. fwrite($conf,'- HereAlbum = '.$this->HereAlbum.PHP_EOL);
  224. fwrite($conf,'- HereNavigation = '.$this->HereNavigation.PHP_EOL);
  225. fwrite($conf,'- HereFooter = '.$this->HereFooter.PHP_EOL);
  226. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  227. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  228. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  229. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  230. fwrite($conf,'- ExpAlbum = '.$this->ExpAlbum.PHP_EOL);
  231. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  232. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  233. fwrite($conf,'- MastodonToken = '.$this->MastodonToken.PHP_EOL);
  234. fwrite($conf,'- MastodonURL = '.$this->MastodonURL.PHP_EOL);
  235. fwrite($conf,'- MastodonPreferredLang = '.$this->MastodonPreferredLang.PHP_EOL);
  236. fwrite($conf,'- HostURL = '.$this->HostURL.PHP_EOL);
  237. fwrite($conf,'- APubID = '.$this->APubID.PHP_EOL);
  238. fflush($conf);fclose($conf);
  239. $conf = fopen('la_redirect.md','w');
  240. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  241. $this->WriteHTACCESS();
  242. $this->WriteTokens();
  243. }
  244. function Install(){
  245. if(!file_exists('la_config.php')){
  246. $this->WriteConfig();
  247. }
  248. if(!is_dir('posts')) mkdir('posts');
  249. if(!is_dir('images')) mkdir('images');
  250. if(!is_dir('images/thumb')) mkdir('images/thumb');
  251. if(!is_dir('styles')) mkdir('styles');
  252. if(!is_dir('archive')) mkdir('archive');
  253. $this->WriteStyles();
  254. $this->WriteHTACCESS();
  255. }
  256. function ReadFromExistingConfig(){
  257. $f=null;
  258. if(file_exists('la_config.php')) $f='la_config.php';
  259. else if(file_exists('la_config.md')) $f='la_config.md';
  260. if(!isset($f)) return;
  261. $c = file_get_contents($f);
  262. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  263. $str = $m[1];
  264. $this->$str = $m[2];
  265. }
  266. $this->CommentEnabled = $this->CommentEnabled=="True";
  267. }
  268. function ReadConfig(){
  269. $this->ReadFromExistingConfig();
  270. if(file_exists('la_redirect.md')){
  271. $c = file_get_contents('la_redirect.md');
  272. $this->BuildRedirectConfig($c);
  273. }
  274. if(!file_exists('la_config.php')){
  275. $this->Install();
  276. }
  277. $this->Translations=[];
  278. if(file_exists("translations.md")){
  279. $c = file_get_contents('translations.md');
  280. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  281. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  282. $this->Translations[] = $entry;
  283. }
  284. }
  285. if(file_exists("custom_translations.md")){
  286. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  287. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  288. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  289. $this->Translations[] = $entry;
  290. }
  291. }
  292. $this->LoginTokens=[];
  293. if(file_exists('la_tokens.php')){
  294. $c = file_get_contents('la_tokens.php');
  295. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  296. $this->LoginTokens[] = $m[1];
  297. }
  298. }
  299. }
  300. function MastodonPostStatus($status){ return $this->MastodonCall('/api/v1/statuses', 'POST', $status); }
  301. function MastodonPostMedia($media){ return $this->MastodonCall('/api/v1/media', 'POST', $media); }
  302. function MastodonCall($endpoint, $method, $data){
  303. $headers = [
  304. 'Authorization: Bearer '.$this->MastodonToken,
  305. 'Content-Type: multipart/form-data',
  306. ];
  307. $ch = curl_init();
  308. curl_setopt($ch, CURLOPT_URL, $this->MastodonURL.$endpoint);
  309. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  310. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  311. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  312. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  313. $reply = curl_exec($ch);
  314. if (!$reply) {
  315. return json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch_status), 'curl_error' => curl_error(ch_status)]);
  316. }
  317. curl_close($ch);
  318. return json_decode($reply, true);
  319. }
  320. function MastodonSendPost(&$post, &$errmsg=NULL){
  321. if(isset($post['mark_value']) && $post['mark_value']==7){ return NULL; }
  322. $this->LanguageAppendix = 'zh';
  323. if(in_array($this->MastodonPreferredLang,['en','zh'])){ $this->LanguageAppendix = $this->MastodonPreferredLang; }
  324. $this->ConvertPost($post);
  325. $media_ids = NULL;
  326. $mastodon_post_url = NULL;
  327. $imcount = 0;
  328. if(isset($post['original_images']) && isset($post['original_images'][0])) foreach($post['original_images'] as $im){
  329. $curl_file = curl_file_create($im, mime_content_type($im), basename($im));
  330. $body = ['file' => $curl_file,]; $response = $this->MastodonPostMedia($body);
  331. if(isset($response['id'])){ if(!isset($media_ids)){$media_ids=[];} $media_ids[]=$response['id']; }
  332. else{ if(isset($response['error'])) $errmsg.=$response['error']."<br /><br />"; }
  333. $imcount++; if($imcount>=4){ break; }
  334. }
  335. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$post['html']));
  336. if(isset($this->HostURL) && $this->HostURL!=""){
  337. $text.=("\n\n".$this->T('来自').' '.$this->HostURL.'?post='.$post['id']);
  338. }
  339. $vis = (isset($post['mark_value']) && $post['mark_value']==6)?"private":"public";
  340. $status_data = [ 'status' => $text, 'visibility' => $vis, 'language' => $this->LanguageAppendix, ];
  341. if(isset($post['prev']) && ($pp=&$this->GetPost($post['prev']))!=$this->NULL_POST){
  342. if(isset($pp['mastodon_url'])){ $status_data['in_reply_to_id'] = basename($pp['mastodon_url']);
  343. }
  344. }
  345. if(isset($media_ids[0])){ $status_data['media_ids']=$media_ids; }
  346. $status_data = preg_replace('/(media_ids%5B)[0-9]+(%5D)/','$1$2', http_build_query($status_data));
  347. $status_response = $this->MastodonPostStatus($status_data);
  348. if(isset($status_response['url']) && $status_response['url']){
  349. $mastodon_post_url = $status_response['url'];
  350. $post['mastodon_url'] = $mastodon_post_url;
  351. $this->NeedWritePosts = 1;
  352. }
  353. if(isset($status_response['error'])) { $errmsg .= $status_response['error']; }
  354. return $mastodon_post_url;
  355. }
  356. function __construct() {
  357. $this->ReadConfig();
  358. $this->PDE = new ParsedownExtra();
  359. $this->PDE->SetInterlinkPath('/');
  360. $this->Posts = [];
  361. $this->Threads = [];
  362. $this->VisitedHere = [];
  363. $this->NULL_IMAGE_DUMMY = [];
  364. $this->NULL_IMAGE_DUMMY['name']=$this->NULL_IMAGE_DUMMY['file']=$this->NULL_IMAGE_DUMMY['thumb']="";
  365. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  366. $this->PostsPerPage = 40;
  367. $this->CommentsPerPage = 100;
  368. $this->HotPostCount = 15;
  369. $this->TIME_STRING = date('YmdHis');
  370. $this->WayBack = NULL;
  371. $this->YearBegin = $this->YearEnd = 2000;
  372. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  373. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  374. $this->UsePosts = &$this->Posts;
  375. }
  376. function DoLogout(){
  377. $this->LoggedIn = false;
  378. unset($_SESSION['user_id']);
  379. $this->RecordToken(true);
  380. }
  381. function RecordToken($unset_current=false){
  382. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  383. $t = $_COOKIE['la_token'];
  384. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  385. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  386. $this->WriteTokens();
  387. return null;
  388. }else{
  389. $t = uniqid('la_',true);
  390. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  391. $this->LoginTokens[] = $t;
  392. $this->WriteTokens();
  393. return $t;
  394. }
  395. }
  396. function LoginThroughToken(){
  397. if(!isset($_COOKIE['la_token'])) return false;
  398. $t = $_COOKIE['la_token'];
  399. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  400. $_SESSION['user_id']=$this->Admin;
  401. $this->LoggedIn = true;
  402. setcookie('la_token',$t,time()+3600*24*7);
  403. return true;
  404. }
  405. return false;
  406. }
  407. function DoLogin(){
  408. session_start();
  409. $redirect=false;
  410. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  411. else if(!isset($_SESSION['user_id'])){
  412. if(isset($_POST['login_button'])){
  413. $id = trim($_POST['login_id']);
  414. $pwd = trim($_POST['login_password']);
  415. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  416. $_SESSION['user_id']=$id;
  417. $this->RecordToken(false);
  418. }
  419. $redirect = true;
  420. }else if($this->LoginThroughToken()){
  421. // nothing;
  422. }
  423. }else{
  424. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  425. else{ $this->DoLogout();}
  426. }
  427. if($redirect){
  428. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  429. .(isset($_GET['settings'])?"?settings=true":""));
  430. }
  431. }
  432. function SetHereMainImage($im_this){
  433. if(isset($im_this) && isset($im_this['parent'])){ $this->HereMainImage = &$this->FindImage($im_this['parent'],true);}
  434. }
  435. function RecordVisitedHere($image_or_post_name, $image_title){
  436. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  437. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  438. if(!(isset($_SESSION[$visited_here][0]) && in_array($image_or_post_name,$_SESSION[$visited_here]))){
  439. $_SESSION[$visited_here][] = $image_or_post_name;
  440. }
  441. if(isset($image_title)){ $this->HereDisplayTitle=$image_title; }
  442. $this->HereNumber = array_search($image_or_post_name,$_SESSION[$visited_here])+1;
  443. $_SESSION['here_number'] = $this->HereNumber;
  444. $this->VisitedHere = $_SESSION[$visited_here];
  445. }
  446. function HereLinkFromNumber($number){
  447. $number -= 1; if($number<0){ $number=0; }
  448. if($number>=sizeof($this->VisitedHere)){ $number = sizeof($this->VisitedHere)-1; }
  449. if(preg_match('/(jpg|jpeg|png|gif)/u',$this->VisitedHere[$number])){ return "?here=images/".$this->VisitedHere[$number]; }
  450. else{ return "?post=".$this->VisitedHere[$number]; }
  451. }
  452. function WriteStyles(){
  453. $this->style="
  454. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  455. body{background-color:%white%;color:%black%;}
  456. sup,sub{line-height:0;}
  457. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  458. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  459. b,strong,th{font-weight:bold;}
  460. select{font-size:inherit;}
  461. .page,.page_gallery{padding:1em;padding-top:0;padding-bottom:0;}
  462. .hidden_on_desktop,.hidden_on_wide{display:none;}
  463. .hidden_on_desktop_force{display:none !important;}
  464. ::file-selector-button{background:none;border:none;}
  465. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  466. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  467. .button:disabled{background-color:%gray%;pointer-events:none;}
  468. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;max-height:100vh;z-index:30;}
  469. 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;}
  470. header>div{overflow:auto;white-space:nowrap;}
  471. .header_nav{display:inline;}
  472. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  473. header a:hover,.button:hover{color:%gray% !important;}
  474. .exp_h_f{padding-top:0.3em !important;padding-bottom:0.3em !important;line-height:1.5em !important;height:2.1em !important;}
  475. .toc_button{position:absolute;top:0.5em;right:0;text-shadow: 0px 0px 10px %white%;background-color:%white%88;}
  476. .footer{background-color:%white%;z-index:10;position:relative;}
  477. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  478. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  479. .gray,.gray a{color:%gray%;}
  480. hr{border:1px solid %gray%;}
  481. header ul,.small_footer ul,.small_footer span,header li,.small_footer li{display:inline-block;}
  482. header li::before,.small_footer li::before{content:' - '}
  483. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  484. .main{position:relative;word-spacing:-1em;}
  485. .main *{word-spacing:initial;}
  486. pre{overflow:auto;max-width:100%;display:block;font-size:0.75em;}
  487. ul{display:block;}
  488. li{display:block;}
  489. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  490. table input{border:none!important;}
  491. table img{max-width:10rem !important;}
  492. td{padding-left:0.1em;padding-right:0.1em;}
  493. td:first-child{padding-left:0;}
  494. td:last-child{padding-right:0;}
  495. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  496. thead{box-shadow:inset 0 -1px 0 0px %black%;position:sticky;top:2rem;background-color:%white%;z-index:5;}
  497. .post table{font-size:0.85em;}
  498. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  499. .interesting_tbody td{display:contents;}
  500. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  501. .interesting_tbody td>*{display:table-cell;}
  502. .interesting_tbody td>.wscroll{display:none !important;}
  503. .interesting_tbody .post_access{padding-top:0;}
  504. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  505. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  506. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  507. .interesting_tbody td>.imd>a{display:flex;}
  508. .interesting_tbody img{object-fit:cover;width:100%;}
  509. .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);}
  510. .interesting_tbody .p_thumb{height:1em;}
  511. .interesting_tbody .p_thumb img{max-height:10rem !important;max-width:20rem !important;}
  512. tr:hover .post_menu_button{opacity:1;}
  513. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  514. .align_right{text-align:right;}
  515. .left{display:inline-block;vertical-align:top;width:25%;max-height:calc(100vh - 2.6em);top:2em;
  516. position:sticky;overflow:auto;padding-right:0.2em;padding-bottom:4rem;}
  517. .center{display:inline-block;vertical-align:top;width:50%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  518. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  519. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  520. .center_wide .p_thumb{height:10rem;}
  521. .sticky_title{position:sticky;top:calc(1.6rem + 2px);z-index:1;box-shadow:6em 3.5em 0.75em -3em inset %white%;pointer-events:none;}
  522. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  523. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  524. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  525. .right{display:inline-block;vertical-align:top;width:25%;position:sticky;top:2em;
  526. padding-left:0.5em;max-height:calc(100vh - 2.6em);overflow:auto;padding-bottom:4rem;}
  527. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  528. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  529. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  530. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  531. .post{position:relative;scroll-margin:3.5em;border-radius:0.3em;}
  532. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;border-radius:0;}
  533. .post_width li,.post_width_big li,.footer_additional li,.footer_additional li,.post_dummy li
  534. {display:list-item;margin-left:1em;list-style:disc;}
  535. .post_width li li,.post_width_big li li,.footer_additional li li,.footer_additional li li,.post_dummy li li{list-style:circle;}
  536. .post_width > *,.post_width_big > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  537. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  538. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  539. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  540. .gallery_left .selected{list-style:'→';}
  541. .focused_post{font-size:1.1em;margin-top:0.1em;margin-bottom:0.1em;padding:0.5rem !important;border:2px dashed #ac7843;}
  542. .post_width{position:relative;left:1.4rem;width:calc(100% - 1.7rem);padding-left:0.2em;overflow:visible;}
  543. .post_width_big{position:relative;left:0;width:100%;overflow:visible;}
  544. .post_menu_button{position:absolute;display:none;right:0rem;width:1.5rem;
  545. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;}
  546. .pointer{cursor:pointer;}
  547. .post:hover .post_menu_button{display:block;}
  548. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%lighterbkg%;
  549. padding:0.3em;right:0.3rem;text-align:right;border-radius:0.3em;font-size:1rem;
  550. box-shadow:0px 0px 10px rgb(0, 0, 0);}
  551. .pop_menu li{list-style:none;margin-left:0;}
  552. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  553. .toc{left:60%;width:40%;top:0;position:absolute;}
  554. .post_access{width:1.4rem;top:0;position:absolute;height:100%;text-align:center;font-weight:bold;border-right:2px solid transparent;user-select:none;}
  555. .post_access:hover{background-color:%lightopbkg%;border-top-left-radius:0.3em;border-bottom-left-radius:0.3em;
  556. border-right:2px solid %black% !important;}
  557. .paa{width:1.4rem;min-width:1.4rem;}
  558. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;}
  559. .post_box{border:1px solid %gray%;border-radius:0.3em;padding:0.3em;}
  560. .post_box:hover,.post_menu_button:hover{background-color:%lightopbkg%}
  561. #big_image_info .post_box:hover{background-color:%graybkg%;}
  562. .post_preview{font-size:0.9rem;overflow:hidden;margin-bottom:0.2em;}
  563. .post .post_ref{margin:0;padding-left:1.7rem;}
  564. .post_ref_main{display:inline-block;vertical-align:top;}
  565. .post_preview .post_ref_main{max-height:6rem;overflow:hidden;}
  566. .post_ref_images{overflow:hidden;}
  567. .page_selector{padding-top:2rem;text-align:center;}
  568. .smaller{font-size:0.85em;}
  569. .bigger{font-size:1.3em;}
  570. .block{display:block;}
  571. .opt_compact{margin-left:1.6rem;}
  572. .opt_compact .post_width {margin-left:0.3em;width: calc(100% - 1.8rem);}
  573. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  574. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  575. .spacer{height:0.5em;}
  576. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  577. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  578. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  579. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  580. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  581. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  582. .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;}
  583. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  584. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  585. .toc_entry_1{font-size:1.1em;}
  586. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  587. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  588. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  589. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  590. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  591. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  592. .deleted_post{color:%gray%;text-decoration:line-through;}
  593. #file_list{margin-top:0.5em;}
  594. .file_thumb img{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  595. #file_list li{margin-bottom:0.3em;}
  596. .ref_thumb{white-space:nowrap;overflow:hidden;}
  597. .ref_thumb .file_thumb{width:3em;height:3em;}
  598. .side_thumb li{margin:0.4em;display:inline-block;}
  599. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  600. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  601. .p_thumb{display:flex;flex-grow:1;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  602. .p_thumb_narrow{width:1rem;}
  603. .p_thumb img{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  604. .ref_count,.p_thumb .post_menu_button{text-shadow: 0px 0px 10px rgb(0, 0, 0);}
  605. .p_thumb:hover .post_menu_button{display:block;}
  606. .p_thumb_selected{color:%black% !important;}
  607. .p_thumb_selected{display:block;}
  608. .post .p_thumb img{max-height:6rem;}
  609. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  610. .big_image_box *{pointer-events:auto;}
  611. .big_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  612. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  613. .here_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  614. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;
  615. background:linear-gradient(to right, rgba(0,0,0,0), rgb(1, 1, 1));transition:background-size .2s linear;background-size: 300% 100%;}
  616. .big_side_box:hover{background-size: 100% 100%;}
  617. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  618. .big_side_box a:hover{color:%gray%;}
  619. #dropping_background{background-color:rgba(0,0,0,0.4);position:fixed;top:0;right:0;bottom:0;left:0;z-index:100;text-align:center;
  620. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  621. img{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  622. .post img{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  623. .post > a > img{display:block;margin:0.3em auto;}
  624. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  625. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  626. .center_exp .post .original_img{display:block;}
  627. .original_img img{max-height:90vh;max-width:100%;}
  628. .p_row .original_img{margin-bottom:0;}
  629. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  630. .b ul{font-size:1.4em;}
  631. no_pop{cursor:unset;}
  632. p{min-height:0.8em;}
  633. .bold,.bold *{font-weight:bold;}
  634. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  635. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;}
  636. .small_footer>div{overflow:auto;white-space:nowrap;}
  637. .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;}
  638. .top_post_hint{margin-left:1.5em;font-weight:bold;}
  639. .white{color:%white%;}
  640. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  641. .image_nav_prev,.image_nav_next{z-index:100;position:absolute;line-height:0;height:100%;width:20%;display:flex;align-items:center;
  642. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  643. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.2));
  644. background-repeat:no-repeat;background-size:0% 100%;}
  645. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  646. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  647. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  648. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  649. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  650. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  651. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  652. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  653. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  654. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  655. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  656. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  657. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  658. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  659. .special_paypal_inner{color:#169bd7;}
  660. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  661. animation:anim_loading 1s linear infinite;}
  662. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  663. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  664. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  665. .product_thumb img{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  666. .product_ref p{margin-bottom:0.2em;text-align:left;}
  667. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  668. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  669. .page_break{page-break-after:always;}
  670. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  671. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  672. .print_title{display:none;}
  673. .show_on_print{display:none;}
  674. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  675. .comment tbody tr:hover{box-shadow:none;}
  676. .comment table{border:none;}
  677. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  678. .comment ul{padding-left:1em;}
  679. .comment ul li *{margin-bottom:0.5em;}
  680. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  681. .history li li{list-style:circle;}
  682. .history ul{padding-left:1em;}
  683. .history a{text-decoration:underline;}
  684. .history .list{overflow:auto;white-space:nowrap;}
  685. .diff_table{table-layout:fixed;}
  686. .diff_table thead{font-size:0.9em;text-align:center;}
  687. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  688. .diff_table td{vertical-align:top;}
  689. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  690. .wayback_close{float:right;}
  691. .wayback_expand{display:inline;}
  692. .post_selecting .post *{pointer-events:none;}
  693. .post_selected{background-color:%graybkg%;}
  694. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  695. .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%;}
  696. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  697. .wayback_link{display:inline;}
  698. .imd{object-fit:cover;width:100%;}
  699. .center_exp .imd{width:60%;}
  700. #here_buttons{display:contents;}
  701. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  702. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  703. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  704. .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;}
  705. @media screen and (max-width:1000px) and (min-width:666px){
  706. .left{width:35%;}
  707. .center,.center_wide{width:65%;}
  708. .center_wide .p_thumb{height:8rem;}
  709. .right{display:none;}
  710. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  711. .post_width_big{left:0;width:100%;}
  712. .hidden_on_wide{display:unset;}
  713. .pop_right{width:30%;}
  714. .pop_right_big{width:40%;}
  715. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  716. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  717. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  718. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  719. .big_side_box{width:35%;}
  720. .big_image_box{width:65%;}
  721. .inquiry_buttons{right:35%;}
  722. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  723. .post_dummy > *{width:80%;max-width:55rem;}
  724. .center_exp .imd{width:80%;}
  725. .here_btn{width:1.5em;height:1.5em;}
  726. }
  727. @media screen and (max-width:666px){
  728. html{font-size:16px;}
  729. .hidden_on_mobile{display:none !important;}
  730. .block_on_mobile{display:block !important;}
  731. .hidden_on_desktop{display:unset;}
  732. .hidden_on_wide{display:unset;}
  733. header ul{display:block;}
  734. header li{display:block;}
  735. header li::before{content:''}
  736. header::before{box-shadow:none;display:none;}
  737. .small_footer::before{box-shadow:none;display:none;}
  738. .left{position:relative;width:100%;position:relative;top:unset;height:unset;min-height:80vh;padding-right:0;display:block;}
  739. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  740. .center_wide .p_thumb{height:6rem;}
  741. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  742. .pop_right{height:30%;}
  743. .pop_right_big{height:70%;}
  744. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  745. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  746. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  747. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  748. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  749. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  750. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  751. .side_box_mobile_inner:hover{background-size:100% 100%;}
  752. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  753. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  754. .p_thumb{height:3rem;}
  755. .center .post{padding-right:0rem;padding-left:0rem;}
  756. .post .p_thumb img{max-height:3rem;}
  757. .page,.page_gallery{padding:0.2em;padding-top:0;}
  758. header{padding-top:0.3em;}
  759. .toc_button{top:0.3em;}
  760. .small_footer{padding-bottom:0.3em;}
  761. .footer_additional{display:block;width:100%;}
  762. .album_hint{display:block;font-size:1rem;}
  763. .image_nav{position:absolute !important;}
  764. .image_nav_prev,.image_nav_next{width:25%;}
  765. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  766. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  767. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  768. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  769. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  770. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  771. .opt_compact,.ref_compact{line-break:anywhere;}
  772. .post_width,.post_width_big{overflow:auto;}
  773. .table_top{left:unset;width:100%;overflow:auto;}
  774. table img{max-width:30vw !important;}
  775. .product_ref{width:100%;display:block;}
  776. .post_dummy > *{width:100%;max-width:25rem;}
  777. .sticky_title{top:1.2em;}
  778. .small_footer{position:relative;}
  779. #upload_selector{width:100%;}
  780. .focused_post{padding:0.3rem !important;}
  781. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  782. .wayback_expand{display:block;text-align:center;}
  783. .wayback_link{display:block;}
  784. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  785. .center_exp .post{overflow:auto;}
  786. .center_exp .imd{width:100%;}
  787. .here_btn{width:1.2em;height:1.2em;}
  788. .exp_h_f{height:unset !important;}
  789. .exp_f{margin-bottom:1em;}
  790. }
  791. @media print{
  792. header::before{box-shadow:none;display:none;}
  793. .small_footer::before{box-shadow:none;display:none;}
  794. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  795. .post *,.post_dummy *{margin-bottom:0em}
  796. .p_row,.post table,.post_width>img,.post_width_big>img,.post_ref>img,.post_ref>.original_img,
  797. .post_width>.original_img,.post_width_big>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  798. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  799. table img{margin:0 !important;}
  800. .post h1+p,.post h2+p,.post img+p,.post table+p,.post p:first-child{text-indent:0;}
  801. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  802. table{border-bottom:2px solid black;border-top:2px solid black;}
  803. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  804. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  805. .post_width,.post_width_big{overflow:clip;left:0;width:100%;padding-left:0em;}
  806. .post h1{margin-top:0.5rem;}
  807. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  808. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  809. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  810. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  811. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  812. .left,.right{display:none;}
  813. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  814. hr{border:1px solid black;}
  815. .post_box_top{display:none;}
  816. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;}
  817. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  818. .focused_post{border:none;font-size:1em;padding:0 !important;}
  819. .hidden_on_print{display:none;}
  820. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  821. .post_access{display:none;}
  822. .opt_compact{margin-left:0;}
  823. .post .post_ref{padding-left:1.4rem;}
  824. .opt_compact .post_width{left:1.4rem;width:calc(100% - 1.4rem);margin-left:0;}
  825. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  826. .print_title:first-of-type{margin-top:1em;}
  827. .print_title+.post h1:first-of-type{display:none;}
  828. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  829. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  830. .header_nav{display:none;}
  831. .show_on_print{display:block;}
  832. blockquote{border-left:2px solid black;}
  833. .footer_additional{display:none;}
  834. .small_footer{margin-top:1rem;}
  835. .page_selector{display:none;}
  836. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  837. .post .p_thumb img{max-height:4rem;}
  838. .sticky_title{box-shadow:none;}
  839. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  840. .center_wide .p_row{display:block;}
  841. .interesting_tbody{background:none;}
  842. .interesting_tbody img{display:none !important;}
  843. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  844. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  845. }
  846. ";
  847. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  848. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  849. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  850. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  851. $this->style=preg_replace('/%lightopbkg%/','#daae8010',$this->style);
  852. $this->style=preg_replace('/%lighterbkg%/','#675340',$this->style);
  853. $this->style=preg_replace('/%focusedbkg%/','#482f0c',$this->style);
  854. $f = fopen('styles/main.css','w');
  855. fwrite($f,$this->style);
  856. fclose($f);
  857. }
  858. function GiveSafeEMail(){
  859. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  860. }
  861. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  862. if(isset($this->Images[0])) foreach($this->Images as &$im){
  863. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  864. else { if($im['name']==$name) return $im; }
  865. }
  866. return $this->NULL_IMAGE;
  867. }
  868. function &GiveImageInHere($rand=false){
  869. $this->ReadImages(); $this->DetectPageType();
  870. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  871. if(!isset($album) || !$album){
  872. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  873. $imlist=[]; $imlist_fallback=[];
  874. if(isset($this->Images[0])){
  875. foreach($this->Images as &$im){
  876. if(isset($im['galleries'][0]) && in_array($album,$im['galleries'])){
  877. if(!$rand) return $im; else if($this->CanShowImage($im)){
  878. $imlist_fallback[] = $im;
  879. if(!in_array($im['name'],$this->VisitedHere)) $imlist[] = $im;
  880. }
  881. }
  882. }
  883. }
  884. if(!$rand || !isset($imlist_fallback[0])) return $this->NULL_IMAGE;
  885. if(sizeof($imlist)){
  886. $r = random_int(0, sizeof($imlist)-1);
  887. return $imlist[$r];
  888. }else{
  889. $r = random_int(0, sizeof($imlist_fallback)-1);
  890. return $imlist_fallback[$r];
  891. }
  892. }
  893. function ImageTitle($im){
  894. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  895. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  896. return $imtitle;
  897. }
  898. function ImageHasHere(&$im, $here_name){
  899. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  900. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  901. }
  902. function ReadImages($clear_non_exist = false){
  903. $path = 'images/list.md';
  904. if($this->DoneReadImages){ return; }
  905. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  906. $c = file_get_contents($path);
  907. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  908. $g=[]; $g['name']=$m[1];//$g['count']=0;
  909. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  910. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  911. $this->Galleries[] = $g;
  912. }
  913. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  914. $name = trim($m[1]);
  915. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  916. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  917. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  918. $item['refs']=[];
  919. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  920. }
  921. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  922. $item['galleries']=[];
  923. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  924. }
  925. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  926. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  927. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  928. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  929. $item['here']=[];
  930. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  931. }
  932. $this->Images[] = $item;
  933. }
  934. $files = array_merge([],glob('images/*.jpg'));
  935. $files = array_merge($files,glob('images/*.jpeg'));
  936. $files = array_merge($files,glob('images/*.png'));
  937. $files = array_merge($files,glob('images/*.gif'));
  938. if(isset($files[0]))foreach($files as $file) {
  939. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png)/u', $file, $m)) {
  940. $name = trim($m[0]);
  941. if(!$this->FindImage($name)){
  942. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  943. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  944. $this->Images[] = $item;
  945. }
  946. }
  947. }
  948. if($clear_non_exist){
  949. if(isset($this->Images[0]) && isset($files[0])){
  950. foreach($this->Images as &$im){
  951. if(!in_array($im['file'],$files)){
  952. $im['deleted'] = 1;
  953. }
  954. }
  955. }
  956. }
  957. function cmpf($a, $b){
  958. if ($a['name'] == $b['name']) return 0;
  959. return (($a['name'] > $b['name']) ? 1 : -1);
  960. }
  961. function cmpaf($a, $b){
  962. if ($a['name'] == $b['name']) return 0;
  963. return ($a['name'] > $b['name']) ? -1 : 1;
  964. }
  965. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  966. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  967. $this->DoneReadImages = 1;
  968. }
  969. function WriteImages(){
  970. if(isset($this->WayBack)) return;
  971. $path = 'images/list.md';
  972. $f = fopen($path,'w');
  973. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  974. if(isset($g['deleted'])) continue;
  975. fwrite($f,'GALLERY '.$g['name']);
  976. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  977. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  978. fwrite($f, PHP_EOL);
  979. }
  980. if(isset($this->Images[0]))foreach($this->Images as &$im){
  981. if(isset($im['deleted'])) continue;
  982. fwrite($f, "- ".$im['name'].'; ');
  983. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  984. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  985. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  986. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  987. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  988. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  989. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  990. }
  991. fwrite($f, PHP_EOL);
  992. }
  993. fflush($f);
  994. fclose($f);
  995. }
  996. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL){
  997. if(!($im = &$this->FindImage($name))) return;
  998. if(isset($link_gallery)){
  999. if($do_remove){
  1000. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  1001. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  1002. $im['galleries'] = array_merge($im['galleries']);
  1003. }else{
  1004. if(!isset($im['galleries'])) $im['galleries']=[];
  1005. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  1006. $im['galleries'][]=$link_gallery;
  1007. }
  1008. }
  1009. if(isset($product_link)){
  1010. if($product_link!=''){$im['product']=$product_link;}
  1011. else{unset($im['product']);}
  1012. }
  1013. if(isset($rename) && $rename!=$im['name']){
  1014. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1015. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1016. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1017. $im['name'] = $rename.'.'.$ext;
  1018. }
  1019. if(isset($parent) && $parent!=$im['parent']){
  1020. if($parent==''){ unset($im['parent']); }
  1021. else{ $im['parent'] = $parent; }
  1022. }
  1023. $this->NeedWriteImages = 1;
  1024. }
  1025. function RegenerateThumbnails(){
  1026. $glob = glob('images/*.jpg');
  1027. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1028. foreach($glob as $file) {
  1029. $thumb_destination = 'images/thumb/'.basename($file);
  1030. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1031. $width=$geo['width']; $height=$geo['height'];
  1032. $lim=400;
  1033. $scale = $lim / min($width,$height);
  1034. if($scale<1){
  1035. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1036. }
  1037. $img->setImageFormat('jpeg');
  1038. $img->setImageCompressionQuality(90);
  1039. $img->writeImage($thumb_destination);
  1040. }
  1041. }
  1042. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max) {
  1043. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1044. $width=$geo['width']; $height=$geo['height'];
  1045. $lim=400;
  1046. $scale = $lim / min($width,$height);
  1047. if($scale<1){
  1048. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1049. }
  1050. $img->setImageFormat('jpeg');
  1051. $img->setImageCompressionQuality($quality);
  1052. $img->writeImage($thumb_destination);
  1053. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1054. if($scale<1){
  1055. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1056. }
  1057. $img2->setImageFormat('jpeg');
  1058. $img2->setImageCompressionQuality($quality);
  1059. $img2->writeImage($destination);
  1060. }
  1061. function DoUpload(){
  1062. if(!isset($_FILES['upload_file_name'])) return 0;
  1063. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1064. if($_FILES['upload_file_name']['error']>0){
  1065. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1066. return -1;
  1067. }else{
  1068. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  1069. if(!in_array($ext,['jpg','jpeg','png','gif'])) return 0;
  1070. $fp = fopen('.la_lock',"w");
  1071. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1072. usleep(10000);
  1073. }
  1074. $num=date('YmdHis'); $replace=0;
  1075. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1076. $num = $mim[1]; $replace=1;
  1077. }
  1078. $base = 'images/'.$num;
  1079. $thumb = 'images/thumb/'.$num;
  1080. if($ext=='png') $ext='jpg';
  1081. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  1082. if(!$replace) while(file_exists($final_path)){
  1083. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  1084. }
  1085. if($ext!='gif'){
  1086. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1087. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1088. $compress?800:1920, $compress?1920:2560);
  1089. }else{
  1090. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1091. }
  1092. flock($fp, LOCK_UN);
  1093. fclose($fp);
  1094. $this->ReadImages(true);
  1095. $this->WriteImages();
  1096. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1097. if(isset($_POST['image_replace_button'])){
  1098. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1099. }
  1100. exit;
  1101. return 1;
  1102. }
  1103. return 0;
  1104. }
  1105. function &GetGallery($name){
  1106. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1107. if($g['name'] == $name) return $g;
  1108. }
  1109. return $this->NULL_GALLERY;
  1110. }
  1111. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  1112. $this->ReadImages();
  1113. $gallery = &$this->GetGallery($name);
  1114. if(!isset($gallery)){
  1115. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1116. $g = []; $g['name']=$new_name;
  1117. $this->Galleries[]=$g;
  1118. }else{
  1119. if(isset($new_name)) {
  1120. if(preg_match('/main|trash|\s/u',$new_name))return;
  1121. $gallery['name'] = $new_name;
  1122. foreach ($this->Images as &$im){
  1123. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1124. if($g == $name){ $g = $new_name; }
  1125. }
  1126. }
  1127. }
  1128. //if(isset($count)) $gallery['count'] = $count;
  1129. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1130. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1131. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1132. }
  1133. if($do_rw) { $this->NeedWriteImages = 1; }
  1134. }
  1135. function ClearData(){
  1136. $this->Posts = [];
  1137. $this->Threads = [];
  1138. $this->Images = [];
  1139. $this->Archive = [];
  1140. $this->ArchiveHandles = [];
  1141. }
  1142. function InsertArchivePost(&$post){
  1143. $a = NULL;
  1144. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1145. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1146. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1147. }
  1148. $a['list'][] = $post;
  1149. $this->Archive[] = $post;
  1150. }
  1151. function ReadArchiveFromFile($path){
  1152. if(!file_exists($path)){
  1153. return;
  1154. }
  1155. $c = file_get_contents($path);
  1156. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1157. foreach($matches as $m){
  1158. $post = [];
  1159. $post['id'] = $m[1];
  1160. $post['content'] = trim($m[3]);
  1161. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1162. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1163. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1164. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1165. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1166. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1167. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1168. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1169. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1170. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1171. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1172. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1173. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1174. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1175. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1176. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1177. }
  1178. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1179. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1180. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1181. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1182. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1183. }
  1184. $this->InsertArchivePost($post);
  1185. }
  1186. }
  1187. }
  1188. function SortArchive(){
  1189. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1190. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1191. return (($a['id'] > $b['id']) ? 1 : -1);
  1192. };
  1193. if(isset($this->Archive[0])){
  1194. usort($this->Archive,$cmpap);
  1195. $year_begin = substr($this->Archive[0]['id'],0,4);
  1196. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1197. }
  1198. if(isset($this->ArchiveHandles[0])){
  1199. usort($this->ArchiveHandles,$cmpac);
  1200. foreach($this->ArchiveHandles as &$a){
  1201. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1202. $last_valid=NULL;
  1203. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1204. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1205. else{ $last_valid = $ver['content']; } }
  1206. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1207. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1208. }
  1209. }
  1210. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1211. $p['archive'] = &$a;
  1212. }
  1213. }
  1214. }
  1215. }
  1216. function ReadPostsFromFile($path){
  1217. if(!file_exists($path)){
  1218. $f = fopen($path,'w');
  1219. fclose($f);
  1220. }
  1221. $c = file_get_contents($path);
  1222. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1223. foreach($matches as $m){
  1224. $post = [];
  1225. $post['id'] = $m[1];
  1226. $post['real_content'] = trim($m[3]);
  1227. $post['content'] = &$post['real_content'];
  1228. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1229. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1230. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1231. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1232. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1233. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1234. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1235. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1236. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1237. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1238. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1239. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1240. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1241. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1242. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1243. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1244. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1245. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1246. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1247. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1248. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1249. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1250. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1251. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1252. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1253. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1254. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1255. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1256. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\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_thread'][0] = $entries; }
  1259. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1260. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1261. }
  1262. if(isset($post['mark_value']) && $post['mark_value']==5){
  1263. $post['product']=[];
  1264. }
  1265. /* marks add here */
  1266. $this->Posts[] = $post;
  1267. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1268. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1269. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1270. }
  1271. }
  1272. }
  1273. }
  1274. function SortPosts($wayback=false){
  1275. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1276. $sortlist = &$this->Posts;
  1277. if($wayback) $sortlist = &$this->WaybackPosts;
  1278. if(isset($sortlist[0])){
  1279. usort($sortlist,$cmpp);
  1280. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1281. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1282. }
  1283. }
  1284. function ReadPosts(){
  1285. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1286. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1287. (!is_dir('posts') || is_readable('posts') == false) ||
  1288. (!is_dir('archive') || is_readable('archive') == false) ||
  1289. (!is_dir('images') || is_readable('images') == false) ||
  1290. (!is_dir('styles') || is_readable('styles') == false)){
  1291. $this->Install();
  1292. }
  1293. if($this->DoneReadPosts){ return; }
  1294. $file_list = [];
  1295. $glob = glob('posts/*');
  1296. foreach($glob as $file) {
  1297. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1298. $file_list[] = $file;
  1299. }
  1300. }
  1301. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1302. foreach($file_list as $f) {
  1303. $this->ReadPostsFromFile($f);
  1304. }
  1305. $this->SortPosts();
  1306. $this->DetectThreads();
  1307. $this->DoneReadPosts=1;
  1308. }
  1309. function UpdatePostRefsForWayback(){
  1310. if(!isset($this->WayBack)) return;
  1311. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1312. if(!isset($this->WaybackPosts[0])) return;
  1313. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1314. foreach($this->WaybackPosts as &$p){
  1315. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1316. $pr = &$this->GetPost($r); if(isset($pr)){
  1317. if(!isset($pr['refs'])) $pr['refs']=[];
  1318. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1319. }
  1320. }
  1321. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1322. $ir = &$this->FindImage($r); if(isset($ir)){
  1323. if(!isset($ir['refs'])) $ir['refs']=[];
  1324. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1325. }
  1326. }
  1327. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1328. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1329. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1330. }
  1331. }
  1332. }
  1333. function ReadArchive(){
  1334. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1335. if ($this->DoneReadArchive) return;
  1336. $file_list = []; $glob = glob('archive/*');
  1337. foreach($glob as $file) {
  1338. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1339. $file_list[] = $file;
  1340. }
  1341. }
  1342. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1343. foreach($file_list as $f) {
  1344. $this->ReadArchiveFromFile($f);
  1345. }
  1346. $this->SortArchive();
  1347. $this->DoneReadArchive=1;
  1348. $this->UpdateThreadForWayback();
  1349. $this->UpdatePostRefsForWayback();
  1350. }
  1351. function GetThreadForPost(&$post){
  1352. if(isset($post['tid'])) return;
  1353. $th = []; $iterp = NULL;
  1354. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1355. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1356. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1357. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1358. $np['tid'] = &$th;
  1359. $th['first'] = &$np;
  1360. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1361. }
  1362. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1363. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1364. $np['tid'] = &$th;
  1365. $th['last'] = &$np;
  1366. $iterp = isset($np['next'])?$np['next']:NULL;
  1367. }
  1368. if(isset($th['first']['mark_value'])){
  1369. if($th['first']['mark_value']==6) $th['exp'] = true;
  1370. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1371. }
  1372. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1373. $this->Threads[] = &$th;
  1374. }
  1375. function IdentifyThreadCategory(&$th,&$first_post){
  1376. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1377. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1378. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1379. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1380. }
  1381. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1382. }
  1383. if(isset($th) && preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1384. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1385. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1386. }
  1387. }
  1388. if(isset($th) && preg_match('/\{\s*REVERSED\s*\}/imu',$first_post['content'],$m)){
  1389. $th['reversed'] = true;
  1390. }
  1391. }
  1392. function IsInterestingPost(&$p){
  1393. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1394. return false;
  1395. }
  1396. function IsReversedThread(&$th){
  1397. if(isset($th['reversed']) && $th['reversed']) return true;
  1398. return false;
  1399. }
  1400. function GiveAllMergedPosts(&$po,&$arr){
  1401. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1402. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1403. }
  1404. if(isset($po['archive']) && isset($po['archive']['list'])){
  1405. foreach($po['archive']['list'] as &$ver){
  1406. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1407. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1408. }
  1409. }
  1410. }
  1411. function ThreadMakeWayback(&$th){
  1412. if(!isset($th['arr'][0])) return;
  1413. if(isset($this->WayBack)){
  1414. $remlist = [];
  1415. foreach($th['arr'] as &$pi){
  1416. $po = &$this->GetPost($pi['id'],true);
  1417. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1418. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1419. }
  1420. $ah = &$this->GetArchiveHandle($po['id']);
  1421. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1422. if(!isset($ver['merged_thread'])) continue;
  1423. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1424. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1425. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1426. }
  1427. }
  1428. }
  1429. if(isset($remlist[0]) && isset($th['arr'][0])){
  1430. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1431. foreach($th['arr'] as $key => $pr){
  1432. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1433. $new_th = []; $new_arr = [];
  1434. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1435. $new_th['arr'] = &$new_arr;
  1436. $this->WaybackThreads[] = &$new_th;
  1437. $this->ThreadMakeWayback($new_th);
  1438. }
  1439. }
  1440. }
  1441. function AddMergedPosts(&$p, &$array){
  1442. if(isset($p['archive']) && isset($p['archive']['list'])){
  1443. foreach($p['archive']['list'] as &$ver){
  1444. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1445. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1446. }
  1447. }
  1448. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1449. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1450. }
  1451. function FinalizeThread(&$th, $relink_posts=false, $now){
  1452. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1453. if(!isset($th['arr'])){
  1454. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1455. $arr[]=&$p;
  1456. } $th['arr'] = &$arr;
  1457. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1458. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1459. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1460. $arr=&$new_arr; $th['arr']=&$new_arr;
  1461. $this->ThreadMakeWayback($th); }
  1462. }
  1463. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1464. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1465. if($relink_posts){ $count = $th['count'];
  1466. $arr = &$th['arr'];
  1467. 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'];
  1468. $arr[$i]['tid']=&$th;}
  1469. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1470. }
  1471. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1472. $this->IdentifyThreadCategory($th, $th['first']);
  1473. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1474. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1475. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1476. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1477. }
  1478. function SortThreads(){
  1479. if (!function_exists('cmpt')) {
  1480. function cmpt($a, $b){
  1481. if ($a['score'] == $b['score']) return 0;
  1482. return ($a['score'] > $b['score']) ? -1 : 1;
  1483. }
  1484. }
  1485. usort($this->Threads,"cmpt");
  1486. }
  1487. function DetectThreads(){
  1488. foreach($this->Posts as &$p){
  1489. if(isset($p['tid'])) { continue; }
  1490. $this->GetThreadForPost($p);
  1491. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1492. }
  1493. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1494. $now = date_timestamp_get(date_create());
  1495. foreach($this->Threads as &$t){
  1496. $this->FinalizeThread($t,false,$now);
  1497. }
  1498. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1499. $this->FinalizeThread($th,false,$now);
  1500. $this->Threads[] = &$th;
  1501. }
  1502. $this->SortThreads();
  1503. }
  1504. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1505. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1506. foreach($this->Threads as &$t){
  1507. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1508. }
  1509. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1510. $this->FinalizeThread($th,true,$now);
  1511. $this->Threads[] = &$th;
  1512. }
  1513. $this->SortThreads();
  1514. $this->SortPosts(true);
  1515. $this->UsePosts = &$this->WaybackPosts;
  1516. }
  1517. function &GetMergedPost($id){
  1518. $this->ReadArchive();
  1519. $ah = &$this->GetArchiveHandle($id);
  1520. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1521. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1522. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1523. [$tp, $tver] = $ver['merged_into'];
  1524. if(isset($this->WayBack)){
  1525. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1526. else return $this->GetPost($id); /* should not happen directly. */
  1527. }
  1528. return $this->GetMergedPost($tp);
  1529. }
  1530. function &GetPost($id, $latest_only=false, $find_merged=false){
  1531. if(!isset($id)) return $this->NULL_POST;
  1532. $found=&$this->NULL_POST;
  1533. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1534. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1535. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1536. }
  1537. if($latest_only || !isset($this->WayBack)){ return $found; }
  1538. else{
  1539. if(isset($found)){
  1540. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1541. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1542. $last_ver = &$this->NULL_POST;
  1543. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1544. if($ver['version'] > $this->WayBack) return $last_ver;
  1545. $last_ver = &$ver;
  1546. }
  1547. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1548. else return $last_ver;
  1549. }else{
  1550. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1551. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1552. if($ver['version'] > $this->WayBack) return $last_ver;
  1553. $last_ver = &$ver;
  1554. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1555. [$tp, $tver] = $last_ver['merged_into'];
  1556. if($tver <= $this->WayBack) {
  1557. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1558. return $last_ver;
  1559. }
  1560. }
  1561. }
  1562. return $this->NULL_POST;
  1563. }
  1564. function &GetArchiveHandle($id){
  1565. if(!isset($id)) return $this->NULL_POST;
  1566. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1567. if($p && $p['id'] == $id) { return $p; }
  1568. }
  1569. return $this->NULL_POST;
  1570. }
  1571. function &GetArchive($id){
  1572. if(!isset($id)) return $this->NULL_POST;
  1573. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1574. if($p && $p['id'] == $id) { return $p; }
  1575. }
  1576. return $this->NULL_POST;
  1577. }
  1578. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1579. if(!isset($ah)) return $this->NULL_POST;
  1580. $found = NULL; $last_verp=NULL;
  1581. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1582. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1583. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1584. $last_verp = &$p;
  1585. }
  1586. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1587. return $this->NULL_POST;
  1588. }
  1589. function CacheArchiveOwnLinks(){
  1590. if(isset($this->WayBack)) return;
  1591. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1592. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1593. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1594. foreach($matches as $m){
  1595. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1596. }
  1597. }
  1598. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1599. foreach($matches as $m){
  1600. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1601. }
  1602. }
  1603. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1604. foreach($matches as $m){
  1605. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. function WriteArchive(){
  1611. if(isset($this->WayBack)) return;
  1612. $cf = NULL;$opened =NULL;
  1613. $this->SortArchive();
  1614. $this->CacheArchiveOwnLinks();
  1615. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1616. $nid = substr($p['id'], 0,6);
  1617. if($cf != $nid){
  1618. if($opened){
  1619. fflush($opened);
  1620. fclose($opened);
  1621. }
  1622. $cf = $nid;
  1623. $opened = fopen("archive/$cf.md", 'w');
  1624. }
  1625. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1626. "VER {$p['version']}; ".
  1627. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1628. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1629. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1630. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1631. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1632. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1633. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1634. ']';
  1635. if(isset($p['merged_thread'])){ $p['content']=""; }
  1636. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1637. }
  1638. }
  1639. function WritePosts(){
  1640. if(isset($this->WayBack)) return;
  1641. $cf = NULL;$opened =NULL;
  1642. $this->SortPosts();
  1643. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1644. $nid = substr($p['id'], 0,6);
  1645. if($cf != $nid){
  1646. if($opened){
  1647. fflush($opened);
  1648. fclose($opened);
  1649. }
  1650. $cf = $nid;
  1651. $opened = fopen("posts/$cf.md", 'w');
  1652. }
  1653. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1654. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1655. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1656. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1657. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1658. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1659. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1660. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1661. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1662. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1663. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1664. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1665. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1666. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1667. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1668. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1669. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1670. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1671. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1672. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1673. ']';
  1674. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1675. }
  1676. }
  1677. function CachePostLinks(){
  1678. if(isset($this->WayBack)) return;
  1679. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1680. $this->ConvertPost($post);
  1681. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1682. //discard lost old version
  1683. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1684. }else return;
  1685. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1686. unset($im['refs']); unset($im['here']); unset($im['title']);
  1687. }
  1688. foreach ($this->Posts as &$post){
  1689. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1690. foreach($matches as $m){
  1691. $ref = &$this->GetPost($m[1],true);
  1692. if($ref!=NULL){
  1693. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1694. }
  1695. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1696. }
  1697. }
  1698. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1699. foreach($matches as $m){
  1700. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1701. }
  1702. }
  1703. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1704. foreach($matches as $m){
  1705. if(($im = &$this->FindImage($m[2]))!=NULL){
  1706. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1707. }
  1708. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1709. }
  1710. }
  1711. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R(-|\*).+){1,})/u",$post['content'],$matches)){
  1712. $use_img_name = $matches[2];
  1713. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1714. 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))/u",$matches[4],$mah,PREG_SET_ORDER)){
  1715. foreach($mah as $ma){
  1716. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1717. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1718. }
  1719. }
  1720. }
  1721. }
  1722. }foreach($this->Posts as &$post){
  1723. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1724. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1725. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1726. }
  1727. }
  1728. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1729. $min_id = '99999999999999';
  1730. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1731. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1732. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1733. }
  1734. }
  1735. }
  1736. function CreatePostAnchor(&$post){
  1737. $that=&$this;
  1738. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1739. $id = '_heading_'.sizeof($this->Anchors);
  1740. $entry=[(int)$ma[1], $id, $ma[2]];
  1741. $that->Anchors[] = $entry;
  1742. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1743. }, $post['html']);
  1744. }
  1745. function RenamePost(&$post, $rename){
  1746. foreach($this->Posts as &$p){
  1747. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1748. }
  1749. foreach($this->Posts as &$p){
  1750. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1751. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1752. }
  1753. $post['id'] = $rename;
  1754. }
  1755. function DetachPost(&$th,&$post){
  1756. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1757. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1758. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1759. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1760. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1761. unset($th['arr']); $now = date_timestamp_get(date_create());
  1762. $this->FinalizeThread($th, true, $now);
  1763. }
  1764. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1765. $a = &$this->GetArchiveHandle($post['id']);
  1766. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1767. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1768. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1769. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1770. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1771. $post['version'] = $optime_id;
  1772. if($mode==1){
  1773. $this->InsertArchivePost($ap);
  1774. }else if($mode==2){
  1775. $post['merged_from'] = $info;
  1776. $this->InsertArchivePost($ap);
  1777. }else if($mode==3){
  1778. $ap['merged_into'] = $info;
  1779. $this->InsertArchivePost($ap);
  1780. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1781. $this->DetachPost($post['tid'], $post);
  1782. }
  1783. }else if($mode==4){
  1784. $post['merged_thread'] = $info;
  1785. $this->InsertArchivePost($ap);
  1786. }
  1787. }
  1788. function &MergeThreads($post_id, $post_into_id){
  1789. $this->ReadPosts();
  1790. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1791. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1792. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1793. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1794. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1795. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1796. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1797. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1798. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  1799. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1800. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1801. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1802. $tt['count'] = sizeof($tt['arr']);
  1803. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1804. $first_post = &$this->NULL_POST;
  1805. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1806. $this->NeedWritePosts=1;
  1807. $this->NeedWriteArchive=1;
  1808. return $first_post;
  1809. }
  1810. function &MergePosts($ids_string){
  1811. $ids = explode(" ", $ids_string);
  1812. $combined_content = ""; $first_id=NULL;
  1813. $this->ReadPosts(); $child_list=[];
  1814. foreach($ids as $id){
  1815. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1816. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1817. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  1818. }
  1819. if(!isset($child_list[0])) return $this->NULL_POST;
  1820. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  1821. foreach($child_list as $id){
  1822. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  1823. }
  1824. $this->NeedWritePosts=1;
  1825. $this->NeedWriteArchive=1;
  1826. return $first_post;
  1827. }
  1828. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1829. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1830. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1831. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  1832. $this->ReadImages();
  1833. $this->ReadPosts();
  1834. if(isset($push_version) && $push_version){
  1835. $this->ReadArchive();
  1836. }
  1837. $p_success = NULL;
  1838. if(isset($id_if_edit)){
  1839. $post = &$this->GetPost($id_if_edit,true);
  1840. if($post===$this->NULL_POST) return $this->NULL_POST;
  1841. if($get_original_only){
  1842. return $post['real_content'];
  1843. }
  1844. if(isset($push_version) && $push_version){
  1845. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1846. }
  1847. if(isset($content)) $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1848. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1849. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1850. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1851. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  1852. $p_success = &$post;
  1853. }else{
  1854. if(!isset($content)) return $this->NULL_POST;
  1855. $id = date('YmdHis');
  1856. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1857. $post = []; $post['id'] = $id;
  1858. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1859. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1860. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1861. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1862. }
  1863. $this->Posts[] = $post;
  1864. $p_success = &$this->Posts[count($this->Posts) - 1];
  1865. }
  1866. $this->NeedWritePosts=1;
  1867. $this->NeedWriteImages=1;
  1868. if(isset($push_version) && $push_version){
  1869. $this->NeedWriteArchive=1;
  1870. }
  1871. return $p_success;
  1872. }
  1873. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1874. $this->ReadPosts();
  1875. $p_success = NULL;
  1876. if(isset($id_if_edit)){
  1877. $post = &$this->GetPost($id_if_edit,true);
  1878. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1879. if(isset($content)) $post['content'] = $content;
  1880. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1881. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1882. if(isset($ip)) $post['ip'] = $ip;
  1883. $p_success = &$post;
  1884. }else{
  1885. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1886. $id = date('YmdHis');
  1887. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1888. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1889. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1890. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1891. if(isset($ip)) $post['ip'] = $ip;
  1892. $this->Posts[] = $post;
  1893. $p_success = &$this->Posts[count($this->Posts) - 1];
  1894. }
  1895. $this->NeedWritePosts=1;
  1896. return $p_success;
  1897. }
  1898. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  1899. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1900. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1901. function($matches){
  1902. $rep = preg_replace('/->/','-@>',$matches[0]);
  1903. $rep = preg_replace('/=>/','=@>',$rep);
  1904. $rep = preg_replace('/<=/','<@=',$rep);
  1905. $rep = preg_replace('/<-/','<@-',$rep);
  1906. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  1907. $rep = preg_replace('/\[-/','[@-',$rep);
  1908. $rep = preg_replace('/\{/','{@',$rep);
  1909. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  1910. return $rep;
  1911. },
  1912. $replacement);
  1913. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  1914. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  1915. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  1916. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  1917. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  1918. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  1919. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  1920. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  1921. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  1922. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  1923. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  1924. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  1925. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  1926. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  1927. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1928. function($matches){
  1929. $rep = preg_replace('/-@>/','->',$matches[0]);
  1930. $rep = preg_replace('/<@-/','<-',$rep);
  1931. $rep = preg_replace('/=@>/','=>',$rep);
  1932. $rep = preg_replace('/<@=/','<=',$rep);
  1933. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  1934. $rep = preg_replace('/\[@-/','[-',$rep);
  1935. $rep = preg_replace('/\{@/','{',$rep);
  1936. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  1937. return $rep;
  1938. }, $replacement);
  1939. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  1940. function($matches) use (&$post_for_it_is_here){
  1941. $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]);
  1942. return $matches[1].$rep;
  1943. }, $replacement);
  1944. return $replacement;
  1945. }
  1946. function CanShowPost(&$p){
  1947. if(!isset($p) || isset($p['comment_to'])) return false;
  1948. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  1949. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  1950. if($is_mark_slf && !$this->LoggedIn){ return false; }
  1951. if(isset($this->WayBack)){
  1952. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  1953. else if ($p['id']>$this->WayBack) return false;
  1954. }
  1955. if(!$this->InExperimentalMode){
  1956. if(!$this->LoggedIn){
  1957. if($is_mark_exp) return false;
  1958. return true;
  1959. }
  1960. return true;
  1961. }else{
  1962. if($is_mark_exp) return true;
  1963. return false;
  1964. }
  1965. }
  1966. function SkipProduct(&$p){
  1967. if($this->LoggedIn) return false;
  1968. return (isset($p['mark_value']) && $p['mark_value']==5);
  1969. }
  1970. function GetRedirect($args=NULL){
  1971. $str = 'index.php?';
  1972. if(isset($args['post'])) $str.='&post='.$args['post'];
  1973. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  1974. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  1975. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  1976. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  1977. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  1978. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  1979. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  1980. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  1981. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  1982. if(isset($args['category'])) $str.='&category='.$args['category'];
  1983. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  1984. if(isset($args['history'])) $str.='&history='.$args['history'];
  1985. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  1986. if(isset($args['version'])) $str.='&version='.$args['version'];
  1987. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  1988. if(isset($args['search'])) $str.='&search='.$args['search'];
  1989. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  1990. if(isset($args['here'])) $str.='&here='.$args['here'];
  1991. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  1992. return $str;
  1993. }
  1994. function WriteAsNecessary(){
  1995. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  1996. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  1997. if($this->NeedWriteImages){ $this->WriteImages(); }
  1998. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  1999. }
  2000. function APubEnsureWebfinger($name, $host){
  2001. if(!is_dir('.well-known')) mkdir('.well-known');
  2002. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  2003. $f = fopen('.well-known/webfinger/index.php',"w");
  2004. $without_protocol = parse_url($host, PHP_URL_HOST);
  2005. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  2006. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  2007. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  2008. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2009. $res = openssl_pkey_new();
  2010. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2011. openssl_pkey_export($res, $this->APubPrivateKey);
  2012. $f = fopen('.well-known/apub_public_key.pem',"w");
  2013. fwrite($f, $this->APubPublicKey); fclose($f);
  2014. $f = fopen('.well-known/apub_private_key.php',"w");
  2015. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2016. }
  2017. }
  2018. function APubEnsureInfo(){
  2019. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2020. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2021. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2022. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2023. "id"=> $this->HostURL."?apub_actor=1",
  2024. "type"=> "Person",
  2025. "name"=> $this->DisplayName,
  2026. "url"=> $this->HostURL,
  2027. "summary"=> "Lazy... No summary",
  2028. "preferredUsername"=> $this->APubID,
  2029. "inbox"=> $this->HostURL."?apub_inbox=1",
  2030. "outbox"=> $this->HostURL."?apub_outbox=1",
  2031. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2032. "owner"=> $this->HostURL."?apub_actor=1",
  2033. "publicKeyPem"=>$pk]];
  2034. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2035. }
  2036. function APubMakeOutbox(){
  2037. $this->ReadPosts();$this->ReadImages();
  2038. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2039. "id"=>$this->HostURL."?apub_outbox=1",
  2040. "type"=>"OrderedCollection"];
  2041. $items=[]; $i=0;
  2042. foreach(array_reverse($this->Posts) as &$p){
  2043. $this->ConvertPost($p);
  2044. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2045. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2046. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2047. "type"=> "Create",
  2048. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2049. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2050. //"to"=> ["https://chatty.example/ben/"],
  2051. "actor"=> $this->HostURL."?apub_actor=1",
  2052. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2053. "object"=> ["type"=> "Note",
  2054. "id"=> $this->HostURL."?post=".$p['id'],
  2055. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2056. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2057. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2058. "content"=> $text]];
  2059. $items[] = $ob;
  2060. $i++; if($i>20) break;
  2061. }
  2062. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2063. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2064. }
  2065. function MakeRSS(){
  2066. $this->ReadPosts();$this->ReadImages();
  2067. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2068. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2069. "<title>".$this->T($this->Title)."</title>".
  2070. "<link href='".$this->HostURL."/?rss' rel='self'/>".
  2071. "<link href='".$this->HostURL."' />".$author;
  2072. $i=0;
  2073. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  2074. if($i>100) break;
  2075. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2076. if(isset($p['tid'])){ /* Should always be set. */
  2077. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2078. if(in_array($p['id'],
  2079. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  2080. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2081. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2082. $is_reversed=false;
  2083. $content="<entry>"; $title = NULL;
  2084. if($is_thread){
  2085. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2086. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2087. foreach($use_arr as &$po){
  2088. $this->ConvertPost($po);
  2089. if(!isset($title)){$title = $this->GetPostTitle($po, false, false);
  2090. $content.="<id>tag:".$this->HostURL."-".$po['id']."</id>";
  2091. $content.="<title>".$title."</title><link>".$this->HostURL."/?post=".$po['id']."</link>";
  2092. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2093. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2094. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;
  2095. $content.="<content type='html'>"; }
  2096. $content.= htmlspecialchars($po['html']);
  2097. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2098. }
  2099. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2100. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2101. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2102. $content.="</content>";
  2103. }else{
  2104. $this->ConvertPost($p);
  2105. if(!isset($title)){$title = $this->GetPostTitle($p, false, false);
  2106. $content.="<id>tag:".$this->HostURL."-".$p['id']."</id>";
  2107. $content.="<title type='text'>".$title."</title><link>".$this->HostURL."/?post=".$p['id']."</link>";
  2108. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2109. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2110. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2111. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2112. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2113. $content.=$this->ReadableTime($p['id'])." - ".
  2114. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2115. $content.="</content>";
  2116. }
  2117. $i++;
  2118. $content.="</entry>";
  2119. $all_content.=$content;
  2120. }
  2121. $all_content.="</feed>";
  2122. header( "Content-type: text/xml");
  2123. echo $all_content;
  2124. }
  2125. function MakeHereButtons($im, $insert_here){
  2126. if(isset($im['here'])&&isset($im['here'][0])){
  2127. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2128. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2129. foreach($im['here'] as $here){
  2130. if($insert_here){
  2131. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2132. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2133. }else{
  2134. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2135. }
  2136. }
  2137. echo "</div>".($insert_here?"</here>":"");
  2138. }
  2139. }
  2140. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  2141. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2142. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2143. return 0;
  2144. }
  2145. if(isset($_GET['set_language'])){
  2146. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2147. $redirect=$this->GetRedirect(); return 0;
  2148. }
  2149. if(isset($_GET['rss'])){
  2150. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2151. $this->MakeRSS(); exit;
  2152. }
  2153. if(isset($_GET['toggle_font'])){ $use_font='local';
  2154. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2155. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2156. $redirect=$this->GetRedirect(); return 0;
  2157. }
  2158. if(isset($_GET['set_wayback'])){
  2159. if($_GET['set_wayback']!='false'){
  2160. $wayback= date('YmdHis');
  2161. if($_GET['set_wayback']=='post'){
  2162. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2163. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2164. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2165. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2166. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2167. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2168. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2169. }else{
  2170. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2171. }
  2172. $redirect=$this->GetRedirect(); return 0;
  2173. }
  2174. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2175. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2176. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2177. if(isset($_GET['part'])){
  2178. if($_GET['part'] == 'hot') $this->ExtraScripts.="ShowLeftSide();";
  2179. else if ($_GET['part'] == 'recent') $this->ExtraScripts.="ShowCenterSide();";
  2180. }
  2181. if(isset($_GET['post'])){
  2182. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2183. }
  2184. if(isset($_GET['random_here'])){
  2185. $this->DoIdentiyExperimental(); $this->DetectPageType();
  2186. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2187. }
  2188. if(isset($_POST['search_content'])){ $redirect='index.php?search='.$_POST['search_content'];return 0; }
  2189. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2190. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2191. $direct_return = !isset($_GET['show_image']);
  2192. $this->ReadImages(); $this->ReadPosts();
  2193. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2194. $im = &$this->FindImage($m);
  2195. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2196. if($direct_return){
  2197. echo "<ref>".sizeof($im['refs'])."</ref>";
  2198. echo "<insert><ul>";
  2199. }else{ ob_start(); }
  2200. foreach(array_reverse($im['refs']) as $ref){
  2201. $p = $this->GetPost($ref);
  2202. if(!$p || !$this->CanShowPost($p)) continue;
  2203. $this->MakeSinglePost($p, false, true, "post_preview", true, false, false, false, true);"</li>";
  2204. }
  2205. if($direct_return){
  2206. echo "</ul></insert>";
  2207. $this->MakeHereButtons($im, true);
  2208. }else{
  2209. $str = ob_get_clean();
  2210. $this->MakePageBegin();
  2211. $side = "";
  2212. if(isset($im['refs'])&&isset($im['refs'][0])){
  2213. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2214. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2215. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$im['file']);
  2216. $this->MakePageEnd();
  2217. }
  2218. exit;
  2219. }
  2220. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2221. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2222. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2223. }
  2224. if(isset($_GET['apub_actor'])){
  2225. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2226. echo $this->APubActor; exit;
  2227. }
  2228. if(isset($_GET['apub_outbox'])){
  2229. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2230. echo $this->APubMakeOutbox(); exit;
  2231. }
  2232. if($this->LoggedIn){
  2233. $this->DoUpload();
  2234. if(isset($_POST['settings_button'])){
  2235. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2236. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2237. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2238. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2239. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2240. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2241. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2242. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2243. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2244. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2245. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2246. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2247. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2248. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2249. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2250. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2251. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2252. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2253. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2254. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2255. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2256. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2257. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2258. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2259. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2260. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2261. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2262. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2263. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2264. $this->APubID=$_POST['settings_apub_id'];
  2265. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2266. }
  2267. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2268. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2269. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2270. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2271. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2272. $redirect=$_SERVER['REQUEST_URI'];
  2273. $this->DoLogout();
  2274. }
  2275. $this->WriteConfig();
  2276. return 0;
  2277. }
  2278. if(isset($_POST['settings_save_redirect'])){
  2279. if(isset($_POST['settings_redirect'])){
  2280. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2281. }
  2282. $this->WriteConfig();
  2283. $redirect = 'index.php?extras=true'; return 0;
  2284. }
  2285. if(isset($_POST['settings_save_translation'])){
  2286. if(isset($_POST['settings_translation'])){
  2287. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2288. }
  2289. $redirect = 'index.php?extras=true'; return 0;
  2290. }
  2291. if(isset($_GET['post'])){
  2292. if(isset($_GET['post_original'])){
  2293. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2294. exit;
  2295. }
  2296. }
  2297. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2298. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2299. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2300. return 0;
  2301. }
  2302. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2303. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2304. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2305. return 0;
  2306. }
  2307. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2308. $c = $_POST['post_content'];
  2309. if('有什么想说的' == $c){ return 0;}
  2310. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2311. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2312. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2313. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2314. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2315. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2316. $redirect='?post='.$edited['id']; return 0;
  2317. };
  2318. }
  2319. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2320. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2321. $redirect='?post='.$edited['id']; return 0;
  2322. };
  2323. }
  2324. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2325. if(($edited =$this->EditPost(
  2326. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2327. $redirect='?post='.$edited['id']; return 0;
  2328. };
  2329. }
  2330. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2331. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2332. if(isset($post)){
  2333. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2334. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2335. echo "SUCCESS ".$mastodon_url;
  2336. }else{ echo $err; }
  2337. } exit;
  2338. }
  2339. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2340. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2341. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2342. }
  2343. }
  2344. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2345. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2346. $redirect='?post='.$pe['id']; return 0;
  2347. }
  2348. }
  2349. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2350. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2351. $c = $_POST['comment_box'];
  2352. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2353. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2354. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2355. if(($edited = $this->EditComment(NULL,
  2356. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2357. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2358. $_SERVER['REMOTE_ADDR']))!=NULL){
  2359. $redirect='?post='.$_GET['post'];
  2360. return 0;
  2361. };
  2362. }
  2363. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2364. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2365. $new_name = $_POST['gallery_edit_new_name'];
  2366. if($old_name!=''){
  2367. $this->EditGallery($old_name, $new_name, false, true, null, null);
  2368. $redirect='?gallery='.$new_name;
  2369. }else{
  2370. $this->EditGallery(null, $new_name, false, true, null);
  2371. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2372. }
  2373. return 0;
  2374. }
  2375. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2376. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  2377. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  2378. return 0;
  2379. }
  2380. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2381. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2382. $this->ReadImages();
  2383. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2384. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL);
  2385. }
  2386. }
  2387. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2388. return 0;
  2389. }
  2390. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2391. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2392. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2393. return 0;
  2394. }
  2395. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2396. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2397. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2398. return 0;
  2399. }
  2400. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2401. $this->ReadImages();
  2402. $gallery = $_GET['image_list'];
  2403. foreach($this->Images as $im){
  2404. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2405. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2406. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2407. }
  2408. exit;
  2409. }
  2410. $do_image_redirect = 0;
  2411. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2412. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif))/u',$_GET['pic'],$ma)){
  2413. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2414. if(isset($_POST['image_ops_product_link'])){
  2415. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL);
  2416. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2417. }
  2418. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2419. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL);
  2420. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2421. $do_image_redirect = 1;
  2422. }
  2423. if(isset($_POST['image_parent'])){ $parent="";
  2424. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2425. $this->EditImage($pic, NULL, false, NULL, NULL, $parent);
  2426. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2427. }
  2428. $this->NeedWriteImages = 1;
  2429. if($do_image_redirect) return 0;
  2430. }
  2431. if(isset($_GET['rewrite_styles'])){
  2432. $this->WriteStyles();
  2433. $redirect='?extras=true'; return 0;
  2434. }
  2435. if(isset($_GET['regenerate_thumbnails'])){
  2436. $this->RegenerateThumbnails();
  2437. $redirect='?extras=true'; return 0;
  2438. }
  2439. if(isset($_GET['clear_all_logins'])){
  2440. $this->LoginTokens=[];
  2441. $this->WriteTokens();
  2442. }
  2443. }
  2444. return 0;
  2445. }
  2446. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null){
  2447. if(!$this->LoggedIn){
  2448. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2449. }
  2450. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2451. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2452. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2453. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2454. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2455. $html = preg_replace("/<p>\s*\{\s*INTERESTING\s+(.*?)\}\s*<\/p>/imu","",$html);
  2456. $html = preg_replace("/\{\s*REVERSED\s*\}/imu","",$html);
  2457. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2458. $html = preg_replace_callback(
  2459. "/(<p>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2460. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2461. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2462. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2463. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2464. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2465. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2466. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2467. $src = $im['thumb']; $orig_src=$im['file'];
  2468. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2469. if($this->InHereMode){
  2470. $click = "<div class='imd'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2471. $m[2].$orig_src.$m[7]."></a></div>";
  2472. return $click;
  2473. }else{ $click =
  2474. "<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2475. $m[2].($original?$orig_src:$src).$m[7]." data-imgsrc='".$m[5]."'".
  2476. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2477. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2478. ($original?" class='original_img'":"")."></a></div>";
  2479. $images_noclick[]=$m[2].$src.$m[7].">"; $images_orig_src_list[]=$orig_src;
  2480. $ret = "";
  2481. if($keep) { $ret = $click; }
  2482. else { $images[] = $click; }
  2483. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2484. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2485. }
  2486. },$html,-1,$count);
  2487. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2488. if(sizeof($images)){
  2489. if(sizeof($images)==1){$html.= $images[0]; }
  2490. else{
  2491. $html.="<div class='p_row'>";
  2492. foreach($images as $img){
  2493. $html.="<div class='p_thumb'>".$img."</div>";
  2494. }
  2495. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2496. }
  2497. }
  2498. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2499. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2500. if($do_product_info){
  2501. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2502. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2503. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2504. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2505. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2506. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2507. else { $product_info['title'] = $this->T('商品'); }
  2508. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2509. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2510. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2511. $this->T('购买').' '.$product_info['title'].
  2512. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2513. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2514. }
  2515. return $html;
  2516. }
  2517. function ConvertPost(&$post){
  2518. if(!isset($post['html'])){
  2519. $info=[];
  2520. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2521. $post['images'],
  2522. isset($post['product']), $info,
  2523. $post['original_images']));
  2524. if(isset($post['product'])) $post['product']=$info;
  2525. }
  2526. }
  2527. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2528. if(!isset($post['title'])){
  2529. if($h1_only){
  2530. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){return $m[1];}
  2531. return NULL;
  2532. }
  2533. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2534. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2535. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2536. $post['title'].=($add_unamed?' (':'').strip_tags($this->PDE->text($m[1])).($add_unamed?')':''); }
  2537. }
  2538. }
  2539. return $this->ChoosePartsByLanguage($post['title']);
  2540. }
  2541. function DetectPageType(){
  2542. if ($this->InExperimentalMode) $this->PageType='experimental';
  2543. else if($this->InHereMode) $this->PageType='here';
  2544. else if(isset($_GET['history'])) $this->PageType='history';
  2545. else if(isset($_GET['extras'])) $this->PageType='extras';
  2546. else if(isset($_GET['settings'])) $this->PageType='settings';
  2547. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2548. else if(isset($_GET['search'])) $this->PageType='search';
  2549. else if(isset($_GET['category'])) $this->PageType='category';
  2550. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2551. else if(isset($_GET['comments'])) $this->PageType='comments';
  2552. else $this->PageType = "main";
  2553. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2554. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2555. $this->VisitedHere = $_SESSION[$visited_here];
  2556. }
  2557. function MakePageBegin(){ ?>
  2558. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2559. <head>
  2560. <meta charset='utf-8'>
  2561. <meta content="width=device-width, initial-scale=1" name="viewport">
  2562. <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2563. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title))?></title>
  2564. <?php if($this->UseRemoteFont){ ?><style>
  2565. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2566. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2567. </style><?php } ?>
  2568. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2569. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2570. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2571. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2572. </head>
  2573. <div class='page'>
  2574. <?php }
  2575. function MakeHeader(&$p){
  2576. $this->MakePageBegin() ?>
  2577. <script type='text/javascript'>
  2578. function toggle_mobile_show(a){a.classList.toggle('hidden_on_mobile')}
  2579. function ShowWaitingBar(){
  2580. wait = document.querySelector("#waiting_bar");
  2581. wait.style.display='';
  2582. }
  2583. function HideWaitingBar(){
  2584. wait = document.querySelector("#waiting_bar");
  2585. wait.style.display='none';
  2586. }
  2587. <?php if(!$this->InHereMode){ ?>
  2588. function la_auto_grow(element){
  2589. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2590. }
  2591. var scroll_l=0,scroll_c=0;in_center=1;
  2592. function ShowLeftSide(){
  2593. scroll_c = window.scrollY;
  2594. document.getElementById('div_left').classList.remove('hidden_on_mobile');
  2595. document.getElementById('div_center').classList.add('hidden_on_mobile');
  2596. window.scroll(0, scroll_l); in_center=0;
  2597. }
  2598. function ShowCenterSide(){
  2599. scroll_l = window.scrollY;
  2600. document.getElementById('div_center').classList.remove('hidden_on_mobile');
  2601. document.getElementById('div_left').classList.add('hidden_on_mobile');
  2602. window.scroll(0, scroll_c); in_center=1;
  2603. }
  2604. function ShowBackdrop(alpha=0.5){
  2605. b = document.getElementById('backdrop');
  2606. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2607. b.style.animation='backdrop_fade_in 0.3s forwards';
  2608. b.style.display = 'block';
  2609. }
  2610. function HideBackdrop(){
  2611. b = document.getElementById('backdrop');
  2612. b.style.animation='backdrop_fade_out 0.3s forwards';
  2613. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2614. }
  2615. function ShowRightSide(big,elem_to_clone){
  2616. p = document.getElementById('pop_right');
  2617. if(elem_to_clone){
  2618. c = elem_to_clone.cloneNode(true);
  2619. c.id='side_bar_cloned';c.className="";c.style="";
  2620. p.querySelector('._content').appendChild(c);
  2621. }
  2622. p.classList.remove('pop_right','pop_right_big');
  2623. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2624. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2625. p.style.display='block';
  2626. ShowBackdrop(0.5);
  2627. }
  2628. function HideRightSide(){
  2629. p = document.getElementById('pop_right');
  2630. if(side=p.querySelector('#side_bar_cloned')){
  2631. side.remove();
  2632. }
  2633. put = document.querySelector("#_uploader");
  2634. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2635. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2636. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2637. HideBackdrop();
  2638. }
  2639. function ToggleLeftSide(){if(in_center)ShowLeftSide();else ShowCenterSide();}
  2640. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2641. function ScrollToPost(id){
  2642. post=null;
  2643. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2644. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2645. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2646. }
  2647. <?php } ?>
  2648. </script>
  2649. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2650. <?php if($this->InHereMode){
  2651. $this->MakeExpNavButtons($p);
  2652. }else{
  2653. $this->MakeNavButtons($p);
  2654. echo "<hr />";
  2655. } ?>
  2656. <?php if(isset($this->WayBack)){
  2657. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2658. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2659. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2660. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_on_mobile")'>
  2661. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2662. <span class='hidden_on_mobile'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2663. <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_on_mobile'>
  2664. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2665. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2666. <br class='hidden_on_desktop' />
  2667. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2668. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2669. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2670. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2671. <br class='hidden_on_desktop' />
  2672. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2673. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2674. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2675. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2676. <br class='hidden_on_desktop' />
  2677. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2678. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2679. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2680. </div></div><?php } ?>
  2681. </div></header>
  2682. <div id='waiting_bar' style='display:none;'></div>
  2683. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2684. <?php if(!$this->InHereMode){ ?>
  2685. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2686. <ul>
  2687. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2688. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2689. <hr />
  2690. <?php if($this->LoggedIn){ ?>
  2691. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2692. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2693. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2694. <?php if(!isset($this->WayBack)){ ?><li>
  2695. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2696. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2697. </li>
  2698. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2699. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2700. <li id='mark_details' style='display:none;'><b>
  2701. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2702. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2703. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2704. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2705. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2706. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2707. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2708. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2709. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2710. </b></li>
  2711. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2712. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2713. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2714. <input class='button' type='submit' form='post_rename_form'
  2715. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2716. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  2717. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  2718. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  2719. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  2720. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  2721. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  2722. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  2723. <input class='button' type='submit' form='post_mastodon_form'
  2724. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  2725. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  2726. <?php }else{ ?>
  2727. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2728. <?php } ?>
  2729. </ul>
  2730. </div>
  2731. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide()'
  2732. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2733. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2734. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2735. <?=$this->T('关闭')?>→</a></div>
  2736. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2737. <div id='_uploader' style='display:none;'>
  2738. <?php $this->MakeUploader(true); ?>
  2739. <p>&nbsp;</p>
  2740. <?php $this->MakeSideGalleryCode(); ?>
  2741. </div>
  2742. <?php } ?>
  2743. <div class='_content'></div>
  2744. </div>
  2745. <?php } ?>
  2746. <?php
  2747. }
  2748. function ChoosePartsByLanguage($content,$use_p=false){
  2749. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  2750. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  2751. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  2752. if($split) for($i=0;$i<sizeof($split);$i+=4){
  2753. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  2754. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  2755. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  2756. }
  2757. if(!$reduced)$reduced = $content;
  2758. return $reduced;
  2759. }
  2760. function TranslatePostParts($html){
  2761. $html = preg_replace_callback('/>([^><]+?)</u', function($ma){
  2762. $reduced = $this->ChoosePartsByLanguage($ma[1], false);
  2763. return ">".$this->T($reduced)."<";
  2764. }, $html);
  2765. return $html;
  2766. }
  2767. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); ?>
  2768. <a href='index.php' class='clean_a hidden_on_mobile' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title)?></b></a>
  2769. <b><a class='hidden_on_desktop'
  2770. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ShortTitle)?>...</a></b>
  2771. <div class='header_nav'>
  2772. <?php if($this->PageType=='post'){ ?>
  2773. <div class='toc_button hidden_on_print'>
  2774. <?php if(!$interesting && isset($p) && isset($p['refs']) && isset($p['refs'][0])){ ?>
  2775. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2776. <?=$this->T('链接')?>(<?=sizeof($p['refs'])?>)</a></span>
  2777. <?php } if(!$interesting){ ?>
  2778. <span class='hidden_on_wide hidden_on_print'>
  2779. <a id='button_toc' href='javascript:ShowRightSide(true,document.querySelector("#div_right"));'>
  2780. <?=$this->T('目录')?></a></span><?php } ?></div>
  2781. <?php }else if($this->PageType=='history' && isset($_GET['version'])){ ?>
  2782. <div style='float:right;' class='hidden_on_print'>
  2783. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2784. <?=$this->T('历史')?></a></span></div>
  2785. <?php } ?>
  2786. <ul class='hidden_on_mobile hidden_on_print' id='mobile_nav' style='text-align:center;'>
  2787. <li class='hidden_on_mobile'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2788. <li class='hidden_on_desktop_force block_on_mobile'>
  2789. <?php if($this->PageType!='main'){ ?>
  2790. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a> |
  2791. <a href='index.php?part=hot' onclick='ShowWaitingBar()'><?=$this->T('热门')?></a> |
  2792. <?php } else { ?>
  2793. <li class='hidden_on_desktop_force block_on_mobile'>
  2794. <a href='javascript:ShowCenterSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('最近')?></a> |
  2795. <a href='javascript:ShowLeftSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('热门')?></a> |
  2796. <?php } ?>
  2797. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a>
  2798. <?php if($this->LoggedIn){ ?>
  2799. | <span class='gray invert_a'><a href='index.php?comments=all'>@</a></span><?php } ?></li>
  2800. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2801. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2802. } ?>
  2803. <li><a href='?search=' onclick='ShowWaitingBar()'><?=$this->T('搜索')?></a></li>
  2804. <?php if($this->LanguageAppendix=='zh'){ ?>
  2805. <li class='invert_a smaller'>
  2806. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  2807. <?php }else { ?>
  2808. <li class='smaller'>
  2809. <a class='invert_a' href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  2810. 汉语/<b>English</b></a>
  2811. <br class='hidden_on_desktop' />
  2812. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  2813. <?php } ?>
  2814. </ul>
  2815. </div>
  2816. <?php
  2817. }
  2818. function MakeExpNavButtons(&$p){ ?>
  2819. <a href='index.php' class='hidden_on_mobile'>
  2820. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  2821. <a class='hidden_on_desktop'
  2822. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b>
  2823. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?>...</b></a>
  2824. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  2825. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  2826. <span class='round_btn'>
  2827. <a href='<?=$this->HereNumber==sizeof($this->VisitedHere)?"?random_here=1":$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a>
  2828. <a href='?random_here=1'><?=$this->T("随机")?></a></span>
  2829. <b><?=$this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle));?></b>
  2830. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):"";?>
  2831. <ul class='hidden_on_mobile gray invert_a' id='mobile_nav' style='text-align:center;'>
  2832. <li class='hidden_on_desktop block_on_mobile'><a href='index.php'><?=$this->T('索引')?></a></li>
  2833. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2834. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2835. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  2836. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2837. } ?>
  2838. <?php if($this->LanguageAppendix=='zh'){ ?>
  2839. <li class='smaller'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  2840. <?php }else { ?>
  2841. <li class='smaller'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  2842. <li class='smaller'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  2843. <?php } ?>
  2844. </ul>
  2845. <?php
  2846. }
  2847. function GenerateLinkedPosts($ht){
  2848. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  2849. function($m){
  2850. $rp = &$this->GetPost($m[1], false, true);
  2851. $s="<div class='smaller block post ref_compact gray'>".
  2852. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  2853. "<div class='post_ref'><div class='smaller'>".$m[2]."</div>".
  2854. (($rp!==NULL && $this->CanShowPost($rp))?
  2855. $this->GenerateSinglePost($rp,false,false,false,true,$this->NULL_POST,true):$this->T("未找到该引用。")).
  2856. "</div></div>";
  2857. return $s;
  2858. },
  2859. $ht
  2860. );
  2861. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  2862. function($m){
  2863. $rp = &$this->GetPost($m[1], false, true);
  2864. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  2865. (($rp!==NULL && $this->CanShowPost($rp))?
  2866. $this->GenerateSinglePost($rp,true,false,false,true,$this->NULL_POST,true):$this->T("未找到该引用。")).
  2867. "</a></div>";
  2868. return $s;
  2869. },
  2870. $ht
  2871. );
  2872. return $ht;
  2873. }
  2874. function ExtractBigTables($html, &$table_out){
  2875. $table = NULL;
  2876. $new_html = preg_replace_callback('/<p>\s*\{big_table\}\s*<\/p>\s*(<table>[\s\S]*?<\/table>)/u', function ($m) use (&$table){
  2877. $table = $m[1];
  2878. return "";
  2879. }, $html);
  2880. $table_out = $table;
  2881. return $new_html;
  2882. }
  2883. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  2884. $generate_thumbs=false, &$table_out, $hide_long = false){
  2885. $this->ConvertPost($post);
  2886. if($generate_anchor){ $this->CreatePostAnchor($post); }
  2887. $ht = $post['html'];
  2888. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  2889. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  2890. "<p class='bold'>".$post['product']['title']."</p>".
  2891. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  2892. "<p class='smaller bold'>".$post['product']['price']."</p>";
  2893. return $ht;
  2894. }
  2895. if($hide_long){
  2896. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  2897. }else{
  2898. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  2899. }
  2900. if ($strip_tags){
  2901. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  2902. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  2903. $ht = "<div class='post_ref_main'>".$ht."</div>";
  2904. }
  2905. else{
  2906. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  2907. if($table_out!=$this->NULL_POST){
  2908. $table = NULL; $ht = $this->ExtractBigTables($ht,$table);
  2909. $table_out = $table;
  2910. }else{
  2911. $ht = preg_replace('/<p>\s*\{big_table\}\s*<\/p>/u','',$ht);
  2912. }
  2913. }
  2914. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  2915. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  2916. foreach($post['images'] as $im){
  2917. $ht.="<li class='file_thumb'>".$im."</li>";
  2918. }
  2919. $ht.="</ul></div>";
  2920. }
  2921. return $ht;
  2922. }
  2923. function MakeSinglePostExp(&$post){
  2924. $big_table = ""; ?>
  2925. <li class='post post_dummy'>
  2926. <?=$this->GenerateSinglePost($post, false, false, true, false, $big_table, false); ?>
  2927. </li>
  2928. <?php if($big_table!=$this->NULL_POST) echo "</ul></li><div class='table_top'>".$big_table.'</div>';?>
  2929. <?php
  2930. }
  2931. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  2932. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  2933. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  2934. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  2935. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  2936. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  2937. $big_table = ($show_thread_link)?$this->NULL_POST:"";
  2938. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  2939. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  2940. ?>
  2941. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  2942. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?><?=$side?" post_box":""?>'
  2943. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  2944. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?> >
  2945. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  2946. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  2947. <?php } ?>
  2948. <?php if($is_top){?>
  2949. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  2950. <?php } ?>
  2951. <?php if(!$side && $show_link){ ?>
  2952. <a href='?post=<?=$post['id']?>' onclick='ShowWaitingBar()'>
  2953. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2954. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"→")?>
  2955. </div>
  2956. <?php if($ref_count){ ?>
  2957. <div class='post_access ref_count'><?=$ref_count?></div>
  2958. <?php } ?>
  2959. </a>
  2960. <?php } ?>
  2961. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  2962. <div class='<?=$side?"":($show_link?'post_width':'post_width_big')?><?=$is_deleted?" deleted_post":""?>'>
  2963. <?php if(!$side && !$strip_tags){?>
  2964. <div class='post_menu_button _menu_hook' >+</div>
  2965. <?php } if($is_product&&!$generate_anchor){
  2966. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  2967. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  2968. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  2969. $generate_thumb,$big_table,($show_thread_link||$side||$force_hide_long)); ?>
  2970. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  2971. </div>
  2972. <?=$side?"</a>":""?> <?php
  2973. if(!$show_thread_link && $big_table!=$this->NULL_POST && !$side){
  2974. echo "</ul></li><div class='table_top'>".$big_table.'</div>';
  2975. ?><ul class='print_column'>
  2976. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  2977. <?php
  2978. }
  2979. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  2980. $post['tid']['first']['id']!=$post['id']){ ?>
  2981. <div class='gray smaller block opt_compact post'>
  2982. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  2983. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  2984. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  2985. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  2986. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true,$this->NULL_POST,true);?>
  2987. </div>
  2988. </div>
  2989. <?php }
  2990. if($show_reply_count && isset($post['tid'])){ ?>
  2991. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  2992. <?=$this->T('个回复')?></a>
  2993. <?php }
  2994. ?>
  2995. </li>
  2996. <?php
  2997. }
  2998. function MakePostingFields($reply_to=NULL, $show_hint=false){
  2999. if(isset($this->WayBack)){ ?>
  3000. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  3001. <?php return; } ?>
  3002. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  3003. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  3004. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  3005. <div id='post_hint_modify' style='display:none;'>
  3006. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  3007. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  3008. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  3009. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  3010. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3011. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3012. onclick='ShowWaitingBar();' />
  3013. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3014. <div style='float:right;'>
  3015. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3016. <?=$this->T('清空')?></a>
  3017. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3018. </div>
  3019. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3020. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3021. <?php if($reply_to){ ?>
  3022. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3023. <?php } ?>
  3024. <?php
  3025. }
  3026. function MakeCommentPosts(){
  3027. if(!$this->LoggedIn) return; ?>
  3028. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3029. <?php if(!$this->CommentEnabled){
  3030. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3031. <div class='comment'><ul>
  3032. <?php $i=0;
  3033. foreach(array_reverse($this->Posts) as $p){
  3034. if(!isset($p['comment_to'])) continue;
  3035. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3036. $ht = $this->GenerateSinglePost($p, false, false, false, false, $t, false);
  3037. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3038. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3039. if(!$post_to) $post_title = "?";
  3040. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3041. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3042. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3043. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3044. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3045. $i++;
  3046. }
  3047. ?>
  3048. </ul><br /></div>
  3049. <?php
  3050. }
  3051. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  3052. <div class='center' id='div_center'>
  3053. <h2><?=isset($search_term)?$this->T('搜索'):
  3054. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3055. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3056. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3057. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  3058. <?php if(isset($search_term)){ ?>
  3059. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  3060. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3061. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3062. <?php }else if(isset($category)){ ?>
  3063. <div></div>
  3064. <?php }else if($this->LoggedIn){ ?>
  3065. <div class='post_box_top _input_bundle'>
  3066. <?php $this->MakePostingFields(NULL,false); ?>
  3067. </div>
  3068. <?php } ?>
  3069. <ul class='print_column list'>
  3070. <?php
  3071. if(!isset($search_term) && !isset($category) &&
  3072. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3073. $this->CanShowPost($p)){
  3074. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  3075. }
  3076. $i = 0;
  3077. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3078. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3079. if(isset($p['tid'])){ /* Should always be set. */
  3080. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3081. if(!isset($search_term)) { $p = &$th['last']; }
  3082. }
  3083. if(isset($search_term)){
  3084. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3085. }else if(isset($category)){
  3086. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3087. (isset($p['categories'])?($p['categories']):[]);
  3088. if ($category=='none') { if($cat!=[]) continue; }
  3089. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3090. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3091. }else{
  3092. if(in_array($p['id'],
  3093. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  3094. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3095. }
  3096. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3097. $this->MakeSinglePost($p, true, false, NULL, false, !isset($search_term), false, false, false, false, isset($search_term));
  3098. $i++;
  3099. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3100. }?>
  3101. </ul>
  3102. <div class='page_selector clean_a'>
  3103. <hr />
  3104. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  3105. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3106. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3107. <?=$this->CurrentOffset+1?>
  3108. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  3109. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3110. → <?=$this->T('下一页')?></a>
  3111. </div>
  3112. </div>
  3113. <?php
  3114. }
  3115. function MakeHotPosts($placeholder_only=false){?>
  3116. <div class='left hidden_on_mobile' id='div_left'>
  3117. <?php if ($placeholder_only){ ?>&nbsp;
  3118. <?php }else{ ?>
  3119. <h2><?=$this->T('热门')?></h2>
  3120. <ul>
  3121. <?php
  3122. $i=0;
  3123. foreach($this->Threads as &$th){
  3124. if(!isset($th['first']) || $th['count']==0){ continue; }
  3125. if(!$this->CanShowPost($th['first'])) continue;
  3126. if($i>=$this->HotPostCount) break;
  3127. $this->MakeSinglePost($th['first'], false, true, "post_preview", true, false, true, false, true, false, false);
  3128. $i++;
  3129. } ?>
  3130. </ul>
  3131. <?php } ?>
  3132. </div>
  3133. <?php
  3134. }
  3135. function MakeLinkedPosts(&$p){
  3136. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3137. <div class='left hidden_on_mobile' id='div_left'>
  3138. <h2<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h2>
  3139. <?php
  3140. if($has_ref){ ?>
  3141. <span class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></span>
  3142. <ul><?php $count_product=0;
  3143. foreach(array_reverse($p['refs']) as &$pr){
  3144. $po = $this->GetPost($pr); if(isset($post['mark_value']) && $po['mark_value']==5){ $count_product++; continue; }
  3145. if(!$this->CanShowPost($po)){ continue; }
  3146. $this->MakeSinglePost($po, false, true, "post_preview", true, false, false, false, true, false, false);
  3147. }
  3148. ?></ul>
  3149. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3150. }else{ ?>
  3151. <span class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></span>
  3152. <?php } ?>
  3153. </div>
  3154. <?php
  3155. }
  3156. function MakeLinkedPostsExp(&$p){
  3157. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3158. <div class='center_exp post_dummy smaller'>
  3159. <hr />
  3160. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3161. <?php
  3162. if($has_ref){ ?>
  3163. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3164. <ul><?php $count_product=0;
  3165. foreach(array_reverse($p['refs']) as &$pr){
  3166. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3167. "</a></li>";
  3168. }
  3169. ?></ul>
  3170. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3171. }else{ ?>
  3172. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3173. <?php } ?>
  3174. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3175. </div>
  3176. <?php
  3177. }
  3178. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3179. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3180. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3181. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3182. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3183. if(!isset($title)) $title=$this->T('未命名');
  3184. if(!isset($ah)){ ?>
  3185. <h2><?=$this->T('没有历史记录')?></h2>
  3186. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3187. <?php }else{ ?>
  3188. <h2><?=$this->T('历史记录')?></h2>
  3189. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3190. <div class='list'><ul>
  3191. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3192. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3193. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3194. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3195. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3196. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3197. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3198. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3199. <?=$this->GetPostTitle($ver);?></a>
  3200. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3201. <?php } ?></ul><?php } ?>
  3202. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3203. $mah = &$this->GetArchiveHandle($pm);
  3204. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3205. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3206. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3207. <?php } ?>
  3208. </li><?php } ?>
  3209. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3210. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3211. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3212. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3213. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3214. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3215. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3216. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3217. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3218. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3219. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3220. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3221. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3222. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3223. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3224. <?=$this->GetPostTitle($ver);?></a>
  3225. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3226. <?php } ?></ul></li><?php } ?>
  3227. <?php } ?></ul></div>
  3228. <?php } ?>
  3229. <?php
  3230. }
  3231. function MakePostDiff(&$this_ver, &$last_ver){
  3232. if(!isset($this_ver)){ ?>
  3233. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3234. <?php }else{ ?>
  3235. <h2><?=$this->T('差异')?></h2>
  3236. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3237. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3238. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3239. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3240. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3241. <?php }else{ ?>
  3242. <table class='diff_table'><thead>
  3243. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3244. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3245. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3246. </thead><tbody>
  3247. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3248. </tbody>
  3249. </table>
  3250. <?php } ?>
  3251. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3252. <?php } ?>
  3253. <?php
  3254. }
  3255. function MakePostHistory(&$post, $version=NULL){
  3256. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3257. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3258. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3259. ?>
  3260. <div class='left hidden_on_mobile history' id='div_left'>
  3261. <?php if (isset($version)){
  3262. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3263. }else{ echo "&nbsp;"; } ?>
  3264. </div>
  3265. <div class='center history' id='div_center'>
  3266. <?php if (!isset($version)){
  3267. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3268. }else{
  3269. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3270. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3271. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3272. $this->MakePostDiff($this_ver, $last_ver, $p);
  3273. } ?>
  3274. </div>
  3275. <?php
  3276. }
  3277. function MakeCommentSection(&$post){
  3278. if(!$this->CommentEnabled){ return; }
  3279. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3280. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3281. ?><div class='comment'>
  3282. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3283. <?php if($comment_count) { echo "<ul>";
  3284. foreach($to_post['comments'] as $p){
  3285. $ht = $this->GenerateSinglePost($p, false, false, false, false, $t, false);
  3286. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3287. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3288. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3289. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3290. }
  3291. echo "</ul>";
  3292. } else {
  3293. echo $this->T('还没有评论');
  3294. } ?>
  3295. <div class='hidden_on_print'>
  3296. <div class='spacer'></div>
  3297. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3298. method="post" style="display:none;" id="comment_form"></form>
  3299. <p><a class='text_highlight bold clean_a'
  3300. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3301. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3302. <div id='comment_box' style='display:none;'>
  3303. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3304. <table style='white-space:nowrap;'>
  3305. <tr><td colspan='2'>
  3306. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3307. oninput="CommentUpdated();" ></textarea>
  3308. </td></tr>
  3309. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3310. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3311. class='full_box' oninput="CommentUpdated();" /></td>
  3312. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3313. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3314. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3315. <tr><td colspan='2'>
  3316. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3317. class='full_box' oninput="CommentUpdated();" />
  3318. </td></tr>
  3319. <tr><td colspan='2'>
  3320. <div class='spacer'></div>
  3321. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3322. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3323. </td></tr>
  3324. </table></div>
  3325. <script>
  3326. const IsValidEmail = (email) => {
  3327. 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,}))$/);
  3328. };
  3329. function IsValidHttpUrl(string) {
  3330. let url; try{ url = new URL(string); } catch (_) { return false; }
  3331. return url.protocol === "http:" || url.protocol === "https:";
  3332. }
  3333. var cbox = document.getElementById('comment_box');
  3334. var cemail = document.getElementById('comment_email');
  3335. var cname = document.getElementById('comment_name');
  3336. var clink = document.getElementById('comment_link');
  3337. var cconfirm = document.getElementById('comment_confirm');
  3338. function CommentUpdated(){
  3339. cconfirm.disabled=true;
  3340. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3341. cbox.innerText.length>2 && cname.value.length>2 &&
  3342. clink.value=="" || IsValidHttpUrl(clink.value)){
  3343. cconfirm.removeAttribute("disabled");
  3344. }
  3345. }
  3346. CommentUpdated();
  3347. </script>
  3348. </div>
  3349. </div>
  3350. <?php
  3351. }
  3352. function MakeInterestingSection(&$th){
  3353. $this->Anchors = [];
  3354. $c = &$th['first']['content'];
  3355. $this->ConvertPost($th['first']);
  3356. $ht = $th['first']['html'];
  3357. ?>
  3358. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3359. <div class='center_full' id='div_center'>
  3360. <?php $this->MakePostTools(); ?>
  3361. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3362. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3363. <ul><li class='post post_width_big' data-post-id='<?=$th['first']['id']?>'>
  3364. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3365. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3366. <?php foreach($th['first']['refs'] as $ref){
  3367. $po = $this->GetPost($ref);
  3368. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3369. if(!$this->CanShowPost($po)){ continue; }
  3370. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3371. } ?>
  3372. </ul><?php } ?>
  3373. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3374. <div class='post_width_big hidden_on_print'><br />
  3375. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3376. </div>
  3377. <?php } ?>
  3378. <table><thead><tr><th></th><?php foreach($th['interesting'] as $header){ ?>
  3379. <th><?=$this->T($header);?></th>
  3380. <?php } ?></tr></thead><tbody class='interesting_tbody'>
  3381. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3382. foreach($plist as &$p){
  3383. $this->ConvertPost($p);
  3384. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3385. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3386. $is_current = $p['id']==$this->CurrentPostID;
  3387. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3388. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3389. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3390. onDblClick='ClickImage(this)'><td>
  3391. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3392. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3393. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3394. </div>
  3395. <?php if($ref_count){ ?>
  3396. <div class='post_access ref_count'><?=$ref_count?></div>
  3397. <?php } ?></a>
  3398. <?=$p['html'];?>
  3399. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a></td></tr>
  3400. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3401. <?php foreach($p['refs'] as $ref){
  3402. $po = $this->GetPost($ref);
  3403. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3404. if(!$this->CanShowPost($po)){ continue; }
  3405. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3406. } ?>
  3407. </ul></td></tr><?php } ?>
  3408. <?php } ?>
  3409. </tbody></table>
  3410. </li></ul>
  3411. <br />
  3412. <?php $this->MakeCommentSection($th['first']); ?>
  3413. </div>
  3414. <?php return true;
  3415. }
  3416. function CssNumberID($id){
  3417. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3418. }
  3419. function MakePostTools(){
  3420. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3421. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3422. <?=$this->T('工具')?></a>:<div class='hidden_on_mobile' style='display:inline'>
  3423. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3424. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3425. </div>
  3426. <select class='hidden_on_desktop' id='merge_select'
  3427. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3428. <option value='-1' selected>--</option>
  3429. <option value='1'><?=$this->T('合并帖子')?></option>
  3430. <option value='2'><?=$this->T('合并话题')?></option></select>
  3431. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3432. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3433. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3434. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3435. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3436. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3437. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3438. </div><div class='spacer'></div><?php
  3439. }
  3440. }
  3441. function MakePostSection(&$post){
  3442. $this->Anchors = [];
  3443. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3444. <div class='center' id='div_center'>
  3445. <h2 class='hidden_on_print'>
  3446. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1; if($is_thread){ $th = $post['tid'];?>
  3447. <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3448. <?php } ?></h2>
  3449. <?php $cat = NULL;
  3450. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3451. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3452. $this->MakePostTools();
  3453. if($cat){ ?>
  3454. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3455. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3456. <?php } ?>
  3457. <ul class='print_column'>
  3458. <?php $is_reversed=false;
  3459. if($is_thread){
  3460. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  3461. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3462. foreach($use_arr as &$p){
  3463. $use_class = ($p == $post)?'focused_post':'';
  3464. $show_link = ($p == $post)?false:true;
  3465. $make_title = ($p == $post);
  3466. $this->MakeSinglePost($p,$show_link,false,$use_class,false, false, false, true, false, false);
  3467. if($make_title){?>
  3468. <script>
  3469. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3470. </script>
  3471. <?php } if($is_reversed && !$hinted){ ?>
  3472. <li class='gray smaller bold' style='text-align:center;'>
  3473. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3474. <?php $hinted = true;
  3475. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3476. <div class='post_width_big hidden_on_print'>
  3477. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3478. <?php } }
  3479. }
  3480. }else{
  3481. $this->MakeSinglePost($post,false, false, 'focused_post',false, false, false, true, false, false);
  3482. ?><script>
  3483. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3484. </script><?php
  3485. } ?>
  3486. <div class='smaller align_right'>
  3487. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3488. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3489. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3490. </div>
  3491. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  3492. <div class='post_width_big hidden_on_print'>
  3493. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3494. </div>
  3495. <?php }
  3496. $this->MakeCommentSection($post);
  3497. ?>
  3498. </ul>
  3499. </div>
  3500. <?php
  3501. }
  3502. function MakePostSectionExp(&$post){
  3503. $this->Anchors = []; $is_thread = isset($post['tid']);
  3504. ?>
  3505. <div class='center_exp' id='div_center'>
  3506. <ul>
  3507. <?php $is_reversed=false;
  3508. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th);
  3509. $hinted=false; if($is_reversed){
  3510. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3511. foreach($use_arr as &$p){
  3512. $this->MakeSinglePostExp($p);
  3513. if($p == $th['first']){?>
  3514. <script>
  3515. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3516. </script>
  3517. <?php } if($is_reversed && !$hinted){ ?>
  3518. <li class='gray smaller bold' style='text-align:center;'>
  3519. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3520. <?php $hinted = true; }
  3521. }
  3522. }else{
  3523. $this->MakeSinglePostExp($post);
  3524. ?><!--<script>
  3525. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3526. </script>--><?php
  3527. } ?>
  3528. </ul>
  3529. </div>
  3530. <?php
  3531. }
  3532. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  3533. <div class='here_image_box clean_a'>
  3534. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  3535. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  3536. <?php if($image_okay){ ?>
  3537. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  3538. <?php } $this->MakeHereButtons($im, false); ?>
  3539. </div>
  3540. <?php }
  3541. function MakeSideGalleryCode(){?>
  3542. <div>
  3543. <h3><?=$this->T('点击图片以插入:')?></h3>
  3544. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3545. <option value="main"><?=$this->T('全部')?></option>
  3546. <?php if($this->LoggedIn){ ?>
  3547. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3548. <?php }?>
  3549. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3550. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3551. <?php } ?>
  3552. </select>
  3553. <div id='side_gallery'>
  3554. </div>
  3555. </div>
  3556. <script>
  3557. function InsertImage(imgname){
  3558. t = document.querySelector("#post_content");
  3559. v = t.value;
  3560. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3561. la_auto_grow(t);
  3562. }
  3563. function RefreshSideGallery(){
  3564. let xhr = new XMLHttpRequest();
  3565. xhr.onreadystatechange = (function(){
  3566. if (this.readyState === this.DONE) {
  3567. if (this.status === 200) {
  3568. ind = document.querySelector("#side_gallery");
  3569. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3570. str = "<ul class='side_thumb'>"
  3571. for (const m of res) {
  3572. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+
  3573. "<img src='"+m[2]+"' /></div>"
  3574. }
  3575. str += "</ul>"
  3576. ind.innerHTML = str;
  3577. }
  3578. }
  3579. }
  3580. });
  3581. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3582. xhr.send();
  3583. }
  3584. </script>
  3585. <?php
  3586. }
  3587. function MakeUploader($is_side=false){ ?>
  3588. <div id='upload_operation_area' class='hidden_on_print'>
  3589. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3590. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3591. <ul id='file_list'>
  3592. </ul>
  3593. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3594. </div>
  3595. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3596. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3597. <script>
  3598. function pastehandler(event){
  3599. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3600. for (index in items) {
  3601. var item = items[index];
  3602. if (item.kind === 'file') {
  3603. put = document.querySelector("#_uploader");
  3604. if(put) ShowSideUploader();
  3605. var blob = item.getAsFile();
  3606. AddImageFile(blob);
  3607. return;
  3608. }
  3609. }
  3610. }
  3611. let _fd_list = []; var uploading=0;
  3612. let hint=document.querySelector('#upload_hint');
  3613. function ToggleCompress(button){
  3614. li = button.parentNode;
  3615. num=li.dataset.number;
  3616. for(i=0;i<_fd_list.length;i++){
  3617. if (_fd_list[i][0] == num){
  3618. state = _fd_list[i][2];
  3619. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3620. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3621. }
  3622. }
  3623. }
  3624. function RemoveFromUpload(button){
  3625. li = button.parentNode;
  3626. num=li.dataset.number;
  3627. for(i=0;i<_fd_list.length;i++){
  3628. if (_fd_list[i][0] == num){
  3629. _fd_list.splice(i, 1);break;
  3630. }
  3631. }
  3632. li.parentNode.removeChild(li);
  3633. }
  3634. function EndThisUpload(){
  3635. unfinished = 0;
  3636. for(i=0;i<_fd_list.length;i++){
  3637. if (_fd_list[i][3]==0){
  3638. unfinished=1;
  3639. }
  3640. }
  3641. if(!unfinished){
  3642. uploading=0;
  3643. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3644. cl=document.querySelector('#upload_click');
  3645. if(!cl.dataset.isSide){
  3646. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3647. cl.href=window.location.href;
  3648. }else{
  3649. _fd_list.splice(0,_fd_list.length);
  3650. fl = document.querySelector("#file_list");
  3651. fl.innerHTML = "";
  3652. list=document.querySelector('#upload_operation_area');
  3653. list.style.pointerEvents='';
  3654. list.style.opacity='';
  3655. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3656. document.onpaste=pastehandler;
  3657. RefreshSideGallery();
  3658. }
  3659. }
  3660. }
  3661. function UploadList(){
  3662. if(!_fd_list.length || uploading) return;
  3663. uploading=1;
  3664. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3665. list=document.querySelector('#upload_operation_area');
  3666. list.style.pointerEvents='none';
  3667. list.style.opacity='0.5';
  3668. document.onpaste="";
  3669. for(i=0;i<_fd_list.length;i++){
  3670. let xhr = new XMLHttpRequest();
  3671. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3672. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3673. function wrap(li, i){
  3674. var ind = li.querySelector('._compress_toggle')
  3675. return function(){
  3676. if (this.readyState === this.DONE) {
  3677. if (this.status === 200) {
  3678. var response = xhr.responseText;
  3679. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3680. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3681. _fd_list[i][3] = 1;
  3682. }else{
  3683. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3684. _fd_list[i][3] = 1;
  3685. }
  3686. EndThisUpload();
  3687. }
  3688. }
  3689. }
  3690. }
  3691. xhr.onreadystatechange = wrap(li, i);
  3692. xhr.send(_fd_list[i][1]);
  3693. }
  3694. }
  3695. function AddImageFile(blob){
  3696. var ext="";
  3697. if(blob.name.match(/png$/))ext = 'png';
  3698. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3699. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3700. else if(blob.name.match(/gif$/))ext = 'gif';
  3701. else return;
  3702. var fd = new FormData();
  3703. blob.name = blob.name=generateUID().toString();
  3704. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3705. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3706. var reader = new FileReader();
  3707. reader.onload = function(event){
  3708. fl = document.querySelector("#file_list");
  3709. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3710. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3711. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3712. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3713. fl.innerHTML+=ht;
  3714. };
  3715. reader.readAsDataURL(blob);
  3716. }
  3717. sel = document.querySelector('#upload_selector');
  3718. sel.addEventListener("change", function(){
  3719. var input = this;
  3720. function ff(file){
  3721. return function(e){
  3722. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3723. blob.name = file.name;
  3724. AddImageFile(blob);
  3725. }
  3726. }
  3727. for(i=0;i<input.files.length;i++){
  3728. if(input.files[i].size){
  3729. let reader = new FileReader();
  3730. reader.onload = ff(input.files[i]);
  3731. reader.readAsArrayBuffer(input.files[i]);
  3732. }
  3733. }
  3734. });
  3735. function generateUID() {
  3736. var firstPart = (Math.random() * 46656) | 0;
  3737. var secondPart = (Math.random() * 46656) | 0;
  3738. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3739. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3740. return firstPart + secondPart;
  3741. }
  3742. document.onpaste = pastehandler;
  3743. function dropHandler(ev) {
  3744. put = document.querySelector("#_uploader");
  3745. if(put) ShowSideUploader();
  3746. bkg=document.querySelector('#dropping_background');
  3747. bkg.style.display="none";
  3748. console.log('File(s) dropped');
  3749. ev.preventDefault();ev.stopPropagation();
  3750. if (ev.dataTransfer && ev.dataTransfer.items) {
  3751. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3752. if (ev.dataTransfer.items[i].kind === 'file') {
  3753. var file = ev.dataTransfer.items[i].getAsFile();
  3754. function ff(file){
  3755. return function(e){
  3756. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3757. blob.name = file.name;
  3758. AddImageFile(blob);
  3759. }
  3760. }
  3761. if(file){
  3762. let reader = new FileReader();
  3763. reader.onload = ff(file);
  3764. reader.readAsArrayBuffer(file);
  3765. }
  3766. }
  3767. }
  3768. } else {
  3769. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3770. function ff(file){
  3771. return function(e){
  3772. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3773. blob.name = file.name;
  3774. AddImageFile(blob);
  3775. }
  3776. }
  3777. if(ev.dataTransfer.files[i].size){
  3778. let reader = new FileReader();
  3779. reader.onload = ff(ev.dataTransfer.files[i]);
  3780. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3781. }
  3782. }
  3783. }
  3784. }
  3785. function dragOverHandler(ev) {
  3786. bkg=document.querySelector('#dropping_background');
  3787. bkg.style.display="";
  3788. console.log('File(s) in drop zone');
  3789. ev.preventDefault();
  3790. }
  3791. </script>
  3792. <?php
  3793. }
  3794. function CanShowGallery(&$g){
  3795. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  3796. return true;
  3797. }
  3798. function CanShowImage(&$im){
  3799. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3800. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3801. }
  3802. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3803. return true;
  3804. }
  3805. function MakeGallerySection(){
  3806. if(!isset($_GET['gallery'])) return;
  3807. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3808. $name=$_GET['gallery'];}?>
  3809. <script>
  3810. document.title+=" | <?=$this->T('画廊')?>";
  3811. </script>
  3812. <div class='center_wide' id='div_center' style='position:relative;'>
  3813. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3814. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3815. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3816. <div class='hidden_on_desktop'>
  3817. <?=$this->T('前往')?>
  3818. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  3819. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3820. if(!isset($g['featured']) || !$g['featured'] ||
  3821. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3822. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3823. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3824. <?php } ?>
  3825. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  3826. <?php if($this->LoggedIn){ ?>
  3827. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  3828. <?php } ?>
  3829. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3830. if((isset($g['featured']) && $g['featured']) ||
  3831. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3832. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3833. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3834. <?php } ?>
  3835. </select>
  3836. </div>
  3837. <?php if($this->LoggedIn){?>
  3838. <div>
  3839. <?php if(isset($name)){ ?>
  3840. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  3841. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  3842. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  3843. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  3844. <?=$this->T('取消精选')?></a>
  3845. <?php }else{ ?>
  3846. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  3847. <?=$this->T('设为精选')?></a>
  3848. <?php } ?><br />
  3849. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  3850. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  3851. <?=$this->T('取消实验')?></a>
  3852. <?php }else{ ?>
  3853. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  3854. <?=$this->T('设为实验')?></a>
  3855. <?php } ?>
  3856. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  3857. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  3858. <a href='javascript:HidePopMenu();'>×</a>
  3859. <hr />
  3860. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  3861. </div>
  3862. </div>
  3863. <?php } ?>
  3864. <?php $this->MakeUploader(false); ?>
  3865. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  3866. <div style='position:relative'>
  3867. <?php if(isset($name)){ ?>
  3868. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  3869. <?php } ?>
  3870. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  3871. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  3872. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  3873. method="post" style='display:none;' id='gallery_edit_form'></form>
  3874. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  3875. <a href='javascript:HidePopMenu();'>×</a>
  3876. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  3877. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  3878. <input class='button' type='submit' form='gallery_edit_form'
  3879. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  3880. </div>
  3881. </div>
  3882. </div>
  3883. <div class='smaller hidden_on_print'>
  3884. <form action="<?=$_SERVER['REQUEST_URI']?>"
  3885. method="post" style='display:none;' id='gallery_move_form'></form>
  3886. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  3887. id='gallery_move_ops' style='display:none'>
  3888. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  3889. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  3890. <p><?=$this->T('添加到')?>
  3891. <select id="gallery_move_to">
  3892. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3893. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3894. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  3895. <?php } ?>
  3896. </select>
  3897. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  3898. </p>
  3899. <p>
  3900. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  3901. </p>
  3902. </div>
  3903. </div>
  3904. <?php } ?>
  3905. <p>&nbsp;</p>
  3906. <div>
  3907. <?php $opened=0; $prev_year=""; if(isset($this->Images[0])) foreach($this->Images as $im){
  3908. if(!$this->CanShowImage($im)){ continue; }
  3909. if($_GET['gallery']=='trash') $name='trash';
  3910. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;}
  3911. $year = substr($im['name'], 0, 4);
  3912. if($year!=$prev_year){
  3913. if($opened) { ?><div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div></div><?php } ?>
  3914. <div><h2 class='sticky_title'><?=$year;?></h2><div class='p_row'><?php $prev_year=$year; $opened=1; } ?>
  3915. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  3916. <?php if($this->LoggedIn){ ?>
  3917. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3918. <?php } ?>
  3919. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  3920. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  3921. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  3922. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>/></a>
  3923. </div>
  3924. <?php } if($opened) { ?>
  3925. <div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div><?php } ?>
  3926. </div>
  3927. </div>
  3928. <?php if($this->LoggedIn){ ?>
  3929. <script type='text/javascript'>
  3930. var selected_image = new Array();
  3931. function RemoveFromGallery(){
  3932. form = document.querySelector('#gallery_move_form');
  3933. ops = document.querySelector('#gallery_move_ops');
  3934. sel = document.querySelector('#gallery_move_to');
  3935. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  3936. form.submit();
  3937. }
  3938. function AddToGallery(){
  3939. form = document.querySelector('#gallery_move_form');
  3940. ops = document.querySelector('#gallery_move_ops');
  3941. sel = document.querySelector('#gallery_move_to');
  3942. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  3943. form.submit();
  3944. }
  3945. function ClearSelectedImages(){
  3946. selected_image.splice(0, selected_image.length);
  3947. checks = document.querySelectorAll('._select_hook');
  3948. [].forEach.call(checks, function(c){
  3949. c.classList.remove('p_thumb_selected');
  3950. });
  3951. count = document.querySelector('#gallery_selected_count');
  3952. count.innerHTML="0";
  3953. }
  3954. function ToggleSelectImage(elem, name){
  3955. count = document.querySelector('#gallery_selected_count');
  3956. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  3957. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  3958. count.innerHTML=selected_image.length.toString()
  3959. }
  3960. function ShowGalleryEditMenu(old_name){
  3961. m = document.querySelector('#gallery_edit_menu');
  3962. old = document.querySelector('#gallery_edit_old_name');
  3963. newname = document.querySelector('#gallery_edit_new_name');
  3964. m.style.display='block';
  3965. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  3966. }
  3967. function ShowDeleteMenu(){
  3968. m=document.querySelector('#gallery_delete_menu');
  3969. m.style.display='block';
  3970. }
  3971. </script>
  3972. <?php } ?>
  3973. <?php
  3974. }
  3975. function MakeGalleryLeft(){?>
  3976. <div class='left hidden_on_mobile gallery_left' id='div_left'>
  3977. <h2><?=$this->T('相册')?></h2>
  3978. <div>
  3979. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  3980. <ul>
  3981. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3982. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  3983. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3984. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  3985. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3986. <?php } ?>
  3987. </ul>
  3988. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  3989. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  3990. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  3991. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3992. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  3993. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3994. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  3995. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3996. <?php } ?>
  3997. <?php if($this->LoggedIn){ ?>
  3998. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  3999. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  4000. <?php } ?>
  4001. </ul></div>
  4002. <p>&nbsp;</p>
  4003. <script>
  4004. </script>
  4005. </div>
  4006. </div>
  4007. <?php
  4008. }
  4009. function MakeTOC(){?>
  4010. <div class='right hidden_on_mobile' id='div_right'>
  4011. <?php if(isset($this->Anchors[0])){?>
  4012. <h2><?=$this->T('目录')?></h2><ul>
  4013. <?php
  4014. foreach($this->Anchors as $a){?>
  4015. <li class='toc_entry_<?=$a[0]>5?5:$a[0]?>'><a href='#<?=$a[1]?>'>
  4016. <?=$this->T($this->ChoosePartsByLanguage($a[2]))?></a></li>
  4017. <?php }
  4018. ?></ul>
  4019. <?php }else{ ?>
  4020. <h2 class='gray'><?=$this->T('目录')?></h2>
  4021. <span class='gray smaller'><?=$this->T('未找到目录')?></span>
  4022. <?php } ?>
  4023. </div>
  4024. <?php
  4025. }
  4026. function MakeSettings(){?>
  4027. <div class='settings'>
  4028. <h2><?=$this->T('设置')?></h2>
  4029. <table style='white-space:nowrap;'>
  4030. <?php if($this->LoggedIn){ ?>
  4031. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4032. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4033. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4034. <tr><td><?=$this->T('网站标题')?></td>
  4035. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4036. value='<?=$this->Title?>'/></td></tr>
  4037. <tr><td><?=$this->T('短标题')?></td>
  4038. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4039. value='<?=$this->ShortTitle?>'/></td></tr>
  4040. <tr><td><?=$this->T('显示名称')?></td>
  4041. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4042. value='<?=$this->DisplayName?>'/></td></tr>
  4043. <tr><td><?=$this->T('电子邮件')?></td>
  4044. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4045. value='<?=$this->EMail?>'/></td></tr>
  4046. <tr><td><?=$this->T('导航栏')?>
  4047. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4048. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4049. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4050. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4051. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4052. value='<?=$this->SpecialFooter?>'/></td></tr>
  4053. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4054. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4055. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4056. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4057. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4058. value='<?=$this->SpecialPinned?>'/></td></tr>
  4059. <tr><td><?=$this->T('默认相册')?></td>
  4060. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4061. value='<?=$this->DefaultGallery?>'/></td></tr>
  4062. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4063. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4064. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4065. <tr><td><?=$this->T('启用评论')?></td>
  4066. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4067. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4068. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  4069. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4070. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4071. <tr><td><?=$this->T('长毛象实例')?></td>
  4072. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4073. value='<?=$this->MastodonURL?>'/></td></tr>
  4074. <tr><td><?=$this->T('长毛象令牌')?></td>
  4075. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4076. value='<?=$this->MastodonToken?>'/></td></tr>
  4077. <tr><td><?=$this->T('偏好语言')?></td>
  4078. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4079. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4080. <tr><td><?=$this->T('本站地址')?></td>
  4081. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4082. value='<?=$this->HostURL?>'/></td></tr>
  4083. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4084. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4085. <tr><td><?=$this->T('用户名')?></td>
  4086. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4087. value='<?=$this->APubID?>'/></td></tr>
  4088. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4089. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4090. <tr><td><?=$this->T('主机')?></td>
  4091. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4092. value='<?=$this->HereHost?>'/></td></tr>
  4093. <tr><td><?=$this->T('网站标题')?></td>
  4094. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4095. value='<?=$this->HereTitle?>'/></td></tr>
  4096. <tr><td><?=$this->T('短标题')?></td>
  4097. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4098. value='<?=$this->HereShortTitle?>'/></td></tr>
  4099. <tr><td><?=$this->T('相册')?></td>
  4100. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4101. value='<?=$this->HereAlbum?>'/></td></tr>
  4102. <tr><td><?=$this->T('导航栏')?>
  4103. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4104. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4105. value='<?=$this->HereNavigation?>'/></td></tr>
  4106. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4107. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4108. value='<?=$this->HereFooter?>'/></td></tr>
  4109. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4110. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4111. <tr><td><?=$this->T('主机')?></td>
  4112. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4113. value='<?=$this->ExpHost?>'/></td></tr>
  4114. <tr><td><?=$this->T('网站标题')?></td>
  4115. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4116. value='<?=$this->ExpTitle?>'/></td></tr>
  4117. <tr><td><?=$this->T('短标题')?></td>
  4118. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4119. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4120. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4121. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4122. value='<?=$this->ExpCaution?>'/></td></tr>
  4123. <tr><td><?=$this->T('相册')?></td>
  4124. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4125. value='<?=$this->ExpAlbum?>'/></td></tr>
  4126. <tr><td><?=$this->T('导航栏')?>
  4127. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4128. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4129. value='<?=$this->ExpNavigation?>'/></td></tr>
  4130. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4131. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4132. value='<?=$this->ExpFooter?>'/></td></tr>
  4133. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4134. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4135. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  4136. <tr><td><?=$this->T('帐号')?></td>
  4137. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4138. value='<?=$this->Admin?>'/></td></tr>
  4139. <tr><td><?=$this->T('新密码')?></td>
  4140. <td><input type="password" form="settings_form"
  4141. id='settings_new_password' name='settings_new_password' /></td></tr>
  4142. <tr><td><?=$this->T('再次输入')?></td>
  4143. <td><input type="password" form="settings_form"
  4144. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4145. <tr><td><?=$this->T('旧密码')?></td>
  4146. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4147. <?php }else{ ?>
  4148. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4149. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4150. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4151. <tr><td><?=$this->T('帐号')?></td>
  4152. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4153. <tr><td><?=$this->T('密码')?></td>
  4154. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4155. <?php } ?>
  4156. </table>
  4157. <?php if($this->LoggedIn){ ?>
  4158. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4159. <?php }else{ ?>
  4160. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4161. <?php } ?>
  4162. </div>
  4163. <?php
  4164. }
  4165. function MakeExtraOperations(){?>
  4166. <div class='settings' style='overflow:auto;'>
  4167. <h2><?=$this->T('附加操作')?></h2>
  4168. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  4169. <p>&nbsp;</p>
  4170. <h3><?=$this->T('自动重定向')?></h3>
  4171. <span class='smaller gray'>
  4172. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4173. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4174. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4175. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  4176. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4177. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4178. value='<?=$this->T('保存重定向设置')?>' />
  4179. <p>&nbsp;</p>
  4180. <h3><?=$this->T('自定义翻译')?></h3>
  4181. <span class='smaller gray'>
  4182. <?=$this->T('填写格式:')?>
  4183. <br /><pre>- 语言 | Language</pre></span>
  4184. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4185. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  4186. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4187. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4188. value='<?=$this->T('保存翻译')?>' />
  4189. <p>&nbsp;</p>
  4190. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4191. <ul>
  4192. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  4193. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  4194. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  4195. </ui>
  4196. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4197. </div>
  4198. <?php
  4199. }
  4200. function MakeMainBegin(){?>
  4201. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4202. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4203. <?php
  4204. }
  4205. function MakeMainEnd(){?>
  4206. </div>
  4207. <?php
  4208. }
  4209. function MakeExpFooter(){?>
  4210. <div class='small_footer exp_h_f exp_f'><div>
  4211. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b>&nbsp;©<?=$this->T($this->DisplayName)?>
  4212. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4213. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4214. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4215. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4216. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4217. }?></div>
  4218. </div>
  4219. </div>
  4220. </div><!-- page -->
  4221. </body>
  4222. </html>
  4223. <script>
  4224. if(trans = document.getElementById('translate_button')){
  4225. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4226. }
  4227. </script>
  4228. <?php
  4229. }
  4230. function MakeImageOverlay($side_info=null,$static_image=null){
  4231. $static=isset($side_info); ?>
  4232. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  4233. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  4234. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  4235. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/>
  4236. </div>
  4237. <div class='big_side_box' onclick='HideBigImage(1);'>
  4238. <?php if(!$static){ ?>
  4239. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  4240. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  4241. <div class='lr_buttons'>←</div></a></div>
  4242. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  4243. <div class='lr_buttons'>→</div></a></div>
  4244. <div id='here_buttons'></div>
  4245. </div><?php } ?>
  4246. <div class='side_box_mobile_inner'>
  4247. <?php if(!$static){ ?>
  4248. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  4249. <span style='display:none;' id='image_purchase' class='clean_a'>
  4250. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  4251. <br class='hidden_on_desktop block_on_mobile' /></span>
  4252. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  4253. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4254. &nbsp;<a class='clean_a' id='image_inquiry'>
  4255. <b>@</b><?=$this->T('咨询')?></a>
  4256. <?php } ?><hr class='hidden_on_desktop block_on_mobile' />
  4257. </div>
  4258. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  4259. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  4260. <hr />
  4261. </div><?php } //static ?>
  4262. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  4263. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  4264. <br /><?=$this->T('印刷品链接')?>
  4265. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  4266. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  4267. <?=$this->T('重命名')?>
  4268. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  4269. <?=$this->T('主图')?>
  4270. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  4271. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  4272. <br /><br /><?=$this->T('替换图像')?>
  4273. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  4274. <input type="file" form='image_edit_form'
  4275. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  4276. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  4277. value=<?=$this->T('执行')?> />
  4278. </div><?php } ?>
  4279. </div>
  4280. </div>
  4281. </div>
  4282. <?php }
  4283. function MakePageEnd(){?>
  4284. </div><!-- page -->
  4285. </body>
  4286. </html>
  4287. <?php }
  4288. function MakeFooter(){?>
  4289. <div class='small_footer'><div>
  4290. <hr />
  4291. <b><?=$this->T($this->Title)?></b>
  4292. <span onclick='event.stopPropagation()'
  4293. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  4294. <div class='wayback_link clean_a invert_a hidden_on_print'><?php if(!isset($this->WayBack)){ ?>
  4295. - <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  4296. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?>
  4297. <br class='hidden_on_desktop' /> - <a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  4298. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a>
  4299. <br class='hidden_on_desktop' />
  4300. - <a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a>
  4301. </div>
  4302. </div></div>
  4303. <div class='footer'>
  4304. <div style='white-space:nowrap;'>
  4305. <div class='footer_additional'>
  4306. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  4307. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4308. } ?>
  4309. </div>
  4310. <div class='footer_additional'>
  4311. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  4312. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4313. } ?>
  4314. </div>
  4315. </div>
  4316. </div>
  4317. <p>&nbsp;<p>
  4318. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  4319. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  4320. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  4321. </div>
  4322. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  4323. <script>
  4324. <?=$this->ExtraScripts?>
  4325. if(back = document.getElementById('button_back')){
  4326. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  4327. back.href='javascript:history.back()';
  4328. }else{
  4329. back.href='index.php';
  4330. }
  4331. }
  4332. function copy_text(t) {
  4333. ta = document.createElement('textarea');
  4334. document.body.appendChild(ta);
  4335. ta.value = t;
  4336. ta.select();
  4337. document.execCommand("copy");
  4338. document.body.removeChild(ta);
  4339. }
  4340. if(trans = document.getElementById('translate_button')){
  4341. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4342. }
  4343. <?php if($this->LoggedIn){ ?>
  4344. var Scenter = document.querySelector('#div_center');
  4345. var Sposts = Scenter.querySelectorAll('.post');
  4346. <?php if(isset($this->MastodonToken)){ ?>
  4347. function MarkPostDoneMastodon(id,mastodon_url){
  4348. for(var i=0;i<Sposts.length;i++){
  4349. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  4350. }
  4351. <?php } ?>
  4352. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  4353. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  4354. var Smerge_post = Scenter.querySelector('#merge_post');
  4355. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  4356. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  4357. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  4358. var Smerge_select = Scenter.querySelector('#merge_select');
  4359. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  4360. var Smerge_thread = Scenter.querySelector('#merge_thread');
  4361. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  4362. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  4363. var select_mode = false; var merge_mode = false; var selected_posts = null;
  4364. function TogglePostSelectMode(force_on=false,force_off=false){
  4365. Scenter.classList.add('post_selecting');
  4366. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  4367. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  4368. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  4369. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  4370. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  4371. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4372. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  4373. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  4374. Smerge_post_count.innerText="0";
  4375. Smerge_post.href="#";
  4376. }
  4377. function TogglePostSelect(elem){
  4378. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  4379. else{ elem.classList.add('post_selected'); }
  4380. selected_posts = new Array();
  4381. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  4382. selected_posts.push(Sposts[i].dataset.postId); } }
  4383. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  4384. Smerge_post_count.innerText=selected_posts.length;
  4385. }
  4386. function ThreadMergeInput(elem){
  4387. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  4388. else{ Smerge_thread.href="#"; }
  4389. }
  4390. function ToggleThreadMerge(force_on=false,force_off=false){
  4391. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  4392. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  4393. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  4394. else{ merge_mode = 0;
  4395. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  4396. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4397. Smerge_thread.href="#";
  4398. Smerge_thread_target.value='';
  4399. }
  4400. <?php } ?>
  4401. function ShowSideUploader(){
  4402. ShowRightSide(true,null);
  4403. put = document.querySelector("#_uploader");
  4404. put.style.display='block';
  4405. RefreshSideGallery();
  4406. }
  4407. dmark = document.querySelector("#mark_details");
  4408. drename = document.querySelector("#rename_details");
  4409. dmastodon = document.querySelector("#mastodon_details");
  4410. drename_form = document.querySelector("#post_rename_form");
  4411. drename_input = document.querySelector("#post_rename_name");
  4412. var rp = document.querySelector('#post_reply_to');
  4413. var _reply_to = rp?rp.defaultValue:"";
  4414. function RestoreReply(){
  4415. if(rp){
  4416. rp.defaultValue = _reply_to;
  4417. }
  4418. document.querySelector('#post_reply_restore').style.display='none';
  4419. ht = document.querySelector('#post_hint_text');
  4420. if (_reply_to!=""){
  4421. ht.style.display='block';
  4422. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  4423. }else{
  4424. ht.style.display='none';
  4425. }
  4426. document.querySelector('#post_edit_target').value="";
  4427. ch = document.querySelector('#post_hint_modify');
  4428. ch.style.display='none';
  4429. }
  4430. function MakeRefer(id){
  4431. t = document.querySelector('#post_content')
  4432. t.focus();
  4433. v = t.value;
  4434. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  4435. la_auto_grow(t);
  4436. if(rp){
  4437. rp.defaultValue = "";
  4438. ht = document.querySelector('#post_hint_text');
  4439. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  4440. document.querySelector('#post_reply_restore').style.display='inline';
  4441. rs = document.querySelector('#post_reply_restore');
  4442. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  4443. document.getElementById('post_menu').style.display='none';
  4444. ch = document.querySelector('#post_hint_modify');
  4445. ch.style.display='none';
  4446. }
  4447. }
  4448. function CopyRefer(id){
  4449. copy_text(id.toString());
  4450. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  4451. }
  4452. function MakeEdit(id){
  4453. ed = document.getElementById('menu_edit');
  4454. ed.innerHTML="<?=$this->T('稍等')?>";
  4455. ed.href="#";
  4456. var xhr = new XMLHttpRequest();
  4457. xhr.onreadystatechange = function() {
  4458. if (this.readyState == 4 && this.status == 200) {
  4459. ed.innerHTML='——';
  4460. ch = document.querySelector('#post_hint_modify');
  4461. ch.style.display='block';
  4462. ht = document.querySelector('#post_hint_text');
  4463. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  4464. rs = document.querySelector('#post_reply_restore');
  4465. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  4466. t = document.querySelector('#post_content');
  4467. t.value=xhr.responseText.trim();
  4468. t.focus();
  4469. la_auto_grow(t);
  4470. document.querySelector('#post_edit_target').value=id;
  4471. document.getElementById('post_menu').style.display='none';
  4472. }
  4473. };
  4474. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4475. xhr.send();
  4476. }
  4477. function MarkDelete(id){
  4478. p = document.querySelector('[data-post-id="'+id+'"]');
  4479. op = p.dataset.markDelete?"false":"true";
  4480. window.location.href=
  4481. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4482. }
  4483. function SetMark(mark){
  4484. menu = document.getElementById('post_menu');
  4485. window.location.href=
  4486. "index.php?<?=$this->GetRedirect()?>&target="+
  4487. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4488. }
  4489. function ToggleMarkDetails(){
  4490. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  4491. drename.style.display=dmastodon.style.display='none';
  4492. }
  4493. function ToggleRenameDetails(){
  4494. drename.style.display=(drename.style.display=='block')?'none':'block';
  4495. dmark.style.display=dmastodon.style.display='none';
  4496. }
  4497. function ToggleMastodonDetails(){
  4498. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  4499. dmark.style.display=drename.style.display='none';
  4500. }
  4501. <?php } ?>
  4502. function ShowPostMenu(post){
  4503. menu = document.getElementById('post_menu');
  4504. menu.style.display='block';
  4505. menu.parentNode.removeChild(menu);
  4506. post.appendChild(menu);
  4507. menu.style.display='block';
  4508. id = post.dataset.postId
  4509. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4510. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4511. window.onClick="HidePopMenu()";
  4512. menu.onClick=(function(event){
  4513. event.stopPropagation();
  4514. });
  4515. hs = menu.querySelector('#menu_history');
  4516. hs.href='?post='+id+'&history=1';
  4517. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4518. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4519. ref = menu.querySelector('#menu_refer_copy')
  4520. ref.innerHTML='<?=$this->T("复制编号")?>';
  4521. ref.href='javascript:CopyRefer(id)';
  4522. ed = menu.querySelector('#menu_edit')
  4523. ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4524. d = menu.querySelector('#menu_delete');
  4525. d.href='javascript:MarkDelete(\"'+id+'\")';
  4526. p = document.querySelector('[data-post-id="'+id+'"]');
  4527. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4528. menu.querySelector('#mark_details').dataset.id=id;
  4529. drename_input.value=id;
  4530. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4531. <?php if(isset($this->MastodonToken)){ ?>
  4532. dmastodon_form = document.querySelector("#post_mastodon_form");
  4533. dmastodon_form.action='?mastodon_post='+id;
  4534. function MastodonSend(id){
  4535. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  4536. var xhr = new XMLHttpRequest();
  4537. function wrapidxhr(_id) { return function() {
  4538. if (this.readyState == 4 && this.status == 200) {
  4539. var response = xhr.responseText;
  4540. let content="";
  4541. if(res = response.match(/SUCCESS (\S+)/u)){
  4542. content="<?=$this->T('成功发送到长毛象')?>";
  4543. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  4544. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  4545. MarkPostDoneMastodon(_id, res[1]);
  4546. } }
  4547. };
  4548. xhr.onreadystatechange = wrapidxhr(id);
  4549. xhr.open("GET", "index.php?mastodon_send_post="+id, true); xhr.send();
  4550. }
  4551. menu_mastodon = menu.querySelector("#menu_mastodon");
  4552. mastodon_send = menu.querySelector("#menu_mastodon_send");
  4553. mastodon_view = menu.querySelector("#menu_mastodon_view");
  4554. mastodon_url = menu.querySelector("#post_mastodon_url");
  4555. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  4556. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  4557. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  4558. mastodon_url.value="";}
  4559. mastodon_send.onclick=function(){
  4560. this.onclick=function(){};
  4561. MastodonSend(id); };
  4562. <?php } } ?>
  4563. title = document.title;
  4564. copy = document.getElementById('share_copy');
  4565. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4566. copy.addEventListener("click", function(){
  4567. url = window.location
  4568. path = location.pathname
  4569. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4570. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4571. });
  4572. }
  4573. function HidePopMenu(){
  4574. var menus = document.querySelectorAll('.pop_menu');
  4575. [].forEach.call(menus, function(m){m.style.display='none';});
  4576. }
  4577. var posts = document.querySelectorAll('.center .post');
  4578. [].forEach.call(posts, function(p){
  4579. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4580. ShowPostMenu(this.parentNode.parentNode);
  4581. });
  4582. });
  4583. var post_clickables = document.querySelectorAll('.center .post a');
  4584. [].forEach.call(post_clickables, function(p){
  4585. p.addEventListener("click", function(event){
  4586. event.stopPropagation();
  4587. });
  4588. });
  4589. function FindImage(imgsrc){
  4590. for(var i=0;i<document.images_filtered.length;i++){
  4591. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4592. }
  4593. return null
  4594. }
  4595. var dottime1;
  4596. var dottime2;
  4597. function ToDataURL(url) {
  4598. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4599. clearTimeout(dottime1);clearTimeout(dottime2);
  4600. ps = document.querySelector('#download_processing');
  4601. ps.innerHTML='↓';ps.style.opacity='';
  4602. return URL.createObjectURL(blob);});
  4603. }
  4604. async function DownloadAsImage(url,name) {
  4605. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4606. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4607. }
  4608. function basename(url){return url.split(/[\\/]/).pop();}
  4609. pushed=0;
  4610. function ShowBigImage(imgsrc,do_push){
  4611. ShowWaitingBar();
  4612. share = document.querySelector('#big_image_share');
  4613. img = document.querySelector('#big_image');
  4614. down = document.querySelector('#image_download');
  4615. img.src = "";
  4616. img.src = src = "images/"+imgsrc;
  4617. down.href="images/"+imgsrc;
  4618. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_+<?=$this->GiveSafeEMail()?>+_'+
  4619. basename(down.href);
  4620. img.alt = downname; down.download=downname;
  4621. var use_href = "images/"+imgsrc;
  4622. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4623. ps = this.querySelector('#download_processing');ps.innerText='…';
  4624. var dotwait = function(ps){ var self = this;
  4625. dottime1 = setTimeout(function(ps){
  4626. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4627. dotwait(this.querySelector('#download_processing'));
  4628. DownloadAsImage(use_href,downname);};
  4629. if(do_push){PushGalleryHistory(src)}
  4630. page_url = encodeURIComponent(window.location.href);
  4631. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4632. inqb = document.querySelector('#image_inquiry');
  4633. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4634. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4635. (page_url)+encodeURIComponent('\n\n');
  4636. <?php } ?>
  4637. this_image = FindImage(imgsrc);
  4638. if(this_image&&this_image.dataset.prevsrc){
  4639. new_image = FindImage(this_image.dataset.prevsrc);
  4640. new_prev = new_image?new_image.dataset.prevsrc:null;
  4641. im = document.querySelector('#prev_image');
  4642. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4643. else {im.style.opacity='0';im.removeAttribute("href");}
  4644. }
  4645. if(this_image&&this_image.dataset.nextsrc){
  4646. new_image = FindImage(this_image.dataset.nextsrc);
  4647. new_next = new_image?new_image.dataset.nextsrc:null;
  4648. im = document.querySelector('#next_image');
  4649. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4650. else {im.style.opacity='0';im.removeAttribute("href");}
  4651. }
  4652. purchase = document.querySelector('#image_purchase');
  4653. purchase_btn = document.querySelector('#image_purchase_button');
  4654. <?php if($this->LoggedIn){ ?>
  4655. product_link = document.querySelector('#image_ops_product_link');
  4656. product_form = document.querySelector('#image_ops_form');
  4657. edit_form = document.querySelector('#image_edit_form');
  4658. edit_new_name = document.querySelector('#image_edit_new_name');
  4659. edit_parent = document.querySelector('#image_parent');
  4660. product_form.action = window.location.href;
  4661. edit_form.action = window.location.href;
  4662. edit_new_name.value = imgsrc.split('.')[0];
  4663. if(this_image&&this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  4664. if(this_image&&this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  4665. <?php } ?>
  4666. if(this_image&&this_image.dataset.product){
  4667. purchase.style.display='';
  4668. href = this_image.dataset.product;
  4669. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4670. href = '?post='+href;
  4671. }
  4672. purchase_btn.href = href;
  4673. }else{
  4674. purchase.style.display='none';
  4675. purchase_btn.removeAttribute("href");
  4676. }
  4677. DelayHideImgBtn(null);
  4678. title = encodeURIComponent(document.title);
  4679. copy = document.getElementById('big_share_copy');
  4680. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4681. copy.addEventListener("click", function(){
  4682. copy_text(window.location.href);
  4683. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4684. });
  4685. o = document.querySelector('#big_image_overlay');
  4686. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  4687. here = document.querySelector('#here_buttons');here.innerHTML='';
  4688. o.style.display="block";
  4689. ShowBackdrop(0.8);
  4690. var xhr = new XMLHttpRequest();
  4691. xhr.onreadystatechange = function() {
  4692. if (this.readyState == 4 && this.status == 200) {
  4693. info = document.querySelector('#big_image_info');
  4694. var response = xhr.responseText;
  4695. let content=""
  4696. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4697. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4698. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4699. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4700. content+="<div class='clean_a'>"+res[1]+"</div>"; }
  4701. info.innerHTML=content;
  4702. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  4703. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  4704. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  4705. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  4706. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  4707. }
  4708. }
  4709. };
  4710. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4711. xhr.send();
  4712. }
  4713. function HideBigImage(do_push){
  4714. o = document.querySelector('#big_image_overlay');
  4715. img = document.querySelector('#big_image');
  4716. img.src = "";
  4717. if(o.style.display!='none'){
  4718. o.style.display="none";
  4719. HideBackdrop();
  4720. if(do_push){PushGalleryHistory("");}
  4721. HideWaitingBar();
  4722. }
  4723. }
  4724. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4725. var inq=document.querySelector('#inquiry_buttons');
  4726. var overlay=document.querySelector('#big_image_overlay');
  4727. var hide_timeout;
  4728. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4729. function DelayHideImgBtn(e){
  4730. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  4731. inq.classList.remove('img_btn_hidden');
  4732. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  4733. clearTimeout(hide_timeout);
  4734. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  4735. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  4736. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  4737. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  4738. }
  4739. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4740. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4741. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4742. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4743. var images = document.querySelectorAll('img');
  4744. var images_filtered=new Array(); var imgadded = new Array();
  4745. var images_remaining=new Array();
  4746. [].forEach.call(images, function(img){
  4747. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4748. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4749. images_filtered.push(img);imgadded.push(imgsrc);
  4750. });
  4751. for(var i=0; i<images_filtered.length; i++){
  4752. previmg = nextimg = null; img = images_filtered[i];
  4753. if(i>0) previmg=images_filtered[i-1];
  4754. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4755. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4756. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4757. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4758. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4759. }
  4760. for(var i=0; i<images_remaining.length; i++){
  4761. img = images_remaining[i];
  4762. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4763. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4764. }
  4765. document.images_filtered = images_filtered;
  4766. function PopGalleryHistory(){
  4767. if(pushed){
  4768. pushed = 0;
  4769. try{
  4770. history.back();
  4771. }catch{
  4772. console.log("can't do it.");
  4773. }
  4774. }
  4775. }
  4776. function PushGalleryHistory(src){
  4777. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  4778. title = "照片"
  4779. extra = "?";
  4780. sp = new URLSearchParams(window.location.search)
  4781. if(sp.has('post')){extra+="post="+sp.get('post')}
  4782. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  4783. try{
  4784. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  4785. }catch{
  4786. console.log("can't do it.");
  4787. }
  4788. pushed = 1;
  4789. }
  4790. document.addEventListener('keydown', function(e){
  4791. large = document.getElementById('big_image_overlay')
  4792. if (large.style.display!='block') return;
  4793. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  4794. HideBigImage(1);
  4795. }
  4796. }, true);
  4797. window.addEventListener('popstate', (event) => {
  4798. if(event.state){
  4799. let sp = new URLSearchParams(event.state)
  4800. if(sp.has('pic')){
  4801. src = sp.get('pic')
  4802. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)) ShowBigImage(onlyimg[0], 0);
  4803. else{HideBigImage(0);}
  4804. }
  4805. }else{HideBigImage(0);}
  4806. });
  4807. let searchParams = new URLSearchParams(window.location.search)
  4808. if(searchParams.has('pic')){
  4809. src = searchParams.get('pic')
  4810. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)){
  4811. ShowBigImage(onlyimg[0], 1);
  4812. }
  4813. }
  4814. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  4815. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  4816. </script>
  4817. </body>
  4818. <?php
  4819. }
  4820. function DoIdentiyExperimental(){
  4821. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  4822. $this->InExperimentalMode=True; $this->InHereMode=True;
  4823. }
  4824. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  4825. $this->InHereMode=True;
  4826. }
  4827. }
  4828. function DoExperimentalTopLink($p){
  4829. if($this->InHereMode && $p){
  4830. if(isset($p['tid']) && $p['tid']['first']!=$p){
  4831. header('Location: ?post='.$p['tid']['first']['id']); exit();
  4832. }
  4833. }
  4834. }
  4835. function MakeExperimentalConfirm(){
  4836. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  4837. return false;
  4838. }
  4839. $caution_html =
  4840. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  4841. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  4842. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  4843. ?>
  4844. <div class='center_exp'><?php
  4845. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  4846. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  4847. ?></div>
  4848. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  4849. <?php return true;
  4850. }
  4851. }
  4852. $la = new LA;
  4853. $la->DoSiteRedirect();
  4854. $la->DoLogin();
  4855. $la->SwitchLanguageAndFont();
  4856. $err = $la->ProcessRequest($message, $redirect);
  4857. $la->WriteAsNecessary();
  4858. $la->DoIdentiyExperimental();
  4859. $la->SwitchWayBackMode();
  4860. if($err){
  4861. echo $message;
  4862. exit();
  4863. }
  4864. if(isset($redirect)){
  4865. header('Location: '.$redirect);
  4866. exit();
  4867. }
  4868. $la->DetectPageType();
  4869. $la->ReadImages(false);
  4870. $la->ReadPosts();
  4871. if(isset($la->WayBack)){
  4872. $la->ReadArchive();
  4873. }
  4874. $im = NULL;
  4875. if(preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  4876. if(!$la->CanShowImage($im)) { $im=&$la->NULL_IMAGE; }
  4877. }
  4878. $p = &$la->GetPost($la->CurrentPostID);
  4879. if(!isset($p)){
  4880. $p = &$la->GetMergedPost($la->CurrentPostID);
  4881. }
  4882. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  4883. else{ $la->DoExperimentalTopLink($p); }
  4884. if(isset($p)){ $la->ActualPostID = $p['id']; }
  4885. if($la->PageType=='here' ||$la->PageType=='experimental'){
  4886. if($im){
  4887. $la->SetHereMainImage($im);
  4888. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  4889. }else if($p){
  4890. $la->RecordVisitedHere($p['id'],NULL);
  4891. }else {
  4892. $im = &$la->GiveImageInHere(false);
  4893. if($im){
  4894. $la->SetHereMainImage($im);
  4895. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  4896. }
  4897. }
  4898. }
  4899. $la->MakeHeader($p);
  4900. $la->MakeMainBegin();
  4901. if($la->PageType=='here' ||$la->PageType=='experimental'){
  4902. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  4903. if($im){
  4904. $la->MakeHereSection($im);
  4905. }else if($p){
  4906. $la->MakePostSectionExp($p);
  4907. $la->MakeLinkedPostsExp($p);
  4908. }else {
  4909. if($im){
  4910. $la->MakeHereSection($im);
  4911. }else{
  4912. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4913. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4914. }
  4915. }
  4916. }
  4917. $la->MakeMainEnd();
  4918. $la->MakeExpFooter();
  4919. }else{
  4920. if($la->PageType=='extras'){
  4921. $la->MakeExtraOperations();
  4922. }else if($la->PageType=='settings'){
  4923. $la->MakeSettings();
  4924. }else if($la->PageType=='gallery'){
  4925. $la->MakeGalleryLeft();
  4926. $la->MakeGallerySection();
  4927. }else if($la->PageType=='post'){
  4928. if($p){
  4929. $made_interesting = false;
  4930. if($la->IsInterestingPost($p)){
  4931. $la->MakeInterestingSection($p['tid']);
  4932. }
  4933. else{
  4934. $la->MakeLinkedPosts($p);
  4935. $la->MakePostSection($p);
  4936. $la->MakeTOC();
  4937. }
  4938. }else{
  4939. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4940. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4941. }
  4942. }else if($la->PageType=='history'){
  4943. $la->ReadArchive();
  4944. $la->MakePostHistory($p, $_GET['version']??NULL);
  4945. }else if($la->PageType=='search'){
  4946. $la->MakeHotPosts(true);
  4947. $la->MakeRecentPosts($_GET['search']);
  4948. }else if($la->PageType=='category'){
  4949. $la->MakeHotPosts(true);
  4950. $la->MakeRecentPosts(NULL,$_GET['category']);
  4951. }else if($la->PageType=='comments'){
  4952. $la->MakeCommentPosts();
  4953. }else{
  4954. $la->MakeHotPosts();
  4955. $la->MakeRecentPosts();
  4956. }
  4957. $la->MakeMainEnd();
  4958. $la->MakeFooter();
  4959. }
  4960. ?>