示例#1
2
 /**
  * Generate the Vcard for the current Contact
  *
  *@return Nothing (display)
  **/
 function generateVcard()
 {
     if (!$this->can($this->fields['id'], READ)) {
         return false;
     }
     // build the Vcard
     $vcard = new VObject\Component\VCard(['N' => [$this->fields["name"], $this->fields["firstname"]], 'EMAIL' => $this->fields["email"], 'NOTE' => $this->fields["comment"]]);
     $vcard->add('TEL', $this->fields["phone"], ['type' => 'PREF;WORK;VOICE']);
     $vcard->add('TEL', $this->fields["phone2"], ['type' => 'HOME;VOICE']);
     $vcard->add('TEL', $this->fields["mobile"], ['type' => 'WORK;CELL']);
     $vcard->add('URL', $this->GetWebsite(), ['type' => 'WORK']);
     $addr = $this->GetAddress();
     if (is_array($addr)) {
         $addr_string = implode(";", array_filter($addr));
         $vcard->add('ADR', $addr_string, ['type' => 'WORK;POSTAL']);
     }
     // send the  VCard
     $output = $vcard->serialize();
     $filename = $this->fields["name"] . "_" . $this->fields["firstname"] . ".vcf";
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/x-vcard; charset=UTF-8");
     echo $output;
 }
示例#2
0
 function assertVCard21serialization($propValue, $expected)
 {
     $doc = new VCard(array('VERSION' => '2.1', 'PROP' => $propValue), false);
     // Adding quoted-printable, because we're testing if it gets removed
     // automatically.
     $doc->PROP['ENCODING'] = 'QUOTED-PRINTABLE';
     $doc->PROP['P1'] = 'V1';
     $output = $doc->serialize();
     $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.1\r\n{$expected}\r\nEND:VCARD\r\n", $output);
 }
 public function NAttribute()
 {
     $vcard = new VObject\Component\VCard();
     $vcard->add('N', ['Werner', 'Lukas', ['Roland', 'Thomas', 'Alfred', 'Joseph'], 'B.Sc.', 'Informatik']);
     $contact = new ContactInformation();
     $contact->setLastname('Werner');
     $contact->setFirstname('Lukas');
     $contact->setAdditionalNames(['Roland', 'Thomas', 'Alfred', 'Joseph']);
     $contact->setHonorificPrefixes('B.Sc.');
     $contact->setHonorificSuffixes('Informatik');
     $this->assertEquals($vcard->serialize(), $this->object->convert($contact)->serialize());
 }
 public function testUpdateProperties()
 {
     $bookId = 42;
     $cardUri = 'card-uri';
     $cardId = 2;
     $backend = $this->getMockBuilder('OCA\\DAV\\CardDAV\\CardDavBackend')->setConstructorArgs([$this->db, $this->principal, null])->setMethods(['getCardId'])->getMock();
     $backend->expects($this->any())->method('getCardId')->willReturn($cardId);
     // add properties for new vCard
     $vCard = new VCard();
     $vCard->add(new Text($vCard, 'UID', $cardUri));
     $vCard->add(new Text($vCard, 'FN', 'John Doe'));
     $this->invokePrivate($backend, 'updateProperties', [$bookId, $cardUri, $vCard->serialize()]);
     $query = $this->db->getQueryBuilder();
     $result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
     $this->assertSame(2, count($result));
     $this->assertSame('UID', $result[0]['name']);
     $this->assertSame($cardUri, $result[0]['value']);
     $this->assertSame($bookId, (int) $result[0]['addressbookid']);
     $this->assertSame($cardId, (int) $result[0]['cardid']);
     $this->assertSame('FN', $result[1]['name']);
     $this->assertSame('John Doe', $result[1]['value']);
     $this->assertSame($bookId, (int) $result[1]['addressbookid']);
     $this->assertSame($cardId, (int) $result[1]['cardid']);
     // update properties for existing vCard
     $vCard = new VCard();
     $vCard->add(new Text($vCard, 'FN', 'John Doe'));
     $this->invokePrivate($backend, 'updateProperties', [$bookId, $cardUri, $vCard->serialize()]);
     $query = $this->db->getQueryBuilder();
     $result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
     $this->assertSame(1, count($result));
     $this->assertSame('FN', $result[0]['name']);
     $this->assertSame('John Doe', $result[0]['value']);
     $this->assertSame($bookId, (int) $result[0]['addressbookid']);
     $this->assertSame($cardId, (int) $result[0]['cardid']);
 }
示例#5
0
 /**
  * Generate vcard for the current user
  **/
 function generateVcard()
 {
     // prepare properties for the Vcard
     if (!empty($this->fields["realname"]) || !empty($this->fields["firstname"])) {
         $name = [$this->fields["realname"], $this->fields["firstname"], "", "", ""];
     } else {
         $name = [$this->fields["name"], "", "", "", ""];
     }
     // create vcard
     $vcard = new VObject\Component\VCard(['N' => $name, 'EMAIL' => $this->getDefaultEmail(), 'NOTE' => $this->fields["comment"]]);
     $vcard->add('TEL', $this->fields["phone"], ['type' => 'PREF;WORK;VOICE']);
     $vcard->add('TEL', $this->fields["phone2"], ['type' => 'HOME;VOICE']);
     $vcard->add('TEL', $this->fields["mobile"], ['type' => 'WORK;CELL']);
     // send the  VCard
     $output = $vcard->serialize();
     $filename = implode("_", array_filter($name)) . ".vcf";
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/x-vcard; charset=UTF-8");
     echo $output;
 }
示例#6
0
 function testAnotherSerializeOrderProp()
 {
     $prop4s = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
     $comp = new VCard(array(), false);
     $comp->__set('SOMEPROP', 'FOO');
     $comp->__set('ANOTHERPROP', 'FOO');
     $comp->__set('THIRDPROP', 'FOO');
     foreach ($prop4s as $prop4) {
         $comp->add('PROP4', 'FOO ' . $prop4);
     }
     $comp->__set('PROPNUMBERFIVE', 'FOO');
     $comp->__set('PROPNUMBERSIX', 'FOO');
     $comp->__set('PROPNUMBERSEVEN', 'FOO');
     $comp->__set('PROPNUMBEREIGHT', 'FOO');
     $comp->__set('PROPNUMBERNINE', 'FOO');
     $comp->__set('PROPNUMBERTEN', 'FOO');
     $comp->__set('VERSION', '2.0');
     $comp->__set('UID', 'FOO');
     $str = $comp->serialize();
     $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.0\r\nSOMEPROP:FOO\r\nANOTHERPROP:FOO\r\nTHIRDPROP:FOO\r\nPROP4:FOO 1\r\nPROP4:FOO 2\r\nPROP4:FOO 3\r\nPROP4:FOO 4\r\nPROP4:FOO 5\r\nPROP4:FOO 6\r\nPROP4:FOO 7\r\nPROP4:FOO 8\r\nPROP4:FOO 9\r\nPROP4:FOO 10\r\nPROPNUMBERFIVE:FOO\r\nPROPNUMBERSIX:FOO\r\nPROPNUMBERSEVEN:FOO\r\nPROPNUMBEREIGHT:FOO\r\nPROPNUMBERNINE:FOO\r\nPROPNUMBERTEN:FOO\r\nUID:FOO\r\nEND:VCARD\r\n", $str);
 }
示例#7
-1
 public function testCreateEmptyVCard()
 {
     $uid = 'uid';
     $expectedVCard = new VCard();
     $expectedVCard->add(new Text($expectedVCard, 'UID', $uid));
     $expectedVCardSerialized = $expectedVCard->serialize();
     $result = $this->invokePrivate($this->addressBookImpl, 'createEmptyVCard', [$uid]);
     $resultSerialized = $result->serialize();
     $this->assertSame($expectedVCardSerialized, $resultSerialized);
 }