File content/formatting/parser/AbstractParser.class.php
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133:
<?php
/**
* This class is the basis of all the formatting processings that exist in PHPBoost.
* @package Content
* @subpackage Formatting\parser
* @copyright © 2005-2019 PHPBoost
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
* @author Regis VIARRE <crowkait@phpboost.com>
* @version PHPBoost 5.2 - last update: 2016 10 28
* @since PHPBoost 2.0 - 2007 11 29
* @contributor Loic ROUCHON <horn@phpboost.com>
* @contributor Benoit SAUTEL <ben.popeye@phpboost.com>
* @contributor Julien BRISWALTER <j1.seth@phpboost.com>
* @contributor Arnaud GENET <elenwii@phpboost.com>
*/
abstract class AbstractParser implements FormattingParser
{
const PICK_UP = true;
const REIMPLANT = false;
/**
* @var string Content of the parser
*/
protected $content = '';
/**
* @var string[] List of the tags which have been picked up by the parser
*/
protected $array_tags = array();
/**
* @var string Path to root of the page in which has been written the content to parse.
*/
protected $path_to_root = PATH_TO_ROOT;
/**
* @var string Path of the page in which has been written the content to parse.
*/
protected $page_path = '';
/**
* @var string[] List of the tags to add from a module. Allows to add a tag [link] from pages or wiki from example
*/
protected $module_special_tags = array();
/**
* Builds a Parser object.
*/
public function __construct()
{
$this->content = '';
$this->page_path = $_SERVER['PHP_SELF'];
}
/**
* {@inheritdoc}
*/
public function get_content()
{
return trim($this->content);
}
/**
* {@inheritdoc}
*/
public function set_content($content)
{
$this->content = $content;
}
/**
* {@inheritdoc}
*/
public function set_path_to_root($path)
{
$this->path_to_root = $path;
}
/**
* {@inheritdoc}
*/
public function get_path_to_root()
{
return $this->path_to_root;
}
/**
* {@inheritdoc}
*/
public function set_page_path($page_path)
{
$this->page_path = $page_path;
}
/**
* {@inheritdoc}
*/
public function get_page_path()
{
return $this->page_path;
}
/**
* {@inheritdoc}
*/
public function add_module_special_tag($pattern, $replacement)
{
$this->module_special_tags[$pattern] = $replacement;
}
/**
* {@inheritdoc}
*/
public function get_module_special_tags()
{
return $this->module_special_tags;
}
/**
* Parses a nested tag
* @param string $match The regular expression which matches the tag to replace
* @param string $regex The regular expression which matches the replacement
* @param string $replace The replacement syntax.
*/
protected function _parse_imbricated($match, $regex, $replace)
{
$nbr_match = TextHelper::substr_count($this->content, $match);
for ($i = 0; $i < $nbr_match; $i++)
{
$this->content = preg_replace($regex, $replace, $this->content);
}
}
}
?>