Horde_SyncMl_Device_sync4j::sif2vcard PHP Method

sif2vcard() public method

public sif2vcard ( $sif )
    public function sif2vcard($sif)
    {
        $a = Horde_SyncMl_Device_sync4j::sif2array($sif);
        $iCal = new Horde_Icalendar();
        $iCal->setAttribute('VERSION', '3.0');
        $iCal->setAttribute('PRODID', '-//The Horde Project//SyncML//EN');
        $iCal->setAttribute('METHOD', 'PUBLISH');
        $vcard = Horde_Icalendar::newComponent('vcard', $iCal);
        $map = array('FileAs' => array('FN'), 'NickName' => array('NICKNAME'), 'HomeTelephoneNumber' => array('TEL', array('TYPE' => 'HOME')), 'Home2TelephoneNumber' => array('TEL', array('TYPE' => 'HOME')), 'HomeFaxNumber' => array('TEL', array('TYPE' => 'HOME')), 'BusinessTelephoneNumber' => array('TEL', array('TYPE' => 'WORK')), 'Business2TelephoneNumber' => array('TEL', array('TYPE' => 'WORK')), 'BusinessFaxNumber' => array('TEL', array('TYPE' => 'FAX')), 'PrimaryTelephoneNumber' => array('TEL', array('TYPE' => 'PREF')), 'MobileTelephoneNumber' => array('TEL', array('TYPE' => 'CELL')), 'CarTelephoneNumber' => array('TEL', array('TYPE' => 'CAR')), 'PagerNumber' => array('TEL', array('TYPE' => 'PAGER')), 'OtherTelephoneNumber' => array('TEL'), 'OtherFaxNumber' => array('TEL'), 'Email1Address' => array('EMAIL'), 'Email2Address' => array('EMAIL', array('TYPE' => 'HOME')), 'Email3Address' => array('EMAIL', array('TYPE' => 'WORK')), 'HomeLabel' => array('LABEL', array('TYPE' => 'HOME')), 'BusinessLabel' => array('LABEL', array('TYPE' => 'WORK')), 'OtherLabel' => array('LABEL'), 'Profession' => array('ROLE'), 'JobTitle' => array('TITLE'), 'Body' => array('NOTE'), 'WebPage' => array('URL'), 'Birthday' => array('BDAY'), 'Categories' => array('CATEGORIES'), 'Timezone' => array('TZ'), 'Anniversary' => array('X-ANNIVERSARY'), 'Spouse' => array('X-SPOUSE'), 'Children' => array('X-CHILDREN'));
        foreach ($map as $sif_value => $vcard_value) {
            if (isset($a[$sif_value])) {
                $vcard->setAttribute($vcard_value[0], $a[$sif_value], isset($vcard_value[1]) ? $vcard_value[1] : array());
            }
        }
        $map = array(array('N', array(Horde_Icalendar_Vcard::N_FAMILY => 'LastName', Horde_Icalendar_Vcard::N_GIVEN => 'FirstName', Horde_Icalendar_Vcard::N_ADDL => 'MiddleName', Horde_Icalendar_Vcard::N_PREFIX => 'Title', Horde_Icalendar_Vcard::N_SUFFIX => 'Suffix'), array(), false), array('ADR', array(Horde_Icalendar_Vcard::ADR_POB => 'HomeAddressPostOfficeBox', Horde_Icalendar_Vcard::ADR_EXTEND => '', Horde_Icalendar_Vcard::ADR_STREET => 'HomeAddressStreet', Horde_Icalendar_Vcard::ADR_LOCALITY => 'HomeAddressCity', Horde_Icalendar_Vcard::ADR_REGION => 'HomeAddressState', Horde_Icalendar_Vcard::ADR_POSTCODE => 'HomeAddressPostalCode', Horde_Icalendar_Vcard::ADR_COUNTRY => 'HomeAddressCountry'), array('TYPE' => 'HOME'), true), array('ADR', array(Horde_Icalendar_Vcard::ADR_POB => 'BusinessAddressPostOfficeBox', Horde_Icalendar_Vcard::ADR_EXTEND => '', Horde_Icalendar_Vcard::ADR_STREET => 'BusinessAddressStreet', Horde_Icalendar_Vcard::ADR_LOCALITY => 'BusinessAddressCity', Horde_Icalendar_Vcard::ADR_REGION => 'BusinessAddressState', Horde_Icalendar_Vcard::ADR_POSTCODE => 'BusinessAddressPostalCode', Horde_Icalendar_Vcard::ADR_COUNTRY => 'BusinessAddressCountry'), array('TYPE' => 'WORK'), true), array('ADR', array(Horde_Icalendar_Vcard::ADR_POB => 'OtherAddressPostOfficeBox', Horde_Icalendar_Vcard::ADR_EXTEND => '', Horde_Icalendar_Vcard::ADR_STREET => 'OtherAddressStreet', Horde_Icalendar_Vcard::ADR_LOCALITY => 'OtherAddressCity', Horde_Icalendar_Vcard::ADR_REGION => 'OtherAddressState', Horde_Icalendar_Vcard::ADR_POSTCODE => 'OtherAddressPostalCode', Horde_Icalendar_Vcard::ADR_COUNTRY => 'OtherAddressCountry'), array(), true));
        foreach ($map as $struct) {
            $values = array();
            foreach ($struct[1] as $vcard_value => $sif_value) {
                $values[$vcard_value] = isset($a[$sif_value]) ? $a[$sif_value] : '';
            }
            $check = array_flip($values);
            if (count($check) > 1 || strlen(key($check))) {
                $vcard->setAttribute($struct[0], implode(';', $values), $struct[2], $struct[3], $values);
            }
        }
        $org = array();
        if (isset($a['CompanyName'])) {
            $org[] = $a['CompanyName'];
            if (isset($a['Department'])) {
                $org[] = $a['Department'];
            }
        }
        if (count($org)) {
            $vcard->setAttribute('ORG', null, array(), true, $org);
        }
        return $vcard->exportvCalendar();
    }

