{"id":999,"date":"2016-12-24T00:35:15","date_gmt":"2016-12-23T22:35:15","guid":{"rendered":"http:\/\/2.225.140.8\/wordpress\/?p=999"},"modified":"2016-12-24T16:59:00","modified_gmt":"2016-12-24T14:59:00","slug":"owncloud-script-esportare-calendari-ics-prevenire-eventuali-perdite-dati","status":"publish","type":"post","link":"https:\/\/roccadomenico.it\/wordpress\/owncloud-script-esportare-calendari-ics-prevenire-eventuali-perdite-dati\/","title":{"rendered":"Owncloud: script per esportare calendari .ics (per prevenire eventuali perdite di dati)"},"content":{"rendered":"<p>Per chi usa Owncloud, una delle maggiori problematiche \u00e8 quella di riuscire a backuppare i calendari in formato .ics, in modo da poterli ripristrinare in caso di crash o importarli in altri calendari che leggono .ics<br \/>\nQuesta breve guida mostra come creare uno script php. da dare in pasto a crontab, per effettuare un backup giornaliero della nostra \/nostre agende<br \/>\nIn pratica dobbiamo prima installare \u201ccomposer\u201d quindi \u201csabre\/vobject\u201d ed infine creare lo script<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>Tested on<br \/>\nO.S. Ubuntu 14.04<br \/>\nO.Cloud server ver. 8.1.8<\/p>\n<p>needs:<br \/>\n-composer<br \/>\n-sabre<\/p>\n<p>composer<br \/>\ncommand line to install composer<br \/>\nphp composer-setup.php &#8211;install-dir=bin &#8211;filename=composer<br \/>\nNow just run php bin\/composer in order to run Composer.<\/p>\n<p>to test composer if it is installed:<br \/>\ncommand line composer<\/p>\n<div class=\"inline-attachment\">\n<dl class=\"file\">\n<dt class=\"attach-image\"><img decoding=\"async\" class=\"postimage\" src=\"http:\/\/2.225.140.8\/phpBB1\/download\/file.php?id=248\" alt=\"forum2.JPG\" \/><\/dt>\n<dd>forum2.JPG (57.32 KiB) Visto 93 volte<\/dd>\n<\/dl>\n<\/div>\n<p>sabre\/vobject<br \/>\ncommand line to install sabre using composer<br \/>\ncomposer require sabre\/vobject ~4.1<\/p>\n<p>If all went well you should see the following folder<\/p>\n<div class=\"inline-attachment\">\n<dl class=\"file\">\n<dt class=\"attach-image\"><img decoding=\"async\" class=\"postimage\" src=\"http:\/\/2.225.140.8\/phpBB1\/download\/file.php?id=249\" alt=\"forum3.jpg\" \/><\/dt>\n<dd>forum3.jpg (63.24 KiB) Visto 93 volte<\/dd>\n<\/dl>\n<\/div>\n<p>into vendor directory you have to see:<\/p>\n<div class=\"inline-attachment\">\n<dl class=\"file\">\n<dt class=\"attach-image\"><img decoding=\"async\" class=\"postimage\" src=\"http:\/\/2.225.140.8\/phpBB1\/download\/file.php?id=250\" alt=\"forum 4.JPG\" \/><\/dt>\n<dd>forum 4.JPG (16.05 KiB) Visto 93 volte<\/dd>\n<\/dl>\n<\/div>\n<p>now you must create this script (source from <a class=\"postlink\" href=\"https:\/\/statuscode.ch\/2015\/06\/Combining-ownCloud-and-Google-calendar-for-public-room-availability\/\">https:\/\/statuscode.ch\/2015\/06\/Combining &#8230; ilability\/<\/a>)<br \/>\nand put it on your server to test before putting it in a cron job to automate<\/p>\n<p>&lt;?php<br \/>\n\/\/ Use &#8220;composer require sabre\/vobject&#8221; to get the required libraries<br \/>\nrequire_once(&#8216;.\/vendor\/autoload.php&#8217;);<\/p>\n<p>use Sabre\\VObject;<\/p>\n<p>\/\/ Configure your data<br \/>\n$remoteHost = &#8216;http:\/\/xxx.xxx.xxx.xxx\/owncloud&#8217;;<br \/>\n$calendarName = &#8216;yourcalendarname&#8217;;<br \/>\n$username = &#8216;usercalendarname&#8217;;<br \/>\n$password = &#8216;pswusercalendar&#8217;;<\/p>\n<p>\/\/ Get ownCloud calendar<br \/>\n$curl = curl_init($remoteHost . &#8216;\/remote.php\/caldav\/calendars\/&#8217;.$username.&#8217;\/&#8217;.$calendarName.&#8217;?export&#8217;);<br \/>\ncurl_setopt($curl, CURLOPT_USERPWD, $username . &#8220;:&#8221; . $password);<br \/>\ncurl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);<br \/>\ncurl_setopt($curl, CURLOPT_VERBOSE, true);<br \/>\n$ics = curl_exec($curl);<br \/>\ncurl_close($curl);<\/p>\n<p>\/\/ Parse calendar file<br \/>\n$calendar = VObject\\Reader::read($ics);<\/p>\n<p>\/\/ Replace all SUMMARY fields with a value of &#8220;Reserved&#8221;<br \/>\n\/\/ foreach($calendar-&gt;children() as $children) {<br \/>\n\/\/ if($children instanceof VObject\\Component\\VEvent) {<br \/>\n\/\/ $children-&gt;SUMMARY = &#8216;Reserved&#8217;;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Put the resulting ICS to &#8220;destinationdirectory&#8221;\/public.ics<br \/>\nfile_put_contents(&#8216;Scrivania\/TEST\/public.ics&#8217;, $calendar-&gt;serialize());<br \/>\n?&gt;<\/p>\n<p>to test you can write in command line:<br \/>\nphp scriptaddress scriptname.php<\/p>\n<p>if runs well you can see something like this<\/p>\n<div class=\"inline-attachment\">\n<dl class=\"file\">\n<dt class=\"attach-image\"><img decoding=\"async\" class=\"postimage\" src=\"http:\/\/2.225.140.8\/phpBB1\/download\/file.php?id=247\" alt=\"forum1.jpg\" \/><\/dt>\n<dd>forum1.jpg (204.67 KiB) Visto 93 volte<\/dd>\n<\/dl>\n<\/div>\n<p>attention: if you return an error like this:<br \/>\nPHP Warning: require_once(.\/vendor\/autoload.php): failed to open stream:<br \/>\nverify you not are writing in command line as &#8220;sudo&#8221;<\/p>\n<p><a href=\"http:\/\/2.225.140.8\/phpBB1\/viewtopic.php?f=2&amp;t=101\">tratto dal mio forum<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Per chi usa Owncloud, una delle maggiori problematiche \u00e8 quella di riuscire a backuppare i calendari in formato .ics, in modo da poterli ripristrinare in caso di crash o importarli in altri calendari che leggono .ics Questa breve guida mostra come creare uno script php. da dare in pasto a crontab, per effettuare un backup [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[33],"class_list":["post-999","post","type-post","status-publish","format-standard","hentry","category-informatica","tag-informatica"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/posts\/999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/comments?post=999"}],"version-history":[{"count":3,"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/posts\/999\/revisions"}],"predecessor-version":[{"id":1003,"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/posts\/999\/revisions\/1003"}],"wp:attachment":[{"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/media?parent=999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/categories?post=999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roccadomenico.it\/wordpress\/wp-json\/wp\/v2\/tags?post=999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}