Add a bunch of Rael plugins.
[matthijs/upstream/blosxom-plugins.git] / general / google_highlight
1 # Blosxom Plugin: google_highlight
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 # Version: 2003-09-09
4 # Documentation: See the bottom of this file or type: perldoc google_highlight
5
6 package google_highlight;
7
8 # --- Configurable variables -----
9
10 # none, null, nada, nothing, zip, zero, zilch
11
12 # --------------------------------
13
14 my $query;
15
16 sub start {
17   my $referer = $ENV{'HTTP_REFERER'};
18
19   ($query) = $referer =~ m#^http://(?:www\.)?google.*q=([^\&]+)#i or return 0;
20   $query =~ s#['"]##g;
21   $query = join '|', split /[\s,\+\.]+/, $query;
22   
23   1;
24 }
25
26 sub story {
27   my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
28
29   $$body_ref =~ s#(?<=>)([^<]+)?\b($query)\b#$1<span class="highlight">$2</span>#gis;
30 }
31
32 1;
33
34 __END__
35
36 =head1 NAME
37
38 Blosxom Plug-in: google_highlight
39
40 =head1 SYNOPSIS
41
42 Highlights any Google search terms used to find your weblog. 
43
44 An adaptation of Dean Allen's [http://www.textism.com/] Google 
45 Hilite [http://www.textism.com/tools/google_hilite/].
46
47 =head1 VERSION
48
49 2003-09-09
50
51 =head1 AUTHOR
52
53 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
54
55 =head1 INSTALLATION
56
57 Drop the interpolate_fancy plug-in into your Blosxom plugins folder.
58
59 Add a "highlight" style to your document or CSS style sheet, e.g.:
60
61 <html>
62 <head>
63 <style>
64 .highlight { background-color: #FF9; }
65 </style>
66 </head>
67 <body>
68 ...
69 </body>
70 </html>
71
72 =head1 USAGE
73
74 Search Google for something that'll lead you to your weblog.  Follow
75 the Google link and notice the terms used in your search are highlighted
76 in your weblog.
77
78 =head1 SEE ALSO
79
80 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
81
82 Blosxom Plugin User Docs: 
83   http://blosxom.sourceforge.net/documentation/users/plugins.html
84 Blosxom Plugin Developer Docs: 
85   http://blosxom.sourceforge.net/documentation/developers/plugins.html
86
87 Dean Allen's Textism [http://www.textism.com/]
88 Dean Allen's Google Hilite [http://www.textism.com/tools/google_hilite/]
89
90 =head1 BUGS
91
92 Address bug reports and comments to the Blosxom mailing list 
93 [http://www.yahoogroups.com/group/blosxom].
94
95 =head1 LICENSE
96
97 Blosxom and this Blosxom Plug-in
98 Copyright 2003, Rael Dornfest 
99
100 Permission is hereby granted, free of charge, to any person obtaining a
101 copy of this software and associated documentation files (the "Software"),
102 to deal in the Software without restriction, including without limitation
103 the rights to use, copy, modify, merge, publish, distribute, sublicense,
104 and/or sell copies of the Software, and to permit persons to whom the
105 Software is furnished to do so, subject to the following conditions:
106
107 The above copyright notice and this permission notice shall be included
108 in all copies or substantial portions of the Software.
109
110 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
111 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
112 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
113 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
114 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
115 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
116 OTHER DEALINGS IN THE SOFTWARE.