unused jbbcode visitors removed
This commit is contained in:
parent
0c61f05ffe
commit
369f66d896
3 changed files with 0 additions and 157 deletions
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
namespace JBBCode\visitors;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This visitor escapes html content of all strings and attributes
|
||||
*
|
||||
* @author Alexander Polyanskikh
|
||||
*/
|
||||
class HTMLSafeVisitor implements \JBBCode\NodeVisitor
|
||||
{
|
||||
public function visitDocumentElement(\JBBCode\DocumentElement $documentElement)
|
||||
{
|
||||
foreach ($documentElement->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function visitTextNode(\JBBCode\TextNode $textNode)
|
||||
{
|
||||
$textNode->setValue($this->htmlSafe($textNode->getValue()));
|
||||
}
|
||||
|
||||
public function visitElementNode(\JBBCode\ElementNode $elementNode)
|
||||
{
|
||||
$attrs = $elementNode->getAttribute();
|
||||
if (is_array($attrs))
|
||||
{
|
||||
foreach ($attrs as &$el)
|
||||
$el = $this->htmlSafe($el);
|
||||
|
||||
$elementNode->setAttribute($attrs);
|
||||
}
|
||||
|
||||
foreach ($elementNode->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
protected function htmlSafe($str, $options = null)
|
||||
{
|
||||
if (is_null($options))
|
||||
{
|
||||
if (defined('ENT_DISALLOWED'))
|
||||
$options = ENT_QUOTES | ENT_DISALLOWED | ENT_HTML401; // PHP 5.4+
|
||||
else
|
||||
$options = ENT_QUOTES; // PHP 5.3
|
||||
}
|
||||
|
||||
return htmlspecialchars($str, $options, 'UTF-8');
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
namespace JBBCode\visitors;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This visitor is an example of how to implement smiley parsing on the JBBCode
|
||||
* parse graph. It converts :) into image tags pointing to /smiley.png.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since April 2013
|
||||
*/
|
||||
class SmileyVisitor implements \JBBCode\NodeVisitor
|
||||
{
|
||||
|
||||
function visitDocumentElement(\JBBCode\DocumentElement $documentElement)
|
||||
{
|
||||
foreach($documentElement->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
function visitTextNode(\JBBCode\TextNode $textNode)
|
||||
{
|
||||
/* Convert :) into an image tag. */
|
||||
$textNode->setValue(str_replace(':)',
|
||||
'<img src="/smiley.png" alt=":)" />',
|
||||
$textNode->getValue()));
|
||||
}
|
||||
|
||||
function visitElementNode(\JBBCode\ElementNode $elementNode)
|
||||
{
|
||||
/* We only want to visit text nodes within elements if the element's
|
||||
* code definition allows for its content to be parsed.
|
||||
*/
|
||||
if ($elementNode->getCodeDefinition()->parseContent()) {
|
||||
foreach ($elementNode->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
namespace JBBCode\visitors;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This visitor traverses parse graph, counting the number of times each
|
||||
* tag name occurs.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since January 2013
|
||||
*/
|
||||
class TagCountingVisitor implements \JBBcode\NodeVisitor
|
||||
{
|
||||
protected $frequencies = array();
|
||||
|
||||
public function visitDocumentElement(\JBBCode\DocumentElement $documentElement)
|
||||
{
|
||||
foreach ($documentElement->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function visitTextNode(\JBBCode\TextNode $textNode)
|
||||
{
|
||||
// Nothing to do here, text nodes do not have tag names or children
|
||||
}
|
||||
|
||||
public function visitElementNode(\JBBCode\ElementNode $elementNode)
|
||||
{
|
||||
$tagName = strtolower($elementNode->getTagName());
|
||||
|
||||
// Update this tag name's frequency
|
||||
if (isset($this->frequencies[$tagName])) {
|
||||
$this->frequencies[$tagName]++;
|
||||
} else {
|
||||
$this->frequencies[$tagName] = 1;
|
||||
}
|
||||
|
||||
// Visit all the node's childrens
|
||||
foreach ($elementNode->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the frequency of the given tag name.
|
||||
*
|
||||
* @param $tagName the tag name to look up
|
||||
*/
|
||||
public function getFrequency($tagName)
|
||||
{
|
||||
if (!isset($this->frequencies[$tagName])) {
|
||||
return 0;
|
||||
} else {
|
||||
return $this->frequencies[$tagName];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue