/[drupal]/contributions/modules/flexinode/field_image.inc
ViewVC logotype

Diff of /contributions/modules/flexinode/field_image.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.20.2.1, Fri Feb 2 12:02:21 2007 UTC revision 1.20.2.2, Tue Feb 6 08:08:32 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: field_image.inc,v 1.20 2006/04/26 11:43:34 ber Exp $  // $Id: field_image.inc,v 1.23 2007/01/27 13:43:17 ber Exp $
   
 // FIXME: admin/settings/flexinode is empty. I don't know how to make it dissapear.  
 // We could add here default subforlder where to keep images (e.g. 'images'). Then each image field in  
 // different flexinode types could have it's own image placeholder, you could set it e.g. to images/type1, images/type2 etc.  
   
 // FIXME: when editing (updating, changing) flexinode node flexinode_field_image_insert() is called and thumbnails/previews are generated  
 // even if no new file was uploaded... don't know how to fix that...  
3    
4  function flexinode_field_image_name($field) {  function flexinode_field_image_name($field) {
5    return t('image');    return t('image');
# Line 44  function flexinode_field_image_db_sort_c Line 37  function flexinode_field_image_db_sort_c
37  function flexinode_field_image_insert($field, $node) {  function flexinode_field_image_insert($field, $node) {
38    $fieldname = 'flexinode_'. $field->field_id;    $fieldname = 'flexinode_'. $field->field_id;
39    $node->$fieldname = file_save_upload($node->$fieldname, $node->$fieldname->filename);    $node->$fieldname = file_save_upload($node->$fieldname, $node->$fieldname->filename);
40    $node->$fieldname->smallpath = flexinode_field_image_make_smaller($node->$fieldname->filepath, '_sm', $field->options[2]);    if (is_object($node->$fieldname)) {
41    $node->$fieldname->thumbpath = flexinode_field_image_make_smaller($node->$fieldname->filepath, '_th', $field->options[3]);      $node->$fieldname->smallpath = flexinode_field_image_make_smaller($node->$fieldname->filepath, '_sm', $field->options[2]);
42    $serialized = is_object($node->$fieldname) ? serialize($node->$fieldname) : '';      $node->$fieldname->thumbpath = flexinode_field_image_make_smaller($node->$fieldname->filepath, '_th', $field->options[3]);
43    db_query("INSERT INTO {flexinode_data} (nid, field_id, textual_data, serialized_data) VALUES (%d, %d, '%s', '%s')", $node->nid, $field->field_id, $node->$fieldname->filename, $serialized);      $serialized = serialize($node->$fieldname);
44        db_query("INSERT INTO {flexinode_data} (nid, field_id, textual_data, serialized_data) VALUES (%d, %d, '%s', '%s')", $node->nid, $field->field_id, $node->$fieldname->filename, $serialized);
45      }
46    return $node;    return $node;
47  }  }
48    
# Line 85  function flexinode_field_image_validate( Line 80  function flexinode_field_image_validate(
80        if ((!in_array($size[2], array(1, 2, 3)))) {        if ((!in_array($size[2], array(1, 2, 3)))) {
81          form_set_error($fieldname, t('The uploaded file was not a valid image.'));          form_set_error($fieldname, t('The uploaded file was not a valid image.'));
82        }        }
83        else if (@filesize($file->filepath) > ($field->options[4] * 1000)) {        elseif (@filesize($file->filepath) > ($field->options[4] * 1000)) {
84          form_set_error($fieldname, t('The uploaded image is too large; the maximum file size is %num kB.', array('%num' => $field->options[4])));          form_set_error($fieldname, t('The uploaded image is too large; the maximum file size is %num kB.', array('%num' => $field->options[4])));
85        }        }
86        else if ($size[0] > $maxwidth || $size[1] > $maxheight) {        elseif ($size[0] > $maxwidth || $size[1] > $maxheight) {
87          form_set_error($fieldname, t('The uploaded image is too large; the maximum dimensions are %nxn pixels.', array('%nxn' => $field->options[1])));          form_set_error($fieldname, t('The uploaded image is too large; the maximum dimensions are %nxn pixels.', array('%nxn' => $field->options[1])));
88        }        }
89      }      }
# Line 96  function flexinode_field_image_validate( Line 91  function flexinode_field_image_validate(
91        form_set_error($fieldname, t('The uploaded file was not a valid image.'));        form_set_error($fieldname, t('The uploaded file was not a valid image.'));
92      }      }
93    }    }
94    elseif(!empty($node->$fieldname)) {    elseif (!empty($node->$fieldname)) {
95      form_set_error($fieldname, t('The image upload was not successful.'));      form_set_error($fieldname, t('The image upload was not successful.'));
96    }    }
97  }  }
# Line 142  function flexinode_field_image_config($f Line 137  function flexinode_field_image_config($f
137      );      );
138    }    }
139    
140    $form['tester'] = array(    $form['options'] = array(
141      '#type' => 'fieldset',      '#type' => 'fieldset',
142      '#title' => t('Options'),      '#title' => t('Options'),
143      '#description' => t('Options for the image upload.'),      '#description' => t('Options for the image upload.'),
144        '#tree' => TRUE,
145    );    );
146    $form['tester'][] = array('options][1' => array(    $form['options'][1] = array(
147      '#type' => 'textfield',      '#type' => 'textfield',
148      '#title' => t('Maximum picture dimensions'),      '#title' => t('Maximum picture dimensions'),
149      '#default_value' => $field->options[1],      '#default_value' => $field->options[1],
150      '#description' => t('Maximum dimensions for pictures. Format: WidthxHeight'),      '#description' => t('Maximum dimensions for pictures. Format: WidthxHeight'),
151      ));      '#required' => TRUE,
152    $form['tester'][] = array('options][2' => array(      );
153      $form['options'][2] = array(
154      '#type' => 'textfield',      '#type' => 'textfield',
155      '#title' => t('Preview dimensions'),      '#title' => t('Preview dimensions'),
156      '#default_value' => $field->options[2],      '#default_value' => $field->options[2],
157      '#description' => t('Dimensions for auto-created preview (scale will be preserved). Format: WidthxHeight'),      '#description' => t('Dimensions for auto-created preview (scale will be preserved). Format: WidthxHeight'),
158      ));      '#required' => TRUE,
159    $form['tester'][] = array('options][3' => array(      );
160      $form['options'][3] = array(
161      '#type' => 'textfield',      '#type' => 'textfield',
162      '#title' => t('Thumbnail dimensions'),      '#title' => t('Thumbnail dimensions'),
163      '#default_value' => $field->options[3],      '#default_value' => $field->options[3],
164      '#description' => t('Dimensions for auto-created thumbnail (scale will be preserved). Format: WidthxHeight'),      '#description' => t('Dimensions for auto-created thumbnail (scale will be preserved). Format: WidthxHeight'),
165      ));      '#required' => TRUE,
166    $form['tester'][] = array('options][4' => array(      );
167      $form['options'][4] = array(
168      '#type' => 'textfield',      '#type' => 'textfield',
169      '#title' => t('Maximum picture size'),      '#title' => t('Maximum picture size'),
170      '#default_value' => $field->options[4],      '#default_value' => $field->options[4],
171      '#description' => t('Maximum picture file size, in kB.'),      '#description' => t('Maximum picture file size, in kB.'),
172      ));      '#required' => TRUE,
173        );
174    
175    return $form;    return $form;
176  }  }

Legend:
Removed from v.1.20.2.1  
changed lines
  Added in v.1.20.2.2

  ViewVC Help
Powered by ViewVC 1.1.2