PluginProbe
Polylang / trunk
Polylang vtrunk
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / src / Switcher / Element / Nav.php

Nav.php in Polylang trunk, at src/Switcher/Element/Nav.php

97 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 namespace WP_Syntex\Polylang\Switcher\Element;
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Data representing an item.
12 *
13 * @since 3.9
14 */
15 class Nav extends Abstract_Element {
16 /**
17 * Returns the markup of a row.
18 *
19 * @since 3.9
20 *
21 * @return string
22 */
23 public function get(): string {
24 $out = sprintf(
25 '<li class="%s">%s</li>',
26 esc_attr( implode( ' ', $this->item_classes ) ),
27 $this->get_link()
28 );
29
30 if ( ! $this->settings->preserve_spacing ) {
31 return $out;
32 }
33
34 return "\t{$out}\n";
35 }
36
37 /**
38 * Returns the markup of a link.
39 *
40 * @since 3.9
41 *
42 * @return string
43 */
44 public function get_link(): string {
45 $link_atts = sprintf(
46 'lang="%1$s" hreflang="%1$s" href="%2$s"',
47 esc_attr( $this->locale ),
48 esc_url( $this->url )
49 );
50
51 if ( ! empty( $this->link_classes ) ) {
52 $link_atts .= sprintf(
53 ' class="%s"',
54 esc_attr( implode( ' ', $this->link_classes ) )
55 );
56 }
57
58 if ( $this->is_current ) {
59 $link_atts .= ' aria-current="true"';
60 }
61
62 return sprintf( '<a %s>%s</a>', $link_atts, $this->get_label() );
63 }
64
65 /**
66 * Returns the markup of the label of a row.
67 *
68 * @since 3.9
69 *
70 * @return string
71 */
72 public function get_label(): string {
73 $label = '';
74
75 if ( ! empty( $this->flag ) ) {
76 // Keep these inline styles in sync with `css/src/lib/switcher-flags.css`.
77 $label .= sprintf(
78 '<span class="pll-switcher-flag" style="%1$s">%2$s</span>',
79 esc_attr(
80 sprintf(
81 'display:inline-block;flex-shrink:0;width:var(--pll-flag-width,18px);overflow:hidden;border-radius:calc(var(--pll-flag-border-radius,0)*.5*1%%);aspect-ratio:%s',
82 str_replace( ':', '/', $this->settings->flag_aspect_ratio )
83 )
84 ),
85 $this->flag
86 );
87 }
88
89 if ( ! empty( $this->label ) ) {
90 $style = empty( $this->flag ) ? '' : ' style="margin-inline-start:var(--pll-flag-label-spacing,0.3em);writing-mode:horizontal-tb"';
91 $label .= sprintf( '<span class="pll-switcher-label"%1$s>%2$s</span>', $style, esc_html( $this->label ) );
92 }
93
94 return $label;
95 }
96 }
97