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