示例#1
0
 public static function getForm($errors = array())
 {
     global $cfg;
     if (LOGGED) {
         redirect(REFERER);
     }
     $note = new Notifier();
     $err = new Error();
     if ($errors) {
         $note->error($errors);
     }
     if ($_POST['login'] && $_POST['module']) {
         $form = array('logname' => $_POST['logname-session'] ? filter($_POST['logname-session'], 100) : '', 'password' => $_POST['password-session'] ? filter($_POST['password-session'], 100) : '');
         $err->setError('empty_logname', t('Logname field is required.'))->condition(!$form['logname']);
         $err->setError('logname_not_exists', t('The logname you used isn't registered.'))->condition($form['logname'] && !User::loginNameRegistered($form['logname']));
         $err->setError('password_empty', t('Password field is required.'))->condition(!$form['password']);
         $err->setError('password_invalid', t('Password is invalid.'))->condition($form['password'] && !User::loginPasswordCorrect($form['password']));
         $err->noErrors() ? redirect(REFERER) : $note->restore()->error($err->toArray());
     }
     $tpl = new PHPTAL('modules/login/form.html');
     $tpl->form = $form;
     $tpl->err = $err->toArray();
     $tpl->note = $note;
     echo $tpl->execute();
 }
示例#2
0
 /**
  * This method is used to process the data into the view and than return it to the main method that will handle what to do.
  * It also uses buffer to handle that content.
  *
  * @author Klederson Bueno <*****@*****.**>
  * @version 0.1a
  *
  * @param String $___phpBurnFilePath
  * @param Array $__phpBurnData
  * @return String
  */
 public function processViewData($___phpBurnFilePath, $__phpBurnData)
 {
     $tpl = new PHPTAL($___phpBurnFilePath);
     $tpl->setOutputMode(PHPTAL::HTML5);
     $tr = new PHPTAL_GetTextTranslator();
     // set language to use for this session (first valid language will
     // be used)
     $tr->setLanguage('pt_BR.utf8', 'pt_BR');
     // register gettext domain to use
     $tr->addDomain('system', SYS_BASE_PATH . 'locale');
     // specify current domain
     $tr->useDomain('system');
     // tell PHPTAL to use our translator
     $tpl->setTranslator($tr);
     foreach ($__phpBurnData as $index => $value) {
         if (is_string($value)) {
             $value = PhpBURN_Views::lazyTranslate($value, $_SESSION['lang']);
         }
         $tpl->{$index} = $value;
     }
     ob_start();
     try {
         echo $tpl->execute();
     } catch (Exception $e) {
         echo $e;
     }
     $___phpBurnBufferStored = ob_get_contents();
     //
     //        //Cleaning the buffer for new sessions
     ob_clean();
     return $___phpBurnBufferStored;
 }
示例#3
0
    public function getContent()
    {
        global $sql;
        //Lang::load('blocks/shoutbox/lang.*.php');
        $err = new Error();
        $note = new Notifier('note-shoutbox');
        $form['author'] = LOGGED ? User::$nickname : '';
        $form['message'] = '';
        if (isset($_POST['reply-shoutbox'])) {
            $form['author'] = LOGGED ? User::$nickname : filter($_POST['author-shoutbox'], 100);
            $form['message'] = filter($_POST['message-shoutbox'], Kio::getConfig('message_max', 'shoutbox'));
            $err->setError('author_empty', t('Author field is required.'))->condition(!$form['author']);
            $err->setError('author_exists', t('Entered nickname is registered.'))->condition(!LOGGED && is_registered($form['author']));
            $err->setError('message_empty', t('Message field is required.'))->condition(!$form['message']);
            // No errors
            if ($err->noErrors()) {
                $sql->exec('
					INSERT INTO ' . DB_PREFIX . 'shoutbox (added, author, message, author_id, author_ip)
					VALUES (
						' . TIMESTAMP . ',
						"' . $form['author'] . '",
						"' . cut($form['message'], Kio::getConfig('message_max', 'shoutbox')) . '",
						' . UID . ',
						"' . IP . '")');
                $sql->clearCache('shoutbox');
                $note->success(t('Entry was added successfully.'));
                redirect(HREF . PATH . '#shoutbox');
            } else {
                $note->error($err->toArray());
            }
        }
        // If cache for shoutbox doesn't exists
        if (!($entries = $sql->getCache('shoutbox'))) {
            $query = $sql->query('
				SELECT u.nickname, u.group_id, s.added, s.author, s.author_id, s.message
				FROM ' . DB_PREFIX . 'shoutbox s
				LEFT JOIN ' . DB_PREFIX . 'users u ON u.id = s.author_id
				ORDER BY s.id DESC
				LIMIT ' . Kio::getConfig('limit', 'shoutbox'));
            while ($row = $query->fetch()) {
                if ($row['author_id']) {
                    $row['author'] = User::format($row['author_id'], $row['nickname'], $row['group_id']);
                    $row['message'] = parse($row['message'], Kio::getConfig('parser', 'shoutbox'));
                }
                $entries[] = $row;
            }
            $sql->putCacheContent('shoutbox', $entries);
        }
        try {
            $tpl = new PHPTAL('blocks/shoutbox/shoutbox.tpl.html');
            $tpl->entries = $entries;
            $tpl->err = $err->toArray();
            $tpl->form = $form;
            $tpl->note = $note;
            return $tpl->execute();
        } catch (Exception $e) {
            return template_error($e->getMessage());
            //echo Note::error($e->getMessage());
        }
    }
示例#4
0
 public function getContent()
 {
     // User is logged in
     if (LOGGED) {
         $this->subcodename = 'logged';
         $tpl = new PHPTAL('blocks/user_panel/logged.html');
         $tpl->user = User::format(User::$id, User::$nickname, User::$groupId);
         $pm_item = User::$pmNew ? array(t('Messages <strong>(New: %new)</strong>', array('%new' => $user->pm_new)), 'pm/inbox') : array(t('Messages'), 'pm');
         $tpl->items = items(array($pm_item[0] => HREF . $pm_item[1], t('Administration') => HREF . 'admin', t('Edit profile') => HREF . 'edit_profile', t('Log out') => HREF . 'logout'));
         return $tpl->execute();
     } else {
         $err = new Error();
         $note = new Notifier('note-user_panel');
         $this->subcodename = 'not_logged';
         $form = array('logname' => null, 'password' => null);
         if ($_POST['login'] && $_POST['user_panel']) {
             $form['logname'] = $_POST['logname-session'] ? filter($_POST['logname-session'], 100) : '';
             $form['password'] = $_POST['password-session'] ? $_POST['password-session'] : '';
             $err->setError('logname_empty', t('Logname field is required.'))->condition(!$form['logname']);
             $err->setError('logname_not_exists', t('Entered logname is not registered.'))->condition(!User::loginNameRegistered($form['logname']));
             $err->setError('password_empty', t('Password field is required.'))->condition(!$form['password']);
             $err->setError('password_incorrect', t('ERROR_PASS_INCORRECT'))->condition($form['password'] && !User::loginPasswordCorrect($form['password']));
             if ($err->noErrors()) {
                 redirect('./');
             } else {
                 $note->error($err->toArray());
             }
         }
         $tpl = new PHPTAL('blocks/user_panel/not_logged.html');
         $tpl->note = $note;
         $tpl->form = $form;
         $tpl->err = $err->toArray();
         return $tpl->execute();
     }
 }
示例#5
0
 private function PHPTALWithSource($source)
 {
     global $PhptalCacheTest_random;
     $tpl = new PHPTAL();
     $tpl->setForceReparse(false);
     $tpl->setSource($source . "<!-- {$this->PhptalCacheTest_random} -->");
     // avoid cached templates from previous test runs
     return $tpl;
 }
示例#6
0
文件: tal.php 项目: abbra/midcom
 public function render(&$toolbar)
 {
     if (!class_exists('PHPTAL')) {
         require 'PHPTAL.php';
     }
     $tal = new PHPTAL();
     $tal->toolbar = $toolbar;
     $tal->setSource($this->template);
     $html = $tal->execute();
     return $html;
 }
示例#7
0
 /**
  * Use PHPTAL to generate some XHTML
  * @return string
  */
 public function execute()
 {
     try {
         $this->phptal->setTemplate($this->template);
         return $this->phptal->execute();
     } catch (Exception $e) {
         $ex = new FrameEx($e->getMessage());
         $ex->backtrace = $e->getTrace();
         throw $ex;
     }
 }
示例#8
0
 public function parse($tplDir, $tplFile, $args)
 {
     if (!$this->is_included) {
         $this->include_php_tal_file();
     }
     /**
      * @var PHPTAL
      */
     $tpl = new PHPTAL($tplDir . "/" . $tplFile);
     $tpl->doc = $args;
     return $tpl->execute();
 }
示例#9
0
    public function getContent()
    {
        global $sql;
        $note = new Notifier('note-poll');
        $stmt = $sql->setCache('poll_topic')->query('
			SELECT id, title, votes
			FROM ' . DB_PREFIX . 'poll_topics
			WHERE active = 1');
        $topic = $stmt->fetch(PDO::FETCH_ASSOC);
        if ($topic) {
            $vote_id = $sql->query('
				SELECT option_id
				FROM ' . DB_PREFIX . 'poll_votes
				WHERE topic_id = ' . $topic['id'] . ' AND voter_ip = "' . IP . '"')->fetchColumn();
            $stmt = $sql->setCache('poll_options')->query('
				SELECT id, title, votes
				FROM ' . DB_PREFIX . 'poll_options
				WHERE topic_id = ' . $topic['id'] . ' ORDER BY votes DESC');
            // User already voted
            if ($vote_id) {
                $options = array();
                $block->subcodename = 'results';
                foreach ($stmt as $row) {
                    $row['percent'] = @round(100 * ($row['votes'] / $topic['votes']), 1);
                    $options[] = $row;
                }
                $tpl = new PHPTAL('blocks/poll/results.html');
                $tpl->vote_id = $vote_id;
            } else {
                if ($_POST['vote-poll'] && $_POST['option-poll']) {
                    $option_id = (int) $_POST['option-poll'];
                    $sql->clearCacheGroup('poll_*')->exec('
					UPDATE ' . DB_PREFIX . 'poll_options o, ' . DB_PREFIX . 'poll_topics t
					SET o.votes = o.votes + 1, t.votes = t.votes + 1
					WHERE o.topic_id = ' . $topic['id'] . ' AND o.id = ' . $option_id . ' AND t.id = ' . $topic['id'] . ';
					INSERT INTO ' . DB_PREFIX . 'poll_votes (topic_id, option_id, voter_id, voter_ip, voted)
					VALUES (' . $topic['id'] . ', ' . $option_id . ', ' . $user->id . ', "' . IP . '", ' . TIMESTAMP . ')');
                    redirect(PATH . '#poll');
                } else {
                    $block->subcodename = 'voting';
                    $options = $stmt->fetchAll(PDO::FETCH_ASSOC);
                    $tpl = new PHPTAL('blocks/poll/voting.html');
                }
            }
            $stmt->closeCursor();
            $tpl->topic = $topic;
            $tpl->options = $options;
            $tpl->note = $note;
            return $tpl->execute();
        } else {
            return t('There is no content to display.');
        }
    }
示例#10
0
 /**
  * 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();
 }
 /**
  * Build the PHPTAL engine.
  *
  * @param array $options An array of parameters used to set up the PHPTAL configuration.
  *                       Available configuration values include:
  *                       - phptal
  *                       - cache-dir
  *                       - template-dir
  */
 public function __construct(array $options = array())
 {
     if (array_key_exists('phptal', $options)) {
         $this->phptal = $options['phptal'];
         return;
     }
     $this->phptal = new \PHPTAL();
     if (array_key_exists('cache-dir', $options)) {
         $this->phptal->setPhpCodeDestination($options['cache-dir']);
     }
     if (array_key_exists('template-dir', $options)) {
         $this->phptal->setTemplateRepository($options['template-dir']);
     }
 }
示例#12
0
    public function getContent()
    {
        global $sql;
        // $kio->disableRegion('left');
        if (u1 || LOGGED) {
            // TODO: Zamiast zapytania dla własnego konta dać User::toArray()
            $profile = $sql->query('
				SELECT u.*
				FROM ' . DB_PREFIX . 'users u
				WHERE u.id = ' . (ctype_digit(u1) ? u1 : UID))->fetch();
        }
        if ($profile) {
            Kio::addTitle(t('Users'));
            Kio::addBreadcrumb(t('Users'), 'users');
            Kio::addTitle($profile['nickname']);
            Kio::addBreadcrumb($profile['nickname'], 'profile/' . u1 . '/' . clean_url($profile['nickname']));
            Kio::setDescription(t('%nickname&apos;s profile', array('%nickname' => $profile['nickname'])) . ($profile['title'] ? ' - ' . $profile['title'] : ''));
            Kio::addTabs(array(t('Edit profile') => 'edit_profile/' . u1));
            if ($profile['birthdate']) {
                $profile['bd'] = $profile['birthdate'] ? explode('-', $profile['birthdate']) : '';
                // DD Month YYYY (Remaining days to next birthday)
                $profile['birthdate'] = $profile['bd'][2] . ' ' . Kio::$months[$profile['bd'][1]] . ' ' . $profile['bd'][0] . ' (' . day_diff(mktime(0, 0, 0, $profile['bd'][1], $profile['bd'][2] + 1, date('y')), t('%d days remaining')) . ')';
                $profile['age'] = get_age($profile['bd'][2], $profile['bd'][1], $profile['bd'][0]);
                if (Plugin::exists('zodiac')) {
                    require_once ROOT . 'plugins/zodiac/zodiac.plugin.php';
                    $profile['zodiac'] = Zodiac::get($profile['bd'][2], $profile['bd'][1]);
                }
            }
            if ($profile['http_agent'] && Plugin::exists('user_agent')) {
                require_once ROOT . 'plugins/user_agent/user_agent.plugin.php';
                $profile['os'] = User_Agent::getOS($profile['http_agent']);
                $profile['browser'] = User_Agent::getBrowser($profile['http_agent']);
            }
            $group = Kio::getGroup($profile['group_id']);
            $profile['group'] = $group['name'] ? $group['inline'] ? sprintf($group['inline'], $group['name']) : $group['name'] : '';
            if ($profile['gender']) {
                $profile['gender'] = $profile['gender'] == 1 ? t('Male') : t('Female');
            }
            try {
                // TODO: Zrobić modyfikator dla funkcji o wielu parametrach (teraz jest tylko jeden możliwy)
                $tpl = new PHPTAL('modules/profile/profile.tpl.html');
                $tpl->profile = $profile;
                return $tpl->execute();
            } catch (Exception $e) {
                return template_error($e);
            }
        } else {
            return not_found(t('Selected user doesn&apos;t exists.'), array(t('This person was deleted from database.'), t('Entered URL is invalid.')));
        }
    }
示例#13
0
 public function getContent()
 {
     //Lang::load('blocks/calendar/lang.*.php');
     $today = date('j');
     $month = date('n');
     $year = date('Y');
     if ($month < 8 && $month % 2 == 1 || $month > 7 && $month % 2 == 0) {
         $total_days = 31;
     } else {
         $total_days = $month == 2 ? date('L') ? 29 : 28 : 30;
     }
     $first_day = date('w', mktime(1, 1, 1, $month, 0, $year));
     $last_day = date('w', mktime(1, 1, 1, $month, $total_days - 1, $year));
     if ($first_day != 0) {
         $colspan = $first_day;
     }
     if (6 - $last_day != 0) {
         $colspan2 = 6 - $last_day;
     }
     $days = null;
     for ($day = 1; $day <= $total_days; ++$day) {
         $day_of_week = date('w', mktime(1, 1, 1, $month, $day - 1, $year));
         if ($day == 1 || $day_of_week == 0) {
             $days .= '<tr class="border-1-parent" title="' . t('Week: %week', array('%week' => date('W', mktime(1, 1, 1, $month, $day, $year)))) . '">';
             if ($colspan > 0 && $day == 1) {
                 $days .= '<td colspan="' . $colspan . '" class="empty">&nbsp;</td>';
             }
         }
         $days .= '<td><a';
         if ($day == $today) {
             $days .= ' class="today border-2"';
         }
         $days .= ' href="#' . $day . '.' . $month . '.' . $year . '">' . $day . '</a></td>';
         if ($day == $total_days && $colspan2 > 0) {
             $days .= '<td colspan="' . $colspan2 . '" class="empty">&nbsp;</td>';
         }
         if ($day_of_week == 6 || $day == $total_days) {
             $days .= '</tr>';
         }
     }
     try {
         $tpl = new PHPTAL('blocks/calendar/month_view.html');
         $tpl->days = $days;
         $tpl->month_year = date('m') . '/' . $year;
         return $tpl->execute();
     } catch (Exception $e) {
         return template_error($e->getMessage());
     }
 }
示例#14
0
 private function echoExecute(PHPTAL $tpl)
 {
     try {
         ob_start();
         $this->assertEquals(0, strlen($tpl->echoExecute()));
         $res = ob_get_clean();
     } catch (Exception $e) {
         ob_end_clean();
         throw $e;
     }
     $res2 = $tpl->execute();
     $res3 = $tpl->execute();
     $this->assertEquals($res2, $res3, "Multiple runs should give same result");
     $this->assertEquals($res2, $res, "Execution with and without buffering should give same result");
     return normalize_html($res);
 }
示例#15
0
 /**
  * Return the content in the right format, it tell to the child class to execute template vars inflating
  *
  * @see controller::finalize
  *
  * @return mixed|void
  */
 public function finalize()
 {
     /**
      * Call child for template vars fill
      *
      */
     $this->setTemplateVars();
     try {
         $buffer = ob_get_contents();
         ob_get_clean();
         ob_start("ob_gzhandler");
         // compress page before sending
         $this->nocache();
         header('Content-Type: text/html; charset=utf-8');
         /**
          * Execute Template Rendering
          */
         echo $this->template->execute();
     } catch (Exception $e) {
         echo "<pre>";
         print_r($e);
         echo "\n\n\n";
         echo "</pre>";
         exit;
     }
 }
示例#16
0
    public function getContent()
    {
        global $sql;
        $pager = new Pager('users', Kio::getStat('total', 'users'), Kio::getConfig('limit', 'users'));
        $pager->sort(array(t('Nickname') => 'nickname', t('Group') => 'g_name', t('Gender') => 'gender', t('Title') => 'title', t('Location') => 'locality', t('Country') => 'country', t('Registered') => 'registered'), 'registered', 'asc');
        $query = $sql->query('
			SELECT id, name, inline, members
			FROM ' . DB_PREFIX . 'groups
			ORDER BY display_order');
        while ($row = $query->fetch()) {
            if ($row['inline']) {
                $row['name'] = sprintf($row['inline'], $row['name']);
            }
            $groups[] = $row;
        }
        $query = $sql->query('
			SELECT u.id, u.nickname, u.email, u.registered, u.group_id, u.gender, u.locality, u.country, u.communicator, u.title, g.name g_name
			FROM ' . DB_PREFIX . 'users u
			LEFT JOIN ' . DB_PREFIX . 'groups g ON g.id = u.group_id
			ORDER BY ' . $pager->orderBy . '
			LIMIT ' . $pager->limit . '
			OFFSET ' . $pager->offset);
        while ($row = $query->fetch()) {
            $row['nickname'] = User::format($row['id'], $row['nickname'], $row['group_id']);
            switch ($row['gender']) {
                case 1:
                    $row['gender'] = ' <img class="gender" src="' . LOCAL . 'themes/' . THEME . '/images/male.png" alt="' . t('Male') . '" title="' . t('Male') . '" />';
                    break;
                case 2:
                    $row['gender'] = ' <img class="gender" src="' . LOCAL . 'themes/' . THEME . '/images/female.png" alt="' . t('Female') . '" title="' . t('Female') . '" />';
                    break;
                default:
                    $row['gender'] = '';
            }
            $users[] = $row;
        }
        try {
            $tpl = new PHPTAL('modules/users/users.tpl.html');
            $tpl->sort = $pager->sorters;
            $tpl->users = $users;
            $tpl->groups = $groups;
            $tpl->pagination = $pager->getLinks();
            return $tpl->execute();
        } catch (Exception $e) {
            return template_error($e);
        }
    }
示例#17
0
 public function __construct($template = false)
 {
     $this->setTemplateRepository(self::$_template_dirs);
     if (DEBUG) {
         $this->setForceReparse(true);
     }
     parent::__construct($template);
 }
示例#18
0
文件: PHPTAL.php 项目: hasanozgan/joy
 public function execute($view)
 {
     parent::execute($view);
     return $view->render();
     $context = Joy_Context::getInstance();
     $resource = $view->getResourceList();
     $context->response->addScript($resource["javascripts"]);
     $context->response->addStyle($resource["stylesheets"]);
     $application = $context->config->application->get("application");
     $application["i18n"] = $view->getLocale();
     $tpl = new PHPTAL();
     $tpl->setSource($view->getTemplate());
     $tpl->import = new Joy_Render_Template_Importer($view);
     $tpl->application = $application;
     $tpl->get = (array) $view->assignAll();
     return $tpl->execute();
 }
 /**
  * Create an instance of PHPTAL and initialize it correctly.
  *
  * @return     PHPTAL The PHPTAL instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.2
  */
 protected function createEngineInstance()
 {
     $phptalPhpCodeDestination = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_DIR . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_SUBDIR . DIRECTORY_SEPARATOR;
     // we keep this for < 1.2
     if (!defined('PHPTAL_PHP_CODE_DESTINATION')) {
         define('PHPTAL_PHP_CODE_DESTINATION', $phptalPhpCodeDestination);
     }
     AgaviToolkit::mkdir($phptalPhpCodeDestination, fileperms(AgaviConfig::get('core.cache_dir')), true);
     if (!class_exists('PHPTAL')) {
         require 'PHPTAL.php';
     }
     $phptal = new PHPTAL();
     if (version_compare(PHPTAL_VERSION, '1.2', 'ge')) {
         $phptal->setPhpCodeDestination($phptalPhpCodeDestination);
     }
     return $phptal;
 }
示例#20
0
文件: View.php 项目: radex/Watermelon
 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();
 }
示例#21
0
 /**
  * This method is used to process the data into the view and than return it to the main method that will handle what to do.
  * It also uses buffer to handle that content.
  *
  * @author Klederson Bueno <*****@*****.**>
  * @version 0.1a
  *
  * @param String $___phpBurnFilePath
  * @param Array $__phpBurnData
  * @return String
  */
 public function processViewData($___phpBurnFilePath, $__phpBurnData)
 {
     $tpl = new PHPTAL($___phpBurnFilePath);
     $tpl->setOutputMode(PHPTAL::HTML5);
     foreach ($__phpBurnData as $index => $value) {
         $tpl->{$index} = $value;
     }
     ob_start();
     try {
         echo $tpl->execute();
     } catch (Exception $e) {
         echo $e;
     }
     $___phpBurnBufferStored = ob_get_contents();
     //
     //        //Cleaning the buffer for new sessions
     ob_clean();
     return $___phpBurnBufferStored;
 }
示例#22
0
 public function __construct($template = false)
 {
     parent::__construct($template);
     $this->setTemplateRepository(self::$_template_dirs);
     if (DEBUG) {
         $this->setForceReparse(true);
     }
     $this->static = new Template_StaticContext();
     $this->global = new Template_GlobalContext();
 }
示例#23
0
 public function getContent()
 {
     $err = new Error();
     $note = new Notifier('note-newsletter');
     $form = array();
     $tpl = 'blocks/newsletter/newsletter_form.html';
     if (isset($_POST['add-newsletter']) || isset($_POST['delete-newsletter']) || isset($_POST['delete2-newsletter'])) {
         include_once ROOT . 'blocks/newsletter/action.php';
     }
     try {
         $tpl = new PHPTAL($tpl);
         $tpl->err = $err->toArray();
         $tpl->note = $note;
         $tpl->form = $form;
         return $tpl->execute();
     } catch (Exception $e) {
         return template_error($e->getMessage());
     }
 }
示例#24
0
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;
    }
}
示例#25
0
 /**
  * Create an instance of PHPTAL and initialize it correctly.
  *
  * @return     PHPTAL The PHPTAL instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.2
  */
 protected function createEngineInstance()
 {
     $phptalPhpCodeDestination = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_DIR . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_SUBDIR . DIRECTORY_SEPARATOR;
     // we keep this for < 1.2
     if (!defined('PHPTAL_PHP_CODE_DESTINATION')) {
         define('PHPTAL_PHP_CODE_DESTINATION', $phptalPhpCodeDestination);
     }
     AgaviToolkit::mkdir($phptalPhpCodeDestination, fileperms(AgaviConfig::get('core.cache_dir')), true);
     if (!class_exists('PHPTAL')) {
         require 'PHPTAL.php';
     }
     $phptal = new PHPTAL();
     if (version_compare(PHPTAL_VERSION, '1.2', 'ge')) {
         $phptal->setPhpCodeDestination($phptalPhpCodeDestination);
     } else {
         trigger_error('Support for PHPTAL versions older than 1.2 is deprecated and will be removed in Agavi 1.2.', E_USER_DEPRECATED);
     }
     if ($this->hasParameter('encoding')) {
         $phptal->setEncoding($this->getParameter('encoding'));
     }
     return $phptal;
 }
示例#26
0
 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;
 }
示例#27
0
 /**
  * Render a template
  *
  * $data cannot contain template as a key
  *
  * throws RuntimeException if $templatePath . $template does not exist
  *
  * @param \ResponseInterface $response
  * @param                    $template
  * @param array              $data
  *
  * @return ResponseInterface
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  */
 public function render(ResponseInterface $response, $template, array $data = [])
 {
     if (isset($data['template'])) {
         throw new \InvalidArgumentException("Duplicate template key found");
     }
     if (!is_file($this->templatePath . $template)) {
         throw new \RuntimeException("View cannot render `{$template}` because the template does not exist");
     }
     $template = \PHPTAL::create($this->templatePath . $template);
     foreach ($data as $key => $value) {
         $template->{$key} = $value;
     }
     $response->getBody()->write($template->execute());
     return $response;
 }
示例#28
0
 /**
  * Constructor
  * @param string $tplName The name of the Template file (without .xml)
  * @throws \Exception
  */
 public function __construct($tplName)
 {
     $this->templateFile = BUZZSEO_DIR . DIRECTORY_SEPARATOR . 'tal' . DIRECTORY_SEPARATOR . $tplName . '.xml';
     if (!is_readable($this->templateFile)) {
         throw new \Exception(sprintf(__('File %s does not exist.', 'buzz-seo'), $this->templateFile), 404);
     }
     // Construct PHPTAL object
     parent::__construct();
     // Add translator
     $this->TalTranslator = new Services\Translation();
     $this->TalTranslator->useDomain('buzz-seo');
     $this->setTranslator($this->TalTranslator);
     // Render as HTML5
     $this->setOutputMode(\PHPTAL::HTML5);
     // Strip comments
     $this->stripComments(true);
     // Set source
     $this->setTemplate($this->templateFile);
 }
示例#29
0
 /**
  *
  * @return PHPTAL
  */
 protected function getTAL()
 {
     try {
         if (!$this->TAL instanceof PHPTAL) {
             $this->TAL = new PHPTAL($this->getPathTemplate());
         }
         $translator = new LBoxTranslator($this->getPathTemplate());
         // zajistit existenci ciloveho adresare PHP kodu pro TAL:
         $phptalPhpCodeDestination = LBoxUtil::fixPathSlashes(LBoxConfigSystem::getInstance()->getParamByPath("output/tal/PHPTAL_PHP_CODE_DESTINATION"));
         LBoxUtil::createDirByPath($phptalPhpCodeDestination);
         $this->TAL->setTranslator($translator);
         $this->TAL->setForceReparse(LBoxConfigSystem::getInstance()->getParamByPath("output/tal/PHPTAL_FORCE_REPARSE"));
         $this->TAL->setPhpCodeDestination($phptalPhpCodeDestination);
         $this->TAL->SELF = $this;
         return $this->TAL;
     } catch (Exception $e) {
         throw $e;
     }
 }
示例#30
0
 /**
  * Get the evaluated contents of the view.
  *
  * @param string $path
  * @param array $data
  *
  * @return string
  */
 public function get($path, array $data = [])
 {
     if (!empty($data)) {
         foreach ($data as $field => $value) {
             // Creating error properties in ViewErrorBag
             if ($field == 'errors') {
                 $bags = $value->getBags();
                 if (!in_array('default', array_keys($bags))) {
                     $value->default = new MessageBag([]);
                 }
                 $this->phptal->errors = $value;
             }
             if (!preg_match('/^_|\\s/', $field)) {
                 $this->phptal->{$field} = $value;
             }
         }
     }
     $this->phptal->setTemplate($path);
     return $this->phptal->execute();
 }