1

Queria criar ficheiro iCalendar (extensão .ics) para guardar e voltar a carregar o conteúdo do ficheiro para um calendário feito em PHP. Guardar os dias, os eventos, o início e o fim de cada evento, etc. Qual é o formato desse tipo de ficheiro, e como criar um com PHP?

0

1 Resposta 1

2

a partir de https://stackoverflow.com/a/12741300/1167333

<?php
class ICS {
    var $data;
    var $name;
    function ICS($start,$end,$name,$description,$location) {
        $this->name = $name;
        $this->data = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTART:".date("Ymd\THis\Z",strtotime($start))."\nDTEND:".date("Ymd\THis\Z",strtotime($end))."\nLOCATION:".$location."\nTRANSP: OPAQUE\nSEQUENCE:0\nUID:\nDTSTAMP:".date("Ymd\THis\Z")."\nSUMMARY:".$name."\nDESCRIPTION:".$description."\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGER:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n";
    }
    function save() {
        file_put_contents($this->name.".ics",$this->data);
    }
    function show() {
        header("Content-type:text/calendar");
        header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
        Header('Content-Length: '.strlen($this->data));
        Header('Connection: close');
        echo $this->data;
    }
}
?>

Saída de arquivo do ICS para o navegador e dar ao usuário a opção de abrir ou salvar

<?php
$event = new ICS ( "2009-11-06 09:00", "2009-11-06 21:00" , "Test Event" , "Este é um evento feito por Jamie Bicknell", "GU1 1AA");
$event->show();
? >

Salve o arquivo ICS para o servidor no diretório de trabalho atual

<?php
$event = new ICS ( "2009-11-06 09:00", "2009-11-06 21:00" , "Test Event" , "Este é um evento feito por Jamie Bicknell", "GU1 1AA");
$event->save();
?>
0

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .