conditions[$key]); } else { if ($key === 'callback') { } elseif (in_array($key, $this->booleans)) { $value = (bool) $value; } else { $value = (int) $value; } $this->conditions[$key] = $value; } return $this; } public function add_class($class) { $this->classes[$class] = $class; return $this; } public function remove_class($class) { unset($this->classes[$class]); return $this; } public function output($str) { $this->output = $str; return $this; } public function notify($data) { list ($month, $day, $year, $week, $current) = $data; $timestamp = mktime(0, 0, 0, $month, $day, $year); $condition = array ( 'timestamp' => (int) $timestamp, 'day' => (int) date('j', $timestamp), 'week' => (int) $week, 'month' => (int) date('n', $timestamp), 'year' => (int) date('Y', $timestamp), 'day_of_week' => (int) date('w', $timestamp), 'current' => (bool) $current, ); $tested = array(); foreach ($condition as $key => $value) { if($key === 'timestamp' AND isset($this->conditions['timestamp'])) { $next_day = $timestamp + 86399; if($this->conditions['timestamp'] < $timestamp OR $this->conditions['timestamp'] > $next_day) return FALSE; } elseif (isset($this->conditions[$key]) AND $this->conditions[$key] !== $value) return FALSE; $tested[$key] = TRUE; } if (isset($this->conditions['weekend'])) { $condition['weekend'] = ($condition['day_of_week'] === 0 OR $condition['day_of_week'] === 6); } if (isset($this->conditions['first_day'])) { $condition['first_day'] = ($condition['day'] === 1); } if (isset($this->conditions['last_day'])) { $condition['last_day'] = ($condition['day'] === (int) date('t', $timestamp)); } if (isset($this->conditions['occurrence'])) { $condition['occurrence'] = $this->day_occurrence($timestamp); } if (isset($this->conditions['last_occurrence'])) { $condition['last_occurrence'] = ((int) date('n', $timestamp + 604800) !== $condition['month']); } if (isset($this->conditions['easter'])) { if ($condition['month'] === 3 OR $condition['month'] === 4) { $a = $condition['year'] % 19; $b = (int) ($condition['year'] / 100); $c = $condition['year'] % 100; $d = (int) ($b / 4); $e = $b % 4; $f = (int) (($b + 8) / 25); $g = (int) (($b - $f + 1) / 3); $h = (19 * $a + $b - $d - $g + 15) % 30; $i = (int) ($c / 4); $k = $c % 4; $l = (32 + 2 * $e + 2 * $i - $h - $k) % 7; $m = (int) (($a + 11 * $h + 22 * $l) / 451); $p = ($h + $l - 7 * $m + 114) % 31; $month = (int) (($h + $l - 7 * $m + 114) / 31); $day = $p + 1; $condition['easter'] = ($condition['month'] === $month AND $condition['day'] === $day); } else { $condition['easter'] = FALSE; } } if (isset($this->conditions['callback'])) { $condition['callback'] = call_user_func($this->conditions['callback'], $condition, $this); } $conditions = array_diff_key($this->conditions, $tested); foreach ($conditions as $key => $value) { if ($key === 'callback') { $value = TRUE; } if ($condition[$key] !== $value) return FALSE; } $this->caller->add_data(array ( 'classes' => $this->classes, 'output' => $this->output, )); } protected function day_occurrence($timestamp) { $month = date('m', $timestamp); $occurrence = 1; while ($timestamp -= 604800) { if (date('m', $timestamp) !== $month) { return $occurrence; } $occurrence++; } } }