function widget($args, $instance) { global $wp_query; extract($args); $current_taxonomy = $this->_get_current_taxonomy($instance); if (!empty($instance['title'])) { $title = $instance['title']; } else { if ('post_tag' == $current_taxonomy) { $title = __('Tags'); } else { $tax = get_taxonomy($current_taxonomy); $title = $tax->labels->name; } } $use_desc_for_title = isset($instance['use_desc_for_title']) ? $instance['use_desc_for_title'] : true; $count = isset($instance['count']) ? $instance['count'] : false; $title = apply_filters('widget_title', $title, $instance, $this->id_base); $current_term = false; $current_term_id = $current_post_id = 0; if (suwp::is_tax($current_taxonomy)) { $current_term = $wp_query->get_queried_object(); $current_term_id = $wp_query->get_queried_object_id(); $title = $current_term->name; } elseif (is_singular()) { $current_post_id = $wp_query->get_queried_object_id(); $post_terms = get_the_terms($current_post_id, $current_taxonomy); if (is_array($post_terms) && count($post_terms)) { $current_term = reset($post_terms); $current_term_id = $current_term->term_id; $title = $current_term->name; } } $term_args = array('taxonomy' => $current_taxonomy, 'orderby' => 'name', 'show_count' => $count ? '1' : '0', 'hierarchical' => '0', 'title_li' => '', 'parent' => $current_term_id, 'show_option_none' => false, 'use_desc_for_title' => $use_desc_for_title ? '1' : '0', 'echo' => false); $category_output = $post_output = ''; if (!$current_term || is_taxonomy_hierarchical($current_taxonomy)) { $category_output = wp_list_categories($term_args); } if ($current_term) { $child_posts = get_posts(array('taxonomy' => $current_taxonomy, 'term' => $current_term->slug, 'numberposts' => 5)); foreach ($child_posts as $child_post) { $css_class = ''; if ($child_post->ID == $current_post_id) { $css_class = 'current_post_item'; } $post_output .= "\n\t\t\t<li class=\"" . $css_class . '"><a href="' . get_permalink($child_post->ID) . '" title="' . esc_attr(wp_strip_all_tags(apply_filters('the_title', $child_post->post_title, $child_post->ID))) . '">' . apply_filters('the_title', $child_post->post_title, $child_post->ID) . "</a></li>\n"; } } if ($category_output || $post_output) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo "\n\t\t<ul>\n"; echo $category_output; echo $post_output; echo "\n\t\t</ul>\n"; echo $after_widget; } }
function get_meta_desc() { global $post; $desc = false; //If we're viewing the homepage, look for homepage meta data. if (is_home()) { $desc = $this->get_setting('home_description'); if (!$desc && $this->get_setting('home_description_tagline_default')) { $desc = get_bloginfo('description'); } //If we're viewing a post or page, look for its meta data. } elseif (is_singular()) { $desc = $this->get_postmeta('description'); if (!trim($desc) && !post_password_required() && ($format = $this->get_setting('description_posttype_' . get_post_type()))) { $auto_excerpt = $post->post_content; $auto_excerpt = strip_shortcodes($auto_excerpt); $auto_excerpt = str_replace(']]>', ']]>', $auto_excerpt); $auto_excerpt = strip_tags($auto_excerpt); $auto_excerpt = sustr::truncate($auto_excerpt, 150, '', true); $desc = str_replace(array('{excerpt::autogen}', '{excerpt}'), array($auto_excerpt, strip_tags($post->post_excerpt)), $format); } //If we're viewing a term, look for its meta data. } elseif (suwp::is_tax()) { global $wp_query; $tax_descriptions = $this->get_setting('taxonomy_descriptions'); $term_id = $wp_query->get_queried_object_id(); $term_obj = $wp_query->get_queried_object(); $desc = isset($tax_descriptions[$term_id]) ? $tax_descriptions[$term_id] : ''; if (!trim($desc) && ($format = $this->get_setting('description_taxonomy_' . $term_obj->taxonomy))) { $desc = str_replace(array('{description}'), array($term_obj->description), $format); } } $desc = trim($desc); if ($desc) { $desc = $this->get_desc_paged($desc); } $desc = trim($desc); $desc = su_esc_attr($desc); return $desc; }
/** * Gets a specified meta value of the current term. * * @since 5.4 * * @param string $key The database setting where the metadata is stored. The function will add a "taxonomy_" prefix. * @param mixed $id The ID number of the post/page. * @return string The meta value requested. */ function get_termmeta($key, $id = false, $module = false) { global $wp_query; if (!$id && suwp::is_tax()) { $id = $wp_query->get_queried_object_id(); } if (!$id) { return null; } $tax_meta = $this->get_setting(sustr::startwith($key, 'taxonomy_'), array(), $module); if (is_array($tax_meta) && isset($tax_meta[$id])) { return $tax_meta[$id]; } return null; }
function head_tag_output() { global $post; $kw = false; //If we're viewing the homepage, look for homepage meta data. if (is_home()) { $kw = $this->get_setting('home_keywords'); //If we're viewing a post or page... } elseif (is_singular()) { //...look for its meta data $kw = $this->get_postmeta('keywords'); //...and add default values if ($posttypename = get_post_type()) { $taxnames = get_object_taxonomies($posttypename); foreach ($taxnames as $taxname) { if ($this->get_setting("auto_keywords_posttype_{$posttypename}_tax_{$taxname}", false)) { $terms = get_the_terms(0, $taxname); $terms = suarr::flatten_values($terms, 'name'); $terms = implode(',', $terms); $kw .= ',' . $terms; } } if ($this->get_setting("auto_keywords_posttype_{$posttypename}_words", false)) { $words = preg_split("/[\\s+]/", strip_tags($post->post_content), null, PREG_SPLIT_NO_EMPTY); $words = array_count_values($words); arsort($words); $words = array_filter($words, array(&$this, 'filter_word_counts')); $words = array_keys($words); $stopwords = suarr::explode_lines($this->get_setting('words_to_remove', array(), 'slugs')); $stopwords = array_map(array('sustr', 'tolower'), $stopwords); $words = array_map(array('sustr', 'tolower'), $words); $words = array_diff($words, $stopwords); $words = array_slice($words, 0, $this->get_setting("auto_keywords_posttype_{$posttypename}_words_value")); $words = implode(',', $words); $kw .= ',' . $words; } } //If we're viewing a term, look for its meta data. } elseif (suwp::is_tax()) { global $wp_query; $tax_keywords = $this->get_setting('taxonomy_keywords'); $term_id = $wp_query->get_queried_object_id(); if (isset($tax_keywords[$term_id])) { $kw = $tax_keywords[$term_id]; } else { $kw = ''; } } if ($globals = $this->get_setting('global_keywords')) { if (strlen($kw)) { $kw .= ','; } $kw .= $globals; } $kw = str_replace(array("\r\n", "\n"), ',', $kw); $kw = explode(',', $kw); $kw = array_map('trim', $kw); //Remove extra spaces from beginning/end of keywords $kw = array_filter($kw); //Remove blank keywords $kw = suarr::array_unique_i($kw); //Remove duplicate keywords $kw = implode(',', $kw); //Do we have keywords? If so, output them. if ($kw) { $kw = su_esc_attr($kw); echo "\t<meta name=\"keywords\" content=\"{$kw}\" />\n"; } }
function get_title() { global $wp_query, $wp_locale; //Custom post/page title? if ($post_title = $this->get_postmeta('title')) { return htmlspecialchars($this->get_title_paged($post_title)); } //Custom taxonomy title? if (suwp::is_tax()) { $tax_titles = $this->get_setting('taxonomy_titles'); if ($tax_title = $tax_titles[$wp_query->get_queried_object_id()]) { return htmlspecialchars($this->get_title_paged($tax_title)); } } //Get format if (!$this->should_rewrite_title()) { return ''; } if (!($format = $this->get_title_format())) { return ''; } //Load post/page titles $post_id = 0; $post_title = ''; $parent_title = ''; if (is_singular()) { $post = $wp_query->get_queried_object(); $post_title = strip_tags(apply_filters('single_post_title', $post->post_title, $post)); $post_id = $post->ID; if ($parent = $post->post_parent) { $parent = get_post($parent); $parent_title = strip_tags(apply_filters('single_post_title', $parent->post_title, $post)); } } //Load date-based archive titles if ($m = get_query_var('m')) { $year = substr($m, 0, 4); $monthnum = intval(substr($m, 4, 2)); $daynum = intval(substr($m, 6, 2)); } else { $year = get_query_var('year'); $monthnum = get_query_var('monthnum'); $daynum = get_query_var('day'); } $month = $wp_locale->get_month($monthnum); $monthnum = zeroise($monthnum, 2); $day = date('jS', mktime(12, 0, 0, $monthnum, $daynum, $year)); $daynum = zeroise($daynum, 2); //Load category titles $cat_title = $cat_titles = $cat_desc = ''; if (is_category()) { $cat_title = single_cat_title('', false); $cat_desc = category_description(); } elseif (count($categories = get_the_category())) { $cat_titles = su_lang_implode($categories, 'name'); usort($categories, '_usort_terms_by_ID'); $cat_title = $categories[0]->name; $cat_desc = category_description($categories[0]->term_id); } if (strlen($cat_title) && $this->get_setting('terms_ucwords', true)) { $cat_title = sustr::tclcwords($cat_title); } //Load tag titles $tag_title = $tag_desc = ''; if (is_tag()) { $tag_title = single_tag_title('', false); $tag_desc = tag_description(); if ($this->get_setting('terms_ucwords', true)) { $tag_title = sustr::tclcwords($tag_title); } } //Load author titles if (is_author()) { $author_obj = $wp_query->get_queried_object(); } elseif (is_singular()) { global $authordata; $author_obj = $authordata; } else { $author_obj = null; } if ($author_obj) { $author = array('username' => $author_obj->user_login, 'name' => $author_obj->display_name, 'firstname' => get_the_author_meta('first_name', $author_obj->ID), 'lastname' => get_the_author_meta('last_name', $author_obj->ID), 'nickname' => get_the_author_meta('nickname', $author_obj->ID)); } else { $author = array('username' => '', 'name' => '', 'firstname' => '', 'lastname' => '', 'nickname' => ''); } $variables = array('{blog}' => get_bloginfo('name'), '{tagline}' => get_bloginfo('description'), '{post}' => $post_title, '{page}' => $post_title, '{page_parent}' => $parent_title, '{category}' => $cat_title, '{categories}' => $cat_titles, '{category_description}' => $cat_desc, '{tag}' => $tag_title, '{tag_description}' => $tag_desc, '{tags}' => su_lang_implode(get_the_tags($post_id), 'name', true), '{daynum}' => $daynum, '{day}' => $day, '{monthnum}' => $monthnum, '{month}' => $month, '{year}' => $year, '{author}' => $author['name'], '{author_name}' => $author['name'], '{author_username}' => $author['username'], '{author_firstname}' => $author['firstname'], '{author_lastname}' => $author['lastname'], '{author_nickname}' => $author['nickname'], '{query}' => su_esc_attr(get_search_query()), '{ucquery}' => su_esc_attr(ucwords(get_search_query())), '{url_words}' => $this->get_url_words($_SERVER['REQUEST_URI'])); $title = str_replace(array_keys($variables), array_values($variables), htmlspecialchars($format)); return $this->get_title_paged($title); }
function autolink_footer($args = array()) { if ($this->already_outputted) { return; } extract(wp_parse_args($args, array('footer_link_section_format' => $this->get_setting('footer_link_section_format', '{links}'), 'footer_link_format' => $this->get_setting('footer_link_format', '{link}'), 'footer_link_sep' => $this->get_setting('footer_link_sep', ' | '))), EXTR_SKIP); $links = $this->get_setting('footer_links', array()); suarr::vksort($links, 'anchor'); $link_html = array(); foreach ($links as $link_data) { if (isset($link_data['from']) && count($link_data['from'])) { $from = $link_data['from'][0]; } else { $from = array(''); } $from_match_children = isset($link_data['from_match_children']) && $link_data['from_match_children']; $from_match_negative = isset($link_data['from_match_negative']) && $link_data['from_match_negative']; if (!isset($link_data['to'])) { $link_data['to'] = ''; } list($from_genus, $from_type, $from_id) = $this->jlsuggest_value_explode($from); $is_from = $from_match_negative; switch ($from_genus) { case 'posttype': $post_ids = array($from_id); if ($from_match_children) { $post_ids[] = wp_get_post_parent_id($from_id); } //Requires WordPress 3.1 foreach ($post_ids as $post_id) { if (is_single($post_id) || is_page($post_id)) { $is_from = !$from_match_negative; break; } } break; case 'taxonomy': if (suwp::is_tax($from_type, $from_id) || $from_match_children && is_singular() && has_term($from_id, $from_type)) { $is_from = !$from_match_negative; } break; case 'home': if (is_home()) { $is_from = !$from_match_negative; } break; case 'author': if (is_author($from_id) || $from_match_children && is_singular() && get_the_author_meta('id') == $from_id) { $is_from = !$from_match_negative; } break; case 'url': if ($from_id) { if (suurl::equal(suurl::current(), $from_id) || $from_match_children && sustr::startswith(suurl::current(), $from_id)) { $is_from = !$from_match_negative; } } else { $is_from = true; } //No "from" restriction break; } if (!$is_from) { continue; } $h_anchor = esc_html($link_data['anchor']); $rel = $link_data['nofollow'] ? ' rel="nofollow"' : ''; $target = $link_data['target'] == 'blank' ? ' target="_blank"' : ''; $title = strlen($a_titletext = su_esc_attr($link_data['title'])) ? " title=\"{$a_titletext}\"" : ''; $a_url = su_esc_attr($this->jlsuggest_value_to_url($link_data['to'])); if (strlen(trim($h_anchor)) && strlen(trim((string) $a_url)) && $a_url != 'http://') { $link_html[] = str_replace('{link}', "<a href=\"{$a_url}\"{$title}{$rel}{$target}>{$h_anchor}</a>", $footer_link_format); } } echo str_replace('{links}', implode($footer_link_sep, $link_html), $footer_link_section_format); }