2 edb Feb 25, 2008 23:25

I fixed this issue with Starrating plugin.
Can anybody try it before I update the download?
http://evocms-plugins.svn.sourceforge.net/viewvc/evocms-plugins/starrating_plugin/trunk/_starrating.plugin.php?revision=827
sam2kb wrote:
I fixed this issue with Starrating plugin.
Can anybody try it before I update the download?
http://evocms-plugins.svn.sourceforge.net/viewvc/evocms-plugins/starrating_plugin/trunk/_starrating.plugin.php?revision=827
i just had the time to test this one
i ve replaced the plugin file with the one you gave,
placed
<?php $Plugins->call_by_code( 'starrating', array('display' => 'toprated', 'limit' => 5 ) ); ?>
as usual, but it was not succesful, i ve never been able to make that Top rated posts thing work, i d be really glad if you could solve it..
i got the following error
Fatal error: Call to a member function get_renderers() on a non-object in /home/tilqi/domains/tilqi.com/public_html/plugins/starrating_plugin/_starrating.plugin.php on line 212
which refers to :
// Check to see if we want a rating for this post
$renders = $Plugins->validate_list( $Item->get_renderers() );
important edit to above post:
i have noticed that the plugin works and displays the top rated posts, but the error i ve mentioned above persists
Can you download the [url=http://sourceforge.net/project/showfiles.php?group_id=160495&package_id=235926]latest version[/url] and try again.
sam2kb wrote:
Can you download the [url=http://sourceforge.net/project/showfiles.php?group_id=160495&package_id=235926]latest version[/url] and try again.
yea, replaced the file and reloaded the plugin, and i ve even re-installed the plugin to make sure, still same.. you can see it at tilqi.com mainpage temporarily at the bottom of the sidebar
The error tells you that "You either use another variable as $Item in your skin or you put the code outside of the posts loop" ;)
Try to edit the line 210 to
elseif( is_object($Item) )
sam2kb wrote:
The error tells you that "You either use another variable as $Item in your skin or you put the code outside of the posts loop" ;)
<?php $Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) ); ?>
this one is in the post loop currently..
<?php $Plugins->call_by_code( 'starrating', array('display' => 'toprated', 'limit' => 5 ) ); ?>
and this goes to sidebar.inc.php right ? i ve placed it right before the sidebar container..
and what do you exactly mean when you say i use another variable $Item ? of course i do, for the post id, post title etc.. $Item->ID etc etc.. shouldnt i ??
sam2kb wrote:
Try to edit the line 210 to
elseif( is_object($Item) )
that seems to solve the problem, thank you very much...
one thing though, in IE6 i get script erros at the status bar.. which i suspect the starrating plugin may cause it, as the install is fresh and i dont use much scripts else than it atm, and also AFAI remember, it was kinda faulty, and you ve fixed those script (validation) errors previously, might it be the same issue again?
it says sth like:
error: 'bm' is null or not an object
line : 3
code: 0
char: 23522
Let me check it in IE6
Here's a demo http://b2evo.sonorth.com/dev/2/blog1.php
I didn't change anything. No PHP errors, no js errors in IE6.
sam2kb wrote:
Here's a demo http://ru.b2evo.net/dev/2/blog1.php
I didn't change anything. No PHP errors, no js errors in IE6.
i ve figured it out after disabling everything, it was the unexpected; google ie code js was causing the error.. strange.. dunno what is wrong with it :|
sam2kb wrote:
Try to edit the line 210 to
elseif( is_object($Item) )
Plugin works fine after adding that however i get
Notice: Undefined index: id in /home/tilqi/domains/tilqi.com/public_html/plugins/starrating_plugin/_starrating.plugin.php on line 224
which refers to :
WHERE id="'.$params['id'].'"');
in sidebar and in single post mode only.
ok, ok.. ignore the above post.. i -dunno- somehow added a 'starrating widget' in the sidebar, that caused it apparently, removing it solved the issue
I don't see any errors now, did you fix it?
sam2kb wrote:
I don't see any errors now, did you fix it?
tilqicom wrote:
i somehow added a 'starrating widget' in the sidebar, that caused it apparently, removing it solved the issue
if you like i can re-enable it for you to see the error :P
I'll check again on my dev blog. It's strange because I can't copy your errors.
sam2kb wrote:
I'll check again on my dev blog. It's strange because I can't copy your errors.
it seems that the plugin has created a 'widget' upon install.. is this the normal behaviour ? and if so ; what is that widget supposed to do..
it's the one causing the error when inserted..
You're right. I'm now fixing it.
tilqicom, can you try if it works now? You should use the widget instead of skin code to display the "Top rated" block. However the code should work also.
One more fix, the 'display' => 'notice' is not required any more.
sam2kb wrote:
tilqicom, can you try if it works now? You should use the widget instead of skin code to display the "Top rated" block. However the code should work also.
One more fix, the 'display' => 'notice' is not required any more.
cool, the widget works.. i have difficulties displaying pop up info, but i believe-hope- it's a particular issue related to me, ll let you know if i find anything, thanks for the fixes
Try to remove this code from skin, and enable pop-ups in settings
<?php $Plugins->call_by_code( 'starrating', array('display' => 'notice' ) ); ?>
sam2kb wrote:
Try to remove this code from skin, and enable pop-ups in settings
<?php $Plugins->call_by_code( 'starrating', array('display' => 'notice' ) ); ?>
did remove it, no luck still. and i havent modified the script or the php file of the plugin.i will try it on another install
I fixed pop-up notices, it was a lightbox/avatars conflict.
Update the starrating.js file
function sndReq(id_num, hturl)
{
var $ = jQuery.noConflict();
$('#unit_long'+id_num).html('<div style="height: 20px;"><em>Loading ...</em></div>');
$.get(hturl, function(data) {
if(data.indexOf('|') != -1) {
update = data.split('|');
$('#' + update[0]).html(update[1])
if (update[2]) disp_notice(update[3]);
//new Effect.Highlight(update[0], {startcolor: '#ff9900', endcolor: '#EEEEEE'});
}
})
}
function disp_notice(text)
{
var $ = jQuery.noConflict();
if ($('#ratingResults').length == 0) {
$('html').append('<div id="ratingResults" style="display:none"></div>')
}
$('#ratingResults').html(text)
el = $('#ratingResults');
var theTop = 30;
if (window.innerHeight) {
pos = window.pageYOffset
} else if (document.documentElement && document.documentElement.scrollTop) {
pos = document.documentElement.scrollTop
} else if (document.body) {
pos = document.body.scrollTop
}
if (pos < theTop) pos = theTop;
else pos += 30;
el.css('top', pos +'px');
el.css('opacity', 0.01)
el.show()
el.fadeTo('slow', 0.8)
setTimeout('el.fadeOut("slow")', 4000);
}
Plugin updated
Top rated block works as a widget.
Fixed pop-up notes lightbox/avatars conflict.
Fixed layout bug in evocamp skin.
Transparent background in infoicon.gif image.
Hi there,
is it possible to reprogram this star raging plugin to work with comments?
In my modified b2e i'm using comments as a main and more important part of the blog, so i need to make users able to rate separate comments, which are still connected to particullar registered users.
can annyone help?
thanx
Ben
Hi there,
I'm an extreme novice and I'm using the B2 evolution to blog my website. I've managed to download the latest Starrating plugin but it says to put some code somewhere in the "post loop"... Sorry, but I have absolutely no idea what a post loop is.
Could someone please lend me some assistance? I don't mind doing the actual work but just not up with the jargon.
Thanks,
Sabrina
www.houkura.com
Welcome to the forums.
In skin directory http://www.houkura.com/b2evolution/blogs/skins/evocamp/ edit the file posts.main.php around the line 110
<?php
$Item->locale_temp_switch(); // Temporarily switch to post locale (useful for multilingual blogs)
?>
<h2><?php $Item->title(); ?></h2>
<div style="float:right">
<?php $Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) ); ?>
</div>
You can also do the same in single.main.php and page.main.php if you need stars in single posts and pages.
Hi,
I have a couple questions about the starratings plugin.
1) How can I get the version that tilqicom has on his site. The one with the bar looking image rather than the stars?
2) I would be fine with the stars, but I want 10 stars, and when I make it ten they overlap into the next column rather than resizing to fit in its normal space.
3) when using it as a widget on the sidebar is it possible to display a thumbnail above the text link that is attached to the post. If no thumbnail, then can it leave it as it is now.
Thanks,
Gene :-)
3. If you already put the function [url=http://forums.b2evolution.net/viewtopic.php?p=84132#84132]get_File_by_item_ID[/url] in hacks.php all you need is edit the following code in _starrating.plugin.php starting on line 489
if( ($rated_item = & $ItemCacheLight->get_by_ID( $results[$i]->post_ID, false )) !== false )
{
echo $params['item_start'];
if( $File = & get_File_by_item_ID($rated_item->ID) )
{ // Display the first linked image
echo '<img src="'.$File->get_thumb_url().'" alt="" />';
}
echo '<a href="'.$rated_item->get_permanent_url().'">'.$rated_item->title.'</a>';
echo $params['before_rating'].number_format( $results[$i]->rating, 1 ).$params['after_rating'];
echo ' <span class="notes">'.$results[$i]->total_votes.' '.$this->T_('votes').'</span>';
echo $params['item_end'];
}
2) I would be fine with the stars, but I want 10 stars, and when I make it ten they overlap into the next column rather than resizing to fit in its normal space.
In file plugins/starrating_plugin/stars.css between lines 85 and 97 edit the following code. Change 100px to 180 or 200px.
div.stars {
width: 100px;
text-align: left;
}
.unit-rating li a.starinfo, .unit-rating li a:hover.starinfo {
display: block;
height: 13px;
width: 13px;
background: url('infoicon.gif') no-repeat top right;
position: absolute;
left: 100px;
top: 3px;
}
Thanks again!
That worked perfectly.
I am curious. Could I replace the star image? I looked and it shows the three different color stars when I click view on any of the three list within my CPanel File Manager.
The image I would want to replace it with is a clear globe, a greyed globe, and a blur and green globe which I am currently working on making those three colors.
Thanks,
Gene :-)
Try this
Change star image
It's not hard to change the star image. First, download the default image and look at it. It's three stars stacked on top of each other. The top star is the empty version, the middle star is the hover version, and the bottom star is the normal one that shows the average rating. Create your new image to match this template, then upload it to the /starrating_plugin/ folder. Then, edit the stars.css file to match your new file name. If your image has a width that's different than 20px, then you'll need to edit the two lines toward the top of stars.css that set the width. Then edit _starrating.plugin.php and find "var $width = 20;" and edit the value to match your image's width.
Thanks again. It worked and looks pretty good to me.
The first time I clicked I got an error message though. After reloading it let me click. To check I had someone else go and try clicking, and they also got the error message. When they reloaded it did not let them click the next time, and gave the error again.
Here is the message:
Forbidden
You don't have permission to access /htsrv/call_plugin.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
--------------------------------------------------------------------------------
Apache/2.2.10 (Unix) mod_ssl/2.2.10 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at worldblogosphere.com Port 80
See if this can help http://forums.b2evolution.net//viewtopic.php?t=15651
Hi!
Does anybody have an idea, where's GENERAL difference between plugin's appearance in Firefox/IE6?
I've installed it just by doc, it works&looks great with Firefox (except for ru encoding, but this comes next :) )
And there's no popup to appear in IE. Popups at b2evolution.net work fine in the same browser, so the problem is somewhere on my website.
Yep, i forgot:
- b2evo 2.4.5
- starrating 0.7.5
- firefox 3.0.4
- IE 6.0.2900.2180.xpsp_sp2_qfe.080814-1242 if it's important
:D
There's an old version of the plugin running on b2evolution.net
Can you give a link to your site?
You can check it at http://kolonka.org/index.php/2007/11/01/?blog=1&m=20071101 (this test page only, there's no ratings on others)
Once again: everything looks ok in ff, but in IE there're no popups.
BTW, i can also see popups running fine in IE at http://tilqi.com/ - are they using an old version as well?
I found a problem. Seems like you use modified _html_footer.inc.php in your skin. Put this code in your template file before the closing </body> tag.
// Trigger plugin event, which could be used e.g. by a google_analytics plugin to add the javascript snippet here:
$Plugins->trigger_event('SkinEndHtmlBody');
Hah! That was damn easy!
Great thanks, sam2kb, now it works in IE! I don't wonder why firefox understands it all better than glitchy IE :D
One more issue left, now encoding-related one.
So
1) i do (re)load a page
2) i click "i" after stars - popup shows cyrillic properly
3) i click on stars - popup appears with "broken unicode"
4) i click "i" or stars again - encoding appears broken again
sam2kb, you seem to be familiar dealing with cyrillic problems, maybe you've faced this issue already?
Well, i hope i could fill locale's _global.php file fith those terrible &#xxx; but there should be a better way :D
PS. And, yes, this affects both ff&ie browsers
The template you're using is messed up and you should fix it first. Look at the source code, the <header> section included twice, that's why you have 70 errors an the website http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fkolonka.org%2Findex.php
Check the file index.main.php and make sure you don't include _html_header.inc.php twice.
To fix the message encoding try to edit the code starting on line 285 in _starrating.plugin.php
function htsrv_vote( & $params )
{
global $DB;
locale_activate( 'ru-RU' );
init_charsets($GLOBALS['current_charset']);
$T_vote = $this->T_('vote');
$T_votes = $this->T_('votes');
Hm, i should have thought better about piorities, but i didn't check validity for that long! :-/ It seems, that's time to really rearrange something. Thanks for your time, sam2kb, i'll check all that stuff.
sam2kb wrote:
To fix the message encoding try to edit the code
This didn't help, but i really have to clear up the template code first. Thanks again :D
I fixed the above code, can you try again.
Ok, here's the final version which will be included in the plugin.
function htsrv_vote( & $params )
{
global $DB, $current_charset;
if( !is_logged_in() )
{ // Use blog locale if not logged in
$BlogCache = & get_Cache( 'BlogCache' );
if( $Blog = & $BlogCache->get_by_ID( $params['blog'], false, false ) )
{
locale_activate( $Blog->locale );
init_charsets($current_charset);
}
}
$T_vote = $this->T_('vote');
$T_votes = $this->T_('votes');
I get this error after install:
Fatal error: Call to undefined function: require_js() in /home/dis000459/domains/cowpoop.nl/public_html/plugins/starrating_plugin/_starrating.plugin.php on line 149
what to do?
What version of b2evo are you using?
If it's not 2.x you should upgrade.
sam2kb wrote:
What version of b2evo are you using?
If it's not 2.x you should upgrade.
No 1.10.2
can't I use an older version of the starrating?
If you don't want to upgrade for some reason you can (probably) use plugin version 0.6 http://downloads.sourceforge.net/evocms-plugins/starrating_plugin-0.6.zip?use_mirror=
Hello,
I have a weird js conflict with this plugin when used with gallery plugin from balupton. i get this :
$("lightboxImage").style has no properties
$('lightboxImage').style.margin = paddingSize + 'px';
when i disable the starating plugin, the error is gone !
any chance to correct this ?
Use version 0.6 with b2evo 1.x
I'm using version O.6 with b2evolution 2.4.6 - do i have to go back ????
How can you use Gallery plugin from balupton if it only works in b2evolution 1.x ?
Use version 0.6 in b2evolution 1.x, and version 0.76 in b2evolution 2.x or 3.x
Hello, is it possible to amend this one to rate comments in the same way like posts - the post is given by moderator and the comments are the answers to the post, these need to be rated. Is it possible to do in some simple way using this plugin?
thnx
Ben
@BenasPlentas
It's not possible without changing the plugin.
SECURITY UPDATE
Version 0.7.7 fixes a few SQL injection vulnerabilites. Upgrade as soon as possible!
[url=https://sourceforge.net/project/showfiles.php?group_id=160495&package_id=235926&release_id=681352]Download at SourceForge[/url]
Okay, I can't get this plugin figured out. I downloaded, installed, and edited the plugin (checked the box to allow voting) but on the instruction page it says to enter this code
<?php $Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) ); ?>
5. to the index.main.php file for any skin where you want the star ratings to be used.
Put this in the post loop inside the bSmallPrint div or just below the post title.
Except I don't see either of those two things (bSmallPrint div or the post title) in the skin I am using (Simple Zen).
Am I totally missing something? Here is my index.main.php for Simple Zen:
<?php
/**
* This is the main/default page template.
*
* For a quick explanation of b2evo 2.0 skins, please start here:
* {@link http://manual.b2evolution.net/Skins_2.0}
*
* The main page template is used to display the blog when no specific page template is available
* to handle the request (based on $disp).
*
* @package evoskins
* @subpackage kubrick
*
* @version $Id: index.main.php,v 1.3 2007/10/01 01:06:31 fplanque Exp $
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
// This is the main template; it may be used to display very different things.
// Do inits depending on current $disp:
skin_init( $disp );
// -------------------------- HTML HEADER INCLUDED HERE --------------------------
skin_include( '_html_header.inc.php' );
// Note: You can customize the default HTML header by copying the generic
// /skins/_html_header.inc.php file into the current skin folder.
// -------------------------------- END OF HEADER --------------------------------
?>
<?php
// ------------------------- BODY HEADER INCLUDED HERE --------------------------
skin_include( '_body_header.inc.php' );
// Note: You can customize the default BODY heder by copying the generic
// /skins/_body_footer.inc.php file into the current skin folder.
// ------------------------------- END OF FOOTER --------------------------------
?>
<div id="content" class="narrowcolumn">
<?php
// ------------------------- MESSAGES GENERATED FROM ACTIONS -------------------------
messages( array(
'block_start' => '<div class="action_messages">',
'block_end' => '</div>',
) );
// --------------------------------- END OF MESSAGES ---------------------------------
?>
<?php
// ------------------------- TITLE FOR THE CURRENT REQUEST -------------------------
request_title( array(
'title_before'=> '<h2>',
'title_after' => '</h2>',
'title_none' => '',
'glue' => ' - ',
'title_single_disp' => true,
'format' => 'htmlbody',
) );
// ------------------------------ END OF REQUEST TITLE -----------------------------
?>
<?php
// -------------- MAIN CONTENT TEMPLATE INCLUDED HERE (Based on $disp) --------------
skin_include( '$disp$', array(
) );
// Note: you can customize any of the sub templates included here by
// copying the matching php file into your skin directory.
// ------------------------- END OF MAIN CONTENT TEMPLATE ---------------------------
?>
</div>
<?php
// ------------------------- SIDEBAR INCLUDED HERE --------------------------
skin_include( '_sidebar.inc.php' );
// Note: You can customize the default BODY footer by copying the
// _body_footer.inc.php file into the current skin folder.
// ----------------------------- END OF SIDEBAR -----------------------------
?>
<?php
// ------------------------ SIDEBAR 2 INCLUDED HERE -------------------------
skin_include( '_sidebar_2.inc.php' );
// Note: You can customize the default BODY footer by copying the
// _body_footer.inc.php file into the current skin folder.
// ----------------------------- END OF SIDEBAR -----------------------------
?>
<?php
// ------------------------- BODY FOOTER INCLUDED HERE --------------------------
skin_include( '_body_footer.inc.php' );
// Note: You can customize the default BODY footer by copying the
// _body_footer.inc.php file into the current skin folder.
// ------------------------------- END OF FOOTER --------------------------------
?>
<?php
// ------------------------- HTML FOOTER INCLUDED HERE --------------------------
skin_include( '_html_footer.inc.php' );
// Note: You can customize the default HTML footer by copying the
// _html_footer.inc.php file into the current skin folder.
// ------------------------------- END OF FOOTER --------------------------------
?>
I did add it below the title section, but I don't see any changes to my posts. The only voting option I see is if you hit comment/feedback, you can vote from "poor" to "excellent." Is this all the star rating does? Put a star rating on the comment? I want stars on the actual post so people can just click on the star (like b2evo has on their pages).
Once you have the plugin installed and the settings the way you want them, then go the write tab and create a post. If you want the post to have the rating system, then make sure that there's a check in the box next to 'Star Rating' in the 'Text renderers' section in the lower right.
I did this.
Now the stars should appear next to your post. To vote, click on the star you're voting for. If JavaScript is enabled, it will say 'Loading . . .', then display the new rating and thank you for your vote. If JavaScript is disabled, then the page will reload and the new rating will be shown.
But I don't get this. I am using Firefox and I am sure I have javascript enabled because I can vote and see starts on b2evo's pages.
I feel so stupid. What am I missing?
In Simple Zen you have to edit posts.main.php and single.main.php
You also need to update stars.css http://evocms-plugins.svn.sourceforge.net/viewvc/evocms-plugins/starrating_plugin/trunk/stars.css?revision=1123
edit
<div class="postmetadata">
<ul>
<?php
$Item->author( array(
'before' => '<li class="author">'.T_( 'By').' ',
'after' => '</li>',
) );
?>
to
<div class="postmetadata">
<ul>
<?php
echo '<li>';
$Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) );
echo '</li>';
?>
<?php
$Item->author( array(
'before' => '<li class="author">'.T_( 'By').' ',
'after' => '</li>',
) );
?>
Okay, I thought I was going nuts!
That said, I found the spot in posts.main.php, but in single.main.php it's:
<p class="postmetadata alt">
but I changed it and it seems to work.
I didn't have a stars.css so added the css to the stylesheet.css - but now I get NO stars unless I roll over them:
http://www.hudson2001.com/blogs/index.php/recipes/
Thoughts?
stars.css is in plugins/starrating_plugin directory
/smacks head
Eek, now I get an assortment of stars all at once! What did I screw up? :o
ETA: FIXED IT!
THANKS!! WOOHOO!!!!!!!!
ETA #2: Whoops...still no stars visible on unrated items (I am going back to each entry and checking the box to allow rating). You can see the "i" but no stars.
I gave you 5 stars for "Peanut Pudding" ;)
To enable rating for all posts select "silent" in plugin settings > rendering
I meant "stealth"
I changed it to stealth and I still only get stars when rolling over [on unrated items].
change this in stars.css, line 17
background: top left repeat-x;
to
background-position: top left;
background-repeat: repeat-x;
YOU ROCK!
I tried to give you reputation points, but it said "To give reputation the same user you should spread it around." Hmmm. Other than that being very strange grammatically, I don't think I've given it to you before?!?!
:)
It means that u cant rep the same person consecutively twice. u hv to rep any other person before repping him again.
Okay. I will try to remember. :)
That said, now I am having another issue. :(
I went back to edit my posts so I can add the star rating system (by checking the box under Text Renderers) and it no longer appears! Not even on posts I've already added the ratings to! Does this have to do with that stealth thing?
Never mind. I got it. Stealth means it shows up automatically and I don't have to check the box, right? Because all my posts on that blog have the stars there without me changing anything.
"stealth" means that you don't have to check the checkbox each time you create a post.
Right.
//edit: sam2kb was faster than me. ;-)
I can give you rep points in 30 minutes. :)
I have an old blog currently using the star rating plugin without any problems. I made a new blog with the Pyrmont skin, and want it to use the star rating also. It kinda works on the new blog, but doesn't load correctly, and shows duplicate sets of stars. http://web420.com/blog/multiple-realities.php.
I didn't add the code: <?php $Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) ); ?> because there is no bSmallPrint div inside the index.main.php for this skin. I am not sure if I need to add it because the star rating already shows up. Is this duplicate star issue because I need to to paste the code somewhere? Where would I add the code for the Prymont skin since it doesn't have a bSmallPrint div inside the index.main.php? If that isn't the issue what else could be causing the star ratings to not load correctly?
Thanks,
Robert
You don't need to add any code because the skin you're using already has it.
Make sure you're using the latest version of the plugin. When you update the plugin, replace [u]all files[/u]
I can't get it to work at my install, tried everything... what do I do wrong?
Nothing displays, accept the error on line 212, no stars, nothing.
So I've been using the star rating plugin on my site:
http://birthdayshoes.com/store/kayakshed
But it seems as though for each instance, no matter what the rating is, it only displays one star. I updated the CSS -- I'm guessing this has something to do with the actual plugin. Anyone have any bright, starry ideas as to what might be the problem?
Your plugin doesn't add CSS styles in <head> section. Make sure you're running the latest version 0.7.7
Please post the content of your _star_rating.plugin.php
Hey sam - thanks for responding.
Definitely running the latest. Here is the php file:
<?php
/**
* This file implements the Star Rating plugin for
* {@link http://b2evolution.net b2evolution}.
*
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
*
* TODO:
* Antispam (and robot) hidden first option, then block
* This is what is skewing votes low
* Allow restricting to members
* Record who voted for what
* Ability to change vote
* Ability to display main column posts in rating order
* Remove some repetition of code
*
*/
class starrating_plugin extends Plugin
{
var $version = '0.7.7';
var $priority = 50;
var $code = 'starrating';
var $author = 'Danny Ferguson';
var $help_url = '';
var $width = 20; // Width of individual star in px.
var $apply_rendering = 'opt-in';
/**
* @internal
*/
var $disp_params = array();
/**
* Set name and desc.
*/
function PluginInit()
{
$this->name = $this->T_('Star Rating');
$this->short_desc = $this->T_('AJAX-powered star ratings for posts.');
}
function starrating_plugin()
{
$this->PluginInit();
}
function GetDefaultSettings()
{
return array(
'outof' => array(
'label' => $this->T_('Out of'),
'defaultvalue' => 5,
'note' => $this->T_('How many stars are possible?'),
'type' => 'integer',
'size' => '2'
),
'checkip' => array(
'label' => $this->T_('Check IP'),
'defaultvalue' => 1,
'note' => $this->T_('Check IP to prevent multiple votes on one post from one person.'),
'type' => 'checkbox'
),
'popup' => array(
'label' => $this->T_('Pop-up info'),
'defaultvalue' => 1,
'note' => $this->T_('Show info and notices in pop-ups that fade in and out. Requires javascript, but does not disrupt layout. This option requires an additional skin tag, see the Readme file.'),
'type' => 'checkbox'
),
'inline' => array(
'label' => $this->T_('Inline info'),
'defaultvalue' => 0,
'note' => $this->T_('Show info and notices just below the stars. Works with or without javascript enabled, but may disrupt layout.'),
'type' => 'checkbox'
) );
}
/**
* Create the table to store the rating votes
*
* @return array
*/
function GetDbLayout()
{
return array("CREATE TABLE ".$this->get_sql_table('ratings')." (
`id` varchar(11) NOT NULL,
`total_votes` int(11) NOT NULL default '0',
`total_value` int(11) NOT NULL default '0',
`used_ips` longtext,
`blog_id` int(11) NOT NULL default '0', PRIMARY KEY (`id`) );");
}
function RenderItemAsHtml( & $params )
{
// This is not actually a renderer,
// we're just using the checkbox
// to see if we should display for
// the given post.
}
/**
* Get definitions for widget specific editable params
*
* @see Plugin::GetDefaultSettings()
* @param local params like 'for_editing' => true
*/
function get_widget_param_definitions( $params )
{
return array(
'title' => array(
'label' => $this->T_('Widget title'),
'note' => $this->T_('Widget title displayed in skin.'),
'defaultvalue' => $this->T_('Top Rated'),
),
'limit' => array(
'label' => $this->T_('Display'),
'note' => $this->T_('Max items to display.'),
'size' => 3,
'defaultvalue' => 5,
'type' => 'integer',
),
'minvote' => array(
'label' => $this->T_('Minimum votes'),
'note' => $this->T_('Minimum number of votes required to be in the list.'),
'size' => 3,
'defaultvalue' => 1,
'type' => 'integer',
),
'display' => array(
'label' => $this->T_('Method'),
'defaultvalue' => 'top_rated',
'disabled' => 1,
),
);
}
function SkinBeginHtmlHead( & $params )
{
global $plugins_url;
$outof = $this->Settings->get('outof');
// Display the head code:
require_js('#jquery#');
require_js($plugins_url.'starrating_plugin/starrating.js', false);
require_css($plugins_url.'starrating_plugin/stars.css', false);
/** echo '<style type="text/css">'."\n";
echo '.unit-rating { width: '.$outof * $this->width.'px }'."\n";
for( $ncount = 1; $ncount <= $outof; $ncount++ )
{
echo '.unit-rating a.r'.$ncount.'-unit { left: '.($ncount - 1) * $this->width.'px }'."\n";
echo '.unit-rating a.r'.$ncount.'-unit:hover { width: '.$ncount * $this->width.'px }'."\n";
}
echo "</style>\n"; */
return true;
}
function SkinEndHtmlBody( & $params )
{
if( !defined('RATING_NOTICE_ADDED') )
echo '<div id="ratingResults" style="display:none"></div>';
}
function SkinTag( $params )
{
global $plugins_url, $DB, $Item, $Plugins, $blog, $Blog;
$T_vote = $this->T_('vote');
$T_votes = $this->T_('votes');
$outof = $this->Settings->get('outof');
if( !isset($params['display']) ) $params['display'] = 'stars';
if( $params['display'] == 'notice' )
{ // Deprecated
echo '<div id="ratingResults" style="display:none"></div>';
define( 'RATING_NOTICE_ADDED', true );
}
elseif( $params['display'] == 'toprated' )
{ // Skin method (deprecated)
$error_msg = '<div class="action_messages"><div class="log_error">';
$error_msg .= 'This method is deprecated!<br />Use the <b>Star Rating</b> widget to display top rated posts.';
$error_msg .= '<br /><br />You should delete the "Top Rated" code from skin.';
$error_msg .= '</div></div>';
//echo $error_msg; // Display error
$this->disp_top_rated( $params );
}
elseif( $params['display'] == 'top_rated' )
{ // Widget
$this->disp_top_rated( $params );
}
elseif( $params['display'] == 'stars' && is_object($Item) )
{ // Display the rating code for an Item:
// Check to see if we want a rating for this post
$renders = $Plugins->validate_list( $Item->get_renderers() );
// If the renderer checkbox is unchecked, then display nothing
if( !in_array($this->code, $renders) ) return false;
$ip = $_SERVER['REMOTE_ADDR'];
$r = $DB->get_row('
SELECT total_votes, total_value, used_ips
FROM '.$this->get_sql_table('ratings').'
WHERE id='.$DB->quote( $params['id'] ) );
if( isset($r) ) $tense = ($r->total_votes == 1) ? $T_vote : $T_votes;
?>
<div id="unit_long<?php echo $Item->ID ?>">
<div id="rating"><h4><center>Store Rating</center></h4>
<ul class="unit-rating">
<?php
echo '<li class="current-rating" style="width: '.@number_format($r->total_value / $r->total_votes , 2 ) *
$this->width.'px">'.$this->T_('Currently').' '.@number_format($r->total_value / $r->total_votes , 2 ).'/'.$outof.'</li>';
for( $ncount = 1; $ncount <= $outof; $ncount++ )
{
// AJAX url:
$hturl = $this->get_htsrv_url('vote', array('vote' => $ncount, 'ip' => $ip, 'id' => $Item->ID, 'blog' => $blog ) );
// Url for non-JS browsers
$current_url = $Blog->get('url');
$hturlnojs = $this->get_htsrv_url('vote', array('vote' => $ncount, 'ip' => $ip, 'id' => $Item->ID, 'returnto' => $current_url, 'blog' => $blog ) );
echo '<li><a href="'.$hturlnojs.'" title="'.$ncount.' '.$this->T_('out of').' '.$outof.'" class="r'.$ncount.'-unit"
onclick="javascript:sndReq(\''.$Item->ID.'\', \''.$hturl.'\');return false">'.$ncount.'</a></li>'."\n";
}
$ncount=0; // resets the count
if( !empty($r->total_votes))
{
$avg = @number_format($r->total_value / $r->total_votes, 1);
$total = $r->total_votes;
}
else
{
$avg = '0.0';
$total = 0;
}
$tense = ($total == 1) ? $T_vote : $T_votes;
if( $this->Settings->get('popup'))
{
echo '<li><a href="javascript:void(0);" onclick="disp_notice(\'<p class=\\\'ratingNotes\\\'>'.
sprintf( /*TRANS: Rating: 34 out of 50 votes cast*/ $this->T_('Rating: %s out of %d %s cast'),
'<strong>'.$avg.'</strong>', $total, $tense ).'</p>\'); return false;" class="starinfo"><span>i</span></a></li>';
}
?>
</ul>
<?php
if( $this->Settings->get('inline') )
{
echo '<p class="ratingNotes">'.sprintf( $this->T_('Rating: %s out of %d %s cast'),
'<strong>'.$avg.'</strong>', $total, $tense ).' </p>';
}
?>
</div>
</div>
<?php
return true;
}
}
// Set the plugin up to take AJAX calls
function GetHtsrvMethods()
{
return array( 'vote' );
}
function htsrv_vote( & $params )
{
global $DB, $current_charset;
if( !is_logged_in() )
{ // Use blog locale if not logged in
$BlogCache = & get_Cache( 'BlogCache' );
if( $Blog = & $BlogCache->get_by_ID( $params['blog'], false, false ) )
{
locale_activate($Blog->locale);
init_charsets($current_charset);
}
}
$T_vote = $this->T_('vote');
$T_votes = $this->T_('votes');
$outof = $this->Settings->get('outof');
$ip_num = $params['ip'];
$id_sent = $params['id'];
$vote_sent = $params['vote'];
$blog = $params['blog'];
$tableName = $this->get_sql_table('ratings');
$r = $DB->get_row('
SELECT total_votes, total_value, used_ips
FROM '.$this->get_sql_table('ratings').'
WHERE id = '.$DB->quote( $params['id'] ) );
$checkIP = ( empty( $r->used_ips) ? NULL : unserialize($r->used_ips) );
$count = ( empty( $r->total_votes ) ? NULL : $r->total_votes );
$current_rating = ( empty( $r->total_value ) ? 0 : $r->total_value );
$sum = $params['vote'] + $current_rating;
$tense = ($count == 1) ? $this->T_('vote') : $this->T_('votes');
//check see if this ip has voted before or not
if( $this->Settings->get('checkip') )
{
$voted = $DB->get_var( 'SELECT count(*) FROM '.$tableName
.' WHERE used_ips LIKE '.$DB->quote( '%'.$ip_num.'%' )
.' AND id = '.$DB->quote( $id_sent ) );
}
// the above pattern match ip:suggested by Bramus! //http://www.bram.us/
if( !empty($voted) )
{
$new_back = '<ul class="unit-rating">'."\n".
'<li class="current-rating" style="width:'.@number_format($current_rating/$count,2) *
$this->width .'px">'.$this->T_('Current rating').'.</li>'."\n";
for( $ncount = 1; $ncount <= $outof; $ncount++ )
{
$new_back .= "<li class=\"r{$ncount}-unit\">{$ncount}</li>\n";
}
if( $this->Settings->get('popup'))
{
$new_back .= '<li><a href="javascript:void(0);" onclick="disp_notice(\'<p class=\\\'ratingNotes\\\'>'.
sprintf( $this->T_('Rating: %s out of %d %s cast'), '<strong>'.@number_format($r->total_value / $r->total_votes, 1).'</strong>',
$r->total_votes, $tense ).'</p>\'); return false;" class="starinfo"><span>i</span></a></li>';
}
$new_back .= '</ul>';
// show the current value of the vote with the current numbers
$notice = '<p class="ratingNotes">'.sprintf( $this->T_('Rating: %s out of %d %s cast'),
'<strong>'.@number_format($current_rating/$count,1).'</strong>', $count, $tense ).
'<br /><span class="error">'.$this->T_('You have previously voted').'!</span></p>';
}
else
{
if( $sum == 0 )
{
$added=0; //checking to see if the first vote has been tallied
}
else
{
$added=$count+1; //increment the current number of votes
}
if( is_array($checkIP) )
{
array_push($checkIP,$ip_num); //if it is an array i.e. already has entries the push in another value
}
else
{
$checkIP=array($ip_num); //for the first entry
}
$insert=serialize($checkIP);
// see if the ID already exists
$idexists = $DB->get_var( 'SELECT count(*) FROM '.$tableName
.' WHERE id='.$DB->quote( $id_sent ) );
if( $idexists == true )
{
$DB->query( 'UPDATE '.$tableName.' SET total_votes='.$DB->quote( $added )
.', total_value='.$DB->quote( $sum ).', used_ips='
.$DB->quote( $insert ).', blog_id='.$DB->quote( $blog )
.' WHERE id='.$DB->quote( $id_sent ) );
}
else
{
$DB->query( 'INSERT INTO '.$tableName.' VALUES ('
.$DB->quote( $id_sent ).', '.$DB->quote( $added )
.', '.$DB->quote( $sum ).', '.$DB->quote( $insert )
.', '.$DB->quote( $blog ).')' );
}
//update the database and echo back the new stuff
$r = $DB->get_row( 'SELECT total_votes, total_value, used_ips '
.'FROM '.$tableName.' WHERE id='.$DB->quote( $id_sent ) );
$count = $r->total_votes; //how many votes total
$current_rating = $r->total_value; //total number of rating added together and stored
$new_back = '<ul class="unit-rating">'."\n".
'<li class="current-rating" style="width:'.@number_format($current_rating/$count,2) *
$this->width.'px">'.$this->T_('Current rating').'.</li>'."\n";
for( $ncount = 1; $ncount <= $outof; $ncount++ )
{
$new_back .= "<li class=\"r{$ncount}-unit\">{$ncount}</li>\n";
}
if( $this->Settings->get('popup') )
{
$new_back .= '<li><a href="javascript:void(0);" onclick="disp_notice(\'<p class=\\\'ratingNotes\\\'>'.
sprintf( $this->T_('Rating: %s out of %d %s cast'), '<strong>'.@number_format($r->total_value / $r->total_votes, 1).'</strong>',
$r->total_votes, $tense ).'</p>\'); return false;" class="starinfo"><span>i</span></a></li>';
}
$new_back .= '</ul>';
$tense = ($count == 1) ? $T_vote : $T_votes;
$notice = '<p class="ratingNotes">'.sprintf( $this->T_('Rating: %s out of %d %s cast'),
'<strong>'.@number_format($sum/$added,1).'</strong>', $added, $tense ).
'<br /><span class="success">'.$this->T_('Thank you for your vote').'!</span></p>';
}
// If JavaScript is off, then just send them back to the referer
if( isset($params['returnto']) )
{
header('location: '.$params['returnto']);
}
else
{
//name of the div id to be updated | the html that needs to be changed
//$output = "unit_long$id_sent|$new_back";
$output = "unit_long$id_sent|$new_back";
if( $this->Settings->get('inline') ) $output .= "$notice";
if( $this->Settings->get('popup') ) $output .= "|ratingResults|$notice";
echo $output;
}
}
// Display the Top Rated block
function disp_top_rated( $params )
{
global $DB, $blog;
if( !isset($params['title'])) $params['title'] = $this->T_('Top Rated'); // Title
if( !isset($params['before_rating'])) $params['before_rating'] = ' ('; // What comes before and after the comment count
if( !isset($params['after_rating'])) $params['after_rating'] = ')'; // How many of the top posts to show
if( !isset($params['limit'])) $params['limit'] = 5; // Limit
if( !isset($params['minvote'])) $params['minvote'] = 1; // Minimum number of votes required to be in the list
$this->init_display( $params );
// Deprecated
if( !isset($params['block_start'])) $params['block_start'] = '<div class="bSideItem">';
if( !isset($params['block_end'])) $params['block_end'] = '</div>';
if( !isset($params['block_title_start'])) $params['block_title_start'] = '<h3>';
if( !isset($params['block_title_end'])) $params['block_title_end'] = '</h3>';
if( !isset($params['list_start'])) $params['list_start'] = '<ol>';
if( !isset($params['list_end'])) $params['list_end'] = '</ol>';
if( !isset($params['item_start'])) $params['item_start'] = '<li>';
if( !isset($params['item_end'])) $params['item_end'] = '</li>';
$sql = "
SELECT DISTINCT post_ID , total_value / total_votes AS rating, total_votes
FROM ( T_items__item , ".$this->get_sql_table('ratings').")
INNER JOIN T_postcats ON post_ID = postcat_post_ID
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
WHERE cat_blog_id = ".$blog."
AND ".$this->get_sql_table('ratings').".id = T_items__item.post_ID
AND total_votes >= ".$params['minvote']."
ORDER BY `rating` DESC
LIMIT ".$params['limit'];
$results = $DB->get_results($sql);
if( empty($results) ) return;
if( empty($results[0]->rating) ) return;
$ItemCacheLight = & get_Cache( 'ItemCacheLight' );
// START DISPLAY:
echo $params['block_start'];
echo $params['block_title_start'];
echo $params['title'];
echo $params['block_title_end'];
echo $params['list_start'];
for( $i = 0; $i < $params['limit']; $i++ )
{
// Stop the loop if you get to a post with 0 comments
if( empty( $results[$i]->rating ) ) break;
if( ($rated_item = & $ItemCacheLight->get_by_ID( $results[$i]->post_ID, false )) !== false )
{
echo $params['item_start'];
echo '<a href="'.$rated_item->get_permanent_url().'">'.$rated_item->title.'</a>';
echo $params['before_rating'].number_format( $results[$i]->rating, 1 ).$params['after_rating'];
echo ' <span class="notes">'.$results[$i]->total_votes.' '.$this->T_('votes').'</span>';
echo $params['item_end'];
}
}
echo $params['list_end'];
echo $params['block_end'];
}
/**
* Sets all the display parameters
* these will either be the default display params
* or the widget display params if it's in a container
*
* @param array $params
*/
function init_display( $params = array() )
{ // Merge Default settings (from this plugin) with basic widget settings into array $disp_params
$temp = $this->get_widget_param_definitions( array() );
foreach( $temp as $setting => $values )
$this->disp_params[ $setting ] = ( isset( $params[ $setting ] ) ? $params[ $setting ] : $this->Settings->get( $setting ) );
foreach( $params as $param => $value )
$this->disp_params[ $param ] = $value;
}
}
?>
Also, just double-checked and the CSS is being called in the header (though I probably should merge it into my main style.css sheet to reduce calls on the server and speed up the site right?).
Here is that file:
http://birthdayshoes.com/plugins/starrating_plugin/stars.css
I was talking about this bit of code, it's commented out. Just uncomment it and you should be fine.
/**
echo '<style type="text/css">'."\n";
echo '.unit-rating { width: '.$outof * $this->width.'px }'."\n";
for( $ncount = 1; $ncount <= $outof; $ncount++ )
{
echo '.unit-rating a.r'.$ncount.'-unit { left: '.($ncount - 1) * $this->width.'px }'."\n";
echo '.unit-rating a.r'.$ncount.'-unit:hover { width: '.$ncount * $this->width.'px }'."\n";
}
echo "</style>\n";
*/
Ok so did that -- still not showing up for me though :( (I see the css in the head too)
Some styles in your style.css breaks the stars. I can see them if I disable style.css in FF web developer.
Try playing with styles.css, especially with styles for <li> and <ul> tags
Thanks for pointing me in the right direction -- here's what I had to do it to fix it (and I suspect this will be a problem for anyone else using an evocamp based theme).
In stars.css, find around row three or four
.unit-rating { background-image: url("star_rating.gif") }
To that, add background: none; so it looks like this:
.unit-rating { background: none; background-image: url("star_rating.gif") }
That fixed it for me (nothing like a little trial and error CSS to kick off your monday morning!)
Hello,
I installed the star rating plugin on the Floral skin (http://skins.b2evo.net/2/index.php?tempskin=Floral).
When a post has no vote is shows fine (white stars only) but when the post gets voted the starts are duplicated like there are two rows of them, one row with white starts and one with yellow stars on top of the other but a little but on the right.
On other skins (b2evo_ru for example) the plugin works fine.
Can you please give me a clue what I should modify to make it work?
Thanks in advance.
[/img]
Hello again,
Just found something using firebug in the style.css of the Floral skin:
.entry ul li,
.entry ol li,
#content ul li,
#content ol li {
margin-left: 25px;
}
if I change margin-left: 0px; the two rows of starts are perfectly align to the left and the duplicate effect disappears.
I'm not a web programmer but I think if I make this modification in the .css I might mess something else.
What is your advice ?
Thanks
Hello.
Can anyone direct me to the star rating plugin download?
Ty much :)
Thank you much! Always.
Plugin updated to v0.8.0
* compatible with b2evolution 4.1 and later
* various fixes and improvements
sam2kb wrote:
Plugin updated to v0.8.0
* compatible with b2evolution 4.1 and later
* various fixes and improvements
I have installed the latest version of the plug-in and I am seeing an issue with the plugin when you extend the number of stars pass five. The little "button" to display the vote results sits in the middle of the stars. I have been trying to figure out exactly what you did here; both in the php and the css. I see you create a li to hold this and that the <li>s are floated left but at the same time I see absolute positioning with a setting for left: for the anchor tag. I thought take the anchor out of the ul but that resulted in 123456789i running down the right of the page. I can keep trying to hack this but thought that since you wrote the plugin you can probably more quickly get this resolved or point me in the right direction.
Thanks for the info, I'll check that.
sam2kb wrote:
Thanks for the info, I'll check that.
This is a simple fix. The problem is that the location is fixed and then a left: position stated in the CSS. Move the left: out of the CSS and put that in the script and have PHP calculate what the left: position should be based on the number of stars. I have yet to implement this as I just decided to change the left: value in the CSS. However, to have it where it can be more flexible, we should calculate that position from the number of stars so that it automatically changes when a user changes the number of stars.
Thanks for your work on this star rating plugin; it is quite nice and works beautifully. :D
Hi,
I have upgraded to 5.0.4.
Earlier I used to see the star rating in the feedback form, but now after upgrading, I'm unable to get the star rating the at the feedback form.
Appreciate you help.
Link to blog: http://nerurkars.in/blogs
Turn it on in blog settings > features > comments
Thanks a lot, François. It worked.
Have you resolved this issue?
I'm pretty sure that with new plugins (v2.* generation) you pretty much don't have to add code to the skin anymore. OTOH if this plugin specifically says it is for 2.* AND it says to add code then I guess it does.