Guest User

Custom WP review plugin

a guest
May 25th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1. <?php
  2.  
  3. function calculate_average($arr) {
  4.     $count = count($arr); //total numbers in array
  5.     foreach ($arr as $value) {
  6.         $total = $total + $value; // total value of array numbers
  7.     }
  8.     $average = ($total/$count); // get average value
  9.     return $average;
  10. }
  11.  
  12. function show_review_shortcode($atts) {
  13.    extract(shortcode_atts(array("id" => ''), $atts));
  14.  
  15.         $user = "root";
  16.         $pass = "";
  17.         $host = "localhost";
  18.         $dbname = "dbname";
  19.         mysql_connect("$host", "$user", "$pass") or die(mysql_error());
  20.         mysql_select_db("$dbname") or die(mysql_error());
  21.         $result = mysql_query("SELECT * FROM `reviews` WHERE `id` = $id");
  22.                 if (!$rec = @mysql_fetch_array($result)){
  23.                     echo("Invalid Review.<br />");
  24.                 }else{
  25.                     $brand = $rec['brand'];
  26.                     $name = $rec['name'];
  27.                     $eff = $rec['eff'];
  28.                     $val = $rec['val'];
  29.                     $ov = $rec['ov'];
  30.                     $pro1 = $rec['pro1'];
  31.                     $pro2 = $rec['pro2'];
  32.                     $pro3 = $rec['pro3'];
  33.                     $con1 = $rec['con1'];
  34.                     $con2 = $rec['con2'];
  35.                     $con3 = $rec['con3'];
  36.                     $review = $rec['review'];
  37.                     $reviewer_name = $rec['reviewer_name'];
  38.                     $reviewer_email = $rec['email'];
  39.                     $site = $rec['site'];
  40.  
  41. ?>
  42. <p><strong><?php echo $brand; ?> <?php echo $name; ?> Review<br /></strong></p>
  43. <table width="500" border="1" cellspacing="0" cellpadding="0">
  44.   <tbody>
  45.     <tr>
  46.       <td width="50%" height="116"><p><strong>Ratings:</strong><strong> </strong></p>
  47.         <strong>Taste [Rating:2/5]</strong>:  [Rating:<?php echo $ov; ?>/5]<br />
  48.           <strong>Effectiveness</strong>: [Rating:<?php echo $eff; ?>/5]<br />
  49.           <strong>Value</strong>: [Rating:<?php echo $val; ?>/5]<br />
  50.           <?php
  51.                 $overall_array = array($ov,$eff,$val);
  52.                 $overall_value = calculate_average($overall_array);
  53.                 $overall_value_formatted = number_format($overall_value, 2, '.', '');
  54.             ?>
  55.           <strong>Overall</strong>: [Rating:<?php echo $overall_value_formatted ?>/5]
  56.         </td>
  57.       <td width="50%"><div align="center"><strong> <a href="http://supplementjudge.net/out.php?id="><img src="http://www.supplementjudge.net/buy.png" width="180" height="71" border="0"></a></strong></div></td>
  58.     </tr>
  59.   </tbody>
  60. </table>
  61. <p><strong>Summary</strong></p>
  62. <table width="500" border="1" cellspacing="0" cellpadding="0">
  63.     <tbody>
  64.         <tr>
  65.         <td width="50%"><strong>Pros</strong></p>
  66.             <ul>
  67.                 <li><?php echo $pro1; ?></li>
  68.                 <li><?php echo $pro2; ?></li>
  69.                 <li><?php echo $pro3; ?></li>
  70.             </ul>
  71.         </td>
  72.         <td width="50%"><strong>Cons</strong></p>
  73.         <ul>
  74.           <li><?php echo $con1; ?></li>
  75.           <li><?php echo $con2; ?></li>
  76.           <li><?php echo $con3; ?></li>
  77.         </ul>
  78.         </td>
  79.         </tr>
  80.     </tbody>
  81. </table>
  82. <p><strong>My Review</strong></p>
  83. <p><?php echo $review; ?></p>
  84. <p><strong>Nutritional Information</strong></p>
  85. <p>Bla</p>
  86. <p><strong>Ingredients</strong></p>
  87. <p>Bla</p>
  88. [toggle title="Serving Info"]Bla[/toggle]
  89. <?php
  90. if (!empty($reviewer_name)){
  91. echo "<p>Reviewed by: $reviewer_name</p>";
  92. }
  93. }
  94. }
  95. add_shortcode('review', 'show_review_shortcode');
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment