spatie / calendar-links

Generate add to calendar links for Google, iCal and other calendar systems
https://spatie.be/opensource
MIT License
913 stars 148 forks source link

Ics generating for emails #98

Closed FrankOssie closed 4 years ago

FrankOssie commented 4 years ago

What do you want to achieve?

public function generate(Link $link): string
    {
        $url = [
            'BEGIN:VCALENDAR',
            'VERSION:2.0',
            'BEGIN:VEVENT',
            'UID:'.($this->options['UID'] ?? $this->generateEventUid($link)),
            'SUMMARY:'.$this->escapeString($link->title),
        ];

        $dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;

        if ($link->allDay) {
            $url[] = 'DTSTART:'.$link->from->format($dateTimeFormat);
            $url[] = 'DURATION:P1D';
        } else {
            $url[] = 'DTSTART;TZID='.$link->from->format($dateTimeFormat);
            $url[] = 'DTEND;TZID='.$link->to->format($dateTimeFormat);
        }

        if ($link->description) {
            $url[] = 'DESCRIPTION:'.$this->escapeString($link->description);
        }
        if ($link->address) {
            $url[] = 'LOCATION:'.$this->escapeString($link->address);
        }

        $url[] = 'END:VEVENT';
        $url[] = 'END:VCALENDAR';
        $redirectLink = implode("\r\n", $url);

        return ['uri' => 'data:text/calendar;charset=utf8;base64,'.base64_encode($redirectLink),'rawData'=>$redirectLink];
    }

Maybe add this?

FrankOssie commented 4 years ago

Or maybe in a different return or another method. To get the raw data

alies-dev commented 4 years ago

Hey @FrankOssie sorry, what do you want to achieve? An event link without base64_encode?

FrankOssie commented 4 years ago

Yes without base64 encode and without the type declarations

alies-dev commented 4 years ago

@FrankOssie what is the problem with type declarations? With base64_encode? I need to see the whole picture before making any changes.

FrankOssie commented 4 years ago

That i want the ics data seperate from the type declarations to attach it to the email. Otherwise it will not be detected as an ics card now i ended up replacing the type like this str_replace('data:text/calendar;charset=utf8;base64,','',$link->ics()), and my provider wants it base64 encoded so would be nice if you just send out the ics card data so everyone can do with it what they want

alies-dev commented 4 years ago

@FrankOssie I've extracted a logic to generate a link from ics parts into a new protected method, now it's easier to extend ICS generator and override this simple method for your needs. This generator can potentially accept a lot of properties what will make further development very complex (combinatorial explosion).

I would recommend you to use \Spatie\CalendarLinks\Link::formatWith(new Your\Custom\IcsGenerator()) for emails.

alies-dev commented 4 years ago

done within https://github.com/spatie/calendar-links/releases/tag/1.4.2

FrankOssie commented 4 years ago

Awesome thnx!