'fieldset', '#title' => t('Thickbox options') ); $form['thickbox_options']['thickbox_auto'] = array( '#type' => 'checkbox', '#title' => t('Enable for image nodes'), '#default_value' => variable_get('thickbox_auto', 0), '#description' => t('Automatically activate Thickbox for all image nodes (requires the image module).'), ); if (module_exists('image')) { $options = array(); $sizes = image_get_sizes(); foreach ($sizes as $label => $size) { $options[$label] = $size['label']; } $form['thickbox_options']['thickbox_derivative'] = array( '#type' => 'select', '#title' => t('Image derivative'), '#options' => $options, '#default_value' => variable_get('thickbox_derivative', 'preview'), '#description' => t('Select which image derivative will be loaded.'), ); } $form['thickbox_options']['thickbox_login'] = array( '#type' => 'checkbox', '#title' => t('Enable for login links'), '#default_value' => variable_get('thickbox_login', 0), '#description' => t('Automatically activate Thickbox for links to user/login.'), ); $form['thickbox_options']['thickbox_pages'] = array( '#type' => 'textarea', '#title' => t('Deactivate Thickbox on specific pages'), '#default_value' => variable_get('thickbox_pages', "admin*\nimg_assist*\nnode/add/*\nnode/*/edit"), '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), ); return system_settings_form($form); } /** * Implementation of hook_menu(). */ function thickbox_menu($may_cache) { global $user; $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/settings/thickbox', 'title' => t('Thickbox'), 'description' => t('Configure Thickbox behavior.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'thickbox_admin_settings', 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM ); $items[] = array( 'path' => 'thickbox_login', 'title' => t('Login'), 'callback' => 'thickbox_login', 'access' => !$user->uid, 'type' => MENU_CALLBACK ); } else { // Code from the block_list funtion in block.module. // If the path doesn't match any of the exeptions, load header files. $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get('thickbox_pages', ''), '/')) .')$/'; // Compare with the internal and path alias (if any). $page_match = preg_match($regexp, $path); if ($path != $_GET['q']) { $page_match = $page_match || preg_match($regexp, $_GET['q']); } if (!$page_match) { _thickbox_doheader(); } } return $items; } /** * Menu callback for thickbox_login. */ function thickbox_login() { print drupal_get_form('user_login'); exit; } /** * Loads the various js and css files. */ function _thickbox_doheader() { $path = drupal_get_path('module', 'thickbox'); drupal_add_css($path .'/thickbox.css'); // Insert translated strings as javascript settings. $tb_msg = array( 'close' => t('Close'), 'next' => t('Next >'), 'prev' => t('< Prev'), 'esc_key' => t('or Esc Key'), 'next_close' => t('Next / Close on last'), 'image_count' => t('Image !current of !total') ); drupal_add_js(array('thickbox' => $tb_msg), 'setting'); global $user; if ($user->uid == 0 && variable_get('thickbox_login', 0)) { drupal_add_js($path .'/thickbox_login.js'); } if (variable_get('thickbox_auto', 0) && module_exists('image')) { drupal_add_js("var thickbox_derivative = ". drupal_to_js(variable_get('thickbox_derivative', 'preview')) .";", 'inline'); drupal_add_js($path .'/thickbox_auto.js'); } drupal_add_js($path .'/thickbox.js'); } /** * Implementation of hook_form_alter(). * Reformat the login form. */ function thickbox_form_alter($form_id, &$form) { if ($form_id == 'user_login' && arg(0) == 'thickbox_login') { $form['#action'] = url('user/login', 'destination='. $_GET['destination']); $form['name']['#size'] = 25; $form['pass']['#size'] = 25; } } /** * Implementation of hook_field_formatter_info(). * Adds certain thickbox+imagecache formatters to CCK image fields if imagefield.module and imagecache.module exist. */ function thickbox_field_formatter_info() { $formatter = array(); if (module_exists('imagefield') && module_exists('imagecache')) { $rules = _imagecache_get_presets(); foreach ($rules as $ruleid => $rulename) { $formatters['thickbox]['. $rulename] = array( 'label' => 'Thickbox: '. $rulename, 'field types' => array('image'), ); } } return $formatters; } /** * Implementation of hook_field_formatter(). */ function thickbox_field_formatter($field, $item, $formatter) { if (module_exists('imagefield') && module_exists('imagecache') && !empty($item['fid'])) { $file = _imagefield_file_load($item['fid']); if (strpos($formatter, 'thickbox][') !== false) { list($null, $namespace) = explode('][', $formatter, 2); $rules = _imagecache_get_presets(); if (in_array($namespace, (array) $rules)) { return theme('imagefield_image_imagecache_thickbox', $namespace, $field, $file['filepath'], $item['alt'], $item['title']); } } } } /** * Implementation of theme_imagefield_image_imagecache_thickbox(). */ function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title = '', $attributes = NULL) { if (!empty($path)) { $attributes = drupal_attributes($attributes); $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path); $image = ''. check_plain($alt) .''; return l($image, file_create_url($path), array('title' => $title, 'class' => 'thickbox', 'rel' => $field['type_name']), NULL, NULL, FALSE, TRUE); } }