転載・引用について

ユーザ用ツール

サイト用ツール


tweet

つぶやき

技術系や雑感等は再編集して本文の記事にする事を前提としているので、こっちにLinkを張らないでください。

My access counter

view counterをInstallしたが、色々気に入らないので、まずはcounterを直してみた。

方針は、

  1. 今日のunique viewerの表示 → 1
  2. 今日のall viewerの表示 → 2
  3. 今までのunique viewerの合計 → 3
  4. 今までのviewerの合計 → 4

を表示すること。

高々これだけでも結構面倒。少しPHPを勉強する気になった。

以下、Install方法

  1. [DokuWiki Data Dir]/pages/_views を作成(普通は[DokuWiki Dir]/data/_viewだろう)
    • Ownerをuser.wwwにするならpermissionを775に www.wwwなら755にする
    • ここに各namespace毎の参照記録が配置される
    • file formatは以下の通り
      • Filename: namespace
      • Data Format: 1 2 3 4 Today ¥n <IP Address>¥n….
  2. [DokuWiki Dir]/inc/counter.phpを設置
    • <?php
       
      /* 
       * DokuWiki Counter
       * Original: Dokuwiki:plugins:viewcounter
       * Revised by seirios@seirios.org.
       * log: 2009/02/07 First Revision
       *
       * Function: Print view counter of followings.
       *     - Today's unique viewers
       *     - Today's all viewers
       *     - Total of "Today's unique viewers"
       *     - Total viewers
      */
       
      global $ID, $ACT;
      $views_str    = "views";
      $myip         = "<".$_SERVER["REMOTE_ADDR"].">";
      $ips          = "";
      $unique       = true;
      $todayviews   = 1;
      $utodayviews  = 1;
      $allviews     = 1;
      $uallviews    = 1;
      $d            = date("Ymd");
       
      $file = realpath($conf["datadir"])."/_views/".$ID;
       
      if (file_exists($file)) {
          $content = file_get_contents($file);
          $pos  = strpos($content, " ");
      
          if ($pos !== FALSE) {
              $todayviews  = substr($content, 0, $pos);
              $str         = substr($content, $pos + 1);
              $pos         = strpos($str, " ");
              $utodayviews = substr($str, 0, $pos);
              $str         = substr($str, $pos + 1);
              $pos         = strpos($str, " ");
              $allviews    = substr($str, 0, $pos);
              $str         = substr($str, $pos + 1);
              $pos         = strpos($str, " ");
              $uallviews   = substr($str, 0, $pos);
              $str         = substr($str, $pos + 1);
              $pos         = strpos($str, " ");
      
              if ($pos !== FALSE) {
                  $old_d = substr($str, 0, $pos);
                  $ips   = substr($str, $pos + 1);
      
                  if ($old_d != $d) {
                      $todayviews  = 1;
                      $utodayviews = 1;
                      $ips   = "";
                  } else if (strpos($ips, $myip) !== FALSE) {
                      ++$todayviews;
                      ++$allviews;
                      $unique = FALSE;
                  } else {
                      ++$todayviews;
                      ++$utodayviews;
                      ++$allviews;
                      ++$uallviews;
                  }
              }
          }
      }
      
      if (($ACT == "show") && ($INFO["exists"])) {
          if ($unique !== FALSE) {
              $ips.="\n".$myip;
          }
      
          $content = $todayviews." ".$utodayviews." ".$allviews." ".$uallviews." ".$d." ".$ips;
          file_put_contents($file, $content);
      }
      
      $fn.=" : Counter: ($todayviews / $utodayviews / $allviews / $uallviews $views_str) ";
      
      ?>
            
  1. [DokuWiki Dir]/inc/template.phpを修正
    • 以下のpatchを適用する
    • # diff -c ./template.php.orig ./template.php
      *** ./template.php.orig Sat Feb  7 14:15:51 2009
      --- ./template.php      Sat Feb  7 14:36:51 2009
      ***************
      *** 945,950 ****
      --- 945,951 ----
        
          // print it
          if($INFO['exists']){
      +     include("counter.php");
            $out = '';
            $out .= $fn;
            $out .= ' &middot; ';
      
            

取りあえずこれだけで最小限のカウンターが、ページ最下部に表示されます。

このカウンターでは、ちっとも目立たないので、そこをどう修正するかが今後の検討課題ですね。

· 2018/07/02 19:01 · 2009/02/07 03:00

Access Counter

DokuWikiにAccess Counterを追加してみる。

追加したのはviewcounter。

  1. data/pages/_cacheを作成。
    • permissionを775にしておく。Ownerをuser.wwwにする
  2. inc/template.phpを修正
    • 個人的には、ここが気に入らないが、仕方がない。
      • $ diff -c inc/template.php.orig inc/template.php
        *** inc/template.php.orig Sat Feb  7 14:15:51 2009
        --- inc/template.php      Sat Feb  7 14:18:46 2009
        ***************
        *** 927,932 ****
        --- 927,935 ----
            global $INFO;
            global $REV;
            global $ID;
        + /* for access counter */
        +   global $ACT;
        + /* ------------------ */
          
            // return if we are not allowed to view the page
            if (!auth_quickaclcheck($ID)) { return false; }
        ***************
        *** 940,945 ****
        --- 943,963 ----
                $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
              }
            }
        +   /* for access counter */
        +   $ID_fn = str_replace(':', '_', $ID); 
        +   $fp_views=fopen(realpath($conf['datadir'])."/_cache/$ID_fn.visits",'a+'); 
        +   if ($fp_views) { 
        +     fscanf($fp_views,"%i",$views); 
        +     if (($ACT == 'show') && ($INFO['exists'])) { 
        +       $views++; 
        +       ftruncate($fp_views,0); 
        +       fseek($fp_views, 0); 
        +       fwrite($fp_views,$views); 
        +     } 
        +     $fn.=" ($views views) "; 
        +     fclose($fp_views); 
        +   } 
        +   /* ------------------ */
            $fn = utf8_decodeFN($fn);
            $date = strftime($conf['dformat'],$INFO['lastmod']);
                

