array2sif() public method

Converts a hash to a SIF XML structure.
public array2sif ( array $array, string $pre = '', string $post = '' ) : string
$array array A hash.
$pre string A prefix string for the XML result.
$post string A suffix string for the XML result.
return string The resulting XML string.
Example #1
0
 public function vtodo2sif($vcard)
 {
     $iCal = new Horde_Icalendar();
     if (!$iCal->parsevCalendar($vcard)) {
         return PEAR::raiseError('There was an error importing the data.');
     }
     $components = $iCal->getComponents();
     switch (count($components)) {
         case 0:
             return PEAR::raiseError('No data was found');
         case 1:
             $content = $components[0];
             break;
         default:
             return PEAR::raiseError('Multiple components found; only one is supported.');
     }
     $hash['Complete'] = 0;
     $due = false;
     $attr = $content->getAllAttributes();
     foreach ($attr as $item) {
         switch ($item['name']) {
             case 'SUMMARY':
                 $hash['Subject'] = $item['value'];
                 break;
             case 'DESCRIPTION':
                 $hash['Body'] = $item['value'];
                 break;
             case 'PRIORITY':
                 if ($item['value'] == 1) {
                     $hash['Importance'] = 2;
                 } elseif ($item['value'] == 5) {
                     $hash['Importance'] = 0;
                 } else {
                     $hash['Importance'] = 1;
                 }
                 break;
             case 'DTSTART':
                 $hash['StartDate'] = Horde_Icalendar::_exportDateTime($item['value']);
                 break;
             case 'DUE':
                 $hash['DueDate'] = Horde_Icalendar::_exportDateTime($item['value']);
                 $due = $item['value'];
                 break;
             case 'AALARM':
                 $hash['ReminderTime'] = $item['value'];
                 $hash['ReminderSet'] = 1;
                 break;
             case 'STATUS':
                 $hash['Complete'] = $item['value'] == 'COMPLETED' ? 1 : 0;
                 break;
             case 'CATEGORIES':
                 $hash['Categories'] = $item['value'];
                 break;
             case 'CLASS':
                 switch (Horde_String::upper($item['value'])) {
                     case 'PUBLIC':
                         $hash['Sensitivity'] = 0;
                         break;
                     case 'PRIVATE':
                         $hash['Sensitivity'] = 2;
                         break;
                     case 'CONFIDENTIAL':
                         $hash['Sensitivity'] = 3;
                         break;
                 }
                 break;
         }
     }
     if ($due && !isset($hash['ReminderSet'])) {
         // Parse VALARM components.
         foreach ($content->getComponents() as $component) {
             if ($component->getType() != 'vAlarm') {
                 continue;
             }
             try {
                 $trigger = $component->getAttribute('TRIGGER');
             } catch (Horde_Icalendar_Exception $e) {
                 continue;
             }
             if (is_array($trigger) || empty($trigger)) {
                 continue;
             }
             $hash['ReminderSet'] = 1;
             $hash['ReminderTime'] = Horde_Icalendar::_exportDateTime($due - $trigger);
         }
     }
     return Horde_SyncMl_Device_sync4j::array2sif($hash, '<?xml version="1.0"?><task>', '</task>');
 }