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

Contents of /contributions/modules/galleria/galleria.module

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Dec 3 14:50:54 2008 UTC (11 months, 3 weeks ago) by marktheunissen
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of Galleria module
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Turns a node into a Galleria image gallery.
7 */
8
9 /**
10 * Implementation of hook_form_alter().
11 */
12 function galleria_form_alter(&$form, $form_state, $form_id) {
13 if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
14 $form['workflow']['galleria'] = array(
15 '#type' => 'radios',
16 '#title' => t('Galleria'),
17 '#default_value' => variable_get('galleria_'. $form['#node_type']->type, 0),
18 '#options' => array(t('Disabled'), t('Enabled')),
19 '#description' => t('Convert this node type into a Galleria.')
20 );
21 }
22 }
23
24 /**
25 * Implementation of hook_theme().
26 */
27 function galleria_theme() {
28 return array(
29 'galleria' => array(
30 'template' => 'galleria',
31 'arguments' => array('node' => NULL),
32 ),
33 );
34 }
35
36 /**
37 * Implementation of hook_nodeapi().
38 */
39 function galleria_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
40 switch ($op) {
41 case 'view':
42 // abort unless we are viewing full page
43 if (!$page) {
44 break;
45 }
46
47 // abort if this is not a galleria type
48 if (variable_get("galleria_$node->type", 0) == 0) {
49 break;
50 }
51
52 // this is a galleria node, so perform modifications!
53 _galleria_includes();
54 unset($node->content);
55 $node->content['galleria']['#value'] = theme('galleria', $node);
56 $node->content['galleria']['#weight'] = 10;
57 break;
58 }
59 }
60
61 /**
62 * Include necessary files for the galleria.
63 */
64 function _galleria_includes() {
65 $modulepath = drupal_get_path('module', 'galleria');
66 drupal_add_css($modulepath . '/inc/galleria.css');
67
68 // add thickbox
69 drupal_add_js($modulepath . '/thickbox/thickbox-compressed.js');
70 drupal_add_css($modulepath . '/thickbox/thickbox.css');
71
72 // pass through the dynamic path so it can be accessed from the jquery
73 $js = "var path_to_galleria = '". base_path() . $modulepath . "';";
74 drupal_add_js($js, 'inline');
75
76 // main plugin
77 drupal_add_js($modulepath . '/inc/jquery.galleria.js');
78
79 // activate galleria on .galleria elements
80 drupal_add_js($modulepath . '/inc/galleria.js');
81 }
82
83 /**
84 * Preprocess the galleria variables.
85 */
86 function template_preprocess_galleria(&$vars) {
87 $files = $vars['node']->files;
88 $images = array();
89 $i = 0;
90
91 foreach ($files as $file) {
92 $images[] = array(
93 'data' => theme('image', $file->filepath),
94 'class' => $i == 0 ? 'active' : '',
95 );
96 $i++;
97 }
98
99 $attribs = array(
100 'class' => 'gallery',
101 );
102 $vars['gallery'] = theme('item_list', $images, NULL, 'ul', $attribs);
103 }
104
105

  ViewVC Help
Powered by ViewVC 1.1.2