diff options
author | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2013-08-30 15:20:30 +0000 |
---|---|---|
committer | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2013-08-30 15:20:30 +0000 |
commit | a1e990177b94299d00ff72125bb1d4ea6a05fd73 (patch) | |
tree | c80f394163dd5a5efb9cdf144d577938ec85c8bc /update.php | |
parent | 1c70b0447570619f537147db8ca491c054467a12 (diff) | |
download | dokuwiki-a1e990177b94299d00ff72125bb1d4ea6a05fd73.tar.gz dokuwiki-a1e990177b94299d00ff72125bb1d4ea6a05fd73.tar.bz2 dokuwiki-a1e990177b94299d00ff72125bb1d4ea6a05fd73.zip |
use smarty to render templates from wikipages
Diffstat (limited to 'update.php')
-rwxr-xr-x | update.php | 112 |
1 files changed, 34 insertions, 78 deletions
@@ -11,6 +11,7 @@ if(!defined('DOKU_INC')) define('DOKU_INC', '/usr/share/dokuwiki/'); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/cliopts.php'); require_once('SymfonyComponents/YAML/sfYaml.php'); +require_once('smarty3/Smarty.class.php'); session_write_close(); #------------------------------------------------------------------------------ @@ -70,6 +71,28 @@ class Doku_Indexer_Mass_Remover extends Doku_Indexer { } #------------------------------------------------------------------------------ +# Smarty + +class Smarty_Hostinfo extends Smarty { + + function __construct() + { + parent::__construct(); + + $this->setCompileDir(__DIR__ . '/templates_c/'); + $this->setConfigDir(__DIR__ . '/configs/'); + + $this->default_resource_type = 'dokuwiki'; + + $this->addPluginsDir(__DIR__ . '/plugins/'); + $this->loadFilter("pre", 'whitespace_control'); + + $this->caching = Smarty::CACHING_OFF; + } +} +$smarty = new Smarty_Hostinfo(); + +#------------------------------------------------------------------------------ # main() $path_to_hostinfo = $OPTS->arg(0); @@ -91,7 +114,13 @@ function _find_current_pages() { global $conf, $PAGES; $data = array(); - search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true), 'hostinfo'); + $opts = array( + 'skipacl' => true, + + // ignore pages in subnamespaces (templates) + 'depth' => 2, + ); + search($data, $conf['datadir'], 'search_allpages', $opts, 'hostinfo'); foreach ($data as $page) { $PAGES[$page['id']] = 'delete'; @@ -162,29 +191,6 @@ function _render($target, $file, $vars=null) { } #------------------------------------------------------------------------------ -# default - -function echo_with_default($value, $default) { - if (!isset($value) || empty($value)) { - echo $default; - } - else { - echo $value; - } -} - -#------------------------------------------------------------------------------ -# get_contact_info - -function get_contact_info($maintainer) { - if (preg_match('/^([^:]*): (.*@.*)$/', $maintainer, $match)) { - return array($match[1], $match[2]); - } - - return array($maintainer, $maintainer . '@spline.inf.fu-berlin.de'); -} - -#------------------------------------------------------------------------------ # get_bcfg2_groups function get_bcfg2_groups($hostinfo) { @@ -218,63 +224,13 @@ function get_bcfg2_groups($hostinfo) { } #------------------------------------------------------------------------------ -# group_by - -function group_by($data, $key) { - $result = array(); - - foreach ($data as $value) { - if (array_key_exists($key, $value)) { - $result[$value[$key]][] = $value; - } - } - - return $result; -} - -#------------------------------------------------------------------------------ -# select_by - -function select_by($data, $key, $exists = true) { - $result = array(); - - if (is_array($data)) { - foreach ($data as $value) { - if (array_key_exists($key, $value) === $exists) { - $result[] = $value; - } - } - } - - return $result; -} - -#------------------------------------------------------------------------------ # _render_template -function _render_template($file, $vars=null) { - // validate $file - $file = preg_replace('/^(?:.+\/)?([a-zA-Z_-]*)(?:\.[a-zA-Z])?$/', '$1', $file); - $file = 'templates/' . $file . '.tpl.php'; - - if (!file_exists($file)) { - // template does not exists - return false; - } - - if (is_array($vars) && !empty($vars)) { - if (array_key_exists('file', $vars)) { - // if $vars would contain a 'file' key, this would overwrite the - // first parameter of the template file - unset($vars['file']); - } - - extract($vars); - } +function _render_template($template, $vars=null) { + global $smarty; - ob_start(); - include $file; - return ob_get_clean(); + $smarty->assign($vars); + return $smarty->fetch($template . '.tpl'); } #------------------------------------------------------------------------------ |