Usage Example

Example #1
0
 /**
  * Convert the content.
  */
 public function convertClient2Server($content, $contentType)
 {
     list($content, $contentType) = parent::convertClient2Server($content, $contentType);
     switch ($contentType) {
         case 'text/x-s4j-sifn':
         case 'text/x-sifn':
             $content = Horde_SyncMl_Device_sync4j::sif2vnote($content);
             $contentType = 'text/x-vnote';
             break;
         case 'text/x-s4j-sifc':
         case 'text/x-sifc':
             $content = Horde_SyncMl_Device_sync4j::sif2vcard($content);
             $contentType = 'text/x-vcard';
             break;
         case 'text/x-s4j-sife':
         case 'text/x-sife':
             $content = Horde_SyncMl_Device_sync4j::sif2vevent($content);
             $contentType = 'text/calendar';
             break;
         case 'text/x-s4j-sift':
         case 'text/x-sift':
             $content = Horde_SyncMl_Device_sync4j::sif2vtodo($content);
             $contentType = 'text/calendar';
             break;
         case 'text/calendar':
         case 'text/x-vcalendar':
             $si = $GLOBALS['backend']->state->sourceURI;
             if (stristr($si, 'fol-') !== false) {
                 // The Funambol Outlook connector uses invalid STATUS
                 // values. Actually it maps MeetingStatus values of the
                 // Outlook event to the STATUS property, which is
                 // completely useless. So drop the STATUS altogether.
                 $content = preg_replace('/^STATUS:.*\\r?\\n/im', '', $content);
             }
             break;
     }
     $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_DATA, "\nInput converted for server ({$contentType}):\n{$content}\n");
     return array($content, $contentType);
 }
All Usage Examples Of Horde_SyncMl_Device_sync4j::sif2vcard