*/}}
Browse Source

statistics

YimingWu 11 months ago
parent
commit
981929af71
2 changed files with 100 additions and 15 deletions
  1. 96 15
      index.php
  2. 4 0
      translations.md

+ 96 - 15
index.php

@@ -791,7 +791,6 @@ animation:anim_loading 1s linear infinite;}
 width:2em;height:2em;display:block;border:1px solid %black%;background-color:rgba(0,0,0,0.5);}
 .round_btn{box-shadow: 0px 0px 0px 1px inset %black%;display:inline-block;padding-left:0.4em;padding-right:0.4em;border-radius:0.5em;}
 
-
 @media screen and (max-width:1000px) and (min-width:666px){
 .left{width:35%;}
 .center,.center_wide{width:65%;}
@@ -1228,9 +1227,10 @@ blockquote{border-left:2px solid black;}
             }
             $base = 'images/'.$num;
             $thumb = 'images/thumb/'.$num;
-            $final_path = $base.'.jpg'; $final_thumb = $thumb.'.jpg'; $i=0;
+            $use_ext=($ext=='gif' || $ext=='mp4')?('.'.$ext):('.jpg');
+            $final_path = $base.$use_ext; $final_thumb = $thumb.$use_ext; $i=0;
             if(!$replace) while(file_exists($final_path)){
-                $final_path = $base.strval($i).'.jpg'; $final_thumb = $thumb.strval($i).'.jpg'; $i++;
+                $final_path = $base.strval($i).$use_ext; $final_thumb = $thumb.strval($i).$use_ext; $i++;
             }
             if($ext!='gif' && $ext!='mp4'){
                 $compress = (isset($_GET['compress'])&&$_GET['compress']);
@@ -2196,6 +2196,8 @@ blockquote{border-left:2px solid black;}
             else if(isset($_GET['pic'])) $str.='&pic='.$_GET['pic'];
         if(isset($args['settings'])) $str.='&settings='.$args['settings'];
             else if(isset($_GET['settings'])) $str.='&settings='.$_GET['settings'];
+        if(isset($args['statistics'])) $str.='&statistics='.$args['statistics'];
+            else if(isset($_GET['statistics'])) $str.='&statistics='.$_GET['statistics'];
         if(isset($args['extras'])) $str.='&extras='.$args['extras'];
             else if(isset($_GET['extras'])) $str.='&extras='.$_GET['extras'];
         if(isset($args['category'])) $str.='&category='.$args['category'];
@@ -2756,10 +2758,10 @@ blockquote{border-left:2px solid black;}
                 $this->NeedWriteImages = 1;
                 if($do_image_redirect) return 0;
             }
