diff --git a/Xbb/Tags/A.php b/Xbb/Tags/A.php index 7cf1958..9c71441 100644 --- a/Xbb/Tags/A.php +++ b/Xbb/Tags/A.php @@ -22,13 +22,18 @@ ******************************************************************************/ // Класс для тегов [a], [anchor] и [url] -class Xbb_Tags_A extends bbcode { +class Xbb_Tags_A extends bbcode +{ public $behaviour = 'a'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $this -> autolinks = false; $text = ''; foreach ($this -> tree as $val) { - if ('text' == $val['type']) { $text .= $val['str']; } + if ('text' === $val['type']) { + $text .= $val['str']; + } } $href = ''; if (isset($this -> attrib['url'])) { @@ -40,15 +45,17 @@ function get_html($tree = null) { if (! $href && isset($this -> attrib['href'])) { $href = $this -> attrib['href']; } - if (! $href && ! isset($this -> attrib['anchor'])) { $href = $text; } - $href = $this -> checkUrl($href); + if (! $href && ! isset($this -> attrib['anchor'])) { + $href = $text; + } + $href = $this -> _checkUrl($href); $attr = 'class="bb"'; if ($href) { - $attr .= ' href="'.$href.'"'; + $attr .= ' href="' . $href . '"'; } if (isset($this -> attrib['title'])) { $title = $this -> attrib['title']; - $attr .= ' title="'.htmlspecialchars($title).'"'; + $attr .= ' title="' . htmlspecialchars($title) . '"'; } $id = ''; if (isset($this -> attrib['id'])) { @@ -62,14 +69,16 @@ function get_html($tree = null) { if (! $id) { $id = $text; } } if ($id) { - if ($id{0} < 'A' || $id{0} > 'z') { $id = 'bb'.$id; } - $attr .= ' id="'.htmlspecialchars($id).'"'; + if ($id{0} < 'A' || $id{0} > 'z') { + $id = 'bb' . $id; + } + $attr .= ' id="' . htmlspecialchars($id) . '"'; } if (isset($this -> attrib['target'])) { $target = $this -> attrib['target']; - $attr .= ' target="'.htmlspecialchars($target).'"'; + $attr .= ' target="' . htmlspecialchars($target) . '"'; } - return ''.parent::get_html($this -> tree).''; + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Abbr.php b/Xbb/Tags/Abbr.php index ac64495..dd104d8 100644 --- a/Xbb/Tags/Abbr.php +++ b/Xbb/Tags/Abbr.php @@ -22,14 +22,16 @@ ******************************************************************************/ // Класс для тега [abbr] -class Xbb_Tags_Abbr extends bbcode { +class Xbb_Tags_Abbr extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attrib = 'class="bb"'; if ($this -> attrib['abbr']) { - $attrib .= ' title="'.htmlspecialchars($this -> attrib['abbr']).'"'; + $attrib .= ' title="' . htmlspecialchars($this -> attrib['abbr']) . '"'; } - return ''.parent::get_html($this -> tree).''; + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Acronym.php b/Xbb/Tags/Acronym.php index 7e38ef9..1d56a06 100644 --- a/Xbb/Tags/Acronym.php +++ b/Xbb/Tags/Acronym.php @@ -22,16 +22,19 @@ ******************************************************************************/ // Класс для тега [acronym] -class Xbb_Tags_Acronym extends bbcode { +class Xbb_Tags_Acronym extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attrib = 'class="bb"'; if ($this -> attrib['acronym']) { - $attrib .= ' title="'.htmlspecialchars($this -> attrib['acronym']) - .'"'; + $attrib .= ' title="' . htmlspecialchars($this -> attrib['acronym']) + . '"'; } - return ''.parent::get_html($this -> tree) - .''; + + return '' . parent::get_html($this -> tree) + . ''; } } -?> diff --git a/Xbb/Tags/Address.php b/Xbb/Tags/Address.php index f790e44..7484b7c 100644 --- a/Xbb/Tags/Address.php +++ b/Xbb/Tags/Address.php @@ -22,11 +22,13 @@ ******************************************************************************/ // Класс для тега [address] -class Xbb_Tags_Address extends bbcode { +class Xbb_Tags_Address extends bbcode +{ public $rbr = 1; - function get_html($tree = null) { - return '
'.parent::get_html($this -> tree) - .'
'; + + public function get_html($tree = null) + { + return '
' . parent::get_html($this -> tree) + . '
'; } } -?> diff --git a/Xbb/Tags/Align.php b/Xbb/Tags/Align.php index 2acff8e..e9e990d 100644 --- a/Xbb/Tags/Align.php +++ b/Xbb/Tags/Align.php @@ -22,9 +22,12 @@ ******************************************************************************/ // Класс для тегов [align], [center], [justify], [left] и [right] -class Xbb_Tags_Align extends bbcode { +class Xbb_Tags_Align extends bbcode +{ public $rbr = 1; - function get_html($tree = null) { + + public function get_html($tree = null) + { $align = ''; if (isset($this -> attrib['justify'])) { $align = 'justify'; } if (isset($this -> attrib['left'])) { $align = 'left'; } @@ -46,8 +49,9 @@ function get_html($tree = null) { break; } } - return '
' - .parent::get_html($this -> tree).'
'; + + return '
' + . parent::get_html($this -> tree) . '
'; } } ?> diff --git a/Xbb/Tags/Bbcode.php b/Xbb/Tags/Bbcode.php index 18647b9..71d25e7 100644 --- a/Xbb/Tags/Bbcode.php +++ b/Xbb/Tags/Bbcode.php @@ -22,12 +22,17 @@ ******************************************************************************/ // Класс для тега [bbcode] -class Xbb_Tags_Bbcode extends bbcode { - public $behaviour = 'code'; - function get_html($tree = null) { +class Xbb_Tags_Bbcode extends bbcode +{ + public $behaviour = 'code'; + + public function get_html($tree = null) + { $str = ''; foreach ($this -> tree as $item) { - if ('item' == $item['type']) { continue; } + if ('item' === $item['type']) { + continue; + } $str .= $item['str']; } $bb = new bbcode(); @@ -35,7 +40,7 @@ function get_html($tree = null) { $bb -> mnemonics = $this -> mnemonics; $bb -> autolinks = $this -> autolinks; $bb -> parse($str); - return ''.$bb -> highlight().''; + + return '' . $bb -> highlight() . ''; } } -?> diff --git a/Xbb/Tags/Bdo.php b/Xbb/Tags/Bdo.php index 34dcb28..a059daa 100644 --- a/Xbb/Tags/Bdo.php +++ b/Xbb/Tags/Bdo.php @@ -22,9 +22,12 @@ ******************************************************************************/ // Класс для тега [bdo] -class Xbb_Tags_Bdo extends bbcode { +class Xbb_Tags_Bdo extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $dir = ''; switch (strtolower($this->attrib['bdo'])) { case 'ltr': @@ -42,7 +45,7 @@ function get_html($tree = null) { if (isset($this->attrib['lang'])) { $attr .= ' lang="' . htmlspecialchars($this->attrib['lang']) . '"'; } + return '' . parent::get_html() . ''; } } -?> \ No newline at end of file diff --git a/Xbb/Tags/Br.php b/Xbb/Tags/Br.php index ef8104d..120c733 100644 --- a/Xbb/Tags/Br.php +++ b/Xbb/Tags/Br.php @@ -22,11 +22,13 @@ ******************************************************************************/ // Класс для тега [br] -class Xbb_Tags_Br extends bbcode { +class Xbb_Tags_Br extends bbcode +{ public $is_close = true; public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { return '
' . "\n"; } } -?> \ No newline at end of file diff --git a/Xbb/Tags/Caption.php b/Xbb/Tags/Caption.php index eda59cf..89a3e95 100644 --- a/Xbb/Tags/Caption.php +++ b/Xbb/Tags/Caption.php @@ -22,11 +22,13 @@ ******************************************************************************/ // Класс для тега [caption] -class Xbb_Tags_Caption extends bbcode { +class Xbb_Tags_Caption extends bbcode +{ public $behaviour = 'caption'; - function get_html($tree = null) { - return ''.parent::get_html($this -> tree) - .''; + + public function get_html($tree = null) + { + return '' . parent::get_html($this -> tree) + . ''; } } -?> diff --git a/Xbb/Tags/Code.php b/Xbb/Tags/Code.php index 1f9d86c..2309077 100644 --- a/Xbb/Tags/Code.php +++ b/Xbb/Tags/Code.php @@ -22,7 +22,8 @@ ******************************************************************************/ /* Класс для тегов подсветки синтаксиса и для тегов [code] и [pre] */ -class Xbb_Tags_Code extends bbcode { +class Xbb_Tags_Code extends bbcode +{ /* Число разрывов строк, которые должны быть игнорированы перед тегом */ public $lbr = 0; /* Число разрывов строк, которые должны быть игнорированы после тега */ @@ -44,18 +45,22 @@ class Xbb_Tags_Code extends bbcode { ); /* Объект GeSHi */ private $_geshi; + /* Конструктор класса */ - function Xbb_Tags_Code() { + public function __construct() + { $geshi_path = realpath( dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'geshi.php' ); @include_once $geshi_path; - @$this->_geshi = new GeSHi('', 'text'); + $this->_geshi = new GeSHi('', 'text'); $this->_geshi->set_header_type(GESHI_HEADER_NONE); } + /* Описываем конвертацию в HTML */ - function get_html($tree = null) { + public function get_html($tree = null) + { // Находим язык подсветки switch ($this->tag) { case 'code': @@ -66,16 +71,19 @@ function get_html($tree = null) { break; default: $language = $this->tag; + break; } if (! $language) { $language = 'text'; } if (isset($this->lang_synonym[$language])) { $language = $this->lang_synonym[$language]; } - @$this->_geshi->set_language($language); + $this->_geshi->set_language($language); // Находим подсвечиваемый код $source = ''; foreach ($this->tree as $item) { - if ('item' == $item['type']) { continue; } + if ('item' === $item['type']) { + continue; + } $source .= $item['str']; } $this->_geshi->set_source($source); @@ -109,7 +117,7 @@ function get_html($tree = null) { $result = htmlspecialchars($this->attrib['title'], ENT_NOQUOTES); } // Получаем подсвеченный код - $result = '
' .$result + $result = '
' . $result . '
' . $this->_geshi->parse_code(); // Формируем подпись под кодом if (isset($this->attrib['footer'])) { @@ -117,8 +125,8 @@ function get_html($tree = null) { $content = ''; $result .= $content; } + // Возвращаем результат return $result . '
'; } } -?> diff --git a/Xbb/Tags/Color.php b/Xbb/Tags/Color.php index 15a7143..b3cf9ac 100644 --- a/Xbb/Tags/Color.php +++ b/Xbb/Tags/Color.php @@ -22,12 +22,14 @@ ******************************************************************************/ // Класс для тега [color] -class Xbb_Tags_Color extends bbcode { +class Xbb_Tags_Color extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $color = htmlspecialchars($this -> attrib['color']); - return ''.parent::get_html($this -> tree) - .''; + return '' . parent::get_html($this -> tree) + . ''; } } -?> diff --git a/Xbb/Tags/Email.php b/Xbb/Tags/Email.php index 8825bec..8b97f68 100644 --- a/Xbb/Tags/Email.php +++ b/Xbb/Tags/Email.php @@ -22,34 +22,39 @@ ******************************************************************************/ // Класс для тега [email] -class Xbb_Tags_Email extends bbcode { +class Xbb_Tags_Email extends bbcode +{ public $behaviour = 'a'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $this -> autolinks = false; $attr = ' class="bb_email"'; $href = $this -> attrib['email']; if (! $href) { foreach ($this -> tree as $text) { - if ('text' == $text['type']) { $href .= $text['str']; } + if ('text' === $text['type']) { + $href .= $text['str']; + } } } $protocols = array('mailto:'); $is_http = false; foreach ($protocols as $val) { - if ($val == substr($href,0,strlen($val))) { + if ($val === substr($href, 0, strlen($val))) { $is_http = true; break; } } - if (! $is_http) { $href = 'mailto:'.$href; } - if ($href) { $attr .= ' href="'.htmlspecialchars($href).'"'; } + if (! $is_http) { $href = 'mailto:' . $href; } + if ($href) { $attr .= ' href="' . htmlspecialchars($href) . '"'; } $title = isset($this -> attrib['title']) ? $this -> attrib['title'] : ''; - if ($title) { $attr .= ' title="'.htmlspecialchars($title).'"'; } + if ($title) { $attr .= ' title="' . htmlspecialchars($title) . '"'; } $name = isset($this -> attrib['name']) ? $this -> attrib['name'] : ''; - if ($name) { $attr .= ' name="'.htmlspecialchars($name).'"'; } + if ($name) { $attr .= ' name="' . htmlspecialchars($name) . '"'; } $target = isset($this -> attrib['target']) ? $this -> attrib['target'] : ''; - if ($target) { $attr .= ' target="'.htmlspecialchars($target).'"'; } - return ''.parent::get_html($this -> tree).''; + if ($target) { $attr .= ' target="' . htmlspecialchars($target) . '"'; } + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Font.php b/Xbb/Tags/Font.php index e7d1de1..c0a8e94 100644 --- a/Xbb/Tags/Font.php +++ b/Xbb/Tags/Font.php @@ -22,9 +22,12 @@ ******************************************************************************/ // Класс для тега [font] -class Xbb_Tags_Font extends bbcode { +class Xbb_Tags_Font extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attr = ''; if (isset($this -> attrib['face'])) { $face = $this -> attrib['face']; @@ -32,13 +35,13 @@ function get_html($tree = null) { $face = $this -> attrib['font']; } if ($face) { - $attr .= ' face="'.htmlspecialchars($face).'"'; + $attr .= ' face="' . htmlspecialchars($face) . '"'; } $color = isset($this -> attrib['color']) ? $this -> attrib['color'] : ''; - if ($color) { $attr .= ' color="'.htmlspecialchars($color).'"'; } + if ($color) { $attr .= ' color="' . htmlspecialchars($color) . '"'; } $size = isset($this -> attrib['size']) ? $this -> attrib['size'] : ''; - if ($size) { $attr .= ' size="'.htmlspecialchars($size).'"'; } - return ''.parent::get_html($this -> tree).''; + if ($size) { $attr .= ' size="' . htmlspecialchars($size) . '"'; } + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Google.php b/Xbb/Tags/Google.php index 7a67773..249f3cd 100644 --- a/Xbb/Tags/Google.php +++ b/Xbb/Tags/Google.php @@ -22,18 +22,22 @@ ******************************************************************************/ // Класс для тега [google] -class Xbb_Tags_Google extends bbcode { +class Xbb_Tags_Google extends bbcode +{ public $behaviour = 'a'; - function get_html($tree = null) { + + public function get_html($tree = null) + { + //TODO:нужен ли htmlspecialchars? $attr = htmlspecialchars(rawurlencode($this -> attrib['google'])); - $attr = ' href="http://www.google.com/search?q='.$attr.'"'; + $attr = ' href="http://www.google.com/search?q=' . $attr . '"'; $title = isset($this -> attrib['title']) ? $this -> attrib['title'] : ''; - if ($title) { $attr .= ' title="'.htmlspecialchars($title).'"'; } + if ($title) { $attr .= ' title="' . htmlspecialchars($title) . '"'; } $name = isset($this -> attrib['name']) ? $this -> attrib['name'] : ''; - if ($name) { $attr .= ' name="'.htmlspecialchars($name).'"'; } + if ($name) { $attr .= ' name="' . htmlspecialchars($name) . '"'; } $target = isset($this -> attrib['target']) ? $this -> attrib['target'] : ''; - if ($target) { $attr .= ' target="'.htmlspecialchars($target).'"'; } - return ''.parent::get_html($this -> tree).''; + if ($target) { $attr .= ' target="' . htmlspecialchars($target) . '"'; } + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Hr.php b/Xbb/Tags/Hr.php index 78c39d7..15dbad2 100644 --- a/Xbb/Tags/Hr.php +++ b/Xbb/Tags/Hr.php @@ -22,12 +22,14 @@ ******************************************************************************/ // Класс для тега [hr] -class Xbb_Tags_Hr extends bbcode { +class Xbb_Tags_Hr extends bbcode +{ public $is_close = true; public $rbr = 1; public $behaviour = 'hr'; - function get_html($tree = null) { + + public function get_html($tree = null) + { return '
'; } } -?> diff --git a/Xbb/Tags/Img.php b/Xbb/Tags/Img.php index d1d7039..3e562a0 100644 --- a/Xbb/Tags/Img.php +++ b/Xbb/Tags/Img.php @@ -22,28 +22,34 @@ ******************************************************************************/ // Класс для тега [img] -class Xbb_Tags_Img extends bbcode { +class Xbb_Tags_Img extends bbcode +{ public $behaviour = 'img'; - function get_html($tree = null) { + + public function get_html($tree = null) + { + //TODO:добавить аттрибуты alt и title $attr = 'alt=""'; if (isset($this -> attrib['width'])) { $width = (int) $this -> attrib['width']; - $attr .= $width ? ' width="'.$width.'"' : ''; + $attr .= $width ? ' width="' . $width . '"' : ''; } if (isset($this -> attrib['height'])) { $height = (int) $this -> attrib['height']; - $attr .= $height ? ' height="'.$height.'"' : ''; + $attr .= $height ? ' height="' . $height . '"' : ''; } if (isset($this -> attrib['border'])) { $border = (int) $this -> attrib['border']; - $attr .= ' border="'.$border.'"'; + $attr .= ' border="' . $border . '"'; } $src = ''; foreach ($this -> tree as $text) { - if ('text' == $text['type']) { $src .= $text['str']; } + if ('text' === $text['type']) { + $src .= $text['str']; + } } - $src = $this -> checkUrl($src); - return ''; + $src = $this -> _checkUrl($src); + + return ''; } } -?> diff --git a/Xbb/Tags/Li.php b/Xbb/Tags/Li.php index 8b1dd89..6ca5cb5 100644 --- a/Xbb/Tags/Li.php +++ b/Xbb/Tags/Li.php @@ -22,15 +22,18 @@ ******************************************************************************/ // Класс для тега [*] -class Xbb_Tags_Li extends bbcode { +class Xbb_Tags_Li extends bbcode +{ public $behaviour = 'li'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attrib = 'class="bb"'; if ('' !== $this -> attrib['*']) { $this -> attrib['*'] = (int) $this -> attrib['*']; - $attrib .= ' value="'.$this -> attrib['*'].'"'; + $attrib .= ' value="' . $this -> attrib['*'] . '"'; } - return '
  • '.parent::get_html($this -> tree).'
  • '; + + return '
  • ' . parent::get_html($this -> tree) . '
  • '; } } -?> diff --git a/Xbb/Tags/List.php b/Xbb/Tags/List.php index 1f6acd9..4af7a98 100644 --- a/Xbb/Tags/List.php +++ b/Xbb/Tags/List.php @@ -22,11 +22,14 @@ ******************************************************************************/ // Класс для тегов [list], [ol], [ul] -class Xbb_Tags_List extends bbcode { +class Xbb_Tags_List extends bbcode +{ public $lbr = 1; public $rbr = 1; public $behaviour = 'ul'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $tag_name = 'ul'; $type = ''; switch ($this->tag) { @@ -42,14 +45,13 @@ function get_html($tree = null) { $this->tag = 'del'; } $attr = ' class="bb"'; - if ('1' == $type) { + if ('1' === $type) { $attr .= ' type="1"'; } elseif ($type) { $attr .= ' type="a"'; } - $str = '<' . $tag_name . $attr . '>' . parent::get_html() . '' . parent::get_html() . ''; - return $str; } } -?> diff --git a/Xbb/Tags/Nobb.php b/Xbb/Tags/Nobb.php index 5b29f04..46d6c03 100644 --- a/Xbb/Tags/Nobb.php +++ b/Xbb/Tags/Nobb.php @@ -22,9 +22,12 @@ ******************************************************************************/ // Класс для тега [nobb] -class Xbb_Tags_Nobb extends bbcode { +class Xbb_Tags_Nobb extends bbcode +{ public $behaviour = 'code'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $str = ''; foreach ($this -> tree as $item) { if ('text' === $item['type']) { @@ -32,7 +35,7 @@ function get_html($tree = null) { } } $str = str_replace(' ', '  ', $str); + return $str; } } -?> diff --git a/Xbb/Tags/P.php b/Xbb/Tags/P.php index ca8c72c..52fb76f 100644 --- a/Xbb/Tags/P.php +++ b/Xbb/Tags/P.php @@ -22,15 +22,18 @@ ******************************************************************************/ // Класс для тега [p] и тегов [h1], [h2], [h3], [h4], [h5], [h6]. -class Xbb_Tags_P extends bbcode { +class Xbb_Tags_P extends bbcode +{ public $lbr = 2; public $rbr = 2; public $behaviour = 'p'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $str = "\n<" . $this->tag . ' class="bb"'; $align = isset($this->attrib['align']) ? $this->attrib['align'] : ''; - if ($align) { $str .= ' align="'.htmlspecialchars($align).'"'; } + if ($align) { $str .= ' align="' . htmlspecialchars($align) . '"'; } + return $str . '>' . parent::get_html() . 'tag . ">\n"; } } -?> diff --git a/Xbb/Tags/Quote.php b/Xbb/Tags/Quote.php index 1fe9553..cde7dfb 100644 --- a/Xbb/Tags/Quote.php +++ b/Xbb/Tags/Quote.php @@ -22,19 +22,22 @@ ******************************************************************************/ // Класс для тегов [quote] и [blockquote] -class Xbb_Tags_Quote extends bbcode { +class Xbb_Tags_Quote extends bbcode +{ public $rbr = 1; - function get_html($tree = null) { - if ('blockquote' == $this->tag) { - $author = htmlspecialchars($this->attrib['blockquote']); + + public function get_html($tree = null) + { + if ('blockquote' === $this->tag) { + $author = htmlspecialchars($this->attrib['blockquote'], ENT_NOQUOTES); } else { - $author = htmlspecialchars($this->attrib['quote']); + $author = htmlspecialchars($this->attrib['quote'], ENT_NOQUOTES); } if ($author) { $author = '
    ' . $author . '
    '; } + return '
    ' . $author . parent::get_html($this -> tree) . '
    '; } } -?> diff --git a/Xbb/Tags/Simple.php b/Xbb/Tags/Simple.php index 9527d3e..1d7650f 100644 --- a/Xbb/Tags/Simple.php +++ b/Xbb/Tags/Simple.php @@ -22,9 +22,12 @@ ******************************************************************************/ // Класс для простейших тегов -class Xbb_Tags_Simple extends bbcode { +class Xbb_Tags_Simple extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { switch ($this->tag) { case 'b': $this->tag = 'strong'; @@ -33,9 +36,8 @@ function get_html($tree = null) { case 'strike': $this->tag = 'del'; } - $html = '<' . $this->tag . ' class="bb">' . parent::get_html() . 'tag . ' class="bb">' . parent::get_html() . 'tag . '>'; - return $html; } } -?> \ No newline at end of file diff --git a/Xbb/Tags/Size.php b/Xbb/Tags/Size.php index c05e5c5..ec51ebb 100644 --- a/Xbb/Tags/Size.php +++ b/Xbb/Tags/Size.php @@ -22,14 +22,17 @@ ******************************************************************************/ // Класс для тега [size] -class Xbb_Tags_Size extends bbcode { +class Xbb_Tags_Size extends bbcode +{ public $behaviour = 'span'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $sign = ''; if (strlen($this -> attrib['size'])) { $sign = $this -> attrib['size']{0}; } - if ('+' != $sign) { $sign = ''; } + if ('+' !== $sign) { $sign = ''; } $size = (int) $this -> attrib['size']; if (7 < $size) { $size = 7; @@ -42,8 +45,8 @@ function get_html($tree = null) { if (0 == $size) { $size = 3; } - $size = $sign.$size; - return ''.parent::get_html($this -> tree).''; + $size = $sign . $size; + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Table.php b/Xbb/Tags/Table.php index 580e235..f500421 100644 --- a/Xbb/Tags/Table.php +++ b/Xbb/Tags/Table.php @@ -22,33 +22,38 @@ ******************************************************************************/ // Класс для тега [table] -class Xbb_Tags_Table extends bbcode { +class Xbb_Tags_Table extends bbcode +{ public $rbr = 1; public $behaviour = 'table'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attr = ' class="bb"'; $border = isset($this -> attrib['border']) ? (int) $this -> attrib['border'] : null; - if (null !== $border) { $attr .= ' border="'.$border.'"'; } + if (null !== $border) { $attr .= ' border="' . $border . '"'; } $width = isset($this -> attrib['width']) ? $this -> attrib['width'] : ''; - if ($width) { $attr .= ' width="'.htmlspecialchars($width).'"'; } + if ($width) { $attr .= ' width="' . htmlspecialchars($width) . '"'; } $cellspacing = isset($this -> attrib['cellspacing']) ? (int) $this -> attrib['cellspacing'] : null; - if (null !== $cellspacing) { $attr .= ' cellspacing="'.$cellspacing.'"'; } + if (null !== $cellspacing) { $attr .= ' cellspacing="' . $cellspacing . '"'; } $cellpadding = isset($this -> attrib['cellpadding']) ? (int) $this -> attrib['cellpadding'] : null; - if (null !== $cellpadding) { $attr .= ' cellpadding="'.$cellpadding.'"'; } + if (null !== $cellpadding) { $attr .= ' cellpadding="' . $cellpadding . '"'; } $align = isset($this -> attrib['align']) ? $this -> attrib['align'] : ''; - if ($align) { $attr .= ' align="'.htmlspecialchars($align).'"'; } - $str = ''; + if ($align) { $attr .= ' align="' . htmlspecialchars($align) . '"'; } + $str = ''; foreach ($this -> tree as $key => $item) { - if ('text' == $item['type']) { unset($this -> tree[$key]); } + if ('text' === $item['type']) { + unset($this -> tree[$key]); + } } - $str .= parent::get_html($this -> tree).''; + $str .= parent::get_html($this -> tree) . ''; + return $str; } } -?> diff --git a/Xbb/Tags/Td.php b/Xbb/Tags/Td.php index ae3ef84..8d63491 100644 --- a/Xbb/Tags/Td.php +++ b/Xbb/Tags/Td.php @@ -22,27 +22,34 @@ ******************************************************************************/ // Класс для тега [td] -class Xbb_Tags_Td extends bbcode { +class Xbb_Tags_Td extends bbcode +{ public $behaviour = 'td'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attr = 'class="bb"'; $width = isset($this -> attrib['width']) ? $this -> attrib['width'] : ''; - if ($width) { $attr .= ' width="'.htmlspecialchars($width).'"'; } + if ($width) { $attr .= ' width="' . htmlspecialchars($width) . '"'; } $height = isset($this -> attrib['height']) ? $this -> attrib['height'] : ''; - if ($height) { $attr .= ' height="'.htmlspecialchars($height).'"'; } + if ($height) { $attr .= ' height="' . htmlspecialchars($height) . '"'; } $align = isset($this -> attrib['align']) ? $this -> attrib['align'] : ''; - if ($align) { $attr .= ' align="'.htmlspecialchars($align).'"'; } + if ($align) { $attr .= ' align="' . htmlspecialchars($align) . '"'; } $valign = isset($this -> attrib['valign']) ? $this -> attrib['valign'] : ''; - if ($valign) { $attr .= ' valign="'.htmlspecialchars($valign).'"'; } + if ($valign) { $attr .= ' valign="' . htmlspecialchars($valign) . '"'; } if (isset($this -> attrib['colspan'])) { $colspan = (int) $this -> attrib['colspan']; - if ($colspan) { $attr .= ' colspan="'.$colspan.'"'; } + if ($colspan) { + $attr .= ' colspan="' . $colspan . '"'; + } } if (isset($this -> attrib['rowspan'])) { $rowspan = (int) $this -> attrib['rowspan']; - if ($rowspan) { $attr .= ' rowspan="'.$rowspan.'"'; } + if ($rowspan) { + $attr .= ' rowspan="' . $rowspan . '"'; + } } - return ''.parent::get_html($this -> tree).''; + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Th.php b/Xbb/Tags/Th.php index 6debc7e..900af8a 100644 --- a/Xbb/Tags/Th.php +++ b/Xbb/Tags/Th.php @@ -22,27 +22,34 @@ ******************************************************************************/ // Класс для тега [th] -class Xbb_Tags_Th extends bbcode { +class Xbb_Tags_Th extends bbcode +{ public $behaviour = 'td'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $attr = ' class="bb"'; $width = isset($this -> attrib['width']) ? $this -> attrib['width'] : ''; - if ($width) { $attr .= ' width="'.htmlspecialchars($width).'"'; } + if ($width) { $attr .= ' width="' . htmlspecialchars($width) . '"'; } $height = isset($this -> attrib['height']) ? $this -> attrib['height'] : ''; - if ($height) { $attr .= ' height="'.htmlspecialchars($height).'"'; } + if ($height) { $attr .= ' height="' . htmlspecialchars($height) . '"'; } $align = isset($this -> attrib['align']) ? $this -> attrib['align'] : ''; - if ($align) { $attr .= ' align="'.htmlspecialchars($align).'"'; } + if ($align) { $attr .= ' align="' . htmlspecialchars($align) . '"'; } $valign = isset($this -> attrib['valign']) ? $this -> attrib['valign'] : ''; - if ($valign) { $attr .= ' valign="'.htmlspecialchars($valign).'"'; } + if ($valign) { $attr .= ' valign="' . htmlspecialchars($valign) . '"'; } if (isset($this -> attrib['colspan'])) { $colspan = (int) $this -> attrib['colspan']; - if ($colspan) { $attr .= ' colspan="'.$colspan.'"'; } + if ($colspan) { + $attr .= ' colspan="' . $colspan . '"'; + } } if (isset($this -> attrib['rowspan'])) { $rowspan = (int) $this -> attrib['rowspan']; - if ($rowspan) { $attr .= ' rowspan="'.$rowspan.'"'; } + if ($rowspan) { + $attr .= ' rowspan="' . $rowspan . '"'; + } } - return ''.parent::get_html($this -> tree).''; + + return '' . parent::get_html($this -> tree) . ''; } } -?> diff --git a/Xbb/Tags/Tr.php b/Xbb/Tags/Tr.php index a9bfd3d..c491efe 100644 --- a/Xbb/Tags/Tr.php +++ b/Xbb/Tags/Tr.php @@ -22,15 +22,20 @@ ******************************************************************************/ // Класс для тега [tr] -class Xbb_Tags_Tr extends bbcode { +class Xbb_Tags_Tr extends bbcode +{ public $behaviour = 'tr'; - function get_html($tree = null) { + + public function get_html($tree = null) + { $str = ''; foreach ($this -> tree as $key => $item) { - if ('text' == $item['type']) { unset($this -> tree[$key]); } + if ('text' === $item['type']) { + unset($this -> tree[$key]); + } } - $str .= parent::get_html($this -> tree).''; + $str .= parent::get_html($this -> tree) . ''; + return $str; } } -?> diff --git a/bbcode.lib.js b/bbcode.lib.js index 731af2b..73b3e2d 100644 --- a/bbcode.lib.js +++ b/bbcode.lib.js @@ -33,12 +33,12 @@ function bbcode(code) { pattern : [ /(\w+:\/\/[A-z0-9\.\?\+\-\/_=&%#:;]+[\w/=]+)/, /([^/])(www\.[A-z0-9\.\?\+\-/_=&%#:;]+[\w/=]+)/, - /([\w]+[\w\-\.]+@[\w\-\.]+\.[\w]+)/, + /([\w]+[\w\-\.]+@[\w\-\.]+\.[\w]+)/ ], highlight : [ '<' + 'span class="bb_autolink">$1<' + '/span>', '$1<' + 'span class="bb_autolink">$2<' + '/span>', - '<' + 'span class="bb_autolink">$1<' + '/span>', + '<' + 'span class="bb_autolink">$1<' + '/span>' ] }; /* Подсвечиваемые смайлики и прочие мнемоники. */ @@ -154,7 +154,7 @@ function bbcode(code) { token_type = 8; } return [token_type, token]; - } + }; this.parse = function(code) { if (code) { this.text = code; } @@ -414,7 +414,7 @@ function bbcode(code) { }; } } - } + }; this.highlight = function() { var chars = [ @@ -497,7 +497,7 @@ function bbcode(code) { str = this.nl2br(str); str = str.replace(/\s\s/, '  '); return str; - } + }; /* Текстовое содержимое узла с заменой
    на разрыв строки и окрыжением @@ -508,7 +508,7 @@ function bbcode(code) { return node.innerText; } if (node.textContent) { - for (var t = [], l = (c = node.childNodes).length, p, i = 0; i < l; i++) { + for (var c, t = [], l = (c = node.childNodes).length, p, i = 0; i < l; i++) { t[t.length] = 'p' == (p = c[i].nodeName.toLowerCase()) ? '\n' + c[i].textContent + '\n' @@ -517,7 +517,7 @@ function bbcode(code) { return t.join(''); } return ''; - } + }; /* Аналог функции in_array в PHP */ this.in_array = function(needle, haystack) { @@ -527,7 +527,7 @@ function bbcode(code) { } } return false; - } + }; /* Аналог функции nl2br в PHP */ this.nl2br = function(str) { @@ -535,7 +535,7 @@ function bbcode(code) { return str.replace(/(\r\n)|(\n\r)|\r|\n/g, '
    '); } return str; - } + }; /* Аналог функции htmlspecialchars в PHP */ this.htmlspecialchars = function(str) { @@ -545,7 +545,7 @@ function bbcode(code) { str = str.replace(//g, '>'); return str - } + }; /* Аналог функции strtr в PHP @@ -555,18 +555,18 @@ function bbcode(code) { */ this.strtr = function(str, pairs, to) { if ((typeof(pairs)=="object") && (pairs.length)) { - for (i in pairs) { - str = str.replace(RegExp(pairs[i][0], "g"), pairs[i][1]); + for (var i in pairs) { + str = str.replace(new RegExp(pairs[i][0], "g"), pairs[i][1]); } return str; } else { - pairs2 = new Array(); + var pairs2 = new Array(); for (i = 0; i < pairs.length; i++) { pairs2[i] = [pairs.substr(i,1), to.substr(i,1)]; } return strtr(str, pairs2); } - } + }; this.parse(); } @@ -708,53 +708,50 @@ function doinsert(text1, text2) { function tag_url() { -var FoundErrors = ''; -var enterURL = prompt(text_enter_url, "http://"); -var enterTITLE = prompt(text_enter_url_name, "My WebPage"); + var FoundErrors = ''; + var enterURL = prompt(text_enter_url, "http://"); + var enterTITLE = prompt(text_enter_url_name, "My WebPage"); -if (!enterURL || enterURL=='http://') {FoundErrors = 1;} -else if (!enterTITLE) {FoundErrors = 1;} + if (!enterURL || enterURL=='http://') {FoundErrors = 1;} + else if (!enterTITLE) {FoundErrors = 1;} -if (FoundErrors) {return;} + if (FoundErrors) {return;} -doinsert ('[url=' + enterURL + ']'+enterTITLE, '[/url]'); + doinsert ('[url=' + enterURL + ']'+enterTITLE, '[/url]'); } function tag_email() { -var emailAddress = prompt(text_enter_email, ""); + var emailAddress = prompt(text_enter_email, ""); -if (!emailAddress) {return;} + if (!emailAddress) {return;} -doinsert("[email]"+emailAddress,"[/email]"); + doinsert("[email]"+emailAddress,"[/email]"); } function tag_image() { -var FoundErrors = ''; -var enterURL = prompt(text_enter_image, "http://"); + var FoundErrors = ''; + var enterURL = prompt(text_enter_image, "http://"); -if (!enterURL || enterURL=='http://' || enterURL.length<10) {return;} + if (!enterURL || enterURL=='http://' || enterURL.length<10) {return;} -doinsert("[img]"+enterURL,"[/img]"); + doinsert("[img]"+enterURL,"[/img]"); } function tag_list() { -var listvalue = "init"; -var thelist = ""; + var listvalue = "init"; + var thelist = ""; -while ( (listvalue != "") && (listvalue != null) ) -{ -listvalue = prompt(list_prompt, ""); -if ( (listvalue != "") && (listvalue != null) ) -{ -thelist = thelist+"[*]"+listvalue+"\n"; -} -} + while ( (listvalue != "") && (listvalue != null) ) { + listvalue = prompt(list_prompt, ""); + if ( (listvalue != "") && (listvalue != null) ) { + thelist = thelist+"[*]"+listvalue+"\n"; + } + } -if ( thelist != "" ) -{ -doinsert( "[list]\n" + thelist, "[/list]\n"); -} + if ( thelist != "" ) { + doinsert( "[list]\n" + thelist, "[/list]\n"); + } } diff --git a/bbcode.lib.php b/bbcode.lib.php index a2745e0..c9c5ece 100644 --- a/bbcode.lib.php +++ b/bbcode.lib.php @@ -21,7 +21,8 @@ * * ******************************************************************************/ -class bbcode { +class bbcode +{ /* Имя тега, которому сопоставлен экземпляр класса. Пустая строка, если экземпляр не сопоставлен никакому тегу. @@ -130,19 +131,25 @@ class bbcode { */ private $_ends; - /* Конструктор класса */ - function bbcode($code = '') { + /** + * Конструктор класса + * + * @param array|string $code + */ + public function __construct ($code = null) + { $this->_current_path = dirname(__FILE__) . DIRECTORY_SEPARATOR; - include $this->_current_path . 'config' . DIRECTORY_SEPARATOR . 'parser.config.php'; - include $this->_current_path . 'config' . DIRECTORY_SEPARATOR . 'tags.php'; + require $this->_current_path . 'config' . DIRECTORY_SEPARATOR . 'parser.config.php'; + require $this->_current_path . 'config' . DIRECTORY_SEPARATOR . 'tags.php'; $this->tags = $tags; $this->_children = $children; $this->_ends = $ends; $this->parse($code); } + /* - get_token() - Функция парсит текст BBCode и возвращает очередную пару + _get_token() - Функция парсит текст BBCode и возвращает очередную пару "число (тип лексемы) - лексема" @@ -156,12 +163,36 @@ function bbcode($code = '') { 3 - апостроф ("'") 4 - равенство ("=") 5 - прямой слэш ("/") - 6 - последовательность пробельных символов (кроме пробела) - ("\t", "\n", "\r", "\0" или "\x0B") + 6 - последовательность пробельных символов + " ", "\t", "\n", "\r", "\0" или "\x0B") 7 - последовательность прочих символов, не являющаяся именем тега 8 - имя тега */ - function get_token() { + + /** + * _get_token() - Функция парсит текст BBCode и возвращает очередную пару + * + * "число (тип лексемы) - лексема" + * + * Лексема - подстрока строки $this -> text, начинающаяся с позиции + * $this -> _cursor + * Типы лексем могут быть следующие: + * + * 0 - открывющая квадратная скобка ("[") + * 1 - закрывающая квадратная cкобка ("]") + * 2 - двойная кавычка ('"') + * 3 - апостроф ("'") + * 4 - равенство ("=") + * 5 - прямой слэш ("/") + * 6 - последовательность пробельных символов + * (" ", "\t", "\n", "\r", "\0" или "\x0B") + * 7 - последовательность прочих символов, не являющаяся именем тега + * 8 - имя тега + * + * @return array|bool + */ + protected function _get_token() + { $token = ''; $token_type = false; $char_type = false; @@ -194,9 +225,9 @@ function get_token() { case '/': $char_type = 5; break; - //case ' ': - // $char_type = 6; - // break; + case ' ': + $char_type = 6; + break; case "\t": $char_type = 6; break; @@ -233,21 +264,29 @@ function get_token() { return array($token_type, $token); } - function parse($code = null) { + + /** + * Парсер + * + * @param array|string $code + * @return array + */ + public function parse($code = null) + { $time_start = $this->_getmicrotime(); if (is_array($code)) { $is_tree = false; foreach ($code as $val) { if (isset($val['val'])) { $this->tree = $code; - $this->syntax = $this->get_syntax(); + $this->syntax = $this->_get_syntax(); $is_tree = true; break; } } if (! $is_tree) { $this->syntax = $code; - $this->get_tree(); + $this->_get_tree(); } $this->text = ''; foreach ($this->syntax as $val) { @@ -335,7 +374,7 @@ function parse($code = null) { $type = false; $this ->_cursor = 0; // Сканируем массив лексем с помощью построенного автомата: - while ($token = $this -> get_token()) { + while ($token = $this -> _get_token()) { $previous_mode = $mode; $mode = $finite_automaton[$previous_mode][$token[0]]; if (-1 < $token_key) { @@ -489,7 +528,7 @@ function parse($code = null) { break; } } - if (count($decomposition)) { + if ($decomposition) { if ('text' === $type) { $this -> syntax[$token_key]['str'] .= $decomposition['str']; } else { @@ -499,12 +538,20 @@ function parse($code = null) { ); } } - $this->get_tree(); + $this->_get_tree(); $this->stat['time_parse'] = $this->_getmicrotime() - $time_start; return $this->syntax; } - function specialchars($string) { + + /** + * _specialchars + * + * @param $string + * @return string + */ + protected function _specialchars($string) + { $chars = array( '[' => '@l;', ']' => '@r;', @@ -515,7 +562,15 @@ function specialchars($string) { return strtr($string, $chars); } - function unspecialchars($string) { + + /** + * _unspecialchars + * + * @param $string + * @return string + */ + protected function _unspecialchars($string) + { $chars = array( '@l;' => '[', '@r;' => ']', @@ -526,11 +581,17 @@ function unspecialchars($string) { return strtr($string, $chars); } - /* - Функция проверяет, должен ли тег с именем $current закрыться, если - начинается тег с именем $next. - */ - function must_close_tag($current, $next) { + + /** + * Функция проверяет, должен ли тег с именем $current закрыться, + * если начинается тег с именем $next. + * + * @param string $current + * @param string $next + * @return bool + */ + protected function _must_close_tag($current, $next) + { if (isset($this -> tags[$current])) { $this->_includeTagFile($current); $class_vars = get_class_vars($this -> tags[$current]); @@ -552,13 +613,19 @@ function must_close_tag($current, $next) { return $must_close; } - /* - Возвращает true, если тег с именем $parent может иметь непосредственным - потомком тег с именем $child. В противном случае - false. - Если $parent - пустая строка, то проверяется, разрешено ли $child входить в - корень дерева BBCode. - */ - function isPermissiblyChild($parent, $child) { + + /** + * Возвращает true, если тег с именем $parent может иметь непосредственным + * потомком тег с именем $child. В противном случае - false. + * Если $parent - пустая строка, то проверяется, разрешено ли $child входить в + * корень дерева BBCode. + * + * @param string $parent + * @param string $child + * @return bool + */ + protected function _isPermissiblyChild($parent, $child) + { $parent = (string) $parent; $child = (string) $child; if (isset($this -> tags[$parent])) { @@ -584,7 +651,15 @@ function isPermissiblyChild($parent, $child) { return $permissibly; } - function normalize_bracket($syntax) { + + /** + * _normalize_bracket + * + * @param array $syntax + * @return array + */ + protected function _normalize_bracket($syntax) + { $structure = array(); $structure_key = -1; $level = 0; @@ -593,7 +668,7 @@ function normalize_bracket($syntax) { unset($val['layout']); switch ($val['type']) { case 'text': - $val['str'] = $this -> unspecialchars($val['str']); + $val['str'] = $this -> _unspecialchars($val['str']); $type = (-1 < $structure_key) ? $structure[$structure_key]['type'] : false; if ('text' === $type) { @@ -605,10 +680,10 @@ function normalize_bracket($syntax) { break; case 'open/close': $val['attrib'] = array_map( - array(&$this, 'unspecialchars'), $val['attrib'] + array($this, '_unspecialchars'), $val['attrib'] ); - foreach (array_reverse($open_tags,true) as $ult_key => $ultimate) { - if ($this -> must_close_tag($ultimate, $val['name'])) { + foreach (array_reverse($open_tags, true) as $ult_key => $ultimate) { + if ($this -> _must_close_tag($ultimate, $val['name'])) { $structure[++$structure_key] = array( 'type' => 'close', 'name' => $ultimate, @@ -626,10 +701,10 @@ function normalize_bracket($syntax) { case 'open': $this->_includeTagFile($val['name']); $val['attrib'] = array_map( - array(&$this, 'unspecialchars'), $val['attrib'] + array($this, '_unspecialchars'), $val['attrib'] ); - foreach (array_reverse($open_tags,true) as $ult_key => $ultimate) { - if ($this -> must_close_tag($ultimate, $val['name'])) { + foreach (array_reverse($open_tags, true) as $ult_key => $ultimate) { + if ($this -> _must_close_tag($ultimate, $val['name'])) { $structure[++$structure_key] = array( 'type' => 'close', 'name' => $ultimate, @@ -637,7 +712,9 @@ function normalize_bracket($syntax) { 'level' => --$level ); unset($open_tags[$ult_key]); - } else { break; } + } else { + break; + } } $class_vars = get_class_vars($this -> tags[$val['name']]); if ($class_vars['is_close']) { @@ -651,7 +728,7 @@ function normalize_bracket($syntax) { } break; case 'close': - if (! count($open_tags)) { + if (!$open_tags) { $type = (-1 < $structure_key) ? $structure[$structure_key]['type'] : false; if ( 'text' === $type ) { @@ -674,7 +751,7 @@ function normalize_bracket($syntax) { unset($open_tags[$ult_key]); break; } - if (! in_array($val['name'],$open_tags)) { + if (! in_array($val['name'], $open_tags)) { $type = (-1 < $structure_key) ? $structure[$structure_key]['type'] : false; if ('text' === $type) { @@ -688,7 +765,7 @@ function normalize_bracket($syntax) { } break; } - foreach (array_reverse($open_tags,true) as $ult_key => $ultimate) { + foreach (array_reverse($open_tags, true) as $ult_key => $ultimate) { if ($ultimate != $val['name']) { $structure[++$structure_key] = array( 'type' => 'close', @@ -706,7 +783,7 @@ function normalize_bracket($syntax) { unset($open_tags[$ult_key]); } } - foreach (array_reverse($open_tags,true) as $ult_key => $ultimate) { + foreach (array_reverse($open_tags, true) as $ult_key => $ultimate) { $structure[++$structure_key] = array( 'type' => 'close', 'name' => $ultimate, @@ -718,9 +795,16 @@ function normalize_bracket($syntax) { return $structure; } - function get_tree() { + + /** + * _get_tree + * + * @return array + */ + protected function _get_tree() + { /* Превращаем $this -> syntax в правильную скобочную структуру */ - $structure = $this -> normalize_bracket($this -> syntax); + $structure = $this -> _normalize_bracket($this -> syntax); /* Отслеживаем, имеют ли элементы неразрешенные подэлементы. Соответственно этому исправляем $structure. */ $normalized = array(); @@ -743,10 +827,9 @@ function get_tree() { break; case 'open/close': $this->_includeTagFile($val['name']); - $is_open = count($open_tags); end($open_tags); - $parent = $is_open ? current($open_tags) : $this->tag; - $permissibly = $this->isPermissiblyChild($parent, $val['name']); + $parent = $open_tags ? current($open_tags) : $this->tag; + $permissibly = $this->_isPermissiblyChild($parent, $val['name']); if (! $permissibly) { $type = (-1 < $normal_key) ? $normalized[$normal_key]['type'] : false; @@ -767,10 +850,9 @@ function get_tree() { break; case 'open': $this->_includeTagFile($val['name']); - $is_open = count($open_tags); end($open_tags); - $parent = $is_open ? current($open_tags) : $this->tag; - $permissibly = $this->isPermissiblyChild($parent, $val['name']); + $parent = $open_tags ? current($open_tags) : $this->tag; + $permissibly = $this->_isPermissiblyChild($parent, $val['name']); if (! $permissibly) { $not_tags[$val['level']] = $val['name']; $type = (-1 < $normal_key) @@ -834,7 +916,7 @@ function get_tree() { ); break; } - $open_tags[$val['level']-1]['val'][] = array( + $open_tags[$val['level'] - 1]['val'][] = array( 'type' => 'text', 'str' => $val['str'] ); @@ -849,7 +931,7 @@ function get_tree() { ); break; } - $open_tags[$val['level']-1]['val'][] = array( + $open_tags[$val['level'] - 1]['val'][] = array( 'type' => 'item', 'name' => $val['name'], 'attrib' => $val['attrib'], @@ -870,7 +952,7 @@ function get_tree() { unset($open_tags[0]); break; } - $open_tags[$val['level']-1]['val'][] = $open_tags[$val['level']]; + $open_tags[$val['level'] - 1]['val'][] = $open_tags[$val['level']]; unset($open_tags[$val['level']]); break; } @@ -882,23 +964,31 @@ function get_tree() { return $result; } - function get_syntax($tree = false) { + + /** + * _get_syntax + * + * @param bool|array $tree + * @return array + */ + function _get_syntax($tree = false) + { if (! is_array($tree)) { $tree = $this -> tree; } $syntax = array(); foreach ($tree as $elem) { - if ('text' == $elem['type']) { + if ('text' === $elem['type']) { $syntax[] = array( 'type' => 'text', - 'str' => $this -> specialchars($elem['str']) + 'str' => $this -> _specialchars($elem['str']) ); } else { - $sub_elems = $this -> get_syntax($elem['val']); + $sub_elems = $this -> _get_syntax($elem['val']); $str = ''; $layout = array(array(0, '[')); foreach ($elem['attrib'] as $name => $val) { - $val = $this -> specialchars($val); + $val = $this -> _specialchars($val); if ($str) { $str .= ' '; $layout[] = array(4, ' '); @@ -908,15 +998,15 @@ function get_syntax($tree = false) { } $str .= $name; if ($val) { - $str .= '="'.$val.'"'; + $str .= '="' . $val . '"'; $layout[] = array(3, '='); $layout[] = array(5, '"'); $layout[] = array(7, $val); $layout[] = array(5, '"'); } } - if (count($sub_elems)) { - $str = '['.$str.']'; + if ($sub_elems) { + $str = '[' . $str . ']'; } else { $str = '['.$str.' /]'; $layout[] = array(4, ' '); @@ -924,17 +1014,19 @@ function get_syntax($tree = false) { } $layout[] = array(0, ']'); $syntax[] = array( - 'type' => count($sub_elems) ? 'open' : 'open/close', + 'type' => $sub_elems ? 'open' : 'open/close', 'str' => $str, 'name' => $elem['name'], 'attrib' => $elem['attrib'], 'layout' => $layout ); - foreach ($sub_elems as $sub_elem) { $syntax[] = $sub_elem; } - if (count($sub_elems)) { + foreach ($sub_elems as $sub_elem) { + $syntax[] = $sub_elem; + } + if ($sub_elems) { $syntax[] = array( 'type' => 'close', - 'str' => '[/'.$elem['name'].']', + 'str' => '[/' . $elem['name'] . ']', 'name' => $elem['name'], 'layout' => array( array(0, '['), @@ -949,8 +1041,16 @@ function get_syntax($tree = false) { return $syntax; } - function insert_smiles($text) { - $text = htmlspecialchars($text,ENT_NOQUOTES); + + /** + * insert_smiles + * + * @param string $text + * @return string + */ + public function insert_smiles($text) + { + $text = htmlspecialchars($text, ENT_NOQUOTES); if ($this -> autolinks) { $search = $this -> preg_autolinks['pattern']; $replace = $this -> preg_autolinks['replacement']; @@ -961,7 +1061,14 @@ function insert_smiles($text) { return $text; } - function highlight() { + + /** + * highlight + * + * @return string + */ + public function highlight() + { $time_start = $this -> _getmicrotime(); $chars = array( '@l;' => '@l;', @@ -973,13 +1080,13 @@ function highlight() { $search = $this -> preg_autolinks['pattern']; $replace = $this -> preg_autolinks['highlight']; $str = ''; - foreach($this -> syntax as $elem) { - if ('text' == $elem['type']) { + foreach ($this -> syntax as $elem) { + if ('text' === $elem['type']) { $elem['str'] = strtr(htmlspecialchars($elem['str']), $chars); foreach ($this -> mnemonics as $mnemonic => $value) { $elem['str'] = str_replace( $mnemonic, - ''.$mnemonic.'', + '' . $mnemonic . '', $elem['str'] ); } @@ -990,8 +1097,8 @@ function highlight() { foreach ($elem['layout'] as $val) { switch ($val[0]) { case 0: - $str .= ''.$val[1] - .''; + $str .= '' . $val[1] + . ''; break; case 1: $str .= '/'; @@ -1010,21 +1117,21 @@ function highlight() { if (! trim($val[1])) { $str .= $val[1]; } else { - $str .= ''.$val[1] - .''; + $str .= '' . $val[1] + . ''; } break; case 6: $str .= '' - .htmlspecialchars($val[1]).''; + . htmlspecialchars($val[1]) . ''; break; case 7: if (! trim($val[1])) { $str .= $val[1]; } else { $str .= '' - .strtr(htmlspecialchars($val[1]), $chars) - .''; + . strtr(htmlspecialchars($val[1]), $chars) + . ''; } break; default: @@ -1040,12 +1147,15 @@ function highlight() { return $str; } + /** * Возвращает HTML код + * * @param array $elems * @return string */ - function get_html($elems = null) { + public function get_html($elems = null) + { $time_start = $this -> _getmicrotime(); if (! is_array($elems)) { $elems =& $this -> tree; @@ -1056,7 +1166,7 @@ function get_html($elems = null) { foreach ($elems as $elem) { if ('text' === $elem['type']) { $elem['str'] = $this -> insert_smiles($elem['str']); - for ($i=0; $i < $rbr; ++$i) { + for ($i = 0; $i < $rbr; ++$i) { $elem['str'] = ltrim($elem['str']); if ('
    ' === substr($elem['str'], 0, 6)) { $elem['str'] = substr_replace($elem['str'], '', 0, 6); @@ -1070,7 +1180,7 @@ function get_html($elems = null) { $class_vars = get_class_vars($handler); $lbr = $class_vars['lbr']; $rbr = $class_vars['rbr']; - for ($i=0; $i < $lbr; ++$i) { + for ($i = 0; $i < $lbr; ++$i) { $result = rtrim($result); if ('
    ' === substr($result, -6)) { $result = substr_replace($result, '', -6, 6); @@ -1104,14 +1214,14 @@ function get_html($elems = null) { */ private function _parseStr ($str) { - $dot = "xbbdot\txbbdot"; - $space = "xbbspace\txbbspace"; + $original = array('.', ' '); + $replace = array("xbbdot\txbbdot", "xbbspace\txbbspace"); - parse_str(str_replace(array('.', ' '), array($dot, $space), $str), $query); + parse_str(str_replace($original, $replace, $str), $query); foreach ($query as $k => $v) { unset($query[$k]); - $query[str_replace(array($dot, $space), array('.', ' '), $k)] = $v; + $query[str_replace($replace, $original, $k)] = $v; } return $query; @@ -1120,10 +1230,12 @@ private function _parseStr ($str) /** * Функция преобразует строку URL в соответствии с RFC 3986 + * * @param string $url * @return string */ - function checkUrl($url) { + protected function _checkUrl($url) + { $parse = parse_url($url); $out = ''; @@ -1155,25 +1267,32 @@ function checkUrl($url) { $out .= '#' . rawurlencode($parse['fragment']); } - return $out; } + /** - * Функция возвращает текущий UNIX timestamp с микросекундами в формате float - * @return float - */ - function _getmicrotime() { + * Функция возвращает текущий UNIX timestamp с микросекундами в формате float + * + * @return float + */ + protected function _getmicrotime() + { return microtime(true); } - /* - Функция проверяет, доступен ли класс - обработчик тега с именем $tagName и, - если нет, пытается подключить файл с соответствующим классом. Если это не - возможно, переназначает тегу обработчик, - сопоставляет ему класс bbcode. - Затем инициализирует объект обработчика (если он еще не инициализирован). - */ - function _includeTagFile($tagName) { + + /** + * Функция проверяет, доступен ли класс - обработчик тега с именем $tagName и, + * если нет, пытается подключить файл с соответствующим классом. Если это не + * возможно, переназначает тегу обработчик, - сопоставляет ему класс bbcode. + * Затем инициализирует объект обработчика (если он еще не инициализирован). + * + * @param string $tagName + * @return bool + */ + protected function _includeTagFile($tagName) + { if (! class_exists($this->tags[$tagName])) { $tag_file = $this->_current_path . str_replace('_', DIRECTORY_SEPARATOR, $this->tags[$tagName]) diff --git a/config/editor.config.php b/config/editor.config.php index 6c10b0b..b8de6e0 100644 --- a/config/editor.config.php +++ b/config/editor.config.php @@ -23,7 +23,8 @@ // Умолчальные значения настроек xBBEditor-а -class Xbb { +class Xbb +{ /* Путь к библиотеке xBB */ @@ -50,4 +51,4 @@ class Xbb { какой либо поддирректории в i18n. */ public $lang = ''; -} \ No newline at end of file +} diff --git a/config/parser.config.php b/config/parser.config.php index 6839970..f32f24d 100644 --- a/config/parser.config.php +++ b/config/parser.config.php @@ -52,11 +52,10 @@ $smiles = array(); foreach ($pak as $val) { $val = trim($val); - if (! $val || '#' == $val{0}) { continue; } + if (! $val || '#' === $val{0}) { continue; } list($gif, $alt, $symbol) = explode('=+:',$val); $smiles[$symbol] = ''
         . htmlspecialchars($alt) . ''; } // Задаем набор смайликов $this->mnemonics = $smiles; -?> diff --git a/config/tags.php b/config/tags.php index 991a0c8..aa8e566 100644 --- a/config/tags.php +++ b/config/tags.php @@ -339,4 +339,4 @@ 'td' => array('td','tr'), 'tr' => array('tr'), 'ul' => array(), -); \ No newline at end of file +); diff --git a/config/xbbeditor.config.php b/config/xbbeditor.config.php index fc35319..06202f8 100644 --- a/config/xbbeditor.config.php +++ b/config/xbbeditor.config.php @@ -77,4 +77,4 @@ array('64.gif', ':gift:' ), array('74.gif', ':pnk:' ), ), -); \ No newline at end of file +); diff --git a/index.php b/index.php index 7622064..e1255be 100644 --- a/index.php +++ b/index.php @@ -1,107 +1,108 @@ - - - - - -xBBEditor demo - - - - - - - -
    - - -

    xBB - PHP-библиотека для работы с BBCode. Версия 0.29

    -
    - -
    -
    - -
     
    - -
    -
    - -
    -
    -

    © 2006-2007, Dmitriy Skorobogatov

    -SourceForge.net Logo -
    - +header('Content-type: text/html; charset=utf-8'); +?> + + + + +xBBEditor demo + + + + + + + +
    + + +

    xBB - PHP-библиотека для работы с BBCode. Версия 0.29

    +
    + +
    +
    + +
     
    + +
    +
    + +
    +
    +

    © 2006-2007, Dmitriy Skorobogatov

    +SourceForge.net Logo +
    + diff --git a/preview.php b/preview.php index 4b02bb4..1bb1294 100644 --- a/preview.php +++ b/preview.php @@ -1,56 +1,56 @@ - - - - - -Test the BBCode parser - - - - - -

    -..:.:: Предварительный просмотр ::.:.. -

    -get_html(); -?> -

    -..:.:: Предварительный просмотр ::.:.. -

    - - + + + + + +Test the BBCode parser + + + + + +

    +..:.:: Предварительный просмотр ::.:.. +

    +get_html(); +?> +

    +..:.:: Предварительный просмотр ::.:.. +

    + + diff --git a/style.css b/style.css index 6b3f084..d6a756d 100644 --- a/style.css +++ b/style.css @@ -1,224 +1,224 @@ -/****************************************************************************** - * * - * style.css, v 0.04 2007/03/29 - This is part of xBB library * - * Copyright (C) 2006-2007 Dmitriy Skorobogatov dima@pc.uz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * * - ******************************************************************************/ - -html { - background-color: #e6e6e6; -} -body { - font-family: Verdana, Arial, sans-serif; - margin: 10px; - border: #d0d0d0 2px solid; - background-color: #f6f6f6; - padding: 10px; - font-size: 12px; - letter-spacing: 1px; - color: #002; -} -p, ul, ol, div, blockquote { - font-size: 12px; - letter-spacing: 1px; - color: #002; -} -acronym { - border-bottom: #303030 1px dotted; - cursor: help; -} -pre { - border: #c0e6ff 1px solid; - background-color: #e0e8ef; - color: #002; -} -hr { - height: 0; - border: none; - border-top: #404040 1px dotted; - width: 75%; -} -var { - color: blue; font-style: normal; font-family: monospace; -} -li { - padding-bottom: 2px; -} -ul li { - font-size: 12px; -} -ul ul li { - font-size: 12px; -} -ul ul ul li { - font-size: 12px; -} -h1 { - color: #404060; -} -h2 { - text-align: center; - color: #404060; -} -h3 { - border-bottom: #b0b0b0 1px dotted; - margin-top: 2em; - border-top: #b0b0b0 1px dotted; - background-color: #ddd; -} -h4 { - margin-top: 1.6em; - border-bottom: #c0c0c0 1px dotted; - margin-bottom: 0; -} -h5 { - border-bottom: #d0d0d0 1px dotted; - margin-top: 1.2em; - margin-bottom: 0; -} -h3, h4, h5 { - color: #707070; - font-weight: normal; -} -table.bb { - border-collapse: collapse; -} -th { - border: #b0b0b0 1px solid; - background-color: #ddd; - color: #555; -} -td.bb { - border: #b0b0b0 1px solid; -} -a { - color: #7777ff; -} -blockquote.bb_quote { - border: #d0d0d0 1px solid; - background-color: #f6f6f6; - padding: 5px; - margin: 1em 0 0 .75em; -} -div.bb_quote_author { - border: #d0d0d0 1px solid; - border-width: 1px 2px 2px 1px; - margin-top: -1.2em; - background-color: #f6f6f6; - width: 150px; - white-space: nowrap; - font-weight: bold; - text-align: center; -} -div.bb_quote_author:after { - content: " писал(а):"; -} -div.bb_code { - border: #d0d0d0 6px double; - background-color: #f6f6f6; - color: #404060; - padding: 5px; - margin: 1em 0 0 0.8em; - font-family: Monaco,'Courier New',monospace; -} -div.bb_code_header { - border: #d0d0d0 1px solid; - border-width: 1px 2px 2px 1px; - padding-left: 5px; - margin-top: -1.6em; - background-color: #f6f6f6; - white-space: nowrap; - font-weight: bold; - color: #404060; - text-align: left; -} -span.bb_code_lang:before { - content: "Код: "; -} -div.bb_code_footer { - margin: 5px -5px -5px -5px; - padding: 4px; - border-width: 1px 0px 0px 0px; - border-style: solid; - border-color: #a9b8c2; - color: #333333; - font-weight: bold; - text-align: center; -} -#content { - padding-left: 1em; -} -#top { - border-bottom: #d0d0d0 1px dotted; -} -#top_h1 { - margin: 0; - color: #404060; - font-size: 18px; - margin-left: 100px; -} -#top_links { - padding-bottom: 1em; - margin-left: 100px; -} -#xbb_logo { - border: none; - float: left; -} - -/* Стили подсветки BBCode: */ - -code.bb_code { - font-size: 1em; - color: #000000; -} -span.bb_spec_char { - color: #000099; -} -span.bb_mnemonic { - color: #ff0000; -} -span.bb_tag { - color: #009900; -} -span.bb_bracket { - font-weight: bold; -} -span.bb_slash { - font-weight: normal; -} -span.bb_tagname { - color: #990099; -} -span.bb_equal { - color: #999900; -} -span.bb_quote { - color: #009999; -} -span.bb_attrib_name { - color: #999900; -} -span.bb_attrib_val { - color: #009999; -} -span.bb_autolink { - color: #0000ff; -} -caption { - font-weight: bold; -} +/****************************************************************************** + * * + * style.css, v 0.04 2007/03/29 - This is part of xBB library * + * Copyright (C) 2006-2007 Dmitriy Skorobogatov dima@pc.uz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * + * * + ******************************************************************************/ + +html { + background-color: #e6e6e6; +} +body { + font-family: Verdana, Arial, sans-serif; + margin: 10px; + border: #d0d0d0 2px solid; + background-color: #f6f6f6; + padding: 10px; + font-size: 12px; + letter-spacing: 1px; + color: #002; +} +p, ul, ol, div, blockquote { + font-size: 12px; + letter-spacing: 1px; + color: #002; +} +acronym { + border-bottom: #303030 1px dotted; + cursor: help; +} +pre { + border: #c0e6ff 1px solid; + background-color: #e0e8ef; + color: #002; +} +hr { + height: 0; + border: none; + border-top: #404040 1px dotted; + width: 75%; +} +var { + color: blue; font-style: normal; font-family: monospace; +} +li { + padding-bottom: 2px; +} +ul li { + font-size: 12px; +} +ul ul li { + font-size: 12px; +} +ul ul ul li { + font-size: 12px; +} +h1 { + color: #404060; +} +h2 { + text-align: center; + color: #404060; +} +h3 { + border-bottom: #b0b0b0 1px dotted; + margin-top: 2em; + border-top: #b0b0b0 1px dotted; + background-color: #ddd; +} +h4 { + margin-top: 1.6em; + border-bottom: #c0c0c0 1px dotted; + margin-bottom: 0; +} +h5 { + border-bottom: #d0d0d0 1px dotted; + margin-top: 1.2em; + margin-bottom: 0; +} +h3, h4, h5 { + color: #707070; + font-weight: normal; +} +table.bb { + border-collapse: collapse; +} +th { + border: #b0b0b0 1px solid; + background-color: #ddd; + color: #555; +} +td.bb { + border: #b0b0b0 1px solid; +} +a { + color: #7777ff; +} +blockquote.bb_quote { + border: #d0d0d0 1px solid; + background-color: #f6f6f6; + padding: 5px; + margin: 1em 0 0 .75em; +} +div.bb_quote_author { + border: #d0d0d0 1px solid; + border-width: 1px 2px 2px 1px; + margin-top: -1.2em; + background-color: #f6f6f6; + width: 150px; + white-space: nowrap; + font-weight: bold; + text-align: center; +} +div.bb_quote_author:after { + content: " писал(а):"; +} +div.bb_code { + border: #d0d0d0 6px double; + background-color: #f6f6f6; + color: #404060; + padding: 5px; + margin: 1em 0 0 0.8em; + font-family: Monaco,'Courier New',monospace; +} +div.bb_code_header { + border: #d0d0d0 1px solid; + border-width: 1px 2px 2px 1px; + padding-left: 5px; + margin-top: -1.6em; + background-color: #f6f6f6; + white-space: nowrap; + font-weight: bold; + color: #404060; + text-align: left; +} +span.bb_code_lang:before { + content: "Код: "; +} +div.bb_code_footer { + margin: 5px -5px -5px -5px; + padding: 4px; + border-width: 1px 0 0 0; + border-style: solid; + border-color: #a9b8c2; + color: #333333; + font-weight: bold; + text-align: center; +} +#content { + padding-left: 1em; +} +#top { + border-bottom: #d0d0d0 1px dotted; +} +#top_h1 { + margin: 0; + color: #404060; + font-size: 18px; + margin-left: 100px; +} +#top_links { + padding-bottom: 1em; + margin-left: 100px; +} +#xbb_logo { + border: none; + float: left; +} + +/* Стили подсветки BBCode: */ + +code.bb_code { + font-size: 1em; + color: #000000; +} +span.bb_spec_char { + color: #000099; +} +span.bb_mnemonic { + color: #ff0000; +} +span.bb_tag { + color: #009900; +} +span.bb_bracket { + font-weight: bold; +} +span.bb_slash { + font-weight: normal; +} +span.bb_tagname { + color: #990099; +} +span.bb_equal { + color: #999900; +} +span.bb_quote { + color: #009999; +} +span.bb_attrib_name { + color: #999900; +} +span.bb_attrib_val { + color: #009999; +} +span.bb_autolink { + color: #0000ff; +} +caption { + font-weight: bold; +} diff --git a/xbb.php b/xbb.php index 49f70ae..28e655c 100644 --- a/xbb.php +++ b/xbb.php @@ -1,920 +1,920 @@ - - - - -xBBEditor - - - - - - - - -идет загрузка - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [b][i][u][s][sub][sup][left][center][right][justify][hr][quote]Preview[code][size][color][font][img][url][email]SmilesAbout programm
    - -
    - - - - - - -
    -  
    - -
    -
    - - + + + + +xBBEditor + + + + + + + + +идет загрузка + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    [b][i][u][s][sub][sup][left][center][right][justify][hr][quote]Preview[code][size][color][font][img][url][email]SmilesAbout programm
    + +
    + + + + + + +
    +  
    + +
    +
    + +