A variation on the counter.php

1° add in the database 2 columns
first field: Speed, Float , 20 is actually a number that shows the 'current' speed of views, expressed by pages per year
second field: Speeddate is the last date the page has been viewed by someone

Ok its the bowen counter.php modified with selecting the two extra parameters
and a speedcalculation, thast a kind of exponantial smoothing and is subsequently stored with the page.

 // Paul Larmuseau code
 // create speeddate as DATETIME variable !!
 // Get hit count, could be integrated as functions in Wikka, as to minimize reads, should be function GetSpeeddate() GetSpeed()
 $result2 = mysql_query( "SELECT hits,speeddate,speed FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='Y'" );
 $row2 = mysql_fetch_array($result2);
 $hit_count1 = $row2[hits];
 // Count is incremented if not your own page (thats bowen code transformed here)
 if ($this->GetUserName() != $this->GetPageOwner($tag))
      // End Get hit Count   Start adding hits
      $hit_count2 = $hit_count1 + 1;
      // speed tuning, here it takes one hour as minimum
          $newspeed= $row2[speed]*0.8+365*24*60*60/(time()-strtotime($row2[speeddate]))*0.2;
         }       else {
           $newspeed= $row2[speed]*0.8+365*24*0.1+$hit_count2*365*24*60*60/(time()-strtotime($this->GetPageTime()))*0.1;

      // End adding hits   Start Update Hit
      $sql = "UPDATE `".$this->config["table_prefix"]."pages` SET hits=$hit_count2,speeddate=now(),speed=$newspeed WHERE tag='$thispage' AND latest='Y'";
      // $sql .= " WHERE `ref` = $ref";
      mysql_query($sql) or die("Unable to process query: " . mysql_error());
// End Update Hit

// parameter show="off" or "no" being checked for
$show = strtolower($show);
// Start output of counter
if ($show != 'off' && $show !='no')
   $result4 = mysql_query("SELECT hits,speeddate,speed FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='Y'");
   //UNIX_TIMESTAMP( not needed
   $row4 = mysql_fetch_array($result4);
   $hit_count3 = $row4['hits'];
   echo '<table cellpadding="0" cellspacing="0">';
   echo '<tr><td><font face="verdana" size="2"><b>Total Hits:</b></font></td><td><font face="verdana" size="2">&nbsp;';
   print "$hit_count3";
   print "Speed  $row2[speed]";
//   debugging
//   $temptijd1=strtotime($row2[speeddate]);
//   $temptijd2=strtotime($row4[speeddate]);
//   $age=$temptijd2-$temptijd1;
//   print "  speeddate $temptijd1";
//   print "  speeddate $temptijd2";
//   $temptijd3=$this->GetPageTime();
//   print "  speeddate $temptijd3";
//   print " age $age";
//   $temptijd=time();
//   print "   temptijd $temptijd";
   echo '</font></td></tr></table>';
// End Output of counter

2° to activate this page, add in the footer.php somewhere
this activates the script for your complete wikka at once


3° Now to show this top speed we use a third trick change the recentchages.xml.php to a mostpseed.xml.php and changing one line by changing the invoked SQL function to LoadMostSpeed(). Subsequently we must define the function in the wikka.php.

This generates a complete xml output of the most currently viewed pages.
Evidently with the
  {{rss url=http.yoursite.com/Homepage/mostspeed.xml}} 
should show you the list within any page

header("Content-type: text/xml");

$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
$xml .= '<?xml-stylesheet href="' . $this->GetConfigValue("base_url") .'/css/xml.css" type="text/css"?' .">\n";
$xml .= "<rss version=\"0.92\">\n";
$xml .= "<channel>\n";
$xml .= "<title>".$this->GetConfigValue("wakka_name")." - ".$this->tag."</title>\n";
$xml .= "<link>".$this->GetConfigValue("base_url")."</link>\n";
$xml .= "<description>Most visited pages of  ".$this->GetConfigValue("wakka_name")."</description>\n";
$xml .= "<language>en-us</language>\n";

if ($pages = $this->LoadMostSpeed())
    $max = $this->GetConfigValue("xml_recent_changes");

    $c = 0;
    foreach ($pages as $page)
        if (($c <= $max) || !$max)
            $xml .= "<item>\n";
            $xml .= "<title>".$page["tag"]."</title>\n";
            $xml .= "<link>".$this->Href("show", $page["tag"], "time=".urlencode($page["time"]))."</link>\n";
            $xml .= "\t<description>".$page["time"]." by ".$page["user"].($page["note"] ? " - ".$page["note"] : "")."</description>\n";
            //$xml .= "\t<guid>".$page["id"]."</guid>";
            $xml .= "\t<pubDate>".date("r",strtotime($page["time"]))."</pubDate>\n";
            $xml .= "</item>\n";
    $xml .= "<item>\n";
    $xml .= "<title>Error</title>\n";
    $xml .= "<link>".$this->Href("show")."</link>\n";
    $xml .= "<description>You're not allowed to access this information.</description>\n";
    $xml .= "</item>\n";

$xml .= "</channel>\n";
$xml .= "</rss>\n";



4° So fourh code twinkering is in the wikka.php

adding this function before LoadRecentlyChanged()

    function LoadMostSpeed()
        if ($pages = $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' order by speed desc"))
            foreach ($pages as $page)
            return $pages;

And hence here you obtain a 'spedometer' say your top10 currently most viewed pages. Or your current hype in your wikka.
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki