Add various plugins from Mark Ivey.
[matthijs/upstream/blosxom-plugins.git] / general / seemore
1 # Blosxom Plugin: seemore                                          -*- perl -*-
2 # Author: Todd Larason (jtl@molehill.org)
3 # Version: 0+3i
4 # Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom
5 # SeeMore plugin Home/Docs/Licensing:
6 #   http://molelog.molehill.org/blox/Computers/Internet/Web/Blosxom/SeeMore/
7
8 package seemore;
9
10 # --- Configuration Variables ---
11 # regular expression to split on
12 $seemore_split ||= qr/\f|<!-- more -->/;
13
14 # show the whole artcile on individual article pages?  Good for summaries,
15 # not so good for spoiler protection
16 $more_on_article = 1 unless defined $more_on_article;
17
18 $debug_level = 1 unless defined $debug_level;
19 # ----------------------------------------------------------------------
20
21 use FileHandle;
22 use CGI;
23 my $package = 'seemore';
24
25 sub debug {
26     my ($level, @msg) = @_;
27
28     if ($debug_level >= $level) {
29         print STDERR "$package debug $level: @msg\n";
30     }
31 }
32
33 sub load_template {
34     my ($bit) = @_;
35     return $blosxom::template->('', "$package.$bit", $blosxom::flavour);
36 }
37
38 sub report {
39     my ($bit, $path, $fn) = @_;
40
41     my $f = load_template($bit);
42     $f =~ s/((\$[\w:]+)|(\$\{[\w:]+\}))/$1 . "||''"/gee;
43     return $f;
44 }
45
46 sub show_more_p {
47   return 1 if $more_on_article and $blosxom::path_info =~ m:\.:;
48   return 1 if (CGI::param("seemore"));
49 # XXX return 1 if google/&c spider?
50   return 0;
51 }
52
53 sub start {
54   debug(1, "start() called, enabled");
55   while (<DATA>) {
56     last if /^(__END__)?$/;
57     my ($flavour, $comp, $txt) = split ' ',$_,3;
58     $txt =~ s:\\n:\n:g;
59     $blosxom::template{$flavour}{"$package.$comp"} = $txt;
60   }
61   return 1;
62 }
63
64 sub story {
65   my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
66
67   debug(2, "story() called");
68   my $more;
69   ($$body_ref, $more) = split $seemore_split, $$body_ref, 2;
70   if ($more) {
71     debug(2, "story() found more");
72     if (show_more_p()) {
73       $$body_ref .= report('divider', $path, $filename) . $more;
74     } else {
75       $$body_ref .= report('showmore', $path, $filename);
76     }
77   }
78   return 1;
79 }
80 1;
81 __DATA__
82 error divider <hr class="seemore">\n
83 error showmore <p><a href="$blosxom::url$path/$fn.$blosxom::flavour?seemore=y" class="seemore">See more ...</a></p>\n
84 rss showmore <p><a href="$blosxom::url$path/$fn.$blosxom::default_flavour?seemore=y" class="seemore">See more ...</a></p>\n
85 __END__
86
87 =head1 NAME
88
89 Blosxom Plug-in: seemore
90
91 =head1 SYNOPSIS
92
93 Purpose: Allows for long or spoiler-y posts to be split, with a "See more..." link
94
95 =head1 VERSION
96
97 0+2i
98
99 2nd test release
100
101 =head1 AUTHOR
102
103 Todd Larason  <jtl@molehill.org>, http://molelog.molehill.org/
104
105 =head1 BUGS
106
107 None known; address bug reports and comments to me or to the Blosxom
108 mailing list [http://www.yahoogroups.com/groups.blosxom].
109
110 =head1 Customization
111
112 =head2 Configuration variables
113
114 C<$seemore_split> is the regular expression used to find where to
115 split stories; the default matches either a form-feed character (as in
116 0+1i) or the string "<!-- more -->" (recommended for most peoples'
117 use).
118
119 C<$more_on_article> controls whether the full article is shown on
120 individual article pages, or only on pages with the special 'seemore' 
121 argument; it defaults to on (0+3i: this is a change of behavior from
122 previous versions).  Turning this on makes sense if you're using seemore
123 to put summaries on a main index paage, but probably not if you're using it
124 for spoiler protection.
125
126 C<$debug_level> can be set to a value between 0 and 5; 0 will output
127 no debug information, while 5 will be very verbose.  The default is 1,
128 and should be changed after you've verified the plugin is working
129 correctly.
130
131 =head2 Classes for CSS control
132
133 There's a class used, available for CSS customization.
134
135   * C<seemore> -- the <hr> dividing the short version of the story
136     from the rest, in the full-story view, and the <a> for the "See
137     more ..." link in the short view.
138
139 =head2 Flavour-style files
140
141 If you want a format change that can't be made by CSS, you can
142 override the HTML generated by creating files similar to Blosxom's
143 flavour files.  They should be named seemore.I<bit>.I<flavour>; for
144 available I<bit>s and their default meanings, see the C<__DATA__>
145 section in the plugin.
146
147 =head1 LICENSE
148
149 this Blosxom Plug-in
150 Copyright 2003, Todd Larason
151
152 (This license is the same as Blosxom's)
153
154 Permission is hereby granted, free of charge, to any person obtaining a
155 copy of this software and associated documentation files (the "Software"),
156 to deal in the Software without restriction, including without limitation
157 the rights to use, copy, modify, merge, publish, distribute, sublicense,
158 and/or sell copies of the Software, and to permit persons to whom the
159 Software is furnished to do so, subject to the following conditions:
160
161 The above copyright notice and this permission notice shall be included
162 in all copies or substantial portions of the Software.
163
164 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
165 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
167 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
168 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
169 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
170 OTHER DEALINGS IN THE SOFTWARE.
171
172