Mailing List Archive

PHP CURL
Hi I want to post "events" to my DAViCal using .ICS file and PHP/CURL.
Below is my code and seems like something wrong with it.

Or is there any other way to push events using .ICS to DAViCal?

Thanks.

$url = "http://my.davical.location/caldav.php/myusername/home/";
$ch = curl_init();
$localfile = "/my/ics/file/location/test.ics";
$fp = fopen ($localfile, "r");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_REFERER, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec($ch);
--
View this message in context: http://davical-general.89287.n3.nabble.com/PHP-CURL-tp955334p955334.html
Sent from the DAViCal general mailing list archive at Nabble.com.
PHP CURL [ In reply to ]
On Fri, 2010-07-09 at 14:44 -0700, Coolrugs wrote:
>
> Hi I want to post "events" to my DAViCal using .ICS file and PHP/CURL.
> Below is my code and seems like something wrong with it.
>
> Or is there any other way to push events using .ICS to DAViCal?
>
> Thanks.
>
> $url = "http://my.davical.location/caldav.php/myusername/home/";
> $ch = curl_init();
> $localfile = "/my/ics/file/location/test.ics";
> $fp = fopen ($localfile, "r");
> curl_setopt($ch, CURLOPT_URL, $url);
> curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd');
> curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
> curl_setopt($ch, CURLOPT_PUT, 1);
> curl_setopt($ch, CURLOPT_UPLOAD, 1);
> curl_setopt($ch, CURLOPT_REFERER, 1);
> curl_setopt($ch, CURLOPT_INFILE, $fp);
> curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
> curl_exec($ch);

Hi,

This seems to be on the right track.

What's the content of $header_array ?

Having a CURLOPT_PUT seems a strange way to set the method though. Is
the library really that broken, or can you just specify the method by
name, somehow? How would one specify more obscure methods such as
MKCALENDAR, BIND or DELTICKET, for example?

DAViCal doesn't check the referrer header, and I'm not sure if
CURLOPT_UPLOAD is needed in this case - you might want to check that
one.

Cheers,
Andrew.

--
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
Wagner's music is better than it sounds.
-- Mark Twain
------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20100710/9c4bd248/attachment.pgp>
-------------- next part --------------
PHP CURL [ In reply to ]
Hi Andrew,

Thanks for your reply, however I tried different combination and removing
$header_array, CURLOPT_PUT, CURLOPT_UPLOAD and CURLOPT_REFERER but it
didn't work.

But I was able to use this:
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'MKCALENDAR');
and successfully I was able to create new calendar.

So I tried playing around "curl_setopt ($ch, CURLOPT_CUSTOMREQUEST,
'PUT');", hoping that I can write .ICS thru 'PUT' but it was not
successfull.

$url = "http://my.davical.location/caldav.php/myusername/home/";
$ch = curl_init();
$localfile = "/my/ics/file/location/test.ics";
$fp = fopen ($localfile, "r");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$response = curl_exec($ch);
print_r($ch);
print_r($response);

SCREEN IS OUTPUT = "Resource id #371"

Any help on using 'PUT' and import .ICS is highly appreciated.

Thanks...

--
View this message in context: http://davical-general.89287.n3.nabble.com/PHP-CURL-tp955334p961377.html
Sent from the DAViCal general mailing list archive at Nabble.com.
PHP CURL [ In reply to ]
On Mon, 12 Jul 2010 13:02:15 -0700 (PDT)
Coolrugs <coolrugs at yahoo.com> wrote:

>
> $url = "http://my.davical.location/caldav.php/myusername/home/";
Your problems are here. The URL must contain a unique local URI.
A solution could be:
$filename = $url . sha1(date('U')) . sha1_file($localfile) . '.ics';
> curl_setopt($ch, CURLOPT_URL, $url);
And then replace:
curl_setopt($ch, CURLOPT_URL, $url);
with
curl_setopt($ch, CURLOPT_URL, $filename);
> curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
>
Also using CURLOPT_CUSTOMREQUEST is not required. Using the above with:
curl_setopt($ch, CURLOPT_PUT, 1);
is sufficient.

--
Hilsen/Regards
Michael Rasmussen

Get my public GnuPG keys:
michael <at> rasmussen <dot> cc
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xD3C9A00E
mir <at> datanom <dot> net
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE501F51C
mir <at> miras <dot> org
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE3E80917
--------------------------------------------------------------
Make sure special cases are truly special.
- The Elements of Programming Style (Kernighan & Plaugher)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20100713/1ee13b28/attachment.pgp>
-------------- next part --------------
PHP CURL [ In reply to ]
On Mon, 2010-07-12 at 13:02 -0700, Coolrugs wrote:
> Hi Andrew,
>
> Thanks for your reply, however I tried different combination and removing
> $header_array, CURLOPT_PUT, CURLOPT_UPLOAD and CURLOPT_REFERER but it
> didn't work.
>
> But I was able to use this:
> curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'MKCALENDAR');
> and successfully I was able to create new calendar.
>
> So I tried playing around "curl_setopt ($ch, CURLOPT_CUSTOMREQUEST,
> 'PUT');", hoping that I can write .ICS thru 'PUT' but it was not
> successfull.
>
> $url = "http://my.davical.location/caldav.php/myusername/home/";
> $ch = curl_init();
> $localfile = "/my/ics/file/location/test.ics";
> $fp = fopen ($localfile, "r");
> curl_setopt($ch, CURLOPT_URL, $url);
> curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd');
> curl_setopt($ch, CURLOPT_INFILE, $fp);
> curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
> curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
> $response = curl_exec($ch);
> print_r($ch);
> print_r($response);
>
> SCREEN IS OUTPUT = "Resource id #371"
>
> Any help on using 'PUT' and import .ICS is highly appreciated.

I should have realised before... what you are very likely missing is
the "Content-type" header on your request. It should be set to
'text/icalendar'.

Good to know that you *can* do custom requests though :-)

Cheers,
Andrew.

--
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
Open Source: the difference between trust and antitrust
------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20100712/71992dff/attachment.pgp>
-------------- next part --------------
PHP CURL [ In reply to ]
Finally! This works...

Thanks Andrew & Michael.
@Andrew, I will try all custom request "caldav.php=>$request->method". I
decided to use CURL because I can't get "$request->method['PUT']" worked.


$url = "http://my.davical.location/caldav.php/myusername/home/";
$localfile = "/my/ics/file/location/test.ics";
$filename = $url.sha1(date('U')).sha1_file($localfile).'.ics';
$header_array = array("Cache-Control: no-cache", "Content-type:
text/icalendar");
$fp = fopen ($localfile, "r");
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $filename );
curl_setopt($ch, CURLOPT_USERPWD, "myname:mypwd");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec($ch);
curl_close($ch);
fclose($fp);


--
View this message in context: http://davical-general.89287.n3.nabble.com/PHP-CURL-tp955334p963342.html
Sent from the DAViCal general mailing list archive at Nabble.com.
PHP CURL [ In reply to ]
Hi Andrew,

Just downloaded davical-0.9.9, and at /davical-0.9.9/htdocs/caldav.php
line #67 "case 'text/calendar':", does it matter between 'text/icalendar' as
you had mentioned?

Thanks...
--
View this message in context: http://davical-general.89287.n3.nabble.com/PHP-CURL-tp955334p963857.html
Sent from the DAViCal general mailing list archive at Nabble.com.
PHP CURL [ In reply to ]
On Tue, 2010-07-13 at 08:53 -0700, Coolrugs wrote:
> Hi Andrew,
>
> Just downloaded davical-0.9.9, and at /davical-0.9.9/htdocs/caldav.php
> line #67 "case 'text/calendar':", does it matter between 'text/icalendar' as
> you had mentioned?

Sorry - I was running from memory, as fallibly as ever, I'm afraid.

If you read 'text/calendar' in the code that is the correct mime type.

Cheers,
Andrew.

--
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
It's all in the mind, ya know.
------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20100715/019b9a45/attachment-0001.pgp>
-------------- next part --------------
PHP CURL [ In reply to ]
Thanks Andrew. I got my PHP->CURL + DAViCal works!

However, I had some concerned. I had a Drag-Drop Calendar
(JQuery+PHP+MySQL) base. And since I already had DAViCal works on my server
I want to store all events to DAViCal DB (which is PostgreSQL). So instead
of writing PostgreSQL Query (that includes converting my existing MySQL
Queries to PG), I did use PHP CURL which works fine (so meaning "NO" PG &
MySQL Query).

Now the issue is, on Drop event I only need to update the "dtstart" and
"dtend" date. To do this I need the following:

1. GET event from DAViCal. (.ICS output)
2. Change the "dtstart" and "dtend" by manipulating that (.ICS output)
3. POST it back to DAViCal. (looks like creating another .ICS)

Does anybody had suggestion or shortcuts to this? I would like to avoid
writing/creating an .ICS file.

Thanks in advance.

--
View this message in context: http://davical-general.89287.n3.nabble.com/PHP-CURL-tp955334p979317.html
Sent from the DAViCal general mailing list archive at Nabble.com.