Projet

Général

Profil

Révision b720ea3e

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_api/date_api_ical.inc
181 181
              $parent[array_pop($parents)][] = array_pop($subgroups);
182 182
            }
183 183
            break;
184

  
184 185
          // Add the timezones in with their index their TZID.
185 186
          case 'VTIMEZONE':
186 187
            $subgroup = end($subgroups);
......
196 197
            array_pop($subgroups);
197 198
            array_pop($parents);
198 199
            break;
200

  
199 201
          // Do some fun stuff with durations and all_day events and then append
200 202
          // to parent.
201 203
          case 'VEVENT':
......
222 224
            // assumes the end date is inclusive.
223 225
            if (!empty($subgroup['DTEND']) && (!empty($subgroup['DTEND']['all_day']))) {
224 226
              // Make the end date one day earlier.
225
              $date = new DateObject ($subgroup['DTEND']['datetime'] . ' 00:00:00', $subgroup['DTEND']['tz']);
227
              $date = new DateObject($subgroup['DTEND']['datetime'] . ' 00:00:00', $subgroup['DTEND']['tz']);
226 228
              date_modify($date, '-1 day');
227
              $subgroup['DTEND']['datetime'] = date_format($date,  'Y-m-d');
229
              $subgroup['DTEND']['datetime'] = date_format($date, 'Y-m-d');
228 230
            }
229 231
            // If a start datetime is defined AND there is no definition for
230 232
            // the end datetime THEN make the end datetime equal the start
......
239 241
            if (!empty($subgroup['DTSTART']['all_day'])) {
240 242
              $subgroup['all_day'] = TRUE;
241 243
            }
242
            // Add this element to the parent as an array under the
244
            // Add this element to the parent as an array under the.
243 245
            prev($subgroups);
244 246
            $parent = &$subgroups[key($subgroups)];
245 247

  
......
264 266
      $field = !empty($matches[2]) ? $matches[2] : '';
265 267
      $data = !empty($matches[3]) ? $matches[3] : '';
266 268
      $parse_result = '';
269

  
267 270
      switch ($name) {
268 271
        // Keep blank lines out of the results.
269 272
        case '':
270 273
          break;
271 274

  
272
          // Lots of properties have date values that must be parsed out.
275
        // Lots of properties have date values that must be parsed out.
273 276
        case 'CREATED':
274 277
        case 'LAST-MODIFIED':
275 278
        case 'DTSTART':
......
317 320
          $parse_result = date_ical_parse_location($field, $data);
318 321
          break;
319 322

  
320
          // For all other properties, just store the property and the value.
321
          // This can be expanded on in the future if other properties should
322
          // be given special treatment.
323
        // For all other properties, just store the property and the value.
324
        // This can be expanded on in the future if other properties should
325
        // be given special treatment.
323 326
        default:
324 327
          $parse_result = $data;
325 328
          break;
......
360 363
 *                      has no timezone; the ical specs say no timezone
361 364
 *                      conversion should be done if no timezone info is
362 365
 *                      supplied
363
 *  @todo
366
 * @todo
364 367
 *   Another option for dates is the format PROPERTY;VALUE=PERIOD:XXXX. The
365 368
 *   period may include a duration, or a date and a duration, or two dates, so
366 369
 *   would have to be split into parts and run through date_ical_parse_date()
......
401 404
        // Date.
402 405
        $datetime = date_pad($regs[1]) . '-' . date_pad($regs[2]) . '-' . date_pad($regs[3]);
403 406
        break;
407

  
404 408
      case 'DATE-TIME':
405 409
        preg_match(DATE_REGEX_ICAL_DATETIME, $data, $regs);
406 410
        // Date.
......
519 523
  $data  = $items['DATA'];
520 524
  preg_match('/^P(\d{1,4}[Y])?(\d{1,2}[M])?(\d{1,2}[W])?(\d{1,2}[D])?([T]{0,1})?(\d{1,2}[H])?(\d{1,2}[M])?(\d{1,2}[S])?/', $data, $duration);
521 525
  $items['year'] = isset($duration[1]) ? str_replace('Y', '', $duration[1]) : '';
522
  $items['month'] = isset($duration[2]) ?str_replace('M', '', $duration[2]) : '';
523
  $items['week'] = isset($duration[3]) ?str_replace('W', '', $duration[3]) : '';
524
  $items['day'] = isset($duration[4]) ?str_replace('D', '', $duration[4]) : '';
525
  $items['hour'] = isset($duration[6]) ?str_replace('H', '', $duration[6]) : '';
526
  $items['minute'] = isset($duration[7]) ?str_replace('M', '', $duration[7]) : '';
527
  $items['second'] = isset($duration[8]) ?str_replace('S', '', $duration[8]) : '';
526
  $items['month'] = isset($duration[2]) ? str_replace('M', '', $duration[2]) : '';
527
  $items['week'] = isset($duration[3]) ? str_replace('W', '', $duration[3]) : '';
528
  $items['day'] = isset($duration[4]) ? str_replace('D', '', $duration[4]) : '';
529
  $items['hour'] = isset($duration[6]) ? str_replace('H', '', $duration[6]) : '';
530
  $items['minute'] = isset($duration[7]) ? str_replace('M', '', $duration[7]) : '';
531
  $items['second'] = isset($duration[8]) ? str_replace('S', '', $duration[8]) : '';
528 532
  $start_date = array_key_exists('DTSTART', $subgroup) ? $subgroup['DTSTART']['datetime'] : date_format(date_now(), DATE_FORMAT_ISO);
529 533
  $timezone = array_key_exists('DTSTART', $subgroup) ? $subgroup['DTSTART']['tz'] : variable_get('date_default_timezone');
530 534
  if (empty($timezone)) {
......
542 546
    'datetime' => date_format($date2, DATE_FORMAT_DATETIME),
543 547
    'all_day' => isset($subgroup['DTSTART']['all_day']) ? $subgroup['DTSTART']['all_day'] : 0,
544 548
    'tz' => $timezone,
545
    );
549
  );
