PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services / 6.8.3
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services v6.8.3
8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 8.5.0 8.4.9 All 531 releases
chatbot / includes / class-common-function.php

class-common-function.php in WPBot – AI ChatBot for Live Support, Lead Generation, AI Services 6.8.3, at includes/class-common-function.php

60 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common functions class
4 */
5 class Qcld_WPBot_Common_Functions {
6
7 /**
8 * Remove stopwords from search query
9 *
10 * @param string $query The search query
11 * @param array $stopwords Array of stopwords to remove
12 * @return string Query with stopwords removed
13 */
14 public static function qcpd_remove_wa_stopwords($query, $stopwords) {
15 return preg_replace('/\b('.implode('|',$stopwords).')\b/','',$query);
16 }
17
18 /**
19 * Get relevant page links based on search query
20 *
21 * @param string $search_query The search query
22 * @return array Array of relevant page links
23 */
24 public static function qcpd_relevant_pagelink($search_query) {
25 $stopwords = explode(',', get_option('qlcd_wp_chatbot_stop_words'));
26
27 $finalQueryWordsWithoutStopWords = self::qcpd_remove_wa_stopwords(strtolower($search_query), $stopwords);
28
29 $cleanWordsWithoutPunctuationMarks = preg_replace('/[\p{P}]/u', '', $finalQueryWordsWithoutStopWords);
30
31 $q = trim($cleanWordsWithoutPunctuationMarks);
32
33 $links = [];
34
35 $post_type_array = get_option('qcld_openai_relevant_post');
36
37 $the_query = new WP_Query(array(
38 'post_status' => 'publish',
39 'posts_per_page' => 5,
40 's' => esc_attr($q),
41 'post_type' => $post_type_array
42 ));
43
44 if($the_query->have_posts()) {
45 while($the_query->have_posts()) {
46 $the_query->the_post();
47
48 $url = esc_url(get_permalink());
49 $link = '<a href=' . $url . ' target="_blank">' . get_the_title() . '</a>';
50 array_push($links, $link);
51 }
52 wp_reset_postdata();
53 }
54
55 $links = array_unique($links);
56 return $links;
57 }
58
59 }
60