%d of %d found this useful.'); SDV($RatingQuery, 'Was this review helpful to you?'); SDV($RatingDateFmt,'%B %d, %Y %H:%M'); SDV($RatingPermission, 'read'); $RatingAverage = array(); $UsefulVote = array(); Markup('ratingpos', '>inline', '/\(:reviewpos:\)/e', ''); Markup('ratingform', ' $RatingMax) ? $RatingMax : ($r < $RatingMin) ? $RatingMin : $r; $a = (int) ($t / $c); $FmtV['RatingsCount'] = $t; return RatingStars($a); } function RatingStars($r) { global $RatingStarDir, $RatingStar; return ".Attach:".$r."stars.gif"; } function Rating($r) { global $RatingAverage; array_push($RatingAverage, $r); return RatingStars($r); } #(:useful:) replace with (:useful-md5(time):) on first save. $ROSPatterns ["/\(:useful:\)/e"] = "RatingReplaceUseful();"; function RatingReplaceUseful() { return sprintf("(:useful-%s:)", md5(rand(1,99999999))); } function RatingUsefulForm($m, $i) { global $RatingUseful, $RatingUsefulTF, $RatingQuery; global $UsefulVote; $o = ParseArgs($i); $t = ($o['t']) ? $o['t'] : 0; $y = ($o['y']) ? $o['y'] : 0; if ($UsefulVote[$m]) list($t, $y) = RatingUsefulAppend($m, $UsefulVote[$m], $t, $y); $c = sprintf($RatingUseful, $y, $t); $f =<<
FORM; $f = keep($f); return "
$c $RatingQuery $f
"; } function RatingUsefulAppend($m, $k, $t, $y) { global $pagename; global $RatingUsefulTF, $RatingPermission; $y += ($RatingUsefulTF[1] == $k) ? 1 : 0; $t++; $re = "/\(:useful-$m.*?:\)/"; $out = "(:useful-$m t=$t y=$y:)"; RatingReplace($re, $out); } function RatingReplace($r, $o) { global $pagename, $RatingPermission; $page = RetrieveAuthPage($pagename, $RatingPermission, true); if (!$page) Abort('?cannot read $pagename'); $new = $page; $new['text'] = preg_replace($r,$o,$page['text']); PostPage($pagename, $page, $new); Redirect($pagename); } function RatingReviewForm() { global $Author; global $HTMLStylesFmt; $HTMLStylesFmt[] =<<



Type your review here:
FORM; return Keep($f); } function RatingAddReview($r) { global $RatingDateFmt; $stars = substr($r['rating'],0,1); if ($stars == '') $stars = 1; $d = strftime($RatingDateFmt); $a = ($r['author'] != '') ? "\nReviewed by $r[author]\n" : "\n"; $useful = sprintf("(:useful-%s:)", md5(rand(1,99999999))); $out =<<>review<< (:rating-$stars:) \\\ '''$r[title]''', $d $a $r[review] $useful >><< OUTPUT; ltrim($out, "\n"); $re = '/\(:reviewpos:\)/'; RatingReplace($re, $out); } #-------------------------------- # if ($_REQUEST['action']=='addreview') { RatingAddReview($_REQUEST); } if ($_REQUEST['action']=='ratingvote') { $UsefulVote[$_REQUEST['votingid']] = $_REQUEST['vote']; }