*/}}

index.php 204 KB

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