colorbox.module 21.5 KB
Newer Older
jdwfly's avatar
jdwfly committed
1
<?php
2

jdwfly's avatar
jdwfly committed
3
4
5
6
/**
 * @file
 * A light-weight, customizable lightbox plugin for jQuery 1.3
 */
7
8
9
10
11

/**
 * The default path to the Colorbox directory.
 */
define('COLORBOX_PATH', 'sites/all/libraries/colorbox');
12
define('COLORBOX_MIN_PLUGIN_VERSION', '1.3.16');
13
14
15


/**
16
 * Implements hook_theme().
17
18
 */
function colorbox_theme() {
19
  return array(
20
    'colorbox_imagefield' => array(
21
      'variables' => array(
22
        'image' => array(),
23
24
25
26
        'path' => NULL,
        'title' => NULL,
        'gid' => NULL,
      ),
27
28
29
      'file' => 'colorbox.theme.inc',
    ),

30
31
32
33
34
35
36
37
38
    'colorbox_insert_image' => array(
      'variables' => array(
        'item' => NULL,
        'widget' => NULL,
      ),
      'template' => 'colorbox-insert-image',
      'file' => 'colorbox.theme.inc',
    ),

39
40
41
    'colorbox_image_formatter' => array(
      'variables' => array(
        'item' => NULL,
42
43
44
        'entity_type' => NULL,
        'entity' => NULL,
        'node' => NULL,  // Left for legacy support.
45
        'field' => array(),
46
        'display_settings' => array(),
47
48
49
50
      ),
      'file' => 'colorbox.theme.inc',
    ),
  );
51
52
53
}

/**
54
 * Implements hook_init().
55
56
 */
function colorbox_init() {
57
58
59
60
61
  // Do not load colorbox during the Drupal installation process, e.g. if part
  // of installation profiles.
  if (!drupal_installation_attempted()) {
    _colorbox_doheader();
  }
62
63
}

64
/**
65
 * Implements hook_views_api().
66
67
68
69
 */
function colorbox_views_api() {
  return array(
    'api' => 2,
70
    'path' => drupal_get_path('module', 'colorbox') . '/views',
71
72
73
  );
}

74
/**
75
 * Implements hook_menu().
76
 */
