/**
  * Enqueue the javascript for live search
  */
 function ht_knowledge_base_live_search_register_scripts()
 {
     //register live search script
     wp_register_script('ht-kb-live-search-plugin', plugins_url('js/jquery.livesearch.js', dirname(__FILE__)), array('jquery'), false, true);
     wp_register_script('ht-kb-live-search', plugins_url('js/hkb-livesearch-js.js', dirname(__FILE__)), array('jquery', 'ht-kb-live-search-plugin'), false, true);
     $search_url = '?ajax=1&ht-kb-search=1&';
     //if wpml is installed append language code if not in default language
     if (defined('ICL_LANGUAGE_CODE')) {
         global $sitepress;
         $default_lang = $sitepress->get_default_language();
         if ($default_lang != ICL_LANGUAGE_CODE) {
             $search_url .= 'lang=' . ICL_LANGUAGE_CODE . '&';
             $search_url = ICL_LANGUAGE_CODE . '/' . $search_url;
         }
     }
     $focus_searchbox = !ht_kb_is_ht_kb_search() && hkb_focus_on_search_box();
     $search_url .= 's=';
     wp_localize_script('ht-kb-live-search', 'hkbJSSettings', array('liveSearchUrl' => home_url($search_url), 'focusSearchBox' => $focus_searchbox));
 }
Example #2
0
 /**
  * Get post ancestors - used in breadcrumbs etc
  * Note posts can have multiple and divergent ancestory
  * @return (Array) Post ancestors
  */
 function ht_kb_get_ancestors()
 {
     global $post, $cat, $hkb_current_article_id;
     $ancestors = array();
     //path number
     $i = 0;
     $ancestors[$i] = array();
     if (!ht_kb_is_ht_kb_front_page()) {
         $taxonomy = ht_kb_get_taxonomy();
         $term_string = ht_kb_get_term();
         $visited = array();
         if (!empty($taxonomy) && !empty($term_string)) {
             //category terms bread crumb
             //add home link to path
             $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
             //kb archive set as home test
             if (!hkb_is_kb_set_as_front()) {
                 //add knowledge base to path
                 $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
             }
             $term = get_term_by('slug', $term_string, $taxonomy);
             if ($term == false) {
                 return;
             }
             if ($term->parent != 0) {
                 //has parents
                 $parents = $this->ht_get_custom_category_ancestors($term->term_id, 'ht_kb_category', true, null, false, $visited, $ancestors, $i);
                 //itself
                 //$ancestors[$i][] = array('label'=>$term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title'=>sprintf( __( "View all posts in %s" ), $term->name), 'type'=>'kb_current_page');
             } else {
                 //path
                 //add knowledge base to path
                 $ancestors[$i][] = array('label' => $term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title' => sprintf(__("View all posts in %s"), $term->name), 'type' => 'kb_tax');
                 $visited[] = $term->term_id;
             }
         } elseif (!is_single() && 'ht_kb' == get_post_type()) {
             //add home link to path
             $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
             //Archive
             $ht_kb_data = get_post_type_object('ht_kb');
             //kb archive set as home test
             if (!hkb_is_kb_set_as_front()) {
                 $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
             }
             //search?
             if (ht_kb_is_ht_kb_search()) {
                 $ancestors[$i][] = array('label' => __('Search Results', 'ht-knowledge-base'), 'link' => '', 'title' => __('Search Results', 'ht-knowledge-base'), 'type' => 'kb_search');
             }
         } elseif (is_single() && 'ht_kb' == get_post_type()) {
             //Single post
             $hkb_current_article_id = empty($hkb_current_article_id) ? get_the_ID() : $hkb_current_article_id;
             $terms = wp_get_post_terms($hkb_current_article_id, 'ht_kb_category');
             if (!empty($terms)) {
                 foreach ($terms as $term) {
                     //add home link to path
                     $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
                     //kb archive set as home test
                     if (!hkb_is_kb_set_as_front()) {
                         //add knowledge base to path
                         $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
                     }
                     if ($term->parent != 0) {
                         $parents = $this->ht_get_custom_category_ancestors($term->term_id, 'ht_kb_category', true, null, false, $visited, $ancestors, $i);
                         //itself
                         //$ancestors[$i][] = array('label'=>$term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title'=>sprintf( __( "Viewing a post in %s" ), $term->name), 'type'=>'kb_current_page');
                     } else {
                         //add knowledge base to path
                         $ancestors[$i][] = array('label' => $term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title' => sprintf(__("View all posts in %s"), $term->name), 'type' => 'kb_tax');
                         $visited[] = $term->term_id;
                     }
                     //itself
                     $ancestors[$i][] = array('label' => get_the_title(), 'link' => get_permalink(), 'title' => get_the_title(), 'type' => 'kb_current_page');
                     //increment the counter
                     $i++;
                 }
                 // End foreach
             } else {
                 //add home link to path
                 $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
                 //kb archive set as home test
                 if (!hkb_is_kb_set_as_front()) {
                     //add knowledge base to path
                     $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
                 }
                 //uncategorized article
                 $ancestors[$i][] = array('label' => get_the_title(), 'link' => get_permalink(), 'title' => get_the_title(), 'type' => 'kb_current_page');
                 $i++;
             }
         } else {
             //Display the post title.
             $ancestors[$i][] = array('label' => get_the_title(), 'link' => get_permalink(), 'title' => get_the_title(), 'type' => 'kb_current_page');
             $i++;
         }
     }
     //is_front_page
     return $ancestors;
 }