Revision [10923]

This is an old revision of SpedoMeter made by PaulBelgian on 2005-09-03 22:15:02.


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.

// Get hit count
$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
if ($this->GetUserName() != $this->GetPageOwner($tag))
	  // End Get hit Count   Start adding hits
	  $hit_count2 = $hit_count1 + 1;
		  $newspeed= $row2[speed]*0.8+(365*24*60*60)/((time()-speeddate)*24*60*60)*0.2;
		 }       else {
		   $newspeed= $row2[speed]*0.8+365*24*0.2;

	  // End adding hits   Start Update Hit
	  $sql = "UPDATE `".$this->config["table_prefix"]."pages` SET hits=$hit_count2,speeddate=CURRENT_TIMESTAMP,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,speed FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='Y'");
   $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 "   $row4[speed]";
   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
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