*/ // 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' => $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; } } 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(); $srch = ''; if($data['name'] !== '') { $contactdata = $this->hlp->getContactByFormattedName($data['id'], $data['name']); $srch = $data['name']; } elseif(($data['firstname'] !== '') || ($data['lastname'] !== '')) { $contactdata = $this->hlp->getContactByStructuredName($data['id'], $data['firstname'], $data['lastname']); $srch = $data['firstname'].' '.$data['lastname']; } elseif(($data['email'] !== '')) { $contactdata = $this->hlp->getContactByEmail($data['id'], $data['email']); $srch = 'E-Mail = '.$data['email']; } elseif(($data['uri'] !== '')) { $contactdata = $this->hlp->getContactByUri($data['id'], $data['uri']); $srch = 'URI = '.$data['uri']; } if($contactdata['result'] === false) { $R->doc .= sprintf($this->getLang('contact_not_found'), $srch); return; } $R->doc .= ''.hsc($contactdata['formattedname']); $R->doc .= ''; if(count($contactdata['addr']) > 0) { $R->doc .= ''; foreach($contactdata['addr'] as $dat) { if(isset($data['type'])) $type = $dat['type']; else $type = 'other'; $R->doc .= ''.hsc($this->getLang('adr'.strtolower($type))).''; if($dat['address'][2] != '') { $R->doc .= ''.hsc($dat['address'][2]).'
'; } if($dat['address'][5] != '') { $R->doc .= ''.hsc($dat['address'][5]).' '; } if($dat['address'][3] != '') { $R->doc .= ''.hsc($dat['address'][3]).'
'; } if($dat['address'][6] != '') { $R->doc .= ''.hsc($dat['address'][6]).''; } } $R->doc .= '
'; } if(count($contactdata['tel']) > 0) { $R->doc .= ''; foreach($contactdata['tel'] as $dat) { if(isset($dat['type'])) $type = $dat['type']; else $type = 'other'; $R->doc .= ''.hsc($this->getLang('tel'.strtolower($type))).' '; $R->doc .= hsc($dat['number']).'
'; } $R->doc .= '
'; } if(count($contactdata['mail']) > 0) { $R->doc .= ''; } $R->doc .= '
'; $R->doc .= '
'; } } // vim:ts=4:sw=4:et:enc=utf-8: