Skip to content
Browse files

New API functions to print maximum file size

- 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...
1 parent e1d4aa5 commit cfb212ed780a0ec8e282698fc149dde23095359d @dregad dregad committed Feb 14, 2014
Showing with 39 additions and 10 deletions.
  1. +3 −2 bug_file_upload_inc.php
  2. +3 −2 bug_report_page.php
  3. +24 −0 core/print_api.php
  4. +2 −2 lang/strings_english.txt
  5. +1 −0 lang/strings_qqq.txt
  6. +3 −2 proj_doc_add_page.php
  7. +3 −2 proj_doc_edit_page.php
View
5 bug_file_upload_inc.php
@@ -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 ?>" />
View
5 bug_report_page.php
@@ -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 ?>" />
View
24 core/print_api.php
@@ -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>';
+}
View
4 lang/strings_english.txt
@@ -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...';
@@ -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';
View
1 lang/strings_qqq.txt
@@ -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)';
View
5 proj_doc_add_page.php
@@ -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 ?>" />
View
5 proj_doc_edit_page.php
@@ -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 ?>" />

2 comments on commit cfb212e

@atrol
Mantis Bug Tracker member
atrol commented on cfb212e Feb 27, 2014
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
Mantis Bug Tracker member
dregad commented on cfb212e Feb 27, 2014

Good catch thanks, I'll fix it.

Please sign in to comment.
Something went wrong with that request. Please try again.