im getting ics files from multiple sources. what i want to do is merge those two files using PHP, but i have no idea how to merge those two files. ?
this is first sample file.
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//HomeAway.com, Inc.//EN
BEGIN:VEVENT
UID:e753a377-cc46-403f-a192-c25990400c0e
DTSTAMP:20161222T071905Z
DTSTART:20160728
DTEND:20160731
SUMMARY:Reserved - Janna Stotz
END:VEVENT
BEGIN:VEVENT
UID:989df323-1c44-4d95-ada7-e738dafa0590
DTSTAMP:20161222T071905Z
DTSTART:20170227
DTEND:20170304
SUMMARY:Reserved - Douglas Lawson
END:VEVENT
BEGIN:VEVENT
UID:3d997ba7-8aee-4836-a159-99d79eaf8f73
DTSTAMP:20161222T071905Z
DTSTART:20170213
DTEND:20170220
SUMMARY:Reserved - Stephen Harrison
END:VEVENT
BEGIN:VEVENT
UID:98a31bee-d25e-43a3-a5a4-9d443ea43b22
DTSTAMP:20161222T071905Z
DTSTART:20161222
DTEND:20161227
SUMMARY:Reserved - John Albert
END:VEVENT
END:VCALENDAR
this is second file below:
BEGIN:VCALENDAR
PRODID;X-RICAL-TZSOURCE=TZINFO:-//Airbnb Inc//Hosting Calendar 0.8.8//EN
CALSCALE:GREGORIAN
VERSION:2.0
BEGIN:VEVENT
DTEND;VALUE=DATE:20160720
DTSTART;VALUE=DATE:20160716
UID:[email protected]
DESCRIPTION:CHECKIN: 07/16/2016\nCHECKOUT: 07/20/2016\nNIGHTS: 4\nPHONE:
+1 (619) 247-5942\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Trevonne Pinckney (DA85Z5)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160724
DTSTART;VALUE=DATE:20160722
UID:[email protected]
DESCRIPTION:CHECKIN: 07/22/2016\nCHECKOUT: 07/24/2016\nNIGHTS: 2\nPHONE:
+1 (239) 898-9784\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Darren Gooden (CQEBTT)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160803
DTSTART;VALUE=DATE:20160731
UID:[email protected]
DESCRIPTION:CHECKIN: 07/31/2016\nCHECKOUT: 08/03/2016\nNIGHTS: 3\nPHONE:
+1 (610) 360-6633\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Chad Opdyke (DFDNMN)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160808
DTSTART;VALUE=DATE:20160805
UID:[email protected]
DESCRIPTION:CHECKIN: 08/05/2016\nCHECKOUT: 08/08/2016\nNIGHTS: 3\nPHONE:
+1 (954) 639-3714\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Shay Walsh (5XBTTH)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160815
DTSTART;VALUE=DATE:20160808
UID:[email protected]
DESCRIPTION:CHECKIN: 08/08/2016\nCHECKOUT: 08/15/2016\nNIGHTS: 7\nPHONE:
+1 (929) 363-8190\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Akeem Feiton (WYCZSJ)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160821
DTSTART;VALUE=DATE:20160819
UID:[email protected]
DESCRIPTION:CHECKIN: 08/19/2016\nCHECKOUT: 08/21/2016\nNIGHTS: 2\nPHONE:
+1 (646) 523-7594\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Walter Fox (HZA2CZ)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160829
DTSTART;VALUE=DATE:20160826
UID:[email protected]
DESCRIPTION:CHECKIN: 08/26/2016\nCHECKOUT: 08/29/2016\nNIGHTS: 3\nPHONE:
+1 (754) 246-2940\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Tamika Jones (ADCFN8)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161008
DTSTART;VALUE=DATE:20161005
UID:[email protected]
DESCRIPTION:CHECKIN: 10/05/2016\nCHECKOUT: 10/08/2016\nNIGHTS: 3\nPHONE:
+1 (425) 891-5016\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Shawn Woods (TSJJCD)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161105
DTSTART;VALUE=DATE:20161102
UID:[email protected]
DESCRIPTION:CHECKIN: 11/02/2016\nCHECKOUT: 11/05/2016\nNIGHTS: 3\nPHONE:
+1 (281) 710-7868\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Glenn Gilbert (94FNJS)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161110
DTSTART;VALUE=DATE:20161105
UID:[email protected]
DESCRIPTION:CHECKIN: 11/05/2016\nCHECKOUT: 11/10/2016\nNIGHTS: 5\nPHONE:
+1 (830) 456-1207\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Meredith Clements (8CHB29)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161118
DTSTART;VALUE=DATE:20161111
UID:[email protected]
DESCRIPTION:CHECKIN: 11/11/2016\nCHECKOUT: 11/18/2016\nNIGHTS: 7\nPHONE:
+1 (925) 519-0481\nEMAIL: (no email alias available)\nPROPERTY: Tropical
Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Charles Delmolino (ZERBWC)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161129
DTSTART;VALUE=DATE:20161124
UID:[email protected]
DESCRIPTION:CHECKIN: 11/24/2016\nCHECKOUT: 11/29/2016\nNIGHTS: 5\nPHONE:
+1 (917) 543-5718\nEMAIL: [email protected]\nPROPE
RTY: Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Scott Reale (5BWZC4)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161205
DTSTART;VALUE=DATE:20161202
UID:[email protected]
DESCRIPTION:CHECKIN: 12/02/2016\nCHECKOUT: 12/05/2016\nNIGHTS: 3\nPHONE:
+1 (914) 960-7912\nEMAIL: [email protected]\nPRO
PERTY: Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Lindsay Klein (9D8PJ8)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20170102
DTSTART;VALUE=DATE:20161226
UID:[email protected]
DESCRIPTION:CHECKIN: 12/26/2016\nCHECKOUT: 01/02/2017\nNIGHTS: 7\nPHONE:
+506 8 868 9215\nEMAIL: [email protected]\nPROPE
RTY: Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Adriana Quiros (NE3RFN)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20170111
DTSTART;VALUE=DATE:20170104
UID:[email protected]
DESCRIPTION:CHECKIN: 01/04/2017\nCHECKOUT: 01/11/2017\nNIGHTS: 7\nPHONE:
+1 (514) 927-4600\nEMAIL: [email protected]\nPROP
ERTY: Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Marcel Groleau (9HRSXZ)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20170121
DTSTART;VALUE=DATE:20170117
UID:[email protected]
DESCRIPTION:CHECKIN: 01/17/2017\nCHECKOUT: 01/21/2017\nNIGHTS: 4\nPHONE:
+1 (505) 321-9458\nEMAIL: [email protected]\nPROP
ERTY: Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Sergio Tirado (RM54BM)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20170305
DTSTART;VALUE=DATE:20170216
UID:[email protected]
DESCRIPTION:CHECKIN: 02/16/2017\nCHECKOUT: 03/05/2017\nNIGHTS: 17\nPHONE:
+33 6 76 04 11 95\nEMAIL: [email protected]\nPR
OPERTY: Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach\n
SUMMARY:Bernard Elmalem (K5MF5W)
LOCATION:Tropical Retreat- 1.5 mi to Las Olas Blvd & Beach
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160711
DTSTART;VALUE=DATE:20160708
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160725
DTSTART;VALUE=DATE:20160724
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160731
DTSTART;VALUE=DATE:20160728
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160819
DTSTART;VALUE=DATE:20160816
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160823
DTSTART;VALUE=DATE:20160822
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20160925
DTSTART;VALUE=DATE:20160829
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161003
DTSTART;VALUE=DATE:20160929
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161005
DTSTART;VALUE=DATE:20161004
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161024
DTSTART;VALUE=DATE:20161008
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161102
DTSTART;VALUE=DATE:20161025
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161130
DTSTART;VALUE=DATE:20161129
UID:[email protected]
SUMMARY:Not available
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20170128
DTSTART;VALUE=DATE:20170122
UID:[email protected]
SUMMARY:FlipKey reservation (Andy Vitrone). Move from 628 to 632A.
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20171223
DTSTART;VALUE=DATE
:20171222
UID:[email protected]
SUMMARY:Not available
END:VEVENT
END:VCALENDAR
=-=-=-=-=-=-=-=-=
My Bad, i did not explained whole scenario. Why i want to merge two ics, is because, i am using wordpress with icalendar. and i get reservation dates from different sites like "Airbnb".
but when wordpress import first calendar, and after that i import second calendar, it overrides the first one.
So what i am trying to do.. is merge calendar events and then import all the events all together.
Here is the PHP Code so far for iCalendar.php.
i have edited this code, tried to do foreach loop and used and moved process to another extended function for processing.
function wpestate_import_calendar_feed_listing($prop_id){
$property_icalendar_import = get_post_meta($prop_id, 'property_icalendar_import', true);
$property_icalendar_import2 = get_post_meta($prop_id, 'property_icalendar_import2', true);
$iCalURLS = array(
'property_icalendar_import' => $property_icalendar_import,
'property_icalendar_import2' => $property_icalendar_import2
);
wpestate_import_calendar_feed_listing_extend($prop_id, $iCalURLS);
// wpestate_import_calendar_feed_listing_extend($prop_id, $property_icalendar_import2);
}
function wpestate_import_calendar_feed_listing_extend($prop_id,$iCalURLS){
if(!intval($prop_id)){
exit();
}
if(empty($iCalURLS) || !is_array($iCalURLS) || (empty($iCalURLS['property_icalendar_import']) and empty($iCalURLS['property_icalendar_import2']))){
return;
}
//Validate the URLS,only if they are not empty.
foreach($iCalURLS as $iCalURL){
if(!empty($iCalURL)){
if (filter_var($iCalURL, FILTER_VALIDATE_URL) === FALSE) {
return;
}
}
}
foreach($iCalURLS as $iCalURL){
}
$ical = new ICal($iCalURLS['property_icalendar_import']);
$ical = new ICal($property_icalendar_import);
$events = $ical->events();
$date = $events[0]['DTSTART'];
if (!is_array($events)){
return;
}
wpestate_clear_ical_imported($prop_id);
//DTSTART which sets a starting time, and a DTEND which sets an ending time.
foreach ($events as $event) {
$unix_time_start ='';
$unix_time_end ='';
if( isset($event['UID']) ){
$uid =$event['UID'];
}else{
$uid= esc_html__('external','wpestate');
}
if( isset($event['DTSTART']) ){
// echo "DTSTART: ".$event['DTSTART']." - UNIX-Time: ".$ical->iCalDateToUnixTimestamp($event['DTSTART'])."<br/>";
$unix_time_start =$ical->iCalDateToUnixTimestamp($event['DTSTART']);
}
if( isset($event['DTEND']) ){
//echo "DTEND: ".$event['DTEND']."<br/>";
$unix_time_end =$ical->iCalDateToUnixTimestamp($event['DTEND']);
}
/*
if( isset($event['SUMMARY']) ){
echo "SUMMARY: ".$event['SUMMARY']."<br/>";
}
if( isset($event['DTSTAMP']) ){
echo "DTSTAMP: ".$event['DTSTAMP']."<br/>";
}
if( isset($event['UID']) ){
echo "UID: ".$event['UID']."<br/>";
}
if( isset($event['CREATED']) ){
echo "CREATED: ".$event['CREATED']."<br/>";
}
if( isset($event['DESCRIPTION']) ){
echo "DESCRIPTION: ".$event['DESCRIPTION']."<br/>";
}
if( isset($event['LAST-MODIFIED']) ){
echo "LAST-MODIFIED: ".$event['LAST-MODIFIED']."<br/>";
}
if( isset($event['LOCATION']) ){
echo "LOCATION: ".$event['LOCATION']."<br/>";
}
if( isset($event['SEQUENCE']) ){
echo "SEQUENCE: ".$event['SEQUENCE']."<br/>";
}
if( isset($event['STATUS']) ){
echo "STATUS: ".$event['STATUS']."<br/>";
}
if( isset($event['TRANSP']) ){
echo "TRANSP: ".$event['TRANSP']."<br/>";
}
echo "<hr/>";
*/
// print $unix_time_start." / ".$unix_time_end." / ".$uid." </br>";
if( $unix_time_start!='' && $unix_time_end!='' && $uid !=''){
wpestate_insert_booking_external_event($prop_id, $unix_time_start,$unix_time_end,$uid);
}
}
// $reservation_array = get_post_meta($prop_id, 'booking_dates',true);
//print_R($reservation_array);
}