Skip to content

trenc/yab_review_rating

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

yab_review_rating

A comment based rating system for articles.

Version: 0.6

Table of contents

  1. Plugin requirements
  2. Configuration
  3. Tags
  4. Examples
  5. Changelog
  6. License
  7. Author contact

Plugin requirements

yab_review_rating’s minimum requirements:

  • Textpattern 4.x

Configuration

Open the plugin code. the first function contains the configuration values. There is a min and a max values for the rating. Valid values are 0-255.

Tags

yab_review_rating

Place this in your comment form. It will show the rating of the current comment.
Can be used elsewhere. If not used in comment context as comments_form or recent_comments you have to fill the id attribute.

id: integer (comment id)
Default: no set
Show the rating of a comment with this ID. Useful in a non comment context.

char: a valid string
Default: no set
If empty (default) the output will be the rating number. If a char (e.g. a asterisk *) is set the output will be the n-times repeated char, where n is the rating.

yab_review_rating_input

The form element for the rating. Should be placed in the comment_form form.

type: input type (text, select, radio, number, range)
Default: text
The type of the form element for the rating. Valid value are text, select, radio, number and range.

html_id: HTML id name
Default: not set
The HTML id attribute applied to the element.

class: HTML class name
Default: not set
The HTML/CSS class attribute applied to the element.

reverse: integer|string (a non-null value)
Default: 0
If reverse is given the output of the select or radio type is displayed in reverse order.

break: breakpoint (br|empty)
Default: ‘br’
Breakpoints für radio intputs. Can be empty or br.

default: integer
Default: not set
Preselected rating value (Could be any number between your min and max values).

yab_review_rating_average

Display the average rating for a given article.

id: string (comma-separated article ids)
Default: no set
The IDs of articles. If not set it must be placed in an article form (article context).

only_visible: integer|bool (1|0)
Default: 1
If set to 0 all comments (spam and moderated comments too) will be calculated.

exclude: string (a comma separated list of ratings)
Default: null
Exclude these ratings from the average rating calculation. So you can exclude ‘0’ values for not rated articles, due 0 is the default value. Depending on your rating system setting.

default: string (Text)
Default: ‘not yet rated’
The default text on articles without a rating.

decimals: integer
Default: 1
Define the decimal precision of the calculation and the output.

separator: string (string|empty)
Default: . (perdiod)
Choose your decimal separator. Can be empty (separator will be omitted) for HTML class friendly output.

round_to_half: string (up|down|)
Default: no net
Round to first half integer up or down or not at all. If not set the last decimal is automatically rounded up.

Examples

Example 1

Example of yab_review_rating_input in a comment_form form.

<txp:comments_error wraptag="ul" break="li" />
	<div class="message">
		<p><label for="name">Name:</label><br /><txp:comment_name_input /></p>
		<p><label for="email">Mail (not required, not visible):</label><br />
			<txp:comment_email_input /></p>
		<p><label for="yab-rr-rating">Rating</label><br />
			<txp:yab_review_rating_input html_id="yab-rr-rating" type="select" reverse="1" default="3" /></p>
		<p><label for="message">Review:</label><br />
			<txp:comment_message_input /></p>
		<p class="submit"><txp:comments_help /><txp:comment_preview /><txp:comment_submit /></p>
</div>

Will produce a comment form for article reviews (e.g. with yab_shop). The select dropdown menu for the rating is in reversed order (highest top) and the preselected rating value is 3.

Example 2

Example of yab_review_rating in a comments form.

<h3 class="commenthead"><txp:comment_permlink>#</txp:comment_permlink> - <txp:comment_name /> wrote at <txp:comment_time />:</h3>
<span class="rating">Rating: <txp:yab_review_rating char="*" /></span>
<txp:comment_message />

Will produce a comment/review with the name, text and time of the comment and the rating with asterisks *.

Example 3

Example of yab_review_rating in a comments form.

<h3 class="commenthead"><txp:comment_permlink>#</txp:comment_permlink> - <txp:comment_name /> wrote at <txp:comment_time />:</h3>
<span class="rating rating-value-<txp:yab_review_rating />">Rating:</span>
<txp:comment_message />

Will produce a the a comment/review with the name, text and time of the comment and the rating as HTML/CSS class.

Example 4

Example yab_review_rating_average.

<txp:yab_review_rating_average id="12" exclude="0" decimals="2" separator="" round_to_half="down" />

Say the article with the ID 12 do have 3 reviews: One with a rating of 0 and two with a rating of 4 each. The output will exclude the 0 from the calculation. So only the two 4-ratings will be used 4+4 = 8÷2 = 4. Average rating is 4. But we have decimals precision of 2, so it will be 4.00. No rounding required but the separator will be ommitted: 400 will be displayed.
exclude=“0” decimals=“2” separator="" round_to_half=“down” />

<txp:yab_review_rating_average id="12" decimals="2" separator="" round_to_half="down" />

Here we calculate an average from all reviews/ratings. Like above we have two 4 and 0-rating. So the rating is 0+4+4 = 8÷3 = 2.6666666667. Now we round to half down: 2.500000000 and use the decimal precision of 2: 2.50 and ommit the separator: 250.

Changelog

  • v0.1: 2013-12-24
    • initial release
  • v0.2: 2014-01-08
    • new: added a the tag <txp:yab_review_rating_average />
  • v0.3: 2014-01-12
    • new: added the id attribute to <txp:yab_review_rating />
    • modify: <txp:yab_review_rating /> can now be used in <txp:recent_comments />
  • v0.4: 2014-01-16
    • new: added reverse attribute to <txp:yab_review_rating_input />
    • new: added only_visible attribute to <txp:yab_review_rating_average />
    • modify: id attribute of <txp:yab_review_rating_average /> can now contain list of article ids
  • v0.5: 2017-02-10
    • TXP 4.6-ready
  • v0.6: 2017-03-09
    • bugfix: handle comment UI correctly, prevent rating resets to 0 if comment status is changed

Licence

This plugin is released under the GNU General Public License Version 2 and above

Author contact

About

A Textpattern plugin comment based rating system for articles.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages