function bluet_keywords_related_render() { //exclude checkbox to exclode the current post from being matched global $post; $current_post_id = $post->ID; $exclude_me = get_post_meta($current_post_id, 'bluet_exclude_post_from_matching', true); ?> <div> <h3><?php _e('Exclude this post from being matched', 'bluet-kw'); ?> </h3> <input type="checkbox" id="bluet_kw_admin_exclude_post_from_matching_id" onClick="hideIfChecked('bluet_kw_admin_exclude_post_from_matching_id','bluet_kw_admin_div_terms')" name="bluet_exclude_post_from_matching_name" <?php if ($exclude_me) { echo "checked"; } ?> /> <span style="color:red;"><?php _e('Exclude this post', 'bluet-kw'); ?> </span> <?php //show keywords list related $my_kws = array(); $my_kws = kttg_get_related_keywords($current_post_id); //echo('<pre>');print_r($my_kws);echo('</pre>'); $bluet_matching_keywords_field = get_post_meta($current_post_id, 'bluet_matching_keywords_field', true); ?> <div id="bluet_kw_admin_div_terms"> <?php if (!empty($my_kws)) { ?> <h3><?php _e('Keywords related', 'bluet-kw'); ?> </h3> <?php echo '<ul style="list-style: initial; padding-left: 20px;">'; foreach ($my_kws as $kw_id) { echo '<li style="color:green;"><i>' . get_the_title($kw_id) . '</i></li>'; } echo '</ul>'; } else { echo '<p>' . __('No KeyWords found for this post', 'bluet-kw') . '</p>'; } echo '<a href="' . get_admin_url() . 'edit.php?post_type=my_keywords">'; echo __('Manage KeyWords', 'bluet-kw') . ' >>'; echo '</a>'; echo '</div>'; echo "</div>"; }
public function widget($args, $instance) { global $is_kttg_glossary_page; if (!(is_single() or is_page())) { return; } $exclude_me = get_post_meta(get_the_id(), 'bluet_exclude_post_from_matching', true); //verifying custom postes to filter if (function_exists('bluet_filter_this_custom_post_type')) { $filter_this_custom_post_type = bluet_filter_this_custom_post_type(get_the_id()); } else { $filter_this_custom_post_type = false; } $settings = get_option('bluet_kw_settings'); if ($exclude_me or is_single() and (get_post_type(get_the_id()) == 'post' and !$settings['bt_kw_for_posts'] or get_post_type(get_the_id()) != 'post' and !$filter_this_custom_post_type) or is_page() and !$settings['bt_kw_for_pages'] or $is_kttg_glossary_page) { return false; } // outputs the content of the widget extract($args); echo $before_widget; echo $before_title; echo $instance['title']; echo $after_title; echo '<ul>'; //widget content process here $my_keywords_ids = kttg_get_related_keywords(get_the_id()); //if user specifies keywords to match $bluet_matching_keywords_field = get_post_meta(get_the_id(), 'bluet_matching_keywords_field', true); if (!empty($bluet_matching_keywords_field)) { $my_keywords_ids = $bluet_matching_keywords_field; } if (!empty($my_keywords_ids)) { //if have terms in concern foreach ($my_keywords_ids as $term_id) { // The Query $wk_args = array('p' => $term_id, 'post_type' => 'my_keywords'); $the_wk_query = new WP_Query($wk_args); // The Loop if ($the_wk_query->have_posts()) { while ($the_wk_query->have_posts()) { $the_wk_query->the_post(); $trm = get_the_title(); $kw_id = get_the_id(); // adding ‌ (invisible character) to avoid tooltips overlapping $dfn = preg_replace('#(' . $trm . ')#i', $trm . '‌', get_the_content()); $img = get_the_post_thumbnail($term_id, 'medium'); $trm = $trm . '‌'; } } /* Restore original Post Data */ wp_reset_postdata(); $string_to_show = '<li> <span class="bluet_tooltip" data-tooltip="' . $kw_id . '"> ' . $trm . ' </span> </li>'; echo $string_to_show; } } else { _e('no terms found for this post', 'bluet-kw'); } // echo '</ul>'; echo $after_widget; }
function kttg_filter_posttype($cont) { /*28-05-2015*/ //specific modification so it can work for "WooCommerce Product Addons" and other addons if (is_array($cont)) { $cont = kttg_specific_plugins($cont); return $cont; } /*28-05-2015 end*/ $my_post_id = get_the_id(); $exclude_me = get_post_meta($my_post_id, 'bluet_exclude_post_from_matching', true); if ($exclude_me) { return $cont; } //glossary settings $bluet_kttg_show_glossary_link = get_option('bluet_kw_settings'); if (!empty($bluet_kttg_show_glossary_link['bluet_kttg_show_glossary_link'])) { $bluet_kttg_show_glossary_link = $bluet_kttg_show_glossary_link['bluet_kttg_show_glossary_link']; } else { $bluet_kttg_show_glossary_link = false; } $bluet_kttg_glossary_page = get_option('bluet_kttg_glossary_page'); $option_settings = get_option('bluet_kw_settings'); //var dans la quelle on cache les tooltips a afficher $html_tooltips_to_add = '<div class="my_tooltips_in_block">'; $my_keywords_ids = kttg_get_related_keywords($my_post_id); //if user specifies keywords to match $bluet_matching_keywords_field = get_post_meta($my_post_id, 'bluet_matching_keywords_field', true); if (!empty($bluet_matching_keywords_field)) { $my_keywords_ids = $bluet_matching_keywords_field; } global $is_kttg_glossary_page; $kttg_fetch_all_keywords = get_option('kttg_fetch_all_keywords'); if (empty($kttg_fetch_all_keywords)) { $kttg_fetch_all_keywords = false; } else { if ($kttg_fetch_all_keywords == "false") { $kttg_fetch_all_keywords = false; } else { if ($kttg_fetch_all_keywords == "true") { $kttg_fetch_all_keywords = true; } } } if (!empty($my_keywords_ids) or $is_kttg_glossary_page or $kttg_fetch_all_keywords) { $my_keywords_terms = array(); //looking in all occurences if glossary page if ($is_kttg_glossary_page) { $post_in = array(); } else { $post_in = $my_keywords_ids; } if ($kttg_fetch_all_keywords) { $post_in = null; } // The Query $wk_args = array('post__in' => $post_in, 'post_type' => 'my_keywords', 'posts_per_page' => -1); $the_wk_query = new WP_Query($wk_args); // The Loop if ($the_wk_query->have_posts()) { while ($the_wk_query->have_posts()) { $the_wk_query->the_post(); if (get_the_title() != "") { //to prevent untitled keywords $tmp_array_kw = array('kw_id' => get_the_id(), 'term' => get_the_title(), 'case' => false, 'pref' => false, 'syns' => get_post_meta(get_the_id(), 'bluet_synonyms_keywords', true), 'youtube' => get_post_meta(get_the_id(), 'bluet_youtube_video_id', true), 'dfn' => get_the_content(), 'img' => get_the_post_thumbnail(get_the_id(), 'medium')); if (get_post_meta(get_the_id(), 'bluet_case_sensitive_word', true) == "on") { $tmp_array_kw['case'] = true; } //if prefix addon activated if (function_exists('bluet_prefix_metabox')) { if (get_post_meta(get_the_id(), 'bluet_prefix_keywords', true) == "on") { $tmp_array_kw['pref'] = true; } } $my_keywords_terms[] = $tmp_array_kw; } } } /* Restore original Post Data */ wp_reset_postdata(); // first preg replace to eliminate html tags $regex = '<\\/?\\w+((\\s+\\w+(\\s*=\\s*(?:".*?"|\'.*?\'|[^\'">\\s]+))?)+\\s*|\\s*)\\/?>'; $out = array(); preg_match_all('#(' . $regex . ')#iu', $cont, $out); $cont = preg_replace('#(' . $regex . ')#i', '**T_A_G**', $cont); //replace tags by **T_A_G** //end $limit_match = $option_settings['bt_kw_match_all'] == 'on' ? -1 : 1; /*tow loops montioned here to avoid overlapping (chevauchement) */ foreach ($my_keywords_terms as $id => $arr) { $term = $arr['term']; //concat synonyms if they are not empty if ($arr['syns'] != "") { $term .= '|' . $arr['syns']; } $is_prefix = $arr['pref']; if (function_exists('bluet_prefix_metabox') and $is_prefix) { $kw_after = '\\w*'; } else { $kw_after = ''; } $term_and_syns_array = explode('|', $term); //sort keywords by string length in the array (to match them properly) usort($term_and_syns_array, 'kttg_length_compare'); //verify if case sensitive if ($arr['case']) { $kttg_case_sensitive = ''; } else { $kttg_case_sensitive = 'i'; } foreach ($term_and_syns_array as $temr_occ) { $temr_occ = elim_apostrophes($temr_occ); $cont = elim_apostrophes($cont); $cont = preg_replace('#((\\W)(' . $temr_occ . '' . $kw_after . ')(\\W))#u' . $kttg_case_sensitive, '$2__$3__$4', $cont, $limit_match); } } foreach ($my_keywords_terms as $id => $arr) { $term = $arr['term']; //concat synonyms if they are not empty if ($arr['syns'] != "") { $term .= '|' . $arr['syns']; } $img = $arr['img']; $dfn = $arr['dfn']; $is_prefix = $arr['pref']; $video = $arr['youtube']; if (function_exists('bluet_prefix_metabox') and $is_prefix) { $kw_after = '\\w*'; } else { $kw_after = ''; } if ($dfn != "") { $dfn = $arr['dfn']; } $html_to_replace = '<span class="bluet_tooltip" data-tooltip="' . $arr["kw_id"] . '">$2</span>'; $term_and_syns_array = explode('|', $term); $kttg_term_title = $term_and_syns_array[0]; if ($video != "" and function_exists('bluet_kttg_all_tooltips_layout')) { $html_tooltips_to_add .= bluet_kttg_all_tooltips_layout($dfn, '', $video, $arr["kw_id"]); } else { $html_tooltips_to_add .= bluet_kttg_tooltip_layout($kttg_term_title, $dfn, $img, $arr["kw_id"], $bluet_kttg_show_glossary_link, $bluet_kttg_glossary_page); } //verify if case sensitive if ($arr['case']) { $kttg_case_sensitive = ''; } else { $kttg_case_sensitive = 'i'; } foreach ($term_and_syns_array as $temr_occ) { $temr_occ = elim_apostrophes($temr_occ); $cont = elim_apostrophes($cont); $cont = preg_replace('#(__(' . $temr_occ . '' . $kw_after . ')__)#u' . $kttg_case_sensitive, $html_to_replace, $cont, -1); } } //Reinsert tag HTML elements foreach ($out[0] as $id => $tag) { $cont = preg_replace('#(\\*\\*T_A_G\\*\\*)#', $tag, $cont, 1); } //prevent HTML Headings (h1 h2 h3) to be matched $regH = '(<h[1-3]+>.*)(class="bluet_tooltip")(.*<\\/h[1-3]+>)'; $cont = preg_replace('#(' . $regH . ')#iu', '$2$4', $cont); } $html_tooltips_to_add = apply_filters('kttg_another_tooltip_in_block', $html_tooltips_to_add); $html_tooltips_to_add .= "</div>"; $cont = $html_tooltips_to_add . $cont; return do_shortcode($cont); //do_shortcode to return content after executing shortcodes }