Revision history for MostVisited


Revision [19529]

Last edited on 2008-02-06 17:34:54 by KrzysztofTrybowski [see also TRBMostVisited]
Additions:
>>//see also:// [[TRBMostVisited]]>>===Most Visited Pages===
Deletions:
===Most Visited Pages===


Revision [19441]

Edited on 2008-01-28 00:16:02 by JavaWoman [Modified links pointing to docs server]

No Differences

Revision [17832]

Edited on 2007-12-12 12:50:19 by JavaWoman [prevent function references looking as page links]
Additions:
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.
and change one line if ($pages = $this->""LoadMostVisited()"") instead of recentchanged() function
Deletions:
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.
and change one line if ($pages = $this->LoadMostVisited()) instead of recentchanged() function


Revision [10918]

Edited on 2005-09-03 13:28:55 by PaulBelgian [prevent function references looking as page links]
Additions:
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.


Revision [10917]

Edited on 2005-09-03 13:08:01 by PaulBelgian [prevent function references looking as page links]
Additions:
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"}}
Deletions:
and with the rss function you can display all the most popular fields.


Revision [10916]

Edited on 2005-09-03 13:05:17 by PaulBelgian [prevent function references looking as page links]
Additions:
===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)<?php
/*
@filename: mostvisited.php
@author: George Petsagourakis
@email: petsagouris@hotmail.com
@date: 24 Dec 2004
@license: GPL

@description: this file assumes that you are running
the counter.php by GmBowen on your Wakka
// config vars //
$hitlist_limit : how many pages are going to be displayed in the list.
$table_alignment : accepts the values that the "align" attr of a <table> 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 = "<table align=\"".$table_alignment."\">\n\t<tr>\n\t";
$str .= "\t\t<th align=\"center\" colspan=\"4\">Most Visited Pages</th>\n";
$str .= "\t</tr>\n";
$str .= "\t<tr>\n";
if ($show_ranking) $str .= "\t\t<th align=\"center\">Rank</th>\n";
$str .= "\t\t<th align=\"center\">PageName</th>\n";
if ($show_current_version_hits) $str .= "\t\t<th align=\"center\">Cur.Version Hits</th>\n";
$str .= "\t\t<th align=\"center\">Total Hits</th>\n";
$str .= "\t</tr>\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<tr>\n";
if ($show_ranking)
$str .= "\t\t<td align=\"right\">".$i.". </td>\n";

$str .= "\t\t<td bgcolor=\"#999999\">".$this->Format($pag)." ";

if ($show_owner)
$str .= "<small>".$this->Format($arr['owner'])."</small>";

$str .="</td>\n";
if ($show_current_version_hits)
$str .= "\t\t<td align=\"center\">".$arr['latest']."</td>\n";

$str .= "\t\t<td align=\"center\">".$arr['hits']."</td>\n";
$str .= "\t</tr>\n";
}
else break;

}
$str .= "</table>";
// 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

%%
<?php
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->LoadMostVisited())
{
$max = $this->GetConfigValue("xml_recent_changes");

$c = 0;
foreach ($pages as $page)
{
$c++;
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";
}
}
}
else
{
$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";

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 fields.

Should be equivalent to the function Mostvisited, but i find the solution a bit cleaner.
Deletions:
===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)<?php
/*
@filename: mostvisited.php
@author: George Petsagourakis
@email: petsagouris@hotmail.com
@date: 24 Dec 2004
@license: GPL

@description: this file assumes that you are running
the counter.php by GmBowen on your Wakka
// config vars //
$hitlist_limit : how many pages are going to be displayed in the list.
$table_alignment : accepts the values that the "align" attr of a <table> 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 = "<table align=\"".$table_alignment."\">\n\t<tr>\n\t";
$str .= "\t\t<th align=\"center\" colspan=\"4\">Most Visited Pages</th>\n";
$str .= "\t</tr>\n";
$str .= "\t<tr>\n";
if ($show_ranking) $str .= "\t\t<th align=\"center\">Rank</th>\n";
$str .= "\t\t<th align=\"center\">PageName</th>\n";
if ($show_current_version_hits) $str .= "\t\t<th align=\"center\">Cur.Version Hits</th>\n";
$str .= "\t\t<th align=\"center\">Total Hits</th>\n";
$str .= "\t</tr>\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<tr>\n";
if ($show_ranking)
$str .= "\t\t<td align=\"right\">".$i.". </td>\n";

$str .= "\t\t<td bgcolor=\"#999999\">".$this->Format($pag)." ";

if ($show_owner)
$str .= "<small>".$this->Format($arr['owner'])."</small>";

$str .="</td>\n";
if ($show_current_version_hits)
$str .= "\t\t<td align=\"center\">".$arr['latest']."</td>\n";

$str .= "\t\t<td align=\"center\">".$arr['hits']."</td>\n";
$str .= "\t</tr>\n";
}
else break;

}
$str .= "</table>";
// displaying the output ...
print $this->ReturnSafeHTML($str);
?>%%
----
//Comments and suggestions as well as modifications are more than welcome ...//
----


Revision [4740]

Edited on 2005-01-17 14:36:26 by NilsLindenberg [cat. changed]
Additions:
CategoryUserContributions
Deletions:
CategoryDevelopment


Revision [3862]

Edited on 2004-12-31 12:16:35 by GeorgePetsagourakis [changed the code with a xhtml comp version ...]
Additions:
@date: 24 Dec 2004
the counter.php by GmBowen on your Wakka
$show_owner : show the page"s owner along with the page title.
$show_current_version_hits = true;
$hitlistQuery = $this->Query( "SELECT id,hits,tag,owner,latest FROM ".$this->config['table_prefix']."pages; " );
$hitlist[$row['tag']] = array( "owner" => $row['owner'],
"hits" => $row['hits']
);
if ($row['latest'] == "Y") $hitlist[$row['tag']]['latest'] = $row['hits']+0;
if ( ($row['latest'] == "Y") && (!$hitlist[$row['latest']]) ) $hitlist[$row['tag']]['latest'] = $row['hits'];
$str = "<table align=\"".$table_alignment."\">\n\t<tr>\n\t";
$str .= "\t\t<th align=\"center\" colspan=\"4\">Most Visited Pages</th>\n";
$str .= "\t</tr>\n";
$str .= "\t<tr>\n";
if ($show_ranking) $str .= "\t\t<th align=\"center\">Rank</th>\n";
$str .= "\t\t<th align=\"center\">PageName</th>\n";
if ($show_current_version_hits) $str .= "\t\t<th align=\"center\">Cur.Version Hits</th>\n";
$str .= "\t\t<th align=\"center\">Total Hits</th>\n";
$str .= "\t</tr>\n";

if ( ($i <= $hitlist_limit) && ( $arr['hits'] !== 0) )
{
if ($show_owner) $arr['owner'] = ($arr['owner'] == "") ? "( not owned )" : "( ".$arr['owner']." )";

$str .= "\t<tr>\n";
if ($show_ranking)
$str .= "\t\t<td align=\"right\">".$i.". </td>\n";

$str .= "\t\t<td bgcolor=\"#999999\">".$this->Format($pag)." ";

if ($show_owner)
$str .= "<small>".$this->Format($arr['owner'])."</small>";

$str .="</td>\n";
if ($show_current_version_hits)
$str .= "\t\t<td align=\"center\">".$arr['latest']."</td>\n";

$str .= "\t\t<td align=\"center\">".$arr['hits']."</td>\n";
$str .= "\t</tr>\n";
print $this->ReturnSafeHTML($str);
Deletions:
@date: 15 Dec 2004
the counter.php by GmBowen on your Wikka
$show_owner : show the page's owner along with the page title.
$show_current_version_hits = false;
$hitlistQuery = $this->Query( 'SELECT id,hits,tag,owner,latest FROM '.$this->config["table_prefix"].'pages; ' );
$hitlist[$row['tag']] = array(
"owner" => $row['owner'],
"hits" => $row['hits']
);
if ($row['latest'] == 'Y') $hitlist[$row['tag']]['latest'] = $row['hits'];
if ( ($row['latest'] == 'Y') && (!$hitlist[$row['latest']]) ) $hitlist[$row['tag']]["latest"] = $row['hits'];
$str = '<table align='.$table_alignment.'><tr>';
$str .= '<td align="center" colspan="4">';
$str .= '<strong>Most Visited Pages</strong>';
$str .= '</td>';
$str .= '</tr>';
$str .= '<tr>';
if ($show_ranking) $str .= '<td align="center">Rank</td>';
$str .= '<td align="center">PageName</td>';
if ($show_current_version_hits) $str .= '<td align="center">Cur.Version Hits</td>';
$str .= '<td align="center">Total Hits</td>';
$str .= '</tr>';
if ( $i <= $hitlist_limit ) {
if ($show_owner){
if ($arr['owner'] == "") $arr['owner'] = "( not owned )";
else $arr['owner'] = "( ".$arr['owner']." )";
}
$str .= "<tr>";
if ($show_ranking) $str .= "<td align=\"right\"> $i.  </td>";
$str .= "<td bgcolor=\"#999999\">".$this->Format($pag)." ";
if ($show_owner) $str .= "<small>".$this->Format($arr['owner'])."</small></td>";
if ($show_current_version_hits) $str .= "<td align=\"center\">".$arr['latest']."</td>";
$str .= "<td align=\"center\">".$arr['hits']."</td>";
$str .= "</tr>";
print( $str );


Revision [3308]

Edited on 2004-12-16 14:21:12 by GeorgePetsagourakis [a small code edit]
Additions:
if ($row['latest'] == 'Y') $hitlist[$row['tag']]['latest'] = $row['hits'];
Deletions:
if ($row['latest'] == 'Y') $hitlist[$row['tag']]["latest"] = $row['hits']+0;


Revision [3269]

Edited on 2004-12-15 22:20:00 by GmBowen [aw crud, TYPO.....it's spelt tee why pee ohhh]
Additions:
This script assumes that you have setup properly the counter.php by GmBowen
Deletions:
This script assumes that you have setup properly the counter.php by GmBowen


Revision [3268]

Edited on 2004-12-15 22:19:05 by GmBowen [type]
Additions:
the counter.php by GmBowen on your Wikka
Deletions:
the counter.php by GmBowen on your Wakka


Revision [3263]

The oldest known version of this page was created on 2004-12-15 20:59:17 by GeorgePetsagourakis [type]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki