`
kfgon38u
  • 浏览: 14500 次
社区版块
存档分类
最新评论

mantis附件图片预览

阅读更多

  mantis在bug详情查看页面里,可以查看bug关联的附件。如果附件类型是文本或者图片时可以提供预览。print_api.php的下面这个函数就是输入附件内容的。 # List the attachments belonging to the specified bug. This is used from within # bug_view_page.php function print_bug_attachments_list( $p_bug_id ) { $t_attachments = file_get_visible_attachments( $p_bug_id ); $t_attachments_count = count( $t_attachments ); $i = 0; $image_previewed = false; foreach ( $t_attachments as $t_attachment ) { $t_file_display_name = string_display_line( $t_attachment['display_name'] ); $t_filesize = number_format( $t_attachment['size'] ); $t_date_added = date( config_get( 'normal_date_format' ), $t_attachment['date_added'] ); if ( $image_previewed ) { $image_previewed = false; echo '
'; } if ( $t_attachment['can_download'] ) { $t_href_start = ""; $t_href_end = ''; } else { $t_href_start = ''; $t_href_end = ''; } if ( !$t_attachment['exists'] ) { print_file_icon( $t_file_display_name ); echo ' ' . $t_file_display_name . '' . lang_get( 'word_separator' ) . '(' . lang_get( 'attachment_missing' ) . ')'; } else { echo $t_href_start; print_file_icon( $t_file_display_name ); echo $t_href_end . ' ' . $t_href_start . $t_file_display_name . $t_href_end . ' (' . $t_filesize . ' ' . lang_get( 'bytes' ) . ') ' . '' . $t_date_added . ''; if ( $t_attachment['can_delete'] ) { echo ' ['; print_link( 'bug_file_delete.php?file_id=' . $t_attachment['id'] . form_security_param( 'bug_file_delete' ), lang_get( 'delete_link' ), false, 'small' ); echo ']'; } if ( ( FTP == config_get( 'file_upload_method' ) ) && $t_attachment['exists'] ) { echo ' (' . lang_get( 'cached' ) . ')'; } if ( $t_attachment['preview'] && ( $t_attachment['type'] == 'text' ) ) { $c_id = db_prepare_int( $t_attachment['id'] ); $t_bug_file_table = db_get_table( 'bug_file' ); echo ""; echo " [" . lang_get( 'show_content' ) . "]"; echo " [" . lang_get( 'hide_content' ) . "]"; echo ""; /** @todo Refactor into a method that gets contents for download / preview. */ switch( config_get( 'file_upload_method' ) ) { case DISK: if ( $t_attachment['exists'] ) { $v_content = file_get_contents( $t_attachment['diskfile'] ); } break; case FTP: if( file_exists( $t_attachment['exists'] ) ) { file_get_contents( $t_attachment['diskfile'] ); } else { $ftp = file_ftp_connect(); file_ftp_get( $ftp, $t_attachment['diskfile'], $t_attachment['diskfile'] ); file_ftp_disconnect( $ftp ); $v_content = file_get_contents( $t_attachment['diskfile'] ); } break; default: $query = "SELECT * FROM $t_bug_file_table WHERE id=" . db_param(); $result = db_query_bound( $query, Array( $c_id ) ); $row = db_fetch_array( $result ); $v_content = $row['content']; } echo htmlspecialchars( $v_content ); echo "\n"; } if ( $t_attachment['can_download'] && $t_attachment['preview'] && $t_attachment['type'] == 'image' ) { $t_preview_style = 'border: 0;'; $t_max_width = config_get( 'preview_max_width' ); if( $t_max_width > 0 ) { $t_preview_style .= ' max-width:' . $t_max_width . 'px;'; } $t_max_height = config_get( 'preview_max_height' ); if( $t_max_height > 0 ) { $t_preview_style .= ' max-height:' . $t_max_height . 'px;'; } $t_preview_style = 'style="' . $t_preview_style . '"'; $t_title = file_get_field( $t_attachment['id'], 'title' ); $t_image_url = $t_attachment['download_url'] . '&show_inline=1' . form_security_param( 'file_show_inline' ); echo "\n
$t_href_start$t_href_end"; $image_previewed = true; } } if ( $i != ( $t_attachments_count - 1 ) ) { echo "
\n"; $i++; } } }   对上面的函数稍作修改,添加一个可显示或隐藏图片预览区域的按钮。下面代码中调用了lang_get('hide_content')
  需要在lang目录下相应语言文件里面加入$s_hide_content变量 # List the attachments belonging to the specified bug. This is used from within # bug_view_page.php function print_bug_attachments_list( $p_bug_id ) { $t_attachments = file_get_visible_attachments( $p_bug_id ); $t_attachments_count = count( $t_attachments ); $i = 0; $image_previewed = false; foreach ( $t_attachments as $t_attachment ) { $t_file_display_name = string_display_line( $t_attachment['display_name'] ); $t_filesize = number_format( $t_attachment['size'] ); $t_date_added = date( config_get( 'normal_date_format' ), $t_attachment['date_added'] ); if ( $image_previewed ) { $image_previewed = false; echo '
'; } if ( $t_attachment['can_download'] ) { $t_href_start = ""; $t_href_end = ''; } else { $t_href_start = ''; $t_href_end = ''; } if ( !$t_attachment['exists'] ) { print_file_icon( $t_file_display_name ); echo ' ' . $t_file_display_name . '' . lang_get( 'word_separator' ) . '(' . lang_get( 'attachment_missing' ) . ')'; } else { echo $t_href_start; print_file_icon( $t_file_display_name ); echo $t_href_end . ' ' . $t_href_start . $t_file_display_name . $t_href_end . ' (' . $t_filesize . ' ' . lang_get( 'bytes' ) . ') ' . '' . $t_date_added . ''; if ( $t_attachment['can_delete'] ) { echo ' ['; print_link( 'bug_file_delete.php?file_id=' . $t_attachment['id'] . form_security_param( 'bug_file_delete' ), lang_get( 'delete_link' ), false, 'small' ); echo ']'; } if ( ( FTP == config_get( 'file_upload_method' ) ) && $t_attachment['exists'] ) { echo ' (' . lang_get( 'cached' ) . ')'; } if ( $t_attachment['preview'] && ( $t_attachment['type'] == 'text' ) ) { $c_id = db_prepare_int( $t_attachment['id'] ); $t_bug_file_table = db_get_table( 'bug_file' ); echo ""; echo " [" . lang_get( 'show_content' ) . "]"; echo " [" . lang_get( 'hide_content' ) . "]"; echo ""; /** @todo Refactor into a method that gets contents for download / preview. */ switch( config_get( 'file_upload_method' ) ) { case DISK: if ( $t_attachment['exists'] ) { $v_content = file_get_contents( $t_attachment['diskfile'] ); } break; case FTP: if( file_exists( $t_attachment['exists'] ) ) { file_get_contents( $t_attachment['diskfile'] ); } else { $ftp = file_ftp_connect(); file_ftp_get( $ftp, $t_attachment['diskfile'], $t_attachment['diskfile'] ); file_ftp_disconnect( $ftp ); $v_content = file_get_contents( $t_attachment['diskfile'] ); } break; default: $query = "SELECT * FROM $t_bug_file_table WHERE id=" . db_param(); $result = db_query_bound( $query, Array( $c_id ) ); $row = db_fetch_array( $result ); $v_content = $row['content']; } echo htmlspecialchars( $v_content ); echo "\n"; } if ( $t_attachment['can_download'] && $t_attachment['preview'] && $t_attachment['type'] == 'image' ) { $t_preview_style = 'border: 0;'; $t_max_width = config_get( 'preview_max_width' ); if( $t_max_width > 0 ) { $t_preview_style .= ' max-width:' . $t_max_width . 'px;'; } $t_max_height = config_get( 'preview_max_height' ); if( $t_max_height > 0 ) { $t_preview_style .= ' max-height:' . $t_max_height . 'px;'; } $t_preview_style = 'style="' . $t_preview_style . '"'; $t_title = file_get_field( $t_attachment['id'], 'title' ); $t_image_url = $t_attachment['download_url'] . '&show_inline=1' . form_security_param( 'file_show_inline' ); echo ""; echo " [" . lang_get( 'show_content' ) . "" . lang_get( 'hide_content' ) . "]"; echo "\n
$t_href_start$t_href_end"; $image_previewed = true; } } if ( $i != ( $t_attachments_count - 1 ) ) { echo "
\n"; $i++; } } }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics