Hello!
First of all ,I have to say this is a very nice and useful snippet!
Second, it has a bug that is pretty annoying . I have traced it down and I will try to explain(I totally suck at explaining stuff
) what it does:
Say you have a ditto listing with 10 article summarys on a page , and after each summary you have:
[!star_rating? &docID=`[+id+]` &onevote=`true`!] (included in the ditto chunk of course).You want your users to vote only once,based on the cookie option ($onevote).When you vote on an article, the only star rating that gets disabled ,is the first one on the page.
I click the star and the
variable gets set . On the page that now loads the snippets begin to be processed. The first one on the page does
setcookie('cssStarRating' . $docID, 'novote', time() + $ovtime);
and is thus disabling it’s own article that should be voted , not the one we chose to vote ! ( the ID of that article is transmitted with the help of $pid if I’m not mistaken).Further on , the snippet processes it’s data, and does: unset ($_GET); . After this snippet called is finished,there are 9 more to pe processed,and there is no more $_GET data.(thus,no more $_GET[’starvote’] and no more cookies
)
To put it short , the cookie is set for the wrong document ID , it sets the current docID from the snippets call as read , instead of the voted one (as those the useSession option).
I would have tried to hack the script myself, but as I am pretty much a newbie in PHP ( woot,this was actually the first php script I ever debugged
) it wouldn’t have been a very good idea.
And third, I have a feature request (well, actually more of a change of behaviour).
After you have voted let’s say hmm... 5 out 10 article summarys that have the star_rating attached ,and disable repeated voting , half your page will have the "You may only vote once" , even if you haven’t had the intention of voting the same article summary again. (maybe this appears only in a certain situation e.g.: when the useSession , onevote paramaters gets used on at a time , or both at once - haven’t checked witch case ...
).
Thus , a say that a better aproach would that of activating $viewOnly for the articles voted instead of displaying the text. I tried to hack the script, but the code is messy and redundant:
if($novote) {
$starPhArray['starRating'] = "<ul class='star-rating'>
<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
<li class='one-star'>1</li>
<li class='two-stars'>2</li>
<li class='three-stars'>3</li>
<li class='four-stars'>4</li>
<li class='five-stars'>5</li>
</ul>";
}
else
{
if (!$viewOnly) {
$starPhArray['starRating'] = "<ul class='star-rating'>
<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=1&pid=' . $docID) . "' title='" . $_lang['one_star'] . "' class='one-star'>1</a></li>
<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=2&pid=' . $docID) . "' title='" . $_lang['two_stars'] . "' class='two-stars'>2</a></li>
<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=3&pid=' . $docID) . "' title='" . $_lang['three_stars'] . "' class='three-stars'>3</a></li>
<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=4&pid=' . $docID) . "' title='" . $_lang['four_stars'] . "' class='four-stars'>4</a></li>
<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=5&pid=' . $docID) . "' title='" . $_lang['five_stars'] . "' class='five-stars'>5</a></li>
</ul>";
} else {
$starPhArray['starRating'] = "<ul class='star-rating'>
<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
<li class='one-star'>1</li>
<li class='two-stars'>2</li>
<li class='three-stars'>3</li>
<li class='four-stars'>4</li>
<li class='five-stars'>5</li>
</ul>";
}
}
$starPhArray['totalVotes'] = $totalVotes;
foreach ($starPhArray as $n => $v) {
$starTpl = str_replace('[+' . $n . '+]', $v, $starTpl);
}
$output .= $starTpl;
Looking forward for some feedback ,I hope that what I wrote makes sense
.