-            if(isset($_GET['rewrite_styles'])){
+            //if(isset($_GET['rewrite_styles'])){
                 $this->WriteStyles();
-                $redirect='?extras=true'; return 0;
-            }
+            //    $redirect='?extras=true'; return 0;
+            //}
             if(isset($_GET['regenerate_thumbnails'])){
                 $this->RegenerateThumbnails();
                 $redirect='?extras=true'; return 0;
@@ -2898,6 +2900,7 @@ blockquote{border-left:2px solid black;}
         else if(isset($_GET['category'])) $this->PageType='category';
         else if(isset($this->CurrentPostID)) $this->PageType = "post";
         else if(isset($_GET['comments'])) $this->PageType='comments';
+        else if(isset($_GET['statistics'])) $this->PageType='statistics';
         else $this->PageType = "main";
         
         $visited_here = $this->InExperimentalMode?"visited_experimental":"visited_here";
@@ -2986,7 +2989,7 @@ blockquote{border-left:2px solid black;}
             $this->MakeExpNavButtons($p);
         }else{
             $this->MakeNavButtons($p);
-            if(isset($p['tid']['header'])){ ?><div style='float:right' class='show_on_print'><?=$p['tid']['header'];?></div><?php }
+            if(isset($p['tid']['header'])){ ?><div style='float:right' class='show_on_print'><?=$this->ChoosePartsByLanguage($p['tid']['header']);?></div><?php }
             echo "<hr class='hidden_m'>";
         } ?>
         <?php if(isset($this->WayBack)){
@@ -3112,8 +3115,8 @@ blockquote{border-left:2px solid black;}
             <li class='hidden_on_desktop_force block_m smaller'>&nbsp;</li>
             <li class='hidden_on_desktop_force block_m bigger'>
                 <a href='index.php?part=recent' onclick='ShowWaitingBar()'><?=$this->T('最近')?></a>
-                <?php if($this->LoggedIn){ ?>
-                    | <span class='gray invert_a'><a href='index.php?comments=all'>@</a></span><?php } ?></li>
+                <?php if($this->LoggedIn){ ?> | <span class='gray invert_a'>
+                    <a href='index.php?comments=all'>@</a> <a href='index.php?statistics=all'>%</a></span><?php } ?></li>
             <li class='hidden_on_desktop_force block_m bigger'>
                 <a href='index.php?gallery=default' onclick='ShowWaitingBar()'><?=$this->T('画廊')?></a></li>
             <?php $this->SpecialNavigation;if(isset($this->SpecialNavigation) && ($p = &$this->GetPost($this->SpecialNavigation))!=NULL){
@@ -3242,7 +3245,7 @@ blockquote{border-left:2px solid black;}
         $mark_value = isset($post['mark_value'])?$this->Markers[$post['mark_value']]:-1;
         $ref_count = isset($post['refs'])?sizeof($post['refs']):0;
         $is_product = isset($post['mark_value'])&&$post['mark_value']==5;
-        $title = $generate_anchor?$this->GetPostTitle($post, true):NULL;
+        $title = $generate_anchor?$this->ChoosePartsByLanguage($this->GetPostTitle($post, true)):NULL;
         $this->ConvertPost($post);// NEEDED FOR WIDE;
         $is_wide = (isset($post['wide'])&&$post['wide']) || (isset($post['tid']) && isset($post['tid']['wide']) && $post['tid']['wide']);
         ?>
@@ -3352,7 +3355,7 @@ blockquote{border-left:2px solid black;}
     }
     
     function MakeRecentPosts($search_term=NULL, $category=NULL){?>
-        <div class='center' id='div_center'><div><br /></div>
+        <div class='center' id='div_center'><br class='hidden_on_print' />
             <?php if(!isset($search_term) && !isset($category) &&
                    (isset($this->SpecialPinned) && ($p = &$this->GetPost($this->SpecialPinned))!=NULL && !$this->CurrentOffset) &&
                    $this->CanShowPost($p)){
@@ -3364,7 +3367,7 @@ blockquote{border-left:2px solid black;}
                                 (isset($category)?("<span class='gray'>".$this->T('分类')."</span> ".
                                     ($category=='none'?$this->T('未分类'):$this->T($category))):($this->T('最近')).
                                     " <span class='gray invert_a hidden_on_print'>".//"<a href='index.php?&set_wayback=true'>↶</a>".
-                                    ($this->LoggedIn?"<a href='index.php?comments=all'>@</a>":"")."</span>")?></h2><br />
+                                    ($this->LoggedIn?"<a href='index.php?comments=all'>@</a> <a href='index.php?statistics=all'>%</a>":"")."</span>")?></h2><br />
             <?php if(isset($search_term)){ ?>
                 <form action="index.php" method="post" style='display:none;' id='search_form'></form>
                 <input id="search_content" name="search_content" rows="4" form='search_form' type='text' value='<?=$search_term?>'>
@@ -3748,7 +3751,7 @@ blockquote{border-left:2px solid black;}
     function MakePostSection(&$post){
         $this->Anchors = [];
         if(isset($this->TagID)){ ?><style><?=$this->CssNumberID($this->TagID);?>{display:block;}</style><?php } ?>
-        <div class='center' id='div_center'><div><br /></div>
+        <div class='center' id='div_center'><br class='hidden_on_print' />
             <h2 class='hidden_on_print'>
             <?php $th=NULL; $is_thread = isset($post['tid']['count'])&&$post['tid']['count']>1;
                 $is_wide = (isset($post['wide'])&&$post['wide']) || ($is_thread && isset($post['tid']['wide']) && $post['tid']['wide']);
@@ -3810,7 +3813,7 @@ blockquote{border-left:2px solid black;}
     function MakePostSectionExp(&$post){
         $this->Anchors = []; $is_thread = isset($post['tid']);
         ?>
-        <div class='center_exp' id='div_center'><div><br /></div>
+        <div class='center_exp' id='div_center'><br class='hidden_on_print' />
             <ul>
             <?php $is_reversed=false;
                 if($is_thread){ $th = &$post['tid'];$use_arr = $th['arr']; $is_reversed=$this->IsReversedThread($th); $hinted=false;
@@ -4157,7 +4160,7 @@ blockquote{border-left:2px solid black;}
         <script>
         document.title+=" | <?=$this->T('画廊')?>";
         </script>
-        <div class='center_wide' id='div_center' style='position:relative;'><div><br /></div>
+        <div class='center_wide' id='div_center' style='position:relative;'><br class='hidden_on_print' />
             <h2><?=(isset($name) && ($gal=$this->GetGallery($name))!=NULL)?
                                     ("<span class='gray album_hint'>".$this->T('相册').":</span>".$this->T($name)):
                                     ($_GET['gallery']=='trash'?$this->T('垃圾桶'):$this->T('画廊'))?></h2>
@@ -4368,6 +4371,82 @@ blockquote{border-left:2px solid black;}
         </div>
     <?php
     }
+    
+    function MakeStatistics(){
+        $this->ReadPosts(); $this->ReadImages(); $this->ReadArchive();
+        $list=[]; $last_date=null; $info=[]; $info['count']=0; $info['edits']=0; $info['length']=0;
+        $imlist=[]; $imlast_date=null; $iminfo=[]; $iminfo['count']=0;
+        $maxposts=0; $maxlength=0; $maximages=0;
+        foreach($this->Posts as &$p){ $is_ref=0;
+            $this_date=substr($p['id'],0,8);
+            if($last_date!=null && $last_date!=$this_date){
+                if($maxposts<$info['count']+$info['edits'])$maxposts=$info['count']+$info['edits'];
+                if($maxlength<$info['length'])$maxlength=$info['length'];
+                $list[]=$info; $info=[]; $info['count']=0; $info['edits']=0; $info['length']=0;
+            }
+            $ah = &$this->GetArchiveHandle($p['id']); if(isset($ah)&&isset($ah['list'][0])) $info['edits']+=count($ah['list']);
+            $info['count']++; $info['id']=$this_date; if(isset($p['content']))$info['length']+=strlen($p['content']); $last_date=$this_date;
+        }
+        $last_date=null;
+        foreach($this->Images as &$im){ $is_ref=0;
+            $this_date=substr($im['name'],0,8);
+            if($last_date!=null && $last_date!=$this_date){
+                if($maximages<$iminfo['count'])$maximages=$iminfo['count'];
+                $imlist[]=$iminfo; $iminfo=[]; $iminfo['count']=0;
+            }
+            $iminfo['count']++; $iminfo['id']=$this_date; $last_date=$this_date;
+        }
+        if($info!=[]) $list[]=$info;
+        if($iminfo!=[]) $imlist[]=$iminfo;
+        if(!isset($list[0])) return;
+        $earliest=DateTimeImmutable::createFromFormat('!Ymd',$list[0]['id']); $ey=substr($list[0]['id'],0,4);
+        $latest=DateTimeImmutable::createFromFormat('!Ymd',end($list)['id']); $ly=substr(end($list)['id'],0,4);
+        $days=$earliest->diff($latest)->days; $lw=2.0; $dw=$days*$lw; $spw=20;
+        ?>
+        <style>.stastics_posts{direction:ltr;} .stastics_posts line,.stastics_posts circle{stroke:#f8ca9b; stroke-width:2px;}
+        .stastics_posts .line_edits{stroke:#f8ca9b40;}
+        .stastics_posts .line_year{stroke:#f8ca9b30; stroke-width:2px;} .stastics_posts text{fill:#f8ca9ba0; font: 0.9em serif;}
+        </style>
+        <div class='settings'><h2><?=$this->T('统计')?></h2><br />
+            <div style="overflow:auto;direction:rtl;width:100%;">
+            <svg class='stastics_posts' viewBox="-<?=$spw?> -<?=$spw?> <?=$days*$lw+$spw*6?> <?=200+4*$spw?>" height="<?=200+4*$spw?>" width="<?=$days*$lw+$spw*6?>">
+            <?php foreach($list as $info){ $itv=DateTimeImmutable::createFromFormat('!Ymd',$info['id'])->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);
+                $p1=100.0*(1-$info['count']/$maxposts); $p2=$p1-100.0*$info['edits']/$maxposts;
+                $p3=100.0*$info['length']/$maxlength+$spw+100; ?>
+                <line x1="<?=$ds?>" x2="<?=$ds?>" y1="100.0" y2="<?=$p1?>"/>
+                <?php if($info['edits']>0){ ?><line class='line_edits' x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=$p1?>" y2="<?=$p2?>"/><?php } ?>
+                <?php if($info['length']>0){ ?><line class='line_edits' x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=$spw+100?>" y2="<?=$p3?>"/><?php } ?>
+            <?php } ?>
+            <?php foreach($imlist as $im){ $itv=DateTimeImmutable::createFromFormat('!Ymd',$im['id'])->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);
+                $p1=100+$spw+100.0*($im['count']/$maximages); ?>
+                <circle cx="<?=$ds?>" cy="<?=$p1?>" r='3'/>
+            <?php } ?>
+            <?php for($y=$ey;$y<=$ly;$y++){ $itv=DateTimeImmutable::createFromFormat('!Y',$y)->diff($earliest); $ds=$lw/2+$lw*$itv->days*($itv->invert?1:-1);?>
+                <line x1="<?=$ds?>" x2="<?=$ds?>" y1="<?=220+$spw?>" y2="-<?=$spw?>" class='line_year'/>
+                <text x="<?=$ds+4?>" y="-4"><?=$y?></text>
+                <text x="<?=$ds+4?>" y="<?=$spw*2+200-4?>"><?=$y?></text>
+                <?php for($ym=1;$ym<=12;$ym++){ $st=str_pad($ym,2,'0',STR_PAD_LEFT); $itv2=DateTimeImmutable::createFromFormat('!Ym',$y.$st)->diff($earliest);
+                    $dds=$lw/2+$lw*$itv2->days*($itv2->invert?1:-1); if($dds<0||$dds>$lw/2+$dw) continue; ?>
+                    <line x1="<?=$dds?>" x2="<?=$dds?>" y1="<?=100+$spw?>" y2="100" class='line_year'/>
+                    <text x="<?=$dds+4?>" y="<?=100+$spw-3?>"><?=$ym?></text>
+            <?php } } ?>
+            <line x1="<?=$lw/2+$dw?>" x2="<?=$days*$lw?>" y1="<?=220+$spw?>" y2="-<?=$spw?>" class='line_year'/>
+            <line x1="0" x2="<?=$dw?>" y1="0" y2="0" class='line_year'/>
+            <line x1="0" x2="<?=$dw?>" y1="100" y2="100" class='line_year'/>
+            <line x1="0" x2="<?=$dw?>" y1="<?=100+$spw?>" y2="<?=100+$spw?>" class='line_year'/>
+            <line x1="0" x2="<?=$dw?>" y1="<?=200+$spw?>" y2="<?=200+$spw?>" class='line_year'/>
+            <text x="<?=$dw+10?>" y="8"><?=$maxposts?></text>
+            <text x="<?=$dw+10?>" y="<?=$spw+8?>"><tspan style='fill:#f8ca9b;'>▪ <?=$this->T('新增')?></tspan></text>
+            <text x="<?=$dw+10?>" y="<?=$spw*2+8?>"><tspan style='fill:#f8ca9ba0;'>▪ <?=$this->T('改动')?></tspan></text>
+            <text x="<?=$dw+10?>" y="<?=$spw*2+200-4?>"><?=$maxlength?></text>
+            <text x="<?=$dw+10?>" y="<?=$spw+200-4?>"><tspan style='fill:#f8ca9b;'><?=$maximages?></tspan></text>
+            <text x="<?=$dw+10?>" y="<?=200-4?>"><tspan style='fill:#f8ca9b;'>▪ <?=$this->T('媒体')?></text>
+            <text x="<?=$dw+10?>" y="<?=200-4-$spw?>">▪ <?=$this->T('长度')?></tspan></text>
+            </svg></div>
+            <br /><br />
+        </div>
+    <?php
+    }
 
     function MakeSettings(){?>
         <div class='settings'>
@@ -5398,6 +5477,8 @@ if($la->PageType=='here' ||$la->PageType=='experimental'){
         $la->MakeRecentPosts(NULL,$_GET['category']);
     }else if($la->PageType=='comments'){
         $la->MakeCommentPosts();
+    }else if($la->PageType=='statistics'){
+        $la->MakeStatistics();
     }else{
         $la->MakeSidebar();
         $la->MakeRecentPosts();

+ 4 - 0
translations.md

@@ -204,4 +204,8 @@
 - 相册单步 | Gallery Step
 - 查看更多 | Load more
 - 没有更多的了 | No more images
+- 统计 | Statistics
+- 新增 | New
+- 改动 | Edits
+- 媒体 | Media