1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
/**
|
4
|
|
|
* Evgeny Muravjev Typograph, http://mdash.ru
|
5
|
|
|
* Version: 3.4 Gold Master
|
6
|
|
|
* Release Date: September 20, 2014
|
7
|
|
|
* Authors: Evgeny Muravjev & Alexander Drutsa
|
8
|
|
|
*/
|
9
|
|
|
|
10
|
|
|
namespace Fenrizbes\TypographBundle\EMT;
|
11
|
|
|
|
12
|
|
|
/**
|
13
|
|
|
* @see EMTTret
|
14
|
|
|
*/
|
15
|
|
|
|
16
|
|
|
class EMTTretText extends EMTTret
|
17
|
|
|
{
|
18
|
|
|
public $classes = array(
|
19
|
|
|
'nowrap' => 'word-spacing:nowrap;',
|
20
|
|
|
);
|
21
|
|
|
|
22
|
|
|
/**
|
23
|
|
|
* Базовые параметры тофа
|
24
|
|
|
*
|
25
|
|
|
* @var array
|
26
|
|
|
*/
|
27
|
|
|
public $title = "Текст и абзацы";
|
28
|
|
|
public $rules = array(
|
29
|
|
|
'auto_links' => array(
|
30
|
|
|
'description' => 'Выделение ссылок из текста',
|
31
|
|
|
'pattern' => '/(\s|^)(http|ftp|mailto|https)(:\/\/)([^\s\,\!\<]{4,})(\s|\.|\,|\!|\?|\<|$)/ieu',
|
32
|
|
|
'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]'
|
33
|
|
|
),
|
34
|
|
|
'email' => array(
|
35
|
|
|
'description' => 'Выделение эл. почты из текста',
|
36
|
|
|
'pattern' => '/(\s|^|\ \;|\()([a-z0-9\-\_\.]{2,})\@([a-z0-9\-\.]{2,})\.([a-z]{2,6})(\)|\s|\.|\,|\!|\?|$|\<)/e',
|
37
|
|
|
'replacement' => '$m[1] . $this->tag($m[2]."@".$m[3].".".$m[4], "a", array("href" => "mailto:".$m[2]."@".$m[3].".".$m[4])) . $m[5]'
|
38
|
|
|
),
|
39
|
|
|
'no_repeat_words' => array(
|
40
|
|
|
'description' => 'Удаление повторяющихся слов',
|
41
|
|
|
'disabled' => true,
|
42
|
|
|
'pattern' => array(
|
43
|
|
|
'/([а-яё]{3,})( |\t|\ \;)\1/iu',
|
44
|
|
|
'/(\s|\ \;|^|\.|\!|\?)(([А-ЯЁ])([а-яё]{2,}))( |\t|\ \;)(([а-яё])\4)/eu',
|
45
|
|
|
),
|
46
|
|
|
'replacement' => array(
|
47
|
|
|
'\1',
|
48
|
|
|
'$m[1].($m[7] === \Fenrizbes\TypographBundle\EMT\EMTLib::strtolower($m[3]) ? $m[2] : $m[2].$m[5].$m[6] )',
|
49
|
|
|
)
|
50
|
|
|
),
|
51
|
|
|
'paragraphs' => array(
|
52
|
|
|
'description' => 'Простановка параграфов',
|
53
|
|
|
'function' => 'build_paragraphs'
|
54
|
|
|
),
|
55
|
|
|
'breakline' => array(
|
56
|
|
|
'description' => 'Простановка переносов строк',
|
57
|
|
|
'function' => 'build_brs'
|
58
|
|
|
),
|
59
|
|
|
|
60
|
|
|
);
|
61
|
|
|
|
62
|
|
|
/**
|
63
|
|
|
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
|
64
|
|
|
*
|
65
|
|
|
* @return void
|
66
|
|
|
*/
|
67
|
|
|
protected function do_paragraphs($text) {
|
68
|
|
|
$text = str_replace("\r\n","\n",$text);
|
69
|
|
|
$text = str_replace("\r","\n",$text);
|
70
|
|
|
$text = '<' . self::BASE64_PARAGRAPH_TAG . '>' . trim($text) . '</' . self::BASE64_PARAGRAPH_TAG . '>';
|
71
|
|
|
//$text = $this->preg_replace_e('/([\040\t]+)?(\n|\r){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
|
|
|
|
|
72
|
|
|
//$text = $this->preg_replace_e('/([\040\t]+)?(\n){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
|
|
|
|
|
73
|
|
|
$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '$m[1]."</" . self::BASE64_PARAGRAPH_TAG . ">".\Fenrizbes\TypographBundle\EMT\EMTLib::iblock($m[2].$m[3])."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
|
74
|
|
|
//$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '"</" . self::BASE64_PARAGRAPH_TAG . ">"."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
|
|
|
|
|
75
|
|
|
//может от открвающего до закрывающего ?!
|
76
|
|
|
$text = preg_replace('/\<' . self::BASE64_PARAGRAPH_TAG . '\>('.EMTLib::INTERNAL_BLOCK_OPEN.'[a-zA-Z0-9\/=]+?'.EMTLib::INTERNAL_BLOCK_CLOSE.')?\<\/' . self::BASE64_PARAGRAPH_TAG . '\>/s', "", $text);
|
77
|
|
|
return $text;
|
78
|
|
|
}
|
79
|
|
|
|
80
|
|
|
/**
|
81
|
|
|
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
|
82
|
|
|
*
|
83
|
|
|
* @return void
|
84
|
|
|
*/
|
85
|
|
|
protected function build_paragraphs()
|
86
|
|
|
{
|
87
|
|
|
$r = mb_strpos($this->_text, '<' . self::BASE64_PARAGRAPH_TAG . '>' );
|
88
|
|
|
$p = EMTLib::rstrpos($this->_text, '</' . self::BASE64_PARAGRAPH_TAG . '>' ) ;
|
89
|
|
|
if(($r!== false) && ($p !== false)) {
|
90
|
|
|
|
91
|
|
|
$beg = mb_substr($this->_text,0,$r);
|
92
|
|
|
$end = mb_substr($this->_text,$p+mb_strlen('</' . self::BASE64_PARAGRAPH_TAG . '>'));
|
93
|
|
|
$this->_text =
|
94
|
|
|
(trim($beg) ? $this->do_paragraphs($beg). "\n":"") .'<' . self::BASE64_PARAGRAPH_TAG . '>'.
|
95
|
|
|
mb_substr($this->_text,$r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'),$p -($r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>')) ).'</' . self::BASE64_PARAGRAPH_TAG . '>'.
|
96
|
|
|
(trim($end) ? "\n".$this->do_paragraphs($end) :"") ;
|
97
|
|
|
} else {
|
98
|
|
|
$this->_text = $this->do_paragraphs($this->_text);
|
|
|
|
|
99
|
|
|
}
|
100
|
|
|
}
|
101
|
|
|
|
102
|
|
|
/**
|
103
|
|
|
* Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
|
104
|
|
|
*
|
105
|
|
|
* @return void
|
106
|
|
|
*/
|
107
|
|
|
protected function build_brs()
|
108
|
|
|
{
|
109
|
|
|
$this->_text = $this->preg_replace_e('/(\<\/' . self::BASE64_PARAGRAPH_TAG . '\>)([\r\n \t]+)(\<' . self::BASE64_PARAGRAPH_TAG . '\>)/mse', '$m[1].\Fenrizbes\TypographBundle\EMT\EMTLib::iblock($m[2]).$m[3]', $this->_text);
|
110
|
|
|
|
111
|
|
|
if (!preg_match('/\<' . self::BASE64_BREAKLINE_TAG . '\>/', $this->_text)) {
|
112
|
|
|
$this->_text = str_replace("\r\n","\n",$this->_text);
|
113
|
|
|
$this->_text = str_replace("\r","\n",$this->_text);
|
114
|
|
|
//$this->_text = $this->preg_replace_e('/(\n|\r)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">"', $this->_text);
|
|
|
|
|
115
|
|
|
$this->_text = $this->preg_replace_e('/(\n)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">\n"', $this->_text);
|
116
|
|
|
}
|
117
|
|
|
}
|
118
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.