546 550
  $duration = date_format($date2, 'U') - date_format($date, 'U');
547 551
  $subgroup['DURATION'] = array('DATA' => $data, 'DURATION' => $duration);
548 552
}
......
631 635
 *
632 636
 * @return string
633 637
 *   Escaped text
634
 *
635 638
 */
636 639
function date_ical_escape_text($text) {
637 640
  $text = drupal_html_to_text($text);
......
693 696
 *     )
694 697
 */
695 698
function date_api_ical_build_rrule($form_values) {
696
  $RRULE = '';
699
  $rrule = '';
697 700
  if (empty($form_values) || !is_array($form_values)) {
698
    return $RRULE;
701
    return $rrule;
699 702
  }
700 703

  
701 704
  // Grab the RRULE data and put them into iCal RRULE format.
702
  $RRULE .= 'RRULE:FREQ=' . (!array_key_exists('FREQ', $form_values) ? 'DAILY' : $form_values['FREQ']);
703
  $RRULE .= ';INTERVAL=' . (!array_key_exists('INTERVAL', $form_values) ? 1 : $form_values['INTERVAL']);
705
  $rrule .= 'RRULE:FREQ=' . (!array_key_exists('FREQ', $form_values) ? 'DAILY' : $form_values['FREQ']);
706
  $rrule .= ';INTERVAL=' . (!array_key_exists('INTERVAL', $form_values) ? 1 : $form_values['INTERVAL']);
704 707

  
705 708
  // Unset the empty 'All' values.
706 709
  if (array_key_exists('BYDAY', $form_values) && is_array($form_values['BYDAY'])) {
......
713 716
    unset($form_values['BYMONTHDAY']['']);
714 717
  }
715 718

  
716
  if (array_key_exists('BYDAY', $form_values) && is_array($form_values['BYDAY']) && $BYDAY = implode(",", $form_values['BYDAY'])) {
717
    $RRULE .= ';BYDAY=' . $BYDAY;
719
  if (array_key_exists('BYDAY', $form_values) && is_array($form_values['BYDAY']) && $byday = implode(",", $form_values['BYDAY'])) {
720
    $rrule .= ';BYDAY=' . $byday;
718 721
  }
719
  if (array_key_exists('BYMONTH', $form_values) && is_array($form_values['BYMONTH']) && $BYMONTH = implode(",", $form_values['BYMONTH'])) {
720
    $RRULE .= ';BYMONTH=' . $BYMONTH;
722
  if (array_key_exists('BYMONTH', $form_values) && is_array($form_values['BYMONTH']) && $bymonth = implode(",", $form_values['BYMONTH'])) {
723
    $rrule .= ';BYMONTH=' . $bymonth;
721 724
  }
722
  if (array_key_exists('BYMONTHDAY', $form_values) && is_array($form_values['BYMONTHDAY']) && $BYMONTHDAY = implode(",", $form_values['BYMONTHDAY'])) {
723
    $RRULE .= ';BYMONTHDAY=' . $BYMONTHDAY;
725
  if (array_key_exists('BYMONTHDAY', $form_values) && is_array($form_values['BYMONTHDAY']) && $bymonthday = implode(",", $form_values['BYMONTHDAY'])) {
726
    $rrule .= ';BYMONTHDAY=' . $bymonthday;
724 727
  }
725 728
  // The UNTIL date is supposed to always be expressed in UTC.
726 729
  // The input date values may already have been converted to a date object on a
......
731 734
    if (!is_object($form_values['UNTIL']['datetime'])) {
732 735
      // If this is a date without time, give it time.
733 736
      if (strlen($form_values['UNTIL']['datetime']) < 11) {
737
        $granularity_options = drupal_map_assoc(array(
738
          'year',
739
          'month',
740
          'day',
741
          'hour',
742
          'minute',
743
          'second',
744
        ));
745

  
734 746
        $form_values['UNTIL']['datetime'] .= ' 23:59:59';
735
        $form_values['UNTIL']['granularity'] = serialize(drupal_map_assoc(array('year', 'month', 'day', 'hour', 'minute', 'second')));
747
        $form_values['UNTIL']['granularity'] = serialize($granularity_options);
736 748
        $form_values['UNTIL']['all_day'] = FALSE;
737 749
      }
738 750
      $until = date_ical_date($form_values['UNTIL'], 'UTC');
......
740 752
    else {
741 753
      $until = $form_values['UNTIL']['datetime'];
742 754
    }
743
    $RRULE .= ';UNTIL=' . date_format($until, DATE_FORMAT_ICAL) . 'Z';
755
    $rrule .= ';UNTIL=' . date_format($until, DATE_FORMAT_ICAL) . 'Z';
744 756
  }
745 757
  // Our form doesn't allow a value for COUNT, but it may be needed by
746 758
  // modules using the API, so add it to the rule.
747 759
  if (array_key_exists('COUNT', $form_values)) {
748
    $RRULE .= ';COUNT=' . $form_values['COUNT'];
760
    $rrule .= ';COUNT=' . $form_values['COUNT'];
749 761
  }
750 762

  
751 763
  // iCal rules presume the week starts on Monday unless otherwise specified,
752 764
  // so we'll specify it.
753 765
  if (array_key_exists('WKST', $form_values)) {
754
    $RRULE .= ';WKST=' . $form_values['WKST'];
766
    $rrule .= ';WKST=' . $form_values['WKST'];
755 767
  }
756 768
  else {
757
    $RRULE .= ';WKST=' . date_repeat_dow2day(variable_get('date_first_day', 0));
769
    $rrule .= ';WKST=' . date_repeat_dow2day(variable_get('date_first_day', 0));
758 770
  }
759 771

  
760 772
  // Exceptions dates go last, on their own line.
......
765 777
    foreach ($form_values['EXDATE'] as $value) {
766 778
      if (!empty($value['datetime'])) {
767 779
        $date = !is_object($value['datetime']) ? date_ical_date($value, 'UTC') : $value['datetime'];
768
        $ex_date = !empty($date) ? date_format($date, DATE_FORMAT_ICAL) . 'Z': '';
780
        $ex_date = !empty($date) ? date_format($date, DATE_FORMAT_ICAL) . 'Z' : '';
769 781
        if (!empty($ex_date)) {
770 782
          $ex_dates[] = $ex_date;
771 783
        }
......
773 785
    }
774 786
    if (!empty($ex_dates)) {
775 787
      sort($ex_dates);
776
      $RRULE .= chr(13) . chr(10) . 'EXDATE:' . implode(',', $ex_dates);
788
      $rrule .= chr(13) . chr(10) . 'EXDATE:' . implode(',', $ex_dates);
777 789
    }
778 790
  }
779 791
  elseif (!empty($form_values['EXDATE'])) {
780
    $RRULE .= chr(13) . chr(10) . 'EXDATE:' . $form_values['EXDATE'];
792
    $rrule .= chr(13) . chr(10) . 'EXDATE:' . $form_values['EXDATE'];
781 793
  }
782 794

  
783 795
  // Exceptions dates go last, on their own line.
......
785 797
    $ex_dates = array();
786 798
    foreach ($form_values['RDATE'] as $value) {
787 799
      $date = !is_object($value['datetime']) ? date_ical_date($value, 'UTC') : $value['datetime'];
788
      $ex_date = !empty($date) ? date_format($date, DATE_FORMAT_ICAL) . 'Z': '';
800
      $ex_date = !empty($date) ? date_format($date, DATE_FORMAT_ICAL) . 'Z' : '';
789 801
      if (!empty($ex_date)) {
790 802
        $ex_dates[] = $ex_date;
791 803
      }
792 804
    }
793 805
    if (!empty($ex_dates)) {
794 806
      sort($ex_dates);
795
      $RRULE .= chr(13) . chr(10) . 'RDATE:' . implode(',', $ex_dates);
807
      $rrule .= chr(13) . chr(10) . 'RDATE:' . implode(',', $ex_dates);
796 808
    }
797 809
  }
798 810
  elseif (!empty($form_values['RDATE'])) {
799
    $RRULE .= chr(13) . chr(10) . 'RDATE:' . $form_values['RDATE'];
811
    $rrule .= chr(13) . chr(10) . 'RDATE:' . $form_values['RDATE'];
800 812
  }
801 813

  
802
  return $RRULE;
814
  return $rrule;
803 815
}

Formats disponibles : Unified diff