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