如何合并两个" .ics"文件到一个?

时间:2016-12-22 08:24:38

标签: php icalendar

我从多个来源获取ics文件。我想要做的是使用PHP合并这两个文件,但我不知道如何合并这两个文件。 ?

这是第一个样本文件。

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

这是下面的第二个文件:

    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:cn31z4tbyhod--eusv3c9eu9i0@airbnb.com
    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:cn31z4tbyhod-fz1hn0cqi6yg@airbnb.com
    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:cn31z4tbyhod-1y3w3tplq0zu@airbnb.com
    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:cn31z4tbyhod--h72i8aomz756@airbnb.com
    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:cn31z4tbyhod-mac5tl2dw3eo@airbnb.com
    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:cn31z4tbyhod-lafyl609ekpi@airbnb.com
    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:cn31z4tbyhod--ays9sq2g0gtg@airbnb.com
    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:cn31z4tbyhod--qkhp871f4c32@airbnb.com
    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:cn31z4tbyhod-j79p4h76jnxy@airbnb.com
    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:cn31z4tbyhod-z0uoqh0ijg0k@airbnb.com
    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:cn31z4tbyhod--5el3occjewuc@airbnb.com
    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:cn31z4tbyhod--4m4p1x5hmon2@airbnb.com
    DESCRIPTION:CHECKIN: 11/24/2016\nCHECKOUT: 11/29/2016\nNIGHTS: 5\nPHONE: 
     +1 (917) 543-5718\nEMAIL: scott-6e0gjexnbdo3gktl@guest.airbnb.com\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:cn31z4tbyhod-hhhkyes8uijs@airbnb.com
    DESCRIPTION:CHECKIN: 12/02/2016\nCHECKOUT: 12/05/2016\nNIGHTS: 3\nPHONE: 
     +1 (914) 960-7912\nEMAIL: lindsay-lnnahjxv7mtalxj7@guest.airbnb.com\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:cn31z4tbyhod-oou2j35paua6@airbnb.com
    DESCRIPTION:CHECKIN: 12/26/2016\nCHECKOUT: 01/02/2017\nNIGHTS: 7\nPHONE: 
     +506 8 868 9215\nEMAIL: adriana-70yuldfuvz6exlda@guest.airbnb.com\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:cn31z4tbyhod-firr1585xa7w@airbnb.com
    DESCRIPTION:CHECKIN: 01/04/2017\nCHECKOUT: 01/11/2017\nNIGHTS: 7\nPHONE: 
     +1 (514) 927-4600\nEMAIL: marcel-rwupwcvc6d6vv556@guest.airbnb.com\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:cn31z4tbyhod-qyvl6rznyesq@airbnb.com
    DESCRIPTION:CHECKIN: 01/17/2017\nCHECKOUT: 01/21/2017\nNIGHTS: 4\nPHONE: 
     +1 (505) 321-9458\nEMAIL: sergio-23nza8uyfzu8sb98@guest.airbnb.com\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:cn31z4tbyhod--7eof74b6h3q6@airbnb.com
    DESCRIPTION:CHECKIN: 02/16/2017\nCHECKOUT: 03/05/2017\nNIGHTS: 17\nPHONE:
      +33 6 76 04 11 95\nEMAIL: bernard-1x4rpabhk5j9yzs3@guest.airbnb.com\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:-sg3p5bpek2gn-x055w817b23p@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20160725
    DTSTART;VALUE=DATE:20160724
    UID:-sg3p5bpek2gn-xobd7jo6cv1t@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20160731
    DTSTART;VALUE=DATE:20160728
    UID:-sg3p5bpek2gn-24l1rot6mqtt@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20160819
    DTSTART;VALUE=DATE:20160816
    UID:-sg3p5bpek2gn--pih0m6c16ygf@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20160823
    DTSTART;VALUE=DATE:20160822
    UID:-sg3p5bpek2gn--47s532pniut7@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20160925
    DTSTART;VALUE=DATE:20160829
    UID:-sg3p5bpek2gn--7tcr0ezisq1j@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20161003
    DTSTART;VALUE=DATE:20160929
    UID:-sg3p5bpek2gn-w06qr66c509x@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20161005
    DTSTART;VALUE=DATE:20161004
    UID:-sg3p5bpek2gn--ixkq49h4tbs3@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20161024
    DTSTART;VALUE=DATE:20161008
    UID:-sg3p5bpek2gn--gtx4mmcry3sv@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20161102
    DTSTART;VALUE=DATE:20161025
    UID:-sg3p5bpek2gn-cylycusbl2jh@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20161130
    DTSTART;VALUE=DATE:20161129
    UID:-sg3p5bpek2gn--yx25kuc3pp67@airbnb.com
    SUMMARY:Not available
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20170128
    DTSTART;VALUE=DATE:20170122
    UID:-sg3p5bpek2gn--34z0d6olbk3f@airbnb.com
    SUMMARY:FlipKey reservation (Andy Vitrone). Move from 628 to 632A.
    END:VEVENT
    BEGIN:VEVENT
    DTEND;VALUE=DATE:20171223
    DTSTART;VALUE=DATE

:20171222
UID:-sg3p5bpek2gn-4mjfwyuewkk1@airbnb.com
SUMMARY:Not available
END:VEVENT
END:VCALENDAR

= - = - = - = - = - = - = - = - =

我的坏,我没有解释整个场景。 为什么我要合并两个ics,因为,我正在使用wordpress与icalendar。 我从不同的网站获得预订日期,例如" Airbnb"。

但是当wordpress导入第一个日历,之后我导入第二个日历时,它会覆盖第一个日历。

所以我想做的是合并日历事件,然后将所有事件一起导入。

这是目前针对iCalendar.php的PHP代码。

我编辑了这段代码,尝试做foreach循环并使用并将进程移动到另一个扩展函数进行处理。

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);
}

0 个答案:

没有答案