• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / texy / 16790351274

06 Aug 2025 10:42PM UTC coverage: 92.746% (+0.005%) from 92.741%
16790351274

push

github

dg
HtmlElement: removed toHtml() & toText()

18 of 19 new or added lines in 5 files covered. (94.74%)

136 existing lines in 23 files now uncovered.

2391 of 2578 relevant lines covered (92.75%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.83
/src/Texy/Configurator.php
1
<?php
2

3
/**
4
 * This file is part of the Texy! (https://texy.info)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Texy;
11

12
use function is_array;
13

14

15
/**
16
 * Texy basic configurators.
17
 *
18
 * <code>
19
 * $texy = new Texy();
20
 * Configurator::safeMode($texy);
21
 * </code>
22
 */
23
class Configurator
24
{
25
        public static array $safeTags = [
26
                'a' => ['href', 'title'],
27
                'abbr' => ['title'],
28
                'b' => [],
29
                'br' => [],
30
                'cite' => [],
31
                'code' => [],
32
                'em' => [],
33
                'i' => [],
34
                'strong' => [],
35
                'sub' => [],
36
                'sup' => [],
37
                'q' => [],
38
                'small' => [],
39
        ];
40

41

42
        /**
43
         * static class.
44
         */
45
        final public function __construct()
46
        {
UNCOV
47
                throw new \LogicException('Cannot instantiate static class ' . static::class);
×
48
        }
49

50

51
        /**
52
         * Configure Texy! for web comments and other usages, where input text may insert attacker.
53
         */
54
        public static function safeMode(Texy $texy): void
1✔
55
        {
56
                $texy->allowedClasses = $texy::NONE; // no class or ID are allowed
1✔
57
                $texy->allowedStyles = $texy::NONE; // style modifiers are disabled
1✔
58
                $texy->allowedTags = self::$safeTags; // only some "safe" HTML tags and attributes are allowed
1✔
59
                $texy->urlSchemeFilters[$texy::FILTER_ANCHOR] = '~https?:|ftp:|mailto:~A';
1✔
60
                $texy->urlSchemeFilters[$texy::FILTER_IMAGE] = '~https?:~A';
1✔
61
                $texy->allowed['image'] = false; // disable images
1✔
62
                $texy->allowed['link/definition'] = false; // disable [ref]: URL reference definitions
1✔
63
                $texy->allowed['html/comment'] = false; // disable HTML comments
1✔
64
                $texy->linkModule->forceNoFollow = true; // force rel="nofollow"
1✔
65
        }
1✔
66

67

68
        /**
69
         * Disable all links.
70
         */
71
        public static function disableLinks(Texy $texy): void
72
        {
73
                $texy->allowed['link/reference'] = false;
×
74
                $texy->allowed['link/email'] = false;
×
75
                $texy->allowed['link/url'] = false;
×
UNCOV
76
                $texy->allowed['link/definition'] = false;
×
77
                $texy->phraseModule->linksAllowed = false;
×
78

UNCOV
79
                if (is_array($texy->allowedTags)) {
×
UNCOV
80
                        unset($texy->allowedTags['a']);
×
81
                } // TODO: else...
82
        }
83

84

85
        /**
86
         * Disable all images.
87
         */
88
        public static function disableImages(Texy $texy): void
89
        {
90
                $texy->allowed['image'] = false;
×
UNCOV
91
                $texy->allowed['figure'] = false;
×
92
                $texy->allowed['image/definition'] = false;
×
93

UNCOV
94
                if (is_array($texy->allowedTags)) {
×
UNCOV
95
                        unset($texy->allowedTags['img'], $texy->allowedTags['object'], $texy->allowedTags['embed'], $texy->allowedTags['applet']);
×
96
                } // TODO: else...
97
        }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc