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

Contents of /contributions/modules/lightbox2/lightbox2.module

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


Revision 1.18 - (show annotations) (download) (as text)
Mon Apr 30 11:06:36 2007 UTC (2 years, 6 months ago) by snpower
Branch: MAIN
CVS Tags: HEAD
Changes since 1.17: +112 -101 lines
File MIME type: text/x-php
modified whitespace to match drupal coding standards
1 <?php
2 // $Id $
3 /**
4 * Enables the use of lightbox V2 which places images above your current page,
5 * not within.
6 * This frees you from the constraints of the layout, particularly column
7 * widths.
8 *
9 * This module is for Drupal 5.x only.
10 *
11 * Module by: Mark Ashmead
12 * Mailto: bugzie@gmail.com
13 * Co-maintainer: Stella Power (http://drupal.org/user/66894)
14 *
15 * Image Node Support: Steve McKenzie
16 *
17 */
18
19 /**
20 * GLOBAL VARIABLES
21 */
22 $LIGHTBOX2_INCLUDE = false;
23
24 /**
25 * Displays the information for this module.
26 * Displays the help text for this module.
27 *
28 */
29 /**
30 * Implementation of hook_help().
31 */
32 function lightbox2_help($section) {
33 switch ($section) {
34 case 'admin/modules#description':
35 return t('Enables Lightbox V2 for Drupal');
36 case 'admin/help#lightbox2':
37 return t('<h3>Overview</h3>
38 <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>
39 <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>
40 <p align="justify"><h3>Usage</h3></p>
41 <p>Add rel=&quot;lightbox&quot; attribute to any link tag to activate the lightbox. For example: </p>
42 <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>
43 <p>Optional: Use the title attribute if you want to show a caption.</p>
44 <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>
45 &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip]"&gt;image #2&lt;/a&gt;<br>
46 &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip]"&gt;image #3&lt;/a&gt;<br></p>
47 <p>No limits to the number of image sets per page or how many images are allowed in each set. Go nuts!</p>
48 <p align="justify"><h3>Known Issues</h3></p>
49 <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>
50 <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>
51 <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>
52 <p>var fileLoadingImage = &quot;/modules/lightbox2/images/loading.gif&quot;;<br>
53 var fileBottomNavCloseImage = &quot;/modules/lightbox2/images/closelabel.gif&quot;;<br>
54 var fileBottomNavZoomImage = &quot;/modules/lightbox2/images/expand.gif&quot;; //Update to 2.02+</p>
55 <p>should be changed to</p>
56 <p>var fileLoadingImage = &quot;/subdirectory/modules/lightbox2/images/loading.gif&quot;;<br>
57 var fileBottomNavCloseImage = &quot;/subdirectory/modules/lightbox2/images/closelabel.gif&quot;;<br>
58 var fileBottomNavZoomImage = &quot;/subdirectory/modules/lightbox2/images/expand.gif&quot;; //Update to 2.02+</p>
59 <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>');
60 break;
61 }
62 }
63
64 /**
65 * Implementation of hook_perm()
66 * Define the permissions this module uses
67 */
68 function lightbox2_perm() {
69 return array('administer lightbox2');
70 }
71
72
73 /**
74 * Implementation of hook_access()
75 */
76 function lightbox2_access($op, $node) {
77 return user_access('administer lightbox2');
78 }
79
80 /**
81 * Implementation of hook_menu()
82 */
83 function lightbox2_menu($may_cache) {
84 $items = array();
85
86 if ($may_cache) {
87 $items[] = array('path' => 'admin/settings/lightbox2',
88 'title' => t('Lightbox2'),
89 'callback' => 'drupal_get_form',
90 'callback arguments' => array('lightbox2_settings_form'),
91 'access' => user_access('administer lightbox2'),
92 'description' => t('Allows the user to configure the lightbox2 settings'),
93 );
94 }
95 else {
96 }
97
98 return $items;
99 }
100
101
102 /**
103 * Implementation of hook_nodeapi().
104 */
105 function lightbox2_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
106 global $LIGHTBOX2_INCLUDE;
107
108 if ($op == "view" && !$LIGHTBOX2_INCLUDE) {
109 lightbox2_add_files();
110 $LIGHTBOX2_INCLUDE = true;
111 }
112 elseif ($node->type == "image" && !$LIGHTBOX2_INCLUDE) {
113 lightbox2_add_files();
114 $LIGHTBOX2_INCLUDE = true;
115 }
116 }
117
118 /**
119 * Implementation of hook_settings()
120 */
121 function lightbox2_settings_form() {
122
123 // Define Lightbox2 Plus form.
124 $form["lightbox2_plus_options"] = array(
125 "#type" => "fieldset",
126 "#title" => t("Lightbox2 Plus"),
127 "#collapsible" => TRUE,
128 "#collapsed" => FALSE,
129 );
130
131 // Add Checkbox for Lightbox2 Plus.
132 $form["lightbox2_plus_options"]["lightbox2_plus"] = array(
133 "#type" => "checkbox",
134 "#title" => t("Use Lightbox2 Plus"),
135 "#description" => t("Un-checking this box will enable Lightbox2 Lite."),
136 "#default_value" => variable_get("lightbox2_plus", true),
137 );
138
139 // Define Image Node Options form.
140 $form["image_node_options"] = array(
141 "#type" => "fieldset",
142 "#title" => t("Lightbox2 Plus Image Node options"),
143 "#collapsible" => TRUE,
144 "#collapsed" => TRUE,
145 );
146
147 // Add Checkbox for Image Node.
148 $form["image_node_options"]["lightbox2_image_node"] = array(
149 "#type" => "checkbox",
150 "#title" => t("Enable for Image Nodes"),
151 "#description" => t("Checking this box will enable automatic URL formatting for Image Nodes."),
152 "#default_value" => variable_get("lightbox2_image_node", true),
153 );
154
155 // Add Checkbox for Image Node Grouping.
156 $form["image_node_options"]["lightbox2_image_group"] = array(
157 "#type" => "checkbox",
158 "#title" => t("Enable Grouping"),
159 "#description" => t("Checking this box will enable automatic grouping of Image Nodes on a page. Useful for image galleries."),
160 "#default_value" => variable_get("lightbox2_image_group", true),
161 );
162
163 // Add Checkbox for Gallery2 Image Filter.
164 $form["image_node_options"]["lightbox2G2_filter"] = array(
165 "#type" => "checkbox",
166 "#title" => t("Enable Gallery 2 Filter"),
167 "#description" => t("Checking this box will enable the Gallery 2 filter."),
168 "#default_value" => variable_get("lightbox2G2_filter", true),
169 );
170
171 $form["update"] = array(
172 '#type' => 'submit',
173 '#value' => t('Update'),
174 '#weight' => 3,
175 );
176
177 return $form;
178 }
179
180 function lightbox2_settings_form_submit($form_id, $form_values) {
181 if ($form_values['op'] == t('Update')) {
182 variable_set("lightbox2_plus", $form_values["lightbox2_plus"]);
183 variable_set("lightbox2G2_filter", $form_values["lightbox2G2_filter"]);
184 variable_set("lightbox2_image_node", $form_values["lightbox2_image_node"]);
185 variable_set("lightbox2_image_group", $form_values["lightbox2_image_group"]);
186 }
187 }
188
189 /**
190 *Implementation of hook_filter().
191 */
192 function lightbox2_filter_tips($delta, $format, $long = false) {
193 return t('Image links from G2 are formatted for use with Lightbox.V2');
194 }
195
196 // Check to see if the G2 Filter is Enabled in Settings
197 if (variable_get("lightbox2G2_filter", true)) {
198 function lightbox2_filter($op, $delta = 0, $format = -1, $text = '') {
199 switch ($op) {
200 case 'list':
201 return array(0 => t('Lightbox filter'));
202 case 'description':
203 return t('Turns g2_filter links into Lighbox.V2 appropriate links');
204 case 'process':
205 $text = ' '. $text .' ';
206 $text = preg_replace('/ShowItem/','DownloadItem',$text);
207 $text = preg_replace('/target=""/','rel="lightbox"',$text);
208 $text = substr($text, 1, -1);
209 return $text;
210 default:
211 return $text;
212 }
213 }
214 }
215 /**
216 * Provides a link to the CSS stylesheet associated with this module.
217 * Provides a link to the JS file associated with this module.
218 */
219
220 function lightbox2_add_files() {
221
222 // Load required js and css files.
223 $path = drupal_get_path('module', 'lightbox2');
224
225 // Check to see if Lightbox2 Plus is enabled.
226 if (variable_get("lightbox2_plus", true)) {
227 if (function_exists('drupal_add_css')) {
228 drupal_add_css($path .'/lightbox.css');
229 }
230 else {
231 theme("add_style", $path .'/lightbox.css');
232 }
233
234 // Check to see if Libraries are installed correctly.
235 if (file_exists($path .'/js/prototype.js')) {
236 drupal_add_js($path .'/js/prototype.js');
237
238 // Check to see if the Image Node Option is enabled in settings.
239 if (variable_get("lightbox2_image_node", true) && variable_get("lightbox2_image_group", true)) {
240 drupal_add_js($path ."/js/image_nodes.js");
241 }
242 elseif (variable_get("lightbox2_image_node", true)) {
243 drupal_add_js($path ."/js/image_nodes_nogroup.js");
244 }
245 drupal_add_js($path .'/js/scriptaculous.js?load=effects');
246 drupal_add_js($path .'/js/lightbox.js');
247 // Future support for non-images will go here.
248 //drupal_add_js($path .'/js/lightbox_docs.js');
249 }
250
251 // Display warning message if Libraries aren't installed correctly.
252 else {
253 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');
254 }
255 }
256 // Load Lightbox Lite if Plus is not enabled.
257 else {
258 if (function_exists('drupal_add_css')) {
259 drupal_add_css($path .'/lightbox_lite.css');
260 }
261 else {
262 theme("add_style", $path .'/lightbox_lite.css');
263 }
264 drupal_add_js($path .'/js/lightbox_lite.js');
265 }
266 }

  ViewVC Help
Powered by ViewVC 1.1.2