本文整理汇总了PHP中PHPTAL类的典型用法代码示例。如果您正苦于以下问题:PHP PHPTAL类的具体用法?PHP PHPTAL怎么用?PHP PHPTAL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPTAL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
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: processViewData
/**
* 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 <klederson@klederson.com>
* @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: getContent
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: getContent
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: PHPTALWithSource
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: render
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: execute
/**
* 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: parse
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: getContent
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: outputTAL
/**
* 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();
}
示例11: __construct
/**
* 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: getContent
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'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't exists.'), array(t('This person was deleted from database.'), t('Entered URL is invalid.')));
}
}
示例13: getContent
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"> </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"> </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: echoExecute
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: getContent
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);
}
}