*/}}

index.php 291 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204
  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:sP');
  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,.interesting_tbody .p_thumb video{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,.file_thumb video{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  595. .file_thumb video{border:2px dashed %black%;}
  596. #file_list li{margin-bottom:0.3em;}
  597. .ref_thumb{white-space:nowrap;overflow:hidden;}
  598. .ref_thumb .file_thumb{width:3em;height:3em;}
  599. .side_thumb li{margin:0.4em;display:inline-block;}
  600. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  601. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  602. .p_thumb{display:flex;flex-grow:1;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  603. .p_thumb_narrow{width:1rem;}
  604. .p_thumb img,.p_thumb video{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  605. .ref_count,.p_thumb .post_menu_button{text-shadow: 0px 0px 10px rgb(0, 0, 0);}
  606. .p_thumb:hover .post_menu_button{display:block;}
  607. .p_thumb_selected{color:%black% !important;}
  608. .p_thumb_selected{display:block;}
  609. .post .p_thumb img,.post .p_thumb video{max-height:6rem;}
  610. .p_thumb video{border:2px dashed %black%;}
  611. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  612. .big_image_box *{pointer-events:auto;}
  613. .big_image_box img,.big_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  614. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  615. .here_image_box img,.here_image_box video{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  616. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;pointer-events:none;
  617. background:linear-gradient(to right, rgba(0,0,0,0), rgb(1, 1, 1));transition:background-size .2s linear;background-size: 300% 100%;}
  618. .big_side_box:hover{background-size: 100% 100%;}
  619. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  620. .big_side_box a:hover{color:%gray%;}
  621. .big_side_box *{pointer-events:auto;}
  622. .image_nav{pointer-events:none;}
  623. #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;
  624. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  625. img,video{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  626. .post img,.post video{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  627. .post > a > img,.post > a > video{display:block;margin:0.3em auto;}
  628. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  629. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  630. .center_exp .post .original_img{display:block;}
  631. .original_img img,.original_img video{max-height:90vh;max-width:100%;}
  632. .p_row .original_img{margin-bottom:0;}
  633. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  634. .b ul{font-size:1.4em;}
  635. no_pop{cursor:unset;}
  636. p{min-height:0.8em;}
  637. .bold,.bold *{font-weight:bold;}
  638. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  639. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;}
  640. .small_footer>div{overflow:auto;white-space:nowrap;}
  641. .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;}
  642. .top_post_hint{margin-left:1.5em;font-weight:bold;}
  643. .white{color:%white%;}
  644. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  645. .image_nav_prev,.image_nav_next{z-index:100;position:absolute;line-height:0;height:50%;width:20%;top:25%;display:flex;align-items:center;
  646. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  647. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.2));
  648. background-repeat:no-repeat;background-size:0% 100%;}
  649. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  650. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  651. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  652. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  653. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  654. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  655. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  656. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  657. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  658. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  659. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  660. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  661. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  662. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  663. .special_paypal_inner{color:#169bd7;}
  664. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  665. animation:anim_loading 1s linear infinite;}
  666. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  667. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  668. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  669. .product_thumb img,{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  670. .product_ref p{margin-bottom:0.2em;text-align:left;}
  671. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  672. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  673. .page_break{page-break-after:always;}
  674. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  675. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  676. .print_title{display:none;}
  677. .show_on_print{display:none;}
  678. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  679. .comment tbody tr:hover{box-shadow:none;}
  680. .comment table{border:none;}
  681. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  682. .comment ul{padding-left:1em;}
  683. .comment ul li *{margin-bottom:0.5em;}
  684. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  685. .history li li{list-style:circle;}
  686. .history ul{padding-left:1em;}
  687. .history a{text-decoration:underline;}
  688. .history .list{overflow:auto;white-space:nowrap;}
  689. .diff_table{table-layout:fixed;}
  690. .diff_table thead{font-size:0.9em;text-align:center;}
  691. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  692. .diff_table td{vertical-align:top;}
  693. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  694. .wayback_close{float:right;}
  695. .wayback_expand{display:inline;}
  696. .post_selecting .post *{pointer-events:none;}
  697. .post_selected{background-color:%graybkg%;}
  698. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  699. .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%;}
  700. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  701. .wayback_link{display:inline;}
  702. .imd{object-fit:cover;width:100%;}
  703. .center_exp .imd{width:60%;}
  704. #here_buttons{display:contents;}
  705. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  706. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  707. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  708. .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;}
  709. @media screen and (max-width:1000px) and (min-width:666px){
  710. .left{width:35%;}
  711. .center,.center_wide{width:65%;}
  712. .center_wide .p_thumb{height:8rem;}
  713. .right{display:none;}
  714. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  715. .post_width_big{left:0;width:100%;}
  716. .hidden_on_wide{display:unset;}
  717. .pop_right{width:30%;}
  718. .pop_right_big{width:40%;}
  719. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  720. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  721. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  722. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  723. .big_side_box{width:35%;}
  724. .big_image_box{width:65%;}
  725. .inquiry_buttons{right:35%;}
  726. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  727. .post_dummy > *{width:80%;max-width:55rem;}
  728. .center_exp .imd{width:80%;}
  729. .here_btn{width:1.5em;height:1.5em;}
  730. }
  731. @media screen and (max-width:666px){
  732. html{font-size:16px;}
  733. .hidden_on_mobile{display:none !important;}
  734. .block_on_mobile{display:block !important;}
  735. .hidden_on_desktop{display:unset;}
  736. .hidden_on_wide{display:unset;}
  737. header ul{display:block;}
  738. header li{display:block;}
  739. header li::before{content:''}
  740. header::before{box-shadow:none;display:none;}
  741. .small_footer::before{box-shadow:none;display:none;}
  742. .left{position:relative;width:100%;position:relative;top:unset;height:unset;min-height:80vh;padding-right:0;display:block;}
  743. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  744. .center_wide .p_thumb{height:6rem;}
  745. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  746. .pop_right{height:30%;}
  747. .pop_right_big{height:70%;}
  748. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  749. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  750. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  751. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  752. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  753. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  754. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  755. .side_box_mobile_inner:hover{background-size:100% 100%;}
  756. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  757. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  758. .p_thumb{height:3rem;}
  759. .center .post{padding-right:0rem;padding-left:0rem;}
  760. .post .p_thumb img,.post .p_thumb video{max-height:3rem;}
  761. .page,.page_gallery{padding:0.2em;padding-top:0;}
  762. header{padding-top:0.3em;}
  763. .toc_button{top:0.3em;}
  764. .small_footer{padding-bottom:0.3em;}
  765. .footer_additional{display:block;width:100%;}
  766. .album_hint{display:block;font-size:1rem;}
  767. .image_nav{position:absolute !important;}
  768. .image_nav_prev,.image_nav_next{width:25%;}
  769. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  770. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  771. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  772. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  773. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  774. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  775. .opt_compact,.ref_compact{line-break:anywhere;}
  776. .post_width,.post_width_big{overflow:auto;}
  777. .table_top{left:unset;width:100%;overflow:auto;}
  778. table img{max-width:30vw !important;}
  779. .product_ref{width:100%;display:block;}
  780. .post_dummy > *{width:100%;max-width:25rem;}
  781. .sticky_title{top:1.2em;}
  782. .small_footer{position:relative;}
  783. #upload_selector{width:100%;}
  784. .focused_post{padding:0.3rem !important;}
  785. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  786. .wayback_expand{display:block;text-align:center;}
  787. .wayback_link{display:block;}
  788. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  789. .center_exp .post{overflow:auto;}
  790. .center_exp .imd{width:100%;}
  791. .here_btn{width:1.2em;height:1.2em;}
  792. .exp_h_f{height:unset !important;}
  793. .exp_f{margin-bottom:1em;}
  794. }
  795. @media print{
  796. header::before{box-shadow:none;display:none;}
  797. .small_footer::before{box-shadow:none;display:none;}
  798. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  799. .post *,.post_dummy *{margin-bottom:0em}
  800. .p_row,.post table,.post_width>img,.post_width_big>img,.post_ref>img,.post_ref>.original_img,
  801. .post_width>.original_img,.post_width_big>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  802. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  803. table img{margin:0 !important;}
  804. .post h1+p,.post h2+p,.post img+p,.post table+p,.post p:first-child{text-indent:0;}
  805. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  806. table{border-bottom:2px solid black;border-top:2px solid black;}
  807. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  808. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  809. .post_width,.post_width_big{overflow:clip;left:0;width:100%;padding-left:0em;}
  810. .post h1{margin-top:0.5rem;}
  811. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  812. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  813. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  814. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  815. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  816. .left,.right{display:none;}
  817. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  818. hr{border:1px solid black;}
  819. .post_box_top{display:none;}
  820. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;}
  821. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  822. .focused_post{border:none;font-size:1em;padding:0 !important;}
  823. .hidden_on_print{display:none;}
  824. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  825. .post_access{display:none;}
  826. .opt_compact{margin-left:0;}
  827. .post .post_ref{padding-left:1.4rem;}
  828. .opt_compact .post_width{left:1.4rem;width:calc(100% - 1.4rem);margin-left:0;}
  829. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  830. .print_title:first-of-type{margin-top:1em;}
  831. .print_title+.post h1:first-of-type{display:none;}
  832. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  833. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  834. .header_nav{display:none;}
  835. .show_on_print{display:block;}
  836. blockquote{border-left:2px solid black;}
  837. .footer_additional{display:none;}
  838. .small_footer{margin-top:1rem;}
  839. .page_selector{display:none;}
  840. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  841. .post .p_thumb img,.post .p_thumb video{max-height:4rem;}
  842. .sticky_title{box-shadow:none;}
  843. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  844. .center_wide .p_row{display:block;}
  845. .interesting_tbody{background:none;}
  846. .interesting_tbody img{display:none !important;}
  847. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  848. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  849. }
  850. ";
  851. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  852. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  853. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  854. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  855. $this->style=preg_replace('/%lightopbkg%/','#daae8010',$this->style);
  856. $this->style=preg_replace('/%lighterbkg%/','#675340',$this->style);
  857. $this->style=preg_replace('/%focusedbkg%/','#482f0c',$this->style);
  858. $f = fopen('styles/main.css','w');
  859. fwrite($f,$this->style);
  860. fclose($f);
  861. }
  862. function GiveSafeEMail(){
  863. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  864. }
  865. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  866. if(isset($this->Images[0])) foreach($this->Images as &$im){
  867. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  868. else { if($im['name']==$name) return $im; }
  869. }
  870. return $this->NULL_IMAGE;
  871. }
  872. function &GiveImageInHere($rand=false){
  873. $this->ReadImages(); $this->DetectPageType();
  874. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  875. if(!isset($album) || !$album){
  876. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  877. $imlist=[]; $imlist_fallback=[];
  878. if(isset($this->Images[0])){
  879. foreach($this->Images as &$im){
  880. if(isset($im['galleries'][0]) && in_array($album,$im['galleries'])){
  881. if(!$rand) return $im; else if($this->CanShowImage($im)){
  882. $imlist_fallback[] = $im;
  883. if(!in_array($im['name'],$this->VisitedHere)) $imlist[] = $im;
  884. }
  885. }
  886. }
  887. }
  888. if(!$rand || !isset($imlist_fallback[0])) return $this->NULL_IMAGE;
  889. if(sizeof($imlist)){
  890. $r = random_int(0, sizeof($imlist)-1);
  891. return $imlist[$r];
  892. }else{
  893. $r = random_int(0, sizeof($imlist_fallback)-1);
  894. return $imlist_fallback[$r];
  895. }
  896. }
  897. function ImageTitle($im){
  898. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  899. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  900. return $imtitle;
  901. }
  902. function ImageHasHere(&$im, $here_name){
  903. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  904. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  905. }
  906. function ReadImages($clear_non_exist = false){
  907. $path = 'images/list.md';
  908. if($this->DoneReadImages){ return; }
  909. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  910. $c = file_get_contents($path);
  911. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  912. $g=[]; $g['name']=$m[1];//$g['count']=0;
  913. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  914. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  915. $this->Galleries[] = $g;
  916. }
  917. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  918. $name = trim($m[1]);
  919. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  920. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  921. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  922. $item['refs']=[];
  923. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  924. }
  925. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  926. $item['galleries']=[];
  927. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  928. }
  929. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  930. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  931. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  932. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  933. $item['here']=[];
  934. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  935. }
  936. if(preg_match('/\.mp4/u',$item['name'])){
  937. $item['video']='video/mp4';
  938. }
  939. $this->Images[] = $item;
  940. }
  941. $files = array_merge([],glob('images/*.jpg'));
  942. $files = array_merge($files,glob('images/*.jpeg'));
  943. $files = array_merge($files,glob('images/*.png'));
  944. $files = array_merge($files,glob('images/*.gif'));
  945. $files = array_merge($files,glob('images/*.mp4'));
  946. if(isset($files[0]))foreach($files as $file) {
  947. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png|mp4)/u', $file, $m)) {
  948. $name = trim($m[0]);
  949. if(!$this->FindImage($name)){
  950. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  951. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  952. $this->Images[] = $item;
  953. }
  954. }
  955. }
  956. if($clear_non_exist){
  957. if(isset($this->Images[0]) && isset($files[0])){
  958. foreach($this->Images as &$im){
  959. if(!in_array($im['file'],$files)){
  960. $im['deleted'] = 1;
  961. }
  962. }
  963. }
  964. }
  965. function cmpf($a, $b){
  966. if ($a['name'] == $b['name']) return 0;
  967. return (($a['name'] > $b['name']) ? 1 : -1);
  968. }
  969. function cmpaf($a, $b){
  970. if ($a['name'] == $b['name']) return 0;
  971. return ($a['name'] > $b['name']) ? -1 : 1;
  972. }
  973. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  974. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  975. $this->DoneReadImages = 1;
  976. }
  977. function WriteImages(){
  978. if(isset($this->WayBack)) return;
  979. $path = 'images/list.md';
  980. $f = fopen($path,'w');
  981. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  982. if(isset($g['deleted'])) continue;
  983. fwrite($f,'GALLERY '.$g['name']);
  984. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  985. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  986. fwrite($f, PHP_EOL);
  987. }
  988. if(isset($this->Images[0]))foreach($this->Images as &$im){
  989. if(isset($im['deleted'])) continue;
  990. fwrite($f, "- ".$im['name'].'; ');
  991. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  992. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  993. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  994. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  995. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  996. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  997. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  998. }
  999. fwrite($f, PHP_EOL);
  1000. }
  1001. fflush($f);
  1002. fclose($f);
  1003. }
  1004. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL){
  1005. if(!($im = &$this->FindImage($name))) return;
  1006. if(isset($link_gallery)){
  1007. if($do_remove){
  1008. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  1009. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  1010. $im['galleries'] = array_merge($im['galleries']);
  1011. }else{
  1012. if(!isset($im['galleries'])) $im['galleries']=[];
  1013. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  1014. $im['galleries'][]=$link_gallery;
  1015. }
  1016. }
  1017. if(isset($product_link)){
  1018. if($product_link!=''){$im['product']=$product_link;}
  1019. else{unset($im['product']);}
  1020. }
  1021. if(isset($rename) && $rename!=$im['name']){
  1022. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1023. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1024. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1025. $im['name'] = $rename.'.'.$ext;
  1026. }
  1027. if(isset($parent) && $parent!=$im['parent']){
  1028. if($parent==''){ unset($im['parent']); }
  1029. else{ $im['parent'] = $parent; }
  1030. }
  1031. $this->NeedWriteImages = 1;
  1032. }
  1033. function RegenerateThumbnails(){
  1034. $glob = glob('images/*.jpg');
  1035. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1036. foreach($glob as $file) {
  1037. $thumb_destination = 'images/thumb/'.basename($file);
  1038. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1039. $width=$geo['width']; $height=$geo['height'];
  1040. $lim=400;
  1041. $scale = $lim / min($width,$height);
  1042. if($scale<1){
  1043. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1044. }
  1045. $img->setImageFormat('jpeg');
  1046. $img->setImageCompressionQuality(90);
  1047. $img->writeImage($thumb_destination);
  1048. }
  1049. }
  1050. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max) {
  1051. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1052. $width=$geo['width']; $height=$geo['height'];
  1053. $lim=400;
  1054. $scale = $lim / min($width,$height);
  1055. if($scale<1){
  1056. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1057. }
  1058. $img->setImageFormat('jpeg');
  1059. $img->setImageCompressionQuality($quality);
  1060. $img->writeImage($thumb_destination);
  1061. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1062. if($scale<1){
  1063. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1064. }
  1065. $img2->setImageFormat('jpeg');
  1066. $img2->setImageCompressionQuality($quality);
  1067. $img2->writeImage($destination);
  1068. }
  1069. function DoUpload(){
  1070. if(!isset($_FILES['upload_file_name'])) return 0;
  1071. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1072. if($_FILES['upload_file_name']['error']>0){
  1073. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1074. return -1;
  1075. }else{
  1076. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  1077. if(!in_array($ext,['jpg','jpeg','png','gif','mp4'])) return 0;
  1078. $fp = fopen('.la_lock',"w");
  1079. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1080. usleep(10000);
  1081. }
  1082. $num=date('YmdHis'); $replace=0;
  1083. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1084. $num = $mim[1]; $replace=1;
  1085. }
  1086. $base = 'images/'.$num;
  1087. $thumb = 'images/thumb/'.$num;
  1088. if($ext=='png') $ext='jpg';
  1089. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  1090. if(!$replace) while(file_exists($final_path)){
  1091. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  1092. }
  1093. if($ext!='gif' && $ext!='mp4'){
  1094. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1095. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1096. $compress?800:1920, $compress?1920:2560);
  1097. }else{
  1098. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1099. }
  1100. flock($fp, LOCK_UN);
  1101. fclose($fp);
  1102. $this->ReadImages(true);
  1103. $this->WriteImages();
  1104. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1105. if(isset($_POST['image_replace_button'])){
  1106. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1107. }
  1108. exit;
  1109. return 1;
  1110. }
  1111. return 0;
  1112. }
  1113. function &GetGallery($name){
  1114. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1115. if($g['name'] == $name) return $g;
  1116. }
  1117. return $this->NULL_GALLERY;
  1118. }
  1119. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  1120. $this->ReadImages();
  1121. $gallery = &$this->GetGallery($name);
  1122. if(!isset($gallery)){
  1123. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1124. $g = []; $g['name']=$new_name;
  1125. $this->Galleries[]=$g;
  1126. }else{
  1127. if(isset($new_name)) {
  1128. if(preg_match('/main|trash|\s/u',$new_name))return;
  1129. $gallery['name'] = $new_name;
  1130. foreach ($this->Images as &$im){
  1131. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1132. if($g == $name){ $g = $new_name; }
  1133. }
  1134. }
  1135. }
  1136. //if(isset($count)) $gallery['count'] = $count;
  1137. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1138. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1139. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1140. }
  1141. if($do_rw) { $this->NeedWriteImages = 1; }
  1142. }
  1143. function ClearData(){
  1144. $this->Posts = [];
  1145. $this->Threads = [];
  1146. $this->Images = [];
  1147. $this->Archive = [];
  1148. $this->ArchiveHandles = [];
  1149. }
  1150. function InsertArchivePost(&$post){
  1151. $a = NULL;
  1152. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1153. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1154. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1155. }
  1156. $a['list'][] = $post;
  1157. $this->Archive[] = $post;
  1158. }
  1159. function ReadArchiveFromFile($path){
  1160. if(!file_exists($path)){
  1161. return;
  1162. }
  1163. $c = file_get_contents($path);
  1164. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1165. foreach($matches as $m){
  1166. $post = [];
  1167. $post['id'] = $m[1];
  1168. $post['content'] = trim($m[3]);
  1169. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1170. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1171. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1172. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1173. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1174. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1175. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1176. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1177. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1178. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1179. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1180. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1181. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1182. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1183. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1184. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1185. }
  1186. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1187. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1188. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1189. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1190. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1191. }
  1192. $this->InsertArchivePost($post);
  1193. }
  1194. }
  1195. }
  1196. function SortArchive(){
  1197. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1198. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1199. return (($a['id'] > $b['id']) ? 1 : -1);
  1200. };
  1201. if(isset($this->Archive[0])){
  1202. usort($this->Archive,$cmpap);
  1203. $year_begin = substr($this->Archive[0]['id'],0,4);
  1204. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1205. }
  1206. if(isset($this->ArchiveHandles[0])){
  1207. usort($this->ArchiveHandles,$cmpac);
  1208. foreach($this->ArchiveHandles as &$a){
  1209. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1210. $last_valid=NULL;
  1211. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1212. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1213. else{ $last_valid = $ver['content']; } }
  1214. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1215. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1216. }
  1217. }
  1218. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1219. $p['archive'] = &$a;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. function ReadPostsFromFile($path){
  1225. if(!file_exists($path)){
  1226. $f = fopen($path,'w');
  1227. fclose($f);
  1228. }
  1229. $c = file_get_contents($path);
  1230. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1231. foreach($matches as $m){
  1232. $post = [];
  1233. $post['id'] = $m[1];
  1234. $post['real_content'] = trim($m[3]);
  1235. $post['content'] = &$post['real_content'];
  1236. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1237. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1238. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1239. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1240. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1241. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1242. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1243. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1244. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1245. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1246. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1247. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1248. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1249. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1250. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1251. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1252. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1253. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1254. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1255. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1256. if(preg_match('/HASTAG\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['hastag'] = $entries; } }
  1259. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1260. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1261. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1262. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1263. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1264. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1265. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1266. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1267. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1268. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1269. }
  1270. if(isset($post['mark_value']) && $post['mark_value']==5){
  1271. $post['product']=[];
  1272. }
  1273. /* marks add here */
  1274. $this->Posts[] = $post;
  1275. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1276. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1277. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1278. }
  1279. }
  1280. }
  1281. }
  1282. function SortPosts($wayback=false){
  1283. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1284. $sortlist = &$this->Posts;
  1285. if($wayback) $sortlist = &$this->WaybackPosts;
  1286. if(isset($sortlist[0])){
  1287. usort($sortlist,$cmpp);
  1288. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1289. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1290. }
  1291. }
  1292. function ReadPosts(){
  1293. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1294. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1295. (!is_dir('posts') || is_readable('posts') == false) ||
  1296. (!is_dir('archive') || is_readable('archive') == false) ||
  1297. (!is_dir('images') || is_readable('images') == false) ||
  1298. (!is_dir('styles') || is_readable('styles') == false)){
  1299. $this->Install();
  1300. }
  1301. if($this->DoneReadPosts){ return; }
  1302. $file_list = [];
  1303. $glob = glob('posts/*');
  1304. foreach($glob as $file) {
  1305. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1306. $file_list[] = $file;
  1307. }
  1308. }
  1309. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1310. foreach($file_list as $f) {
  1311. $this->ReadPostsFromFile($f);
  1312. }
  1313. $this->SortPosts();
  1314. $this->DetectThreads();
  1315. $this->DoneReadPosts=1;
  1316. }
  1317. function UpdatePostRefsForWayback(){
  1318. if(!isset($this->WayBack)) return;
  1319. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1320. if(!isset($this->WaybackPosts[0])) return;
  1321. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1322. foreach($this->WaybackPosts as &$p){
  1323. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1324. $pr = &$this->GetPost($r); if(isset($pr)){
  1325. if(!isset($pr['refs'])) $pr['refs']=[];
  1326. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1327. }
  1328. }
  1329. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1330. $ir = &$this->FindImage($r); if(isset($ir)){
  1331. if(!isset($ir['refs'])) $ir['refs']=[];
  1332. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1333. }
  1334. }
  1335. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1336. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1337. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1338. }
  1339. }
  1340. }
  1341. function ReadArchive(){
  1342. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1343. if ($this->DoneReadArchive) return;
  1344. $file_list = []; $glob = glob('archive/*');
  1345. foreach($glob as $file) {
  1346. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1347. $file_list[] = $file;
  1348. }
  1349. }
  1350. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1351. foreach($file_list as $f) {
  1352. $this->ReadArchiveFromFile($f);
  1353. }
  1354. $this->SortArchive();
  1355. $this->DoneReadArchive=1;
  1356. $this->UpdateThreadForWayback();
  1357. $this->UpdatePostRefsForWayback();
  1358. }
  1359. function GetThreadForPost(&$post){
  1360. if(isset($post['tid'])) return;
  1361. $th = []; $iterp = NULL;
  1362. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1363. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1364. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1365. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1366. $np['tid'] = &$th;
  1367. $th['first'] = &$np;
  1368. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1369. }
  1370. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1371. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1372. $np['tid'] = &$th;
  1373. $th['last'] = &$np;
  1374. $iterp = isset($np['next'])?$np['next']:NULL;
  1375. }
  1376. if(isset($th['first']['mark_value'])){
  1377. if($th['first']['mark_value']==6) $th['exp'] = true;
  1378. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1379. }
  1380. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1381. $this->Threads[] = &$th;
  1382. }
  1383. function IdentifyThreadCategory(&$th,&$first_post){
  1384. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1385. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1386. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1387. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1388. }
  1389. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1390. }
  1391. if(isset($th) && preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1392. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1393. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1394. }
  1395. }
  1396. if(isset($th) && preg_match('/\{\s*REVERSED\s*\}/imu',$first_post['content'],$m)){
  1397. $th['reversed'] = true;
  1398. }
  1399. }
  1400. function IsInterestingPost(&$p){
  1401. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1402. return false;
  1403. }
  1404. function IsReversedThread(&$th){
  1405. if(isset($th['reversed']) && $th['reversed']) return true;
  1406. return false;
  1407. }
  1408. function GiveAllMergedPosts(&$po,&$arr){
  1409. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1410. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1411. }
  1412. if(isset($po['archive']) && isset($po['archive']['list'])){
  1413. foreach($po['archive']['list'] as &$ver){
  1414. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1415. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1416. }
  1417. }
  1418. }
  1419. function ThreadMakeWayback(&$th){
  1420. if(!isset($th['arr'][0])) return;
  1421. if(isset($this->WayBack)){
  1422. $remlist = [];
  1423. foreach($th['arr'] as &$pi){
  1424. $po = &$this->GetPost($pi['id'],true);
  1425. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1426. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1427. }
  1428. $ah = &$this->GetArchiveHandle($po['id']);
  1429. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1430. if(!isset($ver['merged_thread'])) continue;
  1431. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1432. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1433. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1434. }
  1435. }
  1436. }
  1437. if(isset($remlist[0]) && isset($th['arr'][0])){
  1438. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1439. foreach($th['arr'] as $key => $pr){
  1440. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1441. $new_th = []; $new_arr = [];
  1442. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1443. $new_th['arr'] = &$new_arr;
  1444. $this->WaybackThreads[] = &$new_th;
  1445. $this->ThreadMakeWayback($new_th);
  1446. }
  1447. }
  1448. }
  1449. function AddMergedPosts(&$p, &$array){
  1450. if(isset($p['archive']) && isset($p['archive']['list'])){
  1451. foreach($p['archive']['list'] as &$ver){
  1452. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1453. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1454. }
  1455. }
  1456. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1457. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1458. }
  1459. function FinalizeThread(&$th, $relink_posts=false, $now){
  1460. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1461. if(!isset($th['arr'])){
  1462. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1463. $arr[]=&$p;
  1464. } $th['arr'] = &$arr;
  1465. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1466. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1467. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1468. $arr=&$new_arr; $th['arr']=&$new_arr;
  1469. $this->ThreadMakeWayback($th); }
  1470. }
  1471. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1472. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1473. if($relink_posts){ $count = $th['count'];
  1474. $arr = &$th['arr'];
  1475. 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'];
  1476. $arr[$i]['tid']=&$th;}
  1477. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1478. }
  1479. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1480. $this->IdentifyThreadCategory($th, $th['first']);
  1481. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1482. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1483. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1484. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1485. }
  1486. function SortThreads(){
  1487. if (!function_exists('cmpt')) {
  1488. function cmpt($a, $b){
  1489. if ($a['score'] == $b['score']) return 0;
  1490. return ($a['score'] > $b['score']) ? -1 : 1;
  1491. }
  1492. }
  1493. usort($this->Threads,"cmpt");
  1494. }
  1495. function DetectThreads(){
  1496. foreach($this->Posts as &$p){
  1497. if(isset($p['tid'])) { continue; }
  1498. $this->GetThreadForPost($p);
  1499. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1500. }
  1501. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1502. $now = date_timestamp_get(date_create());
  1503. foreach($this->Threads as &$t){
  1504. $this->FinalizeThread($t,false,$now);
  1505. }
  1506. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1507. $this->FinalizeThread($th,false,$now);
  1508. $this->Threads[] = &$th;
  1509. }
  1510. $this->SortThreads();
  1511. }
  1512. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1513. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1514. foreach($this->Threads as &$t){
  1515. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1516. }
  1517. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1518. $this->FinalizeThread($th,true,$now);
  1519. $this->Threads[] = &$th;
  1520. }
  1521. $this->SortThreads();
  1522. $this->SortPosts(true);
  1523. $this->UsePosts = &$this->WaybackPosts;
  1524. }
  1525. function &GetMergedPost($id){
  1526. $this->ReadArchive();
  1527. $ah = &$this->GetArchiveHandle($id);
  1528. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1529. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1530. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1531. [$tp, $tver] = $ver['merged_into'];
  1532. if(isset($this->WayBack)){
  1533. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1534. else return $this->GetPost($id); /* should not happen directly. */
  1535. }
  1536. return $this->GetMergedPost($tp);
  1537. }
  1538. function &GetPost($id, $latest_only=false, $find_merged=false){
  1539. if(!isset($id)) return $this->NULL_POST;
  1540. $found=&$this->NULL_POST;
  1541. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1542. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1543. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1544. }
  1545. if($latest_only || !isset($this->WayBack)){ return $found; }
  1546. else{
  1547. if(isset($found)){
  1548. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1549. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1550. $last_ver = &$this->NULL_POST;
  1551. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1552. if($ver['version'] > $this->WayBack) return $last_ver;
  1553. $last_ver = &$ver;
  1554. }
  1555. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1556. else return $last_ver;
  1557. }else{
  1558. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1559. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1560. if($ver['version'] > $this->WayBack) return $last_ver;
  1561. $last_ver = &$ver;
  1562. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1563. [$tp, $tver] = $last_ver['merged_into'];
  1564. if($tver <= $this->WayBack) {
  1565. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1566. return $last_ver;
  1567. }
  1568. }
  1569. }
  1570. return $this->NULL_POST;
  1571. }
  1572. function &GetArchiveHandle($id){
  1573. if(!isset($id)) return $this->NULL_POST;
  1574. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1575. if($p && $p['id'] == $id) { return $p; }
  1576. }
  1577. return $this->NULL_POST;
  1578. }
  1579. function &GetArchive($id){
  1580. if(!isset($id)) return $this->NULL_POST;
  1581. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1582. if($p && $p['id'] == $id) { return $p; }
  1583. }
  1584. return $this->NULL_POST;
  1585. }
  1586. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1587. if(!isset($ah)) return $this->NULL_POST;
  1588. $found = NULL; $last_verp=NULL;
  1589. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1590. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1591. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1592. $last_verp = &$p;
  1593. }
  1594. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1595. return $this->NULL_POST;
  1596. }
  1597. function CacheArchiveOwnLinks(){
  1598. if(isset($this->WayBack)) return;
  1599. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1600. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1601. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1602. foreach($matches as $m){
  1603. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1604. }
  1605. }
  1606. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1607. foreach($matches as $m){
  1608. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1609. }
  1610. }
  1611. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1612. foreach($matches as $m){
  1613. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. function WriteArchive(){
  1619. if(isset($this->WayBack)) return;
  1620. $cf = NULL;$opened =NULL;
  1621. $this->SortArchive();
  1622. $this->CacheArchiveOwnLinks();
  1623. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1624. $nid = substr($p['id'], 0,6);
  1625. if($cf != $nid){
  1626. if($opened){
  1627. fflush($opened);
  1628. fclose($opened);
  1629. }
  1630. $cf = $nid;
  1631. $opened = fopen("archive/$cf.md", 'w');
  1632. }
  1633. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1634. "VER {$p['version']}; ".
  1635. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1636. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1637. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1638. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1639. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1640. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1641. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1642. ']';
  1643. if(isset($p['merged_thread'])){ $p['content']=""; }
  1644. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1645. }
  1646. }
  1647. function WritePosts(){
  1648. if(isset($this->WayBack)) return;
  1649. $cf = NULL;$opened =NULL;
  1650. $this->SortPosts();
  1651. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1652. $nid = substr($p['id'], 0,6);
  1653. if($cf != $nid){
  1654. if($opened){
  1655. fflush($opened);
  1656. fclose($opened);
  1657. }
  1658. $cf = $nid;
  1659. $opened = fopen("posts/$cf.md", 'w');
  1660. }
  1661. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1662. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1663. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1664. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1665. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1666. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1667. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1668. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1669. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1670. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1671. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1672. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1673. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1674. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1675. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1676. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1677. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1678. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1679. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1680. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1681. ']';
  1682. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1683. }
  1684. }
  1685. function CachePostLinks(){
  1686. if(isset($this->WayBack)) return;
  1687. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1688. $this->ConvertPost($post);
  1689. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1690. //discard lost old version
  1691. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1692. }else return;
  1693. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1694. unset($im['refs']); unset($im['here']); unset($im['title']);
  1695. }
  1696. foreach ($this->Posts as &$post){
  1697. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1698. foreach($matches as $m){
  1699. $ref = &$this->GetPost($m[1],true);
  1700. if($ref!=NULL){
  1701. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1702. }
  1703. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1704. }
  1705. }
  1706. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1707. foreach($matches as $m){
  1708. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1709. }
  1710. }
  1711. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1712. foreach($matches as $m){
  1713. if(($im = &$this->FindImage($m[2]))!=NULL){
  1714. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1715. }
  1716. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1717. }
  1718. }
  1719. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R(-|\*).+){1,})/u",$post['content'],$matches)){
  1720. $use_img_name = $matches[2];
  1721. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1722. 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)){
  1723. foreach($mah as $ma){
  1724. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1725. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }foreach($this->Posts as &$post){
  1731. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1732. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1733. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1734. }
  1735. }
  1736. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1737. $min_id = '99999999999999';
  1738. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1739. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1740. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1741. }
  1742. }
  1743. }
  1744. function CreatePostAnchor(&$post){
  1745. $that=&$this;
  1746. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1747. $id = '_heading_'.sizeof($this->Anchors);
  1748. $entry=[(int)$ma[1], $id, $ma[2]];
  1749. $that->Anchors[] = $entry;
  1750. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1751. }, $post['html']);
  1752. }
  1753. function RenamePost(&$post, $rename){
  1754. foreach($this->Posts as &$p){
  1755. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1756. }
  1757. foreach($this->Posts as &$p){
  1758. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1759. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1760. }
  1761. $post['id'] = $rename;
  1762. }
  1763. function DetachPost(&$th,&$post){
  1764. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1765. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1766. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1767. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1768. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1769. unset($th['arr']); $now = date_timestamp_get(date_create());
  1770. $this->FinalizeThread($th, true, $now);
  1771. }
  1772. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1773. $a = &$this->GetArchiveHandle($post['id']);
  1774. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1775. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1776. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1777. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1778. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1779. $post['version'] = $optime_id;
  1780. if($mode==1){
  1781. $this->InsertArchivePost($ap);
  1782. }else if($mode==2){
  1783. $post['merged_from'] = $info;
  1784. $this->InsertArchivePost($ap);
  1785. }else if($mode==3){
  1786. $ap['merged_into'] = $info;
  1787. $this->InsertArchivePost($ap);
  1788. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1789. $this->DetachPost($post['tid'], $post);
  1790. }
  1791. }else if($mode==4){
  1792. $post['merged_thread'] = $info;
  1793. $this->InsertArchivePost($ap);
  1794. }
  1795. }
  1796. function &MergeThreads($post_id, $post_into_id){
  1797. $this->ReadPosts();
  1798. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1799. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1800. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1801. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1802. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1803. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1804. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1805. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1806. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  1807. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1808. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1809. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1810. $tt['count'] = sizeof($tt['arr']);
  1811. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1812. $first_post = &$this->NULL_POST;
  1813. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1814. $this->NeedWritePosts=1;
  1815. $this->NeedWriteArchive=1;
  1816. return $first_post;
  1817. }
  1818. function &MergePosts($ids_string){
  1819. $ids = explode(" ", $ids_string);
  1820. $combined_content = ""; $first_id=NULL;
  1821. $this->ReadPosts(); $child_list=[];
  1822. foreach($ids as $id){
  1823. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1824. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1825. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  1826. }
  1827. if(!isset($child_list[0])) return $this->NULL_POST;
  1828. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  1829. foreach($child_list as $id){
  1830. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  1831. }
  1832. $this->NeedWritePosts=1;
  1833. $this->NeedWriteArchive=1;
  1834. return $first_post;
  1835. }
  1836. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1837. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1838. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1839. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  1840. $this->ReadImages();
  1841. $this->ReadPosts();
  1842. if(isset($push_version) && $push_version){
  1843. $this->ReadArchive();
  1844. }
  1845. $p_success = NULL;
  1846. if(isset($id_if_edit)){
  1847. $post = &$this->GetPost($id_if_edit,true);
  1848. if($post===$this->NULL_POST) return $this->NULL_POST;
  1849. if($get_original_only){
  1850. return $post['real_content'];
  1851. }
  1852. if(isset($push_version) && $push_version){
  1853. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1854. }
  1855. if(isset($content)) $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1856. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1857. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1858. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1859. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  1860. $p_success = &$post;
  1861. }else{
  1862. if(!isset($content)) return $this->NULL_POST;
  1863. $id = date('YmdHis');
  1864. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1865. $post = []; $post['id'] = $id;
  1866. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1867. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1868. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1869. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1870. }
  1871. $this->Posts[] = $post;
  1872. $p_success = &$this->Posts[count($this->Posts) - 1];
  1873. }
  1874. $this->NeedWritePosts=1;
  1875. $this->NeedWriteImages=1;
  1876. if(isset($push_version) && $push_version){
  1877. $this->NeedWriteArchive=1;
  1878. }
  1879. return $p_success;
  1880. }
  1881. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1882. $this->ReadPosts();
  1883. $p_success = NULL;
  1884. if(isset($id_if_edit)){
  1885. $post = &$this->GetPost($id_if_edit,true);
  1886. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1887. if(isset($content)) $post['content'] = $content;
  1888. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1889. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1890. if(isset($ip)) $post['ip'] = $ip;
  1891. $p_success = &$post;
  1892. }else{
  1893. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1894. $id = date('YmdHis');
  1895. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1896. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1897. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1898. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1899. if(isset($ip)) $post['ip'] = $ip;
  1900. $this->Posts[] = $post;
  1901. $p_success = &$this->Posts[count($this->Posts) - 1];
  1902. }
  1903. $this->NeedWritePosts=1;
  1904. return $p_success;
  1905. }
  1906. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  1907. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1908. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1909. function($matches){
  1910. $rep = preg_replace('/->/','-@>',$matches[0]);
  1911. $rep = preg_replace('/=>/','=@>',$rep);
  1912. $rep = preg_replace('/<=/','<@=',$rep);
  1913. $rep = preg_replace('/<-/','<@-',$rep);
  1914. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  1915. $rep = preg_replace('/\[-/','[@-',$rep);
  1916. $rep = preg_replace('/\{/','{@',$rep);
  1917. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  1918. return $rep;
  1919. },
  1920. $replacement);
  1921. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  1922. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  1923. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  1924. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  1925. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  1926. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  1927. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  1928. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  1929. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  1930. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  1931. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  1932. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  1933. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  1934. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  1935. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1936. function($matches){
  1937. $rep = preg_replace('/-@>/','->',$matches[0]);
  1938. $rep = preg_replace('/<@-/','<-',$rep);
  1939. $rep = preg_replace('/=@>/','=>',$rep);
  1940. $rep = preg_replace('/<@=/','<=',$rep);
  1941. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  1942. $rep = preg_replace('/\[@-/','[-',$rep);
  1943. $rep = preg_replace('/\{@/','{',$rep);
  1944. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  1945. return $rep;
  1946. }, $replacement);
  1947. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  1948. function($matches) use (&$post_for_it_is_here){
  1949. $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]);
  1950. return $matches[1].$rep;
  1951. }, $replacement);
  1952. return $replacement;
  1953. }
  1954. function CanShowPost(&$p){
  1955. if(!isset($p) || isset($p['comment_to'])) return false;
  1956. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  1957. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  1958. if($is_mark_slf && !$this->LoggedIn){ return false; }
  1959. if(isset($this->WayBack)){
  1960. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  1961. else if ($p['id']>$this->WayBack) return false;
  1962. }
  1963. if(!$this->InExperimentalMode){
  1964. if(!$this->LoggedIn){
  1965. if($is_mark_exp) return false;
  1966. return true;
  1967. }
  1968. return true;
  1969. }else{
  1970. if($is_mark_exp) return true;
  1971. return false;
  1972. }
  1973. }
  1974. function SkipProduct(&$p){
  1975. if($this->LoggedIn) return false;
  1976. return (isset($p['mark_value']) && $p['mark_value']==5);
  1977. }
  1978. function GetRedirect($args=NULL){
  1979. $str = 'index.php?';
  1980. if(isset($args['post'])) $str.='&post='.$args['post'];
  1981. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  1982. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  1983. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  1984. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  1985. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  1986. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  1987. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  1988. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  1989. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  1990. if(isset($args['category'])) $str.='&category='.$args['category'];
  1991. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  1992. if(isset($args['history'])) $str.='&history='.$args['history'];
  1993. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  1994. if(isset($args['version'])) $str.='&version='.$args['version'];
  1995. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  1996. if(isset($args['search'])) $str.='&search='.$args['search'];
  1997. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  1998. if(isset($args['here'])) $str.='&here='.$args['here'];
  1999. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  2000. return $str;
  2001. }
  2002. function WriteAsNecessary(){
  2003. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  2004. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  2005. if($this->NeedWriteImages){ $this->WriteImages(); }
  2006. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  2007. }
  2008. function APubEnsureWebfinger($name, $host){
  2009. if(!is_dir('.well-known')) mkdir('.well-known');
  2010. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  2011. $f = fopen('.well-known/webfinger/index.php',"w");
  2012. $without_protocol = parse_url($host, PHP_URL_HOST);
  2013. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  2014. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  2015. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  2016. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2017. $res = openssl_pkey_new();
  2018. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2019. openssl_pkey_export($res, $this->APubPrivateKey);
  2020. $f = fopen('.well-known/apub_public_key.pem',"w");
  2021. fwrite($f, $this->APubPublicKey); fclose($f);
  2022. $f = fopen('.well-known/apub_private_key.php',"w");
  2023. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2024. }
  2025. }
  2026. function APubEnsureInfo(){
  2027. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2028. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2029. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2030. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2031. "id"=> $this->HostURL."?apub_actor=1",
  2032. "type"=> "Person",
  2033. "name"=> $this->DisplayName,
  2034. "url"=> $this->HostURL,
  2035. "summary"=> "Lazy... No summary",
  2036. "preferredUsername"=> $this->APubID,
  2037. "inbox"=> $this->HostURL."?apub_inbox=1",
  2038. "outbox"=> $this->HostURL."?apub_outbox=1",
  2039. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2040. "owner"=> $this->HostURL."?apub_actor=1",
  2041. "publicKeyPem"=>$pk]];
  2042. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2043. }
  2044. function APubMakeOutbox(){
  2045. $this->ReadPosts();$this->ReadImages();
  2046. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2047. "id"=>$this->HostURL."?apub_outbox=1",
  2048. "type"=>"OrderedCollection"];
  2049. $items=[]; $i=0;
  2050. foreach(array_reverse($this->Posts) as &$p){
  2051. $this->ConvertPost($p);
  2052. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2053. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2054. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2055. "type"=> "Create",
  2056. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2057. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2058. //"to"=> ["https://chatty.example/ben/"],
  2059. "actor"=> $this->HostURL."?apub_actor=1",
  2060. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2061. "object"=> ["type"=> "Note",
  2062. "id"=> $this->HostURL."?post=".$p['id'],
  2063. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2064. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2065. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2066. "content"=> $text]];
  2067. $items[] = $ob;
  2068. $i++; if($i>20) break;
  2069. }
  2070. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2071. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2072. }
  2073. function MakeRSS(){
  2074. $this->ReadPosts();$this->ReadImages();
  2075. $posts = []; if(isset($this->UsePosts[0])){
  2076. $posts = array_reverse($this->UsePosts);
  2077. $last_updated = $this->StandardTime($posts[0]['id']);
  2078. }else{ $last_updated= $this->StandardTime("20000101000000"); }
  2079. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2080. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2081. "<id>".$this->HostURL."/?rss</id>".
  2082. "<updated>".$last_updated."</updated>".
  2083. "<title>".$this->T($this->Title)."</title>".
  2084. "<link href='".$this->HostURL."/?rss' rel='self'/>".
  2085. "<link href='".$this->HostURL."' />".$author;
  2086. $i=0;
  2087. if(isset($posts[0])) foreach($posts as &$p){
  2088. if($i>100) break;
  2089. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2090. if(isset($p['tid'])){ /* Should always be set. */
  2091. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2092. if(in_array($p['id'],
  2093. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  2094. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2095. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2096. $is_reversed=false;
  2097. $content="<entry>"; $title = NULL;
  2098. if($is_thread){
  2099. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2100. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2101. foreach($use_arr as &$po){
  2102. $this->ConvertPost($po);
  2103. if(!isset($title)){$title = $this->GetPostTitle($po, false, false);
  2104. $content.="<id>".$this->HostURL."?post=".$po['id']."</id>";
  2105. $content.="<title>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$po['id']."' />";
  2106. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2107. $content.="<updated>".$this->StandardTime(isset($po['tid']['last']['version'])?
  2108. $po['tid']['last']['version']:$po['tid']['last']['id'])."</updated>".$author;
  2109. $content.="<content type='html'>"; }
  2110. $content.= htmlspecialchars($po['html']);
  2111. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2112. }
  2113. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2114. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2115. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2116. $content.="</content>";
  2117. }else{
  2118. $this->ConvertPost($p);
  2119. if(!isset($title)){$title = $this->GetPostTitle($p, false, false);
  2120. $content.="<id>".$this->HostURL."?post=".$p['id']."</id>";
  2121. $content.="<title>".$title."</title><link rel='alternate' href='".$this->HostURL."/?post=".$p['id']."' />";
  2122. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2123. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2124. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2125. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2126. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2127. $content.=$this->ReadableTime($p['id'])." - ".
  2128. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2129. $content.="</content>";
  2130. }
  2131. $i++;
  2132. $content.="</entry>";
  2133. $all_content.=$content;
  2134. }
  2135. $all_content.="</feed>";
  2136. header( "Content-type: text/xml");
  2137. echo $all_content;
  2138. }
  2139. function MakeHereButtons($im, $insert_here){
  2140. if(isset($im['here'])&&isset($im['here'][0])){
  2141. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2142. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2143. foreach($im['here'] as $here){
  2144. if($insert_here){
  2145. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2146. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2147. }else{
  2148. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2149. }
  2150. }
  2151. echo "</div>".($insert_here?"</here>":"");
  2152. }
  2153. }
  2154. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  2155. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2156. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2157. return 0;
  2158. }
  2159. if(isset($_GET['set_language'])){
  2160. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2161. $redirect=$this->GetRedirect(); return 0;
  2162. }
  2163. if(isset($_GET['rss'])){
  2164. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2165. $this->MakeRSS(); exit;
  2166. }
  2167. if(isset($_GET['toggle_font'])){ $use_font='local';
  2168. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2169. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2170. $redirect=$this->GetRedirect(); return 0;
  2171. }
  2172. if(isset($_GET['set_wayback'])){
  2173. if($_GET['set_wayback']!='false'){
  2174. $wayback= date('YmdHis');
  2175. if($_GET['set_wayback']=='post'){
  2176. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2177. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2178. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2179. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2180. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2181. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2182. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2183. }else{
  2184. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2185. }
  2186. $redirect=$this->GetRedirect(); return 0;
  2187. }
  2188. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2189. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2190. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2191. if(isset($_GET['part'])){
  2192. if($_GET['part'] == 'hot') $this->ExtraScripts.="ShowLeftSide();";
  2193. else if ($_GET['part'] == 'recent') $this->ExtraScripts.="ShowCenterSide();";
  2194. }
  2195. if(isset($_GET['post'])){
  2196. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2197. }
  2198. if(isset($_GET['random_here'])){
  2199. $this->DoIdentiyExperimental(); $this->DetectPageType();
  2200. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2201. }
  2202. if(isset($_POST['search_content'])){ $redirect='index.php?search='.$_POST['search_content'];return 0; }
  2203. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2204. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2205. $direct_return = !isset($_GET['show_image']);
  2206. $this->ReadImages(); $this->ReadPosts();
  2207. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2208. $im = &$this->FindImage($m);
  2209. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2210. if($direct_return){
  2211. echo "<ref>".sizeof($im['refs'])."</ref>";
  2212. echo "<insert><ul>";
  2213. }else{ ob_start(); }
  2214. foreach(array_reverse($im['refs']) as $ref){
  2215. $p = $this->GetPost($ref);
  2216. if(!$p || !$this->CanShowPost($p)) continue;
  2217. $this->MakeSinglePost($p, false, true, "post_preview", true, false, false, false, true);"</li>";
  2218. }
  2219. if($direct_return){
  2220. echo "</ul></insert>";
  2221. $this->MakeHereButtons($im, true);
  2222. }else{
  2223. $str = ob_get_clean();
  2224. $this->MakePageBegin();
  2225. $side = "";
  2226. if(isset($im['refs'])&&isset($im['refs'][0])){
  2227. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2228. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2229. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$im['file']);
  2230. $this->MakePageEnd();
  2231. }
  2232. exit;
  2233. }
  2234. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2235. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2236. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2237. }
  2238. if(isset($_GET['apub_actor'])){
  2239. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2240. echo $this->APubActor; exit;
  2241. }
  2242. if(isset($_GET['apub_outbox'])){
  2243. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2244. echo $this->APubMakeOutbox(); exit;
  2245. }
  2246. if($this->LoggedIn){
  2247. $this->DoUpload();
  2248. if(isset($_POST['settings_button'])){
  2249. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2250. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2251. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2252. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2253. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2254. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2255. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2256. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2257. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2258. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2259. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2260. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2261. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2262. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2263. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2264. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2265. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2266. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2267. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2268. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2269. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2270. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2271. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2272. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2273. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2274. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2275. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2276. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2277. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2278. $this->APubID=$_POST['settings_apub_id'];
  2279. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2280. }
  2281. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2282. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2283. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2284. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2285. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2286. $redirect=$_SERVER['REQUEST_URI'];
  2287. $this->DoLogout();
  2288. }
  2289. $this->WriteConfig();
  2290. return 0;
  2291. }
  2292. if(isset($_POST['settings_save_redirect'])){
  2293. if(isset($_POST['settings_redirect'])){
  2294. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2295. }
  2296. $this->WriteConfig();
  2297. $redirect = 'index.php?extras=true'; return 0;
  2298. }
  2299. if(isset($_POST['settings_save_translation'])){
  2300. if(isset($_POST['settings_translation'])){
  2301. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2302. }
  2303. $redirect = 'index.php?extras=true'; return 0;
  2304. }
  2305. if(isset($_GET['post'])){
  2306. if(isset($_GET['post_original'])){
  2307. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2308. exit;
  2309. }
  2310. }
  2311. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2312. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2313. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2314. return 0;
  2315. }
  2316. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2317. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2318. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2319. return 0;
  2320. }
  2321. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2322. $c = $_POST['post_content'];
  2323. if('有什么想说的' == $c){ return 0;}
  2324. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2325. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2326. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2327. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2328. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2329. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2330. $redirect='?post='.$edited['id']; return 0;
  2331. };
  2332. }
  2333. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2334. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2335. $redirect='?post='.$edited['id']; return 0;
  2336. };
  2337. }
  2338. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2339. if(($edited =$this->EditPost(
  2340. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2341. $redirect='?post='.$edited['id']; return 0;
  2342. };
  2343. }
  2344. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2345. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2346. if(isset($post)){
  2347. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2348. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2349. echo "SUCCESS ".$mastodon_url;
  2350. }else{ echo $err; }
  2351. } exit;
  2352. }
  2353. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2354. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2355. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2356. }
  2357. }
  2358. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2359. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2360. $redirect='?post='.$pe['id']; return 0;
  2361. }
  2362. }
  2363. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2364. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2365. $c = $_POST['comment_box'];
  2366. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2367. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2368. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2369. if(($edited = $this->EditComment(NULL,
  2370. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2371. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2372. $_SERVER['REMOTE_ADDR']))!=NULL){
  2373. $redirect='?post='.$_GET['post'];
  2374. return 0;
  2375. };
  2376. }
  2377. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2378. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2379. $new_name = $_POST['gallery_edit_new_name'];
  2380. if($old_name!=''){
  2381. $this->EditGallery($old_name, $new_name, false, true, null, null);
  2382. $redirect='?gallery='.$new_name;
  2383. }else{
  2384. $this->EditGallery(null, $new_name, false, true, null);
  2385. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2386. }
  2387. return 0;
  2388. }
  2389. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2390. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  2391. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  2392. return 0;
  2393. }
  2394. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2395. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2396. $this->ReadImages();
  2397. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2398. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL);
  2399. }
  2400. }
  2401. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2402. return 0;
  2403. }
  2404. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2405. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2406. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2407. return 0;
  2408. }
  2409. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2410. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2411. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2412. return 0;
  2413. }
  2414. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2415. $this->ReadImages();
  2416. $gallery = $_GET['image_list'];
  2417. foreach($this->Images as $im){
  2418. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2419. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2420. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2421. }
  2422. exit;
  2423. }
  2424. $do_image_redirect = 0;
  2425. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2426. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4))/u',$_GET['pic'],$ma)){
  2427. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2428. if(isset($_POST['image_ops_product_link'])){
  2429. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL);
  2430. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2431. }
  2432. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2433. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL);
  2434. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2435. $do_image_redirect = 1;
  2436. }
  2437. if(isset($_POST['image_parent'])){ $parent="";
  2438. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2439. $this->EditImage($pic, NULL, false, NULL, NULL, $parent);
  2440. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2441. }
  2442. $this->NeedWriteImages = 1;
  2443. if($do_image_redirect) return 0;
  2444. }
  2445. if(isset($_GET['rewrite_styles'])){
  2446. $this->WriteStyles();
  2447. $redirect='?extras=true'; return 0;
  2448. }
  2449. if(isset($_GET['regenerate_thumbnails'])){
  2450. $this->RegenerateThumbnails();
  2451. $redirect='?extras=true'; return 0;
  2452. }
  2453. if(isset($_GET['clear_all_logins'])){
  2454. $this->LoginTokens=[];
  2455. $this->WriteTokens();
  2456. }
  2457. }
  2458. return 0;
  2459. }
  2460. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null){
  2461. if(!$this->LoggedIn){
  2462. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2463. }
  2464. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2465. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2466. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2467. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2468. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2469. $html = preg_replace("/<p>\s*\{\s*INTERESTING\s+(.*?)\}\s*<\/p>/imu","",$html);
  2470. $html = preg_replace("/\{\s*REVERSED\s*\}/imu","",$html);
  2471. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2472. $html = preg_replace_callback(
  2473. "/(<p>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif|mp4)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2474. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2475. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2476. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2477. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2478. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2479. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2480. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2481. $src = $im['thumb']; $orig_src=$im['file'];
  2482. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2483. $media_start = $m[2];
  2484. $media_end = $m[7];
  2485. if(isset($im['video']) && isset($im['video'])!=''){
  2486. $media_start = "<video controls><source src='"; $media_end="' type='".$im['video']."'></video";
  2487. $src = $orig_src;
  2488. }
  2489. if($this->InHereMode){
  2490. $click = "<div class='imd'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2491. $media_start.$orig_src.$media_end."></a></div>";
  2492. return $click;
  2493. }else{ $click =
  2494. "<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2495. $media_start.($original?$orig_src:$src).$media_end." data-imgsrc='".$m[5]."'".
  2496. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2497. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2498. ($original?" class='original_img'":"")."></a></div>";
  2499. $images_noclick[]=$media_start.$src.$media_end.">"; $images_orig_src_list[]=$orig_src;
  2500. $ret = "";
  2501. if($keep) { $ret = $click; }
  2502. else { $images[] = $click; }
  2503. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2504. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2505. }
  2506. },$html,-1,$count);
  2507. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2508. if(sizeof($images)){
  2509. if(sizeof($images)==1){$html.= $images[0]; }
  2510. else{
  2511. $html.="<div class='p_row'>";
  2512. foreach($images as $img){
  2513. $html.="<div class='p_thumb'>".$img."</div>";
  2514. }
  2515. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2516. }
  2517. }
  2518. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2519. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2520. if($do_product_info){
  2521. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2522. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2523. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2524. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2525. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2526. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2527. else { $product_info['title'] = $this->T('商品'); }
  2528. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2529. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2530. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2531. $this->T('购买').' '.$product_info['title'].
  2532. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2533. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2534. }
  2535. return $html;
  2536. }
  2537. function ConvertPost(&$post){
  2538. if(!isset($post['html'])){
  2539. $info=[];
  2540. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2541. $post['images'],
  2542. isset($post['product']), $info,
  2543. $post['original_images']));
  2544. if(isset($post['product'])) $post['product']=$info;
  2545. }
  2546. }
  2547. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2548. if(!isset($post['title'])){
  2549. if($h1_only){
  2550. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){return $m[1];}
  2551. return NULL;
  2552. }
  2553. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2554. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2555. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2556. $post['title'].=($add_unamed?' (':'').strip_tags($this->PDE->text($m[1])).($add_unamed?')':''); }
  2557. }
  2558. }
  2559. return $this->ChoosePartsByLanguage($post['title']);
  2560. }
  2561. function DetectPageType(){
  2562. if ($this->InExperimentalMode) $this->PageType='experimental';
  2563. else if($this->InHereMode) $this->PageType='here';
  2564. else if(isset($_GET['history'])) $this->PageType='history';
  2565. else if(isset($_GET['extras'])) $this->PageType='extras';
  2566. else if(isset($_GET['settings'])) $this->PageType='settings';
  2567. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2568. else if(isset($_GET['search'])) $this->PageType='search';
  2569. else if(isset($_GET['category'])) $this->PageType='category';
  2570. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2571. else if(isset($_GET['comments'])) $this->PageType='comments';
  2572. else $this->PageType = "main";
  2573. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2574. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2575. $this->VisitedHere = $_SESSION[$visited_here];
  2576. }
  2577. function MakePageBegin(){ ?>
  2578. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2579. <head>
  2580. <meta charset='utf-8'>
  2581. <meta content="width=device-width, initial-scale=1" name="viewport">
  2582. <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2583. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title))?></title>
  2584. <?php if($this->UseRemoteFont){ ?><style>
  2585. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2586. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2587. </style><?php } ?>
  2588. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2589. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2590. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2591. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2592. </head>
  2593. <div class='page'>
  2594. <?php }
  2595. function MakeHeader(&$p){
  2596. $this->MakePageBegin() ?>
  2597. <script type='text/javascript'>
  2598. function toggle_mobile_show(a){a.classList.toggle('hidden_on_mobile')}
  2599. function ShowWaitingBar(){
  2600. wait = document.querySelector("#waiting_bar");
  2601. wait.style.display='';
  2602. }
  2603. function HideWaitingBar(){
  2604. wait = document.querySelector("#waiting_bar");
  2605. wait.style.display='none';
  2606. }
  2607. <?php if(!$this->InHereMode){ ?>
  2608. function la_auto_grow(element){
  2609. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2610. }
  2611. var scroll_l=0,scroll_c=0;in_center=1;
  2612. function ShowLeftSide(){
  2613. scroll_c = window.scrollY;
  2614. document.getElementById('div_left').classList.remove('hidden_on_mobile');
  2615. document.getElementById('div_center').classList.add('hidden_on_mobile');
  2616. window.scroll(0, scroll_l); in_center=0;
  2617. }
  2618. function ShowCenterSide(){
  2619. scroll_l = window.scrollY;
  2620. document.getElementById('div_center').classList.remove('hidden_on_mobile');
  2621. document.getElementById('div_left').classList.add('hidden_on_mobile');
  2622. window.scroll(0, scroll_c); in_center=1;
  2623. }
  2624. function ShowBackdrop(alpha=0.5){
  2625. b = document.getElementById('backdrop');
  2626. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2627. b.style.animation='backdrop_fade_in 0.3s forwards';
  2628. b.style.display = 'block';
  2629. }
  2630. function HideBackdrop(){
  2631. b = document.getElementById('backdrop');
  2632. b.style.animation='backdrop_fade_out 0.3s forwards';
  2633. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2634. }
  2635. function ShowRightSide(big,elem_to_clone){
  2636. p = document.getElementById('pop_right');
  2637. if(elem_to_clone){
  2638. c = elem_to_clone.cloneNode(true);
  2639. c.id='side_bar_cloned';c.className="";c.style="";
  2640. p.querySelector('._content').appendChild(c);
  2641. }
  2642. p.classList.remove('pop_right','pop_right_big');
  2643. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2644. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2645. p.style.display='block';
  2646. ShowBackdrop(0.5);
  2647. }
  2648. function HideRightSide(){
  2649. p = document.getElementById('pop_right');
  2650. if(side=p.querySelector('#side_bar_cloned')){
  2651. side.remove();
  2652. }
  2653. put = document.querySelector("#_uploader");
  2654. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2655. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2656. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2657. HideBackdrop();
  2658. }
  2659. function ToggleLeftSide(){if(in_center)ShowLeftSide();else ShowCenterSide();}
  2660. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2661. function ScrollToPost(id){
  2662. post=null;
  2663. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2664. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2665. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2666. }
  2667. <?php } ?>
  2668. </script>
  2669. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2670. <?php if($this->InHereMode){
  2671. $this->MakeExpNavButtons($p);
  2672. }else{
  2673. $this->MakeNavButtons($p);
  2674. echo "<hr />";
  2675. } ?>
  2676. <?php if(isset($this->WayBack)){
  2677. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2678. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2679. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2680. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_on_mobile")'>
  2681. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2682. <span class='hidden_on_mobile'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2683. <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_on_mobile'>
  2684. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2685. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2686. <br class='hidden_on_desktop' />
  2687. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2688. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2689. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2690. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2691. <br class='hidden_on_desktop' />
  2692. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2693. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2694. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2695. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2696. <br class='hidden_on_desktop' />
  2697. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2698. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2699. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2700. </div></div><?php } ?>
  2701. </div></header>
  2702. <div id='waiting_bar' style='display:none;'></div>
  2703. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2704. <?php if(!$this->InHereMode){ ?>
  2705. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2706. <ul>
  2707. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2708. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2709. <hr />
  2710. <?php if($this->LoggedIn){ ?>
  2711. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2712. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2713. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2714. <?php if(!isset($this->WayBack)){ ?><li>
  2715. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2716. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2717. </li>
  2718. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2719. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2720. <li id='mark_details' style='display:none;'><b>
  2721. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2722. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2723. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2724. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2725. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2726. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2727. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2728. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2729. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2730. </b></li>
  2731. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2732. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2733. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2734. <input class='button' type='submit' form='post_rename_form'
  2735. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2736. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  2737. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  2738. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  2739. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  2740. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  2741. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  2742. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  2743. <input class='button' type='submit' form='post_mastodon_form'
  2744. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  2745. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  2746. <?php }else{ ?>
  2747. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2748. <?php } ?>
  2749. </ul>
  2750. </div>
  2751. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide()'
  2752. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2753. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2754. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2755. <?=$this->T('关闭')?>→</a></div>
  2756. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2757. <div id='_uploader' style='display:none;'>
  2758. <?php $this->MakeUploader(true); ?>
  2759. <p>&nbsp;</p>
  2760. <?php $this->MakeSideGalleryCode(); ?>
  2761. </div>
  2762. <?php } ?>
  2763. <div class='_content'></div>
  2764. </div>
  2765. <?php } ?>
  2766. <?php
  2767. }
  2768. function ChoosePartsByLanguage($content,$use_p=false){
  2769. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  2770. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  2771. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  2772. if($split) for($i=0;$i<sizeof($split);$i+=4){
  2773. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  2774. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  2775. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  2776. }
  2777. if(!$reduced)$reduced = $content;
  2778. return $reduced;
  2779. }
  2780. function TranslatePostParts($html){
  2781. $html = preg_replace_callback('/>([^><]+?)</u', function($ma){
  2782. $reduced = $this->ChoosePartsByLanguage($ma[1], false);
  2783. return ">".$this->T($reduced)."<";
  2784. }, $html);
  2785. return $html;
  2786. }
  2787. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); ?>
  2788. <a href='index.php' class='clean_a hidden_on_mobile' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title)?></b></a>
  2789. <b><a class='hidden_on_desktop'
  2790. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ShortTitle)?>...</a></b>
  2791. <div class='header_nav'>
  2792. <?php if($this->PageType=='post'){ ?>
  2793. <div class='toc_button hidden_on_print'>
  2794. <?php if(!$interesting && isset($p) && isset($p['refs']) && isset($p['refs'][0])){ ?>
  2795. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2796. <?=$this->T('链接')?>(<?=sizeof($p['refs'])?>)</a></span>
  2797. <?php } if(!$interesting){ ?>
  2798. <span class='hidden_on_wide hidden_on_print'>
  2799. <a id='button_toc' href='javascript:ShowRightSide(true,document.querySelector("#div_right"));'>
  2800. <?=$this->T('目录')?></a></span><?php } ?></div>
  2801. <?php }else if($this->PageType=='history' && isset($_GET['version'])){ ?>
  2802. <div style='float:right;' class='hidden_on_print'>
  2803. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2804. <?=$this->T('历史')?></a></span></div>
  2805. <?php } ?>
  2806. <ul class='hidden_on_mobile hidden_on_print' id='mobile_nav' style='text-align:center;'>
  2807. <li class='hidden_on_mobile'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2808. <li class='hidden_on_desktop_force block_on_mobile'>
  2809. <?php if($this->PageType!='main'){ ?>
  2810. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a> |
  2811. <a href='index.php?part=hot' onclick='ShowWaitingBar()'><?=$this->T('热门')?></a> |
  2812. <?php } else { ?>
  2813. <li class='hidden_on_desktop_force block_on_mobile'>
  2814. <a href='javascript:ShowCenterSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('最近')?></a> |
  2815. <a href='javascript:ShowLeftSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('热门')?></a> |
  2816. <?php } ?>
  2817. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a>
  2818. <?php if($this->LoggedIn){ ?>
  2819. | <span class='gray invert_a'><a href='index.php?comments=all'>@</a></span><?php } ?></li>
  2820. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2821. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2822. } ?>
  2823. <li><a href='?search=' onclick='ShowWaitingBar()'><?=$this->T('搜索')?></a></li>
  2824. <?php if($this->LanguageAppendix=='zh'){ ?>
  2825. <li class='invert_a smaller'>
  2826. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  2827. <?php }else { ?>
  2828. <li class='smaller'>
  2829. <a class='invert_a' href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  2830. 汉语/<b>English</b></a>
  2831. <br class='hidden_on_desktop' />
  2832. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  2833. <?php } ?>
  2834. </ul>
  2835. </div>
  2836. <?php
  2837. }
  2838. function MakeExpNavButtons(&$p){ ?>
  2839. <a href='index.php' class='hidden_on_mobile'>
  2840. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  2841. <a class='hidden_on_desktop'
  2842. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b>
  2843. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?>...</b></a>
  2844. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  2845. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  2846. <span class='round_btn'>
  2847. <a href='<?=$this->HereNumber==sizeof($this->VisitedHere)?"?random_here=1":$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a>
  2848. <a href='?random_here=1'><?=$this->T("随机")?></a></span>
  2849. <b><?=$this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle));?></b>
  2850. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):"";?>
  2851. <ul class='hidden_on_mobile gray invert_a' id='mobile_nav' style='text-align:center;'>
  2852. <li class='hidden_on_desktop block_on_mobile'><a href='index.php'><?=$this->T('索引')?></a></li>
  2853. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2854. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2855. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  2856. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2857. } ?>
  2858. <?php if($this->LanguageAppendix=='zh'){ ?>
  2859. <li class='smaller'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  2860. <?php }else { ?>
  2861. <li class='smaller'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  2862. <li class='smaller'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  2863. <?php } ?>
  2864. </ul>
  2865. <?php
  2866. }
  2867. function GenerateLinkedPosts($ht){
  2868. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  2869. function($m){
  2870. $rp = &$this->GetPost($m[1], false, true);
  2871. $s="<div class='smaller block post ref_compact gray'>".
  2872. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  2873. "<div class='post_ref'><div class='smaller'>".$m[2]."</div>".
  2874. (($rp!==NULL && $this->CanShowPost($rp))?
  2875. $this->GenerateSinglePost($rp,false,false,false,true,$this->NULL_POST,true):$this->T("未找到该引用。")).
  2876. "</div></div>";
  2877. return $s;
  2878. },
  2879. $ht
  2880. );
  2881. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  2882. function($m){
  2883. $rp = &$this->GetPost($m[1], false, true);
  2884. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  2885. (($rp!==NULL && $this->CanShowPost($rp))?
  2886. $this->GenerateSinglePost($rp,true,false,false,true,$this->NULL_POST,true):$this->T("未找到该引用。")).
  2887. "</a></div>";
  2888. return $s;
  2889. },
  2890. $ht
  2891. );
  2892. return $ht;
  2893. }
  2894. function ExtractBigTables($html, &$table_out){
  2895. $table = NULL;
  2896. $new_html = preg_replace_callback('/<p>\s*\{big_table\}\s*<\/p>\s*(<table>[\s\S]*?<\/table>)/u', function ($m) use (&$table){
  2897. $table = $m[1];
  2898. return "";
  2899. }, $html);
  2900. $table_out = $table;
  2901. return $new_html;
  2902. }
  2903. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  2904. $generate_thumbs=false, &$table_out, $hide_long = false){
  2905. $this->ConvertPost($post);
  2906. if($generate_anchor){ $this->CreatePostAnchor($post); }
  2907. $ht = $post['html'];
  2908. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  2909. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  2910. "<p class='bold'>".$post['product']['title']."</p>".
  2911. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  2912. "<p class='smaller bold'>".$post['product']['price']."</p>";
  2913. return $ht;
  2914. }
  2915. if($hide_long){
  2916. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  2917. }else{
  2918. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  2919. }
  2920. if ($strip_tags){
  2921. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  2922. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  2923. $ht = "<div class='post_ref_main'>".$ht."</div>";
  2924. }
  2925. else{
  2926. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  2927. if($table_out!=$this->NULL_POST){
  2928. $table = NULL; $ht = $this->ExtractBigTables($ht,$table);
  2929. $table_out = $table;
  2930. }else{
  2931. $ht = preg_replace('/<p>\s*\{big_table\}\s*<\/p>/u','',$ht);
  2932. }
  2933. }
  2934. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  2935. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  2936. foreach($post['images'] as $im){
  2937. $ht.="<li class='file_thumb'>".$im."</li>";
  2938. }
  2939. $ht.="</ul></div>";
  2940. }
  2941. return $ht;
  2942. }
  2943. function MakeSinglePostExp(&$post){
  2944. $big_table = ""; ?>
  2945. <li class='post post_dummy'>
  2946. <?=$this->GenerateSinglePost($post, false, false, true, false, $big_table, false); ?>
  2947. </li>
  2948. <?php if($big_table!=$this->NULL_POST) echo "</ul></li><div class='table_top'>".$big_table.'</div>';?>
  2949. <?php
  2950. }
  2951. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  2952. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  2953. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  2954. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  2955. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  2956. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  2957. $big_table = ($show_thread_link)?$this->NULL_POST:"";
  2958. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  2959. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  2960. ?>
  2961. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  2962. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?><?=$side?" post_box":""?>'
  2963. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  2964. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?> >
  2965. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  2966. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  2967. <?php } ?>
  2968. <?php if($is_top){?>
  2969. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  2970. <?php } ?>
  2971. <?php if(!$side && $show_link){ ?>
  2972. <a href='?post=<?=$post['id']?>' onclick='ShowWaitingBar()'>
  2973. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2974. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"→")?>
  2975. </div>
  2976. <?php if($ref_count){ ?>
  2977. <div class='post_access ref_count'><?=$ref_count?></div>
  2978. <?php } ?>
  2979. </a>
  2980. <?php } ?>
  2981. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  2982. <div class='<?=$side?"":($show_link?'post_width':'post_width_big')?><?=$is_deleted?" deleted_post":""?>'>
  2983. <?php if(!$side && !$strip_tags){?>
  2984. <div class='post_menu_button _menu_hook' >+</div>
  2985. <?php } if($is_product&&!$generate_anchor){
  2986. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  2987. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  2988. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  2989. $generate_thumb,$big_table,($show_thread_link||$side||$force_hide_long)); ?>
  2990. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  2991. </div>
  2992. <?=$side?"</a>":""?> <?php
  2993. if(!$show_thread_link && $big_table!=$this->NULL_POST && !$side){
  2994. echo "</ul></li><div class='table_top'>".$big_table.'</div>';
  2995. ?><ul class='print_column'>
  2996. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  2997. <?php
  2998. }
  2999. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  3000. $post['tid']['first']['id']!=$post['id']){ ?>
  3001. <div class='gray smaller block opt_compact post'>
  3002. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  3003. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  3004. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  3005. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  3006. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true,$this->NULL_POST,true);?>
  3007. </div>
  3008. </div>
  3009. <?php }
  3010. if($show_reply_count && isset($post['tid'])){ ?>
  3011. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  3012. <?=$this->T('个回复')?></a>
  3013. <?php }
  3014. ?>
  3015. </li>
  3016. <?php
  3017. }
  3018. function MakePostingFields($reply_to=NULL, $show_hint=false){
  3019. if(isset($this->WayBack)){ ?>
  3020. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  3021. <?php return; } ?>
  3022. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  3023. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  3024. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  3025. <div id='post_hint_modify' style='display:none;'>
  3026. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  3027. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  3028. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  3029. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  3030. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3031. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3032. onclick='ShowWaitingBar();' />
  3033. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3034. <div style='float:right;'>
  3035. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3036. <?=$this->T('清空')?></a>
  3037. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3038. </div>
  3039. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3040. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3041. <?php if($reply_to){ ?>
  3042. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3043. <?php } ?>
  3044. <?php
  3045. }
  3046. function MakeCommentPosts(){
  3047. if(!$this->LoggedIn) return; ?>
  3048. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3049. <?php if(!$this->CommentEnabled){
  3050. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3051. <div class='comment'><ul>
  3052. <?php $i=0;
  3053. foreach(array_reverse($this->Posts) as $p){
  3054. if(!isset($p['comment_to'])) continue;
  3055. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3056. $ht = $this->GenerateSinglePost($p, false, false, false, false, $t, false);
  3057. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3058. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3059. if(!$post_to) $post_title = "?";
  3060. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3061. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3062. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3063. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3064. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3065. $i++;
  3066. }
  3067. ?>
  3068. </ul><br /></div>
  3069. <?php
  3070. }
  3071. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  3072. <div class='center' id='div_center'>
  3073. <h2><?=isset($search_term)?$this->T('搜索'):
  3074. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3075. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3076. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3077. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  3078. <?php if(isset($search_term)){ ?>
  3079. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  3080. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3081. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3082. <?php }else if(isset($category)){ ?>
  3083. <div></div>
  3084. <?php }else if($this->LoggedIn){ ?>
  3085. <div class='post_box_top _input_bundle'>
  3086. <?php $this->MakePostingFields(NULL,false); ?>
  3087. </div>
  3088. <?php } ?>
  3089. <ul class='print_column list'>
  3090. <?php
  3091. if(!isset($search_term) && !isset($category) &&
  3092. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3093. $this->CanShowPost($p)){
  3094. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  3095. }
  3096. $i = 0;
  3097. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3098. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3099. if(isset($p['tid'])){ /* Should always be set. */
  3100. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3101. if(!isset($search_term)) { $p = &$th['last']; }
  3102. }
  3103. if(isset($search_term)){
  3104. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3105. }else if(isset($category)){
  3106. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3107. (isset($p['categories'])?($p['categories']):[]);
  3108. if ($category=='none') { if($cat!=[]) continue; }
  3109. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3110. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3111. }else{
  3112. if(in_array($p['id'],
  3113. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  3114. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3115. }
  3116. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3117. $this->MakeSinglePost($p, true, false, NULL, false, !isset($search_term), false, false, false, false, isset($search_term));
  3118. $i++;
  3119. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3120. }?>
  3121. </ul>
  3122. <div class='page_selector clean_a'>
  3123. <hr />
  3124. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  3125. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3126. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3127. <?=$this->CurrentOffset+1?>
  3128. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  3129. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3130. → <?=$this->T('下一页')?></a>
  3131. </div>
  3132. </div>
  3133. <?php
  3134. }
  3135. function MakeHotPosts($placeholder_only=false){?>
  3136. <div class='left hidden_on_mobile' id='div_left'>
  3137. <?php if ($placeholder_only){ ?>&nbsp;
  3138. <?php }else{ ?>
  3139. <h2><?=$this->T('热门')?></h2>
  3140. <ul>
  3141. <?php
  3142. $i=0;
  3143. foreach($this->Threads as &$th){
  3144. if(!isset($th['first']) || $th['count']==0){ continue; }
  3145. if(!$this->CanShowPost($th['first'])) continue;
  3146. if($i>=$this->HotPostCount) break;
  3147. $this->MakeSinglePost($th['first'], false, true, "post_preview", true, false, true, false, true, false, false);
  3148. $i++;
  3149. } ?>
  3150. </ul>
  3151. <?php } ?>
  3152. </div>
  3153. <?php
  3154. }
  3155. function MakeLinkedPosts(&$p){
  3156. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3157. <div class='left hidden_on_mobile' id='div_left'>
  3158. <h2<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h2>
  3159. <?php
  3160. if($has_ref){ ?>
  3161. <span class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></span>
  3162. <ul><?php $count_product=0;
  3163. foreach(array_reverse($p['refs']) as &$pr){
  3164. $po = $this->GetPost($pr); if(isset($post['mark_value']) && $po['mark_value']==5){ $count_product++; continue; }
  3165. if(!$this->CanShowPost($po)){ continue; }
  3166. $this->MakeSinglePost($po, false, true, "post_preview", true, false, false, false, true, false, false);
  3167. }
  3168. ?></ul>
  3169. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3170. }else{ ?>
  3171. <span class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></span>
  3172. <?php } ?>
  3173. </div>
  3174. <?php
  3175. }
  3176. function MakeLinkedPostsExp(&$p){
  3177. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3178. <div class='center_exp post_dummy smaller'>
  3179. <hr />
  3180. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3181. <?php
  3182. if($has_ref){ ?>
  3183. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3184. <ul><?php $count_product=0;
  3185. foreach(array_reverse($p['refs']) as &$pr){
  3186. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3187. "</a></li>";
  3188. }
  3189. ?></ul>
  3190. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3191. }else{ ?>
  3192. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3193. <?php } ?>
  3194. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3195. </div>
  3196. <?php
  3197. }
  3198. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3199. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3200. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3201. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3202. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3203. if(!isset($title)) $title=$this->T('未命名');
  3204. if(!isset($ah)){ ?>
  3205. <h2><?=$this->T('没有历史记录')?></h2>
  3206. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3207. <?php }else{ ?>
  3208. <h2><?=$this->T('历史记录')?></h2>
  3209. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3210. <div class='list'><ul>
  3211. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3212. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3213. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3214. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3215. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3216. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3217. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3218. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3219. <?=$this->GetPostTitle($ver);?></a>
  3220. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3221. <?php } ?></ul><?php } ?>
  3222. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3223. $mah = &$this->GetArchiveHandle($pm);
  3224. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3225. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3226. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3227. <?php } ?>
  3228. </li><?php } ?>
  3229. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3230. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3231. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3232. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3233. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3234. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3235. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3236. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3237. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3238. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3239. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3240. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3241. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3242. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3243. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3244. <?=$this->GetPostTitle($ver);?></a>
  3245. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3246. <?php } ?></ul></li><?php } ?>
  3247. <?php } ?></ul></div>
  3248. <?php } ?>
  3249. <?php
  3250. }
  3251. function MakePostDiff(&$this_ver, &$last_ver){
  3252. if(!isset($this_ver)){ ?>
  3253. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3254. <?php }else{ ?>
  3255. <h2><?=$this->T('差异')?></h2>
  3256. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3257. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3258. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3259. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3260. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3261. <?php }else{ ?>
  3262. <table class='diff_table'><thead>
  3263. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3264. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3265. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3266. </thead><tbody>
  3267. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3268. </tbody>
  3269. </table>
  3270. <?php } ?>
  3271. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3272. <?php } ?>
  3273. <?php
  3274. }
  3275. function MakePostHistory(&$post, $version=NULL){
  3276. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3277. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3278. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3279. ?>
  3280. <div class='left hidden_on_mobile history' id='div_left'>
  3281. <?php if (isset($version)){
  3282. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3283. }else{ echo "&nbsp;"; } ?>
  3284. </div>
  3285. <div class='center history' id='div_center'>
  3286. <?php if (!isset($version)){
  3287. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3288. }else{
  3289. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3290. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3291. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3292. $this->MakePostDiff($this_ver, $last_ver, $p);
  3293. } ?>
  3294. </div>
  3295. <?php
  3296. }
  3297. function MakeCommentSection(&$post){
  3298. if(!$this->CommentEnabled){ return; }
  3299. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3300. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3301. ?><div class='comment'>
  3302. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3303. <?php if($comment_count) { echo "<ul>";
  3304. foreach($to_post['comments'] as $p){
  3305. $ht = $this->GenerateSinglePost($p, false, false, false, false, $t, false);
  3306. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3307. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3308. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3309. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3310. }
  3311. echo "</ul>";
  3312. } else {
  3313. echo $this->T('还没有评论');
  3314. } ?>
  3315. <div class='hidden_on_print'>
  3316. <div class='spacer'></div>
  3317. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3318. method="post" style="display:none;" id="comment_form"></form>
  3319. <p><a class='text_highlight bold clean_a'
  3320. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3321. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3322. <div id='comment_box' style='display:none;'>
  3323. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3324. <table style='white-space:nowrap;'>
  3325. <tr><td colspan='2'>
  3326. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3327. oninput="CommentUpdated();" ></textarea>
  3328. </td></tr>
  3329. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3330. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3331. class='full_box' oninput="CommentUpdated();" /></td>
  3332. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3333. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3334. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3335. <tr><td colspan='2'>
  3336. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3337. class='full_box' oninput="CommentUpdated();" />
  3338. </td></tr>
  3339. <tr><td colspan='2'>
  3340. <div class='spacer'></div>
  3341. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3342. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3343. </td></tr>
  3344. </table></div>
  3345. <script>
  3346. const IsValidEmail = (email) => {
  3347. 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,}))$/);
  3348. };
  3349. function IsValidHttpUrl(string) {
  3350. let url; try{ url = new URL(string); } catch (_) { return false; }
  3351. return url.protocol === "http:" || url.protocol === "https:";
  3352. }
  3353. var cbox = document.getElementById('comment_box');
  3354. var cemail = document.getElementById('comment_email');
  3355. var cname = document.getElementById('comment_name');
  3356. var clink = document.getElementById('comment_link');
  3357. var cconfirm = document.getElementById('comment_confirm');
  3358. function CommentUpdated(){
  3359. cconfirm.disabled=true;
  3360. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3361. cbox.innerText.length>2 && cname.value.length>2 &&
  3362. clink.value=="" || IsValidHttpUrl(clink.value)){
  3363. cconfirm.removeAttribute("disabled");
  3364. }
  3365. }
  3366. CommentUpdated();
  3367. </script>
  3368. </div>
  3369. </div>
  3370. <?php
  3371. }
  3372. function MakeInterestingSection(&$th){
  3373. $this->Anchors = [];
  3374. $c = &$th['first']['content'];
  3375. $this->ConvertPost($th['first']);
  3376. $ht = $th['first']['html'];
  3377. ?>
  3378. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3379. <div class='center_full' id='div_center'>
  3380. <?php $this->MakePostTools(); ?>
  3381. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3382. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3383. <ul><li class='post post_width_big' data-post-id='<?=$th['first']['id']?>'>
  3384. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3385. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3386. <?php foreach($th['first']['refs'] as $ref){
  3387. $po = $this->GetPost($ref);
  3388. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3389. if(!$this->CanShowPost($po)){ continue; }
  3390. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3391. } ?>
  3392. </ul><?php } ?>
  3393. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3394. <div class='post_width_big hidden_on_print'><br />
  3395. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3396. </div>
  3397. <?php } ?>
  3398. <table><thead><tr><th></th><?php foreach($th['interesting'] as $header){ ?>
  3399. <th><?=$this->T($header);?></th>
  3400. <?php } ?></tr></thead><tbody class='interesting_tbody'>
  3401. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3402. foreach($plist as &$p){
  3403. $this->ConvertPost($p);
  3404. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3405. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3406. $is_current = $p['id']==$this->CurrentPostID;
  3407. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3408. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3409. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3410. onDblClick='ClickImage(this)'><td>
  3411. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3412. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3413. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3414. </div>
  3415. <?php if($ref_count){ ?>
  3416. <div class='post_access ref_count'><?=$ref_count?></div>
  3417. <?php } ?></a>
  3418. <?=$p['html'];?>
  3419. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a></td></tr>
  3420. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3421. <?php foreach($p['refs'] as $ref){
  3422. $po = $this->GetPost($ref);
  3423. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3424. if(!$this->CanShowPost($po)){ continue; }
  3425. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3426. } ?>
  3427. </ul></td></tr><?php } ?>
  3428. <?php } ?>
  3429. </tbody></table>
  3430. </li></ul>
  3431. <br />
  3432. <?php $this->MakeCommentSection($th['first']); ?>
  3433. </div>
  3434. <?php return true;
  3435. }
  3436. function CssNumberID($id){
  3437. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3438. }
  3439. function MakePostTools(){
  3440. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3441. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3442. <?=$this->T('工具')?></a>:<div class='hidden_on_mobile' style='display:inline'>
  3443. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3444. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3445. </div>
  3446. <select class='hidden_on_desktop' id='merge_select'
  3447. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3448. <option value='-1' selected>--</option>
  3449. <option value='1'><?=$this->T('合并帖子')?></option>
  3450. <option value='2'><?=$this->T('合并话题')?></option></select>
  3451. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3452. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3453. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3454. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3455. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3456. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3457. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3458. </div><div class='spacer'></div><?php
  3459. }
  3460. }
  3461. function MakePostSection(&$post){
  3462. $this->Anchors = [];
  3463. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3464. <div class='center' id='div_center'>
  3465. <h2 class='hidden_on_print'>
  3466. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1; if($is_thread){ $th = $post['tid'];?>
  3467. <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3468. <?php } ?></h2>
  3469. <?php $cat = NULL;
  3470. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3471. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3472. $this->MakePostTools();
  3473. if($cat){ ?>
  3474. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3475. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3476. <?php } ?>
  3477. <ul class='print_column'>
  3478. <?php $is_reversed=false;
  3479. if($is_thread){
  3480. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  3481. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3482. foreach($use_arr as &$p){
  3483. $use_class = ($p == $post)?'focused_post':'';
  3484. $show_link = ($p == $post)?false:true;
  3485. $make_title = ($p == $post);
  3486. $this->MakeSinglePost($p,$show_link,false,$use_class,false, false, false, true, false, false);
  3487. if($make_title){?>
  3488. <script>
  3489. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3490. </script>
  3491. <?php } if($is_reversed && !$hinted){ ?>
  3492. <li class='gray smaller bold' style='text-align:center;'>
  3493. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3494. <?php $hinted = true;
  3495. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3496. <div class='post_width_big hidden_on_print'>
  3497. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3498. <?php } }
  3499. }
  3500. }else{
  3501. $this->MakeSinglePost($post,false, false, 'focused_post',false, false, false, true, false, false);
  3502. ?><script>
  3503. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3504. </script><?php
  3505. } ?>
  3506. <div class='smaller align_right'>
  3507. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3508. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3509. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3510. </div>
  3511. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  3512. <div class='post_width_big hidden_on_print'>
  3513. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3514. </div>
  3515. <?php }
  3516. $this->MakeCommentSection($post);
  3517. ?>
  3518. </ul>
  3519. </div>
  3520. <?php
  3521. }
  3522. function MakePostSectionExp(&$post){
  3523. $this->Anchors = []; $is_thread = isset($post['tid']);
  3524. ?>
  3525. <div class='center_exp' id='div_center'>
  3526. <ul>
  3527. <?php $is_reversed=false;
  3528. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th);
  3529. $hinted=false; if($is_reversed){
  3530. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3531. foreach($use_arr as &$p){
  3532. $this->MakeSinglePostExp($p);
  3533. if($p == $th['first']){?>
  3534. <script>
  3535. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3536. </script>
  3537. <?php } if($is_reversed && !$hinted){ ?>
  3538. <li class='gray smaller bold' style='text-align:center;'>
  3539. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3540. <?php $hinted = true; }
  3541. }
  3542. }else{
  3543. $this->MakeSinglePostExp($post);
  3544. ?><!--<script>
  3545. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3546. </script>--><?php
  3547. } ?>
  3548. </ul>
  3549. </div>
  3550. <?php
  3551. }
  3552. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  3553. <div class='here_image_box clean_a'>
  3554. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  3555. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  3556. <?php if($image_okay){ ?>
  3557. <?php if(isset($im['video']) && isset($im['video'])!=""){ ?>
  3558. <video controls><source src='<?=$im['file'];?>' type='<?=$im['video']?>'></video>
  3559. <?php }else{ ?>
  3560. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  3561. <?php } ?>
  3562. <?php } $this->MakeHereButtons($im, false); ?>
  3563. </div>
  3564. <?php }
  3565. function MakeSideGalleryCode(){?>
  3566. <div>
  3567. <h3><?=$this->T('点击图片以插入:')?></h3>
  3568. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3569. <option value="main"><?=$this->T('全部')?></option>
  3570. <?php if($this->LoggedIn){ ?>
  3571. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3572. <?php }?>
  3573. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3574. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3575. <?php } ?>
  3576. </select>
  3577. <div id='side_gallery'>
  3578. </div>
  3579. </div>
  3580. <script>
  3581. function InsertImage(imgname){
  3582. t = document.querySelector("#post_content");
  3583. v = t.value;
  3584. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3585. la_auto_grow(t);
  3586. }
  3587. function RefreshSideGallery(){
  3588. let xhr = new XMLHttpRequest();
  3589. xhr.onreadystatechange = (function(){
  3590. if (this.readyState === this.DONE) {
  3591. if (this.status === 200) {
  3592. ind = document.querySelector("#side_gallery");
  3593. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3594. str = "<ul class='side_thumb'>"
  3595. for (const m of res) {
  3596. imgstr = "<img src='"+m[2]+"' />";
  3597. if(m[2].match('\.mp4')){
  3598. imgstr = "<video><source src='"+m[2]+"'></video>";
  3599. }
  3600. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+imgstr+"</div>"
  3601. }
  3602. str += "</ul>"
  3603. ind.innerHTML = str;
  3604. }
  3605. }
  3606. }
  3607. });
  3608. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3609. xhr.send();
  3610. }
  3611. </script>
  3612. <?php
  3613. }
  3614. function MakeUploader($is_side=false){ ?>
  3615. <div id='upload_operation_area' class='hidden_on_print'>
  3616. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3617. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3618. <ul id='file_list'>
  3619. </ul>
  3620. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3621. </div>
  3622. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3623. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3624. <script>
  3625. function pastehandler(event){
  3626. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3627. for (index in items) {
  3628. var item = items[index];
  3629. if (item.kind === 'file') {
  3630. put = document.querySelector("#_uploader");
  3631. if(put) ShowSideUploader();
  3632. var blob = item.getAsFile();
  3633. AddImageFile(blob);
  3634. return;
  3635. }
  3636. }
  3637. }
  3638. let _fd_list = []; var uploading=0;
  3639. let hint=document.querySelector('#upload_hint');
  3640. function ToggleCompress(button){
  3641. li = button.parentNode;
  3642. num=li.dataset.number;
  3643. for(i=0;i<_fd_list.length;i++){
  3644. if (_fd_list[i][0] == num){
  3645. state = _fd_list[i][2];
  3646. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3647. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3648. }
  3649. }
  3650. }
  3651. function RemoveFromUpload(button){
  3652. li = button.parentNode;
  3653. num=li.dataset.number;
  3654. for(i=0;i<_fd_list.length;i++){
  3655. if (_fd_list[i][0] == num){
  3656. _fd_list.splice(i, 1);break;
  3657. }
  3658. }
  3659. li.parentNode.removeChild(li);
  3660. }
  3661. function EndThisUpload(){
  3662. unfinished = 0;
  3663. for(i=0;i<_fd_list.length;i++){
  3664. if (_fd_list[i][3]==0){
  3665. unfinished=1;
  3666. }
  3667. }
  3668. if(!unfinished){
  3669. uploading=0;
  3670. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3671. cl=document.querySelector('#upload_click');
  3672. if(!cl.dataset.isSide){
  3673. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3674. cl.href=window.location.href;
  3675. }else{
  3676. _fd_list.splice(0,_fd_list.length);
  3677. fl = document.querySelector("#file_list");
  3678. fl.innerHTML = "";
  3679. list=document.querySelector('#upload_operation_area');
  3680. list.style.pointerEvents='';
  3681. list.style.opacity='';
  3682. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3683. document.onpaste=pastehandler;
  3684. RefreshSideGallery();
  3685. }
  3686. }
  3687. }
  3688. function UploadList(){
  3689. if(!_fd_list.length || uploading) return;
  3690. uploading=1;
  3691. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3692. list=document.querySelector('#upload_operation_area');
  3693. list.style.pointerEvents='none';
  3694. list.style.opacity='0.5';
  3695. document.onpaste="";
  3696. for(i=0;i<_fd_list.length;i++){
  3697. let xhr = new XMLHttpRequest();
  3698. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3699. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3700. function wrap(li, i){
  3701. var ind = li.querySelector('._compress_toggle')
  3702. return function(){
  3703. if (this.readyState === this.DONE) {
  3704. if (this.status === 200) {
  3705. var response = xhr.responseText;
  3706. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3707. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3708. _fd_list[i][3] = 1;
  3709. }else{
  3710. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3711. _fd_list[i][3] = 1;
  3712. }
  3713. EndThisUpload();
  3714. }
  3715. }
  3716. }
  3717. }
  3718. xhr.onreadystatechange = wrap(li, i);
  3719. xhr.send(_fd_list[i][1]);
  3720. }
  3721. }
  3722. function AddImageFile(blob){
  3723. var ext="";
  3724. if(blob.name.match(/png$/))ext = 'png';
  3725. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3726. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3727. else if(blob.name.match(/gif$/))ext = 'gif';
  3728. else if(blob.name.match(/mp4$/))ext = 'mp4';
  3729. else return;
  3730. var fd = new FormData();
  3731. blob.name = blob.name=generateUID().toString();
  3732. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3733. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3734. var reader = new FileReader();
  3735. reader.onload = function(event){
  3736. fl = document.querySelector("#file_list");
  3737. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3738. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3739. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3740. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3741. fl.innerHTML+=ht;
  3742. };
  3743. reader.readAsDataURL(blob);
  3744. }
  3745. sel = document.querySelector('#upload_selector');
  3746. sel.addEventListener("change", function(){
  3747. var input = this;
  3748. function ff(file){
  3749. return function(e){
  3750. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3751. blob.name = file.name;
  3752. AddImageFile(blob);
  3753. }
  3754. }
  3755. for(i=0;i<input.files.length;i++){
  3756. if(input.files[i].size){
  3757. let reader = new FileReader();
  3758. reader.onload = ff(input.files[i]);
  3759. reader.readAsArrayBuffer(input.files[i]);
  3760. }
  3761. }
  3762. });
  3763. function generateUID() {
  3764. var firstPart = (Math.random() * 46656) | 0;
  3765. var secondPart = (Math.random() * 46656) | 0;
  3766. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3767. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3768. return firstPart + secondPart;
  3769. }
  3770. document.onpaste = pastehandler;
  3771. function dropHandler(ev) {
  3772. put = document.querySelector("#_uploader");
  3773. if(put) ShowSideUploader();
  3774. bkg=document.querySelector('#dropping_background');
  3775. bkg.style.display="none";
  3776. console.log('File(s) dropped');
  3777. ev.preventDefault();ev.stopPropagation();
  3778. if (ev.dataTransfer && ev.dataTransfer.items) {
  3779. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3780. if (ev.dataTransfer.items[i].kind === 'file') {
  3781. var file = ev.dataTransfer.items[i].getAsFile();
  3782. function ff(file){
  3783. return function(e){
  3784. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3785. blob.name = file.name;
  3786. AddImageFile(blob);
  3787. }
  3788. }
  3789. if(file){
  3790. let reader = new FileReader();
  3791. reader.onload = ff(file);
  3792. reader.readAsArrayBuffer(file);
  3793. }
  3794. }
  3795. }
  3796. } else {
  3797. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3798. function ff(file){
  3799. return function(e){
  3800. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3801. blob.name = file.name;
  3802. AddImageFile(blob);
  3803. }
  3804. }
  3805. if(ev.dataTransfer.files[i].size){
  3806. let reader = new FileReader();
  3807. reader.onload = ff(ev.dataTransfer.files[i]);
  3808. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3809. }
  3810. }
  3811. }
  3812. }
  3813. function dragOverHandler(ev) {
  3814. bkg=document.querySelector('#dropping_background');
  3815. bkg.style.display="";
  3816. console.log('File(s) in drop zone');
  3817. ev.preventDefault();
  3818. }
  3819. </script>
  3820. <?php
  3821. }
  3822. function CanShowGallery(&$g){
  3823. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  3824. return true;
  3825. }
  3826. function CanShowImage(&$im){
  3827. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3828. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3829. }
  3830. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3831. return true;
  3832. }
  3833. function MakeGallerySection(){
  3834. if(!isset($_GET['gallery'])) return;
  3835. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3836. $name=$_GET['gallery'];}?>
  3837. <script>
  3838. document.title+=" | <?=$this->T('画廊')?>";
  3839. </script>
  3840. <div class='center_wide' id='div_center' style='position:relative;'>
  3841. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3842. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3843. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3844. <div class='hidden_on_desktop'>
  3845. <?=$this->T('前往')?>
  3846. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  3847. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3848. if(!isset($g['featured']) || !$g['featured'] ||
  3849. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3850. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3851. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3852. <?php } ?>
  3853. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  3854. <?php if($this->LoggedIn){ ?>
  3855. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  3856. <?php } ?>
  3857. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3858. if((isset($g['featured']) && $g['featured']) ||
  3859. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3860. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3861. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3862. <?php } ?>
  3863. </select>
  3864. </div>
  3865. <?php if($this->LoggedIn){?>
  3866. <div>
  3867. <?php if(isset($name)){ ?>
  3868. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  3869. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  3870. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  3871. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  3872. <?=$this->T('取消精选')?></a>
  3873. <?php }else{ ?>
  3874. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  3875. <?=$this->T('设为精选')?></a>
  3876. <?php } ?><br />
  3877. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  3878. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  3879. <?=$this->T('取消实验')?></a>
  3880. <?php }else{ ?>
  3881. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  3882. <?=$this->T('设为实验')?></a>
  3883. <?php } ?>
  3884. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  3885. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  3886. <a href='javascript:HidePopMenu();'>×</a>
  3887. <hr />
  3888. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  3889. </div>
  3890. </div>
  3891. <?php } ?>
  3892. <?php $this->MakeUploader(false); ?>
  3893. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  3894. <div style='position:relative'>
  3895. <?php if(isset($name)){ ?>
  3896. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  3897. <?php } ?>
  3898. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  3899. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  3900. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  3901. method="post" style='display:none;' id='gallery_edit_form'></form>
  3902. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  3903. <a href='javascript:HidePopMenu();'>×</a>
  3904. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  3905. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  3906. <input class='button' type='submit' form='gallery_edit_form'
  3907. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  3908. </div>
  3909. </div>
  3910. </div>
  3911. <div class='smaller hidden_on_print'>
  3912. <form action="<?=$_SERVER['REQUEST_URI']?>"
  3913. method="post" style='display:none;' id='gallery_move_form'></form>
  3914. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  3915. id='gallery_move_ops' style='display:none'>
  3916. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  3917. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  3918. <p><?=$this->T('添加到')?>
  3919. <select id="gallery_move_to">
  3920. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3921. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3922. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  3923. <?php } ?>
  3924. </select>
  3925. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  3926. </p>
  3927. <p>
  3928. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  3929. </p>
  3930. </div>
  3931. </div>
  3932. <?php } ?>
  3933. <p>&nbsp;</p>
  3934. <div>
  3935. <?php $opened=0; $prev_year=""; if(isset($this->Images[0])) foreach($this->Images as $im){
  3936. if(!$this->CanShowImage($im)){ continue; }
  3937. if($_GET['gallery']=='trash') $name='trash';
  3938. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;}
  3939. $year = substr($im['name'], 0, 4);
  3940. if($year!=$prev_year){
  3941. if($opened) { ?><div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div></div><?php } ?>
  3942. <div><h2 class='sticky_title'><?=$year;?></h2><div class='p_row'><?php $prev_year=$year; $opened=1; } ?>
  3943. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  3944. <?php if($this->LoggedIn){ ?>
  3945. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3946. <?php } ?>
  3947. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  3948. <?php if(isset($im['video']) && $im['video']!=""){ ?>
  3949. <video data-imgsrc='<?=$im["name"]?>'><source src='<?=$im['file']?>' type='<?=$im['video']?>'></video>
  3950. <?php }else{ ?>
  3951. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  3952. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  3953. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>/>
  3954. <?php } ?>
  3955. </a>
  3956. </div>
  3957. <?php } if($opened) { ?>
  3958. <div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div><?php } ?>
  3959. </div>
  3960. </div>
  3961. <?php if($this->LoggedIn){ ?>
  3962. <script type='text/javascript'>
  3963. var selected_image = new Array();
  3964. function RemoveFromGallery(){
  3965. form = document.querySelector('#gallery_move_form');
  3966. ops = document.querySelector('#gallery_move_ops');
  3967. sel = document.querySelector('#gallery_move_to');
  3968. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  3969. form.submit();
  3970. }
  3971. function AddToGallery(){
  3972. form = document.querySelector('#gallery_move_form');
  3973. ops = document.querySelector('#gallery_move_ops');
  3974. sel = document.querySelector('#gallery_move_to');
  3975. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  3976. form.submit();
  3977. }
  3978. function ClearSelectedImages(){
  3979. selected_image.splice(0, selected_image.length);
  3980. checks = document.querySelectorAll('._select_hook');
  3981. [].forEach.call(checks, function(c){
  3982. c.classList.remove('p_thumb_selected');
  3983. });
  3984. count = document.querySelector('#gallery_selected_count');
  3985. count.innerHTML="0";
  3986. }
  3987. function ToggleSelectImage(elem, name){
  3988. count = document.querySelector('#gallery_selected_count');
  3989. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  3990. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  3991. count.innerHTML=selected_image.length.toString()
  3992. }
  3993. function ShowGalleryEditMenu(old_name){
  3994. m = document.querySelector('#gallery_edit_menu');
  3995. old = document.querySelector('#gallery_edit_old_name');
  3996. newname = document.querySelector('#gallery_edit_new_name');
  3997. m.style.display='block';
  3998. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  3999. }
  4000. function ShowDeleteMenu(){
  4001. m=document.querySelector('#gallery_delete_menu');
  4002. m.style.display='block';
  4003. }
  4004. </script>
  4005. <?php } ?>
  4006. <?php
  4007. }
  4008. function MakeGalleryLeft(){?>
  4009. <div class='left hidden_on_mobile gallery_left' id='div_left'>
  4010. <h2><?=$this->T('相册')?></h2>
  4011. <div>
  4012. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  4013. <ul>
  4014. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4015. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  4016. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4017. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  4018. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4019. <?php } ?>
  4020. </ul>
  4021. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  4022. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  4023. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  4024. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  4025. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  4026. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  4027. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  4028. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  4029. <?php } ?>
  4030. <?php if($this->LoggedIn){ ?>
  4031. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  4032. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  4033. <?php } ?>
  4034. </ul></div>
  4035. <p>&nbsp;</p>
  4036. <script>
  4037. </script>
  4038. </div>
  4039. </div>
  4040. <?php
  4041. }
  4042. function MakeTOC(){?>
  4043. <div class='right hidden_on_mobile' id='div_right'>
  4044. <?php if(isset($this->Anchors[0])){?>
  4045. <h2><?=$this->T('目录')?></h2><ul>
  4046. <?php
  4047. foreach($this->Anchors as $a){?>
  4048. <li class='toc_entry_<?=$a[0]>5?5:$a[0]?>'><a href='#<?=$a[1]?>'>
  4049. <?=$this->T($this->ChoosePartsByLanguage($a[2]))?></a></li>
  4050. <?php }
  4051. ?></ul>
  4052. <?php }else{ ?>
  4053. <h2 class='gray'><?=$this->T('目录')?></h2>
  4054. <span class='gray smaller'><?=$this->T('未找到目录')?></span>
  4055. <?php } ?>
  4056. </div>
  4057. <?php
  4058. }
  4059. function MakeSettings(){?>
  4060. <div class='settings'>
  4061. <h2><?=$this->T('设置')?></h2>
  4062. <table style='white-space:nowrap;'>
  4063. <?php if($this->LoggedIn){ ?>
  4064. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4065. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4066. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4067. <tr><td><?=$this->T('网站标题')?></td>
  4068. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4069. value='<?=$this->Title?>'/></td></tr>
  4070. <tr><td><?=$this->T('短标题')?></td>
  4071. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4072. value='<?=$this->ShortTitle?>'/></td></tr>
  4073. <tr><td><?=$this->T('显示名称')?></td>
  4074. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4075. value='<?=$this->DisplayName?>'/></td></tr>
  4076. <tr><td><?=$this->T('电子邮件')?></td>
  4077. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4078. value='<?=$this->EMail?>'/></td></tr>
  4079. <tr><td><?=$this->T('导航栏')?>
  4080. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4081. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4082. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4083. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4084. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4085. value='<?=$this->SpecialFooter?>'/></td></tr>
  4086. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4087. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4088. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4089. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4090. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4091. value='<?=$this->SpecialPinned?>'/></td></tr>
  4092. <tr><td><?=$this->T('默认相册')?></td>
  4093. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4094. value='<?=$this->DefaultGallery?>'/></td></tr>
  4095. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4096. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4097. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4098. <tr><td><?=$this->T('启用评论')?></td>
  4099. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4100. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4101. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  4102. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4103. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4104. <tr><td><?=$this->T('长毛象实例')?></td>
  4105. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4106. value='<?=$this->MastodonURL?>'/></td></tr>
  4107. <tr><td><?=$this->T('长毛象令牌')?></td>
  4108. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4109. value='<?=$this->MastodonToken?>'/></td></tr>
  4110. <tr><td><?=$this->T('偏好语言')?></td>
  4111. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4112. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4113. <tr><td><?=$this->T('本站地址')?></td>
  4114. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4115. value='<?=$this->HostURL?>'/></td></tr>
  4116. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4117. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4118. <tr><td><?=$this->T('用户名')?></td>
  4119. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4120. value='<?=$this->APubID?>'/></td></tr>
  4121. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4122. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4123. <tr><td><?=$this->T('主机')?></td>
  4124. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4125. value='<?=$this->HereHost?>'/></td></tr>
  4126. <tr><td><?=$this->T('网站标题')?></td>
  4127. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4128. value='<?=$this->HereTitle?>'/></td></tr>
  4129. <tr><td><?=$this->T('短标题')?></td>
  4130. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4131. value='<?=$this->HereShortTitle?>'/></td></tr>
  4132. <tr><td><?=$this->T('相册')?></td>
  4133. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4134. value='<?=$this->HereAlbum?>'/></td></tr>
  4135. <tr><td><?=$this->T('导航栏')?>
  4136. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4137. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4138. value='<?=$this->HereNavigation?>'/></td></tr>
  4139. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4140. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4141. value='<?=$this->HereFooter?>'/></td></tr>
  4142. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4143. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4144. <tr><td><?=$this->T('主机')?></td>
  4145. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4146. value='<?=$this->ExpHost?>'/></td></tr>
  4147. <tr><td><?=$this->T('网站标题')?></td>
  4148. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4149. value='<?=$this->ExpTitle?>'/></td></tr>
  4150. <tr><td><?=$this->T('短标题')?></td>
  4151. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4152. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4153. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4154. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4155. value='<?=$this->ExpCaution?>'/></td></tr>
  4156. <tr><td><?=$this->T('相册')?></td>
  4157. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4158. value='<?=$this->ExpAlbum?>'/></td></tr>
  4159. <tr><td><?=$this->T('导航栏')?>
  4160. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4161. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4162. value='<?=$this->ExpNavigation?>'/></td></tr>
  4163. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4164. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4165. value='<?=$this->ExpFooter?>'/></td></tr>
  4166. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4167. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4168. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  4169. <tr><td><?=$this->T('帐号')?></td>
  4170. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4171. value='<?=$this->Admin?>'/></td></tr>
  4172. <tr><td><?=$this->T('新密码')?></td>
  4173. <td><input type="password" form="settings_form"
  4174. id='settings_new_password' name='settings_new_password' /></td></tr>
  4175. <tr><td><?=$this->T('再次输入')?></td>
  4176. <td><input type="password" form="settings_form"
  4177. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4178. <tr><td><?=$this->T('旧密码')?></td>
  4179. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4180. <?php }else{ ?>
  4181. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4182. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4183. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4184. <tr><td><?=$this->T('帐号')?></td>
  4185. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4186. <tr><td><?=$this->T('密码')?></td>
  4187. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4188. <?php } ?>
  4189. </table>
  4190. <?php if($this->LoggedIn){ ?>
  4191. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4192. <?php }else{ ?>
  4193. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4194. <?php } ?>
  4195. </div>
  4196. <?php
  4197. }
  4198. function MakeExtraOperations(){?>
  4199. <div class='settings' style='overflow:auto;'>
  4200. <h2><?=$this->T('附加操作')?></h2>
  4201. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  4202. <p>&nbsp;</p>
  4203. <h3><?=$this->T('自动重定向')?></h3>
  4204. <span class='smaller gray'>
  4205. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4206. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4207. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4208. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  4209. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4210. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4211. value='<?=$this->T('保存重定向设置')?>' />
  4212. <p>&nbsp;</p>
  4213. <h3><?=$this->T('自定义翻译')?></h3>
  4214. <span class='smaller gray'>
  4215. <?=$this->T('填写格式:')?>
  4216. <br /><pre>- 语言 | Language</pre></span>
  4217. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4218. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  4219. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4220. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4221. value='<?=$this->T('保存翻译')?>' />
  4222. <p>&nbsp;</p>
  4223. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4224. <ul>
  4225. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  4226. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  4227. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  4228. </ui>
  4229. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4230. </div>
  4231. <?php
  4232. }
  4233. function MakeMainBegin(){?>
  4234. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4235. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4236. <?php
  4237. }
  4238. function MakeMainEnd(){?>
  4239. </div>
  4240. <?php
  4241. }
  4242. function MakeExpFooter(){?>
  4243. <div class='small_footer exp_h_f exp_f'><div>
  4244. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b>&nbsp;©<?=$this->T($this->DisplayName)?>
  4245. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4246. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4247. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4248. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4249. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4250. }?></div>
  4251. </div>
  4252. </div>
  4253. </div><!-- page -->
  4254. </body>
  4255. </html>
  4256. <script>
  4257. if(trans = document.getElementById('translate_button')){
  4258. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4259. }
  4260. </script>
  4261. <?php
  4262. }
  4263. function MakeImageOverlay($side_info=null,$static_image=null){
  4264. $static=isset($side_info); ?>
  4265. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  4266. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  4267. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  4268. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/>
  4269. <video id='big_video' onloadstart="HideWaitingBar();" controls><source id='big_video_src' type='video/mp4'></video>
  4270. </div>
  4271. <div class='big_side_box' onclick='HideBigImage(1);'>
  4272. <?php if(!$static){ ?>
  4273. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  4274. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  4275. <div class='lr_buttons'>←</div></a></div>
  4276. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  4277. <div class='lr_buttons'>→</div></a></div>
  4278. <div id='here_buttons'></div>
  4279. </div><?php } ?>
  4280. <div class='side_box_mobile_inner'>
  4281. <?php if(!$static){ ?>
  4282. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  4283. <span style='display:none;' id='image_purchase' class='clean_a'>
  4284. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  4285. <br class='hidden_on_desktop block_on_mobile' /></span>
  4286. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  4287. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4288. &nbsp;<a class='clean_a' id='image_inquiry'>
  4289. <b>@</b><?=$this->T('咨询')?></a>
  4290. <?php } ?><hr class='hidden_on_desktop block_on_mobile' />
  4291. </div>
  4292. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  4293. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  4294. <hr />
  4295. </div><?php } //static ?>
  4296. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  4297. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  4298. <br /><?=$this->T('印刷品链接')?>
  4299. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  4300. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  4301. <?=$this->T('重命名')?>
  4302. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  4303. <?=$this->T('主图')?>
  4304. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  4305. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  4306. <br /><br /><?=$this->T('替换图像')?>
  4307. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  4308. <input type="file" form='image_edit_form'
  4309. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  4310. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  4311. value=<?=$this->T('执行')?> />
  4312. </div><?php } ?>
  4313. </div>
  4314. </div>
  4315. </div>
  4316. <?php }
  4317. function MakePageEnd(){?>
  4318. </div><!-- page -->
  4319. </body>
  4320. </html>
  4321. <?php }
  4322. function MakeFooter(){?>
  4323. <div class='small_footer'><div>
  4324. <hr />
  4325. <b><?=$this->T($this->Title)?></b>
  4326. <span onclick='event.stopPropagation()'
  4327. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  4328. <div class='wayback_link clean_a invert_a hidden_on_print'><?php if(!isset($this->WayBack)){ ?>
  4329. - <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  4330. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?>
  4331. <br class='hidden_on_desktop' /> - <a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  4332. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a>
  4333. <br class='hidden_on_desktop' />
  4334. - <a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a>
  4335. </div>
  4336. </div></div>
  4337. <div class='footer'>
  4338. <div style='white-space:nowrap;'>
  4339. <div class='footer_additional'>
  4340. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  4341. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4342. } ?>
  4343. </div>
  4344. <div class='footer_additional'>
  4345. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  4346. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4347. } ?>
  4348. </div>
  4349. </div>
  4350. </div>
  4351. <p>&nbsp;<p>
  4352. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  4353. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  4354. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  4355. </div>
  4356. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  4357. <script>
  4358. <?=$this->ExtraScripts?>
  4359. if(back = document.getElementById('button_back')){
  4360. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  4361. back.href='javascript:history.back()';
  4362. }else{
  4363. back.href='index.php';
  4364. }
  4365. }
  4366. function copy_text(t) {
  4367. ta = document.createElement('textarea');
  4368. document.body.appendChild(ta);
  4369. ta.value = t;
  4370. ta.select();
  4371. document.execCommand("copy");
  4372. document.body.removeChild(ta);
  4373. }
  4374. if(trans = document.getElementById('translate_button')){
  4375. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4376. }
  4377. <?php if($this->LoggedIn){ ?>
  4378. var Scenter = document.querySelector('#div_center');
  4379. var Sposts = Scenter.querySelectorAll('.post');
  4380. <?php if(isset($this->MastodonToken)){ ?>
  4381. function MarkPostDoneMastodon(id,mastodon_url){
  4382. for(var i=0;i<Sposts.length;i++){
  4383. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  4384. }
  4385. <?php } ?>
  4386. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  4387. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  4388. var Smerge_post = Scenter.querySelector('#merge_post');
  4389. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  4390. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  4391. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  4392. var Smerge_select = Scenter.querySelector('#merge_select');
  4393. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  4394. var Smerge_thread = Scenter.querySelector('#merge_thread');
  4395. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  4396. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  4397. var select_mode = false; var merge_mode = false; var selected_posts = null;
  4398. function TogglePostSelectMode(force_on=false,force_off=false){
  4399. Scenter.classList.add('post_selecting');
  4400. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  4401. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  4402. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  4403. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  4404. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  4405. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4406. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  4407. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  4408. Smerge_post_count.innerText="0";
  4409. Smerge_post.href="#";
  4410. }
  4411. function TogglePostSelect(elem){
  4412. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  4413. else{ elem.classList.add('post_selected'); }
  4414. selected_posts = new Array();
  4415. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  4416. selected_posts.push(Sposts[i].dataset.postId); } }
  4417. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  4418. Smerge_post_count.innerText=selected_posts.length;
  4419. }
  4420. function ThreadMergeInput(elem){
  4421. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  4422. else{ Smerge_thread.href="#"; }
  4423. }
  4424. function ToggleThreadMerge(force_on=false,force_off=false){
  4425. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  4426. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  4427. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  4428. else{ merge_mode = 0;
  4429. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  4430. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4431. Smerge_thread.href="#";
  4432. Smerge_thread_target.value='';
  4433. }
  4434. <?php } ?>
  4435. function ShowSideUploader(){
  4436. ShowRightSide(true,null);
  4437. put = document.querySelector("#_uploader");
  4438. put.style.display='block';
  4439. RefreshSideGallery();
  4440. }
  4441. dmark = document.querySelector("#mark_details");
  4442. drename = document.querySelector("#rename_details");
  4443. dmastodon = document.querySelector("#mastodon_details");
  4444. drename_form = document.querySelector("#post_rename_form");
  4445. drename_input = document.querySelector("#post_rename_name");
  4446. var rp = document.querySelector('#post_reply_to');
  4447. var _reply_to = rp?rp.defaultValue:"";
  4448. function RestoreReply(){
  4449. if(rp){
  4450. rp.defaultValue = _reply_to;
  4451. }
  4452. document.querySelector('#post_reply_restore').style.display='none';
  4453. ht = document.querySelector('#post_hint_text');
  4454. if (_reply_to!=""){
  4455. ht.style.display='block';
  4456. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  4457. }else{
  4458. ht.style.display='none';
  4459. }
  4460. document.querySelector('#post_edit_target').value="";
  4461. ch = document.querySelector('#post_hint_modify');
  4462. ch.style.display='none';
  4463. }
  4464. function MakeRefer(id){
  4465. t = document.querySelector('#post_content')
  4466. t.focus();
  4467. v = t.value;
  4468. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  4469. la_auto_grow(t);
  4470. if(rp){
  4471. rp.defaultValue = "";
  4472. ht = document.querySelector('#post_hint_text');
  4473. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  4474. document.querySelector('#post_reply_restore').style.display='inline';
  4475. rs = document.querySelector('#post_reply_restore');
  4476. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  4477. document.getElementById('post_menu').style.display='none';
  4478. ch = document.querySelector('#post_hint_modify');
  4479. ch.style.display='none';
  4480. }
  4481. }
  4482. function CopyRefer(id){
  4483. copy_text(id.toString());
  4484. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  4485. }
  4486. function MakeEdit(id){
  4487. ed = document.getElementById('menu_edit');
  4488. ed.innerHTML="<?=$this->T('稍等')?>";
  4489. ed.href="#";
  4490. var xhr = new XMLHttpRequest();
  4491. xhr.onreadystatechange = function() {
  4492. if (this.readyState == 4 && this.status == 200) {
  4493. ed.innerHTML='——';
  4494. ch = document.querySelector('#post_hint_modify');
  4495. ch.style.display='block';
  4496. ht = document.querySelector('#post_hint_text');
  4497. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  4498. rs = document.querySelector('#post_reply_restore');
  4499. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  4500. t = document.querySelector('#post_content');
  4501. t.value=xhr.responseText.trim();
  4502. t.focus();
  4503. la_auto_grow(t);
  4504. document.querySelector('#post_edit_target').value=id;
  4505. document.getElementById('post_menu').style.display='none';
  4506. }
  4507. };
  4508. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4509. xhr.send();
  4510. }
  4511. function MarkDelete(id){
  4512. p = document.querySelector('[data-post-id="'+id+'"]');
  4513. op = p.dataset.markDelete?"false":"true";
  4514. window.location.href=
  4515. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4516. }
  4517. function SetMark(mark){
  4518. menu = document.getElementById('post_menu');
  4519. window.location.href=
  4520. "index.php?<?=$this->GetRedirect()?>&target="+
  4521. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4522. }
  4523. function ToggleMarkDetails(){
  4524. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  4525. drename.style.display=dmastodon.style.display='none';
  4526. }
  4527. function ToggleRenameDetails(){
  4528. drename.style.display=(drename.style.display=='block')?'none':'block';
  4529. dmark.style.display=dmastodon.style.display='none';
  4530. }
  4531. function ToggleMastodonDetails(){
  4532. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  4533. dmark.style.display=drename.style.display='none';
  4534. }
  4535. <?php } ?>
  4536. function ShowPostMenu(post){
  4537. menu = document.getElementById('post_menu');
  4538. menu.style.display='block';
  4539. menu.parentNode.removeChild(menu);
  4540. post.appendChild(menu);
  4541. menu.style.display='block';
  4542. id = post.dataset.postId
  4543. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4544. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4545. window.onClick="HidePopMenu()";
  4546. menu.onClick=(function(event){
  4547. event.stopPropagation();
  4548. });
  4549. hs = menu.querySelector('#menu_history');
  4550. hs.href='?post='+id+'&history=1';
  4551. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4552. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4553. ref = menu.querySelector('#menu_refer_copy')
  4554. ref.innerHTML='<?=$this->T("复制编号")?>';
  4555. ref.href='javascript:CopyRefer(id)';
  4556. ed = menu.querySelector('#menu_edit')
  4557. ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4558. d = menu.querySelector('#menu_delete');
  4559. d.href='javascript:MarkDelete(\"'+id+'\")';
  4560. p = document.querySelector('[data-post-id="'+id+'"]');
  4561. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4562. menu.querySelector('#mark_details').dataset.id=id;
  4563. drename_input.value=id;
  4564. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4565. <?php if(isset($this->MastodonToken)){ ?>
  4566. dmastodon_form = document.querySelector("#post_mastodon_form");
  4567. dmastodon_form.action='?mastodon_post='+id;
  4568. function MastodonSend(id){
  4569. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  4570. var xhr = new XMLHttpRequest();
  4571. function wrapidxhr(_id) { return function() {
  4572. if (this.readyState == 4 && this.status == 200) {
  4573. var response = xhr.responseText;
  4574. let content="";
  4575. if(res = response.match(/SUCCESS (\S+)/u)){
  4576. content="<?=$this->T('成功发送到长毛象')?>";
  4577. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  4578. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  4579. MarkPostDoneMastodon(_id, res[1]);
  4580. } }
  4581. };
  4582. xhr.onreadystatechange = wrapidxhr(id);
  4583. xhr.open("GET", "index.php?mastodon_send_post="+id, true); xhr.send();
  4584. }
  4585. menu_mastodon = menu.querySelector("#menu_mastodon");
  4586. mastodon_send = menu.querySelector("#menu_mastodon_send");
  4587. mastodon_view = menu.querySelector("#menu_mastodon_view");
  4588. mastodon_url = menu.querySelector("#post_mastodon_url");
  4589. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  4590. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  4591. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  4592. mastodon_url.value="";}
  4593. mastodon_send.onclick=function(){
  4594. this.onclick=function(){};
  4595. MastodonSend(id); };
  4596. <?php } } ?>
  4597. title = document.title;
  4598. copy = document.getElementById('share_copy');
  4599. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4600. copy.addEventListener("click", function(){
  4601. url = window.location
  4602. path = location.pathname
  4603. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4604. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4605. });
  4606. }
  4607. function HidePopMenu(){
  4608. var menus = document.querySelectorAll('.pop_menu');
  4609. [].forEach.call(menus, function(m){m.style.display='none';});
  4610. }
  4611. var posts = document.querySelectorAll('.center .post');
  4612. [].forEach.call(posts, function(p){
  4613. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4614. ShowPostMenu(this.parentNode.parentNode);
  4615. });
  4616. });
  4617. var post_clickables = document.querySelectorAll('.center .post a');
  4618. [].forEach.call(post_clickables, function(p){
  4619. p.addEventListener("click", function(event){
  4620. event.stopPropagation();
  4621. });
  4622. });
  4623. function FindImage(imgsrc){
  4624. for(var i=0;i<document.images_filtered.length;i++){
  4625. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4626. }
  4627. return null
  4628. }
  4629. var dottime1;
  4630. var dottime2;
  4631. function ToDataURL(url) {
  4632. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4633. clearTimeout(dottime1);clearTimeout(dottime2);
  4634. ps = document.querySelector('#download_processing');
  4635. ps.innerHTML='↓';ps.style.opacity='';
  4636. return URL.createObjectURL(blob);});
  4637. }
  4638. async function DownloadAsImage(url,name) {
  4639. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4640. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4641. }
  4642. function basename(url){return url.split(/[\\/]/).pop();}
  4643. pushed=0;
  4644. function ShowBigImage(imgsrc,do_push){
  4645. ShowWaitingBar();
  4646. share = document.querySelector('#big_image_share');
  4647. img = document.querySelector('#big_image');
  4648. vid = document.querySelector('#big_video');
  4649. vidsrc = document.querySelector('#big_video_src');
  4650. down = document.querySelector('#image_download');
  4651. img.src = ""; vidsrc.src="";
  4652. if(imgsrc.match(/\.mp4$/)){
  4653. vidsrc.src = src = "images/"+imgsrc; img.style.display='none'; vid.load();vid.style.display='block';
  4654. }else{
  4655. img.src = src = "images/"+imgsrc; vid.style.display='none';img.style.display='block';
  4656. }
  4657. down.href="images/"+imgsrc;
  4658. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_<?=$this->GiveSafeEMail()?>_'+
  4659. basename(down.href);
  4660. img.alt = downname; down.download=downname;
  4661. var use_href = "images/"+imgsrc;
  4662. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4663. ps = this.querySelector('#download_processing');ps.innerText='…';
  4664. var dotwait = function(ps){ var self = this;
  4665. dottime1 = setTimeout(function(ps){
  4666. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4667. dotwait(this.querySelector('#download_processing'));
  4668. DownloadAsImage(use_href,downname);};
  4669. if(do_push){PushGalleryHistory(src)}
  4670. page_url = encodeURIComponent(window.location.href);
  4671. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4672. inqb = document.querySelector('#image_inquiry');
  4673. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4674. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4675. (page_url)+encodeURIComponent('\n\n');
  4676. <?php } ?>
  4677. this_image = FindImage(imgsrc);
  4678. if(this_image&&this_image.dataset.prevsrc){
  4679. new_image = FindImage(this_image.dataset.prevsrc);
  4680. new_prev = new_image?new_image.dataset.prevsrc:null;
  4681. im = document.querySelector('#prev_image');
  4682. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4683. else {im.style.opacity='0';im.removeAttribute("href");}
  4684. }
  4685. if(this_image&&this_image.dataset.nextsrc){
  4686. new_image = FindImage(this_image.dataset.nextsrc);
  4687. new_next = new_image?new_image.dataset.nextsrc:null;
  4688. im = document.querySelector('#next_image');
  4689. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4690. else {im.style.opacity='0';im.removeAttribute("href");}
  4691. }
  4692. purchase = document.querySelector('#image_purchase');
  4693. purchase_btn = document.querySelector('#image_purchase_button');
  4694. <?php if($this->LoggedIn){ ?>
  4695. product_link = document.querySelector('#image_ops_product_link');
  4696. product_form = document.querySelector('#image_ops_form');
  4697. edit_form = document.querySelector('#image_edit_form');
  4698. edit_new_name = document.querySelector('#image_edit_new_name');
  4699. edit_parent = document.querySelector('#image_parent');
  4700. product_form.action = window.location.href;
  4701. edit_form.action = window.location.href;
  4702. edit_new_name.value = imgsrc.split('.')[0];
  4703. if(this_image&&this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  4704. if(this_image&&this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  4705. <?php } ?>
  4706. if(this_image&&this_image.dataset.product){
  4707. purchase.style.display='';
  4708. href = this_image.dataset.product;
  4709. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4710. href = '?post='+href;
  4711. }
  4712. purchase_btn.href = href;
  4713. }else{
  4714. purchase.style.display='none';
  4715. purchase_btn.removeAttribute("href");
  4716. }
  4717. DelayHideImgBtn(null);
  4718. title = encodeURIComponent(document.title);
  4719. copy = document.getElementById('big_share_copy');
  4720. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4721. copy.addEventListener("click", function(){
  4722. copy_text(window.location.href);
  4723. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4724. });
  4725. o = document.querySelector('#big_image_overlay');
  4726. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  4727. here = document.querySelector('#here_buttons');here.innerHTML='';
  4728. o.style.display="block";
  4729. ShowBackdrop(0.8);
  4730. var xhr = new XMLHttpRequest();
  4731. xhr.onreadystatechange = function() {
  4732. if (this.readyState == 4 && this.status == 200) {
  4733. info = document.querySelector('#big_image_info');
  4734. var response = xhr.responseText;
  4735. let content=""
  4736. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4737. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4738. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4739. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4740. content+="<div class='clean_a'>"+res[1]+"</div>"; }
  4741. info.innerHTML=content;
  4742. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  4743. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  4744. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  4745. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  4746. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  4747. }
  4748. }
  4749. };
  4750. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4751. xhr.send();
  4752. }
  4753. function HideBigImage(do_push){
  4754. o = document.querySelector('#big_image_overlay');
  4755. img = document.querySelector('#big_image');
  4756. vid = document.querySelector('#big_video');
  4757. vidsrc = document.querySelector('#big_video_src');
  4758. img.src = ""; vidsrc.src="";
  4759. if(o.style.display!='none'){
  4760. o.style.display="none";
  4761. HideBackdrop();
  4762. if(do_push){PushGalleryHistory("");}
  4763. HideWaitingBar();
  4764. }
  4765. }
  4766. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4767. var inq=document.querySelector('#inquiry_buttons');
  4768. var overlay=document.querySelector('#big_image_overlay');
  4769. var hide_timeout;
  4770. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4771. function DelayHideImgBtn(e){
  4772. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  4773. inq.classList.remove('img_btn_hidden');
  4774. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  4775. clearTimeout(hide_timeout);
  4776. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  4777. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  4778. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  4779. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  4780. }
  4781. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4782. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4783. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4784. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4785. var images = document.querySelectorAll('img, video');
  4786. var images_filtered=new Array(); var imgadded = new Array();
  4787. var images_remaining=new Array();
  4788. [].forEach.call(images, function(img){
  4789. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4790. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4791. images_filtered.push(img);imgadded.push(imgsrc);
  4792. });
  4793. for(var i=0; i<images_filtered.length; i++){
  4794. previmg = nextimg = null; img = images_filtered[i];
  4795. if(i>0) previmg=images_filtered[i-1];
  4796. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4797. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4798. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4799. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4800. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4801. }
  4802. for(var i=0; i<images_remaining.length; i++){
  4803. img = images_remaining[i];
  4804. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4805. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4806. }
  4807. document.images_filtered = images_filtered;
  4808. function PopGalleryHistory(){
  4809. if(pushed){
  4810. pushed = 0;
  4811. try{
  4812. history.back();
  4813. }catch{
  4814. console.log("can't do it.");
  4815. }
  4816. }
  4817. }
  4818. function PushGalleryHistory(src){
  4819. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  4820. title = "照片"
  4821. extra = "?";
  4822. sp = new URLSearchParams(window.location.search)
  4823. if(sp.has('post')){extra+="post="+sp.get('post')}
  4824. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  4825. try{
  4826. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  4827. }catch{
  4828. console.log("can't do it.");
  4829. }
  4830. pushed = 1;
  4831. }
  4832. document.addEventListener('keydown', function(e){
  4833. large = document.getElementById('big_image_overlay')
  4834. if (large.style.display!='block') return;
  4835. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  4836. HideBigImage(1);
  4837. }
  4838. }, true);
  4839. window.addEventListener('popstate', (event) => {
  4840. if(event.state){
  4841. let sp = new URLSearchParams(event.state)
  4842. if(sp.has('pic')){
  4843. src = sp.get('pic')
  4844. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)) ShowBigImage(onlyimg[0], 0);
  4845. else{HideBigImage(0);}
  4846. }
  4847. }else{HideBigImage(0);}
  4848. });
  4849. let searchParams = new URLSearchParams(window.location.search)
  4850. if(searchParams.has('pic')){
  4851. src = searchParams.get('pic')
  4852. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif|mp4)/u)){
  4853. ShowBigImage(onlyimg[0], 1);
  4854. }
  4855. }
  4856. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  4857. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  4858. </script>
  4859. </body>
  4860. <?php
  4861. }
  4862. function DoIdentiyExperimental(){
  4863. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  4864. $this->InExperimentalMode=True; $this->InHereMode=True;
  4865. }
  4866. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  4867. $this->InHereMode=True;
  4868. }
  4869. }
  4870. function DoExperimentalTopLink($p){
  4871. if($this->InHereMode && $p){
  4872. if(isset($p['tid']) && $p['tid']['first']!=$p){
  4873. header('Location: ?post='.$p['tid']['first']['id']); exit();
  4874. }
  4875. }
  4876. }
  4877. function MakeExperimentalConfirm(){
  4878. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  4879. return false;
  4880. }
  4881. $caution_html =
  4882. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  4883. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  4884. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  4885. ?>
  4886. <div class='center_exp'><?php
  4887. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  4888. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  4889. ?></div>
  4890. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  4891. <?php return true;
  4892. }
  4893. }
  4894. $la = new LA;
  4895. $la->DoSiteRedirect();
  4896. $la->DoLogin();
  4897. $la->SwitchLanguageAndFont();
  4898. $err = $la->ProcessRequest($message, $redirect);
  4899. $la->WriteAsNecessary();
  4900. $la->DoIdentiyExperimental();
  4901. $la->SwitchWayBackMode();
  4902. if($err){
  4903. echo $message;
  4904. exit();
  4905. }
  4906. if(isset($redirect)){
  4907. header('Location: '.$redirect);
  4908. exit();
  4909. }
  4910. $la->DetectPageType();
  4911. $la->ReadImages(false);
  4912. $la->ReadPosts();
  4913. if(isset($la->WayBack)){
  4914. $la->ReadArchive();
  4915. }
  4916. $im = NULL;
  4917. if(preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  4918. if(!$la->CanShowImage($im)) { $im=&$la->NULL_IMAGE; }
  4919. }
  4920. $p = &$la->GetPost($la->CurrentPostID);
  4921. if(!isset($p)){
  4922. $p = &$la->GetMergedPost($la->CurrentPostID);
  4923. }
  4924. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  4925. else{ $la->DoExperimentalTopLink($p); }
  4926. if(isset($p)){ $la->ActualPostID = $p['id']; }
  4927. if($la->PageType=='here' ||$la->PageType=='experimental'){
  4928. if($im){
  4929. $la->SetHereMainImage($im);
  4930. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  4931. }else if($p){
  4932. $la->RecordVisitedHere($p['id'],NULL);
  4933. }else {
  4934. $im = &$la->GiveImageInHere(false);
  4935. if($im){
  4936. $la->SetHereMainImage($im);
  4937. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  4938. }
  4939. }
  4940. }
  4941. $la->MakeHeader($p);
  4942. $la->MakeMainBegin();
  4943. if($la->PageType=='here' ||$la->PageType=='experimental'){
  4944. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  4945. if($im){
  4946. $la->MakeHereSection($im);
  4947. }else if($p){
  4948. $la->MakePostSectionExp($p);
  4949. $la->MakeLinkedPostsExp($p);
  4950. }else {
  4951. if($im){
  4952. $la->MakeHereSection($im);
  4953. }else{
  4954. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4955. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4956. }
  4957. }
  4958. }
  4959. $la->MakeMainEnd();
  4960. $la->MakeExpFooter();
  4961. }else{
  4962. if($la->PageType=='extras'){
  4963. $la->MakeExtraOperations();
  4964. }else if($la->PageType=='settings'){
  4965. $la->MakeSettings();
  4966. }else if($la->PageType=='gallery'){
  4967. $la->MakeGalleryLeft();
  4968. $la->MakeGallerySection();
  4969. }else if($la->PageType=='post'){
  4970. if($p){
  4971. $made_interesting = false;
  4972. if($la->IsInterestingPost($p)){
  4973. $la->MakeInterestingSection($p['tid']);
  4974. }
  4975. else{
  4976. $la->MakeLinkedPosts($p);
  4977. $la->MakePostSection($p);
  4978. $la->MakeTOC();
  4979. }
  4980. }else{
  4981. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4982. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4983. }
  4984. }else if($la->PageType=='history'){
  4985. $la->ReadArchive();
  4986. $la->MakePostHistory($p, $_GET['version']??NULL);
  4987. }else if($la->PageType=='search'){
  4988. $la->MakeHotPosts(true);
  4989. $la->MakeRecentPosts($_GET['search']);
  4990. }else if($la->PageType=='category'){
  4991. $la->MakeHotPosts(true);
  4992. $la->MakeRecentPosts(NULL,$_GET['category']);
  4993. }else if($la->PageType=='comments'){
  4994. $la->MakeCommentPosts();
  4995. }else{
  4996. $la->MakeHotPosts();
  4997. $la->MakeRecentPosts();
  4998. }
  4999. $la->MakeMainEnd();
  5000. $la->MakeFooter();
  5001. }
  5002. ?>