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