예제 #1
0
/**
 * Converts year+week to year+month+day. This is really complex. The first week of a year may actually start in December. The first day of the first week is a Monday or a Sunday, depending on configuration.
 *
 * @param  integer			Year #
 * @param  integer			Week #
 * @return array				Month #,Day #,Year #
 */
function date_from_week_of_year($year, $week)
{
    $basis = strval($year) . '-' . str_pad(strval($week), 2, '0', STR_PAD_LEFT);
    $time = mktime(0, 0, 0, 1, 1, $year);
    for ($i = $week == 52 ? 300 : 0; $i < 366; $i++) {
        $new_time = $time + 60 * 60 * 24 * $i;
        if (date('w', $new_time) == '1' && get_option('ssw') == '0' || date('w', $new_time) == '0' && get_option('ssw') == '1') {
            $test = get_week_number_for($new_time);
            if ($test == $basis) {
                $exploded = explode('-', date('m-d-Y', $new_time));
                return array(intval($exploded[0]), intval($exploded[1]), intval($exploded[2]));
            }
        }
    }
    return array(NULL, NULL, NULL);
}
예제 #2
0
 /**
  * The calendar area view for viewing a single month.
  *
  * @param  string			The month we are viewing
  * @param  string			The day (Y-m-d) we are viewing
  * @param  array			List of components of our viewed ID
  * @param  MEMBER			The member ID we are viewing as
  * @param  ?array			The type filter (NULL: none)
  * @return tempcode		The UI
  */
 function view_calendar_view_month($view_id, $day, $explode, $member_id, $filter)
 {
     $period_start = mktime(0, 0, 0, intval($explode[1]), 1, intval($explode[0]));
     $period_end = mktime(0, 0, 0, intval($explode[1]) + 1, 1, intval($explode[0]));
     $_days = intval(round(floatval($period_end - $period_start) / floatval(60 * 60 * 24)));
     if ($_days == 0) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $happenings = calendar_matches($member_id, true, $period_start, $period_end, $filter);
     global $M_SORT_KEY;
     $M_SORT_KEY = 0;
     usort($happenings, 'multi_sort');
     if (get_option('ssw') == '0') {
         $ex_array = array('Mon' => 0, 'Tue' => 1, 'Wed' => 2, 'Thu' => 3, 'Fri' => 4, 'Sat' => 5, 'Sun' => 6);
     } else {
         $ex_array = array('Sun' => 0, 'Mon' => 1, 'Tue' => 2, 'Wed' => 3, 'Thu' => 4, 'Fri' => 5, 'Sat' => 6);
     }
     $empty_entry = do_template('CALENDAR_MONTH_ENTRY_FREE', array('_GUID' => 'c8eba771bd5f9a58d4822f4a2dac57a2', 'CLASS' => 'spacer', 'TEXT' => ''));
     $weeks = new ocp_tempcode();
     $days = new ocp_tempcode();
     $week_date = locale_filter(date(do_lang('calendar_day_of_month'), $period_start));
     $week_count = intval(get_week_number_for($period_start, true));
     $day_of_week = date('D', $period_start);
     for ($x = 0; $x < $ex_array[$day_of_week]; $x++) {
         $days->attach(do_template('CALENDAR_MONTH_DAY', array('_GUID' => '783ff6377292cc0400638c8857446a16', 'CURRENT' => false, 'DAY_URL' => '', 'CLASS' => '', 'DAY' => '', 'ENTRIES' => $empty_entry)));
     }
     $dotw = $ex_array[$day_of_week] - 1;
     for ($i = 1; $i <= $_days; $i++) {
         $entries = new ocp_tempcode();
         $timestamp = $period_start + ($i - 1) * 60 * 60 * 24 + 60 * 60;
         $day_of_week = date('D', $timestamp);
         if ($dotw == 6) {
             $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'week', 'id' => $explode[0] . '-' . strval($week_count)));
             if (get_param_integer('member_id', get_member()) != get_member()) {
                 $map['member_id'] = get_param_integer('member_id');
             }
             $week_url = build_url($map, '_SELF');
             $weeks->attach(do_template('CALENDAR_MONTH_WEEK', array('_GUID' => '1010b12d8677bc577f30a013e9a838ce', 'WEEK_URL' => $week_url, 'WEEK_DATE' => $week_date, 'DAYS' => $days)));
             $days = new ocp_tempcode();
             $week_date = locale_filter(date(do_lang('calendar_day_of_month'), $period_start + ($i - 1) * 60 * 60 * 24));
             $week_count++;
             $dotw = 0;
         } else {
             $dotw++;
         }
         $class = '';
         $worst_priority = 6;
         $cnt = count($happenings);
         for ($hap_i = 0; $hap_i < $cnt; $hap_i++) {
             $happening = $happenings[$hap_i];
             list($e_id, $event, $from, $to, $real_from, $real_to, $utc_real_from) = $happening;
             $date = date('d', $from);
             if (intval($date) == $i) {
                 $date = is_null($event['e_start_hour']) ? '' : locale_filter(my_strftime(do_lang('calendar_minute'), $real_from));
                 if (is_numeric($e_id)) {
                     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'view', 'id' => $event['e_id'], 'day' => date('Y-m-d', $utc_real_from), 'date' => $view_id, 'back' => 'month'));
                     if (get_param_integer('member_id', get_member()) != get_member()) {
                         $map['member_id'] = get_param_integer('member_id');
                     }
                     $url = build_url($map, '_SELF');
                 } else {
                     $url = $e_id;
                 }
                 $icon = $event['t_logo'];
                 if (!is_null($to)) {
                     $date = date_range($real_from, $real_to, !is_null($event['e_start_hour']));
                 }
                 $title = is_integer($event['e_title']) ? get_translated_text($event['e_title']) : $event['e_title'];
                 $entries->attach(do_template('CALENDAR_MONTH_ENTRY', array('_GUID' => '58353fc64595f981d41da303cfe40855', 'ID' => is_string($event['e_id']) ? $event['e_id'] : strval($event['e_id']), 'T_TITLE' => array_key_exists('t_title', $event) ? is_string($event['t_title']) ? $event['t_title'] : get_translated_text($event['t_title']) : 'RSS', 'PRIORITY' => strval($event['e_priority']), 'ICON' => $icon, 'TIME' => $date, 'TITLE' => $title, 'URL' => $url, 'RECURRING' => $event['e_recurrence'] != 'none')));
                 if ($event['e_priority'] < $worst_priority) {
                     $worst_priority = $event['e_priority'];
                     $class = 'priority_' . strval($event['e_priority']);
                 }
                 if (!is_null($to)) {
                     $test = date('d', $to);
                     $test2 = date('d', $from);
                     if (intval($test) > intval($test2) || intval(date('m', $to)) != intval(date('m', $from)) || intval(date('Y', $to)) != intval(date('Y', $from))) {
                         $ntime = mktime(0, 0, 0, intval(date('m', $from)), intval($test2) + 1, intval(date('Y', $from)));
                         if ($ntime < $period_end) {
                             $happenings[] = array($e_id, $event, $ntime, $to, $real_from, $real_to, $utc_real_from);
                         }
                     }
                 }
             }
         }
         if ($entries->is_empty()) {
             $class = 'free_time';
             $text = '&nbsp;';
             $entries = do_template('CALENDAR_MONTH_ENTRY_FREE', array('_GUID' => 'a5e193c8c14deb17ac629e0de74458a2', 'CLASS' => $class, 'TEXT' => $text));
         }
         $day_url = build_url(array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $explode[0] . '-' . $explode[1] . '-' . str_pad(strval($i), 2, '0', STR_PAD_LEFT)), '_SELF');
         $days->attach(do_template('CALENDAR_MONTH_DAY', array('_GUID' => '44162c09e0647888cf079c0ac78c1912', 'CURRENT' => date('Y-m-d') == date('Y-m-d', $timestamp), 'DAY_URL' => $day_url, 'CLASS' => $class, 'DAY' => strval($i), 'ENTRIES' => $entries)));
     }
     $ex_array = array_flip(array_reverse(array_flip($ex_array)));
     for ($x = 0; $x < $ex_array[$day_of_week]; $x++) {
         $days->attach(do_template('CALENDAR_MONTH_DAY', array('_GUID' => '3a34ca72f31d9244b9eb642814836736', 'CURRENT' => false, 'DAY_URL' => '', 'CLASS' => '', 'DAY' => '', 'ENTRIES' => $empty_entry)));
     }
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'week', 'id' => $explode[0] . '-' . strval($week_count)));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $week_url = build_url($map, '_SELF');
     $weeks->attach(do_template('CALENDAR_MONTH_WEEK', array('_GUID' => '0fc7a1691b3cb081d80519a2fe666849', 'WEEK_URL' => $week_url, 'WEEK_DATE' => $week_date, 'DAYS' => $days)));
     return do_template('CALENDAR_MONTH', array('_GUID' => '2ada774f9eb9524db1bed9bea440e5d1', 'WEEKS' => $weeks, 'PERIOD_START' => strval($period_start), 'PERIOD_END' => strval($period_end)));
 }