*/}}

index.php 252 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594
  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 $SelfAuthPath;
  23. protected $ExpHost;
  24. protected $ExpTitle;
  25. protected $ExpShortTitle;
  26. protected $ExpCaution;
  27. protected $ExpIndex;
  28. protected $ExpNavigation;
  29. protected $ExpFooter;
  30. protected $CommentEnabled;
  31. protected $Redirect;
  32. protected $Translations;
  33. protected $CustomTranslationContent;
  34. protected $CurrentOffset;
  35. protected $PostsPerPage;
  36. protected $HotPostCount;
  37. protected $LoggedIn;
  38. protected $LoginTokens;
  39. protected $InExperimentalMode;
  40. protected $LanguageAppendix;
  41. protected $UseRemoteFont;
  42. protected $Posts;
  43. protected $Threads; // [ keys: first last displayed count]
  44. protected $WaybackThreads;
  45. protected $Images;
  46. protected $Galleries;
  47. protected $Anchors;
  48. protected $ArchiveHandles;
  49. protected $Archive;
  50. public $WayBack;
  51. protected $YearBegin;
  52. protected $YearEnd;
  53. protected $Markers;
  54. protected $ExtraScripts;
  55. protected $TIME_STRING;
  56. protected $NULL_POST;
  57. protected $NULL_IMAGE;
  58. protected $NULL_Gallery;
  59. protected $DoneReadPosts;
  60. protected $DoneReadImages;
  61. protected $DoneReadArchive;
  62. protected $NeedWritePosts;
  63. protected $NeedWriteImages;
  64. protected $NeedWriteArchive;
  65. public $PageType;
  66. public $CurrentPostID;
  67. public $ActualPostID;
  68. public $TagID;
  69. function ReadableTime($id){
  70. $dt = DateTime::createFromFormat('YmdHis', $id);
  71. return $dt->format('Y/m/d H:i:s');
  72. }
  73. function FullURL(){
  74. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  75. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  76. $_SERVER['REQUEST_URI'];
  77. }
  78. function T($str){
  79. if(!$this->LanguageAppendix) return $str;
  80. foreach($this->Translations as $entry){
  81. if($entry['zh']==$str)
  82. return $entry[$this->LanguageAppendix];
  83. }
  84. return $str;
  85. }
  86. function SwitchLanguageAndFont(){
  87. if(isset($_COOKIE['la_language'])){
  88. $this->LanguageAppendix = $_COOKIE['la_language'];
  89. }else{
  90. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  91. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  92. $lang = substr($lang,0,5);
  93. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  94. else $this->LanguageAppendix = 'en';
  95. }
  96. }
  97. if(isset($_COOKIE['la_font'])){
  98. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  99. }
  100. }
  101. function SwitchWayBackMode(){
  102. if(isset($_COOKIE['la_wayback'])){
  103. $this->WayBack = $_COOKIE['la_wayback'];
  104. }else $this->WayBack = NULL;
  105. }
  106. function DisplayRedirectConfig(){
  107. $s = "";
  108. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  109. if($r['for']=='P'){
  110. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  111. }else if($r['for']=='S'){
  112. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  113. }
  114. }
  115. return $s;
  116. }
  117. function DoSiteRedirect(){
  118. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  119. if($r['for']=='S'){
  120. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  121. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  122. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  123. }else{
  124. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. function WriteHTACCESS(){
  131. $conf = fopen('.htaccess','w');
  132. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  133. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  134. if($r['for']=='P'){
  135. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  136. }// do site redirect in php.
  137. }
  138. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  139. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  140. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  141. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  142. fwrite($conf, 'RewriteCond %{HTTP_HOST} !^www\.'.PHP_EOL.
  143. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  144. 'RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  145. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  146. fflush($conf);fclose($conf);
  147. }
  148. function BuildRedirectConfig($conf){
  149. $this->Redirect=[];
  150. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  151. foreach($ma as $m){
  152. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  153. $this->Redirect[]=$redirect;
  154. }
  155. }
  156. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  157. foreach($ma as $m){
  158. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  159. $this->Redirect[]=$redirect;
  160. }
  161. }
  162. }
  163. function WriteTokens(){
  164. $tf = fopen('la_tokens.php','w');
  165. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  166. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  167. foreach($this->LoginTokens as $t){
  168. fwrite($tf,'- '.$t.PHP_EOL);
  169. }
  170. }
  171. fflush($tf);fclose($tf);
  172. }
  173. function WriteConfig(){
  174. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  175. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  176. if(!isset($this->Admin)) $this->Admin = 'admin';
  177. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  178. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  179. $conf = fopen('la_config.php','w');
  180. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  181. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  182. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  183. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  184. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  185. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  186. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  187. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  188. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  189. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  190. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  191. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  192. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  193. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  194. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  195. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  196. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  197. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  198. fwrite($conf,'- ExpIndex = '.$this->ExpIndex.PHP_EOL);
  199. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  200. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  201. fflush($conf);fclose($conf);
  202. $conf = fopen('la_redirect.md','w');
  203. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  204. $this->WriteHTACCESS();
  205. $this->WriteTokens();
  206. }
  207. function Install(){
  208. if(!file_exists('la_config.php')){
  209. $this->WriteConfig();
  210. }
  211. if(!is_dir('posts')) mkdir('posts');
  212. if(!is_dir('images')) mkdir('images');
  213. if(!is_dir('images/thumb')) mkdir('images/thumb');
  214. if(!is_dir('styles')) mkdir('styles');
  215. if(!is_dir('archive')) mkdir('archive');
  216. $this->WriteStyles();
  217. $this->WriteHTACCESS();
  218. }
  219. function ReadFromExistingConfig(){
  220. $f=null;
  221. if(file_exists('la_config.php')) $f='la_config.php';
  222. else if(file_exists('la_config.md')) $f='la_config.md';
  223. if(!isset($f)) return;
  224. $c = file_get_contents($f);
  225. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  226. $str = $m[1];
  227. $this->$str = $m[2];
  228. }
  229. }
  230. function ReadConfig(){
  231. $this->ReadFromExistingConfig();
  232. if(file_exists('la_redirect.md')){
  233. $c = file_get_contents('la_redirect.md');
  234. $this->BuildRedirectConfig($c);
  235. }
  236. if(!file_exists('la_config.php')){
  237. $this->Install();
  238. }
  239. $this->Translations=[];
  240. if(file_exists("translations.md")){
  241. $c = file_get_contents('translations.md');
  242. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  243. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  244. $this->Translations[] = $entry;
  245. }
  246. }
  247. if(file_exists("custom_translations.md")){
  248. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  249. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  250. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  251. $this->Translations[] = $entry;
  252. }
  253. }
  254. $this->LoginTokens=[];
  255. if(file_exists('la_tokens.php')){
  256. $c = file_get_contents('la_tokens.php');
  257. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  258. $this->LoginTokens[] = $m[1];
  259. }
  260. }
  261. }
  262. function __construct() {
  263. $this->ReadConfig();
  264. $this->PDE = new ParsedownExtra();
  265. $this->PDE->SetInterlinkPath('/');
  266. $this->Posts = [];
  267. $this->Threads = [];
  268. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  269. $this->PostsPerPage = 40;
  270. $this->CommentsPerPage = 100;
  271. $this->HotPostCount = 15;
  272. $this->TIME_STRING = date('YmdHis');
  273. $this->WayBack = NULL;
  274. $this->YearBegin = $this->YearEnd = 2000;
  275. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  276. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  277. $this->UsePosts = &$this->Posts;
  278. }
  279. function DoLogout(){
  280. $this->LoggedIn = false;
  281. unset($_SESSION['user_id']);
  282. $this->RecordToken(true);
  283. }
  284. function RecordToken($unset_current=false){
  285. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  286. $t = $_COOKIE['la_token'];
  287. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  288. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  289. $this->WriteTokens();
  290. return null;
  291. }else{
  292. $t = uniqid('la_',true);
  293. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  294. $this->LoginTokens[] = $t;
  295. $this->WriteTokens();
  296. return $t;
  297. }
  298. }
  299. function LoginThroughToken(){
  300. if(!isset($_COOKIE['la_token'])) return false;
  301. $t = $_COOKIE['la_token'];
  302. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  303. $_SESSION['user_id']=$this->Admin;
  304. $this->LoggedIn = true;
  305. setcookie('la_token',$t,time()+3600*24*7);
  306. return true;
  307. }
  308. return false;
  309. }
  310. function DoLogin(){
  311. session_start();
  312. $redirect=false;
  313. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  314. else if(!isset($_SESSION['user_id'])){
  315. if(isset($_POST['login_button'])){
  316. $id = trim($_POST['login_id']);
  317. $pwd = trim($_POST['login_password']);
  318. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  319. $_SESSION['user_id']=$id;
  320. $this->RecordToken(false);
  321. }
  322. $redirect = true;
  323. }else if($this->LoginThroughToken()){
  324. // nothing;
  325. }
  326. }else{
  327. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  328. else{ $this->DoLogout();}
  329. }
  330. if($redirect){
  331. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  332. .(isset($_GET['settings'])?"?settings=true":""));
  333. }
  334. }
  335. function WriteStyles(){
  336. $this->style="
  337. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  338. body{background-color:%white%;color:%black%;}
  339. sup,sub{line-height:0;}
  340. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  341. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  342. b,strong,th{font-weight:bold;}
  343. select{font-size:inherit;}
  344. .page,.page_gallery{padding:1em;padding-top:0;}
  345. .hidden_on_desktop,.hidden_on_wide{display:none;}
  346. .hidden_on_desktop_force{display:none !important;}
  347. ::file-selector-button{background:none;border:none;}
  348. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  349. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  350. .button:disabled{background-color:%gray%;pointer-events:none;}
  351. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;max-height:100vh;z-index:30;}
  352. header::before{content:'';position:absolute;left:0;right:0;top:0;height:1.95em;box-shadow:-2em 0em 1em -1em inset %white%;pointer-events:none;}
  353. header>div{overflow:auto;white-space:nowrap;}
  354. .header_nav{display:inline;}
  355. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  356. header a:hover,.button:hover{color:%gray% !important;}
  357. .footer{background-color:%white%;z-index:10;position:relative;}
  358. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  359. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  360. .gray,.gray a{color:%gray%;}
  361. hr{border:1px solid %gray%;}
  362. header ul{display:inline-block;}
  363. header li{display:inline-block;}
  364. header li::before{content:' - '}
  365. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  366. .main{position:relative;word-spacing:-1em;}
  367. .main *{word-spacing:initial;}
  368. pre{overflow:auto;max-width:100%;display:block;font-size:0.75em;}
  369. ul{display:block;}
  370. li{display:block;}
  371. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  372. table input{border:none!important;}
  373. table img{max-width:10rem !important;}
  374. td{padding-left:0.1em;padding-right:0.1em;}
  375. td:first-child{padding-left:0;}
  376. td:last-child{padding-right:0;}
  377. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  378. thead{box-shadow:inset 0 -1px 0 0px %black%;position:sticky;top:2rem;background-color:%white%;z-index:5;}
  379. .post table{font-size:0.85em;}
  380. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  381. .interesting_tbody td{display:contents;}
  382. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  383. .interesting_tbody td>*{display:table-cell;}
  384. .interesting_tbody td>.wscroll{display:none !important;}
  385. .interesting_tbody .post_access{padding-top:0;}
  386. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  387. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  388. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  389. .interesting_tbody td>.imd>a{display:flex;}
  390. .interesting_tbody img{object-fit:cover;width:100%;}
  391. .interesting_tbody .p_row{display:flex;position:absolute;left:1.4em;top:0.25em;z-index:-1;flex-wrap:nowrap;max-width:calc(100% - 1.4em);}
  392. .interesting_tbody .p_thumb{height:1em;}
  393. .interesting_tbody .p_thumb img{max-height:10rem !important;max-width:20rem !important;}
  394. tr:hover .post_menu_button{opacity:1;}
  395. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  396. .align_right{text-align:right;}
  397. .left{display:inline-block;vertical-align:top;width:25%;max-height:calc(100vh - 2.6em);top:2em;
  398. position:sticky;overflow:auto;padding-right:0.2em;padding-bottom:4rem;}
  399. .center{display:inline-block;vertical-align:top;width:50%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  400. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  401. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  402. .center_wide .p_thumb{height:10rem;}
  403. .sticky_title{position:sticky;top:1.35em;z-index:1;box-shadow:6em 3.5em 0.75em -3em inset %white%;pointer-events:none;}
  404. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  405. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  406. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  407. .right{display:inline-block;vertical-align:top;width:25%;position:sticky;top:2em;
  408. padding-left:0.5em;max-height:calc(100vh - 2.6em);overflow:auto;padding-bottom:4rem;}
  409. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  410. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  411. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  412. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  413. .post{position:relative;scroll-margin:3.5em;border-radius:0.3em;}
  414. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;border-radius:0;}
  415. .post_width li,.post_width_big li,.footer_additional li,.footer_additional li,.post_dummy li
  416. {display:list-item;margin-left:1em;list-style:disc;}
  417. .post_width li li,.post_width_big li li,.footer_additional li li,.footer_additional li li,.post_dummy li li{list-style:circle;}
  418. .post_width > *,.post_width_big > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  419. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  420. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  421. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  422. .gallery_left .selected{list-style:'→';}
  423. .focused_post{font-size:1.1em;margin-top:0.1em;margin-bottom:0.1em;padding:0.5rem !important;border:2px dashed #ac7843;}
  424. .post_width{position:relative;left:1.4rem;width:calc(100% - 1.7rem);padding-left:0.2em;overflow:visible;}
  425. .post_width_big{position:relative;left:0;width:100%;overflow:visible;}
  426. .post_menu_button{position:absolute;display:none;right:0rem;width:1.5rem;
  427. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;}
  428. .pointer{cursor:pointer;}
  429. .post:hover .post_menu_button{display:block;}
  430. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%lighterbkg%;
  431. padding:0.3em;right:0.3rem;text-align:right;border-radius:0.3em;font-size:1rem;
  432. box-shadow:0px 0px 10px rgb(0, 0, 0);}
  433. .pop_menu li{list-style:none;margin-left:0;}
  434. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  435. .toc{left:60%;width:40%;top:0;position:absolute;}
  436. .post_access{width:1.4rem;top:0;position:absolute;height:100%;text-align:center;font-weight:bold;border-right:2px solid transparent;user-select:none;}
  437. .post_access:hover{background-color:%lightopbkg%;border-top-left-radius:0.3em;border-bottom-left-radius:0.3em;
  438. border-right:2px solid %black% !important;}
  439. .paa{width:1.4rem;min-width:1.4rem;}
  440. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;}
  441. .post_box{border:1px solid %gray%;border-radius:0.3em;padding:0.3em;}
  442. .post_box:hover,.post_menu_button:hover{background-color:%lightopbkg%}
  443. #big_image_info .post_box:hover{background-color:%graybkg%;}
  444. .post_preview{font-size:0.9rem;overflow:hidden;margin-bottom:0.2em;}
  445. .post .post_ref{margin:0;padding-left:1.7rem;}
  446. .post_ref_main{display:inline-block;vertical-align:top;}
  447. .post_preview .post_ref_main{max-height:6rem;overflow:hidden;}
  448. .post_ref_images{overflow:hidden;}
  449. .page_selector{padding-top:2rem;text-align:center;}
  450. .smaller{font-size:0.85em;}
  451. .bigger{font-size:1.3em;}
  452. .block{display:block;}
  453. .opt_compact{margin-left:1.6rem;}
  454. .opt_compact .post_width {margin-left:0.3em;width: calc(100% - 1.8rem);}
  455. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  456. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  457. .spacer{height:0.5em;}
  458. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  459. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  460. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  461. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  462. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  463. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  464. .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;}
  465. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  466. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  467. .toc_entry_1{font-size:1.1em;}
  468. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  469. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  470. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  471. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  472. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  473. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  474. .deleted_post{color:%gray%;text-decoration:line-through;}
  475. #file_list{margin-top:0.5em;}
  476. .file_thumb img{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  477. #file_list li{margin-bottom:0.3em;}
  478. .ref_thumb{white-space:nowrap;overflow:hidden;}
  479. .ref_thumb .file_thumb{width:3em;height:3em;}
  480. .side_thumb li{margin:0.4em;display:inline-block;}
  481. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  482. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  483. .p_thumb{display:flex;flex-grow:1;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  484. .p_thumb_narrow{width:1rem;}
  485. .p_thumb img{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  486. .ref_count,.p_thumb .post_menu_button{text-shadow: 0px 0px 10px rgb(0, 0, 0);}
  487. .p_thumb:hover .post_menu_button{display:block;}
  488. .p_thumb_selected{color:%black% !important;}
  489. .p_thumb_selected{display:block;}
  490. .post .p_thumb img{max-height:6rem;}
  491. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  492. .big_image_box *{pointer-events:auto;}
  493. .big_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  494. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;
  495. background:linear-gradient(to right, rgba(0,0,0,0), rgb(1, 1, 1));transition:background-size .2s linear;background-size: 300% 100%;}
  496. .big_side_box:hover{background-size: 100% 100%;}
  497. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  498. .big_side_box a:hover{color:%gray%;}
  499. #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;
  500. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  501. img{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  502. .post img{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  503. .post > a > img{display:block;margin:0.3em auto;}
  504. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  505. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  506. .center_exp .post .original_img{display:block;}
  507. .original_img img{max-height:90vh;max-width:100%;}
  508. .p_row .original_img{margin-bottom:0;}
  509. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  510. .b ul{font-size:1.4em;}
  511. no_pop{cursor:unset;}
  512. p{min-height:0.8em;}
  513. .bold,.bold *{font-weight:bold;}
  514. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  515. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;}
  516. .small_footer>div{overflow:auto;white-space:nowrap;}
  517. .small_footer::before{content:'';position:absolute;left:0;right:0;bottom:0;height:1.95em;box-shadow:-2em 0em 1em -1em inset %white%;pointer-events:none;}
  518. .top_post_hint{margin-left:1.5em;font-weight:bold;}
  519. .white{color:%white%;}
  520. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  521. .image_nav_prev,.image_nav_next{z-index:100;position:absolute;line-height:0;height:100%;width:20%;display:flex;align-items:center;
  522. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  523. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.2));
  524. background-repeat:no-repeat;background-size:0% 100%;}
  525. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  526. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  527. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  528. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  529. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  530. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  531. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  532. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  533. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  534. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  535. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  536. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  537. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  538. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  539. .special_paypal_inner{color:#169bd7;}
  540. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  541. animation:anim_loading 1s linear infinite;}
  542. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  543. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  544. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  545. .product_thumb img{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  546. .product_ref p{margin-bottom:0.2em;text-align:left;}
  547. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  548. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  549. .page_break{page-break-after:always;}
  550. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  551. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  552. .print_title{display:none;}
  553. .show_on_print{display:none;}
  554. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  555. .comment tbody tr:hover{box-shadow:none;}
  556. .comment table{border:none;}
  557. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  558. .comment ul{padding-left:1em;}
  559. .comment ul li *{margin-bottom:0.5em;}
  560. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  561. .history li li{list-style:circle;}
  562. .history ul{padding-left:1em;}
  563. .history a{text-decoration:underline;}
  564. .history .list{overflow:auto;white-space:nowrap;}
  565. .diff_table{table-layout:fixed;}
  566. .diff_table thead{font-size:0.9em;text-align:center;}
  567. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  568. .diff_table td{vertical-align:top;}
  569. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  570. .wayback_close{float:right;}
  571. .wayback_expand{display:inline;}
  572. .post_selecting .post *{pointer-events:none;}
  573. .post_selected{background-color:%graybkg%;}
  574. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  575. .wscroll{scroll-margin:3.5em;padding-left:0.3em;display:none;font-weight:bold;font-size:0.75em;box-shadow: 13em 0em 4em -8em inset %gray%;color:%white%;}
  576. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  577. .wayback_link{display:inline;}
  578. .imd{object-fit:cover;width:100%;}
  579. .center_exp .imd{width:60%;}
  580. @media screen and (max-width:1000px) and (min-width:666px){
  581. .left{width:35%;}
  582. .center,.center_wide{width:65%;}
  583. .center_wide .p_thumb{height:8rem;}
  584. .right{display:none;}
  585. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  586. .post_width_big{left:0;width:100%;}
  587. .hidden_on_wide{display:unset;}
  588. .hidden_on_narrow{display:none;}
  589. .pop_right{width:30%;}
  590. .pop_right_big{width:40%;}
  591. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  592. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  593. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  594. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  595. .big_side_box{width:35%;}
  596. .big_image_box{width:65%;}
  597. .inquiry_buttons{right:35%;}
  598. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  599. .post_dummy > *{width:80%;max-width:55rem;}
  600. .center_exp .imd{width:80%;}
  601. }
  602. @media screen and (max-width:666px){
  603. html{font-size:16px;}
  604. .hidden_on_mobile{display:none !important;}
  605. .block_on_mobile{display:block !important;}
  606. .hidden_on_desktop{display:unset;}
  607. header ul{display:block;}
  608. header li{display:block;}
  609. header li::before{content:''}
  610. header::before{box-shadow:none;display:none;}
  611. .small_footer::before{box-shadow:none;display:none;}
  612. .left{position:relative;width:100%;position:relative;top:unset;height:unset;min-height:80vh;padding-right:0;display:block;}
  613. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  614. .center_wide .p_thumb{height:6rem;}
  615. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  616. .pop_right{height:30%;}
  617. .pop_right_big{height:70%;}
  618. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  619. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  620. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  621. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  622. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  623. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  624. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  625. .side_box_mobile_inner:hover{background-size:100% 100%;}
  626. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  627. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  628. .p_thumb{height:3rem;}
  629. .center .post{padding-right:0rem;padding-left:0rem;}
  630. .post .p_thumb img{max-height:3rem;}
  631. .page,.page_gallery{padding:0.2em;padding-top:0;}
  632. header{padding-top:0.3em;}
  633. .small_footer{padding-bottom:0.3em;}
  634. .footer_additional{display:block;width:100%;}
  635. .album_hint{display:block;font-size:1rem;}
  636. .image_nav{position:absolute !important;}
  637. .image_nav_prev,.image_nav_next{width:25%;}
  638. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  639. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  640. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  641. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  642. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  643. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  644. .opt_compact,.ref_compact{line-break:anywhere;}
  645. .post_width,.post_width_big{overflow:auto;}
  646. .table_top{left:unset;width:100%;overflow:auto;}
  647. table img{max-width:30vw !important;}
  648. .product_ref{width:100%;display:block;}
  649. .post_dummy > *{width:100%;max-width:25rem;}
  650. .sticky_title{top:1.2em;}
  651. .small_footer{position:relative;}
  652. #upload_selector{width:100%;}
  653. .focused_post{padding:0.3rem !important;}
  654. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  655. .wayback_expand{display:block;text-align:center;}
  656. .wayback_link{display:block;}
  657. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  658. .center_exp .post{overflow:auto;}
  659. .center_exp .imd{width:100%;}
  660. }
  661. @media print{
  662. header::before{box-shadow:none;display:none;}
  663. .small_footer::before{box-shadow:none;display:none;}
  664. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  665. .post *,.post_dummy *{margin-bottom:0em}
  666. .p_row,.post table,.post_width>img,.post_width_big>img,.post_ref>img,.post_ref>.original_img,
  667. .post_width>.original_img,.post_width_big>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  668. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  669. table img{margin:0 !important;}
  670. .post h1+p,.post h2+p,.post img+p,.post table+p,.post p:first-child{text-indent:0;}
  671. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  672. table{border-bottom:2px solid black;border-top:2px solid black;}
  673. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  674. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  675. .post_width,.post_width_big{overflow:clip;left:0;width:100%;padding-left:0em;}
  676. .post h1{margin-top:0.5rem;}
  677. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  678. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  679. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  680. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  681. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  682. .left,.right{display:none;}
  683. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  684. hr{border:1px solid black;}
  685. .post_box_top{display:none;}
  686. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;}
  687. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  688. .focused_post{border:none;font-size:1em;padding:0 !important;}
  689. .hidden_on_print{display:none;}
  690. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  691. .post_access{display:none;}
  692. .opt_compact{margin-left:0;}
  693. .post .post_ref{padding-left:1.4rem;}
  694. .opt_compact .post_width{left:1.4rem;width:calc(100% - 1.4rem);margin-left:0;}
  695. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  696. .print_title:first-of-type{margin-top:1em;}
  697. .print_title+.post h1:first-of-type{display:none;}
  698. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  699. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  700. .header_nav{display:none;}
  701. .show_on_print{display:block;}
  702. blockquote{border-left:2px solid black;}
  703. .footer_additional{display:none;}
  704. .small_footer{margin-top:1rem;}
  705. .page_selector{display:none;}
  706. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  707. .post .p_thumb img{max-height:4rem;}
  708. .sticky_title{box-shadow:none;}
  709. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  710. .center_wide .p_row{display:block;}
  711. .interesting_tbody{background:none;}
  712. .interesting_tbody img{display:none !important;}
  713. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  714. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  715. }
  716. ";
  717. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  718. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  719. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  720. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  721. $this->style=preg_replace('/%lightopbkg%/','#daae8010',$this->style);
  722. $this->style=preg_replace('/%lighterbkg%/','#675340',$this->style);
  723. $this->style=preg_replace('/%focusedbkg%/','#482f0c',$this->style);
  724. $f = fopen('styles/main.css','w');
  725. fwrite($f,$this->style);
  726. fclose($f);
  727. }
  728. function GiveSafeEMail(){
  729. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  730. }
  731. function &FindImage($name){
  732. if(isset($this->Images[0]))foreach($this->Images as &$im){
  733. if($im['name']==$name) return $im;
  734. }
  735. return $this->NULL_IMAGE;
  736. }
  737. function ReadImages($clear_non_exist = false){
  738. $path = 'images/list.md';
  739. if($this->DoneReadImages){ return; }
  740. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  741. $c = file_get_contents($path);
  742. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  743. $g=[]; $g['name']=$m[1];//$g['count']=0;
  744. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  745. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  746. $this->Galleries[] = $g;
  747. }
  748. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  749. $name = trim($m[1]);
  750. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  751. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  752. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  753. $item['refs']=[];
  754. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  755. }
  756. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  757. $item['galleries']=[];
  758. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  759. }
  760. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){
  761. $item['product']=$product[1];
  762. }
  763. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){
  764. $item['parent']=$parent[1];
  765. }
  766. $this->Images[] = $item;
  767. }
  768. $files = array_merge([],glob('images/*.jpg'));
  769. $files = array_merge($files,glob('images/*.jpeg'));
  770. $files = array_merge($files,glob('images/*.png'));
  771. $files = array_merge($files,glob('images/*.gif'));
  772. if(isset($files[0]))foreach($files as $file) {
  773. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png)/u', $file, $m)) {
  774. $name = trim($m[0]);
  775. if(!$this->FindImage($name)){
  776. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  777. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  778. $this->Images[] = $item;
  779. }
  780. }
  781. }
  782. if($clear_non_exist){
  783. if(isset($this->Images[0]) && isset($files[0])){
  784. foreach($this->Images as &$im){
  785. if(!in_array($im['file'],$files)){
  786. $im['deleted'] = 1;
  787. }
  788. }
  789. }
  790. }
  791. function cmpf($a, $b){
  792. if ($a['name'] == $b['name']) return 0;
  793. return (($a['name'] > $b['name']) ? 1 : -1);
  794. }
  795. function cmpaf($a, $b){
  796. if ($a['name'] == $b['name']) return 0;
  797. return ($a['name'] > $b['name']) ? -1 : 1;
  798. }
  799. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  800. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  801. $this->DoneReadImages = 1;
  802. }
  803. function WriteImages(){
  804. if(isset($this->WayBack)) return;
  805. $path = 'images/list.md';
  806. $f = fopen($path,'w');
  807. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  808. if(isset($g['deleted'])) continue;
  809. fwrite($f,'GALLERY '.$g['name']);
  810. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  811. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  812. fwrite($f, PHP_EOL);
  813. }
  814. if(isset($this->Images[0]))foreach($this->Images as &$im){
  815. if(isset($im['deleted'])) continue;
  816. fwrite($f, "- ".$im['name'].'; ');
  817. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  818. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  819. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  820. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  821. fwrite($f, PHP_EOL);
  822. }
  823. fflush($f);
  824. fclose($f);
  825. }
  826. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL){
  827. if(!($im = &$this->FindImage($name))) return;
  828. if(isset($link_gallery)){
  829. if($do_remove){
  830. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  831. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  832. $im['galleries'] = array_merge($im['galleries']);
  833. }else{
  834. if(!isset($im['galleries'])) $im['galleries']=[];
  835. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  836. $im['galleries'][]=$link_gallery;
  837. }
  838. }
  839. if(isset($product_link)){
  840. if($product_link!=''){$im['product']=$product_link;}
  841. else{unset($im['product']);}
  842. }
  843. if(isset($rename) && $rename!=$im['name']){
  844. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  845. rename($im['file'], 'images/'.$rename.'.'.$ext);
  846. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  847. $im['name'] = $rename.'.'.$ext;
  848. }
  849. if(isset($parent) && $parent!=$im['parent']){
  850. if($parent==''){ unset($im['parent']); }
  851. else{ $im['parent'] = $parent; }
  852. }
  853. $this->NeedWriteImages = 1;
  854. }
  855. function RegenerateThumbnails(){
  856. $glob = glob('images/*.jpg');
  857. if(!is_dir('images/thumb')) mkdir('images/thumb');
  858. foreach($glob as $file) {
  859. $thumb_destination = 'images/thumb/'.basename($file);
  860. $img = new Imagick($file); $geo=$img->getImageGeometry();
  861. $width=$geo['width']; $height=$geo['height'];
  862. $lim=400;
  863. $scale = $lim / min($width,$height);
  864. if($scale<1){
  865. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  866. }
  867. $img->setImageFormat('jpeg');
  868. $img->setImageCompressionQuality(90);
  869. $img->writeImage($thumb_destination);
  870. }
  871. }
  872. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max) {
  873. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  874. $width=$geo['width']; $height=$geo['height'];
  875. $lim=400;
  876. $scale = $lim / min($width,$height);
  877. if($scale<1){
  878. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  879. }
  880. $img->setImageFormat('jpeg');
  881. $img->setImageCompressionQuality($quality);
  882. $img->writeImage($thumb_destination);
  883. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  884. if($scale<1){
  885. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  886. }
  887. $img2->setImageFormat('jpeg');
  888. $img2->setImageCompressionQuality($quality);
  889. $img2->writeImage($destination);
  890. }
  891. function DoUpload(){
  892. if(!isset($_FILES['upload_file_name'])) return 0;
  893. if(!is_dir('images/thumb')) mkdir('images/thumb');
  894. if($_FILES['upload_file_name']['error']>0){
  895. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  896. return -1;
  897. }else{
  898. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  899. if(!in_array($ext,['jpg','jpeg','png','gif'])) return 0;
  900. $fp = fopen('.la_lock',"w");
  901. while (!flock($fp, LOCK_EX| LOCK_NB)){
  902. usleep(10000);
  903. }
  904. $num=date('YmdHis'); $replace=0;
  905. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  906. $num = $mim[1]; $replace=1;
  907. }
  908. $base = 'images/'.$num;
  909. $thumb = 'images/thumb/'.$num;
  910. if($ext=='png') $ext='jpg';
  911. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  912. if(!$replace) while(file_exists($final_path)){
  913. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  914. }
  915. if($ext!='gif'){
  916. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  917. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  918. $compress?800:1920, $compress?1920:2560);
  919. }else{
  920. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  921. }
  922. flock($fp, LOCK_UN);
  923. fclose($fp);
  924. $this->ReadImages(true);
  925. $this->WriteImages();
  926. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  927. if(isset($_POST['image_replace_button'])){
  928. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  929. }
  930. exit;
  931. return 1;
  932. }
  933. return 0;
  934. }
  935. function &GetGallery($name){
  936. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  937. if($g['name'] == $name) return $g;
  938. }
  939. return $this->NULL_GALLERY;
  940. }
  941. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  942. $this->ReadImages();
  943. $gallery = &$this->GetGallery($name);
  944. if(!isset($gallery)){
  945. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  946. $g = []; $g['name']=$new_name;
  947. $this->Galleries[]=$g;
  948. }else{
  949. if(isset($new_name)) {
  950. if(preg_match('/main|trash|\s/u',$new_name))return;
  951. $gallery['name'] = $new_name;
  952. foreach ($this->Images as &$im){
  953. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  954. if($g == $name){ $g = $new_name; }
  955. }
  956. }
  957. }
  958. //if(isset($count)) $gallery['count'] = $count;
  959. if(isset($delete) && $delete) $gallery['deleted'] = true;
  960. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  961. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  962. }
  963. if($do_rw) { $this->NeedWriteImages = 1; }
  964. }
  965. function ClearData(){
  966. $this->Posts = [];
  967. $this->Threads = [];
  968. $this->Images = [];
  969. $this->Archive = [];
  970. $this->ArchiveHandles = [];
  971. }
  972. function InsertArchivePost(&$post){
  973. $a = NULL;
  974. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  975. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  976. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  977. }
  978. $a['list'][] = $post;
  979. $this->Archive[] = $post;
  980. }
  981. function ReadArchiveFromFile($path){
  982. if(!file_exists($path)){
  983. return;
  984. }
  985. $c = file_get_contents($path);
  986. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  987. foreach($matches as $m){
  988. $post = [];
  989. $post['id'] = $m[1];
  990. $post['content'] = trim($m[3]);
  991. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  992. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  993. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  994. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  995. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  996. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  997. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  998. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  999. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1000. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1001. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1002. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1003. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1004. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1005. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1006. }
  1007. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1008. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1009. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1010. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1011. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1012. }
  1013. $this->InsertArchivePost($post);
  1014. }
  1015. }
  1016. }
  1017. function SortArchive(){
  1018. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1019. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1020. return (($a['id'] > $b['id']) ? 1 : -1);
  1021. };
  1022. if(isset($this->Archive[0])){
  1023. usort($this->Archive,$cmpap);
  1024. $year_begin = substr($this->Archive[0]['id'],0,4);
  1025. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1026. }
  1027. if(isset($this->ArchiveHandles[0])){
  1028. usort($this->ArchiveHandles,$cmpac);
  1029. foreach($this->ArchiveHandles as &$a){
  1030. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1031. $last_valid=NULL;
  1032. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1033. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1034. else{ $last_valid = $ver['content']; } }
  1035. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1036. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1037. }
  1038. }
  1039. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1040. $p['archive'] = &$a;
  1041. }
  1042. }
  1043. }
  1044. }
  1045. function ReadPostsFromFile($path){
  1046. if(!file_exists($path)){
  1047. $f = fopen($path,'w');
  1048. fclose($f);
  1049. }
  1050. $c = file_get_contents($path);
  1051. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1052. foreach($matches as $m){
  1053. $post = [];
  1054. $post['id'] = $m[1];
  1055. $post['real_content'] = trim($m[3]);
  1056. $post['content'] = &$post['real_content'];
  1057. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1058. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1059. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1060. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1061. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1062. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1063. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1064. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1065. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1066. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1067. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1068. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1069. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1070. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1071. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1072. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1073. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1074. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1075. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1076. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1077. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1078. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1079. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1080. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1081. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1082. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1083. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1084. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1085. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1086. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1087. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1088. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1089. }
  1090. if(isset($post['mark_value']) && $post['mark_value']==5){
  1091. $post['product']=[];
  1092. }
  1093. /* marks add here */
  1094. $this->Posts[] = $post;
  1095. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1096. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1097. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1098. }
  1099. }
  1100. }
  1101. }
  1102. function SortPosts($wayback=false){
  1103. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1104. $sortlist = &$this->Posts;
  1105. if($wayback) $sortlist = &$this->WaybackPosts;
  1106. if(isset($sortlist[0])){
  1107. usort($sortlist,$cmpp);
  1108. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1109. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1110. }
  1111. }
  1112. function ReadPosts(){
  1113. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1114. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1115. (!is_dir('posts') || is_readable('posts') == false) ||
  1116. (!is_dir('archive') || is_readable('archive') == false) ||
  1117. (!is_dir('images') || is_readable('images') == false) ||
  1118. (!is_dir('styles') || is_readable('styles') == false)){
  1119. $this->Install();
  1120. }
  1121. if($this->DoneReadPosts){ return; }
  1122. $file_list = [];
  1123. $glob = glob('posts/*');
  1124. foreach($glob as $file) {
  1125. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1126. $file_list[] = $file;
  1127. }
  1128. }
  1129. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1130. foreach($file_list as $f) {
  1131. $this->ReadPostsFromFile($f);
  1132. }
  1133. $this->SortPosts();
  1134. $this->DetectThreads();
  1135. $this->DoneReadPosts=1;
  1136. }
  1137. function UpdatePostRefsForWayback(){
  1138. if(!isset($this->WayBack)) return;
  1139. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1140. if(!isset($this->WaybackPosts[0])) return;
  1141. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1142. foreach($this->WaybackPosts as &$p){
  1143. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1144. $pr = &$this->GetPost($r); if(isset($pr)){
  1145. if(!isset($pr['refs'])) $pr['refs']=[];
  1146. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1147. }
  1148. }
  1149. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1150. $ir = &$this->FindImage($r); if(isset($ir)){
  1151. if(!isset($ir['refs'])) $ir['refs']=[];
  1152. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1153. }
  1154. }
  1155. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1156. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1157. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1158. }
  1159. }
  1160. }
  1161. function ReadArchive(){
  1162. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1163. if ($this->DoneReadArchive) return;
  1164. $file_list = []; $glob = glob('archive/*');
  1165. foreach($glob as $file) {
  1166. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1167. $file_list[] = $file;
  1168. }
  1169. }
  1170. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1171. foreach($file_list as $f) {
  1172. $this->ReadArchiveFromFile($f);
  1173. }
  1174. $this->SortArchive();
  1175. $this->DoneReadArchive=1;
  1176. $this->UpdateThreadForWayback();
  1177. $this->UpdatePostRefsForWayback();
  1178. }
  1179. function GetThreadForPost(&$post){
  1180. if(isset($post['tid'])) return;
  1181. $th = []; $iterp = NULL;
  1182. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1183. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1184. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1185. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1186. $np['tid'] = &$th;
  1187. $th['first'] = &$np;
  1188. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1189. }
  1190. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1191. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1192. $np['tid'] = &$th;
  1193. $th['last'] = &$np;
  1194. $iterp = isset($np['next'])?$np['next']:NULL;
  1195. }
  1196. if(isset($th['first']['mark_value'])){
  1197. if($th['first']['mark_value']==6) $th['exp'] = true;
  1198. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1199. }
  1200. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1201. $this->Threads[] = &$th;
  1202. }
  1203. function IdentifyThreadCategory(&$th,&$first_post){
  1204. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1205. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1206. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1207. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1208. }
  1209. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1210. }
  1211. if(isset($th) && preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1212. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1213. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1214. }
  1215. }
  1216. if(isset($th) && preg_match('/\{\s*REVERSED\s*\}/imu',$first_post['content'],$m)){
  1217. $th['reversed'] = true;
  1218. }
  1219. }
  1220. function IsInterestingPost(&$p){
  1221. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1222. return false;
  1223. }
  1224. function IsReversedThread(&$th){
  1225. if(isset($th['reversed']) && $th['reversed']) return true;
  1226. return false;
  1227. }
  1228. function GiveAllMergedPosts(&$po,&$arr){
  1229. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1230. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1231. }
  1232. if(isset($po['archive']) && isset($po['archive']['list'])){
  1233. foreach($po['archive']['list'] as &$ver){
  1234. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1235. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1236. }
  1237. }
  1238. }
  1239. function ThreadMakeWayback(&$th){
  1240. if(!isset($th['arr'][0])) return;
  1241. if(isset($this->WayBack)){
  1242. $remlist = [];
  1243. foreach($th['arr'] as &$pi){
  1244. $po = &$this->GetPost($pi['id'],true);
  1245. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1246. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1247. }
  1248. $ah = &$this->GetArchiveHandle($po['id']);
  1249. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1250. if(!isset($ver['merged_thread'])) continue;
  1251. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1252. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1253. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1254. }
  1255. }
  1256. }
  1257. if(isset($remlist[0]) && isset($th['arr'][0])){
  1258. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1259. foreach($th['arr'] as $key => $pr){
  1260. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1261. $new_th = []; $new_arr = [];
  1262. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1263. $new_th['arr'] = &$new_arr;
  1264. $this->WaybackThreads[] = &$new_th;
  1265. $this->ThreadMakeWayback($new_th);
  1266. }
  1267. }
  1268. }
  1269. function AddMergedPosts(&$p, &$array){
  1270. if(isset($p['archive']) && isset($p['archive']['list'])){
  1271. foreach($p['archive']['list'] as &$ver){
  1272. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1273. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1274. }
  1275. }
  1276. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1277. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1278. }
  1279. function FinalizeThread(&$th, $relink_posts=false, $now){
  1280. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1281. if(!isset($th['arr'])){
  1282. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1283. $arr[]=&$p;
  1284. } $th['arr'] = &$arr;
  1285. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1286. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1287. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1288. $arr=&$new_arr; $th['arr']=&$new_arr;
  1289. $this->ThreadMakeWayback($th); }
  1290. }
  1291. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1292. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1293. if($relink_posts){ $count = $th['count'];
  1294. $arr = &$th['arr'];
  1295. for($i=0; $i<$count; $i++){ if($i>0) $arr[$i]['prev'] = $arr[$i-1]['id']; if($i<$count-1) $arr[$i]['next'] = $arr[$i+1]['id'];
  1296. $arr[$i]['tid']=&$th;}
  1297. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1298. }
  1299. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1300. $this->IdentifyThreadCategory($th, $th['first']);
  1301. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1302. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1303. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1304. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1305. }
  1306. function SortThreads(){
  1307. if (!function_exists('cmpt')) {
  1308. function cmpt($a, $b){
  1309. if ($a['score'] == $b['score']) return 0;
  1310. return ($a['score'] > $b['score']) ? -1 : 1;
  1311. }
  1312. }
  1313. usort($this->Threads,"cmpt");
  1314. }
  1315. function DetectThreads(){
  1316. foreach($this->Posts as &$p){
  1317. if(isset($p['tid'])) { continue; }
  1318. $this->GetThreadForPost($p);
  1319. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1320. }
  1321. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1322. $now = date_timestamp_get(date_create());
  1323. foreach($this->Threads as &$t){
  1324. $this->FinalizeThread($t,false,$now);
  1325. }
  1326. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1327. $this->FinalizeThread($th,false,$now);
  1328. $this->Threads[] = &$th;
  1329. }
  1330. $this->SortThreads();
  1331. }
  1332. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1333. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1334. foreach($this->Threads as &$t){
  1335. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1336. }
  1337. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1338. $this->FinalizeThread($th,true,$now);
  1339. $this->Threads[] = &$th;
  1340. }
  1341. $this->SortThreads();
  1342. $this->SortPosts(true);
  1343. $this->UsePosts = &$this->WaybackPosts;
  1344. }
  1345. function &GetMergedPost($id){
  1346. $this->ReadArchive();
  1347. $ah = &$this->GetArchiveHandle($id);
  1348. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1349. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1350. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1351. [$tp, $tver] = $ver['merged_into'];
  1352. if(isset($this->WayBack)){
  1353. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1354. else return $this->GetPost($id); /* should not happen directly. */
  1355. }
  1356. return $this->GetMergedPost($tp);
  1357. }
  1358. function &GetPost($id, $latest_only=false, $find_merged=false){
  1359. if(!isset($id)) return $this->NULL_POST;
  1360. $found=&$this->NULL_POST;
  1361. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1362. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1363. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1364. }
  1365. if($latest_only || !isset($this->WayBack)){ return $found; }
  1366. else{
  1367. if(isset($found)){
  1368. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1369. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1370. $last_ver = &$this->NULL_POST;
  1371. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1372. if($ver['version'] > $this->WayBack) return $last_ver;
  1373. $last_ver = &$ver;
  1374. }
  1375. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1376. else return $last_ver;
  1377. }else{
  1378. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1379. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1380. if($ver['version'] > $this->WayBack) return $last_ver;
  1381. $last_ver = &$ver;
  1382. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1383. [$tp, $tver] = $last_ver['merged_into'];
  1384. if($tver <= $this->WayBack) {
  1385. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1386. return $last_ver;
  1387. }
  1388. }
  1389. }
  1390. return $this->NULL_POST;
  1391. }
  1392. function &GetArchiveHandle($id){
  1393. if(!isset($id)) return $this->NULL_POST;
  1394. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1395. if($p && $p['id'] == $id) { return $p; }
  1396. }
  1397. return $this->NULL_POST;
  1398. }
  1399. function &GetArchive($id){
  1400. if(!isset($id)) return $this->NULL_POST;
  1401. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1402. if($p && $p['id'] == $id) { return $p; }
  1403. }
  1404. return $this->NULL_POST;
  1405. }
  1406. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1407. if(!isset($ah)) return $this->NULL_POST;
  1408. $found = NULL; $last_verp=NULL;
  1409. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1410. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1411. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1412. $last_verp = &$p;
  1413. }
  1414. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1415. return $this->NULL_POST;
  1416. }
  1417. function CacheArchiveOwnLinks(){
  1418. if(isset($this->WayBack)) return;
  1419. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1420. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1421. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1422. foreach($matches as $m){
  1423. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1424. }
  1425. }
  1426. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1427. foreach($matches as $m){
  1428. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1429. }
  1430. }
  1431. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1432. foreach($matches as $m){
  1433. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. function WriteArchive(){
  1439. if(isset($this->WayBack)) return;
  1440. $cf = NULL;$opened =NULL;
  1441. $this->SortArchive();
  1442. $this->CacheArchiveOwnLinks();
  1443. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1444. $nid = substr($p['id'], 0,6);
  1445. if($cf != $nid){
  1446. if($opened){
  1447. fflush($opened);
  1448. fclose($opened);
  1449. }
  1450. $cf = $nid;
  1451. $opened = fopen("archive/$cf.md", 'w');
  1452. }
  1453. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1454. "VER {$p['version']}; ".
  1455. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1456. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1457. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1458. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1459. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1460. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1461. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1462. ']';
  1463. if(isset($p['merged_thread'])){ $p['content']=""; }
  1464. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1465. }
  1466. }
  1467. function WritePosts(){
  1468. if(isset($this->WayBack)) return;
  1469. $cf = NULL;$opened =NULL;
  1470. $this->SortPosts();
  1471. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1472. $nid = substr($p['id'], 0,6);
  1473. if($cf != $nid){
  1474. if($opened){
  1475. fflush($opened);
  1476. fclose($opened);
  1477. }
  1478. $cf = $nid;
  1479. $opened = fopen("posts/$cf.md", 'w');
  1480. }
  1481. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1482. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1483. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1484. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1485. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1486. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1487. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1488. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1489. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1490. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1491. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1492. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1493. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1494. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1495. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1496. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1497. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1498. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1499. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1500. ']';
  1501. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1502. }
  1503. }
  1504. function CachePostLinks(){
  1505. if(isset($this->WayBack)) return;
  1506. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1507. $this->ConvertPost($post);
  1508. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1509. //discard lost old version
  1510. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1511. }else return;
  1512. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1513. unset($im['refs']);
  1514. }
  1515. foreach ($this->Posts as &$post){
  1516. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1517. foreach($matches as $m){
  1518. $ref = &$this->GetPost($m[1],true);
  1519. if($ref!=NULL){
  1520. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1521. }
  1522. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1523. }
  1524. }
  1525. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1526. foreach($matches as $m){
  1527. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1528. }
  1529. }
  1530. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1531. foreach($matches as $m){
  1532. if(($im = &$this->FindImage($m[2]))!=NULL){
  1533. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1534. }
  1535. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1536. }
  1537. }
  1538. }foreach($this->Posts as &$post){
  1539. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1540. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1541. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1542. }
  1543. }
  1544. }
  1545. function CreatePostAnchor(&$post){
  1546. $that=&$this;
  1547. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1548. $id = '_heading_'.sizeof($this->Anchors);
  1549. $entry=[(int)$ma[1], $id, $ma[2]];
  1550. $that->Anchors[] = $entry;
  1551. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1552. }, $post['html']);
  1553. }
  1554. function RenamePost(&$post, $rename){
  1555. foreach($this->Posts as &$p){
  1556. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1557. }
  1558. foreach($this->Posts as &$p){
  1559. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1560. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1561. }
  1562. $post['id'] = $rename;
  1563. }
  1564. function DetachPost(&$th,&$post){
  1565. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1566. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1567. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1568. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1569. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1570. unset($th['arr']); $now = date_timestamp_get(date_create());
  1571. $this->FinalizeThread($th, true, $now);
  1572. }
  1573. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1574. $a = &$this->GetArchiveHandle($post['id']);
  1575. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1576. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1577. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1578. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1579. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1580. $post['version'] = $optime_id;
  1581. if($mode==1){
  1582. $this->InsertArchivePost($ap);
  1583. }else if($mode==2){
  1584. $post['merged_from'] = $info;
  1585. $this->InsertArchivePost($ap);
  1586. }else if($mode==3){
  1587. $ap['merged_into'] = $info;
  1588. $this->InsertArchivePost($ap);
  1589. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1590. $this->DetachPost($post['tid'], $post);
  1591. }
  1592. }else if($mode==4){
  1593. $post['merged_thread'] = $info;
  1594. $this->InsertArchivePost($ap);
  1595. }
  1596. }
  1597. function &MergeThreads($post_id, $post_into_id){
  1598. $this->ReadPosts();
  1599. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1600. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1601. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1602. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1603. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1604. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1605. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1606. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1607. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info);
  1608. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1609. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1610. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1611. $tt['count'] = sizeof($tt['arr']);
  1612. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1613. $first_post = &$this->NULL_POST;
  1614. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1615. $this->NeedWritePosts=1;
  1616. $this->NeedWriteArchive=1;
  1617. return $first_post;
  1618. }
  1619. function &MergePosts($ids_string){
  1620. $ids = explode(" ", $ids_string);
  1621. $combined_content = ""; $first_id=NULL;
  1622. $this->ReadPosts(); $child_list=[];
  1623. foreach($ids as $id){
  1624. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1625. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1626. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL);
  1627. }
  1628. if(!isset($child_list[0])) return $this->NULL_POST;
  1629. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list);
  1630. foreach($child_list as $id){
  1631. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING]);
  1632. }
  1633. $this->NeedWritePosts=1;
  1634. $this->NeedWriteArchive=1;
  1635. return $first_post;
  1636. }
  1637. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1638. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1639. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1640. $push_version=false, $version_info=NULL){
  1641. $this->ReadImages();
  1642. $this->ReadPosts();
  1643. if(isset($push_version) && $push_version){
  1644. $this->ReadArchive();
  1645. }
  1646. $p_success = NULL;
  1647. if(isset($id_if_edit)){
  1648. $post = &$this->GetPost($id_if_edit,true);
  1649. if($post===$this->NULL_POST) return $this->NULL_POST;
  1650. if($get_original_only){
  1651. return $post['real_content'];
  1652. }
  1653. if(isset($push_version) && $push_version){
  1654. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1655. }
  1656. if(isset($content)) $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1657. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1658. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1659. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1660. $p_success = &$post;
  1661. }else{
  1662. if(!isset($content)) return $this->NULL_POST;
  1663. $id = date('YmdHis');
  1664. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1665. $post = []; $post['id'] = $id;
  1666. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1667. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1668. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1669. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1670. }
  1671. $this->Posts[] = $post;
  1672. $p_success = &$this->Posts[count($this->Posts) - 1];
  1673. }
  1674. $this->NeedWritePosts=1;
  1675. $this->NeedWriteImages=1;
  1676. if(isset($push_version) && $push_version){
  1677. $this->NeedWriteArchive=1;
  1678. }
  1679. return $p_success;
  1680. }
  1681. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1682. $this->ReadPosts();
  1683. $p_success = NULL;
  1684. if(isset($id_if_edit)){
  1685. $post = &$this->GetPost($id_if_edit,true);
  1686. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1687. if(isset($content)) $post['content'] = $content;
  1688. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1689. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1690. if(isset($ip)) $post['ip'] = $ip;
  1691. $p_success = &$post;
  1692. }else{
  1693. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1694. $id = date('YmdHis');
  1695. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1696. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1697. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1698. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1699. if(isset($ip)) $post['ip'] = $ip;
  1700. $this->Posts[] = $post;
  1701. $p_success = &$this->Posts[count($this->Posts) - 1];
  1702. }
  1703. $this->NeedWritePosts=1;
  1704. return $p_success;
  1705. }
  1706. function InsertReplacementSymbols($MarkdownContent){
  1707. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1708. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1709. function($matches){
  1710. $rep = preg_replace('/->/','-@>',$matches[0]);
  1711. $rep = preg_replace('/=>/','=@>',$rep);
  1712. $rep = preg_replace('/<=/','<@=',$rep);
  1713. $rep = preg_replace('/<-/','<@-',$rep);
  1714. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  1715. $rep = preg_replace('/\[-/','[@-',$rep);
  1716. $rep = preg_replace('/\{/','{@',$rep);
  1717. return $rep;
  1718. },
  1719. $replacement);
  1720. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  1721. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  1722. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  1723. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  1724. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  1725. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  1726. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  1727. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  1728. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  1729. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  1730. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  1731. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  1732. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  1733. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  1734. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1735. function($matches){
  1736. $rep = preg_replace('/-@>/','->',$matches[0]);
  1737. $rep = preg_replace('/<@-/','<-',$rep);
  1738. $rep = preg_replace('/=@>/','=>',$rep);
  1739. $rep = preg_replace('/<@=/','<=',$rep);
  1740. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  1741. $rep = preg_replace('/\[@-/','[-',$rep);
  1742. $rep = preg_replace('/\{@/','{',$rep);
  1743. return $rep;
  1744. },
  1745. $replacement);
  1746. return $replacement;
  1747. }
  1748. function CanShowPost(&$p){
  1749. if(!isset($p) || isset($p['comment_to'])) return false;
  1750. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  1751. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  1752. if($is_mark_slf && !$this->LoggedIn){ return false; }
  1753. if(isset($this->WayBack)){
  1754. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  1755. else if ($p['id']>$this->WayBack) return false;
  1756. }
  1757. if(!$this->InExperimentalMode){
  1758. if(!$this->LoggedIn){
  1759. if($is_mark_exp) return false;
  1760. return true;
  1761. }
  1762. return true;
  1763. }else{
  1764. if($is_mark_exp) return true;
  1765. return false;
  1766. }
  1767. }
  1768. function SkipProduct(&$p){
  1769. if($this->LoggedIn) return false;
  1770. return (isset($p['mark_value']) && $p['mark_value']==5);
  1771. }
  1772. function GetRedirect($args=NULL){
  1773. $str = 'index.php?';
  1774. if(isset($args['post'])) $str.='&post='.$args['post'];
  1775. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  1776. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  1777. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  1778. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  1779. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  1780. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  1781. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  1782. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  1783. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  1784. if(isset($args['category'])) $str.='&category='.$args['category'];
  1785. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  1786. if(isset($args['history'])) $str.='&history='.$args['history'];
  1787. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  1788. if(isset($args['version'])) $str.='&version='.$args['version'];
  1789. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  1790. if(isset($args['search'])) $str.='&search='.$args['search'];
  1791. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  1792. return $str;
  1793. }
  1794. function WriteAsNecessary(){
  1795. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  1796. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  1797. if($this->NeedWriteImages){ $this->WriteImages(); }
  1798. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  1799. }
  1800. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  1801. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  1802. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  1803. return 0;
  1804. }
  1805. if(isset($_GET['set_language'])){
  1806. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  1807. $redirect=$this->GetRedirect(); return 0;
  1808. }
  1809. if(isset($_GET['toggle_font'])){ $use_font='local';
  1810. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  1811. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  1812. $redirect=$this->GetRedirect(); return 0;
  1813. }
  1814. if(isset($_GET['set_wayback'])){
  1815. if($_GET['set_wayback']!='false'){
  1816. $wayback= date('YmdHis');
  1817. if($_GET['set_wayback']=='post'){
  1818. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  1819. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  1820. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  1821. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  1822. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  1823. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  1824. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  1825. }else{
  1826. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  1827. }
  1828. $redirect=$this->GetRedirect(); return 0;
  1829. }
  1830. if(isset($_GET['post'])){
  1831. $this->CurrentPostID = $_GET['post'];
  1832. $this->TagID = $this->CurrentPostID;
  1833. }
  1834. if(isset($_GET['offset'])){
  1835. $this->CurrentOffset = $_GET['offset'];
  1836. }
  1837. if(isset($_GET['part'])){
  1838. if($_GET['part'] == 'hot') $this->ExtraScripts.="ShowLeftSide();";
  1839. else if ($_GET['part'] == 'recent') $this->ExtraScripts.="ShowCenterSide();";
  1840. }
  1841. if(isset($_GET['post'])){
  1842. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  1843. }
  1844. if(isset($_POST['search_content'])){
  1845. $redirect='index.php?search='.$_POST['search_content'];return 0;
  1846. }
  1847. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  1848. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  1849. $direct_return = !isset($_GET['show_image']);
  1850. $this->ReadImages();
  1851. $this->ReadPosts();
  1852. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  1853. $im = &$this->FindImage($m);
  1854. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  1855. if($direct_return){
  1856. echo "<ref>".sizeof($im['refs'])."</ref>";
  1857. echo "<insert><ul>";
  1858. }else{ ob_start(); }
  1859. foreach(array_reverse($im['refs']) as $ref){
  1860. $p = $this->GetPost($ref);
  1861. if(!$p || !$this->CanShowPost($p)) continue;
  1862. $this->MakeSinglePost($p, false, true, "post_preview", true, false, false, false, true);"</li>";
  1863. }
  1864. if($direct_return){
  1865. echo "</ul></insert>";
  1866. }else{
  1867. $str = ob_get_clean();
  1868. $this->MakePageBegin();
  1869. $side = "";
  1870. if(isset($im['refs'])&&isset($im['refs'][0])){
  1871. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  1872. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  1873. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$im['file']);
  1874. $this->MakePageEnd();
  1875. }
  1876. exit;
  1877. }
  1878. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  1879. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  1880. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  1881. }
  1882. if($this->LoggedIn){
  1883. $this->DoUpload();
  1884. if(isset($_POST['settings_button'])){
  1885. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  1886. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  1887. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  1888. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  1889. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  1890. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  1891. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  1892. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  1893. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  1894. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  1895. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  1896. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  1897. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  1898. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  1899. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  1900. if(isset($_POST['settings_exp_index'])) $this->ExpIndex=$_POST['settings_exp_index'];
  1901. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  1902. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  1903. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  1904. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  1905. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  1906. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  1907. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  1908. $redirect=$_SERVER['REQUEST_URI'];
  1909. $this->DoLogout();
  1910. }
  1911. $this->WriteConfig();
  1912. return 0;
  1913. }
  1914. if(isset($_POST['settings_save_redirect'])){
  1915. if(isset($_POST['settings_redirect'])){
  1916. $this->BuildRedirectConfig($_POST['settings_redirect']);
  1917. }
  1918. $this->WriteConfig();
  1919. $redirect = 'index.php?extras=true'; return 0;
  1920. }
  1921. if(isset($_POST['settings_save_translation'])){
  1922. if(isset($_POST['settings_translation'])){
  1923. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  1924. }
  1925. $redirect = 'index.php?extras=true'; return 0;
  1926. }
  1927. if(isset($_GET['post'])){
  1928. if(isset($_GET['post_original'])){
  1929. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL);
  1930. exit;
  1931. }
  1932. }
  1933. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  1934. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL);
  1935. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  1936. return 0;
  1937. }
  1938. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  1939. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL);
  1940. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  1941. return 0;
  1942. }
  1943. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  1944. $c = $_POST['post_content'];
  1945. if('有什么想说的' == $c){ return 0;}
  1946. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  1947. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  1948. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  1949. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  1950. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  1951. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL))!=NULL){
  1952. $redirect='?post='.$edited['id']; return 0;
  1953. };
  1954. }
  1955. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  1956. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL))!=NULL){
  1957. $redirect='?post='.$edited['id']; return 0;
  1958. };
  1959. }
  1960. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  1961. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  1962. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  1963. }
  1964. }
  1965. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  1966. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  1967. $redirect='?post='.$pe['id']; return 0;
  1968. }
  1969. }
  1970. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  1971. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  1972. $c = $_POST['comment_box'];
  1973. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  1974. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  1975. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  1976. if(($edited = $this->EditComment(NULL,
  1977. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  1978. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  1979. $_SERVER['REMOTE_ADDR']))!=NULL){
  1980. $redirect='?post='.$_GET['post'];
  1981. return 0;
  1982. };
  1983. }
  1984. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  1985. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  1986. $new_name = $_POST['gallery_edit_new_name'];
  1987. if($old_name!=''){
  1988. $this->EditGallery($old_name, $new_name, false, true, null, null);
  1989. $redirect='?gallery='.$new_name;
  1990. }else{
  1991. $this->EditGallery(null, $new_name, false, true, null);
  1992. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  1993. }
  1994. return 0;
  1995. }
  1996. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  1997. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  1998. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  1999. return 0;
  2000. }
  2001. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2002. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2003. $this->ReadImages();
  2004. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2005. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL);
  2006. }
  2007. }
  2008. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2009. return 0;
  2010. }
  2011. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2012. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2013. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2014. return 0;
  2015. }
  2016. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2017. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2018. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2019. return 0;
  2020. }
  2021. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2022. $this->ReadImages();
  2023. $gallery = $_GET['image_list'];
  2024. foreach($this->Images as $im){
  2025. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2026. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2027. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2028. }
  2029. exit;
  2030. }
  2031. $do_image_redirect = 0;
  2032. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2033. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif))/u',$_GET['pic'],$ma)){
  2034. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2035. if(isset($_POST['image_ops_product_link'])){
  2036. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL);
  2037. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2038. }
  2039. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2040. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL);
  2041. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2042. $do_image_redirect = 1;
  2043. }
  2044. if(isset($_POST['image_parent'])){ $parent="";
  2045. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2046. $this->EditImage($pic, NULL, false, NULL, NULL, $parent);
  2047. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2048. }
  2049. $this->NeedWriteImages = 1;
  2050. if($do_image_redirect) return 0;
  2051. }
  2052. if(isset($_GET['rewrite_styles'])){
  2053. $this->WriteStyles();
  2054. $redirect='?extras=true'; return 0;
  2055. }
  2056. if(isset($_GET['regenerate_thumbnails'])){
  2057. $this->RegenerateThumbnails();
  2058. $redirect='?extras=true'; return 0;
  2059. }
  2060. if(isset($_GET['clear_all_logins'])){
  2061. $this->LoginTokens=[];
  2062. $this->WriteTokens();
  2063. }
  2064. }
  2065. return 0;
  2066. }
  2067. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null){
  2068. if(!$this->LoggedIn){
  2069. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2070. }
  2071. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2072. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2073. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2074. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2075. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2076. $html = preg_replace("/<p>\s*\{\s*INTERESTING\s+(.*?)\}\s*<\/p>/imu","",$html);
  2077. $html = preg_replace("/\{\s*REVERSED\s*\}/imu","",$html);
  2078. $images = [];
  2079. $images_noclick = [];
  2080. $html = preg_replace_callback(
  2081. "/(<p>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2082. function($m) use (&$images,&$images_noclick) {
  2083. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2084. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2085. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2086. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2087. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2088. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2089. $src = $im['thumb']; $orig_src=$im['file'];
  2090. }
  2091. if($this->InExperimentalMode){
  2092. $click = "<div class='imd'><a href='".$im['file']."' class='original_img' target='_blank'>".
  2093. $m[2].$orig_src.$m[7]."></a></div>";
  2094. return $click;
  2095. }else{ $click =
  2096. "<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2097. $m[2].($original?$orig_src:$src).$m[7]." data-imgsrc='".$m[5]."'".
  2098. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2099. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2100. ($original?" class='original_img'":"")."></a></div>";
  2101. $images_noclick[]=$m[2].$src.$m[7].">";
  2102. $ret = "";
  2103. if($keep) { $ret = $click; }
  2104. else { $images[] = $click; }
  2105. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2106. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2107. }
  2108. },$html,-1,$count);
  2109. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2110. if(sizeof($images)){
  2111. if(sizeof($images)==1){$html.= $images[0]; }
  2112. else{
  2113. $html.="<div class='p_row'>";
  2114. foreach($images as $img){
  2115. $html.="<div class='p_thumb'>".$img."</div>";
  2116. }
  2117. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2118. }
  2119. }
  2120. if(sizeof($images_noclick)){
  2121. $added_images = $images_noclick;
  2122. }
  2123. if($do_product_info){
  2124. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2125. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2126. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2127. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2128. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2129. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2130. else { $product_info['title'] = $this->T('商品'); }
  2131. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2132. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2133. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2134. $this->T('购买').' '.$product_info['title'].
  2135. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2136. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2137. }
  2138. return $html;
  2139. }
  2140. function ConvertPost(&$post){
  2141. if(!isset($post['html'])){
  2142. $info=[];
  2143. $post['html'] = $this->PostProcessHTML($this->PDE->text($this->InsertReplacementSymbols($post['content'])),
  2144. $post['images'],
  2145. isset($post['product']), $info);
  2146. if(isset($post['product'])) $post['product']=$info;
  2147. }
  2148. }
  2149. function GetPostTitle(&$post, $h1_only=false){
  2150. if(!isset($post['title'])){
  2151. if($h1_only){
  2152. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){return $m[1];}
  2153. return NULL;
  2154. }
  2155. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2156. else{ $post['title'] = $this->T('未命名'); if(preg_match('/(.*)$/mu',$post['content'],$m))
  2157. {$post['title'].=' ('.strip_tags($this->PDE->text($m[1])).')';} }
  2158. }
  2159. return $post['title'];
  2160. }
  2161. function DetectPageType(){
  2162. if($this->InExperimentalMode) $this->PageType='experimental';
  2163. else if(isset($_GET['history'])) $this->PageType='history';
  2164. else if(isset($_GET['extras'])) $this->PageType='extras';
  2165. else if(isset($_GET['settings'])) $this->PageType='settings';
  2166. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2167. else if(isset($_GET['search'])) $this->PageType='search';
  2168. else if(isset($_GET['category'])) $this->PageType='category';
  2169. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2170. else if(isset($_GET['comments'])) $this->PageType='comments';
  2171. else $this->PageType = "main";
  2172. }
  2173. function MakePageBegin(){ ?>
  2174. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2175. <head>
  2176. <meta charset='utf-8'>
  2177. <meta content="width=device-width, initial-scale=1" name="viewport">
  2178. <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->Title)?></title>
  2179. <?php if($this->UseRemoteFont){ ?><style>
  2180. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2181. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2182. </style><?php } ?>
  2183. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2184. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2185. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2186. </head>
  2187. <div class='page'>
  2188. <?php }
  2189. function MakeHeader(&$p){
  2190. $this->MakePageBegin() ?>
  2191. <script type='text/javascript'>
  2192. function toggle_mobile_show(a){a.classList.toggle('hidden_on_mobile')}
  2193. function ShowWaitingBar(){
  2194. wait = document.querySelector("#waiting_bar");
  2195. wait.style.display='';
  2196. }
  2197. function HideWaitingBar(){
  2198. wait = document.querySelector("#waiting_bar");
  2199. wait.style.display='none';
  2200. }
  2201. <?php if(!$this->InExperimentalMode){ ?>
  2202. function la_auto_grow(element){
  2203. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2204. }
  2205. var scroll_l=0,scroll_c=0;in_center=1;
  2206. function ShowLeftSide(){
  2207. scroll_c = window.scrollY;
  2208. document.getElementById('div_left').classList.remove('hidden_on_mobile');
  2209. document.getElementById('div_center').classList.add('hidden_on_mobile');
  2210. window.scroll(0, scroll_l); in_center=0;
  2211. }
  2212. function ShowCenterSide(){
  2213. scroll_l = window.scrollY;
  2214. document.getElementById('div_center').classList.remove('hidden_on_mobile');
  2215. document.getElementById('div_left').classList.add('hidden_on_mobile');
  2216. window.scroll(0, scroll_c); in_center=1;
  2217. }
  2218. function ShowBackdrop(alpha=0.5){
  2219. b = document.getElementById('backdrop');
  2220. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2221. b.style.animation='backdrop_fade_in 0.3s forwards';
  2222. b.style.display = 'block';
  2223. }
  2224. function HideBackdrop(){
  2225. b = document.getElementById('backdrop');
  2226. b.style.animation='backdrop_fade_out 0.3s forwards';
  2227. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2228. }
  2229. function ShowRightSide(big,elem_to_clone){
  2230. p = document.getElementById('pop_right');
  2231. if(elem_to_clone){
  2232. c = elem_to_clone.cloneNode(true);
  2233. c.id='side_bar_cloned';c.className="";c.style="";
  2234. p.querySelector('._content').appendChild(c);
  2235. }
  2236. p.classList.remove('pop_right','pop_right_big');
  2237. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2238. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2239. p.style.display='block';
  2240. ShowBackdrop(0.5);
  2241. }
  2242. function HideRightSide(){
  2243. p = document.getElementById('pop_right');
  2244. if(side=p.querySelector('#side_bar_cloned')){
  2245. side.remove();
  2246. }
  2247. put = document.querySelector("#_uploader");
  2248. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2249. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2250. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2251. HideBackdrop();
  2252. }
  2253. function ToggleLeftSide(){if(in_center)ShowLeftSide();else ShowCenterSide();}
  2254. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2255. function ScrollToPost(id){
  2256. post=null;
  2257. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2258. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2259. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2260. }
  2261. <?php } ?>
  2262. </script>
  2263. <header><div>
  2264. <?php if($this->InExperimentalMode){
  2265. $this->MakeExpNavButtons($p);
  2266. }else{
  2267. $this->MakeNavButtons($p);
  2268. } ?>
  2269. <hr />
  2270. <?php if(isset($this->WayBack)){
  2271. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2272. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2273. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2274. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_on_mobile")'>
  2275. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2276. <span class='hidden_on_mobile'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2277. <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_on_mobile'>
  2278. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2279. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2280. <br class='hidden_on_desktop' />
  2281. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2282. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2283. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2284. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2285. <br class='hidden_on_desktop' />
  2286. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2287. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2288. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2289. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2290. <br class='hidden_on_desktop' />
  2291. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2292. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2293. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2294. </div></div><?php } ?>
  2295. </div></header>
  2296. <div id='waiting_bar' style='display:none;'></div>
  2297. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2298. <?php if(!$this->InExperimentalMode){ ?>
  2299. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2300. <ul>
  2301. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2302. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2303. <hr />
  2304. <?php if($this->LoggedIn){ ?>
  2305. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2306. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2307. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2308. <?php if(!isset($this->WayBack)){ ?><li>
  2309. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2310. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2311. </li>
  2312. <li><a id='menu_mark' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2313. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2314. <li id='mark_details' style='display:none;'><b>
  2315. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2316. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2317. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2318. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2319. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2320. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2321. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2322. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2323. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2324. </b></li>
  2325. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2326. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2327. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2328. <input class='button' type='submit' form='post_rename_form'
  2329. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2330. </li>
  2331. <hr />
  2332. <li><a id='menu_delete' class='smaller'></a></li><?php } ?>
  2333. <?php }else{ ?>
  2334. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2335. <?php } ?>
  2336. </ul>
  2337. </div>
  2338. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide()'
  2339. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2340. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2341. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2342. <?=$this->T('关闭')?>→</a></div>
  2343. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2344. <div id='_uploader' style='display:none;'>
  2345. <?php $this->MakeUploader(true); ?>
  2346. <p>&nbsp;</p>
  2347. <?php $this->MakeSideGalleryCode(); ?>
  2348. </div>
  2349. <?php } ?>
  2350. <div class='_content'></div>
  2351. </div>
  2352. <?php } ?>
  2353. <?php
  2354. }
  2355. function TranslatePostParts($html){
  2356. $html = preg_replace_callback('/>([^><]+?)</u', function($ma){
  2357. return ">".$this->T($ma[1])."<";
  2358. }, $html);
  2359. return $html;
  2360. }
  2361. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); ?>
  2362. <a href='index.php' class='clean_a hidden_on_mobile' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title)?></b></a>
  2363. <b><a class='hidden_on_desktop'
  2364. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ShortTitle)?>...</a></b>
  2365. <div class='header_nav'>
  2366. <?php if($this->PageType=='post'){ ?>
  2367. <div style='float:right;' class='hidden_on_print'>
  2368. <?php if(!$interesting && isset($p) && isset($p['refs']) && isset($p['refs'][0])){ ?>
  2369. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2370. <?=$this->T('链接')?>(<?=sizeof($p['refs'])?>)</a></span>
  2371. <?php } if(!$interesting){ ?>
  2372. <span class='hidden_on_wide hidden_on_print'>
  2373. <a id='button_toc' href='javascript:ShowRightSide(true,document.querySelector("#div_right"));'>
  2374. <?=$this->T('目录')?></a></span><?php } ?></div>
  2375. <?php }else if($this->PageType=='history' && isset($_GET['version'])){ ?>
  2376. <div style='float:right;' class='hidden_on_print'>
  2377. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2378. <?=$this->T('历史')?></a></span></div>
  2379. <?php } ?>
  2380. <ul class='hidden_on_mobile hidden_on_print' id='mobile_nav' style='text-align:center;'>
  2381. <li class='hidden_on_mobile'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2382. <li class='hidden_on_desktop_force block_on_mobile'>
  2383. <?php if($this->PageType!='main'){ ?>
  2384. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a> |
  2385. <a href='index.php?part=hot' onclick='ShowWaitingBar()'><?=$this->T('热门')?></a> |
  2386. <?php } else { ?>
  2387. <li class='hidden_on_desktop_force block_on_mobile'>
  2388. <a href='javascript:ShowCenterSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('最近')?></a> |
  2389. <a href='javascript:ShowLeftSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('热门')?></a> |
  2390. <?php } ?>
  2391. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a>
  2392. <?php if($this->LoggedIn){ ?>
  2393. | <span class='gray invert_a'><a href='index.php?comments=al最近l'>@</a></span><?php } ?></li>
  2394. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2395. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST));
  2396. } ?>
  2397. <li><a href='?search=' onclick='ShowWaitingBar()'><?=$this->T('搜索')?></a></li>
  2398. <?php if($this->LanguageAppendix=='zh'){ ?>
  2399. <li class='invert_a smaller'>
  2400. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  2401. <?php }else { ?>
  2402. <li class='smaller'>
  2403. <a class='invert_a' href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  2404. 汉语/<b>English</b></a>
  2405. <br class='hidden_on_desktop' />
  2406. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  2407. <?php } ?>
  2408. </ul>
  2409. </div>
  2410. <?php
  2411. }
  2412. function MakeExpNavButtons(&$p){?>
  2413. <b><a href='index.php' class='hidden_on_mobile'><?=$this->T($this->ExpTitle)?></a></b>
  2414. <b><a class='hidden_on_desktop'
  2415. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ExpShortTitle)?>...</a></b>
  2416. <ul class='hidden_on_mobile' id='mobile_nav' style='text-align:center;'>
  2417. <li class='hidden_on_desktop block_on_mobile'><a href='index.php'><?=$this->T('索引')?></a></li>
  2418. <?php $this->ExpNavigation;if(isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2419. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST));
  2420. } ?>
  2421. <?php if($this->LanguageAppendix=='zh'){ ?>
  2422. <li class='invert_a smaller'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  2423. <?php }else { ?>
  2424. <li class='invert_a smaller'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  2425. <span class='text_highlight'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></span></li>
  2426. <?php } ?>
  2427. </ul>
  2428. <?php
  2429. }
  2430. function GenerateLinkedPosts($ht){
  2431. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  2432. function($m){
  2433. $rp = &$this->GetPost($m[1], false, true);
  2434. $s="<div class='smaller block post ref_compact gray'>".
  2435. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  2436. "<div class='post_ref'><div class='smaller'>".$m[2]."</div>".
  2437. (($rp!==NULL && $this->CanShowPost($rp))?$this->TranslatePostParts(
  2438. $this->GenerateSinglePost($rp,false,false,false,true,$this->NULL_POST,true)):$this->T("未找到该引用。")).
  2439. "</div></div>";
  2440. return $s;
  2441. },
  2442. $ht
  2443. );
  2444. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  2445. function($m){
  2446. $rp = &$this->GetPost($m[1], false, true);
  2447. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  2448. (($rp!==NULL && $this->CanShowPost($rp))?$this->TranslatePostParts(
  2449. $this->GenerateSinglePost($rp,true,false,false,true,$this->NULL_POST,true)):$this->T("未找到该引用。")).
  2450. "</a></div>";
  2451. return $s;
  2452. },
  2453. $ht
  2454. );
  2455. return $ht;
  2456. }
  2457. function ExtractBigTables($html, &$table_out){
  2458. $table = NULL;
  2459. $new_html = preg_replace_callback('/<p>\s*\{big_table\}\s*<\/p>\s*(<table>[\s\S]*?<\/table>)/u', function ($m) use (&$table){
  2460. $table = $m[1];
  2461. return "";
  2462. }, $html);
  2463. $table_out = $table;
  2464. return $new_html;
  2465. }
  2466. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  2467. $generate_thumbs=false, &$table_out, $hide_long = false){
  2468. $this->ConvertPost($post);
  2469. if($generate_anchor){ $this->CreatePostAnchor($post); }
  2470. $ht = $post['html'];
  2471. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  2472. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  2473. "<p class='bold'>".$post['product']['title']."</p>".
  2474. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  2475. "<p class='smaller bold'>".$post['product']['price']."</p>";
  2476. return $ht;
  2477. }
  2478. if($hide_long){
  2479. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  2480. }else{
  2481. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  2482. }
  2483. if ($strip_tags){
  2484. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  2485. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  2486. $ht = "<div class='post_ref_main'>".$ht."</div>";
  2487. }
  2488. else{
  2489. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  2490. if($table_out!=$this->NULL_POST){
  2491. $table = NULL; $ht = $this->ExtractBigTables($ht,$table);
  2492. $table_out = $table;
  2493. }else{
  2494. $ht = preg_replace('/<p>\s*\{big_table\}\s*<\/p>/u','',$ht);
  2495. }
  2496. }
  2497. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  2498. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  2499. foreach($post['images'] as $im){
  2500. $ht.="<li class='file_thumb'>".$im."</li>";
  2501. }
  2502. $ht.="</ul></div>";
  2503. }
  2504. return $ht;
  2505. }
  2506. function MakeSinglePostExp(&$post){
  2507. $big_table = ""; ?>
  2508. <li class='post post_dummy'>
  2509. <?=$this->TranslatePostParts(
  2510. $this->GenerateSinglePost($post, false, false, true, false, $big_table, false)); ?>
  2511. </li>
  2512. <?php if($big_table!=$this->NULL_POST) echo "</ul></li><div class='table_top'>".$big_table.'</div>';?>
  2513. <?php
  2514. }
  2515. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  2516. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  2517. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  2518. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  2519. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  2520. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  2521. $big_table = ($show_thread_link)?$this->NULL_POST:"";
  2522. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  2523. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  2524. ?>
  2525. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  2526. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?><?=$side?" post_box":""?>'
  2527. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>>
  2528. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  2529. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  2530. <?php } ?>
  2531. <?php if($is_top){?>
  2532. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  2533. <?php } ?>
  2534. <?php if(!$side && $show_link){ ?>
  2535. <a href='?post=<?=$post['id']?>' onclick='ShowWaitingBar()'>
  2536. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2537. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"→")?>
  2538. </div>
  2539. <?php if($ref_count){ ?>
  2540. <div class='post_access ref_count'><?=$ref_count?></div>
  2541. <?php } ?>
  2542. </a>
  2543. <?php } ?>
  2544. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  2545. <div class='<?=$side?"":($show_link?'post_width':'post_width_big')?><?=$is_deleted?" deleted_post":""?>'>
  2546. <?php if(!$side && !$strip_tags){?>
  2547. <div class='post_menu_button _menu_hook' >+</div>
  2548. <?php } if($is_product&&!$generate_anchor){
  2549. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  2550. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  2551. <?=$this->TranslatePostParts(
  2552. $this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  2553. $generate_thumb,$big_table,($show_thread_link||$side||$force_hide_long))); ?>
  2554. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  2555. </div>
  2556. <?=$side?"</a>":""?> <?php
  2557. if(!$show_thread_link && $big_table!=$this->NULL_POST && !$side){
  2558. echo "</ul></li><div class='table_top'>".$big_table.'</div>';
  2559. ?><ul class='print_column'>
  2560. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  2561. <?php
  2562. }
  2563. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  2564. $post['tid']['first']['id']!=$post['id']){ ?>
  2565. <div class='gray smaller block opt_compact post'>
  2566. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  2567. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  2568. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  2569. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  2570. <?=$this->TranslatePostParts(
  2571. $this->GenerateSinglePost($post['tid']['first'], false, false, false, true,$this->NULL_POST,true));?>
  2572. </div>
  2573. </div>
  2574. <?php }
  2575. if($show_reply_count && isset($post['tid'])){ ?>
  2576. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  2577. <?=$this->T('个回复')?></a>
  2578. <?php }
  2579. ?>
  2580. </li>
  2581. <?php
  2582. }
  2583. function MakePostingFields($reply_to=NULL, $show_hint=false){
  2584. if(isset($this->WayBack)){ ?>
  2585. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  2586. <?php return; } ?>
  2587. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  2588. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  2589. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  2590. <div id='post_hint_modify' style='display:none;'>
  2591. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  2592. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  2593. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  2594. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  2595. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  2596. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  2597. onclick='ShowWaitingBar();' />
  2598. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  2599. <div style='float:right;'>
  2600. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  2601. <?=$this->T('清空')?></a>
  2602. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  2603. </div>
  2604. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  2605. <script> la_auto_grow(document.getElementById("post_content"));</script>
  2606. <?php if($reply_to){ ?>
  2607. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  2608. <?php } ?>
  2609. <?php
  2610. }
  2611. function MakeCommentPosts(){
  2612. if(!$this->LoggedIn) return; ?>
  2613. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  2614. <?php if(!$this->CommentEnabled){
  2615. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  2616. <div class='comment'><ul>
  2617. <?php $i=0;
  2618. foreach(array_reverse($this->Posts) as $p){
  2619. if(!isset($p['comment_to'])) continue;
  2620. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  2621. $ht = $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false, $t, false));
  2622. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  2623. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  2624. if(!$post_to) $post_title = "?";
  2625. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  2626. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  2627. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  2628. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  2629. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  2630. $i++;
  2631. }
  2632. ?>
  2633. </ul><br /></div>
  2634. <?php
  2635. }
  2636. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  2637. <div class='center' id='div_center'>
  2638. <h2><?=isset($search_term)?$this->T('搜索'):
  2639. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  2640. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  2641. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  2642. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  2643. <?php if(isset($search_term)){ ?>
  2644. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  2645. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  2646. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  2647. <?php }else if(isset($category)){ ?>
  2648. <div></div>
  2649. <?php }else if($this->LoggedIn){ ?>
  2650. <div class='post_box_top _input_bundle'>
  2651. <?php $this->MakePostingFields(NULL,false); ?>
  2652. </div>
  2653. <?php } ?>
  2654. <ul class='print_column list'>
  2655. <?php
  2656. if(!isset($search_term) && !isset($category) &&
  2657. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  2658. $this->CanShowPost($p)){
  2659. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  2660. }
  2661. $i = 0;
  2662. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  2663. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2664. if(isset($p['tid'])){ /* Should always be set. */
  2665. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  2666. if(!isset($search_term)) { $p = &$th['last']; }
  2667. }
  2668. if(isset($search_term)){
  2669. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  2670. }else if(isset($category)){
  2671. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  2672. (isset($p['categories'])?($p['categories']):[]);
  2673. if ($category=='none') { if($cat!=[]) continue; }
  2674. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  2675. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2676. }else{
  2677. if(in_array($p['id'],
  2678. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  2679. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2680. }
  2681. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  2682. $this->MakeSinglePost($p, true, false, NULL, false, !isset($search_term), false, false, false, false, isset($search_term));
  2683. $i++;
  2684. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  2685. }?>
  2686. </ul>
  2687. <div class='page_selector clean_a'>
  2688. <hr />
  2689. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  2690. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  2691. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  2692. <?=$this->CurrentOffset+1?>
  2693. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  2694. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  2695. → <?=$this->T('下一页')?></a>
  2696. </div>
  2697. </div>
  2698. <?php
  2699. }
  2700. function MakeHotPosts($placeholder_only=false){?>
  2701. <div class='left hidden_on_mobile' id='div_left'>
  2702. <?php if ($placeholder_only){ ?>&nbsp;
  2703. <?php }else{ ?>
  2704. <h2><?=$this->T('热门')?></h2>
  2705. <ul>
  2706. <?php
  2707. $i=0;
  2708. foreach($this->Threads as &$th){
  2709. if(!isset($th['first']) || $th['count']==0){ continue; }
  2710. if(!$this->CanShowPost($th['first'])) continue;
  2711. if($i>=$this->HotPostCount) break;
  2712. $this->MakeSinglePost($th['first'], false, true, "post_preview", true, false, true, false, true, false, false);
  2713. $i++;
  2714. } ?>
  2715. </ul>
  2716. <?php } ?>
  2717. </div>
  2718. <?php
  2719. }
  2720. function MakeLinkedPosts(&$p){
  2721. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  2722. <div class='left hidden_on_mobile' id='div_left'>
  2723. <h2<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h2>
  2724. <?php
  2725. if($has_ref){ ?>
  2726. <span class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></span>
  2727. <ul><?php $count_product=0;
  2728. foreach(array_reverse($p['refs']) as &$pr){
  2729. $po = $this->GetPost($pr); if(isset($post['mark_value']) && $po['mark_value']==5){ $count_product++; continue; }
  2730. if(!$this->CanShowPost($po)){ continue; }
  2731. $this->MakeSinglePost($po, false, true, "post_preview", true, false, false, false, true, false, false);
  2732. }
  2733. ?></ul>
  2734. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  2735. }else{ ?>
  2736. <span class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></span>
  2737. <?php } ?>
  2738. </div>
  2739. <?php
  2740. }
  2741. function MakeLinkedPostsExp(&$p){
  2742. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  2743. <div class='center_exp post_dummy smaller'>
  2744. <hr />
  2745. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  2746. <?php
  2747. if($has_ref){ ?>
  2748. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  2749. <ul><?php $count_product=0;
  2750. foreach(array_reverse($p['refs']) as &$pr){
  2751. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  2752. "</a></li>";
  2753. }
  2754. ?></ul>
  2755. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  2756. }else{ ?>
  2757. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  2758. <?php } ?>
  2759. <div style='margin-bottom:4rem;'>&nbsp;</div>
  2760. </div>
  2761. <?php
  2762. }
  2763. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  2764. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  2765. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  2766. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  2767. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  2768. if(!isset($title)) $title=$this->T('未命名');
  2769. if(!isset($ah)){ ?>
  2770. <h2><?=$this->T('没有历史记录')?></h2>
  2771. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  2772. <?php }else{ ?>
  2773. <h2><?=$this->T('历史记录')?></h2>
  2774. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  2775. <div class='list'><ul>
  2776. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  2777. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  2778. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  2779. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  2780. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  2781. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  2782. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  2783. <li><a href='?post=<?=$ver['id']?>&history=1'>
  2784. <?=$this->GetPostTitle($ver);?></a>
  2785. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  2786. <?php } ?></ul><?php } ?>
  2787. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  2788. $mah = &$this->GetArchiveHandle($pm);
  2789. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  2790. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  2791. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  2792. <?php } ?>
  2793. </li><?php } ?>
  2794. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  2795. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  2796. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  2797. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  2798. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  2799. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  2800. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  2801. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  2802. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  2803. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  2804. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  2805. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  2806. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  2807. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  2808. <li><a href='?post=<?=$ver['id']?>&history=1'>
  2809. <?=$this->GetPostTitle($ver);?></a>
  2810. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  2811. <?php } ?></ul></li><?php } ?>
  2812. <?php } ?></ul></div>
  2813. <?php } ?>
  2814. <?php
  2815. }
  2816. function MakePostDiff(&$this_ver, &$last_ver){
  2817. if(!isset($this_ver)){ ?>
  2818. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  2819. <?php }else{ ?>
  2820. <h2><?=$this->T('差异')?></h2>
  2821. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  2822. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  2823. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  2824. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  2825. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  2826. <?php }else{ ?>
  2827. <table class='diff_table'><thead>
  2828. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  2829. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  2830. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  2831. </thead><tbody>
  2832. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  2833. </tbody>
  2834. </table>
  2835. <?php } ?>
  2836. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  2837. <?php } ?>
  2838. <?php
  2839. }
  2840. function MakePostHistory(&$post, $version=NULL){
  2841. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  2842. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  2843. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  2844. ?>
  2845. <div class='left hidden_on_mobile history' id='div_left'>
  2846. <?php if (isset($version)){
  2847. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  2848. }else{ echo "&nbsp;"; } ?>
  2849. </div>
  2850. <div class='center history' id='div_center'>
  2851. <?php if (!isset($version)){
  2852. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  2853. }else{
  2854. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  2855. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  2856. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  2857. $this->MakePostDiff($this_ver, $last_ver, $p);
  2858. } ?>
  2859. </div>
  2860. <?php
  2861. }
  2862. function MakeCommentSection(&$post){
  2863. if(!$this->CommentEnabled){ return; }
  2864. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  2865. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  2866. ?><div class='comment'>
  2867. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  2868. <?php if($comment_count) { echo "<ul>";
  2869. foreach($to_post['comments'] as $p){
  2870. $ht = $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false, $t, false));
  2871. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  2872. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  2873. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  2874. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  2875. }
  2876. echo "</ul>";
  2877. } else {
  2878. echo $this->T('还没有评论');
  2879. } ?>
  2880. <div class='hidden_on_print'>
  2881. <div class='spacer'></div>
  2882. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  2883. method="post" style="display:none;" id="comment_form"></form>
  2884. <p><a class='text_highlight bold clean_a'
  2885. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  2886. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  2887. <div id='comment_box' style='display:none;'>
  2888. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  2889. <table style='white-space:nowrap;'>
  2890. <tr><td colspan='2'>
  2891. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  2892. oninput="CommentUpdated();" ></textarea>
  2893. </td></tr>
  2894. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  2895. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  2896. class='full_box' oninput="CommentUpdated();" /></td>
  2897. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  2898. class='full_box' oninput="CommentUpdated();" /></td></tr>
  2899. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  2900. <tr><td colspan='2'>
  2901. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  2902. class='full_box' oninput="CommentUpdated();" />
  2903. </td></tr>
  2904. <tr><td colspan='2'>
  2905. <div class='spacer'></div>
  2906. <input class='button text_highlight bigger' type='submit' form='comment_form'
  2907. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  2908. </td></tr>
  2909. </table></div>
  2910. <script>
  2911. const IsValidEmail = (email) => {
  2912. 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,}))$/);
  2913. };
  2914. function IsValidHttpUrl(string) {
  2915. let url; try{ url = new URL(string); } catch (_) { return false; }
  2916. return url.protocol === "http:" || url.protocol === "https:";
  2917. }
  2918. var cbox = document.getElementById('comment_box');
  2919. var cemail = document.getElementById('comment_email');
  2920. var cname = document.getElementById('comment_name');
  2921. var clink = document.getElementById('comment_link');
  2922. var cconfirm = document.getElementById('comment_confirm');
  2923. function CommentUpdated(){
  2924. cconfirm.disabled=true;
  2925. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  2926. cbox.innerText.length>2 && cname.value.length>2 &&
  2927. clink.value=="" || IsValidHttpUrl(clink.value)){
  2928. cconfirm.removeAttribute("disabled");
  2929. }
  2930. }
  2931. CommentUpdated();
  2932. </script>
  2933. </div>
  2934. </div>
  2935. <?php
  2936. }
  2937. function MakeInterestingSection(&$th){
  2938. $this->Anchors = [];
  2939. $c = &$th['first']['content'];
  2940. $this->ConvertPost($th['first']);
  2941. $ht = $th['first']['html'];
  2942. ?>
  2943. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  2944. <div class='center_full' id='div_center'>
  2945. <?php $this->MakePostTools(); ?>
  2946. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  2947. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  2948. <ul><li class='post post_width_big' data-post-id='<?=$th['first']['id']?>'>
  2949. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$this->TranslatePostParts($ht)?>
  2950. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  2951. <?php foreach($th['first']['refs'] as $ref){
  2952. $po = $this->GetPost($ref);
  2953. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  2954. if(!$this->CanShowPost($po)){ continue; }
  2955. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  2956. } ?>
  2957. </ul><?php } ?>
  2958. <?php if($this->LoggedIn && (!$this->InExperimentalMode)){ ?>
  2959. <div class='post_width_big hidden_on_print'><br />
  2960. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  2961. </div>
  2962. <?php } ?>
  2963. <table><thead><tr><th></th><?php foreach($th['interesting'] as $header){ ?>
  2964. <th><?=$this->T($header);?></th>
  2965. <?php } ?></tr></thead><tbody class='interesting_tbody'>
  2966. <?php $plist = array_reverse(array_slice($th['arr'],1));
  2967. foreach($plist as &$p){
  2968. $this->ConvertPost($p);
  2969. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  2970. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  2971. $is_current = $p['id']==$this->CurrentPostID;
  2972. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  2973. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  2974. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  2975. onDblClick='ClickImage(this)'><td>
  2976. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  2977. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2978. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  2979. </div>
  2980. <?php if($ref_count){ ?>
  2981. <div class='post_access ref_count'><?=$ref_count?></div>
  2982. <?php } ?></a>
  2983. <?=$this->TranslatePostParts($p['html']);?>
  2984. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a></td></tr>
  2985. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  2986. <?php foreach($p['refs'] as $ref){
  2987. $po = $this->GetPost($ref);
  2988. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  2989. if(!$this->CanShowPost($po)){ continue; }
  2990. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  2991. } ?>
  2992. </ul></td></tr><?php } ?>
  2993. <?php } ?>
  2994. </tbody></table>
  2995. </li></ul>
  2996. <br />
  2997. <?php $this->MakeCommentSection($th['first']); ?>
  2998. </div>
  2999. <?php return true;
  3000. }
  3001. function CssNumberID($id){
  3002. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3003. }
  3004. function MakePostTools(){
  3005. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3006. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3007. <?=$this->T('工具')?></a>:<div class='hidden_on_mobile' style='display:inline'>
  3008. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3009. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3010. </div>
  3011. <select class='hidden_on_desktop' id='merge_select'
  3012. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3013. <option value='-1' selected>--</option>
  3014. <option value='1'><?=$this->T('合并帖子')?></option>
  3015. <option value='2'><?=$this->T('合并话题')?></option></select>
  3016. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3017. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3018. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3019. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3020. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3021. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3022. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3023. </div><div class='spacer'></div><?php
  3024. }
  3025. }
  3026. function MakePostSection(&$post){
  3027. $this->Anchors = [];
  3028. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3029. <div class='center' id='div_center'>
  3030. <h2 class='hidden_on_print'>
  3031. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1; if($is_thread){ $th = $post['tid'];?>
  3032. <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3033. <?php } ?></h2>
  3034. <?php $cat = NULL;
  3035. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3036. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3037. $this->MakePostTools();
  3038. if($cat){ ?>
  3039. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3040. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3041. <?php } ?>
  3042. <ul class='print_column'>
  3043. <?php $is_reversed=false;
  3044. if($is_thread){
  3045. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  3046. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3047. foreach($use_arr as &$p){
  3048. $use_class = ($p == $post)?'focused_post':'';
  3049. $show_link = ($p == $post)?false:true;
  3050. $make_title = ($p == $post);
  3051. $this->MakeSinglePost($p,$show_link,false,$use_class,false, false, false, true, false, false);
  3052. if($make_title){?>
  3053. <script>
  3054. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3055. </script>
  3056. <?php } if($is_reversed && !$hinted){ ?>
  3057. <li class='gray smaller bold' style='text-align:center;'>
  3058. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3059. <?php $hinted = true;
  3060. if($this->LoggedIn && (!$this->InExperimentalMode)){ ?>
  3061. <div class='post_width_big hidden_on_print'>
  3062. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3063. <?php } }
  3064. }
  3065. }else{
  3066. $this->MakeSinglePost($post,false, false, 'focused_post',false, false, false, true, false, false);
  3067. ?><script>
  3068. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3069. </script><?php
  3070. } ?>
  3071. <div class='smaller align_right'>
  3072. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3073. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3074. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3075. </div>
  3076. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InExperimentalMode))){ ?>
  3077. <div class='post_width_big hidden_on_print'>
  3078. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3079. </div>
  3080. <?php }
  3081. $this->MakeCommentSection($post);
  3082. ?>
  3083. </ul>
  3084. </div>
  3085. <?php
  3086. }
  3087. function MakePostSectionExp(&$post){
  3088. $this->Anchors = []; $is_thread = isset($post['tid']);
  3089. ?>
  3090. <div class='center_exp' id='div_center'>
  3091. <ul>
  3092. <?php $is_reversed=false;
  3093. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th);
  3094. $hinted=false; if($is_reversed){
  3095. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3096. foreach($use_arr as &$p){
  3097. $this->MakeSinglePostExp($p);
  3098. if($p == $th['first']){?>
  3099. <script>
  3100. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3101. </script>
  3102. <?php } if($is_reversed && !$hinted){ ?>
  3103. <li class='gray smaller bold' style='text-align:center;'>
  3104. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3105. <?php $hinted = true; }
  3106. }
  3107. }else{
  3108. $this->MakeSinglePostExp($post);
  3109. if($post['id']!=$this->ExpIndex){ ?><script>
  3110. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3111. </script><?php }
  3112. } ?>
  3113. </ul>
  3114. </div>
  3115. <?php
  3116. }
  3117. function MakeSideGalleryCode(){?>
  3118. <div>
  3119. <h3><?=$this->T('点击图片以插入:')?></h3>
  3120. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3121. <option value="main"><?=$this->T('全部')?></option>
  3122. <?php if($this->LoggedIn){ ?>
  3123. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3124. <?php }?>
  3125. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3126. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3127. <?php } ?>
  3128. </select>
  3129. <div id='side_gallery'>
  3130. </div>
  3131. </div>
  3132. <script>
  3133. function InsertImage(imgname){
  3134. t = document.querySelector("#post_content");
  3135. v = t.value;
  3136. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3137. la_auto_grow(t);
  3138. }
  3139. function RefreshSideGallery(){
  3140. let xhr = new XMLHttpRequest();
  3141. xhr.onreadystatechange = (function(){
  3142. if (this.readyState === this.DONE) {
  3143. if (this.status === 200) {
  3144. ind = document.querySelector("#side_gallery");
  3145. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3146. str = "<ul class='side_thumb'>"
  3147. for (const m of res) {
  3148. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+
  3149. "<img src='"+m[2]+"' /></div>"
  3150. }
  3151. str += "</ul>"
  3152. ind.innerHTML = str;
  3153. }
  3154. }
  3155. }
  3156. });
  3157. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3158. xhr.send();
  3159. }
  3160. </script>
  3161. <?php
  3162. }
  3163. function MakeUploader($is_side=false){ ?>
  3164. <div id='upload_operation_area' class='hidden_on_print'>
  3165. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3166. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3167. <ul id='file_list'>
  3168. </ul>
  3169. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3170. </div>
  3171. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3172. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3173. <script>
  3174. function pastehandler(event){
  3175. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3176. for (index in items) {
  3177. var item = items[index];
  3178. if (item.kind === 'file') {
  3179. put = document.querySelector("#_uploader");
  3180. if(put) ShowSideUploader();
  3181. var blob = item.getAsFile();
  3182. AddImageFile(blob);
  3183. return;
  3184. }
  3185. }
  3186. }
  3187. let _fd_list = []; var uploading=0;
  3188. let hint=document.querySelector('#upload_hint');
  3189. function ToggleCompress(button){
  3190. li = button.parentNode;
  3191. num=li.dataset.number;
  3192. for(i=0;i<_fd_list.length;i++){
  3193. if (_fd_list[i][0] == num){
  3194. state = _fd_list[i][2];
  3195. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3196. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3197. }
  3198. }
  3199. }
  3200. function RemoveFromUpload(button){
  3201. li = button.parentNode;
  3202. num=li.dataset.number;
  3203. for(i=0;i<_fd_list.length;i++){
  3204. if (_fd_list[i][0] == num){
  3205. _fd_list.splice(i, 1);break;
  3206. }
  3207. }
  3208. li.parentNode.removeChild(li);
  3209. }
  3210. function EndThisUpload(){
  3211. unfinished = 0;
  3212. for(i=0;i<_fd_list.length;i++){
  3213. if (_fd_list[i][3]==0){
  3214. unfinished=1;
  3215. }
  3216. }
  3217. if(!unfinished){
  3218. uploading=0;
  3219. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3220. cl=document.querySelector('#upload_click');
  3221. if(!cl.dataset.isSide){
  3222. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3223. cl.href=window.location.href;
  3224. }else{
  3225. _fd_list.splice(0,_fd_list.length);
  3226. fl = document.querySelector("#file_list");
  3227. fl.innerHTML = "";
  3228. list=document.querySelector('#upload_operation_area');
  3229. list.style.pointerEvents='';
  3230. list.style.opacity='';
  3231. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3232. document.onpaste=pastehandler;
  3233. RefreshSideGallery();
  3234. }
  3235. }
  3236. }
  3237. function UploadList(){
  3238. if(!_fd_list.length || uploading) return;
  3239. uploading=1;
  3240. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3241. list=document.querySelector('#upload_operation_area');
  3242. list.style.pointerEvents='none';
  3243. list.style.opacity='0.5';
  3244. document.onpaste="";
  3245. for(i=0;i<_fd_list.length;i++){
  3246. let xhr = new XMLHttpRequest();
  3247. //xmlHTTP.upload.addEventListener("loadstart", loadStartFunction, false);
  3248. //xmlHTTP.upload.addEventListener("progress", progressFunction, false);
  3249. //xmlHTTP.addEventListener("load", transferCompleteFunction, false);
  3250. //xmlHTTP.addEventListener("error", uploadFailed, false);
  3251. //xmlHTTP.addEventListener("abort", uploadCanceled, false);
  3252. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3253. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3254. function wrap(li, i){
  3255. var ind = li.querySelector('._compress_toggle')
  3256. return function(){
  3257. if (this.readyState === this.DONE) {
  3258. if (this.status === 200) {
  3259. var response = xhr.responseText;
  3260. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3261. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3262. _fd_list[i][3] = 1;
  3263. }else{
  3264. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3265. _fd_list[i][3] = 1;
  3266. }
  3267. EndThisUpload();
  3268. }
  3269. }
  3270. }
  3271. }
  3272. xhr.onreadystatechange = wrap(li, i);
  3273. xhr.send(_fd_list[i][1]);
  3274. }
  3275. }
  3276. function AddImageFile(blob){
  3277. var ext="";
  3278. if(blob.name.match(/png$/))ext = 'png';
  3279. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3280. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3281. else if(blob.name.match(/gif$/))ext = 'gif';
  3282. else return;
  3283. var fd = new FormData();
  3284. blob.name = blob.name=generateUID().toString();
  3285. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3286. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3287. var reader = new FileReader();
  3288. reader.onload = function(event){
  3289. fl = document.querySelector("#file_list");
  3290. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3291. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3292. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3293. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3294. fl.innerHTML+=ht;
  3295. };
  3296. reader.readAsDataURL(blob);
  3297. }
  3298. sel = document.querySelector('#upload_selector');
  3299. sel.addEventListener("change", function(){
  3300. var input = this;
  3301. function ff(file){
  3302. return function(e){
  3303. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3304. blob.name = file.name;
  3305. AddImageFile(blob);
  3306. }
  3307. }
  3308. for(i=0;i<input.files.length;i++){
  3309. if(input.files[i].size){
  3310. let reader = new FileReader();
  3311. reader.onload = ff(input.files[i]);
  3312. reader.readAsArrayBuffer(input.files[i]);
  3313. }
  3314. }
  3315. });
  3316. function generateUID() {
  3317. var firstPart = (Math.random() * 46656) | 0;
  3318. var secondPart = (Math.random() * 46656) | 0;
  3319. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3320. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3321. return firstPart + secondPart;
  3322. }
  3323. document.onpaste = pastehandler;
  3324. function dropHandler(ev) {
  3325. put = document.querySelector("#_uploader");
  3326. if(put) ShowSideUploader();
  3327. bkg=document.querySelector('#dropping_background');
  3328. bkg.style.display="none";
  3329. console.log('File(s) dropped');
  3330. ev.preventDefault();ev.stopPropagation();
  3331. if (ev.dataTransfer && ev.dataTransfer.items) {
  3332. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3333. if (ev.dataTransfer.items[i].kind === 'file') {
  3334. var file = ev.dataTransfer.items[i].getAsFile();
  3335. function ff(file){
  3336. return function(e){
  3337. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3338. blob.name = file.name;
  3339. AddImageFile(blob);
  3340. }
  3341. }
  3342. if(file){
  3343. let reader = new FileReader();
  3344. reader.onload = ff(file);
  3345. reader.readAsArrayBuffer(file);
  3346. }
  3347. }
  3348. }
  3349. } else {
  3350. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3351. function ff(file){
  3352. return function(e){
  3353. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3354. blob.name = file.name;
  3355. AddImageFile(blob);
  3356. }
  3357. }
  3358. if(ev.dataTransfer.files[i].size){
  3359. let reader = new FileReader();
  3360. reader.onload = ff(ev.dataTransfer.files[i]);
  3361. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3362. }
  3363. }
  3364. }
  3365. }
  3366. function dragOverHandler(ev) {
  3367. bkg=document.querySelector('#dropping_background');
  3368. bkg.style.display="";
  3369. console.log('File(s) in drop zone');
  3370. ev.preventDefault();
  3371. }
  3372. </script>
  3373. <?php
  3374. }
  3375. function CanShowGallery(&$g){
  3376. if(!$this->LoggedIn && isset($g['experimental']) && $g['experimental']) return false;
  3377. return true;
  3378. }
  3379. function CanShowImage(&$im){
  3380. if(!$this->LoggedIn && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3381. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3382. }
  3383. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3384. return true;
  3385. }
  3386. function MakeGallerySection(){
  3387. if(!isset($_GET['gallery'])) return;
  3388. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3389. $name=$_GET['gallery'];}?>
  3390. <script>
  3391. document.title+=" | <?=$this->T('画廊')?>";
  3392. </script>
  3393. <div class='center_wide' id='div_center' style='position:relative;'>
  3394. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3395. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3396. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3397. <div class='hidden_on_desktop'>
  3398. <?=$this->T('前往')?>
  3399. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  3400. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3401. if(!isset($g['featured']) || !$g['featured'] ||
  3402. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3403. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3404. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3405. <?php } ?>
  3406. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  3407. <?php if($this->LoggedIn){ ?>
  3408. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  3409. <?php } ?>
  3410. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3411. if((isset($g['featured']) && $g['featured']) ||
  3412. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3413. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3414. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3415. <?php } ?>
  3416. </select>
  3417. </div>
  3418. <?php if($this->LoggedIn){?>
  3419. <div>
  3420. <?php if(isset($name)){ ?>
  3421. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  3422. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  3423. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  3424. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  3425. <?=$this->T('取消精选')?></a>
  3426. <?php }else{ ?>
  3427. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  3428. <?=$this->T('设为精选')?></a>
  3429. <?php } ?><br />
  3430. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  3431. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  3432. <?=$this->T('取消实验')?></a>
  3433. <?php }else{ ?>
  3434. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  3435. <?=$this->T('设为实验')?></a>
  3436. <?php } ?>
  3437. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  3438. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  3439. <a href='javascript:HidePopMenu();'>×</a>
  3440. <hr />
  3441. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  3442. </div>
  3443. </div>
  3444. <?php } ?>
  3445. <?php $this->MakeUploader(false); ?>
  3446. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  3447. <div style='position:relative'>
  3448. <?php if(isset($name)){ ?>
  3449. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  3450. <?php } ?>
  3451. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  3452. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  3453. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  3454. method="post" style='display:none;' id='gallery_edit_form'></form>
  3455. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  3456. <a href='javascript:HidePopMenu();'>×</a>
  3457. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  3458. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  3459. <input class='button' type='submit' form='gallery_edit_form'
  3460. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  3461. </div>
  3462. </div>
  3463. </div>
  3464. <div class='smaller hidden_on_print'>
  3465. <form action="<?=$_SERVER['REQUEST_URI']?>"
  3466. method="post" style='display:none;' id='gallery_move_form'></form>
  3467. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  3468. id='gallery_move_ops' style='display:none'>
  3469. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  3470. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  3471. <p><?=$this->T('添加到')?>
  3472. <select id="gallery_move_to">
  3473. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3474. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3475. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  3476. <?php } ?>
  3477. </select>
  3478. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  3479. </p>
  3480. <p>
  3481. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  3482. </p>
  3483. </div>
  3484. </div>
  3485. <?php } ?>
  3486. <p>&nbsp;</p>
  3487. <div>
  3488. <?php $opened=0; $prev_year=""; if(isset($this->Images[0])) foreach($this->Images as $im){
  3489. if(!$this->CanShowImage($im)){ continue; }
  3490. if($_GET['gallery']=='trash') $name='trash';
  3491. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;}
  3492. $year = substr($im['name'], 0, 4);
  3493. if($year!=$prev_year){
  3494. if($opened) { ?><div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div></div><?php } ?>
  3495. <div><h2 class='sticky_title'><?=$year;?></h2><div class='p_row'><?php $prev_year=$year; $opened=1; } ?>
  3496. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  3497. <?php if($this->LoggedIn){ ?>
  3498. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3499. <?php } ?>
  3500. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  3501. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  3502. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  3503. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>/></a>
  3504. </div>
  3505. <?php } if($opened) { ?>
  3506. <div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div><?php } ?>
  3507. </div>
  3508. </div>
  3509. <?php if($this->LoggedIn){ ?>
  3510. <script type='text/javascript'>
  3511. var selected_image = new Array();
  3512. function RemoveFromGallery(){
  3513. form = document.querySelector('#gallery_move_form');
  3514. ops = document.querySelector('#gallery_move_ops');
  3515. sel = document.querySelector('#gallery_move_to');
  3516. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  3517. form.submit();
  3518. }
  3519. function AddToGallery(){
  3520. form = document.querySelector('#gallery_move_form');
  3521. ops = document.querySelector('#gallery_move_ops');
  3522. sel = document.querySelector('#gallery_move_to');
  3523. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  3524. form.submit();
  3525. }
  3526. function ClearSelectedImages(){
  3527. selected_image.splice(0, selected_image.length);
  3528. checks = document.querySelectorAll('._select_hook');
  3529. [].forEach.call(checks, function(c){
  3530. c.classList.remove('p_thumb_selected');
  3531. });
  3532. count = document.querySelector('#gallery_selected_count');
  3533. count.innerHTML="0";
  3534. }
  3535. function ToggleSelectImage(elem, name){
  3536. count = document.querySelector('#gallery_selected_count');
  3537. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  3538. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  3539. count.innerHTML=selected_image.length.toString()
  3540. }
  3541. function ShowGalleryEditMenu(old_name){
  3542. m = document.querySelector('#gallery_edit_menu');
  3543. old = document.querySelector('#gallery_edit_old_name');
  3544. newname = document.querySelector('#gallery_edit_new_name');
  3545. m.style.display='block';
  3546. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  3547. }
  3548. function ShowDeleteMenu(){
  3549. m=document.querySelector('#gallery_delete_menu');
  3550. m.style.display='block';
  3551. }
  3552. </script>
  3553. <?php } ?>
  3554. <?php
  3555. }
  3556. function MakeGalleryLeft(){?>
  3557. <div class='left hidden_on_mobile gallery_left' id='div_left'>
  3558. <h2><?=$this->T('相册')?></h2>
  3559. <div>
  3560. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  3561. <ul>
  3562. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3563. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  3564. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3565. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  3566. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3567. <?php } ?>
  3568. </ul>
  3569. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  3570. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  3571. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  3572. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3573. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  3574. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3575. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  3576. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3577. <?php } ?>
  3578. <?php if($this->LoggedIn){ ?>
  3579. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  3580. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  3581. <?php } ?>
  3582. </ul></div>
  3583. <p>&nbsp;</p>
  3584. <script>
  3585. </script>
  3586. </div>
  3587. </div>
  3588. <?php
  3589. }
  3590. function MakeTOC(){?>
  3591. <div class='right hidden_on_mobile' id='div_right'>
  3592. <?php if(isset($this->Anchors[0])){?>
  3593. <h2><?=$this->T('目录')?></h2><ul>
  3594. <?php
  3595. foreach($this->Anchors as $a){?>
  3596. <li class='toc_entry_<?=$a[0]>5?5:$a[0]?>'><a href='#<?=$a[1]?>'><?=$this->T($a[2])?></a></li>
  3597. <?php }
  3598. ?></ul>
  3599. <?php }else{ ?>
  3600. <h2 class='gray'><?=$this->T('目录')?></h2>
  3601. <span class='gray smaller'><?=$this->T('未找到目录')?></span>
  3602. <?php } ?>
  3603. </div>
  3604. <?php
  3605. }
  3606. function MakeSettings(){?>
  3607. <div class='settings'>
  3608. <h2><?=$this->T('设置')?></h2>
  3609. <table style='white-space:nowrap;'>
  3610. <?php if($this->LoggedIn){ ?>
  3611. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  3612. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  3613. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  3614. <tr><td><?=$this->T('网站标题')?></td>
  3615. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  3616. value='<?=$this->Title?>'/></td></tr>
  3617. <tr><td><?=$this->T('短标题')?></td>
  3618. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  3619. value='<?=$this->ShortTitle?>'/></td></tr>
  3620. <tr><td><?=$this->T('显示名称')?></td>
  3621. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  3622. value='<?=$this->DisplayName?>'/></td></tr>
  3623. <tr><td><?=$this->T('电子邮件')?></td>
  3624. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  3625. value='<?=$this->EMail?>'/></td></tr>
  3626. <tr><td><?=$this->T('导航栏')?>
  3627. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  3628. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  3629. value='<?=$this->SpecialNavigation?>'/></td></tr>
  3630. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  3631. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  3632. value='<?=$this->SpecialFooter?>'/></td></tr>
  3633. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  3634. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  3635. value='<?=$this->SpecialFooter2?>'/></td></tr>
  3636. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  3637. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  3638. value='<?=$this->SpecialPinned?>'/></td></tr>
  3639. <tr><td><?=$this->T('默认相册')?></td>
  3640. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  3641. value='<?=$this->DefaultGallery?>'/></td></tr>
  3642. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  3643. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  3644. value='<?=$this->SelfAuthPath?>'/></td></tr>
  3645. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  3646. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  3647. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  3648. <tr><td class='smaller gray'>&nbsp;</td></tr>
  3649. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  3650. <tr><td><?=$this->T('主机')?><?=isset($this->ExpHost)?"<a href='?post=".$this->ExpHost."'>→</a>":""?></td>
  3651. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  3652. value='<?=$this->ExpHost?>'/></td></tr>
  3653. <tr><td><?=$this->T('网站标题')?></td>
  3654. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  3655. value='<?=$this->ExpTitle?>'/></td></tr>
  3656. <tr><td><?=$this->T('短标题')?></td>
  3657. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  3658. value='<?=$this->ExpShortTitle?>'/></td></tr>
  3659. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  3660. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  3661. value='<?=$this->ExpCaution?>'/></td></tr>
  3662. <tr><td><?=$this->T('索引')?><?=isset($this->ExpIndex)?"<a href='?post=".$this->ExpIndex."'>→</a>":""?></td>
  3663. <td><input type="text" form="settings_form" id='settings_exp_index' name='settings_exp_index'
  3664. value='<?=$this->ExpIndex?>'/></td></tr>
  3665. <tr><td><?=$this->T('导航栏')?>
  3666. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  3667. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  3668. value='<?=$this->ExpNavigation?>'/></td></tr>
  3669. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  3670. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  3671. value='<?=$this->ExpFooter?>'/></td></tr>
  3672. <tr><td class='smaller gray'>&nbsp;</td></tr>
  3673. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  3674. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  3675. <tr><td><?=$this->T('帐号')?></td>
  3676. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  3677. value='<?=$this->Admin?>'/></td></tr>
  3678. <tr><td><?=$this->T('新密码')?></td>
  3679. <td><input type="password" form="settings_form"
  3680. id='settings_new_password' name='settings_new_password' /></td></tr>
  3681. <tr><td><?=$this->T('再次输入')?></td>
  3682. <td><input type="password" form="settings_form"
  3683. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  3684. <tr><td><?=$this->T('旧密码')?></td>
  3685. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  3686. <?php }else{ ?>
  3687. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  3688. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  3689. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  3690. <tr><td><?=$this->T('帐号')?></td>
  3691. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  3692. <tr><td><?=$this->T('密码')?></td>
  3693. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  3694. <?php } ?>
  3695. </table>
  3696. <?php if($this->LoggedIn){ ?>
  3697. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  3698. <?php }else{ ?>
  3699. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  3700. <?php } ?>
  3701. </div>
  3702. <?php
  3703. }
  3704. function MakeExtraOperations(){?>
  3705. <div class='settings' style='overflow:auto;'>
  3706. <h2><?=$this->T('附加操作')?></h2>
  3707. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  3708. <p>&nbsp;</p>
  3709. <h3><?=$this->T('自动重定向')?></h3>
  3710. <span class='smaller gray'>
  3711. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  3712. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  3713. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  3714. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  3715. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  3716. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  3717. value='<?=$this->T('保存重定向设置')?>' />
  3718. <p>&nbsp;</p>
  3719. <h3><?=$this->T('自定义翻译')?></h3>
  3720. <span class='smaller gray'>
  3721. <?=$this->T('填写格式:')?>
  3722. <br /><pre>- 语言 | Language</pre></span>
  3723. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  3724. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  3725. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  3726. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  3727. value='<?=$this->T('保存翻译')?>' />
  3728. <p>&nbsp;</p>
  3729. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  3730. <ul>
  3731. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  3732. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  3733. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  3734. </ui>
  3735. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  3736. </div>
  3737. <?php
  3738. }
  3739. function MakeMainBegin(){?>
  3740. <div class='main' <?php if(!$this->InExperimentalMode){ ?>
  3741. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  3742. <?php
  3743. }
  3744. function MakeMainEnd(){?>
  3745. </div>
  3746. <?php
  3747. }
  3748. function MakeExpFooter(){?>
  3749. <div class='small_footer'>
  3750. <hr />
  3751. <b><?=$this->T($this->ExpTitle)?></b>&nbsp;©<?=$this->T($this->DisplayName)?>
  3752. </div>
  3753. <div class='footer'>
  3754. <div style='white-space:nowrap;'>
  3755. <div class='footer_additional'>
  3756. <?php if(isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  3757. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false));
  3758. } ?>
  3759. </div>
  3760. </div>
  3761. </div>
  3762. </div><!-- page -->
  3763. </body>
  3764. </html>
  3765. <script>
  3766. if(trans = document.getElementById('translate_button')){
  3767. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  3768. }
  3769. </script>
  3770. <?php
  3771. }
  3772. function MakeImageOverlay($side_info=null,$static_image=null){
  3773. $static=isset($side_info); ?>
  3774. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  3775. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  3776. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  3777. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/>
  3778. </div>
  3779. <div class='big_side_box' onclick='HideBigImage(1);'>
  3780. <?php if(!$static){ ?>
  3781. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  3782. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  3783. <div class='lr_buttons'>←</div></a></div>
  3784. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  3785. <div class='lr_buttons'>→</div></a></div>
  3786. </div><?php } ?>
  3787. <div class='side_box_mobile_inner'>
  3788. <?php if(!$static){ ?>
  3789. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  3790. <span style='display:none;' id='image_purchase' class='clean_a'>
  3791. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  3792. <br class='hidden_on_desktop block_on_mobile' /></span>
  3793. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  3794. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  3795. &nbsp;<a class='clean_a' id='image_inquiry'>
  3796. <b>@</b><?=$this->T('咨询')?></a>
  3797. <?php } ?><hr class='hidden_on_desktop block_on_mobile' />
  3798. </div>
  3799. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  3800. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  3801. <hr />
  3802. </div><?php } //static ?>
  3803. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  3804. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  3805. <br /><?=$this->T('印刷品链接')?>
  3806. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  3807. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  3808. <?=$this->T('重命名')?>
  3809. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  3810. <?=$this->T('主图')?>
  3811. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  3812. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  3813. <br /><br /><?=$this->T('替换图像')?>
  3814. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  3815. <input type="file" form='image_edit_form'
  3816. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  3817. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  3818. value=<?=$this->T('执行')?> />
  3819. </div><?php } ?>
  3820. </div>
  3821. </div>
  3822. </div>
  3823. <?php }
  3824. function MakePageEnd(){?>
  3825. </div><!-- page -->
  3826. </body>
  3827. </html>
  3828. <?php }
  3829. function MakeFooter(){?>
  3830. <div class='small_footer'><div>
  3831. <hr />
  3832. <b><?=$this->T($this->Title)?></b>
  3833. <span onclick='event.stopPropagation()'
  3834. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  3835. <div class='wayback_link clean_a invert_a hidden_on_print'><?php if(!isset($this->WayBack)){ ?>
  3836. - <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  3837. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?>
  3838. <br class='hidden_on_desktop' /> - <a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  3839. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a>
  3840. </div>
  3841. </div></div>
  3842. <div class='footer'>
  3843. <div style='white-space:nowrap;'>
  3844. <div class='footer_additional'>
  3845. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  3846. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false));
  3847. } ?>
  3848. </div>
  3849. <div class='footer_additional'>
  3850. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  3851. echo $this->TranslatePostParts($this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false));
  3852. } ?>
  3853. </div>
  3854. </div>
  3855. </div>
  3856. <p>&nbsp;<p>
  3857. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  3858. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  3859. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  3860. </div>
  3861. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  3862. <script>
  3863. <?=$this->ExtraScripts?>
  3864. if(back = document.getElementById('button_back')){
  3865. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  3866. back.href='javascript:history.back()';
  3867. }else{
  3868. back.href='index.php';
  3869. }
  3870. }
  3871. function copy_text(t) {
  3872. ta = document.createElement('textarea');
  3873. document.body.appendChild(ta);
  3874. ta.value = t;
  3875. ta.select();
  3876. document.execCommand("copy");
  3877. document.body.removeChild(ta);
  3878. }
  3879. if(trans = document.getElementById('translate_button')){
  3880. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  3881. }
  3882. <?php if($this->LoggedIn){ ?>
  3883. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  3884. var Scenter = document.querySelector('#div_center');
  3885. var Sposts = Scenter.querySelectorAll('.post');
  3886. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  3887. var Smerge_post = Scenter.querySelector('#merge_post');
  3888. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  3889. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  3890. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  3891. var Smerge_select = Scenter.querySelector('#merge_select');
  3892. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  3893. var Smerge_thread = Scenter.querySelector('#merge_thread');
  3894. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  3895. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  3896. var select_mode = false; var merge_mode = false; var selected_posts = null;
  3897. function TogglePostSelectMode(force_on=false,force_off=false){
  3898. Scenter.classList.add('post_selecting');
  3899. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  3900. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  3901. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  3902. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  3903. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  3904. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  3905. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  3906. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  3907. Smerge_post_count.innerText="0";
  3908. Smerge_post.href="#";
  3909. }
  3910. function TogglePostSelect(elem){
  3911. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  3912. else{ elem.classList.add('post_selected'); }
  3913. selected_posts = new Array();
  3914. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  3915. selected_posts.push(Sposts[i].dataset.postId); } }
  3916. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  3917. Smerge_post_count.innerText=selected_posts.length;
  3918. }
  3919. function ThreadMergeInput(elem){
  3920. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  3921. else{ Smerge_thread.href="#"; }
  3922. }
  3923. function ToggleThreadMerge(force_on=false,force_off=false){
  3924. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  3925. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  3926. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  3927. else{ merge_mode = 0;
  3928. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  3929. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  3930. Smerge_thread.href="#";
  3931. Smerge_thread_target.value='';
  3932. }
  3933. <?php } ?>
  3934. function ShowSideUploader(){
  3935. ShowRightSide(true,null);
  3936. put = document.querySelector("#_uploader");
  3937. put.style.display='block';
  3938. RefreshSideGallery();
  3939. }
  3940. dmark = document.querySelector("#mark_details");
  3941. drename = document.querySelector("#rename_details");
  3942. drename_form = document.querySelector("#post_rename_form");
  3943. drename_input = document.querySelector("#post_rename_name");
  3944. var rp = document.querySelector('#post_reply_to');
  3945. var _reply_to = rp?rp.defaultValue:"";
  3946. function RestoreReply(){
  3947. if(rp){
  3948. rp.defaultValue = _reply_to;
  3949. }
  3950. document.querySelector('#post_reply_restore').style.display='none';
  3951. ht = document.querySelector('#post_hint_text');
  3952. if (_reply_to!=""){
  3953. ht.style.display='block';
  3954. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  3955. }else{
  3956. ht.style.display='none';
  3957. }
  3958. document.querySelector('#post_edit_target').value="";
  3959. ch = document.querySelector('#post_hint_modify');
  3960. ch.style.display='none';
  3961. }
  3962. function MakeRefer(id){
  3963. t = document.querySelector('#post_content')
  3964. t.focus();
  3965. v = t.value;
  3966. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  3967. la_auto_grow(t);
  3968. if(rp){
  3969. rp.defaultValue = "";
  3970. ht = document.querySelector('#post_hint_text');
  3971. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  3972. document.querySelector('#post_reply_restore').style.display='inline';
  3973. rs = document.querySelector('#post_reply_restore');
  3974. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  3975. document.getElementById('post_menu').style.display='none';
  3976. ch = document.querySelector('#post_hint_modify');
  3977. ch.style.display='none';
  3978. }
  3979. }
  3980. function CopyRefer(id){
  3981. copy_text(id.toString());
  3982. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  3983. }
  3984. function MakeEdit(id){
  3985. ed = document.getElementById('menu_edit');
  3986. ed.innerHTML="<?=$this->T('稍等')?>";
  3987. ed.href="#";
  3988. var xhr = new XMLHttpRequest();
  3989. xhr.onreadystatechange = function() {
  3990. if (this.readyState == 4 && this.status == 200) {
  3991. ed.innerHTML='——';
  3992. ch = document.querySelector('#post_hint_modify');
  3993. ch.style.display='block';
  3994. ht = document.querySelector('#post_hint_text');
  3995. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  3996. rs = document.querySelector('#post_reply_restore');
  3997. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  3998. t = document.querySelector('#post_content');
  3999. t.value=xhr.responseText.trim();
  4000. t.focus();
  4001. la_auto_grow(t);
  4002. document.querySelector('#post_edit_target').value=id;
  4003. document.getElementById('post_menu').style.display='none';
  4004. }
  4005. };
  4006. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4007. xhr.send();
  4008. }
  4009. function MarkDelete(id){
  4010. p = document.querySelector('[data-post-id="'+id+'"]');
  4011. op = p.dataset.markDelete?"false":"true";
  4012. window.location.href=
  4013. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4014. }
  4015. function SetMark(mark){
  4016. menu = document.getElementById('post_menu');
  4017. window.location.href=
  4018. "index.php?<?=$this->GetRedirect()?>&target="+
  4019. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4020. }
  4021. function ToggleMarkDetails(){
  4022. if(dmark.style.display=='block') dmark.style.display='none';
  4023. else dmark.style.display='block';
  4024. }
  4025. function ToggleRenameDetails(){
  4026. if(drename.style.display=='block') drename.style.display='none';
  4027. else drename.style.display='block';
  4028. }
  4029. <?php } ?>
  4030. function ShowPostMenu(post){
  4031. menu = document.getElementById('post_menu');
  4032. menu.style.display='block';
  4033. menu.parentNode.removeChild(menu);
  4034. post.appendChild(menu);
  4035. menu.style.display='block';
  4036. id = post.dataset.postId
  4037. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4038. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4039. window.onClick="HidePopMenu()";
  4040. menu.onClick=(function(event){
  4041. event.stopPropagation();
  4042. });
  4043. hs = menu.querySelector('#menu_history');
  4044. hs.href='?post='+id+'&history=1';
  4045. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4046. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4047. ref = menu.querySelector('#menu_refer_copy')
  4048. ref.innerHTML='<?=$this->T("复制编号")?>';
  4049. ref.href='javascript:CopyRefer(id)';
  4050. ed = menu.querySelector('#menu_edit')
  4051. ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4052. d = menu.querySelector('#menu_delete');
  4053. d.href='javascript:MarkDelete(\"'+id+'\")';
  4054. p = document.querySelector('[data-post-id="'+id+'"]');
  4055. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4056. menu.querySelector('#mark_details').dataset.id=id;
  4057. drename_input.value=id;
  4058. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4059. <?php } ?>
  4060. title = document.title;
  4061. copy = document.getElementById('share_copy');
  4062. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4063. copy.addEventListener("click", function(){
  4064. url = window.location
  4065. path = location.pathname
  4066. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4067. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4068. });
  4069. }
  4070. function HidePopMenu(){
  4071. var menus = document.querySelectorAll('.pop_menu');
  4072. [].forEach.call(menus, function(m){m.style.display='none';});
  4073. }
  4074. var posts = document.querySelectorAll('.center .post');
  4075. [].forEach.call(posts, function(p){
  4076. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4077. ShowPostMenu(this.parentNode.parentNode);
  4078. });
  4079. });
  4080. var post_clickables = document.querySelectorAll('.center .post a');
  4081. [].forEach.call(post_clickables, function(p){
  4082. p.addEventListener("click", function(event){
  4083. event.stopPropagation();
  4084. });
  4085. });
  4086. function FindImage(imgsrc){
  4087. for(var i=0;i<document.images_filtered.length;i++){
  4088. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4089. }
  4090. return null
  4091. }
  4092. var dottime1;
  4093. var dottime2;
  4094. function ToDataURL(url) {
  4095. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4096. clearTimeout(dottime1);clearTimeout(dottime2);
  4097. ps = document.querySelector('#download_processing');
  4098. ps.innerHTML='↓';ps.style.opacity='';
  4099. return URL.createObjectURL(blob);});
  4100. }
  4101. async function DownloadAsImage(url,name) {
  4102. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4103. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4104. }
  4105. function basename(url){return url.split(/[\\/]/).pop();}
  4106. pushed=0;
  4107. function ShowBigImage(imgsrc,do_push){
  4108. ShowWaitingBar();
  4109. share = document.querySelector('#big_image_share');
  4110. img = document.querySelector('#big_image');
  4111. down = document.querySelector('#image_download');
  4112. img.src = "";
  4113. img.src = src = "images/"+imgsrc;
  4114. down.href="images/"+imgsrc;
  4115. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_+<?=$this->GiveSafeEMail()?>+_'+
  4116. basename(down.href);
  4117. img.alt = downname; down.download=downname;
  4118. var use_href = "images/"+imgsrc;
  4119. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4120. ps = this.querySelector('#download_processing');ps.innerText='…';
  4121. var dotwait = function(ps){ var self = this;
  4122. dottime1 = setTimeout(function(ps){
  4123. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4124. dotwait(this.querySelector('#download_processing'));
  4125. DownloadAsImage(use_href,downname);};
  4126. if(do_push){PushGalleryHistory(src)}
  4127. page_url = encodeURIComponent(window.location.href);
  4128. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4129. inqb = document.querySelector('#image_inquiry');
  4130. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4131. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4132. (page_url)+encodeURIComponent('\n\n');
  4133. <?php } ?>
  4134. this_image = FindImage(imgsrc);
  4135. if(this_image.dataset.prevsrc){
  4136. new_image = FindImage(this_image.dataset.prevsrc);
  4137. new_prev = new_image?new_image.dataset.prevsrc:null;
  4138. im = document.querySelector('#prev_image');
  4139. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4140. else {im.style.opacity='0';im.removeAttribute("href");}
  4141. }
  4142. if(this_image.dataset.nextsrc){
  4143. new_image = FindImage(this_image.dataset.nextsrc);
  4144. new_next = new_image?new_image.dataset.nextsrc:null;
  4145. im = document.querySelector('#next_image');
  4146. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4147. else {im.style.opacity='0';im.removeAttribute("href");}
  4148. }
  4149. purchase = document.querySelector('#image_purchase');
  4150. purchase_btn = document.querySelector('#image_purchase_button');
  4151. <?php if($this->LoggedIn){ ?>
  4152. product_link = document.querySelector('#image_ops_product_link');
  4153. product_form = document.querySelector('#image_ops_form');
  4154. edit_form = document.querySelector('#image_edit_form');
  4155. edit_new_name = document.querySelector('#image_edit_new_name');
  4156. edit_parent = document.querySelector('#image_parent');
  4157. product_form.action = window.location.href;
  4158. edit_form.action = window.location.href;
  4159. edit_new_name.value = imgsrc.split('.')[0];
  4160. if(this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  4161. if(this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  4162. <?php } ?>
  4163. if(this_image.dataset.product){
  4164. purchase.style.display='';
  4165. href = this_image.dataset.product;
  4166. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4167. href = '?post='+href;
  4168. }
  4169. purchase_btn.href = href;
  4170. }else{
  4171. purchase.style.display='none';
  4172. purchase_btn.removeAttribute("href");
  4173. }
  4174. DelayHideImgBtn(null);
  4175. title = encodeURIComponent(document.title);
  4176. copy = document.getElementById('big_share_copy');
  4177. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4178. copy.addEventListener("click", function(){
  4179. copy_text(window.location.href);
  4180. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4181. });
  4182. o = document.querySelector('#big_image_overlay');
  4183. info = document.querySelector('#big_image_info');
  4184. info.innerHTML="<?=$this->T('正在查询……')?>";
  4185. o.style.display="block";
  4186. ShowBackdrop(0.8);
  4187. var xhr = new XMLHttpRequest();
  4188. xhr.onreadystatechange = function() {
  4189. if (this.readyState == 4 && this.status == 200) {
  4190. info = document.querySelector('#big_image_info');
  4191. var response = xhr.responseText;
  4192. let content=""
  4193. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4194. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4195. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4196. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4197. content+="<div class='clean_a'>"+res[1]+"</div>";
  4198. }
  4199. info.innerHTML=content;
  4200. }
  4201. };
  4202. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4203. xhr.send();
  4204. }
  4205. function HideBigImage(do_push){
  4206. o = document.querySelector('#big_image_overlay');
  4207. img = document.querySelector('#big_image');
  4208. img.src = "";
  4209. if(o.style.display!='none'){
  4210. o.style.display="none";
  4211. HideBackdrop();
  4212. if(do_push){PushGalleryHistory("");}
  4213. HideWaitingBar();
  4214. }
  4215. }
  4216. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4217. var inq=document.querySelector('#inquiry_buttons');
  4218. var overlay=document.querySelector('#big_image_overlay');
  4219. var hide_timeout;
  4220. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4221. function DelayHideImgBtn(e){
  4222. lbtn.classList.remove('img_btn_hidden');
  4223. rbtn.classList.remove('img_btn_hidden');
  4224. inq.classList.remove('img_btn_hidden');
  4225. clearTimeout(hide_timeout);
  4226. hide_timeout = setTimeout(function(e1,e2,e3){e1.classList.add('img_btn_hidden');
  4227. e2.classList.add('img_btn_hidden');
  4228. e3.classList.add('img_btn_hidden');}, 1000, lbtn, rbtn, inq);
  4229. }
  4230. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4231. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4232. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4233. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4234. var images = document.querySelectorAll('img');
  4235. var images_filtered=new Array(); var imgadded = new Array();
  4236. var images_remaining=new Array();
  4237. [].forEach.call(images, function(img){
  4238. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4239. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4240. images_filtered.push(img);imgadded.push(imgsrc);
  4241. });
  4242. for(var i=0; i<images_filtered.length; i++){
  4243. previmg = nextimg = null; img = images_filtered[i];
  4244. if(i>0) previmg=images_filtered[i-1];
  4245. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4246. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4247. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4248. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4249. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4250. }
  4251. for(var i=0; i<images_remaining.length; i++){
  4252. img = images_remaining[i];
  4253. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4254. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4255. }
  4256. document.images_filtered = images_filtered;
  4257. function PopGalleryHistory(){
  4258. if(pushed){
  4259. pushed = 0;
  4260. try{
  4261. history.back();
  4262. }catch{
  4263. console.log("can't do it.");
  4264. }
  4265. }
  4266. }
  4267. function PushGalleryHistory(src){
  4268. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  4269. title = "照片"
  4270. extra = "?";
  4271. sp = new URLSearchParams(window.location.search)
  4272. if(sp.has('post')){extra+="post="+sp.get('post')}
  4273. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  4274. try{
  4275. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  4276. }catch{
  4277. console.log("can't do it.");
  4278. }
  4279. pushed = 1;
  4280. }
  4281. document.addEventListener('keydown', function(e){
  4282. large = document.getElementById('big_image_overlay')
  4283. if (large.style.display!='block') return;
  4284. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  4285. HideBigImage(1);
  4286. }
  4287. }, true);
  4288. window.addEventListener('popstate', (event) => {
  4289. if(event.state){
  4290. let sp = new URLSearchParams(event.state)
  4291. if(sp.has('pic')){
  4292. src = sp.get('pic')
  4293. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)) ShowBigImage(onlyimg[0], 0);
  4294. else{HideBigImage(0);}
  4295. }
  4296. }else{HideBigImage(0);}
  4297. });
  4298. let searchParams = new URLSearchParams(window.location.search)
  4299. if(searchParams.has('pic')){
  4300. src = searchParams.get('pic')
  4301. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)){
  4302. ShowBigImage(onlyimg[0], 1);
  4303. }
  4304. }
  4305. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  4306. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  4307. </script>
  4308. </body>
  4309. <?php
  4310. }
  4311. function DoIdentiyExperimental(){
  4312. if(!isset($this->ExpHost) || $this->ExpHost=="") return;
  4313. if(preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  4314. $this->InExperimentalMode=True;
  4315. }
  4316. if(!$this->CurrentPostID && $this->InExperimentalMode){
  4317. $this->CurrentPostID = $this->ExpIndex;
  4318. }
  4319. }
  4320. function DoExperimentalTopLink($p){
  4321. if($this->InExperimentalMode && $p){
  4322. if(isset($p['tid']) && $p['tid']['first']!=$p){
  4323. header('Location: ?post='.$p['tid']['first']['id']); exit();
  4324. }
  4325. }
  4326. }
  4327. function MakeExperimentalConfirm(){
  4328. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  4329. return false;
  4330. }
  4331. $caution_html =
  4332. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  4333. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  4334. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  4335. ?>
  4336. <div class='center_exp'><?php
  4337. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  4338. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  4339. ?></div>
  4340. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  4341. <?php return true;
  4342. }
  4343. }
  4344. $la = new LA;
  4345. $la->DoSiteRedirect();
  4346. $la->DoLogin();
  4347. $err = $la->ProcessRequest($message, $redirect);
  4348. $la->WriteAsNecessary();
  4349. $la->DoIdentiyExperimental();
  4350. $la->SwitchLanguageAndFont();
  4351. $la->SwitchWayBackMode();
  4352. if($err){
  4353. echo $message;
  4354. exit();
  4355. }
  4356. if(isset($redirect)){
  4357. header('Location: '.$redirect);
  4358. exit();
  4359. }
  4360. $la->DetectPageType();
  4361. $la->ReadImages(false);
  4362. $la->ReadPosts();
  4363. if(isset($la->WayBack)){
  4364. $la->ReadArchive();
  4365. }
  4366. $p = &$la->GetPost($la->CurrentPostID);
  4367. if(!isset($p)){
  4368. $p = &$la->GetMergedPost($la->CurrentPostID);
  4369. }
  4370. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  4371. else{ $la->DoExperimentalTopLink($p); }
  4372. if(isset($p)){ $la->ActualPostID = $p['id']; }
  4373. $la->MakeHeader($p);
  4374. $la->MakeMainBegin();
  4375. if($la->PageType=='experimental'){
  4376. if(!$la->MakeExperimentalConfirm()){
  4377. if($p){
  4378. $la->MakePostSectionExp($p);
  4379. $la->MakeLinkedPostsExp($p);
  4380. }else{
  4381. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4382. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4383. }
  4384. }
  4385. $la->MakeMainEnd();
  4386. $la->MakeExpFooter();
  4387. }else{
  4388. if($la->PageType=='extras'){
  4389. $la->MakeExtraOperations();
  4390. }else if($la->PageType=='settings'){
  4391. $la->MakeSettings();
  4392. }else if($la->PageType=='gallery'){
  4393. $la->MakeGalleryLeft();
  4394. $la->MakeGallerySection();
  4395. }else if($la->PageType=='post'){
  4396. if($p){
  4397. $made_interesting = false;
  4398. if($la->IsInterestingPost($p)){
  4399. $la->MakeInterestingSection($p['tid']);
  4400. }
  4401. else{
  4402. $la->MakeLinkedPosts($p);
  4403. $la->MakePostSection($p);
  4404. $la->MakeTOC();
  4405. }
  4406. }else{
  4407. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4408. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4409. }
  4410. }else if($la->PageType=='history'){
  4411. $la->ReadArchive();
  4412. $la->MakePostHistory($p, $_GET['version']??NULL);
  4413. }else if($la->PageType=='search'){
  4414. $la->MakeHotPosts(true);
  4415. $la->MakeRecentPosts($_GET['search']);
  4416. }else if($la->PageType=='category'){
  4417. $la->MakeHotPosts(true);
  4418. $la->MakeRecentPosts(NULL,$_GET['category']);
  4419. }else if($la->PageType=='comments'){
  4420. $la->MakeCommentPosts();
  4421. }else{
  4422. $la->MakeHotPosts();
  4423. $la->MakeRecentPosts();
  4424. }
  4425. $la->MakeMainEnd();
  4426. $la->MakeFooter();
  4427. }
  4428. ?>