記事アクセスランキング
monobookプラグインで、PageViewCountでカウントしたデータに基づいて、アクセスランキングを表示。
- ファイルが存在しないものはランキングから外します。
- アクセス権がないものもランキングから外します。
- lib/tpl/monobook/doranking.phpを作成。<code php>
<h1>アクセスランキング</h1> <table class=“inline”
>
<
tr><th>#</th><th>タイトル</th><th>閲覧数</th></tr> <?php if ($numOfPosts == 0) {$numOfPosts = 100;} global $ID; $pvcserver=$conf['auth']['mysql']['server']; $pvcuser=$conf['auth']['mysql']['user']; $pvcpassword=$conf['auth']['mysql']['password']; $pvcdatabase=$conf['auth']['mysql']['database']; $pvctable=“pageview”; $pvcip = $SERVER['REMOTEADDR'];
$con = @mysqlconnect ($pvcserver, $pvcuser, $pvcpassword); 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).'/domedia.php'); </code>の後ろに<code php> else if ($REQUEST['mbdo'] == 'ranking')
@include(dirname(__FILE__).'/do_ranking.php');
</code>を追加。
- lib/tpl/monobook/user/pref.phpにツールボックスの項目を追加
$monobook['toolbox']['ranking']['href'] = DOKU_BASE."doku.php?mbdo=ranking"; $monobook['toolbox']['ranking']['text'] = 'アクセスランキング'; $monobook['toolbox']['ranking']['rel'] = "nofollow";
※UTF-8で保存。