*/}}

index.php 269 KB

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