]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentReferrers.php
simple version at first
[SourceForge/phpwiki.git] / lib / plugin / RecentReferrers.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RecentReferrers.php,v 1.1 2004-11-06 04:52:29 rurban Exp $');
3
4 /**
5  * Analyze our ACCESS_LOG
6  * Check HTTP_REFERER
7  *
8  */
9 include_once("lib/PageList.php");
10
11 class WikiPlugin_RecentReferrers extends WikiPlugin
12 {
13     function getName () {
14         return _("RecentReferrers");
15     }
16
17     function getVersion() {
18         return preg_replace("/[Revision: $]/", '',
19                             "\$Revision: 1.1 $");
20     }
21
22     function getDefaultArguments() {
23         return array_merge
24             (
25              PageList::supportedArgs(),
26              array(
27                    'limit'         => 15,
28                    'noheader'      => false,
29                    'debug'         => false
30                    ));
31     }
32
33     function run($dbi, $argstr, &$request, $basepage) { 
34         if (!ACCESS_LOG) return;
35         $args = $this->getArgs($argstr, $request); 
36         $table = HTML::table(array('cellpadding' => 1,
37                                    'cellspacing' => 2,
38                                    'border'      => 0,
39                                    'class'       => 'pagelist'));
40         if (!$args['noheader'] and !empty($args['caption']))
41             $table->pushContent(HTML::caption(array('align'=>'top'), $args['caption']));
42         $logs = array();
43         $limit = $args['limit'];
44         $logentry = new Request_AccessLogEntry(ACCESS_LOG);
45         while ($logentry->read()) {
46             if (!empty($logentry->referer)) {
47                 $logs[] = $logentry;
48                 if ($limit and count($logs) > $limit)
49                     array_shift($logs);
50                 $logentry = new Request_AccessLogEntry(ACCESS_LOG);
51             }
52         }
53         if ($logs) {
54             $logs = array_reverse($logs);
55             $table->pushContent(HTML::tr(HTML::th("Target"),HTML::th("Referrer"),
56                                          HTML::th("Host"),HTML::th("Date")));
57             $logs = array_slice($logs,0,min($limit,count($logs)));
58             foreach ($logs as $logentry) {
59                 $table->pushContent(HTML::tr(HTML::td($logentry->request),
60                                              HTML::td($logentry->referer),
61                                              HTML::td($logentry->host),
62                                              HTML::td($logentry->time)
63                                              ));
64             }
65             return $table;
66         }
67     }
68 }
69
70 // $Log: not supported by cvs2svn $
71
72 // (c-file-style: "gnu")
73 // Local Variables:
74 // mode: php
75 // tab-width: 8
76 // c-basic-offset: 4
77 // c-hanging-comment-ender-p: nil
78 // indent-tabs-mode: nil
79 // End:
80 ?>