From d52a103c6cc63de48820684118e83744eb183342 Mon Sep 17 00:00:00 2001
From: Kevin Pliester <5339107+pixelbart@users.noreply.github.com>
Date: Thu, 26 Aug 2021 16:12:32 +0200
Subject: [PATCH] 4.4.50
---
core/class-helper.php | 9 +-
core/functions/helpers.php | 5 +-
core/functions/values.php | 7 +-
core/helpers/class-cache.php | 115 +-
core/helpers/class-database.php | 7 +-
core/helpers/class-feedback.php | 1169 +++++-----
core/helpers/class-optimize.php | 599 +++--
core/helpers/class-stats.php | 2711 +++++++++++------------
core/helpers/class-user.php | 29 +-
core/helpers/class-values.php | 13 +-
core/helpers/class-votes.php | 279 ++-
core/index.php | 2 +
core/modules/class-admin.php | 745 ++++---
core/modules/class-core.php | 22 +-
core/modules/class-customizer.php | 299 ++-
core/modules/class-debug.php | 209 +-
core/modules/class-elementor-widget.php | 415 ++--
core/modules/class-feedback-admin.php | 11 +-
core/modules/class-frontend.php | 9 +-
core/modules/class-maintenance.php | 233 +-
core/modules/class-metabox.php | 289 ++-
core/modules/class-widget.php | 51 +-
core/services/class-csv.php | 7 +-
core/services/class-helpful.php | 7 +-
core/services/class-options.php | 5 +-
core/services/class-session.php | 101 +
core/services/class-xml.php | 7 +-
core/tabs/class-design.php | 141 +-
core/tabs/class-details.php | 285 ++-
core/tabs/class-feedback.php | 275 ++-
core/tabs/class-log.php | 7 +-
core/tabs/class-start.php | 559 +++--
core/tabs/class-system.php | 403 ++--
core/tabs/class-texts.php | 241 +-
templates/admin-feedback-item.php | 23 +-
templates/admin-feedback-pagination.php | 17 +-
templates/admin-feedback.php | 30 +-
templates/admin-metabox.php | 51 +-
templates/admin-widget.php | 108 +-
templates/admin.php | 20 +-
templates/feedback-email-voter.php | 15 +-
templates/feedback-email.php | 16 +-
templates/feedback.php | 33 +-
templates/helpful.php | 35 +-
templates/tabs/tab-details.php | 169 +-
templates/tabs/tab-feedback.php | 217 +-
templates/tabs/tab-log.php | 34 +-
templates/tabs/tab-start.php | 45 +-
templates/tabs/tab-system.php | 184 +-
templates/tabs/tab-texts.php | 141 +-
50 files changed, 5219 insertions(+), 5185 deletions(-)
create mode 100644 core/services/class-session.php
diff --git a/core/class-helper.php b/core/class-helper.php
index 3d8706d..3cb1168 100644
--- a/core/class-helper.php
+++ b/core/class-helper.php
@@ -1,10 +1,9 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core;
diff --git a/core/functions/helpers.php b/core/functions/helpers.php
index 1044289..11993c2 100644
--- a/core/functions/helpers.php
+++ b/core/functions/helpers.php
@@ -1,9 +1,8 @@
+ * @since 4.4.50
+ * @since 4.3.0
*/
use Helpful\Core\Helper;
use Helpful\Core\Helpers as Helpers;
diff --git a/core/functions/values.php b/core/functions/values.php
index 7fa4ee1..ea3e4eb 100644
--- a/core/functions/values.php
+++ b/core/functions/values.php
@@ -1,10 +1,7 @@
+ * @package Helpful
+ * @version 4.4.50
* @since 4.0.0
*/
use Helpful\Core\Helpers as Helpers;
diff --git a/core/helpers/class-cache.php b/core/helpers/class-cache.php
index f5307b2..a5bcc62 100644
--- a/core/helpers/class-cache.php
+++ b/core/helpers/class-cache.php
@@ -1,79 +1,78 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
use Helpful\Core\Helper;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Cache
{
- /**
- * Returns the available times for caching with the Transients API from WordPress.
- *
- * @param boolean $labels Outputs either the miliseconds or the labels for the options.
- *
- * @return array
- */
- public static function get_cache_times( $labels = true )
- {
- $times = [];
+ /**
+ * Returns the available times for caching with the Transients API from WordPress.
+ *
+ * @param boolean $labels Outputs either the miliseconds or the labels for the options.
+ *
+ * @return array
+ */
+ public static function get_cache_times($labels = true)
+ {
+ $times = [];
- $times['minute'] = esc_html_x( 'One minute', 'caching time', 'helpful' );
- $times['hour'] = esc_html_x( 'One hour', 'caching time', 'helpful' );
- $times['day'] = esc_html_x( 'One day', 'caching time', 'helpful' );
- $times['week'] = esc_html_x( 'One week', 'caching time', 'helpful' );
- $times['month'] = esc_html_x( 'One month', 'caching time', 'helpful' );
- $times['year'] = esc_html_x( 'One year', 'caching time', 'helpful' );
+ $times['minute'] = esc_html_x('One minute', 'caching time', 'helpful');
+ $times['hour'] = esc_html_x('One hour', 'caching time', 'helpful');
+ $times['day'] = esc_html_x('One day', 'caching time', 'helpful');
+ $times['week'] = esc_html_x('One week', 'caching time', 'helpful');
+ $times['month'] = esc_html_x('One month', 'caching time', 'helpful');
+ $times['year'] = esc_html_x('One year', 'caching time', 'helpful');
- if ( false === $labels ) {
- $times['minute'] = MINUTE_IN_SECONDS;
- $times['hour'] = HOUR_IN_SECONDS;
- $times['day'] = DAY_IN_SECONDS;
- $times['week'] = WEEK_IN_SECONDS;
- $times['month'] = MONTH_IN_SECONDS;
- $times['year'] = YEAR_IN_SECONDS;
- }
+ if (false === $labels) {
+ $times['minute'] = MINUTE_IN_SECONDS;
+ $times['hour'] = HOUR_IN_SECONDS;
+ $times['day'] = DAY_IN_SECONDS;
+ $times['week'] = WEEK_IN_SECONDS;
+ $times['month'] = MONTH_IN_SECONDS;
+ $times['year'] = YEAR_IN_SECONDS;
+ }
- return $times;
- }
+ return $times;
+ }
- /**
- * Deletes all transients related to Helpful and clears the cache of Helpful.
- *
- * @return integer Amount of deleted entries.
- */
- public static function clear_cache()
- {
- global $wpdb;
+ /**
+ * Deletes all transients related to Helpful and clears the cache of Helpful.
+ *
+ * @return integer Amount of deleted entries.
+ */
+ public static function clear_cache()
+ {
+ global $wpdb;
- $table_name = $wpdb->prefix . 'options';
+ $table_name = $wpdb->prefix . 'options';
- $count = 0;
- $sql = "SELECT * FROM $table_name WHERE option_name LIKE '_transient_timeout_helpful_%' OR option_name LIKE '_transient_helpful_%'";
- $rows = $wpdb->get_results( $sql );
+ $count = 0;
+ $sql = "SELECT * FROM $table_name WHERE option_name LIKE '_transient_timeout_helpful_%' OR option_name LIKE '_transient_helpful_%'";
+ $rows = $wpdb->get_results($sql);
- if ( $rows ) {
- foreach ( $rows as $row ) :
- if ( '_transient_timeout_helpful_updated' === $row->option_name || '_transient_helpful_updated' === $row->option_name ) {
- continue;
- }
+ if ($rows) {
+ foreach ($rows as $row):
+ if ('_transient_timeout_helpful_updated' === $row->option_name || '_transient_helpful_updated' === $row->option_name) {
+ continue;
+ }
- $values = [ 'option_name' => $row->option_name ];
- $wpdb->delete( $table_name, $values );
- $count++;
- endforeach;
- }
+ $values = ['option_name' => $row->option_name];
+ $wpdb->delete($table_name, $values);
+ $count++;
+ endforeach;
+ }
- return $count;
- }
-}
\ No newline at end of file
+ return $count;
+ }
+}
diff --git a/core/helpers/class-database.php b/core/helpers/class-database.php
index 953906d..b838cb9 100644
--- a/core/helpers/class-database.php
+++ b/core/helpers/class-database.php
@@ -1,8 +1,9 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
diff --git a/core/helpers/class-feedback.php b/core/helpers/class-feedback.php
index f6f5a55..426958c 100644
--- a/core/helpers/class-feedback.php
+++ b/core/helpers/class-feedback.php
@@ -1,598 +1,595 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 1.0.0
*/
namespace Helpful\Core\Helpers;
use Helpful\Core\Helper;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Feedback
{
- /**
- * Get feedback data by post object.
- *
- * @param object $entry post object.
- *
- * @return string json
- */
- public static function get_feedback( $entry )
- {
- $post = get_post( $entry->post_id );
- $time = strtotime( $entry->time );
-
- $feedback = [];
- $feedback['id'] = $entry->id;
- $feedback['name'] = __( 'Anonymous', 'helpful' );
- $feedback['message'] = nl2br( $entry->message );
- $feedback['pro'] = $entry->pro;
- $feedback['contra'] = $entry->contra;
- $feedback['post'] = $post;
- $feedback['time'] = sprintf(
- /* translators: %s = time difference */
- __( 'Submitted %s ago', 'helpful' ),
- human_time_diff( $time, current_time( 'timestamp' ) )
- );
-
- if ( $entry->fields ) {
- $items = maybe_unserialize( $entry->fields );
- if ( is_array( $items ) ) {
- foreach ( $items as $label => $value ) {
- $feedback['fields'][ $label ] = $value;
- }
- }
- }
-
- $feedback['avatar'] = User::get_avatar();
-
- if ( isset( $feedback['fields']['email'] ) && '' !== $feedback['fields']['email'] ) {
- $feedback['avatar'] = User::get_avatar( $feedback['fields']['email'] );
- }
-
- if ( isset( $feedback['fields']['name'] ) && '' !== $feedback['fields']['name'] ) {
- $feedback['name'] = $feedback['fields']['name'];
- }
-
- $feedback = apply_filters( 'helpful_admin_feedback_item', $feedback, $entry );
-
- return json_decode( wp_json_encode( $feedback ) );
- }
-
- /**
- * Get feedback items.
- *
- * @global $wpdb
- *
- * @param integer $limit posts per page.
- *
- * @return object
- */
- public static function get_feedback_items( $limit = null )
- {
- if ( is_null( $limit ) ) {
- $limit = absint( get_option( 'helpful_widget_amount' ) );
- }
-
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful_feedback';
-
- $query = "SELECT * FROM $helpful ORDER BY time DESC LIMIT %d";
- $query = $wpdb->prepare( $query, $limit );
- $results = $wpdb->get_results( $query );
-
- if ( $results ) {
- return $results;
- }
-
- return false;
- }
-
- /**
- * Insert feedback into database.
- *
- * @global $wpdb
- *
- * @return integer
- */
- public static function insert_feedback()
- {
- global $wpdb;
-
- $fields = [];
- $pro = 0;
- $contra = 0;
- $message = null;
-
- if ( ! isset( $_REQUEST['post_id'] ) ) {
- $message = 'Helpful Notice: Feedback was not saved because the post id is empty in %s on line %d.';
- helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) );
- return null;
- }
-
- $post_id = absint( sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ) );
-
- if ( ! isset( $_REQUEST['message'] ) ) {
- $message = 'Helpful Notice: Feedback was not saved because the message is empty in %s on line %d.';
- helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) );
- return null;
- }
-
- $message = trim( $_REQUEST['message'] );
-
- if ( '' === $message ) {
- $message = 'Helpful Notice: Feedback was not saved because the message is empty in %s on line %d.';
- helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) );
- return null;
- }
-
- if ( helpful_backlist_check( $_REQUEST['message'] ) ) {
- $message = 'Helpful Notice: Feedback was not saved because the message contains blacklisted words in %s on line %d.';
- helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) );
- return null;
- }
-
- $session = [];
-
- if ( isset( $_REQUEST['session'] ) ) {
- $session = $_REQUEST['session'];
- }
-
- if ( isset( $_REQUEST['fields'] ) ) {
- foreach ( $_REQUEST['fields'] as $key => $value ) {
- $fields[ $key ] = sanitize_text_field( $value );
- }
-
- $fields = apply_filters( 'helpful_feedback_submit_fields', $fields, $session );
- }
-
- if ( is_user_logged_in() ) {
- $user = wp_get_current_user();
- $fields = [];
-
- $fields['name'] = $user->display_name;
- $fields['email'] = $user->user_email;
-
- $fields = apply_filters( 'helpful_feedback_submit_fields', $fields, $session );
- }
-
- if ( isset( $_REQUEST['message'] ) ) {
- $message = sanitize_textarea_field( wp_strip_all_tags( wp_unslash( $_REQUEST['message'] ) ) );
- $message = stripslashes( $message );
- $message = apply_filters( 'helpful_feedback_submit_message', $message );
- }
-
- if ( isset( $_REQUEST['type'] ) ) {
- $type = sanitize_text_field( wp_unslash( $_REQUEST['type'] ) );
-
- if ( 'pro' === $type ) {
- $pro = 1;
- } elseif ( 'contra' === $type ) {
- $contra = 1;
- }
- }
-
- $data = [
- 'time' => current_time( 'mysql' ),
- 'user' => esc_attr( $_REQUEST['user_id'] ),
- 'pro' => $pro,
- 'contra' => $contra,
- 'post_id' => $post_id,
- 'message' => $message,
- 'fields' => maybe_serialize( $fields ),
- ];
-
- /* send email */
- self::send_email( $data );
-
- $table_name = $wpdb->prefix . 'helpful_feedback';
- $wpdb->insert( $table_name, $data );
-
- Stats::delete_widget_transient();
-
- return $wpdb->insert_id;
- }
-
- /**
- * Send feedback email.
- *
- * @param array $feedback feedback data.
- *
- * @return void
- */
- public static function send_email( $feedback )
- {
- /**
- * Send email to voter.
- */
- self::send_email_voter( $feedback );
-
- if ( 'on' !== get_option( 'helpful_feedback_send_email' ) ) {
- return;
- }
-
- $post = get_post( $feedback['post_id'] );
-
- if ( ! $post ) {
- return;
- }
-
- $feedback['fields'] = maybe_unserialize( $feedback['fields'] );
-
- /* tags */
- $tags = [
- '{type}' => $type,
- '{name}' => isset( $feedback['fields']['name'] ) ? $feedback['fields']['name'] : '',
- '{email}' => isset( $feedback['fields']['email'] ) ? $feedback['fields']['email'] : '',
- '{message}' => $feedback['message'],
- '{post_url}' => get_permalink( $post ),
- '{post_title}' => $post->post_title,
- '{blog_name}' => get_bloginfo( 'name' ),
- '{blog_url}' => site_url(),
- ];
-
- $tags = apply_filters( 'helpful_feedback_email_tags', $tags );
-
- /* email subject */
- $subject = get_option( 'helpful_feedback_subject' );
- $subject = str_replace( array_keys( $tags ), array_values( $tags ), $subject );
-
- /* unserialize feedback fields */
- $feedback['fields'] = maybe_unserialize( $feedback['fields'] );
-
- $type = esc_html__( 'positive', 'helpful' );
- if ( 1 === $feedback['contra'] ) {
- $type = esc_html__( 'negative', 'helpful' );
- }
-
- /* body */
- $body = get_option( 'helpful_feedback_email_content' );
- $body = str_replace( array_keys( $tags ), array_values( $tags ), $body );
-
- /* receivers by post meta */
- $post_receivers = [];
-
- if ( get_post_meta( $post->ID, 'helpful_feedback_receivers', true ) ) {
- $post_receivers = get_post_meta( $post->ID, 'helpful_feedback_receivers', true );
- $post_receivers = helpful_trim_all( $post_receivers );
- $post_receivers = explode( ',', $post_receivers );
- }
-
- /* receivers by helpful options */
- $helpful_receivers = [];
-
- if ( get_option( 'helpful_feedback_receivers' ) ) {
- $helpful_receivers = get_option( 'helpful_feedback_receivers' );
- $helpful_receivers = helpful_trim_all( $helpful_receivers );
- $helpful_receivers = explode( ',', $helpful_receivers );
- }
-
- $receivers = array_merge( $helpful_receivers, $post_receivers );
- $receivers = array_unique( $receivers );
-
- /* receivers array is empty */
- if ( empty( $receivers ) ) {
- return;
- }
-
- /* email headers */
- $headers = [];
- $headers[] = 'Content-Type: text/html; charset=UTF-8';
-
- if ( $feedback['fields']['email'] ) {
- $headers[] = sprintf( 'Reply-To: %s', $feedback['fields']['email'] );
- }
-
- /* filters */
- $receivers = apply_filters( 'helpful_feedback_email_receivers', $receivers, $feedback );
- $subject = apply_filters( 'helpful_feedback_email_subject', $subject, $feedback );
- $body = apply_filters( 'helpful_feedback_email_body', $body, $feedback );
- $headers = apply_filters( 'helpful_feedback_email_headers', $headers, $feedback );
-
- $response = wp_mail( $receivers, $subject, $body, $headers );
-
- if ( false === $response ) {
- $message = 'Helpful Warning: Email could not be sent in %s on line %d.';
- helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) );
- }
- }
-
- /**
- * Send feedback email to voter.
- *
- * @param array $feedback feedback data.
- *
- * @return void
- */
- public static function send_email_voter( $feedback )
- {
- if ( 'on' !== get_option( 'helpful_feedback_send_email_voter' ) ) {
- return;
- }
-
- $post = get_post( $feedback['post_id'] );
-
- if ( ! $post ) {
- return;
- }
-
- $feedback['fields'] = maybe_unserialize( $feedback['fields'] );
-
- /* tags */
- $tags = [
- '{type}' => $type,
- '{name}' => isset( $feedback['fields']['name'] ) ? $feedback['fields']['name'] : '',
- '{email}' => isset( $feedback['fields']['email'] ) ? $feedback['fields']['email'] : '',
- '{message}' => $feedback['message'],
- '{post_url}' => get_permalink( $post ),
- '{post_title}' => $post->post_title,
- '{blog_name}' => get_bloginfo( 'name' ),
- '{blog_url}' => site_url(),
- ];
-
- $tags = apply_filters( 'helpful_feedback_email_tags', $tags );
-
- /* subject */
- $subject = get_option( 'helpful_feedback_subject_voter' );
- $subject = str_replace( array_keys( $tags ), array_values( $tags ), $subject );
-
- /* unserialize feedback fields */
- $feedback['fields'] = maybe_unserialize( $feedback['fields'] );
-
- $type = esc_html__( 'positive', 'helpful' );
- if ( 1 === $feedback['contra'] ) {
- $type = esc_html__( 'negative', 'helpful' );
- }
-
- /* Body */
- $body = get_option( 'helpful_feedback_email_content_voter' );
- $body = str_replace( array_keys( $tags ), array_values( $tags ), $body );
-
- /* Receivers */
- $receivers = [];
-
- if ( isset( $feedback['fields']['email'] ) && '' !== trim( $feedback['fields']['email'] ) ) {
- $receivers[] = sanitize_email( $feedback['fields']['email'] );
- }
-
- /* receivers array is empty */
- if ( empty( $receivers ) ) {
- return;
- }
-
- /* email headers */
- $headers = [];
- $headers[] = 'Content-Type: text/html; charset=UTF-8';
-
- /* filters */
- $receivers = apply_filters( 'helpful_feedback_email_receivers_voter', $receivers, $feedback );
- $subject = apply_filters( 'helpful_feedback_email_subject_voter', $subject, $feedback );
- $body = apply_filters( 'helpful_feedback_email_body_voter', $body, $feedback );
- $headers = apply_filters( 'helpful_feedback_email_headers_voter', $headers, $feedback );
-
- $response = wp_mail( $receivers, $subject, $body, $headers );
-
- if ( false === $response ) {
- $message = 'Helpful Warning: Email could not be sent in %s on line %d.';
- helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) );
- }
- }
-
- /**
- * Outputs the amount of feedback for a post.
- *
- * @global $wpdb
- *
- * @param int|null $post_id
- *
- * @return int
- */
- public static function get_feedback_count( $post_id = null )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful_feedback';
-
- if ( null === $post_id || ! is_numeric( $post_id ) ) {
- $sql = "SELECT COUNT(*) FROM $helpful";
- return $wpdb->get_var( $sql );
- }
-
- $post_id = intval( $post_id );
- $sql = "SELECT COUNT(*) FROM $helpful WHERE post_id = %d";
-
- $count = $wpdb->get_var( $wpdb->prepare( $sql, $post_id ) );
-
- return apply_filters( 'helpful_pre_get_feedback_count', $count, $post_id );
- }
-
-
-
- /**
- * Render after messages or feedback form, after vote.
- * Checks if custom template exists.
- *
- * @param integer $post_id post id.
- * @param bool $show_feedback show feedback form anyway.
- *
- * @return string
- */
- public static function after_vote( $post_id, $show_feedback = false )
- {
- // $feedback_text = esc_html_x( 'Thank you very much. Please write us your opinion, so that we can improve ourselves.', 'form user note', 'helpful' );
-
- $hide_feedback = get_post_meta( $post_id, 'helpful_hide_feedback_on_post', true );
- $hide_feedback = ( 'on' === $hide_feedback ) ? true : false;
-
- if( Helper::is_feedback_disabled() ) {
- $hide_feedback = true;
- }
-
- $user_id = User::get_user();
- $type = User::get_user_vote_status( $user_id, $post_id );
-
- $accepted_types = [ 'pro', 'contra', 'none' ];
-
- if ( isset( $_REQUEST['value'] ) && 'none' === $type ) {
- if ( in_array( $_REQUEST['value'], $accepted_types ) ) {
- $type = sanitize_text_field( wp_unslash( $_REQUEST['value'] ) );
- }
- }
-
- if ( true === $show_feedback ) {
- $type = 'none';
- $feedback_text = get_option( 'helpful_feedback_message_voted' );
- $feedback_text = apply_filters( 'helpful_pre_feedback_message_voted', $feedback_text, $post_id );
- }
-
- if ( 'pro' === $type ) {
- $feedback_text = get_option( 'helpful_feedback_message_pro' );
-
- if ( false === $show_feedback ) {
- if ( ! get_option( 'helpful_feedback_after_pro' ) || true === $hide_feedback ) {
- $content = do_shortcode( get_option( 'helpful_after_pro' ) );
-
- if ( get_post_meta( $post_id, 'helpful_after_pro', true ) ) {
- $content = do_shortcode( get_post_meta( $post_id, 'helpful_after_pro', true ) );
- }
-
- return apply_filters( 'helpful_pre_after_pro', $content, $post_id );
- }
- }
- }
-
- if ( 'contra' === $type ) {
- $feedback_text = get_option( 'helpful_feedback_message_contra' );
-
- if ( false === $show_feedback ) {
- if ( ! get_option( 'helpful_feedback_after_contra' ) || true === $hide_feedback ) {
- $content = do_shortcode( get_option( 'helpful_after_contra' ) );
-
- if ( get_post_meta( $post_id, 'helpful_after_contra', true ) ) {
- $content = do_shortcode( get_post_meta( $post_id, 'helpful_after_contra', true ) );
- }
-
- return apply_filters( 'helpful_pre_after_contra', $content, $post_id );
- }
- }
- }
-
- if ( 'none' === $type ) {
- if ( ! get_option( 'helpful_feedback_after_pro' ) && ! get_option( 'helpful_feedback_after_contra' ) && false === $show_feedback ) {
- $content = do_shortcode( get_option( 'helpful_after_fallback' ) );
-
- if ( get_post_meta( $post_id, 'helpful_after_fallback', true ) ) {
- $content = do_shortcode( get_post_meta( $post_id, 'helpful_after_fallback', true ) );
- }
-
- return apply_filters( 'helpful_pre_after_fallback', $content, $post_id );
- }
- }
-
- if ( isset( $feedback_text ) && '' === trim( $feedback_text ) ) {
- $feedback_text = false;
- }
-
- if ( ! isset( $feedback_text ) ) {
- $feedback_text = false;
- }
-
- ob_start();
-
- $default_template = HELPFUL_PATH . 'templates/feedback.php';
- $custom_template = locate_template( 'helpful/feedback.php' );
-
- do_action( 'helpful_before_feedback_form' );
-
- echo '
';
-
- do_action( 'helpful_after_feedback_form' );
-
- $content = ob_get_contents();
- ob_end_clean();
-
- if ( false !== $show_feedback ) {
- $content = '';
- }
-
- return apply_filters( 'helpful_pre_feedback', $content, $post_id );
- }
-
- /**
- * Get feedback email content.
- *
- * @return string
- */
- public static function get_email_content()
- {
- $file = HELPFUL_PATH . 'templates/feedback-email.php';
-
- if ( ! file_exists( $file ) ) {
- return '';
- }
-
- ob_start();
- require_once $file;
- $content = ob_get_contents();
- ob_end_clean();
-
- return apply_filters( 'helpful_pre_get_email_content', $content );
- }
-
- /**
- * Get feedback email content for voters.
- *
- * @return string
- */
- public static function get_email_content_voter()
- {
- $file = HELPFUL_PATH . 'templates/feedback-email-voter.php';
-
- if ( ! file_exists( $file ) ) {
- return '';
- }
-
- ob_start();
- require_once $file;
- $content = ob_get_contents();
- ob_end_clean();
-
- return apply_filters( 'helpful_pre_get_email_content_voter', $content );
- }
-}
\ No newline at end of file
+ /**
+ * Get feedback data by post object.
+ *
+ * @param object $entry post object.
+ *
+ * @return string json
+ */
+ public static function get_feedback($entry)
+ {
+ $post = get_post($entry->post_id);
+ $time = strtotime($entry->time);
+
+ $feedback = [];
+ $feedback['id'] = $entry->id;
+ $feedback['name'] = __('Anonymous', 'helpful');
+ $feedback['message'] = nl2br($entry->message);
+ $feedback['pro'] = $entry->pro;
+ $feedback['contra'] = $entry->contra;
+ $feedback['post'] = $post;
+ $feedback['time'] = sprintf(
+ /* translators: %s = time difference */
+ __('Submitted %s ago', 'helpful'),
+ human_time_diff($time, current_time('timestamp'))
+ );
+
+ if ($entry->fields) {
+ $items = maybe_unserialize($entry->fields);
+ if (is_array($items)) {
+ foreach ($items as $label => $value) {
+ $feedback['fields'][$label] = $value;
+ }
+ }
+ }
+
+ $feedback['avatar'] = User::get_avatar();
+
+ if (isset($feedback['fields']['email']) && '' !== $feedback['fields']['email']) {
+ $feedback['avatar'] = User::get_avatar($feedback['fields']['email']);
+ }
+
+ if (isset($feedback['fields']['name']) && '' !== $feedback['fields']['name']) {
+ $feedback['name'] = $feedback['fields']['name'];
+ }
+
+ $feedback = apply_filters('helpful_admin_feedback_item', $feedback, $entry);
+
+ return json_decode(wp_json_encode($feedback));
+ }
+
+ /**
+ * Get feedback items.
+ *
+ * @global $wpdb
+ *
+ * @param integer $limit posts per page.
+ *
+ * @return object
+ */
+ public static function get_feedback_items($limit = null)
+ {
+ if (is_null($limit)) {
+ $limit = absint(get_option('helpful_widget_amount'));
+ }
+
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful_feedback';
+
+ $query = "SELECT * FROM $helpful ORDER BY time DESC LIMIT %d";
+ $query = $wpdb->prepare($query, $limit);
+ $results = $wpdb->get_results($query);
+
+ if ($results) {
+ return $results;
+ }
+
+ return false;
+ }
+
+ /**
+ * Insert feedback into database.
+ *
+ * @global $wpdb
+ *
+ * @return integer
+ */
+ public static function insert_feedback()
+ {
+ global $wpdb;
+
+ $fields = [];
+ $pro = 0;
+ $contra = 0;
+ $message = null;
+
+ if (!isset($_REQUEST['post_id'])) {
+ $message = 'Helpful Notice: Feedback was not saved because the post id is empty in %s on line %d.';
+ helpful_error_log(sprintf($message, __FILE__, __LINE__));
+ return null;
+ }
+
+ $post_id = absint(sanitize_text_field(wp_unslash($_REQUEST['post_id'])));
+
+ if (!isset($_REQUEST['message'])) {
+ $message = 'Helpful Notice: Feedback was not saved because the message is empty in %s on line %d.';
+ helpful_error_log(sprintf($message, __FILE__, __LINE__));
+ return null;
+ }
+
+ $message = trim($_REQUEST['message']);
+
+ if ('' === $message) {
+ $message = 'Helpful Notice: Feedback was not saved because the message is empty in %s on line %d.';
+ helpful_error_log(sprintf($message, __FILE__, __LINE__));
+ return null;
+ }
+
+ if (helpful_backlist_check($_REQUEST['message'])) {
+ $message = 'Helpful Notice: Feedback was not saved because the message contains blacklisted words in %s on line %d.';
+ helpful_error_log(sprintf($message, __FILE__, __LINE__));
+ return null;
+ }
+
+ $session = [];
+
+ if (isset($_REQUEST['session'])) {
+ $session = $_REQUEST['session'];
+ }
+
+ if (isset($_REQUEST['fields'])) {
+ foreach ($_REQUEST['fields'] as $key => $value) {
+ $fields[$key] = sanitize_text_field($value);
+ }
+
+ $fields = apply_filters('helpful_feedback_submit_fields', $fields, $session);
+ }
+
+ if (is_user_logged_in()) {
+ $user = wp_get_current_user();
+ $fields = [];
+
+ $fields['name'] = $user->display_name;
+ $fields['email'] = $user->user_email;
+
+ $fields = apply_filters('helpful_feedback_submit_fields', $fields, $session);
+ }
+
+ if (isset($_REQUEST['message'])) {
+ $message = sanitize_textarea_field(wp_strip_all_tags(wp_unslash($_REQUEST['message'])));
+ $message = stripslashes($message);
+ $message = apply_filters('helpful_feedback_submit_message', $message);
+ }
+
+ if (isset($_REQUEST['type'])) {
+ $type = sanitize_text_field(wp_unslash($_REQUEST['type']));
+
+ if ('pro' === $type) {
+ $pro = 1;
+ } elseif ('contra' === $type) {
+ $contra = 1;
+ }
+ }
+
+ $data = [
+ 'time' => current_time('mysql'),
+ 'user' => esc_attr($_REQUEST['user_id']),
+ 'pro' => $pro,
+ 'contra' => $contra,
+ 'post_id' => $post_id,
+ 'message' => $message,
+ 'fields' => maybe_serialize($fields),
+ ];
+
+ /* send email */
+ self::send_email($data);
+
+ $table_name = $wpdb->prefix . 'helpful_feedback';
+ $wpdb->insert($table_name, $data);
+
+ Stats::delete_widget_transient();
+
+ return $wpdb->insert_id;
+ }
+
+ /**
+ * Send feedback email.
+ *
+ * @param array $feedback feedback data.
+ *
+ * @return void
+ */
+ public static function send_email($feedback)
+ {
+ /**
+ * Send email to voter.
+ */
+ self::send_email_voter($feedback);
+
+ if ('on' !== get_option('helpful_feedback_send_email')) {
+ return;
+ }
+
+ $post = get_post($feedback['post_id']);
+
+ if (!$post) {
+ return;
+ }
+
+ $feedback['fields'] = maybe_unserialize($feedback['fields']);
+
+ /* tags */
+ $tags = [
+ '{type}' => $type,
+ '{name}' => isset($feedback['fields']['name']) ? $feedback['fields']['name'] : '',
+ '{email}' => isset($feedback['fields']['email']) ? $feedback['fields']['email'] : '',
+ '{message}' => $feedback['message'],
+ '{post_url}' => get_permalink($post),
+ '{post_title}' => $post->post_title,
+ '{blog_name}' => get_bloginfo('name'),
+ '{blog_url}' => site_url(),
+ ];
+
+ $tags = apply_filters('helpful_feedback_email_tags', $tags);
+
+ /* email subject */
+ $subject = get_option('helpful_feedback_subject');
+ $subject = str_replace(array_keys($tags), array_values($tags), $subject);
+
+ /* unserialize feedback fields */
+ $feedback['fields'] = maybe_unserialize($feedback['fields']);
+
+ $type = esc_html__('positive', 'helpful');
+ if (1 === $feedback['contra']) {
+ $type = esc_html__('negative', 'helpful');
+ }
+
+ /* body */
+ $body = get_option('helpful_feedback_email_content');
+ $body = str_replace(array_keys($tags), array_values($tags), $body);
+
+ /* receivers by post meta */
+ $post_receivers = [];
+
+ if (get_post_meta($post->ID, 'helpful_feedback_receivers', true)) {
+ $post_receivers = get_post_meta($post->ID, 'helpful_feedback_receivers', true);
+ $post_receivers = helpful_trim_all($post_receivers);
+ $post_receivers = explode(',', $post_receivers);
+ }
+
+ /* receivers by helpful options */
+ $helpful_receivers = [];
+
+ if (get_option('helpful_feedback_receivers')) {
+ $helpful_receivers = get_option('helpful_feedback_receivers');
+ $helpful_receivers = helpful_trim_all($helpful_receivers);
+ $helpful_receivers = explode(',', $helpful_receivers);
+ }
+
+ $receivers = array_merge($helpful_receivers, $post_receivers);
+ $receivers = array_unique($receivers);
+
+ /* receivers array is empty */
+ if (empty($receivers)) {
+ return;
+ }
+
+ /* email headers */
+ $headers = [];
+ $headers[] = 'Content-Type: text/html; charset=UTF-8';
+
+ if ($feedback['fields']['email']) {
+ $headers[] = sprintf('Reply-To: %s', $feedback['fields']['email']);
+ }
+
+ /* filters */
+ $receivers = apply_filters('helpful_feedback_email_receivers', $receivers, $feedback);
+ $subject = apply_filters('helpful_feedback_email_subject', $subject, $feedback);
+ $body = apply_filters('helpful_feedback_email_body', $body, $feedback);
+ $headers = apply_filters('helpful_feedback_email_headers', $headers, $feedback);
+
+ $response = wp_mail($receivers, $subject, $body, $headers);
+
+ if (false === $response) {
+ $message = 'Helpful Warning: Email could not be sent in %s on line %d.';
+ helpful_error_log(sprintf($message, __FILE__, __LINE__));
+ }
+ }
+
+ /**
+ * Send feedback email to voter.
+ *
+ * @param array $feedback feedback data.
+ *
+ * @return void
+ */
+ public static function send_email_voter($feedback)
+ {
+ if ('on' !== get_option('helpful_feedback_send_email_voter')) {
+ return;
+ }
+
+ $post = get_post($feedback['post_id']);
+
+ if (!$post) {
+ return;
+ }
+
+ $feedback['fields'] = maybe_unserialize($feedback['fields']);
+
+ /* tags */
+ $tags = [
+ '{type}' => $type,
+ '{name}' => isset($feedback['fields']['name']) ? $feedback['fields']['name'] : '',
+ '{email}' => isset($feedback['fields']['email']) ? $feedback['fields']['email'] : '',
+ '{message}' => $feedback['message'],
+ '{post_url}' => get_permalink($post),
+ '{post_title}' => $post->post_title,
+ '{blog_name}' => get_bloginfo('name'),
+ '{blog_url}' => site_url(),
+ ];
+
+ $tags = apply_filters('helpful_feedback_email_tags', $tags);
+
+ /* subject */
+ $subject = get_option('helpful_feedback_subject_voter');
+ $subject = str_replace(array_keys($tags), array_values($tags), $subject);
+
+ /* unserialize feedback fields */
+ $feedback['fields'] = maybe_unserialize($feedback['fields']);
+
+ $type = esc_html__('positive', 'helpful');
+ if (1 === $feedback['contra']) {
+ $type = esc_html__('negative', 'helpful');
+ }
+
+ /* Body */
+ $body = get_option('helpful_feedback_email_content_voter');
+ $body = str_replace(array_keys($tags), array_values($tags), $body);
+
+ /* Receivers */
+ $receivers = [];
+
+ if (isset($feedback['fields']['email']) && '' !== trim($feedback['fields']['email'])) {
+ $receivers[] = sanitize_email($feedback['fields']['email']);
+ }
+
+ /* receivers array is empty */
+ if (empty($receivers)) {
+ return;
+ }
+
+ /* email headers */
+ $headers = [];
+ $headers[] = 'Content-Type: text/html; charset=UTF-8';
+
+ /* filters */
+ $receivers = apply_filters('helpful_feedback_email_receivers_voter', $receivers, $feedback);
+ $subject = apply_filters('helpful_feedback_email_subject_voter', $subject, $feedback);
+ $body = apply_filters('helpful_feedback_email_body_voter', $body, $feedback);
+ $headers = apply_filters('helpful_feedback_email_headers_voter', $headers, $feedback);
+
+ $response = wp_mail($receivers, $subject, $body, $headers);
+
+ if (false === $response) {
+ $message = 'Helpful Warning: Email could not be sent in %s on line %d.';
+ helpful_error_log(sprintf($message, __FILE__, __LINE__));
+ }
+ }
+
+ /**
+ * Outputs the amount of feedback for a post.
+ *
+ * @global $wpdb
+ *
+ * @param int|null $post_id
+ *
+ * @return int
+ */
+ public static function get_feedback_count($post_id = null)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful_feedback';
+
+ if (null === $post_id || !is_numeric($post_id)) {
+ $sql = "SELECT COUNT(*) FROM $helpful";
+ return $wpdb->get_var($sql);
+ }
+
+ $post_id = intval($post_id);
+ $sql = "SELECT COUNT(*) FROM $helpful WHERE post_id = %d";
+
+ $count = $wpdb->get_var($wpdb->prepare($sql, $post_id));
+
+ return apply_filters('helpful_pre_get_feedback_count', $count, $post_id);
+ }
+
+ /**
+ * Render after messages or feedback form, after vote.
+ * Checks if custom template exists.
+ *
+ * @param integer $post_id post id.
+ * @param bool $show_feedback show feedback form anyway.
+ *
+ * @return string
+ */
+ public static function after_vote($post_id, $show_feedback = false)
+ {
+ // $feedback_text = esc_html_x( 'Thank you very much. Please write us your opinion, so that we can improve ourselves.', 'form user note', 'helpful' );
+
+ $hide_feedback = get_post_meta($post_id, 'helpful_hide_feedback_on_post', true);
+ $hide_feedback = ('on' === $hide_feedback) ? true : false;
+
+ if (Helper::is_feedback_disabled()) {
+ $hide_feedback = true;
+ }
+
+ $user_id = User::get_user();
+ $type = User::get_user_vote_status($user_id, $post_id);
+
+ $accepted_types = ['pro', 'contra', 'none'];
+
+ if (isset($_REQUEST['value']) && 'none' === $type) {
+ if (in_array($_REQUEST['value'], $accepted_types)) {
+ $type = sanitize_text_field(wp_unslash($_REQUEST['value']));
+ }
+ }
+
+ if (true === $show_feedback) {
+ $type = 'none';
+ $feedback_text = get_option('helpful_feedback_message_voted');
+ $feedback_text = apply_filters('helpful_pre_feedback_message_voted', $feedback_text, $post_id);
+ }
+
+ if ('pro' === $type) {
+ $feedback_text = get_option('helpful_feedback_message_pro');
+
+ if (false === $show_feedback) {
+ if (!get_option('helpful_feedback_after_pro') || true === $hide_feedback) {
+ $content = do_shortcode(get_option('helpful_after_pro'));
+
+ if (get_post_meta($post_id, 'helpful_after_pro', true)) {
+ $content = do_shortcode(get_post_meta($post_id, 'helpful_after_pro', true));
+ }
+
+ return apply_filters('helpful_pre_after_pro', $content, $post_id);
+ }
+ }
+ }
+
+ if ('contra' === $type) {
+ $feedback_text = get_option('helpful_feedback_message_contra');
+
+ if (false === $show_feedback) {
+ if (!get_option('helpful_feedback_after_contra') || true === $hide_feedback) {
+ $content = do_shortcode(get_option('helpful_after_contra'));
+
+ if (get_post_meta($post_id, 'helpful_after_contra', true)) {
+ $content = do_shortcode(get_post_meta($post_id, 'helpful_after_contra', true));
+ }
+
+ return apply_filters('helpful_pre_after_contra', $content, $post_id);
+ }
+ }
+ }
+
+ if ('none' === $type) {
+ if (!get_option('helpful_feedback_after_pro') && !get_option('helpful_feedback_after_contra') && false === $show_feedback) {
+ $content = do_shortcode(get_option('helpful_after_fallback'));
+
+ if (get_post_meta($post_id, 'helpful_after_fallback', true)) {
+ $content = do_shortcode(get_post_meta($post_id, 'helpful_after_fallback', true));
+ }
+
+ return apply_filters('helpful_pre_after_fallback', $content, $post_id);
+ }
+ }
+
+ if (isset($feedback_text) && '' === trim($feedback_text)) {
+ $feedback_text = false;
+ }
+
+ if (!isset($feedback_text)) {
+ $feedback_text = false;
+ }
+
+ ob_start();
+
+ $default_template = HELPFUL_PATH . 'templates/feedback.php';
+ $custom_template = locate_template('helpful/feedback.php');
+
+ do_action('helpful_before_feedback_form');
+
+ echo '';
+
+ do_action('helpful_after_feedback_form');
+
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ if (false !== $show_feedback) {
+ $content = '';
+ }
+
+ return apply_filters('helpful_pre_feedback', $content, $post_id);
+ }
+
+ /**
+ * Get feedback email content.
+ *
+ * @return string
+ */
+ public static function get_email_content()
+ {
+ $file = HELPFUL_PATH . 'templates/feedback-email.php';
+
+ if (!file_exists($file)) {
+ return '';
+ }
+
+ ob_start();
+ require_once $file;
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ return apply_filters('helpful_pre_get_email_content', $content);
+ }
+
+ /**
+ * Get feedback email content for voters.
+ *
+ * @return string
+ */
+ public static function get_email_content_voter()
+ {
+ $file = HELPFUL_PATH . 'templates/feedback-email-voter.php';
+
+ if (!file_exists($file)) {
+ return '';
+ }
+
+ ob_start();
+ require_once $file;
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ return apply_filters('helpful_pre_get_email_content_voter', $content);
+ }
+}
diff --git a/core/helpers/class-optimize.php b/core/helpers/class-optimize.php
index 84a1a9d..e6d0cdf 100644
--- a/core/helpers/class-optimize.php
+++ b/core/helpers/class-optimize.php
@@ -1,312 +1,311 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
use Helpful\Core\Helper;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Optimize
{
- /**
- * Executes the methods and returns a response array.
- *
- * @return array
- */
- public static function optimize_plugin()
- {
- delete_option( 'helpful_is_installed' );
- delete_option( 'helpful_feedback_is_installed' );
-
- $response = [];
- $response = array_merge( $response, Values::table_exists( 'helpful' ) );
- $response = array_merge( $response, Values::table_exists( 'helpful_feedback' ) );
- $response = array_merge( $response, self::optimize_tables() );
- $response = array_merge( $response, self::move_feedback() );
- $response = array_merge( $response, self::remove_incorrect_entries() );
- $response = array_merge( $response, self::fix_incorrect_feedback() );
- $response = array_merge( $response, self::clear_cache() );
- $response = array_merge( $response, self::update_metas() );
-
- array_filter( $response );
-
- return $response;
- }
-
- /**
- * Optimizes database tables.
- *
- * Optimize tables `helpful` and `helpful_feedback`.
- * Uses the SQL-Command `OPTIMIZE` for optimization.
- *
- * @global $wpdb
- *
- * @return array responses
- */
- private static function optimize_tables()
- {
- global $wpdb;
- $response = [];
-
- /* OPTIMIZE helpful table */
- $table_name = $wpdb->prefix . 'helpful';
- if ( $wpdb->query( "OPTIMIZE TABLE $table_name" ) ) {
- /* translators: %s = table name */
- $response[] = sprintf( esc_html_x( "Table '%s' has been optimized.", 'maintenance response', 'helpful' ), $table_name );
- }
-
- /* OPTIMIZE helpful_feedback table */
- $table_name = $wpdb->prefix . 'helpful_feedback';
- if ( $wpdb->query( "OPTIMIZE TABLE $table_name" ) ) {
- /* translators: %s = table name */
- $response[] = sprintf( esc_html_x( "Table '%s' has been optimized.", 'maintenance response', 'helpful' ), $table_name );
- }
-
- return $response;
- }
-
- /**
- * Moves feedback from post type to database table.
- *
- * Moves the feedback from post type `helpful_feedback` to the database
- * table `helpful_feedback` and returns a response array.
- *
- * @global $wpdb
- *
- * @return array response
- */
- private static function move_feedback()
- {
- global $wpdb;
-
- $response = [];
-
- $args = [
- 'post_type' => 'helpful_feedback',
- 'posts_per_page' => -1,
- 'fields' => 'ids',
- ];
-
- $query = new \WP_Query( $args );
-
- if ( ! $query->found_posts ) {
- return [];
- }
-
- $count = $query->found_posts;
-
- foreach ( $query->posts as $post_id ) :
-
- $type = get_post_meta( $post_id, 'type', true );
-
- $fields = [
- 'browser' => get_post_meta( $post_id, 'browser', true ),
- 'platform' => get_post_meta( $post_id, 'platform', true ),
- 'language' => get_post_meta( $post_id, 'language', true ),
- ];
-
- $data = [
- 'time' => get_the_time( 'Y-m-d H:i:s', $post_id ),
- 'user' => 0,
- 'pro' => ( 'Pro' === $type ? 1 : 0 ),
- 'contra' => ( 'Contra' === $type ? 1 : 0 ),
- 'post_id' => get_post_meta( $post_id, 'post_id', true ),
- 'message' => get_post_field( 'post_content', $post_id ),
- 'fields' => maybe_serialize( $fields ),
- ];
-
- /* insert post into database */
- $table_name = $wpdb->prefix . 'helpful_feedback';
- $wpdb->insert( $table_name, $data );
-
- /* delete post */
- if ( $wpdb->insert_id ) {
- wp_delete_post( $post_id, true );
- }
- endforeach;
-
- /* translators: %d = amount of entries */
- $response[] = sprintf( esc_html_x( '%d Feedback entries moved in the database', 'maintenance response', 'helpful' ), $count );
-
- return $response;
- }
-
- /**
- * Removes incorrect entries from database tables.
- *
- * Remove incorrect entries from database tables `helpful`
- * and `helpful_feedback`. All entries that do not have a
- * user saved are affected.
- *
- * @global $wpdb
- *
- * @return array responses
- */
- private static function remove_incorrect_entries()
- {
- global $wpdb;
-
- $response = [];
-
- /* Remove incorrect entries from 'helpful' table */
- $table_name = $wpdb->prefix . 'helpful';
- $query = $wpdb->prepare( "SELECT id, user FROM $table_name WHERE user = %s", '' );
- $items = $wpdb->get_results( $query );
-
- if ( $items ) {
- foreach ( $items as $item ) :
- $wpdb->delete( $table_name, [ 'id' => $item->id ] );
- endforeach;
-
- $count = count( $items );
- $response[] = sprintf(
- /* translators: %1$d = amount of entries %2$s = table name */
- esc_html_x( '%1$d incorrect entries have been removed from table "%2$s"', 'maintenance response', 'helpful' ),
- $count,
- $table_name
- );
- }
-
- /* Remove incorrect entries from 'helpful_feedback' table */
- $table_name = $wpdb->prefix . 'helpful_feedback';
- $query = $wpdb->prepare( "SELECT id, user FROM $table_name WHERE user = %s", '' );
- $items = $wpdb->get_results( $query );
-
- if ( $items ) {
- foreach ( $items as $item ) {
- $wpdb->delete( $table_name, [ 'id' => $item->id ] );
- }
-
- $count = count( $items );
- $response[] = sprintf(
- /* translators: %1$d = amount of entries %2$s = table name */
- esc_html_x( '%1$d incorrect entries have been removed from table "%2$s"', 'maintenance response', 'helpful' ),
- $count,
- $table_name
- );
- }
-
- return $response;
- }
-
- /**
- * Feedback text is cleaned up and slashes removed.
- *
- * @global $wpdb
- *
- * @return array
- */
- public static function fix_incorrect_feedback()
- {
- global $wpdb;
-
- $response = [];
- $table_name = $wpdb->prefix . 'helpful_feedback';
- $query = "SELECT id, message FROM $table_name";
- $items = $wpdb->get_results( $query );
- $fixes = [];
-
- if ( ! empty( $items ) ) {
- foreach ( $items as $item ) :
- if ( false !== strpos( $item->message, '\\' ) ) {
- $fixes[] = $item->id;
- $message = sanitize_textarea_field( wp_strip_all_tags( $item->message ) );
- $message = stripslashes( $message );
- $wpdb->update( $table_name, [ 'message' => $message ], [ 'id' => $item->id ] );
- }
- endforeach;
- }
-
- if ( is_array( $fixes ) && ! empty( $fixes ) ) {
- $count = count( $fixes );
- $response[] = sprintf(
- /* translators: %1$d = amount of entries %2$s = table name */
- esc_html_x( '%1$d incorrect entries have been fixed from table "%2$s".', 'maintenance response', 'helpful' ),
- $count,
- $table_name
- );
- }
-
- return $response;
- }
-
- /**
- * Feedback text is cleaned up and slashes removed.
- *
- * @return array
- */
- public static function clear_cache()
- {
-
- $response = [
- esc_html_x( 'The cache for Helpful has been cleared.', 'maintenance response', 'helpful' ),
- ];
-
- wp_cache_delete( 'stats_total', 'helpful' );
- wp_cache_delete( 'stats_total_pro', 'helpful' );
- wp_cache_delete( 'stats_total_contra', 'helpful' );
-
- /**
- * Deletes all transients related to Helpful.
- */
- $count = 3;
- $count += Cache::clear_cache();
-
- return $response;
- }
-
- /**
- * Update meta fields
- *
- * @return array
- */
- public static function update_metas()
- {
- $response = [];
- $post_types = get_option( 'helpful_post_types' );
-
- $args = [
- 'post_type' => $post_types,
- 'post_status' => 'any',
- 'fields' => 'ids',
- ];
-
- $query = new \WP_Query( $args );
-
- if ( $query->found_posts ) {
- foreach ( $query->posts as $post_id ) :
-
- $percentages = false;
-
- if ( get_option( 'helpful_percentages' ) ) {
- $percentages = true;
- }
-
- $pro = Stats::get_pro( $post_id, $percentages );
- $contra = Stats::get_contra( $post_id, $percentages );
-
- update_post_meta( $post_id, 'helpful-pro', $pro );
- update_post_meta( $post_id, 'helpful-contra', $contra );
-
- endforeach;
- }
-
- $count = $query->found_posts;
- $response[] = sprintf(
- /* translators: %1$d = amount of entries */
- esc_html_x( '%1$d post meta fields have been updated.', 'maintenance response', 'helpful' ),
- $count
- );
-
- return $response;
- }
-}
\ No newline at end of file
+ /**
+ * Executes the methods and returns a response array.
+ *
+ * @return array
+ */
+ public static function optimize_plugin()
+ {
+ delete_option('helpful_is_installed');
+ delete_option('helpful_feedback_is_installed');
+
+ $response = [];
+ $response = array_merge($response, Values::table_exists('helpful'));
+ $response = array_merge($response, Values::table_exists('helpful_feedback'));
+ $response = array_merge($response, self::optimize_tables());
+ $response = array_merge($response, self::move_feedback());
+ $response = array_merge($response, self::remove_incorrect_entries());
+ $response = array_merge($response, self::fix_incorrect_feedback());
+ $response = array_merge($response, self::clear_cache());
+ $response = array_merge($response, self::update_metas());
+
+ array_filter($response);
+
+ return $response;
+ }
+
+ /**
+ * Optimizes database tables.
+ *
+ * Optimize tables `helpful` and `helpful_feedback`.
+ * Uses the SQL-Command `OPTIMIZE` for optimization.
+ *
+ * @global $wpdb
+ *
+ * @return array responses
+ */
+ private static function optimize_tables()
+ {
+ global $wpdb;
+ $response = [];
+
+ /* OPTIMIZE helpful table */
+ $table_name = $wpdb->prefix . 'helpful';
+ if ($wpdb->query("OPTIMIZE TABLE $table_name")) {
+ /* translators: %s = table name */
+ $response[] = sprintf(esc_html_x("Table '%s' has been optimized.", 'maintenance response', 'helpful'), $table_name);
+ }
+
+ /* OPTIMIZE helpful_feedback table */
+ $table_name = $wpdb->prefix . 'helpful_feedback';
+ if ($wpdb->query("OPTIMIZE TABLE $table_name")) {
+ /* translators: %s = table name */
+ $response[] = sprintf(esc_html_x("Table '%s' has been optimized.", 'maintenance response', 'helpful'), $table_name);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Moves feedback from post type to database table.
+ *
+ * Moves the feedback from post type `helpful_feedback` to the database
+ * table `helpful_feedback` and returns a response array.
+ *
+ * @global $wpdb
+ *
+ * @return array response
+ */
+ private static function move_feedback()
+ {
+ global $wpdb;
+
+ $response = [];
+
+ $args = [
+ 'post_type' => 'helpful_feedback',
+ 'posts_per_page' => -1,
+ 'fields' => 'ids',
+ ];
+
+ $query = new \WP_Query($args);
+
+ if (!$query->found_posts) {
+ return [];
+ }
+
+ $count = $query->found_posts;
+
+ foreach ($query->posts as $post_id):
+
+ $type = get_post_meta($post_id, 'type', true);
+
+ $fields = [
+ 'browser' => get_post_meta($post_id, 'browser', true),
+ 'platform' => get_post_meta($post_id, 'platform', true),
+ 'language' => get_post_meta($post_id, 'language', true),
+ ];
+
+ $data = [
+ 'time' => get_the_time('Y-m-d H:i:s', $post_id),
+ 'user' => 0,
+ 'pro' => ('Pro' === $type ? 1 : 0),
+ 'contra' => ('Contra' === $type ? 1 : 0),
+ 'post_id' => get_post_meta($post_id, 'post_id', true),
+ 'message' => get_post_field('post_content', $post_id),
+ 'fields' => maybe_serialize($fields),
+ ];
+
+ /* insert post into database */
+ $table_name = $wpdb->prefix . 'helpful_feedback';
+ $wpdb->insert($table_name, $data);
+
+ /* delete post */
+ if ($wpdb->insert_id) {
+ wp_delete_post($post_id, true);
+ }
+ endforeach;
+
+ /* translators: %d = amount of entries */
+ $response[] = sprintf(esc_html_x('%d Feedback entries moved in the database', 'maintenance response', 'helpful'), $count);
+
+ return $response;
+ }
+
+ /**
+ * Removes incorrect entries from database tables.
+ *
+ * Remove incorrect entries from database tables `helpful`
+ * and `helpful_feedback`. All entries that do not have a
+ * user saved are affected.
+ *
+ * @global $wpdb
+ *
+ * @return array responses
+ */
+ private static function remove_incorrect_entries()
+ {
+ global $wpdb;
+
+ $response = [];
+
+ /* Remove incorrect entries from 'helpful' table */
+ $table_name = $wpdb->prefix . 'helpful';
+ $query = $wpdb->prepare("SELECT id, user FROM $table_name WHERE user = %s", '');
+ $items = $wpdb->get_results($query);
+
+ if ($items) {
+ foreach ($items as $item):
+ $wpdb->delete($table_name, ['id' => $item->id]);
+ endforeach;
+
+ $count = count($items);
+ $response[] = sprintf(
+ /* translators: %1$d = amount of entries %2$s = table name */
+ esc_html_x('%1$d incorrect entries have been removed from table "%2$s"', 'maintenance response', 'helpful'),
+ $count,
+ $table_name
+ );
+ }
+
+ /* Remove incorrect entries from 'helpful_feedback' table */
+ $table_name = $wpdb->prefix . 'helpful_feedback';
+ $query = $wpdb->prepare("SELECT id, user FROM $table_name WHERE user = %s", '');
+ $items = $wpdb->get_results($query);
+
+ if ($items) {
+ foreach ($items as $item) {
+ $wpdb->delete($table_name, ['id' => $item->id]);
+ }
+
+ $count = count($items);
+ $response[] = sprintf(
+ /* translators: %1$d = amount of entries %2$s = table name */
+ esc_html_x('%1$d incorrect entries have been removed from table "%2$s"', 'maintenance response', 'helpful'),
+ $count,
+ $table_name
+ );
+ }
+
+ return $response;
+ }
+
+ /**
+ * Feedback text is cleaned up and slashes removed.
+ *
+ * @global $wpdb
+ *
+ * @return array
+ */
+ public static function fix_incorrect_feedback()
+ {
+ global $wpdb;
+
+ $response = [];
+ $table_name = $wpdb->prefix . 'helpful_feedback';
+ $query = "SELECT id, message FROM $table_name";
+ $items = $wpdb->get_results($query);
+ $fixes = [];
+
+ if (!empty($items)) {
+ foreach ($items as $item):
+ if (false !== strpos($item->message, '\\')) {
+ $fixes[] = $item->id;
+ $message = sanitize_textarea_field(wp_strip_all_tags($item->message));
+ $message = stripslashes($message);
+ $wpdb->update($table_name, ['message' => $message], ['id' => $item->id]);
+ }
+ endforeach;
+ }
+
+ if (is_array($fixes) && !empty($fixes)) {
+ $count = count($fixes);
+ $response[] = sprintf(
+ /* translators: %1$d = amount of entries %2$s = table name */
+ esc_html_x('%1$d incorrect entries have been fixed from table "%2$s".', 'maintenance response', 'helpful'),
+ $count,
+ $table_name
+ );
+ }
+
+ return $response;
+ }
+
+ /**
+ * Feedback text is cleaned up and slashes removed.
+ *
+ * @return array
+ */
+ public static function clear_cache()
+ {
+
+ $response = [
+ esc_html_x('The cache for Helpful has been cleared.', 'maintenance response', 'helpful'),
+ ];
+
+ wp_cache_delete('stats_total', 'helpful');
+ wp_cache_delete('stats_total_pro', 'helpful');
+ wp_cache_delete('stats_total_contra', 'helpful');
+
+ /**
+ * Deletes all transients related to Helpful.
+ */
+ $count = 3;
+ $count += Cache::clear_cache();
+
+ return $response;
+ }
+
+ /**
+ * Update meta fields
+ *
+ * @return array
+ */
+ public static function update_metas()
+ {
+ $response = [];
+ $post_types = get_option('helpful_post_types');
+
+ $args = [
+ 'post_type' => $post_types,
+ 'post_status' => 'any',
+ 'fields' => 'ids',
+ ];
+
+ $query = new \WP_Query($args);
+
+ if ($query->found_posts) {
+ foreach ($query->posts as $post_id):
+
+ $percentages = false;
+
+ if (get_option('helpful_percentages')) {
+ $percentages = true;
+ }
+
+ $pro = Stats::get_pro($post_id, $percentages);
+ $contra = Stats::get_contra($post_id, $percentages);
+
+ update_post_meta($post_id, 'helpful-pro', $pro);
+ update_post_meta($post_id, 'helpful-contra', $contra);
+
+ endforeach;
+ }
+
+ $count = $query->found_posts;
+ $response[] = sprintf(
+ /* translators: %1$d = amount of entries */
+ esc_html_x('%1$d post meta fields have been updated.', 'maintenance response', 'helpful'),
+ $count
+ );
+
+ return $response;
+ }
+}
diff --git a/core/helpers/class-stats.php b/core/helpers/class-stats.php
index fe05709..0094598 100644
--- a/core/helpers/class-stats.php
+++ b/core/helpers/class-stats.php
@@ -1,1193 +1,1192 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
use Helpful\Core\Helper;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Stats
{
- /**
- * Helpful color helper
- *
- * @var string
- */
- public static $green = '#88c057';
-
- /**
- * Helpful color helper
- *
- * @var string
- */
- public static $red = '#ed7161';
-
- /**
- * Todo: Helper for wp_date since WorddPress 5.4.
- * Todo: Currently there is a bug with the time zone here.
- *
- * @url https://developer.wordpress.org/reference/functions/date_i18n/
- *
- * @param string $format Format to display the date.
- * @param int|boolean $timestamp_with_offset Whether to use GMT timezone. Only applies if timestamp is not provided.
- * @param boolean $gmt Whether to use GMT timezone. Only applies if timestamp is not provided.
- * @return string The date, translated if locale specifies it.
- */
- private static function helpful_date( $format, $timestamp_with_offset = false, $gmt = false )
- {
- if ( function_exists( 'wp_date' ) ) {
- return wp_date( $format, $timestamp_with_offset, $gmt );
- } elseif ( function_exists( 'date_i18n' ) ) {
- return date_i18n( $format, $timestamp_with_offset, $gmt );
- } else {
- return date( $format, $timestamp_with_offset );
- }
- }
-
- /**
- * Get amount of pro by post id.
- *
- * @global $wpdb, $post
- *
- * @param int $post_id if null current post id.
- * @param bool $percentages return percentage values on true.
- *
- * @return string
- */
- public static function get_pro( $post_id = null, $percentages = false )
- {
- if ( is_null( $post_id ) ) {
- global $post;
-
- if ( ! isset( $post->ID ) ) {
- return 0;
- }
-
- $post_id = $post->ID;
- }
-
- global $wpdb;
-
- $post_id = absint( $post_id );
- $helpful = $wpdb->prefix . 'helpful';
- $sql = $wpdb->prepare( "SELECT COUNT(*) FROM $helpful WHERE pro = 1 AND post_id = %d", intval( $post_id ) );
-
- $cache_name = 'helpful_pro_' . $post_id;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $var = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $var = $wpdb->get_var( $sql );
- } elseif ( false === $var ) {
- $var = $wpdb->get_var( $sql );
- set_transient( $cache_name, maybe_serialize( $var ), $cache_time );
- }
-
- $var = maybe_unserialize( $var );
-
- if ( false === $percentages ) {
- return $var;
- }
-
- $pro = $var ?: 0;
- $contra = self::get_contra( $post_id );
- $percentage = 0;
-
- if ( 0 !== $pro ) {
- $average = (int) ( $pro - $contra );
- $total = (int) ( $pro + $contra );
- $percentage = ( $pro / $total ) * 100;
- $percentage = round( $percentage, 2 );
- $percentage = number_format( $percentage, 2 );
- }
-
- return str_replace( '.00', '', $percentage );
- }
-
- /**
- * Get contra count by post id.
- *
- * @global $wpdb, $post
- *
- * @param int $post_id if null current post id.
- * @param bool $percentages return percentage values on true.
- *
- * @return string
- */
- public static function get_contra( $post_id = null, $percentages = false )
- {
- if ( is_null( $post_id ) ) {
- global $post, $wpdb;
-
- if ( ! isset( $post->ID ) ) {
- return 0;
- }
-
- $post_id = $post->ID;
- }
-
- global $wpdb;
-
- $post_id = absint( $post_id );
- $helpful = $wpdb->prefix . 'helpful';
- $sql = $wpdb->prepare( "SELECT COUNT(*) FROM $helpful WHERE contra = 1 AND post_id = %d", intval( $post_id ) );
-
- $cache_name = 'helpful_contra_' . $post_id;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $var = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $var = $wpdb->get_var( $sql );
- } elseif ( false === $var ) {
- $var = $wpdb->get_var( $sql );
- set_transient( $cache_name, maybe_serialize( $var ), $cache_time );
- }
-
- $var = maybe_unserialize( $var );
-
- if ( false === $percentages ) {
- return $var;
- }
-
- $contra = $var ?: 0;
- $pro = self::get_pro( $post_id );
- $percentage = 0;
-
- if ( 0 !== $contra ) {
- $average = (int) ( $contra - $pro );
- $total = (int) ( $contra + $pro );
- $percentage = ( $contra / $total ) * 100;
- $percentage = round( $percentage, 2 );
- $percentage = number_format( $percentage, 2 );
- }
-
- return str_replace( '.00', '', $percentage );
- }
-
- /**
- * Get pro count of all posts.
- *
- * @global $wpdb
- *
- * @param bool $percentages return percentage values on true.
- *
- * @return int count
- */
- public static function get_pro_all( $percentages = false )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $sql = "SELECT COUNT(*) FROM $helpful WHERE pro = 1";
-
- $cache_name = 'helpful_pro_all';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $var = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $var = $wpdb->get_var( $sql );
- } elseif ( false === $var ) {
- $var = $wpdb->get_var( $sql );
- set_transient( $cache_name, maybe_serialize( $var ), $cache_time );
- }
-
- $var = maybe_unserialize( $var );
-
- if ( false === $percentages ) {
- return $var;
- }
-
- $pro = $var ?: 0;
- $contra = self::get_contraAll();
- $pro_percent = 0;
-
- if ( is_int( $pro ) && 0 !== $pro && 0 <= $pro ) {
- $pro_percent = ( ( $pro / ( $pro + $contra ) ) * 100 );
- }
-
- $pro_percent = number_format( $pro_percent, 2 );
-
- return (float) str_replace( '.00', '', $pro_percent );
- }
-
- /**
- * Get contra count of all posts.
- *
- * @global $wpdb
- *
- * @param bool $percentages return percentage values on true.
- *
- * @return int count
- */
- public static function get_contra_all( $percentages = false )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $sql = "SELECT COUNT(*) FROM $helpful WHERE contra = 1";
-
- $cache_name = 'helpful_contra_all';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $var = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $var = $wpdb->get_var( $sql );
- } elseif ( false === $var ) {
- $var = $wpdb->get_var( $sql );
- set_transient( $cache_name, maybe_serialize( $var ), $cache_time );
- }
-
- $var = maybe_unserialize( $var );
-
- if ( false === $percentages ) {
- return $var;
- }
-
- $contra = $var ?: 0;
- $pro = self::get_proAll();
- $contra_percent = 0;
-
- if ( is_int( $contra ) && 0 !== $contra && 0 <= $contra ) {
- $contra_percent = ( ( $contra / ( $pro + $contra ) ) * 100 );
- }
-
- $contra_percent = number_format( $contra_percent, 2 );
- return (float) str_replace( '.00', '', $contra_percent );
- }
-
- /**
- * Get years
- *
- * @global $wpdb
- *
- * @return array
- */
- public static function get_years()
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $sql = "SELECT time FROM $helpful ORDER BY time DESC";
-
- $cache_name = 'helpful/stats/years';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [];
- }
-
- $years = [];
-
- foreach ( $results as $result ) :
- $years[] = date( 'Y', strtotime( $result->time ) );
- endforeach;
-
- $years = array_unique( $years );
-
- return $years;
- }
-
- /**
- * Stats for today.
- *
- * @global $wpdb
- *
- * @param int $year response year.
- *
- * @return array
- */
- public static function get_stats_today( $year )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $query = "
+ /**
+ * Helpful color helper
+ *
+ * @var string
+ */
+ public static $green = '#88c057';
+
+ /**
+ * Helpful color helper
+ *
+ * @var string
+ */
+ public static $red = '#ed7161';
+
+ /**
+ * Todo: Helper for wp_date since WorddPress 5.4.
+ * Todo: Currently there is a bug with the time zone here.
+ *
+ * @url https://developer.wordpress.org/reference/functions/date_i18n/
+ *
+ * @param string $format Format to display the date.
+ * @param int|boolean $timestamp_with_offset Whether to use GMT timezone. Only applies if timestamp is not provided.
+ * @param boolean $gmt Whether to use GMT timezone. Only applies if timestamp is not provided.
+ * @return string The date, translated if locale specifies it.
+ */
+ private static function helpful_date($format, $timestamp_with_offset = false, $gmt = false)
+ {
+ if (function_exists('wp_date')) {
+ return wp_date($format, $timestamp_with_offset, $gmt);
+ } elseif (function_exists('date_i18n')) {
+ return date_i18n($format, $timestamp_with_offset, $gmt);
+ } else {
+ return date($format, $timestamp_with_offset);
+ }
+ }
+
+ /**
+ * Get amount of pro by post id.
+ *
+ * @global $wpdb, $post
+ *
+ * @param int $post_id if null current post id.
+ * @param bool $percentages return percentage values on true.
+ *
+ * @return string
+ */
+ public static function get_pro($post_id = null, $percentages = false)
+ {
+ if (is_null($post_id)) {
+ global $post;
+
+ if (!isset($post->ID)) {
+ return 0;
+ }
+
+ $post_id = $post->ID;
+ }
+
+ global $wpdb;
+
+ $post_id = absint($post_id);
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = $wpdb->prepare("SELECT COUNT(*) FROM $helpful WHERE pro = 1 AND post_id = %d", intval($post_id));
+
+ $cache_name = 'helpful_pro_' . $post_id;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $var = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $var = $wpdb->get_var($sql);
+ } elseif (false === $var) {
+ $var = $wpdb->get_var($sql);
+ set_transient($cache_name, maybe_serialize($var), $cache_time);
+ }
+
+ $var = maybe_unserialize($var);
+
+ if (false === $percentages) {
+ return $var;
+ }
+
+ $pro = $var ?: 0;
+ $contra = self::get_contra($post_id);
+ $percentage = 0;
+
+ if (0 !== $pro) {
+ $average = (int) ($pro - $contra);
+ $total = (int) ($pro + $contra);
+ $percentage = ($pro / $total) * 100;
+ $percentage = round($percentage, 2);
+ $percentage = number_format($percentage, 2);
+ }
+
+ return str_replace('.00', '', $percentage);
+ }
+
+ /**
+ * Get contra count by post id.
+ *
+ * @global $wpdb, $post
+ *
+ * @param int $post_id if null current post id.
+ * @param bool $percentages return percentage values on true.
+ *
+ * @return string
+ */
+ public static function get_contra($post_id = null, $percentages = false)
+ {
+ if (is_null($post_id)) {
+ global $post, $wpdb;
+
+ if (!isset($post->ID)) {
+ return 0;
+ }
+
+ $post_id = $post->ID;
+ }
+
+ global $wpdb;
+
+ $post_id = absint($post_id);
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = $wpdb->prepare("SELECT COUNT(*) FROM $helpful WHERE contra = 1 AND post_id = %d", intval($post_id));
+
+ $cache_name = 'helpful_contra_' . $post_id;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $var = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $var = $wpdb->get_var($sql);
+ } elseif (false === $var) {
+ $var = $wpdb->get_var($sql);
+ set_transient($cache_name, maybe_serialize($var), $cache_time);
+ }
+
+ $var = maybe_unserialize($var);
+
+ if (false === $percentages) {
+ return $var;
+ }
+
+ $contra = $var ?: 0;
+ $pro = self::get_pro($post_id);
+ $percentage = 0;
+
+ if (0 !== $contra) {
+ $average = (int) ($contra - $pro);
+ $total = (int) ($contra + $pro);
+ $percentage = ($contra / $total) * 100;
+ $percentage = round($percentage, 2);
+ $percentage = number_format($percentage, 2);
+ }
+
+ return str_replace('.00', '', $percentage);
+ }
+
+ /**
+ * Get pro count of all posts.
+ *
+ * @global $wpdb
+ *
+ * @param bool $percentages return percentage values on true.
+ *
+ * @return int count
+ */
+ public static function get_pro_all($percentages = false)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = "SELECT COUNT(*) FROM $helpful WHERE pro = 1";
+
+ $cache_name = 'helpful_pro_all';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $var = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $var = $wpdb->get_var($sql);
+ } elseif (false === $var) {
+ $var = $wpdb->get_var($sql);
+ set_transient($cache_name, maybe_serialize($var), $cache_time);
+ }
+
+ $var = maybe_unserialize($var);
+
+ if (false === $percentages) {
+ return $var;
+ }
+
+ $pro = $var ?: 0;
+ $contra = self::get_contraAll();
+ $pro_percent = 0;
+
+ if (is_int($pro) && 0 !== $pro && 0 <= $pro) {
+ $pro_percent = (($pro / ($pro + $contra)) * 100);
+ }
+
+ $pro_percent = number_format($pro_percent, 2);
+
+ return (float) str_replace('.00', '', $pro_percent);
+ }
+
+ /**
+ * Get contra count of all posts.
+ *
+ * @global $wpdb
+ *
+ * @param bool $percentages return percentage values on true.
+ *
+ * @return int count
+ */
+ public static function get_contra_all($percentages = false)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = "SELECT COUNT(*) FROM $helpful WHERE contra = 1";
+
+ $cache_name = 'helpful_contra_all';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $var = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $var = $wpdb->get_var($sql);
+ } elseif (false === $var) {
+ $var = $wpdb->get_var($sql);
+ set_transient($cache_name, maybe_serialize($var), $cache_time);
+ }
+
+ $var = maybe_unserialize($var);
+
+ if (false === $percentages) {
+ return $var;
+ }
+
+ $contra = $var ?: 0;
+ $pro = self::get_proAll();
+ $contra_percent = 0;
+
+ if (is_int($contra) && 0 !== $contra && 0 <= $contra) {
+ $contra_percent = (($contra / ($pro + $contra)) * 100);
+ }
+
+ $contra_percent = number_format($contra_percent, 2);
+ return (float) str_replace('.00', '', $contra_percent);
+ }
+
+ /**
+ * Get years
+ *
+ * @global $wpdb
+ *
+ * @return array
+ */
+ public static function get_years()
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = "SELECT time FROM $helpful ORDER BY time DESC";
+
+ $cache_name = 'helpful/stats/years';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [];
+ }
+
+ $years = [];
+
+ foreach ($results as $result):
+ $years[] = date('Y', strtotime($result->time));
+ endforeach;
+
+ $years = array_unique($years);
+
+ return $years;
+ }
+
+ /**
+ * Stats for today.
+ *
+ * @global $wpdb
+ *
+ * @param int $year response year.
+ *
+ * @return array
+ */
+ public static function get_stats_today($year)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $query = "
SELECT pro, contra, time
FROM $helpful
WHERE DAYOFYEAR(time) = DAYOFYEAR(NOW())
AND YEAR(time) = %d
";
- $sql = $wpdb->prepare( $query, intval( $year ) );
-
- $cache_name = 'helpful/stats/today/' . $year;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $pro = wp_list_pluck( $results, 'pro' );
- $pro = array_sum( $pro );
- $contra = wp_list_pluck( $results, 'contra' );
- $contra = array_sum( $contra );
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'doughnut',
- 'data' => [
- 'datasets' => [
- [
- 'data' => [
- absint( $pro ),
- absint( $contra ),
- ],
- 'backgroundColor' => [
- self::$green,
- self::$red,
- ],
- ],
- ],
- 'labels' => [
- __( 'Pro', 'helpful' ),
- __( 'Contra', 'helpful' ),
- ],
- ],
- 'options' => [
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Stats for yesterday.
- *
- * @global $wpdb
- *
- * @param int $year response year.
- *
- * @return array
- */
- public static function get_stats_yesterday( $year )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $query = "
+ $sql = $wpdb->prepare($query, intval($year));
+
+ $cache_name = 'helpful/stats/today/' . $year;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $pro = wp_list_pluck($results, 'pro');
+ $pro = array_sum($pro);
+ $contra = wp_list_pluck($results, 'contra');
+ $contra = array_sum($contra);
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'doughnut',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'data' => [
+ absint($pro),
+ absint($contra),
+ ],
+ 'backgroundColor' => [
+ self::$green,
+ self::$red,
+ ],
+ ],
+ ],
+ 'labels' => [
+ __('Pro', 'helpful'),
+ __('Contra', 'helpful'),
+ ],
+ ],
+ 'options' => [
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Stats for yesterday.
+ *
+ * @global $wpdb
+ *
+ * @param int $year response year.
+ *
+ * @return array
+ */
+ public static function get_stats_yesterday($year)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $query = "
SELECT pro, contra, time
FROM $helpful
WHERE DAYOFYEAR(time) = DAYOFYEAR(SUBDATE(CURDATE(),1))
AND YEAR(time) = %d
";
- $sql = $wpdb->prepare( $query, intval( $year ) );
-
- $cache_name = 'helpful/stats/yesterday/' . $year;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $pro = wp_list_pluck( $results, 'pro' );
- $pro = array_sum( $pro );
- $contra = wp_list_pluck( $results, 'contra' );
- $contra = array_sum( $contra );
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'doughnut',
- 'data' => [
- 'datasets' => [
- [
- 'data' => [
- absint( $pro ),
- absint( $contra ),
- ],
- 'backgroundColor' => [
- self::$green,
- self::$red,
- ],
- ],
- ],
- 'labels' => [
- __( 'Pro', 'helpful' ),
- __( 'Contra', 'helpful' ),
- ],
- ],
- 'options' => [
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Stats for week
- *
- * @global $wpdb
- *
- * @param int $year response year.
- *
- * @return array
- */
- public static function get_stats_week( $year )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $query = "
+ $sql = $wpdb->prepare($query, intval($year));
+
+ $cache_name = 'helpful/stats/yesterday/' . $year;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $pro = wp_list_pluck($results, 'pro');
+ $pro = array_sum($pro);
+ $contra = wp_list_pluck($results, 'contra');
+ $contra = array_sum($contra);
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'doughnut',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'data' => [
+ absint($pro),
+ absint($contra),
+ ],
+ 'backgroundColor' => [
+ self::$green,
+ self::$red,
+ ],
+ ],
+ ],
+ 'labels' => [
+ __('Pro', 'helpful'),
+ __('Contra', 'helpful'),
+ ],
+ ],
+ 'options' => [
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Stats for week
+ *
+ * @global $wpdb
+ *
+ * @param int $year response year.
+ *
+ * @return array
+ */
+ public static function get_stats_week($year)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $query = "
SELECT pro, contra, time
FROM $helpful
WHERE WEEK(time, 1) = WEEK(CURDATE(), 1)
AND YEAR(time) = %d
";
- $sql = $wpdb->prepare( $query, intval( $year ) );
-
- $cache_name = 'helpful/stats/week/' . $year;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $pro = [];
- $contra = [];
- $labels = [];
- $timestamp = strtotime( 'monday this week' );
- $days = 7;
-
- for ( $i = 0; $i < $days; $i++ ) :
- $date = date_i18n( 'Ymd', strtotime( "+$i days", $timestamp ) );
- $day = date_i18n( 'D', strtotime( "+$i days", $timestamp ) );
- $pro[ $date ] = 0;
- $contra[ $date ] = 0;
- $labels[] = $day;
- endfor;
-
- foreach ( $results as $result ) :
- for ( $i = 0; $i < $days; $i++ ) :
- $day = date_i18n( 'Ymd', strtotime( "+$i days", $timestamp ) );
- $date = date_i18n( 'Ymd', strtotime( $result->time ) );
-
- if ( $day === $date ) {
- $pro[ $date ] += $result->pro;
- $contra[ $date ] += $result->contra;
- }
- endfor;
- endforeach;
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'bar',
- 'data' => [
- 'datasets' => [
- [
- 'label' => __( 'Pro', 'helpful' ),
- 'data' => array_values( $pro ),
- 'backgroundColor' => self::$green,
- ],
- [
- 'label' => __( 'Contra', 'helpful' ),
- 'data' => array_values( $contra ),
- 'backgroundColor' => self::$red,
- ],
- ],
- 'labels' => $labels,
- ],
- 'options' => [
- 'scales' => [
- 'xAxes' => [
- [ 'stacked' => true ],
- ],
- 'yAxes' => [
- [ 'stacked' => true ],
- ],
- ],
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Stats for month
- *
- * @global $wpdb
- *
- * @param int $year response year.
- * @param int $month response month.
- *
- * @return array
- */
- public static function get_stats_month( $year, $month = null )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
-
- if ( is_null( $month ) ) {
- $month = date( 'm' );
- } else {
- $month = absint( $month );
- }
-
- $query = "
+ $sql = $wpdb->prepare($query, intval($year));
+
+ $cache_name = 'helpful/stats/week/' . $year;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $pro = [];
+ $contra = [];
+ $labels = [];
+ $timestamp = strtotime('monday this week');
+ $days = 7;
+
+ for ($i = 0; $i < $days; $i++):
+ $date = date_i18n('Ymd', strtotime("+$i days", $timestamp));
+ $day = date_i18n('D', strtotime("+$i days", $timestamp));
+ $pro[$date] = 0;
+ $contra[$date] = 0;
+ $labels[] = $day;
+ endfor;
+
+ foreach ($results as $result):
+ for ($i = 0; $i < $days; $i++):
+ $day = date_i18n('Ymd', strtotime("+$i days", $timestamp));
+ $date = date_i18n('Ymd', strtotime($result->time));
+
+ if ($day === $date) {
+ $pro[$date] += $result->pro;
+ $contra[$date] += $result->contra;
+ }
+ endfor;
+ endforeach;
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'bar',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'label' => __('Pro', 'helpful'),
+ 'data' => array_values($pro),
+ 'backgroundColor' => self::$green,
+ ],
+ [
+ 'label' => __('Contra', 'helpful'),
+ 'data' => array_values($contra),
+ 'backgroundColor' => self::$red,
+ ],
+ ],
+ 'labels' => $labels,
+ ],
+ 'options' => [
+ 'scales' => [
+ 'xAxes' => [
+ ['stacked' => true],
+ ],
+ 'yAxes' => [
+ ['stacked' => true],
+ ],
+ ],
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Stats for month
+ *
+ * @global $wpdb
+ *
+ * @param int $year response year.
+ * @param int $month response month.
+ *
+ * @return array
+ */
+ public static function get_stats_month($year, $month = null)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+
+ if (is_null($month)) {
+ $month = date('m');
+ } else {
+ $month = absint($month);
+ }
+
+ $query = "
SELECT pro, contra, time
FROM $helpful
WHERE MONTH(time) = %d
AND YEAR(time) = %d
";
- $sql = $wpdb->prepare( $query, intval( $month ), intval( $year ) );
-
- $cache_name = 'helpful/stats/month/' . $month . '/' . $year;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $pro = [];
- $contra = [];
- $labels = [];
- $timestamp = strtotime( date( "$year-$month-1" ) );
- $days = date_i18n( 't', $timestamp ) - 1;
-
- for ( $i = 0; $i < $days; $i++ ) :
- $date = date_i18n( 'Ymd', strtotime( "+$i days", $timestamp ) );
- $day = date_i18n( 'j M', strtotime( "+$i days", $timestamp ) );
- $pro[ $date ] = 0;
- $contra[ $date ] = 0;
- $labels[] = $day;
- endfor;
-
- foreach ( $results as $result ) :
- for ( $i = 0; $i < $days; $i++ ) :
- $day = date_i18n( 'Ymd', strtotime( "+$i days", $timestamp ) );
- $date = date_i18n( 'Ymd', strtotime( $result->time ) );
-
- if ( $day === $date ) {
- $pro[ $date ] += $result->pro;
- $contra[ $date ] += $result->contra;
- }
- endfor;
- endforeach;
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'bar',
- 'data' => [
- 'datasets' => [
- [
- 'label' => __( 'Pro', 'helpful' ),
- 'data' => array_values( $pro ),
- 'backgroundColor' => self::$green,
- ],
- [
- 'label' => __( 'Contra', 'helpful' ),
- 'data' => array_values( $contra ),
- 'backgroundColor' => self::$red,
- ],
- ],
- 'labels' => $labels,
- ],
- 'options' => [
- 'scales' => [
- 'xAxes' => [
- [ 'stacked' => true ],
- ],
- 'yAxes' => [
- [ 'stacked' => true ],
- ],
- ],
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Stats for year
- *
- * @global $wpdb
- *
- * @param int $year response year.
- *
- * @return array
- */
- public static function get_stats_year( $year )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $query = "
+ $sql = $wpdb->prepare($query, intval($month), intval($year));
+
+ $cache_name = 'helpful/stats/month/' . $month . '/' . $year;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $pro = [];
+ $contra = [];
+ $labels = [];
+ $timestamp = strtotime(date("$year-$month-1"));
+ $days = date_i18n('t', $timestamp) - 1;
+
+ for ($i = 0; $i < $days; $i++):
+ $date = date_i18n('Ymd', strtotime("+$i days", $timestamp));
+ $day = date_i18n('j M', strtotime("+$i days", $timestamp));
+ $pro[$date] = 0;
+ $contra[$date] = 0;
+ $labels[] = $day;
+ endfor;
+
+ foreach ($results as $result):
+ for ($i = 0; $i < $days; $i++):
+ $day = date_i18n('Ymd', strtotime("+$i days", $timestamp));
+ $date = date_i18n('Ymd', strtotime($result->time));
+
+ if ($day === $date) {
+ $pro[$date] += $result->pro;
+ $contra[$date] += $result->contra;
+ }
+ endfor;
+ endforeach;
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'bar',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'label' => __('Pro', 'helpful'),
+ 'data' => array_values($pro),
+ 'backgroundColor' => self::$green,
+ ],
+ [
+ 'label' => __('Contra', 'helpful'),
+ 'data' => array_values($contra),
+ 'backgroundColor' => self::$red,
+ ],
+ ],
+ 'labels' => $labels,
+ ],
+ 'options' => [
+ 'scales' => [
+ 'xAxes' => [
+ ['stacked' => true],
+ ],
+ 'yAxes' => [
+ ['stacked' => true],
+ ],
+ ],
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Stats for year
+ *
+ * @global $wpdb
+ *
+ * @param int $year response year.
+ *
+ * @return array
+ */
+ public static function get_stats_year($year)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $query = "
SELECT pro, contra, time
FROM $helpful
WHERE YEAR(time) = %d
";
- $sql = $wpdb->prepare( $query, intval( $year ) );
-
- $cache_name = 'helpful/stats/year/' . $year;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $pro = [];
- $contra = [];
- $labels = [];
- $timestamp = strtotime( sprintf( date( '%d-1-1' ), intval( $year ) ) );
- $days = 12;
-
- for ( $i = 0; $i < $days; $i++ ) :
- $month = date_i18n( 'M', strtotime( "+$i months", $timestamp ) );
- $pro[ $month ] = 0;
- $contra [ $month ] = 0;
- $labels[] = $month;
- endfor;
-
- foreach ( $results as $result ) :
- for ( $i = 0; $i < $days; $i++ ) :
- $month = date_i18n( 'M', strtotime( "+$i months", $timestamp ) );
- $m = date_i18n( 'M', strtotime( $result->time ) );
-
- if ( $month === $m ) {
- $pro[ $month ] += $result->pro;
- $contra[ $month ] += $result->contra;
- }
- endfor;
- endforeach;
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'bar',
- 'data' => [
- 'datasets' => [
- [
- 'label' => __( 'Pro', 'helpful' ),
- 'data' => array_values( $pro ),
- 'backgroundColor' => self::$green,
- ],
- [
- 'label' => __( 'Contra', 'helpful' ),
- 'data' => array_values( $contra ),
- 'backgroundColor' => self::$red,
- ],
- ],
- 'labels' => $labels,
- ],
- 'options' => [
- 'scales' => [
- 'xAxes' => [
- [ 'stacked' => true ],
- ],
- 'yAxes' => [
- [ 'stacked' => true ],
- ],
- ],
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Stats by range
- *
- * @global $wpdb
- *
- * @param string $from time string.
- * @param string $to time string.
- *
- * @return array
- */
- public static function get_stats_range( $from, $to )
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $query = "
+ $sql = $wpdb->prepare($query, intval($year));
+
+ $cache_name = 'helpful/stats/year/' . $year;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $pro = [];
+ $contra = [];
+ $labels = [];
+ $timestamp = strtotime(sprintf(date('%d-1-1'), intval($year)));
+ $days = 12;
+
+ for ($i = 0; $i < $days; $i++):
+ $month = date_i18n('M', strtotime("+$i months", $timestamp));
+ $pro[$month] = 0;
+ $contra[$month] = 0;
+ $labels[] = $month;
+ endfor;
+
+ foreach ($results as $result):
+ for ($i = 0; $i < $days; $i++):
+ $month = date_i18n('M', strtotime("+$i months", $timestamp));
+ $m = date_i18n('M', strtotime($result->time));
+
+ if ($month === $m) {
+ $pro[$month] += $result->pro;
+ $contra[$month] += $result->contra;
+ }
+ endfor;
+ endforeach;
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'bar',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'label' => __('Pro', 'helpful'),
+ 'data' => array_values($pro),
+ 'backgroundColor' => self::$green,
+ ],
+ [
+ 'label' => __('Contra', 'helpful'),
+ 'data' => array_values($contra),
+ 'backgroundColor' => self::$red,
+ ],
+ ],
+ 'labels' => $labels,
+ ],
+ 'options' => [
+ 'scales' => [
+ 'xAxes' => [
+ ['stacked' => true],
+ ],
+ 'yAxes' => [
+ ['stacked' => true],
+ ],
+ ],
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Stats by range
+ *
+ * @global $wpdb
+ *
+ * @param string $from time string.
+ * @param string $to time string.
+ *
+ * @return array
+ */
+ public static function get_stats_range($from, $to)
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $query = "
SELECT pro, contra, time
FROM $helpful
WHERE DATE(time) >= DATE(%s)
AND DATE(time) <= DATE(%s)
";
- $sql = $wpdb->prepare( $query, $from, $to );
-
- $cache_name = 'helpful/stats/range/' . $from . '/' . $to;
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $from_date = new \DateTime( $from );
- $to_date = new \DateTime( $to );
- $diff = $from_date->diff( $to_date );
- $pro = [];
- $contra = [];
- $labels = [];
- $timestamp = strtotime( $from );
- $limit = ( $diff->format( '%a' ) + 1 );
-
- for ( $i = 0; $i < $limit; $i++ ) :
- $date = date_i18n( 'Ymd', strtotime( "+$i days", $timestamp ) );
- $day = date_i18n( 'j M', strtotime( "+$i days", $timestamp ) );
- $pro[ $date ] = 0;
- $contra[ $date ] = 0;
- $labels[] = $day;
- endfor;
-
- foreach ( $results as $result ) {
- $date = date_i18n( 'Ymd', strtotime( $result->time ) );
- $pro[ $date ] += (int) $result->pro;
- $contra[ $date ] += (int) $result->contra;
- }
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'bar',
- 'data' => [
- 'datasets' => [
- [
- 'label' => __( 'Pro', 'helpful' ),
- 'data' => array_values( $pro ),
- 'backgroundColor' => self::$green,
- ],
- [
- 'label' => __( 'Contra', 'helpful' ),
- 'data' => array_values( $contra ),
- 'backgroundColor' => self::$red,
- ],
- ],
- 'labels' => $labels,
- ],
- 'options' => [
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Stats for total
- *
- * @global $wpdb
- *
- * @return array
- */
- public static function get_stats_total()
- {
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $sql = "SELECT pro, contra, time FROM $helpful";
-
- $cache_name = 'helpful/stats/total';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( ! $results ) {
- return [
- 'status' => 'error',
- 'message' => __( 'No entries found', 'helpful' ),
- ];
- }
-
- $pro = wp_list_pluck( $results, 'pro' );
- $pro = array_sum( $pro );
-
- $contra = wp_list_pluck( $results, 'contra' );
- $contra = array_sum( $contra );
-
- /* Response for ChartJS */
- $response = [
- 'type' => 'doughnut',
- 'data' => [
- 'datasets' => [
- [
- 'data' => [
- absint( $pro ),
- absint( $contra ),
- ],
- 'backgroundColor' => [
- self::$green,
- self::$red,
- ],
- ],
- ],
- 'labels' => [
- __( 'Pro', 'helpful' ),
- __( 'Contra', 'helpful' ),
- ],
- ],
- 'options' => [
- 'legend' => [
- 'position' => 'bottom',
- ],
- ],
- ];
-
- return $response;
- }
-
- /**
- * Get most helpful posts.
- *
- * @param int $limit posts per page.
- * @param string|array $post_type
- *
- * @return array
- */
- public static function get_most_helpful( $limit = null, $post_type = null )
- {
- if ( is_null( $limit ) ) {
- $limit = intval( get_option( 'helpful_widget_amount' ) );
- } else {
- $limit = intval( $limit );
- }
-
- if ( is_null($post_type)) {
- $post_type = get_option( 'helpful_post_types' );
- }
-
- $args = [
- 'post_type' => $post_type,
- 'post_status' => 'any',
- 'posts_per_page' => -1,
- 'fields' => 'ids',
- ];
-
- $cache_name = 'helpful_most_helpful';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $query = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $query = new \WP_Query( $args );
- } elseif ( false === $query ) {
- $query = new \WP_Query( $args );
- set_transient( $cache_name, maybe_serialize( $query ), $cache_time );
- }
-
- $query = maybe_unserialize( $query );
- $posts = [];
-
- if ( $query->found_posts ) {
- foreach ( $query->posts as $post_id ) :
- $pro = self::get_pro( $post_id ) ? self::get_pro( $post_id ) : 0;
- $contra = self::get_contra( $post_id ) ? self::get_contra( $post_id ) : 0;
- $posts[ $post_id ] = (int) ( $pro - $contra );
- endforeach;
-
- if ( 1 < count( $posts ) ) {
-
- arsort( $posts );
-
- $results = [];
- $posts = array_slice( $posts, 0, $limit, true );
-
- foreach ( $posts as $post_id => $value ) :
- if ( 0 === $value ) {
- continue;
- }
-
- $data = self::get_single_post_stats( $post_id );
- $results[] = [
- 'ID' => $data['ID'],
- 'url' => $data['permalink'],
- 'name' => $data['title'],
- 'pro' => $data['pro']['value'],
- 'contra' => $data['contra']['value'],
- 'percentage' => $data['helpful'],
- 'time' => sprintf(
- /* translators: %s time difference */
- __( 'Published %s ago', 'helpful' ),
- human_time_diff( $data['time']['timestamp'], date_i18n( 'U' ) )
- ),
- ];
- endforeach;
- }
- }
-
- if ( is_array( $results ) ) {
- usort( $results, function( $a, $b ) {
- return $b['percentage'] - $a['percentage'];
- } );
-
- $results = array_filter( $results );
- }
-
- return $results;
- }
-
- /**
- * Get least helpful posts.
- *
- * @param int $limit posts per page.
- * @param string|array $post_type
- *
- * @return array
- */
- public static function get_least_helpful( $limit = null, $post_type = null )
- {
- if ( is_null( $limit ) ) {
- $limit = absint( get_option( 'helpful_widget_amount' ) );
- }
-
- if ( is_null($post_type)) {
- $post_type = get_option( 'helpful_post_types' );
- }
-
- $args = [
- 'post_type' => $post_type,
- 'post_status' => 'any',
- 'posts_per_page' => -1,
- 'fields' => 'ids',
- ];
-
- $cache_name = 'helpful_least_helpful';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $query = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $query = new \WP_Query( $args );
- } elseif ( false === $query ) {
- $query = new \WP_Query( $args );
- set_transient( $cache_name, maybe_serialize( $query ), $cache_time );
- }
-
- $query = maybe_unserialize( $query );
- $posts = [];
-
- if ( $query->found_posts ) {
- foreach ( $query->posts as $post_id ) :
- $pro = self::get_pro( $post_id ) ? self::get_pro( $post_id ) : 0;
- $contra = self::get_contra( $post_id ) ? self::get_contra( $post_id ) : 0;
- $posts[ $post_id ] = (int) ( $contra - $pro );
- endforeach;
-
- if ( 1 < count( $posts ) ) {
-
- arsort( $posts );
-
- $results = [];
- $posts = array_slice( $posts, 0, $limit, true );
-
- foreach ( $posts as $post_id => $value ) :
- if ( 0 === $value ) {
- continue;
- }
-
- $data = self::get_single_post_stats( $post_id );
- $results[] = [
- 'ID' => $data['ID'],
- 'url' => $data['permalink'],
- 'name' => $data['title'],
- 'pro' => $data['pro']['value'],
- 'contra' => $data['contra']['value'],
- 'percentage' => $data['helpful'],
- 'time' => sprintf(
- /* translators: %s time difference */
- __( 'Published %s ago', 'helpful' ),
- human_time_diff( $data['time']['timestamp'], date_i18n( 'U' ) )
- ),
- ];
- endforeach;
- }
- }
-
- if ( is_array( $results ) ) {
- usort( $results, function( $a, $b ) {
- return $a['percentage'] - $b['percentage'];
- } );
-
- $results = array_filter( $results );
- }
-
- return $results;
- }
-
- /**
- * Get recently helpful pro posts
- *
- * @global $wpdb
- *
- * @param int $limit posts per page.
- *
- * @return array
- */
- public static function get_recently_pro( $limit = null )
- {
- if ( is_null( $limit ) ) {
- $limit = absint( get_option( 'helpful_widget_amount' ) );
- }
-
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $sql = "
+ $sql = $wpdb->prepare($query, $from, $to);
+
+ $cache_name = 'helpful/stats/range/' . $from . '/' . $to;
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $from_date = new \DateTime($from);
+ $to_date = new \DateTime($to);
+ $diff = $from_date->diff($to_date);
+ $pro = [];
+ $contra = [];
+ $labels = [];
+ $timestamp = strtotime($from);
+ $limit = ($diff->format('%a') + 1);
+
+ for ($i = 0; $i < $limit; $i++):
+ $date = date_i18n('Ymd', strtotime("+$i days", $timestamp));
+ $day = date_i18n('j M', strtotime("+$i days", $timestamp));
+ $pro[$date] = 0;
+ $contra[$date] = 0;
+ $labels[] = $day;
+ endfor;
+
+ foreach ($results as $result) {
+ $date = date_i18n('Ymd', strtotime($result->time));
+ $pro[$date] += (int) $result->pro;
+ $contra[$date] += (int) $result->contra;
+ }
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'bar',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'label' => __('Pro', 'helpful'),
+ 'data' => array_values($pro),
+ 'backgroundColor' => self::$green,
+ ],
+ [
+ 'label' => __('Contra', 'helpful'),
+ 'data' => array_values($contra),
+ 'backgroundColor' => self::$red,
+ ],
+ ],
+ 'labels' => $labels,
+ ],
+ 'options' => [
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Stats for total
+ *
+ * @global $wpdb
+ *
+ * @return array
+ */
+ public static function get_stats_total()
+ {
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = "SELECT pro, contra, time FROM $helpful";
+
+ $cache_name = 'helpful/stats/total';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if (!$results) {
+ return [
+ 'status' => 'error',
+ 'message' => __('No entries found', 'helpful'),
+ ];
+ }
+
+ $pro = wp_list_pluck($results, 'pro');
+ $pro = array_sum($pro);
+
+ $contra = wp_list_pluck($results, 'contra');
+ $contra = array_sum($contra);
+
+ /* Response for ChartJS */
+ $response = [
+ 'type' => 'doughnut',
+ 'data' => [
+ 'datasets' => [
+ [
+ 'data' => [
+ absint($pro),
+ absint($contra),
+ ],
+ 'backgroundColor' => [
+ self::$green,
+ self::$red,
+ ],
+ ],
+ ],
+ 'labels' => [
+ __('Pro', 'helpful'),
+ __('Contra', 'helpful'),
+ ],
+ ],
+ 'options' => [
+ 'legend' => [
+ 'position' => 'bottom',
+ ],
+ ],
+ ];
+
+ return $response;
+ }
+
+ /**
+ * Get most helpful posts.
+ *
+ * @param int $limit posts per page.
+ * @param string|array $post_type
+ *
+ * @return array
+ */
+ public static function get_most_helpful($limit = null, $post_type = null)
+ {
+ if (is_null($limit)) {
+ $limit = intval(get_option('helpful_widget_amount'));
+ } else {
+ $limit = intval($limit);
+ }
+
+ if (is_null($post_type)) {
+ $post_type = get_option('helpful_post_types');
+ }
+
+ $args = [
+ 'post_type' => $post_type,
+ 'post_status' => 'any',
+ 'posts_per_page' => -1,
+ 'fields' => 'ids',
+ ];
+
+ $cache_name = 'helpful_most_helpful';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $query = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $query = new \WP_Query($args);
+ } elseif (false === $query) {
+ $query = new \WP_Query($args);
+ set_transient($cache_name, maybe_serialize($query), $cache_time);
+ }
+
+ $query = maybe_unserialize($query);
+ $posts = [];
+
+ if ($query->found_posts) {
+ foreach ($query->posts as $post_id):
+ $pro = self::get_pro($post_id) ? self::get_pro($post_id) : 0;
+ $contra = self::get_contra($post_id) ? self::get_contra($post_id) : 0;
+ $posts[$post_id] = (int) ($pro - $contra);
+ endforeach;
+
+ if (1 < count($posts)) {
+
+ arsort($posts);
+
+ $results = [];
+ $posts = array_slice($posts, 0, $limit, true);
+
+ foreach ($posts as $post_id => $value):
+ if (0 === $value) {
+ continue;
+ }
+
+ $data = self::get_single_post_stats($post_id);
+ $results[] = [
+ 'ID' => $data['ID'],
+ 'url' => $data['permalink'],
+ 'name' => $data['title'],
+ 'pro' => $data['pro']['value'],
+ 'contra' => $data['contra']['value'],
+ 'percentage' => $data['helpful'],
+ 'time' => sprintf(
+ /* translators: %s time difference */
+ __('Published %s ago', 'helpful'),
+ human_time_diff($data['time']['timestamp'], date_i18n('U'))
+ ),
+ ];
+ endforeach;
+ }
+ }
+
+ if (is_array($results)) {
+ usort($results, function ($a, $b) {
+ return $b['percentage'] - $a['percentage'];
+ });
+
+ $results = array_filter($results);
+ }
+
+ return $results;
+ }
+
+ /**
+ * Get least helpful posts.
+ *
+ * @param int $limit posts per page.
+ * @param string|array $post_type
+ *
+ * @return array
+ */
+ public static function get_least_helpful($limit = null, $post_type = null)
+ {
+ if (is_null($limit)) {
+ $limit = absint(get_option('helpful_widget_amount'));
+ }
+
+ if (is_null($post_type)) {
+ $post_type = get_option('helpful_post_types');
+ }
+
+ $args = [
+ 'post_type' => $post_type,
+ 'post_status' => 'any',
+ 'posts_per_page' => -1,
+ 'fields' => 'ids',
+ ];
+
+ $cache_name = 'helpful_least_helpful';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $query = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $query = new \WP_Query($args);
+ } elseif (false === $query) {
+ $query = new \WP_Query($args);
+ set_transient($cache_name, maybe_serialize($query), $cache_time);
+ }
+
+ $query = maybe_unserialize($query);
+ $posts = [];
+
+ if ($query->found_posts) {
+ foreach ($query->posts as $post_id):
+ $pro = self::get_pro($post_id) ? self::get_pro($post_id) : 0;
+ $contra = self::get_contra($post_id) ? self::get_contra($post_id) : 0;
+ $posts[$post_id] = (int) ($contra - $pro);
+ endforeach;
+
+ if (1 < count($posts)) {
+
+ arsort($posts);
+
+ $results = [];
+ $posts = array_slice($posts, 0, $limit, true);
+
+ foreach ($posts as $post_id => $value):
+ if (0 === $value) {
+ continue;
+ }
+
+ $data = self::get_single_post_stats($post_id);
+ $results[] = [
+ 'ID' => $data['ID'],
+ 'url' => $data['permalink'],
+ 'name' => $data['title'],
+ 'pro' => $data['pro']['value'],
+ 'contra' => $data['contra']['value'],
+ 'percentage' => $data['helpful'],
+ 'time' => sprintf(
+ /* translators: %s time difference */
+ __('Published %s ago', 'helpful'),
+ human_time_diff($data['time']['timestamp'], date_i18n('U'))
+ ),
+ ];
+ endforeach;
+ }
+ }
+
+ if (is_array($results)) {
+ usort($results, function ($a, $b) {
+ return $a['percentage'] - $b['percentage'];
+ });
+
+ $results = array_filter($results);
+ }
+
+ return $results;
+ }
+
+ /**
+ * Get recently helpful pro posts
+ *
+ * @global $wpdb
+ *
+ * @param int $limit posts per page.
+ *
+ * @return array
+ */
+ public static function get_recently_pro($limit = null)
+ {
+ if (is_null($limit)) {
+ $limit = absint(get_option('helpful_widget_amount'));
+ }
+
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = "
SELECT post_id, time
FROM $helpful
WHERE pro = %d
@@ -1195,65 +1194,65 @@ public static function get_recently_pro( $limit = null )
LIMIT %d
";
- $posts = [];
- $sql = $wpdb->prepare( $sql, 1, intval( $limit ) );
-
- $cache_name = 'helpful_recently_pro';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( $results ) {
- foreach ( $results as $post ) :
- $data = self::get_single_post_stats( $post->post_id );
- $timestamp = strtotime( $post->time );
- $posts[] = [
- 'ID' => $data['ID'],
- 'url' => $data['permalink'],
- 'name' => $data['title'],
- 'percentage' => $data['helpful'],
- 'time' => sprintf(
- /* translators: %s time difference */
- __( 'Submitted %s ago', 'helpful' ),
- human_time_diff( $timestamp, date_i18n( 'U' ) )
- ),
- ];
- endforeach;
- }
-
- return $posts;
- }
-
- /**
- * Get recently unhelpful pro posts.
- *
- * @global $wpdb
- *
- * @param int $limit posts per page.
- *
- * @return array
- */
- public static function get_recently_contra( $limit = null )
- {
- if ( is_null( $limit ) ) {
- $limit = absint( get_option( 'helpful_widget_amount' ) );
- }
-
- global $wpdb;
-
- $helpful = $wpdb->prefix . 'helpful';
- $sql = "
+ $posts = [];
+ $sql = $wpdb->prepare($sql, 1, intval($limit));
+
+ $cache_name = 'helpful_recently_pro';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if ($results) {
+ foreach ($results as $post):
+ $data = self::get_single_post_stats($post->post_id);
+ $timestamp = strtotime($post->time);
+ $posts[] = [
+ 'ID' => $data['ID'],
+ 'url' => $data['permalink'],
+ 'name' => $data['title'],
+ 'percentage' => $data['helpful'],
+ 'time' => sprintf(
+ /* translators: %s time difference */
+ __('Submitted %s ago', 'helpful'),
+ human_time_diff($timestamp, date_i18n('U'))
+ ),
+ ];
+ endforeach;
+ }
+
+ return $posts;
+ }
+
+ /**
+ * Get recently unhelpful pro posts.
+ *
+ * @global $wpdb
+ *
+ * @param int $limit posts per page.
+ *
+ * @return array
+ */
+ public static function get_recently_contra($limit = null)
+ {
+ if (is_null($limit)) {
+ $limit = absint(get_option('helpful_widget_amount'));
+ }
+
+ global $wpdb;
+
+ $helpful = $wpdb->prefix . 'helpful';
+ $sql = "
SELECT post_id, time
FROM $helpful
WHERE contra = %d
@@ -1261,157 +1260,157 @@ public static function get_recently_contra( $limit = null )
LIMIT %d
";
- $posts = [];
- $sql = $wpdb->prepare( $sql, 1, intval( $limit ) );
-
- $cache_name = 'helpful_recently_contra';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = $wpdb->get_results( $sql );
- } elseif ( false === $results ) {
- $results = $wpdb->get_results( $sql );
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- if ( $results ) {
- foreach ( $results as $post ) :
- $data = self::get_single_post_stats( $post->post_id );
- $timestamp = strtotime( $post->time );
- $posts[] = [
- 'ID' => $data['ID'],
- 'url' => $data['permalink'],
- 'name' => $data['title'],
- 'percentage' => $data['helpful'],
- 'time' => sprintf(
- /* translators: %s time difference */
- __( 'Submitted %s ago', 'helpful' ),
- human_time_diff( $timestamp, date_i18n( 'U' ) )
- ),
- ];
- endforeach;
- }
-
- return $posts;
- }
-
- /**
- * Get single post stats
- *
- * @return array
- */
- public static function get_single_post_stats( $post_id )
- {
- $post = get_post( $post_id );
- $pro = self::get_pro( $post->ID ) ? intval( self::get_pro( $post->ID ) ) : 0;
- $contra = self::get_contra( $post->ID ) ? intval( self::get_contra( $post->ID ) ) : 0;
- $prop = self::get_pro( $post->ID, true );
- $conp = self::get_contra( $post->ID, true );
-
- $average = 0;
- $total = 0;
- $percentage = 0;
-
- if ( 0 !== $pro ) {
- $average = (int) ( $pro - $contra );
- $total = (int) ( $pro + $contra );
- $percentage = ( $pro / $total ) * 100;
- $percentage = round( $percentage, 2 );
- }
-
- $post_type = get_post_type_object( $post->post_type );
-
- $results = [
- 'ID' => $post->ID,
- 'permalink' => get_the_permalink( $post->ID ),
- 'title' => esc_html( $post->post_title ),
- 'type' => [
- 'slug' => $post_type->name,
- 'name' => $post_type->labels->singular_name,
- ],
- 'author' => [
- 'ID' => $post->post_author,
- 'name' => get_the_author_meta( 'display_name', $post->post_author ),
- ],
- 'pro' => [
- 'value' => $pro,
- 'percentage' => $prop,
- ],
- 'contra' => [
- 'value' => $contra,
- 'percentage' => $conp,
- ],
- 'helpful' => $percentage,
- 'time' => [
- 'time' => date_i18n( 'H:i:s', get_the_date( 'U', $post->ID ) ),
- 'date' => date_i18n( 'Y-m-d', get_the_date( 'U', $post->ID ) ),
- 'timestamp' => date_i18n( 'U', get_the_date( 'U', $post->ID ) ),
- ],
- ];
-
- return $results;
- }
-
- /**
- * Returns everything at once and saves the result in a transient to reduce the number of queries for the widget.
- *
- * @return array
- */
- public static function get_widget_stats()
- {
- $cache_name = 'helpful_widget_stats';
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_active = get_option( 'helpful_caching', 'off' );
- $cache_times = Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
- $results = get_transient( $cache_name );
-
- if ( 'on' !== $cache_active ) {
- $results = [
- 'most_helpful' => get_option( 'helpful_widget_pro' ) ? self::get_most_helpful() : null,
- 'least_helpful' => get_option( 'helpful_widget_contra' ) ? self::get_least_helpful() : null,
- 'recently_pro' => get_option( 'helpful_widget_pro_recent' ) ? self::get_recently_pro() : null,
- 'recently_contra' => get_option( 'helpful_widget_contra_recent' ) ? self::get_recently_contra() : null,
- 'feedback_items' => get_option( 'helpful_feedback_widget' ) ? Feedback::get_feedback_items() : null,
- 'pro_total' => intval( self::get_pro_all() ),
- 'contra_total' => intval( self::get_contra_all() ),
- ];
-
- return $results;
- }
-
- if ( false === $results ) {
- $results = [
- 'most_helpful' => get_option( 'helpful_widget_pro' ) ? self::get_most_helpful() : null,
- 'least_helpful' => get_option( 'helpful_widget_contra' ) ? self::get_least_helpful() : null,
- 'recently_pro' => get_option( 'helpful_widget_pro_recent' ) ? self::get_recently_pro() : null,
- 'recently_contra' => get_option( 'helpful_widget_contra_recent' ) ? self::get_recently_contra() : null,
- 'feedback_items' => get_option( 'helpful_feedback_widget' ) ? Feedback::get_feedback_items() : null,
- 'pro_total' => intval( self::get_pro_all() ),
- 'contra_total' => intval( self::get_contra_all() ),
- ];
-
- set_transient( $cache_name, maybe_serialize( $results ), $cache_time );
- }
-
- $results = maybe_unserialize( $results );
-
- return $results;
- }
-
- /**
- * Removes the transient for the widget so that current data can be transferred.
- *
- * @return void
- */
- public static function delete_widget_transient()
- {
- delete_transient( 'helpful_widget_stats' );
- }
-}
\ No newline at end of file
+ $posts = [];
+ $sql = $wpdb->prepare($sql, 1, intval($limit));
+
+ $cache_name = 'helpful_recently_contra';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = $wpdb->get_results($sql);
+ } elseif (false === $results) {
+ $results = $wpdb->get_results($sql);
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ if ($results) {
+ foreach ($results as $post):
+ $data = self::get_single_post_stats($post->post_id);
+ $timestamp = strtotime($post->time);
+ $posts[] = [
+ 'ID' => $data['ID'],
+ 'url' => $data['permalink'],
+ 'name' => $data['title'],
+ 'percentage' => $data['helpful'],
+ 'time' => sprintf(
+ /* translators: %s time difference */
+ __('Submitted %s ago', 'helpful'),
+ human_time_diff($timestamp, date_i18n('U'))
+ ),
+ ];
+ endforeach;
+ }
+
+ return $posts;
+ }
+
+ /**
+ * Get single post stats
+ *
+ * @return array
+ */
+ public static function get_single_post_stats($post_id)
+ {
+ $post = get_post($post_id);
+ $pro = self::get_pro($post->ID) ? intval(self::get_pro($post->ID)) : 0;
+ $contra = self::get_contra($post->ID) ? intval(self::get_contra($post->ID)) : 0;
+ $prop = self::get_pro($post->ID, true);
+ $conp = self::get_contra($post->ID, true);
+
+ $average = 0;
+ $total = 0;
+ $percentage = 0;
+
+ if (0 !== $pro) {
+ $average = (int) ($pro - $contra);
+ $total = (int) ($pro + $contra);
+ $percentage = ($pro / $total) * 100;
+ $percentage = round($percentage, 2);
+ }
+
+ $post_type = get_post_type_object($post->post_type);
+
+ $results = [
+ 'ID' => $post->ID,
+ 'permalink' => get_the_permalink($post->ID),
+ 'title' => esc_html($post->post_title),
+ 'type' => [
+ 'slug' => $post_type->name,
+ 'name' => $post_type->labels->singular_name,
+ ],
+ 'author' => [
+ 'ID' => $post->post_author,
+ 'name' => get_the_author_meta('display_name', $post->post_author),
+ ],
+ 'pro' => [
+ 'value' => $pro,
+ 'percentage' => $prop,
+ ],
+ 'contra' => [
+ 'value' => $contra,
+ 'percentage' => $conp,
+ ],
+ 'helpful' => $percentage,
+ 'time' => [
+ 'time' => date_i18n('H:i:s', get_the_date('U', $post->ID)),
+ 'date' => date_i18n('Y-m-d', get_the_date('U', $post->ID)),
+ 'timestamp' => date_i18n('U', get_the_date('U', $post->ID)),
+ ],
+ ];
+
+ return $results;
+ }
+
+ /**
+ * Returns everything at once and saves the result in a transient to reduce the number of queries for the widget.
+ *
+ * @return array
+ */
+ public static function get_widget_stats()
+ {
+ $cache_name = 'helpful_widget_stats';
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_active = get_option('helpful_caching', 'off');
+ $cache_times = Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+ $results = get_transient($cache_name);
+
+ if ('on' !== $cache_active) {
+ $results = [
+ 'most_helpful' => get_option('helpful_widget_pro') ? self::get_most_helpful() : null,
+ 'least_helpful' => get_option('helpful_widget_contra') ? self::get_least_helpful() : null,
+ 'recently_pro' => get_option('helpful_widget_pro_recent') ? self::get_recently_pro() : null,
+ 'recently_contra' => get_option('helpful_widget_contra_recent') ? self::get_recently_contra() : null,
+ 'feedback_items' => get_option('helpful_feedback_widget') ? Feedback::get_feedback_items() : null,
+ 'pro_total' => intval(self::get_pro_all()),
+ 'contra_total' => intval(self::get_contra_all()),
+ ];
+
+ return $results;
+ }
+
+ if (false === $results) {
+ $results = [
+ 'most_helpful' => get_option('helpful_widget_pro') ? self::get_most_helpful() : null,
+ 'least_helpful' => get_option('helpful_widget_contra') ? self::get_least_helpful() : null,
+ 'recently_pro' => get_option('helpful_widget_pro_recent') ? self::get_recently_pro() : null,
+ 'recently_contra' => get_option('helpful_widget_contra_recent') ? self::get_recently_contra() : null,
+ 'feedback_items' => get_option('helpful_feedback_widget') ? Feedback::get_feedback_items() : null,
+ 'pro_total' => intval(self::get_pro_all()),
+ 'contra_total' => intval(self::get_contra_all()),
+ ];
+
+ set_transient($cache_name, maybe_serialize($results), $cache_time);
+ }
+
+ $results = maybe_unserialize($results);
+
+ return $results;
+ }
+
+ /**
+ * Removes the transient for the widget so that current data can be transferred.
+ *
+ * @return void
+ */
+ public static function delete_widget_transient()
+ {
+ delete_transient('helpful_widget_stats');
+ }
+}
diff --git a/core/helpers/class-user.php b/core/helpers/class-user.php
index c85c5d7..e60fc78 100644
--- a/core/helpers/class-user.php
+++ b/core/helpers/class-user.php
@@ -1,12 +1,14 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Services as Services;
/* Prevent direct access */
if (!defined('ABSPATH')) {
@@ -130,25 +132,8 @@ public static function set_user()
}
if ('on' !== $sessions_disabled && !isset($_COOKIE['helpful_user'])) {
- if (function_exists('session_status') && PHP_SESSION_NONE == session_status() && true === $session_start) {
- if (function_exists('session_write_close')) {
- session_write_close();
- }
-
- ob_start();
-
- try {
- session_cache_limiter('');
- header("Cache-Control: public, s-maxage=60");
- session_start();
- } catch (\Exception $e) {
- helpful_error_log($e->getMessage());
- }
- }
-
- if (!isset($_SESSION['helpful_user'])) {
- $_SESSION['helpful_user'] = $string;
- }
+ $session = new Services\Session();
+ $session->set('helpful_user', $string);
}
}
diff --git a/core/helpers/class-values.php b/core/helpers/class-values.php
index 6cdc175..a730ae1 100644
--- a/core/helpers/class-values.php
+++ b/core/helpers/class-values.php
@@ -1,10 +1,9 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
@@ -72,9 +71,9 @@ public static function get_defaults()
'credits_html' => $credits['html'],
'exists' => User::check_user($user_id, $post_id) ? 1 : 0,
'exists_text' => self::convert_tags(get_option('helpful_exists'), $post_id),
- 'exists_hide' => ('on' ===get_option('helpful_exists_hide')) ? 1 : 0,
+ 'exists_hide' => ('on' === get_option('helpful_exists_hide')) ? 1 : 0,
'post_id' => $post_id,
- 'user_id' => User::get_user(),
+ 'user_id' => User::get_user(),
];
return apply_filters('helpful_default_values', $values);
diff --git a/core/helpers/class-votes.php b/core/helpers/class-votes.php
index d8eb836..d4f6011 100644
--- a/core/helpers/class-votes.php
+++ b/core/helpers/class-votes.php
@@ -1,154 +1,153 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Helpers
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Helpers;
use Helpful\Core\Helper;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Votes
{
- /**
- * Returns all votes from the database.
- *
- * @global $wpdb
- *
- * @param output_type $type
- *
- * @return array
- */
- public static function get_votes( $type = OBJECT )
- {
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'helpful';
-
- $sql = "SELECT * FROM $table_name";
-
- return $wpdb->get_results( $sql, $type );
- }
-
- /**
- * @global $wpdb
- *
- * @param int $vote_id
- * @param output_type $type
- *
- * @return array
- */
- public static function get_vote($vote_id, $type = OBJECT)
- {
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'helpful';
-
- $sql = "SELECT * FROM $table_name WHERE id = %d LIMIT 1";
- $sql = $wpdb->prepare($sql, $vote_id);
-
- return $wpdb->get_row( $sql, $type );
- }
-
- /**
- * Delete a vote item by id from database.
- *
- * @global $wpdb
- *
- * @param int $id
- *
- * @return int|false
- */
- public static function delete_vote( $id )
- {
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'helpful';
-
- $where = [
- 'id' => $id,
- ];
-
- $status = $wpdb->delete( $table_name, $where );
+ /**
+ * Returns all votes from the database.
+ *
+ * @global $wpdb
+ *
+ * @param output_type $type
+ *
+ * @return array
+ */
+ public static function get_votes($type = OBJECT)
+ {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'helpful';
+
+ $sql = "SELECT * FROM $table_name";
+
+ return $wpdb->get_results($sql, $type);
+ }
+
+ /**
+ * @global $wpdb
+ *
+ * @param int $vote_id
+ * @param output_type $type
+ *
+ * @return array
+ */
+ public static function get_vote($vote_id, $type = OBJECT)
+ {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'helpful';
+
+ $sql = "SELECT * FROM $table_name WHERE id = %d LIMIT 1";
+ $sql = $wpdb->prepare($sql, $vote_id);
+
+ return $wpdb->get_row($sql, $type);
+ }
+
+ /**
+ * Delete a vote item by id from database.
+ *
+ * @global $wpdb
+ *
+ * @param int $id
+ *
+ * @return int|false
+ */
+ public static function delete_vote($id)
+ {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'helpful';
+
+ $where = [
+ 'id' => $id,
+ ];
+
+ $status = $wpdb->delete($table_name, $where);
$wpdb->query("OPTIMIZE TABLE $table_name");
- if ( false !== $status ) {
- Optimize::clear_cache();
- }
-
- return $status;
- }
-
- /**
- * Delete a vote item by mixed from database.
- *
- * @global $wpdb
- *
- * @param array $where
- *
- * @return int|false
- */
- public static function delete_vote_where( $where )
- {
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'helpful';
-
- $status = $wpdb->delete( $table_name, $where );
-
- if ( false !== $status ) {
- Optimize::clear_cache();
- }
-
- return $status;
- }
-
- /**
- * Insert vote for single user on single post.
- *
- * @param string $user
- * @param int $post_id
- * @param string $type
- *
- * @return int|false
- */
- public static function insert_vote( $user, $post_id, $type = 'pro' )
- {
- global $wpdb;
-
- $pro = 1;
- $contra = 0;
-
- if ( 'contra' === $type ) {
- $pro = 0;
- $contra = 1;
- }
-
- $data = [
- 'time' => current_time( 'mysql' ),
- 'user' => esc_attr( $user ),
- 'pro' => $pro,
- 'contra' => $contra,
- 'post_id' => absint( $post_id ),
- ];
-
- $table_name = $wpdb->prefix . 'helpful';
-
- $status = $wpdb->insert( $table_name, $data );
-
- if ( false !== $status ) {
- update_post_meta( $post_id, 'helpful-contra', Stats::get_contra( $post_id ) );
- Optimize::clear_cache();
- return $wpdb->insert_id;
- }
-
- return false;
- }
-}
\ No newline at end of file
+ if (false !== $status) {
+ Optimize::clear_cache();
+ }
+
+ return $status;
+ }
+
+ /**
+ * Delete a vote item by mixed from database.
+ *
+ * @global $wpdb
+ *
+ * @param array $where
+ *
+ * @return int|false
+ */
+ public static function delete_vote_where($where)
+ {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'helpful';
+
+ $status = $wpdb->delete($table_name, $where);
+
+ if (false !== $status) {
+ Optimize::clear_cache();
+ }
+
+ return $status;
+ }
+
+ /**
+ * Insert vote for single user on single post.
+ *
+ * @param string $user
+ * @param int $post_id
+ * @param string $type
+ *
+ * @return int|false
+ */
+ public static function insert_vote($user, $post_id, $type = 'pro')
+ {
+ global $wpdb;
+
+ $pro = 1;
+ $contra = 0;
+
+ if ('contra' === $type) {
+ $pro = 0;
+ $contra = 1;
+ }
+
+ $data = [
+ 'time' => current_time('mysql'),
+ 'user' => esc_attr($user),
+ 'pro' => $pro,
+ 'contra' => $contra,
+ 'post_id' => absint($post_id),
+ ];
+
+ $table_name = $wpdb->prefix . 'helpful';
+
+ $status = $wpdb->insert($table_name, $data);
+
+ if (false !== $status) {
+ update_post_meta($post_id, 'helpful-contra', Stats::get_contra($post_id));
+ Optimize::clear_cache();
+ return $wpdb->insert_id;
+ }
+
+ return false;
+ }
+}
diff --git a/core/index.php b/core/index.php
index e69de29..6220032 100644
--- a/core/index.php
+++ b/core/index.php
@@ -0,0 +1,2 @@
+
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Admin
{
- /**
- * Instance
- *
- * @var Core
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Core
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'admin_menu', [ &$this, 'register_admin_menu' ] );
- add_action( 'admin_enqueue_scripts', [ &$this, 'enqueue_scripts' ] );
-
- add_action( 'admin_init', [ &$this, 'init_columns' ] );
- }
-
- /**
- * Register admin menu.
- *
- * @return void
- */
- public function register_admin_menu()
- {
- add_menu_page(
- __( 'Helpful', 'helpful' ),
- __( 'Helpful', 'helpful' ),
- get_option( 'helpful_capability', 'manage_options' ),
- 'helpful',
- [ &$this, 'callback_admin_page' ],
- 'dashicons-thumbs-up',
- 99
- );
-
- add_submenu_page(
- 'helpful',
- __( 'Settings', 'helpful' ),
- __( 'Settings', 'helpful' ),
- get_option( 'helpful_settings_capability', 'manage_options' ),
- 'helpful',
- [ &$this, 'callback_admin_page' ]
- );
- }
-
- /**
- * Callback for admin page.
- *
- * @return void
- */
- public function callback_admin_page()
- {
- $tabs = Helper::get_admin_tabs();
-
- foreach ( $tabs as $key => $data ) :
- if ( ! isset( $tabs[ $key ]['href'] ) ) {
- $tabs[ $key ]['href'] = Helper::get_tab_url( $key );
- }
-
- if ( ! isset( $tabs[ $key ]['class'] ) ) {
- $tabs[ $key ]['class'] = Helper::get_tab_class( $key );
- }
-
- if ( ! isset( $tabs[ $key ]['attr'] ) ) {
- $tabs[ $key ]['attr'] = Helper::get_tab_attr( $key );
- }
- endforeach;
-
- include_once HELPFUL_PATH . 'templates/admin.php';
- }
-
- /**
- * Enqueue backend scripts and styles, if current screen is helpful
- *
- * @param string $hook_suffix
- *
- * @return void
- */
- public function enqueue_scripts( $hook_suffix )
- {
- /* shrink admin columns */
- if ( 'on' === get_option( 'helpful_shrink_admin_columns' ) ) {
- $file = plugins_url( 'core/assets/css/admin-columns.css', HELPFUL_FILE );
- wp_enqueue_style( 'helpful-admin-columns', $file );
- }
-
- if ( 'toplevel_page_helpful' !== $hook_suffix ) {
- return;
- }
-
- $plugin = Helper::get_plugin_data();
-
- $file = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css';
- wp_enqueue_style( 'helpful-chartjs', $file, [], '2.9.3' );
-
- $file = '//cdn.datatables.net/v/ju/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/r-2.2.3/sc-2.0.1/datatables.min.css';
- wp_enqueue_style( 'helpful-datatables', $file, [], '1.10.20' );
-
- $file = plugins_url( 'core/assets/vendor/jqueryui/jquery-ui.min.css', HELPFUL_FILE );
- wp_enqueue_style( 'helpful-jquery', $file, [], $plugin['Version'] );
-
- $file = plugins_url( 'core/assets/vendor/jqueryui/jquery-ui.structure.min.css', HELPFUL_FILE );
- wp_enqueue_style( 'helpful-jquery-structure', $file, [], $plugin['Version'] );
-
- $file = plugins_url( 'core/assets/vendor/jqueryui/jquery-ui.theme.min.css', HELPFUL_FILE );
- wp_enqueue_style( 'helpful-jquery-theme', $file, [], $plugin['Version'] );
-
- $file = plugins_url( 'core/assets/css/admin.css', HELPFUL_FILE );
- wp_enqueue_style( 'helpful-backend', $file, [], $plugin['Version'] );
-
- $file = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js';
- wp_enqueue_script( 'helpful-chartjs', $file, [], '2.9.3', true );
-
- $file = plugins_url( 'core/assets/vendor/jqueryui/jquery-ui.min.js', HELPFUL_FILE );
- wp_enqueue_script( 'helpful-jquery', $file, [], $plugin['Version'], true );
-
- $file = '//cdn.datatables.net/v/ju/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/r-2.2.3/sc-2.0.1/sl-1.3.3/datatables.min.js';
- wp_enqueue_script( 'helpful-datatables', $file, [], '1.10.20', true );
-
- $file = plugins_url( 'core/assets/js/admin.js', HELPFUL_FILE );
- wp_enqueue_script( 'helpful-admin', $file, [], $plugin['Version'], true );
-
- $language = Helper::datatables_language_string();
-
- $vars = [
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
- 'nonce' => wp_create_nonce( 'helpful_admin_nonce' ),
- 'language' => $language,
- 'feedback' => true,
- ];
-
- if ( Helper::is_feedback_disabled() ) {
- $vars['feedback'] = false;
- }
-
- $vars = apply_filters( 'helpful_admin_ajax_vars', $vars );
-
- wp_localize_script( 'helpful-admin', 'helpful_admin', $vars );
- }
-
- /**
- * Register columns on admin pages
- *
- * @global $pagenow
- *
- * @return void
- */
- public function init_columns()
- {
- global $pagenow;
-
- $post_types = get_option( 'helpful_post_types' );
- $hide_cols = get_option( 'helpful_hide_admin_columns' );
-
- if ( isset( $hide_cols ) && 'on' === $hide_cols ) {
- return;
- }
-
- /* Allows filtering the content afterwards */
- $post_types = apply_filters( 'helpful_admin_columns_post_types', $post_types );
-
- if ( ! isset( $post_types ) || ! is_array( $post_types ) ) {
- return;
- }
-
- $type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : 'post';
-
- if ( ! in_array( $type, $post_types ) ) {
- return;
- }
-
- foreach ( $post_types as $type ) :
- if ( is_admin() && 'edit.php' === $pagenow ) {
- add_filter( 'manage_' . $type . '_posts_columns', [ &$this, 'register_columns' ] );
- add_action( 'manage_' . $type . '_posts_custom_column', [ &$this, 'populate_columns' ], 10, 2 );
- add_filter( 'manage_edit-' . $type . '_sortable_columns', [ &$this, 'register_sortable_columns' ] );
- add_action( 'pre_get_posts', [ &$this, 'sort_columns_query' ] );
- }
- endforeach;
- }
-
- /**
- * Set column titles
- *
- * @param array $defaults defatul columns.
- *
- * @return array
- */
- public function register_columns( $defaults )
- {
- $columns = [];
- foreach ( $defaults as $key => $value ) :
- $columns[ $key ] = $value;
-
- if ( 'title' === $key ) {
- $columns['helpful-pro'] = get_option( 'helpful_column_pro' ) ? get_option( 'helpful_column_pro' ) : _x( 'Pro', 'column name', 'helpful' );
- $columns['helpful-contra'] = get_option( 'helpful_column_contra' ) ? get_option( 'helpful_column_contra' ) : _x( 'Contra', 'column name', 'helpful' );
- $columns['helpful-feedback'] = get_option( 'helpful_column_feedback' ) ? get_option( 'helpful_column_feedback' ) : _x( 'Feedback', 'column name', 'helpful' );
- }
- endforeach;
-
- return $columns;
- }
-
- /**
- * Columns callback
- *
- * @param string $column_name column name.
- * @param integer $post_id post id.
- *
- * @return void
- */
- public function populate_columns( $column_name, $post_id )
- {
- if ( 'helpful-pro' === $column_name ) {
- if ( get_option( 'helpful_percentages' ) ) {
- $percent = Helpers\Stats::get_pro( $post_id, true );
- $pro = Helpers\Stats::get_pro( $post_id );
- update_post_meta( $post_id, 'helpful-pro', $pro );
- printf( '%d (%s%%)', (int) $pro, $percent );
- } else {
- $pro = Helpers\Stats::get_pro( $post_id );
- $pro = intval( $pro );
- update_post_meta( $post_id, 'helpful-pro', $pro );
- echo $pro;
- }
- }
-
- if ( 'helpful-contra' === $column_name ) {
- if ( get_option( 'helpful_percentages' ) ) {
- $percent = Helpers\Stats::get_contra( $post_id, true );
- $contra = Helpers\Stats::get_contra( $post_id );
- update_post_meta( $post_id, 'helpful-contra', $contra );
- printf( '%d (%s%%)', (int) $contra, $percent );
- } else {
- $contra = Helpers\Stats::get_contra( $post_id );
- $contra = intval( $contra );
- update_post_meta( $post_id, 'helpful-contra', $contra );
- echo $contra;
- }
- }
-
- if ( 'helpful-feedback' === $column_name ) {
- $count = Helpers\Feedback::get_feedback_count( $post_id );
- $count = intval( $count );
-
- update_post_meta( $post_id, 'helpful-feedback-count', $count );
-
- if ( 0 < $count ) {
- $url = admin_url( 'admin.php?page=helpful_feedback&post_id=' . $post_id );
- printf( '%s ', esc_url( $url ), intval( $count ) );
- } else {
- echo $count;
- }
- }
- }
-
- /**
- * Set sortable columns
- *
- * @param array $columns columns.
- * @return array
- */
- public function register_sortable_columns( $columns )
- {
- $columns['helpful-pro'] = 'helpful-pro';
- $columns['helpful-contra'] = 'helpful-contra';
- $columns['helpful-feedback'] = 'helpful-feedback';
-
- return $columns;
- }
-
- /**
- * Make values sortable in columns
- *
- * @param object $query current query.
- * @return void
- */
- public function sort_columns_query( $wp_query )
- {
- if ( ! is_admin() ) {
- return;
- }
-
- $orderby = $wp_query->get( 'orderby' );
-
- if ( 'helpful-pro' === $orderby ) {
- $meta_query = [
- 'relation' => 'OR',
- [
- 'key' => 'helpful-pro',
- 'compare' => 'NOT EXISTS',
- 'type' => 'NUMERIC',
- ],
- [
- 'key' => 'helpful-pro',
- 'type' => 'NUMERIC',
- ],
- ];
-
- $wp_query->set( 'meta_query', $meta_query );
- $wp_query->set( 'orderby', 'meta_value' );
- }
-
- if ( 'helpful-contra' === $orderby ) {
- $meta_query = [
- 'relation' => 'OR',
- [
- 'key' => 'helpful-contra',
- 'compare' => 'NOT EXISTS',
- ],
- [
- 'key' => 'helpful-contra',
- ],
- ];
-
- $wp_query->set( 'meta_query', $meta_query );
- $wp_query->set( 'orderby', 'meta_value' );
- }
-
- if ( 'helpful-feedback' === $orderby ) {
- $meta_query = [
- 'relation' => 'OR',
- [
- 'key' => 'helpful-feedback-count',
- 'compare' => 'NOT EXISTS',
- 'type' => 'NUMERIC',
- ],
- [
- 'key' => 'helpful-feedback-count',
- 'type' => 'NUMERIC',
- ],
- ];
-
- $wp_query->set( 'meta_query', $meta_query );
- $wp_query->set( 'orderby', 'meta_value' );
- }
- }
-
- /**
- * Sets the German language if the user has set German
- * as language in the WordPress settings.
- *
- * @return string
- */
- public function set_datatables_language()
- {
- return wp_json_encode( Helpers\Values::datatables_language_string() );
- }
-}
\ No newline at end of file
+ /**
+ * Instance
+ *
+ * @var Core
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Core
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('admin_menu', [ & $this, 'register_admin_menu']);
+ add_action('admin_enqueue_scripts', [ & $this, 'enqueue_scripts']);
+
+ add_action('admin_init', [ & $this, 'init_columns']);
+ }
+
+ /**
+ * Register admin menu.
+ *
+ * @return void
+ */
+ public function register_admin_menu()
+ {
+ add_menu_page(
+ __('Helpful', 'helpful'),
+ __('Helpful', 'helpful'),
+ get_option('helpful_capability', 'manage_options'),
+ 'helpful',
+ [ & $this, 'callback_admin_page'],
+ 'dashicons-thumbs-up',
+ 99
+ );
+
+ add_submenu_page(
+ 'helpful',
+ __('Settings', 'helpful'),
+ __('Settings', 'helpful'),
+ get_option('helpful_settings_capability', 'manage_options'),
+ 'helpful',
+ [ & $this, 'callback_admin_page']
+ );
+ }
+
+ /**
+ * Callback for admin page.
+ *
+ * @return void
+ */
+ public function callback_admin_page()
+ {
+ $tabs = Helper::get_admin_tabs();
+
+ foreach ($tabs as $key => $data):
+ if (!isset($tabs[$key]['href'])) {
+ $tabs[$key]['href'] = Helper::get_tab_url($key);
+ }
+
+ if (!isset($tabs[$key]['class'])) {
+ $tabs[$key]['class'] = Helper::get_tab_class($key);
+ }
+
+ if (!isset($tabs[$key]['attr'])) {
+ $tabs[$key]['attr'] = Helper::get_tab_attr($key);
+ }
+ endforeach;
+
+ include_once HELPFUL_PATH . 'templates/admin.php';
+ }
+
+ /**
+ * Enqueue backend scripts and styles, if current screen is helpful
+ *
+ * @param string $hook_suffix
+ *
+ * @return void
+ */
+ public function enqueue_scripts($hook_suffix)
+ {
+ /* shrink admin columns */
+ if ('on' === get_option('helpful_shrink_admin_columns')) {
+ $file = plugins_url('core/assets/css/admin-columns.css', HELPFUL_FILE);
+ wp_enqueue_style('helpful-admin-columns', $file);
+ }
+
+ if ('toplevel_page_helpful' !== $hook_suffix) {
+ return;
+ }
+
+ $plugin = Helper::get_plugin_data();
+
+ $file = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css';
+ wp_enqueue_style('helpful-chartjs', $file, [], '2.9.3');
+
+ $file = '//cdn.datatables.net/v/ju/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/r-2.2.3/sc-2.0.1/datatables.min.css';
+ wp_enqueue_style('helpful-datatables', $file, [], '1.10.20');
+
+ $file = plugins_url('core/assets/vendor/jqueryui/jquery-ui.min.css', HELPFUL_FILE);
+ wp_enqueue_style('helpful-jquery', $file, [], $plugin['Version']);
+
+ $file = plugins_url('core/assets/vendor/jqueryui/jquery-ui.structure.min.css', HELPFUL_FILE);
+ wp_enqueue_style('helpful-jquery-structure', $file, [], $plugin['Version']);
+
+ $file = plugins_url('core/assets/vendor/jqueryui/jquery-ui.theme.min.css', HELPFUL_FILE);
+ wp_enqueue_style('helpful-jquery-theme', $file, [], $plugin['Version']);
+
+ $file = plugins_url('core/assets/css/admin.css', HELPFUL_FILE);
+ wp_enqueue_style('helpful-backend', $file, [], $plugin['Version']);
+
+ $file = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js';
+ wp_enqueue_script('helpful-chartjs', $file, [], '2.9.3', true);
+
+ $file = plugins_url('core/assets/vendor/jqueryui/jquery-ui.min.js', HELPFUL_FILE);
+ wp_enqueue_script('helpful-jquery', $file, [], $plugin['Version'], true);
+
+ $file = '//cdn.datatables.net/v/ju/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/r-2.2.3/sc-2.0.1/sl-1.3.3/datatables.min.js';
+ wp_enqueue_script('helpful-datatables', $file, [], '1.10.20', true);
+
+ $file = plugins_url('core/assets/js/admin.js', HELPFUL_FILE);
+ wp_enqueue_script('helpful-admin', $file, [], $plugin['Version'], true);
+
+ $language = Helper::datatables_language_string();
+
+ $vars = [
+ 'ajax_url' => admin_url('admin-ajax.php'),
+ 'nonce' => wp_create_nonce('helpful_admin_nonce'),
+ 'language' => $language,
+ 'feedback' => true,
+ ];
+
+ if (Helper::is_feedback_disabled()) {
+ $vars['feedback'] = false;
+ }
+
+ $vars = apply_filters('helpful_admin_ajax_vars', $vars);
+
+ wp_localize_script('helpful-admin', 'helpful_admin', $vars);
+ }
+
+ /**
+ * Register columns on admin pages
+ *
+ * @global $pagenow
+ *
+ * @return void
+ */
+ public function init_columns()
+ {
+ global $pagenow;
+
+ $post_types = get_option('helpful_post_types');
+ $hide_cols = get_option('helpful_hide_admin_columns');
+
+ if (isset($hide_cols) && 'on' === $hide_cols) {
+ return;
+ }
+
+ /* Allows filtering the content afterwards */
+ $post_types = apply_filters('helpful_admin_columns_post_types', $post_types);
+
+ if (!isset($post_types) || !is_array($post_types)) {
+ return;
+ }
+
+ $type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
+
+ if (!in_array($type, $post_types)) {
+ return;
+ }
+
+ foreach ($post_types as $type):
+ if (is_admin() && 'edit.php' === $pagenow) {
+ add_filter('manage_' . $type . '_posts_columns', [ & $this, 'register_columns']);
+ add_action('manage_' . $type . '_posts_custom_column', [ & $this, 'populate_columns'], 10, 2);
+ add_filter('manage_edit-' . $type . '_sortable_columns', [ & $this, 'register_sortable_columns']);
+ add_action('pre_get_posts', [ & $this, 'sort_columns_query']);
+ }
+ endforeach;
+ }
+
+ /**
+ * Set column titles
+ *
+ * @param array $defaults defatul columns.
+ *
+ * @return array
+ */
+ public function register_columns($defaults)
+ {
+ $columns = [];
+ foreach ($defaults as $key => $value):
+ $columns[$key] = $value;
+
+ if ('title' === $key) {
+ $columns['helpful-pro'] = get_option('helpful_column_pro') ? get_option('helpful_column_pro') : _x('Pro', 'column name', 'helpful');
+ $columns['helpful-contra'] = get_option('helpful_column_contra') ? get_option('helpful_column_contra') : _x('Contra', 'column name', 'helpful');
+ $columns['helpful-feedback'] = get_option('helpful_column_feedback') ? get_option('helpful_column_feedback') : _x('Feedback', 'column name', 'helpful');
+ }
+ endforeach;
+
+ return $columns;
+ }
+
+ /**
+ * Columns callback
+ *
+ * @param string $column_name column name.
+ * @param integer $post_id post id.
+ *
+ * @return void
+ */
+ public function populate_columns($column_name, $post_id)
+ {
+ if ('helpful-pro' === $column_name) {
+ if (get_option('helpful_percentages')) {
+ $percent = Helpers\Stats::get_pro($post_id, true);
+ $pro = Helpers\Stats::get_pro($post_id);
+ update_post_meta($post_id, 'helpful-pro', $pro);
+ printf('%d (%s%%)', (int) $pro, $percent);
+ } else {
+ $pro = Helpers\Stats::get_pro($post_id);
+ $pro = intval($pro);
+ update_post_meta($post_id, 'helpful-pro', $pro);
+ echo $pro;
+ }
+ }
+
+ if ('helpful-contra' === $column_name) {
+ if (get_option('helpful_percentages')) {
+ $percent = Helpers\Stats::get_contra($post_id, true);
+ $contra = Helpers\Stats::get_contra($post_id);
+ update_post_meta($post_id, 'helpful-contra', $contra);
+ printf('%d (%s%%)', (int) $contra, $percent);
+ } else {
+ $contra = Helpers\Stats::get_contra($post_id);
+ $contra = intval($contra);
+ update_post_meta($post_id, 'helpful-contra', $contra);
+ echo $contra;
+ }
+ }
+
+ if ('helpful-feedback' === $column_name) {
+ $count = Helpers\Feedback::get_feedback_count($post_id);
+ $count = intval($count);
+
+ update_post_meta($post_id, 'helpful-feedback-count', $count);
+
+ if (0 < $count) {
+ $url = admin_url('admin.php?page=helpful_feedback&post_id=' . $post_id);
+ printf('%s ', esc_url($url), intval($count));
+ } else {
+ echo $count;
+ }
+ }
+ }
+
+ /**
+ * Set sortable columns
+ *
+ * @param array $columns columns.
+ * @return array
+ */
+ public function register_sortable_columns($columns)
+ {
+ $columns['helpful-pro'] = 'helpful-pro';
+ $columns['helpful-contra'] = 'helpful-contra';
+ $columns['helpful-feedback'] = 'helpful-feedback';
+
+ return $columns;
+ }
+
+ /**
+ * Make values sortable in columns
+ *
+ * @param object $query current query.
+ * @return void
+ */
+ public function sort_columns_query($wp_query)
+ {
+ if (!is_admin()) {
+ return;
+ }
+
+ $orderby = $wp_query->get('orderby');
+
+ if ('helpful-pro' === $orderby) {
+ $meta_query = [
+ 'relation' => 'OR',
+ [
+ 'key' => 'helpful-pro',
+ 'compare' => 'NOT EXISTS',
+ 'type' => 'NUMERIC',
+ ],
+ [
+ 'key' => 'helpful-pro',
+ 'type' => 'NUMERIC',
+ ],
+ ];
+
+ $wp_query->set('meta_query', $meta_query);
+ $wp_query->set('orderby', 'meta_value');
+ }
+
+ if ('helpful-contra' === $orderby) {
+ $meta_query = [
+ 'relation' => 'OR',
+ [
+ 'key' => 'helpful-contra',
+ 'compare' => 'NOT EXISTS',
+ ],
+ [
+ 'key' => 'helpful-contra',
+ ],
+ ];
+
+ $wp_query->set('meta_query', $meta_query);
+ $wp_query->set('orderby', 'meta_value');
+ }
+
+ if ('helpful-feedback' === $orderby) {
+ $meta_query = [
+ 'relation' => 'OR',
+ [
+ 'key' => 'helpful-feedback-count',
+ 'compare' => 'NOT EXISTS',
+ 'type' => 'NUMERIC',
+ ],
+ [
+ 'key' => 'helpful-feedback-count',
+ 'type' => 'NUMERIC',
+ ],
+ ];
+
+ $wp_query->set('meta_query', $meta_query);
+ $wp_query->set('orderby', 'meta_value');
+ }
+ }
+
+ /**
+ * Sets the German language if the user has set German
+ * as language in the WordPress settings.
+ *
+ * @return string
+ */
+ public function set_datatables_language()
+ {
+ return wp_json_encode(Helpers\Values::datatables_language_string());
+ }
+}
diff --git a/core/modules/class-core.php b/core/modules/class-core.php
index bebb87c..b04de88 100644
--- a/core/modules/class-core.php
+++ b/core/modules/class-core.php
@@ -1,13 +1,15 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
use Helpful\Core\Helper;
use Helpful\Core\Helpers as Helpers;
+use Helpful\Core\Services as Services;
/* Prevent direct access */
if (!defined('ABSPATH')) {
@@ -45,6 +47,7 @@ public function __construct()
{
Helper::set_timezone();
+ add_action('init', [ & $this, 'start_session'], -1);
add_action('init', [ & $this, 'set_user_cookie'], 1);
add_action('admin_init', [ & $this, 'setup_helpful_table']);
@@ -67,6 +70,17 @@ public function __construct()
add_action('elementor/elements/categories_registered', [ & $this, 'elementor_categories']);
}
+ /**
+ * Start sessions
+ *
+ * @return void
+ */
+ public function start_session()
+ {
+ $session = new Services\Session();
+ $session->init();
+ }
+
/**
* Set users cookie with unique id
*
@@ -74,9 +88,7 @@ public function __construct()
*/
public function set_user_cookie()
{
- ob_start();
Helpers\User::set_user();
- ob_end_flush();
}
/**
diff --git a/core/modules/class-customizer.php b/core/modules/class-customizer.php
index 966f22f..c65c363 100644
--- a/core/modules/class-customizer.php
+++ b/core/modules/class-customizer.php
@@ -1,168 +1,167 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Customizer
{
- /**
- * Instance
- *
- * @var Customizer
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Customizer
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'customize_register', [ &$this, 'register_customizer' ] );
- }
-
- /**
- * Register custom customizer section/panel
- *
- * @param object $wp_customize WordPress customizer object.
- *
- * @return void
- */
- public static function register_customizer( $wp_customize )
- {
- $panel = [
- 'title' => esc_html_x( 'Helpful', 'customizer panel title', 'helpful' ),
- 'description' => esc_html_x( 'Here you can make small adjustments to Helpful.', 'customizer panel description', 'helpful' ),
- 'priority' => 10,
- ];
-
- $wp_customize->add_panel( 'helpful', $panel );
-
- /* Design Section */
-
- $section = [
- 'title' => esc_html_x( 'Design', 'customizer section title', 'helpful' ),
- 'description' => esc_html_x( 'Here you can customize the design of Helpful.', 'customizer section description', 'helpful' ),
- 'priority' => 10,
- 'panel' => 'helpful',
- ];
-
- $wp_customize->add_section( 'helpful_design', $section );
-
- /* Helpful Themes */
-
- $themes = apply_filters( 'helpful_themes', false );
- $choices = [];
-
- foreach ( $themes as $theme ) :
- $choices[ $theme['id'] ] = $theme['label'];
- endforeach;
-
- $setting = [
- 'default' => 'base',
- 'type' => 'option',
- ];
-
- $wp_customize->add_setting( 'helpful_theme', $setting );
-
- $control = [
- 'label' => esc_html_x( 'Theme', 'customizer control label', 'helpful' ),
- 'section' => 'helpful_design',
- 'settings' => 'helpful_theme',
- 'type' => 'select',
- 'choices' => $choices,
- ];
-
- $wp_customize->add_control( 'helpful_theme', $control );
-
- /* Helpful CSS */
-
- $setting = [
- 'default' => '',
- 'type' => 'option',
- ];
-
- $wp_customize->add_setting( 'helpful_css', $setting );
-
- $control = [
- 'label' => esc_html_x( 'Custom CSS', 'customizer control label', 'helpful' ),
- 'section' => 'helpful_design',
- 'settings' => 'helpful_css',
- 'type' => 'textarea',
- ];
-
- $wp_customize->add_control( 'helpful_css', $control );
-
- /* Details Section */
-
- $section = [
- 'title' => esc_html_x( 'Details', 'customizer section title', 'helpful' ),
- 'description' => esc_html_x( 'Here you can adjust the details of Helpful.', 'customizer section description', 'helpful' ),
- 'priority' => 10,
- 'panel' => 'helpful',
- ];
-
- $wp_customize->add_section( 'helpful_details', $section );
-
- /* Show Counters */
-
- $setting = [
- 'type' => 'option',
- ];
-
- $wp_customize->add_setting( 'helpful_count_hide', $setting );
-
- $control = [
- 'label' => esc_html_x( 'Hide counter', 'customizer control label', 'helpful' ),
- 'section' => 'helpful_details',
- 'settings' => 'helpful_count_hide',
- 'type' => 'checkbox',
- ];
+ /**
+ * Instance
+ *
+ * @var Customizer
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Customizer
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('customize_register', [ & $this, 'register_customizer']);
+ }
+
+ /**
+ * Register custom customizer section/panel
+ *
+ * @param object $wp_customize WordPress customizer object.
+ *
+ * @return void
+ */
+ public static function register_customizer($wp_customize)
+ {
+ $panel = [
+ 'title' => esc_html_x('Helpful', 'customizer panel title', 'helpful'),
+ 'description' => esc_html_x('Here you can make small adjustments to Helpful.', 'customizer panel description', 'helpful'),
+ 'priority' => 10,
+ ];
+
+ $wp_customize->add_panel('helpful', $panel);
+
+ /* Design Section */
+
+ $section = [
+ 'title' => esc_html_x('Design', 'customizer section title', 'helpful'),
+ 'description' => esc_html_x('Here you can customize the design of Helpful.', 'customizer section description', 'helpful'),
+ 'priority' => 10,
+ 'panel' => 'helpful',
+ ];
+
+ $wp_customize->add_section('helpful_design', $section);
+
+ /* Helpful Themes */
+
+ $themes = apply_filters('helpful_themes', false);
+ $choices = [];
+
+ foreach ($themes as $theme):
+ $choices[$theme['id']] = $theme['label'];
+ endforeach;
+
+ $setting = [
+ 'default' => 'base',
+ 'type' => 'option',
+ ];
+
+ $wp_customize->add_setting('helpful_theme', $setting);
+
+ $control = [
+ 'label' => esc_html_x('Theme', 'customizer control label', 'helpful'),
+ 'section' => 'helpful_design',
+ 'settings' => 'helpful_theme',
+ 'type' => 'select',
+ 'choices' => $choices,
+ ];
+
+ $wp_customize->add_control('helpful_theme', $control);
+
+ /* Helpful CSS */
+
+ $setting = [
+ 'default' => '',
+ 'type' => 'option',
+ ];
+
+ $wp_customize->add_setting('helpful_css', $setting);
+
+ $control = [
+ 'label' => esc_html_x('Custom CSS', 'customizer control label', 'helpful'),
+ 'section' => 'helpful_design',
+ 'settings' => 'helpful_css',
+ 'type' => 'textarea',
+ ];
+
+ $wp_customize->add_control('helpful_css', $control);
+
+ /* Details Section */
+
+ $section = [
+ 'title' => esc_html_x('Details', 'customizer section title', 'helpful'),
+ 'description' => esc_html_x('Here you can adjust the details of Helpful.', 'customizer section description', 'helpful'),
+ 'priority' => 10,
+ 'panel' => 'helpful',
+ ];
+
+ $wp_customize->add_section('helpful_details', $section);
+
+ /* Show Counters */
+
+ $setting = [
+ 'type' => 'option',
+ ];
+
+ $wp_customize->add_setting('helpful_count_hide', $setting);
+
+ $control = [
+ 'label' => esc_html_x('Hide counter', 'customizer control label', 'helpful'),
+ 'section' => 'helpful_details',
+ 'settings' => 'helpful_count_hide',
+ 'type' => 'checkbox',
+ ];
- $wp_customize->add_control( 'helpful_count_hide', $control );
+ $wp_customize->add_control('helpful_count_hide', $control);
- /* Credits */
+ /* Credits */
- $setting = [
- 'type' => 'option',
- ];
+ $setting = [
+ 'type' => 'option',
+ ];
- $wp_customize->add_setting( 'helpful_credits', $setting );
+ $wp_customize->add_setting('helpful_credits', $setting);
- $control = [
- 'label' => esc_html_x( 'Show credits', 'customizer control label', 'helpful' ),
- 'section' => 'helpful_details',
- 'settings' => 'helpful_credits',
- 'type' => 'checkbox',
- ];
+ $control = [
+ 'label' => esc_html_x('Show credits', 'customizer control label', 'helpful'),
+ 'section' => 'helpful_details',
+ 'settings' => 'helpful_credits',
+ 'type' => 'checkbox',
+ ];
- $wp_customize->add_control( 'helpful_credits', $control );
- }
-}
\ No newline at end of file
+ $wp_customize->add_control('helpful_credits', $control);
+ }
+}
diff --git a/core/modules/class-debug.php b/core/modules/class-debug.php
index e945868..ed1d97e 100644
--- a/core/modules/class-debug.php
+++ b/core/modules/class-debug.php
@@ -1,117 +1,116 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Debug
{
- /**
- * Class instance
- *
- * @var Debug
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Debug
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-
- /**
- * Constructor.
- *
- * @return void
- */
- public function __construct()
- {
- add_filter( 'helpful_debug_fields', [ &$this, 'debug_fields' ], 1 );
- add_filter( 'debug_information', [ &$this, 'debug_information' ] );
- }
-
- /**
- * Debug Informations for Site Health Page.
- *
- * @param array $info
- *
- * @return array
- */
- public function debug_information( $info )
- {
- $fields = [];
-
- $info['helpful'] = [
- 'label' => esc_html_x( 'Helpful', 'debug label', 'helpful' ),
- 'description' => esc_html_x( 'If you have problems with the plugin, these values can help you with support.', 'debug description', 'helpful' ),
- 'fields' => apply_filters( 'helpful_debug_fields', $fields ),
- 'private' => true,
- ];
-
- return $info;
- }
-
- /**
- * Fields for Debug Informations.
- *
- * @param array $fields
- *
- * @return array
- */
- public function debug_fields( $fields )
- {
- $plugin = Helper::get_plugin_data();
-
- $fields['version'] = [
- 'label' => esc_html_x( 'Helpful version', 'debug field label', 'helpful' ),
- 'value' => $plugin['Version'],
- ];
-
- $fields['wordpress'] = [
- 'label' => esc_html_x( 'WordPress version', 'debug field label', 'helpful' ),
- 'value' => get_bloginfo( 'version' ),
- ];
-
- $fields['php'] = [
- 'label' => esc_html_x( 'PHP version', 'debug field label', 'helpful' ),
- 'value' => phpversion( 'tidy' ),
- ];
-
- $fields['pro'] = [
- 'label' => esc_html_x( 'Pro totals', 'debug field label', 'helpful' ),
- 'value' => Helpers\Stats::get_pro_all(),
- ];
-
- $fields['contra'] = [
- 'label' => esc_html_x( 'Contra totals', 'debug field label', 'helpful' ),
- 'value' => Helpers\Stats::get_contra_all(),
- ];
-
- $fields['feedback'] = [
- 'label' => esc_html_x( 'Feedback totals', 'debug field label', 'helpful' ),
- 'value' => Helpers\Feedback::get_feedback_count( null ),
- ];
-
- return $fields;
- }
-}
\ No newline at end of file
+ /**
+ * Class instance
+ *
+ * @var Debug
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Debug
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_filter('helpful_debug_fields', [ & $this, 'debug_fields'], 1);
+ add_filter('debug_information', [ & $this, 'debug_information']);
+ }
+
+ /**
+ * Debug Informations for Site Health Page.
+ *
+ * @param array $info
+ *
+ * @return array
+ */
+ public function debug_information($info)
+ {
+ $fields = [];
+
+ $info['helpful'] = [
+ 'label' => esc_html_x('Helpful', 'debug label', 'helpful'),
+ 'description' => esc_html_x('If you have problems with the plugin, these values can help you with support.', 'debug description', 'helpful'),
+ 'fields' => apply_filters('helpful_debug_fields', $fields),
+ 'private' => true,
+ ];
+
+ return $info;
+ }
+
+ /**
+ * Fields for Debug Informations.
+ *
+ * @param array $fields
+ *
+ * @return array
+ */
+ public function debug_fields($fields)
+ {
+ $plugin = Helper::get_plugin_data();
+
+ $fields['version'] = [
+ 'label' => esc_html_x('Helpful version', 'debug field label', 'helpful'),
+ 'value' => $plugin['Version'],
+ ];
+
+ $fields['wordpress'] = [
+ 'label' => esc_html_x('WordPress version', 'debug field label', 'helpful'),
+ 'value' => get_bloginfo('version'),
+ ];
+
+ $fields['php'] = [
+ 'label' => esc_html_x('PHP version', 'debug field label', 'helpful'),
+ 'value' => phpversion('tidy'),
+ ];
+
+ $fields['pro'] = [
+ 'label' => esc_html_x('Pro totals', 'debug field label', 'helpful'),
+ 'value' => Helpers\Stats::get_pro_all(),
+ ];
+
+ $fields['contra'] = [
+ 'label' => esc_html_x('Contra totals', 'debug field label', 'helpful'),
+ 'value' => Helpers\Stats::get_contra_all(),
+ ];
+
+ $fields['feedback'] = [
+ 'label' => esc_html_x('Feedback totals', 'debug field label', 'helpful'),
+ 'value' => Helpers\Feedback::get_feedback_count(null),
+ ];
+
+ return $fields;
+ }
+}
diff --git a/core/modules/class-elementor-widget.php b/core/modules/class-elementor-widget.php
index 99822a0..2095185 100644
--- a/core/modules/class-elementor-widget.php
+++ b/core/modules/class-elementor-widget.php
@@ -1,220 +1,219 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Elementor_Widget extends \Elementor\Widget_Base
{
- /**
- * Get widget name.
- *
- * @return string widget name.
- */
- public function get_name()
- {
- return 'helpful-widget';
- }
-
- /**
- * Get widget title.
- *
- * @return string widget title.
- */
- public function get_title()
- {
- return esc_html_x( 'Helpful', 'elementor widget name', 'helpful' );
- }
-
- /**
- * Get widget icon.
- *
- * @return string widget icon.
- */
- public function get_icon()
- {
- return 'fa fa-thumbs-up';
- }
-
- /**
- * Get widget categories.
- *
- * @return array widget categories.
- */
- public function get_categories()
- {
- return [ 'general' ];
- }
-
- /**
- * Register widget controls.
- *
- * @return void
- */
- protected function _register_controls()
- {
- $this->start_controls_section(
- 'general',
- [
- 'label' => esc_html_x( 'General', 'elementor tab name', 'helpful' ),
- 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
- ]
- );
-
- $this->add_control(
- 'helpful_credits',
- [
- 'label' => esc_html_x( 'Show credits', 'elementor option name', 'helpful' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'return_value' => 'on',
- 'default' => 'on',
- ]
- );
-
- $this->add_control(
- 'helpful_counter',
- [
- 'label' => esc_html_x( 'Show counter', 'elementor option name', 'helpful' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'return_value' => 'on',
- 'default' => 'on',
- ]
- );
-
- $this->end_controls_section();
-
- $this->start_controls_section(
- 'texts',
- [
- 'label' => esc_html_x( 'Texts', 'elementor option name', 'helpful' ),
- 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
- ]
- );
-
- $this->add_control(
- 'helpful_heading',
- [
- 'label' => esc_html_x( 'Headline', 'elementor option name', 'helpful' ),
- 'label_block' => true,
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'default' => get_option( 'helpful_heading' ),
- ]
- );
-
- $this->add_control(
- 'helpful_content',
- [
- 'label' => esc_html_x( 'Content', 'elementor option name', 'helpful' ),
- 'label_block' => true,
- 'type' => \Elementor\Controls_Manager::TEXTAREA,
- 'default' => get_option( 'helpful_content' ),
- ]
- );
-
- $this->add_control(
- 'helpful_pro',
- [
- 'label' => esc_html_x( 'Pro', 'elementor option name', 'helpful' ),
- 'label_block' => true,
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'default' => get_option( 'helpful_pro' ),
- ]
- );
-
- $this->add_control(
- 'helpful_contra',
- [
- 'label' => esc_html_x( 'Contra', 'elementor option name', 'helpful' ),
- 'label_block' => true,
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'default' => get_option( 'helpful_contra' ),
- ]
- );
-
- $this->end_controls_section();
-
- $this->start_controls_section(
- 'advanced',
- [
- 'label' => esc_html_x( 'Advanced', 'elementor option name', 'helpful' ),
- 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
- ]
- );
-
- $themes = apply_filters( 'helpful_themes', false );
- $choices = [];
-
- foreach ( $themes as $theme ) :
- $choices[ $theme['id'] ] = $theme['label'];
- endforeach;
-
- $this->add_control(
- 'helpful_theme',
- [
- 'label' => esc_html_x( 'Theme', 'elementor option name', 'helpful' ),
- 'description' => esc_html_x( 'This option overrides the Helpful theme and applies to all Helpful on the site. You will also need to reload the page to see the changes.', 'elementor option description', 'helpful' ),
- 'type' => \Elementor\Controls_Manager::SELECT,
- 'options' => $choices,
- 'default' => get_option( 'helpful_theme' ),
- ]
- );
-
- $this->add_control(
- 'helpful_css',
- [
- 'label' => esc_html_x( 'Custom CSS', 'elementor option name', 'helpful' ),
- 'label_block' => true,
- 'description' => esc_html_x( 'Here you can use your own CSS. Use selector to address Helpful.', 'elementor option description', 'helpful' ),
- 'type' => \Elementor\Controls_Manager::CODE,
- 'default' => 'selector {}',
- 'language' => 'css',
- ]
- );
-
- $this->end_controls_section();
- }
-
- /**
- * Render widget output on the frontend.
- *
- * @return void
- */
- protected function render()
- {
- $settings = $this->get_settings_for_display();
-
- $options = [
- "button_pro='{$settings['helpful_pro']}'",
- "button_contra='{$settings['helpful_contra']}'",
- "heading='{$settings['helpful_heading']}'",
- "content='{$settings['helpful_content']}'",
- ];
-
- update_option( 'helpful_theme', $settings['helpful_theme'] );
-
- if ( 'on' !== $settings['helpful_credits'] ) {
- $options[] = "credits='false'";
- }
-
- if ( 'on' === (string) $settings['helpful_counter'] ) {
- $options[] = "counter='on'";
- }
-
- echo '';
- echo do_shortcode( '[helpful ' . implode( ' ', $options ) . ']' );
- }
-}
\ No newline at end of file
+ /**
+ * Get widget name.
+ *
+ * @return string widget name.
+ */
+ public function get_name()
+ {
+ return 'helpful-widget';
+ }
+
+ /**
+ * Get widget title.
+ *
+ * @return string widget title.
+ */
+ public function get_title()
+ {
+ return esc_html_x('Helpful', 'elementor widget name', 'helpful');
+ }
+
+ /**
+ * Get widget icon.
+ *
+ * @return string widget icon.
+ */
+ public function get_icon()
+ {
+ return 'fa fa-thumbs-up';
+ }
+
+ /**
+ * Get widget categories.
+ *
+ * @return array widget categories.
+ */
+ public function get_categories()
+ {
+ return ['general'];
+ }
+
+ /**
+ * Register widget controls.
+ *
+ * @return void
+ */
+ protected function _register_controls()
+ {
+ $this->start_controls_section(
+ 'general',
+ [
+ 'label' => esc_html_x('General', 'elementor tab name', 'helpful'),
+ 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_credits',
+ [
+ 'label' => esc_html_x('Show credits', 'elementor option name', 'helpful'),
+ 'type' => \Elementor\Controls_Manager::SWITCHER,
+ 'return_value' => 'on',
+ 'default' => 'on',
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_counter',
+ [
+ 'label' => esc_html_x('Show counter', 'elementor option name', 'helpful'),
+ 'type' => \Elementor\Controls_Manager::SWITCHER,
+ 'return_value' => 'on',
+ 'default' => 'on',
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'texts',
+ [
+ 'label' => esc_html_x('Texts', 'elementor option name', 'helpful'),
+ 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_heading',
+ [
+ 'label' => esc_html_x('Headline', 'elementor option name', 'helpful'),
+ 'label_block' => true,
+ 'type' => \Elementor\Controls_Manager::TEXT,
+ 'default' => get_option('helpful_heading'),
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_content',
+ [
+ 'label' => esc_html_x('Content', 'elementor option name', 'helpful'),
+ 'label_block' => true,
+ 'type' => \Elementor\Controls_Manager::TEXTAREA,
+ 'default' => get_option('helpful_content'),
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_pro',
+ [
+ 'label' => esc_html_x('Pro', 'elementor option name', 'helpful'),
+ 'label_block' => true,
+ 'type' => \Elementor\Controls_Manager::TEXT,
+ 'default' => get_option('helpful_pro'),
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_contra',
+ [
+ 'label' => esc_html_x('Contra', 'elementor option name', 'helpful'),
+ 'label_block' => true,
+ 'type' => \Elementor\Controls_Manager::TEXT,
+ 'default' => get_option('helpful_contra'),
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'advanced',
+ [
+ 'label' => esc_html_x('Advanced', 'elementor option name', 'helpful'),
+ 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
+ ]
+ );
+
+ $themes = apply_filters('helpful_themes', false);
+ $choices = [];
+
+ foreach ($themes as $theme):
+ $choices[$theme['id']] = $theme['label'];
+ endforeach;
+
+ $this->add_control(
+ 'helpful_theme',
+ [
+ 'label' => esc_html_x('Theme', 'elementor option name', 'helpful'),
+ 'description' => esc_html_x('This option overrides the Helpful theme and applies to all Helpful on the site. You will also need to reload the page to see the changes.', 'elementor option description', 'helpful'),
+ 'type' => \Elementor\Controls_Manager::SELECT,
+ 'options' => $choices,
+ 'default' => get_option('helpful_theme'),
+ ]
+ );
+
+ $this->add_control(
+ 'helpful_css',
+ [
+ 'label' => esc_html_x('Custom CSS', 'elementor option name', 'helpful'),
+ 'label_block' => true,
+ 'description' => esc_html_x('Here you can use your own CSS. Use selector to address Helpful.', 'elementor option description', 'helpful'),
+ 'type' => \Elementor\Controls_Manager::CODE,
+ 'default' => 'selector {}',
+ 'language' => 'css',
+ ]
+ );
+
+ $this->end_controls_section();
+ }
+
+ /**
+ * Render widget output on the frontend.
+ *
+ * @return void
+ */
+ protected function render()
+ {
+ $settings = $this->get_settings_for_display();
+
+ $options = [
+ "button_pro='{$settings['helpful_pro']}'",
+ "button_contra='{$settings['helpful_contra']}'",
+ "heading='{$settings['helpful_heading']}'",
+ "content='{$settings['helpful_content']}'",
+ ];
+
+ update_option('helpful_theme', $settings['helpful_theme']);
+
+ if ('on' !== $settings['helpful_credits']) {
+ $options[] = "credits='false'";
+ }
+
+ if ('on' === (string) $settings['helpful_counter']) {
+ $options[] = "counter='on'";
+ }
+
+ echo '';
+ echo do_shortcode('[helpful ' . implode(' ', $options) . ']');
+ }
+}
diff --git a/core/modules/class-feedback-admin.php b/core/modules/class-feedback-admin.php
index 4e2dd44..da7dc77 100644
--- a/core/modules/class-feedback-admin.php
+++ b/core/modules/class-feedback-admin.php
@@ -1,8 +1,9 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
@@ -31,9 +32,9 @@ class Feedback_Admin
*/
public function __construct()
{
- if (Helper::is_feedback_disabled()):
+ if (Helper::is_feedback_disabled()) {
return;
- endif;
+ }
add_action('admin_menu', [ & $this, 'add_submenu']);
add_action('admin_enqueue_scripts', [ & $this, 'enqueue_scripts']);
diff --git a/core/modules/class-frontend.php b/core/modules/class-frontend.php
index ffd59fa..e6a8ac0 100644
--- a/core/modules/class-frontend.php
+++ b/core/modules/class-frontend.php
@@ -1,8 +1,9 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
@@ -464,7 +465,7 @@ public function helpful($atts, $content = '')
$helpful['shortcode_class'] = $class;
$object = new Services\Helpful($helpful['post_id'], $helpful);
- return $object->get_template();;
+ return $object->get_template();
}
/**
diff --git a/core/modules/class-maintenance.php b/core/modules/class-maintenance.php
index 44ec4ea..d7fd21c 100644
--- a/core/modules/class-maintenance.php
+++ b/core/modules/class-maintenance.php
@@ -1,130 +1,127 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Maintenance
{
- /**
- * Class instance
- *
- * @var Maintenance
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Maintenance
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'admin_enqueue_scripts', [ &$this, 'enqueue_scripts' ] );
- add_action( 'wp_ajax_helpful_perform_maintenance', [ &$this, 'maintenance' ] );
- add_action( 'admin_init', [ &$this, 'maintenance_after_update' ] );
- }
-
- /**
- * Enqueue styles and scripts
- *
- * @param string $hook_suffix
- *
- * @return void
- */
- public function enqueue_scripts( $hook_suffix )
- {
- if ( 'toplevel_page_helpful' !== $hook_suffix ) {
- return;
- }
-
- $plugin = Helper::get_plugin_data();
-
- $nonce = wp_create_nonce( 'helpful_maintenance_nonce' );
- $file = plugins_url( '/core/assets/js/admin-maintenance.js', HELPFUL_FILE );
-
- wp_enqueue_script( 'helpful-maintenance', $file, [ 'jquery' ], $plugin['Version'], true );
-
- $vars = [
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
- 'data' => [
- 'action' => 'helpful_perform_maintenance',
- '_wpnonce' => $nonce,
- ],
- ];
-
- wp_localize_script( 'helpful-maintenance', 'helpful_maintenance', $vars );
- }
-
- /**
- * Ajax action for performing maintenance.
- *
- * @see class-helpful-helper-optimize.php
- *
- * @return void
- */
- public function maintenance()
- {
- check_admin_referer( 'helpful_maintenance_nonce' );
-
- $response = Helpers\Optimize::optimize_plugin();
- $response = apply_filters( 'helpful_maintenance', $response );
-
- wp_send_json( $response );
- }
-
- /**
- * Informs the user to perform maintenance.
- *
- * @return void
- */
- public function maintenance_after_update()
- {
- if ( 'on' === get_option( 'helpful_notes' ) ) {
- return;
- }
-
- /**
- * Deletes the old transient from version 4.1.4
- */
- if ( get_transient( 'helpful_updated' ) ) {
- delete_transient( 'helpful_updated' );
- }
-
- $plugin = Helper::get_plugin_data();
- $option = get_option( 'helpful_plugin_version' );
-
- if ( $option === $plugin['Version'] ) {
- return;
- }
-
- $response = Helpers\Optimize::optimize_plugin();
-
- update_option( 'helpful_plugin_version', $plugin['Version'] );
- }
-}
\ No newline at end of file
+ /**
+ * Class instance
+ *
+ * @var Maintenance
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Maintenance
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('admin_enqueue_scripts', [ & $this, 'enqueue_scripts']);
+ add_action('wp_ajax_helpful_perform_maintenance', [ & $this, 'maintenance']);
+ add_action('admin_init', [ & $this, 'maintenance_after_update']);
+ }
+
+ /**
+ * Enqueue styles and scripts
+ *
+ * @param string $hook_suffix
+ *
+ * @return void
+ */
+ public function enqueue_scripts($hook_suffix)
+ {
+ if ('toplevel_page_helpful' !== $hook_suffix) {
+ return;
+ }
+
+ $plugin = Helper::get_plugin_data();
+
+ $nonce = wp_create_nonce('helpful_maintenance_nonce');
+ $file = plugins_url('/core/assets/js/admin-maintenance.js', HELPFUL_FILE);
+
+ wp_enqueue_script('helpful-maintenance', $file, ['jquery'], $plugin['Version'], true);
+
+ $vars = [
+ 'ajax_url' => admin_url('admin-ajax.php'),
+ 'data' => [
+ 'action' => 'helpful_perform_maintenance',
+ '_wpnonce' => $nonce,
+ ],
+ ];
+
+ wp_localize_script('helpful-maintenance', 'helpful_maintenance', $vars);
+ }
+
+ /**
+ * Ajax action for performing maintenance.
+ *
+ * @see class-helpful-helper-optimize.php
+ *
+ * @return void
+ */
+ public function maintenance()
+ {
+ check_admin_referer('helpful_maintenance_nonce');
+ $response = Helpers\Optimize::optimize_plugin();
+ $response = apply_filters('helpful_maintenance', $response);
+ wp_send_json($response);
+ }
+
+ /**
+ * Informs the user to perform maintenance.
+ *
+ * @return void
+ */
+ public function maintenance_after_update()
+ {
+ if ('on' === get_option('helpful_notes')) {
+ return;
+ }
+
+ /**
+ * Deletes the old transient from version 4.1.4
+ */
+ if (get_transient('helpful_updated')) {
+ delete_transient('helpful_updated');
+ }
+
+ $plugin = Helper::get_plugin_data();
+ $option = get_option('helpful_plugin_version');
+
+ if ($option === $plugin['Version']) {
+ return;
+ }
+
+ $response = Helpers\Optimize::optimize_plugin();
+
+ update_option('helpful_plugin_version', $plugin['Version']);
+ }
+}
diff --git a/core/modules/class-metabox.php b/core/modules/class-metabox.php
index 85e940c..980ec6b 100644
--- a/core/modules/class-metabox.php
+++ b/core/modules/class-metabox.php
@@ -1,157 +1,156 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Metabox
{
- /**
- * Class instance
- *
- * @var Metabox
- */
- public static $instance;
-
- /**
- * Set instance and fire class.
- *
- * @return Metabox
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- if ( ! get_option( 'helpful_metabox' ) ) {
- return;
- }
-
- add_action( 'add_meta_boxes', [ &$this, 'add_metabox' ] );
-
- add_action( 'save_post', [ &$this, 'save_data' ] );
- add_action( 'save_post', [ &$this, 'save_data' ], 10, 1 );
- }
-
- /**
- * Add metabox to post types.
- *
- * @return void
- */
- public function add_metabox()
- {
- $post_types = get_option( 'helpful_post_types' );
-
- if ( isset( $post_types ) && is_array( $post_types ) ) {
- add_meta_box(
- 'helpful-meta-box',
- esc_html_x( 'Helpful', 'meta box name', 'helpful' ),
- [ $this, 'render_metabox' ],
- $post_types
- );
- }
- }
-
- /**
- * Render metabox content.
- *
- * @global $post
- *
- * @return void
- */
- public function render_metabox()
- {
- global $post;
-
- $pro = Helpers\Stats::get_pro( $post->ID );
- $pro_percent = Helpers\Stats::get_pro( $post->ID, true );
- $contra = Helpers\Stats::get_contra( $post->ID );
- $contra_percent = Helpers\Stats::get_contra( $post->ID, true );
- $hide = get_post_meta( $post->ID, 'helpful_hide_on_post', true );
- $hide_feedback = get_post_meta( $post->ID, 'helpful_hide_feedback_on_post', true );
- $receivers = get_post_meta( $post->ID, 'helpful_feedback_receivers', true );
-
- $helpful_heading = get_post_meta( $post->ID, 'helpful_heading', true );
- $helpful_pro = get_post_meta( $post->ID, 'helpful_pro', true );
- $helpful_contra = get_post_meta( $post->ID, 'helpful_contra', true );
- $helpful_exists = get_post_meta( $post->ID, 'helpful_exists', true );
- $helpful_after_pro = get_post_meta( $post->ID, 'helpful_after_pro', true );
- $helpful_after_contra = get_post_meta( $post->ID, 'helpful_after_contra', true );
- $helpful_after_fallback = get_post_meta( $post->ID, 'helpful_after_fallback', true );
-
- wp_nonce_field( 'helpful_save_metabox', 'helpful_metabox_nonce' );
-
- include HELPFUL_PATH . 'templates/admin-metabox.php';
- }
-
- /**
- * Save meta box data.
- *
- * @param integer $post_id post id.
- *
- * @return void
- */
- public function save_data( $post_id )
- {
- if ( ! isset( $_POST['helpful_metabox_nonce'] ) || ! wp_verify_nonce( $_POST['helpful_metabox_nonce'], 'helpful_save_metabox' ) ) {
- return;
- }
-
- if ( isset( $_POST['helpful_remove_data'] ) && 'yes' === $_POST['helpful_remove_data'] ) {
- Helpers\Values::remove_data( $post_id );
- }
-
- if ( isset( $_POST['helpful_hide_on_post'] ) ) {
- update_post_meta( $post_id, 'helpful_hide_on_post', 'on' );
- } else {
- update_post_meta( $post_id, 'helpful_hide_on_post', 'off' );
- }
-
- if ( isset( $_POST['helpful_hide_feedback_on_post'] ) ) {
- update_post_meta( $post_id, 'helpful_hide_feedback_on_post', 'on' );
- } else {
- update_post_meta( $post_id, 'helpful_hide_feedback_on_post', 'off' );
- }
-
- $metas = [
- 'helpful_heading',
- 'helpful_pro',
- 'helpful_contra',
- 'helpful_exists',
- 'helpful_after_pro',
- 'helpful_after_contra',
- 'helpful_after_fallback',
- 'helpful_feedback_receivers',
- ];
-
- foreach ( $metas as $meta ) :
- if ( isset( $_POST[ $meta ] ) && '' !== trim( $_POST[ $meta ] ) ) {
- update_post_meta( $post_id, $meta, $_POST[ $meta ] );
- } else {
- delete_post_meta( $post_id, $meta );
- }
- endforeach;
- }
-}
\ No newline at end of file
+ /**
+ * Class instance
+ *
+ * @var Metabox
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class.
+ *
+ * @return Metabox
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ if (!get_option('helpful_metabox')) {
+ return;
+ }
+
+ add_action('add_meta_boxes', [ & $this, 'add_metabox']);
+
+ add_action('save_post', [ & $this, 'save_data']);
+ add_action('save_post', [ & $this, 'save_data'], 10, 1);
+ }
+
+ /**
+ * Add metabox to post types.
+ *
+ * @return void
+ */
+ public function add_metabox()
+ {
+ $post_types = get_option('helpful_post_types');
+
+ if (isset($post_types) && is_array($post_types)) {
+ add_meta_box(
+ 'helpful-meta-box',
+ esc_html_x('Helpful', 'meta box name', 'helpful'),
+ [$this, 'render_metabox'],
+ $post_types
+ );
+ }
+ }
+
+ /**
+ * Render metabox content.
+ *
+ * @global $post
+ *
+ * @return void
+ */
+ public function render_metabox()
+ {
+ global $post;
+
+ $pro = Helpers\Stats::get_pro($post->ID);
+ $pro_percent = Helpers\Stats::get_pro($post->ID, true);
+ $contra = Helpers\Stats::get_contra($post->ID);
+ $contra_percent = Helpers\Stats::get_contra($post->ID, true);
+ $hide = get_post_meta($post->ID, 'helpful_hide_on_post', true);
+ $hide_feedback = get_post_meta($post->ID, 'helpful_hide_feedback_on_post', true);
+ $receivers = get_post_meta($post->ID, 'helpful_feedback_receivers', true);
+
+ $helpful_heading = get_post_meta($post->ID, 'helpful_heading', true);
+ $helpful_pro = get_post_meta($post->ID, 'helpful_pro', true);
+ $helpful_contra = get_post_meta($post->ID, 'helpful_contra', true);
+ $helpful_exists = get_post_meta($post->ID, 'helpful_exists', true);
+ $helpful_after_pro = get_post_meta($post->ID, 'helpful_after_pro', true);
+ $helpful_after_contra = get_post_meta($post->ID, 'helpful_after_contra', true);
+ $helpful_after_fallback = get_post_meta($post->ID, 'helpful_after_fallback', true);
+
+ wp_nonce_field('helpful_save_metabox', 'helpful_metabox_nonce');
+
+ include HELPFUL_PATH . 'templates/admin-metabox.php';
+ }
+
+ /**
+ * Save meta box data.
+ *
+ * @param integer $post_id post id.
+ *
+ * @return void
+ */
+ public function save_data($post_id)
+ {
+ if (!isset($_POST['helpful_metabox_nonce']) || !wp_verify_nonce($_POST['helpful_metabox_nonce'], 'helpful_save_metabox')) {
+ return;
+ }
+
+ if (isset($_POST['helpful_remove_data']) && 'yes' === $_POST['helpful_remove_data']) {
+ Helpers\Values::remove_data($post_id);
+ }
+
+ if (isset($_POST['helpful_hide_on_post'])) {
+ update_post_meta($post_id, 'helpful_hide_on_post', 'on');
+ } else {
+ update_post_meta($post_id, 'helpful_hide_on_post', 'off');
+ }
+
+ if (isset($_POST['helpful_hide_feedback_on_post'])) {
+ update_post_meta($post_id, 'helpful_hide_feedback_on_post', 'on');
+ } else {
+ update_post_meta($post_id, 'helpful_hide_feedback_on_post', 'off');
+ }
+
+ $metas = [
+ 'helpful_heading',
+ 'helpful_pro',
+ 'helpful_contra',
+ 'helpful_exists',
+ 'helpful_after_pro',
+ 'helpful_after_contra',
+ 'helpful_after_fallback',
+ 'helpful_feedback_receivers',
+ ];
+
+ foreach ($metas as $meta):
+ if (isset($_POST[$meta]) && '' !== trim($_POST[$meta])) {
+ update_post_meta($post_id, $meta, $_POST[$meta]);
+ } else {
+ delete_post_meta($post_id, $meta);
+ }
+ endforeach;
+ }
+}
diff --git a/core/modules/class-widget.php b/core/modules/class-widget.php
index 9683938..2ce75ff 100644
--- a/core/modules/class-widget.php
+++ b/core/modules/class-widget.php
@@ -1,10 +1,9 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Modules
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Modules;
@@ -63,11 +62,7 @@ public function __construct()
*/
public function enqueue_scripts($hook_suffix)
{
- if ('index.php' !== $hook_suffix) {
- return;
- }
-
- if (get_option('helpful_widget')) {
+ if ('index.php' !== $hook_suffix || get_option('helpful_widget')) {
return;
}
@@ -248,23 +243,23 @@ public function register_cronjob()
{
$years = Helpers\Stats::get_years();
- if ($years) {
- $stats = Helpers\Stats::get_widget_stats();
-
- foreach ($years as $year) :
- Helpers\Stats::get_stats_today($year);
- Helpers\Stats::get_stats_yesterday($year);
- Helpers\Stats::get_stats_week($year);
- Helpers\Stats::get_stats_month($year);
- Helpers\Stats::get_stats_year($year);
- Helpers\Stats::get_stats_total();
- endforeach;
-
- if (isset($widget_stats['feedback_items'])) {
- foreach ( $widget_stats['feedback_items'] as $feedback ) :
- Helpers\Feedback::get_feedback( $feedback );
- endforeach;
- }
- }
+ if ($years) {
+ $stats = Helpers\Stats::get_widget_stats();
+
+ foreach ($years as $year):
+ Helpers\Stats::get_stats_today($year);
+ Helpers\Stats::get_stats_yesterday($year);
+ Helpers\Stats::get_stats_week($year);
+ Helpers\Stats::get_stats_month($year);
+ Helpers\Stats::get_stats_year($year);
+ Helpers\Stats::get_stats_total();
+ endforeach;
+
+ if (isset($widget_stats['feedback_items'])) {
+ foreach ($widget_stats['feedback_items'] as $feedback):
+ Helpers\Feedback::get_feedback($feedback);
+ endforeach;
+ }
+ }
}
}
diff --git a/core/services/class-csv.php b/core/services/class-csv.php
index fb5b235..95553dd 100644
--- a/core/services/class-csv.php
+++ b/core/services/class-csv.php
@@ -1,8 +1,9 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Services
+ * @version 4.4.50
+ * @since 4.4.49
*/
namespace Helpful\Core\Services;
diff --git a/core/services/class-helpful.php b/core/services/class-helpful.php
index ea1fd40..f03b319 100644
--- a/core/services/class-helpful.php
+++ b/core/services/class-helpful.php
@@ -1,8 +1,9 @@
- * @version 4.4.47
+ * @package Helpful
+ * @subpackage Core\Services
+ * @version 4.4.50
+ * @since 4.4.47
*/
namespace Helpful\Core\Services;
diff --git a/core/services/class-options.php b/core/services/class-options.php
index bde3fdd..40cc9be 100644
--- a/core/services/class-options.php
+++ b/core/services/class-options.php
@@ -1,8 +1,9 @@
+ * @package Helpful
+ * @subpackage Core\Services
* @version 4.4.47
+ * @since 4.4.47
*/
namespace Helpful\Core\Services;
diff --git a/core/services/class-session.php b/core/services/class-session.php
new file mode 100644
index 0000000..ad05022
--- /dev/null
+++ b/core/services/class-session.php
@@ -0,0 +1,101 @@
+maybe_start_session();
+ }
+
+ /**
+ * @return bool
+ */
+ public function should_start_session()
+ {
+ $start_session = true;
+
+ if (!empty($_SERVER['REQUEST_URI'])) {
+ $uri = ltrim($_SERVER['REQUEST_URI'], '/');
+ $uri = untrailingslashit($uri);
+
+ if (false !== strpos($uri, 'feed=')) {
+ $start_session = false;
+ }
+
+ if (is_admin() && false === strpos($uri, 'wp-admin/admin-ajax.php')) {
+ $start_session = false;
+ }
+
+ if (false !== strpos($uri, 'wp_scrape_key')) {
+ $start_session = false;
+ }
+ }
+
+ if (get_option('helpful_sessions_false')) {
+ $start_session = false;
+ }
+
+ return apply_filters('helpful/session/start', $start_session);
+ }
+
+ /**
+ * @return void
+ */
+ public function maybe_start_session()
+ {
+ if (!$this->should_start_session()) {
+ return;
+ }
+
+ if (!session_id() && !headers_sent()) {
+ session_start();
+ }
+ }
+}
diff --git a/core/services/class-xml.php b/core/services/class-xml.php
index cfda479..cd18c52 100644
--- a/core/services/class-xml.php
+++ b/core/services/class-xml.php
@@ -1,8 +1,9 @@
- * @version 4.4.47
+ * @package Helpful
+ * @subpackage Core\Services
+ * @version 4.4.50
+ * @since 4.4.47
*/
namespace Helpful\Core\Services;
diff --git a/core/tabs/class-design.php b/core/tabs/class-design.php
index a80ace4..c03559b 100644
--- a/core/tabs/class-design.php
+++ b/core/tabs/class-design.php
@@ -1,97 +1,96 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
+use Helpful\Core\Helper;
use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Vendor as Vendor;
-use Helpful\Core\Helper;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Design
{
- /**
- * Instance
- *
- * @var Design
- */
- public static $instance;
+ /**
+ * Instance
+ *
+ * @var Design
+ */
+ public static $instance;
- /**
- * Class constructor.
- */
- public function __construct()
- {
- add_filter( 'helpful_get_admin_tabs', [ &$this, 'register_tab' ], 10, 2 );
- add_action( 'wp_head', [ &$this, 'custom_css' ], PHP_INT_MAX );
- }
+ /**
+ * Class constructor.
+ */
+ public function __construct()
+ {
+ add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2);
+ add_action('wp_head', [ & $this, 'custom_css'], PHP_INT_MAX);
+ }
- /**
- * Set instance and fire class
- *
- * @return Design
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
+ /**
+ * Set instance and fire class
+ *
+ * @return Design
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
- return self::$instance;
- }
+ return self::$instance;
+ }
- /**
- * Add tab to filter
- *
- * @param array $tabs current tabs.
- *
- * @return array
- */
- public function register_tab( $tabs, $current )
- {
- $query = [];
- $query['autofocus[section]'] = 'helpful_design';
- $section_link = add_query_arg( $query, admin_url( 'customize.php' ) );
+ /**
+ * Add tab to filter
+ *
+ * @param array $tabs current tabs.
+ *
+ * @return array
+ */
+ public function register_tab($tabs, $current)
+ {
+ $query = [];
+ $query['autofocus[section]'] = 'helpful_design';
+ $section_link = add_query_arg($query, admin_url('customize.php'));
- $tabs['design'] = [
- 'id' => 'design',
- 'name' => esc_html_x( 'Design', 'tab name', 'helpful' ),
- 'href' => $section_link,
- ];
+ $tabs['design'] = [
+ 'id' => 'design',
+ 'name' => esc_html_x('Design', 'tab name', 'helpful'),
+ 'href' => $section_link,
+ ];
- return $tabs;
- }
+ return $tabs;
+ }
- /**
- * Print custom css to wp_head.
- *
- * @return void
- */
- public function custom_css()
- {
- $custom_css = get_option( 'helpful_css' );
+ /**
+ * Print custom css to wp_head.
+ *
+ * @return void
+ */
+ public function custom_css()
+ {
+ $custom_css = get_option('helpful_css');
- $parser = new Vendor\Css_Parser();
+ $parser = new Vendor\Css_Parser();
- $parser->load_string( $custom_css );
+ $parser->load_string($custom_css);
- $parser->parse();
+ $parser->parse();
- $custom_css = $parser->glue();
+ $custom_css = $parser->glue();
- if ( $custom_css && '' !== trim( $custom_css ) ) {
- echo '';
- echo '';
- echo '';
- }
- }
+ if ($custom_css && '' !== trim($custom_css)) {
+ echo '';
+ echo '';
+ echo '';
+ }
+ }
}
diff --git a/core/tabs/class-details.php b/core/tabs/class-details.php
index 4072413..823f4ba 100644
--- a/core/tabs/class-details.php
+++ b/core/tabs/class-details.php
@@ -1,156 +1,155 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Details
{
- /**
- * Class instance
- *
- * @var Details
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Details
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'admin_init', [ &$this, 'register_settings' ] );
-
- add_filter( 'helpful_get_admin_tabs', [ &$this, 'register_tab' ], 10, 2 );
- add_action( 'helpful_tabs_content', [ &$this, 'register_tab_content' ] );
-
- add_action( 'helpful_tab_details_before', [ &$this, 'register_tab_alerts' ] );
- }
-
- /**
- * Register settings for admin page
- *
- * @return void
- */
- public function register_settings()
- {
- $fields = [
- 'helpful_credits',
- 'helpful_hide_in_content',
- 'helpful_post_types',
- 'helpful_exists_hide',
- 'helpful_count_hide',
- 'helpful_widget',
- 'helpful_widget_amount',
- 'helpful_widget_pro',
- 'helpful_widget_contra',
- 'helpful_widget_pro_recent',
- 'helpful_widget_contra_recent',
- 'helpful_only_once',
- 'helpful_percentages',
- 'helpful_form_status_pro',
- 'helpful_form_email_pro',
- 'helpful_form_status_contra',
- 'helpful_form_email_contra',
- 'helpful_metabox',
- 'helpful_widget_hide_publication',
- 'helpful_hide_admin_columns',
- 'helpful_shrink_admin_columns',
- 'helpful_feedback_widget',
- 'helpful_feedback_disabled',
- 'helpful_wordpress_user',
- 'helpful_ip_user',
- ];
-
- $fields = apply_filters( 'helpful_details_settings_group', $fields );
-
- foreach ( $fields as $field ) :
- register_setting( 'helpful-details-settings-group', $field );
- endforeach;
- }
-
- /**
- * Register tab in tabs list.
- *
- * @param array $tabs
- * @param string $current
- *
- * @return array
- */
- public function register_tab( $tabs, $current )
- {
- $tabs['details'] = [
- 'id' => 'details',
- 'name' => esc_html_x( 'Details', 'tab name', 'helpful' ),
- ];
-
- return $tabs;
- }
-
- /**
- * Register tab content.
- *
- * @return void
- */
- public function register_tab_content()
- {
- if ( ! Helper::is_active_tab( 'details' ) ) {
- return;
- }
-
- $post_types = get_post_types( [ 'public' => true ] );
- $private_post_types = get_post_types( [ 'public' => false ] );
-
- if ( isset( $private_post_types ) ) {
- $post_types = array_merge( $post_types, $private_post_types );
- } else {
- $private_post_types = [];
- }
-
- $template = HELPFUL_PATH . 'templates/tabs/tab-details.php';
-
- if ( file_exists( $template ) ) {
- include_once $template;
- }
- }
-
- /**
- * Register tab alerts for settings saved and other.
- *
- * @return void
- */
- public function register_tab_alerts()
- {
- if ( isset( $_GET['settings-updated'] ) ) {
- $message = esc_html_x( 'Settings saved.', 'tab alert after save', 'helpful' );
- echo Helper::get_alert( $message, 'success', 1500 );
- }
- }
+ /**
+ * Class instance
+ *
+ * @var Details
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Details
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('admin_init', [ & $this, 'register_settings']);
+
+ add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2);
+ add_action('helpful_tabs_content', [ & $this, 'register_tab_content']);
+
+ add_action('helpful_tab_details_before', [ & $this, 'register_tab_alerts']);
+ }
+
+ /**
+ * Register settings for admin page
+ *
+ * @return void
+ */
+ public function register_settings()
+ {
+ $fields = [
+ 'helpful_credits',
+ 'helpful_hide_in_content',
+ 'helpful_post_types',
+ 'helpful_exists_hide',
+ 'helpful_count_hide',
+ 'helpful_widget',
+ 'helpful_widget_amount',
+ 'helpful_widget_pro',
+ 'helpful_widget_contra',
+ 'helpful_widget_pro_recent',
+ 'helpful_widget_contra_recent',
+ 'helpful_only_once',
+ 'helpful_percentages',
+ 'helpful_form_status_pro',
+ 'helpful_form_email_pro',
+ 'helpful_form_status_contra',
+ 'helpful_form_email_contra',
+ 'helpful_metabox',
+ 'helpful_widget_hide_publication',
+ 'helpful_hide_admin_columns',
+ 'helpful_shrink_admin_columns',
+ 'helpful_feedback_widget',
+ 'helpful_feedback_disabled',
+ 'helpful_wordpress_user',
+ 'helpful_ip_user',
+ ];
+
+ $fields = apply_filters('helpful_details_settings_group', $fields);
+
+ foreach ($fields as $field):
+ register_setting('helpful-details-settings-group', $field);
+ endforeach;
+ }
+
+ /**
+ * Register tab in tabs list.
+ *
+ * @param array $tabs
+ * @param string $current
+ *
+ * @return array
+ */
+ public function register_tab($tabs, $current)
+ {
+ $tabs['details'] = [
+ 'id' => 'details',
+ 'name' => esc_html_x('Details', 'tab name', 'helpful'),
+ ];
+
+ return $tabs;
+ }
+
+ /**
+ * Register tab content.
+ *
+ * @return void
+ */
+ public function register_tab_content()
+ {
+ if (!Helper::is_active_tab('details')) {
+ return;
+ }
+
+ $post_types = get_post_types(['public' => true]);
+ $private_post_types = get_post_types(['public' => false]);
+
+ if (isset($private_post_types)) {
+ $post_types = array_merge($post_types, $private_post_types);
+ } else {
+ $private_post_types = [];
+ }
+
+ $template = HELPFUL_PATH . 'templates/tabs/tab-details.php';
+
+ if (file_exists($template)) {
+ include_once $template;
+ }
+ }
+
+ /**
+ * Register tab alerts for settings saved and other.
+ *
+ * @return void
+ */
+ public function register_tab_alerts()
+ {
+ if (isset($_GET['settings-updated'])) {
+ $message = esc_html_x('Settings saved.', 'tab alert after save', 'helpful');
+ echo Helper::get_alert($message, 'success', 1500);
+ }
+ }
}
diff --git a/core/tabs/class-feedback.php b/core/tabs/class-feedback.php
index 9062b4d..139e66f 100644
--- a/core/tabs/class-feedback.php
+++ b/core/tabs/class-feedback.php
@@ -1,153 +1,152 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Feedback
{
- /**
- * Class instance
- *
- * @var Feedback
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Feedback
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
+ /**
+ * Class instance
+ *
+ * @var Feedback
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Feedback
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('admin_init', [ & $this, 'register_settings']);
+
+ if (Helper::is_feedback_disabled()) {
+ return;
}
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'admin_init', [ &$this, 'register_settings' ] );
-
- if ( Helper::is_feedback_disabled() ) :
- return;
- endif;
-
- add_filter( 'helpful_get_admin_tabs', [ &$this, 'register_tab' ], 10, 2 );
- add_action( 'helpful_tabs_content', [ &$this, 'register_tab_content' ] );
-
- add_action( 'helpful_tab_feedback_before', [ &$this, 'register_tab_alerts' ] );
- }
-
- /**
- * Register settings for admin page
- *
- * @return void
- */
- public function register_settings()
- {
- $fields = [
- 'helpful_feedback_widget',
- 'helpful_feedback_after_pro',
- 'helpful_feedback_after_contra',
- 'helpful_feedback_message_pro',
- 'helpful_feedback_message_contra',
- 'helpful_feedback_messages_table',
- 'helpful_feedback_widget_overview',
- 'helpful_feedback_name',
- 'helpful_feedback_email',
- 'helpful_feedback_cancel',
- 'helpful_feedback_label_message',
- 'helpful_feedback_label_name',
- 'helpful_feedback_label_email',
- 'helpful_feedback_label_submit',
- 'helpful_feedback_label_cancel',
- 'helpful_feedback_gravatar',
- 'helpful_feedback_message_spam',
- 'helpful_feedback_after_vote',
- 'helpful_feedback_message_voted',
- 'helpful_feedback_amount',
- 'helpful_feedback_send_email',
- 'helpful_feedback_receivers',
- 'helpful_feedback_subject',
- 'helpful_feedback_email_content',
- 'helpful_feedback_send_email_voter',
- 'helpful_feedback_subject_voter',
- 'helpful_feedback_email_content_voter',
- ];
-
- $fields = apply_filters( 'helpful_feedback_fields', $fields );
-
- foreach ( $fields as $field ) {
- register_setting( 'helpful-feedback-settings-group', $field );
- }
- }
-
- /**
- * Register tab in tabs list.
- *
- * @param array $tabs
- * @param string $current
- *
- * @return array
- */
- public function register_tab( $tabs, $current )
- {
- $tabs['feedback'] = [
- 'id' => 'feedback',
- 'name' => esc_html_x( 'Feedback', 'tab name', 'helpful' ),
- ];
-
- return $tabs;
- }
-
- /**
- * Register tab content.
- *
- * @return void
- */
- public function register_tab_content()
- {
- if ( ! Helper::is_active_tab( 'feedback' ) ) {
- return;
- }
-
- $template = HELPFUL_PATH . 'templates/tabs/tab-feedback.php';
-
- if ( file_exists( $template ) ) {
- include_once $template;
- }
- }
-
- /**
- * Register tab alerts for settings saved and other.
- *
- * @return void
- */
- public function register_tab_alerts()
- {
- if ( isset( $_GET['settings-updated'] ) ) {
- $message = esc_html_x( 'Settings saved.', 'tab alert after save', 'helpful' );
- echo Helper::get_alert( $message, 'success', 1500 );
- }
- }
+ add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2);
+ add_action('helpful_tabs_content', [ & $this, 'register_tab_content']);
+
+ add_action('helpful_tab_feedback_before', [ & $this, 'register_tab_alerts']);
+ }
+
+ /**
+ * Register settings for admin page
+ *
+ * @return void
+ */
+ public function register_settings()
+ {
+ $fields = [
+ 'helpful_feedback_widget',
+ 'helpful_feedback_after_pro',
+ 'helpful_feedback_after_contra',
+ 'helpful_feedback_message_pro',
+ 'helpful_feedback_message_contra',
+ 'helpful_feedback_messages_table',
+ 'helpful_feedback_widget_overview',
+ 'helpful_feedback_name',
+ 'helpful_feedback_email',
+ 'helpful_feedback_cancel',
+ 'helpful_feedback_label_message',
+ 'helpful_feedback_label_name',
+ 'helpful_feedback_label_email',
+ 'helpful_feedback_label_submit',
+ 'helpful_feedback_label_cancel',
+ 'helpful_feedback_gravatar',
+ 'helpful_feedback_message_spam',
+ 'helpful_feedback_after_vote',
+ 'helpful_feedback_message_voted',
+ 'helpful_feedback_amount',
+ 'helpful_feedback_send_email',
+ 'helpful_feedback_receivers',
+ 'helpful_feedback_subject',
+ 'helpful_feedback_email_content',
+ 'helpful_feedback_send_email_voter',
+ 'helpful_feedback_subject_voter',
+ 'helpful_feedback_email_content_voter',
+ ];
+
+ $fields = apply_filters('helpful_feedback_fields', $fields);
+
+ foreach ($fields as $field) {
+ register_setting('helpful-feedback-settings-group', $field);
+ }
+ }
+
+ /**
+ * Register tab in tabs list.
+ *
+ * @param array $tabs
+ * @param string $current
+ *
+ * @return array
+ */
+ public function register_tab($tabs, $current)
+ {
+ $tabs['feedback'] = [
+ 'id' => 'feedback',
+ 'name' => esc_html_x('Feedback', 'tab name', 'helpful'),
+ ];
+
+ return $tabs;
+ }
+
+ /**
+ * Register tab content.
+ *
+ * @return void
+ */
+ public function register_tab_content()
+ {
+ if (!Helper::is_active_tab('feedback')) {
+ return;
+ }
+
+ $template = HELPFUL_PATH . 'templates/tabs/tab-feedback.php';
+
+ if (file_exists($template)) {
+ include_once $template;
+ }
+ }
+
+ /**
+ * Register tab alerts for settings saved and other.
+ *
+ * @return void
+ */
+ public function register_tab_alerts()
+ {
+ if (isset($_GET['settings-updated'])) {
+ $message = esc_html_x('Settings saved.', 'tab alert after save', 'helpful');
+ echo Helper::get_alert($message, 'success', 1500);
+ }
+ }
}
diff --git a/core/tabs/class-log.php b/core/tabs/class-log.php
index d74ff38..059eca9 100644
--- a/core/tabs/class-log.php
+++ b/core/tabs/class-log.php
@@ -1,8 +1,9 @@
- * @version 4.4.49
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
diff --git a/core/tabs/class-start.php b/core/tabs/class-start.php
index f3b0217..d2ed4d9 100644
--- a/core/tabs/class-start.php
+++ b/core/tabs/class-start.php
@@ -1,297 +1,288 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Start
{
- /**
- * Class instance
- *
- * @var Start
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Start
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_filter( 'helpful_get_admin_tabs', [ &$this, 'register_tab' ], 10, 2 );
- add_action( 'helpful_tabs_content', [ &$this, 'register_tab_content' ] );
-
- add_action( 'wp_ajax_helpful_range_stats', [ &$this, 'ajax_get_stats_range' ] );
- add_action( 'wp_ajax_helpful_total_stats', [ &$this, 'ajax_get_stats_total' ] );
- add_action( 'wp_ajax_helpful_get_posts_data', [ &$this, 'ajax_get_posts_data' ] );
-
- add_action( 'helpful_tab_start_before', [ &$this, 'register_tab_alerts' ] );
- }
-
- /**
- * Add tab to filter
- *
- * @param array $tabs
- * @param string $current
- *
- * @return array
- */
- public function register_tab( $tabs, $current )
- {
- $tabs['start'] = [
- 'id' => 'start',
- 'name' => esc_html_x( 'Start', 'tab name', 'helpful' ),
- ];
-
- return $tabs;
- }
-
- /**
- * Register tab content.
- *
- * @return void
- */
- public function register_tab_content()
- {
- if ( ! Helper::is_active_tab( 'start' ) ) {
- return;
- }
-
- $template = HELPFUL_PATH . 'templates/tabs/tab-start.php';
-
- if ( file_exists( $template ) ) {
- include_once $template;
- }
- }
-
- /**
- * Get stats by date range
- *
- * @see Helpful_Helper_Values::getStatsRange()
- *
- * @return void
- */
- public function ajax_get_stats_range()
- {
- check_ajax_referer( 'helpful_range_stats' );
-
- $from = null;
- if ( isset( $_REQUEST['from'] ) ) {
- $from = $_REQUEST['from'];
- }
-
- $to = null;
- if ( isset( $_REQUEST['to'] ) ) {
- $to = $_REQUEST['to'];
- }
-
- $response = [];
- $from = date_i18n( 'Y-m-d', strtotime( sanitize_text_field( $from ) ) );
- $to = date_i18n( 'Y-m-d', strtotime( sanitize_text_field( $to ) ) );
- $response = Helpers\Stats::get_stats_range( $from, $to );
- $response['from'] = $from;
- $response['to'] = $to;
-
- if ( isset( $_REQUEST['type'] ) && 'default' !== $_REQUEST['type'] ) {
- $response['options']['scales'] = [
- 'xAxes' => [
- [ 'stacked' => true ],
- ],
- 'yAxes' => [
- [ 'stacked' => true ],
- ],
- ];
- }
-
- wp_send_json_success( $response );
- }
-
- /**
- * Get stats total
- *
- * @see Helpful_Helper_Values::getStatsTotal()
- *
- * @return void
- */
- public function ajax_get_stats_total()
- {
- check_ajax_referer( 'helpful_admin_nonce' );
- $response = Helpers\Stats::get_stats_total();
- wp_send_json_success( $response );
- }
-
- /**
- * Get posts data
- *
- * @return void
- */
- public function ajax_get_posts_data()
- {
- check_ajax_referer( 'helpful_admin_nonce' );
-
- Helpers\Values::sync_post_meta();
-
- /*
- $post_types = get_option( 'helpful_post_types' );
-
- if ( ! $post_types ) {
- $post_types = 'any';
- }
- */
-
- $post_types = 'any';
-
- $response = [
- 'status' => 'success',
- 'data' => [],
- ];
-
- $args = [
- 'post_type' => $post_types,
- 'post_status' => 'publish',
- 'fields' => 'ids',
- 'posts_per_page' => -1,
- 'meta_query' => [
- 'relation' => 'OR',
- [
- 'key' => 'helpful-contra',
- 'value' => 1,
- 'compare' => '>='
- ],
- [
- 'key' => 'helpful-pro',
- 'value' => 1,
- 'compare' => '>='
- ],
- ],
- ];
-
- $transient = 'helpful_admin_start_' . md5( serialize( $args ) );
-
- if ( false === ( $query = get_transient( $transient ) ) ) {
- $query = new \WP_Query( $args );
- $cache_time = get_option( 'helpful_cache_time', 'minute' );
- $cache_times = Helpers\Cache::get_cache_times( false );
- $cache_time = $cache_times[ $cache_time ];
-
- set_transient( $transient, $query, $cache_time );
- }
-
- if ( $query->found_posts ) {
- foreach ( $query->posts as $post_id ) :
-
- $data = Helpers\Stats::get_single_post_stats( $post_id );
-
- $title = $data['title'];
- $length = apply_filters( 'helpful_datatables_string_length', 35 );
-
- if ( strlen( $title ) > $length ) {
- $title = substr( $title, 0, $length ) . '...';
- }
-
- if ( '' === $title || 0 === strlen( $title ) ) {
- $title = esc_html_x( 'No title found', 'message if no post title was found', 'helpful' );
- }
-
- $feedback = Helpers\Feedback::get_feedback_count( $post_id );
- $feedback = intval( $feedback );
-
- update_post_meta( $post_id, 'helpful-feedback-count', $feedback );
-
- $feedback_url = admin_url( 'admin.php?page=helpful_feedback&post_id=' . $post_id );
-
- $feedback_display = 0;
-
- if ( 0 < $feedback ) {
- $feedback_display = sprintf( '%d ', $feedback_url, $feedback );
- }
-
- $row = [
- 'post_id' => $data['ID'],
- 'post_title' => sprintf(
- '%2$s ',
- esc_url( $data['permalink'] ),
- esc_html( $title )
- ),
- 'post_type' => [
- 'display' => $data['type']['name'],
- 'sort' => $data['type']['slug'],
- ],
- 'post_author' => [
- 'display' => $data['author']['name'],
- 'sort' => $data['author']['ID'],
- ],
- 'pro' => [
- 'display' => sprintf( '%s (%s%%)', $data['pro']['value'], $data['pro']['percentage'] ),
- 'sort' => $data['pro']['value'],
- ],
- 'contra' => [
- 'display' => sprintf( '%s (%s%%)', $data['contra']['value'], $data['contra']['percentage'] ),
- 'sort' => $data['contra']['value'],
- ],
- 'helpful' => [
- 'display' => sprintf( '%s%%', $data['helpful'] ),
- 'sort' => $data['helpful'],
- ],
- 'post_date' => [
- 'display' => $data['time']['date'],
- 'sort' => $data['time']['timestamp'],
- ],
- ];
-
- if ( ! Helper::is_feedback_disabled() ) {
- $row['feedback'] = [
- 'display' => $feedback_display,
- 'sort' => $feedback,
- ];
- }
-
- $response['data'][] = $row;
-
- endforeach;
- }
-
- wp_send_json( $response );
- }
-
- /**
- * Register tab alerts for settings saved and other.
- *
- * @return void
- */
- public function register_tab_alerts()
- {
- if ( isset( $_GET['settings-updated'] ) ) {
- $message = esc_html_x( 'Settings saved.', 'tab alert after save', 'helpful' );
- echo Helper::get_alert( $message, 'success', 1500 );
- }
- }
+ /**
+ * Class instance
+ *
+ * @var Start
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Start
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2);
+ add_action('helpful_tabs_content', [ & $this, 'register_tab_content']);
+
+ add_action('wp_ajax_helpful_range_stats', [ & $this, 'ajax_get_stats_range']);
+ add_action('wp_ajax_helpful_total_stats', [ & $this, 'ajax_get_stats_total']);
+ add_action('wp_ajax_helpful_get_posts_data', [ & $this, 'ajax_get_posts_data']);
+
+ add_action('helpful_tab_start_before', [ & $this, 'register_tab_alerts']);
+ }
+
+ /**
+ * Add tab to filter
+ *
+ * @param array $tabs
+ * @param string $current
+ *
+ * @return array
+ */
+ public function register_tab($tabs, $current)
+ {
+ $tabs['start'] = [
+ 'id' => 'start',
+ 'name' => esc_html_x('Start', 'tab name', 'helpful'),
+ ];
+
+ return $tabs;
+ }
+
+ /**
+ * Register tab content.
+ *
+ * @return void
+ */
+ public function register_tab_content()
+ {
+ if (!Helper::is_active_tab('start')) {
+ return;
+ }
+
+ $template = HELPFUL_PATH . 'templates/tabs/tab-start.php';
+
+ if (file_exists($template)) {
+ include_once $template;
+ }
+ }
+
+ /**
+ * Get stats by date range
+ *
+ * @see Helpful_Helper_Values::getStatsRange()
+ *
+ * @return void
+ */
+ public function ajax_get_stats_range()
+ {
+ check_ajax_referer('helpful_range_stats');
+
+ $from = null;
+ if (isset($_REQUEST['from'])) {
+ $from = $_REQUEST['from'];
+ }
+
+ $to = null;
+ if (isset($_REQUEST['to'])) {
+ $to = $_REQUEST['to'];
+ }
+
+ $response = [];
+ $from = date_i18n('Y-m-d', strtotime(sanitize_text_field($from)));
+ $to = date_i18n('Y-m-d', strtotime(sanitize_text_field($to)));
+ $response = Helpers\Stats::get_stats_range($from, $to);
+ $response['from'] = $from;
+ $response['to'] = $to;
+
+ if (isset($_REQUEST['type']) && 'default' !== $_REQUEST['type']) {
+ $response['options']['scales'] = [
+ 'xAxes' => [
+ ['stacked' => true],
+ ],
+ 'yAxes' => [
+ ['stacked' => true],
+ ],
+ ];
+ }
+
+ wp_send_json_success($response);
+ }
+
+ /**
+ * Get stats total
+ *
+ * @see Helpful_Helper_Values::getStatsTotal()
+ *
+ * @return void
+ */
+ public function ajax_get_stats_total()
+ {
+ check_ajax_referer('helpful_admin_nonce');
+ $response = Helpers\Stats::get_stats_total();
+ wp_send_json_success($response);
+ }
+
+ /**
+ * Get posts data
+ *
+ * @return void
+ */
+ public function ajax_get_posts_data()
+ {
+ check_ajax_referer('helpful_admin_nonce');
+
+ Helpers\Values::sync_post_meta();
+
+ $post_types = 'any';
+
+ $response = [
+ 'status' => 'success',
+ 'data' => [],
+ ];
+
+ $args = [
+ 'post_type' => $post_types,
+ 'post_status' => 'publish',
+ 'fields' => 'ids',
+ 'posts_per_page' => -1,
+ 'meta_query' => [
+ 'relation' => 'OR',
+ [
+ 'key' => 'helpful-contra',
+ 'value' => 1,
+ 'compare' => '>=',
+ ],
+ [
+ 'key' => 'helpful-pro',
+ 'value' => 1,
+ 'compare' => '>=',
+ ],
+ ],
+ ];
+
+ $transient = 'helpful_admin_start_' . md5(serialize($args));
+
+ if (false === ($query = get_transient($transient))) {
+ $query = new \WP_Query($args);
+ $cache_time = get_option('helpful_cache_time', 'minute');
+ $cache_times = Helpers\Cache::get_cache_times(false);
+ $cache_time = $cache_times[$cache_time];
+
+ set_transient($transient, $query, $cache_time);
+ }
+
+ if ($query->found_posts) {
+ foreach ($query->posts as $post_id):
+
+ $data = Helpers\Stats::get_single_post_stats($post_id);
+
+ $title = $data['title'];
+ $length = apply_filters('helpful_datatables_string_length', 35);
+
+ if (strlen($title) > $length) {
+ $title = substr($title, 0, $length) . '...';
+ }
+
+ if ('' === $title || 0 === strlen($title)) {
+ $title = esc_html_x('No title found', 'message if no post title was found', 'helpful');
+ }
+
+ $feedback = Helpers\Feedback::get_feedback_count($post_id);
+ $feedback = intval($feedback);
+
+ update_post_meta($post_id, 'helpful-feedback-count', $feedback);
+
+ $feedback_url = admin_url('admin.php?page=helpful_feedback&post_id=' . $post_id);
+
+ $feedback_display = 0;
+
+ if (0 < $feedback) {
+ $feedback_display = sprintf('%d ', $feedback_url, $feedback);
+ }
+
+ $row = [
+ 'post_id' => $data['ID'],
+ 'post_title' => sprintf(
+ '%2$s ',
+ esc_url($data['permalink']),
+ esc_html($title)
+ ),
+ 'post_type' => [
+ 'display' => $data['type']['name'],
+ 'sort' => $data['type']['slug'],
+ ],
+ 'post_author' => [
+ 'display' => $data['author']['name'],
+ 'sort' => $data['author']['ID'],
+ ],
+ 'pro' => [
+ 'display' => sprintf('%s (%s%%)', $data['pro']['value'], $data['pro']['percentage']),
+ 'sort' => $data['pro']['value'],
+ ],
+ 'contra' => [
+ 'display' => sprintf('%s (%s%%)', $data['contra']['value'], $data['contra']['percentage']),
+ 'sort' => $data['contra']['value'],
+ ],
+ 'helpful' => [
+ 'display' => sprintf('%s%%', $data['helpful']),
+ 'sort' => $data['helpful'],
+ ],
+ 'post_date' => [
+ 'display' => $data['time']['date'],
+ 'sort' => $data['time']['timestamp'],
+ ],
+ ];
+
+ if (!Helper::is_feedback_disabled()) {
+ $row['feedback'] = [
+ 'display' => $feedback_display,
+ 'sort' => $feedback,
+ ];
+ }
+
+ $response['data'][] = $row;
+
+ endforeach;
+ }
+
+ wp_send_json($response);
+ }
+
+ /**
+ * Register tab alerts for settings saved and other.
+ *
+ * @return void
+ */
+ public function register_tab_alerts()
+ {
+ if (isset($_GET['settings-updated'])) {
+ $message = esc_html_x('Settings saved.', 'tab alert after save', 'helpful');
+ echo Helper::get_alert($message, 'success', 1500);
+ }
+ }
}
diff --git a/core/tabs/class-system.php b/core/tabs/class-system.php
index 51c62b8..f07b203 100644
--- a/core/tabs/class-system.php
+++ b/core/tabs/class-system.php
@@ -1,215 +1,214 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class System
{
- /**
- * Class instance
- *
- * @var System
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return System
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'admin_init', [ &$this, 'register_settings' ] );
-
- add_filter( 'helpful_get_admin_tabs', [ &$this, 'register_tab' ], 10, 2 );
- add_action( 'helpful_tabs_content', [ &$this, 'register_tab_content' ] );
-
- add_action( 'admin_init', [ &$this, 'reset_plugin' ] );
- add_action( 'admin_init', [ &$this, 'reset_feedback' ] );
-
- if ( get_option( 'helpful_classic_editor' ) ) {
- add_filter( 'use_block_editor_for_post', '__return_false', 10 );
- }
-
- add_action( 'helpful_tab_system_before', [ &$this, 'register_tab_alerts' ] );
- }
-
- /**
- * Register settings for admin page
- *
- * @return void
- */
- public function register_settings()
- {
- $fields = [
- 'helpful_uninstall',
- 'helpful_timezone',
- 'helpful_multiple',
- 'helpful_notes',
- 'helpful_plugin_first',
- 'helpful_classic_editor',
- 'helpful_caching',
- 'helpful_caching_time',
- 'helpful_export_separator',
- 'helpful_uninstall_feedback',
- 'helpful_sessions_false',
- 'helpful_user_random',
- 'helpful_disable_frontend_nonce',
- 'helpful_disable_feedback_nonce',
- ];
-
- $fields = apply_filters( 'helpful_system_settings_group', $fields );
-
- foreach ( $fields as $field ) {
- register_setting( 'helpful-system-settings-group', $field );
- }
- }
-
- /**
- * Register tab in tabs list.
- *
- * @param array $tabs
- * @param string $current
- *
- * @return array
- */
- public function register_tab( $tabs, $current )
- {
- $tabs['system'] = [
- 'id' => 'system',
- 'name' => esc_html_x( 'System', 'tab name', 'helpful' ),
- ];
-
- return $tabs;
- }
-
- /**
- * Register tab content.
- *
- * @return void
- */
- public function register_tab_content()
- {
- if ( ! Helper::is_active_tab( 'system' ) ) {
- return;
- }
-
- $post_types = get_post_types( [ 'public' => true ] );
- $private_post_types = get_post_types( [ 'public' => false ] );
-
- if ( isset( $private_post_types ) ) {
- $post_types = array_merge( $post_types, $private_post_types );
- } else {
- $private_post_types = [];
- }
-
- $template = HELPFUL_PATH . 'templates/tabs/tab-system.php';
-
- if ( file_exists( $template ) ) {
- include_once $template;
- }
- }
-
- /**
- * Reset helpful database and entries
- *
- * @global $wpdb
- *
- * @return void
- */
- public function reset_plugin()
- {
- if ( ! get_option( 'helpful_uninstall' ) ) {
- return;
- }
-
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'helpful';
- $wpdb->query( "TRUNCATE TABLE $table_name" );
- update_option( 'helpful_uninstall', false );
-
- $args = [
- 'post_type' => 'any',
- 'posts_per_page' => -1,
- 'fields' => 'ids',
- ];
- $posts = new \WP_Query( $args );
-
- if ( $posts->found_posts ) {
- foreach ( $posts->posts as $post_id ) {
- if ( get_post_meta( $post_id, 'helpful-pro' ) ) {
- delete_post_meta( $post_id, 'helpful-pro' );
- }
- if ( get_post_meta( $post_id, 'helpful-contra' ) ) {
- delete_post_meta( $post_id, 'helpful-contra' );
- }
-
- if ( 'helpful_feedback' === get_post_type( $post_id ) ) {
- wp_delete_post( $post_id, true );
- }
- }
- }
-
- update_option( 'helpful_is_installed', 0 );
- }
-
- /**
- * Reset helpful feedback database
- *
- * @global $wpdb
- *
- * @return void
- */
- public function reset_feedback()
- {
- if ( ! get_option( 'helpful_uninstall_feedback' ) ) {
- return;
- }
-
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'helpful_feedback';
- $wpdb->query( "TRUNCATE TABLE $table_name" );
- update_option( 'helpful_uninstall_feedback', false );
- }
-
- /**
- * Register tab alerts for settings saved and other.
- *
- * @return void
- */
- public function register_tab_alerts()
- {
- if ( isset( $_GET['settings-updated'] ) ) {
- $message = esc_html_x( 'Settings saved.', 'tab alert after save', 'helpful' );
- echo Helper::get_alert( $message, 'success', 1500 );
- }
- }
+ /**
+ * Class instance
+ *
+ * @var System
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return System
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('admin_init', [ & $this, 'register_settings']);
+
+ add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2);
+ add_action('helpful_tabs_content', [ & $this, 'register_tab_content']);
+
+ add_action('admin_init', [ & $this, 'reset_plugin']);
+ add_action('admin_init', [ & $this, 'reset_feedback']);
+
+ if (get_option('helpful_classic_editor')) {
+ add_filter('use_block_editor_for_post', '__return_false', 10);
+ }
+
+ add_action('helpful_tab_system_before', [ & $this, 'register_tab_alerts']);
+ }
+
+ /**
+ * Register settings for admin page
+ *
+ * @return void
+ */
+ public function register_settings()
+ {
+ $fields = [
+ 'helpful_uninstall',
+ 'helpful_timezone',
+ 'helpful_multiple',
+ 'helpful_notes',
+ 'helpful_plugin_first',
+ 'helpful_classic_editor',
+ 'helpful_caching',
+ 'helpful_caching_time',
+ 'helpful_export_separator',
+ 'helpful_uninstall_feedback',
+ 'helpful_sessions_false',
+ 'helpful_user_random',
+ 'helpful_disable_frontend_nonce',
+ 'helpful_disable_feedback_nonce',
+ ];
+
+ $fields = apply_filters('helpful_system_settings_group', $fields);
+
+ foreach ($fields as $field) {
+ register_setting('helpful-system-settings-group', $field);
+ }
+ }
+
+ /**
+ * Register tab in tabs list.
+ *
+ * @param array $tabs
+ * @param string $current
+ *
+ * @return array
+ */
+ public function register_tab($tabs, $current)
+ {
+ $tabs['system'] = [
+ 'id' => 'system',
+ 'name' => esc_html_x('System', 'tab name', 'helpful'),
+ ];
+
+ return $tabs;
+ }
+
+ /**
+ * Register tab content.
+ *
+ * @return void
+ */
+ public function register_tab_content()
+ {
+ if (!Helper::is_active_tab('system')) {
+ return;
+ }
+
+ $post_types = get_post_types(['public' => true]);
+ $private_post_types = get_post_types(['public' => false]);
+
+ if (isset($private_post_types)) {
+ $post_types = array_merge($post_types, $private_post_types);
+ } else {
+ $private_post_types = [];
+ }
+
+ $template = HELPFUL_PATH . 'templates/tabs/tab-system.php';
+
+ if (file_exists($template)) {
+ include_once $template;
+ }
+ }
+
+ /**
+ * Reset helpful database and entries
+ *
+ * @global $wpdb
+ *
+ * @return void
+ */
+ public function reset_plugin()
+ {
+ if (!get_option('helpful_uninstall')) {
+ return;
+ }
+
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'helpful';
+ $wpdb->query("TRUNCATE TABLE $table_name");
+ update_option('helpful_uninstall', false);
+
+ $args = [
+ 'post_type' => 'any',
+ 'posts_per_page' => -1,
+ 'fields' => 'ids',
+ ];
+ $posts = new \WP_Query($args);
+
+ if ($posts->found_posts) {
+ foreach ($posts->posts as $post_id) {
+ if (get_post_meta($post_id, 'helpful-pro')) {
+ delete_post_meta($post_id, 'helpful-pro');
+ }
+ if (get_post_meta($post_id, 'helpful-contra')) {
+ delete_post_meta($post_id, 'helpful-contra');
+ }
+
+ if ('helpful_feedback' === get_post_type($post_id)) {
+ wp_delete_post($post_id, true);
+ }
+ }
+ }
+
+ update_option('helpful_is_installed', 0);
+ }
+
+ /**
+ * Reset helpful feedback database
+ *
+ * @global $wpdb
+ *
+ * @return void
+ */
+ public function reset_feedback()
+ {
+ if (!get_option('helpful_uninstall_feedback')) {
+ return;
+ }
+
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'helpful_feedback';
+ $wpdb->query("TRUNCATE TABLE $table_name");
+ update_option('helpful_uninstall_feedback', false);
+ }
+
+ /**
+ * Register tab alerts for settings saved and other.
+ *
+ * @return void
+ */
+ public function register_tab_alerts()
+ {
+ if (isset($_GET['settings-updated'])) {
+ $message = esc_html_x('Settings saved.', 'tab alert after save', 'helpful');
+ echo Helper::get_alert($message, 'success', 1500);
+ }
+ }
}
diff --git a/core/tabs/class-texts.php b/core/tabs/class-texts.php
index 396af5e..f68d566 100644
--- a/core/tabs/class-texts.php
+++ b/core/tabs/class-texts.php
@@ -1,134 +1,133 @@
- * @version 4.3.0
+ * @package Helpful
+ * @subpackage Core\Tabs
+ * @version 4.4.50
+ * @since 4.3.0
*/
namespace Helpful\Core\Tabs;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Texts
{
- /**
- * Class instance
- *
- * @var Texts
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Texts
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- add_action( 'admin_init', [ &$this, 'register_settings' ] );
-
- add_filter( 'helpful_get_admin_tabs', [ &$this, 'register_tab' ], 10, 2 );
- add_action( 'helpful_tabs_content', [ &$this, 'register_tab_content' ] );
-
- add_action( 'helpful_tab_texts_before', [ &$this, 'register_tab_alerts' ] );
- }
-
- /**
- * Register settings for admin page
- *
- * @return void
- */
- public function register_settings()
- {
- $fields = [
- 'helpful_heading',
- 'helpful_content',
- 'helpful_pro',
- 'helpful_pro_disabled',
- 'helpful_exists',
- 'helpful_contra',
- 'helpful_contra_disabled',
- 'helpful_column_pro',
- 'helpful_column_contra',
- 'helpful_column_feedback',
- 'helpful_after_pro',
- 'helpful_after_contra',
- 'helpful_after_fallback',
- ];
-
- $fields = apply_filters( 'helpful_texts_settings_group', $fields );
-
- foreach ( $fields as $field ) {
- register_setting( 'helpful-texts-settings-group', $field );
- }
- }
-
- /**
- * Register tab in tabs list.
- *
- * @param array $tabs
- * @param string $current
- *
- * @return array
- */
- public function register_tab( $tabs, $current )
- {
- $tabs['texts'] = [
- 'id' => 'texts',
- 'name' => esc_html_x( 'Texts', 'tab name', 'helpful' ),
- ];
-
- return $tabs;
- }
-
- /**
- * Register tab content.
- *
- * @return void
- */
- public function register_tab_content()
- {
- if ( ! Helper::is_active_tab( 'texts' ) ) {
- return;
- }
-
- $template = HELPFUL_PATH . 'templates/tabs/tab-texts.php';
-
- if ( file_exists( $template ) ) {
- include_once $template;
- }
- }
-
- /**
- * Register tab alerts for settings saved and other.
- *
- * @return void
- */
- public function register_tab_alerts()
- {
- if ( isset( $_GET['settings-updated'] ) ) {
- $message = esc_html_x( 'Settings saved.', 'tab alert after save', 'helpful' );
- echo Helper::get_alert( $message, 'success', 1500 );
- }
- }
+ /**
+ * Class instance
+ *
+ * @var Texts
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Texts
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ add_action('admin_init', [ & $this, 'register_settings']);
+
+ add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2);
+ add_action('helpful_tabs_content', [ & $this, 'register_tab_content']);
+
+ add_action('helpful_tab_texts_before', [ & $this, 'register_tab_alerts']);
+ }
+
+ /**
+ * Register settings for admin page
+ *
+ * @return void
+ */
+ public function register_settings()
+ {
+ $fields = [
+ 'helpful_heading',
+ 'helpful_content',
+ 'helpful_pro',
+ 'helpful_pro_disabled',
+ 'helpful_exists',
+ 'helpful_contra',
+ 'helpful_contra_disabled',
+ 'helpful_column_pro',
+ 'helpful_column_contra',
+ 'helpful_column_feedback',
+ 'helpful_after_pro',
+ 'helpful_after_contra',
+ 'helpful_after_fallback',
+ ];
+
+ $fields = apply_filters('helpful_texts_settings_group', $fields);
+
+ foreach ($fields as $field) {
+ register_setting('helpful-texts-settings-group', $field);
+ }
+ }
+
+ /**
+ * Register tab in tabs list.
+ *
+ * @param array $tabs
+ * @param string $current
+ *
+ * @return array
+ */
+ public function register_tab($tabs, $current)
+ {
+ $tabs['texts'] = [
+ 'id' => 'texts',
+ 'name' => esc_html_x('Texts', 'tab name', 'helpful'),
+ ];
+
+ return $tabs;
+ }
+
+ /**
+ * Register tab content.
+ *
+ * @return void
+ */
+ public function register_tab_content()
+ {
+ if (!Helper::is_active_tab('texts')) {
+ return;
+ }
+
+ $template = HELPFUL_PATH . 'templates/tabs/tab-texts.php';
+
+ if (file_exists($template)) {
+ include_once $template;
+ }
+ }
+
+ /**
+ * Register tab alerts for settings saved and other.
+ *
+ * @return void
+ */
+ public function register_tab_alerts()
+ {
+ if (isset($_GET['settings-updated'])) {
+ $message = esc_html_x('Settings saved.', 'tab alert after save', 'helpful');
+ echo Helper::get_alert($message, 'success', 1500);
+ }
+ }
}
diff --git a/templates/admin-feedback-item.php b/templates/admin-feedback-item.php
index c1e1afc..beb2e6e 100644
--- a/templates/admin-feedback-item.php
+++ b/templates/admin-feedback-item.php
@@ -1,34 +1,29 @@
- *
+ * @version 4.4.50
* @since 1.0.0
*/
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
+if (!defined('ABSPATH')) {
exit;
}
?>
-
message; ?>
- fields ) ) : ?>
+ fields)) : ?>
- fields as $label => $value ): ?>
- :
+ fields as $label => $value): ?>
+ :
-
diff --git a/templates/admin-feedback-pagination.php b/templates/admin-feedback-pagination.php
index ae90521..0ac6bff 100644
--- a/templates/admin-feedback-pagination.php
+++ b/templates/admin-feedback-pagination.php
@@ -1,33 +1,30 @@
- *
+ * @version 4.4.50
* @since 1.0.0
*/
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
+if (!defined('ABSPATH')) {
exit;
}
-if ( 1 >= $max_num_pages ) {
+if (1 >= $max_num_pages) {
return;
}
?>