/
Configurator.php
99 lines (84 loc) · 2.31 KB
/
Configurator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* This file is part of the Texy! (https://texy.info)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Texy;
/**
* Texy basic configurators.
*
* <code>
* $texy = new Texy();
* Configurator::safeMode($texy);
* </code>
*/
class Configurator
{
use Strict;
public static $safeTags = [
'a' => ['href', 'title'],
'acronym' => ['title'],
'b' => [],
'br' => [],
'cite' => [],
'code' => [],
'em' => [],
'i' => [],
'strong' => [],
'sub' => [],
'sup' => [],
'q' => [],
'small' => [],
];
/**
* static class.
*/
final public function __construct()
{
throw new \LogicException('Cannot instantiate static class ' . get_class($this));
}
/**
* Configure Texy! for web comments and other usages, where input text may insert attacker.
* @return void
*/
public static function safeMode(Texy $texy)
{
$texy->allowedClasses = $texy::NONE; // no class or ID are allowed
$texy->allowedStyles = $texy::NONE; // style modifiers are disabled
$texy->allowedTags = self::$safeTags; // only some "safe" HTML tags and attributes are allowed
$texy->urlSchemeFilters[$texy::FILTER_ANCHOR] = '#https?:|ftp:|mailto:#A';
$texy->urlSchemeFilters[$texy::FILTER_IMAGE] = '#https?:#A';
$texy->allowed['image'] = FALSE; // disable images
$texy->allowed['link/definition'] = FALSE; // disable [ref]: URL reference definitions
$texy->allowed['html/comment'] = FALSE; // disable HTML comments
$texy->linkModule->forceNoFollow = TRUE; // force rel="nofollow"
}
/**
* Disable all links.
* @return void
*/
public static function disableLinks(Texy $texy)
{
$texy->allowed['link/reference'] = FALSE;
$texy->allowed['link/email'] = FALSE;
$texy->allowed['link/url'] = FALSE;
$texy->allowed['link/definition'] = FALSE;
$texy->phraseModule->linksAllowed = FALSE;
if (is_array($texy->allowedTags)) {
unset($texy->allowedTags['a']);
} // TODO: else...
}
/**
* Disable all images.
* @return void
*/
public static function disableImages(Texy $texy)
{
$texy->allowed['image'] = FALSE;
$texy->allowed['figure'] = FALSE;
$texy->allowed['image/definition'] = FALSE;
if (is_array($texy->allowedTags)) {
unset($texy->allowedTags['img'], $texy->allowedTags['object'], $texy->allowedTags['embed'], $texy->allowedTags['applet']);
} // TODO: else...
}
}