? LICENSE.txt
? clock.make
Index: README.txt
===================================================================
RCS file: README.txt
diff -N README.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ README.txt	11 Apr 2010 09:28:09 -0000
@@ -0,0 +1,24 @@
+// $Id$
+
+/*
+ * Installation
+ */
+1. Obtain the "jQuery Timers" library from
+   http://plugins.jquery.com/project/timers. Current version: 1.2.0.
+
+2. Rename the "jquery.timers-1.2.js.txt" file to "jquery.timers.js".
+
+3. If you haven't already, create a 'libraries' directory in your
+   sites folder (sites/all, sites/default, sites/<sitename>).
+
+4. Create a 'jquerytimers' folder inside the 'libraries' directory.
+
+5. Upload the "jquery.timers.js" file into the 'jquerytimers'
+   directory.
+
+6. If you haven't already, download the "Date" project
+   (http://drupal.org/project/date) and install it as usual. Current
+   version: 6.x-2.4.
+
+7. Enable Clock module as usual.
+
Index: clock.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/clock/clock.info,v
retrieving revision 1.4
diff -u -p -r1.4 clock.info
--- clock.info	25 Jan 2010 23:50:59 -0000	1.4
+++ clock.info	11 Apr 2010 09:28:09 -0000
@@ -1,3 +1,4 @@
+; $Id$
 name = Clock
 description = Provides a block displaying the time of a selected time zone.
 core = 6.x
Index: clock.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/clock/clock.install,v
retrieving revision 1.4
diff -u -p -r1.4 clock.install
--- clock.install	28 Jan 2010 15:02:58 -0000	1.4
+++ clock.install	11 Apr 2010 09:28:09 -0000
@@ -1,31 +1,22 @@
 <?php
+// $Id$
+
 /**
  * @file
  * Install, update and uninstall functions for the clock module.
  */
 
-// $Id: clock.install,v 1.4 2010/01/28 15:02:58 tstoeckler Exp $
-
 /*
  * Implement hook_uninstall().
  */
 function clock_uninstall() {
   // Delete all clock variables if they are set.
-  if (variable_get('clock_timezone_type', '1')) {
-    variable_del('clock_timezone_type');
-  }
-  if (variable_get('clock_custom_timezone', 'UTC')) {
-    variable_del('clock_custom_timezone');
-  }
-  if (variable_get('clock_date_format_type', 'short')) {
-    variable_del('clock_date_format_type');
-  }
-  if (variable_get('clock_custom_date_format', 'g:i a')) {
-    variable_del('clock_custom_date_format');
-  }
-  if (variable_get('clock_js', '1')) {
-    variable_del('clock_js');
-  }
+  variable_del('clock_timezone_type');
+  variable_del('clock_custom_timezone');
+  variable_del('clock_date_format_type');
+  variable_del('clock_custom_date_format');
+  variable_del('clock_js');
+
   // Delete the clock block from the blocks table.
   db_query("DELETE FROM {blocks} WHERE module = 'clock'");
 }
Index: clock.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/clock/clock.module,v
retrieving revision 1.9.2.6
diff -u -p -r1.9.2.6 clock.module
--- clock.module	10 Apr 2010 22:34:36 -0000	1.9.2.6
+++ clock.module	11 Apr 2010 09:28:10 -0000
@@ -2,6 +2,11 @@
 // $Id: clock.module,v 1.9.2.6 2010/04/10 22:34:36 tstoeckler Exp $
 
 /*
+ * @file
+ * Functions to manage the display of a clock.
+ */
+
+/*
  * Implements hook_help().
  */
 function clock_help($path, $arg) {
@@ -48,7 +53,7 @@ function clock_help($path, $arg) {
 }
 
 /*
- * Implements hook_block()
+ * Implements hook_block().
  */
 function clock_block($op = 'list', $delta = 0, $edit = array()) {
   switch ($op) {
@@ -76,41 +81,30 @@ function clock_block($op = 'list', $delt
         drupal_set_message('You currently have not installed the <a href="http://drupal.org/project/libraries">Libraries API</a> module. Please download the latest version (if you haven\'t already) and install it. Currently, Clock module works fine without Libraries API, but the next version of Clock and all future releases will depend on it. Therefore you are strongly advised to make this change now to ensure seamless future upgrades.', 'warning');
       }
 
-      drupal_add_js(drupal_get_path('module', 'clock') . '/clock.js');
+      drupal_add_js(drupal_get_path('module', 'clock') . '/clock.js');
+
+      // Time zone options.
+      $form['timezone'] = array(
+        '#type' => 'radios',
+        '#title' => t('Time zone settings'),
+        '#description' => t('<em>Local time zone</em> is the user\'s operating system time.'),
+        '#weight' => 1,
+        '#default_value' => variable_get('clock_timezone_type', '1'),
+        '#options' => array(
+          '1' => t('Site time zone'),
+          '3' => t('Local time zone'),
+          '4' => t('Custom time zone'),
+        ),
+        '#prefix' => '<div class="edit-timezone">',
+        '#suffix' => '</div>',
+      );
+
       // In case of user-configurable timezones show it as an option.
       if (variable_get('configurable_timezones', 1) == 1) {
-        $form['timezone'] = array(
-          '#type' => 'radios',
-          '#title' => t('Time zone settings'),
-          '#description' => t('<em>Local time zone</em> is the user\'s operating system time, while <em>User time zone</em> is the time zone of the Drupal user.'),
-          '#weight' => 1,
-          '#default_value' => variable_get('clock_timezone_type', '1'),
-          '#options' => array(
-            '1' => t('Site time zone'),
-            '2' => t('User time zone'),
-            '3' => t('Local time zone'),
-            '4' => t('Custom time zone'),
-          ),
-          '#prefix' => '<div class="edit-timezone">',
-          '#suffix' => '</div>',
-        );
-      }
-      else {
-        $form['timezone'] = array(
-          '#type' => 'radios',
-          '#title' => t('Time zone settings'),
-          '#description' => t('<em>Local time zone</em> is the user\'s operating system time.'),
-          '#weight' => 1,
-          '#default_value' => variable_get('clock_timezone_type', '1'),
-          '#options' => array(
-            '1' => t('Site time zone'),
-            '3' => t('Local time zone'),
-            '4' => t('Custom time zone'),
-          ),
-          '#prefix' => '<div class="edit-timezone">',
-          '#suffix' => '</div>',
-        );
-      }
+        $form['timezone']['#description'] = t('<em>Local time zone</em> is the user\'s operating system time, while <em>User time zone</em> is the time zone of the Drupal user.');
+        $form['timezone']['#options']['2'] = t('User time zone');
+      }
+
       $form['timezone']['custom_timezone'] = array(
         '#type' => 'select',
         '#multiple' => FALSE,
@@ -119,96 +113,82 @@ function clock_block($op = 'list', $delt
         '#options' => date_timezone_names(),
         '#prefix' => '<div class="edit-custom-timezone">',
         '#suffix' => '</div>',
-      );
-      // Format the current time with each of the three default date formats to display them in the form.
-      // Get the current timezone.
-      $clock_timezone_type = variable_get('clock_timezone_type', 'site');
-      switch ($clock_timezone_type) {
-        // Site time zone
-        case '1':
-          $clock_timezone = variable_get('date_default_timezone_name', 'UTC');
-          break;
-        // User time zone
-        case '2':
-          $clock_timezone = NULL;
-          break;
-        // Custom time zone
-        case '3':
-          $clock_timezone = variable_get('clock_custom_timezone', 'UTC');
-          break;
-      }
-      
-      $short_date_format_formatted = date_format_date(date_now($clock_timezone), $type = 'short');
-      $medium_date_format_formatted = date_format_date(date_now($clock_timezone), $type = 'medium');
-      $long_date_format_formatted = date_format_date(date_now($clock_timezone), $type = 'long');
+      );
+
+      // Format the current time with each of the three default date formats to display them in the form.
+      $timezone = clock_get_timezone();
+      $short = date_format_date(date_now($timezone), $type = 'short');
+      $medium = date_format_date(date_now($timezone), $type = 'medium');
+      $long = date_format_date(date_now($timezone), $type = 'long');
+
+      // Date format options.
+      $form['date_format'] = array(
+        '#type' => 'radios',
+        '#title' => t('Date format settings'),
+        '#weight' => 3,
+        '#default_value' => variable_get('clock_date_format_type', 'short'),
+        '#options' => array(
+          'short' => t('Short date format (@short)', array('@short' => $short)),
+          'medium' => t('Medium date format (@medium)', array('@medium' => $medium)),
+          'long' => t('Long date format (@long)', array('@long' => $long)),
+        ),
+      );
+
       // If there are custom date formats, gather them and prepare them to display them in the form.
-      $custom_date_formats = db_query("SELECT format FROM {date_formats} WHERE type = 'custom'");
-      $custom_date_formats_array = array();
-      while ($custom_date_format = db_fetch_object($custom_date_formats)) {
-        $custom_date_formats_array[$custom_date_format->format] = date_format_date(date_now($clock_timezone), $type = 'custom', $format = $custom_date_format->format);
-      }
-      if (!empty($custom_date_formats_array)) {
-        $form['date_format'] = array(
-          '#type' => 'radios',
-          '#title' => t('Date format settings'),
-          '#weight' => 3,
-          '#default_value' => variable_get('clock_date_format_type', 'short'),
-          '#options' => array(
-            'short' => t('Short date format (@short_date_format)', array('@short_date_format' => $short_date_format_formatted)),
-            'medium' => t('Medium date format (@medium_date_format)', array('@medium_date_format' => $medium_date_format_formatted)),
-            'long' => t('Long date format (@long_date_format)', array('@long_date_format' => $long_date_format_formatted)),
-            'custom' => t('Custom date format'),
-          ),
-          '#prefix' => '<div class="edit-date-format">',
-          '#suffix' => '</div>',
-        );
+      $result = db_query("SELECT format FROM {date_formats} WHERE type = 'custom'");
+      $date_formats = array();
+      while ($date_format = db_fetch_object($result)) {
+        $date_formats[$date_format->format] = date_format_date(date_now($timezone), $type = 'custom', $format = $date_format->format);
+      }
+
+      if ($custom_date_formats_array) {
+        $form['date_format']['#options']['custom'] = 'custom' => t('Custom date format');
+        $form['date_format']['#prefix'] = '<div class="edit-date-format">';
+        $form['date_format']['#suffix'] = '</div>';
+
         $form['date_format']['custom_date_format'] = array(
           '#type' => 'select',
           '#multiple' => FALSE,
           '#weight' => 4,
-          // Sets the default for the custom date format to e.g.: '1:23 am'
           '#default_value' => variable_get('clock_custom_date_format', 'g:i a'),
-          '#options' => $custom_date_formats_array,
+          '#options' => $date_formats,
           '#prefix' => '<div class="edit-custom-date-format">',
           '#suffix' => '</div>',
         );
       }
-      else {
-        $form['date_format'] = array(
-          '#type' => 'radios',
-          '#title' => t('Date format settings'),
-          '#weight' => 3,
-          '#default_value' => variable_get('clock_date_format_type', 'short'),
-          '#options' => array(
-            'short' => t('Short date format (@short_date_format)', array('@short_date_format' => $short_date_format_formatted)),
-            'medium' => t('Medium date format (@medium_date_format)', array('@medium_date_format' => $medium_date_format_formatted)),
-            'long' => t('Long date format (@long_date_format)', array('@long_date_format' => $long_date_format_formatted)),
-          ),
-        );
-      }
+
+      // JavaScript options.
       $form['js'] = array(
         '#type' => 'checkbox',
         '#title' => t('Use JavaScript to continuously update the clock'),
         '#weight' => 5,
         '#default_value' => variable_get('clock_js', '1'),
-      );
+      );
+
       return $form;
 
     case 'save':
       variable_set('clock_timezone_type', $edit['timezone']);
       if ($edit['timezone'] == '4') {
         variable_set('clock_custom_timezone', $edit['custom_timezone']);
-      }
+      }
+
       variable_set('clock_date_format_type', $edit['date_format']);
       if ($edit['date_format'] == 'custom') {
         variable_set('clock_custom_date_format', $edit['custom_date_format']);
       }
+
       variable_set('clock_js', $edit['js']);
+
       return;
 
-    case 'view':
+    case 'view':
+      $timezone = clock_get_timezone();
+      $date_format = clock_get_date_format();
+      $js = variable_get('clock_js', '1');
+
       $block['subject'] = 'Clock';
-      $block['content'] = theme_clock($clock_timezone, $clock_date_format_type, $clock_custom_date_format);
+      $block['content'] = theme_clock($timezone, $date_format, $js);
       return $block;
   }
 }
