<?php
/**
*
* @package BBParser.php
* @version 2.4.0
* @author Gerasimov Konstantin
* @copyright Copyright (c) 2008-2010, Gerasimov Konstantin
* @license LGPL
*/
interface BBDecoder {
/**
* Возвращает начало обрамления
* @return string
*/
public function GetOpenHTML();
/**
* Возвращает конец обрамления
* @return string
*/
public function GetCloseHTML();
/**
* Возвращает TRUE если желает владеть кодом, иначе FALSE
* @return bool
*/
public function NeedContainCode();
/**
* Добавляет код во владение
*/
public function AddCode($sCodeString);
/**
* Возвращает TRUE если BB-код корректен, иначе FALSE
*/
public function Validate();
}
/**
* Обработчик исключений при работе с BBParser
*/
class BBParserException extends Exception {}
/**
* Класс парсинга
*/
class BBParser {
/**
* @var FSM конечный автомат
*/
private $_FSM;
/**
* @var string входной текст
*/
private $_sInText;
/**
* @var int длинна входного текста
*/
private $_iInTextCount;
/**
* @var string выходной текст
*/
private $_sOutText;
/**
* @var string
*/
private $_sCurrBB;
/**
* @var array
*/
private $_arBBStack;
/**
* @var int
*/
private $_iCurrBBContainStackIndex;
/**
* @var array
*/
private $_arBBCodes;
/**
* @var string
*/
private $_sCharset;
/**
* @var bool
*/
private $_Deb;
/**
* @var string
*/
private $_DebS;
/**
* @param array $arAvailableBBCodes
*/
public function __construct($arAvailableBBCodes = array('B', 'I', 'IMG', 'URL', 'QUOTE', 'CODE', 'ALIGN', 'SIZE', 'COLOR', 'LABEL', 'LIST', 'ENDOFNODEPREVIEW'))
{
$this->_sCharset = 'UTF-8';
/*Иницилизируем FSM*/
$this->_FSM = new FSM('0');
/**
* Состояния:
* 0 - Ожидаем что угодно.
* 1 - Ожидаем символ BB-кода или "/" (только что начался BB-код символом "[")
* 2 - Ожидаем символ BB-кода
* 3 - Ожидаем "]"
*/
//Вход по умолчанию
$this->_FSM->SetDefaultTransition(array($this, 'AddTextChar'), '0');
//Вход: [
$this->_FSM->AddTransition('[', '0', array($this, 'StartBB'), '1');
$this->_FSM->AddTransition('[', '1', array($this, 'BreakBB'), '0');
$this->_FSM->AddTransition('[', '2', array($this, 'BreakBB'), '0');
$this->_FSM->AddTransition('[', '3', array($this, 'BreakBBThenStartBB'), '1');
//Вход: /
$this->_FSM->AddTransition('/', '0', array($this, 'AddTextChar'), '0');
$this->_FSM->AddTransition('/', '1', array($this, 'AddBBChar'), '2');
$this->_FSM->AddTransition('/', '2', array($this, 'AddBBChar'), '2');
$this->_FSM->AddTransition('/', '3', array($this, 'AddBBChar'), '3');
//Вход: ]
$this->_FSM->AddTransition(']', '0', array($this, 'AddTextChar'), '0');
$this->_FSM->AddTransition(']', '1', array($this, 'BreakBB'), '0');
$this->_FSM->AddTransition(']', '2', array($this, 'BreakBB'), '0');
$this->_FSM->AddTransition(']', '3', array($this, 'EndBB'), '0');
//Вход: любой символ кроме "[", "]" и "/"
$this->_FSM->AddDefaultTransition('0', array($this, 'AddTextChar'), '0');
$this->_FSM->AddDefaultTransition('1', array($this, 'AddBBChar'), '3');
$this->_FSM->AddDefaultTransition('2', array($this, 'AddBBChar'), '3');
$this->_FSM->AddDefaultTransition('3', array($this, 'AddBBChar'), '3');
//Доступные BB-коды
$this->_arBBCodes = $arAvailableBBCodes;
//debug
$this->_Deb = FALSE;
$this->_DebS = '';
}
/**
* Устанавливает кодировку
* @param string $sNewCharset
*/
public function SetCharset($sNewCharset)
{
if ($sNewCharset != '') {
$this->_sCharset = $sNewCharset;
}
}
/**
* Добавляет символ текста
* @param string $sChar
*/
public function AddTextChar($sChar)
{
if ($this->_iCurrBBContainStackIndex === -1) {
$this->_sOutText .= htmlspecialchars($sChar, ENT_QUOTES, $this->_sCharset);
}
else {
$this->_arBBStack[$this->_iCurrBBContainStackIndex]['BBDecoder']->AddCode($sChar);
}
}
/**
* Стартует формирвание BB-кода
* @param string $sChar
*/
public function StartBB($sChar)
{
$this->_sCurrBB = $sChar;
}
/**
* Добавляет символ BB-кода
* @param string $sChar
*/
public function AddBBChar($sChar)
{
$this->_sCurrBB .= $sChar;
}
/**
* Ошибка синтаксиса BB-кода
* @param string $sChar
*/
public function BreakBB($sChar)
{
$this->AddTextChar($this->_sCurrBB . $sChar);
$this->_sCurrBB = '';
}
/**
* Завершение формирования BB-кода
* @param string $sChar
*/
public function EndBB($sChar)
{
$this->_sCurrBB .= $sChar;
$this->_ProcessBB($this->_sCurrBB);
}
/**
* Ошибка синтаксиса и инициализация начала BB-кода
* @param string $sChar
*/
public function BreakBBThenStartBB($sChar)
{
$this->BreakBB('');
$this->StartBB($sChar);
}
/**
* Возвращает декодированный HTML текст
* @param string $sInText исходный текст
* @return string HTML текст
*/
public function GetHTML($sInText)
{
BB_CODE::ClearListingNumbers();
$this->_sOutText = '';
$this->ParseText($sInText);
$this->_sOutText = '<div class="node_block">' . $this->_UpdateEndsOfLines($this->_sOutText) . '</div>';
return $this->_sOutText;
}
/**
* @param string $sInText
* @return string
*/
public function ParseText($sInText) {
if ($sInText == '') {
$this->_sOutText = ' ';
return $this->_sOutText;
}
$this->_ClearVars();
$this->_sInText = $sInText;
$this->_iInTextCount = Str::Strlen($this->_sInText);
for($i = 0; $i < $this->_iInTextCount; $i++) {
$this->_FSM->GoStep(Str::Substr($this->_sInText, $i, 1));
}
$this->_CheckNotClosedBB();
return $this->_sOutText;
}
/**
* @param stirn $sText
* @return string
*/
private function _UpdateEndsOfLines($sText)
{
$sText = str_replace("\r\n", "\n", $sText);
$sText = '<p>' . str_replace("\n", '</p><p>', $sText) . '</p>';
$sText = str_replace('<p></p>', '<br>', $sText);
$sText = str_replace('<p></div>', '</div><p>', $sText);
$sText = str_replace('<div class="node_block"></p>', '</p><div class="node_block">', $sText);
return $sText;
}
/**
* Очищает переменные для следующего преобразования
*/
private function _ClearVars()
{
$this->_FSM->SetState('0');
$this->_Deb = FALSE;
$this->_DebS = '';
$this->_iInTextCount = 0;
$this->_sInText = '';
//$this->_sOutText = '';
$this->_sCurrBB = '';
$this->_arBBStack = array();
$this->_iCurrBBContainStackIndex = -1;
}
/**
* Вызывает соответсвтвующи функции обработки
* @param string $sBB
*/
private function _ProcessBB($sBB)
{
if (Str::Substr($sBB, 1, 1) === '/') {
$this->_CloseBB(Str::Substr($sBB, 2, Str::Strlen($sBB) - 3));
}
else {
$this->_OpenBB(Str::Substr($sBB, 1, Str::Strlen($sBB) - 2));
}
}
/**
* Открывает BB-код
* @param string $sCleanBB
*/
private function _OpenBB($sCleanBB)
{
if ($this->_iCurrBBContainStackIndex !== -1) {
$this->BreakBB('');
return;
}
$arBBHash = $this->_GetBBHash($sCleanBB);
if ($arBBHash['BBName'] === '') {
$this->BreakBB('');
return;
}
$BBName = 'BB_' . $arBBHash['BBName'];
$BB = new $BBName($arBBHash['BBParams']);
if (!$BB->Validate()) {
$this->BreakBB('');
return;
}
$BBIndex = array_push($this->_arBBStack, array('BBName'=>$arBBHash['BBName'], 'BBDecoder'=>$BB)) - 1;
if ($BB->NeedContainCode()) {
$this->_StartBBContaining($BBIndex);
}
$this->_sOutText .= $BB->GetOpenHTML();
}
/**
* Закрывает BB-кодs
* @param string $sCleanBB
*/
private function _CloseBB($sCleanBB)
{
$arBBHash = $this->_GetBBHash($sCleanBB);
if ($arBBHash['BBName'] === '') {
$this->BreakBB('');
return;
}
$arLastOpenBB = array_pop($this->_arBBStack);
if (NULL !== $arLastOpenBB) {
if ($arLastOpenBB['BBName'] === $arBBHash['BBName']) {
$this->_sOutText .= $arLastOpenBB['BBDecoder']->GetCloseHTML();
$this->_EndBBContaining();
$arLastOpenBB['BBDecoder'] = NULL;
}
else {
array_push($this->_arBBStack, $arLastOpenBB);
$this->BreakBB('');
}
}
}
/**
* Возвращает хэш параметров BB-кода
* @param string BB-код
*/
private function _GetBBHash($sCleanBB)
{
$arHash = array();
$arHash['BBName'] = $this->_GetBBName($sCleanBB);
$arHash['BBParams'] = $this->_GetBBParams($sCleanBB, Str::Strlen($arHash['BBName']));
return $arHash;
}
/**
* Возвращает имя BB-кода или пустое значени если такой BB-код не известен
* @param string $sCleanBB
* @return string
*/
private function _GetBBName($sCleanBB)
{
$iCount = count($this->_arBBCodes);
for($i = 0; $i < $iCount; $i++) {
if (preg_match('/^('. $this->_arBBCodes[$i] . ')(?(?=[=]{1})(.*)|($))/ui', $sCleanBB)) {
return $this->_arBBCodes[$i];
}
}
return '';
}
/**
* Возваращет параметры BB-кода
* @param string $sCleanBB
* @param ing $iBBNameLength
*/
private function _GetBBParams($sCleanBB, $iBBNameLength)
{
if (($iBBNameLength > 0) &&
(Str::Substr($sCleanBB, $iBBNameLength, 1) === '=') &&
(Str::Strlen(Str::Substr($sCleanBB, $iBBNameLength + 1)) != FALSE)) {
return Str::Substr($sCleanBB, $iBBNameLength + 1);
}
else {
return '';
}
}
/**
* Закрывает открытые BB-коды
*/
private function _CheckNotClosedBB()
{
if (count($this->_arBBStack)) {
while (NULL !== ($arNeedCloseBB = array_pop($this->_arBBStack))) {
$this->_sOutText .= $arNeedCloseBB['BBDecoder']->GetCloseHTML();
$this->_EndBBContaining();
$arNeedCloseBB['BBDecoder'] = NULL;
}
}
}
/**
* Включает режим владения кодом BB-кода с индексом в стэке
* @param int $iBBStackIndex
*/
private function _StartBBContaining($iBBStackIndex)
{
$this->_iCurrBBContainStackIndex = $iBBStackIndex;
}
/**
* Выключает режим владения кодом BB-кода
*/
private function _EndBBContaining()
{
$this->_iCurrBBContainStackIndex = -1;
}
}
/**
* Класс обработки BB-кода [B] [/B]
* Без параметров
*/
class BB_B implements BBDecoder {
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
return '<b>';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</b>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
return TRUE;
}
}
/**
* Класс обработки BB-кода [I] [/I]
* Без параметров
*/
class BB_I implements BBDecoder {
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
return '<em>';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</em>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
return TRUE;
}
}
/**
* Класс обработки BB-кода [IMG] [/IMG]
* Параметры: [IMG=ссылка_на_рисунок]подпись_рисунка[/IMG]
*/
class BB_IMG implements BBDecoder {
/**
* @var string
*/
private $_sSrc;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_sSrc = $sParams;
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
return '<img src="' . $this->_sSrc . '" alt="';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '">';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
return (preg_match('/^[^<>"]+$/iu', $this->_sSrc));
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
}
/**
* Класс обработки BB-кода [URL] [/URL]
* Параметры [URL=ссылка]надпись_ссылки[/URL]
*/
class BB_URL implements BBDecoder {
/**
* @var string
*/
private $_sParams;
/**
* @var string
*/
private $_sURL;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_sParams = $sParams;
$AncorStr = '';
$UrlStr = $this->_sParams;
if(FALSE !== $AncorPos = Str::Strpos($this->_sParams, '#')) {
$AncorStr = Str::Substr($this->_sParams, $AncorPos + 1, Str::Strlen($this->_sParams) - $AncorPos);
$UrlStr = Str::Substr($this->_sParams, 0, $AncorPos);
}
$this->_sURL = (($UrlStr) ? urldecode($UrlStr) : '') . (($AncorStr) ? '#' . urldecode(Str::Strtolower($AncorStr)) : '');
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
return '<a href="' . $this->_sURL . '"' . ((Str::Substr($this->_sURL, 0, 1) == '#') ? ' target="_self"' : ' target="_blank"') . '>';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</a>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
return (preg_match('#^[^<>"]+$#iu', $this->_sParams));
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
}
/**
* Класс обработки BB-кода [QUOTE] [/QUOTE]
* Параметры: [QUOTE=имя_комментриуемого]текст_комментария[/QUOTE]
*/
class BB_QUOTE implements BBDecoder {
/**
* @var string
*/
private $_sName;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_sName = $sParams;
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
return '<div class="quote"><div class="quote_title">' . htmlspecialchars($this->_sName , ENT_QUOTES, 'UTF-8') . '</div>';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</div>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
if(trim($this->_sName) !== '') {
return TRUE;
}
else {
return FALSE;
}
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
}
/**
* Класс обработки BB-кода [CODE] [слешьCODE]
* Параметры: [CODE=имя_языка]текст_программы[слешьCODE]
*/
class BB_CODE implements BBDecoder {
/**
* @var int
*/
private static $_iListingNumber = 0;
/**
* @var string
*/
private $_sCodeName;
/**
* @var string
*/
private $_sCode;
/**
* @var array
*/
private $_arAvailableCodes;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_sCodeName = $sParams;
$this->_sCode = '';
$this->_arAvailableCodes = array('unknown' => 'unknown',
'php' => 'PHP',
'python' => 'Python',
'perl' => 'Perl',
'javascript' => 'JavaScript',
'actionscript3' => 'ActionScript',
'html4strict' => 'HTML',
'css' => 'CSS',
'xml' => 'XML',
'apache' => 'Apache',
'sql' => 'SQL',
'c' => 'C',
'cpp' => 'C++',
'csharp' => 'C#',
'delphi' => 'Delphi',
'pascal' => 'Pascal',
'ruby' => 'Ruby',
'rails' => 'Rails',
'java5' => 'Java5',
'java' => 'Java',
'smalltalk' => 'Smalltalk',
'vb' => 'VisualBasic',
'vbnet' => 'VisualBasic(.Net)',
'visualfoxpro' => 'VisualFoxPro',
'asm' => 'Asm'
);
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
self::$_iListingNumber++;
return '<div class="code"><a name="listing' .
self::$_iListingNumber .
'"></a><div class="code_title">Listing №' .
self::$_iListingNumber .
' (' .
htmlspecialchars($this->_arAvailableCodes[$this->_sCodeName], ENT_QUOTES, 'UTF-8') .
')</div>';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return $this->_GetHighlightCode() . '</div>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return TRUE;
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
$this->_sCode .= $sCodeString;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
if (preg_match('/^[0-9A-Z]+$/ui', $this->_sCodeName)) {
return (array_key_exists(Str::Strtolower($this->_sCodeName), $this->_arAvailableCodes));
}
return FALSE;
}
/**
* Выполняет подсветку синтаксиса
* @return string
*/
private function _GetHighlightCode()
{
if ((Str::Strlen($this->_sCode) < MAX_HIGHLIGHT_BUFFER)) {
require_once GESHI_ROOT . 'geshi' . PHP_EXT;
$Highlighter = new GeSHi($this->_sCode, $this->_sCodeName);
$Highlighter->set_header_type(GESHI_HEADER_DIV);
$Highlighter->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$Highlighter->set_tab_width(2);
$Highlighter->set_encoding('UTF-8');
$sCode = $Highlighter->parse_code();
unset($Highlighter);
return $sCode;
}
else {
return htmlspecialchars($this->_sCode, ENT_QUOTES, 'UTF-8');
}
}
/**
* Очищает счетчик листингов
*/
public static function ClearListingNumbers()
{
self::$_iListingNumber = 0;
}
}
/**
* Класс обработки BB-кода [ALIGN] [/ALIGN]
* Параметры: [ALIGN=выравнивание]текст[/ALIGN]
*/
class BB_ALIGN implements BBDecoder {
/**
* @var string
*/
private $_sAligment;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_sAligment = $sParams;
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
if (strtolower($this->_sAligment) === 'center') {
return '</div><div style="text-align: ' . $this->_sAligment . '; width: auto; border: 0;">';
}
else {
return '</div><div style="text-align: ' . $this->_sAligment . ';float: ' . $this->_sAligment . ';">';
}
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</div><div class="node_block">';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
if((Str::Strtolower($this->_sAligment) === 'right') ||
(Str::Strtolower($this->_sAligment) === 'left') ||
(Str::Strtolower($this->_sAligment) === 'center')) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
}
/**
* Класс обработки BB-кода [SIZE] [/SIZE]
* Параметры: [SIZE=размер]текст[/SIZE]
*/
class BB_SIZE implements BBDecoder {
/**
* @var string
*/
private $_fHeight;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_fHeight = $sParams;
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
return '<div style="font-size: ' . $this->_fHeight . 'em;">';
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</div>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
if (is_numeric($this->_fHeight) && ($this->_fHeight > 0) && ($this->_fHeight < 5)) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
}
/**
* Класс обработки BB-кода [COLOR] [/COLOR]
* Параметры: [COLOR=#00fa000]текст[/COLOR]
*/
class BB_COLOR implements BBDecoder {
/**
* @var array
*/
private $_arColors;
/**
* @var string
*/
private $_sColor;
/**
* @param string $sParams
*/
public function __construct($sParams)
{
$this->_sColor = $sParams;
$this->_arColors = array('red' => '#FF0000',
'green' => '#00FF00',
'blue' => '#0000FF',
'black' => '#000000',
'yellow'=> '#FFFF00',
'gray' => '#808080',
'white' => '#FFFFFF');
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetOpenHTML()
{
if (array_key_exists(Str::Strtolower($this->_sColor), $this->_arColors)) {
return '<span style="color: ' . $this->_arColors[$this->_sColor] . ';">';
}
else {
return '<span style="color: ' . $this->_sColor . ';">';
}
}
/**
*@see interface BBDecoder
*@return string
*/
public function GetCloseHTML()
{
return '</span>';
}
/**
* @see interface BBDecoder
* @return bool
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
* @return bool
*/
public function Validate()
{
if (array_key_exists(Str::Strtolower($this->_sColor), $this->_arColors) || (preg_match('/[#][0-9a-f]{1,6}/iu', $this->_sColor))) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
}
/**
* Класс обработки BB-кода [LABEL] [/LABEL]
* Параметры: [LABEL=имя метки][/LABEL]
*/
class BB_LABEL implements BBDecoder {
/**
* @var string
*/
private $_LabelName;
public function __construct($Params)
{
$this->_LabelName = $Params;
}
/**
* @see interface BBDecoder
*/
public function GetOpenHTML()
{
return '<a name="' . Str::Strtolower($this->_LabelName) . '"></a>';
}
/**
* @see interface BBDecoder
*/
public function GetCloseHTML()
{
return '';
}
/**
* @see interface BBDecoder
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
/**
* @see interface BBDecoder
*/
public function Validate()
{
return (preg_match('#^[_a-z0-9-]+(\s{1}[_a-z0-9-]+)*$#iu', $this->_LabelName));
}
}
/**
* Класс обработки BB-кода [LIST] [/LIST]
* Параметры: [LIST=тип списка][/LIST]
*/
class BB_LIST implements BBDecoder {
/**
* @var strign
*/
private $_Type;
/**
* @var strings
*/
private $_sCode;
/**
* @params $sParams
*/
public function __construct($sParams)
{
$this->_Type = $sParams;
$this->_sCode = '';
}
/**
* @see interface BBDecoder
*/
public function GetOpenHTML()
{
return '<'. $this->_GetListType() . ' class="list">';
}
/**
* @see interface BBDecoder
*/
public function GetCloseHTML()
{
$BBSubParser = new BBParser(array('B', 'I', 'URL', 'SIZE', 'COLOR'));
$sParsedCode = $BBSubParser->ParseText($this->_sCode);
unset($BBSubParser);
$sParsedCode = preg_replace("/\r\n|\n/u", "\n", $sParsedCode);
$sParsedCode = preg_replace("/\n/u", '</li><li class="list_item">', '<li class="list_item">' . $sParsedCode . '</li>');
$sParsedCode = preg_replace('#<li class="list_item"></li>#u', '', $sParsedCode) . '</' . $this->_GetListType(). '>';
return $sParsedCode . "\n";
}
/**
* @see interface BBDecoder
*/
public function NeedContainCode()
{
return TRUE;
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
$this->_sCode .= $sCodeString;
}
/**
* @see interface BBDecoder
*/
public function Validate()
{
return ((Str::Strtolower($this->_Type) === 'numbers') || (Str::Strtolower($this->_Type) === 'points'));
}
/**
* @return string
*/
private function _GetListType()
{
if(Str::Strtolower($this->_Type) === 'numbers') {
return 'ol';
}
else {
return 'ul';
}
}
}
/**
* Класс обработки BB-кода [ENDOFNODEPREVIEW] [/ENDOFNODEPREVIEW]
* Параметры(нету пока параметров): [ENDOFNODEPREVIEW][/ENDOFNODEPREVIEW]
*/
class BB_ENDOFNODEPREVIEW implements BBDecoder {
/**
* @see interface BBDecoder
*/
public function __construct($sParams)
{
}
/**
* @see interface BBDecoder
*/
public function GetOpenHTML()
{
return '';
}
/**
* @see interface BBDecoder
*/
public function GetCloseHTML()
{
return '';
}
/**
* @see interface BBDecoder
*/
public function NeedContainCode()
{
return FALSE;
}
/**
* @see interface BBDecoder
*/
public function AddCode($sCodeString)
{
}
/**
* @see interface BBDecoder
*/
public function Validate()
{
return TRUE;
}
}
?>
ужасный говногодище