'Imagecache javascript crop', 'page callback' => 'drupal_get_form', 'page arguments' => array('imagecrop_settings'), 'access arguments' => array('administer imagecrop'), 'file' => 'imagecrop.admin.inc', ); $items['imagecrop/showcrop'] = array( 'page callback' => 'imagecrop_showcrop', 'type' => MENU_CALLBACK, 'access arguments' => array('crop images with toolbox'), 'file' => 'imagecrop.admin.inc', ); $items['imagecrop/docrop'] = array( 'page callback' => 'imagecrop_docrop', 'type' => MENU_CALLBACK, 'access arguments' => array('crop images with toolbox'), 'file' => 'imagecrop.admin.inc', ); return $items; } /** * Implementation of hook_theme(). */ function imagecrop_theme() { return array( 'imagecrop_javascript' => array( 'arguments' => array('element' => NULL), ), 'imagecrop' => array( 'arguments' => array('url' => NULL, 'width' => NULL, 'height' => NULL, 'resize' => NULL), ), 'imagecrop_result' => array( 'arguments' => array('presetname' => NULL, 'filepath' => NULL, 'alt' => NULL, 'attributes' => NULL), ), 'presettabs' => array( 'arguments' => array('presets' => array(), 'fid' => NULL, 'presetid' => NULL, 'module' => NULL, 'field' => NULL, 'node_type' => NULL), ), ); } /** * Implementation of hook_theme_registry_alter(). */ function imagecrop_theme_registry_alter(&$theme_registry) { array_unshift($theme_registry['page']['theme paths'], drupal_get_path('module', 'imagecrop')); } /** * Implementation of hook_imagecrop_popups(). */ function imagecrop_imagecrop_popups() { $popups = array(); if (module_exists('thickbox')) { $popups['imagecrop_thickbox'] = t('Thickbox'); } if (module_exists('modalframe')) { $popups['imagecrop_modalframe'] = t('Modalframe'); } if (module_exists('colorbox')) { $popups['imagecrop_colorbox'] = t('Colorbox'); } if (module_exists('shadowbox')) { $popups['imagecrop_shadowbox'] = t('Shadowbox'); } return $popups; } /** * Implementation of hook_cron(). * Delete all references in imagecrop table when * a) file doesn't exist anymore. * b) when preset has been deleted. * c) when javascrip_crop action is removed from a preset. */ function imagecrop_cron() { // get all files which do not exist anymore from the files table $result = db_query("SELECT ic.fid,ic.presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT fid FROM {files} f WHERE ic.fid = f.fid) AND ic.reference = 'files'"); while ($row = db_fetch_object($result)) { $records[] = array('fid' => $row->fid, 'presetid' => $row->presetid, 'reference' => 'files'); } // get all files which do not exist anymore from the node_images table if (module_exists('node_images')) { $result = db_query("SELECT ic.fid,presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT id FROM {node_images} ni WHERE ic.fid = ni.id) AND ic.reference = 'node_images'"); while ($row = db_fetch_object($result)) { $records[] = array('fid' => $row->fid, 'presetid' => $row->presetid, 'reference' => 'node_images'); } } /* * Get all records * a) from presets which do not exist anymore. * b) and/or from presets with no imagecrop_javascript action anymore. */ // files table $result = db_query("SELECT ic.fid,ic.presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT presetid FROM {imagecache_action} ia where ic.presetid = ia.presetid AND ia.action = 'imagecrop_javascript') AND ic.reference = 'files'"); while ($row = db_fetch_object($result)) { $records[] = array('fid' => $row->fid, 'presetid' => $row->presetid, 'reference' => 'files'); } // node_images table if (module_exists('node_images')) { $result = db_query("SELECT ic.fid,ic.presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT presetid FROM {imagecache_action} ia where ic.presetid = ia.presetid AND ia.action = 'imagecrop_javascript') AND ic.reference = 'node_images'"); while ($row = db_fetch_object($result)) { $records[] = array('fid' => $row->fid, 'presetid' => $row->presetid, 'reference' => 'node_images'); } } if (!empty($records)) { while (list($key, $val) = each($records)) { db_query("DELETE FROM {imagecrop} WHERE fid=%d AND presetid=%d AND reference = '%s'", $val['fid'], $val['presetid'], $val['reference']); } } } /** * Implementation of filefield.module's hook_file_delete(). * * Remove imagecrop settings + temp files after a file has been deleted. */ function imagecrop_file_delete($file) { db_query("DELETE FROM {imagecrop} WHERE fid = %d", $file->fid); file_delete(imagecache_create_path('_imagecrop_temp', $file->filepath)); } /** * Implementation of hook_imagecache_actions(). */ function imagecrop_imagecache_actions() { $actions = array( 'imagecrop_javascript' => array( 'name' => 'Javascript crop', 'description' => 'Create a crop with a javascript toolbox.', 'file' => 'imagecrop_actions.inc', ), ); return $actions; } /** * Implementation of hook_widget_settings_alter(). */ function imagecrop_widget_settings_alter(&$settings, $op, $widget) { // Only support modules that implement hook_insert_widgets(). $widget_type = isset($widget['widget_type']) ? $widget['widget_type'] : $widget['type']; if ($widget_type != 'imagefield_widget' && $widget_type != 'image_fupload_imagefield_widget' && $widget_type != 'linkimagefield_widget') { return; } // Add our new options to the list of settings to be saved. if ($op == 'save') { $settings = array_merge($settings, imagecrop_widget_settings()); } // Add the additional settings to the form. if ($op == 'form') { $settings = array_merge($settings, imagecrop_widget_form($widget)); } } /** * A list of settings needed by Imagecrop module on widgets. */ function imagecrop_widget_settings() { return array( 'imagecrop', 'imagecrop_presets', ); } /** * Configuration form for editing Imagecrop settings for a field instance. */ function imagecrop_widget_form($widget) { $form['imagecrop'] = array( '#type' => 'fieldset', '#title' => t('Imagecrop'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('These options allow the user to alter JavaScript crops for specific ImageCache presets.'), '#weight' => 15, ); $presets = imagecrop_presets_list(); if (count($presets) > 0) { $form['imagecrop']['imagecrop'] = array( '#type' => 'checkbox', '#title' => t('Enable JavaScript crop'), '#default_value' => (bool) $widget['imagecrop'], '#description' => t('Enable JavaScript image crop tool for this widget.'), ); $form['imagecrop']['imagecrop_presets'] = array( '#title' => t('Enabled imagecrop presets'), '#type' => 'checkboxes', '#options' => $presets, '#default_value' => (array) $widget['imagecrop_presets'], '#description' => t('Select which Imagecache presets should be available for cropping. If no presets are selected, the option to crop the image is not displayed.'), ); } else { $form['imagecrop']['imagecrop_warning'] = array( '#value' => t('No preset is found with the javascript_crop action so far. If you want to take advantage of this module, you will need to create at least one preset with that action.'), ); } return $form; } /** * Get a list of styles suitable for an #options array. */ function imagecrop_presets_list() { $presets = array(); foreach (imagecache_presets() as $preset) { foreach ($preset['actions'] as $action) { if ($action['action'] == 'imagecrop_javascript') { $presets[$preset['presetname']] = $preset['presetname']; } } } return $presets; } /** * Implementation of hook_elements(). */ function imagecrop_elements() { // Add our function to the form element declared by imagefield. $elements = array(); $elements['imagefield_widget'] = array('#after_build' => array('imagecrop_process_cck_field')); $elements['image_fupload_imagefield_widget'] = $elements['imagefield_widget']; $elements['linkimagefield_widget'] = $elements['imagefield_widget']; return $elements; } /** * Process function for imagecrop-enabled cck fields. */ function imagecrop_process_cck_field($element) { $field = content_fields($element['#field_name'], $element['#type_name']); // Bail out if user does not have permission to crop images. if (!user_access('crop images with toolbox')) { return $element; } // Bail out of imagecrop is not enabled on this field. if (!$field['widget']['imagecrop']) { return $element; } $imagecache_presets = array_filter((array) $field['widget']['imagecrop_presets']); if (empty($imagecache_presets)) { return $element; } $element['imagecrop'] = array( '#type' => 'markup', '#widget' => $field['widget'], '#weight' => 10, '#suffix' => '', ); if ($element['fid']['#value']) { $element['imagecrop']['#prefix'] = '