create_go_link($url); } return $url; } endif; if (!function_exists('aksrt_get_page_links_settings')) : /** * Read page_links_* meta for a page. * * @return array */ function aksrt_get_page_links_settings(int $post_id = 0): array { if ($post_id <= 0) { $post_id = (int) get_queried_object_id(); } $cats = get_post_meta($post_id, 'page_links_category', true); if (!is_array($cats)) { $cats = $cats !== '' && $cats !== null ? array_filter(array_map('intval', (array) $cats)) : []; } else { $cats = array_values(array_filter(array_map('intval', $cats))); } $search_types = get_post_meta($post_id, 'page_links_search_types', true); if (!is_array($search_types)) { $search_types = $search_types ? array_values(array_filter(array_map('sanitize_key', (array) $search_types))) : []; } else { $search_types = array_values(array_filter(array_map('sanitize_key', $search_types))); } $submit_cats = get_post_meta($post_id, 'page_links_submit_cats', true); if (!is_array($submit_cats)) { $submit_cats = $submit_cats !== '' && $submit_cats !== null ? array_filter(array_map('intval', (array) $submit_cats)) : []; } else { $submit_cats = array_values(array_filter(array_map('intval', $submit_cats))); } $style = sanitize_key((string) get_post_meta($post_id, 'page_links_style', true)); if (!in_array($style, ['card', 'bigcard', 'image', 'simple'], true)) { $style = 'card'; } $orderby = sanitize_key((string) get_post_meta($post_id, 'page_links_orderby', true)); if (!in_array($orderby, ['name', 'updated', 'rating', 'rand', 'id', 'length'], true)) { $orderby = 'name'; } $order = strtoupper((string) get_post_meta($post_id, 'page_links_order', true)); if (!in_array($order, ['ASC', 'DESC'], true)) { $order = 'ASC'; } $position = sanitize_key((string) get_post_meta($post_id, 'page_links_content_position', true)); if (!in_array($position, ['top', 'bottom'], true)) { $position = 'top'; } return [ 'content_s' => (bool) get_post_meta($post_id, 'page_links_content_s', true), 'content_position' => $position, 'search_s' => (bool) get_post_meta($post_id, 'page_links_search_s', true), 'search_types' => $search_types, 'category' => $cats, 'style' => $style, 'limit' => max(0, (int) get_post_meta($post_id, 'page_links_limit', true)), 'orderby' => $orderby, 'order' => $order, 'go_s' => (bool) get_post_meta($post_id, 'page_links_go_s', true), 'blank_s' => (bool) get_post_meta($post_id, 'page_links_blank_s', true), // Default nofollow ON (zibll default true). 'nofollow_s' => get_post_meta($post_id, 'page_links_nofollow_s', true) === '' ? true : (bool) get_post_meta($post_id, 'page_links_nofollow_s', true), 'submit_s' => (bool) get_post_meta($post_id, 'page_links_submit_s', true), 'submit_sign_s' => get_post_meta($post_id, 'page_links_submit_sign_s', true) === '' ? true : (bool) get_post_meta($post_id, 'page_links_submit_sign_s', true), 'submit_cats' => $submit_cats, 'submit_title' => (string) (get_post_meta($post_id, 'page_links_submit_title', true) ?: __('申请入驻', 'aksrt')), 'submit_dec' => (string) get_post_meta($post_id, 'page_links_submit_dec', true), ]; } endif; if (!function_exists('aksrt_links_box')) : /** * Render bookmark cards (zibll zib_links_box). * * @param array $links Bookmark rows from get_bookmarks(). */ function aksrt_links_box($links = [], string $type = 'card', bool $nofollow = true, bool $go_link = false, bool $blank_s = false): string { if (empty($links) || !is_array($links)) { return ''; } $type = in_array($type, ['card', 'bigcard', 'image', 'simple'], true) ? $type : 'card'; $placeholder = get_template_directory_uri() . '/assets/img/placeholder.svg'; $html = ''; $i = 0; foreach ($links as $raw) { $link = (array) $raw; if (empty($link['href']) && !empty($link['link_url'])) { $link['href'] = $link['link_url']; } if (empty($link['title']) && !empty($link['link_name'])) { $link['title'] = $link['link_name']; } if (empty($link['src']) && !empty($link['link_image'])) { $link['src'] = $link['link_image']; } if (empty($link['desc']) && !empty($link['link_description'])) { $link['desc'] = $link['link_description']; } if ($blank_s) { $link['blank'] = true; } if (empty($link['blank']) && !empty($link['link_target'])) { $link['blank'] = true; } $href = !empty($link['href']) ? (string) $link['href'] : ''; $title = !empty($link['title']) ? (string) $link['title'] : ''; if ($href === '' || $title === '') { continue; } if ($go_link || !empty($link['go_link'])) { $href = aksrt_go_link($href, true); } else { $href = esc_url($href); } $src = !empty($link['src']) ? esc_url((string) $link['src']) : ''; $blank = !empty($link['blank']) ? ' target="_blank"' : ''; $dec = !empty($link['desc']) ? (string) $link['desc'] : ''; $rel = $nofollow ? ' rel="nofollow noopener noreferrer"' : ' rel="noopener noreferrer"'; $img_src = $src !== '' ? $src : $placeholder; $img = ''; $data_dec = $dec !== '' ? ' title="' . esc_attr($title) . '" data-content="' . esc_attr($dec) . '"' : ' data-content="' . esc_attr($title) . '"'; if ($type === 'bigcard') { $html .= ''; } elseif ($type === 'image') { $html .= '' . $img . ''; } elseif ($type === 'simple') { $sc = $i === 0 ? '' : 'icon-spot'; $html .= '' . esc_html($title) . ''; } else { $html .= ''; } $i++; } return $html; } endif; if (!function_exists('aksrt_page_links_html')) : /** * Build the multi/single category links block for a page. */ function aksrt_page_links_html(int $post_id = 0): string { $post_id = $post_id > 0 ? $post_id : (int) get_queried_object_id(); $s = aksrt_get_page_links_settings($post_id); $cats = $s['category']; if (empty($cats)) { if (current_user_can('manage_links')) { return ''; } return ''; } $limit = (int) $s['limit']; $orderby = (string) $s['orderby']; $order = (string) $s['order']; $style = (string) $s['style']; $nofollow = (bool) $s['nofollow_s']; $go_s = (bool) $s['go_s']; $blank_s = (bool) $s['blank_s']; $submit_s = (bool) $s['submit_s']; $submit_title = (string) $s['submit_title']; $is_mobile = wp_is_mobile(); $links_con = ''; if (count($cats) > 1) { $link_cat_con = ''; $link_cat_nav = ''; foreach ($cats as $cat_id) { $args = [ 'orderby' => $orderby, 'order' => $order, 'limit' => $limit > 0 ? $limit : -1, 'category' => (int) $cat_id, ]; $_link = aksrt_links_box(get_bookmarks($args), $style, $nofollow, $go_s, $blank_s); if (!$_link) { continue; } $term = get_term((int) $cat_id, 'link_category'); if (!$term || is_wp_error($term)) { continue; } $_id = 'links-' . (int) $cat_id; $link_cat_con .= ''; $link_cat_nav .= '
  • ' . esc_html($term->name) . '
  • '; } if ($link_cat_con === '') { $links_con = ''; } else { $submit_nav = $submit_s ? '' : ''; $submit_con = $submit_s ? '' : ''; $offset_top = $is_mobile ? '-8' : ''; $offset_bottom = $is_mobile ? '20' : '-30'; $links_con = '
    ' . '
    ' . $link_cat_con . $submit_con . '
    '; } } else { $cat_id = (int) $cats[0]; $args = [ 'orderby' => $orderby, 'order' => $order, 'limit' => $limit > 0 ? $limit : -1, 'category' => $cat_id, ]; $submit_con = $submit_s ? '' : ''; $links_con = '' . $submit_con; } if ($links_con === '') { if (current_user_can('manage_links')) { return ''; } return ''; } return ''; } endif; if (!function_exists('aksrt_link_get_search_cover')) : /** * Search cover with multi-engine tabs (zibll zib_link_get_search_cover). */ function aksrt_link_get_search_cover(int $post_id = 0): string { $post_id = $post_id > 0 ? $post_id : (int) get_queried_object_id(); $s = aksrt_get_page_links_settings($post_id); if (empty($s['search_s']) || empty($s['search_types'])) { return ''; } $search_types_args = [ 'self' => [ 'name' => __('站内', 'aksrt'), 'input_name' => 's', 'url' => home_url('/'), ], 'baidu' => [ 'name' => __('百度', 'aksrt'), 'input_name' => 'wd', 'url' => 'https://www.baidu.com/s', ], 'google' => [ 'name' => __('谷歌', 'aksrt'), 'input_name' => 'q', 'url' => 'https://www.google.com/search', ], 'bing' => [ 'name' => __('必应', 'aksrt'), 'input_name' => 'q', 'url' => 'https://cn.bing.com/search', ], 'sogou' => [ 'name' => __('搜狗', 'aksrt'), 'input_name' => 'query', 'url' => 'https://www.sogou.com/web', ], '360' => [ 'name' => '360', 'input_name' => 'q', 'url' => 'https://www.so.com/s', ], ]; $type_nav = ''; $type_con = ''; $i = 0; foreach ($s['search_types'] as $k) { if (!isset($search_types_args[$k])) { continue; } $cfg = $search_types_args[$k]; $active = $i === 0 ? ' active' : ''; $pane_id = 'link-page-' . $post_id . '-' . $k; $type_nav .= '
  • ' . esc_html($cfg['name']) . '
  • '; $type_con .= '
    ' . '
    ' . '
    ' . '' . '' . '
    ' . esc_html(sprintf(__('%s搜索', 'aksrt'), $cfg['name'])) . '
    ' . '
    ' . '
    '; $i++; } if ($type_nav === '') { return ''; } $title = get_the_title($post_id); $img = ''; $thumb_id = get_post_thumbnail_id($post_id); if ($thumb_id) { $image = wp_get_attachment_image_src($thumb_id, 'full'); $img = !empty($image[0]) ? (string) $image[0] : ''; } if ($img === '') { $img = (string) get_post_meta($post_id, 'page_header_cover_img', true); } if ($img === '' && class_exists('\AKSRT\Settings\Settings')) { $img = (string) \AKSRT\Settings\Settings::get_value('page_header_cover_img', ''); } if ($img === '') { $img = get_template_directory_uri() . '/assets/img/placeholder.svg'; } $src = get_template_directory_uri() . '/assets/img/placeholder.svg'; $search = ''; return ''; } endif; if (!function_exists('aksrt_submit_links_modal')) : /** * Frontend submit modal markup (zibll zib_submit_links_modal). * * @param array{title?:string,dec?:string,sign?:bool,cats?:int[]} $args */ function aksrt_submit_links_modal(array $args = []): string { $defaults = [ 'title' => __('申请入驻', 'aksrt'), 'dec' => '', 'sign' => true, 'cats' => [], ]; $args = array_merge($defaults, $args); $title = (string) $args['title']; $header = $title !== '' ? '
    ' . '' . esc_html($title) . '
    ' : ''; $body = ''; if (!empty($args['dec'])) { $body .= '
    ' . wp_kses_post((string) $args['dec']) . '
    '; } $need_login = !empty($args['sign']) && !is_user_logged_in(); if ($need_login) { $sign_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : (function_exists('aksrt_get_sign_page_url') ? aksrt_get_sign_page_url('login') : wp_login_url()); $body .= '
    '; $body .= '
    ' . esc_html__('请先登录', 'aksrt') . '
    '; $body .= '

    '; if (class_exists('\AKSRT\Auth\OAuth') && method_exists(\AKSRT\Auth\OAuth::get_instance(), 'render_social_buttons')) { $social = (string) \AKSRT\Auth\OAuth::get_instance()->render_social_buttons(__('使用以下方式快速登录', 'aksrt')); if ($social !== '') { $body .= ''; } } $body .= '
    '; } else { $term_args = [ 'taxonomy' => 'link_category', 'hide_empty' => false, ]; if (!empty($args['cats']) && is_array($args['cats'])) { $term_args['include'] = array_map('intval', $args['cats']); $term_args['orderby'] = 'include'; } $terms = get_terms($term_args); $cats_options = ''; if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $item) { $cats_options .= ''; } } $cats_field = $cats_options !== '' ? '
    ' . esc_html__('网站类别', 'aksrt') . '
    ' . '
    ' : ''; $placeholder_upload = get_template_directory_uri() . '/assets/img/placeholder.svg'; $body .= ''; } return ''; } endif;