*/}}

index.php 182 KB

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