/** * Fetch template HTML and parse vars. * * @param array $vars Vars to pass to template. * * @return string */ private function fetchTemplate($vars = array()) { $html = rfile_get_contents(appdir('template/mail/' . $this->template . '.html')); foreach ($this->vars as $key => $var) { $html = str_replace('{{ ' . $key . ' }}', $var, $html); } $css = array(); preg_match_all('/\\{\\%css\\:\\ (.*?)\\ \\%\\}/', $html, $css); if (!empty($css[1][0])) { $style = rfile_get_contents(root('www/asset/css/' . $css[1][0])); $html = str_replace($css[0][0], '<style>' . $style . '</style>', $html); } return $html; }
/** * ### Gets the full path to a config file * * @return string */ function conf($name) { return realpath(appdir() . 'config/' . $name . '.php'); }
/** * Setup Twig template engine * * @return void */ public function setupTwig() { Twig_Autoloader::register(true); if (!is_dir($this->basedir . 'template/')) { Clockwork::throwError('Template directory (' . $this->basedir . 'template/) does not exists'); } $paths = [$this->basedir . 'template/', APP_DIR . 'template/']; $plugins = Clockwork::getInstance()->loadedPlugins; foreach ($plugins as $plugin) { if (is_dir($plugin->dir() . 'template/')) { $paths[] = $plugin->dir() . 'template/'; } } $loader = new Twig_Loader_Filesystem($paths); $this->twig = new Twig_Environment($loader, array('cache' => Config::getSetting('twig_cache') ? appdir('template/cache/') : false)); $functions = get_defined_functions(); foreach ($functions['user'] as $function) { if (strpos(strtolower($function), 'twig') === false) { $this->twig->addFunction(new Twig_SimpleFunction($function, $function)); } } $this->twig->addFunction(new Twig_SimpleFunction('PluginLoader', [Clockwork::getInstance(), 'pluginLoader'])); }