You are here

function _photos_vote_comment in Album Photos 6.2

1 call to _photos_vote_comment()
photos_image_page in inc/photos.image.inc

File

inc/photos.image.inc, line 119

Code

function _photos_vote_comment($fid, $com_count, $nid) {
  global $user;
  if (!$com_count) {
    return false;
  }
  $output = '';
  if (module_exists('comment') && user_access('access comments')) {
    $node->type = 'photos';
    $node->nid = $nid;
    $mode = _comment_get_display_setting('mode', $node);
    $order = _comment_get_display_setting('sort', $node);
    $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
    $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid INNER JOIN {x_vote} x ON c.cid = x.cid WHERE x.fid = %d';
    $query_args = array(
      $fid,
    );
    if (!user_access('administer comments')) {
      $query .= ' AND c.status = %d';
      $query_args[] = COMMENT_PUBLISHED;
    }
    if ($order == COMMENT_ORDER_NEWEST_FIRST) {
      if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
        $query .= ' ORDER BY c.cid DESC';
      }
      else {
        $query .= ' ORDER BY c.thread DESC';
      }
    }
    else {
      if ($order == COMMENT_ORDER_OLDEST_FIRST) {
        if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
          $query .= ' ORDER BY c.cid';
        }
        else {
          $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
        }
      }
    }
    $query = db_rewrite_sql($query, 'c', 'cid');
    $result = pager_query($query, $comments_per_page, 0, NULL, $query_args);
    $divs = 0;
    $num_rows = FALSE;
    $comments = '';
    drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css');
    while ($comment = db_fetch_object($result)) {
      $comment = drupal_unpack($comment);
      $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
      $comment->depth = count(explode('.', $comment->thread)) - 1;
      if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
        if ($comment->depth > $divs) {
          $divs++;
          $comments .= '<div class="indented">';
        }
        else {
          while ($comment->depth < $divs) {
            $divs--;
            $comments .= '</div>';
          }
        }
      }
      $links = module_invoke_all('link', 'comment', $comment, 0);
      if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
        $comments .= theme('comment_flat_collapsed', $comment, $node);
      }
      else {
        if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
          $comments .= theme('comment_view', $comment, $node, $links);
        }
        else {
          if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
            $comments .= theme('comment_thread_collapsed', $comment, $node);
          }
          else {
            if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
              $comments .= theme('comment_view', $comment, $node, $links);
            }
          }
        }
      }
      $num_rows = TRUE;
    }
    while ($divs-- > 0) {
      $comments .= '</div>';
    }
    $comment_controls = variable_get('comment_controls_' . $node->type, COMMENT_CONTROLS_HIDDEN);
    if ($num_rows && ($comment_controls == COMMENT_CONTROLS_ABOVE || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {
      $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
    }
    $output .= $comments;
    $output .= theme('pager', NULL, $comments_per_page, 0);
    if ($num_rows && ($comment_controls == COMMENT_CONTROLS_BELOW || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {
      $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
    }
    $output = theme('comment_wrapper', $output, $node);
  }
  return $output;
}