<?php
  /**
   * loadComments
   *
   * @package Digital Downloads Pro
   * @author wojoscripts.com
   * @copyright 2010
   * @version $Id: loadComments.php, v2.00 2011-04-20 10:12:05 gewa Exp $
   */
  define("_VALID_PHP", true);
  require_once("../../init.php");
  
  $config = $content->getCommentsConfig();
  
  $page = sanitize($_GET['pg']);
  $page = (int)$page;

  $pid = sanitize($_GET['pid']);
  $pid = (int)$pid;
  

  $start = ($page - 1) * $config['perpage'];
  $limit = $start.','.$config['perpage'];

  $sql = "SELECT *, DATE_FORMAT(created, '" . $config['dateformat'] . "') as cdate" 
  . "\n FROM comments" 
  . "\n WHERE pid = '" . $db->escape($pid) ."'"
  . "\n AND active = '1'" 
  . "\n ORDER BY created " . $config['sorting'] . " LIMIT  ". $limit;
  
  $query = $db->fetch_all($sql);
?>
<ul>
  <?php foreach ($query as $comrow):?>
  <li class="comment" id="comment-<?php echo $comrow['id'];?>">
    <div class="commentWrap" id="wrapper_<?php echo $comrow['id'];?>">
      <div class="img-holder"> <img src="http://www.gravatar.com/avatar/<?php echo md5(strtolower(trim($comrow['email'])));?>?s=65" alt="<?php echo $comrow['username'];?>" class="avatar" /> <a class="reply-link" href="#reply" id="doreplay-<?php echo $comrow['id'];?>">پـاسـخ</a> </div>
      <div class="comment-body">
        <div class="com-box">
          <div class="desc">
            <h4>
              <?php if($config['show_username']):?>
              <?php if($config['show_www'] && $comrow['www']):?>
              <a href="<?php echo $comrow['www'];?>" target="_blank"><?php echo $comrow['username'];?></a>
              <?php else:?>
              <?php echo $comrow['username'];?>
              <?php endif;?>
              <?php endif;?>
              <?php if ($config['show_email']) echo $comrow['email'];?>
            </h4>
            <small>(<?php echo $comrow['cdate'];?>)</small></div>
          <p><?php echo cleanOut($comrow['body']);?></p>
        </div>
      </div>
    </div>
  </li>
  <?php endforeach;?>
  <?php unset($comrow);?>
</ul>