Index: node_images.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_images/node_images.module,v retrieving revision 1.5 diff -u -r1.5 node_images.module --- node_images.module 17 Dec 2006 17:24:40 -0000 1.5 +++ node_images.module 7 Jan 2007 13:15:02 -0000 @@ -41,7 +41,7 @@ if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); if ($node->nid && $node->type != 'image') { - if (variable_get('node_images_'. $node->type, 'hide') != 'hide') { + if (variable_get('node_images_position_'.$node->type, 'hide') != 'hide') { $items[] = array( 'path' => 'node/' . arg(1) . '/images', 'title' => t('Images'), @@ -71,16 +71,64 @@ * implementation of hook_form_alter() */ function node_images_form_alter($form_id, &$form) { + $type = $form['#node_type']->type; if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { // radio button in the node's content type configuration page _node_images_check_settings(); - $form['workflow']['node_images'] = array( + $form['node_images'] = array( + '#type' => 'fieldset', + '#title' => t('Node images'), + '#collapsible' => TRUE, + ); + $form['node_images']['node_images_position'] = array( '#type' => 'radios', - '#title' => t('Node images settings'), - '#default_value' => variable_get('node_images_'. $form['identity']['type']['#value'], 'below'), + '#title' => t('Position'), + '#default_value' => variable_get('node_images_position_'.$type, 'below'), '#options' => array('hide' => t('Do not show'), 'above' => t('Show above node body'), 'below' => t('Show below node body'), 'node_template' => t('Manually set in node template by variable $node->node_images')), + '#description' => t('The position of images in the node view.'), + ); + $form['node_images']['node_images_gallery_link'] = array( + '#type' => 'radios', + '#title' => t('Link to image gallery'), + '#default_value' => variable_get('node_images_gallery_link_'.$type, TRUE), + '#options' => array(t('Do not show'), t('Show')), + '#description' => t('Choose whether to show or not the link to the image gallery.'), + ); + $form['node_images']['node_images_teaser_images'] = array( + '#type' => 'textfield', + '#title' => t('Number of images in node teaser'), + '#default_value' => variable_get('node_images_teaser_images_'.$type, 2), + '#size' => 5, + '#maxlength' => 2, + '#description' => t('The maximum number of images to show in the node teaser. 0 will not show images. Leave blank to show all images.'), + ); + $form['node_images']['node_images_body_images'] = array( + '#type' => 'textfield', + '#title' => t('Number of images in node body'), + '#size' => 5, + '#maxlength' => 2, + '#default_value' => variable_get('node_images_body_images_'.$type, NULL), + '#description' => t('The maximum number of images to show in the node body. 0 will not show images. Leave blank to show all images.'), ); + $form['node_images']['node_images_teaser_format'] = array( + '#type' => 'radios', + '#title' => t('Image format in node teaser'), + '#default_value' => variable_get('node_images_teaser_format_'.$type, 'thumbs'), + '#options' => array('thumbs' => t('Thumbnails'), 'fullsize' => t('Full size images')), + '#description' => t('Image format in node teaser.'), + ); + $form['node_images']['node_images_body_format'] = array( + '#type' => 'radios', + '#title' => t('Image format in node body'), + '#default_value' => variable_get('node_images_body_format_'.$type, 'thumbs'), + '#options' => array('thumbs' => t('Thumbnails'), 'fullsize' => t('Full size images')), + '#description' => t('Image format in node body.'), + ); + + $form['submit']['#weight'] = 30; + $form['delete']['#weight'] = 31; + $form['reset']['#weight'] = 32; } } @@ -90,7 +138,7 @@ function node_images_nodeapi(&$node, $op, $teaser, $page) { // test if images are allowed for this node if ($op == 'load' || $op == 'view') { - if (variable_get('node_images_'. $node->type, 'hide') == 'hide') return; + if (variable_get('node_images_position_'.$node->type, 'hide') == 'hide') return; // fire an additional hook for the specific node type // i.e. node images might be a pro feature, so only subscribed users can view them @@ -109,7 +157,7 @@ break; case 'insert': - if (user_access('create node images') && variable_get('node_images_'. $node->type, 'hide') != 'hide') { + if (user_access('create node images') && variable_get('node_images_position_'.$node->type, 'hide') != 'hide') { drupal_set_message(t('Click the !images tab to add images to this node.', array('!images' => l(t('images'), 'node/'.$node->nid.'/images')))); } @@ -139,26 +187,23 @@ $output = theme('node_images_view', $node, $teaser, $page); } $node->node_images = $output; - break; - - case 'alter': - if (!$node->node_images) return; - $position = variable_get('node_images_'.$node->type, 'below'); + $output = '
'.$output.'
'; + $position = variable_get('node_images_position_'.$node->type, 'hide'); switch ($position) { - case 'above': - $node->content['node_images'] = array('#value' => $node->node_images, '#weight' => -1); - break; - case 'node_template': case 'hide': break; + case 'above': + $node->content['node_images'] = array('#value' => $output, '#weight' => -1); + break; + default: - $node->content['node_images'] = array('#value' => $node->node_images, '#weight' => 1); + $node->content['node_images'] = array('#value' => $output, '#weight' => 1); break; } - break; + return $node; } } @@ -168,17 +213,19 @@ function node_images_link($type, $node = null, $teaser = false) { $links = array(); - if ($type == 'node' && $node->nid && variable_get('node_images_'. $node->type, 'hide') != 'hide') { + if ($type == 'node' && $node->nid && variable_get('node_images_position_'.$node->type, 'hide') != 'hide') { if (node_access('update', $node) && user_access('create node images')) { $links['node_images_edit'] = array( 'title' => t('Edit node images'), 'href' => "node/$node->nid/images", ); } - $links['node_images_gallery'] = array( - 'title' => t('Open the image gallery'), - 'href' => "node/$node->nid/image_gallery", - ); + if (count($node->node_images) && variable_get('node_images_gallery_link_'.$node->type, TRUE)) { + $links['node_images_gallery'] = array( + 'title' => t('Open the image gallery'), + 'href' => "node/$node->nid/image_gallery", + ); + } } return $links; @@ -191,7 +238,7 @@ switch ($type) { case 'delete': // Delete image and thumbnail files - $sql = db_query('SELECT filepath, thumbpath FROM {node_images} WHERE uid=%d', $user->nid); + $sql = db_query('SELECT filepath, thumbpath FROM {node_images} WHERE uid=%d', $user->uid); while ($r = db_fetch_object($sql)) { file_delete($r->filepath); file_delete($r->thumbpath); @@ -203,7 +250,7 @@ /** * Implementation of hook_file_download(). - * Find out if an image is accessible when download method is set to private. + * Find out if an image is accessible when download method is set to private */ function node_images_file_download($file) { $path = file_create_path($file); @@ -255,7 +302,7 @@ if (db_num_rows($sql)>0) $output .= drupal_get_form('_node_images_list', $node, $sql); // test if this node can accept new images - // i.e. there might limits to the number of uploaded images for certain node types or user roles + // i.e. there might be limits to the number of uploaded images for certain node types or user roles // if the hook is not present in the node type module, upload is enabled by default $upload = module_invoke($node->type, 'node_images', 'upload', $node); if ($upload !== FALSE) { @@ -445,7 +492,7 @@ $max = variable_get('node_images_max_images', 4); $count = db_num_rows($sql); if ($count>=$max) { - drupal_set_message(t('The selected file %name can not be uploaded, because it exceeded the maximum limit of %max files.', array('%name' => theme('placeholder', $file->filename), '%max' => theme('placeholder', $max))), 'error'); + drupal_set_message(t('The selected file %name can not be uploaded, because it exceeds the maximum limit of %max files.', array('%name' => theme('placeholder', $file->filename), '%max' => theme('placeholder', $max))), 'error'); return FALSE; } @@ -460,6 +507,12 @@ // Save uploaded image $dest = _node_images_get_directory(); + if (variable_get('node_images_md5name', FALSE)) { + // set md5 file name + $extension = substr($file->filename, strrpos($file->filename, '.') + 1); + $file->filename = md5($dest.'/'.$file->filename); + if ($extension) $file->filename .= '.'.$extension; + } if ($file = file_save_upload($file, $dest.'/'.$file->filename)) { $thumb = _node_images_create_thumbnail($file->filepath); $file->filesize = filesize($file->filepath); @@ -478,17 +531,25 @@ ************************************************************/ /** - * Return the first two images associated to a node, add a link to the gallery. + * Show node images in the node view. */ function theme_node_images_view($node, $teaser, $page) { - if (arg(2) == 'image_gallery') return; + if (arg(2) == 'image_gallery' || empty($node->node_images)) return; $output = ''; $i = 0; + + // set maximum number of images for teaser/body + $view = ($teaser ? 'teaser' : 'body'); + $count = variable_get('node_images_'.$view.'_images_'.$node->type, 2); + if (isset($count) && $count === 0) return; + $format = variable_get('node_images_'.$view.'_format_'.$node->type, 'thumbs'); + foreach((array)$node->node_images as $id=>$image) { $description = check_plain($image->description); - $thumb = strtr('%description', - array('%thumbpath'=>file_create_url($image->thumbpath), '%description'=>$description)); + $pattern = '%description'; + $thumb = strtr($pattern, array('%path'=>file_create_url($image->thumbpath), '%description'=>$description)); + $fullsize = strtr($pattern, array('%path'=>file_create_url($image->filepath), '%description'=>$description)); if ($info = getimagesize($image->filepath)) { $width = $info[0] + 36; @@ -499,10 +560,14 @@ $height = 315; } - $i++; - $output .= ''.$thumb.''; - if ($i == 2) break; + if ($format == 'thumbs') { + $output .= ''.$thumb.' '; + } + else { + $output .= $fullsize.' '; + } + if ($count>0 && ++$i >= $count) break; } return $output; } @@ -659,6 +724,12 @@ '#maxlength' => 2, '#description' => t('The maximum number of images a user can upload for each node.'), ); + $form['node_images_md5name'] = array( + '#type' => 'checkbox', + '#title'=> t('MD5 filenames'), + '#description' => t('Override uploaded filenames with the MD5 hash of the file.'), + '#default_value' => variable_get('node_images_md5name', FALSE), + ); return system_settings_form($form); } @@ -672,10 +743,10 @@ function _node_images_check_settings() { // Make sure upload module is enabled if (!module_exists('upload')) { - drupal_set_message(t('upload.module must be enabled'), 'error'); + drupal_set_message(t('node_images.module require upload.module to be enabled.'), 'error'); } - // Sanity check : make sure we've got a working toolkit + // Make sure we've got a working toolkit if (!image_get_toolkit()) { drupal_set_message(t('Make sure you have a working image toolkit installed and enabled, for more information see: %settings', array('%settings' => l(t('the settings page'), 'admin/settings/image-toolkit'))), 'error'); }