bbcodes_config::hidden()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 19
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 9.6333
ccs 2
cts 2
cp 1
crap 2
1
<?php
2
/**
3
 *
4
 * Advanced BBCode Box
5
 *
6
 * @copyright (c) 2018 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\abbc3\core;
12
13
use s9e\TextFormatter\Configurator;
0 ignored issues
show
Bug introduced by
The type s9e\TextFormatter\Configurator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * ABBC3 custom BBCodes configurator
17
 */
18
class bbcodes_config
19
{
20
	/**
21
	 * Configure s9e Auto Video plugin
22
	 *
23
	 * @param Configurator $configurator
24
	 * @access public
25
	 */
26 1
	public function auto_video(Configurator $configurator)
27
	{
28 1
		if (!$configurator->registeredVars['abbc3.auto_video_enabled'])
29 1
		{
30 1
			return;
31
		}
32
33 1
		$configurator->plugins->load('Autovideo');
34
35
		/** @var \s9e\TextFormatter\Configurator\Items\TemplateDocument $dom Add class "auto-video" to allow us to style the video with our CSS */
36 1
		$dom = $configurator->tags['VIDEO']->template->asDOM();
37 1
		foreach ($dom->getElementsByTagName('video') as $video)
38
		{
39 1
			$video->setAttribute('class', 'auto-video');
40 1
		}
41 1
		$dom->saveChanges();
42 1
	}
43
44
	/**
45
	 * Configure s9e Pipes table plugin
46
	 *
47
	 * @param Configurator $configurator
48
	 * @access public
49
	 */
50 1
	public function pipes(Configurator $configurator)
51
	{
52 1
		if (!isset($configurator->BBCodes['pipes']) || !$configurator->registeredVars['abbc3.pipes_enabled'])
53 1
		{
54 1
			return;
55
		}
56
57
		$configurator->plugins->load('PipeTables');
58 1
59 1
		/** @var \s9e\TextFormatter\Configurator\Items\TemplateDocument $dom Add class "pipe-table" to allow us to style the table with our CSS */
60 1
		$dom = $configurator->tags['TABLE']->template->asDOM();
61
		foreach ($dom->getElementsByTagName('table') as $table)
62 1
		{
63 1
			$table->setAttribute('class', 'pipe-table');
64 1
		}
65 1
		$dom->saveChanges();
66 1
	}
67 1
68
	/**
69 1
	 * Configure BBVideo to use the MEDIA tag with the Media Embed plugin
70 1
	 *
71 1
	 * @param Configurator $configurator
72
	 * @access public
73 1
	 */
74 1
	public function bbvideo(Configurator $configurator)
75
	{
76 1
		if (!isset($configurator->BBCodes['bbvideo']))
77 1
		{
78
			return;
79
		}
80
81
		// If MediaEmbed is not already active (for example due to another ext) lets enable it
82
		if (!isset($configurator->MediaEmbed) && !isset($configurator->BBCodes['MEDIA']))
83
		{
84
			foreach ($configurator->MediaEmbed->defaultSites as $tagName => $tag)
85 1
			{
86
				if (!isset($configurator->BBCodes[$tagName]))
87 1
				{
88 1
					$configurator->MediaEmbed->add($tagName);
89 1
				}
90
			}
91
		}
92 1
93 1
		unset($configurator->BBCodes['bbvideo'], $configurator->tags['bbvideo']);
94 1
		$configurator->BBCodes->add(
95
			'bbvideo',
96
			[
97
				'contentAttributes' => ['url'],
98
				'tagName'           => 'MEDIA',
99
			]
100
		);
101
	}
102
103
	/**
104
	 * Configure Hidden BBCode
105
	 *
106
	 * @param Configurator $configurator
107
	 * @access public
108
	 */
109 1
	public function hidden(Configurator $configurator)
110 1
	{
111
		if (!isset($configurator->BBCodes['hidden']))
112
		{
113
			return;
114
		}
115
116
		unset($configurator->BBCodes['hidden'], $configurator->tags['hidden']);
117
		$configurator->BBCodes->addCustom(
118
			'[hidden]{TEXT}[/hidden]',
119
			'<xsl:choose>
120
				<xsl:when test="$S_USER_LOGGED_IN and not($S_IS_BOT)">
121
					<div class="hidebox hidebox_visible">
122
						<div class="hidebox_title hidebox_visible">{L_ABBC3_HIDDEN_OFF}</div>
123
						<div class="hidebox_visible">{TEXT}</div>
124
					</div>
125
				</xsl:when>
126
				<xsl:otherwise>
127
					<div class="hidebox hidebox_hidden">
128
						<div class="hidebox_title hidebox_hidden">{L_ABBC3_HIDDEN_ON}</div>
129
						<div class="hidebox_hidden">{L_ABBC3_HIDDEN_EXPLAIN}</div>
130
					</div>
131
				</xsl:otherwise>
132
			</xsl:choose>'
133
		);
134
	}
135
}
136