Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
168
PHPTAL/Php/Attribute/TAL/Attributes.php
Normal file
168
PHPTAL/Php/Attribute/TAL/Attributes.php
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= attribute_statement [';' attribute_statement]*
|
||||
// attribute_statement ::= attribute_name expression
|
||||
// attribute_name ::= [namespace ':'] Name
|
||||
// namespace ::= Name
|
||||
//
|
||||
// examples:
|
||||
//
|
||||
// <a href="/sample/link.html"
|
||||
// tal:attributes="href here/sub/absolute_url">
|
||||
// <textarea rows="80" cols="20"
|
||||
// tal:attributes="rows request/rows;cols request/cols">
|
||||
//
|
||||
// IN PHPTAL: attributes will not work on structured replace.
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/TalesChainExecutor.php';
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Attributes
|
||||
extends PHPTAL_Php_Attribute
|
||||
implements PHPTAL_Php_TalesChainReader
|
||||
{
|
||||
const ATT_FULL_REPLACE = '$__ATT_';
|
||||
const ATT_VALUE_REPLACE = '$__att_';
|
||||
// this regex is used to determine if an attribute is entirely replaced
|
||||
// by a php variable or if only its value is replaced.
|
||||
const REGEX_FULL_REPLACE = '/<?php echo \$__ATT_.*? ?>/';
|
||||
|
||||
public function start()
|
||||
{
|
||||
// split attributes using ; delimiter
|
||||
$attrs = $this->tag->generator->splitExpression($this->expression);
|
||||
foreach ($attrs as $exp) {
|
||||
list($attribute, $expression) = $this->parseSetExpression($exp);
|
||||
if ($expression) {
|
||||
$this->prepareAttribute($attribute, $expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
}
|
||||
|
||||
private function prepareAttribute($attribute, $expression)
|
||||
{
|
||||
$code = $this->extractEchoType(trim($expression));
|
||||
$code = $this->tag->generator->evaluateExpression($code);
|
||||
|
||||
// if $code is an array then the attribute value is decided by a
|
||||
// tales chained expression
|
||||
if (is_array($code)) {
|
||||
return $this->prepareChainedAttribute2($attribute, $code);
|
||||
}
|
||||
|
||||
// XHTML boolean attribute does not appear when empty of false
|
||||
if (PHPTAL_Dom_Defs::getInstance()->isBooleanAttribute($attribute)) {
|
||||
return $this->prepareBooleanAttribute($attribute, $code);
|
||||
}
|
||||
|
||||
// regular attribute which value is the evaluation of $code
|
||||
$attkey = self::ATT_VALUE_REPLACE . $this->getVarName($attribute);
|
||||
if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE)
|
||||
$value = $code;
|
||||
else
|
||||
$value = $this->tag->generator->escapeCode($code);
|
||||
$this->tag->generator->doSetVar($attkey, $value);
|
||||
$this->tag->overwriteAttributeWithPhpValue($attribute, $attkey);
|
||||
}
|
||||
|
||||
private function prepareChainedAttribute2($attribute, $chain)
|
||||
{
|
||||
$this->_default = false;
|
||||
$this->_attribute = $attribute;
|
||||
if (array_key_exists($attribute, $this->tag->attributes)) {
|
||||
$this->_default = $this->tag->attributes[$attribute];
|
||||
}
|
||||
$this->_attkey = self::ATT_FULL_REPLACE.$this->getVarName($attribute);
|
||||
$executor = new PHPTAL_Php_TalesChainExecutor($this->tag->generator, $chain, $this);
|
||||
$this->tag->overwriteAttributeWithPhpValue($attribute, $this->_attkey);
|
||||
}
|
||||
|
||||
private function prepareBooleanAttribute($attribute, $code)
|
||||
{
|
||||
$attkey = self::ATT_FULL_REPLACE.$this->getVarName($attribute);
|
||||
$value = "' $attribute=\"$attribute\"'";
|
||||
$this->tag->generator->doIf($code);
|
||||
$this->tag->generator->doSetVar($attkey, $value);
|
||||
$this->tag->generator->doElse();
|
||||
$this->tag->generator->doSetVar($attkey, '\'\'');
|
||||
$this->tag->generator->doEnd();
|
||||
$this->tag->overwriteAttributeWithPhpValue($attribute, $attkey);
|
||||
}
|
||||
|
||||
private function getVarName($attribute)
|
||||
{
|
||||
return strtr($attribute,':-', '__');
|
||||
}
|
||||
|
||||
public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->doElse();
|
||||
$this->tag->generator->doSetVar(
|
||||
$this->_attkey,
|
||||
"''"
|
||||
);
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->doElse();
|
||||
$code = ($this->_default !== false)
|
||||
? "' $this->_attribute=\"".str_replace("'",'\\\'',$this->_default)."\"'" // default value
|
||||
: '\'\''; // do not print attribute
|
||||
$this->tag->generator->doSetVar($this->_attkey, $code);
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
|
||||
{
|
||||
if (!$islast) {
|
||||
$condition = "!phptal_isempty($this->_attkey = $exp)";
|
||||
}
|
||||
else {
|
||||
$condition = "NULL !== ($this->_attkey = $exp)";
|
||||
}
|
||||
|
||||
$executor->doIf($condition);
|
||||
if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE)
|
||||
$value = $this->_attkey;
|
||||
else
|
||||
$value = $this->tag->generator->escapeCode($this->_attkey);
|
||||
|
||||
$this->tag->generator->doSetVar($this->_attkey, "' $this->_attribute=\"'.$value.'\"'");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
40
PHPTAL/Php/Attribute/TAL/Comment.php
Normal file
40
PHPTAL/Php/Attribute/TAL/Comment.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Comment extends PHPTAL_Php_Attribute
|
||||
{
|
||||
public function start()
|
||||
{
|
||||
$this->tag->generator->doComment($this->expression);
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
101
PHPTAL/Php/Attribute/TAL/Condition.php
Normal file
101
PHPTAL/Php/Attribute/TAL/Condition.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= expression
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// <p tal:condition="here/copyright"
|
||||
// tal:content="here/copyright">(c) 2000</p>
|
||||
//
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/TalesChainExecutor.php';
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Condition
|
||||
extends PHPTAL_Php_Attribute
|
||||
implements PHPTAL_Php_TalesChainReader
|
||||
{
|
||||
private $expressions = array();
|
||||
|
||||
public function start()
|
||||
{
|
||||
$code = $this->tag->generator->evaluateExpression($this->expression);
|
||||
|
||||
// If it's a chained expression build a new code path
|
||||
if (is_array($code)) {
|
||||
$this->expressions = array();
|
||||
$executor = new PHPTAL_Php_TalesChainExecutor( $this->tag->generator, $code, $this );
|
||||
return;
|
||||
}
|
||||
|
||||
// Force a falsy condition if the nothing keyword is active
|
||||
if ($code == PHPTAL_TALES_NOTHING_KEYWORD) {
|
||||
$code = 'false';
|
||||
}
|
||||
|
||||
$this->tag->generator->doIf($code);
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
$this->tag->generator->doEnd();
|
||||
}
|
||||
|
||||
|
||||
public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
|
||||
{
|
||||
// check if the expression is empty
|
||||
if ( $exp !== 'false' ) {
|
||||
$this->expressions[] = '!phptal_isempty($__content__ = ' . $exp . ')';
|
||||
}
|
||||
|
||||
if ( $islast ) {
|
||||
// for the last one in the chain build a ORed condition
|
||||
$this->tag->generator->doIf( implode(' || ', $this->expressions ) );
|
||||
// The executor will always end an if so we output a dummy if
|
||||
$executor->doIf('false');
|
||||
}
|
||||
}
|
||||
|
||||
public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
// end the chain
|
||||
$this->talesChainPart( $executor, 'false', true );
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
throw new PHPTAL_Exception('\'default\' keyword not allowed on condition expressions');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
98
PHPTAL/Php/Attribute/TAL/Content.php
Normal file
98
PHPTAL/Php/Attribute/TAL/Content.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= (['text'] | 'structure') expression
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// <p tal:content="user/name">Fred Farkas</p>
|
||||
//
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/TalesChainExecutor.php';
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Content
|
||||
extends PHPTAL_Php_Attribute
|
||||
implements PHPTAL_Php_TalesChainReader
|
||||
{
|
||||
public function start()
|
||||
{
|
||||
$expression = $this->extractEchoType($this->expression);
|
||||
|
||||
$code = $this->tag->generator->evaluateExpression($expression);
|
||||
|
||||
if (is_array($code)) {
|
||||
return $this->generateChainedContent($code);
|
||||
}
|
||||
|
||||
if ($code == PHPTAL_TALES_NOTHING_KEYWORD) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($code == PHPTAL_TALES_DEFAULT_KEYWORD) {
|
||||
return $this->generateDefault();
|
||||
}
|
||||
|
||||
$this->doEcho($code);
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
}
|
||||
|
||||
private function generateDefault()
|
||||
{
|
||||
$this->tag->generateContent(true);
|
||||
}
|
||||
|
||||
private function generateChainedContent($code)
|
||||
{
|
||||
$executor = new PHPTAL_Php_TalesChainExecutor($this->tag->generator, $code, $this);
|
||||
}
|
||||
|
||||
public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
|
||||
{
|
||||
$executor->doIf('!phptal_isempty($__content__ = '.$exp.')');
|
||||
$this->doEcho('$__content__');
|
||||
}
|
||||
|
||||
public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->doElse();
|
||||
$this->generateDefault();
|
||||
$executor->breakChain();
|
||||
}
|
||||
}
|
||||
?>
|
||||
183
PHPTAL/Php/Attribute/TAL/Define.php
Normal file
183
PHPTAL/Php/Attribute/TAL/Define.php
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL spec 1.4 for tal:define content
|
||||
//
|
||||
// argument ::= define_scope [';' define_scope]*
|
||||
// define_scope ::= (['local'] | 'global') define_var
|
||||
// define_var ::= variable_name expression
|
||||
// variable_name ::= Name
|
||||
//
|
||||
// Note: If you want to include a semi-colon (;) in an expression, it must be escaped by doubling it (;;).*
|
||||
//
|
||||
// examples:
|
||||
//
|
||||
// tal:define="mytitle template/title; tlen python:len(mytitle)"
|
||||
// tal:define="global company_name string:Digital Creations, Inc."
|
||||
//
|
||||
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/TalesChainExecutor.php';
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Define
|
||||
extends PHPTAL_Php_Attribute
|
||||
implements PHPTAL_Php_TalesChainReader
|
||||
{
|
||||
public function start()
|
||||
{
|
||||
$expressions = $this->tag->generator->splitExpression($this->expression);
|
||||
$definesAnyNonGlobalVars = false;
|
||||
|
||||
foreach ($expressions as $exp){
|
||||
list($defineScope, $defineVar, $expression) = $this->parseExpression($exp);
|
||||
if (!$defineVar) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_defineScope = $defineScope;
|
||||
|
||||
if ($defineScope != 'global') $definesAnyNonGlobalVars = true; // <span tal:define="global foo" /> should be invisible, but <img tal:define="bar baz" /> not
|
||||
|
||||
if ($this->_defineScope != 'global' && !$this->_pushedContext){
|
||||
$this->tag->generator->pushContext();
|
||||
$this->_pushedContext = true;
|
||||
}
|
||||
|
||||
$this->_defineVar = $defineVar;
|
||||
if ($expression === null) {
|
||||
// no expression give, use content of tag as value for newly defined
|
||||
// var.
|
||||
$this->bufferizeContent();
|
||||
continue;
|
||||
}
|
||||
|
||||
$code = $this->tag->generator->evaluateExpression($expression);
|
||||
if (is_array($code)){
|
||||
$this->chainedDefine($code);
|
||||
}
|
||||
elseif ($code == PHPTAL_TALES_NOTHING_KEYWORD) {
|
||||
$this->doDefineVarWith('null');
|
||||
}
|
||||
else {
|
||||
$this->doDefineVarWith($code);
|
||||
}
|
||||
}
|
||||
|
||||
// if the content of the tag was buffered or the tag has nothing to tell, we hide it.
|
||||
if ($this->_buffered || (!$definesAnyNonGlobalVars && !$this->tag->hasRealContent() && !$this->tag->hasRealAttributes())){
|
||||
$this->tag->hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
if ($this->_pushedContext){
|
||||
$this->tag->generator->popContext();
|
||||
}
|
||||
}
|
||||
|
||||
private function chainedDefine($parts)
|
||||
{
|
||||
$executor = new PHPTAL_Php_TalesChainExecutor(
|
||||
$this->tag->generator, $parts, $this
|
||||
);
|
||||
}
|
||||
|
||||
public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->doElse();
|
||||
$this->doDefineVarWith('null');
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->doElse();
|
||||
$this->bufferizeContent();
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
|
||||
{
|
||||
if ($this->_defineScope == 'global'){
|
||||
$executor->doIf('($glb->'.$this->_defineVar.' = '.$exp.') !== null');
|
||||
}
|
||||
else {
|
||||
$executor->doIf('($ctx->'.$this->_defineVar.' = '.$exp.') !== null');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the define expression, already splitted in sub parts by ';'.
|
||||
*/
|
||||
public function parseExpression($exp)
|
||||
{
|
||||
$defineScope = false; // (local | global)
|
||||
$defineVar = false; // var to define
|
||||
|
||||
// extract defineScope from expression
|
||||
$exp = trim($exp);
|
||||
if (preg_match('/^(local|global)\s+(.*?)$/ism', $exp, $m)) {
|
||||
list(,$defineScope, $exp) = $m;
|
||||
$exp = trim($exp);
|
||||
}
|
||||
|
||||
// extract varname and expression from remaining of expression
|
||||
list($defineVar, $exp) = $this->parseSetExpression($exp);
|
||||
if ($exp !== null) $exp = trim($exp);
|
||||
return array($defineScope, $defineVar, $exp);
|
||||
}
|
||||
|
||||
private function bufferizeContent()
|
||||
{
|
||||
if (!$this->_buffered){
|
||||
$this->tag->generator->pushCode( 'ob_start()' );
|
||||
$this->tag->generateContent();
|
||||
$this->tag->generator->pushCode('$__tmp_content__ = ob_get_clean()');
|
||||
$this->_buffered = true;
|
||||
}
|
||||
$this->doDefineVarWith('$__tmp_content__');
|
||||
}
|
||||
|
||||
private function doDefineVarWith($code)
|
||||
{
|
||||
if ($this->_defineScope == 'global'){
|
||||
$this->tag->generator->doSetVar('$glb->'.$this->_defineVar, $code);
|
||||
}
|
||||
else {
|
||||
$this->tag->generator->doSetVar('$ctx->'.$this->_defineVar, $code);
|
||||
}
|
||||
}
|
||||
|
||||
private $_buffered = false;
|
||||
private $_defineScope = null;
|
||||
private $_defineVar = null;
|
||||
private $_pushedContext = false;
|
||||
}
|
||||
|
||||
?>
|
||||
74
PHPTAL/Php/Attribute/TAL/OmitTag.php
Normal file
74
PHPTAL/Php/Attribute/TAL/OmitTag.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= [expression]
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// <div tal:omit-tag="" comment="This tag will be removed">
|
||||
// <i>...but this text will remain.</i>
|
||||
// </div>
|
||||
//
|
||||
// <b tal:omit-tag="not:bold">I may not be bold.</b>
|
||||
//
|
||||
// To leave the contents of a tag in place while omitting the surrounding
|
||||
// start and end tag, use the omit-tag statement.
|
||||
//
|
||||
// If its expression evaluates to a false value, then normal processing
|
||||
// of the element continues.
|
||||
//
|
||||
// If the expression evaluates to a true value, or there is no
|
||||
// expression, the statement tag is replaced with its contents. It is up to
|
||||
// the interface between TAL and the expression engine to determine the
|
||||
// value of true and false. For these purposes, the value nothing is false,
|
||||
// and cancellation of the action has the same effect as returning a
|
||||
// false value.
|
||||
//
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_OmitTag extends PHPTAL_Php_Attribute
|
||||
{
|
||||
public function start()
|
||||
{
|
||||
if (trim($this->expression) == ''){
|
||||
$this->tag->headFootDisabled = true;
|
||||
}
|
||||
else {
|
||||
// print tag header/foot only if condition is false
|
||||
$cond = $this->tag->generator->evaluateExpression($this->expression);
|
||||
$this->tag->headFootPrintCondition = '!('.$cond.')';
|
||||
}
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
81
PHPTAL/Php/Attribute/TAL/OnError.php
Normal file
81
PHPTAL/Php/Attribute/TAL/OnError.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= (['text'] | 'structure') expression
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// <p tal:on-error="string: Error! This paragraph is buggy!">
|
||||
// My name is <span tal:replace="here/SlimShady" />.<br />
|
||||
// (My login name is
|
||||
// <b tal:on-error="string: Username is not defined!"
|
||||
// tal:content="user">Unknown</b>)
|
||||
// </p>
|
||||
//
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_OnError extends PHPTAL_Php_Attribute
|
||||
{
|
||||
const ERR_VAR = '$__err__';
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->tag->generator->doTry();
|
||||
$this->tag->generator->pushCode('ob_start()');
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
$this->tag->generator->pushCode('ob_end_flush()');
|
||||
$this->tag->generator->doCatch('Exception '.self::ERR_VAR);
|
||||
$this->tag->generator->pushCode('$tpl->addError('.self::ERR_VAR.')');
|
||||
$this->tag->generator->pushCode('ob_end_clean()');
|
||||
|
||||
$expression = $this->extractEchoType($this->expression);
|
||||
|
||||
$code = $this->tag->generator->evaluateExpression($expression);
|
||||
switch ($code) {
|
||||
case PHPTAL_TALES_NOTHING_KEYWORD:
|
||||
break;
|
||||
|
||||
case PHPTAL_TALES_DEFAULT_KEYWORD:
|
||||
$this->tag->generator->pushHtml('<pre class="phptalError"');
|
||||
$this->tag->generator->doEcho(self::ERR_VAR);
|
||||
$this->tag->generator->pushHtml('</pre>');
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->doEcho($code);
|
||||
break;
|
||||
}
|
||||
$this->tag->generator->doEnd();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
115
PHPTAL/Php/Attribute/TAL/Repeat.php
Normal file
115
PHPTAL/Php/Attribute/TAL/Repeat.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= variable_name expression
|
||||
// variable_name ::= Name
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// <p tal:repeat="txt python:'one', 'two', 'three'">
|
||||
// <span tal:replace="txt" />
|
||||
// </p>
|
||||
// <table>
|
||||
// <tr tal:repeat="item here/cart">
|
||||
// <td tal:content="repeat/item/index">1</td>
|
||||
// <td tal:content="item/description">Widget</td>
|
||||
// <td tal:content="item/price">$1.50</td>
|
||||
// </tr>
|
||||
// </table>
|
||||
//
|
||||
// The following information is available from an Iterator:
|
||||
//
|
||||
// * index - repetition number, starting from zero.
|
||||
// * number - repetition number, starting from one.
|
||||
// * even - true for even-indexed repetitions (0, 2, 4, ...).
|
||||
// * odd - true for odd-indexed repetitions (1, 3, 5, ...).
|
||||
// * start - true for the starting repetition (index 0).
|
||||
// * end - true for the ending, or final, repetition.
|
||||
// * length - length of the sequence, which will be the total number of repetitions.
|
||||
//
|
||||
// * letter - count reps with lower-case letters: "a" - "z", "aa" - "az", "ba" - "bz", ..., "za" - "zz", "aaa" - "aaz", and so forth.
|
||||
// * Letter - upper-case version of letter.
|
||||
// * roman - count reps with lower-case roman numerals: "i", "ii", "iii", "iv", "v", "vi" ...
|
||||
// * Roman - upper-case version of roman numerals.
|
||||
///
|
||||
// * first - true for the first item in a group - see note below
|
||||
// * lasst - true for the last item in a group - see note below
|
||||
//
|
||||
// Note: first and last are intended for use with sorted sequences. They try to
|
||||
// divide the sequence into group of items with the same value. If you provide
|
||||
// a path, then the value obtained by following that path from a sequence item
|
||||
// is used for grouping, otherwise the value of the item is used. You can
|
||||
// provide the path by appending it to the path from the repeat variable,
|
||||
// as in "repeat/item/first/color".
|
||||
//
|
||||
// PHPTAL: index, number, even, etc... will be stored in the
|
||||
// $ctx->repeat->'item' object. Thus $ctx->repeat->item->odd
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Repeat extends PHPTAL_Php_Attribute
|
||||
{
|
||||
const REPEAT = '$__repeat__';
|
||||
|
||||
public function start()
|
||||
{
|
||||
// alias to repeats handler to avoid calling extra getters on each variable access
|
||||
$this->tag->generator->doSetVar( self::REPEAT, '$ctx->repeat' );
|
||||
|
||||
list( $varName, $expression ) = $this->parseSetExpression( $this->expression );
|
||||
$code = $this->tag->generator->evaluateExpression( $expression );
|
||||
|
||||
$item = '$ctx->' . $varName;
|
||||
$controller = self::REPEAT . '->' . $varName;
|
||||
|
||||
// reset item var into template context
|
||||
/* // Is this actually needed?
|
||||
$this->tag->generator->doIf( '!isset('.$this->item.')' );
|
||||
$this->tag->generator->doSetVar( $this->item, 'false' );
|
||||
$this->tag->generator->doEnd();
|
||||
*/
|
||||
|
||||
// instantiate controller using expression
|
||||
$this->tag->generator->doSetVar( $controller, 'new PHPTAL_RepeatController('.$code.')' );
|
||||
|
||||
// Lets loop the iterator with a foreach construct
|
||||
$this->tag->generator->doForeach( $item, $controller );
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
$this->tag->generator->doEnd();
|
||||
}
|
||||
|
||||
private $item;
|
||||
private $controller;
|
||||
}
|
||||
|
||||
?>
|
||||
117
PHPTAL/Php/Attribute/TAL/Replace.php
Normal file
117
PHPTAL/Php/Attribute/TAL/Replace.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// Copyright (c) 2004-2005 Laurent Bedubourg
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Authors: Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
|
||||
|
||||
// TAL Specifications 1.4
|
||||
//
|
||||
// argument ::= (['text'] | 'structure') expression
|
||||
//
|
||||
// Default behaviour : text
|
||||
//
|
||||
// <span tal:replace="template/title">Title</span>
|
||||
// <span tal:replace="text template/title">Title</span>
|
||||
// <span tal:replace="structure table" />
|
||||
// <span tal:replace="nothing">This element is a comment.</span>
|
||||
//
|
||||
|
||||
require_once PHPTAL_DIR.'PHPTAL/Php/TalesChainExecutor.php';
|
||||
|
||||
/**
|
||||
* @package phptal.php.attribute.tal
|
||||
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
|
||||
*/
|
||||
class PHPTAL_Php_Attribute_TAL_Replace
|
||||
extends PHPTAL_Php_Attribute
|
||||
implements PHPTAL_Php_TalesChainReader
|
||||
{
|
||||
const REPLACE_VAR = '$__replace__';
|
||||
|
||||
public function start()
|
||||
{
|
||||
// tal:replace="" => do nothing and ignore node
|
||||
if (trim($this->expression) == ""){
|
||||
return;
|
||||
}
|
||||
|
||||
$expression = $this->extractEchoType($this->expression);
|
||||
$code = $this->tag->generator->evaluateExpression($expression);
|
||||
|
||||
// chained expression
|
||||
if (is_array($code)){
|
||||
return $this->replaceByChainedExpression($code);
|
||||
}
|
||||
|
||||
// nothing do nothing
|
||||
if ($code == PHPTAL_TALES_NOTHING_KEYWORD) {
|
||||
return;
|
||||
}
|
||||
|
||||
// default generate default tag content
|
||||
if ($code == PHPTAL_TALES_DEFAULT_KEYWORD) {
|
||||
return $this->generateDefault();
|
||||
}
|
||||
|
||||
// replace tag with result of expression
|
||||
$this->doEcho($code);
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
}
|
||||
|
||||
private function replaceByChainedExpression($expArray)
|
||||
{
|
||||
$executor = new PHPTAL_Php_TalesChainExecutor(
|
||||
$this->tag->generator, $expArray, $this
|
||||
);
|
||||
}
|
||||
|
||||
public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->continueChain();
|
||||
}
|
||||
|
||||
public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
|
||||
{
|
||||
$executor->doElse();
|
||||
$this->generateDefault();
|
||||
$executor->breakChain();
|
||||
}
|
||||
|
||||
public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
|
||||
{
|
||||
$executor->doIf('!phptal_isempty('.self::REPLACE_VAR.' = '.$exp.')');
|
||||
$this->doEcho(self::REPLACE_VAR);
|
||||
}
|
||||
|
||||
private function generateDefault()
|
||||
{
|
||||
$this->tag->generateSurroundHead();
|
||||
$this->tag->generateHead();
|
||||
$this->tag->generateContent();
|
||||
$this->tag->generateFoot();
|
||||
$this->tag->generateSurroundFoot();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue