diff options
Diffstat (limited to 'apps/contacts')
-rw-r--r-- | apps/contacts/ajax/addcard.php | 32 | ||||
-rw-r--r-- | apps/contacts/ajax/addproperty.php | 28 | ||||
-rw-r--r-- | apps/contacts/ajax/deletebook.php | 13 | ||||
-rw-r--r-- | apps/contacts/ajax/deletecard.php | 17 | ||||
-rw-r--r-- | apps/contacts/ajax/deleteproperty.php | 38 | ||||
-rw-r--r-- | apps/contacts/ajax/getdetails.php | 45 | ||||
-rw-r--r-- | apps/contacts/ajax/setproperty.php | 49 | ||||
-rw-r--r-- | apps/contacts/ajax/showaddcard.php | 6 | ||||
-rw-r--r-- | apps/contacts/ajax/showaddproperty.php | 16 | ||||
-rw-r--r-- | apps/contacts/ajax/showsetproperty.php | 39 | ||||
-rw-r--r-- | apps/contacts/appinfo/app.php | 1 | ||||
-rw-r--r-- | apps/contacts/index.php | 12 | ||||
-rw-r--r-- | apps/contacts/js/interface.js | 2 | ||||
-rw-r--r-- | apps/contacts/lib/app.php | 122 | ||||
-rw-r--r-- | apps/contacts/lib/vcard.php | 135 | ||||
-rw-r--r-- | apps/contacts/photo.php | 2 | ||||
-rw-r--r-- | apps/contacts/templates/index.php | 9 | ||||
-rw-r--r-- | apps/contacts/templates/part.details.php | 2 | ||||
-rw-r--r-- | apps/contacts/templates/part.property.FN.php | 9 | ||||
-rw-r--r-- | apps/contacts/templates/part.property.php | 2 | ||||
-rw-r--r-- | apps/contacts/templates/part.setpropertyform.php | 4 |
21 files changed, 215 insertions, 368 deletions
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php index dd5b90651f5..9d782246a0a 100644 --- a/apps/contacts/ajax/addcard.php +++ b/apps/contacts/ajax/addcard.php @@ -23,26 +23,20 @@ // Init owncloud require_once('../../../lib/base.php'); -$aid = $_POST['id']; -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$addressbook = OC_Contacts_Addressbook::find( $aid ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? - exit(); -} +$aid = $_POST['id']; +$addressbook = OC_Contacts_App::getAddressbook( $aid ); $fn = $_POST['fn']; $values = $_POST['value']; $parameters = $_POST['parameters']; -$vcard = new Sabre_VObject_Component('VCARD'); -$vcard->add(new Sabre_VObject_Property('FN',$fn)); -$vcard->add(new Sabre_VObject_Property('UID',OC_Contacts_VCard::createUID())); +$vcard = new OC_VObject('VCARD'); +$vcard->setUID(); +$vcard->setString('FN',$fn); // Data to add ... $add = array('TEL', 'EMAIL', 'ORG'); @@ -64,20 +58,8 @@ foreach( $add as $propname){ else{ $prop_parameters = array(); } - OC_Contacts_VCard::addVCardProperty($vcard, $propname, $value, $prop_parameters); + $vcard->addProperty($propname, $value, $prop_parameters); } $id = OC_Contacts_VCard::add($aid,$vcard->serialize()); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); - -$details = OC_Contacts_VCard::structureContact($vcard); -$name = $details['FN'][0]['value']; -$tmpl = new OC_Template('contacts','part.details'); -$tmpl->assign('details',$details); -$tmpl->assign('id',$id); -$tmpl->assign('adr_types',$adr_types); -$tmpl->assign('phone_types',$phone_types); -$page = $tmpl->fetchPage(); - -OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page ))); +OC_Contacts_App::renderDetails($id, $vcard); diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index 101cfabbe84..98877805b46 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -23,40 +23,20 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_POST['id']; -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} - -$vcard = OC_Contacts_VCard::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} +$id = $_POST['id']; +$vcard = OC_Contacts_App::getContactVCard( $id ); $name = $_POST['name']; $value = $_POST['value']; -$parameters = isset($_POST['parameteres'])?$_POST['parameters']:array(); +$parameters = isset($_POST['parameters'])?$_POST['parameters']:array(); -$property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters); +$property = $vcard->addProperty($name, $value, $parameters); $line = count($vcard->children) - 1; -$checksum = md5($property->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize()); diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php index 238975436e7..a89c00575e9 100644 --- a/apps/contacts/ajax/deletebook.php +++ b/apps/contacts/ajax/deletebook.php @@ -23,21 +23,14 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_POST['id']; - -OC_Log::write('contacts','deletebook.php: '.$id,OC_Log::DEBUG); - $l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$addressbook = OC_Contacts_Addressbook::find( $id ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} +//$id = $_GET['id']; +$id = $_POST['id']; +$addressbook = OC_Contacts_App::getAddressbook( $id ); OC_Contacts_Addressbook::delete($id); OC_JSON::success(array('data' => array( 'id' => $id ))); diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php index a0a6b8c3ea8..e26dfd6ebfe 100644 --- a/apps/contacts/ajax/deletecard.php +++ b/apps/contacts/ajax/deletecard.php @@ -23,25 +23,12 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_GET['id']; - -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} +$id = $_GET['id']; +$card = OC_Contacts_App::getContactObject( $id ); OC_Contacts_VCard::delete($id); OC_JSON::success(array('data' => array( 'id' => $id ))); diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php index 0a3a3c293a0..f69735e61c6 100644 --- a/apps/contacts/ajax/deleteproperty.php +++ b/apps/contacts/ajax/deleteproperty.php @@ -23,45 +23,15 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_GET['id']; -$checksum = $_GET['checksum']; - - -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} - -$vcard = OC_Contacts_VCard::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} +$id = $_GET['id']; +$checksum = $_GET['checksum']; -$line = null; -for($i=0;$i<count($vcard->children);$i++){ - if(md5($vcard->children[$i]->serialize()) == $checksum ){ - $line = $i; - } -} -if(is_null($line)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.')))); - exit(); -} +$vcard = OC_Contacts_App::getContactVCard( $id ); +$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum); unset($vcard->children[$line]); diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php index 260fb53a686..8cc0f9cbb0f 100644 --- a/apps/contacts/ajax/getdetails.php +++ b/apps/contacts/ajax/getdetails.php @@ -23,50 +23,11 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_GET['id']; - -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); +$id = $_GET['id']; +$vcard = OC_Contacts_App::getContactVCard( $id ); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} - -$vcard = OC_Contacts_VCard::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} - -$property_types = array( - 'ADR' => $l10n->t('Address'), - 'TEL' => $l10n->t('Telephone'), - 'EMAIL' => $l10n->t('Email'), - 'ORG' => $l10n->t('Organization'), -); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); - -$details = OC_Contacts_VCard::structureContact($vcard); -$tmpl = new OC_Template('contacts','part.details'); -$tmpl->assign('details',$details); -$tmpl->assign('id',$id); -$tmpl->assign('property_types',$property_types); -$tmpl->assign('adr_types',$adr_types); -$tmpl->assign('phone_types',$phone_types); -$page = $tmpl->fetchPage(); - -OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page ))); +OC_Contacts_App::renderDetails($id, $vcard); diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php index c9102c4a2ee..bcc4c161cc0 100644 --- a/apps/contacts/ajax/setproperty.php +++ b/apps/contacts/ajax/setproperty.php @@ -23,48 +23,20 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_POST['id']; -$checksum = $_POST['checksum']; -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} - -$vcard = OC_Contacts_VCard::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} +$id = $_POST['id']; +$checksum = $_POST['checksum']; -$line = null; -for($i=0;$i<count($vcard->children);$i++){ - if(md5($vcard->children[$i]->serialize()) == $checksum ){ - $line = $i; - } -} -if(is_null($line)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.')))); - exit(); -} +$vcard = OC_Contacts_App::getContactVCard( $id ); +$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum); // Set the value $value = $_POST['value']; if(is_array($value)){ - $value = OC_Contacts_VCard::escapeSemicolons($value); + $value = OC_VObject::escapeSemicolons($value); } $vcard->children[$line]->setValue($value); @@ -104,10 +76,15 @@ $checksum = md5($vcard->children[$line]->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize()); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); -$tmpl = new OC_Template('contacts','part.property'); +if ($vcard->children[$line]->name == 'FN'){ + $tmpl = new OC_Template('contacts','part.property.FN'); +} +else{ + $tmpl = new OC_Template('contacts','part.property'); +} $tmpl->assign('adr_types',$adr_types); $tmpl->assign('phone_types',$phone_types); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line)); diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php index 5842046f00c..92e24216c5e 100644 --- a/apps/contacts/ajax/showaddcard.php +++ b/apps/contacts/ajax/showaddcard.php @@ -23,14 +23,12 @@ // Init owncloud require_once('../../../lib/base.php'); -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); $addressbooks = OC_Contacts_Addressbook::allAddressbooks(OC_USER::getUser()); $tmpl = new OC_Template('contacts','part.addcardform'); diff --git a/apps/contacts/ajax/showaddproperty.php b/apps/contacts/ajax/showaddproperty.php index f87cd05359b..30eb7634f80 100644 --- a/apps/contacts/ajax/showaddproperty.php +++ b/apps/contacts/ajax/showaddproperty.php @@ -23,24 +23,12 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_GET['id']; -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} +$id = $_GET['id']; +$card = OC_Contacts_App::getContactObject( $id ); $tmpl = new OC_Template('contacts','part.addpropertyform'); $tmpl->assign('id',$id); diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php index 2ec4b89b824..e23fa21c56b 100644 --- a/apps/contacts/ajax/showsetproperty.php +++ b/apps/contacts/ajax/showsetproperty.php @@ -23,46 +23,19 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_GET['id']; -$checksum = $_GET['checksum']; -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$card = OC_Contacts_VCard::find( $id ); -if( $card === false ){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); - exit(); -} - -$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.')))); - exit(); -} +$id = $_GET['id']; +$checksum = $_GET['checksum']; -$vcard = OC_Contacts_VCard::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} +$vcard = OC_Contacts_App::getContactVCard( $id ); -$line = null; -for($i=0;$i<count($vcard->children);$i++){ - if(md5($vcard->children[$i]->serialize()) == $checksum ){ - $line = $i; - } -} -if(is_null($line)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.')))); - exit(); -} +$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); $tmpl = new OC_Template('contacts','part.setpropertyform'); $tmpl->assign('id',$id); diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php index fc7b3769c53..524cc640bc9 100644 --- a/apps/contacts/appinfo/app.php +++ b/apps/contacts/appinfo/app.php @@ -1,5 +1,6 @@ <?php +OC::$CLASSPATH['OC_Contacts_App'] = 'apps/contacts/lib/app.php'; OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php'; OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php'; OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php'; diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 917335fb68b..29c9e4f1219 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -69,15 +69,15 @@ foreach( $openaddressbooks as $addressbook ){ } usort($contacts,'contacts_namesort'); -$details = array(); -if( !is_null($id) || count($contacts)){ +$details = array(); +if( !is_null($id)/* || count($contacts)*/){ if(is_null($id)) $id = $contacts[0]['id']; - $contact = OC_Contacts_VCard::find($id); - $vcard = OC_Contacts_VCard::parse($contact['carddata']); + $vcard = OC_Contacts_App::getContactVCard($id); $details = OC_Contacts_VCard::structureContact($vcard); } +<<<<<<< HEAD // Include Style and Script OC_Util::addScript('contacts','interface'); OC_Util::addStyle('contacts','styles'); @@ -88,6 +88,10 @@ OC_Util::addStyle('', 'jquery.multiselect'); $l10n = new OC_L10N('contacts'); $adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); $phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +======= +$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); +>>>>>>> eeaf539a4414e3081b6f6652167363a3221a1973 // Process the template $tmpl = new OC_Template( 'contacts', 'index', 'user' ); diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js index 8e699f52c93..2937e8a0925 100644 --- a/apps/contacts/js/interface.js +++ b/apps/contacts/js/interface.js @@ -238,7 +238,7 @@ $(document).ready(function(){ $('.contacts_property [data-use="edit"]').live('click',function(){ var id = $('#rightcontent').data('id'); - var checksum = $(this).parents('li').first().data('checksum'); + var checksum = $(this).parents('.contacts_property').first().data('checksum'); $.getJSON('ajax/showsetproperty.php',{'id': id, 'checksum': checksum },function(jsondata){ if(jsondata.status == 'success'){ $('.contacts_property[data-checksum="'+checksum+'"]').html(jsondata.data.page) diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php new file mode 100644 index 00000000000..ba086e4aca8 --- /dev/null +++ b/apps/contacts/lib/app.php @@ -0,0 +1,122 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher bartv@thisnet.nl + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * This class manages our app actions + */ +OC_Contacts_App::$l10n = new OC_L10N('contacts'); +class OC_Contacts_App{ + public static $l10n; + + /** + * Render templates/part.details to json output + * @param int $id of contact + * @param Sabre_VObject_Component $vcard to render + */ + public static function renderDetails($id, $vcard){ + $property_types = self::getAddPropertyOptions(); + $adr_types = self::getTypesOfProperty('ADR'); + $phone_types = self::getTypesOfProperty('TEL'); + + $details = OC_Contacts_VCard::structureContact($vcard); + $name = $details['FN'][0]['value']; + $tmpl = new OC_Template('contacts','part.details'); + $tmpl->assign('details',$details); + $tmpl->assign('id',$id); + $tmpl->assign('property_types',$property_types); + $tmpl->assign('adr_types',$adr_types); + $tmpl->assign('phone_types',$phone_types); + $page = $tmpl->fetchPage(); + + OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page ))); + } + + public static function getAddressbook($id){ + $addressbook = OC_Contacts_Addressbook::find( $id ); + if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ + OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? + exit(); + } + return $addressbook; + } + + public static function getContactObject($id){ + $card = OC_Contacts_VCard::find( $id ); + if( $card === false ){ + OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('Contact could not be found.')))); + exit(); + } + + self::getAddressbook( $card['addressbookid'] ); + return $card; + } + + public static function getContactVCard($id){ + $card = self::getContactObject( $id ); + + $vcard = OC_VObject::parse($card['carddata']); + // Check if the card is valid + if(is_null($vcard)){ + OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('vCard could not be read.')))); + exit(); + } + return $vcard; + } + + public static function getPropertyLineByChecksum($vcard, $checksum){ + $line = null; + for($i=0;$i<count($vcard->children);$i++){ + if(md5($vcard->children[$i]->serialize()) == $checksum ){ + $line = $i; + } + } + if(is_null($line)){ + OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('Information about vCard is incorrect. Please reload the page.')))); + exit(); + } + return $line; + } + + /** + * @return array of vcard prop => label + */ + public static function getAddPropertyOptions(){ + $l10n = self::$l10n; + return array( + 'ADR' => $l10n->t('Address'), + 'TEL' => $l10n->t('Telephone'), + 'EMAIL' => $l10n->t('Email'), + 'ORG' => $l10n->t('Organization'), + ); + } + + /** + * @return types for property $prop + */ + public static function getTypesOfProperty($prop){ + $l = self::$l10n; + switch($prop){ + case 'ADR': + return array( + 'WORK' => $l->t('Work'), + 'HOME' => $l->t('Home'), + ); + case 'TEL': + return array( + 'HOME' => $l->t('Home'), + 'CELL' => $l->t('Mobile'), + 'WORK' => $l->t('Work'), + 'TEXT' => $l->t('Text'), + 'VOICE' => $l->t('Voice'), + 'FAX' => $l->t('Fax'), + 'VIDEO' => $l->t('Video'), + 'PAGER' => $l->t('Pager'), + ); + } + } +} diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index b03e6ede998..87f2ff5e666 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -111,31 +111,21 @@ class OC_Contacts_VCard{ */ public static function add($id,$data){ $fn = null; - $uri = null; - $card = self::parse($data); + $card = OC_VObject::parse($data); if(!is_null($card)){ - // VCARD must have a version - $hasversion = false; - foreach($card->children as $property){ - if($property->name == 'FN'){ - $fn = $property->value; - } - elseif($property->name == 'VERSION'){ - $hasversion = true; - } - elseif(is_null($uri) && $property->name == 'UID' ){ - $uri = $property->value.'.vcf'; - } - } - if(is_null($uri)){ - $uid = self::createUID(); - $uri = $uid.'.vcf'; - $card->add(new Sabre_VObject_Property('UID',$uid)); + $fn = $card->getAsString('FN'); + $uid = $card->getAsString('UID'); + if(is_null($uid)){ + $card->setUID(); + $uid = $card->getAsString('UID'); $data = $card->serialize(); }; + $uri = $uid.'.vcf'; + // VCARD must have a version + $version = $card->getAsString('VERSION'); // Add version if needed - if(!$hasversion){ + if(is_null($version)){ $card->add(new Sabre_VObject_Property('VERSION','3.0')); $data = $card->serialize(); } @@ -163,7 +153,7 @@ class OC_Contacts_VCard{ */ public static function addFromDAVData($id,$uri,$data){ $fn = null; - $card = self::parse($data); + $card = OC_VObject::parse($data); if(!is_null($card)){ foreach($card->children as $property){ if($property->name == 'FN'){ @@ -190,7 +180,7 @@ class OC_Contacts_VCard{ $oldcard = self::find($id); $fn = null; - $card = self::parse($data); + $card = OC_VObject::parse($data); if(!is_null($card)){ foreach($card->children as $property){ if($property->name == 'FN'){ @@ -218,7 +208,7 @@ class OC_Contacts_VCard{ $oldcard = self::findWhereDAVDataIs($aid,$uri); $fn = null; - $card = self::parse($data); + $card = OC_VObject::parse($data); if(!is_null($card)){ foreach($card->children as $property){ if($property->name == 'FN'){ @@ -269,67 +259,6 @@ class OC_Contacts_VCard{ } /** - * @brief Escapes semicolons - * @param string $value - * @return string - */ - public static function escapeSemicolons($value){ - foreach($value as &$i ){ - $i = implode("\\\\;", explode(';', $i)); - } - return implode(';',$value); - } - - /** - * @brief Creates an array out of a multivalue property - * @param string $value - * @return array - */ - public static function unescapeSemicolons($value){ - $array = explode(';',$value); - for($i=0;$i<count($array);$i++){ - if(substr($array[$i],-2,2)=="\\\\"){ - if(isset($array[$i+1])){ - $array[$i] = substr($array[$i],0,count($array[$i])-2).';'.$array[$i+1]; - unset($array[$i+1]); - } - else{ - $array[$i] = substr($array[$i],0,count($array[$i])-2).';'; - } - $i = $i - 1; - } - } - return $array; - } - - /** - * @brief Add property to vcard object - * @param object $vcard - * @param object $name of property - * @param object $value of property - * @param object $paramerters of property - */ - public static function addVCardProperty($vcard, $name, $value, $parameters=array()){ - if(is_array($value)){ - $value = OC_Contacts_VCard::escapeSemicolons($value); - } - $property = new Sabre_VObject_Property( $name, $value ); - $parameternames = array_keys($parameters); - foreach($parameternames as $i){ - $values = $parameters[$i]; - if (!is_array($values)){ - $values = array($values); - } - foreach($values as $value){ - $property->add($i, $value); - } - } - - $vcard->add($property); - return $property; - } - - /** * @brief Data structure of vCard * @param object $property * @return associative array @@ -365,7 +294,7 @@ class OC_Contacts_VCard{ $value = $property->value; $value = htmlspecialchars($value); if($property->name == 'ADR' || $property->name == 'N'){ - $value = self::unescapeSemicolons($value); + $value = OC_VObject::unescapeSemicolons($value); } $temp = array( 'name' => $property->name, @@ -392,40 +321,4 @@ class OC_Contacts_VCard{ } return $temp; } - - /** - * @brief Parses a vcard file - * @param string vCard - * @return Sabre_VObject or null - * - * Will retun the vobject if sabre DAV is able to parse the file. - */ - public static function parse($data){ - try { - $card = Sabre_VObject_Reader::read($data); - return $card; - } catch (Exception $e) { - return null; - } - } - public static function getTypesOfProperty($l, $prop){ - switch($prop){ - case 'ADR': - return array( - 'WORK' => $l->t('Work'), - 'HOME' => $l->t('Home'), - ); - case 'TEL': - return array( - 'HOME' => $l->t('Home'), - 'CELL' => $l->t('Mobile'), - 'WORK' => $l->t('Work'), - 'TEXT' => $l->t('Text'), - 'VOICE' => $l->t('Voice'), - 'FAX' => $l->t('Fax'), - 'VIDEO' => $l->t('Video'), - 'PAGER' => $l->t('Pager'), - ); - } - } } diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php index 5178fe7a078..60dd81140bf 100644 --- a/apps/contacts/photo.php +++ b/apps/contacts/photo.php @@ -41,7 +41,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ exit(); } -$content = OC_Contacts_VCard::parse($card['carddata']); +$content = OC_VObject::parse($card['carddata']); // invalid vcard if( is_null($content)){ diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 2ecadb4d60f..44505031c64 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -13,7 +13,14 @@ </ul> </div> <div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>"> - <?php echo $this->inc("part.addcardform"); ?> + <?php + if ($_['id']){ + echo $this->inc("part.details"); + } + else{ + echo $this->inc("part.addcardform"); + } + ?> </div> <!-- Dialogs --> <div id="dialog_holder"></div> diff --git a/apps/contacts/templates/part.details.php b/apps/contacts/templates/part.details.php index f6d69005a08..afad0b7f64c 100644 --- a/apps/contacts/templates/part.details.php +++ b/apps/contacts/templates/part.details.php @@ -1,5 +1,5 @@ <?php if(array_key_exists('FN',$_['details'])): ?> - <p id="contacts_details_name"><?php echo $_['details']['FN'][0]['value']; ?></p> + <?php echo $this->inc('part.property.FN', array('property' => $_['details']['FN'][0])); ?> <img class="svg action" id="contacts_deletecard" src="<?php echo image_path('', 'actions/delete.svg'); ?>" title="<?php echo $l->t('Delete contact');?>" /> <?php if(isset($_['details']['PHOTO'])): // Emails first ?> diff --git a/apps/contacts/templates/part.property.FN.php b/apps/contacts/templates/part.property.FN.php new file mode 100644 index 00000000000..83cef94e303 --- /dev/null +++ b/apps/contacts/templates/part.property.FN.php @@ -0,0 +1,9 @@ + <p id="contacts_details_name" class="contacts_property" data-checksum="<?php echo $_['property']['checksum']; ?>"> + <?php echo $_['property']['value']; ?> + <span style="display:none;" data-use="edit"><img class="svg action" src="<?php echo image_path('', 'actions/rename.svg'); ?>" /></span> + </p> +<?php if (!isset($_['details'])): ?> +<script> +$('#leftcontent li.active a').text('<?php echo $_['property']['value']; ?>'); +</script> +<?php endif ?> diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php index afef4311260..6264f296743 100644 --- a/apps/contacts/templates/part.property.php +++ b/apps/contacts/templates/part.property.php @@ -20,7 +20,7 @@ <span style="display:none;" data-use="delete"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></span> </p> <?php elseif($_['property']['name'] == 'TEL'): ?> - <p class="contacts_property_name"><?php echo $l->t('Phone'); ?></p> + <p class="contacts_property_name"><?php echo $_['property']['parameters']['PREF'] ? $l->t('Preferred').' ' : '' ?><?php echo $l->t('Phone'); ?></p> <p class="contacts_property_data"> <?php echo $_['property']['value']; ?> <?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?> diff --git a/apps/contacts/templates/part.setpropertyform.php b/apps/contacts/templates/part.setpropertyform.php index f216a55f5e9..8635d7db1ce 100644 --- a/apps/contacts/templates/part.setpropertyform.php +++ b/apps/contacts/templates/part.setpropertyform.php @@ -1,7 +1,9 @@ <form id="contacts_setpropertyform"> <input type="hidden" name="checksum" value="<?php echo $_['property']['checksum']; ?>"> <input type="hidden" name="id" value="<?php echo $_['id']; ?>"> - <?php if($_['property']['name']=='ADR'): ?> + <?php if($_['property']['name']=='FN'): ?> + <p class="contacts_property_data"><input id="fn" type="text" name="value" value="<?php echo $_['property']['value']; ?>"></p> + <?php elseif($_['property']['name']=='ADR'): ?> <p class="contacts_property_name"><label for="adr_pobox"><?php echo $l->t('Address'); ?></label></p> <ol class="contacts_property_data" id="contacts_addresspart"> <li class="input"> |