4 require_once(drupal_get_path('module', 'gallery') .
'/gallery_base.inc');
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
, '');
17 * Implementation of hook_perm().
19 function gallery_perm() {
20 return array('administer gallery settings', 'access gallery', 'access standalone g2image');
24 * Implementation of hook_menu().
26 function gallery_menu($may_cache) {
31 if (variable_get('gallery_valid', 0)) {
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'),
40 // settings / general administration
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'),
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
,
58 if (variable_get('gallery_valid', 0)) {
60 'path' => 'admin/settings/gallery/general',
61 'title' => t('General'),
62 'access' => user_access('administer gallery settings'),
63 'type' => MENU_DEFAULT_LOCAL_TASK
,
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
,
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
,
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
,
94 'path' => 'admin/settings/gallery/report',
95 'callback' => 'gallery_report',
96 'access' => user_access('administer site configuration'),
97 'type' => MENU_CALLBACK
99 // user administration
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'),
108 'path' => 'admin/user/gallery/users',
109 'title' => t('User Status'),
110 'access' => user_access('administer users'),
111 'type' => MENU_DEFAULT_LOCAL_TASK
,
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
,
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
,
133 'path' => 'admin/user/gallery/advanced_progress',
134 'callback' => 'gallery_user_admin_advanced_progress',
135 'access' => user_access('administer users'),
136 'type' => MENU_CALLBACK
139 'path' => 'admin/user/gallery/users/sync',
140 'callback' => 'gallery_users',
141 'access' => user_access('administer users'),
142 'type' => MENU_CALLBACK
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') {
159 * Implementation of hook_help().
161 function gallery_help($section) {
162 require_once(drupal_get_path('module', 'gallery') .
'/gallery_help.inc');
163 return _gallery_help($section);
167 * Function gallery_settings().
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');
175 * Function gallery_report().
177 function gallery_report($download = NULL
) {
178 require_once(drupal_get_path('module', 'gallery') .
'/gallery_report.inc');
179 return _gallery_report(isset($download));
183 * Implementation of hook_info().
185 function gallery_info($field = NULL
) {
186 $info['name'] = 'Gallery2';
187 $info['protocol'] = 'internal';
189 return isset($field) ?
$info[$field] : $info;
193 * Implementation of hook_auth().
195 function gallery_auth($username, $password, $server) {
196 if (_gallery_init()) {
197 // Is the user allowed to login?
198 list($ret, $disabled) = GalleryCoreApi
::isDisabledUsername($username);
199 if (!$ret && !$disabled) {
200 // Load G2 user to get the hashed password
201 list($ret, $g2_user) = GalleryCoreApi
::fetchUserByUsername($username);
203 // Authenticate the G2 user
204 if (GalleryUtilities
::isCorrectPassword($password, $g2_user->hashedPassword
)) {
205 // Override the Drupal password (so that next time the user can be authenticated directly)
206 if ($user = user_load(array('name' => $username, 'status' => 1))) {
207 user_save($user, array('pass' => $password));
219 * Implementation of hook_user().
221 function gallery_user($op, &$edit, &$user, $category = NULL
) {
222 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user.inc');
232 return gallery_user_view($user);
234 return gallery_user_insert($edit, drupal_clone($user));
236 return gallery_user_update($edit, drupal_clone($user));
238 return gallery_user_delete($user);
243 * Function gallery_users().
244 * (gallery user administration)
246 function gallery_users($args = NULL
) {
247 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc');
248 return _gallery_user_users($args);
252 * Function gallery_user_admin().
254 function gallery_user_admin($form) {
255 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc');
256 return drupal_get_form($form);
260 * Function gallery_user_admin_advanced_progress().
262 function gallery_user_admin_advanced_progress() {
263 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc');
264 return _gallery_user_advanced_progress();
268 * Implementation of hook_search().
270 function gallery_search($op = 'search', $keys = NULL
) {
271 require_once(drupal_get_path('module', 'gallery') .
'/gallery_search.inc');
272 return _gallery_search($op, $keys);
276 * Implementation of hook_search_item().
277 * (override how to display the item)
279 function gallery_search_page($results) {
280 require_once(drupal_get_path('module', 'gallery') .
'/gallery_search.inc');
281 return _gallery_search_page($results);
285 * Implementation of hook_form_alter().
287 function gallery_form_alter($form_id, &$form) {
288 if (($form_id == 'user_admin_role') || ($form_id == 'user_admin_new_role')) {
289 require_once(drupal_get_path('module', 'gallery') .
'/gallery_groups.inc');
290 $form['#submit']['_gallery_groups_submit'] = array();
292 if ($form_id == 'search_form' && arg(1) == 'gallery' && variable_get('gallery_search_advanced', 1) && user_access('access gallery')) {
293 require_once(drupal_get_path('module', 'gallery') .
'/gallery_search.inc');
294 _gallery_search_form($form);
299 * Implementation of hook_filter().
301 function gallery_filter($op, $delta = 0, $format = -1, $text = '') {
302 require_once(drupal_get_path('module', 'gallery') .
'/gallery_filter.inc');
305 return array(0 => t('Gallery2 filter'));
307 return t('Allow users to easily reference Gallery2 items from nodes.');
309 return gallery_filter_process($text);
311 return !variable_get('gallery_filter_can_cache', TRUE
);
318 * Implementation of hook_filter_tips().
320 function gallery_filter_tips($delta = 0, $format = -1, $long = FALSE
) {
321 require_once(drupal_get_path('module', 'gallery') .
'/gallery_help.inc');
323 return gallery_filter_long_tip_translated();
326 return gallery_filter_short_tip_translated();
331 * Implementation of hook_elements().
333 function gallery_elements() {
334 $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array()));
339 * Function gallery_g2image_textarea().
340 * (add image link underneath textareas)
342 function gallery_g2image_textarea($element) {
343 require_once(drupal_get_path('module', 'gallery') .
'/gallery_g2image.inc');
344 if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery')
345 && (variable_get('gallery_g2image_mode', 'disabled') == 'standalone')
346 && (user_access('access standalone g2image'))) {
347 gallery_g2image_add_js();
348 $output = theme('gallery_g2image_textarea_link', $element, $link);
349 $element['#suffix'] .
= $output;
356 * Implementation of hook_block().
358 function gallery_block($op = 'list', $delta = 0, $edit = array()) {
359 require_once(drupal_get_path('module', 'gallery') .
'/gallery_block.inc');
360 if (variable_get('gallery_valid', 0)) {
361 return _gallery_block($op, $delta, $edit);
366 * Function gallery_page().
367 * (main gallery display page)
369 function gallery_page($internal = FALSE
) {
370 if (!_gallery_init()) {
371 return $internal ?
array() : '';
374 if (variable_get('gallery_move_sidebar_to_block', 1)) {
375 GalleryCapabilities
::set('showSidebarBlocks', FALSE
);
377 $result = gallery_handle_request();
378 if ($result && !$result['isDone']) {
379 gallery_set_head($result['headHtml'], TRUE
);
380 // Add pathbar (see http://gallery.menalto.com/node/33447)
381 if (isset($result['themeData'])) {
382 $breadcrumb = array(l(t('Home'), ''));
383 // Some themes (eg hybrid) do not set $result['themeData']['parents']
384 if ($result['themeData']['parents']) {
385 foreach ($result['themeData']['parents'] as
$parent) {
386 $parent_title = $parent['title'];
387 // Simple strip of bbcode (italic, bold)
388 $parent_title = str_replace(
389 array('[i]', '[/i]', '[b]', '[/b]'),
390 array('<i>', '</i>', '<strong>', '</strong>'),
393 $parent_title = str_replace('[/i]', '</i>', $parent_title);
394 // Still does not generate a clean url for /gallery (uses index.php?q=gallery)
395 $link = gallery_generate_url(array('view' => 'core.ShowItem', 'itemId' => $parent['id']), FALSE
);
396 $breadcrumb[] = l($parent_title, $link);
399 drupal_set_breadcrumb($breadcrumb);
401 // Hack to get the admin sidebar
402 if (variable_get('gallery_move_admin_sidebar_to_block', 0)) {
403 if (preg_match("/^(.*<td id=\"gsSidebarCol\">)(.*?)(<\/td>.*?)$/s", $result['bodyHtml'], $match)) {
405 $result['bodyHtml'] = $match[1] .
$match[3];
406 // Insert admin sidebar in $result['sidebarBlocksHtml']
407 if (empty($result['sidebarBlocksHtml'][1])) {
408 $result['sidebarBlocksHtml'][1] = $match[2];
411 $result['sidebarBlocksHtml'][] = $match[2];
415 // Store the sidebar info in a global variable for use in the gallery navigation block
416 $GLOBALS['_gallery_sidebar_'] = $result['sidebarBlocksHtml'];
418 return $internal ?
$result : $result['bodyHtml'];
421 return $internal ?
array() : '';
425 * Function gallery_gsitemap().
426 * (define additional links to add to the site map)
428 * This hook allows modules to add additional links to the site map. Links
429 * may be associated with nodes, terms, or users, as shown in the example.
432 * If given, the type of link to associate additional links with.
434 * If given, an array of criteria for excluding links.
436 * An array of links or an empty array.
438 function gallery_gsitemap($type = NULL
, $excludes = array()) {
439 if (($type != 'xml') || !variable_get('gallery_enable_sitemap', 1)) {
442 // Need to do a full init
443 if (!_gallery_init(TRUE
)) {
447 $view_name = 'sitemap.Sitemap';
448 list($ret, $view) = GalleryView
::loadView($view_name);
450 gallery_error(t('Error loading the Gallery2 Google Sitemap. Make sure the \'Google Sitemap\' plugin is enabled in Gallery2.'), $ret);
453 list($ret, $root_id) = GalleryCoreApi
::getDefaultAlbumId();
455 gallery_error(t('Error loading the Gallery2 Default Album Id.'), $ret);
459 // Get the sitemap from Gallery2
461 $ret = $view->renderSitemap($root_id);
462 $g2_sitemap = ob_get_contents();