array( 'arguments' => array('namespace' => NULL, 'field' => NULL, 'path' => NULL, 'alt' => NULL, 'title' => NULL, 'gid' => NULL, 'attributes' => NULL), ), ); if (module_exists('imagecache')) { foreach (imagecache_presets() as $preset) { $theme['thickbox_formatter_'. $preset['presetname'] .'][thickbox'] = array( 'function' => 'theme_thickbox_formatter', 'arguments' => array('element' => NULL), ); } } return $theme; } /** * Implementation of hook_init(). */ function thickbox_init() { // 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(); } } /** * Implementation of hook_menu(). */ function thickbox_menu() { $items = array(); $items['admin/settings/thickbox'] = array( 'title' => 'Thickbox', 'description' => 'Allows the user to configure the Thickbox settings.', 'file' => 'thickbox.admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('thickbox_admin_settings'), 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); $items['user/login/thickbox'] = array( 'title' => 'Login', 'page callback' => 'thickbox_login', 'access callback' => 'user_is_anonymous', 'type' => MENU_CALLBACK, ); 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() { global $user; $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'); 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(array('thickbox' => array('derivative' => variable_get('thickbox_derivative', 'preview'))), 'setting'); 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, $form_state, $form_id) { if ($form_id == 'user_login' && arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'thickbox') { $form['#action'] = url('user/login', array('query' => array('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() { $formatters = array(); if (module_exists('imagefield') && module_exists('imagecache')) { foreach (imagecache_presets() as $preset) { $formatters[$preset['presetname'] .'][thickbox'] = array( 'label' => t('Thickbox: @preset image', array('@preset' => $preset['presetname'])), 'field types' => array('image', 'filefield'), ); } } return $formatters; } function theme_thickbox_formatter($element) { if (isset($element['#item']['nid']) && $node = node_load($element['#item']['nid'])) { return thickbox_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], $node); } } /** * Implementation of hook_field_formatter(). */ function thickbox_field_formatter($field, $item, $formatter, $node) { if (module_exists('imagefield') && module_exists('imagecache') && !empty($item['fid'])) { if (is_string($item['data'])) { $item['data'] = unserialize($item['data']); } if (!isset($item['filepath'])) { $file = field_file_load($item['fid']); $item['filepath'] = $file['filepath']; } // If the title is empty use description, alt or the node title in that order. if (empty($item['data']['title'])) { if (!empty($item['data']['description'])) { $item['data']['title'] = $item['data']['description']; } else if (!empty($item['data']['alt'])) { $item['data']['title'] = $item['data']['alt']; } else { $item['data']['title'] = $node->title; } } // Build the gallery id. $nid = $item['nid'] ? $item['nid'] : ($node->nid ? $node->nid : ''); switch (variable_get('thickbox_imagefield_gallery', 1)) { case 0: $gallery_id = 'all'; break; case 1: $gallery_id = $nid; break; case 2: $gallery_id = $nid .'-'. $field; break; case 3: $gallery_id = $nid .'-'. $item['fid']; break; } list($namespace, $presetname) = explode('][', $formatter, 2); if ($preset = imagecache_preset_by_name($namespace)) { return theme('imagefield_image_imagecache_thickbox', $namespace, $field, $item['filepath'], $item['data']['alt'], $item['data']['title'], $gallery_id); } } } /** * Implementation of theme_imagefield_image_imagecache_thickbox(). */ function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title = '', $gid = '', $attributes = NULL) { if (!empty($path)) { $attributes = drupal_attributes($attributes); $imagecache_path = imagecache_create_url($namespace, $path); $image = ''. check_plain($alt) .''; if ($presetname = variable_get('thickbox_imagecache_preset', 0)) { $link_path = imagecache_create_url($presetname, $path); } else { $link_path = file_create_url($path); } return l($image, $link_path, array('html' => TRUE, 'attributes' => array('title' => $title, 'class' => 'thickbox', 'rel' => 'gallery-'. $gid))); } }