### Eclipse Workspace Patch 1.0 #P node_images Index: node_images.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_images/node_images.module,v retrieving revision 1.9 diff -u -r1.9 node_images.module --- node_images.module 4 Feb 2007 03:05:44 -0000 1.9 +++ node_images.module 21 Apr 2007 18:32:59 -0000 @@ -36,6 +36,13 @@ 'callback' => '_node_images_js', 'access' => $access, 'type' => MENU_CALLBACK + ); + $items[] = array('path' => 'admin/build/node_images', + 'title' => t('Node images'), + 'description' => t('Resize uploaded node images.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('node_images_form_resize'), + 'access' => $admin ); } else { if (arg(0) == 'node' && is_numeric(arg(1))) { @@ -65,6 +72,56 @@ return $items; } +function node_images_form_resize() { + $form['thumbnails'] = array( + '#type' => 'checkbox', + '#title' => t('Resize thumbnails'), + '#default_value' => 0, + '#description' => t('Check if you want to resize the thumbnails images.'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + return $form; +} + +function node_images_form_resize_validate($form_id, $form_values) { + if (!$form_values['thumbnails']) { + form_set_error('thumbnails', t('Select at least one type for this to do something')); + } +} + +function node_images_form_resize_submit($form_id, $form_values) { + $count = node_images_get_images($form_id, $form_values); + if ($form_values['thumbnails']) { + drupal_set_message(t('You selected to resize thumbnail images. There were '.$count.' images resized')); + } + +} + +function node_images_get_images($form_id, $form_values) { + if (!ini_get('safe_mode')) { + set_time_limit(300); + } + $result = db_query('SELECT * FROM {node_images}'); + while ($images = db_fetch_array($result)){ + $i++; + if (is_file($images['filepath'])) { + if ($form_values['thumbnails'] && is_file($images['thumbpath'])) { + file_delete($images['thumbpath']); + } + if ($form_values['thumbnails']) { + $thumb = _node_images_create_thumbnail($images['filepath']); + $images['thumbsize'] = $thumb->filesize; + $images['thumbpath'] = $thumb->filepath; + } + db_query('UPDATE {node_images} SET mediumpath = "%s", mediumsize = %d, mediumxlpath = "%s", mediumxlsize = %d, thumbpath = "%s", thumbsize = %d WHERE id = %d', $images['mediumpath'], $images['mediumsize'], $images['mediumxlpath'], $images['mediumxlsize'], $images['thumbpath'], $images['thumbsize'], $images['id']); + } + } + return $i; +} + /** * implementation of hook_form_alter() */