Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Dokładka shortcode do skryptu w Wordpress
Forum PHP.pl > Forum > Gotowe rozwiązania > Systemy portalowe i CMS'y
kedzier11
Panowie pytanie dotyczy shortcode. Mam taki skrypt jak widać przez echo mogę wywoływać tę funkcję i zmienić parametry name, procenty itp. Chciał bym móc to zmieniać przy wykorzystaniu shortcode w wordpressie. Ale nie wiem jak. Czy ktoś pomoże? Dodam iż jestem początkującym programistom więc łopatologicznie proszę biggrin.gif
  1. function pullRating($name,$show5 = true, $showPerc = false, $showVotes = true, $static = NULL){
  2.  
  3. // Check if they have already voted...
  4. $text = '';
  5.  
  6. $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'");
  7. if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$name])){
  8.  
  9.  
  10.  
  11. if($show5 || $showPerc || $showVotes){
  12.  
  13. $text .= '<div class="rated_text">';
  14.  
  15. }
  16.  
  17. if($show5){
  18. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  19. }
  20. if($showPerc){
  21. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  22. }
  23. if($showVotes){
  24. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  25. }
  26.  
  27. if($show5 || $showPerc || $showVotes){
  28.  
  29. $text .= '</div>';
  30.  
  31. }
  32.  
  33.  
  34. return $text.'
  35. <ul class="star-rating2" id="rater_'.$name.'">
  36. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  37. <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
  38. <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
  39. <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
  40. <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
  41. <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
  42. </ul>
  43. <div id="loading_'.$name.'"></div>';
  44.  
  45.  
  46. } else {
  47.  
  48. if($show5 || $showPerc || $showVotes){
  49.  
  50. $text .= '<div class="rated_text">';
  51.  
  52. }
  53. if($show5){
  54. $show5bool = 'true';
  55. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  56. } else {
  57. $show5bool = 'false';
  58. }
  59. if($showPerc){
  60. $showPercbool = 'true';
  61. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  62. } else {
  63. $showPercbool = 'false';
  64. }
  65. if($showVotes){
  66. $showVotesbool = 'true';
  67. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  68. } else {
  69. $showVotesbool = 'false';
  70. }
  71.  
  72. if($show5 || $showPerc || $showVotes){
  73.  
  74. $text .= '</div>';
  75.  
  76. }
  77.  
  78. return $text.'
  79. <ul class="star-rating" id="rater_'.$name.'">
  80. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  81. <li><a onclick="rate(\'1\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
  82. <li><a onclick="rate(\'2\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
  83. <li><a onclick="rate(\'3\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
  84. <li><a onclick="rate(\'4\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
  85. <li><a onclick="rate(\'5\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
  86. </ul>
  87. <div id="loading_'.$name.'"></div>';
  88.  
  89. }
  90. }add_shortcode('rater', 'pullRating');
memory
Dodajesz przed funkcją na początku

  1. add_shortcode('pullRating', 'pullRating');

Nastepnie funkcja
  1. function pullRating($attr){
  2. }


$attr to tablica $attr['name'], $attr['show5'] itd. Wywołujesz tak [pullRating name="bar" sho5 = "true"] itd
kedzier11
Cytat(memory @ 26.03.2014, 12:18:14 ) *
Dodajesz przed funkcją na początku

  1. add_shortcode('pullRating', 'pullRating');

Nastepnie funkcja
  1. function pullRating($attr){
  2. }


$attr to tablica $attr['name'], $attr['show5'] itd. Wywołujesz tak [pullRating name="bar" sho5 = "true"] itd

czyli to co napisałeś mam dodac przed:
  1. function pullRating($name,$show5 = true, $showPerc = false, $showVotes = true, $static = NULL)
zamiast czy po? Sory za głupie pytanie ale już sam nie wiem.
memory
  1.  
  2. add_shortcode('pullRating', 'pullRating');
  3.  
  4. function pullRating($attr){
  5.  
  6. $name = $attr['name'];
  7. $show5 = $attr['show5'];
  8. $showPerc=$attr['showPerc'];
  9. $showVotes=$attr['showVotes'];
  10. $static= $attr['static'];
  11.  
  12.  
  13. $text = '';
  14.  
  15. $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'");
  16. if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$name])){
  17.  
  18.  
  19.  
  20. if($show5 || $showPerc || $showVotes){
  21.  
  22. $text .= '<div class="rated_text">';
  23.  
  24. }
  25.  
  26. if($show5){
  27. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  28. }
  29. if($showPerc){
  30. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  31. }
  32. if($showVotes){
  33. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  34. }
  35.  
  36. if($show5 || $showPerc || $showVotes){
  37.  
  38. $text .= '</div>';
  39.  
  40. }
  41.  
  42.  
  43. return $text.'
  44. <ul class="star-rating2" id="rater_'.$name.'">
  45. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  46. <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
  47. <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
  48. <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
  49. <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
  50. <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
  51. </ul>
  52. <div id="loading_'.$name.'"></div>';
  53.  
  54.  
  55. } else {
  56.  
  57. if($show5 || $showPerc || $showVotes){
  58.  
  59. $text .= '<div class="rated_text">';
  60.  
  61. }
  62. if($show5){
  63. $show5bool = 'true';
  64. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  65. } else {
  66. $show5bool = 'false';
  67. }
  68. if($showPerc){
  69. $showPercbool = 'true';
  70. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  71. } else {
  72. $showPercbool = 'false';
  73. }
  74. if($showVotes){
  75. $showVotesbool = 'true';
  76. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  77. } else {
  78. $showVotesbool = 'false';
  79. }
  80.  
  81. if($show5 || $showPerc || $showVotes){
  82.  
  83. $text .= '</div>';
  84.  
  85. }
  86.  
  87. return $text.'
  88. <ul class="star-rating" id="rater_'.$name.'">
  89. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  90. <li><a onclick="rate(\'1\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
  91. <li><a onclick="rate(\'2\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
  92. <li><a onclick="rate(\'3\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
  93. <li><a onclick="rate(\'4\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
  94. <li><a onclick="rate(\'5\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
  95. </ul>
  96. <div id="loading_'.$name.'"></div>';
  97.  
  98. }
  99. }


Zamiast
kedzier11
ok działa. To jeszcze ostatnie pytanie. Jak zrobić aby cały ten skrypt działał:
  1. <?
  2.  
  3.  
  4. function getRating($name){
  5.  
  6.  
  7. $total = 0;
  8. $rows = 0;
  9.  
  10. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  11. if(mysql_num_rows($sel) > 0){
  12.  
  13. while($data = mysql_fetch_assoc($sel)){
  14.  
  15. $total = $total + $data['rating_num'];
  16. $rows++;
  17. }
  18.  
  19. $perc = ($total/$rows) * 20;
  20.  
  21. //$newPerc = round($perc/5)*5;
  22. //return $newPerc.'%';
  23.  
  24. $newPerc = round($perc,2);
  25. return $newPerc.'%';
  26.  
  27. } else {
  28.  
  29. return '0%';
  30.  
  31. }
  32. }
  33.  
  34. function outOfFive($name){
  35. $name = $_SERVER['REQUEST_URI'];
  36. $total = 0;
  37. $rows = 0;
  38.  
  39. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  40. if(mysql_num_rows($sel) > 0){
  41.  
  42. while($data = mysql_fetch_assoc($sel)){
  43.  
  44. $total = $total + $data['rating_num'];
  45. $rows++;
  46. }
  47.  
  48. $perc = ($total/$rows);
  49.  
  50. return round($perc,2);
  51. //return round(($perc*2), 0)/2; // 3.5
  52.  
  53. } else {
  54.  
  55. return '0';
  56.  
  57. }
  58.  
  59.  
  60. }
  61.  
  62. function getVotes($name){
  63. $name = $_SERVER['REQUEST_URI'];
  64. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  65. $rows = mysql_num_rows($sel);
  66. if($rows == 0){
  67. $votes = '0 Votes';
  68. }
  69. else if($rows == 1){
  70. $votes = '1 Vote';
  71. } else {
  72. $votes = $rows.' Votes';
  73. }
  74. return $votes;
  75.  
  76. }
  77.  
  78.  
  79. add_shortcode('rater', 'pullRating');
  80.  
  81. function pullRating($attr){
  82.  
  83. $name = $attr['name'];
  84. $show5 = $attr['show5'];
  85. $showPerc=$attr['showPerc'];
  86. $showVotes=$attr['showVotes'];
  87. $static= $attr['static'];
  88.  
  89.  
  90. // Check if they have already voted...
  91. $text = '';
  92.  
  93. $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'");
  94. if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$name])){
  95.  
  96.  
  97.  
  98. if($show5 || $showPerc || $showVotes){
  99.  
  100. $text .= '<div class="rated_text">';
  101.  
  102. }
  103.  
  104. if($show5){
  105. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  106. }
  107. if($showPerc){
  108. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  109. }
  110. if($showVotes){
  111. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  112. }
  113.  
  114. if($show5 || $showPerc || $showVotes){
  115.  
  116. $text .= '</div>';
  117.  
  118. }
  119.  
  120.  
  121. return $text.'
  122. <ul class="star-rating2" id="rater_'.$name.'">
  123. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  124. <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
  125. <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
  126. <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
  127. <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
  128. <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
  129. </ul>
  130. <div id="loading_'.$name.'"></div>';
  131.  
  132.  
  133. } else {
  134.  
  135. if($show5 || $showPerc || $showVotes){
  136.  
  137. $text .= '<div class="rated_text">';
  138.  
  139. }
  140. if($show5){
  141. $show5bool = 'true';
  142. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  143. } else {
  144. $show5bool = 'false';
  145. }
  146. if($showPerc){
  147. $showPercbool = 'true';
  148. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  149. } else {
  150. $showPercbool = 'false';
  151. }
  152. if($showVotes){
  153. $showVotesbool = 'true';
  154. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  155. } else {
  156. $showVotesbool = 'false';
  157. }
  158.  
  159. if($show5 || $showPerc || $showVotes){
  160.  
  161. $text .= '</div>';
  162.  
  163. }
  164.  
  165. return $text.'
  166. <ul class="star-rating" id="rater_'.$name.'">
  167. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  168. <li><a onclick="rate(\'1\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
  169. <li><a onclick="rate(\'2\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
  170. <li><a onclick="rate(\'3\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
  171. <li><a onclick="rate(\'4\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
  172. <li><a onclick="rate(\'5\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
  173. </ul>
  174. <div id="loading_'.$name.'"></div>';
  175.  
  176. }
  177. }
  178.  
  179. // Added in version 1.5
  180. // Fixed sort in version 1.7
  181. function getTopRated($limit, $table, $namefield, $namefield){
  182. $name = $_SERVER['REQUEST_URI'];
  183. $result = '';
  184.  
  185. $sql = "SELECT COUNT(ratings.id) as rates,ratings.rating_id,".$table.".".$namefield." as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating
  186. FROM ratings,".$table." WHERE ".$table.".".$namefield." = ratings.rating_id GROUP BY rating_id
  187. ORDER BY rates DESC,rating DESC LIMIT ".$limit."";
  188.  
  189. $sel = mysql_query($sql);
  190.  
  191. $result .= '<ul class="topRatedList">'."\n";
  192.  
  193. while($data = @mysql_fetch_assoc($sel)){
  194. $result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n";
  195. }
  196.  
  197. $result .= '</ul>'."\n";
  198.  
  199. return $result;
  200.  
  201. }
  202. ?>
a no i od razu na pw. adres gdzie wysłać flachę ^^
memory
  1. <?
  2.  
  3. add_shortcode('rater', 'pullRating');
  4.  
  5. function pullRating($attr){
  6.  
  7. $name = $attr['name'];
  8. $show5 = $attr['show5'];
  9. $showPerc=$attr['showPerc'];
  10. $showVotes=$attr['showVotes'];
  11. $static= $attr['static'];
  12.  
  13.  
  14. // Check if they have already voted...
  15. $text = '';
  16.  
  17. $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'");
  18. if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$name])){
  19.  
  20.  
  21.  
  22. if($show5 || $showPerc || $showVotes){
  23.  
  24. $text .= '<div class="rated_text">';
  25.  
  26. }
  27.  
  28. if($show5){
  29. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  30. }
  31. if($showPerc){
  32. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  33. }
  34. if($showVotes){
  35. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  36. }
  37.  
  38. if($show5 || $showPerc || $showVotes){
  39.  
  40. $text .= '</div>';
  41.  
  42. }
  43.  
  44.  
  45. return $text.'
  46. <ul class="star-rating2" id="rater_'.$name.'">
  47. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  48. <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
  49. <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
  50. <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
  51. <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
  52. <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
  53. </ul>
  54. <div id="loading_'.$name.'"></div>';
  55.  
  56.  
  57. } else {
  58.  
  59. if($show5 || $showPerc || $showVotes){
  60.  
  61. $text .= '<div class="rated_text">';
  62.  
  63. }
  64. if($show5){
  65. $show5bool = 'true';
  66. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  67. } else {
  68. $show5bool = 'false';
  69. }
  70. if($showPerc){
  71. $showPercbool = 'true';
  72. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  73. } else {
  74. $showPercbool = 'false';
  75. }
  76. if($showVotes){
  77. $showVotesbool = 'true';
  78. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  79. } else {
  80. $showVotesbool = 'false';
  81. }
  82.  
  83. if($show5 || $showPerc || $showVotes){
  84.  
  85. $text .= '</div>';
  86.  
  87. }
  88.  
  89. return $text.'
  90. <ul class="star-rating" id="rater_'.$name.'">
  91. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  92. <li><a onclick="rate(\'1\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
  93. <li><a onclick="rate(\'2\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
  94. <li><a onclick="rate(\'3\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
  95. <li><a onclick="rate(\'4\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
  96. <li><a onclick="rate(\'5\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
  97. </ul>
  98. <div id="loading_'.$name.'"></div>';
  99.  
  100. }
  101. }
  102.  
  103. function getRating($name){
  104.  
  105.  
  106. $total = 0;
  107. $rows = 0;
  108.  
  109. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  110. if(mysql_num_rows($sel) > 0){
  111.  
  112. while($data = mysql_fetch_assoc($sel)){
  113.  
  114. $total = $total + $data['rating_num'];
  115. $rows++;
  116. }
  117.  
  118. $perc = ($total/$rows) * 20;
  119.  
  120. //$newPerc = round($perc/5)*5;
  121. //return $newPerc.'%';
  122.  
  123. $newPerc = round($perc,2);
  124. return $newPerc.'%';
  125.  
  126. } else {
  127.  
  128. return '0%';
  129.  
  130. }
  131. }
  132.  
  133. function outOfFive($name){
  134. $name = $_SERVER['REQUEST_URI'];
  135. $total = 0;
  136. $rows = 0;
  137.  
  138. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  139. if(mysql_num_rows($sel) > 0){
  140.  
  141. while($data = mysql_fetch_assoc($sel)){
  142.  
  143. $total = $total + $data['rating_num'];
  144. $rows++;
  145. }
  146.  
  147. $perc = ($total/$rows);
  148.  
  149. return round($perc,2);
  150. //return round(($perc*2), 0)/2; // 3.5
  151.  
  152. } else {
  153.  
  154. return '0';
  155.  
  156. }
  157.  
  158.  
  159. }
  160.  
  161. function getVotes($name){
  162. $name = $_SERVER['REQUEST_URI'];
  163. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  164. $rows = mysql_num_rows($sel);
  165. if($rows == 0){
  166. $votes = '0 Votes';
  167. }
  168. else if($rows == 1){
  169. $votes = '1 Vote';
  170. } else {
  171. $votes = $rows.' Votes';
  172. }
  173. return $votes;
  174.  
  175. }
  176.  
  177.  
  178.  
  179. // Added in version 1.5
  180. // Fixed sort in version 1.7
  181. function getTopRated($limit, $table, $namefield, $namefield){
  182. $name = $_SERVER['REQUEST_URI'];
  183. $result = '';
  184.  
  185. $sql = "SELECT COUNT(ratings.id) as rates,ratings.rating_id,".$table.".".$namefield." as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating
  186. FROM ratings,".$table." WHERE ".$table.".".$namefield." = ratings.rating_id GROUP BY rating_id
  187. ORDER BY rates DESC,rating DESC LIMIT ".$limit."";
  188.  
  189. $sel = mysql_query($sql);
  190.  
  191. $result .= '<ul class="topRatedList">'."\n";
  192.  
  193. while($data = @mysql_fetch_assoc($sel)){
  194. $result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n";
  195. }
  196.  
  197. $result .= '</ul>'."\n";
  198.  
  199. return $result;
  200.  
  201. }
  202. ?>
