/[drupal]/contributions/modules/thickbox/thickbox.module
ViewVC logotype

Contents of /contributions/modules/thickbox/thickbox.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.18 - (show annotations) (download) (as text)
Fri May 2 15:43:05 2008 UTC (18 months, 3 weeks ago) by frjo
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.17: +109 -69 lines
File MIME type: text/x-php
First commit for Drupal 6. Thanks to patches from Greg Hines and btsukuda.
1 <?php
2 // $Id: thickbox.module,v 1.17 2007/06/21 02:10:53 frjo Exp $
3
4 /**
5 * @file
6 * Author: Fredrik Jonsson fredrik at combonet dot se
7 * The thickbox module is a simple wrapper for the jquery plugin
8 * ThickBox http://jquery.com/demo/thickbox/.
9 */
10
11 /**
12 * Implementation of hook_theme().
13 */
14 function thickbox_theme() {
15 return array(
16 'imagefield_image_imagecache_thickbox' => array(
17 'arguments' => array('namespace' => NULL, 'field' => NULL, 'path' => NULL, 'alt' => NULL, 'title' => NULL, 'gid' => NULL, 'attributes' => NULL),
18 ),
19 );
20 }
21
22 /**
23 * Menu callback; presents the thickbox settings page.
24 */
25 function thickbox_admin_settings() {
26 if (module_exists('image')) {
27 $form['thickbox_imagemodule'] = array(
28 '#type' => 'fieldset',
29 '#title' => t('Image module options')
30 );
31 $form['thickbox_imagemodule']['thickbox_auto'] = array(
32 '#type' => 'checkbox',
33 '#title' => t('Enable for image nodes'),
34 '#default_value' => variable_get('thickbox_auto', 0),
35 '#description' => t('Automatically activate Thickbox for all image nodes (requires the image module).'),
36 );
37 $options = array();
38 $sizes = image_get_sizes();
39 foreach ($sizes as $label => $size) {
40 $options[$label] = $size['label'];
41 }
42 $form['thickbox_imagemodule']['thickbox_derivative'] = array(
43 '#type' => 'select',
44 '#title' => t('Image derivative'),
45 '#options' => $options,
46 '#default_value' => variable_get('thickbox_derivative', 'preview'),
47 '#description' => t('Select which image derivative will be loaded.'),
48 );
49 }
50
51 if (module_exists('imagefield')) {
52 $form['thickbox_imagefield'] = array(
53 '#type' => 'fieldset',
54 '#title' => t('Image field options (CCK)')
55 );
56 $form['thickbox_imagefield']['thickbox_imagefield_gallery'] = array(
57 '#type' => 'radios',
58 '#title' => t('Image field gallery'),
59 '#default_value' => variable_get('thickbox_imagefield_gallery', 0),
60 '#options' => array(0 => t('Per page gallery'), 1 => t('Per post gallery')),
61 '#description' => t('Should the gallery be images within a single post or all images on the page.'),
62 );
63 }
64
65 $form['thickbox_options'] = array(
66 '#type' => 'fieldset',
67 '#title' => t('General options')
68 );
69 $form['thickbox_options']['thickbox_login'] = array(
70 '#type' => 'checkbox',
71 '#title' => t('Enable for login links'),
72 '#default_value' => variable_get('thickbox_login', 0),
73 '#description' => t('Automatically activate Thickbox for links to user/login.'),
74 );
75 $form['thickbox_options']['thickbox_pages'] = array(
76 '#type' => 'textarea',
77 '#title' => t('Deactivate Thickbox on specific pages'),
78 '#default_value' => variable_get('thickbox_pages', "admin*\nimg_assist*\nnode/add/*\nnode/*/edit"),
79 '#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' => '<front>')),
80 );
81
82 return system_settings_form($form);
83 }
84
85 /**
86 * Implementation of hook_init().
87 */
88 function thickbox_init() {
89 // Code from the block_list funtion in block.module.
90 // If the path doesn't match any of the exeptions, load header files.
91 $path = drupal_get_path_alias($_GET['q']);
92 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get('thickbox_pages', ''), '/')) .')$/';
93 // Compare with the internal and path alias (if any).
94 $page_match = preg_match($regexp, $path);
95 if ($path != $_GET['q']) {
96 $page_match = $page_match || preg_match($regexp, $_GET['q']);
97 }
98 if (!$page_match) {
99 _thickbox_doheader();
100 }
101 }
102
103 /**
104 * Implementation of hook_menu().
105 */
106 function thickbox_menu() {
107 global $user;
108
109 $items = array();
110
111 $items['admin/settings/thickbox'] = array(
112 'title' => 'Thickbox',
113 'description' => 'Configure Thickbox behavior.',
114 'page callback' => 'drupal_get_form',
115 'page arguments' => array('thickbox_admin_settings'),
116 'access callback' => 'user_access',
117 'access arguments' => array('administer site configuration'),
118 'type' => MENU_NORMAL_ITEM,
119 );
120 $items['thickbox_login'] = array(
121 'title' => 'Login',
122 'page callback' => 'thickbox_login',
123 'access callback' => 'thickbox_login_user_access',
124 'access arguments' => array($user->uid),
125 'type' => MENU_CALLBACK,
126 );
127
128 return $items;
129 }
130
131 /**
132 * Menu callback for thickbox_login_user_access.
133 */
134 function thickbox_login_user_access($uid) {
135 return ($uid == 0) ? TRUE : FALSE;
136 }
137
138 /**
139 * Menu callback for thickbox_login.
140 */
141 function thickbox_login() {
142 print drupal_get_form('user_login');
143 exit;
144 }
145
146 /**
147 * Loads the various js and css files.
148 */
149 function _thickbox_doheader() {
150 $path = drupal_get_path('module', 'thickbox');
151 drupal_add_css($path .'/thickbox.css');
152
153 // Insert translated strings as javascript settings.
154 $tb_msg = array(
155 'close' => t('Close'),
156 'next' => t('Next >'),
157 'prev' => t('< Prev'),
158 'esc_key' => t('or Esc Key'),
159 'next_close' => t('Next / Close on last'),
160 'image_count' => t('Image !current of !total')
161 );
162 drupal_add_js(array('thickbox' => $tb_msg), 'setting');
163
164 global $user;
165 if ($user->uid == 0 && variable_get('thickbox_login', 0)) {
166 drupal_add_js($path .'/thickbox_login.js');
167 }
168
169 if (variable_get('thickbox_auto', 0) && module_exists('image')) {
170 drupal_add_js("var thickbox_derivative = ". drupal_to_js(variable_get('thickbox_derivative', 'preview')) .";", 'inline');
171 drupal_add_js($path .'/thickbox_auto.js');
172 }
173
174 drupal_add_js($path .'/thickbox.js');
175 }
176
177 /**
178 * Implementation of hook_form_alter().
179 * Reformat the login form.
180 */
181 function thickbox_form_alter(&$form, $form_state, $form_id) {
182 if ($form_id == 'user_login' && arg(0) == 'thickbox_login') {
183 $form['#action'] = url('user/login', array('query' => array('destination' => $_GET['destination'])));
184 $form['name']['#size'] = 25;
185 $form['pass']['#size'] = 25;
186 }
187 }
188
189 /**
190 * Implementation of hook_field_formatter_info().
191 * Adds certain thickbox+imagecache formatters to CCK image fields if imagefield.module and imagecache.module exist.
192 */
193 function thickbox_field_formatter_info() {
194 $formatter = array();
195 if (module_exists('imagefield') && module_exists('imagecache')) {
196 $rules = imagecache_presets();
197 foreach ($rules as $ruleid => $rulename) {
198 $formatters['thickbox]['. $rulename] = array(
199 'label' => 'Thickbox: '. $rulename,
200 'field types' => array('image'),
201 );
202 }
203 }
204
205 return $formatters;
206 }
207
208 /**
209 * Implementation of hook_field_formatter().
210 */
211 function thickbox_field_formatter($field, $item, $formatter, $node = NULL) {
212 if (module_exists('imagefield') && module_exists('imagecache') && !empty($item['fid'])) {
213 $file = _imagefield_file_load($item['fid']);
214 if (strpos($formatter, 'thickbox][') !== FALSE) {
215 list($null, $namespace) = explode('][', $formatter, 2);
216 $gallery_id = variable_get('thickbox_imagefield_gallery', 0) == 0 ? $field['type_name'] : $item['nid'];
217 $rules = array();
218 $rules = imagecache_presets();
219 if (in_array($namespace, $rules)) {
220 return theme('imagefield_image_imagecache_thickbox', $namespace, $field, $file['filepath'], $item['alt'], $item['title'], $gallery_id);
221 }
222 }
223 }
224 }
225
226 /**
227 * Implementation of theme_imagefield_image_imagecache_thickbox().
228 */
229 function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title = '', $gid = '', $attributes = NULL) {
230 if (!empty($path)) {
231 $attributes = drupal_attributes($attributes);
232 $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
233 $image = '<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" '. $attributes .' />';
234
235 return l($image, file_create_url($path), array('html' => TRUE, 'attributes' => array('title' => $title, 'class' => 'thickbox', 'rel' => 'gallery-'. $gid)));
236 }
237 }

  ViewVC Help
Powered by ViewVC 1.1.2