fix merge conflicts
commit
361d4ac13b
Binary file not shown.
|
Before Width: | Height: | Size: 742 B After Width: | Height: | Size: 3.9 KiB |
@ -1 +1 @@
|
||||
0.9.1
|
||||
0.9.5
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,9 @@
|
||||
License
|
||||
|
||||
Copyright (c) 2010 Thomas Planer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@ -0,0 +1,725 @@
|
||||
<?php
|
||||
/**
|
||||
* Name: When
|
||||
* Author: Thomas Planer <tplaner@gmail.com>
|
||||
* Location: http://github.com/tplaner/When
|
||||
* Created: September 2010
|
||||
* Description: Determines the next date of recursion given an iCalendar "rrule" like pattern.
|
||||
* Requirements: PHP 5.3+ - makes extensive use of the Date and Time library (http://us2.php.net/manual/en/book.datetime.php)
|
||||
*/
|
||||
class When
|
||||
{
|
||||
protected $frequency;
|
||||
|
||||
protected $start_date;
|
||||
protected $try_date;
|
||||
|
||||
protected $end_date;
|
||||
|
||||
protected $gobymonth;
|
||||
protected $bymonth;
|
||||
|
||||
protected $gobyweekno;
|
||||
protected $byweekno;
|
||||
|
||||
protected $gobyyearday;
|
||||
protected $byyearday;
|
||||
|
||||
protected $gobymonthday;
|
||||
protected $bymonthday;
|
||||
|
||||
protected $gobyday;
|
||||
protected $byday;
|
||||
|
||||
protected $gobysetpos;
|
||||
protected $bysetpos;
|
||||
|
||||
protected $suggestions;
|
||||
|
||||
protected $count;
|
||||
protected $counter;
|
||||
|
||||
protected $goenddate;
|
||||
|
||||
protected $interval;
|
||||
|
||||
protected $wkst;
|
||||
|
||||
protected $valid_week_days;
|
||||
protected $valid_frequency;
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->frequency = null;
|
||||
|
||||
$this->gobymonth = false;
|
||||
$this->bymonth = range(1,12);
|
||||
|
||||
$this->gobymonthday = false;
|
||||
$this->bymonthday = range(1,31);
|
||||
|
||||
$this->gobyday = false;
|
||||
// setup the valid week days (0 = sunday)
|
||||
$this->byday = range(0,6);
|
||||
|
||||
$this->gobyyearday = false;
|
||||
$this->byyearday = range(0,366);
|
||||
|
||||
$this->gobysetpos = false;
|
||||
$this->bysetpos = range(1,366);
|
||||
|
||||
$this->gobyweekno = false;
|
||||
// setup the range for valid weeks
|
||||
$this->byweekno = range(0,54);
|
||||
|
||||
$this->suggestions = array();
|
||||
|
||||
// this will be set if a count() is specified
|
||||
$this->count = 0;
|
||||
// how many *valid* results we returned
|
||||
$this->counter = 0;
|
||||
|
||||
// max date we'll return
|
||||
$this->end_date = new DateTime('9999-12-31');
|
||||
|
||||
// the interval to increase the pattern by
|
||||
$this->interval = 1;
|
||||
|
||||
// what day does the week start on? (0 = sunday)
|
||||
$this->wkst = 0;
|
||||
|
||||
$this->valid_week_days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
|
||||
|
||||
$this->valid_frequency = array('SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime|string $start_date of the recursion - also is the first return value.
|
||||
* @param string $frequency of the recrusion, valid frequencies: secondly, minutely, hourly, daily, weekly, monthly, yearly
|
||||
*/
|
||||
public function recur($start_date, $frequency = "daily")
|
||||
{
|
||||
try
|
||||
{
|
||||
if(is_object($start_date))
|
||||
{
|
||||
$this->start_date = clone $start_date;
|
||||
}
|
||||
else
|
||||
{
|
||||
// timestamps within the RFC have a 'Z' at the end of them, remove this.
|
||||
$start_date = trim($start_date, 'Z');
|
||||
$this->start_date = new DateTime($start_date);
|
||||
}
|
||||
|
||||
$this->try_date = clone $this->start_date;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid start date DateTime: ' . $e);
|
||||
}
|
||||
|
||||
$this->freq($frequency);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function freq($frequency)
|
||||
{
|
||||
if(in_array(strtoupper($frequency), $this->valid_frequency))
|
||||
{
|
||||
$this->frequency = strtoupper($frequency);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid frequency type.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// accepts an rrule directly
|
||||
public function rrule($rrule)
|
||||
{
|
||||
// strip off a trailing semi-colon
|
||||
$rrule = trim($rrule, ";");
|
||||
|
||||
$parts = explode(";", $rrule);
|
||||
|
||||
foreach($parts as $part)
|
||||
{
|
||||
list($rule, $param) = explode("=", $part);
|
||||
|
||||
$rule = strtoupper($rule);
|
||||
$param = strtoupper($param);
|
||||
|
||||
switch($rule)
|
||||
{
|
||||
case "FREQ":
|
||||
$this->frequency = $param;
|
||||
break;
|
||||
case "UNTIL":
|
||||
$this->until($param);
|
||||
break;
|
||||
case "COUNT":
|
||||
$this->count($param);
|
||||
break;
|
||||
case "INTERVAL":
|
||||
$this->interval($param);
|
||||
break;
|
||||
case "BYDAY":
|
||||
$params = explode(",", $param);
|
||||
$this->byday($params);
|
||||
break;
|
||||
case "BYMONTHDAY":
|
||||
$params = explode(",", $param);
|
||||
$this->bymonthday($params);
|
||||
break;
|
||||
case "BYYEARDAY":
|
||||
$params = explode(",", $param);
|
||||
$this->byyearday($params);
|
||||
break;
|
||||
case "BYWEEKNO":
|
||||
$params = explode(",", $param);
|
||||
$this->byweekno($params);
|
||||
break;
|
||||
case "BYMONTH":
|
||||
$params = explode(",", $param);
|
||||
$this->bymonth($params);
|
||||
break;
|
||||
case "BYSETPOS":
|
||||
$params = explode(",", $param);
|
||||
$this->bysetpos($params);
|
||||
break;
|
||||
case "WKST":
|
||||
$this->wkst($param);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//max number of items to return based on the pattern
|
||||
public function count($count)
|
||||
{
|
||||
$this->count = (int)$count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// how often the recurrence rule repeats
|
||||
public function interval($interval)
|
||||
{
|
||||
$this->interval = (int)$interval;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// starting day of the week
|
||||
public function wkst($day)
|
||||
{
|
||||
switch($day)
|
||||
{
|
||||
case 'SU':
|
||||
$this->wkst = 0;
|
||||
break;
|
||||
case 'MO':
|
||||
$this->wkst = 1;
|
||||
break;
|
||||
case 'TU':
|
||||
$this->wkst = 2;
|
||||
break;
|
||||
case 'WE':
|
||||
$this->wkst = 3;
|
||||
break;
|
||||
case 'TH':
|
||||
$this->wkst = 4;
|
||||
break;
|
||||
case 'FR':
|
||||
$this->wkst = 5;
|
||||
break;
|
||||
case 'SA':
|
||||
$this->wkst = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// max date
|
||||
public function until($end_date)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(is_object($end_date))
|
||||
{
|
||||
$this->end_date = clone $end_date;
|
||||
}
|
||||
else
|
||||
{
|
||||
// timestamps within the RFC have a 'Z' at the end of them, remove this.
|
||||
$end_date = trim($end_date, 'Z');
|
||||
$this->end_date = new DateTime($end_date);
|
||||
}
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid end date DateTime: ' . $e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function bymonth($months)
|
||||
{
|
||||
if(is_array($months))
|
||||
{
|
||||
$this->gobymonth = true;
|
||||
$this->bymonth = $months;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function bymonthday($days)
|
||||
{
|
||||
if(is_array($days))
|
||||
{
|
||||
$this->gobymonthday = true;
|
||||
$this->bymonthday = $days;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function byweekno($weeks)
|
||||
{
|
||||
$this->gobyweekno = true;
|
||||
|
||||
if(is_array($weeks))
|
||||
{
|
||||
$this->byweekno = $weeks;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function bysetpos($days)
|
||||
{
|
||||
$this->gobysetpos = true;
|
||||
|
||||
if(is_array($days))
|
||||
{
|
||||
$this->bysetpos = $days;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function byday($days)
|
||||
{
|
||||
$this->gobyday = true;
|
||||
|
||||
if(is_array($days))
|
||||
{
|
||||
$this->byday = array();
|
||||
foreach($days as $day)
|
||||
{
|
||||
$len = strlen($day);
|
||||
|
||||
$as = '+';
|
||||
|
||||
// 0 mean no occurence is set
|
||||
$occ = 0;
|
||||
|
||||
if($len == 3)
|
||||
{
|
||||
$occ = substr($day, 0, 1);
|
||||
}
|
||||
if($len == 4)
|
||||
{
|
||||
$as = substr($day, 0, 1);
|
||||
$occ = substr($day, 1, 1);
|
||||
}
|
||||
|
||||
if($as == '-')
|
||||
{
|
||||
$occ = '-' . $occ;
|
||||
}
|
||||
else
|
||||
{
|
||||
$occ = '+' . $occ;
|
||||
}
|
||||
|
||||
$day = substr($day, -2, 2);
|
||||
switch($day)
|
||||
{
|
||||
case 'SU':
|
||||
$this->byday[] = $occ . 'SU';
|
||||
break;
|
||||
case 'MO':
|
||||
$this->byday[] = $occ . 'MO';
|
||||
break;
|
||||
case 'TU':
|
||||
$this->byday[] = $occ . 'TU';
|
||||
break;
|
||||
case 'WE':
|
||||
$this->byday[] = $occ . 'WE';
|
||||
break;
|
||||
case 'TH':
|
||||
$this->byday[] = $occ . 'TH';
|
||||
break;
|
||||
case 'FR':
|
||||
$this->byday[] = $occ . 'FR';
|
||||
break;
|
||||
case 'SA':
|
||||
$this->byday[] = $occ . 'SA';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function byyearday($days)
|
||||
{
|
||||
$this->gobyyearday = true;
|
||||
|
||||
if(is_array($days))
|
||||
{
|
||||
$this->byyearday = $days;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// this creates a basic list of dates to "try"
|
||||
protected function create_suggestions()
|
||||
{
|
||||
switch($this->frequency)
|
||||
{
|
||||
case "YEARLY":
|
||||
$interval = 'year';
|
||||
break;
|
||||
case "MONTHLY":
|
||||
$interval = 'month';
|
||||
break;
|
||||
case "WEEKLY":
|
||||
$interval = 'week';
|
||||
break;
|
||||
case "DAILY":
|
||||
$interval = 'day';
|
||||
break;
|
||||
case "HOURLY":
|
||||
$interval = 'hour';
|
||||
break;
|
||||
case "MINUTELY":
|
||||
$interval = 'minute';
|
||||
break;
|
||||
case "SECONDLY":
|
||||
$interval = 'second';
|
||||
break;
|
||||
}
|
||||
|
||||
$month_day = $this->try_date->format('j');
|
||||
$month = $this->try_date->format('n');
|
||||
$year = $this->try_date->format('Y');
|
||||
|
||||
$timestamp = $this->try_date->format('H:i:s');
|
||||
|
||||
if($this->gobysetpos)
|
||||
{
|
||||
if($this->try_date == $this->start_date)
|
||||
{
|
||||
$this->suggestions[] = clone $this->try_date;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->gobyday)
|
||||
{
|
||||
foreach($this->bysetpos as $_pos)
|
||||
{
|
||||
$tmp_array = array();
|
||||
$_mdays = range(1, date('t',mktime(0,0,0,$month,1,$year)));
|
||||
foreach($_mdays as $_mday)
|
||||
{
|
||||
$date_time = new DateTime($year . '-' . $month . '-' . $_mday . ' ' . $timestamp);
|
||||
|
||||
$occur = ceil($_mday / 7);
|
||||
|
||||
$day_of_week = $date_time->format('l');
|
||||
$dow_abr = strtoupper(substr($day_of_week, 0, 2));
|
||||
|
||||
// set the day of the month + (positive)
|
||||
$occur = '+' . $occur . $dow_abr;
|
||||
$occur_zero = '+0' . $dow_abr;
|
||||
|
||||
// set the day of the month - (negative)
|
||||
$total_days = $date_time->format('t') - $date_time->format('j');
|
||||
$occur_neg = '-' . ceil(($total_days + 1)/7) . $dow_abr;
|
||||
|
||||
$day_from_end_of_month = $date_time->format('t') + 1 - $_mday;
|
||||
|
||||
if(in_array($occur, $this->byday) || in_array($occur_zero, $this->byday) || in_array($occur_neg, $this->byday))
|
||||
{
|
||||
$tmp_array[] = clone $date_time;
|
||||
}
|
||||
}
|
||||
|
||||
if($_pos > 0)
|
||||
{
|
||||
$this->suggestions[] = clone $tmp_array[$_pos - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->suggestions[] = clone $tmp_array[count($tmp_array) + $_pos];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($this->gobyyearday)
|
||||
{
|
||||
foreach($this->byyearday as $_day)
|
||||
{
|
||||
if($_day >= 0)
|
||||
{
|
||||
$_day--;
|
||||
|
||||
$_time = strtotime('+' . $_day . ' days', mktime(0, 0, 0, 1, 1, $year));
|
||||
$this->suggestions[] = new Datetime(date('Y-m-d', $_time) . ' ' . $timestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$year_day_neg = 365 + $_day;
|
||||
$leap_year = $this->try_date->format('L');
|
||||
if($leap_year == 1)
|
||||
{
|
||||
$year_day_neg = 366 + $_day;
|
||||
}
|
||||
|
||||
$_time = strtotime('+' . $year_day_neg . ' days', mktime(0, 0, 0, 1, 1, $year));
|
||||
$this->suggestions[] = new Datetime(date('Y-m-d', $_time) . ' ' . $timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
// special case because for years you need to loop through the months too
|
||||
elseif($this->gobyday && $interval == "year")
|
||||
{
|
||||
foreach($this->bymonth as $_month)
|
||||
{
|
||||
// this creates an array of days of the month
|
||||
$_mdays = range(1, date('t',mktime(0,0,0,$_month,1,$year)));
|
||||
foreach($_mdays as $_mday)
|
||||
{
|
||||
$date_time = new DateTime($year . '-' . $_month . '-' . $_mday . ' ' . $timestamp);
|
||||
|
||||
// get the week of the month (1, 2, 3, 4, 5, etc)
|
||||
$week = $date_time->format('W');
|
||||
|
||||
if($date_time >= $this->start_date && in_array($week, $this->byweekno))
|
||||
{
|
||||
$this->suggestions[] = clone $date_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($interval == "day")
|
||||
{
|
||||
$this->suggestions[] = clone $this->try_date;
|
||||
}
|
||||
elseif($interval == "week")
|
||||
{
|
||||
$this->suggestions[] = clone $this->try_date;
|
||||
|
||||
if($this->gobyday)
|
||||
{
|
||||
$week_day = $this->try_date->format('w');
|
||||
|
||||
$days_in_month = $this->try_date->format('t');
|
||||
|
||||
$overflow_count = 1;
|
||||
$_day = $month_day;
|
||||
|
||||
$run = true;
|
||||
while($run)
|
||||
{
|
||||
$_day++;
|
||||
if($_day <= $days_in_month)
|
||||
{
|
||||
$tmp_date = new DateTime($year . '-' . $month . '-' . $_day . ' ' . $timestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
//$tmp_month = $month+1;
|
||||
$tmp_date = new DateTime($year . '-' . $month . '-' . $overflow_count . ' ' . $timestamp);
|
||||
$tmp_date->modify('+1 month');
|
||||
$overflow_count++;
|
||||
}
|
||||
|
||||
$week_day = $tmp_date->format('w');
|
||||
|
||||
if($this->try_date == $this->start_date)
|
||||
{
|
||||
if($week_day == $this->wkst)
|
||||
{
|
||||
$this->try_date = clone $tmp_date;
|
||||
$this->try_date->modify('-7 days');
|
||||
$run = false;
|
||||
}
|
||||
}
|
||||
|
||||
if($week_day != $this->wkst)
|
||||
{
|
||||
$this->suggestions[] = clone $tmp_date;
|
||||
}
|
||||
else
|
||||
{
|
||||
$run = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($this->gobyday || $interval == "month")
|
||||
{
|
||||
$_mdays = range(1, date('t',mktime(0,0,0,$month,1,$year)));
|
||||
foreach($_mdays as $_mday)
|
||||
{
|
||||
$date_time = new DateTime($year . '-' . $month . '-' . $_mday . ' ' . $timestamp);
|
||||
|
||||
// get the week of the month (1, 2, 3, 4, 5, etc)
|
||||
$week = $date_time->format('W');
|
||||
|
||||
if($date_time >= $this->start_date && in_array($week, $this->byweekno))
|
||||
{
|
||||
$this->suggestions[] = clone $date_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($this->gobymonth)
|
||||
{
|
||||
foreach($this->bymonth as $_month)
|
||||
{
|
||||
$date_time = new DateTime($year . '-' . $_month . '-' . $month_day . ' ' . $timestamp);
|
||||
|
||||
if($date_time >= $this->start_date)
|
||||
{
|
||||
$this->suggestions[] = clone $date_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->suggestions[] = clone $this->try_date;
|
||||
}
|
||||
|
||||
if($interval == "month")
|
||||
{
|
||||
$this->try_date->modify('last day of ' . $this->interval . ' ' . $interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->try_date->modify($this->interval . ' ' . $interval);
|
||||
}
|
||||
}
|
||||
|
||||
protected function valid_date($date)
|
||||
{
|
||||
$year = $date->format('Y');
|
||||
$month = $date->format('n');
|
||||
$day = $date->format('j');
|
||||
|
||||
$year_day = $date->format('z') + 1;
|
||||
|
||||
$year_day_neg = -366 + $year_day;
|
||||
$leap_year = $date->format('L');
|
||||
if($leap_year == 1)
|
||||
{
|
||||
$year_day_neg = -367 + $year_day;
|
||||
}
|
||||
|
||||
// this is the nth occurence of the date
|
||||
$occur = ceil($day / 7);
|
||||
|
||||
$week = $date->format('W');
|
||||
|
||||
$day_of_week = $date->format('l');
|
||||
$dow_abr = strtoupper(substr($day_of_week, 0, 2));
|
||||
|
||||
// set the day of the month + (positive)
|
||||
$occur = '+' . $occur . $dow_abr;
|
||||
$occur_zero = '+0' . $dow_abr;
|
||||
|
||||
// set the day of the month - (negative)
|
||||
$total_days = $date->format('t') - $date->format('j');
|
||||
$occur_neg = '-' . ceil(($total_days + 1)/7) . $dow_abr;
|
||||
|
||||
$day_from_end_of_month = $date->format('t') + 1 - $day;
|
||||
|
||||
if(in_array($month, $this->bymonth) &&
|
||||
(in_array($occur, $this->byday) || in_array($occur_zero, $this->byday) || in_array($occur_neg, $this->byday)) &&
|
||||
in_array($week, $this->byweekno) &&
|
||||
(in_array($day, $this->bymonthday) || in_array(-$day_from_end_of_month, $this->bymonthday)) &&
|
||||
(in_array($year_day, $this->byyearday) || in_array($year_day_neg, $this->byyearday)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// return the next valid DateTime object which matches the pattern and follows the rules
|
||||
public function next()
|
||||
{
|
||||
// check the counter is set
|
||||
if($this->count !== 0)
|
||||
{
|
||||
if($this->counter >= $this->count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// create initial set of suggested dates
|
||||
if(count($this->suggestions) === 0)
|
||||
{
|
||||
$this->create_suggestions();
|
||||
}
|
||||
|
||||
// loop through the suggested dates
|
||||
while(count($this->suggestions) > 0)
|
||||
{
|
||||
// get the first one on the array
|
||||
$try_date = array_shift($this->suggestions);
|
||||
|
||||
// make sure the date doesn't exceed the max date
|
||||
if($try_date > $this->end_date)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure it falls within the allowed days
|
||||
if($this->valid_date($try_date) === true)
|
||||
{
|
||||
$this->counter++;
|
||||
return $try_date;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we might be out of suggested days, so load some more
|
||||
if(count($this->suggestions) === 0)
|
||||
{
|
||||
$this->create_suggestions();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
function make_array_out_of_xml ($xml){
|
||||
$returnarray = array();
|
||||
$xml = (array)$xml ;
|
||||
foreach ($xml as $property => $value){
|
||||
$value = (array)$value;
|
||||
if(!isset($value[0])){
|
||||
$returnarray[$property] = make_array_out_of_xml($value);
|
||||
}else{
|
||||
$returnarray[$property] = trim($value[0]);
|
||||
}
|
||||
}
|
||||
return $returnarray;
|
||||
}
|
||||
require_once ("../../../lib/base.php");
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('calendar');
|
||||
$l = new OC_L10N('calendar');
|
||||
$lat = $_GET['lat'];
|
||||
$long = $_GET['long'];
|
||||
$geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . '&lng=' . $long);
|
||||
//Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License
|
||||
$geoxml = simplexml_load_string($geolocation);
|
||||
$geoarray = make_array_out_of_xml($geoxml);
|
||||
if(isset($geoarray['timezone']['timezoneId']) && $geoarray['timezone']['timezoneId'] != ''){
|
||||
OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']);
|
||||
$message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']);
|
||||
OC_JSON::success($message);
|
||||
}else{
|
||||
OC_JSON::error();
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(function(position) {
|
||||
$.getJSON(OC.filePath('calendar', 'ajax', 'guesstimezone.php?lat=' + position.coords.latitude + '&long=' + position.coords.longitude + ''),
|
||||
function(data){
|
||||
if (data.status == 'success'){
|
||||
$('#notification').html(data.message);
|
||||
$('#notification').slideDown();
|
||||
window.setTimeout(function(){$('#notification').slideUp();}, 5000);
|
||||
}else{
|
||||
console.log('Can\'t set new timezone.');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -1,7 +1,11 @@
|
||||
../appinfo/app.php
|
||||
../lib/object.php
|
||||
../templates/calendar.php
|
||||
../templates/part.choosecalendar.php
|
||||
../templates/part.choosecalendar.rowfields.php
|
||||
../templates/part.editcalendar.php
|
||||
../templates/part.editevent.php
|
||||
../templates/part.eventinfo.php
|
||||
../templates/part.eventform.php
|
||||
../templates/part.import.php
|
||||
../templates/part.newevent.php
|
||||
../templates/part.choosecalendar.php
|
||||
../js/calendar.js
|
||||
../templates/settings.php
|
||||
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
class OC_Search_Provider_Calendar extends OC_Search_Provider{
|
||||
function search($query){
|
||||
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
|
||||
if(count($calendars)==0 || !OC_App::isEnabled('calendar')){
|
||||
//return false;
|
||||
}
|
||||
$results=array();
|
||||
$searchquery=array();
|
||||
if(substr_count($query, ' ') > 0){
|
||||
$searchquery = explode(' ', $query);
|
||||
}else{
|
||||
$searchquery[] = $query;
|
||||
}
|
||||
foreach($calendars as $calendar){
|
||||
$objects = OC_Calendar_Object::all($calendar['id']);
|
||||
foreach($objects as $object){
|
||||
if(substr_count(strtolower($object['summary']), strtolower($query)) > 0){//$name,$text,$link,$type
|
||||
$results[]=new OC_Search_Result($object['summary'],'','#','Cal.');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
new OC_Search_Provider_Calendar();
|
||||
@ -0,0 +1,9 @@
|
||||
<p id="contacts_details_name" class="contacts_property" data-checksum="<?php echo $_['property']['checksum']; ?>">
|
||||
<?php echo $_['property']['value']; ?>
|
||||
<span style="display:none;" data-use="edit"><img class="svg action" src="<?php echo image_path('', 'actions/rename.svg'); ?>" /></span>
|
||||
</p>
|
||||
<?php if (!isset($_['details'])): ?>
|
||||
<script>
|
||||
$('#leftcontent li.active a').text('<?php echo $_['property']['value']; ?>');
|
||||
</script>
|
||||
<?php endif ?>
|
||||
@ -1,12 +1,17 @@
|
||||
<form id="ldap" action="#" method="post">
|
||||
<fieldset class="personalblock">
|
||||
<legend><strong>LDAP</strong></legend>
|
||||
<p><label for="ldap_host">Host<input type="text" id="ldap_host" name="ldap_host" value="<?php echo $_['ldap_host']; ?>"></label>
|
||||
<label for="ldap_port">Port</label><input type="text" id="ldap_port" name="ldap_port" value="<?php echo $_['ldap_port']; ?>" /></p>
|
||||
<p><label for="ldap_dn">Name</label><input type="text" id="ldap_dn" name="ldap_dn" value="<?php echo $_['ldap_dn']; ?>" />
|
||||
<label for="ldap_password">Password</label><input type="password" id="ldap_password" name="ldap_password" value="<?php echo $_['ldap_password']; ?>" /></p>
|
||||
<p><label for="ldap_base">Base</label><input type="text" id="ldap_base" name="ldap_base" value="<?php echo $_['ldap_base']; ?>" />
|
||||
<label for="ldap_filter">Filter (use %uid placeholder)</label><input type="text" id="ldap_filter" name="ldap_filter" value="<?php echo $_['ldap_filter']; ?>" /></p>
|
||||
<p><label for="ldap_host"><?php echo $l->t('Host');?><input type="text" id="ldap_host" name="ldap_host" value="<?php echo $_['ldap_host']; ?>"></label>
|
||||
<label for="ldap_port"><?php echo $l->t('Port');?></label><input type="text" id="ldap_port" name="ldap_port" value="<?php echo $_['ldap_port']; ?>" /></p>
|
||||
<p><label for="ldap_dn"><?php echo $l->t('Name');?></label><input type="text" id="ldap_dn" name="ldap_dn" value="<?php echo $_['ldap_dn']; ?>" />
|
||||
<label for="ldap_password"><?php echo $l->t('Password');?></label><input type="password" id="ldap_password" name="ldap_password" value="<?php echo $_['ldap_password']; ?>" />
|
||||
<small><?php echo $l->t('Leave both empty for anonymous bind for search, then bind with users credentials.');?></small></p>
|
||||
<p><label for="ldap_base"><?php echo $l->t('Base');?></label><input type="text" id="ldap_base" name="ldap_base" value="<?php echo $_['ldap_base']; ?>" />
|
||||
<label for="ldap_filter"><?php echo $l->t('Filter (use %%uid placeholder)');?></label><input type="text" id="ldap_filter" name="ldap_filter" value="<?php echo $_['ldap_filter']; ?>" /></p>
|
||||
<p><label for="ldap_display_name"><?php echo $l->t('Display Name Field');?></label><input type="text" id="ldap_display_name" name="ldap_display_name" value="<?php echo $_['ldap_display_name']; ?>" />
|
||||
<small><?php echo $l->t('Currently the display name field needs to be the same you matched %%uid against in the filter above, because ownCloud doesn\'t distinguish between user id and user name.');?></small></p>
|
||||
<p><input type="checkbox" id="ldap_tls" name="ldap_tls" value="1"<?php if ($_['ldap_tls']) echo ' checked'; ?>><label for="ldap_tls"><?php echo $l->t('Use TLS');?></label></p>
|
||||
<p><input type="checkbox" id="ldap_nocase" name="ldap_nocase" value="1"<?php if ($_['ldap_nocase']) echo ' checked'; ?>><label for="ldap_nocase"><?php echo $l->t('Case insensitve LDAP server (Windows)');?></label></p>
|
||||
<input type="submit" value="Save" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* @author Frank Karlitschek
|
||||
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class that handels autoupdating of ownCloud
|
||||
*/
|
||||
class OC_Updater{
|
||||
|
||||
/**
|
||||
* Check if a new version is available
|
||||
*/
|
||||
public static function check(){
|
||||
OC_Config::setValue('lastupdatedat',microtime(true));
|
||||
|
||||
$updaterurl='http://apps.owncloud.com/updater.php';
|
||||
$version=OC_Util::getVersion();
|
||||
$version['installed']=OC_Config::getValue( "installedat");
|
||||
$version['updated']=OC_Config::getValue( "lastupdatedat");
|
||||
$version['updatechannel']='stable';
|
||||
$versionstring=implode('x',$version);
|
||||
|
||||
//fetch xml data from updater
|
||||
$url=$updaterurl.'?version='.$versionstring;
|
||||
$xml=@file_get_contents($url);
|
||||
if($xml==FALSE){
|
||||
return array();
|
||||
}
|
||||
$data=@simplexml_load_string($xml);
|
||||
|
||||
$tmp=array();
|
||||
$tmp['version'] = $data->version;
|
||||
$tmp['versionstring'] = $data->versionstring;
|
||||
$tmp['url'] = $data->url;
|
||||
$tmp['web'] = $data->web;
|
||||
|
||||
|
||||
return $tmp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function ShowUpdatingHint(){
|
||||
$data=OC_Updater::check();
|
||||
if(isset($data['version']) and $data['version']<>'') {
|
||||
$txt='<span style="color:#AA0000; font-weight:bold;">'.$data['versionstring'].' is available. Please click <a href="'.$data['web'].'">here</a> for more information</span>';
|
||||
}else{
|
||||
$txt='Your ownCloud is up to date';
|
||||
}
|
||||
return($txt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* do ownCloud update
|
||||
*/
|
||||
public static function doUpdate(){
|
||||
|
||||
//update ownCloud core
|
||||
|
||||
//update all apps
|
||||
|
||||
//update version in config
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue