- feature: useralbum items in blocks
[project/gallery.git] / gallery.module
1 <?php
2 // $Id$
3
4 require_once(drupal_get_path('module', 'gallery') .'/gallery_base.inc');
5
6 // Default variable values
7 define(GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT, 'maxsize');
8 define(GALLERY_IMAGEBLOCK_SIZE_DEFAULT, 150);
9 define(GALLERY_GRID_SIZE_METHOD_DEFAULT, 'maxsize');
10 define(GALLERY_GRID_SIZE_DEFAULT, 90);
11 define(GALLERY_SEARCH_SIZE_METHOD_DEFAULT, 'maxsize');
12 define(GALLERY_SEARCH_SIZE_DEFAULT, 150);
13 define(GALLERY_FILTER_MAXSIZE_DEFAULT, 150);
14 define(GALLERY_FILTER_EXACTSIZE_DEFAULT, '');
15
16 /**
17 * Implementation of hook_perm().
18 */
19 function gallery_perm() {
20 return array('administer gallery settings', 'access gallery', 'access standalone g2image');
21 }
22
23 /**
24 * Implementation of hook_menu
25 */
26 function gallery_menu($may_cache) {
27 global $custom_theme;
28
29 $items = array();
30 if ($may_cache) {
31 if (variable_get('gallery_valid', 0)) {
32 $items[] = array(
33 'path' => 'gallery',
34 'title' => t('Gallery'),
35 'description' => t('Visit your embedded Gallery2.'),
36 'callback' => variable_get('gallery_page_callback', 'gallery_page'),
37 'access' => user_access('access gallery'),
38 );
39 }
40 // settings / general administration
41 $items[] = array(
42 'path' => 'admin/settings/gallery',
43 'title' => t('Gallery settings'),
44 'callback' => 'gallery_settings',
45 'callback arguments' => '_gallery_settings_general',
46 'description' => t('Configure settings for embedding Gallery2 into Drupal.'),
47 'access' => user_access('administer gallery settings'),
48 );
49 $items[] = array(
50 'path' => 'admin/settings/gallery/install',
51 'title' => t('Install'),
52 'callback' => 'gallery_settings',
53 'callback arguments' => '_gallery_settings_install',
54 'access' => user_access('administer gallery settings'),
55 'type' => variable_get('gallery_valid', 0) ? MENU_LOCAL_TASK : MENU_DEFAULT_LOCAL_TASK,
56 'weight' => 0
57 );
58 if (variable_get('gallery_valid', 0)) {
59 $items[] = array(
60 'path' => 'admin/settings/gallery/general',
61 'title' => t('General'),
62 'access' => user_access('administer gallery settings'),
63 'type' => MENU_DEFAULT_LOCAL_TASK,
64 'weight' => 1
65 );
66 $items[] = array(
67 'path' => 'admin/settings/gallery/filter',
68 'title' => t('Filter'),
69 'callback' => 'gallery_settings',
70 'callback arguments' => '_gallery_settings_filter',
71 'access' => user_access('administer gallery settings'),
72 'type' => MENU_LOCAL_TASK,
73 'weight' => 2
74 );
75 $items[] = array(
76 'path' => 'admin/settings/gallery/g2image',
77 'title' => t('G2Image'),
78 'callback' => 'gallery_settings',
79 'callback arguments' => '_gallery_settings_g2image',
80 'access' => user_access('administer gallery settings'),
81 'type' => MENU_LOCAL_TASK,
82 'weight' => 3
83 );
84 $items[] = array(
85 'path' => 'admin/settings/gallery/search',
86 'title' => t('Search'),
87 'callback' => 'gallery_settings',
88 'callback arguments' => '_gallery_settings_search',
89 'access' => user_access('administer gallery settings'),
90 'type' => MENU_LOCAL_TASK,
91 'weight' => 4
92 );
93 $items[] = array(
94 'path' => 'admin/settings/gallery/report',
95 'callback' => 'gallery_report',
96 'access' => user_access('administer site configuration'),
97 'type' => MENU_CALLBACK
98 );
99 // user administration
100 $items[] = array(
101 'path' => 'admin/user/gallery',
102 'title' => t('Gallery users'),
103 'description' => t('Gallery2 user integration and synchronization'),
104 'callback' => 'gallery_users',
105 'access' => user_access('administer users'),
106 );
107 $items[] = array(
108 'path' => 'admin/user/gallery/users',
109 'title' => t('User Status'),
110 'access' => user_access('administer users'),
111 'type' => MENU_DEFAULT_LOCAL_TASK,
112 'weight' => 0
113 );
114 $items[] = array(
115 'path' => 'admin/user/gallery/advanced',
116 'title' => t('Advanced Sync'),
117 'callback' => 'gallery_user_admin',
118 'callback arguments' => '_gallery_user_advanced',
119 'access' => user_access('administer users'),
120 'type' => MENU_LOCAL_TASK,
121 'weight' => 1
122 );
123 $items[] = array(
124 'path' => 'admin/user/gallery/settings',
125 'title' => t('User Settings'),
126 'callback' => 'gallery_user_admin',
127 'callback arguments' => '_gallery_user_settings',
128 'access' => user_access('administer users') && user_access('administer gallery settings'),
129 'type' => MENU_LOCAL_TASK,
130 'weight' => 2
131 );
132 $items[] = array(
133 'path' => 'admin/user/gallery/advanced_progress',
134 'callback' => 'gallery_user_admin_advanced_progress',
135 'access' => user_access('administer users'),
136 'type' => MENU_CALLBACK
137 );
138 $items[] = array(
139 'path' => 'admin/user/gallery/users/sync',
140 'callback' => 'gallery_users',
141 'access' => user_access('administer users'),
142 'type' => MENU_CALLBACK
143 );
144 }
145 }
146 else {
147 drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery.css');
148 drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery_filter.css');
149 // Switch theme for gallery pages
150 if (arg(0) == 'gallery' && ($custom_theme = variable_get('gallery_page_theme', NULL)) != 'default') {
151 init_theme();
152 }
153 }
154
155 return $items;
156 }
157
158 /**
159 * Implementation of hook_help
160 */
161 function gallery_help($section) {
162 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
163 return _gallery_help($section);
164 }
165
166 /**
167 * Implementation of gallery_settings
168 */
169 function gallery_settings($form = '_gallery_settings_general') {
170 require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
171 return drupal_get_form(variable_get('gallery_valid', 0) ? $form : '_gallery_settings_install');
172 }
173
174 /**
175 * Implementation of gallery_report
176 */
177 function gallery_report($download = NULL) {
178 require_once(drupal_get_path('module', 'gallery') .'/gallery_report.inc');
179 return _gallery_report(isset($download));
180 }
181
182 /**
183 * Implementation of hook_user
184 */
185 function gallery_user($op, &$edit, &$user, $category = NULL) {
186 require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
187
188 switch ($op) {
189 case 'login':
190 gallery_login();
191 break;
192 case 'logout':
193 gallery_logout();
194 case 'view':
195 return gallery_user_view($user);
196 case 'insert':
197 return gallery_user_insert($edit, drupal_clone($user));
198 case 'update':
199 return gallery_user_update($edit, drupal_clone($user));
200 case 'delete':
201 return gallery_user_delete($user);
202 }
203 }
204
205 /**
206 * Gallery User Administration
207 */
208 function gallery_users($args = NULL) {
209 require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
210 return _gallery_user_users($args);
211 }
212
213 function gallery_user_admin($form) {
214 require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
215 return drupal_get_form($form);
216 }
217
218 function gallery_user_admin_advanced_progress() {
219 require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
220 return _gallery_user_advanced_progress();
221 }
222
223 /**
224 * Implementation of hook_search
225 */
226 function gallery_search($op = 'search', $keys = NULL) {
227 require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
228 return _gallery_search($op, $keys);
229 }
230
231 /**
232 * Implementation of hook_search_item to override how to display the item
233 */
234 function gallery_search_page($results) {
235 require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
236 return _gallery_search_page($results);
237 }
238
239 /**
240 * Implementation of hook_form_alter
241 */
242 function gallery_form_alter($form_id, &$form) {
243 if (($form_id == 'user_admin_role') || ($form_id == 'user_admin_new_role')) {
244 require_once(drupal_get_path('module', 'gallery') .'/gallery_groups.inc');
245 $form['#submit']['_gallery_groups_submit'] = array();
246 }
247 if ($form_id == 'search_form' && arg(1) == 'gallery' && variable_get('gallery_search_advanced', 1) && user_access('access gallery')) {
248 require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
249 _gallery_search_form($form);
250 }
251 }
252
253 /**
254 * Implementation of hook_filter
255 */
256 function gallery_filter($op, $delta = 0, $format = -1, $text = '') {
257 require_once(drupal_get_path('module', 'gallery') .'/gallery_filter.inc');
258 switch ($op) {
259 case 'list' :
260 return array(0 => t('Gallery2 filter'));
261 case 'description' :
262 return t('Allow users to easily reference Gallery2 items from nodes.');
263 case 'process' :
264 return gallery_filter_process($text);
265 case 'no cache':
266 return !variable_get('gallery_filter_can_cache', TRUE);
267 default:
268 return $text;
269 }
270 }
271
272 /**
273 * Implementation of hook_filter_tips
274 */
275 function gallery_filter_tips($delta = 0, $format = -1, $long = FALSE) {
276 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
277 if ($long) {
278 return gallery_filter_long_tip_translated();
279 }
280 else {
281 return gallery_filter_short_tip_translated();
282 }
283 }
284
285 /**
286 * Implementation of hook_elements() - from img_assist
287 */
288 function gallery_elements() {
289 $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array()));
290 return $type;
291 }
292
293 /*
294 * Add image link underneath textareas
295 */
296 function gallery_g2image_textarea($element) {
297 require_once(drupal_get_path('module', 'gallery') .'/gallery_g2image.inc');
298 if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery')
299 && (variable_get('gallery_g2image_mode', 'disabled') == 'standalone')
300 && (user_access('access standalone g2image'))) {
301 gallery_g2image_add_js();
302 $output = theme('gallery_g2image_textarea_link', $element, $link);
303 $element['#suffix'] .= $output;
304 }
305
306 return $element;
307 }
308
309 /**
310 * Implementation of hook_block
311 *
312 */
313 function gallery_block($op = 'list', $delta = 0, $edit = array()) {
314 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
315 if (variable_get('gallery_valid', 0)) {
316 return _gallery_block($op, $delta, $edit);
317 }
318 }
319
320 /**
321 * Main gallery display page
322 */
323 function gallery_page($internal = FALSE) {
324 if (!_gallery_init(FALSE)) {
325 return $internal ? array() : '';
326 }
327 // turn off sidebar
328 if (variable_get('gallery_move_sidebar_to_block', 1)) {
329 GalleryCapabilities::set('showSidebarBlocks', FALSE);
330 }
331 $result = gallery_handle_request();
332 if ($result && !$result['isDone']) {
333 gallery_set_head($result['headHtml'], TRUE);
334 // add pathbar. See http://gallery.menalto.com/node/33447
335 if (isset($result['themeData'])) {
336 $breadcrumb = array(l(t('Home'), ''));
337 // some themes (eg hybrid) do not set $result['themeData']['parents']
338 if ($result['themeData']['parents']) {
339 foreach ($result['themeData']['parents'] as $parent) {
340 $parent_title = $parent['title'];
341 // simple strip of bbcode (italic, bold)
342 $parent_title = str_replace(
343 array('[i]', '[/i]', '[b]', '[/b]'),
344 array('<i>', '</i>', '<strong>', '</strong>'),
345 $parent_title
346 );
347 $parent_title = str_replace('[/i]', '</i>', $parent_title);
348 // still does not generate a clean url for /gallery (uses index.php?q=gallery)
349 $link = gallery_generate_url(array('view' => 'core.ShowItem', 'itemId' => $parent['id']), FALSE);
350 $breadcrumb[] = l($parent_title, $link);
351 }
352 }
353 drupal_set_breadcrumb($breadcrumb);
354 }
355 // Hack to get the admin sidebar
356 if (variable_get('gallery_move_admin_sidebar_to_block', 0)) {
357 if (preg_match("/^(.*<td id=\"gsSidebarCol\">)(.*?)(<\/td>.*?)$/s", $result['bodyHtml'], $match)) {
358 // new body
359 $result['bodyHtml'] = $match[1] . $match[3];
360 // insert admin sidebar in $result['sidebarBlocksHtml']
361 if (empty($result['sidebarBlocksHtml'][1])) {
362 $result['sidebarBlocksHtml'][1] = $match[2];
363 }
364 else {
365 $result['sidebarBlocksHtml'][] = $match[2];
366 }
367 }
368 }
369 // store the sidebar info in a global variable for use in the gallery navigation block
370 $GLOBALS['_gallery_sidebar_'] = $result['sidebarBlocksHtml'];
371
372 return $internal ? $result : $result['bodyHtml'];
373 }
374
375 return $internal ? array() : '';
376 }
377
378 /**
379 * Define additional links to add to the site map.
380 *
381 * This hook allows modules to add additional links to the site map. Links
382 * may be associated with nodes, terms, or users, as shown in the example.
383 *
384 * @param $type
385 * If given, the type of link to associate additional links with.
386 * @param $excludes
387 * If given, an array of criteria for excluding links.
388 * @return
389 * An array of links or an empty array.
390 */
391 function gallery_gsitemap($type = NULL, $excludes = array()) {
392 if (($type != 'xml') || !variable_get('gallery_enable_sitemap', 1)) {
393 return;
394 }
395
396 // Need to do a full init
397 if (!_gallery_init(TRUE)) {
398 return;
399 }
400
401 $view_name = 'sitemap.Sitemap';
402 list($ret, $view) = GalleryView::loadView($view_name);
403 if ($ret) {
404 gallery_error(t('Error loading the Gallery2 Google Sitemap. Make sure the \'Google Sitemap\' plugin is enabled in Gallery2.'), $ret);
405 return;
406 }
407 list($ret, $root_id) = GalleryCoreApi::getDefaultAlbumId();
408 if ($ret) {
409 gallery_error(t('Error loading the Gallery2 Default Album Id.'), $ret);
410 return;
411 }
412
413 // Get the sitemap from Gallery2
414 ob_start();
415 $ret = $view->renderSitemap($root_id);
416 $g2_sitemap = ob_get_contents();
417 ob_end_clean();
418
419 return $g2_sitemap;
420 }
421
422 ?>