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 '<br />'; } if ( $t_attachment['can_download'] ) { $t_href_start = "<a href="/" mce_href="/""${t_attachment['download_url']}/">"; $t_href_end = '</a>'; } else { $t_href_start = ''; $t_href_end = ''; } if ( !$t_attachment['exists'] ) { print_file_icon( $t_file_display_name ); echo ' <span class="strike">' . $t_file_display_name . '</span>' . 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' ) . ') ' . '<span class=/"italic/">' . $t_date_added . '</span>'; 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 "<mce:script type=/"text/javascript/"><!-- function swap_content( span ) { displayType = ( document.getElementById( span ).style.display == 'none' ) ? '' : 'none'; document.getElementById( span ).style.display = displayType; } // --></mce:script>"; echo " <span id=/"hideSection_$c_id/">[<a class=/"small/" href="#" mce_href="#" id='attmlink_" . $c_id . "' onclick='swap_content(/"hideSection_" . $c_id . "/");swap_content(/"showSection_" . $c_id . "/");return false;'>" . lang_get( 'show_content' ) . "</a>]</span>"; echo " <span style="display:none" mce_style="display:none" id=/"showSection_$c_id/">[<a class=/"small/" href="#" mce_href="#" id='attmlink_" . $c_id . "' onclick='swap_content(/"hideSection_" . $c_id . "/");swap_content(/"showSection_" . $c_id . "/");return false;'>" . lang_get( 'hide_content' ) . "</a>]"; echo "<pre>"; /** @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 "</pre></span>/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<br />$t_href_start<img alt=/"$t_title/" $t_preview_style src="/" mce_src="/""$t_image_url/" />$t_href_end"; $image_previewed = true; } } if ( $i != ( $t_attachments_count - 1 ) ) { echo "<br />/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 '<br />'; } if ( $t_attachment['can_download'] ) { $t_href_start = "<a href="/" mce_href="/""${t_attachment['download_url']}/">"; $t_href_end = '</a>'; } else { $t_href_start = ''; $t_href_end = ''; } if ( !$t_attachment['exists'] ) { print_file_icon( $t_file_display_name ); echo ' <span class="strike">' . $t_file_display_name . '</span>' . 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' ) . ') ' . '<span class=/"italic/">' . $t_date_added . '</span>'; 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 "<mce:script type=/"text/javascript/"><!-- function swap_content( span ) { displayType = ( document.getElementById( span ).style.display == 'none' ) ? '' : 'none'; document.getElementById( span ).style.display = displayType; } // --></mce:script>"; echo " <span id=/"hideSection_$c_id/">[<a class=/"small/" href="#" mce_href="#" id='attmlink_" . $c_id . "' onclick='swap_content(/"hideSection_" . $c_id . "/");swap_content(/"showSection_" . $c_id . "/");return false;'>" . lang_get( 'show_content' ) . "</a>]</span>"; echo " <span style="display:none" mce_style="display:none" id=/"showSection_$c_id/">[<a class=/"small/" href="#" mce_href="#" id='attmlink_" . $c_id . "' onclick='swap_content(/"hideSection_" . $c_id . "/");swap_content(/"showSection_" . $c_id . "/");return false;'>" . lang_get( 'hide_content' ) . "</a>]"; echo "<pre>"; /** @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 "</pre></span>/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 "<mce:script type=/"text/javascript/"><!-- function show_hide_image( ) { displayType = ( document.getElementById( /"img_prev_area/" ).style.display == 'none' ) ? '' : 'none'; document.getElementById( /"img_prev_area/" ).style.display = displayType; displayType = ( document.getElementById( /"img_prev_ctl_show/" ).style.display == 'none' ) ? '' : 'none'; document.getElementById( /"img_prev_ctl_show/" ).style.display = displayType; displayType = ( document.getElementById( /"img_prev_ctl_hide/" ).style.display == 'none' ) ? '' : 'none'; document.getElementById( /"img_prev_ctl_hide/" ).style.display = displayType; } // --></mce:script>"; echo " [<a class=/"small/" href="#" mce_href="#" onclick='show_hide_image();return false;'><span id=/"img_prev_ctl_show/">" . lang_get( 'show_content' ) . "</span><span style="/" mce_style="/""display:none/" id=/"img_prev_ctl_hide/">" . lang_get( 'hide_content' ) . "</span></a>]"; echo "/n<br /><span id=/"img_prev_area/">$t_href_start<img alt=/"$t_title/" $t_preview_style src="/" mce_src="/""$t_image_url/" />$t_href_end</span>"; $image_previewed = true; } } if ( $i != ( $t_attachments_count - 1 ) ) { echo "<br />/n"; $i++; } } }  

你可能感兴趣的:(mantis附件图片预览)