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

Contents of /contributions/modules/craqbox/craqbox.module

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


Revision 1.3 - (show annotations) (download) (as text)
Mon Apr 16 03:11:57 2007 UTC (2 years, 7 months ago) by stevemckenzie
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.2: +6 -2 lines
File MIME type: text/x-php
ahahah nice perm error.
1 <?php
2 // $Id: craqbox.module,v 1.2 2007/04/12 09:50:14 unconed Exp $
3
4 define('CRAQBOX_WIDTH', variable_get('craqbox_width', 700));
5 define('CRAQBOX_CLOSE_BUTTON_TITLE', variable_get('craqbox_close_button_title', t('Close')));
6 define('CRAQBOX_CLOSE_BUTTON_LABEL', variable_get('craqbox_close_button_label', t('x')));
7 define('CRAQBOX_IMAGE_NODES', variable_get('craqbox_image_nodes', TRUE));
8
9 /**
10 * Implementation of hook_nodeapi().
11 */
12 function craqbox_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
13 switch ($op) {
14 case 'view':
15 if ($node->type == 'image' && CRAQBOX_IMAGE_NODES) {
16 drupal_add_js(array('craqboxLinks' => array(url('node/'. $node->nid, NULL, NULL, TRUE) => $node->images['preview'])), 'setting');
17 _craqbox_image_attach('div.node a[.image-thumbnail]');
18 }
19 break;
20 }
21 }
22
23 /**
24 * Implementation of hook_perm().
25 */
26 function craqbox_perm() {
27 return array('administer craqbox', 'access craqbox');
28 }
29
30 /**
31 * Implementation of hook_menu().
32 */
33 function craqbox_menu() {
34 $items[] = array(
35 'path' => 'admin/settings/craqbox',
36 'title' => t('Craqbox settings'),
37 'description' => t('Configure la Craqbox.'),
38 'callback' => 'drupal_get_form',
39 'callback arguments' => array('craqbox_settings'),
40 'access' => user_access('administer craqbox'),
41 'type' => MENU_NORMAL_ITEM,
42 );
43
44 return $items;
45 }
46
47 /**
48 * Settings page.
49 */
50 function craqbox_settings() {
51 $form['auto'] = array(
52 '#type' => 'fieldset',
53 '#title' => t('Auto attach'),
54 '#collapsible' => TRUE,
55 );
56 if (module_exists('image')) {
57 $form['auto']['craqbox_image_nodes'] = array(
58 '#type' => 'checkbox',
59 '#title' => t('Auto attach to image nodes'),
60 '#description' => t('Image thumbnails in teaser views will get Craqbox attached automatically making the click of the thumbnail popup craqbox with the preview size of that image.'),
61 '#default_value' => CRAQBOX_IMAGE_NODES,
62 );
63 }
64 if (count(element_children($form['auto'])) == 0) {
65 unset($form['auto']);
66 }
67
68 $form['ui'] = array(
69 '#type' => 'fieldset',
70 '#title' => t('Display'),
71 '#collapsible' => TRUE,
72 '#description' => t('Customize what Craqbox looks like.'),
73 );
74 $form['ui']['craqbox_width'] = array(
75 '#type' => 'textfield',
76 '#title' => t('Width'),
77 '#size' => 3,
78 '#field_suffix' => t('px'),
79 '#description' => t('The width for Craqbox when it is displayed.'),
80 '#default_value' => CRAQBOX_WIDTH,
81 );
82 $form['ui']['craqbox_close_button_title'] = array(
83 '#type' => 'textfield',
84 '#title' => t('Close button title'),
85 '#default_value' => CRAQBOX_CLOSE_BUTTON_TITLE,
86 );
87 $form['ui']['craqbox_close_button_label'] = array(
88 '#type' => 'textfield',
89 '#title' => t('Close button label'),
90 '#default_value' => CRAQBOX_CLOSE_BUTTON_LABEL,
91 );
92
93 return system_settings_form($form);
94 }
95
96 /**
97 * Include necessary Craqbox CSS/JS.
98 */
99 function craqbox_include() {
100 static $include;
101
102 if (!user_access('access craqbox')) {
103 return false;
104 }
105
106 if (!$include) {
107 drupal_add_js(drupal_get_path('module', 'craqbox') .'/craqbox.js');
108 drupal_add_css(drupal_get_path('module', 'craqbox') .'/craqbox.css');
109 $include = true;
110 }
111 }
112
113 /**
114 * Implementation of hook_field_formatter_info().
115 * Adds certain craqbox+imagecache formatters to CCK image fields if imagefield.module and imagecache.module exist.
116 */
117 function craqbox_field_formatter_info() {
118 $formatter = array();
119 if (module_exists('imagefield') && module_exists('imagecache')) {
120 $rules = _imagecache_get_presets();
121 foreach ($rules as $ruleid => $rulename) {
122 $formatters['craqbox]['. $rulename] = array(
123 'label' => 'craqbox: '. $rulename,
124 'field types' => array('image'),
125 );
126 }
127 }
128
129 return $formatters;
130 }
131
132 /**
133 * Implementation of hook_field_formatter().
134 */
135 function craqbox_field_formatter($field, $item, $formatter) {
136 if (module_exists('imagefield') && module_exists('imagecache')) {
137 if (!isset($item['fid'])) {
138 return '';
139 }
140
141 $file = _imagefield_file_load($item['fid']);
142 if (strpos($formatter, 'craqbox][') !== false) {
143 list($null, $namespace) = explode('][', $formatter, 2);
144 $rules = _imagecache_get_presets();
145 if (in_array($namespace, (array) $rules)) {
146 return theme('imagefield_image_imagecache_craqbox', $namespace, $field, $file['filepath'], $item['alt'], $item['title']);
147 }
148 }
149 }
150 }
151
152 /**
153 * Auto attach to images with a given selector.
154 */
155 function _craqbox_image_attach($selector = 'a.craqbox') {
156 static $include;
157
158 if ($include[$selector] || !user_access('access craqbox')) {
159 return false;
160 }
161
162 craqbox_include();
163
164 $js = '$("'. $selector .'").each(function() { var o = '. drupal_to_js(array(
165 'type' => 'image',
166 'width' => CRAQBOX_WIDTH,
167 'closeButtonTitle' => CRAQBOX_CLOSE_BUTTON_TITLE,
168 'closeButtonLabel' => CRAQBOX_CLOSE_BUTTON_LABEL,
169 )) .'; o.links = (Drupal.settings && Drupal.settings.craqboxLinks) || {}; $(this).craqbox(o); });';
170 $js = 'if (Drupal.jsEnabled) { $(document).ready(function() { '. $js .' }); }';
171 drupal_add_js($js, 'inline');
172
173 $include[$selector] = true;
174 }
175
176 /**
177 * Implementation of theme_imagefield_image_imagecache_craqbox().
178 */
179 function theme_imagefield_image_imagecache_craqbox($namespace, $field, $path, $alt = '', $title = '', $attributes = NULL) {
180 $attributes = drupal_attributes($attributes);
181 $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
182
183 return '<a href="'. check_url(file_create_url($path)) .'" class="craqbox" rel="'. $field['type_name'] .'"><img src="'. check_url($imagecache_path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' /></a>';
184 }

  ViewVC Help
Powered by ViewVC 1.1.2