Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

возвращен пробел в список пробельных символов, код приведен в большее…

… соответствие стандартам кодирования Zend
  • Loading branch information...
commit 0e8f79951c54dbbaf655bd9f064b64df8ab9f533 1 parent 27979e1
Gemorroj authored
Showing with 1,848 additions and 1,626 deletions.
  1. +21 −12 Xbb/Tags/A.php
  2. +7 −5 Xbb/Tags/Abbr.php
  3. +10 −7 Xbb/Tags/Acronym.php
  4. +7 −5 Xbb/Tags/Address.php
  5. +8 −4 Xbb/Tags/Align.php
  6. +11 −6 Xbb/Tags/Bbcode.php
  7. +6 −3 Xbb/Tags/Bdo.php
  8. +5 −3 Xbb/Tags/Br.php
  9. +7 −5 Xbb/Tags/Caption.php
  10. +16 −8 Xbb/Tags/Code.php
  11. +7 −5 Xbb/Tags/Color.php
  12. +16 −11 Xbb/Tags/Email.php
  13. +10 −7 Xbb/Tags/Font.php
  14. +12 −8 Xbb/Tags/Google.php
  15. +5 −3 Xbb/Tags/Hr.php
  16. +15 −9 Xbb/Tags/Img.php
  17. +8 −5 Xbb/Tags/Li.php
  18. +8 −6 Xbb/Tags/List.php
  19. +6 −3 Xbb/Tags/Nobb.php
  20. +7 −4 Xbb/Tags/P.php
  21. +9 −6 Xbb/Tags/Quote.php
  22. +7 −5 Xbb/Tags/Simple.php
  23. +9 −6 Xbb/Tags/Size.php
  24. +16 −11 Xbb/Tags/Table.php
  25. +17 −10 Xbb/Tags/Td.php
  26. +17 −10 Xbb/Tags/Th.php
  27. +10 −5 Xbb/Tags/Tr.php
  28. +39 −42 bbcode.lib.js
  29. +220 −101 bbcode.lib.php
  30. +3 −2 config/editor.config.php
  31. +1 −2  config/parser.config.php
  32. +1 −1  config/tags.php
  33. +1 −1  config/xbbeditor.config.php
  34. +106 −105 index.php
  35. +56 −56 preview.php
  36. +224 −224 style.css
  37. +920 −920 xbb.php
