PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / Renderer / CustomerDashboardButtonRenderer.php

CustomerDashboardButtonRenderer.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/Renderer/CustomerDashboardButtonRenderer.php

88 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\Renderer;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\App\Services\TemplateService;
7 use FluentCart\Framework\Support\Arr;
8
9 class CustomerDashboardButtonRenderer
10 {
11
12 public function render(array $atts = []): void
13 {
14 $this->renderButton($atts);
15 }
16
17 protected function renderButton($atts = []): void
18 {
19 $displayType = Arr::get($atts, 'display_type', 'button');
20 $buttonText = Arr::get($atts, 'button_text', '');
21 $isShortcode = Helper::toBool(Arr::get($atts, 'is_shortcode', false));
22 $linkTarget = Arr::get($atts, 'link_target', '_self');
23 $showIcon = Helper::toBool(Arr::get($atts, 'show_icon', true), true);
24 $customClass = trim(Arr::get($atts, 'class', ''));
25 $extraClass = trim(Arr::get($atts, 'extra_class', ''));
26
27 if (empty($buttonText)) {
28 $buttonText = __('My Account', 'fluent-cart');
29 }
30
31 $class = $customClass ?: ($displayType === 'button'
32 ? 'wp-block-button__link wp-element-button fct-customer-dashboard-btn'
33 : 'fct-customer-dashboard-link');
34
35 $linkAtts = [
36 'href' => TemplateService::getCustomerProfileUrl(),
37 'class' => $class,
38 'aria-label' => $buttonText,
39 'target' => $linkTarget,
40 ];
41
42 if ($linkTarget === '_blank') {
43 $linkAtts['rel'] = 'noopener noreferrer';
44 }
45
46 if ($extraClass) {
47 $linkAtts['class'] .= ' ' . $extraClass;
48 }
49
50 if ($isShortcode) {
51 ob_start();
52 $this->renderAttributes($linkAtts);
53 $wrapperAttributes = ob_get_clean();
54 } else {
55 $wrapperAttributes = RenderHelper::getBlockWrapperAttributes($linkAtts);
56 }
57
58 ?>
59 <a <?php echo
60 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
61 $wrapperAttributes; ?> >
62 <?php if ($showIcon): ?>
63 <span class="fct-customer-dashboard-icon">
64 <?php echo $this->getUserIcon(); ?>
65 </span>
66 <?php endif; ?>
67 <span><?php echo wp_kses_post($buttonText); ?></span>
68 </a>
69 <?php
70 }
71
72 protected function getUserIcon(): string
73 {
74 return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="24" height="24"><path d="M20 22H18V20C18 18.3431 16.6569 17 15 17H9C7.34315 17 6 18.3431 6 20V22H4V20C4 17.2386 6.23858 15 9 15H15C17.7614 15 20 17.2386 20 20V22ZM12 13C8.68629 13 6 10.3137 6 7C6 3.68629 8.68629 1 12 1C15.3137 1 18 3.68629 18 7C18 10.3137 15.3137 13 12 13ZM12 11C14.2091 11 16 9.20914 16 7C16 4.79086 14.2091 3 12 3C9.79086 3 8 4.79086 8 7C8 9.20914 9.79086 11 12 11Z"></path></svg>';
75 }
76
77 protected function renderAttributes($atts = []): void
78 {
79 foreach ($atts as $attr => $value) {
80 if ($value !== '') {
81 echo esc_attr($attr) . '="' . esc_attr((string)$value) . '" ';
82 } else {
83 echo esc_attr($attr);
84 }
85 }
86 }
87 }
88