EMTTretText::build_paragraphs()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 12
nc 5
nop 0
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|^|\&nbsp\;|\()([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|\&nbsp\;)\1/iu',
44
					'/(\s|\&nbsp\;|^|\.|\!|\?)(([А-ЯЁ])([а-яё]{2,}))( |\t|\&nbsp\;)(([а-яё])\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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
72
		//$text = $this->preg_replace_e('/([\040\t]+)?(\n){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->_text is correct as $this->do_paragraphs($this->_text) (which targets Fenrizbes\TypographBundl...etText::do_paragraphs()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
115
			$this->_text = $this->preg_replace_e('/(\n)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">\n"', $this->_text);
116
		}
117
	}
118
}