*/}}

index.php 146 KB

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