function itweak_upload_comment in iTweak Upload 6.2
Implementation of hook_comment(). Add attachments to the comment on view or preview. Here we intercept attachments from comment_upload.module, and render them ourselves. It is critical to be before comment_upload.module in {system} (lower weight).
Parameters
$comment: Comment object
$op: Operation
File
- ./
itweak_upload.module, line 1287 - iTweakUpload - Tweak attachments display and file upload forms.
Code
function itweak_upload_comment(&$comment, $op) {
if ($op != 'delete' && !($op == 'view' && user_access('view files uploaded to comments')) || !module_exists('comment_upload')) {
return;
}
if (!isset($comment->files)) {
$comment->files = comment_upload_load_files($comment->cid);
}
if (!isset($comment->files) || !count($comment->files)) {
return;
}
if ($op == 'delete') {
if (function_exists('imagecache_file_delete')) {
foreach ($comment->files as $fid => $file) {
// Instead of figuring out if file has other references, been replaced
// or why else it should not be flushed form imagecache,
// we purge the cache regardless.
// Imagecache will rebuild it when needed if there are other references.
imagecache_file_delete((object) $file);
}
}
return;
}
// All we need is node type.
// Maybe we can get it cheaper by simple query? However, it misses node_load cache that way.
$node = node_load($comment->nid);
$node_type = $node->type;
// $node = db_fetch_object(db_query('SELECT n.type FROM {node} n WHERE n.nid = %d', array($comment->nid)));
// $node_type = $node->type;
$files_display = variable_get('itweak_upload_comment_display_' . $node_type, 2);
if ($files_display) {
$group = 'c' . $comment->cid;
// Add 'c' to comment id to avoid potential conflict with node id.
$setting_name = 'comment';
$cnt_other = _itweak_upload_preprocess_files($comment->files, $thumbnails, $files_display, $setting_name, $node_type, $group);
// Add regular attachment list
if ($cnt_other) {
if ($files_display != 4) {
$comment->comment .= theme('itweak_upload_comment_upload_attachments', $comment->files, FALSE, NULL, TRUE);
}
}
// Clear files list so other modules will not try to display it
$comment->files = array();
if (count($thumbnails)) {
$options = array(
'gallery_type' => _itweak_upload_get_setting('gallery_type', $setting_name, $node_type, _itweak_upload_gallery_type_default()),
);
$comment->comment .= theme('itweak_upload_images_comment', $thumbnails, -1, $options);
}
}
}