You are here

function _comment_upload_load_files in Comment Upload 5

Load files belonging to the comment $cid.

When the optional argument $nid is provided all files belonging to comments on that nid are loaded at once and later served from memory. This reduces the amount of queries on node/nid pages.

Return value

Array of file objects.

3 calls to _comment_upload_load_files()
comment_upload_comment in ./comment_upload.module
Implementation of hook_comment.
comment_upload_js in ./comment_upload.module
Menu-callback for JavaScript-based uploads.
_comment_upload_delete in ./comment_upload.module
Delete files associated with the comment $cid.

File

./comment_upload.module, line 198

Code

function _comment_upload_load_files($cid, $nid = NULL) {
  static $cache = array();
  if ($nid) {

    // Cache all for this node to avoid one query per comment
    if (!isset($cache[$nid])) {
      $cache[$nid] = array();
      $result = db_query('SELECT * FROM {comment_upload_files} f WHERE f.nid = %d ORDER BY f.fid DESC', $nid);
      while ($file = db_fetch_object($result)) {
        $cache[$nid][$file->cid][] = $file;
      }
    }
    return $cache[$nid][$cid];
  }
  else {
    if ($cid) {
      $result = db_query('SELECT * FROM {comment_upload_files} f WHERE f.cid = %d ORDER BY f.fid DESC', $cid);
      while ($file = db_fetch_object($result)) {
        $files[] = $file;
      }
      return $files;
    }
  }
}