? co nie działa ?
kedzier11
już sam nie wiem. Generalnie wszystko działa zobacz sam: moje111.nazwa.pl ale nie zapisuje wyników. Może problem z bazą?
@jeżeli dodam do bazy wynik ręcznie to czyta. Ale jak widać nie zapisuje do bazy wyników...
memory
Usuń z rating_update.js i pokaż plik rating_process.
  1. xmlHttp.setRequestHeader("Content-length", params.length);
  2. xmlHttp.setRequestHeader("Connection", "close");


Ogólnie na wordpress jest masa pluginów gotowych np
https://wordpress.org/plugins/universal-sta...ng/screenshots/

kedzier11
Skasowałem z pliku js ten kawałek. Dodam jeszcze że WP musi coś blokować bo przy zwykłym pliku php all działa:http://moje111.nazwa.pl/pull-rating/example.php. Tu masz plik rating_process:
  1. <?
  2.  
  3. header("Cache-Control: no-cache");
  4. header("Pragma: nocache");
  5.  
  6. include("rating_config.php");
  7. // Cookie settings
  8. $expire = time() + 99999999;
  9. $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
  10.  
  11. // escape variables
  12. function escape($val){
  13.  
  14. $val = trim($val);
  15.  
  16. $val = stripslashes($val);
  17. }
  18.  
  19.  
  20. }
  21.  
  22. // IF JAVASCRIPT IS ENABLED
  23.  
  24. if($_POST){
  25.  
  26.  
  27. $name = escape($_POST['id']);
  28. $rating = (int) $_POST['rating'];
  29.  
  30. if($rating <= 5 && $rating >= 1){
  31.  
  32. if(@mysql_fetch_assoc(mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'")) || isset($_COOKIE['has_voted_'.$name])){
  33.  
  34. echo 'already_voted';
  35.  
  36. } else {
  37.  
  38.  
  39. setcookie('has_voted_'.$name,$name,$expire,'/',$domain,false);
  40. mysql_query("INSERT INTO ratings (rating_id,rating_num,IP) VALUES ('$name','$rating','".$_SERVER['REMOTE_ADDR']."')") or die(mysql_error());
  41.  
  42. $total = 0;
  43. $rows = 0;
  44.  
  45. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  46. while($data = mysql_fetch_assoc($sel)){
  47.  
  48. $total = $total + $data['rating_num'];
  49. $rows++;
  50. }
  51.  
  52. $perc = ($total/$rows) * 20;
  53.  
  54. echo round($perc,2);
  55. //echo round($perc/5)*5;
  56.  
  57. }
  58.  
  59. }
  60.  
  61. }
  62.  
  63. // IF JAVASCRIPT IS DISABLED
  64.  
  65. if($_GET){
  66.  
  67. $name = escape($_GET['id']);
  68. $rating = (int) $_GET['rating'];
  69.  
  70. // If you want people to be able to vote more than once, comment the entire if/else block block and uncomment the code below it.
  71.  
  72. if($rating <= 5 && $rating >= 1){
  73.  
  74. if(@mysql_fetch_assoc(mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'")) || isset($_COOKIE['has_voted_'.$name])){
  75.  
  76. echo 'already_voted';
  77.  
  78. } else {
  79.  
  80. setcookie('has_voted_'.$name,$name,$expire,'/',$domain,false);
  81. mysql_query("INSERT INTO ratings (rating_id,rating_num,IP) VALUES ('$name','$rating','".$_SERVER['REMOTE_ADDR']."')") or die(mysql_error());
  82.  
  83. }
  84.  
  85. header("Location:".$_SERVER['HTTP_REFERER']."");
  86. die;
  87.  
  88. }
  89. else {
  90.  
  91. echo 'You cannot rate this more than 5 or less than 1 <a href="'.$_SERVER['HTTP_REFERER'].'">back</a>';
  92.  
  93. }
  94.  
  95.  
  96.  
  97. }
  98.  
  99. ?>
A co do pluginu wiem że jest ich dużo natomiast żaden nie oferuje kilku ratingów w jednym poście.
memory
Nie masz pliku includes/rating_process.php musisz podać dokładną ścieżke tam gdzie go masz, czyli wp-content/plugins/pull-rating/includes/rating_process.php w pliku rating_update var url = "includes/rating_process.php";
kedzier11
Dzięki wielkie! Działa! Jupikajej biggrin.gif To gdzie tę flachę wysłać?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.