2 personman May 30, 2006 18:05

Hi Personman,
Well that sounds fantastic!! I'll look into an upgrade (my project is still in the development stage also) over the next few days.
Would be great if I could test your new plugin for the rating then.
thanks a lot
Hi Personman,
I working on the rating tool using b2evolution 1.8. Do you have a sample which I can use.
Thanks
Here's my plugin:
http://www.brendoman.com/dev/beta/plugins/starrating.zip
It still needs a little polishing before it's ready to be released, but it basically works and I've got it running at plugin.b2evolution.net so people can rate plugins.
Hi Personman,
Thank you for the plugin. I have downloaded it and shall integrate it in 1.8 alpha.
Best wishes.
Hi Personman,
I am having this error when I install the plugin in 1.8.1 RC. The error is
Parse error: parse error, unexpected ';', expecting T_FUNCTION in D:\Apache Group\Apache2\htdocs\b2e\blogs\plugins\starrating_plugin\_starrating.plugin.php on line 318
Can you kindly advice me on fixing this error.
Thanks
Best wishes
chauhans, the error is because personman used a PHP short tag (line 210 in version 0.1 of the plugin).
Search for "<\?[^p]" (regular expression) and replace it with "<?php".
Sorry about that. I just fixed it in the new version, which I'm trying to get released today if blueyed and I can get one more thing fixed.
Ok, here's the official release:
http://plugins.b2evolution.net/index.php/2006/10/05/star_rating
alright :o looks good but I got this error: document all is zero or no object
I am using b2evo 1.8
I solved it by myself. plugin does not work with IE. the rating window is only a "black box".
it works very good with firefox.
If you want to use IE then upgrade to IE7.. unless you are one of the millions on Win2k that MS don't give a hoot about :)
The rating tool works with IE7, as well as a few other things.
Won't help your visitors though, unless you put up a big sign that says "Use Firefox, or if you must use IE, then get 7"
joachim,
You're right, there was a bug, but I just fixed it and updated the zip file. Download copy the new files over the old ones and it should work. Thanks for catching this for me.
Danny
Danny, I'm getting the following errors with Konqueror:
Error: http://demo.b2evolution.net/stable/blogs/plugins/starrating_plugin/scriptaculous/prototype.js: ReferenceError: Can't find variable: HTMLFormElement
Error: http://demo.b2evolution.net/stable/blogs/plugins/starrating_plugin/scriptaculous/effects.js: ReferenceError: Can't find variable: HTMLFormElement
Do you get the same error when trying the demos at script.aculo.us in Konqueror?
Yes, already on the homepage. I'll see if I can report it to either them or the Konqueror guys.
edit: I get it _only_ on the homepage, not on this demo page for example: http://wiki.script.aculo.us/scriptaculous/show/CombinationEffectsDemo
The plugin seems to work anyway.
the black window works pefekt @ IE with the permalink, but if you want to view the rating box from the "main-page" you still get a black box and not the rating inside.
Hi All
I have just installed b2Evolution ( 1.8) anh try to install starrating plugin by manual on manual.b2evolution.net but still have some problem.Could any one help me with some problems:
- I download and install plug-in successfully.
- In Start Rating Plug in setting, I set it "opt-out" in Rendering setting
- Modify "_main.php" in skin as manual
<?php $Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) ); ?>
But I am not sure where to hack second change :
<?php $Plugins->call_by_code( 'starrating', array('display' => 'notice' ) ); ?>
I try to post 1 post with already check Start Rating Option, but I did not see any change in my Blog.
Note: I installed b2E in localhost
Please give me some advices!
Thanks and Best Regards,
Khoa Huynh.
http://sapland.com
Khuynh,
That second line of code goes right after the <body> tag in your _main.php file.
Also make sure that the first bit of code is placed inside the bSmallPrint section (or at least somewhere inside the post loop).
Do you see any stars next to your post after doing that?
Danny
joachim,
I'm not sure what you mean. I tried skins.b2evolution.net in IE and I can vote from the main page. Do you have a link to a site where you're experiencing this problem?
@ personman:
main page: http://www.snigles.de
permalink-page: http://www.snigles.de/index.php/2006/10/08/sommermode_2007
I'm just getting mysql errors at your site.
?? everything works fine ??? there are no mysql errors.
The errors are gone now (but I didn't imagine them this morning). I think I see what has happened. You didn't follow directions very well and you placed the notify skin tag inside the post loop. You end up with several divs with the same id, so when the JS tries to update the div, it doesn't know which to use. Move that notify skin tag to right after the <body> tag and I think your problem will go away.
Dear personman
Thanks for your reply, now It work great.I like this plugin?
Khoa Huynh
Hello
i've got a problem with your plugin personman, i installed it as said in the manual, then i have
Undefined index: display in _starrating.plugin.php on line 123
i'm on 1.8-beta b2evolution.
Regards, patrice.
http://www.stufu.org
Try upgrading to 1.8.2. That what this was designed with. It's a more stable version, anyway, so you should be using it.
personman, the error/notice is with the plugin, not b2evo.
Care to add it to the evocms-plugins repo? Then I would just have taken a look at it.. :)
Seems the SkinTag() method gets called without a "display" param. You might want to check if it's empty() in your plugin (I have 0.5.2-dev here).
Personman
the rating just stops at 'Loading...'
Do you hve any idea why?
It worked for 1 day, than it just died
Thanx,
P.
System: b2evo 1.8.2, starrating 0.5
www.worldphoto.hu/newblog
Peter,
I just voted for a post on your blog and it worked fine.
:( it still desn't work on mine...
Thanx for checking.
P.
I notice that star rating doesn't work on the blog all blog. Is there a way to fix that?
I just installed on the 1.9.1 beta and I am wondering why I am receiving error messages:
Trying to get property of non-object in d:\program_files\wamp\www\blog\plugins\starrating_plugin\_starrating.plugin.php on line 210
Under this is repeats all the stars over and over. Also I am receiving the loading message after trying to submit.
Add
error_reporting(1);
to your /conf/_basic_config.php file (or to the top of the plugin file). 1.9.1 seems to enable display of php notices. I'll release a new version of the plugin that fixes all the notices (sloppy coding on my part), but you can turn down error reporting for the time being.
thanks, will try that!
okay added the error reporting line and that took care of the messages, however there is 1 issue that came out of that. not sure what the fix is, I will look into it but I wanted to show you so you could see:
Can you give a link to your site and let me know what web browser(s) are affected?
sorry its on a localhost, i have been testing and building up a blog. its on a closed network.
browsers affected though in my testing:
ie 6
firefox 2 - firefix also has a small black bar on the left side half of the size of the netscape
netscape 7 - netscape also has a black bar on the left side - image attached
Hi I love the fact that you have developed this plugin! Can't wait to get it working...
I am running 1.9.1- still in test -
I get this error in the sidebar:
Notice: Undefined offset: 2 in /home2/bigjim/public_html/blog/plugins/starrating_plugin/_starrating.plugin.php on line 177
When I go to the file, it's a blank space.
and when you vote you get a new page with this error:
Notice: unserialize() [function.unserialize]: Argument is not a string in /home2/bigjim/public_html/blog/plugins/starrating_plugin/_starrating.plugin.php on line 262
unit_long23|
You can see it at this url:
http://blog.hotstuffleatherandlace.com/index.php/b?cat=4
Also, I don't think the images are right...
Please help when you have the chance...
Thanks Jim
Figster wrote:
I get this error in the sidebar:
Notice: Undefined offset: 2 in /home2/bigjim/public_html/blog/plugins/starrating_plugin/_starrating.plugin.php on line 177
Danny : Something I noticed in Democracy was this error was caused by \n in one of the $params. If it's the same problem you can cure it like this
<input type="hidden" name="params" id="params" value='<?php echo str_replace( "\n", ' ', serialize($params) ); ?>' />
¥
The $params Just bellow line 117 looks like this:
function SkinTag( $params )
{
global $plugins_url, $DB, $Item, $Plugins, $blog, $ReqAbsUrl;
$outof = $this->Settings->get('outof');
if(!isset($params['display'])) $params['display'] = 'stars';
if ($params['display'] == 'notice') {
echo '<div id="ratingResults" style="display:none"></div>';
} elseif ($params['display'] == 'toprated')
{
Where would we fix it?
Thanks,
Jim
Hi Jim,
Sorry that was just a note for Danny.
You'd need to replace every occurence of :-
serialize($params)
with :
str_replace( "\n", ' ', serialize($params) )
Take a backup first though huh, because I haven't looked at the code I'm just basing it on the cure for a different plugin ;)
¥
Thanks again, did a quick search on the code no serialize($params) found. There are plenty of ($params) and even some $params.. not very good at this, maybe I should wait until personman looks at his code?
My blog is not live yet, but, I still don't care to mess up a good thing :)
Here is the code if you want to look at it.
<?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.' );
/**
*/
class starrating_plugin extends Plugin
{
var $version = '0.5-dev';
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';
/**
* Set name and desc.
*/
function starrating_plugin()
{
$this->name = T_('Star Rating');
$this->short_desc = T_('AJAX-powered star ratings for posts.');
}
function GetDefaultSettings()
{
return array(
'outof' => array(
'label' => T_( 'Out of' ),
'defaultvalue' => 5,
'note' => T_('How many stars are possible?'),
'type' => 'integer',
'size' => '2'
),
'checkip' => array(
'label' => T_( 'Check IP' ),
'defaultvalue' => 1,
'note' => T_( 'Check IP to prevent multiple votes on one post from one person.'),
'type' => 'checkbox'
),
'popup' => array(
'label' => T_( 'Pop-up info' ),
'defaultvalue' => 1,
'note' => 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' => T_( 'Inline info' ),
'defaultvalue' => 0,
'note' => 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.
}
function SkinBeginHtmlHead( & $params )
{
global $plugins_url;
$outof = $this->Settings->get('outof');
// Display the head code:
echo '<script type="text/javascript" src="'.$plugins_url.'starrating_plugin/js.js"></script>'."\n".
'<script type="text/javascript" src="'.$plugins_url.'starrating_plugin/scriptaculous/prototype.js"></script>'."\n".
'<script type="text/javascript" src="'.$plugins_url.'starrating_plugin/scriptaculous/scriptaculous.js?load=effects"></script>'."\n".
'<link rel="stylesheet" href="'.$plugins_url.'starrating_plugin/stars.css" type="text/css" />'."\n";
?>
<style type="text/css">
.unit-rating {width: <?php echo $outof * $this->width ?>px;}
<?php
for ($ncount = 1; $ncount <= $outof; $ncount++) { ?>.unit-rating a.r<?php echo $ncount ?>-unit {left: <?php echo ($ncount - 1) * $this->width ?>px; } .unit-rating a.r<?php echo $ncount ?>-unit:hover {width: <?php echo $ncount * $this->width ?>px; }
<?php } ?>
</style>
<?php
return true;
}
function SkinTag( $params )
{
global $plugins_url, $DB, $Item, $Plugins, $blog, $ReqAbsUrl;
$outof = $this->Settings->get('outof');
if(!isset($params['display'])) $params['display'] = 'stars';
if ($params['display'] == 'notice') {
echo '<div id="ratingResults" style="display:none"></div>';
} elseif ($params['display'] == 'toprated')
{
// Display the Top Rated block in the sidebar:
/**
* Default params:
*/
// This is what will enclose the block in the skin:
if(!isset($params['block_start'])) $params['block_start'] = '<div class="bSideItem">';
if(!isset($params['block_end'])) $params['block_end'] = "</div>\n";
// Title:
if(!isset($params['title'])) $params['title'] = '<h3>Top Rated</h3>';
// This is what will enclose the category list:
if(!isset($params['list_start'])) $params['list_start'] = '<ol>';
if(!isset($params['list_end'])) $params['list_end'] = "</ol>\n";
// This is what will separate the category links:
if(!isset($params['line_start'])) $params['line_start'] = '<li>';
if(!isset($params['line_end'])) $params['line_end'] = "</li>\n";
// What comes before and after the comment count:
if(!isset($params['before_rating'])) $params['before_rating'] = ' (';
if(!isset($params['after_rating'])) $params['after_rating'] = ')';
// Limit: How many of the top posts to show
if(!isset($params['limit'])) $params['limit'] = 5;
// Minimum number of votes required to be in the list
if(!isset($params['minvote'])) $params['minvote'] = 5;
// START DISPLAY:
echo $params['block_start'];
echo $params['title'];
// Stuff goes here
$sql = "SELECT DISTINCT post_ID , post_urltitle ,
total_value / total_votes AS rating, total_votes
FROM ( T_posts , ".$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_posts.post_ID
AND total_votes >= ".$params['minvote']."
ORDER BY `rating` DESC
LIMIT ".$params['limit'];
$results = $DB->get_results($sql);
echo $params['list_start'];
for ($i = 0; $i < $params['limit']; $i++) {
// Stop the loop if you get to a post with 0 comments
if ($results[$i]->rating == 0) break;
// Create a new 1 post itemlist for each result (for access to permalinks)
$list = new ItemList($blog, array(), '', '', -1, '', array(),
'', 'DESC', '', 1, '', '', '' ,'', '', '', '', '', '', 'now',
$results[$i]->post_urltitle);
while ($rated_item = $list->get_item()) {
echo $params['line_start'];
echo "<a href=\"", $rated_item->permanent_url();
echo "\">", $rated_item->title('','',false), "</a> ";
}
echo $params['before_rating'].number_format($results[$i]->rating, 1).$params['after_rating']." <span class='notes'>".$results[$i]->total_votes." votes</span>";
echo $params['line_end'];
}
echo $params['list_end'];
echo $params['block_end'];
} else {
// 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="'.$params['id'].'"');
$tense = ($r->total_votes == 1) ? "vote" : "votes";
?>
<div id="unit_long<?php echo $Item->ID ?>">
<ul class="unit-rating">
<li class='current-rating' style="width:<?php echo @number_format($r->total_value / $r->total_votes , 2 ) * $this->width; ?>px;">Currently <?php echo @number_format($r->total_value / $r->total_votes , 2 ); ?>/<?php echo $outof ?></li>
<?php
for ($ncount = 1; $ncount <= $outof; $ncount++) { ?>
<?php
// AJAX url:
$hturl = $this->get_htsrv_url('vote', array('vote' => $ncount, 'ip' => $ip, 'id' => $Item->ID, 'blog' => $blog ) );
// Url for non-JS browsers
$hturlnojs = $this->get_htsrv_url('vote', array('vote' => $ncount, 'ip' => $ip, 'id' => $Item->ID, 'returnto' => $ReqAbsUrl, 'blog' => $blog ) );
?>
<li><a href="<?php echo $hturlnojs ?>" title="<?php echo $ncount ?> out of <?php echo $outof ?>" class="r<?php echo $ncount ?>-unit" onclick="javascript:sndReq('<?php echo $Item->ID ?>', '<?php echo $hturl ?>');return false"><?php echo $ncount ?></a></li>
<? }
$ncount=0; // resets the count
?>
<?php
if ($this->Settings->get('popup')) {
print "<a href='javascript:void(0);' onClick=\"disp_notice('<p class=\'ratingNotes\'>Rating: <strong> ".@number_format($r->total_value / $r->total_votes, 1)."</strong> out of $r->total_votes $tense cast</p>'); return false;\" class='starinfo'><span>i</span></a>";
} ?>
</ul>
<?php
if ($this->Settings->get('inline')) { ?>
<p class="ratingNotes">Rating: <strong> <?php echo @number_format($r->total_value / $r->total_votes, 1) ?></strong> out of <?php echo $r->total_votes ?> <?php echo $tense ?> cast </p>
<?php } ?>
</div>
<?php
return true;
}
}
// Set the plugin up to take AJAX calls
function GetHtsrvMethods()
{
return array( 'vote' );
}
function htsrv_vote( & $params )
{
global $DB;
$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="'.$params['id'].'"');
$checkIP = unserialize($r->used_ips);
$count = $r->total_votes;
$current_rating = $r->total_value;
$sum = $params['vote'] + $current_rating;
$tense = ($count == 1) ? "vote" : "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 '%".$ip_num."%' AND id='$id_sent' ");
}
// the above pattern match ip:suggested by Bramus! //http://www.bram.us/
if($voted){
$new_back =
"<ul class=\"unit-rating\">\n".
"<li class=\"current-rating\" style=\"width:". @number_format($current_rating/$count,2) * $this->width ."px;\">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 .= "<a href='javascript:void(0);' onClick=\"disp_notice('<p class=\'ratingNotes\'>Rating: <strong> ".@number_format($r->total_value / $r->total_votes, 1)."</strong> out of $r->total_votes $tense cast</p>'); return false;\" class='starinfo'><span>i</span></a>";
}
$new_back .= "</ul>";
$notice = "<p class=\"ratingNotes\">Rating: <strong>".@number_format($current_rating/$count,1)."</strong> out of ".$count." ".$tense." cast".
"<br />\n <span class='error'>You have previously voted!</span></p>";//show the current value of the vote with the current numbers
//if not, echo the new changes
}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=$id_sent ");
if($idexists==true) {
$DB->query("UPDATE $tableName SET total_votes='".$added."', total_value='".$sum."', used_ips='".$insert."', blog_id='".$blog."' WHERE id='$id_sent'");
} else {
$DB->query("INSERT INTO $tableName VALUES ('$id_sent', '".$added."','".$sum."', '".$insert."', '$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='$id_sent' ")or die(" Error: ".mysql_error());
$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;\">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 .= "<a href='javascript:void(0);' onClick=\"disp_notice('<p class=\'ratingNotes\'>Rating: <strong> ".@number_format($r->total_value / $r->total_votes, 1)."</strong> out of $r->total_votes $tense cast</p>'); return false;\" class='starinfo'><span>i</span></a>";
}
$new_back .= "</ul>";
$tense = ($count == 1) ? "vote" : "votes";
$notice = "<p class=\"ratingNotes\">Rating: <strong>".@number_format($sum/$added,1)."</strong> out of ".$added." ".$tense." cast".
"<br /><span class='success'>Thank you for your vote!</span></p></div>";//show the updated value of the vote
}
// 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;
}
}
}
?>
Thanks,
Jim
Try changing this line :-
$checkIP = unserialize($r->used_ips);
to :
$checkIP = (empty( $r->used_ips) ? NULL : unserialize($r->used_ips) );
¥
Thanks! that did the trick on the 2nd error after voting. Although it still goes to a new page.
Still have the side box error refering to line 117.
Progress has been made.
Thanks,
Jim
I installed the plugin but instead of getting 5 stars I get 5 numbers...
Apparently I have done something wrong. Here is where I put the code:
</head>
<body>
<?php $Plugins->call_by_code( 'starrating', array('display' => 'notice' ) ); ?>
<div class="bSmallPrint">
<a href="<?php $Item->permanent_url() ?>" title="<?php echo T_('Permanent link to full entry') ?>" class="permalink_right"><img src="img/chain_link.gif" alt="<?php echo T_('Permalink') ?>" width="22" height="22" border="0" class="middle" /></a>
<?php $Item->feedback_link( 'comments', ' • ' ) // Link to comments ?>
<?php $Item->feedback_link( 'trackbacks', ' • ' ) // Link to trackbacks ?>
<?php $Item->feedback_link( 'pingbacks', ' • ' ) // Link to trackbacks ?>
<?php $Item->edit_link( ' • ' ) // Link to backoffice for editing ?>
<?php $Item->trackback_rdf() // trackback autodiscovery information ?>
<?php $Plugins->call_by_code( 'starrating', array('id' => $Item->ID ) ); ?>
</div>
Thoughts?
W. Hill
Btw --- the site is www.theparchment.org -- the post about New Years 2007 has the plugin enabled so you can see what I am getting as a result.
I'm guessing that you haven't fully upgraded your skin. In particular you appear to be missing the hooks that plugins use in the <head> section :-
<head>
<?php skin_content_meta(); /* Charset for static pages */ ?>
<?php $Plugins->trigger_event( 'SkinBeginHtmlHead' ); ?>
¥
ok -- do I add that code and to what file? My skin is Crystal Glass..
You need to add it to _main.php
¥
gbailey,
I'm actually just finishing up a plugin that does exactly that. It uses AJAX to send the vote, which is stored in the database. The voter's IP is checked to make sure it's not a duplicate vote. It also works when the reader has javascript turned off. The plugin is for b2evolution 1.8, which is still in development, but I'm using a cvs snapshot on my site. If you want to go ahead and upgrade, I can tell you how to get the plugin. You can see a demo [url=http://brendoman.com/dev/180-alpha/]here[/url]