*/}}

index.php 114 KB

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