PATH:
home
/
letacommog
/
rdvenunclick.fr1
/
wp-content
/
plugins
/
ultimate-faqs
/
Functions
<?php /* Processes the ajax requests being put out in the admin area and the front-end * of the UPCP plugin */ // Returns the FAQs that are found for a specific search function UFAQ_Search() { $response = do_shortcode("[ultimate-faqs search_string='" . strtolower(sanitize_text_field($_POST['Q'])) . "' include_category='" . sanitize_text_field($_POST['include_category']) . "' exclude_category='" . sanitize_text_field($_POST['exclude_category']) . "' orderby='" . sanitize_text_field($_POST['orderby']) . "' order='" . sanitize_text_field($_POST['order']) . "' post_count='" . sanitize_text_field($_POST['post_count']) . "' current_url='" . sanitize_text_field($_POST['current_url']) . "' faqs_only='" . sanitize_text_field($_POST['faqs_only']) . "' faq_page='" . sanitize_text_field($_POST['faq_page']) . "' ajax='Yes']"); $ReturnArray['request_count'] = sanitize_text_field($_POST['request_count']); $ReturnArray['message'] = $response; echo json_encode($ReturnArray); die(); } add_action('wp_ajax_ufaq_search', 'UFAQ_Search'); add_action( 'wp_ajax_nopriv_ufaq_search', 'UFAQ_Search'); // Change the up and down votes for a particular FAQ function EWD_UFAQ_Update_Rating() { $FAQ_ID = is_numeric($_POST['FAQ_ID']) ? intval($_POST['FAQ_ID']) : 0; $Vote_Type = sanitize_text_field( $_POST['Vote_Type'] ); if ($Vote_Type == "Up") { $Up_Votes = get_post_meta($FAQ_ID, "FAQ_Up_Votes", true); update_post_meta($FAQ_ID, "FAQ_Up_Votes", $Up_Votes + 1); $Total_Score = get_post_meta($FAQ_ID, "FAQ_Total_Score", true); update_post_meta($FAQ_ID, "FAQ_Total_Score", $Total_Score + 1); } if ($Vote_Type == "Down") { $Down_Votes = get_post_meta($FAQ_ID, "FAQ_Down_Votes", true); update_post_meta($FAQ_ID, "FAQ_Down_Votes", $Down_Votes + 1); $Total_Score = get_post_meta($FAQ_ID, "FAQ_Total_Score", true); update_post_meta($FAQ_ID, "FAQ_Total_Score", $Total_Score - 1); } die(); } add_action('wp_ajax_ufaq_update_rating', 'EWD_UFAQ_Update_Rating'); add_action( 'wp_ajax_nopriv_ufaq_update_rating', 'EWD_UFAQ_Update_Rating'); // Records the number of time an FAQ post is opened function UFAQ_Record_View() { global $wpdb; $wpdb->show_errors(); $post_id = intval( substr($_POST['post_id'], 4, strrpos(sanitize_text_field($_POST['post_id']), "-") - 4) ); if (!is_numeric($post_id)) {return;} $Meta_ID = $wpdb->get_var($wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key='ufaq_view_count'", $post_id)); if ($Meta_ID != "" and $Meta_ID != 0) {$wpdb->query($wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value=meta_value+1 WHERE post_id=%d AND meta_key='ufaq_view_count'", $post_id));} else {$wpdb->query($wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES (%d,'ufaq_view_count','1')", $post_id));} die(); } add_action('wp_ajax_ufaq_record_view', 'UFAQ_Record_View'); add_action( 'wp_ajax_nopriv_ufaq_record_view', 'UFAQ_Record_View'); function EWD_UFAQ_Save_Order(){ global $UFAQ_Full_Version; if (!is_array($_POST['ewd-ufaq-item']) or $UFAQ_Full_Version != "Yes") {return;} foreach ($_POST['ewd-ufaq-item'] as $Key=>$ID) { update_post_meta( intval( $ID ), 'ufaq_order', intval( $Key ) ); } die(); } add_action('wp_ajax_UFAQ_update_order','EWD_UFAQ_Save_Order'); function EWD_UFAQ_Add_WC_FAQs(){ $Post_ID = intval( $_POST['Post_ID'] ); if (!is_numeric($Post_ID)) {return;} $Current_FAQs = get_post_meta($Post_ID, 'EWD_UFAQ_WC_Selected_FAQs', true ); if (!is_array($Current_FAQs)) {$Current_FAQs = array();} $FAQs = json_decode(stripslashes_deep($_POST['FAQs'])); if (!is_array($FAQs)) {$FAQs = array();} $Added_FAQs = array(); foreach ($FAQs as $FAQ) { if (!in_array($FAQ, $Current_FAQs)) { $Current_FAQs[] = $FAQ; $FAQ_Post = get_post($FAQ); $Added_FAQs[] = array("ID" => $FAQ, "Name" => $FAQ_Post->post_title); } } update_post_meta($Post_ID, 'EWD_UFAQ_WC_Selected_FAQs', $Current_FAQs); echo json_encode($Added_FAQs); die(); } add_action('wp_ajax_ewd_ufaq_add_wc_faqs','EWD_UFAQ_Add_WC_FAQs'); function EWD_UFAQ_Delete_WC_FAQs(){ $Post_ID = intval( $_POST['Post_ID'] ); $Current_FAQs = get_post_meta($Post_ID, 'EWD_UFAQ_WC_Selected_FAQs', true ); if (!is_array($Current_FAQs)) {$Current_FAQs = array();} $FAQs = json_decode(stripslashes_deep($_POST['FAQs'])); if (!is_array($FAQs)) {$FAQs = array();} $Remaining_FAQs = array_diff($Current_FAQs, $FAQs); update_post_meta($Post_ID, 'EWD_UFAQ_WC_Selected_FAQs', $Remaining_FAQs); die(); } add_action('wp_ajax_ewd_ufaq_delete_wc_faqs','EWD_UFAQ_Delete_WC_FAQs'); function EWD_UFAQ_WC_FAQ_Category() { $Cat_ID = sanitize_text_field($_POST['Cat_ID']); $args = array("numberposts" => -1, "post_type" => 'ufaq'); if ($Cat_ID != "") { $args['tax_query'] = array(array( 'taxonomy' => 'ufaq-category', 'terms' => $Cat_ID )); } $All_FAQs = get_posts($args); $ReturnString .= "<table class='form-table ewd-ufaq-faq-add-table'>"; $ReturnString .= "<tr>"; $ReturnString .= "<th>" . __("Add?", 'ultimate-faqs') . "</th>"; $ReturnString .= "<th>" . __("FAQ", 'ultimate-faqs') . "</th>"; $ReturnString .= "</tr>"; foreach ($All_FAQs as $FAQ) { $ReturnString .= "<tr class='ewd-ufaq-faq-row' data-faqid='" . $FAQ->ID . "'>"; $ReturnString .= "<td><input type='checkbox' class='ewd-ufaq-add-faq' name='Add_FAQs[]' value='" . $FAQ->ID . "'/></td>"; $ReturnString .= "<td>" . $FAQ->post_title . "</td>"; $ReturnString .= "</tr>"; } $ReturnString .= "</table>"; echo $ReturnString; die(); } add_action('wp_ajax_ewd_ufaq_wc_faq_category','EWD_UFAQ_WC_FAQ_Category'); function EWD_UFAQ_Hide_Review_Ask() { $Ask_Review_Date = sanitize_text_field($_POST['Ask_Review_Date']); if (get_option('EWD_UFAQ_Ask_Review_Date') < time()+3600*24*$Ask_Review_Date) { update_option('EWD_UFAQ_Ask_Review_Date', time()+3600*24*$Ask_Review_Date); } die(); } add_action('wp_ajax_ewd_ufaq_hide_review_ask','EWD_UFAQ_Hide_Review_Ask'); function EWD_UFAQ_Send_Feedback() { $headers = 'Content-type: text/html;charset=utf-8' . "\r\n"; $Feedback = sanitize_text_field($_POST['Feedback']); $Feedback .= '<br /><br />Email Address: '; $Feedback .= sanitize_text_field($_POST['EmailAddress']); wp_mail('contact@etoilewebdesign.com', 'UFAQ Feedback - Dashboard Form', $Feedback, $headers); die(); } add_action('wp_ajax_ewd_ufaq_send_feedback','EWD_UFAQ_Send_Feedback'); function EWD_UFAQ_Dismiss_Pointers() { $uid = get_current_user_id(); $pointers = explode( ',', (string) get_user_meta( $uid, 'dismissed_wp_pointers', TRUE ) ); $pointers[] = 'ufaq_admin_pointers_tutorial-one'; $pointers[] = 'ufaq_admin_pointers_tutorial-two'; $pointers[] = 'ufaq_admin_pointers_tutorial-three'; $pointers[] = 'ufaq_admin_pointers_tutorial-four'; $pointers[] = 'ufaq_admin_pointers_tutorial-five'; $pointers[] = 'ufaq_admin_pointers_tutorial-six'; $unique_pointers = array_unique($pointers); update_usermeta($uid, 'dismissed_wp_pointers', implode(",", $unique_pointers)); die(); } add_action('wp_ajax_ufaq-dismiss-wp-pointers','EWD_UFAQ_Dismiss_Pointers'); /* WPForms Search Suggestions */ function EWD_UFAQ_WPForms_Results() { global $wpdb; $post_count = get_option( 'EWD_UFAQ_WPForms_Post_Count' ); $search_string = sanitize_text_field( $_POST['search_string'] ); $words = explode( ' ', $search_string ); foreach ( $words as &$word ) { $word = trim( $word, '.,!?:;()$# '); } $unique_words = array_unique( $words ); usort( $unique_words, 'EWD_UFAQ_Sort_By_String_Length' ); $str_length = strlen( reset( $unique_words) ); $search_string = ''; $search_values = array(); $matching_posts = array(); // Go through the words in the message, starting with the longest, and search for FAQs that contain the same word // Continue by descending word length, until enough posts are found foreach ( $unique_words as $unique_word ) { if ( $str_length != strlen( $unique_word ) ) { $search_string_ready = substr( $search_string, 0, strlen($search_string) - 4 ); $results = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='ufaq' AND post_status='publish' AND ( $search_string_ready ) ", $search_values ) ); foreach ( $results as $result ) { $matching_posts[] = $result->ID; } $unique_posts = array_unique( $matching_posts ); $matching_posts = $unique_posts; if ( sizeof( $matching_posts ) >= $post_count or strlen( $unique_word ) <= 3 ) { break; } $search_string = ''; $search_values = array(); $str_length = strlen( $unique_word ); } $search_string .= "post_content LIKE '%%%s%%' OR post_title LIKE '%%%s%%' OR "; $search_values[] = $unique_word; $search_values[] = $unique_word; } $final_posts = array_slice( $matching_posts, 0, $post_count ); $final_posts_string = implode( ',', $final_posts ); $ReturnArray['request_count'] = intval( $_POST['request_count'] ); if ( sizeof( $final_posts ) > 0 ) { $response = do_shortcode("[ultimate-faqs current_url='" . sanitize_text_field($_POST['current_url']) . "' post__in_string='" . $final_posts_string . "' ajax='Yes']"); $ReturnArray['message'] = $response; } else { $ReturnArray['message'] = false; } echo json_encode($ReturnArray); die(); } add_action( 'wp_ajax_ufaq_wpforms_search', 'EWD_UFAQ_WPForms_Results' ); add_action( 'wp_ajax_nopriv_ufaq_wpforms_search', 'EWD_UFAQ_WPForms_Results' ); function EWD_UFAQ_Sort_By_String_Length( $a, $b ) { if ( function_exists( 'mb_strlen' ) ) { return mb_strlen( $b ) - mb_strlen( $a ); } return strlen( $b ) - strlen( $a ); } /* WELCOME SCREEN AJAX INSTALL FUNCTIONS */ function EWD_UFAQ_AJAX_Add_Category() { $Category_Name = isset($_POST['category_name']) ? sanitize_text_field( $_POST['category_name'] ) : ''; $Category_Description = isset($_POST['category_description']) ? sanitize_text_field($_POST['category_description']) : ''; $Category_Term_IDs = wp_insert_term( $Category_Name, 'ufaq-category', array('description' => $Category_Description) ); echo json_encode( array( 'category_name' => $Category_Name, 'category_id' => $Category_Term_IDs['term_id'] ) ); exit(); } add_action('wp_ajax_ewd_ufaq_welcome_add_category', 'EWD_UFAQ_AJAX_Add_Category'); function EWD_UFAQ_AJAX_Add_FAQ_Page() { wp_insert_post(array( 'post_title' => (isset($_POST['faq_page_title']) ? sanitize_text_field($_POST['faq_page_title']) : ''), 'post_content' => '<!-- wp:paragraph --><p> [ultimate-faqs] </p><!-- /wp:paragraph -->', 'post_status' => 'publish', 'post_type' => 'page' )); exit(); } add_action('wp_ajax_ewd_ufaq_welcome_add_faq_page', 'EWD_UFAQ_AJAX_Add_FAQ_Page'); function EWD_UFAQ_AJAX_Set_Options() { update_option("EWD_UFAQ_FAQ_Accordion", sanitize_text_field( $_POST['faq_accordion'] ) ); update_option("EWD_UFAQ_Toggle", sanitize_text_field( $_POST['faq_toggle'] ) ); update_option("EWD_UFAQ_Group_By_Category", sanitize_text_field( $_POST['group_by_category'] ) ); update_option("EWD_UFAQ_Order_By", sanitize_text_field( $_POST['order_by_setting'] ) ); exit(); } add_action('wp_ajax_ewd_ufaq_welcome_set_options', 'EWD_UFAQ_AJAX_Set_Options'); function EWD_UFAQ_AJAX_Add_FAQ() { $FAQ_Post_ID = wp_insert_post(array( 'post_title' => (isset($_POST['faq_question']) ? sanitize_text_field($_POST['faq_question']) : ''), 'post_content' => (isset($_POST['faq_answer']) ? sanitize_text_field($_POST['faq_answer']) : ''), 'post_status' => 'publish', 'post_type' => 'ufaq' )); if (isset($_POST['faq_category']) and $_POST['faq_category']) { wp_set_post_terms($FAQ_Post_ID, sanitize_text_field( $_POST['faq_category'] ), 'ufaq-category'); } exit(); } add_action('wp_ajax_ewd_ufaq_welcome_add_faq', 'EWD_UFAQ_AJAX_Add_FAQ');
[+]
..
[-] EWD_UFAQ_Upgrade_Box.php
[edit]
[-] EWD_UFAQ_Output_Options_Page.php
[edit]
[-] EWD_UFAQ_Add_Views_Column.php
[edit]
[-] EWD_UFAQ_WooCommerce_Tab.php
[edit]
[-] EWD_UFAQ_Pointers_Manager_Interface.php
[edit]
[-] EWD_UFAQ_Output_Statistics_Page.php
[edit]
[-] EWD_UFAQ_WPForms_Integration.php
[edit]
[-] Update_EWD_UFAQ_Content.php
[edit]
[-] EWD_UFAQ_Pointers_Manager_Class.php
[edit]
[-] EWD_UFAQ_Import.php
[edit]
[-] EWD_UFAQ_Create_Captcha_Image.php
[edit]
[-] EWD_UFAQ_Submit_Question.php
[edit]
[-] EWD_UFAQ_Rewrite_Rules.php
[edit]
[-] EWD_UFAQ_Initial_Data.php
[edit]
[-] EWD_UFAQ_Widgets.php
[edit]
[-] Process_Ajax.php
[edit]
[-] EWD_UFAQ_Export_To_PDF.php
[edit]
[-] Error_Notices.php
[edit]
[-] EWD_UFAQ_Output_Pages.php
[edit]
[-] EWD_UFAQ_Styling.php
[edit]
[-] Update_Admin_Databases.php
[edit]
[-] EWD_UFAQ_Deactivation_Survey.php
[edit]
[-] EWD_UFAQ_Admin_Image_Upload.php
[edit]
[-] EWD_UFAQ_Add_Social_Media_Buttons.php
[edit]
[-] EWD_UFAQ_Output_Import_Page.php
[edit]
[-] EWD_UFAQ_Export.php
[edit]
[-] FrontEndAjaxUrl.php
[edit]
[-] EWD_UFAQ_Help_Pointers.php
[edit]
[-] Register_EWD_UFAQ_Posts_Taxonomies.php
[edit]
[-] EWD_UFAQ_Meta_Boxes.php
[edit]
[-] EWD_UFAQ_Output_Export_Page.php
[edit]
[-] EWD_UFAQ_Version_Update.php
[edit]
[-] EWD_UFAQ_Captcha.php
[edit]