1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14// To disable for certain templates where this would break, temporarily set a log_tpl template variable to false.
15function smarty_prefilter_log_tpl($source, $smarty)
16{
17	global $prefs;
18	if ($prefs['log_tpl'] != 'y' || $smarty->getTemplateVars('log_tpl') === false) {
19		return $source;
20	}
21
22	$resource = $smarty->template_resource;
23
24	// Refrain from logging for some templates
25	if (strpos($resource, 'eval:') === 0 || // Evaluated templates
26			strpos($resource, 'mail/') !== false // email tpls
27			) {
28		return $source;
29	}
30
31	// The opening comment cannot be inserted before the DOCTYPE in HTML documents; put it right after.
32	$commentedSource = preg_replace('/^<!DOCTYPE .*>/i', '$0' . '<!-- TPL: ' . $resource . ' -->', $source, 1, $replacements);
33	if ($replacements) {
34		return $commentedSource . '<!-- /TPL: ' . $resource . ' -->';
35	}
36
37	return '<!-- TPL: ' . $resource . ' -->' . $source . '<!-- /TPL: ' . $resource . ' -->';
38}
39