Completed
Push — master ( 4e5e31...e8f514 )
by Matt
02:38
created

remove_markup::set_data()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
/**
3
 *
4
 * Topic Preview
5
 *
6
 * @copyright (c) 2016 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\topicpreview\core\trim\tools;
12
13
class remove_markup extends base
14
{
15
	/** @var array Data array of regex patterns */
16
	protected $data;
17
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function run()
22
	{
23
		return $this->set_data()->process();
24
	}
25
26
	/**
27
	 * @inheritdoc
28
	 */
29
	public function set_data()
30
	{
31
		if (!isset($this->data))
32
		{
33
			// RegEx patterns originally based on Topic Text Hover Mod by RMcGirr83
34
			$this->data = array(
35
				'#<!-- [lmw] --><a class="postlink[^>]*>(.*<\/a[^>]*>)?<!-- [lmw] -->#Usi', // Magic URLs
36
				'#<[^>]*>(.*<[^>]*>)?#Usi', // HTML code
37
				'#\[/?[^\[\]]+\]#mi', // All BBCode tags
38
				'#(http|https|ftp|mailto)(:|\&\#58;)\/\/[^\s]+#i', // Remaining URLs
39
				'#"#', // Possible un-encoded quotes from older board conversions
40
				'#[ \t]{2,}#' // Multiple spaces #[\s]+#
41
			);
42
		}
43
44
		return $this;
45
	}
46
47
	/**
48
	 * Remove markup from the text
49
	 *
50
	 * @return string Stripped message text
51
	 * @access protected
52
	 */
53
	protected function process()
54
	{
55
		return trim(preg_replace($this->data, ' ', $this->text));
56
	}
57
}
58