Completed
Push — master ( 84c2e4...a13154 )
by smiley
02:40
created

DBBaseModule::sanitize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Class DBBaseModule
4
 *
5
 * @filesource   DBBaseModule.php
6
 * @created      28.02.2016
7
 * @package      chillerlan\bbcode\Modules\DB
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2016 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\bbcode\Modules\DB;
14
15
use chillerlan\bbcode\BBTemp;
16
use chillerlan\bbcode\Modules\Markup\MarkupBaseModule;
17
use chillerlan\Database\Traits\DatabaseTrait;
18
19
/**
20
 *
21
 */
22
class DBBaseModule extends MarkupBaseModule{
23
	use DatabaseTrait;
24
25
	/**
26
	 * Holds an array of FQN strings to the current base module's children
27
	 *
28
	 * @var array
29
	 * @see \chillerlan\bbcode\Modules\ModuleInfo::$modules
30
	 */
31
	protected $modules = [
32
		DBTags::class,
33
	];
34
35
	/**
36
	 * An array of tags the module is able to process
37
	 *
38
	 * @var array
39
	 * @see \chillerlan\bbcode\Modules\Tagmap::$tags
40
	 */
41
	protected $tags = [];
42
43
	/**
44
	 * An optional array of tags contained in self::$tags which are marked as "noparse"
45
	 *
46
	 * @var array
47
	 * @see \chillerlan\bbcode\Modules\Tagmap::$noparse_tags
48
	 */
49
	protected $noparse_tags = [];
50
51
	/**
52
	 * An optional array of tags contained in self::$tags which are marked as "single tag"
53
	 *
54
	 * @var array
55
	 * @see \chillerlan\bbcode\Modules\Tagmap::$singletags
56
	 */
57
	protected $singletags = [];
58
59
	/**
60
	 * @var \chillerlan\Database\Drivers\DBDriverInterface
61
	 */
62
	protected $DBDriverInterface;
63
64
	/**
65
	 * DBBaseModule constructor.
66
	 *
67
	 * @param \chillerlan\bbcode\BBTemp|null $bbtemp
68
	 */
69
	public function __construct(BBTemp $bbtemp = null){
70
		parent::__construct($bbtemp);
71
72
		$this->tags         = [];
73
		$this->noparse_tags = [];
74
		$this->singletags   = [];
75
76
		if($this->parserOptions && $this->parserOptions->DBDriver){
77
			$this->DBDriverInterface = $this->dbconnect($this->parserOptions->DBDriver, $this->parserOptions->DBOptions);
78
		}
79
80
	}
81
82
	/**
83
	 * Holds the current base module's EOL token which will replace any newlines
84
	 *
85
	 * @var string
86
	 * @see \chillerlan\bbcode\Modules\ModuleInfo::$eol_token
87
	 */
88
	protected $eol_token = '<br />';
89
90
	/**
91
	 * Sanitizes the content to prevent vulnerabilities or compatibility problems
92
	 *
93
	 * @param $content string to sanitize
94
	 *
95
	 * @return string
96
	 */
97
	public function sanitize(string $content):string{
98
		return htmlspecialchars($content, ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_DISALLOWED | ENT_HTML5, 'UTF-8', false);
99
	}
100
101
}
102