Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dokładka shortcode do skryptu w Wordpress
kedzier11
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 13.01.2014

Ostrzeżenie: (0%)
-----


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ę (IMG:style_emoticons/default/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');


Ten post edytował kedzier11 25.03.2014, 15:54:04
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kedzier11
post
Post #2





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 13.01.2014

Ostrzeżenie: (0%)
-----


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.

Ten post edytował kedzier11 26.03.2014, 18:06:18
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.10.2025 - 10:41