77
function colorbox_menu() {
78
79
  $items = array();

80
  $items['admin/config/media/colorbox'] = array(
81
    'title' => 'Colorbox',
82
    'description' => 'Adjust Colorbox settings.',
83
    'file' => 'colorbox.admin.inc',
84
85
86
87
    'page callback' => 'drupal_get_form',
    'page arguments' => array('colorbox_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );
88
89
90
91
92
  $items['user/login/colorbox'] = array(
    'title' => 'Login',
    'page callback' => 'colorbox_login',
    'access callback' => 'user_is_anonymous',
    'type' => MENU_CALLBACK,
93
    'file' => 'colorbox.pages.inc',
94
95
96
  );
  $items['colorbox/form'] = array(
    'title' => 'Form',
97
    'page callback' => 'colorbox_form_page',
98
    'page arguments' => array(2),
99
100
    'access callback' => '_colorbox_form_page_access',
    'access arguments' => array(2),
101
    'type' => MENU_CALLBACK,
102
    'file' => 'colorbox.pages.inc',
103
104
  );

105
106
107
  return $items;
}

108
/**
109
 * Colorbox menu access check.
110
 */
111
function _colorbox_form_page_access($form_id) {
112
113
114
  $access = FALSE;

  // First check if this is one of the forms Colorbox support out of the box.
115
  switch ($form_id) {
116
    case 'contact_site_form':
117
118
      $access = user_access('access site-wide contact form');
      break;
119
    case 'user_register_form':
120
121
122
123
124
125
126
      $access = user_register_access();
      break;
    case 'user_pass':
    case 'user_login':
    case 'user_login_block':
      $access = user_is_anonymous();
      break;
127
128
129
130
131
132
133
134
135
  }

  // Invoke hook_colorbox_form_access for all modules.
  if (!$access) {
    foreach (module_implements('colorbox_form_access') as $module) {
      if ($access = module_invoke($module, 'colorbox_form_access', $form_id)) {
        return $access;
      }
    }
136
  }
137
138

  return $access;
139
140
141
142
143
144
145
146
147
}

/**
 * Check if Colorbox should be active for the current URL.
 *
 * @return
 *   TRUE if Colorbox should be active for the current page.
 */
function _colorbox_active() {
148
149
150
151
152
153
  // Make it possible deactivate Colorbox with
  // parameter ?colorbox=no in the url.
  if (isset($_GET['colorbox']) && $_GET['colorbox'] == 'no') {
    return FALSE;
  }

154
155
  // Code from the block_list funtion in block.module.
  $path = drupal_get_path_alias($_GET['q']);
156
  $colorbox_pages = variable_get('colorbox_pages', "admin*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit");
157
  // Compare with the internal and path alias (if any).
158
  $page_match = drupal_match_path($path, $colorbox_pages);
159
  if ($path != $_GET['q']) {
160
    $page_match = $page_match || drupal_match_path($_GET['q'], $colorbox_pages);
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  }

  return !$page_match;
}

/**
 * Loads the various js and css files.
 */
function _colorbox_doheader() {
  static $already_added = FALSE;
  if ($already_added) {
    return; // Don't add the JavaScript and CSS multiple times.
  }
  if (!_colorbox_active()) {
    return; // Don't add the JavaScript and CSS on specified paths.
  }

  // Insert options and translated strings as javascript settings.
  if (variable_get('colorbox_custom_settings_activate', 0)) {
    $js_settings = array(
      'transition' => variable_get('colorbox_transition_type', 'elastic'),
      'speed' => variable_get('colorbox_transition_speed', 350),
183
      'opacity' => variable_get('colorbox_opacity', '0.85'),
184
      'slideshow' => variable_get('colorbox_slideshow', 0) ? TRUE : FALSE,
185
186
187
188
      'slideshowAuto' => variable_get('colorbox_slideshowauto', 1) ? TRUE : FALSE,
      'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
      'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
      'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
189
190
191
192
      'current' => variable_get('colorbox_text_current', '{current} of {total}'),
      'previous' => variable_get('colorbox_text_previous', '« Prev'),
      'next' => variable_get('colorbox_text_next', 'Next »'),
      'close' => variable_get('colorbox_text_close', 'Close'),
193
194
195
      'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
      'maxWidth' => variable_get('colorbox_maxwidth', '100%'),
      'maxHeight' => variable_get('colorbox_maxheight', '100%'),
196
197
198
      'initialWidth' => variable_get('colorbox_initialwidth', '300'),
      'initialHeight' => variable_get('colorbox_initialheight', '100'),
      'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
199
      'scrolling' => variable_get('colorbox_scrolling', 1) ? TRUE : FALSE,
200
201
202
203
    );
  }
  else {
    $js_settings = array(
204
      'opacity' => '0.85',
205
206
207
208
      'current' => t('{current} of {total}'),
      'previous' => t('« Prev'),
      'next' => t('Next »'),
      'close' => t('Close'),
209
210
      'maxWidth' => '100%',
      'maxHeight' => '100%',
211
      'fixed' => TRUE,
212
    );
213
  }
214
215
216
217

  $path = drupal_get_path('module', 'colorbox');
  $style = variable_get('colorbox_style', 'default');

218
  // Give other modules the possibility to override Colorbox settings and style.
219
220
221
222
  $data = &$js_settings;
  $data['__drupal_alter_by_ref'] = array(&$style);
  drupal_alter('colorbox_settings', $data);

223
  drupal_add_js(array('colorbox' => $js_settings), array('type' => 'setting', 'scope' => JS_DEFAULT));
224

225
226
227
228
229
  if (module_exists('image') && variable_get('colorbox_auto_image_nodes', 0)) {
    $image_derivative = variable_get('colorbox_image_derivative', 'preview');
    // If the image derivative is set to IMAGE_ORIGINAL check if the
    // user has access before activating Colorbox.
    if (!($image_derivative == IMAGE_ORIGINAL && !user_access('view original images'))) {
230
231
      drupal_add_js(array('colorbox' => array('image_derivative' => $image_derivative)), array('type' => 'setting', 'scope' => JS_DEFAULT));
      drupal_add_js($path . '/js/colorbox_image_module.js');
232
233
234
    }
  }

235
  // Add and initialise the Colorbox plugin.
236
  drupal_add_js(colorbox_get_js());
237
  drupal_add_js($path . '/js/colorbox.js');
238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
  // Add JS and CSS based on selected style.
  switch ($style) {
    case 'none':
      break;
    case 'default':
      drupal_add_css($path . '/styles/default/colorbox_default_style.css');
      drupal_add_js($path . '/styles/default/colorbox_default_style.js');
      break;
    case 'stockholmsyndrome':
      drupal_add_css($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css');
      drupal_add_js($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.js');
      break;
    default:
      drupal_add_css($style . '/colorbox.css');
253
254
  }

255
  if (variable_get('colorbox_load', 0)) {
256
    drupal_add_js($path . '/js/colorbox_load.js');
257
258
  }

259
260
261
262
  if (variable_get('colorbox_inline', 0)) {
    drupal_add_js($path . '/js/colorbox_inline.js');
  }

263
  if ($GLOBALS['user']->uid == 0 && variable_get('colorbox_login', 0)) {
264
    drupal_add_js($path . '/js/colorbox_login.js');
265
266
267
  }

  $already_added = TRUE;
268
269
}

270
271
272
273
274
275
/**
 * Return the version of Colorbox plugin that is installed.
 *
 * This can be used by other modules' hook_requirements() to ensure that the
 * proper version of Colorbox plugin is installed.
 *
276
 * @see version_compare()
277
 */
278
function colorbox_get_version($colorbox_js = NULL) {
279
280
281
282
  $version = 0;
  $pattern = '#ColorBox v([0-9\.a-z]+)#';

  // No file is passed in so use the default location.
283
284
  if (is_null($colorbox_js)) {
    $colorbox_js = colorbox_get_js();
285
286
  }

287
288
289
290
291
292
  // Return the version of Colorbox plugin, it it exists.
  if (file_exists($colorbox_js)) {
    $colorbox_plugin = file_get_contents($colorbox_js, NULL, NULL, 0, 32);
    if (preg_match($pattern, $colorbox_plugin, $matches)) {
      $version = $matches[1];
    }
293
294
295
296
297
  }

  return $version;
}

298
299
300
301
302
303
304
305
306
/**
 * Return the JS filename for Colorbox plugin.
 *
 * @return
 *   Boolean indicating if the JS is located.
 */
function colorbox_get_js() {
  $library_path = colorbox_get_path();

307
  if (file_exists($library_path . '/colorbox/jquery.colorbox.js') && file_exists($library_path . '/colorbox/jquery.colorbox-min.js')) {
308
309
    $colorbox_js_map = array('none' => 'jquery.colorbox.js', 'min' => 'jquery.colorbox-min.js');
    $colorbox_js = $colorbox_js_map[variable_get('colorbox_compression_type', 'min')];
310
    return $library_path . '/colorbox/' . $colorbox_js;
311
  }
312
313
314
315
//   else {
//     drupal_set_message(t('You need to download the !colorbox and extract the entire contents of the archive into the %path folder of your server.', array('!colorbox' => l(t('Colorbox plugin'), 'http://colorpowered.com/colorbox/'), '%path' => $library_path)), 'error', FALSE);
//     return FALSE;
//   }
316
317
}

318
319
320
321
/**
 * Return the path to the Colorbox plugin.
 */
function colorbox_get_path() {
322
323
324
325
326
327
  static $library_path = NULL;

  // Try to locate the library path in any possible setup.
  if ($library_path == NULL) {
    // First check the default location.
    $path = variable_get('colorbox_path', COLORBOX_PATH);
328
    if (is_dir($path . '/colorbox')) {
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
      $library_path = $path;
    }
    // Ask the libraries module as a fallback.
    elseif ($library_path == NULL && module_exists('libraries')) {
      if ($path = libraries_get_path('colorbox')) {
        $library_path = $path;
        variable_set('colorbox_path', $library_path);
      }
    }
    // HACK: If libraries api module is not installed but available, load it.
    elseif ($library_path == NULL && file_exists(dirname(__FILE__) . '/../libraries/libraries.module')) {
      require_once(dirname(__FILE__) . '/../libraries/libraries.module');
      if ($path = libraries_get_path('colorbox')) {
        $library_path = $path;
        variable_set('colorbox_path', $library_path);
      }
    }
    // If no path is found suggest the default one.
    elseif ($library_path == NULL) {
      $library_path = COLORBOX_PATH;
    }
  }

  return $library_path;
353
354
}

355
/**
356
 * Implements hook_form_alter().
357
358
 * Reformat the login form.
 */
359
function colorbox_form_alter(&$form, &$form_state, $form_id) {
360
361
362
363
  switch ($form_id) {
    case 'user_login':
      if (arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'colorbox') {
        $form['name']['#size'] = 25;
364
        $form['name']['#id'] = 'cbox-edit-name';
365
        $form['pass']['#size'] = 25;
366
        $form['pass']['#id'] = 'cbox-edit-pass';
367
368
369
370
371
372

        // Add links as needed.
        if (variable_get('colorbox_login_links', 0)) {
          $items = array();
          // Add standard links.
          if (variable_get('colorbox_login_links', 0) == 1) {
373
            if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
374
375
376
377
378
379
              $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
            }
            $items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
          }
          // Add links that opens in a Colorbox.
          if (variable_get('colorbox_login_links', 0) == 2) {
380
381
            if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
              $items[] = l(t('Create new account'), 'colorbox/form/user_register_form', array('query' => array('width' => '300', 'height' => 'auto'), 'attributes' => array('title' => t('Create a new user account.'), 'class' => 'colorbox-load')));
382
            }
383
            $items[] = l(t('Request new password'), 'colorbox/form/user_pass', array('query' => array('width' => '300', 'height' => '150'), 'attributes' => array('title' => t('Request new password via e-mail.'), 'class' => 'colorbox-load')));
384
          }
385
          $form['links'] = array('#markup' => theme('item_list', array('items' => $items)));
386
387
388
        }
      }
      break;
389
    case 'user_register_form':
390
      if (arg(0) == 'colorbox' && arg(1) == 'form') {
391
392
        $form['account']['name']['#size'] = 30;
        $form['account']['mail']['#size'] = 30;
393
394
395
396
397
398
399
      }
      break;
    case 'user_pass':
      if (arg(0) == 'colorbox' && arg(1) == 'form') {
        $form['name']['#size'] = 30;
      }
      break;
400
  }
401
402
}

403
/**
404
 * Implements hook_link_alter().
405
 */
406
function colorbox_link_alter(&$links, $node) {
407
  if ($node->type == 'image' && is_array($node->images) && variable_get('colorbox_auto_image_nodes', 0)) {
408
409
    // Add a colorbox class to the image link sizes on the image node.
    foreach ($node->images as $size => $path) {
410
411
412
      $links['image_size_' . $size]['attributes']['class'] = "image image-{$size} colorbox";
      $links['image_size_' . $size]['href'] = $path;
      unset($links['image_size_' . $size]['query']);
413
    }
414
  }
jdwfly's avatar
jdwfly committed
415
}
416

jdwfly's avatar
jdwfly committed
417
/**
418
 * Implements hook_field_formatter_info().
jdwfly's avatar
jdwfly committed
419
420
 */
function colorbox_field_formatter_info() {
421
422
423
424
  return array(
    'colorbox' => array(
      'label' => t('Colorbox'),
      'field types' => array('image'),
425
426
427
428
429
430
      'settings' => array(
        'colorbox_node_style' => '',
        'colorbox_image_style' => '',
        'colorbox_gallery' => 'post',
        'colorbox_gallery_custom' => '',
        'colorbox_caption' => 'auto',
431
        'colorbox_caption_custom' => '',
432
      ),
433
434
    ),
  );
435
}
436

437
/**
438
 * Implements hook_field_formatter_settings_form().
439
440
441
442
443
444
 */
function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  $image_styles = image_style_options(FALSE);
445
446
  $image_styles_hide = $image_styles;
  $image_styles_hide['hide'] = t('Hide (do not display image)');
447
  $element['colorbox_node_style'] = array(
448
    '#title' => t('Content image style'),
449
450
451
    '#type' => 'select',
    '#default_value' => $settings['colorbox_node_style'],
    '#empty_option' => t('None (original image)'),
452
    '#options' => $image_styles_hide,
453
    '#description' => t('Image style to use in the content.'),
454
455
456
457
458
459
460
  );
  $element['colorbox_image_style'] = array(
    '#title' => t('Colorbox image style'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_image_style'],
    '#empty_option' => t('None (original image)'),
    '#options' => $image_styles,
461
    '#description' => t('Image style to use in the Colorbox.'),
462
463
  );

464
465
466
467
468
469
470
471
472
473
474
475
476
  $gallery = array(
    'post' => t('Per post gallery'),
    'page' => t('Per page gallery'),
    'field_post' => t('Per field in post gallery'),
    'field_page' => t('Per field in page gallery'),
    'custom' => t('Custom'),
    'none' => t('No gallery'),
  );
  $element['colorbox_gallery'] = array(
    '#title' => t('Gallery (image grouping)'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_gallery'],
    '#options' => $gallery,
477
    '#description' => t('How Colorbox should group the image galleries.'),
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
  );
  $element['colorbox_gallery_custom'] = array(
    '#title' => t('Custom gallery'),
    '#type' => 'machine_name',
    '#maxlength' => 32,
    '#default_value' => $settings['colorbox_gallery_custom'],
    '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
    '#required' => FALSE,
    '#machine_name' => array(
      'exists' => 'colorbox_gallery_exists',
      'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
      ),
    ),
  );

  $caption = array(
    'auto' =>  t('Automatic'),
    'title' => t('Title text'),
    'alt' => t('Alt text'),
501
    'node_title' => t('Entity title'),
502
    'custom' => t('Custom (with tokens)'),
503
504
505
506
507
508
509
    'none' => t('None'),
  );
  $element['colorbox_caption'] = array(
    '#title' => t('Caption'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_caption'],
    '#options' => $caption,
510
    '#description' => t('Automatic will use the first none empty value of the title, the alt text and the entity title.'),
511
  );
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
  $element['colorbox_caption_custom'] = array(
    '#title' => t('Custom caption'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_caption_custom'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
      ),
    ),
  );
  if (module_exists('token')) {
    $element['colorbox_token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Replacement patterns'),
      '#theme' => 'token_tree',
527
      '#token_types' => array($instance['entity_type'], 'file'),
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
        ),
      ),
    );
  }
  else {
    $element['colorbox_token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Replacement patterns'),
      '#description' => '<strong class="error">' . t('For token support the <a href="@token_url">token module</a> must be installed.', array('@token_url' => 'http://drupal.org/project/token')) . '</strong>',
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
        ),
      ),
    );
  }
