Revision [19578]

This is an old revision of TRBMostVisited made by KrzysztofTrybowski on 2008-02-22 13:26:43.

 

see also: TRBCounter

Most Visited Pages

version 0.1

This is a script based on MostVisited action by GeorgePetsagourakis George Petsagourakis. It adds new functionality compared to the original version, but is compatible with it (both versions show exactly the same results).
To use this script you need to install this TRBCounter page hit counter (TRBCounter) add-on first. You could also go with its predecessor, GmBowenCounter, but that is not fully compatible and provides less functions. For more details on the incompatibility see TRBCounter description.

What's new in this version


0.1 (since the original release by George Petsagourakis)

TODO

Instructions


1. How to set this up

All you need to do is create an action file mostvisited.php in a proper place.
For an unstable Wikka 1.1.7.0 this will be actions/mostvisited/mostvisited.php.
For Wikka 1.1.6.3 this will be actions/mostvisited.php.

<?php
/**
 * Display a list of most visited pages.
 *
 * @package     Actions
 * @name        MostVisited
 * @license     http://www.gnu.org/copyleft/gpl.html GNU General Public License
 * @filesource
 *
 * @author      {@link mailto:petsagouris@hotmail.com George Petsagourakis} (first version)
 * @author      {@link http://wikkawiki.org/KrzysztofTrybowski Krzysztof Trybowski} (later changes)
 * @date        06 Feb 2008
 *
 * @description     This file assumes that you are running TRBCounter add-on on your Wakka
 */


// Default translation entries
if (!defined('MOSTVISITED_HEADING'))  define('MOSTVISITED_HEADING', 'Most visited pages');
if (!defined('MV_RANK'))  define('MV_RANK', 'Rank');
if (!defined('MV_PAGENAME'))  define('MV_PAGENAME', 'Page name');
if (!defined('MV_PAGENAME_WITH_OWNER'))  define('MV_PAGENAME_WITH_OWNER', 'Page name (page owner)');
if (!defined('MV_CURRENT_VERSION_HITS'))  define('MV_CURRENT_VERSION_HITS', 'Current<br> version hits');
if (!defined('MV_TOTAL_HITS'))  define('MV_TOTAL_HITS', 'Total hits');
if (!defined('MV_OWNER'))  define('MV_OWNER', 'Owner');  //not used now, but maybe in the future
if (!defined('MV_NOT_OWNED'))  define('MV_NOT_OWNED', 'not owned');

// Defaults for options and some checking
$showhits=abs($showhits);
if ($showhits==0) $showhits = 10;
if (!isset($showrank)) $showrank = true;
if (!isset($showowner)) $showowner = false;
if (!isset($showcurrent)) $showcurrent = false;
if (!isset($showtotal)) $showtotal = true;
if (!isset($showheader)) $showheader = true;
if (!isset($class)) $class = "mostvisited_container"; else $class = $this->CleanTextNode($class);

// Database query
$result = $this->Query("SELECT * FROM (SELECT t1.tag,owner,total_hits,current_hits FROM (SELECT tag,owner,SUM(hits) AS total_hits FROM ".$this->config['table_prefix']."pages GROUP BY tag ORDER BY total_hits DESC LIMIT ".$showhits.") AS t1 INNER JOIN (SELECT tag,hits AS current_hits FROM ".$this->config['table_prefix']."pages WHERE latest='Y') AS t2 ON t1.tag=t2.tag ORDER BY total_hits DESC) AS t3 WHERE total_hits>'0'");

// Creating the output
$str = "\n\n<div class=\"".$class."\">\n<h2>".MOSTVISITED_HEADING."</h2>\n";
$str .= "<table class=\"mostvisited\">\n";
if ($showheader) {
    $str .= "\t<tr>\n";
    if ($showrank) $str .= "\t\t<th class=\"rank\">".MV_RANK."</th>\n";
    if ($showowner) $str .= "\t\t<th class=\"tag\">".MV_PAGENAME_WITH_OWNER."</th>\n"; else $str .= "\t\t<th>".MV_PAGENAME."</th>\n";
    if ($showcurrent) $str .= "\t\t<th class=\"current_hits\">".MV_CURRENT_VERSION_HITS."</th>\n";
    if ($showtotal) $str .= "\t\t<th class=\"total_hits\">".MV_TOTAL_HITS."</th>\n";
    $str .= "\t</tr>\n";
}
$i = 1;
while($row = mysql_fetch_array($result))
{
    if ($i%2) $str .= "\t<tr>\n"; else $str .= "\t<tr class=\"even\">\n";
    if ($showrank) $str .= "\t\t<td class=\"rank\">".$i.". </td>\n";
    $i+=1;$str .= "\t\t<td class=\"tag\">".$this->Format("[[".$row['tag']."]]")." ";
    if ($showowner) { $row['owner'] = ($row['owner'] == "") ? "(".MV_NOT_OWNED.")" : "<span class=\"user\">".$this->Format("([[".$row['owner']."]])"); $str .= $row['owner']; }
    $str .= "</td>\n";
    if ($showcurrent) $str .= "\t\t<td class=\"current_hits\">".$row['current_hits']."</td>\n";
    if ($showtotal) $str .= "\t\t<td class=\"total_hits\">".$row['total_hits']."</td>\n\t</tr>\n";
}
$str .= "</table>\n</div>\n";

// Displaying the output
print $this->ReturnSafeHTML($str);
?>


2. How to translate it

Add the following lines to your lang/xx/xx.inc.php (substitute xx for a code of your language):

/**#@+
 * Language constant used by the {@link mostvisited.php mostvisited} action
 */

// mostvisited
define('MOSTVISITED_HEADING', 'Most visited pages');
define('MV_RANK', 'Rank');
define('MV_PAGENAME', 'Page name');
define('MV_PAGENAME_WITH_OWNER', 'Page name (page owner)');
define('MV_CURRENT_VERSION_HITS', 'Current<br> version hits');
define('MV_TOTAL_HITS', 'Total hits');
define('MV_OWNER', 'Owner');  //not used now, but soon
define('MV_NOT_OWNED', 'not owned');
/**#@-*/

...replacing English texts with your translations.

3. How to format/skin the output

The whole output of the action is included in a div with mostvisited_containter class. It contains page title within <h2> tag and a table with mostvisited class. The while output contains classes, so it's easy to be skinned -- for details see the source.

My proposed formatting for the action (place it in yoour css/wikka.css file):

.mostvisited { margin-top: 1em; }
.mostvisited th { background: #e3e3e3; padding: 0 0.5em; border: 1px solid #cccccc;}
.mostvisited td { background: #fafafa; padding: 0 1em; border: 1px solid #e3e3e3;}
.mostvisited .even td { background: #f0f0f0; }
.mostvisited td.rank, .mostvisited td.current_hits, .mostvisited td.total_hits  { text-align: right; }
.mostvisited .user { font-size: smaller; }


That's all folks. Best regards -- KrzysztofTrybowski

CategoryUserContributions
There are 2 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki