>>//see also:// [[TRBMostVisited]]>>===Most Visited Pages=== This script assumes that you have setup properly the counter.php by GmBowen find out how to setup it up by visiting GmBowenCounter See the notes in the script to figure out the configuration and customisation options ... You'll need to create **/actions/mostvisited.php** with the following contents %%(php) accepts. $show_ranking : show the numbers on the side of the list ( starting from 1 ). $show_owner : show the page"s owner along with the page title. $show_current_version_hits : show the hits that the page received in its current version. @usage: insert {{mostvisited}} any where in a wakka page. */ // Configuration variables ... $hitlist_limit = 10; $table_alignment = "center"; $show_ranking = true; $show_owner = true; $show_current_version_hits = true; // mysql query ... $hitlistQuery = $this->Query( "SELECT id,hits,tag,owner,latest FROM ".$this->config['table_prefix']."pages; " ); // initialising variables ... $hitlist = array(); $i = 0; // assign the resultset of the msyql query to $hitlist in a custom way ... while( $row = mysql_fetch_array($hitlistQuery) ) { if (!$hitlist[$row['tag']]){ $hitlist[$row['tag']] = array( "owner" => $row['owner'], "hits" => $row['hits'] ); if ($row['latest'] == "Y") $hitlist[$row['tag']]['latest'] = $row['hits']+0; } else { $hitlist[$row['tag']]['hits'] += $row['hits']; if ( ($row['latest'] == "Y") && (!$hitlist[$row['latest']]) ) $hitlist[$row['tag']]['latest'] = $row['hits']; } } // sorting the array ... function hitlistsort( $a, $b ) { if ($a['hits'] == $b['hits']) return 0; return ($a['hits'] > $b['hits']) ? -1 : 1; } uasort($hitlist, "hitlistsort"); // creating the output ... $str = "\n\t\n\t"; $str .= "\t\t\n"; $str .= "\t\n"; $str .= "\t\n"; if ($show_ranking) $str .= "\t\t\n"; $str .= "\t\t\n"; if ($show_current_version_hits) $str .= "\t\t\n"; $str .= "\t\t\n"; $str .= "\t\n"; // creating the listing ... foreach($hitlist as $pag => $arr){ if ( ($i <= $hitlist_limit) && ( $arr['hits'] !== 0) ) { if ($show_owner) $arr['owner'] = ($arr['owner'] == "") ? "( not owned )" : "( ".$arr['owner']." )"; $i++; $str .= "\t\n"; if ($show_ranking) $str .= "\t\t\n"; $str .= "\t\t\n"; if ($show_current_version_hits) $str .= "\t\t\n"; $str .= "\t\t\n"; $str .= "\t\n"; } else break; } $str .= "
Most Visited Pages
RankPageNameCur.Version HitsTotal Hits
".$i.". ".$this->Format($pag)." "; if ($show_owner) $str .= "".$this->Format($arr['owner']).""; $str .="".$arr['latest']."".$arr['hits']."
"; // displaying the output ... print $this->ReturnSafeHTML($str); ?>%% ---- //Comments and suggestions as well as modifications are more than welcome ...// ---- OK another way around 1° create a function in Wikka.php just before function ""LoadRecentlyChanged()"" Actually its a copy of the function function ""LoadRecentlyChanged()"" that will make an SQL sorted on hits. order by hits orders by hits for without totalling the hits per page, this could be improved, i should dig in SQL and make a Sum or Total field %%php function LoadMostVisited() { if ($pages = $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' order by hits desc")) { foreach ($pages as $page) { $this->CachePage($page); } return $pages; } } %% 2° Create a copy of recentchanged.xml.ph in directory /handlers/page/ and rename the copy as mostvisited.xml.php and change one line if ($pages = $this->""LoadMostVisited()"") instead of recentchanged() function %% \n"; $xml .= 'GetConfigValue("base_url") .'/css/xml.css" type="text/css"?' .">\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "".$this->GetConfigValue("wakka_name")." - ".$this->tag."\n"; $xml .= "".$this->GetConfigValue("base_url")."\n"; $xml .= "Most visited pages of ".$this->GetConfigValue("wakka_name")."\n"; $xml .= "en-us\n"; if ($pages = $this->LoadMostVisited()) { $max = $this->GetConfigValue("xml_recent_changes"); $c = 0; foreach ($pages as $page) { $c++; if (($c <= $max) || !$max) { $xml .= "\n"; $xml .= "".$page["tag"]."\n"; $xml .= "".$this->Href("show", $page["tag"], "time=".urlencode($page["time"]))."\n"; $xml .= "\t".$page["time"]." by ".$page["user"].($page["note"] ? " - ".$page["note"] : "")."\n"; //$xml .= "\t".$page["id"].""; $xml .= "\t".date("r",strtotime($page["time"]))."\n"; $xml .= "\n"; } } } else { $xml .= "\n"; $xml .= "Error\n"; $xml .= "".$this->Href("show")."\n"; $xml .= "You're not allowed to access this information.\n"; $xml .= "\n"; } $xml .= "\n"; $xml .= "\n"; print($xml); ?> %% 3° Now you are ready to create XML output of 'mostvisited' pages. and with the rss function you can display all the most popular pages sorted with Bowens hit counter.php . %% {{rss url="http://www.avk.be/Wikka/HomePage/mostvisited.xml" cachetime="60"}} %% Should be equivalent to the function Mostvisited, but i find the solution a bit cleaner. 4° To make every page counted by the counter.php Add this one line to footer.php %% include("actions/counter.php"); %% This activates the counter for each page without having to add the {{counter}} action on each page. ---- CategoryUserContributions