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 8if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { 9 header("location: index.php"); 10 exit; 11} 12/** 13 * \brief Smarty plugin to use wiki page as a template resource parsing as little as with tpl on disk 14 * ------------------------------------------------------------- 15 * File: resource.tplwiki.php 16 * Type: resource 17 * Name: tplPage 18 * Purpose: Fetches a template from a wiki page but parsing as little as with tpl's on disk 19 * ------------------------------------------------------------- 20 */ 21function smarty_resource_tplwiki_source($page, &$tpl_source, $smarty) 22{ 23 global $tikilib, $user; 24 25 $perms = Perms::get([ 'type' => 'wiki page', 'object' => $page ]); 26 if (! $perms->use_as_template) { 27 $tpl_source = tra('Permission denied: the specified wiki page cannot be used as Smarty template resource') . '<br />'; 28 // TODO: do not cache ! and return the message only once should be enough... 29 return true; 30 } 31 32 $info = $tikilib->get_page_info($page); 33 if (empty($info)) { 34 return false; 35 } 36 $tpl_source = $info['data']; 37 return true; 38} 39 40function smarty_resource_tplwiki_timestamp($page, &$tpl_timestamp, $smarty) 41{ 42 global $tikilib, $user; 43 $info = $tikilib->get_page_info($page); 44 if (empty($info)) { 45 return false; 46 } 47 if (preg_match('/\{([A-z-Z0-9_]+) */', $info['data']) || preg_match('/\{\{.+\}\}/', $info['data'])) { // there are some plugins - so it can be risky to cache the page 48 $tpl_timestamp = $tikilib->now; 49 } else { 50 $tpl_timestamp = $info['lastModif']; 51 } 52 return true; 53} 54 55function smarty_resource_tplwiki_secure($tpl_name, $smarty) 56{ 57 return true; 58} 59 60function smarty_resource_tplwiki_trusted($tpl_name, $smarty) 61{ 62 return true; 63} 64