*/}}

index.php 248 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557
  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 $ExpHost;
  24. protected $ExpTitle;
  25. protected $ExpShortTitle;
  26. protected $ExpCaution;
  27. protected $ExpIndex;
  28. protected $ExpNavigation;
  29. protected $ExpFooter;
  30. protected $CommentEnabled;
  31. protected $Redirect;
  32. protected $Translations;
  33. protected $CustomTranslationContent;
  34. protected $CurrentOffset;
  35. protected $PostsPerPage;
  36. protected $HotPostCount;
  37. protected $LoggedIn;
  38. protected $LoginTokens;
  39. protected $InExperimentalMode;
  40. protected $LanguageAppendix;
  41. protected $UseRemoteFont;
  42. protected $Posts;
  43. protected $Threads; // [ keys: first last displayed count]
  44. protected $WaybackThreads;
  45. protected $Images;
  46. protected $Galleries;
  47. protected $Anchors;
  48. protected $ArchiveHandles;
  49. protected $Archive;
  50. public $WayBack;
  51. protected $YearBegin;
  52. protected $YearEnd;
  53. protected $Markers;
  54. protected $ExtraScripts;
  55. protected $TIME_STRING;
  56. protected $NULL_POST;
  57. protected $NULL_IMAGE;
  58. protected $NULL_Gallery;
  59. protected $DoneReadPosts;
  60. protected $DoneReadImages;
  61. protected $DoneReadArchive;
  62. protected $NeedWritePosts;
  63. protected $NeedWriteImages;
  64. protected $NeedWriteArchive;
  65. public $PageType;
  66. public $CurrentPostID;
  67. public $ActualPostID;
  68. public $TagID;
  69. function ReadableTime($id){
  70. $dt = DateTime::createFromFormat('YmdHis', $id);
  71. return $dt->format('Y/m/d H:i:s');
  72. }
  73. function FullURL(){
  74. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  75. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  76. $_SERVER['REQUEST_URI'];
  77. }
  78. function T($str){
  79. if(!$this->LanguageAppendix) return $str;
  80. foreach($this->Translations as $entry){
  81. if($entry['zh']==$str)
  82. return $entry[$this->LanguageAppendix];
  83. }
  84. return $str;
  85. }
  86. function SwitchLanguageAndFont(){
  87. if(isset($_COOKIE['la_language'])){
  88. $this->LanguageAppendix = $_COOKIE['la_language'];
  89. }else{
  90. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  91. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  92. $lang = substr($lang,0,5);
  93. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  94. else $this->LanguageAppendix = 'en';
  95. }
  96. }
  97. if(isset($_COOKIE['la_font'])){
  98. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  99. }
  100. }
  101. function SwitchWayBackMode(){
  102. if(isset($_COOKIE['la_wayback'])){
  103. $this->WayBack = $_COOKIE['la_wayback'];
  104. }else $this->WayBack = NULL;
  105. }
  106. function DisplayRedirectConfig(){
  107. $s = "";
  108. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  109. if($r['for']=='P'){
  110. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  111. }else if($r['for']=='S'){
  112. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  113. }
  114. }
  115. return $s;
  116. }
  117. function DoSiteRedirect(){
  118. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  119. if($r['for']=='S'){
  120. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  121. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  122. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  123. }else{
  124. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. function WriteHTACCESS(){
  131. $conf = fopen('.htaccess','w');
  132. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  133. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  134. if($r['for']=='P'){
  135. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  136. }// do site redirect in php.
  137. }
  138. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  139. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  140. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  141. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  142. fwrite($conf, 'RewriteCond %{HTTP_HOST} !^www\.'.PHP_EOL.
  143. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  144. 'RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  145. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  146. fflush($conf);fclose($conf);
  147. }
  148. function BuildRedirectConfig($conf){
  149. $this->Redirect=[];
  150. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  151. foreach($ma as $m){
  152. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  153. $this->Redirect[]=$redirect;
  154. }
  155. }
  156. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  157. foreach($ma as $m){
  158. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  159. $this->Redirect[]=$redirect;
  160. }
  161. }
  162. }
  163. function WriteTokens(){
  164. $tf = fopen('la_tokens.php','w');
  165. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  166. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  167. foreach($this->LoginTokens as $t){
  168. fwrite($tf,'- '.$t.PHP_EOL);
  169. }
  170. }
  171. fflush($tf);fclose($tf);
  172. }
  173. function WriteConfig(){
  174. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  175. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  176. if(!isset($this->Admin)) $this->Admin = 'admin';
  177. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  178. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  179. $conf = fopen('la_config.php','w');
  180. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  181. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  182. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  183. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  184. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  185. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  186. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  187. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  188. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  189. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  190. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  191. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  192. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  193. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  194. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  195. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  196. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  197. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  198. fwrite($conf,'- ExpIndex = '.$this->ExpIndex.PHP_EOL);
  199. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  200. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  201. fflush($conf);fclose($conf);
  202. $conf = fopen('la_redirect.md','w');
  203. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  204. $this->WriteHTACCESS();
  205. $this->WriteTokens();
  206. }
  207. function Install(){
  208. if(!file_exists('la_config.php')){
  209. $this->WriteConfig();
  210. }
  211. if(!is_dir('posts')) mkdir('posts');
  212. if(!is_dir('images')) mkdir('images');
  213. if(!is_dir('images/thumb')) mkdir('images/thumb');
  214. if(!is_dir('styles')) mkdir('styles');
  215. if(!is_dir('archive')) mkdir('archive');
  216. $this->WriteStyles();
  217. $this->WriteHTACCESS();
  218. }
  219. function ReadFromExistingConfig(){
  220. $f=null;
  221. if(file_exists('la_config.php')) $f='la_config.php';
  222. else if(file_exists('la_config.md')) $f='la_config.md';
  223. if(!isset($f)) return;
  224. $c = file_get_contents($f);
  225. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  226. $str = $m[1];
  227. $this->$str = $m[2];
  228. }
  229. }
  230. function ReadConfig(){
  231. $this->ReadFromExistingConfig();
  232. if(file_exists('la_redirect.md')){
  233. $c = file_get_contents('la_redirect.md');
  234. $this->BuildRedirectConfig($c);
  235. }
  236. if(!file_exists('la_config.php')){
  237. $this->Install();
  238. }
  239. $this->Translations=[];
  240. if(file_exists("translations.md")){
  241. $c = file_get_contents('translations.md');
  242. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  243. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  244. $this->Translations[] = $entry;
  245. }
  246. }
  247. if(file_exists("custom_translations.md")){
  248. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  249. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  250. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  251. $this->Translations[] = $entry;
  252. }
  253. }
  254. $this->LoginTokens=[];
  255. if(file_exists('la_tokens.php')){
  256. $c = file_get_contents('la_tokens.php');
  257. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  258. $this->LoginTokens[] = $m[1];
  259. }
  260. }
  261. }
  262. function __construct() {
  263. $this->ReadConfig();
  264. $this->PDE = new ParsedownExtra();
  265. $this->PDE->SetInterlinkPath('/');
  266. $this->Posts = [];
  267. $this->Threads = [];
  268. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  269. $this->PostsPerPage = 40;
  270. $this->CommentsPerPage = 100;
  271. $this->HotPostCount = 15;
  272. $this->TIME_STRING = date('YmdHis');
  273. $this->WayBack = NULL;
  274. $this->YearBegin = $this->YearEnd = 2000;
  275. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  276. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  277. $this->UsePosts = &$this->Posts;
  278. }
  279. function DoLogout(){
  280. $this->LoggedIn = false;
  281. unset($_SESSION['user_id']);
  282. $this->RecordToken(true);
  283. }
  284. function RecordToken($unset_current=false){
  285. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  286. $t = $_COOKIE['la_token'];
  287. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  288. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  289. $this->WriteTokens();
  290. return null;
  291. }else{
  292. $t = uniqid('la_',true);
  293. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  294. $this->LoginTokens[] = $t;
  295. $this->WriteTokens();
  296. return $t;
  297. }
  298. }
  299. function LoginThroughToken(){
  300. if(!isset($_COOKIE['la_token'])) return false;
  301. $t = $_COOKIE['la_token'];
  302. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  303. $_SESSION['user_id']=$this->Admin;
  304. $this->LoggedIn = true;
  305. setcookie('la_token',$t,time()+3600*24*7);
  306. return true;
  307. }
  308. return false;
  309. }
  310. function DoLogin(){
  311. session_start();
  312. $redirect=false;
  313. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  314. else if(!isset($_SESSION['user_id'])){
  315. if(isset($_POST['login_button'])){
  316. $id = trim($_POST['login_id']);
  317. $pwd = trim($_POST['login_password']);
  318. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  319. $_SESSION['user_id']=$id;
  320. $this->RecordToken(false);
  321. }
  322. $redirect = true;
  323. }else if($this->LoginThroughToken()){
  324. // nothing;
  325. }
  326. }else{
  327. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  328. else{ $this->DoLogout();}
  329. }
  330. if($redirect){
  331. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  332. .(isset($_GET['settings'])?"?settings=true":""));
  333. }
  334. }
  335. function WriteStyles(){
  336. $this->style="
  337. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  338. body{background-color:%white%;color:%black%;}
  339. sup,sub{line-height:0;}
  340. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  341. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  342. b,strong,th{font-weight:bold;}
  343. select{font-size:inherit;}
  344. .page,.page_gallery{padding:1em;padding-top:0;}
  345. .hidden_on_desktop,.hidden_on_wide{display:none;}
  346. .hidden_on_desktop_force{display:none !important;}
  347. ::file-selector-button{background:none;border:none;}
  348. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  349. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  350. .button:disabled{background-color:%gray%;pointer-events:none;}
  351. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;max-height:100vh;z-index:30;}
  352. 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;}
  353. header>div{overflow:auto;white-space:nowrap;}
  354. .header_nav{display:inline;}
  355. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  356. header a:hover,.button:hover{color:%gray% !important;}
  357. .footer{background-color:%white%;z-index:10;position:relative;}
  358. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  359. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  360. .gray,.gray a{color:%gray%;}
  361. hr{border:1px solid %gray%;}
  362. header ul{display:inline-block;}
  363. header li{display:inline-block;}
  364. header li::before{content:' - '}
  365. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  366. .main{position:relative;word-spacing:-1em;}
  367. .main *{word-spacing:initial;}
  368. pre{overflow:auto;max-width:100%;display:block;font-size:0.75em;}
  369. ul{display:block;}
  370. li{display:block;}
  371. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  372. table input{border:none!important;}
  373. table img{max-width:10rem !important;}
  374. td{padding-left:0.1em;padding-right:0.1em;}
  375. td:first-child{padding-left:0;}
  376. td:last-child{padding-right:0;}
  377. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  378. thead{box-shadow:inset 0 -1px 0 0px %black%;position:sticky;top:2rem;background-color:%white%;z-index:5;}
  379. .post table{font-size:0.85em;}
  380. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  381. .interesting_tbody td{display:contents;}
  382. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  383. .interesting_tbody td>*{display:table-cell;}
  384. .interesting_tbody .post_access{padding-top:0;}
  385. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  386. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  387. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  388. .interesting_tbody td>.imd>a{display:flex;}
  389. .interesting_tbody img{object-fit:cover;width:100%;}
  390. .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);}
  391. .interesting_tbody .p_thumb{height:1em;}
  392. .interesting_tbody .p_thumb img{max-height:10rem !important;max-width:20rem !important;}
  393. tr:hover .post_menu_button{opacity:1;}
  394. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  395. .align_right{text-align:right;}
  396. .left{display:inline-block;vertical-align:top;width:25%;max-height:calc(100vh - 2.6em);top:2em;
  397. position:sticky;overflow:auto;padding-right:0.2em;padding-bottom:4rem;}
  398. .center{display:inline-block;vertical-align:top;width:50%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  399. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  400. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  401. .center_wide .p_thumb{height:10rem;}
  402. .sticky_title{position:sticky;top:1.35em;z-index:1;box-shadow:6em 3.5em 0.75em -3em inset %white%;pointer-events:none;}
  403. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  404. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  405. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  406. .right{display:inline-block;vertical-align:top;width:25%;position:sticky;top:2em;
  407. padding-left:0.5em;max-height:calc(100vh - 2.6em);overflow:auto;padding-bottom:4rem;}
  408. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  409. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  410. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  411. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  412. .post{position:relative;scroll-margin:3.5em;border-radius:0.3em;}
  413. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;border-radius:0;}
  414. .post_width li,.post_width_big li,.footer_additional li,.footer_additional li,.post_dummy li
  415. {display:list-item;margin-left:1em;list-style:disc;}
  416. .post_width li li,.post_width_big li li,.footer_additional li li,.footer_additional li li,.post_dummy li li{list-style:circle;}
  417. .post_width > *,.post_width_big > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  418. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  419. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  420. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  421. .gallery_left .selected{list-style:'→';}
  422. .focused_post{font-size:1.1em;margin-top:0.1em;margin-bottom:0.1em;padding:0.5rem !important;border:2px dashed #ac7843;}
  423. .post_width{position:relative;left:1.4rem;width:calc(100% - 1.7rem);padding-left:0.2em;overflow:visible;}
  424. .post_width_big{position:relative;left:0;width:100%;overflow:visible;}
  425. .post_menu_button{position:absolute;display:none;right:0rem;width:1.5rem;
  426. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;}
  427. .pointer{cursor:pointer;}
  428. .post:hover .post_menu_button{display:block;}
  429. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%lighterbkg%;
  430. padding:0.3em;right:0.3rem;text-align:right;border-radius:0.3em;font-size:1rem;
  431. box-shadow:0px 0px 10px rgb(0, 0, 0);}
  432. .pop_menu li{list-style:none;margin-left:0;}
  433. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  434. .toc{left:60%;width:40%;top:0;position:absolute;}
  435. .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;}
  436. .post_access:hover{background-color:%lightopbkg%;border-top-left-radius:0.3em;border-bottom-left-radius:0.3em;
  437. border-right:2px solid %black% !important;}
  438. .paa{width:1.4rem;min-width:1.4rem;}
  439. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;}
  440. .post_box{border:1px solid %gray%;border-radius:0.3em;padding:0.3em;}
  441. .post_box:hover,.post_menu_button:hover{background-color:%lightopbkg%}
  442. #big_image_info .post_box:hover{background-color:%graybkg%;}
  443. .post_preview{font-size:0.9rem;overflow:hidden;margin-bottom:0.2em;}
  444. .post .post_ref{margin:0;padding-left:1.7rem;}
  445. .post_ref_main{display:inline-block;vertical-align:top;}
  446. .post_preview .post_ref_main{max-height:6rem;overflow:hidden;}
  447. .post_ref_images{overflow:hidden;}
  448. .page_selector{padding-top:2rem;text-align:center;}
  449. .smaller{font-size:0.85em;}
  450. .bigger{font-size:1.3em;}
  451. .block{display:block;}
  452. .opt_compact{margin-left:1.6rem;}
  453. .opt_compact .post_width {margin-left:0.3em;width: calc(100% - 1.8rem);}
  454. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  455. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  456. .spacer{height:0.5em;}
  457. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  458. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  459. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  460. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  461. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  462. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  463. .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;}
  464. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  465. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  466. .toc_entry_1{font-size:1.1em;}
  467. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  468. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  469. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  470. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  471. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  472. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  473. .deleted_post{color:%gray%;text-decoration:line-through;}
  474. #file_list{margin-top:0.5em;}
  475. .file_thumb img{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  476. #file_list li{margin-bottom:0.3em;}
  477. .ref_thumb{white-space:nowrap;overflow:hidden;}
  478. .ref_thumb .file_thumb{width:3em;height:3em;}
  479. .side_thumb li{margin:0.4em;display:inline-block;}
  480. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  481. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  482. .p_thumb{display:flex;flex-grow:1;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  483. .p_thumb img{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  484. .ref_count,.p_thumb .post_menu_button{text-shadow: 0px 0px 10px rgb(0, 0, 0);}
  485. .p_thumb:hover .post_menu_button{display:block;}
  486. .p_thumb_selected{color:%black% !important;}
  487. .p_thumb_selected{display:block;}
  488. .post .p_thumb img{max-height:6rem;}
  489. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  490. .big_image_box *{pointer-events:auto;}
  491. .big_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  492. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;
  493. background:linear-gradient(to right, rgba(0,0,0,0), rgb(1, 1, 1));transition:background-size .2s linear;background-size: 300% 100%;}
  494. .big_side_box:hover{background-size: 100% 100%;}
  495. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  496. .big_side_box a:hover{color:%gray%;}
  497. #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;
  498. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  499. img{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  500. .post img{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  501. .post > a > img{display:block;margin:0.3em auto;}
  502. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  503. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  504. .center_exp .post .original_img{display:block;}
  505. .original_img img{max-height:90vh;max-width:100%;}
  506. .p_row .original_img{margin-bottom:0;}
  507. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  508. .b ul{font-size:1.4em;}
  509. no_pop{cursor:unset;}
  510. p{min-height:0.8em;}
  511. .bold,.bold *{font-weight:bold;}
  512. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  513. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;}
  514. .small_footer>div{overflow:auto;white-space:nowrap;}
  515. .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;}
  516. .top_post_hint{margin-left:1.5em;font-weight:bold;}
  517. .white{color:%white%;}
  518. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  519. .image_nav_prev,.image_nav_next{z-index:100;position:absolute;line-height:0;height:100%;width:20%;display:flex;align-items:center;
  520. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  521. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.2));
  522. background-repeat:no-repeat;background-size:0% 100%;}
  523. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  524. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  525. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  526. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  527. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  528. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  529. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  530. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  531. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  532. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  533. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  534. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  535. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  536. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  537. .special_paypal_inner{color:#169bd7;}
  538. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  539. animation:anim_loading 1s linear infinite;}
  540. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  541. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  542. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  543. .product_thumb img{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  544. .product_ref p{margin-bottom:0.2em;text-align:left;}
  545. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  546. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  547. .page_break{page-break-after:always;}
  548. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  549. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  550. .print_title{display:none;}
  551. .show_on_print{display:none;}
  552. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  553. .comment tbody tr:hover{box-shadow:none;}
  554. .comment table{border:none;}
  555. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  556. .comment ul{padding-left:1em;}
  557. .comment ul li *{margin-bottom:0.5em;}
  558. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  559. .history li li{list-style:circle;}
  560. .history ul{padding-left:1em;}
  561. .history a{text-decoration:underline;}
  562. .history .list{overflow:auto;white-space:nowrap;}
  563. .diff_table{table-layout:fixed;}
  564. .diff_table thead{font-size:0.9em;text-align:center;}
  565. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  566. .diff_table td{vertical-align:top;}
  567. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  568. .wayback_close{float:right;}
  569. .wayback_expand{display:inline;}
  570. .post_selecting .post *{pointer-events:none;}
  571. .post_selected{background-color:%graybkg%;}
  572. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  573. .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%;}
  574. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  575. .wayback_link{display:inline;}
  576. .imd{object-fit:cover;width:100%;}
  577. .center_exp .imd{width:60%;}
  578. @media screen and (max-width:1000px) and (min-width:666px){
  579. .left{width:35%;}
  580. .center,.center_wide{width:65%;}
  581. .center_wide .p_thumb{height:8rem;}
  582. .right{display:none;}
  583. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  584. .post_width_big{left:0;width:100%;}
  585. .hidden_on_wide{display:unset;}
  586. .hidden_on_narrow{display:none;}
  587. .pop_right{width:30%;}
  588. .pop_right_big{width:40%;}
  589. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  590. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  591. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  592. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  593. .big_side_box{width:35%;}
  594. .big_image_box{width:65%;}
  595. .inquiry_buttons{right:35%;}
  596. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  597. .post_dummy > *{width:80%;max-width:55rem;}
  598. .center_exp .imd{width:80%;}
  599. }
  600. @media screen and (max-width:666px){
  601. html{font-size:16px;}
  602. .hidden_on_mobile{display:none !important;}
  603. .block_on_mobile{display:block !important;}
  604. .hidden_on_desktop{display:unset;}
  605. header ul{display:block;}
  606. header li{display:block;}
  607. header li::before{content:''}
  608. header::before{box-shadow:none;display:none;}
  609. .small_footer::before{box-shadow:none;display:none;}
  610. .left{position:relative;width:100%;position:relative;top:unset;height:unset;min-height:80vh;padding-right:0;display:block;}
  611. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  612. .center_wide .p_thumb{height:6rem;}
  613. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  614. .pop_right{height:30%;}
  615. .pop_right_big{height:70%;}
  616. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  617. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  618. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  619. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  620. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  621. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  622. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  623. .side_box_mobile_inner:hover{background-size:100% 100%;}
  624. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  625. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  626. .p_thumb{height:3rem;}
  627. .center .post{padding-right:0rem;padding-left:0rem;}
  628. .post .p_thumb img{max-height:3rem;}
  629. .page,.page_gallery{padding:0.2em;padding-top:0;}
  630. header{padding-top:0.3em;}
  631. .small_footer{padding-bottom:0.3em;}
  632. .footer_additional{display:block;width:100%;}
  633. .album_hint{display:block;font-size:1rem;}
  634. .image_nav{position:absolute !important;}
  635. .image_nav_prev,.image_nav_next{width:25%;}
  636. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  637. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  638. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  639. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  640. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  641. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  642. .opt_compact,.ref_compact{line-break:anywhere;}
  643. .post_width,.post_width_big{overflow:auto;}
  644. .table_top{left:unset;width:100%;overflow:auto;}
  645. table img{max-width:30vw !important;}
  646. .product_ref{width:100%;display:block;}
  647. .post_dummy > *{width:100%;max-width:25rem;}
  648. .sticky_title{top:1.2em;}
  649. .small_footer{position:relative;}
  650. #upload_selector{width:100%;}
  651. .focused_post{padding:0.3rem !important;}
  652. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  653. .wayback_expand{display:block;text-align:center;}
  654. .wayback_link{display:block;}
  655. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  656. .center_exp .post{overflow:auto;}
  657. .center_exp .imd{width:100%;}
  658. }
  659. @media print{
  660. header::before{box-shadow:none;display:none;}
  661. .small_footer::before{box-shadow:none;display:none;}
  662. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  663. .post *,.post_dummy *{margin-bottom:0em}
  664. .p_row,.post table,.post_width>img,.post_width_big>img,.post_ref>img,.post_ref>.original_img,
  665. .post_width>.original_img,.post_width_big>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  666. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  667. table img{margin:0 !important;}
  668. .post h1+p,.post h2+p,.post img+p,.post table+p,.post p:first-child{text-indent:0;}
  669. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  670. table{border-bottom:2px solid black;border-top:2px solid black;}
  671. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  672. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  673. .post_width,.post_width_big{overflow:clip;left:0;width:100%;padding-left:0em;}
  674. .post h1{margin-top:0.5rem;}
  675. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  676. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  677. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  678. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  679. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  680. .left,.right{display:none;}
  681. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  682. hr{border:1px solid black;}
  683. .post_box_top{display:none;}
  684. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;}
  685. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  686. .focused_post{border:none;font-size:1em;padding:0 !important;}
  687. .hidden_on_print{display:none;}
  688. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  689. .post_access{display:none;}
  690. .opt_compact{margin-left:0;}
  691. .post .post_ref{padding-left:1.4rem;}
  692. .opt_compact .post_width{left:1.4rem;width:calc(100% - 1.4rem);margin-left:0;}
  693. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  694. .print_title:first-of-type{margin-top:1em;}
  695. .print_title+.post h1:first-of-type{display:none;}
  696. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  697. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  698. .header_nav{display:none;}
  699. .show_on_print{display:block;}
  700. blockquote{border-left:2px solid black;}
  701. .footer_additional{display:none;}
  702. .small_footer{margin-top:1rem;}
  703. .page_selector{display:none;}
  704. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  705. .post .p_thumb img{max-height:4rem;}
  706. .sticky_title{box-shadow:none;}
  707. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  708. .center_wide .p_row{display:block;}
  709. .interesting_tbody{background:none;}
  710. .interesting_tbody img{display:none !important;}
  711. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  712. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  713. }
  714. ";
  715. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  716. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  717. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  718. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  719. $this->style=preg_replace('/%lightopbkg%/','#daae8010',$this->style);
  720. $this->style=preg_replace('/%lighterbkg%/','#675340',$this->style);
  721. $this->style=preg_replace('/%focusedbkg%/','#482f0c',$this->style);
  722. $f = fopen('styles/main.css','w');
  723. fwrite($f,$this->style);
  724. fclose($f);
  725. }
  726. function GiveSafeEMail(){
  727. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  728. }
  729. function &FindImage($name){
  730. if(isset($this->Images[0]))foreach($this->Images as &$im){
  731. if($im['name']==$name) return $im;
  732. }
  733. return $this->NULL_IMAGE;
  734. }
  735. function ReadImages($clear_non_exist = false){
  736. $path = 'images/list.md';
  737. if($this->DoneReadImages){ return; }
  738. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  739. $c = file_get_contents($path);
  740. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  741. $g=[]; $g['name']=$m[1];//$g['count']=0;
  742. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  743. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  744. $this->Galleries[] = $g;
  745. }
  746. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  747. $name = trim($m[1]);
  748. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  749. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  750. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  751. $item['refs']=[];
  752. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  753. }
  754. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  755. $item['galleries']=[];
  756. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  757. }
  758. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){
  759. $item['product']=$product[1];
  760. }
  761. $this->Images[] = $item;
  762. }
  763. $files = array_merge([],glob('images/*.jpg'));
  764. $files = array_merge($files,glob('images/*.jpeg'));
  765. $files = array_merge($files,glob('images/*.png'));
  766. $files = array_merge($files,glob('images/*.gif'));
  767. if(isset($files[0]))foreach($files as $file) {
  768. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png)/u', $file, $m)) {
  769. $name = trim($m[0]);
  770. if(!$this->FindImage($name)){
  771. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  772. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  773. $this->Images[] = $item;
  774. }
  775. }
  776. }
  777. if($clear_non_exist){
  778. if(isset($this->Images[0]) && isset($files[0])){
  779. foreach($this->Images as &$im){
  780. if(!in_array($im['file'],$files)){
  781. $im['deleted'] = 1;
  782. }
  783. }
  784. }
  785. }
  786. function cmpf($a, $b){
  787. if ($a['name'] == $b['name']) return 0;
  788. return (($a['name'] > $b['name']) ? 1 : -1);
  789. }
  790. function cmpaf($a, $b){
  791. if ($a['name'] == $b['name']) return 0;
  792. return ($a['name'] > $b['name']) ? -1 : 1;
  793. }
  794. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  795. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  796. $this->DoneReadImages = 1;
  797. }
  798. function WriteImages(){
  799. if(isset($this->WayBack)) return;
  800. $path = 'images/list.md';
  801. $f = fopen($path,'w');
  802. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  803. if(isset($g['deleted'])) continue;
  804. fwrite($f,'GALLERY '.$g['name']);
  805. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  806. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  807. fwrite($f, PHP_EOL);
  808. }
  809. if(isset($this->Images[0]))foreach($this->Images as &$im){
  810. if(isset($im['deleted'])) continue;
  811. fwrite($f, "- ".$im['name'].'; ');
  812. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  813. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  814. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  815. fwrite($f, PHP_EOL);
  816. }
  817. fflush($f);
  818. fclose($f);
  819. }
  820. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL){
  821. if(!($im = &$this->FindImage($name))) return;
  822. if(isset($link_gallery)){
  823. if($do_remove){
  824. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  825. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  826. $im['galleries'] = array_merge($im['galleries']);
  827. }else{
  828. if(!isset($im['galleries'])) $im['galleries']=[];
  829. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  830. $im['galleries'][]=$link_gallery;
  831. }
  832. }
  833. if(isset($product_link)){
  834. if($product_link!=''){$im['product']=$product_link;}
  835. else{unset($im['product']);}
  836. }
  837. if(isset($rename)){
  838. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  839. rename($im['file'], 'images/'.$rename.'.'.$ext);
  840. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  841. $im['name'] = $rename.'.'.$ext;
  842. }
  843. $this->NeedWriteImages = 1;
  844. }
  845. function RegenerateThumbnails(){
  846. $glob = glob('images/*.jpg');
  847. if(!is_dir('images/thumb')) mkdir('images/thumb');
  848. foreach($glob as $file) {
  849. $thumb_destination = 'images/thumb/'.basename($file);
  850. $img = new Imagick($file); $geo=$img->getImageGeometry();
  851. $width=$geo['width']; $height=$geo['height'];
  852. $lim=400;
  853. $scale = $lim / min($width,$height);
  854. if($scale<1){
  855. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  856. }
  857. $img->setImageFormat('jpeg');
  858. $img->setImageCompressionQuality(90);
  859. $img->writeImage($thumb_destination);
  860. }
  861. }
  862. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max) {
  863. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  864. $width=$geo['width']; $height=$geo['height'];
  865. $lim=400;
  866. $scale = $lim / min($width,$height);
  867. if($scale<1){
  868. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  869. }
  870. $img->setImageFormat('jpeg');
  871. $img->setImageCompressionQuality($quality);
  872. $img->writeImage($thumb_destination);
  873. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  874. if($scale<1){
  875. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  876. }
  877. $img2->setImageFormat('jpeg');
  878. $img2->setImageCompressionQuality($quality);
  879. $img2->writeImage($destination);
  880. }
  881. function DoUpload(){
  882. if(!isset($_FILES['upload_file_name'])) return 0;
  883. if(!is_dir('images/thumb')) mkdir('images/thumb');
  884. if($_FILES['upload_file_name']['error']>0){
  885. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  886. return -1;
  887. }else{
  888. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  889. if(!in_array($ext,['jpg','jpeg','png','gif'])) return 0;
  890. $fp = fopen('.la_lock',"w");
  891. while (!flock($fp, LOCK_EX| LOCK_NB)){
  892. usleep(10000);
  893. }
  894. $num=date('YmdHis'); $replace=0;
  895. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  896. $num = $mim[1]; $replace=1;
  897. }
  898. $base = 'images/'.$num;
  899. $thumb = 'images/thumb/'.$num;
  900. if($ext=='png') $ext='jpg';
  901. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  902. if(!$replace) while(file_exists($final_path)){
  903. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  904. }
  905. if($ext!='gif'){
  906. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  907. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  908. $compress?800:1920, $compress?1920:2560);
  909. }else{
  910. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  911. }
  912. flock($fp, LOCK_UN);
  913. fclose($fp);
  914. $this->ReadImages(true);
  915. $this->WriteImages();
  916. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  917. if(isset($_POST['image_replace_button'])){
  918. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  919. }
  920. exit;
  921. return 1;
  922. }
  923. return 0;
  924. }
  925. function &GetGallery($name){
  926. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  927. if($g['name'] == $name) return $g;
  928. }
  929. return $this->NULL_GALLERY;
  930. }
  931. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  932. $this->ReadImages();
  933. $gallery = &$this->GetGallery($name);
  934. if(!isset($gallery)){
  935. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  936. $g = []; $g['name']=$new_name;
  937. $this->Galleries[]=$g;
  938. }else{
  939. if(isset($new_name)) {
  940. if(preg_match('/main|trash|\s/u',$new_name))return;
  941. $gallery['name'] = $new_name;
  942. foreach ($this->Images as &$im){
  943. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  944. if($g == $name){ $g = $new_name; }
  945. }
  946. }
  947. }
  948. //if(isset($count)) $gallery['count'] = $count;
  949. if(isset($delete) && $delete) $gallery['deleted'] = true;
  950. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  951. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  952. }
  953. if($do_rw) { $this->NeedWriteImages = 1; }
  954. }
  955. function ClearData(){
  956. $this->Posts = [];
  957. $this->Threads = [];
  958. $this->Images = [];
  959. $this->Archive = [];
  960. $this->ArchiveHandles = [];
  961. }
  962. function InsertArchivePost(&$post){
  963. $a = NULL;
  964. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  965. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  966. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  967. }
  968. $a['list'][] = $post;
  969. $this->Archive[] = $post;
  970. }
  971. function ReadArchiveFromFile($path){
  972. if(!file_exists($path)){
  973. return;
  974. }
  975. $c = file_get_contents($path);
  976. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  977. foreach($matches as $m){
  978. $post = [];
  979. $post['id'] = $m[1];
  980. $post['content'] = trim($m[3]);
  981. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  982. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  983. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  984. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  985. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  986. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  987. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  988. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  989. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  990. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  991. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  992. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  993. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  994. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  995. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  996. }
  997. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  998. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  999. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1000. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1001. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1002. }
  1003. $this->InsertArchivePost($post);
  1004. }
  1005. }
  1006. }
  1007. function SortArchive(){
  1008. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1009. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1010. return (($a['id'] > $b['id']) ? 1 : -1);
  1011. };
  1012. if(isset($this->Archive[0])){
  1013. usort($this->Archive,$cmpap);
  1014. $year_begin = substr($this->Archive[0]['id'],0,4);
  1015. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1016. }
  1017. if(isset($this->ArchiveHandles[0])){
  1018. usort($this->ArchiveHandles,$cmpac);
  1019. foreach($this->ArchiveHandles as &$a){
  1020. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1021. $last_valid=NULL;
  1022. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1023. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1024. else{ $last_valid = $ver['content']; } }
  1025. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1026. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1027. }
  1028. }
  1029. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1030. $p['archive'] = &$a;
  1031. }
  1032. }
  1033. }
  1034. }
  1035. function ReadPostsFromFile($path){
  1036. if(!file_exists($path)){
  1037. $f = fopen($path,'w');
  1038. fclose($f);
  1039. }
  1040. $c = file_get_contents($path);
  1041. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1042. foreach($matches as $m){
  1043. $post = [];
  1044. $post['id'] = $m[1];
  1045. $post['real_content'] = trim($m[3]);
  1046. $post['content'] = &$post['real_content'];
  1047. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1048. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1049. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1050. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1051. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1052. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1053. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1054. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1055. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1056. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1057. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1058. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1059. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1060. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1061. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1062. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1063. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1064. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1065. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1066. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1067. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1068. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1069. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1070. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1071. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1072. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1073. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1074. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1075. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1076. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1077. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1078. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1079. }
  1080. if(isset($post['mark_value']) && $post['mark_value']==5){
  1081. $post['product']=[];
  1082. }
  1083. /* marks add here */
  1084. $this->Posts[] = $post;
  1085. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1086. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1087. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1088. }
  1089. }
  1090. }
  1091. }
  1092. function SortPosts($wayback=false){
  1093. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1094. $sortlist = &$this->Posts;
  1095. if($wayback) $sortlist = &$this->WaybackPosts;
  1096. if(isset($sortlist[0])){
  1097. usort($sortlist,$cmpp);
  1098. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1099. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1100. }
  1101. }
  1102. function ReadPosts(){
  1103. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1104. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1105. (!is_dir('posts') || is_readable('posts') == false) ||
  1106. (!is_dir('archive') || is_readable('archive') == false) ||
  1107. (!is_dir('images') || is_readable('images') == false) ||
  1108. (!is_dir('styles') || is_readable('styles') == false)){
  1109. $this->Install();
  1110. }
  1111. if($this->DoneReadPosts){ return; }
  1112. $file_list = [];
  1113. $glob = glob('posts/*');
  1114. foreach($glob as $file) {
  1115. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1116. $file_list[] = $file;
  1117. }
  1118. }
  1119. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1120. foreach($file_list as $f) {
  1121. $this->ReadPostsFromFile($f);
  1122. }
  1123. $this->SortPosts();
  1124. $this->DetectThreads();
  1125. $this->DoneReadPosts=1;
  1126. }
  1127. function UpdatePostRefsForWayback(){
  1128. if(!isset($this->WayBack)) return;
  1129. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1130. if(!isset($this->WaybackPosts[0])) return;
  1131. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1132. foreach($this->WaybackPosts as &$p){
  1133. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1134. $pr = &$this->GetPost($r); if(isset($pr)){
  1135. if(!isset($pr['refs'])) $pr['refs']=[];
  1136. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1137. }
  1138. }
  1139. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1140. $ir = &$this->FindImage($r); if(isset($ir)){
  1141. if(!isset($ir['refs'])) $ir['refs']=[];
  1142. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1143. }
  1144. }
  1145. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1146. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1147. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1148. }
  1149. }
  1150. }
  1151. function ReadArchive(){
  1152. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1153. if ($this->DoneReadArchive) return;
  1154. $file_list = []; $glob = glob('archive/*');
  1155. foreach($glob as $file) {
  1156. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1157. $file_list[] = $file;
  1158. }
  1159. }
  1160. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1161. foreach($file_list as $f) {
  1162. $this->ReadArchiveFromFile($f);
  1163. }
  1164. $this->SortArchive();
  1165. $this->DoneReadArchive=1;
  1166. $this->UpdateThreadForWayback();
  1167. $this->UpdatePostRefsForWayback();
  1168. }
  1169. function GetThreadForPost(&$post){
  1170. if(isset($post['tid'])) return;
  1171. $th = []; $iterp = NULL;
  1172. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1173. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1174. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1175. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1176. $np['tid'] = &$th;
  1177. $th['first'] = &$np;
  1178. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1179. }
  1180. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1181. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1182. $np['tid'] = &$th;
  1183. $th['last'] = &$np;
  1184. $iterp = isset($np['next'])?$np['next']:NULL;
  1185. }
  1186. if(isset($th['first']['mark_value'])){
  1187. if($th['first']['mark_value']==6) $th['exp'] = true;
  1188. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1189. }
  1190. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1191. $this->Threads[] = &$th;
  1192. }
  1193. function IdentifyThreadCategory(&$th,&$first_post){
  1194. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1195. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1196. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1197. }
  1198. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1199. }
  1200. if(isset($th) && preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1201. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1202. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1203. }
  1204. }
  1205. }
  1206. function IsInterestingPost(&$p){
  1207. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1208. return false;
  1209. }
  1210. function GiveAllMergedPosts(&$po,&$arr){
  1211. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1212. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1213. }
  1214. if(isset($po['archive']) && isset($po['archive']['list'])){
  1215. foreach($po['archive']['list'] as &$ver){
  1216. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1217. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1218. }
  1219. }
  1220. }
  1221. function ThreadMakeWayback(&$th){
  1222. if(!isset($th['arr'][0])) return;
  1223. if(isset($this->WayBack)){
  1224. $remlist = [];
  1225. foreach($th['arr'] as &$pi){
  1226. $po = &$this->GetPost($pi['id'],true);
  1227. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1228. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1229. }
  1230. $ah = &$this->GetArchiveHandle($po['id']);
  1231. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1232. if(!isset($ver['merged_thread'])) continue;
  1233. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1234. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1235. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1236. }
  1237. }
  1238. }
  1239. if(isset($remlist[0]) && isset($th['arr'][0])){
  1240. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1241. foreach($th['arr'] as $key => $pr){
  1242. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1243. $new_th = []; $new_arr = [];
  1244. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1245. $new_th['arr'] = &$new_arr;
  1246. $this->WaybackThreads[] = &$new_th;
  1247. $this->ThreadMakeWayback($new_th);
  1248. }
  1249. }
  1250. }
  1251. function AddMergedPosts(&$p, &$array){
  1252. if(isset($p['archive']) && isset($p['archive']['list'])){
  1253. foreach($p['archive']['list'] as &$ver){
  1254. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1255. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1256. }
  1257. }
  1258. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1259. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1260. }
  1261. function FinalizeThread(&$th, $relink_posts=false, $now){
  1262. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1263. if(!isset($th['arr'])){
  1264. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1265. $arr[]=&$p;
  1266. } $th['arr'] = &$arr;
  1267. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1268. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1269. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1270. $arr=&$new_arr; $th['arr']=&$new_arr;
  1271. $this->ThreadMakeWayback($th); }
  1272. }
  1273. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1274. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1275. if($relink_posts){ $count = $th['count'];
  1276. $arr = &$th['arr'];
  1277. 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'];
  1278. $arr[$i]['tid']=&$th;}
  1279. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1280. }
  1281. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1282. $this->IdentifyThreadCategory($th, $th['first']);
  1283. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1284. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1285. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1286. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1287. }
  1288. function SortThreads(){
  1289. if (!function_exists('cmpt')) {
  1290. function cmpt($a, $b){
  1291. if ($a['score'] == $b['score']) return 0;
  1292. return ($a['score'] > $b['score']) ? -1 : 1;
  1293. }
  1294. }
  1295. usort($this->Threads,"cmpt");
  1296. }
  1297. function DetectThreads(){
  1298. foreach($this->Posts as &$p){
  1299. if(isset($p['tid'])) { continue; }
  1300. $this->GetThreadForPost($p);
  1301. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1302. }
  1303. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1304. $now = date_timestamp_get(date_create());
  1305. foreach($this->Threads as &$t){
  1306. $this->FinalizeThread($t,false,$now);
  1307. }
  1308. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1309. $this->FinalizeThread($th,false,$now);
  1310. $this->Threads[] = &$th;
  1311. }
  1312. $this->SortThreads();
  1313. }
  1314. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1315. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1316. foreach($this->Threads as &$t){
  1317. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1318. }
  1319. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1320. $this->FinalizeThread($th,true,$now);
  1321. $this->Threads[] = &$th;
  1322. }
  1323. $this->SortThreads();
  1324. $this->SortPosts(true);
  1325. $this->UsePosts = &$this->WaybackPosts;
  1326. }
  1327. function &GetMergedPost($id){
  1328. $this->ReadArchive();
  1329. $ah = &$this->GetArchiveHandle($id);
  1330. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1331. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1332. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1333. [$tp, $tver] = $ver['merged_into'];
  1334. if(isset($this->WayBack)){
  1335. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1336. else return $this->GetPost($id); /* should not happen directly. */
  1337. }
  1338. return $this->GetMergedPost($tp);
  1339. }
  1340. function &GetPost($id, $latest_only=false, $find_merged=false){
  1341. if(!isset($id)) return $this->NULL_POST;
  1342. $found=&$this->NULL_POST;
  1343. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1344. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1345. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1346. }
  1347. if($latest_only || !isset($this->WayBack)){ return $found; }
  1348. else{
  1349. if(isset($found)){
  1350. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1351. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1352. $last_ver = &$this->NULL_POST;
  1353. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1354. if($ver['version'] > $this->WayBack) return $last_ver;
  1355. $last_ver = &$ver;
  1356. }
  1357. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1358. else return $last_ver;
  1359. }else{
  1360. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1361. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1362. if($ver['version'] > $this->WayBack) return $last_ver;
  1363. $last_ver = &$ver;
  1364. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1365. [$tp, $tver] = $last_ver['merged_into'];
  1366. if($tver <= $this->WayBack) {
  1367. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1368. return $last_ver;
  1369. }
  1370. }
  1371. }
  1372. return $this->NULL_POST;
  1373. }
  1374. function &GetArchiveHandle($id){
  1375. if(!isset($id)) return $this->NULL_POST;
  1376. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1377. if($p && $p['id'] == $id) { return $p; }
  1378. }
  1379. return $this->NULL_POST;
  1380. }
  1381. function &GetArchive($id){
  1382. if(!isset($id)) return $this->NULL_POST;
  1383. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1384. if($p && $p['id'] == $id) { return $p; }
  1385. }
  1386. return $this->NULL_POST;
  1387. }
  1388. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1389. if(!isset($ah)) return $this->NULL_POST;
  1390. $found = NULL; $last_verp=NULL;
  1391. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1392. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1393. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1394. $last_verp = &$p;
  1395. }
  1396. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1397. return $this->NULL_POST;
  1398. }
  1399. function CacheArchiveOwnLinks(){
  1400. if(isset($this->WayBack)) return;
  1401. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1402. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1403. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1404. foreach($matches as $m){
  1405. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1406. }
  1407. }
  1408. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1409. foreach($matches as $m){
  1410. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1411. }
  1412. }
  1413. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1414. foreach($matches as $m){
  1415. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. function WriteArchive(){
  1421. if(isset($this->WayBack)) return;
  1422. $cf = NULL;$opened =NULL;
  1423. $this->SortArchive();
  1424. $this->CacheArchiveOwnLinks();
  1425. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1426. $nid = substr($p['id'], 0,6);
  1427. if($cf != $nid){
  1428. if($opened){
  1429. fflush($opened);
  1430. fclose($opened);
  1431. }
  1432. $cf = $nid;
  1433. $opened = fopen("archive/$cf.md", 'w');
  1434. }
  1435. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1436. "VER {$p['version']}; ".
  1437. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1438. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1439. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1440. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1441. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1442. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1443. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1444. ']';
  1445. if(isset($p['merged_thread'])){ $p['content']=""; }
  1446. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1447. }
  1448. }
  1449. function WritePosts(){
  1450. if(isset($this->WayBack)) return;
  1451. $cf = NULL;$opened =NULL;
  1452. $this->SortPosts();
  1453. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1454. $nid = substr($p['id'], 0,6);
  1455. if($cf != $nid){
  1456. if($opened){
  1457. fflush($opened);
  1458. fclose($opened);
  1459. }
  1460. $cf = $nid;
  1461. $opened = fopen("posts/$cf.md", 'w');
  1462. }
  1463. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1464. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1465. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1466. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1467. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1468. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1469. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1470. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1471. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1472. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1473. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1474. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1475. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1476. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1477. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1478. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1479. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1480. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1481. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1482. ']';
  1483. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1484. }
  1485. }
  1486. function CachePostLinks(){
  1487. if(isset($this->WayBack)) return;
  1488. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1489. $this->ConvertPost($post);
  1490. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1491. //discard lost old version
  1492. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1493. }else return;
  1494. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1495. unset($im['refs']);
  1496. }
  1497. foreach ($this->Posts as &$post){
  1498. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1499. foreach($matches as $m){
  1500. $ref = &$this->GetPost($m[1],true);
  1501. if($ref!=NULL){
  1502. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1503. }
  1504. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1505. }
  1506. }
  1507. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1508. foreach($matches as $m){
  1509. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1510. }
  1511. }
  1512. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1513. foreach($matches as $m){
  1514. if(($im = &$this->FindImage($m[2]))!=NULL){
  1515. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1516. }
  1517. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1518. }
  1519. }
  1520. }foreach($this->Posts as &$post){
  1521. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1522. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1523. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1524. }
  1525. }
  1526. }
  1527. function CreatePostAnchor(&$post){
  1528. $that=&$this;
  1529. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1530. $id = '_heading_'.sizeof($this->Anchors);
  1531. $entry=[(int)$ma[1], $id, $ma[2]];
  1532. $that->Anchors[] = $entry;
  1533. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1534. }, $post['html']);
  1535. }
  1536. function RenamePost(&$post, $rename){
  1537. foreach($this->Posts as &$p){
  1538. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1539. }
  1540. foreach($this->Posts as &$p){
  1541. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1542. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1543. }
  1544. $post['id'] = $rename;
  1545. }
  1546. function DetachPost(&$th,&$post){
  1547. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1548. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1549. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1550. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1551. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1552. unset($th['arr']); $now = date_timestamp_get(date_create());
  1553. $this->FinalizeThread($th, true, $now);
  1554. }
  1555. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1556. $a = &$this->GetArchiveHandle($post['id']);
  1557. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1558. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1559. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1560. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1561. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1562. $post['version'] = $optime_id;
  1563. if($mode==1){
  1564. $this->InsertArchivePost($ap);
  1565. }else if($mode==2){
  1566. $post['merged_from'] = $info;
  1567. $this->InsertArchivePost($ap);
  1568. }else if($mode==3){
  1569. $ap['merged_into'] = $info;
  1570. $this->InsertArchivePost($ap);
  1571. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1572. $this->DetachPost($post['tid'], $post);
  1573. }
  1574. }else if($mode==4){
  1575. $post['merged_thread'] = $info;
  1576. $this->InsertArchivePost($ap);
  1577. }
  1578. }
  1579. function &MergeThreads($post_id, $post_into_id){
  1580. $this->ReadPosts();
  1581. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1582. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1583. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1584. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1585. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1586. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1587. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1588. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1589. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info);
  1590. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1591. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1592. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1593. $tt['count'] = sizeof($tt['arr']);
  1594. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1595. $first_post = &$this->NULL_POST;
  1596. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1597. $this->NeedWritePosts=1;
  1598. $this->NeedWriteArchive=1;
  1599. return $first_post;
  1600. }
  1601. function &MergePosts($ids_string){
  1602. $ids = explode(" ", $ids_string);
  1603. $combined_content = ""; $first_id=NULL;
  1604. $this->ReadPosts(); $child_list=[];
  1605. foreach($ids as $id){
  1606. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1607. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1608. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL);
  1609. }
  1610. if(!isset($child_list[0])) return $this->NULL_POST;
  1611. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list);
  1612. foreach($child_list as $id){
  1613. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING]);
  1614. }
  1615. $this->NeedWritePosts=1;
  1616. $this->NeedWriteArchive=1;
  1617. return $first_post;
  1618. }
  1619. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1620. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1621. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1622. $push_version=false, $version_info=NULL){
  1623. $this->ReadImages();
  1624. $this->ReadPosts();
  1625. if(isset($push_version) && $push_version){
  1626. $this->ReadArchive();
  1627. }
  1628. $p_success = NULL;
  1629. if(isset($id_if_edit)){
  1630. $post = &$this->GetPost($id_if_edit,true);
  1631. if($post===$this->NULL_POST) return $this->NULL_POST;
  1632. if($get_original_only){
  1633. return $post['real_content'];
  1634. }
  1635. if(isset($push_version) && $push_version){
  1636. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1637. }
  1638. if(isset($content)) $post['real_content'] = $content;
  1639. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1640. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1641. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1642. $p_success = &$post;
  1643. }else{
  1644. if(!isset($content)) return $this->NULL_POST;
  1645. $id = date('YmdHis');
  1646. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1647. $post = [];
  1648. $post['id'] = $id;
  1649. $post['real_content'] = $content;
  1650. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1651. if(!(isset($rep['next']) && $rep['next'])){$rep['next'] = $id; $post['prev'] = $rep['id'];}
  1652. else $post['real_content'] = "[引用的文章]($reply_to)".$post['content'];
  1653. }
  1654. $this->Posts[] = $post;
  1655. $p_success = &$this->Posts[count($this->Posts) - 1];
  1656. }
  1657. $this->NeedWritePosts=1;
  1658. $this->NeedWriteImages=1;
  1659. if(isset($push_version) && $push_version){
  1660. $this->NeedWriteArchive=1;
  1661. }
  1662. return $p_success;
  1663. }
  1664. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1665. $this->ReadPosts();
  1666. $p_success = NULL;
  1667. if(isset($id_if_edit)){
  1668. $post = &$this->GetPost($id_if_edit,true);
  1669. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1670. if(isset($content)) $post['content'] = $content;
  1671. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1672. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1673. if(isset($ip)) $post['ip'] = $ip;
  1674. $p_success = &$post;
  1675. }else{
  1676. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1677. $id = date('YmdHis');
  1678. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1679. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1680. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1681. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1682. if(isset($ip)) $post['ip'] = $ip;
  1683. $this->Posts[] = $post;
  1684. $p_success = &$this->Posts[count($this->Posts) - 1];
  1685. }
  1686. $this->NeedWritePosts=1;
  1687. return $p_success;
  1688. }
  1689. function InsertReplacementSymbols($MarkdownContent){
  1690. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1691. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1692. function($matches){
  1693. $rep = preg_replace('/->/','-@>',$matches[0]);
  1694. $rep = preg_replace('/=>/','=@>',$rep);
  1695. $rep = preg_replace('/<=/','<@=',$rep);
  1696. $rep = preg_replace('/<-/','<@-',$rep);
  1697. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  1698. $rep = preg_replace('/\[-/','[@-',$rep);
  1699. $rep = preg_replace('/\{/','{@',$rep);
  1700. return $rep;
  1701. },
  1702. $replacement);
  1703. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  1704. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  1705. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  1706. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  1707. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  1708. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  1709. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  1710. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  1711. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  1712. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  1713. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  1714. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  1715. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  1716. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  1717. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1718. function($matches){
  1719. $rep = preg_replace('/-@>/','->',$matches[0]);
  1720. $rep = preg_replace('/<@-/','<-',$rep);
  1721. $rep = preg_replace('/=@>/','=>',$rep);
  1722. $rep = preg_replace('/<@=/','<=',$rep);
  1723. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  1724. $rep = preg_replace('/\[@-/','[-',$rep);
  1725. $rep = preg_replace('/\{@/','{',$rep);
  1726. return $rep;
  1727. },
  1728. $replacement);
  1729. return $replacement;
  1730. }
  1731. function CanShowPost(&$p){
  1732. if(!isset($p) || isset($p['comment_to'])) return false;
  1733. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  1734. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  1735. if($is_mark_slf && !$this->LoggedIn){ return false; }
  1736. if(isset($this->WayBack)){
  1737. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  1738. else if ($p['id']>$this->WayBack) return false;
  1739. }
  1740. if(!$this->InExperimentalMode){
  1741. if(!$this->LoggedIn){
  1742. if($is_mark_exp) return false;
  1743. return true;
  1744. }
  1745. return true;
  1746. }else{
  1747. if($is_mark_exp) return true;
  1748. return false;
  1749. }
  1750. }
  1751. function SkipProduct(&$p){
  1752. if($this->LoggedIn) return false;
  1753. return (isset($p['mark_value']) && $p['mark_value']==5);
  1754. }
  1755. function GetRedirect($args=NULL){
  1756. $str = 'index.php?';
  1757. if(isset($args['post'])) $str.='&post='.$args['post'];
  1758. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  1759. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  1760. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  1761. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  1762. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  1763. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  1764. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  1765. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  1766. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  1767. if(isset($args['category'])) $str.='&category='.$args['category'];
  1768. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  1769. if(isset($args['history'])) $str.='&history='.$args['history'];
  1770. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  1771. if(isset($args['version'])) $str.='&version='.$args['version'];
  1772. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  1773. if(isset($args['search'])) $str.='&search='.$args['search'];
  1774. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  1775. return $str;
  1776. }
  1777. function WriteAsNecessary(){
  1778. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  1779. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  1780. if($this->NeedWriteImages){ $this->WriteImages(); }
  1781. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  1782. }
  1783. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  1784. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  1785. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  1786. return 0;
  1787. }
  1788. if(isset($_GET['set_language'])){
  1789. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  1790. $redirect=$this->GetRedirect(); return 0;
  1791. }
  1792. if(isset($_GET['toggle_font'])){ $use_font='local';
  1793. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  1794. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  1795. $redirect=$this->GetRedirect(); return 0;
  1796. }
  1797. if(isset($_GET['set_wayback'])){
  1798. if($_GET['set_wayback']!='false'){
  1799. $wayback= date('YmdHis');
  1800. if($_GET['set_wayback']=='post'){
  1801. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  1802. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  1803. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  1804. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  1805. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  1806. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  1807. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  1808. }else{
  1809. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  1810. }
  1811. $redirect=$this->GetRedirect(); return 0;
  1812. }
  1813. if(isset($_GET['post'])){
  1814. $this->CurrentPostID = $_GET['post'];
  1815. $this->TagID = $this->CurrentPostID;
  1816. }
  1817. if(isset($_GET['offset'])){
  1818. $this->CurrentOffset = $_GET['offset'];
  1819. }
  1820. if(isset($_GET['part'])){
  1821. if($_GET['part'] == 'hot') $this->ExtraScripts.="ShowLeftSide();";
  1822. else if ($_GET['part'] == 'recent') $this->ExtraScripts.="ShowCenterSide();";
  1823. }
  1824. if(isset($_GET['post'])){
  1825. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  1826. }
  1827. if(isset($_POST['search_content'])){
  1828. $redirect='index.php?search='.$_POST['search_content'];return 0;
  1829. }
  1830. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  1831. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  1832. $direct_return = !isset($_GET['show_image']);
  1833. $this->ReadImages();
  1834. $this->ReadPosts();
  1835. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  1836. $im = &$this->FindImage($m);
  1837. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  1838. if($direct_return){
  1839. echo "<ref>".sizeof($im['refs'])."</ref>";
  1840. echo "<insert><ul>";
  1841. }else{ ob_start(); }
  1842. foreach(array_reverse($im['refs']) as $ref){
  1843. $p = $this->GetPost($ref);
  1844. if(!$p || !$this->CanShowPost($p)) continue;
  1845. $this->MakeSinglePost($p, false, true, "post_preview", true, false, false, false, true);"</li>";
  1846. }
  1847. if($direct_return){
  1848. echo "</ul></insert>";
  1849. }else{
  1850. $str = ob_get_clean();
  1851. $this->MakePageBegin();
  1852. $side = "";
  1853. if(isset($im['refs'])&&isset($im['refs'][0])){
  1854. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  1855. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  1856. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$im['file']);
  1857. $this->MakePageEnd();
  1858. }
  1859. exit;
  1860. }
  1861. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  1862. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  1863. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  1864. }
  1865. if($this->LoggedIn){
  1866. $this->DoUpload();
  1867. if(isset($_POST['settings_button'])){
  1868. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  1869. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  1870. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  1871. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  1872. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  1873. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  1874. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  1875. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  1876. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  1877. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  1878. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  1879. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  1880. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  1881. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  1882. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  1883. if(isset($_POST['settings_exp_index'])) $this->ExpIndex=$_POST['settings_exp_index'];
  1884. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  1885. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  1886. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  1887. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  1888. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  1889. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  1890. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  1891. $redirect=$_SERVER['REQUEST_URI'];
  1892. $this->DoLogout();
  1893. }
  1894. $this->WriteConfig();
  1895. return 0;
  1896. }
  1897. if(isset($_POST['settings_save_redirect'])){
  1898. if(isset($_POST['settings_redirect'])){
  1899. $this->BuildRedirectConfig($_POST['settings_redirect']);
  1900. }
  1901. $this->WriteConfig();
  1902. $redirect = 'index.php?extras=true'; return 0;
  1903. }
  1904. if(isset($_POST['settings_save_translation'])){
  1905. if(isset($_POST['settings_translation'])){
  1906. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  1907. }
  1908. $redirect = 'index.php?extras=true'; return 0;
  1909. }
  1910. if(isset($_GET['post'])){
  1911. if(isset($_GET['post_original'])){
  1912. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL);
  1913. exit;
  1914. }
  1915. }
  1916. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  1917. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL);
  1918. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  1919. return 0;
  1920. }
  1921. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  1922. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL);
  1923. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  1924. return 0;
  1925. }
  1926. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  1927. $c = $_POST['post_content'];
  1928. if('有什么想说的' == $c){ return 0;}
  1929. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  1930. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  1931. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  1932. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  1933. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  1934. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL))!=NULL){
  1935. $redirect='?post='.$edited['id']; return 0;
  1936. };
  1937. }
  1938. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  1939. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL))!=NULL){
  1940. $redirect='?post='.$edited['id']; return 0;
  1941. };
  1942. }
  1943. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  1944. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  1945. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  1946. }
  1947. }
  1948. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  1949. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  1950. $redirect='?post='.$pe['id']; return 0;
  1951. }
  1952. }
  1953. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  1954. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  1955. $c = $_POST['comment_box'];
  1956. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  1957. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  1958. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  1959. if(($edited = $this->EditComment(NULL,
  1960. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  1961. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  1962. $_SERVER['REMOTE_ADDR']))!=NULL){
  1963. $redirect='?post='.$_GET['post'];
  1964. return 0;
  1965. };
  1966. }
  1967. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  1968. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  1969. $new_name = $_POST['gallery_edit_new_name'];
  1970. if($old_name!=''){
  1971. $this->EditGallery($old_name, $new_name, false, true, null, null);
  1972. $redirect='?gallery='.$new_name;
  1973. }else{
  1974. $this->EditGallery(null, $new_name, false, true, null);
  1975. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  1976. }
  1977. return 0;
  1978. }
  1979. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  1980. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  1981. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  1982. return 0;
  1983. }
  1984. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  1985. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  1986. $this->ReadImages();
  1987. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  1988. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL);
  1989. }
  1990. }
  1991. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  1992. return 0;
  1993. }
  1994. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  1995. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  1996. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  1997. return 0;
  1998. }
  1999. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2000. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2001. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2002. return 0;
  2003. }
  2004. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2005. $this->ReadImages();
  2006. $gallery = $_GET['image_list'];
  2007. foreach($this->Images as $im){
  2008. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2009. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2010. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2011. }
  2012. exit;
  2013. }
  2014. $do_image_redirect = 0;
  2015. if(isset($_POST['image_button'])){
  2016. $this->ReadImages();
  2017. if(isset($_POST['image_ops_product_link'])){
  2018. if(preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif))/u',$_SERVER['REQUEST_URI'],$ma)){
  2019. $this->EditImage($ma[1], NULL, false, $_POST['image_ops_product_link'], NULL);
  2020. $redirect=$_SERVER['REQUEST_URI'];
  2021. $do_image_redirect = 1;
  2022. }
  2023. }
  2024. if(isset($_GET['pic'])&&isset($_POST['image_edit_new_name'])){
  2025. if (preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif))/u',$_GET['pic'],$ma) &&
  2026. preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2027. $this->EditImage($ma[1], NULL, false, NULL, $man[1]);
  2028. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$ma[2]]);
  2029. $do_image_redirect = 1;
  2030. }
  2031. }
  2032. $this->NeedWriteImages = 1;
  2033. if($do_image_redirect) return 0;
  2034. }
  2035. if(isset($_GET['rewrite_styles'])){
  2036. $this->WriteStyles();
  2037. $redirect='?extras=true'; return 0;
  2038. }
  2039. if(isset($_GET['regenerate_thumbnails'])){
  2040. $this->RegenerateThumbnails();
  2041. $redirect='?extras=true'; return 0;
  2042. }
  2043. if(isset($_GET['clear_all_logins'])){
  2044. $this->LoginTokens=[];
  2045. $this->WriteTokens();
  2046. }
  2047. }
  2048. return 0;
  2049. }
  2050. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null){
  2051. if(!$this->LoggedIn){
  2052. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2053. }
  2054. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2055. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2056. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2057. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2058. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2059. $html = preg_replace("/<p>\s*\{\s*INTERESTING\s+(.*?)\}\s*<\/p>/imu","",$html);
  2060. $images = [];
  2061. $images_noclick = [];
  2062. $html = preg_replace_callback(
  2063. "/(<p>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2064. function($m) use (&$images,&$images_noclick) {
  2065. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2066. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2067. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2068. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2069. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2070. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2071. $src = $im['thumb']; $orig_src=$im['file'];
  2072. }
  2073. if($this->InExperimentalMode){
  2074. $click = "<div class='imd'><a href='".$im['file']."' class='original_img' target='_blank'>".
  2075. $m[2].$orig_src.$m[7]."></a></div>";
  2076. return $click;
  2077. }else{ $click =
  2078. "<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2079. $m[2].($original?$orig_src:$src).$m[7]." data-imgsrc='".$m[5]."'".
  2080. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2081. ($original?" class='original_img'":"")."></a></div>";
  2082. $images_noclick[]=$m[2].$src.$m[7].">";
  2083. $ret = "";
  2084. if($keep) { $ret = $click; }
  2085. else { $images[] = $click; }
  2086. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2087. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2088. }
  2089. },$html,-1,$count);
  2090. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2091. if(sizeof($images)){
  2092. if(sizeof($images)==1){$html.= $images[0]; }
  2093. else{
  2094. $html.="<div class='p_row'>";
  2095. foreach($images as $img){
  2096. $html.="<div class='p_thumb'>".$img."</div>";
  2097. }
  2098. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2099. }
  2100. }
  2101. if(sizeof($images_noclick)){
  2102. $added_images = $images_noclick;
  2103. }
  2104. if($do_product_info){
  2105. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2106. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2107. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2108. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2109. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2110. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2111. else { $product_info['title'] = $this->T('商品'); }
  2112. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2113. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2114. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2115. $this->T('购买').' '.$product_info['title'].
  2116. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2117. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2118. }
  2119. return $html;
  2120. }
  2121. function ConvertPost(&$post){
  2122. if(!isset($post['html'])){
  2123. $info=[];
  2124. $post['html'] = $this->PostProcessHTML($this->PDE->text($this->InsertReplacementSymbols($post['content'])),
  2125. $post['images'],
  2126. isset($post['product']), $info);
  2127. if(isset($post['product'])) $post['product']=$info;
  2128. }
  2129. }
  2130. function GetPostTitle(&$post, $h1_only=false){
  2131. if(!isset($post['title'])){
  2132. if($h1_only){
  2133. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){return $m[1];}
  2134. return NULL;
  2135. }
  2136. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2137. else{ $post['title'] = $this->T('未命名'); if(preg_match('/(.*)$/mu',$post['content'],$m))
  2138. {$post['title'].=' ('.strip_tags($this->PDE->text($m[1])).')';} }
  2139. }
  2140. return $post['title'];
  2141. }
  2142. function DetectPageType(){
  2143. if($this->InExperimentalMode) $this->PageType='experimental';
  2144. else if(isset($_GET['history'])) $this->PageType='history';
  2145. else if(isset($_GET['extras'])) $this->PageType='extras';
  2146. else if(isset($_GET['settings'])) $this->PageType='settings';
  2147. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2148. else if(isset($_GET['search'])) $this->PageType='search';
  2149. else if(isset($_GET['category'])) $this->PageType='category';
  2150. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2151. else if(isset($_GET['comments'])) $this->PageType='comments';
  2152. else $this->PageType = "main";
  2153. }
  2154. function MakePageBegin(){ ?>
  2155. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2156. <head>
  2157. <meta charset='utf-8'>
  2158. <meta content="width=device-width, initial-scale=1" name="viewport">
  2159. <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->Title)?></title>
  2160. <?php if($this->UseRemoteFont){ ?><style>
  2161. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2162. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2163. </style><?php } ?>
  2164. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2165. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2166. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2167. </head>
  2168. <div class='page'>
  2169. <?php }
  2170. function MakeHeader(&$p){
  2171. $this->MakePageBegin() ?>
  2172. <script type='text/javascript'>
  2173. function toggle_mobile_show(a){a.classList.toggle('hidden_on_mobile')}
  2174. function ShowWaitingBar(){
  2175. wait = document.querySelector("#waiting_bar");
  2176. wait.style.display='';
  2177. }
  2178. function HideWaitingBar(){
  2179. wait = document.querySelector("#waiting_bar");
  2180. wait.style.display='none';
  2181. }
  2182. <?php if(!$this->InExperimentalMode){ ?>
  2183. function la_auto_grow(element){
  2184. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2185. }
  2186. var scroll_l=0,scroll_c=0;in_center=1;
  2187. function ShowLeftSide(){
  2188. scroll_c = window.scrollY;
  2189. document.getElementById('div_left').classList.remove('hidden_on_mobile');
  2190. document.getElementById('div_center').classList.add('hidden_on_mobile');
  2191. window.scroll(0, scroll_l); in_center=0;
  2192. }
  2193. function ShowCenterSide(){
  2194. scroll_l = window.scrollY;
  2195. document.getElementById('div_center').classList.remove('hidden_on_mobile');
  2196. document.getElementById('div_left').classList.add('hidden_on_mobile');
  2197. window.scroll(0, scroll_c); in_center=1;
  2198. }
  2199. function ShowBackdrop(alpha=0.5){
  2200. b = document.getElementById('backdrop');
  2201. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2202. b.style.animation='backdrop_fade_in 0.3s forwards';
  2203. b.style.display = 'block';
  2204. }
  2205. function HideBackdrop(){
  2206. b = document.getElementById('backdrop');
  2207. b.style.animation='backdrop_fade_out 0.3s forwards';
  2208. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2209. }
  2210. function ShowRightSide(big,elem_to_clone){
  2211. p = document.getElementById('pop_right');
  2212. if(elem_to_clone){
  2213. c = elem_to_clone.cloneNode(true);
  2214. c.id='side_bar_cloned';c.className="";c.style="";
  2215. p.querySelector('._content').appendChild(c);
  2216. }
  2217. p.classList.remove('pop_right','pop_right_big');
  2218. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2219. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2220. p.style.display='block';
  2221. ShowBackdrop(0.5);
  2222. }
  2223. function HideRightSide(){
  2224. p = document.getElementById('pop_right');
  2225. if(side=p.querySelector('#side_bar_cloned')){
  2226. side.remove();
  2227. }
  2228. put = document.querySelector("#_uploader");
  2229. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2230. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2231. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2232. HideBackdrop();
  2233. }
  2234. function ToggleLeftSide(){if(in_center)ShowLeftSide();else ShowCenterSide();}
  2235. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2236. function ScrollToPost(id){
  2237. post=null;
  2238. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2239. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2240. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2241. }
  2242. <?php } ?>
  2243. </script>
  2244. <header><div>
  2245. <?php if($this->InExperimentalMode){
  2246. $this->MakeExpNavButtons($p);
  2247. }else{
  2248. $this->MakeNavButtons($p);
  2249. } ?>
  2250. <hr />
  2251. <?php if(isset($this->WayBack)){
  2252. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2253. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2254. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2255. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_on_mobile")'>
  2256. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2257. <span class='hidden_on_mobile'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2258. <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_on_mobile'>
  2259. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2260. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2261. <br class='hidden_on_desktop' />
  2262. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2263. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2264. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2265. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2266. <br class='hidden_on_desktop' />
  2267. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2268. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2269. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2270. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2271. <br class='hidden_on_desktop' />
  2272. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2273. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2274. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2275. </div></div><?php } ?>
  2276. </div></header>
  2277. <div id='waiting_bar' style='display:none;'></div>
  2278. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2279. <?php if(!$this->InExperimentalMode){ ?>
  2280. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2281. <ul>
  2282. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2283. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2284. <hr />
  2285. <?php if($this->LoggedIn){ ?>
  2286. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2287. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2288. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2289. <?php if(!isset($this->WayBack)){ ?><li>
  2290. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2291. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2292. </li>
  2293. <li><a id='menu_mark' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2294. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2295. <li id='mark_details' style='display:none;'><b>
  2296. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2297. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2298. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2299. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2300. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2301. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2302. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2303. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2304. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2305. </b></li>
  2306. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2307. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2308. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2309. <input class='button' type='submit' form='post_rename_form'
  2310. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2311. </li>
  2312. <hr />
  2313. <li><a id='menu_delete' class='smaller'></a></li><?php } ?>
  2314. <?php }else{ ?>
  2315. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2316. <?php } ?>
  2317. </ul>
  2318. </div>
  2319. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide()'
  2320. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2321. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2322. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2323. <?=$this->T('关闭')?>→</a></div>
  2324. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2325. <div id='_uploader' style='display:none;'>
  2326. <?php $this->MakeUploader(true); ?>
  2327. <p>&nbsp;</p>
  2328. <?php $this->MakeSideGalleryCode(); ?>
  2329. </div>
  2330. <?php } ?>
  2331. <div class='_content'></div>
  2332. </div>
  2333. <?php } ?>
  2334. <?php
  2335. }
  2336. function TranslatePostParts($html){
  2337. $html = preg_replace_callback('/>([^><]+?)</u', function($ma){
  2338. return ">".$this->T($ma[1])."<";
  2339. }, $html);
  2340. return $html;
  2341. }
  2342. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); ?>
  2343. <a href='index.php' class='clean_a hidden_on_mobile' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title)?></b></a>
  2344. <b><a class='hidden_on_desktop'
  2345. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ShortTitle)?>...</a></b>
  2346. <div class='header_nav'>
  2347. <?php if($this->PageType=='post'){ ?>
  2348. <div style='float:right;' class='hidden_on_print'>
  2349. <?php if(!$interesting && isset($p) && isset($p['refs']) && isset($p['refs'][0])){ ?>
  2350. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2351. <?=$this->T('链接')?>(<?=sizeof($p['refs'])?>)</a></span>
  2352. <?php } if(!$interesting){ ?>
  2353. <span class='hidden_on_wide hidden_on_print'>
  2354. <a id='button_toc' href='javascript:ShowRightSide(true,document.querySelector("#div_right"));'>
  2355. <?=$this->T('目录')?></a></span><?php } ?></div>
  2356. <?php }else if($this->PageType=='history' && isset($_GET['version'])){ ?>
  2357. <div style='float:right;' class='hidden_on_print'>
  2358. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2359. <?=$this->T('历史')?></a></span></div>
  2360. <?php } ?>
  2361. <ul class='hidden_on_mobile hidden_on_print' id='mobile_nav' style='text-align:center;'>
  2362. <li class='hidden_on_mobile'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2363. <li class='hidden_on_desktop_force block_on_mobile'>
  2364. <?php if($this->PageType!='main'){ ?>
  2365. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a> |
  2366. <a href='index.php?part=hot' onclick='ShowWaitingBar()'><?=$this->T('热门')?></a> |
  2367. <?php } else { ?>
  2368. <li class='hidden_on_desktop_force block_on_mobile'>
  2369. <a href='javascript:ShowCenterSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('最近')?></a> |
  2370. <a href='javascript:ShowLeftSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('热门')?></a> |
  2371. <?php } ?>
  2372. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a>
  2373. <?php if($this->LoggedIn){ ?>
  2374. | <span class='gray invert_a'><a href='index.php?comments=al最近l'>@</a></span><?php } ?></li>
  2375. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2376. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST));
  2377. } ?>
  2378. <li><a href='?search=' onclick='ShowWaitingBar()'><?=$this->T('搜索')?></a></li>
  2379. <?php if($this->LanguageAppendix=='zh'){ ?>
  2380. <li class='invert_a smaller'>
  2381. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  2382. <?php }else { ?>
  2383. <li class='smaller'>
  2384. <a class='invert_a' href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  2385. 汉语/<b>English</b></a>
  2386. <br class='hidden_on_desktop' />
  2387. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  2388. <?php } ?>
  2389. </ul>
  2390. </div>
  2391. <?php
  2392. }
  2393. function MakeExpNavButtons(&$p){?>
  2394. <b><a href='index.php' class='hidden_on_mobile'><?=$this->T($this->ExpTitle)?></a></b>
  2395. <b><a class='hidden_on_desktop'
  2396. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ExpShortTitle)?>...</a></b>
  2397. <ul class='hidden_on_mobile' id='mobile_nav' style='text-align:center;'>
  2398. <li class='hidden_on_desktop block_on_mobile'><a href='index.php'><?=$this->T('索引')?></a></li>
  2399. <?php $this->ExpNavigation;if(isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2400. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST));
  2401. } ?>
  2402. <?php if($this->LanguageAppendix=='zh'){ ?>
  2403. <li class='invert_a smaller'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  2404. <?php }else { ?>
  2405. <li class='invert_a smaller'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  2406. <span class='text_highlight'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></span></li>
  2407. <?php } ?>
  2408. </ul>
  2409. <?php
  2410. }
  2411. function GenerateLinkedPosts($ht){
  2412. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  2413. function($m){
  2414. $rp = &$this->GetPost($m[1], false, true);
  2415. $s="<div class='smaller block post ref_compact gray'>".
  2416. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  2417. "<div class='post_ref'><div class='smaller'>".$m[2]."</div>".
  2418. (($rp!==NULL && $this->CanShowPost($rp))?$this->TranslatePostParts(
  2419. $this->GenerateSinglePost($rp,false,false,false,true,$this->NULL_POST,true)):$this->T("未找到该引用。")).
  2420. "</div></div>";
  2421. return $s;
  2422. },
  2423. $ht
  2424. );
  2425. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  2426. function($m){
  2427. $rp = &$this->GetPost($m[1], false, true);
  2428. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  2429. (($rp!==NULL && $this->CanShowPost($rp))?$this->TranslatePostParts(
  2430. $this->GenerateSinglePost($rp,true,false,false,true,$this->NULL_POST,true)):$this->T("未找到该引用。")).
  2431. "</a></div>";
  2432. return $s;
  2433. },
  2434. $ht
  2435. );
  2436. return $ht;
  2437. }
  2438. function ExtractBigTables($html, &$table_out){
  2439. $table = NULL;
  2440. $new_html = preg_replace_callback('/<p>\s*\{big_table\}\s*<\/p>\s*(<table>[\s\S]*?<\/table>)/u', function ($m) use (&$table){
  2441. $table = $m[1];
  2442. return "";
  2443. }, $html);
  2444. $table_out = $table;
  2445. return $new_html;
  2446. }
  2447. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  2448. $generate_thumbs=false, &$table_out, $hide_long = false){
  2449. $this->ConvertPost($post);
  2450. if($generate_anchor){ $this->CreatePostAnchor($post); }
  2451. $ht = $post['html'];
  2452. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  2453. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  2454. "<p class='bold'>".$post['product']['title']."</p>".
  2455. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  2456. "<p class='smaller bold'>".$post['product']['price']."</p>";
  2457. return $ht;
  2458. }
  2459. if($hide_long){
  2460. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  2461. }else{
  2462. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  2463. }
  2464. if ($strip_tags){
  2465. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  2466. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  2467. $ht = "<div class='post_ref_main'>".$ht."</div>";
  2468. }
  2469. else{
  2470. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  2471. if($table_out!=$this->NULL_POST){
  2472. $table = NULL; $ht = $this->ExtractBigTables($ht,$table);
  2473. $table_out = $table;
  2474. }else{
  2475. $ht = preg_replace('/<p>\s*\{big_table\}\s*<\/p>/u','',$ht);
  2476. }
  2477. }
  2478. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  2479. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  2480. foreach($post['images'] as $im){
  2481. $ht.="<li class='file_thumb'>".$im."</li>";
  2482. }
  2483. $ht.="</ul></div>";
  2484. }
  2485. return $ht;
  2486. }
  2487. function MakeSinglePostExp(&$post){
  2488. $big_table = ""; ?>
  2489. <li class='post post_dummy'>
  2490. <?=$this->TranslatePostParts(
  2491. $this->GenerateSinglePost($post, false, false, true, false, $big_table, false)); ?>
  2492. </li>
  2493. <?php if($big_table!=$this->NULL_POST) echo "</ul></li><div class='table_top'>".$big_table.'</div>';?>
  2494. <?php
  2495. }
  2496. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  2497. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  2498. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  2499. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  2500. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  2501. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  2502. $big_table = ($show_thread_link)?$this->NULL_POST:"";
  2503. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  2504. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  2505. ?>
  2506. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  2507. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?><?=$side?" post_box":""?>'
  2508. data-post-id='<?=$post['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  2509. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  2510. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  2511. <?php } ?>
  2512. <?php if($is_top){?>
  2513. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  2514. <?php } ?>
  2515. <?php if(!$side && $show_link){ ?>
  2516. <a href='?post=<?=$post['id']?>' onclick='ShowWaitingBar()'>
  2517. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2518. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"→")?>
  2519. </div>
  2520. <?php if($ref_count){ ?>
  2521. <div class='post_access ref_count'><?=$ref_count?></div>
  2522. <?php } ?>
  2523. </a>
  2524. <?php } ?>
  2525. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  2526. <div class='<?=$side?"":($show_link?'post_width':'post_width_big')?><?=$is_deleted?" deleted_post":""?>'>
  2527. <?php if(!$side && !$strip_tags){?>
  2528. <div class='post_menu_button _menu_hook' >+</div>
  2529. <?php } if($is_product&&!$generate_anchor){
  2530. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  2531. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  2532. <?=$this->TranslatePostParts(
  2533. $this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  2534. $generate_thumb,$big_table,($show_thread_link||$side||$force_hide_long))); ?>
  2535. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  2536. </div>
  2537. <?=$side?"</a>":""?> <?php
  2538. if(!$show_thread_link && $big_table!=$this->NULL_POST && !$side){
  2539. echo "</ul></li><div class='table_top'>".$big_table.'</div>';
  2540. ?><ul class='print_column'>
  2541. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  2542. <?php
  2543. }
  2544. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  2545. $post['tid']['first']['id']!=$post['id']){ ?>
  2546. <div class='gray smaller block opt_compact post'>
  2547. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  2548. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  2549. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  2550. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  2551. <?=$this->TranslatePostParts(
  2552. $this->GenerateSinglePost($post['tid']['first'], false, false, false, true,$this->NULL_POST,true));?>
  2553. </div>
  2554. </div>
  2555. <?php }
  2556. if($show_reply_count && isset($post['tid'])){ ?>
  2557. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  2558. <?=$this->T('个回复')?></a>
  2559. <?php }
  2560. ?>
  2561. </li>
  2562. <?php
  2563. }
  2564. function MakePostingFields($reply_to=NULL, $show_hint=false){
  2565. if(isset($this->WayBack)){ ?>
  2566. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  2567. <?php return; } ?>
  2568. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  2569. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  2570. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  2571. <div id='post_hint_modify' style='display:none;'>
  2572. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  2573. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  2574. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  2575. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  2576. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  2577. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  2578. onclick='ShowWaitingBar();' />
  2579. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  2580. <div style='float:right;'>
  2581. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  2582. <?=$this->T('清空')?></a>
  2583. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  2584. </div>
  2585. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  2586. <script> la_auto_grow(document.getElementById("post_content"));</script>
  2587. <?php if($reply_to){ ?>
  2588. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  2589. <?php } ?>
  2590. <?php
  2591. }
  2592. function MakeCommentPosts(){
  2593. if(!$this->LoggedIn) return; ?>
  2594. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  2595. <?php if(!$this->CommentEnabled){
  2596. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  2597. <div class='comment'><ul>
  2598. <?php $i=0;
  2599. foreach(array_reverse($this->Posts) as $p){
  2600. if(!isset($p['comment_to'])) continue;
  2601. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  2602. $ht = $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false, $t, false));
  2603. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  2604. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  2605. if(!$post_to) $post_title = "?";
  2606. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  2607. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  2608. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  2609. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  2610. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  2611. $i++;
  2612. }
  2613. ?>
  2614. </ul><br /></div>
  2615. <?php
  2616. }
  2617. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  2618. <div class='center' id='div_center'>
  2619. <h2><?=isset($search_term)?$this->T('搜索'):
  2620. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  2621. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  2622. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  2623. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  2624. <?php if(isset($search_term)){ ?>
  2625. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  2626. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  2627. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  2628. <?php }else if(isset($category)){ ?>
  2629. <div></div>
  2630. <?php }else if($this->LoggedIn){ ?>
  2631. <div class='post_box_top _input_bundle'>
  2632. <?php $this->MakePostingFields(NULL,false); ?>
  2633. </div>
  2634. <?php } ?>
  2635. <ul class='print_column list'>
  2636. <?php
  2637. if(!isset($search_term) && !isset($category) &&
  2638. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  2639. $this->CanShowPost($p)){
  2640. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  2641. }
  2642. $i = 0;
  2643. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  2644. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2645. if(isset($p['tid'])){ /* Should always be set. */
  2646. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  2647. if(!isset($search_term)) { $p = &$th['last']; }
  2648. }
  2649. if(isset($search_term)){
  2650. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  2651. }else if(isset($category)){
  2652. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  2653. (isset($p['categories'])?($p['categories']):[]);
  2654. if ($category=='none') { if($cat!=[]) continue; }
  2655. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  2656. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2657. }else{
  2658. if(in_array($p['id'],
  2659. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  2660. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2661. }
  2662. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  2663. $this->MakeSinglePost($p, true, false, NULL, false, !isset($search_term), false, false, false, false, isset($search_term));
  2664. $i++;
  2665. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  2666. }?>
  2667. </ul>
  2668. <div class='page_selector clean_a'>
  2669. <hr />
  2670. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  2671. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  2672. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  2673. <?=$this->CurrentOffset+1?>
  2674. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  2675. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  2676. → <?=$this->T('下一页')?></a>
  2677. </div>
  2678. </div>
  2679. <?php
  2680. }
  2681. function MakeHotPosts($placeholder_only=false){?>
  2682. <div class='left hidden_on_mobile' id='div_left'>
  2683. <?php if ($placeholder_only){ ?>&nbsp;
  2684. <?php }else{ ?>
  2685. <h2><?=$this->T('热门')?></h2>
  2686. <ul>
  2687. <?php
  2688. $i=0;
  2689. foreach($this->Threads as &$th){
  2690. if(!isset($th['first']) || $th['count']==0){ continue; }
  2691. if(!$this->CanShowPost($th['first'])) continue;
  2692. if($i>=$this->HotPostCount) break;
  2693. $this->MakeSinglePost($th['first'], false, true, "post_preview", true, false, true, false, true, false, false);
  2694. $i++;
  2695. } ?>
  2696. </ul>
  2697. <?php } ?>
  2698. </div>
  2699. <?php
  2700. }
  2701. function MakeLinkedPosts(&$p){
  2702. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  2703. <div class='left hidden_on_mobile' id='div_left'>
  2704. <h2<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h2>
  2705. <?php
  2706. if($has_ref){ ?>
  2707. <span class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></span>
  2708. <ul><?php $count_product=0;
  2709. foreach(array_reverse($p['refs']) as &$pr){
  2710. $po = $this->GetPost($pr); if(isset($post['mark_value']) && $po['mark_value']==5){ $count_product++; continue; }
  2711. if(!$this->CanShowPost($po)){ continue; }
  2712. $this->MakeSinglePost($po, false, true, "post_preview", true, false, false, false, true, false, false);
  2713. }
  2714. ?></ul>
  2715. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  2716. }else{ ?>
  2717. <span class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></span>
  2718. <?php } ?>
  2719. </div>
  2720. <?php
  2721. }
  2722. function MakeLinkedPostsExp(&$p){
  2723. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  2724. <div class='center_exp post_dummy smaller'>
  2725. <hr />
  2726. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  2727. <?php
  2728. if($has_ref){ ?>
  2729. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  2730. <ul><?php $count_product=0;
  2731. foreach(array_reverse($p['refs']) as &$pr){
  2732. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  2733. "</a></li>";
  2734. }
  2735. ?></ul>
  2736. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  2737. }else{ ?>
  2738. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  2739. <?php } ?>
  2740. <div style='margin-bottom:4rem;'>&nbsp;</div>
  2741. </div>
  2742. <?php
  2743. }
  2744. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  2745. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  2746. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  2747. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  2748. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  2749. if(!isset($title)) $title=$this->T('未命名');
  2750. if(!isset($ah)){ ?>
  2751. <h2><?=$this->T('没有历史记录')?></h2>
  2752. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  2753. <?php }else{ ?>
  2754. <h2><?=$this->T('历史记录')?></h2>
  2755. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  2756. <div class='list'><ul>
  2757. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  2758. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  2759. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  2760. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  2761. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  2762. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  2763. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  2764. <li><a href='?post=<?=$ver['id']?>&history=1'>
  2765. <?=$this->GetPostTitle($ver);?></a>
  2766. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  2767. <?php } ?></ul><?php } ?>
  2768. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  2769. $mah = &$this->GetArchiveHandle($pm);
  2770. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  2771. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  2772. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  2773. <?php } ?>
  2774. </li><?php } ?>
  2775. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  2776. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  2777. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  2778. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  2779. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  2780. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  2781. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  2782. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  2783. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  2784. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  2785. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  2786. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  2787. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  2788. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  2789. <li><a href='?post=<?=$ver['id']?>&history=1'>
  2790. <?=$this->GetPostTitle($ver);?></a>
  2791. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  2792. <?php } ?></ul></li><?php } ?>
  2793. <?php } ?></ul></div>
  2794. <?php } ?>
  2795. <?php
  2796. }
  2797. function MakePostDiff(&$this_ver, &$last_ver){
  2798. if(!isset($this_ver)){ ?>
  2799. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  2800. <?php }else{ ?>
  2801. <h2><?=$this->T('差异')?></h2>
  2802. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  2803. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  2804. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  2805. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  2806. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  2807. <?php }else{ ?>
  2808. <table class='diff_table'><thead>
  2809. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  2810. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  2811. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  2812. </thead><tbody>
  2813. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  2814. </tbody>
  2815. </table>
  2816. <?php } ?>
  2817. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  2818. <?php } ?>
  2819. <?php
  2820. }
  2821. function MakePostHistory(&$post, $version=NULL){
  2822. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  2823. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  2824. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  2825. ?>
  2826. <div class='left hidden_on_mobile history' id='div_left'>
  2827. <?php if (isset($version)){
  2828. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  2829. }else{ echo "&nbsp;"; } ?>
  2830. </div>
  2831. <div class='center history' id='div_center'>
  2832. <?php if (!isset($version)){
  2833. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  2834. }else{
  2835. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  2836. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  2837. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  2838. $this->MakePostDiff($this_ver, $last_ver, $p);
  2839. } ?>
  2840. </div>
  2841. <?php
  2842. }
  2843. function MakeCommentSection(&$post){
  2844. if(!$this->CommentEnabled){ return; }
  2845. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  2846. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  2847. ?><div class='comment'>
  2848. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  2849. <?php if($comment_count) { echo "<ul>";
  2850. foreach($to_post['comments'] as $p){
  2851. $ht = $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false, $t, false));
  2852. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  2853. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  2854. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  2855. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  2856. }
  2857. echo "</ul>";
  2858. } else {
  2859. echo $this->T('还没有评论');
  2860. } ?>
  2861. <div class='hidden_on_print'>
  2862. <div class='spacer'></div>
  2863. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  2864. method="post" style="display:none;" id="comment_form"></form>
  2865. <p><a class='text_highlight bold clean_a'
  2866. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  2867. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  2868. <div id='comment_box' style='display:none;'>
  2869. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  2870. <table style='white-space:nowrap;'>
  2871. <tr><td colspan='2'>
  2872. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  2873. oninput="CommentUpdated();" ></textarea>
  2874. </td></tr>
  2875. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  2876. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  2877. class='full_box' oninput="CommentUpdated();" /></td>
  2878. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  2879. class='full_box' oninput="CommentUpdated();" /></td></tr>
  2880. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  2881. <tr><td colspan='2'>
  2882. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  2883. class='full_box' oninput="CommentUpdated();" />
  2884. </td></tr>
  2885. <tr><td colspan='2'>
  2886. <div class='spacer'></div>
  2887. <input class='button text_highlight bigger' type='submit' form='comment_form'
  2888. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  2889. </td></tr>
  2890. </table></div>
  2891. <script>
  2892. const IsValidEmail = (email) => {
  2893. 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,}))$/);
  2894. };
  2895. function IsValidHttpUrl(string) {
  2896. let url; try{ url = new URL(string); } catch (_) { return false; }
  2897. return url.protocol === "http:" || url.protocol === "https:";
  2898. }
  2899. var cbox = document.getElementById('comment_box');
  2900. var cemail = document.getElementById('comment_email');
  2901. var cname = document.getElementById('comment_name');
  2902. var clink = document.getElementById('comment_link');
  2903. var cconfirm = document.getElementById('comment_confirm');
  2904. function CommentUpdated(){
  2905. cconfirm.disabled=true;
  2906. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  2907. cbox.innerText.length>2 && cname.value.length>2 &&
  2908. clink.value=="" || IsValidHttpUrl(clink.value)){
  2909. cconfirm.removeAttribute("disabled");
  2910. }
  2911. }
  2912. CommentUpdated();
  2913. </script>
  2914. </div>
  2915. </div>
  2916. <?php
  2917. }
  2918. function MakeInterestingSection(&$th){
  2919. $this->Anchors = [];
  2920. $c = &$th['first']['content'];
  2921. $this->ConvertPost($th['first']);
  2922. $ht = $th['first']['html'];
  2923. ?>
  2924. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  2925. <div class='center_full' id='div_center'>
  2926. <?php $this->MakePostTools(); ?>
  2927. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  2928. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  2929. <ul><li class='post post_width_big' data-post-id='<?=$th['first']['id']?>'>
  2930. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$this->TranslatePostParts($ht)?>
  2931. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  2932. <?php foreach($th['first']['refs'] as $ref){
  2933. $po = $this->GetPost($ref);
  2934. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  2935. if(!$this->CanShowPost($po)){ continue; }
  2936. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  2937. } ?>
  2938. </ul><?php } ?>
  2939. <?php if($this->LoggedIn && (!$this->InExperimentalMode)){ ?>
  2940. <div class='post_width_big hidden_on_print'><br />
  2941. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  2942. </div>
  2943. <?php } ?>
  2944. <table><thead><tr><th></th><?php foreach($th['interesting'] as $header){ ?>
  2945. <th><?=$this->T($header);?></th>
  2946. <?php } ?></tr></thead><tbody class='interesting_tbody'>
  2947. <?php $plist = array_reverse(array_slice($th['arr'],1));
  2948. foreach($plist as &$p){
  2949. $this->ConvertPost($p);
  2950. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  2951. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  2952. $is_current = $p['id']==$this->CurrentPostID;
  2953. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  2954. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  2955. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  2956. onDblClick='ClickImage(this)'><td>
  2957. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  2958. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2959. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  2960. </div>
  2961. <?php if($ref_count){ ?>
  2962. <div class='post_access ref_count'><?=$ref_count?></div>
  2963. <?php } ?></a>
  2964. <?=$this->TranslatePostParts($p['html']);?>
  2965. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a></td></tr>
  2966. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  2967. <?php foreach($p['refs'] as $ref){
  2968. $po = $this->GetPost($ref);
  2969. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  2970. if(!$this->CanShowPost($po)){ continue; }
  2971. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  2972. } ?>
  2973. </ul></td></tr><?php } ?>
  2974. <?php } ?>
  2975. </tbody></table>
  2976. </li></ul>
  2977. <br />
  2978. <?php $this->MakeCommentSection($th['first']); ?>
  2979. </div>
  2980. <?php return true;
  2981. }
  2982. function CssNumberID($id){
  2983. return "#\\3".substr($id,0,1)." ".substr($id,1);
  2984. }
  2985. function MakePostTools(){
  2986. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  2987. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  2988. <?=$this->T('工具')?></a>:<div class='hidden_on_mobile' style='display:inline'>
  2989. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  2990. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  2991. </div>
  2992. <select class='hidden_on_desktop' id='merge_select'
  2993. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  2994. <option value='-1' selected>--</option>
  2995. <option value='1'><?=$this->T('合并帖子')?></option>
  2996. <option value='2'><?=$this->T('合并话题')?></option></select>
  2997. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  2998. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  2999. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3000. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3001. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3002. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3003. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3004. </div><div class='spacer'></div><?php
  3005. }
  3006. }
  3007. function MakePostSection(&$post){
  3008. $this->Anchors = [];
  3009. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3010. <div class='center' id='div_center'>
  3011. <h2 class='hidden_on_print'>
  3012. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1; if($is_thread){ $th = $post['tid'];?>
  3013. <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3014. <?php } ?></h2>
  3015. <?php $cat = NULL;
  3016. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3017. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3018. $this->MakePostTools();
  3019. if($cat){ ?>
  3020. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3021. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3022. <?php } ?>
  3023. <ul class='print_column'>
  3024. <?php
  3025. if($is_thread){
  3026. foreach($th['arr'] as &$p){
  3027. $use_class = ($p == $post)?'focused_post':'';
  3028. $show_link = ($p == $post)?false:true;
  3029. $make_title = ($p == $post);
  3030. $this->MakeSinglePost($p,$show_link,false,$use_class,false, false, false, true, false, false);
  3031. if($make_title){?>
  3032. <script>
  3033. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3034. </script>
  3035. <?php }
  3036. }
  3037. }else{
  3038. $this->MakeSinglePost($post,false, false, 'focused_post',false, false, false, true, false, false);
  3039. ?><script>
  3040. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3041. </script><?php
  3042. } ?>
  3043. <div class='smaller align_right'>
  3044. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3045. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3046. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3047. </div>
  3048. <?php if($this->LoggedIn && (!$this->InExperimentalMode)){ ?>
  3049. <div class='post_width_big hidden_on_print'>
  3050. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3051. </div>
  3052. <?php }
  3053. $this->MakeCommentSection($post);
  3054. ?>
  3055. </ul>
  3056. </div>
  3057. <?php
  3058. }
  3059. function MakePostSectionExp(&$post){
  3060. $this->Anchors = []; $is_thread = isset($post['tid']);
  3061. ?>
  3062. <div class='center_exp' id='div_center'>
  3063. <ul>
  3064. <?php
  3065. if($is_thread){
  3066. $th = &$post['tid'];
  3067. foreach($th['arr'] as &$p){
  3068. $this->MakeSinglePostExp($p);
  3069. if($p == $th['first']){?>
  3070. <script>
  3071. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3072. </script>
  3073. <?php }
  3074. }
  3075. }else{
  3076. $this->MakeSinglePostExp($post);
  3077. if($post['id']!=$this->ExpIndex){ ?><script>
  3078. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3079. </script><?php }
  3080. } ?>
  3081. </ul>
  3082. </div>
  3083. <?php
  3084. }
  3085. function MakeSideGalleryCode(){?>
  3086. <div>
  3087. <h3><?=$this->T('点击图片以插入:')?></h3>
  3088. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3089. <option value="main"><?=$this->T('全部')?></option>
  3090. <?php if($this->LoggedIn){ ?>
  3091. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3092. <?php }?>
  3093. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3094. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3095. <?php } ?>
  3096. </select>
  3097. <div id='side_gallery'>
  3098. </div>
  3099. </div>
  3100. <script>
  3101. function InsertImage(imgname){
  3102. t = document.querySelector("#post_content");
  3103. v = t.value;
  3104. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3105. la_auto_grow(t);
  3106. }
  3107. function RefreshSideGallery(){
  3108. let xhr = new XMLHttpRequest();
  3109. xhr.onreadystatechange = (function(){
  3110. if (this.readyState === this.DONE) {
  3111. if (this.status === 200) {
  3112. ind = document.querySelector("#side_gallery");
  3113. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3114. str = "<ul class='side_thumb'>"
  3115. for (const m of res) {
  3116. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+
  3117. "<img src='"+m[2]+"' /></div>"
  3118. }
  3119. str += "</ul>"
  3120. ind.innerHTML = str;
  3121. }
  3122. }
  3123. }
  3124. });
  3125. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3126. xhr.send();
  3127. }
  3128. </script>
  3129. <?php
  3130. }
  3131. function MakeUploader($is_side=false){ ?>
  3132. <div id='upload_operation_area' class='hidden_on_print'>
  3133. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3134. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3135. <ul id='file_list'>
  3136. </ul>
  3137. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3138. </div>
  3139. <a id='upload_click' class='hidden_on_print'
  3140. href='javascript:UploadList()'<?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3141. <script>
  3142. function pastehandler(event){
  3143. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3144. for (index in items) {
  3145. var item = items[index];
  3146. if (item.kind === 'file') {
  3147. put = document.querySelector("#_uploader");
  3148. if(put) ShowSideUploader();
  3149. var blob = item.getAsFile();
  3150. AddImageFile(blob);
  3151. return;
  3152. }
  3153. }
  3154. }
  3155. let _fd_list = [];
  3156. let hint=document.querySelector('#upload_hint');
  3157. function ToggleCompress(button){
  3158. li = button.parentNode;
  3159. num=li.dataset.number;
  3160. for(i=0;i<_fd_list.length;i++){
  3161. if (_fd_list[i][0] == num){
  3162. state = _fd_list[i][2];
  3163. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3164. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3165. }
  3166. }
  3167. }
  3168. function RemoveFromUpload(button){
  3169. li = button.parentNode;
  3170. num=li.dataset.number;
  3171. for(i=0;i<_fd_list.length;i++){
  3172. if (_fd_list[i][0] == num){
  3173. _fd_list.splice(i, 1);break;
  3174. }
  3175. }
  3176. li.parentNode.removeChild(li);
  3177. }
  3178. function EndThisUpload(){
  3179. unfinished = 0;
  3180. for(i=0;i<_fd_list.length;i++){
  3181. if (_fd_list[i][3]==0){
  3182. unfinished=1;
  3183. }
  3184. }
  3185. if(!unfinished){
  3186. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3187. cl=document.querySelector('#upload_click');
  3188. if(!cl.dataset.isSide){
  3189. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3190. cl.href=window.location.href;
  3191. }else{
  3192. _fd_list.splice(0,_fd_list.length);
  3193. fl = document.querySelector("#file_list");
  3194. fl.innerHTML = "";
  3195. list=document.querySelector('#upload_operation_area');
  3196. list.style.pointerEvents='';
  3197. list.style.opacity='';
  3198. document.onpaste=pastehandler;
  3199. RefreshSideGallery();
  3200. }
  3201. }
  3202. }
  3203. function UploadList(){
  3204. if(!_fd_list.length) return;
  3205. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3206. list=document.querySelector('#upload_operation_area');
  3207. list.style.pointerEvents='none';
  3208. list.style.opacity='0.5';
  3209. document.onpaste="";
  3210. for(i=0;i<_fd_list.length;i++){
  3211. let xhr = new XMLHttpRequest();
  3212. //xmlHTTP.upload.addEventListener("loadstart", loadStartFunction, false);
  3213. //xmlHTTP.upload.addEventListener("progress", progressFunction, false);
  3214. //xmlHTTP.addEventListener("load", transferCompleteFunction, false);
  3215. //xmlHTTP.addEventListener("error", uploadFailed, false);
  3216. //xmlHTTP.addEventListener("abort", uploadCanceled, false);
  3217. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3218. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3219. function wrap(li, i){
  3220. var ind = li.querySelector('._compress_toggle')
  3221. return function(){
  3222. if (this.readyState === this.DONE) {
  3223. if (this.status === 200) {
  3224. var response = xhr.responseText;
  3225. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3226. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3227. _fd_list[i][3] = 1;
  3228. }else{
  3229. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3230. _fd_list[i][3] = 1;
  3231. }
  3232. EndThisUpload();
  3233. }
  3234. }
  3235. }
  3236. }
  3237. xhr.onreadystatechange = wrap(li, i);
  3238. xhr.send(_fd_list[i][1]);
  3239. }
  3240. }
  3241. function AddImageFile(blob){
  3242. var ext="";
  3243. if(blob.name.match(/png$/))ext = 'png';
  3244. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3245. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3246. else if(blob.name.match(/gif$/))ext = 'gif';
  3247. else return;
  3248. var fd = new FormData();
  3249. blob.name = blob.name=generateUID().toString();
  3250. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3251. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3252. var reader = new FileReader();
  3253. reader.onload = function(event){
  3254. fl = document.querySelector("#file_list");
  3255. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3256. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3257. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3258. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3259. fl.innerHTML+=ht;
  3260. };
  3261. reader.readAsDataURL(blob);
  3262. }
  3263. sel = document.querySelector('#upload_selector');
  3264. sel.addEventListener("change", function(){
  3265. var input = this;
  3266. function ff(file){
  3267. return function(e){
  3268. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3269. blob.name = file.name;
  3270. AddImageFile(blob);
  3271. }
  3272. }
  3273. for(i=0;i<input.files.length;i++){
  3274. if(input.files[i].size){
  3275. let reader = new FileReader();
  3276. reader.onload = ff(input.files[i]);
  3277. reader.readAsArrayBuffer(input.files[i]);
  3278. }
  3279. }
  3280. });
  3281. function generateUID() {
  3282. var firstPart = (Math.random() * 46656) | 0;
  3283. var secondPart = (Math.random() * 46656) | 0;
  3284. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3285. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3286. return firstPart + secondPart;
  3287. }
  3288. document.onpaste = pastehandler;
  3289. function dropHandler(ev) {
  3290. put = document.querySelector("#_uploader");
  3291. if(put) ShowSideUploader();
  3292. bkg=document.querySelector('#dropping_background');
  3293. bkg.style.display="none";
  3294. console.log('File(s) dropped');
  3295. ev.preventDefault();ev.stopPropagation();
  3296. if (ev.dataTransfer && ev.dataTransfer.items) {
  3297. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3298. if (ev.dataTransfer.items[i].kind === 'file') {
  3299. var file = ev.dataTransfer.items[i].getAsFile();
  3300. function ff(file){
  3301. return function(e){
  3302. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3303. blob.name = file.name;
  3304. AddImageFile(blob);
  3305. }
  3306. }
  3307. if(file){
  3308. let reader = new FileReader();
  3309. reader.onload = ff(file);
  3310. reader.readAsArrayBuffer(file);
  3311. }
  3312. }
  3313. }
  3314. } else {
  3315. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3316. function ff(file){
  3317. return function(e){
  3318. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3319. blob.name = file.name;
  3320. AddImageFile(blob);
  3321. }
  3322. }
  3323. if(ev.dataTransfer.files[i].size){
  3324. let reader = new FileReader();
  3325. reader.onload = ff(ev.dataTransfer.files[i]);
  3326. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3327. }
  3328. }
  3329. }
  3330. }
  3331. function dragOverHandler(ev) {
  3332. bkg=document.querySelector('#dropping_background');
  3333. bkg.style.display="";
  3334. console.log('File(s) in drop zone');
  3335. ev.preventDefault();
  3336. }
  3337. </script>
  3338. <?php
  3339. }
  3340. function CanShowGallery(&$g){
  3341. if(!$this->LoggedIn && isset($g['experimental']) && $g['experimental']) return false;
  3342. return true;
  3343. }
  3344. function CanShowImage(&$im){
  3345. if(!$this->LoggedIn && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3346. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3347. }
  3348. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3349. return true;
  3350. }
  3351. function MakeGallerySection(){
  3352. if(!isset($_GET['gallery'])) return;
  3353. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3354. $name=$_GET['gallery'];}?>
  3355. <script>
  3356. document.title+=" | <?=$this->T('画廊')?>";
  3357. </script>
  3358. <div class='center_wide' id='div_center' style='position:relative;'>
  3359. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3360. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3361. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3362. <div class='hidden_on_desktop'>
  3363. <?=$this->T('前往')?>
  3364. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  3365. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3366. if(!isset($g['featured']) || !$g['featured'] ||
  3367. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3368. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3369. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3370. <?php } ?>
  3371. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  3372. <?php if($this->LoggedIn){ ?>
  3373. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  3374. <?php } ?>
  3375. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3376. if((isset($g['featured']) && $g['featured']) ||
  3377. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3378. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3379. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3380. <?php } ?>
  3381. </select>
  3382. </div>
  3383. <?php if($this->LoggedIn){?>
  3384. <div>
  3385. <?php if(isset($name)){ ?>
  3386. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  3387. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  3388. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  3389. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  3390. <?=$this->T('取消精选')?></a>
  3391. <?php }else{ ?>
  3392. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  3393. <?=$this->T('设为精选')?></a>
  3394. <?php } ?><br />
  3395. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  3396. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  3397. <?=$this->T('取消实验')?></a>
  3398. <?php }else{ ?>
  3399. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  3400. <?=$this->T('设为实验')?></a>
  3401. <?php } ?>
  3402. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  3403. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  3404. <a href='javascript:HidePopMenu();'>×</a>
  3405. <hr />
  3406. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  3407. </div>
  3408. </div>
  3409. <?php } ?>
  3410. <?php $this->MakeUploader(false); ?>
  3411. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  3412. <div style='position:relative'>
  3413. <?php if(isset($name)){ ?>
  3414. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  3415. <?php } ?>
  3416. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  3417. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  3418. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  3419. method="post" style='display:none;' id='gallery_edit_form'></form>
  3420. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  3421. <a href='javascript:HidePopMenu();'>×</a>
  3422. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  3423. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  3424. <input class='button' type='submit' form='gallery_edit_form'
  3425. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  3426. </div>
  3427. </div>
  3428. </div>
  3429. <div class='smaller hidden_on_print'>
  3430. <form action="<?=$_SERVER['REQUEST_URI']?>"
  3431. method="post" style='display:none;' id='gallery_move_form'></form>
  3432. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  3433. id='gallery_move_ops' style='display:none'>
  3434. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  3435. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  3436. <p><?=$this->T('添加到')?>
  3437. <select id="gallery_move_to">
  3438. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3439. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3440. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  3441. <?php } ?>
  3442. </select>
  3443. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  3444. </p>
  3445. <p>
  3446. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  3447. </p>
  3448. </div>
  3449. </div>
  3450. <?php } ?>
  3451. <p>&nbsp;</p>
  3452. <div>
  3453. <?php $opened=0; $prev_year=""; if(isset($this->Images[0])) foreach($this->Images as $im){
  3454. if(!$this->CanShowImage($im)){ continue; }
  3455. if($_GET['gallery']=='trash') $name='trash';
  3456. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;}
  3457. $year = substr($im['name'], 0, 4);
  3458. if($year!=$prev_year){
  3459. if($opened) { ?><div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div></div><?php } ?>
  3460. <div><h2 class='sticky_title'><?=$year;?></h2><div class='p_row'><?php $prev_year=$year; $opened=1; } ?>
  3461. <div class='p_thumb'>
  3462. <?php if($this->LoggedIn){ ?>
  3463. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3464. <?php } ?>
  3465. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'><img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'<?=isset($im['product'])?
  3466. 'data-product="'.$im["product"].'"':""?>/></a>
  3467. </div>
  3468. <?php } if($opened) { ?>
  3469. <div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div><?php } ?>
  3470. </div>
  3471. </div>
  3472. <?php if($this->LoggedIn){ ?>
  3473. <script type='text/javascript'>
  3474. var selected_image = new Array();
  3475. function RemoveFromGallery(){
  3476. form = document.querySelector('#gallery_move_form');
  3477. ops = document.querySelector('#gallery_move_ops');
  3478. sel = document.querySelector('#gallery_move_to');
  3479. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  3480. form.submit();
  3481. }
  3482. function AddToGallery(){
  3483. form = document.querySelector('#gallery_move_form');
  3484. ops = document.querySelector('#gallery_move_ops');
  3485. sel = document.querySelector('#gallery_move_to');
  3486. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  3487. form.submit();
  3488. }
  3489. function ClearSelectedImages(){
  3490. selected_image.splice(0, selected_image.length);
  3491. checks = document.querySelectorAll('._select_hook');
  3492. [].forEach.call(checks, function(c){
  3493. c.classList.remove('p_thumb_selected');
  3494. });
  3495. count = document.querySelector('#gallery_selected_count');
  3496. count.innerHTML="0";
  3497. }
  3498. function ToggleSelectImage(elem, name){
  3499. count = document.querySelector('#gallery_selected_count');
  3500. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  3501. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  3502. count.innerHTML=selected_image.length.toString()
  3503. }
  3504. function ShowGalleryEditMenu(old_name){
  3505. m = document.querySelector('#gallery_edit_menu');
  3506. old = document.querySelector('#gallery_edit_old_name');
  3507. newname = document.querySelector('#gallery_edit_new_name');
  3508. m.style.display='block';
  3509. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  3510. }
  3511. function ShowDeleteMenu(){
  3512. m=document.querySelector('#gallery_delete_menu');
  3513. m.style.display='block';
  3514. }
  3515. </script>
  3516. <?php } ?>
  3517. <?php
  3518. }
  3519. function MakeGalleryLeft(){?>
  3520. <div class='left hidden_on_mobile gallery_left' id='div_left'>
  3521. <h2><?=$this->T('相册')?></h2>
  3522. <div>
  3523. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  3524. <ul>
  3525. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3526. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  3527. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3528. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  3529. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3530. <?php } ?>
  3531. </ul>
  3532. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  3533. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  3534. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  3535. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3536. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  3537. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3538. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  3539. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3540. <?php } ?>
  3541. <?php if($this->LoggedIn){ ?>
  3542. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  3543. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  3544. <?php } ?>
  3545. </ul></div>
  3546. <p>&nbsp;</p>
  3547. <script>
  3548. </script>
  3549. </div>
  3550. </div>
  3551. <?php
  3552. }
  3553. function MakeTOC(){?>
  3554. <div class='right hidden_on_mobile' id='div_right'>
  3555. <?php if(isset($this->Anchors[0])){?>
  3556. <h2><?=$this->T('目录')?></h2><ul>
  3557. <?php
  3558. foreach($this->Anchors as $a){?>
  3559. <li class='toc_entry_<?=$a[0]>5?5:$a[0]?>'><a href='#<?=$a[1]?>'><?=$this->T($a[2])?></a></li>
  3560. <?php }
  3561. ?></ul>
  3562. <?php }else{ ?>
  3563. <h2 class='gray'><?=$this->T('目录')?></h2>
  3564. <span class='gray smaller'><?=$this->T('未找到目录')?></span>
  3565. <?php } ?>
  3566. </div>
  3567. <?php
  3568. }
  3569. function MakeSettings(){?>
  3570. <div class='settings'>
  3571. <h2><?=$this->T('设置')?></h2>
  3572. <table style='white-space:nowrap;'>
  3573. <?php if($this->LoggedIn){ ?>
  3574. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  3575. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  3576. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  3577. <tr><td><?=$this->T('网站标题')?></td>
  3578. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  3579. value='<?=$this->Title?>'/></td></tr>
  3580. <tr><td><?=$this->T('短标题')?></td>
  3581. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  3582. value='<?=$this->ShortTitle?>'/></td></tr>
  3583. <tr><td><?=$this->T('显示名称')?></td>
  3584. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  3585. value='<?=$this->DisplayName?>'/></td></tr>
  3586. <tr><td><?=$this->T('电子邮件')?></td>
  3587. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  3588. value='<?=$this->EMail?>'/></td></tr>
  3589. <tr><td><?=$this->T('导航栏')?>
  3590. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  3591. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  3592. value='<?=$this->SpecialNavigation?>'/></td></tr>
  3593. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  3594. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  3595. value='<?=$this->SpecialFooter?>'/></td></tr>
  3596. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  3597. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  3598. value='<?=$this->SpecialFooter2?>'/></td></tr>
  3599. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  3600. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  3601. value='<?=$this->SpecialPinned?>'/></td></tr>
  3602. <tr><td><?=$this->T('默认相册')?></td>
  3603. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  3604. value='<?=$this->DefaultGallery?>'/></td></tr>
  3605. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  3606. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  3607. value='<?=$this->SelfAuthPath?>'/></td></tr>
  3608. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  3609. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  3610. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  3611. <tr><td class='smaller gray'>&nbsp;</td></tr>
  3612. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  3613. <tr><td><?=$this->T('主机')?><?=isset($this->ExpHost)?"<a href='?post=".$this->ExpHost."'>→</a>":""?></td>
  3614. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  3615. value='<?=$this->ExpHost?>'/></td></tr>
  3616. <tr><td><?=$this->T('网站标题')?></td>
  3617. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  3618. value='<?=$this->ExpTitle?>'/></td></tr>
  3619. <tr><td><?=$this->T('短标题')?></td>
  3620. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  3621. value='<?=$this->ExpShortTitle?>'/></td></tr>
  3622. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  3623. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  3624. value='<?=$this->ExpCaution?>'/></td></tr>
  3625. <tr><td><?=$this->T('索引')?><?=isset($this->ExpIndex)?"<a href='?post=".$this->ExpIndex."'>→</a>":""?></td>
  3626. <td><input type="text" form="settings_form" id='settings_exp_index' name='settings_exp_index'
  3627. value='<?=$this->ExpIndex?>'/></td></tr>
  3628. <tr><td><?=$this->T('导航栏')?>
  3629. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  3630. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  3631. value='<?=$this->ExpNavigation?>'/></td></tr>
  3632. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  3633. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  3634. value='<?=$this->ExpFooter?>'/></td></tr>
  3635. <tr><td class='smaller gray'>&nbsp;</td></tr>
  3636. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  3637. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  3638. <tr><td><?=$this->T('帐号')?></td>
  3639. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  3640. value='<?=$this->Admin?>'/></td></tr>
  3641. <tr><td><?=$this->T('新密码')?></td>
  3642. <td><input type="password" form="settings_form"
  3643. id='settings_new_password' name='settings_new_password' /></td></tr>
  3644. <tr><td><?=$this->T('再次输入')?></td>
  3645. <td><input type="password" form="settings_form"
  3646. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  3647. <tr><td><?=$this->T('旧密码')?></td>
  3648. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  3649. <?php }else{ ?>
  3650. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  3651. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  3652. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  3653. <tr><td><?=$this->T('帐号')?></td>
  3654. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  3655. <tr><td><?=$this->T('密码')?></td>
  3656. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  3657. <?php } ?>
  3658. </table>
  3659. <?php if($this->LoggedIn){ ?>
  3660. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  3661. <?php }else{ ?>
  3662. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  3663. <?php } ?>
  3664. </div>
  3665. <?php
  3666. }
  3667. function MakeExtraOperations(){?>
  3668. <div class='settings' style='overflow:auto;'>
  3669. <h2><?=$this->T('附加操作')?></h2>
  3670. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  3671. <p>&nbsp;</p>
  3672. <h3><?=$this->T('自动重定向')?></h3>
  3673. <span class='smaller gray'>
  3674. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  3675. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  3676. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  3677. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  3678. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  3679. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  3680. value='<?=$this->T('保存重定向设置')?>' />
  3681. <p>&nbsp;</p>
  3682. <h3><?=$this->T('自定义翻译')?></h3>
  3683. <span class='smaller gray'>
  3684. <?=$this->T('填写格式:')?>
  3685. <br /><pre>- 语言 | Language</pre></span>
  3686. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  3687. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  3688. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  3689. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  3690. value='<?=$this->T('保存翻译')?>' />
  3691. <p>&nbsp;</p>
  3692. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  3693. <ul>
  3694. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  3695. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  3696. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  3697. </ui>
  3698. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  3699. </div>
  3700. <?php
  3701. }
  3702. function MakeMainBegin(){?>
  3703. <div class='main' <?php if(!$this->InExperimentalMode){ ?>
  3704. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  3705. <?php
  3706. }
  3707. function MakeMainEnd(){?>
  3708. </div>
  3709. <?php
  3710. }
  3711. function MakeExpFooter(){?>
  3712. <div class='small_footer'>
  3713. <hr />
  3714. <b><?=$this->T($this->ExpTitle)?></b>&nbsp;©<?=$this->T($this->DisplayName)?>
  3715. </div>
  3716. <div class='footer'>
  3717. <div style='white-space:nowrap;'>
  3718. <div class='footer_additional'>
  3719. <?php if(isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  3720. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false));
  3721. } ?>
  3722. </div>
  3723. </div>
  3724. </div>
  3725. </div><!-- page -->
  3726. </body>
  3727. </html>
  3728. <script>
  3729. if(trans = document.getElementById('translate_button')){
  3730. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  3731. }
  3732. </script>
  3733. <?php
  3734. }
  3735. function MakeImageOverlay($side_info=null,$static_image=null){
  3736. $static=isset($side_info); ?>
  3737. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  3738. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  3739. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  3740. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/>
  3741. </div>
  3742. <div class='big_side_box' onclick='HideBigImage(1);'>
  3743. <?php if(!$static){ ?>
  3744. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  3745. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  3746. <div class='lr_buttons'>←</div></a></div>
  3747. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  3748. <div class='lr_buttons'>→</div></a></div>
  3749. </div><?php } ?>
  3750. <div class='side_box_mobile_inner'>
  3751. <?php if(!$static){ ?>
  3752. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  3753. <span style='display:none;' id='image_purchase' class='clean_a'>
  3754. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  3755. <br class='hidden_on_desktop block_on_mobile' /></span>
  3756. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  3757. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  3758. &nbsp;<a class='clean_a' id='image_inquiry'>
  3759. <b>@</b><?=$this->T('咨询')?></a>
  3760. <?php } ?><hr class='hidden_on_desktop block_on_mobile' />
  3761. </div>
  3762. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  3763. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  3764. <hr />
  3765. </div><?php } //static ?>
  3766. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  3767. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  3768. <br /><?=$this->T('印刷品链接')?>
  3769. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  3770. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  3771. <?=$this->T('重命名')?>
  3772. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  3773. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  3774. <br /><br /><?=$this->T('替换图像')?>
  3775. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  3776. <input type="file" form='image_edit_form'
  3777. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  3778. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  3779. value=<?=$this->T('执行')?> />
  3780. </div><?php } ?>
  3781. </div>
  3782. </div>
  3783. </div>
  3784. <?php }
  3785. function MakePageEnd(){?>
  3786. </div><!-- page -->
  3787. </body>
  3788. </html>
  3789. <?php }
  3790. function MakeFooter(){?>
  3791. <div class='small_footer'><div>
  3792. <hr />
  3793. <b><?=$this->T($this->Title)?></b>
  3794. <span onclick='event.stopPropagation()'
  3795. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  3796. <div class='wayback_link clean_a invert_a hidden_on_print'><?php if(!isset($this->WayBack)){ ?>
  3797. - <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  3798. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?>
  3799. <br class='hidden_on_desktop' /> - <a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  3800. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a>
  3801. </div>
  3802. </div></div>
  3803. <div class='footer'>
  3804. <div style='white-space:nowrap;'>
  3805. <div class='footer_additional'>
  3806. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  3807. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false));
  3808. } ?>
  3809. </div>
  3810. <div class='footer_additional'>
  3811. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  3812. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false));
  3813. } ?>
  3814. </div>
  3815. </div>
  3816. </div>
  3817. <p>&nbsp;<p>
  3818. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  3819. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  3820. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  3821. </div>
  3822. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  3823. <script>
  3824. <?=$this->ExtraScripts?>
  3825. if(back = document.getElementById('button_back')){
  3826. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  3827. back.href='javascript:history.back()';
  3828. }else{
  3829. back.href='index.php';
  3830. }
  3831. }
  3832. function copy_text(t) {
  3833. ta = document.createElement('textarea');
  3834. document.body.appendChild(ta);
  3835. ta.value = t;
  3836. ta.select();
  3837. document.execCommand("copy");
  3838. document.body.removeChild(ta);
  3839. }
  3840. if(trans = document.getElementById('translate_button')){
  3841. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  3842. }
  3843. <?php if($this->LoggedIn){ ?>
  3844. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  3845. var Scenter = document.querySelector('#div_center');
  3846. var Sposts = Scenter.querySelectorAll('.post');
  3847. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  3848. var Smerge_post = Scenter.querySelector('#merge_post');
  3849. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  3850. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  3851. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  3852. var Smerge_select = Scenter.querySelector('#merge_select');
  3853. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  3854. var Smerge_thread = Scenter.querySelector('#merge_thread');
  3855. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  3856. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  3857. var select_mode = false; var merge_mode = false; var selected_posts = null;
  3858. function TogglePostSelectMode(force_on=false,force_off=false){
  3859. Scenter.classList.add('post_selecting');
  3860. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  3861. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  3862. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  3863. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  3864. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  3865. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  3866. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  3867. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  3868. Smerge_post_count.innerText="0";
  3869. Smerge_post.href="#";
  3870. }
  3871. function TogglePostSelect(elem){
  3872. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  3873. else{ elem.classList.add('post_selected'); }
  3874. selected_posts = new Array();
  3875. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  3876. selected_posts.push(Sposts[i].dataset.postId); } }
  3877. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  3878. Smerge_post_count.innerText=selected_posts.length;
  3879. }
  3880. function ThreadMergeInput(elem){
  3881. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  3882. else{ Smerge_thread.href="#"; }
  3883. }
  3884. function ToggleThreadMerge(force_on=false,force_off=false){
  3885. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  3886. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  3887. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  3888. else{ merge_mode = 0;
  3889. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  3890. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  3891. Smerge_thread.href="#";
  3892. Smerge_thread_target.value='';
  3893. }
  3894. <?php } ?>
  3895. function ShowSideUploader(){
  3896. ShowRightSide(true,null);
  3897. put = document.querySelector("#_uploader");
  3898. put.style.display='block';
  3899. RefreshSideGallery();
  3900. }
  3901. dmark = document.querySelector("#mark_details");
  3902. drename = document.querySelector("#rename_details");
  3903. drename_form = document.querySelector("#post_rename_form");
  3904. drename_input = document.querySelector("#post_rename_name");
  3905. var rp = document.querySelector('#post_reply_to');
  3906. var _reply_to = rp?rp.defaultValue:"";
  3907. function RestoreReply(){
  3908. if(rp){
  3909. rp.defaultValue = _reply_to;
  3910. }
  3911. document.querySelector('#post_reply_restore').style.display='none';
  3912. ht = document.querySelector('#post_hint_text');
  3913. if (_reply_to!=""){
  3914. ht.style.display='block';
  3915. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  3916. }else{
  3917. ht.style.display='none';
  3918. }
  3919. document.querySelector('#post_edit_target').value="";
  3920. ch = document.querySelector('#post_hint_modify');
  3921. ch.style.display='none';
  3922. }
  3923. function MakeRefer(id){
  3924. t = document.querySelector('#post_content')
  3925. t.focus();
  3926. v = t.value;
  3927. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  3928. la_auto_grow(t);
  3929. if(rp){
  3930. rp.defaultValue = "";
  3931. ht = document.querySelector('#post_hint_text');
  3932. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  3933. document.querySelector('#post_reply_restore').style.display='inline';
  3934. rs = document.querySelector('#post_reply_restore');
  3935. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  3936. document.getElementById('post_menu').style.display='none';
  3937. ch = document.querySelector('#post_hint_modify');
  3938. ch.style.display='none';
  3939. }
  3940. }
  3941. function CopyRefer(id){
  3942. copy_text(id.toString());
  3943. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  3944. }
  3945. function MakeEdit(id){
  3946. ed = document.getElementById('menu_edit');
  3947. ed.innerHTML="<?=$this->T('稍等')?>";
  3948. ed.href="#";
  3949. var xhr = new XMLHttpRequest();
  3950. xhr.onreadystatechange = function() {
  3951. if (this.readyState == 4 && this.status == 200) {
  3952. ed.innerHTML='——';
  3953. ch = document.querySelector('#post_hint_modify');
  3954. ch.style.display='block';
  3955. ht = document.querySelector('#post_hint_text');
  3956. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  3957. rs = document.querySelector('#post_reply_restore');
  3958. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  3959. t = document.querySelector('#post_content');
  3960. t.value=xhr.responseText.trim();
  3961. t.focus();
  3962. la_auto_grow(t);
  3963. document.querySelector('#post_edit_target').value=id;
  3964. document.getElementById('post_menu').style.display='none';
  3965. }
  3966. };
  3967. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  3968. xhr.send();
  3969. }
  3970. function MarkDelete(id){
  3971. p = document.querySelector('[data-post-id="'+id+'"]');
  3972. op = p.dataset.markDelete?"false":"true";
  3973. window.location.href=
  3974. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  3975. }
  3976. function SetMark(mark){
  3977. menu = document.getElementById('post_menu');
  3978. window.location.href=
  3979. "index.php?<?=$this->GetRedirect()?>&target="+
  3980. menu.parentNode.dataset.postId+"&set_mark="+mark;
  3981. }
  3982. function ToggleMarkDetails(){
  3983. if(dmark.style.display=='block') dmark.style.display='none';
  3984. else dmark.style.display='block';
  3985. }
  3986. function ToggleRenameDetails(){
  3987. if(drename.style.display=='block') drename.style.display='none';
  3988. else drename.style.display='block';
  3989. }
  3990. <?php } ?>
  3991. function ShowPostMenu(post){
  3992. menu = document.getElementById('post_menu');
  3993. menu.style.display='block';
  3994. menu.parentNode.removeChild(menu);
  3995. post.appendChild(menu);
  3996. menu.style.display='block';
  3997. id = post.dataset.postId
  3998. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  3999. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4000. window.onClick="HidePopMenu()";
  4001. menu.onClick=(function(event){
  4002. event.stopPropagation();
  4003. });
  4004. hs = menu.querySelector('#menu_history');
  4005. hs.href='?post='+id+'&history=1';
  4006. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4007. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4008. ref = menu.querySelector('#menu_refer_copy')
  4009. ref.innerHTML='<?=$this->T("复制编号")?>';
  4010. ref.href='javascript:CopyRefer(id)';
  4011. ed = menu.querySelector('#menu_edit')
  4012. ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4013. d = menu.querySelector('#menu_delete');
  4014. d.href='javascript:MarkDelete(\"'+id+'\")';
  4015. p = document.querySelector('[data-post-id="'+id+'"]');
  4016. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4017. menu.querySelector('#mark_details').dataset.id=id;
  4018. drename_input.value=id;
  4019. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4020. <?php } ?>
  4021. title = document.title;
  4022. copy = document.getElementById('share_copy');
  4023. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4024. copy.addEventListener("click", function(){
  4025. url = window.location
  4026. path = location.pathname
  4027. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4028. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4029. });
  4030. }
  4031. function HidePopMenu(){
  4032. var menus = document.querySelectorAll('.pop_menu');
  4033. [].forEach.call(menus, function(m){m.style.display='none';});
  4034. }
  4035. var posts = document.querySelectorAll('.center .post');
  4036. [].forEach.call(posts, function(p){
  4037. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4038. ShowPostMenu(this.parentNode.parentNode);
  4039. });
  4040. });
  4041. var post_clickables = document.querySelectorAll('.center .post a');
  4042. [].forEach.call(post_clickables, function(p){
  4043. p.addEventListener("click", function(event){
  4044. event.stopPropagation();
  4045. });
  4046. });
  4047. function FindImage(imgsrc){
  4048. for(var i=0;i<document.images_filtered.length;i++){
  4049. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4050. }
  4051. return null
  4052. }
  4053. var dottime1;
  4054. var dottime2;
  4055. function ToDataURL(url) {
  4056. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4057. clearTimeout(dottime1);clearTimeout(dottime2);
  4058. ps = document.querySelector('#download_processing');
  4059. ps.innerHTML='↓';ps.style.opacity='';
  4060. return URL.createObjectURL(blob);});
  4061. }
  4062. async function DownloadAsImage(url,name) {
  4063. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4064. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4065. }
  4066. function basename(url){return url.split(/[\\/]/).pop();}
  4067. pushed=0;
  4068. function ShowBigImage(imgsrc,do_push){
  4069. ShowWaitingBar();
  4070. share = document.querySelector('#big_image_share');
  4071. img = document.querySelector('#big_image');
  4072. down = document.querySelector('#image_download');
  4073. img.src = "";
  4074. img.src = src = "images/"+imgsrc;
  4075. down.href="images/"+imgsrc;
  4076. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_+<?=$this->GiveSafeEMail()?>+_'+
  4077. basename(down.href);
  4078. img.alt = downname; down.download=downname;
  4079. var use_href = "images/"+imgsrc;
  4080. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4081. ps = this.querySelector('#download_processing');ps.innerText='…';
  4082. var dotwait = function(ps){ var self = this;
  4083. dottime1 = setTimeout(function(ps){
  4084. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4085. dotwait(this.querySelector('#download_processing'));
  4086. DownloadAsImage(use_href,downname);};
  4087. if(do_push){PushGalleryHistory(src)}
  4088. page_url = encodeURIComponent(window.location.href);
  4089. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4090. inqb = document.querySelector('#image_inquiry');
  4091. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4092. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4093. (page_url)+encodeURIComponent('\n\n');
  4094. <?php } ?>
  4095. this_image = FindImage(imgsrc);
  4096. if(this_image.dataset.prevsrc){
  4097. new_image = FindImage(this_image.dataset.prevsrc);
  4098. new_prev = new_image?new_image.dataset.prevsrc:null;
  4099. im = document.querySelector('#prev_image');
  4100. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4101. else {im.style.opacity='0';im.removeAttribute("href");}
  4102. }
  4103. if(this_image.dataset.nextsrc){
  4104. new_image = FindImage(this_image.dataset.nextsrc);
  4105. new_next = new_image?new_image.dataset.nextsrc:null;
  4106. im = document.querySelector('#next_image');
  4107. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4108. else {im.style.opacity='0';im.removeAttribute("href");}
  4109. }
  4110. purchase = document.querySelector('#image_purchase');
  4111. purchase_btn = document.querySelector('#image_purchase_button');
  4112. <?php if($this->LoggedIn){ ?>
  4113. product_link = document.querySelector('#image_ops_product_link');
  4114. product_form = document.querySelector('#image_ops_form');
  4115. edit_form = document.querySelector('#image_edit_form');
  4116. edit_new_name = document.querySelector('#image_edit_new_name');
  4117. product_form.action = window.location.href;
  4118. edit_form.action = window.location.href;
  4119. edit_new_name.value = imgsrc.split('.')[0];
  4120. if(this_image.dataset.product){
  4121. product_link.value = this_image.dataset.product;
  4122. }else{
  4123. product_link.value = "";
  4124. }
  4125. <?php } ?>
  4126. if(this_image.dataset.product){
  4127. purchase.style.display='';
  4128. href = this_image.dataset.product;
  4129. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4130. href = '?post='+href;
  4131. }
  4132. purchase_btn.href = href;
  4133. }else{
  4134. purchase.style.display='none';
  4135. purchase_btn.removeAttribute("href");
  4136. }
  4137. DelayHideImgBtn(null);
  4138. title = encodeURIComponent(document.title);
  4139. copy = document.getElementById('big_share_copy');
  4140. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4141. copy.addEventListener("click", function(){
  4142. copy_text(window.location.href);
  4143. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4144. });
  4145. o = document.querySelector('#big_image_overlay');
  4146. info = document.querySelector('#big_image_info');
  4147. info.innerHTML="<?=$this->T('正在查询……')?>";
  4148. o.style.display="block";
  4149. ShowBackdrop(0.8);
  4150. var xhr = new XMLHttpRequest();
  4151. xhr.onreadystatechange = function() {
  4152. if (this.readyState == 4 && this.status == 200) {
  4153. info = document.querySelector('#big_image_info');
  4154. var response = xhr.responseText;
  4155. let content=""
  4156. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4157. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4158. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4159. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4160. content+="<div class='clean_a'>"+res[1]+"</div>";
  4161. }
  4162. info.innerHTML=content;
  4163. }
  4164. };
  4165. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4166. xhr.send();
  4167. }
  4168. function HideBigImage(do_push){
  4169. o = document.querySelector('#big_image_overlay');
  4170. img = document.querySelector('#big_image');
  4171. img.src = "";
  4172. if(o.style.display!='none'){
  4173. o.style.display="none";
  4174. HideBackdrop();
  4175. if(do_push){PushGalleryHistory("");}
  4176. HideWaitingBar();
  4177. }
  4178. }
  4179. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4180. var inq=document.querySelector('#inquiry_buttons');
  4181. var overlay=document.querySelector('#big_image_overlay');
  4182. var hide_timeout;
  4183. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4184. function DelayHideImgBtn(e){
  4185. lbtn.classList.remove('img_btn_hidden');
  4186. rbtn.classList.remove('img_btn_hidden');
  4187. inq.classList.remove('img_btn_hidden');
  4188. clearTimeout(hide_timeout);
  4189. hide_timeout = setTimeout(function(e1,e2,e3){e1.classList.add('img_btn_hidden');
  4190. e2.classList.add('img_btn_hidden');
  4191. e3.classList.add('img_btn_hidden');}, 1000, lbtn, rbtn, inq);
  4192. }
  4193. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4194. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4195. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4196. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4197. var images = document.querySelectorAll('img');
  4198. var images_filtered=new Array(); var imgadded = new Array();
  4199. var images_remaining=new Array();
  4200. [].forEach.call(images, function(img){
  4201. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4202. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4203. images_filtered.push(img);imgadded.push(imgsrc);
  4204. });
  4205. for(var i=0; i<images_filtered.length; i++){
  4206. previmg = nextimg = null; img = images_filtered[i];
  4207. if(i>0) previmg=images_filtered[i-1];
  4208. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4209. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4210. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4211. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4212. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4213. }
  4214. for(var i=0; i<images_remaining.length; i++){
  4215. img = images_remaining[i];
  4216. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4217. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4218. }
  4219. document.images_filtered = images_filtered;
  4220. function PopGalleryHistory(){
  4221. if(pushed){
  4222. pushed = 0;
  4223. try{
  4224. history.back();
  4225. }catch{
  4226. console.log("can't do it.");
  4227. }
  4228. }
  4229. }
  4230. function PushGalleryHistory(src){
  4231. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  4232. title = "照片"
  4233. extra = "?";
  4234. sp = new URLSearchParams(window.location.search)
  4235. if(sp.has('post')){extra+="post="+sp.get('post')}
  4236. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  4237. try{
  4238. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  4239. }catch{
  4240. console.log("can't do it.");
  4241. }
  4242. pushed = 1;
  4243. }
  4244. document.addEventListener('keydown', function(e){
  4245. large = document.getElementById('big_image_overlay')
  4246. if (large.style.display!='block') return;
  4247. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  4248. HideBigImage(1);
  4249. }
  4250. }, true);
  4251. window.addEventListener('popstate', (event) => {
  4252. if(event.state){
  4253. let sp = new URLSearchParams(event.state)
  4254. if(sp.has('pic')){
  4255. src = sp.get('pic')
  4256. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)) ShowBigImage(onlyimg[0], 0);
  4257. else{HideBigImage(0);}
  4258. }
  4259. }else{HideBigImage(0);}
  4260. });
  4261. let searchParams = new URLSearchParams(window.location.search)
  4262. if(searchParams.has('pic')){
  4263. src = searchParams.get('pic')
  4264. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)){
  4265. ShowBigImage(onlyimg[0], 1);
  4266. }
  4267. }
  4268. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  4269. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  4270. </script>
  4271. </body>
  4272. <?php
  4273. }
  4274. function DoIdentiyExperimental(){
  4275. if(!isset($this->ExpHost) || $this->ExpHost=="") return;
  4276. if(preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  4277. $this->InExperimentalMode=True;
  4278. }
  4279. if(!$this->CurrentPostID && $this->InExperimentalMode){
  4280. $this->CurrentPostID = $this->ExpIndex;
  4281. }
  4282. }
  4283. function DoExperimentalTopLink($p){
  4284. if($this->InExperimentalMode && $p){
  4285. if(isset($p['tid']) && $p['tid']['first']!=$p){
  4286. header('Location: ?post='.$p['tid']['first']['id']); exit();
  4287. }
  4288. }
  4289. }
  4290. function MakeExperimentalConfirm(){
  4291. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  4292. return false;
  4293. }
  4294. $caution_html =
  4295. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  4296. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  4297. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  4298. ?>
  4299. <div class='center_exp'><?php
  4300. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  4301. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  4302. ?></div>
  4303. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  4304. <?php return true;
  4305. }
  4306. }
  4307. $la = new LA;
  4308. $la->DoSiteRedirect();
  4309. $la->DoLogin();
  4310. $err = $la->ProcessRequest($message, $redirect);
  4311. $la->WriteAsNecessary();
  4312. $la->DoIdentiyExperimental();
  4313. $la->SwitchLanguageAndFont();
  4314. $la->SwitchWayBackMode();
  4315. if($err){
  4316. echo $message;
  4317. exit();
  4318. }
  4319. if(isset($redirect)){
  4320. header('Location: '.$redirect);
  4321. exit();
  4322. }
  4323. $la->DetectPageType();
  4324. $la->ReadImages(false);
  4325. $la->ReadPosts();
  4326. if(isset($la->WayBack)){
  4327. $la->ReadArchive();
  4328. }
  4329. $p = &$la->GetPost($la->CurrentPostID);
  4330. if(!isset($p)){
  4331. $p = &$la->GetMergedPost($la->CurrentPostID);
  4332. }
  4333. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  4334. else{ $la->DoExperimentalTopLink($p); }
  4335. if(isset($p)){ $la->ActualPostID = $p['id']; }
  4336. $la->MakeHeader($p);
  4337. $la->MakeMainBegin();
  4338. if($la->PageType=='experimental'){
  4339. if(!$la->MakeExperimentalConfirm()){
  4340. if($p){
  4341. $la->MakePostSectionExp($p);
  4342. $la->MakeLinkedPostsExp($p);
  4343. }else{
  4344. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4345. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4346. }
  4347. }
  4348. $la->MakeMainEnd();
  4349. $la->MakeExpFooter();
  4350. }else{
  4351. if($la->PageType=='extras'){
  4352. $la->MakeExtraOperations();
  4353. }else if($la->PageType=='settings'){
  4354. $la->MakeSettings();
  4355. }else if($la->PageType=='gallery'){
  4356. $la->MakeGalleryLeft();
  4357. $la->MakeGallerySection();
  4358. }else if($la->PageType=='post'){
  4359. if($p){
  4360. $made_interesting = false;
  4361. if($la->IsInterestingPost($p)){
  4362. $la->MakeInterestingSection($p['tid']);
  4363. }
  4364. else{
  4365. $la->MakeLinkedPosts($p);
  4366. $la->MakePostSection($p);
  4367. $la->MakeTOC();
  4368. }
  4369. }else{
  4370. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4371. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4372. }
  4373. }else if($la->PageType=='history'){
  4374. $la->ReadArchive();
  4375. $la->MakePostHistory($p, $_GET['version']??NULL);
  4376. }else if($la->PageType=='search'){
  4377. $la->MakeHotPosts(true);
  4378. $la->MakeRecentPosts($_GET['search']);
  4379. }else if($la->PageType=='category'){
  4380. $la->MakeHotPosts(true);
  4381. $la->MakeRecentPosts(NULL,$_GET['category']);
  4382. }else if($la->PageType=='comments'){
  4383. $la->MakeCommentPosts();
  4384. }else{
  4385. $la->MakeHotPosts();
  4386. $la->MakeRecentPosts();
  4387. }
  4388. $la->MakeMainEnd();
  4389. $la->MakeFooter();
  4390. }
  4391. ?>