1
|
|
|
<?php |
2
|
|
|
namespace EMT\Tret; |
3
|
|
|
|
4
|
|
|
use EMT\Util; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Text |
8
|
|
|
* @package EMT\Tret |
9
|
|
|
*/ |
10
|
|
|
class Text extends AbstractTret |
11
|
|
|
{ |
12
|
|
|
public $classes = array( |
13
|
|
|
'nowrap' => 'word-spacing:nowrap;', |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Базовые параметры тофа |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
public $title = "Текст и абзацы"; |
22
|
|
|
public $rules = array( |
23
|
|
|
'auto_links' => array( |
24
|
|
|
'description' => 'Выделение ссылок из текста', |
25
|
|
|
'pattern' => '/(\s|^)(http|ftp|mailto|https)(:\/\/)([^\s\,\!\<]{4,})(\s|\.|\,|\!|\?|\<|$)/ieu', |
26
|
|
|
'replacement' => '$m[1] . $this->tag((substr($m[4],-1)=="."?substr($m[4],0,-1):$m[4]), "a", array("href" => $m[2].$m[3].(substr($m[4],-1)=="."?substr($m[4],0,-1):$m[4]))) . (substr($m[4],-1)=="."?".":"") .$m[5]' |
27
|
|
|
), |
28
|
|
|
'email' => array( |
29
|
|
|
'description' => 'Выделение эл. почты из текста', |
30
|
|
|
'pattern' => '/(\s|^|\ \;|\()([a-z0-9\-\_\.]{2,})\@([a-z0-9\-\.]{2,})\.([a-z]{2,6})(\)|\s|\.|\,|\!|\?|$|\<)/e', |
31
|
|
|
'replacement' => '$m[1] . $this->tag($m[2]."@".$m[3].".".$m[4], "a", array("href" => "mailto:".$m[2]."@".$m[3].".".$m[4])) . $m[5]' |
32
|
|
|
), |
33
|
|
|
'no_repeat_words' => array( |
34
|
|
|
'description' => 'Удаление повторяющихся слов', |
35
|
|
|
'disabled' => true, |
36
|
|
|
'pattern' => array( |
37
|
|
|
'/([а-яё]{3,})( |\t|\ \;)\1/iu', |
38
|
|
|
'/(\s|\ \;|^|\.|\!|\?)(([А-ЯЁ])([а-яё]{2,}))( |\t|\ \;)(([а-яё])\4)/eu', |
39
|
|
|
), |
40
|
|
|
'replacement' => array( |
41
|
|
|
'\1', |
42
|
|
|
'$m[1].($m[7] === \EMT\Util::strtolower($m[3]) ? $m[2] : $m[2].$m[5].$m[6] )', |
43
|
|
|
) |
44
|
|
|
), |
45
|
|
|
'paragraphs' => array( |
46
|
|
|
'description' => 'Простановка параграфов', |
47
|
|
|
'function' => 'build_paragraphs' |
48
|
|
|
), |
49
|
|
|
'breakline' => array( |
50
|
|
|
'description' => 'Простановка переносов строк', |
51
|
|
|
'function' => 'build_brs' |
52
|
|
|
), |
53
|
|
|
|
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
protected function do_paragraphs($text) |
62
|
|
|
{ |
63
|
|
|
$text = str_replace("\r\n", "\n", $text); |
64
|
|
|
$text = str_replace("\r", "\n", $text); |
65
|
|
|
$text = '<' . self::BASE64_PARAGRAPH_TAG . '>' . trim($text) . '</' . self::BASE64_PARAGRAPH_TAG . '>'; |
66
|
|
|
//$text = $this->preg_replace_e('/([\040\t]+)?(\n|\r){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
67
|
|
|
//$text = $this->preg_replace_e('/([\040\t]+)?(\n){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
68
|
|
|
$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '$m[1]."</" . \EMT\Tret\AbstractTret::BASE64_PARAGRAPH_TAG . ">".\EMT\Util::iblock($m[2].$m[3])."<" .\EMT\Tret\AbstractTret::BASE64_PARAGRAPH_TAG . ">"', $text); |
69
|
|
|
//$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '"</" . self::BASE64_PARAGRAPH_TAG . ">"."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
70
|
|
|
//может от открвающего до закрывающего ?! |
71
|
|
|
$text = preg_replace('/\<' . self::BASE64_PARAGRAPH_TAG . '\>(' . Util::INTERNAL_BLOCK_OPEN . '[a-zA-Z0-9\/=]+?' . Util::INTERNAL_BLOCK_CLOSE . ')?\<\/' . self::BASE64_PARAGRAPH_TAG . '\>/s', "", $text); |
72
|
|
|
|
73
|
|
|
return $text; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
protected function build_paragraphs() |
82
|
|
|
{ |
83
|
|
|
$r = mb_strpos($this->_text, '<' . self::BASE64_PARAGRAPH_TAG . '>'); |
84
|
|
|
$p = Util::rstrpos($this->_text, '</' . self::BASE64_PARAGRAPH_TAG . '>'); |
85
|
|
|
if (($r !== false) && ($p !== false)) { |
86
|
|
|
|
87
|
|
|
$beg = mb_substr($this->_text, 0, $r); |
88
|
|
|
$end = mb_substr($this->_text, $p + mb_strlen('</' . self::BASE64_PARAGRAPH_TAG . '>')); |
89
|
|
|
$this->_text = |
90
|
|
|
(trim($beg) ? $this->do_paragraphs($beg) . "\n" : "") . '<' . self::BASE64_PARAGRAPH_TAG . '>' . |
91
|
|
|
mb_substr($this->_text, $r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'), $p - ($r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'))) . '</' . self::BASE64_PARAGRAPH_TAG . '>' . |
92
|
|
|
(trim($end) ? "\n" . $this->do_paragraphs($end) : ""); |
93
|
|
|
} else { |
94
|
|
|
$this->_text = $this->do_paragraphs($this->_text); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
protected function build_brs() |
104
|
|
|
{ |
105
|
|
|
$this->_text = $this->preg_replace_e('/(\<\/' . self::BASE64_PARAGRAPH_TAG . '\>)([\r\n \t]+)(\<' . self::BASE64_PARAGRAPH_TAG . '\>)/mse', '$m[1].\EMT\Util::iblock($m[2]).$m[3]', $this->_text); |
106
|
|
|
|
107
|
|
|
if (!preg_match('/\<' . self::BASE64_BREAKLINE_TAG . '\>/', $this->_text)) { |
108
|
|
|
$this->_text = str_replace("\r\n", "\n", $this->_text); |
109
|
|
|
$this->_text = str_replace("\r", "\n", $this->_text); |
110
|
|
|
//$this->_text = $this->preg_replace_e('/(\n|\r)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">"', $this->_text); |
111
|
|
|
$this->_text = $this->preg_replace_e('/(\n)/e', '"<" . \EMT\Tret\AbstractTret::BASE64_BREAKLINE_TAG . ">\n"', $this->_text); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.