2020-07-27 09:35:34 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-07-27 09:35:34 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-07-27 09:35:34 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('icon')) {
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* Returns the inline svg icon
|
|
|
|
*
|
|
|
|
* @param string $name name of the icon file without the .svg extension
|
|
|
|
* @param string $class to be added to the svg string
|
2022-02-24 14:48:17 +00:00
|
|
|
* @param 'social'|'podcasting'|'funding' $type type of icon to be added
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return string svg contents
|
|
|
|
*/
|
2022-02-24 14:48:17 +00:00
|
|
|
function icon(string $name, string $class = '', string $type = null): string
|
2021-05-06 14:00:48 +00:00
|
|
|
{
|
2022-02-24 14:48:17 +00:00
|
|
|
if ($type !== null) {
|
|
|
|
$name = $type . '/' . $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$svgContents = file_get_contents('assets/icons/' . $name . '.svg');
|
|
|
|
} catch (Exception) {
|
|
|
|
if ($type !== null) {
|
|
|
|
return icon('default', $class, $type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '□';
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($class !== '') {
|
2021-06-08 09:52:11 +00:00
|
|
|
$svgContents = str_replace('<svg', '<svg class="' . $class . '"', $svgContents);
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
2020-10-02 15:38:16 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
return $svgContents;
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
2020-07-27 09:35:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('svg')) {
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* Returns the inline svg image
|
|
|
|
*
|
|
|
|
* @param string $name name of the image file without the .svg extension
|
|
|
|
* @param string $class to be added to the svg string
|
|
|
|
* @return string svg contents
|
|
|
|
*/
|
|
|
|
function svg(string $name, ?string $class = null): string
|
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
$svgContents = file_get_contents('assets/images/' . $name . '.svg');
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($class) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$svgContents = str_replace('<svg', '<svg class="' . $class . '"', $svgContents);
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
return $svgContents;
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
|
|
|
}
|