gallery.module 6.72 KB
Newer Older
1
<?php
2
// $Id$
3
// For Drupal 4.7 with Gallery 2.1
4

5
6
$path = drupal_get_path('module', 'gallery');
require_once($path . '/gallery_base.inc');
7
8
9
10
11

/**
 * Implementation of hook_menu
 */
function gallery_menu($may_cache) {
12
  global $user;
13
  $items = array();
14
  $view_access = (user_access('access user profiles') || ($user->uid == arg(1)));
15
  if ($may_cache) {
kiz_0987's avatar
kiz_0987 committed
16
17
18
19
20
21
22
    $items[] = array(
      'path' => 'gallery',
      'title' => t('gallery'),
      'callback' => 'gallery_page',
      'access' => user_access('access content'),
      'type' => MENU_NORMAL_ITEM,
      ); 
23
24
25
26
    $items[] = array(
      'path' => 'admin/user/gallery', 'title' => t('gallery'),
      'callback' => 'gallery_users',
      'access' => user_access('administer users'),
kiz_0987's avatar
kiz_0987 committed
27
28
      'type' => MENU_LOCAL_TASK,
      );
29
  } else {
30
31
32
33
    // Add head info here so that it is included once only per page
    // May need modification once the merits/issues of theme_add_style are fully known
    // See http://drupal.org/node/60096
    theme_add_style(drupal_get_path('module', 'gallery') .'/drupal_g2.css');
34
35
  }
  return $items;
36
37
38
39
40
41
42
43
44
} 

/**
 * Implementation of hook_help
 */
function gallery_help($section) {
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_help.inc');
  return _gallery_help($section);
45
46
47
48
49
50
}

/**
 * Implementation of hook_settings
 */
function gallery_settings() {
51
52
53
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_settings.inc');
  return _gallery_settings();
54
55
56
57
58
}

/**
 * Implementation of hook_user
 */
59
function gallery_user($op, &$edit, &$user, $category = NULL) {
60
61
62
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_user.inc');

63
  switch ($op) {
walkah's avatar
walkah committed
64
65
66
67
68
69
70
71
  case 'login':
    /* _gallery_init() will try to create the user, if necessary */
    list ($success, $ret) = _gallery_init();
    if (!$success) {
      gallery_error(t('Unable to log in to Gallery'), $ret);
      return;
    }
    break;
72
73
74
75
76
77
  case 'logout':
    if (variable_get('gallery_valid', 0)) {
      $embedPath = variable_get('gallery_dir', './gallery2/') . 'embed.php';
      require_once($embedPath);
      $ret = GalleryEmbed::logout();
      break;
walkah's avatar
walkah committed
78
    }
79
80
81
82
83
84
85
86
87
88
  case 'view':
    return gallery_view_user($user);
  case 'insert':
    return gallery_insert_user($edit, $user);
  case 'update':
    return gallery_update_user($edit, $user);
  case 'delete':
    return gallery_delete_user($user);
  }
}
walkah's avatar
walkah committed
89

90
91
92
93
94
95
96
97
/**
 * Gallery Users Page - view a set of users
 */
function gallery_users() {
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_user.inc');
  return _gallery_users();
}
walkah's avatar
walkah committed
98

99
100
101
102
103
104
105
106
/**
 * implementation of hook_search
 */
function gallery_search($op = 'search', $keys = null) {
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_search.inc');
  return _gallery_search($op, $keys); 
}
107

108
109
110
111
112
113
114
115
/**
 * Implementation of hook_search_item to override how to display the item
 */
function gallery_search_page($results) {
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_search.inc');
  return _gallery_search_page($results); 
}  
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 * Implementation of hook_filter
 */
function gallery_filter($op, $delta = 0, $format = -1, $text = '') {
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_filter.inc');
	switch ($op) {
		case 'list' :
			return array (0 => t('Gallery2 filter'));
		case 'description' :
			return t('Allow users to easily reference Gallery2 items from nodes.');
		case 'process' :
			return gallery_filter_process($text);
		case 'no cache': 
		  return !variable_get('gallery_filter_can_cache', 1);
		default :
			return $text;
	}
}

/**
 * Implementation of hook_filter_tips
 */
function gallery_filter_tips($delta = 0, $format = -1, $long = false) {
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_help.inc');
	if ($long) {
		return gallery_filter_long_tip_translated();
	} else {
		return gallery_filter_short_tip_translated();
	}
}
walkah's avatar
walkah committed
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
 * Implementation of hook_perm().
 */
function gallery_perm() {
  return array('access standalone g2image');
}

/**
 * Implementation of hook_elements() - from img_assist
 */
function gallery_elements() {
  $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array()));
  return $type;
}

/*
 * Add image link underneath textareas
 */
function gallery_g2image_textarea($element) {
    $path = drupal_get_path('module', 'gallery');
    require_once($path . '/gallery_g2image.inc');
    if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery') && 
      (variable_get('gallery_g2image_mode', 'disabled') == 'standalone') &&
      (user_access('access standalone g2image'))) {
    gallery_g2image_add_js();
    $output = theme('gallery_g2image_textarea_link', $element, $link);
    $element['#suffix'] .= $output;
walkah's avatar
walkah committed
177
  }
178
  return $element;
179
180
181
182
183
184
}

/**
 * Implementation of hook_block
 *
 */
walkah's avatar
walkah committed
185
function gallery_block($op = 'list', $delta = 0, $edit = array()) {
kiz_0987's avatar
kiz_0987 committed
186
187
188
  $path = drupal_get_path('module', 'gallery');
  require_once($path . '/gallery_block.inc');
  return _gallery_block($op, $delta, $edit);
189
190
191
192
193
194
}

/**
 * Main gallery display page
 */
function gallery_page() {
195
  global $gallery_sidebar;
walkah's avatar
walkah committed
196
197
198
  list ($success, $ret) = _gallery_init(true);
  if (!$success) {
    gallery_error(t('Unable to initialize embedded Gallery'), $ret);
199
200
201
202
    $err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link">
              configure your embedded Gallery</a>.', 
              array('%link' => url('admin/settings/gallery')));
    return $err_msg;
walkah's avatar
walkah committed
203
  }
204
  // Turn off sidebar
205
  GalleryCapabilities::set('showSidebarBlocks', false);
walkah's avatar
walkah committed
206
  $result = GalleryEmbed::handleRequest();
207
208
  if (!$result['isDone']) {
    list($title, $css, $javascript) = GalleryEmbed::parseHead($result['headHtml']);
209
    if (!empty($javascript)) {
210
      gallery_set_html_head(implode("\n", $javascript));
211
    }
212
    gallery_set_html_head(implode("\n", $css));
213
    drupal_set_title($title);
214
215
    // Add pathbar. See http://gallery.menalto.com/node/33447
    if (isset($result['themeData'])) {
216
217
218
219
220
221
222
223
224
      $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
      $breadcrumb = array(l(t('Home'), ''));
      foreach ($result['themeData']['parents'] as $parent) {
        $parent_title = $parent['title'];
        // Simple strip of bbcode (italics) 
        $parent_title = str_replace("[i]", "<i>", $parent_title);
        $parent_title = str_replace("[/i]", "</i>", $parent_title);
        $breadcrumb[] = '<a href="'.$urlGenerator->generateUrl(
          array('itemId' => $parent['id'])) .'">'.$parent_title."</a>";
walkah's avatar
walkah committed
225
      }
226
227
228
229
230
      drupal_set_breadcrumb($breadcrumb);
    }
    // Store the sidebar info in a global variable for use in the gallery navigation block 
    $gallery_sidebar = $result['sidebarBlocksHtml'];

231
    return $result['bodyHtml'];
232
  }
walkah's avatar
walkah committed
233
}
234
235

?>