summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax/addproperty.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/ajax/addproperty.php')
-rw-r--r--apps/contacts/ajax/addproperty.php45
1 files changed, 33 insertions, 12 deletions
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 2f932d752a7..f888b94e386 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -23,6 +23,13 @@
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+
+function bailOut($msg) {
+ OCP\JSON::error(array('data' => array('message' => $msg)));
+ OCP\Util::writeLog('contacts','ajax/addproperty.php: '.$msg, OCP\Util::DEBUG);
+ exit();
+}
$id = isset($_POST['id'])?$_POST['id']:null;
$name = isset($_POST['name'])?$_POST['name']:null;
@@ -31,11 +38,21 @@ $parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
$vcard = OC_Contacts_App::getContactVCard($id);
+if(!$name) {
+ bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
+}
+if(!$id) {
+ bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+}
+
+if(!$vcard) {
+ bailOut(OC_Contacts_App::$l10n->t('Could not parse contact: ').$id);
+}
+
if(!is_array($value)){
$value = trim($value);
if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add empty property.'))));
- exit();
+ bailOut(OC_Contacts_App::$l10n->t('Cannot add empty property.'));
}
} elseif($name === 'ADR') { // only add if non-empty elements.
$empty = true;
@@ -46,8 +63,7 @@ if(!is_array($value)){
}
}
if($empty) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('At least one of the address fields has to be filled out.'))));
- exit();
+ bailOut(OC_Contacts_App::$l10n->t('At least one of the address fields has to be filled out.'));
}
}
@@ -56,9 +72,7 @@ $current = $vcard->select($name);
foreach($current as $item) {
$tmpvalue = (is_array($value)?implode(';', $value):$value);
if($tmpvalue == $item->value) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Trying to add duplicate property: ').$name.': '.$tmpvalue)));
- OCP\Util::writeLog('contacts','ajax/addproperty.php: Trying to add duplicate property: '.$name.': '.$tmpvalue, OCP\Util::DEBUG);
- exit();
+ bailOut(OC_Contacts_App::$l10n->t('Trying to add duplicate property: '.$name.': '.$tmpvalue));
}
}
@@ -69,6 +83,7 @@ if(is_array($value)) {
$value = strip_tags($value);
}
+/* preprocessing value */
switch($name) {
case 'BDAY':
$date = New DateTime($value);
@@ -81,6 +96,8 @@ switch($name) {
case 'N':
case 'ORG':
case 'NOTE':
+ $value = str_replace('\n', ' \\n', $value);
+ break;
case 'NICKNAME':
// TODO: Escape commas and semicolons.
break;
@@ -92,8 +109,14 @@ switch($name) {
break;
}
-
-$property = $vcard->addProperty($name, $value); //, $parameters);
+switch($name) {
+ case 'NOTE':
+ $vcard->setString('NOTE', $value);
+ break;
+ default:
+ $property = $vcard->addProperty($name, $value); //, $parameters);
+ break;
+}
$line = count($vcard->children) - 1;
@@ -114,9 +137,7 @@ foreach ($parameters as $key=>$element) {
$checksum = md5($vcard->children[$line]->serialize());
if(!OC_Contacts_VCard::edit($id,$vcard)) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding contact property.'))));
- OCP\Util::writeLog('contacts','ajax/addproperty.php: Error updating contact property: '.$name, OCP\Util::ERROR);
- exit();
+ bailOut(OC_Contacts_App::$l10n->t('Error adding contact property: '.$name));
}
OCP\JSON::success(array('data' => array( 'checksum' => $checksum )));