Skip to content

Commit

Permalink
* bugfixed urls in values (':' was escaped with \)
Browse files Browse the repository at this point in the history
* added support for picture references that are URIs


git-svn-id: http://svn.php.net/repository/pear/packages/Contact_Vcard_Build/trunk@245402 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
till committed Nov 1, 2007
1 parent 50885f5 commit 576f864
Showing 1 changed file with 59 additions and 13 deletions.
72 changes: 59 additions & 13 deletions Contact/Vcard/Build.php
Expand Up @@ -169,7 +169,11 @@ function escape(&$text)
// combined (per note from Daniel Convissor)
$regex = '(?<!\\\\)([\:\;\,\\n])';
$text = preg_replace("/$regex/", '\\\$1', $text);


// fix http(s)\:// to http(s)://
$text = str_replace('http\://', 'http://', $text);
$text = str_replace('https\://', 'http://', $text);

return;
}

Expand Down Expand Up @@ -595,15 +599,15 @@ function getValue($comp, $iter = 0, $part = 0, $rept = null)
* values. There can only be one N component per vCard.
*
* @param mixed $family Single (string) or multiple (array)
* family/last name.
* family/last name.
* @param mixed $given Single (string) or multiple (array)
* given/first name.
* given/first name.
* @param mixed $addl Single (string) or multiple (array)
* additional/middle name.
* additional/middle name.
* @param mixed $prefix Single (string) or multiple (array) honorific
* prefix such as Mr., Miss, etc.
* prefix such as Mr., Miss, etc.
* @param mixed $suffix Single (string) or multiple (array) honorific
* suffix such as III, Jr., Ph.D., etc.
* suffix such as III, Jr., Ph.D., etc.
* @access public
* @return void
*/
Expand Down Expand Up @@ -798,25 +802,38 @@ function getSourceName()
* per vCard.
*
* @param string $text The value to set for this component.
* @param boolean $url True or false, depending if $text is one.
* @access public
* @return void
*/
function setPhoto($text)
function setPhoto($text, $url = false)
{
$this->autoparam = 'PHOTO';
$this->setValue('PHOTO', 0, 0, $text);
if ($url === false) {
$this->autoparam = 'PHOTO';
$this->setValue('PHOTO', 0, 0, $text);
return;
}
$this->autoparam = 'PHOTO:URI';
$this->setValue('PHOTO:URI', 0, 0, $text);
}

/**
* Gets back the value of the PHOTO component. There is only one
* allowed per vCard.
*
* @access public
* @return string The value of this component.
* @return string The value of this component or false if no photo is set.
*/
function getPhoto()
{
return $this->getMeta('PHOTO') . $this->getValue('PHOTO', 0, 0);
if (isset($this->value['PHOTO'])) {
return $this->getMeta('PHOTO') . $this->getValue('PHOTO', 0, 0);
}
if (isset($this->value['PHOTO:URI'])) {
return $this->getMeta('PHOTO:URI') .
$this->getValue('PHOTO:URI', 0, 0);
}
return false;
}

/**
Expand Down Expand Up @@ -1700,8 +1717,9 @@ function fetch()

// personal photo
// available in both 2.1 and 3.0
if (isset($this->value['PHOTO'])) {
$lines[] = $this->getPhoto();
$_photo = $this->getPhoto();
if ($_photo !== false) {
$lines[] = $_photo;
}

// bday
Expand Down Expand Up @@ -1924,6 +1942,34 @@ function send($filename, $disposition = 'attachment', $charset = 'us-ascii')
echo $vcard;
}

/**
* Gets the left-side/prefix/before-the-colon (metadata) part of a
* vCard line, including the component identifier, the parameter
* list, and a colon.
*
* @access public
* @param string $comp The component to get metadata for (ADR, TEL,
* etc).
* @param int $iter The vCard component iteration to get the metadata
* for. E.g., if you have more than one ADR component,
* 0 refers to the first ADR, 1 to the second ADR,
* and so on.
* @return string The line prefix metadata.
*/
function getMeta($comp, $iter = 0)
{
$params = $this->getParam($comp, $iter);

if (trim($params) == '') {
// no parameters
$text = $comp . ':';
} else {
// has parameters. put an extra semicolon in.
$text = $comp . ';' . $params . ':';
}

return $text;
}

/**
* Count the number of iterations for an element type.
Expand Down

0 comments on commit 576f864

Please sign in to comment.