Index: profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile.module,v
retrieving revision 1.79
diff -u -r1.79 profile.module
--- profile.module 20 Sep 2004 23:42:11 -0000 1.79
+++ profile.module 4 Oct 2004 06:11:33 -0000
@@ -172,6 +172,11 @@
if ($value = $user->{$field->name}) {
switch ($field->type) {
+ case 'image':
+ $attr = _profile_get_height_width_attributes($value);
+ $output = theme('form_element', t($field->title), $value);
+ $output .= theme_image($value, '', '', $attr, FALSE);
+ return $output;
case 'textfield':
return drupal_specialchars($value);
case 'textarea':
@@ -256,18 +261,30 @@
while ($field = db_fetch_object($result)) {
$category = $field->category;
switch ($field->type) {
+ case 'image': print_r($user->{$field->name});
+ file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
+ $fields[$category] .= '
| ';
+ $fields[$category] .= form_hidden($field->name, $user->{$field->name});
+ $fields[$category] .= theme('form_element', t($field->title), $user->{$field->name});
+ $fields[$category] .= form_file('', $field->name, 40, _profile_form_explanation($field), $field->required);
+ $fields[$category] .= ' | ';
+
+ $attr = _profile_get_height_width_attributes($user->{$field->name});
+ $fields[$category] .= theme_image($user->{$field->name}, '', '', $attr, FALSE);
+ $fields[$category] .= ' |
';
+ break;
case 'textfield':
case 'url':
- $fields[$category] .= form_textfield($field->title, $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textfield(t($field->title), $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
break;
case 'textarea':
- $fields[$category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textarea(t($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
break;
case 'list':
- $fields[$category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textarea(t($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
break;
case 'checkbox':
- $fields[$category] .= form_checkbox($field->title, $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_checkbox(t($field->title), $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
break;
case 'selection':
$options = array('--');
@@ -278,7 +295,7 @@
}
}
- $fields[$category] .= form_select($field->title, $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
+ $fields[$category] .= form_select(t($field->title), $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
break;
case 'date':
$fields[$category] .= _profile_date_field($field, $edit);
@@ -342,16 +359,33 @@
return format_date(gmmktime(0, 0, 0, $month, 2, 1970), 'custom', 'M', 0);
}
-function profile_validate_profile($edit, $category) {
-
+function profile_validate_profile(&$edit, $category) {
+
if (($_GET['q'] == 'user/register') ? 1 : 0) {
$result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
}
else {
$result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
}
-
+ if(!$edit){
+ $edit = array();
+ }
while ($field = db_fetch_object($result)) {
+
+ // handle uploaded images
+ if ($file = file_check_upload($field->name)) {
+ if (in_array($file->filemime, array('image/jpeg', 'image/gif', 'image/png', 'image/bmp'))) {
+ if ($file = file_save_upload($file->source, file_create_path(), 1)) {
+ if(filesize($node->image_path) < 1000){
+ $edit[$field->name] = $file->filepath;
+ }
+ }
+ }
+ else {
+ form_set_error('file_upload', 'Only JPEG, PNG, BMP and GIF images are allowed');
+ }
+ }
+
if ($edit[$field->name]) {
if ($field->type == 'url') {
if (!valid_url($edit[$field->name], true)) {
@@ -573,7 +607,8 @@
'selection' => t('list selection'),
'list' => t('freeform list'),
'url' => t('URL'),
- 'date' => t('date'));
+ 'date' => t('date'),
+ 'image' => t('image'));
return isset($type) ? $types[$type] : $types;
}
@@ -581,4 +616,30 @@
return $type == 'date';
}
-?>
+
+function _profile_get_height_width_attributes($image_path){
+ // I want the image to fit inside a 200x200 square - this is the logic to
+ // get width and height attributes and theme the image
+ if(list($width, $height, $type, $attr) = @getimagesize($image_path)){
+ if($width > 200 || $height > 200){
+ $bigger = $width > $height ? $width : $height;
+ $smaller = $width > $height ? $height : $width;
+ $ratio = 1;
+ if($bigger !== 0){
+ $ratio = 200 / $bigger;
+ }
+ $bigger = 200;
+ $smaller = (int)($ratio * $smaller);
+ if($width > $height){
+ $width = $bigger;
+ $height = $smaller;
+ } elseif ($height > $width){
+ $height = $bigger;
+ $width = $smaller;
+ }
+ }
+ return 'width="'.$width.'" height="'.$height.'"';
+ }
+}
+
+?>
\ No newline at end of file