Completed
Pull Request — master (#4)
by Helpful
12:49
created
code/YouTubeShortCodeHandler.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -3,37 +3,37 @@
 block discarded – undo
3 3
 class YouTubeShortCodeHandler
4 4
 {
5 5
 
6
-    // taken from http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/ and adapted for SS3
7
-    public static function parse_youtube($arguments, $caption = null, $parser = null, $tagName)
8
-    {
9
-        // first things first, if we dont have a video ID, then we don't need to
10
-        // go any further
11
-        if (empty($arguments['id'])) {
12
-            return;
13
-        }
14
-
15
-        $customise = array();
16
-
17
-        // YouTube video id
18
-        $customise['YouTubeID'] = $arguments['id'];
19
-
20
-        //play the video on page load
21
-        $set = isset($arguments['autoplay']);
22
-        $customise['AutoPlay'] = $set ? true : false;
23
-
24
-        //set the caption
25
-        $customise['Caption'] = $caption ? Convert::raw2xml($caption) : false;
26
-
27
-        //set dimensions
28
-        $widthSet = isset($arguments['width']);
29
-        $heightSet = isset($arguments['height']);
30
-        $customise['Width'] = $widthSet ? $arguments['width'] : 560;
31
-        $customise['Height'] = $heightSet ? $arguments['height'] : 315;
32
-
33
-        //get our YouTube template
34
-        $template = new SSViewer('YouTube');
35
-
36
-        //return the customised template
37
-        return $template->process(new ArrayData($customise));
38
-    }
6
+	// taken from http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/ and adapted for SS3
7
+	public static function parse_youtube($arguments, $caption = null, $parser = null, $tagName)
8
+	{
9
+		// first things first, if we dont have a video ID, then we don't need to
10
+		// go any further
11
+		if (empty($arguments['id'])) {
12
+			return;
13
+		}
14
+
15
+		$customise = array();
16
+
17
+		// YouTube video id
18
+		$customise['YouTubeID'] = $arguments['id'];
19
+
20
+		//play the video on page load
21
+		$set = isset($arguments['autoplay']);
22
+		$customise['AutoPlay'] = $set ? true : false;
23
+
24
+		//set the caption
25
+		$customise['Caption'] = $caption ? Convert::raw2xml($caption) : false;
26
+
27
+		//set dimensions
28
+		$widthSet = isset($arguments['width']);
29
+		$heightSet = isset($arguments['height']);
30
+		$customise['Width'] = $widthSet ? $arguments['width'] : 560;
31
+		$customise['Height'] = $heightSet ? $arguments['height'] : 315;
32
+
33
+		//get our YouTube template
34
+		$template = new SSViewer('YouTube');
35
+
36
+		//return the customised template
37
+		return $template->process(new ArrayData($customise));
38
+	}
39 39
 }
Please login to merge, or discard this patch.
tests/YouTubeShortCodeHandlerTest.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -5,82 +5,82 @@
 block discarded – undo
5 5
 */
6 6
 class YouTubeShortCodeHandlerTest extends SapphireTest
7 7
 {
8
-    protected static $fixture_file = 'YouTubeShortCodeTest.yml';
8
+	protected static $fixture_file = 'YouTubeShortCodeTest.yml';
9 9
 
10
-    public function testVideoIdOnly()
11
-    {
12
-        $page = $this->objFromFixture('Page', 'VideoIdOnly');
13
-        $html = ShortcodeParser::get_active()->parse($page->Content);
14
-        $this->assertContains('<div class="YouTube">', $html);
15
-        $expected = '<iframe width="560" height="315" src="https://www.youtube'
16
-                  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
17
-                  . '></iframe>';
18
-        $this->assertContains($expected, $html);
19
-    }
10
+	public function testVideoIdOnly()
11
+	{
12
+		$page = $this->objFromFixture('Page', 'VideoIdOnly');
13
+		$html = ShortcodeParser::get_active()->parse($page->Content);
14
+		$this->assertContains('<div class="YouTube">', $html);
15
+		$expected = '<iframe width="560" height="315" src="https://www.youtube'
16
+				  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
17
+				  . '></iframe>';
18
+		$this->assertContains($expected, $html);
19
+	}
20 20
 
21
-    public function testVideoWithCaption()
22
-    {
23
-        $page = $this->objFromFixture('Page', 'VideoWithCaption');
24
-        $html = ShortcodeParser::get_active()->parse($page->Content);
25
-        $this->assertContains('<div class="YouTube">', $html);
26
-        $expected = '<iframe width="560" height="315" src="https://www.youtube'
27
-                  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
28
-                  . '></iframe>';
29
-        $this->assertContains('<p>This is a caption</p>', $html);
21
+	public function testVideoWithCaption()
22
+	{
23
+		$page = $this->objFromFixture('Page', 'VideoWithCaption');
24
+		$html = ShortcodeParser::get_active()->parse($page->Content);
25
+		$this->assertContains('<div class="YouTube">', $html);
26
+		$expected = '<iframe width="560" height="315" src="https://www.youtube'
27
+				  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
28
+				  . '></iframe>';
29
+		$this->assertContains('<p>This is a caption</p>', $html);
30 30
 
31
-        $this->assertContains($expected, $html);
32
-    }
31
+		$this->assertContains($expected, $html);
32
+	}
33 33
 
34
-    public function testVideoWithWidth()
35
-    {
36
-        $page = $this->objFromFixture('Page', 'VideoWithWidth');
37
-        $html = ShortcodeParser::get_active()->parse($page->Content);
38
-        $this->assertContains('<div class="YouTube">', $html);
39
-        $expected = '<iframe width="314" height="315" src="https://www.youtube'
40
-                  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
41
-                  . '></iframe>';
42
-        $this->assertContains($expected, $html);
43
-    }
34
+	public function testVideoWithWidth()
35
+	{
36
+		$page = $this->objFromFixture('Page', 'VideoWithWidth');
37
+		$html = ShortcodeParser::get_active()->parse($page->Content);
38
+		$this->assertContains('<div class="YouTube">', $html);
39
+		$expected = '<iframe width="314" height="315" src="https://www.youtube'
40
+				  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
41
+				  . '></iframe>';
42
+		$this->assertContains($expected, $html);
43
+	}
44 44
 
45
-    public function testVideoWithHeight()
46
-    {
47
-        $page = $this->objFromFixture('Page', 'VideoWithHeight');
48
-        $html = ShortcodeParser::get_active()->parse($page->Content);
49
-        $this->assertContains('<div class="YouTube">', $html);
50
-        $expected = '<iframe width="560" height="314" src="https://www.youtube'
51
-                  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
52
-                  . '></iframe>';
53
-        $this->assertContains($expected, $html);
54
-    }
45
+	public function testVideoWithHeight()
46
+	{
47
+		$page = $this->objFromFixture('Page', 'VideoWithHeight');
48
+		$html = ShortcodeParser::get_active()->parse($page->Content);
49
+		$this->assertContains('<div class="YouTube">', $html);
50
+		$expected = '<iframe width="560" height="314" src="https://www.youtube'
51
+				  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
52
+				  . '></iframe>';
53
+		$this->assertContains($expected, $html);
54
+	}
55 55
 
56
-    public function testVideoWithAll()
57
-    {
58
-        $page = $this->objFromFixture('Page', 'VideoWithAll');
59
-        $html = ShortcodeParser::get_active()->parse($page->Content);
60
-        $this->assertContains('<div class="YouTube">', $html);
61
-        $expected = '<iframe width="314" height="418" src="https://www.youtube'
62
-                  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
63
-                  . '></iframe>';
64
-        $this->assertContains($expected, $html);
65
-        $this->assertContains('<p>This is a caption</p>', $html);
66
-    }
56
+	public function testVideoWithAll()
57
+	{
58
+		$page = $this->objFromFixture('Page', 'VideoWithAll');
59
+		$html = ShortcodeParser::get_active()->parse($page->Content);
60
+		$this->assertContains('<div class="YouTube">', $html);
61
+		$expected = '<iframe width="314" height="418" src="https://www.youtube'
62
+				  . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""'
63
+				  . '></iframe>';
64
+		$this->assertContains($expected, $html);
65
+		$this->assertContains('<p>This is a caption</p>', $html);
66
+	}
67 67
 
68
-    public function testVideoWithNoID()
69
-    {
70
-        $page = $this->objFromFixture('Page', 'VideoWithNoID');
71
-        $html = ShortcodeParser::get_active()->parse($page->Content);
68
+	public function testVideoWithNoID()
69
+	{
70
+		$page = $this->objFromFixture('Page', 'VideoWithNoID');
71
+		$html = ShortcodeParser::get_active()->parse($page->Content);
72 72
 
73
-        $this->assertEquals('There should not be a video here ', $html);
74
-    }
73
+		$this->assertEquals('There should not be a video here ', $html);
74
+	}
75 75
 
76
-    public function testVideoWithNoAutoPlay()
77
-    {
78
-        $page = $this->objFromFixture('Page', 'VideoWithNoAutoPlay');
79
-        $html = ShortcodeParser::get_active()->parse($page->Content);
80
-        $this->assertContains('<div class="YouTube">', $html);
81
-        $expected = '<iframe width="560" height="315" src="https://www.youtube.'
82
-                  . 'com/embed/5XQwWATPReA&amp;AutoPlay=1" frameborder="0" allo'
83
-                  . 'wfullscreen="">';
84
-        $this->assertContains($expected, $html);
85
-    }
76
+	public function testVideoWithNoAutoPlay()
77
+	{
78
+		$page = $this->objFromFixture('Page', 'VideoWithNoAutoPlay');
79
+		$html = ShortcodeParser::get_active()->parse($page->Content);
80
+		$this->assertContains('<div class="YouTube">', $html);
81
+		$expected = '<iframe width="560" height="315" src="https://www.youtube.'
82
+				  . 'com/embed/5XQwWATPReA&amp;AutoPlay=1" frameborder="0" allo'
83
+				  . 'wfullscreen="">';
84
+		$this->assertContains($expected, $html);
85
+	}
86 86
 }
Please login to merge, or discard this patch.