function kleo_ajax_search() { //if "s" input is missing exit if (empty($_REQUEST['s']) && empty($_REQUEST['bbp_search'])) { die; } if (!empty($_REQUEST['bbp_search'])) { $search_string = $_REQUEST['bbp_search']; } else { $search_string = $_REQUEST['s']; } $output = ""; $context = "any"; $defaults = array('numberposts' => 4, 'posts_per_page' => 20, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false, 's' => $_REQUEST['s']); if (isset($_REQUEST['context']) && $_REQUEST['context'] != '') { $context = explode(",", $_REQUEST['context']); $defaults['post_type'] = $context; } $defaults = apply_filters('kleo_ajax_query_args', $defaults); $the_query = new WP_Query($defaults); $posts = $the_query->get_posts(); $members = array(); $members['total'] = 0; $groups = array(); $groups['total'] = 0; $forums = FALSE; if (function_exists('bp_is_active') && ($context == "any" || in_array("members", $context))) { $members = bp_core_get_users(array('search_terms' => $search_string, 'per_page' => $defaults['numberposts'], 'populate_extras' => false)); } if (function_exists('bp_is_active') && bp_is_active("groups") && ($context == "any" || in_array("groups", $context))) { $groups = groups_get_groups(array('search_terms' => $search_string, 'per_page' => $defaults['numberposts'], 'populate_extras' => false)); } if (class_exists('bbPress') && ($context == "any" || in_array("forum", $context))) { $forums = kleo_bbp_get_replies($search_string); } //if there are no posts, groups nor members if (empty($posts) && $members['total'] == 0 && $groups['total'] == 0 && !$forums) { $output = "<div class='kleo_ajax_entry ajax_not_found'>"; $output .= "<div class='ajax_search_content'>"; $output .= "<i class='icon icon-exclamation-sign'></i> "; $output .= __("Sorry, we haven't found anything based on your criteria.", 'kleo_framework'); $output .= "<br>"; $output .= __("Please try searching by different terms.", 'kleo_framework'); $output .= "</div>"; $output .= "</div>"; echo $output; die; } //if there are members if ($members['total'] != 0) { $output .= '<div class="kleo-ajax-part kleo-ajax-type-members">'; $output .= '<h4><span>' . __("Members", 'kleo_framework') . '</span></h4>'; foreach ((array) $members['users'] as $member) { $image = '<img src="' . bp_core_fetch_avatar(array('item_id' => $member->ID, 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">'; if ($update = bp_get_user_meta($member->ID, 'bp_latest_update', true)) { $latest_activity = char_trim(trim(strip_tags(bp_create_excerpt($update['content'], 50, "...")))); } else { $latest_activity = ''; } $output .= "<div class ='kleo_ajax_entry'>"; $output .= "<div class='ajax_search_image'>{$image}</div>"; $output .= "<div class='ajax_search_content'>"; $output .= "<a href='" . bp_core_get_user_domain($member->ID) . "' class='search_title'>"; $output .= $member->display_name; $output .= "</a>"; $output .= "<span class='search_excerpt'>"; $output .= $latest_activity; $output .= "</span>"; $output .= "</div>"; $output .= "</div>"; } $output .= "<a class='ajax_view_all' href='" . bp_get_members_directory_permalink() . "?s=" . $search_string . "'>" . __('View member results', 'kleo_framework') . "</a>"; $output .= "</div>"; } //if there are groups if ($groups['total'] != 0) { $output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">'; $output .= '<h4><span>' . __("Groups", 'kleo_framework') . '</span></h4>'; foreach ((array) $groups['groups'] as $group) { $image = '<img src="' . bp_core_fetch_avatar(array('item_id' => $group->id, 'object' => 'group', 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">'; $output .= "<div class ='kleo_ajax_entry'>"; $output .= "<div class='ajax_search_image'>{$image}</div>"; $output .= "<div class='ajax_search_content'>"; $output .= "<a href='" . bp_get_group_permalink($group) . "' class='search_title'>"; $output .= $group->name; $output .= "</a>"; $output .= "</div>"; $output .= "</div>"; } $output .= "<a class='ajax_view_all' href='" . bp_get_groups_directory_permalink() . "?s=" . $search_string . "'>" . __('View group results', 'kleo_framework') . "</a>"; $output .= "</div>"; } //if there are posts if (!empty($posts)) { $post_types = array(); $post_type_obj = array(); foreach ($posts as $post) { $post_types[$post->post_type][] = $post; if (empty($post_type_obj[$post->post_type])) { $post_type_obj[$post->post_type] = get_post_type_object($post->post_type); } } foreach ($post_types as $ptype => $post_type) { $output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr($post_type_obj[$ptype]->name) . '">'; if (isset($post_type_obj[$ptype]->labels->name)) { $output .= "<h4><span>" . $post_type_obj[$ptype]->labels->name . "</span></h4>"; } else { $output .= "<hr>"; } $count = 0; foreach ($post_type as $post) { $count++; if ($count > 4) { continue; } $format = get_post_format($post->ID); if ($img_url = kleo_get_post_thumbnail_url($post->ID)) { $image = aq_resize($img_url, 44, 44, true, true, true); if (!$image) { $image = $img_url; } $image = '<img src="' . $image . '" class="kleo-rounded">'; } else { if ($format == 'video') { $image = "<i class='icon icon-video'></i>"; } elseif ($format == 'image' || $format == 'gallery') { $image = "<i class='icon icon-picture'></i>"; } else { $image = "<i class='icon icon-link'></i>"; } } $excerpt = ""; if (!empty($post->post_content)) { $excerpt = char_trim(trim(strip_tags(strip_shortcodes($post->post_content))), 40, "..."); } $link = apply_filters('kleo_custom_url', get_permalink($post->ID)); $classes = "format-" . $format; $output .= "<div class ='kleo_ajax_entry {$classes}'>"; $output .= "<div class='ajax_search_image'>{$image}</div>"; $output .= "<div class='ajax_search_content'>"; $output .= "<a href='{$link}' class='search_title'>"; $output .= get_the_title($post->ID); $output .= "</a>"; $output .= "<span class='search_excerpt'>"; $output .= $excerpt; $output .= "</span>"; $output .= "</div>"; $output .= "</div>"; } $output .= '</div>'; } $output .= "<a class='ajax_view_all' href='" . home_url('/') . '?s=' . $search_string . "'>" . __('View all results', 'kleo_framework') . "</a>"; } /* Forums topics search */ if (!empty($forums)) { $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">'; $output .= '<h4><span>' . __("Forums", 'kleo_framework') . '</span></h4>'; $i = 0; foreach ($forums as $fk => $forum) { $i++; if ($i <= 4) { $image = "<i class='icon icon-chat-1'></i>"; $output .= "<div class ='kleo_ajax_entry'>"; $output .= "<div class='ajax_search_image'>{$image}</div>"; $output .= "<div class='ajax_search_content'>"; $output .= "<a href='" . $forum['url'] . "' class='search_title'>"; $output .= $forum['name']; $output .= "</a>"; //$output .= "<span class='search_excerpt'>"; //$output .= $latest_activity; //$output .= "</span>"; $output .= "</div>"; $output .= "</div>"; } } $output .= "<a class='ajax_view_all' href='" . bbp_get_search_url() . "?bbp_search=" . $search_string . "'>" . __('View forum results', 'kleo_framework') . "</a>"; $output .= "</div>"; } echo $output; die; }
/** * Output the search url * * @since bbPress (r4579) * * @uses bbp_get_search_url() To get the search url */ function bbp_search_url() { echo esc_url(bbp_get_search_url()); }
function x_bbpress_navbar_menu($items, $args) { if (X_BBPRESS_IS_ACTIVE && x_get_option('x_bbpress_header_menu_enable', '') == '1') { $submenu_items = ''; $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_search_url() . '" class="cf"><i class="x-icon-search" data-x-icon=""></i> <span>' . __('Forums Search', '__x__') . '</span></a></li>'; if (is_user_logged_in()) { $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_favorites_permalink(get_current_user_id()) . '" class="cf"><i class="x-icon-star" data-x-icon=""></i> <span>' . __('Favorites', '__x__') . '</span></a></li>'; $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_subscriptions_permalink(get_current_user_id()) . '" class="cf"><i class="x-icon-bookmark" data-x-icon=""></i> <span>' . __('Subscriptions', '__x__') . '</span></a></li>'; } if (!X_BUDDYPRESS_IS_ACTIVE || X_BUDDYPRESS_IS_ACTIVE && x_get_option('x_buddypress_header_menu_enable', '') == '') { if (!is_user_logged_in()) { $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon=""></i> <span>' . __('Log in', '__x__') . '</span></a></li>'; } else { $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_user_profile_url(get_current_user_id()) . '" class="cf"><i class="x-icon-cog" data-x-icon=""></i> <span>' . __('Profile', '__x__') . '</span></a></li>'; } } if ($args->theme_location == 'primary') { $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-bbpress">' . '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '" class="x-btn-navbar-bbpress">' . '<span><i class="x-icon-comment" data-x-icon=""></i><span class="x-hidden-desktop"> ' . __('Forums', '__x__') . '</span></span>' . '</a>' . '<ul class="sub-menu">' . $submenu_items . '</ul>' . '</li>'; } } return $items; }
/** * Return a breadcrumb ( forum -> topic -> reply ) * * @since bbPress (r2589) * * @param string $sep Separator. Defaults to '←' * @param bool $current_page Include the current item * @param bool $root Include the root page if one exists * * @uses get_post() To get the post * @uses bbp_get_forum_permalink() To get the forum link * @uses bbp_get_topic_permalink() To get the topic link * @uses bbp_get_reply_permalink() To get the reply link * @uses get_permalink() To get the permalink * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_forum_title() To get the forum title * @uses bbp_get_topic_title() To get the topic title * @uses bbp_get_reply_title() To get the reply title * @uses get_the_title() To get the title * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs * @return string Breadcrumbs */ function bbp_get_breadcrumb($args = array()) { // Turn off breadcrumbs if (apply_filters('bbp_no_breadcrumb', is_front_page())) { return; } // Define variables $front_id = $root_id = 0; $ancestors = $crumbs = $tag_data = array(); $pre_root_text = $pre_front_text = $pre_current_text = ''; $pre_include_root = $pre_include_home = $pre_include_current = true; /** Home Text *********************************************************/ // No custom home text if (empty($args['home_text'])) { $front_id = get_option('page_on_front'); // Set home text to page title if (!empty($front_id)) { $pre_front_text = get_the_title($front_id); // Default to 'Home' } else { $pre_front_text = __('Home', 'bbpress'); } } /** Root Text *********************************************************/ // No custom root text if (empty($args['root_text'])) { $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_id = $page->ID; } $pre_root_text = bbp_get_forum_archive_title(); } /** Includes **********************************************************/ // Root slug is also the front page if (!empty($front_id) && $front_id === $root_id) { $pre_include_root = false; } // Don't show root if viewing forum archive if (bbp_is_forum_archive()) { $pre_include_root = false; } // Don't show root if viewing page in place of forum archive if (!empty($root_id) && ((is_single() || is_page()) && $root_id === get_the_ID())) { $pre_include_root = false; } /** Current Text ******************************************************/ // Search page if (bbp_is_search()) { $pre_current_text = bbp_get_search_title(); // Forum archive } elseif (bbp_is_forum_archive()) { $pre_current_text = bbp_get_forum_archive_title(); // Topic archive } elseif (bbp_is_topic_archive()) { $pre_current_text = bbp_get_topic_archive_title(); // View } elseif (bbp_is_single_view()) { $pre_current_text = bbp_get_view_title(); // Single Forum } elseif (bbp_is_single_forum()) { $pre_current_text = bbp_get_forum_title(); // Single Topic } elseif (bbp_is_single_topic()) { $pre_current_text = bbp_get_topic_title(); // Single Topic } elseif (bbp_is_single_reply()) { $pre_current_text = bbp_get_reply_title(); // Topic Tag (or theme compat topic tag) } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag') && !bbp_is_topic_tag_edit()) { // Always include the tag name $tag_data[] = bbp_get_topic_tag_name(); // If capable, include a link to edit the tag if (current_user_can('manage_topic_tags')) { $tag_data[] = '<a href="' . esc_url(bbp_get_topic_tag_edit_link()) . '" class="bbp-edit-topic-tag-link">' . esc_html__('(Edit)', 'bbpress') . '</a>'; } // Implode the results of the tag data $pre_current_text = sprintf(__('Topic Tag: %s', 'bbpress'), implode(' ', $tag_data)); // Edit Topic Tag } elseif (bbp_is_topic_tag_edit()) { $pre_current_text = __('Edit', 'bbpress'); // Single } else { $pre_current_text = get_the_title(); } /** Parse Args ********************************************************/ // Parse args $r = bbp_parse_args($args, array('before' => '<div class="bbp-breadcrumb"><p>', 'after' => '</p></div>', 'sep' => is_rtl() ? __('‹', 'bbpress') : __('›', 'bbpress'), 'pad_sep' => 1, 'sep_before' => '<span class="bbp-breadcrumb-sep">', 'sep_after' => '</span>', 'crumb_before' => '', 'crumb_after' => '', 'include_home' => $pre_include_home, 'home_text' => $pre_front_text, 'include_root' => $pre_include_root, 'root_text' => $pre_root_text, 'include_current' => $pre_include_current, 'current_text' => $pre_current_text, 'current_before' => '<span class="bbp-breadcrumb-current">', 'current_after' => '</span>'), 'get_breadcrumb'); /** Ancestors *********************************************************/ // Get post ancestors if (is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit()) { $ancestors = array_reverse((array) get_post_ancestors(get_the_ID())); } // Do we want to include a link to home? if (!empty($r['include_home']) || empty($r['home_text'])) { $crumbs[] = '<a href="' . trailingslashit(home_url()) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>'; } // Do we want to include a link to the forum root? if (!empty($r['include_root']) || empty($r['root_text'])) { // Page exists at root slug path, so use its permalink $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_url = get_permalink($page->ID); // Use the root slug } else { $root_url = get_post_type_archive_link(bbp_get_forum_post_type()); } // Add the breadcrumb $crumbs[] = '<a href="' . esc_url($root_url) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>'; } // Ancestors exist if (!empty($ancestors)) { // Loop through parents foreach ((array) $ancestors as $parent_id) { // Parents $parent = get_post($parent_id); // Skip parent if empty or error if (empty($parent) || is_wp_error($parent)) { continue; } // Switch through post_type to ensure correct filters are applied switch ($parent->post_type) { // Forum case bbp_get_forum_post_type(): $crumbs[] = '<a href="' . esc_url(bbp_get_forum_permalink($parent->ID)) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($parent->ID) . '</a>'; break; // Topic // Topic case bbp_get_topic_post_type(): $crumbs[] = '<a href="' . esc_url(bbp_get_topic_permalink($parent->ID)) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title($parent->ID) . '</a>'; break; // Reply (Note: not in most themes) // Reply (Note: not in most themes) case bbp_get_reply_post_type(): $crumbs[] = '<a href="' . esc_url(bbp_get_reply_permalink($parent->ID)) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title($parent->ID) . '</a>'; break; // WordPress Post/Page/Other // WordPress Post/Page/Other default: $crumbs[] = '<a href="' . esc_url(get_permalink($parent->ID)) . '" class="bbp-breadcrumb-item">' . get_the_title($parent->ID) . '</a>'; break; } } // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $crumbs[] = '<a href="' . esc_url(get_term_link(bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id())) . '" class="bbp-breadcrumb-topic-tag">' . sprintf(__('Topic Tag: %s', 'bbpress'), bbp_get_topic_tag_name()) . '</a>'; // Search } elseif (bbp_is_search() && bbp_get_search_terms()) { $crumbs[] = '<a href="' . esc_url(bbp_get_search_url()) . '" class="bbp-breadcrumb-search">' . esc_html__('Search', 'bbpress') . '</a>'; } /** Current ***********************************************************/ // Add current page to breadcrumb if (!empty($r['include_current']) || empty($r['current_text'])) { $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after']; } /** Separator *********************************************************/ // Wrap the separator in before/after before padding and filter if (!empty($r['sep'])) { $sep = $r['sep_before'] . $r['sep'] . $r['sep_after']; } // Pad the separator if (!empty($r['pad_sep'])) { if (function_exists('mb_strlen')) { $sep = str_pad($sep, mb_strlen($sep) + (int) $r['pad_sep'] * 2, ' ', STR_PAD_BOTH); } else { $sep = str_pad($sep, strlen($sep) + (int) $r['pad_sep'] * 2, ' ', STR_PAD_BOTH); } } /** Finish Up *********************************************************/ // Filter the separator and breadcrumb $sep = apply_filters('bbp_breadcrumb_separator', $sep); $crumbs = apply_filters('bbp_breadcrumbs', $crumbs); // Build the trail $trail = !empty($crumbs) ? $r['before'] . $r['crumb_before'] . implode($sep . $r['crumb_after'] . $r['crumb_before'], $crumbs) . $r['crumb_after'] . $r['after'] : ''; return apply_filters('bbp_get_breadcrumb', $trail, $crumbs, $r); }
function kleo_search_form_func($atts, $content = null) { $form_style = $type = $placeholder = $context = $el_class = ''; extract(shortcode_atts(array('form_style' => 'default', 'type' => 'both', 'context' => '', 'placeholder' => '', 'el_class' => ''), $atts)); global $kleo_config; $class = ''; if ($el_class != '') { $class = ' ' . $el_class; } $class .= ' search-style-' . $form_style; //Defaults $action = home_url('/'); $hidden = ''; $input_name = 's'; $ajax_results = 'yes'; $search_page = 'yes'; if ($type == 'ajax') { $search_page = 'no'; } elseif ($type == 'form_submit') { $ajax_results = 'no'; } if (function_exists('bp_is_active') && $context == 'members') { //Buddypress members form link $action = bp_get_members_directory_permalink(); } elseif (function_exists('bp_is_active') && bp_is_active('groups') && $context == 'groups') { //Buddypress group directory link $action = bp_get_groups_directory_permalink(); } elseif (class_exists('bbPress') && $context == 'forum') { $action = bbp_get_search_url(); $input_name = 'bbp_search'; } elseif ($context == 'product') { $hidden .= '<input type="hidden" name="post_type" value="product">'; } $output = '<div class="kleo-search-wrap kleo-search-form' . $class . '">'; $output .= '<form role="search" method="get" id="searchform" ' . ($search_page == 'no' ? ' onsubmit="return false;"' : '') . ' action="' . $action . '" data-context="' . $context . '"> <div class="input-group"> <input name="' . $input_name . '" id="' . $input_name . '" autocomplete="off" type="text" class="ajax_s form-control input-lg" value="" placeholder="' . $placeholder . '">'; if ($search_page == 'yes') { $output .= '<span class="input-group-btn">' . '<input type="submit" value="' . __("Search") . '" id="searchsubmit" class="button">' . '</span>'; } $output .= '</div>' . $hidden . '</form>'; if ($ajax_results == 'yes') { $output .= '<span class="kleo-ajax-search-loading"><span class="kleo-loading-icon"></span></span><div class="kleo_ajax_results"></div>'; } $output .= '</div>'; return $output; }