root with the quote, author caption and a Tweet intent link. The tweet text * mirrors widgets/blockquote/tweet.ts; frontend.ts appends the page URL (&url=). * * @var array $settings * @var string $attrs * @var array $element * @var \Zadex\Frontend\Renderer $renderer */ if (!defined('ABSPATH')) { exit; } // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template variables are local to Zadex\Frontend\Renderer::include_template(). if (!function_exists('zadex_blockquote_plain')) { function zadex_blockquote_plain(string $html): string { $text = html_entity_decode(wp_strip_all_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8'); return trim((string) preg_replace('/[\s\x{00a0}]+/u', ' ', $text)); } /** Mirrors tweetText() + tweetUrl() in tweet.ts (240 code points, rawurlencode = RFC 3986). */ function zadex_blockquote_tweet_url(string $quote, string $zx_author = '', string $via = '', string $url = ''): string { $q = zadex_blockquote_plain($quote); if (mb_strlen($q, 'UTF-8') > 240) { $q = rtrim(mb_substr($q, 0, 239, 'UTF-8')) . "\u{2026}"; } $a = zadex_blockquote_plain($zx_author); $text = "\u{201c}" . $q . "\u{201d}" . ($a !== '' ? " \u{2014} " . $a : ''); $out = 'https://twitter.com/intent/tweet?text=' . rawurlencode($text); $v = (string) preg_replace('/[^A-Za-z0-9_]/', '', $via); if ($v !== '') { $out .= '&via=' . rawurlencode($v); } if ($url !== '') { $out .= '&url=' . rawurlencode($url); } return $out; } } $skins = ['border', 'quotation', 'boxed', 'clean']; $skin = in_array($settings['skin'] ?? 'border', $skins, true) ? $settings['skin'] : 'border'; $attrs = preg_replace('/class="/', 'class="zx-blockquote--' . esc_attr($skin) . ' ', $attrs, 1); $quote = is_scalar($settings['quote'] ?? null) ? (string) $settings['quote'] : ''; $zx_author = is_scalar($settings['author'] ?? null) ? trim((string) $settings['author']) : ''; $zx_title = is_scalar($settings['author_title'] ?? null) ? trim((string) $settings['author_title']) : ''; $cite = is_scalar($settings['cite_url'] ?? null) ? trim((string) $settings['cite_url']) : ''; $cite = $cite !== '' ? esc_url($cite) : ''; $tweet = !empty($settings['tweet_button']) && zadex_blockquote_plain($quote) !== ''; $label = trim((string) ($settings['tweet_label'] ?? '')) !== '' ? (string) $settings['tweet_label'] : __('Tweet', 'zadex'); $caption = ''; if ($zx_author !== '' || $zx_title !== '') { $caption .= '' . ($zx_author !== '' ? '' . esc_html($zx_author) . '' : '') . ($zx_title !== '' ? '' . esc_html($zx_title) . '' : '') . ''; } if ($tweet) { $href = zadex_blockquote_tweet_url($quote, $zx_author, (string) ($settings['via'] ?? '')); $caption .= '' . '' . '' . esc_html($label) . ''; } $zx_html = '' . '' . wp_kses_post($quote) . '' . ($caption !== '' ? '' . $caption . '' : '') . "\n"; echo wp_kses($zx_html, \Zadex\Frontend\Kses::allowed_html());
' . '' . wp_kses_post($quote) . '
' . wp_kses_post($quote) . '