adding zend project folders into old campcaster.
This commit is contained in:
parent
56abfaf28e
commit
7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions
38
library/Zend/Markup/Exception.php
Normal file
38
library/Zend/Markup/Exception.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Markup
|
||||
*
|
||||
* @category Zend
|
||||
* @uses Zend_Exception
|
||||
* @package Zend_Markup
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
504
library/Zend/Markup/Parser/Bbcode.php
Normal file
504
library/Zend/Markup/Parser/Bbcode.php
Normal file
|
@ -0,0 +1,504 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Bbcode.php 21128 2010-02-21 15:36:07Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_TokenList
|
||||
*/
|
||||
require_once 'Zend/Markup/TokenList.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Parser_ParserInterface
|
||||
*/
|
||||
require_once 'Zend/Markup/Parser/ParserInterface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Parser_Bbcode implements Zend_Markup_Parser_ParserInterface
|
||||
{
|
||||
const NEWLINE = "[newline\0]";
|
||||
|
||||
// there is a parsing difference between the default tags and single tags
|
||||
const TYPE_DEFAULT = 'default';
|
||||
const TYPE_SINGLE = 'single';
|
||||
|
||||
const NAME_CHARSET = '^\[\]=\s';
|
||||
|
||||
const STATE_SCAN = 0;
|
||||
const STATE_SCANATTRS = 1;
|
||||
const STATE_PARSEVALUE = 2;
|
||||
|
||||
/**
|
||||
* Token tree
|
||||
*
|
||||
* @var Zend_Markup_TokenList
|
||||
*/
|
||||
protected $_tree;
|
||||
|
||||
/**
|
||||
* Current token
|
||||
*
|
||||
* @var Zend_Markup_Token
|
||||
*/
|
||||
protected $_current;
|
||||
|
||||
/**
|
||||
* Source to tokenize
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_value = '';
|
||||
|
||||
/**
|
||||
* Length of the value
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_valueLen = 0;
|
||||
|
||||
/**
|
||||
* Current pointer
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_pointer = 0;
|
||||
|
||||
/**
|
||||
* The buffer
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_buffer = '';
|
||||
|
||||
/**
|
||||
* Temporary tag storage
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_temp;
|
||||
|
||||
/**
|
||||
* Stoppers that we are searching for
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_searchedStoppers = array();
|
||||
|
||||
/**
|
||||
* Tag information
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags = array(
|
||||
'Zend_Markup_Root' => array(
|
||||
'type' => self::TYPE_DEFAULT,
|
||||
'stoppers' => array(),
|
||||
),
|
||||
'*' => array(
|
||||
'type' => self::TYPE_DEFAULT,
|
||||
'stoppers' => array(self::NEWLINE, '[/*]', '[/]'),
|
||||
),
|
||||
'hr' => array(
|
||||
'type' => self::TYPE_SINGLE,
|
||||
'stoppers' => array(),
|
||||
),
|
||||
'code' => array(
|
||||
'type' => self::TYPE_DEFAULT,
|
||||
'stoppers' => array('[/code]', '[/]'),
|
||||
'parse_inside' => false
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Token array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tokens = array();
|
||||
|
||||
/**
|
||||
* State
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_state = self::STATE_SCAN;
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the parsing of a bbcode string, the real parsing is done in {@link _parse()}
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Markup_TokenList
|
||||
*/
|
||||
public function parse($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
/**
|
||||
* @see Zend_Markup_Parser_Exception
|
||||
*/
|
||||
require_once 'Zend/Markup/Parser/Exception.php';
|
||||
throw new Zend_Markup_Parser_Exception('Value to parse should be a string.');
|
||||
}
|
||||
|
||||
if (empty($value)) {
|
||||
/**
|
||||
* @see Zend_Markup_Parser_Exception
|
||||
*/
|
||||
require_once 'Zend/Markup/Parser/Exception.php';
|
||||
throw new Zend_Markup_Parser_Exception('Value to parse cannot be left empty.');
|
||||
}
|
||||
|
||||
$this->_value = str_replace(array("\r\n", "\r", "\n"), self::NEWLINE, $value);
|
||||
|
||||
// variable initialization for tokenizer
|
||||
$this->_valueLen = strlen($this->_value);
|
||||
$this->_pointer = 0;
|
||||
$this->_buffer = '';
|
||||
$this->_temp = array();
|
||||
$this->_state = self::STATE_SCAN;
|
||||
$this->_tokens = array();
|
||||
|
||||
$this->_tokenize();
|
||||
|
||||
// variable initialization for treebuilder
|
||||
$this->_searchedStoppers = array();
|
||||
$this->_tree = new Zend_Markup_TokenList();
|
||||
$this->_current = new Zend_Markup_Token(
|
||||
'',
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'Zend_Markup_Root'
|
||||
);
|
||||
|
||||
$this->_tree->addChild($this->_current);
|
||||
|
||||
$this->_createTree();
|
||||
|
||||
return $this->_tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tokenize
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _tokenize()
|
||||
{
|
||||
$attribute = '';
|
||||
|
||||
while ($this->_pointer < $this->_valueLen) {
|
||||
switch ($this->_state) {
|
||||
case self::STATE_SCAN:
|
||||
$matches = array();
|
||||
$regex = '#\G(?<text>[^\[]*)(?<open>\[(?<name>[' . self::NAME_CHARSET . ']+)?)?#';
|
||||
preg_match($regex, $this->_value, $matches, null, $this->_pointer);
|
||||
|
||||
$this->_pointer += strlen($matches[0]);
|
||||
|
||||
if (!empty($matches['text'])) {
|
||||
$this->_buffer .= $matches['text'];
|
||||
}
|
||||
|
||||
if (!isset($matches['open'])) {
|
||||
// great, no tag, we are ending the string
|
||||
break;
|
||||
}
|
||||
if (!isset($matches['name'])) {
|
||||
$this->_buffer .= $matches['open'];
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_temp = array(
|
||||
'tag' => '[' . $matches['name'],
|
||||
'name' => $matches['name'],
|
||||
'attributes' => array()
|
||||
);
|
||||
|
||||
if ($this->_pointer >= $this->_valueLen) {
|
||||
// damn, no tag
|
||||
$this->_buffer .= $this->_temp['tag'];
|
||||
break 2;
|
||||
}
|
||||
|
||||
if ($this->_value[$this->_pointer] == '=') {
|
||||
$this->_pointer++;
|
||||
|
||||
$this->_temp['tag'] .= '=';
|
||||
$this->_state = self::STATE_PARSEVALUE;
|
||||
$attribute = $this->_temp['name'];
|
||||
} else {
|
||||
$this->_state = self::STATE_SCANATTRS;
|
||||
}
|
||||
break;
|
||||
case self::STATE_SCANATTRS:
|
||||
$matches = array();
|
||||
$regex = '#\G((?<end>\s*\])|\s+(?<attribute>[' . self::NAME_CHARSET . ']+)(?<eq>=?))#';
|
||||
if (!preg_match($regex, $this->_value, $matches, null, $this->_pointer)) {
|
||||
break 2;
|
||||
}
|
||||
|
||||
$this->_pointer += strlen($matches[0]);
|
||||
|
||||
if (!empty($matches['end'])) {
|
||||
if (!empty($this->_buffer)) {
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $this->_buffer,
|
||||
'type' => Zend_Markup_Token::TYPE_NONE
|
||||
);
|
||||
$this->_buffer = '';
|
||||
}
|
||||
$this->_temp['tag'] .= $matches['end'];
|
||||
$this->_temp['type'] = Zend_Markup_Token::TYPE_TAG;
|
||||
|
||||
$this->_tokens[] = $this->_temp;
|
||||
$this->_temp = array();
|
||||
|
||||
$this->_state = self::STATE_SCAN;
|
||||
} else {
|
||||
// attribute name
|
||||
$attribute = $matches['attribute'];
|
||||
|
||||
$this->_temp['tag'] .= $matches[0];
|
||||
|
||||
$this->_temp['attributes'][$attribute] = '';
|
||||
|
||||
if (empty($matches['eq'])) {
|
||||
$this->_state = self::STATE_SCANATTRS;
|
||||
} else {
|
||||
$this->_state = self::STATE_PARSEVALUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case self::STATE_PARSEVALUE:
|
||||
$matches = array();
|
||||
$regex = '#\G((?<quote>"|\')(?<valuequote>.*?)\\2|(?<value>[^\]\s]+))#';
|
||||
if (!preg_match($regex, $this->_value, $matches, null, $this->_pointer)) {
|
||||
$this->_state = self::STATE_SCANATTRS;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_pointer += strlen($matches[0]);
|
||||
|
||||
if (!empty($matches['quote'])) {
|
||||
$this->_temp['attributes'][$attribute] = $matches['valuequote'];
|
||||
} else {
|
||||
$this->_temp['attributes'][$attribute] = $matches['value'];
|
||||
}
|
||||
$this->_temp['tag'] .= $matches[0];
|
||||
|
||||
$this->_state = self::STATE_SCANATTRS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_buffer)) {
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $this->_buffer,
|
||||
'type' => Zend_Markup_Token::TYPE_NONE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the token array into a tree
|
||||
*
|
||||
* @param array $tokens
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _createTree()
|
||||
{
|
||||
foreach ($this->_tokens as $token) {
|
||||
// first we want to know if this tag is a stopper, or at least a searched one
|
||||
if ($this->_isStopper($token['tag'])) {
|
||||
// find the stopper
|
||||
$oldItems = array();
|
||||
|
||||
while (!in_array($token['tag'], $this->_tags[$this->_current->getName()]['stoppers'])) {
|
||||
$oldItems[] = clone $this->_current;
|
||||
$this->_current = $this->_current->getParent();
|
||||
}
|
||||
|
||||
// we found the stopper, so stop the tag
|
||||
$this->_current->setStopper($token['tag']);
|
||||
$this->_removeFromSearchedStoppers($this->_current);
|
||||
$this->_current = $this->_current->getParent();
|
||||
|
||||
// add the old items again if there are any
|
||||
if (!empty($oldItems)) {
|
||||
foreach (array_reverse($oldItems) as $item) {
|
||||
/* @var $token Zend_Markup_Token */
|
||||
$this->_current->addChild($item);
|
||||
$item->setParent($this->_current);
|
||||
$this->_current = $item;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($token['type'] == Zend_Markup_Token::TYPE_TAG) {
|
||||
if ($token['tag'] == self::NEWLINE) {
|
||||
// this is a newline tag, add it as a token
|
||||
$this->_current->addChild(new Zend_Markup_Token(
|
||||
"\n",
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'',
|
||||
array(),
|
||||
$this->_current
|
||||
));
|
||||
} elseif (isset($token['name']) && ($token['name'][0] == '/')) {
|
||||
// this is a stopper, add it as a empty token
|
||||
$this->_current->addChild(new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'',
|
||||
array(),
|
||||
$this->_current
|
||||
));
|
||||
} elseif (isset($this->_tags[$this->_current->getName()]['parse_inside'])
|
||||
&& !$this->_tags[$this->_current->getName()]['parse_inside']
|
||||
) {
|
||||
$this->_current->addChild(new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'',
|
||||
array(),
|
||||
$this->_current
|
||||
));
|
||||
} else {
|
||||
// add the tag
|
||||
$child = new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
$token['type'],
|
||||
$token['name'],
|
||||
$token['attributes'],
|
||||
$this->_current
|
||||
);
|
||||
$this->_current->addChild($child);
|
||||
|
||||
// add stoppers for this tag, if its has stoppers
|
||||
if ($this->_getType($token['name']) == self::TYPE_DEFAULT) {
|
||||
$this->_current = $child;
|
||||
|
||||
$this->_addToSearchedStoppers($this->_current);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no tag, just add it as a simple token
|
||||
$this->_current->addChild(new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'',
|
||||
array(),
|
||||
$this->_current
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a tag declaration, and if it isnt there, add it
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _checkTagDeclaration($name)
|
||||
{
|
||||
if (!isset($this->_tags[$name])) {
|
||||
$this->_tags[$name] = array(
|
||||
'type' => self::TYPE_DEFAULT,
|
||||
'stoppers' => array(
|
||||
'[/' . $name . ']',
|
||||
'[/]'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the tag's type
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function _getType($name)
|
||||
{
|
||||
$this->_checkTagDeclaration($name);
|
||||
|
||||
return $this->_tags[$name]['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the tag is a stopper
|
||||
*
|
||||
* @param string $tag
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isStopper($tag)
|
||||
{
|
||||
$this->_checkTagDeclaration($this->_current->getName());
|
||||
|
||||
if (!empty($this->_searchedStoppers[$tag])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to searched stoppers
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @return void
|
||||
*/
|
||||
protected function _addToSearchedStoppers(Zend_Markup_Token $token)
|
||||
{
|
||||
$this->_checkTagDeclaration($token->getName());
|
||||
|
||||
foreach ($this->_tags[$token->getName()]['stoppers'] as $stopper) {
|
||||
if (!isset($this->_searchedStoppers[$stopper])) {
|
||||
$this->_searchedStoppers[$stopper] = 0;
|
||||
}
|
||||
++$this->_searchedStoppers[$stopper];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove from searched stoppers
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @return void
|
||||
*/
|
||||
protected function _removeFromSearchedStoppers(Zend_Markup_Token $token)
|
||||
{
|
||||
$this->_checkTagDeclaration($token->getName());
|
||||
|
||||
foreach ($this->_tags[$token->getName()]['stoppers'] as $stopper) {
|
||||
--$this->_searchedStoppers[$stopper];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
library/Zend/Markup/Parser/Exception.php
Normal file
40
library/Zend/Markup/Parser/Exception.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Exception
|
||||
*/
|
||||
require_once 'Zend/Markup/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Markup_Parser
|
||||
*
|
||||
* @category Zend
|
||||
* @uses Zend_Markup_Exception
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Parser_Exception extends Zend_Markup_Exception
|
||||
{
|
||||
}
|
67
library/Zend/Markup/Parser/ParserInterface.php
Normal file
67
library/Zend/Markup/Parser/ParserInterface.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ParserInterface.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Markup_Parser_ParserInterface
|
||||
{
|
||||
/**
|
||||
* Parse a string
|
||||
*
|
||||
* This should output something like this:
|
||||
*
|
||||
* <code>
|
||||
* array(
|
||||
* array(
|
||||
* 'tag' => '[tag="a" attr=val]',
|
||||
* 'type' => Zend_Markup::TYPE_TAG,
|
||||
* 'name' => 'tag',
|
||||
* 'stoppers' => array('[/]', '[/tag]'),
|
||||
* 'attributes' => array(
|
||||
* 'tag' => 'a',
|
||||
* 'attr' => 'val'
|
||||
* )
|
||||
* ),
|
||||
* array(
|
||||
* 'tag' => 'value',
|
||||
* 'type' => Zend_Markup::TYPE_NONE
|
||||
* ),
|
||||
* array(
|
||||
* 'tag' => '[/tag]',
|
||||
* 'type' => Zend_Markup::TYPE_STOPPER,
|
||||
* 'name' => 'tag',
|
||||
* 'stoppers' => array(),
|
||||
* 'attributes' => array()
|
||||
* )
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @param string $value
|
||||
* @return array
|
||||
*/
|
||||
public function parse($value);
|
||||
}
|
570
library/Zend/Markup/Parser/Textile.php
Normal file
570
library/Zend/Markup/Parser/Textile.php
Normal file
|
@ -0,0 +1,570 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Textile.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_TokenList
|
||||
*/
|
||||
require_once 'Zend/Markup/TokenList.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Parser_ParserInterface
|
||||
*/
|
||||
require_once 'Zend/Markup/Parser/ParserInterface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Parser_Textile implements Zend_Markup_Parser_ParserInterface
|
||||
{
|
||||
|
||||
const STATE_SCAN = 0;
|
||||
const STATE_NEW_PARAGRAPH = 1;
|
||||
const STATE_NEWLINE = 2;
|
||||
|
||||
const MATCH_ATTR_CLASSID = '\((?<attr_class>[a-zA-Z0-9_]+)?(?:\#(?<attr_id>[a-zA-Z0-9_]+))?\)';
|
||||
const MATCH_ATTR_STYLE = "\{(?<attr_style>[^\}\n]+)\}";
|
||||
const MATCH_ATTR_LANG = '\[(?<attr_lang>[a-zA-Z_]+)\]';
|
||||
const MATCH_ATTR_ALIGN = '(?<attr_align>\<\>?|\>|=)';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Token tree
|
||||
*
|
||||
* @var Zend_Markup_TokenList
|
||||
*/
|
||||
protected $_tree;
|
||||
|
||||
/**
|
||||
* Current token
|
||||
*
|
||||
* @var Zend_Markup_Token
|
||||
*/
|
||||
protected $_current;
|
||||
|
||||
/**
|
||||
* Source to tokenize
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_value = '';
|
||||
|
||||
/**
|
||||
* Length of the value
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_valueLen = 0;
|
||||
|
||||
/**
|
||||
* Current pointer
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_pointer = 0;
|
||||
|
||||
/**
|
||||
* The buffer
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_buffer = '';
|
||||
|
||||
/**
|
||||
* Simple tag translation
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_simpleTags = array(
|
||||
'*' => 'strong',
|
||||
'**' => 'bold',
|
||||
'_' => 'emphasized',
|
||||
'__' => 'italic',
|
||||
'??' => 'citation',
|
||||
'-' => 'deleted',
|
||||
'+' => 'insert',
|
||||
'^' => 'superscript',
|
||||
'~' => 'subscript',
|
||||
'%' => 'span',
|
||||
// these are a little more complicated
|
||||
'@' => 'code',
|
||||
'!' => 'img',
|
||||
);
|
||||
|
||||
/**
|
||||
* Token array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tokens = array();
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the parsing of a Textile string, the real parsing is done in {@link _parse()}
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parse($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
/**
|
||||
* @see Zend_Markup_Parser_Exception
|
||||
*/
|
||||
require_once 'Zend/Markup/Parser/Exception.php';
|
||||
throw new Zend_Markup_Parser_Exception('Value to parse should be a string.');
|
||||
}
|
||||
if (empty($value)) {
|
||||
/**
|
||||
* @see Zend_Markup_Parser_Exception
|
||||
*/
|
||||
require_once 'Zend/Markup/Parser/Exception.php';
|
||||
throw new Zend_Markup_Parser_Exception('Value to parse cannot be left empty.');
|
||||
}
|
||||
|
||||
// first make we only have LF newlines, also trim the value
|
||||
$this->_value = str_replace(array("\r\n", "\r"), "\n", $value);
|
||||
$this->_value = trim($this->_value);
|
||||
|
||||
// initialize variables and tokenize
|
||||
$this->_valueLen = iconv_strlen($this->_value, 'UTF-8');
|
||||
$this->_pointer = 0;
|
||||
$this->_buffer = '';
|
||||
$this->_temp = array();
|
||||
$this->_tokens = array();
|
||||
|
||||
$this->_tokenize();
|
||||
|
||||
// create the tree
|
||||
$this->_tree = new Zend_Markup_TokenList();
|
||||
|
||||
$this->_current = new Zend_Markup_Token('', Zend_Markup_Token::TYPE_NONE, 'Zend_Markup_Root');
|
||||
$this->_tree->addChild($this->_current);
|
||||
|
||||
$this->_createTree();
|
||||
|
||||
return $this->_tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tokenize a textile string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _tokenize()
|
||||
{
|
||||
$state = self::STATE_NEW_PARAGRAPH;
|
||||
|
||||
$attrsMatch = implode('|', array(
|
||||
self::MATCH_ATTR_CLASSID,
|
||||
self::MATCH_ATTR_STYLE,
|
||||
self::MATCH_ATTR_LANG,
|
||||
self::MATCH_ATTR_ALIGN
|
||||
));
|
||||
|
||||
$paragraph = '';
|
||||
|
||||
while ($this->_pointer < $this->_valueLen) {
|
||||
switch ($state) {
|
||||
case self::STATE_SCAN:
|
||||
$matches = array(); //[^\n*_?+~%@!-]
|
||||
$acronym = '(?<acronym>[A-Z]{2,})\((?<title>[^\)]+)\)';
|
||||
$regex = '#\G(?<text>.*?)(?:'
|
||||
. "(?:(?<nl_paragraph>\n{2,})|(?<nl_break>\n))|"
|
||||
. '(?<tag>'
|
||||
. "(?<name>\*{1,2}|_{1,2}|\?{2}|\-|\+|\~|\^|%|@|!|$|{$acronym}"
|
||||
. '|":(?<url>[^\s]+)|")'
|
||||
. "(?:{$attrsMatch})*)"
|
||||
. ')#si';
|
||||
preg_match($regex, $this->_value, $matches, null, $this->_pointer);
|
||||
|
||||
$this->_pointer += strlen($matches[0]);
|
||||
|
||||
if (!empty($matches['text'])) {
|
||||
$this->_buffer .= $matches['text'];
|
||||
}
|
||||
|
||||
// first add the buffer
|
||||
if (!empty($this->_buffer)) {
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $this->_buffer,
|
||||
'type' => Zend_Markup_Token::TYPE_NONE
|
||||
);
|
||||
$this->_buffer = '';
|
||||
}
|
||||
|
||||
if (!empty($matches['nl_paragraph'])) {
|
||||
$this->_temp = array(
|
||||
'tag' => $matches['nl_paragraph'],
|
||||
'name' => 'p',
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'attributes' => array()
|
||||
);
|
||||
|
||||
$state = self::STATE_NEW_PARAGRAPH;
|
||||
} elseif (!empty($matches['nl_break'])) {
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $matches['nl_break'],
|
||||
'name' => 'break',
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'attributes' => array()
|
||||
);
|
||||
|
||||
$state = self::STATE_NEWLINE;
|
||||
} elseif (!empty($matches['tag'])) {
|
||||
if (isset($this->_simpleTags[$matches['name']])) {
|
||||
// now add the new token
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $matches['tag'],
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'name' => $this->_simpleTags[$matches['name']],
|
||||
'attributes' => $this->_extractAttributes($matches)
|
||||
);
|
||||
} else {
|
||||
$attributes = $this->_extractAttributes($matches);
|
||||
if ($matches['tag'][0] == '"') {
|
||||
$name = 'url';
|
||||
if (isset($matches['url'])) {
|
||||
$attributes['url'] = $matches['url'];
|
||||
}
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $matches['tag'],
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'name' => $name,
|
||||
'attributes' => $attributes
|
||||
);
|
||||
} else {
|
||||
$name = 'acronym';
|
||||
$this->_tokens[] = array(
|
||||
'tag' => '',
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'name' => 'acronym',
|
||||
'attributes' => array(
|
||||
'title' => $matches['title']
|
||||
)
|
||||
);
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $matches['acronym'],
|
||||
'type' => Zend_Markup_Token::TYPE_NONE
|
||||
);
|
||||
$this->_tokens[] = array(
|
||||
'tag' => '(' . $matches['title'] . ')',
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'name' => 'acronym',
|
||||
'attributes' => array()
|
||||
);
|
||||
}
|
||||
}
|
||||
$state = self::STATE_SCAN;
|
||||
}
|
||||
|
||||
break;
|
||||
case self::STATE_NEW_PARAGRAPH:
|
||||
if (empty($this->_temp)) {
|
||||
$this->_temp = array(
|
||||
'tag' => '',
|
||||
'name' => 'p',
|
||||
'type' => Zend_Markup_token::TYPE_TAG,
|
||||
'attributes' => array()
|
||||
);
|
||||
} else {
|
||||
$this->_tokens[] = array(
|
||||
'tag' => "\n",
|
||||
'name' => 'p',
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'attributes' => array()
|
||||
);
|
||||
$this->_temp['tag'] = substr($this->_temp['tag'], 1);
|
||||
}
|
||||
|
||||
$matches = array(); //[^\n*_?+~%@!-] (\()? [^()]+ (?(1)\))
|
||||
$regex = "#\G(?<name>(h[1-6]|p)|(?:\#|\*))(?:{$attrsMatch})*(?(2)\.\s|\s)#i";
|
||||
if (!preg_match($regex, $this->_value, $matches, null, $this->_pointer)) {
|
||||
$this->_tokens[] = $this->_temp;
|
||||
$state = self::STATE_SCAN;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_pointer += strlen($matches[0]);
|
||||
|
||||
if ($matches['name'] == 'p') {
|
||||
$this->_temp['tag'] .= $matches[0];
|
||||
$this->_temp['attributes'] = $this->_extractAttributes($matches);
|
||||
|
||||
$this->_tokens[] = $this->_temp;
|
||||
$this->_temp = array();
|
||||
} else {
|
||||
$this->_tokens[] = $this->_temp;
|
||||
$this->_temp = array();
|
||||
|
||||
$name = $matches['name'];
|
||||
$attributes = $this->_extractAttributes($matches);
|
||||
|
||||
if ($name == '#') {
|
||||
$name = 'list';
|
||||
$attributes['list'] = 'decimal';
|
||||
} elseif ($name == '*') {
|
||||
$name = 'list';
|
||||
}
|
||||
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $matches[0],
|
||||
'name' => $name,
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'attributes' => $attributes
|
||||
);
|
||||
}
|
||||
|
||||
$state = self::STATE_SCAN;
|
||||
break;
|
||||
case self::STATE_NEWLINE:
|
||||
$matches = array(); //[^\n*_?+~%@!-]
|
||||
$regex = "#\G(?<name>(h[1-6])|(?:\#|\*))(?:{$attrsMatch})*(?(2)\.\s|\s)#si";
|
||||
if (!preg_match($regex, $this->_value, $matches, null, $this->_pointer)) {
|
||||
$state = self::STATE_SCAN;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_pointer += strlen($matches[0]);
|
||||
|
||||
$name = $matches['name'];
|
||||
$attributes = $this->_extractAttributes($matches);
|
||||
|
||||
if ($name == '#') {
|
||||
$name = 'list';
|
||||
$attributes['list'] = 'decimal';
|
||||
} elseif ($name == '*') {
|
||||
$name = 'list';
|
||||
}
|
||||
|
||||
$this->_tokens[] = array(
|
||||
'tag' => $matches[0],
|
||||
'name' => $name,
|
||||
'type' => Zend_Markup_Token::TYPE_TAG,
|
||||
'attributes' => $attributes
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tree from the tokenized text
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _createTree()
|
||||
{
|
||||
$inside = true;
|
||||
|
||||
foreach ($this->_tokens as $key => $token) {
|
||||
// first check if the token is a stopper
|
||||
if ($this->_isStopper($token, $this->_current)) {
|
||||
if ($this->_current->getName() == 'li') {
|
||||
// list items are handled differently
|
||||
if (isset($this->_tokens[$key + 1])
|
||||
&& ($this->_tokens[$key + 1]['type'] == Zend_Markup_Token::TYPE_TAG)
|
||||
&& ($this->_tokens[$key + 1]['name'] == 'list')
|
||||
) {
|
||||
// the next item is a correct tag
|
||||
$this->_current->setStopper($token['tag']);
|
||||
|
||||
$this->_current = $this->_current->getParent();
|
||||
} else {
|
||||
// close the list
|
||||
$this->_current->setStopper($token['tag']);
|
||||
|
||||
$this->_current = $this->_current->getParent()->getParent();
|
||||
|
||||
// go up in the tree until we found the end
|
||||
while ($this->_isStopper($token, $this->_current)) {
|
||||
$this->_current->setStopper($token['tag']);
|
||||
|
||||
$this->_current = $this->_current->getParent();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// go up in the tree until we found the end of stoppers
|
||||
while ($this->_isStopper($token, $this->_current)) {
|
||||
$this->_current->setStopper($token['tag']);
|
||||
|
||||
if (!empty($token['attributes'])) {
|
||||
foreach ($token['attributes'] as $name => $value) {
|
||||
$this->_current->addAttribute($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_current = $this->_current->getParent();
|
||||
}
|
||||
}
|
||||
$inside = true;
|
||||
} elseif (($token['type'] == Zend_Markup_Token::TYPE_TAG) && $inside) {
|
||||
if ($token['name'] == 'break') {
|
||||
// add the newline and continue parsing
|
||||
$this->_current->addChild(new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'',
|
||||
array(),
|
||||
$this->_current
|
||||
));
|
||||
} else {
|
||||
// handle a list item
|
||||
if ($token['name'] == 'list') {
|
||||
$attributes = array();
|
||||
if (isset($token['attributes']['list'])) {
|
||||
$attributes['list'] = $token['attributes']['list'];
|
||||
unset($token['attributes']['list']);
|
||||
}
|
||||
|
||||
if ($this->_current->getName() != 'list') {
|
||||
// the list isn't started yet, create it
|
||||
$child = new Zend_Markup_Token(
|
||||
'',
|
||||
Zend_Markup_Token::TYPE_TAG,
|
||||
'list',
|
||||
$attributes,
|
||||
$this->_current
|
||||
);
|
||||
|
||||
$this->_current->addChild($child);
|
||||
|
||||
$this->_current = $child;
|
||||
}
|
||||
$token['name'] = 'li';
|
||||
} elseif (($token['name'] == 'img') || ($token['name'] == 'url')) {
|
||||
$inside = false;
|
||||
}
|
||||
|
||||
// add the token
|
||||
$child = new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
Zend_Markup_Token::TYPE_TAG,
|
||||
$token['name'],
|
||||
$token['attributes'],
|
||||
$this->_current
|
||||
);
|
||||
|
||||
$this->_current->addChild($child);
|
||||
|
||||
$this->_current = $child;
|
||||
}
|
||||
} else {
|
||||
// simply add the token as text
|
||||
$this->_current->addChild(new Zend_Markup_Token(
|
||||
$token['tag'],
|
||||
Zend_Markup_Token::TYPE_NONE,
|
||||
'',
|
||||
array(),
|
||||
$this->_current
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a tag is a stopper
|
||||
*
|
||||
* @param array $token
|
||||
* @param Zend_Markup_Token $current
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isStopper(array $token, Zend_Markup_Token $current)
|
||||
{
|
||||
switch ($current->getName()) {
|
||||
case 'h1':
|
||||
case 'h2':
|
||||
case 'h3':
|
||||
case 'h4':
|
||||
case 'h5':
|
||||
case 'h6':
|
||||
case 'list':
|
||||
case 'li':
|
||||
if (($token['type'] == Zend_Markup_Token::TYPE_TAG)
|
||||
&& (($token['name'] == 'break') || ($token['name'] == 'p'))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 'break':
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
if (($token['type'] == Zend_Markup_Token::TYPE_TAG) && ($token['name'] == $current->getName())) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the attributes
|
||||
*
|
||||
* @param array $matches
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _extractAttributes(array $matches)
|
||||
{
|
||||
$attributes = array();
|
||||
|
||||
if (!empty($matches['attr_class'])) {
|
||||
$attributes['class'] = $matches['attr_class'];
|
||||
}
|
||||
if (!empty($matches['attr_id'])) {
|
||||
$attributes['id'] = $matches['attr_id'];
|
||||
}
|
||||
if (!empty($matches['attr_style'])) {
|
||||
$attributes['style'] = $matches['attr_style'];
|
||||
}
|
||||
if (!empty($matches['attr_lang'])) {
|
||||
$attributes['lang'] = $matches['attr_lang'];
|
||||
}
|
||||
if (!empty($matches['attr_align'])) {
|
||||
switch ($matches['attr_align']) {
|
||||
case '=':
|
||||
$attributes['align'] = 'center';
|
||||
break;
|
||||
case '>':
|
||||
$attributes['align'] = 'right';
|
||||
break;
|
||||
case '<>':
|
||||
$attributes['align'] = 'justify';
|
||||
break;
|
||||
default:
|
||||
case '<':
|
||||
$attributes['align'] = 'left';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
}
|
40
library/Zend/Markup/Renderer/Exception.php
Normal file
40
library/Zend/Markup/Renderer/Exception.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Exception
|
||||
*/
|
||||
require_once 'Zend/Markup/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Markup_Renderer
|
||||
*
|
||||
* @category Zend
|
||||
* @uses Zend_Markup_Exception
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Renderer_Exception extends Zend_Markup_Exception
|
||||
{
|
||||
}
|
521
library/Zend/Markup/Renderer/Html.php
Normal file
521
library/Zend/Markup/Renderer/Html.php
Normal file
|
@ -0,0 +1,521 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Html.php 21551 2010-03-18 17:19:11Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Filter_HtmlEntities
|
||||
*/
|
||||
require_once 'Zend/Filter/HtmlEntities.php';
|
||||
/**
|
||||
* @see Zend_Filter_PregReplace
|
||||
*/
|
||||
require_once 'Zend/Filter/PregReplace.php';
|
||||
/**
|
||||
* @see Zend_Filter_Callback
|
||||
*/
|
||||
require_once 'Zend/Filter/Callback.php';
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_RendererAbstract
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/RendererAbstract.php';
|
||||
|
||||
/**
|
||||
* HTML renderer
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Renderer_Html extends Zend_Markup_Renderer_RendererAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Element groups
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_groups = array(
|
||||
'block' => array('block', 'inline', 'block-empty', 'inline-empty', 'list'),
|
||||
'inline' => array('inline', 'inline-empty'),
|
||||
'list' => array('list-item'),
|
||||
'list-item' => array('inline', 'inline-empty', 'list'),
|
||||
'block-empty' => array(),
|
||||
'inline-empty' => array(),
|
||||
);
|
||||
|
||||
/**
|
||||
* The current group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_group = 'block';
|
||||
|
||||
/**
|
||||
* Default attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_defaultAttributes = array(
|
||||
'id' => '',
|
||||
'class' => '',
|
||||
'style' => '',
|
||||
'lang' => '',
|
||||
'title' => ''
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
$this->_pluginLoader = new Zend_Loader_PluginLoader(array(
|
||||
'Zend_Markup_Renderer_Html' => 'Zend/Markup/Renderer/Html/'
|
||||
));
|
||||
|
||||
$this->_defineDefaultMarkups();
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the default markups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _defineDefaultMarkups()
|
||||
{
|
||||
$this->_markups = array(
|
||||
'b' => array(
|
||||
'type' => 10, // self::TYPE_REPLACE | self::TAG_NORMAL
|
||||
'tag' => 'strong',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'u' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'span',
|
||||
'attributes' => array(
|
||||
'style' => 'text-decoration: underline;',
|
||||
),
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'i' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'em',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'cite' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'cite',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'del' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'del',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'ins' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'ins',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'sub' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'sub',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'sup' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'sup',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'span' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'span',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'acronym' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'acronym',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
// headings
|
||||
'h1' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'h1',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'h2' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'h2',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'h3' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'h3',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'h4' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'h4',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'h5' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'h5',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'h6' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'h6',
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
// callback tags
|
||||
'url' => array(
|
||||
'type' => 6, // self::TYPE_CALLBACK | self::TAG_NORMAL
|
||||
'callback' => null,
|
||||
'group' => 'inline',
|
||||
'filter' => true,
|
||||
),
|
||||
'img' => array(
|
||||
'type' => 6,
|
||||
'callback' => null,
|
||||
'group' => 'inline-empty',
|
||||
'filter' => true,
|
||||
),
|
||||
'code' => array(
|
||||
'type' => 6,
|
||||
'callback' => null,
|
||||
'group' => 'block-empty',
|
||||
'filter' => false,
|
||||
),
|
||||
'p' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'p',
|
||||
'group' => 'block',
|
||||
'filter' => true,
|
||||
),
|
||||
'ignore' => array(
|
||||
'type' => 10,
|
||||
'start' => '',
|
||||
'end' => '',
|
||||
'group' => 'block-empty',
|
||||
'filter' => true,
|
||||
),
|
||||
'quote' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'blockquote',
|
||||
'group' => 'block',
|
||||
'filter' => true,
|
||||
),
|
||||
'list' => array(
|
||||
'type' => 6,
|
||||
'callback' => null,
|
||||
'group' => 'list',
|
||||
'filter' => new Zend_Filter_PregReplace('/.*/is', ''),
|
||||
),
|
||||
'*' => array(
|
||||
'type' => 10,
|
||||
'tag' => 'li',
|
||||
'group' => 'list-item',
|
||||
'filter' => true,
|
||||
),
|
||||
'hr' => array(
|
||||
'type' => 9, // self::TYPE_REPLACE | self::TAG_SINGLE
|
||||
'tag' => 'hr',
|
||||
'group' => 'block',
|
||||
'empty' => true,
|
||||
),
|
||||
// aliases
|
||||
'bold' => array(
|
||||
'type' => 16,
|
||||
'name' => 'b',
|
||||
),
|
||||
'strong' => array(
|
||||
'type' => 16,
|
||||
'name' => 'b',
|
||||
),
|
||||
'italic' => array(
|
||||
'type' => 16,
|
||||
'name' => 'i',
|
||||
),
|
||||
'em' => array(
|
||||
'type' => 16,
|
||||
'name' => 'i',
|
||||
),
|
||||
'emphasized' => array(
|
||||
'type' => 16,
|
||||
'name' => 'i',
|
||||
),
|
||||
'underline' => array(
|
||||
'type' => 16,
|
||||
'name' => 'u',
|
||||
),
|
||||
'citation' => array(
|
||||
'type' => 16,
|
||||
'name' => 'cite',
|
||||
),
|
||||
'deleted' => array(
|
||||
'type' => 16,
|
||||
'name' => 'del',
|
||||
),
|
||||
'insert' => array(
|
||||
'type' => 16,
|
||||
'name' => 'ins',
|
||||
),
|
||||
'strike' => array(
|
||||
'type' => 16,
|
||||
'name' => 's',
|
||||
),
|
||||
's' => array(
|
||||
'type' => 16,
|
||||
'name' => 'del',
|
||||
),
|
||||
'subscript' => array(
|
||||
'type' => 16,
|
||||
'name' => 'sub',
|
||||
),
|
||||
'superscript' => array(
|
||||
'type' => 16,
|
||||
'name' => 'sup',
|
||||
),
|
||||
'a' => array(
|
||||
'type' => 16,
|
||||
'name' => 'url',
|
||||
),
|
||||
'image' => array(
|
||||
'type' => 16,
|
||||
'name' => 'img',
|
||||
),
|
||||
'li' => array(
|
||||
'type' => 16,
|
||||
'name' => '*',
|
||||
),
|
||||
'color' => array(
|
||||
'type' => 16,
|
||||
'name' => 'span',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the default filters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDefaultFilters()
|
||||
{
|
||||
$this->_defaultFilter = new Zend_Filter();
|
||||
|
||||
$this->_defaultFilter->addFilter(new Zend_Filter_HtmlEntities(array('encoding' => self::getEncoding())));
|
||||
$this->_defaultFilter->addFilter(new Zend_Filter_Callback('nl2br'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a replace token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param array $markup
|
||||
* @return string
|
||||
*/
|
||||
protected function _executeReplace(Zend_Markup_Token $token, $markup)
|
||||
{
|
||||
if (isset($markup['tag'])) {
|
||||
if (!isset($markup['attributes'])) {
|
||||
$markup['attributes'] = array();
|
||||
}
|
||||
$attrs = self::renderAttributes($token, $markup['attributes']);
|
||||
return "<{$markup['tag']}{$attrs}>{$this->_render($token)}</{$markup['tag']}>";
|
||||
}
|
||||
|
||||
return parent::_executeReplace($token, $markup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a single replace token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param array $markup
|
||||
* @return string
|
||||
*/
|
||||
protected function _executeSingleReplace(Zend_Markup_Token $token, $markup)
|
||||
{
|
||||
if (isset($markup['tag'])) {
|
||||
if (!isset($markup['attributes'])) {
|
||||
$markup['attributes'] = array();
|
||||
}
|
||||
$attrs = self::renderAttributes($token, $markup['attributes']);
|
||||
return "<{$markup['tag']}{$attrs} />";
|
||||
}
|
||||
return parent::_executeSingleReplace($token, $markup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render some attributes
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
public static function renderAttributes(Zend_Markup_Token $token, array $attributes = array())
|
||||
{
|
||||
$attributes = array_merge(self::$_defaultAttributes, $attributes);
|
||||
|
||||
$return = '';
|
||||
|
||||
$tokenAttributes = $token->getAttributes();
|
||||
|
||||
// correct style attribute
|
||||
if (isset($tokenAttributes['style'])) {
|
||||
$tokenAttributes['style'] = trim($tokenAttributes['style']);
|
||||
|
||||
if ($tokenAttributes['style'][strlen($tokenAttributes['style']) - 1] != ';') {
|
||||
$tokenAttributes['style'] .= ';';
|
||||
}
|
||||
} else {
|
||||
$tokenAttributes['style'] = '';
|
||||
}
|
||||
|
||||
// special treathment for 'align' and 'color' attribute
|
||||
if (isset($tokenAttributes['align'])) {
|
||||
$tokenAttributes['style'] .= 'text-align: ' . $tokenAttributes['align'] . ';';
|
||||
unset($tokenAttributes['align']);
|
||||
}
|
||||
if (isset($tokenAttributes['color']) && self::checkColor($tokenAttributes['color'])) {
|
||||
$tokenAttributes['style'] .= 'color: ' . $tokenAttributes['color'] . ';';
|
||||
unset($tokenAttributes['color']);
|
||||
}
|
||||
|
||||
/*
|
||||
* loop through all the available attributes, and check if there is
|
||||
* a value defined by the token
|
||||
* if there is no value defined by the token, use the default value or
|
||||
* don't set the attribute
|
||||
*/
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
if (isset($tokenAttributes[$attribute]) && !empty($tokenAttributes[$attribute])) {
|
||||
$return .= ' ' . $attribute . '="' . htmlentities($tokenAttributes[$attribute],
|
||||
ENT_QUOTES,
|
||||
self::getEncoding()) . '"';
|
||||
} elseif (!empty($value)) {
|
||||
$return .= ' ' . $attribute . '="' . htmlentities($value, ENT_QUOTES, self::getEncoding()) . '"';
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a color is a valid HTML color
|
||||
*
|
||||
* @param string $color
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkColor($color)
|
||||
{
|
||||
/*
|
||||
* aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive,
|
||||
* purple, red, silver, teal, white, and yellow.
|
||||
*/
|
||||
$colors = array(
|
||||
'aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime',
|
||||
'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal',
|
||||
'white', 'yellow'
|
||||
);
|
||||
|
||||
if (in_array($color, $colors)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (preg_match('/\#[0-9a-f]{6}/i', $color)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the URI is valid
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isValidUri($uri)
|
||||
{
|
||||
if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri, $matches)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$scheme = strtolower($matches[1]);
|
||||
|
||||
switch ($scheme) {
|
||||
case 'javascript':
|
||||
// JavaScript scheme is not allowed for security reason
|
||||
return false;
|
||||
|
||||
case 'http':
|
||||
case 'https':
|
||||
case 'ftp':
|
||||
$components = @parse_url($uri);
|
||||
|
||||
if ($components === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($components['host'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
53
library/Zend/Markup/Renderer/Html/Code.php
Normal file
53
library/Zend/Markup/Renderer/Html/Code.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Code.php 20270 2010-01-13 22:37:41Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php';
|
||||
|
||||
/**
|
||||
* Tag interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Renderer_Html_Code extends Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert the token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(Zend_Markup_Token $token, $text)
|
||||
{
|
||||
return highlight_string($text, true);
|
||||
}
|
||||
|
||||
}
|
69
library/Zend/Markup/Renderer/Html/HtmlAbstract.php
Normal file
69
library/Zend/Markup/Renderer/Html/HtmlAbstract.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlAbstract.php 20271 2010-01-13 23:27:34Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_TokenConverterInterface
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/TokenConverterInterface.php';
|
||||
|
||||
/**
|
||||
* Tag interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Markup_Renderer_Html_HtmlAbstract implements Zend_Markup_Renderer_TokenConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* The HTML renderer
|
||||
*
|
||||
* @var Zend_Markup_Renderer_Html
|
||||
*/
|
||||
protected $_renderer;
|
||||
|
||||
|
||||
/**
|
||||
* Set the HTML renderer instance
|
||||
*
|
||||
* @param Zend_Markup_Renderer_Html $renderer
|
||||
*
|
||||
* @return Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
*/
|
||||
public function setRenderer(Zend_Markup_Renderer_Html $renderer)
|
||||
{
|
||||
$this->_renderer = $renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML renderer instance
|
||||
*
|
||||
* @return Zend_Markup_Renderer_Html
|
||||
*/
|
||||
public function getRenderer()
|
||||
{
|
||||
return $this->_renderer;
|
||||
}
|
||||
}
|
84
library/Zend/Markup/Renderer/Html/Img.php
Normal file
84
library/Zend/Markup/Renderer/Html/Img.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Img.php 20664 2010-01-26 18:46:20Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_Html
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/Html.php';
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php';
|
||||
|
||||
/**
|
||||
* Tag interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Renderer_Html_Img extends Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert the token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(Zend_Markup_Token $token, $text)
|
||||
{
|
||||
$uri = $text;
|
||||
|
||||
if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) {
|
||||
$uri = 'http://' . $uri;
|
||||
}
|
||||
|
||||
// check if the URL is valid
|
||||
if (!Zend_Markup_Renderer_Html::isValidUri($uri)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
if ($token->hasAttribute('alt')) {
|
||||
$alt = $token->getAttribute('alt');
|
||||
} else {
|
||||
// try to get the alternative from the URL
|
||||
$alt = rtrim($text, '/');
|
||||
$alt = strrchr($alt, '/');
|
||||
if (false !== strpos($alt, '.')) {
|
||||
$alt = substr($alt, 1, strpos($alt, '.') - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// run the URI and alt through htmlentities
|
||||
$uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
|
||||
$alt = htmlentities($alt, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
|
||||
|
||||
|
||||
return "<img src=\"{$uri}\" alt=\"{$alt}\"" . Zend_Markup_Renderer_Html::renderAttributes($token) . " />";
|
||||
}
|
||||
|
||||
}
|
103
library/Zend/Markup/Renderer/Html/List.php
Normal file
103
library/Zend/Markup/Renderer/Html/List.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: List.php 20270 2010-01-13 22:37:41Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php';
|
||||
|
||||
/**
|
||||
* Tag interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Renderer_Html_List extends Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert the token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(Zend_Markup_Token $token, $text)
|
||||
{
|
||||
$type = null;
|
||||
if ($token->hasAttribute('list')) {
|
||||
// because '01' == '1'
|
||||
if ($token->getAttribute('list') === '01') {
|
||||
$type = 'decimal-leading-zero';
|
||||
} else {
|
||||
switch ($token->getAttribute('list')) {
|
||||
case '1':
|
||||
$type = 'decimal';
|
||||
break;
|
||||
case 'i':
|
||||
$type = 'lower-roman';
|
||||
break;
|
||||
case 'I':
|
||||
$type = 'upper-roman';
|
||||
break;
|
||||
case 'a':
|
||||
$type = 'lower-alpha';
|
||||
break;
|
||||
case 'A':
|
||||
$type = 'upper-alpha';
|
||||
break;
|
||||
|
||||
// the following type is unsupported by IE (including IE8)
|
||||
case 'alpha':
|
||||
$type = 'lower-greek';
|
||||
break;
|
||||
|
||||
// the CSS names itself
|
||||
case 'armenian': // unsupported by IE (including IE8)
|
||||
case 'decimal':
|
||||
case 'decimal-leading-zero': // unsupported by IE (including IE8)
|
||||
case 'georgian': // unsupported by IE (including IE8)
|
||||
case 'lower-alpha':
|
||||
case 'lower-greek': // unsupported by IE (including IE8)
|
||||
case 'lower-latin': // unsupported by IE (including IE8)
|
||||
case 'lower-roman':
|
||||
case 'upper-alpha':
|
||||
case 'upper-latin': // unsupported by IE (including IE8)
|
||||
case 'upper-roman':
|
||||
$type = $token->getAttribute('list');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $type) {
|
||||
return "<ol style=\"list-style-type: {$type}\">{$text}</ol>";
|
||||
} else {
|
||||
return "<ul>{$text}</ul>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
77
library/Zend/Markup/Renderer/Html/Url.php
Normal file
77
library/Zend/Markup/Renderer/Html/Url.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Url.php 20664 2010-01-26 18:46:20Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_Html
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/Html.php';
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php';
|
||||
|
||||
/**
|
||||
* Tag interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer_Html
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Renderer_Html_Url extends Zend_Markup_Renderer_Html_HtmlAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert the token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(Zend_Markup_Token $token, $text)
|
||||
{
|
||||
if ($token->hasAttribute('url')) {
|
||||
$uri = $token->getAttribute('url');
|
||||
} else {
|
||||
$uri = $text;
|
||||
}
|
||||
|
||||
if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) {
|
||||
$uri = 'http://' . $uri;
|
||||
}
|
||||
|
||||
// check if the URL is valid
|
||||
if (!Zend_Markup_Renderer_Html::isValidUri($uri)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$attributes = Zend_Markup_Renderer_Html::renderAttributes($token);
|
||||
|
||||
// run the URI through htmlentities
|
||||
$uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
|
||||
|
||||
return "<a href=\"{$uri}\"{$attributes}>{$text}</a>";
|
||||
}
|
||||
|
||||
}
|
707
library/Zend/Markup/Renderer/RendererAbstract.php
Normal file
707
library/Zend/Markup/Renderer/RendererAbstract.php
Normal file
|
@ -0,0 +1,707 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: RendererAbstract.php 20956 2010-02-06 17:58:58Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_config
|
||||
*/
|
||||
require_once 'Zend/Config.php';
|
||||
/**
|
||||
* @see Zend_Filter
|
||||
*/
|
||||
require_once 'Zend/Filter.php';
|
||||
/**
|
||||
* @see Zend_Markup_Renderer_TokenConverterInterface
|
||||
*/
|
||||
require_once 'Zend/Markup/Renderer/TokenConverterInterface.php';
|
||||
|
||||
/**
|
||||
* Defines the basic rendering functionality
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Markup_Renderer_RendererAbstract
|
||||
{
|
||||
const TYPE_CALLBACK = 4;
|
||||
const TYPE_REPLACE = 8;
|
||||
const TYPE_ALIAS = 16;
|
||||
|
||||
/**
|
||||
* Tag info
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_markups = array();
|
||||
|
||||
/**
|
||||
* Parser
|
||||
*
|
||||
* @var Zend_Markup_Parser_ParserInterface
|
||||
*/
|
||||
protected $_parser;
|
||||
|
||||
/**
|
||||
* What filter to use
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_filter;
|
||||
|
||||
/**
|
||||
* Filter chain
|
||||
*
|
||||
* @var Zend_Filter
|
||||
*/
|
||||
protected $_defaultFilter;
|
||||
|
||||
/**
|
||||
* The current group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_group;
|
||||
|
||||
/**
|
||||
* Groups definition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_groups = array();
|
||||
|
||||
/**
|
||||
* Plugin loader for tags
|
||||
*
|
||||
* @var Zend_Loader_PluginLoader
|
||||
*/
|
||||
protected $_pluginLoader;
|
||||
|
||||
/**
|
||||
* The current token
|
||||
*
|
||||
* @var Zend_Markup_Token
|
||||
*/
|
||||
protected $_token;
|
||||
|
||||
/**
|
||||
* Encoding
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $_encoding = 'UTF-8';
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
if (isset($options['encoding'])) {
|
||||
$this->setEncoding($options['encoding']);
|
||||
}
|
||||
if (isset($options['parser'])) {
|
||||
$this->setParser($options['parser']);
|
||||
}
|
||||
if (isset($options['useDefaultTags']) && ($options['useDefaultTags'] === false)) {
|
||||
$this->removeDefaultTags();
|
||||
}
|
||||
if (!isset($options['useDefaultFilters']) || ($options['useDefaultFilters'] === true)) {
|
||||
$this->addDefaultFilters();
|
||||
}
|
||||
if (isset($options['defaultFilter'])) {
|
||||
$this->addDefaultFilter($options['defaultFilter']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parser
|
||||
*
|
||||
* @param Zend_Markup_Parser_ParserInterface $parser
|
||||
* @return Zend_Markup_Renderer_RendererAbstract
|
||||
*/
|
||||
public function setParser(Zend_Markup_Parser_ParserInterface $parser)
|
||||
{
|
||||
$this->_parser = $parser;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parser
|
||||
*
|
||||
* @return Zend_Markup_Parser_ParserInterface
|
||||
*/
|
||||
public function getParser()
|
||||
{
|
||||
return $this->_parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin loader
|
||||
*
|
||||
* @return Zend_Loader_PluginLoader
|
||||
*/
|
||||
public function getPluginLoader()
|
||||
{
|
||||
return $this->_pluginLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the renderer's encoding
|
||||
*
|
||||
* @param string $encoding
|
||||
*
|
||||
* @return Zend_Markup_Renderer_RendererAbstract
|
||||
*/
|
||||
public static function setEncoding($encoding)
|
||||
{
|
||||
self::$_encoding = $encoding;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the renderer's encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getEncoding()
|
||||
{
|
||||
return self::$_encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new markup
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param array $options
|
||||
*
|
||||
* @return Zend_Markup_Renderer_RendererAbstract
|
||||
*/
|
||||
public function addMarkup($name, $type, array $options)
|
||||
{
|
||||
if (!isset($options['group']) && ($type ^ self::TYPE_ALIAS)) {
|
||||
require_once 'Zend/Markup/Renderer/Exception.php';
|
||||
throw new Zend_Markup_Renderer_Exception("There is no render group defined.");
|
||||
}
|
||||
|
||||
// add the filter
|
||||
if (isset($options['filter'])) {
|
||||
if ($options['filter'] instanceof Zend_Filter_Interface) {
|
||||
$filter = $options['filter'];
|
||||
} elseif ($options['filter'] === true) {
|
||||
$filter = $this->getDefaultFilter();
|
||||
} else {
|
||||
$filter = false;
|
||||
}
|
||||
} else {
|
||||
$filter = $this->getDefaultFilter();
|
||||
}
|
||||
|
||||
// check the type
|
||||
if ($type & self::TYPE_CALLBACK) {
|
||||
// add a callback tag
|
||||
if (isset($options['callback'])) {
|
||||
if (!($options['callback'] instanceof Zend_Markup_Renderer_TokenConverterInterface)) {
|
||||
require_once 'Zend/Markup/Renderer/Exception.php';
|
||||
throw new Zend_Markup_Renderer_Exception("Not a valid tag callback.");
|
||||
}
|
||||
if (method_exists($options['callback'], 'setRenderer')) {
|
||||
$options['callback']->setRenderer($this);
|
||||
}
|
||||
} else {
|
||||
$options['callback'] = null;
|
||||
}
|
||||
|
||||
$options['type'] = $type;
|
||||
$options['filter'] = $filter;
|
||||
|
||||
$this->_markups[$name] = $options;
|
||||
} elseif ($type & self::TYPE_ALIAS) {
|
||||
// add an alias
|
||||
if (empty($options['name'])) {
|
||||
require_once 'Zend/Markup/Renderer/Exception.php';
|
||||
throw new Zend_Markup_Renderer_Exception(
|
||||
'No alias was provided but tag was defined as such');
|
||||
}
|
||||
|
||||
$this->_markups[$name] = array(
|
||||
'type' => self::TYPE_ALIAS,
|
||||
'name' => $options['name']
|
||||
);
|
||||
} else {
|
||||
if ($type && array_key_exists('empty', $options) && $options['empty']) {
|
||||
// add a single replace markup
|
||||
$options['type'] = $type;
|
||||
$options['filter'] = $filter;
|
||||
|
||||
$this->_markups[$name] = $options;
|
||||
} else {
|
||||
// add a replace markup
|
||||
$options['type'] = $type;
|
||||
$options['filter'] = $filter;
|
||||
|
||||
$this->_markups[$name] = $options;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a markup
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeMarkup($name)
|
||||
{
|
||||
unset($this->_markups[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the default tags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearMarkups()
|
||||
{
|
||||
$this->_markups = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render function
|
||||
*
|
||||
* @param Zend_Markup_TokenList|string $tokenList
|
||||
* @return string
|
||||
*/
|
||||
public function render($value)
|
||||
{
|
||||
if ($value instanceof Zend_Markup_TokenList) {
|
||||
$tokenList = $value;
|
||||
} else {
|
||||
$tokenList = $this->getParser()->parse($value);
|
||||
}
|
||||
|
||||
$root = $tokenList->current();
|
||||
|
||||
$this->_filter = $this->getDefaultFilter();
|
||||
|
||||
return $this->_render($root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a single token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @return string
|
||||
*/
|
||||
protected function _render(Zend_Markup_Token $token)
|
||||
{
|
||||
$return = '';
|
||||
|
||||
$this->_token = $token;
|
||||
|
||||
// if this tag has children, execute them
|
||||
if ($token->hasChildren()) {
|
||||
foreach ($token->getChildren() as $child) {
|
||||
$return .= $this->_execute($child);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group of a token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _getGroup(Zend_Markup_Token $token)
|
||||
{
|
||||
if (!isset($this->_markups[$token->getName()])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tag = $this->_markups[$token->getName()];
|
||||
|
||||
// alias processing
|
||||
while ($tag['type'] & self::TYPE_ALIAS) {
|
||||
$tag = $this->_markups[$tag['name']];
|
||||
}
|
||||
|
||||
return isset($tag['group']) ? $tag['group'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @return string
|
||||
*/
|
||||
protected function _execute(Zend_Markup_Token $token)
|
||||
{
|
||||
// first return the normal text tags
|
||||
if ($token->getType() == Zend_Markup_Token::TYPE_NONE) {
|
||||
return $this->_filter($token->getTag());
|
||||
}
|
||||
|
||||
// if the token doesn't have a notation, return the plain text
|
||||
if (!isset($this->_markups[$token->getName()])) {
|
||||
$oldToken = $this->_token;
|
||||
$return = $this->_filter($token->getTag()) . $this->_render($token) . $token->getStopper();
|
||||
$this->_token = $oldToken;
|
||||
return $return;
|
||||
}
|
||||
|
||||
$name = $this->_getMarkupName($token);
|
||||
$markup = (!$name) ? false : $this->_markups[$name];
|
||||
$empty = (is_array($markup) && array_key_exists('empty', $markup) && $markup['empty']);
|
||||
|
||||
// check if the tag has content
|
||||
if (!$empty && !$token->hasChildren()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// check for the context
|
||||
if (is_array($markup) && !in_array($markup['group'], $this->_groups[$this->_group])) {
|
||||
$oldToken = $this->_token;
|
||||
$return = $this->_filter($token->getTag()) . $this->_render($token) . $token->getStopper();
|
||||
$this->_token = $oldToken;
|
||||
return $return;
|
||||
}
|
||||
|
||||
// check for the filter
|
||||
if (!isset($markup['filter'])
|
||||
|| (!($markup['filter'] instanceof Zend_Filter_Interface) && ($markup['filter'] !== false))) {
|
||||
$this->_markups[$name]['filter'] = $this->getDefaultFilter();
|
||||
}
|
||||
|
||||
// save old values to reset them after the work is done
|
||||
$oldFilter = $this->_filter;
|
||||
$oldGroup = $this->_group;
|
||||
|
||||
$return = '';
|
||||
|
||||
// set the filter and the group
|
||||
$this->_filter = $this->getFilter($name);
|
||||
|
||||
if ($group = $this->_getGroup($token)) {
|
||||
$this->_group = $group;
|
||||
}
|
||||
|
||||
// callback
|
||||
if (is_array($markup) && ($markup['type'] & self::TYPE_CALLBACK)) {
|
||||
// load the callback if the tag doesn't exist
|
||||
if (!($markup['callback'] instanceof Zend_Markup_Renderer_TokenConverterInterface)) {
|
||||
$class = $this->getPluginLoader()->load($name);
|
||||
|
||||
$markup['callback'] = new $class;
|
||||
|
||||
if (!($markup['callback'] instanceof Zend_Markup_Renderer_TokenConverterInterface)) {
|
||||
require_once 'Zend/Markup/Renderer/Exception.php';
|
||||
throw new Zend_Markup_Renderer_Exception("Callback for tag '$name' found, but it isn't valid.");
|
||||
}
|
||||
|
||||
if (method_exists($markup['callback'], 'setRenderer')) {
|
||||
$markup['callback']->setRenderer($this);
|
||||
}
|
||||
}
|
||||
if ($markup['type'] && !$empty) {
|
||||
$return = $markup['callback']->convert($token, $this->_render($token));
|
||||
} else {
|
||||
$return = $markup['callback']->convert($token, null);
|
||||
}
|
||||
} else {
|
||||
// replace
|
||||
if ($markup['type'] && !$empty) {
|
||||
$return = $this->_executeReplace($token, $markup);
|
||||
} else {
|
||||
$return = $this->_executeSingleReplace($token, $markup);
|
||||
}
|
||||
}
|
||||
|
||||
// reset to the old values
|
||||
$this->_filter = $oldFilter;
|
||||
$this->_group = $oldGroup;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter method
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _filter($value)
|
||||
{
|
||||
if ($this->_filter instanceof Zend_Filter_Interface) {
|
||||
return $this->_filter->filter($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the markup name
|
||||
*
|
||||
* @param Zend_Markup_Token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getMarkupName(Zend_Markup_Token $token)
|
||||
{
|
||||
$name = $token->getName();
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_resolveMarkupName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve aliases for a markup name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _resolveMarkupName($name)
|
||||
{
|
||||
while (($type = $this->_getMarkupType($name))
|
||||
&& ($type & self::TYPE_ALIAS)
|
||||
) {
|
||||
$name = $this->_markups[$name]['name'];
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve markup type
|
||||
*
|
||||
* @param string $name
|
||||
* @return false|int
|
||||
*/
|
||||
protected function _getMarkupType($name)
|
||||
{
|
||||
if (!isset($this->_markups[$name])) {
|
||||
return false;
|
||||
}
|
||||
if (!isset($this->_markups[$name]['type'])) {
|
||||
return false;
|
||||
}
|
||||
return $this->_markups[$name]['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a replace token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param array $tag
|
||||
* @return string
|
||||
*/
|
||||
protected function _executeReplace(Zend_Markup_Token $token, $tag)
|
||||
{
|
||||
return $tag['start'] . $this->_render($token) . $tag['end'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a single replace token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param array $tag
|
||||
* @return string
|
||||
*/
|
||||
protected function _executeSingleReplace(Zend_Markup_Token $token, $tag)
|
||||
{
|
||||
return $tag['replace'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default filter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getDefaultFilter()
|
||||
{
|
||||
if (null === $this->_defaultFilter) {
|
||||
$this->setDefaultFilter();
|
||||
}
|
||||
|
||||
return $this->_defaultFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a default filter
|
||||
*
|
||||
* @param string $filter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDefaultFilter(Zend_Filter_Interface $filter, $placement = Zend_Filter::CHAIN_APPEND)
|
||||
{
|
||||
if (!($this->_defaultFilter instanceof Zend_Filter)) {
|
||||
$defaultFilter = new Zend_Filter();
|
||||
$defaultFilter->addFilter($filter);
|
||||
$this->_defaultFilter = $defaultFilter;
|
||||
}
|
||||
|
||||
$this->_defaultFilter->addFilter($filter, $placement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default filter
|
||||
*
|
||||
* @param Zend_Filter_Interface $filter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultFilter(Zend_Filter_Interface $filter)
|
||||
{
|
||||
$this->_defaultFilter = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter for an existing markup
|
||||
*
|
||||
* @param string $markup
|
||||
*
|
||||
* @return Zend_Filter_Interface
|
||||
*/
|
||||
public function getFilter($markup)
|
||||
{
|
||||
$markup = $this->_resolveMarkupName($markup);
|
||||
|
||||
if (!isset($this->_markups[$markup]['filter'])
|
||||
|| !($this->_markups[$markup]['filter'] instanceof Zend_Filter_Interface)
|
||||
) {
|
||||
if (isset($this->_markups[$markup]['filter']) && $this->_markups[$markup]['filter']) {
|
||||
$this->_markups[$markup]['filter'] = $this->getDefaultFilter();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_markups[$markup]['filter'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filter for an existing markup
|
||||
*
|
||||
* @param Zend_Filter_Interface $filter
|
||||
* @param string $markup
|
||||
* @param string $placement
|
||||
*
|
||||
* @return Zend_Markup_Renderer_RendererAbstract
|
||||
*/
|
||||
public function addFilter(Zend_Filter_Interface $filter, $markup, $placement = Zend_Filter::CHAIN_APPEND)
|
||||
{
|
||||
$markup = $this->_resolveMarkupName($markup);
|
||||
|
||||
$oldFilter = $this->getFilter($markup);
|
||||
|
||||
// if this filter is the default filter, clone it first
|
||||
if ($oldFilter === $this->getDefaultFilter()) {
|
||||
$oldFilter = clone $oldFilter;
|
||||
}
|
||||
|
||||
if (!($oldFilter instanceof Zend_Filter)) {
|
||||
$this->_markups[$markup]['filter'] = new Zend_Filter();
|
||||
|
||||
if ($oldFilter instanceof Zend_Filter_Interface) {
|
||||
$this->_markups[$markup]['filter']->addFilter($oldFilter);
|
||||
}
|
||||
} else {
|
||||
$this->_markups[$markup]['filter'] = $oldFilter;
|
||||
}
|
||||
|
||||
$this->_markups[$markup]['filter']->addFilter($filter, $placement);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filter for an existing
|
||||
*
|
||||
* @param Zend_Filter_Interface $filter
|
||||
* @param string $markup
|
||||
*
|
||||
* @return Zend_Markup_Renderer_RendererAbstract
|
||||
*/
|
||||
public function setFilter(Zend_Filter_Interface $filter, $markup)
|
||||
{
|
||||
$markup = $this->_resolveMarkupName($markup);
|
||||
|
||||
$this->_markups[$markup]['filter'] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a render group
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $allowedInside
|
||||
* @param array $allowsInside
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addGroup($name, array $allowedInside = array(), array $allowsInside = array())
|
||||
{
|
||||
$this->_groups[$name] = $allowsInside;
|
||||
|
||||
foreach ($allowedInside as $group) {
|
||||
$this->_groups[$group][] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group definitions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
return $this->_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default filters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function addDefaultFilters();
|
||||
|
||||
}
|
44
library/Zend/Markup/Renderer/TokenConverterInterface.php
Normal file
44
library/Zend/Markup/Renderer/TokenConverterInterface.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: TokenConverterInterface.php 20271 2010-01-13 23:27:34Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tag interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Renderer
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Markup_Renderer_TokenConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert the token
|
||||
*
|
||||
* @param Zend_Markup_Token $token
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(Zend_Markup_Token $token, $text);
|
||||
}
|
306
library/Zend/Markup/Token.php
Normal file
306
library/Zend/Markup/Token.php
Normal file
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @subpackage Parser
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Token.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_TokenList
|
||||
*/
|
||||
require_once 'Zend/Markup/TokenList.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_Token
|
||||
{
|
||||
const TYPE_NONE = 'none';
|
||||
const TYPE_TAG = 'tag';
|
||||
|
||||
/**
|
||||
* Children of this token
|
||||
*
|
||||
* @var Zend_Markup_TokenList
|
||||
*/
|
||||
protected $_children;
|
||||
|
||||
/**
|
||||
* The complete tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_tag;
|
||||
|
||||
/**
|
||||
* The tag's type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_type;
|
||||
|
||||
/**
|
||||
* Tag name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = '';
|
||||
|
||||
/**
|
||||
* Tag attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_attributes = array();
|
||||
|
||||
/**
|
||||
* The used tag stopper (empty when none is found)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_stopper = '';
|
||||
|
||||
/**
|
||||
* The parent token
|
||||
*
|
||||
* @var Zend_Markup_Token
|
||||
*/
|
||||
protected $_parent;
|
||||
|
||||
|
||||
/**
|
||||
* Construct the token
|
||||
*
|
||||
* @param string $tag
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
* @param Zend_Markup_Token $parent
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
$tag,
|
||||
$type,
|
||||
$name = '',
|
||||
array $attributes = array(),
|
||||
Zend_Markup_Token $parent = null
|
||||
) {
|
||||
$this->_tag = $tag;
|
||||
$this->_type = $type;
|
||||
$this->_name = $name;
|
||||
$this->_attributes = $attributes;
|
||||
$this->_parent = $parent;
|
||||
}
|
||||
|
||||
// accessors
|
||||
|
||||
/**
|
||||
* Set the stopper
|
||||
*
|
||||
* @param string $stopper
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function setStopper($stopper)
|
||||
{
|
||||
$this->_stopper = $stopper;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stopper
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStopper()
|
||||
{
|
||||
return $this->_stopper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token's name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token's type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete tag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->_tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an attribute
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAttribute($name)
|
||||
{
|
||||
return isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the token has an attribute
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAttribute($name)
|
||||
{
|
||||
return isset($this->_attributes[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an attribute
|
||||
*
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function addAttribute($name, $value)
|
||||
{
|
||||
$this->_attributes[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an attribute is empty
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function attributeIsEmpty($name)
|
||||
{
|
||||
return empty($this->_attributes[$name]);
|
||||
}
|
||||
|
||||
// functions for child/parent tokens
|
||||
|
||||
/**
|
||||
* Add a child token
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addChild(Zend_Markup_Token $child)
|
||||
{
|
||||
$this->getChildren()->addChild($child);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the children token list
|
||||
*
|
||||
* @param Zend_Markup_TokenList $children
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function setChildren(Zend_Markup_TokenList $children)
|
||||
{
|
||||
$this->_children = $children;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the children for this token
|
||||
*
|
||||
* @return Zend_Markup_TokenList
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
if (null === $this->_children) {
|
||||
$this->setChildren(new Zend_Markup_TokenList());
|
||||
}
|
||||
return $this->_children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this token have any children
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren()
|
||||
{
|
||||
return !empty($this->_children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent token (if any)
|
||||
*
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->_parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parent token
|
||||
*
|
||||
* @param Zend_Markup_Token $parent
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function setParent(Zend_Markup_Token $parent)
|
||||
{
|
||||
$this->_parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic clone function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->_parent = null;
|
||||
$this->_children = null;
|
||||
$this->_tag = '';
|
||||
}
|
||||
}
|
124
library/Zend/Markup/TokenList.php
Normal file
124
library/Zend/Markup/TokenList.php
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: TokenList.php 20277 2010-01-14 14:17:12Z kokx $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Markup_Token
|
||||
*/
|
||||
require_once 'Zend/Markup/Token.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Markup
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Markup_TokenList implements RecursiveIterator
|
||||
{
|
||||
|
||||
/**
|
||||
* Array of tokens
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tokens = array();
|
||||
|
||||
/**
|
||||
* Get the current token
|
||||
*
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->_tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the children of the current token
|
||||
*
|
||||
* @return Zend_Markup_TokenList
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return current($this->_tokens)->getChildren();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new child token
|
||||
*
|
||||
* @param Zend_Markup_Token $child
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addChild(Zend_Markup_Token $child)
|
||||
{
|
||||
$this->_tokens[] = $child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current token has children
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren()
|
||||
{
|
||||
return current($this->_tokens)->hasChildren();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key of the current token
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->_tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Go to the next token
|
||||
*
|
||||
* @return Zend_Markup_Token
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->_tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the iterator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the element is valid
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return $this->current() !== false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue