*/}}

index.php 287 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149
  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 $HereHost;
  24. protected $HereTitle;
  25. protected $HereShortTitle;
  26. protected $HereAlbum;
  27. protected $HereNavigation;
  28. protected $HereFooter;
  29. protected $ExpHost;
  30. protected $ExpAlbum;
  31. protected $ExpTitle;
  32. protected $ExpShortTitle;
  33. protected $ExpCaution;
  34. protected $ExpNavigation;
  35. protected $ExpFooter;
  36. protected $CommentEnabled;
  37. protected $MastodonToken;
  38. protected $MastodonURL;
  39. protected $MastodonPreferredLang;
  40. protected $HostURL;
  41. protected $Redirect;
  42. protected $Translations;
  43. protected $CustomTranslationContent;
  44. protected $CurrentOffset;
  45. protected $PostsPerPage;
  46. protected $HotPostCount;
  47. protected $LoggedIn;
  48. protected $LoginTokens;
  49. protected $InHereMode;
  50. protected $InExperimentalMode;
  51. protected $LanguageAppendix;
  52. protected $UseRemoteFont;
  53. protected $Posts;
  54. protected $Threads; // [ keys: first last displayed count]
  55. protected $WaybackThreads;
  56. protected $Images;
  57. protected $Galleries;
  58. protected $Anchors;
  59. protected $ArchiveHandles;
  60. protected $Archive;
  61. public $WayBack;
  62. protected $YearBegin;
  63. protected $YearEnd;
  64. protected $Markers;
  65. protected $ExtraScripts;
  66. protected $APubID;
  67. protected $APubActor;
  68. protected $APubPublicKey;
  69. protected $APubPrivateKey;
  70. protected $TIME_STRING;
  71. protected $NULL_POST;
  72. protected $NULL_IMAGE;
  73. protected $NULL_IMAGE_DUMMY;
  74. protected $NULL_Gallery;
  75. protected $DoneReadPosts;
  76. protected $DoneReadImages;
  77. protected $DoneReadArchive;
  78. protected $NeedWritePosts;
  79. protected $NeedWriteImages;
  80. protected $NeedWriteArchive;
  81. protected $HereDisplayTitle;
  82. protected $VisitedHere;
  83. protected $HereNumber;
  84. protected $HereMainImage;
  85. public $PageType;
  86. public $CurrentPostID;
  87. public $HereID;
  88. public $ActualPostID;
  89. public $TagID;
  90. function ReadableTime($id){
  91. $dt = DateTime::createFromFormat('YmdHis', $id);
  92. return $dt->format('Y/m/d H:i:s');
  93. }
  94. function StandardTime($id){
  95. $dt = DateTime::createFromFormat('YmdHis', $id);
  96. return $dt->format('Y-m-d\TH:i:s');
  97. }
  98. function FullURL(){
  99. return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  100. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  101. $_SERVER['REQUEST_URI'];
  102. }
  103. function T($str){
  104. if(!$this->LanguageAppendix) return $str;
  105. foreach($this->Translations as $entry){
  106. if($entry['zh']==$str)
  107. return $entry[$this->LanguageAppendix];
  108. }
  109. return $str;
  110. }
  111. function SwitchLanguageAndFont(){
  112. $this->LanguageAppendix = 'zh';
  113. if(isset($_COOKIE['la_language'])){
  114. $this->LanguageAppendix = $_COOKIE['la_language'];
  115. }else{
  116. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  117. $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  118. $lang = substr($lang,0,5);
  119. if(preg_match("/zh/i",$lang))$this->LanguageAppendix = 'zh';
  120. else $this->LanguageAppendix = 'en';
  121. }
  122. }
  123. if(isset($_COOKIE['la_font'])){
  124. $this->UseRemoteFont = ($_COOKIE['la_font']!='local');
  125. }
  126. }
  127. function SwitchWayBackMode(){
  128. if(isset($_COOKIE['la_wayback'])){
  129. $this->WayBack = $_COOKIE['la_wayback'];
  130. }else $this->WayBack = NULL;
  131. }
  132. function DisplayRedirectConfig(){
  133. $s = "";
  134. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  135. if($r['for']=='P'){
  136. $s.=("P ".$r['format'].":".$r['target'].";".PHP_EOL);
  137. }else if($r['for']=='S'){
  138. $s.=("S ".$r['format'].":".$r['domain'].":".$r['target'].";".PHP_EOL);
  139. }
  140. }
  141. return $s;
  142. }
  143. function DoSiteRedirect(){
  144. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  145. if($r['for']=='S'){
  146. if(preg_match('/'.$r['format'].'/ui', $_SERVER['HTTP_HOST'])){
  147. if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
  148. header('Location:https://'.$r['domain'].'/index.php?post='.$r['target']); exit;
  149. }else{
  150. header('Location:https://'.$r['domain'].$_SERVER['REQUEST_URI']); exit;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. function WriteHTACCESS(){
  157. $conf = fopen('.htaccess','w');
  158. fwrite($conf,"RewriteEngine on".PHP_EOL.PHP_EOL);
  159. if(isset($this->Redirect) && isset($this->Redirect[0])) foreach($this->Redirect as $r){
  160. if($r['for']=='P'){
  161. fwrite($conf,"RewriteRule ^".$r['format'].'$ /index.php?post='.$r['target'].' [R=302,L]'.PHP_EOL.PHP_EOL);
  162. }// do site redirect in php.
  163. }
  164. fwrite($conf, 'RewriteCond %{HTTPS} !=on'.PHP_EOL.
  165. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  166. 'RewriteCond %{REQUEST_URI} !^.*(jpg|png|gif)$'.PHP_EOL.
  167. 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  168. fwrite($conf, 'RewriteCond %{HTTP_HOST} !^www\.'.PHP_EOL.
  169. 'RewriteCond %{HTTP_HOST} !=localhost'.PHP_EOL.
  170. 'RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]'.PHP_EOL.PHP_EOL);
  171. fwrite($conf,'<Files ~ "\.md$">'.PHP_EOL.'deny from all'.PHP_EOL.'</Files>'.PHP_EOL);
  172. fflush($conf);fclose($conf);
  173. }
  174. function BuildRedirectConfig($conf){
  175. $this->Redirect=[];
  176. if(preg_match_all('/P\s+(.*)\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  177. foreach($ma as $m){
  178. $redirect=[]; $redirect['for'] = 'P'; $redirect['format'] = $m[1]; $redirect['target'] = $m[2];
  179. $this->Redirect[]=$redirect;
  180. }
  181. }
  182. if(preg_match_all('/S\s+(\S+)\s*\:\s*(\S+)\s*\:\s*([0-9]{14})\s*;/u',$conf,$ma,PREG_SET_ORDER)){
  183. foreach($ma as $m){
  184. $redirect=[]; $redirect['for'] = 'S'; $redirect['format'] = $m[1]; $redirect['domain'] = $m[2]; $redirect['target'] = $m[3];
  185. $this->Redirect[]=$redirect;
  186. }
  187. }
  188. }
  189. function WriteTokens(){
  190. $tf = fopen('la_tokens.php','w');
  191. fwrite($tf,'<?php header("Location:index.php"); exit; ?>'.PHP_EOL.PHP_EOL);
  192. if(isset($this->LoginTokens) && sizeof($this->LoginTokens)) {
  193. foreach($this->LoginTokens as $t){
  194. fwrite($tf,'- '.$t.PHP_EOL);
  195. }
  196. }
  197. fflush($tf);fclose($tf);
  198. }
  199. function WriteConfig(){
  200. if(!isset($this->Title)) $this->Title = $this->T('那么的维基');
  201. if(!isset($this->ShortTitle)) $this->ShortTitle = $this->T('基');
  202. if(!isset($this->Admin)) $this->Admin = 'admin';
  203. if(!isset($this->DisplayName)) $this->DisplayName = $this->T('管理员');
  204. if(!isset($this->Password)) $this->Password = password_hash('Admin', PASSWORD_DEFAULT).PHP_EOL;
  205. $conf = fopen('la_config.php','w');
  206. fwrite($conf,'<?php header("Location:index.php"); exit; ?> '.PHP_EOL.PHP_EOL);
  207. fwrite($conf,'- Title = '.$this->Title.PHP_EOL);
  208. fwrite($conf,'- ShortTitle = '.$this->ShortTitle.PHP_EOL);
  209. fwrite($conf,'- Admin = '.$this->Admin.PHP_EOL);
  210. fwrite($conf,'- DisplayName = '.$this->DisplayName.PHP_EOL);
  211. fwrite($conf,'- Password = '.$this->Password.PHP_EOL);
  212. fwrite($conf,'- EMail = '.$this->EMail.PHP_EOL);
  213. fwrite($conf,'- SpecialNavigation = '.$this->SpecialNavigation.PHP_EOL);
  214. fwrite($conf,'- SpecialFooter = '.$this->SpecialFooter.PHP_EOL);
  215. fwrite($conf,'- SpecialFooter2 = '.$this->SpecialFooter2.PHP_EOL);
  216. fwrite($conf,'- SpecialPinned = '.$this->SpecialPinned.PHP_EOL);
  217. fwrite($conf,'- DefaultGallery = '.$this->DefaultGallery.PHP_EOL);
  218. fwrite($conf,'- SelfAuthPath = '.$this->SelfAuthPath.PHP_EOL);
  219. fwrite($conf,'- CommentEnabled = '.($this->CommentEnabled?"True":"False").PHP_EOL);
  220. fwrite($conf,'- HereHost = '.$this->HereHost.PHP_EOL);
  221. fwrite($conf,'- HereTitle = '.$this->HereTitle.PHP_EOL);
  222. fwrite($conf,'- HereShortTitle = '.$this->HereShortTitle.PHP_EOL);
  223. fwrite($conf,'- HereAlbum = '.$this->HereAlbum.PHP_EOL);
  224. fwrite($conf,'- HereNavigation = '.$this->HereNavigation.PHP_EOL);
  225. fwrite($conf,'- HereFooter = '.$this->HereFooter.PHP_EOL);
  226. fwrite($conf,'- ExpHost = '.$this->ExpHost.PHP_EOL);
  227. fwrite($conf,'- ExpTitle = '.$this->ExpTitle.PHP_EOL);
  228. fwrite($conf,'- ExpShortTitle = '.$this->ExpShortTitle.PHP_EOL);
  229. fwrite($conf,'- ExpCaution = '.$this->ExpCaution.PHP_EOL);
  230. fwrite($conf,'- ExpAlbum = '.$this->ExpAlbum.PHP_EOL);
  231. fwrite($conf,'- ExpNavigation = '.$this->ExpNavigation.PHP_EOL);
  232. fwrite($conf,'- ExpFooter = '.$this->ExpFooter.PHP_EOL);
  233. fwrite($conf,'- MastodonToken = '.$this->MastodonToken.PHP_EOL);
  234. fwrite($conf,'- MastodonURL = '.$this->MastodonURL.PHP_EOL);
  235. fwrite($conf,'- MastodonPreferredLang = '.$this->MastodonPreferredLang.PHP_EOL);
  236. fwrite($conf,'- HostURL = '.$this->HostURL.PHP_EOL);
  237. fwrite($conf,'- APubID = '.$this->APubID.PHP_EOL);
  238. fflush($conf);fclose($conf);
  239. $conf = fopen('la_redirect.md','w');
  240. fwrite($conf,$this->DisplayRedirectConfig());fflush($conf);fclose($conf);
  241. $this->WriteHTACCESS();
  242. $this->WriteTokens();
  243. }
  244. function Install(){
  245. if(!file_exists('la_config.php')){
  246. $this->WriteConfig();
  247. }
  248. if(!is_dir('posts')) mkdir('posts');
  249. if(!is_dir('images')) mkdir('images');
  250. if(!is_dir('images/thumb')) mkdir('images/thumb');
  251. if(!is_dir('styles')) mkdir('styles');
  252. if(!is_dir('archive')) mkdir('archive');
  253. $this->WriteStyles();
  254. $this->WriteHTACCESS();
  255. }
  256. function ReadFromExistingConfig(){
  257. $f=null;
  258. if(file_exists('la_config.php')) $f='la_config.php';
  259. else if(file_exists('la_config.md')) $f='la_config.md';
  260. if(!isset($f)) return;
  261. $c = file_get_contents($f);
  262. if(preg_match_all('/-\s*(\S+)\s*=\s*(\S+)\s*$/um', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  263. $str = $m[1];
  264. $this->$str = $m[2];
  265. }
  266. }
  267. function ReadConfig(){
  268. $this->ReadFromExistingConfig();
  269. if(file_exists('la_redirect.md')){
  270. $c = file_get_contents('la_redirect.md');
  271. $this->BuildRedirectConfig($c);
  272. }
  273. if(!file_exists('la_config.php')){
  274. $this->Install();
  275. }
  276. $this->Translations=[];
  277. if(file_exists("translations.md")){
  278. $c = file_get_contents('translations.md');
  279. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  280. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  281. $this->Translations[] = $entry;
  282. }
  283. }
  284. if(file_exists("custom_translations.md")){
  285. $this->CustomTranslationContent = file_get_contents('custom_translations.md');
  286. if(preg_match_all('/-\s+(\S.*)\s*\|\s*(\S.*)$/um',$this->CustomTranslationContent, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  287. $entry = []; $entry['zh'] = trim($m[1]); $entry['en'] = trim($m[2]);
  288. $this->Translations[] = $entry;
  289. }
  290. }
  291. $this->LoginTokens=[];
  292. if(file_exists('la_tokens.php')){
  293. $c = file_get_contents('la_tokens.php');
  294. if(preg_match_all('/-\s+(\S.*)\s*$/um',$c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  295. $this->LoginTokens[] = $m[1];
  296. }
  297. }
  298. }
  299. function MastodonPostStatus($status){ return $this->MastodonCall('/api/v1/statuses', 'POST', $status); }
  300. function MastodonPostMedia($media){ return $this->MastodonCall('/api/v1/media', 'POST', $media); }
  301. function MastodonCall($endpoint, $method, $data){
  302. $headers = [
  303. 'Authorization: Bearer '.$this->MastodonToken,
  304. 'Content-Type: multipart/form-data',
  305. ];
  306. $ch = curl_init();
  307. curl_setopt($ch, CURLOPT_URL, $this->MastodonURL.$endpoint);
  308. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  309. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  310. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  311. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  312. $reply = curl_exec($ch);
  313. if (!$reply) {
  314. return json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch_status), 'curl_error' => curl_error(ch_status)]);
  315. }
  316. curl_close($ch);
  317. return json_decode($reply, true);
  318. }
  319. function MastodonSendPost(&$post, &$errmsg=NULL){
  320. if(isset($post['mark_value']) && $post['mark_value']==7){ return NULL; }
  321. $this->LanguageAppendix = 'zh';
  322. if(in_array($this->MastodonPreferredLang,['en','zh'])){ $this->LanguageAppendix = $this->MastodonPreferredLang; }
  323. $this->ConvertPost($post);
  324. $media_ids = NULL;
  325. $mastodon_post_url = NULL;
  326. $imcount = 0;
  327. if(isset($post['original_images']) && isset($post['original_images'][0])) foreach($post['original_images'] as $im){
  328. $curl_file = curl_file_create($im, mime_content_type($im), basename($im));
  329. $body = ['file' => $curl_file,]; $response = $this->MastodonPostMedia($body);
  330. if(isset($response['id'])){ if(!isset($media_ids)){$media_ids=[];} $media_ids[]=$response['id']; }
  331. else{ if(isset($response['error'])) $errmsg.=$response['error']."<br /><br />"; }
  332. $imcount++; if($imcount>=4){ break; }
  333. }
  334. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$post['html']));
  335. if(isset($this->HostURL) && $this->HostURL!=""){
  336. $text.=("\n\n".$this->T('来自').' '.$this->HostURL.'?post='.$post['id']);
  337. }
  338. $vis = (isset($post['mark_value']) && $post['mark_value']==6)?"private":"public";
  339. $status_data = [ 'status' => $text, 'visibility' => $vis, 'language' => $this->LanguageAppendix, ];
  340. if(isset($post['prev']) && ($pp=&$this->GetPost($post['prev']))!=$this->NULL_POST){
  341. if(isset($pp['mastodon_url'])){ $status_data['in_reply_to_id'] = basename($pp['mastodon_url']);
  342. }
  343. }
  344. if(isset($media_ids[0])){ $status_data['media_ids']=$media_ids; }
  345. $status_data = preg_replace('/(media_ids%5B)[0-9]+(%5D)/','$1$2', http_build_query($status_data));
  346. $status_response = $this->MastodonPostStatus($status_data);
  347. if(isset($status_response['url']) && $status_response['url']){
  348. $mastodon_post_url = $status_response['url'];
  349. $post['mastodon_url'] = $mastodon_post_url;
  350. $this->NeedWritePosts = 1;
  351. }
  352. if(isset($status_response['error'])) { $errmsg .= $status_response['error']; }
  353. return $mastodon_post_url;
  354. }
  355. function __construct() {
  356. $this->ReadConfig();
  357. $this->PDE = new ParsedownExtra();
  358. $this->PDE->SetInterlinkPath('/');
  359. $this->Posts = [];
  360. $this->Threads = [];
  361. $this->VisitedHere = [];
  362. $this->NULL_IMAGE_DUMMY = [];
  363. $this->NULL_IMAGE_DUMMY['name']=$this->NULL_IMAGE_DUMMY['file']=$this->NULL_IMAGE_DUMMY['thumb']="";
  364. $this->Markers=['●', '○', '✓', '×', '!', 'P', 'E', 'S'];
  365. $this->PostsPerPage = 40;
  366. $this->CommentsPerPage = 100;
  367. $this->HotPostCount = 15;
  368. $this->TIME_STRING = date('YmdHis');
  369. $this->WayBack = NULL;
  370. $this->YearBegin = $this->YearEnd = 2000;
  371. $this->DoneReadPosts = $this->DoneReadImages = $this->DoneReadArchive = false;
  372. $this->NeedWritePosts= $this->NeedWriteImages= $this->NeedWriteArchive= false;
  373. $this->UsePosts = &$this->Posts;
  374. }
  375. function DoLogout(){
  376. $this->LoggedIn = false;
  377. unset($_SESSION['user_id']);
  378. $this->RecordToken(true);
  379. }
  380. function RecordToken($unset_current=false){
  381. if(isset($unset_current) && isset($_COOKIE['la_token'])){
  382. $t = $_COOKIE['la_token'];
  383. setcookie('la_token', null, -1); unset($_COOKIE['la_token']);
  384. if (($key = array_search($t,$this->LoginTokens)) !== false) { unset($this->LoginTokens[$key]); }
  385. $this->WriteTokens();
  386. return null;
  387. }else{
  388. $t = uniqid('la_',true);
  389. setcookie('la_token',$t,time()+3600*24*7); $_COOKIE['la_token'] = $t;
  390. $this->LoginTokens[] = $t;
  391. $this->WriteTokens();
  392. return $t;
  393. }
  394. }
  395. function LoginThroughToken(){
  396. if(!isset($_COOKIE['la_token'])) return false;
  397. $t = $_COOKIE['la_token'];
  398. if (($key = array_search($t,$this->LoginTokens)) !== false) {
  399. $_SESSION['user_id']=$this->Admin;
  400. $this->LoggedIn = true;
  401. setcookie('la_token',$t,time()+3600*24*7);
  402. return true;
  403. }
  404. return false;
  405. }
  406. function DoLogin(){
  407. session_start();
  408. $redirect=false;
  409. if(isset($_GET['logout'])){ $this->DoLogout(); header('Location:index.php'); }
  410. else if(!isset($_SESSION['user_id'])){
  411. if(isset($_POST['login_button'])){
  412. $id = trim($_POST['login_id']);
  413. $pwd = trim($_POST['login_password']);
  414. if(strtolower($this->Admin)==strtolower($id)&&password_verify($pwd, $this->Password)){
  415. $_SESSION['user_id']=$id;
  416. $this->RecordToken(false);
  417. }
  418. $redirect = true;
  419. }else if($this->LoginThroughToken()){
  420. // nothing;
  421. }
  422. }else{
  423. if(strtolower($_SESSION['user_id']) == strtolower($this->Admin)){ $this->LoggedIn = true; }
  424. else{ $this->DoLogout();}
  425. }
  426. if($redirect){
  427. header('Location:index.php'.(isset($_GET['post'])?("?post=".$_GET['post']):"")
  428. .(isset($_GET['settings'])?"?settings=true":""));
  429. }
  430. }
  431. function SetHereMainImage($im_this){
  432. if(isset($im_this) && isset($im_this['parent'])){ $this->HereMainImage = &$this->FindImage($im_this['parent'],true);}
  433. }
  434. function RecordVisitedHere($image_or_post_name, $image_title){
  435. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  436. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  437. if(!(isset($_SESSION[$visited_here][0]) && in_array($image_or_post_name,$_SESSION[$visited_here]))){
  438. $_SESSION[$visited_here][] = $image_or_post_name;
  439. }
  440. if(isset($image_title)){ $this->HereDisplayTitle=$image_title; }
  441. $this->HereNumber = array_search($image_or_post_name,$_SESSION[$visited_here])+1;
  442. $_SESSION['here_number'] = $this->HereNumber;
  443. $this->VisitedHere = $_SESSION[$visited_here];
  444. }
  445. function HereLinkFromNumber($number){
  446. $number -= 1; if($number<0){ $number=0; }
  447. if($number>=sizeof($this->VisitedHere)){ $number = sizeof($this->VisitedHere)-1; }
  448. if(preg_match('/(jpg|jpeg|png|gif)/u',$this->VisitedHere[$number])){ return "?here=images/".$this->VisitedHere[$number]; }
  449. else{ return "?post=".$this->VisitedHere[$number]; }
  450. }
  451. function WriteStyles(){
  452. $this->style="
  453. html{font-size:18px;font-family:'Noto Serif CJK SC','Times New Roman','SimSun', Georgia, serif;}
  454. body{background-color:%white%;color:%black%;}
  455. sup,sub{line-height:0;}
  456. blockquote{border-left:2px solid %black%;padding-left:0.3em;}
  457. *{box-sizing:border-box;padding:0;margin:0;font-weight:normal;}
  458. b,strong,th{font-weight:bold;}
  459. select{font-size:inherit;}
  460. .page,.page_gallery{padding:1em;padding-top:0;padding-bottom:0;}
  461. .hidden_on_desktop,.hidden_on_wide{display:none;}
  462. .hidden_on_desktop_force{display:none !important;}
  463. ::file-selector-button{background:none;border:none;}
  464. a,button,::file-selector-button{text-decoration:underline;color:%black%;}
  465. a:hover,.button:hover,::file-selector-button:hover{text-decoration:none;color:%gray%;}
  466. .button:disabled{background-color:%gray%;pointer-events:none;}
  467. header{position:sticky;top:0;background-color:%white%;z-index:10;padding-top:0.5em;max-height:100vh;z-index:30;}
  468. 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;}
  469. header>div{overflow:auto;white-space:nowrap;}
  470. .header_nav{display:inline;}
  471. header a,.left a,.footer a,.clean_a,.clean_a a{text-decoration:none;}
  472. header a:hover,.button:hover{color:%gray% !important;}
  473. .exp_h_f{padding-top:0.3em !important;padding-bottom:0.3em !important;line-height:1.5em !important;height:2.1em !important;}
  474. .toc_button{position:absolute;top:0.5em;right:0;text-shadow: 0px 0px 10px %white%;background-color:%white%88;}
  475. .footer{background-color:%white%;z-index:10;position:relative;}
  476. .invert_a,.invert_a a{color:%gray%;text-decoration:none;}
  477. .invert_a:hover,.invert_a a:hover{color:%black% !important;}
  478. .gray,.gray a{color:%gray%;}
  479. hr{border:1px solid %gray%;}
  480. header ul,.small_footer ul,.small_footer span,header li,.small_footer li{display:inline-block;}
  481. header li::before,.small_footer li::before{content:' - '}
  482. header h1,header h2,header h3,header h4,header h5,header p{display:inline;font-size:1rem;}
  483. .main{position:relative;word-spacing:-1em;}
  484. .main *{word-spacing:initial;}
  485. pre{overflow:auto;max-width:100%;display:block;font-size:0.75em;}
  486. ul{display:block;}
  487. li{display:block;}
  488. table{width:100%;border-collapse:collapse;border-bottom:2px solid %black%;border-top:3px solid %black%;}
  489. table input{border:none!important;}
  490. table img{max-width:10rem !important;}
  491. td{padding-left:0.1em;padding-right:0.1em;}
  492. td:first-child{padding-left:0;}
  493. td:last-child{padding-right:0;}
  494. tbody tr:hover{box-shadow:inset 0 -2px 0 0px %black%;}
  495. thead{box-shadow:inset 0 -1px 0 0px %black%;position:sticky;top:2rem;background-color:%white%;z-index:5;}
  496. .post table{font-size:0.85em;}
  497. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 20em);}
  498. .interesting_tbody td{display:contents;}
  499. .interesting_tbody tr{position:relative;scroll-margin:4.5em}
  500. .interesting_tbody td>*{display:table-cell;}
  501. .interesting_tbody td>.wscroll{display:none !important;}
  502. .interesting_tbody .post_access{padding-top:0;}
  503. .interesting_tbody .post_menu_button{top:0;opacity:0;}
  504. .interesting_tbody td>img,.interesting_tbody td>.imd{position:absolute;left:1.4em;z-index:-1;height:1em;width:20em;
  505. display:flex;top:0.2em;object-fit:cover;max-width:calc(100% - 1.4em) !important;overflow:hidden;}
  506. .interesting_tbody td>.imd>a{display:flex;}
  507. .interesting_tbody img{object-fit:cover;width:100%;}
  508. .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);}
  509. .interesting_tbody .p_thumb{height:1em;}
  510. .interesting_tbody .p_thumb img{max-height:10rem !important;max-width:20rem !important;}
  511. tr:hover .post_menu_button{opacity:1;}
  512. .post_current_row{background-color:%graybkg%;mix-blend-mode:screen;text-shadow:0px 0px 0.1em %white%;}
  513. .align_right{text-align:right;}
  514. .left{display:inline-block;vertical-align:top;width:25%;max-height:calc(100vh - 2.6em);top:2em;
  515. position:sticky;overflow:auto;padding-right:0.2em;padding-bottom:4rem;}
  516. .center{display:inline-block;vertical-align:top;width:50%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  517. .center_wide{display:inline-block;vertical-align:top;width:75%;padding-left:0.3em;overflow:visible;padding-bottom:4rem;}
  518. .center_full{display:inline-block;vertical-align:top;width:100%;overflow:visible;padding-bottom:4rem;}
  519. .center_wide .p_thumb{height:10rem;}
  520. .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;}
  521. .center_exp{display:block;width:80%;margin:0 auto;overflow:visible;padding-bottom:1em;}
  522. .table_top{position:relative;left:calc(-50% - 0.45em);width:calc(200% + 0.6em);background:%white%;z-index:1;
  523. box-shadow:0px 0px 2em 1em %white%;margin-top:2em;margin-bottom:2em;}
  524. .right{display:inline-block;vertical-align:top;width:25%;position:sticky;top:2em;
  525. padding-left:0.5em;max-height:calc(100vh - 2.6em);overflow:auto;padding-bottom:4rem;}
  526. textarea,input[type=text],input[type=password]{width:100%;display:block;font-family:inherit;max-height:60vh;font-size:inherit;}
  527. select,textarea,input[type=text],input[type=password]{background:none;border:none;border-bottom:1px solid %black%;color:%black%;}
  528. .text_highlight input{border-bottom:1px solid %white%;color:%white%;}
  529. .button{background:none;border:none;font-family:inherit;color:%black%;font-size:inherit;font-weight:bold;}
  530. .post{position:relative;scroll-margin:3.5em;border-radius:0.3em;}
  531. .center_exp .post{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;border-radius:0;}
  532. .post_width li,.post_width_big li,.footer_additional li,.footer_additional li,.post_dummy li
  533. {display:list-item;margin-left:1em;list-style:disc;}
  534. .post_width li li,.post_width_big li li,.footer_additional li li,.footer_additional li li,.post_dummy li li{list-style:circle;}
  535. .post_width > *,.post_width_big > *,.post_dummy > *,.post_ref > *{margin:0;margin-bottom:0.5rem}
  536. .post_dummy > *{width:60%;margin:0 auto;margin-bottom:0.5rem}
  537. .post_dummy > p img{display:block;width:100%;margin:0 auto;}
  538. .gallery_left li{display:list-item;margin-left:1em;list-style:none;}
  539. .gallery_left .selected{list-style:'→';}
  540. .focused_post{font-size:1.1em;margin-top:0.1em;margin-bottom:0.1em;padding:0.5rem !important;border:2px dashed #ac7843;}
  541. .post_width{position:relative;left:1.4rem;width:calc(100% - 1.7rem);padding-left:0.2em;overflow:visible;}
  542. .post_width_big{position:relative;left:0;width:100%;overflow:visible;}
  543. .post_menu_button{position:absolute;display:none;right:0rem;width:1.5rem;
  544. text-align:center;border-radius:0.3em;user-select:none;cursor:pointer;z-index:10;}
  545. .pointer{cursor:pointer;}
  546. .post:hover .post_menu_button{display:block;}
  547. .pop_menu{position:absolute;top:0.3rem;z-index:95;background-color:%lighterbkg%;
  548. padding:0.3em;right:0.3rem;text-align:right;border-radius:0.3em;font-size:1rem;
  549. box-shadow:0px 0px 10px rgb(0, 0, 0);}
  550. .pop_menu li{list-style:none;margin-left:0;}
  551. .pop_menu hr{border:2px solid rgba(0,0,0,0.1);}
  552. .toc{left:60%;width:40%;top:0;position:absolute;}
  553. .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;}
  554. .post_access:hover{background-color:%lightopbkg%;border-top-left-radius:0.3em;border-bottom-left-radius:0.3em;
  555. border-right:2px solid %black% !important;}
  556. .paa{width:1.4rem;min-width:1.4rem;}
  557. .opt_compact .post_access,.ref_compact .post_access{border-right:2px solid %gray%;}
  558. .post_box{border:1px solid %gray%;border-radius:0.3em;padding:0.3em;}
  559. .post_box:hover,.post_menu_button:hover{background-color:%lightopbkg%}
  560. #big_image_info .post_box:hover{background-color:%graybkg%;}
  561. .post_preview{font-size:0.9rem;overflow:hidden;margin-bottom:0.2em;}
  562. .post .post_ref{margin:0;padding-left:1.7rem;}
  563. .post_ref_main{display:inline-block;vertical-align:top;}
  564. .post_preview .post_ref_main{max-height:6rem;overflow:hidden;}
  565. .post_ref_images{overflow:hidden;}
  566. .page_selector{padding-top:2rem;text-align:center;}
  567. .smaller{font-size:0.85em;}
  568. .bigger{font-size:1.3em;}
  569. .block{display:block;}
  570. .opt_compact{margin-left:1.6rem;}
  571. .opt_compact .post_width {margin-left:0.3em;width: calc(100% - 1.8rem);}
  572. .post_box_top{padding-bottom:0.3em;padding-top:0.3em;}
  573. .post_box_fixed_bottom{position:sticky;bottom:0em;background-color:%white%;z-index:5;}
  574. .spacer{height:0.5em;}
  575. .pop_right,.pop_right_big{position:fixed;top:0;right:0;bottom:0;width:30%;z-index:100;background-color:%graybkg%;display:none;
  576. transition-timing-function:ease-out;padding:1rem;overflow:auto;}
  577. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  578. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  579. @keyframes pop_slide_in_big{0%{right:-30%;}100%{right:0%;}}
  580. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-30%;}}
  581. .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;}
  582. @keyframes backdrop_fade_in{0%{opacity:0%;}100%{opacity:100%;}}
  583. @keyframes backdrop_fade_out{0%{opacity:100%;}100%{opacity:0%;}}
  584. .toc_entry_1{font-size:1.1em;}
  585. .toc_entry_2{font-size:1.0em;padding-left:0.5rem;}
  586. .toc_entry_3{font-size:0.9em;padding-left:1rem;}
  587. .toc_entry_4{font-size:0.85em;padding-left:1.5rem;}
  588. .toc_entry_5{font-size:0.8em;padding-left:2rem;}
  589. h1,h2,h3,h4,h5{scroll-margin:2.5em;}
  590. .left ul h1,.left ul h2,.left ul h3,.left ul h4,.left ul h5,.left ul p{font-size:1em;}
  591. .deleted_post{color:%gray%;text-decoration:line-through;}
  592. #file_list{margin-top:0.5em;}
  593. .file_thumb img{max-height:100%;max-width:100%;object-fit:cover;min-width:100%;min-height:100%;}
  594. #file_list li{margin-bottom:0.3em;}
  595. .ref_thumb{white-space:nowrap;overflow:hidden;}
  596. .ref_thumb .file_thumb{width:3em;height:3em;}
  597. .side_thumb li{margin:0.4em;display:inline-block;}
  598. .file_thumb{width:4em;height:4em;display:inline-block;line-height:0;vertical-align:middle;overflow:hidden;}
  599. .p_row{display:flex;flex-wrap:wrap;width:100%;}
  600. .p_thumb{display:flex;flex-grow:1;height:6rem;margin-right:0.25rem;margin-bottom:0.25rem;overflow:hidden;position:relative;}
  601. .p_thumb_narrow{width:1rem;}
  602. .p_thumb img{object-fit:cover;max-height:100%;min-width:100%;}.p_thumb a{display:contents;}
  603. .ref_count,.p_thumb .post_menu_button{text-shadow: 0px 0px 10px rgb(0, 0, 0);}
  604. .p_thumb:hover .post_menu_button{display:block;}
  605. .p_thumb_selected{color:%black% !important;}
  606. .p_thumb_selected{display:block;}
  607. .post .p_thumb img{max-height:6rem;}
  608. .big_image_box{position:fixed;top:0;bottom:0;left:0;width:75%;z-index:95;text-align:center;pointer-events:none;}
  609. .big_image_box *{pointer-events:auto;}
  610. .big_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  611. .here_image_box{position:relative;width:100%;text-align:center;height:calc(100vh - 4.5em);}
  612. .here_image_box img{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;cursor:unset;}
  613. .big_side_box{position:fixed;top:0;bottom:0;right:0;width:25%;overflow:auto;z-index:98;color:%black%;padding:1rem;
  614. background:linear-gradient(to right, rgba(0,0,0,0), rgb(1, 1, 1));transition:background-size .2s linear;background-size: 300% 100%;}
  615. .big_side_box:hover{background-size: 100% 100%;}
  616. .big_side_box a,.big_side_box hr,#dropping_background{color:%black%;}
  617. .big_side_box a:hover{color:%gray%;}
  618. #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;
  619. box-shadow:0px 0px 500px black inset;display:flex;align-items:center;}
  620. img{cursor:pointer;max-height:100%;max-width:100%;vertical-align:middle;}
  621. .post img{max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  622. .post > a > img{display:block;margin:0.3em auto;}
  623. .post .original_img{max-width:100%;display:inline-block;vertical-align:middle;
  624. margin-left:auto;margin-right:auto;max-width:100%;max-height:90vh;}
  625. .center_exp .post .original_img{display:block;}
  626. .original_img img{max-height:90vh;max-width:100%;}
  627. .p_row .original_img{margin-bottom:0;}
  628. .post_ref .original_img{margin:unset;max-width:unset;max-height:min(70vh, 20rem);max-width:min(100%, 20rem);}
  629. .b ul{font-size:1.4em;}
  630. no_pop{cursor:unset;}
  631. p{min-height:0.8em;}
  632. .bold,.bold *{font-weight:bold;}
  633. .footer_additional{display:inline-block;width:50%;vertical-align:text-top;white-space:normal;}
  634. .small_footer{background-color:%white%;padding-bottom:0.5em;position:sticky;bottom:0px;z-index:10;}
  635. .small_footer>div{overflow:auto;white-space:nowrap;}
  636. .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;}
  637. .top_post_hint{margin-left:1.5em;font-weight:bold;}
  638. .white{color:%white%;}
  639. .full_box{border:1px solid %black% !important;padding:0.3rem;overflow:auto;}
  640. .image_nav_prev,.image_nav_next{z-index:100;position:absolute;line-height:0;height:100%;width:20%;display:flex;align-items:center;
  641. transition:background-size .2s ease;padding:0.5em;text-shadow:0px 0px 5px black;user-select:none;pointer-events:auto;}
  642. .image_nav_prev{left:0;justify-content:left;background:linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.2));
  643. background-repeat:no-repeat;background-size:0% 100%;}
  644. .image_nav_prev:hover,.image_nav_next:hover{background-size:100% 100%;}
  645. .image_nav_next{right:0;justify-content:right;background:linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.2));
  646. background-repeat:no-repeat;background-size:0% 100%;transition:background-size .2s ease;background-position-x:100%;}
  647. .inquiry_buttons{position:fixed;left:0;right:25%;text-align:center;bottom:1em;margin:0 auto;width:max-content;
  648. background-color:rgba(0,0,0,0.5);z-index:110;padding:0.2em;padding-left:1em;padding-right:1em;
  649. border-radius:1em;box-shadow:0px 0px 5px;text-shadow:0px 0px 5px black;opacity:1;user-select:none;}
  650. .lr_buttons{background-color:rgba(0,0,0,0.5);padding:0.5em;padding-top:1em;padding-bottom:1em;
  651. border-radius:1em;box-shadow:0px 0px 5px;font-size:1.2rem;text-shadow:0px 0px 5px black;}
  652. .img_btn_hidden{opacity:0;transition:opacity 0.2s;}
  653. .special_alipay{background-color:#027aff;color:white;white-space:nowrap;
  654. font-family:sans-serif;font-weight:bold;border-radius:0.7em;font-size:0.75em;padding:0.25em;}
  655. .special_paypal{background-color:white;color:#253b80;white-space:nowrap;
  656. font-family:sans-serif;font-weight:bold;border-radius:2em;font-size:0.75em;
  657. padding:0.25em;padding-left:0.5em;padding-right:0.65em;font-style: italic;}
  658. .special_paypal_inner{color:#169bd7;}
  659. #waiting_bar{position:fixed;z-index:200;top:0;left:0;right:0;height:0.2em;background-color:%black%;transform:translate(-100%,0);
  660. animation:anim_loading 1s linear infinite;}
  661. @keyframes anim_loading{0%{transform:translate(-100%,0);} 100%{transform:translate(100%,0);}}
  662. .product_ref{width:32%;padding:0.2em!important;display:inline-block;text-align:center;vertical-align:top;margin-bottom:0.8em;}
  663. .product_thumb{max-height:11em;max-width:11em;display:inline-flex;margin-bottom:0.2em;background-color:%graybkg%;}
  664. .product_thumb img{box-shadow:none;object-fit:contain;max-height:unset;max-width:unset;width:100%;margin:0 auto !important;}
  665. .product_ref p{margin-bottom:0.2em;text-align:left;}
  666. .post_preview .product_thumb{max-height:4em;max-width:6em;}
  667. .purchase_button{background-color:%black%;color:%white%;padding-left:0.5em;padding-right:0.5em;text-decoration:none;font-weight:bold;}
  668. .page_break{page-break-after:always;}
  669. .text_highlight,.text_highlight a,.text_highlight select{background-color:%black%;color:%white%;border:none;}
  670. .gray.text_highlight,.gray.text_highlight a,.gray.text_highlight select{background-color:%gray%;color:%white%;}
  671. .print_title{display:none;}
  672. .show_on_print{display:none;}
  673. .comment{font-size:0.9em;font-family:sans-serif;overflow:auto !important;width:100%;}
  674. .comment tbody tr:hover{box-shadow:none;}
  675. .comment table{border:none;}
  676. .comment li{display:list-item;list-style:'→';padding-left:0.3em;}
  677. .comment ul{padding-left:1em;}
  678. .comment ul li *{margin-bottom:0.5em;}
  679. .history li{display:list-item;list-style:disc;padding-left:0.3em;}
  680. .history li li{list-style:circle;}
  681. .history ul{padding-left:1em;}
  682. .history a{text-decoration:underline;}
  683. .history .list{overflow:auto;white-space:nowrap;}
  684. .diff_table{table-layout:fixed;}
  685. .diff_table thead{font-size:0.9em;text-align:center;}
  686. .diff_table tbody pre{font-size:0.9rem;white-space:pre-line;}
  687. .diff_table td{vertical-align:top;}
  688. .omittable_title{display:block;width:100%;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
  689. .wayback_close{float:right;}
  690. .wayback_expand{display:inline;}
  691. .post_selecting .post *{pointer-events:none;}
  692. .post_selected{background-color:%graybkg%;}
  693. .small_pad{padding:0.2em;padding-top:0.1em;padding-bottom:0.1em;}
  694. .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%;}
  695. .wscroll:target{display:block;} .post_ref .wscroll{display:none !important;}
  696. .wayback_link{display:inline;}
  697. .imd{object-fit:cover;width:100%;}
  698. .center_exp .imd{width:60%;}
  699. #here_buttons{display:contents;}
  700. .here_buttons_inner{position:absolute;margin:auto;top:0;left:0;right:0;bottom:0;max-height:100%;max-width:100%;}
  701. .here_btn{position:absolute;z-index:110;transform:translate(-50%,-50%);
  702. width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
  703. .round_btn{box-shadow: 0px 0px 0px 1px inset %black%;display:inline-block;padding-left:0.4em;padding-right:0.4em;border-radius:0.5em;}
  704. @media screen and (max-width:1000px) and (min-width:666px){
  705. .left{width:35%;}
  706. .center,.center_wide{width:65%;}
  707. .center_wide .p_thumb{height:8rem;}
  708. .right{display:none;}
  709. .post_width{width:calc(100% - 1.5rem);padding-left:0.2em;}
  710. .post_width_big{left:0;width:100%;}
  711. .hidden_on_wide{display:unset;}
  712. .pop_right{width:30%;}
  713. .pop_right_big{width:40%;}
  714. @keyframes pop_slide_in{0%{right:-30%;}100%{right:0%;}}
  715. @keyframes pop_slide_out{0%{right:0%;}100%{right:-30%;}}
  716. @keyframes pop_slide_in_big{0%{right:-40%;}100%{right:0%;}}
  717. @keyframes pop_slide_out_big{0%{right:0%;}100%{right:-40%;}}
  718. .big_side_box{width:35%;}
  719. .big_image_box{width:65%;}
  720. .inquiry_buttons{right:35%;}
  721. .table_top{left:calc(-50% - 1.7em);width:calc(154% + 0.5em);}
  722. .post_dummy > *{width:80%;max-width:55rem;}
  723. .center_exp .imd{width:80%;}
  724. .here_btn{width:1.5em;height:1.5em;}
  725. }
  726. @media screen and (max-width:666px){
  727. html{font-size:16px;}
  728. .hidden_on_mobile{display:none !important;}
  729. .block_on_mobile{display:block !important;}
  730. .hidden_on_desktop{display:unset;}
  731. .hidden_on_wide{display:unset;}
  732. header ul{display:block;}
  733. header li{display:block;}
  734. header li::before{content:''}
  735. header::before{box-shadow:none;display:none;}
  736. .small_footer::before{box-shadow:none;display:none;}
  737. .left{position:relative;width:100%;position:relative;top:unset;height:unset;min-height:80vh;padding-right:0;display:block;}
  738. .center,.center_wide,.center_full{position:relative;left:0;top:0;width:100%;padding-left:0;display:block;}
  739. .center_wide .p_thumb{height:6rem;}
  740. .pop_right,.pop_right_big{top:unset;right:0;bottom:0;left:0;width:100%;}
  741. .pop_right{height:30%;}
  742. .pop_right_big{height:70%;}
  743. @keyframes pop_slide_in{0%{bottom:-30%;}100%{bottom:0%;}}
  744. @keyframes pop_slide_out{0%{bottom:0%;}100%{bottom:-30%;}}
  745. @keyframes pop_slide_in_big{0%{bottom:-70%;}100%{bottom:0%;}}
  746. @keyframes pop_slide_out_big{0%{bottom:0%;}100%{bottom:-70%;}}
  747. .big_image_box{position:fixed;top:0;bottom:8.5rem;left:0;right:0;width:100%;}
  748. .side_box_mobile_inner{background:linear-gradient(to bottom, rgba(0,0,0,0), rgba(1,1,1,0.9) 20%);
  749. transition:none;background-size:100% 100%;padding:0.5rem;padding-bottom: 5em;}
  750. .side_box_mobile_inner:hover{background-size:100% 100%;}
  751. .big_side_box{position:fixed;top:0;bottom:0;right:0;left:0;width:100%;
  752. height:unset;padding:0;padding-top:calc(100vh - 8.5rem);background:none;}
  753. .p_thumb{height:3rem;}
  754. .center .post{padding-right:0rem;padding-left:0rem;}
  755. .post .p_thumb img{max-height:3rem;}
  756. .page,.page_gallery{padding:0.2em;padding-top:0;}
  757. header{padding-top:0.3em;}
  758. .toc_button{top:0.3em;}
  759. .small_footer{padding-bottom:0.3em;}
  760. .footer_additional{display:block;width:100%;}
  761. .album_hint{display:block;font-size:1rem;}
  762. .image_nav{position:absolute !important;}
  763. .image_nav_prev,.image_nav_next{width:25%;}
  764. .image_nav_prev:hover,.image_nav_next:hover{background-size:0% 100%;color:%black% !important;}
  765. .inquiry_buttons{position:relative;left:unset;right:unset;text-align:left;bottom:unset;margin:unset;width:unset;
  766. background-color:unset;z-index:unset;padding:unset;padding-left:unset;padding-right:unset;
  767. border-radius:unset;box-shadow:unset;text-shadow:unset;}.img_btn_hidden{opacity:1;}
  768. .lr_buttons{background-color:unset;padding:unset;padding-top:unset;padding-bottom:unset;
  769. border-radius:unset;box-shadow:unset;font-size:1.3rem;text-shadow:unset;}
  770. .opt_compact,.ref_compact{line-break:anywhere;}
  771. .post_width,.post_width_big{overflow:auto;}
  772. .table_top{left:unset;width:100%;overflow:auto;}
  773. table img{max-width:30vw !important;}
  774. .product_ref{width:100%;display:block;}
  775. .post_dummy > *{width:100%;max-width:25rem;}
  776. .sticky_title{top:1.2em;}
  777. .small_footer{position:relative;}
  778. #upload_selector{width:100%;}
  779. .focused_post{padding:0.3rem !important;}
  780. .interesting_tbody{background:linear-gradient(90deg, %white%ff, %white%88 10em);}
  781. .wayback_expand{display:block;text-align:center;}
  782. .wayback_link{display:block;}
  783. .center_exp{display:block;width:100%;margin:0 auto;padding-bottom:1em;}
  784. .center_exp .post{overflow:auto;}
  785. .center_exp .imd{width:100%;}
  786. .here_btn{width:1.2em;height:1.2em;}
  787. .exp_h_f{height:unset !important;}
  788. .exp_f{margin-bottom:1em;}
  789. }
  790. @media print{
  791. header::before{box-shadow:none;display:none;}
  792. .small_footer::before{box-shadow:none;display:none;}
  793. body,footer,header,.small_footer,a,.clean_a,.invert_a,.clean_a a,.invert_a a{background:none;color:black;}
  794. .post *,.post_dummy *{margin-bottom:0em}
  795. .p_row,.post table,.post_width>img,.post_width_big>img,.post_ref>img,.post_ref>.original_img,
  796. .post_width>.original_img,.post_width_big>.original_img,.post pre{margin-top:0.5rem;margin-bottom:0.5rem;text-indent:0;}
  797. .post p{line-height:1.3;text-indent:2em;} .product_ref p {text-indent:0;}
  798. table img{margin:0 !important;}
  799. .post h1+p,.post h2+p,.post img+p,.post table+p,.post p:first-child{text-indent:0;}
  800. .post ul,.post ol{margin:1rem;margin-left:1.4rem;margin-right: 0rem;}
  801. table{border-bottom:2px solid black;border-top:2px solid black;}
  802. table img{max-width:5em;max-width:8em !important;max-height:8em !important;}
  803. thead{box-shadow:inset 0 -1px 0 0px black;background:none;}
  804. .post_width,.post_width_big{overflow:clip;left:0;width:100%;padding-left:0em;}
  805. .post h1{margin-top:0.5rem;}
  806. .post h2{font-size:1.8em;margin:2.5em auto 0;}.list h2,.opt_compact h2,.ref_compact h2{margin:0 !important;}
  807. .post h3{font-size:1.5em;margin:1.5em auto 0;}.list h3,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  808. .post h4{font-size:1.1em;margin:0.5em auto 0;}.list h4,.opt_compact h3,.ref_compact h4{margin:0 !important;}
  809. .post .post{margin-bottom:0.5rem;margin-top:0.5rem;}
  810. .gray,.gray a,.deleted_post{color:rgba(0,0,0,0.5);}
  811. .left,.right{display:none;}
  812. .center, .center_wide, .center_full{width:100%;padding:0;display:block;font-size:16px;line-height:1.3}
  813. hr{border:1px solid black;}
  814. .post_box_top{display:none;}
  815. .opt_compact .post_access,.ref_compact .post_access{border-right:none;display:inline;}
  816. .text_highlight,.text_highlight a,.gray.text_highlight,.gray.text_highlight a,.purchase_button{background-color:lightgray;color:black;}
  817. .focused_post{border:none;font-size:1em;padding:0 !important;}
  818. .hidden_on_print{display:none;}
  819. .print_column{column-count:2;margin-top:0.5rem;margin-bottom:0.5rem;}
  820. .post_access{display:none;}
  821. .opt_compact{margin-left:0;}
  822. .post .post_ref{padding-left:1.4rem;}
  823. .opt_compact .post_width{left:1.4rem;width:calc(100% - 1.4rem);margin-left:0;}
  824. .print_title{column-span:all;display:block;margin-top:2em;margin-bottom:0.5rem;font-size:1.2em;}
  825. .print_title:first-of-type{margin-top:1em;}
  826. .print_title+.post h1:first-of-type{display:none;}
  827. .opt_compact h1:first-of-type,.ref_compact h1:first-of-type{display:unset;}
  828. .table_top{position:relative;left:0;width:100%;background:none;z-index:1;box-shadow:none;}
  829. .header_nav{display:none;}
  830. .show_on_print{display:block;}
  831. blockquote{border-left:2px solid black;}
  832. .footer_additional{display:none;}
  833. .small_footer{margin-top:1rem;}
  834. .page_selector{display:none;}
  835. .p_thumb{height:4rem;margin-bottom:0.25rem;}
  836. .post .p_thumb img{max-height:4rem;}
  837. .sticky_title{box-shadow:none;}
  838. .center_wide .p_thumb{display:inline-flex;height:5.8rem;width:5.8rem;margin-right:0;}
  839. .center_wide .p_row{display:block;}
  840. .interesting_tbody{background:none;}
  841. .interesting_tbody img{display:none !important;}
  842. .imd{margin-top:0.5em;margin-bottom:0.5em;line-height:0px;}
  843. .p_row .imd{margin-top:0em;margin-bottom:0em;}
  844. }
  845. ";
  846. $this->style=preg_replace('/%white%/','#231a0d',$this->style);
  847. $this->style=preg_replace('/%black%/','#f8ca9b',$this->style);
  848. $this->style=preg_replace('/%gray%/','#ac7843',$this->style);
  849. $this->style=preg_replace('/%graybkg%/','#39270e',$this->style);
  850. $this->style=preg_replace('/%lightopbkg%/','#daae8010',$this->style);
  851. $this->style=preg_replace('/%lighterbkg%/','#675340',$this->style);
  852. $this->style=preg_replace('/%focusedbkg%/','#482f0c',$this->style);
  853. $f = fopen('styles/main.css','w');
  854. fwrite($f,$this->style);
  855. fclose($f);
  856. }
  857. function GiveSafeEMail(){
  858. return preg_replace('/\./u','[dot]',preg_replace('/\@/u','[at]',$this->EMail));
  859. }
  860. function &FindImage($name, $loose=false){ if(!isset($name) || !$name){ return $this->NULL_IMAGE; }
  861. if(isset($this->Images[0]))foreach($this->Images as &$im){
  862. if($loose) { if(preg_match('/'.preg_quote($name).'/u',$im['name'])) return $im; }
  863. else { if($im['name']==$name) return $im; }
  864. }
  865. return $this->NULL_IMAGE;
  866. }
  867. function &GiveImageInHere($rand=false){
  868. $this->ReadImages();
  869. $album = $this->PageType=='here'?$this->HereAlbum:$this->ExpAlbum;
  870. if(!isset($album) || !$album){
  871. if(isset($this->Images[0])) return $this->Images[0]; else return $this->NULL_IMAGE; }
  872. $imlist=[];
  873. if(isset($this->Images[0])){
  874. foreach($this->Images as &$im){
  875. if(isset($im['galleries'][0]) && in_array($album,$im['galleries'])){
  876. if(!$rand) return $im; else { if($this->CanShowImage($im)) $imlist[] = $im; }
  877. }
  878. }
  879. }
  880. if(!$rand || !isset($imlist[0])) return $this->NULL_IMAGE;
  881. $r = random_int(0, sizeof($imlist)-1);
  882. return $imlist[$r];
  883. }
  884. function ImageTitle($im){
  885. $imtitle = (isset($im)&&isset($im['title']))?$im['title']:NULL;
  886. if(isset($im['parent'])&&($imp = &$this->FindImage($im['parent'],true))&&isset($imp['title'])){ $imtitle=$imp['title']; }
  887. return $imtitle;
  888. }
  889. function ImageHasHere(&$im, $here_name){
  890. if(!isset($im['here'])||!isset($im['here'][0])) return false;
  891. foreach($im['here'] as $h) { if($h[0] == $here_name) return true; } return false;
  892. }
  893. function ReadImages($clear_non_exist = false){
  894. $path = 'images/list.md';
  895. if($this->DoneReadImages){ return; }
  896. if(!file_exists($path)){ $f = fopen($path,'w'); fflush($f); fclose($f); }
  897. $c = file_get_contents($path);
  898. if(preg_match_all('/GALLERY\s+(\S+)(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  899. $g=[]; $g['name']=$m[1];//$g['count']=0;
  900. if(preg_match('/FEATURED([^;]*?);/u', $m[2], $arg)){ $g['featured']=true; }
  901. if(preg_match('/EXPERIMENTAL([^;]*?);/u', $m[2], $arg)){ $g['experimental']=true; }
  902. $this->Galleries[] = $g;
  903. }
  904. if(preg_match_all('/^-\s*([^;]+)\s*?;\s*?(.*)$/mu', $c, $ma, PREG_SET_ORDER)) foreach($ma as $m){
  905. $name = trim($m[1]);
  906. $item = []; $item['file'] = 'images/'.$name; $item['name'] = $name;
  907. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  908. if(preg_match('/REFS\s+([^;]*);/u',$m[2],$refs) && preg_match_all('/[0-9]{14}/u',$refs[1],$rs, PREG_SET_ORDER)){
  909. $item['refs']=[];
  910. foreach($rs as $r){ if(!in_array($r[0], $item['refs'])) $item['refs'][] = $r[0]; }
  911. }
  912. if(preg_match('/GAL\s+([^;]*);/u',$m[2],$gals) && preg_match_all('/(\S+)/u',$gals[1],$ga, PREG_SET_ORDER)){
  913. $item['galleries']=[];
  914. foreach($ga as $g){ if(!in_array($g[0], $item['galleries'])) $item['galleries'][] = $g[0]; }
  915. }
  916. if(preg_match('/PRODUCT\s+([^;]*);/u',$m[2],$product)){ $item['product']=$product[1]; }
  917. if(preg_match('/PARENT\s+([^;]*);/u',$m[2],$parent)){ $item['parent']=$parent[1]; }
  918. if(preg_match('/TITLE\s+([^;]*);/u',$m[2],$title)){ $item['title']=$title[1]; }
  919. if(preg_match('/HERE\s+([^;]*);/u',$m[2],$heres) && preg_match_all('/(\S+)-(\S+)-(\S+)/u',$heres[1],$here, PREG_SET_ORDER)){
  920. $item['here']=[];
  921. foreach($here as $h){ if(!$this->ImageHasHere($item, $h[1])) $item['here'][] = [$h[1],$h[2],$h[3]]; }
  922. }
  923. $this->Images[] = $item;
  924. }
  925. $files = array_merge([],glob('images/*.jpg'));
  926. $files = array_merge($files,glob('images/*.jpeg'));
  927. $files = array_merge($files,glob('images/*.png'));
  928. $files = array_merge($files,glob('images/*.gif'));
  929. if(isset($files[0]))foreach($files as $file) {
  930. if(preg_match('/[0-9]{14,}\.(jpg|jpeg|gif|png)/u', $file, $m)) {
  931. $name = trim($m[0]);
  932. if(!$this->FindImage($name)){
  933. $item = []; $item['name']=$name; $item['file'] = 'images/'.$name;
  934. if(file_exists('images/thumb/'.$name)){$item['thumb']='images/thumb/'.$name;}else{$item['thumb']='images/'.$name;}
  935. $this->Images[] = $item;
  936. }
  937. }
  938. }
  939. if($clear_non_exist){
  940. if(isset($this->Images[0]) && isset($files[0])){
  941. foreach($this->Images as &$im){
  942. if(!in_array($im['file'],$files)){
  943. $im['deleted'] = 1;
  944. }
  945. }
  946. }
  947. }
  948. function cmpf($a, $b){
  949. if ($a['name'] == $b['name']) return 0;
  950. return (($a['name'] > $b['name']) ? 1 : -1);
  951. }
  952. function cmpaf($a, $b){
  953. if ($a['name'] == $b['name']) return 0;
  954. return ($a['name'] > $b['name']) ? -1 : 1;
  955. }
  956. if(isset($this->Galleries[0]))usort($this->Galleries,"cmpf");
  957. if(isset($this->Images[0]))usort($this->Images,"cmpaf");
  958. $this->DoneReadImages = 1;
  959. }
  960. function WriteImages(){
  961. if(isset($this->WayBack)) return;
  962. $path = 'images/list.md';
  963. $f = fopen($path,'w');
  964. if(isset($this->Galleries[0]))foreach($this->Galleries as &$g){
  965. if(isset($g['deleted'])) continue;
  966. fwrite($f,'GALLERY '.$g['name']);
  967. if(isset($g['featured']) && $g['featured']!=false) { fwrite($f,' FEATURED;'); }
  968. if(isset($g['experimental']) && $g['experimental']!=false) { fwrite($f,' EXPERIMENTAL;'); }
  969. fwrite($f, PHP_EOL);
  970. }
  971. if(isset($this->Images[0]))foreach($this->Images as &$im){
  972. if(isset($im['deleted'])) continue;
  973. fwrite($f, "- ".$im['name'].'; ');
  974. if(isset($im['refs']) && isset($im['refs'][0])){ fwrite($f, 'REFS '.implode(" ",$im['refs'])."; "); }
  975. if(isset($im['galleries']) && isset($im['galleries'][0])){ fwrite($f, 'GAL '.implode(" ",$im['galleries'])."; "); }
  976. if(isset($im['product']) && $im['product']!=''){ fwrite($f, 'PRODUCT '.$im['product']."; "); }
  977. if(isset($im['parent']) && $im['parent']!=''){ fwrite($f, 'PARENT '.$im['parent']."; "); }
  978. if(isset($im['title']) && $im['title']!=''){ fwrite($f, 'TITLE '.$im['title']."; "); }
  979. if(isset($im['here']) && $im['here']!=''){ fwrite($f, 'HERE ');
  980. foreach($im['here'] as $here){ fwrite($f, implode('-',$here).' '); } fwrite($f, '; ');
  981. }
  982. fwrite($f, PHP_EOL);
  983. }
  984. fflush($f);
  985. fclose($f);
  986. }
  987. function EditImage($name, $link_gallery, $do_remove = false, $product_link=NULL, $rename=NULL, $parent=NULL){
  988. if(!($im = &$this->FindImage($name))) return;
  989. if(isset($link_gallery)){
  990. if($do_remove){
  991. if(!isset($im['galleries']) || !isset($im['galleries'][0])) return;
  992. foreach($im['galleries'] as $key => $g){ if ($g==$link_gallery) unset($im['galleries'][$key]); }
  993. $im['galleries'] = array_merge($im['galleries']);
  994. }else{
  995. if(!isset($im['galleries'])) $im['galleries']=[];
  996. foreach($im['galleries'] as &$g){ if ($g==$link_gallery) return; }
  997. $im['galleries'][]=$link_gallery;
  998. }
  999. }
  1000. if(isset($product_link)){
  1001. if($product_link!=''){$im['product']=$product_link;}
  1002. else{unset($im['product']);}
  1003. }
  1004. if(isset($rename) && $rename!=$im['name']){
  1005. $ext=pathinfo($im['file'],PATHINFO_EXTENSION);
  1006. rename($im['file'], 'images/'.$rename.'.'.$ext);
  1007. if(isset($im['thumb'])) rename($im['thumb'], 'images/thumb/'.$rename.'.'.$ext);
  1008. $im['name'] = $rename.'.'.$ext;
  1009. }
  1010. if(isset($parent) && $parent!=$im['parent']){
  1011. if($parent==''){ unset($im['parent']); }
  1012. else{ $im['parent'] = $parent; }
  1013. }
  1014. $this->NeedWriteImages = 1;
  1015. }
  1016. function RegenerateThumbnails(){
  1017. $glob = glob('images/*.jpg');
  1018. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1019. foreach($glob as $file) {
  1020. $thumb_destination = 'images/thumb/'.basename($file);
  1021. $img = new Imagick($file); $geo=$img->getImageGeometry();
  1022. $width=$geo['width']; $height=$geo['height'];
  1023. $lim=400;
  1024. $scale = $lim / min($width,$height);
  1025. if($scale<1){
  1026. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1027. }
  1028. $img->setImageFormat('jpeg');
  1029. $img->setImageCompressionQuality(90);
  1030. $img->writeImage($thumb_destination);
  1031. }
  1032. }
  1033. function CompressImage($source, $destination, $thumb_destination, $quality, $sizelim, $abs_max) {
  1034. $img = new Imagick($source); $geo=$img->getImageGeometry(); $img2 = clone $img;
  1035. $width=$geo['width']; $height=$geo['height'];
  1036. $lim=400;
  1037. $scale = $lim / min($width,$height);
  1038. if($scale<1){
  1039. $img->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.7);
  1040. }
  1041. $img->setImageFormat('jpeg');
  1042. $img->setImageCompressionQuality($quality);
  1043. $img->writeImage($thumb_destination);
  1044. $scale = min( $sizelim / min($width,$height), $abs_max / max($width,$height));
  1045. if($scale<1){
  1046. $img2->resizeImage($width*$scale,$height*$scale,imagick::FILTER_GAUSSIAN,0.5);
  1047. }
  1048. $img2->setImageFormat('jpeg');
  1049. $img2->setImageCompressionQuality($quality);
  1050. $img2->writeImage($destination);
  1051. }
  1052. function DoUpload(){
  1053. if(!isset($_FILES['upload_file_name'])) return 0;
  1054. if(!is_dir('images/thumb')) mkdir('images/thumb');
  1055. if($_FILES['upload_file_name']['error']>0){
  1056. echo"file upload err code ".$_FILES['upload_file_name']['error']; exit;
  1057. return -1;
  1058. }else{
  1059. $ext=pathinfo($_FILES['upload_file_name']['name'],PATHINFO_EXTENSION);
  1060. if(!in_array($ext,['jpg','jpeg','png','gif'])) return 0;
  1061. $fp = fopen('.la_lock',"w");
  1062. while (!flock($fp, LOCK_EX| LOCK_NB)){
  1063. usleep(10000);
  1064. }
  1065. $num=date('YmdHis'); $replace=0;
  1066. if(isset($_POST['image_replace_button']) && isset($_GET['pic']) && preg_match('/([0-9]{14,})/u',$_GET['pic'],$mim)){
  1067. $num = $mim[1]; $replace=1;
  1068. }
  1069. $base = 'images/'.$num;
  1070. $thumb = 'images/thumb/'.$num;
  1071. if($ext=='png') $ext='jpg';
  1072. $final_path = $base.'.'.$ext; $final_thumb = $thumb.'.'.$ext; $i=0;
  1073. if(!$replace) while(file_exists($final_path)){
  1074. $final_path = $base.strval($i).'.'.$ext; $final_thumb = $thumb.strval($i).'.'.$ext; $i++;
  1075. }
  1076. if($ext!='gif'){
  1077. $compress = (isset($_GET['compress'])&&$_GET['compress']);
  1078. $this->CompressImage($_FILES['upload_file_name']['tmp_name'], $final_path, $final_thumb, 90,
  1079. $compress?800:1920, $compress?1920:2560);
  1080. }else{
  1081. move_uploaded_file($_FILES['upload_file_name']['tmp_name'], $final_path);
  1082. }
  1083. flock($fp, LOCK_UN);
  1084. fclose($fp);
  1085. $this->ReadImages(true);
  1086. $this->WriteImages();
  1087. echo '<uploaded>'.pathinfo($final_path,PATHINFO_BASENAME)."</uploaded>";
  1088. if(isset($_POST['image_replace_button'])){
  1089. header('Location: '.$_SERVER['REQUEST_URI']);exit;
  1090. }
  1091. exit;
  1092. return 1;
  1093. }
  1094. return 0;
  1095. }
  1096. function &GetGallery($name){
  1097. if(isset($this->Galleries[0])) foreach($this->Galleries as &$g){
  1098. if($g['name'] == $name) return $g;
  1099. }
  1100. return $this->NULL_GALLERY;
  1101. }
  1102. function EditGallery($name, $new_name=null, $delete=false, $do_rw=true, $set_featured=null, $set_experimental=null){
  1103. $this->ReadImages();
  1104. $gallery = &$this->GetGallery($name);
  1105. if(!isset($gallery)){
  1106. if(!isset($new_name) || preg_match('/main|trash|\s/u',$new_name))return;
  1107. $g = []; $g['name']=$new_name;
  1108. $this->Galleries[]=$g;
  1109. }else{
  1110. if(isset($new_name)) {
  1111. if(preg_match('/main|trash|\s/u',$new_name))return;
  1112. $gallery['name'] = $new_name;
  1113. foreach ($this->Images as &$im){
  1114. if(isset($im['galleries'])&&isset($im['galleries'][0]))foreach($im['galleries'] as &$g){
  1115. if($g == $name){ $g = $new_name; }
  1116. }
  1117. }
  1118. }
  1119. //if(isset($count)) $gallery['count'] = $count;
  1120. if(isset($delete) && $delete) $gallery['deleted'] = true;
  1121. if(isset($set_featured)) $gallery['featured'] = $set_featured;
  1122. if(isset($set_experimental)) $gallery['experimental'] = $set_experimental;
  1123. }
  1124. if($do_rw) { $this->NeedWriteImages = 1; }
  1125. }
  1126. function ClearData(){
  1127. $this->Posts = [];
  1128. $this->Threads = [];
  1129. $this->Images = [];
  1130. $this->Archive = [];
  1131. $this->ArchiveHandles = [];
  1132. }
  1133. function InsertArchivePost(&$post){
  1134. $a = NULL;
  1135. if(($a = &$this->GetArchiveHandle($post['id']))==$this->NULL_POST){
  1136. $ah = []; $ah['id'] = $post['id']; $ah['list'] = [];
  1137. $this->ArchiveHandles[] = &$ah; $a = &$ah;
  1138. }
  1139. $a['list'][] = $post;
  1140. $this->Archive[] = $post;
  1141. }
  1142. function ReadArchiveFromFile($path){
  1143. if(!file_exists($path)){
  1144. return;
  1145. }
  1146. $c = file_get_contents($path);
  1147. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1148. foreach($matches as $m){
  1149. $post = [];
  1150. $post['id'] = $m[1];
  1151. $post['content'] = trim($m[3]);
  1152. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1153. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1154. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1155. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1156. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1157. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1158. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1159. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1160. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1161. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1162. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1163. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1164. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1165. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1166. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1167. $post['merged_into'] = [trim($n[1]),trim($n[2])];
  1168. }
  1169. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1170. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1171. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1172. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1173. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1174. }
  1175. $this->InsertArchivePost($post);
  1176. }
  1177. }
  1178. }
  1179. function SortArchive(){
  1180. $cmpac = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1181. $cmpap = function($a, $b){ if ($a['id'] == $b['id']) return ((($a['version'] > $b['version']) ? 1 : -1));
  1182. return (($a['id'] > $b['id']) ? 1 : -1);
  1183. };
  1184. if(isset($this->Archive[0])){
  1185. usort($this->Archive,$cmpap);
  1186. $year_begin = substr($this->Archive[0]['id'],0,4);
  1187. $this->YearBegin = ($year_begin<$this->YearBegin)?$year_begin:$this->YearBegin;
  1188. }
  1189. if(isset($this->ArchiveHandles[0])){
  1190. usort($this->ArchiveHandles,$cmpac);
  1191. foreach($this->ArchiveHandles as &$a){
  1192. if(isset($a['list'])){ usort($a['list'],$cmpap);
  1193. $last_valid=NULL;
  1194. foreach($a['list'] as &$ver){ $ver['archive']= &$a;
  1195. if(isset($ver['merged_thread'])){ $ver['content']=$last_valid; }
  1196. else{ $last_valid = $ver['content']; } }
  1197. if(isset($a['list'][0]['version'])&&$a['list'][0]['version']>$a['list'][0]['id']){ /* if early versions missing. */
  1198. $origin=$a['list'][0]; $origin['version']=$origin['id']; array_unshift($a['list'], $origin);
  1199. }
  1200. }
  1201. if(($p = &$this->GetPost($a['id'],true))!=NULL){
  1202. $p['archive'] = &$a;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. function ReadPostsFromFile($path){
  1208. if(!file_exists($path)){
  1209. $f = fopen($path,'w');
  1210. fclose($f);
  1211. }
  1212. $c = file_get_contents($path);
  1213. if(preg_match_all('/\[LAMDWIKIPOST\s+([0-9]{14})\s*;\s*([\s\S]*?)\]([\S\s]*?)(?=\[LAMDWIKIPOST|$)/u',$c,$matches,PREG_SET_ORDER)){
  1214. foreach($matches as $m){
  1215. $post = [];
  1216. $post['id'] = $m[1];
  1217. $post['real_content'] = trim($m[3]);
  1218. $post['content'] = &$post['real_content'];
  1219. if(preg_match('/COMMENT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['comment_to'] = $n[1];
  1220. if(preg_match('/EMAIL\s+([^;]+)\s*;/u', $m[2], $n)) $post['email'] = $n[1];
  1221. if(preg_match('/NAME\s+([^;]+)\s*;/u', $m[2], $n)) $post['name'] = $n[1];
  1222. if(preg_match('/LINK\s+([^;]+)\s*;/u', $m[2], $n)) $post['link'] = $n[1];
  1223. if(preg_match('/IP\s+([^;]+)\s*;/u', $m[2], $n)) $post['ip'] = $n[1];
  1224. if(preg_match('/NEXT\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['next'] = $n[1];
  1225. if(preg_match('/PREV\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['prev'] = $n[1];
  1226. if(preg_match('/VER\s+([0-9]{14})\s*;/u', $m[2], $n)) $post['version'] = $n[1];
  1227. if(preg_match('/MDEL\s*;/u', $m[2])) $post['mark_delete'] = True;
  1228. if(preg_match('/MVAL\s*([^;]+);/u', $m[2], $n)) $post['mark_value'] = trim($n[1]);
  1229. if(preg_match('/MSTDN\s+(\S+)\s*;/u', $m[2], $n)) $post['mastodon_url'] = $n[1];
  1230. if(preg_match('/REFS\s*([^;]+);/u', $m[2], $ma)){
  1231. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1232. foreach($links as $l){ $entries[] = $l[1]; } $post['refs'] = $entries; } }
  1233. if(preg_match('/HASP\s*([^;]+);/u', $m[2], $ma)){
  1234. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1235. foreach($links as $l){ $entries[] = $l[1]; } $post['hasp'] = $entries; } }
  1236. if(preg_match('/HASI\s*([^;]+);/u', $m[2], $ma)){
  1237. $entries = []; if(preg_match_all('/([0-9]{14}\.(jpg|jpeg|png|gif))/u',$ma[1],$links,PREG_SET_ORDER)){
  1238. foreach($links as $l){ $entries[] = $l[1]; } $post['hasi'] = $entries; } }
  1239. if(preg_match('/HASTAG\s*([^;]+);/u', $m[2], $ma)){
  1240. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1241. foreach($links as $l){ $entries[] = $l[1]; } $post['hastag'] = $entries; } }
  1242. if(preg_match('/FROM\s*([^;]+);/u', $m[2], $ma)){
  1243. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1244. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_from'] = $entries; } }
  1245. if(preg_match('/INTO\s*([0-9]{14})\s*V\s*([0-9]{14})\s*;/u', $m[2], $n)){
  1246. $post['merged_into'] = [trim($n[1]),trim($n[2])]; }
  1247. if(preg_match('/MTHREAD\s*([^;|]+)\s*\|\s*([^;]+);/u', $m[2], $ma)){
  1248. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[1],$links,PREG_SET_ORDER)){
  1249. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][0] = $entries; }
  1250. $entries = []; if(preg_match_all('/([0-9]{14})/u',$ma[2],$links,PREG_SET_ORDER)){
  1251. foreach($links as $l){ $entries[] = $l[1]; } $post['merged_thread'][1] = $entries; }
  1252. }
  1253. if(isset($post['mark_value']) && $post['mark_value']==5){
  1254. $post['product']=[];
  1255. }
  1256. /* marks add here */
  1257. $this->Posts[] = $post;
  1258. if(isset($post['comment_to']) && ($target_post = &$this->GetPost($post['comment_to'],true))){
  1259. if(!isset($target_post['comments']) || !isset($target_post['comments'][0])) $target_post['comments']=[];
  1260. $target_post['comments'][]=&$this->Posts[count($this->Posts) - 1];
  1261. }
  1262. }
  1263. }
  1264. }
  1265. function SortPosts($wayback=false){
  1266. $cmpp = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1267. $sortlist = &$this->Posts;
  1268. if($wayback) $sortlist = &$this->WaybackPosts;
  1269. if(isset($sortlist[0])){
  1270. usort($sortlist,$cmpp);
  1271. $this->YearEnd = substr($this->TIME_STRING,0,4);
  1272. $this->YearBegin = substr($sortlist[0]['id'],0,4);
  1273. }
  1274. }
  1275. function ReadPosts(){
  1276. if ((!file_exists('la_config.md') || is_readable('la_config.md') == false) ||
  1277. (!file_exists('la_config.php') || is_readable('la_config.php') == false) ||
  1278. (!is_dir('posts') || is_readable('posts') == false) ||
  1279. (!is_dir('archive') || is_readable('archive') == false) ||
  1280. (!is_dir('images') || is_readable('images') == false) ||
  1281. (!is_dir('styles') || is_readable('styles') == false)){
  1282. $this->Install();
  1283. }
  1284. if($this->DoneReadPosts){ return; }
  1285. $file_list = [];
  1286. $glob = glob('posts/*');
  1287. foreach($glob as $file) {
  1288. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1289. $file_list[] = $file;
  1290. }
  1291. }
  1292. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1293. foreach($file_list as $f) {
  1294. $this->ReadPostsFromFile($f);
  1295. }
  1296. $this->SortPosts();
  1297. $this->DetectThreads();
  1298. $this->DoneReadPosts=1;
  1299. }
  1300. function UpdatePostRefsForWayback(){
  1301. if(!isset($this->WayBack)) return;
  1302. if(isset($this->Images[0])) foreach($this->Images as &$i){ unset($i['refs']); }
  1303. if(!isset($this->WaybackPosts[0])) return;
  1304. foreach($this->WaybackPosts as &$p){ unset($p['refs']); }
  1305. foreach($this->WaybackPosts as &$p){
  1306. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $r){
  1307. $pr = &$this->GetPost($r); if(isset($pr)){
  1308. if(!isset($pr['refs'])) $pr['refs']=[];
  1309. if(!in_array($p['id'],$pr['refs'])){ $pr['refs'][] = $p['id']; }
  1310. }
  1311. }
  1312. if(isset($p['hasi']) && isset($p['hasi'][0])) foreach($p['hasi'] as $r){
  1313. $ir = &$this->FindImage($r); if(isset($ir)){
  1314. if(!isset($ir['refs'])) $ir['refs']=[];
  1315. if(!in_array($p['id'],$ir['refs'])){ $ir['refs'][] = $p['id'];}
  1316. }
  1317. }
  1318. if(isset($p['hasp']) && isset($p['hasp'][0])) foreach($p['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1319. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1320. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$p['id']; }
  1321. }
  1322. }
  1323. }
  1324. function ReadArchive(){
  1325. if (!is_dir('archive') || is_readable('archive') == false){ $this->Install(); }
  1326. if ($this->DoneReadArchive) return;
  1327. $file_list = []; $glob = glob('archive/*');
  1328. foreach($glob as $file) {
  1329. if(preg_match('/[0-9]{6}\.md/', $file)) {
  1330. $file_list[] = $file;
  1331. }
  1332. }
  1333. sort($file_list, SORT_NATURAL | SORT_FLAG_CASE);
  1334. foreach($file_list as $f) {
  1335. $this->ReadArchiveFromFile($f);
  1336. }
  1337. $this->SortArchive();
  1338. $this->DoneReadArchive=1;
  1339. $this->UpdateThreadForWayback();
  1340. $this->UpdatePostRefsForWayback();
  1341. }
  1342. function GetThreadForPost(&$post){
  1343. if(isset($post['tid'])) return;
  1344. $th = []; $iterp = NULL;
  1345. $post['tid'] = &$th; $th['first'] = &$post; $th['last'] = &$post;
  1346. if(!(isset($post['prev']) || isset($post['next']))) { $this->Threads[] = &$th; return; }
  1347. if(isset($post['prev']))for($p = $post['prev']; $p!=NULL; $p = $iterp){
  1348. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1349. $np['tid'] = &$th;
  1350. $th['first'] = &$np;
  1351. $iterp = isset($np['prev'])?$np['prev']:NULL;
  1352. }
  1353. if(isset($post['next']))for($p = $post['next']; $p!=NULL; $p = $iterp){
  1354. $np = &$this->GetPost($p,true); if(!$np) { break; }//err
  1355. $np['tid'] = &$th;
  1356. $th['last'] = &$np;
  1357. $iterp = isset($np['next'])?$np['next']:NULL;
  1358. }
  1359. if(isset($th['first']['mark_value'])){
  1360. if($th['first']['mark_value']==6) $th['exp'] = true;
  1361. else if($th['first']['mark_value']==7) $th['slf'] = true;
  1362. }
  1363. if($th['first'] == $th['last']){ unset($post['tid']); return; }
  1364. $this->Threads[] = &$th;
  1365. }
  1366. function IdentifyThreadCategory(&$th,&$first_post){
  1367. unset($th['categories']);unset($th['interesting']);unset($th['reversed']);
  1368. if(preg_match('/^\s*\@(.*?)$/mu',$first_post['content'],$m)){
  1369. $first_post['categories']=[]; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1370. foreach($matches as $ma){ $first_post['categories'][] = $ma[1]; }
  1371. }
  1372. if(isset($th) && $th){ $th['categories'] = &$first_post['categories']; }
  1373. }
  1374. if(isset($th) && preg_match('/\{\s*INTERESTING\s+(.*?)\}/imu',$first_post['content'],$m)){
  1375. $th['interesting'] = []; if(preg_match_all('/(\S+)(\s|$)/u',$m[1],$matches,PREG_SET_ORDER)){
  1376. foreach($matches as $ma){ $th['interesting'][] = $ma[1]; }
  1377. }
  1378. }
  1379. if(isset($th) && preg_match('/\{\s*REVERSED\s*\}/imu',$first_post['content'],$m)){
  1380. $th['reversed'] = true;
  1381. }
  1382. }
  1383. function IsInterestingPost(&$p){
  1384. if(isset($p['tid']) && isset($p['tid']['interesting']) && isset($p['tid']['interesting'][0])) return true;
  1385. return false;
  1386. }
  1387. function IsReversedThread(&$th){
  1388. if(isset($th['reversed']) && $th['reversed']) return true;
  1389. return false;
  1390. }
  1391. function GiveAllMergedPosts(&$po,&$arr){
  1392. if(isset($po['merged_from'])&&isset($po['merged_from'][0])) foreach($po['merged_from'] as $pm){
  1393. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr);}
  1394. }
  1395. if(isset($po['archive']) && isset($po['archive']['list'])){
  1396. foreach($po['archive']['list'] as &$ver){
  1397. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $pm){
  1398. $mp=&$this->GetPost($pm); if(isset($mp)){ if(!in_array($mp['id'],$arr)) $arr[]=$mp['id']; $this->GiveAllMergedPosts($mp,$arr); } }
  1399. }
  1400. }
  1401. }
  1402. function ThreadMakeWayback(&$th){
  1403. if(!isset($th['arr'][0])) return;
  1404. if(isset($this->WayBack)){
  1405. $remlist = [];
  1406. foreach($th['arr'] as &$pi){
  1407. $po = &$this->GetPost($pi['id'],true);
  1408. if(isset($po['merged_thread']) && isset($po['version']) && $po['version']>$this->WayBack){
  1409. $remlist = array_unique(array_merge($remlist,$po['merged_thread'][0]));
  1410. }
  1411. $ah = &$this->GetArchiveHandle($po['id']);
  1412. if(isset($ah)) foreach(array_reverse($ah['list']) as &$ver){
  1413. if(!isset($ver['merged_thread'])) continue;
  1414. if((isset($ver['version']) && $ver['version'] > $this->WayBack) ||
  1415. (!isset($ver['version']) && $ver['id'] > $this->WayBack)){
  1416. $remlist = array_unique(array_merge($remlist,$ver['merged_thread'][0]));
  1417. }
  1418. }
  1419. }
  1420. if(isset($remlist[0]) && isset($th['arr'][0])){
  1421. foreach($remlist as $rem){ $this->GiveAllMergedPosts($this->GetPost($rem,true),$remlist); }
  1422. foreach($th['arr'] as $key => $pr){
  1423. foreach($remlist as $rem){ if($pr['id'] == $rem) { unset($th['arr'][$key]); break; } } }
  1424. $new_th = []; $new_arr = [];
  1425. foreach($remlist as $rem){ $np=&$this->GetPost($rem); if(isset($np)){$new_arr[]=&$np;} }
  1426. $new_th['arr'] = &$new_arr;
  1427. $this->WaybackThreads[] = &$new_th;
  1428. $this->ThreadMakeWayback($new_th);
  1429. }
  1430. }
  1431. }
  1432. function AddMergedPosts(&$p, &$array){
  1433. if(isset($p['archive']) && isset($p['archive']['list'])){
  1434. foreach($p['archive']['list'] as &$ver){
  1435. if(isset($ver['merged_from'])&&isset($ver['merged_from'][0])) foreach($ver['merged_from'] as $po){
  1436. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1437. }
  1438. }
  1439. if(isset($p['merged_from'])&&isset($p['merged_from'][0])) foreach($p['merged_from'] as $po){
  1440. $mp=&$this->GetPost($po); if(isset($mp)){ $array[]=&$mp; $this->WaybackPosts[]=&$mp; $this->AddMergedPosts($mp, $array); } }
  1441. }
  1442. function FinalizeThread(&$th, $relink_posts=false, $now){
  1443. $nextp=NULL; $arr=[]; $lasttime=NULL;
  1444. if(!isset($th['arr'])){
  1445. for($p = &$th['first']; $p!=$this->NULL_POST; $p = &$this->GetPost(isset($p['next'])?$p['next']:NULL,true)){
  1446. $arr[]=&$p;
  1447. } $th['arr'] = &$arr;
  1448. if(isset($this->WayBack) && $this->DoneReadArchive){ $new_arr=[];
  1449. foreach($arr as &$p){ $pa = &$this->GetPost($p['id']); if(isset($pa)) {$new_arr[]=&$pa;$this->WaybackPosts[]=&$pa;} }
  1450. foreach($arr as &$p){ $this->AddMergedPosts($p,$new_arr); }
  1451. $arr=&$new_arr; $th['arr']=&$new_arr;
  1452. $this->ThreadMakeWayback($th); }
  1453. }
  1454. $cmppt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1455. if(isset($th['arr'][0])){ usort($th['arr'],$cmppt); } $th['count'] = sizeof($th['arr']);
  1456. if($relink_posts){ $count = $th['count'];
  1457. $arr = &$th['arr'];
  1458. 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'];
  1459. $arr[$i]['tid']=&$th;}
  1460. $th['first'] = &$arr[0]; $th['last'] = &$arr[$count-1]; unset($arr[0]['prev']); unset($arr[$count-1]['next']);
  1461. }
  1462. $th['score'] = 0; if(!isset($th['first'])){ return; }
  1463. $this->IdentifyThreadCategory($th, $th['first']);
  1464. if(isset($this->WayBack)) $lasttime=$this->WayBack;
  1465. if(!isset($last_time)) $lasttime = DateTime::createFromFormat('YmdHis', $th['last']['id']);
  1466. $diff_days = ($now - date_timestamp_get($lasttime))/3600/24;
  1467. $th['score'] = (float)$th['count']*0.2 - min($diff_days,200);
  1468. }
  1469. function SortThreads(){
  1470. if (!function_exists('cmpt')) {
  1471. function cmpt($a, $b){
  1472. if ($a['score'] == $b['score']) return 0;
  1473. return ($a['score'] > $b['score']) ? -1 : 1;
  1474. }
  1475. }
  1476. usort($this->Threads,"cmpt");
  1477. }
  1478. function DetectThreads(){
  1479. foreach($this->Posts as &$p){
  1480. if(isset($p['tid'])) { continue; }
  1481. $this->GetThreadForPost($p);
  1482. if(!isset($p['tid'])) { $this->IdentifyThreadCategory($this->NULL_POST, $p); }
  1483. }
  1484. if(!isset($this->Threads) || !isset($this->Threads[0])) return;
  1485. $now = date_timestamp_get(date_create());
  1486. foreach($this->Threads as &$t){
  1487. $this->FinalizeThread($t,false,$now);
  1488. }
  1489. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1490. $this->FinalizeThread($th,false,$now);
  1491. $this->Threads[] = &$th;
  1492. }
  1493. $this->SortThreads();
  1494. }
  1495. function UpdateThreadForWayback(){$now = date_timestamp_get(date_create());
  1496. if(!isset($this->WayBack) || !$this->DoneReadArchive){ return; }
  1497. foreach($this->Threads as &$t){
  1498. unset($t['arr']); $this->FinalizeThread($t,true,$now);
  1499. }
  1500. if(isset($this->WaybackThreads[0])) foreach($this->WaybackThreads as &$th){
  1501. $this->FinalizeThread($th,true,$now);
  1502. $this->Threads[] = &$th;
  1503. }
  1504. $this->SortThreads();
  1505. $this->SortPosts(true);
  1506. $this->UsePosts = &$this->WaybackPosts;
  1507. }
  1508. function &GetMergedPost($id){
  1509. $this->ReadArchive();
  1510. $ah = &$this->GetArchiveHandle($id);
  1511. if(!isset($ah) || !isset($ah['list']) || !isset($ah['list'][0])){ return $this->NULL_POST; }
  1512. $ver = &$ah['list'][sizeof($ah['list'])-1];
  1513. if(!isset($ver['merged_into'])) return $this->GetPost($id);
  1514. [$tp, $tver] = $ver['merged_into'];
  1515. if(isset($this->WayBack)){
  1516. if($tver <= $this->WayBack) return $this->GetMergedPost($tp);
  1517. else return $this->GetPost($id); /* should not happen directly. */
  1518. }
  1519. return $this->GetMergedPost($tp);
  1520. }
  1521. function &GetPost($id, $latest_only=false, $find_merged=false){
  1522. if(!isset($id)) return $this->NULL_POST;
  1523. $found=&$this->NULL_POST;
  1524. if(isset($this->Posts[0])) foreach($this->Posts as &$p){
  1525. if($p&& $p['id'] == $id) { $found = &$p; break; }
  1526. if($find_merged && isset($p['hastag'][0]) && in_array($id, $p['hastag'])){ $found = &$p; break; }
  1527. }
  1528. if($latest_only || !isset($this->WayBack)){ return $found; }
  1529. else{
  1530. if(isset($found)){
  1531. if(!isset($found['archive'])&&!isset($found['archive']['list']))
  1532. { if($found['id'] > $this->WayBack) return $this->NULL_POST; else return $found; }
  1533. $last_ver = &$this->NULL_POST;
  1534. if(isset($found['archive']['list'][0])) foreach($found['archive']['list'] as &$ver){
  1535. if($ver['version'] > $this->WayBack) return $last_ver;
  1536. $last_ver = &$ver;
  1537. }
  1538. if(isset($found['version']) && $found['version'] <= $this->WayBack) return $found;
  1539. else return $last_ver;
  1540. }else{
  1541. $ah = &$this->GetArchiveHandle($id); $last_ver = &$this->NULL_POST;
  1542. if(isset($ah) && isset($ah['list']) && isset($ah['list'][0])) foreach($ah['list'] as &$ver){
  1543. if($ver['version'] > $this->WayBack) return $last_ver;
  1544. $last_ver = &$ver;
  1545. } if(!isset($last_ver['merged_into'])) return $last_ver; else{
  1546. [$tp, $tver] = $last_ver['merged_into'];
  1547. if($tver <= $this->WayBack) {
  1548. if($find_merged && $tp!=$id) return $this->GetPost($tp); return $this->NULL_POST; }
  1549. return $last_ver;
  1550. }
  1551. }
  1552. }
  1553. return $this->NULL_POST;
  1554. }
  1555. function &GetArchiveHandle($id){
  1556. if(!isset($id)) return $this->NULL_POST;
  1557. if(isset($this->ArchiveHandles[0])) foreach($this->ArchiveHandles as &$p){
  1558. if($p && $p['id'] == $id) { return $p; }
  1559. }
  1560. return $this->NULL_POST;
  1561. }
  1562. function &GetArchive($id){
  1563. if(!isset($id)) return $this->NULL_POST;
  1564. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1565. if($p && $p['id'] == $id) { return $p; }
  1566. }
  1567. return $this->NULL_POST;
  1568. }
  1569. function &GetArchiveVersion(&$ah, $version, &$next_ver, &$last_ver){
  1570. if(!isset($ah)) return $this->NULL_POST;
  1571. $found = NULL; $last_verp=NULL;
  1572. if(isset($ah['list'][0])) foreach($ah['list'] as &$p){
  1573. if(isset($found)){ $next_ver = $p; $last_ver = $last_verp; return $found; }
  1574. if($p && $p['version'] == $version) { $found = &$p; continue; }
  1575. $last_verp = &$p;
  1576. }
  1577. if(isset($found)) { $next_ver=NULL; $last_ver = $last_verp; return $found; }
  1578. return $this->NULL_POST;
  1579. }
  1580. function CacheArchiveOwnLinks(){
  1581. if(isset($this->WayBack)) return;
  1582. if(isset($this->Archive[0])) foreach($this->Archive as &$p){
  1583. $this->ConvertPost($p); unset($p['hasp']); unset($p['hasi']); unset($p['hastag']);
  1584. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$p['html'],$matches,PREG_SET_ORDER)){
  1585. foreach($matches as $m){
  1586. if(!isset($p['hasp']))$p['hasp']=[]; if(!in_array($m[1],$p['hasp'])){ $p['hasp'][]=$m[1]; }
  1587. }
  1588. }
  1589. if(preg_match_all('/\/\/([0-9]{14})/u', $p['content'],$matches,PREG_SET_ORDER)){
  1590. foreach($matches as $m){
  1591. if(!isset($p['hastag']))$p['hastag']=[]; if(!in_array($m[1],$p['hastag'])){ $p['hastag'][]=$m[1]; }
  1592. }
  1593. }
  1594. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $p['content'],$matches,PREG_SET_ORDER)){
  1595. foreach($matches as $m){
  1596. if(!isset($p['hasi']))$p['hasi']=[]; if(!in_array($m[2],$p['hasi'])){ $p['hasi'][]=$m[2]; }
  1597. }
  1598. }
  1599. }
  1600. }
  1601. function WriteArchive(){
  1602. if(isset($this->WayBack)) return;
  1603. $cf = NULL;$opened =NULL;
  1604. $this->SortArchive();
  1605. $this->CacheArchiveOwnLinks();
  1606. if(isset($this->Archive[0])) foreach($this->Archive as $p){
  1607. $nid = substr($p['id'], 0,6);
  1608. if($cf != $nid){
  1609. if($opened){
  1610. fflush($opened);
  1611. fclose($opened);
  1612. }
  1613. $cf = $nid;
  1614. $opened = fopen("archive/$cf.md", 'w');
  1615. }
  1616. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1617. "VER {$p['version']}; ".
  1618. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1619. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1]).";"):"").
  1620. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1621. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1622. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1623. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1624. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1625. ']';
  1626. if(isset($p['merged_thread'])){ $p['content']=""; }
  1627. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['content'].PHP_EOL.PHP_EOL);
  1628. }
  1629. }
  1630. function WritePosts(){
  1631. if(isset($this->WayBack)) return;
  1632. $cf = NULL;$opened =NULL;
  1633. $this->SortPosts();
  1634. if(isset($this->Posts[0])) foreach($this->Posts as $p){
  1635. $nid = substr($p['id'], 0,6);
  1636. if($cf != $nid){
  1637. if($opened){
  1638. fflush($opened);
  1639. fclose($opened);
  1640. }
  1641. $cf = $nid;
  1642. $opened = fopen("posts/$cf.md", 'w');
  1643. }
  1644. $info = "[LAMDWIKIPOST {$p['id']}; ".
  1645. ((isset($p['version']) && $p['version'])?"VER {$p['version']}; ":"").
  1646. ((isset($p['merged_from']) && isset($p['merged_from'][0]))?("FROM ".implode(" ",$p['merged_from'])."; "):"").
  1647. ((isset($p['merged_into']) && isset($p['merged_into'][0]))?("INTO {$p['merged_into'][0]}V{$p['merged_into'][1]}; "):"").
  1648. ((isset($p['merged_thread']) && isset($p['merged_thread'][0]))?
  1649. ("MTHREAD ".implode(" ",$p['merged_thread'][0])." | ".implode(" ",$p['merged_thread'][1])."; "):"").
  1650. ((isset($p['comment_to']) && $p['comment_to'])?"COMMENT {$p['comment_to']}; ":"").
  1651. ((isset($p['email']) && $p['email'])?"EMAIL {$p['email']}; ":"").
  1652. ((isset($p['name']) && $p['name'])?"NAME {$p['name']}; ":"").
  1653. ((isset($p['link']) && $p['link'])?"LINK {$p['link']}; ":"").
  1654. ((isset($p['ip']) && $p['ip'])?"IP {$p['ip']}; ":"").
  1655. ((isset($p['mark_delete']) && $p['mark_delete'])?"MDEL; ":"").
  1656. ((isset($p['mark_value']) && $p['mark_value']>=0)?"MVAL {$p['mark_value']}; ":"").
  1657. ((isset($p['next']) && $p['next'])?"NEXT {$p['next']}; ":"").
  1658. ((isset($p['prev']) && $p['prev'])?"PREV {$p['prev']}; ":"").
  1659. ((isset($p['refs']) && isset($p['refs'][0]))?("REFS ".implode(" ",$p['refs'])."; "):"").
  1660. ((isset($p['hasp']) && isset($p['hasp'][0]))?("HASP ".implode(" ",$p['hasp'])."; "):"").
  1661. ((isset($p['hastag']) && isset($p['hastag'][0]))?("HASTAG ".implode(" ",$p['hastag'])."; "):"").
  1662. ((isset($p['hasi']) && isset($p['hasi'][0]))?("HASI ".implode(" ",$p['hasi'])."; "):"").
  1663. ((isset($p['mastodon_url']) && isset($p['mastodon_url']))?("MSTDN ".$p['mastodon_url']."; "):"").
  1664. ']';
  1665. fwrite($opened, $info.PHP_EOL.PHP_EOL.$p['real_content'].PHP_EOL.PHP_EOL);
  1666. }
  1667. }
  1668. function CachePostLinks(){
  1669. if(isset($this->WayBack)) return;
  1670. if(isset($this->Posts) && isset($this->Posts[0]))foreach ($this->Posts as &$post){
  1671. $this->ConvertPost($post);
  1672. unset($post['refs']);unset($post['hasp']);unset($post['hasi']);unset($post['hastag']);
  1673. //discard lost old version
  1674. //if(!isset($post['archive']) && $this->DoneReadArchive && isset($post['version'])){ unset($post['version']); }
  1675. }else return;
  1676. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1677. unset($im['refs']); unset($im['here']); unset($im['title']);
  1678. }
  1679. foreach ($this->Posts as &$post){
  1680. if(preg_match_all('/<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>.*?<\/a>/u',$post['html'],$matches,PREG_SET_ORDER)){
  1681. foreach($matches as $m){
  1682. $ref = &$this->GetPost($m[1],true);
  1683. if($ref!=NULL){
  1684. if(!isset($ref['refs']))$ref['refs']=[]; if(!in_array($post['id'],$ref['refs']))$ref['refs'][]=$post['id'];
  1685. }
  1686. if(!isset($post['hasp']))$post['hasp']=[]; if(!in_array($m[1],$post['hasp']))$post['hasp'][]=$m[1];
  1687. }
  1688. }
  1689. if(preg_match_all('/\/\/([0-9]{14})/u', $post['content'],$matches,PREG_SET_ORDER)){
  1690. foreach($matches as $m){
  1691. if(!isset($post['hastag']))$post['hastag']=[]; if(!in_array($m[1],$post['hastag']))$post['hastag'][]=$m[1];
  1692. }
  1693. }
  1694. if(preg_match_all('/!\[([^\]]*)\]\(images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\)/u', $post['content'],$matches,PREG_SET_ORDER)){
  1695. foreach($matches as $m){
  1696. if(($im = &$this->FindImage($m[2]))!=NULL){
  1697. if(!isset($im['refs']))$im['refs']=[]; if(!in_array($post['id'], $im['refs']))$im['refs'][] = $post['id'];
  1698. }
  1699. if(!isset($post['hasi']))$post['hasi']=[]; if(!in_array($m[2],$post['hasi']))$post['hasi'][]=$m[2];
  1700. }
  1701. }
  1702. if(preg_match("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R(-|\*).+){1,})/u",$post['content'],$matches)){
  1703. $use_img_name = $matches[2];
  1704. if(($im = &$this->FindImage($use_img_name))!=NULL){
  1705. if(preg_match_all("/(-|\*)\s+here\s*:\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s+images\/([0-9]{14,}\.(jpg|jpeg|png|gif))/u",$matches[4],$mah,PREG_SET_ORDER)){
  1706. foreach($mah as $ma){
  1707. if(!isset($im['here']))$im['here']=[]; if(!$this->ImageHasHere($item, $ma[4])){
  1708. $here = [$ma[4], $ma[2], $ma[3]]; $im['here'][] = $here; }
  1709. }
  1710. }
  1711. }
  1712. }
  1713. }foreach($this->Posts as &$post){
  1714. if(isset($post['hasp']) && isset($post['hasp'][0])) foreach($post['hasp'] as $t){ if(!preg_match("/[0-9]{14}/u",$t)) continue;
  1715. $pt=&$this->GetPost($t,false,true); if(isset($pt) && isset($pt['hastag']) && isset($pt['hastag'][0]) && in_array($t,$pt['hastag'])){
  1716. if(!isset($pt['refs']))$pt['refs']=[]; $pt['refs'][]=$post['id']; }
  1717. }
  1718. }
  1719. if(isset($this->Images) && isset($this->Images[0])) foreach ($this->Images as &$im){
  1720. $min_id = '99999999999999';
  1721. if(isset($im['refs']) && isset($im['refs'][0])) foreach ($im['refs'] as &$ref){
  1722. $r = &$this->GetPost($ref,true); if(isset($r)) $title = $this->GetPostTitle($r,true,false);
  1723. if($title && $ref<$min_id) { $im['title'] = preg_replace('/;/u',' ',trim($title)); $min_id=$r['id']; }
  1724. }
  1725. }
  1726. }
  1727. function CreatePostAnchor(&$post){
  1728. $that=&$this;
  1729. $post['html'] = preg_replace_callback('/<h([0-9])>(.+?)(?=<\/h[0-9]>)/u', function ($ma) use ($that){
  1730. $id = '_heading_'.sizeof($this->Anchors);
  1731. $entry=[(int)$ma[1], $id, $ma[2]];
  1732. $that->Anchors[] = $entry;
  1733. return "<h${ma[1]} id='${id}'>${ma[2]}";
  1734. }, $post['html']);
  1735. }
  1736. function RenamePost(&$post, $rename){
  1737. foreach($this->Posts as &$p){
  1738. if($p['id']==$rename && $p!==$post) { return; /* don't overwrite */ }
  1739. }
  1740. foreach($this->Posts as &$p){
  1741. if(isset($p['prev']) && $p['prev']==$post['id']) { $p['prev']=$rename; }
  1742. if(isset($p['next']) && $p['next']==$post['id']) { $p['next']=$rename; }
  1743. }
  1744. $post['id'] = $rename;
  1745. }
  1746. function DetachPost(&$th,&$post){
  1747. $p0=$p1=NULL;foreach($th['arr'] as $a) echo $a['id']." "; echo '&nbsp;&nbsp;&nbsp;-'.$post['id']."<br />";
  1748. if(isset($post['prev'])){$p0=&$this->GetPost($post['prev'],true);} if(isset($post['next'])){$p1=&$this->GetPost($post['next'],true);}
  1749. if(isset($p0)){ $p0['next']=$p1['id']; }else{ $th['first']=$p1['id']; }
  1750. if(isset($p1)){ $p1['prev'] =$p0['id']; }else{ $th['last']=$p0['id']; }
  1751. foreach($this->Posts as $key => $p){ if ($p==$post) unset($this->Posts[$key]); }
  1752. unset($th['arr']); $now = date_timestamp_get(date_create());
  1753. $this->FinalizeThread($th, true, $now);
  1754. }
  1755. function PushPostVersion(&$post, $optime_id, $mode=1, $info=NULL){
  1756. $a = &$this->GetArchiveHandle($post['id']);
  1757. $ap = []; $ap['id'] = $post['id']; $ap['content'] = $post['real_content'];
  1758. $ap['version'] = isset($post['version'])?$post['version']:$ap['id'];
  1759. if(isset($post['merged_from'])) { $ap['merged_from'] = $post['merged_from']; unset($post['merged_from']); }
  1760. if(isset($post['merged_into'])) { $ap['merged_into'] = $post['merged_into']; unset($post['merged_into']); }
  1761. if(isset($post['merged_thread'])) { $ap['merged_thread'] = $post['merged_thread']; unset($post['merged_thread']); }
  1762. $post['version'] = $optime_id;
  1763. if($mode==1){
  1764. $this->InsertArchivePost($ap);
  1765. }else if($mode==2){
  1766. $post['merged_from'] = $info;
  1767. $this->InsertArchivePost($ap);
  1768. }else if($mode==3){
  1769. $ap['merged_into'] = $info;
  1770. $this->InsertArchivePost($ap);
  1771. if(isset($post['tid']) && $post['tid']['first']!=$post['tid']['last'] && $post!=$post['tid']['first']){
  1772. $this->DetachPost($post['tid'], $post);
  1773. }
  1774. }else if($mode==4){
  1775. $post['merged_thread'] = $info;
  1776. $this->InsertArchivePost($ap);
  1777. }
  1778. }
  1779. function &MergeThreads($post_id, $post_into_id){
  1780. $this->ReadPosts();
  1781. $po = &$this->GetPost($post_id, true); $pt = &$this->GetPost($post_into_id, true);
  1782. if (!isset($po) || !isset($pt) || !isset($po['tid']) || !isset($pt['tid']) ||
  1783. !isset($po['tid']['arr'][0]) || !isset($pt['tid']['arr'][0])){ return $this->NULL_POST; }
  1784. $po = &$po['tid']['arr'][0]; $pt = &$pt['tid']['arr'][0];
  1785. $th = &$po['tid']; $tt = &$pt['tid']; $info=[[],[]];
  1786. if($po['id'] < $pt['id']){ $temp = &$th; $th=&$tt; $tt=&$temp; $temp = &$po; $po=&$pt; $pt=&$temp; }
  1787. foreach($th['arr'] as &$p){ $info[0][]=$p['id']; }
  1788. foreach($tt['arr'] as &$p){ $info[1][]=$p['id']; }
  1789. $this->EditPost($pt['id'], NULL, NULL, NULL, false, NULL, NULL, 4, $info,NULL);
  1790. $arr_combined = array_merge($tt['arr'],$th['arr']);
  1791. $cmppmt = function($a, $b){ if ($a['id'] == $b['id']) return 0; return (($a['id'] > $b['id']) ? 1 : -1); };
  1792. if(isset($arr_combined[0])){ usort($arr_combined,$cmppmt); } $tt['arr']=&$arr_combined;
  1793. $tt['count'] = sizeof($tt['arr']);
  1794. $this->FinalizeThread($tt, true, $this->TIME_STRING);
  1795. $first_post = &$this->NULL_POST;
  1796. if(isset($tt['arr'][0])) $first_post= &$tt['arr'][0];
  1797. $this->NeedWritePosts=1;
  1798. $this->NeedWriteArchive=1;
  1799. return $first_post;
  1800. }
  1801. function &MergePosts($ids_string){
  1802. $ids = explode(" ", $ids_string);
  1803. $combined_content = ""; $first_id=NULL;
  1804. $this->ReadPosts(); $child_list=[];
  1805. foreach($ids as $id){
  1806. if(!preg_match('/[0-9]{14}/u',$id) || $this->GetPost($id,true)==$this->NULL_POST) continue;
  1807. if(!isset($first_id)) { $first_id = $id; } else { $combined_content.=PHP_EOL.PHP_EOL."//".$id.PHP_EOL; $child_list[]=$id; }
  1808. $combined_content.=$this->EditPost($id, NULL, NULL, NULL, true, NULL, NULL, false, NULL,NULL);
  1809. }
  1810. if(!isset($child_list[0])) return $this->NULL_POST;
  1811. $first_post = &$this->EditPost($first_id, $combined_content, NULL, NULL, false, NULL, NULL, 2, $child_list,NULL);
  1812. foreach($child_list as $id){
  1813. $this->EditPost($id, NULL, NULL, NULL, false, NULL, NULL, 3, [$first_id,$this->TIME_STRING],NULL);
  1814. }
  1815. $this->NeedWritePosts=1;
  1816. $this->NeedWriteArchive=1;
  1817. return $first_post;
  1818. }
  1819. /* push_version: 1 edit 2 post merged from ids list 3 post end into id-ver */
  1820. function &EditPost($id_if_edit, $content, $mark_delete, $reply_to,
  1821. $get_original_only=false, $mark_value=NULL, $rename=NULL,
  1822. $push_version=false, $version_info=NULL, $mastodon_url=NULL){
  1823. $this->ReadImages();
  1824. $this->ReadPosts();
  1825. if(isset($push_version) && $push_version){
  1826. $this->ReadArchive();
  1827. }
  1828. $p_success = NULL;
  1829. if(isset($id_if_edit)){
  1830. $post = &$this->GetPost($id_if_edit,true);
  1831. if($post===$this->NULL_POST) return $this->NULL_POST;
  1832. if($get_original_only){
  1833. return $post['real_content'];
  1834. }
  1835. if(isset($push_version) && $push_version){
  1836. $this->PushPostVersion($post,$this->TIME_STRING,$push_version,$version_info);
  1837. }
  1838. if(isset($content)) $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1839. if(isset($mark_delete)) $post['mark_delete'] = $mark_delete;
  1840. if(isset($mark_value)) $post['mark_value'] = $mark_value;
  1841. if(isset($rename) && preg_match('/^[0-9]{14}$/u',$rename)) $this->RenamePost($post,$rename);
  1842. if(isset($mastodon_url)) { if($mastodon_url!='') $post['mastodon_url']=$mastodon_url; else unset($post['mastodon_url']); }
  1843. $p_success = &$post;
  1844. }else{
  1845. if(!isset($content)) return $this->NULL_POST;
  1846. $id = date('YmdHis');
  1847. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1848. $post = []; $post['id'] = $id;
  1849. $post['real_content'] = $content; $post['content'] = &$post['real_content'];
  1850. if(isset($reply_to) && ($rep = &$this->GetPost($reply_to,true))!== $this->NULL_POST){
  1851. while($rep !== $this->NULL_POST && isset($rep['next']) && $rep['next']){ $rep = &$this->GetPost($rep['next'],true); }
  1852. if($rep !== $this->NULL_POST){ $rep['next'] = $id; $post['prev'] = $rep['id']; }
  1853. }
  1854. $this->Posts[] = $post;
  1855. $p_success = &$this->Posts[count($this->Posts) - 1];
  1856. }
  1857. $this->NeedWritePosts=1;
  1858. $this->NeedWriteImages=1;
  1859. if(isset($push_version) && $push_version){
  1860. $this->NeedWriteArchive=1;
  1861. }
  1862. return $p_success;
  1863. }
  1864. function &EditComment($id_if_edit, $comment_to_id, $content, $email, $name, $link=NULL, $ip=NULL){
  1865. $this->ReadPosts();
  1866. $p_success = NULL;
  1867. if(isset($id_if_edit)){
  1868. $post = &$this->GetPost($id_if_edit,true);
  1869. if($post===$this->NULL_POST || !isset($post['comment_to'])) return $this->NULL_POST;
  1870. if(isset($content)) $post['content'] = $content;
  1871. if(isset($comment_to_id)) $post['comment_to'] = $comment_to_id;
  1872. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1873. if(isset($ip)) $post['ip'] = $ip;
  1874. $p_success = &$post;
  1875. }else{
  1876. if(!isset($content) || !isset($comment_to_id)) return $this->NULL_POST;
  1877. $id = date('YmdHis');
  1878. if($this->GetPost($id,true)!== $this->NULL_POST) return $this->NULL_POST;
  1879. if(!($to_post=$this->GetPost($comment_to_id,true))) return $this->NULL_POST;
  1880. $post = []; $post['id'] = $id; $post['content'] = $content; $post['comment_to'] = $comment_to_id;
  1881. if(isset($email)) $post['email'] = $email; if(isset($name)) $post['name'] = $name; if(isset($link)) $post['link'] = $link;
  1882. if(isset($ip)) $post['ip'] = $ip;
  1883. $this->Posts[] = $post;
  1884. $p_success = &$this->Posts[count($this->Posts) - 1];
  1885. }
  1886. $this->NeedWritePosts=1;
  1887. return $p_success;
  1888. }
  1889. function InsertReplacementSymbols($MarkdownContent, &$post_for_it_is_here){
  1890. $replacement = preg_replace('/<!--[\s\S]*-->/U',"",$MarkdownContent);
  1891. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1892. function($matches){
  1893. $rep = preg_replace('/->/','-@>',$matches[0]);
  1894. $rep = preg_replace('/=>/','=@>',$rep);
  1895. $rep = preg_replace('/<=/','<@=',$rep);
  1896. $rep = preg_replace('/<-/','<@-',$rep);
  1897. $rep = preg_replace('/\R([+]{3,})\R/',PHP_EOL.'@$1'.PHP_EOL,$rep);
  1898. $rep = preg_replace('/\[-/','[@-',$rep);
  1899. $rep = preg_replace('/\{/','{@',$rep);
  1900. $rep = preg_replace('/(en|zh|any)\|(en|zh|any)/','$1@|$2',$rep);
  1901. return $rep;
  1902. },
  1903. $replacement);
  1904. $replacement = preg_replace("/<[-]+>/","↔",$replacement);
  1905. $replacement = preg_replace("/([^-])->/","$1→",$replacement);
  1906. $replacement = preg_replace("/<-([^-])/","←$1",$replacement);
  1907. $replacement = preg_replace("/([^-])[-]+->/","$1⟶",$replacement);
  1908. $replacement = preg_replace("/<-[-]+([^-])/","⟵$1",$replacement);
  1909. $replacement = preg_replace("/<[=]+>/","⇔",$replacement);
  1910. $replacement = preg_replace("/[=]+>/","⇒",$replacement);
  1911. $replacement = preg_replace("/<[=]+/","⇐",$replacement);
  1912. $replacement = preg_replace("/\R([+]{3,})\R/","<div class='page_break'></div>",$replacement);
  1913. $replacement = preg_replace("/\[-(.*)-\]/U","<span class='text_highlight'>$1</span>",$replacement);
  1914. $replacement = preg_replace("/{支付宝(\s+[^}]*?)?}/u","<span class='special_alipay'>支付宝$1</span>",$replacement);
  1915. $replacement = preg_replace("/{PayPal(\s+[^}]*?)?}/ui",
  1916. "<span class='special_paypal'>Pay<span class='special_paypal_inner'>Pal</span>$1</span>",$replacement);
  1917. $replacement = preg_replace("/\/\/([0-9]{14})/imu","<p class='wscroll' id='$1'>".$this->T("链接位置")."</p>",$replacement);
  1918. $replacement = preg_replace_callback("/(```|`)([^`]*)(?1)/U",
  1919. function($matches){
  1920. $rep = preg_replace('/-@>/','->',$matches[0]);
  1921. $rep = preg_replace('/<@-/','<-',$rep);
  1922. $rep = preg_replace('/=@>/','=>',$rep);
  1923. $rep = preg_replace('/<@=/','<=',$rep);
  1924. $rep = preg_replace('/\R@([+]{3,})\R/',PHP_EOL.'$1'.PHP_EOL,$rep);
  1925. $rep = preg_replace('/\[@-/','[-',$rep);
  1926. $rep = preg_replace('/\{@/','{',$rep);
  1927. $rep = preg_replace('/(en|zh|any)@\|(en|zh|any)/','$1|$2',$rep);
  1928. return $rep;
  1929. }, $replacement);
  1930. $replacement = preg_replace_callback("/(\!\[.*?\]\(\s*images\/([0-9]{14,}\.(jpg|jpeg|png|gif))\))(\R*(\R.+){1,})/u",
  1931. function($matches) use (&$post_for_it_is_here){
  1932. $rep = preg_replace("/(-|\*)\s+here\s*:\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s+images\/([0-9]{14,}\.(jpg|jpeg|png|gif))/u","", $matches[4]);
  1933. return $matches[1].$rep;
  1934. }, $replacement);
  1935. return $replacement;
  1936. }
  1937. function CanShowPost(&$p){
  1938. if(!isset($p) || isset($p['comment_to'])) return false;
  1939. $is_mark_exp = (isset($p['tid'])&&isset($p['tid']['exp'])&&$p['tid']['exp']) || (isset($p['mark_value'])&&$p['mark_value']==6);
  1940. $is_mark_slf = (isset($p['tid'])&&isset($p['tid']['slf'])&&$p['tid']['slf']) || (isset($p['mark_value'])&&$p['mark_value']==7);
  1941. if($is_mark_slf && !$this->LoggedIn){ return false; }
  1942. if(isset($this->WayBack)){
  1943. if(isset($p['version'])) { if ($p['version']>$this->WayBack) return false; }
  1944. else if ($p['id']>$this->WayBack) return false;
  1945. }
  1946. if(!$this->InExperimentalMode){
  1947. if(!$this->LoggedIn){
  1948. if($is_mark_exp) return false;
  1949. return true;
  1950. }
  1951. return true;
  1952. }else{
  1953. if($is_mark_exp) return true;
  1954. return false;
  1955. }
  1956. }
  1957. function SkipProduct(&$p){
  1958. if($this->LoggedIn) return false;
  1959. return (isset($p['mark_value']) && $p['mark_value']==5);
  1960. }
  1961. function GetRedirect($args=NULL){
  1962. $str = 'index.php?';
  1963. if(isset($args['post'])) $str.='&post='.$args['post'];
  1964. else if(isset($_GET['post'])) $str.='&post='.$_GET['post'];
  1965. if(isset($args['gallery'])) $str.='&gallery='.$args['gallery'];
  1966. else if(isset($_GET['gallery'])) $str.='&gallery='.$_GET['gallery'];
  1967. if(isset($args['pic'])) $str.='&pic='.$args['pic'];
  1968. else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
  1969. if(isset($args['settings'])) $str.='&settings='.$args['settings'];
  1970. else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
  1971. if(isset($args['extras'])) $str.='&extras='.$args['extras'];
  1972. else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
  1973. if(isset($args['category'])) $str.='&category='.$args['category'];
  1974. else if(isset($_GET['category'])) $str.='&category='.$_GET['category'];
  1975. if(isset($args['history'])) $str.='&history='.$args['history'];
  1976. else if(isset($_GET['history'])) $str.='&history='.$_GET['history'];
  1977. if(isset($args['version'])) $str.='&version='.$args['version'];
  1978. else if(isset($_GET['version'])) $str.='&version='.$_GET['version'];
  1979. if(isset($args['search'])) $str.='&search='.$args['search'];
  1980. else if(isset($_GET['search'])) $str.='&search='.$_GET['search'];
  1981. if(isset($args['here'])) $str.='&here='.$args['here'];
  1982. else if(isset($_GET['here'])) $str.='&here='.$_GET['here'];
  1983. return $str;
  1984. }
  1985. function WriteAsNecessary(){
  1986. if(!$this->LoggedIn || isset($this->WayBack)){return;}
  1987. if($this->NeedWritePosts){ $this->CachePostLinks(); $this->WritePosts(); }
  1988. if($this->NeedWriteImages){ $this->WriteImages(); }
  1989. if($this->NeedWriteArchive){ $this->WriteArchive(); }
  1990. }
  1991. function APubEnsureWebfinger($name, $host){
  1992. if(!is_dir('.well-known')) mkdir('.well-known');
  1993. if(!is_dir('.well-known/webfinger')) mkdir('.well-known/webfinger');
  1994. $f = fopen('.well-known/webfinger/index.php',"w");
  1995. $without_protocol = parse_url($host, PHP_URL_HOST);
  1996. $finger = ["subject"=>"acct:".$name.'@'.$without_protocol,
  1997. "links"=>[["rel"=>"self", "type"=>"application/activity+json", "href"=>$host."?apub_actor=1"]]];
  1998. fwrite($f, "<?php header('Content-Type: application/json'); echo '".json_encode($finger, JSON_UNESCAPED_SLASHES)."'; ?>"); fclose($f);
  1999. if(!file_exists('.well-known/apub_public_key.pem') || !file_exists('.well-known/apub_private_key.php')){
  2000. $res = openssl_pkey_new();
  2001. $this->APubPublicKey = openssl_pkey_get_details($res)['key'];
  2002. openssl_pkey_export($res, $this->APubPrivateKey);
  2003. $f = fopen('.well-known/apub_public_key.pem',"w");
  2004. fwrite($f, $this->APubPublicKey); fclose($f);
  2005. $f = fopen('.well-known/apub_private_key.php',"w");
  2006. fwrite($f, "<?php exit; ?>".PHP_EOL.PHP_EOL.$this->APubPrivateKey); fclose($f);
  2007. }
  2008. }
  2009. function APubEnsureInfo(){
  2010. if(!isset($this->APubID) || !isset($this->HostURL)) return;
  2011. if(!file_exists('.well-known/apub_public_key.pem')){$this->APubEnsureWebfinger($this->APubID, $this->HostURL);}
  2012. $pk = file_get_contents('.well-known/apub_public_key.pem'); //$pk = preg_replace('/\n/u','\\n',$pk);
  2013. $actor = ["@context"=>["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],
  2014. "id"=> $this->HostURL."?apub_actor=1",
  2015. "type"=> "Person",
  2016. "name"=> $this->DisplayName,
  2017. "url"=> $this->HostURL,
  2018. "summary"=> "Lazy... No summary",
  2019. "preferredUsername"=> $this->APubID,
  2020. "inbox"=> $this->HostURL."?apub_inbox=1",
  2021. "outbox"=> $this->HostURL."?apub_outbox=1",
  2022. "publicKey"=> ["id"=> $this->HostURL."?apub_actor=1#main-key",
  2023. "owner"=> $this->HostURL."?apub_actor=1",
  2024. "publicKeyPem"=>$pk]];
  2025. $this->APubActor = json_encode($actor, JSON_UNESCAPED_SLASHES);
  2026. }
  2027. function APubMakeOutbox(){
  2028. $this->ReadPosts();$this->ReadImages();
  2029. $obj = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2030. "id"=>$this->HostURL."?apub_outbox=1",
  2031. "type"=>"OrderedCollection"];
  2032. $items=[]; $i=0;
  2033. foreach(array_reverse($this->Posts) as &$p){
  2034. $this->ConvertPost($p);
  2035. $text = strip_tags(preg_replace('/<\/(p|blockquote|h[0-9])>/u',"\n\n",$p['html']));
  2036. $time = DateTime::createFromFormat('YmdHis', $p['id'], new DateTimeZone('+0800'));
  2037. $ob = ["@context"=>"https://www.w3.org/ns/activitystreams",
  2038. "type"=> "Create",
  2039. "id"=> $this->HostURL."?post=".$p['id']."?apub_object=1",
  2040. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2041. //"to"=> ["https://chatty.example/ben/"],
  2042. "actor"=> $this->HostURL."?apub_actor=1",
  2043. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2044. "object"=> ["type"=> "Note",
  2045. "id"=> $this->HostURL."?post=".$p['id'],
  2046. "published"=> $time->format('Y-m-d\TH:i:s\Z'),
  2047. "attributedTo"=> $this->HostURL."?apub_actor=1",
  2048. "to"=> ["https://www.w3.org/ns/activitystreams#Public"],
  2049. "content"=> $text]];
  2050. $items[] = $ob;
  2051. $i++; if($i>20) break;
  2052. }
  2053. $obj['orderedItems'] = $items; $obj["totalItems"] = sizeof($items);
  2054. return json_encode($obj, JSON_UNESCAPED_SLASHES);
  2055. }
  2056. function MakeRSS(){
  2057. $this->ReadPosts();$this->ReadImages();
  2058. $author = "<author><name>".$this->DisplayName."</name><email>".$this->EMail."</email><uri>".$this->HostURL."</uri></author>";
  2059. $all_content="<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'>".
  2060. "<title>".$this->T($this->Title)."</title>".
  2061. "<link href='".$this->HostURL."/?rss' rel='self'/>".
  2062. "<link href='".$this->HostURL."' />".$author;
  2063. $i=0;
  2064. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  2065. if($i>100) break;
  2066. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  2067. if(isset($p['tid'])){ /* Should always be set. */
  2068. $th = &$p['tid']; if($p['tid']['count']==0) continue; }
  2069. if(in_array($p['id'],
  2070. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  2071. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  2072. $is_thread = isset($p['tid']['count'])&&($p['tid']['count']>1);
  2073. $is_reversed=false;
  2074. $content="<entry>"; $title = NULL;
  2075. if($is_thread){
  2076. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  2077. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  2078. foreach($use_arr as &$po){
  2079. $this->ConvertPost($po);
  2080. if(!isset($title)){$title = $this->GetPostTitle($po, false, false);
  2081. $content.="<id>tag:".$this->HostURL."-".$po['id']."</id>";
  2082. $content.="<title>".$title."</title><link>".$this->HostURL."/?post=".$po['id']."</link>";
  2083. $content.="<published>".$this->StandardTime($po['id'])."</published>";
  2084. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2085. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;
  2086. $content.="<content type='html'>"; }
  2087. $content.= htmlspecialchars($po['html']);
  2088. //if(isset($po['images'])&&isset($po['images'][0])) foreach($po['images'] as $im){ $content.=htmlspecialchars($im); }
  2089. }
  2090. $content.=$this->ReadableTime($p['tid']['first']['id'])." - ".
  2091. $this->ReadableTime(isset($p['tid']['last']['version'])?
  2092. $p['tid']['last']['version']:$p['tid']['last']['id']);
  2093. $content.="</content>";
  2094. }else{
  2095. $this->ConvertPost($p);
  2096. if(!isset($title)){$title = $this->GetPostTitle($p, false, false);
  2097. $content.="<id>tag:".$this->HostURL."-".$p['id']."</id>";
  2098. $content.="<title type='text'>".$title."</title><link>".$this->HostURL."/?post=".$p['id']."</link>";
  2099. $content.="<published>".$this->StandardTime($p['id'])."</published>";
  2100. $content.="<updated>".$this->StandardTime(isset($p['tid']['last']['version'])?
  2101. $p['tid']['last']['version']:$p['tid']['last']['id'])."</updated>".$author;}
  2102. $content.= "<content type='html'>".htmlspecialchars($p['html']);
  2103. //if(isset($p['images'])&&isset($p['images'][0])) foreach($p['images'] as $im){ $content.=htmlspecialchars($im); }
  2104. $content.=$this->ReadableTime($p['id'])." - ".
  2105. $this->ReadableTime(isset($p['version'])?$p['version']:$p['id']);
  2106. $content.="</content>";
  2107. }
  2108. $i++;
  2109. $content.="</entry>";
  2110. $all_content.=$content;
  2111. }
  2112. $all_content.="</feed>";
  2113. header( "Content-type: text/xml");
  2114. echo $all_content;
  2115. }
  2116. function MakeHereButtons($im, $insert_here){
  2117. if(isset($im['here'])&&isset($im['here'][0])){
  2118. $size=getimagesize($im['file']); $aspect=$size[0]/$size[1];
  2119. echo ($insert_here?"<here>":"")."<div class='here_buttons_inner' style='aspect-ratio:".$aspect.";'>";
  2120. foreach($im['here'] as $here){
  2121. if($insert_here){
  2122. echo "<a href='?show_image=".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'".
  2123. "onclick='event.preventDefault();event.stopPropagation();ShowBigImage(\"".$here[0]."\",1);'></a>";
  2124. }else{
  2125. echo "<a href='?here=images/".$here[0]."' class='here_btn' style='left:".$here[1]."%;top:".$here[2]."%;'></a>";
  2126. }
  2127. }
  2128. echo "</div>".($insert_here?"</here>":"");
  2129. }
  2130. }
  2131. function ProcessRequest(&$message=NULL, &$redirect=NULL){
  2132. if(isset($_GET['gallery']) && $_GET['gallery']=='default'){
  2133. $redirect = "index.php?gallery=".(isset($this->DefaultGallery)&&$this->DefaultGallery!=''?$this->DefaultGallery:"main");
  2134. return 0;
  2135. }
  2136. if(isset($_GET['set_language'])){
  2137. setcookie('la_language',$_GET['set_language'],time()+3600*24*7); $_COOKIE['la_language'] = $_GET['set_language'];
  2138. $redirect=$this->GetRedirect(); return 0;
  2139. }
  2140. if(isset($_GET['rss'])){
  2141. if(in_array($_GET['rss'],['en','zh'])){$this->LanguageAppendix=$_GET['rss'];}
  2142. $this->MakeRSS(); exit;
  2143. }
  2144. if(isset($_GET['toggle_font'])){ $use_font='local';
  2145. if(!isset($_COOKIE['la_font']) || $_COOKIE['la_font']!='remote') $use_font='remote';
  2146. setcookie('la_font',$use_font,time()+3600*24*7); $_COOKIE['la_font'] = $use_font;
  2147. $redirect=$this->GetRedirect(); return 0;
  2148. }
  2149. if(isset($_GET['set_wayback'])){
  2150. if($_GET['set_wayback']!='false'){
  2151. $wayback= date('YmdHis');
  2152. if($_GET['set_wayback']=='post'){
  2153. if(isset($_POST['wayback_year'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_year'],4,"0",STR_PAD_LEFT),0,4);
  2154. if(isset($_POST['wayback_month'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_month'],2,"0",STR_PAD_LEFT),4,2);
  2155. if(isset($_POST['wayback_day'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_day'],2,"0",STR_PAD_LEFT),6,2);
  2156. if(isset($_POST['wayback_hour'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_hour'],2,"0",STR_PAD_LEFT),8,2);
  2157. if(isset($_POST['wayback_minute'])) $wayback=substr_replace($wayback,str_pad($_POST['wayback_minute'],2,"0",STR_PAD_LEFT),10,2);
  2158. }else{ if(preg_match('/[0-9]{14}/u', $_GET['set_wayback'])) $wayback = $_GET['set_wayback']; }
  2159. setcookie('la_wayback',$wayback); $_COOKIE['la_wayback'] = $wayback;
  2160. }else{
  2161. setcookie('la_wayback', null, -1); unset($_COOKIE['la_wayback']);
  2162. }
  2163. $redirect=$this->GetRedirect(); return 0;
  2164. }
  2165. if(isset($_GET['post'])){ $this->CurrentPostID = $_GET['post']; $this->TagID = $this->CurrentPostID; }
  2166. if(isset($_GET['here'])){ $this->HereID = $_GET['here']; }
  2167. if(isset($_GET['offset'])){ $this->CurrentOffset = $_GET['offset']; }
  2168. if(isset($_GET['part'])){
  2169. if($_GET['part'] == 'hot') $this->ExtraScripts.="ShowLeftSide();";
  2170. else if ($_GET['part'] == 'recent') $this->ExtraScripts.="ShowCenterSide();";
  2171. }
  2172. if(isset($_GET['post'])){
  2173. $this->ExtraScripts.="window.addEventListener('load', (event) => {ScrollToPost('".$_GET['post']."');});";
  2174. }
  2175. if(isset($_GET['random_here'])){
  2176. $this->DoIdentiyExperimental(); $this->DetectPageType();
  2177. $im = &$this->GiveImageInHere(true); if(isset($im)){ $redirect='?here=images/'.$im['name']; return 0; }
  2178. }
  2179. if(isset($_POST['search_content'])){ $redirect='index.php?search='.$_POST['search_content'];return 0; }
  2180. if(isset($_GET['image_info']) || isset($_GET['show_image'])){
  2181. $m=isset($_GET['image_info'])?$_GET['image_info']:$_GET['show_image'];
  2182. $direct_return = !isset($_GET['show_image']);
  2183. $this->ReadImages(); $this->ReadPosts();
  2184. $this->SwitchWayBackMode(); if(isset($this->WayBack)){$this->ReadArchive();}
  2185. $im = &$this->FindImage($m);
  2186. if($im==NULL || !isset($im['refs']) || !isset($im['refs'][0])){ echo "not_found"; exit; }
  2187. if($direct_return){
  2188. echo "<ref>".sizeof($im['refs'])."</ref>";
  2189. echo "<insert><ul>";
  2190. }else{ ob_start(); }
  2191. foreach(array_reverse($im['refs']) as $ref){
  2192. $p = $this->GetPost($ref);
  2193. if(!$p || !$this->CanShowPost($p)) continue;
  2194. $this->MakeSinglePost($p, false, true, "post_preview", true, false, false, false, true);"</li>";
  2195. }
  2196. if($direct_return){
  2197. echo "</ul></insert>";
  2198. $this->MakeHereButtons($im, true);
  2199. }else{
  2200. $str = ob_get_clean();
  2201. $this->MakePageBegin();
  2202. $side = "";
  2203. if(isset($im['refs'])&&isset($im['refs'][0])){
  2204. $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
  2205. }else{$side.="<span class='smaller gray'>".$this->T('该图片未被引用')."</span>";}
  2206. $this->MakeImageOverlay($side."<ul>".$str."</ul>",$im['file']);
  2207. $this->MakePageEnd();
  2208. }
  2209. exit;
  2210. }
  2211. if(isset($_GET['confirm_enter']) && $_GET['confirm_enter']!=false){
  2212. setcookie('la_experimental','confirmed'); $_COOKIE['la_experimental'] = $_GET['confirmed'];
  2213. $redirect='index.php'.(isset($_GET['post'])?'?post='.$_GET['post']:"");return 0;
  2214. }
  2215. if(isset($_GET['apub_actor'])){
  2216. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2217. echo $this->APubActor; exit;
  2218. }
  2219. if(isset($_GET['apub_outbox'])){
  2220. $this->APubEnsureInfo(); header('Content-Type: application/json'); header('Cache-Control no-store, no-cache, must-revalidate');
  2221. echo $this->APubMakeOutbox(); exit;
  2222. }
  2223. if($this->LoggedIn){
  2224. $this->DoUpload();
  2225. if(isset($_POST['settings_button'])){
  2226. if(isset($_POST['settings_title'])) $this->Title=$_POST['settings_title'];
  2227. if(isset($_POST['settings_short_title'])) $this->ShortTitle=$_POST['settings_short_title'];
  2228. if(isset($_POST['settings_display_name'])) $this->DisplayName=$_POST['settings_display_name'];
  2229. if(isset($_POST['settings_email'])) $this->EMail=$_POST['settings_email'];
  2230. if(isset($_POST['settings_special_navigation'])) $this->SpecialNavigation=$_POST['settings_special_navigation'];
  2231. if(isset($_POST['settings_special_footer'])) $this->SpecialFooter=$_POST['settings_special_footer'];
  2232. if(isset($_POST['settings_special_footer2'])) $this->SpecialFooter2=$_POST['settings_special_footer2'];
  2233. if(isset($_POST['settings_special_pinned'])) $this->SpecialPinned=$_POST['settings_special_pinned'];
  2234. if(isset($_POST['settings_default_gallery'])) $this->DefaultGallery=$_POST['settings_default_gallery'];
  2235. if(isset($_POST['settings_selfauth_path'])) $this->SelfAuthPath=$_POST['settings_selfauth_path'];
  2236. if(isset($_POST['settings_enable_comments'])) $this->CommentEnabled=True; else $this->CommentEnabled=False;
  2237. if(isset($_POST['settings_here_host'])) $this->HereHost=$_POST['settings_here_host'];
  2238. if(isset($_POST['settings_here_title'])) $this->HereTitle=$_POST['settings_here_title'];
  2239. if(isset($_POST['settings_here_short_title'])) $this->HereShortTitle=$_POST['settings_here_short_title'];
  2240. if(isset($_POST['settings_here_album'])) $this->HereAlbum=$_POST['settings_here_album'];
  2241. if(isset($_POST['settings_here_navigation'])) $this->HereNavigation=$_POST['settings_here_navigation'];
  2242. if(isset($_POST['settings_here_footer'])) $this->HereFooter=$_POST['settings_here_footer'];
  2243. if(isset($_POST['settings_exp_host'])) $this->ExpHost=$_POST['settings_exp_host'];
  2244. if(isset($_POST['settings_exp_title'])) $this->ExpTitle=$_POST['settings_exp_title'];
  2245. if(isset($_POST['settings_exp_short_title'])) $this->ExpShortTitle=$_POST['settings_exp_short_title'];
  2246. if(isset($_POST['settings_exp_caution'])) $this->ExpCaution=$_POST['settings_exp_caution'];
  2247. if(isset($_POST['settings_exp_album'])) $this->ExpAlbum=$_POST['settings_exp_album'];
  2248. if(isset($_POST['settings_exp_navigation'])) $this->ExpNavigation=$_POST['settings_exp_navigation'];
  2249. if(isset($_POST['settings_exp_footer'])) $this->ExpFooter=$_POST['settings_exp_footer'];
  2250. if(isset($_POST['settings_mastodon_token'])) $this->MastodonToken=$_POST['settings_mastodon_token'];
  2251. if(isset($_POST['settings_mastodon_url'])) $this->MastodonURL=$_POST['settings_mastodon_url'];
  2252. if(isset($_POST['settings_mastodon_lang'])) $this->MastodonPreferredLang=$_POST['settings_mastodon_lang'];
  2253. if(isset($_POST['settings_host_url'])) $this->HostURL=$_POST['settings_host_url'];
  2254. if(isset($_POST['settings_apub_id']) && isset($this->HostURL)) {
  2255. $this->APubID=$_POST['settings_apub_id'];
  2256. $this->APubEnsureWebfinger($this->APubID,$this->HostURL);
  2257. }
  2258. if(isset($_POST['settings_old_password'])&&password_verify($_POST['settings_old_password'], $this->Password)){
  2259. if(isset($_POST['settings_id'])) $this->Admin=$_POST['settings_id'];
  2260. if(isset($_POST['settings_new_password']) && isset($_POST['settings_new_password_redo']) &&
  2261. $_POST['settings_new_password'] = $_POST['settings_new_password_redo'])
  2262. {$this->Password=password_hash($_POST['settings_new_password'], PASSWORD_DEFAULT);}
  2263. $redirect=$_SERVER['REQUEST_URI'];
  2264. $this->DoLogout();
  2265. }
  2266. $this->WriteConfig();
  2267. return 0;
  2268. }
  2269. if(isset($_POST['settings_save_redirect'])){
  2270. if(isset($_POST['settings_redirect'])){
  2271. $this->BuildRedirectConfig($_POST['settings_redirect']);
  2272. }
  2273. $this->WriteConfig();
  2274. $redirect = 'index.php?extras=true'; return 0;
  2275. }
  2276. if(isset($_POST['settings_save_translation'])){
  2277. if(isset($_POST['settings_translation'])){
  2278. $f = fopen("custom_translations.md", "w"); fwrite($f,$_POST['settings_translation']); fflush($f); fclose($f);
  2279. }
  2280. $redirect = 'index.php?extras=true'; return 0;
  2281. }
  2282. if(isset($_GET['post'])){
  2283. if(isset($_GET['post_original'])){
  2284. echo $this->EditPost($_GET['post'],NULL,false,NULL,true,NULL,NULL,false,NULL,NULL);
  2285. exit;
  2286. }
  2287. }
  2288. if(isset($_GET['mark_delete']) && isset($_GET['target'])){
  2289. $this->EditPost($_GET['target'],NULL,$_GET['mark_delete']=='true',NULL,false,NULL,NULL,false,NULL,NULL);
  2290. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2291. return 0;
  2292. }
  2293. if(isset($_GET['set_mark']) && isset($_GET['target'])){
  2294. $this->EditPost($_GET['target'],NULL,NULL,NULL,NULL,$_GET['set_mark'],NULL,false,NULL,NULL);
  2295. if(isset($_GET['post'])) $redirect='?post='.$_GET['target']; else $redirect=$this->GetRedirect();
  2296. return 0;
  2297. }
  2298. if(isset($_POST['post_button']) && isset($_POST['post_content'])){
  2299. $c = $_POST['post_content'];
  2300. if('有什么想说的' == $c){ return 0;}
  2301. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2302. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2303. $reply_to = (isset($_POST['post_reply_to'])&&$_POST['post_reply_to']!="")?$_POST['post_reply_to']:NULL;
  2304. $edit_id = (isset($_POST['post_edit_target'])&&$_POST['post_edit_target']!="")?$_POST['post_edit_target']:NULL;
  2305. $push_history = (isset($edit_id) && isset($_POST['post_record_edit']));
  2306. if(($edited = $this->EditPost($edit_id, $c, NULL, $reply_to,NULL,NULL,NULL,$push_history,NULL,NULL))!=NULL){
  2307. $redirect='?post='.$edited['id']; return 0;
  2308. };
  2309. }
  2310. if(isset($_POST['post_rename_confirm']) && isset($_POST['post_rename_name']) && isset($_GET['rename_post'])){
  2311. if(($edited =$this->EditPost($_GET['rename_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,NULL))!=NULL){
  2312. $redirect='?post='.$edited['id']; return 0;
  2313. };
  2314. }
  2315. if(isset($_POST['post_mastodon_confirm']) && isset($_POST['post_mastodon_url']) && isset($_GET['mastodon_post'])){
  2316. if(($edited =$this->EditPost(
  2317. $_GET['mastodon_post'],NULL,NULL,NULL,NULL,NULL,$_POST['post_rename_name'],false,NULL,$_POST['post_mastodon_url']))!=NULL){
  2318. $redirect='?post='.$edited['id']; return 0;
  2319. };
  2320. }
  2321. if(isset($_GET['mastodon_send_post']) && preg_match('/([0-9]{14})/u',$_GET['mastodon_send_post'],$m)){
  2322. $this->ReadImages(); $this->ReadPosts(); $post = &$this->GetPost($m[1]); $err=$this->T("未知错误");
  2323. if(isset($post)){
  2324. if($mastodon_url = $this->MastodonSendPost($post, $err)){
  2325. $this->NeedWritePosts = 1; $this->WritePosts(); // for mastodon url
  2326. echo "SUCCESS ".$mastodon_url;
  2327. }else{ echo $err; }
  2328. } exit;
  2329. }
  2330. if(isset($_GET['merge_threads'])&&$_GET['merge_threads']!=""){
  2331. if(preg_match('/([0-9]{14})\s+([0-9]{14})/u',$_GET['merge_threads'],$m)){
  2332. if(($pe = &$this->MergeThreads($m[1],$m[2]))!=$this->NULL_POST){ $redirect='?post='.$pe['id']; return 0; }
  2333. }
  2334. }
  2335. if(isset($_GET['merge_posts'])&&$_GET['merge_posts']!=""){
  2336. if(($pe = &$this->MergePosts($_GET['merge_posts']))!=$this->NULL_POST){
  2337. $redirect='?post='.$pe['id']; return 0;
  2338. }
  2339. }
  2340. if ($this->CommentEnabled && isset($_POST['comment_confirm']) && (isset($_GET['comment_to']))
  2341. && isset($_POST['comment_box']) && isset($_POST['comment_email']) && isset($_POST['comment_name'])){
  2342. $c = $_POST['comment_box'];
  2343. if(preg_match('/\[LAMDWIKIPOST/u',$c))
  2344. { $message='Can\'t use character sequence"[LAMDWIKIPOST" anywhere in the post...'; return 1; }
  2345. $comment_to = ($_GET['comment_to']!="")?$_GET['comment_to']:NULL;
  2346. if(($edited = $this->EditComment(NULL,
  2347. $_GET['comment_to'], $c, $_POST['comment_email'], $_POST['comment_name'],
  2348. isset($_POST['comment_link'])?$_POST['comment_link']:NULL,
  2349. $_SERVER['REMOTE_ADDR']))!=NULL){
  2350. $redirect='?post='.$_GET['post'];
  2351. return 0;
  2352. };
  2353. }
  2354. if(isset($_POST['gallery_edit_confirm']) && isset($_POST['gallery_edit_new_name']) && $_POST['gallery_edit_new_name']!=''){
  2355. $old_name = isset($_POST['gallery_edit_old_name'])?$_POST['gallery_edit_old_name']:"";
  2356. $new_name = $_POST['gallery_edit_new_name'];
  2357. if($old_name!=''){
  2358. $this->EditGallery($old_name, $new_name, false, true, null, null);
  2359. $redirect='?gallery='.$new_name;
  2360. }else{
  2361. $this->EditGallery(null, $new_name, false, true, null);
  2362. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2363. }
  2364. return 0;
  2365. }
  2366. if(isset($_GET['gallery_edit_delete'])&&$_GET['gallery_edit_delete']!=null){
  2367. $this->EditGallery($_GET['gallery_edit_delete'], null, true, true, null, null);
  2368. if(isset($_GET['gallery'])) $redirect='?gallery=main'; else $redirect='index.php';
  2369. return 0;
  2370. }
  2371. if(isset($_POST['gallery_move_ops'])&&isset($_POST['gallery_move_ops'])){
  2372. if(preg_match('/^(REM|ADD)\s+(\S+)\s+(.*)$/u', $_POST['gallery_move_ops'], $ma)){
  2373. $this->ReadImages();
  2374. if(preg_match_all('/(\S+)/u', $ma[3], $files, PREG_SET_ORDER)) foreach($files as $name){
  2375. $this->EditImage($name[1], $ma[2], ($ma[1]=='REM'), NULL, NULL, NULL);
  2376. }
  2377. }
  2378. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2379. return 0;
  2380. }
  2381. if(isset($_GET['gallery_set_featured'])&&isset($_GET['value'])){
  2382. $this->EditGallery($_GET['gallery_set_featured'], null, false, true, $_GET['value']!='false', null);
  2383. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2384. return 0;
  2385. }
  2386. if(isset($_GET['gallery_set_experimental'])&&isset($_GET['value'])){
  2387. $this->EditGallery($_GET['gallery_set_experimental'], null, false, true, null, $_GET['value']!='false');
  2388. if(isset($_GET['gallery'])) $redirect='?gallery='.$_GET['gallery']; else $redirect='index.php';
  2389. return 0;
  2390. }
  2391. if(isset($_GET['image_list'])&&$_GET['image_list']!=""){
  2392. $this->ReadImages();
  2393. $gallery = $_GET['image_list'];
  2394. foreach($this->Images as $im){
  2395. if($gallery=='main'){ echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; continue; }
  2396. if(isset($im['galleries']) && isset($im['galleries'][0]) && in_array($gallery,$im['galleries'])) {
  2397. echo "[".$im['name'].",".(isset($im['thumb'])?$im['thumb']:$im['name'])."]"; }
  2398. }
  2399. exit;
  2400. }
  2401. $do_image_redirect = 0;
  2402. if (isset($_POST['image_button']) && isset($_GET['pic']) &&
  2403. preg_match('/([0-9]{14,}\.(jpg|png|jpeg|gif))/u',$_GET['pic'],$ma)){
  2404. $this->ReadImages(); $pic = $ma[1]; $picext=$ma[2];
  2405. if(isset($_POST['image_ops_product_link'])){
  2406. $this->EditImage($pic, NULL, false, $_POST['image_ops_product_link'], NULL, NULL);
  2407. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2408. }
  2409. if(isset($_POST['image_edit_new_name']) && preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_edit_new_name'],$man)){
  2410. $this->EditImage($pic, NULL, false, NULL, $man[1], NULL);
  2411. $redirect=$this->GetRedirect(['pic'=>'images/'.$man[1].'.'.$picext]);
  2412. $do_image_redirect = 1;
  2413. }
  2414. if(isset($_POST['image_parent'])){ $parent="";
  2415. if(preg_match('/\s*([0-9]{14,})\s*/u',$_POST['image_parent'],$man)){ $parent = $man[1]; }
  2416. $this->EditImage($pic, NULL, false, NULL, NULL, $parent);
  2417. $redirect=$_SERVER['REQUEST_URI']; $do_image_redirect = 1;
  2418. }
  2419. $this->NeedWriteImages = 1;
  2420. if($do_image_redirect) return 0;
  2421. }
  2422. if(isset($_GET['rewrite_styles'])){
  2423. $this->WriteStyles();
  2424. $redirect='?extras=true'; return 0;
  2425. }
  2426. if(isset($_GET['regenerate_thumbnails'])){
  2427. $this->RegenerateThumbnails();
  2428. $redirect='?extras=true'; return 0;
  2429. }
  2430. if(isset($_GET['clear_all_logins'])){
  2431. $this->LoginTokens=[];
  2432. $this->WriteTokens();
  2433. }
  2434. }
  2435. return 0;
  2436. }
  2437. function PostProcessHTML($html,&$added_images=null,$do_product_info=false, &$product_info=null, &$orig_src_list=null){
  2438. if(!$this->LoggedIn){
  2439. $html = preg_replace("/(<a[^>]*href=[\'\"])(.*?)([\'\"][^>]*)>(\#.*?<\/a>)/u","",$html);
  2440. }
  2441. $html = preg_replace("/(<a[^>]*href=[\'\"])([0-9]{14})([\'\"][^>]*)>(.*?<\/a>)/u","$1?post=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2442. $html = preg_replace("/(<a[^>]*href=[\'\"])\@(.*?)([\'\"][^>]*)>(.*?<\/a>)/u","$1?category=$2$3 onclick='ShowWaitingBar()'>$4",$html);
  2443. $html = preg_replace("/(<a[^>]*href=[\'\"])((.*?:\/\/).*?)([\'\"][^>]*)(>)(.*?)(<\/a>)/u",
  2444. "$1$2$4 target='_blank'$5$6<sup>↗</sup>$7",$html);
  2445. $html = preg_replace("/<p>\s*\@.*?<\/p>/mu","",$html);
  2446. $html = preg_replace("/<p>\s*\{\s*INTERESTING\s+(.*?)\}\s*<\/p>/imu","",$html);
  2447. $html = preg_replace("/\{\s*REVERSED\s*\}/imu","",$html);
  2448. $images = []; $images_noclick = []; $images_orig_src_list = [];
  2449. $html = preg_replace_callback(
  2450. "/(<p>\s*)?(<img([^>]*)src=[\'\"])(images\/([0-9]{14,}\.(jpg|png|jpeg|gif)))([\'\"][^>]*)\/>(\s*<\/p>)?/u",
  2451. function($m) use (&$images,&$images_noclick,&$images_orig_src_list) {
  2452. $orig_src = $src = $m[5]; $keep = false; $original = false;
  2453. if (preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[3]) ||
  2454. preg_match('/alt=[\'\"].*keep_inline.*[\'\"]/u',$m[7])) { $keep=true; }
  2455. if ($keep && preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[3]) ||
  2456. preg_match('/alt=[\'\"].*original.*[\'\"]/u',$m[7])) { $original=true; }
  2457. if(($im = &$this->FindImage($m[5]))!=NULL && isset($im['thumb'])){
  2458. $src = $im['thumb']; $orig_src=$im['file'];
  2459. }if($im == NULL){ $im = &$this->NULL_IMAGE_DUMMY; }
  2460. if($this->InHereMode){
  2461. $click = "<div class='imd'>"."<a href='?here=".$im['file']."' class='original_img'>".
  2462. $m[2].$orig_src.$m[7]."></a></div>";
  2463. return $click;
  2464. }else{ $click =
  2465. "<div class='imd'><a href='?show_image={$im['name']}' target='_blank' onclick='event.preventDefault();'>".
  2466. $m[2].($original?$orig_src:$src).$m[7]." data-imgsrc='".$m[5]."'".
  2467. (isset($im['product'])?" data-product='".$im['product']."'":"").
  2468. (isset($im['parent'])?" data-parent='".$im['parent']."'":"").
  2469. ($original?" class='original_img'":"")."></a></div>";
  2470. $images_noclick[]=$m[2].$src.$m[7].">"; $images_orig_src_list[]=$orig_src;
  2471. $ret = "";
  2472. if($keep) { $ret = $click; }
  2473. else { $images[] = $click; }
  2474. if(isset($m[1])&&isset($m[8])&&$m[1]&&$m[8]) return $ret;
  2475. else return ((isset($m[1])&&$m[1]?$m[1]:"").$ret.(isset($m[8])&&$m[8]?$m[8]:""));
  2476. }
  2477. },$html,-1,$count);
  2478. $html = preg_replace('/<p>\s*<\/p>/u',"", $html); if($html==""){$html="<p>&nbsp;</p>";}
  2479. if(sizeof($images)){
  2480. if(sizeof($images)==1){$html.= $images[0]; }
  2481. else{
  2482. $html.="<div class='p_row'>";
  2483. foreach($images as $img){
  2484. $html.="<div class='p_thumb'>".$img."</div>";
  2485. }
  2486. $html.="<div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div>";
  2487. }
  2488. }
  2489. if(sizeof($images_noclick)){ $added_images = $images_noclick; }
  2490. if(sizeof($images_orig_src_list)) { $orig_src_list = $images_orig_src_list; }
  2491. if($do_product_info){
  2492. $html = preg_replace_callback("/\{PRICE\s+([^]]+?)\}/u",
  2493. function($m) use (&$product_info) { $product_info['price']=$m[1];return ""; },$html);
  2494. $html = preg_replace_callback("/\{SHORT\s+([^]]+?)\}/u",
  2495. function($m) use (&$product_info) { $product_info['short']=$m[1];return ""; },$html);
  2496. $html = preg_replace('/<p>\s*<\/p>/u',"", $html);
  2497. if (preg_match('/<h[1-5]>(.+?)<\/h/u',$html,$title)){ $product_info['title']=$title[1]; }
  2498. else { $product_info['title'] = $this->T('商品'); }
  2499. if(!isset($product_info['price'])) $product_info['price']=$this->T('未设置价格');
  2500. $html = preg_replace_callback("/\{PURCHASE\s+([^]]+?)\}/u",function($m) use (&$product_info) {
  2501. return "<a class='purchase_button' href=\"mailto:".$this->T($this->DisplayName)."<".$this->EMail.">?subject=".
  2502. $this->T('购买').' '.$product_info['title'].
  2503. "&body=".$this->T('你好!我想购买').$product_info['title'].urlencode(PHP_EOL.PHP_EOL).
  2504. $this->FullURL().urlencode(PHP_EOL.PHP_EOL)."\">".$m[1]."</a>"; },$html);
  2505. }
  2506. return $html;
  2507. }
  2508. function ConvertPost(&$post){
  2509. if(!isset($post['html'])){
  2510. $info=[];
  2511. $post['html'] = $this->TranslatePostParts($this->PostProcessHTML($this->ChoosePartsByLanguage($this->PDE->text($this->InsertReplacementSymbols($post['content'], $post)),true),
  2512. $post['images'],
  2513. isset($post['product']), $info,
  2514. $post['original_images']));
  2515. if(isset($post['product'])) $post['product']=$info;
  2516. }
  2517. }
  2518. function GetPostTitle(&$post, $h1_only=false, $add_unamed=true){
  2519. if(!isset($post['title'])){
  2520. if($h1_only){
  2521. if(preg_match('/^#\s+(.*?)$/mu',$post['content'],$m)){return $m[1];}
  2522. return NULL;
  2523. }
  2524. if(preg_match('/^#{1,6}\s+(.*?)$/mu',$post['content'],$m)){$post['title']=$m[1];}
  2525. else{ $post['title'] = $add_unamed?$this->T('未命名'):"";
  2526. if(preg_match('/(.*)$/mu',$post['content'],$m)){
  2527. $post['title'].=($add_unamed?' (':'').strip_tags($this->PDE->text($m[1])).($add_unamed?')':''); }
  2528. }
  2529. }
  2530. return $this->ChoosePartsByLanguage($post['title']);
  2531. }
  2532. function DetectPageType(){
  2533. if ($this->InExperimentalMode) $this->PageType='experimental';
  2534. else if($this->InHereMode) $this->PageType='here';
  2535. else if(isset($_GET['history'])) $this->PageType='history';
  2536. else if(isset($_GET['extras'])) $this->PageType='extras';
  2537. else if(isset($_GET['settings'])) $this->PageType='settings';
  2538. else if(isset($_GET['gallery'])) $this->PageType='gallery';
  2539. else if(isset($_GET['search'])) $this->PageType='search';
  2540. else if(isset($_GET['category'])) $this->PageType='category';
  2541. else if(isset($this->CurrentPostID)) $this->PageType = "post";
  2542. else if(isset($_GET['comments'])) $this->PageType='comments';
  2543. else $this->PageType = "main";
  2544. $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
  2545. if(!isset($_SESSION[$visited_here])){ $_SESSION[$visited_here] = []; }
  2546. $this->VisitedHere = $_SESSION[$visited_here];
  2547. }
  2548. function MakePageBegin(){ ?>
  2549. <!DOCTYPE html><html lang='zh-Hans-CN'>
  2550. <head>
  2551. <meta charset='utf-8'>
  2552. <meta content="width=device-width, initial-scale=1" name="viewport">
  2553. <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):
  2554. ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title))?></title>
  2555. <?php if($this->UseRemoteFont){ ?><style>
  2556. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
  2557. @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
  2558. </style><?php } ?>
  2559. <link href='styles/main.css' rel='stylesheet' type="text/css">
  2560. <link rel="alternate" type="application/rss+xml" title="<?=$this->T($this->Title);?>" href="?rss=<?=$this->LanguageAppendix;?>" />
  2561. <?php if(isset($this->SelfAuthPath)&&$this->SelfAuthPath!=""){ ?>
  2562. <link rel="authorization_endpoint" href="<?=$this->SelfAuthPath?>" /><?php } ?>
  2563. </head>
  2564. <div class='page'>
  2565. <?php }
  2566. function MakeHeader(&$p){
  2567. $this->MakePageBegin() ?>
  2568. <script type='text/javascript'>
  2569. function toggle_mobile_show(a){a.classList.toggle('hidden_on_mobile')}
  2570. function ShowWaitingBar(){
  2571. wait = document.querySelector("#waiting_bar");
  2572. wait.style.display='';
  2573. }
  2574. function HideWaitingBar(){
  2575. wait = document.querySelector("#waiting_bar");
  2576. wait.style.display='none';
  2577. }
  2578. <?php if(!$this->InHereMode){ ?>
  2579. function la_auto_grow(element){
  2580. s=window.scrollY;element.style.height="30px";element.style.height=(element.scrollHeight)+"px";window.scroll(0, s);
  2581. }
  2582. var scroll_l=0,scroll_c=0;in_center=1;
  2583. function ShowLeftSide(){
  2584. scroll_c = window.scrollY;
  2585. document.getElementById('div_left').classList.remove('hidden_on_mobile');
  2586. document.getElementById('div_center').classList.add('hidden_on_mobile');
  2587. window.scroll(0, scroll_l); in_center=0;
  2588. }
  2589. function ShowCenterSide(){
  2590. scroll_l = window.scrollY;
  2591. document.getElementById('div_center').classList.remove('hidden_on_mobile');
  2592. document.getElementById('div_left').classList.add('hidden_on_mobile');
  2593. window.scroll(0, scroll_c); in_center=1;
  2594. }
  2595. function ShowBackdrop(alpha=0.5){
  2596. b = document.getElementById('backdrop');
  2597. b.style="background-color:rgba(0,0,0,"+alpha+");";
  2598. b.style.animation='backdrop_fade_in 0.3s forwards';
  2599. b.style.display = 'block';
  2600. }
  2601. function HideBackdrop(){
  2602. b = document.getElementById('backdrop');
  2603. b.style.animation='backdrop_fade_out 0.3s forwards';
  2604. setTimeout(function(e1){e1.style.display='none';}, 300, b);
  2605. }
  2606. function ShowRightSide(big,elem_to_clone){
  2607. p = document.getElementById('pop_right');
  2608. if(elem_to_clone){
  2609. c = elem_to_clone.cloneNode(true);
  2610. c.id='side_bar_cloned';c.className="";c.style="";
  2611. p.querySelector('._content').appendChild(c);
  2612. }
  2613. p.classList.remove('pop_right','pop_right_big');
  2614. if(big) {p.classList.add('pop_right_big');p.style.animation='pop_slide_in_big 0.3s forwards';}
  2615. else {p.classList.add('pop_right');p.style.animation='pop_slide_in 0.3s forwards';}
  2616. p.style.display='block';
  2617. ShowBackdrop(0.5);
  2618. }
  2619. function HideRightSide(){
  2620. p = document.getElementById('pop_right');
  2621. if(side=p.querySelector('#side_bar_cloned')){
  2622. side.remove();
  2623. }
  2624. put = document.querySelector("#_uploader");
  2625. if(p.classList.contains('pop_right')){p.style.animation='pop_slide_out 0.3s forwards';}
  2626. else{p.style.animation='pop_slide_out_big 0.3s forwards';}
  2627. setTimeout(function(e1, e2){e1.style.display='none';if(e2)e2.style.display='none';}, 300, p, put);
  2628. HideBackdrop();
  2629. }
  2630. function ToggleLeftSide(){if(in_center)ShowLeftSide();else ShowCenterSide();}
  2631. function CssNumberID(id){ return "#\\3"+id.substr(0,1)+" "+id.substr(1); }
  2632. function ScrollToPost(id){
  2633. post=null;
  2634. if(!(post = document.querySelector("[data-post-id='"+id+"']"))){
  2635. if(!(post = document.querySelector(CssNumberID(id)))) return; }
  2636. post.scrollIntoView({ behavior: 'smooth', block: 'start'});
  2637. }
  2638. <?php } ?>
  2639. </script>
  2640. <header<?=$this->InHereMode?' class="exp_h_f"':''?>><div>
  2641. <?php if($this->InHereMode){
  2642. $this->MakeExpNavButtons($p);
  2643. }else{
  2644. $this->MakeNavButtons($p);
  2645. echo "<hr />";
  2646. } ?>
  2647. <?php if(isset($this->WayBack)){
  2648. $time=(isset($_COOKIE['la_wayback']) && preg_match('/[0-9]{14}/u',$_COOKIE['la_wayback']))?$_COOKIE['la_wayback']:date('YmdHis');
  2649. $year=substr($time,0,4);$month=substr($time,4,2);$day=substr($time,6,2);
  2650. $hour=substr($time,8,2);$minute=substr($time,10,2);?> <div class='text_highlight'>
  2651. &nbsp;<b><span onclick='document.getElementById("wayback_config").classList.toggle("hidden_on_mobile")'>
  2652. <div class='wayback_close' onclick='event.stopPropagation()'><a href='<?=$this->GetRedirect()?>&set_wayback=false'>
  2653. <span class='hidden_on_mobile'><?=$this->T('退出')?></span>×&nbsp;</a></div>
  2654. <?=$this->T('正以过去的日期浏览')?></b><div id='wayback_config' class='wayback_expand hidden_on_mobile'>
  2655. <select id="wayback_year" name="wayback_year" form="wayback_form"><?php for($y=$this->YearBegin;$y<=$this->YearEnd;$y++){ ?>
  2656. <option value="<?=$y?>"<?=$y==$year?" selected":""?>><?=$y?></option><?php } ?></select>
  2657. <br class='hidden_on_desktop' />
  2658. <select id="wayback_month" name="wayback_month" form="wayback_form"><?php for($y=1;$y<=12;$y++){ ?>
  2659. <option value="<?=$y?>"<?=$y==$month?" selected":""?>><?=$y?></option><?php } ?></select>
  2660. <select id="wayback_day" name="wayback_day" form="wayback_form"><?php for($y=1;$y<=31;$y++){ ?>
  2661. <option value="<?=$y?>"<?=$y==$day?" selected":""?>><?=$y?></option><?php } ?></select>
  2662. <br class='hidden_on_desktop' />
  2663. <select id="wayback_hour" name="wayback_hour" form="wayback_form"><?php for($y=0;$y<=23;$y++){ ?>
  2664. <option value="<?=$y?>"<?=$y==$hour?" selected":""?>><?=$y?></option><?php } ?></select>:
  2665. <select id="wayback_minute" name="wayback_minute" form="wayback_form"><?php for($y=0;$y<=59;$y++){ ?>
  2666. <option value="<?=$y?>"<?=$y==$minute?" selected":""?>><?=$y?></option><?php } ?></select>
  2667. <br class='hidden_on_desktop' />
  2668. <form action="<?=$this->GetRedirect()?>&set_wayback=post" method="post" style='display:none;' id='wayback_form'></form>
  2669. <input type='submit' style='font-weight:normal;border-bottom:none;' class='button clean_a' form='wayback_form'
  2670. id='wayback_see' name='wayback_see' value="<?=$this->T('查看')?> →">
  2671. </div></div><?php } ?>
  2672. </div></header>
  2673. <div id='waiting_bar' style='display:none;'></div>
  2674. <script>ShowWaitingBar();window.addEventListener('load',(event) =>{HideWaitingBar();}); </script>
  2675. <?php if(!$this->InHereMode){ ?>
  2676. <div id='post_menu' style='display:none;' class='pop_menu clean_a'>
  2677. <ul>
  2678. <li><span id='_time_hook' class='smaller'>时间</span>&nbsp;&nbsp;<a href='javascript:HidePopMenu();'>×</a></li>
  2679. <li><a id='share_copy'>⎘<?=$this->T('复制链接')?></a></li>
  2680. <hr />
  2681. <?php if($this->LoggedIn){ ?>
  2682. <li><a id='menu_history'><?=$this->T('历史')?></a>
  2683. <?php if(!isset($this->WayBack) && $this->PageType!='search'){ ?>
  2684. | <a id='menu_edit'><?=$this->T('修改')?></a><?php } ?></li>
  2685. <?php if(!isset($this->WayBack)){ ?><li>
  2686. <a id='menu_refer_copy'><?=$this->T('复制编号')?></a><?php if($this->PageType!='search'){ ?>
  2687. | <a id='menu_refer'><?=$this->T('引用')?></a><?php } ?><br class='hidden_on_desktop' />
  2688. </li>
  2689. <li><a id='menu_rename' href='javascript:ToggleRenameDetails()'><?=$this->T('改名')?></a> |
  2690. <a id='menu_mark' href='javascript:ToggleMarkDetails()'><?=$this->T('标记')?></a></li>
  2691. <li id='mark_details' style='display:none;'><b>
  2692. <a id='mark_set_clear' href='javascript:SetMark(-1);'>_</a>
  2693. <a id='mark_set_0' href='javascript:SetMark(0);'><?=$this->Markers[0]?></a>
  2694. <a id='mark_set_1' href='javascript:SetMark(1);'><?=$this->Markers[1]?></a>
  2695. <a id='mark_set_2' href='javascript:SetMark(2);'><?=$this->Markers[2]?></a>
  2696. <a id='mark_set_3' href='javascript:SetMark(3);'><?=$this->Markers[3]?></a>
  2697. <a id='mark_set_4' href='javascript:SetMark(4);'><?=$this->Markers[4]?></a>
  2698. <a id='mark_set_5' href='javascript:SetMark(5);'><?=$this->Markers[5]?></a>
  2699. <a id='mark_set_6' href='javascript:SetMark(6);'><?=$this->Markers[6]?></a>
  2700. <a id='mark_set_7' href='javascript:SetMark(7);'><?=$this->Markers[7]?></a>
  2701. </b></li>
  2702. <li id='rename_details' style='display:none;text-align:left;' class='smaller'>
  2703. <form action="" method="post" style='display:none;' id='post_rename_form'></form>
  2704. <input type='text' id='post_rename_name' name='post_rename_name' form="post_rename_form" style='width:9em;'>
  2705. <input class='button' type='submit' form='post_rename_form'
  2706. name='post_rename_confirm' id='post_rename_confirm' value='<?=$this->T('确认')?>'>
  2707. </li><hr /> <?php if(isset($this->MastodonToken)){ ?>
  2708. <li><a id='menu_mastodon_view' class='button' style='display:none;' target='_blank'><?=$this->T('转到')?></a>
  2709. <a id='menu_mastodon' href='javascript:ToggleMastodonDetails()'><?=$this->T('长毛象')?></a></li>
  2710. <li id='mastodon_details' style='display:none;text-align:left;' class='smaller'>
  2711. <a id='menu_mastodon_send' class='button' target='_blank'><?=$this->T('发送')?></a>
  2712. <form action="" method="post" style='display:none;' id='post_mastodon_form'></form>
  2713. <input type='text' id='post_mastodon_url' name='post_mastodon_url' form="post_mastodon_form" style='width:9em;'>
  2714. <input class='button' type='submit' form='post_mastodon_form'
  2715. name='post_mastodon_confirm' id='post_mastodon_confirm' value='<?=$this->T('修改')?>'></li> <?php } ?>
  2716. <hr /><li><a id='menu_delete' class='smaller'><?=$this->T('删除')?></a></li><?php } ?>
  2717. <?php }else{ ?>
  2718. <li><a id='menu_history'><?=$this->T('历史')?></a></li>
  2719. <?php } ?>
  2720. </ul>
  2721. </div>
  2722. <div id='backdrop' style='display:none;' class='backdrop' onclick='HideRightSide()'
  2723. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"></div>
  2724. <div id='pop_right' class='pop_right' onclick='event.stopPropagation()'>
  2725. <div style='text-align:right;position:sticky;top:0;'><a class='clean_a' href='javascript:HideRightSide();'>
  2726. <?=$this->T('关闭')?>→</a></div>
  2727. <?php if($this->LoggedIn && in_array($this->PageType,['main','post'])){ ?>
  2728. <div id='_uploader' style='display:none;'>
  2729. <?php $this->MakeUploader(true); ?>
  2730. <p>&nbsp;</p>
  2731. <?php $this->MakeSideGalleryCode(); ?>
  2732. </div>
  2733. <?php } ?>
  2734. <div class='_content'></div>
  2735. </div>
  2736. <?php } ?>
  2737. <?php
  2738. }
  2739. function ChoosePartsByLanguage($content,$use_p=false){
  2740. $split = preg_split('/'.($use_p?'<p>\s*':'').'((en|zh|any)\|(en|zh|any))'.($use_p?'<\/p>\s*':'').'/u',$content, -1,
  2741. PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  2742. $lang = $this->LanguageAppendix; $last_lang='0'; $reduced="";
  2743. if($split) for($i=0;$i<sizeof($split);$i+=4){
  2744. $this_lang = '0'; if($i+2>=sizeof($split)){ $this_lang = $last_lang; }else{ $this_lang = $split[$i+2]; }
  2745. if($this_lang==$lang || $this_lang=='any'){ $reduced.=$split[$i]; }
  2746. if($i+3<sizeof($split)){ $last_lang = $split[$i+3]; }
  2747. }
  2748. if(!$reduced)$reduced = $content;
  2749. return $reduced;
  2750. }
  2751. function TranslatePostParts($html){
  2752. $html = preg_replace_callback('/>([^><]+?)</u', function($ma){
  2753. $reduced = $this->ChoosePartsByLanguage($ma[1], false);
  2754. return ">".$this->T($reduced)."<";
  2755. }, $html);
  2756. return $html;
  2757. }
  2758. function MakeNavButtons(&$p){ $interesting=$this->IsInterestingPost($p); ?>
  2759. <a href='index.php' class='clean_a hidden_on_mobile' onclick='ShowWaitingBar()'><b><?=$this->T($this->Title)?></b></a>
  2760. <b><a class='hidden_on_desktop'
  2761. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><?=$this->T($this->ShortTitle)?>...</a></b>
  2762. <div class='header_nav'>
  2763. <?php if($this->PageType=='post'){ ?>
  2764. <div class='toc_button hidden_on_print'>
  2765. <?php if(!$interesting && isset($p) && isset($p['refs']) && isset($p['refs'][0])){ ?>
  2766. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2767. <?=$this->T('链接')?>(<?=sizeof($p['refs'])?>)</a></span>
  2768. <?php } if(!$interesting){ ?>
  2769. <span class='hidden_on_wide hidden_on_print'>
  2770. <a id='button_toc' href='javascript:ShowRightSide(true,document.querySelector("#div_right"));'>
  2771. <?=$this->T('目录')?></a></span><?php } ?></div>
  2772. <?php }else if($this->PageType=='history' && isset($_GET['version'])){ ?>
  2773. <div style='float:right;' class='hidden_on_print'>
  2774. <span class='hidden_on_desktop'><a id='button_ref' href='javascript:ToggleLeftSide();'>
  2775. <?=$this->T('历史')?></a></span></div>
  2776. <?php } ?>
  2777. <ul class='hidden_on_mobile hidden_on_print' id='mobile_nav' style='text-align:center;'>
  2778. <li class='hidden_on_mobile'><a href='?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
  2779. <li class='hidden_on_desktop_force block_on_mobile'>
  2780. <?php if($this->PageType!='main'){ ?>
  2781. <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a> |
  2782. <a href='index.php?part=hot' onclick='ShowWaitingBar()'><?=$this->T('热门')?></a> |
  2783. <?php } else { ?>
  2784. <li class='hidden_on_desktop_force block_on_mobile'>
  2785. <a href='javascript:ShowCenterSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('最近')?></a> |
  2786. <a href='javascript:ShowLeftSide();toggle_mobile_show(document.getElementById("mobile_nav"));'><?=$this->T('热门')?></a> |
  2787. <?php } ?>
  2788. <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a>
  2789. <?php if($this->LoggedIn){ ?>
  2790. | <span class='gray invert_a'><a href='index.php?comments=all'>@</a></span><?php } ?></li>
  2791. <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
  2792. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2793. } ?>
  2794. <li><a href='?search=' onclick='ShowWaitingBar()'><?=$this->T('搜索')?></a></li>
  2795. <?php if($this->LanguageAppendix=='zh'){ ?>
  2796. <li class='invert_a smaller'>
  2797. <a href='<?=$this->GetRedirect().'&set_language=en'?>' onclick='ShowWaitingBar()'><b>汉语</b>/English</a></li>
  2798. <?php }else { ?>
  2799. <li class='smaller'>
  2800. <a class='invert_a' href='<?=$this->GetRedirect().'&set_language=zh'?>' onclick='ShowWaitingBar()'>
  2801. 汉语/<b>English</b></a>
  2802. <br class='hidden_on_desktop' />
  2803. <a id='translate_button' target='_blank'>&nbsp;[Google Translate]&nbsp;</a></li>
  2804. <?php } ?>
  2805. </ul>
  2806. </div>
  2807. <?php
  2808. }
  2809. function MakeExpNavButtons(&$p){ ?>
  2810. <a href='index.php' class='hidden_on_mobile'>
  2811. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b></a>
  2812. <a class='hidden_on_desktop'
  2813. href='javascript:toggle_mobile_show(document.getElementById("mobile_nav"))'><b>
  2814. <?=$this->InExperimentalMode?$this->T($this->ExpShortTitle):$this->T($this->HereShortTitle)?>...</b></a>
  2815. <a <?=$this->HereNumber==1?"class='gray'":("href=".$this->HereLinkFromNumber($this->HereNumber-1))?>>←</a>
  2816. <span><?=$this->HereNumber.'/'.sizeof($this->VisitedHere);?></span>
  2817. <span class='round_btn'><a href='<?=$this->HereLinkFromNumber($this->HereNumber+1);?>'>→</a> <a href='?random_here=1'><?=$this->T("随机")?></a></span>
  2818. <b><?=$this->T($this->ChoosePartsByLanguage($this->HereDisplayTitle));?></b>
  2819. <?=isset($this->HereMainImage)?("<a class='invert_a' href='?here=images/".$this->HereMainImage['name']."'>".$this->T("看全图")."</a>"):"";?>
  2820. <ul class='hidden_on_mobile gray invert_a' id='mobile_nav' style='text-align:center;'>
  2821. <li class='hidden_on_desktop block_on_mobile'><a href='index.php'><?=$this->T('索引')?></a></li>
  2822. <?php if($this->InExperimentalMode && isset($this->ExpNavigation) && ($p = &$this->GetPost($this->ExpNavigation))!=NULL){
  2823. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2824. }else if($this->InHereMode && isset($this->HereNavigation) && ($p = &$this->GetPost($this->HereNavigation))!=NULL){
  2825. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST);
  2826. } ?>
  2827. <?php if($this->LanguageAppendix=='zh'){ ?>
  2828. <li class='smaller'><a href='<?=$this->GetRedirect().'&set_language=en'?>'><b>汉语</b>/English</a></li>
  2829. <?php }else { ?>
  2830. <li class='smaller'><a href='<?=$this->GetRedirect().'&set_language=zh'?>'>汉语/<b>English</b></a></li>
  2831. <li class='smaller'><a id='translate_button' target='_blank'>&nbsp;Google Translate&nbsp;</a></li>
  2832. <?php } ?>
  2833. </ul>
  2834. <?php
  2835. }
  2836. function GenerateLinkedPosts($ht){
  2837. $ht = preg_replace_callback('/<p>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>(.*)<\/a>[\s]*<\/p>/u',
  2838. function($m){
  2839. $rp = &$this->GetPost($m[1], false, true);
  2840. $s="<div class='smaller block post ref_compact gray'>".
  2841. "<a href='?post=".$m[1]."' class='post_access invert_a smaller' onclick='ShowWaitingBar()'>→</a>".
  2842. "<div class='post_ref'><div class='smaller'>".$m[2]."</div>".
  2843. (($rp!==NULL && $this->CanShowPost($rp))?
  2844. $this->GenerateSinglePost($rp,false,false,false,true,$this->NULL_POST,true):$this->T("未找到该引用。")).
  2845. "</div></div>";
  2846. return $s;
  2847. },
  2848. $ht
  2849. );
  2850. $ht = preg_replace_callback('/<li>[\s]*<a[^>]*href=[\'\"]\?post=([0-9]{14})[\'\"][^>]*>PRODUCT\s+(.*)<\/a>[\s]*<\/li>/u',
  2851. function($m){
  2852. $rp = &$this->GetPost($m[1], false, true);
  2853. $s="<div class='product_ref block post ref_compact'><a href='?post=".$m[1]."' class='clean_a' onclick='ShowWaitingBar()'>".
  2854. (($rp!==NULL && $this->CanShowPost($rp))?
  2855. $this->GenerateSinglePost($rp,true,false,false,true,$this->NULL_POST,true):$this->T("未找到该引用。")).
  2856. "</a></div>";
  2857. return $s;
  2858. },
  2859. $ht
  2860. );
  2861. return $ht;
  2862. }
  2863. function ExtractBigTables($html, &$table_out){
  2864. $table = NULL;
  2865. $new_html = preg_replace_callback('/<p>\s*\{big_table\}\s*<\/p>\s*(<table>[\s\S]*?<\/table>)/u', function ($m) use (&$table){
  2866. $table = $m[1];
  2867. return "";
  2868. }, $html);
  2869. $table_out = $table;
  2870. return $new_html;
  2871. }
  2872. function GenerateSinglePost(&$post, $strip_tags, $generate_anchor=false, $generate_refs=false,
  2873. $generate_thumbs=false, &$table_out, $hide_long = false){
  2874. $this->ConvertPost($post);
  2875. if($generate_anchor){ $this->CreatePostAnchor($post); }
  2876. $ht = $post['html'];
  2877. if(isset($post['mark_value']) && $post['mark_value']==5 && ($generate_thumbs || !$generate_anchor)){
  2878. $ht="<div class='product_thumb'>".$post['images'][0]."</div>".
  2879. "<p class='bold'>".$post['product']['title']."</p>".
  2880. (isset($post['product']['short'])?("<p class='smaller gray'>".$post['product']['short']."</p>"):"").
  2881. "<p class='smaller bold'>".$post['product']['price']."</p>";
  2882. return $ht;
  2883. }
  2884. if($hide_long){
  2885. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>[\s\S]*/u',"<p class='smaller bold'>[".$this->T("阅读更多")."]</p>", $ht);
  2886. }else{
  2887. $ht = preg_replace('/<p>\s*\{read_more\}\s*<\/p>/u',"", $ht);
  2888. }
  2889. if ($strip_tags){
  2890. $ht = strip_tags($ht,'<b><i><h1><h2><h3><h4><p><blockquote><span>');
  2891. $ht = preg_replace('/<p>\s*<\/p>/u',"", $ht);
  2892. $ht = "<div class='post_ref_main'>".$ht."</div>";
  2893. }
  2894. else{
  2895. if($generate_refs) $ht = $this->GenerateLinkedPosts($ht);
  2896. if($table_out!=$this->NULL_POST){
  2897. $table = NULL; $ht = $this->ExtractBigTables($ht,$table);
  2898. $table_out = $table;
  2899. }else{
  2900. $ht = preg_replace('/<p>\s*\{big_table\}\s*<\/p>/u','',$ht);
  2901. }
  2902. }
  2903. if ($strip_tags && $generate_thumbs && isset($post['images']) && isset($post['images'][0])){
  2904. $ht.="<div class='post_ref_images'><ul class='side_thumb ref_thumb'>";
  2905. foreach($post['images'] as $im){
  2906. $ht.="<li class='file_thumb'>".$im."</li>";
  2907. }
  2908. $ht.="</ul></div>";
  2909. }
  2910. return $ht;
  2911. }
  2912. function MakeSinglePostExp(&$post){
  2913. $big_table = ""; ?>
  2914. <li class='post post_dummy'>
  2915. <?=$this->GenerateSinglePost($post, false, false, true, false, $big_table, false); ?>
  2916. </li>
  2917. <?php if($big_table!=$this->NULL_POST) echo "</ul></li><div class='table_top'>".$big_table.'</div>';?>
  2918. <?php
  2919. }
  2920. function MakeSinglePost(&$post, $show_link=false, $side=false, $extra_class_string=NULL,
  2921. $strip_tags=false, $show_thread_link=false, $show_reply_count=false, $generate_anchor=false,
  2922. $generate_thumb = false, $is_top = false, $force_hide_long=false){
  2923. $is_deleted = (isset($post['mark_delete'])&&$post['mark_delete']);
  2924. $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
  2925. $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
  2926. $big_table = ($show_thread_link)?$this->NULL_POST:"";
  2927. $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
  2928. $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
  2929. ?>
  2930. <?=$title?"<li class='print_title'><h1>".$title."</h1></li>":""?>
  2931. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?><?=$side?" post_box":""?>'
  2932. <?=(!$side)?"data-post-id='".$post['id']."'":""?> <?=$is_deleted?"data-mark-delete='true'":""?>
  2933. <?=(!$side&&isset($post['mastodon_url']))?"data-mastodon_url='".$post['mastodon_url']."'":""?> >
  2934. <?php if($mark_value>=0 && !$show_link && $mark_value!='P'){?>
  2935. <div class='smaller <?=$is_deleted?"gray":""?>'><?=$mark_value?> <?=$this->T('标记')?></div>
  2936. <?php } ?>
  2937. <?php if($is_top){?>
  2938. <div class='top_post_hint'><?=$this->T('置顶帖子')?><hr /></div>
  2939. <?php } ?>
  2940. <?php if(!$side && $show_link){ ?>
  2941. <a href='?post=<?=$post['id']?>' onclick='ShowWaitingBar()'>
  2942. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  2943. <?=isset($post['mark_value'])?$this->Markers[$post['mark_value']]:($ref_count?"":"→")?>
  2944. </div>
  2945. <?php if($ref_count){ ?>
  2946. <div class='post_access ref_count'><?=$ref_count?></div>
  2947. <?php } ?>
  2948. </a>
  2949. <?php } ?>
  2950. <?=$side?"<a href='?post={$post['id']}' onclick='ShowWaitingBar()'>":""?>
  2951. <div class='<?=$side?"":($show_link?'post_width':'post_width_big')?><?=$is_deleted?" deleted_post":""?>'>
  2952. <?php if(!$side && !$strip_tags){?>
  2953. <div class='post_menu_button _menu_hook' >+</div>
  2954. <?php } if($is_product&&!$generate_anchor){
  2955. echo "<p class='smaller gray'>".$this->T('商品')."</p>";
  2956. echo "<div class='product_ref clean_a'><a href='?post={$post['id']}'>";} ?>
  2957. <?=$this->GenerateSinglePost($post, $strip_tags, $generate_anchor, true,
  2958. $generate_thumb,$big_table,($show_thread_link||$side||$force_hide_long)); ?>
  2959. <?php if($is_product&&!$generate_anchor){echo "</a></div>";} ?>
  2960. </div>
  2961. <?=$side?"</a>":""?> <?php
  2962. if(!$show_thread_link && $big_table!=$this->NULL_POST && !$side){
  2963. echo "</ul></li><div class='table_top'>".$big_table.'</div>';
  2964. ?><ul class='print_column'>
  2965. <li class='post<?=isset($extra_class_string)?' '.$extra_class_string:''?>' <?=$is_deleted?"data-mark-delete='true'":""?>>
  2966. <?php
  2967. }
  2968. if($show_thread_link && isset($post['tid']) && $this->CanShowPost($post['tid']['first']) &&
  2969. $post['tid']['first']['id']!=$post['id']){ ?>
  2970. <div class='gray smaller block opt_compact post'>
  2971. <a href='?post=<?=$post['tid']['first']['id']?>' onclick='ShowWaitingBar()'>
  2972. <div class='post_access invert_a hover_dark smaller'><?=isset($post['tid']['first']['mark_value'])?
  2973. $this->Markers[$post['tid']['first']['mark_value']]:"→"?></div></a>
  2974. <div class='post_width'><div class='smaller'><?=$this->T('回复给主题帖:')?></div>
  2975. <?=$this->GenerateSinglePost($post['tid']['first'], false, false, false, true,$this->NULL_POST,true);?>
  2976. </div>
  2977. </div>
  2978. <?php }
  2979. if($show_reply_count && isset($post['tid'])){ ?>
  2980. <a class='smaller block invert_a' href='?post=<?=$post['tid']['last']['id']?>'><?=$post['tid']['count']?>
  2981. <?=$this->T('个回复')?></a>
  2982. <?php }
  2983. ?>
  2984. </li>
  2985. <?php
  2986. }
  2987. function MakePostingFields($reply_to=NULL, $show_hint=false){
  2988. if(isset($this->WayBack)){ ?>
  2989. <span class='gray'><i><?=$this->T('以过去日期浏览时不能发帖。')?></i></span>
  2990. <?php return; } ?>
  2991. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='post_form'></form>
  2992. <div class='smaller'><div style='display:<?=$show_hint?"block":"none"?>;'>
  2993. <span id='post_hint_text'><?=$this->T('继续补充该话题:')?></span></div>
  2994. <div id='post_hint_modify' style='display:none;'>
  2995. <input type="checkbox" name="post_record_edit" value="1" form='post_form' checked> <?=$this->T('新增历史记录');?></div></div>
  2996. <textarea id="post_content" name="post_content" rows="4" form='post_form'
  2997. onfocus="if (value =='<?=$this->T('有什么想说的')?>'){value ='';}la_auto_grow(this);"
  2998. onblur="if (value ==''){value='<?=$this->T('有什么想说的')?>';la_auto_grow(this);}"
  2999. oninput="la_auto_grow(this);" onload="la_auto_grow(this);"><?=$this->T('有什么想说的')?></textarea>
  3000. <input class='button' form="post_form" type="submit" name='post_button' value=<?=$this->T('发送')?>
  3001. onclick='ShowWaitingBar();' />
  3002. | <a class='gray smaller pointer' onclick='ShowSideUploader();'><?=$this->T('图片')?></a>
  3003. <div style='float:right;'>
  3004. <a class='gray smaller pointer' onclick='t=document.querySelector("#post_content");t.value="";la_auto_grow(t);'>
  3005. <?=$this->T('清空')?></a>
  3006. <a class='gray smaller pointer' style='display:none;' id='post_reply_restore' href='javascript:RestoreReply()'></a>
  3007. </div>
  3008. <input style='display:none;' type=input form="post_form" id='post_edit_target' name='post_edit_target' />
  3009. <script> la_auto_grow(document.getElementById("post_content"));</script>
  3010. <?php if($reply_to){ ?>
  3011. <input style='display:none;' type=input form="post_form" id='post_reply_to' name='post_reply_to' value='<?=$reply_to?>' />
  3012. <?php } ?>
  3013. <?php
  3014. }
  3015. function MakeCommentPosts(){
  3016. if(!$this->LoggedIn) return; ?>
  3017. <h2><?=$this->T('评论')?></h2><div class='spacer'></div>
  3018. <?php if(!$this->CommentEnabled){
  3019. echo "<p><span class='text_highlight'>&nbsp;".$this->T("已关闭评论")."&nbsp;</span></p><br />"; } ?>
  3020. <div class='comment'><ul>
  3021. <?php $i=0;
  3022. foreach(array_reverse($this->Posts) as $p){
  3023. if(!isset($p['comment_to'])) continue;
  3024. if($i < $this->CommentsPerPage * $this->CurrentOffset) {$i++; continue;}
  3025. $ht = $this->GenerateSinglePost($p, false, false, false, false, $t, false);
  3026. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3027. $post_to = $this->GetPost($p['comment_to']); $post_title = $this->GetPostTitle($post_to);
  3028. if(!$post_to) $post_title = "?";
  3029. $mail = "<span class='gray hidden_on_print'>&nbsp;".
  3030. "<a href='mailto:".$p['email']."'>@</a>&nbsp;".
  3031. (isset($p['ip'])?$p['ip']:"?")."&nbsp;<br class='hidden_on_desktop'/>".
  3032. "<a href='index.php?post=".$p['comment_to']."'>(".$post_title.")</a></span>";
  3033. echo "<li><p><b>".$name.":</b>".$mail."<br /></p>".$ht."</li>";
  3034. $i++;
  3035. }
  3036. ?>
  3037. </ul><br /></div>
  3038. <?php
  3039. }
  3040. function MakeRecentPosts($search_term=NULL, $category=NULL){?>
  3041. <div class='center' id='div_center'>
  3042. <h2><?=isset($search_term)?$this->T('搜索'):
  3043. (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
  3044. ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
  3045. " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
  3046. ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2>
  3047. <?php if(isset($search_term)){ ?>
  3048. <form action="index.php" method="post" style='display:none;' id='search_form'></form>
  3049. <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
  3050. <input class='button' form="search_form" type="submit" name='search_button' value=<?=$this->T('搜索')?>
  3051. <?php }else if(isset($category)){ ?>
  3052. <div></div>
  3053. <?php }else if($this->LoggedIn){ ?>
  3054. <div class='post_box_top _input_bundle'>
  3055. <?php $this->MakePostingFields(NULL,false); ?>
  3056. </div>
  3057. <?php } ?>
  3058. <ul class='print_column list'>
  3059. <?php
  3060. if(!isset($search_term) && !isset($category) &&
  3061. (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
  3062. $this->CanShowPost($p)){
  3063. $this->MakeSinglePost($p, true, false, false, false, true, false, false, false, true, false);
  3064. }
  3065. $i = 0;
  3066. if(isset($this->UsePosts[0])) foreach(array_reverse($this->UsePosts) as &$p){
  3067. if(!$this->CanShowPost($p) || $this->SkipProduct($p)) continue;
  3068. if(isset($p['tid'])){ /* Should always be set. */
  3069. $th = &$p['tid']; if($p['tid']['count']==0) continue;
  3070. if(!isset($search_term)) { $p = &$th['last']; }
  3071. }
  3072. if(isset($search_term)){
  3073. if ($search_term=='' || !preg_match("/".preg_quote($search_term)."/iu", $p['content'])) continue;
  3074. }else if(isset($category)){
  3075. $cat = isset($p['tid'])?(isset($p['tid']['categories'])?($p['tid']['categories']):[]):
  3076. (isset($p['categories'])?($p['categories']):[]);
  3077. if ($category=='none') { if($cat!=[]) continue; }
  3078. else{ if ($category=='' || !in_array($category, $cat)) continue; }
  3079. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3080. }else{
  3081. if(in_array($p['id'],
  3082. [$this->SpecialPinned,$this->SpecialFooter,$this->SpecialFooter2,$this->SpecialNavigation])) continue;
  3083. if(isset($p['tid'])){ if(isset($p['tid']['displayed'])) continue; $p['tid']['displayed'] = True; }
  3084. }
  3085. if($i < $this->PostsPerPage * $this->CurrentOffset) {$i++; continue;}
  3086. $this->MakeSinglePost($p, true, false, NULL, false, !isset($search_term), false, false, false, false, isset($search_term));
  3087. $i++;
  3088. if($i >= $this->PostsPerPage * (1+$this->CurrentOffset)) {break;}
  3089. }?>
  3090. </ul>
  3091. <div class='page_selector clean_a'>
  3092. <hr />
  3093. <a <?=$this->CurrentOffset>0?("href='index.php?offset=".($this->CurrentOffset-1).
  3094. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))."'"):""?>
  3095. <?=$this->CurrentOffset==0?"class='gray'":""?>><?=$this->T('上一页')?> ←</a>
  3096. <?=$this->CurrentOffset+1?>
  3097. <a href='index.php?offset=<?=($this->CurrentOffset+1).
  3098. (isset($search_term)?"&search=".$search_term:(isset($category)?"&category=".$category:""))?>'>
  3099. → <?=$this->T('下一页')?></a>
  3100. </div>
  3101. </div>
  3102. <?php
  3103. }
  3104. function MakeHotPosts($placeholder_only=false){?>
  3105. <div class='left hidden_on_mobile' id='div_left'>
  3106. <?php if ($placeholder_only){ ?>&nbsp;
  3107. <?php }else{ ?>
  3108. <h2><?=$this->T('热门')?></h2>
  3109. <ul>
  3110. <?php
  3111. $i=0;
  3112. foreach($this->Threads as &$th){
  3113. if(!isset($th['first']) || $th['count']==0){ continue; }
  3114. if(!$this->CanShowPost($th['first'])) continue;
  3115. if($i>=$this->HotPostCount) break;
  3116. $this->MakeSinglePost($th['first'], false, true, "post_preview", true, false, true, false, true, false, false);
  3117. $i++;
  3118. } ?>
  3119. </ul>
  3120. <?php } ?>
  3121. </div>
  3122. <?php
  3123. }
  3124. function MakeLinkedPosts(&$p){
  3125. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3126. <div class='left hidden_on_mobile' id='div_left'>
  3127. <h2<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h2>
  3128. <?php
  3129. if($has_ref){ ?>
  3130. <span class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></span>
  3131. <ul><?php $count_product=0;
  3132. foreach(array_reverse($p['refs']) as &$pr){
  3133. $po = $this->GetPost($pr); if(isset($post['mark_value']) && $po['mark_value']==5){ $count_product++; continue; }
  3134. if(!$this->CanShowPost($po)){ continue; }
  3135. $this->MakeSinglePost($po, false, true, "post_preview", true, false, false, false, true, false, false);
  3136. }
  3137. ?></ul>
  3138. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3139. }else{ ?>
  3140. <span class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></span>
  3141. <?php } ?>
  3142. </div>
  3143. <?php
  3144. }
  3145. function MakeLinkedPostsExp(&$p){
  3146. $has_ref = isset($p['refs'])&&isset($p['refs'][0]); ?>
  3147. <div class='center_exp post_dummy smaller'>
  3148. <hr />
  3149. <h3<?=$has_ref?"":" class='gray'"?>><?=$this->T('链接')?></h3>
  3150. <?php
  3151. if($has_ref){ ?>
  3152. <div class='smaller'><?=sizeof($p['refs'])?> <?=$this->T('个引用:')?></div>
  3153. <ul><?php $count_product=0;
  3154. foreach(array_reverse($p['refs']) as &$pr){
  3155. echo "<li class='post_dummy'><a href='?post=".$pr."'>".$this->T($this->GetPostTitle($this->GetPost($pr),false)).
  3156. "</a></li>";
  3157. }
  3158. ?></ul>
  3159. <?php if($count_product){ ?> <span class='smaller'><?=$this->T('和').' '.$count_product.' '.$this->T('个商品')?></span> <?php }
  3160. }else{ ?>
  3161. <div class='gray smaller'><?=$this->T('没有帖子链接到这里。')?></div>
  3162. <?php } ?>
  3163. <div style='margin-bottom:4rem;'>&nbsp;</div>
  3164. </div>
  3165. <?php
  3166. }
  3167. function MakePostHistoryList(&$ah, &$post,$version=NULL, $show_latest=true){
  3168. $latest_ver=isset($post['version'])?$post['version']:$post['id'];
  3169. $can_show=1; if(isset($this->WayBack) && $latest_ver>$this->WayBack) $can_show=0;
  3170. $title = NULL; if(!isset($ah) || ($show_latest && $can_show)) { $title=$this->T($this->GetPostTitle($post, false)); }
  3171. else{ $ver = &$ah['list'][sizeof($ah['list'])-1]; $title= $this->GetPostTitle($ver); }
  3172. if(!isset($title)) $title=$this->T('未命名');
  3173. if(!isset($ah)){ ?>
  3174. <h2><?=$this->T('没有历史记录')?></h2>
  3175. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$post['id']?>'><?=$title?></a></span><br />
  3176. <?php }else{ ?>
  3177. <h2><?=$this->T('历史记录')?></h2>
  3178. <span class='omittable_title smaller'><?=$this->T('帖子')?> <a href='?post=<?=$ah['id']?>'><?=$title?></a></span><br />
  3179. <div class='list'><ul>
  3180. <?php if($show_latest && $can_show){ $post['history_displayed']=1; ?>
  3181. <li class='<?=isset($version)&&$version==$latest_ver?" post_current_row bold":""?>' style='list-style:"";'>
  3182. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$latest_ver?>'><?=$this->ReadableTime($latest_ver)?></a>
  3183. <span class='smaller gray'><?=$this->T('长度').' '.strlen($post['content'])?></span>
  3184. <?php if(isset($post['merged_from'][0])){ ?><ul><?php foreach($post['merged_from'] as $from){
  3185. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3186. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3187. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3188. <?=$this->GetPostTitle($ver);?></a>
  3189. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3190. <?php } ?></ul><?php } ?>
  3191. <?php if(isset($post['merged_thread'][0][0])){ $pm=$post['merged_thread'][0][0];
  3192. $mah = &$this->GetArchiveHandle($pm);
  3193. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3194. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3195. <span class='smaller gray'><?=sizeof($post['merged_thread'][0]);?> <?=$this->T('个帖子')?></span></li></ul>
  3196. <?php } ?>
  3197. </li><?php } ?>
  3198. <?php if(isset($ah['list'][0])) foreach(array_reverse($ah['list']) as &$ver){
  3199. if(isset($this->WayBack) && $ver['version']>$this->WayBack) continue;
  3200. if(isset($ver['history_displayed']) && $ver['history_displayed']) continue; ?>
  3201. <li<?=isset($version)&&$version==$ver['version']?" class='post_current_row bold'":""?>>
  3202. <a href='?post=<?=$this->CurrentPostID?>&history=1&version=<?=$ver['version']?>'><?=$this->ReadableTime($ver['version'])?></a>
  3203. <span class='smaller gray'> <?=$this->T('长度').' '.strlen($ver['content'])?></span>
  3204. <?php if(isset($ver['merged_thread'][0][0])){ $pm=$ver['merged_thread'][0][0];
  3205. $mah = &$this->GetArchiveHandle($pm); $mver = &$this->GetPost($pm);
  3206. if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3207. <ul><li><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver);?></a> <?=$this->T('并入这里')?>
  3208. <span class='smaller gray'> <?=sizeof($ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></li></ul>
  3209. <?php } if(isset($ver['merged_from'][0])){ ?><ul><?php foreach($ver['merged_from'] as $from){
  3210. $fromah = &$this->GetArchiveHandle($from); if(!isset($fromah)) continue;
  3211. $ver = &$fromah['list'][sizeof($fromah['list'])-1];?>
  3212. <li><a href='?post=<?=$ver['id']?>&history=1'>
  3213. <?=$this->GetPostTitle($ver);?></a>
  3214. <span class='smaller gray'><?=$this->T('长度').' '.strlen($ver['content'])?></span></li>
  3215. <?php } ?></ul></li><?php } ?>
  3216. <?php } ?></ul></div>
  3217. <?php } ?>
  3218. <?php
  3219. }
  3220. function MakePostDiff(&$this_ver, &$last_ver){
  3221. if(!isset($this_ver)){ ?>
  3222. <h2 class='gray'><?=$this->T('版本不存在')?></h2>
  3223. <?php }else{ ?>
  3224. <h2><?=$this->T('差异')?></h2>
  3225. <?php if(isset($this_ver['merged_thread']) && isset($this_ver['merged_thread'][0][0])){
  3226. $pm=$this_ver['merged_thread'][0][0]; $mah = &$this->GetArchiveHandle($pm);
  3227. $mver = &$this->GetPost($pm); if(!isset($mver) && isset($mah)) $mver = &$mah['list'][sizeof($mah['list'])-1]; ?>
  3228. <p><?=$this->T('话题')?> <a href='?post=<?=$mver['id']?>&history=1'><?=$this->GetPostTitle($mver)?></a> <?=$this->T('并入这里')?>
  3229. <br /><span class='smaller gray'> <?=sizeof($this_ver['merged_thread'][0]);?> <?=$this->T('个帖子')?> </span></p>
  3230. <?php }else{ ?>
  3231. <table class='diff_table'><thead>
  3232. <tr><td><?php if(!isset($last_ver)){ ?><?=$this->T('没有更旧的版本')?><?php }else{ ?>
  3233. <?=$this->T('上一个版本')?><br /><?=$this->ReadableTime($last_ver['version'])?><?php } ?></td>
  3234. <td class='text_highlight bold'><?=$this->T('选择的版本')?><br /><?=$this->ReadableTime($this_ver['version'])?></td></tr>
  3235. </thead><tbody>
  3236. <tr><td><pre><?=isset($last_ver)?$last_ver['content']:""?></pre></td><td><pre><?=$this_ver['content']?></pre></td></tr>
  3237. </tbody>
  3238. </table>
  3239. <?php } ?>
  3240. <br /><a class='smaller' href='?post=<?=$this_ver['id']?>&set_wayback=<?=isset($this_ver['version'])?$this_ver['version']:$this_ver['id']?>'><?=$this->T('前往该版本时间')?> ←</a>
  3241. <?php } ?>
  3242. <?php
  3243. }
  3244. function MakePostHistory(&$post, $version=NULL){
  3245. $ah = &$this->GetArchiveHandle($this->CurrentPostID);
  3246. $p = &$post; if(!isset($post)){ $p=&$ah['list'][0]; }
  3247. $show_latest = isset($ah)?(!isset($ah['list'][sizeof($ah['list'])-1]['merged_into'])):true;
  3248. ?>
  3249. <div class='left hidden_on_mobile history' id='div_left'>
  3250. <?php if (isset($version)){
  3251. $this->MakePostHistoryList($ah, $p, $version, $show_latest);
  3252. }else{ echo "&nbsp;"; } ?>
  3253. </div>
  3254. <div class='center history' id='div_center'>
  3255. <?php if (!isset($version)){
  3256. $this->MakePostHistoryList($ah, $p, NULL, $show_latest);
  3257. }else{
  3258. $this_ver = NULL; $next_ver = NULL; $last_ver=NULL;
  3259. $this_ver = &$this->GetArchiveVersion($ah, $version, $next_ver, $last_ver);
  3260. if(!isset($this_ver)){$this_ver = $p; $last_ver=$ah['list'][sizeof($ah['list'])-1];}
  3261. $this->MakePostDiff($this_ver, $last_ver, $p);
  3262. } ?>
  3263. </div>
  3264. <?php
  3265. }
  3266. function MakeCommentSection(&$post){
  3267. if(!$this->CommentEnabled){ return; }
  3268. $to_post = isset($post['tid'])?$post['tid']['first']:$post;
  3269. $comment_count = (isset($to_post['comments']) && isset($to_post['comments'][0]))?count($to_post['comments']):0;
  3270. ?><div class='comment'>
  3271. <br /><h2><?=$this->T('评论')?> (<?=$comment_count;?>)</h2><div class='spacer'></div>
  3272. <?php if($comment_count) { echo "<ul>";
  3273. foreach($to_post['comments'] as $p){
  3274. $ht = $this->GenerateSinglePost($p, false, false, false, false, $t, false);
  3275. $name = isset($p['link'])?("<a href='".$p['link']."'>".$p['name']."↗</a>"):$p['name'];
  3276. $mail = $this->LoggedIn?("<span class='gray clean_a hidden_on_print'>&nbsp;".
  3277. "<a href='mailto:".$p['email']."'>@</a>&nbsp;</span>"):"";
  3278. echo "<li><p><b>".$name.":</b>".$mail."</p>".$ht."</li>";
  3279. }
  3280. echo "</ul>";
  3281. } else {
  3282. echo $this->T('还没有评论');
  3283. } ?>
  3284. <div class='hidden_on_print'>
  3285. <div class='spacer'></div>
  3286. <form action="index.php?post=<?=$this->CurrentPostID?>&comment_to=<?=$to_post['id']?>"
  3287. method="post" style="display:none;" id="comment_form"></form>
  3288. <p><a class='text_highlight bold clean_a'
  3289. onclick='document.getElementById("comment_box").style.display="block";this.parentNode.style.display="none"'>
  3290. &nbsp;<?=$this->T('写评论');?>&nbsp;</a></p>
  3291. <div id='comment_box' style='display:none;'>
  3292. <p class='gray' style='margin-bottom:0.5em;'><?=$this->T('您的邮箱不会公开展示。');?></p>
  3293. <table style='white-space:nowrap;'>
  3294. <tr><td colspan='2'>
  3295. <textarea id="comment_box" name="comment_box" rows="4" class='full_box' form='comment_form'
  3296. oninput="CommentUpdated();" ></textarea>
  3297. </td></tr>
  3298. <tr><td><?=$this->T('电子邮件')?>*</td><td><?=$this->T('称呼')?>*</td></tr>
  3299. <tr><td><input type="text" form="comment_form" id='comment_email' name='comment_email'
  3300. class='full_box' oninput="CommentUpdated();" /></td>
  3301. <td><input type="text" form="comment_form" id='comment_name' name='comment_name'
  3302. class='full_box' oninput="CommentUpdated();" /></td></tr>
  3303. <tr><td colspan='2'><?=$this->T('个人网站')?></td></tr>
  3304. <tr><td colspan='2'>
  3305. <input type="text" form="comment_form" id='comment_link' name='comment_link'
  3306. class='full_box' oninput="CommentUpdated();" />
  3307. </td></tr>
  3308. <tr><td colspan='2'>
  3309. <div class='spacer'></div>
  3310. <input class='button text_highlight bigger' type='submit' form='comment_form'
  3311. name='comment_confirm' id='comment_confirm' value='&nbsp;<?=$this->T('发送')?>&nbsp;'>
  3312. </td></tr>
  3313. </table></div>
  3314. <script>
  3315. const IsValidEmail = (email) => {
  3316. 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,}))$/);
  3317. };
  3318. function IsValidHttpUrl(string) {
  3319. let url; try{ url = new URL(string); } catch (_) { return false; }
  3320. return url.protocol === "http:" || url.protocol === "https:";
  3321. }
  3322. var cbox = document.getElementById('comment_box');
  3323. var cemail = document.getElementById('comment_email');
  3324. var cname = document.getElementById('comment_name');
  3325. var clink = document.getElementById('comment_link');
  3326. var cconfirm = document.getElementById('comment_confirm');
  3327. function CommentUpdated(){
  3328. cconfirm.disabled=true;
  3329. if (cemail.value!="" && IsValidEmail(cemail.value) &&
  3330. cbox.innerText.length>2 && cname.value.length>2 &&
  3331. clink.value=="" || IsValidHttpUrl(clink.value)){
  3332. cconfirm.removeAttribute("disabled");
  3333. }
  3334. }
  3335. CommentUpdated();
  3336. </script>
  3337. </div>
  3338. </div>
  3339. <?php
  3340. }
  3341. function MakeInterestingSection(&$th){
  3342. $this->Anchors = [];
  3343. $c = &$th['first']['content'];
  3344. $this->ConvertPost($th['first']);
  3345. $ht = $th['first']['html'];
  3346. ?>
  3347. <script>function ClickImage(post_access){im=post_access.querySelector('img');if(im){im.click();}}</script>
  3348. <div class='center_full' id='div_center'>
  3349. <?php $this->MakePostTools(); ?>
  3350. <h2 class='hidden_on_print'><?=$this->T('有趣')?>
  3351. <a class='gray clean_a' href='?post=<?=$th['first']['id']?>'>→</a></h2>
  3352. <ul><li class='post post_width_big' data-post-id='<?=$th['first']['id']?>'>
  3353. <div class='post_menu_button _menu_hook' onclick='ShowPostMenu(this.parentNode);'>+</div><?=$ht?>
  3354. <?php if(isset($th['first']['refs'][0])){ ?><p class='smaller'><?=$this->T('引用')?>: </p><ul class='smaller'>
  3355. <?php foreach($th['first']['refs'] as $ref){
  3356. $po = $this->GetPost($ref);
  3357. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3358. if(!$this->CanShowPost($po)){ continue; }
  3359. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3360. } ?>
  3361. </ul><?php } ?>
  3362. <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3363. <div class='post_width_big hidden_on_print'><br />
  3364. <?php $this->MakePostingFields($th['last']['id'], true);?><br />
  3365. </div>
  3366. <?php } ?>
  3367. <table><thead><tr><th></th><?php foreach($th['interesting'] as $header){ ?>
  3368. <th><?=$this->T($header);?></th>
  3369. <?php } ?></tr></thead><tbody class='interesting_tbody'>
  3370. <?php $plist = array_reverse(array_slice($th['arr'],1));
  3371. foreach($plist as &$p){
  3372. $this->ConvertPost($p);
  3373. $mark_value = isset($p['mark_value'])?$this->Markers[$p['mark_value']]:-1;
  3374. $ref_count = isset($p['refs'])?sizeof($p['refs']):0;
  3375. $is_current = $p['id']==$this->CurrentPostID;
  3376. $is_deleted = (isset($p['mark_delete'])&&$p['mark_delete']); ?>
  3377. <tr class='<?=$is_current?"post_current_row":""?><?=$is_deleted?" deleted_post":""?>'
  3378. data-post-id='<?=$p['id']?>' <?=$is_deleted?"data-mark-delete='true'":""?>
  3379. onDblClick='ClickImage(this)'><td>
  3380. <a <?=$is_current?"":("href='?post=".$p['id']."' onclick='ShowWaitingBar()'");?> class='clean_a paa'>
  3381. <div class='post_access <?=($mark_value<0 || $ref_count)?"invert_a":""?> hover_dark'>
  3382. <?=isset($p['mark_value'])?$this->Markers[$p['mark_value']]:($ref_count?"":"→")?>
  3383. </div>
  3384. <?php if($ref_count){ ?>
  3385. <div class='post_access ref_count'><?=$ref_count?></div>
  3386. <?php } ?></a>
  3387. <?=$p['html'];?>
  3388. <a class='_menu_hook clean_a post_menu_button' onclick='ShowPostMenu(this.parentNode.parentNode);'>+</a></td></tr>
  3389. <?php if($is_current && $ref_count>0){ ?><tr class='post_current_row'><td><p>&nbsp;</p><ul class='smaller'>
  3390. <?php foreach($p['refs'] as $ref){
  3391. $po = $this->GetPost($ref);
  3392. if(isset($post['mark_value']) && $post['mark_value']==5){ $count_product++; continue; }
  3393. if(!$this->CanShowPost($po)){ continue; }
  3394. echo "<li><a href='?post=".$po['id']."'>".$this->GetPostTitle($po)."</a></li>";
  3395. } ?>
  3396. </ul></td></tr><?php } ?>
  3397. <?php } ?>
  3398. </tbody></table>
  3399. </li></ul>
  3400. <br />
  3401. <?php $this->MakeCommentSection($th['first']); ?>
  3402. </div>
  3403. <?php return true;
  3404. }
  3405. function CssNumberID($id){
  3406. return "#\\3".substr($id,0,1)." ".substr($id,1);
  3407. }
  3408. function MakePostTools(){
  3409. if($this->LoggedIn && !isset($this->WayBack)){ ?><div class='smaller gray hidden_on_print clean_a'>
  3410. <a id='merge_cancel' href='javascript:{TogglePostSelectMode(false,true);ToggleThreadMerge(false,true);}'>
  3411. <?=$this->T('工具')?></a>:<div class='hidden_on_mobile' style='display:inline'>
  3412. <span id='merge_post_btn'><a href='javascript:TogglePostSelectMode()'><?=$this->T('合并帖子')?></a></span>
  3413. | <span id='merge_thread_btn'><a href='javascript:ToggleThreadMerge()'><?=$this->T('合并话题')?></a></span>
  3414. </div>
  3415. <select class='hidden_on_desktop' id='merge_select'
  3416. onchange="if(this.selectedIndex==1){TogglePostSelectMode(true);}else if(this.selectedIndex==2){ToggleThreadMerge(true);}">
  3417. <option value='-1' selected>--</option>
  3418. <option value='1'><?=$this->T('合并帖子')?></option>
  3419. <option value='2'><?=$this->T('合并话题')?></option></select>
  3420. <div style='display:none;' id='merge_post_dialog' class='text_highlight small_pad align_right'>
  3421. <div style='display:inline;'><?=$this->T('将合并');?> <span id='merge_post_count'></span> <?=$this->T('个帖子');?></div>
  3422. <span class='clean_a bold align_right'><a id='merge_post'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3423. <div style='display:none;overflow:auto' id='merge_thread_dialog' class='text_highlight small_pad align_right'>
  3424. <div style='display:inline;'><?=$this->T('合并到话题');?></div>
  3425. <input id="merge_thread_target" type="text" style="width:9em;display:inline" onChange='ThreadMergeInput(this);' onInput='ThreadMergeInput(this);'>
  3426. <span class='clean_a bold align_right'><a id='merge_thread'>&nbsp;<?=$this->T('执行');?></a></span></div>
  3427. </div><div class='spacer'></div><?php
  3428. }
  3429. }
  3430. function MakePostSection(&$post){
  3431. $this->Anchors = [];
  3432. if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
  3433. <div class='center' id='div_center'>
  3434. <h2 class='hidden_on_print'>
  3435. <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1; if($is_thread){ $th = $post['tid'];?>
  3436. <?=$this->T('话题')?> <?php }else{ ?> <?=$this->T('详细')?>
  3437. <?php } ?></h2>
  3438. <?php $cat = NULL;
  3439. if($is_thread) { if(isset($th['categories']) && isset($th['categories'][0])){ $cat = $th['categories']; } }
  3440. else { if(isset($post['categories']) && isset($post['categories'][0])) { $cat = $post['categories']; } }
  3441. $this->MakePostTools();
  3442. if($cat){ ?>
  3443. <p><b><?=$this->T('分类')?></b> | <?php foreach($cat as $c){
  3444. echo "<a href='?category=".$c."'>".($c=='none'?$this->T('未分类'):$this->T($c))."</a> "; } ?></p>
  3445. <?php } ?>
  3446. <ul class='print_column'>
  3447. <?php $is_reversed=false;
  3448. if($is_thread){
  3449. $use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false; if($is_reversed){
  3450. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3451. foreach($use_arr as &$p){
  3452. $use_class = ($p == $post)?'focused_post':'';
  3453. $show_link = ($p == $post)?false:true;
  3454. $make_title = ($p == $post);
  3455. $this->MakeSinglePost($p,$show_link,false,$use_class,false, false, false, true, false, false);
  3456. if($make_title){?>
  3457. <script>
  3458. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3459. </script>
  3460. <?php } if($is_reversed && !$hinted){ ?>
  3461. <li class='gray smaller bold' style='text-align:center;'>
  3462. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3463. <?php $hinted = true;
  3464. if($this->LoggedIn && (!$this->InHereMode)){ ?>
  3465. <div class='post_width_big hidden_on_print'>
  3466. <?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?></div><br />
  3467. <?php } }
  3468. }
  3469. }else{
  3470. $this->MakeSinglePost($post,false, false, 'focused_post',false, false, false, true, false, false);
  3471. ?><script>
  3472. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3473. </script><?php
  3474. } ?>
  3475. <div class='smaller align_right'>
  3476. <span class='gray'><?=$this->ReadableTime($post['tid']['first']['id']);?></span>
  3477. <br class='hidden_on_desktop' /><?=$this->ReadableTime(isset($post['tid']['last']['version'])?
  3478. $post['tid']['last']['version']:$post['tid']['last']['id']);?>
  3479. </div>
  3480. <?php if(!$is_reversed && ($this->LoggedIn && (!$this->InHereMode))){ ?>
  3481. <div class='post_width_big hidden_on_print'>
  3482. <br /><?php $this->MakePostingFields($is_thread?$th['last']['id']:$post['id'], true);?>
  3483. </div>
  3484. <?php }
  3485. $this->MakeCommentSection($post);
  3486. ?>
  3487. </ul>
  3488. </div>
  3489. <?php
  3490. }
  3491. function MakePostSectionExp(&$post){
  3492. $this->Anchors = []; $is_thread = isset($post['tid']);
  3493. ?>
  3494. <div class='center_exp' id='div_center'>
  3495. <ul>
  3496. <?php $is_reversed=false;
  3497. if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th);
  3498. $hinted=false; if($is_reversed){
  3499. $use_arr=array_reverse($th['arr']); $fp=array_pop($use_arr); array_unshift($use_arr,$fp); }
  3500. foreach($use_arr as &$p){
  3501. $this->MakeSinglePostExp($p);
  3502. if($p == $th['first']){?>
  3503. <script>
  3504. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
  3505. </script>
  3506. <?php } if($is_reversed && !$hinted){ ?>
  3507. <li class='gray smaller bold' style='text-align:center;'>
  3508. <p>&nbsp;</p><hr><?=$this->T('该话题最新帖子在前')?><hr><p>&nbsp;</p></li>
  3509. <?php $hinted = true; }
  3510. }
  3511. }else{
  3512. $this->MakeSinglePostExp($post);
  3513. ?><!--<script>
  3514. document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
  3515. </script>--><?php
  3516. } ?>
  3517. </ul>
  3518. </div>
  3519. <?php
  3520. }
  3521. function MakeHereSection(&$im){ $image_okay = (isset($im) && $im!=$this->NULL_IMAGE); ?>
  3522. <div class='here_image_box clean_a'>
  3523. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'>
  3524. <?=$image_okay?$this->T('请稍候'):$this->T('未找到图像')?></div>
  3525. <?php if($image_okay){ ?>
  3526. <img id='big_image' onload="HideWaitingBar();" src="<?=$im['file'];?>" />
  3527. <?php } $this->MakeHereButtons($im, false); ?>
  3528. </div>
  3529. <?php }
  3530. function MakeSideGalleryCode(){?>
  3531. <div>
  3532. <h3><?=$this->T('点击图片以插入:')?></h3>
  3533. <select id="side_gallery_select" onchange="RefreshSideGallery()">
  3534. <option value="main"><?=$this->T('全部')?></option>
  3535. <?php if($this->LoggedIn){ ?>
  3536. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3537. <?php }?>
  3538. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3539. <option value="<?=$g['name']?>"><?=$g['name']?></option>
  3540. <?php } ?>
  3541. </select>
  3542. <div id='side_gallery'>
  3543. </div>
  3544. </div>
  3545. <script>
  3546. function InsertImage(imgname){
  3547. t = document.querySelector("#post_content");
  3548. v = t.value;
  3549. t.value = v.slice(0, t.selectionStart) + "![<?=$this->T('图片')?>](images/"+imgname+")"+ v.slice(t.selectionEnd);
  3550. la_auto_grow(t);
  3551. }
  3552. function RefreshSideGallery(){
  3553. let xhr = new XMLHttpRequest();
  3554. xhr.onreadystatechange = (function(){
  3555. if (this.readyState === this.DONE) {
  3556. if (this.status === 200) {
  3557. ind = document.querySelector("#side_gallery");
  3558. if(res = xhr.responseText.matchAll(/\[(.*?),(.*?)\]/gu)){
  3559. str = "<ul class='side_thumb'>"
  3560. for (const m of res) {
  3561. str+="<li><div class='file_thumb' onclick='InsertImage(\""+m[1]+"\")'>"+
  3562. "<img src='"+m[2]+"' /></div>"
  3563. }
  3564. str += "</ul>"
  3565. ind.innerHTML = str;
  3566. }
  3567. }
  3568. }
  3569. });
  3570. xhr.open("GET", "?image_list="+document.querySelector("#side_gallery_select").value, true);
  3571. xhr.send();
  3572. }
  3573. </script>
  3574. <?php
  3575. }
  3576. function MakeUploader($is_side=false){ ?>
  3577. <div id='upload_operation_area' class='hidden_on_print'>
  3578. <p><?=$this->T('选择、粘贴或者拖动到页面以上传图片。')?></p>
  3579. <input type="file" id='upload_selector' accept="image/x-png,image/png,image/gif,image/jpeg" multiple/>
  3580. <ul id='file_list'>
  3581. </ul>
  3582. <div class='smaller gray' id='upload_hint'><?=$this->T('就绪')?></div>
  3583. </div>
  3584. <a id='upload_click' class='hidden_on_print pointer' onclick='this.removeAttribute("onclick");UploadList();'
  3585. <?=$is_side?" data-is-side='true'":""?>><?=$this->T('上传列表中的文件')?></a>
  3586. <script>
  3587. function pastehandler(event){
  3588. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  3589. for (index in items) {
  3590. var item = items[index];
  3591. if (item.kind === 'file') {
  3592. put = document.querySelector("#_uploader");
  3593. if(put) ShowSideUploader();
  3594. var blob = item.getAsFile();
  3595. AddImageFile(blob);
  3596. return;
  3597. }
  3598. }
  3599. }
  3600. let _fd_list = []; var uploading=0;
  3601. let hint=document.querySelector('#upload_hint');
  3602. function ToggleCompress(button){
  3603. li = button.parentNode;
  3604. num=li.dataset.number;
  3605. for(i=0;i<_fd_list.length;i++){
  3606. if (_fd_list[i][0] == num){
  3607. state = _fd_list[i][2];
  3608. if(state){_fd_list[i][2] = 0; button.innerHTML='1920';break;}
  3609. else{_fd_list[i][2] = 1; button.innerHTML='800';break;}
  3610. }
  3611. }
  3612. }
  3613. function RemoveFromUpload(button){
  3614. li = button.parentNode;
  3615. num=li.dataset.number;
  3616. for(i=0;i<_fd_list.length;i++){
  3617. if (_fd_list[i][0] == num){
  3618. _fd_list.splice(i, 1);break;
  3619. }
  3620. }
  3621. li.parentNode.removeChild(li);
  3622. }
  3623. function EndThisUpload(){
  3624. unfinished = 0;
  3625. for(i=0;i<_fd_list.length;i++){
  3626. if (_fd_list[i][3]==0){
  3627. unfinished=1;
  3628. }
  3629. }
  3630. if(!unfinished){
  3631. uploading=0;
  3632. hint.innerHTML="<?=$this->T('上传完成。')?>";
  3633. cl=document.querySelector('#upload_click');
  3634. if(!cl.dataset.isSide){
  3635. cl.innerHTML="<?=$this->T('刷新页面')?>";
  3636. cl.href=window.location.href;
  3637. }else{
  3638. _fd_list.splice(0,_fd_list.length);
  3639. fl = document.querySelector("#file_list");
  3640. fl.innerHTML = "";
  3641. list=document.querySelector('#upload_operation_area');
  3642. list.style.pointerEvents='';
  3643. list.style.opacity='';
  3644. cl.onclick=function(){this.removeAttribute("onclick");UploadList();};
  3645. document.onpaste=pastehandler;
  3646. RefreshSideGallery();
  3647. }
  3648. }
  3649. }
  3650. function UploadList(){
  3651. if(!_fd_list.length || uploading) return;
  3652. uploading=1;
  3653. hint.innerHTML="<?=$this->T('正在上传...')?>";
  3654. list=document.querySelector('#upload_operation_area');
  3655. list.style.pointerEvents='none';
  3656. list.style.opacity='0.5';
  3657. document.onpaste="";
  3658. for(i=0;i<_fd_list.length;i++){
  3659. let xhr = new XMLHttpRequest();
  3660. var li = list.querySelector('[data-number="'+_fd_list[i][0].toString()+'"]')
  3661. xhr.open("POST", "?compress="+_fd_list[i][2].toString(), true);
  3662. function wrap(li, i){
  3663. var ind = li.querySelector('._compress_toggle')
  3664. return function(){
  3665. if (this.readyState === this.DONE) {
  3666. if (this.status === 200) {
  3667. var response = xhr.responseText;
  3668. if(res = response.match(/<uploaded>(.*)<\/uploaded>/)){
  3669. ind.innerHTML = "<?=$this->T('已上传为')?> "+res[1];
  3670. _fd_list[i][3] = 1;
  3671. }else{
  3672. ind.innerHTML = "<?=$this->T('出现错误。')?>";
  3673. _fd_list[i][3] = 1;
  3674. }
  3675. EndThisUpload();
  3676. }
  3677. }
  3678. }
  3679. }
  3680. xhr.onreadystatechange = wrap(li, i);
  3681. xhr.send(_fd_list[i][1]);
  3682. }
  3683. }
  3684. function AddImageFile(blob){
  3685. var ext="";
  3686. if(blob.name.match(/png$/))ext = 'png';
  3687. else if(blob.name.match(/jpg$/))ext = 'jpg';
  3688. else if(blob.name.match(/jpeg$/))ext = 'jpeg';
  3689. else if(blob.name.match(/gif$/))ext = 'gif';
  3690. else return;
  3691. var fd = new FormData();
  3692. blob.name = blob.name=generateUID().toString();
  3693. fd.append("upload_file_name", blob, "_upload_"+blob.name+"."+ext);
  3694. _fd_list.push([blob.name, fd, 1, 0]);/* number original is_compress uploaded */
  3695. var reader = new FileReader();
  3696. reader.onload = function(event){
  3697. fl = document.querySelector("#file_list");
  3698. ht = "<li id='_upload_"+blob.name+"' data-number='"+blob.name+"'>"+
  3699. "<a class='_remove_file pointer invert_a' onclick='RemoveFromUpload(this)'>×</a> "+"<div class='file_thumb'>"+
  3700. "<img class='no_pop' src='"+event.target.result+"'>"+"</div>"+
  3701. " →<a class='_compress_toggle pointer' onclick='ToggleCompress(this)'>800</a></li>";
  3702. fl.innerHTML+=ht;
  3703. };
  3704. reader.readAsDataURL(blob);
  3705. }
  3706. sel = document.querySelector('#upload_selector');
  3707. sel.addEventListener("change", function(){
  3708. var input = this;
  3709. function ff(file){
  3710. return function(e){
  3711. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3712. blob.name = file.name;
  3713. AddImageFile(blob);
  3714. }
  3715. }
  3716. for(i=0;i<input.files.length;i++){
  3717. if(input.files[i].size){
  3718. let reader = new FileReader();
  3719. reader.onload = ff(input.files[i]);
  3720. reader.readAsArrayBuffer(input.files[i]);
  3721. }
  3722. }
  3723. });
  3724. function generateUID() {
  3725. var firstPart = (Math.random() * 46656) | 0;
  3726. var secondPart = (Math.random() * 46656) | 0;
  3727. firstPart = ("000" + firstPart.toString(36)).slice(-3);
  3728. secondPart = ("000" + secondPart.toString(36)).slice(-3);
  3729. return firstPart + secondPart;
  3730. }
  3731. document.onpaste = pastehandler;
  3732. function dropHandler(ev) {
  3733. put = document.querySelector("#_uploader");
  3734. if(put) ShowSideUploader();
  3735. bkg=document.querySelector('#dropping_background');
  3736. bkg.style.display="none";
  3737. console.log('File(s) dropped');
  3738. ev.preventDefault();ev.stopPropagation();
  3739. if (ev.dataTransfer && ev.dataTransfer.items) {
  3740. for (var i = 0; i < ev.dataTransfer.items.length; i++) {
  3741. if (ev.dataTransfer.items[i].kind === 'file') {
  3742. var file = ev.dataTransfer.items[i].getAsFile();
  3743. function ff(file){
  3744. return function(e){
  3745. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3746. blob.name = file.name;
  3747. AddImageFile(blob);
  3748. }
  3749. }
  3750. if(file){
  3751. let reader = new FileReader();
  3752. reader.onload = ff(file);
  3753. reader.readAsArrayBuffer(file);
  3754. }
  3755. }
  3756. }
  3757. } else {
  3758. for (var i = 0; i < ev.dataTransfer.files.length; i++) {
  3759. function ff(file){
  3760. return function(e){
  3761. let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type});
  3762. blob.name = file.name;
  3763. AddImageFile(blob);
  3764. }
  3765. }
  3766. if(ev.dataTransfer.files[i].size){
  3767. let reader = new FileReader();
  3768. reader.onload = ff(ev.dataTransfer.files[i]);
  3769. reader.readAsArrayBuffer(ev.dataTransfer.files[i]);
  3770. }
  3771. }
  3772. }
  3773. }
  3774. function dragOverHandler(ev) {
  3775. bkg=document.querySelector('#dropping_background');
  3776. bkg.style.display="";
  3777. console.log('File(s) in drop zone');
  3778. ev.preventDefault();
  3779. }
  3780. </script>
  3781. <?php
  3782. }
  3783. function CanShowGallery(&$g){
  3784. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($g['experimental']) && $g['experimental']) return false;
  3785. return true;
  3786. }
  3787. function CanShowImage(&$im){
  3788. if((!$this->LoggedIn&&!$this->InExperimentalMode) && isset($im['galleries']) && isset($im['galleries'][0])) foreach($im['galleries'] as $ga){
  3789. if(($g=$this->GetGallery($ga)) && isset($g['experimental']) && $g['experimental']) return false;
  3790. }
  3791. if(isset($this->WayBack) && substr($im['name'],0,14)>$this->WayBack) return false;
  3792. return true;
  3793. }
  3794. function MakeGallerySection(){
  3795. if(!isset($_GET['gallery'])) return;
  3796. $name=NULL; if($_GET['gallery']!='main' && $_GET['gallery']!='trash'){
  3797. $name=$_GET['gallery'];}?>
  3798. <script>
  3799. document.title+=" | <?=$this->T('画廊')?>";
  3800. </script>
  3801. <div class='center_wide' id='div_center' style='position:relative;'>
  3802. <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
  3803. ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
  3804. ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
  3805. <div class='hidden_on_desktop'>
  3806. <?=$this->T('前往')?>
  3807. <select id="gallery_go_to" onchange="window.location.href='?gallery='+this.value;">
  3808. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3809. if(!isset($g['featured']) || !$g['featured'] ||
  3810. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3811. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3812. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3813. <?php } ?>
  3814. <option value="main" <?=$_GET['gallery']=='main'?"selected":""?>>[<?=$this->T('全部')?>]</option>
  3815. <?php if($this->LoggedIn){ ?>
  3816. <option value="trash" <?=$_GET['gallery']=='trash'?"selected":""?>>[<?=$this->T('垃圾桶')?>]</option>
  3817. <?php } ?>
  3818. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3819. if((isset($g['featured']) && $g['featured']) ||
  3820. !$this->CanShowGallery($g)){ continue; } $is_this = ($_GET['gallery']==$g['name']);?>
  3821. <option value="<?=$g['name']?>" <?=$is_this?"selected":""?>>
  3822. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></option>
  3823. <?php } ?>
  3824. </select>
  3825. </div>
  3826. <?php if($this->LoggedIn){?>
  3827. <div>
  3828. <?php if(isset($name)){ ?>
  3829. <div style='text-align:right;position:absolute;right:0;top:0;width:100%;' class='invert_a smaller hidden_on_print'>
  3830. <a href='javascript:ShowDeleteMenu();'><?=$this->T('删除相册')?></a><br />
  3831. <?php if(isset($gal['featured']) && $gal['featured']!=false){ ?>
  3832. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=false'>
  3833. <?=$this->T('取消精选')?></a>
  3834. <?php }else{ ?>
  3835. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_featured=<?=$_GET['gallery']?>&value=true'>
  3836. <?=$this->T('设为精选')?></a>
  3837. <?php } ?><br />
  3838. <?php if(isset($gal['experimental']) && $gal['experimental']!=false){ ?>
  3839. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=false'>
  3840. <?=$this->T('取消实验')?></a>
  3841. <?php }else{ ?>
  3842. <a href='?gallery=<?=$_GET['gallery']?>&gallery_set_experimental=<?=$_GET['gallery']?>&value=true'>
  3843. <?=$this->T('设为实验')?></a>
  3844. <?php } ?>
  3845. <div class='pop_menu invert_a' id='gallery_delete_menu' style='display:none;'>
  3846. <div style='float:left;' class='gray'><?=$this->T('该操作不删除图片。')?></div>
  3847. <a href='javascript:HidePopMenu();'>×</a>
  3848. <hr />
  3849. <a href='?gallery=main&gallery_edit_delete=<?=$_GET['gallery']?>'><b><?=$this->T('删除相册')?></b></a>
  3850. </div>
  3851. </div>
  3852. <?php } ?>
  3853. <?php $this->MakeUploader(false); ?>
  3854. <div style='text-align:right;position:relative;' class='invert_a smaller hidden_on_print'>
  3855. <div style='position:relative'>
  3856. <?php if(isset($name)){ ?>
  3857. <a href='javascript:ShowGalleryEditMenu("<?=$name?>")'><?=$this->T('改名')?></a>
  3858. <?php } ?>
  3859. <a href='javascript:ShowGalleryEditMenu(null)'><?=$this->T('添加')?></a>
  3860. <div class='pop_menu invert_a' id='gallery_edit_menu' style='display:none;max-width:90%;'>
  3861. <form action="<?=$_SERVER['REQUEST_URI']?>&edit_gallery=true"
  3862. method="post" style='display:none;' id='gallery_edit_form'></form>
  3863. <a style='float:left;'><?=$this->T('相册名字:')?></a>
  3864. <a href='javascript:HidePopMenu();'>×</a>
  3865. <input type='text' form='gallery_edit_form' name='gallery_edit_new_name' id='gallery_edit_new_name' style='width:10em;'>
  3866. <input type='text' form='gallery_edit_form' name='gallery_edit_old_name' id='gallery_edit_old_name' style='display:none'>
  3867. <input class='button' type='submit' form='gallery_edit_form'
  3868. name='gallery_edit_confirm' id='gallery_edit_confirm' value='<?=$this->T('确认')?>'>
  3869. </div>
  3870. </div>
  3871. </div>
  3872. <div class='smaller hidden_on_print'>
  3873. <form action="<?=$_SERVER['REQUEST_URI']?>"
  3874. method="post" style='display:none;' id='gallery_move_form'></form>
  3875. <input type='text' form='gallery_move_form' name='gallery_move_ops'
  3876. id='gallery_move_ops' style='display:none'>
  3877. <p><?=$this->T('选择了')?> <span id='gallery_selected_count'>0</span> <?=$this->T('个图片。')?>
  3878. <a href='javascript:ClearSelectedImages()'><?=$this->T('清除')?></a></p>
  3879. <p><?=$this->T('添加到')?>
  3880. <select id="gallery_move_to">
  3881. <option value="trash"><?=$this->T('垃圾桶')?></option>
  3882. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){ ?>
  3883. <option value="<?=$g['name']?>"><?=$this->T($g['name'])?></option>
  3884. <?php } ?>
  3885. </select>
  3886. <a href='javascript:AddToGallery()'><?=$this->T('执行')?></a>
  3887. </p>
  3888. <p>
  3889. <?=$this->T('或者')?><a href='javascript:RemoveFromGallery()'><?=$this->T('从相册移除')?></a>
  3890. </p>
  3891. </div>
  3892. </div>
  3893. <?php } ?>
  3894. <p>&nbsp;</p>
  3895. <div>
  3896. <?php $opened=0; $prev_year=""; if(isset($this->Images[0])) foreach($this->Images as $im){
  3897. if(!$this->CanShowImage($im)){ continue; }
  3898. if($_GET['gallery']=='trash') $name='trash';
  3899. if($_GET['gallery']!='main'){ if(!isset($im['galleries']) || !in_array($name, $im['galleries'])) continue;}
  3900. $year = substr($im['name'], 0, 4);
  3901. if($year!=$prev_year){
  3902. if($opened) { ?><div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div></div><?php } ?>
  3903. <div><h2 class='sticky_title'><?=$year;?></h2><div class='p_row'><?php $prev_year=$year; $opened=1; } ?>
  3904. <div class='p_thumb<?=isset($im['parent'])?" p_thumb_narrow":""?>'>
  3905. <?php if($this->LoggedIn){ ?>
  3906. <div class="post_menu_button _select_hook white" onclick='ToggleSelectImage(this, "<?=$im["name"]?>")'>●</div>
  3907. <?php } ?>
  3908. <a href='?show_image=<?=$im['name']?>' target='_blank' onclick='event.preventDefault();'>
  3909. <img src='<?=$im['thumb']?>' data-imgsrc='<?=$im["name"]?>'
  3910. <?=isset($im['product'])?'data-product="'.$im["product"].'"':""?>
  3911. <?=isset($im['parent'])?'data-parent="'.$im["parent"].'"':""?>/></a>
  3912. </div>
  3913. <?php } if($opened) { ?>
  3914. <div class='p_thumb' style='flex-grow:10000;box-shadow:none;height:0;'></div></div><?php } ?>
  3915. </div>
  3916. </div>
  3917. <?php if($this->LoggedIn){ ?>
  3918. <script type='text/javascript'>
  3919. var selected_image = new Array();
  3920. function RemoveFromGallery(){
  3921. form = document.querySelector('#gallery_move_form');
  3922. ops = document.querySelector('#gallery_move_ops');
  3923. sel = document.querySelector('#gallery_move_to');
  3924. ops.value = "REM <?=$_GET['gallery']?>"+" "+selected_image.join(' ');
  3925. form.submit();
  3926. }
  3927. function AddToGallery(){
  3928. form = document.querySelector('#gallery_move_form');
  3929. ops = document.querySelector('#gallery_move_ops');
  3930. sel = document.querySelector('#gallery_move_to');
  3931. ops.value = "ADD "+sel.value+" "+selected_image.join(' ');
  3932. form.submit();
  3933. }
  3934. function ClearSelectedImages(){
  3935. selected_image.splice(0, selected_image.length);
  3936. checks = document.querySelectorAll('._select_hook');
  3937. [].forEach.call(checks, function(c){
  3938. c.classList.remove('p_thumb_selected');
  3939. });
  3940. count = document.querySelector('#gallery_selected_count');
  3941. count.innerHTML="0";
  3942. }
  3943. function ToggleSelectImage(elem, name){
  3944. count = document.querySelector('#gallery_selected_count');
  3945. if(selected_image.indexOf(name) == -1){ selected_image.push(name); elem.classList.add('p_thumb_selected'); }
  3946. else{ selected_image.splice(selected_image.indexOf(name), 1); elem.classList.remove('p_thumb_selected'); }
  3947. count.innerHTML=selected_image.length.toString()
  3948. }
  3949. function ShowGalleryEditMenu(old_name){
  3950. m = document.querySelector('#gallery_edit_menu');
  3951. old = document.querySelector('#gallery_edit_old_name');
  3952. newname = document.querySelector('#gallery_edit_new_name');
  3953. m.style.display='block';
  3954. if(old_name!=''){ old.value=old_name; newname.value=old.value; }else{ old.value=''; }
  3955. }
  3956. function ShowDeleteMenu(){
  3957. m=document.querySelector('#gallery_delete_menu');
  3958. m.style.display='block';
  3959. }
  3960. </script>
  3961. <?php } ?>
  3962. <?php
  3963. }
  3964. function MakeGalleryLeft(){?>
  3965. <div class='left hidden_on_mobile gallery_left' id='div_left'>
  3966. <h2><?=$this->T('相册')?></h2>
  3967. <div>
  3968. <span class='gray smaller bold'><?=$this->T('精选')?><hr> </span>
  3969. <ul>
  3970. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3971. if(!isset($g['featured']) || !$g['featured'] || !$this->CanShowGallery($g)){ continue; } ?>
  3972. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3973. <li class='<?=$_GET['gallery']==$g['name']?'selected':""?>'>
  3974. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3975. <?php } ?>
  3976. </ul>
  3977. <div class='smaller'><span class='gray'><?=$this->T('其他相册')?><hr></span><ul>
  3978. <a href='?gallery=main' onclick='ShowWaitingBar()'>
  3979. <li class='<?=$_GET['gallery']=='main'?' selected':""?>'>[<?=$this->T('全部图片')?>]</li></a>
  3980. <?php if(isset($this->Galleries[0])) foreach($this->Galleries as $g){
  3981. if((isset($g['featured']) && $g['featured']) || !$this->CanShowGallery($g)){ continue; } ?>
  3982. <a href='?gallery=<?=$g['name']?>' onclick='ShowWaitingBar()'>
  3983. <li class='<?=$_GET['gallery']==$g['name']?' selected':""?>'>
  3984. <?=(isset($g['experimental'])&&$g['experimental'])?'E ':''?><?=$this->T($g['name'])?></li></a>
  3985. <?php } ?>
  3986. <?php if($this->LoggedIn){ ?>
  3987. <a href='?gallery=trash' onclick='ShowWaitingBar()'>
  3988. <li class='<?=$_GET['gallery']=='trash'?' selected':""?>'>[<?=$this->T('垃圾桶')?>]</li></a>
  3989. <?php } ?>
  3990. </ul></div>
  3991. <p>&nbsp;</p>
  3992. <script>
  3993. </script>
  3994. </div>
  3995. </div>
  3996. <?php
  3997. }
  3998. function MakeTOC(){?>
  3999. <div class='right hidden_on_mobile' id='div_right'>
  4000. <?php if(isset($this->Anchors[0])){?>
  4001. <h2><?=$this->T('目录')?></h2><ul>
  4002. <?php
  4003. foreach($this->Anchors as $a){?>
  4004. <li class='toc_entry_<?=$a[0]>5?5:$a[0]?>'><a href='#<?=$a[1]?>'>
  4005. <?=$this->T($this->ChoosePartsByLanguage($a[2]))?></a></li>
  4006. <?php }
  4007. ?></ul>
  4008. <?php }else{ ?>
  4009. <h2 class='gray'><?=$this->T('目录')?></h2>
  4010. <span class='gray smaller'><?=$this->T('未找到目录')?></span>
  4011. <?php } ?>
  4012. </div>
  4013. <?php
  4014. }
  4015. function MakeSettings(){?>
  4016. <div class='settings'>
  4017. <h2><?=$this->T('设置')?></h2>
  4018. <table style='white-space:nowrap;'>
  4019. <?php if($this->LoggedIn){ ?>
  4020. <form action="index.php?settings=true" method="post" style='display:none;' id='settings_form'></form>
  4021. <colgroup><col style='min-width:5em;'><col style='width:100%;min-width:5em;'></colgroup>
  4022. <thead><tr><td><?=$this->T('选项')?></td><td><?=$this->T('值')?></td></tr></thead>
  4023. <tr><td><?=$this->T('网站标题')?></td>
  4024. <td><input type="text" form="settings_form" id='settings_title' name='settings_title'
  4025. value='<?=$this->Title?>'/></td></tr>
  4026. <tr><td><?=$this->T('短标题')?></td>
  4027. <td><input type="text" form="settings_form" id='settings_short_title' name='settings_short_title'
  4028. value='<?=$this->ShortTitle?>'/></td></tr>
  4029. <tr><td><?=$this->T('显示名称')?></td>
  4030. <td><input type="text" form="settings_form" id='settings_display_name' name='settings_display_name'
  4031. value='<?=$this->DisplayName?>'/></td></tr>
  4032. <tr><td><?=$this->T('电子邮件')?></td>
  4033. <td><input type="text" form="settings_form" id='settings_email' name='settings_email'
  4034. value='<?=$this->EMail?>'/></td></tr>
  4035. <tr><td><?=$this->T('导航栏')?>
  4036. <?=isset($this->SpecialNavigation)?"<a href='?post=".$this->SpecialNavigation."'>→</a>":""?></td>
  4037. <td><input type="text" form="settings_form" id='settings_special_navigation' name='settings_special_navigation'
  4038. value='<?=$this->SpecialNavigation?>'/></td></tr>
  4039. <tr><td><?=$this->T('脚注')?> 1<?=isset($this->SpecialFooter)?"<a href='?post=".$this->SpecialFooter."'>→</a>":""?></td>
  4040. <td><input type="text" form="settings_form" id='settings_special_footer' name='settings_special_footer'
  4041. value='<?=$this->SpecialFooter?>'/></td></tr>
  4042. <tr><td><?=$this->T('脚注')?> 2<?=isset($this->SpecialFooter2)?"<a href='?post=".$this->SpecialFooter2."'>→</a>":""?></td>
  4043. <td><input type="text" form="settings_form" id='settings_special_footer2' name='settings_special_footer2'
  4044. value='<?=$this->SpecialFooter2?>'/></td></tr>
  4045. <tr><td><?=$this->T('置顶文')?><?=isset($this->SpecialPinned)?"<a href='?post=".$this->SpecialPinned."'>→</a>":""?></td>
  4046. <td><input type="text" form="settings_form" id='settings_special_pinned' name='settings_special_pinned'
  4047. value='<?=$this->SpecialPinned?>'/></td></tr>
  4048. <tr><td><?=$this->T('默认相册')?></td>
  4049. <td><input type="text" form="settings_form" id='settings_default_gallery' name='settings_default_gallery'
  4050. value='<?=$this->DefaultGallery?>'/></td></tr>
  4051. <tr><td><?=$this->T('SelfAuth 路径')?></td>
  4052. <td><input type="text" form="settings_form" id='settings_selfauth_path' name='settings_selfauth_path'
  4053. value='<?=$this->SelfAuthPath?>'/></td></tr>
  4054. <tr><td><?=$this->T('启用评论')?></td>
  4055. <td><input type="checkbox" id="settings_enable_comments" name="settings_enable_comments"
  4056. form="settings_form" <?=$this->CommentEnabled?"checked":""?>/></td></tr>
  4057. <tr><td><?=$this->T('附加操作')?></td><td><a class='gray' href='index.php?extras=true'><?=$this->T('进入')?></a></td></tr>
  4058. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4059. <tr><td class='smaller gray'><?=$this->T('长毛象')?></td></tr>
  4060. <tr><td><?=$this->T('长毛象实例')?></td>
  4061. <td><input type="text" form="settings_form" id='settings_mastodon_url' name='settings_mastodon_url'
  4062. value='<?=$this->MastodonURL?>'/></td></tr>
  4063. <tr><td><?=$this->T('长毛象令牌')?></td>
  4064. <td><input type="text" form="settings_form" id='settings_mastodon_token' name='settings_mastodon_token'
  4065. value='<?=$this->MastodonToken?>'/></td></tr>
  4066. <tr><td><?=$this->T('偏好语言')?></td>
  4067. <td><input type="text" form="settings_form" id='settings_mastodon_lang' name='settings_mastodon_lang'
  4068. value='<?=$this->MastodonPreferredLang?>'/></td></tr>
  4069. <tr><td><?=$this->T('本站地址')?></td>
  4070. <td><input type="text" form="settings_form" id='settings_host_url' name='settings_host_url'
  4071. value='<?=$this->HostURL?>'/></td></tr>
  4072. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4073. <tr><td class='smaller gray'><?=$this->T('Activity Pub')?></td></tr>
  4074. <tr><td><?=$this->T('用户名')?></td>
  4075. <td><input type="text" form="settings_form" id='settings_apub_id' name='settings_apub_id'
  4076. value='<?=$this->APubID?>'/></td></tr>
  4077. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4078. <tr><td class='smaller gray'><?=$this->T('这里访问')?></td></tr>
  4079. <tr><td><?=$this->T('主机')?></td>
  4080. <td><input type="text" form="settings_form" id='settings_here_host' name='settings_here_host'
  4081. value='<?=$this->HereHost?>'/></td></tr>
  4082. <tr><td><?=$this->T('网站标题')?></td>
  4083. <td><input type="text" form="settings_form" id='settings_here_title' name='settings_here_title'
  4084. value='<?=$this->HereTitle?>'/></td></tr>
  4085. <tr><td><?=$this->T('短标题')?></td>
  4086. <td><input type="text" form="settings_form" id='settings_here_short_title' name='settings_here_short_title'
  4087. value='<?=$this->HereShortTitle?>'/></td></tr>
  4088. <tr><td><?=$this->T('相册')?></td>
  4089. <td><input type="text" form="settings_form" id='settings_here_album' name='settings_here_album'
  4090. value='<?=$this->HereAlbum?>'/></td></tr>
  4091. <tr><td><?=$this->T('导航栏')?>
  4092. <?=isset($this->HereNavigation)?"<a href='?post=".$this->HereNavigation."'>→</a>":""?></td>
  4093. <td><input type="text" form="settings_form" id='settings_here_navigation' name='settings_here_navigation'
  4094. value='<?=$this->HereNavigation?>'/></td></tr>
  4095. <tr><td><?=$this->T('脚注')?><?=isset($this->HereFooter)?"<a href='?post=".$this->HereFooter."'>→</a>":""?></td>
  4096. <td><input type="text" form="settings_form" id='settings_here_footer' name='settings_here_footer'
  4097. value='<?=$this->HereFooter?>'/></td></tr>
  4098. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4099. <tr><td class='smaller gray'><?=$this->T('实验访问')?></td></tr>
  4100. <tr><td><?=$this->T('主机')?></td>
  4101. <td><input type="text" form="settings_form" id='settings_exp_host' name='settings_exp_host'
  4102. value='<?=$this->ExpHost?>'/></td></tr>
  4103. <tr><td><?=$this->T('网站标题')?></td>
  4104. <td><input type="text" form="settings_form" id='settings_exp_title' name='settings_exp_title'
  4105. value='<?=$this->ExpTitle?>'/></td></tr>
  4106. <tr><td><?=$this->T('短标题')?></td>
  4107. <td><input type="text" form="settings_form" id='settings_exp_short_title' name='settings_exp_short_title'
  4108. value='<?=$this->ExpShortTitle?>'/></td></tr>
  4109. <tr><td><?=$this->T('首次提示')?><?=isset($this->ExpCaution)?"<a href='?post=".$this->ExpCaution."'>→</a>":""?></td>
  4110. <td><input type="text" form="settings_form" id='settings_exp_caution' name='settings_exp_caution'
  4111. value='<?=$this->ExpCaution?>'/></td></tr>
  4112. <tr><td><?=$this->T('相册')?></td>
  4113. <td><input type="text" form="settings_form" id='settings_exp_album' name='settings_exp_album'
  4114. value='<?=$this->ExpAlbum?>'/></td></tr>
  4115. <tr><td><?=$this->T('导航栏')?>
  4116. <?=isset($this->ExpNavigation)?"<a href='?post=".$this->ExpNavigation."'>→</a>":""?></td>
  4117. <td><input type="text" form="settings_form" id='settings_exp_navigation' name='settings_exp_navigation'
  4118. value='<?=$this->ExpNavigation?>'/></td></tr>
  4119. <tr><td><?=$this->T('脚注')?><?=isset($this->ExpFooter)?"<a href='?post=".$this->ExpFooter."'>→</a>":""?></td>
  4120. <td><input type="text" form="settings_form" id='settings_exp_footer' name='settings_exp_footer'
  4121. value='<?=$this->ExpFooter?>'/></td></tr>
  4122. <tr><td class='smaller gray'>&nbsp;</td></tr>
  4123. <tr><td class='smaller gray'><?=$this->T('管理员')?></td><td class='smaller'>
  4124. <a href='index.php?logout=true'><?=$this->T('登出')?></a></td></tr>
  4125. <tr><td><?=$this->T('帐号')?></td>
  4126. <td><input type="text" form="settings_form" id='settings_id' name='settings_id'
  4127. value='<?=$this->Admin?>'/></td></tr>
  4128. <tr><td><?=$this->T('新密码')?></td>
  4129. <td><input type="password" form="settings_form"
  4130. id='settings_new_password' name='settings_new_password' /></td></tr>
  4131. <tr><td><?=$this->T('再次输入')?></td>
  4132. <td><input type="password" form="settings_form"
  4133. id='settings_new_password_redo' name='settings_new_password_redo' /></td></tr>
  4134. <tr><td><?=$this->T('旧密码')?></td>
  4135. <td><input type="password" form="settings_form" id='settings_old_password' name='settings_old_password' /></td></tr>
  4136. <?php }else{ ?>
  4137. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='login_form'></form>
  4138. <colgroup><col style='min-width:3em;'><col style='width:100%;min-width:5em;'></colgroup>
  4139. <tr><td class='smaller gray'><?=$this->T('请登录')?></td></tr>
  4140. <tr><td><?=$this->T('帐号')?></td>
  4141. <td><input type="text" form="login_form" id='login_id' name='login_id' /></td></tr>
  4142. <tr><td><?=$this->T('密码')?></td>
  4143. <td><input type="password" form="login_form" id='login_password' name='login_password' /></td></tr>
  4144. <?php } ?>
  4145. </table>
  4146. <?php if($this->LoggedIn){ ?>
  4147. <input class='button' form="settings_form" type="submit" name='settings_button' value='<?=$this->T('保存设置')?>' />
  4148. <?php }else{ ?>
  4149. <input class='button' form="login_form" type="submit" name='login_button' value='<?=$this->T('登录')?>' />
  4150. <?php } ?>
  4151. </div>
  4152. <?php
  4153. }
  4154. function MakeExtraOperations(){?>
  4155. <div class='settings' style='overflow:auto;'>
  4156. <h2><?=$this->T('附加操作')?></h2>
  4157. <a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a>
  4158. <p>&nbsp;</p>
  4159. <h3><?=$this->T('自动重定向')?></h3>
  4160. <span class='smaller gray'>
  4161. <?=$this->T('P为帖子跳转,匹配REQUEST_URI跳到目标文章;S为站点跳转,可以重定向来源域名,例子:')?>
  4162. <br /><pre>P discount:20001001010101;<br />S old_domain:www.new_domain.com:20001001010101;</pre></span>
  4163. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form2'></form>
  4164. <textarea id="settings_redirect" name="settings_redirect" rows="3" class='full_box' wrap="off"
  4165. form='settings_form2'><?=$this->DisplayRedirectConfig()?></textarea>
  4166. <input class='button' form="settings_form2" type="submit" name='settings_save_redirect'
  4167. value='<?=$this->T('保存重定向设置')?>' />
  4168. <p>&nbsp;</p>
  4169. <h3><?=$this->T('自定义翻译')?></h3>
  4170. <span class='smaller gray'>
  4171. <?=$this->T('填写格式:')?>
  4172. <br /><pre>- 语言 | Language</pre></span>
  4173. <form action="<?=$_SERVER['REQUEST_URI']?>" method="post" style='display:none;' id='settings_form3'></form>
  4174. <textarea id="settings_translation" name="settings_translation" rows="3" class='full_box' wrap="off"
  4175. form='settings_form3'><?=$this->CustomTranslationContent?></textarea>
  4176. <input class='button' form="settings_form3" type="submit" name='settings_save_translation'
  4177. value='<?=$this->T('保存翻译')?>' />
  4178. <p>&nbsp;</p>
  4179. <p class='smaller gray'><?=$this->T('当心!下列操作将立即执行:')?></p>
  4180. <ul>
  4181. <li><a href='index.php?rewrite_styles=true'><?=$this->T('重新写入默认CSS')?></a></li>
  4182. <li><a href='index.php?regenerate_thumbnails=true'><?=$this->T('重新生成图片缩略图')?></a></li>
  4183. <li><a href='index.php?clear_all_logins=true'><?=$this->T('删除所有登录')?>(<?=sizeof($this->LoginTokens);?>)</a></li>
  4184. </ui>
  4185. <br /><br /><br /><a href='index.php?&settings=true'><?=$this->T('返回一般设置')?></a><br />&nbsp;
  4186. </div>
  4187. <?php
  4188. }
  4189. function MakeMainBegin(){?>
  4190. <div class='main' <?php if($this->LoggedIn && (!$this->InHereMode)){ ?>
  4191. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);"<?php } ?>>
  4192. <?php
  4193. }
  4194. function MakeMainEnd(){?>
  4195. </div>
  4196. <?php
  4197. }
  4198. function MakeExpFooter(){?>
  4199. <div class='small_footer exp_h_f exp_f'><div>
  4200. <b><?=$this->InExperimentalMode?$this->T($this->ExpTitle):$this->T($this->HereTitle)?></b>&nbsp;©<?=$this->T($this->DisplayName)?>
  4201. <div class='wayback_link gray clean_a invert_a hidden_on_print'><br class="hidden_on_desktop" />
  4202. <?php if($this->InExperimentalMode && isset($this->ExpFooter) && ($p = &$this->GetPost($this->ExpFooter,true))!=NULL){
  4203. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4204. }else if($this->InHereMode && isset($this->HereFooter) && ($p = &$this->GetPost($this->HereFooter,true))!=NULL){
  4205. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4206. }?></div>
  4207. </div>
  4208. </div>
  4209. </div><!-- page -->
  4210. </body>
  4211. </html>
  4212. <script>
  4213. if(trans = document.getElementById('translate_button')){
  4214. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4215. }
  4216. </script>
  4217. <?php
  4218. }
  4219. function MakeImageOverlay($side_info=null,$static_image=null){
  4220. $static=isset($side_info); ?>
  4221. <div id='big_image_overlay' <?=$static?"":"style='display:none'";?>>
  4222. <div class='big_image_box clean_a' onclick='HideBigImage(1)'>
  4223. <div style='display:flex;align-items:center;height:100%;justify-content:center;width:100%;'><?=$this->T('请稍候')?></div>
  4224. <img id='big_image' onload="HideWaitingBar();" <?=isset($static_image)?("src='".$static_image."'"):""?>/>
  4225. </div>
  4226. <div class='big_side_box' onclick='HideBigImage(1);'>
  4227. <?php if(!$static){ ?>
  4228. <div class='big_image_box clean_a image_nav' onclick='HideBigImage(1)'>
  4229. <div ><a id='prev_image' class='image_nav_prev img_btn_hidden' onclick="event.stopPropagation();">
  4230. <div class='lr_buttons'>←</div></a></div>
  4231. <div ><a id='next_image' class='image_nav_next img_btn_hidden' onclick="event.stopPropagation();">
  4232. <div class='lr_buttons'>→</div></a></div>
  4233. <div id='here_buttons'></div>
  4234. </div><?php } ?>
  4235. <div class='side_box_mobile_inner'>
  4236. <?php if(!$static){ ?>
  4237. <div class='inquiry_buttons img_btn_hidden' id='inquiry_buttons' onclick="event.stopPropagation();">
  4238. <span style='display:none;' id='image_purchase' class='clean_a'>
  4239. <b><a id='image_purchase_button' target="_blank">¥<?=$this->T('购买印刷品')?></a></b>
  4240. <br class='hidden_on_desktop block_on_mobile' /></span>
  4241. <b><a class='clean_a' id='image_download'><span id='download_processing'>↓</span><?=$this->T('下载')?></a></b>
  4242. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4243. &nbsp;<a class='clean_a' id='image_inquiry'>
  4244. <b>@</b><?=$this->T('咨询')?></a>
  4245. <?php } ?><hr class='hidden_on_desktop block_on_mobile' />
  4246. </div>
  4247. <div id='big_image_share' class='clean_a' onclick="event.stopPropagation();">
  4248. <li><a id='big_share_copy'>⎘ <?=$this->T('复制链接')?></a></li>
  4249. <hr />
  4250. </div><?php } //static ?>
  4251. <div id='big_image_info' onclick="event.stopPropagation();"><?=$static?$side_info:""?></div>
  4252. <?php if($this->LoggedIn && !$static){ ?><div id='big_image_ops' onclick="event.stopPropagation();">
  4253. <br /><?=$this->T('印刷品链接')?>
  4254. <form action="" method="post" style='display:none;' id='image_ops_form'></form>
  4255. <input type='text' id='image_ops_product_link' name='image_ops_product_link' form="image_ops_form" >
  4256. <?=$this->T('重命名')?>
  4257. <input type='text' id='image_edit_new_name' name='image_edit_new_name' form="image_ops_form" >
  4258. <?=$this->T('主图')?>
  4259. <input type='text' id='image_parent' name='image_parent' form="image_ops_form" >
  4260. <input class='button' form="image_ops_form" type="submit" name='image_button' value=<?=$this->T('保存')?> />
  4261. <br /><br /><?=$this->T('替换图像')?>
  4262. <form action="" method="post" style='display:none;' id='image_edit_form' enctype="multipart/form-data"></form>
  4263. <input type="file" form='image_edit_form'
  4264. id='big_image_upload' name='upload_file_name' accept="image/x-png,image/png,image/gif,image/jpeg"/><br />
  4265. <input class='button' form="image_edit_form" type="submit" name='image_replace_button'
  4266. value=<?=$this->T('执行')?> />
  4267. </div><?php } ?>
  4268. </div>
  4269. </div>
  4270. </div>
  4271. <?php }
  4272. function MakePageEnd(){?>
  4273. </div><!-- page -->
  4274. </body>
  4275. </html>
  4276. <?php }
  4277. function MakeFooter(){?>
  4278. <div class='small_footer'><div>
  4279. <hr />
  4280. <b><?=$this->T($this->Title)?></b>
  4281. <span onclick='event.stopPropagation()'
  4282. ondblclick='javascript:window.location.href="index.php?settings=true"'>©</span><?=$this->T($this->DisplayName)?>
  4283. <div class='wayback_link clean_a invert_a hidden_on_print'><?php if(!isset($this->WayBack)){ ?>
  4284. - <a href='<?=$this->GetRedirect()?>&set_wayback=true'><?=$this->T('以过去的日期浏览')?></a>
  4285. <?php }else{ ?><a href='<?=$this->GetRedirect()?>&set_wayback=false'><?=$this->T('回到当前日期')?></a><?php } ?>
  4286. <br class='hidden_on_desktop' /> - <a href='<?=$this->GetRedirect()?>&toggle_font=true'>
  4287. <?=$this->T('切换字体')?>: <?=$this->T($this->UseRemoteFont?"远程":"本地");?></a>
  4288. <br class='hidden_on_desktop' />
  4289. - <a rel="alternate" type="application/rss+xml" href="?rss=<?=$this->LanguageAppendix;?>" />RSS/Atom<sup><?=$this->LanguageAppendix;?></sup></a>
  4290. </div>
  4291. </div></div>
  4292. <div class='footer'>
  4293. <div style='white-space:nowrap;'>
  4294. <div class='footer_additional'>
  4295. <?php if(isset($this->SpecialFooter) && ($p = &$this->GetPost($this->SpecialFooter))!=NULL){
  4296. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4297. } ?>
  4298. </div>
  4299. <div class='footer_additional'>
  4300. <?php if(isset($this->SpecialFooter2) && ($p = &$this->GetPost($this->SpecialFooter2))!=NULL){
  4301. echo $this->GenerateSinglePost($p, false, false, false, false,$this->NULL_POST,false);
  4302. } ?>
  4303. </div>
  4304. </div>
  4305. </div>
  4306. <p>&nbsp;<p>
  4307. <div id='dropping_background' style='display:none;' onclick='this.style.display="none";'
  4308. ondrop="_dropHandler(event);" ondragover="_dragOverHandler(event);">
  4309. <h2 style='width:100%;'><?=$this->T('上传到这里')?></h2>
  4310. </div>
  4311. <?php $this->MakeImageOverlay(); $this->MakePageEnd(); ?>
  4312. <script>
  4313. <?=$this->ExtraScripts?>
  4314. if(back = document.getElementById('button_back')){
  4315. if(document.referrer.indexOf(location.protocol + "//" + location.host) == 0){
  4316. back.href='javascript:history.back()';
  4317. }else{
  4318. back.href='index.php';
  4319. }
  4320. }
  4321. function copy_text(t) {
  4322. ta = document.createElement('textarea');
  4323. document.body.appendChild(ta);
  4324. ta.value = t;
  4325. ta.select();
  4326. document.execCommand("copy");
  4327. document.body.removeChild(ta);
  4328. }
  4329. if(trans = document.getElementById('translate_button')){
  4330. trans.href='https://translate.google.com/translate?sl=auto&tl=en-US&u='+encodeURIComponent(document.location.href);
  4331. }
  4332. <?php if($this->LoggedIn){ ?>
  4333. var Scenter = document.querySelector('#div_center');
  4334. var Sposts = Scenter.querySelectorAll('.post');
  4335. <?php if(isset($this->MastodonToken)){ ?>
  4336. function MarkPostDoneMastodon(id,mastodon_url){
  4337. for(var i=0;i<Sposts.length;i++){
  4338. if(Sposts[i].dataset.postId==id){ Sposts[i].dataset.mastodon_url= mastodon_url; break;} }
  4339. }
  4340. <?php } ?>
  4341. <?php if($this->PageType=='post' && !isset($this->WayBack)) { ?>
  4342. var Smerge_post_dialog = Scenter.querySelector('#merge_post_dialog');
  4343. var Smerge_post = Scenter.querySelector('#merge_post');
  4344. var Smerge_post_count = Smerge_post_dialog.querySelector('#merge_post_count');
  4345. var Smerge_post_btn = Scenter.querySelector('#merge_post_btn');
  4346. var Smerge_cancel = Scenter.querySelector('#merge_cancel');
  4347. var Smerge_select = Scenter.querySelector('#merge_select');
  4348. var Smerge_thread_dialog = Scenter.querySelector('#merge_thread_dialog');
  4349. var Smerge_thread = Scenter.querySelector('#merge_thread');
  4350. var Smerge_thread_target = Scenter.querySelector('#merge_thread_target');
  4351. var Smerge_thread_btn = Scenter.querySelector('#merge_thread_btn');
  4352. var select_mode = false; var merge_mode = false; var selected_posts = null;
  4353. function TogglePostSelectMode(force_on=false,force_off=false){
  4354. Scenter.classList.add('post_selecting');
  4355. if((!select_mode || force_on) && !force_off){ ToggleThreadMerge(false,true); Scenter.classList.add('post_selecting');
  4356. Smerge_post_dialog.style.display="block";Smerge_post_btn.classList.add('text_highlight');
  4357. Smerge_cancel.innerText='<?=$this->T("取消")?>'; select_mode = 1;}
  4358. else{ select_mode = 0; Scenter.classList.remove('post_selecting');
  4359. Smerge_post_dialog.style.display="none";Smerge_post_btn.classList.remove('text_highlight');
  4360. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4361. for(var i=0;i<Sposts.length;i++){ Sposts[i].classList.remove('post_selected');
  4362. Sposts[i].onclick=select_mode?function(){TogglePostSelect(this);}:null; }
  4363. Smerge_post_count.innerText="0";
  4364. Smerge_post.href="#";
  4365. }
  4366. function TogglePostSelect(elem){
  4367. if(elem.classList.contains('post_selected')){ elem.classList.remove('post_selected'); }
  4368. else{ elem.classList.add('post_selected'); }
  4369. selected_posts = new Array();
  4370. for(var i=0;i<Sposts.length;i++){ if(Sposts[i].classList.contains('post_selected')){
  4371. selected_posts.push(Sposts[i].dataset.postId); } }
  4372. Smerge_post.href="?merge_posts="+selected_posts.join(" ");
  4373. Smerge_post_count.innerText=selected_posts.length;
  4374. }
  4375. function ThreadMergeInput(elem){
  4376. if(elem.value.match(/[0-9]{14}/)) { Smerge_thread.href="?merge_threads=<?=$this->ActualPostID?> "+elem.value; }
  4377. else{ Smerge_thread.href="#"; }
  4378. }
  4379. function ToggleThreadMerge(force_on=false,force_off=false){
  4380. if((!merge_mode || force_on) && !force_off){ TogglePostSelectMode(false,true);
  4381. Smerge_thread_dialog.style.display="block";Smerge_thread_btn.classList.add('text_highlight');
  4382. Smerge_cancel.innerText='<?=$this->T("取消")?>'; merge_mode = 1;}
  4383. else{ merge_mode = 0;
  4384. Smerge_thread_dialog.style.display="none";Smerge_thread_btn.classList.remove('text_highlight');
  4385. Smerge_cancel.innerText='<?=$this->T("工具")?>';Smerge_select.selectedIndex='0'; }
  4386. Smerge_thread.href="#";
  4387. Smerge_thread_target.value='';
  4388. }
  4389. <?php } ?>
  4390. function ShowSideUploader(){
  4391. ShowRightSide(true,null);
  4392. put = document.querySelector("#_uploader");
  4393. put.style.display='block';
  4394. RefreshSideGallery();
  4395. }
  4396. dmark = document.querySelector("#mark_details");
  4397. drename = document.querySelector("#rename_details");
  4398. dmastodon = document.querySelector("#mastodon_details");
  4399. drename_form = document.querySelector("#post_rename_form");
  4400. drename_input = document.querySelector("#post_rename_name");
  4401. var rp = document.querySelector('#post_reply_to');
  4402. var _reply_to = rp?rp.defaultValue:"";
  4403. function RestoreReply(){
  4404. if(rp){
  4405. rp.defaultValue = _reply_to;
  4406. }
  4407. document.querySelector('#post_reply_restore').style.display='none';
  4408. ht = document.querySelector('#post_hint_text');
  4409. if (_reply_to!=""){
  4410. ht.style.display='block';
  4411. ht.innerHTML="<?=$this->T('继续补充该话题:')?>";
  4412. }else{
  4413. ht.style.display='none';
  4414. }
  4415. document.querySelector('#post_edit_target').value="";
  4416. ch = document.querySelector('#post_hint_modify');
  4417. ch.style.display='none';
  4418. }
  4419. function MakeRefer(id){
  4420. t = document.querySelector('#post_content')
  4421. t.focus();
  4422. v = t.value;
  4423. t.value = v.slice(0, t.selectionStart) + "[<?=$this->T('引用文章')?>]("+id.toString()+")" + v.slice(t.selectionEnd);
  4424. la_auto_grow(t);
  4425. if(rp){
  4426. rp.defaultValue = "";
  4427. ht = document.querySelector('#post_hint_text');
  4428. ht.innerHTML = "<?=$this->T('引用并发送新话题:')?>"; ht.style.display='block';
  4429. document.querySelector('#post_reply_restore').style.display='inline';
  4430. rs = document.querySelector('#post_reply_restore');
  4431. rs.style.display='inline'; rs.innerHTML="<?=$this->T('切换为回复')?>";
  4432. document.getElementById('post_menu').style.display='none';
  4433. ch = document.querySelector('#post_hint_modify');
  4434. ch.style.display='none';
  4435. }
  4436. }
  4437. function CopyRefer(id){
  4438. copy_text(id.toString());
  4439. menu.querySelector('#menu_refer_copy').innerHTML="<?=$this->T('已复制')?>";
  4440. }
  4441. function MakeEdit(id){
  4442. ed = document.getElementById('menu_edit');
  4443. ed.innerHTML="<?=$this->T('稍等')?>";
  4444. ed.href="#";
  4445. var xhr = new XMLHttpRequest();
  4446. xhr.onreadystatechange = function() {
  4447. if (this.readyState == 4 && this.status == 200) {
  4448. ed.innerHTML='——';
  4449. ch = document.querySelector('#post_hint_modify');
  4450. ch.style.display='block';
  4451. ht = document.querySelector('#post_hint_text');
  4452. ht.innerHTML = "<?=$this->T('修改帖子:')?>";
  4453. rs = document.querySelector('#post_reply_restore');
  4454. rs.style.display='inline'; rs.innerHTML="<?=$this->T('取消')?>";
  4455. t = document.querySelector('#post_content');
  4456. t.value=xhr.responseText.trim();
  4457. t.focus();
  4458. la_auto_grow(t);
  4459. document.querySelector('#post_edit_target').value=id;
  4460. document.getElementById('post_menu').style.display='none';
  4461. }
  4462. };
  4463. xhr.open("GET", "index.php?post="+id.toString()+'&post_original=true', true);
  4464. xhr.send();
  4465. }
  4466. function MarkDelete(id){
  4467. p = document.querySelector('[data-post-id="'+id+'"]');
  4468. op = p.dataset.markDelete?"false":"true";
  4469. window.location.href=
  4470. "index.php?<?=$this->GetRedirect()?>&mark_delete="+op+'&target='+id.toString();
  4471. }
  4472. function SetMark(mark){
  4473. menu = document.getElementById('post_menu');
  4474. window.location.href=
  4475. "index.php?<?=$this->GetRedirect()?>&target="+
  4476. menu.parentNode.dataset.postId+"&set_mark="+mark;
  4477. }
  4478. function ToggleMarkDetails(){
  4479. dmark.style.display=(dmark.style.display=='block')?'none':'block';
  4480. drename.style.display=dmastodon.style.display='none';
  4481. }
  4482. function ToggleRenameDetails(){
  4483. drename.style.display=(drename.style.display=='block')?'none':'block';
  4484. dmark.style.display=dmastodon.style.display='none';
  4485. }
  4486. function ToggleMastodonDetails(){
  4487. dmastodon.style.display=(dmastodon.style.display=='block')?'none':'block';
  4488. dmark.style.display=drename.style.display='none';
  4489. }
  4490. <?php } ?>
  4491. function ShowPostMenu(post){
  4492. menu = document.getElementById('post_menu');
  4493. menu.style.display='block';
  4494. menu.parentNode.removeChild(menu);
  4495. post.appendChild(menu);
  4496. menu.style.display='block';
  4497. id = post.dataset.postId
  4498. menu.querySelector('#_time_hook').innerHTML = ''+id.substring(2,4)+'/'+id.substring(4,6)+'/'+id.substring(6,8)+
  4499. ' '+id.substring(8,10)+':'+id.substring(10,12);
  4500. window.onClick="HidePopMenu()";
  4501. menu.onClick=(function(event){
  4502. event.stopPropagation();
  4503. });
  4504. hs = menu.querySelector('#menu_history');
  4505. hs.href='?post='+id+'&history=1';
  4506. <?php if($this->LoggedIn && !isset($this->WayBack)){ ?>
  4507. menu.querySelector('#menu_refer').href='javascript:MakeRefer(id)';
  4508. ref = menu.querySelector('#menu_refer_copy')
  4509. ref.innerHTML='<?=$this->T("复制编号")?>';
  4510. ref.href='javascript:CopyRefer(id)';
  4511. ed = menu.querySelector('#menu_edit')
  4512. ed.href='javascript:MakeEdit(id)'; ed.innerHTML="<?=$this->T('修改')?>";
  4513. d = menu.querySelector('#menu_delete');
  4514. d.href='javascript:MarkDelete(\"'+id+'\")';
  4515. p = document.querySelector('[data-post-id="'+id+'"]');
  4516. d.innerHTML = p.dataset.markDelete?"<?=$this->T('恢复')?>":"<?=$this->T('删除')?>";
  4517. menu.querySelector('#mark_details').dataset.id=id;
  4518. drename_input.value=id;
  4519. drename_form.action="<?=$this->GetRedirect()?>"+"&rename_post="+id;
  4520. <?php if(isset($this->MastodonToken)){ ?>
  4521. dmastodon_form = document.querySelector("#post_mastodon_form");
  4522. dmastodon_form.action='?mastodon_post='+id;
  4523. function MastodonSend(id){
  4524. mastodon_send.innerHTML="<?=$this->T('稍等')?>";
  4525. var xhr = new XMLHttpRequest();
  4526. function wrapidxhr(_id) { return function() {
  4527. if (this.readyState == 4 && this.status == 200) {
  4528. var response = xhr.responseText;
  4529. let content="";
  4530. if(res = response.match(/SUCCESS (\S+)/u)){
  4531. content="<?=$this->T('成功发送到长毛象')?>";
  4532. }else{content="<b><?=$this->T('出现问题')?></b><br /><span class='smaller'>"+response+"</span>";}
  4533. mastodon_send.innerHTML=content; mastodon_send.href=res[1];
  4534. MarkPostDoneMastodon(_id, res[1]);
  4535. } }
  4536. };
  4537. xhr.onreadystatechange = wrapidxhr(id);
  4538. xhr.open("GET", "index.php?mastodon_send_post="+id, true); xhr.send();
  4539. }
  4540. menu_mastodon = menu.querySelector("#menu_mastodon");
  4541. mastodon_send = menu.querySelector("#menu_mastodon_send");
  4542. mastodon_view = menu.querySelector("#menu_mastodon_view");
  4543. mastodon_url = menu.querySelector("#post_mastodon_url");
  4544. if(p.dataset.mastodon_url){mastodon_view.style.display='inline';mastodon_view.href=p.dataset.mastodon_url;
  4545. mastodon_send.innerHTML='<?=$this->T("重新发送")?>'; mastodon_url.value=p.dataset.mastodon_url; }
  4546. else{mastodon_view.style.display='none';mastodon_view.href=""; mastodon_send.innerHTML="<?=$this->T('发送')?>";
  4547. mastodon_url.value="";}
  4548. mastodon_send.onclick=function(){
  4549. this.onclick=function(){};
  4550. MastodonSend(id); };
  4551. <?php } } ?>
  4552. title = document.title;
  4553. copy = document.getElementById('share_copy');
  4554. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4555. copy.addEventListener("click", function(){
  4556. url = window.location
  4557. path = location.pathname
  4558. copy_text(url.protocol+"//"+url.host+path+"?post="+id);
  4559. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4560. });
  4561. }
  4562. function HidePopMenu(){
  4563. var menus = document.querySelectorAll('.pop_menu');
  4564. [].forEach.call(menus, function(m){m.style.display='none';});
  4565. }
  4566. var posts = document.querySelectorAll('.center .post');
  4567. [].forEach.call(posts, function(p){
  4568. if(s=p.querySelector('._menu_hook')) s.addEventListener("click", function() {
  4569. ShowPostMenu(this.parentNode.parentNode);
  4570. });
  4571. });
  4572. var post_clickables = document.querySelectorAll('.center .post a');
  4573. [].forEach.call(post_clickables, function(p){
  4574. p.addEventListener("click", function(event){
  4575. event.stopPropagation();
  4576. });
  4577. });
  4578. function FindImage(imgsrc){
  4579. for(var i=0;i<document.images_filtered.length;i++){
  4580. if (document.images_filtered[i].dataset.imgsrc==imgsrc) return document.images_filtered[i]
  4581. }
  4582. return null
  4583. }
  4584. var dottime1;
  4585. var dottime2;
  4586. function ToDataURL(url) {
  4587. return fetch(url).then((response) => {return response.blob();}).then(blob => {
  4588. clearTimeout(dottime1);clearTimeout(dottime2);
  4589. ps = document.querySelector('#download_processing');
  4590. ps.innerHTML='↓';ps.style.opacity='';
  4591. return URL.createObjectURL(blob);});
  4592. }
  4593. async function DownloadAsImage(url,name) {
  4594. const a = document.createElement("a"); a.href = await ToDataURL(url); a.download = name;
  4595. document.body.appendChild(a); a.click(); document.body.removeChild(a);
  4596. }
  4597. function basename(url){return url.split(/[\\/]/).pop();}
  4598. pushed=0;
  4599. function ShowBigImage(imgsrc,do_push){
  4600. ShowWaitingBar();
  4601. share = document.querySelector('#big_image_share');
  4602. img = document.querySelector('#big_image');
  4603. down = document.querySelector('#image_download');
  4604. img.src = "";
  4605. img.src = src = "images/"+imgsrc;
  4606. down.href="images/"+imgsrc;
  4607. var downname='<?=$this->T($this->Title);?>_<?=$this->T($this->DisplayName);?>_+<?=$this->GiveSafeEMail()?>+_'+
  4608. basename(down.href);
  4609. img.alt = downname; down.download=downname;
  4610. var use_href = "images/"+imgsrc;
  4611. down.onclick=function(event){event.stopPropagation();event.preventDefault();
  4612. ps = this.querySelector('#download_processing');ps.innerText='…';
  4613. var dotwait = function(ps){ var self = this;
  4614. dottime1 = setTimeout(function(ps){
  4615. ps.style.opacity='0'; dottime2 = setTimeout(function(ps){ps.style.opacity='1'; dotwait(ps);},300,ps); },300,ps) }
  4616. dotwait(this.querySelector('#download_processing'));
  4617. DownloadAsImage(use_href,downname);};
  4618. if(do_push){PushGalleryHistory(src)}
  4619. page_url = encodeURIComponent(window.location.href);
  4620. <?php if(isset($this->EMail) && $this->EMail!=""){ ?>
  4621. inqb = document.querySelector('#image_inquiry');
  4622. inqb.href="mailto:<?=$this->T($this->DisplayName);?>\<<?=$this->EMail?>\>?subject=<?=$this->T('网站图片咨询');?>&body="+
  4623. encodeURIComponent("<?=$this->T('你好!我对你网站上的这张图片感兴趣:')?>"+'\n\n')+
  4624. (page_url)+encodeURIComponent('\n\n');
  4625. <?php } ?>
  4626. this_image = FindImage(imgsrc);
  4627. if(this_image&&this_image.dataset.prevsrc){
  4628. new_image = FindImage(this_image.dataset.prevsrc);
  4629. new_prev = new_image?new_image.dataset.prevsrc:null;
  4630. im = document.querySelector('#prev_image');
  4631. if(new_prev) {im.href='javascript:ShowBigImage("'+this_image.dataset.prevsrc+'",'+do_push+')';im.style.opacity='';}
  4632. else {im.style.opacity='0';im.removeAttribute("href");}
  4633. }
  4634. if(this_image&&this_image.dataset.nextsrc){
  4635. new_image = FindImage(this_image.dataset.nextsrc);
  4636. new_next = new_image?new_image.dataset.nextsrc:null;
  4637. im = document.querySelector('#next_image');
  4638. if(new_next) {im.href='javascript:ShowBigImage("'+this_image.dataset.nextsrc+'",'+do_push+')';im.style.opacity='';}
  4639. else {im.style.opacity='0';im.removeAttribute("href");}
  4640. }
  4641. purchase = document.querySelector('#image_purchase');
  4642. purchase_btn = document.querySelector('#image_purchase_button');
  4643. <?php if($this->LoggedIn){ ?>
  4644. product_link = document.querySelector('#image_ops_product_link');
  4645. product_form = document.querySelector('#image_ops_form');
  4646. edit_form = document.querySelector('#image_edit_form');
  4647. edit_new_name = document.querySelector('#image_edit_new_name');
  4648. edit_parent = document.querySelector('#image_parent');
  4649. product_form.action = window.location.href;
  4650. edit_form.action = window.location.href;
  4651. edit_new_name.value = imgsrc.split('.')[0];
  4652. if(this_image&&this_image.dataset.product){ product_link.value = this_image.dataset.product; }else{ product_link.value = ""; }
  4653. if(this_image&&this_image.dataset.parent){ edit_parent.value = this_image.dataset.parent; }else{ edit_parent.value = ""; }
  4654. <?php } ?>
  4655. if(this_image&&this_image.dataset.product){
  4656. purchase.style.display='';
  4657. href = this_image.dataset.product;
  4658. if(this_image.dataset.product.match('^[0-9]{14}$')){
  4659. href = '?post='+href;
  4660. }
  4661. purchase_btn.href = href;
  4662. }else{
  4663. purchase.style.display='none';
  4664. purchase_btn.removeAttribute("href");
  4665. }
  4666. DelayHideImgBtn(null);
  4667. title = encodeURIComponent(document.title);
  4668. copy = document.getElementById('big_share_copy');
  4669. copy.innerHTML='⎘ <?=$this->T("复制链接")?>';
  4670. copy.addEventListener("click", function(){
  4671. copy_text(window.location.href);
  4672. this.innerHTML='&#10003;&#xfe0e; <?=$this->T("复制链接")?>';
  4673. });
  4674. o = document.querySelector('#big_image_overlay');
  4675. info = document.querySelector('#big_image_info');info.innerHTML="<?=$this->T('正在查询……')?>";
  4676. here = document.querySelector('#here_buttons');here.innerHTML='';
  4677. o.style.display="block";
  4678. ShowBackdrop(0.8);
  4679. var xhr = new XMLHttpRequest();
  4680. xhr.onreadystatechange = function() {
  4681. if (this.readyState == 4 && this.status == 200) {
  4682. info = document.querySelector('#big_image_info');
  4683. var response = xhr.responseText;
  4684. let content=""
  4685. if(res = response.match(/<ref>(.*)<\/ref>/u)){
  4686. content="<span class='small'><?=$this->T('该图片出现在')?> "+res[1]+" <?=$this->T('个帖子中')?></span>"+content;
  4687. }else{content="<span class='smaller gray'><?=$this->T('该图片未被引用')?></span>"+content;}
  4688. if(res = response.match(/<insert>([\s\S]*)<\/insert>/u)){
  4689. content+="<div class='clean_a'>"+res[1]+"</div>"; }
  4690. info.innerHTML=content;
  4691. if(res = response.match(/<here>([\s\S]*)<\/here>/u)){
  4692. here.innerHTML=res[1]; window.here_b=document.getElementsByClassName('here_btn');
  4693. if(window.here_b)for(b=0;b<window.here_b.length;b++) {
  4694. window.here_b[b].addEventListener('mousemove',DontHideImgBtn);
  4695. window.here_b[b].addEventListener('mouseover',DontHideImgBtn);}
  4696. }
  4697. }
  4698. };
  4699. xhr.open("GET", "index.php?image_info="+imgsrc+"", true);
  4700. xhr.send();
  4701. }
  4702. function HideBigImage(do_push){
  4703. o = document.querySelector('#big_image_overlay');
  4704. img = document.querySelector('#big_image');
  4705. img.src = "";
  4706. if(o.style.display!='none'){
  4707. o.style.display="none";
  4708. HideBackdrop();
  4709. if(do_push){PushGalleryHistory("");}
  4710. HideWaitingBar();
  4711. }
  4712. }
  4713. var lbtn=document.querySelector('#prev_image'),rbtn=document.querySelector('#next_image');
  4714. var inq=document.querySelector('#inquiry_buttons');
  4715. var overlay=document.querySelector('#big_image_overlay');
  4716. var hide_timeout;
  4717. function DontHideImgBtn(e){ clearTimeout(hide_timeout); e.stopPropagation(); }
  4718. function DelayHideImgBtn(e){
  4719. lbtn.classList.remove('img_btn_hidden'); rbtn.classList.remove('img_btn_hidden');
  4720. inq.classList.remove('img_btn_hidden');
  4721. if(window.here_b)for(b=0;b<window.here_b.length;b++){window.here_b[b].classList.remove('img_btn_hidden');}
  4722. clearTimeout(hide_timeout);
  4723. hide_timeout = setTimeout(function(e1,e2,e3,e4){e1.classList.add('img_btn_hidden');
  4724. e2.classList.add('img_btn_hidden');e3.classList.add('img_btn_hidden');
  4725. if(window.here_b)for(b=0;b<window.here_b.length;b++){
  4726. window.here_b[b].classList.add('img_btn_hidden');}}, 1000, lbtn, rbtn, inq);
  4727. }
  4728. lbtn.addEventListener('mousemove',DontHideImgBtn);lbtn.addEventListener('mouseover',DontHideImgBtn);
  4729. rbtn.addEventListener('mousemove',DontHideImgBtn);rbtn.addEventListener('mouseover',DontHideImgBtn);
  4730. inq.addEventListener('mousemove',DontHideImgBtn);inq.addEventListener('mouseover',DontHideImgBtn);
  4731. overlay.addEventListener('mousemove',DelayHideImgBtn);
  4732. var images = document.querySelectorAll('img');
  4733. var images_filtered=new Array(); var imgadded = new Array();
  4734. var images_remaining=new Array();
  4735. [].forEach.call(images, function(img){
  4736. if(img.classList.contains("no_pop") || (!(imgsrc = img.dataset.imgsrc))) return;
  4737. if(imgadded.indexOf(imgsrc)>=0) {images_remaining.push(img); return;}
  4738. images_filtered.push(img);imgadded.push(imgsrc);
  4739. });
  4740. for(var i=0; i<images_filtered.length; i++){
  4741. previmg = nextimg = null; img = images_filtered[i];
  4742. if(i>0) previmg=images_filtered[i-1];
  4743. if(i<images_filtered.length-1) nextimg=images_filtered[i+1];
  4744. prevsrc=previmg?previmg.dataset.imgsrc:null; nextsrc=nextimg?nextimg.dataset.imgsrc:null;
  4745. img.dataset.prevsrc = prevsrc; img.dataset.nextsrc = nextsrc;
  4746. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4747. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4748. }
  4749. for(var i=0; i<images_remaining.length; i++){
  4750. img = images_remaining[i];
  4751. function wrap(imgsrc){return function(){ShowBigImage(imgsrc, 1);}}
  4752. img.addEventListener("click", wrap(img.dataset.imgsrc));
  4753. }
  4754. document.images_filtered = images_filtered;
  4755. function PopGalleryHistory(){
  4756. if(pushed){
  4757. pushed = 0;
  4758. try{
  4759. history.back();
  4760. }catch{
  4761. console.log("can't do it.");
  4762. }
  4763. }
  4764. }
  4765. function PushGalleryHistory(src){
  4766. abs_img = window.location.protocol+"//"+window.location.host+'/'+src
  4767. title = "照片"
  4768. extra = "?";
  4769. sp = new URLSearchParams(window.location.search)
  4770. if(sp.has('post')){extra+="post="+sp.get('post')}
  4771. if(sp.has('gallery')){extra+="&gallery="+sp.get('gallery')}
  4772. try{
  4773. window.history.pushState('&pic='+src, 'Title', extra+'&pic='+src);
  4774. }catch{
  4775. console.log("can't do it.");
  4776. }
  4777. pushed = 1;
  4778. }
  4779. document.addEventListener('keydown', function(e){
  4780. large = document.getElementById('big_image_overlay')
  4781. if (large.style.display!='block') return;
  4782. if(e.key=='Escape'||e.key=='Esc'||e.keyCode==27){
  4783. HideBigImage(1);
  4784. }
  4785. }, true);
  4786. window.addEventListener('popstate', (event) => {
  4787. if(event.state){
  4788. let sp = new URLSearchParams(event.state)
  4789. if(sp.has('pic')){
  4790. src = sp.get('pic')
  4791. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)) ShowBigImage(onlyimg[0], 0);
  4792. else{HideBigImage(0);}
  4793. }
  4794. }else{HideBigImage(0);}
  4795. });
  4796. let searchParams = new URLSearchParams(window.location.search)
  4797. if(searchParams.has('pic')){
  4798. src = searchParams.get('pic')
  4799. if(onlyimg = src.match(/[0-9]{14,}.(jpg|png|jpeg|gif)/u)){
  4800. ShowBigImage(onlyimg[0], 1);
  4801. }
  4802. }
  4803. function _dropHandler(event){ if (typeof dropHandler === "function") dropHandler(event); }
  4804. function _dragOverHandler(event){ if (typeof dragOverHandler === "function") dragOverHandler(event); }
  4805. </script>
  4806. </body>
  4807. <?php
  4808. }
  4809. function DoIdentiyExperimental(){
  4810. if(isset($this->ExpHost) && $this->ExpHost && preg_match('/'.preg_quote($this->ExpHost).'/u', $_SERVER['HTTP_HOST'])){
  4811. $this->InExperimentalMode=True; $this->InHereMode=True;
  4812. }
  4813. if(isset($this->HereHost) && $this->HereHost && preg_match('/'.preg_quote($this->HereHost).'/u', $_SERVER['HTTP_HOST'])){
  4814. $this->InHereMode=True;
  4815. }
  4816. }
  4817. function DoExperimentalTopLink($p){
  4818. if($this->InHereMode && $p){
  4819. if(isset($p['tid']) && $p['tid']['first']!=$p){
  4820. header('Location: ?post='.$p['tid']['first']['id']); exit();
  4821. }
  4822. }
  4823. }
  4824. function MakeExperimentalConfirm(){
  4825. if(isset($_COOKIE['la_experimental']) && $_COOKIE['la_experimental'] == 'confirmed'){
  4826. return false;
  4827. }
  4828. $caution_html =
  4829. $confirm = "<a class='text_highlight clean_a bold' href='index.php?confirm_enter=1".
  4830. (isset($this->CurrentPostID)?("&post=".$this->CurrentPostID):"").
  4831. "'>&nbsp;&nbsp;".$this->T('继续')."&nbsp;&nbsp;</a>";
  4832. ?>
  4833. <div class='center_exp'><?php
  4834. if(isset($this->ExpCaution) && ($p=$this->GetPost($this->ExpCaution,true)))$this->MakeSinglePostExp($p);
  4835. else echo "<li class='post post_dummy'>".$this->TranslatePostParts("<h1>注意</h1><p>您将进入实验站。</p>")."</li>";
  4836. ?></div>
  4837. <div class='center_exp'><li class='post post_dummy'><p><?=$confirm?></p></li></div>
  4838. <?php return true;
  4839. }
  4840. }
  4841. $la = new LA;
  4842. $la->DoSiteRedirect();
  4843. $la->DoLogin();
  4844. $la->SwitchLanguageAndFont();
  4845. $err = $la->ProcessRequest($message, $redirect);
  4846. $la->WriteAsNecessary();
  4847. $la->DoIdentiyExperimental();
  4848. $la->SwitchWayBackMode();
  4849. if($err){
  4850. echo $message;
  4851. exit();
  4852. }
  4853. if(isset($redirect)){
  4854. header('Location: '.$redirect);
  4855. exit();
  4856. }
  4857. $la->DetectPageType();
  4858. $la->ReadImages(false);
  4859. $la->ReadPosts();
  4860. if(isset($la->WayBack)){
  4861. $la->ReadArchive();
  4862. }
  4863. $im = NULL;
  4864. if(preg_match('/images\/(.*)/u',$la->HereID,$imname) && ($im = &$la->FindImage($imname[1]))){
  4865. if(!$la->CanShowImage($im)) { $im=NULL; }
  4866. }
  4867. $p = &$la->GetPost($la->CurrentPostID);
  4868. if(!isset($p)){
  4869. $p = &$la->GetMergedPost($la->CurrentPostID);
  4870. }
  4871. if(isset($p) && !$la->CanShowPost($p)) $p=NULL;
  4872. else{ $la->DoExperimentalTopLink($p); }
  4873. if(isset($p)){ $la->ActualPostID = $p['id']; }
  4874. if($la->PageType=='here' ||$la->PageType=='experimental'){
  4875. if($im){
  4876. $la->SetHereMainImage($im);
  4877. $la->RecordVisitedHere($im['name'],$im?$la->ImageTitle($im):NULL);
  4878. }else if($p){
  4879. $la->RecordVisitedHere($p['id'],NULL);
  4880. }else {
  4881. $im = &$la->GiveImageInHere(false);
  4882. if($im){
  4883. $la->SetHereMainImage($im);
  4884. $la->RecordVisitedHere($im['name'],$la->ImageTitle($im));
  4885. }
  4886. }
  4887. }
  4888. $la->MakeHeader($p);
  4889. $la->MakeMainBegin();
  4890. if($la->PageType=='here' ||$la->PageType=='experimental'){
  4891. if(($la->PageType=='experimental' && (!$la->MakeExperimentalConfirm())) || $la->PageType=='here'){
  4892. if($im){
  4893. $la->MakeHereSection($im);
  4894. }else if($p){
  4895. $la->MakePostSectionExp($p);
  4896. $la->MakeLinkedPostsExp($p);
  4897. }else {
  4898. if($im){
  4899. $la->MakeHereSection($im);
  4900. }else{
  4901. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4902. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4903. }
  4904. }
  4905. }
  4906. $la->MakeMainEnd();
  4907. $la->MakeExpFooter();
  4908. }else{
  4909. if($la->PageType=='extras'){
  4910. $la->MakeExtraOperations();
  4911. }else if($la->PageType=='settings'){
  4912. $la->MakeSettings();
  4913. }else if($la->PageType=='gallery'){
  4914. $la->MakeGalleryLeft();
  4915. $la->MakeGallerySection();
  4916. }else if($la->PageType=='post'){
  4917. if($p){
  4918. $made_interesting = false;
  4919. if($la->IsInterestingPost($p)){
  4920. $la->MakeInterestingSection($p['tid']);
  4921. }
  4922. else{
  4923. $la->MakeLinkedPosts($p);
  4924. $la->MakePostSection($p);
  4925. $la->MakeTOC();
  4926. }
  4927. }else{
  4928. echo "<h2>".$la->T('未找到这个帖子')."</h2><p>".$_SERVER['REQUEST_URI'].
  4929. "</p><p><a href='index.php'>".$la->T('返回首页')."</a></p><br />";
  4930. }
  4931. }else if($la->PageType=='history'){
  4932. $la->ReadArchive();
  4933. $la->MakePostHistory($p, $_GET['version']??NULL);
  4934. }else if($la->PageType=='search'){
  4935. $la->MakeHotPosts(true);
  4936. $la->MakeRecentPosts($_GET['search']);
  4937. }else if($la->PageType=='category'){
  4938. $la->MakeHotPosts(true);
  4939. $la->MakeRecentPosts(NULL,$_GET['category']);
  4940. }else if($la->PageType=='comments'){
  4941. $la->MakeCommentPosts();
  4942. }else{
  4943. $la->MakeHotPosts();
  4944. $la->MakeRecentPosts();
  4945. }
  4946. $la->MakeMainEnd();
  4947. $la->MakeFooter();
  4948. }
  4949. ?>