Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct addMedia include #177

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jeroendesloovere/vcard",
"name": "mammut-alex/vcard",
"type": "library",
"description": "This VCard PHP class can generate a vCard with some data. When using an iOS device it will export as a .ics file because iOS devices don't support the default .vcf files.",
"keywords": ["vcard", "generator", ".vcf", "php"],
Expand Down
113 changes: 57 additions & 56 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ class VCard
/**
* Add address
*
* @param string [optional] $name
* @param string [optional] $extended
* @param string [optional] $street
* @param string [optional] $city
* @param string [optional] $region
* @param string [optional] $zip
* @param string [optional] $country
* @param string [optional] $type
* @param string [optional] $name
* @param string [optional] $extended
* @param string [optional] $street
* @param string [optional] $city
* @param string [optional] $region
* @param string [optional] $zip
* @param string [optional] $country
* @param string [optional] $type
* $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK
* or any combination of these: e.g. "WORK;PARCEL;POSTAL"
* @return $this
Expand All @@ -88,7 +88,8 @@ public function addAddress(
$zip = '',
$country = '',
$type = 'WORK;POSTAL'
) {
)
{
// init value
$value = $name . ';' . $extended . ';' . $street . ';' . $city . ';' . $region . ';' . $zip . ';' . $country;

Expand All @@ -105,7 +106,7 @@ public function addAddress(
/**
* Add birthday
*
* @param string $date Format is YYYY-MM-DD
* @param string $date Format is YYYY-MM-DD
* @return $this
*/
public function addBirthday($date)
Expand Down Expand Up @@ -146,8 +147,8 @@ public function addCompany($company, $department = '')
/**
* Add email
*
* @param string $address The e-mail address
* @param string [optional] $type The type of the email address
* @param string $address The e-mail address
* @param string [optional] $type The type of the email address
* $type may be PREF | WORK | HOME
* or any combination of these: e.g. "PREF;WORK"
* @return $this
Expand All @@ -166,7 +167,7 @@ public function addEmail($address, $type = '')
/**
* Add jobtitle
*
* @param string $jobtitle The jobtitle for the person.
* @param string $jobtitle The jobtitle for the person.
* @return $this
*/
public function addJobtitle($jobtitle)
Expand Down Expand Up @@ -202,7 +203,7 @@ public function addLabel($label, $type = '')
/**
* Add role
*
* @param string $role The role for the person.
* @param string $role The role for the person.
* @return $this
*/
public function addRole($role)
Expand All @@ -225,19 +226,17 @@ public function addRole($role)
* @param string $element The name of the element to set
* @throws VCardException
*/
private function addMedia($property, $url, $include = true, $element)
private function addMedia($property, $url, $include, $element)
{
$mimeType = null;

//Is this URL for a remote resource?
if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
$headers = get_headers($url, 1);

if (array_key_exists('Content-Type', $headers)) {
$mimeType = $headers['Content-Type'];
if (is_array($mimeType)) {
$mimeType = end($mimeType);
}
$mimeType = $headers['Content-Type'] ?? $headers['content-type'] ?? null;
if (is_array($mimeType)) {
$mimeType = end($mimeType);
}
} else {
//Local file, so inspect it directly
Expand All @@ -247,12 +246,13 @@ private function addMedia($property, $url, $include = true, $element)
$mimeType = strstr($mimeType, ';', true);
}
if (!is_string($mimeType) || substr($mimeType, 0, 6) !== 'image/') {
info('url',[$url]);
throw VCardException::invalidImage();
}
$fileType = strtoupper(substr($mimeType, 6));

if ($include) {
if ((bool) ini_get('allow_url_fopen') === true) {
if ((bool)ini_get('allow_url_fopen') === true) {
$value = file_get_contents($url);
} else {
$curl = curl_init();
Expand Down Expand Up @@ -320,11 +320,11 @@ private function addMediaContent($property, $content, $element)
/**
* Add name
*
* @param string [optional] $lastName
* @param string [optional] $firstName
* @param string [optional] $additional
* @param string [optional] $prefix
* @param string [optional] $suffix
* @param string [optional] $lastName
* @param string [optional] $firstName
* @param string [optional] $additional
* @param string [optional] $prefix
* @param string [optional] $suffix
* @return $this
*/
public function addName(
Expand All @@ -333,7 +333,8 @@ public function addName(
$additional = '',
$prefix = '',
$suffix = ''
) {
)
{
// define values with non-empty values
$values = array_filter([
$prefix,
Expand Down Expand Up @@ -370,7 +371,7 @@ public function addName(
/**
* Add note
*
* @param string $note
* @param string $note
* @return $this
*/
public function addNote($note)
Expand Down Expand Up @@ -404,8 +405,8 @@ public function addCategories($categories)
/**
* Add phone number
*
* @param string $number
* @param string [optional] $type
* @param string $number
* @param string [optional] $type
* Type may be PREF | WORK | HOME | VOICE | FAX | MSG |
* CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO
* or any senseful combination, e.g. "PREF;WORK;VOICE"
Expand All @@ -425,8 +426,8 @@ public function addPhoneNumber($number, $type = '')
/**
* Add Logo
*
* @param string $url image url or filename
* @param bool $include Include the image in our vcard?
* @param string $url image url or filename
* @param bool $include Include the image in our vcard?
* @return $this
*/
public function addLogo($url, $include = true)
Expand All @@ -444,7 +445,7 @@ public function addLogo($url, $include = true)
/**
* Add Logo content
*
* @param string $content image content
* @param string $content image content
* @return $this
*/
public function addLogoContent($content)
Expand All @@ -461,8 +462,8 @@ public function addLogoContent($content)
/**
* Add Photo
*
* @param string $url image url or filename
* @param bool $include Include the image in our vcard?
* @param string $url image url or filename
* @param bool $include Include the image in our vcard?
* @return $this
*/
public function addPhoto($url, $include = true)
Expand All @@ -480,7 +481,7 @@ public function addPhoto($url, $include = true)
/**
* Add Photo content
*
* @param string $content image content
* @param string $content image content
* @return $this
*/
public function addPhotoContent($content)
Expand All @@ -497,8 +498,8 @@ public function addPhotoContent($content)
/**
* Add URL
*
* @param string $url
* @param string [optional] $type Type may be WORK | HOME
* @param string $url
* @param string [optional] $type Type may be WORK | HOME
* @return $this
*/
public function addURL($url, $type = '')
Expand Down Expand Up @@ -598,7 +599,7 @@ protected function getUserAgent()
/**
* Decode
*
* @param string $value The value to decode
* @param string $value The value to decode
* @return string decoded
*/
private function decode($value)
Expand Down Expand Up @@ -627,7 +628,7 @@ public function download()
* Fold a line according to RFC2425 section 5.8.1.
*
* @link http://tools.ietf.org/html/rfc2425#section-5.8.1
* @param string $text
* @param string $text
* @return mixed
*/
protected function fold($text)
Expand All @@ -643,10 +644,10 @@ protected function fold($text)
/**
* multibyte word chunk split
* @link http://php.net/manual/en/function.chunk-split.php#107711
*
* @param string $body The string to be chunked.
* @param integer $chunklen The chunk length.
* @param string $end The line ending sequence.
*
* @param string $body The string to be chunked.
* @param integer $chunklen The chunk length.
* @param string $end The line ending sequence.
* @return string Chunked string
*/
protected function chunk_split_unicode($body, $chunklen = 76, $end = "\r\n")
Expand All @@ -664,7 +665,7 @@ protected function chunk_split_unicode($body, $chunklen = 76, $end = "\r\n")
* Escape newline characters according to RFC2425 section 5.8.4.
*
* @link http://tools.ietf.org/html/rfc2425#section-5.8.4
* @param string $text
* @param string $text
* @return string
*/
protected function escape($text)
Expand All @@ -677,9 +678,9 @@ protected function escape($text)

/**
* Get output as string
* @return string
* @deprecated in the future
*
* @return string
*/
public function get()
{
Expand Down Expand Up @@ -745,7 +746,7 @@ public function getFileExtension()
/**
* Get headers
*
* @param bool $asAssociative
* @param bool $asAssociative
* @return array
*/
public function getHeaders($asAssociative)
Expand Down Expand Up @@ -800,7 +801,7 @@ public function getProperties()
/**
* Has property
*
* @param string $key
* @param string $key
* @return bool
*/
public function hasProperty($key)
Expand Down Expand Up @@ -862,7 +863,7 @@ public function save()
/**
* Set charset
*
* @param mixed $charset
* @param mixed $charset
* @return void
*/
public function setCharset($charset)
Expand All @@ -873,9 +874,9 @@ public function setCharset($charset)
/**
* Set filename
*
* @param mixed $value
* @param bool $overwrite [optional] Default overwrite is true
* @param string $separator [optional] Default separator is an underscore '_'
* @param mixed $value
* @param bool $overwrite [optional] Default overwrite is true
* @param string $separator [optional] Default separator is an underscore '_'
* @return void
*/
public function setFilename($value, $overwrite = true, $separator = '_')
Expand Down Expand Up @@ -910,7 +911,7 @@ public function setFilename($value, $overwrite = true, $separator = '_')
/**
* Set the save path directory
*
* @param string $savePath Save Path
* @param string $savePath Save Path
* @throws VCardException
*/
public function setSavePath($savePath)
Expand All @@ -930,9 +931,9 @@ public function setSavePath($savePath)
/**
* Set property
*
* @param string $element The element name you want to set, f.e.: name, email, phoneNumber, ...
* @param string $key
* @param string $value
* @param string $element The element name you want to set, f.e.: name, email, phoneNumber, ...
* @param string $key
* @param string $value
* @throws VCardException
*/
private function setProperty($element, $key, $value)
Expand Down