*/}}

index.php 244 KB

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