*/}}

index.php 120 KB

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