*/}}

index.php 114 KB

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