Made With 💜 by Icegram'; /** * Primary class constructor. * * @param string $name Plugin name. * @param string $plugin Plugin slug. * * @since 1.0.0 */ public function __construct( $name = '', $plugin = '', $plugin_abbr = 'ig_fb', $event_prefix = 'igfb.', $is_dev_mode = false ) { $this->name = $name; $this->plugin = $plugin; $this->plugin_abbr = $plugin_abbr; $this->event_prefix = $event_prefix; $this->ajax_action = $this->plugin_abbr . '_submit-feedback'; $this->is_dev_mode = $is_dev_mode; // Don't run deactivation survey on dev sites. if ( ! $this->can_show_feedback_widget() ) { return; } add_action( 'wp_ajax_' . $this->ajax_action, array( $this, 'submit_feedback' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); /** * Show 5 star review notice to user * * @since 1.0.12 */ add_action( 'admin_notices', array( &$this, 'show_review_notice' ) ); } /** * Ask for user review * * @since 1.0.12 */ public function show_review_notice() { if ( ! defined( 'DOING_AJAX' ) && is_admin() ) { $enable_review_notice = apply_filters( $this->plugin_abbr . '_enable_review_notice', true ); $can_ask_user_for_review = true; if ( $enable_review_notice ) { $current_user_id = get_current_user_id(); $review_done_option = $this->plugin_abbr . '_feedback_review_done'; $no_bug_option = $this->plugin_abbr . '_feedback_do_not_ask_again'; $already_did_option = $this->plugin_abbr . '_feedback_already_did'; $maybe_later_option = $this->plugin_abbr . '_feedback_maybe_later'; $review_done_time_option = $review_done_option . '_time'; $no_bug_time_option = $no_bug_option . '_time'; $already_did_time_option = $already_did_option . '_time'; $maybe_later_time_option = $maybe_later_option . '_time'; $no_bug_days_before = 1; $no_bug_value = get_user_meta( $current_user_id, $no_bug_option, true ); $no_bug_time_value = get_user_meta( $current_user_id, $no_bug_time_option, true ); $review_done_value = get_user_meta( $current_user_id, $review_done_option, true ); $review_done_time_value = get_user_meta( $current_user_id, $review_done_time_option, true ); if ( ! empty( $no_bug_time_value ) && 0 !== $no_bug_time_value ) { $no_bug_time_diff = time() - $no_bug_time_value; $no_bug_days_before = floor( $no_bug_time_diff / 86400 ); // 86400 seconds == 1 day } $already_did_value = get_user_meta( $current_user_id, $already_did_option, true ); $already_did_time_value = get_user_meta( $current_user_id, $already_did_time_option, true ); $maybe_later_days_before = 1; $maybe_later_value = get_user_meta( $current_user_id, $maybe_later_option, true ); $maybe_later_time_value = get_user_meta( $current_user_id, $maybe_later_time_option, true ); if ( $maybe_later_value && ! empty( $maybe_later_time_value ) && 0 !== $maybe_later_time_value ) { $maybe_later_time_diff = time() - $maybe_later_time_value; $maybe_later_days_before = floor( $maybe_later_time_diff / 86400 ); // 86400 seconds == 1 day } // Is user fall in love with our plugin in 15 days after when they said may be later? // But, make sure we are asking user only after 15 days. // We are good people. Respect the user decision. if ( $review_done_value || $no_bug_value || $already_did_value || ( $maybe_later_value && $maybe_later_days_before < 15 ) || $already_did_value ) { $can_ask_user_for_review = false; } $review_data = array( 'review_done_value' => $review_done_value, 'review_done_time_value' => $review_done_time_value, 'no_bug_value' => $no_bug_value, 'no_bug_time_value' => $no_bug_time_value, 'maybe_later_value' => $maybe_later_value, 'maybe_later_time_value' => $maybe_later_time_value, 'already_did_value' => $already_did_value, 'already_did_time_value' => $already_did_time_value, ); $can_ask_user_for_review = apply_filters( $this->plugin_abbr . '_can_ask_user_for_review', $can_ask_user_for_review, $review_data ); if ( $can_ask_user_for_review ) { $current_page_url = ''; if ( ! empty( $_SERVER['HTTP_HOST'] ) && ! empty( $_SERVER['REQUEST_URI'] ) ) { $current_page_url = esc_url_raw( '//' . wp_unslash( $_SERVER['HTTP_HOST'] ) . wp_unslash( $_SERVER['REQUEST_URI'] ) ); } $got_feedback = false; /************** Update Review Status */ $nonce = ! empty( $_GET['ig_feedback_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['ig_feedback_nonce'] ) ) : ''; $nonce_verified = wp_verify_nonce( $nonce, 'review' ); $action = ''; if ( $nonce_verified ) { $action = ! empty( $_GET['ig_feedback_action'] ) ? sanitize_text_field( wp_unslash( $_GET['ig_feedback_action'] ) ) : ''; if ( ! empty( $action ) && $this->is_valid_action( $action ) ) { update_user_meta( $current_user_id, $action, 1 ); update_user_meta( $current_user_id, $action . '_time', time() ); // Got the review request? // Redirect them to review page if ( $action === $review_done_option ) { $url = ! empty( $_GET['review_url'] ) ? esc_url_raw( wp_unslash( $_GET['review_url'] ) ) : ''; if ( ! empty( $url ) ) { ?> plugin}/reviews/"; $icon_url = plugin_dir_url( __FILE__ ) . 'assets/images/icon-64.png'; /* translators: %s: Plugin name */ $message = __( sprintf( "

We hope you're enjoying %s plugin! Could you please do us a BIG favor and give us a 5-star rating on WordPress to help us spread the word and boost our motivation?

", $this->name ), $this->plugin ); $message_data = array( 'review_url' => $review_url, 'icon_url' => $icon_url, 'message' => $message, ); $message_data = apply_filters( $this->plugin_abbr . '_review_message_data', $message_data ); $message = ! empty( $message_data['message'] ) ? $message_data['message'] : ''; $review_url = ! empty( $message_data['review_url'] ) ? $message_data['review_url'] : ''; $icon_url = ! empty( $message_data['icon_url'] ) ? $message_data['icon_url'] : ''; $nonce = wp_create_nonce( 'review' ); $review_url = add_query_arg( 'review_url', $review_url, add_query_arg( 'ig_feedback_nonce', $nonce, add_query_arg( 'ig_feedback_action', $review_done_option, $current_page_url ) ) ); $maybe_later_url = add_query_arg( 'ig_feedback_nonce', $nonce, add_query_arg( 'ig_feedback_action', $maybe_later_option, $current_page_url ) ); $already_did_url = add_query_arg( 'ig_feedback_nonce', $nonce, add_query_arg( 'ig_feedback_action', $already_did_option, $current_page_url ) ); $no_bug_url = add_query_arg( 'ig_feedback_nonce', $nonce, add_query_arg( 'ig_feedback_action', $no_bug_option, $current_page_url ) ); ?> '; echo ' Logo'; echo wp_kses_post( $message ); echo "
'; echo ''; } } } } } /** * Is valid action? * * @param string $action * * @return bool * * @since 1.0.14 */ public function is_valid_action( $action = '' ) { if ( empty( $action ) ) { return false; } $available_actions = array( '_feedback_review_done', '_feedback_already_did', '_feedback_maybe_later', '_feedback_do_not_ask_again', ); foreach ( $available_actions as $available_action ) { if ( strpos( $action, $available_action ) !== false ) { return true; } } return false; } /** * Render Deactivation Feedback * * @since 1.0.0 */ public function render_deactivate_feedback() { add_action( 'admin_print_footer_scripts', array( $this, 'js' ), 20 ); add_action( 'admin_print_scripts', array( $this, 'css' ) ); add_action( 'admin_footer', array( $this, 'modal' ) ); } /** * Load Javascripts * * @since 1.0.1 * * @modify 1.1.0 */ public function enqueue_scripts() { $can_load = apply_filters( $this->plugin_abbr . '_can_load_sweetalert_js', false ); if ( $can_load ) { wp_enqueue_script( 'sweetalert', plugin_dir_url( __FILE__ ) . 'assets/js/sweetalert2.min.js', array( 'jquery' ) ); } } /** * Load Styles * * @since 1.0.1 */ public function enqueue_styles() { $can_load = apply_filters( $this->plugin_abbr . '_can_load_sweetalert_css', false ); if ( $can_load ) { wp_register_style( "sweetalert_{$this->version}", plugin_dir_url( __FILE__ ) . 'assets/css/sweetalert2.min.css', array(), $this->version ); wp_enqueue_style( "sweetalert_{$this->version}" ); wp_register_style( "animate_{$this->version}", plugin_dir_url( __FILE__ ) . 'assets/css/animate.min.css', array(), $this->version ); wp_enqueue_style( "animate_{$this->version}" ); wp_register_style( "ig-feedback-star-rating_{$this->version}", plugin_dir_url( __FILE__ ) . 'assets/css/star-rating.min.css', array(), $this->version ); wp_enqueue_style( "ig-feedback-star-rating_{$this->version}" ); wp_register_style( "ig-feedback-emoji_{$this->version}", plugin_dir_url( __FILE__ ) . 'assets/css/emoji.min.css', array(), $this->version ); wp_enqueue_style( "ig-feedback-emoji_{$this->version}" ); wp_register_style( "ig-feedback_{$this->version}", plugin_dir_url( __FILE__ ) . 'assets/css/feedback.min.css', array(), $this->version ); wp_enqueue_style( "ig-feedback_{$this->version}" ); } } /** * Prepare Widget Params * * @param array $params * * @return array * * @since 1.0.3 */ public function prepare_widget_params( $params = array() ) { $default_params = array( 'event' => 'feedback', 'title' => 'How do you rate ' . $this->plugin, 'position' => 'top-end', 'width' => 300, 'set_transient' => true, 'allowOutsideClick' => false, 'allowEscapeKey' => true, 'showCloseButton' => true, 'confirmButtonText' => 'Ok', 'backdrop' => true, 'delay' => 3, // In Seconds 'consent_text' => 'You are agree to our terms and condition', 'email' => $this->get_contact_email(), 'name' => '', 'consent' => false, ); $params = wp_parse_args( $params, $default_params ); return $params; } /** * Render Widget * * @param array $params * * @since 1.0.0 */ public function render_widget( $params = array() ) { $params = $this->prepare_widget_params( $params ); $title = $params['title']; $slug = sanitize_title( $title ); $event = $this->event_prefix . $params['event']; $html = ! empty( $params['html'] ) ? $params['html'] : ''; ?>
render_widget( $params ); } /** * Render Emoji Widget * * @param array $params * * @since 1.0.1 */ public function render_emoji( $params = array() ) { ob_start(); ?>
render_widget( $params ); } /** * Render General Feedback Sidebar Button Widget * * @since 1.0.3 */ public function render_general_feedback( $params = array() ) { $params = $this->prepare_widget_params( $params ); ob_start(); ?>




event_prefix . $params['event']; $html = ! empty( $params['html'] ) ? $params['html'] : ''; $escape_allowed_tags = $this->get_escape_allowed_tags(); ob_start(); ?> prepare_widget_params( $params ); $title = $params['title']; $widget_tyoe = ! empty( $params['widget_tyoe'] ) ? $params['widget_tyoe'] : 'question'; $slug = sanitize_title( $title ); $event = $this->event_prefix . $params['event']; $html = ! empty( $params['html'] ) ? $params['html'] : ''; $confirm_button_link = ! empty( $params['confirmButtonLink'] ) ? $params['confirmButtonLink'] : ''; $cancel_button_link = ! empty( $params['cancelButtonLink'] ) ? $params['cancelButtonLink'] : ''; $show_cancel_button = ! empty( $params['showCancelButton'] ) ? 'true' : 'false'; $cancel_button_text = ! empty( $params['cancelButtonText'] ) ? $params['cancelButtonText'] : 'Cancel'; ?> prepare_widget_params( $params ); $fields = ! empty( $params['fields'] ) ? $params['fields'] : array(); if ( empty( $fields ) ) { return; } $default_values = ! empty( $params['default_values'] ) ? $params['default_values'] : array(); $allow_multiple = ! empty( $params['allow_multiple'] ) ? $params['allow_multiple'] : false; $title = $params['title']; if ( ! empty( $params['slug'] ) ) { $slug = $params['slug']; } else { $slug = sanitize_title( $title ); } $event = $this->event_prefix . $params['event']; $desc = ! empty( $params['desc'] ) ? $params['desc'] : ''; $display_as = ! empty( $params['display_as'] ) ? $params['display_as'] : 'inline'; $system_info = isset( $params['system_info'] ) ? $params['system_info'] : true; ob_start(); ?>






event_prefix . $params['event']; if ( 'inline' === $display_as ) { $this->render_inline_feedback_widget( $html, $params ); } elseif ( 'popup' === $display_as ) { $this->render_popup_feedback_widget( $html, $params ); } ?> get_escape_allowed_tags(); ?>
get_escape_allowed_tags(); ?> api_url = 'http://192.168.0.130:9094/store/feedback/'; } return $this->api_url; } /** * Deactivation Survey javascript. * * @since 1.0.0 */ public function js() { if ( ! $this->is_plugin_page() ) { return; } $title = 'Why are you deactivating ' . $this->name . '?'; $slug = sanitize_title( $title ); $event = $this->event_prefix . 'plugin.deactivation'; ?> is_plugin_page() ) { return; } ?> is_plugin_page() ) { return; } $email = $this->get_contact_email(); $options = array( 1 => array( 'title' => esc_html__( 'I no longer need the plugin', $this->plugin ), 'slug' => 'i-no-longer-need-the-plugin', ), 2 => array( 'title' => esc_html__( 'I\'m switching to a different plugin', $this->plugin ), 'slug' => 'i-am-switching-to-a-different-plugin', 'details' => esc_html__( 'Please share which plugin', $this->plugin ), ), 3 => array( 'title' => esc_html__( 'I couldn\'t get the plugin to work', $this->plugin ), 'slug' => 'i-could-not-get-the-plugin-to-work', ), 4 => array( 'title' => esc_html__( 'It\'s a temporary deactivation', $this->plugin ), 'slug' => 'it-is-a-temporary-deactivation', ), 5 => array( 'title' => esc_html__( 'Other', $this->plugin ), 'slug' => 'other', 'details' => esc_html__( 'Please share the reason', $this->plugin ), ), ); ?>
plugin ); ?> name ), $this->plugin ); ?>
$option ) : ?>
is_dev_mode ) { return true; } // Don't show on dev setup if dev mode is off. if ( $this->is_dev_url() ) { return false; } return true; } /** * Checks if current admin screen is the plugins page. * * @return bool * @since 1.0.0 */ public function is_plugin_page() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false; if ( empty( $screen ) ) { return false; } return ( ! empty( $screen->id ) && in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ); } /** * Checks if current site is a development one. * * @return bool * * @since 1.0.0 */ public function is_dev_url() { $url = network_site_url( '/' ); $is_local_url = false; // Trim it up $url = strtolower( trim( $url ) ); // Need to get the host...so let's add the scheme so we can use parse_url if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) { $url = 'http://' . $url; } $url_parts = parse_url( $url ); $host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false; // Discard our development environment if ( '192.168.0.112' === $host ) { return false; } if ( ! empty( $url ) && ! empty( $host ) ) { if ( false !== ip2long( $host ) ) { if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { $is_local_url = true; } } elseif ( 'localhost' === $host ) { $is_local_url = true; } $tlds_to_check = array( '.dev', '.local', ':8888' ); foreach ( $tlds_to_check as $tld ) { if ( false !== strpos( $host, $tld ) ) { $is_local_url = true; continue; } } if ( substr_count( $host, '.' ) > 1 ) { $subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' ); foreach ( $subdomains_to_check as $subdomain ) { $subdomain = str_replace( '.', '(.)', $subdomain ); $subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain ); if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) { $is_local_url = true; continue; } } } } return $is_local_url; } /** * Store plugin feedback data into option * * @param $plugin_abbr * @param $event * @param $data * * @since 1.0.1 */ public function set_feedback_data( $plugin_abbr, $event, $data = array() ) { $feedback_option = $plugin_abbr . '_feedback_data'; $feedback_data = maybe_unserialize( get_option( $feedback_option, array() ) ); $data['created_on'] = gmdate( 'Y-m-d H:i:s' ); $feedback_data[ $event ][] = $data; update_option( $feedback_option, $feedback_data ); } /** * Get plugin feedback data * * @param $plugin_abbr * * @return mixed|void * * @since 1.0.1 */ public function get_feedback_data( $plugin_abbr ) { $feedback_option = $plugin_abbr . '_feedback_data'; return get_option( $feedback_option, array() ); } /** * Get event specific feedback data * * @param $plugin_abbr * @param $event * * @return array|mixed */ public function get_event_feedback_data( $plugin_abbr, $event ) { $feedback_data = $this->get_feedback_data( $plugin_abbr ); $event_feedback_data = ! empty( $feedback_data[ $event ] ) ? $feedback_data[ $event ] : array(); return $event_feedback_data; } /** * Check whether event tracked or not. * * @param $plugin_abbr * @param $event * * @return bool * * @since 1.1.0 */ public function is_event_tracked( $plugin_abbr = '', $event = '' ) { if ( empty( $plugin_abbr ) || empty( $event ) ) { return false; } $feedback_data = $this->get_feedback_data( $plugin_abbr ); if ( count( $feedback_data ) > 0 ) { $events = array_keys( $feedback_data ); foreach ( $events as $key => $value ) { if ( strpos( $value, $event ) ) { return true; } } } return false; } /** * Set event into transient * * @param $event * @param int $expiry in days */ public function set_event_transient( $event, $expiry = 45 ) { set_transient( $event, 1, time() + ( 86400 * $expiry ) ); } /** * Check whether event transient is set or not. * * @param $event * * @return bool * * @since 1.0.1 */ public function is_event_transient_set( $event ) { return get_transient( $event ); } /** * Get contact email * * @return string * * @since 1.0.8 */ public function get_contact_email() { $email = ''; // Get logged in User Email Address $current_user = wp_get_current_user(); if ( $current_user instanceof WP_User ) { $email = $current_user->user_email; } // If email empty, get admin email if ( empty( $email ) ) { $email = get_option( 'admin_email' ); } return $email; } /** * Hook to ajax_action * * Send feedback to server */ public function submit_feedback() { check_ajax_referer( $this->plugin_abbr . '-admin-ajax-nonce', 'security' ); $data = ! empty( $_POST ) ? $_POST : array(); $data['site'] = esc_url( home_url() ); $plugin = ! empty( $data['misc']['plugin'] ) ? $data['misc']['plugin'] : 'ig_feedback'; $plugin_abbr = ! empty( $data['misc']['plugin_abbr'] ) ? $data['misc']['plugin_abbr'] : 'ig_feedback'; $is_dev_mode = ! empty( $data['misc']['is_dev_mode'] ) ? $data['misc']['is_dev_mode'] : false; $set_transient = ! empty( $data['misc']['set_transient'] ) ? $data['misc']['set_transient'] : false; $system_info = ( isset( $data['misc']['system_info'] ) && $data['misc']['system_info'] === 'true' ) ? true : false; $meta_info = ! empty( $data['misc']['meta_info'] ) ? $data['misc']['meta_info'] : array(); unset( $data['misc'] ); $default_meta_info = array( 'plugin' => sanitize_key( $plugin ), 'locale' => get_locale(), 'wp_version' => get_bloginfo( 'version' ), 'php_version' => PHP_VERSION, ); $meta_info = wp_parse_args( $meta_info, $default_meta_info ); $additional_info = array(); $additional_info = apply_filters( $plugin_abbr . '_additional_feedback_meta_info', $additional_info, $system_info ); // Get Additional meta information if ( is_array( $additional_info ) && count( $additional_info ) > 0 ) { $meta_info = array_merge( $meta_info, $additional_info ); } $data['meta'] = $meta_info; $data = wp_unslash( $data ); $args = array( 'timeout' => 15, 'sslverify' => false, 'body' => $data, 'blocking' => false, ); $this->set_feedback_data( $plugin_abbr, $data['event'], $data['feedback'] ); // Set Cookie if ( $set_transient ) { $this->set_event_transient( $data['event'] ); } $response = wp_remote_post( $this->get_api_url( $is_dev_mode ), $args ); $result['status'] = 'success'; if ( $response instanceof WP_Error ) { $error_message = $response->get_error_message(); $result['status'] = 'error'; $result['message'] = $error_message; } die( json_encode( $result ) ); } /** * Get list of tags allowed in escaping * * @return array $ig_es_escape_allowed_tags */ public function get_escape_allowed_tags() { $ig_es_escape_allowed_tags = apply_filters( $this->plugin_abbr . '_escape_allowed_tags', array() ); return $ig_es_escape_allowed_tags; } /** * Render Quick Feedback Widget * * @param $params * * @since 4.1.0 */ public function render_feedback_widget( $params ) { if ( ! $this->can_show_feedback_widget() ) { return; } $default_params = array( 'set_transient' => true, 'force' => false, 'show_once' => false, ); $params = wp_parse_args( $params, $default_params ); if ( ! empty( $params['event'] ) ) { $event = $this->event_prefix . $params['event']; $force = ! empty( $params['force'] ) ? $params['force'] : false; $can_show = false; if ( $force ) { $can_show = true; } else { if ( ! $this->is_event_transient_set( $event ) ) { $can_show = true; $feedback_data = $this->get_event_feedback_data( $this->plugin_abbr, $event ); if ( count( $feedback_data ) > 0 ) { $show_once = $params['show_once']; $feedback_data = array_reverse( $feedback_data ); $last_feedback_given_on = $feedback_data[0]['created_on']; // If event feedback given within 45 days or show event only once? // Don't show now if ( $show_once || ( strtotime( $last_feedback_given_on ) > strtotime( '-45 days' ) ) ) { $can_show = false; } } } } if ( $can_show ) { if ( 'star' === $params['type'] ) { $this->render_stars( $params ); } elseif ( 'emoji' === $params['type'] ) { $this->render_emoji( $params ); } elseif ( 'feedback' === $params['type'] ) { $this->render_general_feedback( $params ); } elseif ( 'fb' === $params['type'] ) { /** * We are not calling home for this event and we want to show * this Widget only once. So, we are storing feedback data now. */ $this->set_feedback_data( $this->plugin_abbr, $event ); $this->render_fb_widget( $params ); } elseif ( 'poll' === $params['type'] ) { if ( $params['show_once'] ) { $this->set_feedback_data( $this->plugin_abbr, $event ); } $this->render_poll_widget( $params ); } } } } } } // End if().