547

548
  return $element;
549
}
550

551
/**
552
 * Implements hook_field_formatter_settings_summary().
553
 */
554
555
556
557
558
559
560
561
562
563
564
565
function colorbox_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  $summary = array();

  $image_styles = image_style_options(FALSE);
  // Unset possible 'No defined styles' option.
  unset($image_styles['']);
  // Styles could be lost because of enabled/disabled modules that defines
  // their styles in code.
  if (isset($image_styles[$settings['colorbox_node_style']])) {
566
    $summary[] = t('Content image style: @style', array('@style' => $image_styles[$settings['colorbox_node_style']]));
567
  }
568
  else if ($settings['colorbox_node_style'] == 'hide') {
569
    $summary[] = t('Content image style: Hide');
570
  }
571
  else {
572
    $summary[] = t('Content image style: Original image');
573
  }
574

575
576
  if (isset($image_styles[$settings['colorbox_image_style']])) {
    $summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']]));
577
  }
578
579
580
581
  else {
    $summary[] = t('Colorbox image style: Original image');
  }

582
583
584
585
586
587
588
589
  $gallery = array(
    'post' => t('Per post gallery'),
    'page' => t('Per page gallery'),
    'field_post' => t('Per field in post gallery'),
    'field_page' => t('Per field in page gallery'),
    'custom' => t('Custom'),
    'none' => t('No gallery'),
  );
