4 require_once(drupal_get_path('module', 'gallery') .
'/gallery_settings.inc');
7 * gallery.module : gallery_install.inc
8 * Configure embedded Gallery install (directory options, etc.)
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);
18 * Function _gallery_install_status_init().
20 function _gallery_install_status_init() {
23 'title' => t('PHP Memory Limit'),
24 'severity' => GALLERY_SEVERITY_ERROR
,
28 'title' => t('Gallery2 locations'),
29 'severity' => GALLERY_SEVERITY_ERROR
,
33 'title' => t('Drupal Modules / Gallery2 Plugins'),
34 'severity' => GALLERY_SEVERITY_WARNING
,
37 'urlrewrite' => array(
38 'title' => t('Clean URL / URL Rewrite'),
39 'severity' => GALLERY_SEVERITY_WARNING
,
43 'title' => t('Initial User Synchronization'),
44 'severity' => GALLERY_SEVERITY_ERROR
,
51 * Function _gallery_install_status_report().
53 function _gallery_install_status_report($install_status) {
54 // Install status table
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']) {
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' => $step);
71 $rows[] = array(array(
72 'data' => t('Critical errors are present.'),
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
,
87 return theme('table', array(t('Step'), t('Status'), t('Description')), $rows, array('class' => 'package'));
91 * Function _gallery_install_status().
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.'),
103 $install_status = _gallery_install_status_init();
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'];
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 $autodetect = variable_get('gallery_autodetect_dir', 1);
115 list($install_status['locations']['status'], $values, $result) = _gallery_install_locations($values, $autodetect);
116 $install_status['locations']['info'] = $install_status['locations']['status'] ?
117 t('The Gallery2 location settings appear to be correct.') :
118 gallery_format_status($result, t('Errors in your current Gallery2 location settings:'));
120 // Step 3: Drupal Modules and Gallery2 Plugins check
121 $form += _gallery_install_plugins($install_status);
123 // Step 4: Clean URL configuration
124 _gallery_install_urlrewrite_check($install_status);
126 // Step 5: User Synchronization
127 // Always TRUE (= gallery_valid), otherwise we would be redirected to the install wizard page instead
128 $install_status['usersync']['status'] = TRUE
;
129 $install_status['usersync']['info'] = t('Your initial user synchronization has been completed already.<br /> If you
130 want to resync all your users or you want to import users from an existing
131 Gallery2 setup, you can always use the <a href= "@gallery-usersync">Advanced
132 Sync</a> options in the Gallery user administration.',
133 array('@gallery-usersync' => url('admin/user/gallery/advanced')));
135 $form['install']['status'] = array(
136 '#value' => _gallery_install_status_report($install_status)
139 $form['buttons']['reset'] = array(
141 '#value' => t('Reset & Restart'),
142 '#submit' => array('_gallery_install_reset')
149 * Function _gallery_install().
151 function _gallery_install($form_state) {
152 $form['install'] = array(
153 '#type' => 'fieldset',
154 '#title' => t('Install status'),
155 '#collapsible' => FALSE
,
156 '#collapsed' => FALSE
,
157 '#description' => t(''),
160 if (!isset($form_state['storage'])) {
161 $install_status = _gallery_install_status_init();
162 $install_status['step'] = GALLERY_INSTALL_STEP_PHPMEMORY
;
165 $install_status = $form_state['storage'];
168 // Step 1: Check PHP Memory
169 _gallery_install_step_phpmemory($form, $form_state, $install_status);
171 // Step 2 : Gallery2 Locations
172 if ($install_status['step'] >= GALLERY_INSTALL_STEP_LOCATIONS
) {
173 _gallery_install_step_locations($form, $form_state, $install_status);
176 // Step 3: Drupal Modules and Gallery2 Plugins check
177 if ($install_status['step'] >= GALLERY_INSTALL_STEP_PLUGINS
) {
178 _gallery_install_step_plugins($form, $form_state, $install_status);
181 // Step 4: Clean URL configuration
182 if ($install_status['step'] >= GALLERY_INSTALL_STEP_URLREWRITE
) {
183 _gallery_install_step_urlrewrite($form, $form_state, $install_status);
186 // Step 5: User Synchronization
187 if ($install_status['step'] >= GALLERY_INSTALL_STEP_USERSYNC
) {
188 _gallery_install_step_usersync($form, $form_state, $install_status);
191 $form['install']['status'] = array(
192 '#value' => _gallery_install_status_report($install_status)
195 $form['install_status'] = array(
197 '#value' => $install_status
200 $form['buttons']['reset'] = array(
202 '#value' => t('Reset & Restart'),
203 '#submit' => array('_gallery_install_reset')
210 * Function _gallery_install_reset().
212 function _gallery_install_reset($form, &$form_state) {
213 variable_del('gallery_autodetect_dir');
214 variable_del('gallery_uri');
215 variable_del('gallery_dir');
216 variable_del('gallery_embed_uri');
217 variable_del('gallery_valid');
218 variable_del('gallery_rewrite_disable');
221 unset($form_state['storage']);
222 $form_state['redirect'] = 'admin/settings/gallery/install';
226 * Function _gallery_install_step_phpmemory().
227 * Step 1: Check PHP Memory
229 function _gallery_install_step_phpmemory(&$form, &$form_state, &$install_status) {
230 if ($install_status['step'] == GALLERY_INSTALL_STEP_PHPMEMORY
) {
231 $phpmemory_info = _gallery_php_memcheck();
232 $install_status['phpmemory']['status'] = $phpmemory_info['status'];
233 $install_status['phpmemory']['info'] = $phpmemory_info['info'];
234 if ($phpmemory_info['status']) {
235 $install_status['step'] = GALLERY_INSTALL_STEP_LOCATIONS
;
239 $form['phpmemory'] = array(
240 '#type' => 'fieldset',
241 '#title' => t('Step 1: PHP Memory Test') .
($install_status['phpmemory']['status'] ?
' '.
t('(OK)') : ''),
242 '#description' => $install_status['phpmemory']['info'],
243 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_PHPMEMORY
),
244 '#collapsed' => $install_status['phpmemory']['status'],
246 if (!$install_status['phpmemory']['status']) {
247 $form['phpmemory']['#description'] .
= ' '.
t('Until this is fixed your Gallery2 cannot be installed.');
248 $form['phpmemory']['check'] = array('#type' => 'submit', '#value' => t('Check PHP memory again'));
253 * Function _gallery_install_step_locations().
254 * Step 2: Gallery2 Locations
256 function _gallery_install_step_locations(&$form, &$form_state, &$install_status) {
257 $autodetect_dir = variable_get('gallery_autodetect_dir', 1);
258 $title = t('Step 2: Gallery2 location settings') .
' - '.
($autodetect_dir ?
t('Auto Configuration') : t('Manual Configuration'));
259 $desc = $install_status['locations']['status'] ?
'' : $autodetect_dir ?
260 t('Enter the \'Gallery2 URL or URI\' and click \'Test location settings\'
261 to automatically configure the settings needed for embedding Gallery2 into Drupal. Note that
262 the auto-config will not work for all host configurations. If you have tried it with a value
263 you know is correct and it did not work then just use the manual configuration instead.') :
264 t('Enter the \'Gallery2 URL or URI\' and \'Gallery2 filesystem path\' and then click
265 \'Test location settings\'. This will check and configure the settings needed for embedding
266 Gallery2 into Drupal.');
268 $form['locations'] = array(
269 '#type' => 'fieldset',
270 '#title' => $title .
($install_status['locations']['status'] ?
' '.
t('(OK)') : ''),
271 '#description' => isset($install_status['locations']['details']) ?
($desc .
'<p>'.
$install_status['locations']['details'] .
'</p>') : $desc,
272 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_LOCATIONS
),
273 '#collapsed' => $install_status['locations']['status']
276 if ($autodetect_dir) {
278 $gallery_uri = isset($form_state['values']['gallery_uri_auto']) ?
279 $form_state['values']['gallery_uri_auto'] : ($install_status['locations']['status'] ?
280 variable_get('gallery_uri', '/gallery2/') : '');
282 $gallery_dir = isset($form_state['values']['gallery_dir_auto']) ?
283 $form_state['values']['gallery_dir_auto'] : ($install_status['locations']['status'] ?
284 variable_get('gallery_dir', './gallery2/') : '');
286 $embed_uri = isset($form_state['values']['gallery_embed_uri_auto']) ?
287 $form_state['values']['gallery_embed_uri_auto'] : ($install_status['locations']['status'] ?
288 variable_get('gallery_embed_uri', '?q=gallery') : '');
290 $form['locations']['gallery_uri_auto'] = array(
291 '#type' => 'textfield',
292 '#title' => t('Gallery2 URL or URI'),
293 '#default_value' => $gallery_uri,
296 '#description' => t('URL or URI of the G2 standalone location. This can be either the full URL to Gallery2
297 (e.g. http://www.example.com/gallery2) or the path from docroot to the Gallery2 directory
298 (e.g. /gallery2). If using a URI the protocol/hostname are both optional.'),
299 '#disabled' => $install_status['locations']['status']
302 if (!empty($gallery_dir)) {
303 $form['locations']['gallery_dir_auto_item'] = array(
304 '#title' => t('Gallery2 filesystem path'),
306 '#value' => $gallery_dir
309 $form['locations']['gallery_dir_auto'] = array(
311 '#value' => $gallery_dir
314 if (!empty($embed_uri)) {
315 $form['locations']['gallery_embed_uri_auto_item'] = array(
316 '#title' => t('Embed URI'),
318 '#value' => $embed_uri
321 $form['locations']['gallery_embed_uri_auto'] = array(
323 '#value' => $embed_uri
327 // No Autodetect (manual)
328 $gallery_uri = isset($form_state['values']['gallery_uri_man']) ?
329 $form_state['values']['gallery_uri_man'] : ($install_status['locations']['status'] ?
330 variable_get('gallery_uri', '/gallery2/') : '');
332 $gallery_dir = isset($form_state['values']['gallery_dir_man']) ?
333 $form_state['values']['gallery_dir_man'] : ($install_status['locations']['status'] ?
334 variable_get('gallery_dir', './gallery2/') : '');
336 $embed_uri = isset($form_state['values']['gallery_embed_uri_man']) ?
337 $form_state['values']['gallery_embed_uri_man'] : ($install_status['locations']['status'] ?
338 variable_get('gallery_embed_uri', '?q=gallery') : '');
340 $form['locations']['gallery_uri_man'] = array(
341 '#type' => 'textfield',
342 '#title' => t('Gallery2 URL or URI'),
343 '#default_value' => $gallery_uri,
346 '#description' => t('URL or URI of the G2 standalone location. This can be either the full URL to Gallery2
347 (e.g. http://www.example.com/gallery2) or the path from docroot to the Gallery2 directory
348 (e.g. /gallery2). If using a URI the protocol/hostname are both optional.'),
349 '#disabled' => $install_status['locations']['status']
352 $form['locations']['gallery_dir_man'] = array(
353 '#type' => 'textfield',
354 '#title' => t('Gallery2 filesystem path'),
355 '#default_value' => $gallery_dir,
358 '#description' => t('The filesystem path of your Gallery2 directory. This can be either an absolute path
359 (e.g. /home/mysite/htdocs/gallery2) or relative to the root directory of your Drupal
360 installation (e.g. ../gallery2).'),
361 '#disabled' => $install_status['locations']['status']
364 $form['locations']['gallery_embed_uri_man'] = array(
365 '#type' => 'textfield',
366 '#title' => t('Embed URI'),
367 '#default_value' => $embed_uri,
370 '#description' => t('URI to access G2 via Drupal. Don\'t worry if you are using clean urls in Drupal and this
371 still ends in \'index.php?q=gallery\'. This is needed to get the Gallery2 URL rewrite module
372 to work correctly and will not be visible.'),
373 '#disabled' => $install_status['locations']['status']
377 if (!$install_status['locations']['status']) {
378 $form['locations']['location_button'] = array(
380 '#value' => t('Test location settings'),
381 '#submit' => array('_gallery_install_step_locations_check')
383 $form['locations']['switch_config_button'] = array(
385 '#value' => $autodetect_dir ?
t('Use Manual Configuration') : t('Use Auto Configuration'),
386 '#submit' => array('_gallery_install_step_locations_switch')
392 * Function _gallery_install_step_locations_check().
394 function _gallery_install_step_locations_check($form, &$form_state) {
395 $install_status = $form_state['values']['install_status'];
396 $autodetect = variable_get('gallery_autodetect_dir', 1);
398 $values['gallery_uri'] = $form_state['values']['gallery_uri_auto'];
401 $values['gallery_uri'] = $form_state['values']['gallery_uri_man'];
402 $values['gallery_dir'] = $form_state['values']['gallery_dir_man'];
403 $values['gallery_embed_uri'] = $form_state['values']['gallery_embed_uri_man'];
406 list($install_status['locations']['status'], $values, $result) = _gallery_install_locations($values, $autodetect);
407 if (!$install_status['locations']['status']) {
408 $install_status['locations']['details'] = gallery_format_status($result, t('Errors in your current Gallery2 location settings:'));
411 variable_set('gallery_uri', $values['gallery_uri']);
412 variable_set('gallery_dir', $values['gallery_dir']);
413 variable_set('gallery_embed_uri', $values['gallery_embed_uri']);
414 $install_status['step'] = GALLERY_INSTALL_STEP_PLUGINS
;
418 $form_state['values']['gallery_uri_auto'] = $values['gallery_uri'];
419 $form_state['values']['gallery_dir_auto'] = $values['gallery_dir'];
420 $form_state['values']['gallery_embed_uri_auto'] = $values['gallery_embed_uri'];
423 $form_state['values']['gallery_uri_man'] = $values['gallery_uri'];
424 $form_state['values']['gallery_dir_man'] = $values['gallery_dir'];
425 $form_state['values']['gallery_embed_uri_man'] = $values['gallery_embed_uri'];
428 $install_status['locations']['info'] = $install_status['locations']['status'] ?
429 t('The Gallery2 location settings appear to be correct.') :
430 t('There is a problem with the Gallery2 location settings. Please check below and retest.
431 Remember that the auto-config will not work for all hosts.');
433 $form_state['storage'] = $install_status;
437 * Function _gallery_install_step_locations_switch().
439 function _gallery_install_step_locations_switch($form, &$form_state) {
440 variable_set('gallery_autodetect_dir', !variable_get('gallery_autodetect_dir', 1));
444 * Function _gallery_install_step_plugins().
445 * Step 3: Drupal Modules / Gallery2 Plugins
447 function _gallery_install_step_plugins(&$form, &$form_state, &$install_status) {
448 $title = t('Step 3: Drupal Modules / Gallery2 Plugins') .
($install_status['plugins']['status'] ?
' '.
t('(OK)') : '');
449 $form += _gallery_install_plugins($install_status, $title, ($install_status['step'] > GALLERY_INSTALL_STEP_PLUGINS
));
451 if ($install_status['step'] == GALLERY_INSTALL_STEP_PLUGINS
) {
452 if ($install_status['plugins']['status']) {
453 $install_status['step'] = GALLERY_INSTALL_STEP_URLREWRITE
;
454 $form['plugins']['#collapsed'] = TRUE
;
457 $form['plugins']['plugins_button_desc'] = array(
459 '#value' => t('There are errors in your plugin configuration. Enable/Disable the
460 respective plugins to meet the requirements.')
462 $form['plugins']['plugins_button'] = array(
464 '#value' => t('Check Plugins status again'),
465 '#submit' => array('_gallery_install_step_plugins_check')
472 * Function _gallery_install_step_plugins_check().
474 function _gallery_install_step_plugins_check($form, &$form_state) {
475 $install_status = $form_state['values']['install_status'];
476 _gallery_init(TRUE
, array(), FALSE
);
477 $form_state['storage'] = $install_status;
481 * Function _gallery_install_step_urlrewrite().
482 * Step 4: Clean URL configuration
484 function _gallery_install_step_urlrewrite(&$form, &$form_state, &$install_status) {
485 $title = t('Step 4: Clean URLs / URL Rewrite settings') .
($install_status['urlrewrite']['status'] ?
' '.
t('(OK)') : '');
486 $form['urlrewrite'] = array(
487 '#type' => 'fieldset',
489 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_URLREWRITE
),
490 '#collapsed' => $install_status['urlrewrite']['status']
493 // User selected to skip the URLRewrite step
494 if (variable_get('gallery_rewrite_disable', 0)) {
495 $form['urlrewrite']['#description'] = $install_status['urlrewrite']['info'];
496 $form['urlrewrite']['#description'] .
= ' '.
t('\'Reset & Restart\' your configuration to change these settings.');
500 $clean_urls_status = variable_get('clean_url', 0);
501 $rewrite_status = gallery_single_plugin_status('rewrite');
503 if ($clean_urls_status) {
504 if ($rewrite_status < GALLERY_PLUGIN_ENABLED
) {
505 $form['urlrewrite']['#description'] = t('Clean URLs are enabled in Drupal, but the Gallery2 URL Rewrite plugin is unavailable (!status).',
506 array('!status' => theme('gallery_plugin_status_message', $rewrite_status)));
507 $form['urlrewrite']['check'] = array(
509 '#value' => t('Check URL Rewrite status again'),
510 '#submit' => array('_gallery_install_step_urlrewrite_check')
514 // CleanURL and URLRewrite are both enabled
515 $form['urlrewrite']['#description'] = t('Clean URLs are !clean_url_status in Drupal and the Gallery2 URL Rewrite plugin is
516 !rewrite_status. It is possible to automatically configure the URL Rewrite plugin.
517 The configuration assumes that the rules should be placed in your Drupal .htaccess
518 file (it will add them to the beginning) which works in most applications. If you
519 need a special configuration, enter the desired values manually.',
521 '!clean_url_status' => theme('gallery_module_status_message', $clean_urls_status),
522 '!rewrite_status' => theme('gallery_plugin_status_message', $rewrite_status)
526 _gallery_install_urlrewrite($public_path, $htaccess_path, TRUE
);
527 $form['urlrewrite']['htaccess_public_path'] = array(
528 '#type' => 'textfield',
529 '#title' => t('Public path to your .htaccess file'),
532 '#default_value' => $public_path,
533 '#description' => t('This is the location of your Drupal .htaccess file relative to your webserver document root.'),
534 '#disabled' => $
$install_status['urlrewrite']['status'],
536 $form['urlrewrite']['htaccess_filesystem_path'] = array(
537 '#type' => 'textfield',
538 '#title' => t('Filesystem path to your .htaccess file'),
541 '#default_value' => $htaccess_path,
542 '#description' => t('This is the absolute directory path of your Drupal .htaccess file.'),
543 '#disabled' => $install_status['urlrewrite']['status'],
546 $form['urlrewrite']['config'] = array(
548 '#value' => t('Configure URL Rewrite plugin'),
549 '#submit' => array('_gallery_install_step_urlrewrite_configure')
554 $form['urlrewrite']['check'] = array(
556 '#value' => t('Check URL Rewrite status again'),
557 '#submit' => array('_gallery_install_step_urlrewrite_check')
561 $form['urlrewrite']['skip'] = array(
563 '#value' => t('Skip URL Rewrite Config'),
564 '#submit' => array('_gallery_install_step_urlrewrite_skip')
569 * Function _gallery_install_step_urlrewrite_check().
571 function _gallery_install_step_urlrewrite_check($form, &$form_state) {
572 $install_status = $form_state['values']['install_status'];
573 _gallery_init(TRUE
, array(), FALSE
);
574 $form_state['storage'] = $install_status;
578 * Function _gallery_install_step_urlrewrite_skip().
580 function _gallery_install_step_urlrewrite_skip($form, &$form_state) {
581 $install_status = $form_state['values']['install_status'];
583 variable_set('gallery_rewrite_disable', 1);
585 _gallery_init(TRUE
, array(), FALSE
);
586 _gallery_install_urlrewrite_check($install_status);
588 $install_status['step'] = GALLERY_INSTALL_STEP_USERSYNC
;
589 $form_state['storage'] = $install_status;
593 * Function _gallery_install_step_urlrewrite_configure().
595 function _gallery_install_step_urlrewrite_configure($form, &$form_state) {
596 $install_status = $form_state['values']['install_status'];
598 _gallery_init(TRUE
, array(), FALSE
);
599 _gallery_install_urlrewrite($form_state['values']['htaccess_public_path'], $form_state['values']['htaccess_filesystem_path']);
600 _gallery_install_urlrewrite_check($install_status);
602 if ($install_status['urlrewrite']['status']) {
603 $install_status['step'] = GALLERY_INSTALL_STEP_USERSYNC
;
605 $form_state['storage'] = $install_status;
609 * Function _gallery_install_step_usersync().
610 * Step 5: User Synchronization
612 function _gallery_install_step_usersync(&$form, &$form_state, &$install_status) {
613 $title = t('Step 5: Initial User Synchronization') .
($install_status['usersync']['status'] ?
' '.
t('(OK)') : '');
614 $form['usersync'] = array(
615 '#type' => 'fieldset',
617 '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_USERSYNC
),
618 '#collapsed' => $install_status['usersync']['status'],
621 if ($install_status['usersync']['status']) {
622 $form['usersync']['#description'] = t('Your initial user synchronization has been completed already.<br />
623 If you want to resync all your users or you want to import users from an existing
624 Gallery2 setup, you can always use the <a href= "@gallery-usersync">Advanced Sync
625 </a> options in the Gallery user administration.',
626 array('@gallery-usersync' => url('admin/user/gallery/advanced')));
629 $form['usersync']['#description'] = t('User synchronization is essential for the embedded Gallery to work correctly.
630 Drupal users/groups are usually synced with their Gallery counterparts when a
631 user/group is modified in Drupal. Missing user mappings will cause errors in your
632 embedded Gallery.<br /><br />
633 It is recommended that you sync your users now. However there can be reasons to
634 skip this step, e.g. if you have a working Gallery with many users and a fresh
635 Drupal installation. Note that the current user and the Drupal superuser (uid=1)
636 will always be sync.');
638 $form['usersync']['sync'] = array(
640 '#value' => t('Sync users/groups'),
641 '#submit' => array('_gallery_install_step_usersync_sync')
643 $form['usersync']['skip'] = array(
645 '#value' => t('Skip sync'),
646 '#submit' => array('_gallery_install_step_usersync_skip')
652 * Function _gallery_install_step_usersync_skip().
654 function _gallery_install_step_usersync_skip($form, &$form_state) {
655 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user.inc');
657 // Always sync (at least) the current user to avoid
658 // errors (unknown user) during GalleryEmbed::init()
659 gallery_user_modify($user, 'update', TRUE
, array());
660 // Make sure the Drupal superuser (uid=1) always gets admin right
661 if ($user->uid
!= 1) {
662 gallery_user_modify(user_load(array('uid' => 1)), 'update', FALSE
, array());
665 // Set the global status variable 'gallery_valid'
666 gallery_set_status(array(
667 'gallery_valid' => array(
668 'title' => t('Overall Status (Installation)'),
669 'severity' => GALLERY_SEVERITY_SUCCESS
,
672 variable_set('gallery_valid', TRUE
);
675 $form_state['redirect'] = 'admin/settings/gallery';
676 $form_state['storage'] = array();
680 * Function _gallery_install_step_usersync_sync().
682 function _gallery_install_step_usersync_sync($form, &$form_state) {
683 _gallery_install_step_usersync_skip($form, $form_state);
685 // Trigger bulk user/group sync
686 require_once(drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc');
688 'title' => t('Initial User Synchronization'),
689 'operations' => array(array('_gallery_user_advanced_sync', array())),
690 'file' => drupal_get_path('module', 'gallery') .
'/gallery_user_admin.inc',
691 'finished' => '_gallery_user_advanced_finished'
697 * Function _gallery_install_locations().
699 function _gallery_install_locations($orig, $autodetect = TRUE
) {
700 include_once(drupal_get_path('module', 'gallery') .
'/G2EmbedDiscoveryUtilities.class');
702 // Result status array
704 'gallery_uri' => array(
705 'title' => t('URI of Gallery2'),
706 'severity' => GALLERY_SEVERITY_ERROR
,
708 'gallery_dir' => array(
709 'title' => t('Location of Gallery2'),
710 'severity' => GALLERY_SEVERITY_ERROR
,
713 'title' => t('Gallery Init'),
714 'severity' => GALLERY_SEVERITY_ERROR
,
719 $vars['locations_valid'] = TRUE
;
721 // Strip the end /gallery if present and replace with index.php?q=gallery to avoid any
722 // url rewrite issues. See http://gallery.menalto.com/node/46181
723 // Note the use of index.php in all cases. Not needed for Apache, but for IIS
725 $embed_uri = isset($orig['gallery_embed_uri']) ?
$orig['gallery_embed_uri'] : '';
726 if ($autodetect || empty($embed_uri)) {
727 $embed_uri = url('gallery');
729 // i18n/locale rewrites the link to gallery to include a ?q=en or something
730 /*if (function_exists('language_url_rewrite')) {
731 $embed_uri = trim(substr($embed_uri, strlen($prefix)), '/');
733 if (substr($embed_uri, -8) == '/gallery') {
734 $embed_uri = substr($embed_uri, 0, -7) .
'index.php?q=gallery';
738 // Normalise the Embed Application URI
739 $embed_uri = G2EmbedDiscoveryUtilities
::normalizeEmbedUri($embed_uri);
740 $vars['gallery_embed_uri'] = $embed_uri;
742 // Normalise the G2 URI
743 $g2_uri = G2EmbedDiscoveryUtilities
::normalizeG2Uri($orig['gallery_uri']);
744 $vars['gallery_uri'] = $g2_uri;
746 // Find the Gallery Directory and Embed URI
748 // Auto-Detect the G2 embed path
749 list($success, $embed_php_path, $error_string) = G2EmbedDiscoveryUtilities
::getG2EmbedPathByG2Uri($g2_uri);
751 // G2 Embed Path is found OK
752 $vars['gallery_dir'] = rtrim($embed_php_path, 'embed.php');
755 // Something is wrong with the G2 URI given as the G2 embed path is not found
756 // Try getG2EmbedPathByG2UriEmbedUriAndLocation instead
757 $drupal_path = realpath(".") .
'/';
758 list($success, $embed_php_path, $error_string) =
759 G2EmbedDiscoveryUtilities
::getG2EmbedPathByG2UriEmbedUriAndLocation($g2_uri, $embed_uri, $drupal_path);
761 // G2 Embed Path is found OK
762 $vars['gallery_dir'] = rtrim($embed_php_path, 'embed.php');
765 $result['gallery_uri']['info'] = $error_string;
766 $result['gallery_uri']['status'] = FALSE
;
767 $vars['gallery_dir'] = '';
768 $vars['locations_valid'] = FALSE
;
771 // Check for config.php in the embed_path (not existing => invalid path)
772 // e.g. this is the path to the G2 codebase, but we have a multisite configuration
773 if (!empty($vars['gallery_dir'])) {
774 list($ok, $error_string) = G2EmbedDiscoveryUtilities
::isFileReadable($vars['gallery_dir'] .
'config.php');
776 $result['gallery_dir']['status'] = FALSE
;
777 $result['gallery_dir']['info'] = $error_string;
778 $vars['gallery_dir'] = '';
779 $vars['locations_valid'] = FALSE
;
784 // Do not autodetect the variables, but check the manually entered ones.
785 $embed_php_path = $orig['gallery_dir'];
786 $embed_php_path .
= (substr($embed_php_path, -1) != '/') ?
'/' : '';
787 // Check path can be read, adding embed.php if needed
788 list($ok, $error_string) = G2EmbedDiscoveryUtilities
::isFileReadable($embed_php_path .
'embed.php');
789 $vars['gallery_dir'] = $embed_php_path;
791 $result['gallery_dir']['status'] = FALSE
;
792 $result['gallery_dir']['info'] = $error_string;
793 $vars['locations_valid'] = FALSE
;
796 // Check for config.php in the embed_path (not existing => invalid path)
797 // e.g. this is the path to the G2 codebase, but we have a multisite configuration
798 list($ok, $error_string) = G2EmbedDiscoveryUtilities
::isFileReadable($embed_php_path .
'config.php');
800 $result['gallery_dir']['status'] = FALSE
;
801 $result['gallery_dir']['info'] = $error_string;
802 $vars['locations_valid'] = FALSE
;
807 // If the filepaths seem correct then check Gallery2 works and has the correct module configs
808 if ($vars['locations_valid']) {
809 // Gallery install is thought valid, so init it.
810 if (!_gallery_init(TRUE
, $vars, FALSE
)) {
811 // Gallery install was supposed to be valid, but it still failed. Something is wrong.
812 $result['gallery_init']['status'] = FALSE
;
813 $result['gallery_init']['info'] = t('Everything seemed OK, but the Gallery could still not be initialised.
814 Perhaps a manually entered value is incorrect.');
815 $vars['locations_valid'] = FALSE
;
819 GalleryEmbed
::done();
823 // Only return items where status has been set
824 foreach ($result as
$key => $value) {
825 if (!isset($value['status'])) {
826 unset($result[$key]);
830 return array($vars['locations_valid'], $vars, $result);
834 * Function _gallery_install_plugins().
836 function _gallery_install_plugins(&$install_status, $title = NULL
, $collapse = FALSE
) {
837 $form['plugins'] = array(
838 '#type' => 'fieldset',
839 '#title' => isset($title) ?
$title : t('Drupal Modules / Gallery2 Plugins'),
840 '#collapsible' => TRUE
,
841 '#collapsed' => $collapse,
844 $header = array(t('Name'), t('Status'), t('Description'));
845 $overall_plugin_severity = GALLERY_SEVERITY_UNKNOWN
- 1;
846 $overall_plugin_status = GALLERY_PLUGIN_ENABLED
;
848 // Wanted (required) G2 plugins
850 $wanted_g2_plugins = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_WANTED
);
851 foreach ($wanted_g2_plugins as
$key => $module) {
852 // Find the combination of status and severity of the plugin
853 $severity = ($module['status'] != GALLERY_PLUGIN_ENABLED
) ?
$module['severity'] : GALLERY_SEVERITY_SUCCESS
;
855 $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%');
856 $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status']), 'align' => 'center');
857 $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => $key);
859 if ($module['status'] != GALLERY_PLUGIN_ENABLED
&& $severity > $overall_plugin_severity) {
860 $overall_plugin_severity = $severity;
861 $overall_plugin_status = $module['status'];
864 $form['plugins']['wanted_g2_plugins'] = array(
865 '#type' => 'fieldset',
866 '#title' => t('Recommended Gallery2 plugins'),
867 '#collapsible' => FALSE
,
868 '#collapsed' => FALSE
,
869 '#value' => theme('table', $header, $rows, array('class' => 'package')),
870 '#description' => t('These Gallery2 plugins support much of the functionality that the Drupal Gallery module provides.
871 None of them are strictly required, but you will almost certainly want to activate at least some
872 of them (particularly the Image Block plugin).'),
875 // Unwanted (interfering) G2 plugins
877 $unwanted_g2_plugins = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_UNWANTED
);
878 foreach ($unwanted_g2_plugins as
$key => $module) {
879 // Find the combination of status and severity of the plugin
880 $severity = ($module['status'] == GALLERY_PLUGIN_ENABLED
) ?
$module['severity'] : GALLERY_SEVERITY_SUCCESS
;
882 $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%');
883 $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status'], TRUE
, TRUE
), 'align' => 'center');
884 $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => $key);
886 if ($module['status'] == GALLERY_PLUGIN_ENABLED
&& $severity > $overall_plugin_severity) {
887 $overall_plugin_severity = $severity;
888 $overall_plugin_status = $module['status'];
891 $form['plugins']['unwanted_g2_plugins'] = array(
892 '#type' => 'fieldset',
893 '#title' => t('Gallery2 plugins which should not be installed'),
894 '#collapsible' => FALSE
,
895 '#collapsed' => FALSE
,
896 '#value' => theme('table', $header, $rows, array('class' => 'package')),
897 '#description' => t('These Gallery2 plugins should not be used when Gallery2 is
898 embedded into Drupal as they may cause problems.'),
901 // Wanted (optional) Drupal modules
903 $wanted_modules = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_DRUPAL
);
904 foreach ($wanted_modules as
$key => $module) {
905 // Find the combination of status and severity of the plugin
906 $severity = $module['status'] ? GALLERY_SEVERITY_SUCCESS
: $module['severity'];
908 $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%');
909 $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status']), 'align' => 'center');
910 $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => $key);
912 if ($module['status'] != GALLERY_PLUGIN_ENABLED
&& $severity > $overall_plugin_severity) {
913 $overall_plugin_severity = $severity;
914 $overall_plugin_status = $module['status'];
917 $form['plugins']['wanted_modules'] = array(
918 '#type' => 'fieldset',
919 '#title' => t('Optional Drupal modules'),
920 '#collapsible' => FALSE
,
921 '#collapsed' => FALSE
,
922 '#value' => theme('table', $header, $rows, array('class' => 'package')),
923 '#description' => t('These Drupal modules can optionally be used to enhance the functionality of the Gallery module.'),
926 // Check if no issue was found.
927 if ($overall_plugin_severity < GALLERY_SEVERITY_UNKNOWN
) {
928 $overall_plugin_severity = GALLERY_SEVERITY_SUCCESS
;
931 $install_status['plugins']['status'] = $overall_plugin_status;
932 $install_status['plugins']['severity'] = $overall_plugin_severity;
933 $install_status['plugins']['info'] = ($overall_plugin_status <= 0) ?
934 t('You may have some loss in functionality in your embedded Gallery2 (see below for details). You should check
935 the details and if the functionality is not important for your site you can just ignore this.') :
936 t('The status of all Drupal modules and Gallery2 plugins is optimal for your embedded Gallery2.');
942 * Function _gallery_install_urlrewrite_check().
944 function _gallery_install_urlrewrite_check(&$install_status) {
945 if (variable_get('clean_url', 0)) {
946 if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED
) {
947 _gallery_install_urlrewrite($public_path, $htaccess_path, TRUE
);
948 // Check for writable .htaccess file
949 if (file_exists($htaccess_path .
'.htaccess')) {
950 if (is_writable($htaccess_path .
'.htaccess')) {
951 $install_status['urlrewrite']['status'] = TRUE
;
952 $install_status['urlrewrite']['info'] = t('There is a writable .htaccess file in your defined Drupal directory
953 (@dir).', array('@dir' => $htaccess_path));
956 $install_status['urlrewrite']['status'] = FALSE
;
957 $install_status['urlrewrite']['info'] = t('The .htaccess file in your defined Drupal directory (@dir) is not
958 writable. Please CHMOD it to 644 (or 666 if 644 does not work).',
959 array('@dir' => $htaccess_path));
963 $install_status['urlrewrite']['status'] = FALSE
;
964 $install_status['urlrewrite']['info'] = t('There is no .htaccess file in your defined Drupal directory (@dir) or
965 the directory does not exist.', array('@dir' => $htaccess_path));
969 $install_status['urlrewrite']['status'] = FALSE
;
970 $install_status['urlrewrite']['info'] = t('Clean URLs are enabled in Drupal, but the Gallery2 URL Rewrite plugin
975 $install_status['urlrewrite']['status'] = TRUE
;
976 $install_status['urlrewrite']['info'] = t('Clean URLs are disabled in Drupal and the URL Rewrite plugin will not
980 // User selected to skip the URLRewrite step
981 if (variable_get('gallery_rewrite_disable', 0)) {
982 $install_status['urlrewrite']['status'] = TRUE
;
983 $install_status['urlrewrite']['info'] = t('URL Rewrite has been disabled manually.');
988 * Function _gallery_install_urlrewrite().
990 function _gallery_install_urlrewrite(&$public_path, &$htaccess_path, $load_config = FALSE
) {
991 list($ret, $rewrite_api) = GalleryCoreApi
::newFactoryInstance('RewriteApi');
992 if ($ret || !$rewrite_api) {
993 gallery_error(t('Error trying to create URL Rewrite plugin instance.'), $ret);
997 list($ret, $params) = $rewrite_api->fetchEmbedConfig();
999 gallery_error(t('Error trying to fetch Embedded URL Rewrite configuration.'), $ret);
1003 // Load the configuration from G2 (or derive from Drupal path)
1005 if (empty($params['embeddedHtaccess'])) {
1006 $http = 'http'.
(isset($_SERVER['HTTPS']) ?
(($_SERVER['HTTPS'] == 'on') ?
's' : '') : '');
1007 $public_path = str_replace($http .
'://'.
$_SERVER['HTTP_HOST'], '', base_path());
1008 $htaccess_path = realpath(".") .
'/';
1011 $public_path = $params['embeddedLocation'];
1012 $htaccess_path = $params['embeddedHtaccess'];
1016 // Check for trailing slash
1017 $public_path .
= (substr($public_path, -1) != '/') ?
'/' : '';
1018 $htaccess_path .
= (substr($htaccess_path, -1) != '/') ?
'/' : '';
1020 if (!$load_config) {
1021 if (!file_exists($htaccess_path .
'.htaccess')) {
1022 // File .htaccess does not exist
1023 if (is_writable($htaccess_path .
'.htaccess')) {
1024 // Directory exists and is writable => try to create .htaccess
1025 $f = fopen($htaccess_path .
'.htaccess', 'w');
1031 // Save the G2 rewrite values
1032 $params['embeddedLocation'] = $public_path;
1033 $params['embeddedHtaccess'] = $htaccess_path;
1034 list($ret, $code, $err) = $rewriteApi->saveEmbedConfig($params);
1035 if ($code != REWRITE_STATUS_OK
) {
1036 list($ret, $errstr) = $err;
1037 $errstr = $code .
' - '.
$errstr;
1038 gallery_error(t('The Gallery2 URL Rewrite plugin returned the following error:') .
'<br /><pre>'.
$errstr .
'</pre>');