| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery_base.inc,v 1.8.2.18 2009/01/10 11:20:02 profix898 Exp $ 3 4 /** 5 * gallery.module : gallery_base.inc 6 * Base functions 7 */ 8 9 define('GALLERY_BASE_API', 1); 10 11 define('GALLERY_ERROR_WATCHDOG', 1); 12 define('GALLERY_ERROR_BROWSER', 2); 13 define('GALLERY_ERROR_VERBOSE', 3); 14 15 define('GALLERY_SEVERITY_SUCCESS', 1); 16 define('GALLERY_SEVERITY_ERROR', -1); 17 define('GALLERY_SEVERITY_WARNING', -2); 18 define('GALLERY_SEVERITY_ADVISE', -3); 19 define('GALLERY_SEVERITY_UNKNOWN', -4); 20 21 define('GALLERY_PLUGIN_ENABLED', 1); 22 define('GALLERY_PLUGIN_DISABLED', 0); 23 define('GALLERY_PLUGIN_STATUS_UNKNOWN', -1); 24 define('GALLERY_PLUGIN_NOT_ACTIVE', -2); 25 define('GALLERY_PLUGIN_NOT_INSTALLED', -3); 26 define('GALLERY_PLUGIN_MISSING', -4); 27 28 define('GALLERY_PLUGIN_WANTED', 1); 29 define('GALLERY_PLUGIN_UNWANTED', 2); 30 define('GALLERY_PLUGIN_DRUPAL', 3); 31 32 define('GALLERY_DEBUGTRACE', TRUE); 33 34 /** 35 * Function gallery_login(). 36 * (login user into embedded gallery) 37 */ 38 function gallery_login() { 39 _gallery_init(); 40 } 41 42 /** 43 * Function gallery_logout(). 44 * (end user session) 45 */ 46 function gallery_logout() { 47 if (variable_get('gallery_valid', FALSE)) { 48 $embed_path = variable_get('gallery_dir', './gallery2/') .'embed.php'; 49 if (is_readable($embed_path)) { 50 require_once($embed_path); 51 GalleryEmbed::logout(); 52 } 53 } 54 } 55 56 /** 57 * Function _gallery_init(). 58 * (initialize embedded gallery) 59 */ 60 function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) { 61 global $user, $language; 62 static $ready = array('half' => FALSE, 'full' => FALSE); 63 64 // Initialize only once 65 if ($ready[$full ? 'full' : 'half']) { 66 return TRUE; 67 } 68 69 $init_err_msg = t('Unable to initialize embedded Gallery. You need to <a href="@link"> configure your embedded Gallery</a>.', 70 array('@link' => url('admin/settings/gallery/install'))); 71 72 $g2_dir = isset($vars['gallery_dir']) ? $vars['gallery_dir'] : variable_get('gallery_dir', './gallery2/'); 73 $g2_uri = isset($vars['gallery_uri']) ? $vars['gallery_uri'] : variable_get('gallery_uri', '/gallery2/'); 74 $embed_uri = isset($vars['gallery_embed_uri']) ? $vars['gallery_embed_uri'] : variable_get('gallery_embed_uri', '?q=gallery'); 75 76 $gallery_valid = isset($vars) ? (isset($vars['gallery_valid']) ? $vars['gallery_valid'] : TRUE) : variable_get('gallery_valid', 0); 77 $uid = isset($vars) ? (isset($vars['uid']) ? $vars['uid'] : NULL) : (($user->uid > 0) ? $user->uid : NULL); 78 79 // Language-prefix url rewrite 80 if (function_exists('language_url_rewrite') && variable_get('language_count', 1) > 1 && !empty($language->prefix)) { 81 switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) { 82 case LANGUAGE_NEGOTIATION_PATH_DEFAULT: 83 $default = language_default(); 84 if ($language->language == $default->language) { 85 break; 86 } 87 case LANGUAGE_NEGOTIATION_PATH: 88 $embed_uri = str_replace('index.php?q=', 'index.php?q='. $language->prefix .'/', $embed_uri); 89 break; 90 default: 91 } 92 } 93 94 // Prepare array with init parameters 95 $debug = variable_get('gallery_g2debug', 0) && user_access('administer site configuration'); 96 $params = array('g2Dir' => $g2_dir, 97 'g2Uri' => $g2_uri, 98 'embedUri' => $embed_uri, 99 'loginRedirect' => url('user/login', array('query' => drupal_get_destination(), 'absolute' => TRUE)), 100 'activeUserId' => $uid, 101 'activeLanguage' => gallery_get_language($language->language), 102 'apiVersion' => array(1, 4), 103 'debug' => $debug ? 'buffered' : FALSE, 104 'eventListeners' => array()); 105 106 // Add theme to init parameters 107 if (($g2_theme = variable_get('gallery_embed_theme', 'default')) != 'default') { 108 $params['themeId'] = $g2_theme; 109 } 110 111 // Add root album to init parameters (but only for the gallery pages) 112 $g2_root = variable_get('gallery_root_album', 'default'); 113 if ($g2_root != 'default' && arg(0) == variable_get('gallery_base', 'gallery')) { 114 $params['defaultAlbumId'] = $params['breadcrumbRootId'] = $g2_root; 115 } 116 117 // Allow modules to alter the init parameters 118 drupal_alter('gallery_init', $params, array('fullInit' => $full, 'ready' => $ready)); 119 $params['fullInit'] = $full; 120 121 // Debug output of init parameters 122 gallery_debug($params, t('Init parameters')); 123 124 // Check for existence of 'embed.php' 125 if (!$gallery_valid || !is_readable($params['g2Dir'] .'embed.php')) { 126 if ($report_error) { 127 gallery_error($init_err_msg); 128 } 129 return FALSE; 130 } 131 132 // Initialize Gallery2 133 include_once($params['g2Dir'] .'embed.php'); 134 $ret = GalleryEmbed::init($params); 135 if ($ret) { 136 if ($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH) { 137 $err_msg = t('Embedding API version is incompatible.'); 138 if ($vars) { 139 drupal_set_message($err_msg, 'error'); 140 } 141 gallery_error($vars ? $err_msg : $init_err_msg, $ret, !$vars); 142 } 143 else if ($report_error) { 144 gallery_error($init_err_msg, $ret, TRUE); 145 } 146 return FALSE; 147 } 148 149 // Check if initialization was successful 150 if (!class_exists('GalleryEmbed') || !class_exists('GalleryCoreApi')) { 151 if ($report_error) { 152 gallery_error(t('Initialization seemed successful, but classes \'GalleryEmbed\' 153 and/or \'GalleryCoreApi\' are still not available.')); 154 } 155 return FALSE; 156 } 157 158 // Multiroot: 'Virtual Root' (or 'Alternate guest user') view requested 159 if (isset($params['defaultAlbumId'])) { 160 $GLOBALS['gallery']->setConfig('defaultAlbumId', $params['defaultAlbumId']); 161 } 162 if (isset($params['breadcrumbRootId'])) { 163 $GLOBALS['gallery']->setConfig('breadcrumbRootId', $params['breadcrumbRootId']); 164 } 165 if (isset($params['anonymousUserId'])) { 166 $GLOBALS['gallery']->setConfig('anonymousUserId', $params['anonymousUserId']); 167 } 168 169 // Register event listeners 170 if (count($params['eventListeners'])) { 171 require_once(drupal_get_path('module', 'gallery') .'/G2DrupalHelper.class'); 172 $ret = G2DrupalHelper::registerEventListeners($params['eventListeners']); 173 if ($ret && $report_error) { 174 gallery_error(t('Failed to register event listeners.'), $ret); 175 } 176 } 177 178 // Session handling 179 $g2_session =& $GLOBALS['gallery']->getSession(); 180 $g2_session->doNotUseTempId(); 181 182 $ready['half'] = $params['fullInit'] ? ($ready['full'] = TRUE) : TRUE; 183 184 return TRUE; 185 } 186 187 /** 188 * Function gallery_handle_request(). 189 * (handleRequest extension with error handling) 190 */ 191 function gallery_handle_request() { 192 global $language; 193 194 // Remove the language-prefix for G2 195 if (!empty($_GET['g2_path']) && function_exists('language_url_rewrite') && variable_get('language_count', 1) > 1) { 196 $args = explode('/', $_GET['g2_path']); 197 $prefix = array_shift($args); 198 if (!empty($language->prefix) && $language->prefix == $prefix) { 199 $_GET['g2_path'] = implode('/', $args); 200 } 201 } 202 203 // Handle the request 204 ob_start(); 205 $result = GalleryEmbed::handleRequest(); 206 $output = ob_get_contents(); 207 ob_end_clean(); 208 209 if ($output) { 210 if (!preg_match('%<h2>\sError\s</h2>%', $output)) { 211 // If $output does not contain '<h2>Error</h2>', this is an AJAX/Image callback 212 print $output; 213 exit(); 214 } 215 else { 216 // Otherwise (on regular pages) $output means that an error occured 217 if (variable_get('gallery_error_redirect', 0) && user_access('search content')) { 218 drupal_set_message('The requested Gallery URL does not exist. The item may have been 219 moved or deleted. You can search for it below.', 'notice'); 220 drupal_goto('search/gallery'); 221 } 222 preg_match('%<div id="giStackTrace" [^>]*>(.*?)</div>%is', $output, $matches); 223 gallery_error(t('Error handling request (invalid request)<br />or the requested Gallery URL does not exist.'), $matches[1], TRUE); 224 return NULL; 225 } 226 } 227 228 // Include theme-specific css overrides (gallery-themeid.css) 229 if (isset($result['themeData']['themeId'])) { 230 $stylesheet = drupal_get_path('module', 'gallery') .'/gallery-'. $result['themeData']['themeId'] .'.css'; 231 if (file_exists($stylesheet)) { 232 drupal_add_css($stylesheet); 233 } 234 } 235 236 // Catch debug output from G2 237 if (($pos = strpos($result['bodyHtml'], '<div id="gpDebug">')) !== FALSE) { 238 list($result['bodyHtml'], $suffix) = explode('<div id="gpDebug">', $result['bodyHtml']); 239 if ($suffix) { 240 list($debug, $suffix) = explode('</div>', $suffix, 2); 241 $result['bodyHtml'] .= $suffix; 242 gallery_debug($debug, t('G2 Debug Buffer'), TRUE); 243 } 244 } 245 246 return $result; 247 } 248 249 /** 250 * Function gallery_get_language(). 251 */ 252 function gallery_get_language($lang = '', $user = NULL) { 253 global $language; 254 255 // Get language from $user object 256 $lang = (isset($user) && $user->uid > 0 && !empty($user->language)) ? $user->language : $lang; 257 // Use current global $language, if no other language is specified 258 $lang = empty($lang) ? $language->language : $lang; 259 // Convert certain language codes, e.g. 'esl/spa es' => 'es' or 'fr-ca' => 'fr' 260 $lang = preg_replace(array('/([\w\/]+) ([a-z]{2,3})/i', '/([a-z]{2,3})-(\w+)/i'), array('$2}', '$1}'), $lang); 261 262 return $lang; 263 } 264 265 /** 266 * Function gallery_list_themes(). 267 * (retrieve all (active) themes from Gallery2) 268 */ 269 function gallery_list_themes() { 270 if (!_gallery_init()) { 271 return array(); 272 } 273 // List of themes 274 list($ret, $g2_themes) = GalleryCoreApi::fetchPluginStatus('theme', TRUE); 275 if ($ret) { 276 gallery_error(t('Error retrieving theme list'), $ret); 277 return array(); 278 } 279 280 $themes = array(); 281 foreach (array_keys($g2_themes) as $themeid) { 282 // Only active themes 283 if (!empty($g2_themes[$themeid]['active'])) { 284 // Get theme details 285 list($ret, $theme) = GalleryCoreApi::loadPlugin('theme', $themeid, TRUE); 286 if ($ret) { 287 gallery_error(t('Error getting theme (:themeid) details', 288 array(':themeid' => $themeid)), $ret); 289 return array(); 290 } 291 $themes[$themeid] = $theme->getName(); 292 } 293 } 294 295 return $themes; 296 } 297 298 /** 299 * Function gallery_list_image_frames(). 300 * (retrieve all image frames from Gallery2) 301 */ 302 function gallery_list_image_frames() { 303 if (!_gallery_init()) { 304 return array('none' => t('None')); 305 } 306 // List of available image frames 307 list($ret, $imageframe) = GalleryCoreApi::newFactoryInstance('ImageFrameInterface_1_1'); 308 if ($ret || !isset($imageframe)) { 309 return array('none' => t('None')); 310 } 311 list($ret, $list) = $imageframe->getImageFrameList(); 312 if ($ret) { 313 return array('none' => t('None')); 314 } 315 316 return $list; 317 } 318 319 /** 320 * Function gallery_check_path2id(). 321 */ 322 function gallery_check_path2id($path) { 323 if (!_gallery_init(TRUE)) { 324 return FALSE; 325 } 326 // Cache the request items here to save G2 API calls 327 // (the menu system invokes _load repeatedly with the same arguments) 328 static $items = NULL; 329 if (!isset($items[$path])) { 330 $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); 331 if (isset($url_generator->_shortUrls)) { 332 // Fetch item id for this path (to check existence) and return id 333 list($ret, $id) = GalleryCoreApi::fetchItemIdByPath($path); 334 $items[$path] = $ret ? FALSE : $id; 335 } 336 else if (is_numeric($path) && ($id = intval($path))) { 337 // Fetch item by id (to check existence) and return id 338 list($ret, $entity) = GalleryCoreApi::loadEntitiesById($id); 339 $items[$path] = $ret ? FALSE : $id; 340 } 341 } 342 343 return $items[$path]; 344 } 345 346 /** 347 * Function gallery_generate_url(). 348 */ 349 function gallery_generate_url($params, $html = TRUE, $full = TRUE) { 350 if (!_gallery_init(TRUE)) { 351 return ''; 352 } 353 // Get URL generator and generate the url 354 $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); 355 if (!$url_generator) { 356 gallery_error(t('Error: UrlGenerator not available')); 357 return ''; 358 } 359 360 $options = array(); 361 $options['forceFullUrl'] = $full; 362 $options['htmlEntities'] = $html; 363 364 if (!isset($params['view'])) { 365 $params['view'] = 'core.ShowItem'; 366 } 367 368 return $url_generator->generateUrl($params, $options); 369 } 370 371 /** 372 * Function gallery_album_tree(). 373 */ 374 function gallery_album_tree($root = NULL, $depth = NULL, $uid = NULL) { 375 if (!_gallery_init(TRUE)) { 376 return array(); 377 } 378 // If this is called for the Drupal guest user, pass in G2 379 // anonymous user id (otherwise fetchAlbumTree() returns nothing) 380 global $user; 381 if (!$uid && !$user->uid) { 382 list($ret, $uid) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.anonymousUser'); 383 if ($ret) { 384 return array(); 385 } 386 } 387 // Fetch G2 album tree 388 list($ret, $tree) = GalleryCoreApi::fetchAlbumTree($root, $depth, $uid); 389 if ($ret) { 390 gallery_error(t('Error fetching album tree'), $ret); 391 return array(); 392 } 393 394 return $tree; 395 } 396 397 /** 398 * Function gallery_item_details(). 399 */ 400 function gallery_item_details($id, $verbose = FALSE) { 401 $details = array(); 402 if (!_gallery_init(TRUE)) { 403 return $details; 404 } 405 // Load entity 406 list($ret, $entity) = GalleryCoreApi::loadEntitiesById($id); 407 if ($ret) { 408 gallery_error(t('Error fetching item details (entityId: :id)', 409 array(':id' => $id)), $ret); 410 return $details; 411 } 412 // Extract details 413 $details['g2id'] = $id; 414 $details['g2type'] = $entity->entityType; 415 $details['g2owner'] = $entity->ownerId; 416 $details['g2parent'] = $entity->parentId; 417 // Drupal node properties (without g2 prefix) 418 $details['title'] = _gallery_htmlcharsdecode($entity->title); 419 $details['created'] = $entity->creationTimestamp; 420 $details['changed'] = $entity->modificationTimestamp; 421 // Gallery2 item properties (with g2 prefix) 422 if ($verbose) { 423 $details['g2description'] = _gallery_htmlcharsdecode($entity->description); 424 $details['g2summary'] = _gallery_htmlcharsdecode($entity->summary); 425 $details['g2keywords'] = $entity->keywords; 426 $details['g2theme'] = isset($entity->theme) ? $entity->theme : NULL; 427 } 428 429 return $details; 430 } 431 432 /** 433 * Function gallery_item_access(). 434 */ 435 function gallery_item_access($id, $permission = 'core.view', $user = NULL) { 436 if (!_gallery_init(TRUE) || !is_numeric($id)) { 437 return FALSE; 438 } 439 // Check access permissions 440 list($ret, $access) = GalleryCoreApi::hasItemPermission($id, $permission, $user); 441 if ($ret) { 442 gallery_error(t('Error calling hasItemPermission()'), $ret); 443 return FALSE; 444 } 445 446 return $access; 447 } 448 449 /** 450 * Function gallery_db_query(). 451 */ 452 function gallery_db_query($query, $data = NULL) { 453 if (!_gallery_init(TRUE)) { 454 return FALSE; 455 } 456 // Perform query 457 list ($ret, $search) = $GLOBALS['gallery']->search($query, $data); 458 if ($ret) { 459 return FALSE; 460 } 461 $results = array(); 462 while ($result = $search->nextResult()) { 463 $results += $result; 464 } 465 466 return $results; 467 } 468 469 /** 470 * Function gallery_flush_entity_cache(). 471 */ 472 function gallery_flush_entity_cache() { 473 if (!_gallery_init()) { 474 return FALSE; 475 } 476 // Flush entity cache 477 $platform =& $GLOBALS['gallery']->getPlatform(); 478 $cache_basedir = $GLOBALS['gallery']->getConfig('data.gallery.cache'); 479 $cache_dir = $cache_basedir .'entity'; 480 481 if ($platform->file_exists($cache_dir)) { 482 if (!$platform->recursiveRmDir($cache_dir)) { 483 return FALSE; 484 } 485 } 486 487 return TRUE; 488 } 489 490 /** 491 * Function gallery_set_head(). 492 */ 493 function gallery_set_head($html, $settitle = FALSE) { 494 if (!empty($html)) { 495 list($title, $css, $javascript, $meta) = GalleryEmbed::parseHead($html); 496 if ($settitle) { 497 drupal_set_title($title); 498 } 499 gallery_set_meta($meta); 500 gallery_set_css($css); 501 gallery_set_javascript($javascript); 502 } 503 } 504 505 /** 506 * Function gallery_set_meta(). 507 */ 508 function gallery_set_meta($meta) { 509 static $meta_memory = array(); 510 511 // Debug output 512 gallery_debug($meta, t('Head [Meta]')); 513 // Drupal adds these item by default already 514 if (empty($meta_memory)) { 515 $meta_memory[] = md5('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'); 516 } 517 // Handle head/meta data 518 foreach ($meta as $include) { 519 if (!in_array(($md5 = md5($include)), $meta_memory)) { 520 $meta_memory[] = $md5; 521 drupal_set_html_head($include); 522 } 523 } 524 } 525 526 /** 527 * Function gallery_set_css(). 528 */ 529 function gallery_set_css($css) { 530 static $css_memory = array(); 531 532 if (count($css)) { 533 // Debug output 534 gallery_debug($css, t('Head [CSS]')); 535 // Handle css styles and includes 536 foreach ($css as $include) { 537 if (!in_array(($md5 = md5($include)), $css_memory)) { 538 $css_memory[] = $md5; 539 drupal_set_html_head($include); 540 } 541 } 542 } 543 } 544 545 /** 546 * Function gallery_set_javascript(). 547 * (druapl_add_js() ensures proper cascading of included G2 javascript) 548 */ 549 function gallery_set_javascript($javascript) { 550 static $js_memory = array(); 551 552 if (!empty($javascript)) { 553 // Debug output 554 gallery_debug($javascript, t('Head [Javascript]')); 555 // Handle inline javascript and includes 556 $files = preg_grep('/<script(.*?)src=/i', $javascript); 557 // Inline Javascript 558 $inline = array_diff($javascript, $files); 559 $inline = preg_replace('/<script([^>]*)>(.*?)<\/script>/is', '\2', $inline); 560 drupal_add_js(implode("\n", $inline), 'inline'); 561 // Javascript files 562 foreach ($files as $include) { 563 if (!in_array(($md5 = md5($include)), $js_memory)) { 564 $js_memory[] = $md5; 565 drupal_set_html_head($include); 566 } 567 } 568 } 569 } 570 571 /** 572 * Function gallery_context(). 573 * (store and/or access the context of the current gallery page) 574 */ 575 function gallery_context(&$params, $setcontext = FALSE) { 576 static $context_cache = NULL; 577 578 if ($setcontext) { 579 // Store new context 580 $context_cache = (isset($params) && count($params)) ? $params : array(); 581 gallery_debug($context_cache, t('Context cache')); 582 } 583 else if (isset($context_cache)) { 584 // Get context parameters 585 if (isset($params)) { 586 // Return requested context parameters 587 $params = is_array($params) ? $params : array($params); 588 foreach($params as $param) { 589 if (!isset($context_cache[$param])) { 590 return FALSE; 591 } 592 $context[$param] = $context_cache[$param]; 593 } 594 $params = $context; 595 } 596 else { 597 // Return all stored context parameters 598 $params = $context_cache; 599 } 600 601 return TRUE; 602 } 603 604 return FALSE; 605 } 606 607 /** 608 * Function gallery_list_blocks(). 609 */ 610 function gallery_list_blocks($plugin_names = NULL) { 611 if (!_gallery_init()) { 612 return array(); 613 } 614 // List of available blocks 615 list($ret, $g2_blocks) = GalleryCoreApi::loadAvailableBlocks(); 616 if ($ret) { 617 gallery_error(t('Error retrieving available blocks list'), $ret); 618 return array(); 619 } 620 // Filter plugins 621 if (isset($plugin_names)) { 622 $plugin_names = is_array($plugin_names) ? $plugin_names : array($plugin_names); 623 foreach ($g2_blocks as $plugin => $blocks) { 624 if (!in_array($plugin, $plugin_names)) { 625 unset($g2_blocks[$plugin]); 626 } 627 } 628 } 629 630 return $g2_blocks; 631 } 632 633 /** 634 * Function gallery_get_block(). 635 * 636 * This function allows developers to fetch an image or grid block with certain 637 * parameters from Gallery2. 638 * 639 * @param $params 640 * An array of parameters to be passed to getImageBlock(). 641 * (http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryEmbed.html#methodgetImageBlock) 642 * If 'itemId' is set to 'user' (or 'user:uid') items are be taken from the 643 * current (or specified) user's useralbum. 644 * @param $block 645 * Name of the block to get from Gallery2 (e.g. 'ImageBlock', etc.) 646 * @param $extra 647 * $extra['class']: 648 * Optional class to apply to the block (if customized css styles are required). 649 * $extra['num_cols']: 650 * If given for a 'ImageBlock' a grid block with 'num_cols' columns is generated. 651 * Otherwise (default) a 'normal' image block is returned. 652 */ 653 function gallery_get_block($params, $block = 'ImageBlock', $extra = array()) { 654 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc'); 655 if (!_gallery_init(TRUE)) { 656 return array('content' => ''); 657 } 658 $block_map = _gallery_block_map(); 659 $plugin = $block_map[strtolower($block)]['plugin']; 660 $plugin_block = $block_map[strtolower($block)]['block']; 661 662 return _gallery_block_get_block($plugin, $plugin_block, $params, $extra); 663 } 664 665 /** 666 * Function _gallery_htmlcharsdecode(). 667 * (recover special character's HTML entities, see htmlspecialchars_decode() for php5) 668 */ 669 function _gallery_htmlcharsdecode($string) { 670 return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); 671 } 672 673 /* -------------------------------------------------------------------------- 674 * Error, Debug and Status Functions 675 * -------------------------------------------------------------------------- */ 676 677 /** 678 * Function gallery_error(). 679 */ 680 function gallery_error($msg, $ret = NULL, $serious = FALSE) { 681 $error_mode = variable_get('gallery_error_mode', array(GALLERY_ERROR_WATCHDOG)); 682 $admin = user_access('administer site configuration'); 683 $report = $admin && variable_get('gallery_report', 1); 684 685 // Verbose error messages (include backtrace if available) 686 $debug_info = array(); 687 if (in_array(GALLERY_ERROR_VERBOSE, $error_mode) || variable_get('gallery_debug', 0) || $admin) { 688 $msg = $ret ? (is_object($ret) ? ($msg .'<br />'. $ret->getAsHtml()) : $ret) : $msg; 689 if (GALLERY_DEBUGTRACE && function_exists('debug_backtrace')) { 690 $trace = debug_backtrace(); 691 $source = t('Error in function \':func()\' (:file::line):<br />', 692 array(':func' => $trace[1]['function'], ':file' => basename($trace[0]['file']), ':line' => $trace[0]['line'])); 693 $message = $source .'<ul><li>'. $msg .'</li></ul>'; 694 $debug_info = array('Debug Trace' => $trace); 695 } 696 } 697 $message = !empty($message) ? $message : $msg; 698 699 // Debug output (do not log to watchdog) 700 if (variable_get('gallery_debug', 0) && $admin) { 701 if ($report) { 702 _gallery_report_error($debug_info); 703 } 704 drupal_set_message($message, 'error'); 705 return; 706 } 707 708 // Error output to browser 709 if (in_array(GALLERY_ERROR_BROWSER, $error_mode)) { 710 if ($report) { 711 _gallery_report_error($debug_info); 712 } 713 drupal_set_message($message, 'error'); 714 } 715 elseif ($serious) { 716 if ($report) { 717 _gallery_report_error($debug_info); 718 } 719 drupal_set_message($admin ? $message : t('Embedded Gallery2 is not available or requested Gallery URL does not exist.'), 'error'); 720 } 721 722 // Error output to watchdog 723 if (in_array(GALLERY_ERROR_WATCHDOG, $error_mode)) { 724 watchdog('gallery', $message, array(), WATCHDOG_ERROR); 725 } 726 } 727 728 /** 729 * Function _gallery_report_error(). 730 */ 731 function _gallery_report_error($report = array()) { 732 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc'); 733 require_once(drupal_get_path('module', 'gallery') .'/gallery_report.inc'); 734 735 drupal_set_message(_gallery_report_help(), 'error'); 736 _gallery_report(FALSE, $report, TRUE); 737 } 738 739 /** 740 * Function gallery_debug(). 741 */ 742 function gallery_debug($output, $label = NULL, $html = FALSE) { 743 if (variable_get('gallery_debug', 0) && user_access('administer site configuration')) { 744 // Output debug log into a collapsible fieldset 745 $fieldset = array( 746 '#title' => t('Gallery Debug') . (isset($label) ? (': '. check_plain($label)) : ''), 747 '#collapsible' => TRUE, 748 '#collapsed' => TRUE, 749 '#value' => '<pre>'. ($html ? $output : htmlspecialchars(print_r($output, TRUE))) .'</pre>', 750 ); 751 drupal_set_content('content', theme('fieldset', $fieldset)); 752 } 753 } 754 755 /** 756 * Function gallery_plugin_status(). 757 */ 758 function gallery_plugin_status($plugin_names) { 759 static $all_plugins_status = array(); 760 761 $plugins_status = array(); 762 if (!_gallery_init()) { 763 foreach ($plugin_names as $plugin) { 764 $plugins_status[$plugin] = GALLERY_PLUGIN_STATUS_UNKNOWN; 765 } 766 767 return $plugins_status; 768 } 769 // Fetch status of G2 modules 770 if (empty($plugins_status_cache)) { 771 list($ret, $plugins_status_cache) = GalleryCoreApi::fetchPluginStatus('module'); 772 if ($ret) { 773 gallery_error(t('Unable to get Gallery2 module status.'), $ret); 774 foreach ($plugin_names as $plugin) { 775 $plugins_status[$plugin] = GALLERY_PLUGIN_STATUS_UNKNOWN; 776 } 777 778 return $plugins_status; 779 } 780 } 781 // Generate array containing module status 782 foreach ($plugin_names as $plugin) { 783 if (isset($plugins_status_cache[$plugin])) { 784 if (isset($plugins_status_cache[$plugin]['active']) && $plugins_status_cache[$plugin]['available']) { 785 $plugins_status[$plugin] = GALLERY_PLUGIN_ENABLED; 786 } 787 elseif (!isset($plugins_status_cache[$plugin]['active']) && $plugins_status_cache[$plugin]['available']) { 788 $plugins_status[$plugin] = GALLERY_PLUGIN_NOT_INSTALLED; 789 } 790 elseif (($plugins_status_cache[$plugin]['active'] == FALSE) && $plugins_status_cache[$plugin]['available']) { 791 $plugins_status[$plugin] = GALLERY_PLUGIN_NOT_ACTIVE; 792 } 793 else { 794 $plugins_status[$plugin] = GALLERY_PLUGIN_DISABLED; 795 } 796 } 797 else { 798 $plugins_status[$plugin] = GALLERY_PLUGIN_MISSING; 799 } 800 } 801 802 return $plugins_status; 803 } 804 805 /** 806 * Function gallery_single_plugin_status(). 807 */ 808 function gallery_single_plugin_status($plugin_name) { 809 $status = gallery_plugin_status(array($plugin_name)); 810 return $status[$plugin_name]; 811 } 812 813 /** 814 * Function gallery_set_status(). 815 */ 816 function gallery_set_status($status = array(), $reset = FALSE) { 817 $status_array = $status; 818 if (!$reset) { 819 $status_array = unserialize(variable_get('gallery_status', serialize(array()))); 820 foreach ($status as $key => $value) { 821 if (!empty($value)) { 822 $status_array[$key] = $value; 823 } 824 elseif (isset($status_array[$key])) { 825 unset($status_array[$key]); 826 } 827 } 828 } 829 830 variable_set('gallery_status', serialize($status_array)); 831 } 832 833 /** 834 * Function gallery_get_status(). 835 */ 836 function gallery_get_status() { 837 return unserialize(variable_get('gallery_status', serialize(array()))); 838 } 839 840 /** 841 * Function gallery_version(). 842 */ 843 function gallery_version() { 844 if (!_gallery_init()) { 845 return array(); 846 } 847 // Get API version 848 list($core_major, $core_minor) = GalleryCoreApi::getApiVersion(); 849 list($embed_major, $embed_minor) = GalleryEmbed::getApiVersion(); 850 $version = array( 851 'core' => array('major' => $core_major, 'minor' => $core_minor), 852 'embed' => array('major' => $embed_major, 'minor' => $embed_minor) 853 ); 854 855 // Update version in status messages 856 $status = array('version' => array( 857 'title' => t('Gallery2 API version'), 858 'info' => "$core_major.$core_minor / $embed_major.$embed_minor") 859 ); 860 gallery_set_status($status); 861 862 return $version; 863 }
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 |