Skip to content

Commit

Permalink
Merge pull request #27 from catalyst/fix-video-button-alignment
Browse files Browse the repository at this point in the history
Add wrapper class to center video alignment using flexbox
  • Loading branch information
Peterburnett authored Feb 10, 2022
2 parents 6b72238 + 73adb86 commit 16b5db6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
2 changes: 0 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace filter_smartmedia\privacy;

defined('MOODLE_INTERNAL') || die();

/**
* Privacy Subsystem for filter_smartmedia implementing null_provider.
*
Expand Down
19 changes: 14 additions & 5 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

use local_smartmedia\aws_api;
use local_smartmedia\aws_elastic_transcoder;

Expand Down Expand Up @@ -442,7 +440,13 @@ private function replace($target, $fulltext) : string {

// Get the complete smartmedia markup.
$hasdata = !empty($elements['metadata']);
$replacedlink = $this->get_embed_markup($target, $elements['urls'], $elements['options'], $elements['download'], $hasdata);
$replacedlink = $this->get_embed_markup(
$target,
$elements['urls'],
$elements['options'],
$elements['download'],
$hasdata
);

if (has_capability('filter/smartmedia:viewsource', $context)) {
// Add a button to view source.
Expand Down Expand Up @@ -628,8 +632,13 @@ public function filter($text, array $options = array()) {
}
}

// Then return the raw html minus the wrapping div.
return substr(trim($originaldom->saveHTML()), 5, -6);
// The raw html minus the wrapping div.
$html = substr(trim($originaldom->saveHTML()), 5, -6);

// Add a wrapper class to all smart media video content, so it can be styled further later on.
$html = preg_replace('/(mediaplugin mediaplugin_videojs)/', '$1 local-smartmedia-wrapper', $html);

return $html;
}

}
7 changes: 7 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@
.local-smartmedia-view-source {
text-align: center;
}

.local-smartmedia-wrapper > div {
display: flex;
flex-direction: column;
align-items: center;
}

27 changes: 13 additions & 14 deletions tests/filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class filter_smartmedia_testcase extends advanced_testcase {
*/
public function setUp() {
$this->resetAfterTest(true);
global $CFG;
set_config('api_region', 'ap-southeast-2', 'local_smartmedia');
set_config('api_key', 'somefakekey', 'local_smartmedia');
set_config('api_secret', 'somefakesecret', 'local_smartmedia');
Expand Down Expand Up @@ -288,80 +287,80 @@ public function test_get_placeholder_markkup() {


public function test_filter_replace_dataprovider() {
// Return [text, regex to match in output, match count]
// Return [text, regex to match in output, match count].
return [
// <a>, Legit video link.
// Test <a>, Legit video link.
[
html_writer::link('url.com/pluginfile.php/fake.mp4', 'My Fake Video'),
'~<video~',
1
],
// <a>, Not supported extension.
// Test <a>, Not supported extension.
[
html_writer::link('url.com/pluginfile.php/fake.wtf', 'My Fake Video'),
'~pluginfile\.php/fake\.wtf~',
1
],
// <a>, Not a pluginfile.
// Test <a>, Not a pluginfile.
[
html_writer::link('url.com/dodgypage.php/fake.mp4', 'My Fake Video'),
'~dodgypage\.php/fake\.mp4~',
1
],
// <a>, 2 legit links.
// Test <a>, 2 legit links.
[
'<div>' . html_writer::link('url.com/pluginfile.php/fake.mp4', 'My Fake Video') .
html_writer::link('url.com/pluginfile.php/fake.mp4', 'The Other Fake Video') . '</div>',
'~<video~',
2
],
// <a>, 1 legit, 1 not.
// Test <a>, 1 legit, 1 not.
[
html_writer::link('url.com/pluginfile.php/fake.mp4', 'My Fake Video') .
html_writer::link('url.com/dodgypage.php/fake.mp4', 'The Other Fake Video'),
'~<video~',
1
],
// <video>, legit element.
// Test <video>, legit element.
[
'<video><source src="url.com/pluginfile.php/fake.mp4"/></video>',
'~pluginfile\.php.*fakename\.mp4~',
1
],
// <video>, bad extension.
// Test <video>, bad extension.
[
'<video><source src="url.com/pluginfile.php/fake.wtf"/></video>',
'~pluginfile\.php/fake\.wtf~',
1
],
// <video>, not a pluginfile.
// Test <video>, not a pluginfile.
[
'<video><source src="url.com/dodgypage.php/fake.mp4"/></video>',
'~dodgypage\.php/fake\.mp4~',
1
],
// <video>, 2 legit elements.
// Test <video>, 2 legit elements.
[
'<video><source src="url.com/pluginfile.php/fake.mp4"/></video>' .
'<video><source src="url.com/pluginfile.php/fake.mp4"/></video>',
'~pluginfile\.php.*?fakename\.mp4?~',
2
],
// <video> then <a>, 2 legit elements.
// Test <video> then <a>, 2 legit elements.
[
'<video><source src="url.com/pluginfile.php/fake.mp4"/></video>' .
html_writer::link('url.com/pluginfile.php/fake.mp4', 'My Fake Video'),
'~pluginfile\.php.*?fakename\.mp4?~',
2
],
// <a> then <video>, 2 legit elements.
// Test <a> then <video>, 2 legit elements.
[
html_writer::link('url.com/pluginfile.php/fake.mp4', 'My Fake Video') .
'<video><source src="url.com/pluginfile.php/fake.mp4"/></video>',
'~pluginfile\.php.*?fakename\.mp4~',
2
],
// <a> then <video>, 2 legit elements and one naughty.
// Test <a> then <video>, 2 legit elements and one naughty.
[
html_writer::link('url.com/pluginfile.php/fake.mp4', 'My Fake Video') .
'<video><source src="url.com/pluginfile.php/fake.mp4"/></video>' .
Expand Down

0 comments on commit 16b5db6

Please sign in to comment.