diff --git a/action/ajax.php b/action/ajax.php deleted file mode 100644 --- a/action/ajax.php +++ /dev/null @@ -1,103 +0,0 @@ -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(Doku_Event $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')); - $name = trim($INPUT->post->str('name')); - - if(!checkSecurityToken()) - { - echo "CSRF Attack."; - return; - } - - $data = array(); - - $data['result'] = false; - $data['html'] = $this->getLang('unknown_error'); - - // Parse the requested action - switch($action) - { - case 'getContact': - if($name !== '') - { - $info = $this->hlp->getContactByName($id, $name); - if($info === false) - { - $data['html'] = $this->getLang('contact_not_found'); - break; - } - $data['result'] = true; - if($info['formattedname'] !== '') - $data['html'] = 'Name: '.$info['formattedname'].'
'; - if(count($info['tel']) > 0) - { - foreach($info['tel'] as $type => $nr) - { - $data['html'] .= $type.': '.$nr.'
'; - } - } - if(count($info['addr']) > 0) - { - foreach($info['addr'] as $type => $addr) - { - $data['html'] .= $type.': '.join('
', $addr); - $data['html'] .= '
'; - } - } - if(count($info['mail']) > 0) - { - foreach($info['mail'] as $type => $mail) - { - $data['html'] .= $type.': '.$mail.'
'; - } - } - - } - else - { - $data['html'] = $this->hlp-->getContactByUri($id); - } - 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/action/cache.php b/action/cache.php new file mode 100644 --- /dev/null +++ b/action/cache.php @@ -0,0 +1,44 @@ +register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_parser_cache_use'); + } + + function handle_parser_cache_use(Doku_Event $event, $param) + { + $cache = &$event->data; + if(!isset($cache->page)) return; + //purge only xhtml cache + if($cache->mode != "xhtml") return; + + $meta = p_get_metadata($cache->page, 'plugin_davcard'); + if($meta === null) + return; + // Force re-caching if the webdavclient has synced + if(isset($meta['webdavclient'])) + { + $wdc =& plugin_load('helper', 'webdavclient'); + if(is_null($wdc)) + return; + foreach($meta['webdavclient'] as $connectionId) + { + $cache->depends['files'][] = $wdc->getLastSyncChangeFileForConnection($connectionId); + } + } + } + +} + + diff --git a/lang/en/lang.php b/lang/en/lang.php --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -1,13 +1,34 @@ */ $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['wdc'] = 'Loading webdavclient PlugIn failed.'; +$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['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['adrintl'] = 'International'; +$lang['adrpostal'] = 'Postal'; +$lang['adrparcel'] = 'Parcel'; +$lang['adrwork'] = 'Work'; +$lang['adrdom'] = 'Domestic'; +$lang['adrhome'] = 'Home'; +$lang['adrpref'] = 'preferred'; diff --git a/plugin.info.txt b/plugin.info.txt --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base davcard author Andreas Boehler email dev@aboehler.at -date 2016-05-12 +date 2016-05-13 name Addressbook PlugIn with CardDAV client support desc Show contact information from a CardDAV address book (needs webdavclient) url http://www.dokuwiki.org/plugin:davcard diff --git a/script.js b/script.js deleted file mode 100644 --- a/script.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Initialize the DAVCard script, attaching some event handlers and triggering - * the initial load of the fullcalendar JS - */ - -jQuery(function() { - jQuery('div.plugin_davcard').each(function() { - var $div = jQuery(this); - var id = $div.data('cardid'); - var name = $div.data('name'); - if (!id && !name) return; - - jQuery.post( - DOKU_BASE + 'lib/exe/ajax.php', - { - call: 'plugin_davcard', - id: id, - action: 'getContact', - name: name, - sectok: JSINFO.plugin.davcard['sectok'] - }, - function(data) - { - $div.html(data['html']); - }); - - }); -}); diff --git a/style.css b/style.css new file mode 100644 --- /dev/null +++ b/style.css @@ -0,0 +1,34 @@ +div.dokuwiki a.plugin_davcard_url:link, +div.dokuwiki a.plugin_davcard_url:active, +div.dokuwiki a.plugin_davcard_url:hover, +div.dokuwiki a.plugin_davcard_url:visited { + position: relative; + padding-left: 18px; + z-index: 10; +} + +div.dokuwiki a.plugin_davcard_url:link span.plugin_davcard_popup, +div.dokuwiki a.plugin_davcard_url:active span.plugin_davcard_popup, +div.dokuwiki a.plugin_davcard_url:visited span.plugin_davcard_popup { + display: none; +} + +div.dokuwiki a.plugin_davcard_url:hover { + text-decoration: none !important; + z-index: 15; +} + +div.dokuwiki a.plugin_davcard_url:hover span.plugin_davcard_popup { + display: block; + position: absolute; + top: 1.2em; + left: 18px; + width: 20em; + height: 64px; + min-height: 64px; + height: auto; + background-color: __background__; + border: 1px solid __border__; + padding: 0.5em; + font-size: 90%; +} \ 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,97 +1,164 @@ */ // 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'); } /** * Handle the match */ function handle($match, $state, $pos, Doku_Handler $handler){ global $ID; $options = trim(substr($match,10,-2)); $options = explode(',', $options); $data = array('name' => '', 'id' => '', ); foreach($options as $option) { list($key, $val) = explode('=', $option); $key = strtolower(trim($key)); $val = trim($val); switch($key) { default: $data[$key] = $val; } } if($data['id'] === '' && $data['name'] === '') { msg($this->getLang('id_name_not_set'), -1); } return $data; } /** * Create output */ function render($format, Doku_Renderer $R, $data) { - if($format != 'xhtml') return false; + 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->getContactByName($data['id'], $data['name']); + } + } - $R->doc .= '
'; - $R->doc .= ''; - $R->doc .= $this->getLang('loading_via_ajax').'
'; + $R->doc .= ''.$contactdata['formattedname']; + $R->doc .= ''; + if(count($contactdata['addr']) > 0) + { + $R->doc .= ''; + foreach($contactdata['addr'] as $type => $addr) + { + $R->doc .= ''.$this->getLang('adr'.strtolower($type)).''; + if($addr[2] != '') + { + $R->doc .= ''.$addr[2].'
'; + } + if($addr[5] != '') + { + $R->doc .= ''.$addr[5].' '; + } + if($addr[3] != '') + { + $R->doc .= ''.$addr[3].'
'; + } + + if($addr[6] != '') + { + $R->doc .= ''.$addr[6].''; + } + } + $R->doc .= '

'; + } + if(count($contactdata['tel']) > 0) + { + $R->doc .= ''; + foreach($contactdata['tel'] as $type => $number) + { + $R->doc .= ''.$this->getLang('tel'.strtolower($type)).' '; + $R->doc .= $number.'
'; + } + $R->doc .= '
'; + } + if(count($contactdata['mail']) > 0) + { + $R->doc .= 'EMail:
'; + foreach($contactdata['mail'] as $type => $mail) + { + $R->doc .= '
'; + } + $R->doc .= '

'; + } + + $R->doc .= '
'; + $R->doc .= '
'; } } // vim:ts=4:sw=4:et:enc=utf-8: