Remove deprecated widget locations and widgets, standardize sidebar labels, and render a compact paid-post purchase card in the article sidebar.
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Header and mobile navigation language controls.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
/**
|
|
* Header language dropdown (zibll zib_get_translate_language_btn).
|
|
* Uses SPA i18n_available_langs when i18n enabled and position includes header.
|
|
*
|
|
* @param string $class Extra classes.
|
|
*/
|
|
function aksrt_get_translate_language_btn(string $class = ''): string {
|
|
if (!class_exists('\AKSRT\Settings\Settings')) {
|
|
return '';
|
|
}
|
|
$cfg = \AKSRT\Settings\Settings::get_i18n_config();
|
|
if (empty($cfg['enabled'])) {
|
|
return '';
|
|
}
|
|
$pos = (string) ($cfg['switcherPosition'] ?? 'footer');
|
|
if (!in_array($pos, ['header', 'both'], true)) {
|
|
return '';
|
|
}
|
|
|
|
$raw = (string) ($cfg['availableLangs'] ?? '');
|
|
$buttons = [];
|
|
foreach (preg_split('/\r\n|\r|\n/', $raw) as $line) {
|
|
$line = trim($line);
|
|
if ($line === '' || strpos($line, '|') === false) {
|
|
continue;
|
|
}
|
|
[$code, $label] = array_map('trim', explode('|', $line, 2));
|
|
if ($code === '' || $label === '') {
|
|
continue;
|
|
}
|
|
$buttons[] = ['language' => $code, 'text' => $label];
|
|
}
|
|
if (!$buttons) {
|
|
return '';
|
|
}
|
|
|
|
$buttons_html = '';
|
|
foreach ($buttons as $button) {
|
|
$buttons_html .= '<li><a href="javascript:;" class="translate-button translate-ignore flex ac" data-language="'
|
|
. esc_attr($button['language']) . '">' . esc_html($button['text']) . '</a></li>';
|
|
}
|
|
$is_mobile = wp_is_mobile();
|
|
$dropdown = '<ul class="dropdown-menu hover-show-con">' . $buttons_html . '</ul>';
|
|
$hover = !$is_mobile ? ' hover-show' : '';
|
|
$toggle = !$is_mobile ? '' : ' data-toggle="dropdown"';
|
|
return '<div class="dropdown language-dropdown ' . esc_attr($class) . $hover . '">'
|
|
. '<a href="javascript:;" class="toggle-radius"' . $toggle . ' title="' . esc_attr__('切换语言', 'aksrt') . '">'
|
|
. '<i class="fas fa-language" aria-hidden="true"></i></a>' . $dropdown . '</div>';
|
|
}
|