Ejemplo n.º 1
0
 /**
  * Converts a vcalendar 1.0 component to an icalendar 2.0 component.
  * 
  * @param Sabre_VObject_Component $vobject 
  */
 public static function convertVCard30toVCard21(Sabre\VObject\Component $vobject)
 {
     $qpProperies = array('NOTE', 'FN', 'N');
     if ($vobject->version == '3.0') {
         //vcard 3.0 uses EMAIL;TYPE=INTERNET,HOME:mschering@intermesh.nl
         //We must convert that into EMAIL;INTERNET;HOME:mschering@intermesh.nl for 2.1
         $children = $vobject->children();
         foreach ($children as $property) {
             if (!empty($property['TYPE'])) {
                 $types = explode(',', $property['TYPE']);
                 $property->name .= ';' . implode(';', $types);
                 unset($property['TYPE']);
             }
         }
         $vobject->version = '2.1';
         foreach ($qpProperies as $propName) {
             self::_quotedPrintableEncode($vobject, $propName);
         }
     }
 }
Ejemplo n.º 2
0
 protected function serializeComponent(Component $vObj)
 {
     $this->cWrite('cyan', 'BEGIN');
     $this->cWrite('red', ':');
     $this->cWrite('yellow', $vObj->name . "\n");
     /**
      * Gives a component a 'score' for sorting purposes.
      *
      * This is solely used by the childrenSort method.
      *
      * A higher score means the item will be lower in the list.
      * To avoid score collisions, each "score category" has a reasonable
      * space to accomodate elements. The $key is added to the $score to
      * preserve the original relative order of elements.
      *
      * @param int $key
      * @param array $array
      *
      * @return int
      */
     $sortScore = function ($key, $array) {
         if ($array[$key] instanceof Component) {
             // We want to encode VTIMEZONE first, this is a personal
             // preference.
             if ($array[$key]->name === 'VTIMEZONE') {
                 $score = 300000000;
                 return $score + $key;
             } else {
                 $score = 400000000;
                 return $score + $key;
             }
         } else {
             // Properties get encoded first
             // VCARD version 4.0 wants the VERSION property to appear first
             if ($array[$key] instanceof Property) {
                 if ($array[$key]->name === 'VERSION') {
                     $score = 100000000;
                     return $score + $key;
                 } else {
                     // All other properties
                     $score = 200000000;
                     return $score + $key;
                 }
             }
         }
     };
     $children = $vObj->children();
     $tmp = $children;
     uksort($children, function ($a, $b) use($sortScore, $tmp) {
         $sA = $sortScore($a, $tmp);
         $sB = $sortScore($b, $tmp);
         return $sA - $sB;
     });
     foreach ($children as $child) {
         if ($child instanceof Component) {
             $this->serializeComponent($child);
         } else {
             $this->serializeProperty($child);
         }
     }
     $this->cWrite('cyan', 'END');
     $this->cWrite('red', ':');
     $this->cWrite('yellow', $vObj->name . "\n");
 }
Ejemplo n.º 3
0
 /**
  * remove certain X-OC-* properties from a Sabre Component
  * @param Component &$component
  */
 public static function removeXOCAttrFromComponent(Component &$component)
 {
     foreach ($component->children() as $child) {
         if ($child instanceof Component) {
             self::removeXOCAttrFromComponent($child);
         } elseif (substr($child->name, 0, 5) === 'X-OC-') {
             switch ($child->name) {
                 case 'X-OC-ETAG':
                 case 'X-OC-URI':
                     unset($component->{$child->name});
                     break;
                 default:
                     break;
             }
         }
     }
 }