'parent', 'id' => 'term_id'); //TODO: decouple this var $selected = array(); function mystique_CategoryWalker($type='list', $tag='ul', $selected=array()){ $this->tag = $tag; $this->selected = $selected; $this->type = $type; $this->level = 1; } function start_lvl(&$output){ $this->level++; $output .= "\n<".$this->tag." class=\"level-".$this->level."\">\n"; } function end_lvl(&$output) { $this->level--; $output .= "tag.">\n"; } function start_el(&$output, $category, $depth, $args) { extract($args); $count_text = sprintf(_n('%s post', '%s posts', intval($category->count), 'mystique'),intval($category->count)); if (in_array($category->term_id, $this->selected)) $checked = ' checked="checked"'; else $checked = ''; $classes = array(); $classes[] = 'category category-'.$category->slug; $classes[] = 'count-'.intval($category->count); if (isset($current_category) && $current_category) $_current_category = get_category($current_category); $active_class = ''; if((isset($current_category) && $current_category && ($category->term_id == $current_category))) $active_class = 'active'; elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent)) $active_class = 'active-parent'; $classes[] = $active_class; $output .= '
  • '; if($this->type == 'checkbox'): $output .= ''; $output .= ''; else: if ($category->description) $title = $category->description; else $title = $count_text; $output .= ''.attribute_escape($category->name).''; if($count) $output .= ' ('.intval($category->count).') '; endif; } function end_el(&$output, $page) { $output .= "
  • \n"; } } // page walker class mystique_PageWalker extends Walker { var $db_fields = array('parent' => 'post_parent', 'id' => 'ID'); var $selected = array(); function mystique_PageWalker($type='list', $tag='ul', $selected=array()){ $this->tag = $tag; $this->selected = $selected; $this->type = $type; $this->level = 1; } function start_lvl(&$output) { $this->level++; $output .= "\n<".$this->tag." class=\"level-".$this->level."\">\n"; } function end_lvl(&$output) { $this->level--; $output .= "tag.">\n"; } function start_el(&$output, $page, $depth, $args, $current_page) { extract($args); if (in_array($page->ID, $this->selected)) $checked = ' checked="checked"'; else $checked = ''; $classes = array(); $classes[] = 'page page-'.$page->post_name; $active_class = ''; if (!empty($current_page)): $_current_page = get_page($current_page); if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) $active_class = 'active-ancestor'; elseif (($page->ID == $current_page)) $active_class = 'active'; elseif ($_current_page && $page->ID == $_current_page->post_parent) $active_class = 'active-parent'; endif; $classes[] = $active_class; //$classes = implode(' ', apply_filters('page_css_class', $css_class, $page)); $output .= '
  • '; if($this->type == 'checkbox'): $output .= ' '; else: $output .= ''. apply_filters('the_title', $page->post_title). ''; endif; } function end_el(&$output, $page) { $output .= "
  • \n"; } } // menu walker class mystique_MenuWalker extends Walker { var $tree_type = array('post_type', 'taxonomy', 'custom'); var $db_fields = array('parent' => 'menu_item_parent', 'id' => 'db_id'); function start_lvl(&$output, $depth) { $indent = str_repeat("\t", $depth); $output .= "\n$indent\n"; } function start_el(&$output, $item, $depth, $args) { global $wp_query; $indent = ($depth) ? str_repeat("\t", $depth) : ''; $class_names = $value = ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); if($class_names) $class_names = ' class="' .esc_attr($class_names). '"'; $output .= $indent . '\n"; } } function _mystique_menu_item_classes_by_context( &$menu_items ) { global $wp_query; $queried_object = $wp_query->get_queried_object(); $queried_object_id = (int) $wp_query->queried_object_id; $active_object = ''; $active_parent_item_ids = array(); $active_parent_object_ids = array(); $possible_object_parents = array(); $home_page_id = (int) get_option( 'page_for_posts' ); if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) { foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) { if ( is_taxonomy_hierarchical( $taxonomy ) ) { $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) ); if ( is_array( $terms ) ) $possible_object_parents = array_merge( $possible_object_parents, $terms ); } } } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) { _get_post_ancestors( $queried_object ); } $possible_object_parents = array_filter( $possible_object_parents ); foreach ( (array) $menu_items as $key => $menu_item ) { // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { $active_parent_object_ids[] = (int) $menu_item->object_id; $active_parent_item_ids[] = (int) $menu_item->db_id; $active_object = $queried_object->post_type; // if the menu item corresponds to the currently-queried post or taxonomy object } elseif ( $menu_item->object_id == $queried_object_id && ( ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) ) ) ) { $menu_items[$key]->classes[] = 'active'; $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; // if the menu item corresponds to the currently-requested URL } elseif ( 'custom' == $menu_item->object ) { $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; if ( $item_url == $current_url ) { $menu_items[$key]->classes[] = 'active'; if ( untrailingslashit($current_url) == home_url() ) $menu_items[$key]->classes[] = 'home'; $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; } } // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ) $menu_items[$key]->classes[] = 'active-parent'; } $active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) ); $active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) ); // set parent's class foreach ( (array) $menu_items as $key => $parent_item ) { if ( isset( $parent_item->type ) && 'post_type' == $parent_item->type && ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) && in_array( $parent_item->object_id, $queried_object->ancestors ) ) $menu_items[$key]->classes[] = 'active-' . $queried_object->post_type . '-ancestor active-ancestor'; if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) $menu_items[$key]->classes[] = 'active-parent'; if ( in_array( $parent_item->object_id, $active_parent_object_ids ) ) $menu_items[$key]->classes[] = 'active-' . $active_object . '-parent'; } } // replaces wp_list_categories (didn't like the
  • classes) function mystique_list_categories($args = array()) { global $wp_query; $categories = &get_categories($args); $walker = new mystique_CategoryWalker(); if (!empty($categories)) echo $walker->walk($categories, 0, array('count' => false, 'current_category' =>$wp_query->get_queried_object_id())); } // replaces wp_list_pages function mystique_list_pages($args = array()) { global $wp_query; $pages = &get_pages($args); $walker = new mystique_PageWalker(); if (!empty($pages)) echo $walker->walk($pages,0, array(),$wp_query->get_queried_object_id()); } function mystique_list_menu($args = array()) { $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object($locations['primary']); $menu_items = wp_get_nav_menu_items($menu->term_id); if(empty($menu_items)): printf('
  • '.__("Empty menu (%s)","mystique").'
  • ', $menu->slug); return; endif; $nav_menu = ''; $items = ''; _mystique_menu_item_classes_by_context($menu_items); $sorted_menu_items = array(); foreach ((array) $menu_items as $key => $menu_item) $sorted_menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item($menu_item); $walker = new mystique_MenuWalker(); $items .= $walker->walk($sorted_menu_items, 0, array()); // Allow plugins to hook into the menu to add their own
  • 's $items = apply_filters('wp_nav_menu_items', $items, $args); $items = apply_filters("wp_nav_menu_{$menu->slug}_items", $items, $args); $nav_menu .= $items; $nav_menu = apply_filters('wp_nav_menu', $nav_menu, $args); echo $nav_menu; } // print the main navigation menu function mystique_navigation($navtype = false) { if(!$navtype): // main navi? $navtype = get_mystique_option('navigation'); $nav_extra = apply_filters("mystique_navigation_extra", ''); // check for new icons and output endif; if($navtype): ?>
    '.$nav_extra.'

    '; ?>
    get_queried_object_id(); $doctitle = get_post_meta($id, 'title', true); $doctitle = (!$doctitle && is_front_page()) ? get_bloginfo('name').$separator.get_bloginfo('description') : get_post_field('post_title', $id); elseif (is_archive()): if (is_category() || is_tag() || is_tax()): $term = $wp_query->get_queried_object(); $doctitle = $term->name; elseif (is_author()): $doctitle = get_the_author_meta('display_name', get_query_var('author')); elseif (is_date()): if (is_day()) $doctitle = sprintf(__('Archive for %s', "mystique"), get_the_time(__('F jS, Y', "mystique"))); elseif (get_query_var('w')) $doctitle = sprintf(__('Archive for week %1$s of %2$s', "mystique"), get_the_time(__('W', "mystique")), get_the_time(__('Y', "mystique"))); elseif (is_month()) $doctitle = sprintf(__('Archive for %s', "mystique"), single_month_title(' ', false)); elseif (is_year()) $doctitle = sprintf(__('Archive for year %s', "mystique"), get_the_time(__('Y', "mystique"))); endif; elseif (is_search()): $doctitle = sprintf(__('Search results for %s', "mystique"),'"'.esc_attr(get_search_query()).'"'); elseif (is_404()): $doctitle = __('404 Not Found', "mystique"); endif; /* If paged. */ if ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1) $doctitle .= $separator.sprintf(__('Page %s', "mystique"), $page); /* if comment page... */ if (get_query_var('cpage')) $doctitle .= $separator.sprintf(__('Comment Page %s', "mystique"), get_query_var('cpage')); /* Apply the wp_title filters so we're compatible with plugins. */ $doctitle = apply_filters('wp_title', $doctitle, $separator, ''); echo $doctitle; } function mystique_category_breadcrumb($id, $visited = array()){ $chain = ''; $parent = &get_category($id); $level = 1; if (is_wp_error($parent)) return $parent; $name = $parent->cat_name; if ($parent->parent && ($parent->parent != $parent->term_id) && !in_array($parent->parent, $visited)): $visited[] = $parent->parent; $chain .= mystique_category_breadcrumb($parent->parent, $visited); $level++; endif; $chain .= 'cat_name)).'">'.$name.''; echo ' '.$chain.' '; } function mystique_top_category($categorylist,$link = true){ if($categorylist[0]->category_parent) $top_category = get_category($categorylist[0]->category_parent); else $top_category = get_category($categorylist[0]->cat_ID); ($top_category->description) ? $top_category_description = $top_category->description : $top_category_description = sprintf(_n('%s post', '%s posts', intval($top_category->count), 'mystique'),intval($top_category->count)); if($top_category) echo ''.$top_category->cat_name.''; } function mystique_logo(){ $options = get_option('mystique'); $size = $options['logo_size']; if($size) $size = 'width="'.substr($size, 0, strpos($size, "x")).'" height="'.substr($size, strpos($size, 'x')+1).'"'; $sitename = get_bloginfo('name'); $siteurl = get_bloginfo('url'); $tag = (is_home() || is_front_page()) ? 'h1' : 'div'; $output = '<'.$tag.' id="logo">'; if($options['logo']) // logo image? $output .= ''.$sitename.''; else $output .= ''.$sitename.''; $output .= ''; echo apply_filters('mystique_logo', $output); } function mystique_shareThis(){ global $post; $content = get_the_excerpt(); ?>
    " />
    0): ?> var highlight_search_query = ""; jQuery(".hentry").each(function(){ jQuery(this).highlight(highlight_search_query, 1, "highlight"); }); <',$allowed_tags).'>'; $the_contents = str_replace(']]>', ']]>', $the_contents); // exclude HTML and shortcodes from counting words $the_contents = strip_tags($the_contents, $allowed_tags); $the_contents = strip_shortcodes($the_contents); if(!is_numeric($all_words)) $all_words = 9999; // assuming full post // count all if($all_words > count(preg_split('/[\s]+/', strip_tags($the_contents), -1))) return $the_contents; $all_chunks = preg_split('/([\s]+)/', $the_contents, -1, PREG_SPLIT_DELIM_CAPTURE); $the_contents = ''; $count_words = 0; $enclosed_by_tag = false; foreach($all_chunks as $chunk): // is tag opened? if(0 < preg_match('/<[^>]*$/s', $chunk)) $enclosed_by_tag = true; elseif(0 < preg_match('/>[^<]*$/s', $chunk)) $enclosed_by_tag = false; // get entire word if(!$enclosed_by_tag && '' != trim($chunk) && substr($chunk, -1, 1) != '>') $count_words ++; $the_contents .= $chunk; if($count_words >= $all_words && !$enclosed_by_tag) break; endforeach; // note the class named 'more-link'. style it on your own $the_contents = $the_contents.' '.$read_more_tag.''; // native WordPress check for unclosed tags $the_contents = force_balance_tags($the_contents); endif; return $the_contents; } // strip tags and attributes from a string that can be used to XSS function mystique_strip_tags_attributes($string, $allowed_tags = '