→ 続き...

· 2018/07/02 19:01 · 2009/02/07 02:00

Blikiのformat

Blikiの表示フォーマットをいじってみる。
本質的にはPHPのdate関数と同じ形式でいける模様。

というわけで、日付の表示を yyyy/mm/dd (曜日)形式にしてみた。
この方が見やすいのは慣れの問題なんだろうけど。

いじり方は、conf/local.phpの

$conf['bliki']['dateheader'] = '===== l,F j =====';

の部分を

$conf['bliki']['dateheader'] = '===== Y/m/d (D) =====';

に直しただけ。 ついでにFooterを

$conf['bliki']['footer'] = '<sub>Posted @ {timestamp} -- [[{permalink}|Permalink]] -- [[{edit}|Edit]]</sub>';

になおしておくと、余計な文字列が表示されない。

問題は、timestampのフォーマットだけど、今はここまではいいや。

· 2018/07/02 19:01 · 2009/02/07 01:00

DokuWiki

今頃になって、DokuWikiのPlug-insに関して色々判ってないことが判明。
というわけで、これからじっくりと「Plug-Inに関してDocumentを読む」という作業が必要なようだ。

今一番気になっているのが、Blikiの末尾に¥n¥nが表示されること。この理由が今はちっともわからない。
そのほかにも、Tagの問題だとか、TOCの問題だとか、結構色々やりたいことはある。

加えて、Style Sheetも作りたいしね。

最大の問題は、それだけの時間を確保することなんだけど…

· 2018/07/02 19:01 · 2009/02/06 05:00

BlikiのInstall

BlikiはDokuWikiのPlug-inのなかでもちょっと変わったInstallをする。

  1. Lib/plugins/bliki/Syntax.phpをCut&Pasteで作成
  2. conf/local.phpに設定をCut&Pasteで作成
    • $conf['bliki']['structure'] = 'flat';
      $conf['bliki']['offset'] = '0';
      $conf['bliki']['numposts'] = '5';
      $conf['bliki']['dateheader'] = '===== Y/m/d (D) =====';
      $conf['bliki']['datefooter'] = 'Y/m/d g:ia';
      $conf['bliki']['footer'] = '<sub>Posted @ {timestamp} -- [[{permalink}|Permalink
      ]] -- [[{edit}|Edit]]</sub>';
      $conf['bliki']['newlabel'] = '&raquo; New Post';
      $conf['bliki']['olderlabel'] = 'Older Posts &raquo;';
      $conf['bliki']['newerlabel'] = '&laquo; Newer Posts';
            
  3. lib/styles/style.cssに新たなスタイルをCut&Pasteで作成
    • #blognew {
        font-size: 120%;
        padding: 0.5em;
        display: block;
        width: 6.5em;
        text-align: center;
        border: 1px solid #8CACBB;
        background: #DEE7EC;
      }
       
      #blognew A {
        color: #000000;
        font-weight: bold;
      }
       
      #blogolder, #blognewer {
        border: solid 1px #8cacbb;
        padding: 0.5em;
      }
       
      #blogolder {
        float: right;
      }
       
      #blognewer {
        float: left;
      }
            

だって。 きっと忘れるからメモしておく

· 2018/07/02 19:01 · 2009/02/06 04:00
このウェブサイトはクッキーを使用しています。 Webサイトを使用することで、あなたはあなたのコンピュータにクッキーを保存することに同意します。 また、あなたはあなたが私たちのプライバシーポリシーを読んで理解したことを認めます。 同意しない場合はウェブサイトを離れてください。クッキーに関する詳細情報
tweet.txt · 最終更新: by seirios

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki