You are here

function _photos_comment in Album Photos 7.3

Comments on single picture.

1 call to _photos_comment()
photos_image_page in inc/photos.image.inc
Image page.

File

inc/photos.image.inc, line 258
Handles image page view(s) and content.

Code

function _photos_comment($fid, $com_count, $node) {
  global $user;
  $output = array();
  if (module_exists('comment') && user_access('access comments')) {
    if ($com_count && $node->comment != 0 || user_access('administer comments')) {
      $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
      $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
      $query = db_select('photos_comment', 'v')
        ->extend('PagerDefault');
      $query
        ->join('comment', 'c', 'c.cid = v.cid');
      $query
        ->addField('v', 'cid');
      $query
        ->condition('v.fid', $fid)
        ->addTag('node_access')
        ->addTag('comment_filter')
        ->addMetaData('node', $node)
        ->limit($comments_per_page);
      $count_query = db_select('photos_comment', 'v');
      $count_query
        ->join('comment', 'c', 'c.cid = v.cid');
      $count_query
        ->addExpression('COUNT(*)');
      $count_query
        ->condition('v.fid', $fid)
        ->addTag('node_access')
        ->addTag('comment_filter')
        ->addMetaData('node', $node);
      if (!user_access('administer comments')) {
        $query
          ->condition('c.status', COMMENT_PUBLISHED);
        $count_query
          ->condition('c.status', COMMENT_PUBLISHED);
      }
      if ($mode === COMMENT_MODE_FLAT) {
        $query
          ->orderBy('c.cid', 'ASC');
      }
      else {
        $query
          ->addExpression('SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))', 'torder');
        $query
          ->orderBy('torder', 'ASC');
      }
      $query
        ->setCountQuery($count_query);
      $cids = $query
        ->execute()
        ->fetchCol();
      if (!empty($cids)) {
        $comments = comment_load_multiple($cids);
        comment_prepare_thread($comments);
        $build = comment_view_multiple($comments, $node);
        $build['pager']['#theme'] = 'pager';
        $output['comments'] = $build;
      }
    }
    if ($node->comment == 2) {
      if (user_access('post comments') && variable_get('photos_comment', 0) || user_access('administer comments') && variable_get('photos_comment', 0)) {
        $build = drupal_get_form("comment_node_{$node->type}_form", (object) array(
          'nid' => $node->nid,
        ));
        $output['comment_form'] = $build;
      }
    }
  }
  if ($output) {
    if (module_exists('ajax_comments')) {

      // Add support for ajax comments on image page.
      $output['comments']['#prefix'] = '<div id="comment-wrapper-nid-' . $node->nid . '">';
      $output['comments']['#prefix'] .= '<div class="ajax-comment-wrapper"></div>';
      $output['comments']['#suffix'] = '</div>';
    }
    $output += array(
      '#theme' => 'comment_wrapper__node_' . $node->type,
      '#node' => $node,
      'comments' => array(),
      'comment_form' => array(),
    );
  }
  return $output;
}