<?php
function MYMODULE_luceneapi_result_alter(&$result, $module, $type = NULL) {
// check for node results
if ($type == 'node') {
// check node type
if ($result['node']->type == 'image') {
// define an imagecache image path for image thumbnail
$imagecache_path_thumbnail = file_directory_path() . '/imagecache/thumbnail' . str_replace(file_directory_path(),'',$result['node']->field_image[0]['filepath']);
// define an imagecache image path for image (large)
$imagecache_path_large = file_directory_path() . '/imagecache/large' . str_replace(file_directory_path(),'',$result['node']->field_image[0]['filepath']);
// define theme_image() variables
$alt = check_plain($result['node']->title);
$title = check_plain($result['node']->title);
// add rel=lightbox to enable lightbox2 module
$attributes = array(
'rel' => 'lightbox',
);
// let imagecache define the size
$getsize = FALSE;
// generate the image hml
$image_html = theme('image', $imagecache_path_thumbnail, $alt, $title, $attributes, $getsize);
if ($image_html) {
// define lightbox link
$image_link = l(
$image_html,
$imagecache_path_large,
array(
'html' => true,
'attributes' => array(
'rel' => 'lightbox',
)
)
);
// add data to the result variable, passed by reference
$result['image_thumbnail'] = $image_link;
}
}
}
}
?><?php
function MYTHEME_preprocess_search_result(&$variables) {
// ...snip...
// check for lucene node search results
if ($variables['type']=='luceneapi_node') {
// check for image
if ($variables['result']['image_thumbnail']) {
// pass additional data to theme template file
$variables['image_thumbnail'] = $variables['result']['image_thumbnail'];
}
}
}
?>
<div class="search-result <?php print $search_zebra; ?>">
<?php if($image_thumbnail): ?>
<?php print $image_thumbnail; ?>
<?php endif; ?>
<!-- ...snip... -->
.search-results.luceneapi_node-results .search-result {
clear: both;
}
.search-results.luceneapi_node-results .search-result img {
float: left;
margin: 0px 20px 20px 0px;
}

<?php
// NOTE: this variable is used through the code,
// so I thought it would be better to put it in a constant
define('IMAGE_UPLOAD_CONTAINER', 'image_upload');
/**
* Implements hook_menu()
*/
function helper_menu() {
// create a blank array of menu items
$items = array();
// define page callback for upload form
// NOTE: you'll want to restrict permission better [see: access arguments]
$items['upload'] = array(
'title' => t('Upload'),
'description' => t('Upload'),
'page callback' => 'drupal_get_form',
'page arguments' => array('helper_page_callback_upload_form'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// return menu items
return $items;
}
?><?php
/**
* Implements page callback for upload form
*/
function helper_page_callback_upload_form() {
// create an empty form array
$form = array();
// set the form encoding type
$form['#attributes']['enctype'] = "multipart/form-data";
// add a file upload file
$form[IMAGE_UPLOAD_CONTAINER] = array(
'#type' => 'file',
'#title' => t('Upload an image'),
);
// add a submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
// return form array
return $form;
}
?>
<?php
/**
* Implements form validation handler
*/
function helper_page_callback_upload_form_validate($form, &$form_state) {
// if a file was uploaded, process it.
if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][IMAGE_UPLOAD_CONTAINER])) {
// validate file extension
// NOTE: you can ellaborate on this code and add additional validation
if ($_FILES['files']['type'][IMAGE_UPLOAD_CONTAINER] != 'image/jpeg') {
form_set_error(IMAGE_UPLOAD_CONTAINER, 'Invalid file extension.');
return;
}
// attempt to save the uploaded file
$file = file_save_upload(IMAGE_UPLOAD_CONTAINER, array(), file_directory_path());
// set error if file was not uploaded
if (!$file) {
form_set_error(IMAGE_UPLOAD_CONTAINER, 'Error uploading file.');
return;
}
// set files to form_state, to process when form is submitted
$form_state['storage'][IMAGE_UPLOAD_CONTAINER] = $file;
}
else {
// set error
form_set_error(IMAGE_UPLOAD_CONTAINER, 'Error uploading file.');
return;
}
}
/**
* Implements form submit handler
*/
function helper_page_callback_upload_form_submit($form, &$form_state) {
// create new node object
$new_node = (object) array(
'type' => 'image',
'uid' => $GLOBALS['user']->uid,
'name' => $GLOBALS['user']->name,
'title' => t('YOUR NODE TITLE'),
'status' => 1,
'field_image' => array(
(array) $form_state['storage'][IMAGE_UPLOAD_CONTAINER],
),
);
// save node
node_save($new_node);
// clear form storage, to allow form to submit
$form_state['storage'] = array();
// redirect user, set message, etc!
}
?>
Views
CCK
FileField
ImageField
ImageAPI
ImageCache
<?php
$node = new StdClass();
$node->type = 'MYNODETYPE';
$node->title = 'MYNODETITLE';
$file_temp = file_get_contents($tempFile);
$file_temp = file_save_data($file_temp, file_directory_path() .'/' . $fileName, FILE_EXISTS_RENAME);
$node->field_MYIMAGEFIELD = array(
array(
'fid' => 'upload',
'title' => basename($file_temp),
'filename' => basename($file_temp),
'filepath' => $file_temp,
'filesize' => filesize($file_temp),
'filemime' => mime_content_type($file_temp),
),
);
$node->uid = $GLOBALS['user']->uid;
$node->status = 1;
$node->name = $GLOBALS['user']->name;
// save node
node_save($node);
?>
<?php
function MYMODULE_form_alter($form_id, &$form) {
// ...code...
if ($form_id == 'node_delete_confirm') {
_MYMODULE_form_alter_node_delete_confirm_user_image($form);
}
// ...code...
}
function _MYMODULE_form_alter_node_delete_confirm_user_image(&$form) {
// NOTE: This function assumes the file system path is set to private, which is needs to be for this application
$node = node_load(arg(1));
if ($node->type != 'user_image') return;
$maxDimension = 300;
$imagePath = file_create_path($node->field_user_image[0]['filepath']);
// NOTE: this is a simple function I created that accepts 2 parameters (an image page and a maximum dimension) and it returns resized image dimensions
$imageDimensions = _MYMODULE_images_resize($imagePath, $maxDimension);
// create image html
$img = "<img style='margin: 25px;' width='{$imageDimensions['width']}' height='{$imageDimensions['height']}' src='/system/files/" . $node->field_user_image[0]['filename'] . "' />";
// add image to form
$form['image_preview'] = array(
'#value' => $img,
'#weight' => 10,
);
}
?>