Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Blosxom Plug-in: authorcategory

by goober99 (Scribe)
on Jul 04, 2005 at 09:05 UTC ( #472179=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info Matthew Miller <goober99@myway.com>, http://www.swingthesickle.com
Description: Plugin for popular Perl weblog application, Blosxom, that allows you to link to all the articles written by the same author in the same way that you link to all the files in the same directory. The link $url/authors/name shows all the articles by "name." The link $url/authors creates a list of all the blog's authors.
# Blosxom Plugin: authorcategory
# Author(s): Matthew Miller <goober99@myway.com>
# Inspired by fauxami plugin by Rael Dornfest <rael@oreilly.com>
# Version: .1
# Documentation: See the bottom of this file or type: perldoc authorca
+tegory

package authorcategory;

# --- Configurable variables -----

# What should I consider a delimiter between poster's name and the res
+t of the
# filename (e.g. . for jack.story1.txt)?
my $delimiter = '\.';

# What should I consider a delimiter between the poster's first and la
+st name?
# (e.g. _ for John_Doe)?
my $namedelimiter = '_';

# What should I fall back to as the default name (leave blank for none
+)?
my $default_name = 'Staff';

# What should the category that generates the list of authors be calle
+d? Make
# sure you do not have a directory with the same name in your blosxom 
+$datadir.
my $topcategory_name = "authors";

# From how many posts back should authors be included?
my $postsbackto = 10000;

# --------------------------------

use File::stat;

my $authorname, $name, %allauthors, $dateflavour;

sub start {
  $blosxom::num_entries = $postsbackto;

  # Check URL to see if author category is being requested:
  $ENV{PATH_INFO} =~ m!^/($topcategory_name)(.*)!;
  (my $requested, $authorname) = ($1, $2);
  $authorname =~ s!/!!; # Remove slashes from requested author
  $blosxom::path_info = '';
  
  return ($requested eq $topcategory_name) ? 1 : 0;
}

sub template {
  return sub {
    my ($path, $chunk, $flavour) = @_;

    # Can't actually add date when date chunk is called, because it is
+ called
    # before &story is run and checks if the entry will be shown:
    return '' if ($chunk eq 'date');
    $dateflavour = $flavour; # Remember flavour so &story can grab it

    open(TEMPLATE, "<$blosxom::datadir/$chunk.$flavour");
    my $thischunk;
    while(<TEMPLATE>) { $thischunk .= $_ }
    close(TEMPLATE);
    return ( ($chunk ne 'story') || $authorname ) ? $thischunk : '$bod
+y';

  };
}

sub story {
  my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;

  $name = $filename =~ m!^(.+)$delimiter(.+)$! ? $1 : $default_name;
  # Convert underscores to spaces (allow for easy entry of first and l
+ast name):
  ($realname = $name) =~ s!$namedelimiter! !;

  if ( (!$authorname && $allauthors{$name}) || ( $authorname && ($name
+ ne $authorname) ) )
  # Don't list duplicate names and don't list stories not by requested
+ author:
  {
    $$story_ref = '';
    $$title_ref = '';
    $$body_ref = '';
  }
  elsif (!$authorname) {
    # Keep track of authors so that every author is listed only once:
    $allauthors{$name} = $realname;
    $$body_ref = qq(<a href="$blosxom::url/$topcategory_name/$name">$r
+ealname</a><br />);
  }
  else {
    # We now know the entry will be shown. Call in date template now a
+nd add it
    # in front of the $story_ref.
    open(DATETEMPLATE, "<$blosxom::datadir/date.$dateflavour");
    my $datetemplate;
    while(<DATETEMPLATE>) { $datetemplate .= $_ }
    close(DATETEMPLATE);
    $storytemplate = $$story_ref;
    $$story_ref = $datetemplate . $storytemplate;
  }

  1;
}

1;

__END__

=head1 NAME

Blosxom Plug-in: authorcategory - Creates a list of authors and links 
+to all
the articles by an author

=head1 SYNOPSIS

Allows you to link to all the articles written by the same author in t
+he same
way that you link to all the files in the same directory. The link
$url/authors/name shows all the articles by "name." The link $url/auth
+ors
creates a list of all the blog's authors.

This plugin is meant for blogs with multiple authors and was inspired 
+by the
fauxami plugin by Rael Dornfest. As in the fauxami plugin, anything be
+fore a
specified delimiter ( the default is . ) is the name of the author. In
+ addition,
underscores are converted to spaces so that John_Doe.story.txt is disp
+layed as
"John Doe." You can configure what URL generates the list of authors.

=head1 DESCRIPTION

Name your story files "Author_Name.story.txt" where "Author_Name" is t
+he name of
the story's author. authorcategory will display "Author_Name" as "Auth
+or Name."
See the configuration variables to change the delimiter. Upload your s
+tory files
to your blosxom data folder.

Drop this file into your blosxom plugin folder. In your broswer's addr
+ess bar,
type the URL to blosxom on your server slash authors
(e.g. http://yoursite.com/authors) to see this plugin in action. The U
+RL that
generates the list of authors can be configured. Authors are listed in
+ order of
most recent poster. Each author links to a page of all the stories by 
+that
author.

You can access the page of all the stories by an author by adding a sl
+ash and
the author's name after the URL to generate the author list:
/authors/author_name.

=head1 CONFIGURABLE VARIABLES

All the configurable variables are found at the top of the plugin.

=over 4

=item B<$delimiter>

Same as in the fauxami plugin. Divides the author's name from the rest
+ of the
filename. (Default is the dot [.])

=item B<$namedelimiter>

This is a modification of the fauxami plugin that allows you to easily
+ format
the first and last name of an author. This divides the first and last 
+name and
is replaced with a space. If you use usernames that contain underscore
+s (_), you
may want to change the default for this variable. (Default is the unde
+rscore
[_])

=item B<$default_name>

Same as in fauxami plugin. Used as author's name for posts that do not
+ include
a delimiter. (Default is "Staff")

=item B<$topcategory_name>

This is the keyword used in the URL to generate the list of authors. M
+ake sure
you do not have a directory in your blosxom data directory with the sa
+me name.
(Default is "authors")

=item B<$postsbackto>

Since Blosxom only evaluates a limited number of posts, specify how ma
+ny posts
back you want the plugin to search for authors. (Default is 10000)

=head1 VERSION

.1

=head1 AUTHOR

Matthew Miller <goober99@myway.com>, http://www.swingthesickle.com

Inspired by and bits of code stolen from the fauxami plugin by:
Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/

=head1 SEE ALSO

Fauxami Plugin: http://www.blosxom.com/plugins/author/fauxami.htm

Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/

Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml

=head1 LICENSE

Blosxom
Copyright 2003, Rael Dornfest

authorcategory plugin
Copyright 2005, Matthew Miller

Permission is hereby granted, free of charge, to any person obtaining 
+a
copy of this software and associated documentation files (the "Softwar
+e"),
to deal in the Software without restriction, including without limitat
+ion
the rights to use, copy, modify, merge, publish, distribute, sublicens
+e,
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 include
+d
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRES
+S OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILIT
+Y,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHAL
+L
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://472179]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-01-25 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (65 votes). Check out past polls.

    Notices?