590
591
592
  if (isset($settings['colorbox_gallery'])) {
    $summary[] = t('Colorbox gallery type: @type', array('@type' => $gallery[$settings['colorbox_gallery']])) . ($settings['colorbox_gallery'] == 'custom' ? ' (' . $settings['colorbox_gallery_custom'] . ')' : '');
  }
593
594
595
596
597

  $caption = array(
    'auto' =>  t('Automatic'),
    'title' => t('Title text'),
    'alt' => t('Alt text'),
598
    'node_title' => t('Entity title'),
599
    'custom' => t('Custom (with tokens)'),
600
601
    'none' => t('None'),
  );
602
603
604
  if (isset($settings['colorbox_caption'])) {
    $summary[] = t('Colorbox caption: @type', array('@type' => $caption[$settings['colorbox_caption']]));
  }
605

606
607
608
609
  return implode('<br />', $summary);
}

/**
610
 * Implements hook_field_formatter_view().
611
612
613
 */
function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
614
615
616
617
618

  foreach ($items as $delta => $item) {
    $element[$delta] = array(
      '#theme' => 'colorbox_image_formatter',
      '#item' => $item,
619
620
621
      '#entity_type' => $entity_type,
      '#entity' => $entity,
      '#node' => $entity, // Left for legacy support.
622
      '#field' => $field,
623
      '#display_settings' => $display['settings'],
624
625
626
627
628
629
    );
  }

  return $element;
}

630
/**
631
 * Implements hook_insert_styles().
632
633
634
 */
function colorbox_insert_styles() {
  $insert_styles = array();
635
636
637
  foreach (image_styles() as $key => $style) {
    $insert_styles['colorbox__' . $key] = array('label' => 'Colorbox ' . $style['name']);
  }
638
639
640
641
642

  return $insert_styles;
}

/**
643
 * Implements hook_insert_content().
644
645
 */
function colorbox_insert_content($item, $style, $widget) {
646
  list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2);
647
  return theme('colorbox_insert_image', array('item' => $item, 'widget' => $widget));
648
}
649
650
651
652
653
654
655
656
657
658

/**
 * Machine names normally need to be unique but that does not apply to galleries.
 *
 * @return
 *   Always FALSE
 */
function colorbox_gallery_exists() {
  return FALSE;
}