예제 #1
0
/**
* BEGIN DISPLAY ATTACHMENTS -> PREVIEW
*/
function display_attachments_preview($attachment_list, $attachment_filesize_list, $attachment_filename_list, $attachment_comment_list, $attachment_extension_list, $attachment_thumbnail_list)
{
    // Begin PNphpBB2 Module
    //	global $attach_config, $is_auth, $allowed_extensions, $lang, $userdata, $display_categories, $upload_dir, $upload_icons, $template, $db, $theme;
    global $phpbb_root_path, $attach_config, $is_auth, $allowed_extensions, $lang, $userdata, $display_categories, $upload_dir, $upload_icons, $template, $db, $phpbb_theme;
    // End PNphpBB2 Module
    if (sizeof($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' => '#' . $phpbb_theme['body_text'], 'T_TR_COLOR3' => '#' . $phpbb_theme['tr_color3']));
        for ($i = 0, $size = sizeof($attachment_list); $i < $size; $i++) {
            $filename = $upload_dir . '/' . basename($attachment_list[$i]);
            $thumb_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . basename($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 = $attachment_filename_list[$i];
            $comment = $attachment_comment_list[$i];
            $comment = str_replace("\n", '<br />', $comment);
            $extension = $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] == '') {
                        // 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[$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));
                }
            }
        }
    }
}
 /**
  * Attachment Mod entry switch/output (intern)
  * @private
  */
 function display_attachment_bodies()
 {
     global $attach_config, $db, $is_auth, $lang, $mode, $phpEx, $template, $upload_dir, $userdata, $HTTP_POST_VARS, $forum_id;
     global $phpbb_root_path;
     // Choose what to display
     $value_add = $value_posted = 0;
     if (intval($attach_config['show_apcp'])) {
         if (!empty($HTTP_POST_VARS['add_attachment_box'])) {
             $value_add = $this->add_attachment_body == 0 ? 1 : 0;
             $this->add_attachment_body = $value_add;
         } else {
             $value_add = $this->add_attachment_body == 0 ? 0 : 1;
         }
         if (!empty($HTTP_POST_VARS['posted_attachments_box'])) {
             $value_posted = $this->posted_attachments_body == 0 ? 1 : 0;
             $this->posted_attachments_body = $value_posted;
         } else {
             $value_posted = $this->posted_attachments_body == 0 ? 0 : 1;
         }
         $template->assign_block_vars('show_apcp', array());
     } else {
         $this->add_attachment_body = 1;
         $this->posted_attachments_body = 1;
     }
     $template->set_filenames(array('attachbody' => 'posting_attach_body.tpl'));
     display_compile_cache_clear($template->files['attachbody'], 'attachbody');
     $s_hidden = '<input type="hidden" name="add_attachment_body" value="' . $value_add . '" />';
     $s_hidden .= '<input type="hidden" name="posted_attachments_body" value="' . $value_posted . '" />';
     if ($this->page == PAGE_PRIVMSGS) {
         $u_rules_id = 0;
     } else {
         $u_rules_id = $forum_id;
     }
     $template->assign_vars(array('L_ATTACH_POSTING_CP' => $lang['Attach_posting_cp'], 'L_ATTACH_POSTING_CP_EXPLAIN' => $lang['Attach_posting_cp_explain'], 'L_OPTIONS' => $lang['Options'], 'L_ADD_ATTACHMENT_TITLE' => $lang['Add_attachment_title'], 'L_POSTED_ATTACHMENTS' => $lang['Posted_attachments'], 'L_FILE_NAME' => $lang['File_name'], 'L_FILE_COMMENT' => $lang['File_comment'], 'RULES' => '<a href="' . append_sid($phpbb_root_path . "attach_rules.{$phpEx}?f={$u_rules_id}") . '" target="_blank">' . $lang['Allowed_extensions_and_sizes'] . '</a>', 'S_HIDDEN' => $s_hidden));
     $attachments = array();
     if (sizeof($this->attachment_list) > 0) {
         if (intval($attach_config['show_apcp'])) {
             $template->assign_block_vars('switch_posted_attachments', array());
         }
         for ($i = 0; $i < sizeof($this->attachment_list); $i++) {
             $hidden = '<input type="hidden" name="attachment_list[]" value="' . $this->attachment_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="filename_list[]" value="' . $this->attachment_filename_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="extension_list[]" value="' . $this->attachment_extension_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="mimetype_list[]" value="' . $this->attachment_mimetype_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="filesize_list[]" value="' . $this->attachment_filesize_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="filetime_list[]" value="' . $this->attachment_filetime_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="attach_id_list[]" value="' . $this->attachment_id_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="attach_thumbnail_list[]" value="' . $this->attachment_thumbnail_list[$i] . '" />';
             if (!$this->posted_attachments_body || sizeof($this->attachment_list) == 0) {
                 $hidden .= '<input type="hidden" name="comment_list[]" value="' . $this->attachment_comment_list[$i] . '" />';
             }
             $template->assign_block_vars('hidden_row', array('S_HIDDEN' => $hidden));
         }
     }
     if ($this->add_attachment_body) {
         init_display_template('attachbody', '{ADD_ATTACHMENT_BODY}', 'add_attachment_body.tpl');
         $form_enctype = 'enctype="multipart/form-data"';
         $template->assign_vars(array('L_ADD_ATTACH_TITLE' => $lang['Add_attachment_title'], 'L_ADD_ATTACH_EXPLAIN' => $lang['Add_attachment_explain'], 'L_ADD_ATTACHMENT' => $lang['Add_attachment'], 'FILE_COMMENT' => $this->file_comment, 'FILESIZE' => $attach_config['max_filesize'], 'FILENAME' => $this->filename, 'S_FORM_ENCTYPE' => $form_enctype));
     }
     if ($this->posted_attachments_body && sizeof($this->attachment_list) > 0) {
         init_display_template('attachbody', '{POSTED_ATTACHMENTS_BODY}', 'posted_attachments_body.tpl');
         $template->assign_vars(array('L_POSTED_ATTACHMENTS' => $lang['Posted_attachments'], 'L_UPDATE_COMMENT' => $lang['Update_comment'], 'L_UPLOAD_NEW_VERSION' => $lang['Upload_new_version'], 'L_DELETE_ATTACHMENT' => $lang['Delete_attachment'], 'L_DELETE_THUMBNAIL' => $lang['Delete_thumbnail'], 'L_OPTIONS' => $lang['Options']));
         for ($i = 0; $i < sizeof($this->attachment_list); $i++) {
             if ($this->attachment_id_list[$i] == 0) {
                 $download_link = $upload_dir . '/' . basename($this->attachment_list[$i]);
             } else {
                 $download_link = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $this->attachment_id_list[$i]);
             }
             $template->assign_block_vars('attach_row', array('FILE_NAME' => $this->attachment_filename_list[$i], 'ATTACH_FILENAME' => $this->attachment_list[$i], 'FILE_COMMENT' => $this->attachment_comment_list[$i], 'ATTACH_ID' => $this->attachment_id_list[$i], 'U_VIEW_ATTACHMENT' => $download_link));
             // Thumbnail there ? And is the User Admin or Mod ? Then present the 'Delete Thumbnail' Button
             if (intval($this->attachment_thumbnail_list[$i]) == 1 && (isset($is_auth['auth_mod']) && $is_auth['auth_mod'] || $userdata['user_level'] == ADMIN)) {
                 $template->assign_block_vars('attach_row.switch_thumbnail', array());
             }
             if ($this->attachment_id_list[$i]) {
                 $template->assign_block_vars('attach_row.switch_update_attachment', array());
             }
         }
     }
     $template->assign_var_from_handle('ATTACHBOX', 'attachbody');
 }
예제 #3
0
/**
* Initializes some templating variables for displaying Attachments in Posts
*/
function init_display_post_attachments($switch_attachment)
{
    global $attach_config, $is_auth, $template, $lang, $postrow, $total_posts, $attachments, $forum_row, $t_data;
    if (empty($t_data) && !empty($forum_row)) {
        $switch_attachment = $forum_row['topic_attachment'];
    }
    if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']) || !($is_auth['auth_download'] && $is_auth['auth_view'])) {
        init_display_template('body', '{postrow.ATTACHMENTS}', 'viewtopic_attach_guest.tpl');
        return;
    }
    $post_id_array = array();
    for ($i = 0; $i < $total_posts; $i++) {
        if ($postrow[$i]['post_attachment'] == 1) {
            $post_id_array[] = (int) $postrow[$i]['post_id'];
        }
    }
    if (sizeof($post_id_array) == 0) {
        return;
    }
    $rows = get_attachments_from_post($post_id_array);
    $num_rows = sizeof($rows);
    if ($num_rows == 0) {
        return;
    }
    @reset($attachments);
    for ($i = 0; $i < $num_rows; $i++) {
        $attachments['_' . $rows[$i]['post_id']][] = $rows[$i];
        //bt
        if ($rows[$i]['tracker_status']) {
            if (defined('TORRENT_POST')) {
                bb_die('Multiple registered torrents in one topic<br /><br />first torrent found in post_id = ' . TORRENT_POST . '<br />current post_id = ' . $rows[$i]['post_id'] . '<br /><br />attachments info:<br /><pre style="text-align: left;">' . print_r($rows, TRUE) . '</pre>');
            }
            define('TORRENT_POST', $rows[$i]['post_id']);
        }
        //bt end
    }
    init_display_template('body', '{postrow.ATTACHMENTS}');
    init_complete_extensions_data();
}
예제 #4
0
function display_attachments_preview($attachment_list)
{
    //atm just return
    return;
    global $attach_config, $is_auth, $allowed_extensions, $lang, $userdata, $display_categories, $upload_dir, $upload_icons, $template, $db, $bgcolor2, $textcolor2;
    if (count($attachment_list) < 1) {
        return;
    }
    init_display_template('preview', '{ATTACHMENTS}');
    init_complete_extensions_data();
    $template->assign_block_vars('postrow', array());
    // Another 'i have to fix minor phpBB2 Bugs...' patch
    $template->assign_vars(array('T_BODY_TEXT' => $textcolor2, 'T_TR_COLOR3' => $bgcolor2));
    $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, $attach_count = count($attachment_list); $i < $attach_count; ++$i) {
        $extension = strtolower(trim($attachment_list[$i]['extension']));
        //
        // Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin
        //
        if (!in_array($extension, $allowed_extensions)) {
            $template->assign_block_vars($blockvar . '.denyrow', array('L_DENIED' => sprintf($lang['Extension_disabled_after_posting'], $extension)));
        } else {
            $filename = $upload_dir . '/' . $attachment_list[$i]['physical_filename'];
            //
            // define category
            //
            $display = 'DEF_CAT';
            if (intval($display_categories[$extension]) == STREAM_CAT) {
                $display = 'STREAM_CAT';
            } else {
                if (intval($display_categories[$extension]) == SWF_CAT) {
                    $display = 'SWF_CAT';
                } else {
                    if (intval($display_categories[$extension]) == IMAGE_CAT && intval($attachment_list[$i]['thumbnail']) == 1) {
                        $display = 'THUMB_CAT';
                    } 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) {
                                    $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';
                            }
                        }
                    }
                }
            }
            $blockname = $blockvar;
            switch ($display) {
                // Macromedia Flash Files
                case 'SWF_CAT':
                    list($width, $height) = swf_getdimension($filename);
                    break;
                    // display attachment
                // display attachment
                default:
                    $upload_image = '';
                    if ($attach_config['upload_img'] != '' && $upload_icons[$extension] == '') {
                        $upload_image = '<img src="' . $attach_config['upload_img'] . '" alt="" />';
                    } else {
                        if (trim($upload_icons[$extension]) != '') {
                            $upload_image = '<img src="' . $upload_icons[$extension] . '" alt="" />';
                        }
                    }
                    break;
            }
            $template->assign_block_vars($blockname, array('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' => $attachment_list[$i]['real_filename'], 'S_UPLOAD_IMAGE' => $upload_image, 'FILESIZE' => filesize_to_human($attachment_list[$i]['filesize']), 'COMMENT' => htmlprepare($attachment_list[$i]['comment'], true), 'L_DOWNLOADED_VIEWED' => $display == 'DEF_CAT' ? $lang['Downloaded'] : $lang['Viewed'], 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_number'], $attachment_list[$i]['download_count']), 'IMG_SRC' => $filename, 'IMG_THUMB_SRC' => '', 'U_DOWNLOAD_LINK' => $filename, 'WIDTH' => isset($width) ? $width : '', 'HEIGHT' => isset($height) ? $height : '', 'TARGET_BLANK' => intval($display_categories[$attachment_list[$i]['extension']]) == IMAGE_CAT || $display == 'DEF_CAT' ? 'target="_blank"' : ''));
        }
    }
}