= 0) { $out .= t('GMT +') . $loc[INDEX_GMT] .', '; } else { $out .= t('GMT ') . $loc[INDEX_GMT] .', '; } if ($loc[INDEX_DST] == 0) { $out .= t('No DST '); } else { $out .= t('DST '); // now add DST start and end information $out .= t(' from !stime:00AM on !snth !sdow in !smonth', array('!stime' => $loc[INDEX_STIME], '!snth' => $nth_array[$loc[INDEX_SNTH]], '!sdow' => $dow_array[$loc[INDEX_SDOW]], '!smonth' => $mon_array[$loc[INDEX_SMON]])); $out .= t(' to !etime:00AM on !enth !edow in !emonth', array('!etime' => $loc[INDEX_ETIME], '!enth' => $nth_array[$loc[INDEX_ENTH]], '!edow' => $dow_array[$loc[INDEX_EDOW]], '!emonth' => $mon_array[$loc[INDEX_EMON]])); } return $out; } /** * Help message for the module * * in: $section - which section of the site we are displaying help * return: help text for the section */ /* ---- for Drupal 5.x ---- function worldclock_help($section='') { $output = ''; switch($section) { case "admin/help#worldclock": $output = '

'. t("Displays a world clock") .'

'; break; } return $output; } */ /* ---- for Drupal 6.x ---- */ function worldclock_help($path, $arg) { $output = ''; switch ($path) { case "admin/help#worldclock": $output = '

'. t("Displays a world clock") .'

'; break; } return $output; } /** * Generate HTML for worldclock block * * in: $op is the operation from the URL * in: $delta - offset * return: block HTML code */ function worldclock_block($op='list', $delta=0) { if ($op == 'list') { $block[0]['info'] = t('World Clock'); return $block; } else if ($op == 'view') { $block['subject'] = t('World Clock'); $wc_location = variable_get('wc_location', array()); // get option $maxnum = variable_get('worldclock_maxnum', 4); $footnote = variable_get('worldclock_footnote', ''); $showzebra = variable_get('worldclock_showzebra', 0); $format = variable_get('worldclock_format', 'm/d h:i A'); $timestr = variable_get('worldclock_timestr', 'm/d h:i A'); $showdst = variable_get('worldclock_showdst', 0); $dststr = variable_get('worldclock_dststr', '*'); // output block content $output = theme('clocks_list', $wc_location, $maxnum, $showzebra, $footnote); // output javascript $output .= ''; $block['content'] = $output; return $block; } // end of $op == 'view' } /** * Theme hook */ function worldclock_theme() { return array( 'clocks_list' => array( 'arguments' => array('wc_location' => NULL, 'maxnum' => NULL, 'showzebra' => NULL, 'footnote' => NULL), ), ); } /** * Theming function for block */ function theme_clocks_list($wc_location, $maxnum, $showzebra, $footnote) { $output = ''; // output table HTML $tr_class = ''; $output .= ''; for ($j = 1 ; $j <= $maxnum ; $j++) { if ($showzebra) { if ($j % 2) $tr_class = 'odd'; else $tr_class = 'even'; } $loc_no = variable_get('worldclock_location_'. $j, 0); if ($loc_no > 0) { // get location name $loc = $wc_location[$loc_no]; $loc_name = $loc[INDEX_NAME]; $output .= ''; $output .= ''; $output .= ''; $output .= ''; } } $output .= '
'. $loc_name .''; $output .= '
'; if ($footnote) { $output .= ''. $footnote .''; } return $output; } /** * Module settings (admin page) */ function worldclock_admin() { $wc_location = variable_get('wc_location', array()); $maxnum = variable_get('worldclock_maxnum', 4); $format = variable_get('worldclock_format', 'm/d h:i A'); $timestr = variable_get('worldclock_timestr', 'm/d h:i A'); $form['location'] = array( '#type' => 'fieldset', '#title' => t('Location settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['location']['worldclock_maxnum'] = array( '#type' => 'select', '#title' => t('Maximum number of locations'), '#default_value' => $maxnum, '#options' => array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8'), ); $form['location']['worldclock_note'] = array( '#type' => 'markup', '#value' => t('You may leave the location unselected if you do not need to display the time.'), ); for ($j = 1 ; $j <= $maxnum ; $j++) { // show some information $loc_no = variable_get('worldclock_location_'. $j, 0); $loc_info = ''; if ($loc_no) { $loc = $wc_location[$loc_no]; $loc_info = get_location_info($loc); } // create a pull-down menu $form['location']['worldclock_location_'. $j] = array( '#type' => 'select', '#title' => t('Location ') . $j, '#default_value' => variable_get('worldclock_location_'. $j, 0), '#options' => get_location_options(), '#description' => $loc_info, ); } $format_desc = t('Specify the custom time string format. You can use the following format characters.'); $format_desc .= ''; $format_desc .= t('Any non alphanumeric characters including space character are just copied to the output.') .'
'; $form['display'] = array( '#type' => 'fieldset', '#title' => t('Display settings'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['display']['worldclock_format'] = array( '#type' => 'select', '#title' => t('Display format'), '#options' => array( 'm/d h:i A' => t('04/07 01:23 PM'), 'm/d h:i a' => t('04/07 01:23 pm'), 'm/d h:i:s A' => t('04/07 01:23:45 PM'), 'm/d h:i:s a' => t('04/07 01:23:45 pm'), 'm/d H:i' => t('04/07 13:23'), 'm/d H:i:s' => t('04/07 13:23:45'), 'M d h:i A' => t('Apr 07 01:23 PM'), 'M d h:i a' => t('Apr 07 01:23 pm'), 'M d h:i:s A' => t('Apr 07 01:23:45 PM'), 'M d h:i:s a' => t('Apr 07 01:23:45 pm'), 'M d H:i' => t('Apr 07 13:23'), 'M d H:i:s' => t('Apr 07 13:23:45'), 'd/m h:i A' => t('07/04 01:23 PM'), 'd/m h:i a' => t('07/04 01:23 pm'), 'd/m h:i:s A' => t('07/04 01:23:45 PM'), 'd/m h:i:s a' => t('07/04 01:23:45 pm'), 'd/m H:i' => t('07/04 13:23'), 'd/m H:i:s' => t('07/04 13:23:45'), 'd M h:i A' => t('07 Apr 01:23 PM'), 'd M h:i a' => t('07 Apr 01:23 pm'), 'd M h:i:s A' => t('07 Apr 01:23:45 PM'), 'd M h:i:s a' => t('07 Apr 01:23:45 pm'), 'd M H:i' => t('07 Apr 13:23'), 'd M H:i:s' => t('07 Apr 13:23:45'), 'custom' => t('Custom format'), ), '#description' => t('Date/time used for the menu item is not a current time, but an example..'), '#default_value' => $format, '#attributes' => array('onchange' => 'ChangeFormat(this)'), ); if ($format == 'custom') { $timestr_style = 'visibility: visible; overflow: hidden;'; } else { $timestr_style = 'visibility: hidden; height: 0px; overflow: hidden;'; } $timestr_example = date($timestr); $form['display']['worldclock_timestr'] = array( '#type' => 'textfield', '#title' => t('Custom format string'), '#size' => 20, '#maxlength' => 20, '#field_suffix' => t(' Example: !str1', array('!str1' => date($timestr))), '#default_value' => $timestr, '#description' => $format_desc, '#prefix' => '
', '#suffix' => '
', ); $form['display']['worldclock_showdst'] = array( '#type' => 'checkbox', '#default_value' => variable_get('worldclock_showdst', 0), '#title' => t('Display DST (Daylight Saving Time)'), '#description' => t('If checked, DST marker is displayed after the time when the location is under the DST.'), ); $form['display']['worldclock_dststr'] = array( '#type' => 'textfield', '#title' => t('DST marker'), '#size' => 10, '#maxlength' => 10, '#default_value' => variable_get('worldclock_dststr', '*'), '#description' => t('Specify the DST marker (Symbol, character or a short text). HTML tags are allowed.'), ); $form['display']['worldclock_footnote'] = array( '#type' => 'textfield', '#title' => t('Footnote'), '#size' => 60, '#maxlength' => 60, '#default_value' => variable_get('worldclock_footnote', ''), '#description' => t('Footnote, if any (for example, an explanation about DST marker). HTML tags are allowed.'), ); $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['advanced']['worldclock_showzebra'] = array( '#type' => 'checkbox', '#default_value' => variable_get('worldclock_showzebra', 0), '#title' => t('Add even and odd class to <tr> tag.'), '#description' => t('If checked, odd and even class is added to the <tr> tag of each table row.'), ); return system_settings_form($form); } /** * Menu hook */ /* ---- for Drupal 5.x ---- function worldclock_menu($may_cache) { $items = array(); if(!$may_cache) { // These lines are moved from hook_init() to here because // drupal_get_path() fails when the site cache is enabled. // hook_init() is called when drupal_get_path() has not been // loaded yet when the site cache is enabled. // (only for Drupal 5.x) // drupal_add_js(drupal_get_path('module', 'worldclock') . '/worldclock.js'); register_location_array(); } else { $items[] = array( 'path' => 'admin/settings/worldclock', 'title' => t('World Clock'), 'description' => t('Displays a world clock.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'worldclock_admin', 'access' => user_access('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } */ /* ---- for Drupal 6.x ---- */ function worldclock_menu() { $items = array(); $items['admin/settings/worldclock'] = array( 'title' => 'World Clock', 'description' => 'Displays a world clock.', 'page callback' => 'drupal_get_form', 'page arguments' => array('worldclock_admin'), 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Implementation of hook_init */ function worldclock_init() { /* ---- for Drupal 6.x only ---- */ drupal_add_js(drupal_get_path('module', 'worldclock') . '/worldclock.js'); register_location_array(); }