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 * Implementation of 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 * Implementation of 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_user
185 function gallery_user($op, &$edit, &$user, $category = NULL
) {
186 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user.inc');
195 return gallery_user_view($user);
197 return gallery_user_insert($edit, drupal_clone($user));
199 return gallery_user_update($edit, drupal_clone($user));
201 return gallery_user_delete($user);
206 * Gallery User Administration
208 function gallery_users($args = NULL
) {
209 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc');
210 return _gallery_user_users($args);
213 function gallery_user_admin($form) {
214 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc');
215 return drupal_get_form($form);
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();
224 * Implementation of hook_search
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);
232 * Implementation of hook_search_item to override how to display the item
234 function gallery_search_page($results) {
235 require_once(drupal_get_path('module', 'gallery') .
'/gallery_search.inc');
236 return _gallery_search_page($results);
240 * Implementation of hook_form_alter
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();
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);
254 * Implementation of hook_filter
256 function gallery_filter($op, $delta = 0, $format = -1, $text = '') {
257 require_once(drupal_get_path('module', 'gallery') .
'/gallery_filter.inc');
260 return array(0 => t('Gallery2 filter'));
262 return t('Allow users to easily reference Gallery2 items from nodes.');
264 return gallery_filter_process($text);
266 return !variable_get('gallery_filter_can_cache', TRUE
);
273 * Implementation of hook_filter_tips
275 function gallery_filter_tips($delta = 0, $format = -1, $long = FALSE
) {
276 require_once(drupal_get_path('module', 'gallery') .
'/gallery_help.inc');
278 return gallery_filter_long_tip_translated();
281 return gallery_filter_short_tip_translated();
286 * Implementation of hook_elements() - from img_assist
288 function gallery_elements() {
289 $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array()));
294 * Add image link underneath textareas
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;
310 * Implementation of hook_block
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);
321 * Main gallery display page
323 function gallery_page($internal = FALSE
) {
324 if (!_gallery_init(FALSE
)) {
325 return $internal ?
array() : '';
328 if (variable_get('gallery_move_sidebar_to_block', 1)) {
329 GalleryCapabilities
::set('showSidebarBlocks', FALSE
);
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>'),
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);
353 drupal_set_breadcrumb($breadcrumb);
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)) {
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];
365 $result['sidebarBlocksHtml'][] = $match[2];
369 // store the sidebar info in a global variable for use in the gallery navigation block
370 $GLOBALS['_gallery_sidebar_'] = $result['sidebarBlocksHtml'];
372 return $internal ?
$result : $result['bodyHtml'];
375 return $internal ?
array() : '';
379 * Define additional links to add to the site map.
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.
385 * If given, the type of link to associate additional links with.
387 * If given, an array of criteria for excluding links.
389 * An array of links or an empty array.
391 function gallery_gsitemap($type = NULL
, $excludes = array()) {
392 if (($type != 'xml') || !variable_get('gallery_enable_sitemap', 1)) {
396 // Need to do a full init
397 if (!_gallery_init(TRUE
)) {
401 $view_name = 'sitemap.Sitemap';
402 list($ret, $view) = GalleryView
::loadView($view_name);
404 gallery_error(t('Error loading the Gallery2 Google Sitemap. Make sure the \'Google Sitemap\' plugin is enabled in Gallery2.'), $ret);
407 list($ret, $root_id) = GalleryCoreApi
::getDefaultAlbumId();
409 gallery_error(t('Error loading the Gallery2 Default Album Id.'), $ret);
413 // Get the sitemap from Gallery2
415 $ret = $view->renderSitemap($root_id);
416 $g2_sitemap = ob_get_contents();