From 75722a770de904ac46750a26785820f6a6c7e940 Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 15 Oct 2018 22:35:55 -0300 Subject: [PATCH 1/5] Implements custom vote text options and form --- includes/postratings-activation.php | 3 +++ postratings-options.php | 21 +++++++++++++++++++++ uninstall.php | 2 ++ 3 files changed, 26 insertions(+) diff --git a/includes/postratings-activation.php b/includes/postratings-activation.php index 0411b3b..6b8e77c 100644 --- a/includes/postratings-activation.php +++ b/includes/postratings-activation.php @@ -81,6 +81,9 @@ function ratings_activate() { delete_option('widget_ratings_highest_rated'); delete_option('widget_ratings_most_rated'); + add_option('postratings_vote_text_singular', 'Vote' ); + add_option('postratings_vote_text_plural', 'Votes' ); + // Index $index = $wpdb->get_results( "SHOW INDEX FROM $wpdb->ratings;" ); $key_name = array(); diff --git a/postratings-options.php b/postratings-options.php index 07db9c4..06c2182 100644 --- a/postratings-options.php +++ b/postratings-options.php @@ -45,6 +45,8 @@ $postratings_richsnippet = intval($_POST['postratings_richsnippet']); $postratings_ratingstext_array = $_POST['postratings_ratingstext']; $postratings_ratingstext = array(); + $postratings_vote_text_singular = sanitize_text_field(trim($_POST['postratings_vote_text_singular'])); + $postratings_vote_text_plural = sanitize_text_field(trim($_POST['postratings_vote_text_plural'])); if( ! empty( $postratings_ratingstext_array ) && is_array( $postratings_ratingstext_array ) ) { foreach( $postratings_ratingstext_array as $ratingstext ) { $postratings_ratingstext[] = wp_kses_post(trim( $ratingstext )); @@ -79,6 +81,8 @@ $update_ratings_queries[] = update_option('postratings_logging_method', $postratings_logging_method); $update_ratings_queries[] = update_option('postratings_allowtorate', $postratings_allowtorate); $update_ratings_queries[] = update_option('postratings_options', $postratings_options); + $update_ratings_queries[] = update_option('postratings_vote_text_singular', $postratings_vote_text_singular); + $update_ratings_queries[] = update_option('postratings_vote_text_plural', $postratings_vote_text_plural); $update_ratings_text[] = __('Custom Rating', 'wp-postratings'); $update_ratings_text[] = __('Ratings Template Vote', 'wp-postratings'); $update_ratings_text[] = __('Ratings Template Voted', 'wp-postratings'); @@ -94,6 +98,8 @@ $update_ratings_text[] = __('Logging Method', 'wp-postratings'); $update_ratings_text[] = __('Allow To Vote Option', 'wp-postratings'); $update_ratings_text[] = __('Ratings Settings', 'wp-postratings'); + $update_ratings_text[] = __('Custom vote text (singular)', 'wp-postratings'); + $update_ratings_text[] = __('Custom vote text (plural)', 'wp-postratings'); $i = 0; $text = ''; foreach($update_ratings_queries as $update_ratings_query) { @@ -363,6 +369,21 @@ function set_custom(custom, max) { +

+ + + + + + + + + +
+ +
+ +

diff --git a/uninstall.php b/uninstall.php index 88d30fc..38d5bea 100644 --- a/uninstall.php +++ b/uninstall.php @@ -25,6 +25,8 @@ , 'postratings_options' , 'widget_ratings' , 'widget_ratings-widget' + , 'postratings_vote_text_singular' + , 'postratings_vote_text_plural' ); From 910f2d1838e30cc55bbacf21ccf2107cdf0cb665 Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 15 Oct 2018 22:53:43 -0300 Subject: [PATCH 2/5] Includes the template variable into the default templates --- includes/postratings-activation.php | 12 ++++++------ postratings-templates.php | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/includes/postratings-activation.php b/includes/postratings-activation.php index 6b8e77c..5994ad1 100644 --- a/includes/postratings-activation.php +++ b/includes/postratings-activation.php @@ -58,8 +58,8 @@ function ratings_activate() { // Add In Options (4 Records) add_option('postratings_image', 'stars' ); add_option('postratings_max', '5' ); - add_option('postratings_template_vote', '%RATINGS_IMAGES_VOTE% (%RATINGS_USERS% '.__('votes', 'wp-postratings').__(',', 'wp-postratings').' '.__('average', 'wp-postratings').': %RATINGS_AVERAGE% '.__('out of', 'wp-postratings').' %RATINGS_MAX%)
%RATINGS_TEXT%' ); - add_option('postratings_template_text', '%RATINGS_IMAGES% (%RATINGS_USERS% '.__('votes', 'wp-postratings').__(',', 'wp-postratings').' '.__('average', 'wp-postratings').': %RATINGS_AVERAGE% '.__('out of', 'wp-postratings').' %RATINGS_MAX%'.__(',', 'wp-postratings').' '.__('rated', 'wp-postratings').')' ); + add_option('postratings_template_vote', '%RATINGS_IMAGES_VOTE% (%RATINGS_USERS% %RATINGS_VOTE_TEXT%'.__(',', 'wp-postratings').' '.__('average', 'wp-postratings').': %RATINGS_AVERAGE% '.__('out of', 'wp-postratings').' %RATINGS_MAX%)
%RATINGS_TEXT%' ); + add_option('postratings_template_text', '%RATINGS_IMAGES% (%RATINGS_USERS% %RATINGS_VOTE_TEXT%'.__(',', 'wp-postratings').' '.__('average', 'wp-postratings').': %RATINGS_AVERAGE% '.__('out of', 'wp-postratings').' %RATINGS_MAX%'.__(',', 'wp-postratings').' '.__('rated', 'wp-postratings').')' ); add_option('postratings_template_none', '%RATINGS_IMAGES_VOTE% ('.__('No Ratings Yet', 'wp-postratings').')
%RATINGS_TEXT%' ); // Database Upgrade For WP-PostRatings 1.02 add_option('postratings_logging_method', '3' ); @@ -74,15 +74,15 @@ function ratings_activate() { // Database Upgrade For WP-PostRatings 1.20 add_option('postratings_ratingsvalue', array(1,2,3,4,5) ); add_option('postratings_customrating', 0 ); - add_option('postratings_template_permission', '%RATINGS_IMAGES% (%RATINGS_USERS% '.__('votes', 'wp-postratings').__(',', 'wp-postratings').' '.__('average', 'wp-postratings').': %RATINGS_AVERAGE% '.__('out of', 'wp-postratings').' %RATINGS_MAX%)
'.__('You need to be a registered member to rate this.', 'wp-postratings').'' ); + add_option('postratings_template_permission', '%RATINGS_IMAGES% (%RATINGS_USERS% %RATINGS_VOTE_TEXT%'.__(',', 'wp-postratings').' '.__('average', 'wp-postratings').': %RATINGS_AVERAGE% '.__('out of', 'wp-postratings').' %RATINGS_MAX%)
'.__('You need to be a registered member to rate this.', 'wp-postratings').'' ); // Database Upgrade For WP-PostRatings 1.30 - add_option('postratings_template_mostrated', '
  • %POST_TITLE% - %RATINGS_USERS% '.__('votes', 'wp-postratings').'
  • ' ); + add_option('postratings_template_mostrated', '
  • %POST_TITLE% - %RATINGS_USERS% %RATINGS_VOTE_TEXT%'.'
  • ' ); // Database Upgrade For WP-PostRatings 1.50 delete_option('widget_ratings_highest_rated'); delete_option('widget_ratings_most_rated'); - add_option('postratings_vote_text_singular', 'Vote' ); - add_option('postratings_vote_text_plural', 'Votes' ); + add_option('postratings_vote_text_singular', 'vote' ); + add_option('postratings_vote_text_plural', 'votes' ); // Index $index = $wpdb->get_results( "SHOW INDEX FROM $wpdb->ratings;" ); diff --git a/postratings-templates.php b/postratings-templates.php index 53ba456..e6b3280 100644 --- a/postratings-templates.php +++ b/postratings-templates.php @@ -87,7 +87,7 @@ function ratings_updown_templates(template, print) { default_template = "
  • %POST_TITLE% (%RATINGS_SCORE% %RATINGS_USERS% )
  • "; break; case "mostrated": - default_template = "
  • %POST_TITLE% - %RATINGS_USERS%
  • "; + default_template = "
  • %POST_TITLE% - %RATINGS_USERS% %RATINGS_VOTE_TEXT%
  • "; break; } if(print) { @@ -100,13 +100,13 @@ function ratings_default_templates(template, print) { var default_template; switch(template) { case "vote": - default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_USERS% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    %RATINGS_TEXT%"; + default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_USERS% %RATINGS_VOTE_TEXT% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    %RATINGS_TEXT%"; break; case "text": - default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% : %RATINGS_AVERAGE% %RATINGS_MAX% )"; + default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% %RATINGS_VOTE_TEXT% : %RATINGS_AVERAGE% %RATINGS_MAX% )"; break; case "permission": - default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    "; + default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% %RATINGS_VOTE_TEXT% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    "; break; case "none": default_template = "%RATINGS_IMAGES_VOTE% ()
    %RATINGS_TEXT%"; @@ -115,7 +115,7 @@ function ratings_default_templates(template, print) { default_template = "
  • %POST_TITLE% %RATINGS_IMAGES% (%RATINGS_AVERAGE% %RATINGS_MAX%)
  • "; break; case "mostrated": - default_template = "
  • %POST_TITLE% - %RATINGS_USERS%
  • "; + default_template = "
  • %POST_TITLE% - %RATINGS_USERS% %RATINGS_VOTE_TEXT%
  • "; break; } if(print) { @@ -149,6 +149,9 @@ function ratings_default_templates(template, print) {
    + + +
    %RATINGS_SCORE% - %RATINGS_TEXT% -
    %RATINGS_VOTE_TEXT% -

    @@ -163,6 +166,7 @@ function ratings_default_templates(template, print) {

    - %RATINGS_USERS%

    - %RATINGS_AVERAGE%

    - %RATINGS_PERCENTAGE%

    +

    - %RATINGS_VOTE_TEXT%


    @@ -179,6 +183,7 @@ function ratings_default_templates(template, print) {

    - %RATINGS_USERS%

    - %RATINGS_AVERAGE%

    - %RATINGS_PERCENTAGE%

    +

    - %RATINGS_VOTE_TEXT%


    @@ -194,6 +199,7 @@ function ratings_default_templates(template, print) {

    - %RATINGS_USERS%

    - %RATINGS_AVERAGE%

    - %RATINGS_PERCENTAGE%

    +

    - %RATINGS_VOTE_TEXT%


    @@ -248,6 +254,7 @@ function ratings_default_templates(template, print) {

    - %POST_CONTENT%

    - %POST_URL%

    - %POST_THUMBNAIL%

    +

    - %RATINGS_VOTE_TEXT%


    From b5016b35cba047a4dd25e483748a16b83d1f30b3 Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 15 Oct 2018 23:22:37 -0300 Subject: [PATCH 3/5] Overwrite the Default Templates with the custom Vote Text --- postratings-options.php | 18 +++++++++--------- postratings-templates.php | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/postratings-options.php b/postratings-options.php index 06c2182..bc5b2cd 100644 --- a/postratings-options.php +++ b/postratings-options.php @@ -130,22 +130,22 @@ function ratings_updown_templates(template, print) { var default_template; switch(template) { case "vote": - default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_SCORE% %RATINGS_USERS% )
    %RATINGS_TEXT%"; + default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT%)
    %RATINGS_TEXT%"; break; case "text": - default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% )"; + default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT% )"; break; case "permission": - default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% )
    "; + default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT% )
    "; break; case "none": default_template = "%RATINGS_IMAGES_VOTE% ()
    %RATINGS_TEXT%"; break; case "highestrated": - default_template = "
  • %POST_TITLE% (%RATINGS_SCORE% %RATINGS_USERS% )
  • "; + default_template = "
  • %POST_TITLE% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT%)
  • "; break; case "mostrated": - default_template = "
  • %POST_TITLE% - %RATINGS_USERS%
  • "; + default_template = "
  • %POST_TITLE% - %RATINGS_USERS% %RATINGS_VOTE_TEXT%
  • "; break; } if(print) { @@ -158,13 +158,13 @@ function ratings_default_templates(template, print) { var default_template; switch(template) { case "vote": - default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_USERS% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    %RATINGS_TEXT%"; + default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_USERS% %RATINGS_VOTE_TEXT% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    %RATINGS_TEXT%"; break; case "text": - default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% : %RATINGS_AVERAGE% %RATINGS_MAX% )"; + default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% %RATINGS_VOTE_TEXT% : %RATINGS_AVERAGE% %RATINGS_MAX% )"; break; case "permission": - default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    "; + default_template = "%RATINGS_IMAGES% (%RATINGS_USERS% %RATINGS_VOTE_TEXT% : %RATINGS_AVERAGE% %RATINGS_MAX%)
    "; break; case "none": default_template = "%RATINGS_IMAGES_VOTE% ()
    %RATINGS_TEXT%"; @@ -173,7 +173,7 @@ function ratings_default_templates(template, print) { default_template = "
  • %POST_TITLE% %RATINGS_IMAGES% (%RATINGS_AVERAGE% %RATINGS_MAX%)
  • "; break; case "mostrated": - default_template = "
  • %POST_TITLE% - %RATINGS_USERS%
  • "; + default_template = "
  • %POST_TITLE% - %RATINGS_USERS% %RATINGS_VOTE_TEXT%
  • "; break; } if(print) { diff --git a/postratings-templates.php b/postratings-templates.php index e6b3280..50c1f7a 100644 --- a/postratings-templates.php +++ b/postratings-templates.php @@ -72,19 +72,19 @@ function ratings_updown_templates(template, print) { var default_template; switch(template) { case "vote": - default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_SCORE% %RATINGS_USERS% )
    %RATINGS_TEXT%"; + default_template = "%RATINGS_IMAGES_VOTE% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT%)
    %RATINGS_TEXT%"; break; case "text": - default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% )"; + default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT% )"; break; case "permission": - default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% )
    "; + default_template = "%RATINGS_IMAGES% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT% )
    "; break; case "none": default_template = "%RATINGS_IMAGES_VOTE% ()
    %RATINGS_TEXT%"; break; case "highestrated": - default_template = "
  • %POST_TITLE% (%RATINGS_SCORE% %RATINGS_USERS% )
  • "; + default_template = "
  • %POST_TITLE% (%RATINGS_SCORE% %RATINGS_USERS% %RATINGS_VOTE_TEXT%)
  • "; break; case "mostrated": default_template = "
  • %POST_TITLE% - %RATINGS_USERS% %RATINGS_VOTE_TEXT%
  • "; From 95be39075bade977b446a9ac5ca9519d0262183a Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 15 Oct 2018 23:25:09 -0300 Subject: [PATCH 4/5] Replaces the vote text token by the appropriated value --- wp-postratings.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wp-postratings.php b/wp-postratings.php index 7618b0e..6bbdf32 100644 --- a/wp-postratings.php +++ b/wp-postratings.php @@ -1073,6 +1073,8 @@ function expand_ratings_template($template, $post_data, $post_ratings_data = nul $ratings_max = (int) get_option( 'postratings_max' ); $ratings_custom = (int) get_option( 'postratings_customrating' ); $ratings_options = get_option( 'postratings_options' ); + $ratings_vote_text_singular = get_option('postratings_vote_text_singular'); + $ratings_vote_text_plural = get_option('postratings_vote_text_plural'); if ( is_object( $post_data ) ) { $post_id = (int) $post_data->ID; @@ -1149,6 +1151,11 @@ function expand_ratings_template($template, $post_data, $post_ratings_data = nul $value = str_replace("%RATINGS_AVERAGE%", number_format_i18n($post_ratings_average, 2), $value); $value = str_replace("%RATINGS_PERCENTAGE%", number_format_i18n($post_ratings_percentage, 2), $value); $value = str_replace("%RATINGS_USERS%", number_format_i18n($post_ratings_users), $value); + if ($post_ratings_users > 1) { + $value = str_replace("%RATINGS_VOTE_TEXT%", $ratings_vote_text_plural, $value); + } else { + $value = str_replace("%RATINGS_VOTE_TEXT%", $ratings_vote_text_singular, $value); + } // Post Template Variables $post_link = get_permalink($post_data); From 8aa298dbb138b35e3366c60b1fbb8f952424894b Mon Sep 17 00:00:00 2001 From: Bruno Monteiro Date: Tue, 16 Oct 2018 21:54:49 -0300 Subject: [PATCH 5/5] Provides default values for the vote text options --- wp-postratings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-postratings.php b/wp-postratings.php index 6bbdf32..266352d 100644 --- a/wp-postratings.php +++ b/wp-postratings.php @@ -1073,8 +1073,8 @@ function expand_ratings_template($template, $post_data, $post_ratings_data = nul $ratings_max = (int) get_option( 'postratings_max' ); $ratings_custom = (int) get_option( 'postratings_customrating' ); $ratings_options = get_option( 'postratings_options' ); - $ratings_vote_text_singular = get_option('postratings_vote_text_singular'); - $ratings_vote_text_plural = get_option('postratings_vote_text_plural'); + $ratings_vote_text_singular = get_option('postratings_vote_text_singular', 'vote'); + $ratings_vote_text_plural = get_option('postratings_vote_text_plural', 'votes'); if ( is_object( $post_data ) ) { $post_id = (int) $post_data->ID;