public static function repeats($meta, $year, $month, $week, $start, $end, $id, $elements, $repeated = 0) { $settings = unserialize(get_option("chronosly-settings")); $pos = Post_Type_Chronosly_Calendar::get_event_position_by_hour($meta, $id); if (isset($meta["ev-repeat"][0]) and $meta["ev-repeat"][0] != "" and isset($meta["ev-repeat-every"][0]) and $meta["ev-repeat-every"][0] > 0) { if (!$month and !$week) { if ($repeated) { $start_min = strtotime("01-01-" . $year); } //start building array $end_top = strtotime("31-12-" . $year); //limit of repeats per year if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "until" and isset($meta["ev-until"][0]) and strtotime($meta["ev-until"][0]) < $end_top) { $end_top = strtotime($meta["ev-until"][0]); } } else { if ($week) { if ($repeated) { $start_min = strtotime($year . "W" . str_pad($week, 2, '0', STR_PAD_LEFT)); } //start building array $end_top = strtotime($year . "W" . str_pad($week + 1, 2, '0', STR_PAD_LEFT) . " -1 day"); //limit of repeats per week if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "until" and isset($meta["ev-until"][0]) and strtotime($meta["ev-until"][0]) < $end_top) { $end_top = strtotime($meta["ev-until"][0]); } // if($settings["chronosly_week_start"] == 1) { // // $start_min -= (60*60*24); // // $end_top -= (60*60*24); // } } else { if ($month) { if ($repeated) { $start_min = strtotime("01-{$month}-{$year}"); } //start building array $end_top = strtotime(date("Y-m-t", strtotime($year . "-" . $month))); //limit of repeats per month if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "until" and isset($meta["ev-until"][0]) and strtotime($meta["ev-until"][0]) < $end_top) { $end_top = strtotime($meta["ev-until"][0]); } } } } if ($repeated and $start_min > $end_top) { return $elements; } else { if (!$repeated and $start > $end_top) { return $elements; } } $count = -1; //for count repetitions if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "count" and isset($meta["ev-end_count"][0]) and $meta["ev-end_count"][0] > 0) { $count = $meta["ev-end_count"][0]; } $distance = $meta["ev-repeat-every"][0]; //distance between repeats $event_days = $end - $start; // event days duration switch ($meta["ev-repeat"][0]) { case "day": $start = $end; while ($start < $end_top and $count) { //mientras no estemos en el tope superior $start += $distance * 60 * 60 * 24; //añadimos la distancia de dias $start1 = $start; $end = $start + $event_days; //recalculamos el final --$count; while ($start <= $end and $start <= $end_top) { //rellenamos los dias de este tramo if ($start >= $start_min and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) { $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end); } $start = strtotime("+ 1 day", $start); //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; } $start = strtotime("- 1 day", $start); //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle } break; case "week": $start = $end; while ($start < $end_top and $count) { //mientras no estemos en el tope superior $start += $distance * 7 * 60 * 60 * 24 - $event_days; //añadimos la distancia de semanas, restando los dias que dura el evento...si el evento dura mas de una semana es un total absurdo usarlo $start1 = $start; $end = $start + $event_days; //recalculamos el final --$count; //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; while ($start <= $end and $start <= $end_top) { //rellenamos los dias de este tramo if ((!$repeated or $start >= $start_min) and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) { $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end); } $start = strtotime("+ 1 day", $start); //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; } $start = strtotime("- 1 day", $start); //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle } break; case "month": $start = $end; while ($start < $end_top and $count) { //mientras no estemos en el tope superior $start = strtotime("+{$distance} month", $start) - $event_days; //añadimos la distancia de semanas, restando los dias que dura el evento...si el evento dura mas de una semana es un total absurdo usarlo $start1 = $start; $end = $start + $event_days; //recalculamos el final --$count; //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; while ($start <= $end and $start <= $end_top) { //rellenamos los dias de este tramo if ((!$repeated or $start >= $start_min) and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) { $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end); } $start = strtotime("+ 1 day", $start); //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; } $start = strtotime("- 1 day", $start); //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle } break; case "year": $start = $end; while ($start < $end_top and $count) { //mientras no estemos en el tope superior $start = strtotime("+{$distance} year", $start) - $event_days; //añadimos la distancia de semanas, restando los dias que dura el evento...si el evento dura mas de una semana es un total absurdo usarlo $start1 = $start; $end = $start + $event_days; //recalculamos el final --$count; //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; while ($start <= $end and $start <= $end_top) { //rellenamos los dias de este tramo if ((!$repeated or $start >= $start_min) and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) { $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end); } $start = strtotime("+ 1 day", $start); //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>"; } $start = strtotime("- 1 day", $start); //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle } break; } } return $elements; }