Revision [3268]

This is an old revision of MostVisited made by GmBowen on 2004-12-15 22:19:05.

 

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
    /*  
        @filename:      mostvisited.php
        @author:        George Petsagourakis
        @email:         petsagouris@hotmail.com
        @date:          15 Dec 2004
        @license:       GPL

            @description:   this file assumes that you are running
                            the counter.php by GmBowen on your Wikka
                            // 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 = false;

    // 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.'><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>';
    // creating the listing ...
    foreach($hitlist as $pag => $arr){
        if ( $i <= $hitlist_limit ) {
            if ($show_owner){
                if ($arr['owner'] == "") $arr['owner'] = "( not owned )";
                else $arr['owner'] = "( ".$arr['owner']." )";
            }
            $i++;
            $str .= "<tr>";
            if ($show_ranking) $str .= "<td align=\"right\"> $i. &nbsp;</td>";
            $str .= "<td bgcolor=\"#999999\">".$this->Format($pag)."&nbsp;";
            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>";
        }
        else break;
    }
    $str .= "</table>";
   
    // displaying the output ...
    print( $str );
?>


Comments and suggestions as well as modifications are more than welcome ...

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