array( 'arguments' => array('status' => NULL), ), 'gallery_severity_message' => array( 'arguments' => array('severity' => NULL), ), 'gallery_plugin_status_message' => array( 'arguments' => array('status' => NULL, 'invert' => FALSE), ), 'gallery_severity_status_message' => array( 'arguments' => array('severity' => NULL, 'status' => NULL, 'full_msg' => FALSE, 'invert' => FALSE), ), 'gallery_report' => array( 'arguments' => array('report' => FALSE), ) ); } /** * Implementation of hook_init(). */ function gallery_init() { global $custom_theme; // Include CSS drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery.css'); drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery_filter.css'); // Switch theme for gallery pages if (arg(0) == 'gallery' && (($theme = variable_get('gallery_page_theme', NULL)) != 'default')) { $custom_theme = $theme; init_theme(); } } /** * Implementation of hook_menu(). */ function gallery_menu() { $items = array(); $gallery_valid = variable_get('gallery_valid', 0); if ($gallery_valid) { $items['gallery'] = array( 'title' => 'Gallery', 'description' => 'Visit your embedded Gallery2.', 'access callback' => 'user_access', 'access arguments' => array('access gallery'), 'page callback' => variable_get('gallery_page_callback', 'gallery_page') ); } // Settings / General administration $items['admin/settings/gallery'] = array( 'title' => 'Gallery settings', 'description' => 'Configure settings for embedding Gallery2 into Drupal.', 'access callback' => 'user_access', 'access arguments' => array('administer gallery settings'), 'file' => $gallery_valid ? 'gallery_settings.inc' : 'gallery_install.inc', 'page callback' => 'drupal_get_form', 'page arguments' => $gallery_valid ? array('_gallery_settings_general') : array('_gallery_install') ); $items['admin/settings/gallery/install'] = array( 'title' => 'Install', 'access callback' => 'user_access', 'access arguments' => array('administer gallery settings'), 'file' => 'gallery_install.inc', 'page callback' => 'drupal_get_form', 'page arguments' => $gallery_valid ? array('_gallery_install_status') : array('_gallery_install'), 'type' => $gallery_valid ? MENU_LOCAL_TASK : MENU_DEFAULT_LOCAL_TASK, 'weight' => 0 ); if ($gallery_valid) { $items['admin/settings/gallery/general'] = array( 'title' => 'General', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 1 ); $items['admin/settings/gallery/filter'] = array( 'title' => 'Filter', 'access callback' => 'user_access', 'access arguments' => array('administer gallery settings'), 'file' => 'gallery_settings.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('_gallery_settings_filter'), 'type' => MENU_LOCAL_TASK, 'weight' => 2 ); $items['admin/settings/gallery/g2image'] = array( 'title' => 'G2Image', 'access callback' => 'user_access', 'access arguments' => array('administer gallery settings'), 'file' => 'gallery_settings.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('_gallery_settings_g2image'), 'type' => MENU_LOCAL_TASK, 'weight' => 3 ); if (module_exists('search')) { $items['admin/settings/gallery/search'] = array( 'title' => 'Search', 'access callback' => 'user_access', 'access arguments' => array('administer gallery settings'), 'file' => 'gallery_settings.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('_gallery_settings_search'), 'type' => MENU_LOCAL_TASK, 'weight' => 4 ); } $items['admin/settings/gallery/report'] = array( 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'file' => 'gallery_report.inc', 'page callback' => '_gallery_report', 'page arguments' => array(FALSE), 'type' => MENU_CALLBACK ); $items['admin/settings/gallery/report/download'] = array( 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'file' => 'gallery_report.inc', 'page callback' => '_gallery_report', 'page arguments' => array(TRUE), 'type' => MENU_CALLBACK ); // User administration $items['admin/user/gallery'] = array( 'title' => 'Gallery users', 'description' => 'Gallery2 user integration and synchronization.', 'access callback' => 'user_access', 'access arguments' => array('administer users'), 'file' => 'gallery_user_admin.inc', 'page callback' => '_gallery_user_users' ); $items['admin/user/gallery/users'] = array( 'title' => 'User Status', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 0 ); $items['admin/user/gallery/advanced'] = array( 'title' => 'Advanced Sync', 'access callback' => 'user_access', 'access arguments' => array('administer users'), 'file' => 'gallery_user_admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('_gallery_user_advanced'), 'type' => MENU_LOCAL_TASK, 'weight' => 1 ); $items['admin/user/gallery/settings'] = array( 'title' => 'User Settings', 'access callback' => 'gallery_admin_access', 'access arguments' => array(array('administer users', 'administer gallery settings')), 'file' => 'gallery_user_admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('_gallery_user_settings'), 'type' => MENU_LOCAL_TASK, 'weight' => 2 ); $items['admin/user/gallery/users/sync/%'] = array( 'access callback' => 'user_access', 'access arguments' => array('administer users'), 'file' => 'gallery_user_admin.inc', 'page callback' => '_gallery_user_users_sync', 'page arguments' => array(5), 'type' => MENU_CALLBACK ); } return $items; } /** * Function gallery_admin_access(). */ function gallery_admin_access($perms) { foreach ($perms as $perm) { if (!user_access($perm)) { return FALSE; } } return count($perms); } /** * Implementation of hook_help(). */ function gallery_help($section) { require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc'); return _gallery_help($section); } /** * Function gallery_auth_validate(). * (authenticate user against G2 directly) */ function gallery_auth_validate($form, &$form_state) { if (_gallery_init()) { $username = $form_state['values']['name']; $password = trim($form_state['values']['pass']); // Is the user allowed to login? list($ret, $disabled) = GalleryCoreApi::isDisabledUsername($username); if (!$ret && !$disabled) { // Load G2 user to get the hashed password list($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($username); if (!$ret) { // Authenticate the G2 user if (GalleryUtilities::isCorrectPassword($password, $g2_user->hashedPassword)) { // Does this user exist in Drupal, then override password // (so that next time the user can be authenticated directly) if ($user = user_load(array('name' => $username, 'status' => 1))) { user_save($user, array('pass' => $password)); return TRUE; } } } } } return FALSE; } /** * Implementation of hook_user(). */ function gallery_user($op, &$edit, &$user, $category = NULL) { require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc'); switch ($op) { case 'login': gallery_login(); break; case 'logout': gallery_logout(); break; case 'view': return gallery_user_view($user); case 'insert': return gallery_user_insert($edit, drupal_clone($user)); case 'update': return gallery_user_update($edit, drupal_clone($user)); case 'delete': return gallery_user_delete($user); } } /** * Implementation of hook_search(). */ function gallery_search($op = 'search', $keys = NULL) { require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc'); return _gallery_search($op, $keys); } /** * Implementation of hook_search_item(). * (override how to display the item) */ function gallery_search_page($results) { require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc'); return _gallery_search_page($results); } /** * Implementation of hook_form_alter(). */ function gallery_form_alter(&$form, $form_state, $form_id) { // Trigger groups sync if Drupal roles are added/modified if (($form_id == 'user_admin_role') || ($form_id == 'user_admin_new_role')) { require_once(drupal_get_path('module', 'gallery') .'/gallery_groups.inc'); $form['#submit'][] = '_gallery_groups_submit'; } // Add a custom search form if ($form_id == 'search_form' && arg(1) == 'gallery' && variable_get('gallery_search_advanced', 1) && user_access('access gallery')) { require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc'); _gallery_search_form($form); } // Add _validate() handler for external authentication if ($form_id == 'user_login_block' || $form_id == 'user_login') { $form['#validate'][] = 'gallery_auth_validate'; } } /** * Implementation of hook_filter(). */ function gallery_filter($op, $delta = 0, $format = -1, $text = '') { require_once(drupal_get_path('module', 'gallery') .'/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', TRUE); default: return $text; } } /** * Implementation of hook_filter_tips(). */ function gallery_filter_tips($delta = 0, $format = -1, $long = FALSE) { require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc'); return $long ? gallery_filter_long_tip_translated() : gallery_filter_short_tip_translated(); } /** * Implementation of hook_elements(). */ function gallery_elements() { $type['textarea'] = array('#process' => array('gallery_g2image_textarea')); return $type; } /** * Function gallery_g2image_textarea(). * (add image link underneath textareas) */ function gallery_g2image_textarea($element) { require_once(drupal_get_path('module', 'gallery') .'/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; } return $element; } /** * Implementation of hook_block(). */ function gallery_block($op = 'list', $delta = 0, $edit = array()) { require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc'); if (variable_get('gallery_valid', 0)) { return _gallery_block($op, $delta, $edit); } } /** * Function gallery_page(). * (main gallery display page) */ function gallery_page() { if (!_gallery_init(FALSE)) { return ''; } // Turn off sidebar if (variable_get('gallery_move_sidebar_to_block', 1)) { GalleryCapabilities::set('showSidebarBlocks', FALSE); } $result = gallery_handle_request(); if ($result && !$result['isDone']) { // Allow modules to alter the page drupal_alter('gallery_page', $result); // Add css/js for this page gallery_set_head($result['headHtml'], TRUE); // Add pathbar. See http://gallery.menalto.com/node/33447 if (isset($result['themeData'])) { $breadcrumb = array(l(t('Home'), '')); // Some themes (eg hybrid) do not set $result['themeData']['parents'] if ($result['themeData']['parents']) { foreach ($result['themeData']['parents'] as $parent) { $parent_title = $parent['title']; // Simple strip of BBCode (italic, bold) $parent_title = str_replace( array('[i]', '[/i]', '[b]', '[/b]'), array('', '', '', ''), $parent_title ); $parent_title = str_replace('[/i]', '', $parent_title); // Still does not generate a clean url for /gallery (uses index.php?q=gallery) $link = gallery_generate_url(array('itemId' => $parent['id']), FALSE); // TODO (#154507 + i18n-rewrite): $link = TRUE ? str_replace('?q=gallery', 'gallery', $link) : $link; $breadcrumb[] = l($parent_title, $link); } } drupal_set_breadcrumb($breadcrumb); } // Hack to get the admin sidebar if (variable_get('gallery_move_admin_sidebar_to_block', 0)) { if (preg_match("/^(.*