~pwolanin/+junk/AD-pressflow-6

« back to all changes in this revision

Viewing changes to modules/acquia/date/date/date_content_generate.inc

  • Committer: Peter Wolanin
  • Date: 2009-09-17 21:56:51 UTC
  • Revision ID: pwolanin@curie.local-20090917215651-jm4azy7ee79zx5bz
   Acquia Drupal 1.2.16 (Drupal 6.14 core) has just been released and
   contains important security updates and bug fixes. We recommend that
   you update to the new version as soon as possible.
    1. Please reference the [1]Getting Started Guide for information about
       updating your site.
    2. Next, [2]download the new version.

   Acquia Drupal consists of Acquia's package of Drupal core with a
   curated set of contributed modules, plus the ability to connect to the
   Acquia Network. 
   Acquia Drupal 1.2.16 (Drupal 6.14 core) includes the
   following updates: 
   ===================================================
     * Updated Drupal core to version [3]6.14. This also fixes a multiple
       security issues described in [4]DRUPAL-SA-CORE-2009-008.
     * Updated the Date module to [5]6.x-2.4. This also fixes a Cross Site
       Scripting security issue described in
       [6]DRUPAL-SA-CONTRIB-2009-057.
     * Added the jquery_ui module, version [7]6.x-1.3. This fixes a
       warning that appears on the status page if you have the date_popup
       module enabled.
     * Updated the Content Construction Kit (CCK) module to [8]6.x-2.5.
     * Updated the Image module to [9]6.x-1.0-beta3.
     * Updated the Mollom module to [10]6.x-1.10.
     * Updated the Voting API module to [11]6.x-2.3.

References

   1. http://acquia.com/documentation/getting-started/introduction
   2. http://acquia.com/downloads
   3. http://drupal.org/node/579476
   4. http://drupal.org/node/579482
   5. http://drupal.org/node/579000
   6. http://drupal.org/node/579144
   7. http://drupal.org/node/497608
   8. http://drupal.org/node/539128
   9. http://drupal.org/node/575958
  10. http://drupal.org/node/551398
  11. http://drupal.org/node/550092

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Implementation of Devel module's hook_content_generate().
 
4
 *
 
5
 * Included only when needed.
 
6
 */
 
