| 1 |
<?php |
| 2 |
/** |
| 3 |
* The plugin's brand mark, and a kses list that can actually print it. |
| 4 |
* |
| 5 |
* `wp_kses_post()` has no <svg> in its allow-list, so the logo the sidebar |
| 6 |
* has always built was being stripped down to its coloured square. Anything |
| 7 |
* that echoes logo markup — including the White-Label addon's replacement — |
| 8 |
* goes through `easy_invoice_kses_logo()` instead. |
| 9 |
* |
| 10 |
* @package EasyInvoice |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! function_exists( 'easy_invoice_logo_allowed_html' ) ) { |
| 18 |
/** |
| 19 |
* post allow-list + the SVG subset the brand mark needs. |
| 20 |
* |
| 21 |
* @return array<string, array<string, bool>> |
| 22 |
*/ |
| 23 |
function easy_invoice_logo_allowed_html() { |
| 24 |
$shared = [ |
| 25 |
'class' => true, 'style' => true, 'fill' => true, 'stroke' => true, |
| 26 |
'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, |
| 27 |
'opacity' => true, 'transform' => true, |
| 28 |
]; |
| 29 |
|
| 30 |
return array_merge( |
| 31 |
wp_kses_allowed_html( 'post' ), |
| 32 |
[ |
| 33 |
'svg' => array_merge( $shared, [ |
| 34 |
'xmlns' => true, 'viewbox' => true, 'width' => true, 'height' => true, |
| 35 |
'aria-hidden' => true, 'role' => true, 'focusable' => true, |
| 36 |
] ), |
| 37 |
'g' => $shared, |
| 38 |
'defs' => [], |
| 39 |
'title' => [], |
| 40 |
'lineargradient' => [ 'id' => true, 'x1' => true, 'y1' => true, 'x2' => true, 'y2' => true, 'gradientunits' => true ], |
| 41 |
'stop' => [ 'offset' => true, 'stop-color' => true, 'stop-opacity' => true ], |
| 42 |
'path' => array_merge( $shared, [ 'd' => true ] ), |
| 43 |
'rect' => array_merge( $shared, [ 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true, 'ry' => true ] ), |
| 44 |
'circle' => array_merge( $shared, [ 'cx' => true, 'cy' => true, 'r' => true ] ), |
| 45 |
'line' => array_merge( $shared, [ 'x1' => true, 'y1' => true, 'x2' => true, 'y2' => true ] ), |
| 46 |
'polyline' => array_merge( $shared, [ 'points' => true ] ), |
| 47 |
'polygon' => array_merge( $shared, [ 'points' => true ] ), |
| 48 |
'use' => array_merge( $shared, [ 'href' => true, 'xlink:href' => true ] ), |
| 49 |
] |
| 50 |
); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
if ( ! function_exists( 'easy_invoice_kses_logo' ) ) { |
| 55 |
/** |
| 56 |
* Sanitise logo markup without losing the SVG. |
| 57 |
* |
| 58 |
* @param string $html Logo markup. |
| 59 |
* @return string |
| 60 |
*/ |
| 61 |
function easy_invoice_kses_logo( $html ) { |
| 62 |
return wp_kses( $html, easy_invoice_logo_allowed_html() ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if ( ! function_exists( 'easy_invoice_logo_mark_svg' ) ) { |
| 67 |
/** |
| 68 |
* The brand mark: the same document-and-tick used for the WordPress.org |
| 69 |
* icon and the admin menu, in colour. |
| 70 |
* |
| 71 |
* @param int $size Square size in pixels. |
| 72 |
* @return string |
| 73 |
*/ |
| 74 |
function easy_invoice_logo_mark_svg( $size = 32 ) { |
| 75 |
$size = (int) $size; |
| 76 |
$id = 'ei-logo-g'; |
| 77 |
|
| 78 |
return '<svg class="ei-app-logo-svg" width="' . $size . '" height="' . $size . '" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">' |
| 79 |
. '<defs><lineargradient id="' . $id . '" x1="0" y1="0" x2="48" y2="48" gradientunits="userSpaceOnUse">' |
| 80 |
. '<stop offset="0" stop-color="#4F46E5"/><stop offset="1" stop-color="#0EA5E9"/>' |
| 81 |
. '</lineargradient></defs>' |
| 82 |
. '<rect x="0" y="0" width="48" height="48" rx="12" fill="url(#' . $id . ')"/>' |
| 83 |
. '<rect x="13" y="9" width="22" height="28" rx="3" fill="#FFFFFF"/>' |
| 84 |
. '<path d="M18 17h12M18 22h12M18 27h6" stroke="#CBD5E1" stroke-width="2.4" stroke-linecap="round"/>' |
| 85 |
. '<path d="M18 27h6" stroke="#4F46E5" stroke-width="2.4" stroke-linecap="round"/>' |
| 86 |
. '<circle cx="34" cy="33" r="7.5" fill="#10B981" stroke="#FFFFFF" stroke-width="2.2"/>' |
| 87 |
. '<path d="M30.8 33.2l2.2 2.2 4.2-4.6" stroke="#FFFFFF" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>' |
| 88 |
. '</svg>'; |
| 89 |
} |
| 90 |
} |
| 91 |
|