<?php
/**
* Activation class.
*
* @package Magazine Blocks
* @since 1.0.0
*/
namespace MagazineBlocks;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit();
/**
* Class Icon
*/
class Icon {
/**
* Allowed HTML.
*
* @var bool[][]
*/
public static $allowed_html = array(
'svg' => array(
'class' => true,
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'aria-hidden' => true,
'role' => true,
'focusable' => true,
),
'path' => array(
'fill' => true,
'fill-rule' => true,
'd' => true,
'transform' => true,
),
'circle' => array(
'cx' => true,
'cy' => true,
'r' => true,
),
'polygon' => array(
'fill' => true,
'fill-rule' => true,
'points' => true,
'transform' => true,
'focusable' => true,
),
);
/**
* Get the SVG icon.
*
* @param string $icon Default is empty.
* @param bool $echo Default is true.
* @param array $args Default is empty.
* @return string|null
*/
public static function get_svg( $icon = '', $echo = true, $args = array() ) {
$icons = self::get_icons();
$atts = '';
$svg = '';
if ( ! empty( $args ) ) {
foreach ( $args as $key => $value ) {
if ( ! empty( $value ) ) {
$atts .= esc_html( $key ) . '="' . esc_attr( $value ) . '" ';
}
}
}
if ( array_key_exists( $icon, $icons ) ) {
$repl = sprintf( '<svg class="mzb-icon mzb-icon--%1$s" %2$s', $icon, $atts );
$svg = preg_replace( '/^<svg /', $repl, trim( $icons[ $icon ] ) );
$svg = preg_replace( "/([\n\t]+)/", ' ', $svg );
$svg = preg_replace( '/>\s*</', '><', $svg );
}
if ( ! $svg ) {
return null;
}
if ( $echo ) {
echo wp_kses( $svg, self::$allowed_html );
} else {
return wp_kses( $svg, self::$allowed_html );
}
}
/**
* Get all SVG icons.
*
* @return mixed|void
*/
public static function get_icons() {
/**
* Filter for svg icons.
*
* @since 1.0.0
*/
return apply_filters( 'icons', self::$icons );
}
/**
* SVG icons.
*
* @var string[]
*/
public static $icons = array(
'yelp' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19.6 17.3c-.1.8-1.7 2.9-2.5 3.2-.3.1-.5.1-.7-.1-.1-.1-.3-.3-2-3.2l-.5-.9c-.2-.3-.2-.7.1-1 .3-.3.6-.4 1-.3l1.3.4c3 1 3.1 1 3.2 1.1.1.2.2.5.1.8zm-6-4.5c-.2-.3-.2-.7 0-1l.9-1.1c1.8-2.5 1.9-2.6 2.1-2.7.2-.2.4-.2.7 0 .7.3 2.2 2.5 2.3 3.4 0 .3-.1.5-.3.7-.2.1-.3.2-3.7 1-.5.2-.9.2-1 .3-.4 0-.8-.2-1-.6zm-2.1-1.3c-.2.1-.7.2-1.3-.8 0 0-4.1-6.4-4.2-6.7-.1-.1 0-.3.2-.6.6-.6 3.9-1.6 4.8-1.4.3.1.5.3.5.5.1.3.4 6.3.5 7.7.2 1.1-.3 1.3-.5 1.3zm.6 6.6c0 3.1 0 3.2-.1 3.4-.1.3-.3.4-.6.4-.8.2-3.3-.8-3.8-1.4-.1-.2-.2-.3-.2-.4v-.3c.1-.2.2-.3 2.4-3l.7-.8c.3-.3.6-.3 1-.3.3.2.6.4.5.8v1.6zm-6.9-2c-.3 0-.4-.2-.6-.4-.1-.2-.2-.4-.2-.9-.1-1 0-2.7.3-3.2.2-.3.3-.3.6-.3.2 0 .3.1 3.6 1.4l1 .3c.3.1.5.4.5.9 0 .3-.3.7-.6.8l-1.3.4c-3 1-3.1 1-3.3 1z" /></svg>',
'flash' => '<svg xmlns="http://www.w3.org/2000/svg"><path d="M8.90179 4.33928C9.00893 4.45833 9.02976 4.58929 8.96429 4.73214L4.14286 15.0625C4.06548 15.2113 3.94048 15.2857 3.76786 15.2857C3.74405 15.2857 3.70238 15.2798 3.64286 15.2679C3.54167 15.2381 3.46429 15.1815 3.41071 15.0982C3.3631 15.0149 3.35119 14.9256 3.375 14.8304L5.13393 7.61607L1.50893 8.51786C1.48512 8.52381 1.4494 8.52679 1.40179 8.52679C1.29464 8.52679 1.20238 8.49405 1.125 8.42857C1.01786 8.33929 0.979167 8.22321 1.00893 8.08036L2.80357 0.714285C2.82738 0.630952 2.875 0.562499 2.94643 0.508928C3.01786 0.455357 3.10119 0.428571 3.19643 0.428571H6.125C6.2381 0.428571 6.33333 0.467261 6.41071 0.544642C6.4881 0.616071 6.52679 0.70238 6.52679 0.803571C6.52679 0.85119 6.5119 0.904761 6.48214 0.964285L4.95536 5.09821L8.49107 4.22321C8.53869 4.21131 8.57441 4.20536 8.59821 4.20536C8.71131 4.20536 8.8125 4.25 8.90179 4.33928Z"></path></svg>',
);
}