*/}}

index.php 114 KB

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