*/}}

index.php 262 KB

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