Name

Blosxom Plug-In: moreentries

Synopsis

When the Blosxom variable $num_entries is set to a non-zero number, Any non-date style request(category or root url) will only display $num_entries entries on the page. No method is provided to see subsequent entries (aside from using date-urls to browse back in time, and this can't be combined with categories).

moreentries enables these addional entries to be viewed. moreentries adds the ability for blosxom urls to accept an _start parameter, for example:

  http://jclark.org/weblog/index.html?_start=11

Will show you all the weblog entries *after* the first 10. moreentries also offers several variable to allow you to add Next and Previous links to your templates, and to show the current range of posts, and total posts.

PLEASE NOTE: Probably doens't work with static rendering. Untested.

Quick Start

Just drop it in your $plugin_dir. There is only one config variable, which we will ignore for the quick start; see next section for more info. You'll need to modify your head or foot template to see the links. For a quick start, add $moreentries::links to your head or foot template. And of course, your blosxom.cgi must have a (nonzero) value set for $num_entries.

That's it; you should now have next & previous functionality.

To enable paged access set the $moreentries::numpagelinks to a non-zero value to control how many links to pages preceding and following the current page will be generated. Add the $moreentries::pagelinks to your head or foot template to see the links. You can use this independently from $moreentries::links.

More Info

moreentries exposes the following variables for use in your templates. None of these are per-story, and are generally suited for use in your head or foot template.

$moreentries::active - true if the plugin is 'in use'. This will be false if the url is a date url (blosxom ignores $num_entries), or if there are not at least $num_entries entries matching the request, or if $num_entries is not set. $moreentries::totalposts - total number of entries that match the request $moreentries::start - the number of the first entry being displayed $moreentries::end - the number of the last entry being displayed $moreentries::links - inserts (x)HTML containing links to the previous and next batch of entries. If one (or both) of these links does not apply ( for example, when viewing the first batch of entries, there are no previous entries) there is no link.

The output of $moreentries::links will look like this: <div class='moreentries'> <span class='prevlink' style='padding:0 15px'><a href='http://127.0.0.1/weblog/index.html?_start=1'>Previous 10 entries</a></span> <span class='nextlink' style='padding:0 15px'><a href='http://127.0.0.1/weblog/index.html?_start=21'>Next 10 entries</a></span> </div>

The embedded style prevents the links from being right next to each other. This output is sufficient for a quick drop-in. If you'd like to control CSS styles yourself, there is a config variable ( $selfstyle ) that controls this, just set it to 0.

If you want even more control over your output, there are some additional variables you can use:

$moreentries::prevlink - if $moreentries::start is not 1, this will contain an URL to move to the previous batch of entries. Will be undef if no Previous batch (i.e., $moreentries::start =1)

$moreentries::prevcount - If there is a previous batch, this contains the number of posts in it. This is normally $num_entries, except when there arent enough entries. For example, if this batch starts at post 21 in the Rants category, and your $num_entries is 15, then $morrentries::prevcount will be 5.

$moreentries::nextlink - if $moreentries::end < $morrentries::totalposts, this will contain an URL to the next batch of entries. Will be undef if no Next batch (i.e., $moreentries::end = $moreentries::totalposts)

$moreentries::nextcount - If there is a next batch, this contains the number of posts in it. This is normally $num_entries, except when there arent enough entries left. For example, if there are 12 posts in the Rants category, and your $num_entries is 10, then $morrentries::nextcount will be 2.

There are a number of config variables, explained above in the discussion of $moreentries::links:

$moreentries::selfstyle - when set, $moreentries::links will contain the specified style attributes.

The page links feature has its own configuration variables. The $moreentries::selfstyle variable is also applied to the $moreentries::pagelinks.

$moreentries::numpagelinks - when set, $moreentries::pagelinks will be created and contain the number of links specified by this variable. The current page will be centered in the links if possible.

$moreentries::textlinks - when set to 1 enables text links to preceding and following pages. It can be used independently or combined with the $moreentries::imagelinks setting. The html generated if of the format:

<div class='pagelinks' style='padding:0 5px'> <table border='0' cellpadding='0' cellspacing='0' align='center' style='padding:0 5px'> <tr align='center'><td rowspan='2'>Pages:</td> <td style='padding:0 5px'><a href='http://localhost/cgi-bin/blosxom.cgi?_start=1'>Previous</a></td> <td style='padding:0 5px'><a href='http://localhost/cgi-bin/blosxom.cgi?_start=1' style='padding:0 5px'>1</a></td> <td style='padding:0 5px'>2</td> <td style='padding:0 5px'><a href='http://localhost/cgi-bin/blosxom.cgi?_start=21' style='padding:0 5px'>3</a> ... <td style='padding:0 5px'><a href='http://localhost/cgi-bin/blosxom.cgi?_start=5'>Next</a></td> </tr></table></div>

$moreentries::imagelinks - when set to 1 enables images links to preceding and following pages. It can be used independently or combined with the $moreentries::textlinks setting. The html generated if of the format:

<div class='pagelinks' style='padding:0 5px'> <table border='0' cellpadding='0' cellspacing='0' align='center' style='padding:0 5px'> <tr align='center'><td rowspan='2'>Pages:</td> <td style='padding:0 5px'><a href='http://localhost/cgi-bin/blosxom.cgi?_start=1' style='border-bottom:none'> <img src='/images/left.gif'/></a></td> <td style='padding:0 5px'><img src='/images/text.gif'/></td> <td style='padding:0 5px'><a href='http://localhost/cgi-bin/blosxom.cgi?_start=21' style='border-bottom:none'> <img src='/images/right.gif'/></a></td></tr></table></div>

Where the images used are specified in the following variables:

$moreentries::prevlinkimage - defines an image file to be displayed in a link to the previous page. If not defined no image link is created.

$moreentries::nextlinkimage - defines an image file to be displayed in a link to the next page. If not defined no image link is created.

$moreentries::currentpageimage - defines an image file to be displayed in a link to the current page. If not specified an image from @moreentries::pageimages is used.

@moreentries::pageimages - defines an array of images to use for each page number link. The images will be repeated in the order they are placed in the array.

The pagelink feature adds the following variables for your programming pleasure: $moreentries::totalpages - the number of pages in the site. $moreentres::currentpage - the current page number . $moreentries::pagelinks - the html contain the generated text and/or image links

Internals

This is a big ugly hack. The only entrypoint that worked for this is the filter() hook; the problem is that when filter() is called, the sort() routine hasn't run (isn't even decided on yet!), and %files contains all posts, not just the ones matching the request. Even running as filter, it has to be the last plugin to run, so that any other filtering happens before we decide the 'numbering' of the posts.

The way it works: when filter() is called, we check @plugins to see if moreentries is the last plugin. If not, we munge @plugins, making us the last plugin, and return. If we are the last plugin (as we eventually will be), then we proceed.

The next step is rather inefficient: we have to sort %files to number them, so we check all plugins for a sort() routine, providing a default if none is found. This code is stolen wholesale from blosxom.cgi. Once they are sorted, we get rid of all files that don't match the request url (anything in the wrong category, essentially). This code is also stolen from blosxom.cgi, with a couple of adjustments.

Finally, we delete all the posts before our start (as provided by the param _start), and all posts after our ending post. Thus, when filter is done, %files only contains the posts that will be displayed. This makes redundant much of the code that runs in blosxom after this.

Version

0+4i

Author

Jason Clark (jason@jclark.org; http://jclark.org/weblog)

Acknowledgements

Thanks to Fletcher T. Penny (http://fletcher.freeshell.org/) for helping test the plugin.

See Also

Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net

Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html

Bugs

This whole thing is a big hack, see the Internals section above for some info. This should probably be implemented as part of the core Blosxom application.

Not tested at all with static rendering, probably won't work.

License

This Blosxom Plug-in Copyright 2003, Jason Clark

(This license is the same as Blosxom's) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.