PEAK XOOPS - Hack 1 Summertime/Wintertime fix in englishin japanese

Hack 1 Summertime/Wintertime fix

List posts in the topic

question Hack 1 Summertime/Wintertime fix

msg# 1.1
depth:
1
Previous post - Next post | Parent - Children.1 .2 .3 | Posted on 2004/8/30 15:40
AZNative  一等兵 From: Phoenix, Arizona, USA  Posts: 12
NOTE: This hack only works with MySql as it uses the UNIX_TIMESTAMP method to do the inserts. You implement this code at your own risk

Since there were a lot of lines changed, here is what you need to do to implement this hack.

Open piCal.php and do a search for the function
function rrule_extract(
This is the very last function defined in the file, so if you can't find it by doing a search, just go to the bottom of the file and look for it around line 3320.

Remove the entire function and replace it with the following:

function rrule_extract ($event_id) {
  $yrs = mysql_query ("SELECT *,TO_DAYS(end_date)-TO_DAYS(start_date) AS date_diff FROM $this->table WHERE id='$event_id'", $this->conn);

  if (mysql_num_rows($yrs) < 1) return;
 
  $event = mysql_fetch_object($yrs);

  if($event->rrule == '') return;

  $rrule = strtoupper($event->rrule);
  $rules = split( ';' , $rrule );

  foreach( $rules as $rule ) {
    list($key, $val) = explode('=', $rule, 2);
    $key = trim($key);
    $$key = trim($val);
  }

  if (empty($FREQ)) $FREQ = 'DAILY';

  if (empty($INTERVAL) || $INTERVAL <= 0) $INTERVAL = 1;

  $base_sql = "INSERT INTO $this->table SET uid='$event->uid',groupid='$event->groupid',summary='".addslashes($event->summary)."',location='".addslashes($event->location)."',organizer='".addslashes($event->organizer)."',sequence='$event->sequence',contact='".addslashes($event->contact)."',tzid='$event->tzid',description='".addslashes($event->description)."',dtstamp='$event->dtstamp',categories='".addslashes($event->categories)."',transp='$event->transp',priority='$event->priority',admission='$event->admission',class='$event->class',rrule='".addslashes($event->rrule)."',unique_id='$event->unique_id',allday='$event->allday',start_date=null,end_date=null,cid='$event->cid',event_tz='$event->event_tz',server_tz='$event->server_tz',poster_tz='$event->poster_tz',extkey0='$event->extkey0',extkey1='$event->extkey1',rrule_pid='$event_id'";

  $count = $this->max_rrule_extract;

  if (isset($COUNT) && $COUNT > 0 && $COUNT < $count) {
    $count = $COUNT;
  }

  if (isset($UNTIL)) {
    $year = substr($UNTIL, 0, 4);
    $month = substr($UNTIL, 4, 2);
    $date = substr($UNTIL, 6, 2);

    if (! checkdate($month, $date, $year)) {
      $until = 0x7FFFFFFF;
    } else {
      $until = mktime( 23 , 59 , 59 , $month , $date , $year, 0 ) ;
   
      if (! $event->allday) {
        $until -= intval($tzoffset_date * 86400);
      }
    }
  } else {
    $until = 0x7FFFFFFF ;
  }

  // WKST
  if (empty($WKST)) {
    $WKST = 'MO';
  }

  // UnixTimestamp範囲外の処理
  if (isset($event->start_date)) {

    if (date('Y', $event->start) >= 2038) {
      return;
    }

    if (date('Y', $event->end ) >= 2038) {
      return;
    }

    // 1971
    $event->start = mktime(0, 0, 0, substr($event->start_date, 5 ,2), substr($event->start_date, 8, 2), 1970 + 1);

    // end 1970
    if (isset($event->end_date)) {
      $event->end = $event->start + ($event->date_diff + 1) * 86400;
    }
  }

  $sqls = array();

  switch ($FREQ) {

    case 'DAILY':

      $start = gmmktime(date("H", $event->start), date("i", $event->start), date("s", $event->start), date("m", $event->start), date("d", $event->start), date("Y", $event->start) ) ;
      $end = gmmktime(date("H", $event->end), date("i", $event->end), date("s", $event->end), date("m", $event->end), date("d", $event->end), date("Y", $event->end) ) ;

      for($c = 1; $c < $count; $c ++) {
        $start += $INTERVAL * 86400;
        $end += $INTERVAL * 86400;

        if($start > $until) {
          break;
        } 

        $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')";
      }

      break;
			
    case 'WEEKLY':

      $start = gmmktime( date("H", $event->start), date("i", $event->start), date("s", $event->start), date("m", $event->start), date("d", $event->start), date("Y", $event->start) ) ;
      $end = gmmktime( date("H", $event->end), date("i", $event->end), date("s", $event->end), date("m", $event->end), date("d", $event->end), date("Y", $event->end) ) ;

      $duration = $end - $start;
      $wtop_date = gmdate('j', $start) - gmdate('w', $start);

      if ($WKST != 'SU') {
        $wtop_date = $wtop_date == 7 ? 1 : $wtop_date + 1;
      }

      $secondofday = (gmdate('Z') + $start) % 86400;
      $month = gmdate('m', $start);
      $year  = gmdate('Y', $start);
      $week_top = gmmktime(0, 0, 0, $month, $wtop_date, $year);
      $c = 1;

      $temp_dates = explode(',', $BYDAY);
      $wdays = array_keys($this->byday2langday_w);

      if($WKST != 'SU') {
        // rotate wdays for creating array stating with Monday
        $sun_date = array_shift( $wdays);
        array_push($wday , $sun_date);
      }

      $dates = array();
      foreach ($temp_dates as $date) {

        // measure for bug of PHP<4.2.0
        if( in_array($date, $wdays)) {
          $dates[] = array_search($date, $wdays);
        }
      }

      sort($dates);
      $dates = array_unique($dates);

      if (! count($dates)) {
        return;
      }

      while (1) {
        foreach ($dates as $date) {
          $start = $week_top + ($date - $tzoffset_date) * 86400 + $secondofday;

          if($start <= $event->start) {
            continue;
          }

          $end = $start + $duration;

          if($start > $until) {
            break 2;
          }
          if(++ $c > $count) {
            break 2;
          }

          $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
        }

        $week_top += $INTERVAL * 86400 * 7 ;
      }

      break;
			
    case 'MONTHLY':

      $start = $event->start;
      $secondofday = (date('Z') + $start) % 86400;
      $duration = $event->end - $event->start;
      $month = date('m', $start);
      $year = date('Y', $start);
      $c = 1;

      if (isset($BYDAY) && ereg('^(-1|[1-4])(SU|MO|TU|WE|TH|FR|SA)', $BYDAY, $regs)) {
        $wdays = array_keys($this->byday2langday_w);
        $wday = array_search($regs[2], $wdays);
        $first_ymw = gmdate('Ym', $start) . intval((date('j', $start) - 1) / 7);

        if ($regs[1] == -1) {
          $monthday_bottom = gmmktime(0, 0, 0, $month + 1, 0, $year);

          while (1) {
            for ($i = 0; $i < $INTERVAL; $i ++) {
              $monthday_bottom += gmdate('t', $monthday_bottom + 86400) * 86400;
            }

            $last_monthdays_wday = gmdate('w', $monthday_bottom);
            $date_back = $wday - $last_monthdays_wday;

            if ($date_back > 0) {
              $date_back -= 7;
            }

            $start = $monthday_bottom + ($date_back - $tzoffset_date) * 86400 + $secondofday;
            $end = $start + $duration;

            if ($start > $unti ) {
              break;
            }

            if(++ $c > $count) {
              break;
            }

            // echo date( "Y-m-d" , $start ) . "<br />" ;
            $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
          }
        } else {

          $monthday_top = gmmktime(0, 0, 0, $month, 1, $year);
          $week_number_offset = ($regs[1] - 1) * 7 * 86400;

          while (1) {
            for ($i = 0; $i < $INTERVAL; $i ++) {
              $monthday_top += gmdate('t', $monthday_top) * 86400;
            }


            $week_numbers_top_wday = gmdate('w', $monthday_top + $week_number_offset);
            $date_ahead = $wday - $week_numbers_top_wday;

            if ($date_ahead < 0) {
              $date_ahead += 7;
            }

            $start = $monthday_top + $week_number_offset + ($date_ahead - $tzoffset_date) * 86400 + $secondofday;
            $end = $start + $duration ;

            if ($start > $until) {
              break;
            }

            if (++ $c > $count) {
              break;
            }

            // echo date( "Y-m-d" , $start ) . "<br />" ;
            $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
          }
        }
      } else if (isset($BYMONTHDAY)) {

        $monthday_top = gmmktime(0, 0, 0, $month, 1, $year);
        $temp_dates = explode(',', $BYMONTHDAY);
        $dates = array();

        foreach ($temp_dates as $date) {
          if ($date > 0 && $date <= 31) {
            $dates[] = intval($date);
          }
        }
        sort($dates);
        $dates = array_unique($dates);

        if (! count($dates)) {
          return;
        }

        while (1) {
          $months_day = gmdate('t', $monthday_top);

          foreach ($dates as $date) {
            if ($date > $months_day) {
              $date = $months_day;
            }

            $start = $monthday_top + ($date - 1 - $tzoffset_date) * 86400 + $secondofday;

            if ($start <= $event->start) {
              continue;
            }

            $end = $start + $duration;

            if ($start > $until) {
              break 2;
            }
            if (++ $c > $count) {
              break 2;
            }

            // echo date( "Y-m-d" , $start ) . "<br />" ;
            $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
          }

          for ($i = 0; $i < $INTERVAL; $i ++) {
            $monthday_top += gmdate('t', $monthday_top) * 86400;
          }
        }
      } else {
        return;
      }

      break;
			
    case 'YEARLY':

      $start = gmmktime( date("H", $event->start), date("i", $event->start), date("s", $event->start), date("m", $event->start), date("d", $event->start), date("Y", $event->start) ) ;
      $end = gmmktime(date("H", $event->end), date("i", $event->end), date("s", $event->end), date("m", $event->end), date("d", $event->end), date("Y", $event->end) ) ;
      $secondofday = (gmdate('Z') + $start) % 86400;
      $duration = $end - $start;

      // BYMONTH を前処理して、$months配列にする(BYMONTHは複数可)
      $temp_months = explode(',', $BYMONTH );
      $months = array();

      foreach ($temp_months as $month) {
        if ($month > 0 && $month <= 12) {
          $months[] = intval( $month );
        }
      }

      sort( $months ) ;
      $months = array_unique( $months ) ;

      if (! count($months)) {
        return;
      }

      if (isset($BYDAY) && ereg('^(-1|[1-4])(SU|MO|TU|WE|TH|FR|SA)', $BYDAY, $regs)) {
        $wdays = array_keys($this->byday2langday_w);
	$wday = array_search($regs[2], $wdays);
        $first_ym = gmdate('Ym', $start );
        $year = gmdate('Y', $start );
        $c = 1;

        if ($regs[1] == -1) {

          while (1) {

            foreach ($months as $month) {

              $last_monthdays_wday = gmdate('w', mktime(0, 0, 0, $month + 1, 0, $year));
              $date_back = $wday - $last_monthdays_wday;

              if ($date_back > 0) {
                $date_back -= 7;
              }

              $start = gmmktime(0, 0, 0, $month + 1, $date_back - $tzoffset_date, $year) + $secondofday;

              if (gmdate('Ym', $start) <= $first_ym) {
                continue;
              }

              $end = $start + $duration ;

              if ($start > $until) {
                break 2;
              }

              if (++ $c > $count) {
                break 2;
              }

              // echo date( "Y-m-d" , $start ) . "<br />" ;
              $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
            }

            $year += $INTERVAL;

            if ($year >= 2038) {
              break;
            }
          }
        } else {

          $week_numbers_top_date = 1 + ($regs[1] - 1) * 7;

          while (1) {

            foreach ($months as $month) {
              $week_numbers_top_wday = gmdate('w', gmmktime(0, 0, 0, $month, $week_numbers_top_date, $year));
              $date_ahead = $wday - $week_numbers_top_wday;

              if ($date_ahead < 0) {
                $date_ahead += 7;
              }

              $start = gmmktime(0, 0, 0, $month, $week_numbers_top_date + $date_ahead - $tzoffset_date, $year) + $secondofday;

              if (date('Ym', $start) <= $first_ym) {
                continue;
              }

              $end = $start + $duration;

              if ($start > $until) {
                break 2;
              }

              if (++ $c > $count) {
                break 2;
              }

              // echo date( "Y-m-d" , $start ) . "<br />" ;
              $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
            }

            $year += $INTERVAL;

            if ($year >= 2038) {
              break;
            }
          }
        }
      } else {

        $first_date = gmdate('j', $start);
        $year = gmdate('Y', $start);
        $c = 1 ;

        while (1) {

          foreach($months as $month) {
            $date = $first_date ;

            while (! checkdate($month, $date, $year ) && $date > 0) {
              $date -- ;
            }

            $start = gmmktime(0, 0, 0, $month, $date, $year, 0) + $secondofday;

            if ($start <= $event->start) {
              continue;
            }

            $end = $start + $duration ;

            if ($start > $until) {
              break 2;
            }

            if (++ $c > $count) {
              break 2;
            }

            // echo date( "Y-m-d" , $start ) . "<br />" ;
            $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $start)."'),end=UNIX_TIMESTAMP('".gmdate("Y-m-d H:i:s", $end)."')" ;
          }

          $year += $INTERVAL;

          if ($year >= 2038) {
            break;
          }
	}
      }

      break;
			
    default:
      return;

  }

  // echo "<pre>" ; print_r( $sqls ) ; echo "</pre>" ; exit ;
  foreach ($sqls as $sql) {
    mysql_query($sql, $this->conn);
  }
} // END FUNCTION

Votes:2 Average:0.00

Posts tree

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!