*/}}

index.php 248 KB

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