Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1880446
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
75 KB
Subscribers
None
View Options
diff --git a/action/ajax.php b/action/ajax.php
--- a/action/ajax.php
+++ b/action/ajax.php
@@ -1,214 +1,228 @@
<?php
/**
* DokuWiki DAVCard PlugIn - Ajax component
*/
if(!defined('DOKU_INC')) die();
class action_plugin_davcard_ajax extends DokuWiki_Action_Plugin {
/**
* @var helper_plugin_davcard
*/
private $hlp = null;
function __construct() {
$this->hlp =& plugin_load('helper','davcard');
}
function register(Doku_Event_Handler $controller) {
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
}
function handle_ajax_call_unknown(&$event, $param) {
if($event->data != 'plugin_davcard') return;
$event->preventDefault();
$event->stopPropagation();
global $INPUT;
$action = trim($INPUT->post->str('action'));
$id = trim($INPUT->post->str('id'));
$page = trim($INPUT->post->str('page'));
$params = $INPUT->post->arr('params');
if(isset($_SERVER['REMOTE_USER']) && !is_null($_SERVER['REMOTE_USER']))
$user = $_SERVER['REMOTE_USER'];
else
$user = null;
if(!checkSecurityToken())
{
echo "CSRF Attack.";
return;
}
$data = array();
$data['result'] = false;
$data['html'] = $this->getLang('unknown_error');
// Parse the requested action
switch($action)
{
// Add a new Contact
case 'newContact':
if($this->hlp->addContactEntryToAddressbookForPage($id, $user, $params) === true)
{
$data['result'] = true;
}
else
{
$data['result'] = false;
$data['html'] = $this->getLang('error_adding');
}
break;
// Retrieve contact details
case 'getContactDetails':
$contactdata = $this->hlp->getContactByUri($id, $params['uri']);
if($contactdata['result'] === true)
{
$data['result'] = true;
$data['contactdata'] = $contactdata;
}
else
{
$data['result'] = false;
$data['html'] = $this->getLang('contact_not_found');
}
break;
// Edit a contact
case 'editContact':
-
+ if($this->hlp->editContactEntryToAddressbookForPage($id, $user, $params['uri'], $params) === true)
+ {
+ $data['result'] = true;
+ }
+ else
+ {
+ $data['result'] = false;
+ $data['html'] = $this->getLang('error_editing');
+ }
break;
// Delete a Contact
case 'deleteContact':
break;
// Get AJAX popup
case 'getContactAjax':
$contactdata = $this->hlp->getContactByUri($id, $params['uri']);
$cardpattern = $this->getConf('popup_content');
echo '<div class="plugin_davcard_popup_container">';
- foreach($contactdata['photo'] as $type => $photodata)
+ foreach($contactdata['photo'] as $data)
{
+ if(isset($data['type']))
+ $type = $data['type'];
+ else
+ $type = '';
echo '<div class="plugin_davcard_popup_image">';
- $type = strtolower($type);
- $imgdata = base64_encode($photodata);
+ $imgdata = base64_encode($data['photo']);
$pattern = '/^(?:[;\/?:@&=+$,]|(?:[^\W_]|[-_.!~*\()\[\] ])|(?:%[\da-fA-F]{2}))*$/';
// PNG images
if($type == 'png')
{
$imgdata = 'data:image/png;base64,'.$imgdata;
echo '<img src="'.$imgdata.'" alt="contact image" />';
}
// JPEG images
elseif(($type == 'jpeg') || ($type == 'jpg'))
{
$imgdata = 'data:image/jpeg;base64,'.$imgdata;
echo '<img src="'.$imgdata.'" alt="contact image" />';
}
// GIF images
elseif($type == 'gif')
{
$imgdata = 'data:image/gif;base64,'.$imgdata;
echo '<img src="'.$imgdata.'" alt="contact image" />';
}
// URLs (no type given)
elseif(preg_match( $pattern, $string ) == 1)
{
- echo '<img src="'.$photodata.'" alt="contact image" />';
+ echo '<img src="'.$data['photo'].'" alt="contact image" />';
}
echo '</div>';
}
echo '<div class="plugin_davcard_popup_content">';
$contactname = explode(';', $contactdata['structuredname']);
if(count($contactname) > 1)
{
$cardpattern = str_replace('<DCLASTNAME>', $contactname[0], $cardpattern);
$cardpattern = str_replace('<DCFIRSTNAME>', $contactname[1], $cardpattern);
}
if(count($contactdata['addr']) > 0)
{
- foreach($contactdata['addr'] as $type => $addr)
+ foreach($contactdata['addr'] as $data)
{
- $type = strtolower($type);
- if($type == 'work')
+ if(isset($data['type']) && ($data['type'] == 'work'))
$prefix = 'WORK';
else
$prefix = 'PRIVATE';
- $cardpattern = str_replace('<DC'.$prefix.'STREET>', $addr[2], $cardpattern);
- $cardpattern = str_replace('<DC'.$prefix.'CITY>', $addr[3], $cardpattern);
- $cardpattern = str_replace('<DC'.$prefix.'ZIP>', $addr[5], $cardpattern);
- $cardpattern = str_replace('<DC'.$prefix.'COUNTRY>', $addr[6], $cardpattern);
+ $cardpattern = str_replace('<DC'.$prefix.'STREET>', $data['address'][2], $cardpattern);
+ $cardpattern = str_replace('<DC'.$prefix.'CITY>', $data['address'][3], $cardpattern);
+ $cardpattern = str_replace('<DC'.$prefix.'ZIP>', $data['address'][5], $cardpattern);
+ $cardpattern = str_replace('<DC'.$prefix.'COUNTRY>', $data['address'][6], $cardpattern);
}
}
if(count($contactdata['tel']) > 0)
{
$telArr = array();
- foreach($contactdata['tel'] as $type => $tel)
+ foreach($contactdata['tel'] as $data)
{
- $type = strtolower($type);
- $telArr[] = $this->getLang('tel'.strtolower($type)).': '.$tel;
+ if(isset($data['type']))
+ $type = $data['type'];
+ else
+ $type = 'other';
+ $type = $data['type'];
+ $telArr[] = $this->getLang('tel'.$type).': '.$data['number'];
}
$telStr = implode(' \\\\ ', $telArr);
$cardpattern = str_replace('<DCPHONE>', $telStr, $cardpattern);
}
if(count($contactdata['mail']) > 0)
{
$mailArr = array();
- foreach($contactdata['mail'] as $type => $mail)
+ foreach($contactdata['mail'] as $data)
{
- $mailArr[] = '[['.$mail.']]';
+ $mailArr[] = '[['.$data['mail'].']]';
}
$mailStr = implode(' \\\\ ', $mailArr);
$cardpattern = str_replace('<DCEMAIL>', $mailStr, $cardpattern);
}
if($contactdata['birthday'] != '')
{
$date = DateTime::createFromFormat('Ymd', $contactdata['birthday']);
$dateStr = $date->format($this->getConf('date_format'));
$cardpattern = str_replace('<DCBIRTHDAY>', $dateStr, $cardpattern);
}
if($contactdata['note'] != '')
{
$notestr = str_replace('\n', ' \\ ', $contactdata['note']);
$cardpattern = str_replace('<DCNOTE>', $notestr, $cardpattern);
}
if($contactdata['title'] != '')
{
$cardpattern = str_replace('<DCTITLE>', $contactdata['title'], $cardpattern);
}
if($contactdata['url'] != '')
{
$url = $contactdata['url'];
if(strpos($url, '://') === false)
$url = 'http://'.$url;
$url = '[['.$url.']]';
$cardpattern = str_replace('<DCWEBSITE>', $url, $cardpattern);
}
$replace_match = '/^.*<DC.*>.*$(?:\r\n|\n)?/m';
$cardpattern = preg_replace($replace_match, '', $cardpattern);
echo $this->render_text($cardpattern);
echo '</div>';
echo '</div>';
return;
break;
}
// If we are still here, JSON output is requested
//json library of DokuWiki
require_once DOKU_INC . 'inc/JSON.php';
$json = new JSON();
//set content type
header('Content-Type: application/json');
echo $json->encode($data);
}
}
diff --git a/helper.php b/helper.php
--- a/helper.php
+++ b/helper.php
@@ -1,491 +1,579 @@
<?php
/**
* Helper Class for the DAVCard plugin
* This helper does the actual work.
*
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class helper_plugin_davcard extends DokuWiki_Plugin {
protected $sqlite = null;
/**
* Constructor to load the configuration
*/
public function helper_plugin_davcard() {
$this->sqlite =& plugin_load('helper', 'sqlite');
global $conf;
if(!$this->sqlite)
{
if($conf['allowdebug'])
dbglog('This plugin requires the sqlite plugin. Please install it.');
msg('This plugin requires the sqlite plugin. Please install it.');
return;
}
if(!$this->sqlite->init('davcard', DOKU_PLUGIN.'davcard/db/'))
{
if($conf['allowdebug'])
dbglog('Error initialising the SQLite DB for DAVCard');
return;
}
}
private function getContactByDetails($id, $type, $params = array())
{
if(strpos($id, 'webdav://') === 0)
{
$wdc =& plugin_load('helper', 'webdavclient');
if(is_null($wdc))
return $this->getLang('no_wdc');
$connectionId = str_replace('webdav://', '', $id);
$settings = $wdc->getConnection($connectionId);
if($settings === false)
return array('formattedname' => $this->getLang('settings_not_found'));
if($settings['type'] !== 'contacts')
return array('formattedname' => $this->getLang('wrong_type'));
$entries = $wdc->getAddressbookEntries($connectionId);
}
else
{
$entries = $this->getAddressbookEntries($id);
}
foreach($entries as $entry)
{
switch($type)
{
case 'structuredname':
$contactdata = explode(';', strtolower($entry['structuredname']));
if(count($contactdata) < 2) // We need at least first and lat name
return array('formattedname' => $this->getLang('contact_not_found'));
if(($params['lastname'] != '') &&
($contactdata[0] === $params['lastname'])
|| $params['lastname'] === '')
{
// last name matched or no last name given
if(($params['firstname'] != '') &&
($contactdata[1] === $params['firstname'])
|| $params['firstname'] === '')
{
// first name matched too or no first name given
$info = $this->parseVcard($entry['contactdata'], $entry['uri']);
return $info;
}
}
break;
case 'formattedname':
if(trim(strtolower($entry['formattedname'])) == $params['formattedname'])
{
$info = $this->parseVcard($entry['contactdata'], $entry['uri']);
return $info;
}
break;
case 'email':
$info = $this->parseVcard($entry['contactdata'], $entry['uri']);
- foreach($info['mail'] as $key => $mail)
+ foreach($info['mail'] as $data)
{
- if($mail === strtolower($params['email']))
+ if($data['mail'] === strtolower($params['email']))
return $info;
}
break;
}
}
return array('formattedname' => $this->getLang('contact_not_found'));
}
private function getAddressbookEntries($id)
{
$query = "SELECT contactdata, uri, formattedname, structuredname FROM addressbookobjects WHERE addressbookid = ?";
$res = $this->sqlite->query($query, $id);
return $this->sqlite->res2arr($res);
}
public function getContactByStructuredName($id, $firstname = '', $lastname = '')
{
return $this->getContactByDetails($id, 'structuredname',
array('firstname' => strtolower($firstname), 'lastname' => strtolower($lastname)));
}
public function getContactByEmail($id, $email)
{
// FIXME: Maybe it's a good idea to save the e-mail in the database as well!
return $this->getContactByDetails($id, 'email', array('email' => strtolower($email)));
}
public function getContactByFormattedName($id, $name)
{
return $this->getContactByDetails($id, 'formattedname', array('formattedname' => strtolower($name)));
}
public function getContactByUri($id, $uri)
{
if(strpos($id, 'webdav://') === 0)
{
$wdc =& plugin_load('helper', 'webdavclient');
if(is_null($wdc))
return $this->getLang('no_wdc');
$connectionId = str_replace('webdav://', '', $id);
$settings = $wdc->getConnection($connectionId);
if($settings === false)
return array('formattedname' => $this->getLang('settings_not_found'), 'result' => false);
if($settings['type'] !== 'contacts')
return array('formattedname' => $this->getLang('wrong_type'), 'result' => false);
$row = $wdc->getAddressbookEntryByUri($connectionId, $uri);
}
else
{
$row = $this->getAddressbookEntryByUri($id, $uri);
}
if($row === false)
return array('formattedname' => $this->getLang('contact_not_found'), 'result' => false);
$info = $this->parseVcard($row['contactdata'], $row['uri']);
$info['result'] = true;
return $info;
}
private function getAddressbookEntryByUri($id, $uri)
{
$query = "SELECT contactdata, addressbookid, etag, uri, formattedname, structuredname FROM addressbookobjects WHERE addressbookid = ? AND uri = ?";
$res = $this->sqlite->query($query, $id, $uri);
return $this->sqlite->res2row($res);
}
public function setAddressbookNameForPage($name, $description, $id = null, $userid = null)
{
if(is_null($id))
{
global $ID;
$id = $ID;
}
if(is_null($userid))
{
if(isset($_SERVER['REMOTE_USER']) && !is_null($_SERVER['REMOTE_USER']))
{
$userid = $_SERVER['REMOTE_USER'];
}
else
{
$userid = uniqid('davcard-');
}
}
$bookid = $this->getAddressbookIdForPage($id);
if($bookid === false)
return $this->createAddressbookForPage($name, $description, $id, $userid);
$query = "UPDATE addressbooks SET displayname = ?, description = ? WHERE id = ?";
$res = $this->sqlite->query($query, $name, $description, $bookid);
if($res !== false)
return true;
return false;
}
public function getAddressbookIdForPage($id = null)
{
if(is_null($id))
{
global $ID;
$id = $ID;
}
$query = "SELECT addressbookid FROM pagetoaddressbookmapping WHERE page = ?";
$res = $this->sqlite->query($query, $id);
$row = $this->sqlite->res2row($res);
if(isset($row['addressbookid']))
{
$calid = $row['addressbookid'];
return $calid;
}
return false;
}
public function createAddressbookForPage($name, $description, $id = null, $userid = null)
{
if(is_null($id))
{
global $ID;
$id = $ID;
}
if(is_null($userid))
{
if(isset($_SERVER['REMOTE_USER']) && !is_null($_SERVER['REMOTE_USER']))
{
$userid = $_SERVER['REMOTE_USER'];
}
else
{
$userid = uniqid('davcard-');
}
}
$values = array('principals/'.$userid,
$name,
str_replace(array('/', ' ', ':'), '_', $id),
$description,
1);
$query = "INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) ".
"VALUES (?, ?, ?, ?, ?)";
$res = $this->sqlite->query($query, $values);
if($res === false)
return false;
// Get the new addressbook ID
$query = "SELECT id FROM addressbooks WHERE principaluri = ? AND displayname = ? AND ".
"uri = ? AND description = ? AND synctoken = ?";
$res = $this->sqlite->query($query, $values);
$row = $this->sqlite->res2row($res);
// Update the pagetocalendarmapping table with the new calendar ID
if(isset($row['id']))
{
$query = "INSERT INTO pagetoaddressbookmapping (page, addressbookid) VALUES (?, ?)";
$res = $this->sqlite->query($query, $id, $row['id']);
return ($res !== false);
}
return false;
}
+
+ public function editContactEntryToAddressbookForPage($id, $user, $uri, $params)
+ {
+ require_once(DOKU_PLUGIN.'davcard/vendor/autoload.php');
+
+ if(strpos($id, 'webdav://') === 0)
+ {
+ $wdc =& plugin_load('helper', 'webdavclient');
+ if(is_null($wdc))
+ return $this->getLang('no_wdc');
+ $connectionId = str_replace('webdav://', '', $id);
+ $settings = $wdc->getConnection($connectionId);
+
+ if($settings === false)
+ return array('formattedname' => $this->getLang('settings_not_found'), 'result' => false);
+ if($settings['type'] !== 'contacts')
+ return array('formattedname' => $this->getLang('wrong_type'), 'result' => false);
+
+ $row = $wdc->getAddressbookEntryByUri($connectionId, $uri);
+ }
+ else
+ {
+ $row = $this->getAddressbookEntryByUri($id, $uri);
+ }
+
+ $vcard = \Sabre\VObject\Reader::read($row['contactdata']);
+
+ $vcard->remove('ADR');
+ $vcard->remove('TEL');
+ $vcard->remove('EMAIL');
+
+ if(isset($params['phones']))
+ {
+ foreach($params['phones'] as $data)
+ {
+ $vcard->add('TEL', $data['number'], array('type' => $data['type']));
+ }
+ }
+
+ if(isset($params['email']))
+ {
+ foreach($params['email'] as $data)
+ {
+ $vcard->add('EMAIL', $data['mail'], array('type' => $data['type']));
+ }
+ }
+
+ if(isset($params['addresses']))
+ {
+ foreach($params['addresses'] as $data)
+ {
+ $vcard->add('ADR', array('', '', $data['street'], $data['city'], '', $data['zipcode'], $data['country']), array('type' => $data['type']));
+ }
+ }
+
+ $structuredname = explode(';', (string)$vcard->N);
+ $structuredname[0] = $params['lastname'];
+ $structuredname[1] = $params['firstname'];
+ $formattedname = $params['firstname'].' '.$params['lastname']; // FIXME: Make this configurable?
+ $vcard->N = $structuredname;
+ $vcard->FN = $formattedname;
+
+ $contactdata = $vcard->serialize();
+
+ if(strpos($id, 'webdav://') === 0)
+ {
+ return $wdc->editAddressbookEntry($connectionId, $uri, $contactdata);
+ }
+ else
+ {
+ $now = new \DateTime();
+ $query = "UPDATE addressbookobjects SET (contactdata = ?, lastmodified = ?, etag = ?, size = ?, formattedname = ?, structuredname = ?) WHERE addressbookid = ? AND uri = ?";
+ $res = $this->sqlite->query($query,
+ $contactdata,
+ $now->getTimestamp(),
+ md5($contactdata),
+ strlen($contactdata),
+ $formattedname,
+ $structuredname,
+ $id,
+ $uri
+ );
+ if($res !== false)
+ {
+ $this->updateSyncTokenLog($id, $uri, 'modified');
+ return true;
+ }
+ }
+ return false;
+ }
public function addContactEntryToAddressbookForPage($id, $user, $params)
{
require_once(DOKU_PLUGIN.'davcard/vendor/autoload.php');
$vcard = new \Sabre\VObject\Component\VCard();
$formattedname = $params['firstname'].' '.$params['lastname']; // FIXME: Make this configurable?
$structuredname = array($params['lastname'], $params['firstname'], '', '', '');
- $vcard->FN = $formattedname;
+ $vcard->FN = $formattedname;
+ $vcard->N = $structuredname;
- print_r($params);
if(isset($params['phones']))
{
foreach($params['phones'] as $data)
{
$vcard->add('TEL', $data['number'], array('type' => $data['type']));
}
}
if(isset($params['email']))
{
- foreach($params['email'] as $mail => $data)
+ foreach($params['email'] as $data)
{
- $vcard->add('EMAIL', $data);
+ $vcard->add('EMAIL', $data['mail'], array('type' => $data['type']));
}
}
if(isset($params['addresses']))
{
foreach($params['addresses'] as $data)
{
$vcard->add('ADR', array('', '', $data['street'], $data['city'], '', $data['zipcode'], $data['country']), array('type' => $data['type']));
}
}
- $vcard->N = $structuredname;
-
-
$contactdata = $vcard->serialize();
if(strpos($id, 'webdav://') === 0)
{
$wdc =& plugin_load('helper', 'webdavclient');
if(is_null($wdc))
return false;
$connectionId = str_replace('webdav://', '', $id);
return $wdc->addAddressbookEntry($connectionId, $contactdata);
}
else
{
$addressbookid = $this->getAddressbookIdForPage($id);
$uri = uniqid('dokuwiki-').'.vcf';
$now = new \DateTime();
$query = "INSERT INTO addressbookobjects (contactdata, uri, addressbookid, lastmodified, etag, size, formattedname, structuredname) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$res = $this->sqlite->query($query,
$contactdata,
$uri,
$addressbookid,
$now->getTimestamp(),
md5($contactdata),
strlen($contactdata),
$formattedname,
implode(';', $structuredname)
);
// If successfully, update the sync token database
if($res !== false)
{
$this->updateSyncTokenLog($addressbookid, $uri, 'added');
return true;
}
}
+ return false;
}
private function parseVcard($card, $uri)
{
require_once(DOKU_PLUGIN.'davcard/vendor/autoload.php');
$vObject = \Sabre\VObject\Reader::read($card);
$formattedname = '';
$structuredname = '';
$tel = array();
$addr = array();
$mail = array();
$photo = array();
$birthday = '';
$note = '';
$title = '';
$url = '';
if(isset($vObject->FN))
$formattedname = (string)$vObject->FN;
if(isset($vObject->N))
$structuredname = join(';', $vObject->N->getParts());
if(isset($vObject->TEL))
{
foreach($vObject->TEL as $number)
{
if(isset($number['TYPE']))
- $tel[(string)$number['TYPE']] = (string)$number;
+ $tel[] = array('type' => strtolower((string)$number['TYPE']), 'number' => (string)$number);
else
- $tel[] = (string)$number;
+ $tel[] = array('number' => (string)$number);
}
}
if(isset($vObject->ADR))
{
foreach($vObject->ADR as $adr)
{
if(isset($adr['TYPE']))
- $addr[(string)$adr['TYPE']] = $adr->getParts();
+ $addr[] = array('type' => strtolower((string)$adr['TYPE']), 'address' => $adr->getParts());
else
- $addr[] = $adr->getParts();
+ $addr[] = array('address' => $adr->getParts());
}
}
if(isset($vObject->EMAIL))
{
foreach($vObject->EMAIL as $email)
{
if(isset($email['TYPE']))
- $mail[(string)$email['TYPE']] = (string)$email;
+ $mail[] = array('type' => strtolower((string)$email['TYPE']), 'mail' => (string)$email);
else
- $mail[] = (string)$email;
+ $mail[] = array('mail' => (string)$email);
}
}
if(isset($vObject->PHOTO))
{
if(isset($vObject->PHOTO['TYPE']))
{
- $photo[(string)$vObject->PHOTO['TYPE']] = (string)$vObject->PHOTO;
+ $photo[] = array('type' => strtolower((string)$vObject->PHOTO['TYPE']), 'photo' => (string)$vObject->PHOTO);
}
else
- $photo[] = (string)$vObject->PHOTO;
+ $photo[] = array('photo' => (string)$vObject->PHOTO);
}
if(isset($vObject->BDAY))
{
$birthday = (string)$vObject->BDAY;
$birthday = str_replace('-', '', $birthday);
}
if(isset($vObject->NOTE))
{
$note = (string)$vObject->NOTE;
}
if(isset($vObject->TITLE))
{
$title = (string)$vObject->TITLE;
}
if(isset($vObject->URL))
{
$url = (string)$vObject->URL;
}
return array(
'formattedname' => $formattedname,
'structuredname' => $structuredname,
'tel' => $tel,
'mail' => $mail,
'addr' => $addr,
'uri' => $uri,
'photo' => $photo,
'birthday' => $birthday,
'note' => $note,
'title' => $title,
'url' => $url,
);
}
public function getAddressbookSettings($addressbookid)
{
$query = "SELECT id, principaluri, displayname, uri, description, synctoken FROM addressbooks WHERE id= ? ";
$res = $this->sqlite->query($query, $addressbookid);
$row = $this->sqlite->res2row($res);
return $row;
}
public function getSyncTokenForAddressbook($addressbookid)
{
$row = $this->getAddressbookSettings($addressbookid);
if(isset($row['synctoken']))
return $row['synctoken'];
return false;
}
/**
* Helper function to convert the operation name to
* an operation code as stored in the database
*
* @param string $operationName The operation name
*
* @return mixed The operation code or false
*/
public function operationNameToOperation($operationName)
{
switch($operationName)
{
case 'added':
return 1;
break;
case 'modified':
return 2;
break;
case 'deleted':
return 3;
break;
}
return false;
}
private function updateSyncTokenLog($addressbookid, $uri, $operation)
{
$currentToken = $this->getSyncTokenForAddressbook($addressbookid);
$operationCode = $this->operationNameToOperation($operation);
if(($operationCode === false) || ($currentToken === false))
return false;
$values = array($uri,
$currentToken,
$addressbookid,
$operationCode
);
$query = "INSERT INTO addressbookchanges (uri, synctoken, addressbookid, operation) VALUES(?, ?, ?, ?)";
$res = $this->sqlite->query($query, $uri, $currentToken, $addressbookid, $operationCode);
if($res === false)
return false;
$currentToken++;
$query = "UPDATE addressbooks SET synctoken = ? WHERE id = ?";
$res = $this->sqlite->query($query, $currentToken, $addressbookid);
return ($res !== false);
}
}
diff --git a/lang/en/lang.php b/lang/en/lang.php
--- a/lang/en/lang.php
+++ b/lang/en/lang.php
@@ -1,68 +1,73 @@
<?php
/**
* English language file for DAVCard
*
* @author Andreas Böhler <dev@aboehler.at>
*/
$lang['unknown_error'] = 'Unknown Error';
$lang['id_name_not_set'] = 'Either ID or Name must be set';
$lang['loading_via_ajax'] = 'Loadig Contact Data...';
$lang['no_wdc'] = 'Loading webdavclient PlugIn failed.';
$lang['settings_not_found'] = 'The requested WebDAV connection was not found';
$lang['wrong_type'] = 'The requested WebDAV connection is not of type contact';
$lang['contact_not_found'] = 'The requested contact was not found';
$lang['error_adding'] = 'Error adding contact';
+$lang['error_editing'] = 'Error editing contact';
$lang['telvoice'] = 'Voice';
$lang['telhome'] = 'Home';
$lang['telmsg'] = 'Message';
$lang['telwork'] = 'Work';
$lang['telpref'] = 'preferred';
$lang['telfax'] = 'Fax';
$lang['telcell'] = 'Cell';
$lang['telvideo'] = 'Video';
$lang['telpager'] = 'Pager';
$lang['telbbs'] = 'BBS';
$lang['telmodem'] = 'Modem';
$lang['telcar'] = 'Car';
$lang['telisdn'] = 'ISDN';
$lang['telpcs'] = 'PCS';
+$lang['telother'] = 'Other';
$lang['adrintl'] = 'International';
$lang['adrpostal'] = 'Postal';
$lang['adrparcel'] = 'Parcel';
$lang['adrwork'] = 'Work';
$lang['adrdom'] = 'Domestic';
$lang['adrhome'] = 'Home';
$lang['adrpref'] = 'preferred';
+$lang['adrother'] = 'Other';
$lang['created_by_davcard'] = 'Created by DAVCard';
$lang['add_new'] = 'Add new entry';
$lang['edit'] = 'Edit';
$lang['js']['confirmation'] = 'Confirmation';
$lang['js']['yes'] = 'Yes';
$lang['js']['no'] = 'No';
$lang['js']['cancel'] = 'Cancel';
$lang['js']['create'] = 'Create';
$lang['js']['info'] = 'Info';
$lang['js']['ok'] = 'OK';
$lang['js']['edit'] = 'Edit';
$lang['js']['edit_entry'] = 'Edit Entry';
$lang['js']['create_entry'] = 'Create Entry';
$lang['js']['delete'] = 'Delete';
$lang['js']['really_delete_this_entry'] = 'Really delete this entry?';
$lang['js']['firstname'] = 'First Name';
$lang['js']['lastname'] = 'Last Name';
$lang['js']['city'] = 'City';
$lang['js']['zipcode'] = 'Zip Code';
$lang['js']['cellphone'] = 'Cell Phone';
$lang['js']['phone'] = 'Phone';
$lang['js']['add_phone'] = 'Add Phonenumber';
$lang['js']['add_mail'] = 'Add Mail';
$lang['js']['addresses'] = 'Addresses';
$lang['js']['street'] = 'Street';
$lang['js']['country'] = 'Country';
$lang['js']['email'] = 'Email';
$lang['js']['loading'] = 'Loading...';
$lang['js']['error_loading'] = 'Error loading contact data from server!';
$lang['js']['workphone'] = 'Work Phone';
+$lang['js']['otherphone'] = 'Other Phone';
$lang['js']['work'] = 'Work';
$lang['js']['home'] = 'Home';
$lang['js']['add_address'] = 'Add address';
+$lang['js']['other_address'] = 'Other Address';
diff --git a/script.js b/script.js
--- a/script.js
+++ b/script.js
@@ -1,627 +1,721 @@
jQuery(function() {
// Attach to addressbook links
var addressbookpage = jQuery('#davcardAddressbookList').data('addressbookpage');
if(!addressbookpage) return;
jQuery('div.davcardAddressbookAddNew a').each(function() {
var $link = jQuery(this);
var href = $link.attr('href');
if (!href) return;
$link.click(
function(e)
{
dw_davcard__modals.page = addressbookpage;
dw_davcard__modals.showEditContactDialog(null, false);
e.preventDefault();
return '';
}
);
}
);
var links = 0;
// Remove the CSS-only popup and replace it with a jQuery/AJAX popup
jQuery('div.dokuwiki a.plugin_davcard_url span.plugin_davcard_popup').each(function() {
jQuery(this).addClass('plugin_davcard_nopopup');
jQuery(this).removeClass('plugin_davcard_popup');
var $link = jQuery(this).parents('a.plugin_davcard_url');
if(!$link)
return;
$link.davcard_popup_id = 'plugin_davcard_popup_'+(links++);
$link.mouseover(function () {
$link.davcard_timer = window.setTimeout(
function () {
dw_davcard__modals.showOverlay($link);
$link.davcard_timer = null;
},
300
);
});
// Attach edit event dialog to link
$link.click(
function(e)
{
dw_davcard__modals.showLoadingDialog();
dw_davcard__modals.page = $link.data('davcardid');
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_davcard',
id: $link.data('davcardid'),
page: addressbookpage,
action: 'getContactDetails',
params: {
uri: $link.data('davcarduri'),
},
sectok: JSINFO.plugin.davcard['sectok']
},
function(data)
{
var result = data['result'];
if(result === true)
{
dw_davcard__modals.hideLoadingDialog();
dw_davcard__modals.showEditContactDialog(data['contactdata'], true);
}
else
{
dw_davcard__modals.hideLoadingDialog();
dw_davcard__modals.msg = LANG.plugins.davcard['error_loading'];
dw_davcard__modals.showDialog(false);
}
}
);
e.preventDefault();
return '';
}
);
$link.mouseout(function () {
$link = jQuery(this);
if ($link.davcard_timer)
window.clearTimeout($link.davcard_timer);
$link.davcard_timer = null;
});
});
});
/**
* This holds all modal windows that DAVCard uses.
*/
var dw_davcard__modals = {
$editContactDialog: null,
$confirmDialog: null,
$loadingDialog: null,
page: null,
uri: null,
action: null,
completeCb: null,
msg: null,
showEditContactDialog : function(entry, edit) {
if(dw_davcard__modals.$editContactDialog)
return;
var title = '';
var dialogButtons = {};
if(edit)
{
title = LANG.plugins.davcard['edit_entry'];
dialogButtons[LANG.plugins.davcard['edit']] = function() {
var postArray = { };
var pageid = dw_davcard__modals.page;
var addrArray = new Array();
var mailArray = new Array();
var phoneArray = new Array();
jQuery("tr.dw_davcard__editentry_phone_row").each(function() {
var type = jQuery(this).children("td.dw_davcard__editentry_phone_row_type").data('type');
var phone = jQuery(this).children("td.dw_davcard__editentry_phone_row_number").html();
var phoneRow = { };
phoneRow['type'] = type;
phoneRow['number'] = phone;
phoneArray.push(phoneRow);
});
jQuery("tr.dw_davcard__editentry_email_row").each(function() {
+ var type = jQuery(this).children("td.dw_davcard__editentry_mail_row_data").data('type');
var email = jQuery(this).children("td.dw_davcard__editentry_email_row_data").html();
- mailArray.push(email);
+ mailRow = { };
+ mailRow['type'] = type;
+ mailRow['mail'] = email;
+ mailArray.push(mailRow);
});
jQuery("tr.dw_davcard__editentry_addresses_row").each(function() {
var $rowData = jQuery(this).children("td.dw_davcard__editentry_addresses_row_data");
var type = $rowData.data('type');
var city = $rowData.data('city');
var street = $rowData.data('street');
var zipcode = $rowData.data('zipcode');
var country = $rowData.data('country');
var addrRow = { };
addrRow['type'] = type;
addrRow['city'] = city;
addrRow['street'] = street;
addrRow['zipcode'] = zipcode;
addrRow['country'] = country;
addrArray.push(addrRow);
});
postArray['phones'] = phoneArray;
postArray['email'] = mailArray;
postArray['addresses'] = addrArray;
+ postArray['uri'] = entry['uri'];
jQuery("input.dw_davcard__editcontact").each(function() {
if(jQuery(this).attr('type') == 'checkbox')
{
postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0;
}
else
{
postArray[jQuery(this).prop('name')] = jQuery(this).val();
}
});
jQuery('#dw_davcard__ajaxedit').html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" />');
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_davcard',
id: pageid,
page: dw_davcard__modals.page,
action: 'editContact',
params: postArray,
sectok: JSINFO.plugin.davcard['sectok']
},
function(data)
{
var result = data['result'];
var html = data['html'];
jQuery('#dw_davcard__ajaxedit').html(html);
if(result === true)
{
dw_davcard__modals.hideEditContactDialog();
location.reload();
}
}
);
};
dialogButtons[LANG.plugins.davcard['delete']] = function() {
dw_davcard__modals.action = 'deleteContact';
dw_davcard__modals.msg = LANG.plugins.davcard['really_delete_this_entry'];
dw_davcard__modals.completeCb = function(data) {
var result = data['result'];
if(result === true)
{
dw_davcard__modals.hideEditContactDialog();
location.reload();
}
};
dw_davcard__modals.showDialog(true);
};
}
else
{
title = LANG.plugins.davcard['create_entry'];
dialogButtons[LANG.plugins.davcard['create']] = function() {
var postArray = { };
var pageid = dw_davcard__modals.page;
var addrArray = new Array();
var mailArray = new Array();
var phoneArray = new Array();
jQuery("tr.dw_davcard__editentry_phone_row").each(function() {
var type = jQuery(this).children("td.dw_davcard__editentry_phone_row_type").data('type');
var phone = jQuery(this).children("td.dw_davcard__editentry_phone_row_number").html();
var phoneRow = { };
phoneRow['type'] = type;
phoneRow['number'] = phone;
phoneArray.push(phoneRow);
});
jQuery("tr.dw_davcard__editentry_email_row").each(function() {
+ var type = jQuery(this).children("td.dw_davcard__editentry_mail_row_data").data('type');
var email = jQuery(this).children("td.dw_davcard__editentry_email_row_data").html();
- mailArray.push(email);
+ mailRow = { };
+ mailRow['type'] = type;
+ mailRow['mail'] = email;
+ mailArray.push(mailRow);
});
jQuery("tr.dw_davcard__editentry_addresses_row").each(function() {
var $rowData = jQuery(this).children("td.dw_davcard__editentry_addresses_row_data");
var type = $rowData.data('type');
var city = $rowData.data('city');
var street = $rowData.data('street');
var zipcode = $rowData.data('zipcode');
var country = $rowData.data('country');
var addrRow = { };
addrRow['type'] = type;
addrRow['city'] = city;
addrRow['street'] = street;
addrRow['zipcode'] = zipcode;
addrRow['country'] = country;
addrArray.push(addrRow);
});
postArray['phones'] = phoneArray;
postArray['email'] = mailArray;
postArray['addresses'] = addrArray;
jQuery("input.dw_davcard__editcontact").each(function() {
if(jQuery(this).attr('type') == 'checkbox')
{
postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0;
}
else
{
postArray[jQuery(this).prop('name')] = jQuery(this).val();
}
});
jQuery('#dw_davcard__ajaxedit').html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" />');
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_davcard',
id: pageid,
page: dw_davcard__modals.page,
action: 'newContact',
params: postArray,
sectok: JSINFO.plugin.davcard['sectok']
},
function(data)
{
var result = data['result'];
var html = data['html'];
jQuery('#dw_davcard__ajaxedit').html(html);
if(result === true)
{
dw_davcard__modals.hideEditContactDialog();
location.reload();
}
}
);
};
}
dialogButtons[LANG.plugins.davcard['cancel']] = function() {
dw_davcard__modals.hideEditContactDialog();
};
dw_davcard__modals.$editContactDialog = jQuery(document.createElement('div'))
.dialog({
autoOpen: false,
draggable: true,
// fix for dragging: http://stackoverflow.com/questions/17247486/jquery-ui-dialog-dragging-issues
drag: function(event, ui) {
var fixPix = jQuery(document).scrollTop();
iObj = ui.position;
iObj.top = iObj.top - fixPix;
jQuery(this).closest(".ui-dialog").css("top", iObj.top + "px");
},
title: title,
resizable: true,
buttons: dialogButtons,
})
.html(
'<div><table>' +
// FIXME: '<tr><td>' + LANG.plugins.davcard['calendar'] + '</td><td><select id="dw_davcal__editevent_calendar"></select></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['firstname'] + '</td><td><input type="text" id="dw_davcard__firstname_edit" name="firstname" class="dw_davcard__editcontact"></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['lastname'] + '</td><td><input type="text" id="dw_davcard__lastname_edit" name="lastname" class="dw_davcard__editcontact"></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['phone'] + '</td><td><table id="dw_davcard__editentry_phones"><tbody><tr><td><select id="dw_davcard__editentry_phones_select"></select></td><td><input type="text" id="dw_davcard__editentry_phone_edit"></td><td><a href="#" id="dw_davcard__editentry_phone_add">' + LANG.plugins.davcard['add_phone'] + '</a></td></tr></tbody></table></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['email'] + '</td><td><table id="dw_davcard__editentry_emails"><tbody><tr><td><input type="text" id="dw_davcard__editentry_email_edit"></td><td><a href="#" id="dw_davcard__editentry_email_add">' + LANG.plugins.davcard['add_mail'] + '</a></td></tr></tbody></table></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['addresses'] + '</td><td><table id="dw_davcard__editentry_addresses"><tbody>' +
'<tr><td rowspan="5"><select id="dw_davcard__editentry_addresses_select"></select></td><td>' + LANG.plugins.davcard['street'] + '</td><td><input type="text" id="dw_davcard__editentry_addresses_street"></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['zipcode'] + '</td><td><input type="text" id="dw_davcard__editentry_addresses_zipcode"></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['city'] + '</td><td><input type="text" id="dw_davcard__editentry_addresses_city"></td></tr>' +
'<tr><td>' + LANG.plugins.davcard['country'] + '</td><td><input type="text" id="dw_davcard__editentry_addresses_country"></td></tr>' +
'<tr><td><a href="#" id="dw_davcard__editentry_addresses_add">' + LANG.plugins.davcard['add_address'] + '</a></td></tr></tbody></table></td></tr>' +
'</tbody></table></td></tr>' +
'</table>' +
- '<input type="hidden" name="uri" id="dw_davcard__uid_edit" class="dw_davcard__editcontact">' +
'</div>' +
'<div id="dw_davcard__ajaxedit"></div>'
)
.parent()
.attr('id','dw_davcard__edit')
.css({'overflow-y': 'auto'})
.show()
.appendTo('.dokuwiki:first');
-
- // Resize the dialog if it's higher than the window
- if(jQuery('#dw_davcard__edit').height() > jQuery(window).height())
- {
- jQuery('#dw_davcard__edit').height(jQuery(window).height() * 0.9);
- }
-
- jQuery('#dw_davcard__edit').position({
- my: "center",
- at: "center",
- of: window
- });
// attach event handlers
jQuery('#dw_davcard__edit .ui-dialog-titlebar-close').click(function(){
dw_davcard__modals.hideEditContactDialog();
});
// Populate Dropdowns
var $dropdown = jQuery('#dw_davcard__editentry_phones_select');
- $dropdown.append('<option value="work">' + LANG.plugins.davcard['workphone'] + '</option>');
- $dropdown.append('<option value="cell">' + LANG.plugins.davcard['cellphone'] + '</option>');
- $dropdown.append('<option value="home">' + LANG.plugins.davcard['phone'] + '</option>');
+ $dropdown.append('<option value="work">' + dw_davcard__modals.phoneTypeToString('work') + '</option>');
+ $dropdown.append('<option value="cell">' + dw_davcard__modals.phoneTypeToString('cell') + '</option>');
+ $dropdown.append('<option value="home">' + dw_davcard__modals.phoneTypeToString('home') + '</option>');
$dropdown = jQuery('#dw_davcard__editentry_addresses_select');
- $dropdown.append('<option value="work">' + LANG.plugins.davcard['work'] + '</option>');
- $dropdown.append('<option value="home">' + LANG.plugins.davcard['home'] + '</option>');
+ $dropdown.append('<option value="work">' + dw_davcard__modals.addressTypeToString('work') + '</option>');
+ $dropdown.append('<option value="home">' + dw_davcard__modals.addressTypeToString('home') + '</option>');
dw_davcard__modals.attachPhoneDeleteHandlers();
dw_davcard__modals.attachMailDeleteHandlers();
dw_davcard__modals.attachAddressDeleteHandlers();
jQuery('#dw_davcard__editentry_phone_add').on("click", function(e)
{
e.preventDefault();
var number = jQuery('#dw_davcard__editentry_phone_edit').val();
if(number == '')
return false;
var type = jQuery('#dw_davcard__editentry_phones_select option:selected').val();
var typeText = jQuery('#dw_davcard__editentry_phones_select option:selected').text();
jQuery('#dw_davcard__editentry_phone_edit').val('');
- var row = '<tr class="dw_davcard__editentry_phone_row"><td class="dw_davcard__editentry_phone_row_type" data-type="' + type + '">' + typeText + '</td><td class="dw_davcard__editentry_phone_row_number">' + number + '</td><td><a class="deletePhoneNumber" href="#">' + LANG.plugins.davcard['delete'] + '</a></td></tr>';
- jQuery('#dw_davcard__editentry_phones > tbody:last').append(row);
- dw_davcard__modals.attachPhoneDeleteHandlers();
+ dw_davcard__modals.addPhone(type, typeText, number);
return false;
});
jQuery('#dw_davcard__editentry_email_add').on("click", function(e)
{
e.preventDefault();
var mail = jQuery('#dw_davcard__editentry_email_edit').val();
if(mail == '')
return false;
jQuery('#dw_davcard__editentry_email_edit').val('');
- var row = '<tr class="dw_davcard__editentry_email_row"><td class="dw_davcard__editentry_email_row_data">' + mail + '</td><td><a class="deleteEmail" href="#">' + LANG.plugins.davcard['delete'] + '</a></td></tr>';
- jQuery('#dw_davcard__editentry_emails > tbody:last').append(row);
- dw_davcard__modals.attachMailDeleteHandlers();
+ dw_davcard__modals.addMail('internet', mail);
return false;
});
jQuery('#dw_davcard__editentry_addresses_add').on("click", function(e)
{
e.preventDefault();
var street = jQuery('#dw_davcard__editentry_addresses_street').val();
var zipcode = jQuery('#dw_davcard__editentry_addresses_zipcode').val();
var country = jQuery('#dw_davcard__editentry_addresses_country').val();
var city = jQuery('#dw_davcard__editentry_addresses_city').val();
var type = jQuery('#dw_davcard__editentry_addresses_select option:selected').val();
var typeText = jQuery('#dw_davcard__editentry_addresses_select option:selected').text();
if(street == '' && zipcode == '' && country == '' && city == '')
return false;
jQuery('#dw_davcard__editentry_addresses_street').val('');
jQuery('#dw_davcard__editentry_addresses_city').val('');
jQuery('#dw_davcard__editentry_addresses_country').val('');
jQuery('#dw_davcard__editentry_addresses_zipcode').val('');
- var row = '<tr class="dw_davcard__editentry_addresses_row"><td class="dw_davcard__editentry_addresses_row_data" data-type="' + type + '" data-city="' + city + '" data-zipcode="' + zipcode + '" data-country="' + country + '" data-street="' + street + '">' + typeText + '</td><td colspan="2"><strong>' + LANG.plugins.davcard['street'] + ': </strong>' + street + '<br>' +
- '<strong>' + LANG.plugins.davcard['city'] + ': </strong>' + zipcode + ' ' + city + '<br>' +
- '<strong>' + LANG.plugins.davcard['country'] + ': </strong>' + country + '<br>' +
- '<a class="deleteAddress" href="#">' + LANG.plugins.davcard['delete'] + '</a></td></tr>';
- jQuery('#dw_davcard__editentry_addresses > tbody:last').append(row);
- dw_davcard__modals.attachAddressDeleteHandlers();
+ dw_davcard__modals.addAddress(type, typeText, street, zipcode, city, country);
return false;
});
-
-
+ if(edit)
+ {
+ var name = entry['structuredname'].split(';');
+ jQuery('#dw_davcard__lastname_edit').val(name[0]);
+ jQuery('#dw_davcard__firstname_edit').val(name[1]);
+ for(var i=0; i<entry['tel'].length; i++)
+ {
+ var type = 'other';
+ if('type' in entry['tel'][i])
+ var type = entry['tel'][i]['type'];
+ var val = entry['tel'][i]['number'];
+ var typeText = dw_davcard__modals.phoneTypeToString(type);
+ dw_davcard__modals.addPhone(type, typeText, val);
+ }
+ for(var i=0; i<entry['addr'].length; i++)
+ {
+ var type = 'other';
+ if('type' in entry['addr'][i])
+ type = entry['addr'][i]['type'];
+ var street = entry['addr'][i]['address'][2];
+ var zipcode = entry['addr'][i]['address'][5];
+ var country = entry['addr'][i]['address'][6];
+ var city = entry['addr'][i]['address'][3];
+ var typeText = dw_davcard__modals.addressTypeToString(type);
+ dw_davcard__modals.addAddress(type, typeText, street, zipcode, city, country);
+ }
+ for(var i=0; i<entry['mail'].length; i++)
+ {
+ var type = 'other';
+ if('type' in entry['mail'][i])
+ type = entry['mail'][i]['type'];
+ var mail = entry['mail'][i]['mail'];
+ dw_davcard__modals.addMail(type, mail);
+ }
+ }
+
+ // Resize the dialog if it's higher than the window
+ if(jQuery('#dw_davcard__edit').height() > jQuery(window).height())
+ {
+ jQuery('#dw_davcard__edit').height(jQuery(window).height() * 0.9);
+ }
+
+ jQuery('#dw_davcard__edit').position({
+ my: "center",
+ at: "center",
+ of: window
+ });
+ },
+
+ addressTypeToString: function(type)
+ {
+ var ret = '';
+ switch(type)
+ {
+ case 'work':
+ ret = LANG.plugins.davcard['work'];
+ break;
+ case 'home':
+ ret = LANG.plugins.davcard['home'];
+ break;
+ default:
+ ret = LANG.plugins.davcard['other_address'];
+ break;
+ }
+ return ret;
+ },
+
+ phoneTypeToString: function(type)
+ {
+ var ret = '';
+ switch(type)
+ {
+ case 'work':
+ ret = LANG.plugins.davcard['workphone'];
+ break;
+ case 'cell':
+ ret = LANG.plugins.davcard['cellphone'];
+ break;
+ case 'home':
+ ret = LANG.plugins.davcard['phone'];
+ break;
+ default:
+ ret = LANG.plugins.davcard['otherphone'];
+ break;
+ }
+ return ret;
+ },
+
+ addPhone: function(type, typeText, number)
+ {
+ var row = '<tr class="dw_davcard__editentry_phone_row"><td class="dw_davcard__editentry_phone_row_type" data-type="' + type + '">' + typeText + '</td><td class="dw_davcard__editentry_phone_row_number">' + number + '</td><td><a class="deletePhoneNumber" href="#">' + LANG.plugins.davcard['delete'] + '</a></td></tr>';
+ jQuery('#dw_davcard__editentry_phones > tbody:last').append(row);
+ dw_davcard__modals.attachPhoneDeleteHandlers();
+ },
+
+ addMail: function(type, mail) {
+ var row = '<tr class="dw_davcard__editentry_email_row"><td class="dw_davcard__editentry_email_row_data" data-type="' + type + '">' + mail + '</td><td><a class="deleteEmail" href="#">' + LANG.plugins.davcard['delete'] + '</a></td></tr>';
+ jQuery('#dw_davcard__editentry_emails > tbody:last').append(row);
+ dw_davcard__modals.attachMailDeleteHandlers();
+ },
+
+ addAddress: function(type, typeText, street, zipcode, city, country)
+ {
+ var row = '<tr class="dw_davcard__editentry_addresses_row"><td class="dw_davcard__editentry_addresses_row_data" data-type="' + type + '" data-city="' + city + '" data-zipcode="' + zipcode + '" data-country="' + country + '" data-street="' + street + '">' + typeText + '</td><td colspan="2"><strong>' + LANG.plugins.davcard['street'] + ': </strong>' + street + '<br>' +
+ '<strong>' + LANG.plugins.davcard['city'] + ': </strong>' + zipcode + ' ' + city + '<br>' +
+ '<strong>' + LANG.plugins.davcard['country'] + ': </strong>' + country + '<br>' +
+ '<a class="deleteAddress" href="#">' + LANG.plugins.davcard['delete'] + '</a></td></tr>';
+ jQuery('#dw_davcard__editentry_addresses > tbody:last').append(row);
+ dw_davcard__modals.attachAddressDeleteHandlers();
},
attachAddressDeleteHandlers: function()
{
jQuery("#dw_davcard__editentry_addresses .deleteAddress").on("click", function(e)
{
e.preventDefault();
var tr = jQuery(this).closest('tr');
tr.css("background-color", "#FF3700");
tr.fadeOut(400, function()
{
tr.remove();
});
return false;
});
},
attachPhoneDeleteHandlers: function()
{
jQuery("#dw_davcard__editentry_phones .deletePhoneNumber").on("click", function(e)
{
e.preventDefault();
var tr = jQuery(this).closest('tr');
tr.css("background-color", "#FF3700");
tr.fadeOut(400, function()
{
tr.remove();
});
return false;
});
},
attachMailDeleteHandlers: function()
{
jQuery("#dw_davcard__editentry_emails .deleteEmail").on("click", function(e)
{
e.preventDefault();
var tr = jQuery(this).closest('tr');
tr.css("background-color", "#FF3700");
tr.fadeOut(400, function()
{
tr.remove();
});
return false;
});
},
showLoadingDialog: function() {
if(dw_davcard__modals.$loadingDialog)
return;
var dialogButtons = {};
var title = '';
title = LANG.plugins.davcard['loading'];
dialogButtons[LANG.plugins.davcard['cancel']] = function() {
dw_davcard__modals.hideLoadingDialog();
};
dw_davcard__modals.$loadingDialog = jQuery(document.createElement('div'))
.dialog({
autoOpen: false,
draggable: true,
//fix for dragging: http://stackoverflow.com/questions/17247486/jquery-ui-dialog-dragging-issues
drag: function(event, ui) {
var fixPix = jQuery(document).scrollTop();
iObj = ui.position;
iObj.top = iObj.top - fixPix;
jQuery(this).closest(".ui-dialog").css("top", iObj.top + "px");
},
title: title,
resizable: true,
buttons: dialogButtons,
})
.html('<div>' + LANG.plugins.davcard['loading'] +
'<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" /></div>'
)
.parent()
.attr('id','dw_davcard__loading')
.show()
.appendTo('.dokuwiki:first');
jQuery('#dw_davcard__loading').position({
my: "center",
at: "center",
of: window
});
// attach event handlers
jQuery('#dw_davcard__loading .ui-dialog-titlebar-close').click(function(){
dw_davcard__modals.hideDialog();
});
},
hideEditContactDialog : function() {
dw_davcard__modals.$editContactDialog.empty();
dw_davcard__modals.$editContactDialog.remove();
dw_davcard__modals.$editContactDialog = null;
},
hideDialog: function() {
dw_davcard__modals.$dialog.empty();
dw_davcard__modals.$dialog.remove();
dw_davcard__modals.$dialog = null;
},
hideLoadingDialog: function() {
dw_davcard__modals.$loadingDialog.empty();
dw_davcard__modals.$loadingDialog.remove();
dw_davcard__modals.$loadingDialog = null;
},
showOverlay: function($link)
{
if(!$link.davcard_popup)
{
$link.davcard_popup = dw_page.insituPopup($link, $link.davcard_popup_id);
$link.davcard_popup.addClass('plugin_davcard_popup_overlay');
$link.davcard_popup.load(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_davcard',
sectok: JSINFO.plugin.davcard['sectok'],
action: 'getContactAjax',
id: $link.data('davcardid'),
params: {
uri: $link.data('davcarduri'),
}
}
);
}
$link.davcard_popup.show();
},
showDialog : function(confirm)
{
if(dw_davcard__modals.$confirmDialog)
return;
var dialogButtons = {};
var title = '';
if(confirm)
{
title = LANG.plugins.davcard['confirmation'];
var pageid = dw_davcard__modals.page;
dialogButtons[LANG.plugins.davcard['yes']] = function() {
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_davcard',
id: pageid,
page: dw_davcard__modals.page,
action: dw_davcard__modals.action,
params: {
uri: dw_davcard__modals.uri
},
sectok: JSINFO.plugin.davcard['sectok']
},
function(data)
{
dw_davcard__modals.completeCb(data);
}
);
dw_davcard__modals.hideDialog();
};
dialogButtons[LANG.plugins.davcard['cancel']] = function() {
dw_davcard__modals.hideDialog();
};
}
else
{
title = LANG.plugins.davcard['info'];
dialogButtons[LANG.plugins.davcard['ok']] = function() {
dw_davcard__modals.hideDialog();
};
}
dw_davcard__modals.$dialog = jQuery(document.createElement('div'))
.dialog({
autoOpen: false,
draggable: true,
//fix for dragging: http://stackoverflow.com/questions/17247486/jquery-ui-dialog-dragging-issues
drag: function(event, ui) {
var fixPix = jQuery(document).scrollTop();
iObj = ui.position;
iObj.top = iObj.top - fixPix;
jQuery(this).closest(".ui-dialog").css("top", iObj.top + "px");
},
title: title,
resizable: true,
buttons: dialogButtons,
})
.html(
'<div>' + dw_davcard__modals.msg + '</div>'
)
.parent()
.attr('id','dw_davcard__confirm')
.show()
.appendTo('.dokuwiki:first');
jQuery('#dw_davcard__confirm').position({
my: "center",
at: "center",
of: window
});
// attach event handlers
jQuery('#dw_davcard__confirm .ui-dialog-titlebar-close').click(function(){
dw_davcard__modals.hideDialog();
});
},
};
\ No newline at end of file
diff --git a/syntax/card.php b/syntax/card.php
--- a/syntax/card.php
+++ b/syntax/card.php
@@ -1,205 +1,213 @@
<?php
/**
* DokuWiki Plugin DAVCard (Contact Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Böhler <dev@aboehler.at>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_davcard_card extends DokuWiki_Syntax_Plugin {
protected $hlp = null;
// Load the helper plugin
public function syntax_plugin_davcard_card() {
$this->hlp =& plugin_load('helper', 'davcard');
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* What about paragraphs?
*/
function getPType(){
return 'normal';
}
/**
* Where to sort in?
*/
function getSort(){
return 165;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{davcard>[^}]*\}\}',$mode,'plugin_davcard_card');
$this->Lexer->addSpecialPattern('\{\{davcardclient>[^}]*\}\}',$mode,'plugin_davcard_card');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
global $ID;
$data = array('name' => '',
'id' => '',
'firstname' => '',
'lastname' => '',
'email' => '',
'uri' => '',
);
if(strpos($match, '{{davcardclient') === 0)
{
$options = trim(substr($match,16,-2));
$defaultId = $this->getConf('default_client_id');
if(isset($defaultId) && ($defaultId != ''))
{
$data['id'] = $defaultId;
}
}
else
{
$options = trim(substr($match,10,-2));
}
$options = explode(',', $options);
foreach($options as $option)
{
list($key, $val) = explode('=', $option);
$key = strtolower(trim($key));
$val = trim($val);
switch($key)
{
default:
$data[$key] = $val;
}
}
// FIXME: This is nonsense
if($data['id'] === '')
{
if(($data['name'] === '') || (($data['firstname'] === '') && ($data['lastname'] === '')))
{
msg($this->getLang('id_name_not_set'), -1);
}
}
return $data;
}
/**
* Create output
*/
function render($format, Doku_Renderer $R, $data) {
if($format == 'metadata')
{
if(strpos($data['id'], 'webdav://') === 0)
{
$connectionId = str_replace('webdav://', '', $data['id']);
$R->meta['plugin_davcard']['webdavclient'][] = $connectionId;
return true;
}
}
if($format != 'xhtml')
return false;
$contactdata = array();
if(strpos($data['id'], 'webdav://') === 0)
{
if($data['name'] !== '')
{
$contactdata = $this->hlp->getContactByFormattedName($data['id'], $data['name']);
}
elseif(($data['firstname'] !== '') || ($data['lastname'] !== ''))
{
$contactdata = $this->hlp->getContactByStructuredName($data['id'], $data['firstname'], $data['lastname']);
}
elseif(($data['email'] !== ''))
{
$contactdata = $this->hlp->getContactByEmail($data['id'], $data['email']);
}
elseif(($data['uri'] !== ''))
{
$contactdata = $this->hlp->getContactByUri($data['id'], $data['uri']);
}
if($contactdata === false)
{
$contactdata['formattedname'] = $this->getLang('contact_not_found');
$contactdata['uri'] = '';
}
}
$R->doc .= '<a class="url fn plugin_davcard_url" href="#" data-davcarduri="'
.$contactdata['uri'].'" data-davcardid="'.$data['id'].'">'.$contactdata['formattedname'];
$R->doc .= '<span class="plugin_davcard_popup vcard">';
if(count($contactdata['addr']) > 0)
{
$R->doc .= '<span class="adr">';
- foreach($contactdata['addr'] as $type => $addr)
+ foreach($contactdata['addr'] as $data)
{
+ if(isset($data['type']))
+ $type = $data['type'];
+ else
+ $type = 'other';
$R->doc .= '<span class="type">'.$this->getLang('adr'.strtolower($type)).'</span>';
if($addr[2] != '')
{
- $R->doc .= '<span class="street-address">'.$addr[2].'</span><br>';
+ $R->doc .= '<span class="street-address">'.$data['address'][2].'</span><br>';
}
if($addr[5] != '')
{
- $R->doc .= '<span class="postal-code">'.$addr[5].' </span>';
+ $R->doc .= '<span class="postal-code">'.$data['address'][5].' </span>';
}
if($addr[3] != '')
{
- $R->doc .= '<span class="locality">'.$addr[3].'</span><br>';
+ $R->doc .= '<span class="locality">'.$data['address'][3].'</span><br>';
}
if($addr[6] != '')
{
- $R->doc .= '<span class="country-name">'.$addr[6].'</span>';
+ $R->doc .= '<span class="country-name">'.$data['address'][6].'</span>';
}
}
$R->doc .= '</span>';
}
if(count($contactdata['tel']) > 0)
{
$R->doc .= '<span class="tel">';
- foreach($contactdata['tel'] as $type => $number)
+ foreach($contactdata['tel'] as $data)
{
+ if(isset($data['type']))
+ $type = $data['type'];
+ else
+ $type = 'other';
$R->doc .= '<span class="type">'.$this->getLang('tel'.strtolower($type)).' </span>';
- $R->doc .= $number.'<br>';
+ $R->doc .= $data['number'].'<br>';
}
$R->doc .= '</span>';
}
if(count($contactdata['mail']) > 0)
{
$R->doc .= '<span class="email_outer"><span class="email_type">EMail</span>';
- foreach($contactdata['mail'] as $type => $mail)
+ foreach($contactdata['mail'] as $data)
{
- $R->doc .= '<span class="email">'.$mail.'</span><br>';
+ $R->doc .= '<span class="email">'.$data['mail'].'</span><br>';
}
$R->doc .= '</span>';
}
$R->doc .= '</span>';
$R->doc .= '</a>';
}
}
// vim:ts=4:sw=4:et:enc=utf-8:
diff --git a/vendor/autoload.php b/vendor/autoload.php
--- a/vendor/autoload.php
+++ b/vendor/autoload.php
@@ -1,7 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
-return ComposerAutoloaderInit9f2aaabf46a4de03b538097a57ebf792::getLoader();
+return ComposerAutoloaderInitda1d44bdc668dcff1e738a57f9370e9d::getLoader();
diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php
--- a/vendor/composer/autoload_real.php
+++ b/vendor/composer/autoload_real.php
@@ -1,45 +1,45 @@
<?php
// autoload_real.php @generated by Composer
-class ComposerAutoloaderInit9f2aaabf46a4de03b538097a57ebf792
+class ComposerAutoloaderInitda1d44bdc668dcff1e738a57f9370e9d
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
- spl_autoload_register(array('ComposerAutoloaderInit9f2aaabf46a4de03b538097a57ebf792', 'loadClassLoader'), true, true);
+ spl_autoload_register(array('ComposerAutoloaderInitda1d44bdc668dcff1e738a57f9370e9d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
- spl_autoload_unregister(array('ComposerAutoloaderInit9f2aaabf46a4de03b538097a57ebf792', 'loadClassLoader'));
+ spl_autoload_unregister(array('ComposerAutoloaderInitda1d44bdc668dcff1e738a57f9370e9d', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Jan 24, 5:12 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
532805
Default Alt Text
(75 KB)
Attached To
rDAVCARD DokuWiki davcard PlugIn
Event Timeline
Log In to Comment