*/ 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'); $acl = $this->hlp->checkAddressbookPermission($id); if($acl > AUTH_READ) { $write = true; } elseif($acl < AUTH_READ) { $data['result'] = false; $data['html'] = $this->getLang('no_permission'); // Overwrite $action to bypass switch statement below $action = 'invalid'; } else { $write = false; } // Parse the requested action switch($action) { // Add a new Contact case 'newContact': if($write && ($this->hlp->addContactEntryToAddressbookForPage($id, $user, $params) === true)) { $data['result'] = true; } else { $data['result'] = false; if(!$write) $data['html'] = $this->getLang('no_permission'); else $data['html'] = $this->getLang('error_adding'); } break; // Retrieve contact details case 'getContactDetails': $contactdata = $this->hlp->getContactByUri($id, $params['uri']); if($contactdata['result'] === true) { // When we support pictures for editing contacts, // we need to use the following line: // $contactdata['photo'] = base64_encode($contactdata['photo']); // For now, we just save bandwidth :) unset($contactdata['photo']); $data['result'] = true; $data['contactdata'] = $contactdata; } else { $data['result'] = false; $data['html'] = sprintf($this->getLang('contact_not_found'), 'ID='.$id.' URI='.$params['uri']); } break; // Edit a contact case 'editContact': if($write && ($this->hlp->editContactEntryToAddressbookForPage($id, $user, $params['uri'], $params) === true)) { $data['result'] = true; } else { $data['result'] = false; if(!$write) $data['html'] = $this->getLang('no_permission'); else $data['html'] = $this->getLang('error_editing'); } break; // Delete a Contact case 'deleteContact': if($write && ($this->hlp->deleteContactEntryToAddressbookForPage($id, $user, $params['uri']) === true)) { $data['result'] = true; } else { $data['result'] = false; if(!$write) $data['html'] = $this->getLang('no_permission'); else $data['html'] = $this->getLang('error_deleting'); } break; // Get AJAX popup case 'getContactAjax': $contactdata = $this->hlp->getContactByUri($id, $params['uri']); $cardpattern = $this->getConf('popup_content'); if($contactdata['result'] === false) { echo hsc($contactdata['formattedname']); return; } echo '