*/}}

index.php 180 KB

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