| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery_install.inc,v 1.3.2.10 2008/08/04 21:13:06 profix898 Exp $ 3 4 require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc'); 5 6 /** 7 * gallery.module : gallery_install.inc 8 * Configure embedded Gallery install (directory options, etc.) 9 */ 10 11 define('GALLERY_INSTALL_STEP_PHPMEMORY', 1); 12 define('GALLERY_INSTALL_STEP_LOCATIONS', 2); 13 define('GALLERY_INSTALL_STEP_PLUGINS', 3); 14 define('GALLERY_INSTALL_STEP_URLREWRITE', 4); 15 define('GALLERY_INSTALL_STEP_USERSYNC', 5); 16 17 /** 18 * Function _gallery_install_status_init(). 19 */ 20 function _gallery_install_status_init() { 21 return array( 22 'phpmemory' => array( 23 'title' => t('PHP Memory Limit'), 24 'severity' => GALLERY_SEVERITY_ERROR, 25 'status' => FALSE 26 ), 27 'locations' => array( 28 'title' => t('Gallery2 locations'), 29 'severity' => GALLERY_SEVERITY_ERROR, 30 'status' => FALSE 31 ), 32 'plugins' => array( 33 'title' => t('Drupal Modules / Gallery2 Plugins'), 34 'severity' => GALLERY_SEVERITY_WARNING, 35 'status' => FALSE 36 ), 37 'urlrewrite' => array( 38 'title' => t('Clean URL / URL Rewrite'), 39 'severity' => GALLERY_SEVERITY_WARNING, 40 'status' => FALSE 41 ), 42 'usersync' => array( 43 'title' => t('Initial User Synchronization'), 44 'severity' => GALLERY_SEVERITY_ERROR, 45 'status' => FALSE 46 ), 47 ); 48 } 49 50 /** 51 * Function _gallery_install_status_report(). 52 */ 53 function _gallery_install_status_report($install_status) { 54 // Install status table 55 $error = FALSE; 56 $rows = array(); 57 foreach ($install_status as $step => $status) { 58 // Find the combination of status and severity of the plugin 59 $severity = ($status['status'] <= 0) ? $status['severity'] : GALLERY_SEVERITY_SUCCESS; 60 if (!$status['status'] && $severity == GALLERY_SEVERITY_ERROR) { 61 $error = TRUE; 62 } 63 $row = array(); 64 $row[] = array('data' => $status['title'], 'align' => 'left', 'width' => '20%'); 65 $row[] = array('data' => theme('gallery_severity_message', $severity), 'align' => 'center'); 66 $row[] = array('data' => isset($status['info'])? $status['info'] : '', 'class' => 'description', 'id' => 'gallery-install-status-'. $step); 67 $rows[] = $row; 68 } 69 70 if ($error) { 71 $rows[] = array(array( 72 'data' => t('Critical errors are present.'), 73 'colspan' => '3', 74 'align' => 'center', 75 'class' => 'message') 76 ); 77 } 78 79 // Set the global status variable 'gallery_valid' 80 gallery_set_status(array( 81 'gallery_valid' => array( 82 'title' => t('Overall Status (Installation)'), 83 'severity' => $error ? GALLERY_SEVERITY_ERROR : GALLERY_SEVERITY_SUCCESS 84 ) 85 )); 86 87 return theme('table', array(t('Step'), t('Status'), t('Description')), $rows, array('class' => 'package')); 88 } 89 90 /** 91 * Function _gallery_install_status(). 92 */ 93 function _gallery_install_status($form_state) { 94 $form['install'] = array( 95 '#type' => 'fieldset', 96 '#title' => t('Install status'), 97 '#collapsible' => FALSE, 98 '#collapsed' => FALSE, 99 '#description' => t('Correct configuration of the following items is essential for the 100 embedded gallery to function properly.') 101 ); 102 103 $install_status = _gallery_install_status_init(); 104 105 // Step 1: Check PHP Memory 106 $phpmemory_info = _gallery_php_memcheck(); 107 $install_status['phpmemory']['status'] = $phpmemory_info['status']; 108 $install_status['phpmemory']['info'] = $phpmemory_info['info']; 109 110 // Step 2: Gallery2 Locations 111 $values['gallery_uri'] = variable_get('gallery_uri', '/gallery2/'); 112 $values['gallery_dir'] = variable_get('gallery_dir', './gallery2/'); 113 $values['gallery_embed_uri'] = variable_get('gallery_embed_uri', '?q=gallery'); 114 $values['gallery_base'] = variable_get('gallery_base', 'gallery'); 115 $autodetect = variable_get('gallery_autodetect_dir', 1); 116 // Check location settings and generate status report 117 list($install_status['locations']['status'], $values, $result) = _gallery_install_locations($values, $autodetect); 118 $install_status['locations']['info'] = $install_status['locations']['status'] ? 119 t('The Gallery2 location settings appear to be correct.') : 120 gallery_format_status($result, t('Errors in your current Gallery2 location settings:')); 121 $form['locations'] = array( 122 '#type' => 'fieldset', 123 '#title' => t('Gallery2 location settings') .' - '. ($autodetect ? t('Auto Configuration') : t('Manual Configuration')), 124 '#collapsible' => TRUE, 125 '#collapsed' => $install_status['locations']['status'], 126 '#description' => t('Overview of your Gallery2 location settings as specified or autodetected during install.') 127 ); 128 $form['locations']['gallery_uri'] = array( 129 '#title' => t('Gallery2 URL or URI'), 130 '#type' => 'item', 131 '#value' => $values['gallery_uri'] 132 ); 133 if (!empty($values['gallery_dir'])) { 134 $form['locations']['gallery_dir'] = array( 135 '#title' => t('Gallery2 filesystem path'), 136 '#type' => 'item', 137 '#value' => $values['gallery_dir'] 138 ); 139 } 140 $form['locations']['gallery_embed_uri'] = array( 141 '#title' => t('Embed URI'), 142 '#type' => 'item', 143 '#value' => $values['gallery_embed_uri'] 144 ); 145 $form['locations']['gallery_base'] = array( 146 '#title' => t('Gallery base'), 147 '#type' => 'item', 148 '#value' => $values['gallery_base'] 149 ); 150 151 // Step 3: Drupal Modules and Gallery2 Plugins check 152 $form += _gallery_install_plugins($install_status); 153 154 // Step 4: Clean URL configuration 155 _gallery_install_urlrewrite_check($install_status); 156 if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED) { 157 if (_gallery_install_urlrewrite($public_path, $htaccess_path, TRUE)) { 158 $form['urlrewrite'] = array( 159 '#type' => 'fieldset', 160 '#title' => t('Clean URLs / URL Rewrite settings'), 161 '#collapsible' => TRUE, 162 '#collapsed' => TRUE, 163 '#description' => t('Overview of your URL Rewrite settings as specified during install.') 164 ); 165 $form['urlrewrite']['htaccess_public_path'] = array( 166 '#title' => t('Public path to your .htaccess file'), 167 '#type' => 'item', 168 '#value' => $public_path 169 ); 170 $form['urlrewrite']['htaccess_filesystem_path'] = array( 171 '#title' => t('Filesystem path to your .htaccess file'), 172 '#type' => 'item', 173 '#value' => $htaccess_path 174 ); 175 } 176 } 177 178 // Step 5: User Synchronization 179 $install_status['usersync']['status'] = TRUE; 180 $install_status['usersync']['info'] = t('Your initial user synchronization has been completed already.<br /> If you 181 want to resync all your users or you want to import users from an existing 182 Gallery2 setup, you can always use the <a href= "@gallery-usersync">Advanced 183 Sync</a> options in the Gallery user administration.', 184 array('@gallery-usersync' => url('admin/user/gallery/advanced'))); 185 186 $form['install']['status'] = array( 187 '#value' => _gallery_install_status_report($install_status) 188 ); 189 190 $form['buttons']['reset'] = array( 191 '#type' => 'submit', 192 '#value' => t('Reset & Restart'), 193 '#submit' => array('_gallery_install_reset') 194 ); 195 196 return $form; 197 } 198 199 /** 200 * Function _gallery_install(). 201 */ 202 function _gallery_install($form_state) { 203 $form['install'] = array( 204 '#type' => 'fieldset', 205 '#title' => t('Install status'), 206 '#collapsible' => FALSE, 207 '#collapsed' => FALSE, 208 '#description' => t(''), 209 ); 210 211 if (!isset($form_state['storage'])) { 212 $install_status = _gallery_install_status_init(); 213 $install_status['step'] = GALLERY_INSTALL_STEP_PHPMEMORY; 214 // Check for advanced_help module 215 if (!module_exists('advanced_help')) { 216 drupal_set_message(t('If you install the <a href="@url">advanced help</a> module, Gallery module will provide more 217 and better help.', array('@url' => 'http://drupal.org/project/advanced_help'))); 218 } 219 else { 220 $install_help = theme('advanced_help_topic', 'gallery', 'install', t('Install Tutorial')); 221 drupal_set_message(t('Dont know where to start? Try the "!install-help" page.', array('!install-help' => $install_help))); 222 } 223 } 224 else { 225 $install_status = $form_state['storage']; 226 } 227 228 // Step 1: Check PHP Memory 229 _gallery_install_step_phpmemory($form, $form_state, $install_status); 230 231 // Step 2 : Gallery2 Locations 232 if ($install_status['step'] >= GALLERY_INSTALL_STEP_LOCATIONS) { 233 _gallery_install_step_locations($form, $form_state, $install_status); 234 } 235 236 // Step 3: Drupal Modules and Gallery2 Plugins check 237 if ($install_status['step'] >= GALLERY_INSTALL_STEP_PLUGINS) { 238 _gallery_install_step_plugins($form, $form_state, $install_status); 239 } 240 241 // Step 4: Clean URL configuration 242 if ($install_status['step'] >= GALLERY_INSTALL_STEP_URLREWRITE) { 243 _gallery_install_step_urlrewrite($form, $form_state, $install_status); 244 } 245 246 // Step 5: User Synchronization 247 if ($install_status['step'] >= GALLERY_INSTALL_STEP_USERSYNC) { 248 _gallery_install_step_usersync($form, $form_state, $install_status); 249 } 250 251 $form['install']['status'] = array( 252 '#value' => _gallery_install_status_report($install_status) 253 ); 254 255 $form['install_status'] = array( 256 '#type' => 'value', 257 '#value' => $install_status 258 ); 259 260 $form['buttons']['reset'] = array( 261 '#type' => 'submit', 262 '#value' => t('Reset & Restart'), 263 '#submit' => array('_gallery_install_reset') 264 ); 265 266 return $form; 267 } 268 269 /** 270 * Function _gallery_install_reset(). 271 */ 272 function _gallery_install_reset($form, &$form_state) { 273 variable_del('gallery_autodetect_dir'); 274 variable_del('gallery_uri'); 275 variable_del('gallery_dir'); 276 variable_del('gallery_embed_uri'); 277 variable_del('gallery_valid'); 278 variable_del('gallery_rewrite_disable'); 279 menu_rebuild(); 280 281 unset($form_state['storage']); 282 $form_state['redirect'] = 'admin/settings/gallery/install'; 283 } 284 285 /** 286 * Function _gallery_install_step_phpmemory(). 287 * Step 1: Check PHP Memory 288 */ 289 function _gallery_install_step_phpmemory(&$form, &$form_state, &$install_status) { 290 if ($install_status['step'] == GALLERY_INSTALL_STEP_PHPMEMORY) { 291 $phpmemory_info = _gallery_php_memcheck(); 292 $install_status['phpmemory']['status'] = $phpmemory_info['status']; 293 $install_status['phpmemory']['info'] = $phpmemory_info['info']; 294 if ($phpmemory_info['status']) { 295 $install_status['step'] = GALLERY_INSTALL_STEP_LOCATIONS; 296 } 297 } 298 299 $form['phpmemory'] = array( 300 '#type' => 'fieldset', 301 '#title' => t('Step 1: PHP Memory Test') . ($install_status['phpmemory']['status'] ? ' '. t('(OK)') : ''), 302 '#description' => $install_status['phpmemory']['info'], 303 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_PHPMEMORY), 304 '#collapsed' => $install_status['phpmemory']['status'], 305 ); 306 if (!$install_status['phpmemory']['status']) { 307 $form['phpmemory']['#description'] .= ' '. t('Until this is fixed your Gallery2 cannot be installed.'); 308 $form['phpmemory']['check'] = array('#type' => 'submit', '#value' => t('Check PHP memory again')); 309 } 310 } 311 312 /** 313 * Function _gallery_install_step_locations(). 314 * Step 2: Gallery2 Locations 315 */ 316 function _gallery_install_step_locations(&$form, &$form_state, &$install_status) { 317 $autodetect = variable_get('gallery_autodetect_dir', 1); 318 $title = t('Step 2: Gallery2 location settings') .' - '. ($autodetect ? t('Auto Configuration') : t('Manual Configuration')); 319 $desc = $install_status['locations']['status'] ? '' : $autodetect ? 320 t('Enter the \'Gallery2 URL or URI\' and click \'Test location settings\' 321 to automatically configure the settings needed for embedding Gallery2 into Drupal. Note that 322 the auto-config will not work for all host configurations. If you have tried it with a value 323 you know is correct and it did not work then just use the manual configuration instead.') : 324 t('Enter the \'Gallery2 URL or URI\' and \'Gallery2 filesystem path\' and then click 325 \'Test location settings\'. This will check and configure the settings needed for embedding 326 Gallery2 into Drupal.'); 327 328 $form['locations'] = array( 329 '#type' => 'fieldset', 330 '#title' => $title . ($install_status['locations']['status'] ? ' '. t('(OK)') : ''), 331 '#description' => isset($install_status['locations']['details']) ? ($desc .'<p>'. $install_status['locations']['details'] .'</p>') : $desc, 332 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_LOCATIONS), 333 '#collapsed' => $install_status['locations']['status'] 334 ); 335 336 if ($autodetect) { 337 // Autodetect 338 $gallery_uri = empty($form_state['values']['gallery_uri_auto']) ? 339 variable_get('gallery_uri', '/gallery2/') : $form_state['values']['gallery_uri_auto']; 340 341 $gallery_dir = empty($form_state['values']['gallery_dir_auto']) ? 342 variable_get('gallery_dir', './gallery2/') : $form_state['values']['gallery_dir_auto']; 343 344 $embed_uri = empty($form_state['values']['gallery_embed_uri_auto']) ? 345 variable_get('gallery_embed_uri', '/index.php?q=gallery') : $form_state['values']['gallery_embed_uri_auto']; 346 347 $gallery_base = empty($form_state['values']['gallery_base']) ? 348 variable_get('gallery_base', 'gallery') : $form_state['values']['gallery_base']; 349 350 $form['locations']['gallery_uri_auto'] = array( 351 '#type' => 'textfield', 352 '#title' => t('Gallery2 URL or URI'), 353 '#default_value' => $gallery_uri, 354 '#size' => 64, 355 '#maxlength' => 128, 356 '#description' => t('URL or URI of the G2 standalone location. This can be either the full URL to Gallery2 357 (e.g. http://www.example.com/gallery2) or the path from docroot to the Gallery2 directory 358 (e.g. /gallery2). If using a URI the protocol/hostname are both optional.'), 359 '#disabled' => $install_status['locations']['status'] 360 ); 361 362 if ($install_status['locations']['status']) { 363 $form['locations']['gallery_dir_auto_item'] = array( 364 '#title' => t('Gallery2 filesystem path'), 365 '#type' => 'item', 366 '#value' => $gallery_dir 367 ); 368 } 369 $form['locations']['gallery_dir_auto'] = array( 370 '#type' => 'value', 371 '#value' => $gallery_dir 372 ); 373 374 if ($install_status['locations']['status']) { 375 $form['locations']['gallery_embed_uri_auto_item'] = array( 376 '#title' => t('Embed URI'), 377 '#type' => 'item', 378 '#value' => $embed_uri 379 ); 380 } 381 $form['locations']['gallery_embed_uri_auto'] = array( 382 '#type' => 'value', 383 '#value' => $embed_uri 384 ); 385 386 $form['locations']['gallery_base'] = array( 387 '#type' => 'textfield', 388 '#title' => t('Gallery base (optional)'), 389 '#default_value' => $gallery_base, 390 '#size' => 32, 391 '#maxlength' => 64, 392 '#description' => t('Drupal path to embedded Gallery. This option defaults to \'gallery\' and the embedded gallery 393 will be located at \'@default-base\'.', array('@default-base' => url('gallery'))), 394 '#disabled' => $install_status['locations']['status'] 395 ); 396 } 397 else { 398 // No Autodetect (manual) 399 $gallery_uri = empty($form_state['values']['gallery_uri_man']) ? 400 variable_get('gallery_uri', '/gallery2/') : $form_state['values']['gallery_uri_man']; 401 402 $gallery_dir = empty($form_state['values']['gallery_dir_man']) ? 403 variable_get('gallery_dir', './gallery2/') : $form_state['values']['gallery_dir_man']; 404 405 $embed_uri = empty($form_state['values']['gallery_embed_uri_man']) ? 406 variable_get('gallery_embed_uri', '/index.php?q=gallery') : $form_state['values']['gallery_embed_uri_man']; 407 408 $gallery_base = empty($form_state['values']['gallery_base']) ? 409 variable_get('gallery_base', 'gallery') : $form_state['values']['gallery_base']; 410 411 $form['locations']['gallery_uri_man'] = array( 412 '#type' => 'textfield', 413 '#title' => t('Gallery2 URL or URI'), 414 '#default_value' => $gallery_uri, 415 '#size' => 64, 416 '#maxlength' => 128, 417 '#description' => t('URL or URI of the G2 standalone location. This can be either the full URL to Gallery2 418 (e.g. http://www.example.com/gallery2) or the path from docroot to the Gallery2 directory 419 (e.g. /gallery2). If using a URI the protocol/hostname are both optional.'), 420 '#disabled' => $install_status['locations']['status'] 421 ); 422 423 $form['locations']['gallery_dir_man'] = array( 424 '#type' => 'textfield', 425 '#title' => t('Gallery2 filesystem path'), 426 '#default_value' => $gallery_dir, 427 '#size' => 64, 428 '#maxlength' => 128, 429 '#description' => t('The filesystem path of your Gallery2 directory. This can be either an absolute path 430 (e.g. /home/mysite/htdocs/gallery2) or relative to the root directory of your Drupal 431 installation (e.g. ../gallery2).'), 432 '#disabled' => $install_status['locations']['status'] 433 ); 434 435 $form['locations']['gallery_embed_uri_man'] = array( 436 '#type' => 'textfield', 437 '#title' => t('Embed URI'), 438 '#default_value' => $embed_uri, 439 '#size' => 64, 440 '#maxlength' => 128, 441 '#description' => t('URI to access G2 via Drupal. Don\'t worry if you are using clean urls in Drupal and this 442 still ends in \'index.php?q=gallery\'. This is needed to get the Gallery2 URL rewrite module 443 to work correctly and will not be visible.'), 444 '#disabled' => $install_status['locations']['status'] 445 ); 446 447 $form['locations']['gallery_base'] = array( 448 '#type' => 'textfield', 449 '#title' => t('Gallery base (optional)'), 450 '#default_value' => $gallery_base, 451 '#size' => 32, 452 '#maxlength' => 64, 453 '#description' => t('Drupal path to embedded Gallery. This option defaults to \'gallery\' and the embedded gallery 454 will be located at \'@default-base\'.', array('@default-base' => url('gallery'))), 455 '#disabled' => $install_status['locations']['status'] 456 ); 457 } 458 459 if (!$install_status['locations']['status']) { 460 $form['locations']['location_button'] = array( 461 '#type' => 'submit', 462 '#value' => t('Test location settings'), 463 '#submit' => array('_gallery_install_step_locations_check') 464 ); 465 $form['locations']['switch_config_button'] = array( 466 '#type' => 'submit', 467 '#value' => $autodetect ? t('Use Manual Configuration') : t('Use Auto Configuration'), 468 '#submit' => array('_gallery_install_step_locations_switch') 469 ); 470 } 471 } 472 473 /** 474 * Function _gallery_install_step_locations_check(). 475 */ 476 function _gallery_install_step_locations_check($form, &$form_state) { 477 $install_status = $form_state['values']['install_status']; 478 $autodetect = variable_get('gallery_autodetect_dir', 1); 479 if ($autodetect) { 480 $values['gallery_uri'] = $form_state['values']['gallery_uri_auto']; 481 $values['gallery_base'] = empty($form_state['values']['gallery_base']) ? 'gallery' : $form_state['values']['gallery_base']; 482 } 483 else { 484 $values['gallery_uri'] = $form_state['values']['gallery_uri_man']; 485 $values['gallery_dir'] = $form_state['values']['gallery_dir_man']; 486 $values['gallery_embed_uri'] = $form_state['values']['gallery_embed_uri_man']; 487 } 488 489 list($install_status['locations']['status'], $values, $result) = _gallery_install_locations($values, $autodetect); 490 if (!$install_status['locations']['status']) { 491 $install_status['locations']['details'] = gallery_format_status($result, t('Errors in your current Gallery2 location settings:')); 492 } 493 else { 494 variable_set('gallery_uri', $values['gallery_uri']); 495 variable_set('gallery_dir', $values['gallery_dir']); 496 variable_set('gallery_embed_uri', $values['gallery_embed_uri']); 497 variable_set('gallery_base', $values['gallery_base']); 498 $install_status['locations']['details'] = ''; 499 $install_status['step'] = GALLERY_INSTALL_STEP_PLUGINS; 500 } 501 502 if ($autodetect) { 503 $form_state['values']['gallery_uri_auto'] = $values['gallery_uri']; 504 $form_state['values']['gallery_dir_auto'] = $values['gallery_dir']; 505 $form_state['values']['gallery_embed_uri_auto'] = $values['gallery_embed_uri']; 506 } 507 else { 508 $form_state['values']['gallery_uri_man'] = $values['gallery_uri']; 509 $form_state['values']['gallery_dir_man'] = $values['gallery_dir']; 510 $form_state['values']['gallery_embed_uri_man'] = $values['gallery_embed_uri']; 511 } 512 513 $install_status['locations']['info'] = $install_status['locations']['status'] ? 514 t('The Gallery2 location settings appear to be correct.') : 515 t('There is a problem with the Gallery2 location settings. Please check below and retest. 516 Remember that the auto-config will not work for all hosts.'); 517 518 $form_state['storage'] = $install_status; 519 } 520 521 /** 522 * Function _gallery_install_step_locations_switch(). 523 */ 524 function _gallery_install_step_locations_switch($form, &$form_state) { 525 unset($form_state['storage']); 526 variable_set('gallery_autodetect_dir', !variable_get('gallery_autodetect_dir', 1)); 527 } 528 529 /** 530 * Function _gallery_install_step_plugins(). 531 * Step 3: Drupal Modules / Gallery2 Plugins 532 */ 533 function _gallery_install_step_plugins(&$form, &$form_state, &$install_status) { 534 $title = t('Step 3: Drupal Modules / Gallery2 Plugins') . ($install_status['plugins']['status'] ? ' '. t('(OK)') : ''); 535 $form += _gallery_install_plugins($install_status, $title, ($install_status['step'] > GALLERY_INSTALL_STEP_PLUGINS)); 536 537 if ($install_status['step'] == GALLERY_INSTALL_STEP_PLUGINS) { 538 if (!in_array($install_status['plugins']['status'], array(GALLERY_SEVERITY_ERROR, GALLERY_SEVERITY_WARNING))) { 539 $install_status['step'] = GALLERY_INSTALL_STEP_URLREWRITE; 540 $form['plugins']['#collapsed'] = TRUE; 541 } 542 else { 543 $form['plugins']['plugins_button_desc'] = array( 544 '#type' => 'item', 545 '#value' => t('There are errors in your plugin configuration. Enable/Disable the 546 respective plugins to meet the requirements.') 547 ); 548 $form['plugins']['plugins_button'] = array( 549 '#type' => 'submit', 550 '#value' => t('Check Plugins status again'), 551 '#submit' => array('_gallery_install_step_plugins_check') 552 ); 553 } 554 } 555 } 556 557 /** 558 * Function _gallery_install_step_plugins_check(). 559 */ 560 function _gallery_install_step_plugins_check($form, &$form_state) { 561 $install_status = $form_state['values']['install_status']; 562 _gallery_init(TRUE, array(), FALSE); 563 $form_state['storage'] = $install_status; 564 } 565 566 /** 567 * Function _gallery_install_step_urlrewrite(). 568 * Step 4: Clean URL configuration 569 */ 570 function _gallery_install_step_urlrewrite(&$form, &$form_state, &$install_status) { 571 $title = t('Step 4: Clean URLs / URL Rewrite settings') . ($install_status['urlrewrite']['status'] ? ' '. t('(OK)') : ''); 572 $form['urlrewrite'] = array( 573 '#type' => 'fieldset', 574 '#title' => $title, 575 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_URLREWRITE), 576 '#collapsed' => $install_status['urlrewrite']['status'] 577 ); 578 579 // User selected to skip the URLRewrite step 580 if (variable_get('gallery_rewrite_disable', 0)) { 581 $form['urlrewrite']['#description'] = $install_status['urlrewrite']['info']; 582 $form['urlrewrite']['#description'] .= ' '. t('\'Reset & Restart\' your configuration to change these settings.'); 583 return; 584 } 585 586 $clean_urls_status = variable_get('clean_url', 0); 587 $rewrite_status = gallery_single_plugin_status('rewrite'); 588 589 if ($clean_urls_status) { 590 if ($rewrite_status < GALLERY_PLUGIN_ENABLED) { 591 $form['urlrewrite']['#description'] = t('Clean URLs are enabled in Drupal, but the Gallery2 URL Rewrite plugin is unavailable (!status).', 592 array('!status' => theme('gallery_plugin_status_message', $rewrite_status))); 593 $form['urlrewrite']['check'] = array( 594 '#type' => 'submit', 595 '#value' => t('Check URL Rewrite status again'), 596 '#submit' => array('_gallery_install_step_urlrewrite_check') 597 ); 598 } 599 else { 600 // CleanURL and URLRewrite are both enabled 601 $form['urlrewrite']['#description'] = t('Clean URLs are !clean_url_status in Drupal and the Gallery2 URL Rewrite plugin is 602 !rewrite_status. It is possible to automatically configure the URL Rewrite plugin. 603 The configuration assumes that the rules should be placed in your Drupal .htaccess 604 file (it will add them to the beginning) which works in most applications. If you 605 need a special configuration, enter the desired values manually.', 606 array( 607 '!clean_url_status' => theme('gallery_module_status_message', $clean_urls_status), 608 '!rewrite_status' => theme('gallery_plugin_status_message', $rewrite_status) 609 ) 610 ); 611 612 _gallery_install_urlrewrite($public_path, $htaccess_path, TRUE); 613 $form['urlrewrite']['htaccess_public_path'] = array( 614 '#type' => 'textfield', 615 '#title' => t('Public path to your .htaccess file'), 616 '#size' => 64, 617 '#maxlength' => 255, 618 '#default_value' => $public_path, 619 '#description' => t('This is the location of your Drupal .htaccess file relative to your webserver document root.'), 620 '#disabled' => $install_status['urlrewrite']['status'], 621 ); 622 $form['urlrewrite']['htaccess_filesystem_path'] = array( 623 '#type' => 'textfield', 624 '#title' => t('Filesystem path to your .htaccess file'), 625 '#size' => 100, 626 '#maxlength' => 255, 627 '#default_value' => $htaccess_path, 628 '#description' => t('This is the absolute directory path of your Drupal .htaccess file.'), 629 '#disabled' => $install_status['urlrewrite']['status'], 630 ); 631 632 $form['urlrewrite']['config'] = array( 633 '#type' => 'submit', 634 '#value' => t('Configure URL Rewrite plugin'), 635 '#submit' => array('_gallery_install_step_urlrewrite_configure') 636 ); 637 } 638 } 639 else { 640 $form['urlrewrite']['check'] = array( 641 '#type' => 'submit', 642 '#value' => t('Check URL Rewrite status again'), 643 '#submit' => array('_gallery_install_step_urlrewrite_check') 644 ); 645 } 646 647 $form['urlrewrite']['skip'] = array( 648 '#type' => 'submit', 649 '#value' => t('Skip URL Rewrite Config'), 650 '#submit' => array('_gallery_install_step_urlrewrite_skip') 651 ); 652 } 653 654 /** 655 * Function _gallery_install_step_urlrewrite_check(). 656 */ 657 function _gallery_install_step_urlrewrite_check($form, &$form_state) { 658 $install_status = $form_state['values']['install_status']; 659 _gallery_init(TRUE, array(), FALSE); 660 $form_state['storage'] = $install_status; 661 } 662 663 /** 664 * Function _gallery_install_step_urlrewrite_skip(). 665 */ 666 function _gallery_install_step_urlrewrite_skip($form, &$form_state) { 667 $install_status = $form_state['values']['install_status']; 668 669 variable_set('gallery_rewrite_disable', 1); 670 671 _gallery_init(TRUE, array(), FALSE); 672 _gallery_install_urlrewrite_check($install_status); 673 674 $install_status['step'] = GALLERY_INSTALL_STEP_USERSYNC; 675 $form_state['storage'] = $install_status; 676 } 677 678 /** 679 * Function _gallery_install_step_urlrewrite_configure(). 680 */ 681 function _gallery_install_step_urlrewrite_configure($form, &$form_state) { 682 $install_status = $form_state['values']['install_status']; 683 684 _gallery_init(TRUE, array(), FALSE); 685 if (_gallery_install_urlrewrite($form_state['values']['htaccess_public_path'], $form_state['values']['htaccess_filesystem_path'])) { 686 _gallery_install_urlrewrite_check($install_status); 687 } 688 else { 689 $install_status['urlrewrite']['status'] = FALSE; 690 } 691 692 if ($install_status['urlrewrite']['status']) { 693 $install_status['step'] = GALLERY_INSTALL_STEP_USERSYNC; 694 } 695 $form_state['storage'] = $install_status; 696 } 697 698 /** 699 * Function _gallery_install_step_usersync(). 700 * Step 5: User Synchronization 701 */ 702 function _gallery_install_step_usersync(&$form, &$form_state, &$install_status) { 703 $title = t('Step 5: Initial User Synchronization') . ($install_status['usersync']['status'] ? ' '. t('(OK)') : ''); 704 $form['usersync'] = array( 705 '#type' => 'fieldset', 706 '#title' => $title, 707 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_USERSYNC), 708 '#collapsed' => $install_status['usersync']['status'], 709 ); 710 711 if ($install_status['usersync']['status']) { 712 $form['usersync']['#description'] = t('Your initial user synchronization has been completed already.<br /> 713 If you want to resync all your users or you want to import users from an existing 714 Gallery2 setup, you can always use the <a href= "@gallery-usersync">Advanced Sync 715 </a> options in the Gallery user administration.', 716 array('@gallery-usersync' => url('admin/user/gallery/advanced'))); 717 } 718 else { 719 $form['usersync']['#description'] = t('User synchronization is essential for the embedded Gallery to work correctly. 720 Drupal users/groups are usually synced with their Gallery counterparts when a 721 user/group is modified in Drupal. Missing user mappings will cause errors in your 722 embedded Gallery.<br /><br /> 723 It is recommended that you sync your users now. However there can be reasons to 724 skip this step, e.g. if you have a working Gallery with many users and a fresh 725 Drupal installation. Note that the current user and the Drupal superuser (uid=1) 726 will always be sync.'); 727 728 $form['usersync']['sync'] = array( 729 '#type' => 'submit', 730 '#value' => t('Sync users/groups'), 731 '#submit' => array('_gallery_install_step_usersync_sync') 732 ); 733 $form['usersync']['skip'] = array( 734 '#type' => 'submit', 735 '#value' => t('Skip sync'), 736 '#submit' => array('_gallery_install_step_usersync_skip') 737 ); 738 } 739 } 740 741 /** 742 * Function _gallery_install_step_usersync_skip(). 743 */ 744 function _gallery_install_step_usersync_skip($form, &$form_state) { 745 require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc'); 746 global $user; 747 // Always sync (at least) the current user to avoid 748 // errors (unknown user) during GalleryEmbed::init() 749 gallery_user_modify($user, 'update', TRUE, array()); 750 // Make sure the Drupal superuser (uid=1) always gets admin access 751 if ($user->uid != 1) { 752 gallery_user_modify(user_load(array('uid' => 1)), 'update', FALSE, array()); 753 } 754 755 // Set the global status variable 'gallery_valid' 756 gallery_set_status(array( 757 'gallery_valid' => array( 758 'title' => t('Overall Status (Installation)'), 759 'severity' => GALLERY_SEVERITY_SUCCESS, 760 ), 761 )); 762 variable_set('gallery_valid', TRUE); 763 764 // Clear cache and rebuild menu 765 cache_clear_all('gallery', 'cache', TRUE); 766 menu_rebuild(); 767 768 $form_state['redirect'] = 'admin/settings/gallery'; 769 $form_state['storage'] = array(); 770 } 771 772 /** 773 * Function _gallery_install_step_usersync_sync(). 774 */ 775 function _gallery_install_step_usersync_sync($form, &$form_state) { 776 _gallery_install_step_usersync_skip($form, $form_state); 777 778 // Trigger bulk user/group sync 779 require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc'); 780 $batch = array( 781 'title' => t('Initial User Synchronization'), 782 'operations' => array(array('_gallery_user_advanced_sync', array())), 783 'file' => drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc', 784 'finished' => '_gallery_user_advanced_finished' 785 ); 786 batch_set($batch); 787 } 788 789 /** 790 * Function _gallery_install_locations(). 791 */ 792 function _gallery_install_locations($orig, $autodetect = TRUE) { 793 global $language; 794 include_once(drupal_get_path('module', 'gallery') .'/G2EmbedDiscoveryUtilities.class'); 795 796 // Result status array 797 $result = array( 798 'gallery_uri' => array( 799 'title' => t('URI of Gallery2'), 800 'severity' => GALLERY_SEVERITY_ERROR, 801 ), 802 'gallery_dir' => array( 803 'title' => t('Location of Gallery2'), 804 'severity' => GALLERY_SEVERITY_ERROR, 805 ), 806 'init' => array( 807 'title' => t('Gallery Init'), 808 'severity' => GALLERY_SEVERITY_ERROR, 809 ), 810 ); 811 812 $vars = array(); 813 $vars['locations_valid'] = TRUE; 814 815 // Extract gallery_base_from embed_uri if required 816 $vars['gallery_base'] = isset($orig['gallery_base']) ? $orig['gallery_base'] : strtolower($orig['gallery_embed_uri']); 817 if (($pos = strrpos($vars['gallery_base'], '=')) !== FALSE) { 818 $vars['gallery_base'] = trim(substr($vars['gallery_base'], $pos + 1), '/'); 819 } 820 // Construct embed_uri value 821 $embed_uri = isset($orig['gallery_embed_uri']) ? $orig['gallery_embed_uri'] : ''; 822 if ($autodetect || empty($embed_uri)) { 823 $options = array(); 824 // prevent the language prefix from being added to $embed_uri 825 if (function_exists('language_url_rewrite')) { 826 $options['language'] = (object)array('language' => $language->language, 'prefix' => '', 'domain' => ''); 827 } 828 $embed_uri = url($vars['gallery_base'], $options); 829 // Strip the end /gallery if present and replace with index.php?q=gallery to avoid any 830 // url rewrite issues. See http://gallery.menalto.com/node/46181 831 // Note the use of index.php in all cases. Not needed for Apache, but for IIS 832 $length = strlen('/'. $vars['gallery_base']); 833 if (substr($embed_uri, - $length) == '/'. $vars['gallery_base']) { 834 $embed_uri = substr($embed_uri, 0, - $length + 1) .'index.php?q='. $vars['gallery_base']; 835 } 836 } 837 838 // Normalise the Embed Application URI 839 $embed_uri = G2EmbedDiscoveryUtilities::normalizeEmbedUri($embed_uri); 840 $vars['gallery_embed_uri'] = $embed_uri; 841 842 // Normalise the G2 URI 843 $g2_uri = G2EmbedDiscoveryUtilities::normalizeG2Uri($orig['gallery_uri']); 844 $vars['gallery_uri'] = $g2_uri; 845 846 // Find the Gallery Directory and Embed URI 847 if ($autodetect) { 848 // Auto-Detect the G2 embed path 849 list($success, $embed_php_path, $error_string) = G2EmbedDiscoveryUtilities::getG2EmbedPathByG2Uri($g2_uri); 850 if ($success) { 851 // G2 Embed Path is found OK 852 $vars['gallery_dir'] = rtrim($embed_php_path, 'embed.php'); 853 } 854 else { 855 // Something is wrong with the G2 URI given as the G2 embed path is not found 856 // Try getG2EmbedPathByG2UriEmbedUriAndLocation instead 857 $drupal_path = realpath(".") .'/'; 858 list($success, $embed_php_path, $error_string) = 859 G2EmbedDiscoveryUtilities::getG2EmbedPathByG2UriEmbedUriAndLocation($g2_uri, $embed_uri, $drupal_path); 860 if ($success) { 861 // G2 Embed Path is found OK 862 $vars['gallery_dir'] = rtrim($embed_php_path, 'embed.php'); 863 } 864 else { 865 $result['gallery_uri']['info'] = $error_string; 866 $result['gallery_uri']['status'] = FALSE; 867 $vars['gallery_dir'] = ''; 868 $vars['locations_valid'] = FALSE; 869 } 870 } 871 // Check for config.php in the embed_path (not existing => invalid path) 872 // e.g. this is the path to the G2 codebase, but we have a multisite configuration 873 if (!empty($vars['gallery_dir'])) { 874 list($ok, $error_string) = G2EmbedDiscoveryUtilities::isFileReadable($vars['gallery_dir'] .'config.php'); 875 if (!$ok) { 876 $result['gallery_dir']['status'] = FALSE; 877 $result['gallery_dir']['info'] = $error_string; 878 $vars['gallery_dir'] = ''; 879 $vars['locations_valid'] = FALSE; 880 } 881 } 882 } 883 else { 884 // Do not autodetect the variables, but check the manually entered ones. 885 $embed_php_path = $orig['gallery_dir']; 886 $embed_php_path .= (substr($embed_php_path, -1) != '/') ? '/' : ''; 887 // Check path can be read, adding embed.php if needed 888 list($ok, $error_string) = G2EmbedDiscoveryUtilities::isFileReadable($embed_php_path .'embed.php'); 889 $vars['gallery_dir'] = $embed_php_path; 890 if (!$ok) { 891 $result['gallery_dir']['status'] = FALSE; 892 $result['gallery_dir']['info'] = $error_string; 893 $vars['locations_valid'] = FALSE; 894 } 895 else { 896 // Check for config.php in the embed_path (not existing => invalid path) 897 // e.g. this is the path to the G2 codebase, but we have a multisite configuration 898 list($ok, $error_string) = G2EmbedDiscoveryUtilities::isFileReadable($embed_php_path .'config.php'); 899 if (!$ok) { 900 $result['gallery_dir']['status'] = FALSE; 901 $result['gallery_dir']['info'] = $error_string; 902 $vars['locations_valid'] = FALSE; 903 } 904 } 905 } 906 907 // If the filepaths seem correct then check Gallery2 works and has the correct module configs 908 if ($vars['locations_valid']) { 909 // Gallery install is thought valid, so init it. 910 if (!_gallery_init(TRUE, $vars, FALSE)) { 911 // Gallery install was supposed to be valid, but it still failed. Something is wrong. 912 $result['gallery_init']['status'] = FALSE; 913 $result['gallery_init']['info'] = t('Everything seemed OK, but the Gallery could still not be initialised. 914 Perhaps a manually entered value is incorrect.'); 915 $vars['locations_valid'] = FALSE; 916 } 917 else { 918 // Is Gallery2 installed inside the Drupal root directory? 919 _gallery_install_in_drupal_folder($vars['gallery_dir']); 920 // Update version info 921 gallery_version(); 922 GalleryEmbed::done(); 923 } 924 } 925 926 // Only return items where status has been set 927 foreach ($result as $key => $value) { 928 if (!isset($value['status'])) { 929 unset($result[$key]); 930 } 931 } 932 933 return array($vars['locations_valid'], $vars, $result); 934 } 935 936 /** 937 * Function _gallery_install_in_drupal_folder(). 938 */ 939 function _gallery_install_in_drupal_folder($gallery_dir) { 940 global $base_url; 941 static $warn = TRUE; 942 943 // Dont proceed if G2 is not initialized 944 if (!isset($GLOBALS['gallery'])) { 945 return; 946 } 947 948 if (!empty($gallery_dir)) { 949 // Reset 'gallery_outside' state 950 variable_del('gallery_outside'); 951 // Get location of Drupal, Gallery2, etc. 952 $docroot = strtolower(str_replace('/', '\\' , $_SERVER['DOCUMENT_ROOT'])); 953 $base_path = strtolower(str_replace('/', '\\' , base_path())); 954 $g2_base = strtolower($GLOBALS['gallery']->getConfig('galleryBaseUrl')); 955 if ((strpos(strtolower($gallery_dir), $base_path) === FALSE && strpos(strtolower($gallery_dir), $docroot) !== FALSE) 956 || (!empty($g2_base) && strpos($g2_base, $base_url) === FALSE) || strpos(strtolower($gallery_dir), '../') !== FALSE) { 957 // G2 is installed outside the Drupal root directory 958 variable_set('gallery_outside', TRUE); 959 if ($warn) { 960 // Avoid duplicate warning 961 $warn = FALSE; 962 drupal_set_message(t('Your location settings are valid, but your Gallery2 is installed outside the Drupal 963 root directory. It is highly advisable to move G2 into the Drupal folder or to create 964 a symbolic link in the Drupal directory pointing to your G2 installation (see 965 instructions on <a href="@codex">codex.gallery2.org</a>).', 966 array('@codex' => url('http://codex.gallery2.org/Integration:Drupal:Installation'))), 'error'); 967 } 968 } 969 } 970 } 971 972 /** 973 * Function _gallery_install_plugins(). 974 */ 975 function _gallery_install_plugins(&$install_status, $title = NULL, $collapse = FALSE) { 976 $form['plugins'] = array( 977 '#type' => 'fieldset', 978 '#title' => isset($title) ? $title : t('Drupal Modules / Gallery2 Plugins'), 979 '#collapsible' => TRUE, 980 '#collapsed' => $collapse, 981 ); 982 983 $header = array(t('Name'), t('Status'), t('Description')); 984 $overall_plugin_severity = GALLERY_SEVERITY_UNKNOWN - 1; 985 $overall_plugin_status = GALLERY_PLUGIN_ENABLED; 986 987 // Wanted (required) G2 plugins 988 $rows = array(); 989 $wanted_g2_plugins = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_WANTED); 990 foreach ($wanted_g2_plugins as $key => $module) { 991 // Find the combination of status and severity of the plugin 992 $severity = ($module['status'] != GALLERY_PLUGIN_ENABLED) ? $module['severity'] : GALLERY_SEVERITY_SUCCESS; 993 $row = array(); 994 $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%'); 995 $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status']), 'align' => 'center'); 996 $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => 'gallery-install-plugin-'. $key); 997 $rows[] = $row; 998 if ($module['status'] != GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) { 999 $overall_plugin_severity = $severity; 1000 $overall_plugin_status = $module['status']; 1001 } 1002 } 1003 $form['plugins']['wanted_g2_plugins'] = array( 1004 '#type' => 'fieldset', 1005 '#title' => t('Recommended Gallery2 plugins'), 1006 '#collapsible' => FALSE, 1007 '#collapsed' => FALSE, 1008 '#value' => theme('table', $header, $rows, array('class' => 'package')), 1009 '#description' => t('These Gallery2 plugins support much of the functionality that the Drupal Gallery module provides. 1010 None of them are strictly required, but you will almost certainly want to activate at least some 1011 of them (particularly the Image Block plugin).'), 1012 ); 1013 1014 // Unwanted (interfering) G2 plugins 1015 $rows = array(); 1016 $unwanted_g2_plugins = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_UNWANTED); 1017 foreach ($unwanted_g2_plugins as $key => $module) { 1018 // Find the combination of status and severity of the plugin 1019 $severity = ($module['status'] == GALLERY_PLUGIN_ENABLED) ? $module['severity'] : GALLERY_SEVERITY_SUCCESS; 1020 $row = array(); 1021 $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%'); 1022 $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status'], TRUE, TRUE), 'align' => 'center'); 1023 $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => 'gallery-install-plugin-'. $key); 1024 $rows[] = $row; 1025 if ($module['status'] == GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) { 1026 $overall_plugin_severity = $severity; 1027 $overall_plugin_status = $module['status']; 1028 } 1029 } 1030 $form['plugins']['unwanted_g2_plugins'] = array( 1031 '#type' => 'fieldset', 1032 '#title' => t('Gallery2 plugins which should not be installed'), 1033 '#collapsible' => FALSE, 1034 '#collapsed' => FALSE, 1035 '#value' => theme('table', $header, $rows, array('class' => 'package')), 1036 '#description' => t('These Gallery2 plugins should not be used when Gallery2 is 1037 embedded into Drupal as they may cause problems.'), 1038 ); 1039 1040 // Wanted (optional) Drupal modules 1041 $rows = array(); 1042 $wanted_modules = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_DRUPAL); 1043 foreach ($wanted_modules as $key => $module) { 1044 // Find the combination of status and severity of the plugin 1045 $severity = $module['status'] ? GALLERY_SEVERITY_SUCCESS : $module['severity']; 1046 $row = array(); 1047 $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%'); 1048 $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status']), 'align' => 'center'); 1049 $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => 'gallery-install-plugin-'. $key); 1050 $rows[] = $row; 1051 if ($module['status'] != GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) { 1052 $overall_plugin_severity = $severity; 1053 $overall_plugin_status = $module['status']; 1054 } 1055 } 1056 $form['plugins']['wanted_modules'] = array( 1057 '#type' => 'fieldset', 1058 '#title' => t('Optional Drupal modules'), 1059 '#collapsible' => FALSE, 1060 '#collapsed' => FALSE, 1061 '#value' => theme('table', $header, $rows, array('class' => 'package')), 1062 '#description' => t('These Drupal modules can optionally be used to enhance the functionality of the Gallery module.'), 1063 ); 1064 1065 // Check if no issue was found. 1066 if ($overall_plugin_severity < GALLERY_SEVERITY_UNKNOWN) { 1067 $overall_plugin_severity = GALLERY_SEVERITY_SUCCESS; 1068 } 1069 1070 $install_status['plugins']['status'] = $overall_plugin_status; 1071 $install_status['plugins']['severity'] = $overall_plugin_severity; 1072 $install_status['plugins']['info'] = ($overall_plugin_status <= 0) ? 1073 t('You may have some loss in functionality in your embedded Gallery2 (see below for details). You should check 1074 the details and if the functionality is not important for your site you can just ignore this.') : 1075 t('The status of all Drupal modules and Gallery2 plugins is optimal for your embedded Gallery2.'); 1076 1077 // Print out an extra warning if location errors are present 1078 // (and collapse fieldset to draw attention to the overview table instead) 1079 if (!$install_status['locations']['status']) { 1080 $form['plugins']['#collapsed'] = TRUE; 1081 $install_status['plugins']['info'] = t('Due to errors in your location settings status information is 1082 not available for your G2 plugins.'); 1083 } 1084 1085 return $form; 1086 } 1087 1088 /** 1089 * Function _gallery_install_urlrewrite_check(). 1090 */ 1091 function _gallery_install_urlrewrite_check(&$install_status) { 1092 // User selected to skip the URLRewrite step 1093 if (variable_get('gallery_rewrite_disable', 0)) { 1094 $install_status['urlrewrite']['status'] = TRUE; 1095 $install_status['urlrewrite']['info'] = t('URL Rewrite has been disabled manually.'); 1096 return; 1097 } 1098 1099 // Skip URLRewrite check if location errors are present 1100 if (!$install_status['locations']['status']) { 1101 $install_status['urlrewrite']['status'] = FALSE; 1102 $install_status['urlrewrite']['info'] = t('Due to errors in your location settings the URL Rewrite 1103 status could not be obtained.'); 1104 return; 1105 } 1106 1107 if (variable_get('clean_url', 0)) { 1108 if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED) { 1109 _gallery_install_urlrewrite($public_path, $htaccess_path, TRUE); 1110 // Check for writable .htaccess file 1111 if (file_exists($htaccess_path .'.htaccess')) { 1112 if (is_writable($htaccess_path .'.htaccess')) { 1113 $install_status['urlrewrite']['status'] = TRUE; 1114 $install_status['urlrewrite']['info'] = t('There is a writable .htaccess file in your defined Drupal directory 1115 (@dir).', array('@dir' => $htaccess_path)); 1116 } 1117 else { 1118 $install_status['urlrewrite']['status'] = FALSE; 1119 $install_status['urlrewrite']['info'] = t('The .htaccess file in your defined Drupal directory (@dir) is not 1120 writable. Please CHMOD it to 644 (or 666 if 644 does not work).', 1121 array('@dir' => $htaccess_path)); 1122 } 1123 } 1124 else { 1125 $install_status['urlrewrite']['status'] = FALSE; 1126 $install_status['urlrewrite']['info'] = t('There is no .htaccess file in your defined Drupal directory (@dir) or 1127 the directory does not exist.', array('@dir' => $htaccess_path)); 1128 } 1129 } 1130 else { 1131 $install_status['urlrewrite']['status'] = FALSE; 1132 $install_status['urlrewrite']['info'] = t('Clean URLs are enabled in Drupal, but the Gallery2 URL Rewrite plugin 1133 is unavailable.'); 1134 } 1135 } 1136 else { 1137 $install_status['urlrewrite']['status'] = TRUE; 1138 $install_status['urlrewrite']['info'] = t('Clean URLs are disabled in Drupal and the URL Rewrite plugin will not 1139 be configured.'); 1140 } 1141 1142 // Check syntax of the 'Show Item' rule (must start with 'gallery/') 1143 list ($ret, $rules) = GalleryCoreApi::getPluginParameter('module', 'rewrite', 'activeRules'); 1144 if (!$ret) { 1145 $rules = unserialize($rules); 1146 $gallery_base = variable_get('gallery_base', 'gallery'); 1147 if (isset($rules['rewrite'][0]['pattern']) && substr($rules['rewrite'][0]['pattern'], 0, 7) != $gallery_base) { 1148 $install_status['urlrewrite']['info'] .= ' <strong>'. t('Your \'Show Item\' rule should start with \'@gallery-base/\'. 1149 Make sure to change the URL Rewrite rule(s) accordingly.', 1150 array('@gallery-base' => $gallery_base)) .'</strong>'; 1151 } 1152 } 1153 } 1154 1155 /** 1156 * Function _gallery_install_urlrewrite(). 1157 */ 1158 function _gallery_install_urlrewrite(&$public_path, &$htaccess_path, $load_config = FALSE) { 1159 list($ret, $rewrite_api) = GalleryCoreApi::newFactoryInstance('RewriteApi'); 1160 if ($ret || !isset($rewrite_api)) { 1161 gallery_error(t('Error trying to create URL Rewrite plugin instance.'), $ret); 1162 if (!$ret) { 1163 drupal_set_message(t('URL Rewrite plugin could not be instantiated. 1164 Please check its configuration in standalone Gallery2.'), 'error'); 1165 } 1166 return FALSE; 1167 } 1168 1169 list($ret, $params) = $rewrite_api->fetchEmbedConfig(); 1170 if ($ret) { 1171 gallery_error(t('Error trying to fetch Embedded URL Rewrite configuration.'), $ret); 1172 return FALSE; 1173 } 1174 1175 // Load the configuration from G2 (or derive from Drupal path) 1176 if ($load_config) { 1177 if (empty($params['embeddedHtaccess'])) { 1178 $http = 'http'. (isset($_SERVER['HTTPS']) ? (($_SERVER['HTTPS'] == 'on') ? 's' : '') : ''); 1179 $public_path = str_replace($http .'://'. $_SERVER['HTTP_HOST'], '', base_path()); 1180 $htaccess_path = realpath(".") .'/'; 1181 } 1182 else { 1183 $public_path = $params['embeddedLocation']; 1184 $htaccess_path = $params['embeddedHtaccess']; 1185 } 1186 } 1187 1188 // Check for trailing slash 1189 $public_path .= (substr($public_path, -1) != '/') ? '/' : ''; 1190 $htaccess_path .= (substr($htaccess_path, -1) != '/') ? '/' : ''; 1191 1192 if (!$load_config) { 1193 if (!file_exists($htaccess_path .'.htaccess')) { 1194 // File .htaccess does not exist 1195 if (is_writable($htaccess_path .'.htaccess')) { 1196 // Directory exists and is writable => try to create .htaccess 1197 $f = fopen($htaccess_path .'.htaccess', 'w'); 1198 fclose($f); 1199 } 1200 else { 1201 return FALSE; 1202 } 1203 } 1204 // Save the G2 rewrite values 1205 $params['embeddedLocation'] = $public_path; 1206 $params['embeddedHtaccess'] = $htaccess_path; 1207 list($ret, $code, $errstr) = $rewrite_api->saveEmbedConfig($params); 1208 if ($ret) { 1209 gallery_error(t('Error trying to save Embedded URL Rewrite configuration.'), $ret); 1210 return FALSE; 1211 } 1212 if ($code) { 1213 $errstr = $code .' - '. (is_array($errstr) ? $errstr[1] : $errstr); 1214 drupal_set_message(t('The Gallery2 URL Rewrite plugin returned the following error:') .'<br /><pre>'. $errstr .'</pre>', 'error'); 1215 return FALSE; 1216 } 1217 } 1218 1219 return TRUE; 1220 }
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 |