@@ -220,91 +200,95 @@ function clock_theme() {
   return array(
     'clock' => array(
       'arguments' => array(
-        'clock_timezone' => 'UTC',
-        'clock_date_format_type' => 'short',
-        'clock_custom_date_format' => 'g:i a',
+        'timezone' => 'UTC',
+        'date_format' => 'short',
+        'js' => '1',
       ),
     ),
   );
-}
-
-/*
- * Provide a default implementation of theme_clock().
- */
-function theme_clock($timezone = 'UTC', $format = 'g:i a') {
-  $output = '';
+}
 
-  $clock_timezone_type = variable_get('clock_timezone_type', '1');
-  switch ($clock_timezone_type) {
+/*
+ * Gets the correct time zone.
+ *
+ * @return
+ *   A string containing the time zone name or NULL if the time zone type is
+ *   'User time zone'. If the time zone type is 'Local time zone' the string
+ *   'Local' is returned.
+ */
+function clock_get_timezone() {
+  $timezone_type = variable_get('clock_timezone_type', 'site');
+
+  switch ($timezone_type) {
     // Site time zone
-    case '1':
-    // If time zone is set to 'Local' and the user has JS disabled, show the site time zone.
-    case '3':
-      $clock_timezone = variable_get('date_default_timezone_name', 'UTC');
+    case '1':
+      $timezone = variable_get('date_default_timezone_name', 'UTC');
       break;
     // User time zone
     case '2':
-      $clock_timezone = NULL;
-      break;
+      $timezone = NULL;
+      break;
+    case '3':
+      $timezone = 'Local';
     // Custom time zone
     case '4':
-      $clock_timezone = variable_get('clock_custom_timezone', 'UTC');
+      $timezone = variable_get('clock_custom_timezone', 'UTC');
       break;
-  }
+  }
 
-  $clock_date_format_type = variable_get('clock_date_format_type', 'short');
-  if ($clock_date_format_type == 'custom') {
-    $clock_custom_date_format = variable_get('clock_custom_date_format', 'g:i a');
-  }
-  else {
-    $clock_custom_date_format = NULL;
+  return $timezone;
+}
+
+/*
+ * Gets the correct date format.
+ *
+ * @return
+ *   A date format string. See http://php.net/date for more information.
+ */
+function clock_get_date_format() {
+  $date_format_type = variable_get('clock_date_format_type', 'short');
+
+  switch ($date_format_type) {
+    case 'short':
+      $date_format = variable_get('date_format_short', 'd/m/Y - H:i');
+    case 'medium':
+      $date_format = variable_get('date_format_medium', 'l, m/d/Y, g:i a');
+    case 'long':
+      $date_format = variable_get('date_format_long', 'l, Y,  F j - H:i');
+    case 'custom':
+      $date_format = variable_get('clock_custom_date_format', 'g:i a');
   }
-  $clock_js = variable_get('clock_js', '1');
-  if ($clock_js == '1' || $clock_timezone_type == '3') {
+
+  return $date_format;
+}
+
+/*
+ * Formats a clock in HTML.
+ */
+function theme_clock($timezone, $date_format, $js) {
+  if ($js == '1' || $timezone == 'Local') {
 
     // Create variables that are needed for the JavaScript time calculation.
 
     // Create a time string.
-    $clock_time = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'F j, Y H:i:s');
+    $time = date_format_date(date_make_date(date_now($timezone), $type = 'custom', $format = 'F j, Y H:i:s');
     // Get the time zone offset in seconds.
-    $clock_timezone_offset_seconds = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'Z');
-    // Get the name of the time zone, e.g. 'Europe/London'.
-    if ($clock_timezone_type == '3') {
-      $clock_timezone_name = 'Local';
-    }
-    else {
-      $clock_timezone_name = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'e');
-    }
-
+    $offset_seconds = date_format_date(date_now($timezone), $type = 'custom', $format = 'Z');
     // Get Daylight Savings Time information. '1' for yes, '0' for no.
-    $clock_daylight_savings_time = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'I');
+    $daylight_savings_time = date_format_date(date_now($timezone), $type = 'custom', $format = 'I');
     // Get the name of the offset, e.g. 'GMT'.
-    $clock_offset_name = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = 'custom', $format = 'T');
-    // Get the correct date format.
-    switch ($clock_date_format_type) {
-      case 'short':
-        $clock_date_format = variable_get('date_format_short', 'Y-m-d H:i');
-        break;
-      case 'medium':
-        $clock_date_format = variable_get('date_format_medium', 'D, Y-m-d H:i');
-        break;
-      case 'long':
-        $clock_date_format = variable_get('date_format_long', 'l, F j, Y - H:i');
-        break;
-      case 'custom':
-        $clock_date_format = variable_get('clock_custom_date_format', 'g:i a');
-        break;
-    }
+    $offset_name = date_format_date(date_now($timezone), $type = 'custom', $format = 'T');
+    // Get the correct date format.
 
     // Pass the variables to JavaScript.
     drupal_add_js(array(
-      '0' => $clock_js,
-      '1' => $clock_time,
-      '2' => $clock_timezone_offset_seconds,
-      '3' => $clock_timezone_name,
-      '4' => $clock_daylight_savings_time,
-      '5' => $clock_offset_name,
-      '6' => $clock_date_format,
+      '0' => $js,
+      '1' => $time,
+      '2' => $offset_seconds,
+      '3' => $timezone,
+      '4' => $daylight_savings_time,
+      '5' => $offset_name,
+      '6' => $date_format,
     ), 'setting');
 
 
@@ -323,9 +307,9 @@ function theme_clock($timezone = 'UTC', 
   }
 
   // Create a date object with the correct timezone and format it with the correct date format.
-  $clock_formatted = date_format_date(date_make_date($date = 'now', $timezone = $clock_timezone), $type = $clock_date_format_type, $format = $clock_custom_date_format);
+  $clock = date_format_date(date_now($timezone), $type = 'custom', $format = $date_format);
 
-  $output .= '<div class="clock">' . $clock_formatted . '</div>';
+  $output = '<div class="clock">' . $clock . '</div>';
 
   return $output;
 }
