?
Current File : /home/cideo/www/wp-contentVIp/plugins/gAppointments/includes/add_to_calendar.php
<?php

/**
 * @property string $title
 * @property \DateTime $from
 * @property \DateTime $to
 * @property string $description
 * @property string $address
 */
class ga_add_to_calendar
{
    /** @var string */
    protected $title;

    /** @var \DateTime */
    protected $from;

    /** @var \DateTime */
    protected $to;

    /** @var string */
    protected $description;

    /** @var string */
    protected $address;

    public function __construct($title, DateTime $from, DateTime $to)
    {
        $this->title = $title;
        $this->from = $from;
        $this->to = $to;
    }

    /**
     * @param string $title
     * @param \DateTime $from
     * @param \DateTime $to
     *
     * @return static
     */
    public static function create($title, DateTime $from, DateTime $to)
    {
        return new static($title, $from, $to);
    }

    /**
     * @param string $description
     *
     * @return $this
     */
    public function description($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * @param string $address
     *
     * @return $this
     */
    public function address($address)
    {
        $this->address = $address;

        return $this;
    }

    public function google() {
		$format = 'Ymd\THis';

        $url = 'https://calendar.google.com/calendar/render?action=TEMPLATE';

        $url .= '&text='.urlencode($this->title);
        $url .= '&dates='.$this->from->format($format).'/'.$this->to->format($format);

        if ($this->description) {
            $url .= '&details='.urlencode($this->description);
        }

        if ($this->address) {
            $url .= '&location='.urlencode($this->address);
        }

        $url .= '&sprop=&sprop=name:';

        return $url;
    }

    public function ics()
    {
		$format = 'Ymd\THis';
		
        $url = 'data:text/calendar;charset=utf8,';

        $url .= 'BEGIN:VCALENDAR%0A';
        $url .= 'VERSION:2.0%0A';
        $url .= 'BEGIN:VEVENT%0A';
        $url .= 'DTSTART:'.$this->from->format($format).'%0A';
        $url .= 'DTEND:'.$this->to->format($format).'%0A';
        $url .= "SUMMARY:{$this->title}%0A";

        if ($this->description) {
            $url .= "DESCRIPTION:{$this->description}%0A";
        }

        if ($this->address) {
            $url .= 'LOCATION:'.str_replace(',', '', $this->address).'%0A';
        }

        $url .= 'END:VEVENT%0A';
        $url .= 'END:VCALENDAR';

        return $url;
    }

    public function yahoo()
    {
		$format = 'Ymd\THis';
        $url = 'https://calendar.yahoo.com/?v=60&view=d&type=20';

        $url .= '&title='.urlencode($this->title);
        $url .= '&st='.$this->from->format($format);
        $url .= '&et='.$this->to->format($format);
        $url .= '&dur=23:59';
        if ($this->description) {
            $url .= '&desc='.urlencode($this->description);
        }

        if ($this->address) {
            $url .= '&in_loc='.urlencode($this->address);
        }

        return $url;
    }
}



//$from = DateTime::createFromFormat('Y-m-d H:i', '2018-02-01 09:00');
//$to   = DateTime::createFromFormat('Y-m-d H:i', '2018-02-01 18:00');

//$link = ga_add_to_calendar::create('Sebastian\'s birthday', $from, $to)->description('Cookies & cocktails!')->address('Samberstraat 69D, 2060 Antwerpen');

// Generate a link to create an event on Google calendar
//echo $link->google();

// Generate a link to create an event on Yahoo calendar
//echo $link->yahoo();

// Generate a data uri for an ics file (for iCal & Outlook)
//echo $link->ics();

//$ics = $link->ics();

//echo '<a href="'.$ics.'">Apple Calendar</a>';