>>//see also:// [[TRBCounter | TRBCounter]]>>====Page Counter Action==== - Below are the changes needed to create an action that allows the number of hits on a page to be roughly counted (it doesn't increment if it's your own page, only for the pages of others). - If you want it to keep a count, but without showing the number (so people don't have the urge to "up" the number on you), you can set the parameter show=''"off"'' or show=''"no"''. - It works pretty well overall. Of course, it doesn't "count" if the action isn't on the page, but I thought for "help" pages etc that aren't open for editing it might be pretty useful. Usually we put lots of work into different things in a wiki, I thought it'd be interesting to be able to gauge the use of the different parts. Hope you find it useful. -- Mike (aka GmBowen) - ''the only thing I can think might be useful to add, is if you could add the parameter ignore="//name1, name2, name3//"...but I had no idea how to parse a list like that and include a comparison of to the current user for exclusion'' - ''it also might be useful to have it so that an owner could set show=off or show=no but show up if it is the pageowner looking...I'll have to think through the coding on that though'' the **_pages table** has to have the following field added.... %%`hits` int(50) NOT NULL default '0'%% and the **counter.php** code (save as a file in the action directory).... %%(php) $thispage=$this->GetPageTag(); // Get hit count $result2 = mysql_query( "SELECT hits 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; // End adding hits Start Update Hit $sql = "UPDATE `".$this->config["table_prefix"]."pages` SET `hits` = '$hit_count2' 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); if ($show != 'off' && $show !='no') { // Start output of counter $result4 = mysql_query("SELECT hits FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='Y'"); $row4 = mysql_fetch_array($result4); $hit_count3 = $row4['hits']; echo '
Total Hits: | '; print "$hit_count3"; echo ' |