3
* This file loads and initializes the blog to be displayed.
5
* This file is part of the Quam Plures project - {@link http://quamplures.net/}.
6
* See also {@link https://launchpad.net/quam-plures}.
8
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
9
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
10
* Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
12
* @license http://quamplures.net/license.html GNU General Public License (GPL)
14
* {@internal Open Source relicensing agreement:
15
* Daniel HAHLER grants Francois PLANQUE the right to license
16
* Daniel HAHLER's contributions to this file and the b2evolution project
17
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
20
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
21
* @author blueyed: Daniel HAHLER
22
* @author fplanque: Francois PLANQUE
3
* This file loads and initializes the blog to be displayed
5
* @author {@link http://wonderwinds.com/ Ed Bennett}
6
* @author {@link http://daniel.hahler.de/ Daniel HAHLER}
7
* @author {@link http://fplanque.net/ Francois PLANQUE}
8
* @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
9
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
27
if( !defined('QP_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
12
if(!defined('QP_CONFIG_LOADED')) die('fail');
30
* Initialize everything:
15
* Initialize everything
32
17
require_once dirname(__FILE__).'/_main.inc.php';
34
load_funcs('templates/_template.funcs.php');
35
load_class('items/model/_itemlist.class.php');
19
load_funcs( 'templates/_template.funcs.php' );
37
21
$Timer->start( '_blog_main.inc' );
41
* blog ID. This is a little bit special.
43
* In most cases $blog should be set by a stub file and the param() call below will just check that it's an integer.
45
* Note we do NOT memorize the param as we don't want it in regenerate_url() calls.
46
* Whenever we do, index.php will already have called param() with memorize=true
48
* In some cases $blog will not have been set before and it will be set with the param() call below.
49
* Currently, this only happens with the old /qp_srvc/ RSS stubs.
23
// blog ID. This is a little bit special. In most cases $blog should be set by a
24
// stub file and the param() call below will just check that it's an integer. Note
25
// we do NOT memorize the param as we don't want it in regenerate_url() calls. Whenever
26
// we do, index.php will already have called param() with memorize=true In some cases
27
// $blog will not have been set before and it will be set with the param() call below.
28
// Currently, this only happens with the old /qp_srvc/ RSS stubs.
51
29
param( 'blog', 'integer', '', false );
53
// Getting current blog info:
31
// Getting current blog info
54
32
$BlogCache = & get_Cache( 'BlogCache' );
58
33
$Blog = & $BlogCache->get_by_ID( $blog, false, false );
59
34
if( empty( $Blog ) )
61
require $templates_path.'_404_blog_not_found.main.php'; // error & exit
37
require $templates_path.'_404_blog_not_found.main.php';
67
41
param( 'disp', 'string', 'posts', true );
72
* _______________________________ Locale / Charset for the Blog _________________________________
74
TODO: blueyed>> This should get moved as default to the locale detection in _main.inc.php,
75
as we only want to activate the I/O charset, which is probably the user's..
76
It prevents using a locale/charset in the front office, apart from the one given as default for the blog!!
77
fp>there is no blog defined in _main and there should not be any
78
blueyed> Sure, but that means we should either split it, or use the locale here only, if there's no-one given with higher priority.
80
// Activate matching locale:
81
$Debuglog->add( 'Activating blog locale: '.$Blog->get('locale'), 'locale' );
44
// Locale / Charset for the Blog - activate matching locale
82
45
locale_activate( $Blog->get('locale') );
85
// Re-Init charset handling, in case current_charset has changed:
47
// Re-Init charset handling, in case current_charset has changed
86
48
if( init_charsets( $current_charset ) )
88
// Reload Blog(s) (for encoding of name, tagline etc):
91
$Blog = & $BlogCache->get_by_ID( $blog );
96
* _____________________________ Extra path info decoding ________________________________
98
* This will translate extra path into 'regular' params.
100
* Decoding should try to work like this:
102
* baseurl/blog-urlname/junk/.../junk/post-title -> points to a single post (no ending slash)
103
* baseurl/blog-urlname/junk/.../junk/p142 -> points to a single post
104
* baseurl/blog-urlname/2006/ -> points to a yearly archive because of ending slash + 4 digits
105
* baseurl/blog-urlname/2006/12/ -> points to a monthly archive
106
* baseurl/blog-urlname/2006/12/31/ -> points to a daily archive
107
* baseurl/blog-urlname/2006/w53/ -> points to a weekly archive
108
* baseurl/blog-urlname/junk/.../junk/chap-urlname/ -> points to a single chapter/category (because of ending slash)
109
* Note: category names cannot be named like this [a-z][0-9]+
111
if( ! isset( $resolve_extra_path ) ) { $resolve_extra_path = true; }
50
// Reload Blog(s) (for encoding of name, tagline etc)
52
$Blog = & $BlogCache->get_by_ID( $blog );
55
// Extra path info decoding. This will translate extra path into 'regular' params.
56
// Decoding should try to work like this:
57
// - baseurl/blog-urlname/junk/.../junk/post-title -> points to a single post (no ending slash)
58
// - baseurl/blog-urlname/junk/.../junk/p142 -> points to a single post
59
// - baseurl/blog-urlname/2006/ -> points to a yearly archive because of ending slash + 4 digits
60
// - baseurl/blog-urlname/2006/12/ -> points to a monthly archive
61
// - baseurl/blog-urlname/2006/12/31/ -> points to a daily archive
62
// - baseurl/blog-urlname/2006/w53/ -> points to a weekly archive
63
// - baseurl/blog-urlname/junk/.../junk/cat-urlname/ -> points to a single category (because of ending slash)
64
// Note: category names cannot be named like this [a-z][0-9]+
65
if( ! isset( $resolve_extra_path ) )
67
$resolve_extra_path = true;
112
70
if( $resolve_extra_path )
114
// Check and Remove blog base URI from ReqPath:
72
// Check and Remove blog base URI from ReqPath
115
73
$blog_baseuri = substr( $Blog->gen_baseurl(), strlen( $Blog->get('baseurlroot') ) );
116
$Debuglog->add( 'blog_baseuri: "'.$blog_baseuri.'"', 'params' );
119
76
$blog_baseuri_regexp = preg_replace( '�(\.php[0-9]?)?/?$�', '', $blog_baseuri );
120
// Readd possibilities in order to get a broad match:
77
// Read possibilities in order to get a broad match
121
78
$blog_baseuri_regexp = '�^'.preg_quote( $blog_baseuri_regexp ).'(\.php[0-9]?)?/(.+)$�';
123
80
if( preg_match( $blog_baseuri_regexp, $ReqPath, $matches ) )
124
{ // We have extra path info
82
// We have extra path info
125
83
$path_string = $matches[2];
127
$Debuglog->add( 'Extra path info found! path_string=' . $path_string , 'params' );
129
84
// Replace encoded ";" and ":" with regular chars (used for tags)
130
// TODO: dh> why not urldecode it altogether? fp> would prolly make sense but requires testing -- note: check with tags (move urldecode from tags up here)
131
// TODO: PHP5: use str_ireplace
132
85
$path_string = str_replace(
133
array('%3b', '%3B', '%3a', '%3A'),
134
array(';', ';', ':', ':'),
86
array( '%3b', '%3B', '%3a', '%3A' ),
87
array( ';', ';', ':', ':' ),
138
91
$path_elements = preg_split( '~/~', $path_string, 20, PREG_SPLIT_NO_EMPTY );
140
93
if( isset( $path_elements[0] )
141
94
&& ( $path_elements[0] == $Blog->stub
142
95
|| $path_elements[0] == $Blog->urlname
143
96
|| $path_elements[0] == 'index.php' ) )
144
{ // Ignore stub files, blog url names, and index.php
98
// Ignore stub files, blog url names, and index.php
145
99
array_shift( $path_elements );
146
$Debuglog->add( 'Ignoring stub filename, blog urlname, or index.php in extra path info' , 'params' );
149
102
if( isset( $path_elements[0] )
150
103
&& ( substr_count( $path_elements[0], '.' ) != 0 )
151
104
&& is_file( $basepath.$path_elements[0] ) )
152
{ // Ignore filenames that exist in root
106
// Ignore filenames that exist in root
153
107
array_shift( $path_elements );
154
$Debuglog->add( 'Ignoring filenames that exist as installation root files in extra path info' , 'params' );
157
110
// Do we still have extra path info to decode?
158
111
if( count($path_elements) )
160
// TODO: dh> add plugin hook here, which would allow to handle path elements (name spaces in clean URLs), and to override internal functionality (e.g. handle tags in a different way).
161
113
// Is this a tag ("prefix-only" mode)?
162
if( $Blog->get_setting('tag_links') == 'prefix-only'
114
if( $Blog->get_setting( 'tag_links' ) == 'prefix-only'
163
115
&& count($path_elements) == 2
164
&& $path_elements[0] == $Blog->get_setting('tag_prefix')
116
&& $path_elements[0] == $Blog->get_setting( 'tag_prefix' )
165
117
&& isset($path_elements[1]) )
167
119
$tag = strip_tags(urldecode($path_elements[1]));
169
// # of posts per page for tag page:
120
// # of posts per page for tag page
170
121
if( ! $posts = $Blog->get_setting( 'tag_posts_per_page' ) )
171
{ // use blog default
172
124
$posts = $Blog->get_setting( 'posts_per_page' );
177
129
// Does the pathinfo end with a / or a ; ?
178
130
$last_char = substr( $path_string, -1 );
179
131
$last_part = $path_elements[count( $path_elements )-1];
180
$last_len = strlen( $last_part );
132
$last_len = strlen( $last_part );
181
133
if( ( $last_char == '-' && ( ! $tags_dash_fix || $last_len != 40 ) ) || $last_char == ':'|| $last_char == ';' )
182
{ // - : or ; -> We'll consider this to be a tag page
135
// - : or ; -> We'll consider this to be a tag page
183
136
$tag = substr( $last_part, 0, -1 );
184
137
$tag = urldecode($tag);
185
$tag = strip_tags($tag); // security
138
$tag = strip_tags($tag); // security
187
140
// # of posts per page:
188
141
if( ! $posts = $Blog->get_setting( 'tag_posts_per_page' ) )
189
{ // use blog default
190
144
$posts = $Blog->get_setting( 'posts_per_page' );
193
147
elseif( ( $tags_dash_fix && $last_char == '-' && $last_len == 40 ) || $last_char != '/' )
194
{ // NO ENDING SLASH or ends with a dash, is 40 chars long and $tags_dash_fix is true
195
// -> We'll consider this to be a ref to a post.
196
$Debuglog->add( 'We consider this o be a ref to a post - last char: '.$last_char, 'params' );
149
// NO ENDING SLASH or ends with a dash, is 40 chars long and $tags_dash_fix is true
150
// -> We'll consider this to be a reference to a post.
198
// Set a lot of defaults as if we had received a complex URL:
152
// Set a lot of defaults as if we had received a complex URL
200
154
$more = 1; // Display the extended entries' text
201
$c = 1; // Display comments
202
$tb = 1; // Display trackbacks
155
$c = 1; // Display comments
156
$tb = 1; // Display trackbacks
204
158
if( preg_match( '#^p([0-9]+)$#', $last_part, $req_post ) )
205
{ // The last param is of the form p000
206
$p = $req_post[1]; // Post to display
160
// The last param is of the form p000
161
$p = $req_post[1]; // Post to display
209
{ // Last param is a string, we'll consider this to be a post urltitle
165
// Last param is a string, we'll consider this to be a post urltitle
210
166
$title = $last_part;
214
{ // ENDING SLASH -> we are looking for a daterange OR a chapter:
215
$Debuglog->add( 'Last part: '.$last_part , 'params' );
171
// ENDING SLASH -> we are looking for a daterange OR a category
216
172
if( preg_match( '|^w?[0-9]+$|', $last_part ) )
217
{ // Last part is a number or a "week" number:
174
// Last part is a number or a "week" number
219
$Debuglog->add( 'Last part is a number or a "week" number: '.$path_elements[$i] , 'params' );
220
176
if( isset( $path_elements[$i] ) )
222
178
if( is_numeric( $path_elements[$i] ) )
223
{ // We'll consider this to be the year
180
// We'll consider this to be the year
224
181
$m = $path_elements[$i++];
225
$Debuglog->add( 'Setting year from extra path info. $m=' . $m , 'params' );
227
// Also use the prefered posts per page for archives (may be NULL, in which case the blog default will be used later on)
183
// Also use the prefered posts per page for archives (may be NULL,
184
// in which case the blog default will be used later on)
228
185
if( ! $posts = $Blog->get_setting( 'archive_posts_per_page' ) )
229
{ // use blog default
230
188
$posts = $Blog->get_setting( 'posts_per_page' );
233
191
if( isset( $path_elements[$i] ) && is_numeric( $path_elements[$i] ) )
234
{ // We'll consider this to be the month
193
// We'll consider this to be the month
235
194
$m .= $path_elements[$i++];
236
$Debuglog->add( 'Setting month from extra path info. $m=' . $m , 'params' );
238
196
if( isset( $path_elements[$i] ) && is_numeric( $path_elements[$i] ) )
239
{ // We'll consider this to be the day
198
// We'll consider this to be the day
240
199
$m .= $path_elements[$i++];
241
$Debuglog->add( 'Setting day from extra path info. $m=' . $m , 'params' );
244
202
elseif( isset( $path_elements[$i] ) && substr( $path_elements[$i], 0, 1 ) == 'w' )
245
{ // We consider this a week number
204
// We consider this a week number
246
205
$w = substr( $path_elements[$i], 1, 2 );
250
{ // We did not get a number/year...
210
// We did not get a number/year...
252
212
$disp_detail = '404-malformed_url-missing_year';
256
elseif( preg_match( '|^[A-Za-z0-9\-_]+$|', $last_part ) ) // UNDERSCORES for catching OLD URLS!!!
257
{ // We are pointing to a chapter/category:
258
$ChapterCache = & get_Cache( 'ChapterCache' );
262
$Chapter = & $ChapterCache->get_by_urlname( $last_part, false );
263
if( empty( $Chapter ) )
264
{ // We could not match a chapter...
265
// We are going to consider this to be a post title with a misplaced trailing slash.
266
// That happens when upgrading from WP for example.
216
elseif( preg_match( '|^[A-Za-z0-9\-_]+$|', $last_part ) ) // UNDERSCORES for catching OLD URLS!!!
218
// We are pointing to a category
219
$CategoryCache = & get_Cache( 'CategoryCache' );
220
$Category = & $CategoryCache->get_by_urlname( $last_part, false );
221
if( empty( $Category ) )
223
// We could not match a category; consider this to be a post title with a
224
// misplaced trailing slash. That happens when upgrading from WP for example.
267
225
$title = $last_part; // Will be sought later
268
$already_looked_into_chapters = true;
226
$already_looked_into_cats = true;
271
{ // We could match a chapter from the extra path:
230
// We could match a category from the extra path
231
$cat = $Category->ID;
273
232
// Also use the prefered posts per page for a cat
274
if( ! $posts = $Blog->get_setting( 'chapter_posts_per_page' ) )
275
{ // use blog default
233
if( ! $posts = $Blog->get_setting( 'category_posts_per_page' ) )
276
236
$posts = $Blog->get_setting( 'posts_per_page' );
281
{ // We did not get anything we can decode...
242
// We did not get anything we can decode...
283
244
$disp_detail = '404-malformed_url-bad_char';
294
* ____________________________ Query params ____________________________
296
* Note: if the params have been set by the extra-path-info above, param() will not touch them.
298
param( 'p', 'integer', '', true ); // Specific post number to display
299
param( 'title', 'string', '', true ); // urtitle of post to display
300
param( 'redir', 'string', 'yes', false ); // Do we allow redirection to canonical URL? (allows to force a 'single post' URL for commenting)
301
param( 'preview', 'integer', 0, true ); // Is this preview ?
302
param( 'stats', 'integer', 0 ); // Deprecated but might still be used by spambots
303
param( 'cat', 'integer', '', true ); // Chapter ID
305
// In case these were not set by the stub:
306
if( !isset($timestamp_min) ) $timestamp_min = '';
307
if( !isset($timestamp_max) ) $timestamp_max = '';
311
* ____________________________ Get specific Item if requested ____________________________
313
if( !empty($p) || !empty($title) )
314
{ // We are going to display a single post
315
// Make sure the single post we're requesting (still) exists:
252
// Query params ... Note: if the params have been set by the extra-path-info
253
// above, param() will not touch them.
255
// Specific post number to display
256
param( 'p', 'integer', '', true );
257
// urtitle of post to display
258
param( 'title', 'string', '', true );
259
// Do we allow redirection to canonical URL? (allows to force a 'single post' URL for commenting)
260
param( 'redir', 'string', 'yes', false );
262
param( 'preview', 'integer', 0, true );
263
// Deprecated but might still be used by spambots
264
param( 'stats', 'integer', 0 );
266
param( 'cat', 'integer', '', true );
268
// In case these were not set by the stub
269
if( ! isset( $timestamp_min ) ) $timestamp_min = '';
270
if( ! isset( $timestamp_max ) ) $timestamp_max = '';
272
// Get specific Item if requested
273
if( ! empty( $p ) || ! empty( $title ) )
275
// We are going to display a single post
276
// Make sure the single post we're requesting (still) exists
316
277
$ItemCache = & get_Cache( 'ItemCache' );
318
{ // Get from post ID:
319
281
$Item = & $ItemCache->get_by_ID( $p, false );
322
{ // Get from post title:
285
// Get from post title
323
286
$orig_title = $title;
324
287
$title = preg_replace( '/[^A-Za-z0-9_]/', '-', $title );
325
288
$Item = & $ItemCache->get_by_urltitle( $title, false );
327
290
if( empty( $Item ) )
328
{ // Post doesn't exist!
292
// Post doesn't exist!
330
293
// fp> TODO: ->viewing_allowed() for draft, private, protected and deprecated...
332
294
$title_fallback = false;
333
295
$tag_fallback = ( $tags_dash_fix && substr( $orig_title, -1 ) == '-' && strlen( $orig_title ) == 40 );
335
if( ! $tag_fallback && !empty($title) && empty($already_looked_into_chapters) )
336
{ // Let's try to fall back to a category/chapter...
337
$ChapterCache = & get_Cache( 'ChapterCache' );
341
$Chapter = & $ChapterCache->get_by_urlname( $title, false );
342
if( !empty( $Chapter ) )
343
{ // We could match a chapter from the extra path:
297
if( ! $tag_fallback && ! empty( $title ) && empty( $already_looked_into_cats ) )
299
// Let's try to fall back to a category...
300
$CategoryCache = & get_Cache( 'CategoryCache' );
301
$Category = & $CategoryCache->get_by_urlname( $title, false );
302
if( ! empty( $Category ) )
304
// We could match a category from the extra path
305
$cat = $Category->ID;
345
306
$title_fallback = true;
347
308
// Also use the prefered posts per page for a cat
348
if( ! $posts = $Blog->get_setting( 'chapter_posts_per_page' ) )
349
{ // use blog default
309
if( ! $posts = $Blog->get_setting( 'category_posts_per_page' ) )
350
312
$posts = $Blog->get_setting( 'posts_per_page' );
356
{ // Let's try to fall back to a tag...
317
if( ! empty( $title ) )
319
// Let's try to fall back to a tag...
357
320
if( $tag_fallback )
359
322
$title = substr( $orig_title, 0, -1 );
361
324
if( $Blog->get_tag_post_count( $title ) )
362
{ // We could match a tag from the extra path:
326
// We could match a tag from the extra path
364
328
$title_fallback = true;
369
333
if( ! $title_fallback )
370
{ // We were not able to fallback to anythign meaningful:
335
// We were not able to fallback to anything meaningful
372
337
$disp_detail = '404-post_not_found';
376
else if( ! empty( $cat ) )
377
{ // We are pointing to a chapter/category (by ID):
378
$ChapterCache = & get_Cache( 'ChapterCache' );
382
$Chapter = & $ChapterCache->get_by_ID( $cat, false );
341
elseif( ! empty( $cat ) )
343
// We are pointing to a category (by ID)
344
$CategoryCache = & get_Cache( 'CategoryCache' );
345
$Category = & $CategoryCache->get_by_ID( $cat, false );
385
{ // Category not found, bail out:
349
// Category not found, bail out
387
351
$disp_detail = '404-category-not-found';
393
* ____________________________ "Clean up" the request ____________________________
396
* 1) disp is set to "single" if single post requested
397
* 2) URL is canonical if:
398
* - some content was requested in a weird/deprecated way
399
* - or if content identifiers have changed
355
// "Clean up" the request
357
// 1) disp is set to "single" if single post requested
358
// 2) URL is canonical if:
359
// - some content was requested in a weird/deprecated way
360
// - or if content identifiers have changed
401
361
if( $stats || $disp == 'stats' )
402
{ // This used to be a spamfest...
403
require $templates_path.'_410_stats_gone.main.php'; // error & exit
363
// This used to be a spamfest, error & exit
364
require $templates_path.'_410_stats_gone.main.php';
406
elseif( !empty($preview) )
366
elseif( ! empty( $preview ) )
408
369
$disp = 'single';
409
370
// Consider this as an admin hit!
410
371
$Hit->referer_type = 'admin';
412
elseif( $disp == 'posts' && !empty($Item) )
413
{ // We are going to display a single post
414
// if( in_array( $Item->ptyp_ID, array( 1000, 1500, 1520, 1530, 1570 ) ) ) // pages and intros
373
elseif( $disp == 'posts' && ! empty( $Item ) )
375
// We are going to display a single post
415
376
if( $Item->ptyp_ID == 1000 )
378
// this is a page-type
381
elseif( in_array( $Item->ptyp_ID, array( 1500, 1520, 1530, 1570 ) ) )
383
// these are intro-types
388
// must be good old permalink single post
421
389
$disp = 'single';
424
// fp> note: the redirecting code that was here moved to template_init() with the other redirecting code.
425
// That feels more consistent and may also allow some templates to handle redirects differently (framing?)
426
// I hope I didn't screw that up... but it felt like the historical reasons for this to be here no longer applied.
431
* ______________________ DETERMINE WHICH TEMPLATE TO USE FOR DISPLAY _______________________
435
* Check if a temporary template has been requested (used for RSS syndication
438
* This will be handled like any other template.
439
* tempskin is also checked for b2evolution backward compatibility.
441
* @todo maybe restrict that to authorized users?
393
// DETERMINE WHICH TEMPLATE TO USE FOR DISPLAY
394
// Check if a temporary template has been requested (used for RSS syndication for example).
395
// This will be handled like any other template. tempskin is also checked for b2evolution
396
// backward compatibility.
443
398
if( param( 'viewmode', 'string', param( 'tempskin', 'string' ), true ) !== '' )
445
400
$template = $viewmode;
448
403
if( isset( $template ) )
449
{ // A template has been requested by folder_name (url or stub):
451
// Check validity of requested template name:
405
// A template has been requested by folder_name (url or stub)
406
// Check validity of requested template name
452
407
if( preg_match( '~([^-A-Za-z0-9._]|\.\.)~', $template ) )
454
409
debug_die( 'The requested template name is invalid.' );
471
429
elseif( template_exists( $template ) && ! template_installed( $template ) )
472
{ // The requested template is not a feed template and exists in the file system, but isn't installed:
431
// The requested template is not a feed and exists, but isn't installed
473
432
debug_die( sprintf( T_( 'The template [%s] is not installed on this system.' ), htmlspecialchars( $template ) ) );
475
434
else if( ! empty( $viewmode ) )
476
{ // By definition, we want to see the temporary template (if we don't use feedburner... )
436
// By definition, we want to see the temporary template (if we don't use feedburner...)
481
if( !isset( $template ) && !empty($Blog->template_ID) ) // Note: if $template is set to '', then we want to do a "no template" display
482
{ // Use default template from the database
441
// Note: if $template is set to '', then we want to do a "no template" display
442
if( ! isset( $template ) && ! empty( $Blog->template_ID ) )
444
// Use default template from the database
483
445
$TemplateCache = & get_cache( 'TemplateCache' );
484
446
$Template = & $TemplateCache->get_by_ID( $Blog->template_ID );
485
447
$template = $Template->folder;
488
// Because a lot of bloggers will delete templates, we have to make this fool proof with extra checking:
489
if( !empty( $template ) && !template_exists( $template ) )
490
{ // We want to use a template, but it doesn't exist!
450
// we have to make this fool proof with extra checking ... if someone deletes a template
451
if( ! empty( $template ) && ! template_exists( $template ) )
453
// We want to use a template, but it doesn't exist!
491
454
$err_msg = sprintf( T_('The template [%s] set for blog [%s] does not exist. It must be properly set in the <a %s>blog properties</a> or properly overriden in a stub file.'),
492
htmlspecialchars($template),
493
$Blog->dget('shortname'),
494
'href="'.$admin_url.'?ctrl=coll_settings&tab=template&blog='.$Blog->ID.'"' );
455
htmlspecialchars( $template ),
456
$Blog->dget( 'shortname' ),
457
'href="'.$admin_url.'?ctrl=blog_settings&tab=template&blog='.$Blog->ID.'"' );
495
458
debug_die( $err_msg );
499
461
$Timer->pause( '_blog_main.inc');
503
* _______________________________ READY TO DISPLAY _______________________________
505
* At this point $template holds the name of the template we want to use, or '' for no template!
509
// Trigger plugin event:
463
// READY TO DISPLAY :)
464
// At this point $template holds the name of the template we want to use, or ''
465
// for no template ... which probably doesn't work at all so test it and fix it.
467
// Trigger plugin event
510
468
// fp> TODO: please doc with example of what this can be used for
511
$Plugins->trigger_event( 'BeforeBlogDisplay', array('template'=>$template) );
514
if( !empty( $template ) )
515
{ // We want to display with a template now:
517
// Instanciate PageCache:
518
load_class( '_core/model/_pagecache.class.php' );
469
$Plugins->trigger_event( 'BeforeBlogDisplay', array(
470
'template' => $template
473
if( ! empty( $template ) )
475
// We want to display with a template now
477
// Instanciate PageCache
519
478
$PageCache = new PageCache( $Blog );
520
// Check for cached content & Start caching if needed
521
// Note: there are some redirects inside the templates themselves for canonical URLs,
522
// If we have a cache hit, the redirect won't take place until the cache expires -- probably ok.
523
// If we start collecting and a redirect happens, the collecting will just be lost and that's what we want.
479
// Check for cached content & Start caching if needed Note: there are some redirects
480
// inside the templates themselves for canonical URLs, If we have a cache hit, the
481
// redirect won't take place until the cache expires -- probably ok. If we start
482
// collecting and a redirect happens, the collecting will just be lost and that's what we want.
524
483
if( ! $PageCache->check() )
525
{ // Cache miss, we have to generate:
527
if( $template_provided_by_plugin = template_provided_by_plugin($template) )
485
// Cache miss, we have to generate
486
if( $template_provided_by_plugin = template_provided_by_plugin( $template ) )
529
$Plugins->call_method( $template_provided_by_plugin, 'DisplayTemplate', $tmp_params = array('template'=>$template) );
488
$Plugins->call_method( $template_provided_by_plugin, 'DisplayTemplate', $tmp_params = array( 'template' => $template ) );
533
// Path for the current template:
492
// Path for the current template
534
493
$ads_current_template_path = $templates_path.$template.'/';
536
495
$disp_handlers = array(
537
'404' => '404_not_found.main.php',
538
'arcdir' => 'arcdir.main.php',
539
'catdir' => 'catdir.main.php',
540
'comments' => 'comments.main.php',
541
'credits' => 'credits.main.php',
496
'404' => '404_not_found.main.php',
497
'arcdir' => 'arcdir.main.php',
498
'catdir' => 'catdir.main.php',
499
'comments' => 'comments.main.php',
500
'credits' => 'credits.main.php',
542
501
'feedback-popup' => 'feedback_popup.main.php',
543
'mediaidx' => 'mediaidx.main.php',
544
'msgform' => 'msgform.main.php',
545
'page' => 'page.main.php',
546
'posts' => 'posts.main.php',
547
'profile' => 'profile.main.php',
548
'single' => 'single.main.php',
549
'subs' => 'subs.main.php',
502
'mediaidx' => 'mediaidx.main.php',
503
'msgform' => 'msgform.main.php',
504
'page' => 'page.main.php',
505
'posts' => 'posts.main.php',
506
'profile' => 'profile.main.php',
507
'single' => 'single.main.php',
508
'subs' => 'subs.main.php',
550
509
// All others will default to index.main.php
553
if( !empty($disp_handlers[$disp]) )
512
if( ! empty( $disp_handlers[$disp] ) )
555
514
if( file_exists( $disp_handler = $ads_current_template_path.$disp_handlers[$disp] ) )
556
{ // The template has a customized page handler for this display:
557
$Debuglog->add('blog_main: include '.rel_path_to_base($disp_handler).' (custom to this template)', 'template');
517
* The template has a customized page handler for this display
558
519
require $disp_handler;
561
{ // Use the default handler from the templates dir:
562
$Debuglog->add('blog_main: include '.rel_path_to_base($ads_current_template_path.'index.main.php').' (default handler)', 'template');
524
* Use the default handler from the templates dir
563
526
require $ads_current_template_path.'index.main.php';
567
{ // Use the default handler from the templates dir:
568
$Debuglog->add('blog_main: include '.rel_path_to_base($ads_current_template_path.'index.main.php').' (default index handler)', 'template');
532
* Use the default handler from the templates dir
569
534
require $ads_current_template_path.'index.main.php';
573
// Save collected cached data if needed:
538
// Save collected cached data if needed
574
539
$PageCache->end_collect();