linux.org.py
inicio foro listas mirrors i-fest wiki
 

Hit Counter for Dokuwiki

Credits

Changes

New in this version against the erazor-zone.de version:

  • support for file_put_contents in php4
  • infinite loop check
  • code clean up
  • tested in dokuwiki 2006-11-06 on CentOS 4.4

About

I modified the erazor-zone.de version to be used in php4 and added a few file checks.
You can contact me here: http://tinymailto.com/oliver

Installation instructions:

Steps for installing the hit counter patch:

  • create the directory /dokuwiki/data/pages/_views
  • make sure /dokuwiki/data/pages/_views is owned by the webserver user
    chown apache.apache -R /dokuwiki/data/pages/_views
  • create the file /dokuwiki/inc/counter.php and put this code in there:
    <?php
     
    /*
     *  Simulating PHP5's file_put_contents() function in PHP 4.3.9 (Centos 4.4)
     *  Contact e-mail in: http://tinymailto.com/oliver
     */
    function file_put_contents_counter($file, $views) {
      $written = false;
      if( $fp_counter = fopen($file, 'w') ) {
        // lock before writting
        if (flock($fp_counter, LOCK_EX)) {
          $written = fwrite($fp_counter, $views);
          flock($fp_counter, LOCK_UN);
        }
        fclose($fp_counter);
      }
      if($written === FALSE) {
        return 0;
      }
      else {
        return $written;
      }
    }
     
    global $ID,$ACT;
     
    // local variables
    $file = "";
    $views = false;
    $read_tries = 3;
    $read_count = 0;
    $written=0;
    $write_tries = 3;
    $write_count = 0;
     
    $file=realpath($conf['datadir']).'/_views/'.$ID;
     
    if (file_exists($file)) {
      while ($views===FALSE) {
        $views=file_get_contents($file);
        if ($views===FALSE) {
          usleep(50000);
        }
        $read_count++;
        if($read_count > $read_tries) {
          $views = 0;
          break;
        }
      }
      $views = intval($views) + 1;
    } else {
      $views=1;
    }
     
    if (($ACT == 'show') && ($INFO['exists'])) {
      while(!$written) {
        $written=file_put_contents_counter($file,$views);
        // for php5 use this line
        //$written=file_put_contents($file,$views);
        if (!$written) {
          usleep(50000);
        }
        $write_count++;
        if($write_count > $write_tries) {
          break;
        }
      }
    }
     
    $fn.=" ($views views) ";


  • edit /dokuwiki/inc/template.php around line 741, and add these 2 lines:


 740   // print it
 741   if($INFO['exists']){
 +742     // counter
 +743     include('counter.php');
 744     print $fn;
 
howto/dokuwiki_hit_counter_patch.txt (68 visitas) · Última modificación: 2006/11/23 10:54 por oliversl



 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki