| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery.module,v 1.28.2.17 2008/06/18 20:10:44 profix898 Exp $ 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_theme(). 18 */ 19 function gallery_theme() { 20 return array( 21 'gallery_module_status_message' => array( 22 'arguments' => array('status' => NULL), 23 ), 24 'gallery_severity_message' => array( 25 'arguments' => array('severity' => NULL), 26 ), 27 'gallery_plugin_status_message' => array( 28 'arguments' => array('status' => NULL, 'invert' => FALSE), 29 ), 30 'gallery_severity_status_message' => array( 31 'arguments' => array('severity' => NULL, 'status' => NULL, 'full_msg' => FALSE, 'invert' => FALSE), 32 ), 33 'gallery_report' => array( 34 'arguments' => array('report' => FALSE), 35 ), 36 'gallery_block_image_block' => array( 37 'template' => 'gallery-block-image-block', 38 'file' => 'gallery_block.inc', 39 'arguments' => array('content' => NULL, 'class' => NULL), 40 ), 41 'gallery_block_grid_block' => array( 42 'template' => 'gallery-block-grid-block', 43 'file' => 'gallery_block.inc', 44 'arguments' => array('content' => NULL, 'num_cols' => NULL, 'class' => NULL, 'images' => NULL), 45 ), 46 'gallery_search_item' => array( 47 'arguments' => array('item' => NULL), 48 ) 49 ); 50 } 51 52 /** 53 * Implementation of hook_perm(). 54 */ 55 function gallery_perm() { 56 return array('administer gallery settings', 'access gallery'); 57 } 58 59 /** 60 * Implementation of hook_init(). 61 */ 62 function gallery_init() { 63 global $custom_theme; 64 // Include CSS 65 drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery.css'); 66 drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery_filter.css'); 67 // Switch Drupal theme for gallery pages 68 if (arg(0) == variable_get('gallery_base', 'gallery') && (($theme = variable_get('gallery_page_theme', NULL)) != 'default')) { 69 $custom_theme = $theme; 70 init_theme(); 71 } 72 } 73 74 /** 75 * Implementation of hook_gallery_init_alter(). 76 */ 77 function gallery_gallery_init_alter($params, $context) { 78 if (!$context['fullInit'] || !$context['ready']['half']) { 79 // Set G2 theme for embedded gallery 80 if (isset($params['themeId'])) { 81 $params['eventListeners'][] = array( 82 'class' => 'G2DrupalSimpleThemeEventListener', 83 'events' => array('Gallery::LoadThemeAndParameters'), 84 'params' => array('themeId' => $params['themeId']) 85 ); 86 } 87 // We need to flush the cache if a G2 item is being updated 88 // and Drupal's page cache is enabled 89 if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { 90 $params['eventListeners'][] = array( 91 'class' => 'G2DrupalPageCacheEventListener', 92 'events' => array('GalleryEntity::save', 'GalleryEntity::delete') 93 ); 94 } 95 } 96 } 97 98 /** 99 * Implementation of hook_menu(). 100 */ 101 function gallery_menu() { 102 $items = array(); 103 $gallery_valid = variable_get('gallery_valid', 0); 104 if ($gallery_valid) { 105 $items[variable_get('gallery_base', 'gallery')] = array( 106 'title' => 'Gallery', 107 'description' => 'Visit your embedded Gallery2.', 108 'access callback' => 'user_access', 109 'access arguments' => array('access gallery'), 110 'page callback' => 'gallery_page' 111 ); 112 } 113 // Settings / General administration 114 $items['admin/settings/gallery'] = array( 115 'title' => 'Gallery settings', 116 'description' => 'Configure settings for embedding Gallery2 into Drupal.', 117 'access callback' => 'user_access', 118 'access arguments' => array('administer gallery settings'), 119 'file' => $gallery_valid ? 'gallery_settings.inc' : 'gallery_install.inc', 120 'page callback' => 'drupal_get_form', 121 'page arguments' => $gallery_valid ? array('_gallery_settings_general') : array('_gallery_install') 122 ); 123 $items['admin/settings/gallery/install'] = array( 124 'title' => 'Install', 125 'access callback' => 'user_access', 126 'access arguments' => array('administer gallery settings'), 127 'file' => 'gallery_install.inc', 128 'page callback' => 'drupal_get_form', 129 'page arguments' => $gallery_valid ? array('_gallery_install_status') : array('_gallery_install'), 130 'type' => $gallery_valid ? MENU_LOCAL_TASK : MENU_DEFAULT_LOCAL_TASK, 131 'weight' => 0 132 ); 133 if ($gallery_valid) { 134 $items['admin/settings/gallery/general'] = array( 135 'title' => 'General', 136 'type' => MENU_DEFAULT_LOCAL_TASK, 137 'weight' => 1 138 ); 139 $items['admin/settings/gallery/filter'] = array( 140 'title' => 'Filter', 141 'access callback' => 'user_access', 142 'access arguments' => array('administer gallery settings'), 143 'file' => 'gallery_settings.inc', 144 'page callback' => 'drupal_get_form', 145 'page arguments' => array('_gallery_settings_filter'), 146 'type' => MENU_LOCAL_TASK, 147 'weight' => 2 148 ); 149 if (module_exists('search')) { 150 $items['admin/settings/gallery/search'] = array( 151 'title' => 'Search', 152 'access callback' => 'user_access', 153 'access arguments' => array('administer gallery settings'), 154 'file' => 'gallery_settings.inc', 155 'page callback' => 'drupal_get_form', 156 'page arguments' => array('_gallery_settings_search'), 157 'type' => MENU_LOCAL_TASK, 158 'weight' => 4 159 ); 160 } 161 $items['admin/settings/gallery/report'] = array( 162 'access callback' => 'user_access', 163 'access arguments' => array('administer site configuration'), 164 'file' => 'gallery_report.inc', 165 'page callback' => '_gallery_report', 166 'page arguments' => array(FALSE), 167 'type' => MENU_CALLBACK 168 ); 169 $items['admin/settings/gallery/report/download'] = array( 170 'access callback' => 'user_access', 171 'access arguments' => array('administer site configuration'), 172 'file' => 'gallery_report.inc', 173 'page callback' => '_gallery_report', 174 'page arguments' => array(TRUE), 175 'type' => MENU_CALLBACK 176 ); 177 // User administration 178 $items['admin/user/gallery'] = array( 179 'title' => 'Gallery users', 180 'description' => 'Gallery2 user integration and synchronization.', 181 'access callback' => 'user_access', 182 'access arguments' => array('administer users'), 183 'file' => 'gallery_user_admin.inc', 184 'page callback' => '_gallery_user_users' 185 ); 186 $items['admin/user/gallery/users'] = array( 187 'title' => 'User Status', 188 'type' => MENU_DEFAULT_LOCAL_TASK, 189 'weight' => 0 190 ); 191 $items['admin/user/gallery/advanced'] = array( 192 'title' => 'Advanced Sync', 193 'access callback' => 'user_access', 194 'access arguments' => array('administer users'), 195 'file' => 'gallery_user_admin.inc', 196 'page callback' => 'drupal_get_form', 197 'page arguments' => array('_gallery_user_advanced'), 198 'type' => MENU_LOCAL_TASK, 199 'weight' => 1 200 ); 201 $items['admin/user/gallery/settings'] = array( 202 'title' => 'User Settings', 203 'access callback' => 'gallery_admin_access', 204 'access arguments' => array(array('administer users', 'administer gallery settings')), 205 'file' => 'gallery_user_admin.inc', 206 'page callback' => 'drupal_get_form', 207 'page arguments' => array('_gallery_user_settings'), 208 'type' => MENU_LOCAL_TASK, 209 'weight' => 2 210 ); 211 $items['admin/user/gallery/users/sync/%'] = array( 212 'access callback' => 'user_access', 213 'access arguments' => array('administer users'), 214 'file' => 'gallery_user_admin.inc', 215 'page callback' => '_gallery_user_users_sync', 216 'page arguments' => array(5), 217 'type' => MENU_CALLBACK 218 ); 219 220 if (_gallery_init(TRUE)) { 221 // Derive $skiparg parameter from current rewrite rules 222 // (only required if url rewrite is enabled) 223 $skiparg = 0; 224 $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); 225 if (isset($url_generator->_shortUrls)) { 226 list ($ret, $rules) = GalleryCoreApi::getPluginParameter('module', 'rewrite', 'activeRules'); 227 if (!$ret) { 228 $rules = unserialize($rules); 229 $key = array_search('%path%', explode('/', $rules['rewrite'][0]['pattern'])); 230 $skiparg = ($key === FALSE) ? 0 : $key; 231 } 232 } 233 variable_set('gallery_skiparg', $skiparg); 234 // Build the router items for gallery paths 235 for ($i=1; $i<=MENU_MAX_PARTS; $i++) { 236 $path = variable_get('gallery_base', 'gallery') .'/'. implode('/', array_fill(0, $i, '%gallery')); 237 $items[$path] = array( 238 'access callback' => ($i < $skiparg) ? FALSE : 'gallery_item_access', 239 'access arguments' => array($i), 240 'load arguments' => array('%map', '%index'), 241 'type' => MENU_CALLBACK 242 ); 243 } 244 } 245 } 246 247 return $items; 248 } 249 250 /** 251 * Function gallery_load(). 252 * (_load callback for the menu handler) 253 */ 254 function gallery_load($arg, $map, $index) { 255 if (!_gallery_init(TRUE)) { 256 return FALSE; 257 } 258 259 // Skip args that are static in the G2 rewrite rules 260 $skiparg = variable_get('gallery_skiparg', 0); 261 if ($index < $skiparg) { 262 return $arg; 263 } 264 265 // Check whether the $arg item/path exists and return the G2 item id (if available) 266 $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); 267 $path = isset($url_generator->_shortUrls) ? implode('/', array_slice($map, $skiparg)) : $arg; 268 if (($id = gallery_check_path2id($path)) !== FALSE) { 269 return ($index+1 < count($map)) ? $arg : $id; 270 } 271 272 return FALSE; 273 } 274 275 /** 276 * Function gallery_admin_access(). 277 */ 278 function gallery_admin_access($perms) { 279 foreach ($perms as $perm) { 280 if (!user_access($perm)) { 281 return FALSE; 282 } 283 } 284 285 return count($perms); 286 } 287 288 /** 289 * Implementation of hook_help(). 290 */ 291 function gallery_help($section) { 292 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc'); 293 return _gallery_help($section); 294 } 295 296 /** 297 * Function gallery_auth_validate(). 298 * (authenticate user against G2 directly) 299 */ 300 function gallery_auth_validate($form, &$form_state) { 301 if (_gallery_init()) { 302 $username = $form_state['values']['name']; 303 $password = trim($form_state['values']['pass']); 304 // Is the user allowed to login? 305 list($ret, $disabled) = GalleryCoreApi::isDisabledUsername($username); 306 if (!$ret && !$disabled) { 307 // Load G2 user to get the hashed password 308 list($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($username); 309 if (!$ret) { 310 // Authenticate the G2 user 311 if (GalleryUtilities::isCorrectPassword($password, $g2_user->hashedPassword)) { 312 // If this user exists in Drupal then override password 313 // (so that next time the user can be authenticated directly) 314 if ($user = user_load(array('name' => $username, 'status' => 1))) { 315 user_save($user, array('pass' => $password)); 316 return TRUE; 317 } 318 } 319 } 320 } 321 } 322 323 return FALSE; 324 } 325 326 /** 327 * Implementation of hook_user(). 328 */ 329 function gallery_user($op, &$edit, &$user, $category = NULL) { 330 require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc'); 331 switch ($op) { 332 case 'login': 333 gallery_login(); 334 break; 335 case 'logout': 336 gallery_logout(); 337 break; 338 case 'view': 339 return gallery_user_view($user); 340 case 'insert': 341 return gallery_user_insert($edit, drupal_clone($user)); 342 case 'update': 343 return gallery_user_update($edit, drupal_clone($user)); 344 case 'delete': 345 return gallery_user_delete($user); 346 } 347 } 348 349 /** 350 * Implementation of hook_search(). 351 */ 352 function gallery_search($op = 'search', $keys = NULL) { 353 if (user_access('access gallery') && (gallery_single_plugin_status('search') == GALLERY_PLUGIN_ENABLED)) { 354 require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc'); 355 return _gallery_search($op, $keys); 356 } 357 } 358 359 /** 360 * Implementation of hook_search_item(). 361 * (override how to display the item) 362 */ 363 function gallery_search_page($results) { 364 require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc'); 365 return _gallery_search_page($results); 366 } 367 368 /** 369 * Implementation of hook_form_alter(). 370 */ 371 function gallery_form_alter(&$form, $form_state, $form_id) { 372 // Trigger groups sync if Drupal roles are added/modified 373 if (($form_id == 'user_admin_role') || ($form_id == 'user_admin_new_role')) { 374 require_once(drupal_get_path('module', 'gallery') .'/gallery_groups.inc'); 375 $form['#submit'][] = '_gallery_groups_submit'; 376 } 377 // Add a custom search form 378 else if ($form_id == 'search_form' && arg(1) == 'gallery' && variable_get('gallery_search_advanced', 1) && user_access('access gallery')) { 379 require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc'); 380 _gallery_search_form($form, $form_state); 381 } 382 // Add _validate() handler for external authentication 383 else if ($form_id == 'user_login_block' || $form_id == 'user_login') { 384 $form['#validate'][] = 'gallery_auth_validate'; 385 } 386 387 // Add advanced help to gallery forms 388 if (module_exists('advanced_help')) { 389 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc'); 390 $help = _gallery_advanced_help_get_form_help($form_id); 391 foreach ($help as $element => $topic) { 392 $help_icon = theme('advanced_help_topic', 'gallery', $topic); 393 $element_path = explode('/', $element); 394 $element = &$form; 395 foreach ($element_path as $part) { 396 $element = &$element[$part]; 397 } 398 $element['#description'] = $help_icon .' '. $element['#description']; 399 } 400 } 401 } 402 403 /** 404 * Implementation of hook_filter(). 405 */ 406 function gallery_filter($op, $delta = 0, $format = -1, $text = '') { 407 require_once(drupal_get_path('module', 'gallery') .'/gallery_filter.inc'); 408 switch ($op) { 409 case 'list' : 410 return array(0 => t('Gallery2 filter')); 411 case 'description' : 412 return t('Allow users to easily reference Gallery2 items from nodes.'); 413 case 'process' : 414 return gallery_filter_process($text); 415 case 'no cache': 416 return !variable_get('gallery_filter_can_cache', TRUE); 417 default: 418 return $text; 419 } 420 } 421 422 /** 423 * Implementation of hook_filter_tips(). 424 */ 425 function gallery_filter_tips($delta = 0, $format = -1, $long = FALSE) { 426 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc'); 427 return $long ? gallery_help_filter_long_tip() : gallery_help_filter_short_tip(); 428 } 429 430 /** 431 * Implementation of hook_block(). 432 */ 433 function gallery_block($op = 'list', $delta = 0, $edit = array()) { 434 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc'); 435 if (variable_get('gallery_valid', 0)) { 436 return _gallery_block($op, $delta, $edit); 437 } 438 } 439 440 /** 441 * Function gallery_page(). 442 * (main gallery display page) 443 */ 444 function gallery_page() { 445 if (!_gallery_init()) { 446 return ''; 447 } 448 // Turn off sidebar 449 if (variable_get('gallery_move_sidebar_to_block', 1)) { 450 GalleryCapabilities::set('showSidebarBlocks', FALSE); 451 } 452 $result = gallery_handle_request(); 453 if ($result && !$result['isDone']) { 454 // Allow modules to alter the page 455 drupal_alter('gallery_page', $result, array()); 456 // Add css/js/meta for this page 457 gallery_set_head($result['headHtml'], TRUE); 458 // Add pathbar. See http://gallery.menalto.com/node/33447 459 if (isset($result['themeData'])) { 460 $breadcrumb = array(l(t('Home'), '')); 461 // Some themes (e.g. hybrid) do not set $result['themeData']['parents'] 462 if ($result['themeData']['parents']) { 463 foreach ($result['themeData']['parents'] as $parent) { 464 $parent_title = $parent['title']; 465 // Simple strip of BBCode (italic, bold) 466 $parent_title = str_replace( 467 array('[i]', '[/i]', '[b]', '[/b]'), 468 array('<i>', '</i>', '<strong>', '</strong>'), 469 $parent_title 470 ); 471 $parent_title = str_replace('[/i]', '</i>', $parent_title); 472 // Still does not generate a clean url for /gallery (uses index.php?q=gallery) 473 $link = gallery_generate_url($parent['urlParams'], FALSE); 474 $breadcrumb[] = l($parent_title, $link); 475 } 476 } 477 drupal_set_breadcrumb($breadcrumb); 478 // store G2 page context 479 gallery_context($result['themeData'], TRUE); 480 } 481 // Hack to get the admin sidebar 482 if (variable_get('gallery_move_admin_sidebar_to_block', 0)) { 483 list($result['bodyHtml'], $suffix) = explode('<td id="gsSidebarCol">', $result['bodyHtml']); 484 if ($suffix) { 485 list($sidebar, $suffix) = explode('</td>', $suffix, 2); 486 $result['bodyHtml'] .= '<td></td>'. $suffix; 487 // Insert admin $sidebar in $result['sidebarBlocksHtml'] 488 if (empty($result['sidebarBlocksHtml'][1])) { 489 $result['sidebarBlocksHtml'][1] = $sidebar; 490 } 491 else { 492 $result['sidebarBlocksHtml'][] = $sidebar; 493 } 494 } 495 } 496 // Store the sidebar info in a global variable for use in the gallery navigation block 497 $GLOBALS['gallery_sidebar'] = $result['sidebarBlocksHtml']; 498 499 return $result['bodyHtml']; 500 } 501 502 return ''; 503 } 504 505 /** 506 * Implementation of hook_xmlsitemap_links(). 507 * (define additional links to add to the site map) 508 */ 509 function gallery_xmlsitemap_links($type = NULL, $excludes = array()) { 510 if (($type != 'xml') || !variable_get('gallery_enable_sitemap', 1) || !_gallery_init(TRUE)) { 511 return; 512 } 513 514 list($ret, $view) = GalleryView::loadView('sitemap.Sitemap'); 515 if ($ret) { 516 gallery_error(t('Error loading the Gallery2 Sitemap. Make sure the \'Sitemap\' plugin is enabled in Gallery2.'), $ret); 517 return; 518 } 519 list($ret, $root) = GalleryCoreApi::getDefaultAlbumId(); 520 if ($ret) { 521 gallery_error(t('Error calling getDefaultAlbumId()'), $ret); 522 return; 523 } 524 525 // Get the sitemap from Gallery2 526 ob_start(); 527 $ret = $view->renderSitemap($root); 528 $g2_sitemap = ob_get_contents(); 529 ob_end_clean(); 530 531 if ($ret) { 532 gallery_error(t('Error getting sitemap from Gallery2.'), $ret); 533 return; 534 } 535 536 return $g2_sitemap; 537 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |