-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEMT_Tret_Text.php
121 lines (108 loc) · 5.62 KB
/
EMT_Tret_Text.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace corpsepk\yii2emt;
use corpsepk\yii2emt\EMT_Lib;
/**
* @see EMT_Tret
*/
class EMT_Tret_Text extends \corpsepk\yii2emt\EMT_Tret
{
public $classes = array(
'nowrap' => 'word-spacing:nowrap;',
);
/**
* Базовые параметры тофа
*
* @var array
*/
public $title = "Текст и абзацы";
public $rules = array(
'auto_links' => array(
'description' => 'Выделение ссылок из текста',
'pattern' => '/(\s|^)(http|ftp|mailto|https)(:\/\/)([^\s\,\!\<]{4,})(\s|\.|\,|\!|\?|\<|$)/ieu',
'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]'
),
'email' => array(
'description' => 'Выделение эл. почты из текста',
'pattern' => '/(\s|^|\ \;|\()([a-z0-9\-\_\.]{2,})\@([a-z0-9\-\.]{2,})\.([a-z]{2,6})(\)|\s|\.|\,|\!|\?|$|\<)/e',
'replacement' => '$m[1] . $this->tag($m[2]."@".$m[3].".".$m[4], "a", array("href" => "mailto:".$m[2]."@".$m[3].".".$m[4])) . $m[5]'
),
'no_repeat_words' => array(
'description' => 'Удаление повторяющихся слов',
'disabled' => true,
'pattern' => array(
'/([а-яё]{3,})( |\t|\ \;)\1/iu',
'/(\s|\ \;|^|\.|\!|\?)(([А-ЯЁ])([а-яё]{2,}))( |\t|\ \;)(([а-яё])\4)/eu',
),
'replacement' => array(
'\1',
'$m[1].($m[7] === \corpsepk\yii2emt\EMT_Lib::strtolower($m[3]) ? $m[2] : $m[2].$m[5].$m[6] )',
)
),
'paragraphs' => array(
'description' => 'Простановка параграфов',
'function' => 'build_paragraphs'
),
'breakline' => array(
'description' => 'Простановка переносов строк',
'function' => 'build_brs'
),
);
/**
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
*
* @return void
*/
protected function do_paragraphs($text) {
$text = str_replace("\r\n","\n",$text);
$text = str_replace("\r","\n",$text);
$text = '<' . self::BASE64_PARAGRAPH_TAG . '>' . trim($text) . '</' . self::BASE64_PARAGRAPH_TAG . '>';
//$text = $this->preg_replace_e('/([\040\t]+)?(\n|\r){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
//$text = $this->preg_replace_e('/([\040\t]+)?(\n){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '$m[1]."</" . self::BASE64_PARAGRAPH_TAG . ">".\corpsepk\yii2emt\EMT_Lib::iblock($m[2].$m[3])."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
//$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '"</" . self::BASE64_PARAGRAPH_TAG . ">"."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
//может от открвающего до закрывающего ?!
$text = preg_replace('/\<' . self::BASE64_PARAGRAPH_TAG . '\>('.EMT_Lib::INTERNAL_BLOCK_OPEN.'[a-zA-Z0-9\/=]+?'.EMT_Lib::INTERNAL_BLOCK_CLOSE.')?\<\/' . self::BASE64_PARAGRAPH_TAG . '\>/s', "", $text);
return $text;
}
/**
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
*
* @return void
*/
protected function build_paragraphs()
{
$r = mb_strpos($this->_text, '<' . self::BASE64_PARAGRAPH_TAG . '>' );
$p = EMT_Lib::rstrpos($this->_text, '</' . self::BASE64_PARAGRAPH_TAG . '>' ) ;
if(($r!== false) && ($p !== false)) {
$beg = mb_substr($this->_text,0,$r);
$end = mb_substr($this->_text,$p+mb_strlen('</' . self::BASE64_PARAGRAPH_TAG . '>'));
$this->_text =
(trim($beg) ? $this->do_paragraphs($beg). "\n":"") .'<' . self::BASE64_PARAGRAPH_TAG . '>'.
mb_substr($this->_text,$r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'),$p -($r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>')) ).'</' . self::BASE64_PARAGRAPH_TAG . '>'.
(trim($end) ? "\n".$this->do_paragraphs($end) :"") ;
} else {
$this->_text = $this->do_paragraphs($this->_text);
}
}
/**
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
*
* @return void
*/
protected function build_brs()
{
$this->_text = $this->preg_replace_e('/(\<\/' . self::BASE64_PARAGRAPH_TAG . '\>)([\r\n \t]+)(\<' . self::BASE64_PARAGRAPH_TAG . '\>)/mse', '$m[1].\corpsepk\yii2emt\EMT_Lib::iblock($m[2]).$m[3]', $this->_text);
if (!preg_match('/\<' . self::BASE64_BREAKLINE_TAG . '\>/', $this->_text)) {
$this->_text = str_replace("\r\n","\n",$this->_text);
$this->_text = str_replace("\r","\n",$this->_text);
//$this->_text = $this->preg_replace_e('/(\n|\r)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">"', $this->_text);
$this->_text = $this->preg_replace_e('/(\n)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">\n"', $this->_text);
}
}
}
/**
* Evgeny Muravjev Typograph, http://mdash.ru
* Version: 3.0 Gold Master
* Release Date: September 28, 2013
* Authors: Evgeny Muravjev & Alexander Drutsa
*/