Completed
Push — master ( 8919bf...c1ce74 )
by Matt
06:32
created

bbcodes_config::bbvideo()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

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