Commit 2bb22fa5 authored by Robert Lyon's avatar Robert Lyon

Bug 1838915: Allow externalmedia / iframe sources to use FontAwsome icons if available

behatnotneeded

Change-Id: Ib060fef54ac3ef4a1b881743ed00774e9eb6424a
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent a1595373
...@@ -19,9 +19,20 @@ define('SECTION_PAGE', 'iframesites'); ...@@ -19,9 +19,20 @@ define('SECTION_PAGE', 'iframesites');
require(dirname(dirname(dirname(__FILE__))) . '/init.php'); require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('upgrade.php'); require_once('upgrade.php');
define('TITLE', get_string('allowediframesites', 'admin')); define('TITLE', get_string('allowediframesites', 'admin'));
safe_require('blocktype', 'externalvideo');
$iframesources = get_records_menu('iframe_source', '', '', 'name,prefix'); $iframesources = get_records_menu('iframe_source', '', '', 'name,prefix');
$iframedomains = get_records_menu('iframe_source_icon'); $iframedomains = get_records_menu('iframe_source_icon');
$fa_domains = PluginBlocktypeExternalvideo::get_fa_brand_icons();
$data = array();
foreach ($iframedomains as $name => $domain) {
$data[$name]['name'] = $domain;
$data[$name]['icon'] = favicon_display_url($domain);
$lname = strtolower($name);
if (isset($fa_domains[$lname])) {
$data[$name]['faicon'] = $fa_domains[$lname]['faicon'];
$data[$name]['style'] = $fa_domains[$lname]['style'];
}
}
$newform = pieform(array( $newform = pieform(array(
'name' => 'newurl', 'name' => 'newurl',
...@@ -85,7 +96,7 @@ foreach ($iframesources as $url => $name) { ...@@ -85,7 +96,7 @@ foreach ($iframesources as $url => $name) {
'id' => $i, 'id' => $i,
'url' => $url, 'url' => $url,
'name' => $name, 'name' => $name,
'icon' => favicon_display_url($iframedomains[$name]), 'icon' => $data[$name],
'editform' => pieform(array( 'editform' => pieform(array(
'name' => 'editurl_' . $i, 'name' => 'editurl_' . $i,
'successcallback' => 'editurl_submit', 'successcallback' => 'editurl_submit',
......
...@@ -364,6 +364,17 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -364,6 +364,17 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
return false; return false;
} }
public static function get_fa_brand_icons() {
return array(
'slideshare' => array('faicon' => 'slideshare', 'style' => 'color: #0077B5'),
'vimeo' => array('faicon' => 'vimeo-square', 'style' => 'color: #1AB7EA'),
'youtube' => array('faicon' => 'youtube', 'style' => 'color: #FF0000'),
'youtube [privacy mode]' => array('faicon' => 'youtube-square', 'style' => 'color: #FF0000'),
'google' => array('faicon' => 'google', 'style' => 'color: #4285f4'),
'googlevideo' => array('faicon' => 'google', 'style' => 'color: #4285f4'),
);
}
/** /**
* Returns a block of HTML that the external video block can use to show the * Returns a block of HTML that the external video block can use to show the
* sites for which we will process URLs. * sites for which we will process URLs.
...@@ -372,6 +383,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -372,6 +383,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
$source_instances = self::load_media_sources(); $source_instances = self::load_media_sources();
$wwwroot = get_config('wwwroot'); $wwwroot = get_config('wwwroot');
$fa_domains = self::get_fa_brand_icons();
$data = array(); $data = array();
foreach ($source_instances as $name => $source) { foreach ($source_instances as $name => $source) {
$sourcestr = get_string($name, 'blocktype.externalvideo'); $sourcestr = get_string($name, 'blocktype.externalvideo');
...@@ -380,8 +392,12 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -380,8 +392,12 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
'url' => $source->get_base_url(), 'url' => $source->get_base_url(),
'icon' => $wwwroot . 'blocktype/externalvideo/media_sources/' . $name . '/favicon.png', 'icon' => $wwwroot . 'blocktype/externalvideo/media_sources/' . $name . '/favicon.png',
); );
$lname = strtolower($name);
if (isset($fa_domains[$lname])) {
$data[$sourcestr]['faicon'] = $fa_domains[$lname]['faicon'];
$data[$sourcestr]['style'] = $fa_domains[$lname]['style'];
}
} }
ksort($data); ksort($data);
$smarty = smarty_core(); $smarty = smarty_core();
...@@ -398,7 +414,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -398,7 +414,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
if (empty($iframedomains)) { if (empty($iframedomains)) {
return ''; return '';
} }
$fa_domains = self::get_fa_brand_icons();
$data = array(); $data = array();
foreach ($iframedomains as $name => $host) { foreach ($iframedomains as $name => $host) {
$data[$name] = array( $data[$name] = array(
...@@ -406,6 +422,11 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -406,6 +422,11 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
'url' => 'http://' . $host, 'url' => 'http://' . $host,
'icon' => favicon_display_url($host), 'icon' => favicon_display_url($host),
); );
$lname = strtolower($name);
if (isset($fa_domains[$lname])) {
$data[$name]['faicon'] = $fa_domains[$lname]['faicon'];
$data[$name]['style'] = $fa_domains[$lname]['style'];
}
} }
$smarty = smarty_core(); $smarty = smarty_core();
...@@ -433,6 +454,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -433,6 +454,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
} }
} }
else { else {
$fa_domains = self::get_fa_brand_icons();
foreach ($service_instances as $name => $service) { foreach ($service_instances as $name => $service) {
$servicestr = get_string($name, 'blocktype.externalvideo'); $servicestr = get_string($name, 'blocktype.externalvideo');
$data[$servicestr] = array( $data[$servicestr] = array(
...@@ -440,6 +462,11 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype { ...@@ -440,6 +462,11 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
'url' => $service->get_base_url(), 'url' => $service->get_base_url(),
'icon' => $wwwroot . 'blocktype/externalvideo/embed_services/' . $name . '/favicon.png', 'icon' => $wwwroot . 'blocktype/externalvideo/embed_services/' . $name . '/favicon.png',
); );
$lname = strtolower($name);
if (isset($fa_domains[$lname])) {
$data[$sourcestr]['faicon'] = $fa_domains[$lname]['faicon'];
$data[$sourcestr]['style'] = $fa_domains[$lname]['style'];
}
} }
} }
......
<ul class="text-inline unstyled"> <ul class="text-inline unstyled">
{foreach from=$data item=item} {foreach from=$data item=item}
<li class="text-inline"><a href="{$item.url}"><img src="{$item.icon}" alt="{$item.name}" title="{$item.name}"></a></li> <li class="text-inline"><a href="{$item.url}">
{if $item.faicon}
<span class="icon icon-lg icon-{$item.faicon} icon-brand" style="{$item.style}"></span>
{else}
<img src="{$item.icon}" alt="{$item.name}" title="{$item.name}">
{/if}</a></li>
{/foreach} {/foreach}
</ul> </ul>
\ No newline at end of file
...@@ -15,8 +15,12 @@ ...@@ -15,8 +15,12 @@
<tbody> <tbody>
{foreach from=$editurls item=item name=urls} {foreach from=$editurls item=item name=urls}
<tr class="{cycle values='r0,r1' advance=false}"> <tr class="{cycle values='r0,r1' advance=false}">
<th>{if $item.icon.faicon}
<th><img src="{$item.icon}" alt="{$item.name}" title="{$item.name}">&nbsp;{$item.name}</th> <span class="icon icon-lg icon-brand icon-{$item.icon.faicon}" style="{$item.icon.style}" alt="{$item.name}" title="{$item.name}"></span>
{else}
<img src="{$item.icon.icon}" alt="{$item.name}" title="{$item.name}">
{/if}
{$item.name}</th>
<td>{$item.url}</td> <td>{$item.url}</td>
<td class="buttonscell"> <td class="buttonscell">
<div class="btn-group"> <div class="btn-group">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment