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

Contents of /contributions/modules/slideshowcs/slideshowcs.module

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Sep 3 13:21:24 2008 UTC (14 months, 3 weeks ago) by davebv
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of SlideShowCS module. A fancy slideshow with jquery plugins
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Slide Show CS, fancy slideshow block
7 *
8 * This block provides a fancy customizable slideshow block.
9 */
10
11 /**
12 * Display help and module information
13 * @param path which path of the site we're displaying help
14 * @param arg array that holds the current path as would be returned from arg() function
15 * @return help text for the path
16 */
17 function slideshowcs_help($path, $arg) {
18 $output = '';
19 switch ($path) {
20 case "admin/help#slideshowcs":
21 $output = '<p>'. t("Displays a nice slideshow with cool effects using Cross-Slide jQuery plugin.") .'</p>';
22 break;
23 }
24 return $output;
25 } // function slideshowcs_help
26
27
28 function slideshowcs_install() {
29 $defaultpath = file_directory_path() .'/slideshowcs';
30 file_check_directory($defaultpath, 1); // Check if the directory exist and create it if necessary.
31
32 }
33
34 function slideshowcs_init() {
35 slideshowcs_generate();
36 }
37
38 function slideshowcs_perm() {
39 return array('access slideshowcs content', 'administer slideshowcs');
40 }
41
42 function slideshowcs_block($op = 'list', $delta = 0, $edit = array()) {
43
44 switch ($op) {
45 case 'list':
46 $blocks[0] = array(
47 'info' => t('Slideshow CS block'),
48 );
49 return $blocks;
50 case 'configure':
51 $form = array();
52 if ($delta == 0) {
53 }
54 return $form;
55 case 'view': default:
56 switch ($delta) {
57 case 0:
58 $block['subject'] = "";
59 $block['content'] = slideshowcs_contents(1);
60
61 break;
62 }
63 return $block;
64 }
65 }
66
67 // Theme hook
68 function slideshowcs_theme() {
69 return array(
70 'slideshowcs_my_form' => array(
71 'arguments' => $form,
72 ),
73 'slideshowcs' => array(
74 'template' => 'slideshowcs',
75 'arguments' => array(
76 'contenido' => $contenido,
77 ),
78 ),
79 );
80 }
81
82 // Content Generation
83 function slideshowcs_contents($which_block) {
84 switch ($which_block) {
85 case 1:
86 $filepaths = variable_get('imagesinfolder', array()) ;
87 if (!empty($filepaths)) {
88 $blockidcss = "slideshowCS" ;
89 $trans = array("!blockid" => $blockidcss, "!blockheight" => variable_get('block_height', '200'));
90
91 $contenido = strtr("<div id='!blockid' style='height:!blockheightpx'>", $trans) ;
92 $contenido .= t('Loading...') ."</div>" ;
93 }
94 $contenido = theme('slideshowcs', $contenido);
95 return $contenido;
96 break;
97 default: break;
98 }
99 }
100
101 function slideshowcs_generate() {
102
103 $defaultpath = file_directory_path() .'/slideshowcs';
104 $filepaths = variable_get('imagesinfolder', array()) ;
105 $filebasepath = variable_get('slideshowcs_folderpath', array()) ;
106 $path = drupal_get_path('module', 'slideshowcs');
107
108 if (!empty($filepaths)) {
109 $blockidcss = "slideshowCS" ;
110
111 $trans = array("!blockid" => $blockidcss, "!blockheight" => variable_get('block_height', '200'));
112
113 $contenido = strtr("<div id='!blockid' style='height:!blockheightpx'>", $trans) ;
114 $contenido .= t('Loading...') ."</div>" ;
115
116 $indice = 0 ;
117
118 $images = array();
119
120 foreach ( $filepaths as $valor ) {
121 $indice++ ;
122
123 $fade = variable_get('fade_time', '1');
124 // Picture enabled?
125 $auxiliar = 'enabled'. $indice ;
126
127 if (variable_get($auxiliar, '1')) {
128
129 $auxiliarfromx = 'fromx'. $indice ;
130 $auxiliarfromy = 'fromy'. $indice ;
131 $auxiliarfromzoom = 'fromzoom'. $indice ;
132 $auxiliartox = 'tox'. $indice ;
133 $auxiliartoy = 'toy'. $indice ;
134 $auxiliartozoom = 'tozoom'. $indice ;
135 $auxiliartime = 'time'. $indice ;
136 $urlpic = file_create_url(
137 t("!filebase!filename",
138 array(
139 '!filebase' => $filebasepath,
140 '!filename' => '/'. $valor,
141 )
142 )
143 ) ;
144 $from = array(
145 '!fromx' => variable_get( $auxiliarfromx, '0'),
146 '!fromy'=> variable_get( $auxiliarfromy, '0'),
147 '!fromzoom' => variable_get( $auxiliarfromzoom, '1'),
148 );
149 $to = array(
150 '!tox' => variable_get($auxiliartox, '0'),
151 '!toy' => variable_get($auxiliartoy, '0'),
152 '!tozoom' => variable_get($auxiliartozoom, '1'),
153 );
154 $images[] = array(
155 'src' => $urlpic,
156 'from' => strtr('!fromx% !fromy% !fromzoomx', $from),
157 'to' => strtr('!tox% !toy% !tozoomx', $to),
158 'time' => variable_get($auxiliartime, '2'),
159 );
160 }
161 }
162
163 // If there is no Pictures in the chosen folder
164 }
165 else {
166 $contenido = t("<div id='slideshowCS' style='height:100px'>No images in the configured folder</div>") ;
167 }
168
169 $js_settings = array(
170 'imagesCS' => $images,
171 'fade' => $fade,
172 );
173
174 // Add Style Sheets
175 drupal_add_css($path .'/slideshowcs.css') ;
176
177 // Feature requested to jQuery plugin module: add cross-slide plugin to JQ plugins
178 // if (module_exists('jq')) {jq_add('crossslide');}
179
180 // Until Cross-Slide is added to jQuery plugins:
181 drupal_add_js($path .'/jquery.cross-slide.js', 'module', 'header') ;
182
183 drupal_add_js(array('slideshowcs' => $js_settings), 'setting');
184 //drupal_add_js("var slideshowcsjsvar = ". drupal_to_js($images).";",'inline');
185 drupal_add_js($path .'/slideshowcs.js', 'module', 'header') ;
186 //drupal_add_js($path.'/slideshowcs.js') ;
187
188 return $contenido ;
189 }
190
191
192 // Admin section
193
194 function slideshowcs_menu() {
195
196 $items = array();
197
198 $items['admin/settings/slideshowcs'] = array(
199 'title' => t('Slideshow CS settings'),
200 'page callback' => 'slideshowcs_form',
201 'access arguments' => array('access administration pages'),
202 'description' => t('Configure Slideshow CS'),
203 'type' => MENU_NORMAL_ITEM,
204 );
205
206 return $items;
207 }
208
209 function slideshowcs_form() {
210 return drupal_get_form('slideshowcs_my_form');
211 }
212
213 function theme_slideshowcs_my_form(&$form) {
214 // Render the first section
215 $output = drupal_render($form['Folder']) ;
216
217 // Add the table to be draggable
218 // TODO: save the values to make it work properly
219 // drupal_add_tabledrag('menu-slideshow', 'order', 'sibling', 'menu-weight');
220
221 $header = array(
222 array('data' => t('File')),
223 array('data' => t('Enable')),
224 array('data' => t('From x %')),
225 array('data' => t('From y %')),
226 array('data' => t('From Zoom .x')),
227 array('data' => t('To x %')),
228 array('data' => t('To y %')),
229 array('data' => t('To Zoom .x')),
230 array('data' => t('Time (s)')),
231 );
232 $rows = array() ;
233 $row = array() ;
234 $first_level = array() ;
235 foreach (element_children($form['files']) as $key => $value) {
236 // TODO
237 // $form['files'][$value]['weight']['#attributes']['class'] = 'menu-weight';
238
239 $first_level = array($value) ;
240
241 $second_level = array() ;
242 foreach (element_children($form['files'][$value]) as $key2 => $value2) {
243 $second_level[] = drupal_render($form['files'][$value][$value2]) ;
244 }
245 $row = array_merge($first_level, $second_level, array(drupal_render($form['files'][$value]['weight']))) ;
246 $row = array('data' => $row) ;
247 $row['class'] = !empty($row['class']) ? $row['class'] .' draggable' : 'draggable';
248 $rows[] = $row;
249 }
250
251 if ($rows) {
252 // TODO
253 // $output .= '<div>'. theme('table', $header, $rows, array('id' => 'menu-slideshow')) .'</div>' ;
254 $output .= '<div>'. theme('table', $header, $rows) .'</div>' ;
255 }
256 $output .= drupal_render($form);
257
258 return $output;
259 }
260
261
262 function slideshowcs_my_form($form_state) {
263 //from: '65% 50% 1x',
264 //to: '100% 20% 1x',
265 //time: 2
266 $defaultpath = file_directory_path() . t('/slideshowcs');
267
268 $form['Folder'] = array(
269 '#type' => 'fieldset',
270 '#title' => t('Settings'),
271 '#collapsible' => TRUE,
272 '#collapsed' => FALSE,
273 );
274 $form['Folder']['slideshowcs_folderpath'] = array(
275 '#type' => 'textfield',
276 '#title' => t('Pictures folder'),
277 '#default_value' => variable_get('slideshowcs_folderpath', $defaultpath),
278 '#size' => 50,
279 '#maxlength' => 50,
280 '#description' => t("Folder where the images are situated."),
281 '#required' => TRUE,
282 );
283 $form['Folder']['block_height'] = array(
284 '#type' => 'textfield',
285 '#title' => t('Height'),
286 '#default_value' => variable_get('block_height', '200'),
287 '#size' => 4,
288 '#maxlength' => 4,
289 '#description' => t("Block height in pixels."),
290 '#required' => TRUE,
291 );
292 $form['Folder']['fade_time'] = array(
293 '#type' => 'textfield',
294 '#title' => t('Fade'),
295 '#default_value' => variable_get('fade_time', '1'),
296 '#size' => 4,
297 '#maxlength' => 1,
298 '#description' => t("Fade duration in seconds."),
299 '#required' => TRUE,
300 );
301
302 // Files section
303 $form['files'] = array(
304 '#type' => 'hidden',
305 '#title' => t('Files'),
306 );
307
308 // See if the directory has images
309 $contenido1 = file_scan_directory(
310 variable_get('slideshowcs_folderpath', $defaultpath),
311 "jpg$|png$|gif$",
312 array('.', '..', 'CVS'),
313 0, // Callback (0 for no callback).
314 FALSE,
315 'filename',
316 0
317 ) ;
318
319 $filenames = array() ;
320 foreach ($contenido1 as $value) {
321 // Entire path $value->filename
322 // File name with extension $value->basename
323 // File name with no extension "$value->name
324 if (FALSE == image_get_info( $value->filename )) {
325 drupal_set_message(t('The file %name is not an image', array('%name' => $value->basename)), 'warning');
326 }
327 else {
328 $fileimage = $value->basename ;
329 $filenames[] = $fileimage ;
330 }
331 }
332
333 sort($filenames);
334 variable_set('imagesinfolder', $filenames) ;
335
336 $indice = 0;
337 foreach ($filenames as $key => $value) {
338 $indice++ ;
339
340 $form['files'][$value] = array(
341 '#type' => 'hidden',
342 '#title' => t($value),
343 );
344 $auxiliar = 'enabled'. $indice ;
345 $form['files'][$value][$auxiliar] = array(
346 '#type' => 'checkbox',
347 //'#title' => t($value),
348 '#default_value' => variable_get($auxiliar, '1'),
349 '#weight' => 1 ,
350 );
351 // From
352 $auxiliar = 'fromx'. $indice ;
353 $form['files'][$value][$auxiliar] = array(
354 '#type' => 'textfield',
355 //'#title' => t('Origin x'),
356 '#default_value' => variable_get($auxiliar, '0'),
357 '#size' => 2,
358 '#maxlength' => 3,
359 //'#description' => t("Folder where the images are situated."),
360 '#required' => FALSE,
361 '#weight' => 2 ,
362 );
363 $auxiliar = 'fromy'. $indice ;
364 $form['files'][$value][$auxiliar] = array(
365 '#type' => 'textfield',
366 //'#title' => t('y'),
367 '#default_value' => variable_get($auxiliar, '0'),
368 '#size' => 2,
369 '#maxlength' => 3,
370 //'#description' => t("Folder where the images are situated."),
371 '#required' => FALSE,
372 '#weight' => 3 ,
373 );
374 $auxiliar = 'fromzoom'. $indice ;
375 $form['files'][$value][$auxiliar] = array(
376 '#type' => 'textfield',
377 //'#title' => t('Zoom'),
378 '#default_value' => variable_get($auxiliar, '1'),
379 '#size' => 2,
380 '#maxlength' => 3,
381 //'#description' => t("Folder where the images are situated."),
382 '#required' => FALSE,
383 '#weight' => 4 ,
384 );
385 // TO
386 $auxiliar = 'tox'. $indice ;
387 $form['files'][$value][$auxiliar] = array(
388 '#type' => 'textfield',
389 //'#title' => t('To x'),
390 '#default_value' => variable_get($auxiliar, '0'),
391 '#size' => 2,
392 '#maxlength' => 3,
393 //'#description' => t("Folder where the images are situated."),
394 '#required' => FALSE,
395 '#weight' => 5 ,
396 );
397 $auxiliar = 'toy'. $indice ;
398 $form['files'][$value][$auxiliar] = array(
399 '#type' => 'textfield',
400 //'#title' => t('y'),
401 '#default_value' => variable_get($auxiliar, '0'),
402 '#size' => 2,
403 '#maxlength' => 3,
404 //'#description' => t("Folder where the images are situated."),
405 '#required' => FALSE,
406 '#weight' => 6 ,
407 );
408 $auxiliar = 'tozoom'. $indice ;
409 $form['files'][$value][$auxiliar] = array(
410 '#type' => 'textfield',
411 //'#title' => t('Zoom2'),
412 '#default_value' => variable_get($auxiliar, '1'),
413 '#size' => 2,
414 '#maxlength' => 4,
415 //'#description' => t("Folder where the images are situated."),
416 '#required' => FALSE,
417 '#weight' => 7 ,
418 );
419 // Duration
420 $auxiliar = 'time'. $indice ;
421 $form['files'][$value][$auxiliar] = array(
422 '#type' => 'textfield',
423 //'#title' => t('Duration'),
424 '#default_value' => variable_get($auxiliar, '2'),
425 '#size' => 2,
426 '#maxlength' => 2,
427 //'#description' => t("Duration."),
428 '#required' => FALSE,
429 '#weight' => 8 ,
430 );
431 }
432
433 $form = system_settings_form($form);
434 $form['#theme'] = 'slideshowcs_my_form';
435 return $form;
436 }
437
438 function slideshowcs_my_form_validate($form, &$form_state) {
439 $folderpath = $form_state['values']['slideshowcs_folderpath'];
440
441 $directory = rtrim($folderpath, '/\\');
442 // Check if directory exists.
443 $defaultpath = file_directory_path() . t('/slideshowcs');
444 if (!is_dir($directory)) {
445 //form_set_error('slideshowcs_folderpath', t('The directory %directory does not exist.', array('%directory' => $directory)));
446 drupal_set_message(t('The directory %directory does not exist.', array('%directory' => $directory)), 'error');
447 }
448 }

  ViewVC Help
Powered by ViewVC 1.1.2