'Imagecache javascript crop', 'page callback' => 'drupal_get_form', 'page arguments' => array('imagecrop_settings'), 'access arguments' => array('administer imagecrop'), ); $items['imagecrop/showcrop'] = array( 'page callback' => 'imagecrop_showcrop', 'type' => MENU_CALLBACK, 'access arguments' => array('crop images with toolbox'), ); $items['imagecrop/docrop'] = array( 'page callback' => 'imagecrop_docrop', 'type' => MENU_CALLBACK, 'access arguments' => array('crop images with toolbox'), ); 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; } /** * Imagecrop settings page */ function imagecrop_settings() { // hook into image module if (module_exists('image')) { $options_modules['image'] = t('Hook into image module'); } // hook into node_images module if (module_exists('node_images')) { $result = db_query("SELECT name,value FROM {variable} WHERE name LIKE 'node_images_position_%'"); if ($result) { drupal_set_message(t('When you want to enable support for the node_images module, please read the README that comes with the imagecrop module.')); while ($row = db_fetch_object($result)) { if (variable_get($row->name, 'hide') != 'hide') { $explode = explode('_', $row->name); $options_modules[$row->name] = t('Hook into node_images module for content type @type', array('@type' => $explode[3])); } } } } // show checkboxes if options are not empty if (!empty($options_modules)) { $form['imagecrop_modules'] = array( '#type' => 'checkboxes', '#title' => t('Hook into modules'), '#default_value' => variable_get('imagecrop_modules', array()), '#options' => $options_modules, ); $form['array_filter'] = array('#type' => 'hidden'); } else { $form['no_modules_fields'] = array( '#type' => 'item', '#value' => t('No supported modules were found to hook into.'), ); } if (module_exists('imagefield')) { $form['imagefield'] = array( '#type' => 'item', '#value' => t('Imagecrop settings for CCK Imagefields are found on the field configuration pages.'), ); } $all_popups = array('basic' => t('Basic popup window')); foreach (module_implements('imagecrop_popups') as $module_name) { $function = $module_name .'_imagecrop_popups'; $popups = $function(); if (is_array($popups)) { $all_popups += $popups; } } $form['imagecrop_popup'] = array( '#type' => 'radios', '#title' => t('Popup window type'), '#default_value' => variable_get('imagecrop_popup', 'basic'), '#options' => $all_popups, ); $form['imagecrop_popup_width'] = array( '#type' => 'textfield', '#title' => t('Popup window width'), '#default_value' => variable_get('imagecrop_popup_width', 700), '#size' => 4, '#field_suffix' => 'pixels', ); $form['imagecrop_popup_height'] = array( '#type' => 'textfield', '#title' => t('Popup window height'), '#default_value' => variable_get('imagecrop_popup_height', 600), '#size' => 4, '#field_suffix' => 'pixels', ); $form['imagecrop_scale_step'] = array( '#type' => 'textfield', '#title' => t('Step size for scale dropdown'), '#default_value' => variable_get('imagecrop_scale_step', 50), '#size' => 4, '#field_suffix' => 'pixels', ); // drupal message if no action is found with javascript_crop if (count(imagecrop_presets_list()) == 0) { drupal_set_message(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 system_settings_form($form); } /** * 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 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') { 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. // TODO: Do the same thing for the image and node_images modules. $elements = array(); $elements['imagefield_widget'] = array('#after_build' => array('imagecrop_process')); return $elements; } /** * Process function for imagecrop-enabled fields. */ function imagecrop_process($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'] = '
', '#suffix' => ' | ', ); $form['scaling'] = array( '#type' => 'select', '#options' => $options, '#default_value' => $scale, '#prefix' => '', '#suffix' => ' |