*/}}

index.php 120 KB

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