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

allow extention of setProperty(), add socialmedia option #136

Open
wants to merge 4 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
28 changes: 25 additions & 3 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace JeroenDesloovere\VCard;

/*
* Modified version by HTMLgraphic
*
* This file is part of the VCard PHP Class from Jeroen Desloovere.
*
* For the full copyright and license information, please view the license
Expand Down Expand Up @@ -47,7 +49,8 @@ class VCard
'address',
'phoneNumber',
'url',
'label'
'label',
'socialmedia'
];

/**
Expand Down Expand Up @@ -216,6 +219,25 @@ public function addRole($role)
return $this;
}

/**
* Add socialMedia
*
* @param string $type The type of social media.
* @param string $addr The address of the social media platform.
* @return $this
*/
public function addSocial($type = '', $url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for this function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my todo list.

{

$this->setProperty(
'socialmedia',
'X-SOCIALPROFILE;type=' . (($type != '') ? $type : '' ),
$url
);

return $this;
}

/**
* Add a photo or logo (depending on property name)
*
Expand Down Expand Up @@ -643,7 +665,7 @@ 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.
Expand Down Expand Up @@ -935,7 +957,7 @@ public function setSavePath($savePath)
* @param string $value
* @throws VCardException
*/
private function setProperty($element, $key, $value)
protected function setProperty($element, $key, $value)
{
if (!in_array($element, $this->multiplePropertiesForElementAllowed)
&& isset($this->definedElements[$element])
Expand Down
7 changes: 7 additions & 0 deletions src/VCardParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ protected function parse()
$key = !empty($types) ? implode(';', $types) : 'default';
$cardData->url[$key][] = $value;
break;
case 'SOCIALMEDIA':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for parsing this data

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my todo list, do you have any examples?

if (!isset($cardData->socialmedia)) {
$cardData->socialmedia = [];
}
$key = !empty($types) ? implode(';', $types) : 'default';
$cardData->socialmedia[$key][] = $value;
break;
case 'TITLE':
$cardData->title = $value;
break;
Expand Down