*/}}

index.php 245 KB

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