]> git.imager.perl.org - bse.git/blame - site/docs/dynamic.pod
add a format() method to articles for use in templates
[bse.git] / site / docs / dynamic.pod
CommitLineData
16901a2a
TC
1=head1 NAME
2
3dynamic.pod - dynamic article generation for BSE.
4
5=head1 SYNOPSIS
6
7The 0.15 series of BSE from 0.15_19 on, stable around 0.15_28, added
8the ability for articles to be generated upon presentation to the
9user.
10
11=head1 MAKING ARTICLES DYNAMIC
12
13There are four ways an article can be set to be dynamically generated:
14
15=over
16
17=item *
18
19an article that has any sort of user access controls on it is
20generated dynamically.
21
22=item *
23
24an article with the B<Always dynamic> checkbox checked will be
25generated dynamically.
26
27=item *
28
29an article with any ancestor that has the B<Always dynamic> and
30B<Descendants inherit Always Dynamic> flags set.
31
32=item *
33
34if the C<all_dynamic> flag is set in the [basic] section of
35C<bse.cfg>.
36
37=back
38
39=head2 Access controls
40
41BSE 0.15_21 added the ability to restrict siteuser access to articles
42based on their membership in a group. Articles inherit these access
43controls from their parent articles if they have the B<Inherit Parent
44groups> flag set.
45
46If an article has an group requirements, either set on the article
47itself or inherited from an ancestor article, then that article will
48be generated dynamically.
49
50=head2 Always Dynamic flag
51
52If you set the B<Always dynamic> flag on an article then that article
53is generated dynamically.
54
55=head2 Inherited Always Dynamic flag
56
57If you set the B<Always dynamic> and B<Descendants inherit Always
58Dynamic> flags on an article then that article and all of its
59descendants (not stepchildren) will be generated dynamically.
60
61=head2 Via bse.cfg
62
63If you set the C<all_dynamic> key in the C<[basic]> section of
64C<bse.cfg> to a non-zero value then all articles will be generated
65automatically.
66
67Note: you will need to perform web server configuration to point
68requests for C<http://your.site/> at
69C<http://your.site/cgi-bin/page.pl?id=1>, and similarly for the RSS
70article, otherwise the user will not see generated content for these
71articles. See L<Fixed Links> below.
72
73=head1 PROCESSING OF DYNAMIC ARTICLES
74
75Dynamic articles are processing in 2 stages:
76
77=over
78
79=item 1.
80
81static tag replacement - at this point all of the normal static page
82tags are replaced. The resulting template is saved to the dynamic cache.
83
84=item 2.
85
86dynamic tag replacement - tags specific to dynamic generation are
87replaced at this point, and the article is sent to the user.
88
89=back
90
91=head2 Static tag replacement
92
93This is the same as tag replacement for a static page, except:
94
95=over
96
97=item *
98
99the page is stored in the dynamic cache instead of in the web server
100document tree.
101
102=item *
103
104the ifDynamic tag is true.
105
106=back
107
108Depending on configuration, this can be done either during normal
109site/article regeneration or just prior to page.pl displaying the
110page. See L<Just in time processing>.
111
112=head2 Dynamic tag replacement
113
114Dynamic tags are replaced and the page presented to the user.
115
116The content type sent to the browser is based on the original template
117of the article, so you can set a key to give your template a different
118type from text/html but setting it in the C<[template types]> section
119of bse.cfg.
120
121This is done by the page.pl script.
122
123=head2 Just in time processing
124
125Normally when you regenerate a dynamically generated article BSE will
126perform the first pass immediately and save that to the dynamic cache.
127If your site is large and you do a full site regen this can be very
128time consuming.
129
130If you set C<jit_dynamic_regen> in C<[basic]> in bse.cfg, then
131attempting to regenerate the page (including the regen normally done
132on saving an article) will instead simply delete the pregenerated page
133from the dynamic cache.
134
135Then when the user attempts to display the page, C<page.pl> will
136notice the missing page, pregenerate it and store it in the cache, and
137then proceed to normal dynamic page processing.
138
139This means for large sites that you're only generating the pages that
140users are actually looking at.
141
142Note that if a large percentage of your site is looked at in a day
143you're probably better off not using this option, since it will
144increase the load on your web server instead of reducing it.
145
146If your web server normally suffers from high peak-time loads, you
147should probably not use this, since it moves most page processing to
148peak-time.
149
150=head1 TAGS
151
152All normal dynamic tags are available during dynamic tag processing,
153including:
154
155=over
156
157=item *
158
159script - value of SCRIPT_NAME (CGI variable) - name of the current script
160
161=item *
162
163cgi I<fieldname> - submitted CGI parameters
164
165=item *
166
167old I<fieldname> I<default-func> I<default-args> - access to submited
168CGI parameteres with defaults.
169
170=item *
171
172dynreplace I<source> I<regexp> I<replacement> - replace regular
173expression.
174
175=item *
176
177dyntoday
178
179=item *
180
181dyntoday "I<dateformat>" - formatted current date
182
183=item *
184
185dynreport I<reportname> I<template> I<arg1> ... - dynamic report
186embedding
187
188=back
189
190The following tags are available on all user side dynamic pages
191(search page, shop pages, etc):
192
193=over
194
195=item *
196
197user I<field> - access to information from the currently logged on siteuser
198
199=item *
200
201ifUser - test if there is a currently logged on siteuser
202
203=item *
204
205ifUserCanSee I<which> - test if the user has access to the given
206article. Note: I<which> must refer to a dynamic article tag (of which
207there aren't many yet), or an article by number.
208
209=back
210
211The following tags can be used on dynamically generated article pages
212(as per page.pl):
213
214=over
215
216=item *
217
218dynarticle I<fieldname> - access to information from the current article.
219
220=back
221
222There are no dynamic tags specific to catalogs, products or seminars
223at this point.
224
225=head1 TRAPS
226
227=head2 Two Pass Generation
228
229Since dynamic pages are generated in two passes a single tag cannot
230rely upon tags from the two separate passes.
231
232For example:
233
234 if Or [ifUser] [ifAdmin]
235
236won't work because ifUser is a dynamic tag and ifAdmin is a static
237tag.
238
239=head2 Fixed Links
240
241Some articles, like article 1, the home page, and article 3 the main
242shop article have protected links, by having an entry in the
243C<[protect link]> section of C<bse.cfg>.
244
245If these articles become dynamic by any of the mechanisms listed in
246L<MAKING ARTICLES DYNAMIC> then links to these articles will be
247broken.
248
249For all articles except the home page article you can remove these
250entries, and your site will work again.
251
252The home page article will need extra web server configuration, you
253will need to add a rewrite rule to redirect C<http://your.site/> to
254C<http://your.site/cgi-bin/page.pl?id=1> or whatever other tool your
255web server provides with the same functionality.
256
8f84f3f1
TC
257=head1 Persistent page.pl
258
259There are 2 ways to run page.pl as persistent servers, to reduce
260startup cost:
261
262=over
263
264=item *
265
266run page.pl using Apache::Registry under mod_perl
267
268=item *
269
270run page.fcgi under FastCGI
271
272=item *
273
274set BSE::Handler::Page as a mod_perl handler for page.pl
275
276=back
277
278=head2 page.pl and Apache::Registry
279
280This has the severe limitation that you can only run one page.pl per
281Apache server, due to limitations in BSE.
282
283To configure Apache to run page.pl via mod_perl, add the following to
284your virtual host configuration:
285
286 PerlModule Apache::Registry
287 <Location /cgi-bin/page.pl>
288 SetHandler perl-script
289 PerlHandler Apache::Registry
290 Options ExecCGI
291 </Location>
292
293=head2 page.fcgi and FastCGI
294
295You will need to configure Apache to use mod_fastcgi.
296
297First, Apache needs to be configured to use FastCGI, you may need to
298install it from source, then configure it:
299
300 LoadModule fastcgi_module /usr/lib/apache/1.3/mod_fastcgi.so
301
302Then configure your vhosts cgi-bin directory to run .fcgi scripts with
303fastcgi:
304
305 <Directory /var/www/httpd/bsetest/cgi-bin/>
306 AllowOverride All
307 AddHandler fastcgi-script fcgi
308 </Directory>
309
310Check this works with:
311
312 http://your.site/cgi-bin/page.fcgi?page=1
313
314Then setup a rewrite rule:
315
316 RewriteRule ^/cgi-bin/page.pl(.*) /cgi-bin/page.fcgi$1 [PT]
317
318=head2 BSE::Handler::Page
319
320This sets a native mod_perl hander to process page.pl requests:
321
322First, let perl know where the BSE libraries are:
323
324 <Perl>
325 use lib '/yourpath/cgi-bin/modules';
326 </Perl>
327
328Now load the module, and set it as the handler for page.pl:
329
330 PerlModule BSE::Handler::Page;
331 <Location /cgi-bin/page.pl>
332 PerlSetVar BSEConfig /var/www/httpd/bsetest/cgi-bin/
333 SetHandler perl-script
334 PerlHandler BSE::Handler::Page
335 Options ExecCGI
336 </Location>
337
338The PerlSetVar line should set BSEConfig to the directory containing
339your bse.cfg file, not to the file itself.
340
16901a2a
TC
341=head1 AUTHOR
342
343Tony Cook <tony@develop-help.com>
344
345=head1 REVISION
346
347$Revision$
348
349=cut