記事アクセスランキング
monobookプラグインで、PageViewCountでカウントしたデータに基づいて、アクセスランキングを表示。
- ファイルが存在しないものはランキングから外します。
- アクセス権がないものもランキングから外します。
- lib/tpl/monobook/do_ranking.phpを作成。<code php>
<h1>アクセスランキング</h1> <table class=“inline”> <tr><th>#</th><th>タイトル</th><th>閲覧数</th></tr> <?php if ($numOfPosts == 0) {$numOfPosts = 100;} global $ID; $pvc_server=$conf['auth']['mysql']['server']; $pvc_user=$conf['auth']['mysql']['user']; $pvc_password=$conf['auth']['mysql']['password']; $pvc_database=$conf['auth']['mysql']['database']; $pvc_table=“pageview”; $pvc_ip = $_SERVER['REMOTE_ADDR'];
$con = @mysql_connect ($pvc_server, $pvc_user, $pvc_password); if ($con) { $res=mysql_select_db($pvc_database, $con); if ($res) {
$query = "SELECT id, views FROM $pvc_table ORDER by views DESC LIMIT 0,".$numOfPosts;
$res = @mysql_query($query, $con);
$num = 1;
while($row = mysql_fetch_object($res)) {
$itemid = $row->id;
if (!$itemid) {continue;}
if (isHiddenPage($itemid) || auth_quickaclcheck($itemid) < AUTH_READ) {continue;}
if (!file_exists(wikiFN($itemid))) {@mysql_query("DELETE FROM $pvc_table WHERE id='$itemid'");continue;}
$views = $row->views;
$permanent = DOKU_URL.$itemid;
print '<tr><td class="rightalign">'.$num.'</td><td><a href="'. $permanent.'">';
tpl_pagetitle($itemid,$ret);
print '</a></td><td class="rightalign">'.$views."</td></tr>\n";
$num++;
}
} } ?> </table>
</code>※UTF-8で保存。
- lib/tpl/monobook/main.phpにリンクを追加。<code php>
else if ($_REQUEST['mbdo'] == 'media') @include(dirname(__FILE__).'/do_media.php');
</code>の後ろに
else if ($_REQUEST['mbdo'] == 'ranking') @include(dirname(__FILE__).'/do_ranking.php');
を追加。
- lib/tpl/monobook/user/pref.phpにツールボックスの項目を追加<code php> $monobook['toolbox']['ranking']['href'] = DOKU_BASE.“doku.php?mbdo=ranking”; $monobook['toolbox']['ranking']['text'] = 'アクセスランキング'; $monobook['toolbox']['ranking']['rel'] = “nofollow”;
</code>※UTF-8で保存。