*/}}

index.php 219 KB

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