*/}}

index.php 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441
  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 $SpecialNavigation;
  17. protected $SpecialFooter;
  18. protected $SpecialFooter2;
  19. protected $SpecialPinned;
  20. protected $DefaultGallery;
  21. protected $Redirect;
  22. protected $Translations;
  23. protected $CustomTranslationContent;
  24. protected $CurrentOffset;
  25. protected $PostsPerPage;
  26. protected $HotPostCount;
  27. protected $LoggedIn;
  28. protected $LanguageAppendix;
  29. protected $Posts;
  30. protected $Threads; // [ keys: first last displayed count]
  31. protected $Images;
  32. protected $Galleries;
  33. protected $Anchors;
  34. protected $Markers;
  35. protected $ExtraScripts;
  36. protected $NULL_POST;
  37. protected $NULL_IMAGE;
  38. protected $NULL_Gallery;
  39. public $PageType;
  40. public $CurrentPostID;
  41. function T($str){
  42. if(!$this->LanguageAppendix) return $zh;
  43. foreach($this->Translations as $entry){
  44. if($entry['zh']==$str)
  45. return $entry[$this->LanguageAppendix];
  46. }
  47. return $str;
  48. }
  49. function SwitchLanguage(){
  50. if(isset($_COOKIE['la_language'])){
  51. $this->LanguageAppendix = $_COOKIE['la_language'];
  52. }else{
  53. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  54. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  55. $lang = substr($lang,0,5);
  56. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  57. else $this->LanguageAppendix = 'en';
  58. }
  59. }
  60. }
  61. function DisplayRedirectConfig(){
  62. $s = "";
  63. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  64. if($r['for']=='P'){
  65. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  66. }else if($r['for']=='S'){
  67. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  68. }
  69. }
  70. return $s;
  71. }
  72. function DoSiteRedirect(){
  73. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  74. if($r['for']=='S'){
  75. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  76. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  77. }
  78. }
  79. }
  80. }
  81. function WriteHTACCESS(){
  82. $conf = fopen('.htaccess','w');
  83. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  84. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  85. if($r['for']=='P'){
  86. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  87. }// do site redirect in php.
  88. }
  89. fflush($conf);fclose($conf);
  90. }
  91. function BuildRedirectConfig($conf){
  92. $this->Redirect=[];
  93. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  94. foreach($ma as $m){
  95. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  96. $this->Redirect[]=$redirect;
  97. }
  98. }
  99. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  100. foreach($ma as $m){
  101. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  102. $this->Redirect[]=$redirect;
  103. }
  104. }
  105. }
  106. function WriteConfig(){
  107. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  108. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  109. if(!isset($this->Admin)) $this->Admin = 'admin';
  110. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  111. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  112. $conf = fopen('la_config.md','w');
  113. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  114. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  115. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  116. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  117. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  118. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  119. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  120. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  121. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  122. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  123. fflush($conf);fclose($conf);
  124. $conf = fopen('la_redirect.md','w');
  125. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  126. $this->WriteHTACCESS();
  127. }
  128. function Install(){
  129. if(!file_exists('la_config.md')){
  130. $this->WriteConfig();
  131. }
  132. if(!is_dir('posts')) mkdir('posts');
  133. if(!is_dir('images')) mkdir('images');
  134. if(!is_dir('images/thumb')) mkdir('images/thumb');
  135. if(!is_dir('styles')) mkdir('styles');
  136. $this->WriteStyles();
  137. }
  138. function ReadConfig(){
  139. if(!file_exists('la_config.md')){
  140. $this->Install();
  141. }
  142. $c = file_get_contents('la_config.md');
  143. if(preg_match('/-\s*Title\s*=\s*(\S+)\s*$/um', $c, $m)) $this->Title = $m[1]; else $this->Title=$this->T("那么的维基");
  144. if(preg_match('/-\s*ShortTitle\s*=\s*(\S+)\s*$/um', $c, $m)) $this->ShortTitle = $m[1]; else $this->Title=$this->T("基");
  145. if(preg_match('/-\s*Admin\s*=\s*(\S+)\s*$/um', $c, $m)) $this->Admin = $m[1];
  146. if(preg_match('/-\s*Password\s*=\s*(\S+)\s*$/um', $c, $m)) $this->Password = $m[1];
  147. if(preg_match('/-\s*DisplayName\s*=\s*(\S+)\s*$/um', $c, $m)) $this->DisplayName = $m[1];
  148. if(preg_match('/-\s*SpecialNavigation\s*=\s*(\S+)\s*$/um', $c, $m)) $this->SpecialNavigation = $m[1];
  149. if(preg_match('/-\s*SpecialFooter\s*=\s*(\S+)\s*$/um', $c, $m)) $this->SpecialFooter = $m[1];
  150. if(preg_match('/-\s*SpecialFooter2\s*=\s*(\S+)\s*$/um', $c, $m)) $this->SpecialFooter2 = $m[1];
  151. if(preg_match('/-\s*SpecialPinned\s*=\s*(\S+)\s*$/um', $c, $m)) $this->SpecialPinned = $m[1];
  152. if(preg_match('/-\s*DefaultGallery\s*=\s*(\S+)\s*$/um', $c, $m)) $this->DefaultGallery = $m[1];
  153. if(file_exists('la_redirect.md')){
  154. $c = file_get_contents('la_redirect.md');
  155. $this->BuildRedirectConfig($c);
  156. }
  157. $this->Translations=[];
  158. if(file_exists("translations.md")){
  159. $c = file_get_contents('translations.md');
  160. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  161. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  162. $this->Translations[] = $entry;
  163. }
  164. }
  165. if(file_exists("custom_translations.md")){
  166. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  167. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  168. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  169. $this->Translations[] = $entry;
  170. }
  171. }
  172. }
  173. function __construct() {
  174. $this->ReadConfig();
  175. $this->PDE = new ParsedownExtra();
  176. $this->PDE->SetInterlinkPath('/');
  177. $this->Posts = [];
  178. $this->Threads = [];
  179. $this->Markers=['●', '○', '✓', '×', '!'];
  180. $this->PostsPerPage = 40;
  181. $this->HotPostCount = 15;
  182. }
  183. function DoLogout(){
  184. $this->LoggedIn = false;
  185. unset($_SESSION['user_id']); unset($_SESSION['la_theme']);
  186. }
  187. function DoLogin(){
  188. session_start();
  189. $redirect=false;
  190. if(isset($_GET['logout'])){ $this->DoLogout(); }
  191. else if(!isset($_SESSION['user_id'])){
  192. if(isset($_POST['login_button'])){
  193. $id = trim($_POST['login_id']);
  194. $pwd = trim($_POST['login_password']);
  195. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  196. $_SESSION['user_id']=$id;
  197. }
  198. $redirect = true;
  199. }
  200. }else{
  201. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  202. else{ $this->DoLogout();}
  203. }
  204. if($redirect){
  205. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  206. .(isset($_GET['settings'])?"?settings=true":""));
  207. }
  208. }
  209. function WriteStyles(){
  210. $this->style="
  211. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun',Georgia,serif;}
  212. body{background-color:%white%;color:%black%;}
  213. sup,sub{line-height:0;}
  214. *{box-sizing:border-box;padding:0;margin:0;}
  215. .page,.page_gallery{padding:1em;padding-top:0;}
  216. .hidden_on_desktop, .hidden_on_wide{display:none;}
  217. ::file-selector-button{background:none;border:none;}
  218. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  219. a:hover,button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  220. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:1em;}
  221. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  222. header a:hover,.button:hover{color:%gray% !important;}
  223. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  224. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  225. .gray{color:%gray%;}
  226. hr{border:1px solid %gray%;}
  227. p{margin:0;margin-bottom:0.5em;}
  228. p:last-child{margin-bottom:0;}
  229. header ul{display:inline-block;}
  230. header li{display:inline-block;}
  231. header li::before{content:' - '}
  232. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  233. .main{position:relative;word-spacing:-1em;}
  234. .main div{word-spacing:initial;}
  235. pre{overflow:auto;}
  236. ul{display:block;}
  237. li{display:block;}
  238. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:2px solid %black%;}
  239. table input{border:none!important;}
  240. td{padding-left:0.1em;padding-right:0.1em;}
  241. td:first-child{padding-left:0;}
  242. td:last-child{padding-right:0;}
  243. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  244. thead{border-bottom:1px solid %black%;}
  245. .left{display:inline-block;vertical-align:top;width:25%;height:calc(100vh - 5.2em);
  246. position:sticky;top:2.5em;overflow:auto;padding-right:0.2em;padding-bottom:5rem;}
  247. .center{display:inline-block;vertical-align:top;width:50%;padding-left:0.3em;overflow:auto;padding-bottom:5rem;}
  248. .center .post:hover{background-color:%graybkg%;}
  249. .right{display:inline-block;vertical-align:top;width:25%;position:sticky;top:2.5em;padding-left:0.5em;height:calc(100vh - 2.6em);overflow:auto;padding-bottom:5rem;}
  250. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;}
  251. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  252. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  253. .post{position:relative;scroll-margin:2.5em;border-radius:0.3em;padding:0.5rem;padding-left:0rem;padding-top:0.3rem;padding-bottom:0.3rem;}
  254. .post{margin-top:0.2em;margin-bottom:0.2em;}
  255. .post_width li,.post_width_big li,.footer_additional li,.footer_additional li{display:list-item;margin-left:1em;list-style:disc;}
  256. .post_width li li,.post_width_big li li,.footer_additional li li,.footer_additional li li{list-style:circle;}
  257. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  258. .gallery_left .selected{list-style:'→';}
  259. .gallery_left ul{font-size:1.4em;}
  260. .focused_post{font-size:1.2em;margin-top:0.1em;margin-bottom:0.1em;padding:0.5rem;background-color:%focusedbkg%;}
  261. .post_width{position:relative;left:1.4rem;width:calc(100% - 1.6rem);padding-left:0.2em;}
  262. .post_width_big{position:relative;left:0;width:100%;}
  263. .post .post{padding:0;padding-top:0.3rem;}
  264. .post_menu_button{position:absolute;display:none;right:-0.2rem;width:1.5rem;
  265. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;}
  266. .pointer{cursor:pointer;}
  267. .post:hover .post_menu_button{display:block;}
  268. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%lighterbkg%;
  269. padding:0.3em;right:0.3rem;text-align:right;border-radius:0.3em;font-size:1rem;
  270. box-shadow:0px 0px 10px rgb(0, 0, 0);}
  271. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  272. .toc{left:60%;width:40%;top:0;position:absolute;}
  273. .post_access{width:1.4rem;top:0;position:absolute;height:100%;text-align:center;
  274. font-weight:bold;border-right:2px solid transparent;padding-top:0.3rem;}
  275. .post_access:hover{background-color:%lightopbkg%;border-top-left-radius:0.3em;border-bottom-left-radius:0.3em;
  276. border-right:2px solid %black%;}
  277. .opt_compact .post_access{padding-top:0.2rem;}
  278. .post_box{border:1px solid %gray%;border-radius:0.3em;padding:0.3em;}
  279. .post_box:hover,.post_menu_button:hover{background-color:%lightopbkg%}
  280. #big_image_info .post_box:hover{background-color:%graybkg%;}
  281. .post_preview{font-size:0.9rem;overflow:hidden;}
  282. .post .post_ref{font-size:0.9rem;margin:0.3em;}
  283. .post_ref .post_ref_inner{margin-left:1.2em;}
  284. .post_ref .post_ref_inner::before{content:'→';color:%gray%;margin-left:-1em;}
  285. .post_ref_main{display:inline-block;vertical-align:top;}
  286. .post_preview .post_ref_main{max-height:6rem;overflow:hidden;}
  287. .post_ref_images{overflow:hidden;}
  288. .post_ref_images img{max-height:4em !important;max-width:4em !important;}
  289. .page_selector{padding-top:2rem;text-align:center;}
  290. .focused_post .post_ref{font-size:1rem;}
  291. .smaller{font-size:0.85em;}
  292. .block{display:block;}
  293. .opt_compact{margin-left:1.9em;}
  294. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  295. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  296. .focused_post .opt_compact{font-size:0.6em !important;padding-left:0;}
  297. .spacer{height:0.5em;}
  298. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  299. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  300. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  301. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  302. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  303. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  304. .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;}
  305. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  306. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  307. .toc_entry_1{font-size:1.1em;}
  308. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  309. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  310. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  311. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  312. h1,h2,h3,h4,h5{scroll-margin:1.5em;}
  313. {display:inline}
  314. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p,
  315. .post_ref_inner p,.post_ref_inner h1,.post_ref_inner h2,.post_ref_inner h3,.post_ref_inner h4,.post_ref_inner h5
  316. {font-size:1em;display:inline-block;}
  317. .deleted_post{color:%gray%;text-decoration:line-through;}
  318. #file_list{margin-top:0.5em;}
  319. .file_thumb img{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  320. #file_list li{margin-bottom:0.3em;}
  321. .ref_thumb{white-space:nowrap;overflow:hidden;}
  322. .ref_thumb .file_thumb{width:3em;height:3em;}
  323. .side_thumb li{margin:0.2em;display:inline-block;}
  324. .file_thumb{width:4em;height:4em;display:inline-block;box-shadow:0px 0px 10px rgb(0, 0, 0);
  325. line-height:0;vertical-align:middle;overflow:hidden;}
  326. .p_row{display:flex;flex-wrap:wrap;margin-left:0.25rem;margin-top:0.25rem;}
  327. .p_thumb{display:flex;flex-grow:1;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;
  328. box-shadow:0px 0px 10px rgb(0, 0, 0);overflow:hidden;position:relative;}
  329. .p_thumb img{object-fit:cover;max-height:100%;min-width:100%;}
  330. .ref_count,.p_thumb .post_menu_button{text-shadow: 0px 0px 10px rgb(0, 0, 0);}
  331. .p_thumb:hover .post_menu_button{display:block;}
  332. .p_thumb_selected{color:%black% !important;}
  333. .p_thumb_selected{display:block;}
  334. .post .p_thumb img{max-height:8rem;}
  335. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;}
  336. .big_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;box-shadow: 0px 0px 30px black;cursor:unset;}
  337. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;
  338. background:linear-gradient(to right, rgba(0,0,0,0), rgb(1, 1, 1));transition:background-size .2s linear;background-size: 300% 100%;}
  339. .big_side_box:hover{background-size: 100% 100%;}
  340. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  341. .big_side_box a:hover{color:%gray%;}
  342. #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;
  343. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  344. img{cursor:pointer;max-height:100%;max-width:100%;}
  345. .post img{box-shadow:0px 0px 10px rgb(0, 0, 0);max-height:min(70vh, 20rem);;max-width:min(100%, 20rem);}
  346. .b ul{font-size:1.4em;}
  347. no_pop{cursor:unset;}
  348. p{min-height:0.8em;}
  349. .bold{font-weight:bold;}
  350. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  351. .small_footer{position:sticky;bottom:0em;background-color:%white%;padding-bottom:1em;}
  352. .top_post_hint{margin-left:1.5em;font-weight:bold;}
  353. .white{color:%white%;}
  354. .full_box{border:1px solid %black%;padding:0.3rem;overflow:auto;}
  355. @media screen and (max-width:1000px){
  356. .left{width:35%;}
  357. .center{width:65%;}
  358. .right{display:none;}
  359. .post_width{left:1.5em;width:calc(100% - 1.7rem);padding-left:0.2em;}
  360. .post_width_big{left:0;width:100%;}
  361. .hidden_on_wide{display:unset;}
  362. .hidden_on_narrow{display:none;}
  363. .pop_right{width:30%;}
  364. .pop_right_big{width:40%;}
  365. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  366. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  367. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  368. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  369. .big_side_box{width:35%;}
  370. .big_image_box{width:65%;}
  371. }
  372. @media screen and (max-width:666px){
  373. .hidden_on_mobile{display:none !important;}
  374. .block_on_mobile{display:block !important;}
  375. .hidden_on_desktop{display:unset;}
  376. header ul{display:block;}
  377. header li{display:block;}
  378. header li::before{content:''}
  379. .left{position:relative;width:100%;position:relative;top:unset;height:unset;min-height:80vh;padding-right:0;display:block;}
  380. .center{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  381. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  382. .pop_right{height:30%;}
  383. .pop_right_big{height:70%;}
  384. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  385. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  386. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  387. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  388. .big_image_box{position:fixed;top:0;bottom:7.5rem;left:0;right:0;width:100%;}
  389. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  390. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  391. .side_box_mobile_inner:hover{background-size:100% 100%;}
  392. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  393. height:unset;padding:0;padding-top:calc(100vh - 7.5rem);background:none;}
  394. .p_thumb{height:3rem;}
  395. .post .p_thumb img{max-height:3rem;}
  396. .page,.page_gallery{padding:0.3em;padding-top:0;}
  397. header{padding-top:0.3em;}
  398. .small_footer{padding-bottom:0.3em;}
  399. .footer_additional{display:block;width:100%;}
  400. .album_hint{display:block;font-size:1rem;}
  401. }
  402. ";
  403. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  404. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  405. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  406. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  407. $this->style=preg_replace('/%lightopbkg%/','#daae8010',$this->style);
  408. $this->style=preg_replace('/%lighterbkg%/','#675340',$this->style);
  409. $this->style=preg_replace('/%focusedbkg%/','#482f0c',$this->style);
  410. $f = fopen('styles/main.css','w');
  411. fwrite($f,$this->style);
  412. fclose($f);
  413. }
  414. function &FindImage($name){
  415. if(isset($this->Images[0]))foreach($this->Images as &$im){
  416. if($im['name']==$name) return $im;
  417. }
  418. return $this->NULL_IMAGE;
  419. }
  420. function ReadImages($clear_non_exist = false){
  421. $path = 'images/list.md';
  422. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  423. $c = file_get_contents($path);
  424. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  425. $g=[]; $g['name']=$m[1];//$g['count']=0;
  426. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  427. $this->Galleries[] = $g;
  428. }
  429. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  430. $name = trim($m[1]);
  431. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  432. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  433. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  434. $item['refs']=[];
  435. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  436. }
  437. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  438. $item['galleries']=[];
  439. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  440. }
  441. $this->Images[] = $item;
  442. }
  443. $files = array_merge([],glob('images/*.jpg'));
  444. $files = array_merge($files,glob('images/*.jpeg'));
  445. $files = array_merge($files,glob('images/*.png'));
  446. $files = array_merge($files,glob('images/*.gif'));
  447. if(isset($files[0]))foreach($files as $file) {
  448. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png)/u', $file, $m)) {
  449. $name = trim($m[0]);
  450. if(!$this->FindImage($name)){
  451. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  452. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  453. $this->Images[] = $item;
  454. }
  455. }
  456. }
  457. if($clear_non_exist){
  458. if(isset($this->Images[0]) && isset($files[0])){
  459. foreach($this->Images as &$im){
  460. if(!in_array($im['file'],$files)){
  461. $im['deleted'] = 1;
  462. }
  463. }
  464. }
  465. }
  466. function cmpf($a, $b){
  467. if ($a['name'] == $b['name']) return 0;
  468. return (($a['name'] > $b['name']) ? 1 : -1);
  469. }
  470. function cmpaf($a, $b){
  471. if ($a['name'] == $b['name']) return 0;
  472. return ($a['name'] > $b['name']) ? -1 : 1;
  473. }
  474. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  475. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  476. }
  477. function WriteImages(){
  478. $path = 'images/list.md';
  479. $f = fopen($path,'w');
  480. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  481. if(isset($g['deleted'])) continue;
  482. fwrite($f,'GALLERY '.$g['name']);
  483. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  484. fwrite($f, PHP_EOL);
  485. }
  486. if(isset($this->Images[0]))foreach($this->Images as &$im){
  487. if(isset($im['deleted'])) continue;
  488. fwrite($f, "- ".$im['name'].'; ');
  489. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  490. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  491. fwrite($f, PHP_EOL);
  492. }
  493. fflush($f);
  494. fclose($f);
  495. }
  496. function EditImage($name, $link_gallery, $do_remove = false){
  497. if(!($im = &$this->FindImage($name))) return;
  498. if($do_remove){
  499. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  500. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  501. $im['galleries'] = array_merge($im['galleries']);
  502. }else{
  503. if(!isset($im['galleries'])) $im['galleries']=[];
  504. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  505. $im['galleries'][]=$link_gallery;
  506. }
  507. }
  508. function compressImage($source, $destination, $thumb_destination, $quality, $sizelim) {
  509. $info = getimagesize($source);
  510. if ($info['mime'] == 'image/jpeg')
  511. $image = imagecreatefromjpeg($source);
  512. else if ($info['mime'] == 'image/png')
  513. $image = imagecreatefrompng($source);
  514. else return;
  515. list($width, $height) = getimagesize($source);
  516. $newwidth = $width;
  517. $newheight = $height;
  518. $anychanged = false;
  519. if ($width > $sizelim) {
  520. $newwidth = $sizelim; $newheight = ($height / $width) * $newwidth; $anychanged = true;$width=$newwidth;$height=$newheight;
  521. }
  522. if ($height > $sizelim) {
  523. $newheight = $sizelim; $newwidth = ($width / $height) * $newheight; $anychanged = true;
  524. }
  525. $newimage=$image;
  526. if($anychanged){ $newimage = imagescale($image, $newwidth,$newheight, IMG_BICUBIC); }
  527. imagejpeg($newimage, $destination, $quality);
  528. imagedestroy($newimage);
  529. $sizelim=400; $anychanged=false;
  530. if ($width > $sizelim) {
  531. $newwidth = $sizelim; $newheight = ($height / $width) * $newwidth; $anychanged = true;$width=$newwidth;$height=$newheight;
  532. }
  533. if ($height > $sizelim) {
  534. $newheight = $sizelim; $newwidth = ($width / $height) * $newheight; $anychanged = true;
  535. }
  536. if($anychanged){ $newimage = imagescale($image, $newwidth,$newheight, IMG_BICUBIC);
  537. imagejpeg($newimage, $thumb_destination, $quality);imagedestroy($newimage); }
  538. imagedestroy($image);
  539. }
  540. function DoUpload(){
  541. if(!isset($_FILES['upload_file_name'])) return 0;
  542. if(!is_dir('images/thumb')) mkdir('images/thumb');
  543. if($_FILES['upload_file_name']['error']>0){
  544. return -1;
  545. }else{
  546. $fp = fopen('.la_lock',"w");
  547. while (!flock($fp, LOCK_EX| LOCK_NB)){
  548. usleep(10000);
  549. }
  550. $num=date('YmdHis');
  551. $base = 'images/'.$num;
  552. $thumb = 'images/thumb/'.$num;
  553. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  554. if($ext=='png') $ext='jpg';
  555. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  556. while(file_exists($final_path)){
  557. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  558. }
  559. if($ext!='gif'){
  560. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 80,
  561. (isset($_GET['compress'])&&$_GET['compress'])?800:1920);
  562. }else{
  563. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  564. }
  565. flock($fp, LOCK_UN);
  566. fclose($fp);
  567. $this->ReadImages(true);
  568. $this->WriteImages();
  569. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  570. exit;
  571. return 1;
  572. }
  573. return 0;
  574. }
  575. function &GetGallery($name){
  576. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  577. if($g['name'] == $name) return $g;
  578. }
  579. return $this->NULL_GALLERY;
  580. }
  581. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null){
  582. if($do_rw) $this->ReadImages();
  583. $gallery = &$this->GetGallery($name);
  584. if(!isset($gallery)){
  585. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  586. $g = []; $g['name']=$new_name;
  587. $this->Galleries[]=$g;
  588. }else{
  589. if(isset($new_name)) {
  590. if(preg_match('/main|trash|\s/u',$new_name))return;
  591. $gallery['name'] = $new_name;
  592. foreach ($this->Images as &$im){
  593. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  594. if($g == $name){ $g = $new_name; }
  595. }
  596. }
  597. }
  598. //if(isset($count)) $gallery['count'] = $count;
  599. if(isset($delete) && $delete) $gallery['deleted'] = true;
  600. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  601. }
  602. if($do_rw) { $this->WriteImages(); $this->ClearData(); }
  603. }
  604. function ClearData(){
  605. $this->Posts = [];
  606. $this->Threads = [];
  607. $this->Images = [];
  608. }
  609. function ReadPostsFromFile($path){
  610. if(!file_exists($path)){
  611. $f = fopen($path,'w');
  612. fclose($f);
  613. }
  614. $c = file_get_contents($path);
  615. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  616. foreach($matches as $m){
  617. $post = [];
  618. $post['id'] = $m[1];
  619. $post['content'] = trim($m[3]);
  620. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  621. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  622. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  623. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  624. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  625. $entries = [];
  626. if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  627. foreach($links as $l){
  628. $entries[] = $l[1];
  629. }
  630. $post['refs'] = $entries;
  631. }
  632. }
  633. /* marks add here */
  634. $this->Posts[] = $post;
  635. }
  636. }
  637. }
  638. function ReadPosts(){
  639. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  640. (!is_dir('posts') || is_readable('posts') == false) ||
  641. (!is_dir('images') || is_readable('images') == false) ||
  642. (!is_dir('styles') || is_readable('styles') == false)){
  643. $this->Install();
  644. }
  645. $file_list = [];
  646. $glob = glob('posts/*');
  647. foreach($glob as $file) {
  648. if(preg_match('/[0-9]{6}\.md/', $file)) {
  649. $file_list[] = $file;
  650. }
  651. }
  652. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  653. foreach($file_list as $f) {
  654. $this->ReadPostsFromFile($f);
  655. }
  656. $this->DetectThreads();
  657. }
  658. function GetThreadForPost(&$post){
  659. if(isset($post['tid'])) return;
  660. if(!(isset($post['prev']) || isset($post['next']))) return;
  661. $th = [];
  662. $post['tid'] = &$th;
  663. $th['first'] = $th['last'] = &$post;
  664. $iterp = NULL; $count = 1;
  665. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  666. $np = &$this->GetPost($p);
  667. $np['tid'] = &$th;
  668. $th['first'] = &$np;
  669. $iterp = isset($np['prev'])?$np['prev']:NULL;
  670. $count++;
  671. }
  672. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  673. $np = &$this->GetPost($p);
  674. $np['tid'] = &$th;
  675. $th['last'] = &$np;
  676. $iterp = isset($np['next'])?$np['next']:NULL;
  677. $count++;
  678. }
  679. $th['count'] = $count;
  680. $this->Threads[] = $th;
  681. }
  682. function DetectThreads(){
  683. foreach($this->Posts as &$p){
  684. if(isset($p['tid'])) continue;
  685. $this->GetThreadForPost($p);
  686. }
  687. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  688. $now = date_timestamp_get(date_create());
  689. foreach($this->Threads as &$t){
  690. $lasttime = DateTime::createFromFormat('YmdHis', $t['last']['id']);
  691. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  692. $t['score'] = (float)$t['count']*0.2 - min($diff_days,200);
  693. }
  694. function cmp($a, $b){
  695. if ($a['score'] == $b['score']) return 0;
  696. return ($a['score'] > $b['score']) ? -1 : 1;
  697. }
  698. usort($this->Threads,"cmp");
  699. }
  700. function &GetPost($id){
  701. if(!isset($id)) return $this->NULL_POST;
  702. $i=0; $found=0;
  703. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  704. if($p['id'] == $id) { $found = 1; break; }
  705. $i++;
  706. }
  707. if($found) return $this->Posts[$i];
  708. return $this->NULL_POST;
  709. }
  710. function WritePosts(){
  711. $cf = NULL;$opened =NULL;
  712. foreach($this->Posts as $p){
  713. $nid = substr($p['id'], 0,6);
  714. if($cf != $nid){
  715. if($opened){
  716. fflush($opened);
  717. fclose($opened);
  718. }
  719. $cf = $nid;
  720. $opened = fopen("posts/$cf.md", 'w');
  721. }
  722. $info = "[LAMDWIKIPOST {$p['id']}; ".
  723. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  724. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  725. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  726. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  727. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  728. ']';
  729. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  730. }
  731. }
  732. function CachePostLinks(){
  733. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  734. $this->ConvertPost($post);
  735. unset($post['refs']);
  736. }else return;
  737. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  738. unset($im['refs']);
  739. }
  740. foreach ($this->Posts as &$post){
  741. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"]>.*<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  742. foreach($matches as $m){
  743. $ref = &$this->GetPost($m[1]);
  744. if($ref!=NULL){
  745. if(!isset($ref['refs']))$ref['refs']=[];
  746. if(!in_array($post['id'],$ref['refs'])){ $ref['refs'][]=$post['id']; }
  747. }
  748. }
  749. }
  750. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  751. foreach($matches as $m){
  752. if(($im = &$this->FindImage($m[2]))!=NULL){
  753. if(!isset($im['refs'])){$im['refs']=[];}
  754. if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  755. }
  756. }
  757. }
  758. }
  759. }
  760. function CreatePostAnchor(&$post){
  761. $that=&$this;
  762. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  763. $id = '_heading_'.sizeof($this->Anchors);
  764. $entry=[(int)$ma[1], $id, $ma[2]];
  765. $that->Anchors[] = $entry;
  766. return "<h${ma[1]} id='${id}'>${ma[2]}";
  767. }, $post['html']);
  768. }
  769. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to, $get_original_only=false, $mark_value=NULL){
  770. $this->ReadImages();
  771. $this->ReadPosts();
  772. $p_success = NULL;
  773. if(isset($id_if_edit)){
  774. $post = &$this->GetPost($id_if_edit);
  775. if($post===$this->NULL_POST) return $this->NULL_POST;
  776. if($get_original_only){
  777. return $post['content'];
  778. }
  779. if(isset($content)) $post['content'] = $content;
  780. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  781. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  782. $p_success = &$post;
  783. }else{
  784. if(!isset($content)) return $this->NULL_POST;
  785. $id = date('YmdHis');
  786. if($this->GetPost($id)!== $this->NULL_POST) return $this->NULL_POST;
  787. $post = [];
  788. $post['id'] = $id;
  789. $post['content'] = $content;
  790. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to))!== $this->NULL_POST){
  791. if(!(isset($rep['next']) && $rep['next'])){$rep['next'] = $id; $post['prev'] = $rep['id'];}
  792. else $post['content'] = "[引用的文章]($reply_to)".$post['content'];
  793. }
  794. $this->Posts[] = $post;
  795. $p_success = &$this->Posts[count($this->Posts) - 1];
  796. }
  797. $this->CachePostLinks();
  798. $this->WritePosts();
  799. $this->WriteImages();
  800. $this->ClearData();
  801. return $p_success;
  802. }
  803. function InsertReplacementSymbols($MarkdownContent){
  804. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  805. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  806. function($matches){
  807. $rep = preg_replace('/->/','-@>',$matches[0]);
  808. $rep = preg_replace('/=>/','=@>',$rep);
  809. $rep = preg_replace('/<=/','<@=',$rep);
  810. $rep = preg_replace('/<-/','<@-',$rep);
  811. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  812. $rep = preg_replace('/\[-/','[@-',$rep);
  813. return $rep;
  814. },
  815. $replacement);
  816. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  817. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  818. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  819. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  820. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  821. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  822. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  823. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  824. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  825. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  826. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  827. function($matches){
  828. $rep = preg_replace('/-@>/','->',$matches[0]);
  829. $rep = preg_replace('/<@-/','<-',$rep);
  830. $rep = preg_replace('/=@>/','=>',$rep);
  831. $rep = preg_replace('/<@=/','<=',$rep);
  832. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  833. $rep = preg_replace('/\[@-/','[-',$rep);
  834. return $rep;
  835. },
  836. $replacement);
  837. return $replacement;
  838. }
  839. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  840. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  841. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  842. return 0;
  843. }
  844. if(isset($_GET['set_language'])){
  845. setcookie('la_language',$_GET['set_language']); $_COOKIE['la_language'] = $_GET['set_language'];
  846. $redirect='index.php';return 0;
  847. }
  848. if(isset($_GET['post'])){
  849. $this->CurrentPostID = $_GET['post'];
  850. }
  851. if(isset($_GET['offset'])){
  852. $this->CurrentOffset = $_GET['offset'];
  853. }
  854. if(isset($_GET['part'])){
  855. if($_GET['part'] == 'hot') $this->ExtraScripts.="ShowLeftSide();";
  856. else if ($_GET['part'] == 'recent') $this->ExtraScripts.="ShowCenterSide();";
  857. }
  858. if(isset($_GET['post'])){
  859. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  860. }
  861. if(isset($_GET['image_info'])){
  862. $m=$_GET['image_info'];
  863. $this->ReadImages();
  864. $this->ReadPosts();
  865. $im = &$this->FindImage($m);
  866. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  867. echo "<ref>".sizeof($im['refs'])."</ref>";
  868. echo "<insert><ul>";
  869. foreach($im['refs'] as $ref){
  870. $this->MakeSinglePost($this->GetPost($ref), false, true, "post_preview", true, false, false, false, true);"</li>";
  871. }
  872. echo "</ul></insert>";
  873. exit;
  874. }
  875. if($this->LoggedIn){
  876. $this->DoUpload();
  877. if(isset($_POST['settings_button'])){
  878. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  879. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  880. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  881. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  882. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  883. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  884. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  885. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  886. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  887. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  888. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  889. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  890. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  891. $redirect=$_SERVER['REQUEST_URI'];
  892. $this->DoLogout();
  893. }
  894. $this->WriteConfig();
  895. return 0;
  896. }
  897. if(isset($_POST['settings_save_redirect'])){
  898. if(isset($_POST['settings_redirect'])){
  899. $this->BuildRedirectConfig($_POST['settings_redirect']);
  900. }
  901. $this->WriteConfig();
  902. $redirect = 'index.php?extras=true'; return 0;
  903. }
  904. if(isset($_POST['settings_save_translation'])){
  905. if(isset($_POST['settings_translation'])){
  906. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  907. }
  908. $redirect = 'index.php?extras=true'; return 0;
  909. }
  910. if(isset($_GET['post'])){
  911. if(isset($_GET['post_original'])){
  912. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL);
  913. exit;
  914. }
  915. }
  916. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  917. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL);
  918. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect='index.php';
  919. return 0;
  920. }
  921. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  922. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark']);
  923. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect='index.php';
  924. return 0;
  925. }
  926. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  927. $c = $_POST['post_content'];
  928. if('有什么想说的' == $c){ return 0;}
  929. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  930. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  931. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  932. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  933. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL))!=NULL){
  934. $redirect='?post='.$edited['id'];
  935. return 0;
  936. };
  937. }
  938. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  939. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  940. $new_name = $_POST['gallery_edit_new_name'];
  941. if($old_name!=''){
  942. $this->EditGallery($old_name, $new_name, false, true, null);
  943. $redirect='?gallery='.$new_name;
  944. }else{
  945. $this->EditGallery(null, $new_name, false, true, null);
  946. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  947. }
  948. return 0;
  949. }
  950. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  951. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null);
  952. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  953. return 0;
  954. }
  955. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  956. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  957. $this->ReadImages();
  958. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  959. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'));
  960. }
  961. $this->WriteImages();
  962. $this->ClearData();
  963. }
  964. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  965. return 0;
  966. }
  967. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  968. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false');
  969. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  970. return 0;
  971. }
  972. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  973. $this->ReadImages();
  974. $gallery = $_GET['image_list'];
  975. foreach($this->Images as $im){
  976. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  977. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  978. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  979. }
  980. exit;
  981. }
  982. if(isset($_GET['rewrite_styles'])){
  983. $this->WriteStyles();
  984. $redirect='?extras=true'; return 0;
  985. }
  986. }
  987. return 0;
  988. }
  989. function PostProcessHTML($html,&$added_images=null){
  990. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*>)(.*?<\/a>)/u","$1?post=$2$3$4",$html);
  991. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*>)(.*?)(<\/a>)/u","$1$2$4$5<sup>↗</sup>$6",$html);
  992. $images = [];
  993. $images_noclick = [];
  994. $html = preg_replace_callback("/(<img[^>]*src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif)))([\'\"][^>]*)>/u",
  995. function($m) use (&$images,&$images_noclick) {
  996. $src = $m[3];
  997. if(($im = &$this->FindImage($m[3]))!=NULL && isset($im['thumb'])){
  998. $src = $im['thumb'];
  999. }
  1000. $images[]=$m[1].$src.$m[5]." data-imgsrc='".$m[3]."'>";
  1001. $images_noclick[]=$m[1].$src.$m[5].">";
  1002. return "";
  1003. },$html,-1,$count);
  1004. if($count){
  1005. $added_images = $images_noclick;
  1006. $html = preg_replace("/<p>[\s]*<\/p>/u","",$html);
  1007. if($count==1){$html.=$images[0];}
  1008. else{
  1009. $html.="<div class='p_row'>";
  1010. foreach($images as $img){
  1011. $html.="<div class='p_thumb'>".$img."</div>";
  1012. }
  1013. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  1014. }
  1015. }else{
  1016. $added_images = NULL;
  1017. }
  1018. return $html;
  1019. }
  1020. function ConvertPost(&$post){
  1021. if(!isset($post['html'])){
  1022. $post['html'] = $this->PostProcessHTML($this->PDE->text($this->InsertReplacementSymbols($post['content'])),$post['images']);
  1023. }
  1024. }
  1025. function DetectPageType(){
  1026. if(isset($_GET['extras'])) $this->PageType='extras';
  1027. else if(isset($_GET['settings'])) $this->PageType='settings';
  1028. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  1029. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  1030. else $this->PageType = "main";
  1031. }
  1032. function MakeHeader(&$p){?>
  1033. <!DOCTYPE html><html lang='zh-Hans-CN'>
  1034. <head>
  1035. <meta charset='utf-8'>
  1036. <meta content="width=device-width, initial-scale=1" name="viewport">
  1037. <title><?=$this->T($this->Title)?></title>
  1038. <link href='styles/main.css' rel='stylesheet' type="text/css">
  1039. </head>
  1040. <div class='page'>
  1041. <script type='text/javascript'>
  1042. function toggle_mobile_show(a){a.classList.toggle('hidden_on_mobile')}
  1043. function la_auto_grow(element){
  1044. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  1045. }
  1046. var scroll_l=0,scroll_c=0;in_center=1;
  1047. function ShowLeftSide(){
  1048. scroll_c = window.scrollY;
  1049. document.getElementById('div_left').classList.remove('hidden_on_mobile');
  1050. document.getElementById('div_center').classList.add('hidden_on_mobile');
  1051. window.scroll(0, scroll_l); in_center=0;
  1052. }
  1053. function ShowCenterSide(){
  1054. scroll_l = window.scrollY;
  1055. document.getElementById('div_center').classList.remove('hidden_on_mobile');
  1056. document.getElementById('div_left').classList.add('hidden_on_mobile');
  1057. window.scroll(0, scroll_c); in_center=1;
  1058. }
  1059. function ShowBackdrop(alpha=0.5){
  1060. b = document.getElementById('backdrop');
  1061. b.style="background-color:rgba(0,0,0,"+alpha+");";
  1062. b.style.animation='backdrop_fade_in 0.3s forwards';
  1063. b.style.display = 'block';
  1064. }
  1065. function HideBackdrop(){
  1066. b = document.getElementById('backdrop');
  1067. b.style.animation='backdrop_fade_out 0.3s forwards';
  1068. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  1069. }
  1070. function ShowRightSide(big,elem_to_clone){
  1071. p = document.getElementById('pop_right');
  1072. if(elem_to_clone){
  1073. c = elem_to_clone.cloneNode(true);
  1074. c.id='side_bar_cloned';c.className="";c.style="";
  1075. p.querySelector('._content').appendChild(c);
  1076. }
  1077. p.classList.remove('pop_right','pop_right_big');
  1078. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  1079. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  1080. p.style.display='block';
  1081. ShowBackdrop(0.5);
  1082. }
  1083. function HideRightSide(){
  1084. p = document.getElementById('pop_right');
  1085. if(side=p.querySelector('#side_bar_cloned')){
  1086. side.remove();
  1087. }
  1088. put = document.querySelector("#_uploader");
  1089. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  1090. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  1091. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  1092. HideBackdrop();
  1093. }
  1094. function ToggleLeftSide(){if(in_center)ShowLeftSide();else ShowCenterSide();}
  1095. function ScrollToPost(id){
  1096. if(!(post = document.querySelector("[data-post-id='"+id+"']"))) return;
  1097. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  1098. }
  1099. </script>
  1100. <header>
  1101. <?php $this->MakeNavButtons($p); ?>
  1102. <hr />
  1103. </header>
  1104. <div id='post_menu' style='display:none;' class='pop_menu invert_a'>
  1105. <ul>
  1106. <li><span id='_time_hook' class='smaller gray'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  1107. <li>
  1108. <a id='share_copy'>📋︎</a>
  1109. <a id='share_pin' target='_blank'>Pin</a>
  1110. <a id='share_twitter' target='_blank'>Twitter</a>
  1111. <a id='share_weibo' target='_blank'><?=$this->T('微博')?></a>
  1112. </li>
  1113. <?php if($this->LoggedIn){ ?>
  1114. <hr />
  1115. <li><a id='menu_edit'><?=$this->T('修改')?></a></li>
  1116. <li>
  1117. <a id='menu_refer_copy'><?=$this->T('只复制')?></a>
  1118. <a id='menu_refer'><?=$this->T('引用')?></a><br class='hidden_on_desktop' />
  1119. </li>
  1120. <li><a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  1121. <li id='mark_details' style='display:none;'><b>
  1122. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  1123. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  1124. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  1125. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  1126. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  1127. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  1128. </b></li>
  1129. <hr />
  1130. <li><a id='menu_delete' class='smaller'></a></li>
  1131. <?php } ?>
  1132. </ul>
  1133. </div>
  1134. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide()'
  1135. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  1136. <div id='pop_right' class='pop_right'>
  1137. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  1138. <?=$this->T('关闭')?>→</a></div>
  1139. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  1140. <div id='_uploader' style='display:none;'>
  1141. <?php $this->MakeUploader(true); ?>
  1142. <p>&nbsp;</p>
  1143. <?php $this->MakeSideGalleryCode(); ?>
  1144. </div>
  1145. <?php } ?>
  1146. <div class='_content'></div>
  1147. </div>
  1148. <?php
  1149. }
  1150. function TranslatePostParts($html){
  1151. $html = preg_replace_callback('/>([^<]+?)</u', function($ma){
  1152. return ">".$this->T($ma[1])."<";
  1153. }, $html);
  1154. return $html;
  1155. }
  1156. function MakeNavButtons(&$p){?>
  1157. <b><a href='index.php' class='hidden_on_mobile'><?=$this->T($this->Title)?></a></b>
  1158. <b><a class='hidden_on_desktop'
  1159. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ShortTitle)?>...</a></b>
  1160. <?php if($this->PageType=='post'){ ?>
  1161. <div style='display:inline;'><a id='button_back'>←</a></div>
  1162. <div style='float:right;'>
  1163. <?php if(isset($p) && isset($p['refs']) && isset($p['refs'][0])){ ?>
  1164. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  1165. <?=$this->T('链接')?>(<?=sizeof($p['refs'])?>)</a></span>
  1166. <?php } ?>
  1167. <span class='hidden_on_wide'>
  1168. <a id='button_toc'
  1169. href='javascript:ShowRightSide(true,document.querySelector("#div_right"));'><?=$this->T('目录')?></a></div></span>
  1170. <?php } ?>
  1171. <ul class='hidden_on_mobile' id='mobile_nav'>
  1172. <?php if($this->PageType!='main'){ ?>
  1173. <li class='hidden_on_desktop block_on_mobile' id='button_recent'><a href='index.php?part=recent'><?=$this->T('最近')?></a></li>
  1174. <li class='hidden_on_desktop block_on_mobile' id='button_hot'><a href='index.php?part=hot'><?=$this->T('热门')?></a></li>
  1175. <?php } else { ?>
  1176. <li class='hidden_on_desktop block_on_mobile' id='button_recent'>
  1177. <a href='javascript:ShowCenterSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('最近')?></a></li>
  1178. <li class='hidden_on_desktop block_on_mobile' id='button_hot'>
  1179. <a href='javascript:ShowLeftSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('热门')?></a></li>
  1180. <?php } ?>
  1181. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  1182. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false));
  1183. } ?>
  1184. <li><a href='?gallery=default'><?=$this->T('媒体')?></a></li>
  1185. <?php if($this->LanguageAppendix=='zh'){ ?>
  1186. <li class='invert_a smaller'><a href='<?='index.php?&set_language=en'?>'><b>汉语</b>/English</a></li>
  1187. <?php }else { ?>
  1188. <li class='invert_a smaller'><a href='<?='index.php?&set_language=zh'?>'>汉语/<b>English</b></a></li>
  1189. <?php } ?>
  1190. </ul>
  1191. <?php
  1192. }
  1193. function GenerateLinkedPosts($ht){
  1194. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"]>(.*)<\/a>[\s]*<\/p>/u',
  1195. function($m){
  1196. $rp = &$this->GetPost($m[1]);
  1197. $s="<a href='?post=".$m[1]."' class='clean_a'><div class='post_ref post_box'>".
  1198. "<div class='smaller gray'>".$m[2]."</div><div class='post_ref_inner'>".
  1199. ($rp!==NULL?$this->GenerateSinglePost($rp,true,false,false,true):$this->T("未找到该引用。")).
  1200. "</div></div></a>";
  1201. return $s;
  1202. },
  1203. $ht
  1204. );
  1205. return $ht;
  1206. }
  1207. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false, $generate_thumbs=false){
  1208. $this->ConvertPost($post);
  1209. if($generate_anchor){ $this->CreatePostAnchor($post); }
  1210. $ht = $post['html'];
  1211. if ($strip_tags){
  1212. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote>');
  1213. $ht = "<div class='post_ref_main'>".$ht."</div>";
  1214. }
  1215. else if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  1216. if ($generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  1217. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  1218. foreach($post['images'] as $im){
  1219. $ht.="<li class='file_thumb'>".$im."</li>";
  1220. }
  1221. $ht.="</ul></div>";
  1222. }
  1223. return $ht;
  1224. }
  1225. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  1226. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  1227. $generate_thumb = false, $is_top = false){
  1228. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  1229. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  1230. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  1231. ?>
  1232. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?><?=$side?" post_box":""?>'
  1233. data-post-id='<?=$post['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  1234. <?php if($mark_value>=0 && !$show_link){?>
  1235. <div style='font-size:1rem;' class='<?=$is_deleted?"gray":""?>'><?=$this->Markers[$post['mark_value']]?>
  1236. <?=$this->T('标记')?></div>
  1237. <?php } ?>
  1238. <?php if($is_top){?>
  1239. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  1240. <?php } ?>
  1241. <?=$side?"<a href='?post={$post['id']}'>":""?>
  1242. <div class='<?=$side?"":($show_link?'post_width':'post_width_big')?>
  1243. <?=$is_deleted?"deleted_post":""?>'>
  1244. <?php if(!$side && !$strip_tags){?>
  1245. <div class='post_menu_button _menu_hook' >+</div>
  1246. <?php } ?>
  1247. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true, $generate_thumb)?>
  1248. </div>
  1249. <?=$side?"</a>":""?>
  1250. <?php if(!$side && $show_link){ ?>
  1251. <a href='?post=<?=$post['id']?>'>
  1252. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  1253. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"→")?>
  1254. </div>
  1255. <?php if($ref_count){ ?>
  1256. <div class='post_access ref_count'><?=$ref_count?></div>
  1257. <?php } ?>
  1258. </a>
  1259. <?php }
  1260. if($show_thread_link && isset($post['tid']) && $post['tid']['first']['id']!=$post['id']){ ?>
  1261. <div class='invert_a smaller block opt_compact post'>
  1262. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  1263. <?=$this->GenerateSinglePost($post['tid']['first'], true, false, false, true);?>
  1264. </div>
  1265. <a href='?post=<?=$post['tid']['first']['id']?>'>
  1266. <div class='post_access invert_a hover_dark'><?=isset($post['tid']['first']['mark_value'])?
  1267. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  1268. </div>
  1269. <?php }
  1270. if($show_reply_count && isset($post['tid'])){ ?>
  1271. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  1272. <?=$this->T('个回复')?></a>
  1273. <?php }
  1274. ?>
  1275. </li>
  1276. <?php
  1277. }
  1278. function MakePostingFields($reply_to=NULL, $show_hint=false){?>
  1279. <div class='smaller' id='post_hint_text' style='display:<?=$show_hint?"block":"none"?>;'><?=$this->T('继续补充该话题:')?></div>
  1280. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  1281. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  1282. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  1283. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  1284. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  1285. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?> /></input>
  1286. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  1287. <div style='float:right;'>
  1288. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  1289. <?=$this->T('清空')?></a>
  1290. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  1291. </div>
  1292. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  1293. <script> la_auto_grow(document.getElementById("post_content"));</script>
  1294. <?php if($reply_to){ ?>
  1295. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  1296. <?php } ?>
  1297. <?php
  1298. }
  1299. function MakeRecentPosts(){?>
  1300. <div class='center' id='div_center'>
  1301. <h2><?=$this->T('最近')?></h2>
  1302. <?php if($this->LoggedIn){ ?>
  1303. <div class='post_box_top _input_bundle'>
  1304. <?php $this->MakePostingFields(NULL,false); ?>
  1305. </div>
  1306. <?php } ?>
  1307. <ul>
  1308. <?php
  1309. if(isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset){
  1310. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true);
  1311. }
  1312. $i = 0;
  1313. foreach(array_reverse($this->Posts) as &$p){
  1314. if(in_array($p['id'],[$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation]))
  1315. continue;
  1316. if(isset($p['tid'])){
  1317. if(isset($p['tid']['displayed'])) continue;
  1318. $p['tid']['displayed'] = True;
  1319. }
  1320. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  1321. $this->MakeSinglePost($p, true, false, NULL, false, true, false, false, false, false);
  1322. $i++;
  1323. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  1324. }?>
  1325. </ul>
  1326. <div class='page_selector clean_a'>
  1327. <hr />
  1328. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1)."'"):""?>
  1329. <?=$this->CurrentOffset==0?"class='gray'":""?>>←</a>
  1330. <?=$this->CurrentOffset+1?>
  1331. <a href='index.php?offset=<?=$this->CurrentOffset+1?>'>→</a>
  1332. </div>
  1333. </div>
  1334. <?php
  1335. }
  1336. function MakeHotPosts(){?>
  1337. <div class='left hidden_on_mobile' id='div_left'>
  1338. <h2><?=$this->T('热门')?></h2>
  1339. <ul>
  1340. <?php
  1341. $i=0;
  1342. foreach($this->Threads as &$th){
  1343. if($i>=$this->HotPostCount) break;
  1344. $this->MakeSinglePost($th['first'], false, true, "post_preview", true, false, true, false, true, false);
  1345. $i++;
  1346. } ?>
  1347. </ul>
  1348. </div>
  1349. <?php
  1350. }
  1351. function MakeLinkedPosts(&$p){
  1352. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  1353. <div class='left hidden_on_mobile' id='div_left'>
  1354. <h2<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h2>
  1355. <?php
  1356. if($has_ref){ ?>
  1357. <span class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></span>
  1358. <ul><?php
  1359. foreach($p['refs'] as &$pr){
  1360. $this->MakeSinglePost($this->GetPost($pr), false, true, "post_preview", true, false, false, false, true, false);
  1361. }
  1362. ?></ul>
  1363. <?php }else{ ?>
  1364. <span class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></span>
  1365. <?php } ?>
  1366. </div>
  1367. <?php
  1368. }
  1369. function MakePostSection(&$post){
  1370. $this->Anchors = [];
  1371. ?>
  1372. <div class='center' id='div_center'>
  1373. <?php $th=NULL; $is_thread = isset($post['tid']); if($is_thread){ $th = $post['tid'];?>
  1374. <h2><?=$this->T('话题')?></h2>
  1375. <?php }else{ ?>
  1376. <h2><?=$this->T('详细')?></h2>
  1377. <?php } ?>
  1378. <ul>
  1379. <?php
  1380. if($is_thread){
  1381. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL)){
  1382. $use_class=($p == $post)?'focused_post':'';
  1383. $show_link = ($p == $post)?false:true;
  1384. $this->MakeSinglePost($p,$show_link,false,$use_class,false, false, false, true, false, false);
  1385. if($p == $post){?>
  1386. <script>
  1387. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  1388. </script>
  1389. <?php }
  1390. }
  1391. }else{
  1392. $this->MakeSinglePost($post,false, false, 'focused_post',false, false, false, true, false, false);
  1393. ?><script>
  1394. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  1395. </script><?php
  1396. } ?>
  1397. </ul>
  1398. <?php if($this->LoggedIn){ ?>
  1399. <br />
  1400. <div class='post_width_big'>
  1401. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  1402. </div>
  1403. <?php } ?>
  1404. </div>
  1405. <?php
  1406. }
  1407. function MakeSideGalleryCode(){?>
  1408. <div>
  1409. <h3><?=$this->T('点击图片以插入:')?></h3>
  1410. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  1411. <option value="main"><?=$this->T('全部')?></option>
  1412. <?php if($this->LoggedIn){ ?>
  1413. <option value="trash"><?=$this->T('垃圾桶')?></option>
  1414. <?php }?>
  1415. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  1416. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  1417. <?php } ?>
  1418. </select>
  1419. <div id='side_gallery'>
  1420. </div>
  1421. </div>
  1422. <script>
  1423. function InsertImage(imgname){
  1424. t = document.querySelector("#post_content");
  1425. v = t.value;
  1426. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  1427. la_auto_grow(t);
  1428. }
  1429. function RefreshSideGallery(){
  1430. let xhr = new XMLHttpRequest();
  1431. xhr.onreadystatechange = (function(){
  1432. if (this.readyState === this.DONE) {
  1433. if (this.status === 200) {
  1434. ind = document.querySelector("#side_gallery");
  1435. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  1436. str = "<ul class='side_thumb'>"
  1437. for (const m of res) {
  1438. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+
  1439. "<img src='"+m[2]+"' /></div>"
  1440. }
  1441. str += "</ul>"
  1442. ind.innerHTML = str;
  1443. }
  1444. }
  1445. }
  1446. });
  1447. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  1448. xhr.send();
  1449. }
  1450. </script>
  1451. <?php
  1452. }
  1453. function MakeUploader($is_side=false){ ?>
  1454. <div id='upload_operation_area'>
  1455. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  1456. <input type="file" id='upload_selector' accept="image/x-png,image/gif,image/jpeg" multiple/>
  1457. <ul id='file_list'>
  1458. </ul>
  1459. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  1460. </div>
  1461. <a id='upload_click' href='javascript:UploadList()'<?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  1462. <script>
  1463. function pastehandler(event){
  1464. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  1465. for (index in items) {
  1466. var item = items[index];
  1467. if (item.kind === 'file') {
  1468. put = document.querySelector("#_uploader");
  1469. if(put) ShowSideUploader();
  1470. var blob = item.getAsFile();
  1471. AddImageFile(blob);
  1472. return;
  1473. }
  1474. }
  1475. }
  1476. let _fd_list = [];
  1477. let hint=document.querySelector('#upload_hint');
  1478. function ToggleCompress(button){
  1479. li = button.parentNode;
  1480. num=li.dataset.number;
  1481. for(i=0;i<_fd_list.length;i++){
  1482. if (_fd_list[i][0] == num){
  1483. state = _fd_list[i][2];
  1484. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  1485. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  1486. }
  1487. }
  1488. }
  1489. function RemoveFromUpload(button){
  1490. li = button.parentNode;
  1491. num=li.dataset.number;
  1492. for(i=0;i<_fd_list.length;i++){
  1493. if (_fd_list[i][0] == num){
  1494. _fd_list.splice(i, 1);break;
  1495. }
  1496. }
  1497. li.parentNode.removeChild(li);
  1498. }
  1499. function EndThisUpload(){
  1500. unfinished = 0;
  1501. for(i=0;i<_fd_list.length;i++){
  1502. if (_fd_list[i][3]==0){
  1503. unfinished=1;
  1504. }
  1505. }
  1506. if(!unfinished){
  1507. hint.innerHTML="<?=$this->T('上传完成。')?>";
  1508. cl=document.querySelector('#upload_click');
  1509. if(!cl.dataset.isSide){
  1510. cl.innerHTML="<?=$this->T('刷新页面')?>";
  1511. cl.href=window.location.href;
  1512. }else{
  1513. _fd_list.splice(0,_fd_list.length);
  1514. fl = document.querySelector("#file_list");
  1515. fl.innerHTML = "";
  1516. list=document.querySelector('#upload_operation_area');
  1517. list.style.pointerEvents='';
  1518. list.style.opacity='';
  1519. document.onpaste=pastehandler;
  1520. RefreshSideGallery();
  1521. }
  1522. }
  1523. }
  1524. function UploadList(){
  1525. if(!_fd_list.length) return;
  1526. hint.innerHTML="<?=$this->T('正在上传...')?>";
  1527. list=document.querySelector('#upload_operation_area');
  1528. list.style.pointerEvents='none';
  1529. list.style.opacity='0.5';
  1530. document.onpaste="";
  1531. for(i=0;i<_fd_list.length;i++){
  1532. let xhr = new XMLHttpRequest();
  1533. //xmlHTTP.upload.addEventListener("loadstart", loadStartFunction, false);
  1534. //xmlHTTP.upload.addEventListener("progress", progressFunction, false);
  1535. //xmlHTTP.addEventListener("load", transferCompleteFunction, false);
  1536. //xmlHTTP.addEventListener("error", uploadFailed, false);
  1537. //xmlHTTP.addEventListener("abort", uploadCanceled, false);
  1538. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  1539. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  1540. function wrap(li, i){
  1541. var ind = li.querySelector('._compress_toggle')
  1542. return function(){
  1543. if (this.readyState === this.DONE) {
  1544. if (this.status === 200) {
  1545. var response = xhr.responseText;
  1546. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  1547. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  1548. _fd_list[i][3] = 1;
  1549. }else{
  1550. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  1551. _fd_list[i][3] = 1;
  1552. }
  1553. EndThisUpload();
  1554. }
  1555. }
  1556. }
  1557. }
  1558. xhr.onreadystatechange = wrap(li, i);
  1559. xhr.send(_fd_list[i][1]);
  1560. }
  1561. }
  1562. function AddImageFile(blob){
  1563. var ext="";
  1564. if(blob.name.match(/png$/))ext = 'png';
  1565. else if(blob.name.match(/jpg$/))ext = 'jpg';
  1566. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  1567. else if(blob.name.match(/gif$/))ext = 'gif';
  1568. else return;
  1569. var fd = new FormData();
  1570. blob.name = blob.name=generateUID().toString();
  1571. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  1572. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  1573. var reader = new FileReader();
  1574. reader.onload = function(event){
  1575. fl = document.querySelector("#file_list");
  1576. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  1577. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  1578. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  1579. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  1580. fl.innerHTML+=ht;
  1581. };
  1582. reader.readAsDataURL(blob);
  1583. }
  1584. sel = document.querySelector('#upload_selector');
  1585. sel.addEventListener("change", function(){
  1586. var input = this;
  1587. function ff(file){
  1588. return function(e){
  1589. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  1590. blob.name = file.name;
  1591. AddImageFile(blob);
  1592. }
  1593. }
  1594. for(i=0;i<input.files.length;i++){
  1595. if(input.files[i].size){
  1596. let reader = new FileReader();
  1597. reader.onload = ff(input.files[i]);
  1598. reader.readAsArrayBuffer(input.files[i]);
  1599. }
  1600. }
  1601. });
  1602. function generateUID() {
  1603. var firstPart = (Math.random() * 46656) | 0;
  1604. var secondPart = (Math.random() * 46656) | 0;
  1605. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  1606. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  1607. return firstPart + secondPart;
  1608. }
  1609. document.onpaste = pastehandler;
  1610. function dropHandler(ev) {
  1611. put = document.querySelector("#_uploader");
  1612. if(put) ShowSideUploader();
  1613. bkg=document.querySelector('#dropping_background');
  1614. bkg.style.display="none";
  1615. console.log('File(s) dropped');
  1616. ev.preventDefault();
  1617. if (ev.dataTransfer && ev.dataTransfer.items) {
  1618. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  1619. if (ev.dataTransfer.items[i].kind === 'file') {
  1620. var file = ev.dataTransfer.items[i].getAsFile();
  1621. function ff(file){
  1622. return function(e){
  1623. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  1624. blob.name = file.name;
  1625. AddImageFile(blob);
  1626. }
  1627. }
  1628. if(file){
  1629. let reader = new FileReader();
  1630. reader.onload = ff(file);
  1631. reader.readAsArrayBuffer(file);
  1632. }
  1633. }
  1634. }
  1635. } else {
  1636. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  1637. function ff(file){
  1638. return function(e){
  1639. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  1640. blob.name = file.name;
  1641. AddImageFile(blob);
  1642. }
  1643. }
  1644. if(ev.dataTransfer.files[i].size){
  1645. let reader = new FileReader();
  1646. reader.onload = ff(ev.dataTransfer.files[i]);
  1647. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  1648. }
  1649. }
  1650. }
  1651. }
  1652. function dragOverHandler(ev) {
  1653. bkg=document.querySelector('#dropping_background');
  1654. bkg.style.display="";
  1655. console.log('File(s) in drop zone');
  1656. ev.preventDefault();
  1657. }
  1658. </script>
  1659. <?php
  1660. }
  1661. function MakeGallerySection(){
  1662. if(!isset($_GET['gallery'])) return;
  1663. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  1664. $name=$_GET['gallery'];}?>
  1665. <script>
  1666. document.title+=" | <?=$this->T('画廊')?>";
  1667. </script>
  1668. <div class='center' id='div_center' style='position:relative;'>
  1669. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  1670. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  1671. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  1672. <div class='hidden_on_desktop'>
  1673. <?=$this->T('前往')?>
  1674. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  1675. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  1676. if(!isset($g['featured']) || !$g['featured']){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  1677. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>><?=$this->T($g['name'])?></option>
  1678. <?php } ?>
  1679. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>><?=$this->T('全部')?></option>
  1680. <?php if($this->LoggedIn){ ?>
  1681. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>><?=$this->T('垃圾桶')?></option>
  1682. <?php } ?>
  1683. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  1684. if(isset($g['featured']) && $g['featured']){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  1685. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>><?=$this->T($g['name'])?></option>
  1686. <?php } ?>
  1687. </select>
  1688. </div>
  1689. <?php if($this->LoggedIn){?>
  1690. <div>
  1691. <?php if(isset($name)){ ?>
  1692. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller'>
  1693. <a href='javascript:ShowDeleteMenu();' class='smaller'><?=$this->T('删除相册')?></a><br />
  1694. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  1695. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'
  1696. class='smaller'><?=$this->T('取消精选')?></a>
  1697. <?php }else{ ?>
  1698. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'
  1699. class='smaller'><?=$this->T('设为精选')?></a>
  1700. <?php } ?>
  1701. <div class='pop_menu smaller invert_a' id='gallery_delete_menu' style='display:none;'>
  1702. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  1703. <a href='javascript:HidePopMenu();'>×</a>
  1704. <hr />
  1705. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  1706. </div>
  1707. </div>
  1708. <?php } ?>
  1709. <?php $this->MakeUploader(false); ?>
  1710. <div style='text-align:right;position:relative;' class='invert_a smaller'>
  1711. <div style='position:relative'>
  1712. <?php if(isset($name)){ ?>
  1713. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  1714. <?php } ?>
  1715. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  1716. <div class='pop_menu smaller invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  1717. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  1718. method="post" style='display:none;' id='gallery_edit_form'></form>
  1719. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  1720. <a href='javascript:HidePopMenu();'>×</a>
  1721. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name'>
  1722. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name'
  1723. id='gallery_edit_old_name' style='display:none'>
  1724. <input class='button' type='submit' form='gallery_edit_form'
  1725. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'></a>
  1726. </div>
  1727. </div>
  1728. </div>
  1729. <div class='smaller'>
  1730. <form action="<?=$_SERVER['REQUEST_URI']?>"
  1731. method="post" style='display:none;' id='gallery_move_form'></form>
  1732. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  1733. id='gallery_move_ops' style='display:none'>
  1734. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  1735. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  1736. <p><?=$this->T('添加到')?>
  1737. <select id="gallery_move_to">
  1738. <option value="trash"><?=$this->T('垃圾桶')?></option>
  1739. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  1740. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  1741. <?php } ?>
  1742. </select>
  1743. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  1744. </p>
  1745. <p>
  1746. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  1747. </p>
  1748. </div>
  1749. </div>
  1750. <?php } ?>
  1751. <p>&nbsp;</p>
  1752. <div>
  1753. <div class='p_row'>
  1754. <?php if(isset($this->Images[0])) foreach($this->Images as $im){
  1755. if($_GET['gallery']=='trash') $name='trash';
  1756. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;} ?>
  1757. <div class='p_thumb'>
  1758. <?php if($this->LoggedIn){ ?>
  1759. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  1760. <?php } ?>
  1761. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>' />
  1762. </div>
  1763. <?php } ?>
  1764. <div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div>
  1765. </div>
  1766. </div>
  1767. </div>
  1768. <?php if($this->LoggedIn){ ?>
  1769. <script type='text/javascript'>
  1770. var selected_image = new Array();
  1771. function RemoveFromGallery(){
  1772. form = document.querySelector('#gallery_move_form');
  1773. ops = document.querySelector('#gallery_move_ops');
  1774. sel = document.querySelector('#gallery_move_to');
  1775. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  1776. form.submit();
  1777. }
  1778. function AddToGallery(){
  1779. form = document.querySelector('#gallery_move_form');
  1780. ops = document.querySelector('#gallery_move_ops');
  1781. sel = document.querySelector('#gallery_move_to');
  1782. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  1783. form.submit();
  1784. }
  1785. function ClearSelectedImages(){
  1786. selected_image.splice(0, selected_image.length);
  1787. checks = document.querySelectorAll('._select_hook');
  1788. [].forEach.call(checks, function(c){
  1789. c.classList.remove('p_thumb_selected');
  1790. });
  1791. count = document.querySelector('#gallery_selected_count');
  1792. count.innerHTML="0";
  1793. }
  1794. function ToggleSelectImage(elem, name){
  1795. count = document.querySelector('#gallery_selected_count');
  1796. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  1797. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  1798. count.innerHTML=selected_image.length.toString()
  1799. }
  1800. function ShowGalleryEditMenu(old_name){
  1801. m = document.querySelector('#gallery_edit_menu');
  1802. old = document.querySelector('#gallery_edit_old_name');
  1803. m.style.display='block';
  1804. if(old_name!=''){ old.value=old_name; }else{ old.value=''; }
  1805. }
  1806. function ShowDeleteMenu(){
  1807. m=document.querySelector('#gallery_delete_menu');
  1808. m.style.display='block';
  1809. }
  1810. </script>
  1811. <?php } ?>
  1812. <?php
  1813. }
  1814. function MakeGalleryLeft(){?>
  1815. <div class='left hidden_on_mobile gallery_left' id='div_left'>
  1816. <h2><?=$this->T('相册')?></h2>
  1817. <div>
  1818. <span class='gray smaller'><?=$this->T('精选')?><hr> </span>
  1819. <ul>
  1820. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  1821. if(!isset($g['featured']) || !$g['featured']){ continue; } ?>
  1822. <a href='?gallery=<?=$g['name']?>'>
  1823. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'><?=$this->T($g['name'])?></li></a>
  1824. <?php } ?>
  1825. </ul>
  1826. <span class='gray smaller'><?=$this->T('其他相册')?><hr></span>
  1827. <div class='smaller'><ul>
  1828. <a href='?gallery=main'><li class='<?=$_GET['gallery']=='main'?' selected':""?>'><?=$this->T('全部图片')?></li></a>
  1829. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  1830. if(isset($g['featured']) && $g['featured']){ continue; } ?>
  1831. <a href='?gallery=<?=$g['name']?>'>
  1832. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'><?=$this->T($g['name'])?></li></a>
  1833. <?php } ?>
  1834. <?php if($this->LoggedIn){ ?>
  1835. <a href='?gallery=trash'><li class='<?=$_GET['gallery']=='trash'?' selected':""?>'><?=$this->T('垃圾桶')?></li></a>
  1836. <?php } ?>
  1837. </ul></div>
  1838. <p>&nbsp;</p>
  1839. <script>
  1840. </script>
  1841. </div>
  1842. </div>
  1843. <?php
  1844. }
  1845. function MakeTOC(){?>
  1846. <div class='right hidden_on_mobile' id='div_right'>
  1847. <?php if(isset($this->Anchors[0])){?>
  1848. <h2><?=$this->T('目录')?></h2><ul>
  1849. <?php
  1850. foreach($this->Anchors as $a){?>
  1851. <li class='toc_entry_<?=$a[0]>5?5:$a[0]?>'><a href='#<?=$a[1]?>'><?=$a[2]?></a></li>
  1852. <?php }
  1853. ?></ul>
  1854. <?php }else{ ?>
  1855. <h2 class='gray'><?=$this->T('目录')?></h2>
  1856. <span class='gray smaller'><?=$this->T('未找到目录')?></span>
  1857. <?php } ?>
  1858. </div>
  1859. <?php
  1860. }
  1861. function MakeSettings(){?>
  1862. <div class='settings'>
  1863. <h2><?=$this->T('设置')?></h2>
  1864. <table style='white-space:nowrap;'>
  1865. <?php if($this->LoggedIn){ ?>
  1866. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  1867. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  1868. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  1869. <tr><td><?=$this->T('网站标题')?></td>
  1870. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  1871. value='<?=$this->Title?>'/></td></tr>
  1872. <tr><td><?=$this->T('短标题')?></td>
  1873. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  1874. value='<?=$this->ShortTitle?>'/></td></tr>
  1875. <tr><td><?=$this->T('显示名称')?></td>
  1876. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  1877. value='<?=$this->DisplayName?>'/></td></tr>
  1878. <tr><td><?=$this->T('导航栏')?>
  1879. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  1880. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  1881. value='<?=$this->SpecialNavigation?>'/></td></tr>
  1882. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  1883. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  1884. value='<?=$this->SpecialFooter?>'/></td></tr>
  1885. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  1886. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  1887. value='<?=$this->SpecialFooter2?>'/></td></tr>
  1888. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  1889. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  1890. value='<?=$this->SpecialPinned?>'/></td></tr>
  1891. <tr><td><?=$this->T('默认相册')?></td>
  1892. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  1893. value='<?=$this->DefaultGallery?>'/></td></tr>
  1894. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  1895. <tr><td class='smaller gray'>&nbsp;</td></tr>
  1896. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  1897. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  1898. <tr><td><?=$this->T('帐号')?></td>
  1899. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  1900. value='<?=$this->Admin?>'/></td></tr>
  1901. <tr><td><?=$this->T('新密码')?></td>
  1902. <td><input type="password" form="settings_form"
  1903. id='settings_new_password' name='settings_new_password' /></td></tr>
  1904. <tr><td><?=$this->T('再次输入')?></td>
  1905. <td><input type="password" form="settings_form"
  1906. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  1907. <tr><td><?=$this->T('旧密码')?></td>
  1908. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  1909. <?php }else{ ?>
  1910. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  1911. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  1912. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  1913. <tr><td><?=$this->T('帐号')?></td>
  1914. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  1915. <tr><td><?=$this->T('密码')?></td>
  1916. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  1917. <?php } ?>
  1918. </table>
  1919. <?php if($this->LoggedIn){ ?>
  1920. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' /></input>
  1921. <?php }else{ ?>
  1922. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' /></input>
  1923. <?php } ?>
  1924. </div>
  1925. <?php
  1926. }
  1927. function MakeExtraOperations(){?>
  1928. <div class='settings' style='overflow:auto;'>
  1929. <h2><?=$this->T('附加操作')?></h2>
  1930. <a href='?index.php&settings=true'><?=$this->T('返回一般设置')?></a>
  1931. <p>&nbsp;</p>
  1932. <h3><?=$this->T('自动重定向')?></h3>
  1933. <span class='smaller gray'>
  1934. <?=$this->T('P为帖子跳转,按域名后的字符串匹配跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  1935. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  1936. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  1937. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  1938. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  1939. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  1940. value='<?=$this->T('保存重定向设置')?>' /></input>
  1941. <p>&nbsp;</p>
  1942. <h3><?=$this->T('自定义翻译')?></h3>
  1943. <span class='smaller gray'>
  1944. <?=$this->T('填写格式:')?>
  1945. <br /><pre>- 语言 | Language</pre></span>
  1946. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  1947. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  1948. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  1949. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  1950. value='<?=$this->T('保存翻译')?>' /></input>
  1951. <p>&nbsp;</p>
  1952. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  1953. <ul>
  1954. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  1955. </ui>
  1956. <br /><br /><br /><a href='?index.php&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  1957. </div>
  1958. <?php
  1959. }
  1960. function MakeMainBegin(){?>
  1961. <div class='main' ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  1962. <?php
  1963. }
  1964. function MakeMainEnd(){?>
  1965. </div>
  1966. <?php
  1967. }
  1968. function MakeFooter(){?>
  1969. <div class='small_footer'>
  1970. <hr />
  1971. <b><?=$this->T($this->Title)?></b>
  1972. <span onclick='event.stopPropagation()'
  1973. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  1974. </div>
  1975. <div class='footer'>
  1976. <div style='white-space:nowrap;'>
  1977. <div class='footer_additional'>
  1978. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  1979. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false));
  1980. } ?>
  1981. </div>
  1982. <div class='footer_additional'>
  1983. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  1984. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false));
  1985. } ?>
  1986. </div>
  1987. </div>
  1988. </div>
  1989. <p>&nbsp;<p>
  1990. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  1991. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  1992. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  1993. </div>
  1994. <div id='big_image_overlay' style='display:none'>
  1995. <div class='big_image_box' onclick='HideBigImage()'>
  1996. <img id='big_image' />
  1997. </div>
  1998. <div class='big_side_box' onclick='HideBigImage();'>
  1999. <div class='side_box_mobile_inner'>
  2000. <div style='float:right;'>
  2001. <a class='clean_a' onclick='HideBigImage();'><?=$this->T('关闭')?>→</a>
  2002. </div>
  2003. <div>
  2004. <b><a class='clean_a' download id='image_download' onclick="event.stopPropagation();">↓<?=$this->T('下载')?></a></b>
  2005. <hr />
  2006. </div>
  2007. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  2008. <li>
  2009. <a id='big_share_copy'>📋︎</a>
  2010. <a id='big_share_pin' target='_blank'>Pin</a>
  2011. <a id='big_share_twitter' target='_blank'>Twitter</a>
  2012. <a id='big_share_weibo' target='_blank'><?=$this->T('微博')?></a>
  2013. </li>
  2014. <hr />
  2015. </div>
  2016. <div id='big_image_info' onclick="event.stopPropagation();"></div>
  2017. </div>
  2018. </div>
  2019. </div>
  2020. </div><!-- page -->
  2021. </body>
  2022. </html>
  2023. <script>
  2024. <?=$this->ExtraScripts?>
  2025. if(back = document.getElementById('button_back')){
  2026. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  2027. back.href='javascript:history.back()';
  2028. }else{
  2029. back.href='index.php';
  2030. }
  2031. }
  2032. function copy_text(t) {
  2033. ta = document.createElement('textarea');
  2034. document.body.appendChild(ta);
  2035. ta.value = t;
  2036. ta.select();
  2037. document.execCommand("copy");
  2038. document.body.removeChild(ta);
  2039. }
  2040. <?php if($this->LoggedIn){ ?>
  2041. function ShowSideUploader(){
  2042. ShowRightSide(true,null);
  2043. put = document.querySelector("#_uploader");
  2044. put.style.display='block';
  2045. RefreshSideGallery();
  2046. }
  2047. dmark = document.querySelector("#mark_details");
  2048. var rp = document.querySelector('#post_reply_to');
  2049. var _reply_to = rp?rp.defaultValue:"";
  2050. function RestoreReply(){
  2051. if(rp){
  2052. rp.defaultValue = _reply_to;
  2053. }
  2054. document.querySelector('#post_reply_restore').style.display='none';
  2055. ht = document.querySelector('#post_hint_text');
  2056. if (_reply_to!=""){
  2057. ht.style.display='block';
  2058. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  2059. }else{
  2060. ht.style.display='none';
  2061. }
  2062. document.querySelector('#post_edit_target').value="";
  2063. }
  2064. function MakeRefer(id){
  2065. t = document.querySelector('#post_content')
  2066. t.focus();
  2067. v = t.value;
  2068. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  2069. la_auto_grow(t);
  2070. if(rp){
  2071. rp.defaultValue = "";
  2072. ht = document.querySelector('#post_hint_text');
  2073. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  2074. document.querySelector('#post_reply_restore').style.display='inline';
  2075. rs = document.querySelector('#post_reply_restore');
  2076. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  2077. document.getElementById('post_menu').style.display='none';
  2078. }
  2079. }
  2080. function CopyRefer(id){
  2081. copy_text("[<?=$this->T('引用文章')?>]("+id.toString()+")");
  2082. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  2083. }
  2084. function MakeEdit(id){
  2085. ed = document.getElementById('menu_edit');
  2086. ed.innerHTML="<?=$this->T('稍等')?>";
  2087. ed.href="#";
  2088. var xhr = new XMLHttpRequest();
  2089. xhr.onreadystatechange = function() {
  2090. if (this.readyState == 4 && this.status == 200) {
  2091. ed.innerHTML='——';
  2092. ht = document.querySelector('#post_hint_text');
  2093. ht.innerHTML = "<?=$this->T('修改帖子:')?>"; ht.style.display='block';
  2094. rs = document.querySelector('#post_reply_restore');
  2095. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  2096. t = document.querySelector('#post_content');
  2097. t.value=xhr.responseText.trim();
  2098. t.focus();
  2099. la_auto_grow(t);
  2100. document.querySelector('#post_edit_target').value=id;
  2101. document.getElementById('post_menu').style.display='none';
  2102. }
  2103. };
  2104. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  2105. xhr.send();
  2106. }
  2107. function MarkDelete(id){
  2108. p = document.querySelector('[data-post-id="'+id+'"]');
  2109. op = p.dataset.markDelete?"false":"true";
  2110. window.location.href=
  2111. "index.php?<?=isset($_GET['post'])?('post='.$_GET['post']):""?>&mark_delete="+op+'&target='+id.toString();
  2112. }
  2113. function SetMark(mark){
  2114. menu = document.getElementById('post_menu');
  2115. window.location.href=
  2116. "index.php?<?=isset($_GET['post'])?('post='.$_GET['post']):""?>&target="+
  2117. menu.parentNode.dataset.postId+"&set_mark="+mark;
  2118. }
  2119. function ToggleMarkDetails(){
  2120. if(dmark.style.display=='block') dmark.style.display='none';
  2121. else dmark.style.display='block';
  2122. }
  2123. <?php } ?>
  2124. function ShowPostMenu(post){
  2125. menu = document.getElementById('post_menu');
  2126. menu.style.display='block';
  2127. menu.parentNode.removeChild(menu);
  2128. post.appendChild(menu);
  2129. menu.style.display='block';
  2130. id = post.dataset.postId
  2131. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  2132. ' '+id.substring(8,10)+':'+id.substring(10,12);
  2133. window.onClick="HidePopMenu()";
  2134. menu.onClick=(function(event){
  2135. event.stopPropagation();
  2136. });
  2137. <?php if($this->LoggedIn){ ?>
  2138. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  2139. menu.querySelector('#menu_refer_copy').href='javascript:CopyRefer(id)';
  2140. ed = menu.querySelector('#menu_edit')
  2141. ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  2142. d = menu.querySelector('#menu_delete');
  2143. d.href='javascript:MarkDelete(\"'+id+'\")';
  2144. p = document.querySelector('[data-post-id="'+id+'"]');
  2145. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  2146. menu.querySelector('#mark_details').dataset.id=id;
  2147. <?php } ?>
  2148. title = document.title;
  2149. copy = document.getElementById('share_copy');
  2150. copy.innerHTML='&#128203;&#xfe0e;';
  2151. copy.addEventListener("click", function(){
  2152. url = window.location
  2153. copy_text(url.protocol+"//"+url.host+"/index.php?post="+id);
  2154. this.innerHTML='&#128203;&#xfe0e;&#10003;&#xfe0e;';
  2155. });
  2156. document.getElementById('share_pin').href='https://www.pinterest.com/pin/create/button/?url='+
  2157. encodeURIComponent(window.location.href)+
  2158. //'&media='+abs_img+
  2159. '&description='+encodeURIComponent(title);
  2160. document.getElementById('share_twitter').href='http://twitter.com/share?text='+
  2161. encodeURIComponent(title)+
  2162. '&url='+window.location.href+
  2163. "&hashtags="
  2164. document.getElementById('share_weibo').href='https://service.weibo.com/share/share.php?title='+
  2165. encodeURIComponent(title)+
  2166. ': '+window.location.href
  2167. }
  2168. function HidePopMenu(){
  2169. var menus = document.querySelectorAll('.pop_menu');
  2170. [].forEach.call(menus, function(m){m.style.display='none';});
  2171. }
  2172. var posts = document.querySelectorAll('.center .post');
  2173. [].forEach.call(posts, function(p){
  2174. p.querySelector('._menu_hook').addEventListener("click", function() {
  2175. ShowPostMenu(this.parentNode.parentNode);
  2176. });
  2177. });
  2178. var post_clickables = document.querySelectorAll('.center .post a');
  2179. [].forEach.call(post_clickables, function(p){
  2180. p.addEventListener("click", function(event){
  2181. event.stopPropagation();
  2182. });
  2183. });
  2184. pushed=0;
  2185. function ShowBigImage(imgsrc,do_push){
  2186. share = document.querySelector('#big_image_share');
  2187. img = document.querySelector('#big_image');
  2188. down = document.querySelector('#image_download');
  2189. img.src = src = "images/"+imgsrc;
  2190. down.href="images/"+imgsrc;
  2191. if(do_push){PushGalleryHistory(src)}
  2192. title = document.title;
  2193. copy = document.getElementById('big_share_copy');
  2194. copy.innerHTML='&#128203;&#xfe0e;';
  2195. copy.addEventListener("click", function(){
  2196. copy_text(window.location.href);
  2197. this.innerHTML='&#128203;&#xfe0e;&#10003;&#xfe0e;';
  2198. });
  2199. document.getElementById('big_share_pin').href='https://www.pinterest.com/pin/create/button/?url='+
  2200. encodeURIComponent(window.location.href)+
  2201. '&media='+window.location.host+'/'+src+
  2202. '&description='+encodeURIComponent(title);
  2203. document.getElementById('big_share_twitter').href='http://twitter.com/share?text='+
  2204. encodeURIComponent(title)+
  2205. '&url='+window.location.href+
  2206. "&hashtags="
  2207. document.getElementById('big_share_weibo').href='https://service.weibo.com/share/share.php?title='+
  2208. encodeURIComponent(title)+
  2209. ': '+window.location.href
  2210. o = document.querySelector('#big_image_overlay');
  2211. info = document.querySelector('#big_image_info');
  2212. info.innerHTML="<?=$this->T('正在查询……')?>";
  2213. o.style.display="block";
  2214. ShowBackdrop(0.8);
  2215. var xhr = new XMLHttpRequest();
  2216. xhr.onreadystatechange = function() {
  2217. if (this.readyState == 4 && this.status == 200) {
  2218. info = document.querySelector('#big_image_info');
  2219. var response = xhr.responseText;
  2220. let content=""
  2221. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  2222. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  2223. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  2224. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  2225. content+="<div class='clean_a'>"+res[1]+"</div>";
  2226. }
  2227. info.innerHTML=content;
  2228. }
  2229. };
  2230. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  2231. xhr.send();
  2232. }
  2233. function HideBigImage(){
  2234. o = document.querySelector('#big_image_overlay');
  2235. img = document.querySelector('#big_image');
  2236. img.src = "";
  2237. o.style.display="none";
  2238. HideBackdrop();
  2239. PopGalleryHistory()
  2240. }
  2241. var images = document.querySelectorAll('img');
  2242. [].forEach.call(images, function(img){
  2243. imgid = null;
  2244. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  2245. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  2246. img.addEventListener("click", wrap(imgsrc));
  2247. });
  2248. function PopGalleryHistory(){
  2249. if(pushed){
  2250. pushed = 0;
  2251. history.back();
  2252. }
  2253. }
  2254. function PushGalleryHistory(src){
  2255. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  2256. title = "照片"
  2257. extra = "?";
  2258. sp = new URLSearchParams(window.location.search)
  2259. if(sp.has('post')){extra+="post="+sp.get('post')}
  2260. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  2261. window.history.pushState({}, 'Title', extra+'&pic='+src);
  2262. pushed = 1;
  2263. }
  2264. document.addEventListener('keydown', function(e){
  2265. large = document.getElementById('big_image_overlay')
  2266. if (large.style.display!='block') return;
  2267. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  2268. HideBigImage();
  2269. }
  2270. }, true);
  2271. window.addEventListener('popstate', (event) => {
  2272. if(event.state){
  2273. let sp = new URLSearchParams(event.state)
  2274. if(searchParams.has('pic')){
  2275. src = searchParams.get('pic')
  2276. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)) ShowBigImage(onlyimg[0], 0);
  2277. }
  2278. }else{
  2279. HideBigImage();
  2280. }
  2281. });
  2282. let searchParams = new URLSearchParams(window.location.search)
  2283. if(searchParams.has('pic')){
  2284. src = searchParams.get('pic')
  2285. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)){
  2286. ShowBigImage(onlyimg[0], 0);
  2287. }
  2288. }
  2289. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  2290. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  2291. </script>
  2292. </body>
  2293. <?php
  2294. }
  2295. }
  2296. $la = new LA;
  2297. $la->DoSiteRedirect();
  2298. $la->DoLogin();
  2299. $err = $la->ProcessRequest($message, $redirect);
  2300. $la->SwitchLanguage();
  2301. if($err){
  2302. echo $message;
  2303. exit();
  2304. }
  2305. if(isset($redirect)){
  2306. header('Location: '.$redirect);
  2307. exit();
  2308. }
  2309. $la->DetectPageType();
  2310. $la->ReadImages(false);
  2311. $la->ReadPosts();
  2312. $p = &$la->GetPost($la->CurrentPostID);
  2313. $la->MakeHeader($p);
  2314. $la->MakeMainBegin();
  2315. if($la->PageType=='extras'){
  2316. $la->MakeExtraOperations();
  2317. }else if($la->PageType=='settings'){
  2318. $la->MakeSettings();
  2319. }else if($la->PageType=='gallery'){
  2320. $la->MakeGalleryLeft();
  2321. $la->MakeGallerySection();
  2322. }else if($la->PageType=='post'){
  2323. if($p){
  2324. $la->MakeLinkedPosts($p);
  2325. $la->MakePostSection($p);
  2326. $la->MakeTOC();
  2327. }else{
  2328. echo "Post not found.";
  2329. }
  2330. }else{
  2331. $la->MakeHotPosts();
  2332. $la->MakeRecentPosts();
  2333. }
  2334. $la->MakeMainEnd();
  2335. $la->MakeFooter();
  2336. ?>