Index: worldclock.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/worldclock/worldclock.module,v
retrieving revision 1.1.4.2
diff -u -p -r1.1.4.2 worldclock.module
--- worldclock.module	27 Apr 2008 04:03:51 -0000	1.1.4.2
+++ worldclock.module	3 May 2008 11:17:20 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: 
+// $Id$
 
 /**
  * @file
@@ -27,8 +27,7 @@ define("INDEX_ETIME", 10);
  * Register location array using variable_set().
  * This function is called from worldclock_init().
  */
-function register_location_array()
-{
+function register_location_array() {
   // Note: wc_location array
   //
   //    Name      Country or area name
@@ -163,15 +162,14 @@ function register_location_array()
 /**
  * Construct an array for location pulldown menu
  */
-function get_location_options()
-{
+function get_location_options() {
   // add this array to $GLOBALS so that other functions can access it
 
   $loc_array = array();
   $wc_location = variable_get('wc_location', array());
 
   $numitems = count($wc_location);
-  for($i = 0 ; $i < $numitems ; $i++) {
+  for ($i = 0 ; $i < $numitems ; $i++) {
     $loc = $wc_location[$i];
     $loc_name = $loc[INDEX_NAME];
     $loc_array[] = $loc_name;
@@ -182,10 +180,9 @@ function get_location_options()
 /**
  * Construct location information text string
  */
-function get_location_info($loc)
-{
+function get_location_info($loc) {
   // in: $loc - location record array
-  $nth_array = array('', t('1st '), t('2nd '), t('3rd '), t('4th '), 
+  $nth_array = array('', t('1st '), t('2nd '), t('3rd '), t('4th '),
                      '', '', '', '', t('last '));
   $dow_array = array(t('Sunday'), t('Monday'), t('Tuesday'), t('Wednesday'),
                      t('Thursday'), t('Friday'), t('Saturday'));
@@ -193,13 +190,13 @@ function get_location_info($loc)
                      t('May'), t('June'), t('July'), t('August'),
                      t('September'), t('October'), t('November'), t('December'));
   $out = '';
-  if($loc[INDEX_GMT] >= 0) {
-    $out .= t('GMT +') . $loc[INDEX_GMT] . ', ';
+  if ($loc[INDEX_GMT] >= 0) {
+    $out .= t('GMT +') . $loc[INDEX_GMT] .', ';
   }
   else {
-    $out .= t('GMT ') . $loc[INDEX_GMT] . ', ';
+    $out .= t('GMT ') . $loc[INDEX_GMT] .', ';
   }
-  if($loc[INDEX_DST] == 0) {
+  if ($loc[INDEX_DST] == 0) {
     $out .= t('No DST ');
   }
   else {
@@ -225,24 +222,24 @@ function get_location_info($loc)
  * in: $section - which section of the site we are displaying help
  * return: help text for the section
  */
-/*---- for Drupal 5.x ----
+/* ---- for Drupal 5.x ----
 function worldclock_help($section='') {
   $output = '';
   switch($section) {
     case "admin/help#worldclock":
-      $output = '<p>' . t("Displays a world clock") . '</p>';
+      $output = '<p>'. t("Displays a world clock") .'</p>';
       break;
   }
   return $output;
 }
-*/
+ */
 
-/*---- for Drupal 6.x ----*/
+/* ---- for Drupal 6.x ---- */
 function worldclock_help($path, $arg) {
   $output = '';
-  switch($path) {
+  switch ($path) {
     case "admin/help#worldclock":
-      $output = '<p>' . t("Displays a world clock") . '</p>';
+      $output = '<p>'. t("Displays a world clock") .'</p>';
       break;
   }
   return $output;
@@ -257,92 +254,69 @@ function worldclock_help($path, $arg) {
  */
 function worldclock_block($op='list', $delta=0) {
 
-  if($op == 'list') {
+  if ($op == 'list') {
     $block[0]['info'] = t('World Clock');
     return $block;
   }
-  else if($op == 'view') {
+  else if ($op == 'view') {
     $block['subject'] = t('World Clock');
-    $block['content'] = '';
-    $out = '';
+            
     $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', '*');
-    $footnote  = variable_get('worldclock_footnote', '');
-    $showzebra = variable_get('worldclock_showzebra', 0);
-
-    // output table HTML 
-    $tr_class = '';
-    $out .= '<table id="wordclock">';
-    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];
-        $out .= '<tr class="' . $tr_class . '">';
-        $out .= '<td id="worldclock_location">' . $loc_name  . '</td>';
-        $out .= '<td id="worldclock_time">';
-        $out .= '<span id="worldclock' . $j . '"></span></td>';
-        $out .= '</tr>';
-      }
-    }
-    $out .= '</table>';
-  if($footnote) {
-    $out .= '<span id="worldclock_footnote">' . $footnote . '</span>';
-  }
-
+    
+    // output block content
+    $output = theme('clocks_list', $wc_location, $maxnum, $showzebra, $footnote);
+    
     // output javascript
-    $out .= '<script language="javascript">';
-    $out .= 'var locations = new Array();';
-    $out .= 'var sdow;';
-    $out .= 'var smon;';
-    $out .= 'var maxnum;';
-  $out .= 'var time_str;';
-    $out .= 'var show_dst;';
-  $out .= 'var dst_str;';
-    $out .= 'maxnum  = ' . $maxnum . ';';
-    if($format == 'custom') {
-      $out .= 'time_str = "' . $timestr . '";';
+    $output .= '<script language="javascript">';
+    $output .= 'var locations = new Array();';
+    $output .= 'var sdow;';
+    $output .= 'var smon;';
+    $output .= 'var maxnum;';
+    $output .= 'var time_str;';
+    $output .= 'var show_dst;';
+    $output .= 'var dst_str;';
+    $output .= 'maxnum  = '. $maxnum .';';
+    if ($format == 'custom') {
+      $output .= 'time_str = "'. $timestr .'";';
     }
     else {
-      $out .= 'time_str = "' . $format . '";';
+      $output .= 'time_str = "'. $format .'";';
     }
-    $out .= 'show_dst = ' . $showdst . ';';
-    $out .= 'dst_str  = "' . $dststr . '";';
-  $out .= "sdow = new Array('" .
-      t('Sun') . "', '" .
-      t('Mon') . "', '" .
-      t('Tue') . "', '" .
-      t('Wed') . "', '" .
-      t('Thu') . "', '" .
-      t('Fri') . "', '" .
-      t('Sat') . "');";
-  $out .= "smon = new Array('" .
-      t('Jan') . "', '" .
-      t('Feb') . "', '" .
-      t('Mar') . "', '" .
-      t('Apr') . "', '" .
-      t('May') . "', '" .
-      t('Jun') . "', '" .
-      t('Jul') . "', '" .
-      t('Aug') . "', '" .
-      t('Sep') . "', '" .
-      t('Oct') . "', '" .
-      t('Nov') . "', '" .
-      t('Dec') . "');";
+    $output .= 'show_dst = '. $showdst .';';
+    $output .= 'dst_str  = "'. $dststr .'";';
+    $output .= "sdow = new Array('" .
+      t('Sun') ."', '" .
+      t('Mon') ."', '" .
+      t('Tue') ."', '" .
+      t('Wed') ."', '" .
+      t('Thu') ."', '" .
+      t('Fri') ."', '" .
+      t('Sat') ."');";
+    $output .= "smon = new Array('" .
+      t('Jan') ."', '" .
+      t('Feb') ."', '" .
+      t('Mar') ."', '" .
+      t('Apr') ."', '" .
+      t('May') ."', '" .
+      t('Jun') ."', '" .
+      t('Jul') ."', '" .
+      t('Aug') ."', '" .
+      t('Sep') ."', '" .
+      t('Oct') ."', '" .
+      t('Nov') ."', '" .
+      t('Dec') ."');";
 
-    for($j = 1 ; $j <= $maxnum ; $j++) {
-      $loc_no = variable_get('worldclock_location_' . $j, 0);
+    for ($j = 1 ; $j <= $maxnum ; $j++) {
+      $loc_no = variable_get('worldclock_location_'. $j, 0);
       // get the location record
       $loc = $wc_location[$loc_no];
       $loc_name  = $loc[INDEX_NAME];
@@ -356,29 +330,74 @@ function worldclock_block($op='list', $d
       $loc_enth  = $loc[INDEX_ENTH];
       $loc_edow  = $loc[INDEX_EDOW];
       $loc_etime = $loc[INDEX_ETIME];
-      $out .= "locations[" . $j . "] = new Array('" .
-        $loc_no    . "', '" . 
-        $loc_name  . "', '" . 
-        $loc_diff  . "', '" .
-        $loc_dst   . "', '" .
-        $loc_smon  . "', '" .
-        $loc_snth  . "', '" .
-        $loc_sdow  . "', '" .
-        $loc_stime . "', '" .
-        $loc_emon  . "', '" .
-        $loc_enth  . "', '" .
-        $loc_edow  . "', '" .
-        $loc_etime . "');";
+      $output .= "locations[" . $j ."] = new Array('" .
+        $loc_no    ."', '" .
+        $loc_name  ."', '" .
+        $loc_diff  ."', '" .
+        $loc_dst   ."', '" .
+        $loc_smon  ."', '" .
+        $loc_snth  ."', '" .
+        $loc_sdow  ."', '" .
+        $loc_stime ."', '" .
+        $loc_emon  ."', '" .
+        $loc_enth  ."', '" .
+        $loc_edow  ."', '" .
+        $loc_etime ."');";
     }
-    $out .= 'setTimeout("DisplayClock(maxnum, time_str, show_dst, dst_str, locations)", 100);';
-    $out .= '</script>';
+    $output .= 'setTimeout("DisplayClock(maxnum, time_str, show_dst, dst_str, locations)", 100);';
+    $output .= '</script>';
 
-    $block['content'] = $out;
+    $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 .= '<table id="wordclock">';
+  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 .= '<tr class="'. $tr_class .'">';
+      $output .= '<td id="worldclock_location">'. $loc_name  .'</td>';
+      $output .= '<td id="worldclock_time">';
+      $output .= '<span id="worldclock'. $j .'"></span></td>';
+      $output .= '</tr>';
+    }
+  }
+  $output .= '</table>';
+  if ($footnote) {
+    $output .= '<span id="worldclock_footnote">'. $footnote .'</span>';
   }
+  return $output;
 }
 
-/** 
+/**
  * Module settings (admin page)
  */
 function worldclock_admin() {
@@ -407,19 +426,19 @@ function worldclock_admin() {
     '#value' => t('You may leave the location unselected if you do not need to display the time.'),
   );
 
-  for($j = 1 ; $j <= $maxnum ; $j++) {
+  for ($j = 1 ; $j <= $maxnum ; $j++) {
     // show some information
-    $loc_no = variable_get('worldclock_location_' . $j, 0);
+    $loc_no = variable_get('worldclock_location_'. $j, 0);
     $loc_info = '';
-    if($loc_no) { 
-      $loc = $wc_location[$loc_no]; 
+    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(   
+    $form['location']['worldclock_location_'. $j] = array(
       '#type' => 'select',
       '#title' => t('Location ') . $j,
-      '#default_value' => variable_get('worldclock_location_' . $j, 0),
+      '#default_value' => variable_get('worldclock_location_'. $j, 0),
       '#options' => get_location_options(),
       '#description' => $loc_info,
     );
@@ -427,22 +446,22 @@ function worldclock_admin() {
 
   $format_desc = t('Specify the custom time string format. You can use the following format characters.');
   $format_desc .= '<ul>';
-  $format_desc .= t(' Y - Year (4 digits) eg: 2008') . '<br />';
-  $format_desc .= t(' y - Year (2 digits) eg: 08') . '<br />';
-  $format_desc .= t(' M - Month (3 letters) Jan - Dec') . '<br />';
-  $format_desc .= t(' m - Month (2 digits with leading zeros) 01 - 12') . '<br />';
-  $format_desc .= t(' n - Month (without leading zeros) 1 - 12') . '<br />';
-  $format_desc .= t(' d - Date (2 digits with leading zeros) 01 - 31') . '<br />';
-  $format_desc .= t(' j - Date (without leading zeros) 1 - 31') . '<br />';
-  $format_desc .= t(' D - Day of the week (short) SUN - SAT') . '<br />';
-  $format_desc .= t(' h - Hour (12 hour format with leading zeros) 01 - 12') . '<br />';
-  $format_desc .= t(' H - Hour (24 hour format with leading zeros) 00 - 23') . '<br />';
-  $format_desc .= t(' g - Hour (12 hour format without leading zeros) 1 - 12') . '<br />';
-  $format_desc .= t(' G - Hour (24 hour format without leading zeros) 0 - 23') . '<br />';
-  $format_desc .= t(' i - Minutes (with leading zeros) 00 - 59') . '<br />';
-  $format_desc .= t(' s - Seconds (with leading zeros) 00 - 59') . '<br />';
+  $format_desc .= t(' Y - Year (4 digits) eg: 2008') .'<br />';
+  $format_desc .= t(' y - Year (2 digits) eg: 08') .'<br />';
+  $format_desc .= t(' M - Month (3 letters) Jan - Dec') .'<br />';
+  $format_desc .= t(' m - Month (2 digits with leading zeros) 01 - 12') .'<br />';
+  $format_desc .= t(' n - Month (without leading zeros) 1 - 12') .'<br />';
+  $format_desc .= t(' d - Date (2 digits with leading zeros) 01 - 31') .'<br />';
+  $format_desc .= t(' j - Date (without leading zeros) 1 - 31') .'<br />';
+  $format_desc .= t(' D - Day of the week (short) SUN - SAT') .'<br />';
+  $format_desc .= t(' h - Hour (12 hour format with leading zeros) 01 - 12') .'<br />';
+  $format_desc .= t(' H - Hour (24 hour format with leading zeros) 00 - 23') .'<br />';
+  $format_desc .= t(' g - Hour (12 hour format without leading zeros) 1 - 12') .'<br />';
+  $format_desc .= t(' G - Hour (24 hour format without leading zeros) 0 - 23') .'<br />';
+  $format_desc .= t(' i - Minutes (with leading zeros) 00 - 59') .'<br />';
+  $format_desc .= t(' s - Seconds (with leading zeros) 00 - 59') .'<br />';
   $format_desc .= '</ul>';
-  $format_desc .= t('Any non alphanumeric characters including space character are just copied to the output.') . '<br />';
+  $format_desc .= t('Any non alphanumeric characters including space character are just copied to the output.') .'<br />';
 
   $form['display'] = array(
     '#type' => 'fieldset',
@@ -490,7 +509,7 @@ function worldclock_admin() {
   '#attributes' => array('onchange' => 'ChangeFormat(this)'),
   );
 
-  if($format == 'custom') {
+  if ($format == 'custom') {
   $timestr_style = 'visibility: visible; overflow: hidden;';
   }
   else {
@@ -507,16 +526,16 @@ function worldclock_admin() {
   '#field_suffix' => t(' Example: <b>!str1</b>', array('!str1' => date($timestr))),
   '#default_value' => $timestr,
   '#description' => $format_desc,
-  '#prefix' => '<div id="worldclock_timestr_div" style="' . $timestr_style . '">',
+  '#prefix' => '<div id="worldclock_timestr_div" style="'. $timestr_style .'">',
   '#suffix' => '</div>',
-  ); 
+  );
 
   $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',
@@ -525,7 +544,7 @@ function worldclock_admin() {
   '#maxlength' => 10,
   '#default_value' => variable_get('worldclock_dststr', '*'),
   '#description' => t('Specify the DST marker (Symbol, character or a short text)'),
-  ); 
+  );
 
   $form['display']['worldclock_footnote'] = array(
     '#type' => 'textfield',
@@ -534,32 +553,31 @@ function worldclock_admin() {
   '#maxlength' => 60,
   '#default_value' => variable_get('worldclock_footnote', ''),
   '#description' => t('Footnote if any (for example, an explanation about DST marker)'),
-  ); 
+  );
 
-  $form['advenced'] = array(
+  $form['advanced'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Advenced settings'),
+    '#title' => t('Advanced settings'),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
 
-  $form['advenced']['worldclock_showzebra'] = array(
+  $form['advanced']['worldclock_showzebra'] = array(
     '#type' => 'checkbox',
     '#default_value' => variable_get('worldclock_showzebra', 0),
     '#title' => t('Add even and odd class to &lt;tr&gt; tag.'),
     '#description' => t('If checked, odd and even class is added to the &lt;tr&gt; tag of each table row.'),
-  ); 
+  );
   return system_settings_form($form);
 }
 
-/** 
+/**
  * Menu hook
  */
-function worldclock_menu()
-{
+function worldclock_menu() {
   $items = array();
 
-  /*---- for Drupal 5.x ----
+  /* ---- for Drupal 5.x ----
   $items[] = array(
     'path' => 'admin/settings/worldclock',
     'title' => t('World Clock'),
@@ -569,8 +587,8 @@ function worldclock_menu()
     'access' => user_access('access administration pages'),
     'type' => MENU_NORMAL_ITEM,
   );
-  */ 
-  /*---- for Drupal 6.x ----*/
+  */
+  /* ---- for Drupal 6.x ---- */
   $items['admin/settings/worldclock'] = array(
     'title' => 'World Clock',
     'description' => 'Displays a world clock.',
@@ -583,18 +601,17 @@ function worldclock_menu()
   return $items;
 }
 
-/** 
+/**
  * Init hook
  */
-function worldclock_init()
-{
+function worldclock_init() {
   // NOTE: adding javascript at the hook_footer() does not work
   //       with Drupal 6.x. So we use hook_init() which works with
   //       both Drupal 5.x and 6.x.
 
-  $path = drupal_get_path('module', 'worldclock') . '/worldclock.js';
+  $path = drupal_get_path('module', 'worldclock') .'/worldclock.js';
   drupal_add_js($path);
 
   register_location_array();
 }
-?>
+
