Skip to content

Commit

Permalink
Add CREATED & LAST-MODIFIED
Browse files Browse the repository at this point in the history
  • Loading branch information
labomatik committed Jun 5, 2023
1 parent e9ab4ca commit f4bbb55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/Generators/Ics.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class Ics implements Generator
protected $uid = null;
protected $only_string;

public function __construct($uid = null, $only_string)
/** @var array<non-empty-string, non-empty-string> */
protected $options = [];

public function __construct($uid = null, $only_string = false, array $options = [])
{
$this->uid = $uid;
$this->only_string = $only_string;
$this->options = $options;
}

public function generate(Link $link): string
Expand Down Expand Up @@ -73,18 +77,28 @@ public function generate(Link $link): string
$url[] = 'URL;VALUE=URI:'.$this->escapeString($link->eventUrl);
}

if (isset($this->options['created_at'])) {
$url[] = 'CREATED:'.gmdate($dateTimeFormat,strtotime($this->options['created_at']->format('Y-m-d H:i')));
}else
$url[] = 'CREATED:'.gmdate($dateTimeFormat,strtotime(now()->format('Y-m-d H:i')));

if (isset($this->options['modified_at'])) {
$url[] = 'LAST-MODIFIED:'.gmdate($dateTimeFormat,strtotime($this->options['modified_at']->format('Y-m-d H:i')));
}else
$url[] = 'LAST-MODIFIED:'.gmdate($dateTimeFormat,strtotime(now()->format('Y-m-d H:i')));


$url[] = 'SEQUENCE:0';
$url[] = 'STATUS:CONFIRMED';
$url[] = 'SUMMARY:'.$link->title;
$url[] = 'TRANSP:OPAQUE';
$url[] = 'END:VEVENT';
$url[] = 'END:VCALENDAR';
$redirectLink = implode('%0d%0a', $url);

if($this->only_string)
return $redirectLink;
return implode('%0d%0a', $url);
else
return 'data:text/calendar;charset=utf8,'.$redirectLink;
return implode("\n", $url);
}

/** @see https://tools.ietf.org/html/rfc5545.html#section-3.3.11 */
Expand Down
4 changes: 2 additions & 2 deletions src/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public function google(): string
return (new Google())->generate($this);
}

public function ics($uid = null): string
public function ics($uid = null, array $options = []): string
{
return (new Ics($uid, false))->generate($this);
return (new Ics($uid, false, $options))->generate($this);
}

public function yahoo(): string
Expand Down

0 comments on commit f4bbb55

Please sign in to comment.