This plugin determines the most popular entries on your blog, based upon
the results of the Apache webserver access logs. It makes this
information available via the MTMostVisited container tag, which can
contain MTMostVisitedCount and MTMostVisitedLink tags, as well as any
MTEntry-type tags.
SYNOPSIS
<ol>
<MTMostVisited blogurl="/blog/archives"
logfile="/var/log/httpd/access_log*"
count="10">
<li> <a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a>
of <MTEntryDate format="%B %e, %Y">
(<$MTMostVisitedCount$> hits)
</li>
</MTMostVisited>
</ol>
DESCRIPTION
This plugin determines the most popular entries on your blog, based upon
the results of the Apache webserver access logs. It makes this
information available via the MTMostVisited container tag, which can
contain MTMostVisitedCount and MTMostVisitedLink tags, as well as any
MTEntry-type tags.
This information may be interesting to display, if some of your most
popular entries do not have many comments, or if they have fallen off of
your index page.
Please note: Your webserver must be Apache for this to work, and Apache
must be configured to output log information. (This was the default for
Redhat Linux, at least, and I expect it to be true for the majority of
sites running Movable Type.)
Tags made available through this plugin:
- MTMostVisited -
Container tag, which loops through the most-requested pages on your
blog. It has a number of attributes, which will be enumerated later.
- MTMostVisitedCount -
Returns the number of hits that a particular
entry has received. Used in conjunction with MTMostVisited.
- MTMostVisitedLink -
The URL of the particular entry. Used in
conjunction with MTMostVisited. The MTEntryLink or
MTEntryPermalink tags can be used instead.
- MTEntryXXX -
MTEntry tags can be used within the MTMostVisited container, too.
INSTALLATION
The plugin is available (as a zip archive) here.
To install, place the mt-mostvisited.pl file in your Movable Type
'plugins' directory.
This plugin also requires Akira Hangai's Apache::ParseLog module,
available via CPAN, www.cpan.org. This can either be installed
within your server's Perl libraries (if root access is available),
or placed within the extlib subdirectory of your Movable Type home.
I.e. the total installation should look like:
- (mt home)/plugins/mt-mostvisited.pl
- (mt home)/extlib/Apache/ParseLog.pm
Refer to the Movable Type documentation for more information regarding
plugins.
The apachelog.pl script, included with this distribution, is a
command-line Perl script that also parses the Apache log. It
outputs to the console, thus making it easier to check the
configuration of the plugin. It is NOT needed to implement the Movable
Type functionality.
CONFIGURATION
The configuration of the plugin is done via attributes of the MTMostVisited
element.
- filetype - This specifies the extension of your individual archive
files. It defaults to "html". This can also be a regex-like
expression, like "html|php". (Thanks to Eric James Stone for
the regex suggestion, and sample implementation.)
- blogurl - This specifies the URL of your individual archive directory,
relative to your domain name. For example, if your individual
entry archives can be found by going to the URL
http://www.borlik.net/blog/archives/000001.html, then the
blogurl should be "/blog/archives". Note that the trailing
slash should not be present. Also note that this will be
used within a regular expression, so multiple directories
can be searched with the right wildcards. For example, if you
store your individual entries in category directories (e.g.
"/blog/archives/work" and "/blog/archives/play"), then you can
use a regex wildcard like "/blog/archives/.*". (Please let me
know if that functionality does not work intended.)
- logfile - This plugin needs to know the location of the webserver hit logs.
The logfile attribute is used to specify that location on the
server. Note that the wildcards are acceptible, if you have
multiple logfiles (e.g. rotating logs). An example would be
"/var/log/httpd/access_log*". If you are not running your
own server, ask your host for help.
- ziplogfiles - This attribute is similar to the "logfile" attribute, and
used in the same way. Some webservers automatically gzip
older log files. Logs specified with this attribute will be
unzipped and interpreted correctly. Please note that this
assumes that the server has gunzip installed in the default
path and that a temporary file can be written to the current
directory.
- count - This specifies the number of entries to enumerate. By default,
only the top ten will be listed.
- cleanbuild - If set to "1", then plugin errors will be written out as HTML
and template processing will not be interrupted. This can
be considered to be a debugging utility, perhaps. Some errors,
such as missing requirements or Perl compilation errors will
still screw things up.
PERFORMANCE NOTES AND BUGS
Some webserver log files can be quite large, especially on a popular
site. This plugin may slow down your blog rebuilding. It hasn't been a
problem for me, but then again, nobody likes me.
One technique, suggested by Eric James Stone on the gday mate website, is to create a
separate template just for the MTMostVisited section, and use the
MTInclude directive to include it in one's index page. The extra template
can be rebuilt separately (maybe once a day or something, and possibly
via the various build scripts that are out there). Such a technique is
a necessity if you wish to include MTMostVisited stuff on individual
archive pages. The MTFastInclude
plugin may be useful for this, too.
Monthly archives are not handled well, nor are popup-image pages. (A
critical assumption of this plugin is that all of the files within the
archive directory - $root - are named according to their entry id's.)
Because the monthly archives are named differently, the plugin is unable
to load them in, in order to process MTEntry-type tags. This hasn't been
an issue for me, since my most-accessed files are individual archives.
THE MOST COMMON MISTAKE is not installing Apache::ParseLog. Without
that module, this plugin will break. (Does anyone know of a way of
detecting if a module exists?) This often results in a compile error,
with a strange error message (such as "You used an MTEntryLink tag outside
the context of an entry" or some such nonsense). (The correct Perl
compilation error is dumped into the webserver error log, but not shown
to the MT user.)
Any assistance or suggestions would be appreciated. In particular, I
would like to offer this plugin to bloggers who use entry titles
rather than entry ID's for the naming of the archive web page.
COPYRIGHT
Copyright 2004, Jeffrey Borlik. All rights reserved.
This program is free software; You can redistribute it and/or modify it,
as long as this copyright notice is kept intact and the original author
is given credit.
DISCLAIMER
This package is so distributed WITHOUT ANY WARRANTY in that any use of
the data generated by this package must be used at the user's own
discretion, and the author shall not be held accountable for any results
from the use of this package.
CREDITS
I would like to give credit to Timothy
Appnel, whose MT plugin article was quite helpful, and to Brad Choate, whose
MT-SQL plugin served as a useful starting-point for integrating the
MTEntry tag functionality. Akira Hangai's Apache::Parselog made this plugin possible, of course.
And there have been many users who have offered useful ideas and sample implementations,
including Ian Fenn, Zack,
and Eric James Stone.
CHANGELOG
- 1.0 - Initial release
- 1.1 - Removed unneeded $conf parameter
- 1.2 - Ignore nonentry pages (via a test for only digits)
- 1.3 - Removed pod, and greatly improved error messages
- 2.0 - Moved configuration out of plugin. Allow wildcards for most configs.
AUTHOR / SUPPORT
MT-MostVisited was written and is maintained by Jeffrey Borlik. Please feel free to email me with
problems or suggestions.
The latest version of the plugin archive can be found at http://www.borlik.net/~jborlik/mt-mostvisited.zip
Webpage: http://www.borlik.net for this plugin:
http://www.borlik.net/blog/archives/000043.html
Email: jborlik.DONTSPAM.ATSYMBOL.earthlink.IGNORE.net
Support is also available at the the Movable Type forums: http://www.movabletype.org/support/index.php?act=ST&f=20&t=20333&s=63aa7fee167f1be5388a03bfc8c7be0c
And at the mt-plugins site: http://mt-plugins.org/archives/entry/mostvisited.php