public function httpGet(RequestInterface $request, ResponseInterface $response)
    {
        $queryParams = $request->getQueryParameters();
        if (!array_key_exists('export', $queryParams)) {
            return;
        }

        $path = $request->getPath();

        $node = $this->server->tree->getNodeForPath($path);

        if (!($node instanceof IAddressBook)) {
            return;
        }

        $this->server->transactionType = 'get-addressbook-export';

        // Checking ACL, if available.
        if ($aclPlugin = $this->server->getPlugin('acl')) {
            $aclPlugin->checkPrivileges($path, '{DAV:}read');
        }

        $nodes = $this->server->getPropertiesForPath($path, [
            '{'.Plugin::NS_CARDDAV.'}address-data',
        ], 1);

        $format = 'text/directory';

        $output = null;
        $filenameExtension = null;

        switch ($format) {
            case 'text/directory':
                $output = $this->generateVCF($nodes);
                $filenameExtension = '.vcf';
                break;
        }

        $filename = preg_replace(
            '/[^a-zA-Z0-9-_ ]/um',
            '',
            $node->getName()
        );
        $filename .= '-'.date('Y-m-d').$filenameExtension;

        $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
        $response->setHeader('Content-Type', $format);

        $response->setStatus(200);
        $response->setBody($output);

        // Returning false to break the event chain
        return false;
    }
public function httpGet(RequestInterface $request, ResponseInterface $response)
    {
        $queryParams = $request->getQueryParameters();
        if (!array_key_exists('export', $queryParams)) {
            return;
        }

        $path = $request->getPath();

        $node = $this->server->tree->getNodeForPath($path);

        if (!($node instanceof IAddressBook)) {
            return;
        }

        $this->server->transactionType = 'get-addressbook-export';

        // Checking ACL, if available.
        if ($aclPlugin = $this->server->getPlugin('acl')) {
            $aclPlugin->checkPrivileges($path, '{DAV:}read');
        }

        $nodes = $this->server->getPropertiesForPath($path, [
            '{'.Plugin::NS_CARDDAV.'}address-data',
        ], 1);

        $format = 'text/directory';

        $output = null;
        $filenameExtension = null;

        switch ($format) {
            case 'text/directory':
                $output = $this->generateVCF($nodes);
                $filenameExtension = '.vcf';
                break;
        }

        $filename = preg_replace(
            '/[^a-zA-Z0-9-_ ]/um',
            '',
            $node->getName()
        );
        $filename .= '-'.date('Y-m-d').$filenameExtension;

        $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
        $response->setHeader('Content-Type', $format);

        $response->setStatus(200);
        $response->setBody($output);

        // Returning false to break the event chain
        return false;
    }
public function httpGet ( RequestInterface $ request , ResponseInterface $ response ) { $ queryParams = $ request -> getQueryParameters ( ) ; if ( ! array_key_exists ( 'export' , $ queryParams ) ) { return ; } $ path = $ request -> getPath ( ) ; $ node = $ this -> server -> tree -> getNodeForPath ( $ path ) ; if ( ! ( $ node instanceof IAddressBook ) ) { return ; } $ this -> server -> transactionType = 'get-addressbook-export' ; // Checking ACL, if available. if ( $ aclPlugin = $ this -> server -> getPlugin ( 'acl' ) ) { $ aclPlugin -> checkPrivileges ( $ path , '{DAV:}read' ) ; } $ nodes = $ this -> server -> getPropertiesForPath ( $ path , [ '{' . Plugin :: NS_CARDDAV . '}address-data' , ] , 1 ) ; $ format = 'text/directory' ; $ output = null ; $ filenameExtension = null ; switch ( $ format ) { case 'text/directory' : $ output = $ this -> generateVCF ( $ nodes ) ; $ filenameExtension = '.vcf' ; break ; } $ filename = preg_replace ( '/[^a-zA-Z0-9-_ ]/um' , '' , $ node -> getName ( ) ) ; $ filename .= '-' . date ( 'Y-m-d' ) . $ filenameExtension ; $ response -> setHeader ( 'Content-Disposition' , 'attachment; filename="' . $ filename . '"' ) ; $ response -> setHeader ( 'Content-Type' , $ format ) ; $ response -> setStatus ( 200 ) ; $ response -> setBody ( $ output ) ; // Returning false to break the event chain return false ; }
Intercepts GET requests on addressbook urls ending with ?export.

@param RequestInterface  $request
@param ResponseInterface $response

@return bool
Intercepts GET requests on addressbook urls ending with ?export .