7
function _date_content_generate($node, $field) {
 
8
  include_once('./'. drupal_get_path('module', 'date_api') .'/date_api_elements.inc');
 
9
  
 
10
  $node_field = array();
 
11
  if (isset($field['widget']['year_range'])) {
 
12
    $split = explode(':', $field['widget']['year_range']);
 
13
    $back = str_replace('-', '', $split[0]);
 
14
    $forward = str_replace('+', '', $split[1]);
 
15
  }
 
16
  else {
 
17
    $back = 2;
 
18
    $forward = 2;
 
19
  }
 
20
  // Pick a random year within the time range,
 
21
  // and a random second within that year.
 
22
        $year = date_format(date_now(), 'Y') - $back + mt_rand(0, ($forward + $back));
 
23
        $start = date_make_date($year .'-01-01 00:00:00', date_get_timezone_db($field['tz_handling']));
 
24
        $leap = date_format($start, 'L');
 
25
        $max_days = $leap ? 366 : 365;
 
26
        $seconds = mt_rand(0, ($max_days * 86400));
 
27
        date_modify($start, "+$seconds seconds");
 
28
        $increment = $field['widget']['increment'];
 
29
  date_increment_round($start, $increment);
 
30
    
 
31
        // Modify To date by 1 hour to 3 days, shorter for repeating dates
 
32
        // longer for others.
 
33
        $start2 = drupal_clone($start);
 
34
        $max = !empty($field['repeat']) ? 720 : 4320;
 
35
        $max = 240;
 
36
  date_modify($start2, '+'. mt_rand(60, $max) .' minutes');  
 
37
  date_increment_round($start2, $increment);
 
38
      
 
39
  if ($field['tz_handling'] == 'date') {
 
40
    // Choose a random timezone.
 
41
    // Not all keys exist, so we have to check.
 
42
    $timezones = array_keys(date_timezone_names(TRUE));
 
43
    $key = mt_rand(0, count($timezones) - 1);
 
44
    if (!array_key_exists($key, $timezones)) {
 
45
      $timezone = date_default_timezone_name();
 
46
    }
 
47
    else {
 
48
      $timezone = $timezones[$key];
 
49
    }
 
50
  }
 
51
  else {
 
52
    $timezone = date_get_timezone($field['tz_handling']);
 
53
  }
 
54
    
 
55
  switch ($field['type']) {
 
56
    case 'date':
 
57
      $format = DATE_FORMAT_ISO;
 
58
      break;
 
59
    case 'datestamp':
 
60
      $format = DATE_FORMAT_UNIX;
 
61
      break;
 
62
    case 'datetime':
 
63
      $format = DATE_FORMAT_DATETIME;
 
64
      break;
 
65
  }
 
66
  $node_field['value'] = date_format($start, $format);
 
67
  if ($field['todate']) {
 
68
    $node_field['value2'] = date_format($start2, $format);
 
69
  }
 
70
  date_timezone_set($start, timezone_open($timezone));
 
71
  $node_field['timezone'] = $timezone;
 
72
  $node_field['offset'] = date_offset_get($start);
 
73
  date_timezone_set($start2, timezone_open($timezone));
 
74
  $node_field['offset2'] = date_offset_get($start2);                    
 
75
  
 
76
  if (!empty($field['repeat'])) {
 
77
    include_once('./'. drupal_get_path('module', 'date_repeat') .'/date_repeat_calc.inc');
 
78
    include_once('./'. drupal_get_path('module', 'date') .'/date_repeat.inc');
 
79
    include_once('./'. drupal_get_path('module', 'date_api') .'/date_api_ical.inc');
 
80
  
 
81
    // Create a repeating date.
 
82
    $duration = date_difference($start, $start2);
 
83
    $form_values = array();
 
84
    
 
85
    // Create the default case more frequently than case 1 or 2.
 
86
    $which = mt_rand(0, 10);
 
87
    $max_items = 10;
 
88
    $intervals = array_keys(INTERVAL_options());
 
89
    unset($intervals[0]);
 
90
    $interval = $intervals[mt_rand(1, 3)];
 
91
    switch ($which) {
 
92
      case 1:
 
93
        $mo = mt_rand(1, 28);
 
94
        $options = array('YEARLY', 'MONTHLY');
 
95
        $freq = date_content_generate_key($options);
 
96
        $freq = $options[$freq];
 
97
        $form_values['FREQ'] = $freq;
 
98
        // Make sure we'll find a match in our range.
 
99
        if ($freq == 'YEARLY') {
 
100
          $interval = 1;
 
101
        }
 
102
        $form_values['BYMONTHDAY'] = array($mo);
 
103
        break;
 
104
      case 2:
 
105
        $mo = mt_rand(1, 12);
 
106
        $options = array('YEARLY', 'MONTHLY');
 
107
        $freq = date_content_generate_key($options);
 
108
        $freq = $options[$freq];
 
109
        $form_values['FREQ'] = $freq;
 
110
        // Make sure we'll find a match in our range.
 
111
        if ($freq == 'YEARLY') {
 
112
          $interval = 1;
 
113
        }
 
114
        $form_values['BYMONTH'] = array($mo);
 
115
        break;
 
116
      default:
 
117
        $dows = array_keys(date_content_repeat_dow_options());
 
118
        $day = date_content_generate_key($dows);
 
119
        $dow = $dows[$day];
 
120
        $options = array('MONTHLY', 'DAILY', 'WEEKLY');
 
121
        $freq = date_content_generate_key($options);
 
122
        $freq = $options[$freq];
 
123
        $form_values['FREQ'] = $freq;
 
124
        $form_values['BYDAY'] = array($dow);
 
125
        break;
 
126
    }
 
127
    
 
128
    $form_values['INTERVAL'] = $interval;
 
129
    
 
130
    switch ($freq) {
 
131
      case 'YEARLY':
 
132
        $period = 'year';
 
133
        break;
 
134
      case 'MONTHLY':
 
135
        $period = 'month';
 
136
        break;
 
137
      case 'WEEKLY':
 
138
        $period = 'week';
 
139
        break;
 
140
      default:
 
141
        $period = 'day';
 
142
        break;
 
143
        
 
144
    }
 
145
    date_modify($start2, '+'. max(1, $forward) .' years');
 
146
    date_increment_round($start2, $increment);
 
147
    $until = date_format($start2, 'Y-m-d H:i:s');
 
148
    $form_values['UNTIL'] = array('datetime' => $until, 'tz' => 'UTC');
 
149
    $form_values['COUNT'] = $max_items;
 
150
    
 
151
    $rrule = date_api_ical_build_rrule($form_values);
 
152
    $values = date_repeat_build_dates($rrule, $form_values, $field, $node_field);
 
153
    
 
154
    $start = $node_field;
 
155
    $node_field = array(0 => $start);
 
156
    $node_field[0]['rrule'] = $rrule;
 
157
    $node_field += $values;
 
158
  }
 
159
  return $node_field;
 
160
}
 
161
 
 
162
function date_content_generate_key($array) {
 
163
  $keys = array_keys($array);
 
164
  $min = array_shift($keys);
 
165
  $max = array_pop($keys);
 
166
  return mt_rand($min, $max);
 
167
}
 
168
 
 
169
/**
 
170
 * Helper function for BYDAY options.
 
171
 *
 
172
 * Creates options like -1SU and 2TU
 
173
 * Omit options that won't find many matches, like 5th Sunday.
 
174
 */
 
175
function date_content_repeat_dow_options() {
 
176
  $options = array();
 
177
  foreach (date_repeat_dow_count_options() as $count_key => $count_value) {
 
178
    foreach (date_repeat_dow_day_options() as $dow_key => $dow_value) {
 
179
      if ($count_key != 5 && $count_key != -5) {
 
180
        $options[$count_key . $dow_key] = $count_value .' '. $dow_value;
 
181
      }
 
182
    }
 
183
  }
 
184
  return $options;
 
185
}
 
 
b'\\ No newline at end of file'