Passed
Branch master (e751cb)
by Matt
02:48
created

bbcodes_config::hidden()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 19
nc 2
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 9.6333
c 1
b 0
f 0
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 Pipes table plugin
22
	 *
23
	 * @param Configurator $configurator
24
	 * @access public
25
	 */
26 1
	public function pipes(Configurator $configurator)
27
	{
28 1
		if (!isset($configurator->BBCodes['pipes']) || !$configurator->registeredVars['abbc3.pipes_enabled'])
29 1
		{
30 1
			return;
31
		}
32
33 1
		$configurator->plugins->load('PipeTables');
34
35
		/** @var \s9e\TextFormatter\Configurator\Items\TemplateDocument $dom Add class "pipe-table" to allow us to style the table with our CSS */
36 1
		$dom = $configurator->tags['TABLE']->template->asDOM();
37 1
		foreach ($dom->getElementsByTagName('table') as $table)
38
		{
39 1
			$table->setAttribute('class', 'pipe-table');
40 1
		}
41 1
		$dom->saveChanges();
42 1
	}
43
44
	/**
45
	 * Configure BBVideo to use the MEDIA tag with the Media Embed plugin
46
	 *
47
	 * @param Configurator $configurator
48
	 * @access public
49
	 */
50 1
	public function bbvideo(Configurator $configurator)
51
	{
52 1
		if (!isset($configurator->BBCodes['bbvideo']))
53 1
		{
54 1
			return;
55
		}
56
57
		// If MediaEmbed is not already active (for example due to another ext) lets enable it
58 1
		if (!isset($configurator->MediaEmbed) && !isset($configurator->BBCodes['MEDIA']))
59 1
		{
60 1
			foreach ($configurator->MediaEmbed->defaultSites as $tagName => $tag)
61
			{
62 1
				if (!isset($configurator->BBCodes[$tagName]))
63 1
				{
64 1
					$configurator->MediaEmbed->add($tagName);
65 1
				}
66 1
			}
67 1
		}
68
69 1
		unset($configurator->BBCodes['bbvideo'], $configurator->tags['bbvideo']);
70 1
		$configurator->BBCodes->add(
71 1
			'bbvideo',
72
			[
73 1
				'contentAttributes' => ['url'],
74 1
				'tagName'           => 'MEDIA',
75
			]
76 1
		);
77 1
	}
78
79
	/**
80
	 * Configure Hidden BBCode
81
	 *
82
	 * @param Configurator $configurator
83
	 * @access public
84
	 */
85 1
	public function hidden(Configurator $configurator)
86
	{
87 1
		if (!isset($configurator->BBCodes['hidden']))
88 1
		{
89 1
			return;
90
		}
91
92 1
		unset($configurator->BBCodes['hidden'], $configurator->tags['hidden']);
93 1
		$configurator->BBCodes->addCustom(
94 1
			'[hidden]{TEXT}[/hidden]',
95
			'<xsl:choose>
96
				<xsl:when test="$S_USER_LOGGED_IN and not($S_IS_BOT)">
97
					<div class="hidebox hidebox_visible">
98
						<div class="hidebox_title hidebox_visible">{L_ABBC3_HIDDEN_OFF}</div>
99
						<div class="hidebox_visible">{TEXT}</div>
100
					</div>
101
				</xsl:when>
102
				<xsl:otherwise>
103
					<div class="hidebox hidebox_hidden">
104
						<div class="hidebox_title hidebox_hidden">{L_ABBC3_HIDDEN_ON}</div>
105
						<div class="hidebox_hidden">{L_ABBC3_HIDDEN_EXPLAIN}</div>
106
					</div>
107
				</xsl:otherwise>
108
			</xsl:choose>'
109 1
		);
110 1
	}
111
}
112