/**
* Physical Filename stored already ?
*/
function physical_filename_already_stored($filename)
{
    global $db;
    if ($filename == '') {
        return false;
    }
    $filename = get_physical_filename($filename, false);
    $sql = 'SELECT attach_id
		FROM ' . ATTACHMENTS_DESC_TABLE . "\n\t\tWHERE physical_filename = '" . $db->sql_escape($filename) . "'\n\t\tLIMIT 1";
    $result = $db->sql_query($sql);
    $num_rows = $db->sql_numrows($result);
    $db->sql_freeresult($result);
    return $num_rows == 0 ? false : true;
}
Example #2
0
$rows = $db->sql_fetchrowset($result);
$num_rows = $db->sql_numrows($result);
for ($i = 0; $i < $num_rows; $i++) {
    $extension = strtolower(trim($rows[$i]['extension']));
    $allowed_extensions[] = $extension;
    $download_mode[$extension] = $rows[$i]['download_mode'];
}
// disallowed ?
if (!in_array($attachment['extension'], $allowed_extensions) && $user->data['user_level'] != ADMIN) {
    message_die(GENERAL_MESSAGE, sprintf($lang['Extension_disabled_after_posting'], $attachment['extension']));
}
$download_mode = intval($download_mode[$attachment['extension']]);
if ($thumbnail) {
    $thumb_exists = check_thumbnail($attachment, $upload_dir);
    if (!empty($thumb_exists)) {
        $attachment['physical_filename'] = get_physical_filename($attachment['physical_filename'], true);
    } else {
        $thumbnail = 0;
    }
}
// Update download count
if (!$thumbnail) {
    update_attachments_stats($attachment['attach_id']);
}
// Determine the 'presenting'-method
if ($download_mode == PHYSICAL_LINK) {
    $server_url = create_server_url();
    if ($script_name[strlen($script_name)] != '/') {
        $script_name .= '/';
    }
    if (intval($config['allow_ftp_upload'])) {
    }
    // Now look at the missing posts and PM's
    for ($i = 0; $i < sizeof($table_attachments['attach_id']); $i++) {
        if ($table_attachments['attach_id'][$i]) {
            if (!entry_exists($table_attachments['attach_id'][$i])) {
                $shadow_row['attach_id'][] = $table_attachments['attach_id'][$i];
                $shadow_row['physical_filename'][] = trim($table_attachments['physical_filename'][$i]);
                $shadow_row['comment'][] = $table_attachments['comment'][$i];
            }
        }
    }
    for ($i = 0; $i < sizeof($shadow_attachments); $i++) {
        $template->assign_block_vars('file_shadow_row', array('ATTACH_ID' => $shadow_attachments[$i], 'ATTACH_FILENAME' => $shadow_attachments[$i], 'ATTACH_COMMENT' => $lang['No_file_comment_available'], 'U_ATTACHMENT' => $upload_dir . '/' . get_physical_filename($shadow_attachments[$i], false)));
    }
    for ($i = 0; $i < sizeof($shadow_row['attach_id']); $i++) {
        $template->assign_block_vars('table_shadow_row', array('ATTACH_ID' => $shadow_row['attach_id'][$i], 'ATTACH_FILENAME' => get_physical_filename($shadow_row['physical_filename'][$i], false), 'ATTACH_COMMENT' => trim($shadow_row['comment'][$i]) == '' ? $lang['No_file_comment_available'] : trim($shadow_row['comment'][$i])));
    }
}
if ($submit && $mode == 'cats') {
    if (!$error) {
        $cache->destroy('config');
        message_die(GENERAL_MESSAGE, $lang['Attach_config_updated'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid('admin_attachments.' . PHP_EXT . '?mode=cats') . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid('index.' . PHP_EXT . '?pane=right') . '">', '</a>'));
    }
}
if ($mode == 'cats') {
    $template->set_filenames(array('body' => ADM_TPL . 'attach_cat_body.tpl'));
    $s_assigned_group_images = $lang['None'];
    $s_assigned_group_streams = $lang['None'];
    $s_assigned_group_flash = $lang['None'];
    $sql = 'SELECT group_name, cat_id
		FROM ' . EXTENSION_GROUPS_TABLE . '
Example #4
0
/**
* 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...
        $physical_filename = get_physical_filename($attachments['_' . $post_id][$i]['physical_filename'], false);
        $physical_filename_thumb = get_physical_filename($attachments['_' . $post_id][$i]['physical_filename'], true);
        $filename = $upload_dir . '/' . $physical_filename;
        $thumbnail_filename = $upload_dir . '/' . $physical_filename_thumb;
        $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));
            }
        }
    }
}