Guest User

Untitled

a guest
Mar 26th, 2012
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.94 KB | None | 0 0
  1. <?php
  2. /*
  3.     Plugin Name: Test Review Plugin
  4.     Plugin URI: http://www.site.com/
  5.     Description: ASGSOFTS Test Review Plugin
  6.     Version: 1.0
  7.     Author: ASGSOFT
  8.     Author URI: http://www.site.com/
  9.     License: GPL2
  10.  
  11.     Copyright 2012 ASGSOFT  (email: [email protected])
  12.  
  13.     This program is free software; you can redistribute it and/or modify
  14.     it under the terms of the GNU General Public License, version 2, as
  15.     published by the Free Software Foundation.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software
  24.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  25. */
  26. function calculate_average($arr) {
  27.     $count = count($arr); //total numbers in array
  28.     foreach ($arr as $value) {
  29.         $total = $total + $value; // total value of array numbers
  30.     }
  31.     $average = ($total/$count); // get average value
  32.     return $average;
  33. }
  34.  
  35. function show_review_shortcode($atts) {
  36.    extract(shortcode_atts(array("id" => ''), $atts));
  37.  
  38.         $user = "root";
  39.         $pass = "";
  40.         $host = "localhost";
  41.         $dbname = "sjadmin";
  42.         mysql_connect("$host", "$user", "$pass") or die(mysql_error());
  43.         mysql_select_db("$dbname") or die(mysql_error());
  44.         $result = mysql_query("SELECT * FROM `reviews` WHERE `id` = $id");
  45.                 if (!$rec = @mysql_fetch_array($result)){
  46.                     echo("Invalid Review.<br />");
  47.                 }else{
  48.                     $brand = $rec['brand'];
  49.                     $name = $rec['name'];
  50.                     $eff = $rec['eff'];
  51.                     $val = $rec['val'];
  52.                     $ov = $rec['ov'];
  53.                     $pro1 = $rec['pro1'];
  54.                     $pro2 = $rec['pro2'];
  55.                     $pro3 = $rec['pro3'];
  56.                     $con1 = $rec['con1'];
  57.                     $con2 = $rec['con2'];
  58.                     $con3 = $rec['con3'];
  59.                     $review = $rec['review'];
  60.                     $reviewer_name = $rec['reviewer_name'];
  61.                     $reviewer_email = $rec['email'];
  62.                     $site = $rec['site'];
  63.  
  64. ?>
  65. <p><strong><?php echo $brand; ?> <?php echo $name; ?> Review<br /></strong></p>
  66. <table width="500" border="1" cellspacing="0" cellpadding="0">
  67.   <tbody>
  68.     <tr>
  69.       <td width="50%" height="116"><p><strong>Ratings:</strong><strong> </strong></p>
  70.         <strong>Taste</strong>: [Rating:<?php echo $ov; ?>/5]<br />
  71.           <strong>Effectiveness</strong>: [Rating:<?php echo $eff; ?>/5]<br />
  72.           <strong>Value</strong>: [Rating:<?php echo $val; ?>/5]<br />
  73.           <?php
  74.                 $overall_array = array($ov,$eff,$val);
  75.                 $overall_value = calculate_average($overall_array);
  76.                 $overall_value_formatted = number_format($overall_value, 2, '.', '');
  77.             ?>
  78.           <strong>Overall</strong>: [Rating:<?php echo $overall_value_formatted ?>/5]
  79.         </td>
  80.       <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>
  81.     </tr>
  82.   </tbody>
  83. </table>
  84. <p><strong>Summary</strong></p>
  85. <table width="500" border="1" cellspacing="0" cellpadding="0">
  86.     <tbody>
  87.         <tr>
  88.         <td width="50%"><strong>Pros</strong></p>
  89.             <ul>
  90.                 <li><?php echo $pro1; ?></li>
  91.                 <li><?php echo $pro2; ?></li>
  92.                 <li><?php echo $pro3; ?></li>
  93.             </ul>
  94.         </td>
  95.         <td width="50%"><strong>Cons</strong></p>
  96.         <ul>
  97.           <li><?php echo $con1; ?></li>
  98.           <li><?php echo $con2; ?></li>
  99.           <li><?php echo $con3; ?></li>
  100.         </ul>
  101.         </td>
  102.         </tr>
  103.     </tbody>
  104. </table>
  105. <p><strong>My Review</strong></p>
  106. <p><?php echo $review; ?></p>
  107. <p><strong>Nutritional Information</strong></p>
  108. <p>Bla</p>
  109. <p><strong>Ingredients</strong></p>
  110. <p>Bla</p>
  111. [toggle title="Serving Info"]Bla[/toggle]
  112. <?php
  113. if (!empty($reviewer_name)){
  114. echo "<p>Reviewed by: $reviewer_name</p>";
  115. }
  116. }
  117. }
  118. add_shortcode('review', 'show_review_shortcode');
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment