| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* BetterDocs all shortcodes |
| 5 |
* |
| 6 |
* @link https://wpdeveloper.com |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package BetterDocs |
| 10 |
* @subpackage BetterDocs/public |
| 11 |
*/ |
| 12 |
|
| 13 |
use WPML\FP\Str; |
| 14 |
|
| 15 |
/** |
| 16 |
* Docs Reactions Shortcode |
| 17 |
* * |
| 18 |
* @since 1.0.2 |
| 19 |
* |
| 20 |
*/ |
| 21 |
add_shortcode('betterdocs_article_reactions', 'betterdocs_article_reaction'); |
| 22 |
function betterdocs_article_reaction($atts, $content = null) |
| 23 |
{ |
| 24 |
$get_args = shortcode_atts( |
| 25 |
array( |
| 26 |
'text' => '' |
| 27 |
), |
| 28 |
$atts |
| 29 |
); |
| 30 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 31 |
if ($get_args['text']) { |
| 32 |
$reactions_text = $get_args['text']; |
| 33 |
} else { |
| 34 |
$reactions_text = get_theme_mod('betterdocs_post_reactions_text', esc_html__('What are your Feelings', 'betterdocs')); |
| 35 |
} |
| 36 |
?> |
| 37 |
<div class="betterdocs-article-reactions"> |
| 38 |
<div class="betterdocs-article-reactions-heading"> |
| 39 |
<?php |
| 40 |
if ($reactions_text) { |
| 41 |
echo '<h5>' . esc_html($reactions_text) . '</h5>'; |
| 42 |
} |
| 43 |
?> |
| 44 |
</div> |
| 45 |
<ul class="betterdocs-article-reaction-links"> |
| 46 |
<li> |
| 47 |
<a class="betterdocs-feelings" data-feelings="happy" href="#"> |
| 48 |
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve"> |
| 49 |
<path class="st0" d="M10,0.1c-5.4,0-9.9,4.4-9.9,9.8c0,5.4,4.4,9.9,9.8,9.9c5.4,0,9.9-4.4,9.9-9.8C19.9,4.5,15.4,0.1,10,0.1z |
| 50 |
M13.3,6.4c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C11.8,7.1,12.5,6.4,13.3,6.4z M6.7,6.4 |
| 51 |
c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C5.2,7.1,5.9,6.4,6.7,6.4z M10,16.1c-2.6,0-4.9-1.6-5.8-4 |
| 52 |
l1.2-0.4c0.7,1.9,2.5,3.2,4.6,3.2s3.9-1.3,4.6-3.2l1.2,0.4C14.9,14.5,12.6,16.1,10,16.1z" /> |
| 53 |
<path class="st1" d="M-6.6-119.7c-7.1,0-12.9,5.8-12.9,12.9s5.8,12.9,12.9,12.9s12.9-5.8,12.9-12.9S0.6-119.7-6.6-119.7z |
| 54 |
M-2.3-111.4c1.1,0,2,0.9,2,2c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2C-4.3-110.5-3.4-111.4-2.3-111.4z M-10.9-111.4c1.1,0,2,0.9,2,2 |
| 55 |
c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2C-12.9-110.5-12-111.4-10.9-111.4z M-6.6-98.7c-3.4,0-6.4-2.1-7.6-5.3l1.6-0.6 |
| 56 |
c0.9,2.5,3.3,4.2,6,4.2s5.1-1.7,6-4.2L1-104C-0.1-100.8-3.2-98.7-6.6-98.7z" /> |
| 57 |
</svg> |
| 58 |
</a> |
| 59 |
</li> |
| 60 |
<li> |
| 61 |
<a class="betterdocs-feelings" data-feelings="normal" href="#"> |
| 62 |
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve"> |
| 63 |
<path class="st0" d="M10,0.2c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S15.4,0.2,10,0.2z M6.7,6.5 |
| 64 |
c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5C5.9,9.5,5.2,8.9,5.2,8C5.2,7.2,5.9,6.5,6.7,6.5z M14.2,14.3H5.9 |
| 65 |
c-0.3,0-0.6-0.3-0.6-0.6c0-0.3,0.3-0.6,0.6-0.6h8.3c0.3,0,0.6,0.3,0.6,0.6C14.8,14,14.5,14.3,14.2,14.3z M13.3,9.5 |
| 66 |
c-0.8,0-1.5-0.7-1.5-1.5c0-0.8,0.7-1.5,1.5-1.5c0.8,0,1.5,0.7,1.5,1.5C14.8,8.9,14.1,9.5,13.3,9.5z" /> |
| 67 |
</svg> |
| 68 |
</a> |
| 69 |
</li> |
| 70 |
<li> |
| 71 |
<a class="betterdocs-feelings" data-feelings="sad" href="#"> |
| 72 |
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve"> |
| 73 |
<circle class="st0" cx="27.5" cy="0.6" r="1.9" /> |
| 74 |
<circle class="st0" cx="36" cy="0.6" r="1.9" /> |
| 75 |
<path class="st1" d="M10,0.3c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S15.4,0.3,10,0.3z M13.3,6.6 |
| 76 |
c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C11.8,7.3,12.4,6.6,13.3,6.6z M6.7,6.6c0.8,0,1.5,0.7,1.5,1.5 |
| 77 |
c0,0.8-0.7,1.5-1.5,1.5C5.9,9.6,5.2,9,5.2,8.1C5.2,7.3,5.9,6.6,6.7,6.6z M14.1,15L14.1,15c-0.2,0-0.4-0.1-0.5-0.2 |
| 78 |
c-0.9-1-2.2-1.7-3.7-1.7s-2.8,0.6-3.7,1.7C6.2,14.9,6,15,5.9,15h0c-0.6,0-0.8-0.6-0.5-1.1c1.1-1.3,2.8-2.1,4.6-2.1 |
| 79 |
c1.8,0,3.5,0.8,4.6,2.1C15,14.3,14.7,15,14.1,15z" /> |
| 80 |
</svg> |
| 81 |
</a> |
| 82 |
</li> |
| 83 |
</ul> |
| 84 |
</div> <!-- Social Share end--> |
| 85 |
<?php |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Get terms post count including child terms |
| 90 |
*/ |
| 91 |
function betterdocs_get_postcount($term_count, $term_id, $nested_subcategory=false) |
| 92 |
{ |
| 93 |
if ($nested_subcategory==false) { |
| 94 |
return $term_count; |
| 95 |
} |
| 96 |
|
| 97 |
$taxonomy = 'doc_category'; |
| 98 |
|
| 99 |
$args = array( |
| 100 |
'child_of' => $term_id |
| 101 |
); |
| 102 |
|
| 103 |
$tax_terms = get_terms($taxonomy, $args); |
| 104 |
|
| 105 |
if ($tax_terms) { |
| 106 |
foreach ($tax_terms as $tax_term) { |
| 107 |
$term_count += $tax_term->count; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
return $term_count; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Get the category grid with docs list. |
| 116 |
* * |
| 117 |
* @since 1.0.0 |
| 118 |
* * |
| 119 |
* @param int $atts Get attributes for the categories. |
| 120 |
* @param int $content Get content to category. |
| 121 |
*/ |
| 122 |
add_shortcode('betterdocs_category_grid', 'betterdocs_category_grid'); |
| 123 |
function betterdocs_category_grid($atts, $content = null) |
| 124 |
{ |
| 125 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 126 |
ob_start(); |
| 127 |
global $wp_query; |
| 128 |
|
| 129 |
$column_val = ''; |
| 130 |
$masonry_layout = BetterDocs_DB::get_settings('masonry_layout'); |
| 131 |
$alphabetic_order = BetterDocs_DB::get_settings('alphabetically_order_post'); |
| 132 |
$column_number = BetterDocs_DB::get_settings('column_number'); |
| 133 |
$posts_number = BetterDocs_DB::get_settings('posts_number'); |
| 134 |
$exploremore_btn = BetterDocs_DB::get_settings('exploremore_btn'); |
| 135 |
$exploremore_btn_txt = BetterDocs_DB::get_settings('exploremore_btn_txt'); |
| 136 |
$get_args = shortcode_atts( |
| 137 |
array( |
| 138 |
'sidebar_list' => false, |
| 139 |
'post_type' => 'docs', |
| 140 |
'category' => 'doc_category', |
| 141 |
'orderby' => BetterDocs_DB::get_settings('alphabetically_order_post'), |
| 142 |
'order' => BetterDocs_DB::get_settings('docs_order'), |
| 143 |
'post_counter' => BetterDocs_DB::get_settings('post_count') != 'off' ? 'true' : 'false', |
| 144 |
'icon' => true, |
| 145 |
'masonry' => '', |
| 146 |
'column' => '', |
| 147 |
'posts_per_grid' => '', |
| 148 |
'nested_subcategory' => BetterDocs_DB::get_settings('nested_subcategory') != 'off' ? 'true' : 'false', |
| 149 |
'terms' => '', |
| 150 |
'terms_orderby' => '', |
| 151 |
'terms_order' => '', |
| 152 |
'kb_slug' => '', |
| 153 |
'multiple_knowledge_base' => false, |
| 154 |
'disable_customizer_style' => false, |
| 155 |
'title_tag' => 'h2' |
| 156 |
), |
| 157 |
$atts |
| 158 |
); |
| 159 |
|
| 160 |
$post_counter = ( $get_args['post_counter'] == 'true' ) ? true : false; |
| 161 |
$post_icon_check = ( $get_args['icon'] == 'true' ) ? true : false; |
| 162 |
$masonry_check = ( $get_args['masonry'] == 'true' ) ? true : false; |
| 163 |
$nested_subcategory = $get_args['nested_subcategory'] === 'true' ? true : false; |
| 164 |
$masonry = ($masonry_layout == 1 && $masonry_check == '') || ($masonry_check == true && $masonry_check != "false"); |
| 165 |
$taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms'], $get_args['terms_order'], $get_args['terms_orderby'], $get_args['kb_slug'], $nested_subcategory); |
| 166 |
if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) { |
| 167 |
$class = ['betterdocs-categories-wrap category-grid white-bg']; |
| 168 |
if (!is_singular('docs') && !is_tax('doc_category') && !is_tax('doc_tag')) { |
| 169 |
if ($get_args['sidebar_list'] == true) { |
| 170 |
$class[] = 'layout-flex'; |
| 171 |
} elseif ($masonry == true) { |
| 172 |
wp_enqueue_script('masonry'); |
| 173 |
$class[] = 'layout-masonry'; |
| 174 |
} else { |
| 175 |
$class[] = 'layout-flex'; |
| 176 |
} |
| 177 |
|
| 178 |
if ($get_args['sidebar_list'] == true) { |
| 179 |
$column_val = 1; |
| 180 |
} elseif (isset($get_args['column']) && $get_args['column'] == true && is_numeric($get_args['column'])) { |
| 181 |
$column_val = $get_args['column']; |
| 182 |
} else { |
| 183 |
$column_val = $column_number; |
| 184 |
} |
| 185 |
$class[] = 'docs-col-' . $column_val; |
| 186 |
if ($get_args['disable_customizer_style'] == false) { |
| 187 |
$class[] = 'single-kb'; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
echo '<div class="'. implode(' ', $class) .'" data-column="'. esc_html($column_val) .'">'; |
| 192 |
$term_list = wp_get_post_terms(get_the_ID(), 'doc_category', array("fields" => "all")); |
| 193 |
// get single page category id |
| 194 |
if (is_single() && !empty($term_list)) { |
| 195 |
$category_id = array_column($term_list, 'term_id'); |
| 196 |
$cat_index = isset( $category_id[0] ) ? $category_id[0] : ''; |
| 197 |
$ancestors = get_ancestors($cat_index, 'doc_category'); |
| 198 |
$page_cat = get_the_ID(); |
| 199 |
} else { |
| 200 |
$category_id = array(); |
| 201 |
$page_cat = ''; |
| 202 |
$ancestors = array(); |
| 203 |
} |
| 204 |
/** |
| 205 |
* Get Queried Object - For KB |
| 206 |
*/ |
| 207 |
|
| 208 |
// display category grid by order |
| 209 |
foreach ($taxonomy_objects as $term) { |
| 210 |
//for single doc category page ID |
| 211 |
$current_cat_id = get_queried_object(); |
| 212 |
//for single post Category ID |
| 213 |
$current_post_cat_id = get_the_terms( get_the_ID(), 'doc_category'); |
| 214 |
$term_id = $term->term_id; |
| 215 |
$term_slug = $term->slug; |
| 216 |
$count = $term->count; |
| 217 |
$get_term_count = betterdocs_get_postcount($count, $term_id, $nested_subcategory); |
| 218 |
$term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count, $nested_subcategory); |
| 219 |
$current_term_id = isset( $current_post_cat_id[0]->term_id ) ? $current_post_cat_id[0]->term_id : ''; |
| 220 |
if ($term_count > 0) { |
| 221 |
if (is_single() && ( $current_term_id == $term_id || ( $nested_subcategory == 1 && in_array($term_id, $ancestors ) ) ) ) { |
| 222 |
// set active category class in single page |
| 223 |
$wrap_class = 'docs-single-cat-wrap current-category'; |
| 224 |
$title_class = 'docs-cat-title-wrap active-title'; |
| 225 |
} elseif( BetterDocs_Helper::get_tax() == 'doc_category' && $current_cat_id->term_id == $term_id ) { |
| 226 |
$wrap_class = 'docs-single-cat-wrap current-category'; |
| 227 |
$title_class = 'docs-cat-title-wrap active-title'; |
| 228 |
} else { |
| 229 |
// by default docs page |
| 230 |
$wrap_class = 'docs-single-cat-wrap'; |
| 231 |
$title_class = 'docs-cat-title-wrap'; |
| 232 |
} |
| 233 |
|
| 234 |
$cat_icon_id = get_term_meta($term_id, 'doc_category_image-id', true); |
| 235 |
|
| 236 |
if ($cat_icon_id) { |
| 237 |
$cat_icon_url = wp_get_attachment_image_url($cat_icon_id, 'thumbnail'); |
| 238 |
$cat_icon = '<img class="docs-cat-icon" src="' . $cat_icon_url . '" alt="'.$term->name.'">'; |
| 239 |
} else { |
| 240 |
$cat_icon = '<img class="docs-cat-icon" src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="'.$term->name.'">'; |
| 241 |
} |
| 242 |
|
| 243 |
if ($post_icon_check == false) { |
| 244 |
$cat_icon = ''; |
| 245 |
} |
| 246 |
|
| 247 |
echo '<div id="cat-id-'. esc_attr($term_id) .'" class="'. esc_attr($wrap_class) .'"> |
| 248 |
<div class="'. esc_attr($title_class) .'"> |
| 249 |
<div class="docs-cat-title-inner">'; |
| 250 |
$term_permalink = BetterDocs_Helper::term_permalink('doc_category', $term->slug); |
| 251 |
|
| 252 |
if ($get_args['sidebar_list'] == true) { |
| 253 |
echo '<div class="docs-cat-title">' . $cat_icon . '<'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-heading">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'></div>'; |
| 254 |
} else { |
| 255 |
echo '<div class="docs-cat-title">' . $cat_icon . '<a href="' . esc_url($term_permalink) . '"><'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-heading">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'></a></div>'; |
| 256 |
} |
| 257 |
|
| 258 |
if ( $post_counter === true ) { |
| 259 |
echo '<div class="docs-item-count"><span>' . $term_count . '</span></div>'; |
| 260 |
} |
| 261 |
|
| 262 |
echo '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="angle-down" class="cat-list-arrow-down svg-inline--fa fa-angle-down fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"> |
| 263 |
<path fill="currentColor" d="M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z"></path> |
| 264 |
</svg> |
| 265 |
</div> |
| 266 |
</div> |
| 267 |
<div class="docs-item-container">'; |
| 268 |
if (isset($get_args['posts_per_grid']) && $get_args['posts_per_grid'] == true && is_numeric($get_args['posts_per_grid'])) { |
| 269 |
$posts_per_grid = $get_args['posts_per_grid']; |
| 270 |
} else { |
| 271 |
$posts_per_grid = $posts_number; |
| 272 |
} |
| 273 |
|
| 274 |
$list_args = BetterDocs_Helper::list_query_arg('docs', $get_args['multiple_knowledge_base'], $term_slug, $posts_per_grid, $get_args['orderby'], $get_args['order'], $get_args['kb_slug']); |
| 275 |
$args = apply_filters('betterdocs_articles_args', $list_args, $term->term_id); |
| 276 |
$post_query = new WP_Query($args); |
| 277 |
if ($post_query->have_posts()) : |
| 278 |
echo '<ul>'; |
| 279 |
while ($post_query->have_posts()) : $post_query->the_post(); |
| 280 |
$attr = ['href="' . get_the_permalink() . '"']; |
| 281 |
if ($page_cat === get_the_ID() && BetterDocs_Helper::get_tax() != 'doc_category') { |
| 282 |
$attr[] = 'class="active"'; |
| 283 |
} |
| 284 |
echo '<li>' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>'; |
| 285 |
endwhile; |
| 286 |
echo '</ul>'; |
| 287 |
endif; |
| 288 |
wp_reset_query(); |
| 289 |
|
| 290 |
// Sub category query |
| 291 |
if ($nested_subcategory == true) { |
| 292 |
nested_category_list( |
| 293 |
$term_id, |
| 294 |
$get_args['multiple_knowledge_base'], |
| 295 |
$category_id, |
| 296 |
'docs', |
| 297 |
$get_args['orderby'], |
| 298 |
$get_args['order'], |
| 299 |
$get_args['terms_orderby'], |
| 300 |
$get_args['terms_order'], |
| 301 |
$page_cat, |
| 302 |
$get_args['kb_slug'] |
| 303 |
); |
| 304 |
} |
| 305 |
|
| 306 |
// Read More Button |
| 307 |
if ($get_args['posts_per_grid'] == '-1' || $posts_number == '-1') { |
| 308 |
echo ''; |
| 309 |
} else if ($exploremore_btn == 1 && !is_singular('docs') && BetterDocs_Helper::get_tax() != 'doc_category' && !is_tax('doc_tag')) { |
| 310 |
echo '<a class="docs-cat-link-btn" href="' . $term_permalink . '">' . esc_html(stripslashes($exploremore_btn_txt)) . '</a>'; |
| 311 |
} |
| 312 |
echo '</div> |
| 313 |
</div>'; |
| 314 |
} |
| 315 |
} |
| 316 |
echo '</div>'; |
| 317 |
} else { |
| 318 |
echo '<div class="betterdocs-categories-wrap category-grid"> |
| 319 |
<div class="docs-single-cat-wrap"> |
| 320 |
<div class="docs-cat-title-wrap"> |
| 321 |
<div class="docs-cat-title-inner"> |
| 322 |
<div class="docs-cat-title"> |
| 323 |
<img class="docs-cat-icon" src="<?php echo BETTERDOCS_ADMIN_URL ?>assets/img/betterdocs-cat-icon.svg" alt=""> |
| 324 |
<'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'>'.esc_html__('Uncategorised', 'betterdocs').'</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'> |
| 325 |
</div> |
| 326 |
</div> |
| 327 |
</div> |
| 328 |
<div class="docs-item-container">'; |
| 329 |
$args = array( |
| 330 |
'post_type' => 'docs' |
| 331 |
); |
| 332 |
if (isset($get_args['posts_per_grid']) && $get_args['posts_per_grid'] == true && is_numeric($get_args['posts_per_grid'])) { |
| 333 |
$posts_number = $get_args['posts_per_grid']; |
| 334 |
} |
| 335 |
$args['posts_per_page'] = $posts_number; |
| 336 |
|
| 337 |
if ($alphabetic_order == 1) { |
| 338 |
$args['orderby'] = 'title'; |
| 339 |
$args['order'] = 'ASC'; |
| 340 |
} |
| 341 |
|
| 342 |
$uncategorised_tax_query = ''; |
| 343 |
$args['tax_query'] = apply_filters('betterdocs_kb_uncategorised_tax_query', $uncategorised_tax_query, $wp_query); |
| 344 |
$args = apply_filters('betterdocs_articles_args', $args); |
| 345 |
$args = apply_filters('betterdocs_uncategorized_args', $args); |
| 346 |
$post_query = new WP_Query($args); |
| 347 |
if ($post_query->have_posts()) : |
| 348 |
echo '<ul>'; |
| 349 |
while ($post_query->have_posts()) : $post_query->the_post(); |
| 350 |
$attr = ['href="' . get_the_permalink() . '"']; |
| 351 |
echo '<li>' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>'; |
| 352 |
endwhile; |
| 353 |
echo '</ul>'; |
| 354 |
endif; |
| 355 |
wp_reset_query(); |
| 356 |
echo '</div> |
| 357 |
</div> |
| 358 |
</div>'; |
| 359 |
} |
| 360 |
|
| 361 |
if ($masonry == true ) { |
| 362 |
$output = betterdocs_generate_output(); |
| 363 |
echo '<script> |
| 364 |
jQuery(document).ready(function() { |
| 365 |
let masonryGrid = jQuery(".betterdocs-categories-wrap.layout-masonry"); |
| 366 |
let columnPerGrid = jQuery(".betterdocs-categories-wrap.layout-masonry").attr("data-column"); |
| 367 |
let masonryItem = jQuery(".betterdocs-categories-wrap.layout-masonry .docs-single-cat-wrap"); |
| 368 |
let doc_page_column_space = '.$output['betterdocs_doc_page_column_space'].'; |
| 369 |
let total_margin = (columnPerGrid - 1) * doc_page_column_space; |
| 370 |
if (masonryGrid.length) { |
| 371 |
masonryItem.css("width", "calc((100% - "+total_margin+"px) / "+parseInt(columnPerGrid)+")"); |
| 372 |
masonryGrid.masonry({ |
| 373 |
itemSelector: ".docs-single-cat-wrap", |
| 374 |
percentPosition: true, |
| 375 |
gutter: doc_page_column_space |
| 376 |
}); |
| 377 |
} |
| 378 |
}); |
| 379 |
</script>'; |
| 380 |
} |
| 381 |
return ob_get_clean(); |
| 382 |
} |
| 383 |
|
| 384 |
function nested_category_list($term_id, $multiple_kb, $category_id, $post_type, $docs_orderby, $docs_order, $terms_orderby, $terms_order, $page_cat, $kb_slug='', $nested_posts_num = -1) { |
| 385 |
$sub_categories = BetterDocs_Helper::child_taxonomy_terms($term_id, $multiple_kb, $terms_orderby, $terms_order, $kb_slug); |
| 386 |
if ($sub_categories) { |
| 387 |
foreach ($sub_categories as $sub_category) { |
| 388 |
if (is_single() && in_array($sub_category->term_id, $category_id)) { |
| 389 |
$subcat_class = 'docs-sub-cat current-sub-cat'; |
| 390 |
} else { |
| 391 |
$subcat_class = 'docs-sub-cat'; |
| 392 |
} |
| 393 |
|
| 394 |
echo '<span class="docs-sub-cat-title"> |
| 395 |
' . BetterDocs_Helper::arrow_right_svg() . ' |
| 396 |
' . BetterDocs_Helper::arrow_down_svg() . ' |
| 397 |
<a href="#">' . $sub_category->name . '</a></span>'; |
| 398 |
|
| 399 |
echo '<ul class="' . esc_attr($subcat_class) . '">'; |
| 400 |
$sub_args = BetterDocs_Helper::list_query_arg($post_type, $multiple_kb, $sub_category->slug, $nested_posts_num, $docs_orderby, $docs_order, $kb_slug); |
| 401 |
$sub_args = apply_filters('betterdocs_articles_args', $sub_args, $sub_category->term_id); |
| 402 |
$sub_post_query = new WP_Query($sub_args); |
| 403 |
|
| 404 |
if ($sub_post_query->have_posts()) : |
| 405 |
while ($sub_post_query->have_posts()) : $sub_post_query->the_post(); |
| 406 |
$sub_attr = ['href="' . get_the_permalink() . '"']; |
| 407 |
if ($page_cat === get_the_ID() && BetterDocs_Helper::get_tax() != 'doc_category') { |
| 408 |
$sub_attr[] = 'class="active"'; |
| 409 |
} |
| 410 |
echo '<li class="sub-list">' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $sub_attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>'; |
| 411 |
endwhile; |
| 412 |
endif; |
| 413 |
wp_reset_query(); |
| 414 |
nested_category_list( $sub_category->term_id, $multiple_kb, $category_id, $post_type, $docs_orderby, $docs_order, $terms_orderby, $terms_order, $page_cat, $kb_slug, $nested_posts_num ); |
| 415 |
echo '</ul>'; |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
/** |
| 422 |
* Get the category grid with docs list. |
| 423 |
* * |
| 424 |
* @since 1.0.0 |
| 425 |
* * |
| 426 |
* @param int $atts Get attributes for the categories. |
| 427 |
* @param int $content Get content to category. |
| 428 |
*/ |
| 429 |
add_shortcode('betterdocs_category_list', 'betterdocs_category_list'); |
| 430 |
function betterdocs_category_list($atts, $content = null) |
| 431 |
{ |
| 432 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 433 |
ob_start(); |
| 434 |
$alphabetic_order = BetterDocs_DB::get_settings('alphabetically_order_post'); |
| 435 |
$nested_subcategory = BetterDocs_DB::get_settings('nested_subcategory'); |
| 436 |
$get_args = shortcode_atts( |
| 437 |
array( |
| 438 |
'post_type' => 'docs', |
| 439 |
'category' => 'doc_category', |
| 440 |
'orderby' => BetterDocs_DB::get_settings('alphabetically_order_post'), |
| 441 |
'order' => BetterDocs_DB::get_settings('docs_order'), |
| 442 |
'masonry' => '', |
| 443 |
'column' => '', |
| 444 |
'posts_per_page' => '', |
| 445 |
'nested_subcategory' => '', |
| 446 |
'terms' => '', |
| 447 |
'terms_orderby' => '', |
| 448 |
'terms_order' => '', |
| 449 |
'kb_slug' => '', |
| 450 |
'multiple_knowledge_base' => false, |
| 451 |
'title_tag' => 'h2' |
| 452 |
), |
| 453 |
$atts |
| 454 |
); |
| 455 |
|
| 456 |
$nested_subcategory = ($nested_subcategory == 1 && $get_args['nested_subcategory'] == '') || ($get_args['nested_subcategory'] == true && $get_args['nested_subcategory'] != "false"); |
| 457 |
$taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms'], $get_args['terms_order'], $get_args['terms_orderby'], $get_args['kb_slug'], $nested_subcategory); |
| 458 |
|
| 459 |
if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) : ?> |
| 460 |
<div class="betterdocs-categories-wrap category-list"> |
| 461 |
<?php |
| 462 |
$term_list = wp_get_post_terms(get_the_ID(), 'doc_category', array("fields" => "all")); |
| 463 |
|
| 464 |
// get single page category id |
| 465 |
if (is_single() && $term_list) { |
| 466 |
$category_id = array_column($term_list, 'term_id'); |
| 467 |
$page_cat = get_the_ID(); |
| 468 |
} else { |
| 469 |
$category_id = array(); |
| 470 |
$page_cat = ''; |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* For Multiple KB |
| 475 |
*/ |
| 476 |
$q_object = get_queried_object(); |
| 477 |
$kb_slug = ''; |
| 478 |
|
| 479 |
if ($q_object instanceof WP_Term) { |
| 480 |
$kb_slug = $q_object->slug; |
| 481 |
} |
| 482 |
|
| 483 |
// display category grid by order |
| 484 |
foreach ($taxonomy_objects as $term) { |
| 485 |
$term_id = $term->term_id; |
| 486 |
$term_slug = $term->slug; |
| 487 |
$count = $term->count; |
| 488 |
$get_term_count = betterdocs_get_postcount($count, $term_id, $nested_subcategory); |
| 489 |
$term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count, $nested_subcategory); |
| 490 |
if ($term_count > 0) { |
| 491 |
// set active category class in single page |
| 492 |
if (is_single() && in_array($term_id, $category_id)) { |
| 493 |
$wrap_class = 'docs-single-cat-wrap-2 current-category'; |
| 494 |
$title_class = 'active-title'; |
| 495 |
} else { |
| 496 |
$wrap_class = 'docs-single-cat-wrap-2'; |
| 497 |
$title_class = ''; |
| 498 |
} |
| 499 |
|
| 500 |
$term_permalink = BetterDocs_Helper::term_permalink('doc_category', $term_slug); |
| 501 |
?> |
| 502 |
<div id="cat-id-<?php echo $term_id; ?>" class="cat tet <?php echo esc_attr($wrap_class) ?>"> |
| 503 |
<div class="<?php echo esc_attr($title_class) ?>"> |
| 504 |
<div class="docs-cat-title-inner"> |
| 505 |
<?php |
| 506 |
echo '<div class="docs-cat-title"><a href="' . esc_url($term_permalink) . '"><'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-heading">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'></a></div>'; |
| 507 |
?> |
| 508 |
</div> |
| 509 |
</div> |
| 510 |
<div class="docs-item-container"> |
| 511 |
<?php |
| 512 |
$list_args = BetterDocs_Helper::list_query_arg('docs', $get_args['multiple_knowledge_base'], $term_slug, -1, $get_args['orderby'], $get_args['order'], $kb_slug); |
| 513 |
$args = apply_filters('betterdocs_articles_args', $list_args, $term->term_id); |
| 514 |
$post_query = new WP_Query($args); |
| 515 |
if ($post_query->have_posts()) : |
| 516 |
|
| 517 |
echo '<ul>'; |
| 518 |
while ($post_query->have_posts()) : $post_query->the_post(); |
| 519 |
$attr = ['href="' . get_the_permalink() . '"']; |
| 520 |
if ($page_cat === get_the_ID()) { |
| 521 |
$attr[] = 'class="active"'; |
| 522 |
} |
| 523 |
echo '<li><a ' . implode(' ', $attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>'; |
| 524 |
endwhile; |
| 525 |
|
| 526 |
echo '</ul>'; |
| 527 |
|
| 528 |
endif; |
| 529 |
wp_reset_query(); |
| 530 |
|
| 531 |
// Sub category query |
| 532 |
if (($nested_subcategory == 1 || $get_args['nested_subcategory'] == true) && $get_args['nested_subcategory'] != "false") { |
| 533 |
nested_category_list( |
| 534 |
$term_id, |
| 535 |
$get_args['multiple_knowledge_base'], |
| 536 |
$category_id, |
| 537 |
'docs', |
| 538 |
$get_args['orderby'], |
| 539 |
$get_args['order'], |
| 540 |
$get_args['terms_orderby'], |
| 541 |
$get_args['terms_order'], |
| 542 |
$page_cat, |
| 543 |
'' |
| 544 |
); |
| 545 |
} |
| 546 |
?> |
| 547 |
</div> |
| 548 |
</div> |
| 549 |
<?php } |
| 550 |
} ?> |
| 551 |
</div> |
| 552 |
<?php |
| 553 |
endif; |
| 554 |
return ob_get_clean(); |
| 555 |
} |
| 556 |
|
| 557 |
/** |
| 558 |
* Get the category grid with docs list. |
| 559 |
* * |
| 560 |
* @since 1.0.0 |
| 561 |
* * |
| 562 |
* @param int $atts Get attributes for the categories. |
| 563 |
* @param int $content Get content to category. |
| 564 |
*/ |
| 565 |
add_shortcode('betterdocs_category_box', 'betterdocs_category_box'); |
| 566 |
function betterdocs_category_box($atts, $content = null) |
| 567 |
{ |
| 568 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 569 |
ob_start(); |
| 570 |
$column_number = BetterDocs_DB::get_settings('column_number'); |
| 571 |
$post_count = BetterDocs_DB::get_settings('post_count'); |
| 572 |
$count_text_singular = BetterDocs_DB::get_settings('count_text_singular'); |
| 573 |
$count_text = BetterDocs_DB::get_settings('count_text'); |
| 574 |
$nested_subcategory = BetterDocs_DB::get_settings('nested_subcategory'); |
| 575 |
$get_args = shortcode_atts( |
| 576 |
array( |
| 577 |
'post_type' => 'docs', |
| 578 |
'category' => 'doc_category', |
| 579 |
'orderby' => BetterDocs_DB::get_settings('alphabetically_order_post'), |
| 580 |
'column' => '', |
| 581 |
'nested_subcategory' => '', |
| 582 |
'terms' => '', |
| 583 |
'terms_orderby' => BetterDocs_DB::get_settings('alphabetically_order_term'), |
| 584 |
'terms_order' => '', |
| 585 |
'icon' => true, |
| 586 |
'kb_slug' => '', |
| 587 |
'title_tag' => 'h2', |
| 588 |
'multiple_knowledge_base' => false, |
| 589 |
'disable_customizer_style' => false, |
| 590 |
'border_bottom' => false |
| 591 |
), |
| 592 |
$atts |
| 593 |
); |
| 594 |
$post_icon_check = ( $get_args['icon'] == 'true' ) ? true : false; |
| 595 |
$nested_subcategory = ($nested_subcategory == 1 && $get_args['nested_subcategory'] == '') || ($get_args['nested_subcategory'] == true && $get_args['nested_subcategory'] != "false"); |
| 596 |
$taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms'], $get_args['terms_order'], $get_args['terms_orderby'], $get_args['kb_slug'], $nested_subcategory); |
| 597 |
|
| 598 |
if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) : |
| 599 |
$class = ['betterdocs-categories-wrap betterdocs-category-box layout-2 ash-bg']; |
| 600 |
$class[] = 'layout-flex'; |
| 601 |
|
| 602 |
if (isset($get_args['column']) && $get_args['column'] == true && is_numeric($get_args['column'])) { |
| 603 |
$class[] = 'docs-col-' . $get_args['column']; |
| 604 |
} else { |
| 605 |
$class[] = 'docs-col-' . $column_number; |
| 606 |
} |
| 607 |
|
| 608 |
if (isset($get_args['border_bottom']) && $get_args['border_bottom'] == true) { |
| 609 |
$class[] = 'border-bottom'; |
| 610 |
} |
| 611 |
|
| 612 |
if ($get_args['disable_customizer_style'] == false) { |
| 613 |
$class[] = 'single-kb'; |
| 614 |
} |
| 615 |
|
| 616 |
echo '<div class="'.implode(' ', $class).'">'; |
| 617 |
// display category grid by order |
| 618 |
foreach ($taxonomy_objects as $term) { |
| 619 |
$term_id = $term->term_id; |
| 620 |
$term_slug = $term->slug; |
| 621 |
$count = $term->count; |
| 622 |
$get_term_count = betterdocs_get_postcount($count, $term_id, $nested_subcategory); |
| 623 |
$term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count, $nested_subcategory); |
| 624 |
|
| 625 |
if ($term_count > 0) { |
| 626 |
// set active category class in single page |
| 627 |
$wrap_class = 'docs-single-cat-wrap'; |
| 628 |
$term_permalink = BetterDocs_Helper::term_permalink('doc_category', $term->slug); |
| 629 |
echo '<a href="'.esc_url($term_permalink).'" class="'.esc_attr($wrap_class).'" id="cat-id-'.$term_id.'">'; |
| 630 |
if($post_icon_check) { |
| 631 |
$cat_icon_id = get_term_meta($term_id, 'doc_category_image-id', true); |
| 632 |
if ($cat_icon_id) { |
| 633 |
echo wp_get_attachment_image($cat_icon_id, 'thumbnail'); |
| 634 |
} else { |
| 635 |
echo '<img class="docs-cat-icon" src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="">'; |
| 636 |
} |
| 637 |
} |
| 638 |
echo '<'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-title">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'>'; |
| 639 |
$cat_desc = get_theme_mod('betterdocs_doc_page_cat_desc'); |
| 640 |
if ($cat_desc == true) { |
| 641 |
echo '<p class="cat-description">' . $term->description . '</p>'; |
| 642 |
} |
| 643 |
if ($post_count == 1) { |
| 644 |
if ($term->count == 1) { |
| 645 |
echo wp_sprintf('<span class="docs-count">%s %s</span>', $term_count, ($count_text_singular) ? $count_text_singular : __('article', 'betterdocs')); |
| 646 |
} else { |
| 647 |
echo wp_sprintf('<span class="docs-count">%s %s</span>', $term_count, ($count_text) ? $count_text : __('articles', 'betterdocs')); |
| 648 |
} |
| 649 |
} |
| 650 |
echo '</a>'; |
| 651 |
} |
| 652 |
} |
| 653 |
echo '</div>'; |
| 654 |
endif; |
| 655 |
return ob_get_clean(); |
| 656 |
} |
| 657 |
|
| 658 |
/** |
| 659 |
* Advance search search form with live dropdown result |
| 660 |
* * |
| 661 |
* @since 1.0.0 |
| 662 |
* |
| 663 |
*/ |
| 664 |
add_shortcode('betterdocs_search_form', 'betterdocs_search_form'); |
| 665 |
function betterdocs_search_form($atts, $content = null) |
| 666 |
{ |
| 667 |
$get_args = shortcode_atts( |
| 668 |
apply_filters('betterdocs_search_form_atts', array( |
| 669 |
'placeholder' => false, |
| 670 |
'heading' => false, |
| 671 |
'subheading' => false, |
| 672 |
'heading_tag' => 'h2', |
| 673 |
'subheading_tag' => 'h3' |
| 674 |
)), |
| 675 |
$atts |
| 676 |
); |
| 677 |
|
| 678 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 679 |
|
| 680 |
ob_start(); |
| 681 |
echo '<div class="betterdocs-live-search">'; |
| 682 |
if ( $get_args['heading'] == true || $get_args['subheading'] == true ) { |
| 683 |
echo '<div class="betterdocs-search-heading">'; |
| 684 |
if ( $get_args['heading'] == true ) { |
| 685 |
echo '<'.$get_args['heading_tag'].' class="heading"> ' . esc_html($get_args['heading']) . ' </'.$get_args['heading_tag'].'>'; |
| 686 |
} |
| 687 |
|
| 688 |
if ( $get_args['subheading'] == true ) { |
| 689 |
echo '<'.$get_args['subheading_tag'].' class="subheading"> ' . esc_html($get_args['subheading']) . ' </'.$get_args['subheading_tag'].'>'; |
| 690 |
} |
| 691 |
echo '</div>'; |
| 692 |
} |
| 693 |
|
| 694 |
do_action('betterdocs_before_live_search_form', $get_args); |
| 695 |
|
| 696 |
echo '<form class="betterdocs-searchform betterdocs-advance-searchform"> |
| 697 |
<div class="betterdocs-searchform-input-wrap"> |
| 698 |
<svg class="docs-search-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="38px" viewBox="0 0 50 50" version="1.1"> |
| 699 |
<g id="surface1"> |
| 700 |
<path style=" " d="M 21 3 C 11.601563 3 4 10.601563 4 20 C 4 29.398438 11.601563 37 21 37 C 24.355469 37 27.460938 36.015625 30.09375 34.34375 L 42.375 46.625 L 46.625 42.375 L 34.5 30.28125 C 36.679688 27.421875 38 23.878906 38 20 C 38 10.601563 30.398438 3 21 3 Z M 21 7 C 28.199219 7 34 12.800781 34 20 C 34 27.199219 28.199219 33 21 33 C 13.800781 33 8 27.199219 8 20 C 8 12.800781 13.800781 7 21 7 Z "></path> |
| 701 |
</g> |
| 702 |
</svg> |
| 703 |
<input type="text" class="betterdocs-search-field" name="s" placeholder="'. $get_args['placeholder'] .'" autocomplete="off" value="'.get_search_query().'"> |
| 704 |
<svg class="docs-search-loader" width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#444b54"> |
| 705 |
<g fill="none" fill-rule="evenodd"> |
| 706 |
<g transform="translate(1 1)" stroke-width="2"> |
| 707 |
<circle stroke-opacity=".5" cx="18" cy="18" r="18" /> |
| 708 |
<path d="M36 18c0-9.94-8.06-18-18-18"> |
| 709 |
<animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="1s" repeatCount="indefinite" /> |
| 710 |
</path> |
| 711 |
</g> |
| 712 |
</g> |
| 713 |
</svg> |
| 714 |
<svg class="docs-search-close" xmlns="http://www.w3.org/2000/svg" width="38px" viewBox="0 0 128 128"> |
| 715 |
<path fill="#fff" d="M64 14A50 50 0 1 0 64 114A50 50 0 1 0 64 14Z" transform="rotate(-45.001 64 64.001)"></path> |
| 716 |
<path class="close-border" d="M64,117c-14.2,0-27.5-5.5-37.5-15.5c-20.7-20.7-20.7-54.3,0-75C36.5,16.5,49.8,11,64,11c14.2,0,27.5,5.5,37.5,15.5c10,10,15.5,23.3,15.5,37.5s-5.5,27.5-15.5,37.5C91.5,111.5,78.2,117,64,117z M64,17c-12.6,0-24.4,4.9-33.2,13.8c-18.3,18.3-18.3,48.1,0,66.5C39.6,106.1,51.4,111,64,111c12.6,0,24.4-4.9,33.2-13.8S111,76.6,111,64s-4.9-24.4-13.8-33.2S76.6,17,64,17z"></path> |
| 717 |
<path class="close-line" d="M53.4,77.6c-0.8,0-1.5-0.3-2.1-0.9c-1.2-1.2-1.2-3.1,0-4.2l21.2-21.2c1.2-1.2,3.1-1.2,4.2,0c1.2,1.2,1.2,3.1,0,4.2L55.5,76.7C54.9,77.3,54.2,77.6,53.4,77.6z"></path> |
| 718 |
<path class="close-line" d="M74.6,77.6c-0.8,0-1.5-0.3-2.1-0.9L51.3,55.5c-1.2-1.2-1.2-3.1,0-4.2c1.2-1.2,3.1-1.2,4.2,0l21.2,21.2c1.2,1.2,1.2,3.1,0,4.2C76.1,77.3,75.4,77.6,74.6,77.6z"></path> |
| 719 |
</svg> |
| 720 |
</div>'; |
| 721 |
|
| 722 |
do_action('betterdocs_live_search_form_footer', $get_args); |
| 723 |
|
| 724 |
echo '<input type="hidden" value="Search" class="betterdocs-search-submit">'; |
| 725 |
echo '</form>'; |
| 726 |
|
| 727 |
do_action('betterdocs_after_live_search_form', $get_args); |
| 728 |
|
| 729 |
echo '</div>'; |
| 730 |
return ob_get_clean(); |
| 731 |
} |
| 732 |
|
| 733 |
/** |
| 734 |
* Get the search result from ajax load. |
| 735 |
* * |
| 736 |
* @since 1.0.0 |
| 737 |
* |
| 738 |
*/ |
| 739 |
add_action('wp_ajax_nopriv_betterdocs_get_search_result', 'betterdocs_get_search_result'); |
| 740 |
add_action('wp_ajax_betterdocs_get_search_result', 'betterdocs_get_search_result'); |
| 741 |
function betterdocs_get_search_result() { |
| 742 |
global $wpdb; |
| 743 |
$search_input = isset($_POST['search_input']) ? sanitize_text_field($_POST['search_input']) : ''; |
| 744 |
$search_cat = isset($_POST['search_cat']) ? wp_strip_all_tags($_POST['search_cat']) : ''; |
| 745 |
$search_input = preg_replace('/[^A-Za-z0-9_\- ][]]/', '', strtolower($search_input)); |
| 746 |
$args = array( |
| 747 |
'post_type' => 'docs', |
| 748 |
'post_status' => 'publish', |
| 749 |
'posts_per_page' => -1, |
| 750 |
'suppress_filters' => true, |
| 751 |
's' => $search_input, |
| 752 |
); |
| 753 |
$tax_query = ''; |
| 754 |
if($search_cat) { |
| 755 |
$tax_query = array( |
| 756 |
array( |
| 757 |
'taxonomy' => 'doc_category', |
| 758 |
'field' => 'slug', |
| 759 |
'terms' => $search_cat, |
| 760 |
'operator' => 'AND', |
| 761 |
'include_children' => true |
| 762 |
) |
| 763 |
); |
| 764 |
} |
| 765 |
|
| 766 |
$args['tax_query'] = array( |
| 767 |
apply_filters('betterdocs_live_search_tax_query', $tax_query, $_POST) |
| 768 |
); |
| 769 |
|
| 770 |
$args = apply_filters('betterdocs_articles_args', $args); |
| 771 |
$loop = new WP_Query($args); |
| 772 |
$output = '<div class="betterdocs-search-result-wrap"><ul class="docs-search-result">'; |
| 773 |
if ($loop->have_posts()) : |
| 774 |
$input_not_found = ''; |
| 775 |
while ($loop->have_posts()) : $loop->the_post(); |
| 776 |
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches); |
| 777 |
|
| 778 |
if ($matches[1]) { |
| 779 |
$first_img = $matches[1][0]; |
| 780 |
} else { |
| 781 |
$first_img = ''; |
| 782 |
} |
| 783 |
|
| 784 |
$terms = get_the_terms(get_the_ID(), 'doc_category'); |
| 785 |
$terms_name = array(); |
| 786 |
|
| 787 |
if ($terms) { |
| 788 |
foreach ($terms as $term) { |
| 789 |
$terms_name[] = $term->name; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
$all_terms = join(", ", $terms_name); |
| 794 |
$icon = ''; |
| 795 |
$search_result_image = BetterDocs_DB::get_settings('search_result_image'); |
| 796 |
if ($search_result_image == 1 && has_post_thumbnail()) { |
| 797 |
$icon = get_the_post_thumbnail(); |
| 798 |
} elseif ($search_result_image == 1 && !empty($first_img)) { |
| 799 |
$icon = '<img src="' . $first_img . '" alt="">'; |
| 800 |
} |
| 801 |
$output .= '<li>' . $icon . '<a href="' . get_permalink() . '"><span class="betterdocs-search-title">' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</span><br><span class="betterdocs-search-category">' . $all_terms . '</span></a></li>'; |
| 802 |
endwhile; |
| 803 |
else : |
| 804 |
$input_not_found = $search_input; |
| 805 |
$output .= '<li>' . stripslashes(BetterDocs_DB::get_settings('search_not_found_text')) . '</li>'; |
| 806 |
endif; |
| 807 |
$output .= '</ul></div>'; |
| 808 |
$response[ 'post_lists' ] = $output; |
| 809 |
|
| 810 |
if ( $output && strlen( $search_input ) >= 3) { |
| 811 |
BetterDocs_Helper::search_insert($search_input, $input_not_found); |
| 812 |
} |
| 813 |
wp_send_json_success( $response ); |
| 814 |
wp_reset_postdata(); |
| 815 |
die(); |
| 816 |
} |
| 817 |
|
| 818 |
/** |
| 819 |
* feedback form shortcode |
| 820 |
* * |
| 821 |
* @since 1.0.0 |
| 822 |
* |
| 823 |
*/ |
| 824 |
add_shortcode('betterdocs_feedback_form', 'betterdocs_feedback_form'); |
| 825 |
function betterdocs_feedback_form($atts, $content = null) |
| 826 |
{ |
| 827 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 828 |
$get_args = shortcode_atts( |
| 829 |
array( |
| 830 |
'button_text' => esc_html__('Send', 'betterdocs') |
| 831 |
), |
| 832 |
$atts |
| 833 |
); |
| 834 |
ob_start(); |
| 835 |
if (is_user_logged_in()) { |
| 836 |
$userdata = get_userdata(get_current_user_id()); |
| 837 |
$name = $userdata->first_name . ' ' . $userdata->last_name; |
| 838 |
$email = $userdata->user_email; |
| 839 |
} else { |
| 840 |
$name = ''; |
| 841 |
$email = ''; |
| 842 |
} |
| 843 |
|
| 844 |
?> |
| 845 |
<div class="form-wrapper"> |
| 846 |
<div class="response"></div> |
| 847 |
<form id="betterdocs-feedback-form" class="betterdocs-feedback-form" action="" method="post"> |
| 848 |
<p><label for="message_name" class="form-name"> |
| 849 |
<?php esc_html_e('Name:', 'betterdocs') ?> <span>*</span> <br> |
| 850 |
<input type="text" id="message_name" name="message_name" value="<?php echo esc_html($name) ?>"> |
| 851 |
</label> |
| 852 |
</p> |
| 853 |
<p><label for="message_email" class="form-email"> |
| 854 |
<?php esc_html_e('Email:', 'betterdocs') ?> <span>*</span> <br> |
| 855 |
<input type="text" id="message_email" name="message_email" value="<?php echo esc_html($email) ?>"> |
| 856 |
</label> |
| 857 |
</p> |
| 858 |
<p><label for="message_text" class="form-message"> |
| 859 |
<?php esc_html_e('Message:', 'betterdocs') ?> <span>*</span> <br> |
| 860 |
<textarea type="text" id="message_text" name="message_text"></textarea> |
| 861 |
</label> |
| 862 |
</p> |
| 863 |
<div class="feedback-from-button"> |
| 864 |
<input type="hidden" name="submitted" value="1"> |
| 865 |
<input type="submit" name="submit" class="button" id="feedback_form_submit_btn" value="<?php echo esc_attr($get_args['button_text']) ?>" /> |
| 866 |
</div> |
| 867 |
</form> |
| 868 |
</div> |
| 869 |
<?php |
| 870 |
return ob_get_clean(); |
| 871 |
} |
| 872 |
|
| 873 |
/** |
| 874 |
* Submit form via ajax |
| 875 |
* * |
| 876 |
* @since 1.0.0 |
| 877 |
* |
| 878 |
*/ |
| 879 |
add_action('wp_ajax_nopriv_betterdocs_feedback_form_submit', 'betterdocs_feedback_form_submit'); |
| 880 |
add_action('wp_ajax_betterdocs_feedback_form_submit', 'betterdocs_feedback_form_submit'); |
| 881 |
|
| 882 |
function betterdocs_feedback_form_submit() |
| 883 |
{ |
| 884 |
check_ajax_referer( 'betterdocs_submit_data', 'security' ); |
| 885 |
$postID = isset($_POST['postID']) ? $_POST['postID'] : ''; |
| 886 |
$article = get_the_title($postID); |
| 887 |
$name = isset($_POST['message_name']) ? sanitize_text_field(stripslashes($_POST['message_name'])) : ''; |
| 888 |
$email = isset($_POST['message_email']) ? sanitize_email(stripslashes($_POST['message_email'])) : ''; |
| 889 |
$message_text = isset($_POST['message_text']) ? sanitize_textarea_field(stripslashes($_POST['message_text'])) : ''; |
| 890 |
$message = <<<EOD |
| 891 |
Name : {$name} <br> |
| 892 |
Docs : {$article} |
| 893 |
{$message_text} |
| 894 |
EOD; |
| 895 |
|
| 896 |
//response messages |
| 897 |
$missing_name = esc_html__('Please enter your name.', 'betterdocs'); |
| 898 |
$email_invalid = esc_html__('Enter a valid email address.', 'betterdocs'); |
| 899 |
$missing_message = esc_html__('Please write your message.', 'betterdocs'); |
| 900 |
$message_unsent = esc_html__('Message was not sent. Try Again.', 'betterdocs'); |
| 901 |
$message_sent = esc_html__('Thanks! Your message has been sent.', 'betterdocs'); |
| 902 |
|
| 903 |
//php mailer variables |
| 904 |
$to = BetterDocs_DB::get_settings('email_address'); |
| 905 |
if (empty($to)) { |
| 906 |
$to = get_option('admin_email'); |
| 907 |
} |
| 908 |
|
| 909 |
$subject = wp_sprintf(__('Feedback message from %s', 'betterdocs'), get_bloginfo('name')); |
| 910 |
$headers = 'From: ' . $email . "\r\n" . |
| 911 |
'Reply-To: ' . $email . "\r\n"; |
| 912 |
$response = array(); |
| 913 |
|
| 914 |
//validate presence of name |
| 915 |
if (empty($name)) { |
| 916 |
$response['nameStatus'] = 'error'; |
| 917 |
$response['nameMessage'] = $missing_name; |
| 918 |
} |
| 919 |
|
| 920 |
//validate email |
| 921 |
if (empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) { |
| 922 |
$response['emailStatus'] = 'error'; |
| 923 |
$response['emailMessage'] = $email_invalid; |
| 924 |
} |
| 925 |
|
| 926 |
//validate presence of message |
| 927 |
if (empty($message_text)) { |
| 928 |
$response['messageStatus'] = 'error'; |
| 929 |
$response['messageMessage'] = $missing_message; |
| 930 |
} |
| 931 |
|
| 932 |
if (!empty($name) && !empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($message_text)) { |
| 933 |
$sent = wp_mail($to, $subject, strip_tags($message), $headers); |
| 934 |
if ($sent) { |
| 935 |
$response['sentStatus'] = 'success'; |
| 936 |
$response['sentMessage'] = $message_sent; |
| 937 |
} else { |
| 938 |
$response['sentStatus'] = 'error'; |
| 939 |
$response['sentMessage'] = $message_unsent; |
| 940 |
} |
| 941 |
} |
| 942 |
echo json_encode($response); |
| 943 |
die(); |
| 944 |
} |
| 945 |
|
| 946 |
/** |
| 947 |
* Social Share Shortcode |
| 948 |
* * |
| 949 |
* @since 1.0.0 |
| 950 |
* |
| 951 |
*/ |
| 952 |
add_shortcode('betterdocs_social_share', 'betterdocs_social_share'); |
| 953 |
function betterdocs_social_share($atts, $content = null) |
| 954 |
{ |
| 955 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 956 |
$get_args = shortcode_atts( |
| 957 |
array( |
| 958 |
'title' => esc_html__('Share This Article :', 'betterdocs'), |
| 959 |
'facebook_sharing' => '1', |
| 960 |
'twitter_sharing' => '1', |
| 961 |
'linkedin_sharing' => '1', |
| 962 |
'pinterest_sharing' => '1' |
| 963 |
), |
| 964 |
$atts |
| 965 |
); |
| 966 |
$thumbnail = ''; |
| 967 |
if (function_exists('has_post_thumbnail')) { |
| 968 |
if (has_post_thumbnail()) { |
| 969 |
$thumbnail = wp_get_attachment_url(get_post_thumbnail_id()); |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
?> |
| 974 |
<div class="betterdocs-social-share"> |
| 975 |
<div class="betterdocs-social-share-heading"> |
| 976 |
<?php |
| 977 |
if ($get_args['title']) : |
| 978 |
echo '<h5>' . esc_html($get_args['title']) . '</h5>'; |
| 979 |
endif; |
| 980 |
?> |
| 981 |
</div> |
| 982 |
<ul class="betterdocs-social-share-links"> |
| 983 |
<?php if ($get_args['facebook_sharing'] == true) : ?> |
| 984 |
<li><a href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/facebook.svg" alt="Facebook"></a></li> |
| 985 |
<?php endif; ?> |
| 986 |
|
| 987 |
<?php if ($get_args['twitter_sharing'] == true) : ?> |
| 988 |
<li><a href="https://twitter.com/intent/tweet?url=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/twitter.svg" alt="Twitter"></a></li> |
| 989 |
<?php endif; ?> |
| 990 |
|
| 991 |
<?php if ($get_args['linkedin_sharing'] == true) : ?> |
| 992 |
<li><a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=&summary=&source=" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/linkedin.svg" alt="LinkedIn"></a></li> |
| 993 |
<?php endif; ?> |
| 994 |
|
| 995 |
<?php if ($get_args['pinterest_sharing'] == true) : ?> |
| 996 |
<li><a href="https://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $thumbnail; ?>&description=" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/pinterest.svg" alt="Pinterest"></a></li> |
| 997 |
<?php endif; ?> |
| 998 |
</ul> |
| 999 |
</div> <!-- Social Share end--> |
| 1000 |
<?php } |
| 1001 |
|
| 1002 |
add_shortcode('betterdocs_toc', 'betterdocs_toc'); |
| 1003 |
function betterdocs_toc($atts, $content = null) |
| 1004 |
{ |
| 1005 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 1006 |
$get_args = shortcode_atts( |
| 1007 |
array( |
| 1008 |
'post_type' => 'docs', |
| 1009 |
'post_id' => get_the_ID(), |
| 1010 |
'htags' => '1,2,3,4,5,6', |
| 1011 |
'hierarchy' => '', |
| 1012 |
'list_number' => '', |
| 1013 |
'collapsible_on_mobile' => '', |
| 1014 |
'toc_title' => '', |
| 1015 |
), |
| 1016 |
$atts |
| 1017 |
); |
| 1018 |
|
| 1019 |
$get_post = get_post($get_args['post_id']); |
| 1020 |
$post_content = $get_post->post_content; |
| 1021 |
|
| 1022 |
return BetterDocs_Public::betterdocs_toc( |
| 1023 |
$post_content, |
| 1024 |
$get_args['htags'], |
| 1025 |
$get_args['hierarchy'], |
| 1026 |
$get_args['list_number'], |
| 1027 |
$get_args['collapsible_on_mobile'], |
| 1028 |
$get_args['toc_title'] |
| 1029 |
); |
| 1030 |
} |
| 1031 |
|
| 1032 |
add_shortcode('betterdocs_post_content', 'betterdocs_post_content'); |
| 1033 |
function betterdocs_post_content($atts, $content = null) |
| 1034 |
{ |
| 1035 |
do_action( 'betterdocs_before_shortcode_load' ); |
| 1036 |
$get_args = shortcode_atts( |
| 1037 |
array( |
| 1038 |
'post_id' => get_the_ID(), |
| 1039 |
'htags' => 'h1,h2,h3,h4,h5,h6', |
| 1040 |
'enable_toc' => '', |
| 1041 |
'toc_hierarchy' => '', |
| 1042 |
'list_number' => '', |
| 1043 |
'display_toc_on_top' => '', |
| 1044 |
'collapsible_toc_mobile' => '' |
| 1045 |
), |
| 1046 |
$atts |
| 1047 |
); |
| 1048 |
|
| 1049 |
$get_post = get_post($get_args['post_id']); |
| 1050 |
$post_content = $get_post->post_content; |
| 1051 |
$the_content = BetterDocs_Public::betterdocs_the_content( |
| 1052 |
$post_content, |
| 1053 |
$get_args['htags'], |
| 1054 |
$get_args['enable_toc'] |
| 1055 |
); |
| 1056 |
|
| 1057 |
return $the_content; |
| 1058 |
} |