2 package IkiWiki
::Plugin
::sidebar2
;
6 IkiWiki::Plugin::sidebar2 - Improved version of IkiWiki::Plugin::sidebar
10 This describes version B<0.1> of IkiWiki::Plugin::sidebar2
18 Improved version of IkiWiki::Plugin::sidebar2. Main features are:
20 - allowing several sidebars;
21 - enabling sidebars using pagespects.
23 See doc/plugins/sidebar2.mdwn for documentation.
31 http://atelier.gresille.org/projects/gresille-ikiwiki/wiki/Sidebar2
32 http://ikiwiki.info/plugins/contrib/sidebar2/
36 Tuomo Valkonen wrote the original Ikiwiki::plugin::sidebar.
37 Others (on http://ikiwiki.info) helped to improve it.
38 Louis Paternault (spalax) <spalax at gresille dot org> improved it to write Ikiwiki::plugin::sidebar2.
42 Copyright 2006 Tuomo Valkonen <tuomov at iki dot fi>
43 Copyright 2013 by Louis Paternault <spalax at gresille dot org>
45 This program is free software; you can redistribute it and/or modify
46 it under the terms of the GNU General Public License as published by
47 the Free Software Foundation; either version 2 of the License, or
48 (at your option) any later version.
50 This program is distributed in the hope that it will be useful,
51 but WITHOUT ANY WARRANTY; without even the implied warranty of
52 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 GNU General Public License for more details.
55 You should have received a copy of the GNU General Public License
56 along with this program; if not, write to the Free Software
57 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
66 hook
(type
=> "checkconfig", id
=> "sidebar2", call
=> \
&checkconfig
);
67 hook
(type
=> "getsetup", id
=> "sidebar2", call
=> \
&getsetup
);
68 hook
(type
=> "preprocess", id
=> "sidebar", call
=> \
&preprocess
);
69 hook
(type
=> "pagetemplate", id
=> "sidebar2", call
=> \
&pagetemplate
);
75 if (defined $config{global_sidebars
} and (ref($config{global_sidebars
}) eq "ARRAY")) {
76 my $length = $#{$config{global_sidebars}}+1;
77 if (($length % 3) != 0) {
78 error
("'sidebars' length must be a multiple of 3.");
80 for(my $i=0; $i<$length/3;$i += 1) {
81 unless(exists($sidebars{$config{global_sidebars
}[3*$i]})) {
82 $sidebars{$config{global_sidebars
}[3*$i]} = ();
85 @
{$sidebars{$config{global_sidebars
}[3*$i]}},
87 $config{global_sidebars
}[3*$i+1],
88 $config{global_sidebars
}[3*$i+2],
93 if (not defined $config{global_sidebars
}) {
94 $config{global_sidebars
} = 1;
96 if (IkiWiki
::yesno
($config{global_sidebars
})) {
98 "sidebar" => [["sidebar", "*"]]
103 @
{$config{sidebars
}} = %sidebars;
115 description
=> "show sidebar page on all pages?",
126 my $page=$params{page
};
127 return "" unless $page eq $params{destpage
};
129 if (! defined $params{var
}) {
130 $params{var
} = "sidebar";
132 if (! defined $params{content
}) {
133 $pagesidebar{$page}{$params{var
}}=undef;
136 my $file = $pagesources{$page};
137 my $type = pagetype
($file);
139 unless(exists($pagesidebar{$page})) {
140 $pagesidebar{$page} = ();
142 $pagesidebar{$page}{$params{var
}} = IkiWiki
::htmlize
($page, $page, $type,
143 IkiWiki
::linkify
($page, $page,
144 IkiWiki
::preprocess
($page, $page, $params{content
})));
153 sub sidebar_content
($$$$) {
154 my $templatevar=shift;
159 return delete $pagesidebar{$page}{$templatevar} if defined $pagesidebar{$page}{$templatevar};
161 return if ! exists $pagesidebar{$page}{$templatevar} &&
162 ! pagespec_match
($page, $pagespec)
165 my $sidebar_page=bestlink
($page, $included) || return;
166 my $sidebar_file=$pagesources{$sidebar_page} || return;
167 my $sidebar_type=pagetype
($sidebar_file);
169 if (defined $sidebar_type) {
170 # FIXME: This isn't quite right; it won't take into account
171 # adding a new sidebar page. So adding such a page
172 # currently requires a wiki rebuild.
173 add_depends
($page, $sidebar_page);
176 if (defined $oldfile && $sidebar_file eq $oldfile) {
177 $content=$oldcontent;
180 $content=readfile
(srcfile
($sidebar_file));
181 $oldcontent=$content;
182 $oldfile=$sidebar_file;
185 return unless length $content;
186 return IkiWiki
::htmlize
($sidebar_page, $page, $sidebar_type,
187 IkiWiki
::linkify
($sidebar_page, $page,
188 IkiWiki
::preprocess
($sidebar_page, $page,
189 IkiWiki
::filter
($sidebar_page, $page, $content))));
194 sub pagetemplate
(@
) {
197 my $template=$params{template
};
198 my %sidebars = @
{$config{sidebars
}};
199 if ($params{destpage
} eq $params{page
}) {
200 foreach my $templatevar (keys(%sidebars)) {
201 if ($template->query(name
=> $templatevar) and exists($sidebars{$templatevar})) {
202 for my $data (@
{$sidebars{$templatevar}}) {
203 my $content=sidebar_content
($templatevar, $params{destpage
}, @
{$data}[0], @
{$data}[1]);
204 if (defined $content && length $content) {
205 $template->param($templatevar => $content);