/** * Assign Variables and Definitions based on the fetched Attachments - internal * used by all displaying functions, the Data was collected before, it's only dependend on the template used. :) * before this function is usable, init_display_attachments have to be called for specific pages (pm, posting, review etc...) */ function display_attachments($post_id) { global $template, $upload_dir, $userdata, $allowed_extensions, $display_categories, $download_modes, $db, $lang, $phpEx, $attachments, $upload_icons, $attach_config; global $phpbb_root_path; $num_attachments = sizeof($attachments['_' . $post_id]); if ($num_attachments == 0) { return; } $template->assign_block_vars('postrow.attach', array()); for ($i = 0; $i < $num_attachments; $i++) { // Some basic things... $filename = $upload_dir . '/' . basename($attachments['_' . $post_id][$i]['physical_filename']); $thumbnail_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . basename($attachments['_' . $post_id][$i]['physical_filename']); $upload_image = ''; if ($attach_config['upload_img'] != '' && trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) == '') { // Begin PNphpBB2 Module // $upload_image = '<img src="' . $attach_config['upload_img'] . '" alt="" border="0" />'; $upload_image = '<img src="' . $phpbb_root_path . $attach_config['upload_img'] . '" alt="" />'; // End PNphpBB2 Module } else { if (trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) != '') { $upload_image = '<img src="' . $upload_icons[$attachments['_' . $post_id][$i]['extension']] . '" alt="" border="0" />'; } } $filesize = $attachments['_' . $post_id][$i]['filesize']; $size_lang = $filesize >= 1048576 ? $lang['MB'] : ($filesize >= 1024 ? $lang['KB'] : $lang['Bytes']); if ($filesize >= 1048576) { $filesize = round(round($filesize / 1048576 * 100) / 100, 2); } else { if ($filesize >= 1024) { $filesize = round(round($filesize / 1024 * 100) / 100, 2); } } $display_name = $attachments['_' . $post_id][$i]['real_filename']; $comment = $attachments['_' . $post_id][$i]['comment']; $comment = str_replace("\n", '<br />', $comment); $denied = false; // Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin if (!in_array($attachments['_' . $post_id][$i]['extension'], $allowed_extensions)) { $denied = true; $template->assign_block_vars('postrow.attach.denyrow', array('L_DENIED' => sprintf($lang['Extension_disabled_after_posting'], $attachments['_' . $post_id][$i]['extension']))); } if (!$denied || $userdata['user_level'] == ADMIN) { // Some basic Template Vars $template->assign_vars(array('L_DESCRIPTION' => $lang['Description'], 'L_DOWNLOAD' => $lang['Download'], 'L_FILENAME' => $lang['File_name'], 'L_FILESIZE' => $lang['Filesize'])); // define category $image = FALSE; $stream = FALSE; $swf = FALSE; $thumbnail = FALSE; $link = FALSE; if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == STREAM_CAT) { $stream = TRUE; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == SWF_CAT) { $swf = TRUE; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && intval($attach_config['img_display_inlined'])) { if (intval($attach_config['img_link_width']) != 0 || intval($attach_config['img_link_height']) != 0) { list($width, $height) = image_getdimension($filename); if ($width == 0 && $height == 0) { $image = TRUE; } else { if ($width <= intval($attach_config['img_link_width']) && $height <= intval($attach_config['img_link_height'])) { $image = TRUE; } } } else { $image = TRUE; } } } } if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1) { $thumbnail = TRUE; $image = FALSE; } if (!$image && !$stream && !$swf && !$thumbnail) { $link = TRUE; } if ($image) { // Images // NOTE: If you want to use the download.php everytime an image is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $img_source = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); // $download_link = TRUE; // // if (intval($attach_config['allow_ftp_upload']) && trim($attach_config['download_path']) == '') { // Begin PNphpBB2 Module // $img_source = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); $img_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); // End PNphpBB2 Module $download_link = TRUE; } else { // Check if we can reach the file or if it is stored outside of the webroot if ($attach_config['upload_dir'][0] == '/' || $attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':') { // Begin PNphpBB2 Module // $img_source = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); $img_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); // End PNphpBB2 Module $download_link = TRUE; } else { // BEGIN $img_source = $filename; $download_link = FALSE; // END } } $template->assign_block_vars('postrow.attach.cat_images', array('DOWNLOAD_NAME' => $display_name, 'S_UPLOAD_IMAGE' => $upload_image, 'IMG_SRC' => $img_source, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']))); // Directly Viewed Image ... update the download count if (!$download_link) { $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int) $attachments['_' . $post_id][$i]['attach_id']; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count.', '', __LINE__, __FILE__, $sql); } } } if ($thumbnail) { // Images, but display Thumbnail // NOTE: If you want to use the download.php everytime an thumnmail is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $thumb_source = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); // if (intval($attach_config['allow_ftp_upload']) && trim($attach_config['download_path']) == '') { // Begin PNphpBB2 Module // $thumb_source = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); $thumb_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); // End PNphpBB2 Module } else { // Check if we can reach the file or if it is stored outside of the webroot if ($attach_config['upload_dir'][0] == '/' || $attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':') { // Begin PNphpBB2 Module // $thumb_source = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); $thumb_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); // End PNphpBB2 Module } else { // BEGIN $thumb_source = $thumbnail_filename; // END } } $template->assign_block_vars('postrow.attach.cat_thumb_images', array('DOWNLOAD_NAME' => $display_name, 'S_UPLOAD_IMAGE' => $upload_image, 'IMG_SRC' => append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']), 'IMG_THUMB_SRC' => $thumb_source, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']))); } if ($stream) { // Streams $template->assign_block_vars('postrow.attach.cat_stream', array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']))); // Viewed/Heared File ... update the download count (download.php is not called here) $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int) $attachments['_' . $post_id][$i]['attach_id']; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count', '', __LINE__, __FILE__, $sql); } } if ($swf) { // Macromedia Flash Files list($width, $height) = swf_getdimension($filename); $template->assign_block_vars('postrow.attach.cat_swf', array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']), 'WIDTH' => $width, 'HEIGHT' => $height)); // Viewed/Heared File ... update the download count (download.php is not called here) $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int) $attachments['_' . $post_id][$i]['attach_id']; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count', '', __LINE__, __FILE__, $sql); } } if ($link) { $target_blank = 'target="_blank"'; //( (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT) ) ? 'target="_blank"' : ''; // display attachment $template->assign_block_vars('postrow.attach.attachrow', array('U_DOWNLOAD_LINK' => append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']), 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'TARGET_BLANK' => $target_blank, 'L_DOWNLOADED_VIEWED' => $lang['Downloaded'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']))); } } } }
function display_attachments_preview($attachment_list, $attachment_filesize_list, $attachment_filename_list, $attachment_comment_list, $attachment_extension_list, $attachment_thumbnail_list) { global $attach_config, $is_auth, $allowed_extensions, $lang, $userdata, $display_categories, $upload_dir, $upload_icons, $template, $theme; if (count($attachment_list) != 0) { init_display_template('preview', '{ATTACHMENTS}'); init_complete_extensions_data(); $template->assign_block_vars('postrow', array()); $template->assign_block_vars('postrow.attach', array()); $template->assign_vars(array('T_BODY_TEXT' => '#' . $theme['body_text'], 'T_TR_COLOR3' => '#' . $theme['tr_color3'])); for ($i = 0; $i < count($attachment_list); $i++) { $filename = $upload_dir . '/' . $attachment_list[$i]; $thumb_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . $attachment_list[$i]; $filesize = $attachment_filesize_list[$i]; $size_lang = $filesize >= 1048576 ? $lang['MB'] : ($filesize >= 1024 ? $lang['KB'] : $lang['Bytes']); if ($filesize >= 1048576) { $filesize = round(round($filesize / 1048576 * 100) / 100, 2); } else { if ($filesize >= 1024) { $filesize = round(round($filesize / 1024 * 100) / 100, 2); } } $display_name = htmlspecialchars($attachment_filename_list[$i]); $comment = trim(htmlspecialchars(stripslashes($attachment_comment_list[$i]))); $comment = str_replace("\n", '<br />', $comment); $extension = strtolower(trim($attachment_extension_list[$i])); $denied = false; // // Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin // if (!in_array($extension, $allowed_extensions)) { $denied = true; $template->assign_block_vars('postrow.attach.denyrow', array('L_DENIED' => sprintf($lang['Extension_disabled_after_posting'], $extension))); } if (!$denied) { // // Some basic Template Vars // $template->assign_vars(array('L_DESCRIPTION' => $lang['Description'], 'L_DOWNLOAD' => $lang['Download'], 'L_FILENAME' => $lang['File_name'], 'L_FILESIZE' => $lang['Filesize'])); // // define category // $image = FALSE; $stream = FALSE; $swf = FALSE; $thumbnail = FALSE; $link = FALSE; if (intval($display_categories[$extension]) == STREAM_CAT) { $stream = TRUE; } else { if (intval($display_categories[$extension]) == SWF_CAT) { $swf = TRUE; } else { if (intval($display_categories[$extension]) == IMAGE_CAT && intval($attach_config['img_display_inlined'])) { if (intval($attach_config['img_link_width']) != 0 || intval($attach_config['img_link_height']) != 0) { list($width, $height) = image_getdimension($filename); if ($width == 0 && $height == 0) { $image = TRUE; } else { if ($width <= intval($attach_config['img_link_width']) && $height <= intval($attach_config['img_link_height'])) { $image = TRUE; } } } else { $image = TRUE; } } } } if (intval($display_categories[$extension]) == IMAGE_CAT && intval($attachment_thumbnail_list[$i]) == 1) { $thumbnail = TRUE; $image = FALSE; } if (!$image && !$stream && !$swf && !$thumbnail) { $link = TRUE; } if ($image) { // // Images // $template->assign_block_vars('postrow.attach.cat_images', array('DOWNLOAD_NAME' => $display_name, 'IMG_SRC' => $filename, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'])); } if ($thumbnail) { // // Images, but display Thumbnail // $template->assign_block_vars('postrow.attach.cat_thumb_images', array('DOWNLOAD_NAME' => $display_name, 'IMG_SRC' => $filename, 'IMG_THUMB_SRC' => $thumb_filename, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'])); } if ($stream) { // // Streams // $template->assign_block_vars('postrow.attach.cat_stream', array('U_DOWNLOAD_LINK' => $filename, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'])); } if ($swf) { // // Macromedia Flash Files // list($width, $height) = swf_getdimension($filename); $template->assign_block_vars('postrow.attach.cat_swf', array('U_DOWNLOAD_LINK' => $filename, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'WIDTH' => $width, 'HEIGHT' => $height)); } if ($link) { $upload_image = ''; if ($attach_config['upload_img'] != '' && $upload_icons[$extension] == '') { $upload_image = '<img src="' . $attach_config['upload_img'] . '" alt="" border="0" />'; } else { if (trim($upload_icons[$extension]) != '') { $upload_image = '<img src="' . $upload_icons[$extension] . '" alt="" border="0" />'; } } $target_blank = 'target="_blank"'; // // display attachment // $template->assign_block_vars('postrow.attach.attachrow', array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Downloaded'], 'TARGET_BLANK' => $target_blank)); } } } } }
function display_attachments($post_id, $num_attachments) { global $template, $upload_dir, $userdata, $allowed_extensions, $display_categories, $download_modes, $db, $lang, $phpEx, $attachments, $upload_icons, $attach_config; $template->set_filename('attachments', 'attachments.tpl'); // // Some basic Template Vars // $template->assign_vars(array('L_DESCRIPTION' => $lang['Description'], 'L_DOWNLOAD' => $lang['Download'], 'L_FILENAME' => $lang['File_name'], 'L_FILESIZE' => $lang['Filesize'])); for ($i = 0; $i < $num_attachments; $i++) { // // Some basic things... // $filename = $upload_dir . '/' . $attachments['_' . $post_id][$i]['physical_filename']; $thumbnail_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . $attachments['_' . $post_id][$i]['physical_filename']; $upload_image = ''; if ($attach_config['upload_img'] != '' && trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) == '') { $upload_image = '<img src="templates/' . $template->tpl . '/images/' . $attach_config['upload_img'] . '" alt="" border="0" />'; } else { if (trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) != '') { $upload_image = '<img src="' . $upload_icons[$attachments['_' . $post_id][$i]['extension']] . '" alt="" border="0" />'; } } $filesize = $attachments['_' . $post_id][$i]['filesize']; $size_lang = $filesize >= 1048576 ? $lang['MB'] : ($filesize >= 1024 ? $lang['KB'] : $lang['Bytes']); if ($filesize >= 1048576) { $filesize = round(round($filesize / 1048576 * 100) / 100, 2); } else { if ($filesize >= 1024) { $filesize = round(round($filesize / 1024 * 100) / 100, 2); } } $display_name = $attachments['_' . $post_id][$i]['real_filename']; $comment = trim(htmlspecialchars(stripslashes($attachments['_' . $post_id][$i]['comment']))); $comment = str_replace("\n", '<br />', $comment); $attachments['_' . $post_id][$i]['extension'] = strtolower(trim($attachments['_' . $post_id][$i]['extension'])); $denied = false; // // Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin // if (!in_array($attachments['_' . $post_id][$i]['extension'], $allowed_extensions)) { $denied = true; } if (!$denied) { // // define category // $type = ''; $image = FALSE; $stream = FALSE; $swf = FALSE; $thumbnail = FALSE; $link = FALSE; if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == STREAM_CAT) { $type = 'stream'; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == SWF_CAT) { $type = 'swf'; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && intval($attach_config['img_display_inlined'])) { if (intval($attach_config['img_link_width']) != 0 || intval($attach_config['img_link_height']) != 0) { list($width, $height) = image_getdimension($filename); if ($width == 0 && $height == 0) { $type = 'image'; } else { if ($width <= intval($attach_config['img_link_width']) && $height <= intval($attach_config['img_link_height'])) { $type = 'image'; } } } else { $type = 'image'; } } } } if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1) { $type = 'thumbnail'; } if ($type != 'image' && $type != 'stream' && $type != 'swf' && $type != 'thumbnail') { $type = 'link'; } if ($type == 'image') { // // Images // NOTE: If you want to use the download.php everytime an image is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $img_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); // $download_link = TRUE; // // if (intval($attach_config['allow_ftp_upload']) && trim($attach_config['download_path']) == '') { $img_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); $download_link = TRUE; } else { $img_source = $filename; $download_link = FALSE; } $attachrow_vars = array('DOWNLOAD_NAME' => $display_name, 'S_UPLOAD_IMAGE' => $upload_image, 'IMG_SRC' => $img_source, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count'])); // // Directly Viewed Image ... update the download count // if (!$download_link) { $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . $attachments['_' . $post_id][$i]['attach_id']; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count.', '', __LINE__, __FILE__, $sql); } } } elseif ($type == 'thumbnail') { // // Images, but display Thumbnail // NOTE: If you want to use the download.php everytime an thumnmail is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $thumb_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); // if (intval($attach_config['allow_ftp_upload']) && trim($attach_config['download_path']) == '') { $thumb_source = append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); } else { $thumb_source = $thumbnail_filename; } $attachrow_vars = array('DOWNLOAD_NAME' => $display_name, 'S_UPLOAD_IMAGE' => $upload_image, 'IMG_SRC' => append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']), 'IMG_THUMB_SRC' => $thumb_source, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count'])); } elseif ($type == 'stream') { // // Streams // $attachrow_vars = array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count'])); // // Viewed/Heared File ... update the download count (download.php is not called here) // $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . $attachments['_' . $post_id][$i]['attach_id']; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count', '', __LINE__, __FILE__, $sql); } } elseif ($type == 'swf') { // // Macromedia Flash Files // list($width, $height) = swf_getdimension($filename); $attachrow_vars = array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']), 'WIDTH' => $width, 'HEIGHT' => $height); // // Viewed/Heared File ... update the download count (download.php is not called here) // $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . $attachments['_' . $post_id][$i]['attach_id']; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count', '', __LINE__, __FILE__, $sql); } } elseif ($type == 'link') { $target_blank = intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT ? 'target="_blank"' : ''; // // display attachment // $attachrow_vars = array('U_DOWNLOAD_LINK' => append_sid('download.' . $phpEx . '?id=' . $attachments['_' . $post_id][$i]['attach_id']), 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'TARGET_BLANK' => $target_blank, 'L_DOWNLOADED_VIEWED' => $lang['Downloaded'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count'])); } } $attachrow_vars['TYPE'] = $type; $attachrow_vars['L_DENIED'] = $denied ? sprintf($lang['Extension_disabled_after_posting'], $attachments['_' . $post_id][$i]['extension']) : ''; $template->assign_block_vars('attachrow', $attachrow_vars); } $template->assign_block_var_from_handle('postrow.ATTACHMENTS', 'attachments'); $template->clear_block_var('attachrow'); }
/** * Assign Variables and Definitions based on the fetched Attachments - internal * used by all displaying functions, the Data was collected before, it's only dependend on the template used. :) * before this function is usable, init_display_attachments have to be called for specific pages (pm, posting, review etc...) */ function display_attachments($post_id, $type = 'postrow') { global $db, $config, $template, $user, $lang; global $upload_dir, $allowed_extensions, $display_categories, $download_modes, $attachments, $upload_icons, $username_from; $num_attachments = sizeof($attachments['_' . $post_id]); if ($num_attachments == 0) { return; } $template->assign_block_vars($type . '.attach', array()); for ($i = 0; $i < $num_attachments; $i++) { // Some basic things... $filename = $upload_dir . '/' . basename($attachments['_' . $post_id][$i]['physical_filename']); $thumbnail_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . basename($attachments['_' . $post_id][$i]['physical_filename']); $upload_image = ''; if ($config['upload_img'] != '' && trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) == '') { $upload_image = '<img src="' . $config['upload_img'] . '" alt="" />'; } elseif (trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) != '') { $upload_image = '<img src="' . $upload_icons[$attachments['_' . $post_id][$i]['extension']] . '" alt="" />'; } $filesize = $attachments['_' . $post_id][$i]['filesize']; $size_lang = $filesize >= 1048576 ? $lang['MB'] : ($filesize >= 1024 ? $lang['KB'] : $lang['Bytes']); if ($filesize >= 1048576) { $filesize = round(round($filesize / 1048576 * 100) / 100, 2); } elseif ($filesize >= 1024) { $filesize = round(round($filesize / 1024 * 100) / 100, 2); } $display_name = $attachments['_' . $post_id][$i]['real_filename']; $comment = $attachments['_' . $post_id][$i]['comment']; $comment = str_replace("\n", '<br />', $comment); $denied = false; // Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin if (!in_array($attachments['_' . $post_id][$i]['extension'], $allowed_extensions)) { $denied = true; $template->assign_block_vars($type . '.attach.denyrow', array('L_DENIED' => sprintf($lang['Extension_disabled_after_posting'], $attachments['_' . $post_id][$i]['extension']))); } if (!$denied || $user->data['user_level'] == ADMIN) { // Some basic Template Vars $template->assign_vars(array('L_DESCRIPTION' => $lang['Description'], 'L_DOWNLOAD' => $lang['Download'], 'L_FILENAME' => $lang['File_name'], 'L_FILESIZE' => $lang['Filesize'])); // define category $image = false; $stream = false; $swf = false; $thumbnail = false; $link = false; if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == STREAM_CAT) { $stream = true; } elseif (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == SWF_CAT) { $swf = true; } elseif (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && intval($config['img_display_inlined'])) { if (intval($config['img_link_width']) != 0 || intval($config['img_link_height']) != 0) { list($width, $height) = image_getdimension($filename); if ($width == 0 && $height == 0) { $image = true; } else { if ($width <= intval($config['img_link_width']) && $height <= intval($config['img_link_height'])) { $image = true; } } } else { $image = true; } } if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1) { $thumbnail = true; $image = false; } if (!$image && !$stream && !$swf && !$thumbnail) { $link = true; } if ($image) { // Images // NOTE: If you want to use the download.php everytime an image is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $img_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); // $download_link = true; // // if (intval($config['allow_ftp_upload']) && trim($config['download_path']) == '') { $img_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); $download_link = true; } else { // Check if we can reach the file or if it is stored outside of the webroot if ($config['upload_dir'][0] == '/' || $config['upload_dir'][0] != '/' && $config['upload_dir'][1] == ':') { $img_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id']); $download_link = true; } else { // BEGIN $img_source = $filename; $download_link = false; // END } } $max_image_width = intval($config['liw_max_width']); $server_protocol = $config['cookie_secure'] ? 'https://' : 'http://'; $server_name = preg_replace('#^\\/?(.*?)\\/?$#', '\\1', trim($config['server_name'])); $server_port = $config['server_port'] != 80 ? ':' . trim($config['server_port']) : ''; $script_name = preg_replace('#^\\/?(.*?)\\/?$#', '\\1', trim($config['script_path'])); $script_name = $script_name == '' ? $script_name : '/' . $script_name; if ($max_image_width != 0 && $config['liw_attach_enabled'] == 1 && !isset($username_from)) { if (!function_exists('liw_get_dimensions')) { include_once IP_ROOT_PATH . ATTACH_MOD_PATH . 'includes/functions_includes.' . PHP_EXT; } list($image_width, $image_height) = liw_get_dimensions($server_protocol . $server_name . $server_port . $script_name . '/' . $img_source, $post_id); if ($image_width && $image_width > $max_image_width || empty($image_width) || empty($image_height)) { $img_code = generate_liw_img_popup($img_source, $image_width, $image_height, $max_image_width); } else { $img_code = '<img src="' . $img_source . '" alt="' . $display_name . '" />'; } } else { $img_code = '<img src="' . $img_source . '" alt="' . $display_name . '" />'; } $download_count_link = $attachments['_' . $post_id][$i]['download_count'] > '0' && $user->data['user_level'] == ADMIN ? '<a href="' . append_sid(IP_ROOT_PATH . 'attachments.' . PHP_EXT . '?attach_id=' . $attachments['_' . $post_id][$i]['attach_id']) . '">' . sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']) . '</a>' : sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']); $template->assign_block_vars($type . '.attach.cat_images', array('DOWNLOAD_NAME' => $display_name, 'S_UPLOAD_IMAGE' => $upload_image, 'IMG_CODE' => $img_code, 'IMG_SRC' => $img_source, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => $download_count_link)); // Directly Viewed Image ... update the download count if (!$download_link) { update_attachments_stats($attachments['_' . $post_id][$i]['attach_id']); } } if ($thumbnail) { // Images, but display Thumbnail // NOTE: If you want to use the download.php everytime an thumbnail is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $thumb_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); // if (intval($config['allow_ftp_upload']) && trim($config['download_path']) == '') { $thumb_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); } else { // Check if we can reach the file or if it is stored outside of the webroot if ($config['upload_dir'][0] == '/' || $config['upload_dir'][0] != '/' && $config['upload_dir'][1] == ':') { $thumb_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); } else { if (file_exists($thumbnail_filename)) { // BEGIN $thumb_source = $thumbnail_filename; // END } else { $thumb_source = append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); } } } $download_count_link = $attachments['_' . $post_id][$i]['download_count'] > '0' && $user->data['user_level'] == ADMIN ? '<a href="' . append_sid(IP_ROOT_PATH . 'attachments.' . PHP_EXT . '?attach_id=' . $attachments['_' . $post_id][$i]['attach_id']) . '">' . sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']) . '</a>' : sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']); $template->assign_block_vars($type . '.attach.cat_thumb_images', array('DOWNLOAD_NAME' => $display_name, 'S_UPLOAD_IMAGE' => $upload_image, 'IMG_SRC' => append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id']), 'IMG_THUMB_SRC' => $thumb_source, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => $download_count_link)); } if ($stream) { // Streams $download_count_link = $attachments['_' . $post_id][$i]['download_count'] > '0' && $user->data['user_level'] == ADMIN ? '<a href="' . append_sid(IP_ROOT_PATH . 'attachments.' . PHP_EXT . '?attach_id=' . $attachments['_' . $post_id][$i]['attach_id']) . '">' . sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']) . '</a>' : sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']); $template->assign_block_vars($type . '.attach.cat_stream', array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => $download_count_link)); // Viewed/Heared File ... update the download count (download.php is not called here) update_attachments_stats($attachments['_' . $post_id][$i]['attach_id']); } if ($swf) { // Macromedia Flash Files list($width, $height) = swf_getdimension($filename); $download_count_link = $attachments['_' . $post_id][$i]['download_count'] > '0' && $user->data['user_level'] == ADMIN ? '<a href="' . append_sid(IP_ROOT_PATH . 'attachments.' . PHP_EXT . '?attach_id=' . $attachments['_' . $post_id][$i]['attach_id']) . '">' . sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']) . '</a>' : sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']); $template->assign_block_vars($type . '.attach.cat_swf', array('U_DOWNLOAD_LINK' => $filename, 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'L_DOWNLOADED_VIEWED' => $lang['Viewed'], 'L_DOWNLOAD_COUNT' => $download_count_link, 'WIDTH' => $width, 'HEIGHT' => $height)); // Viewed/Heared File ... update the download count (download.php is not called here) update_attachments_stats($attachments['_' . $post_id][$i]['attach_id']); } if ($link) { $target_blank = 'target="_blank"'; //((intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT)) ? 'target="_blank"' : ''; // display attachment $download_count_link = $attachments['_' . $post_id][$i]['download_count'] > '0' && $user->data['user_level'] == ADMIN ? '<a href="' . append_sid(IP_ROOT_PATH . 'attachments.' . PHP_EXT . '?attach_id=' . $attachments['_' . $post_id][$i]['attach_id']) . '">' . sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']) . '</a>' : sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']); $template->assign_block_vars($type . '.attach.attachrow', array('U_DOWNLOAD_LINK' => append_sid(IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $attachments['_' . $post_id][$i]['attach_id']), 'S_UPLOAD_IMAGE' => $upload_image, 'DOWNLOAD_NAME' => $display_name, 'FILESIZE' => $filesize, 'SIZE_VAR' => $size_lang, 'COMMENT' => $comment, 'TARGET_BLANK' => $target_blank, 'L_DOWNLOADED_VIEWED' => $lang['Downloaded'], 'L_DOWNLOAD_COUNT' => $download_count_link)); } } } }
function display_attachments($post_id) { global $template, $upload_dir, $userdata, $allowed_extensions, $display_categories, $download_modes, $db, $lang, $attachments, $upload_icons, $attach_config, $module_name; if (empty($attachments) || !isset($attachments['_' . $post_id])) { // trigger_error('There are no attachments for '.$post_id, E_USER_NOTICE); return; } $num_attachments = count($attachments['_' . $post_id]); $blockvar = 'postrow.attachment'; // // Some basic Template Vars // $template->assign_vars(array('L_DESCRIPTION' => $lang['Description'], 'L_DOWNLOAD' => $lang['Download'], 'L_FILENAME' => $lang['File_name'], 'L_FILESIZE' => $lang['Filesize'])); for ($i = 0; $i < $num_attachments; $i++) { // // Some basic things... // $attachments['_' . $post_id][$i]['extension'] = strtolower(trim($attachments['_' . $post_id][$i]['extension'])); // // Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin // $denied = !in_array($attachments['_' . $post_id][$i]['extension'], $allowed_extensions); if (!$denied || is_admin()) { $filename = $upload_dir . '/' . $attachments['_' . $post_id][$i]['physical_filename']; $upload_image = ''; if ($attach_config['upload_img'] != '' && trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) == '') { $upload_image = '<img src="' . $attach_config['upload_img'] . '" alt="" />'; } else { if (trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) != '') { $upload_image = '<img src="' . $upload_icons[$attachments['_' . $post_id][$i]['extension']] . '" alt="" />'; } } // // define category // $display = 'DEF_CAT'; if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == STREAM_CAT) { $display = 'STREAM_CAT'; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == SWF_CAT) { $display = 'SWF_CAT'; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1) { $display = 'THUMB_CAT'; } else { if (intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && intval($attach_config['img_display_inlined'])) { if (intval($attach_config['img_link_width']) != 0 || intval($attach_config['img_link_height']) != 0) { list($width, $height) = image_getdimension($filename); if ($width == 0 && $height == 0) { $display = 'IMAGE_CAT'; } else { if ($width <= intval($attach_config['img_link_width']) && $height <= intval($attach_config['img_link_height'])) { $display = 'IMAGE_CAT'; } } } else { $display = 'IMAGE_CAT'; } } } } } $thumb_source = ''; $width = $height = 0; $blockname = $blockvar; $module = $module_name == 'Private_Messages' ? 'Forums' : $module_name; switch ($display) { // Images case 'IMAGE_CAT': // NOTE: If you want to use the download.php everytime an image is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $img_source = URL::index($module.'&file=download&id=' . $attachments['_' . $post_id][$i]['attach_id']); // $download_link = TRUE; // if (intval($attach_config['allow_ftp_upload']) && trim($attach_config['download_path']) == '') { $filename = URL::index($module . '&file=download&id=' . $attachments['_' . $post_id][$i]['attach_id']); $download_link = TRUE; } else { $download_link = FALSE; } // // Directly Viewed Image ... update the download count // if (!$download_link) { $db->sql_query('UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . $attachments['_' . $post_id][$i]['attach_id']); } break; // Images, but display Thumbnail // Images, but display Thumbnail case 'THUMB_CAT': // NOTE: If you want to use the download.php everytime an thumnmail is displayed inlined, replace the // Section between BEGIN and END with (Without the // of course): // $thumb_source = URL::index($module.'&file=download&id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); // if (intval($attach_config['allow_ftp_upload']) && trim($attach_config['download_path']) == '') { $thumb_source = URL::index($module . '&file=download&id=' . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1'); } else { $thumb_source = $upload_dir . '/' . THUMB_DIR . '/t_' . $attachments['_' . $post_id][$i]['physical_filename']; } $filename = URL::index($module . '&file=download&id=' . $attachments['_' . $post_id][$i]['attach_id']); break; // Streams // Streams case 'STREAM_CAT': // // Viewed/Heared File ... update the download count (download.php is not called here) // $db->sql_query('UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . $attachments['_' . $post_id][$i]['attach_id']); break; // Macromedia Flash Files // Macromedia Flash Files case 'SWF_CAT': list($width, $height) = swf_getdimension($filename); // // Viewed/Heared File ... update the download count (download.php is not called here) // $db->sql_query('UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 WHERE attach_id = ' . $attachments['_' . $post_id][$i]['attach_id']); break; // display attachment // display attachment default: $filename = URL::index($module . '&file=download&id=' . $attachments['_' . $post_id][$i]['attach_id']); break; } $template->assign_block_vars($blockname, array('L_ALLOWED' => !$denied || is_admin(), 'L_DENIED' => $denied ? sprintf($lang['Extension_disabled_after_posting'], $attachments['_' . $post_id][$i]['extension']) : false, 'S_DEF_CAT' => false, 'S_IMAGE_CAT' => false, 'S_THUMB_CAT' => false, 'S_STREAM_CAT' => false, 'S_SWF_CAT' => false, 'S_' . $display => true, 'DOWNLOAD_NAME' => $attachments['_' . $post_id][$i]['real_filename'], 'S_UPLOAD_IMAGE' => $upload_image, 'FILESIZE' => filesize_to_human($attachments['_' . $post_id][$i]['filesize']), 'COMMENT' => htmlprepare($attachments['_' . $post_id][$i]['comment'], true), 'L_DOWNLOADED_VIEWED' => $display == 'DEF_CAT' ? $lang['Downloaded'] : $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachments['_' . $post_id][$i]['download_count']), 'IMG_SRC' => $filename, 'IMG_THUMB_SRC' => $thumb_source, 'U_DOWNLOAD_LINK' => $filename, 'WIDTH' => $width, 'HEIGHT' => $height, 'TARGET_BLANK' => intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT || $display == 'DEF_CAT' ? 'target="_blank"' : '')); } } }