summaryrefslogtreecommitdiffstats
path: root/lightbox2.module
blob: 0fa856d5a82894585be9ef75abe3d1cc446f2aa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
// $Id $
/**
 * Enables the use of lightbox V2 which places images above your current page, not within.
 * This frees you from the constraints of the layout, particularly column widths.
 * 
 * This module is for Drupal 5.x only.
 *
 * Module by: Mark Ashmead
 * Mailto: bugzie@gmail.com
 * Co-maintainer: Stella Power (http://drupal.org/user/66894)
 *
 * Image Node Support: Steve McKenzie
 *
*/

/**
 *	GLOBAL VARIABLES
 */
$LIGHTBOX2_INCLUDE = false;

/**
 * Displays the information for this module.
 * Displays the help text for this module.
 *
 */
/**
 * Implementation of hook_help().
 */
function lightbox2_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Enables Lightbox V2 for Drupal');
    case 'admin/help#lightbox2':
      return t('<h3>Overview</h3>
      <p align="justify">Lightbox JS V2 is a simple, unobtrusive script used to overlay images on the current page. It\'s a snap to setup and works on all modern browsers. The module comes with a Lightbox2 Lite option which does not use the Scriptaculous/Prototype libraries; it is therefore less likely to conflict with anything else.</p>
      <p align="justify">Places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths. Keeps users on the same page. Clicking to view an image and then having to click the back button to return to your site is bad for continuity (and no fun!).</p>
      <p align="justify"><h3>Usage</h3></p>
      <p>Add rel=&quot;lightbox&quot; attribute to any link tag to activate the lightbox. For example: </p>
      <p>&lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox&quot; title=&quot;my caption&quot;&gt;image #1&lt;/a&gt;</p>
      <p>Optional: Use the title attribute if you want to show a caption.</p>
	  <p>If you have a set of related images that you would like to group, follow step one but additionally include a group name between square brackets in the rel attribute. For example:</p><p>&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br>
&lt;a href="images/image-2.jpg" rel="lightbox[roadtrip]"&gt;image #2&lt;/a&gt;<br>
&lt;a href="images/image-3.jpg" rel="lightbox[roadtrip]"&gt;image #3&lt;/a&gt;<br></p>
<p>No limits to the number of image sets per page or how many images are allowed in each set. Go nuts!</p>
	<p align="justify"><h3>Known Issues</h3></p>
	<p>Image Issues - An issue has been identified with the loading of certain images when using the module. (closelabel.gif, expand.gif, loading.gif)</p>
    <p>If your installation of Drupal exists in the root of your domain, i.e., www.yourinstallation.com then you shouldn\'t have any problems. The issue only occurs when Drupal is installed in a subdirectory, i.e., www.yourinstallation.com/subdirectory.</p>
    <p>If this is the case, you will need to edit the lightbox.js on lines 63, 64 and 65 to reflect the fully qualified URL of your images. In the above case, this would be as follows;</p>
    <p>var fileLoadingImage = &quot;/modules/lightbox2/images/loading.gif&quot;;<br>
      var fileBottomNavCloseImage = &quot;/modules/lightbox2/images/closelabel.gif&quot;;<br>
      var fileBottomNavZoomImage = &quot;/modules/lightbox2/images/expand.gif&quot;; //Update to 2.02+</p>
    <p>should be changed to</p>
    <p>var fileLoadingImage = &quot;/subdirectory/modules/lightbox2/images/loading.gif&quot;;<br>
      var fileBottomNavCloseImage = &quot;/subdirectory/modules/lightbox2/images/closelabel.gif&quot;;<br>
      var fileBottomNavZoomImage = &quot;/subdirectory/modules/lightbox2/images/expand.gif&quot;; //Update to 2.02+</p>
    <p>There may be other methods that can be used to achieve this, but this should be the simplest for those with little or no programming experience. If you choose to use Lightbox2 Lite option, then you will need to edit the lightbox_lite.js file in a similar manner on lines 39 and 40.</p>');
      break;
  }
}

/**
* Implementation of hook_perm()
* Define the permissions this module uses
*/
function lightbox2_perm() {
  return array('administer lightbox2');
}


/**
* Implementation of hook_access()
*/
function lightbox2_access($op, $node) {
  return user_access('administer lightbox2');
}

/**
* Implementation of hook_menu()
*/
function lightbox2_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $items[] = array('path' => 'admin/settings/lightbox2',
      'title' => t('Lightbox2'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('lightbox2_settings_form'),
      'access' => user_access('administer lightbox2'),
      'description' => t('Allows the user to configure the lightbox2 settings.'),
    );
  }
  else {
  }

  return $items;
}


/**
 * Implementation of hook_nodeapi().
 */
function lightbox2_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {	
	global $LIGHTBOX2_INCLUDE;
	
	if ($op == "view" && !$LIGHTBOX2_INCLUDE) {
		lightbox2_add_files();
		$LIGHTBOX2_INCLUDE = true;
	}
	elseif ($node->type == "image" && !$LIGHTBOX2_INCLUDE) {
		lightbox2_add_files();
		$LIGHTBOX2_INCLUDE = true;
	}
}

/**
 * Implementation of hook_settings().
 */
function lightbox2_settings_form() {	

	// Define Lightbox2 Plus form.
	$form["lightbox2_plus_options"] = array(
		"#type" => "fieldset",
		"#title" => t("Lightbox2 Plus"),
		"#collapsible" => TRUE, 
		"#collapsed" => FALSE,
	);
	// Add Checkbox for Lightbox2 Plus.
	$form["lightbox2_plus_options"]["lightbox2_plus"]  = array(
		"#type" => "checkbox",
		"#title" => t("Use Lightbox2 Plus"),
		"#description" => t("Un-checking this box will enable Lightbox2 Lite."),
		"#default_value" => variable_get("lightbox2_plus", true),
	);
	// Define Image Node Options form.
	$form["image_node_options"] = array(
		"#type" => "fieldset",
		"#title" => t("Lightbox2 Plus Image Node options"),
		"#collapsible" => TRUE, 
		"#collapsed" => TRUE,
	);
	// Add Checkbox for Image Node.
	$form["image_node_options"]["lightbox2_image_node"]  = array(
		"#type" => "checkbox",
		"#title" => t("Enable for Image Nodes"),
		"#description" => t("Checking this box will enable automatic URL formatting for Image Nodes."),
		"#default_value" => variable_get("lightbox2_image_node", true),
	);
	// Add Checkbox for Image Node Grouping.
	$form["image_node_options"]["lightbox2_image_group"]  = array(
		"#type" => "checkbox",
		"#title" => t("Enable Grouping"),
		"#description" => t("Checking this box will enable automatic grouping of Image Nodes on a page. Useful for image galleries."),
		"#default_value" => variable_get("lightbox2_image_group", true),
	);
	// Add Checkbox for Gallery2 Image Filter.
	$form["image_node_options"]["lightbox2G2_filter"]  = array(
		"#type" => "checkbox",
		"#title" => t("Enable Gallery 2 Filter"),
		"#description" => t("Checking this box will enable the Gallery 2 filter."),
		"#default_value" => variable_get("lightbox2G2_filter", true),
	);

 $form["update"] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#weight' => 3,
 );

	
	return $form;
}

function lightbox2_settings_form_submit($form_id, $form_values) {
  if ($form_values['op'] == t('Update')) {
    variable_set("lightbox2_plus", $form_values["lightbox2_plus"]);
    variable_set("lightbox2G2_filter", $form_values["lightbox2G2_filter"]);
    variable_set("lightbox2_image_node", $form_values["lightbox2_image_node"]);
    variable_set("lightbox2_image_group", $form_values["lightbox2_image_group"]);
  }
}

/**
 *Implementation of hook_filter().
 */
function lightbox2_filter_tips($delta, $format, $long = false) {
    return t('Image links from G2 are formatted for use with Lightbox.V2');
}

// Check to see if the G2 Filter is Enabled in Settings
if (variable_get("lightbox2G2_filter", true)) {
function lightbox2_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(0 => t('Lightbox filter'));
    case 'description':
      return t('Turns g2_filter links into Lighbox.V2 appropriate links');
    case 'process':
        $text = ' ' . $text . ' ';
        $text = preg_replace('/ShowItem/','DownloadItem',$text);
        $text = preg_replace('/target=""/','rel="lightbox"',$text);
        $text = substr($text, 1, -1);
    return $text;
    default:
      return $text;
  }
 }
}
/**
 * Provides a link to the CSS stylesheet associated with this module.
 * Provides a link to the JS file associated with this module.
 */

function lightbox2_add_files() {
  // Load required js and css files.
  $path = drupal_get_path('module', 'lightbox2');
	// Check to see if Lightbox2 Plus is enabled.
	if (variable_get("lightbox2_plus", true)) {
		if (function_exists('drupal_add_css')) {
				drupal_add_css($path .'/lightbox.css');
  }
  else {
  	theme("add_style", $path . '/lightbox.css');
  }
  		// Check to see if Libraries are installed correctly.
  		if (file_exists($path .'/js/prototype.js')) {
		drupal_add_js($path . '/js/prototype.js');
 	 		// Check to see if the Image Node Option is enabled in settings.
 	 		if (variable_get("lightbox2_image_node", true) && variable_get("lightbox2_image_group", true)) {
  				drupal_add_js($path . "/js/image_nodes.js");
 	 		}
			elseif (variable_get("lightbox2_image_node", true)) {
				drupal_add_js($path . "/js/image_nodes_nogroup.js");
 	 		}
  		drupal_add_js($path . '/js/scriptaculous.js?load=effects');
  		drupal_add_js($path . '/js/lightbox.js');
		// Future support for non-images will go here.
		//drupal_add_js($path . '/js/lightbox_docs.js');
  		}
 		// Display warning message if Libraries aren't installed correctly.
		else {
      	drupal_set_message(t('The script.aculo.us library is in not installed correctly. Please download from <a href="http://script.aculo.us/downloads">http://script.aculo.us/downloads</a>, follow the instructions in the Lightbox V.2 README.TXT file to copy the files to their correct locations.'), 'error');
    	}
	}
	// Load Lightbox Lite if Plus is not enabled.
 	else {
				if (function_exists('drupal_add_css')) {
						drupal_add_css($path .'/lightbox_lite.css');
				}
				else {
						theme("add_style", $path . '/lightbox_lite.css');
				}
 	drupal_add_js($path . '/js/lightbox_lite.js');
    }
}