From 39e79f97178c74591b84d6cbe952f7a182d19abe Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 Nov 2010 11:59:03 +0100 Subject: [PATCH] Simple local avatar feature --- account_prefs_inc.php | 3 ++ avatar_file_add.php | 67 ++++++++++++++++++++++++++++++++++ avatar_file_delete.php | 77 +++++++++++++++++++++++++++++++++++++++ avatar_file_upload_inc.php | 85 ++++++++++++++++++++++++++++++++++++++++++++ config_defaults_inc.php | 22 +++++++++++ file_download.php | 47 ++++++++++++------------ 6 files changed, 277 insertions(+), 24 deletions(-) create mode 100644 avatar_file_add.php create mode 100644 avatar_file_delete.php create mode 100644 avatar_file_upload_inc.php diff --git a/account_prefs_inc.php b/account_prefs_inc.php index 36b9b33..47adf0f 100644 --- a/account_prefs_inc.php +++ b/account_prefs_inc.php @@ -186,6 +186,9 @@ + + +
diff --git a/avatar_file_add.php b/avatar_file_add.php new file mode 100644 index 0000000..736d227 --- /dev/null +++ b/avatar_file_add.php @@ -0,0 +1,67 @@ +. + + /** + * Add the image file to b used as avatar + * + * @package MantisBT + * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org + * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + /** + * MantisBT Core API's + */ + require_once( 'core.php' ); + + require_once( 'file_api.php' ); + + $f_avatar_id = gpc_get_int ( 'avatar_id', -1 ); + $f_file = gpc_get_file( 'file' , -1 ); + + if ( $f_avatar_id == -1 && $f_file == -1 ) { + # _POST/_FILES does not seem to get populated if you exceed size limit so check if avatar_id is -1 + trigger_error( ERROR_FILE_TOO_BIG, ERROR ); + } + + form_security_validate( 'avatar_file_add' ); + + if ( !file_is_uploading_enabled() ) { + access_denied(); + } + + access_ensure_global_level( config_get( 'upload_avatar_file_threshold' ) ); + + file_add( $f_avatar_id, $f_file, 'avatar' ); + + form_security_purge( 'avatar_file_add' ); + + # Determine which view page to redirect back to. + $t_redirect_url = 'account_prefs_page.php'; + + html_page_top( null, $t_redirect_url ); + +?> +
+
+'; + print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) ); +?> +
+ +. + + /** + * Delete a file from a bug and then view the bug + * + * @package MantisBT + * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org + * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + /** + * MantisBT Core API's + */ + require_once( 'core.php' ); + + require_once( 'file_api.php' ); + + /** + * Get array of attachments associated with the specified avatar id. The array will be + * sorted in terms of date added (ASC). The array will include the following fields: + * id, title, diskfile, filename, filesize, file_type, date_added. For now one user has + * only one avatar which has his avatar_id set equal to user_id. + * @param int p_avatar_id integer representing avatar id + * @return array array of results or null + * @access public + * @uses database_api.php + * @uses file_api.php + */ + function get_avatar ( $p_avatar_id ) { + $c_avatar_id = db_prepare_int( $p_avatar_id ); + + $t_avatar_file_table = db_get_table( 'mantis_avatar_file_table' ); + + $query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added + FROM $t_avatar_file_table + WHERE avatar_id=" . db_param() . " + ORDER BY date_added"; + $db_result = db_query_bound( $query, Array( $c_avatar_id ) ); + $num_files = db_num_rows( $db_result ); + + $t_result = array(); + + for( $i = 0;$i < $num_files;$i++ ) { + $t_result[] = db_fetch_array( $db_result ); + } + + return $t_result; + } + + form_security_validate( 'avatar_file_delete' ); + + $f_avatar_id = gpc_get_int( 'avatar_id' ); + $f_file_id = get_avatar ( $f_avatar_id ); + + access_ensure_global_level( config_get( 'update_avatar_threshold' ) ); + + helper_ensure_confirmed( lang_get( 'delete_attachment_sure_msg' ), lang_get( 'delete_attachment_button' ) ); + + file_delete( $f_file_id[0]['id'], 'avatar' ); + + form_security_purge( 'avatar_file_delete' ); + + print_header_redirect( 'account_prefs_page.php' ); diff --git a/avatar_file_upload_inc.php b/avatar_file_upload_inc.php new file mode 100644 index 0000000..0b80285 --- /dev/null +++ b/avatar_file_upload_inc.php @@ -0,0 +1,85 @@ +. + + /** + * This include file prints out the avatar file upload form + * It POSTs to avatar_file_add.php + * @package MantisBT + * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org + * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + + require_once( 'file_api.php' ); + + # check if we can allow the upload... bail out if we can't + if ( !file_is_uploading_enabled() ) { + return false; + } + + $t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) ); +?> +
+ + +
+ + + + + + + + + +
+ +
+
+ (' . lang_get( 'max_file_size' ) . ': ' . number_format( $t_max_file_size/1000 ) . 'k)'?> +
+ + + + + +
+
+ + + + + +
+ +
+ +