PHP Classes

File: test_vcard.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of CPK Smithies  >  IMC Objects 2  >  test_vcard.php  >  Download  
File: test_vcard.php
Role: Example script
Content type: text/plain
Description: Example code
Class: IMC Objects 2
Parse and generate vCard and iCalendar files
Author: By
Last change:
Date: 3 years ago
Size: 2,542 bytes


Class file image Download
 * Test functionality of vCard classes
 * @author cpks
 * @license Public Domain
 * @version 1.0
require 'imc_vCard.php';
define('SKIP_FAX', TRUE);
if (
SKIP_FAX) require 'imc_ptm.php';

// Create a stand-alone vCard object from code
// A vCard object can write (but not read!) a file.
$vcard = new imc\vCard;
// add a Name property
$prop = new imc\PropertyN;
$prop->suffix = 'Mr'; // was $vcard->setNameSuffix('Mr.'); etc.
$prop->forename = 'Andreas';
$prop->surname = 'Haberstroh';
// add an Address property
$prop = new imc\PropertyAdr; // or, new imc\PropertyAdr(array('TYPE' => 'DOM,HOME'));
$prop->setTypeParam(array('DOM', 'HOME'));
// set the address fields
$prop->street = '341 N. Bitterbush St.';
$prop->state = 'CA';
$prop->locality = 'Orange';
$prop->zip = '92868';
$prop->country = 'USA';
// add a FN ("file under") property
$vcard->setFN('Andreas Haberstroh');
// add a TELephone number
$tel = new imc\customProperty('TEL', '714-532-9493', array('TYPE' => 'HOME'));
$vcard->setVersion('3.0'); // required by the standard
// write the vCard to file

echo "<h1>vCard Object Usage</h1>\n<pre>\n";
echo "</pre>\n";

// Demonstrate reading a vcard file. This might contain multiple vCard
// objects. So we don't use a vCard, we use a ComponentSet. This will
// construct and contain all the vCard objects we need.
$vcard = new imc\ComponentSet;
// Component Sets (and components) are Countable
echo count($vcard), " vCards in sample.vcf:\n";
// and Traversable
foreach ($vcard as $vc) {
// get all WORK contact details
$iter = $vc->getPropertiesOfType('*', 'WORK');
  if (
SKIP_FAX) {// if we want to drop fax values
$inner = $iter;
$iter = new imc\propertyTypeMask($inner, 'FAX');
// get the 'FN' value. This method can be used even for non-unique
  // values in fact.
$person_name = $vc->getUniqueProperty('FN')->getValue();
$colwidth = strlen($person_name) + 1;
$person_name, ' ';
$iter->rewind(); // standard to do this before first use
if (!$iter->valid())
"(no contact details)\n";
  else {
$iter->current()->getValue() . PHP_EOL; // 1st contact detail
    // iterate over subsequent ones
for ($iter->next(); $iter->valid(); $iter->next())
str_repeat(' ', $colwidth), $iter->current()->getValue(), PHP_EOL;