Plugin Directory

Changeset 2951952


Ignore:
Timestamp:
08/11/2023 05:53:56 AM (3 years ago)
Author:
Dudo
Message:

version 3.4.4

Location:
yet-another-stars-rating/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • yet-another-stars-rating/trunk/admin/editor/YasrOnSavePost.php

    r2907917 r2951952  
    9090        $rating = (float)$rating;
    9191
    92         if ($rating > 5) {
    93             $rating = 5;
    94         }
    95 
    96         if($rating <= 0) {
    97             return;
    98         }
     92        $rating = yasr_validate_rating($rating, 0);
    9993
    10094        /**
  • yet-another-stars-rating/trunk/docs/yasr_hooks.md

    r2944495 r2951952  
    66_Add custom script in one of the page used by YASR, at the beginning_
    77
    8 | Argument | Type | Description |
    9 | --- | --- | --- |
    10 | $hook | string |  |
     8|Argument | Type | Description |
     9| --- | --- | --- |
     10|$hook | string |  |
    1111___
    1212 ### `do_action('yasr_add_admin_scripts_end')`
     
    1616_Add custom script in one of the page used by YASR, at the end_
    1717
    18 | Argument | Type | Description |
    19 | --- | --- | --- |
    20 | $hook | string |  |
     18|Argument | Type | Description |
     19| --- | --- | --- |
     20|$hook | string |  |
    2121___
    2222
     
    3434_Use this action to add content inside shortcode creator_
    3535
    36 | Argument | Type | Description |
    37 | --- | --- | --- |
    38 | $n_multi_set | int |  |
    39 | $multi_set | string |  the multiset name |
     36|Argument | Type | Description |
     37| --- | --- | --- |
     38|$n_multi_set | int |  |
     39|$multi_set | string |  the multiset name |
    4040___
    4141
     
    5757_Hook here to add new content at the beginning of the div_
    5858
    59 | Argument | Type | Description |
    60 | --- | --- | --- |
    61 | $post_id | int |  |
    62 | $set_id | int |  |
     59|Argument | Type | Description |
     60| --- | --- | --- |
     61|$post_id | int |  |
     62|$set_id | int |  |
    6363___
    6464 ### `do_action('yasr_add_content_multiset_tab_pro')`
     
    6868_Hook here to add new content_
    6969
    70 | Argument | Type | Description |
    71 | --- | --- | --- |
    72 | $post_id | int |  |
    73 | $set_id | int |  |
     70|Argument | Type | Description |
     71| --- | --- | --- |
     72|$post_id | int |  |
     73|$set_id | int |  |
    7474___
    7575
     
    8080_Hook here to add actions when YASR save data on save_post_
    8181
    82 | Argument | Type | Description |
    83 | --- | --- | --- |
    84 | $post_id | int |  |
     82|Argument | Type | Description |
     83| --- | --- | --- |
     84|$post_id | int |  |
    8585___
    8686 ### `do_action('yasr_action_on_overall_rating')`
     
    9090_Do action before overall rating is saved, works only in classic editor_
    9191
    92 | Argument | Type | Description |
    93 | --- | --- | --- |
    94 | $post_id | int |  |
    95 | $rating | float |  |
     92|Argument | Type | Description |
     93| --- | --- | --- |
     94|$post_id | int |  |
     95|$rating | float |  |
    9696___
    9797
     
    102102_Hook here to add content at the bottom of the metabox_
    103103
    104 | Argument | Type | Description |
    105 | --- | --- | --- |
    106 | $post_id | int |  |
     104|Argument | Type | Description |
     105| --- | --- | --- |
     106|$post_id | int |  |
    107107___
    108108
     
    130130_Since this could contain js, this will only allow FALSE as value_
    131131
    132 | Argument | Type | Description |
    133 | --- | --- | --- |
    134 | $style_page_upgrade_pro_js | string |  |
     132|Argument | Type | Description |
     133| --- | --- | --- |
     134|$style_page_upgrade_pro_js | string |  |
    135135___
    136136
     
    248248_Use this hook to add (or eventually remove) supported itemTypes_
    249249
    250 | Argument | Type | Description |
    251 | --- | --- | --- |
    252 | $itemTypes | array |  an array containing all the default supported itemTypes |
     250|Argument | Type | Description |
     251| --- | --- | --- |
     252|$itemTypes | array |  an array containing all the default supported itemTypes |
    253253___
    254254 ### `apply_filters('yasr_filter_itemtypes_fields')`
     
    264264_yasr_softwareapplication_price_
    265265
    266 | Argument | Type | Description |
    267 | --- | --- | --- |
    268 | $additionalFields | array |  an array containing all the default supported additional fields |
     266|Argument | Type | Description |
     267| --- | --- | --- |
     268|$additionalFields | array |  an array containing all the default supported additional fields |
    269269___
    270270
     
    333333_If not used, will work with no support for atts_
    334334
    335 | Argument | Type | Description |
    336 | --- | --- | --- |
    337 | $this->shortcode_name | string |  Name of shortcode caller |
    338 | $atts | string|array |  Shortcode atts |
     335|Argument | Type | Description |
     336| --- | --- | --- |
     337|$this->shortcode_name | string |  Name of shortcode caller |
     338|$atts | string|array |  Shortcode atts |
    339339___
    340340 ### `apply_filters('yasr_multi_set_ranking_atts')`
     
    350350_If not used, shortcode will works only with setId param_
    351351
    352 | Argument | Type | Description |
    353 | --- | --- | --- |
    354 | $this->shortcode_name | string |  Name of shortcode caller |
    355 | $atts | string|array |  Shortcode atts |
     352|Argument | Type | Description |
     353| --- | --- | --- |
     354|$this->shortcode_name | string |  Name of shortcode caller |
     355|$atts | string|array |  Shortcode atts |
    356356___
    357357
     
    367367 ### `do_action('yasr_action_on_visitor_vote')`
    368368
    369  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 89](.././includes/shortcodes/classes/YasrShortcodesAjax.php:89)
     369 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 93](.././includes/shortcodes/classes/YasrShortcodesAjax.php:93)
     370
     371_Hook here to add an action on visitor votes (e.g. empty cache)_
     372
     373|Argument | Type | Description |
     374| --- | --- | --- |
     375|$array_action_visitor_vote | array |  An array containing post_id and is_singular |
    370376___
    371377 ### `apply_filters('yasr_vv_cookie')`
    372378
    373  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 197](.././includes/shortcodes/classes/YasrShortcodesAjax.php:197)
     379 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 201](.././includes/shortcodes/classes/YasrShortcodesAjax.php:201)
    374380___
    375381 ### `apply_filters('yasr_vv_updated_text')`
    376382
    377  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 210](.././includes/shortcodes/classes/YasrShortcodesAjax.php:210)
     383 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 214](.././includes/shortcodes/classes/YasrShortcodesAjax.php:214)
    378384___
    379385 ### `apply_filters('yasr_vv_saved_text')`
    380386
    381  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 213](.././includes/shortcodes/classes/YasrShortcodesAjax.php:213)
     387 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 217](.././includes/shortcodes/classes/YasrShortcodesAjax.php:217)
    382388___
    383389 ### `do_action('yasr_action_on_visitor_multiset_vote')`
    384390
    385  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 324](.././includes/shortcodes/classes/YasrShortcodesAjax.php:324)
     391 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 328](.././includes/shortcodes/classes/YasrShortcodesAjax.php:328)
    386392___
    387393 ### `apply_filters('yasr_mv_cookie')`
    388394
    389  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 429](.././includes/shortcodes/classes/YasrShortcodesAjax.php:429)
     395 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 433](.././includes/shortcodes/classes/YasrShortcodesAjax.php:433)
    390396___
    391397 ### `apply_filters('yasr_mv_saved_text')`
    392398
    393  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 438](.././includes/shortcodes/classes/YasrShortcodesAjax.php:438)
     399 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 442](.././includes/shortcodes/classes/YasrShortcodesAjax.php:442)
    394400___
    395401 ### `apply_filters('yasr_filter_ranking_request')`
    396402
    397  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 621](.././includes/shortcodes/classes/YasrShortcodesAjax.php:621)
     403 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 625](.././includes/shortcodes/classes/YasrShortcodesAjax.php:625)
    398404___
    399405 ### `apply_filters('yasr_add_sources_ranking_request')`
    400406
    401  Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 672](.././includes/shortcodes/classes/YasrShortcodesAjax.php:672)
     407 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 676](.././includes/shortcodes/classes/YasrShortcodesAjax.php:676)
    402408___
    403409
     
    417423_Use this filter to customize yasr visitor votes readonly._
    418424
    419 | Argument | Type | Description |
    420 | --- | --- | --- |
    421 | $shortcode_html | string |  html for the shortcode |
    422 | $stored_votes | array |  array with average rating data for the post id. |
    423 | $this->post_id | int |  the post id |
    424 | $stored_votes | YasrDB::visitorVotes() |  array |
     425|Argument | Type | Description |
     426| --- | --- | --- |
     427|$shortcode_html | string |  html for the shortcode |
     428|$stored_votes | array |  array with average rating data for the post id. |
     429|$this->post_id | int |  the post id |
     430|$stored_votes | YasrDB::visitorVotes() |  array |
    425431___
    426432 ### `apply_filters('yasr_vv_cookie')`
     
    430436_Use this filter to customize the visitor votes cookie name_
    431437
    432 | Argument | Type | Description |
    433 | --- | --- | --- |
    434 |  | string |  yasr_visitor_votes_cookie is the default name |
     438|Argument | Type | Description |
     439| --- | --- | --- |
     440| | string |  yasr_visitor_votes_cookie is the default name |
    435441___
    436442 ### `apply_filters('yasr_cstm_text_already_voted')`
     
    466472_"General Settings" -> "Custom text to display BEFORE Visitor Rating"_
    467473
    468 | Argument | Type | Description |
    469 | --- | --- | --- |
    470 | $number_of_votes | int |  the total number of votes |
    471 | $average_rating | float |  the average rating |
    472 | $this->unique_id | string |  the dom ID |
     474|Argument | Type | Description |
     475| --- | --- | --- |
     476|$number_of_votes | int |  the total number of votes |
     477|$average_rating | float |  the average rating |
     478|$this->unique_id | string |  the dom ID |
    473479___
    474480 ### `apply_filters('yasr_cstm_text_after_vv')`
     
    482488_"General Settings" -> "Custom text to display AFTER Visitor Rating"_
    483489
    484 | Argument | Type | Description |
    485 | --- | --- | --- |
    486 | $number_of_votes | int |  the total number of votes |
    487 | $average_rating | float |  the average rating |
    488 | $this->unique_id | string |  the dom ID |
     490|Argument | Type | Description |
     491| --- | --- | --- |
     492|$number_of_votes | int |  the total number of votes |
     493|$average_rating | float |  the average rating |
     494|$this->unique_id | string |  the dom ID |
    489495___
    490496 ### `apply_filters('yasr_vv_shortcode')`
     
    494500_Use this filter to customize the yasr_visitor_votes shortcode_
    495501
    496 | Argument | Type | Description |
    497 | --- | --- | --- |
    498 | $shortcode_html | string |  html for the shortcode |
    499 | $this->post_id | int |  the post id |
    500 | $this->starSize | string | () the star size |
    501 | $this->readonly | string |  is the stars are readonly or not |
    502 | $this->ajax_nonce_visitor | string |  the WordPress nonce |
    503 | $this->is_singular | string |  if the current page is_singular or not |
     502|Argument | Type | Description |
     503| --- | --- | --- |
     504|$shortcode_html | string |  html for the shortcode |
     505|$this->post_id | int |  the post id |
     506|$this->starSize | string | () the star size |
     507|$this->readonly | string |  is the stars are readonly or not |
     508|$this->ajax_nonce_visitor | string |  the WordPress nonce |
     509|$this->is_singular | string |  if the current page is_singular or not |
    504510___
    505511
     
    537543_Use this hook to write your custom microdata from scratch_
    538544
    539 | Argument | Type | Description |
    540 | --- | --- | --- |
    541 | $item_type_for_post | string |  the itemType selected for the post |
     545|Argument | Type | Description |
     546| --- | --- | --- |
     547|$item_type_for_post | string |  the itemType selected for the post |
    542548___
    543549 ### `apply_filters('yasr_filter_existing_schema')`
  • yet-another-stars-rating/trunk/includes/classes/YasrDB.php

    r2944495 r2951952  
    9191        $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
    9292
    93         if (!$overall_rating || $overall_rating < 0) {
    94             $overall_rating = 0;
    95         }
    96         if($overall_rating > 5) {
    97             $overall_rating = 5;
    98         }
     93        $overall_rating = yasr_validate_rating($overall_rating, 0);
     94
    9995        return $overall_rating;
    10096    }
  • yet-another-stars-rating/trunk/includes/shortcodes/classes/YasrShortcodesAjax.php

    r2944495 r2951952  
    4444        add_action('wp_ajax_nopriv_yasr_send_visitor_rating', array($this, 'saveVV'));
    4545
     46        //die if post status is non publish
     47        add_action('yasr_action_on_visitor_vote',             array($this, 'dieIfPrivatePost'));
     48        add_action('yasr_action_on_visitor_multiset_vote',    array($this, 'dieIfPrivatePost'));
     49
    4650        //MV save rating
    4751        add_action('wp_ajax_yasr_visitor_multiset_field_vote',        array($this, 'saveMV'));
     
    6973        $this->dieIfNotAjax();
    7074
    71         if (isset($_POST['rating'], $_POST['post_id'])) {
    72             $rating        = (int) $_POST['rating'];
    73             $post_id       = (int) $_POST['post_id'];
    74             $is_singular   = $_POST['is_singular'];
    75         }
    76         else {
    77             echo ($this->returnErrorResponse(__('Error in Ajax Call, missing required param.', 'yet-another-stars-rating')));
    78             die();
    79         }
    80 
    81         if(isset($_POST['nonce_visitor'])) {
    82             $nonce_visitor = $_POST['nonce_visitor'];
    83         } else {
    84             $nonce_visitor = false;
    85         }
    86 
    87         $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular);
    88 
    89         do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
    90 
    91         $nonce_response = self::validNonce($nonce_visitor, 'yasr_nonce_vv');
    92         if($nonce_response !== true) {
    93             die($nonce_response);
    94         }
    95 
    96         if(YASR_ALLOWED_USER === 'logged_only' && !is_user_logged_in()) {
    97             echo ($this->returnErrorResponse(__('Only logged in user can rate.', 'yet-another-stars-rating')));
    98             die();
    99         }
    100 
    101         if ($rating < 1) {
    102             $rating = 1;
    103         }
    104         elseif ($rating > 5) {
    105             $rating = 5;
    106         }
    107 
    108         $current_user_id = get_current_user_id();
     75        $this->vvDieIfNotValidData();
     76
     77        $post_id     = (int) $_POST['post_id'];
     78        $is_singular = $_POST['is_singular'];
     79
     80        $this->vvDieIfNonceInvalid();
     81
     82        $this->actionOnVV($post_id, $is_singular);
     83
     84        $this->vvDieIfNotAllowed();
     85
     86        $rating = yasr_validate_rating((int) $_POST['rating']);
    10987
    11088        if (is_user_logged_in()) {
    111             $result_insert_log = $this->saveVVLoggedIn($post_id, $current_user_id, $rating);
     89            $result_insert_log = $this->saveVVLoggedIn($post_id, get_current_user_id(), $rating);
    11290
    11391        } //if user is not logged in insert
     
    125103        die(); // this is required to return a proper result
    126104    }
     105
     106    /**
     107     * Echo an error and die if rating or post id are missing in $_POST
     108     *
     109     * @author Dario Curvino <@dudo>
     110     *
     111     * @since  3.4.4
     112     * @return void
     113     */
     114    private function vvDieIfNotValidData() {
     115        if (!isset($_POST['rating']) || !isset($_POST['post_id'])) {
     116            echo $this->returnErrorResponse(__('Error in Ajax Call, missing required param.', 'yet-another-stars-rating'));
     117            die();
     118        }
     119    }
     120
     121    /**
     122     * Validate the nonce
     123     *
     124     * @author Dario Curvino <@dudo>
     125     *
     126     * @since  3.4.4
     127     * @return void
     128     */
     129    private function vvDieIfNonceInvalid () {
     130        if(isset($_POST['nonce_visitor'])) {
     131            $nonce_visitor = $_POST['nonce_visitor'];
     132        } else {
     133            $nonce_visitor = false;
     134        }
     135
     136        $nonce_response = self::validNonce($nonce_visitor, 'yasr_nonce_vv');
     137        if($nonce_response !== true) {
     138            die($nonce_response);
     139        }
     140    }
     141
     142
     143    /**
     144     * Create an array and add an action to perform on vv
     145     *
     146     * @author Dario Curvino <@dudo>
     147     *
     148     * @since 3.4.4
     149     *
     150     * @param $post_id
     151     * @param $is_singular
     152     *
     153     * @return void
     154     */
     155    private function actionOnVV($post_id, $is_singular) {
     156        $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular);
     157
     158        /**
     159         * Hook here to add an action on visitor votes (e.g. empty cache)
     160         * @param array $array_action_visitor_vote An array containing post_id and is_singular
     161         */
     162        do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
     163    }
     164
     165    /**
     166     * @author Dario Curvino <@dudo>
     167     *
     168     * Die if user not allowed to rate
     169     *
     170     * @since 3.4.4
     171     * @return void
     172     */
     173    private function vvDieIfNotAllowed() {
     174        if(YASR_ALLOWED_USER === 'logged_only' && !is_user_logged_in()) {
     175            echo ($this->returnErrorResponse(__('Only logged in user can rate.', 'yet-another-stars-rating')));
     176            die();
     177        }
     178    }
     179
    127180
    128181    /**
     
    285338        //return rest response
    286339        return $array_to_return;
     340    }
     341
     342    /**
     343     * @author Dario Curvino <@dudo>
     344     *
     345     * @since 3.4.4
     346     *
     347     * @param $array_action_visitor_vote
     348     *
     349     * @return void
     350     */
     351    public function dieIfPrivatePost($array_action_visitor_vote) {
     352        $post_id = $array_action_visitor_vote['post_id'];
     353        if(!is_user_logged_in() || !current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
     354            $status = get_post_status($post_id);
     355
     356            if ($status !== 'publish') {
     357                echo $this->returnErrorResponse(__("This post doesn't exists or is private", 'yet-another-stars-rating'));
     358                die();
     359            }
     360        }
    287361    }
    288362
  • yet-another-stars-rating/trunk/includes/shortcodes/classes/YasrVisitorVotes.php

    r2929048 r2951952  
    153153            }
    154154
    155             //I've to check $cookie_value !== false before because
    156             //if $cookie_value is false, $cookie_value < 1 return true (...wtf...)
     155            //I've to check $cookie_value !== false before
    157156            if($cookie_value !== false) {
    158                 if ($cookie_value > 5) {
    159                     $cookie_value = 5;
    160                 } elseif ($cookie_value < 1) {
    161                     $cookie_value = 1;
    162                 }
     157                $cookie_value = yasr_validate_rating($cookie_value);
    163158            }
    164159            //return int
  • yet-another-stars-rating/trunk/includes/yasr-includes-functions.php

    r2907917 r2951952  
    384384    return esc_html($prefix) . str_shuffle(uniqid());
    385385}
     386
     387/**
     388 * Sanitize rating
     389 *
     390 * @author Dario Curvino <@dudo>
     391 *
     392 * @since 3.4.4
     393 *
     394 * @param $rating
     395 * @param $min_value
     396 * @param $only_min
     397 * @param $only_max
     398 *
     399 * @return int|mixed
     400 */
     401function yasr_validate_rating($rating, $min_value=1, $only_min=false, $only_max=false) {
     402    if(!$rating) {
     403        $rating = 0;
     404    }
     405
     406    if ($rating < $min_value) {
     407        $rating = $min_value;
     408    }
     409    elseif ($rating > 5) {
     410        $rating = 5;
     411    }
     412
     413    return $rating;
     414}
  • yet-another-stars-rating/trunk/readme.txt

    r2944495 r2951952  
    55Contributors: Dudo
    66Tested up to: 6.3
    7 Stable tag: 3.4.3
     7Stable tag: 3.4.4
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
     
    207207The full changelog can be found in the plugin's directory. Recent entries:
    208208
     209= 3.4.4 =
     210* TWEAKED: since this version, for non-logged-in users, or users that can't edit posts, it is no longer possible to vote for a post that do not exist or is marked as private.
     211If, for some reason, you need to do this, just add [this code](https://gist.github.com/Dudo1985/9105ee335f6104cc4ce4ea392416678c) into your functions.php file
     212
    209213= 3.4.3 =
    210214* TWEAKED: The same mechanisms to prevent spam ratings for yasr_visitor_votes now also work for yasr_visitor_multiset.
  • yet-another-stars-rating/trunk/yet-another-stars-rating.php

    r2944495 r2951952  
    55 * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
    66 * Description: Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
    7  * Version: 3.4.3
     7 * Version: 3.4.4
    88 * Requires at least: 4.7
    99 * Requires PHP: 5.4
     
    7979    // Signal that SDK was initiated.
    8080    do_action( 'yasr_fs_loaded' );
    81     define( 'YASR_VERSION_NUM', '3.4.3' );
     81    define( 'YASR_VERSION_NUM', '3.4.4' );
    8282    //Plugin absolute path
    8383    //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
Note: See TracChangeset for help on using the changeset viewer.