diff --git kiosk.module kiosk.module index 7c8a150..057cc32 100755 --- kiosk.module +++ kiosk.module @@ -5,7 +5,7 @@ * Implementation of hook_boot(). */ function kiosk_init() { - + if (kiosk_is_kiosk()) { // We need a separate page cache table for the kiosk mode, so we play // games with the database prefix. @@ -20,17 +20,18 @@ function kiosk_init() { } } + /** * Implementation of hook_cron(). */ function kiosk_cron() { - // Because we can't hook into the cache clearing process in Drupal 5, we have + // Because we can't hook into the cache clearing process in Drupal, we have // to clear the kiosk page cache on our own periodically. This may introduce // a delay before a site change appears on kiosk computers, but in D5 there - // is no better alternative. + // was no better alternative. + + // TODO: find a way to hook into the Drupal cache clearing process instead of cron - // TODO: find a way to hook into the Drupal 6 cache clearing process instaed of cron - cache_clear_all('*', 'kiosk_cache_page', TRUE); } @@ -46,79 +47,99 @@ function kiosk_perm() { */ function kiosk_menu() { $items = array(); - + $items['admin/settings/kiosk'] = array( 'title' => 'Kiosk mode', - 'description' => 'Configure what clients will be considered "kisok mode".', + 'description' => 'Configure what clients will be considered "kiosk mode".', 'page callback' => 'drupal_get_form', 'page arguments' => array('kiosk_configure'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('administer kiosk settings'), ); - $items[] = array( + $items['admin/settings/kiosk/ip'] = array( 'title' => 'By IP', - 'path' => 'admin/settings/kiosk/ip', 'type' => MENU_DEFAULT_LOCAL_TASK, 'access arguments' => array('administer kiosk settings'), ); $items['admin/settings/kiosk/cookie'] = array( - 'title' => 'Set computer', - 'description' => 'Set a cookie on the current computer to force it into kiosk mode, regardless of IP address.', + 'title' => 'By Cookie', + 'description' => 'Set a cookie on the current browser to force it into kiosk mode, regardless of IP address.', 'page callback' => 'drupal_get_form', 'page arguments' => array('kiosk_configure_cookie'), 'type' => MENU_LOCAL_TASK, 'access arguments' => array('administer kiosk settings'), ); - + return $items; } /** - * Form builder; Configure kiosk computers by cookie. - * - * @ingroup forms + * Form builder; Configure kiosk browsers by cookie. + * * @see kiosk_configure_cookie_submit(). */ function kiosk_configure_cookie() { $form = array(); - + $form['description'] = array( '#type' => 'item', - '#value' => t('To set the computer you are currently using to kiosk mode using a cookie, click the button below. The system will remain flagged for kiosk mode for one year or until cookies are cleared.'), ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Set this computer to kiosk mode.'), - - ); - + if (kiosk_is_kiosk()) { + $form['description']['#value'] = t('This browser is currently in kiosk mode. You may exit kiosk mode using the button below.'); + } + else { + $form['description']['#value'] = t('To set this browser to kiosk mode using a cookie, click the button below. The browser will remain in kiosk mode until January, 2038 or until you return to this page and exit kiosk mode or until cookies are cleared.'); + } + + if (kiosk_is_kiosk()) { + $form['reset'] = array( + '#type' => 'submit', + '#value' => t('Exit kiosk mode'), + '#submit' => array('kiosk_configure_cookie_reset',), + ); + } + else { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Set this browser to kiosk mode permanently (until cookies are reset).'), + ); + } + return $form; } +/** + * Set a cookie valid until near the end of php time values. + */ function kiosk_configure_cookie_submit($form, &$form_state) { - - setcookie('drupal_kiosk_mode', 1, $expire, '/'); - drupal_set_message(t('This computer has been set to kiosk mode. Clear your cookies in order to reset it.')); - + setcookie('drupal_kiosk_mode', 1, strtotime('2038-01-01'), '/'); + drupal_set_message(t('This browser has been set to kiosk mode. Clear your cookies or return to this page in order to reset it.')); } +/** + * Delete the cookie by setting to a past time. + */ +function kiosk_configure_cookie_reset($form, &$form_state) { + setcookie('drupal_kiosk_mode', 1, time() - 3600, '/'); + drupal_set_message(t('This browser is no longer in kiosk mode')); +} /** * Form builder; Configure kiosk computers by IP address. - * + * * @ingroup forms * @see system_settings_form(). */ function kiosk_configure() { $form = array(); - + $form['kiosk_ip_addresses'] = array( '#type' => 'textarea', '#title' => t('Kiosk IP Addresses'), '#description' => t('Specify IP addresses here that should be always be flagged for "kiosk mode". Separate each IP address with a line break or comma. Note that this is the IP address that Drupal sees; it will be affected by firewalls, NAT routers, proxies, etc.'), '#default_value' => variable_get('kiosk_ip_addresses', ''), ); - + return system_settings_form($form); } @@ -128,10 +149,10 @@ function kiosk_configure() { * @return TRUE or FALSE */ function kiosk_is_kiosk() { - + $ip_addresses = kiosk_parse_list_values(variable_get('kiosk_ip_addresses', '')); - - return (in_array(ip_address(), $ip_addresses) || 1 == $_COOKIE['drupal_kiosk_mode']); + + return (in_array(ip_address(), $ip_addresses) || ($_COOKIE['drupal_kiosk_mode'] == 1)); } /**