Permalink
Browse files

Added PHPTAL as an Addon (you can remove it) and Integrated phptalVie…

…ws with it
  • Loading branch information...
Klederson Bueno
Klederson Bueno committed Aug 19, 2010
1 parent 477cb0d commit 1c68af19140f5806d68065dd01d7f0f3745fdf14
Showing 449 changed files with 20,456 additions and 4 deletions.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,196 @@
<?php
/**
* PHPTAL templating engine
*
* PHP Version 5
*
* @category HTML
* @package PHPTAL
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
* @author Kornel Lesiński <kornel@aardvarkmedia.co.uk>
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id: Attr.php 715 2009-09-14 22:57:56Z kornel $
* @link http://phptal.org/
*/
/**
* node that represents element's attribute
*
* @package PHPTAL
* @subpackage Dom
*/
class PHPTAL_Dom_Attr
{
private $value_escaped, $qualified_name, $namespace_uri, $encoding;
/**
* attribute's value can be overriden with a variable
*/
private $phpVariable;
const HIDDEN = -1;
const NOT_REPLACED = 0;
const VALUE_REPLACED = 1;
const FULLY_REPLACED = 2;
private $replacedState = 0;
/**
* @param string $qualified_name attribute name with prefix
* @param string $namespace_uri full namespace URI or empty string
* @param string $value_escaped value with HTML-escaping
* @param string $encoding character encoding used by the value
*/
function __construct($qualified_name, $namespace_uri, $value_escaped, $encoding)
{
$this->value_escaped = $value_escaped;
$this->qualified_name = $qualified_name;
$this->namespace_uri = $namespace_uri;
$this->encoding = $encoding;
}
/**
* get character encoding used by this attribute.
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* get full namespace URI. "" for default namespace.
*/
function getNamespaceURI()
{
return $this->namespace_uri;
}
/**
* get attribute name including namespace prefix, if any
*/
function getQualifiedName()
{
return $this->qualified_name;
}
/**
* get "foo" of "ns:foo" attribute name
*/
function getLocalName()
{
$n = explode(':', $this->qualified_name,2);
return end($n);
}
/**
* Returns true if this attribute is ns declaration (xmlns="...")
*
* @return bool
*/
function isNamespaceDeclaration()
{
return preg_match('/^xmlns(?:$|:)/',$this->qualified_name);
}
/**
* get value as plain text
*
* @return string
*/
function getValue()
{
return html_entity_decode($this->value_escaped, ENT_QUOTES, $this->encoding);
}
/**
* set plain text as value
*/
function setValue($val)
{
$this->value_escaped = htmlspecialchars($val);
}
/**
* Depends on replaced state.
* If value is not replaced, it will return it with HTML escapes.
*
* @see getReplacedState()
* @see overwriteValueWithVariable()
*/
function getValueEscaped()
{
return $this->value_escaped;
}
/**
* Set value of the attribute to this exact string.
* String must be HTML-escaped and use attribute's encoding.
*
* @param string $value_escaped new content
*/
function setValueEscaped($value_escaped)
{
$this->replacedState = self::NOT_REPLACED;
$this->value_escaped = $value_escaped;
}
/**
* set PHP code as value of this attribute. Code is expected to echo the value.
*/
private function setPHPCode($code)
{
$this->value_escaped = '<?php '.$code.' ?>';
}
/**
* hide this attribute. It won't be generated.
*/
function hide()
{
$this->replacedState = self::HIDDEN;
}
/**
* generate value of this attribute from variable
*/
function overwriteValueWithVariable($phpVariable)
{
$this->replacedState = self::VALUE_REPLACED;
$this->phpVariable = $phpVariable;
$this->setPHPCode('echo '.$phpVariable);
}
/**
* generate complete syntax of this attribute using variable
*/
function overwriteFullWithVariable($phpVariable)
{
$this->replacedState = self::FULLY_REPLACED;
$this->phpVariable = $phpVariable;
$this->setPHPCode('echo '.$phpVariable);
}
/**
* use any PHP code to generate this attribute's value
*/
function overwriteValueWithCode($code)
{
$this->replacedState = self::VALUE_REPLACED;
$this->phpVariable = NULL;
$this->setPHPCode($code);
}
/**
* if value was overwritten with variable, get its name
*/
function getOverwrittenVariableName()
{
return $this->phpVariable;
}
/**
* whether getValueEscaped() returns real value or PHP code
*/
function getReplacedState()
{
return $this->replacedState;
}
}
@@ -0,0 +1,48 @@
<?php
/**
* PHPTAL templating engine
*
* PHP Version 5
*
* @category HTML
* @package PHPTAL
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
* @author Kornel Lesiński <kornel@aardvarkmedia.co.uk>
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id: CDATASection.php 605 2009-05-03 02:50:26Z kornel $
* @link http://phptal.org/
*/
/**
* Outputs <![CDATA[ ]]> blocks, sometimes converts them to text
* @todo this might be moved to CDATA processing in Element
*
* @package PHPTAL
* @subpackage Dom
*/
class PHPTAL_Dom_CDATASection extends PHPTAL_Dom_Node
{
public function generateCode(PHPTAL_Php_CodeWriter $codewriter)
{
$mode = $codewriter->getOutputMode();
$value = $this->getValueEscaped();
$inCDATAelement = PHPTAL_Dom_Defs::getInstance()->isCDATAElementInHTML($this->parentNode->getNamespaceURI(), $this->parentNode->getLocalName());
// in HTML5 must limit it to <script> and <style>
if ($mode === PHPTAL::HTML5 && $inCDATAelement) {
$codewriter->pushHTML($codewriter->interpolateCDATA(str_replace('</', '<\/', $value)));
} elseif (($mode === PHPTAL::XHTML && $inCDATAelement) // safe for text/html
|| ($mode === PHPTAL::XML && preg_match('/[<>&]/', $value)) // non-useless in XML
|| ($mode !== PHPTAL::HTML5 && preg_match('/<\?|\${structure/', $value))) // hacks with structure (in X[HT]ML) may need it
{
// in text/html "</" is dangerous and the only sensible way to escape is ECMAScript string escapes.
if ($mode === PHPTAL::XHTML) $value = str_replace('</', '<\/', $value);
$codewriter->pushHTML($codewriter->interpolateCDATA('<![CDATA['.$value.']]>'));
} else {
$codewriter->pushHTML($codewriter->interpolateHTML(htmlspecialchars($value)));
}
}
}
@@ -0,0 +1,28 @@
<?php
/**
* PHPTAL templating engine
*
* PHP Version 5
*
* @category HTML
* @package PHPTAL
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
* @author Kornel Lesiński <kornel@aardvarkmedia.co.uk>
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id: Comment.php 739 2009-09-25 18:11:22Z kornel $
* @link http://phptal.org/
*/
/**
* @package PHPTAL
* @subpackage Dom
*/
class PHPTAL_Dom_Comment extends PHPTAL_Dom_Node
{
public function generateCode(PHPTAL_Php_CodeWriter $codewriter)
{
if (!preg_match('/^\s*!/', $this->getValueEscaped())) {
$codewriter->pushHTML('<!--'.$this->getValueEscaped().'-->');
}
}
}
Oops, something went wrong.

0 comments on commit 1c68af1

Please sign in to comment.