33 Xbb/Tags/A.php
View
@@ -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 '<a '.$attr.'>'.parent::get_html($this -> tree).'</a>';
+
+ return '<a ' . $attr . '>' . parent::get_html($this -> tree) . '</a>';
}
}
-?>
12 Xbb/Tags/Abbr.php
View
@@ -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 '<abbr '.$attrib.'>'.parent::get_html($this -> tree).'</abbr>';
+ return '<abbr ' . $attrib . '>' . parent::get_html($this -> tree) . '</abbr>';
}
}
-?>
17 Xbb/Tags/Acronym.php
View
@@ -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 '<acronym '.$attrib.'>'.parent::get_html($this -> tree)
- .'</acronym>';
+
+ return '<acronym ' . $attrib . '>' . parent::get_html($this -> tree)
+ . '</acronym>';
}
}
-?>
12 Xbb/Tags/Address.php
View
@@ -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 '<address class="bb">'.parent::get_html($this -> tree)
- .'</address>';
+
+ public function get_html($tree = null)
+ {
+ return '<address class="bb">' . parent::get_html($this -> tree)
+ . '</address>';
}
}
-?>
12 Xbb/Tags/Align.php
View
@@ -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 '<div class="bb" align="'.$align.'">'
- .parent::get_html($this -> tree).'</div>';
+
+ return '<div class="bb" align="' . $align . '">'
+ . parent::get_html($this -> tree) . '</div>';
}
}
?>
17 Xbb/Tags/Bbcode.php
View
@@ -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 '<code class="bb_code">'.$bb -> highlight().'</code>';
+
+ return '<code class="bb_code">' . $bb -> highlight() . '</code>';
}
}
-?>
9 Xbb/Tags/Bdo.php
View
@@ -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 '<bdo ' . $attr . '>' . parent::get_html() . '</bdo>';
}
}
-?>
8 Xbb/Tags/Br.php
View
@@ -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 '<br class="bb" />' . "\n";
}
}
-?>
12 Xbb/Tags/Caption.php
View
@@ -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 '<caption class="bb">'.parent::get_html($this -> tree)
- .'</caption>';
+
+ public function get_html($tree = null)
+ {
+ return '<caption class="bb">' . parent::get_html($this -> tree)
+ . '</caption>';
}
}
-?>
24 Xbb/Tags/Code.php
View
@@ -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 = '<div class="bb_code"><div class="bb_code_header">' .$result
+ $result = '<div class="bb_code"><div class="bb_code_header">' . $result
. '</div>' . $this->_geshi->parse_code();
// Формируем подпись под кодом
if (isset($this->attrib['footer'])) {
@@ -117,8 +125,8 @@ function get_html($tree = null) {
$content = '<div class="bb_code_footer">' . $content . '</div>';
$result .= $content;
}
+
// Возвращаем результат
return $result . '</div>';
}
}
-?>
12 Xbb/Tags/Color.php
View
@@ -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 '<font color="'.$color.'">'.parent::get_html($this -> tree)
- .'</font>';
+ return '<font color="' . $color . '">' . parent::get_html($this -> tree)
+ . '</font>';
}
}
-?>
27 Xbb/Tags/Email.php
View
@@ -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 '<a'.$attr.'>'.parent::get_html($this -> tree).'</a>';
+ if ($target) { $attr .= ' target="' . htmlspecialchars($target) . '"'; }
+
+ return '<a' . $attr . '>' . parent::get_html($this -> tree) . '</a>';
}
}
-?>
17 Xbb/Tags/Font.php
View
@@ -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 '<font'.$attr.'>'.parent::get_html($this -> tree).'</font>';
+ if ($size) { $attr .= ' size="' . htmlspecialchars($size) . '"'; }
+
+ return '<font' . $attr . '>' . parent::get_html($this -> tree) . '</font>';
}
}
-?>
20 Xbb/Tags/Google.php
View
@@ -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 '<a class="bb_google" '.$attr.'>'.parent::get_html($this -> tree).'</a>';
+ if ($target) { $attr .= ' target="' . htmlspecialchars($target) . '"'; }
+
+ return '<a class="bb_google" ' . $attr . '>' . parent::get_html($this -> tree) . '</a>';
}
}
-?>
8 Xbb/Tags/Hr.php
View
@@ -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 '<hr class="bb" />';
}
}
-?>
24 Xbb/Tags/Img.php
View
@@ -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 '<img src="'.$src.'" '.$attr.' />';
+ $src = $this -> _checkUrl($src);
+
+ return '<img src="' . $src . '" ' . $attr . ' />';
}
}
-?>
13 Xbb/Tags/Li.php
View
@@ -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 '<li '.$attrib.'>'.parent::get_html($this -> tree).'</li>';
+
+ return '<li ' . $attrib . '>' . parent::get_html($this -> tree) . '</li>';
}
}
-?>
14 Xbb/Tags/List.php
View
@@ -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() . '</'
+
+ return '<' . $tag_name . $attr . '>' . parent::get_html() . '</'
. $tag_name . '>';
- return $str;
}
}
-?>
9 Xbb/Tags/Nobb.php
View
@@ -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(' ', '&#160;&#160;', $str);
+
return $str;
}
}
-?>
11 Xbb/Tags/P.php
View
@@ -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() . '</' . $this->tag . ">\n";
}
}
-?>
15 Xbb/Tags/Quote.php
View
@@ -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 = '<div class="bb_quote_author">' . $author . '</div>';
}
+
return '<blockquote class="bb_quote">' . $author
. parent::get_html($this -> tree) . '</blockquote>';
}
}
-?>
12 Xbb/Tags/Simple.php
View
@@ -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() . '</'
+
+ return '<' . $this->tag . ' class="bb">' . parent::get_html() . '</'
. $this->tag . '>';
- return $html;
}
}
-?>
15 Xbb/Tags/Size.php
View
@@ -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 '<font size="'.$size.'">'.parent::get_html($this -> tree).'</font>';
+ $size = $sign . $size;
+
+ return '<font size="' . $size . '">' . parent::get_html($this -> tree) . '</font>';
}
}
-?>
27 Xbb/Tags/Table.php
View
@@ -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 = '<table'.$attr.'>';
+ if ($align) { $attr .= ' align="' . htmlspecialchars($align) . '"'; }
+ $str = '<table' . $attr . '>';
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).'</table>';
+ $str .= parent::get_html($this -> tree) . '</table>';
+
return $str;
}
}
-?>
27 Xbb/Tags/Td.php
View
@@ -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 '<td '.$attr.'>'.parent::get_html($this -> tree).'</td>';
+
+ return '<td ' . $attr . '>' . parent::get_html($this -> tree) . '</td>';
}
}
-?>
27 Xbb/Tags/Th.php
View
@@ -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 '<th'.$attr.'>'.parent::get_html($this -> tree).'</th>';
+
+ return '<th' . $attr . '>' . parent::get_html($this -> tree) . '</th>';
}
}
-?>
15 Xbb/Tags/Tr.php
View
@@ -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 = '<tr class="bb">';
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).'</tr>';
+ $str .= parent::get_html($this -> tree) . '</tr>';
+
return $str;
}
}
-?>
81 bbcode.lib.js
View
@@ -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/, '&nbsp;&nbsp;');
return str;
- }
+ };
/*
Текстовое содержимое узла с заменой <br /> на разрыв строки и окрыжением
@@ -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, '<br />');
}
return str;
- }
+ };
/* Аналог функции htmlspecialchars в PHP */
this.htmlspecialchars = function(str) {
@@ -545,7 +545,7 @@ function bbcode(code) {
str = str.replace(/</g, '&lt;');
str = str.replace(/>/g, '&gt;');
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");
+ }
}
321 bbcode.lib.php
View
@@ -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;' => '<span class="bb_spec_char">@l;</span>',
@@ -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,
- '<span class="bb_mnemonic">'.$mnemonic.'</span>',
+ '<span class="bb_mnemonic">' . $mnemonic . '</span>',
$elem['str']
);
}
@@ -990,8 +1097,8 @@ function highlight() {
foreach ($elem['layout'] as $val) {
switch ($val[0]) {
case 0:
- $str .= '<span class="bb_bracket">'.$val[1]
- .'</span>';
+ $str .= '<span class="bb_bracket">' . $val[1]
+ . '</span>';
break;
case 1:
$str .= '<span class="bb_slash">/</span>';
@@ -1010,21 +1117,21 @@ function highlight() {
if (! trim($val[1])) {
$str .= $val[1];
} else {
- $str .= '<span class="bb_quote">'.$val[1]
- .'</span>';
+ $str .= '<span class="bb_quote">' . $val[1]
+ . '</span>';
}
break;
case 6:
$str .= '<span class="bb_attrib_name">'
- .htmlspecialchars($val[1]).'</span>';
+ . htmlspecialchars($val[1]) . '</span>';
break;
case 7:
if (! trim($val[1])) {
$str .= $val[1];
} else {
$str .= '<span class="bb_attrib_val">'
- .strtr(htmlspecialchars($val[1]), $chars)
- .'</span>';
+ . strtr(htmlspecialchars($val[1]), $chars)
+ . '</span>';
}
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 ('<br />' === 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 ('<br />' === 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);
}