field_id;
$output = '';
if ($node->$fieldname) {
$output .= form_hidden($fieldname .'_old', serialize($node->$fieldname));
}
$output .= form_file(t($field->label), $fieldname, 40, ($node->$fieldname ? t('"%filename" has been uploaded. If you upload another file, the current file will be replaced.', array('%filename' => $node->$fieldname->filename)) : '') .' '. t($field->description) .' '. t('The file is limited to %kbKB and a resolution of %wxh pixels (width x height).', array('%wxh' => $field->options[1], '%kb' => $field->options[2])), $field->required);
return $output;
}
function flexinode_field_image_db_select($field) {
$fieldname = 'flexinode_'. $field->field_id;
return $fieldname .'.serialized_data AS '. $fieldname;
}
function flexinode_field_image_db_sort_column($field) {
return 'flexinode_'. $field->field_id .'.textual_data';
}
function flexinode_field_image_insert($field, $node) {
$fieldname = 'flexinode_'. $field->field_id;
$node->$fieldname = file_save_upload($node->$fieldname, $node->$fieldname->filename);
$serialized = is_object($node->$fieldname) ? serialize($node->$fieldname) : '';
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);
return $node;
}
function flexinode_field_image_delete($field, $node, $unconditional = 0) {
$fieldname = 'flexinode_'. $field->field_id;
$result = db_fetch_object(db_query('SELECT serialized_data FROM {flexinode_data} WHERE nid = %d AND field_id = %d', $node->nid, $field->field_id));
$file = unserialize($result->serialized_data);
if ($unconditional || $node->$fieldname != $file) {
file_delete($file->filepath);
}
}
function flexinode_field_image_validate($field, $node) {
$fieldname = 'flexinode_'. $field->field_id;
$file = flexinode_validate_picture($field, $node);
if (is_string($file)) {
return array('value' => $node->$fieldname, 'error' => $file);
}
else if (is_object($file)) {
return array('value' => $file);
}
else if (empty($node->$fieldname)) {
return array('value' => unserialize($node->{$fieldname .'_old'}));
}
}
function flexinode_field_image_format($field, $node, $brief = 0) {
$fieldname = 'flexinode_'. $field->field_id;
$file = is_object($node->$fieldname) ? $node->$fieldname : unserialize($node->$fieldname);
if ($file) {
if ($brief) {
return ''. check_plain($file->filename) .' ('. format_size($file->filesize) .')';
}
else {
return '';
}
}
}
function flexinode_field_image_load($field, $node) {
$fieldname = 'flexinode_'. $field->field_id;
return unserialize($node->$fieldname);
}
function flexinode_field_image_config($field, $edit) {
if (!isset($edit['options'])) {
$edit['options'][1] = '400x300';
$edit['options'][2] = 100;
}
$output = form_textfield(t('Maximum picture dimensions'), 'options][', $edit['options'][1], 60, 128, t('Maximum dimensions for pictures. Format: widthxheight'));
$output .= form_textfield(t('Maximum picture size'), 'options][', $edit['options'][2], 60, 128, t('Maximum picture file size, in kB.'));
return form_group(t('Options'), $output, t('Options for the image upload.'));
}
function flexinode_field_image_settings() {
$group = form_textfield(t('Default thumbnail resolution'), 'flexinode_thumb_size', variable_get('flexinode_thumb_size', '100'), 10, 255, t('Default size of thumbnails: format will be the same as original image. Use just one dimension, and put a "x" to specify height. Examples: "100" for width of 100; "x200" for height of 200.'));
$group .= form_textfield(t('Imagemagick Convert path'), 'flexinode_convert_path', variable_get('flexinode_convert_path', '/usr/local/bin/convert'), 50, 255, t('Absolute path to ImageMagick convert executable. Include the filename at the end.'));
return form_group(t('Image processing'), $group);
}
/**
* @addtogroup themeable
* @{
*/
/**
* Format an image for display in a node.
*
* @param field_id
* Which field is being displayed (useful when overriding this function
* if you want to style one particular field differently).
* @param label
* The label for the field as displayed on the node form.
* @param file
* The file that the user has uploaded. This is an object as provided
* by file.inc.
* @param formatted_value
* The image as an HTML tag.
*/
function theme_flexinode_image($field_id, $label, $file, $formatted_value) {
$output = theme('form_element', $label, $formatted_value);
$output = '