starting changes for v2

This commit is contained in:
Christoph Haas 2016-06-13 10:18:47 +02:00
parent 8ddce98d22
commit 2118320a5d
7 changed files with 178 additions and 201 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

147
build.xml
View File

@ -1,18 +1,15 @@
<project default="all"> <project default="all">
<!--############# CONFIGURE ALL PROPERTIES FOR THE REPLACER HERE ################--> <property environment="env"/>
<property name="plugin_version" value="1.0.3"/> <property name="root-folder" value="${basedir}/../../"/>
<!-- EOC --> <property name="tools-folder" value="${root-folder}/tools/"/>
<property name="target-folder" value="${root-folder}/deploy/plugins"/>
<property name="root-folder" value="${basedir}/../"/> <property name="server-folder" value="${root-folder}/server"/>
<property name="tools-folder" value="${root-folder}/TOOLS/"/>
<property name="target-folder" value="${root-folder}/DEPLOY/plugins"/>
<import file="${tools-folder}/antutil.xml"/> <import file="${tools-folder}/antutil.xml"/>
<typedef file="${tools-folder}/antlib.xml"> <typedef file="${tools-folder}/antlib.xml">
<classpath> <classpath>
<pathelement location="${tools-folder}/tools.jar"/> <pathelement location="${tools-folder}/tools.jar"/>
<pathelement location="${tools-folder}/lib/compiler.jar"/>
</classpath> </classpath>
</typedef> </typedef>
@ -22,29 +19,7 @@
</classpath> </classpath>
</taskdef> </taskdef>
<!-- os checks for xmllint... -->
<condition property="isWindows" value="true">
<os family="windows" />
</condition>
<!-- define nicknames for libraries -->
<property name="yui-compressor" location="${tools-folder}/lib/yuicompressor-2.4.2.jar" />
<property name="yui-compressor-ant-task" location="${tools-folder}/lib/yui-compressor-ant-task-0.5.jar" />
<!-- adds libraries to the classpath -->
<path id="yui.classpath">
<pathelement location="${yui-compressor}" />
<pathelement location="${yui-compressor-ant-task}" />
</path>
<!-- define tasks -->
<taskdef name="yui-compressor" classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask">
<classpath refid="yui.classpath" />
</taskdef>
<!-- Determine plugin name --> <!-- Determine plugin name -->
<var name="plugin" unset="true"/>
<basename file="${basedir}" property="plugin"/> <basename file="${basedir}" property="plugin"/>
<!-- The Plugin distribution files --> <!-- The Plugin distribution files -->
@ -54,8 +29,7 @@
<!-- The Plugin CSS files --> <!-- The Plugin CSS files -->
<property name="plugin-css-folder" value="resources/css"/> <property name="plugin-css-folder" value="resources/css"/>
<property name="plugin-css-file" value="${plugin}-min.css"/> <property name="plugin-css-file" value="${plugin}.css"/>
<property name="plugin-css-debug-file" value="${plugin}.css"/>
<!-- Meta target --> <!-- Meta target -->
<target name="all" depends="concat, compress"/> <target name="all" depends="concat, compress"/>
@ -68,16 +42,6 @@
<include name="${plugin-file}"/> <include name="${plugin-file}"/>
<include name="${plugin-debugfile}"/> <include name="${plugin-debugfile}"/>
</fileset> </fileset>
<fileset dir="${target-folder}/${plugin-folder}/php">
<include name="**/*.php"/>
</fileset>
<fileset dir="${target-folder}/${plugin-folder}/resources">
<include name="**/*"/>
</fileset>
<fileset dir="${target-folder}/${plugin-folder}/${plugin-css-folder}">
<include name="${plugin-css-debug-file}"/>
<include name="${plugin-css-file}"/>
</fileset>
</delete> </delete>
</target> </target>
@ -89,19 +53,11 @@
<then> <then>
<mkdir dir="${target-folder}/${plugin-folder}/js"/> <mkdir dir="${target-folder}/${plugin-folder}/js"/>
<echo message="Concatenating: ${plugin-debugfile}"/> <echo message="Concatenating: ${plugin-debugfile}"/>
<!-- TODO: fix JS files for zConcat --> <zConcat outputFolder="${target-folder}/${plugin-folder}/js" outputFile="${plugin-debugfile}" prioritize="\w+">
<!--zConcat outputFolder="${target-folder}/${plugin-folder}/js" outputFile="${plugin-debugfile}" prioritize="\w+">
<concatfiles> <concatfiles>
<fileset dir="js" includes="**/*.js" /> <fileset dir="js" includes="**/*.js" />
</concatfiles> </concatfiles>
</zConcat--> </zConcat>
<concat destfile="${target-folder}/${plugin-folder}/js/${plugin-debugfile}">
<fileset file="js/ABOUT.js" />
<fileset file="js/plugin.contactimporter.js" />
<fileset file="js/data/ResponseHandler.js" />
<fileset file="js/dialogs/ImportContentPanel.js" />
<fileset file="js/dialogs/ImportPanel.js" />
</concat>
</then> </then>
</if> </if>
@ -110,8 +66,8 @@
<available file="${plugin-css-folder}" type="dir" /> <available file="${plugin-css-folder}" type="dir" />
<then> <then>
<mkdir dir="${target-folder}/${plugin-folder}/${plugin-css-folder}"/> <mkdir dir="${target-folder}/${plugin-folder}/${plugin-css-folder}"/>
<echo message="Concatenating: ${plugin-css-debug-file}"/> <echo message="Concatenating: ${plugin-css-file}"/>
<zConcat outputFolder="${target-folder}/${plugin-folder}/${plugin-css-folder}" outputFile="${plugin-css-debug-file}"> <zConcat outputFolder="${target-folder}/${plugin-folder}/${plugin-css-folder}" outputFile="${plugin-css-file}">
<concatfiles> <concatfiles>
<fileset dir="${plugin-css-folder}" includes="**/*.css" /> <fileset dir="${plugin-css-folder}" includes="**/*.css" />
</concatfiles> </concatfiles>
@ -156,21 +112,15 @@
var pgettext = function(msgctxt, msgid) {}; var pgettext = function(msgctxt, msgid) {};
</externs> </externs>
</zCompile> </zCompile>
<!--yui-compressor
warn="false"
munge="true"
preserveallsemicolons="false"
fromdir="${target-folder}/${plugin-folder}/js"
todir="${target-folder}/${plugin-folder}/js">
<include name="${plugin-debugfile}" />
</yui-compressor-->
</then> </then>
</if> </if>
</target> </target>
<!-- syntax check all PHP files --> <!-- syntax check all PHP files -->
<target name="validate"> <target name="validate">
<if>
<available file="php" filepath="${env.PATH}" />
<then>
<if> <if>
<available file="config.php" type="file" /> <available file="config.php" type="file" />
<then> <then>
@ -191,86 +141,59 @@
</foreach> </foreach>
</then> </then>
</if> </if>
</then>
<else>
<echo message="WARNING: PHP not available, not performing syntax-check on php files"/>
</else>
</if>
</target> </target>
<target name="syntax-check"> <target name="syntax-check">
<echo message="validating ${file}"/> <echo message="validating ${file}"/>
<exec executable="php" failonerror="true" failifexecutionfails="false"> <exec executable="php" failonerror="true">
<arg value="-l"/> <arg value="-l"/>
<arg value="${file}"/> <arg value="${file}"/>
</exec> </exec>
</target> </target>
<!-- on windows we do not check the xml file --> <!-- Install all files into the target folder -->
<target name="xml-os-sel" depends="xml-check,xml-copy"> <target name="deploy" depends="compress, validate">
<echo>Processing manifest.xml</echo> <mkdir dir="${target-folder}/${plugin-folder}"/>
</target>
<!-- check manifest.xml if we are on windows... -->
<target name="xml-check" unless="isWindows">
<echo message="Checking xml: manifest.xml" />
<!-- Copy (and validate) manifest.xml --> <!-- Copy (and validate) manifest.xml -->
<exec executable="xmllint" output="${target-folder}/${plugin-folder}/manifest.xml" failonerror="true" error="/dev/stdout" failifexecutionfails="false"> <if>
<available file="xmllint" filepath="${env.PATH}" />
<then>
<exec executable="xmllint" output="${target-folder}/${plugin-folder}/manifest.xml" failonerror="true">
<arg value="--valid"/> <arg value="--valid"/>
<arg value="--path"/> <arg value="--path"/>
<arg value="${root-folder}/server"/> <arg value="${server-folder}"/>
<arg value="manifest.xml"/> <arg value="manifest.xml"/>
</exec> </exec>
</target> </then>
<else>
<!-- check manifest.xml if we are on windows... --> <echo message="WARNING: xmllint not available, not performing syntax-check on manifest.xml"/>
<target name="xml-copy" if="isWindows"> <!-- xmllint is not available, so we must copy the file manually -->
<echo message="Copying xml: manifest.xml" />
<!-- Copy manifest.xml -->
<copy todir="${target-folder}/${plugin-folder}"> <copy todir="${target-folder}/${plugin-folder}">
<fileset dir="."> <fileset dir=".">
<include name="manifest.xml"/> <include name="manifest.xml"/>
</fileset> </fileset>
</copy> </copy>
</target> </else>
</if>
<!-- Install all files into the target folder -->
<target name="deploy" depends="clean, compress, compresscss, validate, xml-os-sel">
<mkdir dir="${target-folder}/${plugin-folder}"/>
<!-- copy files --> <!-- copy files -->
<copy todir="${target-folder}/${plugin-folder}"> <copy todir="${target-folder}/${plugin-folder}">
<fileset dir="."> <fileset dir=".">
<include name="resources/**/*"/> <include name="resources/**/*.*"/>
<include name="external/**/*.*"/>
<include name="php/**/*.php"/> <include name="php/**/*.php"/>
<include name="config.php"/> <include name="config.php"/>
<include name="changelog.txt"/>
<!-- exclude the ant script --> <!-- exclude the ant script -->
<exclude name="build.xml"/> <exclude name="build.xml"/>
<!-- CSS is generated during build --> <!-- CSS is generated during build -->
<exclude name="resources/css/*.*"/> <exclude name="resources/css/*.*"/>
</fileset> </fileset>
</copy> </copy>
<!-- replace all variables... -->
<replace file="${target-folder}/${plugin-folder}/manifest.xml" token="@_@PLUGIN_VERSION@_@" value="${plugin_version}" />
</target> </target>
<!-- compresses each CSS file -->
<target name="compresscss" depends="concat">
<available file="${tools-folder}/lib/yui-compressor-ant-task-0.5.jar" property="YUIANT_AVAILABLE" />
<fail unless="YUIANT_AVAILABLE" message="yui-compressor-ant-task-0.5.jar not found" />
<if>
<available file="${target-folder}/${plugin-folder}/${plugin-css-folder}/${plugin-css-debug-file}" type="file" />
<then>
<yui-compressor
warn="false"
munge="true"
preserveallsemicolons="false"
fromdir="${target-folder}/${plugin-folder}/${plugin-css-folder}"
todir="${target-folder}/${plugin-folder}/${plugin-css-folder}">
<include name="${plugin-css-debug-file}" />
</yui-compressor>
</then>
</if>
</target>
</project> </project>

