Completed
Push — master ( d09163...346149 )
by Matt
06:42
created

markup::set_data()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

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