1
|
<?php
|
2
|
// $Id: lightbox2.insert.inc,v 1.1.2.6 2010/09/22 10:47:15 snpower Exp $
|
3
|
|
4
|
/**
|
5
|
* @file
|
6
|
* Lightbox2 support for Insert module.
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Implementation of hook_insert_styles().
|
11
|
*/
|
12
|
function lightbox2_insert_styles() {
|
13
|
$cck_formatters = lightbox2_field_formatter_info();
|
14
|
$insert_styles = array();
|
15
|
// Reformat CCK formatter ids as Insert style ids.
|
16
|
foreach ($cck_formatters as $formatter_id => $formatter_info) {
|
17
|
// Currently only the "imagefield--lightbox2" formatters are implemented as styles.
|
18
|
if (preg_match('/^imagefield__lightbox2__((?:_(?!_)|[^_])+)__((?:_(?!_)|[^_])+)$/', $formatter_id, $matches)) {
|
19
|
$style_id = 'lightbox2--' . $matches[1] . '--' . $matches[2];
|
20
|
$insert_styles[$style_id] = $formatter_info;
|
21
|
}
|
22
|
}
|
23
|
return $insert_styles;
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* Implementation of hook_insert_content().
|
28
|
*/
|
29
|
function lightbox2_insert_content($item, $style, $widget) {
|
30
|
if (preg_match('/^lightbox2--((?:-(?!-)|[^-])+)--((?:-(?!-)|[^-])+)$/', $style['name'], $matches)) {
|
31
|
$image_preset_name = $matches[1];
|
32
|
$link_preset_name = $matches[2];
|
33
|
return theme('lightbox2_insert_image', $item, $widget, 'view', $image_preset_name, $link_preset_name);
|
34
|
}
|
35
|
else {
|
36
|
return '';
|
37
|
}
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Theme the content that will be inserted for Lightbox2 presets.
|
42
|
*/
|
43
|
function template_preprocess_lightbox2_insert_image(&$vars) {
|
44
|
if ($vars['image_preset_name'] != 'original') {
|
45
|
$filepath = imagecache_create_path($vars['image_preset_name'], $vars['item']['filepath']);
|
46
|
}
|
47
|
else {
|
48
|
$filepath = $vars['item']['filepath'];
|
49
|
}
|
50
|
$vars['url'] = insert_create_url($filepath);
|
51
|
|
52
|
if ($vars['link_preset_name'] != 'original') {
|
53
|
$linkpath = imagecache_create_path($vars['link_preset_name'], $vars['item']['filepath']);
|
54
|
}
|
55
|
else {
|
56
|
$linkpath = $vars['item']['filepath'];
|
57
|
}
|
58
|
$vars['linkurl'] = insert_create_url($linkpath);
|
59
|
|
60
|
$vars['download_link'] = '';
|
61
|
$download_link_text = check_plain(variable_get('lightbox2_download_link_text', 'Download Original'));
|
62
|
if (!empty($download_link_text) && user_access('download original image')) {
|
63
|
$vars['download_link'] = '<br /><br />' . l($download_link_text, $vars['linkurl'], array('attributes' => array('target' => '_blank', 'id' => 'lightbox2-download-link-text')));
|
64
|
}
|
65
|
|
66
|
$vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
|
67
|
}
|
68
|
|