Completed
Push — master ( eda6e2...0d43e9 )
by Matt
07:15
created

bbcodes_config   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 84
ccs 29
cts 36
cp 0.8056
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pipes() 0 17 3
B bbvideo() 0 23 5
A hidden() 0 21 1
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
		if (!isset($configurator->BBCodes['pipes']))
29 1
		{
30 1
			return;
31
		}
32
33
		$configurator->plugins->load('PipeTables');
34
35
		// Add class "pipe-table" to allow us to style the table with our CSS
36
		$dom = $configurator->tags['TABLE']->template->asDOM();
37
		foreach ($dom->getElementsByTagName('table') as $table)
38
		{
39
			$table->setAttribute('class', 'pipe-table');
40
		}
41
		$dom->saveChanges();
42
	}
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
		// If MediaEmbed is not already active (for example due to another ext) lets enable it
53 1
		if (!isset($configurator->MediaEmbed) && !isset($configurator->BBCodes['MEDIA']))
54 1
		{
55 1
			foreach ($configurator->MediaEmbed->defaultSites as $tagName => $tag)
56
			{
57 1
				if (!isset($configurator->BBCodes[$tagName]))
58 1
				{
59 1
					$configurator->MediaEmbed->add($tagName);
60 1
				}
61 1
			}
62 1
		}
63
64 1
		unset($configurator->BBCodes['bbvideo'], $configurator->tags['bbvideo']);
65 1
		$configurator->BBCodes->add(
66 1
			'bbvideo',
67
			[
68 1
				'contentAttributes' => ['url'],
69
				'tagName'           => 'MEDIA'
70 1
			]
71 1
		);
72 1
	}
73
74
	/**
75
	 * Configure Hidden BBCode
76
	 *
77
	 * @param Configurator $configurator
78
	 * @access public
79
	 */
80 1
	public function hidden(Configurator $configurator)
81 1
	{
82 1
		unset($configurator->BBCodes['hidden'], $configurator->tags['hidden']);
83 1
		$configurator->BBCodes->addCustom(
84 1
			'[hidden]{TEXT}[/hidden]',
85
			'<xsl:choose>
86
				<xsl:when test="$S_USER_LOGGED_IN and not($S_IS_BOT)">
87
					<div class="hidebox hidebox_visible">
88
						<div class="hidebox_title hidebox_visible">{L_ABBC3_HIDDEN_OFF}</div>
89 1
						<div class="hidebox_visible">{TEXT}</div>
90
					</div>
91
				</xsl:when>
92
				<xsl:otherwise>
93
					<div class="hidebox hidebox_hidden">
94
						<div class="hidebox_title hidebox_hidden">{L_ABBC3_HIDDEN_ON}</div>
95
						<div class="hidebox_hidden">{L_ABBC3_HIDDEN_EXPLAIN}</div>
96
					</div>
97
				</xsl:otherwise>
98
			</xsl:choose>'
99 1
		);
100 1
	}
101
}
102