View File

@ -2,7 +2,7 @@
/** Disable the import plugin for all clients */ /** Disable the import plugin for all clients */
define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE', false); define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE', false);
/** Disable the export feature for all clients */ /** Disable the export feature for all clients */
define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE_EXPORT', false); // currently not available define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE_EXPORT', false);
/** The default addressbook to import to (default: contact)*/ /** The default addressbook to import to (default: contact)*/
define('PLUGIN_CONTACTIMPORTER_DEFAULT', "contact"); define('PLUGIN_CONTACTIMPORTER_DEFAULT', "contact");

View File

@ -47,7 +47,7 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
config = config || {}; config = config || {};
var self = this; var self = this;
if(typeof config.filename !== "undefined") { if(!Ext.isEmpty(config.filename)) {
this.vcffile = config.filename; this.vcffile = config.filename;
} }
@ -146,13 +146,13 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
var i = 0; var i = 0;
for(i = 0; i < contactdata.contacts.length; i++) { for(i = 0; i < contactdata.contacts.length; i++) {
parsedData[i] = new Array( parsedData[i] = [
contactdata.contacts[i]["display_name"], contactdata.contacts[i]["display_name"],
contactdata.contacts[i]["given_name"], contactdata.contacts[i]["given_name"],
contactdata.contacts[i]["surname"], contactdata.contacts[i]["surname"],
contactdata.contacts[i]["company_name"], contactdata.contacts[i]["company_name"],
contactdata.contacts[i] contactdata.contacts[i]
); ];
} }
} else { } else {
return null; return null;
@ -202,10 +202,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
/* add all local contact folders */ /* add all local contact folders */
var i = 0; var i = 0;
myStore.push(new Array(defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName())); myStore.push([defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName()]);
for(i = 0; i < subFolders.length; i++) { for(i = 0; i < subFolders.length; i++) {
/* Store all subfolders */ /* Store all subfolders */
myStore.push(new Array(subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false)); // 3rd field = isPublicfolder myStore.push([subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false]); // 3rd field = isPublicfolder
} }
/* add all shared contact folders */ /* add all shared contact folders */
@ -217,7 +217,7 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
var pubSubFolders = pubFolder.getChildren(); var pubSubFolders = pubFolder.getChildren();
for(i = 0; i < pubSubFolders.length; i++) { for(i = 0; i < pubSubFolders.length; i++) {
if(pubSubFolders[i].isContainerClass("IPF.Contact")){ if(pubSubFolders[i].isContainerClass("IPF.Contact")){
myStore.push(new Array(pubSubFolders[i].getDisplayName(), pubSubFolders[i].getDisplayName() + " [Shared]", true)); // 3rd field = isPublicfolder myStore.push([pubSubFolders[i].getDisplayName(), pubSubFolders[i].getDisplayName() + " [Shared]", true]); // 3rd field = isPublicfolder
} }
} }
} catch (e) { } catch (e) {
@ -455,7 +455,7 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
if(addressbookexist) { if(addressbookexist) {
this.loadMask.show(); this.loadMask.show();
var uids = new Array(); var uids = [];
var store_entryid = ""; var store_entryid = "";
//receive Records from grid rows //receive Records from grid rows

View File

@ -47,6 +47,7 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
/* directly import received vcfs */ /* directly import received vcfs */
this.registerInsertionPoint('common.contextmenu.attachment.actions', this.createAttachmentImportButton); this.registerInsertionPoint('common.contextmenu.attachment.actions', this.createAttachmentImportButton);
/* add import button to south navigation */ /* add import button to south navigation */
this.registerInsertionPoint("navigation.south", this.createImportButton, this); this.registerInsertionPoint("navigation.south", this.createImportButton, this);
}, },
@ -60,7 +61,6 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
createImportButton: function () { createImportButton: function () {
var button = { var button = {
xtype : 'button', xtype : 'button',
id : "importcontactsbutton",
text : _('Import Contacts'), text : _('Import Contacts'),
iconCls : 'icon_contactimporter_button', iconCls : 'icon_contactimporter_button',
navigationContext : container.getContextByName('contact'), navigationContext : container.getContextByName('contact'),
@ -90,9 +90,9 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
var extension = record.data.name.split('.').pop().toLowerCase(); var extension = record.data.name.split('.').pop().toLowerCase();
if(record.data.filetype == "text/vcard" || extension == "vcf" || extension == "vcard") { if(record.data.filetype == "text/vcard" || extension == "vcf" || extension == "vcard") {
item.setDisabled(false); item.setVisible(false);
} else { } else {
item.setDisabled(true); item.setVisible(true);
} }
} }
}; };
@ -103,10 +103,7 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
*/ */
gotAttachmentFileName: function(response) { gotAttachmentFileName: function(response) {
if(response.status == true) { if(response.status == true) {
Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts'], undefined, { this.openImportDialog(response.tmpname);
manager : Ext.WindowMgr,
filename : response.tmpname
});
} else { } else {
Zarafa.common.dialogs.MessageBox.show({ Zarafa.common.dialogs.MessageBox.show({
title : _('Error'), title : _('Error'),
@ -182,10 +179,21 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
* Clickhandler for the button * Clickhandler for the button
*/ */
onImportButtonClick: function () { onImportButtonClick: function () {
Ext.getCmp("importcontactsbutton").disable(); this.openImportDialog();
Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts'], undefined, { },
manager : Ext.WindowMgr
}); /**
* Open the import dialog.
*
* @param {String} filename
*/
openImportDialog: function(filename) {
var componentType = Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts'];
var config = {
filename: filename
};
Zarafa.core.data.UIFactory.openLayerComponent(componentType, undefined, config);
}, },
/** /**
@ -200,7 +208,7 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
var bid = -1; var bid = -1;
switch(type) { switch(type) {
case Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts']: case Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts']:
bid = 2; bid = 1;
break; break;
} }
return bid; return bid;

View File

@ -2,7 +2,7 @@
<!DOCTYPE plugin SYSTEM "manifest.dtd"> <!DOCTYPE plugin SYSTEM "manifest.dtd">
<plugin version="2"> <plugin version="2">
<info> <info>
<version>@_@PLUGIN_VERSION@_@</version> <version>2.0.0</version>
<name>contactimporter</name> <name>contactimporter</name>
<title>VCF Contact Importer/Exporter</title> <title>VCF Contact Importer/Exporter</title>
<author>Christoph Haas</author> <author>Christoph Haas</author>
@ -24,6 +24,7 @@
<clientfile load="debug">js/contactimporter-debug.js</clientfile> <clientfile load="debug">js/contactimporter-debug.js</clientfile>
<clientfile load="source">js/plugin.contactimporter.js</clientfile> <clientfile load="source">js/plugin.contactimporter.js</clientfile>
<clientfile load="source">js/ABOUT.js</clientfile>
<clientfile load="source">js/data/ResponseHandler.js</clientfile> <clientfile load="source">js/data/ResponseHandler.js</clientfile>
<clientfile load="source">js/dialogs/ImportContentPanel.js</clientfile> <clientfile load="source">js/dialogs/ImportContentPanel.js</clientfile>
<clientfile load="source">js/dialogs/ImportPanel.js</clientfile> <clientfile load="source">js/dialogs/ImportPanel.js</clientfile>

View File

@ -5,9 +5,8 @@
* @link https://github.com/nuovo/vCard-parser * @link https://github.com/nuovo/vCard-parser
* @author Martins Pilsetnieks, Roberts Bruveris * @author Martins Pilsetnieks, Roberts Bruveris
* @see RFC 2426, RFC 2425 * @see RFC 2426, RFC 2425
* @version 0.4.8 * @version 0.4.9
*/ */
class vCard implements Countable, Iterator class vCard implements Countable, Iterator
{ {
const MODE_ERROR = 'error'; const MODE_ERROR = 'error';
@ -42,15 +41,15 @@ class vCard implements Countable, Iterator
* @static Parts of structured elements according to the spec. * @static Parts of structured elements according to the spec.
*/ */
private static $Spec_StructuredElements = array( private static $Spec_StructuredElements = array(
'n' => array('LastName', 'FirstName', 'AdditionalNames', 'Prefixes', 'Suffixes'), 'n' => array('lastname', 'firstname', 'additionalnames', 'prefixes', 'suffixes'),
'adr' => array('POBox', 'ExtendedAddress', 'StreetAddress', 'Locality', 'Region', 'PostalCode', 'Country'), 'adr' => array('pobox', 'extendedaddress', 'streetaddress', 'locality', 'region', 'postalcode', 'country'),
'geo' => array('Latitude', 'Longitude'), 'geo' => array('latitude', 'longitude'),
'org' => array('Name', 'Unit1', 'Unit2') 'org' => array('name', 'unit1', 'unit2')
); );
private static $Spec_MultipleValueElements = array('nickname', 'categories'); private static $Spec_MultipleValueElements = array('nickname', 'categories');
private static $Spec_ElementTypes = array( private static $Spec_ElementTypes = array(
'email' => array('internet', 'x400', 'pref'), 'email' => array('internet', 'x400', 'pref', 'home', 'work'),
'adr' => array('dom', 'intl', 'postal', 'parcel', 'home', 'work', 'pref'), 'adr' => array('dom', 'intl', 'postal', 'parcel', 'home', 'work', 'pref'),
'label' => array('dom', 'intl', 'postal', 'parcel', 'home', 'work', 'pref'), 'label' => array('dom', 'intl', 'postal', 'parcel', 'home', 'work', 'pref'),
'tel' => array('home', 'msg', 'work', 'pref', 'voice', 'fax', 'cell', 'video', 'pager', 'bbs', 'modem', 'car', 'isdn', 'pcs'), 'tel' => array('home', 'msg', 'work', 'pref', 'voice', 'fax', 'cell', 'video', 'pager', 'bbs', 'modem', 'car', 'isdn', 'pcs'),
@ -121,21 +120,26 @@ class vCard implements Countable, Iterator
$this -> Mode = $vCardBeginCount == 1 ? vCard::MODE_SINGLE : vCard::MODE_MULTIPLE; $this -> Mode = $vCardBeginCount == 1 ? vCard::MODE_SINGLE : vCard::MODE_MULTIPLE;
// Removing/changing inappropriate newlines, i.e., all CRs or multiple newlines are changed to a single newline // Removing/changing inappropriate newlines, i.e., all CRs or multiple newlines are changed to a single newline
$this -> RawData = str_replace("\r", "\n", $this -> RawData);
$this -> RawData = preg_replace('{(\n+)}', "\n", $this -> RawData); // MCA: removed, this break crlf vcard specification, all line dilimiter are CRLF
//$this -> RawData = str_replace("\r", "\n", $this -> RawData);
//$this -> RawData = preg_replace('{(\n)+}', "\n", $this -> RawData);
// In multiple card mode the raw text is split at card beginning markers and each // In multiple card mode the raw text is split at card beginning markers and each
// fragment is parsed in a separate vCard object. // fragment is parsed in a separate vCard object.
if ($this -> Mode == self::MODE_MULTIPLE) if ($this -> Mode == self::MODE_MULTIPLE)
{ {
$this -> RawData = explode('BEGIN:VCARD', $this -> RawData); //Cannot use "explode", because we need to ignore, for example, 'AGENT:BEGIN:VCARD'
$this -> RawData = preg_split('{^BEGIN\:VCARD}miS', $this -> RawData);
$this -> RawData = array_filter($this -> RawData); $this -> RawData = array_filter($this -> RawData);
foreach ($this -> RawData as $SinglevCardRawData) foreach ($this -> RawData as $SinglevCardRawData)
{ {
// mca: remove \n and \r at start
//$SinglevCardRawData=ltrim($SinglevCardRawData);
// Prepending "BEGIN:VCARD" to the raw string because we exploded on that one. // Prepending "BEGIN:VCARD" to the raw string because we exploded on that one.
// If there won't be the BEGIN marker in the new object, it will fail. // If there won't be the BEGIN marker in the new object, it will fail.
$SinglevCardRawData = 'BEGIN:VCARD'."\n".$SinglevCardRawData; $SinglevCardRawData = 'BEGIN:VCARD'.$SinglevCardRawData;
$ClassName = get_class($this); $ClassName = get_class($this);
$this -> Data[] = new $ClassName(false, $SinglevCardRawData); $this -> Data[] = new $ClassName(false, $SinglevCardRawData);
@ -143,20 +147,20 @@ class vCard implements Countable, Iterator
} }
else else
{ {
// Protect the BASE64 final = sign (detected by the line beginning with whitespace), otherwise the next replace will get rid of it
$this -> RawData = preg_replace('{(\n\s.+)=(\n)}', '$1-base64=-$2', $this -> RawData);
// Joining multiple lines that are split with a hard wrap and indicated by an equals sign at the end of line // Joining multiple lines that are split with a hard wrap and indicated by an equals sign at the end of line
// (quoted-printable-encoded values in v2.1 vCards) // (quoted-printable-encoded values in v2.1 vCards)
$this -> RawData = str_replace("=\n", '', $this -> RawData); $this -> RawData = str_replace("=\r\n", '', $this -> RawData);
// Protect the BASE64 final = sign (detected by the line beginning with whitespace), otherwise the next replace will get rid of it
$this -> RawData = preg_replace('{(\r\n\s.+)=(\r\n)}', '$1-base64=-$2', $this -> RawData);
// Joining multiple lines that are split with a soft wrap (space or tab on the beginning of the next line // Joining multiple lines that are split with a soft wrap (space or tab on the beginning of the next line
$this -> RawData = str_replace(array("\n ", "\n\t"), '-wrap-', $this -> RawData); $this -> RawData = str_replace(array("\r\n ", "\r\n\t"), '-wrap-', $this -> RawData);
// Restoring the BASE64 final equals sign (see a few lines above) // Restoring the BASE64 final equals sign (see a few lines above)
$this -> RawData = str_replace("-base64=-\n", "=\n", $this -> RawData); $this -> RawData = str_replace("-base64=-\r\n", "=\r\n", $this -> RawData);
$Lines = explode("\n", $this -> RawData); $Lines = explode("\r\n", $this -> RawData);
foreach ($Lines as $Line) foreach ($Lines as $Line)
{ {
@ -212,6 +216,7 @@ class vCard implements Countable, Iterator
$ItemIndex = (int)str_ireplace('item', '', $TmpKey[0]); $ItemIndex = (int)str_ireplace('item', '', $TmpKey[0]);
} }
if (count($KeyParts) > 1) if (count($KeyParts) > 1)
{ {
$Parameters = self::ParseParameters($Key, array_slice($KeyParts, 1)); $Parameters = self::ParseParameters($Key, array_slice($KeyParts, 1));
@ -262,7 +267,7 @@ class vCard implements Countable, Iterator
$Value = self::ParseStructuredValue($Value, $Key); $Value = self::ParseStructuredValue($Value, $Key);
if ($Type) if ($Type)
{ {
$Value['Type'] = $Type; $Value['type'] = $Type;
} }
} }
else else
@ -275,15 +280,15 @@ class vCard implements Countable, Iterator
if ($Type) if ($Type)
{ {
$Value = array( $Value = array(
'Value' => $Value, 'value' => $Value,
'Type' => $Type 'type' => $Type
); );
} }
} }
if (is_array($Value) && $Encoding) if (is_array($Value) && $Encoding)
{ {
$Value['Encoding'] = $Encoding; $Value['encoding'] = $Encoding;
} }
if (!isset($this -> Data[$Key])) if (!isset($this -> Data[$Key]))
@ -296,6 +301,22 @@ class vCard implements Countable, Iterator
} }
} }
/**
* method to get key list of the current vcard
*
* @return array list of key
*/
public function getKeyList()
{
$keylist=array();
if (isset($this -> Data))
{
foreach($this -> Data as $key => $val)
$keylist[]=$key;
}
return $keylist;
}
/** /**
* Magic method to get the various vCard values as object members, e.g. * Magic method to get the various vCard values as object members, e.g.
* a call to $vCard -> N gets the "N" value * a call to $vCard -> N gets the "N" value
@ -318,10 +339,10 @@ class vCard implements Countable, Iterator
$Value = $this -> Data[$Key]; $Value = $this -> Data[$Key];
foreach ($Value as $K => $V) foreach ($Value as $K => $V)
{ {
if (stripos($V['Value'], 'uri:') === 0) if (isset($V['Value']) && stripos($V['Value'], 'uri:') === 0)
{ {
$Value[$K]['Value'] = substr($V, 4); $Value[$K]['value'] = substr($V, 4);
$Value[$K]['Encoding'] = 'uri'; $Value[$K]['encoding'] = 'uri';
} }
} }
return $Value; return $Value;
@ -340,6 +361,20 @@ class vCard implements Countable, Iterator
return array(); return array();
} }
/**
* Magic method to check isset for the various vCard values as object members, e.g.
* a call to isset( $vCard -> fn ) checks existence of a value.
*
* @param string Key
*
* @return bool isset
*/
public function __isset($Key) {
$Key = strtolower($Key);
$val = $this->$Key;
return isset($val);
}
/** /**
* Saves an embedded file * Saves an embedded file
* *
@ -361,15 +396,15 @@ class vCard implements Countable, Iterator
} }
// Returing false if it is an image URL // Returing false if it is an image URL
if (stripos($this -> Data[$Key][$Index]['Value'], 'uri:') === 0) if (stripos($this -> Data[$Key][$Index]['value'], 'uri:') === 0)
{ {
return false; return false;
} }
if (is_writable($TargetPath) || (!file_exists($TargetPath) && is_writable(dirname($TargetPath)))) if (is_writable($TargetPath) || (!file_exists($TargetPath) && is_writable(dirname($TargetPath))))
{ {
$RawContent = $this -> Data[$Key][$Index]['Value']; $RawContent = $this -> Data[$Key][$Index]['value'];
if (isset($this -> Data[$Key][$Index]['Encoding']) && $this -> Data[$Key][$Index]['Encoding'] == 'b') if (isset($this -> Data[$Key][$Index]['encoding']) && $this -> Data[$Key][$Index]['encoding'] == 'b')
{ {
$RawContent = base64_decode($RawContent); $RawContent = base64_decode($RawContent);
} }
@ -404,10 +439,10 @@ class vCard implements Countable, Iterator
if (count($Arguments) > 1) if (count($Arguments) > 1)
{ {
$Types = array_values(array_slice($Arguments, 1)); $Types = array_map('strtolower', array_values(array_slice($Arguments, 1)));
if (isset(self::$Spec_StructuredElements[$Key]) && if (isset(self::$Spec_StructuredElements[$Key]) &&
in_array($Arguments[1], self::$Spec_StructuredElements[$Key]) in_array(strtolower($Arguments[1]), self::$Spec_StructuredElements[$Key])
) )
{ {
$LastElementIndex = 0; $LastElementIndex = 0;
@ -439,8 +474,8 @@ class vCard implements Countable, Iterator
elseif (isset(self::$Spec_ElementTypes[$Key])) elseif (isset(self::$Spec_ElementTypes[$Key]))
{ {
$this -> Data[$Key][] = array( $this -> Data[$Key][] = array(
'Value' => $Value, 'value' => $Value,
'Type' => $Types 'type' => $Types
); );
} }
} }
@ -475,9 +510,9 @@ class vCard implements Countable, Iterator
foreach ($Values as $Index => $Value) foreach ($Values as $Index => $Value)
{ {
$Text .= $KeyUC; $Text .= $KeyUC;
if (is_array($Value) && isset($Value['Type'])) if (is_array($Value) && isset($Value['type']))
{ {
$Text .= ';TYPE='.self::PrepareTypeStrForOutput($Value['Type']); $Text .= ';TYPE='.self::PrepareTypeStrForOutput($Value['type']);
} }
$Text .= ':'; $Text .= ':';
@ -492,7 +527,7 @@ class vCard implements Countable, Iterator
} }
elseif (is_array($Value) && isset(self::$Spec_ElementTypes[$Key])) elseif (is_array($Value) && isset(self::$Spec_ElementTypes[$Key]))
{ {
$Text .= $Value['Value']; $Text .= $Value['value'];
} }
else else
{ {
@ -574,7 +609,8 @@ class vCard implements Countable, Iterator
$Parameters = array(); $Parameters = array();
foreach ($RawParams as $Item) foreach ($RawParams as $Item)
{ {
$Parameters[] = explode('=', strtolower($Item)); // try to correct issue https://github.com/nuovo/vCard-parser/issues/20
$Parameters[] = explode('=', strtolower($Item),2);
} }
$Type = array(); $Type = array();
@ -603,6 +639,8 @@ class vCard implements Countable, Iterator
} }
} }
elseif (count($Parameter) > 2) elseif (count($Parameter) > 2)
{
if(count(explode(',', $RawParams[$Index], -1)) > 0)
{ {
$TempTypeParams = self::ParseParameters($Key, explode(',', $RawParams[$Index])); $TempTypeParams = self::ParseParameters($Key, explode(',', $RawParams[$Index]));
if ($TempTypeParams['type']) if ($TempTypeParams['type'])
@ -610,6 +648,7 @@ class vCard implements Countable, Iterator
$Type = array_merge($Type, $TempTypeParams['type']); $Type = array_merge($Type, $TempTypeParams['type']);
} }
} }
}
else else
{ {
switch ($Parameter[0]) switch ($Parameter[0])