*/}}

index.php 249 KB

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