functions.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class postRating
  3. {
  4. // rateIt(): Affiche si nécessaire le formulaire
  5. function rateIt($ret='<form action ="" method="POST"><select name="ri_value"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select><input type="submit" value="Valider"><input type="hidden" name="ri_id" value="%s"></form>')
  6. {
  7. global $con;
  8. $rs = $con->select('SELECT rate_ip FROM '.DB_PREFIX.'rate WHERE rate_post_id='.$GLOBALS['news']->f('post_id').' AND rate_ip=\''.$_SERVER["REMOTE_ADDR"].'\'','recordset', false);
  9. // Sinon, s'il n'a jamais voté on affiche le formulaire
  10. if ($rs->isEmpty())
  11. {
  12. printf($ret, $GLOBALS['news']->f('post_id'));
  13. }
  14. }
  15. // getRate(): Renvois la note moyenne du billet
  16. function getRate($ret='Rating for this post: %s(%s)')
  17. {
  18. global $con;
  19. $rs = $con->select('SELECT rate_value FROM '.DB_PREFIX.'rate WHERE rate_post_id='.$GLOBALS['news']->f('post_id'),'recordset', false);
  20. if ($rs->isEmpty())
  21. {
  22. printf($ret,0,0);
  23. }else{
  24. $tot=0;
  25. while ($rs->fetch())
  26. $tot += $rs->f('rate_value');
  27. printf($ret, round(($tot / $rs->int_row_count), 2), $rs->int_row_count);
  28. }
  29. }
  30. function checkNewVersion($current, $check)
  31. {
  32. $current = explode('.',$current);
  33. $check = explode('.',$check);
  34. if( $check[0] > $current[0] )
  35. {
  36. return true;
  37. }elseif(( $check[0] == $current[0] ) && ( $check[1] > $current[1] )){
  38. return true;
  39. }else{
  40. return false;
  41. }
  42. }
  43. }
  44. ?>