*/}}

index.php 228 KB

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