aboutsummaryrefslogtreecommitdiff
path: root/jquery_gallery_view.module
blob: 4006e7da2be681ebac759887dc08e8eead8709f9 (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
<?php
// $Id$

/**
 * @file
 * jQuery GalleryView module.
 */

/**
 * Implementation of hook_menu().
 */
function jquery_gallery_view_menu() {
  $items['jquery_gallery_view'] = array(
    'page callback'    => 'jquery_gallery_view',
    'access arguments' => array('access content'),
    'type'             => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Implementation of hook_theme().
 */
function jquery_gallery_view_theme() {
  return array(
    'jquery_gallery_view' => array(
      'arguments'         => array(
        'images'          => array(),
      ),
    ),
  );
}

/**
 * Menu callback.
 */
function jquery_gallery_view() {
  return jquery_gallery_view_setup_photos();
}

/**
 * Load needed javascript files.
 */
function jquery_gallery_view_load() {
  drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/jquery_gallery_view.js');
  drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/galleryview/jquery.galleryview-2.1.1-pack.js');
  drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/galleryview/jquery.timers-1.2.js');
}

/**
 * Setup photos for a view.
 *
 * @param $viewname
 *   View data.
 *
 * @param $field
 *   File field name.
 *
 * @param $title
 *   Title field name.
 */
function jquery_gallery_view_setup_photos($viewname = 'foto', $field = 'field_foto_fid', $title = 'field_xmp_title_value') {
  global $base_url;
  $files = variable_get('file_directory_path', conf_path() .'/files');
  $view  = views_get_view($viewname);
  $view->execute();

  $field = $view->display_handler->get_handler('field', $field)->field_alias;
  $title = $view->display_handler->get_handler('field', $title)->field_alias;

  foreach ($view->result as $result) {
    $fid = $result->{$field};
    if ($fid != NULL) {
      $file     = field_file_load($fid);        
      $text     = $result->{$title};
      $images[] = array(
        'url'   => $base_url .'/'. $files .'/imagecache/65x40/images/'. $file['filename'],
        'title' => $text,
      );
    }
  }

  echo theme('jquery_gallery_view', $images);
  exit;
}

/**
 * Theme a jQuery Gallery list.
 *
 * @param $images
 *   Array with images's urls and titles.
 *
 * @return
 *   HTML list of images.
 */
function theme_jquery_gallery_view($images = array()) {
  $output = '<ul id="jquery-gallery-view">';

  foreach ($images as $image) {
    $output .= '<li><span class="panel-overlay">'. $image['title'] . '</span><img src="' . $image['url'] .'" /></li>';
  }

  $output .= '</ul>';
  return $output;
}