Skip to content

Commit

Permalink
New API functions to print maximum file size
Browse files Browse the repository at this point in the history
- get_filesize_info() returns the file size in the desired unit
- print_max_filesize() prints the span tag with maximum file size in
  desired unit, including tooltip in bytes

Updated language strings, refactored code to use the new functions

Issue #16970
  • Loading branch information
dregad committed Feb 14, 2014
1 parent e1d4aa5 commit cfb212e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
5 changes: 3 additions & 2 deletions bug_file_upload_inc.php
Expand Up @@ -69,8 +69,9 @@
</tr>
<tr class="row-1">
<td class="category" width="15%">
<?php echo lang_get( $t_file_upload_max_num == 1 ? 'select_file' : 'select_files' ) ?><br />
<span class="small"><?php echo lang_get( 'max_file_size_label' ) . lang_get( 'word_separator' ) . number_format( $t_max_file_size/1000 ) . lang_get( 'word_separator' ) . lang_get( 'file_kb' ) ?></span>
<?php echo lang_get( $t_file_upload_max_num == 1 ? 'select_file' : 'select_files' ) ?>
<br />
<?php echo print_max_filesize( $t_max_file_size ); ?>
</td>
<td width="85%">
<input type="hidden" name="bug_id" value="<?php echo $f_bug_id ?>" />
Expand Down
5 changes: 3 additions & 2 deletions bug_report_page.php
Expand Up @@ -597,8 +597,9 @@
?>
<tr>
<th class="category">
<label for="file"><?php echo lang_get( $t_file_upload_max_num == 1 ? 'upload_file' : 'upload_files' ) ?></label><br />
<span class="small"><?php echo lang_get( 'max_file_size_label' ) . lang_get( 'word_separator' ) . number_format( $t_max_file_size/1000 ) . lang_get( 'word_separator' ) . lang_get( 'file_kb' ) ?></span>
<label for="file"><?php echo lang_get( $t_file_upload_max_num == 1 ? 'upload_file' : 'upload_files' ) ?></label>
<br />
<?php echo print_max_filesize( $t_max_file_size ); ?>
</th>
<td>
<input type="hidden" name="max_file_size" value="<?php echo $t_max_file_size ?>" />
Expand Down
24 changes: 24 additions & 0 deletions core/print_api.php
Expand Up @@ -1866,3 +1866,27 @@ function print_timezone_option_list( $p_timezone ) {
echo "\t</optgroup>\n";
}
}

/**
* Return file size information
* @param int $p_size
* @param string $p_unit
* @return string
*/
function get_filesize_info( $p_size, $p_unit ) {
return sprintf( lang_get( 'file_size_info' ), number_format( $p_size ), $p_unit );
}

/**
* Print maximum file size information
* @param int $p_size in bytes
* @param int $p_divider optional divider, defaults to 1000
* @param string $p_unit optional language string of unit, defaults to KB
*/
function print_max_filesize( $p_size, $p_divider = 1000, $p_unit = 'kb' ) {
echo '<span class="small" title="' . get_filesize_info( $p_size, lang_get( 'bytes' ) ) . '">';
echo lang_get( 'max_file_size_label' )
. lang_get( 'word_separator' )
. get_filesize_info( $p_size / $p_divider, lang_get( $p_unit ) );
echo '</span>';
}
4 changes: 2 additions & 2 deletions lang/strings_english.txt
Expand Up @@ -489,9 +489,8 @@ $s_select_file = 'Select File';
$s_select_files = 'Select Files';
$s_upload_file_button = 'Upload File';
$s_upload_files_button = 'Upload Files';
$s_max_file_size = 'Maximum size';
$s_max_file_size_label = 'Maximum size:';
$s_file_kb = 'KiB';
$s_file_size_info = '%1$s %2$s'; # $1 = size, $2 = unit (e.g. kb, bytes)

# bug_reopen.php
$s_bug_reopened_msg = 'Issue has been reopened...';
Expand Down Expand Up @@ -1304,6 +1303,7 @@ $s_monitored_by = 'Monitored By';
$s_monitored_by_label = 'Monitored By:';
$s_attachments = 'attachment(s)';
$s_bytes = 'bytes';
$s_kb = 'KB';
$s_attachment_missing = 'Attachment missing';
$s_attachment_count = 'Attachment count';
$s_view_attachments_for_issue = 'View %1$d attachment(s) for issue #%2$d';
Expand Down
1 change: 1 addition & 0 deletions lang/strings_qqq.txt
Expand Up @@ -71,6 +71,7 @@ $s_add_new_relationship_button = '{{Identical|Add}}';
$s_on = 'Switch confition (for filter, for example)';
$s_off = 'Switch condition (for filter, for example)';
$s_show_all_tags = '{{Identical|All}}';
$s_file_size_info = 'Displays file size information, where $1 is the size and $2 is the unit';


$MANTIS_ERROR[ERROR_PLUGIN_GENERIC] = 'If we need to specify the number of expected parameter in string, we just need to write something like "Lalal %2$s bububu %1$d", where 1 and 2 - the index number in argument list (actually, expected in original message)';
5 changes: 3 additions & 2 deletions proj_doc_add_page.php
Expand Up @@ -86,8 +86,9 @@
</tr>
<tr class="row-1">
<td class="category">
<span class="required">*</span><?php echo lang_get( 'select_file' ); ?><br />
<span class="small"><?php echo lang_get( 'max_file_size_label' ) . lang_get( 'word_separator' ) . number_format( $t_max_file_size/1000 ) . lang_get( 'word_separator' ) . lang_get( 'file_kb' ) ?></span>
<span class="required">*</span><?php echo lang_get( 'select_file' ); ?>
<br />
<?php echo print_max_filesize( $t_max_file_size ); ?>
</td>
<td>
<input type="hidden" name="max_file_size" value="<?php echo $t_max_file_size ?>" />
Expand Down
5 changes: 3 additions & 2 deletions proj_doc_edit_page.php
Expand Up @@ -124,8 +124,9 @@
</tr>
<tr class="row-2">
<td class="category">
<?php echo lang_get( 'select_file' ); ?><br />
<span class="small"><?php echo lang_get( 'max_file_size_label' ) . lang_get( 'word_separator' ) . number_format( $t_max_file_size/1000 ) . lang_get( 'word_separator' ) . lang_get( 'file_kb' ) ?></span>
<?php echo lang_get( 'select_file' ); ?>
<br />
<?php echo print_max_filesize( $t_max_file_size ); ?>
</td>
<td>
<input type="hidden" name="max_file_size" value="<?php echo $t_max_file_size ?>" />
Expand Down

2 comments on commit cfb212e

@atrol
Copy link
Member

@atrol atrol commented on cfb212e Feb 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo print_max_filesize

should be replaced 3 times by

print_max_filesize

as print_max_filesize does not return any value and the echoing is already done by the function.

@dregad
Copy link
Member Author

@dregad dregad commented on cfb212e Feb 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch thanks, I'll fix it.

Please sign in to comment.