public function generate() { // getting view file contents, and stripping from <?php die?\> $viewContent = file_get_contents($this->_viewPath); $viewContent = str_replace('<?php die?>', '', $viewContent); $viewContent = '<tal:block>' . $viewContent . '</tal:block>'; // PHPTAL configuration $view = new PHPTAL(); $view->setSource($viewContent, $this->_viewPath); foreach ($this->_params as $key => $value) { $view->set($key, $value); } $view->setOutputMode(PHPTAL::HTML5); // PHPTAL filters $view->addPreFilter(new ViewPreFilter()); // <? --> <?php, <?= --> <?php echo $view->addPreFilter(new PHPTAL_PreFilter_StripComments()); if (!defined('WM_Debug')) { $view->addPreFilter(new PHPTAL_PreFilter_Normalize()); // strips whitespaces etc. } // predefined parameters // (NOTE: when changed, change also array in ->__set()) if (class_exists('Users')) { $view->set('isAdmin', Users::isLogged()); } // executing return $view->execute(); }
/** * Executes PHPTAL template and wraps its result in layout.xhtml */ private static function outputTAL(array $result, $path) { $phptal = new PHPTAL(); foreach ($result as $k => $v) { $phptal->set($k, $v); } $layout = clone $phptal; // lazy hack $layout->setTemplate('templates/layout.xhtml'); $phptal->setTemplate($path); $layout->content_phptal = $phptal; $layout->echoExecute(); }
function vanilla_shortcode($shortcode) { global $tpl_set, $tpl; $active_template = vanilla_get_template('shortcodes/' . $shortcode . ".html"); if (!$active_template) { return ""; } // No need to include the PHP tpl file here. Already loaded at init. $tpl_source = '<metal:block define-macro="' . $shortcode . '_shortcode">' . "\n" . "<!-- shortcode: " . $shortcode . " -->\n" . '<span tal:condition="php:VANILLA_DEBUG" class="widget-debug">SHORTCODE: ' . $shortcode . '</span>' . "\n" . '<span metal:use-macro="' . $active_template . '/loader" />' . "\n" . '<span metal:define-slot="' . $shortcode . '" />' . "\n" . '</metal:block><metal:block use-macro="' . $shortcode . '_shortcode" />' . "\n"; //return "<textarea style='width:500px; height:300px;'> $tpl_source </textarea>"; // Load and fire the PHPTAL template! $template = new PHPTAL(); $template->setSource($tpl_source, $tpl_set . $shortcode); $template->set('vanilla', $tpl); try { return $template->execute(); } catch (Exception $e) { return $e; } }
function apply(&$regionContent) { $this->checkRequiredValues($regionContent); $templateSource = @implode('', file($this->fileName)); $templateSource = $this->fixUrl($templateSource); $compiler = org_glizy_ObjectFactory::createObject('org.glizy.compilers.Skin'); $compiledFileName = $compiler->verify($this->fileName, array('defaultHtml' => $templateSource)); $pathInfo = pathinfo($compiledFileName); $templClass = new PHPTAL($pathInfo['basename'], $pathInfo['dirname'], org_glizy_Paths::getRealPath('CACHE_CODE')); foreach ($regionContent as $region => $content) { $templClass->set($region, $content); } $res = $templClass->execute(); if (PEAR::isError($res)) { $templateSource = $res->toString() . "\n"; } else { $templateSource = $res; } if (isset($regionContent['__body__'])) { $templateSource = $this->modifyBodyTag($regionContent['__body__'], $templateSource); } $templateSource = $this->fixLanguages($templateSource); return $templateSource; }
* * You should have received a copy of the GNU Affero General Public License * along with eCamp. If not, see <http://www.gnu.org/licenses/>. */ include "./config.php"; include $lib_dir . "/mysql.php"; include $lib_dir . "/functions/error.php"; require_once "./lib/PHPTAL.php"; db_connect(); $user_id = mysql_escape_string($_REQUEST['user_id']); $login = mysql_escape_string($_REQUEST['login']); $acode = mysql_escape_string($_REQUEST['acode']); $query = "\tSELECT user.id FROM user WHERE id = {$user_id} AND mail = '{$login}' AND acode = '{$acode}'"; $result = mysql_query($query); if (mysql_error() || !mysql_num_rows($result)) { die("FEHLER; Support anfragen"); } if ($_SESSION[skin] == "") { $_SESSION[skin] = $GLOBALS[skin]; } $html = new PHPTAL("public/skin/" . $_SESSION[skin] . "/pwreset.tpl"); $html->setEncoding('UTF-8'); $html->set('SHOW_MSG', false); if (isset($_REQUEST['msg'])) { $html->set('SHOW_MSG', true); $html->set('MSG', mysql_escape_string($_REQUEST['msg'])); } $html->set('user_id', $user_id); $html->set('login', $login); $html->set('acode', $acode); echo $html->execute();
# Beschreibung: Übernimmt den Login-Vorgang # # ToDo: - Herausfinden der Berechtigungen nach dem Login --> user[auth_level] # => NICHT BEI ANMELDUNG, SONDERN BEI LAGERWAHL!!! # - Überprüfen, wie oft ein Login versucht wurde --> Kennwortrücksetzung anbieten # - Validieren der User-Eingaben include "./config.php"; include $lib_dir . "/session.php"; include $lib_dir . "/functions/error.php"; require_once "./lib/PHPTAL.php"; if ($_SESSION[skin] == "") { $_SESSION[skin] = $GLOBALS[skin]; } $html = new PHPTAL("public/skin/" . $_SESSION[skin] . "/login.tpl"); $html->setEncoding('UTF-8'); $html->set('SHOW_MSG', false); session_start(); if (isset($_REQUEST[msg])) { $html->set('SHOW_MSG', true); $html->set('MSG', $_REQUEST[msg]); } if ($_POST['Form'] == "Login") { include $lib_dir . "/mysql.php"; db_connect(); // Verhindern von injection!!! $_POST['Login'] = mysql_real_escape_string($_POST['Login']); $query = "SELECT pw, id, scoutname, firstname, active, last_camp FROM user WHERE mail = '" . $_POST['Login'] . "' LIMIT 1"; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); if ($row['active'] == 1) {
private static function display(array $res, array $pageinf) { if (isset($res['redirect'])) { if ($_SERVER['REQUEST_METHOD'] != 'GET') { header('HTTP/1.1 303 see'); } if (preg_match('!^https?://!', $res['redirect'])) { $url = $res['redirect']; } else { $url = 'http://' . $_SERVER['HTTP_HOST'] . self::$baseuri . $res['redirect']; } header("Location: {$url}"); die($url); } $phptal = new PHPTAL(); $phptal->set('POST', $_POST); foreach ($res as $k => $v) { $phptal->set($k, $v); } if (!isset($res['page_template'])) { $res['page_template'] = $pageinf['pagename']; } if (!isset($res['page_content']) && $res['page_template']) { $phptal->setTemplate('admin/tpl/' . $res['page_template'] . '.inc'); $res['page_content'] = $phptal->execute(); $phptal->set('page_content', $res['page_content']); } if (!isset($res['content_type'])) { $res['content_type'] = 'text/html;charset=UTF-8'; } header("Content-Type: " . $res['content_type']); if (!isset($res['layout_template'])) { $res['layout_template'] = 'layout'; } if ($res['layout_template']) { $phptal->setTemplate('admin/tpl/' . $res['layout_template'] . '.inc'); echo $phptal->execute(); } else { echo $res['page_content']; } }
* This file is part of eCamp. * * eCamp is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * eCamp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with eCamp. If not, see <http://www.gnu.org/licenses/>. */ include "./config.php"; include $lib_dir . "/functions/error.php"; require_once "./lib/PHPTAL.php"; require_once "./lib/recaptchalib.php"; if ($_SESSION[skin] == "") { $_SESSION[skin] = $GLOBALS[skin]; } $html = new PHPTAL("public/skin/" . $_SESSION[skin] . "/reminder.tpl"); $html->setEncoding('UTF-8'); $html->set('SHOW_MSG', false); if (isset($_REQUEST['msg'])) { $html->set('SHOW_MSG', true); $html->set('MSG', mysql_escape_string($_REQUEST['msg'])); } $html->set('captcha', recaptcha_get_html($GLOBALS[captcha_pub])); echo $html->execute();
/** * Initialize default data and execute the template. * * This automatically sets object variables not beginning with an * underscore as part of the TAL. This step is necessary or else * PHPTAL will not recognize the class variables during its execution * If the inner template is set, it is executed as well and its returned HTML * composes the body of this template. Otherwise, the HTML provided by * $this->html() does the job. * * @throws CannotCreateTemplateException if no HTML or inner template is set * @return html all template HTML */ public function execute() { $this->init(); if (isset($this->_sub_template)) { $this->body = $this->_sub_template->execute(); } else { if (empty($this->body)) { throw new CannotCreateTemplateException('Error in ' . __METHOD__ . 'No inner template found. ' . 'Please set an inner template file with the constructor or setTemplate() method'); } } foreach (get_object_vars($this) as $key => $val) { if (strpos($key, '_') !== 0) { parent::set($key, $val); } } return parent::execute(); }
/** * Returns PHPTAL output - either from a render or from the cache. * * @param string|array $template The name of the template to render or * an array with the ('src') src for a template * and a ('name') name to help identify the * template in error messages. * * @return string */ public function render($template) { $this->_checkLoaded(); if ($this->_zendPageCacheContent != false) { return $this->_zendPageCacheContent; } if (!is_array($template)) { //conversion of template names from '-' split to camel-case $templateParts = explode('-', $template); $firstPart = array_shift($templateParts); foreach ($templateParts as &$currentPart) { $currentPart = ucfirst($currentPart); } $template = $firstPart . implode('', $templateParts); $this->_engine->setTemplate($template); } else { $this->_engine->setSource($template['src'], $template['name']); } $this->productionMode = 'production' == APPLICATION_ENV; $this->_engine->set('doctype', $this->doctype()); $this->_engine->set('headTitle', $this->headTitle()); $this->_engine->set('headScript', $this->headScript()); $this->_engine->set('headLink', $this->headLink()); $this->_engine->set('headMeta', $this->headMeta()); $this->_engine->set('headStyle', $this->headStyle()); if ($this->_purgeCacheBeforeRender) { $cacheFolder = $this->_engine->getPhpCodeDestination(); if (is_dir($cacheFolder)) { foreach (new DirectoryIterator($cacheFolder) as $cacheItem) { if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) { continue; } @unlink($cacheItem->getPathname()); } } } // if a layout is being used and nothing has already overloaded the viewContent, // register the content as viewContent, otherwise set it to empty if (!isset($this->viewContent)) { if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) { $this->_engine->set('viewContent', $this->layout()->content); } else { $this->viewContent = ''; } } // Strip html comments and compress un-needed whitespace $this->_engine->addPreFilter(new PHPTAL_PreFilter_StripComments()); if ($this->_compressWhitespace == true) { $this->_engine->addPreFilter(new PHPTAL_PreFilter_Compress()); } try { $result = $this->_engine->execute(); } catch (PHPTAL_TemplateException $e) { // If the exception is a root PHPTAL_TemplateException // rather than a subclass of this exception and xdebug is enabled, // it will have already been picked up by xdebug, if enabled, and // should be shown like any other php error. // Any subclass of PHPTAL_TemplateException can be handled by // the phptal internal exception handler as it gives a useful // error output if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) { exit; } throw $e; } if ($this->_zendPageCache instanceof Zend_Cache_Core) { $this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration); } return $result; }
/** * Returns PHPTAL output - either from a render or from the cache. * * @param string|array $template The name of the template to render or * an array with the ('src') src for a template * and a ('name') name to help identify the * template in error messages. * * @return string */ public function render($template) { // Check we are fully configured and initialised. if ($this->_engine == null) { throw new \Zend_View_Exception('PHPTAL is not defined', $this); } // If a cache has been setup and content is available, return it if ($this->_zendPageCacheContent != false) { return $this->_zendPageCacheContent; } // Setup the script locations based on the view's script paths $this->_engine->setTemplateRepository($this->getScriptPaths()); // Do this at this point rather than in the constructor because we don't // know what the template repositories are going to be at that point. $this->_engine->addSourceResolver(new PharResolver($this->getScriptPaths())); // Assign all the variables set here through to the PHPTAL engine. foreach ($this->getVars() as $key => $value) { $this->_engine->set($key, $value); } if (!is_array($template)) { $this->_engine->setTemplate($this->_convertTemplateName($template)); } else { $this->_engine->setSource($template['src'], $template['name']); } // Setup a collection of standard variable available in the view $this->_engine->set('doctype', $this->doctype()); $this->_engine->set('headTitle', $this->headTitle()); $this->_engine->set('headScript', $this->headScript()); $this->_engine->set('headLink', $this->headLink()); $this->_engine->set('headMeta', $this->headMeta()); $this->_engine->set('headStyle', $this->headStyle()); $this->productionMode = 'production' == APPLICATION_ENV; // If perging of the tal template cache is enabled // find all template cache files and delete them if ($this->_purgeCacheBeforeRender) { $cacheFolder = $this->_engine->getPhpCodeDestination(); if (is_dir($cacheFolder)) { foreach (new \DirectoryIterator($cacheFolder) as $cacheItem) { if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) { continue; } @unlink($cacheItem->getPathname()); } } } // if a layout is being used and nothing has already overloaded the viewContent, // register the content as viewContent, otherwise set it to empty if (!isset($this->viewContent)) { if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) { $this->_engine->set('viewContent', $this->layout()->content); } else { $this->viewContent = ''; } } if (!$this->_preFiltersRegistered) { // Strip html comments and compress un-needed whitespace $this->_engine->addPreFilter(new \PHPTAL_PreFilter_StripComments()); if ($this->_compressWhitespace == true) { $this->_engine->addPreFilter(new \PHPTAL_PreFilter_Compress()); } $this->_preFiltersRegistered = true; } try { $result = $this->_engine->execute(); } catch (\PHPTAL_TemplateException $e) { // If the exception is a root PHPTAL_TemplateException // rather than a subclass of this exception and xdebug is enabled, // it will have already been picked up by xdebug, if enabled, and // should be shown like any other php error. // Any subclass of PHPTAL_TemplateException can be handled by // the phptal internal exception handler as it gives a useful // error output if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) { exit; } throw $e; } // If the page needed to be rendered but was configured to // cache then cache the result of the render. if ($this->_zendPageCache instanceof \Zend_Cache_Core) { $this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration); } return $result; }
<?php /* * Copyright (C) 2010 Urban Suppiger, Pirmin Mattmann * * This file is part of eCamp. * * eCamp is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * eCamp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with eCamp. If not, see <http://www.gnu.org/licenses/>. */ require_once "./config.php"; require_once "./lib/PHPTAL.php"; if ($_SESSION[skin] == "") { $_SESSION[skin] = $GLOBALS[skin]; } $html = new PHPTAL("public/skin/" . $_SESSION[skin] . "/resendacode.tpl"); $html->setEncoding('UTF-8'); $html->set('SHOW_MSG', false); echo $html->execute();
/** * Inject helpers into the PHPTAL instance. * * @param PHPTAL $template * @param ContainerInterface $container * @throws Exception\MissingHelperException */ private function injectHelpers(PhptalEngine $template, ContainerInterface $container) { if (!$container->has(HelperManager::class)) { throw new Exception\MissingHelperException(sprintf('An instance of %s is required in order to register new helper', HelperManager::class)); } $helperManager = $container->get(HelperManager::class); $template->set('helper', $helperManager); if ($container->has(Helper\UrlHelper::class)) { $helperManager->registerHelper($container->get(Helper\UrlHelper::class)); } if ($container->has(Helper\ServerUrlHelper::class)) { $helperManager->registerHelper($container->get(Helper\ServerUrlHelper::class)); } $talesRegistry = PHPTAL_TalesRegistry::getInstance(); if (!$talesRegistry->isRegistered('helper')) { $talesRegistry->registerPrefix('helper', [TalesHelper::class, 'helper']); } }